agent-dag 1.34.4 → 1.34.6
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.
|
@@ -58,7 +58,7 @@ Error generating stack: `+x.message+`
|
|
|
58
58
|
`)}function Sv(e,n,r){const i=(n??r)-e;if(i<1e3)return`${Math.max(0,i)}ms`;const o=Math.floor(i/1e3);if(o<60)return`${o}s`;const l=Math.floor(o/60),u=o%60;return`${l}m ${String(u).padStart(2,"0")}s`}function zP({data:e,selected:n}){var h;const r=e.now??Date.now(),i=["agent-node",`state-${e.state}`,e.synthetic?"synthetic":"",n?"selected":""].filter(Boolean).join(" "),o=e.tools.filter(p=>!p.endedAt).length,l=Kv(e.sessionId),u=((h=e.context)==null?void 0:h.currentContextTokens)??0,c=e.kind==="root"&&u>0;return g.jsxs("div",{className:i,style:{"--session-hue":l},children:[g.jsx("span",{className:"accent-stripe"}),g.jsx(vo,{type:"target",position:Ae.Left,style:{background:"transparent",border:"none"}}),g.jsxs("div",{className:"head",children:[g.jsxs("div",{className:"title",children:[g.jsx(BP,{state:e.state}),g.jsx("span",{className:"label",title:e.cwd,children:e.label}),e.synthetic&&g.jsx("span",{className:"synth-tag",title:"No SessionStart captured — synthesised",children:"?"})]}),g.jsxs("div",{className:"head-right",children:[c&&e.onOpenContext&&g.jsx(DP,{currentContextTokens:u,modelId:e.model,contextWindow:e.contextWindow,onClick:()=>e.onOpenContext(e.sessionId)}),g.jsx("div",{className:"time",title:`Started ${new Date(e.startedAt).toLocaleTimeString()}`,children:Sv(e.startedAt,e.endedAt,r)})]})]}),g.jsxs("div",{className:"sub",children:[e.kind==="root"?"session":"subagent",e.childCount>0&&g.jsxs("span",{className:"spawn-badge",title:`${e.childCount} subagents spawned`,children:["→ ",e.childCount]}),e.cwdBasename&&e.kind==="subagent"?` · ${e.cwdBasename}`:"",e.model&&g.jsx("span",{className:"model-chip",title:e.model,children:li(e.model)})]}),e.waiting&&g.jsx(HP,{waiting:e.waiting,now:r}),e.tools.length>0&&g.jsx(VP,{tools:e.tools,now:r}),g.jsxs("div",{className:"meta",children:[g.jsxs("span",{children:[g.jsx("b",{children:e.toolCount})," tools"]}),o>0&&g.jsxs("span",{className:"inflight-meta",children:[g.jsx("b",{children:o})," in-flight"]}),e.usage.inputTokens+e.usage.outputTokens>0&&g.jsxs("span",{className:"tokens-meta",title:`in:${e.usage.inputTokens} out:${e.usage.outputTokens} cache-r:${e.usage.cacheReadTokens} cache-c:${e.usage.cacheCreateTokens}${(e.usage.reasoningOutputTokens??0)>0?` reasoning:${e.usage.reasoningOutputTokens}`:""}`,children:[g.jsx("b",{children:WP(e.usage.inputTokens+e.usage.outputTokens)})," tok"]}),e.model&&Xv(e.model)&&(()=>{const p=fn(e.usage,e.model);if(p.total<=0)return null;const d=Math.max(0,((e.endedAt??r)-e.startedAt)/1e3),m=e.state==="active"?_u(p.total,d):null,y=FP(e.usage,e.model)+(m?`
|
|
59
59
|
burn: ${m}`:"");return g.jsxs("span",{className:"cost-meta",title:y,children:[g.jsx("b",{children:ze(p.total)}),m&&g.jsx("span",{className:"cost-rate",children:m})]})})()]}),g.jsx(vo,{type:"source",position:Ae.Right,style:{background:"transparent",border:"none"}})]})}function Zv(e){return e==="active"?"live":e==="done"?"done":"err"}function BP({state:e}){return g.jsx("span",{className:`state-pill state-${e}`,children:Zv(e)})}function Iu(e){return e.message?e.message:e.kind==="permission"?"Needs your permission":"Waiting for your input"}function UP(e){return e.kind==="permission"?Iu(e):"Your turn"}function HP({waiting:e,now:n}){const r=e.kind==="permission",i=Iu(e);return g.jsxs("div",{className:r?"waiting-row permission":"waiting-row idle",title:`${i}
|
|
60
60
|
Blocked for ${Sv(e.since,void 0,n)} — the answer goes in the terminal, not here.`,children:[r?g.jsx("span",{className:"ap-pulse","aria-hidden":!0}):g.jsx("span",{className:"waiting-dot","aria-hidden":!0}),g.jsx("span",{className:"waiting-said",children:UP(e)}),g.jsx("b",{children:Sv(e.since,void 0,n)})]})}function WP(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function VP({tools:e,now:n}){const l=new Array(24).fill(0);let u=0;for(const y of e){const w=n-y.startedAt;if(w<0||w>=6e4)continue;const N=23-Math.floor(w/2500);N>=0&&N<24&&(l[N]+=1,u+=1)}const c=Math.max(1,...l),h=132,p=14,d=h/24,m=c/(2500/1e3);return g.jsxs("div",{className:"tool-spark-row",title:`${u} tool calls in last 60s · peak ${m.toFixed(1)}/s`,children:[g.jsx("svg",{className:"tool-spark",width:h,height:p,viewBox:`0 0 ${h} ${p}`,"aria-hidden":!0,children:l.map((y,w)=>{const N=y===0?1.5:Math.max(1.5,y/c*p),_=w===23&&y>0,S=`tool-spark-bar${y>0?" active":""}${_?" latest":""}`;return g.jsx("rect",{x:w*d+.4,y:p-N,width:Math.max(.5,d-1),height:N,rx:.8,className:S},w)})}),g.jsx("span",{className:"tool-spark-label",children:"60s"})]})}function li(e){const n=e.replace(/^anthropic\./,"").replace(/[-_]\d{8}(?!\d)/,""),r=n.match(/^claude[-_](opus|sonnet|haiku|fable|mythos)[-_](\d+(?:[-_.]\d+)*)/i);if(r){const l=r[1][0].toUpperCase()+r[1].slice(1).toLowerCase(),u=r[2].replace(/[-_]/g,".");return`${l} ${u}`}const i=n.match(/^gpt[-_](\d+(?:[-_.]\d+)*)[-_]codex\b/i);if(i)return`GPT-${i[1].replace(/[-_]/g,".")} Codex`;const o=n.match(/^gpt[-_](\d+(?:[-_.]\d+)*)/i);return o?`GPT-${o[1].replace(/[-_]/g,".")}`:e}function qx(e){if(e==null)return"(none)";if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function GP(e){if(e.endedAt==null)return"in-flight…";const n=e.endedAt-e.startedAt;return n<1e3?`${n}ms`:`${(n/1e3).toFixed(2)}s`}function YP({tool:e,onClose:n}){const r=xo(n),i=e.endedAt==null?"inflight":e.ok===!1?"err":"done";return g.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:g.jsxs("div",{ref:r,className:"modal",onClick:o=>o.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"tool-modal-title",children:[g.jsxs("header",{className:"modal-head",children:[g.jsxs("div",{className:"modal-title",children:[g.jsx("span",{className:`status-dot ${i}`,"aria-hidden":!0}),g.jsx("span",{id:"tool-modal-title",className:"modal-tool-name",children:e.name}),g.jsxs("span",{className:"modal-tool-id",title:e.id,children:[e.id.slice(0,12),"…"]})]}),g.jsxs("div",{className:"modal-actions",children:[g.jsx("span",{className:"modal-dur",children:GP(e)}),g.jsx("button",{className:"btn icon-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]})]}),g.jsxs("section",{className:"modal-body",children:[e.trimmed&&g.jsx("div",{className:"modal-section",children:g.jsx("p",{className:"modal-note",children:"Full payloads for this call were released to keep memory bounded — only the previews below are still held."})}),g.jsxs("div",{className:"modal-section",children:[g.jsx("h4",{children:"Input"}),g.jsx("pre",{children:qx(e.input??e.inputPreview)})]}),g.jsxs("div",{className:"modal-section",children:[g.jsxs("h4",{children:["Response ",i==="err"&&g.jsx("span",{className:"err-tag",children:"error"})]}),g.jsx("pre",{children:e.endedAt==null?"(waiting…)":qx(e.response??e.errorPreview)})]})]})]})})}const Jl=18,$x=26,KP=12;function XP(e){return QP(e.nodeInternals.values())}function QP(e){const n=new Map;for(const o of e){if(o.type!=="agent")continue;const l=o.data;if(!(l!=null&&l.sessionId)||l.exitAt!=null||o.width==null||o.height==null)continue;const u=o.position.x,c=o.position.y,h=u+o.width,p=c+o.height,d=n.get(l.sessionId);d?(d.minX=Math.min(d.minX,u),d.minY=Math.min(d.minY,c),d.maxX=Math.max(d.maxX,h),d.maxY=Math.max(d.maxY,p),l.kind==="root"&&(d.label=Dx(l)??d.label)):n.set(l.sessionId,{minX:u,minY:c,maxX:h,maxY:p,label:Dx(l)??l.sessionId})}const r=new Map;for(const o of n.values())r.set(o.label,(r.get(o.label)??0)+1);const i=[];for(const[o,l]of n){const c=(r.get(l.label)??0)>1?`${l.label} · ${ZP(o)}`:l.label;i.push({sessionId:o,label:c,x:l.minX-Jl,y:l.minY-Jl-$x,w:l.maxX-l.minX+Jl*2,h:l.maxY-l.minY+Jl*2+$x})}return i}function ZP(e){const n=e.match(/[a-zA-Z0-9]{4}/);return n?n[0]:e.slice(0,4)}function Dx(e){if(e.kind==="root")return e.label}function JP(){const{x:e,y:n,zoom:r}=eC(),i=La(),o=Qe(XP,e3);if(o.length<=1)return null;const l=u=>{try{const c=i.getNodes().filter(h=>{const p=h.data;return(p==null?void 0:p.sessionId)===u});if(c.length===0)return;i.fitView({padding:.3,duration:500,nodes:c})}catch{}};return g.jsx("div",{className:"session-clusters",children:o.map(u=>{const c=Kv(u.sessionId),h={position:"absolute",left:u.x*r+e,top:u.y*r+n,width:u.w*r,height:u.h*r,"--session-hue":c},p={position:"absolute",left:u.x*r+e+16*r,top:(u.y-KP)*r+n,transform:`scale(${Math.min(1,r)})`,transformOrigin:"left top","--session-hue":c};return g.jsxs(ue.Fragment,{children:[g.jsx("div",{className:"cluster-card",style:h,"aria-hidden":!0}),g.jsx("button",{type:"button",className:"cluster-label",style:p,title:`Fit view to ${u.label} · drag the wrapper to move the whole session`,onClick:()=>l(u.sessionId),children:u.label})]},u.sessionId)})})}function e3(e,n){if(e.length!==n.length)return!1;for(let r=0;r<e.length;r++){const i=e[r],o=n[r];if(i.sessionId!==o.sessionId||i.label!==o.label||i.x!==o.x||i.y!==o.y||i.w!==o.w||i.h!==o.h)return!1}return!0}function t3({data:e}){return g.jsx("div",{className:"session-group-handle",style:{width:(e==null?void 0:e.w)??0,height:(e==null?void 0:e.h)??0}})}const gC=600,n3=4,r3=36,kv=16,s3=60,i3=6,Fx=220,zx=96,o3=28,a3={Read:"file",Write:"file",Edit:"file",MultiEdit:"file",Glob:"file",Grep:"file",LS:"file",NotebookEdit:"file",Bash:"shell",PowerShell:"shell",shell:"shell",exec_command:"shell",shell_command:"shell",write_stdin:"shell",wait:"shell",apply_patch:"file",update_plan:"task",WebFetch:"web",WebSearch:"web",Task:"agent",Agent:"agent",TodoWrite:"task",TaskCreate:"task",TaskUpdate:"task",TaskList:"task",TaskGet:"task",TaskOutput:"task",TaskStop:"task",EnterPlanMode:"plan",ExitPlanMode:"plan",AskUserQuestion:"plan",Skill:"plan",Workflow:"plan",ScheduleWakeup:"other",CronCreate:"other",CronList:"other",CronDelete:"other",Monitor:"other",PushNotification:"other",RemoteTrigger:"other",ToolSearch:"other"};function l3(e){return e.startsWith("mcp__")?"mcp":a3[e]??"other"}const u3={Read:"📖",Write:"💾",Edit:"✏️",MultiEdit:"🔧",Glob:"🗺️",Grep:"🔎",Bash:"⚡",PowerShell:"💻",shell:"⚡",exec_command:"⚡",shell_command:"⚡",write_stdin:"💻",wait:"⏳",apply_patch:"🩹",update_plan:"📋",LS:"📂",Task:"🤖",Agent:"🤖",TodoWrite:"📋",TaskCreate:"📋",TaskUpdate:"📝",TaskList:"🗂️",TaskGet:"🗂️",TaskOutput:"📤",TaskStop:"🛑",WebFetch:"🌐",WebSearch:"🔭",ToolSearch:"🧰",NotebookEdit:"📓",EnterPlanMode:"🧭",ExitPlanMode:"🏁",AskUserQuestion:"❓",ScheduleWakeup:"⏰",CronCreate:"⏰",CronList:"📅",CronDelete:"🗑️",Skill:"🎯",Workflow:"🎬",Monitor:"📡",PushNotification:"🔔",RemoteTrigger:"📡"};function Bx(e){return e.startsWith("mcp__")?"🔌":u3[e]??"✨"}const c3={git:"🐙",gh:"🐙",glab:"🐙",npm:"📦",pnpm:"📦",yarn:"📦",bun:"📦",brew:"🍺",node:"🟢",deno:"🟢",python:"🐍",python3:"🐍",py:"🐍",pip:"🐍",pip3:"🐍",uv:"🐍",ruby:"💎",bundle:"💎",gem:"💎",cargo:"🦀",rustc:"🦀",rustup:"🦀",go:"🐹",docker:"🐳","docker-compose":"🐳",podman:"🐳",kubectl:"☸️",helm:"☸️",k9s:"☸️",grep:"🔎",rg:"🔎",ag:"🔎",ack:"🔎",find:"🔍",fd:"🔍",locate:"🔍",which:"🔍",ls:"📂",dir:"📂",tree:"📂",cat:"📄",head:"📄",tail:"📄",less:"📄",more:"📄",bat:"📄",cp:"📋",mv:"✂️",rm:"🗑️",rmdir:"🗑️",mkdir:"📁",touch:"📁",sed:"✏️",awk:"✏️",tr:"✏️",curl:"🌐",wget:"🌐",http:"🌐",httpie:"🌐",ssh:"🔐",scp:"🔐",rsync:"🔐",ping:"📡",make:"🔨",cmake:"🔨",ninja:"🔨",bazel:"🔨",just:"🔨",terraform:"🏗️",ansible:"📕",pulumi:"🏗️",ps:"📊",top:"📊",htop:"📊",btm:"📊",kill:"💀",pkill:"💀",systemctl:"⚙️",service:"⚙️",tar:"🗜️",zip:"🗜️",unzip:"🗜️",gzip:"🗜️","7z":"🗜️",vim:"📝",nvim:"📝",nano:"📝",emacs:"📝",code:"📝",jq:"🪺",yq:"🪺",echo:"💬",printf:"💬",ffmpeg:"🎞️",ffprobe:"🎞️",imagemagick:"🖼️",convert:"🖼️","Get-ChildItem":"📂","Get-Content":"📄","Set-Content":"💾","Out-File":"💾","Add-Content":"💾","Set-Location":"📍","Get-Location":"📍","Get-Process":"📊","Start-Process":"▶️","Stop-Process":"💀","Invoke-WebRequest":"🌐","Invoke-RestMethod":"🌐","New-Item":"📁","Remove-Item":"🗑️","Copy-Item":"📋","Move-Item":"✂️","Test-Path":"🔍","Where-Object":"🔎","ForEach-Object":"🔁","Select-Object":"🎯","Measure-Object":"📊","Get-Service":"⚙️","Restart-Service":"⚙️","ConvertTo-Json":"🪺","ConvertFrom-Json":"🪺"};function vC(e){if(!e)return null;let n=e.trim();if(!n)return null;const r=n.match(/^(?:bash|sh|zsh|fish|powershell|pwsh)(?:\.exe)?\s+(?:-c|-Command|-NoProfile|-NonInteractive|\s)+["']([^"']+)["']/i);if(r)return vC(r[1]);for(;;){const l=n.match(/^([A-Z_][A-Z0-9_]*=\S*)\s+/);if(!l)break;n=n.slice(l[0].length)}n=n.replace(/^sudo(?:\s+-\S+)*\s+/,""),n=n.replace(/^(?:time|nohup|xargs)\s+/,"");const i=n.match(/^([^\s|;&<>(]+)/);if(!i)return null;let o=i[1];return o=o.replace(/^.*[/\\]/,""),o=o.replace(/\.(exe|cmd|bat|ps1)$/i,""),o||null}function d3(e){if(typeof e=="string")return e;if(!e||typeof e!="object")return null;const n=e;if(typeof n.cmd=="string")return n.cmd;if(typeof n.command=="string")return n.command;if(Array.isArray(n.command)&&n.command.every(r=>typeof r=="string")){const r=n.command;if(/powershell|cmd|bash|sh(\.exe)?$/i.test(r[0]??"")){const i=r.findIndex(o=>/^(-Command|-c)$/i.test(o));if(i>=0&&i+1<r.length)return r[i+1]}return r.join(" ")}return typeof n.script=="string"?n.script:null}const f3=new Set(["Bash","PowerShell","shell","exec_command","shell_command","write_stdin","wait"]),h3=new Set(["shell","exec_command","shell_command","write_stdin","wait","apply_patch","update_plan"]);function p3(e,n){return h3.has(e)||e.startsWith("mcp__")?Math.max(zx,34+n.length*7.5):zx}function m3(e,n){if(!f3.has(e))return null;const r=d3(n);if(!r)return null;const i=vC(r);return i?{emoji:c3[i]??"⚙️",label:i,category:"shell",detail:r}:null}const g3=new Set(["Read","Write","Edit","MultiEdit","NotebookEdit","LS","Glob","apply_patch"]),Ux={ts:"🟦",tsx:"🟦",d:"🟦",js:"🟨",jsx:"🟨",mjs:"🟨",cjs:"🟨",py:"🐍",pyi:"🐍",ipynb:"📓",rs:"🦀",go:"🐹",rb:"💎",erb:"💎",java:"☕",kt:"☕",scala:"☕",gradle:"☕",cs:"🔷",fs:"🔷",php:"🐘",swift:"🦅",c:"🇨",cpp:"🇨",cc:"🇨",h:"🇨",hpp:"🇨",md:"📝",mdx:"📝",rst:"📝",json:"🪺",json5:"🪺",jsonl:"🪺",yaml:"⚙️",yml:"⚙️",toml:"⚙️",ini:"⚙️",conf:"⚙️",cfg:"⚙️",xml:"📰",html:"🌐",htm:"🌐",vue:"🌐",svelte:"🌐",css:"🎨",scss:"🎨",sass:"🎨",less:"🎨",sh:"⚡",bash:"⚡",zsh:"⚡",fish:"⚡",ps1:"⚡",txt:"📄",log:"📄",out:"📄",csv:"📊",tsv:"📊",xlsx:"📊",xls:"📊",pdf:"📕",png:"🖼️",jpg:"🖼️",jpeg:"🖼️",gif:"🖼️",webp:"🖼️",svg:"🖼️",ico:"🖼️",mp4:"🎬",mov:"🎬",avi:"🎬",mkv:"🎬",webm:"🎬",mp3:"🎵",wav:"🎵",ogg:"🎵",flac:"🎵",zip:"🗜️",tar:"🗜️",gz:"🗜️",bz2:"🗜️","7z":"🗜️",xz:"🗜️",rar:"🗜️",env:"🔐",lock:"🔐",pem:"🔐",key:"🔐",crt:"🔐",sql:"🗄️",db:"🗄️",sqlite:"🗄️",parquet:"🗄️"},Hx={dockerfile:"🐳",makefile:"🔨",rakefile:"💎","package.json":"📦","pnpm-lock.yaml":"📦","yarn.lock":"📦","cargo.toml":"🦀","cargo.lock":"🦀","go.mod":"🐹","go.sum":"🐹","pyproject.toml":"🐍","requirements.txt":"🐍","readme.md":"📖",readme:"📖",license:"📜",".gitignore":"🐙",".gitattributes":"🐙",".env":"🔐",".dockerignore":"🐳"};function v3(e){const r=e.replace(/\\/g,"/").replace(/\/+$/,""),i=r.lastIndexOf("/");return i>=0?r.slice(i+1):r}function y3(e){const n=e.toLowerCase();if(Hx[n])return Hx[n];if(n.startsWith("dockerfile."))return"🐳";if(/\.(test|spec)\.[a-z]+$/.test(n))return"🧪";const r=n.lastIndexOf(".");if(r>0&&r<n.length-1){const i=n.slice(r+1);if(Ux[i])return Ux[i]}return"📄"}function w3(e,n){if(!n||typeof n!="object")return null;const r=n;if(e==="apply_patch"&&typeof r.patch=="string"){const i=r.patch.match(/^\*\*\* (?:Update|Add|Delete) File: (.+)$/m);return i?i[1].trim():null}return typeof r.file_path=="string"?r.file_path:typeof r.notebook_path=="string"?r.notebook_path:typeof r.path=="string"?r.path:e==="Glob"&&typeof r.pattern=="string"?r.pattern:null}function x3(e,n){if(!g3.has(e))return null;const r=w3(e,n);if(!r)return null;const i=v3(r);return i?{emoji:e==="LS"?"📂":y3(i),label:i,category:"file",detail:r}:null}const yC={github:{emoji:"🐙",name:"GitHub"},git:{emoji:"🐙",name:"Git"},gitlab:{emoji:"🦊",name:"GitLab"},slack:{emoji:"💬",name:"Slack"},discord:{emoji:"💬",name:"Discord"},linear:{emoji:"📐",name:"Linear"},jira:{emoji:"🅹",name:"Jira"},atlassian:{emoji:"🅰️",name:"Atlassian"},notion:{emoji:"📓",name:"Notion"},asana:{emoji:"📋",name:"Asana"},intercom:{emoji:"💬",name:"Intercom"},figma:{emoji:"🎨",name:"Figma"},gmail:{emoji:"📧",name:"Gmail"},calendar:{emoji:"📅",name:"Calendar"},drive:{emoji:"☁️",name:"Drive"},zoom:{emoji:"📹",name:"Zoom"},spotify:{emoji:"🎵",name:"Spotify"},youtube:{emoji:"📺",name:"YouTube"},ccd_session:{emoji:"📡",name:"Session"},ccd_directory:{emoji:"📂",name:"Directory"},ccd_session_mgmt:{emoji:"📡",name:"Sessions"},mcp_registry:{emoji:"🧰",name:"Registry"},"computer-use":{emoji:"🖱️",name:"Computer"},"claude-in-chrome":{emoji:"🌐",name:"Chrome"},"claude-preview":{emoji:"👀",name:"Preview"},"scheduled-tasks":{emoji:"⏰",name:"Scheduler"},visualize:{emoji:"🎨",name:"Visualize"},"plugin-design-asana":{emoji:"📋",name:"Asana"},"plugin-design-atlassian":{emoji:"🅰️",name:"Atlassian"},"plugin-design-figma":{emoji:"🎨",name:"Figma"},"plugin-design-intercom":{emoji:"💬",name:"Intercom"},"plugin-design-linear":{emoji:"📐",name:"Linear"},"plugin-design-notion":{emoji:"📓",name:"Notion"},"plugin-design-slack":{emoji:"💬",name:"Slack"}};function wC(e){if(!e.startsWith("mcp__"))return null;const n=e.slice(5),r=n.indexOf("__");return r<=0?{server:n,method:""}:{server:n.slice(0,r),method:n.slice(r+2)}}function _3(e){let n=5381;for(let r=0;r<e.length;r++)n=(n<<5)+n^e.charCodeAt(r);return Math.abs(n)%360}function b3(e,n){const r=wC(e);if(!r)return null;const{server:i,method:o}=r;if(!o)return null;const l=yC[i.toLowerCase()];return{emoji:(l==null?void 0:l.emoji)??"🔌",label:o,category:"mcp",detail:l?`${l.name} · ${o}`:`${i} · ${o}`}}function S3(e,n){return m3(e,n)??x3(e,n)??b3(e)}const k3={shell:"Shell",exec_command:"Shell",shell_command:"Shell",write_stdin:"stdin",wait:"wait",apply_patch:"Edit",update_plan:"Plan"};function E3(e){const n=wC(e);if(n){const i=yC[n.server.toLowerCase()];return i?{emoji:i.emoji,label:i.name}:{emoji:"🔌",label:n.server,hue:_3(n.server)}}const r=k3[e];return r?{emoji:Bx(e),label:r}:{emoji:Bx(e),label:e}}function N3(e){return e.endedAt==null?"inflight":e.ok===!1?"err":"done"}function C3(e,n,r){if(r==null)return 1;const i=n-r;return i<0?1:Math.max(0,1-i/gC)}function R3(e,n){const r=[],i=new Set;for(let o=e.length-1;o>=0&&r.length<n;o--){const l=e[o];i.has(l.id)||(i.add(l.id),r.push(l))}return r.reverse()}function T3(e,n,r,i,o,l){const u=[];for(const c of e.values()){if(!n.has(c.id)||c.exitAt!=null&&l-c.exitAt>gC)continue;const h=i.get(c.id)??r.get(c.id);if(!h)continue;const p=R3(c.tools,n3);if(p.length===0)continue;const d=c.exitAt??null,m=o.get(c.id),y=Math.max((m==null?void 0:m.width)??Fx,Fx),w=(m==null?void 0:m.height)??130,N=h.x,_=h.y,b=N+y,S=_+w/2;p.forEach((k,E)=>{const C=E*r3,I=N+y+s3,P=_+i3+C,A=C3(k,l,d),U=k.inputPreview??"",L=N3(k),O=A<.999,q=E3(k.name);u.push({id:`${c.id}::${k.id}`,toolId:k.id,agentId:c.id,toolName:k.name,name:q.label,emoji:q.emoji,status:L,category:l3(k.name),mcpHue:q.hue,inputPreview:U,fade:A,fading:O,worldX:I,worldY:P,anchorX:b,anchorY:S,spawnDx:b-I,spawnDy:S-(P+kv)});const G=S3(k.name,k.input);if(G){const F=p3(k.name,q.label),j=I+F+o3,B=P,z=I+F,ne=P+kv;u.push({id:`sub:${c.id}::${k.id}`,toolId:k.id,agentId:c.id,toolName:k.name,name:G.label,emoji:G.emoji,isSub:!0,status:L,category:G.category,inputPreview:G.detail??U,fade:A,fading:O,worldX:j,worldY:B,anchorX:z,anchorY:ne,spawnDx:z-j,spawnDy:0})}})}return u}function j3({agents:e,visibleAgentIds:n,positions:r,pinned:i,measured:o,dimUnmatched:l,spotlight:u,hiddenCategories:c,now:h,onOpenTool:p}){const d=T3(e,n,r,i,o,h),m=c&&c.size>0?d.filter(y=>!c.has(y.category)):d;return g.jsx(A3,{bursts:m,dimUnmatched:l,spotlight:u,onOpenTool:p})}function A3({bursts:e,dimUnmatched:n,spotlight:r,onOpenTool:i}){const{x:o,y:l,zoom:u}=eC();return g.jsxs("div",{className:"tool-bursts-layer","aria-hidden":!0,children:[g.jsx("svg",{className:"tool-bursts-svg",children:e.map(c=>{const h=c.anchorX*u+o,p=c.anchorY*u+l,d=(c.worldX+6)*u+o,m=(c.worldY+kv)*u+l,y=h+(d-h)*.55,w=n!=null&&!n.has(c.agentId),N=r!=null&&!r.has(c.agentId),_=c.fade*(w||N?.14:1);return g.jsx("path",{d:`M ${h} ${p} Q ${y} ${p}, ${d} ${m}`,className:`tool-conn status-${c.status}${c.fading?" fading":""}`,opacity:_},`l:${c.id}`)})}),e.map(c=>{const h=c.worldX*u+o,p=c.worldY*u+l,d={left:`${h}px`,top:`${p}px`,transform:`scale(${u})`,transformOrigin:"left top","--spawn-dx":`${c.spawnDx}px`,"--spawn-dy":`${c.spawnDy}px`},m=c.isSub?`${c.toolName} · ${c.name}`:c.toolName,y=c.inputPreview?`${m} · ${c.inputPreview}`:m,w=i!=null,N=c.mcpHue!=null?{"--mcp-hue":c.mcpHue}:{},_=n!=null&&!n.has(c.agentId),b=r!=null&&!r.has(c.agentId),S=_||b?" dim":"";return g.jsx("div",{className:"tool-burst-wrap",style:d,children:g.jsxs("div",{className:`tool-burst cat-${c.category}${c.mcpHue!=null?" mcp-hue":""} status-${c.status}${c.fading?" fading":""}${w?" clickable":""}${c.isSub?" sub":""}${S}`,style:N,title:y,onClick:w?()=>i(c.toolId):void 0,children:[g.jsx("span",{className:"tb-emoji",children:c.emoji}),g.jsx("span",{className:"tb-name",children:c.name}),c.status==="inflight"&&g.jsx("span",{className:"tb-spin"}),c.status==="done"&&g.jsx("span",{className:"tb-mark done",children:"✓"}),c.status==="err"&&g.jsx("span",{className:"tb-mark err",children:"×"})]})},c.id)})]})}function I3({state:e,sessionId:n,onClose:r}){const i=T.useMemo(()=>O3(e,n),[e,n]),o=T.useRef(null),l=xo(r,{focusRef:o});return i?g.jsx("div",{className:"modal-backdrop",onClick:r,role:"presentation",children:g.jsxs("div",{ref:l,className:"modal session-summary",onClick:u=>u.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"ss-title",children:[g.jsxs("div",{className:"modal-head",children:[g.jsxs("div",{className:"modal-title",children:[g.jsx("span",{className:"state-pill state-done","aria-hidden":!0,children:"done"}),g.jsx("span",{id:"ss-title",className:"modal-tool-name",title:i.cwd??i.sessionId,children:i.label}),g.jsxs("span",{className:"modal-tool-id",children:["· ",i.sessionId.slice(0,8)]})]}),g.jsxs("div",{className:"modal-actions",children:[g.jsx("span",{className:"modal-dur",title:"Total wall time",children:i.durationLabel}),g.jsx("button",{type:"button",ref:o,className:"btn",onClick:r,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]})]}),g.jsxs("div",{className:"modal-body",children:[g.jsxs("section",{className:"ss-hero",children:[g.jsxs("div",{className:"ss-hero-left",children:[g.jsx("div",{className:"ss-cost-label",children:"total spend"}),g.jsx("div",{className:"ss-cost",children:ze(i.cost.total)}),i.modelChips.length>0&&g.jsx("div",{className:"ss-models",children:i.modelChips.map(u=>g.jsx("span",{className:"model-chip",title:u,children:li(u)},u))})]}),g.jsx("div",{className:"ss-hero-right",children:i.cost.total>0&&g.jsxs(g.Fragment,{children:[g.jsx(M3,{cost:i.cost}),g.jsxs("div",{className:"ss-cost-legend",children:[g.jsxs("span",{className:"ssl ssl-in",children:["input ",g.jsx("b",{children:ze(i.cost.input)})]}),g.jsxs("span",{className:"ssl ssl-out",children:["output ",g.jsx("b",{children:ze(i.cost.output)})]}),g.jsxs("span",{className:"ssl ssl-cr",children:["cache r ",g.jsx("b",{children:ze(i.cost.cacheRead)})]}),g.jsxs("span",{className:"ssl ssl-cw",children:["cache w ",g.jsx("b",{children:ze(i.cost.cacheWrite)})]})]})]})})]}),g.jsxs("section",{className:"ss-stats",children:[g.jsx(so,{label:"agents",value:i.agentCount}),g.jsx(so,{label:"subagents",value:i.subagentCount}),g.jsx(so,{label:"tool calls",value:i.toolCount}),g.jsx(so,{label:"prompts",value:i.promptCount}),g.jsx(so,{label:"tokens",value:i.tokensSum.toLocaleString()}),i.errCount>0&&g.jsx(so,{label:"errors",value:i.errCount,tone:"err"})]}),i.topTools.length>0&&g.jsxs("section",{className:"modal-section",children:[g.jsx("h4",{children:"Most-used tools"}),g.jsx("div",{className:"ss-top-tools",children:i.topTools.map(([u,c])=>g.jsxs("div",{className:"ss-tt",children:[g.jsx("span",{className:"ss-tt-name",children:u}),g.jsx("span",{className:"ss-tt-bar",children:g.jsx("span",{className:"ss-tt-bar-fill",style:{width:`${c/i.topTools[0][1]*100}%`}})}),g.jsx("span",{className:"ss-tt-count",children:c})]},u))})]}),i.firstPrompt&&g.jsxs("section",{className:"modal-section",children:[g.jsx("h4",{children:"Opening prompt"}),g.jsx("div",{className:"ss-prompt",children:i.firstPrompt})]})]})]})}):null}function so({label:e,value:n,tone:r}){return g.jsxs("div",{className:`ss-stat${r?` tone-${r}`:""}`,children:[g.jsx("div",{className:"ss-stat-value",children:n}),g.jsx("div",{className:"ss-stat-label",children:e})]})}function M3({cost:e}){const n=e.total;if(n<=0)return null;const r=(i,o,l)=>{if(i<=0)return null;const u=i/n*100;return g.jsx("span",{className:`cb-seg ${o}`,style:{width:`${u}%`},title:`${l}: ${ze(i)} (${u.toFixed(0)}%)`},o)};return g.jsxs("div",{className:"cost-bar cost-bar-lg","aria-label":"Cost breakdown",children:[r(e.input,"cb-input","input"),r(e.output,"cb-output","output"),r(e.cacheRead,"cb-cache-r","cache read"),r(e.cacheWrite,"cb-cache-w","cache write")]})}function O3(e,n){const r=e.agents.get(n);if(!r)return null;const i=[];for(const E of e.agents.values())E.sessionId===n&&i.push(E);if(i.length===0)return null;const o={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},l=new Set,u=new Map;let c=0,h=0,p=0,d=0,m=0,y,w=1/0,N=0;for(const E of i){const C=fn(E.usage,E.model);o.input+=C.input,o.output+=C.output,o.cacheRead+=C.cacheRead,o.cacheWrite+=C.cacheWrite,o.total+=C.total,E.model&&l.add(E.model),E.kind==="subagent"&&m++,h+=E.prompts.length,!y&&E.prompts.length>0&&(y=E.prompts[0].text),p+=E.usage.inputTokens+E.usage.outputTokens,c+=E.toolCount,w=Math.min(w,E.startedAt),N=Math.max(N,E.endedAt??Date.now());for(const I of E.tools)u.set(I.name,(u.get(I.name)??0)+1),I.ok===!1&&d++}const _=Math.max(0,N-w),b=Math.floor(_/1e3),S=b<60?`${b}s`:b<3600?`${Math.floor(b/60)}m ${String(b%60).padStart(2,"0")}s`:`${Math.floor(b/3600)}h ${Math.floor(b%3600/60)}m`,k=Array.from(u.entries()).sort((E,C)=>C[1]-E[1]).slice(0,5);return{sessionId:n,label:r.label||r.cwdBasename||"session",cwd:r.cwd,durationLabel:S,cost:o,modelChips:Array.from(l),agentCount:i.length,subagentCount:m,toolCount:c,promptCount:h,tokensSum:p,errCount:d,topTools:k,firstPrompt:y}}function Jv(e){return(e==null?void 0:e.kind)==="permission"}function P3(e){const n=[];for(const r of e)r.kind==="root"&&Jv(r.waiting)&&n.push({id:r.id,label:r.label,waiting:r.waiting});return n.sort((r,i)=>r.waiting.since-i.waiting.since)}function L3(e){const n=new Set;for(const r of e)r.state==="active"&&n.add(r.sessionId);return n.size}function Wx(e){return e.waiting?Jv(e.waiting)?0:1:e.state==="active"?2:3}function q3(e,n){const r=[];for(const i of e.agents.values()){if(i.kind!=="root")continue;let o=i.toolCount,l=fn(i.usage,i.model).total,u=i.endedAt??i.startedAt;for(const c of e.agents.values()){if(c.sessionId!==i.sessionId||c.kind==="root")continue;o+=c.toolCount,l+=fn(c.usage,c.model).total;const h=c.endedAt??c.startedAt;h>u&&(u=h)}r.push({sessionId:i.sessionId,label:i.label||i.cwdBasename||"session",cwdBasename:i.cwdBasename,state:i.state,waiting:i.waiting,modelId:i.model,toolCount:o,cost:l,startedAt:i.startedAt,lastActivity:u})}return r.sort((i,o)=>{const l=Wx(i),u=Wx(o);return l!==u?l-u:i.waiting&&o.waiting?i.waiting.since-o.waiting.since:o.lastActivity-i.lastActivity}),r}function Vx(e,n,r){const i=(n??r)-e;if(i<1e3)return"<1s";const o=Math.floor(i/1e3);if(o<60)return`${o}s`;const l=Math.floor(o/60);return l<60?`${l}m`:`${Math.floor(l/60)}h ${l%60}m`}function $3({state:e,now:n,selectedIds:r,onSelect:i,onClose:o}){const l=T.useMemo(()=>q3(e),[e,e.lastSeq,n]),u=l.filter(h=>h.state==="active").length,c=l.filter(h=>Jv(h.waiting)).length;return g.jsxs("aside",{className:"session-list",id:"session-list","aria-label":"Sessions",children:[g.jsxs("div",{className:"sl-header",children:[g.jsxs("h3",{children:["Sessions ",g.jsx("span",{className:"sl-count",children:l.length})]}),c>0&&g.jsxs("span",{className:"sl-waiting-count",children:[c," waiting"]}),u>0&&g.jsxs("span",{className:"sl-live-count",children:[u," live"]}),g.jsx("button",{className:"btn icon-btn sl-close",onClick:o,title:"Hide sidebar (L)","aria-label":"Hide session list",children:"‹"})]}),g.jsxs("div",{className:"sl-rows",children:[l.length===0&&g.jsx("div",{className:"sl-empty",children:"No sessions yet."}),l.map(h=>{const p=r.has(h.sessionId);return g.jsxs("button",{type:"button",className:`sl-row state-${h.state}${p?" selected":""}`,onClick:()=>i(h.sessionId),title:`Focus ${h.label}`,children:[g.jsx("span",{className:`sl-dot state-${h.state}`,"aria-hidden":!0}),g.jsx("span",{className:"vis-hidden",children:Zv(h.state)}),g.jsxs("div",{className:"sl-row-body",children:[g.jsxs("div",{className:"sl-row-head",children:[g.jsx("span",{className:"sl-label",children:h.label}),h.modelId&&g.jsx("span",{className:"model-chip",title:h.modelId,children:li(h.modelId)})]}),g.jsxs("div",{className:"sl-row-meta",children:[g.jsxs("span",{title:"tool calls",children:[g.jsx("b",{children:h.toolCount})," tools"]}),h.cost>0&&g.jsx("span",{className:"sl-cost",title:"total spend",children:g.jsx("b",{children:ze(h.cost)})}),h.waiting?g.jsxs("span",{className:"sl-waiting",title:`${Iu(h.waiting)}
|
|
61
|
-
Blocked since ${new Date(h.waiting.since).toLocaleTimeString()} · started ${new Date(h.startedAt).toLocaleString()}`,children:["waiting ",Vx(h.waiting.since,void 0,n)]}):g.jsx("span",{className:"sl-elapsed",title:`Started ${new Date(h.startedAt).toLocaleString()}`,children:Vx(h.startedAt,h.state==="active"?void 0:h.lastActivity,n)})]})]})]},h.sessionId)})]})]})}const tn="ccdeck";function Dt(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:e<1e9?`${(e/1e6).toFixed(2)}M`:`${(e/1e9).toFixed(2)}B`}function Gx(e,n){if(!e)return null;const r=n-Math.floor(e/1e3);return r<10?"just now":r<60?`${r}s ago`:r<3600?`${Math.floor(r/60)}m ago`:`${Math.floor(r/3600)}h ago`}function D3(e){return e==="claude-swap"?"Read from claude-swap's last collection — costs no request against your usage-endpoint budget":e==="api"?"Fetched from Anthropic's usage endpoint, at most once every 5 minutes":e==="cli"?"Parsed from `claude /usage`, at most once every 5 minutes":"Last update"}function F3({cost:e}){const n=e.total;if(n<=0)return null;const r=(i,o,l)=>{if(i<=0)return null;const u=i/n*100;return g.jsx("span",{className:`cb-seg ${o}`,style:{width:`${u}%`},title:`${l}: ${ze(i)} (${u.toFixed(0)}%)`},o)};return g.jsxs("div",{className:"cost-bar","aria-label":"Cost breakdown",children:[r(e.input,"cb-input","input"),r(e.output,"cb-output","output"),r(e.cacheRead,"cb-cache-r","cache read"),r(e.cacheWrite,"cb-cache-w","cache write")]})}function z3(e,n){const r=e-n;if(r<=0)return null;const i=Math.floor(r/3600),o=Math.floor(r%3600/60);if(i>23){const l=Math.floor(r/86400),u=Math.floor(r%86400/3600);return`${l}d ${u}h`}return i>0?`${i}h ${o}m`:`${o}m`}function B3(e,n,r,i){const o=Math.max(0,n-i),l=Math.max(0,r-o);if(l<120)return null;const u=Math.min(100,l/r*100),c=e-u;if(Math.abs(c)<3)return{label:"on pace",color:"var(--ok)",expectedPct:u,isDeficit:!1};if(c>0){const h=100-e,p=l>0?e/l:0,d=p>0?h/p:1/0,m={label:`${Math.round(c)}% ahead`,color:"var(--warn)",expectedPct:u,isDeficit:!0};if(d<o&&d<86400){const y=Math.floor(d/3600),w=Math.floor(d%3600/60);m.runsOutIn=y>0?`${y}h ${w}m`:`${w}m`}return m}return{label:`${Math.round(-c)}% reserve`,color:"var(--ok)",expectedPct:u,isDeficit:!1}}function ei({pct:e,label:n,reset:r,resetAt:i,windowSec:o,limitReached:l,nowSec:u}){const c=Math.min(100,Math.max(0,e)),p=l||c>=90?"var(--err)":c>=70?"var(--warn)":"var(--accent)",d=c===0?"< 1%":`${c}%`,m=c===0?2:c,y=i?z3(i,u):null,w=i&&o?B3(c,i,o,u):null;return g.jsxs("div",{className:"qb-row",children:[g.jsxs("div",{className:"qb-meta",children:[g.jsxs("span",{className:"qb-label",children:[n,l&&g.jsx("span",{className:"qb-limit-badge",title:"Rate limit reached",children:"⛔"})]}),g.jsx("span",{className:"qb-pct",style:{color:p},children:d})]}),g.jsxs("div",{className:"qb-track",children:[g.jsx("div",{className:"qb-fill",style:{width:`${m}%`,background:p,opacity:c===0?.4:1}}),w&&g.jsx("div",{className:"qb-pace-marker",style:{left:`${w.expectedPct}%`,background:w.isDeficit?"var(--err)":"var(--ok)"},title:`To last until reset, stay near ${Math.round(w.expectedPct)}% by now`})]}),g.jsxs("div",{className:"qb-reset-row",children:[y?g.jsxs("span",{className:"qb-reset",children:["resets in ",y]}):r?g.jsxs("span",{className:"qb-reset",children:["resets ",r]}):null,w&&g.jsx("span",{className:"qb-pace",style:{color:w.color},children:w.runsOutIn?`runs out in ${w.runsOutIn}`:w.label})]})]})}const U3=6e4;function H3(){const[e,n]=T.useState(null),[r,i]=T.useState(!1),o=T.useRef(null),l=async(c=!1)=>{c&&i(!0);try{const p=await fetch(c?"/api/quota?refresh=1":"/api/quota");p.ok&&n(await p.json())}catch{}finally{c&&i(!1)}};return T.useEffect(()=>(l(!0),o.current=window.setInterval(()=>l(!1),U3),()=>{o.current!=null&&window.clearInterval(o.current)}),[]),{quota:e,loading:r,refresh:()=>l(!0)}}function W3(e){switch(e){case"no_token":return"Run codex login to authenticate.";case"api_key_mode":return"API-key login — ChatGPT quota is only available for codex login.";case"refresh_rejected":return"Codex session expired — run codex login.";case"refresh_failed":return"Couldn't refresh the Codex token — click ↻ to retry.";case"untrusted_base_url":return"chatgpt_base_url in ~/.codex/config.toml is not an https OpenAI host, so the token was not sent.";default:return"ChatGPT API unreachable — click ↻ to retry."}}const xC=6e4;function V3(){const[e,n]=T.useState(null),[r,i]=T.useState(!1),o=T.useRef(null),l=async(c=!1)=>{c&&i(!0);try{const p=await fetch(c?"/api/codex-quota?refresh=1":"/api/codex-quota");p.ok&&n(await p.json())}catch{}finally{c&&i(!1)}};return T.useEffect(()=>(l(!0),o.current=window.setInterval(()=>l(!1),xC),()=>{o.current!=null&&window.clearInterval(o.current)}),[]),{data:e,loading:r,refresh:()=>l(!0)}}function G3(){const[e,n]=T.useState(null),r=T.useRef(null),i=async()=>{try{const o=await fetch("/api/codex-usage");o.ok&&n(await o.json())}catch{}};return T.useEffect(()=>(i(),r.current=window.setInterval(i,xC),()=>{r.current!=null&&window.clearInterval(r.current)}),[]),{data:e}}function Y3({state:e,now:n,onClose:r}){var A,U;const{quota:i,loading:o,refresh:l}=H3(),{data:u,loading:c,refresh:h}=V3(),{data:p}=G3(),[d,m]=T.useState(()=>Math.floor(Date.now()/1e3));T.useEffect(()=>{const L=window.setInterval(()=>m(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(L)},[]);const{byModel:y,totalCost:w,totalTokens:N,burnRate:_}=T.useMemo(()=>{const L=new Map,O={total:0,input:0,output:0,cacheRead:0,cacheWrite:0};let q=0,G=0,F=0,j=0;for(const $ of e.agents.values()){const Q=$.model??"__unknown__",M=fn($.usage,$.model),V=L.get(Q);V?(V.inputTokens+=$.usage.inputTokens,V.outputTokens+=$.usage.outputTokens,V.cacheReadTokens+=$.usage.cacheReadTokens,V.cacheCreateTokens+=$.usage.cacheCreateTokens,V.cost.total+=M.total,V.cost.input+=M.input,V.cost.output+=M.output,V.cost.cacheRead+=M.cacheRead,V.cost.cacheWrite+=M.cacheWrite,V.agentCount++):L.set(Q,{model:Q,inputTokens:$.usage.inputTokens,outputTokens:$.usage.outputTokens,cacheReadTokens:$.usage.cacheReadTokens,cacheCreateTokens:$.usage.cacheCreateTokens,cost:{...M},agentCount:1}),O.total+=M.total,O.input+=M.input,O.output+=M.output,O.cacheRead+=M.cacheRead,O.cacheWrite+=M.cacheWrite,q+=$.usage.inputTokens,G+=$.usage.outputTokens,F+=$.usage.cacheReadTokens,j+=$.usage.cacheCreateTokens}const B=Array.from(L.values()).sort(($,Q)=>Q.cost.total-$.cost.total);let z=0,ne=0;for(const $ of e.agents.values()){if($.state!=="active")continue;const Q=fn($.usage,$.model);z+=Q.total,ne=Math.max(ne,(($.endedAt??n)-$.startedAt)/1e3)}const Z=ne>0?_u(z,ne):null;return{byModel:B,totalCost:O,totalTokens:{in:q,out:G,cacheR:F,cacheC:j},burnRate:Z}},[e,e.lastSeq,n]),b=T.useMemo(()=>{const L=[];for(const O of e.agents.values()){if(O.kind!=="root")continue;let q=fn(O.usage,O.model).total,G=O.usage.inputTokens,F=O.usage.outputTokens;for(const j of e.agents.values())j.sessionId!==O.sessionId||j.kind==="root"||(q+=fn(j.usage,j.model).total,G+=j.usage.inputTokens,F+=j.usage.outputTokens);L.push({sessionId:O.sessionId,label:O.label||O.cwdBasename||"session",state:O.state,cost:q,inputTokens:G,outputTokens:F})}return L.sort((O,q)=>q.cost-O.cost).slice(0,12)},[e,e.lastSeq]),S=w.total>0,k=N.in+N.out,E=o||c,C=Gx(i==null?void 0:i.fetchedAt,d),I=Gx(u==null?void 0:u.fetchedAt,d),P=()=>{l(),h()};return g.jsxs("div",{className:"usage-panel",id:"usage-panel","aria-label":"Usage",children:[g.jsxs("div",{className:"up-header",children:[g.jsx("h3",{children:"Usage"}),_&&g.jsx("span",{className:"up-rate",children:_}),g.jsxs("div",{className:"up-header-right",children:[g.jsx("button",{type:"button",className:"btn up-refresh-btn",onClick:P,disabled:E,title:"Refresh Claude + Codex quota",children:E?"…":"↻"}),g.jsx("button",{type:"button",className:"btn icon-btn up-close",onClick:r,"aria-label":"Close usage panel",title:"Close (U)",children:"×"})]})]}),g.jsxs("section",{className:"up-section up-quota-section",children:[g.jsxs("h4",{className:"up-section-title",children:["Claude quota",C&&!o&&g.jsx("span",{className:"up-section-age",title:D3(i==null?void 0:i.source),children:C})]}),i!=null&&i.ok?g.jsxs("div",{className:"up-quota-bars",children:[i.session5hPct!=null&&g.jsx(ei,{label:"5-hour window",pct:i.session5hPct,reset:i.session5hReset,resetAt:i.session5hResetAt,windowSec:i.session5hWindowSec,nowSec:d}),i.week7dPct!=null&&g.jsx(ei,{label:"7-day window",pct:i.week7dPct,reset:i.week7dReset,resetAt:i.week7dResetAt,windowSec:i.week7dWindowSec,nowSec:d}),i.weekSonnetPct!=null&&g.jsx(ei,{label:"Sonnet (7d)",pct:i.weekSonnetPct,nowSec:d}),i.weekOpusPct!=null&&g.jsx(ei,{label:"Opus (7d)",pct:i.weekOpusPct,nowSec:d})]}):(i==null?void 0:i.ok)===!1?g.jsxs("div",{className:"up-quota-na",children:[g.jsx("span",{children:"Quota unavailable."}),g.jsxs("span",{className:"up-quota-hint",children:["Run ",g.jsx("code",{children:"/usage"})," in a claude session, then click ↻"]})]}):g.jsx("div",{className:"up-quota-na up-quota-loading",children:"Checking…"})]}),g.jsxs("section",{className:"up-section up-quota-section",children:[g.jsxs("h4",{className:"up-section-title",children:["Codex quota",(u==null?void 0:u.ok)&&u.planLabel&&g.jsx("span",{className:"up-plan-badge",children:u.planLabel}),I&&!c&&g.jsx("span",{className:"up-section-age",title:"Fetched from the Codex usage endpoint",children:I})]}),u!=null&&u.ok?g.jsxs("div",{className:"up-quota-bars",children:[(A=u.windows)==null?void 0:A.map(L=>g.jsx(ei,{label:L.label,pct:L.pct,reset:L.reset??void 0,resetAt:L.resetAt??void 0,windowSec:L.windowSec??void 0,limitReached:u.limitReached&&L.pct>=100,nowSec:d},L.id)),(U=u.extraWindows)==null?void 0:U.map(L=>g.jsx(ei,{label:L.label,pct:L.pct,reset:L.reset??void 0,resetAt:L.resetAt??void 0,windowSec:L.windowSec??void 0,nowSec:d},L.id)),u.creditLimit&&g.jsx(ei,{label:`spend cap · $${Math.round(u.creditLimit.used)} of $${Math.round(u.creditLimit.limit)}`,pct:u.creditLimit.usedPct,reset:u.creditLimit.reset??void 0,resetAt:u.creditLimit.resetAt??void 0,limitReached:u.spendControlReached,nowSec:d}),(p==null?void 0:p.ok)&&p.window7d&&p.window7d.sessionCount>0&&g.jsxs("div",{className:"up-quota-sub",children:[Dt(p.window7d.totalTokens)," tokens · ",p.window7d.sessionCount," session",p.window7d.sessionCount!==1?"s":""," (7d)"]}),u.creditsBalance&&!u.creditsUnlimited&&g.jsxs("div",{className:"up-quota-sub up-credits",children:["credits: $",u.creditsBalance,u.overageReached&&" · overage limit reached"]}),u.creditsUnlimited&&g.jsx("div",{className:"up-quota-sub up-credits",children:"credits: unlimited"}),u.resetCredits&&u.resetCredits.availableCount>0&&g.jsxs("div",{className:"up-quota-sub up-reset-credits",title:`Redeem in the Codex CLI or ChatGPT — ${tn} only reports them`,children:[u.resetCredits.availableCount," rate-limit reset",u.resetCredits.availableCount!==1?"s":""," available",u.resetCredits.nextExpiryAt&&` · expires ${new Date(u.resetCredits.nextExpiryAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`]}),u.promo&&g.jsx("div",{className:"up-quota-sub",children:u.promo}),u.partial&&g.jsx("div",{className:"up-quota-sub up-quota-hint",children:"Partial data — OpenAI returned limits this build doesn't recognise."})]}):(u==null?void 0:u.ok)===!1?g.jsxs("div",{className:"up-quota-na",children:[g.jsx("span",{children:"Quota unavailable."}),g.jsx("span",{className:"up-quota-hint",children:W3(u.reason)})]}):g.jsx("div",{className:"up-quota-na up-quota-loading",children:"Checking…"})]}),S?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"up-total",children:[g.jsx("span",{className:"up-total-value",children:ze(w.total)}),g.jsx("span",{className:"up-total-label",children:"total spend"})]}),g.jsx(F3,{cost:w}),k>0&&g.jsxs("div",{className:"up-tokens-row",children:[g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"in"}),Dt(N.in)]}),g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"out"}),Dt(N.out)]}),N.cacheR>0&&g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"cache r"}),Dt(N.cacheR)]}),N.cacheC>0&&g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"cache c"}),Dt(N.cacheC)]})]}),y.filter(L=>L.cost.total>0).length>0&&g.jsxs("section",{className:"up-section",children:[g.jsx("h4",{className:"up-section-title",children:"By model"}),g.jsxs("table",{className:"up-table",children:[g.jsx("thead",{children:g.jsxs("tr",{children:[g.jsx("th",{children:"Model"}),g.jsx("th",{children:"Tokens"}),g.jsx("th",{children:"Cost"})]})}),g.jsx("tbody",{children:y.filter(L=>L.cost.total>0).map(L=>g.jsxs("tr",{children:[g.jsx("td",{className:"up-model-name",title:L.model,children:li(L.model)}),g.jsx("td",{className:"up-num",children:Dt(L.inputTokens+L.outputTokens)}),g.jsx("td",{className:"up-num up-cost-val",children:ze(L.cost.total)})]},L.model))})]})]}),b.filter(L=>L.cost>0).length>0&&g.jsxs("section",{className:"up-section",children:[g.jsx("h4",{className:"up-section-title",children:"By session"}),g.jsx("div",{className:"up-sessions",children:b.filter(L=>L.cost>0).map(L=>g.jsxs("div",{className:"up-session-row",children:[g.jsx("span",{className:`sl-dot state-${L.state}`,"aria-hidden":!0}),g.jsx("span",{className:"vis-hidden",children:Zv(L.state)}),g.jsx("span",{className:"up-session-label",children:L.label}),g.jsx("span",{className:"up-session-tokens",children:Dt(L.inputTokens+L.outputTokens)}),g.jsx("span",{className:"up-session-cost",children:ze(L.cost)})]},L.sessionId))})]})]}):k>0?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"up-tokens-row",children:[g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"in"}),Dt(N.in)]}),g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"out"}),Dt(N.out)]})]}),g.jsx("div",{className:"up-hint",children:"Cost appears once a known model is detected."})]}):g.jsxs("div",{className:"up-empty",children:["No usage data yet.",g.jsx("br",{}),"Start a Claude Code or Codex session."]})]})}const Yx=18,K3=1100,io=(e,n)=>{const r=Math.sin(e*12.9898+n*78.233)*43758.5453;return r-Math.floor(r)},X3=Array.from({length:Yx},(e,n)=>{const r=-72+144*n/(Yx-1)+(io(n,1)-.5)*9,i=(r-90)*(Math.PI/180),o=(54+32*Math.cos(r*Math.PI/180))*(.74+io(n,2)*.52);return{dx:Math.cos(i)*o,dy:Math.sin(i)*o,rot:(n%2?1:-1)*(100+io(n,3)*260),delay:Math.round(io(n,4)*90),dur:760+Math.round(io(n,5)*260),scale:.8+io(n,6)*.45,hue:n%4,round:n%3===0}});function Kx({anchor:e,lifetimeMs:n=K3}){var l;const[r,i]=T.useState(null),o=typeof window<"u"&&((l=window.matchMedia)==null?void 0:l.call(window,"(prefers-reduced-motion: reduce)").matches);return T.useEffect(()=>{if(o)return;const u=e.current;if(!u)return;const c=u.getBoundingClientRect();i({x:c.left+c.width/2,y:c.top+c.height/2});const h=window.setTimeout(()=>i(null),n);return()=>window.clearTimeout(h)},[e,n,o]),o||!r?null:qI.createPortal(g.jsx("div",{className:"confetti",style:{left:`${r.x}px`,top:`${r.y}px`},"aria-hidden":!0,children:X3.map((u,c)=>g.jsx("span",{className:`confetti-bit${u.round?" round":""}`,"data-hue":u.hue,style:{"--dx":`${u.dx.toFixed(1)}px`,"--dy":`${u.dy.toFixed(1)}px`,"--rot":`${u.rot}deg`,"--s":u.scale.toFixed(2),animationDelay:`${u.delay}ms`,animationDuration:`${u.dur}ms, ${u.dur}ms`}},c))}),document.body)}const _C=new Set(["awaiting_url","awaiting_code","registering"]);function Q3(e){return e!=null&&_C.has(e)}function bC(e){return e!=null&&e!=="done"&&!_C.has(e)}const Z3="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",J3="the sign-in did not complete";function eL({state:e,serverError:n,localError:r}){const i=e==="idle";return{title:i?"Sign-in ended":"Sign-in failed",message:r||n||(i?Z3:J3)}}const tL="done";function nL(){let e=!1;return{shouldAnnounce(n){return n!==tL?(e=!1,!1):e?!1:(e=!0,!0)}}}const Xx={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 ccdeck1:",corrupt:"that share is incomplete — copy the whole thing",wrong_version:`that share was made by a newer ${tn}`,expired:"that share has expired — make a new one",import_failed:"claude-swap refused the import",bad_value:"an alias can only use letters, numbers, spaces, dots, dashes and underscores, up to 64 characters"},Qx={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"},rL=`claude-swap could not read the login keychain — start ${tn} from a Terminal window rather than a background service`;function Ev(e,n){return(e==null?void 0:e.reason)!=="no_cswap"&&/keychain/i.test(yo(e))?rL:e!=null&&e.reason&&Qx[e.reason]?Qx[e.reason]:(e==null?void 0:e.reason)||n}function yo(e){return((e==null?void 0:e.output)||(e==null?void 0:e.detail)||(e==null?void 0:e.error)||"").trim()}const Zx={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",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"},sL="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 iL(e){return/\bnpx\b/i.test(e)&&/(command not found|not found|not recognized|ENOENT)/i.test(e)}function oL(e,n){return iL(yo(e))?sL:e!=null&&e.reason&&Zx[e.reason]?Zx[e.reason]:(e==null?void 0:e.reason)||n}function cu(e,n){return e!=null&&e.detail?e.detail:e!=null&&e.error&&bC(e.state)?e.error:e!=null&&e.reason&&Xx[e.reason]?Xx[e.reason]:e!=null&&e.error?e.error:(e==null?void 0:e.reason)||n}const aL=1500;async function eu(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const Nv=ue.forwardRef((e,n)=>g.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:n,children:[g.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),g.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));Nv.displayName="SuccessMark";function lL({onClose:e,onChanged:n}){const[r,i]=T.useState("login"),[o,l]=T.useState(null),[u,c]=T.useState(""),[h,p]=T.useState(""),[d,m]=T.useState(!1),[y,w]=T.useState(null),[N,_]=T.useState(null),b=T.useRef(!1),S=T.useRef(null),k=T.useRef(null),E=T.useRef(null),C=T.useRef(null),I=T.useCallback(()=>{b.current&&eu({action:"login-cancel"}).catch(()=>{}),e()},[e]),P=xo(I,{focusRef:E}),A=T.useCallback(async()=>{m(!0),w(null),b.current=!0;const B=await eu({action:"login"}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){w(cu(B,"could not start the sign-in"));return}l(B)},[]);T.useEffect(()=>{if(!Q3(o==null?void 0:o.state))return;const B=window.setInterval(async()=>{try{const z=await fetch("/api/claude-accounts/login");z.ok&&l(await z.json())}catch{}},aL);return()=>window.clearInterval(B)},[o]);const U=T.useRef(n);U.current=n;const L=T.useRef(nL());T.useEffect(()=>{var B;(o==null?void 0:o.state)==="awaiting_code"&&((B=S.current)==null||B.focus()),L.current.shouldAnnounce(o==null?void 0:o.state)&&U.current()},[o==null?void 0:o.state]),T.useEffect(()=>{var B;r==="paste"&&((B=k.current)==null||B.focus())},[r]);const O=T.useCallback(async()=>{var z;m(!0),w(null);const B=await eu({action:"login-code",code:u}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){w(cu(B,"the code was not accepted")),B!=null&&B.state&&l(B),(z=S.current)==null||z.select();return}c(""),l(B)},[u,o]),q=T.useCallback(async()=>{m(!0),w(null);const B=await eu({action:"import",blob:h}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){w(cu(B,"the import failed"));return}p(""),_({added:B.added===!0,num:B.num??null,email:B.email??null}),n()},[h,n]),G=(o==null?void 0:o.state)==="done"?o.account:null,F=bC(o==null?void 0:o.state)||!!(y&&b.current&&!d),j=eL({state:o==null?void 0:o.state,serverError:o==null?void 0:o.error,localError:y});return g.jsx("div",{className:"modal-backdrop",onClick:I,role:"presentation",children:g.jsxs("div",{ref:P,className:"modal aa-modal",onClick:B=>B.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[g.jsxs("header",{className:"modal-head",children:[g.jsx("div",{className:"modal-title",children:g.jsxs("span",{className:"aa-tabs",role:"tablist",children:[g.jsx("button",{type:"button",role:"tab","aria-selected":r==="login",className:`aa-tab${r==="login"?" on":""}`,onClick:()=>i("login"),children:"Sign in"}),g.jsx("button",{type:"button",role:"tab","aria-selected":r==="paste",className:`aa-tab${r==="paste"?" on":""}`,onClick:()=>i("paste"),children:"Paste a share"})]})}),g.jsx("div",{className:"modal-actions",children:g.jsx("button",{type:"button",className:"btn icon-btn",onClick:I,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),g.jsx("section",{className:"modal-body aa-body",children:r==="login"?G?g.jsxs("div",{className:"aa-done",children:[g.jsx(Nv,{ref:C}),g.jsx(Kx,{anchor:C}),g.jsx("h4",{children:G.added?`Account ${G.num} added`:"Credentials refreshed"}),g.jsxs("p",{className:"aa-note",children:[g.jsx("strong",{children:G.email}),G.added?" is in the rotation. The account you were using is still active.":" was already managed, so its stored credentials were replaced."]}),g.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"})]}):(o==null?void 0:o.state)==="awaiting_code"||(o==null?void 0:o.state)==="registering"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"1 · Approve in the browser"}),g.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),g.jsx("a",{className:"aa-link",href:o.url??"#",target:"_blank",rel:"noreferrer noopener",children:o.url})]}),g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"2 · Paste the code it gives you"}),g.jsxs("div",{className:"aa-field",children:[g.jsx("input",{ref:S,type:"text",value:u,onChange:B=>c(B.target.value),onKeyDown:B=>{B.key==="Enter"&&u.trim()&&!d&&O()},placeholder:"paste the code here",spellCheck:!1,autoComplete:"off","aria-label":"Sign-in code",disabled:o.state==="registering"}),g.jsx("button",{type:"button",className:"btn primary",disabled:d||!u.trim()||o.state==="registering",onClick:O,children:o.state==="registering"?"registering…":"Continue"})]}),(y||o.error)&&g.jsx("p",{className:"aa-err",children:y??o.error}),g.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."})]})]}):F?g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:j.title}),g.jsx("p",{className:"aa-err",children:j.message}),g.jsx("button",{type:"button",className:"btn",onClick:()=>{b.current=!1,l(null),w(null),A()},children:"Try again"})]}):d||b.current?g.jsx("div",{className:"aa-step",children:g.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):g.jsxs("div",{className:"aa-step aa-primer",children:[g.jsx("h4",{children:"Sign in to Anthropic"}),g.jsx("p",{className:"aa-note",children:"Opens a browser tab where you approve the sign-in, then asks for the code it shows you. claude-swap records the account when it completes, and the account you are using now stays active."}),g.jsx("div",{className:"aa-actions",children:g.jsx("button",{type:"button",ref:E,className:"btn primary",onClick:A,disabled:d,children:"Open the sign-in page"})})]}):N?g.jsxs("div",{className:"aa-done",children:[g.jsx(Nv,{ref:C}),N.added&&g.jsx(Kx,{anchor:C}),g.jsx("h4",{children:N.added?`Account ${N.num} imported`:"Already here"}),g.jsx("p",{className:"aa-note",children:N.added?g.jsxs(g.Fragment,{children:[N.email?g.jsx("strong",{children:N.email}):"That account"," is in the rotation now. Nothing changed on the deck you copied it from."]}):"This deck already holds that account, so nothing changed."}),g.jsxs("div",{className:"aa-actions",children:[g.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"}),g.jsx("button",{type:"button",className:"btn",onClick:()=>_(null),children:"Import another"})]})]}):g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"Paste an account shared from another deck"}),g.jsxs("div",{className:"aa-field",children:[g.jsx("input",{ref:k,type:"text",value:h,onChange:B=>p(B.target.value),onKeyDown:B=>{B.key==="Enter"&&h.trim()&&!d&&q()},placeholder:"ccdeck1:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),g.jsx("button",{type:"button",className:"btn primary",disabled:d||!h.trim(),onClick:q,children:d?"importing…":"Import"})]}),y&&g.jsx("p",{className:"aa-err",children:y}),g.jsxs("p",{className:"aa-note",children:["Use ",g.jsx("strong",{children:"share"})," on an account in the other deck. A share carries a live login and expires ten minutes after it is made."]})]})})]})})}function uL(e,n){const r=new Set(e),i=e.length?Math.max(...e):0;return[...new Set([...e,i+1])].sort((o,l)=>o-l).map(o=>{const l=o===n?"here":r.has(o)?"swap":"free";return{slot:o,kind:l,label:l==="here"?`slot ${o}`:`slot ${o} · ${l}`}})}function cL(e,n,r){if(!(r!=null&&r.ok))return null;const i=Number.isInteger(r.to)?r.to:null;if(i==null)return{menuFor:null,confirmRemove:null,shareFor:null,swapNote:null};const o=r.swapped===!0&&i!==n;return{menuFor:e.menuFor===n?i:o&&e.menuFor===i?n:e.menuFor,confirmRemove:null,shareFor:null,swapNote:o?{at:i,displaced:n}:null}}const dL=64;function fL(e,n){const r=e.trim();return{alias:r,commit:r!==(n??"").trim()}}const hL=Object.freeze({text:"couldn't reach the deck server",reload:!0});async function Jx(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function pL(e){const n=e.find(i=>!i.ok);if(!n)return null;const r=yo(n.body);return{text:Ev(n.body,`the deck server answered ${n.status}`),...r?{raw:r}:{},reload:!0}}function e_(e,n){return n?e!=null&&e.reload&&e.text===n.text&&e.raw===n.raw?e:n:e!=null&&e.reload?null:e}const t_=15e3,mL=8e3,gL=1800,vL=3e4,yL=[70,80,85,90,95];function wL(e,n){const r=e-n;if(r<=0)return null;const i=Math.floor(r/86400),o=Math.floor(r%86400/3600),l=Math.floor(r%3600/60);return i>0?`${i}d ${o}h`:o>0?`${o}h ${l}m`:`${l}m`}function n_(e,n){const r=n-Math.floor(e/1e3);return r<60?"just now":r<3600?`${Math.floor(r/60)}m ago`:r<86400?`${Math.floor(r/3600)}h ago`:`${Math.floor(r/86400)}d ago`}function xL(e,n){if(!e)return"";const r=Math.floor(e/1e3)-n;return r<=0?" · due":r<60?` · next in ${r}s`:` · next in ${Math.round(r/60)}m`}function _L(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 bL({lane:e,nowSec:n}){const r=Math.min(100,Math.max(0,e.pct)),i=r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",o=e.resetAt?wL(e.resetAt,n):null;return g.jsxs("div",{className:"ap-lane",children:[g.jsx("span",{className:"ap-lane-label",children:e.label}),g.jsx("div",{className:"ap-lane-track",children:g.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:i,opacity:r===0?.4:1}})}),g.jsxs("span",{className:"ap-lane-pct",style:{color:i},children:[r,"%"]}),g.jsx("span",{className:"ap-lane-reset",children:o?`resets ${o}`:""})]})}async function SL(e){var r;let n=!1;try{n=await Promise.race([((r=navigator.clipboard)==null?void 0:r.writeText(e).then(()=>!0))??Promise.resolve(!1),new Promise(i=>window.setTimeout(()=>i(!1),500))])}catch{n=!1}if(n)return!0;try{const i=document.createElement("textarea");i.value=e,i.setAttribute("readonly",""),i.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(i),i.select(),n=document.execCommand("copy"),i.remove()}catch{n=!1}return n}function kL(e,n){const r=Math.round(e/1e3)-n;return r<=0?{text:"expired",tone:"gone"}:r<60?{text:`expires in ${r}s`,tone:"soon"}:{text:`expires in ${Math.round(r/60)}m`,tone:"ok"}}function EL({onClose:e}){var re,le,fe;const[n,r]=T.useState(null),[i,o]=T.useState(null),[l,u]=T.useState(null),[c,h]=T.useState(!1),[p,d]=T.useState(null),[m,y]=T.useState(null),[w,N]=T.useState(()=>Math.floor(Date.now()/1e3)),_=T.useRef(null),[b,S]=T.useState(null),[k,E]=T.useState(!1),[C,I]=T.useState(""),[P,A]=T.useState(null),[U,L]=T.useState(null),[O,q]=T.useState(null),[G,F]=T.useState(!1),[j,B]=T.useState(null),z=T.useCallback(async(te=!1)=>{te&&h(!0);const ce=new AbortController,Ce=window.setTimeout(()=>ce.abort(),vL);try{const[ve,je]=await Promise.all([fetch(`/api/claude-accounts${te?"?refresh=1":""}`,{signal:ce.signal}),fetch("/api/cswap-auto",{signal:ce.signal})]);ve.ok&&r(await ve.json()),je.ok&&o(await je.json());const ye=pL([await Jx(ve),await Jx(je)]);y(ke=>e_(ke,ye))}catch{y(ve=>e_(ve,hL))}finally{window.clearTimeout(Ce),te&&h(!1)}},[]),ne=T.useCallback(async(te,ce)=>{u(ce),y(null);try{const ve=await(await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(te)})).json().catch(()=>null);return ve!=null&&ve.ok||y({text:Ev(ve,"command failed"),raw:yo(ve)}),ve}catch{return y({text:"server unreachable"}),null}finally{u(null)}},[]),Z=T.useCallback(async(te,ce)=>{u(ce),y(null);try{const ve=await(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(te)})).json().catch(()=>null);return ve!=null&&ve.ok||y({text:cu(ve,"command failed")}),ve}catch{return y({text:"server unreachable"}),null}finally{u(null)}},[]);T.useEffect(()=>(z(!0),_.current=window.setInterval(()=>z(!1),t_),()=>{_.current!=null&&window.clearInterval(_.current)}),[z]),T.useEffect(()=>{const te=window.setInterval(()=>N(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(te)},[]);const $=((re=i==null?void 0:i.settings["autoswitch.threshold"])==null?void 0:re.value)??"90",Q=(le=n==null?void 0:n.accounts)==null?void 0:le.find(te=>te.active),M=Q!=null&&Q.lanes.length?Math.max(...Q.lanes.map(te=>te.pct)):null,V=M!=null&&M>=Number($)-15,Y=async te=>{d(te),y(null);try{const Ce=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:te})})).json().catch(()=>null);Ce!=null&&Ce.ok||y({text:Ev(Ce,"the switch failed"),raw:yo(Ce)}),await z(!0)}catch{y({text:"server unreachable"})}finally{d(null)}},H=async(te,ce)=>{const{commit:Ce,alias:ve}=fL(C,ce);if(Ce){const je=await Z({action:"alias",account:te,alias:ve},`alias-${te}`);if(await z(!0),!(je!=null&&je.ok))return;I(ve)}A(te),window.setTimeout(()=>A(je=>je===te?null:je),gL)},J=async(te,ce)=>{const Ce=await Z({action:"move",account:te,slot:ce},`move-${te}`),ve=cL({menuFor:b,shareFor:(O==null?void 0:O.num)??null},te,Ce);if(await z(!0),ve){S(ve.menuFor),L(ve.confirmRemove),ve.shareFor==null&&(q(null),F(!1)),B(ve.swapNote);const je=ve.swapNote;je&&window.setTimeout(()=>B(ye=>ye===je?null:ye),mL)}};return g.jsxs("div",{className:"accounts-panel",id:"accounts-panel","aria-label":"Claude accounts",children:[g.jsxs("div",{className:"ap-header",children:[g.jsx("h3",{children:"Accounts"}),g.jsxs("div",{className:"ap-header-right",children:[g.jsx("button",{type:"button",className:"btn ap-add",onClick:()=>E(!0),title:"Sign in to another Claude account, or paste one shared from another deck",children:"+"}),g.jsx("button",{type:"button",className:"btn ap-refresh",onClick:()=>z(!0),disabled:c,"aria-label":"Reload accounts",title:"Reload from claude-swap",children:c?"…":"↻"}),g.jsx("button",{type:"button",className:"btn icon-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:"×"})]})]}),n==null?m?g.jsxs("div",{className:"ap-empty",role:"alert",children:[g.jsx("span",{title:m.raw||void 0,children:m.text}),g.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",t_/1e3," seconds."]}),g.jsx("button",{type:"button",className:"ap-fix",disabled:c,onClick:()=>z(!0),children:c?"trying…":"try again"})]}):g.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?g.jsxs(g.Fragment,{children:[(fe=n.accounts)==null?void 0:fe.map(te=>g.jsxs("div",{className:`ap-account${te.active?" active":""}${te.disabled?" disabled":""}`,children:[g.jsxs("div",{className:"ap-account-head",children:[g.jsx("span",{className:"ap-num",children:te.num}),te.alias&&g.jsx("span",{className:"ap-alias",title:te.alias,children:te.alias}),g.jsx("span",{className:"ap-email",title:te.org??void 0,children:te.email}),g.jsx("button",{type:"button",className:`ap-more${b===te.num?" on":""}`,"aria-label":`Manage account ${te.num}`,"aria-expanded":b===te.num,"aria-controls":b===te.num?`ap-manage-${te.num}`:void 0,title:"Share, rename, move, remove",onClick:()=>{S(b===te.num?null:te.num),I(te.alias??""),L(null),q(null),F(!1),B(null),A(null)},children:"⋯"}),te.active?g.jsx("span",{className:"ap-badge-active",children:"● active"}):g.jsx("button",{type:"button",className:"btn ap-switch",disabled:p!=null||te.disabled,onClick:()=>Y(te.num),title:te.disabled?"Held out of rotation":`Switch to ${te.alias??te.email}`,children:p===te.num?"…":"switch"})]}),te.lanes.length>0?te.lanes.map(ce=>g.jsx(bL,{lane:ce,nowSec:w},ce.id)):g.jsx("div",{className:"ap-hint",children:"No usage recorded yet."}),g.jsxs("div",{className:"ap-meta",children:[te.error&&(()=>{const ce=_L(te.error);return g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"ap-err",title:ce.hint,children:ce.text}),ce.fixable&&g.jsx("button",{type:"button",className:"ap-fix",onClick:()=>E(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"sign in again"})]})})(),((i==null?void 0:i.enabled)||(i==null?void 0:i.external))&&!te.active&&g.jsx("button",{type:"button",className:"ap-rotate",disabled:l!=null,onClick:()=>ne({action:"account",account:te.num,enabled:te.disabled},`rot-${te.num}`).then(()=>z(!0)),title:te.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",children:te.disabled?"held out":"in rotation"}),te.fetchedAt?g.jsxs("span",{className:`ap-age${te.stale?" 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 ",n_(te.fetchedAt,w),xL(te.nextAt,w)]}):g.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})]}),b===te.num&&g.jsxs("div",{className:"ap-manage",id:`ap-manage-${te.num}`,role:"group","aria-label":`Manage account ${te.num}`,children:[g.jsxs("div",{className:"ap-manage-name",children:[g.jsx("label",{className:"vis-hidden",htmlFor:`ap-alias-${te.num}`,children:"Alias"}),g.jsx("input",{id:`ap-alias-${te.num}`,className:"ap-manage-input",type:"text",value:C,onChange:ce=>I(ce.target.value),onKeyDown:ce=>{ce.key==="Enter"&&H(te.num,te.alias)},maxLength:dL,placeholder:"e.g. work",spellCheck:!1,autoFocus:!0}),g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,onClick:()=>H(te.num,te.alias),title:"A short name to show instead of the email",children:P===te.num?"saved":"save"})]}),g.jsxs("div",{className:"ap-manage-acts",children:[g.jsx("label",{className:"vis-hidden",htmlFor:`ap-slot-${te.num}`,children:"Slot"}),g.jsx("span",{className:"ap-field",children:g.jsx("select",{id:`ap-slot-${te.num}`,value:String(te.num),disabled:l!=null,onChange:ce=>J(te.num,Number(ce.target.value)),children:uL((n.accounts??[]).map(ce=>ce.num),te.num).map(ce=>g.jsx("option",{value:ce.slot,children:ce.label},ce.slot))})}),g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,title:`Copy this account to another ${tn}. 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:async()=>{F(!1);const ce=await Z({action:"share",account:te.num},`share-${te.num}`);ce!=null&&ce.ok&&q({num:te.num,blob:ce.blob,expiresAt:ce.expiresAt})},children:"share"}),g.jsx("button",{type:"button",className:`ap-manage-btn danger${U===te.num?" armed":""}`,disabled:l!=null,title:U===te.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{if(U!==te.num){L(te.num),window.setTimeout(()=>L(ce=>ce===te.num?null:ce),4e3);return}L(null),Z({action:"remove",account:te.num},`rm-${te.num}`).then(()=>{S(null),z(!0)})},children:U===te.num?"confirm":"remove"})]}),(j==null?void 0:j.at)===te.num&&(()=>{var ve;const ce=(ve=n.accounts)==null?void 0:ve.find(je=>je.num===j.displaced),Ce=(ce==null?void 0:ce.alias)??(ce==null?void 0:ce.email)??"the account that was there";return g.jsxs("span",{className:"ap-manage-hint ap-manage-swap",title:`Slot ${j.at} was taken, so the two accounts traded places: ${Ce} now holds slot ${j.displaced}.`,children:["swapped with slot ",j.displaced]})})(),(O==null?void 0:O.num)===te.num&&(()=>{const ce=kL(O.expiresAt,w),Ce=ce.tone==="gone";return g.jsxs("div",{className:`ap-share${Ce?" expired":""}`,children:[g.jsx("code",{className:"ap-share-blob",children:O.blob}),g.jsxs("div",{className:"ap-share-foot",children:[g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,onClick:async()=>{if(Ce){F(!1);const ve=await Z({action:"share",account:te.num},`share-${te.num}`);ve!=null&&ve.ok&&q({num:te.num,blob:ve.blob,expiresAt:ve.expiresAt});return}await SL(O.blob)&&(F(!0),window.setTimeout(()=>F(!1),1800))},children:Ce?"make a new share":G?"copied":"copy"}),g.jsxs("span",{className:"ap-manage-hint",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:[g.jsx("span",{className:"ap-share-warn",children:"this is the password"})," · ",g.jsx("span",{className:`ap-share-expiry ${ce.tone}`,children:ce.text})]})]})]})})()]})]},te.num)),(i==null?void 0:i.ok)&&g.jsxs("div",{className:"ap-auto",children:[g.jsxs("div",{className:"ap-auto-head",children:[g.jsx("span",{className:"ap-auto-title",children:"Auto-switch"}),g.jsxs("span",{className:"ap-auto-ctl",children:[M!=null&&g.jsxs("span",{className:`ap-auto-now${V?" near":""}`,children:[Math.round(M),"%"]}),g.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:g.jsx("select",{"aria-label":"Switch threshold",value:$,disabled:l!=null,onChange:te=>ne({action:"setting",key:"autoswitch.threshold",value:te.target.value},"threshold").then(()=>z(!0)),children:yL.map(te=>g.jsxs("option",{value:te,children:[te,"%"]},te))})}),g.jsxs("button",{type:"button",className:`ap-auto-state${i.enabled?" live":""}`,role:"switch","aria-checked":i.enabled,disabled:l!=null,onClick:()=>ne({action:"enable",enabled:!i.enabled},"enable").then(()=>z(!0)),title:i.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:[g.jsx("i",{className:i.enabled?"ap-pulse":"ap-dot","aria-hidden":!0}),i.enabled?"on":"off"]})]})]}),i.external&&g.jsxs("p",{className:"ap-auto-note",children:[g.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",g.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",i.enabled?" — this toggle takes over when you stop it.":"."]}),i.lastTick&&g.jsx("div",{className:"ap-auto-foot",children:g.jsxs("span",{className:"ap-auto-result",children:["checked ",n_(i.lastTick.at,w)]})})]}),m&&g.jsxs("div",{className:"ap-failure",role:"alert",children:[g.jsx("span",{className:"ap-failure-text",title:m.raw||void 0,children:m.text}),g.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>y(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),g.jsx("p",{className:"ap-footnote",title:"Anthropic's usage endpoint allows roughly 28–30 requests per hour per account, shared by every tool on this machine — polling it from here would rate-limit your account. So the deck never fetches: it asks claude-swap to collect while this panel is open, at most once every three minutes, and claude-swap decides whether that touches the network at all.",children:"Collected by claude-swap while this panel is open."})]}):g.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"claude-swap isn't installed."}),g.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&g.jsx("code",{className:"ap-cmd",children:n.hint}),g.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",g.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"No accounts added yet."}),g.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",g.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"Couldn't read the account store."}),g.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})}),k&&g.jsx(lL,{onClose:()=>E(!1),onChanged:()=>z(!0)})]})}const NL=3e4;function CL({bundle:e,running:n,lastTried:r}){return!n||e===n?!1:r!==n}function RL({bundle:e,running:n,pending:r,lastTried:i}){return n?CL({bundle:e,running:n,lastTried:i})?"reload":r==null||r&&r!==n?"wait":"confirm":"wait"}function TL(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function jL({asked:e,reported:n}){return n?n!==e:!1}function AL(e){const n=e.thresholdMs??NL;return!e.enabled||e.kind!=="restart"||!e.canRestart?{idleSince:null,restart:!1}:e.busy?{idleSince:null,restart:!1}:e.idleSince==null?{idleSince:e.now,restart:!1}:e.now<e.idleSince?{idleSince:e.now,restart:!1}:{idleSince:e.idleSince,restart:e.now-e.idleSince>=n}}function IL({agentCount:e,onConfirm:n,onCancel:r}){const i=T.useRef(null),o=xo(r,{focusRef:i,layer:SP}),l=e===0?"This deletes the server's event log":`This removes ${e===1?"the one agent":`all ${e} agents`} on the canvas and deletes the server's event log`;return g.jsx("div",{className:"modal-backdrop",onClick:r,role:"presentation",children:g.jsxs("div",{ref:o,className:"modal clear-confirm",onClick:u=>u.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[g.jsxs("header",{className:"modal-head",children:[g.jsxs("div",{className:"modal-title",children:[g.jsx("span",{className:"status-dot err","aria-hidden":!0}),g.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),g.jsx("div",{className:"modal-actions",children:g.jsx("button",{type:"button",className:"btn icon-btn",onClick:r,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),g.jsxs("section",{className:"modal-body",children:[g.jsxs("p",{className:"modal-note",children:[l," — the file a restarted deck replays to rebuild what you see. Layout, pins and selection go with it. This cannot be undone."]}),g.jsxs("div",{className:"cc-actions",children:[g.jsx("button",{type:"button",ref:i,className:"btn",onClick:r,children:"Cancel"}),g.jsx("button",{type:"button",className:"btn danger",onClick:n,children:"Clear everything"})]})]})]})})}function ML(e,n){return e==="confirmation"?n.confirmOpen?"clear":"ignore":n.modalOpen||n.confirmOpen?"ignore":"confirm"}function OL(e){return e.slice().sort((n,r)=>n.y-r.y||n.x-r.x)}function PL(e,n,r){var u;if(e.length===0)return null;const i=OL(e),o=n?i.findIndex(c=>c.id===n):-1,l=o===-1?r===1?0:i.length-1:(o+r+i.length)%i.length;return((u=i[l])==null?void 0:u.id)??null}const LL=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Escape","Delete","Backspace"]);function qL(e,n){return n==null?{kind:"deck",nodeId:null}:e.key==="Enter"||e.key===" "?{kind:"activate",nodeId:n,additive:e.shiftKey}:LL.has(e.key)?{kind:"node",nodeId:n}:{kind:"deck",nodeId:n}}const $L=new Set(["","BODY","HTML","#DOCUMENT"]);function DL(e){return!e||Qv(e)?!1:!$L.has(String(e.tagName??"").toUpperCase())}function tu(e,n){if(n.size!==0)for(const r of Array.from(e.keys()))n.has(r)||e.delete(r)}function FL(e){const n=new Set;for(const r of e)n.add(r.id),n.add(`group:${r.sessionId}`);return n}function SC(e,n,r){return!n.has(e)||r.has(e)}function zL(e,n,r,i){return!n.has(e)&&SC(e,r,i)}function BL(e,n,r){const i={x:0,y:0};return n.set(e,i),r.add(e),i}function UL(e,n,r,i){r.set(e,n),i.delete(e)}const HL=40,WL=120;function VL(e,n){let r=null,i=0,o=Number.NEGATIVE_INFINITY;const l=()=>{r=null,o=n.now(),e()},u=()=>{r!=null&&(n.clearTimeout(r),r=null)},c=(h,p,d)=>{if(r!=null){if(i<=h)return;u()}const m=Math.min(d,Math.max(0,h-p));i=h,r=n.setTimeout(l,m)};return{live(h=HL){const p=n.now(),d=Math.max(o+h,p);if(d<=p){u(),l();return}c(d,p,h)},replay(h=WL){u(),i=n.now()+h,r=n.setTimeout(l,h)},flush(){u(),l()},cancel(){u()}}}function GL(){let e=!1,n=[];return{get paused(){return e},get size(){return n.length},accept(r){return e?(n.push(r),!1):!0},setPaused(r){if(e=r,r||n.length===0)return[];const i=n;return n=[],i}}}const YL="1",r_="agent-dag.schema",KL=["agent-dag.layout","agent-dag.viewport"];function kC(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function XL(e,n=YL){let r=null;try{r=e.getItem(r_)}catch{return[]}if(r===n)return[];const i=[];if(r!==null)for(const o of KL)try{e.getItem(o)!==null&&(e.removeItem(o),i.push(o))}catch{}try{e.setItem(r_,n)}catch{}return i}const EC="agent-dag.theme";function QL(e){return e==="light"?"light":"dark"}function ZL(){return QL(kC(EC))}function JL({waiting:e,running:n}){return{title:e>0?`(${e}) ${tn}`:tn,icon:e>0?"waiting":n>0?"running":"idle"}}const Dd={waiting:"#c97d12",running:"#2a90d4",idle:"#7e828c"};function Fd(e,n){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">${n==="waiting"?`<circle cx="16" cy="16" r="14.5" fill="${e}"/>`:`<circle cx="16" cy="16" r="12" fill="none" stroke="${e}" stroke-width="5"/>`+(n==="running"?`<circle cx="16" cy="16" r="5" fill="${e}"/>`:"")}</svg>`}const eq=Object.freeze({waiting:`data:image/svg+xml,${encodeURIComponent(Fd(Dd.waiting,"waiting"))}`,running:`data:image/svg+xml,${encodeURIComponent(Fd(Dd.running,"running"))}`,idle:`data:image/svg+xml,${encodeURIComponent(Fd(Dd.idle,"idle"))}`}),tq="No sessions are waiting for you.";function nq(e){if(e.length===0)return"";const[n,...r]=e;if(r.length===0)return`${n.label} is waiting for your permission.`;const i=`${r.length} more session${r.length===1?"":"s"}`;return`${n.label} and ${i} are waiting for your permission.`}function rq(e,n){return n!==""?n:e===""?"":tq}function sq(){let e=0;return{begin(){const n=++e;return()=>n===e},cancel(){e++}}}function iq(e,n=new Date){return new Date(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()-(e-1))).toISOString().slice(0,10).replace(/-/g,"")}function oq(e){return!e.answer||e.answer.range!==e.want?{phase:"busy",stale:!1}:e.answer.ok?{phase:e.answer.days>0?"chart":"empty",stale:e.loading}:{phase:"error",stale:e.loading}}function nu(e){const n=e.toLowerCase();return n.includes("opus")?"#c4b5fd":n.includes("sonnet")?"#7dd3fc":n.includes("haiku")?"#86efac":n.includes("gpt-5")||n.includes("gpt5")?"#fcd34d":n.includes("gpt")?"#fca5a5":n.includes("gemini")?"#a5b4fc":n.includes("codex")?"#fdba74":"#94a3b8"}const aq=[7,14,30,90];function lq(e){const[n,r]=T.useState(null),[i,o]=T.useState(!1),l=T.useRef(sq()).current,u=(c=!1)=>{const h=l.begin(),p=e;o(!0);const m=`/api/ccusage?since=${iq(p)}${c?"&refresh=1":""}`;fetch(m).then(y=>y.json()).then(y=>{h()&&r({range:p,resp:y})}).catch(()=>{h()&&r({range:p,resp:{ok:!1,reason:"unreachable"}})}).finally(()=>{h()&&o(!1)})};return T.useEffect(()=>(u(!1),()=>l.cancel()),[e]),{landed:n,loading:i,reload:()=>u(!0)}}function uq({onClose:e}){var C,I,P;const[n,r]=T.useState(30),[i,o]=T.useState(null),{landed:l,loading:u,reload:c}=lq(n),h=T.useRef(null),p=xo(e,{focusRef:h}),d=oq({loading:u,want:n,answer:l&&{range:l.range,ok:l.resp.ok===!0,days:((C=l.resp.days)==null?void 0:C.length)??0}}),m=d.phase==="chart"?l.resp.days??[]:[],y=T.useMemo(()=>m.reduce((A,U)=>Math.max(A,U.totalCost),0),[m]),{totalCost:w,totalTok:N,inOut:_,cacheRead:b,modelCosts:S}=T.useMemo(()=>{let A=0,U=0,L=0,O=0;const q=new Map;for(const G of m){A+=G.totalCost,U+=G.totalTokens,L+=G.inputTokens+G.outputTokens,O+=G.cacheReadTokens;for(const F of G.modelBreakdowns)q.set(F.modelName,(q.get(F.modelName)??0)+F.cost)}return{totalCost:A,totalTok:U,inOut:L,cacheRead:O,modelCosts:q}},[m]),k=T.useMemo(()=>Array.from(S.entries()).sort((A,U)=>U[1]-A[1]),[S]),E=i?m.find(A=>A.period===i)??null:null;return g.jsx("div",{className:"uh-backdrop",onClick:e,role:"presentation",children:g.jsxs("div",{ref:p,className:"uh-modal",onClick:A=>A.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Usage history",children:[g.jsxs("header",{className:"uh-head",children:[g.jsxs("div",{className:"uh-titlewrap",children:[g.jsx("div",{className:"uh-title",children:"Usage history"}),g.jsx("div",{className:"uh-sub",children:"via ccusage · local Claude / Codex logs"})]}),g.jsx("div",{className:"uh-range",role:"tablist","aria-label":"Range",children:aq.map(A=>g.jsxs("button",{role:"tab","aria-selected":n===A,className:`uh-range-btn${n===A?" on":""}`,onClick:()=>{r(A),o(null)},children:[A,"d"]},A))}),g.jsx("button",{className:"btn icon-btn uh-reload",onClick:c,disabled:u,title:"Re-run ccusage","aria-label":"Reload",children:u?"…":"↻"}),g.jsx("button",{ref:h,className:"uh-close",onClick:e,"aria-label":"Close",children:"×"})]}),d.phase==="busy"?g.jsx("div",{className:"uh-status","aria-busy":"true",children:l?"running ccusage…":"running ccusage… (first run downloads the package)"}):d.phase==="error"?g.jsxs("div",{className:"uh-status uh-err",title:yo(l.resp)||void 0,children:[oL(l.resp,"ccusage did not report usage"),g.jsx("div",{children:g.jsx("button",{className:"btn uh-retry",onClick:c,disabled:u,children:u?"trying…":"Try again"})})]}):d.phase==="empty"?g.jsx("div",{className:`uh-status${d.stale?" uh-stale":""}`,"aria-busy":d.stale||void 0,children:"no usage in this range"}):g.jsxs("div",{className:d.stale?"uh-stale":void 0,"aria-busy":d.stale||void 0,children:[g.jsxs("div",{className:"uh-totals",children:[g.jsx(ru,{label:"total cost",val:ze(w),accent:!0}),g.jsx(ru,{label:"tokens",val:Dt(N)}),g.jsx(ru,{label:"input+output",val:Dt(_)}),g.jsx(ru,{label:"cache reads",val:Dt(b)})]}),g.jsx("div",{className:"uh-chart",role:"img","aria-label":"Daily cost by model",children:m.map(A=>{const U=y>0?A.totalCost/y*100:0,L=A.period===i;return g.jsxs("button",{className:`uh-bar-col${L?" sel":""}`,onClick:()=>o(L?null:A.period),title:`${A.period} · ${ze(A.totalCost)}`,style:{flexBasis:`${100/m.length}%`},children:[g.jsx("div",{className:"uh-bar",style:{height:`${Math.max(U,A.totalCost>0?2:0)}%`},children:A.modelBreakdowns.slice().sort((O,q)=>q.cost-O.cost).map(O=>{const q=A.totalCost>0?O.cost/A.totalCost*100:0;return g.jsx("div",{className:"uh-bar-seg",style:{height:`${q}%`,background:nu(O.modelName)}},O.modelName)})}),g.jsx("span",{className:"uh-bar-label",children:A.period.slice(5)})]},A.period)})}),g.jsx("div",{className:"uh-legend",children:k.map(([A,U])=>g.jsxs("span",{className:"uh-legend-item",children:[g.jsx("span",{className:"uh-legend-dot",style:{background:nu(A)}}),li(A)," ",g.jsx("span",{className:"uh-legend-cost",children:ze(U)})]},A))}),E&&g.jsxs("div",{className:"uh-detail",children:[g.jsxs("div",{className:"uh-detail-head",children:[g.jsx("span",{className:"uh-detail-date",children:E.period}),g.jsx("span",{className:"uh-detail-cost",children:ze(E.totalCost)}),(P=(I=E.metadata)==null?void 0:I.agents)!=null&&P.length?g.jsx("span",{className:"uh-detail-agents",children:E.metadata.agents.join(" · ")}):null]}),g.jsxs("div",{className:"uh-detail-mini",children:[g.jsx(su,{label:"input",val:Dt(E.inputTokens)}),g.jsx(su,{label:"output",val:Dt(E.outputTokens)}),g.jsx(su,{label:"cache write",val:Dt(E.cacheCreationTokens)}),g.jsx(su,{label:"cache read",val:Dt(E.cacheReadTokens)})]}),g.jsx("div",{className:"uh-detail-models",children:E.modelBreakdowns.slice().sort((A,U)=>U.cost-A.cost).map(A=>{const U=E.totalCost>0?A.cost/E.totalCost*100:0;return g.jsxs("div",{className:"uh-model-row",children:[g.jsxs("span",{className:"uh-model-name",children:[g.jsx("span",{className:"uh-legend-dot",style:{background:nu(A.modelName)}}),li(A.modelName)]}),g.jsx("span",{className:"uh-model-bar",children:g.jsx("span",{className:"uh-model-bar-fill",style:{width:`${U}%`,background:nu(A.modelName)}})}),g.jsx("span",{className:"uh-model-cost",children:ze(A.cost)})]},A.modelName)})})]})]})]})})}function ru({label:e,val:n,accent:r}){return g.jsxs("div",{className:"uh-stat",children:[g.jsx("span",{className:`uh-stat-val${r?" accent":""}`,children:n}),g.jsx("span",{className:"uh-stat-label",children:e})]})}function su({label:e,val:n}){return g.jsxs("div",{className:"uh-ministat",children:[g.jsx("span",{className:"uh-ministat-val",children:n}),g.jsx("span",{className:"uh-ministat-label",children:e})]})}function ey(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 zd,s_;function cq(){if(s_)return zd;s_=1;function e(){this.__data__=[],this.size=0}return zd=e,zd}var Bd,i_;function _o(){if(i_)return Bd;i_=1;function e(n,r){return n===r||n!==n&&r!==r}return Bd=e,Bd}var Ud,o_;function Mu(){if(o_)return Ud;o_=1;var e=_o();function n(r,i){for(var o=r.length;o--;)if(e(r[o][0],i))return o;return-1}return Ud=n,Ud}var Hd,a_;function dq(){if(a_)return Hd;a_=1;var e=Mu(),n=Array.prototype,r=n.splice;function i(o){var l=this.__data__,u=e(l,o);if(u<0)return!1;var c=l.length-1;return u==c?l.pop():r.call(l,u,1),--this.size,!0}return Hd=i,Hd}var Wd,l_;function fq(){if(l_)return Wd;l_=1;var e=Mu();function n(r){var i=this.__data__,o=e(i,r);return o<0?void 0:i[o][1]}return Wd=n,Wd}var Vd,u_;function hq(){if(u_)return Vd;u_=1;var e=Mu();function n(r){return e(this.__data__,r)>-1}return Vd=n,Vd}var Gd,c_;function pq(){if(c_)return Gd;c_=1;var e=Mu();function n(r,i){var o=this.__data__,l=e(o,r);return l<0?(++this.size,o.push([r,i])):o[l][1]=i,this}return Gd=n,Gd}var Yd,d_;function Ou(){if(d_)return Yd;d_=1;var e=cq(),n=dq(),r=fq(),i=hq(),o=pq();function l(u){var c=-1,h=u==null?0:u.length;for(this.clear();++c<h;){var p=u[c];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=i,l.prototype.set=o,Yd=l,Yd}var Kd,f_;function mq(){if(f_)return Kd;f_=1;var e=Ou();function n(){this.__data__=new e,this.size=0}return Kd=n,Kd}var Xd,h_;function gq(){if(h_)return Xd;h_=1;function e(n){var r=this.__data__,i=r.delete(n);return this.size=r.size,i}return Xd=e,Xd}var Qd,p_;function vq(){if(p_)return Qd;p_=1;function e(n){return this.__data__.get(n)}return Qd=e,Qd}var Zd,m_;function yq(){if(m_)return Zd;m_=1;function e(n){return this.__data__.has(n)}return Zd=e,Zd}var Jd,g_;function NC(){if(g_)return Jd;g_=1;var e=typeof zl=="object"&&zl&&zl.Object===Object&&zl;return Jd=e,Jd}var ef,v_;function nr(){if(v_)return ef;v_=1;var e=NC(),n=typeof self=="object"&&self&&self.Object===Object&&self,r=e||n||Function("return this")();return ef=r,ef}var tf,y_;function bo(){if(y_)return tf;y_=1;var e=nr(),n=e.Symbol;return tf=n,tf}var nf,w_;function wq(){if(w_)return nf;w_=1;var e=bo(),n=Object.prototype,r=n.hasOwnProperty,i=n.toString,o=e?e.toStringTag:void 0;function l(u){var c=r.call(u,o),h=u[o];try{u[o]=void 0;var p=!0}catch{}var d=i.call(u);return p&&(c?u[o]=h:delete u[o]),d}return nf=l,nf}var rf,x_;function xq(){if(x_)return rf;x_=1;var e=Object.prototype,n=e.toString;function r(i){return n.call(i)}return rf=r,rf}var sf,__;function ui(){if(__)return sf;__=1;var e=bo(),n=wq(),r=xq(),i="[object Null]",o="[object Undefined]",l=e?e.toStringTag:void 0;function u(c){return c==null?c===void 0?o:i:l&&l in Object(c)?n(c):r(c)}return sf=u,sf}var of,b_;function Ln(){if(b_)return of;b_=1;function e(n){var r=typeof n;return n!=null&&(r=="object"||r=="function")}return of=e,of}var af,S_;function $a(){if(S_)return af;S_=1;var e=ui(),n=Ln(),r="[object AsyncFunction]",i="[object Function]",o="[object GeneratorFunction]",l="[object Proxy]";function u(c){if(!n(c))return!1;var h=e(c);return h==i||h==o||h==r||h==l}return af=u,af}var lf,k_;function _q(){if(k_)return lf;k_=1;var e=nr(),n=e["__core-js_shared__"];return lf=n,lf}var uf,E_;function bq(){if(E_)return uf;E_=1;var e=_q(),n=(function(){var i=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return i?"Symbol(src)_1."+i:""})();function r(i){return!!n&&n in i}return uf=r,uf}var cf,N_;function CC(){if(N_)return cf;N_=1;var e=Function.prototype,n=e.toString;function r(i){if(i!=null){try{return n.call(i)}catch{}try{return i+""}catch{}}return""}return cf=r,cf}var df,C_;function Sq(){if(C_)return df;C_=1;var e=$a(),n=bq(),r=Ln(),i=CC(),o=/[\\^$.*+?()[\]{}|]/g,l=/^\[object .+?Constructor\]$/,u=Function.prototype,c=Object.prototype,h=u.toString,p=c.hasOwnProperty,d=RegExp("^"+h.call(p).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function m(y){if(!r(y)||n(y))return!1;var w=e(y)?d:l;return w.test(i(y))}return df=m,df}var ff,R_;function kq(){if(R_)return ff;R_=1;function e(n,r){return n==null?void 0:n[r]}return ff=e,ff}var hf,T_;function ci(){if(T_)return hf;T_=1;var e=Sq(),n=kq();function r(i,o){var l=n(i,o);return e(l)?l:void 0}return hf=r,hf}var pf,j_;function ty(){if(j_)return pf;j_=1;var e=ci(),n=nr(),r=e(n,"Map");return pf=r,pf}var mf,A_;function Pu(){if(A_)return mf;A_=1;var e=ci(),n=e(Object,"create");return mf=n,mf}var gf,I_;function Eq(){if(I_)return gf;I_=1;var e=Pu();function n(){this.__data__=e?e(null):{},this.size=0}return gf=n,gf}var vf,M_;function Nq(){if(M_)return vf;M_=1;function e(n){var r=this.has(n)&&delete this.__data__[n];return this.size-=r?1:0,r}return vf=e,vf}var yf,O_;function Cq(){if(O_)return yf;O_=1;var e=Pu(),n="__lodash_hash_undefined__",r=Object.prototype,i=r.hasOwnProperty;function o(l){var u=this.__data__;if(e){var c=u[l];return c===n?void 0:c}return i.call(u,l)?u[l]:void 0}return yf=o,yf}var wf,P_;function Rq(){if(P_)return wf;P_=1;var e=Pu(),n=Object.prototype,r=n.hasOwnProperty;function i(o){var l=this.__data__;return e?l[o]!==void 0:r.call(l,o)}return wf=i,wf}var xf,L_;function Tq(){if(L_)return xf;L_=1;var e=Pu(),n="__lodash_hash_undefined__";function r(i,o){var l=this.__data__;return this.size+=this.has(i)?0:1,l[i]=e&&o===void 0?n:o,this}return xf=r,xf}var _f,q_;function jq(){if(q_)return _f;q_=1;var e=Eq(),n=Nq(),r=Cq(),i=Rq(),o=Tq();function l(u){var c=-1,h=u==null?0:u.length;for(this.clear();++c<h;){var p=u[c];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=i,l.prototype.set=o,_f=l,_f}var bf,$_;function Aq(){if($_)return bf;$_=1;var e=jq(),n=Ou(),r=ty();function i(){this.size=0,this.__data__={hash:new e,map:new(r||n),string:new e}}return bf=i,bf}var Sf,D_;function Iq(){if(D_)return Sf;D_=1;function e(n){var r=typeof n;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?n!=="__proto__":n===null}return Sf=e,Sf}var kf,F_;function Lu(){if(F_)return kf;F_=1;var e=Iq();function n(r,i){var o=r.__data__;return e(i)?o[typeof i=="string"?"string":"hash"]:o.map}return kf=n,kf}var Ef,z_;function Mq(){if(z_)return Ef;z_=1;var e=Lu();function n(r){var i=e(this,r).delete(r);return this.size-=i?1:0,i}return Ef=n,Ef}var Nf,B_;function Oq(){if(B_)return Nf;B_=1;var e=Lu();function n(r){return e(this,r).get(r)}return Nf=n,Nf}var Cf,U_;function Pq(){if(U_)return Cf;U_=1;var e=Lu();function n(r){return e(this,r).has(r)}return Cf=n,Cf}var Rf,H_;function Lq(){if(H_)return Rf;H_=1;var e=Lu();function n(r,i){var o=e(this,r),l=o.size;return o.set(r,i),this.size+=o.size==l?0:1,this}return Rf=n,Rf}var Tf,W_;function ny(){if(W_)return Tf;W_=1;var e=Aq(),n=Mq(),r=Oq(),i=Pq(),o=Lq();function l(u){var c=-1,h=u==null?0:u.length;for(this.clear();++c<h;){var p=u[c];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=i,l.prototype.set=o,Tf=l,Tf}var jf,V_;function qq(){if(V_)return jf;V_=1;var e=Ou(),n=ty(),r=ny(),i=200;function o(l,u){var c=this.__data__;if(c instanceof e){var h=c.__data__;if(!n||h.length<i-1)return h.push([l,u]),this.size=++c.size,this;c=this.__data__=new r(h)}return c.set(l,u),this.size=c.size,this}return jf=o,jf}var Af,G_;function qu(){if(G_)return Af;G_=1;var e=Ou(),n=mq(),r=gq(),i=vq(),o=yq(),l=qq();function u(c){var h=this.__data__=new e(c);this.size=h.size}return u.prototype.clear=n,u.prototype.delete=r,u.prototype.get=i,u.prototype.has=o,u.prototype.set=l,Af=u,Af}var If,Y_;function ry(){if(Y_)return If;Y_=1;function e(n,r){for(var i=-1,o=n==null?0:n.length;++i<o&&r(n[i],i,n)!==!1;);return n}return If=e,If}var Mf,K_;function RC(){if(K_)return Mf;K_=1;var e=ci(),n=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return Mf=n,Mf}var Of,X_;function $u(){if(X_)return Of;X_=1;var e=RC();function n(r,i,o){i=="__proto__"&&e?e(r,i,{configurable:!0,enumerable:!0,value:o,writable:!0}):r[i]=o}return Of=n,Of}var Pf,Q_;function Du(){if(Q_)return Pf;Q_=1;var e=$u(),n=_o(),r=Object.prototype,i=r.hasOwnProperty;function o(l,u,c){var h=l[u];(!(i.call(l,u)&&n(h,c))||c===void 0&&!(u in l))&&e(l,u,c)}return Pf=o,Pf}var Lf,Z_;function Da(){if(Z_)return Lf;Z_=1;var e=Du(),n=$u();function r(i,o,l,u){var c=!l;l||(l={});for(var h=-1,p=o.length;++h<p;){var d=o[h],m=u?u(l[d],i[d],d,l,i):void 0;m===void 0&&(m=i[d]),c?n(l,d,m):e(l,d,m)}return l}return Lf=r,Lf}var qf,J_;function $q(){if(J_)return qf;J_=1;function e(n,r){for(var i=-1,o=Array(n);++i<n;)o[i]=r(i);return o}return qf=e,qf}var $f,e1;function vr(){if(e1)return $f;e1=1;function e(n){return n!=null&&typeof n=="object"}return $f=e,$f}var Df,t1;function Dq(){if(t1)return Df;t1=1;var e=ui(),n=vr(),r="[object Arguments]";function i(o){return n(o)&&e(o)==r}return Df=i,Df}var Ff,n1;function Fa(){if(n1)return Ff;n1=1;var e=Dq(),n=vr(),r=Object.prototype,i=r.hasOwnProperty,o=r.propertyIsEnumerable,l=e((function(){return arguments})())?e:function(u){return n(u)&&i.call(u,"callee")&&!o.call(u,"callee")};return Ff=l,Ff}var zf,r1;function bt(){if(r1)return zf;r1=1;var e=Array.isArray;return zf=e,zf}var ya={exports:{}},Bf,s1;function Fq(){if(s1)return Bf;s1=1;function e(){return!1}return Bf=e,Bf}ya.exports;var i1;function So(){return i1||(i1=1,(function(e,n){var r=nr(),i=Fq(),o=n&&!n.nodeType&&n,l=o&&!0&&e&&!e.nodeType&&e,u=l&&l.exports===o,c=u?r.Buffer:void 0,h=c?c.isBuffer:void 0,p=h||i;e.exports=p})(ya,ya.exports)),ya.exports}var Uf,o1;function Fu(){if(o1)return Uf;o1=1;var e=9007199254740991,n=/^(?:0|[1-9]\d*)$/;function r(i,o){var l=typeof i;return o=o??e,!!o&&(l=="number"||l!="symbol"&&n.test(i))&&i>-1&&i%1==0&&i<o}return Uf=r,Uf}var Hf,a1;function sy(){if(a1)return Hf;a1=1;var e=9007199254740991;function n(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return Hf=n,Hf}var Wf,l1;function zq(){if(l1)return Wf;l1=1;var e=ui(),n=sy(),r=vr(),i="[object Arguments]",o="[object Array]",l="[object Boolean]",u="[object Date]",c="[object Error]",h="[object Function]",p="[object Map]",d="[object Number]",m="[object Object]",y="[object RegExp]",w="[object Set]",N="[object String]",_="[object WeakMap]",b="[object ArrayBuffer]",S="[object DataView]",k="[object Float32Array]",E="[object Float64Array]",C="[object Int8Array]",I="[object Int16Array]",P="[object Int32Array]",A="[object Uint8Array]",U="[object Uint8ClampedArray]",L="[object Uint16Array]",O="[object Uint32Array]",q={};q[k]=q[E]=q[C]=q[I]=q[P]=q[A]=q[U]=q[L]=q[O]=!0,q[i]=q[o]=q[b]=q[l]=q[S]=q[u]=q[c]=q[h]=q[p]=q[d]=q[m]=q[y]=q[w]=q[N]=q[_]=!1;function G(F){return r(F)&&n(F.length)&&!!q[e(F)]}return Wf=G,Wf}var Vf,u1;function zu(){if(u1)return Vf;u1=1;function e(n){return function(r){return n(r)}}return Vf=e,Vf}var wa={exports:{}};wa.exports;var c1;function iy(){return c1||(c1=1,(function(e,n){var r=NC(),i=n&&!n.nodeType&&n,o=i&&!0&&e&&!e.nodeType&&e,l=o&&o.exports===i,u=l&&r.process,c=(function(){try{var h=o&&o.require&&o.require("util").types;return h||u&&u.binding&&u.binding("util")}catch{}})();e.exports=c})(wa,wa.exports)),wa.exports}var Gf,d1;function za(){if(d1)return Gf;d1=1;var e=zq(),n=zu(),r=iy(),i=r&&r.isTypedArray,o=i?n(i):e;return Gf=o,Gf}var Yf,f1;function TC(){if(f1)return Yf;f1=1;var e=$q(),n=Fa(),r=bt(),i=So(),o=Fu(),l=za(),u=Object.prototype,c=u.hasOwnProperty;function h(p,d){var m=r(p),y=!m&&n(p),w=!m&&!y&&i(p),N=!m&&!y&&!w&&l(p),_=m||y||w||N,b=_?e(p.length,String):[],S=b.length;for(var k in p)(d||c.call(p,k))&&!(_&&(k=="length"||w&&(k=="offset"||k=="parent")||N&&(k=="buffer"||k=="byteLength"||k=="byteOffset")||o(k,S)))&&b.push(k);return b}return Yf=h,Yf}var Kf,h1;function Bu(){if(h1)return Kf;h1=1;var e=Object.prototype;function n(r){var i=r&&r.constructor,o=typeof i=="function"&&i.prototype||e;return r===o}return Kf=n,Kf}var Xf,p1;function jC(){if(p1)return Xf;p1=1;function e(n,r){return function(i){return n(r(i))}}return Xf=e,Xf}var Qf,m1;function Bq(){if(m1)return Qf;m1=1;var e=jC(),n=e(Object.keys,Object);return Qf=n,Qf}var Zf,g1;function oy(){if(g1)return Zf;g1=1;var e=Bu(),n=Bq(),r=Object.prototype,i=r.hasOwnProperty;function o(l){if(!e(l))return n(l);var u=[];for(var c in Object(l))i.call(l,c)&&c!="constructor"&&u.push(c);return u}return Zf=o,Zf}var Jf,v1;function Wr(){if(v1)return Jf;v1=1;var e=$a(),n=sy();function r(i){return i!=null&&n(i.length)&&!e(i)}return Jf=r,Jf}var eh,y1;function Ss(){if(y1)return eh;y1=1;var e=TC(),n=oy(),r=Wr();function i(o){return r(o)?e(o):n(o)}return eh=i,eh}var th,w1;function Uq(){if(w1)return th;w1=1;var e=Da(),n=Ss();function r(i,o){return i&&e(o,n(o),i)}return th=r,th}var nh,x1;function Hq(){if(x1)return nh;x1=1;function e(n){var r=[];if(n!=null)for(var i in Object(n))r.push(i);return r}return nh=e,nh}var rh,_1;function Wq(){if(_1)return rh;_1=1;var e=Ln(),n=Bu(),r=Hq(),i=Object.prototype,o=i.hasOwnProperty;function l(u){if(!e(u))return r(u);var c=n(u),h=[];for(var p in u)p=="constructor"&&(c||!o.call(u,p))||h.push(p);return h}return rh=l,rh}var sh,b1;function di(){if(b1)return sh;b1=1;var e=TC(),n=Wq(),r=Wr();function i(o){return r(o)?e(o,!0):n(o)}return sh=i,sh}var ih,S1;function Vq(){if(S1)return ih;S1=1;var e=Da(),n=di();function r(i,o){return i&&e(o,n(o),i)}return ih=r,ih}var xa={exports:{}};xa.exports;var k1;function AC(){return k1||(k1=1,(function(e,n){var r=nr(),i=n&&!n.nodeType&&n,o=i&&!0&&e&&!e.nodeType&&e,l=o&&o.exports===i,u=l?r.Buffer:void 0,c=u?u.allocUnsafe:void 0;function h(p,d){if(d)return p.slice();var m=p.length,y=c?c(m):new p.constructor(m);return p.copy(y),y}e.exports=h})(xa,xa.exports)),xa.exports}var oh,E1;function IC(){if(E1)return oh;E1=1;function e(n,r){var i=-1,o=n.length;for(r||(r=Array(o));++i<o;)r[i]=n[i];return r}return oh=e,oh}var ah,N1;function MC(){if(N1)return ah;N1=1;function e(n,r){for(var i=-1,o=n==null?0:n.length,l=0,u=[];++i<o;){var c=n[i];r(c,i,n)&&(u[l++]=c)}return u}return ah=e,ah}var lh,C1;function OC(){if(C1)return lh;C1=1;function e(){return[]}return lh=e,lh}var uh,R1;function ay(){if(R1)return uh;R1=1;var e=MC(),n=OC(),r=Object.prototype,i=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,l=o?function(u){return u==null?[]:(u=Object(u),e(o(u),function(c){return i.call(u,c)}))}:n;return uh=l,uh}var ch,T1;function Gq(){if(T1)return ch;T1=1;var e=Da(),n=ay();function r(i,o){return e(i,n(i),o)}return ch=r,ch}var dh,j1;function ly(){if(j1)return dh;j1=1;function e(n,r){for(var i=-1,o=r.length,l=n.length;++i<o;)n[l+i]=r[i];return n}return dh=e,dh}var fh,A1;function Uu(){if(A1)return fh;A1=1;var e=jC(),n=e(Object.getPrototypeOf,Object);return fh=n,fh}var hh,I1;function PC(){if(I1)return hh;I1=1;var e=ly(),n=Uu(),r=ay(),i=OC(),o=Object.getOwnPropertySymbols,l=o?function(u){for(var c=[];u;)e(c,r(u)),u=n(u);return c}:i;return hh=l,hh}var ph,M1;function Yq(){if(M1)return ph;M1=1;var e=Da(),n=PC();function r(i,o){return e(i,n(i),o)}return ph=r,ph}var mh,O1;function LC(){if(O1)return mh;O1=1;var e=ly(),n=bt();function r(i,o,l){var u=o(i);return n(i)?u:e(u,l(i))}return mh=r,mh}var gh,P1;function qC(){if(P1)return gh;P1=1;var e=LC(),n=ay(),r=Ss();function i(o){return e(o,r,n)}return gh=i,gh}var vh,L1;function Kq(){if(L1)return vh;L1=1;var e=LC(),n=PC(),r=di();function i(o){return e(o,r,n)}return vh=i,vh}var yh,q1;function Xq(){if(q1)return yh;q1=1;var e=ci(),n=nr(),r=e(n,"DataView");return yh=r,yh}var wh,$1;function Qq(){if($1)return wh;$1=1;var e=ci(),n=nr(),r=e(n,"Promise");return wh=r,wh}var xh,D1;function $C(){if(D1)return xh;D1=1;var e=ci(),n=nr(),r=e(n,"Set");return xh=r,xh}var _h,F1;function Zq(){if(F1)return _h;F1=1;var e=ci(),n=nr(),r=e(n,"WeakMap");return _h=r,_h}var bh,z1;function ko(){if(z1)return bh;z1=1;var e=Xq(),n=ty(),r=Qq(),i=$C(),o=Zq(),l=ui(),u=CC(),c="[object Map]",h="[object Object]",p="[object Promise]",d="[object Set]",m="[object WeakMap]",y="[object DataView]",w=u(e),N=u(n),_=u(r),b=u(i),S=u(o),k=l;return(e&&k(new e(new ArrayBuffer(1)))!=y||n&&k(new n)!=c||r&&k(r.resolve())!=p||i&&k(new i)!=d||o&&k(new o)!=m)&&(k=function(E){var C=l(E),I=C==h?E.constructor:void 0,P=I?u(I):"";if(P)switch(P){case w:return y;case N:return c;case _:return p;case b:return d;case S:return m}return C}),bh=k,bh}var Sh,B1;function Jq(){if(B1)return Sh;B1=1;var e=Object.prototype,n=e.hasOwnProperty;function r(i){var o=i.length,l=new i.constructor(o);return o&&typeof i[0]=="string"&&n.call(i,"index")&&(l.index=i.index,l.input=i.input),l}return Sh=r,Sh}var kh,U1;function DC(){if(U1)return kh;U1=1;var e=nr(),n=e.Uint8Array;return kh=n,kh}var Eh,H1;function uy(){if(H1)return Eh;H1=1;var e=DC();function n(r){var i=new r.constructor(r.byteLength);return new e(i).set(new e(r)),i}return Eh=n,Eh}var Nh,W1;function e$(){if(W1)return Nh;W1=1;var e=uy();function n(r,i){var o=i?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.byteLength)}return Nh=n,Nh}var Ch,V1;function t$(){if(V1)return Ch;V1=1;var e=/\w*$/;function n(r){var i=new r.constructor(r.source,e.exec(r));return i.lastIndex=r.lastIndex,i}return Ch=n,Ch}var Rh,G1;function n$(){if(G1)return Rh;G1=1;var e=bo(),n=e?e.prototype:void 0,r=n?n.valueOf:void 0;function i(o){return r?Object(r.call(o)):{}}return Rh=i,Rh}var Th,Y1;function FC(){if(Y1)return Th;Y1=1;var e=uy();function n(r,i){var o=i?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.length)}return Th=n,Th}var jh,K1;function r$(){if(K1)return jh;K1=1;var e=uy(),n=e$(),r=t$(),i=n$(),o=FC(),l="[object Boolean]",u="[object Date]",c="[object Map]",h="[object Number]",p="[object RegExp]",d="[object Set]",m="[object String]",y="[object Symbol]",w="[object ArrayBuffer]",N="[object DataView]",_="[object Float32Array]",b="[object Float64Array]",S="[object Int8Array]",k="[object Int16Array]",E="[object Int32Array]",C="[object Uint8Array]",I="[object Uint8ClampedArray]",P="[object Uint16Array]",A="[object Uint32Array]";function U(L,O,q){var G=L.constructor;switch(O){case w:return e(L);case l:case u:return new G(+L);case N:return n(L,q);case _:case b:case S:case k:case E:case C:case I:case P:case A:return o(L,q);case c:return new G;case h:case m:return new G(L);case p:return r(L);case d:return new G;case y:return i(L)}}return jh=U,jh}var Ah,X1;function zC(){if(X1)return Ah;X1=1;var e=Ln(),n=Object.create,r=(function(){function i(){}return function(o){if(!e(o))return{};if(n)return n(o);i.prototype=o;var l=new i;return i.prototype=void 0,l}})();return Ah=r,Ah}var Ih,Q1;function BC(){if(Q1)return Ih;Q1=1;var e=zC(),n=Uu(),r=Bu();function i(o){return typeof o.constructor=="function"&&!r(o)?e(n(o)):{}}return Ih=i,Ih}var Mh,Z1;function s$(){if(Z1)return Mh;Z1=1;var e=ko(),n=vr(),r="[object Map]";function i(o){return n(o)&&e(o)==r}return Mh=i,Mh}var Oh,J1;function i$(){if(J1)return Oh;J1=1;var e=s$(),n=zu(),r=iy(),i=r&&r.isMap,o=i?n(i):e;return Oh=o,Oh}var Ph,eb;function o$(){if(eb)return Ph;eb=1;var e=ko(),n=vr(),r="[object Set]";function i(o){return n(o)&&e(o)==r}return Ph=i,Ph}var Lh,tb;function a$(){if(tb)return Lh;tb=1;var e=o$(),n=zu(),r=iy(),i=r&&r.isSet,o=i?n(i):e;return Lh=o,Lh}var qh,nb;function UC(){if(nb)return qh;nb=1;var e=qu(),n=ry(),r=Du(),i=Uq(),o=Vq(),l=AC(),u=IC(),c=Gq(),h=Yq(),p=qC(),d=Kq(),m=ko(),y=Jq(),w=r$(),N=BC(),_=bt(),b=So(),S=i$(),k=Ln(),E=a$(),C=Ss(),I=di(),P=1,A=2,U=4,L="[object Arguments]",O="[object Array]",q="[object Boolean]",G="[object Date]",F="[object Error]",j="[object Function]",B="[object GeneratorFunction]",z="[object Map]",ne="[object Number]",Z="[object Object]",$="[object RegExp]",Q="[object Set]",M="[object String]",V="[object Symbol]",Y="[object WeakMap]",H="[object ArrayBuffer]",J="[object DataView]",re="[object Float32Array]",le="[object Float64Array]",fe="[object Int8Array]",te="[object Int16Array]",ce="[object Int32Array]",Ce="[object Uint8Array]",ve="[object Uint8ClampedArray]",je="[object Uint16Array]",ye="[object Uint32Array]",ke={};ke[L]=ke[O]=ke[H]=ke[J]=ke[q]=ke[G]=ke[re]=ke[le]=ke[fe]=ke[te]=ke[ce]=ke[z]=ke[ne]=ke[Z]=ke[$]=ke[Q]=ke[M]=ke[V]=ke[Ce]=ke[ve]=ke[je]=ke[ye]=!0,ke[F]=ke[j]=ke[Y]=!1;function Ke(we,_e,Be,ft,ht,We){var $e,Je=_e&P,Xe=_e&A,vt=_e&U;if(Be&&($e=ht?Be(we,ft,ht,We):Be(we)),$e!==void 0)return $e;if(!k(we))return we;var ot=_(we);if(ot){if($e=y(we),!Je)return u(we,$e)}else{var yt=m(we),Gt=yt==j||yt==B;if(b(we))return l(we,Je);if(yt==Z||yt==L||Gt&&!ht){if($e=Xe||Gt?{}:N(we),!Je)return Xe?h(we,o($e,we)):c(we,i($e,we))}else{if(!ke[yt])return ht?we:{};$e=w(we,yt,Je)}}We||(We=new e);var It=We.get(we);if(It)return It;We.set(we,$e),E(we)?we.forEach(function(pt){$e.add(Ke(pt,_e,Be,pt,we,We))}):S(we)&&we.forEach(function(pt,mt){$e.set(mt,Ke(pt,_e,Be,mt,we,We))});var Ze=vt?Xe?d:p:Xe?I:C,wt=ot?void 0:Ze(we);return n(wt||we,function(pt,mt){wt&&(mt=pt,pt=we[mt]),r($e,mt,Ke(pt,_e,Be,mt,we,We))}),$e}return qh=Ke,qh}var $h,rb;function l$(){if(rb)return $h;rb=1;var e=UC(),n=4;function r(i){return e(i,n)}return $h=r,$h}var Dh,sb;function cy(){if(sb)return Dh;sb=1;function e(n){return function(){return n}}return Dh=e,Dh}var Fh,ib;function u$(){if(ib)return Fh;ib=1;function e(n){return function(r,i,o){for(var l=-1,u=Object(r),c=o(r),h=c.length;h--;){var p=c[n?h:++l];if(i(u[p],p,u)===!1)break}return r}}return Fh=e,Fh}var zh,ob;function dy(){if(ob)return zh;ob=1;var e=u$(),n=e();return zh=n,zh}var Bh,ab;function fy(){if(ab)return Bh;ab=1;var e=dy(),n=Ss();function r(i,o){return i&&e(i,o,n)}return Bh=r,Bh}var Uh,lb;function c$(){if(lb)return Uh;lb=1;var e=Wr();function n(r,i){return function(o,l){if(o==null)return o;if(!e(o))return r(o,l);for(var u=o.length,c=i?u:-1,h=Object(o);(i?c--:++c<u)&&l(h[c],c,h)!==!1;);return o}}return Uh=n,Uh}var Hh,ub;function Hu(){if(ub)return Hh;ub=1;var e=fy(),n=c$(),r=n(e);return Hh=r,Hh}var Wh,cb;function fi(){if(cb)return Wh;cb=1;function e(n){return n}return Wh=e,Wh}var Vh,db;function HC(){if(db)return Vh;db=1;var e=fi();function n(r){return typeof r=="function"?r:e}return Vh=n,Vh}var Gh,fb;function WC(){if(fb)return Gh;fb=1;var e=ry(),n=Hu(),r=HC(),i=bt();function o(l,u){var c=i(l)?e:n;return c(l,r(u))}return Gh=o,Gh}var Yh,hb;function VC(){return hb||(hb=1,Yh=WC()),Yh}var Kh,pb;function d$(){if(pb)return Kh;pb=1;var e=Hu();function n(r,i){var o=[];return e(r,function(l,u,c){i(l,u,c)&&o.push(l)}),o}return Kh=n,Kh}var Xh,mb;function f$(){if(mb)return Xh;mb=1;var e="__lodash_hash_undefined__";function n(r){return this.__data__.set(r,e),this}return Xh=n,Xh}var Qh,gb;function h$(){if(gb)return Qh;gb=1;function e(n){return this.__data__.has(n)}return Qh=e,Qh}var Zh,vb;function GC(){if(vb)return Zh;vb=1;var e=ny(),n=f$(),r=h$();function i(o){var l=-1,u=o==null?0:o.length;for(this.__data__=new e;++l<u;)this.add(o[l])}return i.prototype.add=i.prototype.push=n,i.prototype.has=r,Zh=i,Zh}var Jh,yb;function p$(){if(yb)return Jh;yb=1;function e(n,r){for(var i=-1,o=n==null?0:n.length;++i<o;)if(r(n[i],i,n))return!0;return!1}return Jh=e,Jh}var ep,wb;function YC(){if(wb)return ep;wb=1;function e(n,r){return n.has(r)}return ep=e,ep}var tp,xb;function KC(){if(xb)return tp;xb=1;var e=GC(),n=p$(),r=YC(),i=1,o=2;function l(u,c,h,p,d,m){var y=h&i,w=u.length,N=c.length;if(w!=N&&!(y&&N>w))return!1;var _=m.get(u),b=m.get(c);if(_&&b)return _==c&&b==u;var S=-1,k=!0,E=h&o?new e:void 0;for(m.set(u,c),m.set(c,u);++S<w;){var C=u[S],I=c[S];if(p)var P=y?p(I,C,S,c,u,m):p(C,I,S,u,c,m);if(P!==void 0){if(P)continue;k=!1;break}if(E){if(!n(c,function(A,U){if(!r(E,U)&&(C===A||d(C,A,h,p,m)))return E.push(U)})){k=!1;break}}else if(!(C===I||d(C,I,h,p,m))){k=!1;break}}return m.delete(u),m.delete(c),k}return tp=l,tp}var np,_b;function m$(){if(_b)return np;_b=1;function e(n){var r=-1,i=Array(n.size);return n.forEach(function(o,l){i[++r]=[l,o]}),i}return np=e,np}var rp,bb;function hy(){if(bb)return rp;bb=1;function e(n){var r=-1,i=Array(n.size);return n.forEach(function(o){i[++r]=o}),i}return rp=e,rp}var sp,Sb;function g$(){if(Sb)return sp;Sb=1;var e=bo(),n=DC(),r=_o(),i=KC(),o=m$(),l=hy(),u=1,c=2,h="[object Boolean]",p="[object Date]",d="[object Error]",m="[object Map]",y="[object Number]",w="[object RegExp]",N="[object Set]",_="[object String]",b="[object Symbol]",S="[object ArrayBuffer]",k="[object DataView]",E=e?e.prototype:void 0,C=E?E.valueOf:void 0;function I(P,A,U,L,O,q,G){switch(U){case k:if(P.byteLength!=A.byteLength||P.byteOffset!=A.byteOffset)return!1;P=P.buffer,A=A.buffer;case S:return!(P.byteLength!=A.byteLength||!q(new n(P),new n(A)));case h:case p:case y:return r(+P,+A);case d:return P.name==A.name&&P.message==A.message;case w:case _:return P==A+"";case m:var F=o;case N:var j=L&u;if(F||(F=l),P.size!=A.size&&!j)return!1;var B=G.get(P);if(B)return B==A;L|=c,G.set(P,A);var z=i(F(P),F(A),L,O,q,G);return G.delete(P),z;case b:if(C)return C.call(P)==C.call(A)}return!1}return sp=I,sp}var ip,kb;function v$(){if(kb)return ip;kb=1;var e=qC(),n=1,r=Object.prototype,i=r.hasOwnProperty;function o(l,u,c,h,p,d){var m=c&n,y=e(l),w=y.length,N=e(u),_=N.length;if(w!=_&&!m)return!1;for(var b=w;b--;){var S=y[b];if(!(m?S in u:i.call(u,S)))return!1}var k=d.get(l),E=d.get(u);if(k&&E)return k==u&&E==l;var C=!0;d.set(l,u),d.set(u,l);for(var I=m;++b<w;){S=y[b];var P=l[S],A=u[S];if(h)var U=m?h(A,P,S,u,l,d):h(P,A,S,l,u,d);if(!(U===void 0?P===A||p(P,A,c,h,d):U)){C=!1;break}I||(I=S=="constructor")}if(C&&!I){var L=l.constructor,O=u.constructor;L!=O&&"constructor"in l&&"constructor"in u&&!(typeof L=="function"&&L instanceof L&&typeof O=="function"&&O instanceof O)&&(C=!1)}return d.delete(l),d.delete(u),C}return ip=o,ip}var op,Eb;function y$(){if(Eb)return op;Eb=1;var e=qu(),n=KC(),r=g$(),i=v$(),o=ko(),l=bt(),u=So(),c=za(),h=1,p="[object Arguments]",d="[object Array]",m="[object Object]",y=Object.prototype,w=y.hasOwnProperty;function N(_,b,S,k,E,C){var I=l(_),P=l(b),A=I?d:o(_),U=P?d:o(b);A=A==p?m:A,U=U==p?m:U;var L=A==m,O=U==m,q=A==U;if(q&&u(_)){if(!u(b))return!1;I=!0,L=!1}if(q&&!L)return C||(C=new e),I||c(_)?n(_,b,S,k,E,C):r(_,b,A,S,k,E,C);if(!(S&h)){var G=L&&w.call(_,"__wrapped__"),F=O&&w.call(b,"__wrapped__");if(G||F){var j=G?_.value():_,B=F?b.value():b;return C||(C=new e),E(j,B,S,k,C)}}return q?(C||(C=new e),i(_,b,S,k,E,C)):!1}return op=N,op}var ap,Nb;function XC(){if(Nb)return ap;Nb=1;var e=y$(),n=vr();function r(i,o,l,u,c){return i===o?!0:i==null||o==null||!n(i)&&!n(o)?i!==i&&o!==o:e(i,o,l,u,r,c)}return ap=r,ap}var lp,Cb;function w$(){if(Cb)return lp;Cb=1;var e=qu(),n=XC(),r=1,i=2;function o(l,u,c,h){var p=c.length,d=p,m=!h;if(l==null)return!d;for(l=Object(l);p--;){var y=c[p];if(m&&y[2]?y[1]!==l[y[0]]:!(y[0]in l))return!1}for(;++p<d;){y=c[p];var w=y[0],N=l[w],_=y[1];if(m&&y[2]){if(N===void 0&&!(w in l))return!1}else{var b=new e;if(h)var S=h(N,_,w,l,u,b);if(!(S===void 0?n(_,N,r|i,h,b):S))return!1}}return!0}return lp=o,lp}var up,Rb;function QC(){if(Rb)return up;Rb=1;var e=Ln();function n(r){return r===r&&!e(r)}return up=n,up}var cp,Tb;function x$(){if(Tb)return cp;Tb=1;var e=QC(),n=Ss();function r(i){for(var o=n(i),l=o.length;l--;){var u=o[l],c=i[u];o[l]=[u,c,e(c)]}return o}return cp=r,cp}var dp,jb;function ZC(){if(jb)return dp;jb=1;function e(n,r){return function(i){return i==null?!1:i[n]===r&&(r!==void 0||n in Object(i))}}return dp=e,dp}var fp,Ab;function _$(){if(Ab)return fp;Ab=1;var e=w$(),n=x$(),r=ZC();function i(o){var l=n(o);return l.length==1&&l[0][2]?r(l[0][0],l[0][1]):function(u){return u===o||e(u,o,l)}}return fp=i,fp}var hp,Ib;function Eo(){if(Ib)return hp;Ib=1;var e=ui(),n=vr(),r="[object Symbol]";function i(o){return typeof o=="symbol"||n(o)&&e(o)==r}return hp=i,hp}var pp,Mb;function py(){if(Mb)return pp;Mb=1;var e=bt(),n=Eo(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,i=/^\w*$/;function o(l,u){if(e(l))return!1;var c=typeof l;return c=="number"||c=="symbol"||c=="boolean"||l==null||n(l)?!0:i.test(l)||!r.test(l)||u!=null&&l in Object(u)}return pp=o,pp}var mp,Ob;function b$(){if(Ob)return mp;Ob=1;var e=ny(),n="Expected a function";function r(i,o){if(typeof i!="function"||o!=null&&typeof o!="function")throw new TypeError(n);var l=function(){var u=arguments,c=o?o.apply(this,u):u[0],h=l.cache;if(h.has(c))return h.get(c);var p=i.apply(this,u);return l.cache=h.set(c,p)||h,p};return l.cache=new(r.Cache||e),l}return r.Cache=e,mp=r,mp}var gp,Pb;function S$(){if(Pb)return gp;Pb=1;var e=b$(),n=500;function r(i){var o=e(i,function(u){return l.size===n&&l.clear(),u}),l=o.cache;return o}return gp=r,gp}var vp,Lb;function k$(){if(Lb)return vp;Lb=1;var e=S$(),n=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,i=e(function(o){var l=[];return o.charCodeAt(0)===46&&l.push(""),o.replace(n,function(u,c,h,p){l.push(h?p.replace(r,"$1"):c||u)}),l});return vp=i,vp}var yp,qb;function Wu(){if(qb)return yp;qb=1;function e(n,r){for(var i=-1,o=n==null?0:n.length,l=Array(o);++i<o;)l[i]=r(n[i],i,n);return l}return yp=e,yp}var wp,$b;function E$(){if($b)return wp;$b=1;var e=bo(),n=Wu(),r=bt(),i=Eo(),o=e?e.prototype:void 0,l=o?o.toString:void 0;function u(c){if(typeof c=="string")return c;if(r(c))return n(c,u)+"";if(i(c))return l?l.call(c):"";var h=c+"";return h=="0"&&1/c==-1/0?"-0":h}return wp=u,wp}var xp,Db;function JC(){if(Db)return xp;Db=1;var e=E$();function n(r){return r==null?"":e(r)}return xp=n,xp}var _p,Fb;function Vu(){if(Fb)return _p;Fb=1;var e=bt(),n=py(),r=k$(),i=JC();function o(l,u){return e(l)?l:n(l,u)?[l]:r(i(l))}return _p=o,_p}var bp,zb;function Ba(){if(zb)return bp;zb=1;var e=Eo();function n(r){if(typeof r=="string"||e(r))return r;var i=r+"";return i=="0"&&1/r==-1/0?"-0":i}return bp=n,bp}var Sp,Bb;function Gu(){if(Bb)return Sp;Bb=1;var e=Vu(),n=Ba();function r(i,o){o=e(o,i);for(var l=0,u=o.length;i!=null&&l<u;)i=i[n(o[l++])];return l&&l==u?i:void 0}return Sp=r,Sp}var kp,Ub;function N$(){if(Ub)return kp;Ub=1;var e=Gu();function n(r,i,o){var l=r==null?void 0:e(r,i);return l===void 0?o:l}return kp=n,kp}var Ep,Hb;function C$(){if(Hb)return Ep;Hb=1;function e(n,r){return n!=null&&r in Object(n)}return Ep=e,Ep}var Np,Wb;function eR(){if(Wb)return Np;Wb=1;var e=Vu(),n=Fa(),r=bt(),i=Fu(),o=sy(),l=Ba();function u(c,h,p){h=e(h,c);for(var d=-1,m=h.length,y=!1;++d<m;){var w=l(h[d]);if(!(y=c!=null&&p(c,w)))break;c=c[w]}return y||++d!=m?y:(m=c==null?0:c.length,!!m&&o(m)&&i(w,m)&&(r(c)||n(c)))}return Np=u,Np}var Cp,Vb;function tR(){if(Vb)return Cp;Vb=1;var e=C$(),n=eR();function r(i,o){return i!=null&&n(i,o,e)}return Cp=r,Cp}var Rp,Gb;function R$(){if(Gb)return Rp;Gb=1;var e=XC(),n=N$(),r=tR(),i=py(),o=QC(),l=ZC(),u=Ba(),c=1,h=2;function p(d,m){return i(d)&&o(m)?l(u(d),m):function(y){var w=n(y,d);return w===void 0&&w===m?r(y,d):e(m,w,c|h)}}return Rp=p,Rp}var Tp,Yb;function nR(){if(Yb)return Tp;Yb=1;function e(n){return function(r){return r==null?void 0:r[n]}}return Tp=e,Tp}var jp,Kb;function T$(){if(Kb)return jp;Kb=1;var e=Gu();function n(r){return function(i){return e(i,r)}}return jp=n,jp}var Ap,Xb;function j$(){if(Xb)return Ap;Xb=1;var e=nR(),n=T$(),r=py(),i=Ba();function o(l){return r(l)?e(i(l)):n(l)}return Ap=o,Ap}var Ip,Qb;function Vr(){if(Qb)return Ip;Qb=1;var e=_$(),n=R$(),r=fi(),i=bt(),o=j$();function l(u){return typeof u=="function"?u:u==null?r:typeof u=="object"?i(u)?n(u[0],u[1]):e(u):o(u)}return Ip=l,Ip}var Mp,Zb;function rR(){if(Zb)return Mp;Zb=1;var e=MC(),n=d$(),r=Vr(),i=bt();function o(l,u){var c=i(l)?e:n;return c(l,r(u,3))}return Mp=o,Mp}var Op,Jb;function A$(){if(Jb)return Op;Jb=1;var e=Object.prototype,n=e.hasOwnProperty;function r(i,o){return i!=null&&n.call(i,o)}return Op=r,Op}var Pp,eS;function sR(){if(eS)return Pp;eS=1;var e=A$(),n=eR();function r(i,o){return i!=null&&n(i,o,e)}return Pp=r,Pp}var Lp,tS;function I$(){if(tS)return Lp;tS=1;var e=oy(),n=ko(),r=Fa(),i=bt(),o=Wr(),l=So(),u=Bu(),c=za(),h="[object Map]",p="[object Set]",d=Object.prototype,m=d.hasOwnProperty;function y(w){if(w==null)return!0;if(o(w)&&(i(w)||typeof w=="string"||typeof w.splice=="function"||l(w)||c(w)||r(w)))return!w.length;var N=n(w);if(N==h||N==p)return!w.size;if(u(w))return!e(w).length;for(var _ in w)if(m.call(w,_))return!1;return!0}return Lp=y,Lp}var qp,nS;function iR(){if(nS)return qp;nS=1;function e(n){return n===void 0}return qp=e,qp}var $p,rS;function oR(){if(rS)return $p;rS=1;var e=Hu(),n=Wr();function r(i,o){var l=-1,u=n(i)?Array(i.length):[];return e(i,function(c,h,p){u[++l]=o(c,h,p)}),u}return $p=r,$p}var Dp,sS;function aR(){if(sS)return Dp;sS=1;var e=Wu(),n=Vr(),r=oR(),i=bt();function o(l,u){var c=i(l)?e:r;return c(l,n(u,3))}return Dp=o,Dp}var Fp,iS;function M$(){if(iS)return Fp;iS=1;function e(n,r,i,o){var l=-1,u=n==null?0:n.length;for(o&&u&&(i=n[++l]);++l<u;)i=r(i,n[l],l,n);return i}return Fp=e,Fp}var zp,oS;function O$(){if(oS)return zp;oS=1;function e(n,r,i,o,l){return l(n,function(u,c,h){i=o?(o=!1,u):r(i,u,c,h)}),i}return zp=e,zp}var Bp,aS;function lR(){if(aS)return Bp;aS=1;var e=M$(),n=Hu(),r=Vr(),i=O$(),o=bt();function l(u,c,h){var p=o(u)?e:i,d=arguments.length<3;return p(u,r(c,4),h,d,n)}return Bp=l,Bp}var Up,lS;function P$(){if(lS)return Up;lS=1;var e=ui(),n=bt(),r=vr(),i="[object String]";function o(l){return typeof l=="string"||!n(l)&&r(l)&&e(l)==i}return Up=o,Up}var Hp,uS;function L$(){if(uS)return Hp;uS=1;var e=nR(),n=e("length");return Hp=n,Hp}var Wp,cS;function q$(){if(cS)return Wp;cS=1;var e="\\ud800-\\udfff",n="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",i="\\u20d0-\\u20ff",o=n+r+i,l="\\ufe0e\\ufe0f",u="\\u200d",c=RegExp("["+u+e+o+l+"]");function h(p){return c.test(p)}return Wp=h,Wp}var Vp,dS;function $$(){if(dS)return Vp;dS=1;var e="\\ud800-\\udfff",n="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",i="\\u20d0-\\u20ff",o=n+r+i,l="\\ufe0e\\ufe0f",u="["+e+"]",c="["+o+"]",h="\\ud83c[\\udffb-\\udfff]",p="(?:"+c+"|"+h+")",d="[^"+e+"]",m="(?:\\ud83c[\\udde6-\\uddff]){2}",y="[\\ud800-\\udbff][\\udc00-\\udfff]",w="\\u200d",N=p+"?",_="["+l+"]?",b="(?:"+w+"(?:"+[d,m,y].join("|")+")"+_+N+")*",S=_+N+b,k="(?:"+[d+c+"?",c,m,y,u].join("|")+")",E=RegExp(h+"(?="+h+")|"+k+S,"g");function C(I){for(var P=E.lastIndex=0;E.test(I);)++P;return P}return Vp=C,Vp}var Gp,fS;function D$(){if(fS)return Gp;fS=1;var e=L$(),n=q$(),r=$$();function i(o){return n(o)?r(o):e(o)}return Gp=i,Gp}var Yp,hS;function F$(){if(hS)return Yp;hS=1;var e=oy(),n=ko(),r=Wr(),i=P$(),o=D$(),l="[object Map]",u="[object Set]";function c(h){if(h==null)return 0;if(r(h))return i(h)?o(h):h.length;var p=n(h);return p==l||p==u?h.size:e(h).length}return Yp=c,Yp}var Kp,pS;function z$(){if(pS)return Kp;pS=1;var e=ry(),n=zC(),r=fy(),i=Vr(),o=Uu(),l=bt(),u=So(),c=$a(),h=Ln(),p=za();function d(m,y,w){var N=l(m),_=N||u(m)||p(m);if(y=i(y,4),w==null){var b=m&&m.constructor;_?w=N?new b:[]:h(m)?w=c(b)?n(o(m)):{}:w={}}return(_?e:r)(m,function(S,k,E){return y(w,S,k,E)}),w}return Kp=d,Kp}var Xp,mS;function B$(){if(mS)return Xp;mS=1;var e=bo(),n=Fa(),r=bt(),i=e?e.isConcatSpreadable:void 0;function o(l){return r(l)||n(l)||!!(i&&l&&l[i])}return Xp=o,Xp}var Qp,gS;function my(){if(gS)return Qp;gS=1;var e=ly(),n=B$();function r(i,o,l,u,c){var h=-1,p=i.length;for(l||(l=n),c||(c=[]);++h<p;){var d=i[h];o>0&&l(d)?o>1?r(d,o-1,l,u,c):e(c,d):u||(c[c.length]=d)}return c}return Qp=r,Qp}var Zp,vS;function U$(){if(vS)return Zp;vS=1;function e(n,r,i){switch(i.length){case 0:return n.call(r);case 1:return n.call(r,i[0]);case 2:return n.call(r,i[0],i[1]);case 3:return n.call(r,i[0],i[1],i[2])}return n.apply(r,i)}return Zp=e,Zp}var Jp,yS;function uR(){if(yS)return Jp;yS=1;var e=U$(),n=Math.max;function r(i,o,l){return o=n(o===void 0?i.length-1:o,0),function(){for(var u=arguments,c=-1,h=n(u.length-o,0),p=Array(h);++c<h;)p[c]=u[o+c];c=-1;for(var d=Array(o+1);++c<o;)d[c]=u[c];return d[o]=l(p),e(i,this,d)}}return Jp=r,Jp}var em,wS;function H$(){if(wS)return em;wS=1;var e=cy(),n=RC(),r=fi(),i=n?function(o,l){return n(o,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:r;return em=i,em}var tm,xS;function W$(){if(xS)return tm;xS=1;var e=800,n=16,r=Date.now;function i(o){var l=0,u=0;return function(){var c=r(),h=n-(c-u);if(u=c,h>0){if(++l>=e)return arguments[0]}else l=0;return o.apply(void 0,arguments)}}return tm=i,tm}var nm,_S;function cR(){if(_S)return nm;_S=1;var e=H$(),n=W$(),r=n(e);return nm=r,nm}var rm,bS;function Yu(){if(bS)return rm;bS=1;var e=fi(),n=uR(),r=cR();function i(o,l){return r(n(o,l,e),o+"")}return rm=i,rm}var sm,SS;function dR(){if(SS)return sm;SS=1;function e(n,r,i,o){for(var l=n.length,u=i+(o?1:-1);o?u--:++u<l;)if(r(n[u],u,n))return u;return-1}return sm=e,sm}var im,kS;function V$(){if(kS)return im;kS=1;function e(n){return n!==n}return im=e,im}var om,ES;function G$(){if(ES)return om;ES=1;function e(n,r,i){for(var o=i-1,l=n.length;++o<l;)if(n[o]===r)return o;return-1}return om=e,om}var am,NS;function Y$(){if(NS)return am;NS=1;var e=dR(),n=V$(),r=G$();function i(o,l,u){return l===l?r(o,l,u):e(o,n,u)}return am=i,am}var lm,CS;function K$(){if(CS)return lm;CS=1;var e=Y$();function n(r,i){var o=r==null?0:r.length;return!!o&&e(r,i,0)>-1}return lm=n,lm}var um,RS;function X$(){if(RS)return um;RS=1;function e(n,r,i){for(var o=-1,l=n==null?0:n.length;++o<l;)if(i(r,n[o]))return!0;return!1}return um=e,um}var cm,TS;function Q$(){if(TS)return cm;TS=1;function e(){}return cm=e,cm}var dm,jS;function Z$(){if(jS)return dm;jS=1;var e=$C(),n=Q$(),r=hy(),i=1/0,o=e&&1/r(new e([,-0]))[1]==i?function(l){return new e(l)}:n;return dm=o,dm}var fm,AS;function J$(){if(AS)return fm;AS=1;var e=GC(),n=K$(),r=X$(),i=YC(),o=Z$(),l=hy(),u=200;function c(h,p,d){var m=-1,y=n,w=h.length,N=!0,_=[],b=_;if(d)N=!1,y=r;else if(w>=u){var S=p?null:o(h);if(S)return l(S);N=!1,y=i,b=new e}else b=p?[]:_;e:for(;++m<w;){var k=h[m],E=p?p(k):k;if(k=d||k!==0?k:0,N&&E===E){for(var C=b.length;C--;)if(b[C]===E)continue e;p&&b.push(E),_.push(k)}else y(b,E,d)||(b!==_&&b.push(E),_.push(k))}return _}return fm=c,fm}var hm,IS;function fR(){if(IS)return hm;IS=1;var e=Wr(),n=vr();function r(i){return n(i)&&e(i)}return hm=r,hm}var pm,MS;function e4(){if(MS)return pm;MS=1;var e=my(),n=Yu(),r=J$(),i=fR(),o=n(function(l){return r(e(l,1,i,!0))});return pm=o,pm}var mm,OS;function t4(){if(OS)return mm;OS=1;var e=Wu();function n(r,i){return e(i,function(o){return r[o]})}return mm=n,mm}var gm,PS;function hR(){if(PS)return gm;PS=1;var e=t4(),n=Ss();function r(i){return i==null?[]:e(i,n(i))}return gm=r,gm}var vm,LS;function qn(){if(LS)return vm;LS=1;var e;if(typeof ey=="function")try{e={clone:l$(),constant:cy(),each:VC(),filter:rR(),has:sR(),isArray:bt(),isEmpty:I$(),isFunction:$a(),isUndefined:iR(),keys:Ss(),map:aR(),reduce:lR(),size:F$(),transform:z$(),union:e4(),values:hR()}}catch{}return e||(e=window._),vm=e,vm}var ym,qS;function gy(){if(qS)return ym;qS=1;var e=qn();ym=o;var n="\0",r="\0",i="";function o(d){this._isDirected=e.has(d,"directed")?d.directed:!0,this._isMultigraph=e.has(d,"multigraph")?d.multigraph:!1,this._isCompound=e.has(d,"compound")?d.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[r]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}o.prototype._nodeCount=0,o.prototype._edgeCount=0,o.prototype.isDirected=function(){return this._isDirected},o.prototype.isMultigraph=function(){return this._isMultigraph},o.prototype.isCompound=function(){return this._isCompound},o.prototype.setGraph=function(d){return this._label=d,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultNodeLabelFn=d,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var d=this;return e.filter(this.nodes(),function(m){return e.isEmpty(d._in[m])})},o.prototype.sinks=function(){var d=this;return e.filter(this.nodes(),function(m){return e.isEmpty(d._out[m])})},o.prototype.setNodes=function(d,m){var y=arguments,w=this;return e.each(d,function(N){y.length>1?w.setNode(N,m):w.setNode(N)}),this},o.prototype.setNode=function(d,m){return e.has(this._nodes,d)?(arguments.length>1&&(this._nodes[d]=m),this):(this._nodes[d]=arguments.length>1?m:this._defaultNodeLabelFn(d),this._isCompound&&(this._parent[d]=r,this._children[d]={},this._children[r][d]=!0),this._in[d]={},this._preds[d]={},this._out[d]={},this._sucs[d]={},++this._nodeCount,this)},o.prototype.node=function(d){return this._nodes[d]},o.prototype.hasNode=function(d){return e.has(this._nodes,d)},o.prototype.removeNode=function(d){var m=this;if(e.has(this._nodes,d)){var y=function(w){m.removeEdge(m._edgeObjs[w])};delete this._nodes[d],this._isCompound&&(this._removeFromParentsChildList(d),delete this._parent[d],e.each(this.children(d),function(w){m.setParent(w)}),delete this._children[d]),e.each(e.keys(this._in[d]),y),delete this._in[d],delete this._preds[d],e.each(e.keys(this._out[d]),y),delete this._out[d],delete this._sucs[d],--this._nodeCount}return this},o.prototype.setParent=function(d,m){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(m))m=r;else{m+="";for(var y=m;!e.isUndefined(y);y=this.parent(y))if(y===d)throw new Error("Setting "+m+" as parent of "+d+" would create a cycle");this.setNode(m)}return this.setNode(d),this._removeFromParentsChildList(d),this._parent[d]=m,this._children[m][d]=!0,this},o.prototype._removeFromParentsChildList=function(d){delete this._children[this._parent[d]][d]},o.prototype.parent=function(d){if(this._isCompound){var m=this._parent[d];if(m!==r)return m}},o.prototype.children=function(d){if(e.isUndefined(d)&&(d=r),this._isCompound){var m=this._children[d];if(m)return e.keys(m)}else{if(d===r)return this.nodes();if(this.hasNode(d))return[]}},o.prototype.predecessors=function(d){var m=this._preds[d];if(m)return e.keys(m)},o.prototype.successors=function(d){var m=this._sucs[d];if(m)return e.keys(m)},o.prototype.neighbors=function(d){var m=this.predecessors(d);if(m)return e.union(m,this.successors(d))},o.prototype.isLeaf=function(d){var m;return this.isDirected()?m=this.successors(d):m=this.neighbors(d),m.length===0},o.prototype.filterNodes=function(d){var m=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});m.setGraph(this.graph());var y=this;e.each(this._nodes,function(_,b){d(b)&&m.setNode(b,_)}),e.each(this._edgeObjs,function(_){m.hasNode(_.v)&&m.hasNode(_.w)&&m.setEdge(_,y.edge(_))});var w={};function N(_){var b=y.parent(_);return b===void 0||m.hasNode(b)?(w[_]=b,b):b in w?w[b]:N(b)}return this._isCompound&&e.each(m.nodes(),function(_){m.setParent(_,N(_))}),m},o.prototype.setDefaultEdgeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultEdgeLabelFn=d,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(d,m){var y=this,w=arguments;return e.reduce(d,function(N,_){return w.length>1?y.setEdge(N,_,m):y.setEdge(N,_),_}),this},o.prototype.setEdge=function(){var d,m,y,w,N=!1,_=arguments[0];typeof _=="object"&&_!==null&&"v"in _?(d=_.v,m=_.w,y=_.name,arguments.length===2&&(w=arguments[1],N=!0)):(d=_,m=arguments[1],y=arguments[3],arguments.length>2&&(w=arguments[2],N=!0)),d=""+d,m=""+m,e.isUndefined(y)||(y=""+y);var b=c(this._isDirected,d,m,y);if(e.has(this._edgeLabels,b))return N&&(this._edgeLabels[b]=w),this;if(!e.isUndefined(y)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(d),this.setNode(m),this._edgeLabels[b]=N?w:this._defaultEdgeLabelFn(d,m,y);var S=h(this._isDirected,d,m,y);return d=S.v,m=S.w,Object.freeze(S),this._edgeObjs[b]=S,l(this._preds[m],d),l(this._sucs[d],m),this._in[m][b]=S,this._out[d][b]=S,this._edgeCount++,this},o.prototype.edge=function(d,m,y){var w=arguments.length===1?p(this._isDirected,arguments[0]):c(this._isDirected,d,m,y);return this._edgeLabels[w]},o.prototype.hasEdge=function(d,m,y){var w=arguments.length===1?p(this._isDirected,arguments[0]):c(this._isDirected,d,m,y);return e.has(this._edgeLabels,w)},o.prototype.removeEdge=function(d,m,y){var w=arguments.length===1?p(this._isDirected,arguments[0]):c(this._isDirected,d,m,y),N=this._edgeObjs[w];return N&&(d=N.v,m=N.w,delete this._edgeLabels[w],delete this._edgeObjs[w],u(this._preds[m],d),u(this._sucs[d],m),delete this._in[m][w],delete this._out[d][w],this._edgeCount--),this},o.prototype.inEdges=function(d,m){var y=this._in[d];if(y){var w=e.values(y);return m?e.filter(w,function(N){return N.v===m}):w}},o.prototype.outEdges=function(d,m){var y=this._out[d];if(y){var w=e.values(y);return m?e.filter(w,function(N){return N.w===m}):w}},o.prototype.nodeEdges=function(d,m){var y=this.inEdges(d,m);if(y)return y.concat(this.outEdges(d,m))};function l(d,m){d[m]?d[m]++:d[m]=1}function u(d,m){--d[m]||delete d[m]}function c(d,m,y,w){var N=""+m,_=""+y;if(!d&&N>_){var b=N;N=_,_=b}return N+i+_+i+(e.isUndefined(w)?n:w)}function h(d,m,y,w){var N=""+m,_=""+y;if(!d&&N>_){var b=N;N=_,_=b}var S={v:N,w:_};return w&&(S.name=w),S}function p(d,m){return c(d,m.v,m.w,m.name)}return ym}var wm,$S;function n4(){return $S||($S=1,wm="2.1.8"),wm}var xm,DS;function r4(){return DS||(DS=1,xm={Graph:gy(),version:n4()}),xm}var _m,FS;function s4(){if(FS)return _m;FS=1;var e=qn(),n=gy();_m={write:r,read:l};function r(u){var c={options:{directed:u.isDirected(),multigraph:u.isMultigraph(),compound:u.isCompound()},nodes:i(u),edges:o(u)};return e.isUndefined(u.graph())||(c.value=e.clone(u.graph())),c}function i(u){return e.map(u.nodes(),function(c){var h=u.node(c),p=u.parent(c),d={v:c};return e.isUndefined(h)||(d.value=h),e.isUndefined(p)||(d.parent=p),d})}function o(u){return e.map(u.edges(),function(c){var h=u.edge(c),p={v:c.v,w:c.w};return e.isUndefined(c.name)||(p.name=c.name),e.isUndefined(h)||(p.value=h),p})}function l(u){var c=new n(u.options).setGraph(u.value);return e.each(u.nodes,function(h){c.setNode(h.v,h.value),h.parent&&c.setParent(h.v,h.parent)}),e.each(u.edges,function(h){c.setEdge({v:h.v,w:h.w,name:h.name},h.value)}),c}return _m}var bm,zS;function i4(){if(zS)return bm;zS=1;var e=qn();bm=n;function n(r){var i={},o=[],l;function u(c){e.has(i,c)||(i[c]=!0,l.push(c),e.each(r.successors(c),u),e.each(r.predecessors(c),u))}return e.each(r.nodes(),function(c){l=[],u(c),l.length&&o.push(l)}),o}return bm}var Sm,BS;function pR(){if(BS)return Sm;BS=1;var e=qn();Sm=n;function n(){this._arr=[],this._keyIndices={}}return n.prototype.size=function(){return this._arr.length},n.prototype.keys=function(){return this._arr.map(function(r){return r.key})},n.prototype.has=function(r){return e.has(this._keyIndices,r)},n.prototype.priority=function(r){var i=this._keyIndices[r];if(i!==void 0)return this._arr[i].priority},n.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},n.prototype.add=function(r,i){var o=this._keyIndices;if(r=String(r),!e.has(o,r)){var l=this._arr,u=l.length;return o[r]=u,l.push({key:r,priority:i}),this._decrease(u),!0}return!1},n.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var r=this._arr.pop();return delete this._keyIndices[r.key],this._heapify(0),r.key},n.prototype.decrease=function(r,i){var o=this._keyIndices[r];if(i>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+r+" Old: "+this._arr[o].priority+" New: "+i);this._arr[o].priority=i,this._decrease(o)},n.prototype._heapify=function(r){var i=this._arr,o=2*r,l=o+1,u=r;o<i.length&&(u=i[o].priority<i[u].priority?o:u,l<i.length&&(u=i[l].priority<i[u].priority?l:u),u!==r&&(this._swap(r,u),this._heapify(u)))},n.prototype._decrease=function(r){for(var i=this._arr,o=i[r].priority,l;r!==0&&(l=r>>1,!(i[l].priority<o));)this._swap(r,l),r=l},n.prototype._swap=function(r,i){var o=this._arr,l=this._keyIndices,u=o[r],c=o[i];o[r]=c,o[i]=u,l[c.key]=r,l[u.key]=i},Sm}var km,US;function mR(){if(US)return km;US=1;var e=qn(),n=pR();km=i;var r=e.constant(1);function i(l,u,c,h){return o(l,String(u),c||r,h||function(p){return l.outEdges(p)})}function o(l,u,c,h){var p={},d=new n,m,y,w=function(N){var _=N.v!==m?N.v:N.w,b=p[_],S=c(N),k=y.distance+S;if(S<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+N+" Weight: "+S);k<b.distance&&(b.distance=k,b.predecessor=m,d.decrease(_,k))};for(l.nodes().forEach(function(N){var _=N===u?0:Number.POSITIVE_INFINITY;p[N]={distance:_},d.add(N,_)});d.size()>0&&(m=d.removeMin(),y=p[m],y.distance!==Number.POSITIVE_INFINITY);)h(m).forEach(w);return p}return km}var Em,HS;function o4(){if(HS)return Em;HS=1;var e=mR(),n=qn();Em=r;function r(i,o,l){return n.transform(i.nodes(),function(u,c){u[c]=e(i,c,o,l)},{})}return Em}var Nm,WS;function gR(){if(WS)return Nm;WS=1;var e=qn();Nm=n;function n(r){var i=0,o=[],l={},u=[];function c(h){var p=l[h]={onStack:!0,lowlink:i,index:i++};if(o.push(h),r.successors(h).forEach(function(y){e.has(l,y)?l[y].onStack&&(p.lowlink=Math.min(p.lowlink,l[y].index)):(c(y),p.lowlink=Math.min(p.lowlink,l[y].lowlink))}),p.lowlink===p.index){var d=[],m;do m=o.pop(),l[m].onStack=!1,d.push(m);while(h!==m);u.push(d)}}return r.nodes().forEach(function(h){e.has(l,h)||c(h)}),u}return Nm}var Cm,VS;function a4(){if(VS)return Cm;VS=1;var e=qn(),n=gR();Cm=r;function r(i){return e.filter(n(i),function(o){return o.length>1||o.length===1&&i.hasEdge(o[0],o[0])})}return Cm}var Rm,GS;function l4(){if(GS)return Rm;GS=1;var e=qn();Rm=r;var n=e.constant(1);function r(o,l,u){return i(o,l||n,u||function(c){return o.outEdges(c)})}function i(o,l,u){var c={},h=o.nodes();return h.forEach(function(p){c[p]={},c[p][p]={distance:0},h.forEach(function(d){p!==d&&(c[p][d]={distance:Number.POSITIVE_INFINITY})}),u(p).forEach(function(d){var m=d.v===p?d.w:d.v,y=l(d);c[p][m]={distance:y,predecessor:p}})}),h.forEach(function(p){var d=c[p];h.forEach(function(m){var y=c[m];h.forEach(function(w){var N=y[p],_=d[w],b=y[w],S=N.distance+_.distance;S<b.distance&&(b.distance=S,b.predecessor=_.predecessor)})})}),c}return Rm}var Tm,YS;function vR(){if(YS)return Tm;YS=1;var e=qn();Tm=n,n.CycleException=r;function n(i){var o={},l={},u=[];function c(h){if(e.has(l,h))throw new r;e.has(o,h)||(l[h]=!0,o[h]=!0,e.each(i.predecessors(h),c),delete l[h],u.push(h))}if(e.each(i.sinks(),c),e.size(o)!==i.nodeCount())throw new r;return u}function r(){}return r.prototype=new Error,Tm}var jm,KS;function u4(){if(KS)return jm;KS=1;var e=vR();jm=n;function n(r){try{e(r)}catch(i){if(i instanceof e.CycleException)return!1;throw i}return!0}return jm}var Am,XS;function yR(){if(XS)return Am;XS=1;var e=qn();Am=n;function n(i,o,l){e.isArray(o)||(o=[o]);var u=(i.isDirected()?i.successors:i.neighbors).bind(i),c=[],h={};return e.each(o,function(p){if(!i.hasNode(p))throw new Error("Graph does not have node: "+p);r(i,p,l==="post",h,u,c)}),c}function r(i,o,l,u,c,h){e.has(u,o)||(u[o]=!0,l||h.push(o),e.each(c(o),function(p){r(i,p,l,u,c,h)}),l&&h.push(o))}return Am}var Im,QS;function c4(){if(QS)return Im;QS=1;var e=yR();Im=n;function n(r,i){return e(r,i,"post")}return Im}var Mm,ZS;function d4(){if(ZS)return Mm;ZS=1;var e=yR();Mm=n;function n(r,i){return e(r,i,"pre")}return Mm}var Om,JS;function f4(){if(JS)return Om;JS=1;var e=qn(),n=gy(),r=pR();Om=i;function i(o,l){var u=new n,c={},h=new r,p;function d(y){var w=y.v===p?y.w:y.v,N=h.priority(w);if(N!==void 0){var _=l(y);_<N&&(c[w]=p,h.decrease(w,_))}}if(o.nodeCount()===0)return u;e.each(o.nodes(),function(y){h.add(y,Number.POSITIVE_INFINITY),u.setNode(y)}),h.decrease(o.nodes()[0],0);for(var m=!1;h.size()>0;){if(p=h.removeMin(),e.has(c,p))u.setEdge(p,c[p]);else{if(m)throw new Error("Input graph is not connected: "+o);m=!0}o.nodeEdges(p).forEach(d)}return u}return Om}var Pm,ek;function h4(){return ek||(ek=1,Pm={components:i4(),dijkstra:mR(),dijkstraAll:o4(),findCycles:a4(),floydWarshall:l4(),isAcyclic:u4(),postorder:c4(),preorder:d4(),prim:f4(),tarjan:gR(),topsort:vR()}),Pm}var Lm,tk;function p4(){if(tk)return Lm;tk=1;var e=r4();return Lm={Graph:e.Graph,json:s4(),alg:h4(),version:e.version},Lm}var qm,nk;function er(){if(nk)return qm;nk=1;var e;if(typeof ey=="function")try{e=p4()}catch{}return e||(e=window.graphlib),qm=e,qm}var $m,rk;function m4(){if(rk)return $m;rk=1;var e=UC(),n=1,r=4;function i(o){return e(o,n|r)}return $m=i,$m}var Dm,sk;function Ku(){if(sk)return Dm;sk=1;var e=_o(),n=Wr(),r=Fu(),i=Ln();function o(l,u,c){if(!i(c))return!1;var h=typeof u;return(h=="number"?n(c)&&r(u,c.length):h=="string"&&u in c)?e(c[u],l):!1}return Dm=o,Dm}var Fm,ik;function g4(){if(ik)return Fm;ik=1;var e=Yu(),n=_o(),r=Ku(),i=di(),o=Object.prototype,l=o.hasOwnProperty,u=e(function(c,h){c=Object(c);var p=-1,d=h.length,m=d>2?h[2]:void 0;for(m&&r(h[0],h[1],m)&&(d=1);++p<d;)for(var y=h[p],w=i(y),N=-1,_=w.length;++N<_;){var b=w[N],S=c[b];(S===void 0||n(S,o[b])&&!l.call(c,b))&&(c[b]=y[b])}return c});return Fm=u,Fm}var zm,ok;function v4(){if(ok)return zm;ok=1;var e=Vr(),n=Wr(),r=Ss();function i(o){return function(l,u,c){var h=Object(l);if(!n(l)){var p=e(u,3);l=r(l),u=function(m){return p(h[m],m,h)}}var d=o(l,u,c);return d>-1?h[p?l[d]:d]:void 0}}return zm=i,zm}var Bm,ak;function y4(){if(ak)return Bm;ak=1;var e=/\s/;function n(r){for(var i=r.length;i--&&e.test(r.charAt(i)););return i}return Bm=n,Bm}var Um,lk;function w4(){if(lk)return Um;lk=1;var e=y4(),n=/^\s+/;function r(i){return i&&i.slice(0,e(i)+1).replace(n,"")}return Um=r,Um}var Hm,uk;function x4(){if(uk)return Hm;uk=1;var e=w4(),n=Ln(),r=Eo(),i=NaN,o=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,u=/^0o[0-7]+$/i,c=parseInt;function h(p){if(typeof p=="number")return p;if(r(p))return i;if(n(p)){var d=typeof p.valueOf=="function"?p.valueOf():p;p=n(d)?d+"":d}if(typeof p!="string")return p===0?p:+p;p=e(p);var m=l.test(p);return m||u.test(p)?c(p.slice(2),m?2:8):o.test(p)?i:+p}return Hm=h,Hm}var Wm,ck;function wR(){if(ck)return Wm;ck=1;var e=x4(),n=1/0,r=17976931348623157e292;function i(o){if(!o)return o===0?o:0;if(o=e(o),o===n||o===-n){var l=o<0?-1:1;return l*r}return o===o?o:0}return Wm=i,Wm}var Vm,dk;function _4(){if(dk)return Vm;dk=1;var e=wR();function n(r){var i=e(r),o=i%1;return i===i?o?i-o:i:0}return Vm=n,Vm}var Gm,fk;function b4(){if(fk)return Gm;fk=1;var e=dR(),n=Vr(),r=_4(),i=Math.max;function o(l,u,c){var h=l==null?0:l.length;if(!h)return-1;var p=c==null?0:r(c);return p<0&&(p=i(h+p,0)),e(l,n(u,3),p)}return Gm=o,Gm}var Ym,hk;function S4(){if(hk)return Ym;hk=1;var e=v4(),n=b4(),r=e(n);return Ym=r,Ym}var Km,pk;function xR(){if(pk)return Km;pk=1;var e=my();function n(r){var i=r==null?0:r.length;return i?e(r,1):[]}return Km=n,Km}var Xm,mk;function k4(){if(mk)return Xm;mk=1;var e=dy(),n=HC(),r=di();function i(o,l){return o==null?o:e(o,n(l),r)}return Xm=i,Xm}var Qm,gk;function E4(){if(gk)return Qm;gk=1;function e(n){var r=n==null?0:n.length;return r?n[r-1]:void 0}return Qm=e,Qm}var Zm,vk;function N4(){if(vk)return Zm;vk=1;var e=$u(),n=fy(),r=Vr();function i(o,l){var u={};return l=r(l,3),n(o,function(c,h,p){e(u,h,l(c,h,p))}),u}return Zm=i,Zm}var Jm,yk;function vy(){if(yk)return Jm;yk=1;var e=Eo();function n(r,i,o){for(var l=-1,u=r.length;++l<u;){var c=r[l],h=i(c);if(h!=null&&(p===void 0?h===h&&!e(h):o(h,p)))var p=h,d=c}return d}return Jm=n,Jm}var eg,wk;function C4(){if(wk)return eg;wk=1;function e(n,r){return n>r}return eg=e,eg}var tg,xk;function R4(){if(xk)return tg;xk=1;var e=vy(),n=C4(),r=fi();function i(o){return o&&o.length?e(o,r,n):void 0}return tg=i,tg}var ng,_k;function _R(){if(_k)return ng;_k=1;var e=$u(),n=_o();function r(i,o,l){(l!==void 0&&!n(i[o],l)||l===void 0&&!(o in i))&&e(i,o,l)}return ng=r,ng}var rg,bk;function T4(){if(bk)return rg;bk=1;var e=ui(),n=Uu(),r=vr(),i="[object Object]",o=Function.prototype,l=Object.prototype,u=o.toString,c=l.hasOwnProperty,h=u.call(Object);function p(d){if(!r(d)||e(d)!=i)return!1;var m=n(d);if(m===null)return!0;var y=c.call(m,"constructor")&&m.constructor;return typeof y=="function"&&y instanceof y&&u.call(y)==h}return rg=p,rg}var sg,Sk;function bR(){if(Sk)return sg;Sk=1;function e(n,r){if(!(r==="constructor"&&typeof n[r]=="function")&&r!="__proto__")return n[r]}return sg=e,sg}var ig,kk;function j4(){if(kk)return ig;kk=1;var e=Da(),n=di();function r(i){return e(i,n(i))}return ig=r,ig}var og,Ek;function A4(){if(Ek)return og;Ek=1;var e=_R(),n=AC(),r=FC(),i=IC(),o=BC(),l=Fa(),u=bt(),c=fR(),h=So(),p=$a(),d=Ln(),m=T4(),y=za(),w=bR(),N=j4();function _(b,S,k,E,C,I,P){var A=w(b,k),U=w(S,k),L=P.get(U);if(L){e(b,k,L);return}var O=I?I(A,U,k+"",b,S,P):void 0,q=O===void 0;if(q){var G=u(U),F=!G&&h(U),j=!G&&!F&&y(U);O=U,G||F||j?u(A)?O=A:c(A)?O=i(A):F?(q=!1,O=n(U,!0)):j?(q=!1,O=r(U,!0)):O=[]:m(U)||l(U)?(O=A,l(A)?O=N(A):(!d(A)||p(A))&&(O=o(U))):q=!1}q&&(P.set(U,O),C(O,U,E,I,P),P.delete(U)),e(b,k,O)}return og=_,og}var ag,Nk;function I4(){if(Nk)return ag;Nk=1;var e=qu(),n=_R(),r=dy(),i=A4(),o=Ln(),l=di(),u=bR();function c(h,p,d,m,y){h!==p&&r(p,function(w,N){if(y||(y=new e),o(w))i(h,p,N,d,c,m,y);else{var _=m?m(u(h,N),w,N+"",h,p,y):void 0;_===void 0&&(_=w),n(h,N,_)}},l)}return ag=c,ag}var lg,Ck;function M4(){if(Ck)return lg;Ck=1;var e=Yu(),n=Ku();function r(i){return e(function(o,l){var u=-1,c=l.length,h=c>1?l[c-1]:void 0,p=c>2?l[2]:void 0;for(h=i.length>3&&typeof h=="function"?(c--,h):void 0,p&&n(l[0],l[1],p)&&(h=c<3?void 0:h,c=1),o=Object(o);++u<c;){var d=l[u];d&&i(o,d,u,h)}return o})}return lg=r,lg}var ug,Rk;function O4(){if(Rk)return ug;Rk=1;var e=I4(),n=M4(),r=n(function(i,o,l){e(i,o,l)});return ug=r,ug}var cg,Tk;function SR(){if(Tk)return cg;Tk=1;function e(n,r){return n<r}return cg=e,cg}var dg,jk;function P4(){if(jk)return dg;jk=1;var e=vy(),n=SR(),r=fi();function i(o){return o&&o.length?e(o,r,n):void 0}return dg=i,dg}var fg,Ak;function L4(){if(Ak)return fg;Ak=1;var e=vy(),n=Vr(),r=SR();function i(o,l){return o&&o.length?e(o,n(l,2),r):void 0}return fg=i,fg}var hg,Ik;function q4(){if(Ik)return hg;Ik=1;var e=nr(),n=function(){return e.Date.now()};return hg=n,hg}var pg,Mk;function $4(){if(Mk)return pg;Mk=1;var e=Du(),n=Vu(),r=Fu(),i=Ln(),o=Ba();function l(u,c,h,p){if(!i(u))return u;c=n(c,u);for(var d=-1,m=c.length,y=m-1,w=u;w!=null&&++d<m;){var N=o(c[d]),_=h;if(N==="__proto__"||N==="constructor"||N==="prototype")return u;if(d!=y){var b=w[N];_=p?p(b,N,w):void 0,_===void 0&&(_=i(b)?b:r(c[d+1])?[]:{})}e(w,N,_),w=w[N]}return u}return pg=l,pg}var mg,Ok;function D4(){if(Ok)return mg;Ok=1;var e=Gu(),n=$4(),r=Vu();function i(o,l,u){for(var c=-1,h=l.length,p={};++c<h;){var d=l[c],m=e(o,d);u(m,d)&&n(p,r(d,o),m)}return p}return mg=i,mg}var gg,Pk;function F4(){if(Pk)return gg;Pk=1;var e=D4(),n=tR();function r(i,o){return e(i,o,function(l,u){return n(i,u)})}return gg=r,gg}var vg,Lk;function z4(){if(Lk)return vg;Lk=1;var e=xR(),n=uR(),r=cR();function i(o){return r(n(o,void 0,e),o+"")}return vg=i,vg}var yg,qk;function B4(){if(qk)return yg;qk=1;var e=F4(),n=z4(),r=n(function(i,o){return i==null?{}:e(i,o)});return yg=r,yg}var wg,$k;function U4(){if($k)return wg;$k=1;var e=Math.ceil,n=Math.max;function r(i,o,l,u){for(var c=-1,h=n(e((o-i)/(l||1)),0),p=Array(h);h--;)p[u?h:++c]=i,i+=l;return p}return wg=r,wg}var xg,Dk;function H4(){if(Dk)return xg;Dk=1;var e=U4(),n=Ku(),r=wR();function i(o){return function(l,u,c){return c&&typeof c!="number"&&n(l,u,c)&&(u=c=void 0),l=r(l),u===void 0?(u=l,l=0):u=r(u),c=c===void 0?l<u?1:-1:r(c),e(l,u,c,o)}}return xg=i,xg}var _g,Fk;function W4(){if(Fk)return _g;Fk=1;var e=H4(),n=e();return _g=n,_g}var bg,zk;function V4(){if(zk)return bg;zk=1;function e(n,r){var i=n.length;for(n.sort(r);i--;)n[i]=n[i].value;return n}return bg=e,bg}var Sg,Bk;function G4(){if(Bk)return Sg;Bk=1;var e=Eo();function n(r,i){if(r!==i){var o=r!==void 0,l=r===null,u=r===r,c=e(r),h=i!==void 0,p=i===null,d=i===i,m=e(i);if(!p&&!m&&!c&&r>i||c&&h&&d&&!p&&!m||l&&h&&d||!o&&d||!u)return 1;if(!l&&!c&&!m&&r<i||m&&o&&u&&!l&&!c||p&&o&&u||!h&&u||!d)return-1}return 0}return Sg=n,Sg}var kg,Uk;function Y4(){if(Uk)return kg;Uk=1;var e=G4();function n(r,i,o){for(var l=-1,u=r.criteria,c=i.criteria,h=u.length,p=o.length;++l<h;){var d=e(u[l],c[l]);if(d){if(l>=p)return d;var m=o[l];return d*(m=="desc"?-1:1)}}return r.index-i.index}return kg=n,kg}var Eg,Hk;function K4(){if(Hk)return Eg;Hk=1;var e=Wu(),n=Gu(),r=Vr(),i=oR(),o=V4(),l=zu(),u=Y4(),c=fi(),h=bt();function p(d,m,y){m.length?m=e(m,function(_){return h(_)?function(b){return n(b,_.length===1?_[0]:_)}:_}):m=[c];var w=-1;m=e(m,l(r));var N=i(d,function(_,b,S){var k=e(m,function(E){return E(_)});return{criteria:k,index:++w,value:_}});return o(N,function(_,b){return u(_,b,y)})}return Eg=p,Eg}var Ng,Wk;function X4(){if(Wk)return Ng;Wk=1;var e=my(),n=K4(),r=Yu(),i=Ku(),o=r(function(l,u){if(l==null)return[];var c=u.length;return c>1&&i(l,u[0],u[1])?u=[]:c>2&&i(u[0],u[1],u[2])&&(u=[u[0]]),n(l,e(u,1),[])});return Ng=o,Ng}var Cg,Vk;function Q4(){if(Vk)return Cg;Vk=1;var e=JC(),n=0;function r(i){var o=++n;return e(i)+o}return Cg=r,Cg}var Rg,Gk;function Z4(){if(Gk)return Rg;Gk=1;function e(n,r,i){for(var o=-1,l=n.length,u=r.length,c={};++o<l;){var h=o<u?r[o]:void 0;i(c,n[o],h)}return c}return Rg=e,Rg}var Tg,Yk;function J4(){if(Yk)return Tg;Yk=1;var e=Du(),n=Z4();function r(i,o){return n(i||[],o||[],e)}return Tg=r,Tg}var jg,Kk;function it(){if(Kk)return jg;Kk=1;var e;if(typeof ey=="function")try{e={cloneDeep:m4(),constant:cy(),defaults:g4(),each:VC(),filter:rR(),find:S4(),flatten:xR(),forEach:WC(),forIn:k4(),has:sR(),isUndefined:iR(),last:E4(),map:aR(),mapValues:N4(),max:R4(),merge:O4(),min:P4(),minBy:L4(),now:q4(),pick:B4(),range:W4(),reduce:lR(),sortBy:X4(),uniqueId:Q4(),values:hR(),zipObject:J4()}}catch{}return e||(e=window._),jg=e,jg}var Ag,Xk;function eD(){if(Xk)return Ag;Xk=1,Ag=e;function e(){var i={};i._next=i._prev=i,this._sentinel=i}e.prototype.dequeue=function(){var i=this._sentinel,o=i._prev;if(o!==i)return n(o),o},e.prototype.enqueue=function(i){var o=this._sentinel;i._prev&&i._next&&n(i),i._next=o._next,o._next._prev=i,o._next=i,i._prev=o},e.prototype.toString=function(){for(var i=[],o=this._sentinel,l=o._prev;l!==o;)i.push(JSON.stringify(l,r)),l=l._prev;return"["+i.join(", ")+"]"};function n(i){i._prev._next=i._next,i._next._prev=i._prev,delete i._next,delete i._prev}function r(i,o){if(i!=="_next"&&i!=="_prev")return o}return Ag}var Ig,Qk;function tD(){if(Qk)return Ig;Qk=1;var e=it(),n=er().Graph,r=eD();Ig=o;var i=e.constant(1);function o(p,d){if(p.nodeCount()<=1)return[];var m=c(p,d||i),y=l(m.graph,m.buckets,m.zeroIdx);return e.flatten(e.map(y,function(w){return p.outEdges(w.v,w.w)}),!0)}function l(p,d,m){for(var y=[],w=d[d.length-1],N=d[0],_;p.nodeCount();){for(;_=N.dequeue();)u(p,d,m,_);for(;_=w.dequeue();)u(p,d,m,_);if(p.nodeCount()){for(var b=d.length-2;b>0;--b)if(_=d[b].dequeue(),_){y=y.concat(u(p,d,m,_,!0));break}}}return y}function u(p,d,m,y,w){var N=w?[]:void 0;return e.forEach(p.inEdges(y.v),function(_){var b=p.edge(_),S=p.node(_.v);w&&N.push({v:_.v,w:_.w}),S.out-=b,h(d,m,S)}),e.forEach(p.outEdges(y.v),function(_){var b=p.edge(_),S=_.w,k=p.node(S);k.in-=b,h(d,m,k)}),p.removeNode(y.v),N}function c(p,d){var m=new n,y=0,w=0;e.forEach(p.nodes(),function(b){m.setNode(b,{v:b,in:0,out:0})}),e.forEach(p.edges(),function(b){var S=m.edge(b.v,b.w)||0,k=d(b),E=S+k;m.setEdge(b.v,b.w,E),w=Math.max(w,m.node(b.v).out+=k),y=Math.max(y,m.node(b.w).in+=k)});var N=e.range(w+y+3).map(function(){return new r}),_=y+1;return e.forEach(m.nodes(),function(b){h(N,_,m.node(b))}),{graph:m,buckets:N,zeroIdx:_}}function h(p,d,m){m.out?m.in?p[m.out-m.in+d].enqueue(m):p[p.length-1].enqueue(m):p[0].enqueue(m)}return Ig}var Mg,Zk;function nD(){if(Zk)return Mg;Zk=1;var e=it(),n=tD();Mg={run:r,undo:o};function r(l){var u=l.graph().acyclicer==="greedy"?n(l,c(l)):i(l);e.forEach(u,function(h){var p=l.edge(h);l.removeEdge(h),p.forwardName=h.name,p.reversed=!0,l.setEdge(h.w,h.v,p,e.uniqueId("rev"))});function c(h){return function(p){return h.edge(p).weight}}}function i(l){var u=[],c={},h={};function p(d){e.has(h,d)||(h[d]=!0,c[d]=!0,e.forEach(l.outEdges(d),function(m){e.has(c,m.w)?u.push(m):p(m.w)}),delete c[d])}return e.forEach(l.nodes(),p),u}function o(l){e.forEach(l.edges(),function(u){var c=l.edge(u);if(c.reversed){l.removeEdge(u);var h=c.forwardName;delete c.reversed,delete c.forwardName,l.setEdge(u.w,u.v,c,h)}})}return Mg}var Og,Jk;function hn(){if(Jk)return Og;Jk=1;var e=it(),n=er().Graph;Og={addDummyNode:r,simplify:i,asNonCompoundGraph:o,successorWeights:l,predecessorWeights:u,intersectRect:c,buildLayerMatrix:h,normalizeRanks:p,removeEmptyRanks:d,addBorderNode:m,maxRank:y,partition:w,time:N,notime:_};function r(b,S,k,E){var C;do C=e.uniqueId(E);while(b.hasNode(C));return k.dummy=S,b.setNode(C,k),C}function i(b){var S=new n().setGraph(b.graph());return e.forEach(b.nodes(),function(k){S.setNode(k,b.node(k))}),e.forEach(b.edges(),function(k){var E=S.edge(k.v,k.w)||{weight:0,minlen:1},C=b.edge(k);S.setEdge(k.v,k.w,{weight:E.weight+C.weight,minlen:Math.max(E.minlen,C.minlen)})}),S}function o(b){var S=new n({multigraph:b.isMultigraph()}).setGraph(b.graph());return e.forEach(b.nodes(),function(k){b.children(k).length||S.setNode(k,b.node(k))}),e.forEach(b.edges(),function(k){S.setEdge(k,b.edge(k))}),S}function l(b){var S=e.map(b.nodes(),function(k){var E={};return e.forEach(b.outEdges(k),function(C){E[C.w]=(E[C.w]||0)+b.edge(C).weight}),E});return e.zipObject(b.nodes(),S)}function u(b){var S=e.map(b.nodes(),function(k){var E={};return e.forEach(b.inEdges(k),function(C){E[C.v]=(E[C.v]||0)+b.edge(C).weight}),E});return e.zipObject(b.nodes(),S)}function c(b,S){var k=b.x,E=b.y,C=S.x-k,I=S.y-E,P=b.width/2,A=b.height/2;if(!C&&!I)throw new Error("Not possible to find intersection inside of the rectangle");var U,L;return Math.abs(I)*P>Math.abs(C)*A?(I<0&&(A=-A),U=A*C/I,L=A):(C<0&&(P=-P),U=P,L=P*I/C),{x:k+U,y:E+L}}function h(b){var S=e.map(e.range(y(b)+1),function(){return[]});return e.forEach(b.nodes(),function(k){var E=b.node(k),C=E.rank;e.isUndefined(C)||(S[C][E.order]=k)}),S}function p(b){var S=e.min(e.map(b.nodes(),function(k){return b.node(k).rank}));e.forEach(b.nodes(),function(k){var E=b.node(k);e.has(E,"rank")&&(E.rank-=S)})}function d(b){var S=e.min(e.map(b.nodes(),function(I){return b.node(I).rank})),k=[];e.forEach(b.nodes(),function(I){var P=b.node(I).rank-S;k[P]||(k[P]=[]),k[P].push(I)});var E=0,C=b.graph().nodeRankFactor;e.forEach(k,function(I,P){e.isUndefined(I)&&P%C!==0?--E:E&&e.forEach(I,function(A){b.node(A).rank+=E})})}function m(b,S,k,E){var C={width:0,height:0};return arguments.length>=4&&(C.rank=k,C.order=E),r(b,"border",C,S)}function y(b){return e.max(e.map(b.nodes(),function(S){var k=b.node(S).rank;if(!e.isUndefined(k))return k}))}function w(b,S){var k={lhs:[],rhs:[]};return e.forEach(b,function(E){S(E)?k.lhs.push(E):k.rhs.push(E)}),k}function N(b,S){var k=e.now();try{return S()}finally{console.log(b+" time: "+(e.now()-k)+"ms")}}function _(b,S){return S()}return Og}var Pg,eE;function rD(){if(eE)return Pg;eE=1;var e=it(),n=hn();Pg={run:r,undo:o};function r(l){l.graph().dummyChains=[],e.forEach(l.edges(),function(u){i(l,u)})}function i(l,u){var c=u.v,h=l.node(c).rank,p=u.w,d=l.node(p).rank,m=u.name,y=l.edge(u),w=y.labelRank;if(d!==h+1){l.removeEdge(u);var N,_,b;for(b=0,++h;h<d;++b,++h)y.points=[],_={width:0,height:0,edgeLabel:y,edgeObj:u,rank:h},N=n.addDummyNode(l,"edge",_,"_d"),h===w&&(_.width=y.width,_.height=y.height,_.dummy="edge-label",_.labelpos=y.labelpos),l.setEdge(c,N,{weight:y.weight},m),b===0&&l.graph().dummyChains.push(N),c=N;l.setEdge(c,p,{weight:y.weight},m)}}function o(l){e.forEach(l.graph().dummyChains,function(u){var c=l.node(u),h=c.edgeLabel,p;for(l.setEdge(c.edgeObj,h);c.dummy;)p=l.successors(u)[0],l.removeNode(u),h.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(h.x=c.x,h.y=c.y,h.width=c.width,h.height=c.height),u=p,c=l.node(u)})}return Pg}var Lg,tE;function Su(){if(tE)return Lg;tE=1;var e=it();Lg={longestPath:n,slack:r};function n(i){var o={};function l(u){var c=i.node(u);if(e.has(o,u))return c.rank;o[u]=!0;var h=e.min(e.map(i.outEdges(u),function(p){return l(p.w)-i.edge(p).minlen}));return(h===Number.POSITIVE_INFINITY||h===void 0||h===null)&&(h=0),c.rank=h}e.forEach(i.sources(),l)}function r(i,o){return i.node(o.w).rank-i.node(o.v).rank-i.edge(o).minlen}return Lg}var qg,nE;function kR(){if(nE)return qg;nE=1;var e=it(),n=er().Graph,r=Su().slack;qg=i;function i(c){var h=new n({directed:!1}),p=c.nodes()[0],d=c.nodeCount();h.setNode(p,{});for(var m,y;o(h,c)<d;)m=l(h,c),y=h.hasNode(m.v)?r(c,m):-r(c,m),u(h,c,y);return h}function o(c,h){function p(d){e.forEach(h.nodeEdges(d),function(m){var y=m.v,w=d===y?m.w:y;!c.hasNode(w)&&!r(h,m)&&(c.setNode(w,{}),c.setEdge(d,w,{}),p(w))})}return e.forEach(c.nodes(),p),c.nodeCount()}function l(c,h){return e.minBy(h.edges(),function(p){if(c.hasNode(p.v)!==c.hasNode(p.w))return r(h,p)})}function u(c,h,p){e.forEach(c.nodes(),function(d){h.node(d).rank+=p})}return qg}var $g,rE;function sD(){if(rE)return $g;rE=1;var e=it(),n=kR(),r=Su().slack,i=Su().longestPath,o=er().alg.preorder,l=er().alg.postorder,u=hn().simplify;$g=c,c.initLowLimValues=m,c.initCutValues=h,c.calcCutValue=d,c.leaveEdge=w,c.enterEdge=N,c.exchangeEdges=_;function c(E){E=u(E),i(E);var C=n(E);m(C),h(C,E);for(var I,P;I=w(C);)P=N(C,E,I),_(C,E,I,P)}function h(E,C){var I=l(E,E.nodes());I=I.slice(0,I.length-1),e.forEach(I,function(P){p(E,C,P)})}function p(E,C,I){var P=E.node(I),A=P.parent;E.edge(I,A).cutvalue=d(E,C,I)}function d(E,C,I){var P=E.node(I),A=P.parent,U=!0,L=C.edge(I,A),O=0;return L||(U=!1,L=C.edge(A,I)),O=L.weight,e.forEach(C.nodeEdges(I),function(q){var G=q.v===I,F=G?q.w:q.v;if(F!==A){var j=G===U,B=C.edge(q).weight;if(O+=j?B:-B,S(E,I,F)){var z=E.edge(I,F).cutvalue;O+=j?-z:z}}}),O}function m(E,C){arguments.length<2&&(C=E.nodes()[0]),y(E,{},1,C)}function y(E,C,I,P,A){var U=I,L=E.node(P);return C[P]=!0,e.forEach(E.neighbors(P),function(O){e.has(C,O)||(I=y(E,C,I,O,P))}),L.low=U,L.lim=I++,A?L.parent=A:delete L.parent,I}function w(E){return e.find(E.edges(),function(C){return E.edge(C).cutvalue<0})}function N(E,C,I){var P=I.v,A=I.w;C.hasEdge(P,A)||(P=I.w,A=I.v);var U=E.node(P),L=E.node(A),O=U,q=!1;U.lim>L.lim&&(O=L,q=!0);var G=e.filter(C.edges(),function(F){return q===k(E,E.node(F.v),O)&&q!==k(E,E.node(F.w),O)});return e.minBy(G,function(F){return r(C,F)})}function _(E,C,I,P){var A=I.v,U=I.w;E.removeEdge(A,U),E.setEdge(P.v,P.w,{}),m(E),h(E,C),b(E,C)}function b(E,C){var I=e.find(E.nodes(),function(A){return!C.node(A).parent}),P=o(E,I);P=P.slice(1),e.forEach(P,function(A){var U=E.node(A).parent,L=C.edge(A,U),O=!1;L||(L=C.edge(U,A),O=!0),C.node(A).rank=C.node(U).rank+(O?L.minlen:-L.minlen)})}function S(E,C,I){return E.hasEdge(C,I)}function k(E,C,I){return I.low<=C.lim&&C.lim<=I.lim}return $g}var Dg,sE;function iD(){if(sE)return Dg;sE=1;var e=Su(),n=e.longestPath,r=kR(),i=sD();Dg=o;function o(h){switch(h.graph().ranker){case"network-simplex":c(h);break;case"tight-tree":u(h);break;case"longest-path":l(h);break;default:c(h)}}var l=n;function u(h){n(h),r(h)}function c(h){i(h)}return Dg}var Fg,iE;function oD(){if(iE)return Fg;iE=1;var e=it();Fg=n;function n(o){var l=i(o);e.forEach(o.graph().dummyChains,function(u){for(var c=o.node(u),h=c.edgeObj,p=r(o,l,h.v,h.w),d=p.path,m=p.lca,y=0,w=d[y],N=!0;u!==h.w;){if(c=o.node(u),N){for(;(w=d[y])!==m&&o.node(w).maxRank<c.rank;)y++;w===m&&(N=!1)}if(!N){for(;y<d.length-1&&o.node(w=d[y+1]).minRank<=c.rank;)y++;w=d[y]}o.setParent(u,w),u=o.successors(u)[0]}})}function r(o,l,u,c){var h=[],p=[],d=Math.min(l[u].low,l[c].low),m=Math.max(l[u].lim,l[c].lim),y,w;y=u;do y=o.parent(y),h.push(y);while(y&&(l[y].low>d||m>l[y].lim));for(w=y,y=c;(y=o.parent(y))!==w;)p.push(y);return{path:h.concat(p.reverse()),lca:w}}function i(o){var l={},u=0;function c(h){var p=u;e.forEach(o.children(h),c),l[h]={low:p,lim:u++}}return e.forEach(o.children(),c),l}return Fg}var zg,oE;function aD(){if(oE)return zg;oE=1;var e=it(),n=hn();zg={run:r,cleanup:u};function r(c){var h=n.addDummyNode(c,"root",{},"_root"),p=o(c),d=e.max(e.values(p))-1,m=2*d+1;c.graph().nestingRoot=h,e.forEach(c.edges(),function(w){c.edge(w).minlen*=m});var y=l(c)+1;e.forEach(c.children(),function(w){i(c,h,m,y,d,p,w)}),c.graph().nodeRankFactor=m}function i(c,h,p,d,m,y,w){var N=c.children(w);if(!N.length){w!==h&&c.setEdge(h,w,{weight:0,minlen:p});return}var _=n.addBorderNode(c,"_bt"),b=n.addBorderNode(c,"_bb"),S=c.node(w);c.setParent(_,w),S.borderTop=_,c.setParent(b,w),S.borderBottom=b,e.forEach(N,function(k){i(c,h,p,d,m,y,k);var E=c.node(k),C=E.borderTop?E.borderTop:k,I=E.borderBottom?E.borderBottom:k,P=E.borderTop?d:2*d,A=C!==I?1:m-y[w]+1;c.setEdge(_,C,{weight:P,minlen:A,nestingEdge:!0}),c.setEdge(I,b,{weight:P,minlen:A,nestingEdge:!0})}),c.parent(w)||c.setEdge(h,_,{weight:0,minlen:m+y[w]})}function o(c){var h={};function p(d,m){var y=c.children(d);y&&y.length&&e.forEach(y,function(w){p(w,m+1)}),h[d]=m}return e.forEach(c.children(),function(d){p(d,1)}),h}function l(c){return e.reduce(c.edges(),function(h,p){return h+c.edge(p).weight},0)}function u(c){var h=c.graph();c.removeNode(h.nestingRoot),delete h.nestingRoot,e.forEach(c.edges(),function(p){var d=c.edge(p);d.nestingEdge&&c.removeEdge(p)})}return zg}var Bg,aE;function lD(){if(aE)return Bg;aE=1;var e=it(),n=hn();Bg=r;function r(o){function l(u){var c=o.children(u),h=o.node(u);if(c.length&&e.forEach(c,l),e.has(h,"minRank")){h.borderLeft=[],h.borderRight=[];for(var p=h.minRank,d=h.maxRank+1;p<d;++p)i(o,"borderLeft","_bl",u,h,p),i(o,"borderRight","_br",u,h,p)}}e.forEach(o.children(),l)}function i(o,l,u,c,h,p){var d={width:0,height:0,rank:p,borderType:l},m=h[l][p-1],y=n.addDummyNode(o,"border",d,u);h[l][p]=y,o.setParent(y,c),m&&o.setEdge(m,y,{weight:1})}return Bg}var Ug,lE;function uD(){if(lE)return Ug;lE=1;var e=it();Ug={adjust:n,undo:r};function n(p){var d=p.graph().rankdir.toLowerCase();(d==="lr"||d==="rl")&&i(p)}function r(p){var d=p.graph().rankdir.toLowerCase();(d==="bt"||d==="rl")&&l(p),(d==="lr"||d==="rl")&&(c(p),i(p))}function i(p){e.forEach(p.nodes(),function(d){o(p.node(d))}),e.forEach(p.edges(),function(d){o(p.edge(d))})}function o(p){var d=p.width;p.width=p.height,p.height=d}function l(p){e.forEach(p.nodes(),function(d){u(p.node(d))}),e.forEach(p.edges(),function(d){var m=p.edge(d);e.forEach(m.points,u),e.has(m,"y")&&u(m)})}function u(p){p.y=-p.y}function c(p){e.forEach(p.nodes(),function(d){h(p.node(d))}),e.forEach(p.edges(),function(d){var m=p.edge(d);e.forEach(m.points,h),e.has(m,"x")&&h(m)})}function h(p){var d=p.x;p.x=p.y,p.y=d}return Ug}var Hg,uE;function cD(){if(uE)return Hg;uE=1;var e=it();Hg=n;function n(r){var i={},o=e.filter(r.nodes(),function(p){return!r.children(p).length}),l=e.max(e.map(o,function(p){return r.node(p).rank})),u=e.map(e.range(l+1),function(){return[]});function c(p){if(!e.has(i,p)){i[p]=!0;var d=r.node(p);u[d.rank].push(p),e.forEach(r.successors(p),c)}}var h=e.sortBy(o,function(p){return r.node(p).rank});return e.forEach(h,c),u}return Hg}var Wg,cE;function dD(){if(cE)return Wg;cE=1;var e=it();Wg=n;function n(i,o){for(var l=0,u=1;u<o.length;++u)l+=r(i,o[u-1],o[u]);return l}function r(i,o,l){for(var u=e.zipObject(l,e.map(l,function(y,w){return w})),c=e.flatten(e.map(o,function(y){return e.sortBy(e.map(i.outEdges(y),function(w){return{pos:u[w.w],weight:i.edge(w).weight}}),"pos")}),!0),h=1;h<l.length;)h<<=1;var p=2*h-1;h-=1;var d=e.map(new Array(p),function(){return 0}),m=0;return e.forEach(c.forEach(function(y){var w=y.pos+h;d[w]+=y.weight;for(var N=0;w>0;)w%2&&(N+=d[w+1]),w=w-1>>1,d[w]+=y.weight;m+=y.weight*N})),m}return Wg}var Vg,dE;function fD(){if(dE)return Vg;dE=1;var e=it();Vg=n;function n(r,i){return e.map(i,function(o){var l=r.inEdges(o);if(l.length){var u=e.reduce(l,function(c,h){var p=r.edge(h),d=r.node(h.v);return{sum:c.sum+p.weight*d.order,weight:c.weight+p.weight}},{sum:0,weight:0});return{v:o,barycenter:u.sum/u.weight,weight:u.weight}}else return{v:o}})}return Vg}var Gg,fE;function hD(){if(fE)return Gg;fE=1;var e=it();Gg=n;function n(o,l){var u={};e.forEach(o,function(h,p){var d=u[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:p};e.isUndefined(h.barycenter)||(d.barycenter=h.barycenter,d.weight=h.weight)}),e.forEach(l.edges(),function(h){var p=u[h.v],d=u[h.w];!e.isUndefined(p)&&!e.isUndefined(d)&&(d.indegree++,p.out.push(u[h.w]))});var c=e.filter(u,function(h){return!h.indegree});return r(c)}function r(o){var l=[];function u(p){return function(d){d.merged||(e.isUndefined(d.barycenter)||e.isUndefined(p.barycenter)||d.barycenter>=p.barycenter)&&i(p,d)}}function c(p){return function(d){d.in.push(p),--d.indegree===0&&o.push(d)}}for(;o.length;){var h=o.pop();l.push(h),e.forEach(h.in.reverse(),u(h)),e.forEach(h.out,c(h))}return e.map(e.filter(l,function(p){return!p.merged}),function(p){return e.pick(p,["vs","i","barycenter","weight"])})}function i(o,l){var u=0,c=0;o.weight&&(u+=o.barycenter*o.weight,c+=o.weight),l.weight&&(u+=l.barycenter*l.weight,c+=l.weight),o.vs=l.vs.concat(o.vs),o.barycenter=u/c,o.weight=c,o.i=Math.min(l.i,o.i),l.merged=!0}return Gg}var Yg,hE;function pD(){if(hE)return Yg;hE=1;var e=it(),n=hn();Yg=r;function r(l,u){var c=n.partition(l,function(_){return e.has(_,"barycenter")}),h=c.lhs,p=e.sortBy(c.rhs,function(_){return-_.i}),d=[],m=0,y=0,w=0;h.sort(o(!!u)),w=i(d,p,w),e.forEach(h,function(_){w+=_.vs.length,d.push(_.vs),m+=_.barycenter*_.weight,y+=_.weight,w=i(d,p,w)});var N={vs:e.flatten(d,!0)};return y&&(N.barycenter=m/y,N.weight=y),N}function i(l,u,c){for(var h;u.length&&(h=e.last(u)).i<=c;)u.pop(),l.push(h.vs),c++;return c}function o(l){return function(u,c){return u.barycenter<c.barycenter?-1:u.barycenter>c.barycenter?1:l?c.i-u.i:u.i-c.i}}return Yg}var Kg,pE;function mD(){if(pE)return Kg;pE=1;var e=it(),n=fD(),r=hD(),i=pD();Kg=o;function o(c,h,p,d){var m=c.children(h),y=c.node(h),w=y?y.borderLeft:void 0,N=y?y.borderRight:void 0,_={};w&&(m=e.filter(m,function(I){return I!==w&&I!==N}));var b=n(c,m);e.forEach(b,function(I){if(c.children(I.v).length){var P=o(c,I.v,p,d);_[I.v]=P,e.has(P,"barycenter")&&u(I,P)}});var S=r(b,p);l(S,_);var k=i(S,d);if(w&&(k.vs=e.flatten([w,k.vs,N],!0),c.predecessors(w).length)){var E=c.node(c.predecessors(w)[0]),C=c.node(c.predecessors(N)[0]);e.has(k,"barycenter")||(k.barycenter=0,k.weight=0),k.barycenter=(k.barycenter*k.weight+E.order+C.order)/(k.weight+2),k.weight+=2}return k}function l(c,h){e.forEach(c,function(p){p.vs=e.flatten(p.vs.map(function(d){return h[d]?h[d].vs:d}),!0)})}function u(c,h){e.isUndefined(c.barycenter)?(c.barycenter=h.barycenter,c.weight=h.weight):(c.barycenter=(c.barycenter*c.weight+h.barycenter*h.weight)/(c.weight+h.weight),c.weight+=h.weight)}return Kg}var Xg,mE;function gD(){if(mE)return Xg;mE=1;var e=it(),n=er().Graph;Xg=r;function r(o,l,u){var c=i(o),h=new n({compound:!0}).setGraph({root:c}).setDefaultNodeLabel(function(p){return o.node(p)});return e.forEach(o.nodes(),function(p){var d=o.node(p),m=o.parent(p);(d.rank===l||d.minRank<=l&&l<=d.maxRank)&&(h.setNode(p),h.setParent(p,m||c),e.forEach(o[u](p),function(y){var w=y.v===p?y.w:y.v,N=h.edge(w,p),_=e.isUndefined(N)?0:N.weight;h.setEdge(w,p,{weight:o.edge(y).weight+_})}),e.has(d,"minRank")&&h.setNode(p,{borderLeft:d.borderLeft[l],borderRight:d.borderRight[l]}))}),h}function i(o){for(var l;o.hasNode(l=e.uniqueId("_root")););return l}return Xg}var Qg,gE;function vD(){if(gE)return Qg;gE=1;var e=it();Qg=n;function n(r,i,o){var l={},u;e.forEach(o,function(c){for(var h=r.parent(c),p,d;h;){if(p=r.parent(h),p?(d=l[p],l[p]=h):(d=u,u=h),d&&d!==h){i.setEdge(d,h);return}h=p}})}return Qg}var Zg,vE;function yD(){if(vE)return Zg;vE=1;var e=it(),n=cD(),r=dD(),i=mD(),o=gD(),l=vD(),u=er().Graph,c=hn();Zg=h;function h(y){var w=c.maxRank(y),N=p(y,e.range(1,w+1),"inEdges"),_=p(y,e.range(w-1,-1,-1),"outEdges"),b=n(y);m(y,b);for(var S=Number.POSITIVE_INFINITY,k,E=0,C=0;C<4;++E,++C){d(E%2?N:_,E%4>=2),b=c.buildLayerMatrix(y);var I=r(y,b);I<S&&(C=0,k=e.cloneDeep(b),S=I)}m(y,k)}function p(y,w,N){return e.map(w,function(_){return o(y,_,N)})}function d(y,w){var N=new u;e.forEach(y,function(_){var b=_.graph().root,S=i(_,b,N,w);e.forEach(S.vs,function(k,E){_.node(k).order=E}),l(_,N,S.vs)})}function m(y,w){e.forEach(w,function(N){e.forEach(N,function(_,b){y.node(_).order=b})})}return Zg}var Jg,yE;function wD(){if(yE)return Jg;yE=1;var e=it(),n=er().Graph,r=hn();Jg={positionX:N,findType1Conflicts:i,findType2Conflicts:o,addConflict:u,hasConflict:c,verticalAlignment:h,horizontalCompaction:p,alignCoordinates:y,findSmallestWidthAlignment:m,balance:w};function i(S,k){var E={};function C(I,P){var A=0,U=0,L=I.length,O=e.last(P);return e.forEach(P,function(q,G){var F=l(S,q),j=F?S.node(F).order:L;(F||q===O)&&(e.forEach(P.slice(U,G+1),function(B){e.forEach(S.predecessors(B),function(z){var ne=S.node(z),Z=ne.order;(Z<A||j<Z)&&!(ne.dummy&&S.node(B).dummy)&&u(E,z,B)})}),U=G+1,A=j)}),P}return e.reduce(k,C),E}function o(S,k){var E={};function C(P,A,U,L,O){var q;e.forEach(e.range(A,U),function(G){q=P[G],S.node(q).dummy&&e.forEach(S.predecessors(q),function(F){var j=S.node(F);j.dummy&&(j.order<L||j.order>O)&&u(E,F,q)})})}function I(P,A){var U=-1,L,O=0;return e.forEach(A,function(q,G){if(S.node(q).dummy==="border"){var F=S.predecessors(q);F.length&&(L=S.node(F[0]).order,C(A,O,G,U,L),O=G,U=L)}C(A,O,A.length,L,P.length)}),A}return e.reduce(k,I),E}function l(S,k){if(S.node(k).dummy)return e.find(S.predecessors(k),function(E){return S.node(E).dummy})}function u(S,k,E){if(k>E){var C=k;k=E,E=C}var I=S[k];I||(S[k]=I={}),I[E]=!0}function c(S,k,E){if(k>E){var C=k;k=E,E=C}return e.has(S[k],E)}function h(S,k,E,C){var I={},P={},A={};return e.forEach(k,function(U){e.forEach(U,function(L,O){I[L]=L,P[L]=L,A[L]=O})}),e.forEach(k,function(U){var L=-1;e.forEach(U,function(O){var q=C(O);if(q.length){q=e.sortBy(q,function(z){return A[z]});for(var G=(q.length-1)/2,F=Math.floor(G),j=Math.ceil(G);F<=j;++F){var B=q[F];P[O]===O&&L<A[B]&&!c(E,O,B)&&(P[B]=O,P[O]=I[O]=I[B],L=A[B])}}})}),{root:I,align:P}}function p(S,k,E,C,I){var P={},A=d(S,k,E,I),U=I?"borderLeft":"borderRight";function L(G,F){for(var j=A.nodes(),B=j.pop(),z={};B;)z[B]?G(B):(z[B]=!0,j.push(B),j=j.concat(F(B))),B=j.pop()}function O(G){P[G]=A.inEdges(G).reduce(function(F,j){return Math.max(F,P[j.v]+A.edge(j))},0)}function q(G){var F=A.outEdges(G).reduce(function(B,z){return Math.min(B,P[z.w]-A.edge(z))},Number.POSITIVE_INFINITY),j=S.node(G);F!==Number.POSITIVE_INFINITY&&j.borderType!==U&&(P[G]=Math.max(P[G],F))}return L(O,A.predecessors.bind(A)),L(q,A.successors.bind(A)),e.forEach(C,function(G){P[G]=P[E[G]]}),P}function d(S,k,E,C){var I=new n,P=S.graph(),A=_(P.nodesep,P.edgesep,C);return e.forEach(k,function(U){var L;e.forEach(U,function(O){var q=E[O];if(I.setNode(q),L){var G=E[L],F=I.edge(G,q);I.setEdge(G,q,Math.max(A(S,O,L),F||0))}L=O})}),I}function m(S,k){return e.minBy(e.values(k),function(E){var C=Number.NEGATIVE_INFINITY,I=Number.POSITIVE_INFINITY;return e.forIn(E,function(P,A){var U=b(S,A)/2;C=Math.max(P+U,C),I=Math.min(P-U,I)}),C-I})}function y(S,k){var E=e.values(k),C=e.min(E),I=e.max(E);e.forEach(["u","d"],function(P){e.forEach(["l","r"],function(A){var U=P+A,L=S[U],O;if(L!==k){var q=e.values(L);O=A==="l"?C-e.min(q):I-e.max(q),O&&(S[U]=e.mapValues(L,function(G){return G+O}))}})})}function w(S,k){return e.mapValues(S.ul,function(E,C){if(k)return S[k.toLowerCase()][C];var I=e.sortBy(e.map(S,C));return(I[1]+I[2])/2})}function N(S){var k=r.buildLayerMatrix(S),E=e.merge(i(S,k),o(S,k)),C={},I;e.forEach(["u","d"],function(A){I=A==="u"?k:e.values(k).reverse(),e.forEach(["l","r"],function(U){U==="r"&&(I=e.map(I,function(G){return e.values(G).reverse()}));var L=(A==="u"?S.predecessors:S.successors).bind(S),O=h(S,I,E,L),q=p(S,I,O.root,O.align,U==="r");U==="r"&&(q=e.mapValues(q,function(G){return-G})),C[A+U]=q})});var P=m(S,C);return y(C,P),w(C,S.graph().align)}function _(S,k,E){return function(C,I,P){var A=C.node(I),U=C.node(P),L=0,O;if(L+=A.width/2,e.has(A,"labelpos"))switch(A.labelpos.toLowerCase()){case"l":O=-A.width/2;break;case"r":O=A.width/2;break}if(O&&(L+=E?O:-O),O=0,L+=(A.dummy?k:S)/2,L+=(U.dummy?k:S)/2,L+=U.width/2,e.has(U,"labelpos"))switch(U.labelpos.toLowerCase()){case"l":O=U.width/2;break;case"r":O=-U.width/2;break}return O&&(L+=E?O:-O),O=0,L}}function b(S,k){return S.node(k).width}return Jg}var ev,wE;function xD(){if(wE)return ev;wE=1;var e=it(),n=hn(),r=wD().positionX;ev=i;function i(l){l=n.asNonCompoundGraph(l),o(l),e.forEach(r(l),function(u,c){l.node(c).x=u})}function o(l){var u=n.buildLayerMatrix(l),c=l.graph().ranksep,h=0;e.forEach(u,function(p){var d=e.max(e.map(p,function(m){return l.node(m).height}));e.forEach(p,function(m){l.node(m).y=h+d/2}),h+=d+c})}return ev}var tv,xE;function _D(){if(xE)return tv;xE=1;var e=it(),n=nD(),r=rD(),i=iD(),o=hn().normalizeRanks,l=oD(),u=hn().removeEmptyRanks,c=aD(),h=lD(),p=uD(),d=yD(),m=xD(),y=hn(),w=er().Graph;tv=N;function N(H,J){var re=J&&J.debugTiming?y.time:y.notime;re("layout",function(){var le=re(" buildLayoutGraph",function(){return L(H)});re(" runLayout",function(){_(le,re)}),re(" updateInputGraph",function(){b(H,le)})})}function _(H,J){J(" makeSpaceForEdgeLabels",function(){O(H)}),J(" removeSelfEdges",function(){$(H)}),J(" acyclic",function(){n.run(H)}),J(" nestingGraph.run",function(){c.run(H)}),J(" rank",function(){i(y.asNonCompoundGraph(H))}),J(" injectEdgeLabelProxies",function(){q(H)}),J(" removeEmptyRanks",function(){u(H)}),J(" nestingGraph.cleanup",function(){c.cleanup(H)}),J(" normalizeRanks",function(){o(H)}),J(" assignRankMinMax",function(){G(H)}),J(" removeEdgeLabelProxies",function(){F(H)}),J(" normalize.run",function(){r.run(H)}),J(" parentDummyChains",function(){l(H)}),J(" addBorderSegments",function(){h(H)}),J(" order",function(){d(H)}),J(" insertSelfEdges",function(){Q(H)}),J(" adjustCoordinateSystem",function(){p.adjust(H)}),J(" position",function(){m(H)}),J(" positionSelfEdges",function(){M(H)}),J(" removeBorderNodes",function(){Z(H)}),J(" normalize.undo",function(){r.undo(H)}),J(" fixupEdgeLabelCoords",function(){z(H)}),J(" undoCoordinateSystem",function(){p.undo(H)}),J(" translateGraph",function(){j(H)}),J(" assignNodeIntersects",function(){B(H)}),J(" reversePoints",function(){ne(H)}),J(" acyclic.undo",function(){n.undo(H)})}function b(H,J){e.forEach(H.nodes(),function(re){var le=H.node(re),fe=J.node(re);le&&(le.x=fe.x,le.y=fe.y,J.children(re).length&&(le.width=fe.width,le.height=fe.height))}),e.forEach(H.edges(),function(re){var le=H.edge(re),fe=J.edge(re);le.points=fe.points,e.has(fe,"x")&&(le.x=fe.x,le.y=fe.y)}),H.graph().width=J.graph().width,H.graph().height=J.graph().height}var S=["nodesep","edgesep","ranksep","marginx","marginy"],k={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},E=["acyclicer","ranker","rankdir","align"],C=["width","height"],I={width:0,height:0},P=["minlen","weight","width","height","labeloffset"],A={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},U=["labelpos"];function L(H){var J=new w({multigraph:!0,compound:!0}),re=Y(H.graph());return J.setGraph(e.merge({},k,V(re,S),e.pick(re,E))),e.forEach(H.nodes(),function(le){var fe=Y(H.node(le));J.setNode(le,e.defaults(V(fe,C),I)),J.setParent(le,H.parent(le))}),e.forEach(H.edges(),function(le){var fe=Y(H.edge(le));J.setEdge(le,e.merge({},A,V(fe,P),e.pick(fe,U)))}),J}function O(H){var J=H.graph();J.ranksep/=2,e.forEach(H.edges(),function(re){var le=H.edge(re);le.minlen*=2,le.labelpos.toLowerCase()!=="c"&&(J.rankdir==="TB"||J.rankdir==="BT"?le.width+=le.labeloffset:le.height+=le.labeloffset)})}function q(H){e.forEach(H.edges(),function(J){var re=H.edge(J);if(re.width&&re.height){var le=H.node(J.v),fe=H.node(J.w),te={rank:(fe.rank-le.rank)/2+le.rank,e:J};y.addDummyNode(H,"edge-proxy",te,"_ep")}})}function G(H){var J=0;e.forEach(H.nodes(),function(re){var le=H.node(re);le.borderTop&&(le.minRank=H.node(le.borderTop).rank,le.maxRank=H.node(le.borderBottom).rank,J=e.max(J,le.maxRank))}),H.graph().maxRank=J}function F(H){e.forEach(H.nodes(),function(J){var re=H.node(J);re.dummy==="edge-proxy"&&(H.edge(re.e).labelRank=re.rank,H.removeNode(J))})}function j(H){var J=Number.POSITIVE_INFINITY,re=0,le=Number.POSITIVE_INFINITY,fe=0,te=H.graph(),ce=te.marginx||0,Ce=te.marginy||0;function ve(je){var ye=je.x,ke=je.y,Ke=je.width,we=je.height;J=Math.min(J,ye-Ke/2),re=Math.max(re,ye+Ke/2),le=Math.min(le,ke-we/2),fe=Math.max(fe,ke+we/2)}e.forEach(H.nodes(),function(je){ve(H.node(je))}),e.forEach(H.edges(),function(je){var ye=H.edge(je);e.has(ye,"x")&&ve(ye)}),J-=ce,le-=Ce,e.forEach(H.nodes(),function(je){var ye=H.node(je);ye.x-=J,ye.y-=le}),e.forEach(H.edges(),function(je){var ye=H.edge(je);e.forEach(ye.points,function(ke){ke.x-=J,ke.y-=le}),e.has(ye,"x")&&(ye.x-=J),e.has(ye,"y")&&(ye.y-=le)}),te.width=re-J+ce,te.height=fe-le+Ce}function B(H){e.forEach(H.edges(),function(J){var re=H.edge(J),le=H.node(J.v),fe=H.node(J.w),te,ce;re.points?(te=re.points[0],ce=re.points[re.points.length-1]):(re.points=[],te=fe,ce=le),re.points.unshift(y.intersectRect(le,te)),re.points.push(y.intersectRect(fe,ce))})}function z(H){e.forEach(H.edges(),function(J){var re=H.edge(J);if(e.has(re,"x"))switch((re.labelpos==="l"||re.labelpos==="r")&&(re.width-=re.labeloffset),re.labelpos){case"l":re.x-=re.width/2+re.labeloffset;break;case"r":re.x+=re.width/2+re.labeloffset;break}})}function ne(H){e.forEach(H.edges(),function(J){var re=H.edge(J);re.reversed&&re.points.reverse()})}function Z(H){e.forEach(H.nodes(),function(J){if(H.children(J).length){var re=H.node(J),le=H.node(re.borderTop),fe=H.node(re.borderBottom),te=H.node(e.last(re.borderLeft)),ce=H.node(e.last(re.borderRight));re.width=Math.abs(ce.x-te.x),re.height=Math.abs(fe.y-le.y),re.x=te.x+re.width/2,re.y=le.y+re.height/2}}),e.forEach(H.nodes(),function(J){H.node(J).dummy==="border"&&H.removeNode(J)})}function $(H){e.forEach(H.edges(),function(J){if(J.v===J.w){var re=H.node(J.v);re.selfEdges||(re.selfEdges=[]),re.selfEdges.push({e:J,label:H.edge(J)}),H.removeEdge(J)}})}function Q(H){var J=y.buildLayerMatrix(H);e.forEach(J,function(re){var le=0;e.forEach(re,function(fe,te){var ce=H.node(fe);ce.order=te+le,e.forEach(ce.selfEdges,function(Ce){y.addDummyNode(H,"selfedge",{width:Ce.label.width,height:Ce.label.height,rank:ce.rank,order:te+ ++le,e:Ce.e,label:Ce.label},"_se")}),delete ce.selfEdges})})}function M(H){e.forEach(H.nodes(),function(J){var re=H.node(J);if(re.dummy==="selfedge"){var le=H.node(re.e.v),fe=le.x+le.width/2,te=le.y,ce=re.x-fe,Ce=le.height/2;H.setEdge(re.e,re.label),H.removeNode(J),re.label.points=[{x:fe+2*ce/3,y:te-Ce},{x:fe+5*ce/6,y:te-Ce},{x:fe+ce,y:te},{x:fe+5*ce/6,y:te+Ce},{x:fe+2*ce/3,y:te+Ce}],re.label.x=re.x,re.label.y=re.y}})}function V(H,J){return e.mapValues(e.pick(H,J),Number)}function Y(H){var J={};return e.forEach(H,function(re,le){J[le.toLowerCase()]=re}),J}return tv}var nv,_E;function bD(){if(_E)return nv;_E=1;var e=it(),n=hn(),r=er().Graph;nv={debugOrdering:i};function i(o){var l=n.buildLayerMatrix(o),u=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(c){u.setNode(c,{label:c}),u.setParent(c,"layer"+o.node(c).rank)}),e.forEach(o.edges(),function(c){u.setEdge(c.v,c.w,{},c.name)}),e.forEach(l,function(c,h){var p="layer"+h;u.setNode(p,{rank:"same"}),e.reduce(c,function(d,m){return u.setEdge(d,m,{style:"invis"}),m})}),u}return nv}var rv,bE;function SD(){return bE||(bE=1,rv="0.8.5"),rv}var sv,SE;function kD(){return SE||(SE=1,sv={graphlib:er(),layout:_D(),debug:bD(),util:{time:hn().time,notime:hn().notime},version:SD()}),sv}var ED=kD();const kE=Av(ED),wo=240,ku=130,ho=74,Xu=72,EE=ho+Xu;function ND(e,n){var i;let r=wo;for(const o of e)r=Math.max(r,((i=n.get(o.id))==null?void 0:i.width)??wo);return r}const ER=420,CD=2;function ja(e){var r;return((r=e.data)==null?void 0:r.sessionId)??"_default"}function RD(e,n){return((n==null?void 0:n.get(e))??0)>0?ER:0}function TD(e,n){const r=(n==null?void 0:n.get(e))??0;return r>0?6+r*36:0}function Aa(e,n,r){const i=n.get(e);return{w:((i==null?void 0:i.width)??wo)+RD(e,r),h:Math.max((i==null?void 0:i.height)??ku,TD(e,r))}}function jD(e){return[...e.keys()].sort().map(n=>`${n}:${e.get(n)}`).join("|")}function AD(e,n,r,i,o,l){const u=new kE.graphlib.Graph;u.setDefaultEdgeLabel(()=>({})),u.setGraph({rankdir:r,marginx:0,marginy:0,nodesep:70,ranksep:160,edgesep:30});const c=e.filter(S=>!o.has(S)),h=new Set(c);for(const S of c){const{w:k,h:E}=Aa(S,i,l);u.setNode(S,{width:k,height:E})}for(const S of n)h.has(S.source)&&h.has(S.target)&&u.setEdge(S.source,S.target);kE.layout(u);const p=new Map;let d=1/0,m=1/0,y=-1/0,w=-1/0;for(const S of c){const k=u.node(S);if(!k)continue;const E=i.get(S),C=(E==null?void 0:E.width)??wo,I=(E==null?void 0:E.height)??ku,P=Aa(S,i,l),A=k.x-P.w/2,U=k.y-P.h/2;p.set(S,{x:A,y:U}),A<d&&(d=A),U<m&&(m=U),A+C>y&&(y=A+C),U+I>w&&(w=U+I)}if(Number.isFinite(d)&&Number.isFinite(m))for(const[S,k]of p)p.set(S,{x:k.x-d,y:k.y-m});const N=Number.isFinite(y)?y-d:0,_=Number.isFinite(w)?w-m:0;let b=null;for(const S of e){const k=o.get(S);if(!k)continue;const E=i.get(S),C=(E==null?void 0:E.width)??wo,I=(E==null?void 0:E.height)??ku;b=b===null?{minX:k.x,minY:k.y,maxX:k.x+C,maxY:k.y+I}:{minX:Math.min(b.minX,k.x),minY:Math.min(b.minY,k.y),maxX:Math.max(b.maxX,k.x+C),maxY:Math.max(b.maxY,k.y+I)}}return{positions:p,width:N,height:_,pinnedBox:b}}function ID(e,n,r={}){const i=r.direction??"LR",o=r.pinned??new Map,l=r.measured??new Map,u=r.lanes,c=new Map;for(const S of e){const k=ja(S),E=c.get(k);E?E.push(S.id):c.set(k,[S.id])}const p=Array.from(c.keys()).sort().map(S=>({sid:S,...AD(c.get(S),n,i,l,o,u)})),d=ND(e,l),m=r.availableHeight&&r.availableHeight>0?r.availableHeight:Number.POSITIVE_INFINITY,y=S=>{const k=[[]];let E=0;for(const C of p)k.length<S&&E>0&&E+C.height>m&&(k.push([]),E=0),k[k.length-1].push(C),E+=C.height+EE;return k},w=S=>S.reduce((k,E)=>Math.max(k,E.width),0)+ER;let N=y(r.availableWidth?CD:1);N.length>1&&N.reduce((k,E)=>k+w(E),0)+d*(N.length-1)>(r.availableWidth??0)&&(N=y(1));const _=new Map;let b=0;for(const S of N){const k=w(S);let E=0;for(const{positions:C,height:I,pinnedBox:P}of S){for(const[U,L]of C)_.set(U,{x:L.x+b,y:L.y+E});let A=E+I;P&&P.maxY>A&&P.minX<b+k&&b<P.maxX&&(A=P.maxY),E=A+EE}b+=k+d}return e.map(S=>{const k=o.get(S.id);if(k)return{...S,position:k};const E=_.get(S.id);return E?{...S,position:E}:S})}function MD(e,n,r,i,o){const u=ho+Xu,c=60,h=w=>Aa(w,i,o),p=new Map(e.map(w=>[w.id,ja(w)])),d=[],m=e.map(w=>({id:w.id,pos:r.get(w.id)??n.get(w.id)})).filter(w=>w.pos!=null).sort((w,N)=>w.pos.y-N.pos.y||w.pos.x-N.pos.x||w.id.localeCompare(N.id)),y=[];for(const{id:w,pos:N}of m){const{w:_,h:b}=h(w),S=p.get(w)??"_default";if(r.has(w)){d.push({x:N.x,y:N.y,w:_,h:b,sid:S});continue}let k=N.y;for(let E=0;E<d.length+1;E++){const C=d.find(I=>{const P=I.sid===S?24:c,A=I.sid===S?24:u;return N.x<I.x+I.w+P&&I.x<N.x+_+P&&k<I.y+I.h+A&&I.y<k+b+A});if(!C)break;k=C.y+C.h+(C.sid===S?24:u)}k!==N.y&&(n.set(w,{x:N.x,y:k}),y.push(w)),d.push({x:N.x,y:k,w:_,h:b,sid:S})}return y}function OD(e,n,r,i,o,l){const u=_=>Aa(_,i,l),c=_=>r.get(_)??n.get(_),h=new Map;for(const _ of e){if(!c(_.id))continue;const b=ja(_),S=h.get(b);S?S.push(_):h.set(b,[_])}const p=new Set;for(const[_,b]of h)b.every(S=>o.has(S.id)&&!r.has(S.id))&&p.add(_);const d=new Map,m=[];for(const _ of e){const b=c(_.id);if(!b)continue;const{w:S,h:k}=u(_.id),E=ja(_);p.has(E)?(d.get(E)??d.set(E,[]).get(E)).push(_):m.push({x:b.x,y:b.y,w:S,h:k})}if(d.size===0)return[];const y=ho+Xu,w=(_,b,S,k)=>m.some(E=>_<E.x+E.w+ho&&E.x<_+S+ho&&b<E.y+E.h+y&&E.y<b+k+y),N=[];for(const _ of[...d.keys()].sort()){const b=d.get(_);let S=1/0,k=1/0,E=-1/0,C=-1/0;for(const q of b){const G=c(q.id),{w:F,h:j}=u(q.id);S=Math.min(S,G.x),k=Math.min(k,G.y),E=Math.max(E,G.x+F),C=Math.max(C,G.y+j)}const I=E-S,P=C-k,A=[...new Set(m.map(q=>Math.round(q.x)))].sort((q,G)=>q-G),U=A.length?A:[S],L=[0,...m.map(q=>q.y+q.h+y)].sort((q,G)=>q-G);let O=null;e:for(const q of U)for(const G of L){if(G>=k)break;if(!w(q,G,I,P)){O={x:q,y:G};break e}}if(O){const q=O.x-S,G=O.y-k;for(const F of b){const j=c(F.id);n.set(F.id,{x:j.x+q,y:j.y+G})}N.push(_)}for(const q of b){const G=c(q.id),{w:F,h:j}=u(q.id);m.push({x:G.x,y:G.y,w:F,h:j})}}return N}function PD(e,n,r,i,o,l=!1,u){const p=ho+Xu+1,d=8,m=1.75,y=200,w=.7,N=.01,_=O=>Aa(O,i,u),b=O=>r.get(O)??n.get(O),S=new Map;for(const O of e){if(!b(O.id))continue;const q=ja(O),G=S.get(q);G?G.push(O):S.set(q,[O])}const k=[],E=new Set,C=new Set,I=o.size===0;for(const O of[...S.keys()].sort()){const q=S.get(O);let G=1/0,F=1/0,j=-1/0,B=-1/0,z=!1;for(const Q of q){const M=b(Q.id),{w:V,h:Y}=_(Q.id);G=Math.min(G,M.x),F=Math.min(F,M.y),j=Math.max(j,M.x+V),B=Math.max(B,M.y+Y),r.has(Q.id)&&(z=!0)}const ne=j-G,Z=B-F;C.add(O);const $=o.get(O);$&&(ne>$.w+d||Z>$.h+d)&&E.add(O),o.set(O,{w:ne,h:Z}),k.push({sid:O,members:q.map(Q=>Q.id),x:G,y:F,w:ne,h:Z,anchored:z,mass:1})}for(const O of[...o.keys()])C.has(O)||o.delete(O);if(l||I)return[];let P=!1;for(let O=0;O<k.length&&!P;O++)for(let q=O+1;q<k.length;q++){const G=k[O],F=k[q];if(!(G.anchored&&F.anchored)&&Math.abs(G.x+G.w/2-(F.x+F.w/2))<(G.w+F.w)/2+61&&Math.abs(G.y+G.h/2-(F.y+F.h/2))<(G.h+F.h)/2+p){P=!0;break}}if(E.size===0&&!P)return[];if(E.size>0)for(const O of k)E.has(O.sid)&&(O.mass=8);else for(const O of k)O.mass=Math.max(1,O.w*O.h/(wo*ku));const A=new Map(k.map(O=>[O.sid,O.x])),U=new Map(k.map(O=>[O.sid,O.y]));for(let O=0;O<y;O++){const q=new Map,G=new Map;let F=0;for(let j=0;j<k.length;j++)for(let B=j+1;B<k.length;B++){const z=k[j],ne=k[B];if(z.anchored&&ne.anchored)continue;const Z=z.x+z.w/2,$=z.y+z.h/2,Q=ne.x+ne.w/2,M=ne.y+ne.h/2,V=(z.w+ne.w)/2+61-Math.abs(Z-Q),Y=(z.h+ne.h)/2+p-Math.abs($-M);if(V<=0||Y<=0)continue;const H=($e,Je)=>!$e.anchored&&!(Je<0&&$e.x<=0),J=($e,Je)=>!$e.anchored&&!(Je<0&&$e.y<=0),re=($e,Je,Xe)=>{const vt=$e===Je,ot=vt?z.sid<ne.sid?-1:1:Math.sign($e-Je);return Xe(z,ot)||Xe(ne,-ot)?ot:vt&&(Xe(z,-ot)||Xe(ne,ot))?-ot:0},le=re(Z,Q,H),fe=re($,M,J),te=le!==0,ce=fe!==0;if(!te&&!ce)continue;const Ce=te&&(!ce||V*m<Y),[ve,je,ye,ke]=Ce?[le,V,q,H]:[fe,Y,G,J],Ke=ke(z,ve),we=ke(ne,-ve),_e=z.mass,Be=ne.mass,ft=Ke?we?Be/(_e+Be):1:0,ht=we?Ke?_e/(_e+Be):1:0,We=je*w;ye.set(z.sid,(ye.get(z.sid)??0)+ve*We*ft),ye.set(ne.sid,(ye.get(ne.sid)??0)-ve*We*ht),F+=We}for(const j of k)j.anchored||(j.x=Math.max(0,j.x+(q.get(j.sid)??0)),j.y=Math.max(0,j.y+(G.get(j.sid)??0)));if(F<N)break}const L=[];for(const O of k){const q=O.x-A.get(O.sid),G=O.y-U.get(O.sid);if(!(Math.abs(q)<1&&Math.abs(G)<1)){for(const F of O.members){if(r.has(F))continue;const j=n.get(F);j&&n.set(F,{x:j.x+q,y:j.y+G})}L.push(O.sid)}}return L}const LD=600;function Cv(e,n){return!(e.exitAt!=null&&n-e.exitAt>LD||e.kind==="root"&&e.state==="done"&&e.tools.length===0&&e.endedAt!=null&&e.endedAt-e.startedAt<3e3)}function qD(e,n){const r=new Set;for(const i of e.agents.values())Cv(i,n)&&r.add(i.id);return r}function $D(e,n,r=0){return e.right+r>n.left&&e.left-r<n.right&&e.bottom+r>n.top&&e.top-r<n.bottom}function DD(e,n,r=0){if(!e)return!1;for(const i of n)if($D(e,i,r))return!0;return!1}const NR="sessionGroup";function FD(e,n){var i;if(e.type===NR)return"transparent";const r=(i=e.data)==null?void 0:i.state;return n(r==="err"?"--err":r==="active"?"--inflight":"--ok")}const zD="Update checks are off (AGENTS_DECK_NO_UPDATE_CHECK=1).";function BD(e){if(e.checkDisabled)return zD;if(e.checking)return"Asking npm for the newest release…";const n=e.latest?`npm has v${e.latest}`:e.latestPending?`npm's latest tag names v${e.latestPending}, which it cannot serve yet`:"npm not reached yet",r=e.checkedAgo?` · checked ${e.checkedAgo}`:"";return`${n}${r} · re-checked periodically · click to check npm now`}function UD(e){const n=`Version v${e.running}`;return e.checkDisabled?`${n}, update checks are off`:e.checking?`${n}, checking npm for a newer release`:`${n}, check npm for a newer release`}function HD(e){if(e==null)return{kind:"unknown",lead:"No data yet. Start a Claude Code or Codex session — it appears here as soon as its first hook fires.",workspace:null,tail:""};const n=e.trim();return n===""?{kind:"machine",lead:"No data yet. Start a Claude Code or Codex session anywhere on this machine — this deck is unscoped and captures every workspace.",workspace:null,tail:""}:{kind:"scoped",lead:"No data yet. This deck only captures sessions running under",workspace:n,tail:" — start one there, or restart it without --workspace/--scope to watch the whole machine."}}function CR(e){const n=Math.max(0,Math.floor(e));return`${n} event${n===1?"":"s"}`}function WD(e){return e.connected?e.paused?{tone:"paused",label:"paused",title:e.held>0?`Connected — ${CR(e.held)} held until you resume (Space)`:"Connected — updates held until you resume (Space)"}:{tone:"live",label:"live",title:"Receiving events"}:{tone:"dead",label:"offline",title:e.paused?"SSE disconnected — and the canvas is paused, so resuming will not bring events back until it reconnects":"SSE disconnected"}}function VD(e){return e.paused?e.held<=0?{label:"Resume",title:"Nothing has arrived since you paused. Resume to follow the canvas again (Space)"}:{label:`Resume · ${e.held} held`,title:`${CR(e.held)} arrived while paused and will be applied in order when you resume (Space)`}:{label:"Pause",title:"Pause live updates — events keep arriving and are applied when you resume (Space)"}}function RR(e,n){return e!==""&&n>0}function GD(e,n,r){return e===""?{active:!1,matched:n,total:r,count:null,empty:!1,message:null,dim:!1}:{active:!0,matched:n,total:r,count:`${n} of ${r}`,empty:n===0,message:n===0?`No agents match “${e}”`:null,dim:RR(e,n)}}function Rv(e){const n=Math.max(0,Math.floor(e/1e3));return n<60?"just now":n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:`${Math.floor(n/86400)}d ago`}function YD(e,n){return e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()}function KD(e,n,r){const i=new Date(e),o=Rv(n-e);return{label:YD(i,new Date(n))?o:`${o} · ${i.toLocaleDateString(r,{month:"short",day:"numeric"})}`,title:i.toLocaleString(r,{dateStyle:"medium",timeStyle:"medium"})}}function ma(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const XD={agent:zP,sessionGroup:t3},TR="react-flow__node";function NE(e){var n,r;return!!e&&((r=(n=e.classList)==null?void 0:n.contains)==null?void 0:r.call(n,TR))===!0}function QD(e){try{const n=document.querySelector(`.${TR}[data-id="${CSS.escape(e)}"]`);n==null||n.focus({preventScroll:!0})}catch{}}const ZD=420,iu=18,JD=9e4,e5=200,t5=5*6e4,n5=6,r5=2*6e4,yy="agent-dag.layout",wy="agent-dag.viewport",jR="agent-dag.summariesDismissed",AR="agent-dag.sessionListOpen",IR="agent-dag.detailOpen",MR="agent-dag.usagePanelOpen",CE="agent-dag.accountsPanelOpen",RE="agent-dag.versionNoticeDismissed",TE="agent-dag.oldNameNoticeDismissed",s5=15*6e4,jE={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:"},AE="agent-dag.autoRestart",IE="agent-dag.bundleReloadedFor";function i5(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(AR)==="1"}catch{return!1}}function o5(e){if(!(typeof window>"u"))try{window.localStorage.setItem(AR,e?"1":"0")}catch{}}function a5(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(IR)==="1"}catch{return!1}}function l5(e){if(!(typeof window>"u"))try{window.localStorage.setItem(IR,e?"1":"0")}catch{}}function u5(){const e=kC(MR);return e===null?!0:e==="1"}function c5(e){if(!(typeof window>"u"))try{window.localStorage.setItem(MR,e?"1":"0")}catch{}}function d5(){if(typeof window>"u")return new Set;try{const e=window.localStorage.getItem(jR);if(!e)return new Set;const n=JSON.parse(e);return new Set(Array.isArray(n)?n.filter(r=>typeof r=="string"):[])}catch{return new Set}}function ME(e){if(!(typeof window>"u"))try{const n=Array.from(e),r=n.length>200?n.slice(-200):n;window.localStorage.setItem(jR,JSON.stringify(r))}catch{}}function f5(){const e={positions:[],pins:[]};if(typeof window>"u")return e;try{const n=window.localStorage.getItem(yy);if(!n)return e;const r=JSON.parse(n);if(!("v"in r)){const o=Object.entries(r).filter(([,l])=>l&&typeof l.x=="number"&&typeof l.y=="number");return{positions:o,pins:o.map(([l])=>l)}}return{positions:Object.entries(r.positions??{}).filter(([,o])=>o&&typeof o.x=="number"&&typeof o.y=="number"),pins:Array.isArray(r.pins)?r.pins:[]}}catch{return e}}function iv(e,n){if(!(typeof window>"u"))try{const r={};for(const[i,o]of e)r[i]=o;for(const[i,o]of n)r[i]=o;window.localStorage.setItem(yy,JSON.stringify({v:2,positions:r,pins:Array.from(n.keys())}))}catch{}}function h5(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(wy);if(!e)return null;const n=JSON.parse(e);return typeof(n==null?void 0:n.x)!="number"||typeof(n==null?void 0:n.y)!="number"||typeof(n==null?void 0:n.zoom)!="number"?null:n}catch{return null}}function p5(e){if(!(typeof window>"u"))try{window.localStorage.setItem(wy,JSON.stringify(e))}catch{}}function OE(){if(!(typeof window>"u")){try{window.localStorage.removeItem(yy)}catch{}try{window.localStorage.removeItem(wy)}catch{}}}function m5(e,n){const r=e.agents.get(n);if(!r)return;const i=[];for(const d of e.agents.values())d.sessionId===n&&i.push(d);const o={schemaVersion:1,exportedAt:new Date().toISOString(),sessionId:n,label:r.label,cwd:r.cwd,startedAt:r.startedAt,endedAt:r.endedAt,model:r.model,agents:i.map(d=>({id:d.id,kind:d.kind,label:d.label,parentId:d.parentId,state:d.state,startedAt:d.startedAt,endedAt:d.endedAt,model:d.model,cwd:d.cwd,usage:d.usage,prompts:d.prompts,tools:d.tools.map(m=>({id:m.id,name:m.name,inputPreview:m.inputPreview,startedAt:m.startedAt,endedAt:m.endedAt,ok:m.ok,errorPreview:m.errorPreview,usage:m.usage}))}))},l=JSON.stringify(o,null,2),u=new Blob([l],{type:"application/json"}),c=URL.createObjectURL(u),h=document.createElement("a"),p=(r.label||"session").replace(/[^a-z0-9._-]/gi,"_");h.href=c,h.download=`${tn}-${p}-${n.slice(0,8)}.json`,document.body.appendChild(h),h.click(),document.body.removeChild(h),setTimeout(()=>URL.revokeObjectURL(c),1e3)}const Tv={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},jv={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},g5={Read:"file",Write:"file",Edit:"file",MultiEdit:"file",Glob:"file",Grep:"file",LS:"file",NotebookEdit:"file",Bash:"shell",PowerShell:"shell",shell:"shell",exec_command:"shell",shell_command:"shell",write_stdin:"shell",wait:"shell",apply_patch:"file",update_plan:"task",WebFetch:"web",WebSearch:"web",Task:"agent",Agent:"agent",TodoWrite:"task",TaskCreate:"task",TaskUpdate:"task",TaskList:"task",TaskGet:"task",TaskOutput:"task",TaskStop:"task",EnterPlanMode:"plan",ExitPlanMode:"plan",AskUserQuestion:"plan",Skill:"plan",Workflow:"plan"};function OR(e){return e.startsWith("mcp__")?"mcp":g5[e]??"other"}function PR(e,n){var i,o,l;if(!n)return!0;const r=n.toLowerCase();if(e.label.toLowerCase().includes(r)||(i=e.cwd)!=null&&i.toLowerCase().includes(r)||(o=e.cwdBasename)!=null&&o.toLowerCase().includes(r)||e.sessionId.toLowerCase().includes(r)||(l=e.firstPrompt)!=null&&l.toLowerCase().includes(r))return!0;for(const u of e.tools)if(u.name.toLowerCase().includes(r))return!0;return!1}function v5(e,n){if(!n)return null;const r=new Set([n]);let i=n;for(;i;){const l=e.agents.get(i);if(!(l!=null&&l.parentId)||r.has(l.parentId))break;r.add(l.parentId),i=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 y5(e,n,r,i,o,l,u,c,h,p,d,m,y,w,N,_,b,S,k){const E=[],C=[],I=new Set;if(l)for(const F of e.agents.values())S.has(F.id)&&PR(F,l)&&I.add(F.id);const P=RR(l,I.size);for(const F of e.agents.values()){if(!S.has(F.id))continue;const j=P&&!I.has(F.id),B=F.exitAt!=null,z=b!=null&&!b.has(F.id),ne=[j?"rf-dim":"",B?"rf-exiting":"",z?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,Z=u.get(F.id);if(E.push({id:F.id,type:"agent",position:{x:0,y:0},data:{...F,now:n,onOpenContext:k},className:ne,...Z?{width:Z.width,height:Z.height}:null}),F.parentId&&S.has(F.parentId)){const $=Kv(F.sessionId),Q=l&&!I.has(F.id)&&!I.has(F.parentId),M=B,V=_.size>0&&(_.has(F.id)||_.has(F.parentId)),Y=b!=null&&!b.has(F.id)&&!b.has(F.parentId),H=F.state==="active"?2:1.5,J=V?H+1.5:H,re=Q||M?.2:Y?.12:1,le=["sess-edge",F.state==="active"?"sess-live":"sess-idle",M?"rf-edge-exiting":"",V?"rf-edge-selected":""].filter(Boolean).join(" ");C.push({id:`e:${F.parentId}->${F.id}`,source:F.parentId,target:F.id,animated:(F.state==="active"||V)&&!Q&&!M,type:"smoothstep",style:{"--session-hue":$,strokeWidth:J,opacity:re,transition:"opacity 500ms ease, stroke-width 200ms ease"},className:le})}}const A=new Map;for(const F of e.agents.values())F.tools.length>0&&A.set(F.id,Math.min(4,F.tools.length));const U=`${w}#lanes:${jD(A)}`,L=E.filter(F=>zL(F.id,o,m,y));if(L.length>0||U!==N.current){if(L.length>0){const F=ID(E,C,{direction:"LR",pinned:o,measured:u,availableWidth:r,availableHeight:i,lanes:A});for(const j of F)SC(j.id,m,y)&&UL(j.id,j.position,m,y);OD(E,m,o,u,new Set(L.map(j=>j.id)),A)}MD(E,m,o,u,A),N.current=U}const O=PD(E,m,o,u,c,!p||d,A);O.length>0&&h(O),tu(m,e.agents),tu(y,e.agents),tu(o,e.agents),tu(u,FL(e.agents.values()));const q=[];let G=!1;for(const F of E){let j=o.get(F.id)??m.get(F.id);j||(j=BL(F.id,m,y),G=!0),q.push({...F,position:j})}return G&&(N.current=""),{nodes:q,edges:C}}function w5(){return g.jsx(Yv,{children:g.jsx(x5,{})})}function x5(){var Ha,Wa,Ai,Va;const e=La(),n=T.useRef(bv()),[,r]=T.useState(0),i=T.useCallback(()=>r(W=>W+1),[]),[o,l]=T.useState(()=>new Set),[u,c]=T.useState(null),[h,p]=T.useState(null),d=T.useCallback((W,K)=>{l(ae=>{if(!K)return new Set([W]);const de=new Set(ae);return de.has(W)?de.delete(W):de.add(W),de}),c(ae=>K&&ae===W?ae:W)},[]),m=T.useCallback(()=>{l(new Set),c(null)},[]),[y,w]=T.useState(null),[N,_]=T.useState(null),b=T.useCallback(W=>_(W),[]),[S,k]=T.useState(!1),E=T.useRef(d5()),[C,I]=T.useState(i5);T.useEffect(()=>{o5(C)},[C]);const[P,A]=T.useState(a5);T.useEffect(()=>{l5(P)},[P]);const[U,L]=T.useState(u5);T.useEffect(()=>{c5(U)},[U]);const[O,q]=T.useState(()=>{try{const W=window.localStorage.getItem(CE);return W===null?!0:W==="1"}catch{return!0}});T.useEffect(()=>{try{window.localStorage.setItem(CE,O?"1":"0")}catch{}},[O]);const[G,F]=T.useState(null),[j,B]=T.useState(!1),[z,ne]=T.useState(0),[Z,$]=T.useState(0);T.useEffect(()=>{fetch("/api/sound-hook").then(W=>W.ok?W.json():null).then(W=>{W!=null&&W.ok&&(F(W.enabled===!0),ne((W.foreign??[]).filter(K=>K.worksHere).length),$(typeof W.parked=="number"?W.parked:0))}).catch(()=>{})},[]);const Q=T.useCallback(async()=>{B(!0);try{const K=await(await fetch("/api/sound-hook",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!G})})).json().catch(()=>null);K!=null&&K.ok&&F(K.enabled===!0),fetch("/api/sound-hook").then(ae=>ae.ok?ae.json():null).then(ae=>{ae!=null&&ae.ok&&(ne((ae.foreign??[]).filter(de=>de.worksHere).length),$(typeof ae.parked=="number"?ae.parked:0))}).catch(()=>{})}catch{}finally{B(!1)}},[G]),[M,V]=T.useState(!1),[Y,H]=T.useState(null),[J,re]=T.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(RE)??""}catch{return""}}),[le,fe]=T.useState(!1),te=T.useRef(0),[ce,Ce]=T.useState(!1),ve=T.useCallback((W=!1)=>{W&&(te.current=Date.now(),Ce(!0)),fetch(W?"/api/version?refresh=1":"/api/version").then(K=>K.ok?K.json():null).then(K=>{K&&H(K)}).catch(()=>{}).finally(()=>{W&&Ce(!1)})},[]),je=T.useCallback(()=>{ve(Date.now()-te.current>=s5)},[ve]);T.useEffect(()=>{ve();const W=window.setInterval(je,5*6e4),K=()=>{document.visibilityState==="visible"&&je()};return document.addEventListener("visibilitychange",K),()=>{window.clearInterval(W),document.removeEventListener("visibilitychange",K)}},[ve,je]),T.useEffect(()=>{M&&ve()},[M,ve]);const ye=(Y==null?void 0:Y.notice)??null,[ke,Ke]=T.useState(null);T.useEffect(()=>{let W=!1;return fetch("/api/health").then(K=>K.ok?K.json():null).then(K=>{W||!K||typeof K.workspace!="string"||Ke(K.workspace)}).catch(()=>{}),()=>{W=!0}},[M]);const we=ye?`${ye.kind}:${ye.to}`:"",_e=ye!=null&&J!==we,Be=T.useCallback(()=>{if(!ye)return;const W=J===we?"":we;re(W);try{window.localStorage.setItem(RE,W)}catch{}},[ye,we,J]),[ft,ht]=T.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(TE)??""}catch{return""}}),We=Y!=null&&Y.invokedAs&&Y.invokedAs!==tn?Y.invokedAs:null,$e=We!=null&&ft!==We,Je=T.useCallback(()=>{if(We){ht(We);try{window.localStorage.setItem(TE,We)}catch{}}},[We]),Xe=((Ha=Y==null?void 0:Y.upgrade)==null?void 0:Ha.state)??"idle",vt=TL(Y==null?void 0:Y.upgrade),ot=T.useCallback(async()=>{try{await fetch("/api/upgrade",{method:"POST"})}catch{}ve()},[ve]);T.useEffect(()=>{if(Xe!=="running")return;const W=window.setInterval(ve,3e3);return()=>window.clearInterval(W)},[Xe,ve]);const yt=T.useCallback(async()=>{var ae;const W=Y==null?void 0:Y.command;if(!W)return;let K=!1;try{K=await Promise.race([((ae=navigator.clipboard)==null?void 0:ae.writeText(W).then(()=>!0))??Promise.resolve(!1),new Promise(de=>window.setTimeout(()=>de(!1),500))])}catch{K=!1}if(!K)try{const de=document.createElement("textarea");de.value=W,de.setAttribute("readonly",""),de.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(de),de.select(),K=document.execCommand("copy"),de.remove()}catch{K=!1}K&&(fe(!0),window.setTimeout(()=>fe(!1),1600))},[Y==null?void 0:Y.command]),Gt=T.useCallback(()=>{I(W=>(W||q(!1),!W))},[]),It=T.useCallback(()=>{q(W=>(W||I(!1),!W))},[]),[Ze,wt]=T.useState(!1),[pt,mt]=T.useState(0),_n=T.useRef(null),[Yt,Mt]=T.useState(!1),Kt=T.useRef(null),[yr,bn]=T.useState(0),Xt=T.useRef(GL()),[pn,Sn]=T.useState(!1),Gr=T.useCallback(()=>{const W=Xt.current,K=W.setPaused(!W.paused);for(const ae of K)n.current=Mx(n.current,ae);Sn(W.paused)},[]),[ut,hi]=T.useState(Date.now()),[rr,ks]=T.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(AE)!=="0"}catch{return!0}}),pi=T.useCallback(()=>{ks(W=>{const K=!W;try{window.localStorage.setItem(AE,K?"1":"0")}catch{}return K})},[]),[Qt,sr]=T.useState(!1),[wr,No]=T.useState("restart"),[ir,xr]=T.useState(null),mn=T.useRef(!1),Yr=T.useRef(null),mi=T.useRef(0),Kr=T.useCallback(async W=>{if(mn.current)return;const K=(W==null?void 0:W.upgrade)===!0;mn.current=!0,Yr.current=vt;const ae=++mi.current;No(K?"npx":"restart"),sr(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(ye==null?void 0:ye.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:K})})}catch{}window.setTimeout(()=>{if(mi.current===ae&&mn.current){mn.current=!1,sr(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},K?18e4:3e4)},[ye==null?void 0:ye.to,vt]),Es=T.useRef(null);T.useEffect(()=>{let W=!1;for(const ae of n.current.agents.values())if(ae.state==="active"){W=!0;break}const K=AL({enabled:rr,kind:ye==null?void 0:ye.kind,canRestart:(Y==null?void 0:Y.canRestart)===!0,busy:W,idleSince:Es.current,now:ut});Es.current=K.idleSince,K.restart&&Kr()},[rr,ye==null?void 0:ye.kind,Y==null?void 0:Y.canRestart,ut,Kr]),T.useEffect(()=>{const W=Y==null?void 0:Y.running;let K=null,ae=null;try{K=window.sessionStorage.getItem("agent-dag.restartPending"),ae=window.sessionStorage.getItem(IE)}catch{return}const de=RL({bundle:"1.34.4",running:W,pending:K,lastTried:ae});if(de==="reload"){try{window.sessionStorage.setItem(IE,W??"")}catch{return}window.location.reload();return}if(de!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}mn.current=!1,sr(!1),xr(W??null);const xe=window.setTimeout(()=>xr(null),6e3);return()=>window.clearTimeout(xe)},[Y==null?void 0:Y.running]),T.useEffect(()=>{if(Qt&&jL({asked:Yr.current,reported:vt})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}mn.current=!1,sr(!1)}},[Qt,vt]);const gn=T.useRef(f5()).current;T.useRef(!1);const Rt=T.useRef(new Map(gn.positions.filter(([W])=>gn.pins.includes(W)))),_r=T.useRef(null),Xr=T.useState(()=>h5())[0],[Zt,Qr]=T.useState(""),[Ns,gi]=T.useState(()=>new Set),[or,vi]=T.useState(ZL),[et,Co]=T.useState(!1),br=T.useRef(null);T.useEffect(()=>{document.documentElement.dataset.theme=or;try{window.localStorage.setItem(EC,or)}catch{}},[or]),T.useEffect(()=>{if(!Xr)return;const W=window.setTimeout(()=>{try{e.setViewport(Xr,{duration:0})}catch{}},60);return()=>window.clearTimeout(W)},[e,Xr]);const Cs=T.useRef(!0);T.useEffect(()=>{const W=new EventSource("/events"),K=VL(i,{now:()=>Date.now(),setTimeout:(ae,de)=>window.setTimeout(ae,de),clearTimeout:ae=>window.clearTimeout(ae)});return W.addEventListener("open",()=>{V(!0),Co(!0)}),W.addEventListener("error",()=>V(!1)),W.addEventListener("replay-end",()=>{Cs.current=!1,K.flush()}),W.addEventListener("hook",ae=>{try{const de=JSON.parse(ae.data);if(!Xt.current.accept(de))return;n.current=Mx(n.current,de),de.replay===!0||Cs.current||Date.now()-de.receivedAt>3e4?K.replay():K.live()}catch{}}),()=>{W.close(),K.cancel()}},[i]),T.useEffect(()=>{const W=setInterval(()=>{const K=Date.now();hi(K);let ae=aP(n.current,K,JD);uP(n.current,K,lP)&&(ae=!0),iP(n.current,K,e5,t5)&&(ae=!0),oP(n.current,K,n5,r5)&&(ae=!0),ae&&i()},250);return()=>clearInterval(W)},[i]);const ar=T.useRef(null),$n=T.useRef(0),yi=420,Ot=T.useCallback((W=500)=>{try{const Ee=document.querySelector(".canvas-wrap"),Pe=Array.from(document.querySelectorAll(".react-flow__node")).filter(xt=>xt.offsetWidth>0);if(!Ee||Pe.length===0)return;const De=Ee.getBoundingClientRect(),Ye=e.getViewport();if(!Number.isFinite(Ye.zoom)||Ye.zoom<=0)return;const Ue=xt=>(xt-De.left-Ye.x)/Ye.zoom,Fe=xt=>(xt-De.top-Ye.y)/Ye.zoom,Nn=Pe.map(xt=>xt.getBoundingClientRect()),Fs=Math.min(...Nn.map(xt=>Ue(xt.left))),Ii=Math.max(...Nn.map(xt=>Ue(xt.right))),zs=Math.min(...Nn.map(xt=>Fe(xt.top))),$o=Math.max(...Nn.map(xt=>Fe(xt.bottom))),Ga=Ii-Fs,Mi=$o-zs;if(!(Ga>0&&Mi>0))return;const Un=Math.max(.2,Math.min(1,(De.width-160)/(Ga+yi)*.86,(De.height-160)/Mi*.86));e.setViewport({x:80-Fs*Un,y:Math.max(80,(De.height-Mi*Un)/2)-zs*Un,zoom:Un},{duration:W}),$n.current=Date.now(),window.setTimeout(()=>{try{const xt={x:80-Fs*Un,y:Math.max(80,(De.height-Mi*Un)/2)-zs*Un,zoom:Un},Ya=e.getViewport();(Math.abs(Ya.zoom-Un)>.01||Math.abs(Ya.x-xt.x)>2)&&e.setViewport(xt,{duration:0})}catch{}},W+60)}catch{}},[e]),zt=T.useRef(""),Sr=T.useRef(null),nn=T.useRef(0),wi=T.useCallback(()=>{nn.current=Date.now()},[]),Ro="agent-dag.autoFitDisabled",kr=T.useRef((()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Ro)==="1"}catch{return!1}})()),[Rs,Ts]=T.useState(kr.current),Zr=T.useCallback(()=>{if(!kr.current){kr.current=!0,Ts(!0);try{window.localStorage.setItem(Ro,"1")}catch{}}},[]),xi=T.useCallback(()=>{kr.current=!1,Ts(!1);try{window.localStorage.removeItem(Ro)}catch{}Ot(400)},[e,Ot]);T.useEffect(()=>{const W=setInterval(()=>{if(kr.current||Date.now()-nn.current<800)return;const K=n.current,ae=Date.now(),de=[];for(const Ue of K.agents.values())Cv(Ue,ae)&&de.push({id:Ue.id});if(de.length===0)return;const xe=e.getViewport(),Ee=window.innerWidth-360,Pe=window.innerHeight-52;let De=!1,Ye=!1;for(const{id:Ue}of de){const Fe=Jr.current.get(Ue),Nn=Rt.current.get(Ue)??Bt.current.get(Ue);if(!Fe||!Nn)continue;Ye=!0;const Fs=Nn.x*xe.zoom+xe.x,Ii=Nn.y*xe.zoom+xe.y,zs=(Nn.x+Fe.width)*xe.zoom+xe.x,$o=(Nn.y+Fe.height)*xe.zoom+xe.y;if(zs>0&&Fs<Ee&&$o>0&&Ii<Pe){De=!0;break}}Ye&&!De&&Ot(600)},1500);return()=>clearInterval(W)},[e]);const To=T.useRef(!1),Jr=T.useRef(new Map),_i=T.useRef(0),Ua=T.useCallback(W=>{const K=Jr.current;let ae=!1;for(const de of W.nodeInternals.values()){const xe=de.width,Ee=de.height;if(xe==null||Ee==null)continue;const Pe=K.get(de.id);Pe?(Math.abs(Pe.height-Ee)>4||Math.abs(Pe.width-xe)>4)&&(K.set(de.id,{width:xe,height:Ee}),ae=!0):(K.set(de.id,{width:xe,height:Ee}),ae=!0)}return ae&&(_i.current+=1),_i.current},[]),bi=Qe(Ua),[es,Qu]=T.useState(0);T.useEffect(()=>{let W=0;const K=()=>{const de=Jr.current;let xe=!1;for(const Ee of document.querySelectorAll(".react-flow__node[data-id]")){const Pe=Ee.getAttribute("data-id");if(!Pe)continue;const De=Ee.offsetWidth,Ye=Ee.offsetHeight;if(!De||!Ye)continue;const Ue=de.get(Pe);(!Ue||Math.abs(Ue.width-De)>4||Math.abs(Ue.height-Ye)>4)&&(de.set(Pe,{width:De,height:Ye}),xe=!0)}xe&&Qu(Ee=>Ee+1)};if(To.current)return;let ae=0;return document.visibilityState==="hidden"?ae=window.setTimeout(K,32):W=requestAnimationFrame(K),()=>{cancelAnimationFrame(W),window.clearTimeout(ae)}});const Bt=T.useRef(new Map(gn.positions)),Ge=T.useRef(new Set),Si=T.useRef(""),Er=T.useMemo(()=>{const W=[];for(const K of n.current.agents.values())Cv(K,ut)&&W.push(K.id+(K.parentId?`>${K.parentId}`:""));return W.sort(),`${W.join("|")}#sv${bi}.${es}`},[n.current,n.current.lastSeq,ut,bi,es]),Nr=T.useRef(null);T.useEffect(()=>(Nr.current!=null&&window.clearTimeout(Nr.current),Nr.current=window.setTimeout(()=>{iv(Bt.current,Rt.current)},1500),()=>{Nr.current!=null&&window.clearTimeout(Nr.current)}),[Er]),T.useEffect(()=>{if(zt.current===Er)return;const W=zt.current;if(zt.current=Er,!W||kr.current)return;Date.now()-$n.current>1200&&Ot(400),ar.current&&window.clearTimeout(ar.current),ar.current=window.setTimeout(()=>{kr.current||Ot(500)},280)},[Er,e,Ot]);const ki=T.useMemo(()=>{if(o.size===0)return null;const W=new Set;for(const K of o){const ae=v5(n.current,K);if(ae)for(const de of ae)W.add(de)}return W.size>0?W:null},[n.current,n.current.lastSeq,o]),lr=T.useMemo(()=>qD(n.current,ut),[n.current,n.current.lastSeq,ut]),jo=T.useRef(null),[ts,js]=T.useState({w:0,h:0});T.useEffect(()=>{const W=jo.current;if(!W||typeof ResizeObserver>"u")return;const K=new ResizeObserver(ae=>{var xe;const de=(xe=ae[0])==null?void 0:xe.contentRect;de&&js(Ee=>Math.abs(Ee.w-de.width)>40||Math.abs(Ee.h-de.height)>40?{w:de.width,h:de.height}:Ee)});return K.observe(W),js({w:W.clientWidth,h:W.clientHeight}),()=>K.disconnect()},[]);const ur=T.useRef(new Map),[Dn,cr]=T.useState(!1);T.useEffect(()=>{const W=window.setTimeout(()=>cr(!0),2500);return()=>window.clearTimeout(W)},[]);const[As,Cr]=T.useState(!1),Pt=T.useRef(null),[Ao,Io]=T.useState(!1),Is=T.useCallback(()=>{Pt.current&&(window.clearTimeout(Pt.current),Pt.current=null),Cr(!1)},[]),Zu=T.useCallback(W=>{W.length!==0&&queueMicrotask(()=>{Cr(!0),Pt.current&&window.clearTimeout(Pt.current),Pt.current=window.setTimeout(()=>Cr(!1),ZD+80)})},[]);T.useEffect(()=>()=>{Pt.current&&window.clearTimeout(Pt.current)},[]);const Mo=ts.w>0?ts.w*.92:0,Ms=ts.h>0?ts.h:0,{nodes:Fn,edges:Ju}=T.useMemo(()=>y5(n.current,ut,Mo,Ms,Rt.current,Zt,Jr.current,ur.current,Zu,Dn,Ao,Bt.current,Ge.current,Er,Si,o,ki,lr,b),[n.current,n.current.lastSeq,ut,Mo,Ms,Dn,Ao,Zt,Er,o,ki,lr,b,pt]),ns=T.useMemo(()=>{const W=new Map;for(const ae of Fn){const de=ae.data;if(!(de!=null&&de.sessionId)||de.exitAt!=null)continue;const xe=ae.width,Ee=ae.height;if(xe==null||Ee==null)continue;const Pe=ae.position.x,De=ae.position.y,Ye=Pe+xe,Ue=De+Ee,Fe=W.get(de.sessionId);Fe?(Fe.minX=Math.min(Fe.minX,Pe),Fe.minY=Math.min(Fe.minY,De),Fe.maxX=Math.max(Fe.maxX,Ye),Fe.maxY=Math.max(Fe.maxY,Ue)):W.set(de.sessionId,{minX:Pe,minY:De,maxX:Ye,maxY:Ue})}const K=[];for(const[ae,de]of W){const xe=de.maxX-de.minX+iu*2,Ee=de.maxY-de.minY+iu*2;K.push({id:`group:${ae}`,type:NR,position:{x:de.minX-iu,y:de.minY-iu},data:{sessionId:ae,w:xe,h:Ee},width:xe,height:Ee,style:{width:xe,height:Ee},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return K},[Fn,ut]),Os=T.useMemo(()=>{const W=[...ns,...Fn],K=Kt.current;return!K||K.size===0?W:W.map(ae=>{const de=K.get(ae.id);return de?{...ae,position:de}:ae})},[ns,Fn,yr]),kn=T.useMemo(()=>{if(!Zt)return null;const W=new Set;for(const K of n.current.agents.values())lr.has(K.id)&&PR(K,Zt)&&W.add(K.id);return W},[n.current,n.current.lastSeq,Zt,lr]),En=T.useMemo(()=>GD(Zt,(kn==null?void 0:kn.size)??0,lr.size),[Zt,kn,lr]),Ei=T.useMemo(()=>{const W=new Set;for(const K of n.current.agents.values())for(const ae of K.tools)W.add(OR(ae.name));return Object.keys(Tv).filter(K=>W.has(K))},[n.current,n.current.lastSeq]);T.useEffect(()=>{if(Ei.length<=1){Mt(!1);return}let W=0;const K=()=>{const ae=_n.current;if(ae&&!document.hidden){const de=ae.getBoundingClientRect(),xe=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Pe=>Pe.getBoundingClientRect()),Ee=DD(de,xe,8);Mt(Pe=>Pe===Ee?Pe:Ee)}W=window.setTimeout(K,300)};return K(),()=>window.clearTimeout(W)},[Ei.length]);const Ps=T.useMemo(()=>{const W=new Map;for(const ae of n.current.agents.values())for(const de of ae.tools){if(!de.name.startsWith("mcp__"))continue;const xe=de.name.slice(5),Ee=xe.indexOf("__"),Pe=Ee>0?xe.slice(0,Ee):xe;W.set(Pe,(W.get(Pe)??0)+1)}const K=[];for(const[ae,de]of W){let xe=5381;for(let Ee=0;Ee<ae.length;Ee++)xe=(xe<<5)+xe^ae.charCodeAt(Ee);K.push({server:ae,count:de,hue:Math.abs(xe)%360})}return K.sort((ae,de)=>de.count-ae.count),K},[n.current,n.current.lastSeq]),Oo=T.useCallback(W=>{gi(K=>{const ae=new Set(K);return ae.has(W)?ae.delete(W):ae.add(W),ae})},[]),St=u?n.current.agents.get(u):null,Ls=h?Array.from(n.current.agents.values()).flatMap(W=>W.tools).find(W=>W.id===h)??null:null,Po=T.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}n.current=bv(),Rt.current.clear(),Jr.current.clear(),Bt.current.clear(),Si.current="",OE(),m(),i()},[i,m]),zn=T.useRef(S);zn.current=S;const Ni=T.useRef(!1);Ni.current=Ls!=null||Ze||N!=null||y!=null;const Rr=T.useCallback(W=>{const K=ML(W,{confirmOpen:zn.current,modalOpen:Ni.current});K==="confirm"?k(!0):K==="clear"&&(k(!1),Po())},[Po]),Ci=T.useCallback(()=>{Rt.current.clear(),Bt.current.clear(),Si.current="",OE(),i(),window.setTimeout(()=>Ot(500),80)},[i,e,Ot]),qs=T.useCallback(()=>Ot(500),[Ot]),Tr=T.useRef(Fn);Tr.current=Fn;const Lo=T.useRef(u);Lo.current=u;const Lt=T.useCallback(W=>{const K=Tr.current,ae=PL(K.map(Ee=>({id:Ee.id,x:Ee.position.x,y:Ee.position.y})),Lo.current,W),de=ae?K.find(Ee=>Ee.id===ae):void 0;if(!de)return;const xe=NE(document.activeElement);d(de.id,!1),window.setTimeout(()=>{try{e.fitView({padding:.35,duration:350,nodes:[de]})}catch{}$n.current=Date.now(),xe&&QD(de.id)},30)},[d,e]),jr=T.useCallback(W=>{d(W,!1),window.setTimeout(()=>{try{const K=Tr.current.find(ae=>ae.id===W);K&&e.fitView({padding:.3,duration:500,nodes:[K]}),$n.current=Date.now()}catch{}},60)},[d,e]);T.useEffect(()=>{const W=K=>{var De,Ye,Ue;const ae=K.target,de={tagName:ae==null?void 0:ae.tagName,isContentEditable:ae==null?void 0:ae.isContentEditable,role:(De=ae==null?void 0:ae.getAttribute)==null?void 0:De.call(ae,"role"),type:ae==null?void 0:ae.type};if(K.key==="Escape"){const Fe=EP({overlayOpen:bu.depth()>0,typing:Qv(de)});Fe==="dismiss"?bu.dismissTop():Fe==="blur"?ae==null||ae.blur():(DL(de)&&(ae==null||ae.blur()),m());return}if(hC(K))return;const xe=NE(ae)?(Ye=ae==null?void 0:ae.getAttribute)==null?void 0:Ye.call(ae,"data-id"):null,Ee=xe&&Tr.current.some(Fe=>Fe.id===xe)?xe:null,Pe=qL(K,Ee);if(Pe.kind==="activate"){K.preventDefault(),d(Pe.nodeId,Pe.additive);return}if(Pe.kind!=="node"&&!(Pe.nodeId==null&&MP(de))){if(K.key==="/"){K.preventDefault(),(Ue=br.current)==null||Ue.focus();return}K.key===" "&&(K.preventDefault(),Gr()),(K.key==="c"||K.key==="C")&&Rr("shortcut"),(K.key==="r"||K.key==="R")&&Ci(),(K.key==="f"||K.key==="F")&&qs(),(K.key==="l"||K.key==="L")&&Gt(),(K.key==="h"||K.key==="H")&&wt(Fe=>!Fe),(K.key==="u"||K.key==="U")&&L(Fe=>!Fe),(K.key==="a"||K.key==="A")&&It(),(K.key==="j"||K.key==="J")&&Lt(1),(K.key==="k"||K.key==="K")&&Lt(-1),(K.key==="t"||K.key==="T")&&vi(Fe=>Fe==="dark"?"light":"dark")}};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[Rr,Ci,qs,m,d,Lt,Gr]);const Ar=n.current.agents.size,$s=new Set(Array.from(n.current.agents.values()).map(W=>W.sessionId)).size,Bn=T.useMemo(()=>P3(n.current.agents.values()),[n.current,n.current.lastSeq]),Ri=T.useMemo(()=>L3(n.current.agents.values()),[n.current,n.current.lastSeq]),Ti=T.useRef(null);T.useEffect(()=>{const W=JL({waiting:Bn.length,running:Ri}),K=Ti.current;if(Ti.current=W,(K==null?void 0:K.title)!==W.title&&(document.title=W.title),(K==null?void 0:K.icon)!==W.icon){const ae=document.querySelector('link[rel="icon"]');ae&&(ae.href=eq[W.icon])}},[Bn.length,Ri]);const[Ds,ji]=T.useState(""),qo=nq(Bn);T.useEffect(()=>{ji(W=>rq(W,qo))},[qo]);const rn=T.useMemo(()=>{let W=0,K=0,ae=0,de=0,xe=0,Ee=0,Pe=0,De=0,Ye=0;for(const Ue of n.current.agents.values()){W+=Ue.usage.inputTokens,K+=Ue.usage.outputTokens,ae+=Ue.usage.cacheReadTokens,de+=Ue.usage.cacheCreateTokens;const Fe=fn(Ue.usage,Ue.model);xe+=Fe.total,Ee+=Fe.input,Pe+=Fe.output,De+=Fe.cacheRead,Ye+=Fe.cacheWrite}return{inT:W,outT:K,cacheR:ae,cacheC:de,sum:W+K,cost:{total:xe,input:Ee,output:Pe,cacheRead:De,cacheWrite:Ye}}},[n.current,n.current.lastSeq]);return g.jsxs("div",{className:"app",children:[g.jsxs("header",{className:"topbar",children:[g.jsxs("div",{className:"brand",children:[g.jsx("span",{className:"logo"}),tn,ye?g.jsxs("button",{type:"button",className:"v stale",onClick:Be,title:ye.kind==="restart"?`Running v${ye.from}; v${ye.to} is installed on disk. Restart to pick it up.`:`Running v${ye.from}; v${ye.to} is on npm.`,children:["v",ye.from,g.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const W={running:(Y==null?void 0:Y.running)??"1.34.4",latest:Y==null?void 0:Y.latest,latestPending:Y==null?void 0:Y.latestPending,checkedAgo:Y!=null&&Y.checkedAt?Rv(ut-Y.checkedAt):null,checkDisabled:Y==null?void 0:Y.checkDisabled,checking:ce};return g.jsxs("button",{type:"button",className:ce?"v checking":"v",onClick:()=>ve(!0),"aria-busy":ce||void 0,"aria-label":UD(W),title:BD(W),children:["v",W.running]})})()]}),St&&(()=>{const W=fn(St.usage,St.model),K=Math.max(0,((St.endedAt??ut)-St.startedAt)/1e3),ae=St.state==="active"?_u(W.total,K):null,de=o.size-1;return g.jsxs("button",{type:"button",className:"selected-ribbon",title:`Fit view to ${St.label}`,onClick:()=>{try{const xe=Fn.find(Ee=>Ee.id===St.id);xe&&e.fitView({padding:.35,duration:500,nodes:[xe]}),$n.current=Date.now()}catch{}},children:[g.jsx("span",{className:`state-pill state-${St.state}`,children:St.state==="active"?"live":St.state}),g.jsx("span",{className:"selected-label",children:St.label}),W.total>0&&g.jsxs("span",{className:"selected-cost",children:[ze(W.total),ae?g.jsxs("span",{className:"selected-rate",children:[" · ",ae]}):null]}),de>0&&g.jsxs("span",{className:"selected-extra",children:["+",de]}),g.jsx("span",{"aria-hidden":!0,className:"selected-close",onClick:xe=>{xe.stopPropagation(),m()},children:"×"})]})})(),g.jsxs("div",{className:"actions",children:[g.jsxs("div",{className:"search",children:[g.jsx("span",{className:"search-icon","aria-hidden":!0,children:"⌕"}),g.jsx("input",{ref:br,type:"text",placeholder:"Search agents, cwd, tools…",value:Zt,onChange:W=>Qr(W.target.value),spellCheck:!1,"aria-label":"Filter the graph"}),Zt?g.jsx("button",{className:"search-clear","aria-label":"Clear search",onClick:()=>Qr(""),children:"×"}):g.jsx("kbd",{className:"search-kbd","aria-hidden":!0,children:"/"}),En.count&&g.jsx("span",{className:`search-count${En.empty?" none":""}`,"aria-live":"polite",title:`${En.count} agents on the canvas match “${Zt}”`,children:En.count})]}),g.jsxs("span",{className:"status",children:[(()=>{const W=WD({connected:M,paused:pn,held:Xt.current.size});return g.jsx("span",{className:`pill ${W.tone}`,title:W.title,children:W.label})})(),g.jsxs("span",{className:"stat",title:"Distinct CC sessions",children:[g.jsx("span",{className:"count",children:$s}),g.jsx("span",{className:"lbl",children:"sessions"})]}),g.jsxs("span",{className:"stat",title:"Total agents (root + subagents)",children:[g.jsx("span",{className:"count",children:Ar}),g.jsx("span",{className:"lbl",children:"agents"})]}),g.jsxs("span",{className:"stat",title:"Total hook events received",children:[g.jsx("span",{className:"count",children:n.current.totalEvents}),g.jsx("span",{className:"lbl",children:"events"})]}),rn.sum>0&&g.jsxs("span",{className:"stat",title:`in:${rn.inT.toLocaleString()} out:${rn.outT.toLocaleString()} cache-r:${rn.cacheR.toLocaleString()} cache-c:${rn.cacheC.toLocaleString()}`,children:[g.jsx("span",{className:"count",children:Dt(rn.sum)}),g.jsx("span",{className:"lbl",children:"tokens"})]}),Ps.length>0&&g.jsxs("span",{className:"stat mcp-legend",title:`MCP servers seen this session:
|
|
61
|
+
Blocked since ${new Date(h.waiting.since).toLocaleTimeString()} · started ${new Date(h.startedAt).toLocaleString()}`,children:["waiting ",Vx(h.waiting.since,void 0,n)]}):g.jsx("span",{className:"sl-elapsed",title:`Started ${new Date(h.startedAt).toLocaleString()}`,children:Vx(h.startedAt,h.state==="active"?void 0:h.lastActivity,n)})]})]})]},h.sessionId)})]})]})}const tn="ccdeck";function Dt(e){return e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:e<1e9?`${(e/1e6).toFixed(2)}M`:`${(e/1e9).toFixed(2)}B`}function Gx(e,n){if(!e)return null;const r=n-Math.floor(e/1e3);return r<10?"just now":r<60?`${r}s ago`:r<3600?`${Math.floor(r/60)}m ago`:`${Math.floor(r/3600)}h ago`}function D3(e){return e==="claude-swap"?"Read from claude-swap's last collection — costs no request against your usage-endpoint budget":e==="api"?"Fetched from Anthropic's usage endpoint, at most once every 5 minutes":e==="cli"?"Parsed from `claude /usage`, at most once every 5 minutes":"Last update"}function F3({cost:e}){const n=e.total;if(n<=0)return null;const r=(i,o,l)=>{if(i<=0)return null;const u=i/n*100;return g.jsx("span",{className:`cb-seg ${o}`,style:{width:`${u}%`},title:`${l}: ${ze(i)} (${u.toFixed(0)}%)`},o)};return g.jsxs("div",{className:"cost-bar","aria-label":"Cost breakdown",children:[r(e.input,"cb-input","input"),r(e.output,"cb-output","output"),r(e.cacheRead,"cb-cache-r","cache read"),r(e.cacheWrite,"cb-cache-w","cache write")]})}function z3(e,n){const r=e-n;if(r<=0)return null;const i=Math.floor(r/3600),o=Math.floor(r%3600/60);if(i>23){const l=Math.floor(r/86400),u=Math.floor(r%86400/3600);return`${l}d ${u}h`}return i>0?`${i}h ${o}m`:`${o}m`}function B3(e,n,r,i){const o=Math.max(0,n-i),l=Math.max(0,r-o);if(l<120)return null;const u=Math.min(100,l/r*100),c=e-u;if(Math.abs(c)<3)return{label:"on pace",color:"var(--ok)",expectedPct:u,isDeficit:!1};if(c>0){const h=100-e,p=l>0?e/l:0,d=p>0?h/p:1/0,m={label:`${Math.round(c)}% ahead`,color:"var(--warn)",expectedPct:u,isDeficit:!0};if(d<o&&d<86400){const y=Math.floor(d/3600),w=Math.floor(d%3600/60);m.runsOutIn=y>0?`${y}h ${w}m`:`${w}m`}return m}return{label:`${Math.round(-c)}% reserve`,color:"var(--ok)",expectedPct:u,isDeficit:!1}}function ei({pct:e,label:n,reset:r,resetAt:i,windowSec:o,limitReached:l,nowSec:u}){const c=Math.min(100,Math.max(0,e)),p=l||c>=90?"var(--err)":c>=70?"var(--warn)":"var(--accent)",d=c===0?"< 1%":`${c}%`,m=c===0?2:c,y=i?z3(i,u):null,w=i&&o?B3(c,i,o,u):null;return g.jsxs("div",{className:"qb-row",children:[g.jsxs("div",{className:"qb-meta",children:[g.jsxs("span",{className:"qb-label",children:[n,l&&g.jsx("span",{className:"qb-limit-badge",title:"Rate limit reached",children:"⛔"})]}),g.jsx("span",{className:"qb-pct",style:{color:p},children:d})]}),g.jsxs("div",{className:"qb-track",children:[g.jsx("div",{className:"qb-fill",style:{width:`${m}%`,background:p,opacity:c===0?.4:1}}),w&&g.jsx("div",{className:"qb-pace-marker",style:{left:`${w.expectedPct}%`,background:w.isDeficit?"var(--err)":"var(--ok)"},title:`To last until reset, stay near ${Math.round(w.expectedPct)}% by now`})]}),g.jsxs("div",{className:"qb-reset-row",children:[y?g.jsxs("span",{className:"qb-reset",children:["resets in ",y]}):r?g.jsxs("span",{className:"qb-reset",children:["resets ",r]}):null,w&&g.jsx("span",{className:"qb-pace",style:{color:w.color},children:w.runsOutIn?`runs out in ${w.runsOutIn}`:w.label})]})]})}const U3=6e4;function H3(){const[e,n]=T.useState(null),[r,i]=T.useState(!1),o=T.useRef(null),l=async(c=!1)=>{c&&i(!0);try{const p=await fetch(c?"/api/quota?refresh=1":"/api/quota");p.ok&&n(await p.json())}catch{}finally{c&&i(!1)}};return T.useEffect(()=>(l(!0),o.current=window.setInterval(()=>l(!1),U3),()=>{o.current!=null&&window.clearInterval(o.current)}),[]),{quota:e,loading:r,refresh:()=>l(!0)}}function W3(e){switch(e){case"no_token":return"Run codex login to authenticate.";case"api_key_mode":return"API-key login — ChatGPT quota is only available for codex login.";case"refresh_rejected":return"Codex session expired — run codex login.";case"refresh_failed":return"Couldn't refresh the Codex token — click ↻ to retry.";case"untrusted_base_url":return"chatgpt_base_url in ~/.codex/config.toml is not an https OpenAI host, so the token was not sent.";default:return"ChatGPT API unreachable — click ↻ to retry."}}const xC=6e4;function V3(){const[e,n]=T.useState(null),[r,i]=T.useState(!1),o=T.useRef(null),l=async(c=!1)=>{c&&i(!0);try{const p=await fetch(c?"/api/codex-quota?refresh=1":"/api/codex-quota");p.ok&&n(await p.json())}catch{}finally{c&&i(!1)}};return T.useEffect(()=>(l(!0),o.current=window.setInterval(()=>l(!1),xC),()=>{o.current!=null&&window.clearInterval(o.current)}),[]),{data:e,loading:r,refresh:()=>l(!0)}}function G3(){const[e,n]=T.useState(null),r=T.useRef(null),i=async()=>{try{const o=await fetch("/api/codex-usage");o.ok&&n(await o.json())}catch{}};return T.useEffect(()=>(i(),r.current=window.setInterval(i,xC),()=>{r.current!=null&&window.clearInterval(r.current)}),[]),{data:e}}function Y3({state:e,now:n,onClose:r}){var A,U;const{quota:i,loading:o,refresh:l}=H3(),{data:u,loading:c,refresh:h}=V3(),{data:p}=G3(),[d,m]=T.useState(()=>Math.floor(Date.now()/1e3));T.useEffect(()=>{const L=window.setInterval(()=>m(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(L)},[]);const{byModel:y,totalCost:w,totalTokens:N,burnRate:_}=T.useMemo(()=>{const L=new Map,O={total:0,input:0,output:0,cacheRead:0,cacheWrite:0};let q=0,G=0,F=0,j=0;for(const $ of e.agents.values()){const Q=$.model??"__unknown__",M=fn($.usage,$.model),V=L.get(Q);V?(V.inputTokens+=$.usage.inputTokens,V.outputTokens+=$.usage.outputTokens,V.cacheReadTokens+=$.usage.cacheReadTokens,V.cacheCreateTokens+=$.usage.cacheCreateTokens,V.cost.total+=M.total,V.cost.input+=M.input,V.cost.output+=M.output,V.cost.cacheRead+=M.cacheRead,V.cost.cacheWrite+=M.cacheWrite,V.agentCount++):L.set(Q,{model:Q,inputTokens:$.usage.inputTokens,outputTokens:$.usage.outputTokens,cacheReadTokens:$.usage.cacheReadTokens,cacheCreateTokens:$.usage.cacheCreateTokens,cost:{...M},agentCount:1}),O.total+=M.total,O.input+=M.input,O.output+=M.output,O.cacheRead+=M.cacheRead,O.cacheWrite+=M.cacheWrite,q+=$.usage.inputTokens,G+=$.usage.outputTokens,F+=$.usage.cacheReadTokens,j+=$.usage.cacheCreateTokens}const B=Array.from(L.values()).sort(($,Q)=>Q.cost.total-$.cost.total);let z=0,ne=0;for(const $ of e.agents.values()){if($.state!=="active")continue;const Q=fn($.usage,$.model);z+=Q.total,ne=Math.max(ne,(($.endedAt??n)-$.startedAt)/1e3)}const Z=ne>0?_u(z,ne):null;return{byModel:B,totalCost:O,totalTokens:{in:q,out:G,cacheR:F,cacheC:j},burnRate:Z}},[e,e.lastSeq,n]),b=T.useMemo(()=>{const L=[];for(const O of e.agents.values()){if(O.kind!=="root")continue;let q=fn(O.usage,O.model).total,G=O.usage.inputTokens,F=O.usage.outputTokens;for(const j of e.agents.values())j.sessionId!==O.sessionId||j.kind==="root"||(q+=fn(j.usage,j.model).total,G+=j.usage.inputTokens,F+=j.usage.outputTokens);L.push({sessionId:O.sessionId,label:O.label||O.cwdBasename||"session",state:O.state,cost:q,inputTokens:G,outputTokens:F})}return L.sort((O,q)=>q.cost-O.cost).slice(0,12)},[e,e.lastSeq]),S=w.total>0,k=N.in+N.out,E=o||c,C=Gx(i==null?void 0:i.fetchedAt,d),I=Gx(u==null?void 0:u.fetchedAt,d),P=()=>{l(),h()};return g.jsxs("div",{className:"usage-panel",id:"usage-panel","aria-label":"Usage",children:[g.jsxs("div",{className:"up-header",children:[g.jsx("h3",{children:"Usage"}),_&&g.jsx("span",{className:"up-rate",children:_}),g.jsxs("div",{className:"up-header-right",children:[g.jsx("button",{type:"button",className:"btn up-refresh-btn",onClick:P,disabled:E,title:"Refresh Claude + Codex quota",children:E?"…":"↻"}),g.jsx("button",{type:"button",className:"btn icon-btn up-close",onClick:r,"aria-label":"Close usage panel",title:"Close (U)",children:"×"})]})]}),g.jsxs("section",{className:"up-section up-quota-section",children:[g.jsxs("h4",{className:"up-section-title",children:["Claude quota",C&&!o&&g.jsx("span",{className:"up-section-age",title:D3(i==null?void 0:i.source),children:C})]}),i!=null&&i.ok?g.jsxs("div",{className:"up-quota-bars",children:[i.session5hPct!=null&&g.jsx(ei,{label:"5-hour window",pct:i.session5hPct,reset:i.session5hReset,resetAt:i.session5hResetAt,windowSec:i.session5hWindowSec,nowSec:d}),i.week7dPct!=null&&g.jsx(ei,{label:"7-day window",pct:i.week7dPct,reset:i.week7dReset,resetAt:i.week7dResetAt,windowSec:i.week7dWindowSec,nowSec:d}),i.weekSonnetPct!=null&&g.jsx(ei,{label:"Sonnet (7d)",pct:i.weekSonnetPct,nowSec:d}),i.weekOpusPct!=null&&g.jsx(ei,{label:"Opus (7d)",pct:i.weekOpusPct,nowSec:d})]}):(i==null?void 0:i.ok)===!1?g.jsxs("div",{className:"up-quota-na",children:[g.jsx("span",{children:"Quota unavailable."}),g.jsxs("span",{className:"up-quota-hint",children:["Run ",g.jsx("code",{children:"/usage"})," in a claude session, then click ↻"]})]}):g.jsx("div",{className:"up-quota-na up-quota-loading",children:"Checking…"})]}),g.jsxs("section",{className:"up-section up-quota-section",children:[g.jsxs("h4",{className:"up-section-title",children:["Codex quota",(u==null?void 0:u.ok)&&u.planLabel&&g.jsx("span",{className:"up-plan-badge",children:u.planLabel}),I&&!c&&g.jsx("span",{className:"up-section-age",title:"Fetched from the Codex usage endpoint",children:I})]}),u!=null&&u.ok?g.jsxs("div",{className:"up-quota-bars",children:[(A=u.windows)==null?void 0:A.map(L=>g.jsx(ei,{label:L.label,pct:L.pct,reset:L.reset??void 0,resetAt:L.resetAt??void 0,windowSec:L.windowSec??void 0,limitReached:u.limitReached&&L.pct>=100,nowSec:d},L.id)),(U=u.extraWindows)==null?void 0:U.map(L=>g.jsx(ei,{label:L.label,pct:L.pct,reset:L.reset??void 0,resetAt:L.resetAt??void 0,windowSec:L.windowSec??void 0,nowSec:d},L.id)),u.creditLimit&&g.jsx(ei,{label:`spend cap · $${Math.round(u.creditLimit.used)} of $${Math.round(u.creditLimit.limit)}`,pct:u.creditLimit.usedPct,reset:u.creditLimit.reset??void 0,resetAt:u.creditLimit.resetAt??void 0,limitReached:u.spendControlReached,nowSec:d}),(p==null?void 0:p.ok)&&p.window7d&&p.window7d.sessionCount>0&&g.jsxs("div",{className:"up-quota-sub",children:[Dt(p.window7d.totalTokens)," tokens · ",p.window7d.sessionCount," session",p.window7d.sessionCount!==1?"s":""," (7d)"]}),u.creditsBalance&&!u.creditsUnlimited&&g.jsxs("div",{className:"up-quota-sub up-credits",children:["credits: $",u.creditsBalance,u.overageReached&&" · overage limit reached"]}),u.creditsUnlimited&&g.jsx("div",{className:"up-quota-sub up-credits",children:"credits: unlimited"}),u.resetCredits&&u.resetCredits.availableCount>0&&g.jsxs("div",{className:"up-quota-sub up-reset-credits",title:`Redeem in the Codex CLI or ChatGPT — ${tn} only reports them`,children:[u.resetCredits.availableCount," rate-limit reset",u.resetCredits.availableCount!==1?"s":""," available",u.resetCredits.nextExpiryAt&&` · expires ${new Date(u.resetCredits.nextExpiryAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`]}),u.promo&&g.jsx("div",{className:"up-quota-sub",children:u.promo}),u.partial&&g.jsx("div",{className:"up-quota-sub up-quota-hint",children:"Partial data — OpenAI returned limits this build doesn't recognise."})]}):(u==null?void 0:u.ok)===!1?g.jsxs("div",{className:"up-quota-na",children:[g.jsx("span",{children:"Quota unavailable."}),g.jsx("span",{className:"up-quota-hint",children:W3(u.reason)})]}):g.jsx("div",{className:"up-quota-na up-quota-loading",children:"Checking…"})]}),S?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"up-total",children:[g.jsx("span",{className:"up-total-value",children:ze(w.total)}),g.jsx("span",{className:"up-total-label",children:"total spend"})]}),g.jsx(F3,{cost:w}),k>0&&g.jsxs("div",{className:"up-tokens-row",children:[g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"in"}),Dt(N.in)]}),g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"out"}),Dt(N.out)]}),N.cacheR>0&&g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"cache r"}),Dt(N.cacheR)]}),N.cacheC>0&&g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"cache c"}),Dt(N.cacheC)]})]}),y.filter(L=>L.cost.total>0).length>0&&g.jsxs("section",{className:"up-section",children:[g.jsx("h4",{className:"up-section-title",children:"By model"}),g.jsxs("table",{className:"up-table",children:[g.jsx("thead",{children:g.jsxs("tr",{children:[g.jsx("th",{children:"Model"}),g.jsx("th",{children:"Tokens"}),g.jsx("th",{children:"Cost"})]})}),g.jsx("tbody",{children:y.filter(L=>L.cost.total>0).map(L=>g.jsxs("tr",{children:[g.jsx("td",{className:"up-model-name",title:L.model,children:li(L.model)}),g.jsx("td",{className:"up-num",children:Dt(L.inputTokens+L.outputTokens)}),g.jsx("td",{className:"up-num up-cost-val",children:ze(L.cost.total)})]},L.model))})]})]}),b.filter(L=>L.cost>0).length>0&&g.jsxs("section",{className:"up-section",children:[g.jsx("h4",{className:"up-section-title",children:"By session"}),g.jsx("div",{className:"up-sessions",children:b.filter(L=>L.cost>0).map(L=>g.jsxs("div",{className:"up-session-row",children:[g.jsx("span",{className:`sl-dot state-${L.state}`,"aria-hidden":!0}),g.jsx("span",{className:"vis-hidden",children:Zv(L.state)}),g.jsx("span",{className:"up-session-label",children:L.label}),g.jsx("span",{className:"up-session-tokens",children:Dt(L.inputTokens+L.outputTokens)}),g.jsx("span",{className:"up-session-cost",children:ze(L.cost)})]},L.sessionId))})]})]}):k>0?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"up-tokens-row",children:[g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"in"}),Dt(N.in)]}),g.jsxs("span",{className:"up-tok",children:[g.jsx("span",{className:"up-k",children:"out"}),Dt(N.out)]})]}),g.jsx("div",{className:"up-hint",children:"Cost appears once a known model is detected."})]}):g.jsxs("div",{className:"up-empty",children:["No usage data yet.",g.jsx("br",{}),"Start a Claude Code or Codex session."]})]})}const Yx=18,K3=1100,io=(e,n)=>{const r=Math.sin(e*12.9898+n*78.233)*43758.5453;return r-Math.floor(r)},X3=Array.from({length:Yx},(e,n)=>{const r=-72+144*n/(Yx-1)+(io(n,1)-.5)*9,i=(r-90)*(Math.PI/180),o=(54+32*Math.cos(r*Math.PI/180))*(.74+io(n,2)*.52);return{dx:Math.cos(i)*o,dy:Math.sin(i)*o,rot:(n%2?1:-1)*(100+io(n,3)*260),delay:Math.round(io(n,4)*90),dur:760+Math.round(io(n,5)*260),scale:.8+io(n,6)*.45,hue:n%4,round:n%3===0}});function Kx({anchor:e,lifetimeMs:n=K3}){var l;const[r,i]=T.useState(null),o=typeof window<"u"&&((l=window.matchMedia)==null?void 0:l.call(window,"(prefers-reduced-motion: reduce)").matches);return T.useEffect(()=>{if(o)return;const u=e.current;if(!u)return;const c=u.getBoundingClientRect();i({x:c.left+c.width/2,y:c.top+c.height/2});const h=window.setTimeout(()=>i(null),n);return()=>window.clearTimeout(h)},[e,n,o]),o||!r?null:qI.createPortal(g.jsx("div",{className:"confetti",style:{left:`${r.x}px`,top:`${r.y}px`},"aria-hidden":!0,children:X3.map((u,c)=>g.jsx("span",{className:`confetti-bit${u.round?" round":""}`,"data-hue":u.hue,style:{"--dx":`${u.dx.toFixed(1)}px`,"--dy":`${u.dy.toFixed(1)}px`,"--rot":`${u.rot}deg`,"--s":u.scale.toFixed(2),animationDelay:`${u.delay}ms`,animationDuration:`${u.dur}ms, ${u.dur}ms`}},c))}),document.body)}const _C=new Set(["awaiting_url","awaiting_code","registering"]);function Q3(e){return e!=null&&_C.has(e)}function bC(e){return e!=null&&e!=="done"&&!_C.has(e)}const Z3="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",J3="the sign-in did not complete";function eL({state:e,serverError:n,localError:r}){const i=e==="idle";return{title:i?"Sign-in ended":"Sign-in failed",message:r||n||(i?Z3:J3)}}const tL="done";function nL(){let e=!1;return{shouldAnnounce(n){return n!==tL?(e=!1,!1):e?!1:(e=!0,!0)}}}const Xx={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 ccdeck1:",corrupt:"that share is incomplete — copy the whole thing",wrong_version:`that share was made by a newer ${tn}`,expired:"that share has expired — make a new one",import_failed:"claude-swap refused the import",bad_value:"an alias can only use letters, numbers, spaces, dots, dashes and underscores, up to 64 characters"},Qx={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"},rL=`claude-swap could not read the login keychain — start ${tn} from a Terminal window rather than a background service`;function Ev(e,n){return(e==null?void 0:e.reason)!=="no_cswap"&&/keychain/i.test(yo(e))?rL:e!=null&&e.reason&&Qx[e.reason]?Qx[e.reason]:(e==null?void 0:e.reason)||n}function yo(e){return((e==null?void 0:e.output)||(e==null?void 0:e.detail)||(e==null?void 0:e.error)||"").trim()}const Zx={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",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"},sL="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 iL(e){return/\bnpx\b/i.test(e)&&/(command not found|not found|not recognized|ENOENT)/i.test(e)}function oL(e,n){return iL(yo(e))?sL:e!=null&&e.reason&&Zx[e.reason]?Zx[e.reason]:(e==null?void 0:e.reason)||n}function cu(e,n){return e!=null&&e.detail?e.detail:e!=null&&e.error&&bC(e.state)?e.error:e!=null&&e.reason&&Xx[e.reason]?Xx[e.reason]:e!=null&&e.error?e.error:(e==null?void 0:e.reason)||n}const aL=1500;async function eu(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const Nv=ue.forwardRef((e,n)=>g.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:n,children:[g.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),g.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));Nv.displayName="SuccessMark";function lL({onClose:e,onChanged:n}){const[r,i]=T.useState("login"),[o,l]=T.useState(null),[u,c]=T.useState(""),[h,p]=T.useState(""),[d,m]=T.useState(!1),[y,w]=T.useState(null),[N,_]=T.useState(null),b=T.useRef(!1),S=T.useRef(null),k=T.useRef(null),E=T.useRef(null),C=T.useRef(null),I=T.useCallback(()=>{b.current&&eu({action:"login-cancel"}).catch(()=>{}),e()},[e]),P=xo(I,{focusRef:E}),A=T.useCallback(async()=>{m(!0),w(null),b.current=!0;const B=await eu({action:"login"}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){w(cu(B,"could not start the sign-in"));return}l(B)},[]);T.useEffect(()=>{if(!Q3(o==null?void 0:o.state))return;const B=window.setInterval(async()=>{try{const z=await fetch("/api/claude-accounts/login");z.ok&&l(await z.json())}catch{}},aL);return()=>window.clearInterval(B)},[o]);const U=T.useRef(n);U.current=n;const L=T.useRef(nL());T.useEffect(()=>{var B;(o==null?void 0:o.state)==="awaiting_code"&&((B=S.current)==null||B.focus()),L.current.shouldAnnounce(o==null?void 0:o.state)&&U.current()},[o==null?void 0:o.state]),T.useEffect(()=>{var B;r==="paste"&&((B=k.current)==null||B.focus())},[r]);const O=T.useCallback(async()=>{var z;m(!0),w(null);const B=await eu({action:"login-code",code:u}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){w(cu(B,"the code was not accepted")),B!=null&&B.state&&l(B),(z=S.current)==null||z.select();return}c(""),l(B)},[u,o]),q=T.useCallback(async()=>{m(!0),w(null);const B=await eu({action:"import",blob:h}).catch(()=>null);if(m(!1),!(B!=null&&B.ok)){w(cu(B,"the import failed"));return}p(""),_({added:B.added===!0,num:B.num??null,email:B.email??null}),n()},[h,n]),G=(o==null?void 0:o.state)==="done"?o.account:null,F=bC(o==null?void 0:o.state)||!!(y&&b.current&&!d),j=eL({state:o==null?void 0:o.state,serverError:o==null?void 0:o.error,localError:y});return g.jsx("div",{className:"modal-backdrop",onClick:I,role:"presentation",children:g.jsxs("div",{ref:P,className:"modal aa-modal",onClick:B=>B.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[g.jsxs("header",{className:"modal-head",children:[g.jsx("div",{className:"modal-title",children:g.jsxs("span",{className:"aa-tabs",role:"tablist",children:[g.jsx("button",{type:"button",role:"tab","aria-selected":r==="login",className:`aa-tab${r==="login"?" on":""}`,onClick:()=>i("login"),children:"Sign in"}),g.jsx("button",{type:"button",role:"tab","aria-selected":r==="paste",className:`aa-tab${r==="paste"?" on":""}`,onClick:()=>i("paste"),children:"Paste a share"})]})}),g.jsx("div",{className:"modal-actions",children:g.jsx("button",{type:"button",className:"btn icon-btn",onClick:I,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),g.jsx("section",{className:"modal-body aa-body",children:r==="login"?G?g.jsxs("div",{className:"aa-done",children:[g.jsx(Nv,{ref:C}),g.jsx(Kx,{anchor:C}),g.jsx("h4",{children:G.added?`Account ${G.num} added`:"Credentials refreshed"}),g.jsxs("p",{className:"aa-note",children:[g.jsx("strong",{children:G.email}),G.added?" is in the rotation. The account you were using is still active.":" was already managed, so its stored credentials were replaced."]}),g.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"})]}):(o==null?void 0:o.state)==="awaiting_code"||(o==null?void 0:o.state)==="registering"?g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"1 · Approve in the browser"}),g.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),g.jsx("a",{className:"aa-link",href:o.url??"#",target:"_blank",rel:"noreferrer noopener",children:o.url})]}),g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"2 · Paste the code it gives you"}),g.jsxs("div",{className:"aa-field",children:[g.jsx("input",{ref:S,type:"text",value:u,onChange:B=>c(B.target.value),onKeyDown:B=>{B.key==="Enter"&&u.trim()&&!d&&O()},placeholder:"paste the code here",spellCheck:!1,autoComplete:"off","aria-label":"Sign-in code",disabled:o.state==="registering"}),g.jsx("button",{type:"button",className:"btn primary",disabled:d||!u.trim()||o.state==="registering",onClick:O,children:o.state==="registering"?"registering…":"Continue"})]}),(y||o.error)&&g.jsx("p",{className:"aa-err",children:y??o.error}),g.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."})]})]}):F?g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:j.title}),g.jsx("p",{className:"aa-err",children:j.message}),g.jsx("button",{type:"button",className:"btn",onClick:()=>{b.current=!1,l(null),w(null),A()},children:"Try again"})]}):d||b.current?g.jsx("div",{className:"aa-step",children:g.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):g.jsxs("div",{className:"aa-step aa-primer",children:[g.jsx("h4",{children:"Sign in to Anthropic"}),g.jsx("p",{className:"aa-note",children:"Opens a browser tab where you approve the sign-in, then asks for the code it shows you. claude-swap records the account when it completes, and the account you are using now stays active."}),g.jsx("div",{className:"aa-actions",children:g.jsx("button",{type:"button",ref:E,className:"btn primary",onClick:A,disabled:d,children:"Open the sign-in page"})})]}):N?g.jsxs("div",{className:"aa-done",children:[g.jsx(Nv,{ref:C}),N.added&&g.jsx(Kx,{anchor:C}),g.jsx("h4",{children:N.added?`Account ${N.num} imported`:"Already here"}),g.jsx("p",{className:"aa-note",children:N.added?g.jsxs(g.Fragment,{children:[N.email?g.jsx("strong",{children:N.email}):"That account"," is in the rotation now. Nothing changed on the deck you copied it from."]}):"This deck already holds that account, so nothing changed."}),g.jsxs("div",{className:"aa-actions",children:[g.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"}),g.jsx("button",{type:"button",className:"btn",onClick:()=>_(null),children:"Import another"})]})]}):g.jsxs("div",{className:"aa-step",children:[g.jsx("h4",{children:"Paste an account shared from another deck"}),g.jsxs("div",{className:"aa-field",children:[g.jsx("input",{ref:k,type:"text",value:h,onChange:B=>p(B.target.value),onKeyDown:B=>{B.key==="Enter"&&h.trim()&&!d&&q()},placeholder:"ccdeck1:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),g.jsx("button",{type:"button",className:"btn primary",disabled:d||!h.trim(),onClick:q,children:d?"importing…":"Import"})]}),y&&g.jsx("p",{className:"aa-err",children:y}),g.jsxs("p",{className:"aa-note",children:["Use ",g.jsx("strong",{children:"share"})," on an account in the other deck. A share carries a live login and expires ten minutes after it is made."]})]})})]})})}function uL(e,n){const r=new Set(e),i=e.length?Math.max(...e):0;return[...new Set([...e,i+1])].sort((o,l)=>o-l).map(o=>{const l=o===n?"here":r.has(o)?"swap":"free";return{slot:o,kind:l,label:l==="here"?`slot ${o}`:`slot ${o} · ${l}`}})}function cL(e,n,r){if(!(r!=null&&r.ok))return null;const i=Number.isInteger(r.to)?r.to:null;if(i==null)return{menuFor:null,confirmRemove:null,shareFor:null,swapNote:null};const o=r.swapped===!0&&i!==n;return{menuFor:e.menuFor===n?i:o&&e.menuFor===i?n:e.menuFor,confirmRemove:null,shareFor:null,swapNote:o?{at:i,displaced:n}:null}}const dL=64;function fL(e,n){const r=e.trim();return{alias:r,commit:r!==(n??"").trim()}}const hL=Object.freeze({text:"couldn't reach the deck server",reload:!0});async function Jx(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function pL(e){const n=e.find(i=>!i.ok);if(!n)return null;const r=yo(n.body);return{text:Ev(n.body,`the deck server answered ${n.status}`),...r?{raw:r}:{},reload:!0}}function e_(e,n){return n?e!=null&&e.reload&&e.text===n.text&&e.raw===n.raw?e:n:e!=null&&e.reload?null:e}const t_=15e3,mL=8e3,gL=1800,vL=3e4,yL=[70,80,85,90,95];function wL(e,n){const r=e-n;if(r<=0)return null;const i=Math.floor(r/86400),o=Math.floor(r%86400/3600),l=Math.floor(r%3600/60);return i>0?`${i}d ${o}h`:o>0?`${o}h ${l}m`:`${l}m`}function n_(e,n){const r=n-Math.floor(e/1e3);return r<60?"just now":r<3600?`${Math.floor(r/60)}m ago`:r<86400?`${Math.floor(r/3600)}h ago`:`${Math.floor(r/86400)}d ago`}function xL(e,n){if(!e)return"";const r=Math.floor(e/1e3)-n;return r<=0?" · due":r<60?` · next in ${r}s`:` · next in ${Math.round(r/60)}m`}function _L(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 bL({lane:e,nowSec:n}){const r=Math.min(100,Math.max(0,e.pct)),i=r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",o=e.resetAt?wL(e.resetAt,n):null;return g.jsxs("div",{className:"ap-lane",children:[g.jsx("span",{className:"ap-lane-label",children:e.label}),g.jsx("div",{className:"ap-lane-track",children:g.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:i,opacity:r===0?.4:1}})}),g.jsxs("span",{className:"ap-lane-pct",style:{color:i},children:[r,"%"]}),g.jsx("span",{className:"ap-lane-reset",children:o?`resets ${o}`:""})]})}async function SL(e){var r;let n=!1;try{n=await Promise.race([((r=navigator.clipboard)==null?void 0:r.writeText(e).then(()=>!0))??Promise.resolve(!1),new Promise(i=>window.setTimeout(()=>i(!1),500))])}catch{n=!1}if(n)return!0;try{const i=document.createElement("textarea");i.value=e,i.setAttribute("readonly",""),i.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(i),i.select(),n=document.execCommand("copy"),i.remove()}catch{n=!1}return n}function kL(e,n){const r=Math.round(e/1e3)-n;return r<=0?{text:"expired",tone:"gone"}:r<60?{text:`expires in ${r}s`,tone:"soon"}:{text:`expires in ${Math.round(r/60)}m`,tone:"ok"}}function EL({onClose:e}){var re,le,fe;const[n,r]=T.useState(null),[i,o]=T.useState(null),[l,u]=T.useState(null),[c,h]=T.useState(!1),[p,d]=T.useState(null),[m,y]=T.useState(null),[w,N]=T.useState(()=>Math.floor(Date.now()/1e3)),_=T.useRef(null),[b,S]=T.useState(null),[k,E]=T.useState(!1),[C,I]=T.useState(""),[P,A]=T.useState(null),[U,L]=T.useState(null),[O,q]=T.useState(null),[G,F]=T.useState(!1),[j,B]=T.useState(null),z=T.useCallback(async(te=!1)=>{te&&h(!0);const ce=new AbortController,Ce=window.setTimeout(()=>ce.abort(),vL);try{const[ve,je]=await Promise.all([fetch(`/api/claude-accounts${te?"?refresh=1":""}`,{signal:ce.signal}),fetch("/api/cswap-auto",{signal:ce.signal})]);ve.ok&&r(await ve.json()),je.ok&&o(await je.json());const ye=pL([await Jx(ve),await Jx(je)]);y(ke=>e_(ke,ye))}catch{y(ve=>e_(ve,hL))}finally{window.clearTimeout(Ce),te&&h(!1)}},[]),ne=T.useCallback(async(te,ce)=>{u(ce),y(null);try{const ve=await(await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(te)})).json().catch(()=>null);return ve!=null&&ve.ok||y({text:Ev(ve,"command failed"),raw:yo(ve)}),ve}catch{return y({text:"server unreachable"}),null}finally{u(null)}},[]),Z=T.useCallback(async(te,ce)=>{u(ce),y(null);try{const ve=await(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(te)})).json().catch(()=>null);return ve!=null&&ve.ok||y({text:cu(ve,"command failed")}),ve}catch{return y({text:"server unreachable"}),null}finally{u(null)}},[]);T.useEffect(()=>(z(!0),_.current=window.setInterval(()=>z(!1),t_),()=>{_.current!=null&&window.clearInterval(_.current)}),[z]),T.useEffect(()=>{const te=window.setInterval(()=>N(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(te)},[]);const $=((re=i==null?void 0:i.settings["autoswitch.threshold"])==null?void 0:re.value)??"90",Q=(le=n==null?void 0:n.accounts)==null?void 0:le.find(te=>te.active),M=Q!=null&&Q.lanes.length?Math.max(...Q.lanes.map(te=>te.pct)):null,V=M!=null&&M>=Number($)-15,Y=async te=>{d(te),y(null);try{const Ce=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:te})})).json().catch(()=>null);Ce!=null&&Ce.ok||y({text:Ev(Ce,"the switch failed"),raw:yo(Ce)}),await z(!0)}catch{y({text:"server unreachable"})}finally{d(null)}},H=async(te,ce)=>{const{commit:Ce,alias:ve}=fL(C,ce);if(Ce){const je=await Z({action:"alias",account:te,alias:ve},`alias-${te}`);if(await z(!0),!(je!=null&&je.ok))return;I(ve)}A(te),window.setTimeout(()=>A(je=>je===te?null:je),gL)},J=async(te,ce)=>{const Ce=await Z({action:"move",account:te,slot:ce},`move-${te}`),ve=cL({menuFor:b,shareFor:(O==null?void 0:O.num)??null},te,Ce);if(await z(!0),ve){S(ve.menuFor),L(ve.confirmRemove),ve.shareFor==null&&(q(null),F(!1)),B(ve.swapNote);const je=ve.swapNote;je&&window.setTimeout(()=>B(ye=>ye===je?null:ye),mL)}};return g.jsxs("div",{className:"accounts-panel",id:"accounts-panel","aria-label":"Claude accounts",children:[g.jsxs("div",{className:"ap-header",children:[g.jsx("h3",{children:"Accounts"}),g.jsxs("div",{className:"ap-header-right",children:[g.jsx("button",{type:"button",className:"btn ap-add",onClick:()=>E(!0),title:"Sign in to another Claude account, or paste one shared from another deck",children:"+"}),g.jsx("button",{type:"button",className:"btn ap-refresh",onClick:()=>z(!0),disabled:c,"aria-label":"Reload accounts",title:"Reload from claude-swap",children:c?"…":"↻"}),g.jsx("button",{type:"button",className:"btn icon-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:"×"})]})]}),n==null?m?g.jsxs("div",{className:"ap-empty",role:"alert",children:[g.jsx("span",{title:m.raw||void 0,children:m.text}),g.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",t_/1e3," seconds."]}),g.jsx("button",{type:"button",className:"ap-fix",disabled:c,onClick:()=>z(!0),children:c?"trying…":"try again"})]}):g.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?g.jsxs(g.Fragment,{children:[(fe=n.accounts)==null?void 0:fe.map(te=>g.jsxs("div",{className:`ap-account${te.active?" active":""}${te.disabled?" disabled":""}`,children:[g.jsxs("div",{className:"ap-account-head",children:[g.jsx("span",{className:"ap-num",children:te.num}),te.alias&&g.jsx("span",{className:"ap-alias",title:te.alias,children:te.alias}),g.jsx("span",{className:"ap-email",title:te.org??void 0,children:te.email}),g.jsx("button",{type:"button",className:`ap-more${b===te.num?" on":""}`,"aria-label":`Manage account ${te.num}`,"aria-expanded":b===te.num,"aria-controls":b===te.num?`ap-manage-${te.num}`:void 0,title:"Share, rename, move, remove",onClick:()=>{S(b===te.num?null:te.num),I(te.alias??""),L(null),q(null),F(!1),B(null),A(null)},children:"⋯"}),te.active?g.jsx("span",{className:"ap-badge-active",children:"● active"}):g.jsx("button",{type:"button",className:"btn ap-switch",disabled:p!=null||te.disabled,onClick:()=>Y(te.num),title:te.disabled?"Held out of rotation":`Switch to ${te.alias??te.email}`,children:p===te.num?"…":"switch"})]}),te.lanes.length>0?te.lanes.map(ce=>g.jsx(bL,{lane:ce,nowSec:w},ce.id)):g.jsx("div",{className:"ap-hint",children:"No usage recorded yet."}),g.jsxs("div",{className:"ap-meta",children:[te.error&&(()=>{const ce=_L(te.error);return g.jsxs(g.Fragment,{children:[g.jsx("span",{className:"ap-err",title:ce.hint,children:ce.text}),ce.fixable&&g.jsx("button",{type:"button",className:"ap-fix",onClick:()=>E(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"sign in again"})]})})(),((i==null?void 0:i.enabled)||(i==null?void 0:i.external))&&!te.active&&g.jsx("button",{type:"button",className:"ap-rotate",disabled:l!=null,onClick:()=>ne({action:"account",account:te.num,enabled:te.disabled},`rot-${te.num}`).then(()=>z(!0)),title:te.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",children:te.disabled?"held out":"in rotation"}),te.fetchedAt?g.jsxs("span",{className:`ap-age${te.stale?" 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 ",n_(te.fetchedAt,w),xL(te.nextAt,w)]}):g.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})]}),b===te.num&&g.jsxs("div",{className:"ap-manage",id:`ap-manage-${te.num}`,role:"group","aria-label":`Manage account ${te.num}`,children:[g.jsxs("div",{className:"ap-manage-name",children:[g.jsx("label",{className:"vis-hidden",htmlFor:`ap-alias-${te.num}`,children:"Alias"}),g.jsx("input",{id:`ap-alias-${te.num}`,className:"ap-manage-input",type:"text",value:C,onChange:ce=>I(ce.target.value),onKeyDown:ce=>{ce.key==="Enter"&&H(te.num,te.alias)},maxLength:dL,placeholder:"e.g. work",spellCheck:!1,autoFocus:!0}),g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,onClick:()=>H(te.num,te.alias),title:"A short name to show instead of the email",children:P===te.num?"saved":"save"})]}),g.jsxs("div",{className:"ap-manage-acts",children:[g.jsx("label",{className:"vis-hidden",htmlFor:`ap-slot-${te.num}`,children:"Slot"}),g.jsx("span",{className:"ap-field",children:g.jsx("select",{id:`ap-slot-${te.num}`,value:String(te.num),disabled:l!=null,onChange:ce=>J(te.num,Number(ce.target.value)),children:uL((n.accounts??[]).map(ce=>ce.num),te.num).map(ce=>g.jsx("option",{value:ce.slot,children:ce.label},ce.slot))})}),g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,title:`Copy this account to another ${tn}. 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:async()=>{F(!1);const ce=await Z({action:"share",account:te.num},`share-${te.num}`);ce!=null&&ce.ok&&q({num:te.num,blob:ce.blob,expiresAt:ce.expiresAt})},children:"share"}),g.jsx("button",{type:"button",className:`ap-manage-btn danger${U===te.num?" armed":""}`,disabled:l!=null,title:U===te.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{if(U!==te.num){L(te.num),window.setTimeout(()=>L(ce=>ce===te.num?null:ce),4e3);return}L(null),Z({action:"remove",account:te.num},`rm-${te.num}`).then(()=>{S(null),z(!0)})},children:U===te.num?"confirm":"remove"})]}),(j==null?void 0:j.at)===te.num&&(()=>{var ve;const ce=(ve=n.accounts)==null?void 0:ve.find(je=>je.num===j.displaced),Ce=(ce==null?void 0:ce.alias)??(ce==null?void 0:ce.email)??"the account that was there";return g.jsxs("span",{className:"ap-manage-hint ap-manage-swap",title:`Slot ${j.at} was taken, so the two accounts traded places: ${Ce} now holds slot ${j.displaced}.`,children:["swapped with slot ",j.displaced]})})(),(O==null?void 0:O.num)===te.num&&(()=>{const ce=kL(O.expiresAt,w),Ce=ce.tone==="gone";return g.jsxs("div",{className:`ap-share${Ce?" expired":""}`,children:[g.jsx("code",{className:"ap-share-blob",children:O.blob}),g.jsxs("div",{className:"ap-share-foot",children:[g.jsx("button",{type:"button",className:"ap-manage-btn",disabled:l!=null,onClick:async()=>{if(Ce){F(!1);const ve=await Z({action:"share",account:te.num},`share-${te.num}`);ve!=null&&ve.ok&&q({num:te.num,blob:ve.blob,expiresAt:ve.expiresAt});return}await SL(O.blob)&&(F(!0),window.setTimeout(()=>F(!1),1800))},children:Ce?"make a new share":G?"copied":"copy"}),g.jsxs("span",{className:"ap-manage-hint",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:[g.jsx("span",{className:"ap-share-warn",children:"this is the password"})," · ",g.jsx("span",{className:`ap-share-expiry ${ce.tone}`,children:ce.text})]})]})]})})()]})]},te.num)),(i==null?void 0:i.ok)&&g.jsxs("div",{className:"ap-auto",children:[g.jsxs("div",{className:"ap-auto-head",children:[g.jsx("span",{className:"ap-auto-title",children:"Auto-switch"}),g.jsxs("span",{className:"ap-auto-ctl",children:[M!=null&&g.jsxs("span",{className:`ap-auto-now${V?" near":""}`,children:[Math.round(M),"%"]}),g.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:g.jsx("select",{"aria-label":"Switch threshold",value:$,disabled:l!=null,onChange:te=>ne({action:"setting",key:"autoswitch.threshold",value:te.target.value},"threshold").then(()=>z(!0)),children:yL.map(te=>g.jsxs("option",{value:te,children:[te,"%"]},te))})}),g.jsxs("button",{type:"button",className:`ap-auto-state${i.enabled?" live":""}`,role:"switch","aria-checked":i.enabled,disabled:l!=null,onClick:()=>ne({action:"enable",enabled:!i.enabled},"enable").then(()=>z(!0)),title:i.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:[g.jsx("i",{className:i.enabled?"ap-pulse":"ap-dot","aria-hidden":!0}),i.enabled?"on":"off"]})]})]}),i.external&&g.jsxs("p",{className:"ap-auto-note",children:[g.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",g.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",i.enabled?" — this toggle takes over when you stop it.":"."]}),i.lastTick&&g.jsx("div",{className:"ap-auto-foot",children:g.jsxs("span",{className:"ap-auto-result",children:["checked ",n_(i.lastTick.at,w)]})})]}),m&&g.jsxs("div",{className:"ap-failure",role:"alert",children:[g.jsx("span",{className:"ap-failure-text",title:m.raw||void 0,children:m.text}),g.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>y(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),g.jsx("p",{className:"ap-footnote",title:"Anthropic's usage endpoint allows roughly 28–30 requests per hour per account, shared by every tool on this machine — polling it from here would rate-limit your account. So the deck never fetches: it asks claude-swap to collect while this panel is open, at most once every three minutes, and claude-swap decides whether that touches the network at all.",children:"Collected by claude-swap while this panel is open."})]}):g.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"claude-swap isn't installed."}),g.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&g.jsx("code",{className:"ap-cmd",children:n.hint}),g.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",g.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"No accounts added yet."}),g.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",g.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):g.jsxs(g.Fragment,{children:[g.jsx("span",{children:"Couldn't read the account store."}),g.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})}),k&&g.jsx(lL,{onClose:()=>E(!1),onChanged:()=>z(!0)})]})}const NL=3e4;function CL({bundle:e,running:n,lastTried:r}){return!n||e===n?!1:r!==n}function RL({bundle:e,running:n,pending:r,lastTried:i}){return n?CL({bundle:e,running:n,lastTried:i})?"reload":r==null||r&&r!==n?"wait":"confirm":"wait"}function TL(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function jL({asked:e,reported:n}){return n?n!==e:!1}function AL(e){const n=e.thresholdMs??NL;return!e.enabled||e.kind!=="restart"||!e.canRestart?{idleSince:null,restart:!1}:e.busy?{idleSince:null,restart:!1}:e.idleSince==null?{idleSince:e.now,restart:!1}:e.now<e.idleSince?{idleSince:e.now,restart:!1}:{idleSince:e.idleSince,restart:e.now-e.idleSince>=n}}function IL({agentCount:e,onConfirm:n,onCancel:r}){const i=T.useRef(null),o=xo(r,{focusRef:i,layer:SP}),l=e===0?"This deletes the server's event log":`This removes ${e===1?"the one agent":`all ${e} agents`} on the canvas and deletes the server's event log`;return g.jsx("div",{className:"modal-backdrop",onClick:r,role:"presentation",children:g.jsxs("div",{ref:o,className:"modal clear-confirm",onClick:u=>u.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[g.jsxs("header",{className:"modal-head",children:[g.jsxs("div",{className:"modal-title",children:[g.jsx("span",{className:"status-dot err","aria-hidden":!0}),g.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),g.jsx("div",{className:"modal-actions",children:g.jsx("button",{type:"button",className:"btn icon-btn",onClick:r,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),g.jsxs("section",{className:"modal-body",children:[g.jsxs("p",{className:"modal-note",children:[l," — the file a restarted deck replays to rebuild what you see. Layout, pins and selection go with it. This cannot be undone."]}),g.jsxs("div",{className:"cc-actions",children:[g.jsx("button",{type:"button",ref:i,className:"btn",onClick:r,children:"Cancel"}),g.jsx("button",{type:"button",className:"btn danger",onClick:n,children:"Clear everything"})]})]})]})})}function ML(e,n){return e==="confirmation"?n.confirmOpen?"clear":"ignore":n.modalOpen||n.confirmOpen?"ignore":"confirm"}function OL(e){return e.slice().sort((n,r)=>n.y-r.y||n.x-r.x)}function PL(e,n,r){var u;if(e.length===0)return null;const i=OL(e),o=n?i.findIndex(c=>c.id===n):-1,l=o===-1?r===1?0:i.length-1:(o+r+i.length)%i.length;return((u=i[l])==null?void 0:u.id)??null}const LL=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Escape","Delete","Backspace"]);function qL(e,n){return n==null?{kind:"deck",nodeId:null}:e.key==="Enter"||e.key===" "?{kind:"activate",nodeId:n,additive:e.shiftKey}:LL.has(e.key)?{kind:"node",nodeId:n}:{kind:"deck",nodeId:n}}const $L=new Set(["","BODY","HTML","#DOCUMENT"]);function DL(e){return!e||Qv(e)?!1:!$L.has(String(e.tagName??"").toUpperCase())}function tu(e,n){if(n.size!==0)for(const r of Array.from(e.keys()))n.has(r)||e.delete(r)}function FL(e){const n=new Set;for(const r of e)n.add(r.id),n.add(`group:${r.sessionId}`);return n}function SC(e,n,r){return!n.has(e)||r.has(e)}function zL(e,n,r,i){return!n.has(e)&&SC(e,r,i)}function BL(e,n,r){const i={x:0,y:0};return n.set(e,i),r.add(e),i}function UL(e,n,r,i){r.set(e,n),i.delete(e)}const HL=40,WL=120;function VL(e,n){let r=null,i=0,o=Number.NEGATIVE_INFINITY;const l=()=>{r=null,o=n.now(),e()},u=()=>{r!=null&&(n.clearTimeout(r),r=null)},c=(h,p,d)=>{if(r!=null){if(i<=h)return;u()}const m=Math.min(d,Math.max(0,h-p));i=h,r=n.setTimeout(l,m)};return{live(h=HL){const p=n.now(),d=Math.max(o+h,p);if(d<=p){u(),l();return}c(d,p,h)},replay(h=WL){u(),i=n.now()+h,r=n.setTimeout(l,h)},flush(){u(),l()},cancel(){u()}}}function GL(){let e=!1,n=[];return{get paused(){return e},get size(){return n.length},accept(r){return e?(n.push(r),!1):!0},setPaused(r){if(e=r,r||n.length===0)return[];const i=n;return n=[],i}}}const YL="1",r_="agent-dag.schema",KL=["agent-dag.layout","agent-dag.viewport"];function kC(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function XL(e,n=YL){let r=null;try{r=e.getItem(r_)}catch{return[]}if(r===n)return[];const i=[];if(r!==null)for(const o of KL)try{e.getItem(o)!==null&&(e.removeItem(o),i.push(o))}catch{}try{e.setItem(r_,n)}catch{}return i}const EC="agent-dag.theme";function QL(e){return e==="light"?"light":"dark"}function ZL(){return QL(kC(EC))}function JL({waiting:e,running:n}){return{title:e>0?`(${e}) ${tn}`:tn,icon:e>0?"waiting":n>0?"running":"idle"}}const Dd={waiting:"#c97d12",running:"#2a90d4",idle:"#7e828c"};function Fd(e,n){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">${n==="waiting"?`<circle cx="16" cy="16" r="14.5" fill="${e}"/>`:`<circle cx="16" cy="16" r="12" fill="none" stroke="${e}" stroke-width="5"/>`+(n==="running"?`<circle cx="16" cy="16" r="5" fill="${e}"/>`:"")}</svg>`}const eq=Object.freeze({waiting:`data:image/svg+xml,${encodeURIComponent(Fd(Dd.waiting,"waiting"))}`,running:`data:image/svg+xml,${encodeURIComponent(Fd(Dd.running,"running"))}`,idle:`data:image/svg+xml,${encodeURIComponent(Fd(Dd.idle,"idle"))}`}),tq="No sessions are waiting for you.";function nq(e){if(e.length===0)return"";const[n,...r]=e;if(r.length===0)return`${n.label} is waiting for your permission.`;const i=`${r.length} more session${r.length===1?"":"s"}`;return`${n.label} and ${i} are waiting for your permission.`}function rq(e,n){return n!==""?n:e===""?"":tq}function sq(){let e=0;return{begin(){const n=++e;return()=>n===e},cancel(){e++}}}function iq(e,n=new Date){return new Date(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()-(e-1))).toISOString().slice(0,10).replace(/-/g,"")}function oq(e){return!e.answer||e.answer.range!==e.want?{phase:"busy",stale:!1}:e.answer.ok?{phase:e.answer.days>0?"chart":"empty",stale:e.loading}:{phase:"error",stale:e.loading}}function nu(e){const n=e.toLowerCase();return n.includes("opus")?"#c4b5fd":n.includes("sonnet")?"#7dd3fc":n.includes("haiku")?"#86efac":n.includes("gpt-5")||n.includes("gpt5")?"#fcd34d":n.includes("gpt")?"#fca5a5":n.includes("gemini")?"#a5b4fc":n.includes("codex")?"#fdba74":"#94a3b8"}const aq=[7,14,30,90];function lq(e){const[n,r]=T.useState(null),[i,o]=T.useState(!1),l=T.useRef(sq()).current,u=(c=!1)=>{const h=l.begin(),p=e;o(!0);const m=`/api/ccusage?since=${iq(p)}${c?"&refresh=1":""}`;fetch(m).then(y=>y.json()).then(y=>{h()&&r({range:p,resp:y})}).catch(()=>{h()&&r({range:p,resp:{ok:!1,reason:"unreachable"}})}).finally(()=>{h()&&o(!1)})};return T.useEffect(()=>(u(!1),()=>l.cancel()),[e]),{landed:n,loading:i,reload:()=>u(!0)}}function uq({onClose:e}){var C,I,P;const[n,r]=T.useState(30),[i,o]=T.useState(null),{landed:l,loading:u,reload:c}=lq(n),h=T.useRef(null),p=xo(e,{focusRef:h}),d=oq({loading:u,want:n,answer:l&&{range:l.range,ok:l.resp.ok===!0,days:((C=l.resp.days)==null?void 0:C.length)??0}}),m=d.phase==="chart"?l.resp.days??[]:[],y=T.useMemo(()=>m.reduce((A,U)=>Math.max(A,U.totalCost),0),[m]),{totalCost:w,totalTok:N,inOut:_,cacheRead:b,modelCosts:S}=T.useMemo(()=>{let A=0,U=0,L=0,O=0;const q=new Map;for(const G of m){A+=G.totalCost,U+=G.totalTokens,L+=G.inputTokens+G.outputTokens,O+=G.cacheReadTokens;for(const F of G.modelBreakdowns)q.set(F.modelName,(q.get(F.modelName)??0)+F.cost)}return{totalCost:A,totalTok:U,inOut:L,cacheRead:O,modelCosts:q}},[m]),k=T.useMemo(()=>Array.from(S.entries()).sort((A,U)=>U[1]-A[1]),[S]),E=i?m.find(A=>A.period===i)??null:null;return g.jsx("div",{className:"uh-backdrop",onClick:e,role:"presentation",children:g.jsxs("div",{ref:p,className:"uh-modal",onClick:A=>A.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Usage history",children:[g.jsxs("header",{className:"uh-head",children:[g.jsxs("div",{className:"uh-titlewrap",children:[g.jsx("div",{className:"uh-title",children:"Usage history"}),g.jsx("div",{className:"uh-sub",children:"via ccusage · local Claude / Codex logs"})]}),g.jsx("div",{className:"uh-range",role:"tablist","aria-label":"Range",children:aq.map(A=>g.jsxs("button",{role:"tab","aria-selected":n===A,className:`uh-range-btn${n===A?" on":""}`,onClick:()=>{r(A),o(null)},children:[A,"d"]},A))}),g.jsx("button",{className:"btn icon-btn uh-reload",onClick:c,disabled:u,title:"Re-run ccusage","aria-label":"Reload",children:u?"…":"↻"}),g.jsx("button",{ref:h,className:"uh-close",onClick:e,"aria-label":"Close",children:"×"})]}),d.phase==="busy"?g.jsx("div",{className:"uh-status","aria-busy":"true",children:l?"running ccusage…":"running ccusage… (first run downloads the package)"}):d.phase==="error"?g.jsxs("div",{className:"uh-status uh-err",title:yo(l.resp)||void 0,children:[oL(l.resp,"ccusage did not report usage"),g.jsx("div",{children:g.jsx("button",{className:"btn uh-retry",onClick:c,disabled:u,children:u?"trying…":"Try again"})})]}):d.phase==="empty"?g.jsx("div",{className:`uh-status${d.stale?" uh-stale":""}`,"aria-busy":d.stale||void 0,children:"no usage in this range"}):g.jsxs("div",{className:d.stale?"uh-stale":void 0,"aria-busy":d.stale||void 0,children:[g.jsxs("div",{className:"uh-totals",children:[g.jsx(ru,{label:"total cost",val:ze(w),accent:!0}),g.jsx(ru,{label:"tokens",val:Dt(N)}),g.jsx(ru,{label:"input+output",val:Dt(_)}),g.jsx(ru,{label:"cache reads",val:Dt(b)})]}),g.jsx("div",{className:"uh-chart",role:"img","aria-label":"Daily cost by model",children:m.map(A=>{const U=y>0?A.totalCost/y*100:0,L=A.period===i;return g.jsxs("button",{className:`uh-bar-col${L?" sel":""}`,onClick:()=>o(L?null:A.period),title:`${A.period} · ${ze(A.totalCost)}`,style:{flexBasis:`${100/m.length}%`},children:[g.jsx("div",{className:"uh-bar",style:{height:`${Math.max(U,A.totalCost>0?2:0)}%`},children:A.modelBreakdowns.slice().sort((O,q)=>q.cost-O.cost).map(O=>{const q=A.totalCost>0?O.cost/A.totalCost*100:0;return g.jsx("div",{className:"uh-bar-seg",style:{height:`${q}%`,background:nu(O.modelName)}},O.modelName)})}),g.jsx("span",{className:"uh-bar-label",children:A.period.slice(5)})]},A.period)})}),g.jsx("div",{className:"uh-legend",children:k.map(([A,U])=>g.jsxs("span",{className:"uh-legend-item",children:[g.jsx("span",{className:"uh-legend-dot",style:{background:nu(A)}}),li(A)," ",g.jsx("span",{className:"uh-legend-cost",children:ze(U)})]},A))}),E&&g.jsxs("div",{className:"uh-detail",children:[g.jsxs("div",{className:"uh-detail-head",children:[g.jsx("span",{className:"uh-detail-date",children:E.period}),g.jsx("span",{className:"uh-detail-cost",children:ze(E.totalCost)}),(P=(I=E.metadata)==null?void 0:I.agents)!=null&&P.length?g.jsx("span",{className:"uh-detail-agents",children:E.metadata.agents.join(" · ")}):null]}),g.jsxs("div",{className:"uh-detail-mini",children:[g.jsx(su,{label:"input",val:Dt(E.inputTokens)}),g.jsx(su,{label:"output",val:Dt(E.outputTokens)}),g.jsx(su,{label:"cache write",val:Dt(E.cacheCreationTokens)}),g.jsx(su,{label:"cache read",val:Dt(E.cacheReadTokens)})]}),g.jsx("div",{className:"uh-detail-models",children:E.modelBreakdowns.slice().sort((A,U)=>U.cost-A.cost).map(A=>{const U=E.totalCost>0?A.cost/E.totalCost*100:0;return g.jsxs("div",{className:"uh-model-row",children:[g.jsxs("span",{className:"uh-model-name",children:[g.jsx("span",{className:"uh-legend-dot",style:{background:nu(A.modelName)}}),li(A.modelName)]}),g.jsx("span",{className:"uh-model-bar",children:g.jsx("span",{className:"uh-model-bar-fill",style:{width:`${U}%`,background:nu(A.modelName)}})}),g.jsx("span",{className:"uh-model-cost",children:ze(A.cost)})]},A.modelName)})})]})]})]})})}function ru({label:e,val:n,accent:r}){return g.jsxs("div",{className:"uh-stat",children:[g.jsx("span",{className:`uh-stat-val${r?" accent":""}`,children:n}),g.jsx("span",{className:"uh-stat-label",children:e})]})}function su({label:e,val:n}){return g.jsxs("div",{className:"uh-ministat",children:[g.jsx("span",{className:"uh-ministat-val",children:n}),g.jsx("span",{className:"uh-ministat-label",children:e})]})}function ey(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 zd,s_;function cq(){if(s_)return zd;s_=1;function e(){this.__data__=[],this.size=0}return zd=e,zd}var Bd,i_;function _o(){if(i_)return Bd;i_=1;function e(n,r){return n===r||n!==n&&r!==r}return Bd=e,Bd}var Ud,o_;function Mu(){if(o_)return Ud;o_=1;var e=_o();function n(r,i){for(var o=r.length;o--;)if(e(r[o][0],i))return o;return-1}return Ud=n,Ud}var Hd,a_;function dq(){if(a_)return Hd;a_=1;var e=Mu(),n=Array.prototype,r=n.splice;function i(o){var l=this.__data__,u=e(l,o);if(u<0)return!1;var c=l.length-1;return u==c?l.pop():r.call(l,u,1),--this.size,!0}return Hd=i,Hd}var Wd,l_;function fq(){if(l_)return Wd;l_=1;var e=Mu();function n(r){var i=this.__data__,o=e(i,r);return o<0?void 0:i[o][1]}return Wd=n,Wd}var Vd,u_;function hq(){if(u_)return Vd;u_=1;var e=Mu();function n(r){return e(this.__data__,r)>-1}return Vd=n,Vd}var Gd,c_;function pq(){if(c_)return Gd;c_=1;var e=Mu();function n(r,i){var o=this.__data__,l=e(o,r);return l<0?(++this.size,o.push([r,i])):o[l][1]=i,this}return Gd=n,Gd}var Yd,d_;function Ou(){if(d_)return Yd;d_=1;var e=cq(),n=dq(),r=fq(),i=hq(),o=pq();function l(u){var c=-1,h=u==null?0:u.length;for(this.clear();++c<h;){var p=u[c];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=i,l.prototype.set=o,Yd=l,Yd}var Kd,f_;function mq(){if(f_)return Kd;f_=1;var e=Ou();function n(){this.__data__=new e,this.size=0}return Kd=n,Kd}var Xd,h_;function gq(){if(h_)return Xd;h_=1;function e(n){var r=this.__data__,i=r.delete(n);return this.size=r.size,i}return Xd=e,Xd}var Qd,p_;function vq(){if(p_)return Qd;p_=1;function e(n){return this.__data__.get(n)}return Qd=e,Qd}var Zd,m_;function yq(){if(m_)return Zd;m_=1;function e(n){return this.__data__.has(n)}return Zd=e,Zd}var Jd,g_;function NC(){if(g_)return Jd;g_=1;var e=typeof zl=="object"&&zl&&zl.Object===Object&&zl;return Jd=e,Jd}var ef,v_;function nr(){if(v_)return ef;v_=1;var e=NC(),n=typeof self=="object"&&self&&self.Object===Object&&self,r=e||n||Function("return this")();return ef=r,ef}var tf,y_;function bo(){if(y_)return tf;y_=1;var e=nr(),n=e.Symbol;return tf=n,tf}var nf,w_;function wq(){if(w_)return nf;w_=1;var e=bo(),n=Object.prototype,r=n.hasOwnProperty,i=n.toString,o=e?e.toStringTag:void 0;function l(u){var c=r.call(u,o),h=u[o];try{u[o]=void 0;var p=!0}catch{}var d=i.call(u);return p&&(c?u[o]=h:delete u[o]),d}return nf=l,nf}var rf,x_;function xq(){if(x_)return rf;x_=1;var e=Object.prototype,n=e.toString;function r(i){return n.call(i)}return rf=r,rf}var sf,__;function ui(){if(__)return sf;__=1;var e=bo(),n=wq(),r=xq(),i="[object Null]",o="[object Undefined]",l=e?e.toStringTag:void 0;function u(c){return c==null?c===void 0?o:i:l&&l in Object(c)?n(c):r(c)}return sf=u,sf}var of,b_;function Ln(){if(b_)return of;b_=1;function e(n){var r=typeof n;return n!=null&&(r=="object"||r=="function")}return of=e,of}var af,S_;function $a(){if(S_)return af;S_=1;var e=ui(),n=Ln(),r="[object AsyncFunction]",i="[object Function]",o="[object GeneratorFunction]",l="[object Proxy]";function u(c){if(!n(c))return!1;var h=e(c);return h==i||h==o||h==r||h==l}return af=u,af}var lf,k_;function _q(){if(k_)return lf;k_=1;var e=nr(),n=e["__core-js_shared__"];return lf=n,lf}var uf,E_;function bq(){if(E_)return uf;E_=1;var e=_q(),n=(function(){var i=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return i?"Symbol(src)_1."+i:""})();function r(i){return!!n&&n in i}return uf=r,uf}var cf,N_;function CC(){if(N_)return cf;N_=1;var e=Function.prototype,n=e.toString;function r(i){if(i!=null){try{return n.call(i)}catch{}try{return i+""}catch{}}return""}return cf=r,cf}var df,C_;function Sq(){if(C_)return df;C_=1;var e=$a(),n=bq(),r=Ln(),i=CC(),o=/[\\^$.*+?()[\]{}|]/g,l=/^\[object .+?Constructor\]$/,u=Function.prototype,c=Object.prototype,h=u.toString,p=c.hasOwnProperty,d=RegExp("^"+h.call(p).replace(o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function m(y){if(!r(y)||n(y))return!1;var w=e(y)?d:l;return w.test(i(y))}return df=m,df}var ff,R_;function kq(){if(R_)return ff;R_=1;function e(n,r){return n==null?void 0:n[r]}return ff=e,ff}var hf,T_;function ci(){if(T_)return hf;T_=1;var e=Sq(),n=kq();function r(i,o){var l=n(i,o);return e(l)?l:void 0}return hf=r,hf}var pf,j_;function ty(){if(j_)return pf;j_=1;var e=ci(),n=nr(),r=e(n,"Map");return pf=r,pf}var mf,A_;function Pu(){if(A_)return mf;A_=1;var e=ci(),n=e(Object,"create");return mf=n,mf}var gf,I_;function Eq(){if(I_)return gf;I_=1;var e=Pu();function n(){this.__data__=e?e(null):{},this.size=0}return gf=n,gf}var vf,M_;function Nq(){if(M_)return vf;M_=1;function e(n){var r=this.has(n)&&delete this.__data__[n];return this.size-=r?1:0,r}return vf=e,vf}var yf,O_;function Cq(){if(O_)return yf;O_=1;var e=Pu(),n="__lodash_hash_undefined__",r=Object.prototype,i=r.hasOwnProperty;function o(l){var u=this.__data__;if(e){var c=u[l];return c===n?void 0:c}return i.call(u,l)?u[l]:void 0}return yf=o,yf}var wf,P_;function Rq(){if(P_)return wf;P_=1;var e=Pu(),n=Object.prototype,r=n.hasOwnProperty;function i(o){var l=this.__data__;return e?l[o]!==void 0:r.call(l,o)}return wf=i,wf}var xf,L_;function Tq(){if(L_)return xf;L_=1;var e=Pu(),n="__lodash_hash_undefined__";function r(i,o){var l=this.__data__;return this.size+=this.has(i)?0:1,l[i]=e&&o===void 0?n:o,this}return xf=r,xf}var _f,q_;function jq(){if(q_)return _f;q_=1;var e=Eq(),n=Nq(),r=Cq(),i=Rq(),o=Tq();function l(u){var c=-1,h=u==null?0:u.length;for(this.clear();++c<h;){var p=u[c];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=i,l.prototype.set=o,_f=l,_f}var bf,$_;function Aq(){if($_)return bf;$_=1;var e=jq(),n=Ou(),r=ty();function i(){this.size=0,this.__data__={hash:new e,map:new(r||n),string:new e}}return bf=i,bf}var Sf,D_;function Iq(){if(D_)return Sf;D_=1;function e(n){var r=typeof n;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?n!=="__proto__":n===null}return Sf=e,Sf}var kf,F_;function Lu(){if(F_)return kf;F_=1;var e=Iq();function n(r,i){var o=r.__data__;return e(i)?o[typeof i=="string"?"string":"hash"]:o.map}return kf=n,kf}var Ef,z_;function Mq(){if(z_)return Ef;z_=1;var e=Lu();function n(r){var i=e(this,r).delete(r);return this.size-=i?1:0,i}return Ef=n,Ef}var Nf,B_;function Oq(){if(B_)return Nf;B_=1;var e=Lu();function n(r){return e(this,r).get(r)}return Nf=n,Nf}var Cf,U_;function Pq(){if(U_)return Cf;U_=1;var e=Lu();function n(r){return e(this,r).has(r)}return Cf=n,Cf}var Rf,H_;function Lq(){if(H_)return Rf;H_=1;var e=Lu();function n(r,i){var o=e(this,r),l=o.size;return o.set(r,i),this.size+=o.size==l?0:1,this}return Rf=n,Rf}var Tf,W_;function ny(){if(W_)return Tf;W_=1;var e=Aq(),n=Mq(),r=Oq(),i=Pq(),o=Lq();function l(u){var c=-1,h=u==null?0:u.length;for(this.clear();++c<h;){var p=u[c];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=n,l.prototype.get=r,l.prototype.has=i,l.prototype.set=o,Tf=l,Tf}var jf,V_;function qq(){if(V_)return jf;V_=1;var e=Ou(),n=ty(),r=ny(),i=200;function o(l,u){var c=this.__data__;if(c instanceof e){var h=c.__data__;if(!n||h.length<i-1)return h.push([l,u]),this.size=++c.size,this;c=this.__data__=new r(h)}return c.set(l,u),this.size=c.size,this}return jf=o,jf}var Af,G_;function qu(){if(G_)return Af;G_=1;var e=Ou(),n=mq(),r=gq(),i=vq(),o=yq(),l=qq();function u(c){var h=this.__data__=new e(c);this.size=h.size}return u.prototype.clear=n,u.prototype.delete=r,u.prototype.get=i,u.prototype.has=o,u.prototype.set=l,Af=u,Af}var If,Y_;function ry(){if(Y_)return If;Y_=1;function e(n,r){for(var i=-1,o=n==null?0:n.length;++i<o&&r(n[i],i,n)!==!1;);return n}return If=e,If}var Mf,K_;function RC(){if(K_)return Mf;K_=1;var e=ci(),n=(function(){try{var r=e(Object,"defineProperty");return r({},"",{}),r}catch{}})();return Mf=n,Mf}var Of,X_;function $u(){if(X_)return Of;X_=1;var e=RC();function n(r,i,o){i=="__proto__"&&e?e(r,i,{configurable:!0,enumerable:!0,value:o,writable:!0}):r[i]=o}return Of=n,Of}var Pf,Q_;function Du(){if(Q_)return Pf;Q_=1;var e=$u(),n=_o(),r=Object.prototype,i=r.hasOwnProperty;function o(l,u,c){var h=l[u];(!(i.call(l,u)&&n(h,c))||c===void 0&&!(u in l))&&e(l,u,c)}return Pf=o,Pf}var Lf,Z_;function Da(){if(Z_)return Lf;Z_=1;var e=Du(),n=$u();function r(i,o,l,u){var c=!l;l||(l={});for(var h=-1,p=o.length;++h<p;){var d=o[h],m=u?u(l[d],i[d],d,l,i):void 0;m===void 0&&(m=i[d]),c?n(l,d,m):e(l,d,m)}return l}return Lf=r,Lf}var qf,J_;function $q(){if(J_)return qf;J_=1;function e(n,r){for(var i=-1,o=Array(n);++i<n;)o[i]=r(i);return o}return qf=e,qf}var $f,e1;function vr(){if(e1)return $f;e1=1;function e(n){return n!=null&&typeof n=="object"}return $f=e,$f}var Df,t1;function Dq(){if(t1)return Df;t1=1;var e=ui(),n=vr(),r="[object Arguments]";function i(o){return n(o)&&e(o)==r}return Df=i,Df}var Ff,n1;function Fa(){if(n1)return Ff;n1=1;var e=Dq(),n=vr(),r=Object.prototype,i=r.hasOwnProperty,o=r.propertyIsEnumerable,l=e((function(){return arguments})())?e:function(u){return n(u)&&i.call(u,"callee")&&!o.call(u,"callee")};return Ff=l,Ff}var zf,r1;function bt(){if(r1)return zf;r1=1;var e=Array.isArray;return zf=e,zf}var ya={exports:{}},Bf,s1;function Fq(){if(s1)return Bf;s1=1;function e(){return!1}return Bf=e,Bf}ya.exports;var i1;function So(){return i1||(i1=1,(function(e,n){var r=nr(),i=Fq(),o=n&&!n.nodeType&&n,l=o&&!0&&e&&!e.nodeType&&e,u=l&&l.exports===o,c=u?r.Buffer:void 0,h=c?c.isBuffer:void 0,p=h||i;e.exports=p})(ya,ya.exports)),ya.exports}var Uf,o1;function Fu(){if(o1)return Uf;o1=1;var e=9007199254740991,n=/^(?:0|[1-9]\d*)$/;function r(i,o){var l=typeof i;return o=o??e,!!o&&(l=="number"||l!="symbol"&&n.test(i))&&i>-1&&i%1==0&&i<o}return Uf=r,Uf}var Hf,a1;function sy(){if(a1)return Hf;a1=1;var e=9007199254740991;function n(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=e}return Hf=n,Hf}var Wf,l1;function zq(){if(l1)return Wf;l1=1;var e=ui(),n=sy(),r=vr(),i="[object Arguments]",o="[object Array]",l="[object Boolean]",u="[object Date]",c="[object Error]",h="[object Function]",p="[object Map]",d="[object Number]",m="[object Object]",y="[object RegExp]",w="[object Set]",N="[object String]",_="[object WeakMap]",b="[object ArrayBuffer]",S="[object DataView]",k="[object Float32Array]",E="[object Float64Array]",C="[object Int8Array]",I="[object Int16Array]",P="[object Int32Array]",A="[object Uint8Array]",U="[object Uint8ClampedArray]",L="[object Uint16Array]",O="[object Uint32Array]",q={};q[k]=q[E]=q[C]=q[I]=q[P]=q[A]=q[U]=q[L]=q[O]=!0,q[i]=q[o]=q[b]=q[l]=q[S]=q[u]=q[c]=q[h]=q[p]=q[d]=q[m]=q[y]=q[w]=q[N]=q[_]=!1;function G(F){return r(F)&&n(F.length)&&!!q[e(F)]}return Wf=G,Wf}var Vf,u1;function zu(){if(u1)return Vf;u1=1;function e(n){return function(r){return n(r)}}return Vf=e,Vf}var wa={exports:{}};wa.exports;var c1;function iy(){return c1||(c1=1,(function(e,n){var r=NC(),i=n&&!n.nodeType&&n,o=i&&!0&&e&&!e.nodeType&&e,l=o&&o.exports===i,u=l&&r.process,c=(function(){try{var h=o&&o.require&&o.require("util").types;return h||u&&u.binding&&u.binding("util")}catch{}})();e.exports=c})(wa,wa.exports)),wa.exports}var Gf,d1;function za(){if(d1)return Gf;d1=1;var e=zq(),n=zu(),r=iy(),i=r&&r.isTypedArray,o=i?n(i):e;return Gf=o,Gf}var Yf,f1;function TC(){if(f1)return Yf;f1=1;var e=$q(),n=Fa(),r=bt(),i=So(),o=Fu(),l=za(),u=Object.prototype,c=u.hasOwnProperty;function h(p,d){var m=r(p),y=!m&&n(p),w=!m&&!y&&i(p),N=!m&&!y&&!w&&l(p),_=m||y||w||N,b=_?e(p.length,String):[],S=b.length;for(var k in p)(d||c.call(p,k))&&!(_&&(k=="length"||w&&(k=="offset"||k=="parent")||N&&(k=="buffer"||k=="byteLength"||k=="byteOffset")||o(k,S)))&&b.push(k);return b}return Yf=h,Yf}var Kf,h1;function Bu(){if(h1)return Kf;h1=1;var e=Object.prototype;function n(r){var i=r&&r.constructor,o=typeof i=="function"&&i.prototype||e;return r===o}return Kf=n,Kf}var Xf,p1;function jC(){if(p1)return Xf;p1=1;function e(n,r){return function(i){return n(r(i))}}return Xf=e,Xf}var Qf,m1;function Bq(){if(m1)return Qf;m1=1;var e=jC(),n=e(Object.keys,Object);return Qf=n,Qf}var Zf,g1;function oy(){if(g1)return Zf;g1=1;var e=Bu(),n=Bq(),r=Object.prototype,i=r.hasOwnProperty;function o(l){if(!e(l))return n(l);var u=[];for(var c in Object(l))i.call(l,c)&&c!="constructor"&&u.push(c);return u}return Zf=o,Zf}var Jf,v1;function Wr(){if(v1)return Jf;v1=1;var e=$a(),n=sy();function r(i){return i!=null&&n(i.length)&&!e(i)}return Jf=r,Jf}var eh,y1;function Ss(){if(y1)return eh;y1=1;var e=TC(),n=oy(),r=Wr();function i(o){return r(o)?e(o):n(o)}return eh=i,eh}var th,w1;function Uq(){if(w1)return th;w1=1;var e=Da(),n=Ss();function r(i,o){return i&&e(o,n(o),i)}return th=r,th}var nh,x1;function Hq(){if(x1)return nh;x1=1;function e(n){var r=[];if(n!=null)for(var i in Object(n))r.push(i);return r}return nh=e,nh}var rh,_1;function Wq(){if(_1)return rh;_1=1;var e=Ln(),n=Bu(),r=Hq(),i=Object.prototype,o=i.hasOwnProperty;function l(u){if(!e(u))return r(u);var c=n(u),h=[];for(var p in u)p=="constructor"&&(c||!o.call(u,p))||h.push(p);return h}return rh=l,rh}var sh,b1;function di(){if(b1)return sh;b1=1;var e=TC(),n=Wq(),r=Wr();function i(o){return r(o)?e(o,!0):n(o)}return sh=i,sh}var ih,S1;function Vq(){if(S1)return ih;S1=1;var e=Da(),n=di();function r(i,o){return i&&e(o,n(o),i)}return ih=r,ih}var xa={exports:{}};xa.exports;var k1;function AC(){return k1||(k1=1,(function(e,n){var r=nr(),i=n&&!n.nodeType&&n,o=i&&!0&&e&&!e.nodeType&&e,l=o&&o.exports===i,u=l?r.Buffer:void 0,c=u?u.allocUnsafe:void 0;function h(p,d){if(d)return p.slice();var m=p.length,y=c?c(m):new p.constructor(m);return p.copy(y),y}e.exports=h})(xa,xa.exports)),xa.exports}var oh,E1;function IC(){if(E1)return oh;E1=1;function e(n,r){var i=-1,o=n.length;for(r||(r=Array(o));++i<o;)r[i]=n[i];return r}return oh=e,oh}var ah,N1;function MC(){if(N1)return ah;N1=1;function e(n,r){for(var i=-1,o=n==null?0:n.length,l=0,u=[];++i<o;){var c=n[i];r(c,i,n)&&(u[l++]=c)}return u}return ah=e,ah}var lh,C1;function OC(){if(C1)return lh;C1=1;function e(){return[]}return lh=e,lh}var uh,R1;function ay(){if(R1)return uh;R1=1;var e=MC(),n=OC(),r=Object.prototype,i=r.propertyIsEnumerable,o=Object.getOwnPropertySymbols,l=o?function(u){return u==null?[]:(u=Object(u),e(o(u),function(c){return i.call(u,c)}))}:n;return uh=l,uh}var ch,T1;function Gq(){if(T1)return ch;T1=1;var e=Da(),n=ay();function r(i,o){return e(i,n(i),o)}return ch=r,ch}var dh,j1;function ly(){if(j1)return dh;j1=1;function e(n,r){for(var i=-1,o=r.length,l=n.length;++i<o;)n[l+i]=r[i];return n}return dh=e,dh}var fh,A1;function Uu(){if(A1)return fh;A1=1;var e=jC(),n=e(Object.getPrototypeOf,Object);return fh=n,fh}var hh,I1;function PC(){if(I1)return hh;I1=1;var e=ly(),n=Uu(),r=ay(),i=OC(),o=Object.getOwnPropertySymbols,l=o?function(u){for(var c=[];u;)e(c,r(u)),u=n(u);return c}:i;return hh=l,hh}var ph,M1;function Yq(){if(M1)return ph;M1=1;var e=Da(),n=PC();function r(i,o){return e(i,n(i),o)}return ph=r,ph}var mh,O1;function LC(){if(O1)return mh;O1=1;var e=ly(),n=bt();function r(i,o,l){var u=o(i);return n(i)?u:e(u,l(i))}return mh=r,mh}var gh,P1;function qC(){if(P1)return gh;P1=1;var e=LC(),n=ay(),r=Ss();function i(o){return e(o,r,n)}return gh=i,gh}var vh,L1;function Kq(){if(L1)return vh;L1=1;var e=LC(),n=PC(),r=di();function i(o){return e(o,r,n)}return vh=i,vh}var yh,q1;function Xq(){if(q1)return yh;q1=1;var e=ci(),n=nr(),r=e(n,"DataView");return yh=r,yh}var wh,$1;function Qq(){if($1)return wh;$1=1;var e=ci(),n=nr(),r=e(n,"Promise");return wh=r,wh}var xh,D1;function $C(){if(D1)return xh;D1=1;var e=ci(),n=nr(),r=e(n,"Set");return xh=r,xh}var _h,F1;function Zq(){if(F1)return _h;F1=1;var e=ci(),n=nr(),r=e(n,"WeakMap");return _h=r,_h}var bh,z1;function ko(){if(z1)return bh;z1=1;var e=Xq(),n=ty(),r=Qq(),i=$C(),o=Zq(),l=ui(),u=CC(),c="[object Map]",h="[object Object]",p="[object Promise]",d="[object Set]",m="[object WeakMap]",y="[object DataView]",w=u(e),N=u(n),_=u(r),b=u(i),S=u(o),k=l;return(e&&k(new e(new ArrayBuffer(1)))!=y||n&&k(new n)!=c||r&&k(r.resolve())!=p||i&&k(new i)!=d||o&&k(new o)!=m)&&(k=function(E){var C=l(E),I=C==h?E.constructor:void 0,P=I?u(I):"";if(P)switch(P){case w:return y;case N:return c;case _:return p;case b:return d;case S:return m}return C}),bh=k,bh}var Sh,B1;function Jq(){if(B1)return Sh;B1=1;var e=Object.prototype,n=e.hasOwnProperty;function r(i){var o=i.length,l=new i.constructor(o);return o&&typeof i[0]=="string"&&n.call(i,"index")&&(l.index=i.index,l.input=i.input),l}return Sh=r,Sh}var kh,U1;function DC(){if(U1)return kh;U1=1;var e=nr(),n=e.Uint8Array;return kh=n,kh}var Eh,H1;function uy(){if(H1)return Eh;H1=1;var e=DC();function n(r){var i=new r.constructor(r.byteLength);return new e(i).set(new e(r)),i}return Eh=n,Eh}var Nh,W1;function e$(){if(W1)return Nh;W1=1;var e=uy();function n(r,i){var o=i?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.byteLength)}return Nh=n,Nh}var Ch,V1;function t$(){if(V1)return Ch;V1=1;var e=/\w*$/;function n(r){var i=new r.constructor(r.source,e.exec(r));return i.lastIndex=r.lastIndex,i}return Ch=n,Ch}var Rh,G1;function n$(){if(G1)return Rh;G1=1;var e=bo(),n=e?e.prototype:void 0,r=n?n.valueOf:void 0;function i(o){return r?Object(r.call(o)):{}}return Rh=i,Rh}var Th,Y1;function FC(){if(Y1)return Th;Y1=1;var e=uy();function n(r,i){var o=i?e(r.buffer):r.buffer;return new r.constructor(o,r.byteOffset,r.length)}return Th=n,Th}var jh,K1;function r$(){if(K1)return jh;K1=1;var e=uy(),n=e$(),r=t$(),i=n$(),o=FC(),l="[object Boolean]",u="[object Date]",c="[object Map]",h="[object Number]",p="[object RegExp]",d="[object Set]",m="[object String]",y="[object Symbol]",w="[object ArrayBuffer]",N="[object DataView]",_="[object Float32Array]",b="[object Float64Array]",S="[object Int8Array]",k="[object Int16Array]",E="[object Int32Array]",C="[object Uint8Array]",I="[object Uint8ClampedArray]",P="[object Uint16Array]",A="[object Uint32Array]";function U(L,O,q){var G=L.constructor;switch(O){case w:return e(L);case l:case u:return new G(+L);case N:return n(L,q);case _:case b:case S:case k:case E:case C:case I:case P:case A:return o(L,q);case c:return new G;case h:case m:return new G(L);case p:return r(L);case d:return new G;case y:return i(L)}}return jh=U,jh}var Ah,X1;function zC(){if(X1)return Ah;X1=1;var e=Ln(),n=Object.create,r=(function(){function i(){}return function(o){if(!e(o))return{};if(n)return n(o);i.prototype=o;var l=new i;return i.prototype=void 0,l}})();return Ah=r,Ah}var Ih,Q1;function BC(){if(Q1)return Ih;Q1=1;var e=zC(),n=Uu(),r=Bu();function i(o){return typeof o.constructor=="function"&&!r(o)?e(n(o)):{}}return Ih=i,Ih}var Mh,Z1;function s$(){if(Z1)return Mh;Z1=1;var e=ko(),n=vr(),r="[object Map]";function i(o){return n(o)&&e(o)==r}return Mh=i,Mh}var Oh,J1;function i$(){if(J1)return Oh;J1=1;var e=s$(),n=zu(),r=iy(),i=r&&r.isMap,o=i?n(i):e;return Oh=o,Oh}var Ph,eb;function o$(){if(eb)return Ph;eb=1;var e=ko(),n=vr(),r="[object Set]";function i(o){return n(o)&&e(o)==r}return Ph=i,Ph}var Lh,tb;function a$(){if(tb)return Lh;tb=1;var e=o$(),n=zu(),r=iy(),i=r&&r.isSet,o=i?n(i):e;return Lh=o,Lh}var qh,nb;function UC(){if(nb)return qh;nb=1;var e=qu(),n=ry(),r=Du(),i=Uq(),o=Vq(),l=AC(),u=IC(),c=Gq(),h=Yq(),p=qC(),d=Kq(),m=ko(),y=Jq(),w=r$(),N=BC(),_=bt(),b=So(),S=i$(),k=Ln(),E=a$(),C=Ss(),I=di(),P=1,A=2,U=4,L="[object Arguments]",O="[object Array]",q="[object Boolean]",G="[object Date]",F="[object Error]",j="[object Function]",B="[object GeneratorFunction]",z="[object Map]",ne="[object Number]",Z="[object Object]",$="[object RegExp]",Q="[object Set]",M="[object String]",V="[object Symbol]",Y="[object WeakMap]",H="[object ArrayBuffer]",J="[object DataView]",re="[object Float32Array]",le="[object Float64Array]",fe="[object Int8Array]",te="[object Int16Array]",ce="[object Int32Array]",Ce="[object Uint8Array]",ve="[object Uint8ClampedArray]",je="[object Uint16Array]",ye="[object Uint32Array]",ke={};ke[L]=ke[O]=ke[H]=ke[J]=ke[q]=ke[G]=ke[re]=ke[le]=ke[fe]=ke[te]=ke[ce]=ke[z]=ke[ne]=ke[Z]=ke[$]=ke[Q]=ke[M]=ke[V]=ke[Ce]=ke[ve]=ke[je]=ke[ye]=!0,ke[F]=ke[j]=ke[Y]=!1;function Ke(we,_e,Be,ft,ht,We){var $e,Je=_e&P,Xe=_e&A,vt=_e&U;if(Be&&($e=ht?Be(we,ft,ht,We):Be(we)),$e!==void 0)return $e;if(!k(we))return we;var ot=_(we);if(ot){if($e=y(we),!Je)return u(we,$e)}else{var yt=m(we),Gt=yt==j||yt==B;if(b(we))return l(we,Je);if(yt==Z||yt==L||Gt&&!ht){if($e=Xe||Gt?{}:N(we),!Je)return Xe?h(we,o($e,we)):c(we,i($e,we))}else{if(!ke[yt])return ht?we:{};$e=w(we,yt,Je)}}We||(We=new e);var It=We.get(we);if(It)return It;We.set(we,$e),E(we)?we.forEach(function(pt){$e.add(Ke(pt,_e,Be,pt,we,We))}):S(we)&&we.forEach(function(pt,mt){$e.set(mt,Ke(pt,_e,Be,mt,we,We))});var Ze=vt?Xe?d:p:Xe?I:C,wt=ot?void 0:Ze(we);return n(wt||we,function(pt,mt){wt&&(mt=pt,pt=we[mt]),r($e,mt,Ke(pt,_e,Be,mt,we,We))}),$e}return qh=Ke,qh}var $h,rb;function l$(){if(rb)return $h;rb=1;var e=UC(),n=4;function r(i){return e(i,n)}return $h=r,$h}var Dh,sb;function cy(){if(sb)return Dh;sb=1;function e(n){return function(){return n}}return Dh=e,Dh}var Fh,ib;function u$(){if(ib)return Fh;ib=1;function e(n){return function(r,i,o){for(var l=-1,u=Object(r),c=o(r),h=c.length;h--;){var p=c[n?h:++l];if(i(u[p],p,u)===!1)break}return r}}return Fh=e,Fh}var zh,ob;function dy(){if(ob)return zh;ob=1;var e=u$(),n=e();return zh=n,zh}var Bh,ab;function fy(){if(ab)return Bh;ab=1;var e=dy(),n=Ss();function r(i,o){return i&&e(i,o,n)}return Bh=r,Bh}var Uh,lb;function c$(){if(lb)return Uh;lb=1;var e=Wr();function n(r,i){return function(o,l){if(o==null)return o;if(!e(o))return r(o,l);for(var u=o.length,c=i?u:-1,h=Object(o);(i?c--:++c<u)&&l(h[c],c,h)!==!1;);return o}}return Uh=n,Uh}var Hh,ub;function Hu(){if(ub)return Hh;ub=1;var e=fy(),n=c$(),r=n(e);return Hh=r,Hh}var Wh,cb;function fi(){if(cb)return Wh;cb=1;function e(n){return n}return Wh=e,Wh}var Vh,db;function HC(){if(db)return Vh;db=1;var e=fi();function n(r){return typeof r=="function"?r:e}return Vh=n,Vh}var Gh,fb;function WC(){if(fb)return Gh;fb=1;var e=ry(),n=Hu(),r=HC(),i=bt();function o(l,u){var c=i(l)?e:n;return c(l,r(u))}return Gh=o,Gh}var Yh,hb;function VC(){return hb||(hb=1,Yh=WC()),Yh}var Kh,pb;function d$(){if(pb)return Kh;pb=1;var e=Hu();function n(r,i){var o=[];return e(r,function(l,u,c){i(l,u,c)&&o.push(l)}),o}return Kh=n,Kh}var Xh,mb;function f$(){if(mb)return Xh;mb=1;var e="__lodash_hash_undefined__";function n(r){return this.__data__.set(r,e),this}return Xh=n,Xh}var Qh,gb;function h$(){if(gb)return Qh;gb=1;function e(n){return this.__data__.has(n)}return Qh=e,Qh}var Zh,vb;function GC(){if(vb)return Zh;vb=1;var e=ny(),n=f$(),r=h$();function i(o){var l=-1,u=o==null?0:o.length;for(this.__data__=new e;++l<u;)this.add(o[l])}return i.prototype.add=i.prototype.push=n,i.prototype.has=r,Zh=i,Zh}var Jh,yb;function p$(){if(yb)return Jh;yb=1;function e(n,r){for(var i=-1,o=n==null?0:n.length;++i<o;)if(r(n[i],i,n))return!0;return!1}return Jh=e,Jh}var ep,wb;function YC(){if(wb)return ep;wb=1;function e(n,r){return n.has(r)}return ep=e,ep}var tp,xb;function KC(){if(xb)return tp;xb=1;var e=GC(),n=p$(),r=YC(),i=1,o=2;function l(u,c,h,p,d,m){var y=h&i,w=u.length,N=c.length;if(w!=N&&!(y&&N>w))return!1;var _=m.get(u),b=m.get(c);if(_&&b)return _==c&&b==u;var S=-1,k=!0,E=h&o?new e:void 0;for(m.set(u,c),m.set(c,u);++S<w;){var C=u[S],I=c[S];if(p)var P=y?p(I,C,S,c,u,m):p(C,I,S,u,c,m);if(P!==void 0){if(P)continue;k=!1;break}if(E){if(!n(c,function(A,U){if(!r(E,U)&&(C===A||d(C,A,h,p,m)))return E.push(U)})){k=!1;break}}else if(!(C===I||d(C,I,h,p,m))){k=!1;break}}return m.delete(u),m.delete(c),k}return tp=l,tp}var np,_b;function m$(){if(_b)return np;_b=1;function e(n){var r=-1,i=Array(n.size);return n.forEach(function(o,l){i[++r]=[l,o]}),i}return np=e,np}var rp,bb;function hy(){if(bb)return rp;bb=1;function e(n){var r=-1,i=Array(n.size);return n.forEach(function(o){i[++r]=o}),i}return rp=e,rp}var sp,Sb;function g$(){if(Sb)return sp;Sb=1;var e=bo(),n=DC(),r=_o(),i=KC(),o=m$(),l=hy(),u=1,c=2,h="[object Boolean]",p="[object Date]",d="[object Error]",m="[object Map]",y="[object Number]",w="[object RegExp]",N="[object Set]",_="[object String]",b="[object Symbol]",S="[object ArrayBuffer]",k="[object DataView]",E=e?e.prototype:void 0,C=E?E.valueOf:void 0;function I(P,A,U,L,O,q,G){switch(U){case k:if(P.byteLength!=A.byteLength||P.byteOffset!=A.byteOffset)return!1;P=P.buffer,A=A.buffer;case S:return!(P.byteLength!=A.byteLength||!q(new n(P),new n(A)));case h:case p:case y:return r(+P,+A);case d:return P.name==A.name&&P.message==A.message;case w:case _:return P==A+"";case m:var F=o;case N:var j=L&u;if(F||(F=l),P.size!=A.size&&!j)return!1;var B=G.get(P);if(B)return B==A;L|=c,G.set(P,A);var z=i(F(P),F(A),L,O,q,G);return G.delete(P),z;case b:if(C)return C.call(P)==C.call(A)}return!1}return sp=I,sp}var ip,kb;function v$(){if(kb)return ip;kb=1;var e=qC(),n=1,r=Object.prototype,i=r.hasOwnProperty;function o(l,u,c,h,p,d){var m=c&n,y=e(l),w=y.length,N=e(u),_=N.length;if(w!=_&&!m)return!1;for(var b=w;b--;){var S=y[b];if(!(m?S in u:i.call(u,S)))return!1}var k=d.get(l),E=d.get(u);if(k&&E)return k==u&&E==l;var C=!0;d.set(l,u),d.set(u,l);for(var I=m;++b<w;){S=y[b];var P=l[S],A=u[S];if(h)var U=m?h(A,P,S,u,l,d):h(P,A,S,l,u,d);if(!(U===void 0?P===A||p(P,A,c,h,d):U)){C=!1;break}I||(I=S=="constructor")}if(C&&!I){var L=l.constructor,O=u.constructor;L!=O&&"constructor"in l&&"constructor"in u&&!(typeof L=="function"&&L instanceof L&&typeof O=="function"&&O instanceof O)&&(C=!1)}return d.delete(l),d.delete(u),C}return ip=o,ip}var op,Eb;function y$(){if(Eb)return op;Eb=1;var e=qu(),n=KC(),r=g$(),i=v$(),o=ko(),l=bt(),u=So(),c=za(),h=1,p="[object Arguments]",d="[object Array]",m="[object Object]",y=Object.prototype,w=y.hasOwnProperty;function N(_,b,S,k,E,C){var I=l(_),P=l(b),A=I?d:o(_),U=P?d:o(b);A=A==p?m:A,U=U==p?m:U;var L=A==m,O=U==m,q=A==U;if(q&&u(_)){if(!u(b))return!1;I=!0,L=!1}if(q&&!L)return C||(C=new e),I||c(_)?n(_,b,S,k,E,C):r(_,b,A,S,k,E,C);if(!(S&h)){var G=L&&w.call(_,"__wrapped__"),F=O&&w.call(b,"__wrapped__");if(G||F){var j=G?_.value():_,B=F?b.value():b;return C||(C=new e),E(j,B,S,k,C)}}return q?(C||(C=new e),i(_,b,S,k,E,C)):!1}return op=N,op}var ap,Nb;function XC(){if(Nb)return ap;Nb=1;var e=y$(),n=vr();function r(i,o,l,u,c){return i===o?!0:i==null||o==null||!n(i)&&!n(o)?i!==i&&o!==o:e(i,o,l,u,r,c)}return ap=r,ap}var lp,Cb;function w$(){if(Cb)return lp;Cb=1;var e=qu(),n=XC(),r=1,i=2;function o(l,u,c,h){var p=c.length,d=p,m=!h;if(l==null)return!d;for(l=Object(l);p--;){var y=c[p];if(m&&y[2]?y[1]!==l[y[0]]:!(y[0]in l))return!1}for(;++p<d;){y=c[p];var w=y[0],N=l[w],_=y[1];if(m&&y[2]){if(N===void 0&&!(w in l))return!1}else{var b=new e;if(h)var S=h(N,_,w,l,u,b);if(!(S===void 0?n(_,N,r|i,h,b):S))return!1}}return!0}return lp=o,lp}var up,Rb;function QC(){if(Rb)return up;Rb=1;var e=Ln();function n(r){return r===r&&!e(r)}return up=n,up}var cp,Tb;function x$(){if(Tb)return cp;Tb=1;var e=QC(),n=Ss();function r(i){for(var o=n(i),l=o.length;l--;){var u=o[l],c=i[u];o[l]=[u,c,e(c)]}return o}return cp=r,cp}var dp,jb;function ZC(){if(jb)return dp;jb=1;function e(n,r){return function(i){return i==null?!1:i[n]===r&&(r!==void 0||n in Object(i))}}return dp=e,dp}var fp,Ab;function _$(){if(Ab)return fp;Ab=1;var e=w$(),n=x$(),r=ZC();function i(o){var l=n(o);return l.length==1&&l[0][2]?r(l[0][0],l[0][1]):function(u){return u===o||e(u,o,l)}}return fp=i,fp}var hp,Ib;function Eo(){if(Ib)return hp;Ib=1;var e=ui(),n=vr(),r="[object Symbol]";function i(o){return typeof o=="symbol"||n(o)&&e(o)==r}return hp=i,hp}var pp,Mb;function py(){if(Mb)return pp;Mb=1;var e=bt(),n=Eo(),r=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,i=/^\w*$/;function o(l,u){if(e(l))return!1;var c=typeof l;return c=="number"||c=="symbol"||c=="boolean"||l==null||n(l)?!0:i.test(l)||!r.test(l)||u!=null&&l in Object(u)}return pp=o,pp}var mp,Ob;function b$(){if(Ob)return mp;Ob=1;var e=ny(),n="Expected a function";function r(i,o){if(typeof i!="function"||o!=null&&typeof o!="function")throw new TypeError(n);var l=function(){var u=arguments,c=o?o.apply(this,u):u[0],h=l.cache;if(h.has(c))return h.get(c);var p=i.apply(this,u);return l.cache=h.set(c,p)||h,p};return l.cache=new(r.Cache||e),l}return r.Cache=e,mp=r,mp}var gp,Pb;function S$(){if(Pb)return gp;Pb=1;var e=b$(),n=500;function r(i){var o=e(i,function(u){return l.size===n&&l.clear(),u}),l=o.cache;return o}return gp=r,gp}var vp,Lb;function k$(){if(Lb)return vp;Lb=1;var e=S$(),n=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,r=/\\(\\)?/g,i=e(function(o){var l=[];return o.charCodeAt(0)===46&&l.push(""),o.replace(n,function(u,c,h,p){l.push(h?p.replace(r,"$1"):c||u)}),l});return vp=i,vp}var yp,qb;function Wu(){if(qb)return yp;qb=1;function e(n,r){for(var i=-1,o=n==null?0:n.length,l=Array(o);++i<o;)l[i]=r(n[i],i,n);return l}return yp=e,yp}var wp,$b;function E$(){if($b)return wp;$b=1;var e=bo(),n=Wu(),r=bt(),i=Eo(),o=e?e.prototype:void 0,l=o?o.toString:void 0;function u(c){if(typeof c=="string")return c;if(r(c))return n(c,u)+"";if(i(c))return l?l.call(c):"";var h=c+"";return h=="0"&&1/c==-1/0?"-0":h}return wp=u,wp}var xp,Db;function JC(){if(Db)return xp;Db=1;var e=E$();function n(r){return r==null?"":e(r)}return xp=n,xp}var _p,Fb;function Vu(){if(Fb)return _p;Fb=1;var e=bt(),n=py(),r=k$(),i=JC();function o(l,u){return e(l)?l:n(l,u)?[l]:r(i(l))}return _p=o,_p}var bp,zb;function Ba(){if(zb)return bp;zb=1;var e=Eo();function n(r){if(typeof r=="string"||e(r))return r;var i=r+"";return i=="0"&&1/r==-1/0?"-0":i}return bp=n,bp}var Sp,Bb;function Gu(){if(Bb)return Sp;Bb=1;var e=Vu(),n=Ba();function r(i,o){o=e(o,i);for(var l=0,u=o.length;i!=null&&l<u;)i=i[n(o[l++])];return l&&l==u?i:void 0}return Sp=r,Sp}var kp,Ub;function N$(){if(Ub)return kp;Ub=1;var e=Gu();function n(r,i,o){var l=r==null?void 0:e(r,i);return l===void 0?o:l}return kp=n,kp}var Ep,Hb;function C$(){if(Hb)return Ep;Hb=1;function e(n,r){return n!=null&&r in Object(n)}return Ep=e,Ep}var Np,Wb;function eR(){if(Wb)return Np;Wb=1;var e=Vu(),n=Fa(),r=bt(),i=Fu(),o=sy(),l=Ba();function u(c,h,p){h=e(h,c);for(var d=-1,m=h.length,y=!1;++d<m;){var w=l(h[d]);if(!(y=c!=null&&p(c,w)))break;c=c[w]}return y||++d!=m?y:(m=c==null?0:c.length,!!m&&o(m)&&i(w,m)&&(r(c)||n(c)))}return Np=u,Np}var Cp,Vb;function tR(){if(Vb)return Cp;Vb=1;var e=C$(),n=eR();function r(i,o){return i!=null&&n(i,o,e)}return Cp=r,Cp}var Rp,Gb;function R$(){if(Gb)return Rp;Gb=1;var e=XC(),n=N$(),r=tR(),i=py(),o=QC(),l=ZC(),u=Ba(),c=1,h=2;function p(d,m){return i(d)&&o(m)?l(u(d),m):function(y){var w=n(y,d);return w===void 0&&w===m?r(y,d):e(m,w,c|h)}}return Rp=p,Rp}var Tp,Yb;function nR(){if(Yb)return Tp;Yb=1;function e(n){return function(r){return r==null?void 0:r[n]}}return Tp=e,Tp}var jp,Kb;function T$(){if(Kb)return jp;Kb=1;var e=Gu();function n(r){return function(i){return e(i,r)}}return jp=n,jp}var Ap,Xb;function j$(){if(Xb)return Ap;Xb=1;var e=nR(),n=T$(),r=py(),i=Ba();function o(l){return r(l)?e(i(l)):n(l)}return Ap=o,Ap}var Ip,Qb;function Vr(){if(Qb)return Ip;Qb=1;var e=_$(),n=R$(),r=fi(),i=bt(),o=j$();function l(u){return typeof u=="function"?u:u==null?r:typeof u=="object"?i(u)?n(u[0],u[1]):e(u):o(u)}return Ip=l,Ip}var Mp,Zb;function rR(){if(Zb)return Mp;Zb=1;var e=MC(),n=d$(),r=Vr(),i=bt();function o(l,u){var c=i(l)?e:n;return c(l,r(u,3))}return Mp=o,Mp}var Op,Jb;function A$(){if(Jb)return Op;Jb=1;var e=Object.prototype,n=e.hasOwnProperty;function r(i,o){return i!=null&&n.call(i,o)}return Op=r,Op}var Pp,eS;function sR(){if(eS)return Pp;eS=1;var e=A$(),n=eR();function r(i,o){return i!=null&&n(i,o,e)}return Pp=r,Pp}var Lp,tS;function I$(){if(tS)return Lp;tS=1;var e=oy(),n=ko(),r=Fa(),i=bt(),o=Wr(),l=So(),u=Bu(),c=za(),h="[object Map]",p="[object Set]",d=Object.prototype,m=d.hasOwnProperty;function y(w){if(w==null)return!0;if(o(w)&&(i(w)||typeof w=="string"||typeof w.splice=="function"||l(w)||c(w)||r(w)))return!w.length;var N=n(w);if(N==h||N==p)return!w.size;if(u(w))return!e(w).length;for(var _ in w)if(m.call(w,_))return!1;return!0}return Lp=y,Lp}var qp,nS;function iR(){if(nS)return qp;nS=1;function e(n){return n===void 0}return qp=e,qp}var $p,rS;function oR(){if(rS)return $p;rS=1;var e=Hu(),n=Wr();function r(i,o){var l=-1,u=n(i)?Array(i.length):[];return e(i,function(c,h,p){u[++l]=o(c,h,p)}),u}return $p=r,$p}var Dp,sS;function aR(){if(sS)return Dp;sS=1;var e=Wu(),n=Vr(),r=oR(),i=bt();function o(l,u){var c=i(l)?e:r;return c(l,n(u,3))}return Dp=o,Dp}var Fp,iS;function M$(){if(iS)return Fp;iS=1;function e(n,r,i,o){var l=-1,u=n==null?0:n.length;for(o&&u&&(i=n[++l]);++l<u;)i=r(i,n[l],l,n);return i}return Fp=e,Fp}var zp,oS;function O$(){if(oS)return zp;oS=1;function e(n,r,i,o,l){return l(n,function(u,c,h){i=o?(o=!1,u):r(i,u,c,h)}),i}return zp=e,zp}var Bp,aS;function lR(){if(aS)return Bp;aS=1;var e=M$(),n=Hu(),r=Vr(),i=O$(),o=bt();function l(u,c,h){var p=o(u)?e:i,d=arguments.length<3;return p(u,r(c,4),h,d,n)}return Bp=l,Bp}var Up,lS;function P$(){if(lS)return Up;lS=1;var e=ui(),n=bt(),r=vr(),i="[object String]";function o(l){return typeof l=="string"||!n(l)&&r(l)&&e(l)==i}return Up=o,Up}var Hp,uS;function L$(){if(uS)return Hp;uS=1;var e=nR(),n=e("length");return Hp=n,Hp}var Wp,cS;function q$(){if(cS)return Wp;cS=1;var e="\\ud800-\\udfff",n="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",i="\\u20d0-\\u20ff",o=n+r+i,l="\\ufe0e\\ufe0f",u="\\u200d",c=RegExp("["+u+e+o+l+"]");function h(p){return c.test(p)}return Wp=h,Wp}var Vp,dS;function $$(){if(dS)return Vp;dS=1;var e="\\ud800-\\udfff",n="\\u0300-\\u036f",r="\\ufe20-\\ufe2f",i="\\u20d0-\\u20ff",o=n+r+i,l="\\ufe0e\\ufe0f",u="["+e+"]",c="["+o+"]",h="\\ud83c[\\udffb-\\udfff]",p="(?:"+c+"|"+h+")",d="[^"+e+"]",m="(?:\\ud83c[\\udde6-\\uddff]){2}",y="[\\ud800-\\udbff][\\udc00-\\udfff]",w="\\u200d",N=p+"?",_="["+l+"]?",b="(?:"+w+"(?:"+[d,m,y].join("|")+")"+_+N+")*",S=_+N+b,k="(?:"+[d+c+"?",c,m,y,u].join("|")+")",E=RegExp(h+"(?="+h+")|"+k+S,"g");function C(I){for(var P=E.lastIndex=0;E.test(I);)++P;return P}return Vp=C,Vp}var Gp,fS;function D$(){if(fS)return Gp;fS=1;var e=L$(),n=q$(),r=$$();function i(o){return n(o)?r(o):e(o)}return Gp=i,Gp}var Yp,hS;function F$(){if(hS)return Yp;hS=1;var e=oy(),n=ko(),r=Wr(),i=P$(),o=D$(),l="[object Map]",u="[object Set]";function c(h){if(h==null)return 0;if(r(h))return i(h)?o(h):h.length;var p=n(h);return p==l||p==u?h.size:e(h).length}return Yp=c,Yp}var Kp,pS;function z$(){if(pS)return Kp;pS=1;var e=ry(),n=zC(),r=fy(),i=Vr(),o=Uu(),l=bt(),u=So(),c=$a(),h=Ln(),p=za();function d(m,y,w){var N=l(m),_=N||u(m)||p(m);if(y=i(y,4),w==null){var b=m&&m.constructor;_?w=N?new b:[]:h(m)?w=c(b)?n(o(m)):{}:w={}}return(_?e:r)(m,function(S,k,E){return y(w,S,k,E)}),w}return Kp=d,Kp}var Xp,mS;function B$(){if(mS)return Xp;mS=1;var e=bo(),n=Fa(),r=bt(),i=e?e.isConcatSpreadable:void 0;function o(l){return r(l)||n(l)||!!(i&&l&&l[i])}return Xp=o,Xp}var Qp,gS;function my(){if(gS)return Qp;gS=1;var e=ly(),n=B$();function r(i,o,l,u,c){var h=-1,p=i.length;for(l||(l=n),c||(c=[]);++h<p;){var d=i[h];o>0&&l(d)?o>1?r(d,o-1,l,u,c):e(c,d):u||(c[c.length]=d)}return c}return Qp=r,Qp}var Zp,vS;function U$(){if(vS)return Zp;vS=1;function e(n,r,i){switch(i.length){case 0:return n.call(r);case 1:return n.call(r,i[0]);case 2:return n.call(r,i[0],i[1]);case 3:return n.call(r,i[0],i[1],i[2])}return n.apply(r,i)}return Zp=e,Zp}var Jp,yS;function uR(){if(yS)return Jp;yS=1;var e=U$(),n=Math.max;function r(i,o,l){return o=n(o===void 0?i.length-1:o,0),function(){for(var u=arguments,c=-1,h=n(u.length-o,0),p=Array(h);++c<h;)p[c]=u[o+c];c=-1;for(var d=Array(o+1);++c<o;)d[c]=u[c];return d[o]=l(p),e(i,this,d)}}return Jp=r,Jp}var em,wS;function H$(){if(wS)return em;wS=1;var e=cy(),n=RC(),r=fi(),i=n?function(o,l){return n(o,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:r;return em=i,em}var tm,xS;function W$(){if(xS)return tm;xS=1;var e=800,n=16,r=Date.now;function i(o){var l=0,u=0;return function(){var c=r(),h=n-(c-u);if(u=c,h>0){if(++l>=e)return arguments[0]}else l=0;return o.apply(void 0,arguments)}}return tm=i,tm}var nm,_S;function cR(){if(_S)return nm;_S=1;var e=H$(),n=W$(),r=n(e);return nm=r,nm}var rm,bS;function Yu(){if(bS)return rm;bS=1;var e=fi(),n=uR(),r=cR();function i(o,l){return r(n(o,l,e),o+"")}return rm=i,rm}var sm,SS;function dR(){if(SS)return sm;SS=1;function e(n,r,i,o){for(var l=n.length,u=i+(o?1:-1);o?u--:++u<l;)if(r(n[u],u,n))return u;return-1}return sm=e,sm}var im,kS;function V$(){if(kS)return im;kS=1;function e(n){return n!==n}return im=e,im}var om,ES;function G$(){if(ES)return om;ES=1;function e(n,r,i){for(var o=i-1,l=n.length;++o<l;)if(n[o]===r)return o;return-1}return om=e,om}var am,NS;function Y$(){if(NS)return am;NS=1;var e=dR(),n=V$(),r=G$();function i(o,l,u){return l===l?r(o,l,u):e(o,n,u)}return am=i,am}var lm,CS;function K$(){if(CS)return lm;CS=1;var e=Y$();function n(r,i){var o=r==null?0:r.length;return!!o&&e(r,i,0)>-1}return lm=n,lm}var um,RS;function X$(){if(RS)return um;RS=1;function e(n,r,i){for(var o=-1,l=n==null?0:n.length;++o<l;)if(i(r,n[o]))return!0;return!1}return um=e,um}var cm,TS;function Q$(){if(TS)return cm;TS=1;function e(){}return cm=e,cm}var dm,jS;function Z$(){if(jS)return dm;jS=1;var e=$C(),n=Q$(),r=hy(),i=1/0,o=e&&1/r(new e([,-0]))[1]==i?function(l){return new e(l)}:n;return dm=o,dm}var fm,AS;function J$(){if(AS)return fm;AS=1;var e=GC(),n=K$(),r=X$(),i=YC(),o=Z$(),l=hy(),u=200;function c(h,p,d){var m=-1,y=n,w=h.length,N=!0,_=[],b=_;if(d)N=!1,y=r;else if(w>=u){var S=p?null:o(h);if(S)return l(S);N=!1,y=i,b=new e}else b=p?[]:_;e:for(;++m<w;){var k=h[m],E=p?p(k):k;if(k=d||k!==0?k:0,N&&E===E){for(var C=b.length;C--;)if(b[C]===E)continue e;p&&b.push(E),_.push(k)}else y(b,E,d)||(b!==_&&b.push(E),_.push(k))}return _}return fm=c,fm}var hm,IS;function fR(){if(IS)return hm;IS=1;var e=Wr(),n=vr();function r(i){return n(i)&&e(i)}return hm=r,hm}var pm,MS;function e4(){if(MS)return pm;MS=1;var e=my(),n=Yu(),r=J$(),i=fR(),o=n(function(l){return r(e(l,1,i,!0))});return pm=o,pm}var mm,OS;function t4(){if(OS)return mm;OS=1;var e=Wu();function n(r,i){return e(i,function(o){return r[o]})}return mm=n,mm}var gm,PS;function hR(){if(PS)return gm;PS=1;var e=t4(),n=Ss();function r(i){return i==null?[]:e(i,n(i))}return gm=r,gm}var vm,LS;function qn(){if(LS)return vm;LS=1;var e;if(typeof ey=="function")try{e={clone:l$(),constant:cy(),each:VC(),filter:rR(),has:sR(),isArray:bt(),isEmpty:I$(),isFunction:$a(),isUndefined:iR(),keys:Ss(),map:aR(),reduce:lR(),size:F$(),transform:z$(),union:e4(),values:hR()}}catch{}return e||(e=window._),vm=e,vm}var ym,qS;function gy(){if(qS)return ym;qS=1;var e=qn();ym=o;var n="\0",r="\0",i="";function o(d){this._isDirected=e.has(d,"directed")?d.directed:!0,this._isMultigraph=e.has(d,"multigraph")?d.multigraph:!1,this._isCompound=e.has(d,"compound")?d.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[r]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}o.prototype._nodeCount=0,o.prototype._edgeCount=0,o.prototype.isDirected=function(){return this._isDirected},o.prototype.isMultigraph=function(){return this._isMultigraph},o.prototype.isCompound=function(){return this._isCompound},o.prototype.setGraph=function(d){return this._label=d,this},o.prototype.graph=function(){return this._label},o.prototype.setDefaultNodeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultNodeLabelFn=d,this},o.prototype.nodeCount=function(){return this._nodeCount},o.prototype.nodes=function(){return e.keys(this._nodes)},o.prototype.sources=function(){var d=this;return e.filter(this.nodes(),function(m){return e.isEmpty(d._in[m])})},o.prototype.sinks=function(){var d=this;return e.filter(this.nodes(),function(m){return e.isEmpty(d._out[m])})},o.prototype.setNodes=function(d,m){var y=arguments,w=this;return e.each(d,function(N){y.length>1?w.setNode(N,m):w.setNode(N)}),this},o.prototype.setNode=function(d,m){return e.has(this._nodes,d)?(arguments.length>1&&(this._nodes[d]=m),this):(this._nodes[d]=arguments.length>1?m:this._defaultNodeLabelFn(d),this._isCompound&&(this._parent[d]=r,this._children[d]={},this._children[r][d]=!0),this._in[d]={},this._preds[d]={},this._out[d]={},this._sucs[d]={},++this._nodeCount,this)},o.prototype.node=function(d){return this._nodes[d]},o.prototype.hasNode=function(d){return e.has(this._nodes,d)},o.prototype.removeNode=function(d){var m=this;if(e.has(this._nodes,d)){var y=function(w){m.removeEdge(m._edgeObjs[w])};delete this._nodes[d],this._isCompound&&(this._removeFromParentsChildList(d),delete this._parent[d],e.each(this.children(d),function(w){m.setParent(w)}),delete this._children[d]),e.each(e.keys(this._in[d]),y),delete this._in[d],delete this._preds[d],e.each(e.keys(this._out[d]),y),delete this._out[d],delete this._sucs[d],--this._nodeCount}return this},o.prototype.setParent=function(d,m){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(m))m=r;else{m+="";for(var y=m;!e.isUndefined(y);y=this.parent(y))if(y===d)throw new Error("Setting "+m+" as parent of "+d+" would create a cycle");this.setNode(m)}return this.setNode(d),this._removeFromParentsChildList(d),this._parent[d]=m,this._children[m][d]=!0,this},o.prototype._removeFromParentsChildList=function(d){delete this._children[this._parent[d]][d]},o.prototype.parent=function(d){if(this._isCompound){var m=this._parent[d];if(m!==r)return m}},o.prototype.children=function(d){if(e.isUndefined(d)&&(d=r),this._isCompound){var m=this._children[d];if(m)return e.keys(m)}else{if(d===r)return this.nodes();if(this.hasNode(d))return[]}},o.prototype.predecessors=function(d){var m=this._preds[d];if(m)return e.keys(m)},o.prototype.successors=function(d){var m=this._sucs[d];if(m)return e.keys(m)},o.prototype.neighbors=function(d){var m=this.predecessors(d);if(m)return e.union(m,this.successors(d))},o.prototype.isLeaf=function(d){var m;return this.isDirected()?m=this.successors(d):m=this.neighbors(d),m.length===0},o.prototype.filterNodes=function(d){var m=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});m.setGraph(this.graph());var y=this;e.each(this._nodes,function(_,b){d(b)&&m.setNode(b,_)}),e.each(this._edgeObjs,function(_){m.hasNode(_.v)&&m.hasNode(_.w)&&m.setEdge(_,y.edge(_))});var w={};function N(_){var b=y.parent(_);return b===void 0||m.hasNode(b)?(w[_]=b,b):b in w?w[b]:N(b)}return this._isCompound&&e.each(m.nodes(),function(_){m.setParent(_,N(_))}),m},o.prototype.setDefaultEdgeLabel=function(d){return e.isFunction(d)||(d=e.constant(d)),this._defaultEdgeLabelFn=d,this},o.prototype.edgeCount=function(){return this._edgeCount},o.prototype.edges=function(){return e.values(this._edgeObjs)},o.prototype.setPath=function(d,m){var y=this,w=arguments;return e.reduce(d,function(N,_){return w.length>1?y.setEdge(N,_,m):y.setEdge(N,_),_}),this},o.prototype.setEdge=function(){var d,m,y,w,N=!1,_=arguments[0];typeof _=="object"&&_!==null&&"v"in _?(d=_.v,m=_.w,y=_.name,arguments.length===2&&(w=arguments[1],N=!0)):(d=_,m=arguments[1],y=arguments[3],arguments.length>2&&(w=arguments[2],N=!0)),d=""+d,m=""+m,e.isUndefined(y)||(y=""+y);var b=c(this._isDirected,d,m,y);if(e.has(this._edgeLabels,b))return N&&(this._edgeLabels[b]=w),this;if(!e.isUndefined(y)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(d),this.setNode(m),this._edgeLabels[b]=N?w:this._defaultEdgeLabelFn(d,m,y);var S=h(this._isDirected,d,m,y);return d=S.v,m=S.w,Object.freeze(S),this._edgeObjs[b]=S,l(this._preds[m],d),l(this._sucs[d],m),this._in[m][b]=S,this._out[d][b]=S,this._edgeCount++,this},o.prototype.edge=function(d,m,y){var w=arguments.length===1?p(this._isDirected,arguments[0]):c(this._isDirected,d,m,y);return this._edgeLabels[w]},o.prototype.hasEdge=function(d,m,y){var w=arguments.length===1?p(this._isDirected,arguments[0]):c(this._isDirected,d,m,y);return e.has(this._edgeLabels,w)},o.prototype.removeEdge=function(d,m,y){var w=arguments.length===1?p(this._isDirected,arguments[0]):c(this._isDirected,d,m,y),N=this._edgeObjs[w];return N&&(d=N.v,m=N.w,delete this._edgeLabels[w],delete this._edgeObjs[w],u(this._preds[m],d),u(this._sucs[d],m),delete this._in[m][w],delete this._out[d][w],this._edgeCount--),this},o.prototype.inEdges=function(d,m){var y=this._in[d];if(y){var w=e.values(y);return m?e.filter(w,function(N){return N.v===m}):w}},o.prototype.outEdges=function(d,m){var y=this._out[d];if(y){var w=e.values(y);return m?e.filter(w,function(N){return N.w===m}):w}},o.prototype.nodeEdges=function(d,m){var y=this.inEdges(d,m);if(y)return y.concat(this.outEdges(d,m))};function l(d,m){d[m]?d[m]++:d[m]=1}function u(d,m){--d[m]||delete d[m]}function c(d,m,y,w){var N=""+m,_=""+y;if(!d&&N>_){var b=N;N=_,_=b}return N+i+_+i+(e.isUndefined(w)?n:w)}function h(d,m,y,w){var N=""+m,_=""+y;if(!d&&N>_){var b=N;N=_,_=b}var S={v:N,w:_};return w&&(S.name=w),S}function p(d,m){return c(d,m.v,m.w,m.name)}return ym}var wm,$S;function n4(){return $S||($S=1,wm="2.1.8"),wm}var xm,DS;function r4(){return DS||(DS=1,xm={Graph:gy(),version:n4()}),xm}var _m,FS;function s4(){if(FS)return _m;FS=1;var e=qn(),n=gy();_m={write:r,read:l};function r(u){var c={options:{directed:u.isDirected(),multigraph:u.isMultigraph(),compound:u.isCompound()},nodes:i(u),edges:o(u)};return e.isUndefined(u.graph())||(c.value=e.clone(u.graph())),c}function i(u){return e.map(u.nodes(),function(c){var h=u.node(c),p=u.parent(c),d={v:c};return e.isUndefined(h)||(d.value=h),e.isUndefined(p)||(d.parent=p),d})}function o(u){return e.map(u.edges(),function(c){var h=u.edge(c),p={v:c.v,w:c.w};return e.isUndefined(c.name)||(p.name=c.name),e.isUndefined(h)||(p.value=h),p})}function l(u){var c=new n(u.options).setGraph(u.value);return e.each(u.nodes,function(h){c.setNode(h.v,h.value),h.parent&&c.setParent(h.v,h.parent)}),e.each(u.edges,function(h){c.setEdge({v:h.v,w:h.w,name:h.name},h.value)}),c}return _m}var bm,zS;function i4(){if(zS)return bm;zS=1;var e=qn();bm=n;function n(r){var i={},o=[],l;function u(c){e.has(i,c)||(i[c]=!0,l.push(c),e.each(r.successors(c),u),e.each(r.predecessors(c),u))}return e.each(r.nodes(),function(c){l=[],u(c),l.length&&o.push(l)}),o}return bm}var Sm,BS;function pR(){if(BS)return Sm;BS=1;var e=qn();Sm=n;function n(){this._arr=[],this._keyIndices={}}return n.prototype.size=function(){return this._arr.length},n.prototype.keys=function(){return this._arr.map(function(r){return r.key})},n.prototype.has=function(r){return e.has(this._keyIndices,r)},n.prototype.priority=function(r){var i=this._keyIndices[r];if(i!==void 0)return this._arr[i].priority},n.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},n.prototype.add=function(r,i){var o=this._keyIndices;if(r=String(r),!e.has(o,r)){var l=this._arr,u=l.length;return o[r]=u,l.push({key:r,priority:i}),this._decrease(u),!0}return!1},n.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var r=this._arr.pop();return delete this._keyIndices[r.key],this._heapify(0),r.key},n.prototype.decrease=function(r,i){var o=this._keyIndices[r];if(i>this._arr[o].priority)throw new Error("New priority is greater than current priority. Key: "+r+" Old: "+this._arr[o].priority+" New: "+i);this._arr[o].priority=i,this._decrease(o)},n.prototype._heapify=function(r){var i=this._arr,o=2*r,l=o+1,u=r;o<i.length&&(u=i[o].priority<i[u].priority?o:u,l<i.length&&(u=i[l].priority<i[u].priority?l:u),u!==r&&(this._swap(r,u),this._heapify(u)))},n.prototype._decrease=function(r){for(var i=this._arr,o=i[r].priority,l;r!==0&&(l=r>>1,!(i[l].priority<o));)this._swap(r,l),r=l},n.prototype._swap=function(r,i){var o=this._arr,l=this._keyIndices,u=o[r],c=o[i];o[r]=c,o[i]=u,l[c.key]=r,l[u.key]=i},Sm}var km,US;function mR(){if(US)return km;US=1;var e=qn(),n=pR();km=i;var r=e.constant(1);function i(l,u,c,h){return o(l,String(u),c||r,h||function(p){return l.outEdges(p)})}function o(l,u,c,h){var p={},d=new n,m,y,w=function(N){var _=N.v!==m?N.v:N.w,b=p[_],S=c(N),k=y.distance+S;if(S<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+N+" Weight: "+S);k<b.distance&&(b.distance=k,b.predecessor=m,d.decrease(_,k))};for(l.nodes().forEach(function(N){var _=N===u?0:Number.POSITIVE_INFINITY;p[N]={distance:_},d.add(N,_)});d.size()>0&&(m=d.removeMin(),y=p[m],y.distance!==Number.POSITIVE_INFINITY);)h(m).forEach(w);return p}return km}var Em,HS;function o4(){if(HS)return Em;HS=1;var e=mR(),n=qn();Em=r;function r(i,o,l){return n.transform(i.nodes(),function(u,c){u[c]=e(i,c,o,l)},{})}return Em}var Nm,WS;function gR(){if(WS)return Nm;WS=1;var e=qn();Nm=n;function n(r){var i=0,o=[],l={},u=[];function c(h){var p=l[h]={onStack:!0,lowlink:i,index:i++};if(o.push(h),r.successors(h).forEach(function(y){e.has(l,y)?l[y].onStack&&(p.lowlink=Math.min(p.lowlink,l[y].index)):(c(y),p.lowlink=Math.min(p.lowlink,l[y].lowlink))}),p.lowlink===p.index){var d=[],m;do m=o.pop(),l[m].onStack=!1,d.push(m);while(h!==m);u.push(d)}}return r.nodes().forEach(function(h){e.has(l,h)||c(h)}),u}return Nm}var Cm,VS;function a4(){if(VS)return Cm;VS=1;var e=qn(),n=gR();Cm=r;function r(i){return e.filter(n(i),function(o){return o.length>1||o.length===1&&i.hasEdge(o[0],o[0])})}return Cm}var Rm,GS;function l4(){if(GS)return Rm;GS=1;var e=qn();Rm=r;var n=e.constant(1);function r(o,l,u){return i(o,l||n,u||function(c){return o.outEdges(c)})}function i(o,l,u){var c={},h=o.nodes();return h.forEach(function(p){c[p]={},c[p][p]={distance:0},h.forEach(function(d){p!==d&&(c[p][d]={distance:Number.POSITIVE_INFINITY})}),u(p).forEach(function(d){var m=d.v===p?d.w:d.v,y=l(d);c[p][m]={distance:y,predecessor:p}})}),h.forEach(function(p){var d=c[p];h.forEach(function(m){var y=c[m];h.forEach(function(w){var N=y[p],_=d[w],b=y[w],S=N.distance+_.distance;S<b.distance&&(b.distance=S,b.predecessor=_.predecessor)})})}),c}return Rm}var Tm,YS;function vR(){if(YS)return Tm;YS=1;var e=qn();Tm=n,n.CycleException=r;function n(i){var o={},l={},u=[];function c(h){if(e.has(l,h))throw new r;e.has(o,h)||(l[h]=!0,o[h]=!0,e.each(i.predecessors(h),c),delete l[h],u.push(h))}if(e.each(i.sinks(),c),e.size(o)!==i.nodeCount())throw new r;return u}function r(){}return r.prototype=new Error,Tm}var jm,KS;function u4(){if(KS)return jm;KS=1;var e=vR();jm=n;function n(r){try{e(r)}catch(i){if(i instanceof e.CycleException)return!1;throw i}return!0}return jm}var Am,XS;function yR(){if(XS)return Am;XS=1;var e=qn();Am=n;function n(i,o,l){e.isArray(o)||(o=[o]);var u=(i.isDirected()?i.successors:i.neighbors).bind(i),c=[],h={};return e.each(o,function(p){if(!i.hasNode(p))throw new Error("Graph does not have node: "+p);r(i,p,l==="post",h,u,c)}),c}function r(i,o,l,u,c,h){e.has(u,o)||(u[o]=!0,l||h.push(o),e.each(c(o),function(p){r(i,p,l,u,c,h)}),l&&h.push(o))}return Am}var Im,QS;function c4(){if(QS)return Im;QS=1;var e=yR();Im=n;function n(r,i){return e(r,i,"post")}return Im}var Mm,ZS;function d4(){if(ZS)return Mm;ZS=1;var e=yR();Mm=n;function n(r,i){return e(r,i,"pre")}return Mm}var Om,JS;function f4(){if(JS)return Om;JS=1;var e=qn(),n=gy(),r=pR();Om=i;function i(o,l){var u=new n,c={},h=new r,p;function d(y){var w=y.v===p?y.w:y.v,N=h.priority(w);if(N!==void 0){var _=l(y);_<N&&(c[w]=p,h.decrease(w,_))}}if(o.nodeCount()===0)return u;e.each(o.nodes(),function(y){h.add(y,Number.POSITIVE_INFINITY),u.setNode(y)}),h.decrease(o.nodes()[0],0);for(var m=!1;h.size()>0;){if(p=h.removeMin(),e.has(c,p))u.setEdge(p,c[p]);else{if(m)throw new Error("Input graph is not connected: "+o);m=!0}o.nodeEdges(p).forEach(d)}return u}return Om}var Pm,ek;function h4(){return ek||(ek=1,Pm={components:i4(),dijkstra:mR(),dijkstraAll:o4(),findCycles:a4(),floydWarshall:l4(),isAcyclic:u4(),postorder:c4(),preorder:d4(),prim:f4(),tarjan:gR(),topsort:vR()}),Pm}var Lm,tk;function p4(){if(tk)return Lm;tk=1;var e=r4();return Lm={Graph:e.Graph,json:s4(),alg:h4(),version:e.version},Lm}var qm,nk;function er(){if(nk)return qm;nk=1;var e;if(typeof ey=="function")try{e=p4()}catch{}return e||(e=window.graphlib),qm=e,qm}var $m,rk;function m4(){if(rk)return $m;rk=1;var e=UC(),n=1,r=4;function i(o){return e(o,n|r)}return $m=i,$m}var Dm,sk;function Ku(){if(sk)return Dm;sk=1;var e=_o(),n=Wr(),r=Fu(),i=Ln();function o(l,u,c){if(!i(c))return!1;var h=typeof u;return(h=="number"?n(c)&&r(u,c.length):h=="string"&&u in c)?e(c[u],l):!1}return Dm=o,Dm}var Fm,ik;function g4(){if(ik)return Fm;ik=1;var e=Yu(),n=_o(),r=Ku(),i=di(),o=Object.prototype,l=o.hasOwnProperty,u=e(function(c,h){c=Object(c);var p=-1,d=h.length,m=d>2?h[2]:void 0;for(m&&r(h[0],h[1],m)&&(d=1);++p<d;)for(var y=h[p],w=i(y),N=-1,_=w.length;++N<_;){var b=w[N],S=c[b];(S===void 0||n(S,o[b])&&!l.call(c,b))&&(c[b]=y[b])}return c});return Fm=u,Fm}var zm,ok;function v4(){if(ok)return zm;ok=1;var e=Vr(),n=Wr(),r=Ss();function i(o){return function(l,u,c){var h=Object(l);if(!n(l)){var p=e(u,3);l=r(l),u=function(m){return p(h[m],m,h)}}var d=o(l,u,c);return d>-1?h[p?l[d]:d]:void 0}}return zm=i,zm}var Bm,ak;function y4(){if(ak)return Bm;ak=1;var e=/\s/;function n(r){for(var i=r.length;i--&&e.test(r.charAt(i)););return i}return Bm=n,Bm}var Um,lk;function w4(){if(lk)return Um;lk=1;var e=y4(),n=/^\s+/;function r(i){return i&&i.slice(0,e(i)+1).replace(n,"")}return Um=r,Um}var Hm,uk;function x4(){if(uk)return Hm;uk=1;var e=w4(),n=Ln(),r=Eo(),i=NaN,o=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,u=/^0o[0-7]+$/i,c=parseInt;function h(p){if(typeof p=="number")return p;if(r(p))return i;if(n(p)){var d=typeof p.valueOf=="function"?p.valueOf():p;p=n(d)?d+"":d}if(typeof p!="string")return p===0?p:+p;p=e(p);var m=l.test(p);return m||u.test(p)?c(p.slice(2),m?2:8):o.test(p)?i:+p}return Hm=h,Hm}var Wm,ck;function wR(){if(ck)return Wm;ck=1;var e=x4(),n=1/0,r=17976931348623157e292;function i(o){if(!o)return o===0?o:0;if(o=e(o),o===n||o===-n){var l=o<0?-1:1;return l*r}return o===o?o:0}return Wm=i,Wm}var Vm,dk;function _4(){if(dk)return Vm;dk=1;var e=wR();function n(r){var i=e(r),o=i%1;return i===i?o?i-o:i:0}return Vm=n,Vm}var Gm,fk;function b4(){if(fk)return Gm;fk=1;var e=dR(),n=Vr(),r=_4(),i=Math.max;function o(l,u,c){var h=l==null?0:l.length;if(!h)return-1;var p=c==null?0:r(c);return p<0&&(p=i(h+p,0)),e(l,n(u,3),p)}return Gm=o,Gm}var Ym,hk;function S4(){if(hk)return Ym;hk=1;var e=v4(),n=b4(),r=e(n);return Ym=r,Ym}var Km,pk;function xR(){if(pk)return Km;pk=1;var e=my();function n(r){var i=r==null?0:r.length;return i?e(r,1):[]}return Km=n,Km}var Xm,mk;function k4(){if(mk)return Xm;mk=1;var e=dy(),n=HC(),r=di();function i(o,l){return o==null?o:e(o,n(l),r)}return Xm=i,Xm}var Qm,gk;function E4(){if(gk)return Qm;gk=1;function e(n){var r=n==null?0:n.length;return r?n[r-1]:void 0}return Qm=e,Qm}var Zm,vk;function N4(){if(vk)return Zm;vk=1;var e=$u(),n=fy(),r=Vr();function i(o,l){var u={};return l=r(l,3),n(o,function(c,h,p){e(u,h,l(c,h,p))}),u}return Zm=i,Zm}var Jm,yk;function vy(){if(yk)return Jm;yk=1;var e=Eo();function n(r,i,o){for(var l=-1,u=r.length;++l<u;){var c=r[l],h=i(c);if(h!=null&&(p===void 0?h===h&&!e(h):o(h,p)))var p=h,d=c}return d}return Jm=n,Jm}var eg,wk;function C4(){if(wk)return eg;wk=1;function e(n,r){return n>r}return eg=e,eg}var tg,xk;function R4(){if(xk)return tg;xk=1;var e=vy(),n=C4(),r=fi();function i(o){return o&&o.length?e(o,r,n):void 0}return tg=i,tg}var ng,_k;function _R(){if(_k)return ng;_k=1;var e=$u(),n=_o();function r(i,o,l){(l!==void 0&&!n(i[o],l)||l===void 0&&!(o in i))&&e(i,o,l)}return ng=r,ng}var rg,bk;function T4(){if(bk)return rg;bk=1;var e=ui(),n=Uu(),r=vr(),i="[object Object]",o=Function.prototype,l=Object.prototype,u=o.toString,c=l.hasOwnProperty,h=u.call(Object);function p(d){if(!r(d)||e(d)!=i)return!1;var m=n(d);if(m===null)return!0;var y=c.call(m,"constructor")&&m.constructor;return typeof y=="function"&&y instanceof y&&u.call(y)==h}return rg=p,rg}var sg,Sk;function bR(){if(Sk)return sg;Sk=1;function e(n,r){if(!(r==="constructor"&&typeof n[r]=="function")&&r!="__proto__")return n[r]}return sg=e,sg}var ig,kk;function j4(){if(kk)return ig;kk=1;var e=Da(),n=di();function r(i){return e(i,n(i))}return ig=r,ig}var og,Ek;function A4(){if(Ek)return og;Ek=1;var e=_R(),n=AC(),r=FC(),i=IC(),o=BC(),l=Fa(),u=bt(),c=fR(),h=So(),p=$a(),d=Ln(),m=T4(),y=za(),w=bR(),N=j4();function _(b,S,k,E,C,I,P){var A=w(b,k),U=w(S,k),L=P.get(U);if(L){e(b,k,L);return}var O=I?I(A,U,k+"",b,S,P):void 0,q=O===void 0;if(q){var G=u(U),F=!G&&h(U),j=!G&&!F&&y(U);O=U,G||F||j?u(A)?O=A:c(A)?O=i(A):F?(q=!1,O=n(U,!0)):j?(q=!1,O=r(U,!0)):O=[]:m(U)||l(U)?(O=A,l(A)?O=N(A):(!d(A)||p(A))&&(O=o(U))):q=!1}q&&(P.set(U,O),C(O,U,E,I,P),P.delete(U)),e(b,k,O)}return og=_,og}var ag,Nk;function I4(){if(Nk)return ag;Nk=1;var e=qu(),n=_R(),r=dy(),i=A4(),o=Ln(),l=di(),u=bR();function c(h,p,d,m,y){h!==p&&r(p,function(w,N){if(y||(y=new e),o(w))i(h,p,N,d,c,m,y);else{var _=m?m(u(h,N),w,N+"",h,p,y):void 0;_===void 0&&(_=w),n(h,N,_)}},l)}return ag=c,ag}var lg,Ck;function M4(){if(Ck)return lg;Ck=1;var e=Yu(),n=Ku();function r(i){return e(function(o,l){var u=-1,c=l.length,h=c>1?l[c-1]:void 0,p=c>2?l[2]:void 0;for(h=i.length>3&&typeof h=="function"?(c--,h):void 0,p&&n(l[0],l[1],p)&&(h=c<3?void 0:h,c=1),o=Object(o);++u<c;){var d=l[u];d&&i(o,d,u,h)}return o})}return lg=r,lg}var ug,Rk;function O4(){if(Rk)return ug;Rk=1;var e=I4(),n=M4(),r=n(function(i,o,l){e(i,o,l)});return ug=r,ug}var cg,Tk;function SR(){if(Tk)return cg;Tk=1;function e(n,r){return n<r}return cg=e,cg}var dg,jk;function P4(){if(jk)return dg;jk=1;var e=vy(),n=SR(),r=fi();function i(o){return o&&o.length?e(o,r,n):void 0}return dg=i,dg}var fg,Ak;function L4(){if(Ak)return fg;Ak=1;var e=vy(),n=Vr(),r=SR();function i(o,l){return o&&o.length?e(o,n(l,2),r):void 0}return fg=i,fg}var hg,Ik;function q4(){if(Ik)return hg;Ik=1;var e=nr(),n=function(){return e.Date.now()};return hg=n,hg}var pg,Mk;function $4(){if(Mk)return pg;Mk=1;var e=Du(),n=Vu(),r=Fu(),i=Ln(),o=Ba();function l(u,c,h,p){if(!i(u))return u;c=n(c,u);for(var d=-1,m=c.length,y=m-1,w=u;w!=null&&++d<m;){var N=o(c[d]),_=h;if(N==="__proto__"||N==="constructor"||N==="prototype")return u;if(d!=y){var b=w[N];_=p?p(b,N,w):void 0,_===void 0&&(_=i(b)?b:r(c[d+1])?[]:{})}e(w,N,_),w=w[N]}return u}return pg=l,pg}var mg,Ok;function D4(){if(Ok)return mg;Ok=1;var e=Gu(),n=$4(),r=Vu();function i(o,l,u){for(var c=-1,h=l.length,p={};++c<h;){var d=l[c],m=e(o,d);u(m,d)&&n(p,r(d,o),m)}return p}return mg=i,mg}var gg,Pk;function F4(){if(Pk)return gg;Pk=1;var e=D4(),n=tR();function r(i,o){return e(i,o,function(l,u){return n(i,u)})}return gg=r,gg}var vg,Lk;function z4(){if(Lk)return vg;Lk=1;var e=xR(),n=uR(),r=cR();function i(o){return r(n(o,void 0,e),o+"")}return vg=i,vg}var yg,qk;function B4(){if(qk)return yg;qk=1;var e=F4(),n=z4(),r=n(function(i,o){return i==null?{}:e(i,o)});return yg=r,yg}var wg,$k;function U4(){if($k)return wg;$k=1;var e=Math.ceil,n=Math.max;function r(i,o,l,u){for(var c=-1,h=n(e((o-i)/(l||1)),0),p=Array(h);h--;)p[u?h:++c]=i,i+=l;return p}return wg=r,wg}var xg,Dk;function H4(){if(Dk)return xg;Dk=1;var e=U4(),n=Ku(),r=wR();function i(o){return function(l,u,c){return c&&typeof c!="number"&&n(l,u,c)&&(u=c=void 0),l=r(l),u===void 0?(u=l,l=0):u=r(u),c=c===void 0?l<u?1:-1:r(c),e(l,u,c,o)}}return xg=i,xg}var _g,Fk;function W4(){if(Fk)return _g;Fk=1;var e=H4(),n=e();return _g=n,_g}var bg,zk;function V4(){if(zk)return bg;zk=1;function e(n,r){var i=n.length;for(n.sort(r);i--;)n[i]=n[i].value;return n}return bg=e,bg}var Sg,Bk;function G4(){if(Bk)return Sg;Bk=1;var e=Eo();function n(r,i){if(r!==i){var o=r!==void 0,l=r===null,u=r===r,c=e(r),h=i!==void 0,p=i===null,d=i===i,m=e(i);if(!p&&!m&&!c&&r>i||c&&h&&d&&!p&&!m||l&&h&&d||!o&&d||!u)return 1;if(!l&&!c&&!m&&r<i||m&&o&&u&&!l&&!c||p&&o&&u||!h&&u||!d)return-1}return 0}return Sg=n,Sg}var kg,Uk;function Y4(){if(Uk)return kg;Uk=1;var e=G4();function n(r,i,o){for(var l=-1,u=r.criteria,c=i.criteria,h=u.length,p=o.length;++l<h;){var d=e(u[l],c[l]);if(d){if(l>=p)return d;var m=o[l];return d*(m=="desc"?-1:1)}}return r.index-i.index}return kg=n,kg}var Eg,Hk;function K4(){if(Hk)return Eg;Hk=1;var e=Wu(),n=Gu(),r=Vr(),i=oR(),o=V4(),l=zu(),u=Y4(),c=fi(),h=bt();function p(d,m,y){m.length?m=e(m,function(_){return h(_)?function(b){return n(b,_.length===1?_[0]:_)}:_}):m=[c];var w=-1;m=e(m,l(r));var N=i(d,function(_,b,S){var k=e(m,function(E){return E(_)});return{criteria:k,index:++w,value:_}});return o(N,function(_,b){return u(_,b,y)})}return Eg=p,Eg}var Ng,Wk;function X4(){if(Wk)return Ng;Wk=1;var e=my(),n=K4(),r=Yu(),i=Ku(),o=r(function(l,u){if(l==null)return[];var c=u.length;return c>1&&i(l,u[0],u[1])?u=[]:c>2&&i(u[0],u[1],u[2])&&(u=[u[0]]),n(l,e(u,1),[])});return Ng=o,Ng}var Cg,Vk;function Q4(){if(Vk)return Cg;Vk=1;var e=JC(),n=0;function r(i){var o=++n;return e(i)+o}return Cg=r,Cg}var Rg,Gk;function Z4(){if(Gk)return Rg;Gk=1;function e(n,r,i){for(var o=-1,l=n.length,u=r.length,c={};++o<l;){var h=o<u?r[o]:void 0;i(c,n[o],h)}return c}return Rg=e,Rg}var Tg,Yk;function J4(){if(Yk)return Tg;Yk=1;var e=Du(),n=Z4();function r(i,o){return n(i||[],o||[],e)}return Tg=r,Tg}var jg,Kk;function it(){if(Kk)return jg;Kk=1;var e;if(typeof ey=="function")try{e={cloneDeep:m4(),constant:cy(),defaults:g4(),each:VC(),filter:rR(),find:S4(),flatten:xR(),forEach:WC(),forIn:k4(),has:sR(),isUndefined:iR(),last:E4(),map:aR(),mapValues:N4(),max:R4(),merge:O4(),min:P4(),minBy:L4(),now:q4(),pick:B4(),range:W4(),reduce:lR(),sortBy:X4(),uniqueId:Q4(),values:hR(),zipObject:J4()}}catch{}return e||(e=window._),jg=e,jg}var Ag,Xk;function eD(){if(Xk)return Ag;Xk=1,Ag=e;function e(){var i={};i._next=i._prev=i,this._sentinel=i}e.prototype.dequeue=function(){var i=this._sentinel,o=i._prev;if(o!==i)return n(o),o},e.prototype.enqueue=function(i){var o=this._sentinel;i._prev&&i._next&&n(i),i._next=o._next,o._next._prev=i,o._next=i,i._prev=o},e.prototype.toString=function(){for(var i=[],o=this._sentinel,l=o._prev;l!==o;)i.push(JSON.stringify(l,r)),l=l._prev;return"["+i.join(", ")+"]"};function n(i){i._prev._next=i._next,i._next._prev=i._prev,delete i._next,delete i._prev}function r(i,o){if(i!=="_next"&&i!=="_prev")return o}return Ag}var Ig,Qk;function tD(){if(Qk)return Ig;Qk=1;var e=it(),n=er().Graph,r=eD();Ig=o;var i=e.constant(1);function o(p,d){if(p.nodeCount()<=1)return[];var m=c(p,d||i),y=l(m.graph,m.buckets,m.zeroIdx);return e.flatten(e.map(y,function(w){return p.outEdges(w.v,w.w)}),!0)}function l(p,d,m){for(var y=[],w=d[d.length-1],N=d[0],_;p.nodeCount();){for(;_=N.dequeue();)u(p,d,m,_);for(;_=w.dequeue();)u(p,d,m,_);if(p.nodeCount()){for(var b=d.length-2;b>0;--b)if(_=d[b].dequeue(),_){y=y.concat(u(p,d,m,_,!0));break}}}return y}function u(p,d,m,y,w){var N=w?[]:void 0;return e.forEach(p.inEdges(y.v),function(_){var b=p.edge(_),S=p.node(_.v);w&&N.push({v:_.v,w:_.w}),S.out-=b,h(d,m,S)}),e.forEach(p.outEdges(y.v),function(_){var b=p.edge(_),S=_.w,k=p.node(S);k.in-=b,h(d,m,k)}),p.removeNode(y.v),N}function c(p,d){var m=new n,y=0,w=0;e.forEach(p.nodes(),function(b){m.setNode(b,{v:b,in:0,out:0})}),e.forEach(p.edges(),function(b){var S=m.edge(b.v,b.w)||0,k=d(b),E=S+k;m.setEdge(b.v,b.w,E),w=Math.max(w,m.node(b.v).out+=k),y=Math.max(y,m.node(b.w).in+=k)});var N=e.range(w+y+3).map(function(){return new r}),_=y+1;return e.forEach(m.nodes(),function(b){h(N,_,m.node(b))}),{graph:m,buckets:N,zeroIdx:_}}function h(p,d,m){m.out?m.in?p[m.out-m.in+d].enqueue(m):p[p.length-1].enqueue(m):p[0].enqueue(m)}return Ig}var Mg,Zk;function nD(){if(Zk)return Mg;Zk=1;var e=it(),n=tD();Mg={run:r,undo:o};function r(l){var u=l.graph().acyclicer==="greedy"?n(l,c(l)):i(l);e.forEach(u,function(h){var p=l.edge(h);l.removeEdge(h),p.forwardName=h.name,p.reversed=!0,l.setEdge(h.w,h.v,p,e.uniqueId("rev"))});function c(h){return function(p){return h.edge(p).weight}}}function i(l){var u=[],c={},h={};function p(d){e.has(h,d)||(h[d]=!0,c[d]=!0,e.forEach(l.outEdges(d),function(m){e.has(c,m.w)?u.push(m):p(m.w)}),delete c[d])}return e.forEach(l.nodes(),p),u}function o(l){e.forEach(l.edges(),function(u){var c=l.edge(u);if(c.reversed){l.removeEdge(u);var h=c.forwardName;delete c.reversed,delete c.forwardName,l.setEdge(u.w,u.v,c,h)}})}return Mg}var Og,Jk;function hn(){if(Jk)return Og;Jk=1;var e=it(),n=er().Graph;Og={addDummyNode:r,simplify:i,asNonCompoundGraph:o,successorWeights:l,predecessorWeights:u,intersectRect:c,buildLayerMatrix:h,normalizeRanks:p,removeEmptyRanks:d,addBorderNode:m,maxRank:y,partition:w,time:N,notime:_};function r(b,S,k,E){var C;do C=e.uniqueId(E);while(b.hasNode(C));return k.dummy=S,b.setNode(C,k),C}function i(b){var S=new n().setGraph(b.graph());return e.forEach(b.nodes(),function(k){S.setNode(k,b.node(k))}),e.forEach(b.edges(),function(k){var E=S.edge(k.v,k.w)||{weight:0,minlen:1},C=b.edge(k);S.setEdge(k.v,k.w,{weight:E.weight+C.weight,minlen:Math.max(E.minlen,C.minlen)})}),S}function o(b){var S=new n({multigraph:b.isMultigraph()}).setGraph(b.graph());return e.forEach(b.nodes(),function(k){b.children(k).length||S.setNode(k,b.node(k))}),e.forEach(b.edges(),function(k){S.setEdge(k,b.edge(k))}),S}function l(b){var S=e.map(b.nodes(),function(k){var E={};return e.forEach(b.outEdges(k),function(C){E[C.w]=(E[C.w]||0)+b.edge(C).weight}),E});return e.zipObject(b.nodes(),S)}function u(b){var S=e.map(b.nodes(),function(k){var E={};return e.forEach(b.inEdges(k),function(C){E[C.v]=(E[C.v]||0)+b.edge(C).weight}),E});return e.zipObject(b.nodes(),S)}function c(b,S){var k=b.x,E=b.y,C=S.x-k,I=S.y-E,P=b.width/2,A=b.height/2;if(!C&&!I)throw new Error("Not possible to find intersection inside of the rectangle");var U,L;return Math.abs(I)*P>Math.abs(C)*A?(I<0&&(A=-A),U=A*C/I,L=A):(C<0&&(P=-P),U=P,L=P*I/C),{x:k+U,y:E+L}}function h(b){var S=e.map(e.range(y(b)+1),function(){return[]});return e.forEach(b.nodes(),function(k){var E=b.node(k),C=E.rank;e.isUndefined(C)||(S[C][E.order]=k)}),S}function p(b){var S=e.min(e.map(b.nodes(),function(k){return b.node(k).rank}));e.forEach(b.nodes(),function(k){var E=b.node(k);e.has(E,"rank")&&(E.rank-=S)})}function d(b){var S=e.min(e.map(b.nodes(),function(I){return b.node(I).rank})),k=[];e.forEach(b.nodes(),function(I){var P=b.node(I).rank-S;k[P]||(k[P]=[]),k[P].push(I)});var E=0,C=b.graph().nodeRankFactor;e.forEach(k,function(I,P){e.isUndefined(I)&&P%C!==0?--E:E&&e.forEach(I,function(A){b.node(A).rank+=E})})}function m(b,S,k,E){var C={width:0,height:0};return arguments.length>=4&&(C.rank=k,C.order=E),r(b,"border",C,S)}function y(b){return e.max(e.map(b.nodes(),function(S){var k=b.node(S).rank;if(!e.isUndefined(k))return k}))}function w(b,S){var k={lhs:[],rhs:[]};return e.forEach(b,function(E){S(E)?k.lhs.push(E):k.rhs.push(E)}),k}function N(b,S){var k=e.now();try{return S()}finally{console.log(b+" time: "+(e.now()-k)+"ms")}}function _(b,S){return S()}return Og}var Pg,eE;function rD(){if(eE)return Pg;eE=1;var e=it(),n=hn();Pg={run:r,undo:o};function r(l){l.graph().dummyChains=[],e.forEach(l.edges(),function(u){i(l,u)})}function i(l,u){var c=u.v,h=l.node(c).rank,p=u.w,d=l.node(p).rank,m=u.name,y=l.edge(u),w=y.labelRank;if(d!==h+1){l.removeEdge(u);var N,_,b;for(b=0,++h;h<d;++b,++h)y.points=[],_={width:0,height:0,edgeLabel:y,edgeObj:u,rank:h},N=n.addDummyNode(l,"edge",_,"_d"),h===w&&(_.width=y.width,_.height=y.height,_.dummy="edge-label",_.labelpos=y.labelpos),l.setEdge(c,N,{weight:y.weight},m),b===0&&l.graph().dummyChains.push(N),c=N;l.setEdge(c,p,{weight:y.weight},m)}}function o(l){e.forEach(l.graph().dummyChains,function(u){var c=l.node(u),h=c.edgeLabel,p;for(l.setEdge(c.edgeObj,h);c.dummy;)p=l.successors(u)[0],l.removeNode(u),h.points.push({x:c.x,y:c.y}),c.dummy==="edge-label"&&(h.x=c.x,h.y=c.y,h.width=c.width,h.height=c.height),u=p,c=l.node(u)})}return Pg}var Lg,tE;function Su(){if(tE)return Lg;tE=1;var e=it();Lg={longestPath:n,slack:r};function n(i){var o={};function l(u){var c=i.node(u);if(e.has(o,u))return c.rank;o[u]=!0;var h=e.min(e.map(i.outEdges(u),function(p){return l(p.w)-i.edge(p).minlen}));return(h===Number.POSITIVE_INFINITY||h===void 0||h===null)&&(h=0),c.rank=h}e.forEach(i.sources(),l)}function r(i,o){return i.node(o.w).rank-i.node(o.v).rank-i.edge(o).minlen}return Lg}var qg,nE;function kR(){if(nE)return qg;nE=1;var e=it(),n=er().Graph,r=Su().slack;qg=i;function i(c){var h=new n({directed:!1}),p=c.nodes()[0],d=c.nodeCount();h.setNode(p,{});for(var m,y;o(h,c)<d;)m=l(h,c),y=h.hasNode(m.v)?r(c,m):-r(c,m),u(h,c,y);return h}function o(c,h){function p(d){e.forEach(h.nodeEdges(d),function(m){var y=m.v,w=d===y?m.w:y;!c.hasNode(w)&&!r(h,m)&&(c.setNode(w,{}),c.setEdge(d,w,{}),p(w))})}return e.forEach(c.nodes(),p),c.nodeCount()}function l(c,h){return e.minBy(h.edges(),function(p){if(c.hasNode(p.v)!==c.hasNode(p.w))return r(h,p)})}function u(c,h,p){e.forEach(c.nodes(),function(d){h.node(d).rank+=p})}return qg}var $g,rE;function sD(){if(rE)return $g;rE=1;var e=it(),n=kR(),r=Su().slack,i=Su().longestPath,o=er().alg.preorder,l=er().alg.postorder,u=hn().simplify;$g=c,c.initLowLimValues=m,c.initCutValues=h,c.calcCutValue=d,c.leaveEdge=w,c.enterEdge=N,c.exchangeEdges=_;function c(E){E=u(E),i(E);var C=n(E);m(C),h(C,E);for(var I,P;I=w(C);)P=N(C,E,I),_(C,E,I,P)}function h(E,C){var I=l(E,E.nodes());I=I.slice(0,I.length-1),e.forEach(I,function(P){p(E,C,P)})}function p(E,C,I){var P=E.node(I),A=P.parent;E.edge(I,A).cutvalue=d(E,C,I)}function d(E,C,I){var P=E.node(I),A=P.parent,U=!0,L=C.edge(I,A),O=0;return L||(U=!1,L=C.edge(A,I)),O=L.weight,e.forEach(C.nodeEdges(I),function(q){var G=q.v===I,F=G?q.w:q.v;if(F!==A){var j=G===U,B=C.edge(q).weight;if(O+=j?B:-B,S(E,I,F)){var z=E.edge(I,F).cutvalue;O+=j?-z:z}}}),O}function m(E,C){arguments.length<2&&(C=E.nodes()[0]),y(E,{},1,C)}function y(E,C,I,P,A){var U=I,L=E.node(P);return C[P]=!0,e.forEach(E.neighbors(P),function(O){e.has(C,O)||(I=y(E,C,I,O,P))}),L.low=U,L.lim=I++,A?L.parent=A:delete L.parent,I}function w(E){return e.find(E.edges(),function(C){return E.edge(C).cutvalue<0})}function N(E,C,I){var P=I.v,A=I.w;C.hasEdge(P,A)||(P=I.w,A=I.v);var U=E.node(P),L=E.node(A),O=U,q=!1;U.lim>L.lim&&(O=L,q=!0);var G=e.filter(C.edges(),function(F){return q===k(E,E.node(F.v),O)&&q!==k(E,E.node(F.w),O)});return e.minBy(G,function(F){return r(C,F)})}function _(E,C,I,P){var A=I.v,U=I.w;E.removeEdge(A,U),E.setEdge(P.v,P.w,{}),m(E),h(E,C),b(E,C)}function b(E,C){var I=e.find(E.nodes(),function(A){return!C.node(A).parent}),P=o(E,I);P=P.slice(1),e.forEach(P,function(A){var U=E.node(A).parent,L=C.edge(A,U),O=!1;L||(L=C.edge(U,A),O=!0),C.node(A).rank=C.node(U).rank+(O?L.minlen:-L.minlen)})}function S(E,C,I){return E.hasEdge(C,I)}function k(E,C,I){return I.low<=C.lim&&C.lim<=I.lim}return $g}var Dg,sE;function iD(){if(sE)return Dg;sE=1;var e=Su(),n=e.longestPath,r=kR(),i=sD();Dg=o;function o(h){switch(h.graph().ranker){case"network-simplex":c(h);break;case"tight-tree":u(h);break;case"longest-path":l(h);break;default:c(h)}}var l=n;function u(h){n(h),r(h)}function c(h){i(h)}return Dg}var Fg,iE;function oD(){if(iE)return Fg;iE=1;var e=it();Fg=n;function n(o){var l=i(o);e.forEach(o.graph().dummyChains,function(u){for(var c=o.node(u),h=c.edgeObj,p=r(o,l,h.v,h.w),d=p.path,m=p.lca,y=0,w=d[y],N=!0;u!==h.w;){if(c=o.node(u),N){for(;(w=d[y])!==m&&o.node(w).maxRank<c.rank;)y++;w===m&&(N=!1)}if(!N){for(;y<d.length-1&&o.node(w=d[y+1]).minRank<=c.rank;)y++;w=d[y]}o.setParent(u,w),u=o.successors(u)[0]}})}function r(o,l,u,c){var h=[],p=[],d=Math.min(l[u].low,l[c].low),m=Math.max(l[u].lim,l[c].lim),y,w;y=u;do y=o.parent(y),h.push(y);while(y&&(l[y].low>d||m>l[y].lim));for(w=y,y=c;(y=o.parent(y))!==w;)p.push(y);return{path:h.concat(p.reverse()),lca:w}}function i(o){var l={},u=0;function c(h){var p=u;e.forEach(o.children(h),c),l[h]={low:p,lim:u++}}return e.forEach(o.children(),c),l}return Fg}var zg,oE;function aD(){if(oE)return zg;oE=1;var e=it(),n=hn();zg={run:r,cleanup:u};function r(c){var h=n.addDummyNode(c,"root",{},"_root"),p=o(c),d=e.max(e.values(p))-1,m=2*d+1;c.graph().nestingRoot=h,e.forEach(c.edges(),function(w){c.edge(w).minlen*=m});var y=l(c)+1;e.forEach(c.children(),function(w){i(c,h,m,y,d,p,w)}),c.graph().nodeRankFactor=m}function i(c,h,p,d,m,y,w){var N=c.children(w);if(!N.length){w!==h&&c.setEdge(h,w,{weight:0,minlen:p});return}var _=n.addBorderNode(c,"_bt"),b=n.addBorderNode(c,"_bb"),S=c.node(w);c.setParent(_,w),S.borderTop=_,c.setParent(b,w),S.borderBottom=b,e.forEach(N,function(k){i(c,h,p,d,m,y,k);var E=c.node(k),C=E.borderTop?E.borderTop:k,I=E.borderBottom?E.borderBottom:k,P=E.borderTop?d:2*d,A=C!==I?1:m-y[w]+1;c.setEdge(_,C,{weight:P,minlen:A,nestingEdge:!0}),c.setEdge(I,b,{weight:P,minlen:A,nestingEdge:!0})}),c.parent(w)||c.setEdge(h,_,{weight:0,minlen:m+y[w]})}function o(c){var h={};function p(d,m){var y=c.children(d);y&&y.length&&e.forEach(y,function(w){p(w,m+1)}),h[d]=m}return e.forEach(c.children(),function(d){p(d,1)}),h}function l(c){return e.reduce(c.edges(),function(h,p){return h+c.edge(p).weight},0)}function u(c){var h=c.graph();c.removeNode(h.nestingRoot),delete h.nestingRoot,e.forEach(c.edges(),function(p){var d=c.edge(p);d.nestingEdge&&c.removeEdge(p)})}return zg}var Bg,aE;function lD(){if(aE)return Bg;aE=1;var e=it(),n=hn();Bg=r;function r(o){function l(u){var c=o.children(u),h=o.node(u);if(c.length&&e.forEach(c,l),e.has(h,"minRank")){h.borderLeft=[],h.borderRight=[];for(var p=h.minRank,d=h.maxRank+1;p<d;++p)i(o,"borderLeft","_bl",u,h,p),i(o,"borderRight","_br",u,h,p)}}e.forEach(o.children(),l)}function i(o,l,u,c,h,p){var d={width:0,height:0,rank:p,borderType:l},m=h[l][p-1],y=n.addDummyNode(o,"border",d,u);h[l][p]=y,o.setParent(y,c),m&&o.setEdge(m,y,{weight:1})}return Bg}var Ug,lE;function uD(){if(lE)return Ug;lE=1;var e=it();Ug={adjust:n,undo:r};function n(p){var d=p.graph().rankdir.toLowerCase();(d==="lr"||d==="rl")&&i(p)}function r(p){var d=p.graph().rankdir.toLowerCase();(d==="bt"||d==="rl")&&l(p),(d==="lr"||d==="rl")&&(c(p),i(p))}function i(p){e.forEach(p.nodes(),function(d){o(p.node(d))}),e.forEach(p.edges(),function(d){o(p.edge(d))})}function o(p){var d=p.width;p.width=p.height,p.height=d}function l(p){e.forEach(p.nodes(),function(d){u(p.node(d))}),e.forEach(p.edges(),function(d){var m=p.edge(d);e.forEach(m.points,u),e.has(m,"y")&&u(m)})}function u(p){p.y=-p.y}function c(p){e.forEach(p.nodes(),function(d){h(p.node(d))}),e.forEach(p.edges(),function(d){var m=p.edge(d);e.forEach(m.points,h),e.has(m,"x")&&h(m)})}function h(p){var d=p.x;p.x=p.y,p.y=d}return Ug}var Hg,uE;function cD(){if(uE)return Hg;uE=1;var e=it();Hg=n;function n(r){var i={},o=e.filter(r.nodes(),function(p){return!r.children(p).length}),l=e.max(e.map(o,function(p){return r.node(p).rank})),u=e.map(e.range(l+1),function(){return[]});function c(p){if(!e.has(i,p)){i[p]=!0;var d=r.node(p);u[d.rank].push(p),e.forEach(r.successors(p),c)}}var h=e.sortBy(o,function(p){return r.node(p).rank});return e.forEach(h,c),u}return Hg}var Wg,cE;function dD(){if(cE)return Wg;cE=1;var e=it();Wg=n;function n(i,o){for(var l=0,u=1;u<o.length;++u)l+=r(i,o[u-1],o[u]);return l}function r(i,o,l){for(var u=e.zipObject(l,e.map(l,function(y,w){return w})),c=e.flatten(e.map(o,function(y){return e.sortBy(e.map(i.outEdges(y),function(w){return{pos:u[w.w],weight:i.edge(w).weight}}),"pos")}),!0),h=1;h<l.length;)h<<=1;var p=2*h-1;h-=1;var d=e.map(new Array(p),function(){return 0}),m=0;return e.forEach(c.forEach(function(y){var w=y.pos+h;d[w]+=y.weight;for(var N=0;w>0;)w%2&&(N+=d[w+1]),w=w-1>>1,d[w]+=y.weight;m+=y.weight*N})),m}return Wg}var Vg,dE;function fD(){if(dE)return Vg;dE=1;var e=it();Vg=n;function n(r,i){return e.map(i,function(o){var l=r.inEdges(o);if(l.length){var u=e.reduce(l,function(c,h){var p=r.edge(h),d=r.node(h.v);return{sum:c.sum+p.weight*d.order,weight:c.weight+p.weight}},{sum:0,weight:0});return{v:o,barycenter:u.sum/u.weight,weight:u.weight}}else return{v:o}})}return Vg}var Gg,fE;function hD(){if(fE)return Gg;fE=1;var e=it();Gg=n;function n(o,l){var u={};e.forEach(o,function(h,p){var d=u[h.v]={indegree:0,in:[],out:[],vs:[h.v],i:p};e.isUndefined(h.barycenter)||(d.barycenter=h.barycenter,d.weight=h.weight)}),e.forEach(l.edges(),function(h){var p=u[h.v],d=u[h.w];!e.isUndefined(p)&&!e.isUndefined(d)&&(d.indegree++,p.out.push(u[h.w]))});var c=e.filter(u,function(h){return!h.indegree});return r(c)}function r(o){var l=[];function u(p){return function(d){d.merged||(e.isUndefined(d.barycenter)||e.isUndefined(p.barycenter)||d.barycenter>=p.barycenter)&&i(p,d)}}function c(p){return function(d){d.in.push(p),--d.indegree===0&&o.push(d)}}for(;o.length;){var h=o.pop();l.push(h),e.forEach(h.in.reverse(),u(h)),e.forEach(h.out,c(h))}return e.map(e.filter(l,function(p){return!p.merged}),function(p){return e.pick(p,["vs","i","barycenter","weight"])})}function i(o,l){var u=0,c=0;o.weight&&(u+=o.barycenter*o.weight,c+=o.weight),l.weight&&(u+=l.barycenter*l.weight,c+=l.weight),o.vs=l.vs.concat(o.vs),o.barycenter=u/c,o.weight=c,o.i=Math.min(l.i,o.i),l.merged=!0}return Gg}var Yg,hE;function pD(){if(hE)return Yg;hE=1;var e=it(),n=hn();Yg=r;function r(l,u){var c=n.partition(l,function(_){return e.has(_,"barycenter")}),h=c.lhs,p=e.sortBy(c.rhs,function(_){return-_.i}),d=[],m=0,y=0,w=0;h.sort(o(!!u)),w=i(d,p,w),e.forEach(h,function(_){w+=_.vs.length,d.push(_.vs),m+=_.barycenter*_.weight,y+=_.weight,w=i(d,p,w)});var N={vs:e.flatten(d,!0)};return y&&(N.barycenter=m/y,N.weight=y),N}function i(l,u,c){for(var h;u.length&&(h=e.last(u)).i<=c;)u.pop(),l.push(h.vs),c++;return c}function o(l){return function(u,c){return u.barycenter<c.barycenter?-1:u.barycenter>c.barycenter?1:l?c.i-u.i:u.i-c.i}}return Yg}var Kg,pE;function mD(){if(pE)return Kg;pE=1;var e=it(),n=fD(),r=hD(),i=pD();Kg=o;function o(c,h,p,d){var m=c.children(h),y=c.node(h),w=y?y.borderLeft:void 0,N=y?y.borderRight:void 0,_={};w&&(m=e.filter(m,function(I){return I!==w&&I!==N}));var b=n(c,m);e.forEach(b,function(I){if(c.children(I.v).length){var P=o(c,I.v,p,d);_[I.v]=P,e.has(P,"barycenter")&&u(I,P)}});var S=r(b,p);l(S,_);var k=i(S,d);if(w&&(k.vs=e.flatten([w,k.vs,N],!0),c.predecessors(w).length)){var E=c.node(c.predecessors(w)[0]),C=c.node(c.predecessors(N)[0]);e.has(k,"barycenter")||(k.barycenter=0,k.weight=0),k.barycenter=(k.barycenter*k.weight+E.order+C.order)/(k.weight+2),k.weight+=2}return k}function l(c,h){e.forEach(c,function(p){p.vs=e.flatten(p.vs.map(function(d){return h[d]?h[d].vs:d}),!0)})}function u(c,h){e.isUndefined(c.barycenter)?(c.barycenter=h.barycenter,c.weight=h.weight):(c.barycenter=(c.barycenter*c.weight+h.barycenter*h.weight)/(c.weight+h.weight),c.weight+=h.weight)}return Kg}var Xg,mE;function gD(){if(mE)return Xg;mE=1;var e=it(),n=er().Graph;Xg=r;function r(o,l,u){var c=i(o),h=new n({compound:!0}).setGraph({root:c}).setDefaultNodeLabel(function(p){return o.node(p)});return e.forEach(o.nodes(),function(p){var d=o.node(p),m=o.parent(p);(d.rank===l||d.minRank<=l&&l<=d.maxRank)&&(h.setNode(p),h.setParent(p,m||c),e.forEach(o[u](p),function(y){var w=y.v===p?y.w:y.v,N=h.edge(w,p),_=e.isUndefined(N)?0:N.weight;h.setEdge(w,p,{weight:o.edge(y).weight+_})}),e.has(d,"minRank")&&h.setNode(p,{borderLeft:d.borderLeft[l],borderRight:d.borderRight[l]}))}),h}function i(o){for(var l;o.hasNode(l=e.uniqueId("_root")););return l}return Xg}var Qg,gE;function vD(){if(gE)return Qg;gE=1;var e=it();Qg=n;function n(r,i,o){var l={},u;e.forEach(o,function(c){for(var h=r.parent(c),p,d;h;){if(p=r.parent(h),p?(d=l[p],l[p]=h):(d=u,u=h),d&&d!==h){i.setEdge(d,h);return}h=p}})}return Qg}var Zg,vE;function yD(){if(vE)return Zg;vE=1;var e=it(),n=cD(),r=dD(),i=mD(),o=gD(),l=vD(),u=er().Graph,c=hn();Zg=h;function h(y){var w=c.maxRank(y),N=p(y,e.range(1,w+1),"inEdges"),_=p(y,e.range(w-1,-1,-1),"outEdges"),b=n(y);m(y,b);for(var S=Number.POSITIVE_INFINITY,k,E=0,C=0;C<4;++E,++C){d(E%2?N:_,E%4>=2),b=c.buildLayerMatrix(y);var I=r(y,b);I<S&&(C=0,k=e.cloneDeep(b),S=I)}m(y,k)}function p(y,w,N){return e.map(w,function(_){return o(y,_,N)})}function d(y,w){var N=new u;e.forEach(y,function(_){var b=_.graph().root,S=i(_,b,N,w);e.forEach(S.vs,function(k,E){_.node(k).order=E}),l(_,N,S.vs)})}function m(y,w){e.forEach(w,function(N){e.forEach(N,function(_,b){y.node(_).order=b})})}return Zg}var Jg,yE;function wD(){if(yE)return Jg;yE=1;var e=it(),n=er().Graph,r=hn();Jg={positionX:N,findType1Conflicts:i,findType2Conflicts:o,addConflict:u,hasConflict:c,verticalAlignment:h,horizontalCompaction:p,alignCoordinates:y,findSmallestWidthAlignment:m,balance:w};function i(S,k){var E={};function C(I,P){var A=0,U=0,L=I.length,O=e.last(P);return e.forEach(P,function(q,G){var F=l(S,q),j=F?S.node(F).order:L;(F||q===O)&&(e.forEach(P.slice(U,G+1),function(B){e.forEach(S.predecessors(B),function(z){var ne=S.node(z),Z=ne.order;(Z<A||j<Z)&&!(ne.dummy&&S.node(B).dummy)&&u(E,z,B)})}),U=G+1,A=j)}),P}return e.reduce(k,C),E}function o(S,k){var E={};function C(P,A,U,L,O){var q;e.forEach(e.range(A,U),function(G){q=P[G],S.node(q).dummy&&e.forEach(S.predecessors(q),function(F){var j=S.node(F);j.dummy&&(j.order<L||j.order>O)&&u(E,F,q)})})}function I(P,A){var U=-1,L,O=0;return e.forEach(A,function(q,G){if(S.node(q).dummy==="border"){var F=S.predecessors(q);F.length&&(L=S.node(F[0]).order,C(A,O,G,U,L),O=G,U=L)}C(A,O,A.length,L,P.length)}),A}return e.reduce(k,I),E}function l(S,k){if(S.node(k).dummy)return e.find(S.predecessors(k),function(E){return S.node(E).dummy})}function u(S,k,E){if(k>E){var C=k;k=E,E=C}var I=S[k];I||(S[k]=I={}),I[E]=!0}function c(S,k,E){if(k>E){var C=k;k=E,E=C}return e.has(S[k],E)}function h(S,k,E,C){var I={},P={},A={};return e.forEach(k,function(U){e.forEach(U,function(L,O){I[L]=L,P[L]=L,A[L]=O})}),e.forEach(k,function(U){var L=-1;e.forEach(U,function(O){var q=C(O);if(q.length){q=e.sortBy(q,function(z){return A[z]});for(var G=(q.length-1)/2,F=Math.floor(G),j=Math.ceil(G);F<=j;++F){var B=q[F];P[O]===O&&L<A[B]&&!c(E,O,B)&&(P[B]=O,P[O]=I[O]=I[B],L=A[B])}}})}),{root:I,align:P}}function p(S,k,E,C,I){var P={},A=d(S,k,E,I),U=I?"borderLeft":"borderRight";function L(G,F){for(var j=A.nodes(),B=j.pop(),z={};B;)z[B]?G(B):(z[B]=!0,j.push(B),j=j.concat(F(B))),B=j.pop()}function O(G){P[G]=A.inEdges(G).reduce(function(F,j){return Math.max(F,P[j.v]+A.edge(j))},0)}function q(G){var F=A.outEdges(G).reduce(function(B,z){return Math.min(B,P[z.w]-A.edge(z))},Number.POSITIVE_INFINITY),j=S.node(G);F!==Number.POSITIVE_INFINITY&&j.borderType!==U&&(P[G]=Math.max(P[G],F))}return L(O,A.predecessors.bind(A)),L(q,A.successors.bind(A)),e.forEach(C,function(G){P[G]=P[E[G]]}),P}function d(S,k,E,C){var I=new n,P=S.graph(),A=_(P.nodesep,P.edgesep,C);return e.forEach(k,function(U){var L;e.forEach(U,function(O){var q=E[O];if(I.setNode(q),L){var G=E[L],F=I.edge(G,q);I.setEdge(G,q,Math.max(A(S,O,L),F||0))}L=O})}),I}function m(S,k){return e.minBy(e.values(k),function(E){var C=Number.NEGATIVE_INFINITY,I=Number.POSITIVE_INFINITY;return e.forIn(E,function(P,A){var U=b(S,A)/2;C=Math.max(P+U,C),I=Math.min(P-U,I)}),C-I})}function y(S,k){var E=e.values(k),C=e.min(E),I=e.max(E);e.forEach(["u","d"],function(P){e.forEach(["l","r"],function(A){var U=P+A,L=S[U],O;if(L!==k){var q=e.values(L);O=A==="l"?C-e.min(q):I-e.max(q),O&&(S[U]=e.mapValues(L,function(G){return G+O}))}})})}function w(S,k){return e.mapValues(S.ul,function(E,C){if(k)return S[k.toLowerCase()][C];var I=e.sortBy(e.map(S,C));return(I[1]+I[2])/2})}function N(S){var k=r.buildLayerMatrix(S),E=e.merge(i(S,k),o(S,k)),C={},I;e.forEach(["u","d"],function(A){I=A==="u"?k:e.values(k).reverse(),e.forEach(["l","r"],function(U){U==="r"&&(I=e.map(I,function(G){return e.values(G).reverse()}));var L=(A==="u"?S.predecessors:S.successors).bind(S),O=h(S,I,E,L),q=p(S,I,O.root,O.align,U==="r");U==="r"&&(q=e.mapValues(q,function(G){return-G})),C[A+U]=q})});var P=m(S,C);return y(C,P),w(C,S.graph().align)}function _(S,k,E){return function(C,I,P){var A=C.node(I),U=C.node(P),L=0,O;if(L+=A.width/2,e.has(A,"labelpos"))switch(A.labelpos.toLowerCase()){case"l":O=-A.width/2;break;case"r":O=A.width/2;break}if(O&&(L+=E?O:-O),O=0,L+=(A.dummy?k:S)/2,L+=(U.dummy?k:S)/2,L+=U.width/2,e.has(U,"labelpos"))switch(U.labelpos.toLowerCase()){case"l":O=U.width/2;break;case"r":O=-U.width/2;break}return O&&(L+=E?O:-O),O=0,L}}function b(S,k){return S.node(k).width}return Jg}var ev,wE;function xD(){if(wE)return ev;wE=1;var e=it(),n=hn(),r=wD().positionX;ev=i;function i(l){l=n.asNonCompoundGraph(l),o(l),e.forEach(r(l),function(u,c){l.node(c).x=u})}function o(l){var u=n.buildLayerMatrix(l),c=l.graph().ranksep,h=0;e.forEach(u,function(p){var d=e.max(e.map(p,function(m){return l.node(m).height}));e.forEach(p,function(m){l.node(m).y=h+d/2}),h+=d+c})}return ev}var tv,xE;function _D(){if(xE)return tv;xE=1;var e=it(),n=nD(),r=rD(),i=iD(),o=hn().normalizeRanks,l=oD(),u=hn().removeEmptyRanks,c=aD(),h=lD(),p=uD(),d=yD(),m=xD(),y=hn(),w=er().Graph;tv=N;function N(H,J){var re=J&&J.debugTiming?y.time:y.notime;re("layout",function(){var le=re(" buildLayoutGraph",function(){return L(H)});re(" runLayout",function(){_(le,re)}),re(" updateInputGraph",function(){b(H,le)})})}function _(H,J){J(" makeSpaceForEdgeLabels",function(){O(H)}),J(" removeSelfEdges",function(){$(H)}),J(" acyclic",function(){n.run(H)}),J(" nestingGraph.run",function(){c.run(H)}),J(" rank",function(){i(y.asNonCompoundGraph(H))}),J(" injectEdgeLabelProxies",function(){q(H)}),J(" removeEmptyRanks",function(){u(H)}),J(" nestingGraph.cleanup",function(){c.cleanup(H)}),J(" normalizeRanks",function(){o(H)}),J(" assignRankMinMax",function(){G(H)}),J(" removeEdgeLabelProxies",function(){F(H)}),J(" normalize.run",function(){r.run(H)}),J(" parentDummyChains",function(){l(H)}),J(" addBorderSegments",function(){h(H)}),J(" order",function(){d(H)}),J(" insertSelfEdges",function(){Q(H)}),J(" adjustCoordinateSystem",function(){p.adjust(H)}),J(" position",function(){m(H)}),J(" positionSelfEdges",function(){M(H)}),J(" removeBorderNodes",function(){Z(H)}),J(" normalize.undo",function(){r.undo(H)}),J(" fixupEdgeLabelCoords",function(){z(H)}),J(" undoCoordinateSystem",function(){p.undo(H)}),J(" translateGraph",function(){j(H)}),J(" assignNodeIntersects",function(){B(H)}),J(" reversePoints",function(){ne(H)}),J(" acyclic.undo",function(){n.undo(H)})}function b(H,J){e.forEach(H.nodes(),function(re){var le=H.node(re),fe=J.node(re);le&&(le.x=fe.x,le.y=fe.y,J.children(re).length&&(le.width=fe.width,le.height=fe.height))}),e.forEach(H.edges(),function(re){var le=H.edge(re),fe=J.edge(re);le.points=fe.points,e.has(fe,"x")&&(le.x=fe.x,le.y=fe.y)}),H.graph().width=J.graph().width,H.graph().height=J.graph().height}var S=["nodesep","edgesep","ranksep","marginx","marginy"],k={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},E=["acyclicer","ranker","rankdir","align"],C=["width","height"],I={width:0,height:0},P=["minlen","weight","width","height","labeloffset"],A={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},U=["labelpos"];function L(H){var J=new w({multigraph:!0,compound:!0}),re=Y(H.graph());return J.setGraph(e.merge({},k,V(re,S),e.pick(re,E))),e.forEach(H.nodes(),function(le){var fe=Y(H.node(le));J.setNode(le,e.defaults(V(fe,C),I)),J.setParent(le,H.parent(le))}),e.forEach(H.edges(),function(le){var fe=Y(H.edge(le));J.setEdge(le,e.merge({},A,V(fe,P),e.pick(fe,U)))}),J}function O(H){var J=H.graph();J.ranksep/=2,e.forEach(H.edges(),function(re){var le=H.edge(re);le.minlen*=2,le.labelpos.toLowerCase()!=="c"&&(J.rankdir==="TB"||J.rankdir==="BT"?le.width+=le.labeloffset:le.height+=le.labeloffset)})}function q(H){e.forEach(H.edges(),function(J){var re=H.edge(J);if(re.width&&re.height){var le=H.node(J.v),fe=H.node(J.w),te={rank:(fe.rank-le.rank)/2+le.rank,e:J};y.addDummyNode(H,"edge-proxy",te,"_ep")}})}function G(H){var J=0;e.forEach(H.nodes(),function(re){var le=H.node(re);le.borderTop&&(le.minRank=H.node(le.borderTop).rank,le.maxRank=H.node(le.borderBottom).rank,J=e.max(J,le.maxRank))}),H.graph().maxRank=J}function F(H){e.forEach(H.nodes(),function(J){var re=H.node(J);re.dummy==="edge-proxy"&&(H.edge(re.e).labelRank=re.rank,H.removeNode(J))})}function j(H){var J=Number.POSITIVE_INFINITY,re=0,le=Number.POSITIVE_INFINITY,fe=0,te=H.graph(),ce=te.marginx||0,Ce=te.marginy||0;function ve(je){var ye=je.x,ke=je.y,Ke=je.width,we=je.height;J=Math.min(J,ye-Ke/2),re=Math.max(re,ye+Ke/2),le=Math.min(le,ke-we/2),fe=Math.max(fe,ke+we/2)}e.forEach(H.nodes(),function(je){ve(H.node(je))}),e.forEach(H.edges(),function(je){var ye=H.edge(je);e.has(ye,"x")&&ve(ye)}),J-=ce,le-=Ce,e.forEach(H.nodes(),function(je){var ye=H.node(je);ye.x-=J,ye.y-=le}),e.forEach(H.edges(),function(je){var ye=H.edge(je);e.forEach(ye.points,function(ke){ke.x-=J,ke.y-=le}),e.has(ye,"x")&&(ye.x-=J),e.has(ye,"y")&&(ye.y-=le)}),te.width=re-J+ce,te.height=fe-le+Ce}function B(H){e.forEach(H.edges(),function(J){var re=H.edge(J),le=H.node(J.v),fe=H.node(J.w),te,ce;re.points?(te=re.points[0],ce=re.points[re.points.length-1]):(re.points=[],te=fe,ce=le),re.points.unshift(y.intersectRect(le,te)),re.points.push(y.intersectRect(fe,ce))})}function z(H){e.forEach(H.edges(),function(J){var re=H.edge(J);if(e.has(re,"x"))switch((re.labelpos==="l"||re.labelpos==="r")&&(re.width-=re.labeloffset),re.labelpos){case"l":re.x-=re.width/2+re.labeloffset;break;case"r":re.x+=re.width/2+re.labeloffset;break}})}function ne(H){e.forEach(H.edges(),function(J){var re=H.edge(J);re.reversed&&re.points.reverse()})}function Z(H){e.forEach(H.nodes(),function(J){if(H.children(J).length){var re=H.node(J),le=H.node(re.borderTop),fe=H.node(re.borderBottom),te=H.node(e.last(re.borderLeft)),ce=H.node(e.last(re.borderRight));re.width=Math.abs(ce.x-te.x),re.height=Math.abs(fe.y-le.y),re.x=te.x+re.width/2,re.y=le.y+re.height/2}}),e.forEach(H.nodes(),function(J){H.node(J).dummy==="border"&&H.removeNode(J)})}function $(H){e.forEach(H.edges(),function(J){if(J.v===J.w){var re=H.node(J.v);re.selfEdges||(re.selfEdges=[]),re.selfEdges.push({e:J,label:H.edge(J)}),H.removeEdge(J)}})}function Q(H){var J=y.buildLayerMatrix(H);e.forEach(J,function(re){var le=0;e.forEach(re,function(fe,te){var ce=H.node(fe);ce.order=te+le,e.forEach(ce.selfEdges,function(Ce){y.addDummyNode(H,"selfedge",{width:Ce.label.width,height:Ce.label.height,rank:ce.rank,order:te+ ++le,e:Ce.e,label:Ce.label},"_se")}),delete ce.selfEdges})})}function M(H){e.forEach(H.nodes(),function(J){var re=H.node(J);if(re.dummy==="selfedge"){var le=H.node(re.e.v),fe=le.x+le.width/2,te=le.y,ce=re.x-fe,Ce=le.height/2;H.setEdge(re.e,re.label),H.removeNode(J),re.label.points=[{x:fe+2*ce/3,y:te-Ce},{x:fe+5*ce/6,y:te-Ce},{x:fe+ce,y:te},{x:fe+5*ce/6,y:te+Ce},{x:fe+2*ce/3,y:te+Ce}],re.label.x=re.x,re.label.y=re.y}})}function V(H,J){return e.mapValues(e.pick(H,J),Number)}function Y(H){var J={};return e.forEach(H,function(re,le){J[le.toLowerCase()]=re}),J}return tv}var nv,_E;function bD(){if(_E)return nv;_E=1;var e=it(),n=hn(),r=er().Graph;nv={debugOrdering:i};function i(o){var l=n.buildLayerMatrix(o),u=new r({compound:!0,multigraph:!0}).setGraph({});return e.forEach(o.nodes(),function(c){u.setNode(c,{label:c}),u.setParent(c,"layer"+o.node(c).rank)}),e.forEach(o.edges(),function(c){u.setEdge(c.v,c.w,{},c.name)}),e.forEach(l,function(c,h){var p="layer"+h;u.setNode(p,{rank:"same"}),e.reduce(c,function(d,m){return u.setEdge(d,m,{style:"invis"}),m})}),u}return nv}var rv,bE;function SD(){return bE||(bE=1,rv="0.8.5"),rv}var sv,SE;function kD(){return SE||(SE=1,sv={graphlib:er(),layout:_D(),debug:bD(),util:{time:hn().time,notime:hn().notime},version:SD()}),sv}var ED=kD();const kE=Av(ED),wo=240,ku=130,ho=74,Xu=72,EE=ho+Xu;function ND(e,n){var i;let r=wo;for(const o of e)r=Math.max(r,((i=n.get(o.id))==null?void 0:i.width)??wo);return r}const ER=420,CD=2;function ja(e){var r;return((r=e.data)==null?void 0:r.sessionId)??"_default"}function RD(e,n){return((n==null?void 0:n.get(e))??0)>0?ER:0}function TD(e,n){const r=(n==null?void 0:n.get(e))??0;return r>0?6+r*36:0}function Aa(e,n,r){const i=n.get(e);return{w:((i==null?void 0:i.width)??wo)+RD(e,r),h:Math.max((i==null?void 0:i.height)??ku,TD(e,r))}}function jD(e){return[...e.keys()].sort().map(n=>`${n}:${e.get(n)}`).join("|")}function AD(e,n,r,i,o,l){const u=new kE.graphlib.Graph;u.setDefaultEdgeLabel(()=>({})),u.setGraph({rankdir:r,marginx:0,marginy:0,nodesep:70,ranksep:160,edgesep:30});const c=e.filter(S=>!o.has(S)),h=new Set(c);for(const S of c){const{w:k,h:E}=Aa(S,i,l);u.setNode(S,{width:k,height:E})}for(const S of n)h.has(S.source)&&h.has(S.target)&&u.setEdge(S.source,S.target);kE.layout(u);const p=new Map;let d=1/0,m=1/0,y=-1/0,w=-1/0;for(const S of c){const k=u.node(S);if(!k)continue;const E=i.get(S),C=(E==null?void 0:E.width)??wo,I=(E==null?void 0:E.height)??ku,P=Aa(S,i,l),A=k.x-P.w/2,U=k.y-P.h/2;p.set(S,{x:A,y:U}),A<d&&(d=A),U<m&&(m=U),A+C>y&&(y=A+C),U+I>w&&(w=U+I)}if(Number.isFinite(d)&&Number.isFinite(m))for(const[S,k]of p)p.set(S,{x:k.x-d,y:k.y-m});const N=Number.isFinite(y)?y-d:0,_=Number.isFinite(w)?w-m:0;let b=null;for(const S of e){const k=o.get(S);if(!k)continue;const E=i.get(S),C=(E==null?void 0:E.width)??wo,I=(E==null?void 0:E.height)??ku;b=b===null?{minX:k.x,minY:k.y,maxX:k.x+C,maxY:k.y+I}:{minX:Math.min(b.minX,k.x),minY:Math.min(b.minY,k.y),maxX:Math.max(b.maxX,k.x+C),maxY:Math.max(b.maxY,k.y+I)}}return{positions:p,width:N,height:_,pinnedBox:b}}function ID(e,n,r={}){const i=r.direction??"LR",o=r.pinned??new Map,l=r.measured??new Map,u=r.lanes,c=new Map;for(const S of e){const k=ja(S),E=c.get(k);E?E.push(S.id):c.set(k,[S.id])}const p=Array.from(c.keys()).sort().map(S=>({sid:S,...AD(c.get(S),n,i,l,o,u)})),d=ND(e,l),m=r.availableHeight&&r.availableHeight>0?r.availableHeight:Number.POSITIVE_INFINITY,y=S=>{const k=[[]];let E=0;for(const C of p)k.length<S&&E>0&&E+C.height>m&&(k.push([]),E=0),k[k.length-1].push(C),E+=C.height+EE;return k},w=S=>S.reduce((k,E)=>Math.max(k,E.width),0)+ER;let N=y(r.availableWidth?CD:1);N.length>1&&N.reduce((k,E)=>k+w(E),0)+d*(N.length-1)>(r.availableWidth??0)&&(N=y(1));const _=new Map;let b=0;for(const S of N){const k=w(S);let E=0;for(const{positions:C,height:I,pinnedBox:P}of S){for(const[U,L]of C)_.set(U,{x:L.x+b,y:L.y+E});let A=E+I;P&&P.maxY>A&&P.minX<b+k&&b<P.maxX&&(A=P.maxY),E=A+EE}b+=k+d}return e.map(S=>{const k=o.get(S.id);if(k)return{...S,position:k};const E=_.get(S.id);return E?{...S,position:E}:S})}function MD(e,n,r,i,o){const u=ho+Xu,c=60,h=w=>Aa(w,i,o),p=new Map(e.map(w=>[w.id,ja(w)])),d=[],m=e.map(w=>({id:w.id,pos:r.get(w.id)??n.get(w.id)})).filter(w=>w.pos!=null).sort((w,N)=>w.pos.y-N.pos.y||w.pos.x-N.pos.x||w.id.localeCompare(N.id)),y=[];for(const{id:w,pos:N}of m){const{w:_,h:b}=h(w),S=p.get(w)??"_default";if(r.has(w)){d.push({x:N.x,y:N.y,w:_,h:b,sid:S});continue}let k=N.y;for(let E=0;E<d.length+1;E++){const C=d.find(I=>{const P=I.sid===S?24:c,A=I.sid===S?24:u;return N.x<I.x+I.w+P&&I.x<N.x+_+P&&k<I.y+I.h+A&&I.y<k+b+A});if(!C)break;k=C.y+C.h+(C.sid===S?24:u)}k!==N.y&&(n.set(w,{x:N.x,y:k}),y.push(w)),d.push({x:N.x,y:k,w:_,h:b,sid:S})}return y}function OD(e,n,r,i,o,l){const u=_=>Aa(_,i,l),c=_=>r.get(_)??n.get(_),h=new Map;for(const _ of e){if(!c(_.id))continue;const b=ja(_),S=h.get(b);S?S.push(_):h.set(b,[_])}const p=new Set;for(const[_,b]of h)b.every(S=>o.has(S.id)&&!r.has(S.id))&&p.add(_);const d=new Map,m=[];for(const _ of e){const b=c(_.id);if(!b)continue;const{w:S,h:k}=u(_.id),E=ja(_);p.has(E)?(d.get(E)??d.set(E,[]).get(E)).push(_):m.push({x:b.x,y:b.y,w:S,h:k})}if(d.size===0)return[];const y=ho+Xu,w=(_,b,S,k)=>m.some(E=>_<E.x+E.w+ho&&E.x<_+S+ho&&b<E.y+E.h+y&&E.y<b+k+y),N=[];for(const _ of[...d.keys()].sort()){const b=d.get(_);let S=1/0,k=1/0,E=-1/0,C=-1/0;for(const q of b){const G=c(q.id),{w:F,h:j}=u(q.id);S=Math.min(S,G.x),k=Math.min(k,G.y),E=Math.max(E,G.x+F),C=Math.max(C,G.y+j)}const I=E-S,P=C-k,A=[...new Set(m.map(q=>Math.round(q.x)))].sort((q,G)=>q-G),U=A.length?A:[S],L=[0,...m.map(q=>q.y+q.h+y)].sort((q,G)=>q-G);let O=null;e:for(const q of U)for(const G of L){if(G>=k)break;if(!w(q,G,I,P)){O={x:q,y:G};break e}}if(O){const q=O.x-S,G=O.y-k;for(const F of b){const j=c(F.id);n.set(F.id,{x:j.x+q,y:j.y+G})}N.push(_)}for(const q of b){const G=c(q.id),{w:F,h:j}=u(q.id);m.push({x:G.x,y:G.y,w:F,h:j})}}return N}function PD(e,n,r,i,o,l=!1,u){const p=ho+Xu+1,d=8,m=1.75,y=200,w=.7,N=.01,_=O=>Aa(O,i,u),b=O=>r.get(O)??n.get(O),S=new Map;for(const O of e){if(!b(O.id))continue;const q=ja(O),G=S.get(q);G?G.push(O):S.set(q,[O])}const k=[],E=new Set,C=new Set,I=o.size===0;for(const O of[...S.keys()].sort()){const q=S.get(O);let G=1/0,F=1/0,j=-1/0,B=-1/0,z=!1;for(const Q of q){const M=b(Q.id),{w:V,h:Y}=_(Q.id);G=Math.min(G,M.x),F=Math.min(F,M.y),j=Math.max(j,M.x+V),B=Math.max(B,M.y+Y),r.has(Q.id)&&(z=!0)}const ne=j-G,Z=B-F;C.add(O);const $=o.get(O);$&&(ne>$.w+d||Z>$.h+d)&&E.add(O),o.set(O,{w:ne,h:Z}),k.push({sid:O,members:q.map(Q=>Q.id),x:G,y:F,w:ne,h:Z,anchored:z,mass:1})}for(const O of[...o.keys()])C.has(O)||o.delete(O);if(l||I)return[];let P=!1;for(let O=0;O<k.length&&!P;O++)for(let q=O+1;q<k.length;q++){const G=k[O],F=k[q];if(!(G.anchored&&F.anchored)&&Math.abs(G.x+G.w/2-(F.x+F.w/2))<(G.w+F.w)/2+61&&Math.abs(G.y+G.h/2-(F.y+F.h/2))<(G.h+F.h)/2+p){P=!0;break}}if(E.size===0&&!P)return[];if(E.size>0)for(const O of k)E.has(O.sid)&&(O.mass=8);else for(const O of k)O.mass=Math.max(1,O.w*O.h/(wo*ku));const A=new Map(k.map(O=>[O.sid,O.x])),U=new Map(k.map(O=>[O.sid,O.y]));for(let O=0;O<y;O++){const q=new Map,G=new Map;let F=0;for(let j=0;j<k.length;j++)for(let B=j+1;B<k.length;B++){const z=k[j],ne=k[B];if(z.anchored&&ne.anchored)continue;const Z=z.x+z.w/2,$=z.y+z.h/2,Q=ne.x+ne.w/2,M=ne.y+ne.h/2,V=(z.w+ne.w)/2+61-Math.abs(Z-Q),Y=(z.h+ne.h)/2+p-Math.abs($-M);if(V<=0||Y<=0)continue;const H=($e,Je)=>!$e.anchored&&!(Je<0&&$e.x<=0),J=($e,Je)=>!$e.anchored&&!(Je<0&&$e.y<=0),re=($e,Je,Xe)=>{const vt=$e===Je,ot=vt?z.sid<ne.sid?-1:1:Math.sign($e-Je);return Xe(z,ot)||Xe(ne,-ot)?ot:vt&&(Xe(z,-ot)||Xe(ne,ot))?-ot:0},le=re(Z,Q,H),fe=re($,M,J),te=le!==0,ce=fe!==0;if(!te&&!ce)continue;const Ce=te&&(!ce||V*m<Y),[ve,je,ye,ke]=Ce?[le,V,q,H]:[fe,Y,G,J],Ke=ke(z,ve),we=ke(ne,-ve),_e=z.mass,Be=ne.mass,ft=Ke?we?Be/(_e+Be):1:0,ht=we?Ke?_e/(_e+Be):1:0,We=je*w;ye.set(z.sid,(ye.get(z.sid)??0)+ve*We*ft),ye.set(ne.sid,(ye.get(ne.sid)??0)-ve*We*ht),F+=We}for(const j of k)j.anchored||(j.x=Math.max(0,j.x+(q.get(j.sid)??0)),j.y=Math.max(0,j.y+(G.get(j.sid)??0)));if(F<N)break}const L=[];for(const O of k){const q=O.x-A.get(O.sid),G=O.y-U.get(O.sid);if(!(Math.abs(q)<1&&Math.abs(G)<1)){for(const F of O.members){if(r.has(F))continue;const j=n.get(F);j&&n.set(F,{x:j.x+q,y:j.y+G})}L.push(O.sid)}}return L}const LD=600;function Cv(e,n){return!(e.exitAt!=null&&n-e.exitAt>LD||e.kind==="root"&&e.state==="done"&&e.tools.length===0&&e.endedAt!=null&&e.endedAt-e.startedAt<3e3)}function qD(e,n){const r=new Set;for(const i of e.agents.values())Cv(i,n)&&r.add(i.id);return r}function $D(e,n,r=0){return e.right+r>n.left&&e.left-r<n.right&&e.bottom+r>n.top&&e.top-r<n.bottom}function DD(e,n,r=0){if(!e)return!1;for(const i of n)if($D(e,i,r))return!0;return!1}const NR="sessionGroup";function FD(e,n){var i;if(e.type===NR)return"transparent";const r=(i=e.data)==null?void 0:i.state;return n(r==="err"?"--err":r==="active"?"--inflight":"--ok")}const zD="Update checks are off (AGENTS_DECK_NO_UPDATE_CHECK=1).";function BD(e){if(e.checkDisabled)return zD;if(e.checking)return"Asking npm for the newest release…";const n=e.latest?`npm has v${e.latest}`:e.latestPending?`npm's latest tag names v${e.latestPending}, which it cannot serve yet`:"npm not reached yet",r=e.checkedAgo?` · checked ${e.checkedAgo}`:"";return`${n}${r} · re-checked periodically · click to check npm now`}function UD(e){const n=`Version v${e.running}`;return e.checkDisabled?`${n}, update checks are off`:e.checking?`${n}, checking npm for a newer release`:`${n}, check npm for a newer release`}function HD(e){if(e==null)return{kind:"unknown",lead:"No data yet. Start a Claude Code or Codex session — it appears here as soon as its first hook fires.",workspace:null,tail:""};const n=e.trim();return n===""?{kind:"machine",lead:"No data yet. Start a Claude Code or Codex session anywhere on this machine — this deck is unscoped and captures every workspace.",workspace:null,tail:""}:{kind:"scoped",lead:"No data yet. This deck only captures sessions running under",workspace:n,tail:" — start one there, or restart it without --workspace/--scope to watch the whole machine."}}function CR(e){const n=Math.max(0,Math.floor(e));return`${n} event${n===1?"":"s"}`}function WD(e){return e.connected?e.paused?{tone:"paused",label:"paused",title:e.held>0?`Connected — ${CR(e.held)} held until you resume (Space)`:"Connected — updates held until you resume (Space)"}:{tone:"live",label:"live",title:"Receiving events"}:{tone:"dead",label:"offline",title:e.paused?"SSE disconnected — and the canvas is paused, so resuming will not bring events back until it reconnects":"SSE disconnected"}}function VD(e){return e.paused?e.held<=0?{label:"Resume",title:"Nothing has arrived since you paused. Resume to follow the canvas again (Space)"}:{label:`Resume · ${e.held} held`,title:`${CR(e.held)} arrived while paused and will be applied in order when you resume (Space)`}:{label:"Pause",title:"Pause live updates — events keep arriving and are applied when you resume (Space)"}}function RR(e,n){return e!==""&&n>0}function GD(e,n,r){return e===""?{active:!1,matched:n,total:r,count:null,empty:!1,message:null,dim:!1}:{active:!0,matched:n,total:r,count:`${n} of ${r}`,empty:n===0,message:n===0?`No agents match “${e}”`:null,dim:RR(e,n)}}function Rv(e){const n=Math.max(0,Math.floor(e/1e3));return n<60?"just now":n<3600?`${Math.floor(n/60)}m ago`:n<86400?`${Math.floor(n/3600)}h ago`:`${Math.floor(n/86400)}d ago`}function YD(e,n){return e.getFullYear()===n.getFullYear()&&e.getMonth()===n.getMonth()&&e.getDate()===n.getDate()}function KD(e,n,r){const i=new Date(e),o=Rv(n-e);return{label:YD(i,new Date(n))?o:`${o} · ${i.toLocaleDateString(r,{month:"short",day:"numeric"})}`,title:i.toLocaleString(r,{dateStyle:"medium",timeStyle:"medium"})}}function ma(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const XD={agent:zP,sessionGroup:t3},TR="react-flow__node";function NE(e){var n,r;return!!e&&((r=(n=e.classList)==null?void 0:n.contains)==null?void 0:r.call(n,TR))===!0}function QD(e){try{const n=document.querySelector(`.${TR}[data-id="${CSS.escape(e)}"]`);n==null||n.focus({preventScroll:!0})}catch{}}const ZD=420,iu=18,JD=9e4,e5=200,t5=5*6e4,n5=6,r5=2*6e4,yy="agent-dag.layout",wy="agent-dag.viewport",jR="agent-dag.summariesDismissed",AR="agent-dag.sessionListOpen",IR="agent-dag.detailOpen",MR="agent-dag.usagePanelOpen",CE="agent-dag.accountsPanelOpen",RE="agent-dag.versionNoticeDismissed",TE="agent-dag.oldNameNoticeDismissed",s5=15*6e4,jE={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:"},AE="agent-dag.autoRestart",IE="agent-dag.bundleReloadedFor";function i5(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(AR)==="1"}catch{return!1}}function o5(e){if(!(typeof window>"u"))try{window.localStorage.setItem(AR,e?"1":"0")}catch{}}function a5(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(IR)==="1"}catch{return!1}}function l5(e){if(!(typeof window>"u"))try{window.localStorage.setItem(IR,e?"1":"0")}catch{}}function u5(){const e=kC(MR);return e===null?!0:e==="1"}function c5(e){if(!(typeof window>"u"))try{window.localStorage.setItem(MR,e?"1":"0")}catch{}}function d5(){if(typeof window>"u")return new Set;try{const e=window.localStorage.getItem(jR);if(!e)return new Set;const n=JSON.parse(e);return new Set(Array.isArray(n)?n.filter(r=>typeof r=="string"):[])}catch{return new Set}}function ME(e){if(!(typeof window>"u"))try{const n=Array.from(e),r=n.length>200?n.slice(-200):n;window.localStorage.setItem(jR,JSON.stringify(r))}catch{}}function f5(){const e={positions:[],pins:[]};if(typeof window>"u")return e;try{const n=window.localStorage.getItem(yy);if(!n)return e;const r=JSON.parse(n);if(!("v"in r)){const o=Object.entries(r).filter(([,l])=>l&&typeof l.x=="number"&&typeof l.y=="number");return{positions:o,pins:o.map(([l])=>l)}}return{positions:Object.entries(r.positions??{}).filter(([,o])=>o&&typeof o.x=="number"&&typeof o.y=="number"),pins:Array.isArray(r.pins)?r.pins:[]}}catch{return e}}function iv(e,n){if(!(typeof window>"u"))try{const r={};for(const[i,o]of e)r[i]=o;for(const[i,o]of n)r[i]=o;window.localStorage.setItem(yy,JSON.stringify({v:2,positions:r,pins:Array.from(n.keys())}))}catch{}}function h5(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(wy);if(!e)return null;const n=JSON.parse(e);return typeof(n==null?void 0:n.x)!="number"||typeof(n==null?void 0:n.y)!="number"||typeof(n==null?void 0:n.zoom)!="number"?null:n}catch{return null}}function p5(e){if(!(typeof window>"u"))try{window.localStorage.setItem(wy,JSON.stringify(e))}catch{}}function OE(){if(!(typeof window>"u")){try{window.localStorage.removeItem(yy)}catch{}try{window.localStorage.removeItem(wy)}catch{}}}function m5(e,n){const r=e.agents.get(n);if(!r)return;const i=[];for(const d of e.agents.values())d.sessionId===n&&i.push(d);const o={schemaVersion:1,exportedAt:new Date().toISOString(),sessionId:n,label:r.label,cwd:r.cwd,startedAt:r.startedAt,endedAt:r.endedAt,model:r.model,agents:i.map(d=>({id:d.id,kind:d.kind,label:d.label,parentId:d.parentId,state:d.state,startedAt:d.startedAt,endedAt:d.endedAt,model:d.model,cwd:d.cwd,usage:d.usage,prompts:d.prompts,tools:d.tools.map(m=>({id:m.id,name:m.name,inputPreview:m.inputPreview,startedAt:m.startedAt,endedAt:m.endedAt,ok:m.ok,errorPreview:m.errorPreview,usage:m.usage}))}))},l=JSON.stringify(o,null,2),u=new Blob([l],{type:"application/json"}),c=URL.createObjectURL(u),h=document.createElement("a"),p=(r.label||"session").replace(/[^a-z0-9._-]/gi,"_");h.href=c,h.download=`${tn}-${p}-${n.slice(0,8)}.json`,document.body.appendChild(h),h.click(),document.body.removeChild(h),setTimeout(()=>URL.revokeObjectURL(c),1e3)}const Tv={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},jv={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},g5={Read:"file",Write:"file",Edit:"file",MultiEdit:"file",Glob:"file",Grep:"file",LS:"file",NotebookEdit:"file",Bash:"shell",PowerShell:"shell",shell:"shell",exec_command:"shell",shell_command:"shell",write_stdin:"shell",wait:"shell",apply_patch:"file",update_plan:"task",WebFetch:"web",WebSearch:"web",Task:"agent",Agent:"agent",TodoWrite:"task",TaskCreate:"task",TaskUpdate:"task",TaskList:"task",TaskGet:"task",TaskOutput:"task",TaskStop:"task",EnterPlanMode:"plan",ExitPlanMode:"plan",AskUserQuestion:"plan",Skill:"plan",Workflow:"plan"};function OR(e){return e.startsWith("mcp__")?"mcp":g5[e]??"other"}function PR(e,n){var i,o,l;if(!n)return!0;const r=n.toLowerCase();if(e.label.toLowerCase().includes(r)||(i=e.cwd)!=null&&i.toLowerCase().includes(r)||(o=e.cwdBasename)!=null&&o.toLowerCase().includes(r)||e.sessionId.toLowerCase().includes(r)||(l=e.firstPrompt)!=null&&l.toLowerCase().includes(r))return!0;for(const u of e.tools)if(u.name.toLowerCase().includes(r))return!0;return!1}function v5(e,n){if(!n)return null;const r=new Set([n]);let i=n;for(;i;){const l=e.agents.get(i);if(!(l!=null&&l.parentId)||r.has(l.parentId))break;r.add(l.parentId),i=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 y5(e,n,r,i,o,l,u,c,h,p,d,m,y,w,N,_,b,S,k){const E=[],C=[],I=new Set;if(l)for(const F of e.agents.values())S.has(F.id)&&PR(F,l)&&I.add(F.id);const P=RR(l,I.size);for(const F of e.agents.values()){if(!S.has(F.id))continue;const j=P&&!I.has(F.id),B=F.exitAt!=null,z=b!=null&&!b.has(F.id),ne=[j?"rf-dim":"",B?"rf-exiting":"",z?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,Z=u.get(F.id);if(E.push({id:F.id,type:"agent",position:{x:0,y:0},data:{...F,now:n,onOpenContext:k},className:ne,...Z?{width:Z.width,height:Z.height}:null}),F.parentId&&S.has(F.parentId)){const $=Kv(F.sessionId),Q=l&&!I.has(F.id)&&!I.has(F.parentId),M=B,V=_.size>0&&(_.has(F.id)||_.has(F.parentId)),Y=b!=null&&!b.has(F.id)&&!b.has(F.parentId),H=F.state==="active"?2:1.5,J=V?H+1.5:H,re=Q||M?.2:Y?.12:1,le=["sess-edge",F.state==="active"?"sess-live":"sess-idle",M?"rf-edge-exiting":"",V?"rf-edge-selected":""].filter(Boolean).join(" ");C.push({id:`e:${F.parentId}->${F.id}`,source:F.parentId,target:F.id,animated:(F.state==="active"||V)&&!Q&&!M,type:"smoothstep",style:{"--session-hue":$,strokeWidth:J,opacity:re,transition:"opacity 500ms ease, stroke-width 200ms ease"},className:le})}}const A=new Map;for(const F of e.agents.values())F.tools.length>0&&A.set(F.id,Math.min(4,F.tools.length));const U=`${w}#lanes:${jD(A)}`,L=E.filter(F=>zL(F.id,o,m,y));if(L.length>0||U!==N.current){if(L.length>0){const F=ID(E,C,{direction:"LR",pinned:o,measured:u,availableWidth:r,availableHeight:i,lanes:A});for(const j of F)SC(j.id,m,y)&&UL(j.id,j.position,m,y);OD(E,m,o,u,new Set(L.map(j=>j.id)),A)}MD(E,m,o,u,A),N.current=U}const O=PD(E,m,o,u,c,!p||d,A);O.length>0&&h(O),tu(m,e.agents),tu(y,e.agents),tu(o,e.agents),tu(u,FL(e.agents.values()));const q=[];let G=!1;for(const F of E){let j=o.get(F.id)??m.get(F.id);j||(j=BL(F.id,m,y),G=!0),q.push({...F,position:j})}return G&&(N.current=""),{nodes:q,edges:C}}function w5(){return g.jsx(Yv,{children:g.jsx(x5,{})})}function x5(){var Ha,Wa,Ai,Va;const e=La(),n=T.useRef(bv()),[,r]=T.useState(0),i=T.useCallback(()=>r(W=>W+1),[]),[o,l]=T.useState(()=>new Set),[u,c]=T.useState(null),[h,p]=T.useState(null),d=T.useCallback((W,K)=>{l(ae=>{if(!K)return new Set([W]);const de=new Set(ae);return de.has(W)?de.delete(W):de.add(W),de}),c(ae=>K&&ae===W?ae:W)},[]),m=T.useCallback(()=>{l(new Set),c(null)},[]),[y,w]=T.useState(null),[N,_]=T.useState(null),b=T.useCallback(W=>_(W),[]),[S,k]=T.useState(!1),E=T.useRef(d5()),[C,I]=T.useState(i5);T.useEffect(()=>{o5(C)},[C]);const[P,A]=T.useState(a5);T.useEffect(()=>{l5(P)},[P]);const[U,L]=T.useState(u5);T.useEffect(()=>{c5(U)},[U]);const[O,q]=T.useState(()=>{try{const W=window.localStorage.getItem(CE);return W===null?!0:W==="1"}catch{return!0}});T.useEffect(()=>{try{window.localStorage.setItem(CE,O?"1":"0")}catch{}},[O]);const[G,F]=T.useState(null),[j,B]=T.useState(!1),[z,ne]=T.useState(0),[Z,$]=T.useState(0);T.useEffect(()=>{fetch("/api/sound-hook").then(W=>W.ok?W.json():null).then(W=>{W!=null&&W.ok&&(F(W.enabled===!0),ne((W.foreign??[]).filter(K=>K.worksHere).length),$(typeof W.parked=="number"?W.parked:0))}).catch(()=>{})},[]);const Q=T.useCallback(async()=>{B(!0);try{const K=await(await fetch("/api/sound-hook",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!G})})).json().catch(()=>null);K!=null&&K.ok&&F(K.enabled===!0),fetch("/api/sound-hook").then(ae=>ae.ok?ae.json():null).then(ae=>{ae!=null&&ae.ok&&(ne((ae.foreign??[]).filter(de=>de.worksHere).length),$(typeof ae.parked=="number"?ae.parked:0))}).catch(()=>{})}catch{}finally{B(!1)}},[G]),[M,V]=T.useState(!1),[Y,H]=T.useState(null),[J,re]=T.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(RE)??""}catch{return""}}),[le,fe]=T.useState(!1),te=T.useRef(0),[ce,Ce]=T.useState(!1),ve=T.useCallback((W=!1)=>{W&&(te.current=Date.now(),Ce(!0)),fetch(W?"/api/version?refresh=1":"/api/version").then(K=>K.ok?K.json():null).then(K=>{K&&H(K)}).catch(()=>{}).finally(()=>{W&&Ce(!1)})},[]),je=T.useCallback(()=>{ve(Date.now()-te.current>=s5)},[ve]);T.useEffect(()=>{ve();const W=window.setInterval(je,5*6e4),K=()=>{document.visibilityState==="visible"&&je()};return document.addEventListener("visibilitychange",K),()=>{window.clearInterval(W),document.removeEventListener("visibilitychange",K)}},[ve,je]),T.useEffect(()=>{M&&ve()},[M,ve]);const ye=(Y==null?void 0:Y.notice)??null,[ke,Ke]=T.useState(null);T.useEffect(()=>{let W=!1;return fetch("/api/health").then(K=>K.ok?K.json():null).then(K=>{W||!K||typeof K.workspace!="string"||Ke(K.workspace)}).catch(()=>{}),()=>{W=!0}},[M]);const we=ye?`${ye.kind}:${ye.to}`:"",_e=ye!=null&&J!==we,Be=T.useCallback(()=>{if(!ye)return;const W=J===we?"":we;re(W);try{window.localStorage.setItem(RE,W)}catch{}},[ye,we,J]),[ft,ht]=T.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(TE)??""}catch{return""}}),We=Y!=null&&Y.invokedAs&&Y.invokedAs!==tn?Y.invokedAs:null,$e=We!=null&&ft!==We,Je=T.useCallback(()=>{if(We){ht(We);try{window.localStorage.setItem(TE,We)}catch{}}},[We]),Xe=((Ha=Y==null?void 0:Y.upgrade)==null?void 0:Ha.state)??"idle",vt=TL(Y==null?void 0:Y.upgrade),ot=T.useCallback(async()=>{try{await fetch("/api/upgrade",{method:"POST"})}catch{}ve()},[ve]);T.useEffect(()=>{if(Xe!=="running")return;const W=window.setInterval(ve,3e3);return()=>window.clearInterval(W)},[Xe,ve]);const yt=T.useCallback(async()=>{var ae;const W=Y==null?void 0:Y.command;if(!W)return;let K=!1;try{K=await Promise.race([((ae=navigator.clipboard)==null?void 0:ae.writeText(W).then(()=>!0))??Promise.resolve(!1),new Promise(de=>window.setTimeout(()=>de(!1),500))])}catch{K=!1}if(!K)try{const de=document.createElement("textarea");de.value=W,de.setAttribute("readonly",""),de.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(de),de.select(),K=document.execCommand("copy"),de.remove()}catch{K=!1}K&&(fe(!0),window.setTimeout(()=>fe(!1),1600))},[Y==null?void 0:Y.command]),Gt=T.useCallback(()=>{I(W=>(W||q(!1),!W))},[]),It=T.useCallback(()=>{q(W=>(W||I(!1),!W))},[]),[Ze,wt]=T.useState(!1),[pt,mt]=T.useState(0),_n=T.useRef(null),[Yt,Mt]=T.useState(!1),Kt=T.useRef(null),[yr,bn]=T.useState(0),Xt=T.useRef(GL()),[pn,Sn]=T.useState(!1),Gr=T.useCallback(()=>{const W=Xt.current,K=W.setPaused(!W.paused);for(const ae of K)n.current=Mx(n.current,ae);Sn(W.paused)},[]),[ut,hi]=T.useState(Date.now()),[rr,ks]=T.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(AE)!=="0"}catch{return!0}}),pi=T.useCallback(()=>{ks(W=>{const K=!W;try{window.localStorage.setItem(AE,K?"1":"0")}catch{}return K})},[]),[Qt,sr]=T.useState(!1),[wr,No]=T.useState("restart"),[ir,xr]=T.useState(null),mn=T.useRef(!1),Yr=T.useRef(null),mi=T.useRef(0),Kr=T.useCallback(async W=>{if(mn.current)return;const K=(W==null?void 0:W.upgrade)===!0;mn.current=!0,Yr.current=vt;const ae=++mi.current;No(K?"npx":"restart"),sr(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(ye==null?void 0:ye.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:K})})}catch{}window.setTimeout(()=>{if(mi.current===ae&&mn.current){mn.current=!1,sr(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},K?18e4:3e4)},[ye==null?void 0:ye.to,vt]),Es=T.useRef(null);T.useEffect(()=>{let W=!1;for(const ae of n.current.agents.values())if(ae.state==="active"){W=!0;break}const K=AL({enabled:rr,kind:ye==null?void 0:ye.kind,canRestart:(Y==null?void 0:Y.canRestart)===!0,busy:W,idleSince:Es.current,now:ut});Es.current=K.idleSince,K.restart&&Kr()},[rr,ye==null?void 0:ye.kind,Y==null?void 0:Y.canRestart,ut,Kr]),T.useEffect(()=>{const W=Y==null?void 0:Y.running;let K=null,ae=null;try{K=window.sessionStorage.getItem("agent-dag.restartPending"),ae=window.sessionStorage.getItem(IE)}catch{return}const de=RL({bundle:"1.34.6",running:W,pending:K,lastTried:ae});if(de==="reload"){try{window.sessionStorage.setItem(IE,W??"")}catch{return}window.location.reload();return}if(de!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}mn.current=!1,sr(!1),xr(W??null);const xe=window.setTimeout(()=>xr(null),6e3);return()=>window.clearTimeout(xe)},[Y==null?void 0:Y.running]),T.useEffect(()=>{if(Qt&&jL({asked:Yr.current,reported:vt})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}mn.current=!1,sr(!1)}},[Qt,vt]);const gn=T.useRef(f5()).current;T.useRef(!1);const Rt=T.useRef(new Map(gn.positions.filter(([W])=>gn.pins.includes(W)))),_r=T.useRef(null),Xr=T.useState(()=>h5())[0],[Zt,Qr]=T.useState(""),[Ns,gi]=T.useState(()=>new Set),[or,vi]=T.useState(ZL),[et,Co]=T.useState(!1),br=T.useRef(null);T.useEffect(()=>{document.documentElement.dataset.theme=or;try{window.localStorage.setItem(EC,or)}catch{}},[or]),T.useEffect(()=>{if(!Xr)return;const W=window.setTimeout(()=>{try{e.setViewport(Xr,{duration:0})}catch{}},60);return()=>window.clearTimeout(W)},[e,Xr]);const Cs=T.useRef(!0);T.useEffect(()=>{const W=new EventSource("/events"),K=VL(i,{now:()=>Date.now(),setTimeout:(ae,de)=>window.setTimeout(ae,de),clearTimeout:ae=>window.clearTimeout(ae)});return W.addEventListener("open",()=>{V(!0),Co(!0)}),W.addEventListener("error",()=>V(!1)),W.addEventListener("replay-end",()=>{Cs.current=!1,K.flush()}),W.addEventListener("hook",ae=>{try{const de=JSON.parse(ae.data);if(!Xt.current.accept(de))return;n.current=Mx(n.current,de),de.replay===!0||Cs.current||Date.now()-de.receivedAt>3e4?K.replay():K.live()}catch{}}),()=>{W.close(),K.cancel()}},[i]),T.useEffect(()=>{const W=setInterval(()=>{const K=Date.now();hi(K);let ae=aP(n.current,K,JD);uP(n.current,K,lP)&&(ae=!0),iP(n.current,K,e5,t5)&&(ae=!0),oP(n.current,K,n5,r5)&&(ae=!0),ae&&i()},250);return()=>clearInterval(W)},[i]);const ar=T.useRef(null),$n=T.useRef(0),yi=420,Ot=T.useCallback((W=500)=>{try{const Ee=document.querySelector(".canvas-wrap"),Pe=Array.from(document.querySelectorAll(".react-flow__node")).filter(xt=>xt.offsetWidth>0);if(!Ee||Pe.length===0)return;const De=Ee.getBoundingClientRect(),Ye=e.getViewport();if(!Number.isFinite(Ye.zoom)||Ye.zoom<=0)return;const Ue=xt=>(xt-De.left-Ye.x)/Ye.zoom,Fe=xt=>(xt-De.top-Ye.y)/Ye.zoom,Nn=Pe.map(xt=>xt.getBoundingClientRect()),Fs=Math.min(...Nn.map(xt=>Ue(xt.left))),Ii=Math.max(...Nn.map(xt=>Ue(xt.right))),zs=Math.min(...Nn.map(xt=>Fe(xt.top))),$o=Math.max(...Nn.map(xt=>Fe(xt.bottom))),Ga=Ii-Fs,Mi=$o-zs;if(!(Ga>0&&Mi>0))return;const Un=Math.max(.2,Math.min(1,(De.width-160)/(Ga+yi)*.86,(De.height-160)/Mi*.86));e.setViewport({x:80-Fs*Un,y:Math.max(80,(De.height-Mi*Un)/2)-zs*Un,zoom:Un},{duration:W}),$n.current=Date.now(),window.setTimeout(()=>{try{const xt={x:80-Fs*Un,y:Math.max(80,(De.height-Mi*Un)/2)-zs*Un,zoom:Un},Ya=e.getViewport();(Math.abs(Ya.zoom-Un)>.01||Math.abs(Ya.x-xt.x)>2)&&e.setViewport(xt,{duration:0})}catch{}},W+60)}catch{}},[e]),zt=T.useRef(""),Sr=T.useRef(null),nn=T.useRef(0),wi=T.useCallback(()=>{nn.current=Date.now()},[]),Ro="agent-dag.autoFitDisabled",kr=T.useRef((()=>{if(typeof window>"u")return!1;try{return window.localStorage.getItem(Ro)==="1"}catch{return!1}})()),[Rs,Ts]=T.useState(kr.current),Zr=T.useCallback(()=>{if(!kr.current){kr.current=!0,Ts(!0);try{window.localStorage.setItem(Ro,"1")}catch{}}},[]),xi=T.useCallback(()=>{kr.current=!1,Ts(!1);try{window.localStorage.removeItem(Ro)}catch{}Ot(400)},[e,Ot]);T.useEffect(()=>{const W=setInterval(()=>{if(kr.current||Date.now()-nn.current<800)return;const K=n.current,ae=Date.now(),de=[];for(const Ue of K.agents.values())Cv(Ue,ae)&&de.push({id:Ue.id});if(de.length===0)return;const xe=e.getViewport(),Ee=window.innerWidth-360,Pe=window.innerHeight-52;let De=!1,Ye=!1;for(const{id:Ue}of de){const Fe=Jr.current.get(Ue),Nn=Rt.current.get(Ue)??Bt.current.get(Ue);if(!Fe||!Nn)continue;Ye=!0;const Fs=Nn.x*xe.zoom+xe.x,Ii=Nn.y*xe.zoom+xe.y,zs=(Nn.x+Fe.width)*xe.zoom+xe.x,$o=(Nn.y+Fe.height)*xe.zoom+xe.y;if(zs>0&&Fs<Ee&&$o>0&&Ii<Pe){De=!0;break}}Ye&&!De&&Ot(600)},1500);return()=>clearInterval(W)},[e]);const To=T.useRef(!1),Jr=T.useRef(new Map),_i=T.useRef(0),Ua=T.useCallback(W=>{const K=Jr.current;let ae=!1;for(const de of W.nodeInternals.values()){const xe=de.width,Ee=de.height;if(xe==null||Ee==null)continue;const Pe=K.get(de.id);Pe?(Math.abs(Pe.height-Ee)>4||Math.abs(Pe.width-xe)>4)&&(K.set(de.id,{width:xe,height:Ee}),ae=!0):(K.set(de.id,{width:xe,height:Ee}),ae=!0)}return ae&&(_i.current+=1),_i.current},[]),bi=Qe(Ua),[es,Qu]=T.useState(0);T.useEffect(()=>{let W=0;const K=()=>{const de=Jr.current;let xe=!1;for(const Ee of document.querySelectorAll(".react-flow__node[data-id]")){const Pe=Ee.getAttribute("data-id");if(!Pe)continue;const De=Ee.offsetWidth,Ye=Ee.offsetHeight;if(!De||!Ye)continue;const Ue=de.get(Pe);(!Ue||Math.abs(Ue.width-De)>4||Math.abs(Ue.height-Ye)>4)&&(de.set(Pe,{width:De,height:Ye}),xe=!0)}xe&&Qu(Ee=>Ee+1)};if(To.current)return;let ae=0;return document.visibilityState==="hidden"?ae=window.setTimeout(K,32):W=requestAnimationFrame(K),()=>{cancelAnimationFrame(W),window.clearTimeout(ae)}});const Bt=T.useRef(new Map(gn.positions)),Ge=T.useRef(new Set),Si=T.useRef(""),Er=T.useMemo(()=>{const W=[];for(const K of n.current.agents.values())Cv(K,ut)&&W.push(K.id+(K.parentId?`>${K.parentId}`:""));return W.sort(),`${W.join("|")}#sv${bi}.${es}`},[n.current,n.current.lastSeq,ut,bi,es]),Nr=T.useRef(null);T.useEffect(()=>(Nr.current!=null&&window.clearTimeout(Nr.current),Nr.current=window.setTimeout(()=>{iv(Bt.current,Rt.current)},1500),()=>{Nr.current!=null&&window.clearTimeout(Nr.current)}),[Er]),T.useEffect(()=>{if(zt.current===Er)return;const W=zt.current;if(zt.current=Er,!W||kr.current)return;Date.now()-$n.current>1200&&Ot(400),ar.current&&window.clearTimeout(ar.current),ar.current=window.setTimeout(()=>{kr.current||Ot(500)},280)},[Er,e,Ot]);const ki=T.useMemo(()=>{if(o.size===0)return null;const W=new Set;for(const K of o){const ae=v5(n.current,K);if(ae)for(const de of ae)W.add(de)}return W.size>0?W:null},[n.current,n.current.lastSeq,o]),lr=T.useMemo(()=>qD(n.current,ut),[n.current,n.current.lastSeq,ut]),jo=T.useRef(null),[ts,js]=T.useState({w:0,h:0});T.useEffect(()=>{const W=jo.current;if(!W||typeof ResizeObserver>"u")return;const K=new ResizeObserver(ae=>{var xe;const de=(xe=ae[0])==null?void 0:xe.contentRect;de&&js(Ee=>Math.abs(Ee.w-de.width)>40||Math.abs(Ee.h-de.height)>40?{w:de.width,h:de.height}:Ee)});return K.observe(W),js({w:W.clientWidth,h:W.clientHeight}),()=>K.disconnect()},[]);const ur=T.useRef(new Map),[Dn,cr]=T.useState(!1);T.useEffect(()=>{const W=window.setTimeout(()=>cr(!0),2500);return()=>window.clearTimeout(W)},[]);const[As,Cr]=T.useState(!1),Pt=T.useRef(null),[Ao,Io]=T.useState(!1),Is=T.useCallback(()=>{Pt.current&&(window.clearTimeout(Pt.current),Pt.current=null),Cr(!1)},[]),Zu=T.useCallback(W=>{W.length!==0&&queueMicrotask(()=>{Cr(!0),Pt.current&&window.clearTimeout(Pt.current),Pt.current=window.setTimeout(()=>Cr(!1),ZD+80)})},[]);T.useEffect(()=>()=>{Pt.current&&window.clearTimeout(Pt.current)},[]);const Mo=ts.w>0?ts.w*.92:0,Ms=ts.h>0?ts.h:0,{nodes:Fn,edges:Ju}=T.useMemo(()=>y5(n.current,ut,Mo,Ms,Rt.current,Zt,Jr.current,ur.current,Zu,Dn,Ao,Bt.current,Ge.current,Er,Si,o,ki,lr,b),[n.current,n.current.lastSeq,ut,Mo,Ms,Dn,Ao,Zt,Er,o,ki,lr,b,pt]),ns=T.useMemo(()=>{const W=new Map;for(const ae of Fn){const de=ae.data;if(!(de!=null&&de.sessionId)||de.exitAt!=null)continue;const xe=ae.width,Ee=ae.height;if(xe==null||Ee==null)continue;const Pe=ae.position.x,De=ae.position.y,Ye=Pe+xe,Ue=De+Ee,Fe=W.get(de.sessionId);Fe?(Fe.minX=Math.min(Fe.minX,Pe),Fe.minY=Math.min(Fe.minY,De),Fe.maxX=Math.max(Fe.maxX,Ye),Fe.maxY=Math.max(Fe.maxY,Ue)):W.set(de.sessionId,{minX:Pe,minY:De,maxX:Ye,maxY:Ue})}const K=[];for(const[ae,de]of W){const xe=de.maxX-de.minX+iu*2,Ee=de.maxY-de.minY+iu*2;K.push({id:`group:${ae}`,type:NR,position:{x:de.minX-iu,y:de.minY-iu},data:{sessionId:ae,w:xe,h:Ee},width:xe,height:Ee,style:{width:xe,height:Ee},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return K},[Fn,ut]),Os=T.useMemo(()=>{const W=[...ns,...Fn],K=Kt.current;return!K||K.size===0?W:W.map(ae=>{const de=K.get(ae.id);return de?{...ae,position:de}:ae})},[ns,Fn,yr]),kn=T.useMemo(()=>{if(!Zt)return null;const W=new Set;for(const K of n.current.agents.values())lr.has(K.id)&&PR(K,Zt)&&W.add(K.id);return W},[n.current,n.current.lastSeq,Zt,lr]),En=T.useMemo(()=>GD(Zt,(kn==null?void 0:kn.size)??0,lr.size),[Zt,kn,lr]),Ei=T.useMemo(()=>{const W=new Set;for(const K of n.current.agents.values())for(const ae of K.tools)W.add(OR(ae.name));return Object.keys(Tv).filter(K=>W.has(K))},[n.current,n.current.lastSeq]);T.useEffect(()=>{if(Ei.length<=1){Mt(!1);return}let W=0;const K=()=>{const ae=_n.current;if(ae&&!document.hidden){const de=ae.getBoundingClientRect(),xe=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Pe=>Pe.getBoundingClientRect()),Ee=DD(de,xe,8);Mt(Pe=>Pe===Ee?Pe:Ee)}W=window.setTimeout(K,300)};return K(),()=>window.clearTimeout(W)},[Ei.length]);const Ps=T.useMemo(()=>{const W=new Map;for(const ae of n.current.agents.values())for(const de of ae.tools){if(!de.name.startsWith("mcp__"))continue;const xe=de.name.slice(5),Ee=xe.indexOf("__"),Pe=Ee>0?xe.slice(0,Ee):xe;W.set(Pe,(W.get(Pe)??0)+1)}const K=[];for(const[ae,de]of W){let xe=5381;for(let Ee=0;Ee<ae.length;Ee++)xe=(xe<<5)+xe^ae.charCodeAt(Ee);K.push({server:ae,count:de,hue:Math.abs(xe)%360})}return K.sort((ae,de)=>de.count-ae.count),K},[n.current,n.current.lastSeq]),Oo=T.useCallback(W=>{gi(K=>{const ae=new Set(K);return ae.has(W)?ae.delete(W):ae.add(W),ae})},[]),St=u?n.current.agents.get(u):null,Ls=h?Array.from(n.current.agents.values()).flatMap(W=>W.tools).find(W=>W.id===h)??null:null,Po=T.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}n.current=bv(),Rt.current.clear(),Jr.current.clear(),Bt.current.clear(),Si.current="",OE(),m(),i()},[i,m]),zn=T.useRef(S);zn.current=S;const Ni=T.useRef(!1);Ni.current=Ls!=null||Ze||N!=null||y!=null;const Rr=T.useCallback(W=>{const K=ML(W,{confirmOpen:zn.current,modalOpen:Ni.current});K==="confirm"?k(!0):K==="clear"&&(k(!1),Po())},[Po]),Ci=T.useCallback(()=>{Rt.current.clear(),Bt.current.clear(),Si.current="",OE(),i(),window.setTimeout(()=>Ot(500),80)},[i,e,Ot]),qs=T.useCallback(()=>Ot(500),[Ot]),Tr=T.useRef(Fn);Tr.current=Fn;const Lo=T.useRef(u);Lo.current=u;const Lt=T.useCallback(W=>{const K=Tr.current,ae=PL(K.map(Ee=>({id:Ee.id,x:Ee.position.x,y:Ee.position.y})),Lo.current,W),de=ae?K.find(Ee=>Ee.id===ae):void 0;if(!de)return;const xe=NE(document.activeElement);d(de.id,!1),window.setTimeout(()=>{try{e.fitView({padding:.35,duration:350,nodes:[de]})}catch{}$n.current=Date.now(),xe&&QD(de.id)},30)},[d,e]),jr=T.useCallback(W=>{d(W,!1),window.setTimeout(()=>{try{const K=Tr.current.find(ae=>ae.id===W);K&&e.fitView({padding:.3,duration:500,nodes:[K]}),$n.current=Date.now()}catch{}},60)},[d,e]);T.useEffect(()=>{const W=K=>{var De,Ye,Ue;const ae=K.target,de={tagName:ae==null?void 0:ae.tagName,isContentEditable:ae==null?void 0:ae.isContentEditable,role:(De=ae==null?void 0:ae.getAttribute)==null?void 0:De.call(ae,"role"),type:ae==null?void 0:ae.type};if(K.key==="Escape"){const Fe=EP({overlayOpen:bu.depth()>0,typing:Qv(de)});Fe==="dismiss"?bu.dismissTop():Fe==="blur"?ae==null||ae.blur():(DL(de)&&(ae==null||ae.blur()),m());return}if(hC(K))return;const xe=NE(ae)?(Ye=ae==null?void 0:ae.getAttribute)==null?void 0:Ye.call(ae,"data-id"):null,Ee=xe&&Tr.current.some(Fe=>Fe.id===xe)?xe:null,Pe=qL(K,Ee);if(Pe.kind==="activate"){K.preventDefault(),d(Pe.nodeId,Pe.additive);return}if(Pe.kind!=="node"&&!(Pe.nodeId==null&&MP(de))){if(K.key==="/"){K.preventDefault(),(Ue=br.current)==null||Ue.focus();return}K.key===" "&&(K.preventDefault(),Gr()),(K.key==="c"||K.key==="C")&&Rr("shortcut"),(K.key==="r"||K.key==="R")&&Ci(),(K.key==="f"||K.key==="F")&&qs(),(K.key==="l"||K.key==="L")&&Gt(),(K.key==="h"||K.key==="H")&&wt(Fe=>!Fe),(K.key==="u"||K.key==="U")&&L(Fe=>!Fe),(K.key==="a"||K.key==="A")&&It(),(K.key==="j"||K.key==="J")&&Lt(1),(K.key==="k"||K.key==="K")&&Lt(-1),(K.key==="t"||K.key==="T")&&vi(Fe=>Fe==="dark"?"light":"dark")}};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[Rr,Ci,qs,m,d,Lt,Gr]);const Ar=n.current.agents.size,$s=new Set(Array.from(n.current.agents.values()).map(W=>W.sessionId)).size,Bn=T.useMemo(()=>P3(n.current.agents.values()),[n.current,n.current.lastSeq]),Ri=T.useMemo(()=>L3(n.current.agents.values()),[n.current,n.current.lastSeq]),Ti=T.useRef(null);T.useEffect(()=>{const W=JL({waiting:Bn.length,running:Ri}),K=Ti.current;if(Ti.current=W,(K==null?void 0:K.title)!==W.title&&(document.title=W.title),(K==null?void 0:K.icon)!==W.icon){const ae=document.querySelector('link[rel="icon"]');ae&&(ae.href=eq[W.icon])}},[Bn.length,Ri]);const[Ds,ji]=T.useState(""),qo=nq(Bn);T.useEffect(()=>{ji(W=>rq(W,qo))},[qo]);const rn=T.useMemo(()=>{let W=0,K=0,ae=0,de=0,xe=0,Ee=0,Pe=0,De=0,Ye=0;for(const Ue of n.current.agents.values()){W+=Ue.usage.inputTokens,K+=Ue.usage.outputTokens,ae+=Ue.usage.cacheReadTokens,de+=Ue.usage.cacheCreateTokens;const Fe=fn(Ue.usage,Ue.model);xe+=Fe.total,Ee+=Fe.input,Pe+=Fe.output,De+=Fe.cacheRead,Ye+=Fe.cacheWrite}return{inT:W,outT:K,cacheR:ae,cacheC:de,sum:W+K,cost:{total:xe,input:Ee,output:Pe,cacheRead:De,cacheWrite:Ye}}},[n.current,n.current.lastSeq]);return g.jsxs("div",{className:"app",children:[g.jsxs("header",{className:"topbar",children:[g.jsxs("div",{className:"brand",children:[g.jsx("span",{className:"logo"}),tn,ye?g.jsxs("button",{type:"button",className:"v stale",onClick:Be,title:ye.kind==="restart"?`Running v${ye.from}; v${ye.to} is installed on disk. Restart to pick it up.`:`Running v${ye.from}; v${ye.to} is on npm.`,children:["v",ye.from,g.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const W={running:(Y==null?void 0:Y.running)??"1.34.6",latest:Y==null?void 0:Y.latest,latestPending:Y==null?void 0:Y.latestPending,checkedAgo:Y!=null&&Y.checkedAt?Rv(ut-Y.checkedAt):null,checkDisabled:Y==null?void 0:Y.checkDisabled,checking:ce};return g.jsxs("button",{type:"button",className:ce?"v checking":"v",onClick:()=>ve(!0),"aria-busy":ce||void 0,"aria-label":UD(W),title:BD(W),children:["v",W.running]})})()]}),St&&(()=>{const W=fn(St.usage,St.model),K=Math.max(0,((St.endedAt??ut)-St.startedAt)/1e3),ae=St.state==="active"?_u(W.total,K):null,de=o.size-1;return g.jsxs("button",{type:"button",className:"selected-ribbon",title:`Fit view to ${St.label}`,onClick:()=>{try{const xe=Fn.find(Ee=>Ee.id===St.id);xe&&e.fitView({padding:.35,duration:500,nodes:[xe]}),$n.current=Date.now()}catch{}},children:[g.jsx("span",{className:`state-pill state-${St.state}`,children:St.state==="active"?"live":St.state}),g.jsx("span",{className:"selected-label",children:St.label}),W.total>0&&g.jsxs("span",{className:"selected-cost",children:[ze(W.total),ae?g.jsxs("span",{className:"selected-rate",children:[" · ",ae]}):null]}),de>0&&g.jsxs("span",{className:"selected-extra",children:["+",de]}),g.jsx("span",{"aria-hidden":!0,className:"selected-close",onClick:xe=>{xe.stopPropagation(),m()},children:"×"})]})})(),g.jsxs("div",{className:"actions",children:[g.jsxs("div",{className:"search",children:[g.jsx("span",{className:"search-icon","aria-hidden":!0,children:"⌕"}),g.jsx("input",{ref:br,type:"text",placeholder:"Search agents, cwd, tools…",value:Zt,onChange:W=>Qr(W.target.value),spellCheck:!1,"aria-label":"Filter the graph"}),Zt?g.jsx("button",{className:"search-clear","aria-label":"Clear search",onClick:()=>Qr(""),children:"×"}):g.jsx("kbd",{className:"search-kbd","aria-hidden":!0,children:"/"}),En.count&&g.jsx("span",{className:`search-count${En.empty?" none":""}`,"aria-live":"polite",title:`${En.count} agents on the canvas match “${Zt}”`,children:En.count})]}),g.jsxs("span",{className:"status",children:[(()=>{const W=WD({connected:M,paused:pn,held:Xt.current.size});return g.jsx("span",{className:`pill ${W.tone}`,title:W.title,children:W.label})})(),g.jsxs("span",{className:"stat",title:"Distinct CC sessions",children:[g.jsx("span",{className:"count",children:$s}),g.jsx("span",{className:"lbl",children:"sessions"})]}),g.jsxs("span",{className:"stat",title:"Total agents (root + subagents)",children:[g.jsx("span",{className:"count",children:Ar}),g.jsx("span",{className:"lbl",children:"agents"})]}),g.jsxs("span",{className:"stat",title:"Total hook events received",children:[g.jsx("span",{className:"count",children:n.current.totalEvents}),g.jsx("span",{className:"lbl",children:"events"})]}),rn.sum>0&&g.jsxs("span",{className:"stat",title:`in:${rn.inT.toLocaleString()} out:${rn.outT.toLocaleString()} cache-r:${rn.cacheR.toLocaleString()} cache-c:${rn.cacheC.toLocaleString()}`,children:[g.jsx("span",{className:"count",children:Dt(rn.sum)}),g.jsx("span",{className:"lbl",children:"tokens"})]}),Ps.length>0&&g.jsxs("span",{className:"stat mcp-legend",title:`MCP servers seen this session:
|
|
62
62
|
${Ps.map(W=>` ${W.server}: ${W.count} call${W.count===1?"":"s"}`).join(`
|
|
63
63
|
`)}`,children:[Ps.slice(0,6).map(W=>g.jsx("span",{className:"mcp-dot",style:{"--mcp-hue":W.hue}},W.server)),Ps.length>6&&g.jsxs("span",{className:"mcp-more",children:["+",Ps.length-6]}),g.jsx("span",{className:"lbl",children:"mcp"})]}),rn.cost.total>0&&(()=>{let W=0,K=0;for(const xe of n.current.agents.values()){if(xe.state!=="active")continue;const Ee=fn(xe.usage,xe.model);W+=Ee.total,K=Math.max(K,((xe.endedAt??ut)-xe.startedAt)/1e3)}const ae=K>0?_u(W,K):null,de=`input ${ze(rn.cost.input)} + output ${ze(rn.cost.output)} + cache r ${ze(rn.cost.cacheRead)} + cache w ${ze(rn.cost.cacheWrite)}${ae?`
|
|
64
64
|
active burn: ${ae}`:""}`;return g.jsxs("span",{className:"stat",title:de,children:[g.jsx("span",{className:"count",children:ze(rn.cost.total)}),g.jsxs("span",{className:"lbl",children:["cost",ae?` · ${ae}`:""]})]})})()]}),g.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Ds}),Bn.length>0&&g.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>jr(Bn[0].id),title:`Blocked waiting for you — click to go to the one that has been stuck longest:
|