ccdeck 3.38.0 → 3.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/web/assets/{BrowserWatchModal-BPObeZn1.js → BrowserWatchModal-D2iFbRdJ.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-Drv13uht.js → UsageHistoryModal-DaH3RkMw.js} +1 -1
- package/dist/web/assets/{index-0cUs2Jed.css → index-D-HX6Mea.css} +1 -1
- package/dist/web/assets/{index-C_h8mR-c.js → index-DnnkOgia.js} +5 -5
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/release-notes.json +2 -1
- package/src/server/deck-prefs.mjs +5 -2
- package/src/server/lan-engine.mjs +40 -34
- package/src/server/lan-reach.mjs +21 -0
- package/src/server/lan-routes.mjs +4 -1
- package/src/server/lan-sync.mjs +6 -5
|
@@ -88,8 +88,8 @@ last 5h: ${it(n.window5h.totalTokens)} tokens · ${n.window5h.sessionCount} sess
|
|
|
88
88
|
${h.sessionId}`:h.sessionId,children:h.label??c0(h.sessionId,8)}),a.jsx("span",{className:"up-session-tokens",children:it(h.tokens)}),h.cost>0?a.jsx("span",{className:"up-session-cost",title:h.models.join(", ")||void 0,children:qe(h.cost)}):a.jsx("span",{className:"up-session-cost up-unpriced",children:ms})]},h.sessionId)}),!e&&n.map(h=>a.jsxs("div",{className:"up-session-row",children:[a.jsx("span",{className:`sl-dot state-${h.state}`,"aria-hidden":!0}),a.jsx("span",{className:"vis-hidden",children:fi(h.state)}),a.jsx("span",{className:"up-session-label",children:h.label}),a.jsx("span",{className:"up-session-tokens",children:it(h.inputTokens+h.outputTokens)}),h.cost>0?a.jsxs("span",{className:"up-session-cost",title:h.unpricedTokens>0?`${it(h.unpricedTokens)} tokens in this session are on an unpriced model, so this is a floor`:void 0,children:[qe(h.cost),h.unpricedTokens>0?"+":""]}):a.jsx("span",{className:"up-session-cost up-unpriced",children:ms})]},h.sessionId))]})]})}function ia(e,t){return{disabled:e!=null&&e!==t,busy:e===t}}function lh(e){return e==null}const Gx="self";function Dr(e,t=!1){const n=ia(e?Gx:null,Gx);return{disabled:t||n.disabled,"aria-busy":n.busy}}function lr(e){return lh(e?Gx:null)}const Kl=400;function Yl({armedFor:e,target:t,armedAt:n,now:r,gapMs:s}){return e!==t?"arm":r-n<s?"ignore":"fire"}function aI(e){return[...e==null?[]:[`#ap-more-${e}`],".accounts-panel .ap-refresh"]}function Tn(e){return e==null||e==="BODY"||e==="HTML"}const w7=6e4,v7=2e4;function x7(e){const[t,n]=y.useState(null),[r,s]=y.useState(!1),o=y.useRef(null),l=y.useRef(!1),c=async(h=!1)=>{if(!(h&&!lr(l.current))){h&&(l.current=!0,s(!0));try{const p=await fetch(h?"/api/quota?refresh=1":"/api/quota",{signal:AbortSignal.timeout(v7)});p.ok&&n(await p.json())}catch{}finally{h&&(l.current=!1,s(!1))}}};return y.useEffect(()=>{if(e)return c(!0),o.current=window.setInterval(()=>c(!1),w7),()=>{o.current!=null&&window.clearInterval(o.current)}},[e]),{quota:t,loading:r,refresh:()=>{e&&c(!0)}}}const oI=6e4;function b7(e){const[t,n]=y.useState(null),[r,s]=y.useState(!1),o=y.useRef(null),l=y.useRef(!1),c=async(h=!1)=>{if(!(h&&!lr(l.current))){h&&(l.current=!0,s(!0));try{const p=await fetch(h?"/api/codex-quota?refresh=1":"/api/codex-quota");p.ok&&n(await p.json())}catch{}finally{h&&(l.current=!1,s(!1))}}};return y.useEffect(()=>{if(e)return c(!0),o.current=window.setInterval(()=>c(!1),oI),()=>{o.current!=null&&window.clearInterval(o.current)}},[e]),{data:t,loading:r,refresh:()=>{e&&c(!0)}}}function k7(e){const[t,n]=y.useState(null),r=y.useRef(null),s=async()=>{try{const o=await fetch("/api/codex-usage");o.ok&&n(await o.json())}catch{}};return y.useEffect(()=>{if(e)return s(),r.current=window.setInterval(s,oI),()=>{r.current!=null&&window.clearInterval(r.current)}},[e]),{data:t}}const cS=6e4;function N7(e,t,n){const[r,s]=y.useState(null),[o,l]=y.useState(!1),[c,d]=y.useState(0),h=y.useRef(0);y.useEffect(()=>{const p=()=>document.visibilityState==="visible",g=()=>{p()&&d(k=>k+1)},v=window.setInterval(g,cS),N=()=>{p()&&Date.now()-h.current>=cS&&d(k=>k+1)};return document.addEventListener("visibilitychange",N),()=>{window.clearInterval(v),document.removeEventListener("visibilitychange",N)}},[]);const f=y.useRef(t);return y.useEffect(()=>{let p=!0;const g=t!==f.current;f.current=t;const v=e,N=Z$(v);return l(!0),fetch(`/api/ccusage?since=${N}${g?"&refresh=1":""}`).then(k=>k.ok?k.json():null).then(k=>{!p||!(k!=null&&k.ok)||(h.current=Date.now(),s({period:v,data:k,baseline:n()}))}).catch(()=>{}).finally(()=>{p&&l(!1)}),()=>{p=!1}},[e,t,c]),{...QH(r,e),loading:o}}const j7=e=>1-Math.pow(1-e,5),iI=420;function S7(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e===t)return!1;const n=Math.abs(t-e);if(n<1)return!1;const r=Math.max(Math.abs(e),Math.abs(t));return r===0||n/r>=.005}function _7(e,t,n,r=iI){return n>=r?t:n<=0?e:e+(t-e)*j7(n/r)}function lI(){return typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}function uS(e,t,n,r={}){const s=r.now??(()=>performance.now()),o=r.raf??(v=>requestAnimationFrame(v)),l=r.cancel??(v=>cancelAnimationFrame(v)),c=r.reducedMotion??lI,d=r.hidden??(()=>typeof document=="object"&&document.hidden===!0);if(c()||d()||!S7(e,t))return n(t),()=>{};const h=s();let f=0,p=!0;const g=()=>{if(!p)return;const v=s()-h;n(_7(e,t,v)),v<iI&&(f=o(g))};return f=o(g),()=>{p=!1,f&&l(f)}}const E7=typeof window>"u"?y.useEffect:y.useLayoutEffect;function Da(e,{countIn:t=!1}={}){const[n,r]=y.useState(e),s=y.useRef(e),o=y.useRef(!0);return y.useEffect(()=>{s.current=n},[n]),E7(()=>{!t||lI()||(s.current=0,r(0))},[]),y.useEffect(()=>{if(o.current){if(o.current=!1,t)return uS(0,e,c=>{s.current=c,r(c)});s.current=e,r(e);return}return uS(s.current,e,c=>{s.current=c,r(c)})},[e]),n}function cI(e,t,n){const r=C7*Math.max(1,n/dI);let s=0;for(const[o,l]of t){const c=e.get(o);if(c===void 0)continue;const d=l.cost-c.cost;d>0&&d<=r&&(s+=d)}return s}const dS={samples:[],last:new Map,watched:0},uI=10*6e4,T7=6e4,dI=5e3,C7=20;function A7(e,t,n){const r=e.samples[e.samples.length-1];if(r&&t-r.t<dI)return e;const s=e.watched+cI(e.last,n,r?t-r.t:0),o=e.samples.filter(l=>t-l.t<=uI);return o.push({t,watched:s}),{samples:o,last:n,watched:s}}function R7(e,t,n){const r=e.samples[0];if(!r)return null;const s=t-r.t;if(s<T7)return null;const o=e.samples[e.samples.length-1].t,l=e.watched+cI(e.last,n,t-o)-r.watched;return l>0?{spent:l,spanSec:s/1e3,spanMin:Math.min(uI/6e4,Math.ceil(s/6e4))}:null}function M7(e,t,n){const r=y.useRef(dS),s=y.useRef(null);return y.useMemo(()=>{const o=MH(e.agents.values()),l=TH(e.agents.values());s.current!==n&&(s.current=n,r.current=dS);const c=Hx(e.agents.values(),t);n!=null&&(r.current=A7(r.current,t,c));const d=n==null?null:R7(r.current,t,c),h=d?{label:e0(d.spent,d.spanSec),spanMin:d.spanMin}:null;return{byModel:o,totalCost:l.cost,totalTokens:l,burnRate:h}},[e,e.revision,t,n])}const $7=3e4;function hI(){const[e,t]=y.useState(()=>Math.floor(Date.now()/1e3));return y.useEffect(()=>{const n=window.setInterval(()=>t(Math.floor(Date.now()/1e3)),$7);return()=>window.clearInterval(n)},[]),e}function hS(e){return(typeof e.cost=="number"?e.cost:e.cost.total)>0||e.inputTokens+e.outputTokens>0}function I7(e,t,n){return e?t.some(r=>r.cost<=0&&r.tokens>0):n.some(r=>!r.priced)}function O7(e){return e.claude&&e.codex?"Refresh Claude + Codex quota":e.codex?"Refresh Codex quota":"Refresh Claude quota"}function L7(e){const t=new Map;for(const n of e){if(n.kind!=="root"||!n.sessionId)continue;const r=n.label||n.cwdBasename;r&&t.set(n.sessionId,r)}return t}function P7(e){const t=new Map;for(const n of e)n.kind!=="root"||!n.sessionId||t.set(n.sessionId,n.state);return t}function D7(e){const t=new Map;for(const n of e){if(!n.label)continue;const r=t.get(n.label);r?r.push(n.sessionId):t.set(n.label,[n.sessionId])}return e.map(n=>{const r=n.label?t.get(n.label)??[]:[];return r.length>1?{...n,label:`${n.label} ${G$(n.sessionId,r)}`}:n})}function F7({state:e,now:t,providers:n,incidents:r=[],leaving:s,onClose:o,liveSince:l=null}){const{quota:c,loading:d,refresh:h}=x7(n.claude),{data:f,loading:p,refresh:g}=b7(n.codex),{data:v}=k7(n.codex),N=hI(),{byModel:k,totalCost:x,totalTokens:j,burnRate:b}=M7(e,t,l),_=y.useMemo(()=>$H(e.agents.values()),[e,e.revision]),[E,R]=y.useState(t7);y.useEffect(()=>{n7(E)},[E]);const[C,A]=y.useState(r7);y.useEffect(()=>{s7(C)},[C]);const[U,L]=y.useState(0),F=y.useRef(()=>new Map);F.current=()=>l==null?null:Hx(e.agents.values(),t);const O=y.useCallback(()=>F.current(),[]),{data:I,shown:B,stale:M,loading:$,baseline:P}=N7(E,U,O),G=I!=null,K=$&&M,q=y.useMemo(()=>L7(e.agents.values()),[e,e.revision]),H=y.useMemo(()=>P7(e.agents.values()),[e,e.revision]),D=y.useMemo(()=>G?J$(I):[],[I,G]),W=y.useMemo(()=>G?D7(XH(I,q).slice(0,12)):[],[I,G,q]),J=y.useMemo(()=>ih(I),[I]),V=y.useMemo(()=>ZH(I,J.cost),[I,J.cost]),X=Q$(B,E),Y=y.useMemo(()=>G?VH(P,Hx(e.agents.values(),t)):Wx,[e,e.revision,P,G,t]),Z=e7(I,{...j,cost:x},Y),ee=Z.hasCost,ne=Z.tokenSum,se=Da(Z.cost),pe=Da(Z.inputTokens),ke=Da(Z.outputTokens),ae=Da(Z.cacheReadTokens),fe=Da(Z.cacheCreateTokens),me=k.filter(hS),he=_.filter(hS),ge=I7(G,D,me),ue=d||p,be=()=>{h(),g(),L(je=>je+1)},oe=O7(n);return a.jsxs("aside",{className:`usage-panel${s?" leaving":""}`,id:"usage-panel","aria-label":"Usage",children:[a.jsxs("div",{className:"up-header",children:[a.jsx("h2",{children:"Usage"}),b&&a.jsxs("span",{className:"up-rate",title:`Spend on this board over the last ${b.spanMin} min`,children:[b.label,a.jsxs("span",{className:"up-rate-span",children:[" · ",b.spanMin," min"]})]}),a.jsxs("div",{className:"up-header-right",children:[(n.claude||n.codex)&&a.jsx("button",{type:"button",className:"glyph-btn up-refresh-btn",onClick:be,...Dr(ue),"aria-label":oe,title:oe,children:ue?"…":"↻"}),a.jsx("button",{type:"button",className:"glyph-btn up-close",onClick:o,"aria-label":"Close usage panel",title:"Close (U)",children:"×"})]})]}),n.claude&&a.jsx(f7,{quota:c,quotaLoading:d,nowSec:N,incident:r.find(je=>je.provider==="claude")}),n.codex&&a.jsx(p7,{codexQuota:f,codexLoading:p,codexUsage:v,nowSec:N,incident:r.find(je=>je.provider==="codex")}),G&&a.jsx(g7,{period:E,rangePending:K,setPeriod:R}),ne>0?a.jsxs(a.Fragment,{children:[ee&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"up-total",title:G?void 0:oS,children:[a.jsx("span",{className:"up-total-value",children:qe(se)}),a.jsx("span",{className:"up-total-label",children:G?X:CH})]}),Z.showCostBar&&a.jsx(u0,{cost:x})]}),a.jsxs("div",{className:"up-tokens-row",title:G?void 0:oS,children:[a.jsxs("span",{className:"up-tok",children:[a.jsx("span",{className:"up-k",children:"in"}),it(pe)]}),a.jsxs("span",{className:"up-tok",children:[a.jsx("span",{className:"up-k",children:"out"}),it(ke)]}),Z.cacheReadTokens>0&&a.jsxs("span",{className:"up-tok",children:[a.jsx("span",{className:"up-k",children:"cache r"}),it(ae)]}),Z.cacheCreateTokens>0&&a.jsxs("span",{className:"up-tok",children:[a.jsx("span",{className:"up-k",children:"cache c"}),it(fe)]}),!ee&&a.jsx("span",{className:"up-tok up-scope",children:AH})]}),(G?D.length:me.length)>0&&a.jsx(m7,{fromRange:G,rangeModelRows:D,boardModelRows:me}),G&&W.length===0&&J.tokens>0&&a.jsxs("section",{className:"up-section",children:[a.jsx("h3",{className:"up-section-title",children:"By session"}),a.jsxs("div",{className:"up-hint",children:["No session is dated ",X," yet — ccusage dates sessions in UTC, and the totals above are your local day."]})]}),(G?W.length:he.length)>0&&a.jsx(y7,{fromRange:G,rangeSessionRows:W,boardSessionRows:he,boardStates:H,sessionsOpen:C,setSessionsOpen:A,periodNoun:X,sessionScale:V}),ge&&a.jsxs("div",{className:"up-hint",children:["“",ms,"” means this build holds no published rate for that model — those tokens are counted above and their dollars are not."]})]}):a.jsx("div",{className:"up-empty",children:G?(B??E)==="all"?a.jsx(a.Fragment,{children:"No usage in any transcript on this machine."}):a.jsxs(a.Fragment,{children:["No usage ",X,".",a.jsx("br",{}),"Try a longer period."]}):a.jsxs(a.Fragment,{children:["No usage data yet.",a.jsx("br",{}),"Start a Claude Code or Codex session."]})}),a.jsx("div",{className:"film-foot",children:a.jsx(Gl,{film:"usage"})})]})}function Lp(e){return e<9.95?e.toFixed(1):String(Math.round(e))}function d0(e){const t=Number.isFinite(e)?Math.max(0,e):0;return t<50?{value:"0",unit:"KB/s"}:t<999500?{value:Lp(t/1e3),unit:"KB/s"}:t<9995e5?{value:Lp(t/1e6),unit:"MB/s"}:{value:Lp(t/1e9),unit:"GB/s"}}function ch(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 Xl(e){return e.unit?e.unit==="%"||e.unit==="°C"?`${e.value}${e.unit}`:`${e.value} ${e.unit}`:e.value}const B7="thermal:Throttling";function h0(e){const t="timeHeld"in e?e.timeHeld:100-e.speedLimit;return Math.max(0,Math.min(100,t))}function q7(e){var n,r,s,o;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 l of((s=e.thermal)==null?void 0:s.celsius)??[])t[`thermal:${l.label}`]=l.celsius;return(o=e.thermal)!=null&&o.throttle&&(t[B7]=h0(e.thermal.throttle)),t}function $l(e,t){return t==="B/s"?Xl(d0(e)):t==="ms"?Xl(ch(e)):t==="C"?`${Math.round(e)}°`:t==="%"?`${Math.round(e)}%`:e.toFixed(2)}function Du(e,t){return t==="B/s"||t==="ms"||!Number.isInteger(e)?$l(e,t):t==="C"?`${e}°`:t==="%"?`${e}%`:`${e}`}function U7(e,t,n){return e>=n?"hot":e>=t?"warn":"calm"}function z7(e,t,n=Date.now()){const r=h0(e),s="timeHeld"in e;return{pct:r,value:`${r}%`,tone:r===0?"calm":r>=30?"hot":"warn",note:r>0?s?`CPU throttled ${r}% of the time to cool down`:`CPU held to ${100-r}% of full speed to cool down`:t?s?`at full speed · ${t.peak}% throttled ${fS(t.lastMs,n)}`:`at full speed · held to ${100-t.peak}% ${fS(t.lastMs,n)}`:"running at full speed, and never held back"}}function fS(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 W7(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 H7(e){var r,s;const t=(r=e.thermal)==null?void 0:r.throttle,n=t?h0(t):0;return t&&n>0?"timeHeld"in t?`throttled ${n}% of the time`:`throttled to ${100-n}% 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 V7(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})`:""}`}const G7=3e3;function K7(){const[e,t]=y.useState(null),n=y.useRef(null);return y.useEffect(()=>{let r=!0;const s=async()=>{if(document.visibilityState!=="hidden")try{const d=await fetch("/api/system");if(!d.ok)return;const h=await d.json();r&&(h!=null&&h.ok)&&t(h)}catch{}},o=()=>{n.current==null&&(s(),n.current=window.setInterval(s,G7))},l=()=>{n.current!=null&&(window.clearInterval(n.current),n.current=null)},c=()=>{if(document.visibilityState==="hidden"){l();return}o(),s()};return o(),document.addEventListener("visibilitychange",c),()=>{r=!1,l(),document.removeEventListener("visibilitychange",c)}},[]),e}function Y7(e,t){return!e||e.key!==t?"none":e.dir==="asc"?"ascending":"descending"}function jl({col:e,label:t,note:n,sort:r,next:s,onSort:o,className:l}){const c=Y7(r,e);return a.jsx("th",{scope:"col","aria-sort":c,className:l,children:a.jsxs("button",{type:"button",className:"sd-sort",title:n?`Sort by ${t}
|
|
89
89
|
|
|
90
90
|
${n}`:`Sort by ${t}`,onClick:()=>o(s(r,e)),children:[t,a.jsx("span",{className:"sd-sort-dir","aria-hidden":!0,children:c==="none"?"":c==="ascending"?"↑":"↓"})]})})}function Pp(e,t){return t==="B/s"?d0(e):t==="ms"?ch(e):{value:String(e),unit:t==="C"?"°C":t}}const Et={l:30,r:6,t:6,b:2},Xs={l:0,r:0,t:2,b:1},uh=104,X7=64;function ir(e,t=100,n=uh,r=Et){const s=n-r.t-r.b;return r.t+s*(1-Math.max(0,Math.min(t,e))/t)}function fI(e,t){return t??[e[0].t,e[e.length-1].t]}function f0(e,[t,n],r,s=Et){const o=r-s.l-s.r,l=n-t;return s.l+(l>0?o*(e-t)/l:o/2)}function pI(e,t,n,r=100,s=uh,o=Et,l){if(!e.length)return"";const c=fI(e,l),d=p=>f0(p,c,t,o);let h="",f=null;for(const p of e){const g=f&&p.t-f.t<=n*2?"L":"M";h+=`${g}${d(p.t).toFixed(1)} ${ir(p.v,r,s,o).toFixed(1)}`,f=p}return h}function mI(e,t,n,r=100,s=uh,o=Et,l){if(e.length<2)return"";const c=s-o.b,d=fI(e,l),h=v=>f0(v,d,t,o);let f="",p=[];const g=()=>{if(p.length>=2){let v=`M${h(p[0].t).toFixed(1)} ${c}`;for(const N of p)v+=`L${h(N.t).toFixed(1)} ${ir(N.v,r,s,o).toFixed(1)}`;f+=`${v}L${h(p[p.length-1].t).toFixed(1)} ${c}Z`}p=[]};for(const v of e)p.length&&v.t-p[p.length-1].t>n*2&&g(),p.push(v);return g(),f}function Z7(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 gI(e,t,n){return n!=null&&e>=n?"hot":t!=null&&e>=t?"warn":""}function J7(e,t,n=r=>Fa(r)){const r=e.filter(l=>l.v>0);if(!e.length)return null;if(!r.length)return"never held back";const s=r.length*(t/6e4),o=r[r.length-1];return`held back for ${s===1?"1 minute":`${s} minutes`}, last at ${n(o.t)}`}function Fa(e){const t=new Date(e);return`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function p0(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 Q7({group:e,title:t,onClose:n}){const r=ut(n),s=gt(n),[o,l]=y.useState(null);y.useEffect(()=>{let p=!0;const g=async()=>{try{const N=await fetch(`/api/system/history?group=${e}`);if(!N.ok)return;const k=await N.json();p&&(k!=null&&k.ok)&&l(k)}catch{}};g();const v=window.setInterval(g,2e4);return()=>{p=!1,window.clearInterval(v)}},[e]);const c=(o==null?void 0:o.series)??[],[d,h,f]=y.useMemo(()=>{let p=1/0,g=0;for(const v of c)v.points.length&&(p=Math.min(p,v.points[0].t),g=Math.max(g,v.points[v.points.length-1].t));return Number.isFinite(p)?[Math.max(p,(o==null?void 0:o.sinceMs)??0),g,[p,g]]:[(o==null?void 0:o.sinceMs)??0,g,void 0]},[c,o==null?void 0:o.sinceMs]);return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...s,role:"presentation",children:a.jsxs("div",{ref:r,className:"modal hist-modal",onClick:p=>p.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"hist-modal-title",children:[a.jsxs("div",{className:"modal-head",children:[a.jsx("span",{className:"modal-title",id:"hist-modal-title",children:t}),o&&d>0&&a.jsxs("span",{className:"hist-since",children:["since ",Fa(d)," · ",p0(d,h||Date.now())]}),a.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]}),a.jsx("div",{className:"hist-body",children:o==null?a.jsx("p",{className:"hist-empty",children:"Reading…"}):c.length===0?a.jsx("p",{className:"hist-empty",children:"Nothing has been measured yet."}):c.map(p=>a.jsx(e9,{series:p,stepMs:o.stepMs,domain:f},p.label))})]})}),document.body)}function e9({series:e,stepMs:t,domain:n}){const r=y.useRef(null),[s,o]=y.useState(560),[l,c]=y.useState(null);y.useEffect(()=>{const O=r.current;if(!O||typeof ResizeObserver>"u")return;const I=new ResizeObserver(([B])=>o(Math.max(160,B.contentRect.width)));return I.observe(O),()=>I.disconnect()},[]);const{points:d,unit:h,warnAt:f,critAt:p,label:g,top:v,restsAtZero:N,changes:k}=e,x=N?X7:uh,{now:j,peak:b}=Z7(d),_=j!=null?Pp(j,h):null,E=b!=null?Pp(b,h):null,R=g==="Throttling"?J7(d,t):null,C=l!=null?d[l]:null,[A,U]=n??(d.length?[d[0].t,d[d.length-1].t]:[0,0]),L=O=>f0(O,[A,U],s),F=O=>{if(d.length<2)return;const I=O.currentTarget.getBoundingClientRect(),B=(O.clientX-I.left-Et.l)/Math.max(1,I.width-Et.l-Et.r),M=A+(U-A)*Math.max(0,Math.min(1,B));let $=0;for(let P=1;P<d.length;P++)Math.abs(d[P].t-M)<Math.abs(d[$].t-M)&&($=P);c($)};return a.jsxs("section",{className:"hist-series","aria-label":`${g} history`,children:[a.jsxs("div",{className:"hist-head",children:[a.jsx("span",{className:"hist-label",children:g}),a.jsxs("span",{className:"hist-stats",children:[_&&a.jsxs(a.Fragment,{children:[a.jsx("b",{children:_.value}),a.jsxs("span",{children:[_.unit," now"]})]}),b!=null&&E&&a.jsxs(a.Fragment,{children:[a.jsx("b",{className:gI(b,f,p),children:E.value}),a.jsxs("span",{children:[E.unit," peak"]})]})]})]}),a.jsx("div",{className:"hist-plot",ref:r,children:a.jsxs("svg",{className:"hist-chart",width:"100%",height:x,viewBox:`0 0 ${s} ${x}`,preserveAspectRatio:"none",role:"img","aria-label":_==null||E==null?`${g}: nothing measured yet`:`${g}: ${Xl(_)} now, peak ${Xl(E)}, over ${p0(d[0].t,d[d.length-1].t)}`,onPointerMove:F,onPointerLeave:()=>c(null),children:[[["warn",f],["hot",p]].map(([O,I])=>I==null||I>v?null:a.jsxs("g",{children:[a.jsx("line",{className:`hist-rule ${O}`,x1:Et.l,x2:s-Et.r,y1:ir(I,v,x),y2:ir(I,v,x)}),a.jsx("text",{className:`hist-rule-tag ${O}`,x:2,y:ir(I,v,x)+3,children:I})]},O)),a.jsx("line",{className:"hist-floor",x1:Et.l,x2:s-Et.r,y1:x-Et.b,y2:x-Et.b}),(k??[]).filter(O=>O.from!=null&&d.length>1&&O.t>=A&&O.t<=U).map(O=>a.jsx("line",{className:"hist-mark",x1:L(O.t),x2:L(O.t),y1:Et.t,y2:x-Et.b},O.t)),a.jsx("path",{className:"hist-area",d:mI(d,s,t,v,x,Et,[A,U])}),a.jsx("path",{className:"hist-line",d:pI(d,s,t,v,x,Et,[A,U])}),d.length===1&&a.jsx("circle",{className:"hist-dot",cx:L(d[0].t),cy:ir(d[0].v,v,x),r:3}),C&&a.jsxs("g",{children:[a.jsx("line",{className:"hist-cross",x1:L(C.t),x2:L(C.t),y1:Et.t,y2:x-Et.b}),a.jsx("circle",{className:"hist-dot",cx:L(C.t),cy:ir(C.v,v,x),r:3})]})]})}),a.jsx("div",{className:"hist-axis",children:C?a.jsxs("span",{className:"hist-at",children:[Fa(C.t)," — ",(()=>{const O=Pp(C.v,h);return a.jsxs(a.Fragment,{children:[a.jsx("b",{children:O.value}),O.unit==="%"||O.unit==="°C"||!O.unit?O.unit:` ${O.unit}`]})})()]}):a.jsxs(a.Fragment,{children:[a.jsx("span",{children:d.length?Fa(A):""}),a.jsx("span",{children:d.length?Fa(U):""})]})}),R&&a.jsx("div",{className:"hist-note",children:R}),k==null?void 0:k.slice(-3).map(O=>a.jsx("div",{className:"hist-note hist-route",children:O.from==null?`Since ${Fa(O.t)} — ${O.label}`:`${Fa(O.t)} — ${O.label.charAt(0).toUpperCase()+O.label.slice(1)}`},O.t))]})}const pS=["cores","memory","load","thermal"],Ia=116,Ir=24,t9=60,n9=6e4;function r9(e){return e.points.length?e.restsAtZero?e.points.some(t=>t.v>0):!0:!1}function s9(e){return e.unit==="C"?`${e.label} temp`:e.key==="mem:physical"?"Physical RAM":e.key==="mem:swap"?`${e.label} memory`:e.label}function a9(e,t=t9){return e.points.length<=t?e:{...e,points:e.points.slice(-t)}}function o9({sys:e}){const[t,n]=y.useState({});y.useEffect(()=>{let l=!0;const c=async()=>{const h=await Promise.all(pS.map(async f=>{try{const p=await fetch(`/api/system/history?group=${f}`);return p.ok?[f,await p.json()]:[f,null]}catch{return[f,null]}}));l&&n(f=>{const p={...f};for(const[g,v]of h)v!=null&&v.ok&&(p[g]=v);return p})};c();const d=setInterval(()=>void c(),n9);return()=>{l=!1,clearInterval(d)}},[]);const r=y.useMemo(()=>q7(e),[e]),s=y.useMemo(()=>pS.flatMap(l=>{const c=t[l];return c?c.series.filter(r9).map(d=>({series:a9(d),stepMs:c.stepMs})):[]}),[t]),o=y.useMemo(()=>{let l=1/0,c=-1/0;for(const{series:d}of s){const h=d.points;h.length&&(l=Math.min(l,h[0].t),c=Math.max(c,h[h.length-1].t))}return Number.isFinite(l)?p0(l,c):"less than a minute"},[s]);return Object.keys(r).length?a.jsx("div",{className:"pl-strip",role:"group","aria-label":`This machine, over the last ${o}`,children:s.map(({series:l,stepMs:c})=>a.jsx(i9,{series:l,stepMs:c,now:r[l.key],span:o},l.key))}):null}function i9({series:e,stepMs:t,now:n,span:r}){var v;const{points:s,top:o,unit:l,warnAt:c,critAt:d}=e,h=s9(e),f=n??((v=s[s.length-1])==null?void 0:v.v),p=f==null?"":gI(f,c,d),g=Math.max(...s.map(N=>N.v));return a.jsxs("div",{className:`pl-cell${p?` ${p}`:""}`,title:[`${h} · peak ${$l(g,l)} over the last ${r}`,c!=null?`over ${Du(c,l)} is uncomfortable`:"",d!=null?`over ${Du(d,l)} the machine acts`:""].filter(Boolean).join(" · "),children:[a.jsxs("div",{className:"pl-cell-head",children:[a.jsx("span",{className:"pl-cell-label",children:h}),a.jsx("span",{className:"pl-cell-now",children:f==null?"—":$l(f,l)})]}),a.jsxs("svg",{className:"pl-spark",width:Ia,height:Ir,viewBox:`0 0 ${Ia} ${Ir}`,preserveAspectRatio:"none","aria-hidden":!0,children:[a.jsx("line",{className:"pl-spark-floor",x1:0,x2:Ia,y1:Ir-Xs.b,y2:Ir-Xs.b}),a.jsx("path",{className:"pl-spark-area",d:mI(s,Ia,t,o,Ir,Xs)}),c!=null&&a.jsx("line",{className:"pl-rule warn",x1:0,x2:Ia,y1:ir(c,o,Ir,Xs),y2:ir(c,o,Ir,Xs)}),d!=null&&a.jsx("line",{className:"pl-rule hot",x1:0,x2:Ia,y1:ir(d,o,Ir,Xs),y2:ir(d,o,Ir,Xs)}),a.jsx("path",{className:"pl-spark-line",d:pI(s,Ia,t,o,Ir,Xs)})]}),a.jsxs("span",{className:"vis-hidden",children:["peak ",$l(g,l)," over the last ",r,c!=null&&`, uncomfortable over ${Du(c,l)}`,d!=null&&`, the machine acts over ${Du(d,l)}`]})]})}const yI={key:"cpu",dir:"desc"};function l9(e,t){return e.key===t?{...e,dir:e.dir==="asc"?"desc":"asc"}:{key:t,dir:t==="name"||t==="user"?"asc":"desc"}}function c9(e,t){const n=t.dir==="asc"?1:-1,r=o=>t.key==="cpu"?o.cpu:t.key==="mem"?o.mem:t.key==="rss"?o.rssBytes:t.key==="threads"?o.threads:o.uptimeSec,s=(o,l)=>{if(t.key==="name")return n*o.name.localeCompare(l.name,void 0,{sensitivity:"base"});if(t.key==="user"){const h=o.user??"",f=l.user??"";return!h||!f?h===f?0:h?-1:1:n*h.localeCompare(f,void 0,{sensitivity:"base"})}const c=r(o),d=r(l);return c==null||d==null?c==null?d==null?0:1:-1:n*(c-d)};return[...e].sort((o,l)=>s(o,l)||(l.cpu??-1)-(o.cpu??-1)||l.mem-o.mem||o.pid-l.pid)}const u9=4e3;function d9(e,t){const n=t!=null&&t.ok&&Array.isArray(t.procs)?t.procs:[];return n.length?{procs:n,total:t.total??0}:e??{procs:[],total:0}}function h9(){const[e,t]=y.useState(null);return y.useEffect(()=>{let n=!0;const r=async()=>{if(document.visibilityState!=="hidden")try{const o=await fetch("/api/system/processes?detail=1");if(!o.ok)return;const l=await o.json();n&&t(c=>d9(c,l))}catch{}};r();const s=window.setInterval(r,u9);return()=>{n=!1,window.clearInterval(s)}},[]),e}function f9(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 p9({sys:e,onClose:t}){qt("process-list");const n=ut(t),r=gt(t),[s,o]=y.useState(yI),l=h9();return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...r,role:"presentation",children:a.jsx("div",{ref:n,className:"modal pl-modal",onClick:c=>c.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"pl-modal-title",children:a.jsx(m9,{read:l,sort:s,onSort:o,sys:e,onClose:t})})}),document.body)}function m9({read:e,sort:t,onSort:n,sys:r,onClose:s}){const o=e?c9(e.procs,t):null;return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"modal-head",children:[a.jsx("span",{className:"modal-title",id:"pl-modal-title",children:"Busiest processes"}),o!=null&&o.length>0&&a.jsxs("span",{className:"pl-count",children:[o.length," of ",e.total," running"]}),a.jsx("button",{type:"button",className:"glyph-btn",onClick:s,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]}),a.jsxs("div",{className:"pl-split",children:[a.jsx("div",{className:"pl-body",children:o==null?a.jsx("p",{className:"pl-empty",children:"Reading the process list…"}):o.length===0?a.jsx("p",{className:"pl-empty",children:"Could not read the process list — retrying."}):a.jsxs("table",{className:"sd-procs pl-table",children:[a.jsx("thead",{children:a.jsxs("tr",{children:[a.jsx(Uo,{col:"cpu",label:"cpu",sort:t,onSort:n}),a.jsx(Uo,{col:"rss",label:"memory",note:"Resident set size, which is what ps and Task Manager report; macOS Activity Monitor shows a different figure.",sort:t,onSort:n}),a.jsx(Uo,{col:"threads",label:"threads",sort:t,onSort:n}),a.jsx(Uo,{col:"uptime",label:"up",sort:t,onSort:n}),a.jsx(Uo,{col:"user",label:"user",sort:t,onSort:n}),a.jsx("th",{scope:"col",className:"pl-pid-h",children:"pid"}),a.jsx(Uo,{col:"name",label:"process",note:"Command lines have anything secret-shaped removed, which is a filter and not a guarantee.",sort:t,onSort:n})]})}),a.jsx("tbody",{children:o.map(l=>a.jsxs("tr",{children:[a.jsx("td",{className:"sd-num",children:l.cpu==null?"—":l.cpu.toFixed(0)}),a.jsx("td",{className:"sd-num sd-dim",title:`${l.mem.toFixed(1)}% of installed memory`,children:ea(l.rssBytes)}),a.jsx("td",{className:"sd-num sd-dim",children:l.threads??"—"}),a.jsx("td",{className:"sd-num sd-dim",children:f9(l.uptimeSec)}),a.jsx("td",{className:"sd-dim pl-user",children:l.user??"—"}),a.jsx("td",{className:"sd-num sd-dim pl-pid",children:l.pid}),a.jsxs("td",{className:"pl-name",children:[l.name,l.cmd&&a.jsxs("span",{className:"pl-cmd",title:l.cmd,children:[" ",l.cmd]})]})]},l.pid))})]})}),a.jsx(o9,{sys:r})]})]})}function Uo(e){return a.jsx(jl,{...e,next:(t,n)=>l9(t??yI,n)})}function Kx({value:e,unit:t,cap:n}){return t?a.jsxs("span",{className:"sd-fig",children:[a.jsx("span",{className:"sd-fig-cap",children:n}),a.jsxs("span",{className:"sd-fig-read",children:[a.jsx("b",{children:e})," ",a.jsx("span",{className:"sd-fig-unit",children:t})]})]}):a.jsxs("span",{className:"sd-fig",children:[a.jsx("b",{children:e}),a.jsx("span",{className:"sd-fig-cap",children:n})]})}const g9=300;function Zl({group:e,title:t,action:n,label:r,value:s,hint:o,children:l}){const[c,d]=y.useState(!1),h=y.useRef(null),f=y.useRef(null),p=()=>{f.current!=null&&window.clearTimeout(f.current),f.current=null};y.useEffect(()=>p,[]);const g=v=>{var N;p(),!(v.detail>1||((N=window.getSelection())==null?void 0:N.isCollapsed)===!1)&&(f.current=window.setTimeout(()=>{var k,x;f.current=null,((k=window.getSelection())==null?void 0:k.isCollapsed)!==!1&&((x=h.current)==null||x.focus({preventScroll:!0}),d(!0))},g9))};return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"sd-reading",onClick:g,children:[a.jsx("button",{ref:h,type:"button",className:"sd-open",onClick:v=>{v.stopPropagation(),p(),d(!0)},title:n,"aria-label":s==null?`${r}: show history`:`${r}: show history, now ${s}`,"aria-describedby":o?`sd-hint-${e}`:void 0,children:a.jsxs("span",{className:"sd-h","aria-hidden":!0,children:[r," ",a.jsx("i",{className:"sd-row-more",children:"›"}),s!=null&&a.jsx("span",{className:"sd-h-val",children:s})]})}),l]}),o&&a.jsx("span",{id:`sd-hint-${e}`,className:"vis-hidden",children:o}),c&&a.jsx(Q7,{group:e,title:t,onClose:()=>d(!1)})]})}function _d({label:e,value:t,pct:n,tone:r="calm",note:s,mark:o,title:l,trackLabel:c}){return a.jsxs("div",{className:"sd-row",title:l,children:[a.jsxs("div",{className:"sd-row-head",children:[a.jsx("span",{className:"sd-row-label",children:e}),a.jsx("span",{className:"sd-row-val",children:t})]}),a.jsxs("span",{className:"sd-track",role:c?"img":void 0,"aria-label":c,children:[a.jsx("span",{className:`sd-fill${r==="calm"?"":` ${r}`}`,style:{transform:`scaleX(${n<=0?0:Math.max(1,Math.min(100,n))/100})`}}),o!=null&&o>0&&o<100&&a.jsx("span",{className:"sd-mark",style:{left:`${o}%`},"aria-hidden":!0})]}),s&&a.jsx("div",{className:"sd-note",children:s})]})}function y9(e,t,n){if(n<=0||eh(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 ra=4,Bn=8;function m0(e,t,n){const r=n.width-Bn-(e.right+ra),s=e.left-ra-Bn,o=t.width<=r||r>=s?"right":"left",l=o==="right"?e.right+ra:e.left-ra-t.width,c=n.height-Bn*2,d=t.height<=c,h=d?t.height:Math.max(0,c),f=Math.max(Bn,Math.min(e.top,n.height-Bn-h)),p=Math.max(Bn,Math.min(l,n.width-Bn-t.width));return{top:f,left:p,side:o,maxHeight:d?null:h}}function w9(e,t,n){const r=n.height-Bn-(e.bottom+ra),s=e.top-ra-Bn,o=t.height<=r||r>=s?"below":"above",l=o==="below"?r:s,c=t.height<=l,d=c?t.height:Math.max(0,l),h=o==="below"?e.bottom+ra:e.top-ra-d,f=Math.max(Bn,Math.min(e.right-t.width,n.width-Bn-t.width));return{top:Math.max(Bn,h),left:f,side:o,maxHeight:c?null:d}}function v9(e,t,n){return!(!e||t!=null&&t.contains(e)||n!=null&&n.contains(e))}function wI(e,t,n){const r=y.useRef(t);r.current=t;const s=y.useRef(n);s.current=n,y.useEffect(()=>{const o=l=>{v9(l.target,e.current,r.current())&&s.current()};return window.addEventListener("pointerdown",o,!0),()=>window.removeEventListener("pointerdown",o,!0)},[e])}const vI='[role="menuitem"]';function mS(e){return e?Array.from(e.querySelectorAll(vI)).filter(t=>!t.disabled):[]}function dh({anchorId:e,boundaryId:t,id:n,className:r,role:s,labelledBy:o,start:l="first",focusRef:c,fallbackFocus:d,onClose:h,children:f}){const p=y.useRef(h);p.current=h;const g=y.useRef(d);g.current=d;const v=ut(()=>{var b;(b=document.getElementById(e))==null||b.focus(),p.current()},{popover:!0,focusRef:c}),N=y.useCallback(()=>{var A,U,L;const b=v.current;if(!b)return;const _=document.getElementById(e);if(!_){p.current();return}if(_.getClientRects().length===0){b.contains(document.activeElement)&&((U=(A=g.current)==null?void 0:A.call(g))==null||U.focus()),p.current();return}const E=_.getBoundingClientRect(),R=t?(L=document.getElementById(t))==null?void 0:L.getBoundingClientRect():null;if(R&&(E.bottom<=R.top||E.top>=R.bottom)){b.contains(document.activeElement)&&_.focus({preventScroll:!0}),p.current();return}b.style.maxHeight="";const C=w9(E,{width:b.offsetWidth,height:b.offsetHeight},{width:window.innerWidth,height:window.innerHeight});b.style.top=`${C.top}px`,b.style.left=`${C.left}px`,b.style.maxHeight=C.maxHeight==null?"":`${C.maxHeight}px`,b.dataset.side=C.side},[e,t,v]);y.useLayoutEffect(()=>{N()}),y.useEffect(()=>{const b=_=>{var E;(E=v.current)!=null&&E.contains(_.target)||N()};return window.addEventListener("scroll",b,!0),window.addEventListener("resize",N),()=>{window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",N)}},[N,v]),wI(v,()=>document.getElementById(e),h),y.useEffect(()=>{var _;if(s!=="menu")return;const b=mS(v.current);(_=l==="last"?b[b.length-1]:b[0])==null||_.focus()},[]);const k=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 E=mS(v.current),R=y9(b,E.indexOf(document.activeElement),E.length);R.kind==="focus"&&(b.preventDefault(),E[R.index].focus())}b.key.length===1&&b.stopPropagation()},x=b=>{b.target.closest("button, input, select, textarea, code")||b.preventDefault()},j=b=>{if(s!=="menu"||b.pointerType==="touch")return;const _=b.target.closest(vI);_&&!_.disabled&&document.activeElement!==_&&_.focus({preventScroll:!0})};return Lt.createPortal(a.jsx("div",{ref:v,id:n,className:`anchored-popover${r?` ${r}`:""}`,role:s,"aria-labelledby":o,onKeyDown:k,onMouseDown:x,onPointerMove:j,children:f}),document.body)}function x9({network:e}){const{down:t,up:n,api:r,route:s}=e,[o,l]=y.useState(!1),c=r&&r.ms!=null?ch(r.ms):null,d=t!=null&&n!=null;return a.jsxs("div",{className:"sd-section",role:"group","aria-label":"Network",children:[a.jsxs(Zl,{group:"network",title:"Network history",action:"Show network history",label:"Network",children:[(d||c)&&a.jsxs("div",{className:"sd-figs sd-figs-named",children:[d&&[["Download",t],["Upload",n]].map(([h,f])=>{const p=d0(f);return a.jsx(Kx,{value:p.value,unit:p.unit,cap:h},h)}),c&&a.jsx(Kx,{value:c.value,unit:c.unit,cap:"Claude API"})]}),!d&&a.jsx("div",{className:"sd-note",children:"measuring…"}),r&&r.ms==null&&a.jsx("div",{className:"sd-note sd-note-warn",children:"Can’t reach Claude"})]}),s&&a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",className:"sd-detail",id:"sd-conn","aria-expanded":o,"aria-haspopup":"dialog",onClick:()=>l(h=>!h),children:["Connection details",s.relay&&a.jsx("span",{className:"sd-route-relay",children:" · relayed"}),a.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),o&&a.jsx(b9,{route:s,api:r,onClose:()=>l(!1)})]})]})}function b9({route:e,api:t,onClose:n}){return a.jsxs(dh,{anchorId:"sd-conn",boundaryId:"system-panel",id:"sd-conn-pop",className:"sd-pop",role:"dialog",labelledBy:"sd-conn-title",onClose:n,children:[a.jsx("p",{className:"sd-pop-title",id:"sd-conn-title",children:"Connection"}),a.jsxs("dl",{className:"sd-pop-rows",children:[a.jsxs("div",{className:"sd-pop-row",children:[a.jsx("dt",{children:e.to==="claude"?"Traffic to Claude":"Internet traffic"}),a.jsxs("dd",{children:["through ",V7(e)]})]}),e.relay&&a.jsxs("div",{className:"sd-pop-row",children:[a.jsx("dt",{children:"Relay"}),a.jsxs("dd",{children:[a.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&&a.jsxs("div",{className:"sd-pop-row",children:[a.jsx("dt",{children:"Round trip"}),a.jsx("dd",{children:t.ms==null?`${t.host} did not answer`:`${Xl(ch(t.ms))} to open a connection to ${t.host}`})]}),a.jsxs("div",{className:"sd-pop-row",children:[a.jsx("dt",{children:"Throughput"}),a.jsx("dd",{children:"every interface on this machine, not this path alone"})]})]})]})}function gS({usageOpen:e,leaving:t,sub:n,flag:r,onClose:s,children:o}){return a.jsxs("aside",{className:`sysdetail${e?" shifted":""}${t?" leaving":""}`,id:"system-panel","aria-labelledby":"sd-title",children:[a.jsxs("div",{className:"sd-top",children:[a.jsxs("div",{className:"sd-head",children:[a.jsx("h2",{className:"sd-title",id:"sd-title",children:"This machine"}),n&&a.jsx("span",{className:"sd-sub",children:n}),a.jsx("button",{type:"button",className:"glyph-btn sd-close",onClick:s,"aria-label":"Close",title:"Close",children:"×"})]}),r&&a.jsx("p",{className:"sd-flag",children:r})]}),o]})}function k9({usageOpen:e,leaving:t,onClose:n}){const r=K7();if(!r||r.cpu==null||!r.memory)return a.jsx(gS,{usageOpen:e,leaving:t,onClose:n,children:a.jsx("div",{className:"sd-note",children:"reading this machine…"})});const{memory:s,swap:o,perCore:l,loadavg:c,cores:d,uptimeSec:h,platform:f,thermal:p,network:g,cpu:v}=r;return a.jsxs(gS,{usageOpen:e,leaving:t,sub:`up ${W7(h)} · ${d} cores`,flag:H7(r),onClose:n,children:[a.jsx(N9,{cpu:v,perCore:l,loadavg:c,cores:d}),a.jsx(j9,{memory:s,swap:o,platform:f}),g&&a.jsx(x9,{network:g}),a.jsx(S9,{thermal:p}),a.jsx(_9,{sys:r})]})}function N9({cpu:e,perCore:t,loadavg:n,cores:r}){const s=!!t&&t.length>0;return!s&&!n?null:a.jsxs("div",{className:"sd-section sd-cpu",role:"group","aria-label":"CPU",children:[s&&a.jsx(Zl,{group:"cores",title:"Core history",action:"Show core history",label:"CPU",value:e==null?null:`${Math.round(e)}%`,children:a.jsx("div",{className:"sd-cores",role:"img","aria-label":`${t.length} logical cores, busiest at ${Math.round(Math.max(...t))}%`,children:t.map((o,l)=>a.jsx("span",{className:"sd-core",title:`logical core ${l+1} · ${o}% busy`,children:a.jsx("span",{className:"sd-core-fill",style:{transform:`scaleY(${Math.max(2,o)/100})`}})},l))})}),n&&a.jsxs(Zl,{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:[a.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((o,l)=>a.jsx(Kx,{value:o.toFixed(2),cap:["1m","5m","15m"][l]},l))}),n[0]>r&&a.jsx("div",{className:"sd-note",children:`${(n[0]/r).toFixed(1)}× more work queued than cores to run it`})]})]})}function j9({memory:e,swap:t,platform:n}){const r=e.total-e.available,s=n==="win32"?"Commit":"Swap",o=t&&t.total>0?t.used/t.total*100:0;return a.jsx("div",{className:"sd-section",role:"group","aria-label":"Memory",children:a.jsxs(Zl,{group:"memory",title:"Memory history",action:"Show memory history",label:"Memory",children:[a.jsx(_d,{label:"Physical",value:a.jsxs(a.Fragment,{children:[a.jsx("b",{children:ea(r)})," of ",ea(e.total)]}),pct:e.usedPct,tone:e.usedPct>=90?"warn":"calm",note:`${ea(e.available)} available`}),t&&t.total>0&&a.jsx(_d,{label:s,value:a.jsxs(a.Fragment,{children:[a.jsx("b",{children:ea(t.used)})," of ",ea(t.total)]}),pct:o,tone:o>=90?"warn":"calm"})]})})}function S9({thermal:e}){if(!e)return null;const t=e.throttle?z7(e.throttle,e.heldBack):null;return a.jsx("div",{className:"sd-section",role:"group","aria-label":"Thermal",children:a.jsxs(Zl,{group:"thermal",title:"Thermal history",action:"Show thermal history",label:"Thermal",children:[e.celsius.map(n=>a.jsx(_d,{label:n.label,value:a.jsxs(a.Fragment,{children:[a.jsx("b",{children:n.celsius})," °C"]}),pct:n.celsius/n.critAt*100,mark:n.warnAt/n.critAt*100,tone:U7(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&&a.jsx(_d,{label:"Throttling",value:a.jsx("b",{children:t.value}),pct:t.pct,tone:t.tone,note:t.note})]})})}function _9({sys:e}){const[t,n]=y.useState(!1);return a.jsxs("div",{className:"sd-section sd-door-section",children:[a.jsx("button",{type:"button",className:"sd-open sd-door",onClick:()=>n(!0),"aria-label":"Busiest processes: show every process the deck is watching",children:a.jsxs("span",{className:"sd-door-plate",children:[a.jsxs("span",{className:"sd-door-name",children:["Busiest processes",a.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),a.jsx("span",{className:"sd-door-sub",children:"every process, with its command line"})]})}),t&&a.jsx(p9,{sys:e,onClose:()=>n(!1)})]})}function g0(e){const t={inputTokens:e.i,outputTokens:e.o,cacheReadTokens:e.cr,cacheCreateTokens:e.cc,cacheCreate1hTokens:e.c1h,cacheCreate5mTokens:e.c5m},n=e.s?Object.entries(e.s):[];return n.length>0&&(t.bySpeed=Object.fromEntries(n.map(([r,s])=>[r,g0(s)]))),t}function yS(e){const t=r=>({...r,cacheCreate1hTokens:0,cacheCreate5mTokens:0}),n=t(g0(e));return n.bySpeed&&(n.bySpeed=Object.fromEntries(Object.entries(n.bySpeed).map(([r,s])=>[r,t(s)]))),n}function xI(e){return e.i+e.o+e.cr+e.cc}function bI(e,t){var n;e.i+=t.i,e.o+=t.o,e.cr+=t.cr,e.cc+=t.cc,e.c1h+=t.c1h,e.c5m+=t.c5m;for(const[r,s]of Object.entries(t.s??{}))bI((n=e.s??(e.s={}))[r]??(n[r]={i:0,o:0,cr:0,cc:0,c1h:0,c5m:0}),s);return e}function wS(e,t,n){let r=0,s=0,o=0;const l=[];for(const c of Zd(e)){if(!ca(t,n,c.speed)){const d=c.usage,h=d.inputTokens+d.outputTokens+d.cacheReadTokens+d.cacheCreateTokens;h>0&&(o+=h,l.push(c.speed));continue}r+=bd(c.usage,t,c.speed,n).total,s+=bd(c.usage,t,aa,n).total}return{atSpeed:r,atStandard:s,unpriced:o,unpricedSpeeds:l}}function vS(e){let t=0;for(const n of Object.values(e))t+=xI(n);return t}function E9(e){const t=s=>typeof s=="number"&&Number.isFinite(s)?s:0,n=new Map,r=e&&Array.isArray(e.days)?e.days:[];for(const s of r){const o=typeof s.period=="string"?s.period:"",l=Array.isArray(s.modelBreakdowns)?s.modelBreakdowns:[];for(const c of l){const d=typeof c.modelName=="string"?c.modelName:"";if(!o||!/claude/i.test(d)||c.missingPricing===!0)continue;const h=`${o}|${d}`,f=n.get(h),p=f?f.usage:{inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreateTokens:0,cacheCreate1hTokens:0,cacheCreate5mTokens:0};p.inputTokens+=t(c.inputTokens),p.outputTokens+=t(c.outputTokens),p.cacheReadTokens+=t(c.cacheReadTokens),p.cacheCreateTokens+=t(c.cacheCreationTokens),f?f.cost+=t(c.cost):n.set(h,{cost:t(c.cost),usage:p})}}return n}function T9(e,t,n,r=Date.now()){const s=new Map;for(const A of e){const U={},L=F=>{for(const[O,I]of Object.entries(F))bI(U[O]??(U[O]={i:0,o:0,cr:0,cc:0,c1h:0,c5m:0}),I)};for(const F of A.projects)L(F.models);A.unattributed&&L(A.unattributed);for(const[F,O]of Object.entries(U)){if(!O.s)continue;const{atSpeed:I,atStandard:B}=wS(yS(O),F,r);if(!(I>0&&B>0))continue;let M=s.get(A.day);M||(M=new Map,s.set(A.day,M)),M.set(F,I/B),M.has(cs(F))||M.set(cs(F),I/B)}}const o=(A,U)=>{const L=s.get(A);return(L==null?void 0:L.get(U))??(L==null?void 0:L.get(cs(U)))??1},l=new Map;let c=0,d=0;for(const[A,U]of n){const L=A.indexOf("|"),F=A.slice(0,L),O=A.slice(L+1),I=Xd(U.usage,O,r).total*o(F,O);if(!(I>0&&U.cost>0))continue;c+=U.cost,d+=I;let B=l.get(F);B||(B=new Map,l.set(F,B)),B.set(O,U.cost/I)}const h=d>0,f=(A,U)=>{const L=l.get(A);return(L==null?void 0:L.get(U))??(L==null?void 0:L.get(cs(U)))??null},p=new Set,g=(A,U)=>{let L=0,F=0;for(const[O,I]of Object.entries(A)){if(ca(O,r)){const M=U(O),$=wS(M===null?g0(I):yS(I),O,r);L+=M===null?$.atSpeed:$.atSpeed*M,F+=$.unpriced;for(const P of $.unpricedSpeeds)p.add(`${O} (${P})`);continue}const B=xI(I);B>0&&(F+=B,p.add(O))}return{cost:L,unpriced:F}},v=new Map,N=[];for(const A of e){const U=new Map,L=new Map;let F=0;for(const O of A.projects){const{cost:I,unpriced:B}=g(O.models,$=>f(A.day,$));U.set(O.path,(U.get(O.path)??0)+I),B>0&&L.set(O.path,(L.get(O.path)??0)+B),F+=I;let M=v.get(O.path);M||(M={path:O.path,cost:0,tokens:0,unpricedTokens:0},v.set(O.path,M)),M.cost+=I,M.tokens+=vS(O.models),M.unpricedTokens+=B}N.push({day:A.day,total:F,byPath:U,unpricedByPath:L})}const k=[...v.values()].sort((A,U)=>U.cost-A.cost||U.tokens-A.tokens),x=k.reduce((A,U)=>A+U.cost,0),j=k.reduce((A,U)=>A+U.tokens,0),b=k.reduce((A,U)=>A+U.unpricedTokens,0),_=h?c/d:null,E=t?vS(t):0,R=t?g(t,()=>_):{cost:0,unpriced:0},C=R.cost>0||E>0?{cost:R.cost,tokens:E,unpricedTokens:R.unpriced}:null;return{projects:k,totalCost:x,totalTokens:j,unpricedTokens:b,perDay:N,unattributed:C,unpricedModels:[...p].sort(),calibrated:h,reconciled:h&&b===0}}function Or(e,t,n=qe){return t>0?e>0?`${n(e)}+`:ms:n(e)}function zo(e){return e>0?`${it(e)} of these tokens are on an unpriced model, so this is a floor`:void 0}function C9(e){if(e.length===0)return null;const t=e.length===1,n=t?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;return t?`${n} is ${ms}: this build holds no published rate for it, so its tokens are counted and its dollars are not.`:`${n} are ${ms}: this build holds no published rate for them, so their tokens are counted and their dollars are not.`}const A9={phase:"running"},R9={phase:"failed"},M9={gen:0,report:null,error:null,early:null};function $9(e,t){var n,r;if(t.type!=="start"&&t.gen!==e.gen)return e;switch(t.type){case"start":return{...e,gen:t.gen,error:null,early:null};case"report":{const s=((n=e.early)==null?void 0:n.gen)===t.gen?e.early.cost:A9;return{...e,report:{gen:t.gen,days:t.days,data:t.data,cost:s},early:null}}case"reportFailed":return{...e,report:null,error:t.message,early:null};case"cost":return((r=e.report)==null?void 0:r.gen)===t.gen?{...e,report:{...e.report,cost:t.cost}}:{...e,early:{gen:t.gen,cost:t.cost}}}}function I9(e){var t;return((t=e.report)==null?void 0:t.gen)!==e.gen&&e.error===null}function O9(e){const t=e;return t&&t.ok!==!1?{phase:"ready",range:t}:R9}function L9(e){return`${e.getFullYear()}${String(e.getMonth()+1).padStart(2,"0")}${String(e.getDate()).padStart(2,"0")}`}function P9(e,t,n=Date.now()){const r=t===0?60:t,s=new Date(n),o=Vx(r,s),l=L9(s);return{report:`/api/account-projects?num=${e}&days=${t}`,ccusage:`/api/ccusage?since=${o}&until=${l}`}}function D9({num:e,days:t,gen:n,dispatch:r,get:s=(l,c)=>fetch(l,c),now:o=Date.now()}){const l=P9(e,t,o),c={credentials:"same-origin"};s(l.report,c).then(d=>d.ok?d.json():Promise.reject(new Error(`HTTP ${d.status}`))).then(d=>r({type:"report",gen:n,days:t,data:d}),d=>r({type:"reportFailed",gen:n,message:(d==null?void 0:d.message)||"Could not load"})),s(l.ccusage,c).then(d=>d.ok?d.json():null).catch(()=>null).then(d=>r({type:"cost",gen:n,cost:O9(d)}))}async function eo(e,t=500){var r;if(!e)return!1;let n=!1;try{n=await Promise.race([((r=navigator.clipboard)==null?void 0:r.writeText(e).then(()=>!0))??Promise.resolve(!1),new Promise(s=>window.setTimeout(()=>s(!1),t))])}catch{n=!1}if(n)return!0;try{const s=document.createElement("textarea");s.value=e,s.setAttribute("readonly",""),s.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(s),s.select(),n=document.execCommand("copy"),s.remove()}catch{n=!1}return n}function kI(e){return/^[A-Za-z]:[\\/]$/.test(e)?e:e.replace(/[\\/]+$/,"")}function Dp(e){const t=kI(e).replace(/\\/g,"/");return/^[A-Za-z]:\//.test(t)?t.toLowerCase():t}function xS(e){if(!e)return e;const t=kI(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 F9(e,t){const n=Dp(e);let r;for(const s of t){const o=Dp(s.path);!o||o===n||!n.startsWith(`${o}/`)||(!r||Dp(r.path).length<o.length)&&(r=s)}return r==null?void 0:r.label}function Yx(e){return e===0?"all time":e===1?"today":`the last ${e} days`}function B9(e){return e===1?"No work attributed to this account yet today.":`No work attributed to this account in ${Yx(e)}.`}function q9(e){return e===1?7:e===7?30:e===30?0:null}function U9(e,t){return e!==1&&t>0}const z9=[{days:1,label:"Today"},{days:7,label:"7d"},{days:30,label:"30d"},{days:0,label:"All"}],Wo=["var(--usage-blue)","var(--usage-teal)","var(--usage-lime)","var(--usage-purple)","var(--usage-indigo)","var(--usage-pink)","var(--usage-orange)","var(--usage-zinc)"],W9="var(--usage-zinc)",Fp=6,H9=1600;function V9(e){const t=qe(e),n=/^\$(\d{4,})$/.exec(t);return n?`$${Number(n[1]).toLocaleString("en-US")}`:t}function Fu(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 G9(e){const t=/^\d{4}-(\d{2})-(\d{2})$/.exec(e);return t?`${Number(t[1])}/${Number(t[2])}`:e}function K9(e){const t=Math.max(1,Math.ceil(e/6));return n=>n===0||n===e-1||n%t===0}function Bp(e){if(!e)return"";try{return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return""}}function Y9({num:e,name:t,onClose:n}){var P,G,K,q;qt("account-projects");const[r,s]=y.useState(1),[o,l]=y.useReducer($9,M9),c=((P=o.report)==null?void 0:P.data)??null,d=((G=o.report)==null?void 0:G.days)??r,h=((K=o.report)==null?void 0:K.cost.phase)==="ready"?o.report.cost.range:null,f=((q=o.report)==null?void 0:q.cost.phase)==="running",[p,g]=y.useState(null),[v,N]=y.useState(()=>new Set),k=I9(o),x=o.error,[j,b]=y.useState(null),_=y.useRef(void 0),E=y.useRef(!0);y.useEffect(()=>()=>{E.current=!1,window.clearTimeout(_.current)},[]);const R=y.useRef(null),C=ut(n,{focusRef:R}),A=gt(n),U=y.useRef(0);y.useEffect(()=>{const H=++U.current;l({type:"start",gen:H}),g(null),N(new Set),D9({num:e,days:r,gen:H,dispatch:l})},[e,r]);const L=y.useMemo(()=>{const H=Date.now();if(!c)return null;const D=T9(c.daily??[],c.unattributed,E9(h),H),W=be=>be.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||be||"(unknown)",J=new Map;for(const be of D.projects)J.set(W(be.path),(J.get(W(be.path))??0)+1);const V=be=>{const oe=W(be);if((J.get(oe)??0)<=1)return oe;const je=be.replace(/[\\/]+$/,"").split(/[\\/]/).slice(-2,-1)[0];return je?`${je}/${oe}`:oe},X=D.projects.map(be=>({path:be.path,label:V(be.path)})),Y=be=>({path:be.path,label:V(be.path),parentLabel:F9(be.path,X),cost:be.cost,tokens:be.tokens,unpricedTokens:be.unpricedTokens}),Z=Wo[Fp%Wo.length],ee=new Map,ne=[],se=D.projects.slice(0,Fp),pe=D.projects.slice(Fp);se.forEach((be,oe)=>{ee.set(be.path,Wo[oe%Wo.length]),ne.push({key:be.path,...Y(be),color:Wo[oe%Wo.length]})}),pe.length&&ne.push({key:"__other__",label:`Other · ${pe.length} project${pe.length>1?"s":""}`,cost:pe.reduce((be,oe)=>be+oe.cost,0),tokens:pe.reduce((be,oe)=>be+oe.tokens,0),unpricedTokens:pe.reduce((be,oe)=>be+oe.unpricedTokens,0),color:Z,muted:!0,members:pe.map(Y)});const ke=D.totalCost,ae=D.totalTokens,fe=ke>0&&D.unpricedTokens===0?"cost":"tokens",me=fe==="cost"?ke:ae,he=ne.map(be=>be.color),ge=D.perDay.map(be=>{const oe=new Map;for(const[Oe,Ue]of be.byPath){const Be=ee.get(Oe)??Z;oe.set(Be,(oe.get(Be)??0)+Ue)}const je=new Map;let $e=0;for(const[Oe,Ue]of be.unpricedByPath){const Be=ee.get(Oe)??Z;je.set(Be,(je.get(Be)??0)+Ue),$e+=Ue}return{day:be.day,total:be.total,costByColor:oe,unpricedByColor:je,unpriced:$e}}),ue=ge.reduce((be,oe)=>Math.max(be,oe.total),0);return{projectCount:D.projects.length,rows:ne,totalCost:ke,totalTokens:ae,basis:fe,denom:me,un:D.unattributed,chart:ge,maxDay:ue,colorOrder:he,unpricedTokens:D.unpricedTokens,unpricedNote:C9(D.unpricedModels),calibrated:D.calibrated,reconciled:D.reconciled}},[c,h]),F=(H,D)=>{eo(H).then(W=>{E.current&&(window.clearTimeout(_.current),b({path:H,label:D,ok:W}),_.current=window.setTimeout(()=>{E.current&&b(null)},H9))})},O=H=>j!=null&&j.ok&&j.path===H?"Copied":"Copy",I=c!=null&&c.trackedSince?`Tracked since ${Bp(c.trackedSince)}`:"Tracking starts with this version",B=Yx(d),M=q9(d),$=k&&!!c;return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...A,role:"presentation",children:a.jsxs("div",{ref:C,className:"modal ap-proj-modal",onClick:H=>H.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"ap-proj-title ap-proj-sub",children:[a.jsxs("header",{className:"ap-proj-head",children:[a.jsxs("div",{className:"ap-proj-titlewrap",children:[a.jsx("div",{className:"ap-proj-title",id:"ap-proj-title",children:"Projects"}),a.jsx("div",{className:"ap-proj-sub",id:"ap-proj-sub",title:t,children:t})]}),a.jsx("div",{className:"uh-range",role:"group","aria-label":"Range",children:z9.map(H=>a.jsx("button",{type:"button",className:"uh-range-btn","aria-pressed":r===H.days,onClick:()=>s(H.days),children:H.label},H.days))}),a.jsx("button",{ref:R,className:"glyph-btn ap-proj-close",onClick:n,"aria-label":"Close",children:"×"})]}),a.jsxs("div",{className:`ap-proj-body${$?" refreshing":""}`,"aria-busy":k,children:[k&&!c&&a.jsx("div",{className:"ap-proj-state",children:"Loading…"}),!k&&x&&a.jsxs("div",{className:"ap-proj-state ap-proj-error",children:["Couldn’t load this report: ",x]}),!x&&L&&a.jsx(a.Fragment,{children:L.rows.length===0?a.jsxs("div",{className:"ap-proj-state",children:[$?"Updating…":B9(d),M!=null&&a.jsx("div",{className:"ap-proj-widen-wrap",children:a.jsxs("button",{type:"button",className:"ap-proj-copy",onClick:()=>s(M),children:["Show ",Yx(M)]})}),a.jsxs("div",{className:"ap-proj-note",children:[I,". Only work from this version onward can be tied to an account."]})]}):a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"ap-proj-bar",role:"img","aria-label":`Share of ${L.basis==="cost"?qe(L.totalCost):`${it(L.totalTokens)} tokens`} across ${L.projectCount} project${L.projectCount>1?"s":""}`,children:L.rows.map(H=>{const D=L.basis==="cost"?H.cost:H.tokens,W=L.denom>0?D/L.denom*100:0;if(W<=0)return null;const J=L.basis==="cost"?Fu(H.cost,L.totalCost):`${Fu(H.tokens,L.totalTokens)} of tokens`;return a.jsx("span",{className:"ap-proj-seg",style:{width:`${W}%`,background:H.color},title:`${H.label} · ${Or(H.cost,H.unpricedTokens)} · ${J}${H.tokens?` · ${it(H.tokens)} tokens`:""}`},H.key)})}),a.jsxs("div",{className:"ap-proj-totals",children:[a.jsx("span",{className:"ap-proj-total-cost",title:zo(L.unpricedTokens),children:Or(L.totalCost,L.unpricedTokens)}),a.jsxs("span",{className:"ap-proj-total-tok",children:[it(L.totalTokens)," tokens"]}),a.jsxs("span",{className:"ap-proj-total-win",children:["· ",$?"updating…":B]}),f&&a.jsx("span",{className:"ap-proj-total-pending",children:"Reconciling cost…"})]}),L.unpricedNote&&a.jsx("div",{className:"ap-proj-note",children:L.unpricedNote}),U9(d,L.chart.length)&&a.jsxs("div",{className:"ap-proj-days",children:[a.jsxs("div",{className:"ap-proj-days-cap",children:["By day",L.chart.length>1?" · click a bar":""]}),a.jsx("div",{className:"ap-proj-days-plot",role:"group","aria-label":`Spend across ${L.chart.length} day${L.chart.length>1?"s":""}`,children:L.chart.map(H=>{const D=L.maxDay>0?H.total/L.maxDay*100:0,W=p===H.day,J=L.rows.map(X=>({label:X.label,c:H.costByColor.get(X.color)??0,u:H.unpricedByColor.get(X.color)??0})).filter(X=>X.c>0||X.u>0),V=`${Bp(Date.parse(`${H.day}T00:00:00`))}, ${Or(H.total,H.unpriced)}. ${J.map(X=>`${X.label} ${Or(X.c,X.u)}`).join(", ")}`;return a.jsx("button",{type:"button",className:`ap-proj-day${W?" selected":""}`,"aria-pressed":W,"aria-label":V,title:`${H.day} · ${Or(H.total,H.unpriced)}`,onClick:()=>g(X=>X===H.day?null:H.day),children:a.jsx("span",{className:"ap-proj-col",style:{height:`${D}%`},children:L.colorOrder.map((X,Y)=>{const Z=H.costByColor.get(X)??0;return Z<=0||H.total<=0?null:a.jsx("span",{className:"ap-proj-colseg",style:{height:`${Z/H.total*100}%`,background:X}},Y)})})},H.day)})}),(()=>{const H=K9(L.chart.length);return a.jsx("div",{className:"ap-proj-days-axis","aria-hidden":"true",children:L.chart.map((D,W)=>a.jsx("div",{className:"ap-proj-axis-cell",children:H(W)?G9(D.day):""},D.day))})})(),(()=>{const H=p?L.chart.find(W=>W.day===p):null;if(!H)return null;const D=L.rows.map(W=>({r:W,c:H.costByColor.get(W.color)??0,u:H.unpricedByColor.get(W.color)??0})).filter(W=>W.c>0||W.u>0);return a.jsxs("div",{className:"ap-proj-day-detail",children:[a.jsxs("div",{className:"ap-proj-day-detail-head",children:[a.jsx("span",{children:Bp(Date.parse(`${H.day}T00:00:00`))}),a.jsx("span",{className:"ap-proj-day-detail-total",title:zo(H.unpriced),children:Or(H.total,H.unpriced)})]}),D.map(({r:W,c:J,u:V})=>a.jsxs("div",{className:"ap-proj-day-detail-row",children:[a.jsx("span",{className:"ap-proj-dot",style:{background:W.color},"aria-hidden":"true"}),a.jsx("span",{className:"ap-proj-day-detail-name",children:W.label}),a.jsx("span",{className:"ap-proj-day-detail-cost",title:zo(V),children:Or(J,V)})]},W.key))]})})()]}),a.jsx("ul",{className:"ap-proj-list",children:L.rows.map((H,D)=>{const W=L.basis==="cost"?H.cost:H.tokens,J=L.denom>0?W/L.denom*100:0,V=v.has(H.key),X=`ap-proj-details-${D}`,Y=V&&(!!H.path||!!H.members),Z=H.members?`${V?"Hide":"Show"} the ${H.members.length} project${H.members.length>1?"s":""} folded into Other`:`${V?"Hide":"Show"} location for ${H.label}`;return a.jsxs("li",{className:`ap-proj-row${H.muted?" muted":""}${V?" expanded":""}`,children:[a.jsx("span",{className:"ap-proj-dot",style:{background:H.color},"aria-hidden":"true"}),a.jsxs("span",{className:"ap-proj-name",children:[H.label,H.parentLabel&&a.jsxs("span",{className:"ap-proj-parent",children:[" · in ",H.parentLabel]})]}),a.jsx("span",{className:"ap-proj-track",title:L.basis==="cost"?`${Fu(H.cost,L.totalCost)} of tracked cost`:`${Fu(H.tokens,L.totalTokens)} of tracked tokens`,children:a.jsx("span",{className:"ap-proj-fill",style:{width:`${J}%`,background:H.color}})}),a.jsx("span",{className:"ap-proj-cost",title:zo(H.unpricedTokens),children:Or(H.cost,H.unpricedTokens)}),a.jsx("span",{className:"ap-proj-tok",children:it(H.tokens)}),a.jsx("button",{type:"button",className:"glyph-btn ap-proj-info","aria-expanded":V,"aria-controls":Y?X:void 0,"aria-label":Z,onClick:()=>N(ee=>{const ne=new Set(ee);return ne.has(H.key)?ne.delete(H.key):ne.add(H.key),ne}),children:"ⓘ"}),V&&H.path&&a.jsxs("div",{className:"ap-proj-details",id:X,children:[a.jsx("code",{className:"ap-proj-path",children:xS(H.path)}),a.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${O(H.path)} location for ${H.label}`,onClick:()=>F(H.path,H.label),children:O(H.path)})]}),V&&H.members&&a.jsx("div",{className:"ap-proj-details ap-proj-other-members",id:X,children:H.members.map(ee=>a.jsxs("div",{className:"ap-proj-other-member",children:[a.jsxs("div",{className:"ap-proj-other-name",children:[ee.label,ee.parentLabel&&a.jsxs("span",{className:"ap-proj-parent",children:[" · in ",ee.parentLabel]})]}),a.jsx("code",{className:"ap-proj-path",children:xS(ee.path)}),a.jsx("span",{className:"ap-proj-cost",title:zo(ee.unpricedTokens),children:Or(ee.cost,ee.unpricedTokens)}),a.jsx("span",{className:"ap-proj-tok",children:it(ee.tokens)}),a.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${O(ee.path)} location for ${ee.label}`,onClick:()=>F(ee.path,ee.label),children:O(ee.path)})]},ee.path))})]},H.key)})}),L.un&&a.jsxs("div",{className:"ap-proj-unattributed",children:[a.jsx("span",{className:"ap-proj-dot",style:{background:W9},"aria-hidden":"true"}),a.jsxs("div",{className:"ap-proj-un-labels",children:[a.jsx("span",{className:"ap-proj-un-title",children:"Unattributed usage"}),a.jsx("span",{className:"ap-proj-un-tag",children:"Excluded from the project totals"})]}),a.jsx("span",{className:"ap-proj-un-cost",title:zo(L.un.unpricedTokens),children:Or(L.un.cost,L.un.unpricedTokens,V9)}),a.jsx("span",{className:"ap-proj-un-tok",children:it(L.un.tokens)}),a.jsx("div",{className:"ap-proj-note",children:"Work no account could be tied to — from before tracking, or a gap."})]}),a.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:j&&(j.ok?`Copied the location of ${j.label}`:`Could not copy the location of ${j.label} — select it and copy it by hand`)}),a.jsxs("div",{className:"ap-proj-foot",children:[f?"Dollars estimated · ccusage still running":L.reconciled?"Dollars from ccusage · split by activity":L.calibrated?"Dollars from ccusage for the priced models · split by activity":h?"Dollars estimated · ccusage could not price this window":"Dollars estimated · ccusage unavailable"," · ",I]})]})})]})]})}),document.body)}function yi(e,t){return V$(t-Math.floor(e/1e3))}function X9(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 y0(){return a.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:[a.jsx("path",{d:"M7 1.9 12.9 12H1.1Z"}),a.jsx("path",{d:"M7 5.6v2.9"}),a.jsx("path",{d:"M7 10.3v.05"})]})}function Z9({anchorId:e,boundaryId:t,issue:n,who:r,fetchedAt:s,nowSec:o,onClose:l,onSignIn:c,onReport:d}){const h=y.useRef(null);return a.jsx(dh,{anchorId:e,boundaryId:t,id:"ap-issue-pop",className:"ap-pop ap-issue-pop",role:"dialog",labelledBy:"ap-issue-title",focusRef:h,onClose:()=>l(),children:a.jsxs("div",{className:"ap-pop-form",children:[a.jsxs("p",{className:"ap-pop-title ap-issue-title",id:"ap-issue-title","data-tone":n.tone,children:[n.tone==="warn"&&a.jsx(y0,{}),n.text]}),a.jsx("p",{className:"ap-pop-note ap-issue-hint",children:n.hint}),a.jsxs("p",{className:"ap-pop-note ap-issue-when",children:[a.jsx("span",{className:"ap-issue-who",children:r})," · ",s?`last collected ${yi(s,o)}`:"never collected"]}),a.jsxs("div",{className:"ap-pop-actions",children:[d&&a.jsx("button",{type:"button",className:"ap-issue-report",onClick:()=>{l(),d()},children:"Report this"}),a.jsx("button",{type:"button",ref:h,className:"btn",onClick:()=>l(!0),children:"Done"}),n.fix&&a.jsx("button",{type:"button",className:"btn primary",onClick:()=>{l(!0),c()},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:n.fix})]})]})})}function Sl(e){return e.charAt(0).toUpperCase()+e.slice(1)}function J9(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 Q9(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 eV(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.`}}}const bS={text:"Login expired on all online decks",hint:"Every paired deck online right now that shares this account holds a copy that has expired too, so none of them can repair this one. Claude retires a login's other copies each time one machine refreshes it, which is how shared copies expire together. Sign in again on any one machine; the others repair from it on their next round."};function wi(e,t,n){const r=nV(e,t);return!r||!(n!=null&&n.noCopyWorksNearby)||!tV(e)?r:{...r,text:bS.text,hint:bS.hint}}function tV(e){return e.staleCopy?!1:e.stopped?e.collector==="relogin_required":e.error==="invalid_grant"||e.error==="no_refresh_token"}function nV(e,t){if(e.staleCopy){const n=J9(e.repair??null,t);return{text:Sl(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=eV(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:Sl(n.text),hint:n.hint,fix:n.fix?Sl(n.fix):null,tone:r||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:r}}if(e.error){const n=Q9(e.error);return{text:Sl(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function kS(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function NS(e){const t=e.filter(c=>!kS(c)),n=e.filter(c=>kS(c)),r=t.length?t:n,s=t.length?n:[],o=r.reduce((c,d)=>c&&c.pct>=d.pct?c:d,null);let l=null;for(const c of s)o&&c.pct<=o.pct||(!l||c.pct>l.pct)&&(l=c);return{shown:r,rest:s,fuller:l,peak:l??o}}function Jl(e,t){return!!e.resetAt&&e.resetAt<=t}function w0(e,t){const n=e.lanes??[],r=n.filter(s=>!Jl(s,t));return r.length===n.length?e.headroom:r.length?Math.max(0,100-Math.max(...r.map(s=>s.pct))):null}const rV="\0";function Lr(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}${rV}${n}`}function sV(e,t,n=Lr){const r=n(t);return e.includes(r)?e.filter(s=>s!==r):[...e,r]}const hh="slot",v0=[{lane:"five_hour",name:"5h"},{lane:"seven_day",name:"7d"}],NI=e=>e.id.startsWith("scoped-");function aV(e){var t;return((t=v0.find(n=>n.lane===e.id))==null?void 0:t.name)??e.label}function oV(e){if(e==="room")return"room";const t=/^(.+):(full|empty)$/.exec(e);return t?t[1]:null}function jI(e){const t=[...new Set(e.flatMap(r=>(r.lanes??[]).filter(NI).map(s=>s.label)))].sort((r,s)=>r.localeCompare(s)),n=[...v0.map(r=>r.name),...t];return[{id:hh,label:"Slot"},...n.flatMap(r=>[{id:`${r}:full`,label:`${r} · fullest`},{id:`${r}:empty`,label:`${r} · emptiest`}]),{id:"room",label:"Most room"}]}function jS(e,t,n){const r=v0.find(o=>o.name===t),s=(e.lanes??[]).find(o=>r?o.id===r.lane:NI(o)&&o.label===t);return s&&n!=null&&Jl(s,n)?null:s&&Number.isFinite(s.pct)?s.pct:null}function iV(e,t,n=()=>!0,r){const s=[...e],o=f=>[...f.filter(n),...f.filter(p=>!n(p))];if(t==="room"){const f=p=>r==null?p.headroom:w0(p,r);return o(SS(s,p=>{const g=f(p);return Number.isFinite(g)?g:null},"desc"))}const l=/^(.+):(full|empty)$/.exec(t);if(!l)return s;const[,c,d]=l;if(!s.some(f=>jS(f,c,r)!=null))return s;const h=SS(s,f=>jS(f,c,r),d==="full"?"desc":"asc");return d==="empty"?o(h):h}function SS(e,t,n){const r=e.filter(o=>t(o)!=null),s=e.filter(o=>t(o)==null);return r.sort((o,l)=>n==="desc"?t(l)-t(o):t(o)-t(l)),[...r,...s]}function lV(e,t){return jI(t).some(n=>n.id===e)?e:hh}function Xx(e,t){if(!t)return[...e];const n=new Map(t.map((o,l)=>[o,l])),r=e.filter(o=>n.has(Lr(o))).sort((o,l)=>n.get(Lr(o))-n.get(Lr(l))),s=e.filter(o=>!n.has(Lr(o)));return[...r,...s]}function x0(e){const t=Lr(e);return t.startsWith("slot:")?t:`h:${cV(t)}`}function cV(e){let t=3735928559,n=1103547991;for(let r=0;r<e.length;r++){const s=e.charCodeAt(r);t=Math.imul(t^s,2654435761),n=Math.imul(n^s,1597334677)}return t=Math.imul(t^t>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507)^Math.imul(t^t>>>13,3266489909),(4294967296*(2097151&n)+(t>>>0)).toString(36)}const Zx={mode:"some",keys:[]};function SI(e,t){const n=e.keys.includes(x0(t));return e.mode==="all"?!n:n}function uV(e,t){return{mode:e.mode,keys:sV(e.keys,t,x0)}}function _I(e,t){return t.length>0&&t.every(n=>SI(e,n))}function dV(e,t){return _I(e,t)?Zx:{mode:"all",keys:[]}}function hV(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(x0)),r=e.keys.filter(s=>n.has(s));return r.length===e.keys.length?e:{mode:e.mode,keys:r}}function fV(e){return e>=90?"hi":e>=70?"mid":void 0}function pV({lane:e,nowSec:t,frozen:n,sortedBy:r}){const s=Math.min(100,Math.max(0,e.pct)),o=Jl(e,t),l=n||o,c=l?"var(--muted)":s>=90?"var(--err)":s>=70?"var(--warn)":"var(--accent)",d=e.resetAt&&!l?sh(e.resetAt,t):null;return a.jsxs("div",{className:"ap-lane","data-sort-key":r?"":void 0,children:[a.jsx("span",{className:"ap-lane-label",title:e.label,children:e.label}),a.jsx("div",{className:"ap-lane-track",children:a.jsx("div",{className:"ap-lane-fill",style:{width:`${s===0?1.5:s}%`,background:c,opacity:s===0||l?.4:1}})}),a.jsxs("span",{className:"ap-lane-pct",style:{color:c},children:[Math.round(s),"%"]}),a.jsxs("span",{className:"ap-lane-reset",title:d?`${e.label} resets in ${d}`:o&&!n?`${e.label} has reset since this reading`:void 0,children:[d&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"vis-hidden",children:"resets in "}),d]}),o&&!n&&"reset"]})]})}function mV({a:e,nowSec:t,lan:n,opened:r,onToggleLanes:s,busy:o,pressProps:l,onSwitch:c,menuOpen:d,onOpenMenu:h,onCloseMenu:f,refusal:p,onDismissRefusal:g,switchedHere:v,swapped:N,displaced:k,issueExpanded:x,onOpenIssue:j,sortKey:b=null}){const _=e.lanes.filter(M=>!Jl(M,t)),{shown:E}=NS(e.lanes),{fuller:R}=NS(_),C=b==="room"?_.reduce((M,$)=>M&&M.pct>=$.pct?M:$,null):b?e.lanes.find(M=>aV(M)===b)??null:null,A=wi(e,t,n),U=e.active||r,L=e.alias??e.email??`account ${e.num}`,F=e.alias&&e.email?`${e.alias} · ${e.email}`:L,O=e.stale||(A==null?void 0:A.blocksSwitch)===!0,I=R?[...E,R]:E,B=e.fetchedAt?yi(e.fetchedAt,t):null;return a.jsxs("li",{className:`ap-account${e.active?" active":""}`,"aria-current":e.active?"true":void 0,"data-open":U?"":void 0,"data-frozen":O?"":void 0,children:[!e.active&&a.jsx("button",{type:"button",className:"ap-row-open",id:`ap-row-${e.num}`,title:F,"aria-expanded":U,"aria-controls":U?`ap-detail-${e.num}`:void 0,"aria-describedby":[e.alias&&e.email?`ap-email-${e.num}`:null,!U&&!(A!=null&&A.blocksSwitch)?`ap-quota-${e.num}`:null].filter(Boolean).join(" ")||void 0,onClick:()=>s(),children:a.jsxs("span",{className:"vis-hidden",children:[L,", ",U?"hide details":"details"]})}),a.jsxs("div",{className:"ap-account-head",children:[e.active?a.jsx("span",{className:"ap-live",title:`Active account · slot ${e.num}`,children:a.jsxs("span",{className:"vis-hidden",children:["Active account, slot ",e.num,":"]})}):a.jsx("span",{className:"ap-num",children:e.num}),e.alias&&a.jsx("span",{className:"ap-alias",title:e.alias,children:e.alias}),a.jsx("span",{className:"ap-email",id:`ap-email-${e.num}`,title:e.email??void 0,children:e.email}),e.disabled&&a.jsx("span",{className:"ap-held",children:"held out"}),!e.active&&!e.disabled&&!(A!=null&&A.blocksSwitch)&&a.jsx("button",{type:"button",className:"ap-switch",...l(`switch-${e.num}`),onClick:()=>c(e.num,L),"aria-label":`Switch to ${L}`,title:`Switch to ${e.alias??e.email}`,children:o===`switch-${e.num}`?"…":"Switch"}),a.jsx("button",{type:"button",id:`ap-more-${e.num}`,className:"ap-more","aria-label":`More actions for ${e.email??e.alias??`account ${e.num}`}`,"aria-haspopup":"menu","aria-expanded":d,"aria-controls":d?`ap-menu-${e.num}`:void 0,title:"More actions",onClick:()=>d?f():h(e.num),onKeyDown:M=>{M.key!=="ArrowDown"&&M.key!=="ArrowUp"||(M.preventDefault(),h(e.num,M.key==="ArrowUp"?"last":"first"))},children:a.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":!0,children:[a.jsx("circle",{cx:"2.8",cy:"7",r:"1.15"}),a.jsx("circle",{cx:"7",cy:"7",r:"1.15"}),a.jsx("circle",{cx:"11.2",cy:"7",r:"1.15"})]})})]}),p&&a.jsxs("div",{className:"ap-failure ap-row-failure",role:"alert",children:[a.jsx("span",{className:"ap-failure-text",title:p.raw||void 0,children:p.text}),a.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>g(),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),e.active&&v&&a.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."}),N&&(()=>{const M=(k==null?void 0:k.alias)??(k==null?void 0:k.email)??"the account that was there";return a.jsxs("p",{className:"ap-note ap-swap-note",title:`Slot ${N.at} was taken, so the two accounts traded places: ${M} now holds slot ${N.displaced}.`,children:["swapped with slot ",N.displaced]})})(),A&&a.jsxs("div",{className:"ap-issue-line",children:[a.jsxs("button",{type:"button",id:`ap-issue-${e.num}`,className:"ap-issue","data-tone":A.tone,"aria-haspopup":"dialog","aria-expanded":x,"aria-controls":x?"ap-issue-pop":void 0,onClick:()=>j(e.num,`ap-issue-${e.num}`),children:[A.tone==="warn"&&a.jsx(y0,{}),a.jsx("span",{className:"ap-issue-text",children:A.text})]}),!U&&a.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:B??"never collected"})]}),!U&&!(A!=null&&A.blocksSwitch)&&a.jsxs("p",{className:"ap-quota",id:`ap-quota-${e.num}`,children:[I.length?I.map(M=>a.jsxs("span",{className:"ap-q","data-sort-key":M.id===(C==null?void 0:C.id)?"":void 0,children:[a.jsx("span",{className:"ap-q-label",children:M.label})," ",Jl(M,t)?a.jsx("span",{className:"ap-q-pct",title:`${M.label} has reset since this reading`,children:"reset"}):a.jsxs("span",{className:"ap-q-pct","data-level":O?void 0:fV(M.pct),children:[Math.round(M.pct),"%"]})]},M.id)):a.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),e.stale&&!A&&a.jsx("span",{className:"ap-q-age","data-never":B?void 0:"",title:"When claude-swap last read this account's usage",children:B??"never collected"})]}),U&&a.jsxs("div",{className:"ap-detail",id:`ap-detail-${e.num}`,children:[a.jsx("div",{className:"ap-lanes",children:e.lanes.length?e.lanes.map(M=>a.jsx(pV,{lane:M,nowSec:t,frozen:O,sortedBy:M.id===(C==null?void 0:C.id)},M.id)):a.jsx("div",{className:"ap-hint",children:"No usage recorded yet."})}),a.jsx("div",{className:"ap-meta",children:e.fetchedAt?a.jsxs("span",{className:`ap-age${e.stale&&!A?" 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 ",yi(e.fetchedAt,t),A!=null&&A.blocksSwitch?"":X9(e.nextAt,t)]}):a.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})})]})]})}function gV({data:e}){return a.jsx("div",{className:"ap-empty",children:e.reason==="cswap_installing"?a.jsxs(a.Fragment,{children:[a.jsx("span",{children:"Installing claude-swap…"}),a.jsx("span",{className:"ap-hint",children:"The deck is setting it up in the background, so there is nothing to do here. On a new machine this can take a few minutes; the panel fills in by itself when it is done."})]}):e.reason==="no_cswap"?a.jsxs(a.Fragment,{children:[a.jsx("span",{children:"claude-swap isn't installed."}),a.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."}),e.hint&&a.jsx("code",{className:"ap-cmd",children:e.hint}),a.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",a.jsx("strong",{children:"+"})," button above."]})]}):e.reason==="cswap_refused"?a.jsxs(a.Fragment,{children:[a.jsx("span",{children:"claude-swap was installed, but not the version the deck asked for."}),a.jsxs("span",{className:"ap-hint",children:[e.version?`v${e.version} answered`:"A different version answered",e.want?` where ${e.want} was asked for`:"",", so the deck is not driving it. Install the version it asked for, or set AGENTS_DECK_CSWAP to a claude-swap you trust."]})]}):e.reason==="no_accounts"?a.jsxs(a.Fragment,{children:[a.jsx("span",{children:"No accounts added yet."}),a.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",a.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):a.jsxs(a.Fragment,{children:[a.jsx("span",{children:"Couldn't read the account store."}),a.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",e.reason?` (${e.reason})`:"","."]})]})})}function yV({canShare:e,canReport:t,onAdd:n,onReport:r,onShareSet:s,onReload:o,pressProps:l,reloading:c,closeButton:d}){return a.jsxs("div",{className:"ap-header",children:[a.jsx("h2",{children:"Claude accounts"}),a.jsxs("div",{className:"ap-header-right",children:[a.jsx("button",{type:"button",className:"glyph-btn ap-add",onClick:()=>n(),"aria-label":"Add an account",title:"Sign in to another Claude account, or paste one shared from another deck",children:a.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:a.jsx("path",{d:"M7 2.2v9.6M2.2 7h9.6"})})}),t&&a.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>r(),"aria-label":"Account capacity","aria-haspopup":"dialog",title:"Account capacity — how many accounts are ready, and what the 5h and 7d windows have left",children:a.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[a.jsx("path",{d:"M2.5 10.9A5.2 5.2 0 1 1 11.5 10.9"}),a.jsx("path",{d:"M7 8.3l2.1-2.1"})]})}),e&&a.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>s(),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${kt} in one paste. The text carries a live login for each one — treat it as those passwords.`,children:a.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:[a.jsx("path",{d:"M3.3 10.7L10.7 3.3"}),a.jsx("path",{d:"M5.5 3.3h5.2v5.2"})]})}),a.jsx("button",{type:"button",className:"glyph-btn ap-refresh",onClick:()=>o(),...l("reload",c),"aria-label":"Reload accounts",title:"Reload from claude-swap",children:a.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:[a.jsx("path",{d:"M11.6 6.2A4.8 4.8 0 1 0 11 9.6"}),a.jsx("path",{d:"M11.9 2.6v3.7h-3.6"})]})}),d]})]})}const Va=[{id:"five_hour",label:"5h",long:"5-hour"},{id:"seven_day",label:"7d",long:"7-day"}];function _S(e){return e.counted?e.pct:e.why==="login"?null:e.estimate}function wV(e){const t=_S(e.five_hour),n=_S(e.seven_day);if(t==null||n==null)return"stale";const r=+(t>=100)+ +(n>=100);return r===0?"ready":r===1?"limited":"exhausted"}function vV(e,t){const n=Va.map(r=>e.cells[r.id]);for(const r of n)if(!r.counted&&(r.why==="login"||r.why==="none"))return{text:r.say,old:!0};return e.updatedAt==null?{text:"never read",old:!0}:n.every(r=>r.counted)?{text:"now",old:!1}:{text:yi(e.updatedAt,t),old:!0}}const xV=15*6e4,bV=e=>e.alias??e.email??`account ${e.num}`;function ES(e,t,n){const r=Va.find(f=>f.id===t).label,s=(e.lanes??[]).find(f=>f.id===t),o=s&&Number.isFinite(s.pct)?kV(s.pct):null,l=wi(e,n),c=(s==null?void 0:s.resetAt)!=null&&s.resetAt<=n,d=(f,p)=>({counted:!1,why:f,say:p,last:o,estimate:o==null?null:c?0:o,resetAt:c?null:(s==null?void 0:s.resetAt)??null});return l!=null&&l.blocksSwitch?d("login",l.text):o==null?d("none",`No ${r} reading`):e.stale||e.fetchedAt==null||n*1e3-e.fetchedAt>xV?d("stale",e.fetchedAt?`Updated ${yi(e.fetchedAt,n)}`:"Never read"):c?d("reset",`Reset ${yi(s.resetAt*1e3,n)}, not updated`):{counted:!0,pct:o,resetAt:s.resetAt}}const kV=e=>Math.min(100,Math.max(0,e));function NV(e,t){const n=Va.find(h=>h.id===t);let r=0,s=0,o=0;const l=[];for(const h of e){const f=h.cells[t],p=f.counted?f.pct:f.estimate;p!=null&&(r+=p,o++,f.counted&&s++,f.resetAt!=null&&l.push({at:f.resetAt,name:h.name,pct:p}))}const c=l.reduce((h,f)=>!h||f.at<h.at?f:h,null),d=c&&{...c,more:l.filter(h=>h!==c&&h.at-c.at<60).length};return{id:t,label:n.label,long:n.long,reporting:s,included:o,total:e.length,used:o?r/o:null,nextReset:d}}function EI(e,t){const n=e.map(s=>{const o={five_hour:ES(s,"five_hour",t),seven_day:ES(s,"seven_day",t)};return{num:s.num,key:Lr(s),name:bV(s),active:s.active,heldOut:s.disabled===!0,cells:o,status:wV(o),updatedAt:s.fetchedAt??null}}),r=n.filter(s=>s.status==="ready").length;return{rows:n,windows:Va.map(s=>NV(n,s.id)),roomInBoth:r}}function Bu(e,t){return(e==null?void 0:e.key)===t?{key:t,dir:e.dir==="asc"?"desc":"asc"}:{key:t,dir:"asc"}}const jV={ready:0,limited:1,exhausted:2,stale:3};function SV(e){return e.counted?e.pct:e.last}function TS(e,t){return t==="status"?jV[e.status]:t==="updated"?e.updatedAt==null?null:-e.updatedAt:SV(e.cells[t])}function _V(e,t){if(!t)return[...e];const n=t.dir==="asc"?1:-1,r=new Map(e.map((o,l)=>[o.num,l])),s=(o,l)=>{if(t.key==="account")return n*o.name.localeCompare(l.name,void 0,{sensitivity:"base"});const c=TS(o,t.key),d=TS(l,t.key);return c==null||d==null?c==null?d==null?0:1:-1:n*(c-d)};return[...e].sort((o,l)=>s(o,l)||r.get(o.num)-r.get(l.num))}function Ed(e){return e>=100?100:Math.min(99,Math.round(e))}function EV(e){const t=Ed(e);return{used:t,available:100-t}}function TV(e,t,n){return e?`${e} These are the last readings.`:t&&n?"The account store could not be read just now. These are the last readings.":null}function TI(e){return e>=90?"hi":e>=70?"mid":void 0}const CI=(e,t,n)=>`${e} ${e===1?t:n}`;function CS(e){const t=e.more>0?`, and ${CI(e.more,"more account","more accounts")} in the same minute`:"";return`First: ${e.name} (${Ed(e.pct)}% used)${t}`}function CV({w:e,nowSec:t}){const n=`ap-report-${e.id}`,r=e.total-e.included,s=r>0&&a.jsxs("p",{className:"ap-report-basis",children:[r," never read"]}),{used:o,available:l}=EV(e.used??0),c=Math.round(Da(l,{countIn:!0}));if(e.used==null)return a.jsxs("section",{className:"ap-report-sum","aria-labelledby":n,children:[a.jsxs("h3",{className:"ap-report-win",id:n,children:[e.long," window"]}),a.jsxs("p",{className:"ap-report-none",children:["No account has a ",e.long," reading yet."]}),s]});const d=e.nextReset?sh(e.nextReset.at,t):null;return a.jsxs("section",{className:"ap-report-sum","aria-labelledby":n,children:[a.jsxs("h3",{className:"ap-report-win",id:n,children:[e.long," window"]}),a.jsxs("p",{className:"ap-report-left",children:[a.jsxs("b",{children:[c,"%"]})," remaining"]}),a.jsx("div",{className:"ap-report-meter","data-level":TI(o),"aria-hidden":!0,children:a.jsx("i",{style:{"--left":l/100}})}),d&&e.nextReset&&a.jsxs("p",{className:"ap-report-reset",title:CS(e.nextReset),children:[a.jsxs("span",{children:["Next reset in ",a.jsx("span",{className:"ap-report-num",children:d})]}),a.jsx("span",{"aria-hidden":!0,children:"·"}),a.jsx("span",{className:"ap-report-who",children:e.nextReset.name}),e.nextReset.more>0&&a.jsxs("span",{className:"ap-report-more",children:["+",e.nextReset.more]}),a.jsxs("span",{className:"vis-hidden",children:[". ",CS(e.nextReset)]})]}),s]})}function AV({cell:e,nowSec:t}){if(!e.counted)return a.jsxs("td",{className:"ap-report-cell","data-uncounted":"",children:[a.jsx("span",{className:"ap-report-pct",children:e.last==null?a.jsxs(a.Fragment,{children:[a.jsx("span",{"aria-hidden":!0,children:"—"}),a.jsx("span",{className:"vis-hidden",children:"no reading"})]}):`${Ed(e.last)}%`}),a.jsx("span",{className:"vis-hidden",children:", not counted"})]});const n=e.resetAt!=null?sh(e.resetAt,t):null;return a.jsxs("td",{className:"ap-report-cell",children:[a.jsxs("span",{className:"ap-report-pct","data-level":TI(e.pct),children:[Ed(e.pct),"%"]}),n&&a.jsxs("span",{className:"ap-report-in",children:[a.jsx("span",{className:"vis-hidden",children:"resets in "}),n]})]})}const RV={ready:"Ready",limited:"Limited",exhausted:"Exhausted",stale:"Stale"};function MV({row:e}){return a.jsx("td",{className:"ap-report-state","data-status":e.status,children:a.jsxs("span",{className:"ap-report-state-word",children:[a.jsx("i",{"aria-hidden":!0}),RV[e.status]]})})}function $V({row:e,nowSec:t}){const n=vV(e,t);return a.jsx("td",{className:"ap-report-upd","data-old":n.old?"":void 0,children:n.text})}function IV(){return a.jsxs("svg",{className:"ap-report-how-mark",viewBox:"0 0 16 16",width:"12",height:"12","aria-hidden":!0,focusable:"false",children:[a.jsx("circle",{cx:"8",cy:"8",r:"6.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4"}),a.jsx("path",{d:"M8 7.2v4.1M8 4.8v.1",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}function OV({accounts:e,nowSec:t,held:n,sort:r=null,onSort:s=()=>{}}){const o=EI(e,t),l=o.rows.length,c=Math.round(Da(o.roomInBoth,{countIn:!0}));return a.jsxs("div",{className:"ap-proj-body ap-report-body",role:"region","aria-label":"Report",children:[n&&a.jsx("p",{className:"ap-report-held",children:n}),a.jsxs("p",{className:"ap-report-lead",children:[a.jsx("b",{children:c})," of ",CI(l,"Claude account","Claude accounts")," ready"]}),a.jsx("div",{className:"ap-report-sums",children:o.windows.map(d=>a.jsx(CV,{w:d,nowSec:t},d.id))}),a.jsxs("table",{className:"ap-report-table",children:[a.jsx("caption",{className:"vis-hidden",children:"Each account's use of each window, and what it can do now"}),a.jsxs("colgroup",{children:[a.jsx("col",{}),Va.map(d=>a.jsx("col",{className:"ap-report-col-win"},d.id)),a.jsx("col",{className:"ap-report-col-state"}),a.jsx("col",{className:"ap-report-col-upd"})]}),a.jsx("thead",{children:a.jsxs("tr",{children:[a.jsx(jl,{col:"account",label:"Account",sort:r,next:Bu,onSort:s}),Va.map(d=>a.jsx(jl,{col:d.id,label:`${d.label} used`,sort:r,next:Bu,onSort:s},d.id)),a.jsx(jl,{col:"status",label:"Status",sort:r,next:Bu,onSort:s}),a.jsx(jl,{col:"updated",label:"Updated",className:"ap-report-upd-h",sort:r,next:Bu,onSort:s})]})}),a.jsx("tbody",{children:o.rows.map((d,h)=>a.jsxs("tr",{"data-active":d.active?"":void 0,style:{"--row":h},children:[a.jsx("th",{scope:"row",className:"ap-report-acct",children:a.jsxs("span",{className:"ap-report-acct-in",children:[a.jsx("span",{className:"ap-report-name",title:d.name,children:d.name}),d.active&&a.jsx("span",{className:"ap-report-current",children:"Current"}),d.heldOut&&a.jsx("span",{className:"ap-report-tag",children:"held out"})]})}),Va.map(f=>a.jsx(AV,{cell:d.cells[f.id],nowSec:t},f.id)),a.jsx(MV,{row:d}),a.jsx($V,{row:d,nowSec:t})]},d.num))})]}),a.jsxs("details",{className:"ap-report-how",children:[a.jsxs("summary",{children:[a.jsx(IV,{}),"How usage is calculated"]}),a.jsxs("div",{className:"ap-report-how-body",children:[a.jsxs("p",{children:["Every account here, at its last reading: ",a.jsx("b",{children:"used"})," is their average, and ",a.jsx("b",{children:"remaining"})," is the rest."]}),a.jsxs("p",{children:[a.jsx("b",{children:"Ready"})," has room in both windows. ",a.jsx("b",{children:"Limited"})," is at the limit of one, and ",a.jsx("b",{children:"Exhausted"})," of both. ",a.jsx("b",{children:"Stale"})," was never read, or is signed out."]})]})]})]})}function LV({accounts:e,order:t,failed:n,nowSec:r,onClose:s}){const o=y.useRef(null),l=ut(s,{focusRef:o}),c=gt(s),[d,h]=y.useState(e??[]);y.useEffect(()=>{e&&e.length>0&&h(e)},[e]);const f=TV(n,!e||e.length===0,d.length>0),[p,g]=y.useState(null),v=Xx(d,(p==null?void 0:p.order)??t),N=k=>{const x=EI(Xx(d,t),r).rows;g({sort:k,order:_V(x,k).map(j=>j.key)})};return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...c,role:"presentation",children:a.jsxs("div",{ref:l,className:"modal ap-report-modal",onClick:k=>k.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"ap-report-title",children:[a.jsxs("header",{className:"ap-proj-head",children:[a.jsx("div",{className:"ap-proj-titlewrap",children:a.jsx("h2",{className:"ap-proj-title",id:"ap-report-title",children:"Account capacity"})}),a.jsx("button",{ref:o,type:"button",className:"glyph-btn ap-proj-close",onClick:s,"aria-label":"Close",children:"×"})]}),a.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:f??""}),a.jsx(OV,{accounts:v,nowSec:r,held:f,sort:(p==null?void 0:p.sort)??null,onSort:N})]})}),document.body)}const qp=[70,80,85,90,95];function PV(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!qp.includes(t)?[...qp,t]:qp].sort((r,s)=>r-s)}function DV({auto:e,threshold:t,thresholdPick:n,thresholdCtl:r,thresholdSaved:s,thresholdRef:o,thresholdSaveRef:l,proposeThreshold:c,doThreshold:d,pressProps:h,post:f,load:p}){return a.jsxs("div",{className:"ap-policy-block",children:[a.jsxs("div",{className:"ap-policy",children:[a.jsx("h3",{className:"ap-auto-title",children:"Auto-switch"}),a.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:a.jsx("select",{ref:o,"aria-label":"Switch threshold",value:n,...h("threshold"),onChange:g=>c(g.target.value),children:PV(t).map(g=>a.jsxs("option",{value:g,children:[g,"%"]},g))})}),(r.sends||s)&&a.jsx("button",{ref:l,type:"button",className:"ap-manage-btn",...h("threshold"),title:r.title,onClick:()=>d(n,r),children:s&&!r.sends?r.done:r.label}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":e.enabled,"aria-label":"Auto-switch",...h("enable"),onClick:()=>f({action:"enable",enabled:!e.enabled},"enable").then(()=>p(!0)),title:e.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:a.jsx("span",{className:"switch-knob"})})]}),e.external&&a.jsxs("p",{className:"ap-auto-note",children:[a.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",a.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",e.enabled?" — this toggle takes over when you stop it.":"."]})]})}const AS=18,FV=1100,Ho=(e,t)=>{const n=Math.sin(e*12.9898+t*78.233)*43758.5453;return n-Math.floor(n)},BV=Array.from({length:AS},(e,t)=>{const n=-72+144*t/(AS-1)+(Ho(t,1)-.5)*9,r=(n-90)*(Math.PI/180),s=(54+32*Math.cos(n*Math.PI/180))*(.74+Ho(t,2)*.52);return{dx:Math.cos(r)*s,dy:Math.sin(r)*s,rot:(t%2?1:-1)*(100+Ho(t,3)*260),delay:Math.round(Ho(t,4)*90),dur:760+Math.round(Ho(t,5)*260),scale:.8+Ho(t,6)*.45,hue:t%4,round:t%3===0}});function RS({anchor:e}){var s;const[t,n]=y.useState(null),r=typeof window<"u"&&((s=window.matchMedia)==null?void 0:s.call(window,"(prefers-reduced-motion: reduce)").matches);return y.useEffect(()=>{if(r)return;const o=e.current;if(!o)return;const l=o.getBoundingClientRect();n({x:l.left+l.width/2,y:l.top+l.height/2});const c=window.setTimeout(()=>n(null),FV);return()=>window.clearTimeout(c)},[e,r]),r||!t?null:Lt.createPortal(a.jsx("div",{className:"confetti",style:{left:`${t.x}px`,top:`${t.y}px`},"aria-hidden":!0,children:BV.map((o,l)=>a.jsx("span",{className:`confetti-bit${o.round?" round":""}`,"data-hue":o.hue,style:{"--dx":`${o.dx.toFixed(1)}px`,"--dy":`${o.dy.toFixed(1)}px`,"--rot":`${o.rot}deg`,"--s":o.scale.toFixed(2),animationDelay:`${o.delay}ms`,animationDuration:`${o.dur}ms, ${o.dur}ms`}},l))}),document.body)}const Td=y.forwardRef((e,t)=>a.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:t,children:[a.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),a.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));Td.displayName="SuccessMark";const AI=new Set(["awaiting_url","awaiting_code","registering"]);function RI(e){return e!=null&&AI.has(e)}function MI(e){return e!=null&&e!=="done"&&!AI.has(e)}const qV="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",UV="the sign-in did not complete";function zV({state:e,serverError:t,localError:n}){const r=e==="idle";return{title:r?"Sign-in ended":"Sign-in failed",message:n||t||(r?qV:UV)}}function WV({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 HV({started:e,state:t}){return!e||t==="done"?null:{action:"login-cancel"}}function VV({login:e,started:t,loginError:n,loginBusy:r}){return(e==null?void 0:e.state)==="done"&&e.account?"done":(e==null?void 0:e.state)==="awaiting_code"||(e==null?void 0:e.state)==="registering"?"code":MI(e==null?void 0:e.state)||n&&t&&!r?"ended":r||RI(e==null?void 0:e.state)?"asking":"primer"}const GV="done";function KV(){let e=!1;return{shouldAnnounce(t){return t!==GV?(e=!1,!1):e?!1:(e=!0,!0)}}}function b0(e,t){return t?Ot(e,t):void 0}const YV={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 ${kt}`,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"},XV={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"},k0=`claude-swap could not read the login keychain — start ${kt} from a Terminal window rather than a background service`,ZV={unreadable_here:{short:"Keychain locked on this Mac",long:`${k0}.`},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 Cd(e){return e?Ot(ZV,e)??null:null}const $I={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 Jx(e,t,n){const r=n==null?null:$I[n];if(r)return r;if((e==null?void 0:e.reason)!=="no_cswap"&&/keychain/i.test(Ql(e)))return k0;const s=b0(XV,e==null?void 0:e.reason);return s||(e==null?void 0:e.reason)||t}function Ql(e){return((e==null?void 0:e.output)||(e==null?void 0:e.detail)||(e==null?void 0:e.error)||"").trim()}const JV={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"},QV="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 eG(e){return/\bnpx\b/i.test(e)&&/(command not found|not found|not recognized|ENOENT)/i.test(e)}const tG="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",nG="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",rG=e=>/\b(?:ERR_)?MODULE_NOT_FOUND\b|cannot find (?:module|package)/i.test(e),sG=/node_modules[\\/]npm[\\/]bin[\\/]|\bnpm-prefix\.js\b|\bnp[mx][-.][\w.-]*cli\.js\b/i,aG=/[\\/]_npx[\\/]/i,oG=`the copy of ccusage ${kt} installed for itself`;function iG(e){const t=String((e==null?void 0:e.install)??"").replace(/\s+/g," ").trim();return t.length>240?`${t.slice(0,239)}…`:t}function Hle(e,t){const n=lG(e,t),r=iG(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 ${vl(n)}`:`there is no managed copy of ccusage on this machine, and the npx fallback failed: ${vl(n)}`;case"managed":return`${oG} failed to run: ${vl(n)}`;case"path":return e.bin?`the ccusage this deck found at ${e.bin} failed to run: ${vl(n)}`:`the ccusage this deck found on your PATH failed to run: ${vl(n)}`;default:return n}}const vl=e=>/^[A-Z][a-z]/.test(e)?e[0].toLowerCase()+e.slice(1):e;function lG(e,t){const n=Ql(e);if(rG(n)){if(aG.test(n))return nG;if(sG.test(n))return tG}if(eG(n))return QV;const r=b0(JV,e==null?void 0:e.reason);return r||(e==null?void 0:e.reason)||t}function Jo(e,t,n){const r=n==null?null:$I[n];if(r)return r;if(e!=null&&e.detail)return e.detail;if(e!=null&&e.error&&MI(e.state))return e.error;const s=b0(YV,e==null?void 0:e.reason);return s||(e!=null&&e.error?e.error:(e==null?void 0:e.reason)||t)}function cG(e,t,n){if(n<=0||eh(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 II(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 uG(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}`,o=[];return n.alias&&r&&o.push(r),r&&(t.get(r.toLowerCase())??0)>1&&o.push(n.org||`slot ${n.num}`),{num:n.num,label:s,sub:o.length?o.join(" · "):null}})}function dG(e,t){return e.filter(n=>!t.includes(n.num)).map(n=>n.num)}function hG(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function fG(e){return e.length?{action:"share",accounts:[...e]}:null}function pG(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 Qx(e){return`${e.email}|${e.org??""}`}function mG(e,t,n){return e&&e.map(r=>Qx(r)===t?n:r)}function gG(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 yG(e){const t=e.length;if(!t)return"Nothing to import.";const n=f=>e.filter(p=>p.state===f).length,r=[],s=n("imported");s&&r.push(`${s} of ${t} imported`);const o=n("healed");o&&r.push(`${o} had a dead token replaced`);const l=n("updated");l&&r.push(`${l} updated`);const c=n("present");c&&r.push(`${c} already here`);const d=n("failed");d&&r.push(`${d} did not arrive`);const h=[...new Set(e.map(f=>{var p;return(p=Cd(f.check))==null?void 0:p.short}).filter(f=>!!f))];return`${r.join(", ")}${h.length?`, ${h.join(", ")}`:""}.`}const wG=1500,qu=[{id:"login",label:"Sign in"},{id:"paste",label:"Paste a share"}],MS="aa-panel",$S=e=>`aa-tab-${e}`;async function Vo(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}function OI({onClose:e,onChanged:t,email:n=null,onSignedIn:r}){qt("add-account");const[s,o]=y.useState("login"),[l,c]=y.useState(null),[d,h]=y.useState(""),[f,p]=y.useState(""),[g,v]=y.useState(!1),[N,k]=y.useState(!1),[x,j]=y.useState(null),[b,_]=y.useState(null),E=g||N,[R,C]=y.useState(null),[A,U]=y.useState(null),[L,F]=y.useState(null),O=y.useRef(""),I=y.useRef(!1),B=y.useRef(!1),M=y.useRef(null),$=y.useRef(null),P=y.useRef(null),G=y.useRef(null),K=y.useRef([]),q=y.useRef(!1),H=y.useCallback(()=>{const he=HV({started:I.current,state:l==null?void 0:l.state});he&&Vo(he).catch(()=>{}),e()},[e,l==null?void 0:l.state]),D=ut(H,{focusRef:P}),W=gt(H),J=y.useCallback(async()=>{if(!lr(B.current))return;B.current=!0,v(!0),j(null),I.current=!0;let he=await Vo(n?{action:"login",email:n}:{action:"login"}).catch(()=>null);if(n&&(he==null?void 0:he.reason)==="bad_email"&&(he=await Vo({action:"login"}).catch(()=>null)),B.current=!1,v(!1),!(he!=null&&he.ok)){j(Jo(he,"could not start the sign-in"));return}c(he)},[n]);y.useEffect(()=>{if(!RI(l==null?void 0:l.state))return;const he=window.setInterval(async()=>{try{const ge=await fetch("/api/claude-accounts/login");ge.ok&&c(await ge.json())}catch{}},wG);return()=>window.clearInterval(he)},[l]);const V=y.useRef(t);V.current=t;const X=y.useState(KV)[0];y.useEffect(()=>{var he;(l==null?void 0:l.state)==="awaiting_code"&&((he=M.current)==null||he.focus()),X.shouldAnnounce(l==null?void 0:l.state)&&V.current()},[l==null?void 0:l.state,X]);const Y=y.useRef(r);Y.current=r;const Z=y.useRef(null);y.useEffect(()=>{var ue;const he=(l==null?void 0:l.state)==="done"?l.account:null,ge=he?`${he.num??""}|${he.email}`:null;!he||Z.current===ge||(Z.current=ge,(ue=Y.current)==null||ue.call(Y,he))},[l]),y.useEffect(()=>{var he;s==="paste"&&!q.current&&((he=$.current)==null||he.focus()),q.current=!1},[s]);const ee=y.useCallback(he=>{var ue;const ge=cG(he,qu.findIndex(be=>be.id===s),qu.length);ge.kind!=="pass"&&(he.preventDefault(),q.current=!0,o(qu[ge.index].id),(ue=K.current[ge.index])==null||ue.focus())},[s]),ne=y.useCallback(async()=>{var ge;if(!lr(B.current))return;B.current=!0,v(!0),j(null);const he=await Vo({action:"login-code",code:d}).catch(()=>null);if(B.current=!1,v(!1),!(he!=null&&he.ok)){j(Jo(he,"the code was not accepted")),he!=null&&he.state&&c(he),(ge=M.current)==null||ge.select();return}h(""),c(he)},[d,l]),se=y.useCallback(async()=>{if(!lr(B.current))return;B.current=!0,k(!0),_(null);const he=await Vo({action:"import",blob:f}).catch(()=>null);if(B.current=!1,k(!1),!(he!=null&&he.ok)){_(Jo(he,"the import failed"));return}O.current=f,p(""),F(null),C(he.results??[]),t()},[f,t]),pe=y.useCallback(async he=>{const ge=Qx(he);if(!lr(B.current)||!O.current)return;B.current=!0,k(!0),U(ge),F(null);const ue=await Vo({action:"import",blob:O.current,force:!0,only:{email:he.email,org:he.org??""}}).catch(()=>null);if(B.current=!1,k(!1),U(null),!(ue!=null&&ue.ok)){F({key:ge,text:Jo(ue,"that account could not be updated")});return}const be=(ue.results??[])[0];be&&C(oe=>mG(oe,ge,be)),t()},[t]),ke=(l==null?void 0:l.state)==="done"?l.account:null,ae=WV({restored:l==null?void 0:l.restored,activeAccount:l==null?void 0:l.activeAccount}),fe=VV({login:l,started:I.current,loginError:x,loginBusy:g}),me=zV({state:l==null?void 0:l.state,serverError:l==null?void 0:l.error,localError:x});return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...W,role:"presentation",children:a.jsxs("div",{ref:D,className:"modal aa-modal",onClick:he=>he.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{className:"aa-tabs",role:"tablist","aria-label":"How to add the account",onKeyDown:ee,children:qu.map((he,ge)=>a.jsx("button",{type:"button",role:"tab",id:$S(he.id),ref:ue=>{K.current[ge]=ue},"aria-selected":s===he.id,"aria-controls":MS,tabIndex:s===he.id?0:-1,className:`aa-tab${s===he.id?" on":""}`,onClick:()=>{q.current=!1,o(he.id)},children:he.label},he.id))})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:H,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsx("section",{className:"modal-body aa-body",id:MS,role:"tabpanel","aria-labelledby":$S(s),children:s==="login"?fe==="done"&&ke?a.jsxs("div",{className:"aa-done",children:[a.jsx(Td,{ref:G}),a.jsx(RS,{anchor:G}),a.jsx("h4",{children:ke.added?`Account ${ke.num} added`:"Credentials refreshed"}),a.jsxs("p",{className:"aa-note",children:[a.jsx("strong",{children:ke.email}),ke.added?ae?" 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."]}),ae?a.jsx("p",{className:"aa-note aa-warn",role:"status",children:ae}):null,a.jsx("button",{type:"button",className:"btn primary",onClick:H,children:"Done"})]}):fe==="code"&&l?a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"aa-step",children:[a.jsx("h4",{children:"1 · Approve in the browser"}),a.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),a.jsx("a",{className:"aa-link",href:l.url??"#",target:"_blank",rel:"noreferrer noopener",children:l.url})]}),a.jsxs("div",{className:"aa-step",children:[a.jsx("h4",{children:"2 · Paste a code, if the page shows one"}),a.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."}),a.jsxs("div",{className:"aa-field",children:[a.jsx("input",{ref:M,type:"text",value:d,onChange:he=>h(he.target.value),onKeyDown:he=>{he.key==="Enter"&&d.trim()&&!E&&ne()},placeholder:"paste the code here",spellCheck:!1,autoComplete:"off","aria-label":"Sign-in code",disabled:l.state==="registering"}),a.jsx("button",{type:"button",className:"btn primary",...Dr(E,!d.trim()||l.state==="registering"),onClick:ne,children:l.state==="registering"?"registering…":"Continue"})]}),(x||l.error)&&a.jsx("p",{className:"aa-err",children:x??l.error}),a.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."})]})]}):fe==="ended"?a.jsxs("div",{className:"aa-step",children:[a.jsx("h4",{children:me.title}),a.jsx("p",{className:"aa-err",children:me.message}),a.jsx("button",{type:"button",className:"btn",onClick:()=>{I.current=!1,c(null),j(null),J()},children:"Try again"})]}):fe==="asking"?a.jsx("div",{className:"aa-step",children:a.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):a.jsxs("div",{className:"aa-step aa-primer",children:[a.jsx("h4",{children:n?a.jsxs(a.Fragment,{children:["Sign in again as ",a.jsx("strong",{children:n})]}):"Sign in to Anthropic"}),a.jsxs("p",{className:"aa-note",children:["Opens a browser tab where you approve the sign-in",n?", with this address already filled in":"",". It normally completes by itself; only if the page hands you a code does it need pasting back here.",n?" claude-swap replaces the expired login in place — the account keeps its slot, its alias and its history — and the account you are using now stays active.":" claude-swap records the account when it completes, and the account you are using now stays active."]}),a.jsx("div",{className:"aa-actions",children:a.jsx("button",{type:"button",ref:P,className:"btn primary",...Dr(E),onClick:J,children:"Open the sign-in page"})})]}):R?(()=>{const he=R.filter(ue=>ue.state==="imported").length,ge=R.some(ue=>Cd(ue.check));return a.jsxs("div",{className:"aa-done",children:[!ge&&a.jsx(Td,{ref:G}),he>0&&!ge&&a.jsx(RS,{anchor:G}),a.jsx("h4",{children:yG(R)}),R.length>0&&a.jsx("ul",{className:"aa-results",children:R.map(ue=>{const be=Qx(ue),oe=Cd(ue.check);return a.jsxs("li",{className:`aa-result ${ue.state}`,children:[a.jsx("span",{className:"aa-result-who",children:ue.email||(ue.num?`slot ${ue.num}`:"an account")}),a.jsx("span",{className:"aa-result-what",children:gG(ue.state)}),ue.state==="present"&&a.jsx("button",{type:"button",className:"aa-result-fix","aria-busy":A===be,title:`Overwrite the stored login for ${ue.email} with the one in this share. Do this when that account has stopped working here; if it works, leave it.`,onClick:()=>pe(ue),children:A===be?"updating…":"update anyway"}),oe&&a.jsx("span",{className:"aa-result-err",children:oe.long}),(L==null?void 0:L.key)===be&&a.jsx("span",{className:"aa-result-err",children:L.text})]},be)})}),a.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",a.jsx("strong",{children:" update anyway"}),"."]}),a.jsxs("div",{className:"aa-actions",children:[a.jsx("button",{type:"button",className:"btn primary",onClick:H,children:"Done"}),a.jsx("button",{type:"button",className:"btn",onClick:()=>{O.current="",F(null),C(null)},children:"Import another"})]})]})})():a.jsxs("div",{className:"aa-step",children:[a.jsx("h4",{children:"Paste an account shared from another deck"}),a.jsxs("div",{className:"aa-field",children:[a.jsx("input",{ref:$,type:"text",value:f,onChange:he=>p(he.target.value),onKeyDown:he=>{he.key==="Enter"&&f.trim()&&!E&&se()},placeholder:"ccdeck2:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),a.jsx("button",{type:"button",className:"btn primary",...Dr(E,!f.trim()),onClick:se,children:N?"importing…":"Import"})]}),b&&a.jsx("p",{className:"aa-err",children:b}),a.jsxs("p",{className:"aa-note",children:["Use ",a.jsx("strong",{children:"share"})," on one account in the other deck, or ",a.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)}function vG(e,t){const n=new Set(e),r=e.length?Math.max(...e):0;return[...new Set([...e,r+1])].sort((s,o)=>s-o).map(s=>{const o=s===t?"here":n.has(s)?"swap":"free";return{slot:s,kind:o,label:o==="here"?`slot ${s}`:`slot ${s} · ${o}`}})}function xG(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}}const bG=64;function kG(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}function NG(e,t,n){return t!=null&&e.some(r=>r.slot===t)?t:n}function jG(e,t,n){var s;const r=((s=e.find(o=>o.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 SG(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 _G({a:e,slots:t,nowSec:n,boundaryId:r,accountMenu:s,busy:o,pressProps:l,rotating:c,onProjects:d,onRotation:h}){const{menu:f,menuError:p,aliasDraft:g,confirmRemove:v,share:N,shareCopied:k,slotDraft:x,dropMenu:j,closeMenu:b,startRename:_,typeAlias:E,doAlias:R,startMove:C,pickSlot:A,doSlot:U,makeShare:L,copyShare:F,pressRemove:O}=s;if(!f)return null;const I=`ap-pop-title-${e.num}`,B=p&&a.jsx("p",{className:"ap-pop-error",role:"alert",title:p.raw||void 0,children:p.text});return a.jsxs(dh,{anchorId:`ap-more-${e.num}`,boundaryId:r,id:`ap-menu-${e.num}`,className:"ap-pop",role:f.view==="menu"?"menu":"dialog",labelledBy:f.view==="menu"?`ap-more-${e.num}`:I,start:f.start,onClose:j,children:[f.view==="menu"&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>_(e.num,e.alias),children:"Rename"}),a.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>C(e.num),children:"Move to slot…"}),a.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...l(`share-${e.num}`),title:`Copy this account to another ${kt}. 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:()=>L(e.num),children:o===`share-${e.num}`?"Sharing…":"Share"}),a.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",title:"See how much this account worked in each project",onClick:()=>d(),children:"Projects"}),(c&&!e.active||e.disabled)&&a.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...l(`rot-${e.num}`),title:e.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",onClick:()=>h(),children:e.disabled?"Put back in rotation":"Hold out of rotation"}),a.jsx("div",{role:"separator",className:"ap-menu-sep"}),a.jsx("button",{type:"button",role:"menuitem",className:`ap-menu-item danger${v===e.num?" armed":""}`,...l(`rm-${e.num}`),"aria-label":v===e.num?"Confirm remove":void 0,title:v===e.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>O(e.num),children:o===`rm-${e.num}`?"Removing…":v===e.num?"Confirm":"Remove"}),B]}),f.view==="rename"&&a.jsxs("form",{className:"ap-pop-form",onSubmit:M=>{M.preventDefault(),R(e.num,e.alias)},children:[a.jsx("label",{className:"ap-pop-title",id:I,htmlFor:`ap-alias-${e.num}`,children:"Rename account"}),a.jsx("input",{id:`ap-alias-${e.num}`,className:"ap-manage-input",type:"text",value:g,onChange:M=>E(M.target.value),maxLength:bG,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:M=>M.currentTarget.select()}),B,a.jsxs("div",{className:"ap-pop-actions",children:[a.jsx("button",{type:"button",className:"btn",onClick:()=>b(),children:"Cancel"}),a.jsx("button",{type:"submit",className:"btn primary",...l(`alias-${e.num}`),title:"A short name to show instead of the email",children:o===`alias-${e.num}`?"…":"Save"})]})]}),f.view==="move"&&(()=>{const M=vG(t,e.num),$=NG(M,x,e.num),P=jG(M,$,e.num);return a.jsxs("div",{className:"ap-pop-form",children:[a.jsx("label",{className:"ap-pop-title",id:I,htmlFor:`ap-slot-${e.num}`,children:"Move to slot"}),a.jsx("span",{className:"ap-field",children:a.jsx("select",{id:`ap-slot-${e.num}`,value:String($),...l(`move-${e.num}`),onChange:G=>A(Number(G.target.value)),autoFocus:!0,children:M.map(G=>a.jsx("option",{value:G.slot,children:G.label},G.slot))})}),B,a.jsxs("div",{className:"ap-pop-actions",children:[a.jsx("button",{type:"button",className:"btn",onClick:()=>b(),children:"Cancel"}),a.jsx("button",{type:"button",className:"btn primary",...l(`move-${e.num}`),title:P.title,onClick:()=>U(e.num,$,P),children:o===`move-${e.num}`?"…":Sl(P.label)})]})]})})(),f.view==="share"&&(N==null?void 0:N.num)===e.num&&(()=>{const M=II(N.expiresAt,n),$=M.tone==="gone";return a.jsxs("div",{className:"ap-pop-form",children:[a.jsx("p",{className:"ap-pop-title",id:I,children:"Share account"}),a.jsx("code",{className:"ap-share-blob",children:N.blob}),a.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:[a.jsx("span",{className:"ap-share-warn",children:"This is the password"})," · ",a.jsx("span",{className:`ap-share-expiry ${M.tone}`,children:M.text})]}),B,a.jsxs("div",{className:"ap-pop-actions",children:[a.jsx("button",{type:"button",className:"btn",onClick:()=>b(),children:"Done"}),a.jsx("button",{type:"button",className:"btn primary",...l(`share-${e.num}`),autoFocus:!0,onClick:async()=>{if($){await L(e.num);return}await F(N.blob)},children:$?"Make a new share":k?"Copied":"Copy"})]})]})})()]})}const EG=6;function TG(e,t){const n=e.filter(c=>c.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",o=t.strained&&!t.armed?CG(n):null,l=[r];return o!=null&&l.push(`${o}% free`),l.push(t.armed?`auto ${t.threshold??"on"}${t.threshold?"%":""}`:"auto off"),{text:l.join(" · "),tone:s,free:o}}function CG(e){const t=e.map(n=>n.headroom).filter(n=>typeof n=="number");return t.length?Math.round(Math.max(...t)):null}function AG(e){const t=[...e].sort((s,o)=>{if(s.ready!==o.ready)return s.ready?-1:1;if(!s.ready)return s.name.localeCompare(o.name);const l=s.headroom,c=o.headroom;return l==null&&c==null?s.name.localeCompare(o.name):l==null?1:c==null?-1:c-l}),n=t.slice(0,EG),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 Fr(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 RG={keychain_unavailable:{short:"Keychain locked on the other Mac",long:`the other Mac could not export it. On that Mac: ${k0}. The next round brings it.`}};function eb(e){return e.why?Ot(RG,e.why)??Cd(e.why):null}const N0={"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"}},MG={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 IS(e){var r;const t=$G[e];if(t)return t;const n=(r=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:r[1];return n&&MG[n]||e}const $G={"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 fh(e,t){var f;if(!e)return null;if(e.error&&((f=e.done)!=null&&f.length)){const p=fh({...e,error:void 0},t),g=` · ${Fr(e.at,t)}`;return{...p,text:`${p.text.slice(0,-g.length)}, then ${IS(e.error)}${g}`,tone:"bad"}}if(e.error)return N0[e.error]??{text:IS(e.error),tone:"bad"};const n=e.done??[];if(!n.length)return{text:`all logins fine · ${Fr(e.at,t)}`,tone:"idle"};const r=n.filter(p=>p.ok),s=r.length===1?"login":"logins",o=n.map(p=>({d:p,why:eb(p)})).filter(p=>p.why),l=[...new Set(o.map(p=>p.why.short))],c=l.length?`, ${l.join(", ")}`:"",d=o.length?o.map(p=>`${p.d.email}: ${p.why.long}`).join(" "):void 0,h=Fr(e.at,t);return r.length===n.length?{text:`${r.length} ${s} arrived${c} · ${h}`,tone:o.length?"warn":"ok",...d?{hint:d}:{}}:{text:`${r.length} of ${n.length} logins arrived${c} · ${h}`,tone:"bad",...d?{hint:d}:{}}}const IG=9e4;function OG({error:e,host:t,port:n},r,s,o=45317){if(e!=="handshake timed out")return null;const l=(t??"").trim();if(!l)return null;const c=r.filter(h=>h.addr===l&&h.port&&h.at>0&&s-h.at<IG);if(!c.length)return null;const d=[...new Set(c.map(h=>h.port))];if(n!=null&&!d.includes(n)){const h=d.length===1?`port ${d[0]}`:`ports ${d.join(" and ")}`;return`A deck at ${l} is announcing itself on ${h}, 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 ${l}, not a network fault. Whoever uses it can allow two ports: UDP ${o} and TCP ${n??d[0]}.`}function ph(e,t){var n,r;return(n=e.last)!=null&&n.error&&!N0[e.last.error]?!1:!!((r=e.last)!=null&&r.at&&t-e.last.at<tb||e.lastSeen!=null&&t-e.lastSeen<tb)}const tb=95e3;function LG(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(p=>p.paired!==!1||p.met);if(!r.length)return{text:"no deck paired yet",tone:"idle"};const s=p=>p.waiting?LI(p.lastSeen,t):ph(p,t),o=p=>{var g;return!p.waiting&&((g=p.last)==null?void 0:g.error)==="waiting for the other deck to accept this one"},l=e.aliases??{};let c=0,d=0,h=0;for(const p of DI(r,g=>PI(g,g.peerFp??g.fp,l).name,g=>g.addr??"")){const g=p.filter(s);if(!g.length){h++;continue}c++,g.every(o)&&d++}if(c&&d===c)return{text:c===1?"1 deck found · waiting for them to accept":`${c} decks found · waiting for them to accept`,tone:"wait"};if(!c)return{text:h===1?"this deck cannot reach the one it is paired with":`this deck cannot reach any of its ${h} decks`,tone:"bad"};const f=c===1?"1 deck ready":`${c} decks ready`;return{text:h?`${f} · ${h} away`:f,tone:"ok"}}function PG(e,t,n){if(n)return"checking…";if(e==null)return"not checked yet";const r=Fr(e,t);return r==="now"?"checked just now":`checked ${r}`}function j0(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 LI(e,t){return e!=null&&t-e<tb}function DG(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=LI(e,t);return{text:n?"online · one-way, it calls in":`one-way · last online ${Fr(e,t)}`,here:n}}function OS(e,t,n){return t?"online":e.lastSeen!=null?`last online ${Fr(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function FG(e,t){if(!e)return[];const n=[],r=new Set,s=(p,g)=>p.name.localeCompare(g.name,void 0,{numeric:!0}),o=e.aliases??{};for(const p of e.pending??[])!(p!=null&&p.fp)||r.has(p.fp)||(r.add(p.fp),n.push(BG(p,o,t)));const l=[],c=[];for(const p of e.peers??[]){const g=p.peerFp??p.fp;!g||r.has(g)||(r.add(g),!p.paired&&p.manual&&!p.met?c.push(qG(p,g,t)):l.push(UG(p,g,o,t)))}n.push(...HG(l).sort(s),...c.sort(s));const d=[];for(const p of e.strangers??[])!(p!=null&&p.fp)||r.has(p.fp)||(r.add(p.fp),d.push(zG(p,o,e.pairingMode)));n.push(...d.sort(s));const h=[];for(const p of e.declined??[])!(p!=null&&p.fp)||r.has(p.fp)||(r.add(p.fp),h.push(WG(p,o)));n.push(...h.sort(s));const f=new Map;for(const p of n)f.set(p.name,(f.get(p.name)??0)+1);for(const p of n)(f.get(p.name)??0)<2||!p.addr||(p.state=p.quiet||!p.state?p.addr:`${p.addr} · ${p.state}`,p.quiet=!1);return n}function BG(e,t,n){const r=mh(t,e.fp,e.name||e.fp);return{fp:e.fp,...r,addr:e.addr??"",kind:"asks",state:`wants to pair · ${j0(e.at,n)}`,tone:"wait",here:!0,hint:`${r.name} at ${e.addr}${e.via==="tailscale"?", over Tailscale,":""} is waiting for an answer.`,...gh(e.via)}}function qG(e,t,n){var o;const r=fh(e.last,n),s=e.addr?`${e.addr}:${e.port}`:"";return{fp:s,name:s||e.name||t,addr:e.addr??"",kind:"dialling",state:r?nb(r):"trying…",tone:r?r.tone:"idle",here:!1,hint:(o=e.last)!=null&&o.error?`Nothing has answered at ${s} yet — ${e.last.error}.`:`Dialling ${s} until something answers.`,...gh(e.via)}}function UG(e,t,n,r){var v,N,k,x;const s=fh(e.last,r),o=ph(e,r),l=e.addr?`${e.addr}:${e.port}`:"",c=e.waiting?DG(e.lastSeen,r):null,d=c?c.here:o,h=!c&&s?d?`online · ${nb(s)}`:`${nb(s)} · ${OS(e,d,r)}`:c?c.text:OS(e,d,r),f=(v=e.last)!=null&&v.error?N0[e.last.error]:null,p=!c&&d&&!((N=e.last)!=null&&N.error)&&!(((k=e.last)==null?void 0:k.done)??[]).length,g=PI(e,t,n);return{fp:t,...g,addr:e.addr??"",kind:"paired",state:h,quiet:p,tone:f?f.tone==="bad"?"bad":"wait":s?s.tone:d?"ok":"idle",here:c?c.here:o,...gh(e.via),hint:c?`${g.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. ${e.lastSeen==null?"It has not called since this deck started.":`It last called ${Fr(e.lastSeen,r)}.`} Add its address through Add a deck, the link at the top of this view, to reach it either way.`:`${g.name}${l?` at ${l}`:""}${(x=e.last)!=null&&x.error?` — ${e.last.error}`:""}${s!=null&&s.hint?` — ${s.hint}`:""}`}}function PI(e,t,n){return e.manual&&!e.met?{name:e.addr?`${e.addr}:${e.port}`:""}:mh(n,t,e.name||t)}function zG(e,t,n){const r=mh(t,e.fp,e.name||e.fp);return{fp:e.fp,...r,addr:e.addr??"",kind:"nearby",state:n==="invite"?"needs an invite":"not paired yet",tone:"idle",here:!0,hint:e.via==="tailscale"?`${r.name} at ${e.addr} is on your tailnet and nothing is shared with it.`:`${r.name} at ${e.addr} is on this network and nothing is shared with it.`,...gh(e.via)}}function WG(e,t){const n=mh(t,e.fp,e.name||e.fp);return{fp:e.fp,...n,addr:e.addr??"",kind:"declined",state:"you said no",tone:"idle",here:!1,hint:`${n.name} asked and was turned away. It is not asking any more.`}}function mh(e,t,n){const r=t?e[t]:void 0;return r&&r!==n?{name:r,self:n}:{name:n}}function gh(e){return e==="tailscale"?{via:"tailscale"}:{}}function nb(e){return e.text.replace(/ · .*$/,"")}function HG(e){return DI(e,t=>t.name,t=>t.addr).map(VG)}function DI(e,t,n){const r=new Map;for(const o of e){const l=r.get(t(o));l?l.push(o):r.set(t(o),[o])}const s=[];for(const o of r.values()){const l=[...new Set(o.map(n).filter(Boolean))];if(l.length>1){for(const c of l)s.push(o.filter(d=>n(d)===c));for(const c of o)n(c)||s.push([c])}else s.push(o)}return s}function VG(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 LS(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function ec(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 GG(e,t){var o;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(l=>l.kind==="asks").length;if(n)return{text:n===1?"1 deck wants to pair":`${n} decks want to pair`,tone:"wait",live:!1};if((o=e.reach)!=null&&o.blocked)return{text:"nothing can get in",tone:"bad",live:!1};const r=t.filter(l=>l.kind==="paired");if(!r.length)return{text:"On · none paired yet",tone:"idle",live:!1};const s=r.filter(l=>l.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 KG(e,t){const n=e.filter(f=>f.kind==="asks"),r=e.filter(f=>f.kind!=="asks"),s=r.filter(f=>f.here),o=r.filter(f=>!f.here),l=o.filter(f=>f.tone==="bad").length,c=t||s.length===0,d=c?[...s,...o]:s,h=r.filter(f=>f.kind==="paired").length;return{asks:n,rest:r,live:s,folded:o,troubled:l,showFolded:c,shown:d,paired:h}}function PS(e){return e.map(t=>({key:`${String(t.email??"").trim().toLowerCase()}@@${t.orgUuid??""}`,email:t.email??"",alive:t.alive===!0,shareable:t.collector==="ok"||t.collector==null&&!t.active}))}function YG(e,t,n){if(!(t!=null&&t.enabled)||!(t.shared??[]).includes(e))return!1;const r=(t.peers??[]).filter(s=>s.paired&&ph(s,n)).map(s=>{var o,l;return(l=(o=s.offers)==null?void 0:o.accounts)==null?void 0:l.find(c=>c.key===e)}).filter(s=>s!=null);return r.length>0&&r.every(s=>!s.alive)}function XG(e,t,n,r){if(!(n!=null&&n.enabled)||n.running===!1||!(n.shared??[]).includes(e))return!1;const s=String(t??"").trim().toLowerCase();return(n.peers??[]).some(o=>{var c,d,h,f;if(!o.paired||!ph(o,r))return!1;const l=(d=(c=o.offers)==null?void 0:c.accounts)==null?void 0:d.find(p=>p.key===e);return!(l!=null&&l.alive)||l.shareable===!1?!1:!((f=(h=o.last)==null?void 0:h.done)!=null&&f.some(p=>p.action==="heal"&&String(p.email??"").trim().toLowerCase()===s))})}const FI=160,BI=140;function ZG(){const[e,t]=y.useState(!1),n=y.useRef(0);return y.useEffect(()=>()=>window.clearTimeout(n.current),[]),{peek:e,openPeek:c=>{window.clearTimeout(n.current),n.current=window.setTimeout(()=>t(!0),c)},shutPeek:()=>{window.clearTimeout(n.current),n.current=window.setTimeout(()=>t(!1),BI)},holdPeek:()=>window.clearTimeout(n.current),dropPeek:()=>{window.clearTimeout(n.current),t(!1)}}}function JG(e){var t;return((t=e==null?void 0:e.detail)==null?void 0:t.fix)==="give_back"}function sr(e,t){return{text:e,giveBack:JG(t),done:!1}}async function QG(){try{return await(await fetch("/api/prefs/give-back",{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"})).json().catch(()=>null)}catch{return null}}const eK={cancelled:"Nothing changed — the password dialog was closed. The folder still belongs to another user.",timed_out:"Nothing changed — the password dialog was not answered in time.",busy:"The password dialog is already open. It may be behind this window."};function tK(e){if(e!=null&&e.ok)return{text:e.changed===!1?"The settings folder is already yours, and the deck has read it again. Try that once more.":"Done — the settings folder is yours again, and the deck has read it again. Try that once more.",giveBack:!1,done:!0};if(e==null)return{text:"Could not give it back — the deck did not answer.",giveBack:!0,done:!1};const t=e.reason?eK[e.reason]:void 0;return t?{text:t,giveBack:!0,done:!1}:{text:"macOS did not give the folder back. The deck's log has the command that does it by hand.",giveBack:!1,done:!1}}const rb=5e3,qI=6e4;function Tt(e,t){if(t==null)return`Could not ${e} — the deck did not answer.`;const n=t.reason?sK(t.reason,t.detail):void 0;return n?`Could not ${e} — ${n}`:t.reason?`Could not ${e} — the deck refused it (${t.reason}).`:`Could not ${e}.`}const nK={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."},rK=new Set(["EACCES","EPERM"]);function sK(e,t){const n=nK[e];if(!n)return;const r=e==="prefs_unreadable"&&t?aK(t):void 0,s=t!=null&&t.code&&t.code!=="BADJSON"?` Error code: ${t.code}.`:"";return(r??n)+s}function aK({code:e,owner:t,on:n}){if(e==="BADJSON")return"its settings file is damaged and could not be moved aside, so it will not write over it. The deck's log names the file.";if(n==="folder"&&t==="other")return"this deck cannot open its settings folder, which belongs to another user, for example after ccdeck was run with sudo. The deck's log has the command that gives it back.";if(n==="folder"&&t==="you")return"this deck cannot open its own settings folder, so it will not write over what is in it. The deck's log names the folder.";if(t==="other")return"its settings file belongs to another user and could not be moved aside, so it will not write over it. The deck's log names the file.";if(t==="you")return"this deck cannot read its settings file although the file is yours, so it will not write over it. Something on this machine is blocking the read; the deck's log names the file.";if(e&&!rK.has(e))return"this deck cannot read its settings file, so it will not write over it. The deck's log names the file."}async function Go(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function oK(e,t){const[n,r]=y.useState(null),[s,o]=y.useState([]),[l,c]=y.useState(null),[d,h]=y.useState(null),f=y.useRef(null),p=y.useCallback(O=>lh(f.current)?(f.current=O,c(O),!0):!1,[]),g=y.useCallback(()=>{f.current=null,x.current&&c(null)},[]),v=O=>{const I=ia(l,O);return{disabled:I.disabled,"aria-busy":I.busy}},[N,k]=y.useState(()=>Date.now()),x=y.useRef(!0),j=y.useRef(rb),b=y.useCallback(async()=>{var O,I;try{const[B,M]=await Promise.all([fetch("/api/lan").then($=>$.json()),fetch("/api/prefs").then($=>$.json())]);if(!x.current)return;B!=null&&B.ok&&r(B),M!=null&&M.ok&&o(Array.isArray((I=(O=M.prefs)==null?void 0:O.lan)==null?void 0:I.manual)?M.prefs.lan.manual:[]),j.current=(B==null?void 0:B.enabled)===!0?rb:qI}catch{}},[]);y.useEffect(()=>{x.current=!0;let O=0;const I=async()=>{k(Date.now()),await b(),x.current&&(O=window.setTimeout(I,j.current))};return I(),()=>{x.current=!1,window.clearTimeout(O)}},[b]);const _=y.useCallback(async()=>{const O=(n==null?void 0:n.enabled)===!0;if(p("switch"))try{const I=await Go("/api/prefs",{lan:{enabled:!O}});if(!x.current)return;I!=null&&I.ok?(h(null),O||t()):h(sr(Tt(O?"turn this off":"turn this on",I),I)),await b()}catch{x.current&&h(sr(Tt(O?"turn this off":"turn this on",null)))}finally{g()}},[n==null?void 0:n.enabled,b,p,g,t]),E=y.useCallback(async(O,I,B)=>{if(!p(`${O}:${I}`))return null;let M=null;try{const $=await Go("/api/lan/peer",{action:O,fp:I});if(!x.current)return null;$!=null&&$.ok?(r($),h(null)):(M=Tt(B,$),h(sr(M,$))),await b()}catch{M=Tt(B,null),x.current&&h(sr(M))}finally{g()}return M},[b,p,g]),R=y.useCallback(async O=>{if(!p(`drop:${O}`))return null;let I=null;try{const B=await Go("/api/prefs",{lan:{manual:s.filter(M=>M!==O)}});if(!x.current)return null;B!=null&&B.ok?(h(null),e()):(I=Tt("stop dialling that address",B),h(sr(I,B))),await b()}catch{I=Tt("stop dialling that address",null),x.current&&h(sr(I))}finally{g()}return I},[s,b,e,p,g]),C=y.useCallback(async(O,I)=>{if(!p(`alias:${O}`))return"Something else is still being saved. Try again in a moment.";try{const B=await Go("/api/lan/peer",{action:"alias",fp:O,name:I});return x.current?B!=null&&B.ok?(r(B),null):Tt("rename that deck",B):null}catch{return Tt("rename that deck",null)}finally{g()}},[p,g]),A=y.useCallback(async O=>{if(!p(`check:${O}`))return null;try{const I=await Go("/api/lan/sync",{fp:O});return x.current?I!=null&&I.ok?(r(I),e(),null):(I==null?void 0:I.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.":Tt("check that deck",I):null}catch{return Tt("check that deck",null)}finally{g()}},[p,g,e]),U=y.useCallback(async()=>{if(p("check"))try{const O=await Go("/api/lan/sync",{});if(!x.current)return;O!=null&&O.ok?(r(O),h(null)):h(sr(Tt("check the other decks",O),O)),e()}catch{x.current&&h(sr(Tt("check the other decks",null)))}finally{g()}},[p,g,e]);return{status:n,manual:s,now:N,busy:l,failure:d,dismissFailure:()=>h(null),answerGiveBack:O=>{h(O),O.done&&(b(),e())},pressProps:v,load:b,toggle:_,answer:E,dropAddress:R,rename:C,checkOne:A,checkNow:U}}function iK(e){const[t,n]=y.useState(null),r=y.useRef(0);return y.useEffect(()=>{if(t==null)return;const o=window.setTimeout(()=>n(null),4e3);return()=>window.clearTimeout(o)},[t]),{armed:t,pressUnpair:o=>{const l=Date.now(),c=Yl({armedFor:t,target:o.fp,armedAt:r.current,now:l,gapMs:Kl});if(c==="arm"){n(o.fp),r.current=l;return}c!=="ignore"&&(n(null),e("unpair",o.fp,"unpair that deck"))}}}function UI({title:e,steps:t,finish:n,aside:r,onClose:s}){const o=y.useRef(null),l=ut(s,{focusRef:o}),c=gt(s),[d,h]=y.useState(0),f=d===t.length-1,p=t[d],g=k=>h(Math.max(0,Math.min(t.length-1,k)));y.useEffect(()=>{var k,x;Tn(((k=document.activeElement)==null?void 0:k.tagName)??null)&&((x=o.current)==null||x.focus())},[d]);const v=k=>{k.key!=="ArrowRight"&&k.key!=="ArrowLeft"||(k.preventDefault(),k.stopPropagation(),g(k.key==="ArrowRight"?d+1:d-1))},N=()=>{if(!f){g(d+1);return}n?n.act():s()};return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...c,role:"presentation",children:a.jsxs("div",{ref:l,className:"modal guide",onClick:k=>k.stopPropagation(),onKeyDown:v,role:"dialog","aria-modal":"true","aria-labelledby":"guide-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsxs("div",{className:"modal-title",children:[a.jsx("span",{id:"guide-title",className:"modal-tool-name",children:e}),a.jsxs("span",{className:"modal-tool-id",children:[d+1," / ",t.length]})]}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:s,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[a.jsx("div",{className:"guide-stage",children:p.art},d),a.jsx("p",{className:"guide-line","aria-live":"polite",children:p.line}),a.jsx("p",{className:"guide-tip",children:p.tip??""}),a.jsxs("div",{className:"guide-foot",children:[a.jsx("div",{className:"guide-dots",children:t.map((k,x)=>a.jsx("button",{type:"button",className:"glyph-btn guide-dot","aria-label":`Step ${x+1} of ${t.length}`,"aria-current":x===d?"step":void 0,onClick:()=>g(x)},x))}),f&&r&&a.jsx("button",{type:"button",className:"ap-lan-word guide-aside",onClick:r.act,children:r.label}),d>0&&a.jsx("button",{type:"button",className:"btn",onClick:()=>g(d-1),children:"Back"}),a.jsx("button",{ref:o,type:"button",className:"btn primary",onClick:N,children:f?(n==null?void 0:n.label)??"Done":"Next"})]})]})]})}),document.body)}const sb={ok:"ga-ok",warn:"ga-warn",accent:"ga-accent",flight:"ga-flight"};function Hn({children:e}){return a.jsx("svg",{className:"guide-art",viewBox:"0 0 440 200","aria-hidden":!0,focusable:"false",children:e})}function Wn({x:e,y:t=34,w:n=176,h:r=132,label:s}){return a.jsxs(a.Fragment,{children:[s&&a.jsx("text",{x:e+2,y:t-9,className:"ga-cap",children:s}),a.jsx("rect",{x:e,y:t,width:n,height:r,rx:10,className:"ga-screen"})]})}function ur({x:e,y:t,email:n,state:r,tone:s,bars:o}){return a.jsxs(a.Fragment,{children:[a.jsx("circle",{cx:e+3,cy:t-4,r:3,className:sb[s]}),a.jsx("text",{x:e+12,y:t,className:"ga-t ga-mono",children:n}),a.jsx("text",{x:e+12,y:t+16,className:`ga-s ${sb[s]}`,children:r}),o==null?void 0:o.map((l,c)=>a.jsxs("g",{children:[a.jsx("text",{x:e,y:t+40+c*18,className:"ga-s",children:c?"7d":"5h"}),a.jsx("rect",{x:e+22,y:t+35+c*18,width:96,height:4,rx:2,className:"ga-track"}),a.jsx("rect",{x:e+22,y:t+35+c*18,width:96*l/100,height:4,rx:2,className:"ga-accent"}),a.jsxs("text",{x:e+148,y:t+40+c*18,className:"ga-s ga-accent",textAnchor:"end",children:[l,"%"]})]},c))]})}function zI({x:e,y:t,on:n}){return a.jsxs(a.Fragment,{children:[a.jsx("rect",{x:e,y:t,width:30,height:18,rx:9,className:n?"ga-switch-on":"ga-switch"}),a.jsx("circle",{cx:n?e+21:e+9,cy:t+9,r:6,className:n?"ga-knob-on":"ga-knob"})]})}function Uu({x:e,y:t,name:n,here:r=!0}){return a.jsxs(a.Fragment,{children:[a.jsx("circle",{cx:e+3,cy:t-4,r:3,className:r?"ga-ok":"ga-dim"}),a.jsx("text",{x:e+12,y:t,className:r?"ga-t":"ga-s",children:n})]})}function DS({x:e,y:t,on:n}){return n?a.jsxs(a.Fragment,{children:[a.jsx("rect",{x:e,y:t,width:12,height:12,rx:3,className:"ga-accent"}),a.jsx("path",{d:`M${e+3} ${t+6.2}l2.3 2.3 4-4.6`,className:"ga-tick"})]}):a.jsx("rect",{x:e+.5,y:t+.5,width:11,height:11,rx:3,className:"ga-box"})}function FS({x:e,y:t,d:n}){return a.jsx("path",{d:n,transform:`translate(${e} ${t})`,className:"ga-glyph"})}function S0({x:e,y:t}){return a.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 _0(){return a.jsxs(a.Fragment,{children:[a.jsx("circle",{r:9,className:"ga-key-bed"}),a.jsxs("g",{transform:"translate(-6 -6) scale(0.857)",className:"ga-key",children:[a.jsx("circle",{cx:4.6,cy:7,r:2.6}),a.jsx("path",{d:"M7.2 7h5.2M10.6 7v2.2M12.4 7v1.6"})]})]})}function Qo({x:e,y:t,w:n,title:r,sub:s,tone:o}){return a.jsxs(a.Fragment,{children:[a.jsx("rect",{x:e,y:t,width:n,height:40,rx:8,className:"ga-screen"}),a.jsx("rect",{x:e+6,y:t+10,width:3,height:20,rx:1.5,className:sb[o]}),a.jsx("text",{x:e+16,y:t+17,className:"ga-t ga-strong",children:r}),a.jsx("text",{x:e+16,y:t+31,className:"ga-s",children:s})]})}function oi({x:e,y:t,label:n,live:r}){return a.jsxs(a.Fragment,{children:[a.jsx("rect",{x:e,y:t,width:46,height:20,rx:10,className:r?"ga-chip-live":"ga-chip"}),a.jsx("text",{x:e+23,y:t+14,className:"ga-s ga-mono",textAnchor:"middle",children:n})]})}function Ad({x:e,y:t}){return a.jsxs(a.Fragment,{children:[a.jsx("text",{x:e,y:t,className:"ga-cap",children:"LOCAL NETWORK"}),a.jsx(zI,{x:e+118,y:t-13,on:!0})]})}function lK(){return a.jsxs(Hn,{children:[a.jsx("rect",{x:14,y:14,width:206,height:172,rx:10,className:"ga-screen"}),a.jsx("text",{x:28,y:38,className:"ga-t ga-strong",children:"Sessions"}),a.jsx("text",{x:206,y:38,className:"ga-s ga-warn",textAnchor:"end",children:"1 waiting"}),a.jsx("rect",{x:20,y:50,width:194,height:42,rx:6,className:"ga-bed-warn"}),a.jsx("circle",{cx:33,cy:64,r:7,className:"ga-ring-warn ga-ping"}),a.jsx("circle",{cx:33,cy:64,r:3.5,className:"ga-warn"}),a.jsx("text",{x:44,y:68,className:"ga-t",children:"api-server"}),a.jsx("text",{x:44,y:83,className:"ga-s ga-warn",children:"waiting 6m · Bash"}),a.jsx("circle",{cx:33,cy:108,r:3.5,className:"ga-flight"}),a.jsx("text",{x:44,y:112,className:"ga-t",children:"docs-site"}),a.jsx("text",{x:44,y:127,className:"ga-s",children:"running · 12 tools"}),a.jsx("circle",{cx:33,cy:150,r:3.5,className:"ga-ok"}),a.jsx("text",{x:44,y:154,className:"ga-t",children:"billing"}),a.jsx("text",{x:44,y:169,className:"ga-s",children:"done · $0.84"}),a.jsx("path",{d:"M216 71C234 71 230 100 244 100",className:"ga-arc"}),a.jsx("path",{d:"M239 96l5 4-5 4",className:"ga-arrow"}),a.jsx("rect",{x:248,y:44,width:178,height:112,rx:10,className:"ga-screen"}),a.jsx("text",{x:262,y:64,className:"ga-cap",children:"API-SERVER"}),a.jsx("line",{x1:248,y1:74,x2:426,y2:74,className:"ga-line"}),a.jsx("text",{x:262,y:96,className:"ga-s ga-mono",children:"Bash(npm test)"}),a.jsx("text",{x:262,y:116,className:"ga-t ga-mono ga-warn",children:"Allow this command?"}),a.jsx("text",{x:262,y:136,className:"ga-s ga-mono",children:"> 1. Yes 2. No"})]})}function cK(){return a.jsxs(Hn,{children:[a.jsx("path",{d:"M136 100C166 100 166 38 196 38",className:"ga-edge ga-flow"}),a.jsx("path",{d:"M136 100H196",className:"ga-edge ga-flow"}),a.jsx("path",{d:"M136 100C166 100 166 162 196 162",className:"ga-edge-done"}),a.jsx("path",{d:"M308 38H326M308 100H326",className:"ga-edge"}),a.jsx(Qo,{x:20,y:80,w:116,title:"main",sub:"Opus 5 · 9 tools",tone:"accent"}),a.jsx(Qo,{x:196,y:18,w:112,title:"explore",sub:"Haiku · 14 tools",tone:"flight"}),a.jsx(Qo,{x:196,y:80,w:112,title:"tests",sub:"Sonnet · 6 tools",tone:"flight"}),a.jsx(Qo,{x:196,y:142,w:112,title:"review",sub:"done · 38s",tone:"ok"}),a.jsx(oi,{x:326,y:28,label:"Read"}),a.jsx(oi,{x:380,y:28,label:"Grep",live:!0}),a.jsx(oi,{x:326,y:90,label:"Bash",live:!0})]})}function BS({x:e,y:t,label:n,pct:r,note:s}){return a.jsxs(a.Fragment,{children:[a.jsx("text",{x:e,y:t,className:"ga-s",children:n}),a.jsxs("text",{x:e+194,y:t,className:"ga-s ga-accent",textAnchor:"end",children:[r,"%"]}),a.jsx("rect",{x:e,y:t+7,width:194,height:5,rx:2.5,className:"ga-track"}),a.jsx("rect",{x:e,y:t+7,width:194*r/100,height:5,rx:2.5,className:"ga-accent"}),a.jsx("text",{x:e,y:t+26,className:"ga-s",children:s})]})}function uK(){return a.jsxs(Hn,{children:[a.jsx("rect",{x:14,y:30,width:172,height:140,rx:10,className:"ga-screen"}),a.jsx("text",{x:30,y:56,className:"ga-cap",children:"THIS SESSION"}),a.jsx("text",{x:30,y:98,className:"ga-big",children:"$3.66"}),a.jsx("text",{x:30,y:122,className:"ga-s",children:"Opus 5 · 1.2M tokens"}),a.jsx("text",{x:30,y:150,className:"ga-s",children:"$21.40 today"}),a.jsx("rect",{x:200,y:30,width:226,height:140,rx:10,className:"ga-screen"}),a.jsx("text",{x:216,y:56,className:"ga-cap",children:"CLAUDE QUOTA"}),a.jsx(BS,{x:216,y:80,label:"5-hour window",pct:24,note:"resets in 53m"}),a.jsx(BS,{x:216,y:124,label:"7-day window",pct:61,note:"resets in 4d"})]})}function dK(){return a.jsxs(Hn,{children:[a.jsx("rect",{x:14,y:40,width:172,height:120,rx:10,className:"ga-canvas"}),a.jsx(Qo,{x:30,y:80,w:140,title:"tests",sub:"Sonnet 5 · 6 tools",tone:"flight"}),a.jsx(S0,{x:156,y:106}),a.jsx("path",{d:"M170 92C186 92 184 60 200 60",className:"ga-arc"}),a.jsx("path",{d:"M195 56l5 4-5 4",className:"ga-arrow"}),a.jsx(Wn,{x:200,y:22,w:226,h:160}),a.jsx("text",{x:214,y:46,className:"ga-t ga-strong",children:"tests"}),a.jsx("text",{x:412,y:46,className:"ga-s",textAnchor:"end",children:"Sonnet 5 · 38s"}),a.jsx("line",{x1:200,y1:56,x2:426,y2:56,className:"ga-line"}),a.jsx("text",{x:214,y:76,className:"ga-cap",children:"PROMPT"}),a.jsx("text",{x:214,y:92,className:"ga-t",children:"Run the suite and fix what fails"}),a.jsx("text",{x:214,y:116,className:"ga-cap",children:"TOOLS · 6"}),a.jsx(oi,{x:214,y:122,label:"Read"}),a.jsx(oi,{x:266,y:122,label:"Edit"}),a.jsx(oi,{x:318,y:122,label:"Bash",live:!0}),a.jsx("text",{x:214,y:164,className:"ga-cap",children:"TOKENS"}),a.jsx("text",{x:214,y:178,className:"ga-s ga-mono",children:"41k in · 2.1k out · $0.12"})]})}function hK(){const e=[18,24,28,14,22,26,30,16,24,28,20,26];return a.jsxs(Hn,{children:[a.jsx(Wn,{x:14,y:20,w:412,h:160}),a.jsx("text",{x:28,y:44,className:"ga-t ga-strong",children:"This machine"}),a.jsx("text",{x:412,y:44,className:"ga-s",textAnchor:"end",children:"12 cores · up 10d"}),a.jsx("line",{x1:14,y1:56,x2:426,y2:56,className:"ga-line"}),a.jsx("text",{x:28,y:76,className:"ga-cap",children:"CORES"}),e.map((t,n)=>a.jsxs("g",{children:[a.jsx("rect",{x:28+n*15,y:82,width:10,height:30,rx:2,className:"ga-track"}),a.jsx("rect",{x:28+n*15,y:112-t,width:10,height:t,rx:2,className:"ga-accent"})]},n)),a.jsx("text",{x:28,y:136,className:"ga-cap",children:"MEMORY"}),a.jsx("rect",{x:28,y:143,width:178,height:5,rx:2.5,className:"ga-track"}),a.jsx("rect",{x:28,y:143,width:105,height:5,rx:2.5,className:"ga-accent"}),a.jsx("text",{x:28,y:165,className:"ga-s",children:"18.9 GB of 32.0 GB"}),a.jsx("text",{x:240,y:76,className:"ga-cap",children:"THERMAL"}),a.jsx("text",{x:240,y:100,className:"ga-big",children:"66 °C"}),a.jsx("text",{x:240,y:118,className:"ga-s ga-ok",children:"running at full speed"}),a.jsx("text",{x:240,y:142,className:"ga-cap",children:"BUSIEST PROCESSES"}),a.jsx("text",{x:240,y:160,className:"ga-s ga-mono",children:"node · claude"}),a.jsx("text",{x:412,y:160,className:"ga-s ga-mono",textAnchor:"end",children:"38%"}),a.jsx("text",{x:240,y:176,className:"ga-s ga-mono",children:"esbuild"}),a.jsx("text",{x:412,y:176,className:"ga-s ga-mono",textAnchor:"end",children:"21%"})]})}function fK(){return a.jsxs(Hn,{children:[a.jsx("rect",{x:14,y:40,width:188,height:120,rx:10,className:"ga-screen"}),a.jsx("text",{x:28,y:60,className:"ga-cap",children:"~/MY-PROJECT"}),a.jsx("line",{x1:14,y1:70,x2:202,y2:70,className:"ga-line"}),a.jsxs("text",{x:28,y:100,className:"ga-t ga-mono",children:[a.jsx("tspan",{className:"ga-accent",children:"$"})," claude"]}),a.jsx("rect",{x:86,y:90,width:7,height:13,className:"ga-caret ga-blink"}),a.jsx("text",{x:28,y:130,className:"ga-s ga-mono",children:"or: codex"}),a.jsx("path",{d:"M210 100H238",className:"ga-arc"}),a.jsx("path",{d:"M233 95l6 5-6 5",className:"ga-arrow"}),a.jsx("rect",{x:250,y:40,width:176,height:120,rx:10,className:"ga-canvas"}),a.jsx("g",{className:"ga-pop",children:a.jsx(Qo,{x:278,y:80,w:120,title:"my-project",sub:"Opus 5 · live",tone:"accent"})})]})}function pK(){return a.jsxs(Hn,{children:[a.jsx(Wn,{x:14,y:16,w:232,h:170}),a.jsx("text",{x:28,y:40,className:"ga-t ga-strong",children:"Claude accounts"}),a.jsx(FS,{x:196,y:33,d:"M7 2.2v9.6M2.2 7h9.6"}),a.jsx(FS,{x:220,y:33,d:"M3.3 10.7L10.7 3.3M5.2 3.3h5.5v5.5"}),a.jsx("line",{x1:14,y1:52,x2:246,y2:52,className:"ga-line"}),a.jsx(ur,{x:28,y:74,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),a.jsx("rect",{x:190,y:62,width:44,height:18,rx:9,className:"ga-accent"}),a.jsx("text",{x:212,y:74,className:"ga-s ga-on-accent",textAnchor:"middle",children:"active"}),a.jsx("line",{x1:14,y1:140,x2:246,y2:140,className:"ga-line"}),a.jsx(ur,{x:28,y:160,email:"personal@me.dev",state:"signed in",tone:"ok"}),a.jsx("rect",{x:188,y:148,width:46,height:18,rx:9,className:"ga-chip"}),a.jsx("text",{x:211,y:160,className:"ga-s",textAnchor:"middle",children:"switch"}),a.jsx(S0,{x:221,y:161}),a.jsx("path",{d:"M250 40C270 40 262 78 282 78",className:"ga-arc"}),a.jsx("path",{d:"M277 74l5 4-5 4",className:"ga-arrow"}),a.jsx(Wn,{x:282,y:62,w:144,h:64,label:"ANOTHER MACHINE"}),a.jsx("g",{className:"ga-pop",children:a.jsx(ur,{x:296,y:92,email:"work@team.dev",state:"shared here",tone:"ok"})})]})}function mK(){return a.jsxs(Hn,{children:[a.jsx(Wn,{x:14,label:"THIS MACHINE"}),a.jsx(Ad,{x:28,y:60}),a.jsx("g",{className:"ga-swap-out",children:a.jsx(ur,{x:28,y:98,email:"work@team.dev",state:"login expired",tone:"warn"})}),a.jsx("g",{className:"ga-swap-in",children:a.jsx(ur,{x:28,y:98,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),a.jsx(Wn,{x:250,label:"ANOTHER MACHINE"}),a.jsx(Ad,{x:264,y:60}),a.jsx(ur,{x:264,y:98,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),a.jsx("path",{d:"M246 120C234 80 206 80 194 120",className:"ga-arc"}),a.jsx("g",{className:"ga-travel ga-travel-low",transform:"translate(220 90)",children:a.jsx(_0,{})})]})}const gK=[{art:a.jsx(lK,{}),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:a.jsx(cK,{}),line:"Every agent and subagent is a node. Tool calls light up as they run."},{art:a.jsx(dK,{}),line:"Double-click any node: its prompt, every tool call, tokens and timing."},{art:a.jsx(uK,{}),line:"What each session costs, and how much quota is left."},{art:a.jsx(hK,{}),line:"Cores, memory and heat while the agents run, and what is hogging them."},{art:a.jsx(pK,{}),line:"Several Claude accounts: switch, add one, share one to another machine."},{art:a.jsx(mK,{}),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:a.jsx(fK,{}),line:"Run claude or codex in any folder. It shows up here on its own."}];function yK(){return a.jsxs(Hn,{children:[a.jsx(Wn,{x:14,label:"THIS MACHINE"}),a.jsx(ur,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"}),a.jsx("rect",{x:40,y:94,width:86,height:20,rx:10,className:"ga-pill-warn"}),a.jsx("text",{x:83,y:108,className:"ga-s ga-warn",textAnchor:"middle",children:"sign in again"}),a.jsx("line",{x1:198,y1:100,x2:242,y2:100,className:"ga-off"}),a.jsx(Wn,{x:250,label:"ANOTHER MACHINE"}),a.jsx(ur,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]})]})}function wK(){return a.jsxs(Hn,{children:[a.jsx(Wn,{x:14,label:"THIS MACHINE"}),a.jsx(Ad,{x:28,y:60}),a.jsx(Uu,{x:28,y:92,name:"Ana's MacBook"}),a.jsx(Uu,{x:28,y:114,name:"Dorin's PC"}),a.jsx(Wn,{x:250,label:"ANOTHER MACHINE"}),a.jsx(Ad,{x:264,y:60}),a.jsx(Uu,{x:264,y:92,name:"Your MacBook"}),a.jsx(Uu,{x:264,y:114,name:"Dorin's PC"}),a.jsx("line",{x1:196,y1:100,x2:244,y2:100,className:"ga-arc"}),a.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping"}),a.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping ga-ping-2"}),a.jsx("circle",{cx:220,cy:100,r:3,className:"ga-accent"})]})}function vK(){return a.jsxs(Hn,{children:[a.jsx("rect",{x:90,y:18,width:260,height:164,rx:10,className:"ga-screen"}),a.jsx("text",{x:106,y:42,className:"ga-t ga-strong",children:"This deck on the network"}),a.jsx("line",{x1:90,y1:54,x2:350,y2:54,className:"ga-line"}),a.jsx("text",{x:106,y:76,className:"ga-cap",children:"SHARE THESE ACCOUNTS"}),a.jsx(DS,{x:106,y:88,on:!0}),a.jsx("text",{x:126,y:98,className:"ga-t ga-mono",children:"work@team.dev"}),a.jsx(DS,{x:106,y:112}),a.jsx("text",{x:126,y:122,className:"ga-s ga-mono",children:"personal@me.dev"}),a.jsx("text",{x:106,y:150,className:"ga-cap",children:"PAIRING"}),a.jsx("text",{x:106,y:168,className:"ga-s",children:"Say yes to every deck that asks"}),a.jsx(zI,{x:304,y:157,on:!0}),a.jsx(S0,{x:115,y:97})]})}function xK(){return a.jsxs(Hn,{children:[a.jsx(Wn,{x:14,label:"THIS MACHINE"}),a.jsx("g",{className:"ga-swap-out",children:a.jsx(ur,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"})}),a.jsx("g",{className:"ga-swap-in",children:a.jsx(ur,{x:28,y:64,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),a.jsx(Wn,{x:250,label:"ANOTHER MACHINE"}),a.jsx(ur,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),a.jsx("path",{d:"M246 96C234 56 206 56 194 96",className:"ga-arc"}),a.jsx("g",{className:"ga-travel",transform:"translate(220 66)",children:a.jsx(_0,{})})]})}const bK=[{art:a.jsx(yK,{}),line:"A login can expire on one machine while it still works on another."},{art:a.jsx(wK,{}),line:"Both decks are on. They find each other and ask to pair.",tip:"Not showing up? Add a deck, the link at the top, takes an address or invite."},{art:a.jsx(vK,{}),line:"Tick which logins this machine may hand out. Nothing is shared until you do."},{art:a.jsx(xK,{}),line:"An expired login is copied from a paired machine within a minute."}];function kK(){return a.jsxs("svg",{className:"guide-art",viewBox:"0 0 232 60","aria-hidden":!0,focusable:"false",children:[a.jsx("rect",{x:1,y:14,width:78,height:42,rx:7,className:"ga-screen"}),a.jsx("circle",{cx:13,cy:29,r:3,className:"ga-warn"}),a.jsx("rect",{x:21,y:27,width:46,height:4,rx:2,className:"ga-track"}),a.jsx("rect",{x:13,y:39,width:40,height:3,rx:1.5,className:"ga-track"}),a.jsx("rect",{x:153,y:14,width:78,height:42,rx:7,className:"ga-screen"}),a.jsx("circle",{cx:165,cy:29,r:3,className:"ga-ok"}),a.jsx("rect",{x:173,y:27,width:46,height:4,rx:2,className:"ga-track"}),a.jsx("rect",{x:165,y:39,width:40,height:3,rx:1.5,className:"ga-accent"}),a.jsx("path",{d:"M150 36C138 6 94 6 82 36",className:"ga-arc"}),a.jsx("g",{transform:"translate(116 13)",children:a.jsx(_0,{})})]})}const NK={panel:"Nothing here is stuck: whoever pastes an invite is the one dialling out. Ask them for one and paste it behind Add a deck, the link 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."},jK=1600;function WI({reach:e,where:t}){const[n,r]=y.useState(!1),s=y.useRef(!0);y.useEffect(()=>()=>{s.current=!1},[]);const o=(e==null?void 0:e.steps)??[],l=y.useCallback(async()=>{await eo(o.join(`
|
|
91
|
-
`))&&s.current&&(r(!0),window.setTimeout(()=>{s.current&&r(!1)},jK))},[o]);if(!(e!=null&&e.blocked))return null;const c=e.shell==="sh";return a.jsxs("div",{className:"ap-lan-reach",children:[a.jsx("p",{className:"lan-warn",children:e.text}),a.jsx("p",{className:"lan-note",children:NK[t]}),o.length>0&&a.jsxs("details",{className:"ap-lan-reach-fix",children:[a.jsx("summary",{children:"or let them find this deck on their own"}),a.jsxs("p",{className:"lan-note",children:[c?a.jsx(a.Fragment,{children:"Run this in a terminal on this machine, then restart the deck."}):a.jsxs(a.Fragment,{children:["Run this in PowerShell ",a.jsx("strong",{children:"as Administrator"}),", then restart the deck."]}),e.category==="Public"&&a.jsx(a.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&&a.jsxs(a.Fragment,{children:[" ",e.unsure]})]}),a.jsx("pre",{className:"ap-lan-cmd",children:a.jsx("code",{children:o.join(`
|
|
92
|
-
`)})}),a.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>void l(),title:c?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:n?"copied":"copy command"})]})]})}function SK(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 _K(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}async function Up(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const EK={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."},TK={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function qS(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||Tt(n,t)}function CK({status:e,manual:t,startWith:n,onClose:r,onChanged:s}){const o=y.useRef(null),l=y.useRef(null),c=y.useRef(null),d=y.useRef(null),h=e.pairingMode==="invite",f=ut(r,{focusRef:h?l:o}),p=gt(r),[g,v]=y.useState(""),[N,k]=y.useState(""),[x,j]=y.useState(null),[b,_]=y.useState(null),[E,R]=y.useState(null),[C,A]=y.useState(null),[U,L]=y.useState(()=>Date.now());y.useEffect(()=>{const Y=window.setInterval(()=>L(Date.now()),1e3);return()=>window.clearInterval(Y)},[]);const F=y.useRef(!0);y.useEffect(()=>()=>{F.current=!1},[]);const O=y.useRef(null),I=y.useRef(null),B=y.useCallback(Y=>lh(O.current)?(O.current=Y,R(Y),!0):!1,[]),M=y.useCallback(()=>{O.current=null,F.current&&R(null)},[]),$=Y=>{const Z=ia(E,Y);return{disabled:Z.disabled,"aria-busy":Z.busy}},P=Y=>(x==null?void 0:x.field)===Y?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},G=Y=>j(Z=>Z&&Z.field===Y?null:Z),K=y.useCallback(async()=>{if(h)return;const Y=SK(g);if(!Y){j({text:AK(g),field:"addr"});return}const Z=`${Y.addr}:${Y.port}`,ee=e.peers.find(ne=>ne.addr===Y.addr&&ne.port===Y.port&&ne.paired);if(ee){j({text:`Already paired with ${ee.name} at that address.`,field:"addr"});return}if(t.includes(Z)){j({text:"This deck already calls that address.",field:"addr"});return}if(B("add"))try{const ne=await Up("/api/prefs",{lan:{manual:[...t,Z]}});if(!F.current)return;ne!=null&&ne.ok?(j(null),v(""),s(),r()):j({text:Tt("add that address",ne),field:"addr"})}catch{F.current&&j({text:Tt("add that address",null),field:"addr"})}finally{M()}},[g,h,t,e.peers,s,r,B,M]),q=y.useCallback(async Y=>{if(!B(`invite:${Y}`))return;const Z=Y==="make"?"make an invite":"cancel that invite";try{const ee=await Up("/api/lan/invite",{action:Y});if(!F.current)return;ee!=null&&ee.ok?(I.current=Y,j(null),_(null),s()):j({text:qS(TK,ee,Z)})}catch{F.current&&j({text:Tt(Z,null)})}finally{M()}},[s,B,M]),H=y.useCallback(async()=>{const Y=N.trim();if(!(!Y||!B("join"))){A(null);try{const Z=await Up("/api/lan/invite",{action:"join",token:Y});if(!F.current)return;Z!=null&&Z.ok?(k(""),j(null),s(),r()):(Z==null?void 0:Z.reason)==="unreachable"&&Array.isArray(Z.tried)&&Z.tried.length?(A(Z.tried),j(null)):(A(null),j({text:qS(EK,Z,"use that invite"),field:"join"}))}catch{F.current&&j({text:Tt("use that invite",null),field:"join"})}finally{M()}}},[N,s,r,B,M]),D=y.useCallback(async(Y,Z)=>{try{await navigator.clipboard.writeText(Y),_(Z),window.setTimeout(()=>{F.current&&_(ee=>ee===Z?null:ee)},1600)}catch{j({text:"Could not copy it — select the text and copy it by hand."})}},[]),W=e.invite&&e.invite.expiresAt>U?e.invite:null,J=y.useRef(!1);y.useEffect(()=>{n!=="invite"||J.current||W||(J.current=!0,q("make"))},[n,W,q]);const V=y.useRef(!1);y.useEffect(()=>{var Y;n!=="invite"||V.current||!W||(V.current=!0,(Y=c.current)==null||Y.focus())},[n,W]),y.useEffect(()=>{var Z,ee;const Y=I.current;!Y||Y==="make"!=!!W||(I.current=null,Tn(((Z=document.activeElement)==null?void 0:Z.tagName)??null)&&((ee=(Y==="make"?c:d).current)==null||ee.focus()))},[W]);const X=e.port!=null?(e.addrs??[]).map(Y=>`${Y}:${e.port}`):[];return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...p,role:"presentation",children:a.jsxs("div",{ref:f,className:"modal lan-add",onClick:Y=>Y.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-add-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"lan-add-title",className:"modal-tool-name",children:"Add a deck"})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{className:"glyph-btn",onClick:r,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[x&&a.jsxs("div",{className:"ap-failure",role:"alert",children:[a.jsx("span",{id:"lan-add-failure",className:"ap-failure-text",children:x.text}),a.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>j(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),a.jsx(WI,{reach:e.reach,where:"dialog"}),h&&a.jsx("div",{className:"modal-section",children:a.jsx("p",{className:"lan-note",children:"Adding by address is off while this deck pairs only by invite."})}),!h&&a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",children:"By address"}),a.jsxs("div",{className:"ap-lan-row",children:[a.jsx("input",{ref:o,className:"ap-manage-input ap-lan-input","aria-label":"Another deck's address",value:g,placeholder:"192.168.1.5:54340",spellCheck:!1,...P("addr"),onChange:Y=>{v(Y.target.value),G("addr")},onKeyDown:Y=>{Y.key==="Enter"&&K()}}),g.trim()!==""&&a.jsx("button",{type:"button",className:"ap-manage-btn",...$("add"),onClick:()=>void K(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),a.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&X.length>0&&a.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",X.map((Y,Z)=>a.jsxs("span",{children:[Z>0&&" or ",a.jsx("code",{className:"ap-lan-code",children:Y})]},Y)),a.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...$("copy:mine"),onClick:()=>void D(X.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:b==="mine"?"copied":"copy"})]})]}),a.jsxs("div",{className:"modal-section",children:[a.jsxs("h3",{className:"lan-h",children:["With an invite",!W&&a.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",ref:d,...$("invite:make"),onClick:()=>void q("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:E==="invite:make"?"making…":"make one to send"})]}),a.jsxs("div",{className:"ap-lan-row",children:[a.jsx("input",{ref:l,className:"ap-manage-input ap-lan-input","aria-label":"An invite you were sent",value:N,placeholder:"paste one you were sent",spellCheck:!1,...P("join"),onChange:Y=>{k(Y.target.value),A(null),G("join")},onKeyDown:Y=>{Y.key==="Enter"&&H()}}),N.trim()!==""&&a.jsx("button",{type:"button",className:"ap-manage-btn",...$("join"),onClick:()=>void H(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:E==="join"?"joining…":"join"})]}),a.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),C&&a.jsxs("div",{className:"ap-lan-tried",children:[a.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(Y=>a.jsxs("span",{className:"ap-lan-tried-row",children:[a.jsx("code",{className:"ap-lan-code",children:Y.addr}),a.jsx("span",{className:"ap-lan-bad",children:Y.why})]},Y.addr))]}),W&&a.jsxs("div",{className:"ap-lan-invite",children:[a.jsxs("div",{className:"ap-lan-invite-head",children:[a.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),a.jsxs("span",{className:"ap-lan-invite-left",id:"lan-invite-left",children:[_K(W.expiresAt,U)," left"]})]}),a.jsx("code",{className:"ap-lan-token",children:W.token}),a.jsxs("div",{className:"ap-lan-acts",children:[a.jsx("button",{type:"button",className:"ap-manage-btn",ref:c,...$("copy:invite"),"aria-label":b==="invite"?"Invite copied":"Copy invite","aria-describedby":"lan-invite-left",onClick:()=>void D(W.token,"invite"),title:"Copy it, and send it however you already talk to them",children:b==="invite"?"copied":"copy"}),a.jsx("button",{type:"button",className:"ap-manage-btn",...$("invite:withdraw"),onClick:()=>void q("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),a.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function AK(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}".`}function RK({asks:e,pressProps:t,answer:n}){return a.jsx("div",{className:"ap-lan-asks",role:"alert",children:e.map(r=>a.jsxs("div",{className:"ap-lan-ask",children:[a.jsxs("span",{className:"ap-lan-ask-what",children:[a.jsx("strong",{className:"ap-lan-peer-name",children:r.name})," at ",a.jsx("code",{className:"ap-lan-code",children:r.addr})," wants to pair"]}),a.jsxs("span",{className:"ap-lan-ask-fp",id:`lan-ask-fp-${r.fp}`,children:["fingerprint ",a.jsx("code",{className:"ap-lan-code",children:r.fp})]}),a.jsxs("span",{className:"ap-lan-ask-acts",children:[a.jsx("button",{type:"button",className:"ap-manage-btn",...t(`accept:${r.fp}`),"aria-label":`Accept ${r.name}`,"aria-describedby":`lan-ask-fp-${r.fp}`,onClick:()=>void n("accept",r.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${r.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),a.jsx("button",{type:"button",className:"ap-manage-btn",...t(`dismiss:${r.fp}`),"aria-label":`Decline ${r.name}`,"aria-describedby":`lan-ask-fp-${r.fp}`,onClick:()=>void n("dismiss",r.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},r.fp))})}function MK({rows:e,pairingMode:t,armed:n,pressProps:r,answer:s,dropAddress:o,onUnpair:l,onOpenPeer:c,onInvite:d}){return a.jsx("ul",{className:"ap-lan-here",children:e.map((h,f)=>a.jsxs("li",{className:"ap-lan-who","data-tone":h.tone,children:[a.jsx("i",{className:h.here?"ap-pulse":"ap-dot","aria-hidden":!0}),a.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[h.name,h.via==="tailscale"&&a.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]}),a.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${f}`,onClick:()=>c(h.fp),children:a.jsxs("span",{className:"vis-hidden",children:[h.name,h.via==="tailscale"?", over Tailscale":"",", details"]})}),a.jsx("span",{id:`lan-who-state-${f}`,className:h.quiet?"vis-hidden":"ap-lan-who-when",children:h.state}),h.kind==="nearby"&&t!=="invite"&&a.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...r(`accept:${h.fp}`),onClick:()=>void s("accept",h.fp,"reach that deck"),"aria-label":`Ask ${h.name} to pair`,title:`Send ${h.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${h.fp}.`,children:"ask"}),(h.kind==="nearby"||h.kind==="declined")&&t==="invite"&&a.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do","aria-haspopup":"dialog",onClick:d,"aria-label":`Invite ${h.name} to pair`,title:`This deck pairs only by invite. Make one and send it to whoever is at ${h.name}.`,children:"invite"}),h.kind==="paired"&&a.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${n===h.fp?" armed":""}`,...r(`unpair:${h.fp}`),onClick:()=>l(h),"aria-label":n===h.fp?`Confirm unpairing ${h.name}`:`Unpair ${h.name}`,title:n===h.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:n===h.fp?"confirm":"unpair"}),h.kind==="dialling"&&a.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...r(`drop:${h.fp}`),onClick:()=>void o(h.fp),"aria-label":`Stop dialling ${h.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),h.kind==="declined"&&t!=="invite"&&a.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...r(`allow:${h.fp}`),onClick:()=>void s("allow",h.fp,"let that deck ask again"),"aria-label":`Let ${h.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${h.kind}:${h.fp}`))})}function $K(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 IK({on:e,status:t}){return a.jsxs(a.Fragment,{children:[e&&a.jsx(WI,{reach:t==null?void 0:t.reach,where:"panel"}),e&&(t==null?void 0:t.deaf)&&a.jsx("p",{className:"ap-lan-fine",children:t.deaf}),e&&(t==null?void 0:t.lanTunneled)&&a.jsx("p",{className:"ap-lan-fine",children:$K(t)})]})}const US=["online","offline","loose"],OK={online:0,offline:1,loose:2};function LK(e){return e.kind==="declined"?null:e.kind==="paired"?e.here?"online":"offline":"loose"}const PK=76,DK=62,Rd=96,FK={1:[.62],2:[.58,1],3:[.42,.72,1]},BK=.2,qK=.16,UK=.05,zK=20,WK=17,zu=7,HK=30,VK=116,GK=6.6,KK=6,YK=e=>E0(e,null),XK=1.5,ZK=80,JK=.45,zS=40,QK=64,eY=150,WS=.3,HS=84,VS=8,tY=1.3,Md=6,nY=5.94,GS=7,KS=16,xl=4,YS=.16;function ab(e,t){return Math.PI*(3*(e+t)-Math.sqrt((3*e+t)*(e+3*t)))}function HI(e,t){return t<-Math.abs(e)*.6?"top":"bottom"}function rY(e,t){if(e<=2)return t%2===0?0:90;const n=360/e;return-90+(t%2===0?0:n/2)}function sY(e){return e.map((t,n)=>({...t,i:n})).sort((t,n)=>US.indexOf(t.tier)-US.indexOf(n.tier)||+(t.row.via==="tailscale")-+(n.row.via==="tailscale")||t.i-n.i).map(({row:t,tier:n})=>({row:t,tier:n}))}function XS(e,t){let n=2166136261^t;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return(n>>>0)%2e4/1e4-1}function aY(e,t,n){const r=[...FK[e.length]??[]];for(let s=0;s<r.length;s++){const o=e[s];if(o<2)continue;const l=ab(t*r[s],n*r[s])/o;if(!(l>0)||l>=Rd)continue;const c=s+1<r.length?r[s+1]-BK:1;r[s]=Math.max(r[s],Math.min(c,r[s]*(Rd/l)*1.02))}return r}const Pa=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1,zp={h:16,ch:6.1,maxW:100};function oY(e){const t=e?Math.max(80,e.length*7.2+16):128;return{x0:-t/2,y0:32,x1:t/2,y1:66}}function VI(e,t,n,r,s,o){const l=t==="loose"?WK:zK,c=!s||e.kind==="asks",d=c?HK:zp.h,h=s?zp.ch:GK,f=c?o.length:0,p=Math.min(s?zp.maxW:VK,Math.max(2*l,KI(e).length*h,f*KK)),g={x0:n-l,y0:r-l,x1:n+l,y1:r+l},v=HI(n,r)==="top"?{x0:n-p/2,y0:r-l-zu-d,x1:n+p/2,y1:r-l-zu}:{x0:n-p/2,y0:r+l+zu,x1:n+p/2,y1:r+l+zu+d};return[g,v]}const ob=e=>{const t=e.theta*Math.PI/180;return[Math.cos(t)*e.ring.rx*e.reach,Math.sin(t)*e.ring.ry*e.reach]},Wu=(e,t)=>((e-t)%360+540)%360-180;function ZS(e,t,n){const r=new Map;for(const f of e)r.has(f.ring)||r.set(f.ring,[]),r.get(f.ring).push(f);const s=()=>e.map(f=>{const[p,g]=ob(f);return VI(f.row,f.tier,p,g,t,f.caption)}),o=(f,p,g=!1)=>{if(f.count<=2&&!g)return!1;const v=f.theta+p*XK,N=r.get(f.ring),k=(f.count>2?360/f.count:f.turn)*JK,x=N[(f.index+1)%f.count],j=N[(f.index-1+f.count)%f.count];return!(x===f||(p>0?Wu(x.theta,v)>=k:Wu(v,j.theta)>=k))||v<f.lo||v>f.hi?!1:(f.theta=v,!0)},l=([f,p],[g,v])=>Pa(p,g)||Pa(v,f)||Pa(p,v)||Pa(f,g),c=([f,p])=>Pa(f,n)||Pa(p,n);for(let f=0;f<ZK;f++){const p=s();let g=!1;for(let v=0;v<e.length;v++){c(p[v])&&(g=o(e[v],Wu(e[v].theta,90)>=0?1:-1,!0)||g);for(let N=v+1;N<e.length;N++){if(!l(p[v],p[N]))continue;const k=e[v],x=e[N],j=x.ring.ring>k.ring.ring||x.ring===k.ring&&N>v?x:k,b=j===x?k:x,_=Wu(j.theta,b.theta)>=0?1:-1;g=o(j,_)||o(b,-_)||g}}if(!g)break}const d=s();let h=0;for(let f=0;f<d.length;f++){c(d[f])&&h++;for(let p=f+1;p<d.length;p++)l(d[f],d[p])&&h++}return h}const iY={online:0,offline:1,loose:1};function lY(e,t,n,r="",s=YK){const o=[];for(const l of[!0,!1]){const c=JS(e,t,n,r,OK,s,l);if(c.clashes===0)return c.named();if(o.push(c),c.layout.rings.length===3){const d=JS(e,t,n,r,iY,s,l),h={clashes:d.clashes,named:()=>({...d.named(),folded:!0})};if(h.clashes===0)return h.named();o.push(h)}if(!c.layout.zone)break}return o.reduce((l,c)=>c.clashes<l.clashes?c:l).named()}function JS(e,t,n,r,s,o,l=!0){const c=new Map;for(const B of e){const M=LK(B);if(!M)continue;const $=s[M];c.has($)||c.set($,[]),c.get($).push({row:B,tier:M})}const d=[...c.keys()].sort((B,M)=>B-M),h=Math.max(0,t/2-PK),f=Math.max(0,n/2-DK),p=aY(d.map(B=>c.get(B).length),h,f),g=d.map((B,M)=>({ring:B,rx:h*p[M],ry:f*p[M],count:c.get(B).length})),v=g.reduce((B,M)=>B+M.count,0),N=B=>B.row.via==="tailscale",k=[...c.values()].flat().filter(N).length,x=Math.max(0,...g.map(B=>{const M=c.get(B.ring).filter(N).length,$=ab(B.rx,B.ry);return M>0&&$>0?M*Rd*tY/$*360:0})),j=l&&k>0&&k<v?Math.min(eY,Math.max(QK,k/v*360,x)):0,b=zS-j/2,_=zS+j/2,E=[];let R=!1;g.forEach((B,M)=>{const $=sY(c.get(B.ring)),P=$.length,G=P>1&&ab(B.rx,B.ry)/P<Rd;G&&(R=!0);const K=M===g.length-1,q=K?-YS*(p[M]-(p[M-1]??0)):YS*(p[M+1]-p[M]),H=j>0?[{members:$.filter(W=>W.row.via!=="tailscale"),from:_,width:360-j},{members:$.filter(W=>W.row.via==="tailscale"),from:b+360,width:j}]:[{members:$,from:null,width:360}];let D=0;for(const W of H){const J=W.members.length;if(J===0)continue;const V=W.width/J,X=J>2;W.members.forEach(({row:Y,tier:Z},ee)=>{const ne=rr(Y),se=W.from==null?rY(J,M)+V*ee:W.from+V*(ee+.5),pe=X?XS(ne,1)*qK*V:0,ke=G&&D%2===1?1+q/p[M]:1,ae=X?XS(ne,2)*UK:0,fe=V*.3;E.push({row:Y,tier:Z,ring:B,index:D,count:P,theta:se+pe,reach:ke*(1+(K?-Math.abs(ae):ae)),lo:W.from==null?-1/0:W.from+fe,hi:W.from==null?1/0:W.from+W.width-fe,turn:V,caption:o(Y)}),D++})}});const C=oY(r);let A=ZS(E,R,C);A>0&&!R&&(R=!0,A=ZS(E,!0,C));const U=E.map((B,M)=>{const[$,P]=ob(B);return{row:B.row,tier:B.tier,ring:B.ring.ring,x:$,y:P,angle:cY(Math.atan2(P,$)*180/Math.PI),dist:Math.hypot($,P),side:HI($,P),order:M}}),L=g.reduce((B,M,$)=>c.get(M.ring).some(N)?Math.max(B,p[$]):B,0),F=B=>({from:b,to:_,inner:{rx:h*WS,ry:f*WS},outer:{rx:Math.min(t/2-8,h*L+B),ry:Math.min(n/2-8,f*L+B)},count:k}),O={nodes:U,rings:g,dense:R,zone:j>0?{...F(HS),labelAt:null}:null};return{layout:O,clashes:A,named:()=>{if(!O.zone)return O;const B=E.flatMap(P=>{const[G,K]=ob(P);return VI(P.row,P.tier,G,K,R,P.caption)});let M={...O.zone,labelAt:QS(O.zone,B)},$=M.outer;for(let P=HS+VS;M.labelAt==null;P+=VS){const G=F(P);if(G.outer.rx===$.rx&&G.outer.ry===$.ry)break;$=G.outer;const K=QS(G,B);K!=null&&(M={...G,labelAt:K})}return{...O,zone:M}}}}function GI(e){return`Tailscale · ${e} deck${e===1?"":"s"}`}function QS(e,t){const n={rx:e.outer.rx-Md,ry:e.outer.ry-Md};if(!(n.rx>0&&n.ry>0))return null;const r=Math.min(.5,2/Math.max(n.rx,n.ry)*(180/Math.PI)),s=[];for(let b=e.to;b>=e.from;b-=r){const _=b*Math.PI/180;s.push([Math.cos(_)*n.rx,Math.sin(_)*n.ry])}const o=GS+xl,l={x0:Math.min(...s.map(b=>b[0]))-o,x1:Math.max(...s.map(b=>b[0]))+o,y0:Math.min(...s.map(b=>b[1]))-o,y1:Math.max(...s.map(b=>b[1]))+o},c=t.map(b=>({x0:b.x0-xl,y0:b.y0-xl,x1:b.x1+xl,y1:b.y1+xl})).filter(b=>Pa(b,l)),d=(b,_)=>c.some(E=>b>E.x0&&b<E.x1&&_>E.y0&&_<E.y1),h=[],f=[];let p=0;s.forEach(([b,_],E)=>{E>0&&(p+=Math.hypot(b-s[E-1][0],_-s[E-1][1]));const R=Math.hypot(b,_)||1;let C=!1;for(let A=0;A<=GS&&!C;A+=1.75)C=d(b-b/R*A,_-_/R*A);h.push(p),f.push((f.at(-1)??0)+(C?1:0))});const g=GI(e.count).length*nY/2,v=g+KS,N=p-g-KS;if(!(p>0)||N<v)return null;const k=b=>{let _=0,E=h.length;for(;_<E;){const R=_+E>>1;h[R]<b?_=R+1:E=R}return _},x=b=>{const _=k(b-g),E=k(b+g+1e-9)-1;return E<_||f[E]-(_>0?f[_-1]:0)===0},j=p/2;for(let b=0;j-b>=v;b+=2)for(const _ of b===0?[j]:[j-b,j+b])if(x(_))return _/p;return null}function cY(e){return(e%360+360)%360}function uY(e){const t=n=>e.filter(n).length;return{paired:t(n=>n.kind==="paired"),online:t(n=>n.kind==="paired"&&n.here),offline:t(n=>n.kind==="paired"&&!n.here),nearby:t(n=>n.kind==="nearby"),asks:t(n=>n.kind==="asks"),dialling:t(n=>n.kind==="dialling"),declined:t(n=>n.kind==="declined"),tailnet:t(n=>n.kind!=="declined"&&n.via==="tailscale"),oneWay:t(n=>n.kind==="paired"&&!n.here&&n.state.startsWith("one-way"))}}function dY(e){const t=[];return e.asks&&t.push(e.asks===1?"1 deck wants to pair":`${e.asks} decks want to pair`),e.paired===0?t.push("no paired decks yet"):e.paired===1?t.push(e.online?"1 paired deck, online":"1 paired deck, away"):e.online===e.paired?t.push(`${e.paired} paired decks, all online`):t.push(`${e.online} of ${e.paired} paired decks online`),e.nearby&&t.push(`${e.nearby} nearby, not paired`),e.dialling&&t.push(`${e.dialling} still dialling`),t.join(" · ")}function E0(e,t){switch(e.kind){case"asks":return"wants to pair";case"nearby":return e.state;case"dialling":return YI(e)?`${e.name.slice(e.addr.length)} · dialling`:"dialling";case"declined":return"declined";case"paired":{if(e.here)return t?hY(t):"online";const n=ZI(e);return n?n==="now"?"away · just now":`away · ${n}`:e.state.startsWith("one-way")?"has not called yet":"away"}}}function KI(e){return YI(e)?e.addr:e.name}function YI(e){return e.kind==="dialling"&&!!e.addr&&e.name.startsWith(`${e.addr}:`)}function XI(e){if(e.kind!=="paired")return e.via==="tailscale"?`${e.state}, over Tailscale`:e.state;if(e.here)return e.via==="tailscale"?"online, over Tailscale":"online";const t=ZI(e),n=t?t==="now"?"away · last online just now":`away · last online ${t}`:e.state.startsWith("one-way")?e.state:"away";return e.via==="tailscale"?`${n}, over Tailscale`:n}function ZI(e){var t;return((t=/last online (.+)$/.exec(e.state))==null?void 0:t[1])??null}function hY(e){return e.trim().split(/\s+/).slice(0,2).join(" ")}function fY(e){var r;if(!e)return[];const t=(e.addrs??[]).map(s=>`${s}:${e.port}`),n=(r=e.tailscale)==null?void 0:r.addr;return n&&!(e.addrs??[]).includes(n)&&t.push(`${n}:${e.port}`),t}function rr(e){let t=e.fp;for(const n of e.twins??[])n.fp<t&&(t=n.fp);return t}function pY(e,t){if(e==null)return t;const n=((t-e)%360+540)%360-180;return e+n}function mY(e,t){if(e.asks)return e.asks===1?"1 deck wants to pair. Answer it in the Local network list, behind this map.":`${e.asks} decks want to pair. Answer them in the Local network list, behind this map.`;if(e.oneWay)return`${e.oneWay} away deck${e.oneWay===1?" only calls":"s only call"} in, and this deck has no address to call ${e.oneWay===1?"it":"them"} on. Add ${e.oneWay===1?"its address":"their addresses"} through Add a deck to reach ${e.oneWay===1?"it":"them"} both ways.`;if(e.dialling)return e.dialling===1?"1 address has never answered. Open it to stop dialling it.":`${e.dialling} addresses have never answered. Open one to stop dialling it.`;if(e.nearby){const n=e.nearby===1?"1 deck nearby is not paired.":`${e.nearby} decks nearby are not paired.`;return t==="invite"?`${n} ${JI}`:e.nearby===1?`${n} Open it to ask to pair.`:`${n} Open one to ask to pair.`}return null}const JI="This deck pairs by invite only. Send one from Add a deck.";function gY(e,t){switch(e.kind){case"asks":return"Waiting for your answer, in the Local network list behind this map.";case"dialling":return"Nothing has answered here yet. Its dialog can stop dialling it.";case"nearby":return t==="invite"?JI:"Not paired yet. Its dialog can ask to pair.";case"paired":return!e.here&&e.state.startsWith("one-way")?"It can reach this deck, not the other way. Add its address through Add a deck.":null;default:return null}}function yY(e){const t={bad:0,wait:1,idle:2,ok:3};return e.map((n,r)=>({l:n,i:r})).sort((n,r)=>t[n.l.tone]-t[r.l.tone]||n.i-r.i).map(({l:n})=>n)}function wY(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 o=Number(n[s])-Number(r[s]);if(o)return Math.sign(o)}return 0}function vY(e,t,n,r=!0){const s=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:s,note:null,tone:"idle"};if(!e.alive){const o=t&&!t.alive?"neither copy works — sign in again here":null;return{there:"broken there",here:s,note:o,tone:o?"bad":"idle"}}return t?t.alive?{there:"works there",here:s,note:null,tone:t.shareable===!1?"idle":"ok"}:r||n?{there:"works there",here:s,note:"repairs next round",tone:"wait"}:{there:"works there",here:s,note:"paired automatically — share it to repair",tone:"bad"}:r||n?{there:"works there",here:s,note:"arrives next round",tone:"wait"}:{there:"works there",here:s,note:"paired automatically — pair by invite to take it",tone:"bad"}}function xY(e,t,n,r=null,s=!0){var h;const o=new Map;for(const f of t)(h=o.get(f.key))!=null&&h.alive||o.set(f.key,f);const l=new Set(n),c=[],d=new Set;for(const f of e??[]){if(d.has(f.key))continue;d.add(f.key);const p=o.get(f.key)??null,g=l.has(f.key),v=vY(f,p,g,s),N=p?p.alive?p.shareable===!1?"unavailable":"works":"expired":"missing",k=!f.alive&&p&&!p.alive?v.note:[N==="works"?null:v.here,f.alive&&f.shareable!==!1?null:v.there,v.note].filter(Boolean).join(" · ")||null;c.push({key:f.key,email:f.email,here:N,there:f.alive?f.shareable===!1?"unavailable":"works":"broken",in:!f.alive||f.shareable===!1?"cut":v.tone==="wait"?"wait":v.tone==="bad"?"blocked":"live",out:g&&p?p.alive&&p.shareable!==!1?"live":"cut":null,caption:k,tone:v.tone,usedThere:r===f.key})}for(const f of n){const p=o.get(f);!p||d.has(f)||(d.add(f),c.push({key:f,email:p.email,here:p.alive?p.shareable===!1?"unavailable":"works":"expired",there:"unknown",in:null,out:p.alive&&p.shareable!==!1?"live":"cut",caption:p.alive?p.shareable===!1?"cannot share here":null:"expired here",tone:p.alive?p.shareable===!1?"idle":"ok":"bad",usedThere:!1}))}return c}const bY=1e3;function kY(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),r=Fr(e,t);return`${n} · ${r==="now"?"just now":r}`}function ib(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}const QI={works:"works here",expired:"expired here",missing:"not on this deck",unavailable:"cannot share here"},eO={works:"works there",broken:"broken there",unavailable:"cannot share there",unknown:"not offered by that deck"};function tO(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${QI[e.here]}, ${eO[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function nO({row:e,source:t,status:n,accounts:r,now:s}){var V,X,Y,Z,ee;const{peer:o,stranger:l}=t,c=e.kind==="paired",d=e.self??e.name,h=e.kind!=="dialling",f=e.kind==="dialling"?null:e.fp,p=o?o.addr?`${o.addr}:${o.port}`:"":l?l.port?`${l.addr}:${l.port}`:l.addr:e.addr,g=(o==null?void 0:o.about)??null,v=((V=n.about)==null?void 0:V.version)??null,N=c?o!=null&&o.waiting?o.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":o!=null&&o.offers?"not said — it runs an older version":"not reached yet":"shown once paired",k=ib(n.about),x=ib(g),j=g!=null&&g.version&&v?wY(g.version,v):null,b=o?fh(o.last,s):null,_=o&&((X=o.last)!=null&&X.error)?OG({error:o.last.error,host:o.addr,port:o.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(ne=>!ne.manual&&ne.addr).map(ne=>({fp:ne.fp,name:ne.name,addr:ne.addr,port:ne.port,at:ne.lastSeen??0}))],s):null,E=(Y=o==null?void 0:o.last)!=null&&Y.error&&b&&b.text!==o.last.error?o.last.error:null,R=((Z=o==null?void 0:o.last)==null?void 0:Z.done)??[],C=!!b&&!!E&&!e.quiet&&e.state.startsWith(b.text),A=c||e.kind==="dialling",U=((o==null?void 0:o.via)??e.via)==="tailscale",L=o?o.waiting?null:o.manual?U?"added by its Tailscale address":"added by address":U?"over Tailscale":"on this network":e.kind==="nearby"?U?"heard over Tailscale":"heard on this network":U?"asked this deck to pair, over Tailscale":"asked this deck to pair",F=e.tone==="bad"?"bad":c?e.here?"up":"down":"loose",O=(o==null?void 0:o.offers)??null,I=F==="up"?(O==null?void 0:O.current)??null:null,B=I&&"key"in I?I.key:null,M=!!I&&"hidden"in I,$=!!I&&"other"in I,P=c?xY((O==null?void 0:O.accounts)??null,r,n.shared??[],B,(o==null?void 0:o.autoPaired)!==!0):[],G=P.filter(ne=>ne.in==null&&ne.out==="cut"),K=P.some(ne=>ne.in!=null),q=P.some(ne=>ne.out!=null),H=new Map(R.map(ne=>[ne.email,ne])),D=R.filter(ne=>!P.some(se=>se.email===ne.email)),W=c?O?O.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:o!=null&&o.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.":(ee=o==null?void 0:o.last)!=null&&ee.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,J=O&&(o!=null&&o.last)&&o.last.at-O.at>bY?Fr(O.at,s):null;return{peer:o,stranger:l,paired:c,own:d,canRename:h,fp:f,where:p,about:g,unsaid:N,hereRuns:k,thereRuns:x,order:j,line:b,silence:_,raw:E,echoed:C,showRound:A,how:L,link:F,hiddenThere:M,otherThere:$,lanes:P,spent:G,taking:K,giving:q,told:H,unplaced:D,unknown:W,stale:J}}function lb(){return a.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:[a.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),a.jsx("path",{d:"M1 13h14"})]})}function Hu({dir:e,gate:t=!1}){const n=t?12:8;return a.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:a.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"})})}function NY({view:e,row:t,status:n,asking:r,drawn:s,onSettings:o}){const{peer:l,paired:c,where:d,about:h,unsaid:f,hereRuns:p,thereRuns:g,order:v,line:N,silence:k,raw:x,echoed:j,showRound:b,how:_,link:E,hiddenThere:R,otherThere:C,lanes:A,spent:U,taking:L,giving:F,told:O,unplaced:I,unknown:B,stale:M}=e;return a.jsxs("div",{className:"lan-map","data-link":E,"data-asking":r||void 0,"data-bus":A.length>0||void 0,children:[a.jsxs("div",{className:"lan-ends",children:[a.jsxs("p",{className:"lan-end",children:[a.jsx("span",{className:"lan-end-name",children:"This deck"}),p&&a.jsx("span",{className:"lan-end-runs",children:p}),c&&n.shareActive===!1&&a.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),a.jsxs("p",{className:"lan-end","data-side":"there",children:[a.jsx("span",{className:"lan-end-name",children:t.name}),t.kind!=="dialling"&&a.jsxs("span",{className:"lan-end-runs",children:[g??(h?"not said":f),v?` · ${v<0?"older":"newer"}`:null]}),R&&a.jsx("span",{className:"lan-end-note",children:"current account hidden"}),C&&a.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),a.jsxs("div",{className:"lan-link",children:[a.jsx(lb,{}),a.jsxs("span",{className:"lan-span",children:[a.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[a.jsx("i",{className:"lan-glint","data-dir":"out"}),a.jsx("i",{className:"lan-glint","data-dir":"in"})]}),a.jsx("span",{className:"lan-link-label",children:d?a.jsx("code",{className:"ap-lan-code",children:d}):"none here — it calls this deck"})]}),a.jsx(lb,{}),(d&&_||b)&&a.jsxs("p",{className:"lan-link-sub",children:[d&&_,d&&_&&b&&" · ",b&&(N?j?a.jsx("code",{className:"ap-lan-code",children:x}):a.jsx("span",{className:"lan-round","data-tone":N.tone,children:N.text.replace(/ · now$/," · just now")}):"not asked yet"),b&&x&&!j&&a.jsx("code",{className:"lan-fact-raw",children:x})]}),I.length>0&&a.jsx("ul",{className:"lan-done",children:I.map($=>{const P=eb($);return a.jsxs("li",{"data-ok":$.ok&&!P,children:[$.email," ",a.jsxs("span",{className:"lan-done-what",children:[$.ok?"arrived":"did not arrive",P&&` — ${P.long}`]})]},`${$.email}:${$.action}`)})}),k&&a.jsx("p",{className:"lan-note lan-link-note",children:k}),(l==null?void 0:l.waiting)&&a.jsx("p",{className:"lan-note lan-link-note",children:t.hint}),(N==null?void 0:N.hint)&&a.jsx("p",{className:"lan-note lan-link-note",children:N.hint})]}),A.length>0&&a.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${t.name}`,children:A.map(($,P)=>{const G=O.get($.email),K=G?eb(G):null,q=$.out==="live"||$.in!=null&&$.in!=="cut";return a.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":$.tone,"data-draw":$.in&&$.out?"both":$.in?"in":"out","data-used-there":$.usedThere||void 0,style:{"--i":P},children:[a.jsx("i",{className:"lan-pip","data-end":"here","data-state":$.here,"aria-hidden":!0}),a.jsxs("span",{className:"lan-track",children:[a.jsxs("span",{className:"lan-wire","data-flow":q?"live":"cut","aria-hidden":!0,children:[($.in==="live"||$.in==="wait")&&a.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":$.in}),$.out==="live"&&a.jsx("i",{className:"lan-glint","data-dir":"out"})]}),$.in&&$.in!=="cut"&&a.jsx(Hu,{dir:"in",gate:$.in==="blocked"}),$.out==="live"&&a.jsx(Hu,{dir:"out"}),a.jsx("span",{className:"lan-lane-email",children:$.email})]}),a.jsx("i",{className:"lan-pip","data-end":"there","data-state":$.there,"aria-hidden":!0}),a.jsx("span",{className:"vis-hidden",children:tO($)}),($.caption||G)&&a.jsxs("span",{className:"lan-lane-note",children:[$.caption,$.caption&&G&&" · ",G&&a.jsxs("span",{className:"lan-lane-done","data-ok":G.ok&&!K,children:[G.ok?"arrived last round":"did not arrive last round",K&&` — ${K.long}`]})]})]},$.key)})},s),c&&a.jsxs(a.Fragment,{children:[U.length>0&&a.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",U.length===1?U[0].email:"the expired ones"," until you sign in again here."]}),B&&a.jsx("p",{className:"lan-empty",children:B}),M&&a.jsxs("p",{className:"lan-stale",children:["As of ",M==="now"?"just now":M,", when it last answered."]}),a.jsxs("div",{className:"lan-legend",children:[L&&a.jsxs("span",{className:"lan-key",children:[a.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:a.jsx(Hu,{dir:"in"})}),"from ",t.name]}),F?a.jsxs("span",{className:"lan-key",children:[a.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:a.jsx(Hu,{dir:"out"})}),"from this deck, to every paired deck"]}):a.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),a.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:o,"aria-label":"Change what this deck offers",children:"change"})]})]})]})}const jY=20,SY=17,e_=34,_Y=160,EY=80,TY=200,CY=8,AY=14,RY=10,MY=.61803398875;function $Y({status:e,rows:t,accounts:n,now:r,covered:s,onOpenDeck:o,onClose:l}){const c=y.useRef(null),d=ut(l,{focusRef:c}),h=gt(l),f=y.useRef(null),[p,g]=y.useState(null),[v,N]=y.useState(!1),k=y.useRef(null);y.useLayoutEffect(()=>{const ae=f.current;if(!ae)return;let fe=null;const me=()=>{const ge=Math.round(ae.clientWidth),ue=Math.round(ae.clientHeight);fe&&fe.w===ge&&fe.h===ue||(fe&&(N(!0),k.current!=null&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>N(!1),TY)),fe={w:ge,h:ue},g(fe))};if(me(),typeof ResizeObserver>"u")return;const he=new ResizeObserver(me);return he.observe(ae),()=>{he.disconnect(),k.current!=null&&window.clearTimeout(k.current)}},[]);const x=y.useMemo(()=>p?lY(t,p.w,p.h,(e==null?void 0:e.name)??"",ae=>{var fe,me;return E0(ae,(me=(fe=ec(e,ae).peer)==null?void 0:fe.about)==null?void 0:me.os)}):null,[t,p,e]),j=y.useMemo(()=>uY(t),[t]),b=(x==null?void 0:x.nodes)??[],_=y.useRef(new Map),E=y.useMemo(()=>{const ae=new Map;for(const fe of b){const me=rr(fe.row);ae.set(me,pY(_.current.get(me),fe.angle))}return _.current=ae,ae},[b]),[R,C]=y.useState(null),[A,U]=y.useState(null),[L,F]=y.useState("none"),O=y.useRef(null),I=y.useCallback((ae,fe)=>{O.current!==ae&&(O.current=ae,F(fe),U(ae))},[]),B=y.useRef(null),M=y.useRef(null),$=y.useCallback(()=>{M.current!=null&&window.clearTimeout(M.current),M.current=null},[]),P=y.useCallback((ae,fe)=>{if(B.current!=null&&window.clearTimeout(B.current),B.current=null,$(),C(ae),fe==="keyboard"){I(ae,"none");return}M.current=window.setTimeout(()=>I(ae,O.current?"swap":"full"),EY)},[I,$]),G=y.useCallback(()=>{B.current!=null&&window.clearTimeout(B.current),$(),B.current=window.setTimeout(()=>C(null),_Y)},[$]);y.useEffect(()=>()=>{B.current!=null&&window.clearTimeout(B.current),$()},[$]);const K=R&&b.some(ae=>rr(ae.row)===R)?R:null,q=A?t.find(ae=>rr(ae)===A)??null:null;y.useEffect(()=>{A&&!q&&I(null,"swap")},[A,q,I]);const[H,D]=y.useState(null),W=y.useRef(new Map),J=b.findIndex(ae=>rr(ae.row)===H),V=J<0?0:J,X=ae=>{var ge;if(b.length===0)return;const fe=ae.key==="ArrowRight"||ae.key==="ArrowDown"?1:ae.key==="ArrowLeft"||ae.key==="ArrowUp"?-1:0,me=ae.key==="Home"?0:ae.key==="End"?b.length-1:fe?(V+fe+b.length)%b.length:null;if(me==null)return;ae.preventDefault();const he=rr(b[me].row);D(he),(ge=W.current.get(he))==null||ge.focus()},[Y,Z]=y.useState(()=>typeof document<"u"&&document.hidden);y.useEffect(()=>{const ae=()=>Z(document.hidden);return document.addEventListener("visibilitychange",ae),()=>document.removeEventListener("visibilitychange",ae)},[]);const ee=(e==null?void 0:e.enabled)===!0,ne=e?ee?dY(j):"Local network is off":"checking…",se=()=>{$(),I(null,"swap"),C(null)},pe=K?b.find(ae=>rr(ae.row)===K)??null:null,ke=()=>{var ae;A&&((ae=W.current.get(A))==null||ae.focus()),se()};return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...h,role:"presentation",children:a.jsxs("div",{ref:d,className:"modal nm-modal",onClick:ae=>ae.stopPropagation(),"data-paused":s||Y||void 0,role:"dialog","aria-modal":"true","aria-labelledby":"nm-title","aria-describedby":"nm-sub",children:[a.jsxs("header",{className:"modal-head nm-head",children:[a.jsxs("div",{className:"nm-heading",children:[a.jsx("h2",{id:"nm-title",className:"modal-title nm-title",children:"Network map"}),a.jsx("p",{id:"nm-sub",className:"nm-sub",children:ne})]}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{ref:c,type:"button",className:"glyph-btn",onClick:l,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("div",{className:"nm-body",children:[a.jsxs("div",{className:"nm-view",children:[a.jsx("div",{ref:f,className:"nm-stage","data-focus":K?"":void 0,"data-focus-via":pe==null?void 0:pe.row.via,"data-dense":(x==null?void 0:x.dense)||void 0,"data-still":v||void 0,onClick:ae=>{ae.target===ae.currentTarget&&se()},children:p&&x&&a.jsxs(a.Fragment,{children:[a.jsx(IY,{layout:x,w:p.w,h:p.h}),b.map(ae=>{const fe=rr(ae.row);return a.jsx(PY,{node:ae,angle:E.get(fe)??ae.angle,lit:K===fe},fe)}),a.jsx(DY,{status:e}),a.jsx("span",{id:"nm-ring-hint",className:"vis-hidden",children:"Arrow keys move between decks. Enter opens the deck's own dialog."}),a.jsx("div",{className:"nm-ring",role:"group","aria-label":`Decks around this deck, ${b.length}`,"aria-describedby":"nm-ring-hint",onKeyDown:X,children:b.map((ae,fe)=>{var he,ge;const me=rr(ae.row);return a.jsx(FY,{node:ae,angle:E.get(me)??ae.angle,os:(ge=(he=ec(e,ae.row).peer)==null?void 0:he.about)==null?void 0:ge.os,lit:K===me,shown:A===me,tabbable:fe===V,register:ue=>{ue?W.current.set(me,ue):W.current.delete(me)},onHold:ue=>{D(me),P(me,ue)},onRelease:G,onOpen:()=>o(ae.row.fp)},me)})}),b.length===0&&a.jsx(BY,{status:e})]})}),a.jsx(qY,{slice:(x==null?void 0:x.zone)!=null})]}),a.jsx("aside",{className:"nm-side","aria-label":"Details",children:q&&e?a.jsx(zY,{row:q,status:e,accounts:n,now:r,entrance:L,onOpen:()=>o(q.fp),onBack:ke},rr(q)):a.jsx(UY,{status:e,summary:j,entrance:L,slice:(x==null?void 0:x.zone)!=null})})]})]})}),document.body)}function rO(){return a.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:[a.jsx("circle",{cx:"7",cy:"7.4",r:"1.8"}),a.jsx("circle",{cx:"2.4",cy:"2.9",r:"1.2"}),a.jsx("circle",{cx:"11.6",cy:"2.9",r:"1.2"}),a.jsx("circle",{cx:"7",cy:"12.4",r:"1.1"}),a.jsx("path",{d:"M5.7 6.1 3.3 3.8M8.3 6.1l2.4-2.3M7 9.2v2.1"})]})}function IY({layout:e,w:t,h:n}){const{zone:r}=e;return a.jsxs("svg",{className:"nm-orbits",width:t,height:n,viewBox:`0 0 ${t} ${n}`,"aria-hidden":!0,children:[r&&a.jsxs(a.Fragment,{children:[a.jsxs("defs",{children:[a.jsx("path",{id:"nm-zone-arc",d:LY(r,t/2,n/2)}),a.jsxs("radialGradient",{id:"nm-zone-fill",gradientUnits:"userSpaceOnUse",cx:t/2,cy:n/2,r:Math.max(r.outer.rx,r.outer.ry),children:[a.jsx("stop",{className:"nm-zone-stop",offset:"0.2","data-at":"in"}),a.jsx("stop",{className:"nm-zone-stop",offset:"0.5","data-at":"mid"}),a.jsx("stop",{className:"nm-zone-stop",offset:"1","data-at":"out"})]})]}),a.jsx("path",{className:"nm-zone",d:OY(r,t/2,n/2),fill:"url(#nm-zone-fill)"}),r.labelAt!=null&&a.jsx("text",{className:"nm-zone-label",children:a.jsx("textPath",{href:"#nm-zone-arc",startOffset:`${(r.labelAt*100).toFixed(2)}%`,textAnchor:"middle",children:GI(r.count)})})]}),e.rings.map((s,o)=>a.jsx("ellipse",{className:"nm-orbit","data-ring":s.ring,"data-folded":e.folded&&s.ring===1||void 0,cx:t/2,cy:n/2,rx:s.rx,ry:s.ry,style:{"--ring":o}},s.ring))]})}function t_(e,t,n,r){const s=r*Math.PI/180;return`${(t+Math.cos(s)*e.rx).toFixed(1)},${(n+Math.sin(s)*e.ry).toFixed(1)}`}function OY(e,t,n){const r=e.to-e.from>180?1:0,s=(j,b)=>{const _=b*Math.PI/180;return[t+Math.cos(_)*j.rx,n+Math.sin(_)*j.ry]},o=(j,b)=>b/((j.rx+j.ry)/2)*(180/Math.PI),l=(j,b,_)=>{const E=Math.hypot(b[0]-j[0],b[1]-j[1])||1,R=Math.min(.5,_/E);return[j[0]+(b[0]-j[0])*R,j[1]+(b[1]-j[1])*R]},c=([j,b])=>`${j.toFixed(1)},${b.toFixed(1)}`,d=RY,h=AY,f=o(e.inner,d),p=o(e.outer,h),g=s(e.inner,e.from),v=s(e.outer,e.from),N=s(e.outer,e.to),k=s(e.inner,e.to),x=j=>`${j.rx.toFixed(1)},${j.ry.toFixed(1)}`;return[`M${c(s(e.inner,e.from+f))}`,`Q${c(g)} ${c(l(g,v,d))}`,`L${c(l(v,g,h))}`,`Q${c(v)} ${c(s(e.outer,e.from+p))}`,`A${x(e.outer)} 0 ${r} 1 ${c(s(e.outer,e.to-p))}`,`Q${c(N)} ${c(l(N,k,h))}`,`L${c(l(k,N,d))}`,`Q${c(k)} ${c(s(e.inner,e.to-f))}`,`A${x(e.inner)} 0 ${r} 0 ${c(s(e.inner,e.from+f))}`,"Z"].join(" ")}function LY(e,t,n){const r={rx:e.outer.rx-Md,ry:e.outer.ry-Md},s=e.to-e.from>180?1:0;return`M${t_(r,t,n,e.to)} A${r.rx.toFixed(1)},${r.ry.toFixed(1)} 0 ${s} 0 ${t_(r,t,n,e.from)}`}function PY({node:e,angle:t,lit:n}){const r=e.row.kind==="paired"&&e.row.here,s=e.order*MY%1*CY;return a.jsx("span",{className:"nm-wire","aria-hidden":!0,"data-tier":e.tier,"data-via":e.row.via,"data-on":n||void 0,style:{"--nm-a":`${t.toFixed(2)}deg`,"--nm-d":`${e.dist.toFixed(1)}px`,"--from":`${e_}px`,"--gap":`${e_+(e.tier==="loose"?SY:jY)}px`,"--i":e.order,"--phase":`${s.toFixed(2)}s`},children:r&&a.jsx("i",{className:"nm-glint"})})}function DY({status:e}){const t=(e==null?void 0:e.enabled)===!0&&e.running;return a.jsxs("div",{className:"nm-core","data-listening":t||void 0,children:[a.jsx("span",{className:"nm-core-orb","aria-hidden":!0}),a.jsxs("span",{className:"nm-core-label",children:[a.jsx("span",{className:"nm-core-name",children:(e==null?void 0:e.name)??"…"}),a.jsx("span",{className:"nm-core-what",children:"this deck"})]})]})}function FY({node:e,angle:t,os:n,lit:r,shown:s,tabbable:o,register:l,onHold:c,onRelease:d,onOpen:h}){const{row:f}=e,p=`nm-d-${WY(rr(f))}`,g=e.angle*Math.PI/180,v=E0(f,n);return a.jsxs("button",{ref:l,type:"button",className:"nm-node",tabIndex:o?0:-1,"data-tier":e.tier,"data-kind":f.kind,"data-side":e.side,"data-via":f.via,"data-on":r||void 0,"data-shown":s||void 0,"aria-label":`${f.name}: ${XI(f)}`,"aria-describedby":e.tier==="online"?p:void 0,style:{"--nm-a":`${t.toFixed(2)}deg`,"--nm-d":`${e.dist.toFixed(1)}px`,"--i":e.order,"--in-x":`${(-Math.cos(g)*14).toFixed(1)}px`,"--in-y":`${(-Math.sin(g)*14).toFixed(1)}px`},onPointerEnter:N=>{N.pointerType==="mouse"&&c("pointer")},onPointerLeave:d,onFocus:N=>c(N.currentTarget.matches(":focus-visible")?"keyboard":"pointer"),onBlur:d,onClick:h,children:[a.jsx("i",{className:"nm-halo","data-tier":e.tier,"aria-hidden":!0}),f.kind==="dialling"?a.jsx("i",{className:"nm-addr-dot","aria-hidden":!0}):a.jsx(lb,{}),e.tier!=="online"&&a.jsx("i",{className:"nm-mark","data-tier":e.tier,"data-kind":f.kind,"aria-hidden":!0}),a.jsxs("span",{className:"nm-label","aria-hidden":!0,children:[a.jsx("span",{className:"nm-name",children:KI(f)}),a.jsx("span",{className:"nm-cap",children:v})]}),e.tier==="online"&&a.jsx("span",{id:p,className:"vis-hidden",children:v})]})}function BY({status:e}){const t=(e==null?void 0:e.enabled)===!0;return a.jsx("p",{className:"nm-empty",children:e?t?"No other deck yet. Decks on one network usually find each other within a minute; one on another network needs its address, through Add a deck in Local network.":"Local network is off, so this deck is not looking for any other.":"Asking this deck about the network…"})}function qY({slice:e}){return a.jsxs("ul",{className:"nm-legend",children:[a.jsxs("li",{children:[a.jsxs("span",{className:"nm-key","aria-hidden":!0,children:[a.jsx("i",{className:"nm-key-wire","data-tier":"online"}),a.jsx("i",{className:"nm-key-mark","data-tier":"online"})]}),"online"]}),a.jsxs("li",{children:[a.jsxs("span",{className:"nm-key","aria-hidden":!0,children:[a.jsx("i",{className:"nm-key-wire","data-tier":"offline"}),a.jsx("i",{className:"nm-key-mark","data-tier":"offline"})]}),"away"]}),a.jsxs("li",{children:[a.jsxs("span",{className:"nm-key","aria-hidden":!0,children:[a.jsx("i",{className:"nm-key-wire","data-tier":"loose"}),a.jsx("i",{className:"nm-key-mark","data-tier":"loose"})]}),"not paired"]}),e&&a.jsxs("li",{children:[a.jsx("i",{className:"nm-key-zone","aria-hidden":!0}),"over Tailscale"]})]})}function sO({facts:e}){return a.jsx("dl",{className:"lan-facts nm-facts",children:e.map(t=>a.jsxs("div",{className:"lan-fact","data-tone":t.quiet?"quiet":void 0,children:[a.jsx("dt",{children:t.label}),a.jsx("dd",{children:t.value})]},t.label))})}function UY({status:e,summary:t,entrance:n,slice:r}){const s=fY(e),o=ib(e==null?void 0:e.about),l=[];o&&l.push({label:"Runs",value:o}),l.push({label:s.length>1?"Addresses":"Address",value:s.length?a.jsx("span",{className:"nm-addrs",children:s.map(h=>a.jsx("code",{className:"ap-lan-code",children:h},h))}):"none yet",quiet:s.length===0}),e!=null&&e.pairingMode&&l.push({label:"Pairing",value:e.pairingMode==="invite"?"by invite only":"asks and answers"});const c=[{key:"online",n:t.online,words:"online",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"online","aria-hidden":!0})},{key:"away",n:t.offline,words:"away",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"offline","aria-hidden":!0})},{key:"asks",n:t.asks,words:"asking to pair",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"loose","data-kind":"asks","aria-hidden":!0})},{key:"nearby",n:t.nearby,words:"nearby, not paired",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"loose","aria-hidden":!0})},{key:"dialling",n:t.dialling,words:"still dialling",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"loose","aria-hidden":!0})},{key:"declined",n:t.declined,words:"declined, not drawn",mark:a.jsx("i",{"aria-hidden":!0})}],d=mY(t,e==null?void 0:e.pairingMode);return a.jsxs("div",{className:"nm-panel","data-view":"network","data-entrance":n,children:[a.jsx("h3",{className:"nm-panel-name",children:(e==null?void 0:e.name)??"…"}),a.jsx("p",{className:"nm-panel-self",children:"this deck, at the centre of the map"}),a.jsx("ul",{className:"nm-counts",children:c.filter(h=>h.n>0).map(h=>a.jsxs("li",{"data-count":h.key,children:[h.mark,a.jsx("span",{className:"nm-count-n",children:h.n}),a.jsx("span",{className:"nm-count-words",children:h.words})]},h.key))}),t.tailnet>0&&a.jsxs("p",{className:"nm-counts-note",children:[t.tailnet," reached over Tailscale",r?" — the shaded slice, lower right":""]}),d&&a.jsx("p",{className:"nm-next",children:d}),a.jsx(sO,{facts:l}),a.jsx("p",{className:"nm-panel-hint",children:"Point at a deck, or reach one with the arrow keys, to see it here. Press it to open its own dialog."})]})}function zY({row:e,status:t,accounts:n,now:r,entrance:s,onOpen:o,onBack:l}){var x;const c=nO({row:e,source:ec(t,e),status:t,accounts:n,now:r}),d=[];c.where&&d.push({label:"Address",value:a.jsx("code",{className:"ap-lan-code",children:c.where})}),c.thereRuns&&d.push({label:"Runs",value:`${c.thereRuns}${c.order?` · ${c.order<0?"older than this deck":"newer than this deck"}`:""}`}),c.hiddenThere&&d.push({label:"Signed in to",value:"not said — its owner hides it",quiet:!0}),c.otherThere&&d.push({label:"Signed in to",value:"an account it does not share",quiet:!0});const h=e.kind==="paired"&&e.here||e.kind==="asks",f=gY(e,t.pairingMode),p=yY(c.lanes),g=p.length,v=p.filter(j=>j.tone==="ok").length,N=g===0?"No shared logins":v===g?`${g} shared login${g===1?", fine":"s, all fine"}`:`${g} shared login${g===1?"":"s"} · ${v} fine`,k=c.unknown&&((x=c.peer)!=null&&x.waiting)&&!c.peer.offers?"Its side is not known until it next calls.":c.unknown;return a.jsxs("div",{className:"nm-panel","data-view":"deck","data-entrance":s,"data-tier":e.kind==="paired"?e.here?"online":"offline":"loose",children:[a.jsxs("button",{type:"button",className:"ap-lan-word nm-back",onClick:l,children:[a.jsx("span",{"aria-hidden":!0,children:"‹ "}),"the whole network"]}),a.jsxs("div",{className:"nm-panel-head",children:[a.jsxs("h3",{className:"nm-panel-name",children:[a.jsx("i",{className:h?"ap-pulse":"ap-dot","data-kind":e.kind,"aria-hidden":!0}),a.jsx("span",{className:"nm-panel-title",children:e.name})]}),a.jsx("button",{type:"button",className:"btn nm-open",onClick:o,"aria-label":`Open ${e.name}`,children:"Open"})]}),e.self&&a.jsxs("p",{className:"nm-panel-self",children:["calls itself ",e.self]}),a.jsx("p",{className:"nm-panel-state","data-kind":e.kind,children:XI(e)}),f&&a.jsx("p",{className:"nm-next",children:f}),d.length>0&&a.jsx(sO,{facts:d}),c.paired&&a.jsxs("section",{className:"nm-logins","aria-label":"Logins the two decks share",children:[a.jsx("p",{className:"nm-logins-title",children:N}),g>0&&a.jsx("ul",{className:"nm-lanes",children:p.map((j,b)=>a.jsxs("li",{className:"nm-lane","data-tone":j.tone,style:{"--k":b},children:[a.jsx("i",{className:"nm-lane-dot","aria-hidden":!0}),a.jsx("span",{className:"nm-lane-email","aria-hidden":!0,children:j.email}),n_(j)&&a.jsx("span",{className:"nm-lane-said","aria-hidden":!0,children:n_(j)}),j.usedThere&&a.jsx("span",{className:"nm-lane-used","aria-hidden":!0,children:"in use there"}),a.jsxs("span",{className:"vis-hidden",children:[j.email,": ",tO(j)]})]},j.key))}),k&&a.jsx("p",{className:"nm-panel-hint",children:k})]})]})}function n_(e){return e.caption?e.caption:e.tone==="ok"?null:`${QI[e.here]} · ${eO[e.there]}`}function WY(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}const HY=6;function VY({anchorId:e,id:t,rows:n,onHold:r,onLet:s}){const o=y.useRef(null),l=n.filter(g=>g.kind==="paired"),c=l.filter(g=>g.here),d=c.slice(0,HY),h=l.length-c.length,f=c.length>d.length?`and ${c.length-d.length} more`:h>0?`${h} not on right now`:null,p=y.useCallback(()=>{const g=o.current,v=document.getElementById(e);if(!g||!v)return;const N=m0(v.getBoundingClientRect(),{width:g.offsetWidth,height:g.offsetHeight},{width:window.innerWidth,height:window.innerHeight});g.style.top=`${N.top}px`,g.style.left=`${N.left}px`,g.style.maxHeight=N.maxHeight==null?"":`${N.maxHeight}px`,g.dataset.side=N.side},[e]);return y.useLayoutEffect(()=>{p()}),y.useEffect(()=>(window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}),[p]),Lt.createPortal(a.jsxs("div",{ref:o,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[a.jsx("p",{className:"ap-peek-title",children:c.length?"On the network now":"Nobody on the network"}),d.length>0&&a.jsx("div",{className:"ap-peek-list",children:d.map(g=>a.jsxs("span",{className:"ap-peek-who",children:[a.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),a.jsxs("span",{children:[g.name,g.via==="tailscale"&&a.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]})]},`${g.kind}:${g.fp}`))}),f&&a.jsx("p",{className:"ap-peek-rest",children:f})]}),document.body)}function GY({entry:e,rows:t,onOpen:n,onMap:r,peek:s,openPeek:o,shutPeek:l,holdPeek:c,dropPeek:d}){return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{d(),n()},"aria-describedby":s?"ap-lan-peek":void 0,onPointerEnter:h=>{h.pointerType==="mouse"&&o(FI)},onPointerLeave:l,onFocus:h=>{h.target.matches(":focus-visible")&&o(0)},onBlur:l,children:[a.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:[a.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),a.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),a.jsxs("span",{className:"ap-nav-text",children:[a.jsx("span",{className:"ap-nav-name",children:"Local network"}),a.jsxs("span",{className:"ap-nav-state","data-tone":e.tone,children:[e.live&&a.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),e.text]})]}),a.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:a.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),r&&a.jsx("button",{type:"button",className:"ap-lan-map",onClick:()=>{d(),r()},"aria-label":"Show the network map",title:"Network map — every deck this one knows, drawn around it",children:a.jsx(rO,{})}),s&&a.jsx(VY,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:t,onHold:c,onLet:l})]})}function KY({row:e,run:t,onVerb:n,onUnpair:r}){const[s,o]=y.useState(!1),l=y.useRef(0),[c,d]=y.useState(null);return y.useEffect(()=>{if(!s)return;const p=window.setTimeout(()=>o(!1),4e3);return()=>window.clearTimeout(p)},[s]),y.useEffect(()=>{if(!c)return;const p=window.setTimeout(()=>d(null),4e3);return()=>window.clearTimeout(p)},[c]),{armed:s,armedTwin:c,pressOwn:()=>{const p=Date.now(),g=Yl({armedFor:s?e.fp:null,target:e.fp,armedAt:l.current,now:p,gapMs:Kl});if(g==="arm"){o(!0),d(null),l.current=p;return}g!=="ignore"&&(o(!1),t(n))},pressTwin:p=>{if(!r)return;const g=Date.now(),v=Yl({armedFor:c,target:p,armedAt:l.current,now:g,gapMs:Kl});if(v==="arm"){d(p),o(!1),l.current=g;return}v!=="ignore"&&(d(null),t(()=>r(p)))}}}function YY({row:e,paired:t,peer:n,status:r,busy:s,press:o,checkNow:l,armed:c,pressOwn:d,run:h,onVerb:f,onInvite:p}){return a.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&a.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),t&&!(n!=null&&n.waiting)&&a.jsx("button",{type:"button",className:"btn",...o(`check:${e.fp}`),onClick:l,title:"Ask this deck now instead of waiting for the next round",children:s===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&a.jsx("button",{type:"button",className:`btn danger lan-peer-verb${c?" armed":""}`,...o(`unpair:${e.fp}`),onKeyDown:g=>{g.repeat&&g.preventDefault()},onClick:()=>d(),"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:s===`unpair:${e.fp}`?"Unpairing…":c?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&r.pairingMode!=="invite"&&a.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...o(`accept:${e.fp}`),onClick:()=>void h(f),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:s===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&a.jsx("button",{type:"button",className:"btn lan-peer-verb",...o(`drop:${e.fp}`),onClick:()=>void h(f),title:"Stop trying this address. Nothing was ever paired here.",children:s===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&r.pairingMode!=="invite"&&a.jsx("button",{type:"button",className:"btn lan-peer-verb",...o(`allow:${e.fp}`),onClick:()=>void h(f),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:s===`allow:${e.fp}`?"Allowing…":"Let it ask again"}),(e.kind==="nearby"||e.kind==="declined")&&r.pairingMode==="invite"&&p&&a.jsx("button",{type:"button",className:"btn primary lan-peer-verb",onClick:p,title:"This deck pairs only by invite. Make one and send it to whoever is at that machine.",children:"Invite to pair"})]})}function XY({instances:e,now:t,busy:n,press:r,armedTwin:s,pressTwin:o,onUnpair:l}){return a.jsxs("div",{className:"modal-section",children:[a.jsxs("h3",{className:"lan-h",children:[e.length," decks on this machine"]}),a.jsx("ul",{className:"lan-twins",role:"list",children:e.map((c,d)=>{var N,k,x,j;const h=(N=c.peer)!=null&&N.addr?`${c.peer.addr}:${c.peer.port}`:c.row.addr,f=h||c.row.fp,p=(k=c.peer)!=null&&k.pairedAt?Fr(c.peer.pairedAt,t):null,g=[(j=(x=c.peer)==null?void 0:x.about)!=null&&j.version?`runs ${c.peer.about.version}`:null,p?`paired ${p==="now"?"just now":p}`:null,c.row.state].filter(Boolean).join(" · "),v=c.row.fp;return a.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":c.row.tone,children:[a.jsx("i",{className:c.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),h?a.jsx("code",{className:"ap-lan-code lan-twin-at",children:h}):a.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),a.jsx("code",{className:"ap-lan-code lan-twin-fp",children:v}),d>0&&l&&a.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${s===v?" armed":""}`,...r(`unpair:${v}`),onKeyDown:b=>{b.repeat&&b.preventDefault()},onClick:()=>o(v),"aria-label":s===v?`Confirm unpairing ${f}`:`Unpair ${f}`,title:s===v?"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:n===`unpair:${v}`?"unpairing…":s===v?"confirm":"unpair"}),a.jsx("span",{className:"lan-twin-meta",children:d===0?`${g} · shown above`:g})]},v)})})]})}function ZY(){return a.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:[a.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),a.jsx("path",{d:"M8.4 3.6l2 2"})]})}function JY({row:e,source:t,status:n,accounts:r,now:s,busy:o,onClose:l,onRename:c,onCheck:d,onVerb:h,onSettings:f,onInvite:p,twins:g=[],onUnpair:v}){const N=y.useRef(null),k=ut(l,{focusRef:N}),x=gt(l),[j,b]=y.useState(null),[_,E]=y.useState(null),[R,C]=y.useState(!1),[A,U]=y.useState(0),L=y.useRef(null),F=y.useRef(null),O=y.useRef(!0);y.useEffect(()=>()=>{O.current=!1},[]);const I=j!=null;y.useEffect(()=>{var ae;I&&((ae=L.current)==null||ae.select())},[I]);const B=y.useRef(!1);y.useEffect(()=>{var ae,fe;B.current&&!I&&Tn(((ae=document.activeElement)==null?void 0:ae.tagName)??null)&&((fe=F.current)==null||fe.focus()),B.current=I},[I]);const M=ae=>{const fe=ia(o,ae);return{disabled:fe.disabled,"aria-busy":fe.busy}},$=async ae=>{const fe=await ae();return O.current&&E(fe),fe==null},{armed:P,armedTwin:G,pressOwn:K,pressTwin:q}=KY({row:e,run:$,onVerb:h,onUnpair:v}),H=nO({row:e,source:t,status:n,accounts:r,now:s}),{peer:D,stranger:W,paired:J,own:V,canRename:X,fp:Y}=H,Z=o===`check:${e.fp}`,ee=async ae=>{const fe=ae.trim()===V?"":ae;await $(()=>c(fe))&&b(null)},ne=()=>void $(d).then(ae=>{ae&&O.current&&U(fe=>fe+1)}),se=async()=>{if(Y)try{if(await navigator.clipboard.writeText(Y),!O.current)return;C(!0),window.setTimeout(()=>{O.current&&C(!1)},1600)}catch{O.current&&E("Could not copy it — select the fingerprint and copy it by hand.")}},pe=[];J&&(D!=null&&D.pairedAt)?pe.push({label:"Paired",value:kY(D.pairedAt,s),tone:"meta"}):e.kind==="declined"&&W&&pe.push({label:"Paired",value:`no · you said no ${j0(W.at,s)}`,tone:"meta"}),pe.push({label:"Fingerprint",value:Y?a.jsxs("span",{className:"lan-fp",children:[a.jsx("code",{className:"ap-lan-code",children:Y}),a.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void se(),"aria-label":R?"Fingerprint copied":"Copy the fingerprint",children:R?"copied":"copy"})]}):"not known — nothing has answered there",tone:Y?void 0:"quiet"});const ke=g.length?[{row:e,peer:D??null},...g]:[];return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...x,role:"presentation",children:a.jsxs("div",{ref:k,className:"modal lan-peer","data-tone":e.tone,onClick:ae=>ae.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[a.jsxs("header",{className:"modal-head lan-peer-head",children:[a.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),a.jsxs("div",{className:"lan-peer-id",children:[I?a.jsxs("form",{className:"lan-peer-edit",onSubmit:ae=>{ae.preventDefault(),ee(j??"")},children:[a.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),a.jsx("input",{ref:L,className:"ap-manage-input lan-peer-input",value:j??"",maxLength:48,placeholder:V,"aria-label":"Name for this deck, shown on this deck only",onChange:ae=>b(ae.target.value)}),a.jsx("button",{type:"submit",className:"ap-manage-btn",...M(`alias:${e.fp}`),children:"save"}),a.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>b(null),children:"cancel"})]}):a.jsxs("span",{className:"lan-peer-title",children:[a.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),X&&a.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",ref:F,onClick:()=>{E(null),b(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:a.jsx(ZY,{})})]}),a.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&a.jsxs(a.Fragment,{children:["calls itself ",a.jsx("span",{className:"lan-peer-self",children:e.self}),I&&a.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...M(`alias:${e.fp}`),onClick:()=>void ee(""),children:"use this name"}),a.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&a.jsx("span",{"aria-hidden":!0,children:" · "})]}),a.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{ref:N,type:"button",className:"glyph-btn",onClick:l,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body lan-peer-body",children:[_&&a.jsxs("div",{className:"ap-failure",role:"alert",children:[a.jsx("span",{className:"ap-failure-text",children:_}),a.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>E(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),a.jsx(NY,{view:H,row:e,status:n,asking:Z,drawn:A,onSettings:f}),a.jsx("dl",{className:"lan-facts",children:pe.map(ae=>a.jsxs("div",{className:"lan-fact","data-tone":ae.tone,children:[a.jsx("dt",{children:ae.label}),a.jsx("dd",{children:ae.value})]},ae.label))}),ke.length>1&&a.jsx(XY,{instances:ke,now:s,busy:o,press:M,armedTwin:G,pressTwin:q,onUnpair:v})]}),a.jsx(YY,{row:e,paired:J,peer:D,status:n,busy:o,press:M,checkNow:ne,armed:P,pressOwn:K,run:$,onVerb:h,onInvite:p})]})}),document.body)}function is(e,t){const n=y.useRef(!1);return y.useEffect(()=>{var r,s;!e||!n.current||(n.current=!1,Tn(((r=document.activeElement)==null?void 0:r.tagName)??null)&&(typeof t=="function"?t():(s=t.current)==null||s.focus()))},[e]),()=>{n.current=!0}}function QY(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function eX(e,t,n,r){const s=new Set(e??t);return r?s.add(n):s.delete(n),[...s]}function r_(e,t,n){return e==null||n!=null&&!n.ok||QY(e,t)?null:e}function aO({line:e,onDismiss:t,onAnswer:n}){const[r,s]=y.useState(!1),o=y.useRef(!1),l=y.useRef(!0);y.useEffect(()=>(l.current=!0,()=>{l.current=!1}),[]);const c=y.useRef(null),d=y.useRef(null),h=y.useRef(!1);if(y.useEffect(()=>{var p;h.current&&(h.current=!1,e!=null&&e.giveBack||(p=d.current)==null||p.focus())},[e]),!e)return null;const f=async()=>{if(o.current)return;o.current=!0,s(!0);const p=await QG();o.current=!1,l.current&&(s(!1),h.current=document.activeElement===c.current,n(tK(p)))};return a.jsxs("div",{className:e.done?"ap-failure ap-failure-done":"ap-failure",role:"alert",children:[a.jsx("span",{className:"ap-failure-text",children:e.text}),e.giveBack&&a.jsx("button",{ref:c,type:"button",className:"ap-fix ap-give-back","aria-busy":r,onClick:f,title:"Opens macOS's password dialog to make the settings folder yours again",children:r?"waiting for macOS…":"give it back"}),a.jsx("button",{ref:d,type:"button",className:"ap-failure-x",onClick:t,"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]})}function tX(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 Vu="Paused while this deck pairs only by invite. Turn that off above to use it.";function nX({status:e,accounts:t,onClose:n,onChanged:r}){qt("lan-setup");const s=ut(n),o=gt(n),[l,c]=y.useState(null),[d,h]=y.useState(null),[f,p]=y.useState(!1),[g,v]=y.useState(null),N=y.useRef(null),k=q=>{const H=ia(g,q);return{disabled:H.disabled,"aria-busy":H.busy}},x=y.useRef(null),j=y.useRef(!0);y.useEffect(()=>()=>{j.current=!1},[]),y.useEffect(()=>{x.current=r_(x.current,e.shared??[],null)},[e.shared]);const b=y.useCallback(async(q,H,D="write")=>{N.current=D,v(D);try{const J=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:q})})).json().catch(()=>null);return j.current?(J!=null&&J.ok?h(null):h(sr(Tt(H,J),J)),r(),(J==null?void 0:J.ok)===!0):!1}catch{return j.current&&h(sr(Tt(H,null))),!1}finally{N.current=null,j.current&&v(null)}},[r]),_=y.useCallback(async q=>{const H=await b({name:q},"save the name","name");return H&&j.current&&c(D=>D===q?null:D),H},[b]),E=y.useRef(null),R=l!=null&&l!==(e.name??""),C=is(!R,E),A=y.useCallback(async()=>{R&&!await _(l)||n()},[R,l,_,n]),U=async()=>{if(!e.fp)return;const q=await eo(e.fp);if(j.current){if(!q){h(sr("Could not copy it — select the fingerprint and copy it by hand."));return}p(!0),window.setTimeout(()=>{j.current&&p(!1)},1600)}},L=new Set(x.current??e.shared??[]),F=e.autoAsk!==!1,O=e.autoAccept!==!1,I=e.pairingMode==="invite",B=q=>{const H=k(q);return{...H,disabled:H.disabled||I}},M=e.shareActive!==!1,$=e.tailscale??null,P=!!($!=null&&$.on),G=($==null?void 0:$.ask)!==!1,K=($==null?void 0:$.accept)!==!1;return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...o,role:"presentation",children:a.jsxs("div",{ref:s,className:"modal lan-modal",onClick:q=>q.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[a.jsx(aO,{line:d,onDismiss:()=>h(null),onAnswer:q=>{h(q),q.done&&r()}}),a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",children:"Name"}),a.jsxs("div",{className:"ap-lan-row",children:[a.jsx("span",{className:"ap-lan-label",children:"appear as"}),a.jsx("input",{ref:E,className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:l??e.name??"",placeholder:"this machine",onChange:q=>c(q.target.value),onKeyDown:q=>{q.key!=="Enter"||l==null||_(l)}}),R&&a.jsx("button",{type:"button",className:"ap-manage-btn",...k("name"),onClick:()=>{C(),_(l)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),a.jsxs("div",{className:"ap-lan-row",children:[a.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?a.jsxs("span",{className:"lan-fp",children:[a.jsx("code",{className:"ap-lan-code",children:e.fp}),a.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void U(),"aria-label":f?"Fingerprint copied":"Copy this deck's fingerprint",children:f?"copied":"copy"})]}):a.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",children:"Share these accounts"}),a.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&a.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(q=>a.jsxs("label",{className:"ap-lan-pick",title:q.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:[a.jsx("input",{type:"checkbox",checked:L.has(q.key),onChange:H=>{const D=eX(x.current,e.shared??[],q.key,H.target.checked);x.current=D,b({shared:D},H.target.checked?"share that account":"stop sharing that account").then(W=>{x.current===D&&(x.current=r_(D,e.shared??[],{ok:W}))})}}),a.jsx("span",{className:"ap-lan-pick-name",children:q.email}),!q.alive&&a.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},q.key))]}),t.length>0&&a.jsxs("div",{className:"lan-switch",children:[a.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":M,"aria-label":"Show paired decks which of these this deck is using",...k("current"),onClick:()=>void b({shareActive:!M},M?"stop showing which account this deck is using":"show which account this deck is using","current"),title:M?"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:a.jsx("span",{className:"switch-knob"})})]})]}),a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",id:"lan-pairing-h",children:"Pairing"}),a.jsx("div",{className:"lan-switches lan-switches-lead",role:"group","aria-labelledby":"lan-pairing-h",children:a.jsxs("div",{className:"lan-switch",children:[a.jsxs("span",{className:"lan-switch-what",children:["Pair new decks only by invite",I&&a.jsx("span",{id:"lan-invite-only-detail",className:"lan-switch-detail",children:"A new deck needs an invite from Add a deck, the link at the top of Local network. Paired decks stay paired."})]}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":I,"aria-label":"Pair new decks only by invite","aria-describedby":I?"lan-invite-only-detail":void 0,...k("mode"),onKeyDown:q=>{q.repeat&&q.preventDefault()},onClick:()=>void b({pairingMode:I?"automatic":"invite"},I?"let decks pair on their own again":"pair new decks only by invite","mode"),title:I?"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:a.jsx("span",{className:"switch-knob"})})]})}),a.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-auto-h",children:[a.jsxs("p",{className:"lan-sub",id:"lan-auto-h",children:["Automatic pairing",I&&a.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),a.jsxs("div",{className:"lan-switches","data-paused":I||void 0,children:[a.jsxs("div",{className:"lan-switch",children:[a.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":F,"aria-label":"Ask every deck this one finds",...B("ask"),onClick:()=>void b({autoAsk:!F},F?"stop asking automatically":"ask every deck this one finds","ask"),title:I?Vu:F?"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:a.jsx("span",{className:"switch-knob"})})]}),a.jsxs("div",{className:"lan-switch",children:[a.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":O,"aria-label":"Say yes to every deck that asks","data-tone":"warn",...B("accept"),onKeyDown:q=>{q.repeat&&q.preventDefault()},onClick:()=>void b({autoAccept:!O},O?"stop accepting automatically":"accept every deck that asks","accept"),title:I?Vu:O?"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:a.jsx("span",{className:"switch-knob"})})]})]})]})]}),($==null?void 0:$.found)&&a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",children:"Tailscale"}),a.jsxs("div",{className:"lan-switches",children:[a.jsxs("div",{className:"lan-switch",children:[a.jsxs("span",{className:"lan-switch-what",children:["Look for my devices",a.jsx("span",{id:"lan-ts-detail",className:"lan-switch-detail",children:tX($)})]}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":P,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",...k("tailscale"),onClick:()=>void b({tailscale:!P},P?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:P?"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:a.jsx("span",{className:"switch-knob"})})]}),P&&a.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-ts-auto-h",children:[a.jsxs("p",{className:"lan-sub",id:"lan-ts-auto-h",children:["Automatic pairing with my devices",I&&a.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),a.jsxs("div",{className:"lan-switches",children:[a.jsxs("div",{className:"lan-switch","data-paused":I||void 0,children:[a.jsx("span",{className:"lan-switch-what",children:"Ask each device it finds"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":G,"aria-label":"Ask each of my devices it finds over Tailscale",...B("tailscale-ask"),onClick:()=>void b({tailscaleAsk:!G},G?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:I?Vu:G?"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:a.jsx("span",{className:"switch-knob"})})]}),a.jsxs("div",{className:"lan-switch","data-paused":I||void 0,children:[a.jsx("span",{className:"lan-switch-what",children:"Say yes to each device that asks"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":K,"aria-label":"Say yes to my devices when they ask over Tailscale","data-tone":"warn",...B("tailscale-accept"),onKeyDown:q=>{q.repeat&&q.preventDefault()},onClick:()=>void b({tailscaleAccept:!K},K?"stop accepting your devices automatically":"accept your devices automatically","tailscale-accept"),title:I?Vu:K?"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:a.jsx("span",{className:"switch-knob"})})]})]})]})]})]})]}),a.jsxs("footer",{className:"lan-setup-foot",children:[a.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),a.jsx("button",{type:"button",className:"btn primary",...k("name"),onClick:()=>void A(),children:"Done"})]})]})}),document.body)}function rX({on:e,status:t,paired:n,busy:r,pressProps:s,checkNow:o,setAddOpen:l,setSetupOpen:c,setMapOpen:d,onBack:h,closeButton:f}){return a.jsxs("div",{className:"ap-header",children:[a.jsx("button",{type:"button",id:"ap-lan-back",className:"glyph-btn ap-back",onClick:h,"aria-label":"Back to Claude accounts",title:"Back to Claude accounts",children:a.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:a.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),a.jsx("h2",{id:"ap-lan-title",children:"Local network"}),a.jsxs("div",{className:"ap-header-right",children:[e&&a.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>d(!0),"aria-label":"Show the network map",title:"Network map — every deck this one knows, drawn around it",children:a.jsx(rO,{})}),e&&a.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>l("add"),"aria-label":"Add a deck",title:(t==null?void 0:t.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:a.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:[a.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"}),a.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"})]})}),e&&n>0&&a.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...s("check"),onClick:()=>void o(),"aria-label":r==="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:a.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:[a.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),a.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"}),a.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"})]})}),e&&a.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...s("setup"),onClick:()=>c(!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:a.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[a.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),a.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),a.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),f]})]})}function sX({accounts:e,onChanged:t,onNoCopy:n,view:r,onOpen:s,onBack:o,closeButton:l}){const[c,d]=y.useState(!1),[h,f]=y.useState(!1),[p,g]=y.useState(!1),v=ZG(),[N,k]=y.useState(!1),{status:x,manual:j,now:b,busy:_,failure:E,dismissFailure:R,answerGiveBack:C,pressProps:A,load:U,toggle:L,answer:F,dropAddress:O,rename:I,checkOne:B,checkNow:M}=oK(t,()=>d(!0)),{armed:$,pressUnpair:P}=iK(F),[G,K]=y.useState(null),[q,H]=y.useState(!1),D=y.useMemo(()=>e.filter(me=>YG(me.key,x??null,b)).map(me=>me.key).sort().join(`
|
|
91
|
+
`))&&s.current&&(r(!0),window.setTimeout(()=>{s.current&&r(!1)},jK))},[o]);if(!(e!=null&&e.blocked))return null;const c=e.shell==="sh",d=!!e.tool;return a.jsxs("div",{className:"ap-lan-reach",children:[a.jsx("p",{className:"lan-warn",children:e.text}),a.jsx("p",{className:"lan-note",children:NK[t]}),o.length>0&&a.jsxs("details",{className:"ap-lan-reach-fix",children:[a.jsx("summary",{children:"or let them find this deck on their own"}),a.jsxs("p",{className:"lan-note",children:[d?a.jsx(a.Fragment,{children:"Run this in a terminal on this machine. It applies at once, and this note goes away when another deck connects."}):c?a.jsx(a.Fragment,{children:"Run this in a terminal on this machine, then restart the deck."}):a.jsxs(a.Fragment,{children:["Run this in PowerShell ",a.jsx("strong",{children:"as Administrator"}),", then restart the deck."]}),e.category==="Public"&&a.jsx(a.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&&a.jsxs(a.Fragment,{children:[" ",e.unsure]})]}),a.jsx("pre",{className:"ap-lan-cmd",children:a.jsx("code",{children:o.join(`
|
|
92
|
+
`)})}),a.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>void l(),title:c?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:n?"copied":"copy command"})]})]})}function SK(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 _K(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}async function Up(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const EK={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."},TK={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function qS(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||Tt(n,t)}function CK({status:e,manual:t,startWith:n,onClose:r,onChanged:s}){const o=y.useRef(null),l=y.useRef(null),c=y.useRef(null),d=y.useRef(null),h=e.pairingMode==="invite",f=ut(r,{focusRef:h?l:o}),p=gt(r),[g,v]=y.useState(""),[N,k]=y.useState(""),[x,j]=y.useState(null),[b,_]=y.useState(null),[E,R]=y.useState(null),[C,A]=y.useState(null),[U,L]=y.useState(()=>Date.now());y.useEffect(()=>{const Y=window.setInterval(()=>L(Date.now()),1e3);return()=>window.clearInterval(Y)},[]);const F=y.useRef(!0);y.useEffect(()=>()=>{F.current=!1},[]);const O=y.useRef(null),I=y.useRef(null),B=y.useCallback(Y=>lh(O.current)?(O.current=Y,R(Y),!0):!1,[]),M=y.useCallback(()=>{O.current=null,F.current&&R(null)},[]),$=Y=>{const Z=ia(E,Y);return{disabled:Z.disabled,"aria-busy":Z.busy}},P=Y=>(x==null?void 0:x.field)===Y?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},G=Y=>j(Z=>Z&&Z.field===Y?null:Z),K=y.useCallback(async()=>{if(h)return;const Y=SK(g);if(!Y){j({text:AK(g),field:"addr"});return}const Z=`${Y.addr}:${Y.port}`,ee=e.peers.find(ne=>ne.addr===Y.addr&&ne.port===Y.port&&ne.paired);if(ee){j({text:`Already paired with ${ee.name} at that address.`,field:"addr"});return}if(t.includes(Z)){j({text:"This deck already calls that address.",field:"addr"});return}if(B("add"))try{const ne=await Up("/api/prefs",{lan:{manual:[...t,Z]}});if(!F.current)return;ne!=null&&ne.ok?(j(null),v(""),s(),r()):j({text:Tt("add that address",ne),field:"addr"})}catch{F.current&&j({text:Tt("add that address",null),field:"addr"})}finally{M()}},[g,h,t,e.peers,s,r,B,M]),q=y.useCallback(async Y=>{if(!B(`invite:${Y}`))return;const Z=Y==="make"?"make an invite":"cancel that invite";try{const ee=await Up("/api/lan/invite",{action:Y});if(!F.current)return;ee!=null&&ee.ok?(I.current=Y,j(null),_(null),s()):j({text:qS(TK,ee,Z)})}catch{F.current&&j({text:Tt(Z,null)})}finally{M()}},[s,B,M]),H=y.useCallback(async()=>{const Y=N.trim();if(!(!Y||!B("join"))){A(null);try{const Z=await Up("/api/lan/invite",{action:"join",token:Y});if(!F.current)return;Z!=null&&Z.ok?(k(""),j(null),s(),r()):(Z==null?void 0:Z.reason)==="unreachable"&&Array.isArray(Z.tried)&&Z.tried.length?(A(Z.tried),j(null)):(A(null),j({text:qS(EK,Z,"use that invite"),field:"join"}))}catch{F.current&&j({text:Tt("use that invite",null),field:"join"})}finally{M()}}},[N,s,r,B,M]),D=y.useCallback(async(Y,Z)=>{try{await navigator.clipboard.writeText(Y),_(Z),window.setTimeout(()=>{F.current&&_(ee=>ee===Z?null:ee)},1600)}catch{j({text:"Could not copy it — select the text and copy it by hand."})}},[]),W=e.invite&&e.invite.expiresAt>U?e.invite:null,J=y.useRef(!1);y.useEffect(()=>{n!=="invite"||J.current||W||(J.current=!0,q("make"))},[n,W,q]);const V=y.useRef(!1);y.useEffect(()=>{var Y;n!=="invite"||V.current||!W||(V.current=!0,(Y=c.current)==null||Y.focus())},[n,W]),y.useEffect(()=>{var Z,ee;const Y=I.current;!Y||Y==="make"!=!!W||(I.current=null,Tn(((Z=document.activeElement)==null?void 0:Z.tagName)??null)&&((ee=(Y==="make"?c:d).current)==null||ee.focus()))},[W]);const X=e.port!=null?(e.addrs??[]).map(Y=>`${Y}:${e.port}`):[];return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...p,role:"presentation",children:a.jsxs("div",{ref:f,className:"modal lan-add",onClick:Y=>Y.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-add-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"lan-add-title",className:"modal-tool-name",children:"Add a deck"})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{className:"glyph-btn",onClick:r,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[x&&a.jsxs("div",{className:"ap-failure",role:"alert",children:[a.jsx("span",{id:"lan-add-failure",className:"ap-failure-text",children:x.text}),a.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>j(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),a.jsx(WI,{reach:e.reach,where:"dialog"}),h&&a.jsx("div",{className:"modal-section",children:a.jsx("p",{className:"lan-note",children:"Adding by address is off while this deck pairs only by invite."})}),!h&&a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",children:"By address"}),a.jsxs("div",{className:"ap-lan-row",children:[a.jsx("input",{ref:o,className:"ap-manage-input ap-lan-input","aria-label":"Another deck's address",value:g,placeholder:"192.168.1.5:54340",spellCheck:!1,...P("addr"),onChange:Y=>{v(Y.target.value),G("addr")},onKeyDown:Y=>{Y.key==="Enter"&&K()}}),g.trim()!==""&&a.jsx("button",{type:"button",className:"ap-manage-btn",...$("add"),onClick:()=>void K(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),a.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&X.length>0&&a.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",X.map((Y,Z)=>a.jsxs("span",{children:[Z>0&&" or ",a.jsx("code",{className:"ap-lan-code",children:Y})]},Y)),a.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...$("copy:mine"),onClick:()=>void D(X.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:b==="mine"?"copied":"copy"})]})]}),a.jsxs("div",{className:"modal-section",children:[a.jsxs("h3",{className:"lan-h",children:["With an invite",!W&&a.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",ref:d,...$("invite:make"),onClick:()=>void q("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:E==="invite:make"?"making…":"make one to send"})]}),a.jsxs("div",{className:"ap-lan-row",children:[a.jsx("input",{ref:l,className:"ap-manage-input ap-lan-input","aria-label":"An invite you were sent",value:N,placeholder:"paste one you were sent",spellCheck:!1,...P("join"),onChange:Y=>{k(Y.target.value),A(null),G("join")},onKeyDown:Y=>{Y.key==="Enter"&&H()}}),N.trim()!==""&&a.jsx("button",{type:"button",className:"ap-manage-btn",...$("join"),onClick:()=>void H(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:E==="join"?"joining…":"join"})]}),a.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),C&&a.jsxs("div",{className:"ap-lan-tried",children:[a.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(Y=>a.jsxs("span",{className:"ap-lan-tried-row",children:[a.jsx("code",{className:"ap-lan-code",children:Y.addr}),a.jsx("span",{className:"ap-lan-bad",children:Y.why})]},Y.addr))]}),W&&a.jsxs("div",{className:"ap-lan-invite",children:[a.jsxs("div",{className:"ap-lan-invite-head",children:[a.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),a.jsxs("span",{className:"ap-lan-invite-left",id:"lan-invite-left",children:[_K(W.expiresAt,U)," left"]})]}),a.jsx("code",{className:"ap-lan-token",children:W.token}),a.jsxs("div",{className:"ap-lan-acts",children:[a.jsx("button",{type:"button",className:"ap-manage-btn",ref:c,...$("copy:invite"),"aria-label":b==="invite"?"Invite copied":"Copy invite","aria-describedby":"lan-invite-left",onClick:()=>void D(W.token,"invite"),title:"Copy it, and send it however you already talk to them",children:b==="invite"?"copied":"copy"}),a.jsx("button",{type:"button",className:"ap-manage-btn",...$("invite:withdraw"),onClick:()=>void q("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),a.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function AK(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}".`}function RK({asks:e,pressProps:t,answer:n}){return a.jsx("div",{className:"ap-lan-asks",role:"alert",children:e.map(r=>a.jsxs("div",{className:"ap-lan-ask",children:[a.jsxs("span",{className:"ap-lan-ask-what",children:[a.jsx("strong",{className:"ap-lan-peer-name",children:r.name})," at ",a.jsx("code",{className:"ap-lan-code",children:r.addr})," wants to pair"]}),a.jsxs("span",{className:"ap-lan-ask-fp",id:`lan-ask-fp-${r.fp}`,children:["fingerprint ",a.jsx("code",{className:"ap-lan-code",children:r.fp})]}),a.jsxs("span",{className:"ap-lan-ask-acts",children:[a.jsx("button",{type:"button",className:"ap-manage-btn",...t(`accept:${r.fp}`),"aria-label":`Accept ${r.name}`,"aria-describedby":`lan-ask-fp-${r.fp}`,onClick:()=>void n("accept",r.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${r.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),a.jsx("button",{type:"button",className:"ap-manage-btn",...t(`dismiss:${r.fp}`),"aria-label":`Decline ${r.name}`,"aria-describedby":`lan-ask-fp-${r.fp}`,onClick:()=>void n("dismiss",r.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},r.fp))})}function MK({rows:e,pairingMode:t,armed:n,pressProps:r,answer:s,dropAddress:o,onUnpair:l,onOpenPeer:c,onInvite:d}){return a.jsx("ul",{className:"ap-lan-here",children:e.map((h,f)=>a.jsxs("li",{className:"ap-lan-who","data-tone":h.tone,children:[a.jsx("i",{className:h.here?"ap-pulse":"ap-dot","aria-hidden":!0}),a.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[h.name,h.via==="tailscale"&&a.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]}),a.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${f}`,onClick:()=>c(h.fp),children:a.jsxs("span",{className:"vis-hidden",children:[h.name,h.via==="tailscale"?", over Tailscale":"",", details"]})}),a.jsx("span",{id:`lan-who-state-${f}`,className:h.quiet?"vis-hidden":"ap-lan-who-when",children:h.state}),h.kind==="nearby"&&t!=="invite"&&a.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...r(`accept:${h.fp}`),onClick:()=>void s("accept",h.fp,"reach that deck"),"aria-label":`Ask ${h.name} to pair`,title:`Send ${h.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${h.fp}.`,children:"ask"}),(h.kind==="nearby"||h.kind==="declined")&&t==="invite"&&a.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do","aria-haspopup":"dialog",onClick:d,"aria-label":`Invite ${h.name} to pair`,title:`This deck pairs only by invite. Make one and send it to whoever is at ${h.name}.`,children:"invite"}),h.kind==="paired"&&a.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${n===h.fp?" armed":""}`,...r(`unpair:${h.fp}`),onClick:()=>l(h),"aria-label":n===h.fp?`Confirm unpairing ${h.name}`:`Unpair ${h.name}`,title:n===h.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:n===h.fp?"confirm":"unpair"}),h.kind==="dialling"&&a.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...r(`drop:${h.fp}`),onClick:()=>void o(h.fp),"aria-label":`Stop dialling ${h.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),h.kind==="declined"&&t!=="invite"&&a.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...r(`allow:${h.fp}`),onClick:()=>void s("allow",h.fp,"let that deck ask again"),"aria-label":`Let ${h.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${h.kind}:${h.fp}`))})}function $K(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 IK({on:e,status:t}){return a.jsxs(a.Fragment,{children:[e&&a.jsx(WI,{reach:t==null?void 0:t.reach,where:"panel"}),e&&(t==null?void 0:t.deaf)&&a.jsx("p",{className:"ap-lan-fine",children:t.deaf}),e&&(t==null?void 0:t.lanTunneled)&&a.jsx("p",{className:"ap-lan-fine",children:$K(t)})]})}const US=["online","offline","loose"],OK={online:0,offline:1,loose:2};function LK(e){return e.kind==="declined"?null:e.kind==="paired"?e.here?"online":"offline":"loose"}const PK=76,DK=62,Rd=96,FK={1:[.62],2:[.58,1],3:[.42,.72,1]},BK=.2,qK=.16,UK=.05,zK=20,WK=17,zu=7,HK=30,VK=116,GK=6.6,KK=6,YK=e=>E0(e,null),XK=1.5,ZK=80,JK=.45,zS=40,QK=64,eY=150,WS=.3,HS=84,VS=8,tY=1.3,Md=6,nY=5.94,GS=7,KS=16,xl=4,YS=.16;function ab(e,t){return Math.PI*(3*(e+t)-Math.sqrt((3*e+t)*(e+3*t)))}function HI(e,t){return t<-Math.abs(e)*.6?"top":"bottom"}function rY(e,t){if(e<=2)return t%2===0?0:90;const n=360/e;return-90+(t%2===0?0:n/2)}function sY(e){return e.map((t,n)=>({...t,i:n})).sort((t,n)=>US.indexOf(t.tier)-US.indexOf(n.tier)||+(t.row.via==="tailscale")-+(n.row.via==="tailscale")||t.i-n.i).map(({row:t,tier:n})=>({row:t,tier:n}))}function XS(e,t){let n=2166136261^t;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619);return(n>>>0)%2e4/1e4-1}function aY(e,t,n){const r=[...FK[e.length]??[]];for(let s=0;s<r.length;s++){const o=e[s];if(o<2)continue;const l=ab(t*r[s],n*r[s])/o;if(!(l>0)||l>=Rd)continue;const c=s+1<r.length?r[s+1]-BK:1;r[s]=Math.max(r[s],Math.min(c,r[s]*(Rd/l)*1.02))}return r}const Pa=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1,zp={h:16,ch:6.1,maxW:100};function oY(e){const t=e?Math.max(80,e.length*7.2+16):128;return{x0:-t/2,y0:32,x1:t/2,y1:66}}function VI(e,t,n,r,s,o){const l=t==="loose"?WK:zK,c=!s||e.kind==="asks",d=c?HK:zp.h,h=s?zp.ch:GK,f=c?o.length:0,p=Math.min(s?zp.maxW:VK,Math.max(2*l,KI(e).length*h,f*KK)),g={x0:n-l,y0:r-l,x1:n+l,y1:r+l},v=HI(n,r)==="top"?{x0:n-p/2,y0:r-l-zu-d,x1:n+p/2,y1:r-l-zu}:{x0:n-p/2,y0:r+l+zu,x1:n+p/2,y1:r+l+zu+d};return[g,v]}const ob=e=>{const t=e.theta*Math.PI/180;return[Math.cos(t)*e.ring.rx*e.reach,Math.sin(t)*e.ring.ry*e.reach]},Wu=(e,t)=>((e-t)%360+540)%360-180;function ZS(e,t,n){const r=new Map;for(const f of e)r.has(f.ring)||r.set(f.ring,[]),r.get(f.ring).push(f);const s=()=>e.map(f=>{const[p,g]=ob(f);return VI(f.row,f.tier,p,g,t,f.caption)}),o=(f,p,g=!1)=>{if(f.count<=2&&!g)return!1;const v=f.theta+p*XK,N=r.get(f.ring),k=(f.count>2?360/f.count:f.turn)*JK,x=N[(f.index+1)%f.count],j=N[(f.index-1+f.count)%f.count];return!(x===f||(p>0?Wu(x.theta,v)>=k:Wu(v,j.theta)>=k))||v<f.lo||v>f.hi?!1:(f.theta=v,!0)},l=([f,p],[g,v])=>Pa(p,g)||Pa(v,f)||Pa(p,v)||Pa(f,g),c=([f,p])=>Pa(f,n)||Pa(p,n);for(let f=0;f<ZK;f++){const p=s();let g=!1;for(let v=0;v<e.length;v++){c(p[v])&&(g=o(e[v],Wu(e[v].theta,90)>=0?1:-1,!0)||g);for(let N=v+1;N<e.length;N++){if(!l(p[v],p[N]))continue;const k=e[v],x=e[N],j=x.ring.ring>k.ring.ring||x.ring===k.ring&&N>v?x:k,b=j===x?k:x,_=Wu(j.theta,b.theta)>=0?1:-1;g=o(j,_)||o(b,-_)||g}}if(!g)break}const d=s();let h=0;for(let f=0;f<d.length;f++){c(d[f])&&h++;for(let p=f+1;p<d.length;p++)l(d[f],d[p])&&h++}return h}const iY={online:0,offline:1,loose:1};function lY(e,t,n,r="",s=YK){const o=[];for(const l of[!0,!1]){const c=JS(e,t,n,r,OK,s,l);if(c.clashes===0)return c.named();if(o.push(c),c.layout.rings.length===3){const d=JS(e,t,n,r,iY,s,l),h={clashes:d.clashes,named:()=>({...d.named(),folded:!0})};if(h.clashes===0)return h.named();o.push(h)}if(!c.layout.zone)break}return o.reduce((l,c)=>c.clashes<l.clashes?c:l).named()}function JS(e,t,n,r,s,o,l=!0){const c=new Map;for(const B of e){const M=LK(B);if(!M)continue;const $=s[M];c.has($)||c.set($,[]),c.get($).push({row:B,tier:M})}const d=[...c.keys()].sort((B,M)=>B-M),h=Math.max(0,t/2-PK),f=Math.max(0,n/2-DK),p=aY(d.map(B=>c.get(B).length),h,f),g=d.map((B,M)=>({ring:B,rx:h*p[M],ry:f*p[M],count:c.get(B).length})),v=g.reduce((B,M)=>B+M.count,0),N=B=>B.row.via==="tailscale",k=[...c.values()].flat().filter(N).length,x=Math.max(0,...g.map(B=>{const M=c.get(B.ring).filter(N).length,$=ab(B.rx,B.ry);return M>0&&$>0?M*Rd*tY/$*360:0})),j=l&&k>0&&k<v?Math.min(eY,Math.max(QK,k/v*360,x)):0,b=zS-j/2,_=zS+j/2,E=[];let R=!1;g.forEach((B,M)=>{const $=sY(c.get(B.ring)),P=$.length,G=P>1&&ab(B.rx,B.ry)/P<Rd;G&&(R=!0);const K=M===g.length-1,q=K?-YS*(p[M]-(p[M-1]??0)):YS*(p[M+1]-p[M]),H=j>0?[{members:$.filter(W=>W.row.via!=="tailscale"),from:_,width:360-j},{members:$.filter(W=>W.row.via==="tailscale"),from:b+360,width:j}]:[{members:$,from:null,width:360}];let D=0;for(const W of H){const J=W.members.length;if(J===0)continue;const V=W.width/J,X=J>2;W.members.forEach(({row:Y,tier:Z},ee)=>{const ne=rr(Y),se=W.from==null?rY(J,M)+V*ee:W.from+V*(ee+.5),pe=X?XS(ne,1)*qK*V:0,ke=G&&D%2===1?1+q/p[M]:1,ae=X?XS(ne,2)*UK:0,fe=V*.3;E.push({row:Y,tier:Z,ring:B,index:D,count:P,theta:se+pe,reach:ke*(1+(K?-Math.abs(ae):ae)),lo:W.from==null?-1/0:W.from+fe,hi:W.from==null?1/0:W.from+W.width-fe,turn:V,caption:o(Y)}),D++})}});const C=oY(r);let A=ZS(E,R,C);A>0&&!R&&(R=!0,A=ZS(E,!0,C));const U=E.map((B,M)=>{const[$,P]=ob(B);return{row:B.row,tier:B.tier,ring:B.ring.ring,x:$,y:P,angle:cY(Math.atan2(P,$)*180/Math.PI),dist:Math.hypot($,P),side:HI($,P),order:M}}),L=g.reduce((B,M,$)=>c.get(M.ring).some(N)?Math.max(B,p[$]):B,0),F=B=>({from:b,to:_,inner:{rx:h*WS,ry:f*WS},outer:{rx:Math.min(t/2-8,h*L+B),ry:Math.min(n/2-8,f*L+B)},count:k}),O={nodes:U,rings:g,dense:R,zone:j>0?{...F(HS),labelAt:null}:null};return{layout:O,clashes:A,named:()=>{if(!O.zone)return O;const B=E.flatMap(P=>{const[G,K]=ob(P);return VI(P.row,P.tier,G,K,R,P.caption)});let M={...O.zone,labelAt:QS(O.zone,B)},$=M.outer;for(let P=HS+VS;M.labelAt==null;P+=VS){const G=F(P);if(G.outer.rx===$.rx&&G.outer.ry===$.ry)break;$=G.outer;const K=QS(G,B);K!=null&&(M={...G,labelAt:K})}return{...O,zone:M}}}}function GI(e){return`Tailscale · ${e} deck${e===1?"":"s"}`}function QS(e,t){const n={rx:e.outer.rx-Md,ry:e.outer.ry-Md};if(!(n.rx>0&&n.ry>0))return null;const r=Math.min(.5,2/Math.max(n.rx,n.ry)*(180/Math.PI)),s=[];for(let b=e.to;b>=e.from;b-=r){const _=b*Math.PI/180;s.push([Math.cos(_)*n.rx,Math.sin(_)*n.ry])}const o=GS+xl,l={x0:Math.min(...s.map(b=>b[0]))-o,x1:Math.max(...s.map(b=>b[0]))+o,y0:Math.min(...s.map(b=>b[1]))-o,y1:Math.max(...s.map(b=>b[1]))+o},c=t.map(b=>({x0:b.x0-xl,y0:b.y0-xl,x1:b.x1+xl,y1:b.y1+xl})).filter(b=>Pa(b,l)),d=(b,_)=>c.some(E=>b>E.x0&&b<E.x1&&_>E.y0&&_<E.y1),h=[],f=[];let p=0;s.forEach(([b,_],E)=>{E>0&&(p+=Math.hypot(b-s[E-1][0],_-s[E-1][1]));const R=Math.hypot(b,_)||1;let C=!1;for(let A=0;A<=GS&&!C;A+=1.75)C=d(b-b/R*A,_-_/R*A);h.push(p),f.push((f.at(-1)??0)+(C?1:0))});const g=GI(e.count).length*nY/2,v=g+KS,N=p-g-KS;if(!(p>0)||N<v)return null;const k=b=>{let _=0,E=h.length;for(;_<E;){const R=_+E>>1;h[R]<b?_=R+1:E=R}return _},x=b=>{const _=k(b-g),E=k(b+g+1e-9)-1;return E<_||f[E]-(_>0?f[_-1]:0)===0},j=p/2;for(let b=0;j-b>=v;b+=2)for(const _ of b===0?[j]:[j-b,j+b])if(x(_))return _/p;return null}function cY(e){return(e%360+360)%360}function uY(e){const t=n=>e.filter(n).length;return{paired:t(n=>n.kind==="paired"),online:t(n=>n.kind==="paired"&&n.here),offline:t(n=>n.kind==="paired"&&!n.here),nearby:t(n=>n.kind==="nearby"),asks:t(n=>n.kind==="asks"),dialling:t(n=>n.kind==="dialling"),declined:t(n=>n.kind==="declined"),tailnet:t(n=>n.kind!=="declined"&&n.via==="tailscale"),oneWay:t(n=>n.kind==="paired"&&!n.here&&n.state.startsWith("one-way"))}}function dY(e){const t=[];return e.asks&&t.push(e.asks===1?"1 deck wants to pair":`${e.asks} decks want to pair`),e.paired===0?t.push("no paired decks yet"):e.paired===1?t.push(e.online?"1 paired deck, online":"1 paired deck, away"):e.online===e.paired?t.push(`${e.paired} paired decks, all online`):t.push(`${e.online} of ${e.paired} paired decks online`),e.nearby&&t.push(`${e.nearby} nearby, not paired`),e.dialling&&t.push(`${e.dialling} still dialling`),t.join(" · ")}function E0(e,t){switch(e.kind){case"asks":return"wants to pair";case"nearby":return e.state;case"dialling":return YI(e)?`${e.name.slice(e.addr.length)} · dialling`:"dialling";case"declined":return"declined";case"paired":{if(e.here)return t?hY(t):"online";const n=ZI(e);return n?n==="now"?"away · just now":`away · ${n}`:e.state.startsWith("one-way")?"has not called yet":"away"}}}function KI(e){return YI(e)?e.addr:e.name}function YI(e){return e.kind==="dialling"&&!!e.addr&&e.name.startsWith(`${e.addr}:`)}function XI(e){if(e.kind!=="paired")return e.via==="tailscale"?`${e.state}, over Tailscale`:e.state;if(e.here)return e.via==="tailscale"?"online, over Tailscale":"online";const t=ZI(e),n=t?t==="now"?"away · last online just now":`away · last online ${t}`:e.state.startsWith("one-way")?e.state:"away";return e.via==="tailscale"?`${n}, over Tailscale`:n}function ZI(e){var t;return((t=/last online (.+)$/.exec(e.state))==null?void 0:t[1])??null}function hY(e){return e.trim().split(/\s+/).slice(0,2).join(" ")}function fY(e){var r;if(!e)return[];const t=(e.addrs??[]).map(s=>`${s}:${e.port}`),n=(r=e.tailscale)==null?void 0:r.addr;return n&&!(e.addrs??[]).includes(n)&&t.push(`${n}:${e.port}`),t}function rr(e){let t=e.fp;for(const n of e.twins??[])n.fp<t&&(t=n.fp);return t}function pY(e,t){if(e==null)return t;const n=((t-e)%360+540)%360-180;return e+n}function mY(e,t){if(e.asks)return e.asks===1?"1 deck wants to pair. Answer it in the Local network list, behind this map.":`${e.asks} decks want to pair. Answer them in the Local network list, behind this map.`;if(e.oneWay)return`${e.oneWay} away deck${e.oneWay===1?" only calls":"s only call"} in, and this deck has no address to call ${e.oneWay===1?"it":"them"} on. Add ${e.oneWay===1?"its address":"their addresses"} through Add a deck to reach ${e.oneWay===1?"it":"them"} both ways.`;if(e.dialling)return e.dialling===1?"1 address has never answered. Open it to stop dialling it.":`${e.dialling} addresses have never answered. Open one to stop dialling it.`;if(e.nearby){const n=e.nearby===1?"1 deck nearby is not paired.":`${e.nearby} decks nearby are not paired.`;return t==="invite"?`${n} ${JI}`:e.nearby===1?`${n} Open it to ask to pair.`:`${n} Open one to ask to pair.`}return null}const JI="This deck pairs by invite only. Send one from Add a deck.";function gY(e,t){switch(e.kind){case"asks":return"Waiting for your answer, in the Local network list behind this map.";case"dialling":return"Nothing has answered here yet. Its dialog can stop dialling it.";case"nearby":return t==="invite"?JI:"Not paired yet. Its dialog can ask to pair.";case"paired":return!e.here&&e.state.startsWith("one-way")?"It can reach this deck, not the other way. Add its address through Add a deck.":null;default:return null}}function yY(e){const t={bad:0,wait:1,idle:2,ok:3};return e.map((n,r)=>({l:n,i:r})).sort((n,r)=>t[n.l.tone]-t[r.l.tone]||n.i-r.i).map(({l:n})=>n)}function wY(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 o=Number(n[s])-Number(r[s]);if(o)return Math.sign(o)}return 0}function vY(e,t){const n=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:n,note:null,tone:"idle"};if(!e.alive){const r=t&&!t.alive?"neither copy works — sign in again here":null;return{there:"broken there",here:n,note:r,tone:r?"bad":"idle"}}return t?t.alive?{there:"works there",here:n,note:null,tone:t.shareable===!1?"idle":"ok"}:{there:"works there",here:n,note:"repairs next round",tone:"wait"}:{there:"works there",here:n,note:"arrives next round",tone:"wait"}}function xY(e,t,n,r=null){var d;const s=new Map;for(const h of t)(d=s.get(h.key))!=null&&d.alive||s.set(h.key,h);const o=new Set(n),l=[],c=new Set;for(const h of e??[]){if(c.has(h.key))continue;c.add(h.key);const f=s.get(h.key)??null,p=o.has(h.key),g=vY(h,f),v=f?f.alive?f.shareable===!1?"unavailable":"works":"expired":"missing",N=!h.alive&&f&&!f.alive?g.note:[v==="works"?null:g.here,h.alive&&h.shareable!==!1?null:g.there,g.note].filter(Boolean).join(" · ")||null;l.push({key:h.key,email:h.email,here:v,there:h.alive?h.shareable===!1?"unavailable":"works":"broken",in:!h.alive||h.shareable===!1?"cut":g.tone==="wait"?"wait":"live",out:p&&f?f.alive&&f.shareable!==!1?"live":"cut":null,caption:N,tone:g.tone,usedThere:r===h.key})}for(const h of n){const f=s.get(h);!f||c.has(h)||(c.add(h),l.push({key:h,email:f.email,here:f.alive?f.shareable===!1?"unavailable":"works":"expired",there:"unknown",in:null,out:f.alive&&f.shareable!==!1?"live":"cut",caption:f.alive?f.shareable===!1?"cannot share here":null:"expired here",tone:f.alive?f.shareable===!1?"idle":"ok":"bad",usedThere:!1}))}return l}const bY=1e3;function kY(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),r=Fr(e,t);return`${n} · ${r==="now"?"just now":r}`}function ib(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}const QI={works:"works here",expired:"expired here",missing:"not on this deck",unavailable:"cannot share here"},eO={works:"works there",broken:"broken there",unavailable:"cannot share there",unknown:"not offered by that deck"};function tO(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${QI[e.here]}, ${eO[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function nO({row:e,source:t,status:n,accounts:r,now:s}){var V,X,Y,Z,ee;const{peer:o,stranger:l}=t,c=e.kind==="paired",d=e.self??e.name,h=e.kind!=="dialling",f=e.kind==="dialling"?null:e.fp,p=o?o.addr?`${o.addr}:${o.port}`:"":l?l.port?`${l.addr}:${l.port}`:l.addr:e.addr,g=(o==null?void 0:o.about)??null,v=((V=n.about)==null?void 0:V.version)??null,N=c?o!=null&&o.waiting?o.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":o!=null&&o.offers?"not said — it runs an older version":"not reached yet":"shown once paired",k=ib(n.about),x=ib(g),j=g!=null&&g.version&&v?wY(g.version,v):null,b=o?fh(o.last,s):null,_=o&&((X=o.last)!=null&&X.error)?OG({error:o.last.error,host:o.addr,port:o.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(ne=>!ne.manual&&ne.addr).map(ne=>({fp:ne.fp,name:ne.name,addr:ne.addr,port:ne.port,at:ne.lastSeen??0}))],s):null,E=(Y=o==null?void 0:o.last)!=null&&Y.error&&b&&b.text!==o.last.error?o.last.error:null,R=((Z=o==null?void 0:o.last)==null?void 0:Z.done)??[],C=!!b&&!!E&&!e.quiet&&e.state.startsWith(b.text),A=c||e.kind==="dialling",U=((o==null?void 0:o.via)??e.via)==="tailscale",L=o?o.waiting?null:o.manual?U?"added by its Tailscale address":"added by address":U?"over Tailscale":"on this network":e.kind==="nearby"?U?"heard over Tailscale":"heard on this network":U?"asked this deck to pair, over Tailscale":"asked this deck to pair",F=e.tone==="bad"?"bad":c?e.here?"up":"down":"loose",O=(o==null?void 0:o.offers)??null,I=F==="up"?(O==null?void 0:O.current)??null:null,B=I&&"key"in I?I.key:null,M=!!I&&"hidden"in I,$=!!I&&"other"in I,P=c?xY((O==null?void 0:O.accounts)??null,r,n.shared??[],B):[],G=P.filter(ne=>ne.in==null&&ne.out==="cut"),K=P.some(ne=>ne.in!=null),q=P.some(ne=>ne.out!=null),H=new Map(R.map(ne=>[ne.email,ne])),D=R.filter(ne=>!P.some(se=>se.email===ne.email)),W=c?O?O.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:o!=null&&o.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.":(ee=o==null?void 0:o.last)!=null&&ee.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,J=O&&(o!=null&&o.last)&&o.last.at-O.at>bY?Fr(O.at,s):null;return{peer:o,stranger:l,paired:c,own:d,canRename:h,fp:f,where:p,about:g,unsaid:N,hereRuns:k,thereRuns:x,order:j,line:b,silence:_,raw:E,echoed:C,showRound:A,how:L,link:F,hiddenThere:M,otherThere:$,lanes:P,spent:G,taking:K,giving:q,told:H,unplaced:D,unknown:W,stale:J}}function lb(){return a.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:[a.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),a.jsx("path",{d:"M1 13h14"})]})}function Hu({dir:e}){return a.jsx("svg",{className:"lan-chev","data-dir":e,width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:a.jsx("path",{d:e==="out"?"M2.8 1L6 4 2.8 7":"M5.2 1L2 4l3.2 3"})})}function NY({view:e,row:t,status:n,asking:r,drawn:s,onSettings:o}){const{peer:l,paired:c,where:d,about:h,unsaid:f,hereRuns:p,thereRuns:g,order:v,line:N,silence:k,raw:x,echoed:j,showRound:b,how:_,link:E,hiddenThere:R,otherThere:C,lanes:A,spent:U,taking:L,giving:F,told:O,unplaced:I,unknown:B,stale:M}=e;return a.jsxs("div",{className:"lan-map","data-link":E,"data-asking":r||void 0,"data-bus":A.length>0||void 0,children:[a.jsxs("div",{className:"lan-ends",children:[a.jsxs("p",{className:"lan-end",children:[a.jsx("span",{className:"lan-end-name",children:"This deck"}),p&&a.jsx("span",{className:"lan-end-runs",children:p}),c&&n.shareActive===!1&&a.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),a.jsxs("p",{className:"lan-end","data-side":"there",children:[a.jsx("span",{className:"lan-end-name",children:t.name}),t.kind!=="dialling"&&a.jsxs("span",{className:"lan-end-runs",children:[g??(h?"not said":f),v?` · ${v<0?"older":"newer"}`:null]}),R&&a.jsx("span",{className:"lan-end-note",children:"current account hidden"}),C&&a.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),a.jsxs("div",{className:"lan-link",children:[a.jsx(lb,{}),a.jsxs("span",{className:"lan-span",children:[a.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[a.jsx("i",{className:"lan-glint","data-dir":"out"}),a.jsx("i",{className:"lan-glint","data-dir":"in"})]}),a.jsx("span",{className:"lan-link-label",children:d?a.jsx("code",{className:"ap-lan-code",children:d}):"none here — it calls this deck"})]}),a.jsx(lb,{}),(d&&_||b)&&a.jsxs("p",{className:"lan-link-sub",children:[d&&_,d&&_&&b&&" · ",b&&(N?j?a.jsx("code",{className:"ap-lan-code",children:x}):a.jsx("span",{className:"lan-round","data-tone":N.tone,children:N.text.replace(/ · now$/," · just now")}):"not asked yet"),b&&x&&!j&&a.jsx("code",{className:"lan-fact-raw",children:x})]}),I.length>0&&a.jsx("ul",{className:"lan-done",children:I.map($=>{const P=eb($);return a.jsxs("li",{"data-ok":$.ok&&!P,children:[$.email," ",a.jsxs("span",{className:"lan-done-what",children:[$.ok?"arrived":"did not arrive",P&&` — ${P.long}`]})]},`${$.email}:${$.action}`)})}),k&&a.jsx("p",{className:"lan-note lan-link-note",children:k}),(l==null?void 0:l.waiting)&&a.jsx("p",{className:"lan-note lan-link-note",children:t.hint}),(N==null?void 0:N.hint)&&a.jsx("p",{className:"lan-note lan-link-note",children:N.hint})]}),A.length>0&&a.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${t.name}`,children:A.map(($,P)=>{const G=O.get($.email),K=G?eb(G):null,q=$.out==="live"||$.in!=null&&$.in!=="cut";return a.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":$.tone,"data-draw":$.in&&$.out?"both":$.in?"in":"out","data-used-there":$.usedThere||void 0,style:{"--i":P},children:[a.jsx("i",{className:"lan-pip","data-end":"here","data-state":$.here,"aria-hidden":!0}),a.jsxs("span",{className:"lan-track",children:[a.jsxs("span",{className:"lan-wire","data-flow":q?"live":"cut","aria-hidden":!0,children:[($.in==="live"||$.in==="wait")&&a.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":$.in}),$.out==="live"&&a.jsx("i",{className:"lan-glint","data-dir":"out"})]}),$.in&&$.in!=="cut"&&a.jsx(Hu,{dir:"in"}),$.out==="live"&&a.jsx(Hu,{dir:"out"}),a.jsx("span",{className:"lan-lane-email",children:$.email})]}),a.jsx("i",{className:"lan-pip","data-end":"there","data-state":$.there,"aria-hidden":!0}),a.jsx("span",{className:"vis-hidden",children:tO($)}),($.caption||G)&&a.jsxs("span",{className:"lan-lane-note",children:[$.caption,$.caption&&G&&" · ",G&&a.jsxs("span",{className:"lan-lane-done","data-ok":G.ok&&!K,children:[G.ok?"arrived last round":"did not arrive last round",K&&` — ${K.long}`]})]})]},$.key)})},s),c&&a.jsxs(a.Fragment,{children:[U.length>0&&a.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",U.length===1?U[0].email:"the expired ones"," until you sign in again here."]}),B&&a.jsx("p",{className:"lan-empty",children:B}),M&&a.jsxs("p",{className:"lan-stale",children:["As of ",M==="now"?"just now":M,", when it last answered."]}),a.jsxs("div",{className:"lan-legend",children:[L&&a.jsxs("span",{className:"lan-key",children:[a.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:a.jsx(Hu,{dir:"in"})}),"from ",t.name]}),F?a.jsxs("span",{className:"lan-key",children:[a.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:a.jsx(Hu,{dir:"out"})}),"from this deck, to every paired deck"]}):a.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),a.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:o,"aria-label":"Change what this deck offers",children:"change"})]})]})]})}const jY=20,SY=17,e_=34,_Y=160,EY=80,TY=200,CY=8,AY=14,RY=10,MY=.61803398875;function $Y({status:e,rows:t,accounts:n,now:r,covered:s,onOpenDeck:o,onClose:l}){const c=y.useRef(null),d=ut(l,{focusRef:c}),h=gt(l),f=y.useRef(null),[p,g]=y.useState(null),[v,N]=y.useState(!1),k=y.useRef(null);y.useLayoutEffect(()=>{const ae=f.current;if(!ae)return;let fe=null;const me=()=>{const ge=Math.round(ae.clientWidth),ue=Math.round(ae.clientHeight);fe&&fe.w===ge&&fe.h===ue||(fe&&(N(!0),k.current!=null&&window.clearTimeout(k.current),k.current=window.setTimeout(()=>N(!1),TY)),fe={w:ge,h:ue},g(fe))};if(me(),typeof ResizeObserver>"u")return;const he=new ResizeObserver(me);return he.observe(ae),()=>{he.disconnect(),k.current!=null&&window.clearTimeout(k.current)}},[]);const x=y.useMemo(()=>p?lY(t,p.w,p.h,(e==null?void 0:e.name)??"",ae=>{var fe,me;return E0(ae,(me=(fe=ec(e,ae).peer)==null?void 0:fe.about)==null?void 0:me.os)}):null,[t,p,e]),j=y.useMemo(()=>uY(t),[t]),b=(x==null?void 0:x.nodes)??[],_=y.useRef(new Map),E=y.useMemo(()=>{const ae=new Map;for(const fe of b){const me=rr(fe.row);ae.set(me,pY(_.current.get(me),fe.angle))}return _.current=ae,ae},[b]),[R,C]=y.useState(null),[A,U]=y.useState(null),[L,F]=y.useState("none"),O=y.useRef(null),I=y.useCallback((ae,fe)=>{O.current!==ae&&(O.current=ae,F(fe),U(ae))},[]),B=y.useRef(null),M=y.useRef(null),$=y.useCallback(()=>{M.current!=null&&window.clearTimeout(M.current),M.current=null},[]),P=y.useCallback((ae,fe)=>{if(B.current!=null&&window.clearTimeout(B.current),B.current=null,$(),C(ae),fe==="keyboard"){I(ae,"none");return}M.current=window.setTimeout(()=>I(ae,O.current?"swap":"full"),EY)},[I,$]),G=y.useCallback(()=>{B.current!=null&&window.clearTimeout(B.current),$(),B.current=window.setTimeout(()=>C(null),_Y)},[$]);y.useEffect(()=>()=>{B.current!=null&&window.clearTimeout(B.current),$()},[$]);const K=R&&b.some(ae=>rr(ae.row)===R)?R:null,q=A?t.find(ae=>rr(ae)===A)??null:null;y.useEffect(()=>{A&&!q&&I(null,"swap")},[A,q,I]);const[H,D]=y.useState(null),W=y.useRef(new Map),J=b.findIndex(ae=>rr(ae.row)===H),V=J<0?0:J,X=ae=>{var ge;if(b.length===0)return;const fe=ae.key==="ArrowRight"||ae.key==="ArrowDown"?1:ae.key==="ArrowLeft"||ae.key==="ArrowUp"?-1:0,me=ae.key==="Home"?0:ae.key==="End"?b.length-1:fe?(V+fe+b.length)%b.length:null;if(me==null)return;ae.preventDefault();const he=rr(b[me].row);D(he),(ge=W.current.get(he))==null||ge.focus()},[Y,Z]=y.useState(()=>typeof document<"u"&&document.hidden);y.useEffect(()=>{const ae=()=>Z(document.hidden);return document.addEventListener("visibilitychange",ae),()=>document.removeEventListener("visibilitychange",ae)},[]);const ee=(e==null?void 0:e.enabled)===!0,ne=e?ee?dY(j):"Local network is off":"checking…",se=()=>{$(),I(null,"swap"),C(null)},pe=K?b.find(ae=>rr(ae.row)===K)??null:null,ke=()=>{var ae;A&&((ae=W.current.get(A))==null||ae.focus()),se()};return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...h,role:"presentation",children:a.jsxs("div",{ref:d,className:"modal nm-modal",onClick:ae=>ae.stopPropagation(),"data-paused":s||Y||void 0,role:"dialog","aria-modal":"true","aria-labelledby":"nm-title","aria-describedby":"nm-sub",children:[a.jsxs("header",{className:"modal-head nm-head",children:[a.jsxs("div",{className:"nm-heading",children:[a.jsx("h2",{id:"nm-title",className:"modal-title nm-title",children:"Network map"}),a.jsx("p",{id:"nm-sub",className:"nm-sub",children:ne})]}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{ref:c,type:"button",className:"glyph-btn",onClick:l,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("div",{className:"nm-body",children:[a.jsxs("div",{className:"nm-view",children:[a.jsx("div",{ref:f,className:"nm-stage","data-focus":K?"":void 0,"data-focus-via":pe==null?void 0:pe.row.via,"data-dense":(x==null?void 0:x.dense)||void 0,"data-still":v||void 0,onClick:ae=>{ae.target===ae.currentTarget&&se()},children:p&&x&&a.jsxs(a.Fragment,{children:[a.jsx(IY,{layout:x,w:p.w,h:p.h}),b.map(ae=>{const fe=rr(ae.row);return a.jsx(PY,{node:ae,angle:E.get(fe)??ae.angle,lit:K===fe},fe)}),a.jsx(DY,{status:e}),a.jsx("span",{id:"nm-ring-hint",className:"vis-hidden",children:"Arrow keys move between decks. Enter opens the deck's own dialog."}),a.jsx("div",{className:"nm-ring",role:"group","aria-label":`Decks around this deck, ${b.length}`,"aria-describedby":"nm-ring-hint",onKeyDown:X,children:b.map((ae,fe)=>{var he,ge;const me=rr(ae.row);return a.jsx(FY,{node:ae,angle:E.get(me)??ae.angle,os:(ge=(he=ec(e,ae.row).peer)==null?void 0:he.about)==null?void 0:ge.os,lit:K===me,shown:A===me,tabbable:fe===V,register:ue=>{ue?W.current.set(me,ue):W.current.delete(me)},onHold:ue=>{D(me),P(me,ue)},onRelease:G,onOpen:()=>o(ae.row.fp)},me)})}),b.length===0&&a.jsx(BY,{status:e})]})}),a.jsx(qY,{slice:(x==null?void 0:x.zone)!=null})]}),a.jsx("aside",{className:"nm-side","aria-label":"Details",children:q&&e?a.jsx(zY,{row:q,status:e,accounts:n,now:r,entrance:L,onOpen:()=>o(q.fp),onBack:ke},rr(q)):a.jsx(UY,{status:e,summary:j,entrance:L,slice:(x==null?void 0:x.zone)!=null})})]})]})}),document.body)}function rO(){return a.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:[a.jsx("circle",{cx:"7",cy:"7.4",r:"1.8"}),a.jsx("circle",{cx:"2.4",cy:"2.9",r:"1.2"}),a.jsx("circle",{cx:"11.6",cy:"2.9",r:"1.2"}),a.jsx("circle",{cx:"7",cy:"12.4",r:"1.1"}),a.jsx("path",{d:"M5.7 6.1 3.3 3.8M8.3 6.1l2.4-2.3M7 9.2v2.1"})]})}function IY({layout:e,w:t,h:n}){const{zone:r}=e;return a.jsxs("svg",{className:"nm-orbits",width:t,height:n,viewBox:`0 0 ${t} ${n}`,"aria-hidden":!0,children:[r&&a.jsxs(a.Fragment,{children:[a.jsxs("defs",{children:[a.jsx("path",{id:"nm-zone-arc",d:LY(r,t/2,n/2)}),a.jsxs("radialGradient",{id:"nm-zone-fill",gradientUnits:"userSpaceOnUse",cx:t/2,cy:n/2,r:Math.max(r.outer.rx,r.outer.ry),children:[a.jsx("stop",{className:"nm-zone-stop",offset:"0.2","data-at":"in"}),a.jsx("stop",{className:"nm-zone-stop",offset:"0.5","data-at":"mid"}),a.jsx("stop",{className:"nm-zone-stop",offset:"1","data-at":"out"})]})]}),a.jsx("path",{className:"nm-zone",d:OY(r,t/2,n/2),fill:"url(#nm-zone-fill)"}),r.labelAt!=null&&a.jsx("text",{className:"nm-zone-label",children:a.jsx("textPath",{href:"#nm-zone-arc",startOffset:`${(r.labelAt*100).toFixed(2)}%`,textAnchor:"middle",children:GI(r.count)})})]}),e.rings.map((s,o)=>a.jsx("ellipse",{className:"nm-orbit","data-ring":s.ring,"data-folded":e.folded&&s.ring===1||void 0,cx:t/2,cy:n/2,rx:s.rx,ry:s.ry,style:{"--ring":o}},s.ring))]})}function t_(e,t,n,r){const s=r*Math.PI/180;return`${(t+Math.cos(s)*e.rx).toFixed(1)},${(n+Math.sin(s)*e.ry).toFixed(1)}`}function OY(e,t,n){const r=e.to-e.from>180?1:0,s=(j,b)=>{const _=b*Math.PI/180;return[t+Math.cos(_)*j.rx,n+Math.sin(_)*j.ry]},o=(j,b)=>b/((j.rx+j.ry)/2)*(180/Math.PI),l=(j,b,_)=>{const E=Math.hypot(b[0]-j[0],b[1]-j[1])||1,R=Math.min(.5,_/E);return[j[0]+(b[0]-j[0])*R,j[1]+(b[1]-j[1])*R]},c=([j,b])=>`${j.toFixed(1)},${b.toFixed(1)}`,d=RY,h=AY,f=o(e.inner,d),p=o(e.outer,h),g=s(e.inner,e.from),v=s(e.outer,e.from),N=s(e.outer,e.to),k=s(e.inner,e.to),x=j=>`${j.rx.toFixed(1)},${j.ry.toFixed(1)}`;return[`M${c(s(e.inner,e.from+f))}`,`Q${c(g)} ${c(l(g,v,d))}`,`L${c(l(v,g,h))}`,`Q${c(v)} ${c(s(e.outer,e.from+p))}`,`A${x(e.outer)} 0 ${r} 1 ${c(s(e.outer,e.to-p))}`,`Q${c(N)} ${c(l(N,k,h))}`,`L${c(l(k,N,d))}`,`Q${c(k)} ${c(s(e.inner,e.to-f))}`,`A${x(e.inner)} 0 ${r} 0 ${c(s(e.inner,e.from+f))}`,"Z"].join(" ")}function LY(e,t,n){const r={rx:e.outer.rx-Md,ry:e.outer.ry-Md},s=e.to-e.from>180?1:0;return`M${t_(r,t,n,e.to)} A${r.rx.toFixed(1)},${r.ry.toFixed(1)} 0 ${s} 0 ${t_(r,t,n,e.from)}`}function PY({node:e,angle:t,lit:n}){const r=e.row.kind==="paired"&&e.row.here,s=e.order*MY%1*CY;return a.jsx("span",{className:"nm-wire","aria-hidden":!0,"data-tier":e.tier,"data-via":e.row.via,"data-on":n||void 0,style:{"--nm-a":`${t.toFixed(2)}deg`,"--nm-d":`${e.dist.toFixed(1)}px`,"--from":`${e_}px`,"--gap":`${e_+(e.tier==="loose"?SY:jY)}px`,"--i":e.order,"--phase":`${s.toFixed(2)}s`},children:r&&a.jsx("i",{className:"nm-glint"})})}function DY({status:e}){const t=(e==null?void 0:e.enabled)===!0&&e.running;return a.jsxs("div",{className:"nm-core","data-listening":t||void 0,children:[a.jsx("span",{className:"nm-core-orb","aria-hidden":!0}),a.jsxs("span",{className:"nm-core-label",children:[a.jsx("span",{className:"nm-core-name",children:(e==null?void 0:e.name)??"…"}),a.jsx("span",{className:"nm-core-what",children:"this deck"})]})]})}function FY({node:e,angle:t,os:n,lit:r,shown:s,tabbable:o,register:l,onHold:c,onRelease:d,onOpen:h}){const{row:f}=e,p=`nm-d-${WY(rr(f))}`,g=e.angle*Math.PI/180,v=E0(f,n);return a.jsxs("button",{ref:l,type:"button",className:"nm-node",tabIndex:o?0:-1,"data-tier":e.tier,"data-kind":f.kind,"data-side":e.side,"data-via":f.via,"data-on":r||void 0,"data-shown":s||void 0,"aria-label":`${f.name}: ${XI(f)}`,"aria-describedby":e.tier==="online"?p:void 0,style:{"--nm-a":`${t.toFixed(2)}deg`,"--nm-d":`${e.dist.toFixed(1)}px`,"--i":e.order,"--in-x":`${(-Math.cos(g)*14).toFixed(1)}px`,"--in-y":`${(-Math.sin(g)*14).toFixed(1)}px`},onPointerEnter:N=>{N.pointerType==="mouse"&&c("pointer")},onPointerLeave:d,onFocus:N=>c(N.currentTarget.matches(":focus-visible")?"keyboard":"pointer"),onBlur:d,onClick:h,children:[a.jsx("i",{className:"nm-halo","data-tier":e.tier,"aria-hidden":!0}),f.kind==="dialling"?a.jsx("i",{className:"nm-addr-dot","aria-hidden":!0}):a.jsx(lb,{}),e.tier!=="online"&&a.jsx("i",{className:"nm-mark","data-tier":e.tier,"data-kind":f.kind,"aria-hidden":!0}),a.jsxs("span",{className:"nm-label","aria-hidden":!0,children:[a.jsx("span",{className:"nm-name",children:KI(f)}),a.jsx("span",{className:"nm-cap",children:v})]}),e.tier==="online"&&a.jsx("span",{id:p,className:"vis-hidden",children:v})]})}function BY({status:e}){const t=(e==null?void 0:e.enabled)===!0;return a.jsx("p",{className:"nm-empty",children:e?t?"No other deck yet. Decks on one network usually find each other within a minute; one on another network needs its address, through Add a deck in Local network.":"Local network is off, so this deck is not looking for any other.":"Asking this deck about the network…"})}function qY({slice:e}){return a.jsxs("ul",{className:"nm-legend",children:[a.jsxs("li",{children:[a.jsxs("span",{className:"nm-key","aria-hidden":!0,children:[a.jsx("i",{className:"nm-key-wire","data-tier":"online"}),a.jsx("i",{className:"nm-key-mark","data-tier":"online"})]}),"online"]}),a.jsxs("li",{children:[a.jsxs("span",{className:"nm-key","aria-hidden":!0,children:[a.jsx("i",{className:"nm-key-wire","data-tier":"offline"}),a.jsx("i",{className:"nm-key-mark","data-tier":"offline"})]}),"away"]}),a.jsxs("li",{children:[a.jsxs("span",{className:"nm-key","aria-hidden":!0,children:[a.jsx("i",{className:"nm-key-wire","data-tier":"loose"}),a.jsx("i",{className:"nm-key-mark","data-tier":"loose"})]}),"not paired"]}),e&&a.jsxs("li",{children:[a.jsx("i",{className:"nm-key-zone","aria-hidden":!0}),"over Tailscale"]})]})}function sO({facts:e}){return a.jsx("dl",{className:"lan-facts nm-facts",children:e.map(t=>a.jsxs("div",{className:"lan-fact","data-tone":t.quiet?"quiet":void 0,children:[a.jsx("dt",{children:t.label}),a.jsx("dd",{children:t.value})]},t.label))})}function UY({status:e,summary:t,entrance:n,slice:r}){const s=fY(e),o=ib(e==null?void 0:e.about),l=[];o&&l.push({label:"Runs",value:o}),l.push({label:s.length>1?"Addresses":"Address",value:s.length?a.jsx("span",{className:"nm-addrs",children:s.map(h=>a.jsx("code",{className:"ap-lan-code",children:h},h))}):"none yet",quiet:s.length===0}),e!=null&&e.pairingMode&&l.push({label:"Pairing",value:e.pairingMode==="invite"?"by invite only":"asks and answers"});const c=[{key:"online",n:t.online,words:"online",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"online","aria-hidden":!0})},{key:"away",n:t.offline,words:"away",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"offline","aria-hidden":!0})},{key:"asks",n:t.asks,words:"asking to pair",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"loose","data-kind":"asks","aria-hidden":!0})},{key:"nearby",n:t.nearby,words:"nearby, not paired",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"loose","aria-hidden":!0})},{key:"dialling",n:t.dialling,words:"still dialling",mark:a.jsx("i",{className:"nm-key-mark","data-tier":"loose","aria-hidden":!0})},{key:"declined",n:t.declined,words:"declined, not drawn",mark:a.jsx("i",{"aria-hidden":!0})}],d=mY(t,e==null?void 0:e.pairingMode);return a.jsxs("div",{className:"nm-panel","data-view":"network","data-entrance":n,children:[a.jsx("h3",{className:"nm-panel-name",children:(e==null?void 0:e.name)??"…"}),a.jsx("p",{className:"nm-panel-self",children:"this deck, at the centre of the map"}),a.jsx("ul",{className:"nm-counts",children:c.filter(h=>h.n>0).map(h=>a.jsxs("li",{"data-count":h.key,children:[h.mark,a.jsx("span",{className:"nm-count-n",children:h.n}),a.jsx("span",{className:"nm-count-words",children:h.words})]},h.key))}),t.tailnet>0&&a.jsxs("p",{className:"nm-counts-note",children:[t.tailnet," reached over Tailscale",r?" — the shaded slice, lower right":""]}),d&&a.jsx("p",{className:"nm-next",children:d}),a.jsx(sO,{facts:l}),a.jsx("p",{className:"nm-panel-hint",children:"Point at a deck, or reach one with the arrow keys, to see it here. Press it to open its own dialog."})]})}function zY({row:e,status:t,accounts:n,now:r,entrance:s,onOpen:o,onBack:l}){var x;const c=nO({row:e,source:ec(t,e),status:t,accounts:n,now:r}),d=[];c.where&&d.push({label:"Address",value:a.jsx("code",{className:"ap-lan-code",children:c.where})}),c.thereRuns&&d.push({label:"Runs",value:`${c.thereRuns}${c.order?` · ${c.order<0?"older than this deck":"newer than this deck"}`:""}`}),c.hiddenThere&&d.push({label:"Signed in to",value:"not said — its owner hides it",quiet:!0}),c.otherThere&&d.push({label:"Signed in to",value:"an account it does not share",quiet:!0});const h=e.kind==="paired"&&e.here||e.kind==="asks",f=gY(e,t.pairingMode),p=yY(c.lanes),g=p.length,v=p.filter(j=>j.tone==="ok").length,N=g===0?"No shared logins":v===g?`${g} shared login${g===1?", fine":"s, all fine"}`:`${g} shared login${g===1?"":"s"} · ${v} fine`,k=c.unknown&&((x=c.peer)!=null&&x.waiting)&&!c.peer.offers?"Its side is not known until it next calls.":c.unknown;return a.jsxs("div",{className:"nm-panel","data-view":"deck","data-entrance":s,"data-tier":e.kind==="paired"?e.here?"online":"offline":"loose",children:[a.jsxs("button",{type:"button",className:"ap-lan-word nm-back",onClick:l,children:[a.jsx("span",{"aria-hidden":!0,children:"‹ "}),"the whole network"]}),a.jsxs("div",{className:"nm-panel-head",children:[a.jsxs("h3",{className:"nm-panel-name",children:[a.jsx("i",{className:h?"ap-pulse":"ap-dot","data-kind":e.kind,"aria-hidden":!0}),a.jsx("span",{className:"nm-panel-title",children:e.name})]}),a.jsx("button",{type:"button",className:"btn nm-open",onClick:o,"aria-label":`Open ${e.name}`,children:"Open"})]}),e.self&&a.jsxs("p",{className:"nm-panel-self",children:["calls itself ",e.self]}),a.jsx("p",{className:"nm-panel-state","data-kind":e.kind,children:XI(e)}),f&&a.jsx("p",{className:"nm-next",children:f}),d.length>0&&a.jsx(sO,{facts:d}),c.paired&&a.jsxs("section",{className:"nm-logins","aria-label":"Logins the two decks share",children:[a.jsx("p",{className:"nm-logins-title",children:N}),g>0&&a.jsx("ul",{className:"nm-lanes",children:p.map((j,b)=>a.jsxs("li",{className:"nm-lane","data-tone":j.tone,style:{"--k":b},children:[a.jsx("i",{className:"nm-lane-dot","aria-hidden":!0}),a.jsx("span",{className:"nm-lane-email","aria-hidden":!0,children:j.email}),n_(j)&&a.jsx("span",{className:"nm-lane-said","aria-hidden":!0,children:n_(j)}),j.usedThere&&a.jsx("span",{className:"nm-lane-used","aria-hidden":!0,children:"in use there"}),a.jsxs("span",{className:"vis-hidden",children:[j.email,": ",tO(j)]})]},j.key))}),k&&a.jsx("p",{className:"nm-panel-hint",children:k})]})]})}function n_(e){return e.caption?e.caption:e.tone==="ok"?null:`${QI[e.here]} · ${eO[e.there]}`}function WY(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}const HY=6;function VY({anchorId:e,id:t,rows:n,onHold:r,onLet:s}){const o=y.useRef(null),l=n.filter(g=>g.kind==="paired"),c=l.filter(g=>g.here),d=c.slice(0,HY),h=l.length-c.length,f=c.length>d.length?`and ${c.length-d.length} more`:h>0?`${h} not on right now`:null,p=y.useCallback(()=>{const g=o.current,v=document.getElementById(e);if(!g||!v)return;const N=m0(v.getBoundingClientRect(),{width:g.offsetWidth,height:g.offsetHeight},{width:window.innerWidth,height:window.innerHeight});g.style.top=`${N.top}px`,g.style.left=`${N.left}px`,g.style.maxHeight=N.maxHeight==null?"":`${N.maxHeight}px`,g.dataset.side=N.side},[e]);return y.useLayoutEffect(()=>{p()}),y.useEffect(()=>(window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}),[p]),Lt.createPortal(a.jsxs("div",{ref:o,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[a.jsx("p",{className:"ap-peek-title",children:c.length?"On the network now":"Nobody on the network"}),d.length>0&&a.jsx("div",{className:"ap-peek-list",children:d.map(g=>a.jsxs("span",{className:"ap-peek-who",children:[a.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),a.jsxs("span",{children:[g.name,g.via==="tailscale"&&a.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]})]},`${g.kind}:${g.fp}`))}),f&&a.jsx("p",{className:"ap-peek-rest",children:f})]}),document.body)}function GY({entry:e,rows:t,onOpen:n,onMap:r,peek:s,openPeek:o,shutPeek:l,holdPeek:c,dropPeek:d}){return a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{d(),n()},"aria-describedby":s?"ap-lan-peek":void 0,onPointerEnter:h=>{h.pointerType==="mouse"&&o(FI)},onPointerLeave:l,onFocus:h=>{h.target.matches(":focus-visible")&&o(0)},onBlur:l,children:[a.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:[a.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),a.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),a.jsxs("span",{className:"ap-nav-text",children:[a.jsx("span",{className:"ap-nav-name",children:"Local network"}),a.jsxs("span",{className:"ap-nav-state","data-tone":e.tone,children:[e.live&&a.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),e.text]})]}),a.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:a.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),r&&a.jsx("button",{type:"button",className:"ap-lan-map",onClick:()=>{d(),r()},"aria-label":"Show the network map",title:"Network map — every deck this one knows, drawn around it",children:a.jsx(rO,{})}),s&&a.jsx(VY,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:t,onHold:c,onLet:l})]})}function KY({row:e,run:t,onVerb:n,onUnpair:r}){const[s,o]=y.useState(!1),l=y.useRef(0),[c,d]=y.useState(null);return y.useEffect(()=>{if(!s)return;const p=window.setTimeout(()=>o(!1),4e3);return()=>window.clearTimeout(p)},[s]),y.useEffect(()=>{if(!c)return;const p=window.setTimeout(()=>d(null),4e3);return()=>window.clearTimeout(p)},[c]),{armed:s,armedTwin:c,pressOwn:()=>{const p=Date.now(),g=Yl({armedFor:s?e.fp:null,target:e.fp,armedAt:l.current,now:p,gapMs:Kl});if(g==="arm"){o(!0),d(null),l.current=p;return}g!=="ignore"&&(o(!1),t(n))},pressTwin:p=>{if(!r)return;const g=Date.now(),v=Yl({armedFor:c,target:p,armedAt:l.current,now:g,gapMs:Kl});if(v==="arm"){d(p),o(!1),l.current=g;return}v!=="ignore"&&(d(null),t(()=>r(p)))}}}function YY({row:e,paired:t,peer:n,status:r,busy:s,press:o,checkNow:l,armed:c,pressOwn:d,run:h,onVerb:f,onInvite:p}){return a.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&a.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),t&&!(n!=null&&n.waiting)&&a.jsx("button",{type:"button",className:"btn",...o(`check:${e.fp}`),onClick:l,title:"Ask this deck now instead of waiting for the next round",children:s===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&a.jsx("button",{type:"button",className:`btn danger lan-peer-verb${c?" armed":""}`,...o(`unpair:${e.fp}`),onKeyDown:g=>{g.repeat&&g.preventDefault()},onClick:()=>d(),"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:s===`unpair:${e.fp}`?"Unpairing…":c?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&r.pairingMode!=="invite"&&a.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...o(`accept:${e.fp}`),onClick:()=>void h(f),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:s===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&a.jsx("button",{type:"button",className:"btn lan-peer-verb",...o(`drop:${e.fp}`),onClick:()=>void h(f),title:"Stop trying this address. Nothing was ever paired here.",children:s===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&r.pairingMode!=="invite"&&a.jsx("button",{type:"button",className:"btn lan-peer-verb",...o(`allow:${e.fp}`),onClick:()=>void h(f),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:s===`allow:${e.fp}`?"Allowing…":"Let it ask again"}),(e.kind==="nearby"||e.kind==="declined")&&r.pairingMode==="invite"&&p&&a.jsx("button",{type:"button",className:"btn primary lan-peer-verb",onClick:p,title:"This deck pairs only by invite. Make one and send it to whoever is at that machine.",children:"Invite to pair"})]})}function XY({instances:e,now:t,busy:n,press:r,armedTwin:s,pressTwin:o,onUnpair:l}){return a.jsxs("div",{className:"modal-section",children:[a.jsxs("h3",{className:"lan-h",children:[e.length," decks on this machine"]}),a.jsx("ul",{className:"lan-twins",role:"list",children:e.map((c,d)=>{var N,k,x,j;const h=(N=c.peer)!=null&&N.addr?`${c.peer.addr}:${c.peer.port}`:c.row.addr,f=h||c.row.fp,p=(k=c.peer)!=null&&k.pairedAt?Fr(c.peer.pairedAt,t):null,g=[(j=(x=c.peer)==null?void 0:x.about)!=null&&j.version?`runs ${c.peer.about.version}`:null,p?`paired ${p==="now"?"just now":p}`:null,c.row.state].filter(Boolean).join(" · "),v=c.row.fp;return a.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":c.row.tone,children:[a.jsx("i",{className:c.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),h?a.jsx("code",{className:"ap-lan-code lan-twin-at",children:h}):a.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),a.jsx("code",{className:"ap-lan-code lan-twin-fp",children:v}),d>0&&l&&a.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${s===v?" armed":""}`,...r(`unpair:${v}`),onKeyDown:b=>{b.repeat&&b.preventDefault()},onClick:()=>o(v),"aria-label":s===v?`Confirm unpairing ${f}`:`Unpair ${f}`,title:s===v?"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:n===`unpair:${v}`?"unpairing…":s===v?"confirm":"unpair"}),a.jsx("span",{className:"lan-twin-meta",children:d===0?`${g} · shown above`:g})]},v)})})]})}function ZY(){return a.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:[a.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),a.jsx("path",{d:"M8.4 3.6l2 2"})]})}function JY({row:e,source:t,status:n,accounts:r,now:s,busy:o,onClose:l,onRename:c,onCheck:d,onVerb:h,onSettings:f,onInvite:p,twins:g=[],onUnpair:v}){const N=y.useRef(null),k=ut(l,{focusRef:N}),x=gt(l),[j,b]=y.useState(null),[_,E]=y.useState(null),[R,C]=y.useState(!1),[A,U]=y.useState(0),L=y.useRef(null),F=y.useRef(null),O=y.useRef(!0);y.useEffect(()=>()=>{O.current=!1},[]);const I=j!=null;y.useEffect(()=>{var ae;I&&((ae=L.current)==null||ae.select())},[I]);const B=y.useRef(!1);y.useEffect(()=>{var ae,fe;B.current&&!I&&Tn(((ae=document.activeElement)==null?void 0:ae.tagName)??null)&&((fe=F.current)==null||fe.focus()),B.current=I},[I]);const M=ae=>{const fe=ia(o,ae);return{disabled:fe.disabled,"aria-busy":fe.busy}},$=async ae=>{const fe=await ae();return O.current&&E(fe),fe==null},{armed:P,armedTwin:G,pressOwn:K,pressTwin:q}=KY({row:e,run:$,onVerb:h,onUnpair:v}),H=nO({row:e,source:t,status:n,accounts:r,now:s}),{peer:D,stranger:W,paired:J,own:V,canRename:X,fp:Y}=H,Z=o===`check:${e.fp}`,ee=async ae=>{const fe=ae.trim()===V?"":ae;await $(()=>c(fe))&&b(null)},ne=()=>void $(d).then(ae=>{ae&&O.current&&U(fe=>fe+1)}),se=async()=>{if(Y)try{if(await navigator.clipboard.writeText(Y),!O.current)return;C(!0),window.setTimeout(()=>{O.current&&C(!1)},1600)}catch{O.current&&E("Could not copy it — select the fingerprint and copy it by hand.")}},pe=[];J&&(D!=null&&D.pairedAt)?pe.push({label:"Paired",value:kY(D.pairedAt,s),tone:"meta"}):e.kind==="declined"&&W&&pe.push({label:"Paired",value:`no · you said no ${j0(W.at,s)}`,tone:"meta"}),pe.push({label:"Fingerprint",value:Y?a.jsxs("span",{className:"lan-fp",children:[a.jsx("code",{className:"ap-lan-code",children:Y}),a.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void se(),"aria-label":R?"Fingerprint copied":"Copy the fingerprint",children:R?"copied":"copy"})]}):"not known — nothing has answered there",tone:Y?void 0:"quiet"});const ke=g.length?[{row:e,peer:D??null},...g]:[];return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...x,role:"presentation",children:a.jsxs("div",{ref:k,className:"modal lan-peer","data-tone":e.tone,onClick:ae=>ae.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[a.jsxs("header",{className:"modal-head lan-peer-head",children:[a.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),a.jsxs("div",{className:"lan-peer-id",children:[I?a.jsxs("form",{className:"lan-peer-edit",onSubmit:ae=>{ae.preventDefault(),ee(j??"")},children:[a.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),a.jsx("input",{ref:L,className:"ap-manage-input lan-peer-input",value:j??"",maxLength:48,placeholder:V,"aria-label":"Name for this deck, shown on this deck only",onChange:ae=>b(ae.target.value)}),a.jsx("button",{type:"submit",className:"ap-manage-btn",...M(`alias:${e.fp}`),children:"save"}),a.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>b(null),children:"cancel"})]}):a.jsxs("span",{className:"lan-peer-title",children:[a.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),X&&a.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",ref:F,onClick:()=>{E(null),b(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:a.jsx(ZY,{})})]}),a.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&a.jsxs(a.Fragment,{children:["calls itself ",a.jsx("span",{className:"lan-peer-self",children:e.self}),I&&a.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...M(`alias:${e.fp}`),onClick:()=>void ee(""),children:"use this name"}),a.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&a.jsx("span",{"aria-hidden":!0,children:" · "})]}),a.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{ref:N,type:"button",className:"glyph-btn",onClick:l,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body lan-peer-body",children:[_&&a.jsxs("div",{className:"ap-failure",role:"alert",children:[a.jsx("span",{className:"ap-failure-text",children:_}),a.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>E(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),a.jsx(NY,{view:H,row:e,status:n,asking:Z,drawn:A,onSettings:f}),a.jsx("dl",{className:"lan-facts",children:pe.map(ae=>a.jsxs("div",{className:"lan-fact","data-tone":ae.tone,children:[a.jsx("dt",{children:ae.label}),a.jsx("dd",{children:ae.value})]},ae.label))}),ke.length>1&&a.jsx(XY,{instances:ke,now:s,busy:o,press:M,armedTwin:G,pressTwin:q,onUnpair:v})]}),a.jsx(YY,{row:e,paired:J,peer:D,status:n,busy:o,press:M,checkNow:ne,armed:P,pressOwn:K,run:$,onVerb:h,onInvite:p})]})}),document.body)}function is(e,t){const n=y.useRef(!1);return y.useEffect(()=>{var r,s;!e||!n.current||(n.current=!1,Tn(((r=document.activeElement)==null?void 0:r.tagName)??null)&&(typeof t=="function"?t():(s=t.current)==null||s.focus()))},[e]),()=>{n.current=!0}}function QY(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function eX(e,t,n,r){const s=new Set(e??t);return r?s.add(n):s.delete(n),[...s]}function r_(e,t,n){return e==null||n!=null&&!n.ok||QY(e,t)?null:e}function aO({line:e,onDismiss:t,onAnswer:n}){const[r,s]=y.useState(!1),o=y.useRef(!1),l=y.useRef(!0);y.useEffect(()=>(l.current=!0,()=>{l.current=!1}),[]);const c=y.useRef(null),d=y.useRef(null),h=y.useRef(!1);if(y.useEffect(()=>{var p;h.current&&(h.current=!1,e!=null&&e.giveBack||(p=d.current)==null||p.focus())},[e]),!e)return null;const f=async()=>{if(o.current)return;o.current=!0,s(!0);const p=await QG();o.current=!1,l.current&&(s(!1),h.current=document.activeElement===c.current,n(tK(p)))};return a.jsxs("div",{className:e.done?"ap-failure ap-failure-done":"ap-failure",role:"alert",children:[a.jsx("span",{className:"ap-failure-text",children:e.text}),e.giveBack&&a.jsx("button",{ref:c,type:"button",className:"ap-fix ap-give-back","aria-busy":r,onClick:f,title:"Opens macOS's password dialog to make the settings folder yours again",children:r?"waiting for macOS…":"give it back"}),a.jsx("button",{ref:d,type:"button",className:"ap-failure-x",onClick:t,"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]})}function tX(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 Vu="Paused while this deck pairs only by invite. Turn that off above to use it.";function nX({status:e,accounts:t,onClose:n,onChanged:r}){qt("lan-setup");const s=ut(n),o=gt(n),[l,c]=y.useState(null),[d,h]=y.useState(null),[f,p]=y.useState(!1),[g,v]=y.useState(null),N=y.useRef(null),k=q=>{const H=ia(g,q);return{disabled:H.disabled,"aria-busy":H.busy}},x=y.useRef(null),j=y.useRef(!0);y.useEffect(()=>()=>{j.current=!1},[]),y.useEffect(()=>{x.current=r_(x.current,e.shared??[],null)},[e.shared]);const b=y.useCallback(async(q,H,D="write")=>{N.current=D,v(D);try{const J=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:q})})).json().catch(()=>null);return j.current?(J!=null&&J.ok?h(null):h(sr(Tt(H,J),J)),r(),(J==null?void 0:J.ok)===!0):!1}catch{return j.current&&h(sr(Tt(H,null))),!1}finally{N.current=null,j.current&&v(null)}},[r]),_=y.useCallback(async q=>{const H=await b({name:q},"save the name","name");return H&&j.current&&c(D=>D===q?null:D),H},[b]),E=y.useRef(null),R=l!=null&&l!==(e.name??""),C=is(!R,E),A=y.useCallback(async()=>{R&&!await _(l)||n()},[R,l,_,n]),U=async()=>{if(!e.fp)return;const q=await eo(e.fp);if(j.current){if(!q){h(sr("Could not copy it — select the fingerprint and copy it by hand."));return}p(!0),window.setTimeout(()=>{j.current&&p(!1)},1600)}},L=new Set(x.current??e.shared??[]),F=e.autoAsk!==!1,O=e.autoAccept!==!1,I=e.pairingMode==="invite",B=q=>{const H=k(q);return{...H,disabled:H.disabled||I}},M=e.shareActive!==!1,$=e.tailscale??null,P=!!($!=null&&$.on),G=($==null?void 0:$.ask)!==!1,K=($==null?void 0:$.accept)!==!1;return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...o,role:"presentation",children:a.jsxs("div",{ref:s,className:"modal lan-modal",onClick:q=>q.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[a.jsx(aO,{line:d,onDismiss:()=>h(null),onAnswer:q=>{h(q),q.done&&r()}}),a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",children:"Name"}),a.jsxs("div",{className:"ap-lan-row",children:[a.jsx("span",{className:"ap-lan-label",children:"appear as"}),a.jsx("input",{ref:E,className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:l??e.name??"",placeholder:"this machine",onChange:q=>c(q.target.value),onKeyDown:q=>{q.key!=="Enter"||l==null||_(l)}}),R&&a.jsx("button",{type:"button",className:"ap-manage-btn",...k("name"),onClick:()=>{C(),_(l)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),a.jsxs("div",{className:"ap-lan-row",children:[a.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?a.jsxs("span",{className:"lan-fp",children:[a.jsx("code",{className:"ap-lan-code",children:e.fp}),a.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void U(),"aria-label":f?"Fingerprint copied":"Copy this deck's fingerprint",children:f?"copied":"copy"})]}):a.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",children:"Share these accounts"}),a.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&a.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(q=>a.jsxs("label",{className:"ap-lan-pick",title:q.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:[a.jsx("input",{type:"checkbox",checked:L.has(q.key),onChange:H=>{const D=eX(x.current,e.shared??[],q.key,H.target.checked);x.current=D,b({shared:D},H.target.checked?"share that account":"stop sharing that account").then(W=>{x.current===D&&(x.current=r_(D,e.shared??[],{ok:W}))})}}),a.jsx("span",{className:"ap-lan-pick-name",children:q.email}),!q.alive&&a.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},q.key))]}),t.length>0&&a.jsxs("div",{className:"lan-switch",children:[a.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":M,"aria-label":"Show paired decks which of these this deck is using",...k("current"),onClick:()=>void b({shareActive:!M},M?"stop showing which account this deck is using":"show which account this deck is using","current"),title:M?"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:a.jsx("span",{className:"switch-knob"})})]})]}),a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",id:"lan-pairing-h",children:"Pairing"}),a.jsx("div",{className:"lan-switches lan-switches-lead",role:"group","aria-labelledby":"lan-pairing-h",children:a.jsxs("div",{className:"lan-switch",children:[a.jsxs("span",{className:"lan-switch-what",children:["Pair new decks only by invite",I&&a.jsx("span",{id:"lan-invite-only-detail",className:"lan-switch-detail",children:"A new deck needs an invite from Add a deck, the link at the top of Local network. Paired decks stay paired."})]}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":I,"aria-label":"Pair new decks only by invite","aria-describedby":I?"lan-invite-only-detail":void 0,...k("mode"),onKeyDown:q=>{q.repeat&&q.preventDefault()},onClick:()=>void b({pairingMode:I?"automatic":"invite"},I?"let decks pair on their own again":"pair new decks only by invite","mode"),title:I?"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:a.jsx("span",{className:"switch-knob"})})]})}),a.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-auto-h",children:[a.jsxs("p",{className:"lan-sub",id:"lan-auto-h",children:["Automatic pairing",I&&a.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),a.jsxs("div",{className:"lan-switches","data-paused":I||void 0,children:[a.jsxs("div",{className:"lan-switch",children:[a.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":F,"aria-label":"Ask every deck this one finds",...B("ask"),onClick:()=>void b({autoAsk:!F},F?"stop asking automatically":"ask every deck this one finds","ask"),title:I?Vu:F?"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:a.jsx("span",{className:"switch-knob"})})]}),a.jsxs("div",{className:"lan-switch",children:[a.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":O,"aria-label":"Say yes to every deck that asks","data-tone":"warn",...B("accept"),onKeyDown:q=>{q.repeat&&q.preventDefault()},onClick:()=>void b({autoAccept:!O},O?"stop accepting automatically":"accept every deck that asks","accept"),title:I?Vu:O?"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:a.jsx("span",{className:"switch-knob"})})]})]})]})]}),($==null?void 0:$.found)&&a.jsxs("div",{className:"modal-section",children:[a.jsx("h3",{className:"lan-h",children:"Tailscale"}),a.jsxs("div",{className:"lan-switches",children:[a.jsxs("div",{className:"lan-switch",children:[a.jsxs("span",{className:"lan-switch-what",children:["Look for my devices",a.jsx("span",{id:"lan-ts-detail",className:"lan-switch-detail",children:tX($)})]}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":P,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",...k("tailscale"),onClick:()=>void b({tailscale:!P},P?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:P?"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:a.jsx("span",{className:"switch-knob"})})]}),P&&a.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-ts-auto-h",children:[a.jsxs("p",{className:"lan-sub",id:"lan-ts-auto-h",children:["Automatic pairing with my devices",I&&a.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),a.jsxs("div",{className:"lan-switches",children:[a.jsxs("div",{className:"lan-switch","data-paused":I||void 0,children:[a.jsx("span",{className:"lan-switch-what",children:"Ask each device it finds"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":G,"aria-label":"Ask each of my devices it finds over Tailscale",...B("tailscale-ask"),onClick:()=>void b({tailscaleAsk:!G},G?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:I?Vu:G?"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:a.jsx("span",{className:"switch-knob"})})]}),a.jsxs("div",{className:"lan-switch","data-paused":I||void 0,children:[a.jsx("span",{className:"lan-switch-what",children:"Say yes to each device that asks"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":K,"aria-label":"Say yes to my devices when they ask over Tailscale","data-tone":"warn",...B("tailscale-accept"),onKeyDown:q=>{q.repeat&&q.preventDefault()},onClick:()=>void b({tailscaleAccept:!K},K?"stop accepting your devices automatically":"accept your devices automatically","tailscale-accept"),title:I?Vu:K?"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:a.jsx("span",{className:"switch-knob"})})]})]})]})]})]})]}),a.jsxs("footer",{className:"lan-setup-foot",children:[a.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),a.jsx("button",{type:"button",className:"btn primary",...k("name"),onClick:()=>void A(),children:"Done"})]})]})}),document.body)}function rX({on:e,status:t,paired:n,busy:r,pressProps:s,checkNow:o,setAddOpen:l,setSetupOpen:c,setMapOpen:d,onBack:h,closeButton:f}){return a.jsxs("div",{className:"ap-header",children:[a.jsx("button",{type:"button",id:"ap-lan-back",className:"glyph-btn ap-back",onClick:h,"aria-label":"Back to Claude accounts",title:"Back to Claude accounts",children:a.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:a.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),a.jsx("h2",{id:"ap-lan-title",children:"Local network"}),a.jsxs("div",{className:"ap-header-right",children:[e&&a.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>d(!0),"aria-label":"Show the network map",title:"Network map — every deck this one knows, drawn around it",children:a.jsx(rO,{})}),e&&a.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>l("add"),"aria-label":"Add a deck",title:(t==null?void 0:t.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:a.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:[a.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"}),a.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"})]})}),e&&n>0&&a.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...s("check"),onClick:()=>void o(),"aria-label":r==="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:a.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:[a.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),a.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"}),a.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"})]})}),e&&a.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...s("setup"),onClick:()=>c(!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:a.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[a.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),a.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),a.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),f]})]})}function sX({accounts:e,onChanged:t,onNoCopy:n,view:r,onOpen:s,onBack:o,closeButton:l}){const[c,d]=y.useState(!1),[h,f]=y.useState(!1),[p,g]=y.useState(!1),v=ZG(),[N,k]=y.useState(!1),{status:x,manual:j,now:b,busy:_,failure:E,dismissFailure:R,answerGiveBack:C,pressProps:A,load:U,toggle:L,answer:F,dropAddress:O,rename:I,checkOne:B,checkNow:M}=oK(t,()=>d(!0)),{armed:$,pressUnpair:P}=iK(F),[G,K]=y.useState(null),[q,H]=y.useState(!1),D=y.useMemo(()=>e.filter(me=>YG(me.key,x??null,b)).map(me=>me.key).sort().join(`
|
|
93
93
|
`),[e,x,b]);y.useEffect(()=>{n==null||n(D?D.split(`
|
|
94
94
|
`):[])},[D,n]);const W=(x==null?void 0:x.enabled)===!0,J=y.useMemo(()=>FG((x==null?void 0:x.pairingMode)==="invite"&&x?{...x,pending:[]}:x,b),[x,b]),V=G?J.find(me=>{var he;return me.fp===G||((he=me.twins)==null?void 0:he.some(ge=>ge.fp===G))})??null:null;y.useEffect(()=>{G&&x&&!V&&K(null)},[G,x,V]);const{asks:X,rest:Y,live:Z,folded:ee,troubled:ne,shown:se,paired:pe}=KG(J,N),ke=LG(x,b),ae=GG(x,J),fe=a.jsxs(a.Fragment,{children:[h&&x&&a.jsx(CK,{status:x,manual:j,startWith:h==="invite"?"invite":void 0,onClose:()=>f(!1),onChanged:()=>{U(),t()}}),p&&a.jsx(UI,{title:"How Local network works",steps:bK,finish:W?void 0:{label:"Turn it on",act:()=>{g(!1),L()}},onClose:()=>g(!1)}),c&&x&&a.jsx(nX,{status:{...x,manualRows:j},accounts:e,manual:j,onClose:()=>d(!1),onChanged:()=>{U(),t()}}),q&&a.jsx($Y,{status:x,rows:J,accounts:e,now:b,covered:!!V||c||!!h||p,onOpenDeck:K,onClose:()=>H(!1)}),V&&x&&a.jsx(JY,{row:V,source:ec(x,V),status:x,accounts:e,now:b,busy:_,onClose:()=>K(null),onRename:me=>I(V.fp,me),onCheck:()=>B(V.fp),onVerb:()=>{switch(V.kind){case"paired":return F("unpair",V.fp,"unpair that deck");case"nearby":return F("accept",V.fp,"reach that deck");case"declined":return F("allow",V.fp,"let that deck ask again");case"dialling":return O(V.fp);default:return Promise.resolve(null)}},onSettings:()=>{K(null),d(!0)},onInvite:()=>{K(null),f("invite")},twins:(V.twins??[]).map(me=>({row:me,peer:ec(x,me).peer??null})),onUnpair:me=>F("unpair",me,"unpair that deck")})]});return r?a.jsxs("div",{className:"ap-lan-view",children:[a.jsx(rX,{on:W,status:x,paired:pe,busy:_,pressProps:A,checkNow:M,setAddOpen:f,setSetupOpen:d,setMapOpen:H,onBack:o,closeButton:l}),a.jsx("div",{className:"ap-scroll",id:"ap-lan-scroll",children:a.jsxs("div",{className:"ap-lan",children:[a.jsxs("div",{className:"ap-policy",children:[a.jsx("h3",{className:"ap-auto-title",children:"Sync with paired decks"}),a.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":W,"aria-label":"Sync with paired decks",...A("switch"),onClick:()=>void L(),title:W?"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:a.jsx("span",{className:"switch-knob"})})]}),a.jsx(IK,{on:W,status:x}),!W&&a.jsxs("div",{className:"ap-lan-intro-row",children:[a.jsxs("button",{type:"button",className:"ap-lan-intro",onClick:()=>g(!0),title:"Four pictures: what this does, and what to do on each machine",children:[a.jsx(kK,{}),a.jsx("span",{className:"ap-lan-intro-text",children:"Paired machines repair each other's expired logins."}),a.jsx("span",{className:"ap-lan-intro-go",children:"See how it works"})]}),a.jsx(Gl,{film:"localNetwork"})]}),a.jsx("p",{className:`ap-lan-status ${ke.tone}`,role:"status",children:ke.tone==="ok"?"":ke.text}),a.jsx(aO,{line:E,onDismiss:R,onAnswer:C}),W&&a.jsxs(a.Fragment,{children:[X.length>0&&a.jsx(RK,{asks:X,pressProps:A,answer:F}),se.length>0&&a.jsx(MK,{rows:se,pairingMode:x==null?void 0:x.pairingMode,armed:$,pressProps:A,answer:F,dropAddress:O,onUnpair:P,onOpenPeer:K,onInvite:()=>f("invite")}),(Z.length>0&&ee.length>0||W&&pe>0)&&a.jsxs("div",{className:"ap-lan-tail",children:[Z.length>0&&ee.length>0&&a.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":N,onClick:()=>k(me=>!me),title:N?"Show only the decks that are on":`Show the ${ee.length} deck${ee.length===1?"":"s"} that are not responding right now`,children:[a.jsx("span",{className:`ap-lan-chev${N?" open":""}`,"aria-hidden":!0,children:"›"}),N?"fewer":`${ee.length} more`,!N&&ne>0&&a.jsxs("span",{className:"ap-lan-more-bad",children:[" · ",ne," not responding"]})]}),W&&pe>0&&a.jsx("span",{className:"ap-lan-checked",children:PG(x==null?void 0:x.checkedAt,b,_==="check")})]}),Y.length===0&&X.length===0&&!(x!=null&&x.stalled)&&!(x!=null&&x.deaf)&&!(x!=null&&x.lanTunneled)&&a.jsxs(a.Fragment,{children:[a.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."}),a.jsx("button",{type:"button",className:"ap-lan-word ap-lan-how",onClick:()=>g(!0),children:"How it works"}),a.jsx(Gl,{film:"localNetwork"})]})]})]})}),fe]}):a.jsxs("div",{className:"ap-foot",children:[a.jsx(GY,{entry:ae,rows:J,onOpen:s,onMap:W?()=>H(!0):void 0,...v}),a.jsx("p",{className:"vis-hidden",role:"status",children:ke.tone==="ok"?"":ke.text}),fe]})}function aX({anchorId:e,id:t,peers:n,onHold:r,onLet:s}){const o=y.useRef(null),{title:l,shown:c,rest:d}=AG(n),h=y.useCallback(()=>{const f=o.current,p=document.getElementById(e);if(!f||!p)return;const g=m0(p.getBoundingClientRect(),{width:f.offsetWidth,height:f.offsetHeight},{width:window.innerWidth,height:window.innerHeight});f.style.top=`${g.top}px`,f.style.left=`${g.left}px`,f.style.maxHeight=g.maxHeight==null?"":`${g.maxHeight}px`,f.dataset.side=g.side},[e]);return y.useLayoutEffect(()=>{h()}),y.useEffect(()=>(window.addEventListener("scroll",h,!0),window.addEventListener("resize",h),()=>{window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",h)}),[h]),Lt.createPortal(a.jsxs("div",{ref:o,id:t,className:"ap-peek ap-fold-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[a.jsx("p",{className:"ap-peek-title",children:l}),a.jsx("div",{className:"ap-peek-list",children:c.map(f=>a.jsxs("span",{className:"ap-peek-who ap-fold-who",children:[a.jsx("span",{className:"ap-fold-name",children:f.name}),a.jsx("span",{className:"ap-fold-state","data-tone":f.ready?"ok":f.warn?"warn":"idle",children:f.ready?f.headroom==null?"not read yet":`${Math.round(f.headroom)}% free`:f.why})]},f.key))}),d&&a.jsx("p",{className:"ap-peek-rest",children:d})]}),document.body)}function oX({peers:e,strained:t,armed:n,threshold:r,open:s,onToggle:o,order:l,choices:c,onOrder:d,allOpen:h,onToggleAll:f,held:p=!1}){const[g,v]=y.useState(!1),N=y.useRef(0);y.useEffect(()=>()=>window.clearTimeout(N.current),[]),y.useEffect(()=>{s&&(window.clearTimeout(N.current),v(!1))},[s]);const k=E=>{s||(window.clearTimeout(N.current),N.current=window.setTimeout(()=>v(!0),E))},x=()=>{window.clearTimeout(N.current),N.current=window.setTimeout(()=>v(!1),BI)},j=()=>window.clearTimeout(N.current),b=()=>{window.clearTimeout(N.current),v(!1)},_=TG(e,{strained:t&&!s,armed:n,threshold:r});return a.jsxs("div",{className:"ap-rest",children:[a.jsxs("button",{type:"button",id:"ap-rest-entry",className:"ap-nav","aria-expanded":s,"aria-controls":s?"ap-rest-panel":void 0,"aria-describedby":g?"ap-rest-peek":void 0,onClick:()=>{b(),o()},onPointerEnter:E=>{E.pointerType==="mouse"&&k(FI)},onPointerLeave:x,onFocus:E=>{E.target.matches(":focus-visible")&&k(0)},onBlur:x,children:[a.jsxs("span",{className:"ap-nav-text",children:[a.jsx("span",{className:"ap-nav-name",children:"Other accounts"}),a.jsx("span",{className:"ap-nav-state","data-tone":_.tone,children:_.text})]}),a.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:a.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),g&&a.jsx(aX,{anchorId:"ap-rest-entry",id:"ap-rest-peek",peers:e,onHold:j,onLet:x}),s&&a.jsx(iX,{order:l,choices:c,onOrder:d,allOpen:h,onToggleAll:f,held:p})]})}function iX({order:e,choices:t,onOrder:n,allOpen:r,onToggleAll:s,held:o}){var d;const l=y.useRef(null);y.useLayoutEffect(()=>{const h=l.current,f=h==null?void 0:h.parentElement;if(!h||!f)return;const p=()=>f.style.setProperty("--rest-tools-w",`${Math.ceil(h.offsetWidth)}px`);if(p(),typeof ResizeObserver>"u")return;const g=new ResizeObserver(p);return g.observe(h),()=>{g.disconnect(),f.style.removeProperty("--rest-tools-w")}},[]);const c=((d=t.find(h=>h.id===e))==null?void 0:d.label)??"Slot";return a.jsxs("div",{className:"ap-rest-tools",ref:l,children:[a.jsxs("span",{className:"ap-rest-sort",children:[a.jsx("select",{value:e,onChange:h=>n(h.target.value),"aria-label":"Order of the other accounts",title:o?`${c} — held where it was while you are in the list`:c,"data-sorted":e===hh?void 0:"","data-held":o?"":void 0,children:t.map(h=>a.jsx("option",{value:h.id,children:h.label},h.id))}),a.jsx("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:a.jsx("path",{d:"M2.5 3.8 5 6.3l2.5-2.5"})})]}),a.jsx("button",{type:"button",className:"ap-rest-all","aria-label":"Expand every account","aria-pressed":r,"aria-controls":"ap-rest-list",title:r?"Collapse every account":"Expand every account",onClick:s,children:a.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:a.jsx("path",{d:r?"M2 7h10M7 1.5V5M5.2 3.2 7 5l1.8-1.8M7 12.5V9M5.2 10.8 7 9l1.8 1.8":"M2 7h10M7 1.5V5M5.2 3.3 7 1.5l1.8 1.8M7 12.5V9M5.2 10.7 7 12.5l1.8-1.8"})})})]})}async function lX(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const cX=1800;function uX({accounts:e,onClose:t,copyText:n}){qt("share-accounts");const[r,s]=y.useState([]),[o,l]=y.useState(null),[c,d]=y.useState(!1),[h,f]=y.useState(null),[p,g]=y.useState(!1),[v,N]=y.useState(()=>Math.floor(Date.now()/1e3)),k=y.useRef(null),x=y.useRef(!1),j=ut(t,{focusRef:k}),b=gt(t),_=is(o!=null,k),E=is(o==null,k);y.useEffect(()=>{if(!o)return;N(Math.floor(Date.now()/1e3));const P=window.setInterval(()=>N(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval(P)},[o]);const R=uG(e),C=dG(e,r),A=C.length===e.length,U=P=>s(G=>hG(G,P)),L=y.useCallback(async()=>{const P=fG(C);if(!lr(x.current)||!P)return;x.current=!0,d(!0),f(null),g(!1);const G=await lX(P).catch(()=>null);if(x.current=!1,d(!1),!(G!=null&&G.ok)){f(Jo(G,"the share could not be made"));return}l({blob:G.blob,expiresAt:G.expiresAt,shared:G.shared??[],failed:G.failed??[]})},[e,C]),F=o?II(o.expiresAt,v):null,O=(F==null?void 0:F.tone)==="gone",I=(o==null?void 0:o.shared.length)??0,B=O?"This share has expired":I===1?"1 account, ready to paste":`${I} accounts, ready to paste`,M=I===1?"this is the password":`this is ${I} passwords`,$=o?O?B:`${B} — ${M}`:"";return Lt.createPortal(a.jsx("div",{className:"modal-backdrop",...b,role:"presentation",children:a.jsxs("div",{ref:j,className:"modal sa-modal",onClick:P=>P.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Share accounts with another deck",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("h3",{children:"Share accounts"})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body sa-body",children:[a.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:$}),o?a.jsxs("div",{className:"sa-step",children:[a.jsx("h4",{children:B}),a.jsx("code",{className:"ap-share-blob",children:o.blob}),a.jsxs("div",{className:"ap-share-foot",children:[a.jsx("button",{type:"button",className:"ap-manage-btn",ref:k,onClick:async()=>{if(O){E(),_(),l(null),L();return}await n(o.blob)&&(g(!0),window.setTimeout(()=>g(!1),cX))},children:O?"make a new share":p?"copied":`copy ${I===1?"the share":"all "+I}`}),a.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:[a.jsx("span",{className:"ap-share-warn",children:M})," · ",a.jsx("span",{className:`ap-share-expiry ${F==null?void 0:F.tone}`,children:F==null?void 0:F.text})]})]}),o.failed.length>0&&a.jsxs("div",{className:"sa-failed",role:"alert",children:[a.jsx("p",{className:"sa-failed-head",children:o.failed.length===1?"One account is not in this bundle:":`${o.failed.length} accounts are not in this bundle:`}),a.jsx("ul",{className:"sa-list",children:o.failed.map(P=>{var K;const G=!!(P.email&&((K=P.detail)!=null&&K.includes(P.email)));return a.jsxs("li",{children:[!G&&a.jsx("span",{className:"sa-who",children:P.email||`account ${P.num}`}),a.jsx("span",{className:"sa-why",children:P.detail||"could not be exported"})]},`${P.num}-${P.email}`)})})]}),a.jsx("p",{className:"sa-note",children:O?a.jsx(a.Fragment,{children:"Another deck will refuse this text now. Make a new one — the same accounts are still picked."}):a.jsxs(a.Fragment,{children:["Paste it into the other deck with ",a.jsx("strong",{children:"+"})," → ",a.jsx("strong",{children:"Paste a share"}),". Accounts it already holds are left exactly as they are."]})}),a.jsxs("div",{className:"sa-actions",children:[a.jsx("button",{type:"button",className:"btn",onClick:()=>{E(),l(null),g(!1)},children:"Pick again"}),a.jsx("button",{type:"button",className:"btn primary",onClick:t,children:"Done"})]})]}):e.length===0?a.jsxs("div",{className:"sa-step",children:[a.jsx("h4",{children:"Nothing to share"}),a.jsxs("p",{className:"sa-note",children:["This deck is not holding any accounts right now. Sign one in with ",a.jsx("strong",{children:"+"}),", or wait — the panel is still reading the store."]}),a.jsx("div",{className:"sa-actions",children:a.jsx("button",{type:"button",className:"btn primary",ref:k,onClick:t,children:"Close"})})]}):a.jsxs("div",{className:"sa-step",children:[a.jsxs("h4",{children:["Which accounts go to the other ",kt,"?"]}),a.jsx("p",{className:`sa-count${C.length?"":" empty"}`,children:pG(C.length)}),a.jsx("ul",{className:"sa-list sa-pick",children:R.map(P=>a.jsx("li",{children:a.jsxs("label",{className:"sa-row",children:[a.jsx("input",{type:"checkbox",checked:C.includes(P.num),onChange:()=>U(P.num)}),a.jsx("span",{className:"sa-who",children:P.label}),P.sub&&a.jsx("span",{className:"sa-sub",children:P.sub})]})},P.num))}),h&&a.jsx("p",{className:"aa-err",role:"alert",children:h}),a.jsxs("div",{className:"sa-actions",children:[a.jsx("button",{type:"button",className:"btn",onClick:()=>s(A?e.map(P=>P.num):[]),children:A?"Clear all":"Select all"}),a.jsx("button",{type:"button",className:"btn primary",ref:k,...Dr(c,!C.length),onClick:()=>{_(),L()},children:c?"making the share…":C.length===0?"Share":C.length===1?"Share 1 account":`Share ${C.length} accounts`})]})]})]})]})}),document.body)}function oO(e,t){var n;return!e.disabled&&!((n=wi(e,t))!=null&&n.blocksSwitch)}function dX(e,t,n){return e.map(r=>{const s=wi(r,t,n==null?void 0:n(r));return{key:Lr(r),name:r.alias??r.email??`account ${r.num}`,ready:oO(r,t),why:r.disabled?"held out":s!=null&&s.blocksSwitch?s.text:null,warn:(s==null?void 0:s.tone)==="warn",headroom:w0(r,t)}})}function hX(e,t,n){const r=Number(t),s=e&&(n==null?e.headroom:w0(e,n));return s!=null&&Number.isFinite(r)&&100-s>=r}function fX(e){return(e==null?void 0:e.ok)===!0&&(e.enabled||e.external)}const iO="agent-dag.otherAccountsOrder",lO="agent-dag.otherAccountsOpen";function pX(){const e=Qe(iO);return typeof e=="string"&&e.length>0&&e.length<=64?e:hh}function mX(e){Ze(iO,e)}function gX(){const e=Qe(lO);if(!e)return Zx;try{const t=JSON.parse(e);if(((t==null?void 0:t.mode)==="some"||(t==null?void 0:t.mode)==="all")&&Array.isArray(t.keys)&&t.keys.every(n=>typeof n=="string"))return{mode:t.mode,keys:t.keys.slice(0,200)}}catch{}return Zx}function yX(e){Ze(lO,JSON.stringify({mode:e.mode,keys:e.keys.filter(t=>!t.startsWith("slot:"))}))}function wX(){const[e,t]=y.useState(null),n=y.useRef(null),r=y.useCallback(l=>lh(n.current)?(n.current=l,t(l),!0):!1,[]),s=y.useCallback(()=>{n.current=null,t(null)},[]);return{busy:e,claim:r,release:s,pressProps:(l,c=!1)=>{const d=ia(e,l);return{disabled:d.disabled,"aria-busy":d.busy||c}}}}const vX=8e3,xX=1800,bX=4e3;function kX({claim:e,release:t,load:n,clearFailure:r,rescueFocus:s}){const[o,l]=y.useState(null),c=(o==null?void 0:o.num)??null,d=y.useRef(o);d.current=o;const[h,f]=y.useState(null),[p,g]=y.useState(""),[v,N]=y.useState(null),k=y.useRef(0);y.useEffect(()=>{if(v==null)return;const J=window.setTimeout(()=>N(null),bX);return()=>window.clearTimeout(J)},[v]);const[x,j]=y.useState(null),[b,_]=y.useState(!1),[E,R]=y.useState(null),[C,A]=y.useState(null),U=y.useCallback(async(J,V)=>{if(!e(V))return null;r(),f(null);try{const X=await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J)}),Y=await X.json().catch(()=>null);return Y!=null&&Y.ok||f({text:Jo(Y,"command failed",X.status)}),Y}catch{return f({text:"server unreachable"}),null}finally{t()}},[e,t,r]),L=y.useCallback(()=>{l(null),f(null),N(null),j(null),_(!1)},[]),F=(J,V="first")=>{L(),A(null),l({num:J,view:"menu",start:V})},O=y.useCallback(J=>{var Y,Z;const V=d.current;if(!V||J!=null&&V.num!==J)return;const X=document.getElementById(`ap-menu-${V.num}`);(X!=null&&X.contains(document.activeElement)||Tn(((Y=document.activeElement)==null?void 0:Y.tagName)??null))&&((Z=document.getElementById(`ap-more-${V.num}`))==null||Z.focus()),L()},[L]),I=y.useCallback(J=>f(J),[]),B=(J,V)=>{g(V??""),f(null),l({num:J,view:"rename"})},M=J=>g(J),$=J=>{A(null),f(null),l({num:J,view:"move"})},P=J=>A(J),G=async J=>{var X;_(!1);const V=await U({action:"share",account:J},`share-${J}`);!(V!=null&&V.ok)||((X=d.current)==null?void 0:X.num)!==J||(j({num:J,blob:V.blob,expiresAt:V.expiresAt}),l({num:J,view:"share"}))},K=async J=>{await eo(J)&&(_(!0),window.setTimeout(()=>_(!1),xX))},q=async(J,V)=>{const{commit:X,alias:Y}=kG(p,V);if(X){const Z=await U({action:"alias",account:J,alias:Y},`alias-${J}`);if(await n(!0),!(Z!=null&&Z.ok))return}O(J)},H=async(J,V)=>{var Z,ee,ne;const X=await U({action:"move",account:J,slot:V},`move-${J}`),Y=xG({menuFor:((Z=d.current)==null?void 0:Z.num)??null,shareFor:(x==null?void 0:x.num)??null},J,X);if(await n(!0),Y){if(Y.menuFor!=null){const pe=document.getElementById(`ap-menu-${J}`),ke=document.getElementById(`ap-more-${Y.menuFor}`);ke&&(pe!=null&&pe.contains(document.activeElement)||Tn(((ee=document.activeElement)==null?void 0:ee.tagName)??null))&&ke.focus()}((ne=d.current)==null?void 0:ne.num)===J&&L(),N(Y.confirmRemove),Y.shareFor==null&&(j(null),_(!1)),R(Y.swapNote);const se=Y.swapNote;se&&window.setTimeout(()=>R(pe=>pe===se?null:pe),vX),A(null),s(Y.menuFor)}return X};return{menu:o,menuFor:c,menuError:h,aliasDraft:p,confirmRemove:v,share:x,shareCopied:b,slotDraft:C,swapNote:E,showMenu:F,dropMenu:L,closeMenu:O,sayInMenu:I,startRename:B,typeAlias:M,doAlias:q,startMove:$,pickSlot:P,doSlot:async(J,V,X)=>{if(!X.sends){O(J);return}await H(J,V)},makeShare:G,copyShare:K,pressRemove:J=>{const V=Date.now(),X=Yl({armedFor:v,target:J,armedAt:k.current,now:V,gapMs:Kl});if(X==="arm"){N(J),k.current=V;return}X!=="ignore"&&(N(null),U({action:"remove",account:J},`rm-${J}`).then(Y=>{var Z;n(!0),Y!=null&&Y.ok&&(((Z=d.current)==null?void 0:Z.num)===J&&L(),s(null))}))}}}function NX(e,t){return!e||!t||t.some(n=>n.num===e.num&&n.active)?e:null}function jX({data:e,claim:t,release:n,load:r,sayFailure:s,clearFailure:o,sayInMenu:l,rescueFocus:c}){const[d,h]=y.useState(null),f=y.useCallback(async(g,v,N="panel")=>{if(!t(v))return null;const k=N==="menu"?l:s;k(null);try{const x=await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)}),j=await x.json().catch(()=>null);return j!=null&&j.ok||k({text:Jx(j,"command failed",x.status),raw:Ql(j)}),j}catch{return k({text:"server unreachable"}),null}finally{n()}},[t,n,l,s]);return y.useEffect(()=>{!(e!=null&&e.ok)||!e.accounts||h(g=>NX(g,e.accounts))},[e]),{switched:d,post:f,doSwitch:async(g,v)=>{if(t(`switch-${g}`)){o(),h(null);try{const k=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:g})})).json().catch(()=>null);k!=null&&k.ok?h({num:g,name:v}):s({text:Jx(k,"the switch failed"),raw:Ql(k),row:g}),await r(!0)}catch{s({text:"server unreachable",row:g})}finally{n(),c(g)}}}}}const SX=1800;function _X({auto:e,post:t,load:n}){var N;const[r,s]=y.useState(null),[o,l]=y.useState(!1),c=y.useRef(null),d=y.useRef(null),h=((N=e==null?void 0:e.settings["autoswitch.threshold"])==null?void 0:N.value)??"90",f=r??h,p=SG(f,h);return{threshold:h,thresholdPick:f,thresholdCtl:p,thresholdSaved:o,thresholdRef:c,thresholdSaveRef:d,proposeThreshold:k=>s(k),doThreshold:async(k,x)=>{if(x.sends){const j=await t({action:"setting",key:"autoswitch.threshold",value:k},"threshold");if(await n(!0),!(j!=null&&j.ok))return;s(null)}l(!0),window.setTimeout(()=>{var j;document.activeElement===d.current&&((j=c.current)==null||j.focus()),l(!1)},SX)}}}const EX=Object.freeze({text:"couldn't reach the deck server",reload:!0}),TX=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function s_(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function CX(e){const t=e.find(r=>!r.ok);if(!t)return null;const n=Ql(t.body);return{text:Jx(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function a_(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 cO=15e3,AX=3e4;function RX(e){const[t,n]=y.useState(null),[r,s]=y.useState(null),[o,l]=y.useState(!1),[c,d]=y.useState(null),h=y.useRef(null),f=y.useCallback(async(v=!1)=>{v&&l(!0);const N=new AbortController,k=window.setTimeout(()=>N.abort(),AX);try{const[x,j]=await Promise.all([fetch(`/api/claude-accounts${v?"?refresh=1":""}`,{signal:N.signal}),fetch("/api/cswap-auto",{signal:N.signal})]);if(x.ok){const _=await x.json();n(_),e(_)}j.ok&&s(await j.json());const b=CX([await s_(x),await s_(j)]);d(_=>a_(_,b))}catch{d(x=>a_(x,N.signal.aborted?TX:EX))}finally{window.clearTimeout(k),v&&l(!1)}},[e]);y.useEffect(()=>(f(!0),h.current=window.setInterval(()=>f(!1),cO),()=>{h.current!=null&&window.clearInterval(h.current)}),[f]);const p=y.useCallback(v=>d(v),[]),g=y.useCallback(()=>d(null),[]);return{data:t,auto:r,reloading:o,failure:c,load:f,sayFailure:p,clearFailure:g}}const MX="#ap-rest-entry";function $X(e){return[`#${e}`,MX,...aI(null)]}function IX(e){const t=y.useRef(null),n=s=>{t.current=s.target.id||null},r=s=>{s.target.isConnected&&(t.current=null)};return y.useLayoutEffect(()=>{var o;const s=t.current;if(!(!s||!Tn(((o=document.activeElement)==null?void 0:o.tagName)??null)))for(const l of $X(s)){const c=document.querySelector(l);if(c){c.focus();return}}},[e]),{onFocus:n,onBlur:r}}function OX({onClose:e,leaving:t,onReport:n,onRoster:r}){var Gt,bs,Vr;qt("accounts-panel");const{busy:s,claim:o,release:l,pressProps:c}=wX(),[d,h]=y.useState("accounts"),[f,p]=y.useState(!1),[g,v]=y.useState(null),N=y.useRef(g);N.current=g;const[k,x]=y.useState(!1),[j,b]=y.useState(!1),[_,E]=y.useState([]),[R,C]=y.useState(!1),[A,U]=y.useState(null),[L,F]=y.useState(gX),[O,I]=y.useState(pX),[B,M]=y.useState(null),[$,P]=y.useState(!1),G=y.useRef(r);G.current=r;const K=y.useCallback(ye=>{var Fe;F(Ge=>hV(Ge,ye.accounts)),(Fe=G.current)==null||Fe.call(G,ye)},[]),{data:q,auto:H,reloading:D,failure:W,load:J,sayFailure:V,clearFailure:X}=RX(K),Y=IX(q),Z=y.useCallback(ye=>{window.requestAnimationFrame(()=>{var Fe;if(Tn(((Fe=document.activeElement)==null?void 0:Fe.tagName)??null))for(const Ge of aI(ye)){const rn=document.querySelector(Ge);if(rn){rn.focus();return}}})},[]),ee=kX({claim:o,release:l,load:J,clearFailure:X,rescueFocus:Z}),{menu:ne,menuFor:se,swapNote:pe,showMenu:ke,dropMenu:ae,closeMenu:fe,sayInMenu:me}=ee,{switched:he,post:ge,doSwitch:ue}=jX({data:q,claim:o,release:l,load:J,sayFailure:V,clearFailure:X,sayInMenu:me,rescueFocus:Z}),{threshold:be,thresholdPick:oe,thresholdCtl:je,thresholdSaved:$e,thresholdRef:Oe,thresholdSaveRef:Ue,proposeThreshold:Be,doThreshold:We}=_X({auto:H,post:ge,load:J}),He=hI();y.useEffect(()=>{yX(L)},[L]),y.useEffect(()=>{mX(O)},[O]);const[rt,lt]=y.useState(()=>new Set),Rt=y.useCallback(ye=>lt(new Set(ye)),[]),De=ye=>({noCopyWorksNearby:rt.has(PS([ye])[0].key)}),et=(Gt=q==null?void 0:q.accounts)==null?void 0:Gt.find(ye=>ye.active),Je=et?wi(et,He,De(et)):null,tt=(q==null?void 0:q.accounts)??[],yt=et?tt.filter(ye=>!ye.active):[],Pt=jI(yt),wt=lV(O,yt),st=Xx(iV(yt,wt,ye=>oO(ye,He),He),B),zt=y.useRef(!1),Wt=y.useRef(!1),Dt=y.useRef(!1),Ht=y.useCallback(()=>{!zt.current&&!Wt.current&&!Dt.current&&M(null)},[]),Vt=()=>M(ye=>ye??st.map(Lr)),vs={onPointerEnter:()=>{zt.current=!0,Vt()},onPointerLeave:()=>{zt.current=!1,Ht()},onFocus:ye=>{ye.target.matches(":focus-visible")&&(Wt.current=!0,Vt())},onBlur:ye=>{ye.currentTarget.contains(ye.relatedTarget)||(Wt.current=!1,Ht())}},Cn=se!=null&&yt.some(ye=>ye.num===se)||g!=null&&yt.some(ye=>ye.num===g.num);y.useEffect(()=>{Dt.current=Cn,Cn||Ht()},[Cn,Ht]);const mr=$&&yt.length>0;y.useEffect(()=>{mr||(zt.current=Wt.current=Dt.current=!1,M(null))},[mr]);const zr=y.useRef(!1);y.useEffect(()=>{zr.current&&yt.length===0&&Z(null),zr.current=yt.length>0},[yt.length,Z]);const gr=st.length?tt.filter(ye=>ye.active):tt,Wr=dX(st,He,De),mn=hX(et,be,He),Hr=fX(H),An=ye=>$&&st.some(Fe=>Fe.num===ye)?"ap-rest-list":"ap-scroll",da=(ye,Fe="first")=>{ke(ye,Fe),v(null)},gn=(ye,Fe)=>{ae(),v(Ge=>(Ge==null?void 0:Ge.anchor)===Fe?null:{num:ye,anchor:Fe})},yr=y.useCallback((ye=!1)=>{var Ge;const Fe=N.current;ye&&Fe&&((Ge=document.getElementById(Fe.anchor))==null||Ge.focus()),v(null)},[]),wr=()=>{ae(),v(null),h("lan")},xt=y.useRef(d);y.useEffect(()=>{xt.current!==d&&(xt.current=d,window.requestAnimationFrame(()=>{var ye;(ye=document.getElementById(d==="lan"?"ap-lan-back":"ap-lan-entry"))==null||ye.focus()}))},[d]),y.useEffect(()=>{q!=null&&q.ok&&p(!0)},[q==null?void 0:q.ok]),y.useEffect(()=>{t&&(ae(),v(null))},[t,ae]),y.useEffect(()=>{ne&&(q!=null&&q.accounts)&&!q.accounts.some(ye=>ye.num===ne.num)&&ae(),g&&(q!=null&&q.accounts)&&!q.accounts.some(ye=>ye.num===g.num)&&v(null)},[q,ne,g,ae]),y.useEffect(()=>{A==null||!(q!=null&&q.accounts)||q.accounts.some(ye=>ye.num===A.num)||(U(null),Z(null))},[q,A,Z]);const xs=a.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:a.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:a.jsx("path",{d:"M3.4 3.4l7.2 7.2M10.6 3.4l-7.2 7.2"})})}),vr=ye=>{const Fe=SI(L,ye),Ge=se===ye.num,rn=(W==null?void 0:W.row)===ye.num?W:null,Gr=(he==null?void 0:he.num)===ye.num,br=(pe==null?void 0:pe.at)===ye.num?pe:null,ha=br?tt.find(Kr=>Kr.num===br.displaced):void 0,Ke=(g==null?void 0:g.anchor)===`ap-issue-${ye.num}`;return a.jsx(mV,{a:ye,nowSec:He,lan:De(ye),opened:Fe,onToggleLanes:()=>F(Kr=>uV(Kr,ye)),busy:s,pressProps:c,onSwitch:ue,menuOpen:Ge,onOpenMenu:da,onCloseMenu:fe,refusal:rn,onDismissRefusal:()=>X(),switchedHere:Gr,swapped:br,displaced:ha,issueExpanded:Ke,onOpenIssue:gn,sortKey:ye.active?null:oV(wt)},ye.num)},xr=q!=null&&q.ok&&(H!=null&&H.ok)?a.jsx(DV,{auto:H,threshold:be,thresholdPick:oe,thresholdCtl:je,thresholdSaved:$e,thresholdRef:Oe,thresholdSaveRef:Ue,proposeThreshold:Be,doThreshold:We,pressProps:c,post:ge,load:J}):null;return a.jsxs("aside",{className:`accounts-panel${t?" leaving":""}`,id:"accounts-panel","aria-label":"Claude accounts",onFocus:Y.onFocus,onBlur:Y.onBlur,children:[d==="accounts"&&a.jsx(yV,{canShare:(((bs=q==null?void 0:q.accounts)==null?void 0:bs.length)??0)>0,canReport:(((Vr=q==null?void 0:q.accounts)==null?void 0:Vr.length)??0)>1||j,onAdd:()=>x(!0),onReport:()=>{E([...gr,...st].map(Lr)),b(!0)},onShareSet:()=>C(!0),onReload:()=>J(!0),pressProps:c,reloading:D,closeButton:xs}),d==="accounts"&&a.jsxs("div",{className:"ap-scroll",id:"ap-scroll",children:[q==null?W?a.jsxs("div",{className:"ap-empty",role:"alert",children:[a.jsx("span",{title:W.raw||void 0,children:W.text}),a.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",cO/1e3," seconds."]}),a.jsx("button",{type:"button",className:"ap-fix",...c("reload",D),onClick:()=>J(!0).then(()=>Z(null)),children:D?"trying…":"try again"})]}):a.jsx("div",{className:"ap-empty",children:"Checking…"}):q.ok?a.jsxs(a.Fragment,{children:[et&&(Je==null?void 0:Je.tone)==="warn"&&a.jsxs("div",{className:"ap-notice",children:[a.jsxs("button",{type:"button",id:"ap-notice",className:"ap-issue","data-tone":"warn","aria-haspopup":"dialog","aria-expanded":(g==null?void 0:g.anchor)==="ap-notice","aria-controls":(g==null?void 0:g.anchor)==="ap-notice"?"ap-issue-pop":void 0,onClick:()=>gn(et.num,"ap-notice"),children:[a.jsx(y0,{}),a.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),Je.fix&&a.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>x(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"Sign in"})]}),a.jsx("ul",{className:"ap-list",children:gr.map(vr)}),st.length>0&&a.jsx(oX,{peers:Wr,strained:mn,armed:Hr,threshold:H!=null&&H.ok?be:null,open:$,onToggle:()=>P(ye=>!ye),order:wt,choices:Pt,onOrder:I,allOpen:_I(L,st),onToggleAll:()=>F(ye=>dV(ye,st)),held:B!=null}),st.length>0&&$&&a.jsxs("div",{className:"ap-rest-panel",id:"ap-rest-panel",children:[a.jsx("ul",{className:"ap-list ap-others",id:"ap-rest-list",...vs,children:st.map(vr)}),xr]}),st.length===0&&xr,W&&W.row==null&&a.jsxs("div",{className:"ap-failure",role:"alert",children:[a.jsx("span",{className:"ap-failure-text",title:W.raw||void 0,children:W.text}),a.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>X(),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),ne&&(()=>{var Fe;const ye=(Fe=q.accounts)==null?void 0:Fe.find(Ge=>Ge.num===ne.num);return ye?a.jsx(_G,{a:ye,accountMenu:ee,slots:(q.accounts??[]).map(Ge=>Ge.num),boundaryId:An(ye.num),nowSec:He,busy:s,pressProps:c,rotating:!!(H!=null&&H.enabled||H!=null&&H.external),onProjects:()=>{U({num:ye.num,name:ye.alias??ye.email??`account ${ye.num}`}),fe(ye.num)},onRotation:()=>ge({action:"account",account:ye.num,enabled:ye.disabled},`rot-${ye.num}`,"menu").then(Ge=>{J(!0),Ge!=null&&Ge.ok&&fe(ye.num)})}):null})(),g&&(()=>{var Ge;const ye=(Ge=q.accounts)==null?void 0:Ge.find(rn=>rn.num===g.num),Fe=ye?wi(ye,He,De(ye)):null;return!ye||!Fe?null:a.jsx(Z9,{anchorId:g.anchor,boundaryId:g.anchor==="ap-notice"?"ap-scroll":An(ye.num),issue:Fe,who:ye.alias??ye.email??`account ${ye.num}`,fetchedAt:ye.fetchedAt,nowSec:He,onClose:yr,onSignIn:()=>x(!0),onReport:n&&(()=>n({initialKind:Fe.tone==="warn"?"bug":"other",initialBody:`Account issue: ${Fe.text}. ${Fe.hint}`}))})})()]}):a.jsx(gV,{data:q}),a.jsx("div",{className:"film-foot",children:a.jsx(Gl,{film:"claudeAccounts"})})]}),a.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:he?`Now active: ${he.name}`:""}),f&&a.jsx(sX,{accounts:PS((q==null?void 0:q.accounts)??[]),onChanged:()=>J(!0),onNoCopy:Rt,view:d==="lan",onOpen:wr,onBack:()=>h("accounts"),closeButton:xs}),k&&a.jsx(OI,{onClose:()=>x(!1),onChanged:()=>J(!0)}),R&&a.jsx(uX,{accounts:((q==null?void 0:q.accounts)??[]).map(ye=>({num:ye.num,email:ye.email,alias:ye.alias,org:ye.org})),onClose:()=>C(!1),copyText:eo}),A!=null&&(()=>{var Fe;const ye=(Fe=q==null?void 0:q.accounts)==null?void 0:Fe.find(Ge=>Ge.num===A.num);return q!=null&&q.accounts&&!ye?null:a.jsx(Y9,{num:A.num,name:ye?ye.alias??ye.email??`account ${ye.num}`:A.name,onClose:()=>U(null)})})(),j&&a.jsx(LV,{accounts:(q==null?void 0:q.accounts)??null,order:_,failed:W!=null&&W.reload?W.text:null,nowSec:He,onClose:()=>b(!1)})]})}const LX=16,PX=120;function DX(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 FX(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 BX(e,t){return DX(e,t,LX)?"over":FX(e,t)<=PX?"near":"far"}function qX(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 UX(){const[e,t]=y.useState(!1),[n,r]=y.useState(""),[s,o]=y.useState("far"),l=y.useRef(null),c=td(e,140),d=y.useCallback(g=>{var k;const v=(k=l.current)==null?void 0:k.getBoundingClientRect(),N=qX(g);return v&&N?BX(N,v):"far"},[]),h=y.useCallback(g=>{g!==null&&(r(g),t(!0)),o("far")},[]),f=y.useCallback(g=>{o(d(g))},[d]),p=y.useCallback((g,v)=>{const N=v&&d(g)==="over";return t(!1),N},[d]);return{trashDragging:e,trashLabel:n,trashState:s,trashZoneRef:l,trashPhase:c,beginTrashDrag:h,trackTrashDrag:f,endTrashDrag:p}}const zX=420;function WX(){const[e,t]=y.useState(!1),n=y.useRef(null),r=y.useCallback(()=>{n.current&&(window.clearTimeout(n.current),n.current=null),t(!1)},[]),s=y.useCallback(o=>{o.length!==0&&queueMicrotask(()=>{t(!0),n.current&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>t(!1),zX+80)})},[]);return y.useEffect(()=>()=>{n.current&&window.clearTimeout(n.current)},[]),{bubbling:e,endBubble:r,onBubble:s}}const T0=11,uO=7.2,dO=6.6,HX={width:104,height:48},o_={width:96,height:44},hO={width:220,height:103};function VX(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)?hO:{width:Math.max(160,t),height:Math.max(72,n)}}function Wp(e,t,n){return e.width*t>=n.width&&e.height*t>=n.height}function GX(e,t,n=hO){if(!Number.isFinite(t)||t<=0)return e??"detail";const r=T0*t;return e==="detail"?r>=dO?"detail":Wp(n,t,o_)?"compact":"overview":r>=uO?"detail":e==="compact"?Wp(n,t,o_)?"compact":"overview":Wp(n,t,HX)?"compact":"overview"}const KX=uO/T0,YX=dO/T0;function XX(e,t){return e>=KX?e:Math.max(e,Math.min(t,YX-.001))}const ZX=.8,JX=1;function QX({stateRef:e,measuredRef:t,measuredVersionRef:n,canvasRef:r}){const[s,o]=y.useState("detail"),l=y.useRef(null),c=y.useRef(null),d=y.useCallback(()=>{var v;const f=n.current;if(((v=c.current)==null?void 0:v.version)===f)return c.current.card;const p=[];for(const N of e.current.agents.keys()){const k=t.current.get(N);k&&p.push(k)}const g=VX(p);return c.current={version:f,card:g},g},[]),h=y.useCallback(f=>{var g;const p=GX(l.current,f,d());return p===l.current?null:(l.current=p,(g=r.current)==null||g.setAttribute("data-lod",p),o(p),p)},[d,r]);return{lod:s,lodRef:l,applyZoom:h}}const eZ=40,tZ=120;function nZ(e,t){let n=null,r=0,s=Number.NEGATIVE_INFINITY;const o=()=>{n=null,s=t.now(),e()},l=()=>{n!=null&&(t.clearTimeout(n),n=null)},c=(d,h,f)=>{if(n!=null){if(r<=d)return;l()}const p=Math.min(f,Math.max(0,d-h));r=d,n=t.setTimeout(o,p)};return{live(d=eZ){const h=t.now(),f=Math.max(s+d,h);if(f<=h){l(),o();return}c(f,h,d)},replay(d=tZ){l(),r=t.now()+d,n=t.setTimeout(o,d)},flush(){l(),o()},cancel(){l()}}}const rZ=1024*1024,i_=5,fO=.8,cb=24,sZ="agent-dag.soundCustom.done",aZ="agent-dag.soundCustom.needs-input",Il={done:sZ,"needs-input":aZ};function tc(e){if(e.kind!=="audio")return e;const{bytes:t,...n}=e;return n}function l_(e){return!e||!/^[a-zA-Z0-9._-]{1,96}$/.test(e)?null:e}function oZ(e){return{done:l_(e(Il.done)),"needs-input":l_(e(Il["needs-input"]))}}function iZ(e,t){return{done:e.done===t?null:e.done,"needs-input":e["needs-input"]===t?null:e["needs-input"]}}function lZ(e){return e.done&&e.done===e["needs-input"]?e.done:null}const cZ={wav:"audio/wav",wave:"audio/wav",mp3:"audio/mpeg",ogg:"audio/ogg",oga:"audio/ogg",webm:"audio/webm",m4a:"audio/mp4",mp4:"audio/mp4"},pO=new Set(["audio/wav","audio/x-wav","audio/mpeg","audio/mp3","audio/ogg","audio/webm","audio/mp4"]);function mO(e,t){const n=t.toLowerCase().split(";")[0].trim();if(pO.has(n))return n;const r=e.toLowerCase().split(".").pop()??"";return cZ[r]??n}function c_(e,t){const n=mO(e.name,e.type);if(!pO.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>rZ)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>i_)return`Audio must be ${i_} seconds or shorter.`}return null}function ub(e){return e>=cb?`There are already ${cb} custom sounds. Delete one first.`:null}function uZ(e,t){const n=e.indexOf(t);return n<0?null:e[n+1]??e[n-1]??null}function dZ(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,fO/t)}function gO(){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 hZ(e,t,n=gO()){var h;const r=((h=e.name)==null?void 0:h.trim())||"Custom sound",s=c_({name:r,type:e.type,size:e.size});if(s)throw new Error(s);const o=await e.arrayBuffer();let l;try{l=await t(o.slice(0))}catch{throw new Error("The audio file could not be decoded.")}const c=c_({name:r,type:e.type,size:e.size},l.duration);if(c)throw new Error(c);const d=Array.from({length:l.numberOfChannels},(f,p)=>l.getChannelData(p));return{id:n,name:r.replace(/\.(wav|wave|mp3|ogg|oga|webm|m4a|mp4)$/i,"")||"Custom sound",kind:"audio",mime:mO(r,e.type),duration:l.duration,normalizationGain:dZ(d),bytes:o}}function fZ(e,t=gO()){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,o=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,o))}}const pZ="ccdeck-notification-audio",mZ=2,dr="assets",Br="summaries";function fc(){return typeof window<"u"?window.ccdeckNotificationAudio??null:null}function gZ(){return new Promise((e,t)=>{const n=indexedDB.open(pZ,mZ);n.onupgradeneeded=r=>{const s=n.result,o=s.objectStoreNames.contains(dr)?n.transaction.objectStore(dr):s.createObjectStore(dr,{keyPath:"id"});if(s.objectStoreNames.contains(Br))return;const l=s.createObjectStore(Br,{keyPath:"id"});if(r.oldVersion<1)return;const c=o.openCursor();c.onsuccess=()=>{const d=c.result;d&&(l.put(tc(d.value)),d.continue())}},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error??new Error("Could not open local audio storage."))})}async function pc(e,t,n){const r=await gZ();try{return await new Promise((s,o)=>{const l=r.transaction(e,t),c=n(l),d=()=>o(l.error??new Error("Local audio storage failed."));l.oncomplete=()=>s(c?c.result:void 0),l.onerror=d,l.onabort=d})}finally{r.close()}}async function yZ(){const e=fc();return e?e.list():typeof indexedDB>"u"?[]:await pc([Br],"readonly",t=>t.objectStore(Br).getAll())??[]}async function wZ(e){const t=fc();return t?t.get(e):typeof indexedDB>"u"?null:await pc([dr],"readonly",n=>n.objectStore(dr).get(e))??null}async function u_(e){const t=fc();if(t){await t.put(e);return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await pc([dr,Br],"readwrite",n=>{n.objectStore(dr).put(e),n.objectStore(Br).put(tc(e))})}async function vZ(e,t){const n=fc();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 pc([dr,Br],"readwrite",r=>{const s=r.objectStore(dr),o=s.get(e);o.onsuccess=()=>{const l=o.result;if(!l)return;const c={...l,name:t};s.put(c),r.objectStore(Br).put(tc(c))}})}async function xZ(e){const t=fc();if(t){await t.remove(e);return}typeof indexedDB>"u"||await pc([dr,Br],"readwrite",n=>{n.objectStore(dr).delete(e),n.objectStore(Br).delete(e)})}const ad=["done","needs-input"],bZ=[{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}]}],kZ=[{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}]}],C0={done:bZ,"needs-input":kZ},jn="two";function db(e,t){const n=C0[e];return n.find(r=>r.id===t)??n.find(r=>r.id===jn)??n[0]}function yO(e,t){return C0[e].some(r=>r.id===t)?t:jn}db("done",jn).notes,db("needs-input",jn).notes;const d_=.04,wO=.24,od=0,$d=100,hb=5,Qa=50;function vi(e){if(!Number.isFinite(e))return Qa;const t=Math.round(e/hb)*hb;return Math.min($d,Math.max(od,t))}function vO(e){if(e==null)return Qa;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?vi(Number(t)):Qa}function A0(e){const t=vi(e),n=d_+(wO-d_)*(t/$d);return Math.round(n*1e4)/1e4}function NZ(e,t){const n=t.trim,r=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(A0(e)*r*1e4)/1e4}const jZ=.012,h_=1e-4;function SZ(e){return Math.min(1,A0(e)/wO)}function _Z(e,t){const n=e*(A0(t)/fO);return Math.max(1e-4,n)}const EZ=160,TZ="agent-dag.soundLevel.done",CZ="agent-dag.soundLevel.needs-input",AZ="agent-dag.soundFigure.done",RZ="agent-dag.soundFigure.needs-input",xO={done:TZ,"needs-input":CZ},Id={done:AZ,"needs-input":RZ},fb={done:{level:Qa,figure:jn},"needs-input":{level:Qa,figure:jn}};function MZ(e){const t=n=>({level:vO(e(xO[n])),figure:yO(n,e(Id[n]))});return{done:t("done"),"needs-input":t("needs-input")}}function $Z(e,t){return(e??fb)[t]??fb[t]}const IZ={Stop:"done",Notification:"needs-input"};function OZ(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:Ot(IZ,n)??null}const LZ=6,PZ="ccdeck-tabs";function DZ(e){return e>=LZ}function FZ(e,t,n){const r=s=>{const o=s.data;(o==null?void 0:o.kind)==="who"&&o.from!==t&&e.postMessage({kind:"here",from:t,to:o.from,streaming:n()})};return e.addEventListener("message",r),{ask(s,o=(l,c)=>setTimeout(l,c)){return new Promise(l=>{const c=new Set,d=h=>{const f=h.data;(f==null?void 0:f.kind)==="here"&&f.to===t&&f.streaming&&c.add(f.from)};e.addEventListener("message",d),e.postMessage({kind:"who",from:t}),o(()=>{e.removeEventListener("message",d),l(c.size)},s)})},leave(){var s;e.removeEventListener("message",r),(s=e.close)==null||s.call(e)}}}function BZ({stateRef:e,rerender:t,pauseGate:n,chimesRef:r,desktopUpdateRef:s}){const[o,l]=y.useState(!1),[c,d]=y.useState(!1),[h,f]=y.useState(!1),p=y.useRef(!0),[g,v]=y.useState(null);return y.useEffect(()=>{const N=new EventSource("/events"),k=nZ(t,{now:()=>Date.now(),setTimeout:(_,E)=>window.setTimeout(_,E),clearTimeout:_=>window.clearTimeout(_)});let x=!1;const j=typeof BroadcastChannel=="function"?FZ(new BroadcastChannel(PZ),Math.random().toString(36).slice(2),()=>x):null,b=window.setInterval(()=>{x||!j||j.ask(600).then(_=>{x||d(DZ(_))})},3e3);return N.addEventListener("open",()=>{l(!0),f(!0)}),N.addEventListener("error",()=>{l(!1),v(null)}),N.addEventListener("open",()=>{x=!0,d(!1)}),N.addEventListener("error",()=>{x=!1}),N.addEventListener("replay-end",()=>{p.current=!1,k.flush(),v(Date.now())}),N.addEventListener("desktop-update",_=>s.current(_.data)),N.addEventListener("hook",_=>{var E;try{const R=JSON.parse(_.data);if(!n.accept(R))return;e.current=h$(e.current,R);const C=R.replay===!0||p.current||Date.now()-R.receivedAt>3e4;C?k.replay():k.live();const A=OZ(R,C);A&&((E=r.current)==null||E.play(A))}catch{}}),()=>{N.close(),k.cancel(),window.clearInterval(b),j==null||j.leave()}},[t]),{live:o,tabCapped:c,everConnected:h,liveSince:g}}const qZ=200,UZ=5*6e4,zZ=6,WZ=2*6e4;function Gu(e,t){if(t.size!==0)for(const n of Array.from(e.keys()))t.has(n)||e.delete(n)}function HZ(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 VZ(e){const t=new Set;for(const n of e)t.add(n.id),t.add(`group:${n.sessionId}`),n.kind==="root"&&t.add(s0(n.id));return t}function GZ(e){const t=new Set;for(const n of e)t.add(n.id),n.kind==="root"&&t.add(s0(n.id));return t}function KZ(e,t){let n=Mq(e,t,Sj);$q(e,t,Sj)&&(n=!0);const r=[],s=o=>{r.push(o)};return Cq(e,t,qZ,UZ,s)&&(n=!0),Aq(e,t,zZ,WZ,s)&&(n=!0),{changed:n,forgotten:r}}function YZ(e,t,n){if(!n)return{ids:new Set([t]),primary:t};const r=new Set(e.ids);if(!r.has(t))return r.add(t),{ids:r,primary:t};if(r.delete(t),e.primary!==t)return{ids:r,primary:e.primary};let s=null;for(const o of r)s=o;return{ids:r,primary:s}}function XZ(e,t){const[n,r]=y.useState(()=>({ids:new Set,primary:null})),{ids:s,primary:o}=n,l=y.useCallback((h,f,p=!f)=>{r(g=>YZ(g,h,f)),!f&&p&&t(!0)},[]),c=y.useCallback(()=>{r({ids:new Set,primary:null})},[]),d=y.useCallback(()=>{r(h=>{const f=HZ(h.ids,e.current.agents),p=h.primary!=null&&!e.current.agents.has(h.primary)?null:h.primary;return f===h.ids&&p===h.primary?h:{ids:f,primary:p}})},[e]);return{selectedIds:s,primarySelectedId:o,selectAgent:l,clearSelection:c,pruneSelectionToBoard:d}}function ZZ({stateRef:e,rerender:t,pruneSelectionToBoard:n,setContextFor:r,setSummaryFor:s}){const[o,l]=y.useState(Date.now());return y.useEffect(()=>{const c=setInterval(()=>{const d=Date.now();l(d);const{changed:h,forgotten:f}=KZ(e.current,d);f.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:f})}).catch(()=>{}),n(),r(p=>p!=null&&!e.current.agents.has(p)?null:p),s(p=>p!=null&&!e.current.agents.has(p)?null:p),h&&t()},250);return()=>clearInterval(c)},[t]),o}function R0(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 Hp,f_;function JZ(){if(f_)return Hp;f_=1;function e(){this.__data__=[],this.size=0}return Hp=e,Hp}var Vp,p_;function Ei(){if(p_)return Vp;p_=1;function e(t,n){return t===n||t!==t&&n!==n}return Vp=e,Vp}var Gp,m_;function yh(){if(m_)return Gp;m_=1;var e=Ei();function t(n,r){for(var s=n.length;s--;)if(e(n[s][0],r))return s;return-1}return Gp=t,Gp}var Kp,g_;function QZ(){if(g_)return Kp;g_=1;var e=yh(),t=Array.prototype,n=t.splice;function r(s){var o=this.__data__,l=e(o,s);if(l<0)return!1;var c=o.length-1;return l==c?o.pop():n.call(o,l,1),--this.size,!0}return Kp=r,Kp}var Yp,y_;function eJ(){if(y_)return Yp;y_=1;var e=yh();function t(n){var r=this.__data__,s=e(r,n);return s<0?void 0:r[s][1]}return Yp=t,Yp}var Xp,w_;function tJ(){if(w_)return Xp;w_=1;var e=yh();function t(n){return e(this.__data__,n)>-1}return Xp=t,Xp}var Zp,v_;function nJ(){if(v_)return Zp;v_=1;var e=yh();function t(n,r){var s=this.__data__,o=e(s,n);return o<0?(++this.size,s.push([n,r])):s[o][1]=r,this}return Zp=t,Zp}var Jp,x_;function wh(){if(x_)return Jp;x_=1;var e=JZ(),t=QZ(),n=eJ(),r=tJ(),s=nJ();function o(l){var c=-1,d=l==null?0:l.length;for(this.clear();++c<d;){var h=l[c];this.set(h[0],h[1])}}return o.prototype.clear=e,o.prototype.delete=t,o.prototype.get=n,o.prototype.has=r,o.prototype.set=s,Jp=o,Jp}var Qp,b_;function rJ(){if(b_)return Qp;b_=1;var e=wh();function t(){this.__data__=new e,this.size=0}return Qp=t,Qp}var em,k_;function sJ(){if(k_)return em;k_=1;function e(t){var n=this.__data__,r=n.delete(t);return this.size=n.size,r}return em=e,em}var tm,N_;function aJ(){if(N_)return tm;N_=1;function e(t){return this.__data__.get(t)}return tm=e,tm}var nm,j_;function oJ(){if(j_)return nm;j_=1;function e(t){return this.__data__.has(t)}return nm=e,nm}var rm,S_;function bO(){if(S_)return rm;S_=1;var e=typeof Nu=="object"&&Nu&&Nu.Object===Object&Νreturn rm=e,rm}var sm,__;function pr(){if(__)return sm;__=1;var e=bO(),t=typeof self=="object"&&self&&self.Object===Object&&self,n=e||t||Function("return this")();return sm=n,sm}var am,E_;function Ti(){if(E_)return am;E_=1;var e=pr(),t=e.Symbol;return am=t,am}var om,T_;function iJ(){if(T_)return om;T_=1;var e=Ti(),t=Object.prototype,n=t.hasOwnProperty,r=t.toString,s=e?e.toStringTag:void 0;function o(l){var c=n.call(l,s),d=l[s];try{l[s]=void 0;var h=!0}catch{}var f=r.call(l);return h&&(c?l[s]=d:delete l[s]),f}return om=o,om}var im,C_;function lJ(){if(C_)return im;C_=1;var e=Object.prototype,t=e.toString;function n(r){return t.call(r)}return im=n,im}var lm,A_;function to(){if(A_)return lm;A_=1;var e=Ti(),t=iJ(),n=lJ(),r="[object Null]",s="[object Undefined]",o=e?e.toStringTag:void 0;function l(c){return c==null?c===void 0?s:r:o&&o in Object(c)?t(c):n(c)}return lm=l,lm}var cm,R_;function Vn(){if(R_)return cm;R_=1;function e(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}return cm=e,cm}var um,M_;function mc(){if(M_)return um;M_=1;var e=to(),t=Vn(),n="[object AsyncFunction]",r="[object Function]",s="[object GeneratorFunction]",o="[object Proxy]";function l(c){if(!t(c))return!1;var d=e(c);return d==r||d==s||d==n||d==o}return um=l,um}var dm,$_;function cJ(){if($_)return dm;$_=1;var e=pr(),t=e["__core-js_shared__"];return dm=t,dm}var hm,I_;function uJ(){if(I_)return hm;I_=1;var e=cJ(),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 hm=n,hm}var fm,O_;function kO(){if(O_)return fm;O_=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 fm=n,fm}var pm,L_;function dJ(){if(L_)return pm;L_=1;var e=mc(),t=uJ(),n=Vn(),r=kO(),s=/[\\^$.*+?()[\]{}|]/g,o=/^\[object .+?Constructor\]$/,l=Function.prototype,c=Object.prototype,d=l.toString,h=c.hasOwnProperty,f=RegExp("^"+d.call(h).replace(s,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function p(g){if(!n(g)||t(g))return!1;var v=e(g)?f:o;return v.test(r(g))}return pm=p,pm}var mm,P_;function hJ(){if(P_)return mm;P_=1;function e(t,n){return t==null?void 0:t[n]}return mm=e,mm}var gm,D_;function no(){if(D_)return gm;D_=1;var e=dJ(),t=hJ();function n(r,s){var o=t(r,s);return e(o)?o:void 0}return gm=n,gm}var ym,F_;function M0(){if(F_)return ym;F_=1;var e=no(),t=pr(),n=e(t,"Map");return ym=n,ym}var wm,B_;function vh(){if(B_)return wm;B_=1;var e=no(),t=e(Object,"create");return wm=t,wm}var vm,q_;function fJ(){if(q_)return vm;q_=1;var e=vh();function t(){this.__data__=e?e(null):{},this.size=0}return vm=t,vm}var xm,U_;function pJ(){if(U_)return xm;U_=1;function e(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}return xm=e,xm}var bm,z_;function mJ(){if(z_)return bm;z_=1;var e=vh(),t="__lodash_hash_undefined__",n=Object.prototype,r=n.hasOwnProperty;function s(o){var l=this.__data__;if(e){var c=l[o];return c===t?void 0:c}return r.call(l,o)?l[o]:void 0}return bm=s,bm}var km,W_;function gJ(){if(W_)return km;W_=1;var e=vh(),t=Object.prototype,n=t.hasOwnProperty;function r(s){var o=this.__data__;return e?o[s]!==void 0:n.call(o,s)}return km=r,km}var Nm,H_;function yJ(){if(H_)return Nm;H_=1;var e=vh(),t="__lodash_hash_undefined__";function n(r,s){var o=this.__data__;return this.size+=this.has(r)?0:1,o[r]=e&&s===void 0?t:s,this}return Nm=n,Nm}var jm,V_;function wJ(){if(V_)return jm;V_=1;var e=fJ(),t=pJ(),n=mJ(),r=gJ(),s=yJ();function o(l){var c=-1,d=l==null?0:l.length;for(this.clear();++c<d;){var h=l[c];this.set(h[0],h[1])}}return o.prototype.clear=e,o.prototype.delete=t,o.prototype.get=n,o.prototype.has=r,o.prototype.set=s,jm=o,jm}var Sm,G_;function vJ(){if(G_)return Sm;G_=1;var e=wJ(),t=wh(),n=M0();function r(){this.size=0,this.__data__={hash:new e,map:new(n||t),string:new e}}return Sm=r,Sm}var _m,K_;function xJ(){if(K_)return _m;K_=1;function e(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}return _m=e,_m}var Em,Y_;function xh(){if(Y_)return Em;Y_=1;var e=xJ();function t(n,r){var s=n.__data__;return e(r)?s[typeof r=="string"?"string":"hash"]:s.map}return Em=t,Em}var Tm,X_;function bJ(){if(X_)return Tm;X_=1;var e=xh();function t(n){var r=e(this,n).delete(n);return this.size-=r?1:0,r}return Tm=t,Tm}var Cm,Z_;function kJ(){if(Z_)return Cm;Z_=1;var e=xh();function t(n){return e(this,n).get(n)}return Cm=t,Cm}var Am,J_;function NJ(){if(J_)return Am;J_=1;var e=xh();function t(n){return e(this,n).has(n)}return Am=t,Am}var Rm,Q_;function jJ(){if(Q_)return Rm;Q_=1;var e=xh();function t(n,r){var s=e(this,n),o=s.size;return s.set(n,r),this.size+=s.size==o?0:1,this}return Rm=t,Rm}var Mm,eE;function $0(){if(eE)return Mm;eE=1;var e=vJ(),t=bJ(),n=kJ(),r=NJ(),s=jJ();function o(l){var c=-1,d=l==null?0:l.length;for(this.clear();++c<d;){var h=l[c];this.set(h[0],h[1])}}return o.prototype.clear=e,o.prototype.delete=t,o.prototype.get=n,o.prototype.has=r,o.prototype.set=s,Mm=o,Mm}var $m,tE;function SJ(){if(tE)return $m;tE=1;var e=wh(),t=M0(),n=$0(),r=200;function s(o,l){var c=this.__data__;if(c instanceof e){var d=c.__data__;if(!t||d.length<r-1)return d.push([o,l]),this.size=++c.size,this;c=this.__data__=new n(d)}return c.set(o,l),this.size=c.size,this}return $m=s,$m}var Im,nE;function bh(){if(nE)return Im;nE=1;var e=wh(),t=rJ(),n=sJ(),r=aJ(),s=oJ(),o=SJ();function l(c){var d=this.__data__=new e(c);this.size=d.size}return l.prototype.clear=t,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=s,l.prototype.set=o,Im=l,Im}var Om,rE;function I0(){if(rE)return Om;rE=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 Om=e,Om}var Lm,sE;function NO(){if(sE)return Lm;sE=1;var e=no(),t=(function(){try{var n=e(Object,"defineProperty");return n({},"",{}),n}catch{}})();return Lm=t,Lm}var Pm,aE;function kh(){if(aE)return Pm;aE=1;var e=NO();function t(n,r,s){r=="__proto__"&&e?e(n,r,{configurable:!0,enumerable:!0,value:s,writable:!0}):n[r]=s}return Pm=t,Pm}var Dm,oE;function Nh(){if(oE)return Dm;oE=1;var e=kh(),t=Ei(),n=Object.prototype,r=n.hasOwnProperty;function s(o,l,c){var d=o[l];(!(r.call(o,l)&&t(d,c))||c===void 0&&!(l in o))&&e(o,l,c)}return Dm=s,Dm}var Fm,iE;function gc(){if(iE)return Fm;iE=1;var e=Nh(),t=kh();function n(r,s,o,l){var c=!o;o||(o={});for(var d=-1,h=s.length;++d<h;){var f=s[d],p=l?l(o[f],r[f],f,o,r):void 0;p===void 0&&(p=r[f]),c?t(o,f,p):e(o,f,p)}return o}return Fm=n,Fm}var Bm,lE;function _J(){if(lE)return Bm;lE=1;function e(t,n){for(var r=-1,s=Array(t);++r<t;)s[r]=n(r);return s}return Bm=e,Bm}var qm,cE;function Ur(){if(cE)return qm;cE=1;function e(t){return t!=null&&typeof t=="object"}return qm=e,qm}var Um,uE;function EJ(){if(uE)return Um;uE=1;var e=to(),t=Ur(),n="[object Arguments]";function r(s){return t(s)&&e(s)==n}return Um=r,Um}var zm,dE;function yc(){if(dE)return zm;dE=1;var e=EJ(),t=Ur(),n=Object.prototype,r=n.hasOwnProperty,s=n.propertyIsEnumerable,o=e((function(){return arguments})())?e:function(l){return t(l)&&r.call(l,"callee")&&!s.call(l,"callee")};return zm=o,zm}var Wm,hE;function jt(){if(hE)return Wm;hE=1;var e=Array.isArray;return Wm=e,Wm}var _l={exports:{}},Hm,fE;function TJ(){if(fE)return Hm;fE=1;function e(){return!1}return Hm=e,Hm}_l.exports;var pE;function Ci(){return pE||(pE=1,(function(e,t){var n=pr(),r=TJ(),s=t&&!t.nodeType&&t,o=s&&!0&&e&&!e.nodeType&&e,l=o&&o.exports===s,c=l?n.Buffer:void 0,d=c?c.isBuffer:void 0,h=d||r;e.exports=h})(_l,_l.exports)),_l.exports}var Vm,mE;function jh(){if(mE)return Vm;mE=1;var e=9007199254740991,t=/^(?:0|[1-9]\d*)$/;function n(r,s){var o=typeof r;return s=s??e,!!s&&(o=="number"||o!="symbol"&&t.test(r))&&r>-1&&r%1==0&&r<s}return Vm=n,Vm}var Gm,gE;function O0(){if(gE)return Gm;gE=1;var e=9007199254740991;function t(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=e}return Gm=t,Gm}var Km,yE;function CJ(){if(yE)return Km;yE=1;var e=to(),t=O0(),n=Ur(),r="[object Arguments]",s="[object Array]",o="[object Boolean]",l="[object Date]",c="[object Error]",d="[object Function]",h="[object Map]",f="[object Number]",p="[object Object]",g="[object RegExp]",v="[object Set]",N="[object String]",k="[object WeakMap]",x="[object ArrayBuffer]",j="[object DataView]",b="[object Float32Array]",_="[object Float64Array]",E="[object Int8Array]",R="[object Int16Array]",C="[object Int32Array]",A="[object Uint8Array]",U="[object Uint8ClampedArray]",L="[object Uint16Array]",F="[object Uint32Array]",O={};O[b]=O[_]=O[E]=O[R]=O[C]=O[A]=O[U]=O[L]=O[F]=!0,O[r]=O[s]=O[x]=O[o]=O[j]=O[l]=O[c]=O[d]=O[h]=O[f]=O[p]=O[g]=O[v]=O[N]=O[k]=!1;function I(B){return n(B)&&t(B.length)&&!!O[e(B)]}return Km=I,Km}var Ym,wE;function Sh(){if(wE)return Ym;wE=1;function e(t){return function(n){return t(n)}}return Ym=e,Ym}var El={exports:{}};El.exports;var vE;function L0(){return vE||(vE=1,(function(e,t){var n=bO(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,o=s&&s.exports===r,l=o&&n.process,c=(function(){try{var d=s&&s.require&&s.require("util").types;return d||l&&l.binding&&l.binding("util")}catch{}})();e.exports=c})(El,El.exports)),El.exports}var Xm,xE;function wc(){if(xE)return Xm;xE=1;var e=CJ(),t=Sh(),n=L0(),r=n&&n.isTypedArray,s=r?t(r):e;return Xm=s,Xm}var Zm,bE;function jO(){if(bE)return Zm;bE=1;var e=_J(),t=yc(),n=jt(),r=Ci(),s=jh(),o=wc(),l=Object.prototype,c=l.hasOwnProperty;function d(h,f){var p=n(h),g=!p&&t(h),v=!p&&!g&&r(h),N=!p&&!g&&!v&&o(h),k=p||g||v||N,x=k?e(h.length,String):[],j=x.length;for(var b in h)(f||c.call(h,b))&&!(k&&(b=="length"||v&&(b=="offset"||b=="parent")||N&&(b=="buffer"||b=="byteLength"||b=="byteOffset")||s(b,j)))&&x.push(b);return x}return Zm=d,Zm}var Jm,kE;function _h(){if(kE)return Jm;kE=1;var e=Object.prototype;function t(n){var r=n&&n.constructor,s=typeof r=="function"&&r.prototype||e;return n===s}return Jm=t,Jm}var Qm,NE;function SO(){if(NE)return Qm;NE=1;function e(t,n){return function(r){return t(n(r))}}return Qm=e,Qm}var eg,jE;function AJ(){if(jE)return eg;jE=1;var e=SO(),t=e(Object.keys,Object);return eg=t,eg}var tg,SE;function P0(){if(SE)return tg;SE=1;var e=_h(),t=AJ(),n=Object.prototype,r=n.hasOwnProperty;function s(o){if(!e(o))return t(o);var l=[];for(var c in Object(o))r.call(o,c)&&c!="constructor"&&l.push(c);return l}return tg=s,tg}var ng,_E;function ys(){if(_E)return ng;_E=1;var e=mc(),t=O0();function n(r){return r!=null&&t(r.length)&&!e(r)}return ng=n,ng}var rg,EE;function ua(){if(EE)return rg;EE=1;var e=jO(),t=P0(),n=ys();function r(s){return n(s)?e(s):t(s)}return rg=r,rg}var sg,TE;function RJ(){if(TE)return sg;TE=1;var e=gc(),t=ua();function n(r,s){return r&&e(s,t(s),r)}return sg=n,sg}var ag,CE;function MJ(){if(CE)return ag;CE=1;function e(t){var n=[];if(t!=null)for(var r in Object(t))n.push(r);return n}return ag=e,ag}var og,AE;function $J(){if(AE)return og;AE=1;var e=Vn(),t=_h(),n=MJ(),r=Object.prototype,s=r.hasOwnProperty;function o(l){if(!e(l))return n(l);var c=t(l),d=[];for(var h in l)h=="constructor"&&(c||!s.call(l,h))||d.push(h);return d}return og=o,og}var ig,RE;function ro(){if(RE)return ig;RE=1;var e=jO(),t=$J(),n=ys();function r(s){return n(s)?e(s,!0):t(s)}return ig=r,ig}var lg,ME;function IJ(){if(ME)return lg;ME=1;var e=gc(),t=ro();function n(r,s){return r&&e(s,t(s),r)}return lg=n,lg}var Tl={exports:{}};Tl.exports;var $E;function _O(){return $E||($E=1,(function(e,t){var n=pr(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,o=s&&s.exports===r,l=o?n.Buffer:void 0,c=l?l.allocUnsafe:void 0;function d(h,f){if(f)return h.slice();var p=h.length,g=c?c(p):new h.constructor(p);return h.copy(g),g}e.exports=d})(Tl,Tl.exports)),Tl.exports}var cg,IE;function EO(){if(IE)return cg;IE=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 cg=e,cg}var ug,OE;function TO(){if(OE)return ug;OE=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,o=0,l=[];++r<s;){var c=t[r];n(c,r,t)&&(l[o++]=c)}return l}return ug=e,ug}var dg,LE;function CO(){if(LE)return dg;LE=1;function e(){return[]}return dg=e,dg}var hg,PE;function D0(){if(PE)return hg;PE=1;var e=TO(),t=CO(),n=Object.prototype,r=n.propertyIsEnumerable,s=Object.getOwnPropertySymbols,o=s?function(l){return l==null?[]:(l=Object(l),e(s(l),function(c){return r.call(l,c)}))}:t;return hg=o,hg}var fg,DE;function OJ(){if(DE)return fg;DE=1;var e=gc(),t=D0();function n(r,s){return e(r,t(r),s)}return fg=n,fg}var pg,FE;function F0(){if(FE)return pg;FE=1;function e(t,n){for(var r=-1,s=n.length,o=t.length;++r<s;)t[o+r]=n[r];return t}return pg=e,pg}var mg,BE;function Eh(){if(BE)return mg;BE=1;var e=SO(),t=e(Object.getPrototypeOf,Object);return mg=t,mg}var gg,qE;function AO(){if(qE)return gg;qE=1;var e=F0(),t=Eh(),n=D0(),r=CO(),s=Object.getOwnPropertySymbols,o=s?function(l){for(var c=[];l;)e(c,n(l)),l=t(l);return c}:r;return gg=o,gg}var yg,UE;function LJ(){if(UE)return yg;UE=1;var e=gc(),t=AO();function n(r,s){return e(r,t(r),s)}return yg=n,yg}var wg,zE;function RO(){if(zE)return wg;zE=1;var e=F0(),t=jt();function n(r,s,o){var l=s(r);return t(r)?l:e(l,o(r))}return wg=n,wg}var vg,WE;function MO(){if(WE)return vg;WE=1;var e=RO(),t=D0(),n=ua();function r(s){return e(s,n,t)}return vg=r,vg}var xg,HE;function PJ(){if(HE)return xg;HE=1;var e=RO(),t=AO(),n=ro();function r(s){return e(s,n,t)}return xg=r,xg}var bg,VE;function DJ(){if(VE)return bg;VE=1;var e=no(),t=pr(),n=e(t,"DataView");return bg=n,bg}var kg,GE;function FJ(){if(GE)return kg;GE=1;var e=no(),t=pr(),n=e(t,"Promise");return kg=n,kg}var Ng,KE;function $O(){if(KE)return Ng;KE=1;var e=no(),t=pr(),n=e(t,"Set");return Ng=n,Ng}var jg,YE;function BJ(){if(YE)return jg;YE=1;var e=no(),t=pr(),n=e(t,"WeakMap");return jg=n,jg}var Sg,XE;function Ai(){if(XE)return Sg;XE=1;var e=DJ(),t=M0(),n=FJ(),r=$O(),s=BJ(),o=to(),l=kO(),c="[object Map]",d="[object Object]",h="[object Promise]",f="[object Set]",p="[object WeakMap]",g="[object DataView]",v=l(e),N=l(t),k=l(n),x=l(r),j=l(s),b=o;return(e&&b(new e(new ArrayBuffer(1)))!=g||t&&b(new t)!=c||n&&b(n.resolve())!=h||r&&b(new r)!=f||s&&b(new s)!=p)&&(b=function(_){var E=o(_),R=E==d?_.constructor:void 0,C=R?l(R):"";if(C)switch(C){case v:return g;case N:return c;case k:return h;case x:return f;case j:return p}return E}),Sg=b,Sg}var _g,ZE;function qJ(){if(ZE)return _g;ZE=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r){var s=r.length,o=new r.constructor(s);return s&&typeof r[0]=="string"&&t.call(r,"index")&&(o.index=r.index,o.input=r.input),o}return _g=n,_g}var Eg,JE;function IO(){if(JE)return Eg;JE=1;var e=pr(),t=e.Uint8Array;return Eg=t,Eg}var Tg,QE;function B0(){if(QE)return Tg;QE=1;var e=IO();function t(n){var r=new n.constructor(n.byteLength);return new e(r).set(new e(n)),r}return Tg=t,Tg}var Cg,eT;function UJ(){if(eT)return Cg;eT=1;var e=B0();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.byteLength)}return Cg=t,Cg}var Ag,tT;function zJ(){if(tT)return Ag;tT=1;var e=/\w*$/;function t(n){var r=new n.constructor(n.source,e.exec(n));return r.lastIndex=n.lastIndex,r}return Ag=t,Ag}var Rg,nT;function WJ(){if(nT)return Rg;nT=1;var e=Ti(),t=e?e.prototype:void 0,n=t?t.valueOf:void 0;function r(s){return n?Object(n.call(s)):{}}return Rg=r,Rg}var Mg,rT;function OO(){if(rT)return Mg;rT=1;var e=B0();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.length)}return Mg=t,Mg}var $g,sT;function HJ(){if(sT)return $g;sT=1;var e=B0(),t=UJ(),n=zJ(),r=WJ(),s=OO(),o="[object Boolean]",l="[object Date]",c="[object Map]",d="[object Number]",h="[object RegExp]",f="[object Set]",p="[object String]",g="[object Symbol]",v="[object ArrayBuffer]",N="[object DataView]",k="[object Float32Array]",x="[object Float64Array]",j="[object Int8Array]",b="[object Int16Array]",_="[object Int32Array]",E="[object Uint8Array]",R="[object Uint8ClampedArray]",C="[object Uint16Array]",A="[object Uint32Array]";function U(L,F,O){var I=L.constructor;switch(F){case v:return e(L);case o:case l:return new I(+L);case N:return t(L,O);case k:case x:case j:case b:case _:case E:case R:case C:case A:return s(L,O);case c:return new I;case d:case p:return new I(L);case h:return n(L);case f:return new I;case g:return r(L)}}return $g=U,$g}var Ig,aT;function LO(){if(aT)return Ig;aT=1;var e=Vn(),t=Object.create,n=(function(){function r(){}return function(s){if(!e(s))return{};if(t)return t(s);r.prototype=s;var o=new r;return r.prototype=void 0,o}})();return Ig=n,Ig}var Og,oT;function PO(){if(oT)return Og;oT=1;var e=LO(),t=Eh(),n=_h();function r(s){return typeof s.constructor=="function"&&!n(s)?e(t(s)):{}}return Og=r,Og}var Lg,iT;function VJ(){if(iT)return Lg;iT=1;var e=Ai(),t=Ur(),n="[object Map]";function r(s){return t(s)&&e(s)==n}return Lg=r,Lg}var Pg,lT;function GJ(){if(lT)return Pg;lT=1;var e=VJ(),t=Sh(),n=L0(),r=n&&n.isMap,s=r?t(r):e;return Pg=s,Pg}var Dg,cT;function KJ(){if(cT)return Dg;cT=1;var e=Ai(),t=Ur(),n="[object Set]";function r(s){return t(s)&&e(s)==n}return Dg=r,Dg}var Fg,uT;function YJ(){if(uT)return Fg;uT=1;var e=KJ(),t=Sh(),n=L0(),r=n&&n.isSet,s=r?t(r):e;return Fg=s,Fg}var Bg,dT;function DO(){if(dT)return Bg;dT=1;var e=bh(),t=I0(),n=Nh(),r=RJ(),s=IJ(),o=_O(),l=EO(),c=OJ(),d=LJ(),h=MO(),f=PJ(),p=Ai(),g=qJ(),v=HJ(),N=PO(),k=jt(),x=Ci(),j=GJ(),b=Vn(),_=YJ(),E=ua(),R=ro(),C=1,A=2,U=4,L="[object Arguments]",F="[object Array]",O="[object Boolean]",I="[object Date]",B="[object Error]",M="[object Function]",$="[object GeneratorFunction]",P="[object Map]",G="[object Number]",K="[object Object]",q="[object RegExp]",H="[object Set]",D="[object String]",W="[object Symbol]",J="[object WeakMap]",V="[object ArrayBuffer]",X="[object DataView]",Y="[object Float32Array]",Z="[object Float64Array]",ee="[object Int8Array]",ne="[object Int16Array]",se="[object Int32Array]",pe="[object Uint8Array]",ke="[object Uint8ClampedArray]",ae="[object Uint16Array]",fe="[object Uint32Array]",me={};me[L]=me[F]=me[V]=me[X]=me[O]=me[I]=me[Y]=me[Z]=me[ee]=me[ne]=me[se]=me[P]=me[G]=me[K]=me[q]=me[H]=me[D]=me[W]=me[pe]=me[ke]=me[ae]=me[fe]=!0,me[B]=me[M]=me[J]=!1;function he(ge,ue,be,oe,je,$e){var Oe,Ue=ue&C,Be=ue&A,We=ue&U;if(be&&(Oe=je?be(ge,oe,je,$e):be(ge)),Oe!==void 0)return Oe;if(!b(ge))return ge;var He=k(ge);if(He){if(Oe=g(ge),!Ue)return l(ge,Oe)}else{var rt=p(ge),lt=rt==M||rt==$;if(x(ge))return o(ge,Ue);if(rt==K||rt==L||lt&&!je){if(Oe=Be||lt?{}:N(ge),!Ue)return Be?d(ge,s(Oe,ge)):c(ge,r(Oe,ge))}else{if(!me[rt])return je?ge:{};Oe=v(ge,rt,Ue)}}$e||($e=new e);var Rt=$e.get(ge);if(Rt)return Rt;$e.set(ge,Oe),_(ge)?ge.forEach(function(Je){Oe.add(he(Je,ue,be,Je,ge,$e))}):j(ge)&&ge.forEach(function(Je,tt){Oe.set(tt,he(Je,ue,be,tt,ge,$e))});var De=We?Be?f:h:Be?R:E,et=He?void 0:De(ge);return t(et||ge,function(Je,tt){et&&(tt=Je,Je=ge[tt]),n(Oe,tt,he(Je,ue,be,tt,ge,$e))}),Oe}return Bg=he,Bg}var qg,hT;function XJ(){if(hT)return qg;hT=1;var e=DO(),t=4;function n(r){return e(r,t)}return qg=n,qg}var Ug,fT;function q0(){if(fT)return Ug;fT=1;function e(t){return function(){return t}}return Ug=e,Ug}var zg,pT;function ZJ(){if(pT)return zg;pT=1;function e(t){return function(n,r,s){for(var o=-1,l=Object(n),c=s(n),d=c.length;d--;){var h=c[t?d:++o];if(r(l[h],h,l)===!1)break}return n}}return zg=e,zg}var Wg,mT;function U0(){if(mT)return Wg;mT=1;var e=ZJ(),t=e();return Wg=t,Wg}var Hg,gT;function z0(){if(gT)return Hg;gT=1;var e=U0(),t=ua();function n(r,s){return r&&e(r,s,t)}return Hg=n,Hg}var Vg,yT;function JJ(){if(yT)return Vg;yT=1;var e=ys();function t(n,r){return function(s,o){if(s==null)return s;if(!e(s))return n(s,o);for(var l=s.length,c=r?l:-1,d=Object(s);(r?c--:++c<l)&&o(d[c],c,d)!==!1;);return s}}return Vg=t,Vg}var Gg,wT;function Th(){if(wT)return Gg;wT=1;var e=z0(),t=JJ(),n=t(e);return Gg=n,Gg}var Kg,vT;function so(){if(vT)return Kg;vT=1;function e(t){return t}return Kg=e,Kg}var Yg,xT;function FO(){if(xT)return Yg;xT=1;var e=so();function t(n){return typeof n=="function"?n:e}return Yg=t,Yg}var Xg,bT;function BO(){if(bT)return Xg;bT=1;var e=I0(),t=Th(),n=FO(),r=jt();function s(o,l){var c=r(o)?e:t;return c(o,n(l))}return Xg=s,Xg}var Zg,kT;function qO(){return kT||(kT=1,Zg=BO()),Zg}var Jg,NT;function QJ(){if(NT)return Jg;NT=1;var e=Th();function t(n,r){var s=[];return e(n,function(o,l,c){r(o,l,c)&&s.push(o)}),s}return Jg=t,Jg}var Qg,jT;function eQ(){if(jT)return Qg;jT=1;var e="__lodash_hash_undefined__";function t(n){return this.__data__.set(n,e),this}return Qg=t,Qg}var ey,ST;function tQ(){if(ST)return ey;ST=1;function e(t){return this.__data__.has(t)}return ey=e,ey}var ty,_T;function UO(){if(_T)return ty;_T=1;var e=$0(),t=eQ(),n=tQ();function r(s){var o=-1,l=s==null?0:s.length;for(this.__data__=new e;++o<l;)this.add(s[o])}return r.prototype.add=r.prototype.push=t,r.prototype.has=n,ty=r,ty}var ny,ET;function nQ(){if(ET)return ny;ET=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 ny=e,ny}var ry,TT;function zO(){if(TT)return ry;TT=1;function e(t,n){return t.has(n)}return ry=e,ry}var sy,CT;function WO(){if(CT)return sy;CT=1;var e=UO(),t=nQ(),n=zO(),r=1,s=2;function o(l,c,d,h,f,p){var g=d&r,v=l.length,N=c.length;if(v!=N&&!(g&&N>v))return!1;var k=p.get(l),x=p.get(c);if(k&&x)return k==c&&x==l;var j=-1,b=!0,_=d&s?new e:void 0;for(p.set(l,c),p.set(c,l);++j<v;){var E=l[j],R=c[j];if(h)var C=g?h(R,E,j,c,l,p):h(E,R,j,l,c,p);if(C!==void 0){if(C)continue;b=!1;break}if(_){if(!t(c,function(A,U){if(!n(_,U)&&(E===A||f(E,A,d,h,p)))return _.push(U)})){b=!1;break}}else if(!(E===R||f(E,R,d,h,p))){b=!1;break}}return p.delete(l),p.delete(c),b}return sy=o,sy}var ay,AT;function rQ(){if(AT)return ay;AT=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s,o){r[++n]=[o,s]}),r}return ay=e,ay}var oy,RT;function W0(){if(RT)return oy;RT=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s){r[++n]=s}),r}return oy=e,oy}var iy,MT;function sQ(){if(MT)return iy;MT=1;var e=Ti(),t=IO(),n=Ei(),r=WO(),s=rQ(),o=W0(),l=1,c=2,d="[object Boolean]",h="[object Date]",f="[object Error]",p="[object Map]",g="[object Number]",v="[object RegExp]",N="[object Set]",k="[object String]",x="[object Symbol]",j="[object ArrayBuffer]",b="[object DataView]",_=e?e.prototype:void 0,E=_?_.valueOf:void 0;function R(C,A,U,L,F,O,I){switch(U){case b:if(C.byteLength!=A.byteLength||C.byteOffset!=A.byteOffset)return!1;C=C.buffer,A=A.buffer;case j:return!(C.byteLength!=A.byteLength||!O(new t(C),new t(A)));case d:case h:case g:return n(+C,+A);case f:return C.name==A.name&&C.message==A.message;case v:case k:return C==A+"";case p:var B=s;case N:var M=L&l;if(B||(B=o),C.size!=A.size&&!M)return!1;var $=I.get(C);if($)return $==A;L|=c,I.set(C,A);var P=r(B(C),B(A),L,F,O,I);return I.delete(C),P;case x:if(E)return E.call(C)==E.call(A)}return!1}return iy=R,iy}var ly,$T;function aQ(){if($T)return ly;$T=1;var e=MO(),t=1,n=Object.prototype,r=n.hasOwnProperty;function s(o,l,c,d,h,f){var p=c&t,g=e(o),v=g.length,N=e(l),k=N.length;if(v!=k&&!p)return!1;for(var x=v;x--;){var j=g[x];if(!(p?j in l:r.call(l,j)))return!1}var b=f.get(o),_=f.get(l);if(b&&_)return b==l&&_==o;var E=!0;f.set(o,l),f.set(l,o);for(var R=p;++x<v;){j=g[x];var C=o[j],A=l[j];if(d)var U=p?d(A,C,j,l,o,f):d(C,A,j,o,l,f);if(!(U===void 0?C===A||h(C,A,c,d,f):U)){E=!1;break}R||(R=j=="constructor")}if(E&&!R){var L=o.constructor,F=l.constructor;L!=F&&"constructor"in o&&"constructor"in l&&!(typeof L=="function"&&L instanceof L&&typeof F=="function"&&F instanceof F)&&(E=!1)}return f.delete(o),f.delete(l),E}return ly=s,ly}var cy,IT;function oQ(){if(IT)return cy;IT=1;var e=bh(),t=WO(),n=sQ(),r=aQ(),s=Ai(),o=jt(),l=Ci(),c=wc(),d=1,h="[object Arguments]",f="[object Array]",p="[object Object]",g=Object.prototype,v=g.hasOwnProperty;function N(k,x,j,b,_,E){var R=o(k),C=o(x),A=R?f:s(k),U=C?f:s(x);A=A==h?p:A,U=U==h?p:U;var L=A==p,F=U==p,O=A==U;if(O&&l(k)){if(!l(x))return!1;R=!0,L=!1}if(O&&!L)return E||(E=new e),R||c(k)?t(k,x,j,b,_,E):n(k,x,A,j,b,_,E);if(!(j&d)){var I=L&&v.call(k,"__wrapped__"),B=F&&v.call(x,"__wrapped__");if(I||B){var M=I?k.value():k,$=B?x.value():x;return E||(E=new e),_(M,$,j,b,E)}}return O?(E||(E=new e),r(k,x,j,b,_,E)):!1}return cy=N,cy}var uy,OT;function HO(){if(OT)return uy;OT=1;var e=oQ(),t=Ur();function n(r,s,o,l,c){return r===s?!0:r==null||s==null||!t(r)&&!t(s)?r!==r&&s!==s:e(r,s,o,l,n,c)}return uy=n,uy}var dy,LT;function iQ(){if(LT)return dy;LT=1;var e=bh(),t=HO(),n=1,r=2;function s(o,l,c,d){var h=c.length,f=h,p=!d;if(o==null)return!f;for(o=Object(o);h--;){var g=c[h];if(p&&g[2]?g[1]!==o[g[0]]:!(g[0]in o))return!1}for(;++h<f;){g=c[h];var v=g[0],N=o[v],k=g[1];if(p&&g[2]){if(N===void 0&&!(v in o))return!1}else{var x=new e;if(d)var j=d(N,k,v,o,l,x);if(!(j===void 0?t(k,N,n|r,d,x):j))return!1}}return!0}return dy=s,dy}var hy,PT;function VO(){if(PT)return hy;PT=1;var e=Vn();function t(n){return n===n&&!e(n)}return hy=t,hy}var fy,DT;function lQ(){if(DT)return fy;DT=1;var e=VO(),t=ua();function n(r){for(var s=t(r),o=s.length;o--;){var l=s[o],c=r[l];s[o]=[l,c,e(c)]}return s}return fy=n,fy}var py,FT;function GO(){if(FT)return py;FT=1;function e(t,n){return function(r){return r==null?!1:r[t]===n&&(n!==void 0||t in Object(r))}}return py=e,py}var my,BT;function cQ(){if(BT)return my;BT=1;var e=iQ(),t=lQ(),n=GO();function r(s){var o=t(s);return o.length==1&&o[0][2]?n(o[0][0],o[0][1]):function(l){return l===s||e(l,s,o)}}return my=r,my}var gy,qT;function Ri(){if(qT)return gy;qT=1;var e=to(),t=Ur(),n="[object Symbol]";function r(s){return typeof s=="symbol"||t(s)&&e(s)==n}return gy=r,gy}var yy,UT;function H0(){if(UT)return yy;UT=1;var e=jt(),t=Ri(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function s(o,l){if(e(o))return!1;var c=typeof o;return c=="number"||c=="symbol"||c=="boolean"||o==null||t(o)?!0:r.test(o)||!n.test(o)||l!=null&&o in Object(l)}return yy=s,yy}var wy,zT;function uQ(){if(zT)return wy;zT=1;var e=$0(),t="Expected a function";function n(r,s){if(typeof r!="function"||s!=null&&typeof s!="function")throw new TypeError(t);var o=function(){var l=arguments,c=s?s.apply(this,l):l[0],d=o.cache;if(d.has(c))return d.get(c);var h=r.apply(this,l);return o.cache=d.set(c,h)||d,h};return o.cache=new(n.Cache||e),o}return n.Cache=e,wy=n,wy}var vy,WT;function dQ(){if(WT)return vy;WT=1;var e=uQ(),t=500;function n(r){var s=e(r,function(l){return o.size===t&&o.clear(),l}),o=s.cache;return s}return vy=n,vy}var xy,HT;function hQ(){if(HT)return xy;HT=1;var e=dQ(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,n=/\\(\\)?/g,r=e(function(s){var o=[];return s.charCodeAt(0)===46&&o.push(""),s.replace(t,function(l,c,d,h){o.push(d?h.replace(n,"$1"):c||l)}),o});return xy=r,xy}var by,VT;function Ch(){if(VT)return by;VT=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,o=Array(s);++r<s;)o[r]=n(t[r],r,t);return o}return by=e,by}var ky,GT;function fQ(){if(GT)return ky;GT=1;var e=Ti(),t=Ch(),n=jt(),r=Ri(),s=e?e.prototype:void 0,o=s?s.toString:void 0;function l(c){if(typeof c=="string")return c;if(n(c))return t(c,l)+"";if(r(c))return o?o.call(c):"";var d=c+"";return d=="0"&&1/c==-1/0?"-0":d}return ky=l,ky}var Ny,KT;function KO(){if(KT)return Ny;KT=1;var e=fQ();function t(n){return n==null?"":e(n)}return Ny=t,Ny}var jy,YT;function Ah(){if(YT)return jy;YT=1;var e=jt(),t=H0(),n=hQ(),r=KO();function s(o,l){return e(o)?o:t(o,l)?[o]:n(r(o))}return jy=s,jy}var Sy,XT;function vc(){if(XT)return Sy;XT=1;var e=Ri();function t(n){if(typeof n=="string"||e(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}return Sy=t,Sy}var _y,ZT;function Rh(){if(ZT)return _y;ZT=1;var e=Ah(),t=vc();function n(r,s){s=e(s,r);for(var o=0,l=s.length;r!=null&&o<l;)r=r[t(s[o++])];return o&&o==l?r:void 0}return _y=n,_y}var Ey,JT;function pQ(){if(JT)return Ey;JT=1;var e=Rh();function t(n,r,s){var o=n==null?void 0:e(n,r);return o===void 0?s:o}return Ey=t,Ey}var Ty,QT;function mQ(){if(QT)return Ty;QT=1;function e(t,n){return t!=null&&n in Object(t)}return Ty=e,Ty}var Cy,eC;function YO(){if(eC)return Cy;eC=1;var e=Ah(),t=yc(),n=jt(),r=jh(),s=O0(),o=vc();function l(c,d,h){d=e(d,c);for(var f=-1,p=d.length,g=!1;++f<p;){var v=o(d[f]);if(!(g=c!=null&&h(c,v)))break;c=c[v]}return g||++f!=p?g:(p=c==null?0:c.length,!!p&&s(p)&&r(v,p)&&(n(c)||t(c)))}return Cy=l,Cy}var Ay,tC;function XO(){if(tC)return Ay;tC=1;var e=mQ(),t=YO();function n(r,s){return r!=null&&t(r,s,e)}return Ay=n,Ay}var Ry,nC;function gQ(){if(nC)return Ry;nC=1;var e=HO(),t=pQ(),n=XO(),r=H0(),s=VO(),o=GO(),l=vc(),c=1,d=2;function h(f,p){return r(f)&&s(p)?o(l(f),p):function(g){var v=t(g,f);return v===void 0&&v===p?n(g,f):e(p,v,c|d)}}return Ry=h,Ry}var My,rC;function ZO(){if(rC)return My;rC=1;function e(t){return function(n){return n==null?void 0:n[t]}}return My=e,My}var $y,sC;function yQ(){if(sC)return $y;sC=1;var e=Rh();function t(n){return function(r){return e(r,n)}}return $y=t,$y}var Iy,aC;function wQ(){if(aC)return Iy;aC=1;var e=ZO(),t=yQ(),n=H0(),r=vc();function s(o){return n(o)?e(r(o)):t(o)}return Iy=s,Iy}var Oy,oC;function ws(){if(oC)return Oy;oC=1;var e=cQ(),t=gQ(),n=so(),r=jt(),s=wQ();function o(l){return typeof l=="function"?l:l==null?n:typeof l=="object"?r(l)?t(l[0],l[1]):e(l):s(l)}return Oy=o,Oy}var Ly,iC;function JO(){if(iC)return Ly;iC=1;var e=TO(),t=QJ(),n=ws(),r=jt();function s(o,l){var c=r(o)?e:t;return c(o,n(l,3))}return Ly=s,Ly}var Py,lC;function vQ(){if(lC)return Py;lC=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r,s){return r!=null&&t.call(r,s)}return Py=n,Py}var Dy,cC;function QO(){if(cC)return Dy;cC=1;var e=vQ(),t=YO();function n(r,s){return r!=null&&t(r,s,e)}return Dy=n,Dy}var Fy,uC;function xQ(){if(uC)return Fy;uC=1;var e=P0(),t=Ai(),n=yc(),r=jt(),s=ys(),o=Ci(),l=_h(),c=wc(),d="[object Map]",h="[object Set]",f=Object.prototype,p=f.hasOwnProperty;function g(v){if(v==null)return!0;if(s(v)&&(r(v)||typeof v=="string"||typeof v.splice=="function"||o(v)||c(v)||n(v)))return!v.length;var N=t(v);if(N==d||N==h)return!v.size;if(l(v))return!e(v).length;for(var k in v)if(p.call(v,k))return!1;return!0}return Fy=g,Fy}var By,dC;function eL(){if(dC)return By;dC=1;function e(t){return t===void 0}return By=e,By}var qy,hC;function tL(){if(hC)return qy;hC=1;var e=Th(),t=ys();function n(r,s){var o=-1,l=t(r)?Array(r.length):[];return e(r,function(c,d,h){l[++o]=s(c,d,h)}),l}return qy=n,qy}var Uy,fC;function nL(){if(fC)return Uy;fC=1;var e=Ch(),t=ws(),n=tL(),r=jt();function s(o,l){var c=r(o)?e:n;return c(o,t(l,3))}return Uy=s,Uy}var zy,pC;function bQ(){if(pC)return zy;pC=1;function e(t,n,r,s){var o=-1,l=t==null?0:t.length;for(s&&l&&(r=t[++o]);++o<l;)r=n(r,t[o],o,t);return r}return zy=e,zy}var Wy,mC;function kQ(){if(mC)return Wy;mC=1;function e(t,n,r,s,o){return o(t,function(l,c,d){r=s?(s=!1,l):n(r,l,c,d)}),r}return Wy=e,Wy}var Hy,gC;function rL(){if(gC)return Hy;gC=1;var e=bQ(),t=Th(),n=ws(),r=kQ(),s=jt();function o(l,c,d){var h=s(l)?e:r,f=arguments.length<3;return h(l,n(c,4),d,f,t)}return Hy=o,Hy}var Vy,yC;function NQ(){if(yC)return Vy;yC=1;var e=to(),t=jt(),n=Ur(),r="[object String]";function s(o){return typeof o=="string"||!t(o)&&n(o)&&e(o)==r}return Vy=s,Vy}var Gy,wC;function jQ(){if(wC)return Gy;wC=1;var e=ZO(),t=e("length");return Gy=t,Gy}var Ky,vC;function SQ(){if(vC)return Ky;vC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,o="\\ufe0e\\ufe0f",l="\\u200d",c=RegExp("["+l+e+s+o+"]");function d(h){return c.test(h)}return Ky=d,Ky}var Yy,xC;function _Q(){if(xC)return Yy;xC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,o="\\ufe0e\\ufe0f",l="["+e+"]",c="["+s+"]",d="\\ud83c[\\udffb-\\udfff]",h="(?:"+c+"|"+d+")",f="[^"+e+"]",p="(?:\\ud83c[\\udde6-\\uddff]){2}",g="[\\ud800-\\udbff][\\udc00-\\udfff]",v="\\u200d",N=h+"?",k="["+o+"]?",x="(?:"+v+"(?:"+[f,p,g].join("|")+")"+k+N+")*",j=k+N+x,b="(?:"+[f+c+"?",c,p,g,l].join("|")+")",_=RegExp(d+"(?="+d+")|"+b+j,"g");function E(R){for(var C=_.lastIndex=0;_.test(R);)++C;return C}return Yy=E,Yy}var Xy,bC;function EQ(){if(bC)return Xy;bC=1;var e=jQ(),t=SQ(),n=_Q();function r(s){return t(s)?n(s):e(s)}return Xy=r,Xy}var Zy,kC;function TQ(){if(kC)return Zy;kC=1;var e=P0(),t=Ai(),n=ys(),r=NQ(),s=EQ(),o="[object Map]",l="[object Set]";function c(d){if(d==null)return 0;if(n(d))return r(d)?s(d):d.length;var h=t(d);return h==o||h==l?d.size:e(d).length}return Zy=c,Zy}var Jy,NC;function CQ(){if(NC)return Jy;NC=1;var e=I0(),t=LO(),n=z0(),r=ws(),s=Eh(),o=jt(),l=Ci(),c=mc(),d=Vn(),h=wc();function f(p,g,v){var N=o(p),k=N||l(p)||h(p);if(g=r(g,4),v==null){var x=p&&p.constructor;k?v=N?new x:[]:d(p)?v=c(x)?t(s(p)):{}:v={}}return(k?e:n)(p,function(j,b,_){return g(v,j,b,_)}),v}return Jy=f,Jy}var Qy,jC;function AQ(){if(jC)return Qy;jC=1;var e=Ti(),t=yc(),n=jt(),r=e?e.isConcatSpreadable:void 0;function s(o){return n(o)||t(o)||!!(r&&o&&o[r])}return Qy=s,Qy}var ew,SC;function V0(){if(SC)return ew;SC=1;var e=F0(),t=AQ();function n(r,s,o,l,c){var d=-1,h=r.length;for(o||(o=t),c||(c=[]);++d<h;){var f=r[d];s>0&&o(f)?s>1?n(f,s-1,o,l,c):e(c,f):l||(c[c.length]=f)}return c}return ew=n,ew}var tw,_C;function RQ(){if(_C)return tw;_C=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 tw=e,tw}var nw,EC;function sL(){if(EC)return nw;EC=1;var e=RQ(),t=Math.max;function n(r,s,o){return s=t(s===void 0?r.length-1:s,0),function(){for(var l=arguments,c=-1,d=t(l.length-s,0),h=Array(d);++c<d;)h[c]=l[s+c];c=-1;for(var f=Array(s+1);++c<s;)f[c]=l[c];return f[s]=o(h),e(r,this,f)}}return nw=n,nw}var rw,TC;function MQ(){if(TC)return rw;TC=1;var e=q0(),t=NO(),n=so(),r=t?function(s,o){return t(s,"toString",{configurable:!0,enumerable:!1,value:e(o),writable:!0})}:n;return rw=r,rw}var sw,CC;function $Q(){if(CC)return sw;CC=1;var e=800,t=16,n=Date.now;function r(s){var o=0,l=0;return function(){var c=n(),d=t-(c-l);if(l=c,d>0){if(++o>=e)return arguments[0]}else o=0;return s.apply(void 0,arguments)}}return sw=r,sw}var aw,AC;function aL(){if(AC)return aw;AC=1;var e=MQ(),t=$Q(),n=t(e);return aw=n,aw}var ow,RC;function Mh(){if(RC)return ow;RC=1;var e=so(),t=sL(),n=aL();function r(s,o){return n(t(s,o,e),s+"")}return ow=r,ow}var iw,MC;function oL(){if(MC)return iw;MC=1;function e(t,n,r,s){for(var o=t.length,l=r+(s?1:-1);s?l--:++l<o;)if(n(t[l],l,t))return l;return-1}return iw=e,iw}var lw,$C;function IQ(){if($C)return lw;$C=1;function e(t){return t!==t}return lw=e,lw}var cw,IC;function OQ(){if(IC)return cw;IC=1;function e(t,n,r){for(var s=r-1,o=t.length;++s<o;)if(t[s]===n)return s;return-1}return cw=e,cw}var uw,OC;function LQ(){if(OC)return uw;OC=1;var e=oL(),t=IQ(),n=OQ();function r(s,o,l){return o===o?n(s,o,l):e(s,t,l)}return uw=r,uw}var dw,LC;function PQ(){if(LC)return dw;LC=1;var e=LQ();function t(n,r){var s=n==null?0:n.length;return!!s&&e(n,r,0)>-1}return dw=t,dw}var hw,PC;function DQ(){if(PC)return hw;PC=1;function e(t,n,r){for(var s=-1,o=t==null?0:t.length;++s<o;)if(r(n,t[s]))return!0;return!1}return hw=e,hw}var fw,DC;function FQ(){if(DC)return fw;DC=1;function e(){}return fw=e,fw}var pw,FC;function BQ(){if(FC)return pw;FC=1;var e=$O(),t=FQ(),n=W0(),r=1/0,s=e&&1/n(new e([,-0]))[1]==r?function(o){return new e(o)}:t;return pw=s,pw}var mw,BC;function qQ(){if(BC)return mw;BC=1;var e=UO(),t=PQ(),n=DQ(),r=zO(),s=BQ(),o=W0(),l=200;function c(d,h,f){var p=-1,g=t,v=d.length,N=!0,k=[],x=k;if(f)N=!1,g=n;else if(v>=l){var j=h?null:s(d);if(j)return o(j);N=!1,g=r,x=new e}else x=h?[]:k;e:for(;++p<v;){var b=d[p],_=h?h(b):b;if(b=f||b!==0?b:0,N&&_===_){for(var E=x.length;E--;)if(x[E]===_)continue e;h&&x.push(_),k.push(b)}else g(x,_,f)||(x!==k&&x.push(_),k.push(b))}return k}return mw=c,mw}var gw,qC;function iL(){if(qC)return gw;qC=1;var e=ys(),t=Ur();function n(r){return t(r)&&e(r)}return gw=n,gw}var yw,UC;function UQ(){if(UC)return yw;UC=1;var e=V0(),t=Mh(),n=qQ(),r=iL(),s=t(function(o){return n(e(o,1,r,!0))});return yw=s,yw}var ww,zC;function zQ(){if(zC)return ww;zC=1;var e=Ch();function t(n,r){return e(r,function(s){return n[s]})}return ww=t,ww}var vw,WC;function lL(){if(WC)return vw;WC=1;var e=zQ(),t=ua();function n(r){return r==null?[]:e(r,t(r))}return vw=n,vw}var xw,HC;function Gn(){if(HC)return xw;HC=1;var e;if(typeof R0=="function")try{e={clone:XJ(),constant:q0(),each:qO(),filter:JO(),has:QO(),isArray:jt(),isEmpty:xQ(),isFunction:mc(),isUndefined:eL(),keys:ua(),map:nL(),reduce:rL(),size:TQ(),transform:CQ(),union:UQ(),values:lL()}}catch{}return e||(e=window._),xw=e,xw}var bw,VC;function G0(){if(VC)return bw;VC=1;var e=Gn();bw=s;var t="\0",n="\0",r="";function s(f){this._isDirected=e.has(f,"directed")?f.directed:!0,this._isMultigraph=e.has(f,"multigraph")?f.multigraph:!1,this._isCompound=e.has(f,"compound")?f.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(f){return this._label=f,this},s.prototype.graph=function(){return this._label},s.prototype.setDefaultNodeLabel=function(f){return e.isFunction(f)||(f=e.constant(f)),this._defaultNodeLabelFn=f,this},s.prototype.nodeCount=function(){return this._nodeCount},s.prototype.nodes=function(){return e.keys(this._nodes)},s.prototype.sources=function(){var f=this;return e.filter(this.nodes(),function(p){return e.isEmpty(f._in[p])})},s.prototype.sinks=function(){var f=this;return e.filter(this.nodes(),function(p){return e.isEmpty(f._out[p])})},s.prototype.setNodes=function(f,p){var g=arguments,v=this;return e.each(f,function(N){g.length>1?v.setNode(N,p):v.setNode(N)}),this},s.prototype.setNode=function(f,p){return e.has(this._nodes,f)?(arguments.length>1&&(this._nodes[f]=p),this):(this._nodes[f]=arguments.length>1?p:this._defaultNodeLabelFn(f),this._isCompound&&(this._parent[f]=n,this._children[f]={},this._children[n][f]=!0),this._in[f]={},this._preds[f]={},this._out[f]={},this._sucs[f]={},++this._nodeCount,this)},s.prototype.node=function(f){return this._nodes[f]},s.prototype.hasNode=function(f){return e.has(this._nodes,f)},s.prototype.removeNode=function(f){var p=this;if(e.has(this._nodes,f)){var g=function(v){p.removeEdge(p._edgeObjs[v])};delete this._nodes[f],this._isCompound&&(this._removeFromParentsChildList(f),delete this._parent[f],e.each(this.children(f),function(v){p.setParent(v)}),delete this._children[f]),e.each(e.keys(this._in[f]),g),delete this._in[f],delete this._preds[f],e.each(e.keys(this._out[f]),g),delete this._out[f],delete this._sucs[f],--this._nodeCount}return this},s.prototype.setParent=function(f,p){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(p))p=n;else{p+="";for(var g=p;!e.isUndefined(g);g=this.parent(g))if(g===f)throw new Error("Setting "+p+" as parent of "+f+" would create a cycle");this.setNode(p)}return this.setNode(f),this._removeFromParentsChildList(f),this._parent[f]=p,this._children[p][f]=!0,this},s.prototype._removeFromParentsChildList=function(f){delete this._children[this._parent[f]][f]},s.prototype.parent=function(f){if(this._isCompound){var p=this._parent[f];if(p!==n)return p}},s.prototype.children=function(f){if(e.isUndefined(f)&&(f=n),this._isCompound){var p=this._children[f];if(p)return e.keys(p)}else{if(f===n)return this.nodes();if(this.hasNode(f))return[]}},s.prototype.predecessors=function(f){var p=this._preds[f];if(p)return e.keys(p)},s.prototype.successors=function(f){var p=this._sucs[f];if(p)return e.keys(p)},s.prototype.neighbors=function(f){var p=this.predecessors(f);if(p)return e.union(p,this.successors(f))},s.prototype.isLeaf=function(f){var p;return this.isDirected()?p=this.successors(f):p=this.neighbors(f),p.length===0},s.prototype.filterNodes=function(f){var p=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});p.setGraph(this.graph());var g=this;e.each(this._nodes,function(k,x){f(x)&&p.setNode(x,k)}),e.each(this._edgeObjs,function(k){p.hasNode(k.v)&&p.hasNode(k.w)&&p.setEdge(k,g.edge(k))});var v={};function N(k){var x=g.parent(k);return x===void 0||p.hasNode(x)?(v[k]=x,x):x in v?v[x]:N(x)}return this._isCompound&&e.each(p.nodes(),function(k){p.setParent(k,N(k))}),p},s.prototype.setDefaultEdgeLabel=function(f){return e.isFunction(f)||(f=e.constant(f)),this._defaultEdgeLabelFn=f,this},s.prototype.edgeCount=function(){return this._edgeCount},s.prototype.edges=function(){return e.values(this._edgeObjs)},s.prototype.setPath=function(f,p){var g=this,v=arguments;return e.reduce(f,function(N,k){return v.length>1?g.setEdge(N,k,p):g.setEdge(N,k),k}),this},s.prototype.setEdge=function(){var f,p,g,v,N=!1,k=arguments[0];typeof k=="object"&&k!==null&&"v"in k?(f=k.v,p=k.w,g=k.name,arguments.length===2&&(v=arguments[1],N=!0)):(f=k,p=arguments[1],g=arguments[3],arguments.length>2&&(v=arguments[2],N=!0)),f=""+f,p=""+p,e.isUndefined(g)||(g=""+g);var x=c(this._isDirected,f,p,g);if(e.has(this._edgeLabels,x))return N&&(this._edgeLabels[x]=v),this;if(!e.isUndefined(g)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(f),this.setNode(p),this._edgeLabels[x]=N?v:this._defaultEdgeLabelFn(f,p,g);var j=d(this._isDirected,f,p,g);return f=j.v,p=j.w,Object.freeze(j),this._edgeObjs[x]=j,o(this._preds[p],f),o(this._sucs[f],p),this._in[p][x]=j,this._out[f][x]=j,this._edgeCount++,this},s.prototype.edge=function(f,p,g){var v=arguments.length===1?h(this._isDirected,arguments[0]):c(this._isDirected,f,p,g);return this._edgeLabels[v]},s.prototype.hasEdge=function(f,p,g){var v=arguments.length===1?h(this._isDirected,arguments[0]):c(this._isDirected,f,p,g);return e.has(this._edgeLabels,v)},s.prototype.removeEdge=function(f,p,g){var v=arguments.length===1?h(this._isDirected,arguments[0]):c(this._isDirected,f,p,g),N=this._edgeObjs[v];return N&&(f=N.v,p=N.w,delete this._edgeLabels[v],delete this._edgeObjs[v],l(this._preds[p],f),l(this._sucs[f],p),delete this._in[p][v],delete this._out[f][v],this._edgeCount--),this},s.prototype.inEdges=function(f,p){var g=this._in[f];if(g){var v=e.values(g);return p?e.filter(v,function(N){return N.v===p}):v}},s.prototype.outEdges=function(f,p){var g=this._out[f];if(g){var v=e.values(g);return p?e.filter(v,function(N){return N.w===p}):v}},s.prototype.nodeEdges=function(f,p){var g=this.inEdges(f,p);if(g)return g.concat(this.outEdges(f,p))};function o(f,p){f[p]?f[p]++:f[p]=1}function l(f,p){--f[p]||delete f[p]}function c(f,p,g,v){var N=""+p,k=""+g;if(!f&&N>k){var x=N;N=k,k=x}return N+r+k+r+(e.isUndefined(v)?t:v)}function d(f,p,g,v){var N=""+p,k=""+g;if(!f&&N>k){var x=N;N=k,k=x}var j={v:N,w:k};return v&&(j.name=v),j}function h(f,p){return c(f,p.v,p.w,p.name)}return bw}var kw,GC;function WQ(){return GC||(GC=1,kw="2.1.8"),kw}var Nw,KC;function HQ(){return KC||(KC=1,Nw={Graph:G0(),version:WQ()}),Nw}var jw,YC;function VQ(){if(YC)return jw;YC=1;var e=Gn(),t=G0();jw={write:n,read:o};function n(l){var c={options:{directed:l.isDirected(),multigraph:l.isMultigraph(),compound:l.isCompound()},nodes:r(l),edges:s(l)};return e.isUndefined(l.graph())||(c.value=e.clone(l.graph())),c}function r(l){return e.map(l.nodes(),function(c){var d=l.node(c),h=l.parent(c),f={v:c};return e.isUndefined(d)||(f.value=d),e.isUndefined(h)||(f.parent=h),f})}function s(l){return e.map(l.edges(),function(c){var d=l.edge(c),h={v:c.v,w:c.w};return e.isUndefined(c.name)||(h.name=c.name),e.isUndefined(d)||(h.value=d),h})}function o(l){var c=new t(l.options).setGraph(l.value);return e.each(l.nodes,function(d){c.setNode(d.v,d.value),d.parent&&c.setParent(d.v,d.parent)}),e.each(l.edges,function(d){c.setEdge({v:d.v,w:d.w,name:d.name},d.value)}),c}return jw}var Sw,XC;function GQ(){if(XC)return Sw;XC=1;var e=Gn();Sw=t;function t(n){var r={},s=[],o;function l(c){e.has(r,c)||(r[c]=!0,o.push(c),e.each(n.successors(c),l),e.each(n.predecessors(c),l))}return e.each(n.nodes(),function(c){o=[],l(c),o.length&&s.push(o)}),s}return Sw}var _w,ZC;function cL(){if(ZC)return _w;ZC=1;var e=Gn();_w=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 o=this._arr,l=o.length;return s[n]=l,o.push({key:n,priority:r}),this._decrease(l),!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,o=s+1,l=n;s<r.length&&(l=r[s].priority<r[l].priority?s:l,o<r.length&&(l=r[o].priority<r[l].priority?o:l),l!==n&&(this._swap(n,l),this._heapify(l)))},t.prototype._decrease=function(n){for(var r=this._arr,s=r[n].priority,o;n!==0&&(o=n>>1,!(r[o].priority<s));)this._swap(n,o),n=o},t.prototype._swap=function(n,r){var s=this._arr,o=this._keyIndices,l=s[n],c=s[r];s[n]=c,s[r]=l,o[c.key]=n,o[l.key]=r},_w}var Ew,JC;function uL(){if(JC)return Ew;JC=1;var e=Gn(),t=cL();Ew=r;var n=e.constant(1);function r(o,l,c,d){return s(o,String(l),c||n,d||function(h){return o.outEdges(h)})}function s(o,l,c,d){var h={},f=new t,p,g,v=function(N){var k=N.v!==p?N.v:N.w,x=h[k],j=c(N),b=g.distance+j;if(j<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+N+" Weight: "+j);b<x.distance&&(x.distance=b,x.predecessor=p,f.decrease(k,b))};for(o.nodes().forEach(function(N){var k=N===l?0:Number.POSITIVE_INFINITY;h[N]={distance:k},f.add(N,k)});f.size()>0&&(p=f.removeMin(),g=h[p],g.distance!==Number.POSITIVE_INFINITY);)d(p).forEach(v);return h}return Ew}var Tw,QC;function KQ(){if(QC)return Tw;QC=1;var e=uL(),t=Gn();Tw=n;function n(r,s,o){return t.transform(r.nodes(),function(l,c){l[c]=e(r,c,s,o)},{})}return Tw}var Cw,eA;function dL(){if(eA)return Cw;eA=1;var e=Gn();Cw=t;function t(n){var r=0,s=[],o={},l=[];function c(d){var h=o[d]={onStack:!0,lowlink:r,index:r++};if(s.push(d),n.successors(d).forEach(function(g){e.has(o,g)?o[g].onStack&&(h.lowlink=Math.min(h.lowlink,o[g].index)):(c(g),h.lowlink=Math.min(h.lowlink,o[g].lowlink))}),h.lowlink===h.index){var f=[],p;do p=s.pop(),o[p].onStack=!1,f.push(p);while(d!==p);l.push(f)}}return n.nodes().forEach(function(d){e.has(o,d)||c(d)}),l}return Cw}var Aw,tA;function YQ(){if(tA)return Aw;tA=1;var e=Gn(),t=dL();Aw=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 Aw}var Rw,nA;function XQ(){if(nA)return Rw;nA=1;var e=Gn();Rw=n;var t=e.constant(1);function n(s,o,l){return r(s,o||t,l||function(c){return s.outEdges(c)})}function r(s,o,l){var c={},d=s.nodes();return d.forEach(function(h){c[h]={},c[h][h]={distance:0},d.forEach(function(f){h!==f&&(c[h][f]={distance:Number.POSITIVE_INFINITY})}),l(h).forEach(function(f){var p=f.v===h?f.w:f.v,g=o(f);c[h][p]={distance:g,predecessor:h}})}),d.forEach(function(h){var f=c[h];d.forEach(function(p){var g=c[p];d.forEach(function(v){var N=g[h],k=f[v],x=g[v],j=N.distance+k.distance;j<x.distance&&(x.distance=j,x.predecessor=k.predecessor)})})}),c}return Rw}var Mw,rA;function hL(){if(rA)return Mw;rA=1;var e=Gn();Mw=t,t.CycleException=n;function t(r){var s={},o={},l=[];function c(d){if(e.has(o,d))throw new n;e.has(s,d)||(o[d]=!0,s[d]=!0,e.each(r.predecessors(d),c),delete o[d],l.push(d))}if(e.each(r.sinks(),c),e.size(s)!==r.nodeCount())throw new n;return l}function n(){}return n.prototype=new Error,Mw}var $w,sA;function ZQ(){if(sA)return $w;sA=1;var e=hL();$w=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return $w}var Iw,aA;function fL(){if(aA)return Iw;aA=1;var e=Gn();Iw=t;function t(r,s,o){e.isArray(s)||(s=[s]);var l=(r.isDirected()?r.successors:r.neighbors).bind(r),c=[],d={};return e.each(s,function(h){if(!r.hasNode(h))throw new Error("Graph does not have node: "+h);n(r,h,o==="post",d,l,c)}),c}function n(r,s,o,l,c,d){e.has(l,s)||(l[s]=!0,o||d.push(s),e.each(c(s),function(h){n(r,h,o,l,c,d)}),o&&d.push(s))}return Iw}var Ow,oA;function JQ(){if(oA)return Ow;oA=1;var e=fL();Ow=t;function t(n,r){return e(n,r,"post")}return Ow}var Lw,iA;function QQ(){if(iA)return Lw;iA=1;var e=fL();Lw=t;function t(n,r){return e(n,r,"pre")}return Lw}var Pw,lA;function eee(){if(lA)return Pw;lA=1;var e=Gn(),t=G0(),n=cL();Pw=r;function r(s,o){var l=new t,c={},d=new n,h;function f(g){var v=g.v===h?g.w:g.v,N=d.priority(v);if(N!==void 0){var k=o(g);k<N&&(c[v]=h,d.decrease(v,k))}}if(s.nodeCount()===0)return l;e.each(s.nodes(),function(g){d.add(g,Number.POSITIVE_INFINITY),l.setNode(g)}),d.decrease(s.nodes()[0],0);for(var p=!1;d.size()>0;){if(h=d.removeMin(),e.has(c,h))l.setEdge(h,c[h]);else{if(p)throw new Error("Input graph is not connected: "+s);p=!0}s.nodeEdges(h).forEach(f)}return l}return Pw}var Dw,cA;function tee(){return cA||(cA=1,Dw={components:GQ(),dijkstra:uL(),dijkstraAll:KQ(),findCycles:YQ(),floydWarshall:XQ(),isAcyclic:ZQ(),postorder:JQ(),preorder:QQ(),prim:eee(),tarjan:dL(),topsort:hL()}),Dw}var Fw,uA;function nee(){if(uA)return Fw;uA=1;var e=HQ();return Fw={Graph:e.Graph,json:VQ(),alg:tee(),version:e.version},Fw}var Bw,dA;function hr(){if(dA)return Bw;dA=1;var e;if(typeof R0=="function")try{e=nee()}catch{}return e||(e=window.graphlib),Bw=e,Bw}var qw,hA;function ree(){if(hA)return qw;hA=1;var e=DO(),t=1,n=4;function r(s){return e(s,t|n)}return qw=r,qw}var Uw,fA;function $h(){if(fA)return Uw;fA=1;var e=Ei(),t=ys(),n=jh(),r=Vn();function s(o,l,c){if(!r(c))return!1;var d=typeof l;return(d=="number"?t(c)&&n(l,c.length):d=="string"&&l in c)?e(c[l],o):!1}return Uw=s,Uw}var zw,pA;function see(){if(pA)return zw;pA=1;var e=Mh(),t=Ei(),n=$h(),r=ro(),s=Object.prototype,o=s.hasOwnProperty,l=e(function(c,d){c=Object(c);var h=-1,f=d.length,p=f>2?d[2]:void 0;for(p&&n(d[0],d[1],p)&&(f=1);++h<f;)for(var g=d[h],v=r(g),N=-1,k=v.length;++N<k;){var x=v[N],j=c[x];(j===void 0||t(j,s[x])&&!o.call(c,x))&&(c[x]=g[x])}return c});return zw=l,zw}var Ww,mA;function aee(){if(mA)return Ww;mA=1;var e=ws(),t=ys(),n=ua();function r(s){return function(o,l,c){var d=Object(o);if(!t(o)){var h=e(l,3);o=n(o),l=function(p){return h(d[p],p,d)}}var f=s(o,l,c);return f>-1?d[h?o[f]:f]:void 0}}return Ww=r,Ww}var Hw,gA;function oee(){if(gA)return Hw;gA=1;var e=/\s/;function t(n){for(var r=n.length;r--&&e.test(n.charAt(r)););return r}return Hw=t,Hw}var Vw,yA;function iee(){if(yA)return Vw;yA=1;var e=oee(),t=/^\s+/;function n(r){return r&&r.slice(0,e(r)+1).replace(t,"")}return Vw=n,Vw}var Gw,wA;function lee(){if(wA)return Gw;wA=1;var e=iee(),t=Vn(),n=Ri(),r=NaN,s=/^[-+]0x[0-9a-f]+$/i,o=/^0b[01]+$/i,l=/^0o[0-7]+$/i,c=parseInt;function d(h){if(typeof h=="number")return h;if(n(h))return r;if(t(h)){var f=typeof h.valueOf=="function"?h.valueOf():h;h=t(f)?f+"":f}if(typeof h!="string")return h===0?h:+h;h=e(h);var p=o.test(h);return p||l.test(h)?c(h.slice(2),p?2:8):s.test(h)?r:+h}return Gw=d,Gw}var Kw,vA;function pL(){if(vA)return Kw;vA=1;var e=lee(),t=1/0,n=17976931348623157e292;function r(s){if(!s)return s===0?s:0;if(s=e(s),s===t||s===-t){var o=s<0?-1:1;return o*n}return s===s?s:0}return Kw=r,Kw}var Yw,xA;function cee(){if(xA)return Yw;xA=1;var e=pL();function t(n){var r=e(n),s=r%1;return r===r?s?r-s:r:0}return Yw=t,Yw}var Xw,bA;function uee(){if(bA)return Xw;bA=1;var e=oL(),t=ws(),n=cee(),r=Math.max;function s(o,l,c){var d=o==null?0:o.length;if(!d)return-1;var h=c==null?0:n(c);return h<0&&(h=r(d+h,0)),e(o,t(l,3),h)}return Xw=s,Xw}var Zw,kA;function dee(){if(kA)return Zw;kA=1;var e=aee(),t=uee(),n=e(t);return Zw=n,Zw}var Jw,NA;function mL(){if(NA)return Jw;NA=1;var e=V0();function t(n){var r=n==null?0:n.length;return r?e(n,1):[]}return Jw=t,Jw}var Qw,jA;function hee(){if(jA)return Qw;jA=1;var e=U0(),t=FO(),n=ro();function r(s,o){return s==null?s:e(s,t(o),n)}return Qw=r,Qw}var ev,SA;function fee(){if(SA)return ev;SA=1;function e(t){var n=t==null?0:t.length;return n?t[n-1]:void 0}return ev=e,ev}var tv,_A;function pee(){if(_A)return tv;_A=1;var e=kh(),t=z0(),n=ws();function r(s,o){var l={};return o=n(o,3),t(s,function(c,d,h){e(l,d,o(c,d,h))}),l}return tv=r,tv}var nv,EA;function K0(){if(EA)return nv;EA=1;var e=Ri();function t(n,r,s){for(var o=-1,l=n.length;++o<l;){var c=n[o],d=r(c);if(d!=null&&(h===void 0?d===d&&!e(d):s(d,h)))var h=d,f=c}return f}return nv=t,nv}var rv,TA;function mee(){if(TA)return rv;TA=1;function e(t,n){return t>n}return rv=e,rv}var sv,CA;function gee(){if(CA)return sv;CA=1;var e=K0(),t=mee(),n=so();function r(s){return s&&s.length?e(s,n,t):void 0}return sv=r,sv}var av,AA;function gL(){if(AA)return av;AA=1;var e=kh(),t=Ei();function n(r,s,o){(o!==void 0&&!t(r[s],o)||o===void 0&&!(s in r))&&e(r,s,o)}return av=n,av}var ov,RA;function yee(){if(RA)return ov;RA=1;var e=to(),t=Eh(),n=Ur(),r="[object Object]",s=Function.prototype,o=Object.prototype,l=s.toString,c=o.hasOwnProperty,d=l.call(Object);function h(f){if(!n(f)||e(f)!=r)return!1;var p=t(f);if(p===null)return!0;var g=c.call(p,"constructor")&&p.constructor;return typeof g=="function"&&g instanceof g&&l.call(g)==d}return ov=h,ov}var iv,MA;function yL(){if(MA)return iv;MA=1;function e(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}return iv=e,iv}var lv,$A;function wee(){if($A)return lv;$A=1;var e=gc(),t=ro();function n(r){return e(r,t(r))}return lv=n,lv}var cv,IA;function vee(){if(IA)return cv;IA=1;var e=gL(),t=_O(),n=OO(),r=EO(),s=PO(),o=yc(),l=jt(),c=iL(),d=Ci(),h=mc(),f=Vn(),p=yee(),g=wc(),v=yL(),N=wee();function k(x,j,b,_,E,R,C){var A=v(x,b),U=v(j,b),L=C.get(U);if(L){e(x,b,L);return}var F=R?R(A,U,b+"",x,j,C):void 0,O=F===void 0;if(O){var I=l(U),B=!I&&d(U),M=!I&&!B&&g(U);F=U,I||B||M?l(A)?F=A:c(A)?F=r(A):B?(O=!1,F=t(U,!0)):M?(O=!1,F=n(U,!0)):F=[]:p(U)||o(U)?(F=A,o(A)?F=N(A):(!f(A)||h(A))&&(F=s(U))):O=!1}O&&(C.set(U,F),E(F,U,_,R,C),C.delete(U)),e(x,b,F)}return cv=k,cv}var uv,OA;function xee(){if(OA)return uv;OA=1;var e=bh(),t=gL(),n=U0(),r=vee(),s=Vn(),o=ro(),l=yL();function c(d,h,f,p,g){d!==h&&n(h,function(v,N){if(g||(g=new e),s(v))r(d,h,N,f,c,p,g);else{var k=p?p(l(d,N),v,N+"",d,h,g):void 0;k===void 0&&(k=v),t(d,N,k)}},o)}return uv=c,uv}var dv,LA;function bee(){if(LA)return dv;LA=1;var e=Mh(),t=$h();function n(r){return e(function(s,o){var l=-1,c=o.length,d=c>1?o[c-1]:void 0,h=c>2?o[2]:void 0;for(d=r.length>3&&typeof d=="function"?(c--,d):void 0,h&&t(o[0],o[1],h)&&(d=c<3?void 0:d,c=1),s=Object(s);++l<c;){var f=o[l];f&&r(s,f,l,d)}return s})}return dv=n,dv}var hv,PA;function kee(){if(PA)return hv;PA=1;var e=xee(),t=bee(),n=t(function(r,s,o){e(r,s,o)});return hv=n,hv}var fv,DA;function wL(){if(DA)return fv;DA=1;function e(t,n){return t<n}return fv=e,fv}var pv,FA;function Nee(){if(FA)return pv;FA=1;var e=K0(),t=wL(),n=so();function r(s){return s&&s.length?e(s,n,t):void 0}return pv=r,pv}var mv,BA;function jee(){if(BA)return mv;BA=1;var e=K0(),t=ws(),n=wL();function r(s,o){return s&&s.length?e(s,t(o,2),n):void 0}return mv=r,mv}var gv,qA;function See(){if(qA)return gv;qA=1;var e=pr(),t=function(){return e.Date.now()};return gv=t,gv}var yv,UA;function _ee(){if(UA)return yv;UA=1;var e=Nh(),t=Ah(),n=jh(),r=Vn(),s=vc();function o(l,c,d,h){if(!r(l))return l;c=t(c,l);for(var f=-1,p=c.length,g=p-1,v=l;v!=null&&++f<p;){var N=s(c[f]),k=d;if(N==="__proto__"||N==="constructor"||N==="prototype")return l;if(f!=g){var x=v[N];k=h?h(x,N,v):void 0,k===void 0&&(k=r(x)?x:n(c[f+1])?[]:{})}e(v,N,k),v=v[N]}return l}return yv=o,yv}var wv,zA;function Eee(){if(zA)return wv;zA=1;var e=Rh(),t=_ee(),n=Ah();function r(s,o,l){for(var c=-1,d=o.length,h={};++c<d;){var f=o[c],p=e(s,f);l(p,f)&&t(h,n(f,s),p)}return h}return wv=r,wv}var vv,WA;function Tee(){if(WA)return vv;WA=1;var e=Eee(),t=XO();function n(r,s){return e(r,s,function(o,l){return t(r,l)})}return vv=n,vv}var xv,HA;function Cee(){if(HA)return xv;HA=1;var e=mL(),t=sL(),n=aL();function r(s){return n(t(s,void 0,e),s+"")}return xv=r,xv}var bv,VA;function Aee(){if(VA)return bv;VA=1;var e=Tee(),t=Cee(),n=t(function(r,s){return r==null?{}:e(r,s)});return bv=n,bv}var kv,GA;function Ree(){if(GA)return kv;GA=1;var e=Math.ceil,t=Math.max;function n(r,s,o,l){for(var c=-1,d=t(e((s-r)/(o||1)),0),h=Array(d);d--;)h[l?d:++c]=r,r+=o;return h}return kv=n,kv}var Nv,KA;function Mee(){if(KA)return Nv;KA=1;var e=Ree(),t=$h(),n=pL();function r(s){return function(o,l,c){return c&&typeof c!="number"&&t(o,l,c)&&(l=c=void 0),o=n(o),l===void 0?(l=o,o=0):l=n(l),c=c===void 0?o<l?1:-1:n(c),e(o,l,c,s)}}return Nv=r,Nv}var jv,YA;function $ee(){if(YA)return jv;YA=1;var e=Mee(),t=e();return jv=t,jv}var Sv,XA;function Iee(){if(XA)return Sv;XA=1;function e(t,n){var r=t.length;for(t.sort(n);r--;)t[r]=t[r].value;return t}return Sv=e,Sv}var _v,ZA;function Oee(){if(ZA)return _v;ZA=1;var e=Ri();function t(n,r){if(n!==r){var s=n!==void 0,o=n===null,l=n===n,c=e(n),d=r!==void 0,h=r===null,f=r===r,p=e(r);if(!h&&!p&&!c&&n>r||c&&d&&f&&!h&&!p||o&&d&&f||!s&&f||!l)return 1;if(!o&&!c&&!p&&n<r||p&&s&&l&&!o&&!c||h&&s&&l||!d&&l||!f)return-1}return 0}return _v=t,_v}var Ev,JA;function Lee(){if(JA)return Ev;JA=1;var e=Oee();function t(n,r,s){for(var o=-1,l=n.criteria,c=r.criteria,d=l.length,h=s.length;++o<d;){var f=e(l[o],c[o]);if(f){if(o>=h)return f;var p=s[o];return f*(p=="desc"?-1:1)}}return n.index-r.index}return Ev=t,Ev}var Tv,QA;function Pee(){if(QA)return Tv;QA=1;var e=Ch(),t=Rh(),n=ws(),r=tL(),s=Iee(),o=Sh(),l=Lee(),c=so(),d=jt();function h(f,p,g){p.length?p=e(p,function(k){return d(k)?function(x){return t(x,k.length===1?k[0]:k)}:k}):p=[c];var v=-1;p=e(p,o(n));var N=r(f,function(k,x,j){var b=e(p,function(_){return _(k)});return{criteria:b,index:++v,value:k}});return s(N,function(k,x){return l(k,x,g)})}return Tv=h,Tv}var Cv,eR;function Dee(){if(eR)return Cv;eR=1;var e=V0(),t=Pee(),n=Mh(),r=$h(),s=n(function(o,l){if(o==null)return[];var c=l.length;return c>1&&r(o,l[0],l[1])?l=[]:c>2&&r(l[0],l[1],l[2])&&(l=[l[0]]),t(o,e(l,1),[])});return Cv=s,Cv}var Av,tR;function Fee(){if(tR)return Av;tR=1;var e=KO(),t=0;function n(r){var s=++t;return e(r)+s}return Av=n,Av}var Rv,nR;function Bee(){if(nR)return Rv;nR=1;function e(t,n,r){for(var s=-1,o=t.length,l=n.length,c={};++s<o;){var d=s<l?n[s]:void 0;r(c,t[s],d)}return c}return Rv=e,Rv}var Mv,rR;function qee(){if(rR)return Mv;rR=1;var e=Nh(),t=Bee();function n(r,s){return t(r||[],s||[],e)}return Mv=n,Mv}var $v,sR;function dt(){if(sR)return $v;sR=1;var e;if(typeof R0=="function")try{e={cloneDeep:ree(),constant:q0(),defaults:see(),each:qO(),filter:JO(),find:dee(),flatten:mL(),forEach:BO(),forIn:hee(),has:QO(),isUndefined:eL(),last:fee(),map:nL(),mapValues:pee(),max:gee(),merge:kee(),min:Nee(),minBy:jee(),now:See(),pick:Aee(),range:$ee(),reduce:rL(),sortBy:Dee(),uniqueId:Fee(),values:lL(),zipObject:qee()}}catch{}return e||(e=window._),$v=e,$v}var Iv,aR;function Uee(){if(aR)return Iv;aR=1,Iv=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,o=s._prev;o!==s;)r.push(JSON.stringify(o,n)),o=o._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 Iv}var Ov,oR;function zee(){if(oR)return Ov;oR=1;var e=dt(),t=hr().Graph,n=Uee();Ov=s;var r=e.constant(1);function s(h,f){if(h.nodeCount()<=1)return[];var p=c(h,f||r),g=o(p.graph,p.buckets,p.zeroIdx);return e.flatten(e.map(g,function(v){return h.outEdges(v.v,v.w)}),!0)}function o(h,f,p){for(var g=[],v=f[f.length-1],N=f[0],k;h.nodeCount();){for(;k=N.dequeue();)l(h,f,p,k);for(;k=v.dequeue();)l(h,f,p,k);if(h.nodeCount()){for(var x=f.length-2;x>0;--x)if(k=f[x].dequeue(),k){g=g.concat(l(h,f,p,k,!0));break}}}return g}function l(h,f,p,g,v){var N=v?[]:void 0;return e.forEach(h.inEdges(g.v),function(k){var x=h.edge(k),j=h.node(k.v);v&&N.push({v:k.v,w:k.w}),j.out-=x,d(f,p,j)}),e.forEach(h.outEdges(g.v),function(k){var x=h.edge(k),j=k.w,b=h.node(j);b.in-=x,d(f,p,b)}),h.removeNode(g.v),N}function c(h,f){var p=new t,g=0,v=0;e.forEach(h.nodes(),function(x){p.setNode(x,{v:x,in:0,out:0})}),e.forEach(h.edges(),function(x){var j=p.edge(x.v,x.w)||0,b=f(x),_=j+b;p.setEdge(x.v,x.w,_),v=Math.max(v,p.node(x.v).out+=b),g=Math.max(g,p.node(x.w).in+=b)});var N=e.range(v+g+3).map(function(){return new n}),k=g+1;return e.forEach(p.nodes(),function(x){d(N,k,p.node(x))}),{graph:p,buckets:N,zeroIdx:k}}function d(h,f,p){p.out?p.in?h[p.out-p.in+f].enqueue(p):h[h.length-1].enqueue(p):h[0].enqueue(p)}return Ov}var Lv,iR;function Wee(){if(iR)return Lv;iR=1;var e=dt(),t=zee();Lv={run:n,undo:s};function n(o){var l=o.graph().acyclicer==="greedy"?t(o,c(o)):r(o);e.forEach(l,function(d){var h=o.edge(d);o.removeEdge(d),h.forwardName=d.name,h.reversed=!0,o.setEdge(d.w,d.v,h,e.uniqueId("rev"))});function c(d){return function(h){return d.edge(h).weight}}}function r(o){var l=[],c={},d={};function h(f){e.has(d,f)||(d[f]=!0,c[f]=!0,e.forEach(o.outEdges(f),function(p){e.has(c,p.w)?l.push(p):h(p.w)}),delete c[f])}return e.forEach(o.nodes(),h),l}function s(o){e.forEach(o.edges(),function(l){var c=o.edge(l);if(c.reversed){o.removeEdge(l);var d=c.forwardName;delete c.reversed,delete c.forwardName,o.setEdge(l.w,l.v,c,d)}})}return Lv}var Pv,lR;function fn(){if(lR)return Pv;lR=1;var e=dt(),t=hr().Graph;Pv={addDummyNode:n,simplify:r,asNonCompoundGraph:s,successorWeights:o,predecessorWeights:l,intersectRect:c,buildLayerMatrix:d,normalizeRanks:h,removeEmptyRanks:f,addBorderNode:p,maxRank:g,partition:v,time:N,notime:k};function n(x,j,b,_){var E;do E=e.uniqueId(_);while(x.hasNode(E));return b.dummy=j,x.setNode(E,b),E}function r(x){var j=new t().setGraph(x.graph());return e.forEach(x.nodes(),function(b){j.setNode(b,x.node(b))}),e.forEach(x.edges(),function(b){var _=j.edge(b.v,b.w)||{weight:0,minlen:1},E=x.edge(b);j.setEdge(b.v,b.w,{weight:_.weight+E.weight,minlen:Math.max(_.minlen,E.minlen)})}),j}function s(x){var j=new t({multigraph:x.isMultigraph()}).setGraph(x.graph());return e.forEach(x.nodes(),function(b){x.children(b).length||j.setNode(b,x.node(b))}),e.forEach(x.edges(),function(b){j.setEdge(b,x.edge(b))}),j}function o(x){var j=e.map(x.nodes(),function(b){var _={};return e.forEach(x.outEdges(b),function(E){_[E.w]=(_[E.w]||0)+x.edge(E).weight}),_});return e.zipObject(x.nodes(),j)}function l(x){var j=e.map(x.nodes(),function(b){var _={};return e.forEach(x.inEdges(b),function(E){_[E.v]=(_[E.v]||0)+x.edge(E).weight}),_});return e.zipObject(x.nodes(),j)}function c(x,j){var b=x.x,_=x.y,E=j.x-b,R=j.y-_,C=x.width/2,A=x.height/2;if(!E&&!R)throw new Error("Not possible to find intersection inside of the rectangle");var U,L;return Math.abs(R)*C>Math.abs(E)*A?(R<0&&(A=-A),U=A*E/R,L=A):(E<0&&(C=-C),U=C,L=C*R/E),{x:b+U,y:_+L}}function d(x){var j=e.map(e.range(g(x)+1),function(){return[]});return e.forEach(x.nodes(),function(b){var _=x.node(b),E=_.rank;e.isUndefined(E)||(j[E][_.order]=b)}),j}function h(x){var j=e.min(e.map(x.nodes(),function(b){return x.node(b).rank}));e.forEach(x.nodes(),function(b){var _=x.node(b);e.has(_,"rank")&&(_.rank-=j)})}function f(x){var j=e.min(e.map(x.nodes(),function(R){return x.node(R).rank})),b=[];e.forEach(x.nodes(),function(R){var C=x.node(R).rank-j;b[C]||(b[C]=[]),b[C].push(R)});var _=0,E=x.graph().nodeRankFactor;e.forEach(b,function(R,C){e.isUndefined(R)&&C%E!==0?--_:_&&e.forEach(R,function(A){x.node(A).rank+=_})})}function p(x,j,b,_){var E={width:0,height:0};return arguments.length>=4&&(E.rank=b,E.order=_),n(x,"border",E,j)}function g(x){return e.max(e.map(x.nodes(),function(j){var b=x.node(j).rank;if(!e.isUndefined(b))return b}))}function v(x,j){var b={lhs:[],rhs:[]};return e.forEach(x,function(_){j(_)?b.lhs.push(_):b.rhs.push(_)}),b}function N(x,j){var b=e.now();try{return j()}finally{console.log(x+" time: "+(e.now()-b)+"ms")}}function k(x,j){return j()}return Pv}var Dv,cR;function Hee(){if(cR)return Dv;cR=1;var e=dt(),t=fn();Dv={run:n,undo:s};function n(o){o.graph().dummyChains=[],e.forEach(o.edges(),function(l){r(o,l)})}function r(o,l){var c=l.v,d=o.node(c).rank,h=l.w,f=o.node(h).rank,p=l.name,g=o.edge(l),v=g.labelRank;if(f!==d+1){o.removeEdge(l);var N,k,x;for(x=0,++d;d<f;++x,++d)g.points=[],k={width:0,height:0,edgeLabel:g,edgeObj:l,rank:d},N=t.addDummyNode(o,"edge",k,"_d"),d===v&&(k.width=g.width,k.height=g.height,k.dummy="edge-label",k.labelpos=g.labelpos),o.setEdge(c,N,{weight:g.weight},p),x===0&&o.graph().dummyChains.push(N),c=N;o.setEdge(c,h,{weight:g.weight},p)}}function s(o){e.forEach(o.graph().dummyChains,function(l){var c=o.node(l),d=c.edgeLabel,h;for(o.setEdge(c.edgeObj,d);c.dummy;)h=o.successors(l)[0],o.removeNode(l),d.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(d.x=c.x,d.y=c.y,d.width=c.width,d.height=c.height),l=h,c=o.node(l)})}return Dv}var Fv,uR;function Od(){if(uR)return Fv;uR=1;var e=dt();Fv={longestPath:t,slack:n};function t(r){var s={};function o(l){var c=r.node(l);if(e.has(s,l))return c.rank;s[l]=!0;var d=e.min(e.map(r.outEdges(l),function(h){return o(h.w)-r.edge(h).minlen}));return(d===Number.POSITIVE_INFINITY||d===void 0||d===null)&&(d=0),c.rank=d}e.forEach(r.sources(),o)}function n(r,s){return r.node(s.w).rank-r.node(s.v).rank-r.edge(s).minlen}return Fv}var Bv,dR;function vL(){if(dR)return Bv;dR=1;var e=dt(),t=hr().Graph,n=Od().slack;Bv=r;function r(c){var d=new t({directed:!1}),h=c.nodes()[0],f=c.nodeCount();d.setNode(h,{});for(var p,g;s(d,c)<f;)p=o(d,c),g=d.hasNode(p.v)?n(c,p):-n(c,p),l(d,c,g);return d}function s(c,d){function h(f){e.forEach(d.nodeEdges(f),function(p){var g=p.v,v=f===g?p.w:g;!c.hasNode(v)&&!n(d,p)&&(c.setNode(v,{}),c.setEdge(f,v,{}),h(v))})}return e.forEach(c.nodes(),h),c.nodeCount()}function o(c,d){return e.minBy(d.edges(),function(h){if(c.hasNode(h.v)!==c.hasNode(h.w))return n(d,h)})}function l(c,d,h){e.forEach(c.nodes(),function(f){d.node(f).rank+=h})}return Bv}var qv,hR;function Vee(){if(hR)return qv;hR=1;var e=dt(),t=vL(),n=Od().slack,r=Od().longestPath,s=hr().alg.preorder,o=hr().alg.postorder,l=fn().simplify;qv=c,c.initLowLimValues=p,c.initCutValues=d,c.calcCutValue=f,c.leaveEdge=v,c.enterEdge=N,c.exchangeEdges=k;function c(_){_=l(_),r(_);var E=t(_);p(E),d(E,_);for(var R,C;R=v(E);)C=N(E,_,R),k(E,_,R,C)}function d(_,E){var R=o(_,_.nodes());R=R.slice(0,R.length-1),e.forEach(R,function(C){h(_,E,C)})}function h(_,E,R){var C=_.node(R),A=C.parent;_.edge(R,A).cutvalue=f(_,E,R)}function f(_,E,R){var C=_.node(R),A=C.parent,U=!0,L=E.edge(R,A),F=0;return L||(U=!1,L=E.edge(A,R)),F=L.weight,e.forEach(E.nodeEdges(R),function(O){var I=O.v===R,B=I?O.w:O.v;if(B!==A){var M=I===U,$=E.edge(O).weight;if(F+=M?$:-$,j(_,R,B)){var P=_.edge(R,B).cutvalue;F+=M?-P:P}}}),F}function p(_,E){arguments.length<2&&(E=_.nodes()[0]),g(_,{},1,E)}function g(_,E,R,C,A){var U=R,L=_.node(C);return E[C]=!0,e.forEach(_.neighbors(C),function(F){e.has(E,F)||(R=g(_,E,R,F,C))}),L.low=U,L.lim=R++,A?L.parent=A:delete L.parent,R}function v(_){return e.find(_.edges(),function(E){return _.edge(E).cutvalue<0})}function N(_,E,R){var C=R.v,A=R.w;E.hasEdge(C,A)||(C=R.w,A=R.v);var U=_.node(C),L=_.node(A),F=U,O=!1;U.lim>L.lim&&(F=L,O=!0);var I=e.filter(E.edges(),function(B){return O===b(_,_.node(B.v),F)&&O!==b(_,_.node(B.w),F)});return e.minBy(I,function(B){return n(E,B)})}function k(_,E,R,C){var A=R.v,U=R.w;_.removeEdge(A,U),_.setEdge(C.v,C.w,{}),p(_),d(_,E),x(_,E)}function x(_,E){var R=e.find(_.nodes(),function(A){return!E.node(A).parent}),C=s(_,R);C=C.slice(1),e.forEach(C,function(A){var U=_.node(A).parent,L=E.edge(A,U),F=!1;L||(L=E.edge(U,A),F=!0),E.node(A).rank=E.node(U).rank+(F?L.minlen:-L.minlen)})}function j(_,E,R){return _.hasEdge(E,R)}function b(_,E,R){return R.low<=E.lim&&E.lim<=R.lim}return qv}var Uv,fR;function Gee(){if(fR)return Uv;fR=1;var e=Od(),t=e.longestPath,n=vL(),r=Vee();Uv=s;function s(d){switch(d.graph().ranker){case"network-simplex":c(d);break;case"tight-tree":l(d);break;case"longest-path":o(d);break;default:c(d)}}var o=t;function l(d){t(d),n(d)}function c(d){r(d)}return Uv}var zv,pR;function Kee(){if(pR)return zv;pR=1;var e=dt();zv=t;function t(s){var o=r(s);e.forEach(s.graph().dummyChains,function(l){for(var c=s.node(l),d=c.edgeObj,h=n(s,o,d.v,d.w),f=h.path,p=h.lca,g=0,v=f[g],N=!0;l!==d.w;){if(c=s.node(l),N){for(;(v=f[g])!==p&&s.node(v).maxRank<c.rank;)g++;v===p&&(N=!1)}if(!N){for(;g<f.length-1&&s.node(v=f[g+1]).minRank<=c.rank;)g++;v=f[g]}s.setParent(l,v),l=s.successors(l)[0]}})}function n(s,o,l,c){var d=[],h=[],f=Math.min(o[l].low,o[c].low),p=Math.max(o[l].lim,o[c].lim),g,v;g=l;do g=s.parent(g),d.push(g);while(g&&(o[g].low>f||p>o[g].lim));for(v=g,g=c;(g=s.parent(g))!==v;)h.push(g);return{path:d.concat(h.reverse()),lca:v}}function r(s){var o={},l=0;function c(d){var h=l;e.forEach(s.children(d),c),o[d]={low:h,lim:l++}}return e.forEach(s.children(),c),o}return zv}var Wv,mR;function Yee(){if(mR)return Wv;mR=1;var e=dt(),t=fn();Wv={run:n,cleanup:l};function n(c){var d=t.addDummyNode(c,"root",{},"_root"),h=s(c),f=e.max(e.values(h))-1,p=2*f+1;c.graph().nestingRoot=d,e.forEach(c.edges(),function(v){c.edge(v).minlen*=p});var g=o(c)+1;e.forEach(c.children(),function(v){r(c,d,p,g,f,h,v)}),c.graph().nodeRankFactor=p}function r(c,d,h,f,p,g,v){var N=c.children(v);if(!N.length){v!==d&&c.setEdge(d,v,{weight:0,minlen:h});return}var k=t.addBorderNode(c,"_bt"),x=t.addBorderNode(c,"_bb"),j=c.node(v);c.setParent(k,v),j.borderTop=k,c.setParent(x,v),j.borderBottom=x,e.forEach(N,function(b){r(c,d,h,f,p,g,b);var _=c.node(b),E=_.borderTop?_.borderTop:b,R=_.borderBottom?_.borderBottom:b,C=_.borderTop?f:2*f,A=E!==R?1:p-g[v]+1;c.setEdge(k,E,{weight:C,minlen:A,nestingEdge:!0}),c.setEdge(R,x,{weight:C,minlen:A,nestingEdge:!0})}),c.parent(v)||c.setEdge(d,k,{weight:0,minlen:p+g[v]})}function s(c){var d={};function h(f,p){var g=c.children(f);g&&g.length&&e.forEach(g,function(v){h(v,p+1)}),d[f]=p}return e.forEach(c.children(),function(f){h(f,1)}),d}function o(c){return e.reduce(c.edges(),function(d,h){return d+c.edge(h).weight},0)}function l(c){var d=c.graph();c.removeNode(d.nestingRoot),delete d.nestingRoot,e.forEach(c.edges(),function(h){var f=c.edge(h);f.nestingEdge&&c.removeEdge(h)})}return Wv}var Hv,gR;function Xee(){if(gR)return Hv;gR=1;var e=dt(),t=fn();Hv=n;function n(s){function o(l){var c=s.children(l),d=s.node(l);if(c.length&&e.forEach(c,o),e.has(d,"minRank")){d.borderLeft=[],d.borderRight=[];for(var h=d.minRank,f=d.maxRank+1;h<f;++h)r(s,"borderLeft","_bl",l,d,h),r(s,"borderRight","_br",l,d,h)}}e.forEach(s.children(),o)}function r(s,o,l,c,d,h){var f={width:0,height:0,rank:h,borderType:o},p=d[o][h-1],g=t.addDummyNode(s,"border",f,l);d[o][h]=g,s.setParent(g,c),p&&s.setEdge(p,g,{weight:1})}return Hv}var Vv,yR;function Zee(){if(yR)return Vv;yR=1;var e=dt();Vv={adjust:t,undo:n};function t(h){var f=h.graph().rankdir.toLowerCase();(f==="lr"||f==="rl")&&r(h)}function n(h){var f=h.graph().rankdir.toLowerCase();(f==="bt"||f==="rl")&&o(h),(f==="lr"||f==="rl")&&(c(h),r(h))}function r(h){e.forEach(h.nodes(),function(f){s(h.node(f))}),e.forEach(h.edges(),function(f){s(h.edge(f))})}function s(h){var f=h.width;h.width=h.height,h.height=f}function o(h){e.forEach(h.nodes(),function(f){l(h.node(f))}),e.forEach(h.edges(),function(f){var p=h.edge(f);e.forEach(p.points,l),e.has(p,"y")&&l(p)})}function l(h){h.y=-h.y}function c(h){e.forEach(h.nodes(),function(f){d(h.node(f))}),e.forEach(h.edges(),function(f){var p=h.edge(f);e.forEach(p.points,d),e.has(p,"x")&&d(p)})}function d(h){var f=h.x;h.x=h.y,h.y=f}return Vv}var Gv,wR;function Jee(){if(wR)return Gv;wR=1;var e=dt();Gv=t;function t(n){var r={},s=e.filter(n.nodes(),function(h){return!n.children(h).length}),o=e.max(e.map(s,function(h){return n.node(h).rank})),l=e.map(e.range(o+1),function(){return[]});function c(h){if(!e.has(r,h)){r[h]=!0;var f=n.node(h);l[f.rank].push(h),e.forEach(n.successors(h),c)}}var d=e.sortBy(s,function(h){return n.node(h).rank});return e.forEach(d,c),l}return Gv}var Kv,vR;function Qee(){if(vR)return Kv;vR=1;var e=dt();Kv=t;function t(r,s){for(var o=0,l=1;l<s.length;++l)o+=n(r,s[l-1],s[l]);return o}function n(r,s,o){for(var l=e.zipObject(o,e.map(o,function(g,v){return v})),c=e.flatten(e.map(s,function(g){return e.sortBy(e.map(r.outEdges(g),function(v){return{pos:l[v.w],weight:r.edge(v).weight}}),"pos")}),!0),d=1;d<o.length;)d<<=1;var h=2*d-1;d-=1;var f=e.map(new Array(h),function(){return 0}),p=0;return e.forEach(c.forEach(function(g){var v=g.pos+d;f[v]+=g.weight;for(var N=0;v>0;)v%2&&(N+=f[v+1]),v=v-1>>1,f[v]+=g.weight;p+=g.weight*N})),p}return Kv}var Yv,xR;function ete(){if(xR)return Yv;xR=1;var e=dt();Yv=t;function t(n,r){return e.map(r,function(s){var o=n.inEdges(s);if(o.length){var l=e.reduce(o,function(c,d){var h=n.edge(d),f=n.node(d.v);return{sum:c.sum+h.weight*f.order,weight:c.weight+h.weight}},{sum:0,weight:0});return{v:s,barycenter:l.sum/l.weight,weight:l.weight}}else return{v:s}})}return Yv}var Xv,bR;function tte(){if(bR)return Xv;bR=1;var e=dt();Xv=t;function t(s,o){var l={};e.forEach(s,function(d,h){var f=l[d.v]={indegree:0,in:[],out:[],vs:[d.v],i:h};e.isUndefined(d.barycenter)||(f.barycenter=d.barycenter,f.weight=d.weight)}),e.forEach(o.edges(),function(d){var h=l[d.v],f=l[d.w];!e.isUndefined(h)&&!e.isUndefined(f)&&(f.indegree++,h.out.push(l[d.w]))});var c=e.filter(l,function(d){return!d.indegree});return n(c)}function n(s){var o=[];function l(h){return function(f){f.merged||(e.isUndefined(f.barycenter)||e.isUndefined(h.barycenter)||f.barycenter>=h.barycenter)&&r(h,f)}}function c(h){return function(f){f.in.push(h),--f.indegree===0&&s.push(f)}}for(;s.length;){var d=s.pop();o.push(d),e.forEach(d.in.reverse(),l(d)),e.forEach(d.out,c(d))}return e.map(e.filter(o,function(h){return!h.merged}),function(h){return e.pick(h,["vs","i","barycenter","weight"])})}function r(s,o){var l=0,c=0;s.weight&&(l+=s.barycenter*s.weight,c+=s.weight),o.weight&&(l+=o.barycenter*o.weight,c+=o.weight),s.vs=o.vs.concat(s.vs),s.barycenter=l/c,s.weight=c,s.i=Math.min(o.i,s.i),o.merged=!0}return Xv}var Zv,kR;function nte(){if(kR)return Zv;kR=1;var e=dt(),t=fn();Zv=n;function n(o,l){var c=t.partition(o,function(k){return e.has(k,"barycenter")}),d=c.lhs,h=e.sortBy(c.rhs,function(k){return-k.i}),f=[],p=0,g=0,v=0;d.sort(s(!!l)),v=r(f,h,v),e.forEach(d,function(k){v+=k.vs.length,f.push(k.vs),p+=k.barycenter*k.weight,g+=k.weight,v=r(f,h,v)});var N={vs:e.flatten(f,!0)};return g&&(N.barycenter=p/g,N.weight=g),N}function r(o,l,c){for(var d;l.length&&(d=e.last(l)).i<=c;)l.pop(),o.push(d.vs),c++;return c}function s(o){return function(l,c){return l.barycenter<c.barycenter?-1:l.barycenter>c.barycenter?1:o?c.i-l.i:l.i-c.i}}return Zv}var Jv,NR;function rte(){if(NR)return Jv;NR=1;var e=dt(),t=ete(),n=tte(),r=nte();Jv=s;function s(c,d,h,f){var p=c.children(d),g=c.node(d),v=g?g.borderLeft:void 0,N=g?g.borderRight:void 0,k={};v&&(p=e.filter(p,function(R){return R!==v&&R!==N}));var x=t(c,p);e.forEach(x,function(R){if(c.children(R.v).length){var C=s(c,R.v,h,f);k[R.v]=C,e.has(C,"barycenter")&&l(R,C)}});var j=n(x,h);o(j,k);var b=r(j,f);if(v&&(b.vs=e.flatten([v,b.vs,N],!0),c.predecessors(v).length)){var _=c.node(c.predecessors(v)[0]),E=c.node(c.predecessors(N)[0]);e.has(b,"barycenter")||(b.barycenter=0,b.weight=0),b.barycenter=(b.barycenter*b.weight+_.order+E.order)/(b.weight+2),b.weight+=2}return b}function o(c,d){e.forEach(c,function(h){h.vs=e.flatten(h.vs.map(function(f){return d[f]?d[f].vs:f}),!0)})}function l(c,d){e.isUndefined(c.barycenter)?(c.barycenter=d.barycenter,c.weight=d.weight):(c.barycenter=(c.barycenter*c.weight+d.barycenter*d.weight)/(c.weight+d.weight),c.weight+=d.weight)}return Jv}var Qv,jR;function ste(){if(jR)return Qv;jR=1;var e=dt(),t=hr().Graph;Qv=n;function n(s,o,l){var c=r(s),d=new t({compound:!0}).setGraph({root:c}).setDefaultNodeLabel(function(h){return s.node(h)});return e.forEach(s.nodes(),function(h){var f=s.node(h),p=s.parent(h);(f.rank===o||f.minRank<=o&&o<=f.maxRank)&&(d.setNode(h),d.setParent(h,p||c),e.forEach(s[l](h),function(g){var v=g.v===h?g.w:g.v,N=d.edge(v,h),k=e.isUndefined(N)?0:N.weight;d.setEdge(v,h,{weight:s.edge(g).weight+k})}),e.has(f,"minRank")&&d.setNode(h,{borderLeft:f.borderLeft[o],borderRight:f.borderRight[o]}))}),d}function r(s){for(var o;s.hasNode(o=e.uniqueId("_root")););return o}return Qv}var ex,SR;function ate(){if(SR)return ex;SR=1;var e=dt();ex=t;function t(n,r,s){var o={},l;e.forEach(s,function(c){for(var d=n.parent(c),h,f;d;){if(h=n.parent(d),h?(f=o[h],o[h]=d):(f=l,l=d),f&&f!==d){r.setEdge(f,d);return}d=h}})}return ex}var tx,_R;function ote(){if(_R)return tx;_R=1;var e=dt(),t=Jee(),n=Qee(),r=rte(),s=ste(),o=ate(),l=hr().Graph,c=fn();tx=d;function d(g){var v=c.maxRank(g),N=h(g,e.range(1,v+1),"inEdges"),k=h(g,e.range(v-1,-1,-1),"outEdges"),x=t(g);p(g,x);for(var j=Number.POSITIVE_INFINITY,b,_=0,E=0;E<4;++_,++E){f(_%2?N:k,_%4>=2),x=c.buildLayerMatrix(g);var R=n(g,x);R<j&&(E=0,b=e.cloneDeep(x),j=R)}p(g,b)}function h(g,v,N){return e.map(v,function(k){return s(g,k,N)})}function f(g,v){var N=new l;e.forEach(g,function(k){var x=k.graph().root,j=r(k,x,N,v);e.forEach(j.vs,function(b,_){k.node(b).order=_}),o(k,N,j.vs)})}function p(g,v){e.forEach(v,function(N){e.forEach(N,function(k,x){g.node(k).order=x})})}return tx}var nx,ER;function ite(){if(ER)return nx;ER=1;var e=dt(),t=hr().Graph,n=fn();nx={positionX:N,findType1Conflicts:r,findType2Conflicts:s,addConflict:l,hasConflict:c,verticalAlignment:d,horizontalCompaction:h,alignCoordinates:g,findSmallestWidthAlignment:p,balance:v};function r(j,b){var _={};function E(R,C){var A=0,U=0,L=R.length,F=e.last(C);return e.forEach(C,function(O,I){var B=o(j,O),M=B?j.node(B).order:L;(B||O===F)&&(e.forEach(C.slice(U,I+1),function($){e.forEach(j.predecessors($),function(P){var G=j.node(P),K=G.order;(K<A||M<K)&&!(G.dummy&&j.node($).dummy)&&l(_,P,$)})}),U=I+1,A=M)}),C}return e.reduce(b,E),_}function s(j,b){var _={};function E(C,A,U,L,F){var O;e.forEach(e.range(A,U),function(I){O=C[I],j.node(O).dummy&&e.forEach(j.predecessors(O),function(B){var M=j.node(B);M.dummy&&(M.order<L||M.order>F)&&l(_,B,O)})})}function R(C,A){var U=-1,L,F=0;return e.forEach(A,function(O,I){if(j.node(O).dummy==="border"){var B=j.predecessors(O);B.length&&(L=j.node(B[0]).order,E(A,F,I,U,L),F=I,U=L)}E(A,F,A.length,L,C.length)}),A}return e.reduce(b,R),_}function o(j,b){if(j.node(b).dummy)return e.find(j.predecessors(b),function(_){return j.node(_).dummy})}function l(j,b,_){if(b>_){var E=b;b=_,_=E}var R=j[b];R||(j[b]=R={}),R[_]=!0}function c(j,b,_){if(b>_){var E=b;b=_,_=E}return e.has(j[b],_)}function d(j,b,_,E){var R={},C={},A={};return e.forEach(b,function(U){e.forEach(U,function(L,F){R[L]=L,C[L]=L,A[L]=F})}),e.forEach(b,function(U){var L=-1;e.forEach(U,function(F){var O=E(F);if(O.length){O=e.sortBy(O,function(P){return A[P]});for(var I=(O.length-1)/2,B=Math.floor(I),M=Math.ceil(I);B<=M;++B){var $=O[B];C[F]===F&&L<A[$]&&!c(_,F,$)&&(C[$]=F,C[F]=R[F]=R[$],L=A[$])}}})}),{root:R,align:C}}function h(j,b,_,E,R){var C={},A=f(j,b,_,R),U=R?"borderLeft":"borderRight";function L(I,B){for(var M=A.nodes(),$=M.pop(),P={};$;)P[$]?I($):(P[$]=!0,M.push($),M=M.concat(B($))),$=M.pop()}function F(I){C[I]=A.inEdges(I).reduce(function(B,M){return Math.max(B,C[M.v]+A.edge(M))},0)}function O(I){var B=A.outEdges(I).reduce(function($,P){return Math.min($,C[P.w]-A.edge(P))},Number.POSITIVE_INFINITY),M=j.node(I);B!==Number.POSITIVE_INFINITY&&M.borderType!==U&&(C[I]=Math.max(C[I],B))}return L(F,A.predecessors.bind(A)),L(O,A.successors.bind(A)),e.forEach(E,function(I){C[I]=C[_[I]]}),C}function f(j,b,_,E){var R=new t,C=j.graph(),A=k(C.nodesep,C.edgesep,E);return e.forEach(b,function(U){var L;e.forEach(U,function(F){var O=_[F];if(R.setNode(O),L){var I=_[L],B=R.edge(I,O);R.setEdge(I,O,Math.max(A(j,F,L),B||0))}L=F})}),R}function p(j,b){return e.minBy(e.values(b),function(_){var E=Number.NEGATIVE_INFINITY,R=Number.POSITIVE_INFINITY;return e.forIn(_,function(C,A){var U=x(j,A)/2;E=Math.max(C+U,E),R=Math.min(C-U,R)}),E-R})}function g(j,b){var _=e.values(b),E=e.min(_),R=e.max(_);e.forEach(["u","d"],function(C){e.forEach(["l","r"],function(A){var U=C+A,L=j[U],F;if(L!==b){var O=e.values(L);F=A==="l"?E-e.min(O):R-e.max(O),F&&(j[U]=e.mapValues(L,function(I){return I+F}))}})})}function v(j,b){return e.mapValues(j.ul,function(_,E){if(b)return j[b.toLowerCase()][E];var R=e.sortBy(e.map(j,E));return(R[1]+R[2])/2})}function N(j){var b=n.buildLayerMatrix(j),_=e.merge(r(j,b),s(j,b)),E={},R;e.forEach(["u","d"],function(A){R=A==="u"?b:e.values(b).reverse(),e.forEach(["l","r"],function(U){U==="r"&&(R=e.map(R,function(I){return e.values(I).reverse()}));var L=(A==="u"?j.predecessors:j.successors).bind(j),F=d(j,R,_,L),O=h(j,R,F.root,F.align,U==="r");U==="r"&&(O=e.mapValues(O,function(I){return-I})),E[A+U]=O})});var C=p(j,E);return g(E,C),v(E,j.graph().align)}function k(j,b,_){return function(E,R,C){var A=E.node(R),U=E.node(C),L=0,F;if(L+=A.width/2,e.has(A,"labelpos"))switch(A.labelpos.toLowerCase()){case"l":F=-A.width/2;break;case"r":F=A.width/2;break}if(F&&(L+=_?F:-F),F=0,L+=(A.dummy?b:j)/2,L+=(U.dummy?b:j)/2,L+=U.width/2,e.has(U,"labelpos"))switch(U.labelpos.toLowerCase()){case"l":F=U.width/2;break;case"r":F=-U.width/2;break}return F&&(L+=_?F:-F),F=0,L}}function x(j,b){return j.node(b).width}return nx}var rx,TR;function lte(){if(TR)return rx;TR=1;var e=dt(),t=fn(),n=ite().positionX;rx=r;function r(o){o=t.asNonCompoundGraph(o),s(o),e.forEach(n(o),function(l,c){o.node(c).x=l})}function s(o){var l=t.buildLayerMatrix(o),c=o.graph().ranksep,d=0;e.forEach(l,function(h){var f=e.max(e.map(h,function(p){return o.node(p).height}));e.forEach(h,function(p){o.node(p).y=d+f/2}),d+=f+c})}return rx}var sx,CR;function cte(){if(CR)return sx;CR=1;var e=dt(),t=Wee(),n=Hee(),r=Gee(),s=fn().normalizeRanks,o=Kee(),l=fn().removeEmptyRanks,c=Yee(),d=Xee(),h=Zee(),f=ote(),p=lte(),g=fn(),v=hr().Graph;sx=N;function N(V,X){var Y=X&&X.debugTiming?g.time:g.notime;Y("layout",function(){var Z=Y(" buildLayoutGraph",function(){return L(V)});Y(" runLayout",function(){k(Z,Y)}),Y(" updateInputGraph",function(){x(V,Z)})})}function k(V,X){X(" makeSpaceForEdgeLabels",function(){F(V)}),X(" removeSelfEdges",function(){q(V)}),X(" acyclic",function(){t.run(V)}),X(" nestingGraph.run",function(){c.run(V)}),X(" rank",function(){r(g.asNonCompoundGraph(V))}),X(" injectEdgeLabelProxies",function(){O(V)}),X(" removeEmptyRanks",function(){l(V)}),X(" nestingGraph.cleanup",function(){c.cleanup(V)}),X(" normalizeRanks",function(){s(V)}),X(" assignRankMinMax",function(){I(V)}),X(" removeEdgeLabelProxies",function(){B(V)}),X(" normalize.run",function(){n.run(V)}),X(" parentDummyChains",function(){o(V)}),X(" addBorderSegments",function(){d(V)}),X(" order",function(){f(V)}),X(" insertSelfEdges",function(){H(V)}),X(" adjustCoordinateSystem",function(){h.adjust(V)}),X(" position",function(){p(V)}),X(" positionSelfEdges",function(){D(V)}),X(" removeBorderNodes",function(){K(V)}),X(" normalize.undo",function(){n.undo(V)}),X(" fixupEdgeLabelCoords",function(){P(V)}),X(" undoCoordinateSystem",function(){h.undo(V)}),X(" translateGraph",function(){M(V)}),X(" assignNodeIntersects",function(){$(V)}),X(" reversePoints",function(){G(V)}),X(" acyclic.undo",function(){t.undo(V)})}function x(V,X){e.forEach(V.nodes(),function(Y){var Z=V.node(Y),ee=X.node(Y);Z&&(Z.x=ee.x,Z.y=ee.y,X.children(Y).length&&(Z.width=ee.width,Z.height=ee.height))}),e.forEach(V.edges(),function(Y){var Z=V.edge(Y),ee=X.edge(Y);Z.points=ee.points,e.has(ee,"x")&&(Z.x=ee.x,Z.y=ee.y)}),V.graph().width=X.graph().width,V.graph().height=X.graph().height}var j=["nodesep","edgesep","ranksep","marginx","marginy"],b={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},_=["acyclicer","ranker","rankdir","align"],E=["width","height"],R={width:0,height:0},C=["minlen","weight","width","height","labeloffset"],A={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},U=["labelpos"];function L(V){var X=new v({multigraph:!0,compound:!0}),Y=J(V.graph());return X.setGraph(e.merge({},b,W(Y,j),e.pick(Y,_))),e.forEach(V.nodes(),function(Z){var ee=J(V.node(Z));X.setNode(Z,e.defaults(W(ee,E),R)),X.setParent(Z,V.parent(Z))}),e.forEach(V.edges(),function(Z){var ee=J(V.edge(Z));X.setEdge(Z,e.merge({},A,W(ee,C),e.pick(ee,U)))}),X}function F(V){var X=V.graph();X.ranksep/=2,e.forEach(V.edges(),function(Y){var Z=V.edge(Y);Z.minlen*=2,Z.labelpos.toLowerCase()!=="c"&&(X.rankdir==="TB"||X.rankdir==="BT"?Z.width+=Z.labeloffset:Z.height+=Z.labeloffset)})}function O(V){e.forEach(V.edges(),function(X){var Y=V.edge(X);if(Y.width&&Y.height){var Z=V.node(X.v),ee=V.node(X.w),ne={rank:(ee.rank-Z.rank)/2+Z.rank,e:X};g.addDummyNode(V,"edge-proxy",ne,"_ep")}})}function I(V){var X=0;e.forEach(V.nodes(),function(Y){var Z=V.node(Y);Z.borderTop&&(Z.minRank=V.node(Z.borderTop).rank,Z.maxRank=V.node(Z.borderBottom).rank,X=e.max(X,Z.maxRank))}),V.graph().maxRank=X}function B(V){e.forEach(V.nodes(),function(X){var Y=V.node(X);Y.dummy==="edge-proxy"&&(V.edge(Y.e).labelRank=Y.rank,V.removeNode(X))})}function M(V){var X=Number.POSITIVE_INFINITY,Y=0,Z=Number.POSITIVE_INFINITY,ee=0,ne=V.graph(),se=ne.marginx||0,pe=ne.marginy||0;function ke(ae){var fe=ae.x,me=ae.y,he=ae.width,ge=ae.height;X=Math.min(X,fe-he/2),Y=Math.max(Y,fe+he/2),Z=Math.min(Z,me-ge/2),ee=Math.max(ee,me+ge/2)}e.forEach(V.nodes(),function(ae){ke(V.node(ae))}),e.forEach(V.edges(),function(ae){var fe=V.edge(ae);e.has(fe,"x")&&ke(fe)}),X-=se,Z-=pe,e.forEach(V.nodes(),function(ae){var fe=V.node(ae);fe.x-=X,fe.y-=Z}),e.forEach(V.edges(),function(ae){var fe=V.edge(ae);e.forEach(fe.points,function(me){me.x-=X,me.y-=Z}),e.has(fe,"x")&&(fe.x-=X),e.has(fe,"y")&&(fe.y-=Z)}),ne.width=Y-X+se,ne.height=ee-Z+pe}function $(V){e.forEach(V.edges(),function(X){var Y=V.edge(X),Z=V.node(X.v),ee=V.node(X.w),ne,se;Y.points?(ne=Y.points[0],se=Y.points[Y.points.length-1]):(Y.points=[],ne=ee,se=Z),Y.points.unshift(g.intersectRect(Z,ne)),Y.points.push(g.intersectRect(ee,se))})}function P(V){e.forEach(V.edges(),function(X){var Y=V.edge(X);if(e.has(Y,"x"))switch((Y.labelpos==="l"||Y.labelpos==="r")&&(Y.width-=Y.labeloffset),Y.labelpos){case"l":Y.x-=Y.width/2+Y.labeloffset;break;case"r":Y.x+=Y.width/2+Y.labeloffset;break}})}function G(V){e.forEach(V.edges(),function(X){var Y=V.edge(X);Y.reversed&&Y.points.reverse()})}function K(V){e.forEach(V.nodes(),function(X){if(V.children(X).length){var Y=V.node(X),Z=V.node(Y.borderTop),ee=V.node(Y.borderBottom),ne=V.node(e.last(Y.borderLeft)),se=V.node(e.last(Y.borderRight));Y.width=Math.abs(se.x-ne.x),Y.height=Math.abs(ee.y-Z.y),Y.x=ne.x+Y.width/2,Y.y=Z.y+Y.height/2}}),e.forEach(V.nodes(),function(X){V.node(X).dummy==="border"&&V.removeNode(X)})}function q(V){e.forEach(V.edges(),function(X){if(X.v===X.w){var Y=V.node(X.v);Y.selfEdges||(Y.selfEdges=[]),Y.selfEdges.push({e:X,label:V.edge(X)}),V.removeEdge(X)}})}function H(V){var X=g.buildLayerMatrix(V);e.forEach(X,function(Y){var Z=0;e.forEach(Y,function(ee,ne){var se=V.node(ee);se.order=ne+Z,e.forEach(se.selfEdges,function(pe){g.addDummyNode(V,"selfedge",{width:pe.label.width,height:pe.label.height,rank:se.rank,order:ne+ ++Z,e:pe.e,label:pe.label},"_se")}),delete se.selfEdges})})}function D(V){e.forEach(V.nodes(),function(X){var Y=V.node(X);if(Y.dummy==="selfedge"){var Z=V.node(Y.e.v),ee=Z.x+Z.width/2,ne=Z.y,se=Y.x-ee,pe=Z.height/2;V.setEdge(Y.e,Y.label),V.removeNode(X),Y.label.points=[{x:ee+2*se/3,y:ne-pe},{x:ee+5*se/6,y:ne-pe},{x:ee+se,y:ne},{x:ee+5*se/6,y:ne+pe},{x:ee+2*se/3,y:ne+pe}],Y.label.x=Y.x,Y.label.y=Y.y}})}function W(V,X){return e.mapValues(e.pick(V,X),Number)}function J(V){var X={};return e.forEach(V,function(Y,Z){X[Z.toLowerCase()]=Y}),X}return sx}var ax,AR;function ute(){if(AR)return ax;AR=1;var e=dt(),t=fn(),n=hr().Graph;ax={debugOrdering:r};function r(s){var o=t.buildLayerMatrix(s),l=new n({compound:!0,multigraph:!0}).setGraph({});return e.forEach(s.nodes(),function(c){l.setNode(c,{label:c}),l.setParent(c,"layer"+s.node(c).rank)}),e.forEach(s.edges(),function(c){l.setEdge(c.v,c.w,{},c.name)}),e.forEach(o,function(c,d){var h="layer"+d;l.setNode(h,{rank:"same"}),e.reduce(c,function(f,p){return l.setEdge(f,p,{style:"invis"}),p})}),l}return ax}var ox,RR;function dte(){return RR||(RR=1,ox="0.8.5"),ox}var ix,MR;function hte(){return MR||(MR=1,ix={graphlib:hr(),layout:cte(),debug:ute(),util:{time:fn().time,notime:fn().notime},version:dte()}),ix}var fte=hte();const $R=Tb(fte),nc=240,xL=130,pb=Ua*2+qx+K$,pte=72,ii=pb+pte,id=24,bL=Ua*2+id,Ld=ii;function kL(e,t){var r;let n=nc;for(const s of e)n=Math.max(n,((r=t.get(s.id))==null?void 0:r.width)??nc);return n}const Pd=420,NL=1;function mte(e,t,n,r){return Math.min(NL,n/Math.max(1,e),r/Math.max(1,t))}function Ih(e){var n;return((n=e.data)==null?void 0:n.sessionId)??"_default"}function Oh(e,t=()=>!0){const n=new Map;for(const r of e){if(!t(r))continue;const s=Ih(r),o=n.get(s);o?o.push(r):n.set(s,[r])}return n}function gte(e,t){return((t==null?void 0:t.get(e))??0)>0?Pd:0}function yte(e,t){const n=(t==null?void 0:t.get(e))??0;return n>0?6+n*36:0}function Dd(e,t){const n=t.get(e);return{w:(n==null?void 0:n.width)??nc,h:(n==null?void 0:n.height)??xL}}function rc(e,t,n){const r=Dd(e,t);return{w:r.w+gte(e,n),h:Math.max(r.h,yte(e,n))}}function wte(e){return[...e.keys()].sort().map(t=>`${t}:${e.get(t)}`).join("|")}function vte(e,t,n){const r=Oh(e,s=>!t.has(s.id)&&n(s.id)!=null);if(r.size===0)return e;for(const s of r.values())s.sort((o,l)=>o.id.localeCompare(l.id));return e.map(s=>{var h;if(t.has(s.id)||n(s.id))return s;const o=r.get(Ih(s));if(!o)return s;const l=(h=s.data)==null?void 0:h.parentId,c=o.find(f=>f.id===l)??o[0],d=n(c.id);return{...s,position:{x:s.position.x+d.x-c.position.x,y:s.position.y+d.y-c.position.y}}})}function xte(e,t,n,r,s,o,l){const c=_=>rc(_,r,o),d=_=>n.get(_)??t.get(_),h=_=>{const{w:E,h:R}=Dd(_,r);return{cw:E,ch:R}},f=l!=null&&l.width>0&&l.height>0,p=Oh(e,_=>d(_.id)!=null),g=new Set;for(const[_,E]of p)E.every(R=>s.has(R.id)&&!n.has(R.id))&&g.add(_);const v=new Map,N=[];for(const _ of e){const E=d(_.id);if(!E)continue;const{w:R,h:C}=c(_.id),A=Ih(_);g.has(A)?(v.get(A)??v.set(A,[]).get(A)).push(_):N.push({x:E.x,y:E.y,w:R,h:C,...h(_.id)})}if(v.size===0||f&&N.length===0)return[];const k=Ld,x=(_,E,R,C)=>N.some(A=>_<A.x+A.w+pb&&A.x<_+R+pb&&E<A.y+A.h+k&&A.y<E+C+k),j=kL(e,r),b=[];for(const _ of[...v.keys()].sort()){const E=v.get(_);let R=1/0,C=1/0,A=-1/0,U=-1/0,L=-1/0,F=-1/0;for(const G of E){const K=d(G.id),{w:q,h:H}=c(G.id),{cw:D,ch:W}=h(G.id);R=Math.min(R,K.x),C=Math.min(C,K.y),A=Math.max(A,K.x+q),U=Math.max(U,K.y+H),L=Math.max(L,K.x+D),F=Math.max(F,K.y+W)}const O=A-R,I=U-C,B=[...new Set(N.map(G=>Math.round(G.x)))].sort((G,K)=>G-K),M=B.length?B:[R],$=[0,...N.map(G=>G.y+G.h+k)].sort((G,K)=>G-K);let P=null;if(f){let G=1/0,K=1/0,q=-1/0,H=-1/0;for(const Y of N)G=Math.min(G,Y.x),K=Math.min(K,Y.y),q=Math.max(q,Y.x+Y.cw),H=Math.max(H,Y.y+Y.ch);const D=(Y,Z)=>{const ee=l.width/(Math.max(q,Y+L-R)-Math.min(G,Y)+Pd),ne=l.height/(Math.max(H,Z+F-C)-Math.min(K,Z));return[Math.min(NL,ee,ne),Math.min(ee,ne),Math.max(ee,ne)]},W=(Y,Z)=>{for(let ee=0;ee<Y.length;ee++){if(Y[ee]>Z[ee]+1e-9)return!0;if(Y[ee]<Z[ee]-1e-9)return!1}return!1},J=Math.round(q+Pd+j),V=[...new Set([...$,K])].sort((Y,Z)=>Y-Z);let X=null;for(const Y of[...M,J])for(const Z of V){if(x(Y,Z,O,I))continue;const ee=D(Y,Z);(X===null||W(ee,X))&&(X=ee,P={x:Y,y:Z})}P&&P.x===R&&P.y===C&&(P=null)}else e:for(const G of M)for(const K of $){if(K>=C)break;if(!x(G,K,O,I)){P={x:G,y:K};break e}}if(P){const G=P.x-R,K=P.y-C;for(const q of E){const H=d(q.id);t.set(q.id,{x:H.x+G,y:H.y+K})}b.push(_)}for(const G of E){const K=d(G.id),{w:q,h:H}=c(G.id);N.push({x:K.x,y:K.y,w:q,h:H,...h(G.id)})}}return b}function bte(e,t,n,r,s,o){const l=g=>rc(g,r,s),c=new Map(e.map(g=>[g.id,Ih(g)])),d=[],h=e.map(g=>({id:g.id,pos:n.get(g.id)??t.get(g.id)})).filter(g=>g.pos!=null).sort((g,v)=>g.pos.y-v.pos.y||g.pos.x-v.pos.x||g.id.localeCompare(v.id)),f=g=>(o==null?void 0:o.has(g))===!0&&!n.has(g);for(const{id:g,pos:v}of h){if(!f(g))continue;const{w:N,h:k}=l(g);d.push({x:v.x,y:v.y,w:N,h:k,sid:c.get(g)??"_default"})}const p=[];for(const{id:g,pos:v}of h){if(f(g))continue;const{w:N,h:k}=l(g),x=c.get(g)??"_default";if(n.has(g)){d.push({x:v.x,y:v.y,w:N,h:k,sid:x});continue}let j=v.y;for(let b=0;b<d.length+1;b++){const _=d.find(E=>{const R=E.sid===x?id:bL,C=E.sid===x?id:Ld;return v.x<E.x+E.w+R&&E.x<v.x+N+R&&j<E.y+E.h+C&&E.y<j+k+C});if(!_)break;j=_.y+_.h+(_.sid===x?id:Ld)}j!==v.y&&(t.set(g,{x:v.x,y:j}),p.push(g)),d.push({x:v.x,y:j,w:N,h:k,sid:x})}return p}function kte(e,t,n,r,s,o=!1,l){const d=bL+1,h=Ld+1,f=8,p=1.75,g=200,v=.7,N=.01,k=I=>rc(I,r,l),x=I=>n.get(I)??t.get(I),j=Oh(e,I=>x(I.id)!=null),b=[],_=new Set,E=new Set,R=s.size===0;for(const I of[...j.keys()].sort()){const B=j.get(I);let M=1/0,$=1/0,P=-1/0,G=-1/0,K=!1;for(const W of B){const J=x(W.id),{w:V,h:X}=k(W.id);M=Math.min(M,J.x),$=Math.min($,J.y),P=Math.max(P,J.x+V),G=Math.max(G,J.y+X),n.has(W.id)&&(K=!0)}const q=P-M,H=G-$;E.add(I);const D=s.get(I);D&&(q>D.w+f||H>D.h+f)&&_.add(I),s.set(I,{w:q,h:H}),b.push({sid:I,members:B.map(W=>W.id),x:M,y:$,w:q,h:H,anchored:K,mass:1})}for(const I of[...s.keys()])E.has(I)||s.delete(I);if(o||R)return[];let C=!1;for(let I=0;I<b.length&&!C;I++)for(let B=I+1;B<b.length;B++){const M=b[I],$=b[B];if(!(M.anchored&&$.anchored)&&Math.abs(M.x+M.w/2-($.x+$.w/2))<(M.w+$.w)/2+d&&Math.abs(M.y+M.h/2-($.y+$.h/2))<(M.h+$.h)/2+h){C=!0;break}}if(_.size===0&&!C)return[];if(_.size>0)for(const I of b)_.has(I.sid)&&(I.mass=8);else for(const I of b)I.mass=Math.max(1,I.w*I.h/(nc*xL));const A=new Map(b.map(I=>[I.sid,I.x])),U=new Map(b.map(I=>[I.sid,I.y])),L=new Map(b.map(I=>[I.sid,Math.min(0,I.x)])),F=new Map(b.map(I=>[I.sid,Math.min(0,I.y)]));for(let I=0;I<g;I++){const B=new Map,M=new Map;let $=0;for(let P=0;P<b.length;P++)for(let G=P+1;G<b.length;G++){const K=b[P],q=b[G];if(K.anchored&&q.anchored)continue;const H=K.x+K.w/2,D=K.y+K.h/2,W=q.x+q.w/2,J=q.y+q.h/2,V=(K.w+q.w)/2+d-Math.abs(H-W),X=(K.h+q.h)/2+h-Math.abs(D-J);if(V<=0||X<=0)continue;const Y=(Be,We)=>!Be.anchored&&!(We<0&&Be.x<=L.get(Be.sid)),Z=(Be,We)=>!Be.anchored&&!(We<0&&Be.y<=F.get(Be.sid)),ee=(Be,We,He)=>{const rt=Be===We,lt=rt?K.sid<q.sid?-1:1:Math.sign(Be-We);return He(K,lt)||He(q,-lt)?lt:rt&&(He(K,-lt)||He(q,lt))?-lt:0},ne=ee(H,W,Y),se=ee(D,J,Z),pe=ne!==0,ke=se!==0;if(!pe&&!ke)continue;const ae=pe&&(!ke||V*p<X),[fe,me,he,ge]=ae?[ne,V,B,Y]:[se,X,M,Z],ue=ge(K,fe),be=ge(q,-fe),oe=K.mass,je=q.mass,$e=ue?be?je/(oe+je):1:0,Oe=be?ue?oe/(oe+je):1:0,Ue=me*v;he.set(K.sid,(he.get(K.sid)??0)+fe*Ue*$e),he.set(q.sid,(he.get(q.sid)??0)-fe*Ue*Oe),$+=Ue}for(const P of b)P.anchored||(P.x=Math.max(L.get(P.sid),P.x+(B.get(P.sid)??0)),P.y=Math.max(F.get(P.sid),P.y+(M.get(P.sid)??0)));if($<N)break}const O=[];for(const I of b){const B=I.x-A.get(I.sid),M=I.y-U.get(I.sid);if(!(Math.abs(B)<1&&Math.abs(M)<1)){for(const $ of I.members){if(n.has($))continue;const P=t.get($);P&&t.set($,{x:P.x+B,y:P.y+M})}O.push(I.sid)}}return O}function Nte(e,t,n,r,s,o){const l=new $R.graphlib.Graph;l.setDefaultEdgeLabel(()=>({})),l.setGraph({rankdir:n,marginx:0,marginy:0,nodesep:70,ranksep:160,edgesep:30});const c=e.filter(j=>!s.has(j)),d=new Set(c);for(const j of c){const{w:b,h:_}=rc(j,r,o);l.setNode(j,{width:b,height:_})}for(const j of t)d.has(j.source)&&d.has(j.target)&&l.setEdge(j.source,j.target);$R.layout(l);const h=new Map;let f=1/0,p=1/0,g=-1/0,v=-1/0;for(const j of c){const b=l.node(j);if(!b)continue;const{w:_,h:E}=Dd(j,r),R=rc(j,r,o),C=b.x-R.w/2,A=b.y-R.h/2;h.set(j,{x:C,y:A}),C<f&&(f=C),A<p&&(p=A),C+_>g&&(g=C+_),A+E>v&&(v=A+E)}if(Number.isFinite(f)&&Number.isFinite(p))for(const[j,b]of h)h.set(j,{x:b.x-f,y:b.y-p});const N=Number.isFinite(g)?g-f:0,k=Number.isFinite(v)?v-p:0;let x=null;for(const j of e){const b=s.get(j);if(!b)continue;const{w:_,h:E}=Dd(j,r);x=x===null?{minX:b.x,minY:b.y,maxX:b.x+_,maxY:b.y+E}:{minX:Math.min(x.minX,b.x),minY:Math.min(x.minY,b.y),maxX:Math.max(x.maxX,b.x+_),maxY:Math.max(x.maxY,b.y+E)}}return{positions:h,width:N,height:k,pinnedBox:x}}function jL(e,t,n){const r=n.direction??"LR",s=n.pinned??new Map,o=n.measured??new Map,l=n.lanes,c=Oh(e);return{laid:Array.from(c.keys()).sort().map(f=>({sid:f,...Nte(c.get(f).map(p=>p.id),t,r,o,s,l)})),gap:kL(e,o)}}const SL=e=>e.reduce((t,n)=>Math.max(t,n.width),0)+Pd,jte=e=>e.reduce((t,n)=>t+n.height,0)+ii*Math.max(0,e.length-1);function mb(e,t,n,r){const s=d=>{const h=[[]];let f=0;for(const p of e)f>0&&f+p.height>d&&(h.push([]),f=0),h[h.length-1].push(p),f+=p.height+ii;return h},o=[];for(let d=0;d<e.length;d++){let h=-ii;for(let f=d;f<e.length;f++)o.push(h+=e[f].height+ii)}o.sort((d,h)=>d-h);const l=d=>{let h=0,f=o.length-1;for(;h<f;){const p=h+f>>1;s(o[p]).length<=d?f=p:h=p+1}return s(o[h])};let c=[e];if(n>0&&r>0){const d=f=>mte(f.reduce((p,g)=>p+SL(g),0)+t*(f.length-1),Math.max(...f.map(jte)),n,r);let h=d(c);for(let f=2;f<=e.length;f++){const p=l(f),g=d(p);g>h+1e-9&&(h=g,c=p)}}return c}function Ste(e,t,n,r,s){if(!(r.width>0&&r.height>0&&s.width>0&&s.height>0))return!1;const{laid:o,gap:l}=jL(e,t,n);return o.length<2?!1:mb(o,l,r.width,r.height).length!==mb(o,l,s.width,s.height).length}function _te(e,t,n={}){const r=n.pinned??new Map,{laid:s,gap:o}=jL(e,t,n),l=mb(s,o,n.availableWidth??0,n.availableHeight??0),c=new Map;let d=0;for(const h of l){const f=SL(h);let p=0;for(const{positions:g,height:v,pinnedBox:N}of h){for(const[x,j]of g)c.set(x,{x:j.x+d,y:j.y+p});let k=p+v;N&&N.maxY>k&&N.minX<d+f&&d<N.maxX&&(k=N.maxY),p=k+ii}d+=f+o}return e.map(h=>{const f=r.get(h.id);if(f)return{...h,position:f};const p=c.get(h.id);return p?{...h,position:p}:h})}function ld(e,t,n){return!t.has(e)||n.has(e)}function Ete(e,t,n,r){return!t.has(e)&&ld(e,n,r)}function Tte(e,t,n){const r={x:0,y:0};return t.set(e,r),n.add(e),r}function IR(e,t,n,r){n.set(e,t),r.delete(e)}const Cte=300,OR=130,Ate=160,LR=new WeakMap;function Rte(e,t){let n=LR.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map,branches:FU(e.agents.values())},LR.set(e,n));const{byId:r,branches:s}=n;return o=>{let l=r.get(o.id);if(!l){const c=o.kind==="root"?s.get(o.sessionId):void 0;l=c?{...o,onOpenContext:t,branch:c}:{...o,onOpenContext:t},r.set(o.id,l)}return l}}function Y0(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 Mte(e,t){const n=l=>{var c;return((c=l.data)==null?void 0:c.sessionId)??l.id},r=new Map;for(const l of e){const c=n(l),d=l.position.x+(l.width??nc),h=r.get(c);h?(h.minX=Math.min(h.minX,l.position.x),h.maxX=Math.max(h.maxX,d),h.minY=Math.min(h.minY,l.position.y)):r.set(c,{minX:l.position.x,maxX:d,minY:l.position.y})}const s=[];for(const[l,c]of[...r].sort((d,h)=>d[1].minX-h[1].minX)){const d=s[s.length-1];d&&c.minX<d.maxX?(d.maxX=Math.max(d.maxX,c.maxX),d.sessions.push({sid:l,top:c.minY})):s.push({maxX:c.maxX,sessions:[{sid:l,top:c.minY}]})}const o=new Map;for(const l of s)for(const{sid:c}of l.sessions.sort((d,h)=>d.top-h.top))o.set(c,o.size);return e.slice().sort((l,c)=>o.get(n(l))-o.get(n(c))||t(l)-t(c)||l.position.y-c.position.y||l.position.x-c.position.x)}function $te(e,t){var r;let n=0;for(let s=t.parentId;s!=null&&n<e.agents.size;s=(r=e.agents.get(s))==null?void 0:r.parentId)n++;return n}function Ite(e,t,n,r,s,o,l,c,d,h,f,p,g,v,N,k,x,j,b,_){var G,K,q,H;const E=[],R=[],C=Rte(e,j);for(const D of e.agents.values()){if(!x.has(D.id))continue;const W=D.exitAt!=null,J=k!=null&&!k.has(D.id),V=[W?"rf-exiting":"",J?"rf-spotlit-out":"",N.has(D.id)?"rf-selected":""].filter(Boolean).join(" ")||void 0,X=o.get(D.id);if(E.push({id:D.id,type:"agent",position:{x:0,y:0},data:C(D),className:V,ariaLabel:tU(D,t,N.has(D.id)),...X?{width:X.width,height:X.height}:null}),D.parentId&&x.has(D.parentId)){const ee=xd(D.sessionId),ne=W,se=N.size>0&&(N.has(D.id)||N.has(D.parentId)),pe=k!=null&&!k.has(D.id)&&!k.has(D.parentId),ke=D.state==="active"?2:1.5,ae=se?ke+1.5:ke,fe=ne?.2:pe?.12:1,me=["sess-edge",D.state==="active"?"sess-live":"sess-idle",ne?"rf-edge-exiting":"",se?"rf-edge-selected":""].filter(Boolean).join(" ");R.push({id:`e:${D.parentId}->${D.id}`,source:D.parentId,target:D.id,animated:(D.state==="active"||se)&&!ne,type:"smoothstep",style:{"--session-hue":ee,strokeWidth:`calc(${ae}px * var(--edge-k, 1))`,opacity:fe,transition:"var(--edge-transition)"},className:me})}const Y=D.kind==="root"?th(D):null,Z=Y?C$(D.sessionId,Y.at):null;if(Y&&Z&&!$U(Z)){const ee=s0(D.id),ne=xd(D.sessionId),se=o.get(ee);E.push({id:ee,type:"recapNote",position:{x:0,y:0},data:{sessionId:D.sessionId,parentId:D.id,recap:Y,noteKey:Z,hue:ne},className:J?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${D.label}`,...se?{width:se.width,height:se.height}:null}),R.push({id:`e:recap:${D.id}`,source:ee,target:D.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":ne}})}}const A=Y0(e),U=_.size>0&&!(d&&b);U||_.clear();const L=`${g}#lanes:${wte(A)}${U?"#held":""}`,F=new Set(E.filter(D=>D.type==="recapNote").map(D=>D.id));for(const D of Array.from(f.keys()))b&&PU(D)&&!F.has(D)&&!s.has(D)&&(f.delete(D),p.delete(D));const O=E.filter(D=>Ete(D.id,s,f,p));if(O.length>0||L!==v.current){if(O.length>0){for(const W of O)_.delete(W.id);const D=vte(_te(E,R,{direction:"LR",pinned:s,measured:o,availableWidth:n,availableHeight:r,lanes:A}),s,W=>ld(W,f,p)?void 0:f.get(W));for(const W of D)ld(W.id,f,p)&&IR(W.id,W.position,f,p);xte(E,f,s,o,new Set(O.filter(W=>W.type!=="recapNote").map(W=>W.id)),A,{width:n,height:r});for(const W of O){if(W.type!=="recapNote")continue;const J=(G=W.data)==null?void 0:G.parentId;if(!J)continue;const V=s.get(J)??(ld(J,f,p)?void 0:f.get(J));if(!V)continue;const X=((K=o.get(W.id))==null?void 0:K.width)??Cte,Y=((q=o.get(W.id))==null?void 0:q.height)??OR,Z=((H=o.get(J))==null?void 0:H.height)??OR;IR(W.id,{x:V.x-Ate-X,y:V.y+(Z-Y)/2},f,p)}}bte(E,f,s,o,A,U?_:void 0),v.current=L}const I=kte(E,f,s,o,l,!d||h,A);I.length>0&&c(I);const B=GZ(e.agents.values());b&&Gu(f,B),Gu(p,B),b&&Gu(s,B),Gu(o,VZ(e.agents.values()));const M=[];let $=!1;for(const D of E){let W=s.get(D.id)??f.get(D.id);W||(W=Tte(D.id,f,p),$=!0),M.push({...D,position:W})}return $&&(v.current=""),{nodes:Mte(M,D=>{if(D.type==="recapNote")return-1;const W=e.agents.get(D.id);return W?$te(e,W):0}),edges:R}}function Ote(e){return e.slice().sort((t,n)=>t.y-n.y||t.x-n.x)}function Lte(e,t,n){var l;if(e.length===0)return null;const r=Ote(e),s=t?r.findIndex(c=>c.id===t):-1,o=s===-1?n===1?0:r.length-1:(s+n+r.length)%r.length;return((l=r[o])==null?void 0:l.id)??null}const Pte=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Escape","Backspace"]);function Dte(e,t){return t==null?{kind:"deck",nodeId:null}:e.key==="Enter"||e.key===" "?{kind:"activate",nodeId:t,additive:e.shiftKey}:Pte.has(e.key)?{kind:"node",nodeId:t}:{kind:"deck",nodeId:t}}const Fte=new Set(["","BODY","HTML","#DOCUMENT"]);function Bte(e){return!e||hc(e)?!1:!Fte.has(String(e.tagName??"").toUpperCase())}const _L="react-flow__node";function X0(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,_L))===!0}function EL(e){try{const t=document.querySelector(`.${_L}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}let Ga=null,ei=null;const gb=new Set,yb=()=>{for(const e of gb)e()},qte=e=>(gb.add(e),()=>{gb.delete(e)}),PR=()=>Ga,Ute=90;function TL(e){!ei||e!=null&&ei.at.id!==e||(clearTimeout(ei.timer),ei=null)}function CL(e,t,n="pointer"){TL();const r={id:e,anchor:t,by:n};if(Ga||n==="focus"){Ga=r,yb();return}ei={at:r,timer:setTimeout(()=>{ei=null,Ga=r,yb()},Ute)}}function la(e){TL(e),!(!Ga||e!=null&&Ga.id!==e)&&(Ga=null,yb())}function zte({agentFor:e,recapFor:t,labelFor:n,bounds:r}){const s=y.useSyncExternalStore(qte,PR,PR),o=s?e(s.id):void 0,l=s&&!o?t(s.id):void 0,c=s!=null&&(!o&&!l||!s.anchor.isConnected);return y.useEffect(()=>{c&&s&&la(s.id)},[c,s]),!s||c?null:o?a.jsx(Hte,{a:o,anchor:s.anchor,parentLabel:o.parentId?n(o.parentId):void 0,bounds:r},s.id):l?a.jsx(Wte,{r:l,anchor:s.anchor,bounds:r},s.id):null}function AL(e,t){const n=y.useRef(null),r=y.useCallback(()=>{const s=n.current;if(!s||!e.isConnected)return;const o=m0(e.getBoundingClientRect(),{width:s.offsetWidth,height:s.offsetHeight},t());s.style.top=`${o.top}px`,s.style.left=`${o.left}px`,s.style.maxHeight=o.maxHeight==null?"":`${o.maxHeight}px`,s.dataset.side=o.side},[e,t]);return y.useLayoutEffect(()=>{r()}),n}function Wte({r:e,anchor:t,bounds:n}){const r=AL(t,n),s=_i(3e4),o=Sd(e.recap.at,s);return Lt.createPortal(a.jsxs("div",{ref:r,className:"ap-peek node-peek recap-peek",role:"tooltip",id:"node-peek",style:{"--session-hue":e.hue},children:[a.jsxs("div",{className:"node-peek-head",children:[a.jsxs("span",{className:"recap-peek-mark",children:[a.jsx(Vl,{}),"recap"]}),a.jsx("span",{className:"node-peek-time",title:o.title,children:o.label})]}),e.sessionLabel&&a.jsx("div",{className:"node-peek-kind",children:a.jsxs("span",{children:["Claude Code's recap of ",e.sessionLabel]})}),a.jsx("p",{className:"recap-peek-text",children:e.recap.text}),a.jsx("p",{className:"node-peek-hint",children:"Click to go to the session · double-click for its details"})]}),document.body)}function Hte({a:e,anchor:t,parentLabel:n,bounds:r}){const s=AL(t,r),o=_i(1e3),l=n0(e.sessionName,e.sessionTitle),c=e.toolErrorCount??0,d=e.tools.filter(N=>!N.endedAt).length,h=pn(e,o).total,f=e.usage.inputTokens+e.usage.outputTokens,p=e.kind==="root"&&Sn(e.waiting),g=e.kind==="root"?"session":n?`subagent of ${n}`:"subagent",v=[`${e.toolCount} ${e.toolCount===1?"tool":"tools"}`,d>0?`${d} in-flight`:null,f>0?`${it(f)} tok`:null,h>0?`${qe(h)}${Hl(e,o)>0?"+":""}`:null].filter(Boolean).join(" · ");return Lt.createPortal(a.jsxs("div",{ref:s,className:"ap-peek node-peek",role:"tooltip",id:"node-peek",children:[a.jsxs("div",{className:"node-peek-head",children:[a.jsx("span",{className:"node-peek-name",children:e.label}),a.jsxs("span",{className:"node-peek-time",children:[e.synthetic?"≥ ":"",mi(e.startedAt,e.endedAt,o)]})]}),a.jsxs("div",{className:"node-peek-kind",children:[a.jsxs("span",{className:"node-peek-state","data-kind":Lx(e.state),children:[a.jsx(P$,{kind:Lx(e.state)}),fi(e.state)]}),a.jsx("span",{children:g}),e.model?a.jsx("span",{children:oa(e.model)}):null]}),e.kind==="root"&&l.face&&a.jsx("p",{className:"node-peek-title",children:l.face}),e.kind==="root"&&e.waiting&&a.jsxs("p",{className:`node-peek-wait${p?" warn":""}`,children:[p&&a.jsx(i0,{}),a.jsx("span",{children:t0(e.waiting)}),a.jsx("b",{children:mi(e.waiting.since,void 0,o)})]}),a.jsxs("p",{className:"node-peek-facts",children:[v,c>0&&a.jsxs("span",{className:"node-peek-failed",children:[" · ",c," failed"]})]}),e.branch&&e.branch.total>0&&a.jsx("p",{className:"node-peek-branch",children:A$(e.branch)}),a.jsx("p",{className:"node-peek-hint",children:"Click to go to the session · double-click for details"})]}),document.body)}function Vte(e){const t=e.minZoom??ZX,n=e.maxZoom??JX,r=e.fill??.9,s=e.insets.left,o=e.insets.top,l=Math.max(1,e.pane.width-e.insets.left-e.insets.right),c=Math.max(1,e.pane.height-e.insets.top-e.insets.bottom),d=e.context,h=e.anchor,f=Math.min(l/Math.max(1,d.width),c/Math.max(1,d.height))*r,p=Math.max(t,Math.min(n,f)),g=(v,N,k,x,j,b)=>{let _=v+(N-x*p)/2-k*p;const E=j*p+_,R=(j+b)*p+_;return b*p<=N?E<v?_+=v-E:R>v+N&&(_-=R-(v+N)):_+=v-E,_};return{x:g(s,l,d.x,d.width,h.x,h.width),y:g(o,c,d.y,d.height,h.y,h.height),zoom:p}}function Gte(e){let t=1/0,n=1/0,r=-1/0,s=-1/0;for(const o of e)t=Math.min(t,o.x),n=Math.min(n,o.y),r=Math.max(r,o.x+o.width),s=Math.max(s,o.y+o.height);return Number.isFinite(t)?{x:t,y:n,width:r-t,height:s-n}:null}function _n(e){const t=y.useRef(e);return t.current=e,t}const wb=80,vb=.86;function RL(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 Kte({canvasRef:e,canvasSize:t,machinePhase:n,usagePhase:r,usagePanelOpen:s,detailShown:o}){const[l,c]=y.useState(0);y.useEffect(()=>{const p=RL(e.current);c(g=>Math.abs(g-p)>40?p:g)},[n,r,s,o,t.w]);const d=_n(l),h=t.w>0?Math.max(0,(t.w-l-wb*2)*vb):0,f=t.h>0?Math.max(0,(t.h-wb*2)*vb):0;return{railInsetRef:d,availableWidth:h,availableHeight:f}}const ML=420;function Yte(){const e=ki(),t=Nt(),n=y.useCallback((d,h)=>{if($x({durationMs:h,documentHidden:document.hidden})){e.setViewport(d,{duration:h});return}const{d3Zoom:f,d3Selection:p}=t.getState(),g=p==null?void 0:p.property("__zoom");if(f&&p&&g&&g.k>0&&d.zoom>0){f.transform(p,g.scale(d.zoom/g.k).translate((d.x-g.x)/d.zoom,(d.y-g.y)/d.zoom));return}e.setViewport(d,{duration:0})},[e,t]),r=y.useRef(null),s=y.useRef(0),o=y.useRef(0),l=y.useCallback((d,h)=>{const f=++s.current;return n(d,h),o.current=Date.now(),r.current=$x({durationMs:h,documentHidden:document.hidden})?{target:d,until:Date.now()+h+60}:null,f},[n]),c=y.useCallback((d=500)=>{const h=wb,f=1,p=.2,g=vb;try{const v=document.querySelector(".canvas-wrap"),N=Array.from(document.querySelectorAll(".react-flow__node")).filter($=>$.offsetWidth>0);if(!v||N.length===0)return;const k=v.getBoundingClientRect(),x=e.getViewport();if(!Number.isFinite(x.zoom)||x.zoom<=0)return;const j=$=>($-k.left-x.x)/x.zoom,b=$=>($-k.top-x.y)/x.zoom,_=N.map($=>$.getBoundingClientRect()),E=Math.min(..._.map($=>j($.left))),R=Math.max(..._.map($=>j($.right))),C=Math.min(..._.map($=>b($.top))),A=Math.max(..._.map($=>b($.bottom))),U=R-E,L=A-C;if(!(U>0&&L>0))return;const F=RL(v),O=$=>Math.max(p,Math.min(f,(k.width-F-h*2)/(U+$)*g,(k.height-h*2)/L*g)),I=XX(O(ML),O(0)),B={x:h-E*I,y:Math.max(h,(k.height-L*I)/2)-C*I,zoom:I},M=l(B,d);window.setTimeout(()=>{var $;try{if((($=r.current)==null?void 0:$.target)===B&&(r.current=null),s.current!==M)return;const P=e.getViewport();(Math.abs(P.zoom-I)>.01||Math.abs(P.x-B.x)>2)&&n(B,0)}catch{}},d+60)}catch{}},[e,n,l]);return y.useEffect(()=>{const d=()=>{if(!document.hidden)return;const h=r.current;if(r.current=null,!(!h||Date.now()>h.until)){try{n(h.target,0)}catch{}o.current=Date.now()}};return document.addEventListener("visibilitychange",d),()=>document.removeEventListener("visibilitychange",d)},[n]),{applyViewport:n,moveCamera:l,fitLeft:c,cameraEpochRef:s,lastFitTimeRef:o}}const Xte=450;function Zte({canvasRef:e,stateRef:t,measuredRef:n,nodesRef:r,railInsetRef:s,moveCamera:o,disableAutoFit:l,lastFocusRef:c,focusAgentRef:d,selectAgent:h,primarySelectedIdRef:f}){const p=y.useCallback(N=>{var U;const k=e.current,x=t.current.agents.get(N);if(!k||!x)return;const j=Y0(t.current),b=(L,F)=>{const O=n.current.get(L.id);if(!O)return null;const I=F&&j.has(L.id)?ML:0;return{x:L.position.x,y:L.position.y,width:O.width+I,height:O.height}},_=r.current.find(L=>L.id===N),E=_?b(_,!1):null;if(!E)return;const R=[];for(const L of r.current){if(L.type!=="agent"&&L.type!=="recapNote"||((U=L.data)==null?void 0:U.sessionId)!==x.sessionId)continue;const F=b(L,L.type==="agent");F&&R.push(F)}const C=k.getBoundingClientRect(),A=Vte({pane:{width:C.width,height:C.height},insets:{top:56,left:72,bottom:32,right:s.current+32},context:Gte(R)??E,anchor:E});la(),l(),c.current={id:N,at:Date.now()},o(A,Xte)},[o,l]);d.current=p;const g=y.useCallback(N=>{const k=r.current.filter(_=>_.type==="agent"),x=Lte(k.map(_=>({id:_.id,x:_.position.x,y:_.position.y})),f.current,N),j=x?k.find(_=>_.id===x):void 0;if(!j)return;const b=X0(document.activeElement);h(j.id,!1),window.setTimeout(()=>{try{p(j.id)}catch{}b&&EL(j.id)},30)},[h,p]),v=y.useCallback(N=>{h(N,!1),window.setTimeout(()=>{try{p(N)}catch{}},60)},[h,p]);return{focusAgent:p,stepAgent:g,focusSession:v}}function Jte({nodesRef:e,stateRef:t,canvasRef:n,railInsetRef:r}){const s=y.useCallback(d=>{const h=e.current.find(f=>f.id===d&&f.type==="agent");return h?h.data:void 0},[]),o=y.useCallback(d=>{var h;return(h=t.current.agents.get(d))==null?void 0:h.label},[]),l=y.useCallback(d=>{var p;const h=e.current.find(g=>g.id===d&&g.type==="recapNote");if(!h)return;const f=h.data;return{recap:f.recap,hue:f.hue,sessionLabel:(p=t.current.agents.get(f.parentId))==null?void 0:p.label}},[]),c=y.useCallback(()=>{var f;const d=(f=n.current)==null?void 0:f.getBoundingClientRect(),h=document.documentElement;return d?{width:d.right-r.current,height:d.bottom}:{width:h.clientWidth,height:h.clientHeight}},[]);return{peekAgent:s,peekLabel:o,peekRecap:l,peekBounds:c}}function Qte(e){const t=new Set(e.pins),n=new Map,r=new Map;for(const[s,o]of e.positions)n.set(s,o),t.has(s)&&r.set(s,o);return{positions:n,pinned:r,restored:new Set(n.keys())}}function DR(e){return Object.entries(e??{}).filter(([,t])=>t&&typeof t.x=="number"&&typeof t.y=="number")}function ene(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=DR(n);return{positions:s,pins:s.map(([o])=>o)}}const r=n;return{positions:DR(r.positions),pins:Array.isArray(r.pins)?r.pins:[]}}function tne(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 nne(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 Z0="agent-dag.layout",J0="agent-dag.layoutFrame",Q0="agent-dag.viewport";function rne(){return ene(Qe(Z0))}function sc(e,t){Ze(Z0,tne(e,t))}function sne(){return nne(Qe(J0))}function $L(e){Ze(J0,JSON.stringify(e))}function ane(){return y8(Qe(Q0))}function one(e){Ze(Q0,JSON.stringify(e))}function IL(){hs(Z0),hs(Q0),hs(J0)}function ine(e){const t=y.useState(()=>Qte(rne()))[0],n=y.useRef(t.pinned),r=y.useRef(t.positions),s=y.useRef(new Set),o=y.useRef(""),[l,c]=y.useState(0),d=y.useState(sne)[0],h=y.useRef(d),f=y.useCallback(()=>{n.current.clear(),r.current.clear(),o.current="",IL(),c(p=>p+1),window.setTimeout(()=>{sc(r.current,n.current),h.current&&$L(h.current),e(500)},80)},[e]);return{restoredLayout:t,pinnedRef:n,positionsRef:r,provisionalRef:s,lastLayoutSigRef:o,layoutEpoch:l,setLayoutEpoch:c,lastLayoutFrameRef:h,handleRelayout:f}}function lne(e,t){const{positionsRef:n,pinnedRef:r}=t,s=y.useRef(null);y.useEffect(()=>(s.current!=null&&window.clearTimeout(s.current),s.current=window.setTimeout(()=>{sc(n.current,r.current)},1500),()=>{s.current!=null&&window.clearTimeout(s.current)}),[e])}function cne({nodes:e,edges:t,settled:n,dragging:r,availableWidth:s,availableHeight:o,layout:l,camera:c,rf:d,measuredRef:h,stateRef:f,lastFocusRef:p,primarySelectedIdRef:g,focusAgentRef:v,autoFitDisabledRef:N}){const{lastLayoutFrameRef:k,pinnedRef:x,positionsRef:j,provisionalRef:b,lastLayoutSigRef:_,setLayoutEpoch:E}=l,{applyViewport:R,fitLeft:C,cameraEpochRef:A,lastFitTimeRef:U}=c;y.useEffect(()=>{if(!n||r)return;const L={width:s,height:o};if(!(L.width>0&&L.height>0))return;const F=k.current;if(k.current=L,$L(L),!F||F.width===L.width&&F.height===L.height)return;const O={direction:"LR",pinned:x.current,measured:h.current,lanes:Y0(f.current)};if(!Ste(e,t,O,F,L))return;const I=p.current&&Date.now()-p.current.at<1500?p.current.id:null,B=I??g.current,M=B?x.current.get(B)??j.current.get(B):void 0;for(const $ of Array.from(j.current.keys()))x.current.has($)||j.current.delete($);b.current.clear(),_.current="",E($=>$+1),window.setTimeout(()=>{if(sc(j.current,x.current),N.current){if(I){v.current(I);return}const $=B?x.current.get(B)??j.current.get(B):void 0;if(M&&$&&($.x!==M.x||$.y!==M.y)){const P=d.getViewport();A.current+=1,R({x:P.x-($.x-M.x)*P.zoom,y:P.y-($.y-M.y)*P.zoom,zoom:P.zoom},0),U.current=Date.now()}return}C(500)},80)},[s,o,n,r,C,d,R])}function une(e,t,n,r,s){const o=[];for(const l of e)!ah(l,t)||n.has(l.id)||o.push(l.id+(l.parentId?`>${l.parentId}`:""));return o.sort(),`${o.join("|")}#sv${r}.${s}`}const ek="agent-dag.removedNodes";function dne(e){try{const t=JSON.parse((e==null?void 0:e.getItem(ek))??"[]");return new Set(Array.isArray(t)?t.filter(n=>typeof n=="string"):[])}catch{return new Set}}function FR(e,t){try{e==null||e.setItem(ek,JSON.stringify([...t]))}catch{}}function OL(e,t){const n=new Map(e.map(o=>[o.id,o.parentId])),r=new Set(t),s=o=>{if(r.has(o))return!0;const l=new Set([o]);let c=n.get(o);for(;c&&!l.has(c);){if(r.has(c))return r.add(o),!0;l.add(c),c=n.get(c)}return!1};return o=>s(o.id)||s(o.sessionId??o.id)}function hne(e,t){if(t.size===0)return new Set;const n=[...e],r=OL(n,t);return new Set(n.filter(r).map(s=>s.id))}function fne(e,t,n){const r=c=>({id:c.id,parentId:c.data.parentId,sessionId:c.data.sessionId}),s=OL(e.map(r),n),o=e.filter(c=>!s(r(c))),l=new Set(o.map(c=>c.id));return{nodes:o,edges:t.filter(c=>l.has(c.source)&&l.has(c.target))}}function pne(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 mne(e,t){return t.size===0?[]:[...e].filter(n=>t.has(n.id)).map(n=>n.id)}function gne(e){let t=e.kind==="subagent"?e.startedAt:-1/0;const n=e.tools[e.tools.length-1];n&&n.startedAt>t&&(t=n.startedAt);const r=e.prompts[e.prompts.length-1];return r&&r.at>t&&(t=r.at),e.lastOutputAt!=null&&e.lastOutputAt>t&&(t=e.lastOutputAt),t}function yne(e,t,n){let r=null;for(const s of t)e.has(s)||(r??(r=new Map(e)),r.set(s,n));for(const s of e.keys())t.has(s)||(r??(r=new Map(e)),r.delete(s));return r??e}function wne(e,t,n,r){if(n.size===0)return[];let s=1/0;for(const l of r.values())l<s&&(s=l);const o=new Set;for(const l of t){const c=e.get(l);if(!c)continue;const d=gne(c);if(d<=s)continue;const h=[],f=new Set,p=v=>{var N;for(let k=v;k&&!f.has(k);k=(N=e.get(k))==null?void 0:N.parentId)f.add(k),n.has(k)&&h.push(k)};p(c.id),p(c.sessionId);let g=-1/0;for(const v of h)g=Math.max(g,r.get(v)??1/0);if(d>g)for(const v of h)o.add(v)}return[...o]}const LL="sessionGroup";function vne(e,t){var r,s;if(e.type===LL)return"transparent";if(Sn((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 Ku=Ua;function xne(e){const t=new Map;for(const r of e){const s=r.data;if(!(s!=null&&s.sessionId)||s.exitAt!=null)continue;const o=r.width,l=r.height;if(o==null||l==null)continue;const c=r.position.x,d=r.position.y,h=c+o,f=d+l,p=t.get(s.sessionId);p?(p.minX=Math.min(p.minX,c),p.minY=Math.min(p.minY,d),p.maxX=Math.max(p.maxX,h),p.maxY=Math.max(p.maxY,f)):t.set(s.sessionId,{minX:c,minY:d,maxX:h,maxY:f})}const n=[];for(const[r,s]of t){const o=s.maxX-s.minX+Ku*2,l=s.maxY-s.minY+Ku*2;n.push({id:`group:${r}`,type:LL,position:{x:s.minX-Ku,y:s.minY-Ku},data:{sessionId:r,w:o,h:l},width:o,height:l,style:{width:o,height:l},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return n}function bne(e,t){if(!t||!e.agents.get(t))return null;const r=new Set([t]);let s=t;for(;s;){const l=e.agents.get(s);if(!(l!=null&&l.parentId)||r.has(l.parentId))break;r.add(l.parentId),s=l.parentId}let o=!0;for(;o;){o=!1;for(const l of e.agents.values())l.parentId&&r.has(l.parentId)&&!r.has(l.id)&&(r.add(l.id),o=!0)}return r}function kne(e,t){const n=new Set;for(const r of t){const s=bne(e,r);if(s)for(const o of s)n.add(o)}return n.size>0?n:null}function Nne({stateRef:e,now:t,removedAgentIds:n,sizeVersion:r,domSizeVersion:s}){return y.useMemo(()=>une(e.current.agents.values(),t,n,r,s),[e.current,e.current.revision,t,r,s,n])}function jne({stateRef:e,now:t,availableWidth:n,availableHeight:r,layout:s,measuredRef:o,onBubble:l,settled:c,dragging:d,layoutSig:h,selectedIds:f,openContext:p,historyReplayed:g,removedNodes:v,removedAgentIds:N,dragTick:k,dragPatchRef:x,dragMoveTick:j}){const{pinnedRef:b,positionsRef:_,provisionalRef:E,lastLayoutSigRef:R,restoredLayout:C,layoutEpoch:A}=s,U=y.useMemo(()=>kne(e.current,f),[e.current,e.current.revision,f]),L=y.useMemo(()=>{const P=FH(e.current,t);for(const G of N)P.delete(G);return P},[e.current,e.current.revision,t,N]),F=y.useRef(new Map),O=DU(),{nodes:I,edges:B}=y.useMemo(()=>{const P=Ite(e.current,t,n,r,b.current,o.current,F.current,l,c,d,_.current,E.current,h,R,f,U,L,p,g,C.restored);return fne(P.nodes,P.edges,v)},[e.current,e.current.revision,t,n,r,c,d,h,f,U,L,p,k,O,v,A,g]),M=y.useMemo(()=>xne(I),[I]),$=y.useMemo(()=>{const P=[...M,...I],G=x.current;return!G||G.size===0?P:P.map(K=>{const q=G.get(K.id);return q?{...K,position:q}:K})},[M,I,j]);return{spotlightSet:U,visibleAgentIds:L,nodes:I,edges:B,allNodes:$}}function Sne(e,t,n){const r=e.x*t.zoom+t.x,s=e.y*t.zoom+t.y,o=(e.x+e.width)*t.zoom+t.x,l=(e.y+e.height)*t.zoom+t.y;return o>0&&r<n.width&&l>0&&s<n.height}function _ne({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,Sne(s,t,e))return!1;return r}function Ene({layoutSig:e,rf:t,stateRef:n,measuredRef:r,pinnedRef:s,positionsRef:o,paneSizeRef:l,lastInteractRef:c,autoFitDisabledRef:d,lastFitTimeRef:h,fitLeft:f}){const p=y.useRef(null),g=y.useRef("");y.useEffect(()=>{const v=setInterval(()=>{if(d.current||Date.now()-c.current<800)return;const N=n.current,k=Date.now(),x=[];for(const b of N.agents.values())ah(b,k)&&x.push({id:b.id});if(x.length===0)return;const j=[];for(const{id:b}of x){const _=r.current.get(b),E=s.current.get(b)??o.current.get(b);!_||!E||j.push({x:E.x,y:E.y,width:_.width,height:_.height})}_ne({pane:l.current,viewport:t.getViewport(),boxes:j})&&f(600)},1500);return()=>clearInterval(v)},[t]),y.useEffect(()=>{if(g.current===e)return;const v=g.current;if(g.current=e,!v||d.current)return;Date.now()-h.current>1200&&f(400),p.current&&window.clearTimeout(p.current),p.current=window.setTimeout(()=>{d.current||f(500)},280)},[e,t,f])}function Tne({stateRef:e,pinnedRef:t,positionsRef:n,canvasRef:r,clearSelection:s,primarySelectedId:o}){const[l,c]=y.useState(()=>dne(Ml())),[d,h]=y.useState(null),f=y.useMemo(()=>hne(e.current.agents.values(),l),[e.current,e.current.revision,l]),p=y.useCallback(j=>{const b=e.current.agents.get(j);b&&(c(_=>{const E=new Set(_);return E.add(j),FR(Ml(),E),E}),h({id:j,label:b.label}),t.current.delete(j),n.current.delete(j),s())},[s]),g=y.useCallback(()=>{o&&p(o)},[o,p]),v=d&&l.has(d.id)?d:null;y.useEffect(()=>{var j;d&&((j=r.current)==null||j.focus())},[d]);const N=y.useCallback(j=>{const b=[...j];c(_=>{const E=pne(_,b);return E!==_&&FR(Ml(),E),E})},[]),k=y.useCallback(()=>{N([...l]),h(null)},[N,l]),x=y.useCallback(()=>{c(new Set),h(null),hs(ek)},[]);return{removedNodes:l,lastRemoval:d,removedAgentIds:f,removeNode:p,removeSelectedNode:g,removalNotice:v,bringBack:N,bringBackAll:k,forgetRemovals:x}}function Cne({stateRef:e,waitingSessions:t,removedAgentIds:n,removedNodes:r,bringBack:s}){const o=y.useRef(new Map);y.useEffect(()=>{o.current=yne(o.current,r,Date.now());const l=[...mne(t,n),...wne(e.current.agents,n,r,o.current)];l.length>0&&s(l)},[t,n,r,s])}function Ane({waiting:e,running:t,connected:n=!0}){return{title:e>0?`(${e}) ${kt}`:kt,icon:n?e>0?"waiting":t>0?"running":"idle":"offline"}}const PL=Object.freeze({offline:"/state/favicon-error.svg",waiting:"/state/favicon-waiting.svg",running:"/state/favicon-syncing.svg",idle:"/favicon.svg"}),DL=Object.freeze({offline:"/state/favicon-error-32.png",waiting:"/state/favicon-waiting-32.png",running:"/state/favicon-syncing-32.png",idle:"/favicon.ico"}),Rne=Object.freeze([...new Set([...Object.values(PL),...Object.values(DL)])]),xb=new Map;function BR(e){return xb.get(e)??e}async function Mne(e,t=n=>fetch(n)){await Promise.all(e.map(async n=>{if(!xb.has(n))try{const r=await t(n),s=(r.headers.get("Content-Type")??"").split(";")[0].trim();if(!r.ok||!s.startsWith("image/"))return;xb.set(n,`data:${s};base64,${$ne(new Uint8Array(await r.arrayBuffer()))}`)}catch{}}))}function $ne(e){let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function Ine({stateRef:e,waitingSessions:t,live:n}){const r=y.useMemo(()=>Gq(e.current.agents.values()),[e.current,e.current.revision]),s=y.useRef(null);y.useEffect(()=>{n&&Mne(Rne)},[n]),y.useEffect(()=>{const o=Ane({waiting:t.length,running:r,connected:n}),l=s.current;s.current=o,(l==null?void 0:l.title)!==o.title&&(document.title=o.title),(l==null?void 0:l.icon)!==o.icon&&FL(o.icon)},[t.length,r,n])}function FL(e){const t=document.querySelector('link[rel="icon"][type="image/svg+xml"]');t&&(t.href=BR(PL[e]));const n=document.querySelector('link[rel="icon"][sizes="32x32"]');n&&(n.href=BR(DL[e]))}const One=1200,Lne=1e3;function lx(e){return e.lastDeckFitAt>0&&e.at-e.lastDeckFitAt<One?!1:e.hasSourceEvent?!0:e.lastCanvasInputAt>0&&e.at-e.lastCanvasInputAt<Lne}function Pne({applyViewport:e,lastFitTimeRef:t,cameraEpochRef:n,disableAutoFit:r,markInteract:s,canvasRef:o,applyZoom:l}){const c=y.useState(()=>ane())[0];y.useEffect(()=>{if(!c)return;const N=window.setTimeout(()=>{try{e(c,0)}catch{}t.current=Date.now()},60);return()=>window.clearTimeout(N)},[e,c]);const d=y.useRef(null),h=y.useRef(0),f=y.useCallback(()=>{h.current=Date.now()},[]),p=y.useCallback(N=>({hasSourceEvent:!!N,at:Date.now(),lastDeckFitAt:t.current,lastCanvasInputAt:h.current}),[]);return{restoredViewport:c,markCanvasInput:f,onMoveStart:N=>{la(),lx(p(N))&&(n.current+=1),lx(p(N))&&r()},onMove:(N,k)=>{var x;s(),lx(p(N))&&r(),(x=o.current)==null||x.style.setProperty("--zoom",String(k.zoom)),l(k.zoom)==="detail"&&la(),d.current&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>one(k),250)}}}function Dne({clearSelection:e,selectAgent:t,detailOpen:n,setDetailOpen:r,detailShown:s,focusAgent:o,draggingRef:l,lodRef:c}){return{onNodeClick:(v,N)=>{if(N.type==="sessionGroup"){e();return}const k=N.type==="recapNote"?N.data.parentId:N.id;t(k,v.shiftKey,!1),!v.shiftKey&&(n&&r(!1),s?window.setTimeout(()=>{try{o(k)}catch{}},80):o(k))},onPaneClick:()=>{la(),e()},onNodeDoubleClick:(v,N)=>{if(N.type!=="agent"&&N.type!=="recapNote")return;const k=N.type==="recapNote"?N.data.parentId:N.id;t(k,!1),window.setTimeout(()=>{try{o(k)}catch{}},80)},onNodeMouseEnter:(v,N)=>{N.type!=="agent"&&N.type!=="recapNote"||l.current||c.current==null||c.current==="detail"||CL(N.id,v.currentTarget)},onNodeMouseLeave:(v,N)=>la(N.id)}}function Fne(){const e=y.useRef(null),t=y.useRef(null),[n,r]=y.useState({w:0,h:0});return y.useEffect(()=>{const s=t.current;if(!s||typeof ResizeObserver>"u")return;const o=new ResizeObserver(l=>{var d;const c=(d=l[0])==null?void 0:d.contentRect;c&&(e.current={width:c.width,height:c.height},r(h=>Math.abs(h.w-c.width)>40||Math.abs(h.h-c.height)>40?{w:c.width,h:c.height}:h))});return o.observe(s),e.current={width:s.clientWidth,height:s.clientHeight},r({w:s.clientWidth,h:s.clientHeight}),()=>o.disconnect()},[]),{canvasRef:t,canvasSize:n,paneSizeRef:e}}function Bne(e){const t=y.useRef(new Map),n=y.useRef(0),r=y.useCallback(c=>{const d=t.current;let h=!1;for(const f of c.nodeInternals.values()){const p=f.width,g=f.height;if(p==null||g==null)continue;const v=d.get(f.id);v?(Math.abs(v.height-g)>4||Math.abs(v.width-p)>4)&&(d.set(f.id,{width:p,height:g}),h=!0):(d.set(f.id,{width:p,height:g}),h=!0)}return h&&(n.current+=1),n.current},[]),s=Xe(r),[o,l]=y.useState(0);return y.useEffect(()=>{let c=0;const d=()=>{const f=t.current;let p=!1;for(const g of document.querySelectorAll(".react-flow__node[data-id]")){const v=g.getAttribute("data-id");if(!v)continue;const N=g.offsetWidth,k=g.offsetHeight;if(!N||!k)continue;const x=f.get(v);(!x||Math.abs(x.width-N)>4||Math.abs(x.height-k)>4)&&(f.set(v,{width:N,height:k}),p=!0)}p&&l(g=>g+1)};if(e.current)return;let h=0;return document.visibilityState==="hidden"?h=window.setTimeout(d,32):c=requestAnimationFrame(d),()=>{cancelAnimationFrame(c),window.clearTimeout(h)}}),{measuredRef:t,measuredVersionRef:n,sizeVersion:s,domSizeVersion:o}}function qne(){const[e,t]=y.useState(!1);return y.useEffect(()=>{const n=window.setTimeout(()=>t(!0),2500);return()=>window.clearTimeout(n)},[]),e}function Une(){const e=y.useRef(null);return y.useEffect(()=>{let t=-1/0;const n=()=>{t=performance.now()},r=s=>{e.current=performance.now()-t<250?s.target:null};return window.addEventListener("pointerdown",n,!0),window.addEventListener("focusin",r,!0),()=>{window.removeEventListener("pointerdown",n,!0),window.removeEventListener("focusin",r,!0)}},[]),e}function zne({pointerFocusRef:e,nodesRef:t,stateRef:n,primarySelectedIdRef:r,providersRef:s,soundOnRef:o,keyHelpOpenRef:l,modalOpenRef:c,waitingCursorRef:d,removeSelectedRef:h,activateSoundRef:f,clearSelection:p,selectAgent:g,focusAgent:v,stepAgent:N,focusSession:k,requestClear:x,handleRelayout:j,handleFit:b,togglePause:_,toggleSessionList:E,toggleAccountsPanel:R,setDetailOpen:C,setUsageHistoryOpen:A,setUsagePanelOpen:U,setMachinePanelOpen:L,setBrowserWatchOpen:F,setSoundMenuOpen:O,setKeyHelpOpen:I,setTheme:B}){y.useEffect(()=>{const M=$=>{var D,W;const P=$.target,G={tagName:P==null?void 0:P.tagName,isContentEditable:P==null?void 0:P.isContentEditable,role:(D=P==null?void 0:P.getAttribute)==null?void 0:D.call(P,"role"),type:P==null?void 0:P.type,pointerFocused:P!=null&&P===e.current};if($.key==="Escape"){const J=cU({overlayOpen:ds.depth()>0,typing:hc(G)});J==="dismiss"?ds.dismissTop():J==="blur"?P==null||P.blur():(Bte(G)&&(P==null||P.blur()),p());return}if(eh($))return;const K=X0(P)?(W=P==null?void 0:P.getAttribute)==null?void 0:W.call(P,"data-id"):null,q=K&&t.current.some(J=>J.id===K)?K:null,H=Dte($,q);if(H.kind==="activate"){$.preventDefault(),g(H.nodeId,H.additive);return}if(H.kind!=="node"){if(xU({key:$.key,sheetOpen:l.current,target:G})){$.repeat||I(!1);return}if(!(H.nodeId==null&&wU(G,$.key))&&!vU({key:$.key,modalOpen:k$({appModal:c.current,dialogDepth:ds.dialogDepth()}),sheetOpen:l.current})&&!($.repeat&&!/^[ jkJK]$/.test($.key))){if($.key===" "&&($.preventDefault(),$.repeat||_()),($.key==="c"||$.key==="C")&&x("shortcut"),($.key==="r"||$.key==="R")&&j(),($.key==="f"||$.key==="F")&&b(),($.key==="z"||$.key==="Z")&&r.current&&v(r.current),$.key==="Delete"&&h.current(),($.key==="l"||$.key==="L")&&E(),$.key==="d"||$.key==="D")if(r.current)C(J=>!J);else{const J=Ix(n.current.agents.values());J.length>0?k(J[0].id):N(1)}if(($.key==="h"||$.key==="H")&&A(J=>!J),($.key==="u"||$.key==="U")&&U(J=>!J),($.key==="a"||$.key==="A")&&s.current.claude&&R(),($.key==="j"||$.key==="J")&&N(1),($.key==="k"||$.key==="K")&&N(-1),$.key==="w"||$.key==="W"){const J=Vq(Ix(n.current.agents.values()),d.current);J&&(d.current=J.id,k(J.id))}($.key==="t"||$.key==="T")&&B(J=>J==="dark"?"light":"dark"),($.key==="m"||$.key==="M")&&s.current.claude&&o.current!==null&&f.current($.shiftKey),($.key==="s"||$.key==="S")&&L(J=>!J),($.key==="b"||$.key==="B")&&F(J=>!J),($.key==="v"||$.key==="V")&&s.current.claude&&o.current!==null&&O(J=>!J),$.key==="?"&&I(J=>!J)}}};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[x,j,b,p,g,N,k,v,_])}function Wne(){var e,t;return((t=(e=document.activeElement)==null?void 0:e.matches)==null?void 0:t.call(e,":focus-visible"))===!0}function Hne({sessionListShown:e,usageShown:t,machineShown:n,accountsShown:r,detailShown:s,primarySelectedId:o,canvasRef:l}){const c={sessionList:y.useRef(null),usage:y.useRef(null),accounts:y.useRef(null),machine:y.useRef(null)},d=h=>()=>{Wne()&&h()};return{toggles:c,sessionList:d(is(!e,c.sessionList)),usage:d(is(!t,c.usage)),machine:d(is(!n,c.machine)),accounts:d(is(!r,c.accounts)),detail:d(is(!s,()=>{var h,f;o&&EL(o),Tn(((h=document.activeElement)==null?void 0:h.tagName)??null)&&((f=l.current)==null||f.focus({preventScroll:!0}))}))}}function Vne({nodes:e,stateRef:t,pinnedRef:n,positionsRef:r,draggingRef:s,dragPatchRef:o,setDragging:l,setDragMoveTick:c,setDragTick:d,endBubble:h,markInteract:f,disableAutoFit:p,beginTrashDrag:g,trackTrashDrag:v,endTrashDrag:N,removeNode:k}){const x=y.useRef(null);return{onNodeDragStart:(E,R)=>{var C,A;if(la(),h(),s.current=!0,o.current=new Map,l(!0),g(R.type==="agent"?((C=t.current.agents.get(R.id))==null?void 0:C.label)??"":null),f(),p(),R.type==="sessionGroup"){const U=(A=R.data)==null?void 0:A.sessionId,L=new Map;if(U)for(const F of e){const O=F.data;(O==null?void 0:O.sessionId)===U&&L.set(F.id,{x:F.position.x,y:F.position.y})}x.current={start:{x:R.position.x,y:R.position.y},members:L};return}n.current.set(R.id,{x:R.position.x,y:R.position.y})},onNodeDrag:(E,R)=>{var C;if(f(),R.type==="agent"&&v(E),R.type==="sessionGroup"){const A=x.current;if(!A)return;const U=R.position.x-A.start.x,L=R.position.y-A.start.y;for(const[O,I]of A.members){const B={x:I.x+U,y:I.y+L};n.current.set(O,B),r.current.set(O,B)}const F=o.current;if(F){for(const[O,I]of A.members)F.set(O,{x:I.x+U,y:I.y+L});F.set(R.id,{x:R.position.x,y:R.position.y})}c(O=>O+1);return}n.current.set(R.id,{x:R.position.x,y:R.position.y}),r.current.set(R.id,{x:R.position.x,y:R.position.y}),(C=o.current)==null||C.set(R.id,{x:R.position.x,y:R.position.y}),c(A=>A+1)},onNodeDragStop:(E,R)=>{f();const C=N(E,R.type==="agent");if(s.current=!1,o.current=null,l(!1),d(A=>A+1),R.type==="sessionGroup"){const A=x.current;if(A){const U=R.position.x-A.start.x,L=R.position.y-A.start.y;for(const[F,O]of A.members){const I={x:O.x+U,y:O.y+L};n.current.set(F,I),r.current.set(F,I)}}x.current=null,sc(r.current,n.current),d(U=>U+1);return}if(n.current.set(R.id,{x:R.position.x,y:R.position.y}),r.current.set(R.id,{x:R.position.x,y:R.position.y}),C){k(R.id);return}sc(r.current,n.current)}}}function Gne(e){return e.claude&&e.codex?"Claude Code and Codex":e.claude?"Claude Code":e.codex?"Codex":null}const Kne={claude:"Claude Code",codex:"Codex",opencode:"OpenCode",openclaw:"OpenClaw",copilot:"GitHub Copilot",pi:"pi-agent",zcode:"ZCode"};function Yne(e){const t=e.toLowerCase(),n=Ot(Kne,t);return n!==void 0?n:t?t[0].toUpperCase()+t.slice(1):""}function Xne(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Vle(e,t=[]){const n=t.length?Xne(t.map(Yne)):Gne(e);return n?`via ccusage · local ${n} logs`:"via ccusage · local agent logs"}function Zne(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 Jne(e,t){const n=t.prefs??fb,r=vi(n.done.level),s=vi(n["needs-input"].level),o=r===s?`${r}%`:`${r}% and ${s}%`,l=t.on?`Sound: on at ${o} — 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)",c=e.codex?`
|
|
95
95
|
|
|
@@ -106,7 +106,7 @@ ${e.map(s=>` ${s.label}: ${pi(s.waiting)} (${jd(r-s.waiting.since)})`).join(`
|
|
|
106
106
|
${qe(o.total)} spent${c?` · ${c}`:""}`:""}`,onClick:()=>{try{r(e.id)}catch{}},children:[a.jsx("span",{className:`state-pill state-${e.state}`,children:e.state==="active"?"live":e.state}),a.jsx("span",{className:"selected-label",children:e.label}),o.total>0&&a.jsxs("span",{className:"selected-cost",children:[qe(o.total),c?a.jsxs("span",{className:"selected-rate",children:[" · ",c]}):null]}),d>0&&a.jsxs("span",{className:"selected-extra",children:["+",d]}),a.jsx("span",{"aria-hidden":!0,className:"selected-close",onClick:h=>{h.stopPropagation(),s()},children:"×"})]})}function mse({catBarRef:e,catBarOccluded:t,presentCats:n,hiddenCats:r,toggleCat:s}){return a.jsx("div",{ref:e,className:`cat-filter-bar${t?" occluded":""}`,role:"group","aria-label":"Filter tools by category",children:n.map(o=>{const l=r.has(o);return a.jsxs("button",{type:"button",className:`cat-filter${l?" off":""}`,onClick:()=>s(o),"aria-pressed":!l,title:`${l?"Show":"Hide"} ${Fd[o]} tools`,children:[a.jsx(lre,{cat:o}),a.jsx("span",{className:"cat-name",children:Fd[o]})]},o)})})}const gse=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(",");function yse(e){var n,r;const t=e.target;!(t!=null&&t.closest)||t.closest(gse)!==e.currentTarget||(e.preventDefault(),(r=(n=document.activeElement)==null?void 0:n.blur)==null||r.call(n))}function wse({trashZoneRef:e,trashState:t,trashPhase:n,trashLabel:r}){return a.jsxs("div",{ref:e,className:`drag-trash-zone ${t}${n==="leaving"?" leaving":""}`,role:"status",children:[a.jsx("svg",{className:"drag-trash-icon",viewBox:"0 0 24 24","aria-hidden":"true",children:a.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"})}),a.jsxs("span",{className:"drag-trash-copy",children:[a.jsx("span",{className:"drag-trash-text",children:t==="over"?a.jsxs(a.Fragment,{children:["Release to remove ",a.jsx("strong",{className:"drag-trash-name",children:r||"this card"})]}):"Drop here to remove from the board"}),a.jsx("span",{className:"drag-trash-hint",children:t==="over"?"The session list (L) brings it back":"The session keeps running"})]})]})}function vse({canvasRef:e,bubbling:t,dragging:n,trash:r,zoom:s,viewport:o,stateRef:l,peek:c,children:d}){const{trashDragging:h,trashState:f,trashPhase:p,trashZoneRef:g,trashLabel:v}=r,{lod:N,lodRef:k}=s,{markCanvasInput:x}=o,{peekAgent:j,peekLabel:b,peekRecap:_,peekBounds:E}=c;return a.jsxs("main",{id:"canvas",tabIndex:-1,className:`canvas-wrap${t?" bubbling":""}${n?" dragging-any":""}${h&&f==="over"?" trash-hover":""}`,"data-lod":N,ref:e,onMouseDownCapture:yse,onPointerDownCapture:x,onPointerUpCapture:x,onWheelCapture:x,onFocusCapture:R=>{const C=R.target;if(!X0(C)||k.current==null||k.current==="detail")return;const A=C.getAttribute("data-id");A&&l.current.agents.has(A)&&C.matches(":focus-visible")&&CL(A,C,"focus")},onBlurCapture:R=>{var A,U;const C=(U=(A=R.target).getAttribute)==null?void 0:U.call(A,"data-id");C&&la(C)},children:[d,La(p)&&a.jsx(wse,{trashZoneRef:g,trashState:f,trashPhase:p,trashLabel:v}),a.jsx(zte,{agentFor:j,recapFor:_,labelFor:b,bounds:E})]})}function xse({restarting:e,restartMode:t,live:n,paused:r}){return a.jsxs("div",{className:"conn-banner",role:"alert",children:[a.jsx("span",{className:"conn-dot"}),e?t==="npx"?"Fetching the new version with npx — this can take a minute…":`Restarting ${kt}…`:(()=>{const s=Az({connected:n,paused:r});return a.jsxs(a.Fragment,{children:[`Lost connection to the ${kt} server. Reconnecting…`,s&&a.jsx("span",{className:"conn-sub",children:s})]})})()]})}function bse({oldName:e,version:t,dismissOldName:n}){return a.jsxs("div",{className:"ver-banner",role:"status",children:[a.jsx("span",{className:"ver-dot"}),a.jsxs("strong",{children:[e," still works — the deck is called ",kt," now."]}),t!=null&&t.renameFix?a.jsx("span",{className:"ver-sub",children:t.renameFix}):null,a.jsx("button",{type:"button","aria-label":"Dismiss",className:"ver-close",onClick:n,children:"×"})]})}const GL="Thanks — that helps.",kse=Array.from({length:11},(e,t)=>t);function Nse(e){return e===0?"0 out of 10, not useful":e===10?"10 out of 10, extremely useful":`${e} out of 10`}const jse=6;function Sse(e){const t=y.useRef(null);return y.useLayoutEffect(()=>{const n=t.current,r=n==null?void 0:n.closest(".app");if(!n||!r)return;const s=()=>r.style.setProperty("--rating-h",`${Math.ceil(n.getBoundingClientRect().height)}px`);s();const o=typeof ResizeObserver>"u"?null:new ResizeObserver(s);return o==null||o.observe(n),()=>{o==null||o.disconnect(),r.style.removeProperty("--rating-h")}},[e]),t}function _se(){var e;(e=document.getElementById("canvas"))==null||e.focus()}function Ese({phase:e,score:t,onAnswer:n,onLater:r,onClose:s,onFeedback:o,onHold:l}){const c=Sse(e),d=y.useRef(null),h=y.useRef(null),f=y.useRef(!1);y.useEffect(()=>{var g,v;e!=="thanks"||!f.current||(f.current=!1,Tn(((g=document.activeElement)==null?void 0:g.tagName)??null)&&((v=d.current??h.current)==null||v.focus()))},[e]);const p=g=>{var v;(v=c.current)!=null&&v.contains(document.activeElement)&&_se(),g()};return e==="thanks"?a.jsxs("div",{ref:c,className:"ver-banner note rating-banner",onFocus:()=>l(!0),onBlur:g=>{g.currentTarget.contains(g.relatedTarget)||l(!1)},children:[a.jsx("span",{className:"ver-dot"}),a.jsx("strong",{children:GL}),t!==null&&t<=jse?a.jsx("button",{ref:d,type:"button",className:"ver-act",onClick:o,children:"Tell us what would make it better"}):null,a.jsx("button",{ref:h,type:"button","aria-label":"Dismiss",className:"ver-close",onClick:()=>p(s),children:"×"})]}):a.jsxs("div",{ref:c,className:"ver-banner note rating-banner",role:"group","aria-labelledby":"rating-question",children:[a.jsx("span",{className:"ver-dot"}),a.jsx("strong",{id:"rating-question",children:"How useful is ccdeck to you?"}),a.jsx("span",{className:"rating-scale",children:kse.map(g=>a.jsx("button",{type:"button",className:"rating-pick","aria-label":Nse(g),onClick:v=>{f.current=v.detail===0||v.currentTarget.matches(":focus-visible"),n(g)},children:g},g))}),a.jsx("span",{className:"ver-sub rating-ends","aria-hidden":"true",children:"0 not at all · 10 extremely"}),a.jsx("button",{type:"button",className:"ver-act",onClick:()=>p(r),children:"Not now"})]})}const Tse=3e4;function Cse({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function Ase({bundle:e,running:t,pending:n,lastTried:r}){return t?Cse({bundle:e,running:t,lastTried:r})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function Rse(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function Mse({asked:e,reported:t}){return t?t!==e:!1}function KL(e){const t=e.thresholdMs??Tse;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 $se(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 Ise(e,t){return e?t==null?"auto when idle":`auto in ${$se(t)}`:"auto-restart off"}function YR(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function Ose(e,t=!1){return e<=0&&t?{label:"Restart anyway",clause:"the canvas is paused — running agents cannot be seen"}: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 Lse(e){const t=KL(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}}const XR={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",one_off:"this deck runs from a one-off pnpm dlx, bunx or yarn dlx copy that cannot be upgraded in place — to keep one, 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:"};function Pse({notice:e,version:t,dismissNotice:n,upgradeState:r,startUpgrade:s,copyCommand:o,cmdCopied:l,autoRestart:c,toggleAutoRestart:d,askRestart:h,restartCopy:f,restartFuseMs:p,restarting:g}){var v,N,k;return a.jsxs("div",{className:`ver-banner ${e.kind}`,role:"status",children:[a.jsx("span",{className:`ver-dot${p==null?"":" armed"}`}),e.kind==="restart"?a.jsxs(a.Fragment,{children:[a.jsxs("strong",{children:["v",e.to," is installed — this deck still runs v",e.from,"."]}),t!=null&&t.canRestart?a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"ver-act",onClick:()=>h(),...Dr(g),title:`Stop this process and bring it back on the same port. The canvas replays from the event log.
|
|
107
107
|
|
|
108
108
|
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:g?"restarting…":f.label}),!g&&a.jsx("span",{className:"ver-sub",children:f.clause}),a.jsxs("label",{className:"ver-auto",children:[a.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":c,onClick:d,"aria-label":"Auto-restart when idle",title:c?"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:a.jsx("span",{className:"switch-knob"})}),a.jsx("span",{"aria-hidden":!0,children:Ise(c,p)})]})]}):a.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."})]}):a.jsxs(a.Fragment,{children:[a.jsxs("strong",{children:[kt," v",e.to," is out — you are on v",e.from,"."]}),(t==null?void 0:t.upgradeMode)==="install"&&r!=="failed"&&a.jsx("button",{type:"button",className:"ver-act",onClick:s,...Dr(r==="running",r==="done"),title:`Runs ${((v=t==null?void 0:t.upgrade)==null?void 0:v.command)??(t==null?void 0:t.command)??"npm i -g"} here, then restarts once nothing is running.`,children:r==="running"?"installing…":r==="done"?"installed":"Update now"}),(t==null?void 0:t.upgradeMode)==="npx"&&(t==null?void 0:t.canRestart)&&a.jsx("button",{type:"button",className:"ver-act",onClick:()=>h({upgrade:!0}),...Dr(g),title:`Runs ${t==null?void 0:t.command} and hands it this port. Nothing is installed globally — npx unpacks its own copy.`,children:g?"fetching…":r==="failed"?"Retry update":"Update & restart"}),r==="failed"?a.jsxs("span",{className:"ver-sub fail",title:((N=t==null?void 0:t.upgrade)==null?void 0:N.error)??"",children:[(t==null?void 0:t.upgradeMode)==="npx"?"update failed":"install failed",": ",((k=t==null?void 0:t.upgrade)==null?void 0:k.error)??"unknown error"," — run it yourself:"]}):(t==null?void 0:t.upgradeMode)==="npx"?a.jsx("span",{className:"ver-sub",children:t!=null&&t.canRestart?"npx cannot upgrade in place, so the deck re-runs:":XR.npx}):t!=null&&t.upgradeBlocked?a.jsx("span",{className:"ver-sub",children:Ot(XR,t.upgradeBlocked)??"cannot install from here"}):null,a.jsxs("button",{type:"button",className:"ver-cmd",onClick:o,title:"Copy to clipboard",children:[a.jsx("code",{children:t==null?void 0:t.command}),a.jsx("span",{className:"ver-cmd-hint",children:l?"copied":"copy"})]})]}),a.jsx("button",{type:"button","aria-label":"Dismiss",className:"ver-close",onClick:n,children:"×"})]})}function Dse({restart:e,versionCheck:t,upgrade:n,oldNameNotice:r,rating:s,onFeedback:o,everConnected:l,live:c,paused:d}){const{autoRestart:h,toggleAutoRestart:f,restarting:p,restartMode:g,restartedTo:v,askRestart:N,restartCopy:k,restartFuseMs:x}=e,{version:j,notice:b,noticeOpen:_,dismissNotice:E}=t,{upgradeState:R,startUpgrade:C,copyCommand:A,cmdCopied:U}=n,{oldName:L,oldNameOpen:F,dismissOldName:O}=r,{ratingPhase:I,ratingScore:B,answerRating:M,rateLater:$,closeRating:P,holdThanks:G}=s,K=v?a.jsxs("div",{className:"ver-banner done",role:"status",children:[a.jsx("span",{className:"ver-dot"}),a.jsxs("strong",{children:["Restarted — now running v",v,"."]}),a.jsx("span",{className:"ver-sub",children:"The canvas replayed from the event log."})]}):l&&!c?a.jsx(xse,{restarting:p,restartMode:g,live:c,paused:d}):_&&b?a.jsx(Pse,{notice:b,version:j,dismissNotice:E,upgradeState:R,startUpgrade:C,copyCommand:A,cmdCopied:U,autoRestart:h,toggleAutoRestart:f,askRestart:N,restartCopy:k,restartFuseMs:x,restarting:p}):F&&L?a.jsx(bse,{oldName:L,version:j,dismissOldName:O}):I!=="hidden"?a.jsx(Ese,{phase:I,score:B,onAnswer:M,onLater:$,onClose:P,onFeedback:o,onHold:G}):null;return a.jsxs(a.Fragment,{children:[K,a.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:I==="thanks"?GL:""})]})}function Fse(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function Bse(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 qse(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function Use(e,t){const n=qse(e),r=(...l)=>[n?`${n} on the canvas`:null,...l,"layout, pins and selection"].filter(c=>c!==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 l=t.ownerPort===null?"another running deck owns that file":`the deck on port ${t.ownerPort} owns that file`,c=t.decks>2?`, one of ${t.decks} decks sharing it`:"";return{goes:r(),stays:[`the event log — ${l}${c}`,"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 o=t.decks-1;return{goes:r(`the event log ${o===1?"1 other running deck shares":`${o} other running decks share`} with this one — every session recorded in it, not just the ones drawn here`),stays:[o===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 zse({agentCount:e,onConfirm:t,onCancel:n}){const r=y.useRef(null),s=ut(n,{focusRef:r,layer:iU}),o=gt(n),[l,c]=y.useState(null);y.useEffect(()=>{let g=!1;return fetch("/api/clear").then(v=>v.ok?v.json():null).then(v=>{g||c(Bse(v))}).catch(()=>{}),()=>{g=!0}},[]);const{goes:d,stays:h,final:f,confirm:p}=Use(e,l);return a.jsx("div",{className:"modal-backdrop",...o,role:"presentation",children:a.jsxs("div",{ref:s,className:"modal clear-confirm",onClick:g=>g.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsxs("div",{className:"modal-title",children:[a.jsx("span",{className:"status-dot err","aria-hidden":!0}),a.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[a.jsxs("dl",{className:"cc-plan",children:[a.jsx("dt",{children:"Goes"}),a.jsx("dd",{children:d.map(g=>a.jsx("span",{children:g},g))}),a.jsx("dt",{children:"Stays"}),a.jsx("dd",{children:h.length>0?h.map(g=>a.jsx("span",{children:g},g)):a.jsx("span",{children:"nothing"})})]}),f&&a.jsx("p",{className:"cc-final",children:f}),a.jsxs("div",{className:"cc-actions",children:[a.jsx("button",{type:"button",ref:r,className:"btn",onClick:n,children:"Cancel"}),a.jsx("button",{type:"button",className:"btn danger",onClick:t,children:p})]})]})]})})}const jb=[{value:"bug",label:"Bug",question:"What happened?",placeholder:`I was trying to…
|
|
109
|
-
What did you expect to happen?`},{value:"idea",label:"Idea",question:"What would make ccdeck better?",placeholder:"It would be useful if…"},{value:"other",label:"Other",question:"What would you like to tell us?",placeholder:"Write anything…"}];function YL(e){return jb.find(t=>t.value===e)??jb[0]}const Sb=3,ux=120,Wse=1e4,Hse=200,Vse="Write something first.";function ZR(e){return e.trim()!==""}function Gse(e){var o;const t=e.trim();if(t==="")return"";const n=JR(t.split(/\r?\n/,1)[0]),r=((o=/^(.+?[.!?])(?=\s|$)/.exec(n))==null?void 0:o[1])??n,s=dx(r).length>=Sb?dx(r):dx(n);return Yse(s.length>=Sb?s:JR(t))}function Kse(e,t){const n=Gse(t);return n.length>=Sb?n:`${YL(e).label}: ${n}`}function JR(e){return e.replace(/\s+/g," ").trim()}function dx(e){return/[^.]\.$/.test(e)?e.slice(0,-1):e}function Yse(e){if(e.length<=ux)return e;const t=e.slice(0,ux-1),n=t.lastIndexOf(" ");return`${(n>=ux/2?t.slice(0,n):t).replace(/[\uD800-\uDBFF]$/,"").replace(/[\s,;:.\-–—]+$/,"")}…`}function Xse({kind:e,body:t,contact:n}){const r={kind:e,title:Kse(e,t),body:t.trim()};return n.trim()!==""&&(r.contact=n.trim()),r}function Zse(e){const t=e;return(t==null?void 0:t.ok)!==!0||typeof t.appVersion!="string"||typeof t.platform!="string"||t.appVersion===""||t.platform===""?null:{appVersion:t.appVersion,platform:t.platform}}const Jse={darwin:"macOS",win32:"Windows",linux:"Linux"};function Qse(e){const t=e.indexOf("-"),n=t===-1?e:e.slice(0,t),r=t===-1?"":e.slice(t+1),s=Jse[n]??n;return r?`${s} · ${r}`:s}function eae(e){return e?`ccdeck ${e.appVersion} · ${Qse(e.platform)}`:null}const tae="sent with it",nae="Your ccdeck version and system are sent with it.",rae="Add details",sae="How to reach you",aae="Email or GitHub @name",oae="Only if you would like an answer.",iae=["It all goes to the people who make ccdeck, with the version and system below.","Nothing becomes public by being sent. They may open a public GitHub issue from it, choosing its title and text; your contact and screenshots are never put on one."];function lae(e){return e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&!e.isComposing}function XL(e){return e.key==="Enter"&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&!e.isComposing}function cae(e){return/mac|iphone|ipad/i.test(e)?["⌘","Enter"]:["Ctrl","Enter"]}function uae(e){return[...e].length===1}const ZL="Thanks — feedback sent.";function QR(e,t,n){if(t==="vetoed")return"This deck was started with AGENTS_DECK_NO_INSTALL=1, which keeps it off the network, so nothing was sent.";if(e===429||t==="too_many")return"Too much feedback from this network in the last hour. Try again later; your text is still here.";if(e===413||t==="too_large")return"The images are too large to send together. Remove one and send again; your text is still here.";const r=n==null?void 0:n.images;return e===400&&Array.isArray(r)&&typeof r[0]=="string"?`The server did not accept an image. ${r[0]} Remove it and send again; your text is still here.`:e===400?"The server did not accept the message. It is still here; check it and send again.":"ccdeck's server could not be reached. Nothing was sent; your text is still here, so try again in a moment."}function dae(e){return e==="sending"?"Sending…":e==="sent"?ZL:""}const eM=1400,hae=160;function fae({kind:e,onChange:t}){return a.jsxs("fieldset",{className:"fb-kinds",children:[a.jsx("legend",{className:"vis-hidden",children:"Kind of feedback"}),jb.map(n=>a.jsxs("label",{className:"fb-kind",children:[a.jsx("input",{type:"radio",name:"feedback-kind",value:n.value,checked:e===n.value,onChange:()=>t(n.value),onKeyDown:r=>{XL(r.nativeEvent)&&r.preventDefault()}}),n.label]},n.value))]})}const JL="fb-details";function pae({open:e,onToggle:t}){return a.jsxs("button",{type:"button",className:"fb-tool fb-more","aria-expanded":e,"aria-controls":JL,onClick:t,children:[rae,a.jsx("svg",{className:"fb-chev",width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,focusable:"false",children:a.jsx("path",{d:"M2.5 3.75 5 6.25l2.5-2.5"})})]})}function mae({open:e,contact:t,onContact:n}){const r=y.useId();return a.jsx("div",{id:JL,className:"fb-details","data-open":e||void 0,children:a.jsx("div",{className:"fb-details-clip",children:a.jsxs("div",{className:"fb-details-body",children:[a.jsxs("div",{className:"fb-field",children:[a.jsxs("label",{className:"fb-field-label",htmlFor:"fb-contact",children:[sae,a.jsx("span",{className:"fb-optional",children:"optional"})]}),a.jsx("input",{id:"fb-contact",className:"ap-manage-input",type:"text",value:t,maxLength:Hse,autoComplete:"email",placeholder:aae,"aria-describedby":r,onChange:s=>n(s.target.value),onKeyDown:s=>{XL(s.nativeEvent)&&s.preventDefault()}}),a.jsx("p",{id:r,className:"fb-hint",children:oae})]}),a.jsx("div",{className:"fb-where",children:iae.map(s=>a.jsx("p",{children:s},s))})]})})})}const ti=3,gae=5*1024*1024,yae=12*1024*1024,_b=8192,wae=64*1024,vae=256*1024,xae=.92,bae=640,QL=.9,kae=.85,Nae=6,jae=512*1024,qd={png:"image/png",jpeg:"image/jpeg"},Sae={png:"png",jpeg:"jpg"},_ae=[137,80,78,71,13,10,26,10],Eae=[255,216,255];function eP(e){const t=n=>e.length>=n.length&&n.every((r,s)=>e[s]===r);return t(_ae)?"png":t(Eae)?"jpeg":null}function Tae(e){const t=eP(e);return t==="png"?Cae(e):t==="jpeg"?Rae(e):null}function Cae(e){const t=[73,72,68,82];if(e.length<24||!t.every((r,s)=>e[12+s]===r))return null;const n=new DataView(e.buffer,e.byteOffset,e.byteLength);return{width:n.getUint32(16),height:n.getUint32(20)}}function Aae(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}function Rae(e){let t=2;for(;t<e.length;){if(e[t]!==255)return null;for(;t<e.length&&e[t]===255;)t++;const n=e[t++];if(n===void 0||n===217||n===218)return null;if(n===1||n>=208&&n<=215)continue;if(t+2>e.length)return null;const r=e[t]<<8|e[t+1];if(r<2)return null;if(Aae(n))return t+7>e.length?null:{height:e[t+3]<<8|e[t+4],width:e[t+5]<<8|e[t+6]};t+=r}return null}function tM(e,t){return e.bytes>t||e.width>_b||e.height>_b}function Mae(e){return Math.min(gae,yae-wae-e)}function tP(e,t){return{width:Math.max(1,Math.floor(e.width*t)),height:Math.max(1,Math.floor(e.height*t))}}function $ae(e,t){const n=_b/Math.max(e.width,e.height),r=e.bytes>t?Math.sqrt(t/e.bytes)*QL:1;return tP(e,Math.min(1,n,r))}async function Iae(e,t,n){let r=$ae(e,t),s=e.format;for(let o=0;o<Nae;o++){const l=await n(r,s,s==="jpeg"?xae:void 0);if(!l)return null;if(l.size<=t)return{...r,blob:l,format:s};if(s==="png"){s="jpeg";continue}if(r=tP(r,Math.min(kae,Math.sqrt(t/l.size)*QL)),Math.max(r.width,r.height)<bae)return null}return null}async function Oae(e,t,n){const r=new Uint8Array(await e.slice(0,jae).arrayBuffer()),s=eP(r);if(!s)return{ok:!1,problem:"type"};if(t<vae)return{ok:!1,problem:"no_room"};const o=e.type===qd[s]?e:new Blob([e],{type:qd[s]}),l=Tae(r);if(l&&!tM({...l,bytes:e.size},t))return{ok:!0,blob:o,resized:null};const c=await n(e).catch(()=>null);if(!c)return{ok:!1,problem:"unreadable"};try{const d={width:c.width,height:c.height,bytes:e.size,format:s};if(!tM(d,t))return{ok:!0,blob:o,resized:null};const h=await Iae(d,t,c.encoder);return h?{ok:!0,blob:h.blob,resized:{width:h.width,height:h.height}}:{ok:!1,problem:"too_large"}}finally{c.release()}}function Lae(e){return({width:t,height:n},r,s)=>new Promise(o=>{const l=document.createElement("canvas");l.width=t,l.height=n;const c=l.getContext("2d");if(!c)return o(null);r==="jpeg"&&(c.fillStyle="white",c.fillRect(0,0,t,n)),c.imageSmoothingQuality="high",c.drawImage(e,0,0,t,n),l.toBlob(d=>{l.width=0,l.height=0,o(d)},qd[r],s)})}const Pae=async e=>{const t=await createImageBitmap(e);return{width:t.width,height:t.height,encoder:Lae(t),release:()=>t.close()}};function Dae(e){return e.includes("Files")}function Fae({files:e,hasText:t,intoTextField:n}){return e>0&&(!t||!n)}function Bae(e,t){const n=e.indexOf(t);return e[n+1]??e[n-1]??null}function qae(e,t){if(t.length===0)return{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)};const n=new FormData;return n.append("kind",e.kind),n.append("title",e.title),n.append("body",e.body),e.contact!==void 0&&n.append("contact",e.contact),t.forEach((r,s)=>{const o=r.type===qd.jpeg?"jpeg":"png";n.append("images",r,`image-${s+1}.${Sae[o]}`)}),{method:"POST",body:n}}const Uae="Add screenshot",nM="PNG or JPEG, up to three. You can also paste one, or drop it on this dialog.",zae="A screenshot can show emails, costs and paths. Crop out what should not be seen.",rM="Three images at most. Remove one to add another.",Wae="An image could not be attached, so nothing was sent. Check the images and send again; your text is still here.";function Hae(e,t,n){const r=n?`, resized to ${n.width} × ${n.height} to fit`:"";return`Replace image ${e+1}: ${t}${r}`}function Vae(e,t){const n=`${e} of ${ti}`;return t>0?`${n} · ${t} resized to fit`:n}function Gae(e){return`Three images at most, so ${e===1?"one was":`${e} were`} left out.`}function Kae(e){return`“${e.length>40?`${e.slice(0,30)}…${e.slice(-9)}`:e}”`}function Yae(e,t){const n=Kae(t);return e==="type"?`${n} is not a PNG or a JPEG, so it was not added. GIF, WebP and HEIC are not converted; save it as a PNG or a JPEG first.`:e==="no_room"?`There is no room left for ${n}: images go at up to 12 MB in all. Remove one to add it.`:e==="unreadable"?`${n} could not be read as an image.`:`${n} could not be made small enough to send: images go at up to 5 MB each.`}const nP="image/png,image/jpeg";function rP({className:e="fb-glyph"}){return a.jsxs("svg",{className:e,width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,focusable:"false",children:[a.jsx("rect",{x:"1.8",y:"2.4",width:"10.4",height:"9.2",rx:"1.6"}),a.jsx("circle",{cx:"5",cy:"5.6",r:"1"}),a.jsx("path",{d:"M2.4 10.4 5.5 7.6l2.1 1.8 1.5-1.3 2.5 2.2"})]})}function Xae({images:e,buttonRef:t}){const n=y.useRef(null),r=e.shots.length>=ti;return a.jsxs(a.Fragment,{children:[a.jsxs("button",{ref:t,type:"button",className:"fb-tool",title:nM,"aria-describedby":"fb-attach-hint",onClick:()=>{var s;return r?e.sayFull():(s=n.current)==null?void 0:s.click()},children:[a.jsx(rP,{}),Uae]}),a.jsx("span",{id:"fb-attach-hint",hidden:!0,children:nM}),a.jsx("input",{ref:n,type:"file",accept:nP,multiple:!0,hidden:!0,onChange:s=>{e.add(Array.from(s.target.files??[])),s.target.value=""}})]})}function Zae({images:e,addRef:t}){const n=y.useRef(new Map),r=y.useRef(null),s=y.useRef(null),o=y.useRef(null),[l,c]=y.useState(null),{shots:d}=e,h=Vae(d.length,d.filter(g=>g.resized).length);y.useLayoutEffect(()=>{var g;l!==null&&((g=l==="add"?t.current:n.current.get(l))==null||g.focus(),c(null))},[l,t]),y.useEffect(()=>{var g;e.problem&&((g=r.current)==null||g.scrollIntoView({block:"nearest"}))},[e.problem,e.problemId]);function f(g){c(Bae(d.map(v=>v.id),g)??"add"),e.remove(g)}function p(g){var v;o.current=g,(v=s.current)==null||v.click()}return a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"vis-hidden",role:"status",children:e.announcement}),a.jsx("input",{ref:s,type:"file",accept:nP,hidden:!0,onChange:g=>{const v=o.current;v!==null&&e.replace(v,Array.from(g.target.files??[])),o.current=null,g.target.value=""}}),d.length>0&&a.jsxs("div",{className:"fb-shots",children:[a.jsxs("div",{className:"fb-shots-row",children:[a.jsx("ul",{className:"fb-shots-list",children:d.map((g,v)=>a.jsxs("li",{className:"fb-shot","data-fitting":g.blob?void 0:!0,children:[a.jsxs("button",{type:"button",className:"fb-shot-pick","aria-label":Hae(v,g.name,g.resized),onClick:()=>p(g.id),children:[a.jsx("img",{className:"fb-shot-img",src:g.url,alt:""}),g.blob?a.jsx("span",{className:"fb-shot-cue","aria-hidden":"true",children:"Replace"}):a.jsx("span",{className:"fb-shot-busy","aria-hidden":"true",children:"Resizing…"})]}),a.jsx("button",{ref:N=>{N?n.current.set(g.id,N):n.current.delete(g.id)},type:"button",className:"glyph-btn fb-shot-remove","aria-label":`Remove image ${v+1}`,title:`Remove image ${v+1}`,onClick:()=>f(g.id),children:a.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round","aria-hidden":!0,focusable:"false",children:a.jsx("path",{d:"M2.5 2.5 7.5 7.5M7.5 2.5 2.5 7.5"})})})]},g.id))}),a.jsx("span",{className:"fb-shots-count",children:h})]}),a.jsx("p",{className:"fb-hint",children:zae})]}),e.problem&&a.jsx("p",{ref:r,className:"fb-error",role:"alert",children:e.problem},e.problemId)]})}function Jae(e,t,n){return n?e.map(r=>r.id===t.id?t:r):[...e,t]}function Qae(e,t,n){return n?e.map(r=>r.id===t?n:r):e.filter(r=>r.id!==t)}function eoe(){const[e,t]=y.useState([]),[n,r]=y.useState({problem:"",id:0}),s=y.useRef(0),o=y.useCallback(C=>{C&&s.current++,r(A=>C?{problem:C,id:A.id+1}:A.problem?{problem:"",id:A.id}:A)},[]),[l,c]=y.useState(""),d=y.useRef([]),h=y.useRef(null),f=y.useRef(1),p=y.useRef(!0),g=y.useCallback(C=>{d.current=C(d.current),t(d.current)},[]);y.useEffect(()=>(p.current=!0,()=>{p.current=!1;for(const C of d.current)URL.revokeObjectURL(C.url)}),[]);const v=y.useCallback(async(C,A)=>{const U=d.current.reduce((P,G)=>{var K;return P+(G.id===(A==null?void 0:A.id)?0:((K=G.blob)==null?void 0:K.size)??0)},0),L=(A==null?void 0:A.id)??f.current++,F=URL.createObjectURL(C),O={id:L,name:C.name||"image",url:F,blob:null,resized:null};let I=!1;const B=()=>{I||(I=!0,g(P=>Jae(P,O,A!==void 0)))},M=await Oae(C,Mae(U),async P=>(B(),Pae(P))).catch(()=>({ok:!1,problem:"unreadable"})),$=d.current.some(P=>P.id===L);return!p.current||!$&&(I||A)?(URL.revokeObjectURL(F),A&&URL.revokeObjectURL(A.url),""):M.ok?(B(),A&&URL.revokeObjectURL(A.url),g(P=>P.map(G=>G.id===L?{...G,blob:M.blob,resized:M.resized}:G)),""):(URL.revokeObjectURL(F),I&&g(P=>Qae(P,L,A)),Yae(M.problem,C.name||"image"))},[g]),N=y.useCallback(async C=>{o("");const A=[];let U=0,L=0;for(const O of C){if(!p.current)return;if(d.current.length>=ti){U++;continue}const I=d.current.length,B=await v(O);B&&A.push(B),d.current.length>I&&L++}if(!p.current)return;U>0&&A.push(L===0&&A.length===0?rM:Gae(U)),o(A.join(" "));const F=d.current.length;L>0&&c(`${L===1?"Image":`${L} images`} added, ${F} of ${ti}.`)},[v,o]),k=y.useCallback(async(C,A)=>{o("");const U=d.current.find(O=>O.id===C);if(!U)return N([A]);const L=await v(A,U);if(!p.current)return;o(L);const F=d.current.findIndex(O=>O.id===C);!L&&F!==-1&&c(`Image ${F+1} replaced, ${d.current.length} of ${ti}.`)},[N,v,o]),x=y.useCallback(C=>{h.current=(h.current??Promise.resolve()).then(C).catch(()=>{})},[]),j=y.useCallback(C=>{C.length>0&&x(()=>N(C))},[N,x]),b=y.useCallback((C,A)=>{const U=A[0];U&&x(()=>k(C,U))},[x,k]),_=y.useCallback(C=>{const A=d.current.find(U=>U.id===C);A&&(URL.revokeObjectURL(A.url),g(U=>U.filter(L=>L.id!==C)),o(""),c(`Image removed, ${d.current.length} of ${ti}.`))},[g,o]),E=y.useCallback(()=>o(rM),[o]),R=y.useCallback(async()=>{const C=s.current;return await h.current,s.current!==C?null:d.current.flatMap(A=>A.blob?[A.blob]:[])},[]);return{shots:e,problem:n.problem,problemId:n.id,announcement:l,add:j,replace:b,remove:_,sayFull:E,ready:R}}function toe(){const[e,t]=y.useState(null);return y.useEffect(()=>{let n=!0;return fetch("/api/feedback").then(r=>r.ok?r.json():null).then(r=>{n&&t(Zse(r))}).catch(()=>{}),()=>{n=!1}},[]),e}function noe(e){const[t,n]=y.useState({state:"idle"}),r=y.useRef(!1),s=y.useRef(null);y.useEffect(()=>()=>{var l;return(l=s.current)==null?void 0:l.abort()},[]);async function o(l){if(!lr(r.current))return;r.current=!0;const{signal:c}=s.current=new AbortController;n({state:"sending"});try{const d=await e.ready();if(c.aborted)return;if(!d){n({state:"failed",message:Wae});return}const h=await fetch("/api/feedback",{...qae(Xse(l),d),signal:c}),f=await h.json().catch(()=>null);n(h.ok&&(f!=null&&f.ok)?{state:"sent"}:{state:"failed",message:QR(h.status,f==null?void 0:f.reason,f==null?void 0:f.errors)})}catch{c.aborted||n({state:"failed",message:QR(0,null)})}finally{r.current=!1}}return{outcome:t,sending:t.state==="sending",send:o}}function roe(e,t){const[n,r]=y.useState(!1),s=y.useRef(t);return s.current=t,y.useEffect(()=>{if(!e)return;const o=window.setTimeout(()=>r(!0),eM),l=window.setTimeout(()=>s.current(),eM+hae);return()=>{window.clearTimeout(o),window.clearTimeout(l)}},[e]),n}function soe(){var t;return typeof navigator>"u"?"":((t=navigator.userAgentData)==null?void 0:t.platform)||navigator.platform||""}function sP({onClose:e,initialKind:t,initialBody:n}){const r=y.useRef(null),s=y.useRef(null),o=y.useRef(null),l=y.useRef(null),c=y.useRef(null),d=y.useRef(null),h=y.useRef(null),f=y.useRef(0),p=ut(e,{focusRef:r}),g=gt(e),[v,N]=y.useState(t??"bug"),[k,x]=y.useState(n??""),[j,b]=y.useState(""),[_,E]=y.useState(!1),[R,C]=y.useState(!1),[A,U]=y.useState(!1),L=eoe(),F=eae(toe()),{outcome:O,sending:I,send:B}=noe(L),M=O.state==="sent",$=roe(M,e),P=YL(v),G=R&&!ZR(k),[K,q]=cae(soe());y.useEffect(()=>{var ke,ae;const se=l.current;if(!se)return;const pe=se.contains(document.activeElement)||Tn(((ke=document.activeElement)==null?void 0:ke.tagName)??null);se.inert=M,M&&pe&&((ae=s.current)==null||ae.focus())},[M]),y.useEffect(()=>{var ae,fe;const se=c.current;if(!se)return;if(I){const me=document.activeElement;h.current=me&&se.contains(me)?me:null,se.inert=!0,h.current&&((ae=d.current)==null||ae.focus());return}se.inert=!1;const pe=h.current;h.current=null;const ke=document.activeElement===d.current||Tn(((fe=document.activeElement)==null?void 0:fe.tagName)??null);!M&&pe&&ke&&pe.focus()},[I,M]);function H(se){var pe;if(se.preventDefault(),!ZR(k)){C(!0),(pe=r.current)==null||pe.focus();return}B({kind:v,body:k,contact:j})}const D=!M&&!I,W=se=>Dae(Array.from(se.dataTransfer.types));function J(se){!W(se)||!D||(se.preventDefault(),f.current++,U(!0))}function V(se){W(se)&&(se.preventDefault(),se.dataTransfer.dropEffect=D?"copy":"none")}function X(se){W(se)&&(f.current=Math.max(0,f.current-1),f.current===0&&U(!1))}function Y(se){W(se)&&(se.preventDefault(),f.current=0,U(!1),D&&L.add(Array.from(se.dataTransfer.files)))}function Z(se){se.target!==se.currentTarget||!W(se)||(se.preventDefault(),se.dataTransfer.dropEffect="none")}function ee(se){W(se)&&se.preventDefault()}function ne(se){if(!D)return;const pe=Array.from(se.clipboardData.files),ke=se.target,ae=ke instanceof HTMLTextAreaElement||ke instanceof HTMLInputElement,fe=Array.from(se.clipboardData.types).includes("text/plain");Fae({files:pe.length,hasText:fe,intoTextField:ae})&&(se.preventDefault(),L.add(pe))}return a.jsx("div",{className:"modal-backdrop",...g,role:"presentation",onDragOver:Z,onDrop:ee,"data-leaving":$||void 0,children:a.jsxs("div",{ref:p,className:"modal feedback-dialog",onClick:se=>se.stopPropagation(),onDragEnter:J,onDragOver:V,onDragLeave:X,onDrop:Y,onPaste:ne,role:"dialog","aria-modal":"true","aria-labelledby":"feedback-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"feedback-title",className:"modal-tool-name",children:"Send feedback"})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{ref:s,type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsx("p",{className:"vis-hidden",role:"status",children:dae(O.state)}),a.jsxs("div",{className:"fb-stage",children:[a.jsxs("form",{ref:l,className:"fb-form",onSubmit:H,onKeyDown:se=>{lae(se.nativeEvent)&&(se.preventDefault(),se.currentTarget.requestSubmit())},noValidate:!0,children:[a.jsxs("section",{ref:c,className:"modal-body fb-body",children:[a.jsx(fae,{kind:v,onChange:N}),a.jsxs("div",{className:"fb-compose",children:[a.jsx("label",{className:"fb-label",htmlFor:"fb-body",children:P.question}),a.jsx("textarea",{ref:r,id:"fb-body",className:"ap-manage-input fb-message",value:k,maxLength:Wse,rows:5,placeholder:P.placeholder,onChange:se=>x(se.target.value),"aria-invalid":G||void 0,"aria-describedby":G?"fb-body-error":void 0,required:!0}),G&&a.jsx("p",{id:"fb-body-error",className:"fb-error",children:Vse}),a.jsx(Zae,{images:L,addRef:o}),a.jsxs("div",{className:"fb-tools",children:[a.jsx(Xae,{images:L,buttonRef:o}),a.jsx(pae,{open:_,onToggle:()=>E(se=>!se)})]}),a.jsx(mae,{open:_,contact:j,onContact:b})]}),a.jsx("p",{className:"fb-facts",children:F?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"fb-facts-value",children:F})," — ",tae]}):nae}),O.state==="failed"&&a.jsx("p",{className:"fb-error",role:"alert",children:O.message})]}),a.jsxs("div",{className:"fb-foot",children:[a.jsxs("span",{className:"fb-shortcut","aria-hidden":"true",children:[a.jsx("kbd",{"data-symbol":uae(K)||void 0,children:K}),a.jsx("kbd",{children:q})," to send"]}),a.jsx("button",{type:"button",className:"btn",onClick:e,children:"Cancel"}),a.jsx("button",{ref:d,type:"submit",className:"btn primary fb-send","aria-keyshortcuts":"Meta+Enter Control+Enter",...Dr(I),children:a.jsxs("span",{className:"fb-send-label",children:[a.jsx("span",{className:"fb-send-idle",children:"Send feedback"}),a.jsx("span",{className:"fb-send-busy",children:"Sending…"})]})})]})]}),M&&a.jsxs("div",{className:"fb-done",children:[a.jsx(Td,{}),a.jsx("p",{className:"fb-done-line",children:ZL})]})]}),a.jsx("div",{className:"fb-drop","aria-hidden":"true","data-active":A||void 0,children:a.jsxs("div",{className:"fb-drop-frame",children:[a.jsx(rP,{className:"fb-drop-glyph"}),a.jsx("p",{className:"fb-drop-title",children:"Drop to attach"}),a.jsx("p",{className:"fb-drop-note",children:"PNG or JPEG, up to three"})]})})]})})}const aoe="Press Esc first if a key does nothing.",ooe=[{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 — the session list (L) 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 ioe({onClose:e,onTour:t}){const n=ut(e),r=gt(e);return a.jsx("div",{className:"modal-backdrop",...r,role:"presentation",children:a.jsxs("div",{ref:n,className:"modal key-help",onClick:s=>s.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[t&&a.jsxs("div",{className:"guide-door",children:[a.jsx("span",{children:"Eight pictures of what the deck shows."}),a.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),a.jsx("div",{className:"shortcuts",children:ooe.map(s=>a.jsxs(y.Fragment,{children:[a.jsx("h3",{className:"kh-group",children:s.title}),s.rows.map(o=>a.jsxs("div",{className:"sc",children:[a.jsx("kbd",{children:o.cap}),a.jsx("span",{children:o.action})]},`${s.title}:${o.cap}:${o.action}`))]},s.title))}),a.jsx("p",{className:"kh-foot",children:aoe})]})]})})}function aP(e,t){return y.lazy(()=>e().catch(n=>(console.warn(`ccdeck could not load ${t}`,n),{default:({onClose:r})=>a.jsx(loe,{name:t,onClose:r})})))}function loe({name:e,onClose:t}){const n=y.useRef(null),r=ut(t,{focusRef:n}),s=gt(t);return a.jsx("div",{className:"modal-backdrop",...s,role:"presentation",children:a.jsxs("div",{ref:r,className:"modal dialog-missing",onClick:o=>o.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"dialog-missing-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"dialog-missing-title",className:"modal-tool-name",children:e})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[a.jsxs("p",{className:"dm-note",children:[e," did not load. The deck has most likely been updated since this tab opened, and a reload picks up the new version."]}),a.jsxs("div",{className:"dm-actions",children:[a.jsx("button",{type:"button",className:"btn",onClick:t,children:"Close"}),a.jsx("button",{type:"button",ref:n,className:"btn primary",onClick:()=>window.location.reload(),children:"Reload"})]})]})]})})}function coe(e,t){return`${e}#${t}`}function uoe(e,{lan:t,now:n,closed:r}){if(t===void 0)return[];const s=[];for(const o of e??[]){const l=o.reauth;if(!l||l.dismissed||o.origin!=="ccdeck_signin")continue;const c=coe(l.key,l.since);if(r.has(c)||XG(l.key,o.email,t,n))continue;const d=o.email??"";s.push({id:c,key:l.key,since:l.since,num:o.num,email:d,name:d||o.alias||`Account ${o.num}`,alias:d&&o.alias?o.alias:null})}return s}function doe(e,t){const n=String((t==null?void 0:t.email)??"").trim().toLowerCase();return n?e.filter(r=>r.email.toLowerCase()===n&&((t==null?void 0:t.num)==null||String(r.num)===String(t.num))).map(r=>r.id):[]}function oP({rows:e,ours:t,dialogs:n}){return e===0?!1:t||n===0}function hoe(e){return e===1?"Account needs your attention":"Accounts need your attention"}function foe(e){return`${e===1?"One Claude account needs":`${e} Claude accounts need`} you to sign in again.`}const poe="Login expired",moe="Until then the deck cannot read its usage or switch to it. Signing in again brings it back — it keeps its slot, its alias and its history.",goe="The account stays marked in the Accounts panel. This will not ask again until it has worked and stopped again.";function yoe(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,o)=>(s.at??0)-(o.at??0));return{request:r[0],waiting:r.length-1}}function woe({request:e,waiting:t,busy:n,now:r,onAccept:s,onDecline:o,onLater:l}){const c=y.useRef(null),d=ut(l,{focusRef:c}),h=gt(l),f=ia(n,"accept"),p=ia(n,"dismiss");return a.jsx("div",{className:"modal-backdrop",...h,role:"presentation",children:a.jsxs("div",{ref:d,className:"modal lan-ask",onClick:g=>g.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-ask-title","aria-describedby":"lan-ask-who",children:[a.jsxs("header",{className:"modal-head",children:[a.jsxs("div",{className:"modal-title",children:[a.jsx("i",{className:"ap-pulse","aria-hidden":!0}),a.jsx("span",{id:"lan-ask-title",className:"modal-tool-name",children:"A deck wants to pair"})]}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:l,"aria-label":"Answer later (Esc)",title:"Answer later (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[a.jsxs("p",{id:"lan-ask-who",className:"lan-ask-who",children:[a.jsx("strong",{className:"lan-ask-name",children:e.name})," at ",a.jsx("code",{className:"ap-lan-code",children:e.addr})," · asked ",j0(e.at,r)]}),a.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."}),a.jsxs("p",{className:"lan-ask-fp",children:["Its fingerprint is ",a.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&&a.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.`}),a.jsxs("div",{className:"lan-ask-acts",children:[a.jsx("button",{type:"button",ref:c,className:"btn",disabled:p.disabled,"aria-busy":p.busy,onClick:o,title:"Nothing is shared. If that deck asks again, this comes back.",children:n==="dismiss"?"declining…":"Decline"}),a.jsx("button",{type:"button",className:"btn primary",disabled:f.disabled,"aria-busy":f.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"})]})]})]})})}function voe(e){const t=y.useRef(!1),n=xoe(e),r=oP({rows:n?1:0,ours:t.current,dialogs:ds.dialogDepth()});return t.current=r,r?n:null}function xoe({lanPending:e,lanDeferred:t,lanBusy:n,answerLanPair:r,deferLanPair:s}){const{request:o,waiting:l}=yoe(e,t.current);return o?a.jsx(woe,{request:o,waiting:l,busy:n,now:Date.now(),onAccept:()=>void r("accept",o.fp),onDecline:()=>void r("dismiss",o.fp),onLater:()=>s(o.fp)},o.fp):null}function boe({rows:e,onSignIn:t,onLater:n,firstRef:r}){const s=e.length===1?e[0]:null;return a.jsxs("section",{className:"modal-body",children:[s?a.jsxs(a.Fragment,{children:[a.jsxs("p",{id:"reauth-lead",className:"reauth-lead",children:["The Claude login for ",a.jsx("strong",{className:"reauth-name",children:s.name}),s.alias?a.jsxs("span",{className:"reauth-alias",children:[" (",s.alias,")"]}):null," ","has expired and needs a new sign","‑","in."]}),a.jsx("p",{className:"reauth-note",children:moe})]}):a.jsxs(a.Fragment,{children:[a.jsx("p",{id:"reauth-lead",className:"reauth-lead",children:foe(e.length)}),a.jsx("ul",{className:"reauth-list",children:e.map((o,l)=>a.jsxs("li",{className:"reauth-row",children:[a.jsxs("span",{className:"reauth-who",title:o.alias?`${o.alias} — ${o.name}`:o.name,children:[o.name,o.alias?a.jsxs("span",{className:"reauth-alias",children:[" ",o.alias]}):null]}),a.jsx("span",{className:"reauth-what",children:poe}),a.jsx("button",{type:"button",className:"btn",ref:l===0?r:void 0,"aria-label":`Sign in again as ${o.name}`,onClick:()=>t(o),children:"Sign in again"})]},o.id))}),a.jsx("p",{className:"reauth-note",children:"Each keeps its slot, its alias and its history."})]}),a.jsxs("div",{className:"reauth-acts",children:[a.jsx("button",{type:"button",className:"btn",title:goe,onClick:n,children:"Not now"}),s&&a.jsx("button",{type:"button",className:"btn primary",ref:r,onClick:()=>t(s),children:"Sign in again"})]})]})}function koe({rows:e,onSignIn:t,onLater:n}){const r=y.useRef(null),s=ut(n,{focusRef:r}),o=gt(n);return a.jsx("div",{className:"modal-backdrop",...o,role:"presentation",children:a.jsxs("div",{ref:s,className:"modal reauth-ask",onClick:l=>l.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"reauth-title","aria-describedby":"reauth-lead",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"reauth-title",className:"modal-tool-name",children:hoe(e.length)})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Not now (Esc)",title:"Not now (Esc)",children:"×"})})]}),a.jsx(boe,{rows:e,onSignIn:t,onLater:n,firstRef:r})]})})}function Noe({rows:e,signingIn:t,signIn:n,signedIn:r,refresh:s,closeSignIn:o,later:l,pairing:c=!1}){const d=y.useRef(!1),h=ds.dialogDepth()+(c?1:0),f=t!=null||oP({rows:e.length,ours:d.current,dialogs:h});return d.current=f,t?a.jsx(OI,{email:t.email||null,onClose:o,onChanged:s,onSignedIn:r}):f?a.jsx(koe,{rows:e,onSignIn:n,onLater:l},e.length===1?"one":"many"):null}const joe={"//":["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.4","3.29.6","3.29.7","3.29.9","3.33.1","3.35.0","3.35.1","3.36.0","3.36.1","3.36.4","3.36.5","3.36.6","3.36.7","3.36.8","3.36.9","3.37.0","3.38.0"],"3.37.1":[{title:"🔁 Expired logins repair from your other machines",body:"When a login stops working on this machine and a machine you paired with still has it working and ticked, Local network now copies it back on the next round, whether or not the account is ticked here. Before, it stayed marked expired until the account was ticked here as well, or deleted so that it arrived again. A machine that paired on its own, through Say yes to every deck that asks, still repairs only the accounts ticked here."}],"3.36.3":[{title:"🔑 An expired login asks to be signed in again",body:"When an account you added with + → Sign in stops working, the deck now tells you in one dialog, with every affected account together and Sign in again beside each. That opens the usual sign-in with the address already filled in, and the account keeps its slot, its alias and its history. Not now leaves it marked in the Accounts panel and does not ask again until it has worked and stopped again. A paired deck holding a working copy gets to repair it first, and accounts that came from a share or Local network are never asked about."}],"3.34.1":[{title:"🗂️ The tray menu stays open while you read it",body:"On Linux the menu behind the tray icon could close by itself while agents were working, often before the row you pressed took the click, so it had to be opened and pressed again. It now changes only when something it says has changed, and stays open while you choose."}],"3.34.0":[{title:"🗺️ The network map shows who you are connected to",body:"Paired decks that are on stand closest to this one, and a light runs along their wires. Paired decks that are away come next, in a colour of their own, with how long they have been gone, and machines that are not paired stand outside in grey. Decks reached over Tailscale sit together in their own shaded slice instead of on dashed wires. Pointing at a deck opens its details beside the map: whether it is there, what to do next if anything, its address and what it runs, and every login the two share, the ones that need a look first."},{title:"🔑 A login that expired everywhere says so",body:`When a shared login expired on this deck and every paired deck that is on held an expired copy too, the row said "Login expired" and waited for a repair that could never come. It now says "Login expired on all online decks". Claude retires a login's other copies each time one machine refreshes it, so shared copies expire together: sign in again on any one machine and the others repair from it on their next round.`},{title:"💬 Send feedback from inside the deck",body:'Appearance settings has a "Send feedback…" button: pick what kind it is, write a title and a few lines, and add a way to reach you if you want an answer. It goes to the people who make ccdeck, who may open a public issue from it, never with your contact in it. If it cannot be sent, the form stays filled in and says why.'}],"3.33.0":[{title:"🪝 Hooks you add in Claude Code are no longer removed",body:"Claude Code's hook editor often files a new hook into the same group as the deck's own. Starting the deck, or uninstalling it, then removed the whole group, and your hook went with it without a word. The deck now takes out only its own command and leaves yours where it was, and the same goes for the old finish-sound hook. `ccdeck --uninstall` also stops the decks that are running, so an update in the background cannot put the hooks back."},{title:"🧵 Resumed Codex sessions show up again",body:"A Codex session picked up with `codex resume`, or one that ran for days, could go dark on the canvas and drop out of the 5-hour and 7-day usage, because the deck only looked in the two newest day folders. It now follows those sessions and counts their tokens. Two Codex sessions in the same folder get different id suffixes, and a `bash -lc` call shows the command it runs."},{title:"🤝 A deck paired by the accept switch brings in less",body:'A deck that paired through the automatic accept switch, and not through an invite, now brings in only the logins you have ticked on this deck, and nothing from it is ticked for sharing onward. Its dialog says "paired automatically — pair by invite to take it". Pairing by invite works as before. A typed address is no longer dropped after one failed round, and the sync port stays the same after a rename.'},{title:"⬆️ Desktop updates install when you expect them",body:'On Windows and Linux a downloaded update now installs when you quit. On a Mac, Quit installs it and the app stays closed. The Linux .deb needs an administrator password to install, so it no longer does that by itself: it waits for "Restart to update" and says a password is coming. "Start at login" now works on Linux, and "Restart ccdeck" stops a deck that has hung.'},{title:"🕵️ Browser Watch waits before it acts, and quits only its own browser",body:"A program's visit is now logged and reacted to once its quiet window has closed, about 16 minutes after it, and not on the first poll, so a visit that is withdrawn no longer quits the browser. On Linux the quit reaction ends only the browser that holds the watched profile; other Chrome channels and headless browsers keep running. When it cannot tell which process that is, it does nothing and says so, which includes a Flatpak Brave."},{title:"🧮 Figures that were off are right",body:`Spend by labelled and workflow subagents counts toward a session's tokens and cost. The Projects report prices 1-hour cache writes the way ccusage does, so its dollars match the Usage panel. After a restart the deck rebuilds its whole event history, where it used to rebuild about a third. On Linux the process list shows what each process is using now, not its lifetime average. A count near a boundary reads "1.00M", and a full quota window says "used up".`},{title:"🔑 The Usage panel's reads answer the deck's own page only",body:"The routes behind the Usage panel (/api/quota, /api/ccusage, /api/codex-usage, /api/codex-quota and /api/cswap-auto) now answer the deck's own page, or a client that sends the deck's token. A script that read them with a plain request gets 401 from this version on. The hook, the desktop app and the `ccdeck` command are not affected."},{title:"🛠️ Smaller fixes you may notice",body:"With the canvas paused, an update no longer restarts the server while an agent is working: it waits until no turn is open. `ccdeck --stop -p4317` stops that one deck. A deck started at login can update itself on Homebrew and nvm setups. Dialogs keep keyboard focus after a button goes away, screen readers hear pairing requests by deck name and the machine panel's readings, dim text is readable in both themes, Windows High Contrast shows what is selected, and below 640px the detail panel opens over the canvas."}],"3.32.2":[{title:"🔒 Self-updates wait until your screen is unlocked",body:"On Linux with GNOME, the app installs an update by itself when you leave it alone, which is often while your screen is locked. GNOME switches the panel's tray off under the lock screen, and a version that started then never showed its icon. The app now waits until you are back before restarting by itself, so its icon comes back with it."}],"3.32.1":[{title:"🔔 The tray icon comes back on Linux",body:"On Linux the app could lose its icon in the panel, after it updated itself or when the panel restarted, and stay without it until it was quit. It now notices within a minute and restarts by itself the next time you are away from its window, the way it installs an update. It does this at most once every six hours, and not again if a restart did not help."},{title:"🔕 A window you closed stays closed after a self-update",body:"When the app restarted by itself to install an update, it opened its window again even if you had closed it, and while that window was open the deck held back its notifications. A window you closed now stays closed."},{title:"🪟 No empty icon when ccdeck is already open",body:'Opening ccdeck again while it was running flashed an empty "…" icon in the Linux panel before bringing the window forward. It now only brings the window forward.'}],"3.32.0":[{title:"🗺️ A map of your network",body:"A new button on the Local network row, and in its view's header, opens a map of every deck around this one. This deck is at the centre and the paired decks that are on stand around it. Further out are the quiet ones, the machines nearby and any deck asking to pair. Wires are solid on your local network and dashed over Tailscale. Pointing at a deck says how it is reached, what it runs and which logins the two share, and pressing it opens that deck's own dialog."}],"3.31.0":[{title:"📊 Account capacity",body:"A gauge button in the accounts panel's header opens Account capacity: how many of your Claude accounts are ready now, what the 5-hour and 7-day windows have left across all of them, and a row for each account with its use, its state (Ready, Limited, Exhausted or Stale) and when it was last read. Each window also says whose reset comes next."},{title:"🚦 Claude and Codex incidents",body:"When Anthropic's or OpenAI's status page reports an incident on something your sessions use, the deck says so in the topbar, the Usage panel and the tray, and every mark links to the status page. A provider with nothing wrong draws nothing."},{title:"↕️ Order your other accounts",body:"The Other accounts row can sort the list by slot, by how full a window is, or by most room, and open every account at once. Both stay as you left them after a reload."},{title:"🔐 A settings folder left by sudo can be given back",body:'On a Mac, running ccdeck once with sudo left its settings folder owned by another user, and every settings change was refused, sharing an account included. The message now offers "give it back": macOS asks for your password, the folder is yours again, and the deck reads its settings back without a restart.'}],"3.30.0":[{title:"🧮 Token counts and costs are no longer doubled",body:"Claude Code writes a reply that has thinking, text and tool calls as several transcript lines, each carrying the whole request's usage. The deck added up every line, so a session's tokens and cost on its card came out close to twice what it was billed, and the context panel counted each part of a reply as its own message. Each request is now counted once. Expect the totals on your cards to come down."},{title:"⏳ Claude's saved limit resets on the Usage panel",body:`When your Claude account has free limit resets to spend ("Reset for free" in Claude's Settings → Usage), the Claude card now says how many there are and when the first one expires, the way the Codex card already did. The deck only reports them; you spend them in Claude's own settings.`},{title:"🔑 LAN invites need the other deck updated",body:`An invite's code is now a long random secret instead of six digits, so nobody else on the network can work it out and pair in your place, and a wrong code is refused by name. An invite made on this version can only be joined from a deck on this version or later: an older deck answers "That is not an invite". Update that deck, or make the invite on the older one and join it here.`},{title:"🔕 AGENTS_DECK_NO_NOTIFY keeps Browser Watch quiet too",body:"A deck started with AGENTS_DECK_NO_NOTIFY=1 still raised a desktop notification for every new Browser Watch finding. It no longer does. The finding is still in the Browser Watch panel and its log, which says why no notification came."},{title:"🛠️ Smaller fixes",body:'Delete removes the card you just clicked. A LAN address you typed stays in the list when a round cannot reach it, and the status line under the LAN switch now agrees with the rows below it. In the desktop app, a dismissed "update is ready" notice stays dismissed after you answer the first-launch question. Sizes read the same in every panel ("1.1 KB"). Faded text stays readable, a keyboard can see the scrollbar, and numbers use a monospaced font on Windows and Linux as well.'}],"3.29.11":[{title:"💲 Claude Sonnet 5.5 has a price",body:`Sessions on Claude Sonnet 5.5 showed "not priced" on the board, and the Projects report could only show a minimum for them. They are now priced at Anthropic's published rate, the same as Sonnet 5: $2 per million input tokens and $10 per million output tokens.`}],"3.29.10":[{title:"💲 Claude Opus 5.5 has a price",body:`Sessions on Claude Opus 5.5 showed "not priced" on the board, and the Projects report counted them as costing nothing, so its totals read far too low. They are now priced at Anthropic's published rate. If a model still has no price, Projects shows its total as a minimum, like $11.19+, and names the model, instead of a total that looks complete.`}],"3.29.8":[{title:"🔁 Removed cards come back when their agent works again",body:"Remove from board is for finished work. If the agent behind a card you removed starts a tool call, gets a new prompt or starts a subagent, the card returns on its own, together with the card it hangs from, and it stays back after a reload. Cards whose agents stay idle stay removed."}],"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.
|
|
109
|
+
What did you expect to happen?`},{value:"idea",label:"Idea",question:"What would make ccdeck better?",placeholder:"It would be useful if…"},{value:"other",label:"Other",question:"What would you like to tell us?",placeholder:"Write anything…"}];function YL(e){return jb.find(t=>t.value===e)??jb[0]}const Sb=3,ux=120,Wse=1e4,Hse=200,Vse="Write something first.";function ZR(e){return e.trim()!==""}function Gse(e){var o;const t=e.trim();if(t==="")return"";const n=JR(t.split(/\r?\n/,1)[0]),r=((o=/^(.+?[.!?])(?=\s|$)/.exec(n))==null?void 0:o[1])??n,s=dx(r).length>=Sb?dx(r):dx(n);return Yse(s.length>=Sb?s:JR(t))}function Kse(e,t){const n=Gse(t);return n.length>=Sb?n:`${YL(e).label}: ${n}`}function JR(e){return e.replace(/\s+/g," ").trim()}function dx(e){return/[^.]\.$/.test(e)?e.slice(0,-1):e}function Yse(e){if(e.length<=ux)return e;const t=e.slice(0,ux-1),n=t.lastIndexOf(" ");return`${(n>=ux/2?t.slice(0,n):t).replace(/[\uD800-\uDBFF]$/,"").replace(/[\s,;:.\-–—]+$/,"")}…`}function Xse({kind:e,body:t,contact:n}){const r={kind:e,title:Kse(e,t),body:t.trim()};return n.trim()!==""&&(r.contact=n.trim()),r}function Zse(e){const t=e;return(t==null?void 0:t.ok)!==!0||typeof t.appVersion!="string"||typeof t.platform!="string"||t.appVersion===""||t.platform===""?null:{appVersion:t.appVersion,platform:t.platform}}const Jse={darwin:"macOS",win32:"Windows",linux:"Linux"};function Qse(e){const t=e.indexOf("-"),n=t===-1?e:e.slice(0,t),r=t===-1?"":e.slice(t+1),s=Jse[n]??n;return r?`${s} · ${r}`:s}function eae(e){return e?`ccdeck ${e.appVersion} · ${Qse(e.platform)}`:null}const tae="sent with it",nae="Your ccdeck version and system are sent with it.",rae="Add details",sae="How to reach you",aae="Email or GitHub @name",oae="Only if you would like an answer.",iae=["It all goes to the people who make ccdeck, with the version and system below.","Nothing becomes public by being sent. They may open a public GitHub issue from it, choosing its title and text; your contact and screenshots are never put on one."];function lae(e){return e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&!e.altKey&&!e.shiftKey&&!e.isComposing}function XL(e){return e.key==="Enter"&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&!e.shiftKey&&!e.isComposing}function cae(e){return/mac|iphone|ipad/i.test(e)?["⌘","Enter"]:["Ctrl","Enter"]}function uae(e){return[...e].length===1}const ZL="Thanks — feedback sent.";function QR(e,t,n){if(t==="vetoed")return"This deck was started with AGENTS_DECK_NO_INSTALL=1, which keeps it off the network, so nothing was sent.";if(e===429||t==="too_many")return"Too much feedback from this network in the last hour. Try again later; your text is still here.";if(e===413||t==="too_large")return"The images are too large to send together. Remove one and send again; your text is still here.";const r=n==null?void 0:n.images;return e===400&&Array.isArray(r)&&typeof r[0]=="string"?`The server did not accept an image. ${r[0]} Remove it and send again; your text is still here.`:e===400?"The server did not accept the message. It is still here; check it and send again.":"ccdeck's server could not be reached. Nothing was sent; your text is still here, so try again in a moment."}function dae(e){return e==="sending"?"Sending…":e==="sent"?ZL:""}const eM=1400,hae=160;function fae({kind:e,onChange:t}){return a.jsxs("fieldset",{className:"fb-kinds",children:[a.jsx("legend",{className:"vis-hidden",children:"Kind of feedback"}),jb.map(n=>a.jsxs("label",{className:"fb-kind",children:[a.jsx("input",{type:"radio",name:"feedback-kind",value:n.value,checked:e===n.value,onChange:()=>t(n.value),onKeyDown:r=>{XL(r.nativeEvent)&&r.preventDefault()}}),n.label]},n.value))]})}const JL="fb-details";function pae({open:e,onToggle:t}){return a.jsxs("button",{type:"button",className:"fb-tool fb-more","aria-expanded":e,"aria-controls":JL,onClick:t,children:[rae,a.jsx("svg",{className:"fb-chev",width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,focusable:"false",children:a.jsx("path",{d:"M2.5 3.75 5 6.25l2.5-2.5"})})]})}function mae({open:e,contact:t,onContact:n}){const r=y.useId();return a.jsx("div",{id:JL,className:"fb-details","data-open":e||void 0,children:a.jsx("div",{className:"fb-details-clip",children:a.jsxs("div",{className:"fb-details-body",children:[a.jsxs("div",{className:"fb-field",children:[a.jsxs("label",{className:"fb-field-label",htmlFor:"fb-contact",children:[sae,a.jsx("span",{className:"fb-optional",children:"optional"})]}),a.jsx("input",{id:"fb-contact",className:"ap-manage-input",type:"text",value:t,maxLength:Hse,autoComplete:"email",placeholder:aae,"aria-describedby":r,onChange:s=>n(s.target.value),onKeyDown:s=>{XL(s.nativeEvent)&&s.preventDefault()}}),a.jsx("p",{id:r,className:"fb-hint",children:oae})]}),a.jsx("div",{className:"fb-where",children:iae.map(s=>a.jsx("p",{children:s},s))})]})})})}const ti=3,gae=5*1024*1024,yae=12*1024*1024,_b=8192,wae=64*1024,vae=256*1024,xae=.92,bae=640,QL=.9,kae=.85,Nae=6,jae=512*1024,qd={png:"image/png",jpeg:"image/jpeg"},Sae={png:"png",jpeg:"jpg"},_ae=[137,80,78,71,13,10,26,10],Eae=[255,216,255];function eP(e){const t=n=>e.length>=n.length&&n.every((r,s)=>e[s]===r);return t(_ae)?"png":t(Eae)?"jpeg":null}function Tae(e){const t=eP(e);return t==="png"?Cae(e):t==="jpeg"?Rae(e):null}function Cae(e){const t=[73,72,68,82];if(e.length<24||!t.every((r,s)=>e[12+s]===r))return null;const n=new DataView(e.buffer,e.byteOffset,e.byteLength);return{width:n.getUint32(16),height:n.getUint32(20)}}function Aae(e){return e>=192&&e<=207&&e!==196&&e!==200&&e!==204}function Rae(e){let t=2;for(;t<e.length;){if(e[t]!==255)return null;for(;t<e.length&&e[t]===255;)t++;const n=e[t++];if(n===void 0||n===217||n===218)return null;if(n===1||n>=208&&n<=215)continue;if(t+2>e.length)return null;const r=e[t]<<8|e[t+1];if(r<2)return null;if(Aae(n))return t+7>e.length?null:{height:e[t+3]<<8|e[t+4],width:e[t+5]<<8|e[t+6]};t+=r}return null}function tM(e,t){return e.bytes>t||e.width>_b||e.height>_b}function Mae(e){return Math.min(gae,yae-wae-e)}function tP(e,t){return{width:Math.max(1,Math.floor(e.width*t)),height:Math.max(1,Math.floor(e.height*t))}}function $ae(e,t){const n=_b/Math.max(e.width,e.height),r=e.bytes>t?Math.sqrt(t/e.bytes)*QL:1;return tP(e,Math.min(1,n,r))}async function Iae(e,t,n){let r=$ae(e,t),s=e.format;for(let o=0;o<Nae;o++){const l=await n(r,s,s==="jpeg"?xae:void 0);if(!l)return null;if(l.size<=t)return{...r,blob:l,format:s};if(s==="png"){s="jpeg";continue}if(r=tP(r,Math.min(kae,Math.sqrt(t/l.size)*QL)),Math.max(r.width,r.height)<bae)return null}return null}async function Oae(e,t,n){const r=new Uint8Array(await e.slice(0,jae).arrayBuffer()),s=eP(r);if(!s)return{ok:!1,problem:"type"};if(t<vae)return{ok:!1,problem:"no_room"};const o=e.type===qd[s]?e:new Blob([e],{type:qd[s]}),l=Tae(r);if(l&&!tM({...l,bytes:e.size},t))return{ok:!0,blob:o,resized:null};const c=await n(e).catch(()=>null);if(!c)return{ok:!1,problem:"unreadable"};try{const d={width:c.width,height:c.height,bytes:e.size,format:s};if(!tM(d,t))return{ok:!0,blob:o,resized:null};const h=await Iae(d,t,c.encoder);return h?{ok:!0,blob:h.blob,resized:{width:h.width,height:h.height}}:{ok:!1,problem:"too_large"}}finally{c.release()}}function Lae(e){return({width:t,height:n},r,s)=>new Promise(o=>{const l=document.createElement("canvas");l.width=t,l.height=n;const c=l.getContext("2d");if(!c)return o(null);r==="jpeg"&&(c.fillStyle="white",c.fillRect(0,0,t,n)),c.imageSmoothingQuality="high",c.drawImage(e,0,0,t,n),l.toBlob(d=>{l.width=0,l.height=0,o(d)},qd[r],s)})}const Pae=async e=>{const t=await createImageBitmap(e);return{width:t.width,height:t.height,encoder:Lae(t),release:()=>t.close()}};function Dae(e){return e.includes("Files")}function Fae({files:e,hasText:t,intoTextField:n}){return e>0&&(!t||!n)}function Bae(e,t){const n=e.indexOf(t);return e[n+1]??e[n-1]??null}function qae(e,t){if(t.length===0)return{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)};const n=new FormData;return n.append("kind",e.kind),n.append("title",e.title),n.append("body",e.body),e.contact!==void 0&&n.append("contact",e.contact),t.forEach((r,s)=>{const o=r.type===qd.jpeg?"jpeg":"png";n.append("images",r,`image-${s+1}.${Sae[o]}`)}),{method:"POST",body:n}}const Uae="Add screenshot",nM="PNG or JPEG, up to three. You can also paste one, or drop it on this dialog.",zae="A screenshot can show emails, costs and paths. Crop out what should not be seen.",rM="Three images at most. Remove one to add another.",Wae="An image could not be attached, so nothing was sent. Check the images and send again; your text is still here.";function Hae(e,t,n){const r=n?`, resized to ${n.width} × ${n.height} to fit`:"";return`Replace image ${e+1}: ${t}${r}`}function Vae(e,t){const n=`${e} of ${ti}`;return t>0?`${n} · ${t} resized to fit`:n}function Gae(e){return`Three images at most, so ${e===1?"one was":`${e} were`} left out.`}function Kae(e){return`“${e.length>40?`${e.slice(0,30)}…${e.slice(-9)}`:e}”`}function Yae(e,t){const n=Kae(t);return e==="type"?`${n} is not a PNG or a JPEG, so it was not added. GIF, WebP and HEIC are not converted; save it as a PNG or a JPEG first.`:e==="no_room"?`There is no room left for ${n}: images go at up to 12 MB in all. Remove one to add it.`:e==="unreadable"?`${n} could not be read as an image.`:`${n} could not be made small enough to send: images go at up to 5 MB each.`}const nP="image/png,image/jpeg";function rP({className:e="fb-glyph"}){return a.jsxs("svg",{className:e,width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,focusable:"false",children:[a.jsx("rect",{x:"1.8",y:"2.4",width:"10.4",height:"9.2",rx:"1.6"}),a.jsx("circle",{cx:"5",cy:"5.6",r:"1"}),a.jsx("path",{d:"M2.4 10.4 5.5 7.6l2.1 1.8 1.5-1.3 2.5 2.2"})]})}function Xae({images:e,buttonRef:t}){const n=y.useRef(null),r=e.shots.length>=ti;return a.jsxs(a.Fragment,{children:[a.jsxs("button",{ref:t,type:"button",className:"fb-tool",title:nM,"aria-describedby":"fb-attach-hint",onClick:()=>{var s;return r?e.sayFull():(s=n.current)==null?void 0:s.click()},children:[a.jsx(rP,{}),Uae]}),a.jsx("span",{id:"fb-attach-hint",hidden:!0,children:nM}),a.jsx("input",{ref:n,type:"file",accept:nP,multiple:!0,hidden:!0,onChange:s=>{e.add(Array.from(s.target.files??[])),s.target.value=""}})]})}function Zae({images:e,addRef:t}){const n=y.useRef(new Map),r=y.useRef(null),s=y.useRef(null),o=y.useRef(null),[l,c]=y.useState(null),{shots:d}=e,h=Vae(d.length,d.filter(g=>g.resized).length);y.useLayoutEffect(()=>{var g;l!==null&&((g=l==="add"?t.current:n.current.get(l))==null||g.focus(),c(null))},[l,t]),y.useEffect(()=>{var g;e.problem&&((g=r.current)==null||g.scrollIntoView({block:"nearest"}))},[e.problem,e.problemId]);function f(g){c(Bae(d.map(v=>v.id),g)??"add"),e.remove(g)}function p(g){var v;o.current=g,(v=s.current)==null||v.click()}return a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"vis-hidden",role:"status",children:e.announcement}),a.jsx("input",{ref:s,type:"file",accept:nP,hidden:!0,onChange:g=>{const v=o.current;v!==null&&e.replace(v,Array.from(g.target.files??[])),o.current=null,g.target.value=""}}),d.length>0&&a.jsxs("div",{className:"fb-shots",children:[a.jsxs("div",{className:"fb-shots-row",children:[a.jsx("ul",{className:"fb-shots-list",children:d.map((g,v)=>a.jsxs("li",{className:"fb-shot","data-fitting":g.blob?void 0:!0,children:[a.jsxs("button",{type:"button",className:"fb-shot-pick","aria-label":Hae(v,g.name,g.resized),onClick:()=>p(g.id),children:[a.jsx("img",{className:"fb-shot-img",src:g.url,alt:""}),g.blob?a.jsx("span",{className:"fb-shot-cue","aria-hidden":"true",children:"Replace"}):a.jsx("span",{className:"fb-shot-busy","aria-hidden":"true",children:"Resizing…"})]}),a.jsx("button",{ref:N=>{N?n.current.set(g.id,N):n.current.delete(g.id)},type:"button",className:"glyph-btn fb-shot-remove","aria-label":`Remove image ${v+1}`,title:`Remove image ${v+1}`,onClick:()=>f(g.id),children:a.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round","aria-hidden":!0,focusable:"false",children:a.jsx("path",{d:"M2.5 2.5 7.5 7.5M7.5 2.5 2.5 7.5"})})})]},g.id))}),a.jsx("span",{className:"fb-shots-count",children:h})]}),a.jsx("p",{className:"fb-hint",children:zae})]}),e.problem&&a.jsx("p",{ref:r,className:"fb-error",role:"alert",children:e.problem},e.problemId)]})}function Jae(e,t,n){return n?e.map(r=>r.id===t.id?t:r):[...e,t]}function Qae(e,t,n){return n?e.map(r=>r.id===t?n:r):e.filter(r=>r.id!==t)}function eoe(){const[e,t]=y.useState([]),[n,r]=y.useState({problem:"",id:0}),s=y.useRef(0),o=y.useCallback(C=>{C&&s.current++,r(A=>C?{problem:C,id:A.id+1}:A.problem?{problem:"",id:A.id}:A)},[]),[l,c]=y.useState(""),d=y.useRef([]),h=y.useRef(null),f=y.useRef(1),p=y.useRef(!0),g=y.useCallback(C=>{d.current=C(d.current),t(d.current)},[]);y.useEffect(()=>(p.current=!0,()=>{p.current=!1;for(const C of d.current)URL.revokeObjectURL(C.url)}),[]);const v=y.useCallback(async(C,A)=>{const U=d.current.reduce((P,G)=>{var K;return P+(G.id===(A==null?void 0:A.id)?0:((K=G.blob)==null?void 0:K.size)??0)},0),L=(A==null?void 0:A.id)??f.current++,F=URL.createObjectURL(C),O={id:L,name:C.name||"image",url:F,blob:null,resized:null};let I=!1;const B=()=>{I||(I=!0,g(P=>Jae(P,O,A!==void 0)))},M=await Oae(C,Mae(U),async P=>(B(),Pae(P))).catch(()=>({ok:!1,problem:"unreadable"})),$=d.current.some(P=>P.id===L);return!p.current||!$&&(I||A)?(URL.revokeObjectURL(F),A&&URL.revokeObjectURL(A.url),""):M.ok?(B(),A&&URL.revokeObjectURL(A.url),g(P=>P.map(G=>G.id===L?{...G,blob:M.blob,resized:M.resized}:G)),""):(URL.revokeObjectURL(F),I&&g(P=>Qae(P,L,A)),Yae(M.problem,C.name||"image"))},[g]),N=y.useCallback(async C=>{o("");const A=[];let U=0,L=0;for(const O of C){if(!p.current)return;if(d.current.length>=ti){U++;continue}const I=d.current.length,B=await v(O);B&&A.push(B),d.current.length>I&&L++}if(!p.current)return;U>0&&A.push(L===0&&A.length===0?rM:Gae(U)),o(A.join(" "));const F=d.current.length;L>0&&c(`${L===1?"Image":`${L} images`} added, ${F} of ${ti}.`)},[v,o]),k=y.useCallback(async(C,A)=>{o("");const U=d.current.find(O=>O.id===C);if(!U)return N([A]);const L=await v(A,U);if(!p.current)return;o(L);const F=d.current.findIndex(O=>O.id===C);!L&&F!==-1&&c(`Image ${F+1} replaced, ${d.current.length} of ${ti}.`)},[N,v,o]),x=y.useCallback(C=>{h.current=(h.current??Promise.resolve()).then(C).catch(()=>{})},[]),j=y.useCallback(C=>{C.length>0&&x(()=>N(C))},[N,x]),b=y.useCallback((C,A)=>{const U=A[0];U&&x(()=>k(C,U))},[x,k]),_=y.useCallback(C=>{const A=d.current.find(U=>U.id===C);A&&(URL.revokeObjectURL(A.url),g(U=>U.filter(L=>L.id!==C)),o(""),c(`Image removed, ${d.current.length} of ${ti}.`))},[g,o]),E=y.useCallback(()=>o(rM),[o]),R=y.useCallback(async()=>{const C=s.current;return await h.current,s.current!==C?null:d.current.flatMap(A=>A.blob?[A.blob]:[])},[]);return{shots:e,problem:n.problem,problemId:n.id,announcement:l,add:j,replace:b,remove:_,sayFull:E,ready:R}}function toe(){const[e,t]=y.useState(null);return y.useEffect(()=>{let n=!0;return fetch("/api/feedback").then(r=>r.ok?r.json():null).then(r=>{n&&t(Zse(r))}).catch(()=>{}),()=>{n=!1}},[]),e}function noe(e){const[t,n]=y.useState({state:"idle"}),r=y.useRef(!1),s=y.useRef(null);y.useEffect(()=>()=>{var l;return(l=s.current)==null?void 0:l.abort()},[]);async function o(l){if(!lr(r.current))return;r.current=!0;const{signal:c}=s.current=new AbortController;n({state:"sending"});try{const d=await e.ready();if(c.aborted)return;if(!d){n({state:"failed",message:Wae});return}const h=await fetch("/api/feedback",{...qae(Xse(l),d),signal:c}),f=await h.json().catch(()=>null);n(h.ok&&(f!=null&&f.ok)?{state:"sent"}:{state:"failed",message:QR(h.status,f==null?void 0:f.reason,f==null?void 0:f.errors)})}catch{c.aborted||n({state:"failed",message:QR(0,null)})}finally{r.current=!1}}return{outcome:t,sending:t.state==="sending",send:o}}function roe(e,t){const[n,r]=y.useState(!1),s=y.useRef(t);return s.current=t,y.useEffect(()=>{if(!e)return;const o=window.setTimeout(()=>r(!0),eM),l=window.setTimeout(()=>s.current(),eM+hae);return()=>{window.clearTimeout(o),window.clearTimeout(l)}},[e]),n}function soe(){var t;return typeof navigator>"u"?"":((t=navigator.userAgentData)==null?void 0:t.platform)||navigator.platform||""}function sP({onClose:e,initialKind:t,initialBody:n}){const r=y.useRef(null),s=y.useRef(null),o=y.useRef(null),l=y.useRef(null),c=y.useRef(null),d=y.useRef(null),h=y.useRef(null),f=y.useRef(0),p=ut(e,{focusRef:r}),g=gt(e),[v,N]=y.useState(t??"bug"),[k,x]=y.useState(n??""),[j,b]=y.useState(""),[_,E]=y.useState(!1),[R,C]=y.useState(!1),[A,U]=y.useState(!1),L=eoe(),F=eae(toe()),{outcome:O,sending:I,send:B}=noe(L),M=O.state==="sent",$=roe(M,e),P=YL(v),G=R&&!ZR(k),[K,q]=cae(soe());y.useEffect(()=>{var ke,ae;const se=l.current;if(!se)return;const pe=se.contains(document.activeElement)||Tn(((ke=document.activeElement)==null?void 0:ke.tagName)??null);se.inert=M,M&&pe&&((ae=s.current)==null||ae.focus())},[M]),y.useEffect(()=>{var ae,fe;const se=c.current;if(!se)return;if(I){const me=document.activeElement;h.current=me&&se.contains(me)?me:null,se.inert=!0,h.current&&((ae=d.current)==null||ae.focus());return}se.inert=!1;const pe=h.current;h.current=null;const ke=document.activeElement===d.current||Tn(((fe=document.activeElement)==null?void 0:fe.tagName)??null);!M&&pe&&ke&&pe.focus()},[I,M]);function H(se){var pe;if(se.preventDefault(),!ZR(k)){C(!0),(pe=r.current)==null||pe.focus();return}B({kind:v,body:k,contact:j})}const D=!M&&!I,W=se=>Dae(Array.from(se.dataTransfer.types));function J(se){!W(se)||!D||(se.preventDefault(),f.current++,U(!0))}function V(se){W(se)&&(se.preventDefault(),se.dataTransfer.dropEffect=D?"copy":"none")}function X(se){W(se)&&(f.current=Math.max(0,f.current-1),f.current===0&&U(!1))}function Y(se){W(se)&&(se.preventDefault(),f.current=0,U(!1),D&&L.add(Array.from(se.dataTransfer.files)))}function Z(se){se.target!==se.currentTarget||!W(se)||(se.preventDefault(),se.dataTransfer.dropEffect="none")}function ee(se){W(se)&&se.preventDefault()}function ne(se){if(!D)return;const pe=Array.from(se.clipboardData.files),ke=se.target,ae=ke instanceof HTMLTextAreaElement||ke instanceof HTMLInputElement,fe=Array.from(se.clipboardData.types).includes("text/plain");Fae({files:pe.length,hasText:fe,intoTextField:ae})&&(se.preventDefault(),L.add(pe))}return a.jsx("div",{className:"modal-backdrop",...g,role:"presentation",onDragOver:Z,onDrop:ee,"data-leaving":$||void 0,children:a.jsxs("div",{ref:p,className:"modal feedback-dialog",onClick:se=>se.stopPropagation(),onDragEnter:J,onDragOver:V,onDragLeave:X,onDrop:Y,onPaste:ne,role:"dialog","aria-modal":"true","aria-labelledby":"feedback-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"feedback-title",className:"modal-tool-name",children:"Send feedback"})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{ref:s,type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsx("p",{className:"vis-hidden",role:"status",children:dae(O.state)}),a.jsxs("div",{className:"fb-stage",children:[a.jsxs("form",{ref:l,className:"fb-form",onSubmit:H,onKeyDown:se=>{lae(se.nativeEvent)&&(se.preventDefault(),se.currentTarget.requestSubmit())},noValidate:!0,children:[a.jsxs("section",{ref:c,className:"modal-body fb-body",children:[a.jsx(fae,{kind:v,onChange:N}),a.jsxs("div",{className:"fb-compose",children:[a.jsx("label",{className:"fb-label",htmlFor:"fb-body",children:P.question}),a.jsx("textarea",{ref:r,id:"fb-body",className:"ap-manage-input fb-message",value:k,maxLength:Wse,rows:5,placeholder:P.placeholder,onChange:se=>x(se.target.value),"aria-invalid":G||void 0,"aria-describedby":G?"fb-body-error":void 0,required:!0}),G&&a.jsx("p",{id:"fb-body-error",className:"fb-error",children:Vse}),a.jsx(Zae,{images:L,addRef:o}),a.jsxs("div",{className:"fb-tools",children:[a.jsx(Xae,{images:L,buttonRef:o}),a.jsx(pae,{open:_,onToggle:()=>E(se=>!se)})]}),a.jsx(mae,{open:_,contact:j,onContact:b})]}),a.jsx("p",{className:"fb-facts",children:F?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"fb-facts-value",children:F})," — ",tae]}):nae}),O.state==="failed"&&a.jsx("p",{className:"fb-error",role:"alert",children:O.message})]}),a.jsxs("div",{className:"fb-foot",children:[a.jsxs("span",{className:"fb-shortcut","aria-hidden":"true",children:[a.jsx("kbd",{"data-symbol":uae(K)||void 0,children:K}),a.jsx("kbd",{children:q})," to send"]}),a.jsx("button",{type:"button",className:"btn",onClick:e,children:"Cancel"}),a.jsx("button",{ref:d,type:"submit",className:"btn primary fb-send","aria-keyshortcuts":"Meta+Enter Control+Enter",...Dr(I),children:a.jsxs("span",{className:"fb-send-label",children:[a.jsx("span",{className:"fb-send-idle",children:"Send feedback"}),a.jsx("span",{className:"fb-send-busy",children:"Sending…"})]})})]})]}),M&&a.jsxs("div",{className:"fb-done",children:[a.jsx(Td,{}),a.jsx("p",{className:"fb-done-line",children:ZL})]})]}),a.jsx("div",{className:"fb-drop","aria-hidden":"true","data-active":A||void 0,children:a.jsxs("div",{className:"fb-drop-frame",children:[a.jsx(rP,{className:"fb-drop-glyph"}),a.jsx("p",{className:"fb-drop-title",children:"Drop to attach"}),a.jsx("p",{className:"fb-drop-note",children:"PNG or JPEG, up to three"})]})})]})})}const aoe="Press Esc first if a key does nothing.",ooe=[{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 — the session list (L) 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 ioe({onClose:e,onTour:t}){const n=ut(e),r=gt(e);return a.jsx("div",{className:"modal-backdrop",...r,role:"presentation",children:a.jsxs("div",{ref:n,className:"modal key-help",onClick:s=>s.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[t&&a.jsxs("div",{className:"guide-door",children:[a.jsx("span",{children:"Eight pictures of what the deck shows."}),a.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),a.jsx("div",{className:"shortcuts",children:ooe.map(s=>a.jsxs(y.Fragment,{children:[a.jsx("h3",{className:"kh-group",children:s.title}),s.rows.map(o=>a.jsxs("div",{className:"sc",children:[a.jsx("kbd",{children:o.cap}),a.jsx("span",{children:o.action})]},`${s.title}:${o.cap}:${o.action}`))]},s.title))}),a.jsx("p",{className:"kh-foot",children:aoe})]})]})})}function aP(e,t){return y.lazy(()=>e().catch(n=>(console.warn(`ccdeck could not load ${t}`,n),{default:({onClose:r})=>a.jsx(loe,{name:t,onClose:r})})))}function loe({name:e,onClose:t}){const n=y.useRef(null),r=ut(t,{focusRef:n}),s=gt(t);return a.jsx("div",{className:"modal-backdrop",...s,role:"presentation",children:a.jsxs("div",{ref:r,className:"modal dialog-missing",onClick:o=>o.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"dialog-missing-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"dialog-missing-title",className:"modal-tool-name",children:e})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[a.jsxs("p",{className:"dm-note",children:[e," did not load. The deck has most likely been updated since this tab opened, and a reload picks up the new version."]}),a.jsxs("div",{className:"dm-actions",children:[a.jsx("button",{type:"button",className:"btn",onClick:t,children:"Close"}),a.jsx("button",{type:"button",ref:n,className:"btn primary",onClick:()=>window.location.reload(),children:"Reload"})]})]})]})})}function coe(e,t){return`${e}#${t}`}function uoe(e,{lan:t,now:n,closed:r}){if(t===void 0)return[];const s=[];for(const o of e??[]){const l=o.reauth;if(!l||l.dismissed||o.origin!=="ccdeck_signin")continue;const c=coe(l.key,l.since);if(r.has(c)||XG(l.key,o.email,t,n))continue;const d=o.email??"";s.push({id:c,key:l.key,since:l.since,num:o.num,email:d,name:d||o.alias||`Account ${o.num}`,alias:d&&o.alias?o.alias:null})}return s}function doe(e,t){const n=String((t==null?void 0:t.email)??"").trim().toLowerCase();return n?e.filter(r=>r.email.toLowerCase()===n&&((t==null?void 0:t.num)==null||String(r.num)===String(t.num))).map(r=>r.id):[]}function oP({rows:e,ours:t,dialogs:n}){return e===0?!1:t||n===0}function hoe(e){return e===1?"Account needs your attention":"Accounts need your attention"}function foe(e){return`${e===1?"One Claude account needs":`${e} Claude accounts need`} you to sign in again.`}const poe="Login expired",moe="Until then the deck cannot read its usage or switch to it. Signing in again brings it back — it keeps its slot, its alias and its history.",goe="The account stays marked in the Accounts panel. This will not ask again until it has worked and stopped again.";function yoe(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,o)=>(s.at??0)-(o.at??0));return{request:r[0],waiting:r.length-1}}function woe({request:e,waiting:t,busy:n,now:r,onAccept:s,onDecline:o,onLater:l}){const c=y.useRef(null),d=ut(l,{focusRef:c}),h=gt(l),f=ia(n,"accept"),p=ia(n,"dismiss");return a.jsx("div",{className:"modal-backdrop",...h,role:"presentation",children:a.jsxs("div",{ref:d,className:"modal lan-ask",onClick:g=>g.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-ask-title","aria-describedby":"lan-ask-who",children:[a.jsxs("header",{className:"modal-head",children:[a.jsxs("div",{className:"modal-title",children:[a.jsx("i",{className:"ap-pulse","aria-hidden":!0}),a.jsx("span",{id:"lan-ask-title",className:"modal-tool-name",children:"A deck wants to pair"})]}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:l,"aria-label":"Answer later (Esc)",title:"Answer later (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[a.jsxs("p",{id:"lan-ask-who",className:"lan-ask-who",children:[a.jsx("strong",{className:"lan-ask-name",children:e.name})," at ",a.jsx("code",{className:"ap-lan-code",children:e.addr})," · asked ",j0(e.at,r)]}),a.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."}),a.jsxs("p",{className:"lan-ask-fp",children:["Its fingerprint is ",a.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&&a.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.`}),a.jsxs("div",{className:"lan-ask-acts",children:[a.jsx("button",{type:"button",ref:c,className:"btn",disabled:p.disabled,"aria-busy":p.busy,onClick:o,title:"Nothing is shared. If that deck asks again, this comes back.",children:n==="dismiss"?"declining…":"Decline"}),a.jsx("button",{type:"button",className:"btn primary",disabled:f.disabled,"aria-busy":f.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"})]})]})]})})}function voe(e){const t=y.useRef(!1),n=xoe(e),r=oP({rows:n?1:0,ours:t.current,dialogs:ds.dialogDepth()});return t.current=r,r?n:null}function xoe({lanPending:e,lanDeferred:t,lanBusy:n,answerLanPair:r,deferLanPair:s}){const{request:o,waiting:l}=yoe(e,t.current);return o?a.jsx(woe,{request:o,waiting:l,busy:n,now:Date.now(),onAccept:()=>void r("accept",o.fp),onDecline:()=>void r("dismiss",o.fp),onLater:()=>s(o.fp)},o.fp):null}function boe({rows:e,onSignIn:t,onLater:n,firstRef:r}){const s=e.length===1?e[0]:null;return a.jsxs("section",{className:"modal-body",children:[s?a.jsxs(a.Fragment,{children:[a.jsxs("p",{id:"reauth-lead",className:"reauth-lead",children:["The Claude login for ",a.jsx("strong",{className:"reauth-name",children:s.name}),s.alias?a.jsxs("span",{className:"reauth-alias",children:[" (",s.alias,")"]}):null," ","has expired and needs a new sign","‑","in."]}),a.jsx("p",{className:"reauth-note",children:moe})]}):a.jsxs(a.Fragment,{children:[a.jsx("p",{id:"reauth-lead",className:"reauth-lead",children:foe(e.length)}),a.jsx("ul",{className:"reauth-list",children:e.map((o,l)=>a.jsxs("li",{className:"reauth-row",children:[a.jsxs("span",{className:"reauth-who",title:o.alias?`${o.alias} — ${o.name}`:o.name,children:[o.name,o.alias?a.jsxs("span",{className:"reauth-alias",children:[" ",o.alias]}):null]}),a.jsx("span",{className:"reauth-what",children:poe}),a.jsx("button",{type:"button",className:"btn",ref:l===0?r:void 0,"aria-label":`Sign in again as ${o.name}`,onClick:()=>t(o),children:"Sign in again"})]},o.id))}),a.jsx("p",{className:"reauth-note",children:"Each keeps its slot, its alias and its history."})]}),a.jsxs("div",{className:"reauth-acts",children:[a.jsx("button",{type:"button",className:"btn",title:goe,onClick:n,children:"Not now"}),s&&a.jsx("button",{type:"button",className:"btn primary",ref:r,onClick:()=>t(s),children:"Sign in again"})]})]})}function koe({rows:e,onSignIn:t,onLater:n}){const r=y.useRef(null),s=ut(n,{focusRef:r}),o=gt(n);return a.jsx("div",{className:"modal-backdrop",...o,role:"presentation",children:a.jsxs("div",{ref:s,className:"modal reauth-ask",onClick:l=>l.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"reauth-title","aria-describedby":"reauth-lead",children:[a.jsxs("header",{className:"modal-head",children:[a.jsx("div",{className:"modal-title",children:a.jsx("span",{id:"reauth-title",className:"modal-tool-name",children:hoe(e.length)})}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Not now (Esc)",title:"Not now (Esc)",children:"×"})})]}),a.jsx(boe,{rows:e,onSignIn:t,onLater:n,firstRef:r})]})})}function Noe({rows:e,signingIn:t,signIn:n,signedIn:r,refresh:s,closeSignIn:o,later:l,pairing:c=!1}){const d=y.useRef(!1),h=ds.dialogDepth()+(c?1:0),f=t!=null||oP({rows:e.length,ours:d.current,dialogs:h});return d.current=f,t?a.jsx(OI,{email:t.email||null,onClose:o,onChanged:s,onSignedIn:r}):f?a.jsx(koe,{rows:e,onSignIn:n,onLater:l},e.length===1?"one":"many"):null}const joe={"//":["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.4","3.29.6","3.29.7","3.29.9","3.33.1","3.35.0","3.35.1","3.36.0","3.36.1","3.36.4","3.36.5","3.36.6","3.36.7","3.36.8","3.36.9","3.37.0","3.38.0","3.38.1"],"3.37.1":[{title:"🔁 Expired logins repair from your other machines",body:"When a login stops working on this machine and a machine you paired with still has it working and ticked, Local network now copies it back on the next round, whether or not the account is ticked here. Before, it stayed marked expired until the account was ticked here as well, or deleted so that it arrived again. A machine that paired on its own, through Say yes to every deck that asks, still repairs only the accounts ticked here."}],"3.36.3":[{title:"🔑 An expired login asks to be signed in again",body:"When an account you added with + → Sign in stops working, the deck now tells you in one dialog, with every affected account together and Sign in again beside each. That opens the usual sign-in with the address already filled in, and the account keeps its slot, its alias and its history. Not now leaves it marked in the Accounts panel and does not ask again until it has worked and stopped again. A paired deck holding a working copy gets to repair it first, and accounts that came from a share or Local network are never asked about."}],"3.34.1":[{title:"🗂️ The tray menu stays open while you read it",body:"On Linux the menu behind the tray icon could close by itself while agents were working, often before the row you pressed took the click, so it had to be opened and pressed again. It now changes only when something it says has changed, and stays open while you choose."}],"3.34.0":[{title:"🗺️ The network map shows who you are connected to",body:"Paired decks that are on stand closest to this one, and a light runs along their wires. Paired decks that are away come next, in a colour of their own, with how long they have been gone, and machines that are not paired stand outside in grey. Decks reached over Tailscale sit together in their own shaded slice instead of on dashed wires. Pointing at a deck opens its details beside the map: whether it is there, what to do next if anything, its address and what it runs, and every login the two share, the ones that need a look first."},{title:"🔑 A login that expired everywhere says so",body:`When a shared login expired on this deck and every paired deck that is on held an expired copy too, the row said "Login expired" and waited for a repair that could never come. It now says "Login expired on all online decks". Claude retires a login's other copies each time one machine refreshes it, so shared copies expire together: sign in again on any one machine and the others repair from it on their next round.`},{title:"💬 Send feedback from inside the deck",body:'Appearance settings has a "Send feedback…" button: pick what kind it is, write a title and a few lines, and add a way to reach you if you want an answer. It goes to the people who make ccdeck, who may open a public issue from it, never with your contact in it. If it cannot be sent, the form stays filled in and says why.'}],"3.33.0":[{title:"🪝 Hooks you add in Claude Code are no longer removed",body:"Claude Code's hook editor often files a new hook into the same group as the deck's own. Starting the deck, or uninstalling it, then removed the whole group, and your hook went with it without a word. The deck now takes out only its own command and leaves yours where it was, and the same goes for the old finish-sound hook. `ccdeck --uninstall` also stops the decks that are running, so an update in the background cannot put the hooks back."},{title:"🧵 Resumed Codex sessions show up again",body:"A Codex session picked up with `codex resume`, or one that ran for days, could go dark on the canvas and drop out of the 5-hour and 7-day usage, because the deck only looked in the two newest day folders. It now follows those sessions and counts their tokens. Two Codex sessions in the same folder get different id suffixes, and a `bash -lc` call shows the command it runs."},{title:"🤝 A deck paired by the accept switch brings in less",body:'A deck that paired through the automatic accept switch, and not through an invite, now brings in only the logins you have ticked on this deck, and nothing from it is ticked for sharing onward. Its dialog says "paired automatically — pair by invite to take it". Pairing by invite works as before. A typed address is no longer dropped after one failed round, and the sync port stays the same after a rename.'},{title:"⬆️ Desktop updates install when you expect them",body:'On Windows and Linux a downloaded update now installs when you quit. On a Mac, Quit installs it and the app stays closed. The Linux .deb needs an administrator password to install, so it no longer does that by itself: it waits for "Restart to update" and says a password is coming. "Start at login" now works on Linux, and "Restart ccdeck" stops a deck that has hung.'},{title:"🕵️ Browser Watch waits before it acts, and quits only its own browser",body:"A program's visit is now logged and reacted to once its quiet window has closed, about 16 minutes after it, and not on the first poll, so a visit that is withdrawn no longer quits the browser. On Linux the quit reaction ends only the browser that holds the watched profile; other Chrome channels and headless browsers keep running. When it cannot tell which process that is, it does nothing and says so, which includes a Flatpak Brave."},{title:"🧮 Figures that were off are right",body:`Spend by labelled and workflow subagents counts toward a session's tokens and cost. The Projects report prices 1-hour cache writes the way ccusage does, so its dollars match the Usage panel. After a restart the deck rebuilds its whole event history, where it used to rebuild about a third. On Linux the process list shows what each process is using now, not its lifetime average. A count near a boundary reads "1.00M", and a full quota window says "used up".`},{title:"🔑 The Usage panel's reads answer the deck's own page only",body:"The routes behind the Usage panel (/api/quota, /api/ccusage, /api/codex-usage, /api/codex-quota and /api/cswap-auto) now answer the deck's own page, or a client that sends the deck's token. A script that read them with a plain request gets 401 from this version on. The hook, the desktop app and the `ccdeck` command are not affected."},{title:"🛠️ Smaller fixes you may notice",body:"With the canvas paused, an update no longer restarts the server while an agent is working: it waits until no turn is open. `ccdeck --stop -p4317` stops that one deck. A deck started at login can update itself on Homebrew and nvm setups. Dialogs keep keyboard focus after a button goes away, screen readers hear pairing requests by deck name and the machine panel's readings, dim text is readable in both themes, Windows High Contrast shows what is selected, and below 640px the detail panel opens over the canvas."}],"3.32.2":[{title:"🔒 Self-updates wait until your screen is unlocked",body:"On Linux with GNOME, the app installs an update by itself when you leave it alone, which is often while your screen is locked. GNOME switches the panel's tray off under the lock screen, and a version that started then never showed its icon. The app now waits until you are back before restarting by itself, so its icon comes back with it."}],"3.32.1":[{title:"🔔 The tray icon comes back on Linux",body:"On Linux the app could lose its icon in the panel, after it updated itself or when the panel restarted, and stay without it until it was quit. It now notices within a minute and restarts by itself the next time you are away from its window, the way it installs an update. It does this at most once every six hours, and not again if a restart did not help."},{title:"🔕 A window you closed stays closed after a self-update",body:"When the app restarted by itself to install an update, it opened its window again even if you had closed it, and while that window was open the deck held back its notifications. A window you closed now stays closed."},{title:"🪟 No empty icon when ccdeck is already open",body:'Opening ccdeck again while it was running flashed an empty "…" icon in the Linux panel before bringing the window forward. It now only brings the window forward.'}],"3.32.0":[{title:"🗺️ A map of your network",body:"A new button on the Local network row, and in its view's header, opens a map of every deck around this one. This deck is at the centre and the paired decks that are on stand around it. Further out are the quiet ones, the machines nearby and any deck asking to pair. Wires are solid on your local network and dashed over Tailscale. Pointing at a deck says how it is reached, what it runs and which logins the two share, and pressing it opens that deck's own dialog."}],"3.31.0":[{title:"📊 Account capacity",body:"A gauge button in the accounts panel's header opens Account capacity: how many of your Claude accounts are ready now, what the 5-hour and 7-day windows have left across all of them, and a row for each account with its use, its state (Ready, Limited, Exhausted or Stale) and when it was last read. Each window also says whose reset comes next."},{title:"🚦 Claude and Codex incidents",body:"When Anthropic's or OpenAI's status page reports an incident on something your sessions use, the deck says so in the topbar, the Usage panel and the tray, and every mark links to the status page. A provider with nothing wrong draws nothing."},{title:"↕️ Order your other accounts",body:"The Other accounts row can sort the list by slot, by how full a window is, or by most room, and open every account at once. Both stay as you left them after a reload."},{title:"🔐 A settings folder left by sudo can be given back",body:'On a Mac, running ccdeck once with sudo left its settings folder owned by another user, and every settings change was refused, sharing an account included. The message now offers "give it back": macOS asks for your password, the folder is yours again, and the deck reads its settings back without a restart.'}],"3.30.0":[{title:"🧮 Token counts and costs are no longer doubled",body:"Claude Code writes a reply that has thinking, text and tool calls as several transcript lines, each carrying the whole request's usage. The deck added up every line, so a session's tokens and cost on its card came out close to twice what it was billed, and the context panel counted each part of a reply as its own message. Each request is now counted once. Expect the totals on your cards to come down."},{title:"⏳ Claude's saved limit resets on the Usage panel",body:`When your Claude account has free limit resets to spend ("Reset for free" in Claude's Settings → Usage), the Claude card now says how many there are and when the first one expires, the way the Codex card already did. The deck only reports them; you spend them in Claude's own settings.`},{title:"🔑 LAN invites need the other deck updated",body:`An invite's code is now a long random secret instead of six digits, so nobody else on the network can work it out and pair in your place, and a wrong code is refused by name. An invite made on this version can only be joined from a deck on this version or later: an older deck answers "That is not an invite". Update that deck, or make the invite on the older one and join it here.`},{title:"🔕 AGENTS_DECK_NO_NOTIFY keeps Browser Watch quiet too",body:"A deck started with AGENTS_DECK_NO_NOTIFY=1 still raised a desktop notification for every new Browser Watch finding. It no longer does. The finding is still in the Browser Watch panel and its log, which says why no notification came."},{title:"🛠️ Smaller fixes",body:'Delete removes the card you just clicked. A LAN address you typed stays in the list when a round cannot reach it, and the status line under the LAN switch now agrees with the rows below it. In the desktop app, a dismissed "update is ready" notice stays dismissed after you answer the first-launch question. Sizes read the same in every panel ("1.1 KB"). Faded text stays readable, a keyboard can see the scrollbar, and numbers use a monospaced font on Windows and Linux as well.'}],"3.29.11":[{title:"💲 Claude Sonnet 5.5 has a price",body:`Sessions on Claude Sonnet 5.5 showed "not priced" on the board, and the Projects report could only show a minimum for them. They are now priced at Anthropic's published rate, the same as Sonnet 5: $2 per million input tokens and $10 per million output tokens.`}],"3.29.10":[{title:"💲 Claude Opus 5.5 has a price",body:`Sessions on Claude Opus 5.5 showed "not priced" on the board, and the Projects report counted them as costing nothing, so its totals read far too low. They are now priced at Anthropic's published rate. If a model still has no price, Projects shows its total as a minimum, like $11.19+, and names the model, instead of a total that looks complete.`}],"3.29.8":[{title:"🔁 Removed cards come back when their agent works again",body:"Remove from board is for finished work. If the agent behind a card you removed starts a tool call, gets a new prompt or starts a subagent, the card returns on its own, together with the card it hangs from, and it stays back after a reload. Cards whose agents stay idle stay removed."}],"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.
|
|
110
110
|
|
|
111
111
|
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.
|
|
112
112
|
|
|
@@ -300,8 +300,8 @@ It marks that work now. A chart with bars in it means the agent is doing somethi
|
|
|
300
300
|
|
|
301
301
|
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.`}]},tk="agent-dag.releaseNotesSeen";function sM(e){return e.split(/[.\-+]/).map(t=>parseInt(t,10)).map(t=>Number.isNaN(t)?0:t)}function xi(e,t){const n=sM(e),r=sM(t);for(let s=0;s<Math.max(n.length,r.length);s++){const o=(n[s]??0)-(r[s]??0);if(o!==0)return o<0?-1:1}return 0}function bi(e){return typeof e=="string"&&/^\d+\.\d+\.\d+/.test(e)}function Soe(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 _oe(e){if(!e||typeof e!="object")return[];const t=[];for(const[n,r]of Object.entries(e)){if(!bi(n)||!Array.isArray(r))continue;const s=r.filter(Soe);s.length&&t.push({version:n,notes:s})}return t.sort((n,r)=>xi(r.version,n.version))}const aM=_oe(joe);function iP(e,t,n){return e.filter(r=>xi(r.version,n)<=0&&(t===null||xi(r.version,t)>0))}function Eoe(e,t){return e.filter(n=>xi(n.version,t)===0)}function Toe(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 Coe({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 l=n.length===1?"one release":`${n.length} releases`;return`You were last caught up at v${e}. Since then ${l} changed something you would notice. Clicking the version in the topbar brings this back.`}if(r&&bi(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(!bi(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 o=xi(s,t);return o<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.`:o>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 Aoe=new RegExp("^(?:\\p{Extended_Pictographic}|\\p{Emoji_Modifier}|\\p{Regional_Indicator}|[\\u200D\\uFE0F])+(?= \\S)","u");function Roe(e){const t=Aoe.exec(e);return t?{icon:t[0],rest:e.slice(t[0].length)}:{icon:null,rest:e}}function Moe(e){if(!e)return null;let t=null;try{t=e.getItem(tk)}catch{return null}return bi(t)?t:null}function $oe(e){if(!e)return!1;try{return e.getItem(tk),!0}catch{return!1}}function Ioe(e,t){if(!e)return!1;try{return e.setItem(tk,t),!0}catch{return!1}}const lP="agent-dag.tourSeen";function Ooe(e){if(!e)return!1;try{return e.getItem(lP)==="1"}catch{return!1}}function Loe(e){if(!e)return!1;try{return e.setItem(lP,"1"),!0}catch{return!1}}function Poe({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 Doe({stored:e,running:t,notes:n,remembers:r=!0}){if(!bi(t))return{show:[],record:null,reason:"no-version"};if(!bi(e)){if(!r)return{show:[],record:t,reason:"cannot-remember"};const l=Eoe(n,t);return l.length?{show:l,record:t,reason:"welcome"}:{show:[],record:t,reason:"first-run"}}const s=xi(e,t);if(s===0)return{show:[],record:null,reason:"seen"};if(s>0)return{show:[],record:null,reason:"ahead"};const o=iP(n,e,t);return o.length?{show:o,record:t,reason:"new-notes"}:{show:[],record:t,reason:"nothing-new"}}function Foe(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 cP(e,t=!0){const n=[];let r="";const s=()=>{r&&(n.push({kind:"text",text:r}),r="")};let o=0;for(;o<e.length;){if(e[o]==="`"){const l=e.indexOf("`",o+1);if(l>o+1){s(),n.push({kind:"code",text:e.slice(o+1,l)}),o=l+1;continue}}else if(t&&e.startsWith("**",o)){const l=Foe(e,o);if(l>0){s(),n.push({kind:"bold",kids:cP(e.slice(o+2,l),!1)}),o=l+2;continue}}r+=e[o],o+=1}return s(),n}function Boe({entries:e,since:t,running:n,firstRun:r,onClose:s,onTour:o,updateVersion:l,updateBusy:c,onUpdateRestart:d,updateFailure:h,onRestart:f}){const p=ut(s),g=gt(s),v=Toe(e);return a.jsx("div",{className:"modal-backdrop",...g,role:"presentation",children:a.jsxs("div",{ref:p,className:"modal release-notes",onClick:N=>N.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"release-notes-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsxs("div",{className:"modal-title",children:[a.jsx("span",{id:"release-notes-title",className:"modal-tool-name",children:"What's new"}),v&&a.jsx("span",{className:"modal-tool-id",children:v})]}),a.jsx("div",{className:"modal-actions",children:a.jsx("button",{type:"button",className:"glyph-btn",onClick:s,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),a.jsxs("section",{className:"modal-body",children:[(l||h)&&a.jsxs("div",{className:"rn-update",children:[l&&d&&a.jsxs("div",{className:"guide-door",children:[a.jsxs("span",{children:["ccdeck v",l," is downloaded and verified."]}),a.jsx("button",{type:"button",className:"btn",onClick:d,"aria-busy":c||void 0,children:c?"Restarting…":Bd})]}),a.jsx("p",{className:"rn-update-said",role:"status",children:h})]}),a.jsx("p",{className:"modal-note",children:Coe({since:t,running:n,firstRun:r,entries:e})}),o&&!l&&a.jsxs("div",{className:"guide-door",children:[a.jsx("span",{children:"Eight pictures of what the deck shows."}),a.jsx("button",{type:"button",className:"btn",onClick:o,children:"Take the tour"})]}),f&&a.jsxs("div",{className:"guide-door",children:[a.jsx("span",{children:"Restart the deck. Sessions, settings and pairings come back as they were."}),a.jsx("button",{type:"button",className:"btn",onClick:f,children:"Restart"})]}),e.map(N=>a.jsxs("section",{className:"modal-section",children:[a.jsxs("h3",{className:"rn-version",children:["v",N.version]}),a.jsx("ul",{className:"rn-notes",children:N.notes.map((k,x)=>{const{icon:j,rest:b}=Roe(k.title);return a.jsxs("li",{className:"rn-note",children:[a.jsxs("p",{className:"rn-note-title",children:[j&&a.jsx("span",{className:"rn-note-icon",children:j}),b]}),a.jsx("p",{className:"rn-note-body",children:uP(cP(k.body))})]},x)})})]},N.version))]})]})})}function uP(e){return e.map((t,n)=>t.kind==="text"?t.text:t.kind==="code"?a.jsx("code",{className:"rn-code",children:t.text},n):a.jsx("strong",{className:"rn-strong",children:uP(t.kids)},n))}function qoe({state:e,sessionId:t,onClose:n}){const r=y.useMemo(()=>Uoe(e,t),[e,e.revision,t]),s=y.useRef(null),o=ut(n,{focusRef:s}),l=gt(n);return r?a.jsx("div",{className:"modal-backdrop",...l,role:"presentation",children:a.jsxs("div",{ref:o,className:"modal session-summary",onClick:c=>c.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"ss-title",children:[a.jsxs("div",{className:"modal-head",children:[a.jsxs("div",{className:"modal-title",children:[a.jsx("span",{className:"state-pill state-done","aria-hidden":!0,children:"done"}),a.jsx("span",{id:"ss-title",className:"modal-tool-name",title:r.cwd??r.sessionId,children:r.label}),a.jsxs("span",{className:"modal-tool-id",children:["· ",r.sessionId.slice(0,8)]})]}),a.jsxs("div",{className:"modal-actions",children:[a.jsx("span",{className:"modal-dur",title:"Total wall time",children:r.durationLabel}),a.jsx("button",{type:"button",ref:s,className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]})]}),a.jsxs("div",{className:"modal-body",children:[a.jsxs("section",{className:"ss-hero",children:[a.jsxs("div",{className:"ss-hero-left",children:[a.jsx("div",{className:"ss-cost-label",children:X$}),a.jsx("div",{className:"ss-cost",children:qe(r.cost.total)}),r.modelChips.length>0&&a.jsx("div",{className:"ss-models",children:r.modelChips.map(c=>a.jsx("span",{className:"model-chip","data-family":Jd(c),title:c,children:oa(c)},c))})]}),a.jsx("div",{className:"ss-hero-right",children:r.cost.total>0&&a.jsxs(a.Fragment,{children:[a.jsx(u0,{cost:r.cost,size:"lg"}),a.jsxs("div",{className:"ss-cost-legend",children:[a.jsxs("span",{className:"ssl ssl-in",children:["input ",a.jsx("b",{children:qe(r.cost.input)})]}),a.jsxs("span",{className:"ssl ssl-out",children:["output ",a.jsx("b",{children:qe(r.cost.output)})]}),a.jsxs("span",{className:"ssl ssl-cr",children:["cache r ",a.jsx("b",{children:qe(r.cost.cacheRead)})]}),a.jsxs("span",{className:"ssl ssl-cw",children:["cache w ",a.jsx("b",{children:qe(r.cost.cacheWrite)})]})]})]})})]}),a.jsxs("section",{className:"ss-stats",children:[a.jsx(Xo,{label:"agents",value:r.agentCount}),a.jsx(Xo,{label:"subagents",value:r.subagentCount}),a.jsx(Xo,{label:"tool calls",value:r.toolCount}),a.jsx(Xo,{label:"prompts",value:r.promptCount}),a.jsx(Xo,{label:"tokens",value:r.tokensSum.toLocaleString()}),r.errCount>0&&a.jsx(Xo,{label:"errors",value:r.errCount,tone:"err"})]}),r.topTools.length>0&&a.jsxs("section",{className:"modal-section",children:[a.jsx("h4",{children:"Most-used tools"}),a.jsx("div",{className:"ss-top-tools",children:r.topTools.map(([c,d])=>a.jsxs("div",{className:"ss-tt",children:[a.jsx("span",{className:"ss-tt-name",children:c}),a.jsx("span",{className:"ss-tt-bar",children:a.jsx("span",{className:"ss-tt-bar-fill",style:{width:`${d/r.topTools[0][1]*100}%`}})}),a.jsx("span",{className:"ss-tt-count",children:d})]},c))})]}),r.firstPrompt&&a.jsxs("section",{className:"modal-section",children:[a.jsx("h4",{children:"Opening prompt"}),a.jsx("div",{className:"ss-prompt",children:r.firstPrompt})]})]})]})}):null}function Xo({label:e,value:t,tone:n}){return a.jsxs("div",{className:`ss-stat${n?` tone-${n}`:""}`,children:[a.jsx("div",{className:"ss-stat-value",children:t}),a.jsx("div",{className:"ss-stat-label",children:e})]})}function Uoe(e,t){const n=e.agents.get(t);if(!n)return null;const r=[];for(const _ of e.agents.values())_.sessionId===t&&r.push(_);if(r.length===0)return null;const s={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},o=new Set,l=new Map;let c=0,d=0,h=0,f=0,p=0,g,v=1/0,N=0;for(const _ of r){const E=pn(_);s.input+=E.input,s.output+=E.output,s.cacheRead+=E.cacheRead,s.cacheWrite+=E.cacheWrite,s.total+=E.total;for(const C of g$(_))o.add(C);_.model&&o.add(_.model),_.kind==="subagent"&&p++;const R=t$(_.prompts);d+=R.length,!g&&R.length>0&&(g=R[0].text),h+=_.usage.inputTokens+_.usage.outputTokens,c+=_.toolCount,f+=_.toolErrorCount??0;for(const[C,A]of _.toolCountByName??[])l.set(C,(l.get(C)??0)+A);v=Math.min(v,_.startedAt),N=Math.max(N,_.endedAt??Date.now())}const k=Math.max(0,N-v),x=Math.floor(k/1e3),j=x<60?`${x}s`:x<3600?`${Math.floor(x/60)}m ${String(x%60).padStart(2,"0")}s`:`${Math.floor(x/3600)}h ${Math.floor(x%3600/60)}m`,b=Array.from(l.entries()).sort((_,E)=>E[1]-_[1]).slice(0,5);return{sessionId:t,label:n.label||n.cwdBasename||"session",cwd:n.cwd,durationLabel:j,cost:s,modelChips:Array.from(o),agentCount:r.length,subagentCount:p,toolCount:c,promptCount:d,tokensSum:h,errCount:f,topTools:b,firstPrompt:g}}function zoe({tool:e,onClose:t}){const n=ut(t),r=gt(t),s=e.endedAt==null?"inflight":e.ok===!1?"err":"done",o=y.useRef({of:null});o.current.of!==e&&(o.current={of:e}),e.input!==void 0&&(o.current.input=e.input),e.response!==void 0&&(o.current.response=e.response);const l=o.current.input??e.inputPreview,c=o.current.response??e.errorPreview,d=e.trimmed===!0&&o.current.input===void 0&&o.current.response===void 0,h=y.useMemo(()=>{const f=G8(e.name,l,c);return{input:f.input.map((p,g)=>a.jsx(oM,{block:p},g)),response:f.response.map((p,g)=>a.jsx(oM,{block:p},g)),copyInput:bj(e.name,"input",l),copyResponse:bj(e.name,"response",c)}},[e.name,l,c]);return a.jsx("div",{className:"modal-backdrop",...r,role:"presentation",children:a.jsxs("div",{ref:n,className:"modal",onClick:f=>f.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"tool-modal-title",children:[a.jsxs("header",{className:"modal-head",children:[a.jsxs("div",{className:"modal-title",children:[a.jsx("span",{className:`status-dot ${s}`,"aria-hidden":!0}),a.jsx("span",{id:"tool-modal-title",className:"modal-tool-name",children:e.name}),a.jsxs("span",{className:"modal-tool-id",title:e.id,children:[e.id.slice(0,12),"…"]})]}),a.jsxs("div",{className:"modal-actions",children:[a.jsx("span",{className:"modal-dur",children:v$(e,"in-flight…")}),a.jsx("button",{className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]})]}),a.jsxs("section",{className:"modal-body",children:[d&&a.jsx("div",{className:"modal-section",children:a.jsx("p",{className:"modal-note",children:"Full payloads for this call were released to keep memory bounded — only the previews below are still held."})}),a.jsxs("div",{className:"modal-section",children:[a.jsxs("div",{className:"tm-head",children:[a.jsx("h4",{children:"Input"}),a.jsx(iM,{text:h.copyInput,what:"input"})]}),h.input]}),a.jsxs("div",{className:"modal-section",children:[a.jsxs("div",{className:"tm-head",children:[a.jsxs("h4",{children:["Response ",s==="err"&&a.jsx("span",{className:"err-tag",children:"error"})]}),e.endedAt!=null&&a.jsx(iM,{text:h.copyResponse,what:"response"})]}),e.endedAt==null?a.jsx("pre",{children:"(waiting…)"}):h.response]})]})]})})}const Woe={del:"tm-del",add:"tm-add",ctx:"tm-ctx"};function oM({block:e}){const[t,n]=y.useState(!1);if(e.inline)return a.jsxs("p",{className:"tm-inline",children:[e.label&&a.jsx("span",{className:"tm-label",children:e.label}),a.jsx("code",{children:e.text})]});const r=y.useMemo(()=>B8(e),[e]),{shown:s}=n$(r,t),o=q8(r,t);return a.jsxs("div",{className:"tm-block",children:[e.label&&a.jsx("span",{className:"tm-label",children:e.label}),a.jsx("pre",{className:e.err?"tm-err":void 0,children:e.lines?s.map((l,c)=>a.jsxs("span",{className:l.tone?Woe[l.tone]:void 0,children:[l.text,c<s.length-1?`
|
|
302
302
|
`:""]},c)):s.map(l=>l.text).join(`
|
|
303
|
-
`)}),o&&a.jsx("button",{type:"button",className:"btn tm-more","aria-expanded":o.expanded,onClick:()=>n(l=>!l),children:o.label})]})}function iM({text:e,what:t}){const[n,r]=y.useState(!1),s=y.useRef(!0);return y.useEffect(()=>()=>{s.current=!1},[]),a.jsx("button",{type:"button",className:"btn tm-copy",disabled:!e,"aria-label":n?`The ${t} was copied`:`Copy the ${t}`,onClick:()=>void eo(e).then(o=>{!o||!s.current||(r(!0),window.setTimeout(()=>{s.current&&r(!1)},1600))}),children:n?"copied":"copy"})}const Hoe=aP(()=>l0(()=>import("./UsageHistoryModal-
|
|
303
|
+
`)}),o&&a.jsx("button",{type:"button",className:"btn tm-more","aria-expanded":o.expanded,onClick:()=>n(l=>!l),children:o.label})]})}function iM({text:e,what:t}){const[n,r]=y.useState(!1),s=y.useRef(!0);return y.useEffect(()=>()=>{s.current=!1},[]),a.jsx("button",{type:"button",className:"btn tm-copy",disabled:!e,"aria-label":n?`The ${t} was copied`:`Copy the ${t}`,onClick:()=>void eo(e).then(o=>{!o||!s.current||(r(!0),window.setTimeout(()=>{s.current&&r(!1)},1600))}),children:n?"copied":"copy"})}const Hoe=aP(()=>l0(()=>import("./UsageHistoryModal-DaH3RkMw.js"),[]),"Usage history"),Voe=aP(()=>l0(()=>import("./BrowserWatchModal-D2iFbRdJ.js"),[]),"Browser Watch");function Goe({dialogs:e,welcome:t,desktopUpdate:n,versionCheck:r,restart:s,lanPairs:o,attention:l,clearFlow:c,watchBadge:d,announcements:h,appearance:f,providers:p,stateRef:g,agentCount:v}){const{openedTool:N,setOpenedToolKey:k,usageHistoryOpen:x,setUsageHistoryOpen:j,browserWatchOpen:b,setBrowserWatchOpen:_,contextAgent:E,setContextFor:R,summaryFor:C,setSummaryFor:A,keyHelpOpen:U,setKeyHelpOpen:L,feedbackOpen:F,setFeedbackOpen:O,feedbackPrefill:I,setFeedbackPrefill:B}=e,{tourOpen:M,openTour:$,closeTour:P,releaseNotes:G,closeReleaseNotes:K,chipVersion:q}=t,{desktopUpdateRestarting:H,desktopUpdateFailure:D,readyAppUpdate:W,askDesktopUpdateRestart:J}=n,{version:V}=r,{askRestart:X}=s,{clearConfirmOpen:Y,setClearConfirmOpen:Z,requestClear:ee}=c,{setWatchOn:ne,markWatchSeen:se}=d,{setWatchSaid:pe}=h,{palette:ke}=f;return a.jsxs(a.Fragment,{children:[N&&a.jsx(zoe,{tool:N,onClose:()=>k(null)}),x&&a.jsx(y.Suspense,{fallback:null,children:a.jsx(Hoe,{providers:p,onClose:()=>j(!1)})}),b&&a.jsx(y.Suspense,{fallback:null,children:a.jsx(Voe,{onClose:()=>_(!1),onSeen:ae=>{pe(""),se(ae)},onWatching:ne,palette:ke})}),E&&a.jsx(SU,{agent:E,onClose:()=>R(null)}),F&&a.jsx(sP,{initialKind:I==null?void 0:I.initialKind,initialBody:I==null?void 0:I.initialBody,onClose:()=>{O(!1),B(null)}}),C&&a.jsx(qoe,{state:g.current,sessionId:C,onClose:()=>A(null)}),G&&a.jsx(Boe,{entries:G.entries,since:G.since,firstRun:G.firstRun,running:q,onClose:K,onTour:()=>{K(),$()},updateVersion:W==null?void 0:W.version,updateBusy:H,updateFailure:D&&(!W||W.version===D.version)?nse(D.failure,D.version):void 0,onUpdateRestart:W?()=>{J(W.version)}:void 0,onRestart:!W&&(V!=null&&V.canRestart)?()=>{K(),X()}:void 0}),a.jsx(Koe,{lanPairs:o,attention:l}),U&&a.jsx(ioe,{onClose:()=>L(!1),onTour:()=>{L(!1),$()}}),M&&a.jsx(UI,{title:"What the deck shows you",steps:gK,onClose:P}),Y&&a.jsx(zse,{agentCount:v,onConfirm:()=>ee("confirmation"),onCancel:()=>Z(!1)})]})}function Koe({lanPairs:e,attention:t}){const n=voe(e);return a.jsxs(a.Fragment,{children:[n,a.jsx(Noe,{...t,pairing:n!=null})]})}const Yoe=10,dP=500,hP=4e3,Xoe=[/ResizeObserver loop/i,/^Script error\.?$/i],Ud=String.raw`[^\s\\/:'"\`<>|?*;,]`,Zoe=String.raw`${Ud}(?:[^\\/\r\n:'"\`<>|?*;,]*${Ud})?[\\/]`,Joe=String.raw`[^\s\\/:'"\`<>|?*;,()]+`,bl=String.raw`(?:${Zoe})*(?:${Joe})?`,Qoe=String.raw`(?<![\w.~/\\\]-]|<(?:deck|host)>)(?:file://(?:/[A-Za-z]:)?[^\s:'"\`<>()]*|~[\\/]${bl}|[A-Za-z]:[\\/]${bl}|\\\\(?:[?.]\\)?(?:[A-Za-z]:\\)?${bl}|/(?=${Ud})${bl}|(?<!:)//(?=${Ud})${bl})`,eie=String.raw`(?<![\w-])(?:[A-Za-z]--|-[A-Za-z0-9][\w.]*-)[\w.-]*`,tie=new Set([".claude",".codex"]);function nie(e){if(!e.startsWith("~"))return"<path>";const t=e[1],[n,...r]=e.slice(2).split(/[\\/]/);return n?tie.has(n)?r.join("")?`~${t}${n}${t}<path>`:e:`~${t}<path>`:e}const rie=String.raw`\b(https?|wss?)://[^\s/?#\\'"\x60<>(),;]+(?=(/assets/)?)`;function sie(e,t,n){return n?"<deck>":`${t}://<host>`}const lM=String.raw`(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)`,fP=String.raw`${lM}(?:\.${lM}){3}`,hx=String.raw`[0-9A-Fa-f]{1,4}`,cM=String.raw`(?=[0-9A-Fa-f:]*\d)(?=[0-9A-Fa-f:]*::|(?:${hx}:){7})(?:(?:${hx})?:)+(?:${fP}|${hx})?`,uM=String.raw`%[\w-]+(?:\.[\w-]+)*`,dM=String.raw`(?:::1?|::ffff:(?:127(?:\.\d{1,3}){3}|0\.0\.0\.0))`,aie=String.raw`(?<![\w:.%-])(?:\[(?!${dM}\])${cM}(?:${uM})?\]|(?!${dM}(?::\d{1,5})?(?![\w:%]|\.\d))${cM}(?:${uM})?(?![\w%]|\.\d))|(?<![\w./-])(?!127\.|0\.0\.0\.0\b)${fP}(?![\w-]|\.\d)`,fx=String.raw`(?=[\w.-]*[A-Za-z])[A-Za-z0-9][\w-]*(?:\.[\w-]+)*`,oie=String.raw`(?<![\w.@/\\%-])(?!localhost(?![\w-]|\.\w))(?:(?<=\b(?:(?:getaddrinfo|connect) E[A-Z_]+|ENOTFOUND|EAI_AGAIN) )${fx}|${fx}(?=:\d{1,5}(?![\w:-]|\.\w))|${fx}\.(?:local|lan|home|internal|ts\.net)(?![\w-]|\.\w))`;function hM(e){return String(e??"").replace(/\/(?:home|Users)\/[^/\s:'"]+/g,"~").replace(/[A-Za-z]:\\(?:Users|Documents and Settings)\\[^\\\r\n:'"]+/gi,"~").replace(new RegExp(Qoe,"g"),nie).replace(new RegExp(eie,"g"),"<project>").replace(new RegExp(rie,"g"),sie).replace(new RegExp(aie,"g"),"<host>").replace(new RegExp(oie,"g"),"<host>").replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g,"<email>").replace(/\b(?:sk-ant-[A-Za-z0-9_-]{8,}|sk-[A-Za-z0-9_-]{20,}|gh[pousr]_[A-Za-z0-9]{20,}|xox[abpr]-[A-Za-z0-9-]{10,}|eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}|[A-Fa-f0-9]{40,}|[A-Za-z0-9+_=-]{48,})/g,"<secret>")}const pP=e=>{fetch("/api/client-error",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e),keepalive:!0}).catch(()=>{})};function iie(e,t,n=pP){const r=String(e??"").slice(0,dP).trim();r&&n({message:r,stack:typeof t=="string"?t.slice(0,hP):void 0})}function lie(e,t=window,n=pP){let r=0;const s=new Set,o=(d,h)=>{const f=String(d??"").slice(0,dP).trim();!e()||!f||r>=Yoe||s.has(f)||Xoe.some(p=>p.test(f))||(s.add(f),r++,n({message:f,stack:typeof h=="string"?h.slice(0,hP):void 0}))},l=d=>{var h,f;return o(((h=d.error)==null?void 0:h.message)??d.message,(f=d.error)==null?void 0:f.stack)},c=d=>typeof d.reason=="object"&&d.reason!==null?o(d.reason.message,d.reason.stack):o(d.reason,void 0);return t.addEventListener("error",l),t.addEventListener("unhandledrejection",c),()=>{t.removeEventListener("error",l),t.removeEventListener("unhandledrejection",c)}}const cie=12;function uie(e,t){const n=[hM(e).trim()||"The deck threw an error with no message."],r=t==null?void 0:t.trim();if(r){const s=r.split(`
|
|
304
304
|
`).slice(0,cie).join(`
|
|
305
305
|
`);n.push("",hM(s).trim())}return n.join(`
|
|
306
306
|
`)}class die extends y.Component{constructor(){super(...arguments);lp(this,"state",{error:null,componentStack:null,reportOpen:!1});lp(this,"onKey",n=>{b$(n.key)&&ds.dismissTop()})}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,r){console.error("ccdeck hit a render error it could not draw past",n,r.componentStack),this.setState({componentStack:r.componentStack??null}),iie(n.message,n.stack),FL("offline")}componentDidUpdate(n,r){this.state.reportOpen!==r.reportOpen&&(this.state.reportOpen?window.addEventListener("keydown",this.onKey):window.removeEventListener("keydown",this.onKey))}componentWillUnmount(){window.removeEventListener("keydown",this.onKey)}render(){const{error:n,componentStack:r,reportOpen:s}=this.state;return n?a.jsxs("div",{className:"error-fallback",children:[a.jsxs("div",{className:"error-fallback-card",role:"alert",children:[a.jsx("p",{className:"error-fallback-title",children:"Something went wrong"}),a.jsx("p",{className:"error-fallback-note",children:"The deck hit an error it could not draw past. Reloading usually clears it — and if it keeps happening, a report tells the people who make ccdeck what broke."}),a.jsxs("div",{className:"error-fallback-actions",children:[a.jsx("button",{type:"button",className:"btn primary",onClick:()=>window.location.reload(),children:"Reload"}),a.jsx("button",{type:"button",className:"btn",onClick:()=>this.setState({reportOpen:!0}),"aria-haspopup":"dialog",children:"Send report"})]})]}),s&&a.jsx(sP,{initialKind:"bug",initialBody:uie(n.message,r),onClose:()=>this.setState({reportOpen:!1})})]}):this.props.children}}const hie=1e3;function fie(e={}){const t=Math.max(1,Math.floor(e.limit??hie)),n=e.protect;let r=!1,s=[],o=new Set,l=0,c=0,d=null;return{get paused(){return r},get size(){return s.length},get dropped(){return l},get overflowed(){return l>0},get through(){return c},accept(h){const f=typeof(h==null?void 0:h.seq)=="number"?h.seq:null,p=(h==null?void 0:h.epoch)??null,g=p!==null&&p!==d;g&&(d=p,c=0);const v=f!==null&&!g&&f<=c;if(f!==null&&f>c&&(c=f),!r)return!0;if(v)return!1;if(s.push(h),n!=null&&n(h)&&o.add(h),s.length>t){let N=0;if(o.size<s.length)for(;o.has(s[N]);)N++;const[k]=s.splice(N,1);o.delete(k),l++}return!1},setPaused(h){if(r=h,h)return[];const f=s;return s=[],o=new Set,l=0,f}}}function pie(e){const t=y.useState(()=>fie({protect:o=>J8(e.current,o)}))[0],[n,r]=y.useState(!1),s=y.useCallback(()=>{const o=t.paused&&t.dropped>0,l=t.setPaused(!t.paused);o&&Rq(e.current);for(const c of l)e.current=h$(e.current,c);r(t.paused)},[t,e]);return{pauseGate:t,paused:n,togglePause:s}}const Eb={kind:"assumed",claude:!0,codex:!0};function mie(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 gie(e){const[t,n]=y.useState(null),[r,s]=y.useState(Eb);y.useEffect(()=>{let l=!1;return fetch("/api/health").then(c=>c.ok?c.json():null).then(c=>{l||(s(mie(c)),!(!c||typeof c.workspace!="string")&&n(c.workspace))}).catch(()=>{}),()=>{l=!0}},[e]);const o=_n(r);return{workspace:t,providers:r,providersRef:o}}const mP=3*6e4,yie=2e4;function wie({fetchReport:e,visible:t,now:n,onReport:r}){let s=0,o=!0;const l=async()=>{if(!t())return;const c=await e();!o||!c||(s=n(),r(c))};return{tick:l,wake:async()=>{t()&&n()-s>=mP&&await l()},stop:()=>{o=!1}}}async function vie(){try{const e=await fetch("/api/provider-status",{signal:AbortSignal.timeout(yie)});return e.ok?await e.json():null}catch{return null}}function xie(e){const[t,n]=y.useState(null);return y.useEffect(()=>{if(!e){n(null);return}const r=wie({fetchReport:vie,visible:()=>document.visibilityState==="visible",now:()=>Date.now(),onReport:n});r.tick();const s=window.setInterval(r.tick,mP),o=()=>{r.wake()};return document.addEventListener("visibilitychange",o),()=>{r.stop(),window.clearInterval(s),document.removeEventListener("visibilitychange",o)}},[e]),t}const bie={degraded:"degraded performance",partial_outage:"partial outage",major_outage:"major outage",maintenance:"maintenance"},kie={degraded:"degraded",partial_outage:"partial outage",major_outage:"major outage",maintenance:"maintenance"},Nie={degraded:"degraded",partial_outage:"outage",major_outage:"outage",maintenance:"maint."},jie={claude:"Claude",codex:"Codex"},Sie=new Set(["status.claude.com","status.openai.com"]),_ie=30*6e4,Eie=10*6e4;function Tie(e){if(typeof e!="string")return null;try{const t=new URL(e);return t.protocol==="https:"&&Sie.has(t.hostname)?t:null}catch{return null}}function fM(e){return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hourCycle:"h23"})}function Cie(e){const t=Math.floor(e/6e4);return t<1?"just now":t<60?`${t} min ago`:`${Math.floor(t/60)} h ago`}function Aie(e,t){if(!e||typeof e!="object")return null;const n=Ot(bie,e.state),r=Ot(jie,e.provider);if(!n||!r||typeof e.checkedAt!="number"||t-e.checkedAt>_ie)return null;const s=Tie(e.statusPageUrl);if(!s)return null;const o=Array.isArray(e.components)?e.components:[],l=e.stale===!0||t-e.checkedAt>Eie,c=[`${r}: ${n}${e.summary?` — ${e.summary}`:""}`,o.length>0?`Affected: ${o.join(", ")}`:null,e.scope==="page"?`The page's overall status: it names none of ${r}'s components`:null,l?`Last read from ${s.hostname} at ${fM(e.checkedAt)}; this is the last thing it said`:`Reported by ${s.hostname}, checked ${Cie(t-e.checkedAt)}`,"Opens the status page"],d=l?fM(e.checkedAt):null;return{provider:e.provider,state:e.state,name:r,label:`${r} · ${n}${d?` · as of ${d}`:""}`,words:n,chipWords:Ot(kie,e.state)??n,shortWords:Ot(Nie,e.state)??n,asOf:d,what:e.summary||(o.length>0?o.join(", "):null),href:s.href,host:s.hostname,stale:l,detail:c.filter(Boolean).join(`
|
|
307
|
-
`)}}function Rie(e,t){return!(e!=null&&e.ok)||e.disabled||!Array.isArray(e.providers)?[]:e.providers.map(n=>Aie(n,t)).filter(n=>n!==null)}function Mie(e){return e.map(t=>`${t.name}'s status page reports ${t.state.endsWith("outage")?`a ${t.words}`:t.words}.`).join(" ")}const $ie="The providers' status pages report no incident.";function Iie({version:e,loadVersion:t}){var h;const[n,r]=y.useState(!1),s=((h=e==null?void 0:e.upgrade)==null?void 0:h.state)??"idle",o=Rse(e==null?void 0:e.upgrade),l=y.useRef(!1),c=y.useCallback(async()=>{if(lr(l.current||s==="running")){l.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await t(),l.current=!1}},[s,t]);y.useEffect(()=>{if(s!=="running")return;const f=window.setInterval(t,3e3);return()=>window.clearInterval(f)},[s,t]);const d=y.useCallback(async()=>{const f=e==null?void 0:e.command;!f||!await eo(f)||(r(!0),window.setTimeout(()=>r(!1),1600))},[e==null?void 0:e.command]);return{upgradeState:s,upgradeFailure:o,startUpgrade:c,copyCommand:d,cmdCopied:n}}const pM="agent-dag.browserWatch.seenMs";function Oie(e,t){return e.filter(n=>n.startMs>t)}function Lie(){const[e,t]=y.useState(()=>Number(Qe(pM))||0),[n,r]=y.useState([]),[s,o]=y.useState(!1);y.useEffect(()=>{let d=!0;const h=()=>{fetch("/api/browser-watch?live=0").then(p=>p.ok?p.json():null).then(p=>{var g;!d||!(p!=null&&p.ok)||(r(p.episodes??[]),o(((g=p.settings)==null?void 0:g.enabled)===!0))}).catch(()=>{})};h();const f=setInterval(h,5*6e4);return()=>{d=!1,clearInterval(f)}},[]);const l=y.useMemo(()=>Oie(n,e).length,[n,e]),c=y.useCallback(d=>{t(d),Ze(pM,String(d))},[]);return{watchOn:s,setWatchOn:o,watchUnseen:l,markWatchSeen:c}}const gP=["--err","--inflight","--ok","--grid-line","--minimap-mask","--panel","--line","--accent","--text-dim","--bg"];function mM(e){const t={};for(const n of gP)t[n]=e(n);return t}function Pie(e){return t=>e[t]??""}function Die(e,t){return gP.every(n=>e[n]===t[n])}const yP="agent-dag.theme";function Fie(e,t=!1){return e==="light"||e==="dark"?e:t?"light":"dark"}function Bie(){try{return window.matchMedia("(prefers-color-scheme: light)").matches}catch{return!1}}function qie(){return Fie(Qe(yP),Bie())}function gM(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}function Uie(){const[e,t]=y.useState(qie),[n,r]=y.useState(wre),[s,o]=y.useState(()=>mM(gM)),l=y.useMemo(()=>Pie(s),[s]),c=y.useCallback(d=>vne(d,l),[l]);return y.useEffect(()=>{document.documentElement.dataset.theme=e,Ze(yP,e),o(d=>{const h=mM(gM);return Die(d,h)?d:h})},[e]),y.useEffect(()=>{Ze(zL,n?"1":"0")},[n]),y.useEffect(()=>{const d=document.querySelector('meta[name="theme-color"]'),h=s["--panel"];d&&h&&d.setAttribute("content",h)},[s]),{theme:e,setTheme:t,characterEnabled:n,setCharacterEnabled:r,palette:s,minimapNodeFill:c}}function zie(e){const t=y.useRef(null),[n,r]=y.useState(!1),[s,o]=y.useState(()=>new Set),l=y.useMemo(()=>{const d=new Set;for(const h of e.current.agents.values())for(const f of h.tools)d.add(qL(f.name));return Object.keys(BL).filter(h=>d.has(h))},[e.current,e.current.revision]);y.useEffect(()=>{if(l.length<=1){r(!1);return}let d=0;const h=()=>{const f=t.current;if(f&&!document.hidden){const p=f.getBoundingClientRect(),g=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(N=>N.getBoundingClientRect()),v=qH(p,g,8);r(N=>N===v?N:v)}d=window.setTimeout(h,300)};return h(),()=>window.clearTimeout(d)},[l.length]);const c=y.useCallback(d=>{o(h=>{const f=new Set(h);return f.has(d)?f.delete(d):f.add(d),f})},[]);return{presentCats:l,hiddenCats:s,toggleCat:c,catBarRef:t,catBarOccluded:n}}function Wie(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null;const r=new Set,s=()=>e.enabled()?(n==null?void 0:n.state)==="running"?"ready":"locked":"off",o=()=>{var g;return(g=e.onState)==null?void 0:g.call(e,s())};function l(){var g,v;if(!(!t||(n==null?void 0:n.state)==="running"))try{n||(n=new t,(g=n.addEventListener)==null||g.call(n,"statechange",o)),(v=n.resume)==null||v.call(n).then(o,()=>{}),o()}catch{}}function c(g,v,N=v.figure){if(!n||n.state!=="running")return!1;const k=db(g,N),x=NZ(v.level,k),j=n.currentTime;for(const b of k.notes){const _=n.createOscillator(),E=n.createGain();_.type=k.type??"sine",_.frequency.value=b.hz;const R=j+b.at,C=R+b.ms/1e3;E.gain.setValueAtTime(h_,R),E.gain.exponentialRampToValueAtTime(x,R+jZ),E.gain.exponentialRampToValueAtTime(h_,C),_.connect(E).connect(n.destination),_.start(R),_.stop(C+.02)}return!0}async function d(g,v){var x;if(!e.loadCustom)return"unavailable";let N;try{N=await e.loadCustom(g)}catch{return"unavailable"}if(!N)return"missing";if(N.kind==="tts"){if(typeof window>"u"||!("speechSynthesis"in window)||typeof SpeechSynthesisUtterance>"u")return"unavailable";const j=new SpeechSynthesisUtterance(N.text),b=window.speechSynthesis.getVoices();j.voice=b.find(_=>_.voiceURI===N.voiceURI)??null,j.rate=N.rate,j.pitch=N.pitch,j.volume=SZ(v.level);try{return window.speechSynthesis.cancel(),window.speechSynthesis.speak(j),"played"}catch{return"unavailable"}}if(!n||n.state!=="running")return"locked";let k;try{k=await n.decodeAudioData(N.bytes.slice(0))}catch{return"broken"}try{const j=n.createBufferSource(),b=n.createGain();return j.buffer=k,b.gain.setValueAtTime(_Z(N.normalizationGain,v.level),n.currentTime),j.connect(b).connect(n.destination),r.add(j),(x=j.addEventListener)==null||x.call(j,"ended",()=>r.delete(j)),j.start(n.currentTime),"played"}catch{return"unavailable"}}function h(g,v=!1){var x,j;if(!v&&!e.enabled())return!1;const N=$Z((x=e.prefs)==null?void 0:x.call(e),g),k=((j=e.customSelection)==null?void 0:j.call(e)[g])??null;return k&&e.loadCustom?(d(k,N).then(b=>{var _;b==="played"||b==="locked"||((b==="missing"||b==="broken")&&((_=e.onCustomFailure)==null||_.call(e,g,k)),c(g,{...N,figure:jn},jn))}),!0):!n||n.state!=="running"?!1:c(g,N)}function f(g,v=Qa){return d(g,{level:vi(v),figure:jn}),!0}function p(){try{typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}catch{}for(const g of r)try{g.stop()}catch{}r.clear()}return{unlock:l,play:h,previewCustom:f,silence:p,state:s,get context(){return n}}}function Hie({chimesRef:e,soundOnRef:t,tonePrefsRef:n,customSelectionsRef:r,fallbackCustomRef:s}){const[o,l]=y.useState("locked");return y.useEffect(()=>{const c=Wie({enabled:()=>t.current===!0,prefs:()=>n.current,customSelection:()=>r.current,loadCustom:wZ,onCustomFailure:(p,g)=>s.current(p,g),onState:l});e.current=c,l(c.state());const d=["pointerdown","pointerup","keydown"],h=()=>{for(const p of d)window.removeEventListener(p,f,{capture:!0})},f=()=>{var p;c.unlock(),((p=c.context)==null?void 0:p.state)==="running"&&h()};for(const p of d)window.addEventListener(p,f,{capture:!0});return h},[]),{chimeState:o}}function Vie(){const[e,t]=y.useState(xre),[n,r]=y.useState(()=>h8(Qe(pj))),[s,o]=y.useState(()=>d8(Qe(mj))),[l,c]=y.useState(()=>f8(Qe(qR),n,gre)),[d,h]=y.useState(()=>new Set),[f,p]=y.useState(0);y.useEffect(()=>{Ze(WL,String(e))},[e]),y.useEffect(()=>{Ze(mj,s?"1":"0")},[s]),y.useEffect(()=>{Ze(pj,JSON.stringify(n))},[n]),y.useEffect(()=>{Ze(qR,l)},[l]);const g=y.useCallback(j=>{r(b=>b.some(_=>_.id===j.id)?b:[...b,j]),h(b=>{if(!b.has(j.id))return b;const _=new Set(b);return _.delete(j.id),_})},[]),v=y.useCallback((j,b)=>{const _=b.trim();!_||_.length>zl||r(E=>E.map(R=>R.id===j?{...R,name:_}:R))},[]),N=y.useCallback(j=>{r(b=>b.filter(_=>_.id!==j)),c(b=>p8(b,j)),h(b=>{if(!b.has(j))return b;const _=new Set(b);return _.delete(j),_})},[]),k=y.useCallback(j=>{const b=gj(j),_=d.has(b);j===l&&!_||(_&&h(E=>{const R=new Set(E);return R.delete(b),R}),c(j),p(E=>E+1))},[l,d]),x=y.useCallback((j,b)=>{const _=gj(j);h(E=>{if(E.has(_)===b)return E;const C=new Set(E);return b?C.add(_):C.delete(_),C})},[]);return{fmVolume:e,setFmVolume:t,fmMuted:s,setFmMuted:o,fmSource:l,customFmStations:n,unavailableFmStations:d,fmPlayRequest:f,addFmStation:g,renameFmStation:v,removeFmStation:N,pickFmSource:k,markFmStationAvailability:x}}function Gie(e){const[t,n]=y.useState(null),[r,s]=y.useState(!1),[o,l]=y.useState(null),c=y.useRef(0);y.useEffect(()=>{if(!e||!ac())return;let N=!1;const k=c.current;return fetch("/api/desktop-update").then(x=>x.ok?x.json():null).then(x=>{if(N||c.current!==k)return;const j=KR(x);j&&n(j)}).catch(()=>{}),()=>{N=!0}},[e]);const d=Zre(t),h=y.useRef(!1),f=y.useRef(0),p=y.useRef(0);y.useEffect(()=>()=>window.clearTimeout(f.current),[]);const g=y.useCallback(async N=>{if(!lr(h.current))return;const k=++p.current;window.clearTimeout(f.current),h.current=!0,s(!0),l(null);const x=j=>{k===p.current&&(window.clearTimeout(f.current),h.current=!1,s(!1),l({failure:j,version:N}))};try{const j=await fetch("/api/desktop-update/restart",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:N})});if(!j.ok)return x(tse(await j.json().catch(()=>null)))}catch{return x("unreachable")}k===p.current&&(f.current=window.setTimeout(()=>x("timeout"),HL))},[]),v=y.useCallback(N=>{if(ac())try{const k=KR(JSON.parse(N));k&&(c.current++,n(k),k.status!=="ready"&&(p.current++,window.clearTimeout(f.current),h.current=!1,s(!1)))}catch{}},[]);return{desktopUpdateRestarting:r,desktopUpdateFailure:o,readyAppUpdate:d,askDesktopUpdateRestart:g,onDesktopUpdateEvent:v}}const Xu="agent-dag.autoRestart",yM="agent-dag.bundleReloadedFor";function Kie({now:e,stateRef:t,version:n,notice:r,noticeOpen:s,upgradeFailure:o,paused:l}){const[c,d]=y.useState(()=>Qe(Xu)!=="0"),h=y.useRef(!1),f=y.useCallback(()=>{const F=!c;h.current=!0,hs(Xu),d(F),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:F})}).then(O=>O.ok?O.json():null).then(O=>{var I;O!=null&&O.ok&&d(((I=O.prefs)==null?void 0:I.autoUpdate)!==!1)}).catch(()=>{})},[c]),[p,g]=y.useState(!1),[v,N]=y.useState("restart"),[k,x]=y.useState(null),j=y.useRef(!1),b=y.useRef(null),_=y.useRef(0),E=y.useRef(null),R=y.useCallback(async F=>{if(!lr(j.current))return;const O=(F==null?void 0:F.upgrade)===!0,I=(F==null?void 0:F.whenIdle)===!0;j.current=!0,b.current=o;const B=++_.current,M=()=>{N(O?"npx":"restart"),g(!0)};I||M();try{window.sessionStorage.setItem("agent-dag.restartPending",(r==null?void 0:r.to)??"")}catch{}let $=!1;try{const P=await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(I?{upgrade:O,whenIdle:I}:{upgrade:O})});$=I&&P.status===409}catch{}if($){j.current=!1,E.current=null;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}return}I&&M(),window.setTimeout(()=>{if(_.current===B&&j.current){j.current=!1,g(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},O?18e4:3e4)},[r==null?void 0:r.to,o]);y.useEffect(()=>{const F=YR(t.current.agents.values())>0,O=Lse({enabled:c,kind:r==null?void 0:r.kind,canRestart:(n==null?void 0:n.canRestart)===!0,noticeOpen:s,visible:document.visibilityState==="visible",busy:F,idleSince:E.current,now:e});E.current=O.idleSince,O.restart&&R({whenIdle:!0})},[c,r==null?void 0:r.kind,n==null?void 0:n.canRestart,s,e,R]);const C=YR(t.current.agents.values()),A=Ose(C,l),U=KL({enabled:c,kind:r==null?void 0:r.kind,canRestart:(n==null?void 0:n.canRestart)===!0,noticeOpen:s,visible:document.visibilityState==="visible",busy:C>0,idleSince:E.current,now:e});y.useEffect(()=>{const F=n==null?void 0:n.running;let O=null,I=null;try{O=window.sessionStorage.getItem("agent-dag.restartPending"),I=window.sessionStorage.getItem(yM)}catch{return}const B=Ase({bundle:"3.38.0",running:F,pending:O,lastTried:I});if(B==="reload"){try{window.sessionStorage.setItem(yM,F??"")}catch{return}window.location.reload();return}if(B!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}j.current=!1,g(!1),x(F??null);const M=window.setTimeout(()=>x(null),6e3);return()=>window.clearTimeout(M)},[n==null?void 0:n.running]),y.useEffect(()=>{if(p&&Mse({asked:b.current,reported:o})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}j.current=!1,g(!1)}},[p,o]);const L=y.useCallback(F=>{var O,I;if(!h.current){const B=Qe(Xu)==="0";hs(Xu),B&&((O=F.prefs)==null?void 0:O.autoUpdate)!==!1?(d(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):d(((I=F.prefs)==null?void 0:I.autoUpdate)!==!1)}},[]);return{autoRestart:c,toggleAutoRestart:f,restarting:p,restartMode:v,restartedTo:k,askRestart:R,restartCopy:A,restartFuseMs:U,loadAutoRestartPrefs:L}}function Yie(){const[e,t]=y.useState([]),n=y.useRef(new Set),[r,s]=y.useState(null),[o,l]=y.useState(void 0);y.useEffect(()=>{let h=!0,f=0;const p=()=>{fetch("/api/lan").then(g=>g.ok?g.json():null).then(g=>h?(g!=null&&g.ok&&t(LS(Array.isArray(g.pending)?g.pending:[],g.aliases)),g):null).catch(()=>null).then(g=>{h&&(l(v=>g!=null&&g.ok?g:v===void 0?null:v),f=window.setTimeout(p,(g==null?void 0:g.enabled)===!0?rb:qI))})};return p(),()=>{h=!1,window.clearTimeout(f)}},[]);const c=y.useCallback(async(h,f)=>{if(!r){s(h);try{const g=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:h,fp:f})})).json().catch(()=>null);g&&Array.isArray(g.pending)?t(LS(g.pending,g.aliases)):t(v=>v.filter(N=>N.fp!==f))}catch{}finally{s(null)}}},[r]),d=y.useCallback(h=>{r||(n.current.add(h),t(f=>[...f]))},[r]);return{lanPending:e,lanDeferred:n,lanBusy:r,answerLanPair:c,deferLanPair:d,lanStatus:o}}const Xie=6e4;function Zie({enabled:e,lanStatus:t,now:n}){const[r,s]=y.useState(null),[o,l]=y.useState(()=>new Set),[c,d]=y.useState(null),h=y.useCallback(j=>{j!=null&&j.ok&&Array.isArray(j.accounts)&&s(j.accounts)},[]),f=y.useCallback(async j=>{try{const b=await fetch(`/api/claude-accounts${j?"?refresh=1":""}`);b.ok&&h(await b.json())}catch{}},[h]);y.useEffect(()=>{e&&f(!1)},[e,f]),y.useEffect(()=>{if(!e)return;let j=Date.now();const b=()=>{document.visibilityState!=="visible"||Date.now()-j<Xie||(j=Date.now(),f(!1))};return document.addEventListener("visibilitychange",b),window.addEventListener("focus",b),()=>{document.removeEventListener("visibilitychange",b),window.removeEventListener("focus",b)}},[e,f]);const p=y.useMemo(()=>e?uoe(r,{lan:t,now:n,closed:o}):[],[e,r,t,n,o]),g=y.useRef(p);g.current=p;const v=y.useCallback(j=>{j.length&&l(b=>new Set([...b,...j]))},[]),N=y.useCallback(()=>{const j=g.current;j.length&&(v(j.map(b=>b.id)),fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"reauth-later",incidents:j.map(b=>({key:b.key,since:b.since}))})}).catch(()=>{}))},[v]),k=y.useRef(c);k.current=c;const x=y.useCallback(j=>{const b=k.current;v(doe(b?[b,...g.current]:g.current,j))},[v]);return{rows:p,signingIn:c,observe:h,signIn:d,signedIn:x,refresh:y.useCallback(()=>{f(!0)},[f]),closeSignIn:y.useCallback(()=>d(null),[]),later:N}}const wP="agent-dag.sessionListOpen",vP="agent-dag.accountsPanelOpen";function Jie(){return Qe(wP)==="1"}function Qie(e){Ze(wP,e?"1":"0")}function ele(){const e=Qe(vP);return e===null?!0:e==="1"}function tle(){const[e,t]=y.useState(Jie);y.useEffect(()=>{Qie(e)},[e]);const n=y.useRef(!1),[r,s]=y.useState(()=>{const h=ele();return h&&e?(n.current=!0,!1):h});y.useEffect(()=>{!r&&n.current||Ze(vP,r?"1":"0")},[r]),y.useEffect(()=>{!e&&n.current&&(n.current=!1,s(!0))},[e]);const o=y.useCallback(()=>{t(h=>(h||s(f=>(f&&(n.current=!0),!1)),!h))},[]),l=y.useCallback(()=>{n.current=!1,s(h=>(h||t(!1),!h))},[]),c=y.useCallback(()=>t(!1),[]),d=y.useCallback(()=>s(!1),[]);return{sessionListOpen:e,accountsPanelOpen:r,toggleSessionList:o,toggleAccountsPanel:l,closeSessionList:c,closeAccountsPanel:d}}const xP="agent-dag.detailOpen",bP="agent-dag.usagePanelOpen",kP="agent-dag.systemPanelOpen";function nle(){return Qe(xP)==="1"}function rle(e){Ze(xP,e?"1":"0")}function sle(){const e=Qe(bP);return e===null?!0:e==="1"}function ale(e){Ze(bP,e?"1":"0")}function ole(){const e=Qe(kP);return e===null?!0:e==="1"}function ile(e){Ze(kP,e?"1":"0")}function lle(){const[e,t]=y.useState(nle);y.useEffect(()=>{rle(e)},[e]);const[n,r]=y.useState(sle);y.useEffect(()=>{ale(n)},[n]);const[s,o]=y.useState(ole);return y.useEffect(()=>{ile(s)},[s]),qt("usage-panel",n),qt("machine-panel",s),{detailOpen:e,setDetailOpen:t,usagePanelOpen:n,setUsagePanelOpen:r,machinePanelOpen:s,setMachinePanelOpen:o}}const cle={permission:"your permission",asked:"your answer"},ule="No sessions are waiting for you.";function dle(e){if(e.length===0)return"";const[t,...n]=e,r=t.waiting.kind,s=n.every(l=>l.waiting.kind===r)?cle[r]??"you":"you";if(n.length===0)return`${t.label} is waiting for ${s}.`;const o=`${n.length} more session${n.length===1?"":"s"}`;return`${t.label} and ${o} are waiting for ${s}.`}function px(e,t,n=ule){return t!==""?t:e===""?"":n}function hle({waitingSessions:e,watchUnseen:t,incidents:n=[]}){const[r,s]=y.useState(""),o=dle(e);y.useEffect(()=>{s(g=>px(g,o))},[o]);const[l,c]=y.useState(""),d=t>0?`Browser watch has ${t} unread ${t===1?"finding":"findings"}.`:"";y.useEffect(()=>{c(g=>px(g,d,"Browser watch has no unread findings."))},[d]);const[h,f]=y.useState(""),p=Mie(n);return y.useEffect(()=>{f(g=>px(g,p,$ie))},[p]),{blockedSaid:r,watchSaid:l,setWatchSaid:c,incidentSaid:h}}const fle="/icon-192.png";function ple({waitingSessions:e,liveSince:t,focusSession:n}){const[r,s]=y.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[o,l]=y.useState(null),[c,d]=y.useState(!1),[h,f]=y.useState(!1),p=y.useRef(()=>{}),g=y.useRef(new Set),v=_n(e),N=y.useCallback(()=>{const R=!c;d(R),R&&(g.current=Iu(v.current)),R&&typeof Notification<"u"&&Notification.permission==="default"&&p.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:R})}).then(C=>C.ok?C.json():null).then(C=>{var A;C!=null&&C.ok&&(d(((A=C.prefs)==null?void 0:A.notifications)===!0),f(C.notificationsVetoed===!0))}).catch(()=>{})},[c]),k=typeof Notification<"u";y.useEffect(()=>{if(!o)return;const C=setTimeout(()=>l(null),o==="blocked"?8e3:4e3);return()=>clearTimeout(C)},[o]);const x=y.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(R=>{const C=R;s(C),C==="granted"?l("on"):C==="denied"&&l("blocked")})},[]);p.current=x;const j=y.useRef(null),b=e.map(R=>Qd(R.id,R.waiting)).join("|");y.useEffect(()=>{Zq(j.current,r)&&(j.current=r,g.current=Iu(e))},[r]);const _=y.useRef(!1);y.useEffect(()=>{Jq(_.current,t)&&(_.current=!0,g.current=Iu(e))},[t]),y.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!Qq(j.current,t))return;const R=typeof document>"u"||!document.hidden,C=Yq(e,g.current,R,c);for(const A of C)try{const U=new Notification(A.title,{body:A.body,tag:A.key,icon:fle});U.onclick=()=>{window.focus(),n(A.sessionId),U.close()}}catch{}g.current=R?Iu(e):Xq(e,C,g.current)},[b,t]);const E=y.useCallback(R=>{var C;d(((C=R.prefs)==null?void 0:C.notifications)===!0),f(R.notificationsVetoed===!0)},[]);return{notifyPermission:r,notifySaid:o,notifyOn:c,notifyVetoed:h,toggleNotify:N,notifySupported:k,askForNotifications:x,loadNotifyPrefs:E}}function mle({openedTool:e,usageHistoryOpen:t,contextFor:n,tourOpen:r,summaryFor:s,browserWatchOpen:o,keyHelpOpen:l,releaseNotes:c,feedbackOpen:d}){const h=_n(l),f=y.useRef(!1);return f.current=e!=null||t||n!=null||r||s!=null||o||l||c!=null||d,{keyHelpOpenRef:h,modalOpenRef:f}}function gle({stateRef:e,tourOpen:t,releaseNotes:n}){const[r,s]=y.useState(null),o=y.useCallback((F,O)=>s({agentId:F,toolId:O}),[]),[l,c]=y.useState(null),[d,h]=y.useState(null),f=y.useCallback(F=>h(F),[]),[p,g]=y.useState(!1),[v,N]=y.useState(!1),[k,x]=y.useState(!1),[j,b]=y.useState(!1),[_,E]=y.useState(null),R=y.useCallback(F=>{E(F??null),b(!0)},[]);qt("tool-detail",r!==null),qt("session-summary",l!==null),qt("context-window",d!==null),qt("keyboard-help",p),qt("usage-history",v),qt("browser-watch",k),qt("feedback",j);const C=r?K8(e.current.agents,r.agentId,r.toolId):null,A=d?e.current.agents.get(d):void 0,{keyHelpOpenRef:U,modalOpenRef:L}=mle({openedTool:C,usageHistoryOpen:v,contextFor:d,tourOpen:t,summaryFor:l,browserWatchOpen:k,keyHelpOpen:p,releaseNotes:n,feedbackOpen:j});return{setOpenedToolKey:s,openTool:o,openedTool:C,summaryFor:l,setSummaryFor:c,contextFor:d,setContextFor:h,openContext:f,contextAgent:A,keyHelpOpen:p,setKeyHelpOpen:g,usageHistoryOpen:v,setUsageHistoryOpen:N,browserWatchOpen:k,setBrowserWatchOpen:x,feedbackOpen:j,setFeedbackOpen:b,feedbackPrefill:_,setFeedbackPrefill:E,openFeedback:R,keyHelpOpenRef:U,modalOpenRef:L}}function yle({stateRef:e,pinnedRef:t,measuredRef:n,positionsRef:r,lastLayoutSigRef:s,forgetRemovals:o,clearSelection:l,rerender:c,modalOpenRef:d}){const[h,f]=y.useState(!1),p=y.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}e.current=Yb(),t.current.clear(),n.current.clear(),r.current.clear(),s.current="",IL(),o(),l(),c()},[c,l,o]),g=_n(h),v=y.useCallback(N=>{const k=Fse(N,{confirmOpen:g.current,modalOpen:d.current});k==="confirm"?f(!0):k==="clear"&&(f(!1),p())},[p]);return{clearConfirmOpen:h,setClearConfirmOpen:f,requestClear:v}}const wM="agent-dag.oldNameNoticeDismissed";function wle(e){const[t,n]=y.useState(()=>Qe(wM)??""),r=e!=null&&e.invokedAs&&e.invokedAs!==kt?e.invokedAs:null,s=r!=null&&t!==r,o=y.useCallback(()=>{r&&(n(r),Ze(wM,r))},[r]);return{oldName:r,oldNameOpen:s,dismissOldName:o}}const vle=300*1e3,xle=1800*1e3,ble=8e3,kle=3e4;function vM(e){return fetch("/api/rating",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)}).catch(()=>null)}function Nle({modalOpenRef:e}){const t=y.useCallback(()=>k$({appModal:e.current,dialogDepth:ds.dialogDepth()}),[e]),[n,r]=y.useState("hidden"),[s,o]=y.useState(null),[l,c]=y.useState(!1),d=y.useRef(n);d.current=n,y.useEffect(()=>{let v=!1;const N=async()=>{if(d.current==="thanks"||d.current==="hidden"&&(document.hidden||t()))return;const j=await fetch("/api/rating").then(b=>b.ok?b.json():null).catch(()=>null);v||!j||r(b=>b==="thanks"?b:j.ask===!0?"asking":"hidden")},k=window.setTimeout(N,vle),x=window.setInterval(N,xle);return()=>{v=!0,window.clearTimeout(k),window.clearInterval(x)}},[t]),y.useEffect(()=>{if(n!=="thanks"||l)return;const v=s!==null&&s<=6?kle:ble;let N=0;const k=()=>{t()?N=window.setTimeout(k,v):r("hidden")};return N=window.setTimeout(k,v),()=>window.clearTimeout(N)},[n,s,l,t]);const h=y.useCallback(v=>{o(v),c(!1),r("thanks"),vM({score:v})},[]),f=y.useCallback(v=>c(v),[]),p=y.useCallback(()=>{r("hidden"),vM({later:!0})},[]),g=y.useCallback(()=>r("hidden"),[]);return{ratingPhase:n,ratingScore:s,answerRating:h,rateLater:p,closeRating:g,holdThanks:f}}function jle({chimesRef:e,setTonePrefs:t,tonePrefsRef:n,previewTone:r}){const[s,o]=y.useState(()=>oZ(Qe)),l=_n(s),[c,d]=y.useState([]),h=y.useCallback(b=>{o(_=>{const E={..._,[b]:null};return l.current=E,E}),hs(Il[b])},[]),f=y.useCallback((b,_)=>{const E=l.current[b];_&&E!==_||(h(b),t(R=>{const C={...R,[b]:{...R[b],figure:jn}};return n.current=C,C}),Ze(Id[b],jn))},[h]),p=_n(f);y.useEffect(()=>{let b=!0;return yZ().then(_=>{if(!b)return;d(_);const E=new Set(_.map(R=>R.id));for(const R of ad){const C=l.current[R];C&&!E.has(C)&&p.current(R,C)}},()=>{}),()=>{b=!1}},[]);const g=y.useCallback((b,_)=>{if(!c.some(R=>R.id===_))return;const E={...l.current,[b]:_};l.current=E,o(E),Ze(Il[b],_),r(b,!0)},[c,r]),v=y.useCallback(async b=>{var C;const _=ub(c.length);if(_)throw new Error(_);const E=window.AudioContext??window.webkitAudioContext;if(!E)throw new Error("This browser cannot decode audio files.");const R=new E;try{const A=await hZ(b,L=>R.decodeAudioData(L));await u_(A);const U=tc(A);d(L=>[...L.filter(F=>F.id!==U.id),U])}finally{(C=R.close)==null||C.call(R)}},[c.length]),N=y.useCallback(async b=>{const _=ub(c.length);if(_)throw new Error(_);const E=fZ(b);await u_(E);const R=tc(E);d(C=>[...C.filter(A=>A.id!==R.id),R])},[c.length]),k=y.useCallback(async(b,_)=>{const E=c.find(C=>C.id===b),R=_.trim().slice(0,80);!E||!R||R===E.name||(await vZ(b,R),d(C=>C.map(A=>A.id===b?{...A,name:R}:A)))},[c]),x=y.useCallback(async b=>{await xZ(b),d(C=>C.filter(A=>A.id!==b));const _=l.current,E=iZ(_,b);l.current=E,o(E);const R=ad.filter(C=>_[C]===b);for(const C of R)hs(Il[C]),Ze(Id[C],jn);R.length>0&&t(C=>{const A={...C};for(const U of R)A[U]={...A[U],figure:jn};return n.current=A,A})},[]),j=y.useCallback(b=>{var R,C;const _=ad.find(A=>l.current[A]===b),E=_?n.current[_].level:Qa;(R=e.current)==null||R.unlock(),(C=e.current)==null||C.previewCustom(b,E)},[]);return{customSelections:s,customSelectionsRef:l,customAssets:c,clearCustomOnly:h,fallbackCustomRef:p,selectCustomTone:g,importNotificationAudio:v,createNotificationVoice:N,renameCustomAsset:k,deleteCustomAsset:x,previewCustomAsset:j}}function Sle(e){const[t,n]=y.useState(()=>MZ(Qe)),r=_n(t),s=y.useRef(null),o=y.useCallback((c,d=!1)=>{var h,f;if((h=e.current)==null||h.unlock(),s.current!==null&&clearTimeout(s.current),s.current=null,!d){(f=e.current)==null||f.play(c,!0);return}s.current=setTimeout(()=>{var p;s.current=null,(p=e.current)==null||p.play(c,!0)},EZ)},[]),l=y.useCallback((c,d)=>{n(h=>{const f={level:vi(d.level??h[c].level),figure:yO(c,d.figure??h[c].figure)};return Ze(xO[c],String(f.level)),Ze(Id[c],f.figure),{...h,[c]:f}}),o(c,!0)},[o]);return y.useEffect(()=>()=>{s.current!==null&&clearTimeout(s.current)},[]),{tonePrefs:t,setTonePrefs:n,tonePrefsRef:r,previewTone:o,changeTone:l}}const _le=15e3;function Ele(e){return e.visibilityState==="visible"&&e.hasFocus()}function Tle(e,t){return t||e===!0}function Cle(){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 Ale(){y.useEffect(()=>{const e=Cle();let t=null;const n=l=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:e,looking:l}),keepalive:!0}).catch(()=>{})},r=()=>{const l=Ele(document);Tle(t,l)&&n(l),t=l},s=()=>{t&&n(!1),t=!1};r();const o=window.setInterval(r,_le);return window.addEventListener("focus",r),window.addEventListener("blur",r),document.addEventListener("visibilitychange",r),window.addEventListener("pagehide",s),()=>{window.clearInterval(o),window.removeEventListener("focus",r),window.removeEventListener("blur",r),document.removeEventListener("visibilitychange",r),window.removeEventListener("pagehide",s),s()}},[])}function Rle({loadAutoRestartPrefs:e,loadNotifyPrefs:t,loadReportsPrefs:n}){y.useEffect(()=>{let r=!0;return fetch("/api/prefs").then(s=>s.ok?s.json():null).then(s=>{!r||!(s!=null&&s.ok)||(e(s),t(s),n(s))}).catch(()=>{}),()=>{r=!1}},[])}const mx="agent-dag.versionNoticeDismissed",Mle=15*6e4;function $le(e){const[t,n]=y.useState(null),[r,s]=y.useState(()=>Qe(mx)??""),o=y.useRef(0),[l,c]=y.useState(!1),d=y.useCallback((k=!1)=>(k&&(o.current=Date.now(),c(!0)),fetch(k?"/api/version?refresh=1":"/api/version").then(x=>x.ok?x.json():null).then(x=>{x&&n(x)}).catch(()=>{}).finally(()=>{k&&c(!1)})),[]),h=y.useCallback(()=>{d(Date.now()-o.current>=Mle)},[d]);y.useEffect(()=>{d();const k=window.setInterval(h,5*6e4),x=()=>{document.visibilityState==="visible"&&h()};return document.addEventListener("visibilitychange",x),()=>{window.clearInterval(k),document.removeEventListener("visibilitychange",x)}},[d,h]),y.useEffect(()=>{e&&d()},[e,d]);const f=(t==null?void 0:t.notice)??null,p=VL(f),g=ise(f,r),v=y.useCallback(()=>{s(""),Ze(mx,"")},[]),N=y.useCallback(()=>{f&&(s(p),Ze(mx,p))},[f,p]);return{version:t,notice:f,noticeOpen:g,showNotice:v,dismissNotice:N,versionChecking:l,loadVersion:d}}function Ile({version:e,readyAppUpdate:t}){const[n,r]=y.useState(!1),s=y.useRef(null),[o,l]=y.useState(null),c=o&&t?t.version:null,d=y.useRef(null);y.useEffect(()=>{!c||d.current===c||(d.current=c,fetch("/api/desktop-update/seen",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:c})}).catch(()=>{}))},[c]);const h=y.useRef(!1);y.useEffect(()=>{if(h.current)return;const x=Ml(),j=Moe(x),b=Doe({stored:j,running:(e==null?void 0:e.running)??null,notes:aM,remembers:$oe(x)});if(b.reason==="no-version")return;h.current=!0,b.record&&Ioe(x,b.record);let _=!0;return(async()=>{var U;let R=Ooe(x);if(ac())try{const L=await fetch("/api/prefs");if(!L.ok)throw new Error("desktop tour preferences unavailable");const F=await L.json();if(!(F!=null&&F.ok))throw new Error("desktop tour preferences unavailable");const O=((U=F.prefs)==null?void 0:U.tourSeen)===!0;R&&!O&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{}),R=R||O}catch{R=!0}if(!_)return;const C=Poe({tourSeen:R,decision:b}),A=b.show.length?{entries:b.show,since:j,firstRun:!1}:null;C.tour&&r(!0),C.notes==="now"?l(A):C.notes==="after"&&(s.current=A)})(),()=>{_=!1}},[e==null?void 0:e.running]);const f=(e==null?void 0:e.running)??"3.38.0",p=y.useMemo(()=>iP(aM,null,f),[f]),g=y.useCallback(()=>{l({entries:p,since:null,firstRun:!1})},[p]),v=y.useCallback(()=>r(!0),[]),N=y.useCallback(()=>l(null),[]),k=y.useCallback(()=>{r(!1),Loe(Ml()),ac()&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{});const x=s.current;s.current=null,x&&l(x)},[]);return{tourOpen:n,openTour:v,closeTour:k,releaseNotes:o,closeReleaseNotes:N,chipVersion:f,openReleaseNotes:g}}function Ole(){const[e,t]=y.useState(void 0),[n,r]=y.useState(!1),s=y.useRef(!1);return s.current=e===!0&&!n,y.useEffect(()=>lie(()=>s.current),[]),{loadReportsPrefs:y.useCallback(l=>{var c;t(((c=l.prefs)==null?void 0:c.reports)!==!1),r(l.reportsVetoed===!0)},[])}}function Lle(){const[e,t]=y.useState(null),[n,r]=y.useState(!1),s=y.useRef(null);return y.useEffect(()=>{let o=!0,l=!1,c=null,d=null,h="";const f=k=>{o&&(r(!0),k!==h&&t(null))},p=()=>{if(l)return;l=!0,c=Date.now();const k=VR();d=k,fetch(`/api/ccusage?since=${k}`).then(x=>x.ok?x.json():null).then(x=>{if(o){if(!(x!=null&&x.ok)){f(k);return}h=k,t(Yre(x)),r(!1)}}).catch(()=>f(k)).finally(()=>{l=!1})},g=()=>{const k=s.current;Kre({shown:!!k&&k.getClientRects().length>0,tabVisible:document.visibilityState==="visible",lastSince:d,since:VR(),lastReadAt:c,now:Date.now()})&&p()};g();const v=window.setInterval(g,Gre);document.addEventListener("visibilitychange",g);let N=null;return s.current&&typeof ResizeObserver<"u"&&(N=new ResizeObserver(g),N.observe(s.current)),()=>{o=!1,window.clearInterval(v),document.removeEventListener("visibilitychange",g),N==null||N.disconnect()}},[]),{monthlyUsage:e,monthlyUsageUnavailable:n,monthUsageRef:s}}function Ple(e){const[t,n]=y.useState(null);y.useEffect(()=>{const c=Qe("agent-dag.sound");n(c===null?!0:c==="on")},[]);const r=y.useCallback(()=>{n(c=>{var h,f;const d=c!==!0;return Ze("agent-dag.sound",d?"on":"off"),d?(h=e.current)==null||h.unlock():(f=e.current)==null||f.silence(),d})},[]),s=y.useCallback(c=>{r()},[r]),o=_n(s),l=_n(t);return{soundOn:t,toggleSound:r,activateSoundRef:o,soundOnRef:l}}function Dle(){const[e,t]=y.useState(!1),n=y.useRef(null),[r,s]=y.useState(!1),o=y.useRef(null);return y.useEffect(()=>{e&&s(!1)},[e]),{soundMenuOpen:e,setSoundMenuOpen:t,soundButtonRef:n,appearanceMenuOpen:r,setAppearanceMenuOpen:s,appearanceButtonRef:o}}const Fle="agent-dag.autoFitDisabled";function Ble(e){const t=y.useRef(!1),[n,r]=y.useState(!1);y.useEffect(()=>{hs(Fle)},[]);const s=y.useCallback(()=>{t.current||(t.current=!0,r(!0))},[]),o=y.useCallback(()=>{t.current=!1,r(!1),e(400)},[e]);return{autoFitDisabled:n,autoFitDisabledRef:t,disableAutoFit:s,enableAutoFitAndRefit:o}}function qle(){return a.jsx(Vb,{children:a.jsx(die,{children:a.jsx(Ule,{})})})}function Ule(){const e=ki(),t=y.useState(Yb)[0],n=y.useRef(t),[,r]=y.useState(0),s=y.useCallback(()=>r(ba=>ba+1),[]),{detailOpen:o,setDetailOpen:l,usagePanelOpen:c,setUsagePanelOpen:d,machinePanelOpen:h,setMachinePanelOpen:f}=lle(),{selectedIds:p,primarySelectedId:g,selectAgent:v,clearSelection:N,pruneSelectionToBoard:k}=XZ(n,l),{sessionListOpen:x,accountsPanelOpen:j,toggleSessionList:b,toggleAccountsPanel:_,closeSessionList:E,closeAccountsPanel:R}=tle(),C=Lle(),A=td(j,200),U=td(c,130),L=td(h,130),F=y.useRef(null),O=Ple(F),{activateSoundRef:I,soundOnRef:B}=O,M=Sle(F),{setTonePrefs:$,tonePrefsRef:P,previewTone:G}=M,K=jle({chimesRef:F,setTonePrefs:$,tonePrefsRef:P,previewTone:G}),{customSelectionsRef:q,fallbackCustomRef:H}=K,D=Dle(),{setSoundMenuOpen:W}=D,{chimeState:J}=Hie({chimesRef:F,soundOnRef:B,tonePrefsRef:P,customSelectionsRef:q,fallbackCustomRef:H}),V=pie(n),{pauseGate:X,paused:Y,togglePause:Z}=V,ee=y.useRef(()=>{}),{live:ne,tabCapped:se,everConnected:pe,liveSince:ke}=BZ({stateRef:n,rerender:s,pauseGate:X,chimesRef:F,desktopUpdateRef:ee}),ae=$le(ne),{version:fe,notice:me,noticeOpen:he,loadVersion:ge}=ae,ue=Gie(ne),{readyAppUpdate:be,onDesktopUpdateEvent:oe}=ue;ee.current=oe,Ale();const je=Ile({version:fe,readyAppUpdate:be}),{tourOpen:$e,openTour:Oe,releaseNotes:Ue}=je,{workspace:Be,providers:We,providersRef:He}=gie(ne),rt=wle(fe),lt=Iie({version:fe,loadVersion:ge}),{upgradeFailure:Rt}=lt,De=gle({stateRef:n,tourOpen:$e,releaseNotes:Ue}),et=Nle({modalOpenRef:De.modalOpenRef}),{openTool:Je,setSummaryFor:tt,setContextFor:yt,openContext:Pt,setKeyHelpOpen:wt,setUsageHistoryOpen:st,setBrowserWatchOpen:zt,keyHelpOpenRef:Wt,modalOpenRef:Dt}=De,Ht=Ole(),Vt=Lie(),{watchOn:vs,watchUnseen:Cn}=Vt,mr=Yie(),[zr,gr]=y.useState(0),{presentCats:Wr,hiddenCats:mn,toggleCat:Hr,catBarRef:An,catBarOccluded:da}=zie(n),gn=y.useRef(null),[yr,wr]=y.useState(0),xt=ZZ({stateRef:n,rerender:s,pruneSelectionToBoard:k,setContextFor:yt,setSummaryFor:tt}),xs=xie(We.claude||We.codex),vr=Rie(xs,xt),xr=Zie({enabled:We.claude,lanStatus:mr.lanStatus,now:xt}),Gt=Kie({now:xt,stateRef:n,version:fe,notice:me,noticeOpen:he,upgradeFailure:Rt,paused:V.paused}),{askRestart:bs,loadAutoRestartPrefs:Vr}=Gt,ye=Uie(),{setTheme:Fe,palette:Ge}=ye,rn=Vie(),Gr=Yte(),{applyViewport:br,moveCamera:ha,fitLeft:Ke,cameraEpochRef:Kr,lastFitTimeRef:ks}=Gr,kr=ine(Ke),{pinnedRef:Kn,positionsRef:Yr,lastLayoutSigRef:ao,handleRelayout:Ns}=kr,Jt=y.useRef(null),js=y.useRef(()=>{}),yn=ke!==null,xc=y.useRef(0),bc=y.useCallback(()=>{xc.current=Date.now()},[]),{canvasRef:Nr,canvasSize:oo,paneSizeRef:io}=Fne(),Ss=Ble(Ke),{autoFitDisabledRef:fa,disableAutoFit:Mi}=Ss,$i=y.useRef(!1),{measuredRef:Yn,measuredVersionRef:kc,sizeVersion:Ii,domSizeVersion:pa}=Bne($i),{removedNodes:Nc,removedAgentIds:jr,removeNode:Ye,removeSelectedNode:Oi,removalNotice:Li,bringBack:ma,bringBackAll:jc,forgetRemovals:Sc}=Tne({stateRef:n,pinnedRef:Kn,positionsRef:Yr,canvasRef:Nr,clearSelection:N,primarySelectedId:g}),lo=Nne({stateRef:n,now:xt,removedAgentIds:jr,sizeVersion:Ii,domSizeVersion:pa});lne(lo,kr),Ene({layoutSig:lo,rf:e,stateRef:n,measuredRef:Yn,pinnedRef:Kn,positionsRef:Yr,paneSizeRef:io,lastInteractRef:xc,autoFitDisabledRef:fa,lastFitTimeRef:ks,fitLeft:Ke});const co=qne(),{bubbling:uo,endBubble:Sr,onBubble:_r}=WX(),[Rn,ga]=y.useState(!1),_s=UX(),{beginTrashDrag:Er,trackTrashDrag:Lh,endTrashDrag:_c}=_s,Es=QX({stateRef:n,measuredRef:Yn,measuredVersionRef:kc,canvasRef:Nr}),{lodRef:Ph,applyZoom:Ec}=Es,ya=Pne({applyViewport:br,lastFitTimeRef:ks,cameraEpochRef:Kr,disableAutoFit:Mi,markInteract:bc,canvasRef:Nr,applyZoom:Ec}),Ts=g?n.current.agents.get(g):null,Pi=o&&Ts!=null,wn=Hne({sessionListShown:x,usageShown:La(U),machineShown:La(L),accountsShown:La(A)&&We.claude,detailShown:Pi,primarySelectedId:g,canvasRef:Nr}),{railInsetRef:Cs,availableWidth:Xr,availableHeight:wa}=Kte({canvasRef:Nr,canvasSize:oo,machinePhase:L,usagePhase:U,usagePanelOpen:c,detailShown:Pi}),Tc=jne({stateRef:n,now:xt,availableWidth:Xr,availableHeight:wa,layout:kr,measuredRef:Yn,onBubble:_r,settled:co,dragging:Rn,layoutSig:lo,selectedIds:p,openContext:Pt,historyReplayed:yn,removedNodes:Nc,removedAgentIds:jr,dragTick:zr,dragPatchRef:gn,dragMoveTick:yr}),{nodes:Di,edges:Fi}=Tc,As=_n(g);cne({nodes:Di,edges:Fi,settled:co,dragging:Rn,availableWidth:Xr,availableHeight:wa,layout:kr,camera:Gr,rf:e,measuredRef:Yn,stateRef:n,lastFocusRef:Jt,primarySelectedIdRef:As,focusAgentRef:js,autoFitDisabledRef:fa});const ho=yle({stateRef:n,pinnedRef:Kn,measuredRef:Yn,positionsRef:Yr,lastLayoutSigRef:ao,forgetRemovals:Sc,clearSelection:N,rerender:s,modalOpenRef:Dt}),{requestClear:Bi}=ho,Tr=Vne({nodes:Di,stateRef:n,pinnedRef:Kn,positionsRef:Yr,draggingRef:$i,dragPatchRef:gn,setDragging:ga,setDragMoveTick:wr,setDragTick:gr,endBubble:Sr,markInteract:bc,disableAutoFit:Mi,beginTrashDrag:Er,trackTrashDrag:Lh,endTrashDrag:_c,removeNode:Ye}),qi=y.useCallback(()=>Ke(500),[Ke]),Rs=_n(Di),{focusAgent:va,stepAgent:fo,focusSession:Cr}=Zte({canvasRef:Nr,stateRef:n,measuredRef:Yn,nodesRef:Rs,railInsetRef:Cs,moveCamera:ha,disableAutoFit:Mi,lastFocusRef:Jt,focusAgentRef:js,selectAgent:v,primarySelectedIdRef:As}),Cc=Dne({clearSelection:N,selectAgent:v,detailOpen:o,setDetailOpen:l,detailShown:Pi,focusAgent:va,draggingRef:$i,lodRef:Ph}),Qt=Jte({nodesRef:Rs,stateRef:n,canvasRef:Nr,railInsetRef:Cs}),Ms=_n(Oi),po=y.useRef(null),xa=y.useCallback(ba=>{jr.has(ba)&&ma([ba]),Cr(ba)},[jr,ma,Cr]),Dh=Une();zne({pointerFocusRef:Dh,nodesRef:Rs,stateRef:n,primarySelectedIdRef:As,providersRef:He,soundOnRef:B,keyHelpOpenRef:Wt,modalOpenRef:Dt,waitingCursorRef:po,removeSelectedRef:Ms,activateSoundRef:I,clearSelection:N,selectAgent:v,focusAgent:va,stepAgent:fo,focusSession:Cr,requestClear:Bi,handleRelayout:Ns,handleFit:qi,togglePause:Z,toggleSessionList:b,toggleAccountsPanel:_,setDetailOpen:l,setUsageHistoryOpen:st,setUsagePanelOpen:d,setMachinePanelOpen:f,setBrowserWatchOpen:zt,setSoundMenuOpen:W,setKeyHelpOpen:wt,setTheme:Fe});const mo=n.current.agents.size,Zr=y.useMemo(()=>Ix(n.current.agents.values()),[n.current,n.current.revision]);Cne({stateRef:n,waitingSessions:Zr,removedAgentIds:jr,removedNodes:Nc,bringBack:ma}),Ine({stateRef:n,waitingSessions:Zr,live:ne});const $s=hle({waitingSessions:Zr,watchUnseen:Cn,incidents:vr}),Is=ple({waitingSessions:Zr,liveSince:ke,focusSession:Cr}),{loadNotifyPrefs:Ac}=Is;return Rle({loadAutoRestartPrefs:Vr,loadNotifyPrefs:Ac,loadReportsPrefs:Ht.loadReportsPrefs}),a.jsxs("div",{className:"app",children:[a.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),a.jsxs("header",{className:"topbar",children:[a.jsx(fse,{versionCheck:ae,welcome:je,desktopUpdate:ue,pause:V,monthly:C,announcements:$s,notify:Is,waitingSessions:Zr,waitingCursorRef:po,focusSession:Cr,live:ne,now:xt,incidents:vr}),Ts&&a.jsx(pse,{selected:Ts,now:xt,selectedIds:p,focusAgent:va,clearSelection:N}),a.jsxs("div",{className:"actions",children:[a.jsx(zre,{sessionListOpen:x,toggleSessionList:b,usagePanelOpen:c,setUsagePanelOpen:d,setUsageHistoryOpen:st,toggles:wn.toggles}),a.jsx(Wre,{providers:We,accountsPanelOpen:j,toggleAccountsPanel:_,machinePanelOpen:h,setMachinePanelOpen:f,watchOn:vs,watchUnseen:Cn,setBrowserWatchOpen:zt,toggles:wn.toggles}),a.jsx(Hre,{providers:We,sound:O,tones:M,customTones:K,notify:Is,chimeState:J,menus:D,appearance:ye,fm:rn,onFeedback:()=>De.openFeedback(),watchUnseen:Cn,setUsageHistoryOpen:st,setBrowserWatchOpen:zt})]})]}),a.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Li?`${Li.label} removed from the board.`:""}),a.jsx(Dse,{restart:Gt,versionCheck:ae,upgrade:lt,oldNameNotice:rt,rating:et,onFeedback:De.openFeedback,everConnected:pe,live:ne,paused:Y}),La(A)&&We.claude&&a.jsx(OX,{leaving:A==="leaving",onReport:De.openFeedback,onRoster:xr.observe,onClose:()=>{wn.accounts(),R()}}),x&&a.jsx(WH,{state:n.current,now:xt,selectedIds:p,onSelect:xa,onClose:()=>{wn.sessionList(),E()},removedIds:jr,onBringBackAll:jc}),a.jsxs(vse,{canvasRef:Nr,bubbling:uo,dragging:Rn,trash:_s,zoom:Es,viewport:ya,stateRef:n,peek:Qt,children:[mo===0&&(!ne&&se?a.jsx(ere,{}):a.jsx(tre,{live:ne,everConnected:pe,providers:We,workspace:Be,onTour:Oe})),(Wr.length>1||mn.size>0)&&a.jsx(mse,{catBarRef:An,catBarOccluded:da,presentCats:Wr,hiddenCats:mn,toggleCat:Hr}),a.jsx(EH,{graph:Tc,layout:kr,viewport:ya,clicks:Cc,drag:Tr,appearance:ye,fm:rn,autoFit:Ss,pause:V,stateRef:n,measuredRef:Yn,hiddenCats:mn,now:xt,openTool:Je,focusAgent:va,requestClear:Bi,setKeyHelpOpen:wt})]}),La(U)&&a.jsx(F7,{state:n.current,now:xt,providers:We,incidents:vr,liveSince:ke,leaving:U==="leaving",onClose:()=>{wn.usage(),d(!1)}}),La(L)&&a.jsx(k9,{usageOpen:c,leaving:L==="leaving",onClose:()=>{wn.machine(),f(!1)}}),o&&Ts?a.jsx(pre,{selected:Ts,now:xt,openTool:Je,setSummaryFor:tt,stateRef:n,removeSelectedNode:Oi,onClose:()=>{wn.detail(),l(!1)}}):null,a.jsx(Goe,{dialogs:De,welcome:je,desktopUpdate:ue,versionCheck:ae,restart:Gt,lanPairs:mr,attention:xr,clearFlow:ho,watchBadge:Vt,announcements:$s,appearance:ye,providers:We,stateRef:n,agentCount:mo})]})}try{RU(window.localStorage)}catch{}const zle=r4.createRoot(document.getElementById("root"));zle.render(a.jsx(qle,{}));export{Yne as a,it as b,oa as c,gt as d,is as e,qe as f,Vle as g,Dr as h,Hle as i,a as j,Ql as k,Tn as l,uZ as m,ea as n,eo as o,Vx as p,y as r,lr as s,ut as u};
|
|
307
|
+
`)}}function Rie(e,t){return!(e!=null&&e.ok)||e.disabled||!Array.isArray(e.providers)?[]:e.providers.map(n=>Aie(n,t)).filter(n=>n!==null)}function Mie(e){return e.map(t=>`${t.name}'s status page reports ${t.state.endsWith("outage")?`a ${t.words}`:t.words}.`).join(" ")}const $ie="The providers' status pages report no incident.";function Iie({version:e,loadVersion:t}){var h;const[n,r]=y.useState(!1),s=((h=e==null?void 0:e.upgrade)==null?void 0:h.state)??"idle",o=Rse(e==null?void 0:e.upgrade),l=y.useRef(!1),c=y.useCallback(async()=>{if(lr(l.current||s==="running")){l.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await t(),l.current=!1}},[s,t]);y.useEffect(()=>{if(s!=="running")return;const f=window.setInterval(t,3e3);return()=>window.clearInterval(f)},[s,t]);const d=y.useCallback(async()=>{const f=e==null?void 0:e.command;!f||!await eo(f)||(r(!0),window.setTimeout(()=>r(!1),1600))},[e==null?void 0:e.command]);return{upgradeState:s,upgradeFailure:o,startUpgrade:c,copyCommand:d,cmdCopied:n}}const pM="agent-dag.browserWatch.seenMs";function Oie(e,t){return e.filter(n=>n.startMs>t)}function Lie(){const[e,t]=y.useState(()=>Number(Qe(pM))||0),[n,r]=y.useState([]),[s,o]=y.useState(!1);y.useEffect(()=>{let d=!0;const h=()=>{fetch("/api/browser-watch?live=0").then(p=>p.ok?p.json():null).then(p=>{var g;!d||!(p!=null&&p.ok)||(r(p.episodes??[]),o(((g=p.settings)==null?void 0:g.enabled)===!0))}).catch(()=>{})};h();const f=setInterval(h,5*6e4);return()=>{d=!1,clearInterval(f)}},[]);const l=y.useMemo(()=>Oie(n,e).length,[n,e]),c=y.useCallback(d=>{t(d),Ze(pM,String(d))},[]);return{watchOn:s,setWatchOn:o,watchUnseen:l,markWatchSeen:c}}const gP=["--err","--inflight","--ok","--grid-line","--minimap-mask","--panel","--line","--accent","--text-dim","--bg"];function mM(e){const t={};for(const n of gP)t[n]=e(n);return t}function Pie(e){return t=>e[t]??""}function Die(e,t){return gP.every(n=>e[n]===t[n])}const yP="agent-dag.theme";function Fie(e,t=!1){return e==="light"||e==="dark"?e:t?"light":"dark"}function Bie(){try{return window.matchMedia("(prefers-color-scheme: light)").matches}catch{return!1}}function qie(){return Fie(Qe(yP),Bie())}function gM(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}function Uie(){const[e,t]=y.useState(qie),[n,r]=y.useState(wre),[s,o]=y.useState(()=>mM(gM)),l=y.useMemo(()=>Pie(s),[s]),c=y.useCallback(d=>vne(d,l),[l]);return y.useEffect(()=>{document.documentElement.dataset.theme=e,Ze(yP,e),o(d=>{const h=mM(gM);return Die(d,h)?d:h})},[e]),y.useEffect(()=>{Ze(zL,n?"1":"0")},[n]),y.useEffect(()=>{const d=document.querySelector('meta[name="theme-color"]'),h=s["--panel"];d&&h&&d.setAttribute("content",h)},[s]),{theme:e,setTheme:t,characterEnabled:n,setCharacterEnabled:r,palette:s,minimapNodeFill:c}}function zie(e){const t=y.useRef(null),[n,r]=y.useState(!1),[s,o]=y.useState(()=>new Set),l=y.useMemo(()=>{const d=new Set;for(const h of e.current.agents.values())for(const f of h.tools)d.add(qL(f.name));return Object.keys(BL).filter(h=>d.has(h))},[e.current,e.current.revision]);y.useEffect(()=>{if(l.length<=1){r(!1);return}let d=0;const h=()=>{const f=t.current;if(f&&!document.hidden){const p=f.getBoundingClientRect(),g=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(N=>N.getBoundingClientRect()),v=qH(p,g,8);r(N=>N===v?N:v)}d=window.setTimeout(h,300)};return h(),()=>window.clearTimeout(d)},[l.length]);const c=y.useCallback(d=>{o(h=>{const f=new Set(h);return f.has(d)?f.delete(d):f.add(d),f})},[]);return{presentCats:l,hiddenCats:s,toggleCat:c,catBarRef:t,catBarOccluded:n}}function Wie(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null;const r=new Set,s=()=>e.enabled()?(n==null?void 0:n.state)==="running"?"ready":"locked":"off",o=()=>{var g;return(g=e.onState)==null?void 0:g.call(e,s())};function l(){var g,v;if(!(!t||(n==null?void 0:n.state)==="running"))try{n||(n=new t,(g=n.addEventListener)==null||g.call(n,"statechange",o)),(v=n.resume)==null||v.call(n).then(o,()=>{}),o()}catch{}}function c(g,v,N=v.figure){if(!n||n.state!=="running")return!1;const k=db(g,N),x=NZ(v.level,k),j=n.currentTime;for(const b of k.notes){const _=n.createOscillator(),E=n.createGain();_.type=k.type??"sine",_.frequency.value=b.hz;const R=j+b.at,C=R+b.ms/1e3;E.gain.setValueAtTime(h_,R),E.gain.exponentialRampToValueAtTime(x,R+jZ),E.gain.exponentialRampToValueAtTime(h_,C),_.connect(E).connect(n.destination),_.start(R),_.stop(C+.02)}return!0}async function d(g,v){var x;if(!e.loadCustom)return"unavailable";let N;try{N=await e.loadCustom(g)}catch{return"unavailable"}if(!N)return"missing";if(N.kind==="tts"){if(typeof window>"u"||!("speechSynthesis"in window)||typeof SpeechSynthesisUtterance>"u")return"unavailable";const j=new SpeechSynthesisUtterance(N.text),b=window.speechSynthesis.getVoices();j.voice=b.find(_=>_.voiceURI===N.voiceURI)??null,j.rate=N.rate,j.pitch=N.pitch,j.volume=SZ(v.level);try{return window.speechSynthesis.cancel(),window.speechSynthesis.speak(j),"played"}catch{return"unavailable"}}if(!n||n.state!=="running")return"locked";let k;try{k=await n.decodeAudioData(N.bytes.slice(0))}catch{return"broken"}try{const j=n.createBufferSource(),b=n.createGain();return j.buffer=k,b.gain.setValueAtTime(_Z(N.normalizationGain,v.level),n.currentTime),j.connect(b).connect(n.destination),r.add(j),(x=j.addEventListener)==null||x.call(j,"ended",()=>r.delete(j)),j.start(n.currentTime),"played"}catch{return"unavailable"}}function h(g,v=!1){var x,j;if(!v&&!e.enabled())return!1;const N=$Z((x=e.prefs)==null?void 0:x.call(e),g),k=((j=e.customSelection)==null?void 0:j.call(e)[g])??null;return k&&e.loadCustom?(d(k,N).then(b=>{var _;b==="played"||b==="locked"||((b==="missing"||b==="broken")&&((_=e.onCustomFailure)==null||_.call(e,g,k)),c(g,{...N,figure:jn},jn))}),!0):!n||n.state!=="running"?!1:c(g,N)}function f(g,v=Qa){return d(g,{level:vi(v),figure:jn}),!0}function p(){try{typeof window<"u"&&"speechSynthesis"in window&&window.speechSynthesis.cancel()}catch{}for(const g of r)try{g.stop()}catch{}r.clear()}return{unlock:l,play:h,previewCustom:f,silence:p,state:s,get context(){return n}}}function Hie({chimesRef:e,soundOnRef:t,tonePrefsRef:n,customSelectionsRef:r,fallbackCustomRef:s}){const[o,l]=y.useState("locked");return y.useEffect(()=>{const c=Wie({enabled:()=>t.current===!0,prefs:()=>n.current,customSelection:()=>r.current,loadCustom:wZ,onCustomFailure:(p,g)=>s.current(p,g),onState:l});e.current=c,l(c.state());const d=["pointerdown","pointerup","keydown"],h=()=>{for(const p of d)window.removeEventListener(p,f,{capture:!0})},f=()=>{var p;c.unlock(),((p=c.context)==null?void 0:p.state)==="running"&&h()};for(const p of d)window.addEventListener(p,f,{capture:!0});return h},[]),{chimeState:o}}function Vie(){const[e,t]=y.useState(xre),[n,r]=y.useState(()=>h8(Qe(pj))),[s,o]=y.useState(()=>d8(Qe(mj))),[l,c]=y.useState(()=>f8(Qe(qR),n,gre)),[d,h]=y.useState(()=>new Set),[f,p]=y.useState(0);y.useEffect(()=>{Ze(WL,String(e))},[e]),y.useEffect(()=>{Ze(mj,s?"1":"0")},[s]),y.useEffect(()=>{Ze(pj,JSON.stringify(n))},[n]),y.useEffect(()=>{Ze(qR,l)},[l]);const g=y.useCallback(j=>{r(b=>b.some(_=>_.id===j.id)?b:[...b,j]),h(b=>{if(!b.has(j.id))return b;const _=new Set(b);return _.delete(j.id),_})},[]),v=y.useCallback((j,b)=>{const _=b.trim();!_||_.length>zl||r(E=>E.map(R=>R.id===j?{...R,name:_}:R))},[]),N=y.useCallback(j=>{r(b=>b.filter(_=>_.id!==j)),c(b=>p8(b,j)),h(b=>{if(!b.has(j))return b;const _=new Set(b);return _.delete(j),_})},[]),k=y.useCallback(j=>{const b=gj(j),_=d.has(b);j===l&&!_||(_&&h(E=>{const R=new Set(E);return R.delete(b),R}),c(j),p(E=>E+1))},[l,d]),x=y.useCallback((j,b)=>{const _=gj(j);h(E=>{if(E.has(_)===b)return E;const C=new Set(E);return b?C.add(_):C.delete(_),C})},[]);return{fmVolume:e,setFmVolume:t,fmMuted:s,setFmMuted:o,fmSource:l,customFmStations:n,unavailableFmStations:d,fmPlayRequest:f,addFmStation:g,renameFmStation:v,removeFmStation:N,pickFmSource:k,markFmStationAvailability:x}}function Gie(e){const[t,n]=y.useState(null),[r,s]=y.useState(!1),[o,l]=y.useState(null),c=y.useRef(0);y.useEffect(()=>{if(!e||!ac())return;let N=!1;const k=c.current;return fetch("/api/desktop-update").then(x=>x.ok?x.json():null).then(x=>{if(N||c.current!==k)return;const j=KR(x);j&&n(j)}).catch(()=>{}),()=>{N=!0}},[e]);const d=Zre(t),h=y.useRef(!1),f=y.useRef(0),p=y.useRef(0);y.useEffect(()=>()=>window.clearTimeout(f.current),[]);const g=y.useCallback(async N=>{if(!lr(h.current))return;const k=++p.current;window.clearTimeout(f.current),h.current=!0,s(!0),l(null);const x=j=>{k===p.current&&(window.clearTimeout(f.current),h.current=!1,s(!1),l({failure:j,version:N}))};try{const j=await fetch("/api/desktop-update/restart",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:N})});if(!j.ok)return x(tse(await j.json().catch(()=>null)))}catch{return x("unreachable")}k===p.current&&(f.current=window.setTimeout(()=>x("timeout"),HL))},[]),v=y.useCallback(N=>{if(ac())try{const k=KR(JSON.parse(N));k&&(c.current++,n(k),k.status!=="ready"&&(p.current++,window.clearTimeout(f.current),h.current=!1,s(!1)))}catch{}},[]);return{desktopUpdateRestarting:r,desktopUpdateFailure:o,readyAppUpdate:d,askDesktopUpdateRestart:g,onDesktopUpdateEvent:v}}const Xu="agent-dag.autoRestart",yM="agent-dag.bundleReloadedFor";function Kie({now:e,stateRef:t,version:n,notice:r,noticeOpen:s,upgradeFailure:o,paused:l}){const[c,d]=y.useState(()=>Qe(Xu)!=="0"),h=y.useRef(!1),f=y.useCallback(()=>{const F=!c;h.current=!0,hs(Xu),d(F),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:F})}).then(O=>O.ok?O.json():null).then(O=>{var I;O!=null&&O.ok&&d(((I=O.prefs)==null?void 0:I.autoUpdate)!==!1)}).catch(()=>{})},[c]),[p,g]=y.useState(!1),[v,N]=y.useState("restart"),[k,x]=y.useState(null),j=y.useRef(!1),b=y.useRef(null),_=y.useRef(0),E=y.useRef(null),R=y.useCallback(async F=>{if(!lr(j.current))return;const O=(F==null?void 0:F.upgrade)===!0,I=(F==null?void 0:F.whenIdle)===!0;j.current=!0,b.current=o;const B=++_.current,M=()=>{N(O?"npx":"restart"),g(!0)};I||M();try{window.sessionStorage.setItem("agent-dag.restartPending",(r==null?void 0:r.to)??"")}catch{}let $=!1;try{const P=await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(I?{upgrade:O,whenIdle:I}:{upgrade:O})});$=I&&P.status===409}catch{}if($){j.current=!1,E.current=null;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}return}I&&M(),window.setTimeout(()=>{if(_.current===B&&j.current){j.current=!1,g(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},O?18e4:3e4)},[r==null?void 0:r.to,o]);y.useEffect(()=>{const F=YR(t.current.agents.values())>0,O=Lse({enabled:c,kind:r==null?void 0:r.kind,canRestart:(n==null?void 0:n.canRestart)===!0,noticeOpen:s,visible:document.visibilityState==="visible",busy:F,idleSince:E.current,now:e});E.current=O.idleSince,O.restart&&R({whenIdle:!0})},[c,r==null?void 0:r.kind,n==null?void 0:n.canRestart,s,e,R]);const C=YR(t.current.agents.values()),A=Ose(C,l),U=KL({enabled:c,kind:r==null?void 0:r.kind,canRestart:(n==null?void 0:n.canRestart)===!0,noticeOpen:s,visible:document.visibilityState==="visible",busy:C>0,idleSince:E.current,now:e});y.useEffect(()=>{const F=n==null?void 0:n.running;let O=null,I=null;try{O=window.sessionStorage.getItem("agent-dag.restartPending"),I=window.sessionStorage.getItem(yM)}catch{return}const B=Ase({bundle:"3.38.1",running:F,pending:O,lastTried:I});if(B==="reload"){try{window.sessionStorage.setItem(yM,F??"")}catch{return}window.location.reload();return}if(B!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}j.current=!1,g(!1),x(F??null);const M=window.setTimeout(()=>x(null),6e3);return()=>window.clearTimeout(M)},[n==null?void 0:n.running]),y.useEffect(()=>{if(p&&Mse({asked:b.current,reported:o})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}j.current=!1,g(!1)}},[p,o]);const L=y.useCallback(F=>{var O,I;if(!h.current){const B=Qe(Xu)==="0";hs(Xu),B&&((O=F.prefs)==null?void 0:O.autoUpdate)!==!1?(d(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):d(((I=F.prefs)==null?void 0:I.autoUpdate)!==!1)}},[]);return{autoRestart:c,toggleAutoRestart:f,restarting:p,restartMode:v,restartedTo:k,askRestart:R,restartCopy:A,restartFuseMs:U,loadAutoRestartPrefs:L}}function Yie(){const[e,t]=y.useState([]),n=y.useRef(new Set),[r,s]=y.useState(null),[o,l]=y.useState(void 0);y.useEffect(()=>{let h=!0,f=0;const p=()=>{fetch("/api/lan").then(g=>g.ok?g.json():null).then(g=>h?(g!=null&&g.ok&&t(LS(Array.isArray(g.pending)?g.pending:[],g.aliases)),g):null).catch(()=>null).then(g=>{h&&(l(v=>g!=null&&g.ok?g:v===void 0?null:v),f=window.setTimeout(p,(g==null?void 0:g.enabled)===!0?rb:qI))})};return p(),()=>{h=!1,window.clearTimeout(f)}},[]);const c=y.useCallback(async(h,f)=>{if(!r){s(h);try{const g=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:h,fp:f})})).json().catch(()=>null);g&&Array.isArray(g.pending)?t(LS(g.pending,g.aliases)):t(v=>v.filter(N=>N.fp!==f))}catch{}finally{s(null)}}},[r]),d=y.useCallback(h=>{r||(n.current.add(h),t(f=>[...f]))},[r]);return{lanPending:e,lanDeferred:n,lanBusy:r,answerLanPair:c,deferLanPair:d,lanStatus:o}}const Xie=6e4;function Zie({enabled:e,lanStatus:t,now:n}){const[r,s]=y.useState(null),[o,l]=y.useState(()=>new Set),[c,d]=y.useState(null),h=y.useCallback(j=>{j!=null&&j.ok&&Array.isArray(j.accounts)&&s(j.accounts)},[]),f=y.useCallback(async j=>{try{const b=await fetch(`/api/claude-accounts${j?"?refresh=1":""}`);b.ok&&h(await b.json())}catch{}},[h]);y.useEffect(()=>{e&&f(!1)},[e,f]),y.useEffect(()=>{if(!e)return;let j=Date.now();const b=()=>{document.visibilityState!=="visible"||Date.now()-j<Xie||(j=Date.now(),f(!1))};return document.addEventListener("visibilitychange",b),window.addEventListener("focus",b),()=>{document.removeEventListener("visibilitychange",b),window.removeEventListener("focus",b)}},[e,f]);const p=y.useMemo(()=>e?uoe(r,{lan:t,now:n,closed:o}):[],[e,r,t,n,o]),g=y.useRef(p);g.current=p;const v=y.useCallback(j=>{j.length&&l(b=>new Set([...b,...j]))},[]),N=y.useCallback(()=>{const j=g.current;j.length&&(v(j.map(b=>b.id)),fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"reauth-later",incidents:j.map(b=>({key:b.key,since:b.since}))})}).catch(()=>{}))},[v]),k=y.useRef(c);k.current=c;const x=y.useCallback(j=>{const b=k.current;v(doe(b?[b,...g.current]:g.current,j))},[v]);return{rows:p,signingIn:c,observe:h,signIn:d,signedIn:x,refresh:y.useCallback(()=>{f(!0)},[f]),closeSignIn:y.useCallback(()=>d(null),[]),later:N}}const wP="agent-dag.sessionListOpen",vP="agent-dag.accountsPanelOpen";function Jie(){return Qe(wP)==="1"}function Qie(e){Ze(wP,e?"1":"0")}function ele(){const e=Qe(vP);return e===null?!0:e==="1"}function tle(){const[e,t]=y.useState(Jie);y.useEffect(()=>{Qie(e)},[e]);const n=y.useRef(!1),[r,s]=y.useState(()=>{const h=ele();return h&&e?(n.current=!0,!1):h});y.useEffect(()=>{!r&&n.current||Ze(vP,r?"1":"0")},[r]),y.useEffect(()=>{!e&&n.current&&(n.current=!1,s(!0))},[e]);const o=y.useCallback(()=>{t(h=>(h||s(f=>(f&&(n.current=!0),!1)),!h))},[]),l=y.useCallback(()=>{n.current=!1,s(h=>(h||t(!1),!h))},[]),c=y.useCallback(()=>t(!1),[]),d=y.useCallback(()=>s(!1),[]);return{sessionListOpen:e,accountsPanelOpen:r,toggleSessionList:o,toggleAccountsPanel:l,closeSessionList:c,closeAccountsPanel:d}}const xP="agent-dag.detailOpen",bP="agent-dag.usagePanelOpen",kP="agent-dag.systemPanelOpen";function nle(){return Qe(xP)==="1"}function rle(e){Ze(xP,e?"1":"0")}function sle(){const e=Qe(bP);return e===null?!0:e==="1"}function ale(e){Ze(bP,e?"1":"0")}function ole(){const e=Qe(kP);return e===null?!0:e==="1"}function ile(e){Ze(kP,e?"1":"0")}function lle(){const[e,t]=y.useState(nle);y.useEffect(()=>{rle(e)},[e]);const[n,r]=y.useState(sle);y.useEffect(()=>{ale(n)},[n]);const[s,o]=y.useState(ole);return y.useEffect(()=>{ile(s)},[s]),qt("usage-panel",n),qt("machine-panel",s),{detailOpen:e,setDetailOpen:t,usagePanelOpen:n,setUsagePanelOpen:r,machinePanelOpen:s,setMachinePanelOpen:o}}const cle={permission:"your permission",asked:"your answer"},ule="No sessions are waiting for you.";function dle(e){if(e.length===0)return"";const[t,...n]=e,r=t.waiting.kind,s=n.every(l=>l.waiting.kind===r)?cle[r]??"you":"you";if(n.length===0)return`${t.label} is waiting for ${s}.`;const o=`${n.length} more session${n.length===1?"":"s"}`;return`${t.label} and ${o} are waiting for ${s}.`}function px(e,t,n=ule){return t!==""?t:e===""?"":n}function hle({waitingSessions:e,watchUnseen:t,incidents:n=[]}){const[r,s]=y.useState(""),o=dle(e);y.useEffect(()=>{s(g=>px(g,o))},[o]);const[l,c]=y.useState(""),d=t>0?`Browser watch has ${t} unread ${t===1?"finding":"findings"}.`:"";y.useEffect(()=>{c(g=>px(g,d,"Browser watch has no unread findings."))},[d]);const[h,f]=y.useState(""),p=Mie(n);return y.useEffect(()=>{f(g=>px(g,p,$ie))},[p]),{blockedSaid:r,watchSaid:l,setWatchSaid:c,incidentSaid:h}}const fle="/icon-192.png";function ple({waitingSessions:e,liveSince:t,focusSession:n}){const[r,s]=y.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[o,l]=y.useState(null),[c,d]=y.useState(!1),[h,f]=y.useState(!1),p=y.useRef(()=>{}),g=y.useRef(new Set),v=_n(e),N=y.useCallback(()=>{const R=!c;d(R),R&&(g.current=Iu(v.current)),R&&typeof Notification<"u"&&Notification.permission==="default"&&p.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:R})}).then(C=>C.ok?C.json():null).then(C=>{var A;C!=null&&C.ok&&(d(((A=C.prefs)==null?void 0:A.notifications)===!0),f(C.notificationsVetoed===!0))}).catch(()=>{})},[c]),k=typeof Notification<"u";y.useEffect(()=>{if(!o)return;const C=setTimeout(()=>l(null),o==="blocked"?8e3:4e3);return()=>clearTimeout(C)},[o]);const x=y.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(R=>{const C=R;s(C),C==="granted"?l("on"):C==="denied"&&l("blocked")})},[]);p.current=x;const j=y.useRef(null),b=e.map(R=>Qd(R.id,R.waiting)).join("|");y.useEffect(()=>{Zq(j.current,r)&&(j.current=r,g.current=Iu(e))},[r]);const _=y.useRef(!1);y.useEffect(()=>{Jq(_.current,t)&&(_.current=!0,g.current=Iu(e))},[t]),y.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!Qq(j.current,t))return;const R=typeof document>"u"||!document.hidden,C=Yq(e,g.current,R,c);for(const A of C)try{const U=new Notification(A.title,{body:A.body,tag:A.key,icon:fle});U.onclick=()=>{window.focus(),n(A.sessionId),U.close()}}catch{}g.current=R?Iu(e):Xq(e,C,g.current)},[b,t]);const E=y.useCallback(R=>{var C;d(((C=R.prefs)==null?void 0:C.notifications)===!0),f(R.notificationsVetoed===!0)},[]);return{notifyPermission:r,notifySaid:o,notifyOn:c,notifyVetoed:h,toggleNotify:N,notifySupported:k,askForNotifications:x,loadNotifyPrefs:E}}function mle({openedTool:e,usageHistoryOpen:t,contextFor:n,tourOpen:r,summaryFor:s,browserWatchOpen:o,keyHelpOpen:l,releaseNotes:c,feedbackOpen:d}){const h=_n(l),f=y.useRef(!1);return f.current=e!=null||t||n!=null||r||s!=null||o||l||c!=null||d,{keyHelpOpenRef:h,modalOpenRef:f}}function gle({stateRef:e,tourOpen:t,releaseNotes:n}){const[r,s]=y.useState(null),o=y.useCallback((F,O)=>s({agentId:F,toolId:O}),[]),[l,c]=y.useState(null),[d,h]=y.useState(null),f=y.useCallback(F=>h(F),[]),[p,g]=y.useState(!1),[v,N]=y.useState(!1),[k,x]=y.useState(!1),[j,b]=y.useState(!1),[_,E]=y.useState(null),R=y.useCallback(F=>{E(F??null),b(!0)},[]);qt("tool-detail",r!==null),qt("session-summary",l!==null),qt("context-window",d!==null),qt("keyboard-help",p),qt("usage-history",v),qt("browser-watch",k),qt("feedback",j);const C=r?K8(e.current.agents,r.agentId,r.toolId):null,A=d?e.current.agents.get(d):void 0,{keyHelpOpenRef:U,modalOpenRef:L}=mle({openedTool:C,usageHistoryOpen:v,contextFor:d,tourOpen:t,summaryFor:l,browserWatchOpen:k,keyHelpOpen:p,releaseNotes:n,feedbackOpen:j});return{setOpenedToolKey:s,openTool:o,openedTool:C,summaryFor:l,setSummaryFor:c,contextFor:d,setContextFor:h,openContext:f,contextAgent:A,keyHelpOpen:p,setKeyHelpOpen:g,usageHistoryOpen:v,setUsageHistoryOpen:N,browserWatchOpen:k,setBrowserWatchOpen:x,feedbackOpen:j,setFeedbackOpen:b,feedbackPrefill:_,setFeedbackPrefill:E,openFeedback:R,keyHelpOpenRef:U,modalOpenRef:L}}function yle({stateRef:e,pinnedRef:t,measuredRef:n,positionsRef:r,lastLayoutSigRef:s,forgetRemovals:o,clearSelection:l,rerender:c,modalOpenRef:d}){const[h,f]=y.useState(!1),p=y.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}e.current=Yb(),t.current.clear(),n.current.clear(),r.current.clear(),s.current="",IL(),o(),l(),c()},[c,l,o]),g=_n(h),v=y.useCallback(N=>{const k=Fse(N,{confirmOpen:g.current,modalOpen:d.current});k==="confirm"?f(!0):k==="clear"&&(f(!1),p())},[p]);return{clearConfirmOpen:h,setClearConfirmOpen:f,requestClear:v}}const wM="agent-dag.oldNameNoticeDismissed";function wle(e){const[t,n]=y.useState(()=>Qe(wM)??""),r=e!=null&&e.invokedAs&&e.invokedAs!==kt?e.invokedAs:null,s=r!=null&&t!==r,o=y.useCallback(()=>{r&&(n(r),Ze(wM,r))},[r]);return{oldName:r,oldNameOpen:s,dismissOldName:o}}const vle=300*1e3,xle=1800*1e3,ble=8e3,kle=3e4;function vM(e){return fetch("/api/rating",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)}).catch(()=>null)}function Nle({modalOpenRef:e}){const t=y.useCallback(()=>k$({appModal:e.current,dialogDepth:ds.dialogDepth()}),[e]),[n,r]=y.useState("hidden"),[s,o]=y.useState(null),[l,c]=y.useState(!1),d=y.useRef(n);d.current=n,y.useEffect(()=>{let v=!1;const N=async()=>{if(d.current==="thanks"||d.current==="hidden"&&(document.hidden||t()))return;const j=await fetch("/api/rating").then(b=>b.ok?b.json():null).catch(()=>null);v||!j||r(b=>b==="thanks"?b:j.ask===!0?"asking":"hidden")},k=window.setTimeout(N,vle),x=window.setInterval(N,xle);return()=>{v=!0,window.clearTimeout(k),window.clearInterval(x)}},[t]),y.useEffect(()=>{if(n!=="thanks"||l)return;const v=s!==null&&s<=6?kle:ble;let N=0;const k=()=>{t()?N=window.setTimeout(k,v):r("hidden")};return N=window.setTimeout(k,v),()=>window.clearTimeout(N)},[n,s,l,t]);const h=y.useCallback(v=>{o(v),c(!1),r("thanks"),vM({score:v})},[]),f=y.useCallback(v=>c(v),[]),p=y.useCallback(()=>{r("hidden"),vM({later:!0})},[]),g=y.useCallback(()=>r("hidden"),[]);return{ratingPhase:n,ratingScore:s,answerRating:h,rateLater:p,closeRating:g,holdThanks:f}}function jle({chimesRef:e,setTonePrefs:t,tonePrefsRef:n,previewTone:r}){const[s,o]=y.useState(()=>oZ(Qe)),l=_n(s),[c,d]=y.useState([]),h=y.useCallback(b=>{o(_=>{const E={..._,[b]:null};return l.current=E,E}),hs(Il[b])},[]),f=y.useCallback((b,_)=>{const E=l.current[b];_&&E!==_||(h(b),t(R=>{const C={...R,[b]:{...R[b],figure:jn}};return n.current=C,C}),Ze(Id[b],jn))},[h]),p=_n(f);y.useEffect(()=>{let b=!0;return yZ().then(_=>{if(!b)return;d(_);const E=new Set(_.map(R=>R.id));for(const R of ad){const C=l.current[R];C&&!E.has(C)&&p.current(R,C)}},()=>{}),()=>{b=!1}},[]);const g=y.useCallback((b,_)=>{if(!c.some(R=>R.id===_))return;const E={...l.current,[b]:_};l.current=E,o(E),Ze(Il[b],_),r(b,!0)},[c,r]),v=y.useCallback(async b=>{var C;const _=ub(c.length);if(_)throw new Error(_);const E=window.AudioContext??window.webkitAudioContext;if(!E)throw new Error("This browser cannot decode audio files.");const R=new E;try{const A=await hZ(b,L=>R.decodeAudioData(L));await u_(A);const U=tc(A);d(L=>[...L.filter(F=>F.id!==U.id),U])}finally{(C=R.close)==null||C.call(R)}},[c.length]),N=y.useCallback(async b=>{const _=ub(c.length);if(_)throw new Error(_);const E=fZ(b);await u_(E);const R=tc(E);d(C=>[...C.filter(A=>A.id!==R.id),R])},[c.length]),k=y.useCallback(async(b,_)=>{const E=c.find(C=>C.id===b),R=_.trim().slice(0,80);!E||!R||R===E.name||(await vZ(b,R),d(C=>C.map(A=>A.id===b?{...A,name:R}:A)))},[c]),x=y.useCallback(async b=>{await xZ(b),d(C=>C.filter(A=>A.id!==b));const _=l.current,E=iZ(_,b);l.current=E,o(E);const R=ad.filter(C=>_[C]===b);for(const C of R)hs(Il[C]),Ze(Id[C],jn);R.length>0&&t(C=>{const A={...C};for(const U of R)A[U]={...A[U],figure:jn};return n.current=A,A})},[]),j=y.useCallback(b=>{var R,C;const _=ad.find(A=>l.current[A]===b),E=_?n.current[_].level:Qa;(R=e.current)==null||R.unlock(),(C=e.current)==null||C.previewCustom(b,E)},[]);return{customSelections:s,customSelectionsRef:l,customAssets:c,clearCustomOnly:h,fallbackCustomRef:p,selectCustomTone:g,importNotificationAudio:v,createNotificationVoice:N,renameCustomAsset:k,deleteCustomAsset:x,previewCustomAsset:j}}function Sle(e){const[t,n]=y.useState(()=>MZ(Qe)),r=_n(t),s=y.useRef(null),o=y.useCallback((c,d=!1)=>{var h,f;if((h=e.current)==null||h.unlock(),s.current!==null&&clearTimeout(s.current),s.current=null,!d){(f=e.current)==null||f.play(c,!0);return}s.current=setTimeout(()=>{var p;s.current=null,(p=e.current)==null||p.play(c,!0)},EZ)},[]),l=y.useCallback((c,d)=>{n(h=>{const f={level:vi(d.level??h[c].level),figure:yO(c,d.figure??h[c].figure)};return Ze(xO[c],String(f.level)),Ze(Id[c],f.figure),{...h,[c]:f}}),o(c,!0)},[o]);return y.useEffect(()=>()=>{s.current!==null&&clearTimeout(s.current)},[]),{tonePrefs:t,setTonePrefs:n,tonePrefsRef:r,previewTone:o,changeTone:l}}const _le=15e3;function Ele(e){return e.visibilityState==="visible"&&e.hasFocus()}function Tle(e,t){return t||e===!0}function Cle(){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 Ale(){y.useEffect(()=>{const e=Cle();let t=null;const n=l=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:e,looking:l}),keepalive:!0}).catch(()=>{})},r=()=>{const l=Ele(document);Tle(t,l)&&n(l),t=l},s=()=>{t&&n(!1),t=!1};r();const o=window.setInterval(r,_le);return window.addEventListener("focus",r),window.addEventListener("blur",r),document.addEventListener("visibilitychange",r),window.addEventListener("pagehide",s),()=>{window.clearInterval(o),window.removeEventListener("focus",r),window.removeEventListener("blur",r),document.removeEventListener("visibilitychange",r),window.removeEventListener("pagehide",s),s()}},[])}function Rle({loadAutoRestartPrefs:e,loadNotifyPrefs:t,loadReportsPrefs:n}){y.useEffect(()=>{let r=!0;return fetch("/api/prefs").then(s=>s.ok?s.json():null).then(s=>{!r||!(s!=null&&s.ok)||(e(s),t(s),n(s))}).catch(()=>{}),()=>{r=!1}},[])}const mx="agent-dag.versionNoticeDismissed",Mle=15*6e4;function $le(e){const[t,n]=y.useState(null),[r,s]=y.useState(()=>Qe(mx)??""),o=y.useRef(0),[l,c]=y.useState(!1),d=y.useCallback((k=!1)=>(k&&(o.current=Date.now(),c(!0)),fetch(k?"/api/version?refresh=1":"/api/version").then(x=>x.ok?x.json():null).then(x=>{x&&n(x)}).catch(()=>{}).finally(()=>{k&&c(!1)})),[]),h=y.useCallback(()=>{d(Date.now()-o.current>=Mle)},[d]);y.useEffect(()=>{d();const k=window.setInterval(h,5*6e4),x=()=>{document.visibilityState==="visible"&&h()};return document.addEventListener("visibilitychange",x),()=>{window.clearInterval(k),document.removeEventListener("visibilitychange",x)}},[d,h]),y.useEffect(()=>{e&&d()},[e,d]);const f=(t==null?void 0:t.notice)??null,p=VL(f),g=ise(f,r),v=y.useCallback(()=>{s(""),Ze(mx,"")},[]),N=y.useCallback(()=>{f&&(s(p),Ze(mx,p))},[f,p]);return{version:t,notice:f,noticeOpen:g,showNotice:v,dismissNotice:N,versionChecking:l,loadVersion:d}}function Ile({version:e,readyAppUpdate:t}){const[n,r]=y.useState(!1),s=y.useRef(null),[o,l]=y.useState(null),c=o&&t?t.version:null,d=y.useRef(null);y.useEffect(()=>{!c||d.current===c||(d.current=c,fetch("/api/desktop-update/seen",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:c})}).catch(()=>{}))},[c]);const h=y.useRef(!1);y.useEffect(()=>{if(h.current)return;const x=Ml(),j=Moe(x),b=Doe({stored:j,running:(e==null?void 0:e.running)??null,notes:aM,remembers:$oe(x)});if(b.reason==="no-version")return;h.current=!0,b.record&&Ioe(x,b.record);let _=!0;return(async()=>{var U;let R=Ooe(x);if(ac())try{const L=await fetch("/api/prefs");if(!L.ok)throw new Error("desktop tour preferences unavailable");const F=await L.json();if(!(F!=null&&F.ok))throw new Error("desktop tour preferences unavailable");const O=((U=F.prefs)==null?void 0:U.tourSeen)===!0;R&&!O&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{}),R=R||O}catch{R=!0}if(!_)return;const C=Poe({tourSeen:R,decision:b}),A=b.show.length?{entries:b.show,since:j,firstRun:!1}:null;C.tour&&r(!0),C.notes==="now"?l(A):C.notes==="after"&&(s.current=A)})(),()=>{_=!1}},[e==null?void 0:e.running]);const f=(e==null?void 0:e.running)??"3.38.1",p=y.useMemo(()=>iP(aM,null,f),[f]),g=y.useCallback(()=>{l({entries:p,since:null,firstRun:!1})},[p]),v=y.useCallback(()=>r(!0),[]),N=y.useCallback(()=>l(null),[]),k=y.useCallback(()=>{r(!1),Loe(Ml()),ac()&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{});const x=s.current;s.current=null,x&&l(x)},[]);return{tourOpen:n,openTour:v,closeTour:k,releaseNotes:o,closeReleaseNotes:N,chipVersion:f,openReleaseNotes:g}}function Ole(){const[e,t]=y.useState(void 0),[n,r]=y.useState(!1),s=y.useRef(!1);return s.current=e===!0&&!n,y.useEffect(()=>lie(()=>s.current),[]),{loadReportsPrefs:y.useCallback(l=>{var c;t(((c=l.prefs)==null?void 0:c.reports)!==!1),r(l.reportsVetoed===!0)},[])}}function Lle(){const[e,t]=y.useState(null),[n,r]=y.useState(!1),s=y.useRef(null);return y.useEffect(()=>{let o=!0,l=!1,c=null,d=null,h="";const f=k=>{o&&(r(!0),k!==h&&t(null))},p=()=>{if(l)return;l=!0,c=Date.now();const k=VR();d=k,fetch(`/api/ccusage?since=${k}`).then(x=>x.ok?x.json():null).then(x=>{if(o){if(!(x!=null&&x.ok)){f(k);return}h=k,t(Yre(x)),r(!1)}}).catch(()=>f(k)).finally(()=>{l=!1})},g=()=>{const k=s.current;Kre({shown:!!k&&k.getClientRects().length>0,tabVisible:document.visibilityState==="visible",lastSince:d,since:VR(),lastReadAt:c,now:Date.now()})&&p()};g();const v=window.setInterval(g,Gre);document.addEventListener("visibilitychange",g);let N=null;return s.current&&typeof ResizeObserver<"u"&&(N=new ResizeObserver(g),N.observe(s.current)),()=>{o=!1,window.clearInterval(v),document.removeEventListener("visibilitychange",g),N==null||N.disconnect()}},[]),{monthlyUsage:e,monthlyUsageUnavailable:n,monthUsageRef:s}}function Ple(e){const[t,n]=y.useState(null);y.useEffect(()=>{const c=Qe("agent-dag.sound");n(c===null?!0:c==="on")},[]);const r=y.useCallback(()=>{n(c=>{var h,f;const d=c!==!0;return Ze("agent-dag.sound",d?"on":"off"),d?(h=e.current)==null||h.unlock():(f=e.current)==null||f.silence(),d})},[]),s=y.useCallback(c=>{r()},[r]),o=_n(s),l=_n(t);return{soundOn:t,toggleSound:r,activateSoundRef:o,soundOnRef:l}}function Dle(){const[e,t]=y.useState(!1),n=y.useRef(null),[r,s]=y.useState(!1),o=y.useRef(null);return y.useEffect(()=>{e&&s(!1)},[e]),{soundMenuOpen:e,setSoundMenuOpen:t,soundButtonRef:n,appearanceMenuOpen:r,setAppearanceMenuOpen:s,appearanceButtonRef:o}}const Fle="agent-dag.autoFitDisabled";function Ble(e){const t=y.useRef(!1),[n,r]=y.useState(!1);y.useEffect(()=>{hs(Fle)},[]);const s=y.useCallback(()=>{t.current||(t.current=!0,r(!0))},[]),o=y.useCallback(()=>{t.current=!1,r(!1),e(400)},[e]);return{autoFitDisabled:n,autoFitDisabledRef:t,disableAutoFit:s,enableAutoFitAndRefit:o}}function qle(){return a.jsx(Vb,{children:a.jsx(die,{children:a.jsx(Ule,{})})})}function Ule(){const e=ki(),t=y.useState(Yb)[0],n=y.useRef(t),[,r]=y.useState(0),s=y.useCallback(()=>r(ba=>ba+1),[]),{detailOpen:o,setDetailOpen:l,usagePanelOpen:c,setUsagePanelOpen:d,machinePanelOpen:h,setMachinePanelOpen:f}=lle(),{selectedIds:p,primarySelectedId:g,selectAgent:v,clearSelection:N,pruneSelectionToBoard:k}=XZ(n,l),{sessionListOpen:x,accountsPanelOpen:j,toggleSessionList:b,toggleAccountsPanel:_,closeSessionList:E,closeAccountsPanel:R}=tle(),C=Lle(),A=td(j,200),U=td(c,130),L=td(h,130),F=y.useRef(null),O=Ple(F),{activateSoundRef:I,soundOnRef:B}=O,M=Sle(F),{setTonePrefs:$,tonePrefsRef:P,previewTone:G}=M,K=jle({chimesRef:F,setTonePrefs:$,tonePrefsRef:P,previewTone:G}),{customSelectionsRef:q,fallbackCustomRef:H}=K,D=Dle(),{setSoundMenuOpen:W}=D,{chimeState:J}=Hie({chimesRef:F,soundOnRef:B,tonePrefsRef:P,customSelectionsRef:q,fallbackCustomRef:H}),V=pie(n),{pauseGate:X,paused:Y,togglePause:Z}=V,ee=y.useRef(()=>{}),{live:ne,tabCapped:se,everConnected:pe,liveSince:ke}=BZ({stateRef:n,rerender:s,pauseGate:X,chimesRef:F,desktopUpdateRef:ee}),ae=$le(ne),{version:fe,notice:me,noticeOpen:he,loadVersion:ge}=ae,ue=Gie(ne),{readyAppUpdate:be,onDesktopUpdateEvent:oe}=ue;ee.current=oe,Ale();const je=Ile({version:fe,readyAppUpdate:be}),{tourOpen:$e,openTour:Oe,releaseNotes:Ue}=je,{workspace:Be,providers:We,providersRef:He}=gie(ne),rt=wle(fe),lt=Iie({version:fe,loadVersion:ge}),{upgradeFailure:Rt}=lt,De=gle({stateRef:n,tourOpen:$e,releaseNotes:Ue}),et=Nle({modalOpenRef:De.modalOpenRef}),{openTool:Je,setSummaryFor:tt,setContextFor:yt,openContext:Pt,setKeyHelpOpen:wt,setUsageHistoryOpen:st,setBrowserWatchOpen:zt,keyHelpOpenRef:Wt,modalOpenRef:Dt}=De,Ht=Ole(),Vt=Lie(),{watchOn:vs,watchUnseen:Cn}=Vt,mr=Yie(),[zr,gr]=y.useState(0),{presentCats:Wr,hiddenCats:mn,toggleCat:Hr,catBarRef:An,catBarOccluded:da}=zie(n),gn=y.useRef(null),[yr,wr]=y.useState(0),xt=ZZ({stateRef:n,rerender:s,pruneSelectionToBoard:k,setContextFor:yt,setSummaryFor:tt}),xs=xie(We.claude||We.codex),vr=Rie(xs,xt),xr=Zie({enabled:We.claude,lanStatus:mr.lanStatus,now:xt}),Gt=Kie({now:xt,stateRef:n,version:fe,notice:me,noticeOpen:he,upgradeFailure:Rt,paused:V.paused}),{askRestart:bs,loadAutoRestartPrefs:Vr}=Gt,ye=Uie(),{setTheme:Fe,palette:Ge}=ye,rn=Vie(),Gr=Yte(),{applyViewport:br,moveCamera:ha,fitLeft:Ke,cameraEpochRef:Kr,lastFitTimeRef:ks}=Gr,kr=ine(Ke),{pinnedRef:Kn,positionsRef:Yr,lastLayoutSigRef:ao,handleRelayout:Ns}=kr,Jt=y.useRef(null),js=y.useRef(()=>{}),yn=ke!==null,xc=y.useRef(0),bc=y.useCallback(()=>{xc.current=Date.now()},[]),{canvasRef:Nr,canvasSize:oo,paneSizeRef:io}=Fne(),Ss=Ble(Ke),{autoFitDisabledRef:fa,disableAutoFit:Mi}=Ss,$i=y.useRef(!1),{measuredRef:Yn,measuredVersionRef:kc,sizeVersion:Ii,domSizeVersion:pa}=Bne($i),{removedNodes:Nc,removedAgentIds:jr,removeNode:Ye,removeSelectedNode:Oi,removalNotice:Li,bringBack:ma,bringBackAll:jc,forgetRemovals:Sc}=Tne({stateRef:n,pinnedRef:Kn,positionsRef:Yr,canvasRef:Nr,clearSelection:N,primarySelectedId:g}),lo=Nne({stateRef:n,now:xt,removedAgentIds:jr,sizeVersion:Ii,domSizeVersion:pa});lne(lo,kr),Ene({layoutSig:lo,rf:e,stateRef:n,measuredRef:Yn,pinnedRef:Kn,positionsRef:Yr,paneSizeRef:io,lastInteractRef:xc,autoFitDisabledRef:fa,lastFitTimeRef:ks,fitLeft:Ke});const co=qne(),{bubbling:uo,endBubble:Sr,onBubble:_r}=WX(),[Rn,ga]=y.useState(!1),_s=UX(),{beginTrashDrag:Er,trackTrashDrag:Lh,endTrashDrag:_c}=_s,Es=QX({stateRef:n,measuredRef:Yn,measuredVersionRef:kc,canvasRef:Nr}),{lodRef:Ph,applyZoom:Ec}=Es,ya=Pne({applyViewport:br,lastFitTimeRef:ks,cameraEpochRef:Kr,disableAutoFit:Mi,markInteract:bc,canvasRef:Nr,applyZoom:Ec}),Ts=g?n.current.agents.get(g):null,Pi=o&&Ts!=null,wn=Hne({sessionListShown:x,usageShown:La(U),machineShown:La(L),accountsShown:La(A)&&We.claude,detailShown:Pi,primarySelectedId:g,canvasRef:Nr}),{railInsetRef:Cs,availableWidth:Xr,availableHeight:wa}=Kte({canvasRef:Nr,canvasSize:oo,machinePhase:L,usagePhase:U,usagePanelOpen:c,detailShown:Pi}),Tc=jne({stateRef:n,now:xt,availableWidth:Xr,availableHeight:wa,layout:kr,measuredRef:Yn,onBubble:_r,settled:co,dragging:Rn,layoutSig:lo,selectedIds:p,openContext:Pt,historyReplayed:yn,removedNodes:Nc,removedAgentIds:jr,dragTick:zr,dragPatchRef:gn,dragMoveTick:yr}),{nodes:Di,edges:Fi}=Tc,As=_n(g);cne({nodes:Di,edges:Fi,settled:co,dragging:Rn,availableWidth:Xr,availableHeight:wa,layout:kr,camera:Gr,rf:e,measuredRef:Yn,stateRef:n,lastFocusRef:Jt,primarySelectedIdRef:As,focusAgentRef:js,autoFitDisabledRef:fa});const ho=yle({stateRef:n,pinnedRef:Kn,measuredRef:Yn,positionsRef:Yr,lastLayoutSigRef:ao,forgetRemovals:Sc,clearSelection:N,rerender:s,modalOpenRef:Dt}),{requestClear:Bi}=ho,Tr=Vne({nodes:Di,stateRef:n,pinnedRef:Kn,positionsRef:Yr,draggingRef:$i,dragPatchRef:gn,setDragging:ga,setDragMoveTick:wr,setDragTick:gr,endBubble:Sr,markInteract:bc,disableAutoFit:Mi,beginTrashDrag:Er,trackTrashDrag:Lh,endTrashDrag:_c,removeNode:Ye}),qi=y.useCallback(()=>Ke(500),[Ke]),Rs=_n(Di),{focusAgent:va,stepAgent:fo,focusSession:Cr}=Zte({canvasRef:Nr,stateRef:n,measuredRef:Yn,nodesRef:Rs,railInsetRef:Cs,moveCamera:ha,disableAutoFit:Mi,lastFocusRef:Jt,focusAgentRef:js,selectAgent:v,primarySelectedIdRef:As}),Cc=Dne({clearSelection:N,selectAgent:v,detailOpen:o,setDetailOpen:l,detailShown:Pi,focusAgent:va,draggingRef:$i,lodRef:Ph}),Qt=Jte({nodesRef:Rs,stateRef:n,canvasRef:Nr,railInsetRef:Cs}),Ms=_n(Oi),po=y.useRef(null),xa=y.useCallback(ba=>{jr.has(ba)&&ma([ba]),Cr(ba)},[jr,ma,Cr]),Dh=Une();zne({pointerFocusRef:Dh,nodesRef:Rs,stateRef:n,primarySelectedIdRef:As,providersRef:He,soundOnRef:B,keyHelpOpenRef:Wt,modalOpenRef:Dt,waitingCursorRef:po,removeSelectedRef:Ms,activateSoundRef:I,clearSelection:N,selectAgent:v,focusAgent:va,stepAgent:fo,focusSession:Cr,requestClear:Bi,handleRelayout:Ns,handleFit:qi,togglePause:Z,toggleSessionList:b,toggleAccountsPanel:_,setDetailOpen:l,setUsageHistoryOpen:st,setUsagePanelOpen:d,setMachinePanelOpen:f,setBrowserWatchOpen:zt,setSoundMenuOpen:W,setKeyHelpOpen:wt,setTheme:Fe});const mo=n.current.agents.size,Zr=y.useMemo(()=>Ix(n.current.agents.values()),[n.current,n.current.revision]);Cne({stateRef:n,waitingSessions:Zr,removedAgentIds:jr,removedNodes:Nc,bringBack:ma}),Ine({stateRef:n,waitingSessions:Zr,live:ne});const $s=hle({waitingSessions:Zr,watchUnseen:Cn,incidents:vr}),Is=ple({waitingSessions:Zr,liveSince:ke,focusSession:Cr}),{loadNotifyPrefs:Ac}=Is;return Rle({loadAutoRestartPrefs:Vr,loadNotifyPrefs:Ac,loadReportsPrefs:Ht.loadReportsPrefs}),a.jsxs("div",{className:"app",children:[a.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),a.jsxs("header",{className:"topbar",children:[a.jsx(fse,{versionCheck:ae,welcome:je,desktopUpdate:ue,pause:V,monthly:C,announcements:$s,notify:Is,waitingSessions:Zr,waitingCursorRef:po,focusSession:Cr,live:ne,now:xt,incidents:vr}),Ts&&a.jsx(pse,{selected:Ts,now:xt,selectedIds:p,focusAgent:va,clearSelection:N}),a.jsxs("div",{className:"actions",children:[a.jsx(zre,{sessionListOpen:x,toggleSessionList:b,usagePanelOpen:c,setUsagePanelOpen:d,setUsageHistoryOpen:st,toggles:wn.toggles}),a.jsx(Wre,{providers:We,accountsPanelOpen:j,toggleAccountsPanel:_,machinePanelOpen:h,setMachinePanelOpen:f,watchOn:vs,watchUnseen:Cn,setBrowserWatchOpen:zt,toggles:wn.toggles}),a.jsx(Hre,{providers:We,sound:O,tones:M,customTones:K,notify:Is,chimeState:J,menus:D,appearance:ye,fm:rn,onFeedback:()=>De.openFeedback(),watchUnseen:Cn,setUsageHistoryOpen:st,setBrowserWatchOpen:zt})]})]}),a.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Li?`${Li.label} removed from the board.`:""}),a.jsx(Dse,{restart:Gt,versionCheck:ae,upgrade:lt,oldNameNotice:rt,rating:et,onFeedback:De.openFeedback,everConnected:pe,live:ne,paused:Y}),La(A)&&We.claude&&a.jsx(OX,{leaving:A==="leaving",onReport:De.openFeedback,onRoster:xr.observe,onClose:()=>{wn.accounts(),R()}}),x&&a.jsx(WH,{state:n.current,now:xt,selectedIds:p,onSelect:xa,onClose:()=>{wn.sessionList(),E()},removedIds:jr,onBringBackAll:jc}),a.jsxs(vse,{canvasRef:Nr,bubbling:uo,dragging:Rn,trash:_s,zoom:Es,viewport:ya,stateRef:n,peek:Qt,children:[mo===0&&(!ne&&se?a.jsx(ere,{}):a.jsx(tre,{live:ne,everConnected:pe,providers:We,workspace:Be,onTour:Oe})),(Wr.length>1||mn.size>0)&&a.jsx(mse,{catBarRef:An,catBarOccluded:da,presentCats:Wr,hiddenCats:mn,toggleCat:Hr}),a.jsx(EH,{graph:Tc,layout:kr,viewport:ya,clicks:Cc,drag:Tr,appearance:ye,fm:rn,autoFit:Ss,pause:V,stateRef:n,measuredRef:Yn,hiddenCats:mn,now:xt,openTool:Je,focusAgent:va,requestClear:Bi,setKeyHelpOpen:wt})]}),La(U)&&a.jsx(F7,{state:n.current,now:xt,providers:We,incidents:vr,liveSince:ke,leaving:U==="leaving",onClose:()=>{wn.usage(),d(!1)}}),La(L)&&a.jsx(k9,{usageOpen:c,leaving:L==="leaving",onClose:()=>{wn.machine(),f(!1)}}),o&&Ts?a.jsx(pre,{selected:Ts,now:xt,openTool:Je,setSummaryFor:tt,stateRef:n,removeSelectedNode:Oi,onClose:()=>{wn.detail(),l(!1)}}):null,a.jsx(Goe,{dialogs:De,welcome:je,desktopUpdate:ue,versionCheck:ae,restart:Gt,lanPairs:mr,attention:xr,clearFlow:ho,watchBadge:Vt,announcements:$s,appearance:ye,providers:We,stateRef:n,agentCount:mo})]})}try{RU(window.localStorage)}catch{}const zle=r4.createRoot(document.getElementById("root"));zle.render(a.jsx(qle,{}));export{Yne as a,it as b,oa as c,gt as d,is as e,qe as f,Vle as g,Dr as h,Hle as i,a as j,Ql as k,Tn as l,uZ as m,ea as n,eo as o,Vx as p,y as r,lr as s,ut as u};
|