@wrongstack/webui-hq 0.285.0 → 0.287.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/assets/alerts-kbWAfhjN.js +1 -0
- package/dist/assets/brain-CayB2b6L.js +1 -0
- package/dist/assets/cockpit-BWjbppJO.js +1 -0
- package/dist/assets/control-yKYUP4dT.js +1 -0
- package/dist/assets/cost-6_nyzxV1.js +1 -0
- package/dist/assets/fleet-map-CRWXjQLl.js +7 -0
- package/dist/assets/fleet-topology-bqBx4MWN.js +15 -0
- package/dist/assets/hq-local-prefs-s3e1p-3z.js +1 -0
- package/dist/assets/icons-C96v59MH.js +1 -0
- package/dist/assets/index-CMcQz_5E.css +1 -0
- package/dist/assets/index-CnjW7pne.js +2 -0
- package/dist/assets/live-console-B1fJ3RK5.js +1 -0
- package/dist/assets/mailbox-Ds-0XIKq.js +1 -0
- package/dist/assets/manrope-cyrillic-wght-normal-Dvxsihut.woff2 +0 -0
- package/dist/assets/manrope-greek-wght-normal-DL7QRZyv.woff2 +0 -0
- package/dist/assets/manrope-latin-ext-wght-normal-Ch3YOpNY.woff2 +0 -0
- package/dist/assets/manrope-latin-wght-normal-DHIcAJRg.woff2 +0 -0
- package/dist/assets/manrope-vietnamese-wght-normal-usUDDRr7.woff2 +0 -0
- package/dist/assets/{markdown-1TXf7spl.js → markdown-guT6oS8r.js} +1 -1
- package/dist/assets/space-grotesk-latin-ext-wght-normal-D9tNdqV9.woff2 +0 -0
- package/dist/assets/space-grotesk-latin-wght-normal-BhU9QXUp.woff2 +0 -0
- package/dist/assets/space-grotesk-vietnamese-wght-normal-D0rl6rjA.woff2 +0 -0
- package/dist/assets/trends-CQ2vYXnF.js +1 -0
- package/dist/assets/use-backfilled-events-DkIwsDSF.js +1 -0
- package/dist/assets/{vendor-B486on_u.js → vendor-C2H6D67p.js} +1 -1
- package/dist/assets/worktree-BnKsTLKp.js +1 -0
- package/dist/index.html +5 -5
- package/package.json +11 -6
- package/dist/assets/icons-DqY1dCmo.js +0 -1
- package/dist/assets/index-8UgsUYFY.js +0 -21
- package/dist/assets/index-Cw3VaZli.css +0 -1
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import{r as e,t}from"./rolldown-runtime-QTnfLwEv.js";import{$ as n,A as r,B as i,C as a,D as o,E as s,F as c,G as l,H as u,I as d,J as f,K as p,L as m,M as h,N as g,O as _,P as v,Q as y,R as b,S as x,T as S,U as C,V as w,W as T,X as E,Y as D,Z as O,_ as k,a as A,b as j,c as M,d as N,f as P,g as F,h as I,i as L,j as R,k as z,l as B,m as V,n as H,o as U,p as ee,q as te,r as W,s as ne,t as re,u as ie,v as ae,w as oe,x as se,y as ce,z as le}from"./icons-DqY1dCmo.js";import{n as ue,t as de}from"./vendor-B486on_u.js";import{i as fe,n as pe,r as me,t as he}from"./markdown-1TXf7spl.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var G=e(n(),1),ge=de(),_e=`wrongstack.hq.token.v1`;function ve(){if(typeof window>`u`)return null;try{let e=new URLSearchParams(window.location.search).get(`token`);return e!==null&&e.length>0?e:null}catch{return null}}function ye(){if(typeof window>`u`)return null;try{return window.sessionStorage??null}catch{return null}}function be(){try{let e=ye()?.getItem(_e)??null;return e!==null&&e.length>0?e:null}catch{return null}}function xe(e){try{ye()?.setItem(_e,e)}catch{}}function Se(){let e=ve();return e===null?be():(xe(e),e)}function Ce(){if(typeof window>`u`)return;let e=ve();if(e!==null&&(xe(e),be()===e))try{let e=new URL(window.location.href);e.searchParams.delete(`token`),window.history.replaceState(null,``,`${e.pathname}${e.search}${e.hash}`)}catch{}}function we(){let e=Se();return e===null?{}:{Authorization:`Bearer ${e}`}}function Te(e,t){let n={...t?.headers??{},...we()};return fetch(e,{...t,headers:n})}var Ee=25e3,De=1e4,Oe=3e4,ke=class{ws=null;handlers=new Set;stateHandlers=new Set;reconnectAttempt=0;reconnectTimer=null;heartbeatTimer=null;lastMessageAt=0;stopped=!1;_state=`disconnected`;url;maxRetries;heartbeatIntervalMs;heartbeatTimeoutMs;maxBackoffMs;constructor(e){if(this.maxRetries=e?.maxRetries??1/0,this.heartbeatIntervalMs=e?.heartbeatIntervalMs??Ee,this.heartbeatTimeoutMs=e?.heartbeatTimeoutMs??De,this.maxBackoffMs=e?.maxBackoffMs??Oe,e?.url)this.url=e.url;else{let e=typeof window<`u`?window.location:{host:`127.0.0.1:3499`,protocol:`http:`},t=e.protocol===`https:`?`wss:`:`ws:`,n=Se(),r=`${t}//${e.host}/ws/browser`;this.url=n===null?r:`${r}?token=${encodeURIComponent(n)}`}}get state(){return this._state}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}connect(){if(this.stopped||this.ws!==null)return;this.emitState(`connecting`);let e;try{e=new WebSocket(this.url)}catch{this.scheduleReconnect();return}this.ws=e,e.onopen=()=>{this.reconnectAttempt=0,this.lastMessageAt=Date.now(),this.emitState(`connected`),this.startHeartbeat()},e.onmessage=e=>{this.lastMessageAt=Date.now();try{let t=JSON.parse(typeof e.data==`string`?e.data:``);for(let e of this.handlers)try{e(t)}catch{}}catch{}},e.onclose=()=>this.handleClose(`close`),e.onerror=()=>this.handleClose(`error`)}close(){this.stopped=!0,this.stopHeartbeat(),this.reconnectTimer!==null&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.ws?.close(1e3,`client closed`),this.ws=null,this.emitState(`disconnected`)}on(e){return this.handlers.add(e),()=>this.handlers.delete(e)}onStateChange(e){return this.stateHandlers.add(e),e(this._state),()=>this.stateHandlers.delete(e)}handleClose(e){this.ws!==null&&(this.ws=null,this.stopHeartbeat(),this.scheduleReconnect())}scheduleReconnect(){if(this.stopped||this.reconnectTimer!==null)return;if(this.reconnectAttempt>=this.maxRetries){this.emitState(`disconnected`);return}let e=1e3*2**Math.min(this.reconnectAttempt,4)*(.5+Math.random()*.5),t=Math.min(e,this.maxBackoffMs);this.reconnectAttempt++,this.emitState(`reconnecting`),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},t)}get isHeartbeatTimedOut(){return this.ws===null?!0:Date.now()-this.lastMessageAt>this.heartbeatIntervalMs+this.heartbeatTimeoutMs}startHeartbeat(){this.stopHeartbeat(),this.lastMessageAt=Date.now(),this.heartbeatTimer=setInterval(()=>{this.isHeartbeatTimedOut&&this.ws!==null&&(this.ws.close(4e3,`heartbeat timeout`),this.ws=null,this.scheduleReconnect())},this.heartbeatIntervalMs)}stopHeartbeat(){this.heartbeatTimer!==null&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}emitState(e){this._state=e;for(let t of this.stateHandlers)try{t(e)}catch{}}},Ae=null;function je(){return Ae===null&&(Ae=new ke,Ae.connect()),Ae}var Me={snapshot:null,events:[],alerts:[],activeView:`cockpit`,selectedSessionId:null,selectedAgentId:null,selectedClientId:null,connected:!1,authRequired:!1},Ne=new Set,Pe=new Map;function Fe(e){for(let t of Ne){let n=Pe.get(t);(n==null||n.some(t=>e.includes(t)))&&t()}}function Ie(e,t){return Ne.add(e),Pe.set(e,t??null),()=>{Ne.delete(e),Pe.delete(e)}}function Le(){return Me}function Re(e){Me={...Me,...e},Fe(Object.keys(e))}var ze=!1;function Be(){if(ze)return;ze=!0;let e=je();e.onStateChange(e=>{Re({connected:e===`connected`})}),e.on(e=>{e.type===`hq.snapshot`?Re({snapshot:e.snapshot,connected:!0}):e.type===`hq.event`?Re({events:[...Me.events,e.event].slice(-500)}):e.type===`hq.alert`&&Re({alerts:[...Me.alerts,e].slice(-100)})})}function Ve(e){return(0,G.useEffect)(()=>{Be()},[]),(0,G.useSyncExternalStore)(t=>Ie(t,e),Le,Le)}function He(e){Re({activeView:e})}function Ue(e,t=null){Re({selectedSessionId:e,selectedAgentId:t})}function We(e,t){Re({selectedSessionId:e,selectedAgentId:t})}function Ge(e){Re({selectedClientId:e})}function Ke(){Me.authRequired||Re({authRequired:!0})}async function qe(e){let t;try{t=await Te(e)}catch{throw Error(`Network error fetching ${e}`)}if(t.status===401)throw Ke(),Error(`401 Unauthorized fetching ${e} — browser token required`);if(!t.ok)throw Error(`${t.status} ${t.statusText}`);try{return await t.json()}catch{throw Error(`Invalid JSON response from ${e}: ${t.status}`)}}async function Je(e){let t;try{t=await Te(`/api/mailbox-send`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})}catch{throw Error(`Network error sending mailbox message`)}if(t.status===401)throw Ke(),Error(`401 Unauthorized — browser token required`);if(!t.ok){let e=await t.json().catch(()=>null),n=typeof e?.error==`string`?e.error:t.statusText||`HTTP ${t.status}`;throw Error(n)}try{return await t.json()}catch{throw Error(`Invalid JSON response from mailbox-send API`)}}async function Ye(e,t,n){let r;try{r=await Te(`/api/command`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clientId:e,type:t,payload:n})})}catch{throw Error(`Network error sending command`)}if(r.status===401)throw Ke(),Error(`401 Unauthorized — browser token required`);if(!r.ok){let e=(await r.json().catch(()=>null))?.error??(r.statusText||`HTTP ${r.status}`);throw Error(e)}try{return await r.json()}catch{throw Error(`Invalid JSON response from command API`)}}var K=fe();function Xe(){let e=Ve([`alerts`,`snapshot`]),[t,n]=(0,G.useState)([]),[r,i]=(0,G.useState)([]);(0,G.useEffect)(()=>{let e=!1,t=()=>{qe(`/api/alerts`).then(t=>{e||(n(t.active),i(t.history))}).catch(()=>{})};t();let r=setInterval(t,15e3);return()=>{e=!0,clearInterval(r)}},[]);let a=e.alerts.slice(-50).reverse();return(0,K.jsxs)(`div`,{children:[t.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`hq-card-title`,children:[`Active Alerts (`,t.length,`)`]}),t.map(e=>(0,K.jsxs)(`div`,{className:`hq-card`,style:{borderColor:`var(--red)`},children:[(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,K.jsx)(`span`,{style:{fontWeight:700},children:e.ruleId}),(0,K.jsxs)(`span`,{className:`hq-mono`,style:{marginLeft:`auto`,color:`var(--dim)`},children:[`since `,new Date(e.firstFiredAt).toLocaleTimeString()]})]}),(0,K.jsx)(`div`,{style:{marginTop:4},children:e.message})]},e.id))]}),(0,K.jsxs)(`div`,{className:`hq-card-title`,children:[`Live Alert Feed (last `,a.length,`)`]}),a.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:`No live alerts. Alerts fire when fleet rules trigger (cost, stale, failures).`}):a.map((e,t)=>(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,K.jsx)(`span`,{className:`hq-mono`,style:{marginLeft:`auto`,color:`var(--dim)`},children:new Date(e.timestamp).toLocaleTimeString()})]}),(0,K.jsx)(`div`,{style:{marginTop:4},children:e.message})]},t)),(0,K.jsxs)(`div`,{className:`hq-card-title`,children:[`Alert History (`,r.length,`)`]}),(0,K.jsx)(`div`,{className:`hq-card`,children:r.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:`No historical alerts.`}):r.slice(-30).reverse().map((e,t)=>(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(`span`,{className:`hq-pill `+e.severity,children:e.severity}),(0,K.jsx)(`span`,{className:`hq-mono`,children:e.ruleId}),(0,K.jsx)(`span`,{style:{color:`var(--muted)`},children:e.message}),(0,K.jsx)(`span`,{className:`hq-mono`,style:{marginLeft:`auto`,color:`var(--dim)`},children:new Date(e.lastFiredAt).toLocaleTimeString()})]},t))})]})}function Ze(e,t=200){let n=Ve([`events`]),[r,i]=(0,G.useState)([]),[a,o]=(0,G.useState)(!0);return(0,G.useEffect)(()=>{let n=!1;return qe(`/api/events?type=${encodeURIComponent(e)}&limit=${t}`).then(e=>{n||(i([...e.events??[]].reverse()),o(!1))}).catch(()=>{n||o(!1)}),()=>{n=!0}},[e,t]),{events:(0,G.useMemo)(()=>{let t=new Set,i=[];for(let n of r)n.type!==e||t.has(n.id)||(t.add(n.id),i.push(n));for(let r of n.events)r.type!==e||t.has(r.id)||(t.add(r.id),i.push(r));return i},[r,n.events,e]),loading:a}}var Qe={decision_requested:{label:`Requested`,Icon:O,cls:`info`},decision_answered:{label:`Answered`,Icon:y,cls:`active`},decision_ask_human:{label:`Ask Human`,Icon:ce,cls:`warn`},decision_denied:{label:`Denied`,Icon:v,cls:`error`},human_answered:{label:`Human`,Icon:C,cls:`info`},intervention:{label:`Intervention`,Icon:re,cls:`warn`}};function $e(){let{events:e,loading:t}=Ze(`brain.event`,200),n=e.slice(-200).reverse();return n.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:t?`Loading brain history…`:`No brain decisions yet. Brain events appear when autonomous consumers (Director, AutoPhase, Eternal) route decisions through the Brain.`}):(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`hq-card-title`,children:[`Brain Decisions (last `,n.length,`)`]}),n.map(e=>{let t=e.payload,n=Qe[t.kind]??{label:t.kind,Icon:i,cls:`info`};return(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(n.Icon,{size:15,className:`hq-kind-icon ${n.cls}`}),(0,K.jsx)(`span`,{style:{fontWeight:700},children:n.label}),t.source!==void 0&&(0,K.jsx)(`span`,{className:`hq-pill info`,children:t.source}),t.risk!==void 0&&(0,K.jsxs)(`span`,{className:`hq-pill ${t.risk===`high`||t.risk===`critical`?`error`:`warn`}`,children:[t.risk,` risk`]}),(0,K.jsx)(`span`,{className:`hq-mono hq-row-time`,children:new Date(t.at).toLocaleTimeString()})]}),t.question!==void 0&&(0,K.jsx)(`div`,{className:`hq-mono hq-row-detail`,children:t.question}),t.decision!==void 0&&(0,K.jsx)(`div`,{className:`hq-row`,style:{marginTop:4},children:(0,K.jsxs)(`span`,{className:`hq-pill active`,children:[`→ `,t.decision]})}),t.detail!==void 0&&(0,K.jsx)(`div`,{className:`hq-mono hq-row-subtle`,children:t.detail}),t.kind===`intervention`&&(0,K.jsxs)(`div`,{className:`hq-row`,style:{marginTop:4},children:[(0,K.jsx)(`span`,{className:`hq-pill warn`,children:t.interventionKind}),(0,K.jsx)(`span`,{className:`hq-pill`,children:t.intervened?`steered`:`observed`})]})]},e.id)})]})}function et(){let e=Ve([`snapshot`,`alerts`]),t=e.snapshot,n=t?.totals,r=t?.machines??[],i=t?.projects??[],a=t?.clients??[],o=t?.liveSessions??[],s=a.filter(e=>e.capabilities.includes(`control.receive`)),c=e.selectedClientId??s[0]?.clientId??null,l=s.find(e=>e.clientId===c)??s[0]??null,[u,d]=(0,G.useState)([]),[f,p]=(0,G.useState)([]),[m,h]=(0,G.useState)(null),[g,_]=(0,G.useState)(null),[v,y]=(0,G.useState)(null),[b,x]=(0,G.useState)(null);(0,G.useEffect)(()=>{let e=!1,t=()=>{qe(`/api/alerts`).then(t=>{e||(d(t.active),p(t.history),h(null))}).catch(t=>{e||h(t instanceof Error?t.message:String(t))})};t();let n=setInterval(t,15e3);return()=>{e=!0,clearInterval(n)}},[]);let S=(0,G.useMemo)(()=>{let t=e.alerts.slice(-30).reverse().map(e=>({severity:typeof e.severity==`string`?e.severity:`info`,ruleId:`live`,message:`Live alert envelope received.`,timestamp:typeof e.timestamp==`string`?e.timestamp:new Date().toISOString()})),n=[...u,...f].slice(-30).reverse().map(e=>({severity:typeof e.severity==`string`?e.severity:`info`,ruleId:typeof e.ruleId==`string`?e.ruleId:`alert`,message:typeof e.message==`string`?e.message:``,timestamp:typeof e.lastFiredAt==`string`?e.lastFiredAt:typeof e.firstFiredAt==`string`?e.firstFiredAt:new Date().toISOString()})),r=[...t,...n],i=new Set,a=[];for(let e of r){let t=`${e.ruleId}|${e.message}|${e.timestamp}`;if(!i.has(t)&&(i.add(t),a.push(e),a.length>=12))break}return a},[e.alerts,u,f]),C=(0,G.useMemo)(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of o){a.status===`active`&&(i+=1);for(let i of a.agents??[])e+=1,i.status===`running`||i.status===`streaming`?t+=1:i.status===`waiting_user`?n+=1:i.status===`error`&&(r+=1)}return{total:e,busy:t,waiting:n,errored:r,activeSessions:i}},[o]),w=(0,G.useMemo)(()=>[...i].sort((e,t)=>t.totalCostUsd-e.totalCostUsd).slice(0,4),[i]);async function T(e){if(l!==null){_(e),y(null),x(null);try{let t=e===`pause-noisy`?{subject:`HQ quick action: pause noisy agents`,body:`HQ operator requests: pause non-critical/noisy agent work, reduce chatter, and keep only essential status updates until resumed.`,priority:`high`}:{subject:`HQ quick action: status request`,body:`HQ operator requests a concise status broadcast from active agents: current task, blocker if any, and next expected action.`,priority:`normal`};y(`queued ${(await Ye(l.clientId,`broadcast`,t)).commandId}`)}catch(e){x(e instanceof Error?e.message:String(e))}finally{_(null)}}}let E=[{title:`Fleet`,view:`fleet`,cta:`open fleet`,body:(0,K.jsxs)(`div`,{className:`hq-cockpit-grid`,children:[(0,K.jsx)(tt,{label:`machines`,value:r.length}),(0,K.jsx)(tt,{label:`clients`,value:a.length}),(0,K.jsx)(tt,{label:`sessions`,value:C.activeSessions,accent:C.activeSessions>0?`green`:void 0}),(0,K.jsx)(tt,{label:`agents`,value:C.total}),(0,K.jsx)(tt,{label:`busy`,value:C.busy,accent:C.busy>0?`green`:void 0}),(0,K.jsx)(tt,{label:`waiting`,value:C.waiting,accent:C.waiting>0?`warn`:void 0}),(0,K.jsx)(tt,{label:`errored`,value:C.errored,accent:C.errored>0?`error`:void 0}),(0,K.jsx)(tt,{label:`cost $`,value:(n?.totalCostUsd??0).toFixed(2),accent:`green`})]})}],D={title:`Alerts`,view:`alerts`,cta:`open alerts`,body:S.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,style:{padding:14,fontSize:12},children:`No alerts in the last few minutes.`}):(0,K.jsx)(`div`,{className:`hq-cockpit-alert-list`,children:S.map((e,t)=>(0,K.jsxs)(`div`,{className:`hq-cockpit-alert-row`,children:[(0,K.jsx)(`span`,{className:`hq-pill `+it(e.severity),children:e.severity}),(0,K.jsx)(`span`,{className:`hq-mono`,children:e.ruleId}),(0,K.jsx)(`span`,{className:`hq-cockpit-alert-msg`,children:e.message}),(0,K.jsx)(`span`,{className:`hq-mono`,style:{color:`var(--dim)`,marginLeft:`auto`},children:rt(e.timestamp)})]},`${e.ruleId}-${e.timestamp}-${t}`))})},O={title:`Cost`,view:`cost`,cta:`open cost`,body:w.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,style:{padding:14,fontSize:12},children:`No cost data yet — connect some clients.`}):(0,K.jsx)(`div`,{className:`hq-cockpit-cost-list`,children:w.map(e=>{let t=(n?.totalCostUsd??0)>0?e.totalCostUsd/n.totalCostUsd*100:0;return(0,K.jsxs)(`div`,{className:`hq-cockpit-cost-row`,children:[(0,K.jsxs)(`div`,{className:`hq-cockpit-cost-line`,children:[(0,K.jsx)(`span`,{className:`hq-cockpit-cost-name`,children:e.projectName}),(0,K.jsx)(`span`,{className:`hq-mono`,style:{color:`var(--dim)`},children:e.projectId}),(0,K.jsxs)(`span`,{className:`hq-mono`,style:{color:`var(--green)`,marginLeft:`auto`},children:[`$`,e.totalCostUsd.toFixed(4)]}),(0,K.jsxs)(`span`,{className:`hq-mono`,style:{color:`var(--dim)`},children:[t.toFixed(1),`%`]})]}),(0,K.jsx)(`div`,{className:`hq-cockpit-cost-bar`,"aria-label":`${t.toFixed(1)}% of fleet cost`,children:(0,K.jsx)(`span`,{style:{width:`${Math.max(2,t)}%`}})}),(0,K.jsxs)(`div`,{className:`hq-cockpit-cost-meta`,children:[(0,K.jsxs)(`span`,{children:[e.activeSessions,` sessions`]}),(0,K.jsxs)(`span`,{children:[e.activeSubagents,` subagents`]}),(0,K.jsxs)(`span`,{children:[e.activeClients,` clients`]})]})]},e.projectId)})})};return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`hq-card-title`,children:`Cockpit`}),(0,K.jsxs)(`div`,{className:`hq-card hq-cockpit-summary`,children:[(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(`span`,{className:`hq-pill info`,children:e.connected?`connected`:`reconnecting`}),(0,K.jsxs)(`span`,{className:`hq-pill`,children:[n?.activeMachines??0,` machines`]}),(0,K.jsxs)(`span`,{className:`hq-pill`,children:[n?.activeSessions??0,` sessions`]}),(0,K.jsxs)(`span`,{className:`hq-pill`,children:[n?.activeAgents??0,` agents`]}),(0,K.jsxs)(`span`,{className:`hq-pill green`,children:[`$`,(n?.totalCostUsd??0).toFixed(2)]}),u.length>0&&(0,K.jsxs)(`span`,{className:`hq-pill error`,children:[u.length,` active alerts`]}),m!==null&&(0,K.jsx)(`span`,{className:`hq-pill error`,children:m}),(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,style:{marginLeft:`auto`},onClick:()=>He(`fleet`),children:`Open Fleet`})]}),(0,K.jsxs)(`div`,{className:`hq-cockpit-actions`,"aria-label":`Cockpit quick actions`,children:[(0,K.jsxs)(`div`,{className:`hq-cockpit-actions-copy`,children:[(0,K.jsx)(`span`,{className:`hq-card-title`,style:{margin:0},children:`Quick Actions`}),(0,K.jsx)(`span`,{className:`hq-mono`,children:l===null?`no controllable client connected`:`target ${nt(l.clientId)}`})]}),(0,K.jsxs)(`div`,{className:`hq-cockpit-actions-buttons`,children:[(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:l===null||g!==null,onClick:()=>void T(`pause-noisy`),children:g===`pause-noisy`?`Queuing…`:`Pause noisy agents`}),(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:l===null||g!==null,onClick:()=>void T(`status-request`),children:g===`status-request`?`Queuing…`:`Broadcast status request`}),(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>He(`control`),children:`Open Control`})]}),v!==null&&(0,K.jsx)(`span`,{className:`hq-pill info`,children:v}),b!==null&&(0,K.jsx)(`span`,{className:`hq-pill error`,children:b})]})]}),[...E,D,O].map(e=>(0,K.jsxs)(`div`,{className:`hq-card hq-cockpit-section`,children:[(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(`span`,{className:`hq-card-title`,style:{margin:0},children:e.title}),(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,style:{marginLeft:`auto`},onClick:()=>He(e.view),children:e.cta})]}),e.body]},e.title))]})}function tt({label:e,value:t,accent:n}){return(0,K.jsxs)(`div`,{className:`hq-stat`+(n?` ${n}`:``),children:[(0,K.jsx)(`span`,{className:`hq-stat-num`,children:t}),(0,K.jsx)(`span`,{className:`hq-stat-label`,children:e})]})}function nt(e){return e.length<=18?e:`${e.slice(0,9)}…${e.slice(-6)}`}function rt(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString()}function it(e){return e===`critical`||e===`error`||e===`high`?`error`:e===`warn`||e===`warning`||e===`medium`?`warn`:e===`info`||e===`low`?`info`:`idle`}var at=`wrongstack.hq.local-prefs.v1`,q={control:{cmdType:`steer`,abortTarget:`leader`,spawnRole:`bug-hunter`,spawnTask:``,steerTo:`leader`,steerSubject:``,steerBody:``,broadcastSubject:``,broadcastBody:``},mailbox:{query:``,types:[],priorities:[],includeCompleted:!0}},ot=null,st=new Set;function ct(){for(let e of st)e()}function lt(e){return typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e))}function ut(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function dt(){if(typeof window>`u`||window.localStorage===void 0)return lt(q);try{let e=window.localStorage.getItem(at);return e===null?lt(q):ft(JSON.parse(e))}catch{return lt(q)}}function ft(e){if(!ut(e))return lt(q);let t=ut(e.control)?e.control:{},n=ut(e.mailbox)?e.mailbox:{};return{control:{cmdType:t.cmdType===`btw`||t.cmdType===`queue`||t.cmdType===`abort`||t.cmdType===`spawn`||t.cmdType===`broadcast`||t.cmdType===`run-command`?t.cmdType:q.control.cmdType,abortTarget:t.abortTarget===`fleet`?`fleet`:`leader`,spawnRole:typeof t.spawnRole==`string`&&t.spawnRole.length>0?t.spawnRole:q.control.spawnRole,spawnTask:typeof t.spawnTask==`string`?t.spawnTask:q.control.spawnTask,steerTo:typeof t.steerTo==`string`?t.steerTo:q.control.steerTo,steerSubject:typeof t.steerSubject==`string`?t.steerSubject:q.control.steerSubject,steerBody:typeof t.steerBody==`string`?t.steerBody:q.control.steerBody,broadcastSubject:typeof t.broadcastSubject==`string`?t.broadcastSubject:q.control.broadcastSubject,broadcastBody:typeof t.broadcastBody==`string`?t.broadcastBody:q.control.broadcastBody},mailbox:{query:typeof n.query==`string`?n.query:q.mailbox.query,types:Array.isArray(n.types)?n.types.filter(e=>typeof e==`string`):[],priorities:Array.isArray(n.priorities)?n.priorities.filter(e=>typeof e==`string`):[],includeCompleted:typeof n.includeCompleted==`boolean`?n.includeCompleted:!0}}}function pt(){return ot===null&&(ot=dt()),ot}function mt(e){if(!(typeof window>`u`||window.localStorage===void 0))try{window.localStorage.setItem(at,JSON.stringify(e))}catch{}}function ht(e){return st.add(e),()=>st.delete(e)}function gt(){return pt()}function _t(){return q}function vt(){return(0,G.useSyncExternalStore)(ht,gt,_t)}function yt(e){let t=pt();ot={...t,control:{...t.control,...e}},mt(ot),ct()}function bt(e){let t=pt();ot={...t,mailbox:{...t.mailbox,...e}},mt(ot),ct()}var xt={steer:{label:`steer`,icon:(0,K.jsx)(re,{size:13}),desc:`High-priority course correction — interrupts the agent at the next turn.`},btw:{label:`btw`,icon:(0,K.jsx)(N,{size:13}),desc:`Non-urgent FYI — rides alongside the run without interrupting it.`},queue:{label:`queue`,icon:(0,K.jsx)(V,{size:13}),desc:`Queue a prompt — picked up after the current run finishes.`},abort:{label:`abort`,icon:(0,K.jsx)(p,{size:13}),desc:`Stop the leader run or every subagent on the client. Destructive.`,danger:!0},spawn:{label:`spawn`,icon:(0,K.jsx)(w,{size:13}),desc:`Launch a role subagent (bug-hunter, critic, …) with an optional task.`},broadcast:{label:`broadcast`,icon:(0,K.jsx)(P,{size:13}),desc:`Mailbox message to every agent in the client’s project.`},"run-command":{label:`run-command`,icon:(0,K.jsx)(l,{size:13}),desc:`Route a shell command to the client. RCE-gated (--hq-allow-exec + control.execute).`,danger:!0}};function St(){let e=Ve([`snapshot`,`selectedClientId`]),t=(e.snapshot?.clients??[]).filter(e=>e.capabilities.includes(`control.receive`)),n=e.selectedClientId??t[0]?.clientId??null,r=t.find(e=>e.clientId===n)??t[0]??null,i=vt().control,[a,o]=(0,G.useState)(i.cmdType),[s,c]=(0,G.useState)(`compose`),[l,u]=(0,G.useState)(i.steerTo),[d,f]=(0,G.useState)(i.steerSubject),[p,m]=(0,G.useState)(i.steerBody),[h,g]=(0,G.useState)(i.spawnRole),[_,v]=(0,G.useState)(i.spawnTask),[y,b]=(0,G.useState)(i.abortTarget),[x,S]=(0,G.useState)(i.broadcastSubject),[C,w]=(0,G.useState)(i.broadcastBody),[E,D]=(0,G.useState)(``),[O,k]=(0,G.useState)(``),[A,j]=(0,G.useState)(``),[M,N]=(0,G.useState)(null),[P,F]=(0,G.useState)(null),[I,L]=(0,G.useState)(!1),[R,z]=(0,G.useState)([]),[B,V]=(0,G.useState)(!1),[H,U]=(0,G.useState)(null),[ee,te]=(0,G.useState)(null),W=(0,G.useMemo)(()=>ue(),[a,l,d,p,h,_,y,x,C,E,O]),ne=W.risk===`danger`,re=a===`run-command`?`RUN`:`ABORT`,ie=n!==null&&W.disabledReason===null&&(!ne||A===re),ae=W.disabledReason===null&&n!==null;function oe(){c(`compose`),j(``),F(null),N(null)}function se(e){o(e),yt({cmdType:e}),oe()}async function ce(){V(!0),U(null);try{z((await qe(`/api/commands?limit=25`)).commands.slice().reverse())}catch(e){U(e instanceof Error?e.message:String(e))}finally{V(!1)}}(0,G.useEffect)(()=>{ce();let e=setInterval(()=>{document.hidden||ce()},5e3);return()=>clearInterval(e)},[]);async function le(){if(!(n===null||!ie)){L(!0),F(null),N(null);try{let e=await Ye(n,W.type,W.payload);N(`queued ${W.type} command ${e.commandId}`),te(e.commandId),c(`compose`),j(``),ce()}catch(e){F(e instanceof Error?e.message:String(e))}finally{L(!1)}}}(0,G.useEffect)(()=>{let e=e=>{e.key!==`Enter`||!(e.ctrlKey||e.metaKey)||(e.preventDefault(),s===`compose`&&ae?(c(`preview`),N(null),F(null)):s===`preview`&&ie&&!I&&le())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)});function ue(){if(a===`steer`||a===`btw`||a===`queue`){let e=p.trim(),t=a===`steer`?`Send high-priority steer to`:a===`btw`?`Post a non-urgent FYI (btw) to`:`Queue a prompt for`;return{type:a,payload:{to:l||`leader`,subject:d||`HQ ${a}`,body:p,priority:a===`steer`?`high`:`normal`},disabledReason:e.length===0?`Message body is required.`:null,risk:`normal`,summary:`${t} ${l||`leader`}.`}}if(a===`run-command`){let e=E.trim();return{type:`run-command`,payload:{command:E,...O.trim()?{cwd:O.trim()}:{}},disabledReason:e.length===0?`Command is required.`:null,risk:`danger`,summary:`Route a shell command to the client (requires --hq-allow-exec + control.execute; delivered as a steer, the agent’s permission policy still applies).`}}if(a===`abort`)return{type:`abort`,payload:{target:y},disabledReason:null,risk:`danger`,summary:y===`fleet`?`Abort all subagents on the selected client.`:`Abort the selected target on the selected client.`};if(a===`spawn`){let e=_.trim();return{type:`spawn`,payload:{role:h,...e?{task:e}:{}},disabledReason:h.trim().length===0?`Role is required.`:null,risk:`normal`,summary:`Spawn a ${h} subagent${e?` with an initial task`:``}.`}}let e=C.trim();return{type:`broadcast`,payload:{subject:x||`HQ broadcast`,body:C,priority:`normal`},disabledReason:e.length===0?`Broadcast body is required.`:null,risk:`normal`,summary:`Broadcast a normal-priority mailbox message to the selected client project.`}}return t.length===0?(0,K.jsxs)(`div`,{className:`hq-empty`,children:[`No controllable clients connected. Clients must advertise the `,(0,K.jsx)(`code`,{children:`control.receive`}),` `,`capability (CLI/TUI/WebUI surfaces do this automatically when connected to HQ).`]}):(0,K.jsxs)(`div`,{className:`hq-control-grid`,children:[(0,K.jsxs)(`div`,{className:`hq-control-composer`,children:[(0,K.jsx)(`div`,{className:`hq-card-title`,children:`Command Target`}),(0,K.jsxs)(`div`,{className:`hq-card hq-control-target`,children:[(0,K.jsx)(`label`,{className:`hq-label`,children:`Client`}),(0,K.jsx)(`select`,{className:`hq-select`,value:n??``,onChange:e=>{Ge(e.target.value),oe()},children:t.map(e=>(0,K.jsxs)(`option`,{value:e.clientId,children:[e.kind,` — `,e.hostname??e.clientId,` (`,e.projectId,`)`]},e.clientId))}),r!==null&&(0,K.jsxs)(`div`,{className:`hq-control-meta`,children:[(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`kind`}),` `,r.kind]}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`host`}),` `,r.hostname??`unknown`]}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`project`}),` `,r.projectId]}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`client`}),` `,Ct(r.clientId)]})]})]}),(0,K.jsx)(`div`,{className:`hq-card-title`,children:`Command Type`}),(0,K.jsxs)(`div`,{className:`hq-control-steps`,"aria-label":`Control command stages`,children:[(0,K.jsx)(`span`,{className:`hq-step active`,children:`1 compose`}),(0,K.jsx)(`span`,{className:`hq-step`+(s===`preview`?` active`:``),children:`2 preview`}),(0,K.jsx)(`span`,{className:`hq-step`+(M===null?``:` active`),children:`3 queued`})]}),(0,K.jsx)(`div`,{className:`hq-control-types`,children:Object.keys(xt).map(e=>{let t=xt[e];return(0,K.jsxs)(`button`,{type:`button`,title:t.desc,className:`hq-control-type`+(a===e?` selected`:``)+(t.danger===!0?` danger`:``),onClick:()=>se(e),children:[t.icon,t.label]},e)})}),(0,K.jsxs)(`div`,{className:`hq-control-typedesc`,children:[xt[a].danger===!0&&(0,K.jsx)(T,{size:12}),xt[a].desc]}),(0,K.jsxs)(`div`,{style:{marginTop:12},children:[(a===`steer`||a===`btw`||a===`queue`)&&(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsxs)(`label`,{className:`hq-label`,children:[`To (agent address — e.g. `,(0,K.jsx)(`code`,{children:`leader`}),`, `,(0,K.jsx)(`code`,{children:`leader@sessionTag`}),`, or a subagent id)`]}),(0,K.jsx)(`input`,{className:`hq-input`,value:l,onChange:e=>{u(e.target.value),yt({steerTo:e.target.value})},placeholder:`leader`}),(0,K.jsx)(`label`,{className:`hq-label`,style:{marginTop:8},children:`Subject`}),(0,K.jsx)(`input`,{className:`hq-input`,value:d,onChange:e=>{f(e.target.value),yt({steerSubject:e.target.value})}}),(0,K.jsx)(`label`,{className:`hq-label`,style:{marginTop:8},children:`Body`}),(0,K.jsx)(`textarea`,{className:`hq-textarea`,value:p,onChange:e=>{m(e.target.value),yt({steerBody:e.target.value})}})]}),a===`abort`&&(0,K.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,K.jsx)(`label`,{className:`hq-label`,children:`Target`}),(0,K.jsxs)(`select`,{className:`hq-select`,value:y,onChange:e=>{b(e.target.value),yt({abortTarget:e.target.value})},children:[(0,K.jsx)(`option`,{value:`leader`,children:`leader (session leader)`}),(0,K.jsx)(`option`,{value:`fleet`,children:`fleet (all subagents)`})]}),(0,K.jsxs)(`div`,{className:`hq-control-warning`,children:[`Abort is destructive. Preview requires typing `,(0,K.jsx)(`strong`,{children:`ABORT`}),` before dispatch.`]})]}),a===`spawn`&&(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsx)(`label`,{className:`hq-label`,children:`Role`}),(0,K.jsxs)(`select`,{className:`hq-select`,value:h,onChange:e=>{g(e.target.value),yt({spawnRole:e.target.value})},children:[(0,K.jsx)(`option`,{value:`bug-hunter`,children:`bug-hunter`}),(0,K.jsx)(`option`,{value:`refactor-planner`,children:`refactor-planner`}),(0,K.jsx)(`option`,{value:`critic`,children:`critic`}),(0,K.jsx)(`option`,{value:`security-scanner`,children:`security-scanner`}),(0,K.jsx)(`option`,{value:`code-reviewer`,children:`code-reviewer`})]}),(0,K.jsx)(`label`,{className:`hq-label`,style:{marginTop:8},children:`Task (optional)`}),(0,K.jsx)(`textarea`,{className:`hq-textarea`,value:_,onChange:e=>{v(e.target.value),yt({spawnTask:e.target.value})},placeholder:`Describe the task…`})]}),a===`run-command`&&(0,K.jsxs)(`div`,{className:`hq-card hq-card-danger`,children:[(0,K.jsx)(`label`,{className:`hq-label`,children:`Shell command`}),(0,K.jsx)(`textarea`,{className:`hq-textarea`,value:E,onChange:e=>D(e.target.value),placeholder:`pnpm test`}),(0,K.jsx)(`label`,{className:`hq-label`,style:{marginTop:8},children:`Working directory (optional — defaults to the agent's project root)`}),(0,K.jsx)(`input`,{className:`hq-input`,value:O,onChange:e=>k(e.target.value),placeholder:``}),(0,K.jsxs)(`div`,{className:`hq-control-warning`,children:[`RCE-gated: the client must run with `,(0,K.jsx)(`code`,{children:`--hq-allow-exec`}),` and your token needs the `,(0,K.jsx)(`code`,{children:`control.execute`}),` capability — otherwise the server rejects this. Preview requires typing `,(0,K.jsx)(`strong`,{children:`RUN`}),` before dispatch.`]})]}),a===`broadcast`&&(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsx)(`label`,{className:`hq-label`,children:`Subject`}),(0,K.jsx)(`input`,{className:`hq-input`,value:x,onChange:e=>{S(e.target.value),yt({broadcastSubject:e.target.value})}}),(0,K.jsx)(`label`,{className:`hq-label`,style:{marginTop:8},children:`Body`}),(0,K.jsx)(`textarea`,{className:`hq-textarea`,value:C,onChange:e=>{w(e.target.value),yt({broadcastBody:e.target.value})}})]})]}),(0,K.jsx)(`div`,{className:`hq-card-title`,children:`Dispatch Gate`}),(0,K.jsxs)(`div`,{className:`hq-card hq-command-preview`+(W.risk===`danger`?` hq-card-danger`:``),children:[(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(`span`,{className:`hq-pill `+(W.risk===`danger`?`error`:`info`),children:W.risk}),(0,K.jsx)(`span`,{children:W.summary}),W.disabledReason!==null&&(0,K.jsx)(`span`,{className:`hq-pill warn`,children:W.disabledReason})]}),s===`preview`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`hq-msg-sublabel`,children:`payload preview`}),(0,K.jsx)(`pre`,{className:`hq-msg-pre`,children:JSON.stringify({clientId:n,type:W.type,payload:W.payload},null,2)}),ne&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`label`,{className:`hq-label`,style:{marginTop:12},children:`Confirm destructive dispatch`}),(0,K.jsx)(`input`,{className:`hq-input`,value:A,onChange:e=>j(e.target.value),placeholder:`Type ${re}`})]}),(0,K.jsxs)(`div`,{className:`hq-row`,style:{marginTop:12},children:[(0,K.jsx)(`button`,{className:`hq-btn`,disabled:I||!ie,onClick:()=>void le(),title:`Ctrl+Enter`,children:I?`Dispatching…`:`Dispatch Command`}),(0,K.jsx)(`button`,{className:`hq-btn secondary`,disabled:I,onClick:oe,children:`Back to Compose`})]})]}):(0,K.jsx)(`button`,{className:`hq-btn`,disabled:!ae,onClick:()=>{c(`preview`),N(null),F(null)},title:`Ctrl+Enter`,children:`Preview Command`})]}),M&&(0,K.jsx)(`div`,{className:`hq-pill active`,style:{marginTop:12},children:M}),P&&(0,K.jsx)(`div`,{className:`hq-pill error`,style:{marginTop:12},children:P})]}),(0,K.jsxs)(`div`,{className:`hq-control-audit`,children:[(0,K.jsx)(`div`,{className:`hq-card-title`,children:`Command Audit`}),(0,K.jsxs)(`div`,{className:`hq-card hq-command-audit`,children:[(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsxs)(`span`,{className:`hq-pill info`,children:[`recent `,R.length]}),B&&(0,K.jsx)(`span`,{className:`hq-pill idle`,children:`refreshing`}),H!==null&&(0,K.jsx)(`span`,{className:`hq-pill error`,children:H}),(0,K.jsx)(`button`,{className:`hq-btn secondary`,style:{marginLeft:`auto`},onClick:()=>void ce(),children:`Refresh`})]}),R.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,style:{padding:16,fontSize:12},children:`No command audit entries yet.`}):(0,K.jsx)(`div`,{className:`hq-audit-list`,children:R.map(e=>(0,K.jsxs)(`div`,{className:`hq-audit-row`+(e.commandId===ee?` just-dispatched`:``)+(n!==null&&e.clientId===n?``:` other-client`),children:[(0,K.jsxs)(`div`,{className:`hq-audit-main`,children:[(0,K.jsx)(`span`,{className:`hq-pill `+Tt(e),children:e.status}),(0,K.jsx)(`span`,{className:`hq-pill info`,children:e.type}),(0,K.jsx)(`span`,{className:`hq-mono`,children:Ct(e.commandId)}),e.ackStatus!==void 0&&(0,K.jsxs)(`span`,{className:`hq-pill `+Et(e.ackStatus),children:[`ack `,e.ackStatus]})]}),(0,K.jsxs)(`div`,{className:`hq-audit-meta`,children:[(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`client`}),` `,Ct(e.clientId)]}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`by`}),` `,e.enqueuedBy]}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`queued`}),` `,wt(e.enqueuedAt)]}),e.ackedAt!==void 0&&(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`acked`}),` `,wt(e.ackedAt)]})]}),e.ackMessage!==void 0&&e.ackMessage.length>0&&(0,K.jsx)(`div`,{className:`hq-audit-message`,children:e.ackMessage})]},e.commandId))})]})]})]})}function Ct(e){return e.length>18?`${e.slice(0,10)}…${e.slice(-6)}`:e}function wt(e,t=Date.now()){let n=new Date(e);if(Number.isNaN(n.getTime()))return e;let r=Math.max(0,t-n.getTime());return r<6e4?`${Math.floor(r/1e3)}s ago`:r<36e5?`${Math.floor(r/6e4)}m ago`:n.toLocaleTimeString()}function Tt(e){return e.ackStatus===`failed`||e.ackStatus===`rejected`?`error`:e.status===`acked`?`active`:e.status===`delivered`?`info`:e.status===`queued`?`warn`:`idle`}function Et(e){return e===`failed`||e===`rejected`?`error`:e===`completed`?`active`:`info`}function Dt(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Ot(){let e=Ve([`snapshot`]),t=e.snapshot?.projects??[],n=e.snapshot?.liveSessions??[],r=e.snapshot?.totals.totalCostUsd??0,i=(0,G.useMemo)(()=>n.map(e=>{let t=0,n=0,r=new Set;for(let i of e.agents)t+=i.costUsd??0,n+=(i.tokensIn??0)+(i.tokensOut??0),i.model!==void 0&&r.add(i.model);return{s:e,cost:t,tokens:n,models:[...r]}}).filter(e=>e.cost>0||e.tokens>0).sort((e,t)=>t.cost-e.cost),[n]);if(t.length===0)return(0,K.jsx)(`div`,{className:`hq-empty`,children:`No cost data yet — connect some clients.`});let a=[...t].sort((e,t)=>t.totalCostUsd-e.totalCostUsd);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`hq-kpi-row`,children:[(0,K.jsxs)(`div`,{className:`hq-kpi hero`,children:[(0,K.jsxs)(`span`,{className:`hq-kpi-value accent-cost`,children:[`$`,r.toFixed(4)]}),(0,K.jsx)(`span`,{className:`hq-kpi-label`,children:`total fleet cost`})]}),(0,K.jsxs)(`div`,{className:`hq-kpi`,children:[(0,K.jsx)(`span`,{className:`hq-kpi-value`,children:t.length}),(0,K.jsx)(`span`,{className:`hq-kpi-label`,children:`projects`})]}),(0,K.jsxs)(`div`,{className:`hq-kpi`,children:[(0,K.jsx)(`span`,{className:`hq-kpi-value`,children:i.length}),(0,K.jsx)(`span`,{className:`hq-kpi-label`,children:`costed sessions`})]})]}),(0,K.jsx)(`div`,{className:`hq-card-title`,children:`By Project`}),a.map(e=>{let t=r>0?e.totalCostUsd/r*100:0;return(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(`span`,{style:{fontWeight:700},children:e.projectName}),(0,K.jsx)(`span`,{className:`hq-mono hq-row-subtle`,children:e.projectId}),(0,K.jsxs)(`span`,{className:`hq-cost-amount`,children:[`$`,e.totalCostUsd.toFixed(4)]}),(0,K.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[t.toFixed(1),`%`]})]}),(0,K.jsx)(`div`,{className:`hq-share-track`,children:(0,K.jsx)(`div`,{className:`hq-share-fill`,style:{width:`${t}%`}})}),(0,K.jsxs)(`div`,{className:`hq-row`,style:{marginTop:4},children:[(0,K.jsxs)(`span`,{className:`hq-pill info`,children:[e.activeSessions,` sessions`]}),(0,K.jsxs)(`span`,{className:`hq-pill active`,children:[e.activeSubagents,` subagents`]}),(0,K.jsxs)(`span`,{className:`hq-pill idle`,children:[e.activeClients,` clients`]})]})]},e.projectId)}),i.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`hq-card-title`,children:`By Session`}),(0,K.jsx)(`div`,{className:`hq-card`,children:i.map(({s:e,cost:t,tokens:n,models:r})=>(0,K.jsxs)(`div`,{className:`hq-row hq-row-click`,onClick:()=>{Ue(e.sessionId),He(`console`)},title:`Open in Console`,children:[(0,K.jsx)(`span`,{style:{fontWeight:600},children:e.projectName}),(0,K.jsx)(`span`,{className:`hq-pill idle`,children:e.clientKind}),r.map(e=>(0,K.jsx)(`span`,{className:`hq-pill info`,children:e},e)),(0,K.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,children:[Dt(n),` tok`]}),(0,K.jsxs)(`span`,{className:`hq-cost-amount`,children:[`$`,t.toFixed(4)]})]},e.sessionId))})]})]})}function J(e){if(typeof e==`string`||typeof e==`number`)return``+e;let t=``;if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=J(e[n]))!==``&&(t+=(t&&` `)+r);else for(let n in e)e[n]&&(t+=(t&&` `)+n);return t}var kt={value:()=>{}};function At(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new jt(n)}function jt(e){this._=e}function Mt(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}jt.prototype=At.prototype={constructor:jt,on:function(e,t){var n=this._,r=Mt(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=Nt(n[i],e.name)))return i;return}if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=Pt(n[i],e.name,t);else if(t==null)for(i in n)n[i]=Pt(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new jt(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function Nt(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function Pt(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=kt,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}function Ft(e){return function(){return this.matches(e)}}function It(e){return function(t){return t.matches(e)}}var Lt={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function Rt(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),Lt.hasOwnProperty(t)?{space:Lt[t],local:e}:e}function zt(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Bt(e,t){if(e=zt(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}function Vt(){}function Ht(e){return e==null?Vt:function(){return this.querySelector(e)}}function Ut(e){typeof e!=`function`&&(e=Ht(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new Nr(r,this._parents)}function Wt(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Gt(){return[]}function Kt(e){return e==null?Gt:function(){return this.querySelectorAll(e)}}function qt(e){return function(){return Wt(e.apply(this,arguments))}}function Jt(e){e=typeof e==`function`?qt(e):Kt(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new Nr(r,i)}var Yt=Array.prototype.find;function Xt(e){return function(){return Yt.call(this.children,e)}}function Zt(){return this.firstElementChild}function Qt(e){return this.select(e==null?Zt:Xt(typeof e==`function`?e:It(e)))}var $t=Array.prototype.filter;function en(){return Array.from(this.children)}function tn(e){return function(){return $t.call(this.children,e)}}function nn(e){return this.selectAll(e==null?en:tn(typeof e==`function`?e:It(e)))}function rn(e){typeof e!=`function`&&(e=Ft(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new Nr(r,this._parents)}function an(e){return Array(e.length)}function on(){return new Nr(this._enter||this._groups.map(an),this._parents)}function sn(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}sn.prototype={constructor:sn,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function cn(e){return function(){return e}}function ln(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new sn(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function un(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new sn(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function dn(e){return e.__data__}function fn(e,t){if(!arguments.length)return Array.from(this,dn);var n=t?un:ln,r=this._parents,i=this._groups;typeof e!=`function`&&(e=cn(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=pn(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,y,b;_<m;++_)if(y=h[_]){for(_>=v&&(v=_+1);!(b=g[v])&&++v<m;);y._next=b||null}}return o=new Nr(o,r),o._enter=s,o._exit=c,o}function pn(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function mn(){return new Nr(this._exit||this._groups.map(an),this._parents)}function hn(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function gn(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new Nr(s,this._parents)}function _n(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function vn(e){e||=yn;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new Nr(i,this._parents).order()}function yn(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function bn(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function xn(){return Array.from(this)}function Sn(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function Cn(){let e=0;for(let t of this)++e;return e}function wn(){return!this.node()}function Tn(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function En(e){return function(){this.removeAttribute(e)}}function Dn(e){return function(){this.removeAttributeNS(e.space,e.local)}}function On(e,t){return function(){this.setAttribute(e,t)}}function kn(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function An(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function jn(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Mn(e,t){var n=Rt(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?Dn:En:typeof t==`function`?n.local?jn:An:n.local?kn:On)(n,t))}function Nn(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Pn(e){return function(){this.style.removeProperty(e)}}function Fn(e,t,n){return function(){this.style.setProperty(e,t,n)}}function In(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function Ln(e,t,n){return arguments.length>1?this.each((t==null?Pn:typeof t==`function`?In:Fn)(e,t,n??``)):Rn(this.node(),e)}function Rn(e,t){return e.style.getPropertyValue(t)||Nn(e).getComputedStyle(e,null).getPropertyValue(t)}function zn(e){return function(){delete this[e]}}function Bn(e,t){return function(){this[e]=t}}function Vn(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Hn(e,t){return arguments.length>1?this.each((t==null?zn:typeof t==`function`?Vn:Bn)(e,t)):this.node()[e]}function Un(e){return e.trim().split(/^|\s+/)}function Wn(e){return e.classList||new Gn(e)}function Gn(e){this._node=e,this._names=Un(e.getAttribute(`class`)||``)}Gn.prototype={add:function(e){this._names.indexOf(e)<0&&(this._names.push(e),this._node.setAttribute(`class`,this._names.join(` `)))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute(`class`,this._names.join(` `)))},contains:function(e){return this._names.indexOf(e)>=0}};function Kn(e,t){for(var n=Wn(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function qn(e,t){for(var n=Wn(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function Jn(e){return function(){Kn(this,e)}}function Yn(e){return function(){qn(this,e)}}function Xn(e,t){return function(){(t.apply(this,arguments)?Kn:qn)(this,e)}}function Zn(e,t){var n=Un(e+``);if(arguments.length<2){for(var r=Wn(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?Xn:t?Jn:Yn)(n,t))}function Qn(){this.textContent=``}function $n(e){return function(){this.textContent=e}}function er(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function tr(e){return arguments.length?this.each(e==null?Qn:(typeof e==`function`?er:$n)(e)):this.node().textContent}function nr(){this.innerHTML=``}function rr(e){return function(){this.innerHTML=e}}function ir(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function ar(e){return arguments.length?this.each(e==null?nr:(typeof e==`function`?ir:rr)(e)):this.node().innerHTML}function or(){this.nextSibling&&this.parentNode.appendChild(this)}function sr(){return this.each(or)}function cr(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function lr(){return this.each(cr)}function ur(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function dr(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function fr(e){var t=Rt(e);return(t.local?dr:ur)(t)}function pr(e){var t=typeof e==`function`?e:fr(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function mr(){return null}function hr(e,t){var n=typeof e==`function`?e:fr(e),r=t==null?mr:typeof t==`function`?t:Ht(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function gr(){var e=this.parentNode;e&&e.removeChild(this)}function _r(){return this.each(gr)}function vr(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function yr(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function br(e){return this.select(e?yr:vr)}function xr(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function Sr(e){return function(t){e.call(this,t,this.__data__)}}function Cr(e){return e.trim().split(/^|\s+/).map(function(e){var t=``,n=e.indexOf(`.`);return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function wr(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function Tr(e,t,n){return function(){var r=this.__on,i,a=Sr(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function Er(e,t,n){var r=Cr(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}return}for(s=t?Tr:wr,i=0;i<a;++i)this.each(s(r[i],t,n));return this}function Dr(e,t,n){var r=Nn(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function Or(e,t){return function(){return Dr(this,e,t)}}function kr(e,t){return function(){return Dr(this,e,t.apply(this,arguments))}}function Ar(e,t){return this.each((typeof t==`function`?kr:Or)(e,t))}function*jr(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var Mr=[null];function Nr(e,t){this._groups=e,this._parents=t}function Pr(){return new Nr([[document.documentElement]],Mr)}function Fr(){return this}Nr.prototype=Pr.prototype={constructor:Nr,select:Ut,selectAll:Jt,selectChild:Qt,selectChildren:nn,filter:rn,data:fn,enter:on,exit:mn,join:hn,merge:gn,selection:Fr,order:_n,sort:vn,call:bn,nodes:xn,node:Sn,size:Cn,empty:wn,each:Tn,attr:Mn,style:Ln,property:Hn,classed:Zn,text:tr,html:ar,raise:sr,lower:lr,append:pr,insert:hr,remove:_r,clone:br,datum:xr,on:Er,dispatch:Ar,[Symbol.iterator]:jr};function Ir(e){return typeof e==`string`?new Nr([[document.querySelector(e)]],[document.documentElement]):new Nr([[e]],Mr)}var Lr={passive:!1},Rr={capture:!0,passive:!1};function zr(e){e.stopImmediatePropagation()}function Br(e){e.preventDefault(),e.stopImmediatePropagation()}function Vr(e){var t=e.document.documentElement,n=Ir(e).on(`dragstart.drag`,Br,Rr);`onselectstart`in t?n.on(`selectstart.drag`,Br,Rr):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect=`none`)}function Hr(e,t){var n=e.document.documentElement,r=Ir(e).on(`dragstart.drag`,null);t&&(r.on(`click.drag`,Br,Rr),setTimeout(function(){r.on(`click.drag`,null)},0)),`onselectstart`in n?r.on(`selectstart.drag`,null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}var Ur=e=>()=>e;function Wr(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:a,x:o,y:s,dx:c,dy:l,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:s,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:u}})}Wr.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Gr(e){return!e.ctrlKey&&!e.button}function Kr(){return this.parentNode}function qr(e,t){return t??{x:e.x,y:e.y}}function Jr(){return navigator.maxTouchPoints||`ontouchstart`in this}function Yr(){var e=Gr,t=Kr,n=qr,r=Jr,i={},a=At(`start`,`drag`,`end`),o=0,s,c,l,u,d=0;function f(e){e.on(`mousedown.drag`,p).filter(r).on(`touchstart.drag`,g).on(`touchmove.drag`,_,Lr).on(`touchend.drag touchcancel.drag`,v).style(`touch-action`,`none`).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}function p(n,r){if(!(u||!e.call(this,n,r))){var i=y(this,t.call(this,n,r),n,r,`mouse`);i&&(Ir(n.view).on(`mousemove.drag`,m,Rr).on(`mouseup.drag`,h,Rr),Vr(n.view),zr(n),l=!1,s=n.clientX,c=n.clientY,i(`start`,n))}}function m(e){if(Br(e),!l){var t=e.clientX-s,n=e.clientY-c;l=t*t+n*n>d}i.mouse(`drag`,e)}function h(e){Ir(e.view).on(`mousemove.drag mouseup.drag`,null),Hr(e.view,l),Br(e),i.mouse(`end`,e)}function g(n,r){if(e.call(this,n,r)){var i=n.changedTouches,a=t.call(this,n,r),o=i.length,s,c;for(s=0;s<o;++s)(c=y(this,a,n,r,i[s].identifier,i[s]))&&(zr(n),c(`start`,n,i[s]))}}function _(e){var t=e.changedTouches,n=t.length,r,a;for(r=0;r<n;++r)(a=i[t[r].identifier])&&(Br(e),a(`drag`,e,t[r]))}function v(e){var t=e.changedTouches,n=t.length,r,a;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),r=0;r<n;++r)(a=i[t[r].identifier])&&(zr(e),a(`end`,e,t[r]))}function y(e,t,r,s,c,l){var u=a.copy(),d=Bt(l||r,t),p,m,h;if((h=n.call(e,new Wr(`beforestart`,{sourceEvent:r,target:f,identifier:c,active:o,x:d[0],y:d[1],dx:0,dy:0,dispatch:u}),s))!=null)return p=h.x-d[0]||0,m=h.y-d[1]||0,function n(r,a,l){var g=d,_;switch(r){case`start`:i[c]=n,_=o++;break;case`end`:delete i[c],--o;case`drag`:d=Bt(l||a,t),_=o;break}u.call(r,e,new Wr(r,{sourceEvent:a,subject:h,target:f,identifier:c,active:_,x:d[0]+p,y:d[1]+m,dx:d[0]-g[0],dy:d[1]-g[1],dispatch:u}),s)}}return f.filter=function(t){return arguments.length?(e=typeof t==`function`?t:Ur(!!t),f):e},f.container=function(e){return arguments.length?(t=typeof e==`function`?e:Ur(e),f):t},f.subject=function(e){return arguments.length?(n=typeof e==`function`?e:Ur(e),f):n},f.touchable=function(e){return arguments.length?(r=typeof e==`function`?e:Ur(!!e),f):r},f.on=function(){var e=a.on.apply(a,arguments);return e===a?f:e},f.clickDistance=function(e){return arguments.length?(d=(e=+e)*e,f):Math.sqrt(d)},f}function Xr(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Zr(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function Qr(){}var $r=.7,ei=1/$r,ti=`\\s*([+-]?\\d+)\\s*`,ni=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,ri=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,ii=/^#([0-9a-f]{3,8})$/,ai=RegExp(`^rgb\\(${ti},${ti},${ti}\\)$`),oi=RegExp(`^rgb\\(${ri},${ri},${ri}\\)$`),si=RegExp(`^rgba\\(${ti},${ti},${ti},${ni}\\)$`),ci=RegExp(`^rgba\\(${ri},${ri},${ri},${ni}\\)$`),li=RegExp(`^hsl\\(${ni},${ri},${ri}\\)$`),ui=RegExp(`^hsla\\(${ni},${ri},${ri},${ni}\\)$`),di={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Xr(Qr,gi,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:fi,formatHex:fi,formatHex8:pi,formatHsl:mi,formatRgb:hi,toString:hi});function fi(){return this.rgb().formatHex()}function pi(){return this.rgb().formatHex8()}function mi(){return Oi(this).formatHsl()}function hi(){return this.rgb().formatRgb()}function gi(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=ii.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?_i(t):n===3?new Y(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?vi(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?vi(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=ai.exec(e))?new Y(t[1],t[2],t[3],1):(t=oi.exec(e))?new Y(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=si.exec(e))?vi(t[1],t[2],t[3],t[4]):(t=ci.exec(e))?vi(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=li.exec(e))?Di(t[1],t[2]/100,t[3]/100,1):(t=ui.exec(e))?Di(t[1],t[2]/100,t[3]/100,t[4]):di.hasOwnProperty(e)?_i(di[e]):e===`transparent`?new Y(NaN,NaN,NaN,0):null}function _i(e){return new Y(e>>16&255,e>>8&255,e&255,1)}function vi(e,t,n,r){return r<=0&&(e=t=n=NaN),new Y(e,t,n,r)}function yi(e){return e instanceof Qr||(e=gi(e)),e?(e=e.rgb(),new Y(e.r,e.g,e.b,e.opacity)):new Y}function bi(e,t,n,r){return arguments.length===1?yi(e):new Y(e,t,n,r??1)}function Y(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Xr(Y,bi,Zr(Qr,{brighter(e){return e=e==null?ei:ei**+e,new Y(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?$r:$r**+e,new Y(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Y(Ti(this.r),Ti(this.g),Ti(this.b),wi(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:xi,formatHex:xi,formatHex8:Si,formatRgb:Ci,toString:Ci}));function xi(){return`#${Ei(this.r)}${Ei(this.g)}${Ei(this.b)}`}function Si(){return`#${Ei(this.r)}${Ei(this.g)}${Ei(this.b)}${Ei((isNaN(this.opacity)?1:this.opacity)*255)}`}function Ci(){let e=wi(this.opacity);return`${e===1?`rgb(`:`rgba(`}${Ti(this.r)}, ${Ti(this.g)}, ${Ti(this.b)}${e===1?`)`:`, ${e})`}`}function wi(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Ti(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Ei(e){return e=Ti(e),(e<16?`0`:``)+e.toString(16)}function Di(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ai(e,t,n,r)}function Oi(e){if(e instanceof Ai)return new Ai(e.h,e.s,e.l,e.opacity);if(e instanceof Qr||(e=gi(e)),!e)return new Ai;if(e instanceof Ai)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new Ai(o,s,c,e.opacity)}function ki(e,t,n,r){return arguments.length===1?Oi(e):new Ai(e,t,n,r??1)}function Ai(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Xr(Ai,ki,Zr(Qr,{brighter(e){return e=e==null?ei:ei**+e,new Ai(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?$r:$r**+e,new Ai(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new Y(Ni(e>=240?e-240:e+120,i,r),Ni(e,i,r),Ni(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new Ai(ji(this.h),Mi(this.s),Mi(this.l),wi(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){let e=wi(this.opacity);return`${e===1?`hsl(`:`hsla(`}${ji(this.h)}, ${Mi(this.s)*100}%, ${Mi(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function ji(e){return e=(e||0)%360,e<0?e+360:e}function Mi(e){return Math.max(0,Math.min(1,e||0))}function Ni(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var Pi=e=>()=>e;function Fi(e,t){return function(n){return e+n*t}}function Ii(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function Li(e){return(e=+e)==1?Ri:function(t,n){return n-t?Ii(t,n,e):Pi(isNaN(t)?n:t)}}function Ri(e,t){var n=t-e;return n?Fi(e,n):Pi(isNaN(e)?t:e)}var zi=(function e(t){var n=Li(t);function r(e,t){var r=n((e=bi(e)).r,(t=bi(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=Ri(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function Bi(e,t){t||=[];var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=e[i]*(1-a)+t[i]*a;return r}}function Vi(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Hi(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=Array(r),a=Array(n),o;for(o=0;o<r;++o)i[o]=Zi(e[o],t[o]);for(;o<n;++o)a[o]=t[o];return function(e){for(o=0;o<r;++o)a[o]=i[o](e);return a}}function Ui(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function Wi(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Gi(e,t){var n={},r={},i;for(i in(typeof e!=`object`||!e)&&(e={}),(typeof t!=`object`||!t)&&(t={}),t)i in e?n[i]=Zi(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var Ki=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,qi=new RegExp(Ki.source,`g`);function Ji(e){return function(){return e}}function Yi(e){return function(t){return e(t)+``}}function Xi(e,t){var n=Ki.lastIndex=qi.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=Ki.exec(e))&&(i=qi.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:Wi(r,i)})),n=qi.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?Yi(c[0].x):Ji(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}function Zi(e,t){var n=typeof t,r;return t==null||n===`boolean`?Pi(t):(n===`number`?Wi:n===`string`?(r=gi(t))?(t=r,zi):Xi:t instanceof gi?zi:t instanceof Date?Ui:Vi(t)?Bi:Array.isArray(t)?Hi:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?Gi:Wi)(e,t)}var Qi=180/Math.PI,$i={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function ea(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*Qi,skewX:Math.atan(c)*Qi,scaleX:o,scaleY:s}}var ta;function na(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?$i:ea(t.a,t.b,t.c,t.d,t.e,t.f)}function ra(e){return e==null||(ta||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),ta.setAttribute(`transform`,e),!(e=ta.transform.baseVal.consolidate()))?$i:(e=e.matrix,ea(e.a,e.b,e.c,e.d,e.e,e.f))}function ia(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:Wi(e,i)},{i:c-2,x:Wi(r,a)})}else(i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:Wi(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:Wi(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:Wi(e,n)},{i:s-2,x:Wi(t,r)})}else(n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var aa=ia(na,`px, `,`px)`,`deg)`),oa=ia(ra,`, `,`)`,`)`),sa=1e-12;function ca(e){return((e=Math.exp(e))+1/e)/2}function la(e){return((e=Math.exp(e))-1/e)/2}function ua(e){return((e=Math.exp(2*e))-1)/(e+1)}var da=(function e(t,n,r){function i(e,i){var a=e[0],o=e[1],s=e[2],c=i[0],l=i[1],u=i[2],d=c-a,f=l-o,p=d*d+f*f,m,h;if(p<sa)h=Math.log(u/s)/t,m=function(e){return[a+e*d,o+e*f,s*Math.exp(t*e*h)]};else{var g=Math.sqrt(p),_=(u*u-s*s+r*p)/(2*s*n*g),v=(u*u-s*s-r*p)/(2*u*n*g),y=Math.log(Math.sqrt(_*_+1)-_);h=(Math.log(Math.sqrt(v*v+1)-v)-y)/t,m=function(e){var r=e*h,i=ca(y),c=s/(n*g)*(i*ua(t*r+y)-la(y));return[a+c*d,o+c*f,s*i/ca(t*r+y)]}}return m.duration=h*1e3*t/Math.SQRT2,m}return i.rho=function(t){var n=Math.max(.001,+t),r=n*n;return e(n,r,r*r)},i})(Math.SQRT2,2,4),fa=0,pa=0,ma=0,ha=1e3,ga,_a,va=0,ya=0,ba=0,xa=typeof performance==`object`&&performance.now?performance:Date,Sa=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Ca(){return ya||=(Sa(wa),xa.now()+ba)}function wa(){ya=0}function Ta(){this._call=this._time=this._next=null}Ta.prototype=Ea.prototype={constructor:Ta,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?Ca():+n)+(t==null?0:+t),!this._next&&_a!==this&&(_a?_a._next=this:ga=this,_a=this),this._call=e,this._time=n,ja()},stop:function(){this._call&&(this._call=null,this._time=1/0,ja())}};function Ea(e,t,n){var r=new Ta;return r.restart(e,t,n),r}function Da(){Ca(),++fa;for(var e=ga,t;e;)(t=ya-e._time)>=0&&e._call.call(void 0,t),e=e._next;--fa}function Oa(){ya=(va=xa.now())+ba,fa=pa=0;try{Da()}finally{fa=0,Aa(),ya=0}}function ka(){var e=xa.now(),t=e-va;t>ha&&(ba-=t,va=e)}function Aa(){for(var e,t=ga,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:ga=n);_a=e,ja(r)}function ja(e){fa||(pa&&=clearTimeout(pa),e-ya>24?(e<1/0&&(pa=setTimeout(Oa,e-xa.now()-ba)),ma&&=clearInterval(ma)):(ma||=(va=xa.now(),setInterval(ka,ha)),fa=1,Sa(Oa)))}function Ma(e,t,n){var r=new Ta;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var Na=At(`start`,`end`,`cancel`,`interrupt`),Pa=[];function Fa(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;za(e,n,{name:t,index:r,group:i,on:Na,tween:Pa,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function Ia(e,t){var n=Ra(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function La(e,t){var n=Ra(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function Ra(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function za(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Ea(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return Ma(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(Ma(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function Ba(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n){if((r=n[o]).name!==t){a=!1;continue}i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]}a&&delete e.__transition}}function Va(e){return this.each(function(){Ba(this,e)})}function Ha(e,t){var n,r;return function(){var i=La(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function Ua(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=La(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function Wa(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=Ra(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?Ha:Ua)(n,e,t))}function Ga(e,t,n){var r=e._id;return e.each(function(){var e=La(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return Ra(e,r).value[t]}}function Ka(e,t){var n;return(typeof t==`number`?Wi:t instanceof gi?zi:(n=gi(t))?(t=n,zi):Xi)(e,t)}function qa(e){return function(){this.removeAttribute(e)}}function Ja(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Ya(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function Xa(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function Za(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function Qa(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function $a(e,t){var n=Rt(e),r=n===`transform`?oa:Ka;return this.attrTween(e,typeof t==`function`?(n.local?Qa:Za)(n,r,Ga(this,`attr.`+e,t)):t==null?(n.local?Ja:qa)(n):(n.local?Xa:Ya)(n,r,t))}function eo(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function to(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function no(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&to(e,i)),n}return i._value=t,i}function ro(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&eo(e,i)),n}return i._value=t,i}function io(e,t){var n=`attr.`+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!=`function`)throw Error();var r=Rt(e);return this.tween(n,(r.local?no:ro)(r,t))}function ao(e,t){return function(){Ia(this,e).delay=+t.apply(this,arguments)}}function oo(e,t){return t=+t,function(){Ia(this,e).delay=t}}function so(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?ao:oo)(t,e)):Ra(this.node(),t).delay}function co(e,t){return function(){La(this,e).duration=+t.apply(this,arguments)}}function lo(e,t){return t=+t,function(){La(this,e).duration=t}}function uo(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?co:lo)(t,e)):Ra(this.node(),t).duration}function fo(e,t){if(typeof t!=`function`)throw Error();return function(){La(this,e).ease=t}}function po(e){var t=this._id;return arguments.length?this.each(fo(t,e)):Ra(this.node(),t).ease}function mo(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();La(this,e).ease=n}}function ho(e){if(typeof e!=`function`)throw Error();return this.each(mo(this._id,e))}function go(e){typeof e!=`function`&&(e=Ft(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new Go(r,this._parents,this._name,this._id)}function _o(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new Go(o,this._parents,this._name,this._id)}function vo(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function yo(e,t,n){var r,i,a=vo(t)?Ia:La;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function bo(e,t){var n=this._id;return arguments.length<2?Ra(this.node(),n).on.on(e):this.each(yo(n,e,t))}function xo(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function So(){return this.on(`end.remove`,xo(this._id))}function Co(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=Ht(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,Fa(l[f],t,n,f,l,Ra(u,n)));return new Go(a,this._parents,t,n)}function wo(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=Kt(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=Ra(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&Fa(p,t,n,h,f,m);a.push(f),o.push(u)}return new Go(a,o,t,n)}var To=Pr.prototype.constructor;function Eo(){return new To(this._groups,this._parents)}function Do(e,t){var n,r,i;return function(){var a=Rn(this,e),o=(this.style.removeProperty(e),Rn(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function Oo(e){return function(){this.style.removeProperty(e)}}function ko(e,t,n){var r,i=n+``,a;return function(){var o=Rn(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function Ao(e,t,n){var r,i,a;return function(){var o=Rn(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),Rn(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function jo(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=La(this,e),l=c.on,u=c.value[a]==null?s||=Oo(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function Mo(e,t,n){var r=(e+=``)==`transform`?aa:Ka;return t==null?this.styleTween(e,Do(e,r)).on(`end.style.`+e,Oo(e)):typeof t==`function`?this.styleTween(e,Ao(e,r,Ga(this,`style.`+e,t))).each(jo(this._id,e)):this.styleTween(e,ko(e,r,t),n).on(`end.style.`+e,null)}function No(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Po(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&No(e,a,n)),r}return a._value=t,a}function Fo(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,Po(e,t,n??``))}function Io(e){return function(){this.textContent=e}}function Lo(e){return function(){var t=e(this);this.textContent=t??``}}function Ro(e){return this.tween(`text`,typeof e==`function`?Lo(Ga(this,`text`,e)):Io(e==null?``:e+``))}function zo(e){return function(t){this.textContent=e.call(this,t)}}function Bo(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&zo(r)),t}return r._value=e,r}function Vo(e){var t=`text`;if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!=`function`)throw Error();return this.tween(t,Bo(e))}function Ho(){for(var e=this._name,t=this._id,n=qo(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=Ra(c,t);Fa(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Go(r,this._parents,e,n)}function Uo(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=La(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var Wo=0;function Go(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function Ko(e){return Pr().transition(e)}function qo(){return++Wo}var Jo=Pr.prototype;Go.prototype=Ko.prototype={constructor:Go,select:Co,selectAll:wo,selectChild:Jo.selectChild,selectChildren:Jo.selectChildren,filter:go,merge:_o,selection:Eo,transition:Ho,call:Jo.call,nodes:Jo.nodes,node:Jo.node,size:Jo.size,empty:Jo.empty,each:Jo.each,on:bo,attr:$a,attrTween:io,style:Mo,styleTween:Fo,text:Ro,textTween:Vo,remove:So,tween:Wa,delay:so,duration:uo,ease:po,easeVarying:ho,end:Uo,[Symbol.iterator]:Jo[Symbol.iterator]};function Yo(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Xo={time:null,delay:0,duration:250,ease:Yo};function Zo(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function Qo(e){var t,n;e instanceof Go?(t=e._id,e=e._name):(t=qo(),(n=Xo).time=Ca(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&Fa(c,e,t,l,o,n||Zo(c,t));return new Go(r,this._parents,e,t)}Pr.prototype.interrupt=Va,Pr.prototype.transition=Qo;var $o=e=>()=>e;function es(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function ts(e,t,n){this.k=e,this.x=t,this.y=n}ts.prototype={constructor:ts,scale:function(e){return e===1?this:new ts(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new ts(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return`translate(`+this.x+`,`+this.y+`) scale(`+this.k+`)`}};var ns=new ts(1,0,0);rs.prototype=ts.prototype;function rs(e){for(;!e.__zoom;)if(!(e=e.parentNode))return ns;return e.__zoom}function is(e){e.stopImmediatePropagation()}function as(e){e.preventDefault(),e.stopImmediatePropagation()}function os(e){return(!e.ctrlKey||e.type===`wheel`)&&!e.button}function ss(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute(`viewBox`)?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function cs(){return this.__zoom||ns}function ls(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function us(){return navigator.maxTouchPoints||`ontouchstart`in this}function ds(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),o>a?(a+o)/2:Math.min(0,a)||Math.max(0,o))}function fs(){var e=os,t=ss,n=ds,r=ls,i=us,a=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],s=250,c=da,l=At(`start`,`zoom`,`end`),u,d,f,p=500,m=150,h=0,g=10;function _(e){e.property(`__zoom`,cs).on(`wheel.zoom`,w,{passive:!1}).on(`mousedown.zoom`,T).on(`dblclick.zoom`,E).filter(i).on(`touchstart.zoom`,D).on(`touchmove.zoom`,O).on(`touchend.zoom touchcancel.zoom`,k).style(`-webkit-tap-highlight-color`,`rgba(0,0,0,0)`)}_.transform=function(e,t,n,r){var i=e.selection?e.selection():e;i.property(`__zoom`,cs),e===i?i.interrupt().each(function(){S(this,arguments).event(r).start().zoom(null,typeof t==`function`?t.apply(this,arguments):t).end()}):x(e,t,n,r)},_.scaleBy=function(e,t,n,r){_.scaleTo(e,function(){return this.__zoom.k*(typeof t==`function`?t.apply(this,arguments):t)},n,r)},_.scaleTo=function(e,r,i,a){_.transform(e,function(){var e=t.apply(this,arguments),a=this.__zoom,s=i==null?b(e):typeof i==`function`?i.apply(this,arguments):i,c=a.invert(s),l=typeof r==`function`?r.apply(this,arguments):r;return n(y(v(a,l),s,c),e,o)},i,a)},_.translateBy=function(e,r,i,a){_.transform(e,function(){return n(this.__zoom.translate(typeof r==`function`?r.apply(this,arguments):r,typeof i==`function`?i.apply(this,arguments):i),t.apply(this,arguments),o)},null,a)},_.translateTo=function(e,r,i,a,s){_.transform(e,function(){var e=t.apply(this,arguments),s=this.__zoom,c=a==null?b(e):typeof a==`function`?a.apply(this,arguments):a;return n(ns.translate(c[0],c[1]).scale(s.k).translate(typeof r==`function`?-r.apply(this,arguments):-r,typeof i==`function`?-i.apply(this,arguments):-i),e,o)},a,s)};function v(e,t){return t=Math.max(a[0],Math.min(a[1],t)),t===e.k?e:new ts(t,e.x,e.y)}function y(e,t,n){var r=t[0]-n[0]*e.k,i=t[1]-n[1]*e.k;return r===e.x&&i===e.y?e:new ts(e.k,r,i)}function b(e){return[(+e[0][0]+ +e[1][0])/2,(+e[0][1]+ +e[1][1])/2]}function x(e,n,r,i){e.on(`start.zoom`,function(){S(this,arguments).event(i).start()}).on(`interrupt.zoom end.zoom`,function(){S(this,arguments).event(i).end()}).tween(`zoom`,function(){var e=this,a=arguments,o=S(e,a).event(i),s=t.apply(e,a),l=r==null?b(s):typeof r==`function`?r.apply(e,a):r,u=Math.max(s[1][0]-s[0][0],s[1][1]-s[0][1]),d=e.__zoom,f=typeof n==`function`?n.apply(e,a):n,p=c(d.invert(l).concat(u/d.k),f.invert(l).concat(u/f.k));return function(e){if(e===1)e=f;else{var t=p(e),n=u/t[2];e=new ts(n,l[0]-t[0]*n,l[1]-t[1]*n)}o.zoom(null,e)}})}function S(e,t,n){return!n&&e.__zooming||new C(e,t)}function C(e,n){this.that=e,this.args=n,this.active=0,this.sourceEvent=null,this.extent=t.apply(e,n),this.taps=0}C.prototype={event:function(e){return e&&(this.sourceEvent=e),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit(`start`)),this},zoom:function(e,t){return this.mouse&&e!==`mouse`&&(this.mouse[1]=t.invert(this.mouse[0])),this.touch0&&e!==`touch`&&(this.touch0[1]=t.invert(this.touch0[0])),this.touch1&&e!==`touch`&&(this.touch1[1]=t.invert(this.touch1[0])),this.that.__zoom=t,this.emit(`zoom`),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit(`end`)),this},emit:function(e){var t=Ir(this.that).datum();l.call(e,this.that,new es(e,{sourceEvent:this.sourceEvent,target:_,type:e,transform:this.that.__zoom,dispatch:l}),t)}};function w(t,...i){if(!e.apply(this,arguments))return;var s=S(this,i).event(t),c=this.__zoom,l=Math.max(a[0],Math.min(a[1],c.k*2**r.apply(this,arguments))),u=Bt(t);if(s.wheel)(s.mouse[0][0]!==u[0]||s.mouse[0][1]!==u[1])&&(s.mouse[1]=c.invert(s.mouse[0]=u)),clearTimeout(s.wheel);else if(c.k===l)return;else s.mouse=[u,c.invert(u)],Ba(this),s.start();as(t),s.wheel=setTimeout(d,m),s.zoom(`mouse`,n(y(v(c,l),s.mouse[0],s.mouse[1]),s.extent,o));function d(){s.wheel=null,s.end()}}function T(t,...r){if(f||!e.apply(this,arguments))return;var i=t.currentTarget,a=S(this,r,!0).event(t),s=Ir(t.view).on(`mousemove.zoom`,d,!0).on(`mouseup.zoom`,p,!0),c=Bt(t,i),l=t.clientX,u=t.clientY;Vr(t.view),is(t),a.mouse=[c,this.__zoom.invert(c)],Ba(this),a.start();function d(e){if(as(e),!a.moved){var t=e.clientX-l,r=e.clientY-u;a.moved=t*t+r*r>h}a.event(e).zoom(`mouse`,n(y(a.that.__zoom,a.mouse[0]=Bt(e,i),a.mouse[1]),a.extent,o))}function p(e){s.on(`mousemove.zoom mouseup.zoom`,null),Hr(e.view,a.moved),as(e),a.event(e).end()}}function E(r,...i){if(e.apply(this,arguments)){var a=this.__zoom,c=Bt(r.changedTouches?r.changedTouches[0]:r,this),l=a.invert(c),u=a.k*(r.shiftKey?.5:2),d=n(y(v(a,u),c,l),t.apply(this,i),o);as(r),s>0?Ir(this).transition().duration(s).call(x,d,c,r):Ir(this).call(_.transform,d,c,r)}}function D(t,...n){if(e.apply(this,arguments)){var r=t.touches,i=r.length,a=S(this,n,t.changedTouches.length===i).event(t),o,s,c,l;for(is(t),s=0;s<i;++s)c=r[s],l=Bt(c,this),l=[l,this.__zoom.invert(l),c.identifier],a.touch0?!a.touch1&&a.touch0[2]!==l[2]&&(a.touch1=l,a.taps=0):(a.touch0=l,o=!0,a.taps=1+!!u);u&&=clearTimeout(u),o&&(a.taps<2&&(d=l[0],u=setTimeout(function(){u=null},p)),Ba(this),a.start())}}function O(e,...t){if(this.__zooming){var r=S(this,t).event(e),i=e.changedTouches,a=i.length,s,c,l,u;for(as(e),s=0;s<a;++s)c=i[s],l=Bt(c,this),r.touch0&&r.touch0[2]===c.identifier?r.touch0[0]=l:r.touch1&&r.touch1[2]===c.identifier&&(r.touch1[0]=l);if(c=r.that.__zoom,r.touch1){var d=r.touch0[0],f=r.touch0[1],p=r.touch1[0],m=r.touch1[1],h=(h=p[0]-d[0])*h+(h=p[1]-d[1])*h,g=(g=m[0]-f[0])*g+(g=m[1]-f[1])*g;c=v(c,Math.sqrt(h/g)),l=[(d[0]+p[0])/2,(d[1]+p[1])/2],u=[(f[0]+m[0])/2,(f[1]+m[1])/2]}else if(r.touch0)l=r.touch0[0],u=r.touch0[1];else return;r.zoom(`touch`,n(y(c,l,u),r.extent,o))}}function k(e,...t){if(this.__zooming){var n=S(this,t).event(e),r=e.changedTouches,i=r.length,a,o;for(is(e),f&&clearTimeout(f),f=setTimeout(function(){f=null},p),a=0;a<i;++a)o=r[a],n.touch0&&n.touch0[2]===o.identifier?delete n.touch0:n.touch1&&n.touch1[2]===o.identifier&&delete n.touch1;if(n.touch1&&!n.touch0&&(n.touch0=n.touch1,delete n.touch1),n.touch0)n.touch0[1]=this.__zoom.invert(n.touch0[0]);else if(n.end(),n.taps===2&&(o=Bt(o,this),Math.hypot(d[0]-o[0],d[1]-o[1])<g)){var s=Ir(this).on(`dblclick.zoom`);s&&s.apply(this,arguments)}}}return _.wheelDelta=function(e){return arguments.length?(r=typeof e==`function`?e:$o(+e),_):r},_.filter=function(t){return arguments.length?(e=typeof t==`function`?t:$o(!!t),_):e},_.touchable=function(e){return arguments.length?(i=typeof e==`function`?e:$o(!!e),_):i},_.extent=function(e){return arguments.length?(t=typeof e==`function`?e:$o([[+e[0][0],+e[0][1]],[+e[1][0],+e[1][1]]]),_):t},_.scaleExtent=function(e){return arguments.length?(a[0]=+e[0],a[1]=+e[1],_):[a[0],a[1]]},_.translateExtent=function(e){return arguments.length?(o[0][0]=+e[0][0],o[1][0]=+e[1][0],o[0][1]=+e[0][1],o[1][1]=+e[1][1],_):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},_.constrain=function(e){return arguments.length?(n=e,_):n},_.duration=function(e){return arguments.length?(s=+e,_):s},_.interpolate=function(e){return arguments.length?(c=e,_):c},_.on=function(){var e=l.on.apply(l,arguments);return e===l?_:e},_.clickDistance=function(e){return arguments.length?(h=(e=+e)*e,_):Math.sqrt(h)},_.tapDistance=function(e){return arguments.length?(g=+e,_):g},_}var ps={error001:(e=`react`)=>`Seems like you have not used ${e===`svelte`?`SvelteFlowProvider`:`ReactFlowProvider`} as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>`It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.`,error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>`The parent container needs a width and a height to render the graph.`,error005:()=>`Only child nodes can use a parent extent.`,error006:()=>`Can't create edge. An edge needs a source and a target.`,error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e===`source`?n:r}", edge id: ${t}.`,error010:()=>`Handle: No node id found. Make sure to only use a Handle inside a custom Node.`,error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e=`react`)=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>`useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.`,error015:()=>`It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.`,error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},ms=[[-1/0,-1/0],[1/0,1/0]],hs=[`Enter`,` `,`Escape`],gs={"node.a11yDescription.default":`Press enter or space to select a node. Press delete to remove it and escape to cancel.`,"node.a11yDescription.keyboardDisabled":`Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.`,"node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":`Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.`,"controls.ariaLabel":`Control Panel`,"controls.zoomIn.ariaLabel":`Zoom In`,"controls.zoomOut.ariaLabel":`Zoom Out`,"controls.fitView.ariaLabel":`Fit View`,"controls.interactive.ariaLabel":`Toggle Interactivity`,"minimap.ariaLabel":`Mini Map`,"handle.ariaLabel":`Handle`},_s;(function(e){e.Strict=`strict`,e.Loose=`loose`})(_s||={});var vs;(function(e){e.Free=`free`,e.Vertical=`vertical`,e.Horizontal=`horizontal`})(vs||={});var ys;(function(e){e.Partial=`partial`,e.Full=`full`})(ys||={});var bs={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null},xs;(function(e){e.Bezier=`default`,e.Straight=`straight`,e.Step=`step`,e.SmoothStep=`smoothstep`,e.SimpleBezier=`simplebezier`})(xs||={});var Ss;(function(e){e.Arrow=`arrow`,e.ArrowClosed=`arrowclosed`})(Ss||={});var X;(function(e){e.Left=`left`,e.Top=`top`,e.Right=`right`,e.Bottom=`bottom`})(X||={});var Cs={[X.Left]:X.Right,[X.Right]:X.Left,[X.Top]:X.Bottom,[X.Bottom]:X.Top};function ws(e){return e===null?null:e?`valid`:`invalid`}var Ts=e=>`id`in e&&`source`in e&&`target`in e,Es=e=>`id`in e&&`position`in e&&!(`source`in e)&&!(`target`in e),Ds=e=>`id`in e&&`internals`in e&&!(`source`in e)&&!(`target`in e),Os=(e,t=[0,0])=>{let{width:n,height:r}=cc(e),i=e.origin??t,a=n*i[0],o=r*i[1];return{x:e.position.x-a,y:e.position.y-o}},ks=(e,t={nodeOrigin:[0,0]})=>e.length===0?{x:0,y:0,width:0,height:0}:Ws(e.reduce((e,n)=>{let r=typeof n==`string`,i=!t.nodeLookup&&!r?n:void 0;return t.nodeLookup&&(i=r?t.nodeLookup.get(n):Ds(n)?n:t.nodeLookup.get(n.id)),Hs(e,i?Ks(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0})},{x:1/0,y:1/0,x2:-1/0,y2:-1/0})),As=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(e=>{(t.filter===void 0||t.filter(e))&&(n=Hs(n,Ks(e)),r=!0)}),r?Ws(n):{x:0,y:0,width:0,height:0}},js=(e,t,[n,r,i]=[0,0,1],a=!1,o=!1)=>{let s=(t.x-n)/i,c=(t.y-r)/i,l=t.width/i,u=t.height/i,d=[];for(let t of e.values()){let{measured:e,selectable:n=!0,hidden:r=!1}=t;if(o&&!n||r)continue;let i=e.width??t.width??t.initialWidth??0,f=e.height??t.height??t.initialHeight??0,{x:p,y:m}=t.internals.positionAbsolute,h=Js(s,c,l,u,p,m,i,f),g=i*f,_=a&&h>0;(!t.internals.handleBounds||_||h>=g||t.dragging)&&d.push(t)}return d},Ms=(e,t)=>{let n=new Set;return e.forEach(e=>{n.add(e.id)}),t.filter(e=>n.has(e.source)||n.has(e.target))};function Ns(e,t){let n=new Map,r=t?.nodes?new Set(t.nodes.map(e=>e.id)):null;return e.forEach(e=>{e.measured.width&&e.measured.height&&(t?.includeHiddenNodes||!e.hidden)&&(!r||r.has(e.id))&&n.set(e.id,e)}),n}async function Ps({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:a},o){if(e.size===0)return!0;let s=ac(As(Ns(e,o)),t,n,o?.minZoom??i,o?.maxZoom??a,o?.padding??.1);return await r.setViewport(s,{duration:o?.duration,ease:o?.ease,interpolate:o?.interpolate}),!0}function Fs({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:i,onError:a}){let o=n.get(e),s=o.parentId?n.get(o.parentId):void 0,{x:c,y:l}=s?s.internals.positionAbsolute:{x:0,y:0},u=o.origin??r,d=o.extent||i;if(o.extent===`parent`&&!o.expandParent)if(!s)a?.(`005`,ps.error005());else{let e=s.measured.width,t=s.measured.height;e&&t&&(d=[[c,l],[c+e,l+t]])}else s&&sc(o.extent)&&(d=[[o.extent[0][0]+c,o.extent[0][1]+l],[o.extent[1][0]+c,o.extent[1][1]+l]]);let f=sc(d)?Rs(t,d,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&a?.(`015`,ps.error015()),{position:{x:f.x-c+(o.measured.width??0)*u[0],y:f.y-l+(o.measured.height??0)*u[1]},positionAbsolute:f}}async function Is({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){let a=new Set(e.map(e=>e.id)),o=[];for(let e of n){if(e.deletable===!1)continue;let t=a.has(e.id),n=!t&&e.parentId&&o.find(t=>t.id===e.parentId);(t||n)&&o.push(e)}let s=new Set(t.map(e=>e.id)),c=r.filter(e=>e.deletable!==!1),l=Ms(o,c);for(let e of c)s.has(e.id)&&!l.find(t=>t.id===e.id)&&l.push(e);if(!i)return{edges:l,nodes:o};let u=await i({nodes:o,edges:l});return typeof u==`boolean`?u?{edges:l,nodes:o}:{edges:[],nodes:[]}:u}var Ls=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Rs=(e={x:0,y:0},t,n)=>({x:Ls(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Ls(e.y,t[0][1],t[1][1]-(n?.height??0))});function zs(e,t,n){let{width:r,height:i}=cc(n),{x:a,y:o}=n.internals.positionAbsolute;return Rs(e,[[a,o],[a+r,o+i]],t)}var Bs=(e,t,n)=>e<t?Ls(Math.abs(e-t),1,t)/t:e>n?-Ls(Math.abs(e-n),1,t)/t:0,Vs=(e,t,n=15,r=40)=>[Bs(e.x,r,t.width-r)*n,Bs(e.y,r,t.height-r)*n],Hs=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Us=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),Ws=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Gs=(e,t=[0,0])=>{let{x:n,y:r}=Ds(e)?e.internals.positionAbsolute:Os(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},Ks=(e,t=[0,0])=>{let{x:n,y:r}=Ds(e)?e.internals.positionAbsolute:Os(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},qs=(e,t)=>Ws(Hs(Us(e),Us(t))),Js=(e,t,n,r,i,a,o,s)=>{let c=Math.max(0,Math.min(e+n,i+o)-Math.max(e,i)),l=Math.max(0,Math.min(t+r,a+s)-Math.max(t,a));return Math.ceil(c*l)},Ys=(e,t)=>Js(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),Xs=e=>Zs(e.width)&&Zs(e.height)&&Zs(e.x)&&Zs(e.y),Zs=e=>!isNaN(e)&&isFinite(e),Qs=(e,t)=>(e,t)=>{},$s=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),ec=({x:e,y:t},[n,r,i],a=!1,o=[1,1])=>{let s={x:(e-n)/i,y:(t-r)/i};return a?$s(s,o):s},tc=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function nc(e,t){if(typeof e==`number`)return Math.floor((t-t/(1+e))*.5);if(typeof e==`string`&&e.endsWith(`px`)){let t=parseFloat(e);if(!Number.isNaN(t))return Math.floor(t)}if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function rc(e,t,n){if(typeof e==`string`||typeof e==`number`){let r=nc(e,n),i=nc(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e==`object`){let r=nc(e.top??e.y??0,n),i=nc(e.bottom??e.y??0,n),a=nc(e.left??e.x??0,t),o=nc(e.right??e.x??0,t);return{top:r,right:o,bottom:i,left:a,x:a+o,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function ic(e,t,n,r,i,a){let{x:o,y:s}=tc(e,[t,n,r]),{x:c,y:l}=tc({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-c,d=a-l;return{left:Math.floor(o),top:Math.floor(s),right:Math.floor(u),bottom:Math.floor(d)}}var ac=(e,t,n,r,i,a)=>{let o=rc(a,t,n),s=(t-o.x)/e.width,c=(n-o.y)/e.height,l=Ls(Math.min(s,c),r,i),u=e.x+e.width/2,d=e.y+e.height/2,f=t/2-u*l,p=n/2-d*l,m=ic(e,f,p,l,t,n),h={left:Math.min(m.left-o.left,0),top:Math.min(m.top-o.top,0),right:Math.min(m.right-o.right,0),bottom:Math.min(m.bottom-o.bottom,0)};return{x:f-h.left+h.right,y:p-h.top+h.bottom,zoom:l}},oc=()=>typeof navigator<`u`&&navigator?.userAgent?.indexOf(`Mac`)>=0;function sc(e){return e!=null&&e!==`parent`}function cc(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function lc(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function uc(e,t={width:0,height:0},n,r,i){let a={...e},o=r.get(n);if(o){let e=o.origin||i;a.x+=o.internals.positionAbsolute.x-(t.width??0)*e[0],a.y+=o.internals.positionAbsolute.y-(t.height??0)*e[1]}return a}function dc(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function fc(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function pc(e){return{...gs,...e||{}}}function mc(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){let{x:a,y:o}=bc(e),s=ec({x:a-(i?.left??0),y:o-(i?.top??0)},r),{x:c,y:l}=n?$s(s,t):s;return{xSnapped:c,ySnapped:l,...s}}var hc=e=>({width:e.offsetWidth,height:e.offsetHeight}),gc=e=>e?.getRootNode?.()||window?.document,_c=[`INPUT`,`SELECT`,`TEXTAREA`];function vc(e){let t=e.composedPath?.()?.[0]||e.target;return t?.nodeType===1?_c.includes(t.nodeName)||t.hasAttribute(`contenteditable`)||!!t.closest(`.nokey`):!1}var yc=e=>`clientX`in e,bc=(e,t)=>{let n=yc(e),r=n?e.clientX:e.touches?.[0].clientX,i=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:i-(t?.top??0)}},xc=(e,t,n,r,i)=>{let a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...hc(t)}})};function Sc({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:i,sourceControlY:a,targetControlX:o,targetControlY:s}){let c=e*.125+i*.375+o*.375+n*.125,l=t*.125+a*.375+s*.375+r*.125;return[c,l,Math.abs(c-e),Math.abs(l-t)]}function Cc(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function wc({pos:e,x1:t,y1:n,x2:r,y2:i,c:a}){switch(e){case X.Left:return[t-Cc(t-r,a),n];case X.Right:return[t+Cc(r-t,a),n];case X.Top:return[t,n-Cc(n-i,a)];case X.Bottom:return[t,n+Cc(i-n,a)]}}function Tc({sourceX:e,sourceY:t,sourcePosition:n=X.Bottom,targetX:r,targetY:i,targetPosition:a=X.Top,curvature:o=.25}){let[s,c]=wc({pos:n,x1:e,y1:t,x2:r,y2:i,c:o}),[l,u]=wc({pos:a,x1:r,y1:i,x2:e,y2:t,c:o}),[d,f,p,m]=Sc({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:s,sourceControlY:c,targetControlX:l,targetControlY:u});return[`M${e},${t} C${s},${c} ${l},${u} ${r},${i}`,d,f,p,m]}function Ec({sourceX:e,sourceY:t,targetX:n,targetY:r}){let i=Math.abs(n-e)/2,a=n<e?n+i:n-i,o=Math.abs(r-t)/2;return[a,r<t?r+o:r-o,i,o]}function Dc({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:a=`basic`}){return a===`manual`?r:(i&&n?r+1e3:r)+Math.max(e.parentId||i&&e.selected?e.internals.z:0,t.parentId||i&&t.selected?t.internals.z:0)}function Oc({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){let a=Hs(Ks(e),Ks(t));return a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1),Ys({x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]},Ws(a))>0}var kc=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||``}-${n}${r||``}`,Ac=(e,t)=>t.some(t=>t.source===e.source&&t.target===e.target&&(t.sourceHandle===e.sourceHandle||!t.sourceHandle&&!e.sourceHandle)&&(t.targetHandle===e.targetHandle||!t.targetHandle&&!e.targetHandle)),jc=(e,t,n={})=>{if(!e.source||!e.target)return n.onError?.(`006`,ps.error006()),t;let r=n.getEdgeId||kc,i;return i=Ts(e)?{...e}:{...e,id:r(e)},Ac(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function Mc({sourceX:e,sourceY:t,targetX:n,targetY:r}){let[i,a,o,s]=Ec({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,a,o,s]}var Nc={[X.Left]:{x:-1,y:0},[X.Right]:{x:1,y:0},[X.Top]:{x:0,y:-1},[X.Bottom]:{x:0,y:1}},Pc=({source:e,sourcePosition:t=X.Bottom,target:n})=>t===X.Left||t===X.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},Fc=(e,t)=>Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2);function Ic({source:e,sourcePosition:t=X.Bottom,target:n,targetPosition:r=X.Top,center:i,offset:a,stepPosition:o}){let s=Nc[t],c=Nc[r],l={x:e.x+s.x*a,y:e.y+s.y*a},u={x:n.x+c.x*a,y:n.y+c.y*a},d=Pc({source:l,sourcePosition:t,target:u}),f=d.x===0?`y`:`x`,p=d[f],m=[],h,g,_={x:0,y:0},v={x:0,y:0},[,,y,b]=Ec({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(s[f]*c[f]===-1){f===`x`?(h=i.x??l.x+(u.x-l.x)*o,g=i.y??(l.y+u.y)/2):(h=i.x??(l.x+u.x)/2,g=i.y??l.y+(u.y-l.y)*o);let e=[{x:h,y:l.y},{x:h,y:u.y}],t=[{x:l.x,y:g},{x:u.x,y:g}];m=s[f]===p?f===`x`?e:t:f===`x`?t:e}else{let i=[{x:l.x,y:u.y}],o=[{x:u.x,y:l.y}];if(m=f===`x`?s.x===p?o:i:s.y===p?i:o,t===r){let t=Math.abs(e[f]-n[f]);if(t<=a){let r=Math.min(a-1,a-t);s[f]===p?_[f]=(l[f]>e[f]?-1:1)*r:v[f]=(u[f]>n[f]?-1:1)*r}}if(t!==r){let e=f===`x`?`y`:`x`,t=s[f]===c[e],n=l[e]>u[e],r=l[e]<u[e];(s[f]===1&&(!t&&n||t&&r)||s[f]!==1&&(!t&&r||t&&n))&&(m=f===`x`?i:o)}let d={x:l.x+_.x,y:l.y+_.y},y={x:u.x+v.x,y:u.y+v.y};Math.max(Math.abs(d.x-m[0].x),Math.abs(y.x-m[0].x))>=Math.max(Math.abs(d.y-m[0].y),Math.abs(y.y-m[0].y))?(h=(d.x+y.x)/2,g=m[0].y):(h=m[0].x,g=(d.y+y.y)/2)}let x={x:l.x+_.x,y:l.y+_.y},S={x:u.x+v.x,y:u.y+v.y};return[[e,...x.x!==m[0].x||x.y!==m[0].y?[x]:[],...m,...S.x!==m[m.length-1].x||S.y!==m[m.length-1].y?[S]:[],n],h,g,y,b]}function Lc(e,t,n,r){let i=Math.min(Fc(e,t)/2,Fc(t,n)/2,r),{x:a,y:o}=t;if(e.x===a&&a===n.x||e.y===o&&o===n.y)return`L${a} ${o}`;if(e.y===o){let t=e.x<n.x?-1:1,r=e.y<n.y?1:-1;return`L ${a+i*t},${o}Q ${a},${o} ${a},${o+i*r}`}let s=e.x<n.x?1:-1;return`L ${a},${o+i*(e.y<n.y?-1:1)}Q ${a},${o} ${a+i*s},${o}`}function Rc({sourceX:e,sourceY:t,sourcePosition:n=X.Bottom,targetX:r,targetY:i,targetPosition:a=X.Top,borderRadius:o=5,centerX:s,centerY:c,offset:l=20,stepPosition:u=.5}){let[d,f,p,m,h]=Ic({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:a,center:{x:s,y:c},offset:l,stepPosition:u}),g=`M${d[0].x} ${d[0].y}`;for(let e=1;e<d.length-1;e++)g+=Lc(d[e-1],d[e],d[e+1],o);return g+=`L${d[d.length-1].x} ${d[d.length-1].y}`,[g,f,p,m,h]}function zc(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Bc(e){let{sourceNode:t,targetNode:n}=e;if(!zc(t)||!zc(n))return null;let r=t.internals.handleBounds||Vc(t.handles),i=n.internals.handleBounds||Vc(n.handles),a=Uc(r?.source??[],e.sourceHandle),o=Uc(e.connectionMode===_s.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!a||!o)return e.onError?.(`008`,ps.error008(a?`target`:`source`,{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;let s=a?.position||X.Bottom,c=o?.position||X.Top,l=Hc(t,a,s),u=Hc(n,o,c);return{sourceX:l.x,sourceY:l.y,targetX:u.x,targetY:u.y,sourcePosition:s,targetPosition:c}}function Vc(e){if(!e)return null;let t=[],n=[];for(let r of e)r.width=r.width??1,r.height=r.height??1,r.type===`source`?t.push(r):r.type===`target`&&n.push(r);return{source:t,target:n}}function Hc(e,t,n=X.Left,r=!1){let i=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:o,height:s}=t??cc(e);if(r)return{x:i+o/2,y:a+s/2};switch(t?.position??n){case X.Top:return{x:i+o/2,y:a};case X.Right:return{x:i+o,y:a+s/2};case X.Bottom:return{x:i+o/2,y:a+s};case X.Left:return{x:i,y:a+s/2}}}function Uc(e,t){return e&&(t?e.find(e=>e.id===t):e[0])||null}function Wc(e,t){return e?typeof e==`string`?e:`${t?`${t}__`:``}${Object.keys(e).sort().map(t=>`${t}=${e[t]}`).join(`&`)}`:``}function Gc(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:i}){let a=new Set;return e.reduce((e,o)=>([o.markerStart||r,o.markerEnd||i].forEach(r=>{if(r&&typeof r==`object`){let i=Wc(r,t);a.has(i)||(e.push({id:i,color:r.color||n,...r}),a.add(i))}}),e),[]).sort((e,t)=>e.id.localeCompare(t.id))}var Kc=1e3,qc=10,Jc={nodeOrigin:[0,0],nodeExtent:ms,elevateNodesOnSelect:!0,zIndexMode:`basic`,defaults:{}},Yc={...Jc,checkEquality:!0};function Xc(e,t){let n={...e};for(let e in t)t[e]!==void 0&&(n[e]=t[e]);return n}function Zc(e,t,n){let r=Xc(Jc,n);for(let n of e.values())if(n.parentId)nl(n,e,t,r);else{let e=Rs(Os(n,r.nodeOrigin),sc(n.extent)?n.extent:r.nodeExtent,cc(n));n.internals.positionAbsolute=e}}function Qc(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;let n=[],r=[];for(let t of e.handles){let i={id:t.id,width:t.width??1,height:t.height??1,nodeId:e.id,x:t.x,y:t.y,position:t.position,type:t.type};t.type===`source`?n.push(i):t.type===`target`&&r.push(i)}return{source:n,target:r}}function $c(e){return e===`manual`}function el(e,t,n,r={}){let i=Xc(Yc,r),a={i:0},o=new Map(t),s=i?.elevateNodesOnSelect&&!$c(i.zIndexMode)?Kc:0,c=e.length>0,l=!1;t.clear(),n.clear();for(let u of e){let e=o.get(u.id);if(i.checkEquality&&u===e?.internals.userNode)t.set(u.id,e);else{let n=Rs(Os(u,i.nodeOrigin),sc(u.extent)?u.extent:i.nodeExtent,cc(u));e={...i.defaults,...u,measured:{width:u.measured?.width,height:u.measured?.height},internals:{positionAbsolute:n,handleBounds:Qc(u,e),z:rl(u,s,i.zIndexMode),userNode:u}},t.set(u.id,e)}(e.measured===void 0||e.measured.width===void 0||e.measured.height===void 0)&&!e.hidden&&(c=!1),u.parentId&&nl(e,t,n,r,a),l||=u.selected??!1}return{nodesInitialized:c,hasSelectedNodes:l}}function tl(e,t){if(!e.parentId)return;let n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function nl(e,t,n,r,i){let{elevateNodesOnSelect:a,nodeOrigin:o,nodeExtent:s,zIndexMode:c}=Xc(Jc,r),l=e.parentId,u=t.get(l);if(!u){console.warn(`Parent node ${l} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}tl(e,n),i&&!u.parentId&&u.internals.rootParentIndex===void 0&&c===`auto`&&(u.internals.rootParentIndex=++i.i,u.internals.z=u.internals.z+i.i*qc),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);let{x:d,y:f,z:p}=il(e,u,o,s,a&&!$c(c)?Kc:0,c),{positionAbsolute:m}=e.internals,h=d!==m.x||f!==m.y;(h||p!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:h?{x:d,y:f}:m,z:p}})}function rl(e,t,n){let r=Zs(e.zIndex)?e.zIndex:0;return $c(n)?r:r+(e.selected?t:0)}function il(e,t,n,r,i,a){let{x:o,y:s}=t.internals.positionAbsolute,c=cc(e),l=Os(e,n),u=sc(e.extent)?Rs(l,e.extent,c):l,d=Rs({x:o+u.x,y:s+u.y},r,c);e.extent===`parent`&&(d=zs(d,c,t));let f=rl(e,i,a),p=t.internals.z??0;return{x:d.x,y:d.y,z:p>=f?p+1:f}}function al(e,t,n,r=[0,0]){let i=[],a=new Map;for(let n of e){let e=t.get(n.parentId);if(!e)continue;let r=qs(a.get(n.parentId)?.expandedRect??Gs(e),n.rect);a.set(n.parentId,{expandedRect:r,parent:e})}return a.size>0&&a.forEach(({expandedRect:t,parent:a},o)=>{let s=a.internals.positionAbsolute,c=cc(a),l=a.origin??r,u=t.x<s.x?Math.round(Math.abs(s.x-t.x)):0,d=t.y<s.y?Math.round(Math.abs(s.y-t.y)):0,f=Math.max(c.width,Math.round(t.width)),p=Math.max(c.height,Math.round(t.height)),m=(f-c.width)*l[0],h=(p-c.height)*l[1];(u>0||d>0||m||h)&&(i.push({id:o,type:`position`,position:{x:a.position.x-u+m,y:a.position.y-d+h}}),n.get(o)?.forEach(t=>{e.some(e=>e.id===t.id)||i.push({id:t.id,type:`position`,position:{x:t.position.x+u,y:t.position.y+d}})})),(c.width<t.width||c.height<t.height||u||d)&&i.push({id:o,type:`dimensions`,setAttributes:!0,dimensions:{width:f+(u?l[0]*u-m:0),height:p+(d?l[1]*d-h:0)}})}),i}function ol(e,t,n,r,i,a,o){let s=r?.querySelector(`.xyflow__viewport`),c=!1;if(!s)return{changes:[],updatedInternals:c};let l=[],u=window.getComputedStyle(s),{m22:d}=new window.DOMMatrixReadOnly(u.transform),f=[];for(let r of e.values()){let e=t.get(r.id);if(!e)continue;if(e.hidden){t.set(e.id,{...e,internals:{...e.internals,handleBounds:void 0}}),c=!0;continue}let s=hc(r.nodeElement),u=e.measured.width!==s.width||e.measured.height!==s.height;if(s.width&&s.height&&(u||!e.internals.handleBounds||r.force)){let p=r.nodeElement.getBoundingClientRect(),m=sc(e.extent)?e.extent:a,{positionAbsolute:h}=e.internals;e.parentId&&e.extent===`parent`?h=zs(h,s,t.get(e.parentId)):m&&(h=Rs(h,m,s));let g={...e,measured:s,internals:{...e.internals,positionAbsolute:h,handleBounds:{source:xc(`source`,r.nodeElement,p,d,e.id),target:xc(`target`,r.nodeElement,p,d,e.id)}}};t.set(e.id,g),e.parentId&&nl(g,t,n,{nodeOrigin:i,zIndexMode:o}),c=!0,u&&(l.push({id:e.id,type:`dimensions`,dimensions:s}),e.expandParent&&e.parentId&&f.push({id:e.id,parentId:e.parentId,rect:Gs(g,i)}))}}if(f.length>0){let e=al(f,t,n,i);l.push(...e)}return{changes:l,updatedInternals:c}}async function sl({delta:e,panZoom:t,transform:n,translateExtent:r,width:i,height:a}){if(!t||!e.x&&!e.y)return!1;let o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[i,a]],r);return!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2])}function cl(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function ll(e,t,n){e.clear(),t.clear();for(let r of n){let{source:n,target:i,sourceHandle:a=null,targetHandle:o=null}=r,s={edgeId:r.id,source:n,target:i,sourceHandle:a,targetHandle:o},c=`${n}-${a}--${i}-${o}`;cl(`source`,s,`${i}-${o}--${n}-${a}`,e,n,a),cl(`target`,s,c,e,i,o),t.set(r.id,r)}}function ul(e,t){if(!e.parentId)return!1;let n=t.get(e.parentId);return n?n.selected?!0:ul(n,t):!1}function dl(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function fl(e,t,n,r){let i=new Map;for(let[a,o]of e)if((o.selected||o.id===r)&&(!o.parentId||!ul(o,e))&&(o.draggable||t&&o.draggable===void 0)){let t=e.get(a);t&&i.set(a,{id:a,position:t.position||{x:0,y:0},distance:{x:n.x-t.internals.positionAbsolute.x,y:n.y-t.internals.positionAbsolute.y},extent:t.extent,parentId:t.parentId,origin:t.origin,expandParent:t.expandParent,internals:{positionAbsolute:t.internals.positionAbsolute||{x:0,y:0}},measured:{width:t.measured.width??0,height:t.measured.height??0}})}return i}function pl({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){let i=[];for(let[e,a]of t){let t=n.get(e)?.internals.userNode;t&&i.push({...t,position:a.position,dragging:r})}if(!e)return[i[0],i];let a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:i[0],i]}function ml({dragItems:e,snapGrid:t,x:n,y:r}){let i=e.values().next().value;if(!i)return null;let a={x:n-i.distance.x,y:r-i.distance.y},o=$s(a,t);return{x:o.x-a.x,y:o.y-a.y}}function hl({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:i}){let a={x:null,y:null},o=0,s=new Map,c=!1,l={x:0,y:0},u=null,d=!1,f=null,p=!1,m=!1,h=null;function g({noDragClassName:g,handleSelector:_,domNode:v,isSelectable:y,nodeId:b,nodeClickDistance:x=0}){f=Ir(v);function S({x:e,y:n}){let{nodeLookup:i,nodeExtent:o,snapGrid:c,snapToGrid:l,nodeOrigin:u,onNodeDrag:d,onSelectionDrag:f,onError:p,updateNodePositions:g}=t();a={x:e,y:n};let _=!1,v=s.size>1,y=v&&o?Us(As(s)):null,x=v&&l?ml({dragItems:s,snapGrid:c,x:e,y:n}):null;for(let[t,r]of s){if(!i.has(t))continue;let a={x:e-r.distance.x,y:n-r.distance.y};l&&(a=x?{x:Math.round(a.x+x.x),y:Math.round(a.y+x.y)}:$s(a,c));let s=null;if(v&&o&&!r.extent&&y){let{positionAbsolute:e}=r.internals,t=e.x-y.x+o[0][0],n=e.x+r.measured.width-y.x2+o[1][0],i=e.y-y.y+o[0][1],a=e.y+r.measured.height-y.y2+o[1][1];s=[[t,i],[n,a]]}let{position:d,positionAbsolute:f}=Fs({nodeId:t,nextPosition:a,nodeLookup:i,nodeExtent:s||o,nodeOrigin:u,onError:p});_=_||r.position.x!==d.x||r.position.y!==d.y,r.position=d,r.internals.positionAbsolute=f}if(m||=_,_&&(g(s,!0),h&&(r||d||!b&&f))){let[e,t]=pl({nodeId:b,dragItems:s,nodeLookup:i});r?.(h,s,e,t),d?.(h,e,t),b||f?.(h,t)}}async function C(){if(!u)return;let{transform:e,panBy:n,autoPanSpeed:r,autoPanOnNodeDrag:i}=t();if(!i){c=!1,cancelAnimationFrame(o);return}let[s,d]=Vs(l,u,r);(s!==0||d!==0)&&(a.x=(a.x??0)-s/e[2],a.y=(a.y??0)-d/e[2],await n({x:s,y:d})&&S(a)),o=requestAnimationFrame(C)}function w(r){let{nodeLookup:i,multiSelectionActive:o,nodesDraggable:c,transform:l,snapGrid:f,snapToGrid:p,selectNodesOnDrag:m,onNodeDragStart:h,onSelectionDragStart:g,unselectNodesAndEdges:_}=t();d=!0,(!m||!y)&&!o&&b&&(i.get(b)?.selected||_()),y&&m&&b&&e?.(b);let v=mc(r.sourceEvent,{transform:l,snapGrid:f,snapToGrid:p,containerBounds:u});if(a=v,s=fl(i,c,v,b),s.size>0&&(n||h||!b&&g)){let[e,t]=pl({nodeId:b,dragItems:s,nodeLookup:i});n?.(r.sourceEvent,s,e,t),h?.(r.sourceEvent,e,t),b||g?.(r.sourceEvent,t)}}let T=Yr().clickDistance(x).on(`start`,e=>{let{domNode:n,nodeDragThreshold:r,transform:i,snapGrid:o,snapToGrid:s}=t();u=n?.getBoundingClientRect()||null,p=!1,m=!1,h=e.sourceEvent,r===0&&w(e),a=mc(e.sourceEvent,{transform:i,snapGrid:o,snapToGrid:s,containerBounds:u}),l=bc(e.sourceEvent,u)}).on(`drag`,e=>{let{autoPanOnNodeDrag:n,transform:r,snapGrid:i,snapToGrid:o,nodeDragThreshold:f,nodeLookup:m}=t(),g=mc(e.sourceEvent,{transform:r,snapGrid:i,snapToGrid:o,containerBounds:u});if(h=e.sourceEvent,(e.sourceEvent.type===`touchmove`&&e.sourceEvent.touches.length>1||b&&!m.has(b))&&(p=!0),!p){if(!c&&n&&d&&(c=!0,C()),!d){let t=bc(e.sourceEvent,u),n=t.x-l.x,r=t.y-l.y;Math.sqrt(n*n+r*r)>f&&w(e)}(a.x!==g.xSnapped||a.y!==g.ySnapped)&&s&&d&&(l=bc(e.sourceEvent,u),S(g))}}).on(`end`,e=>{if(!d||p){p&&s.size>0&&t().updateNodePositions(s,!1);return}if(c=!1,d=!1,cancelAnimationFrame(o),s.size>0){let{nodeLookup:n,updateNodePositions:r,onNodeDragStop:a,onSelectionDragStop:o}=t();if(m&&=(r(s,!1),!1),i||a||!b&&o){let[t,r]=pl({nodeId:b,dragItems:s,nodeLookup:n,dragging:!1});i?.(e.sourceEvent,s,t,r),a?.(e.sourceEvent,t,r),b||o?.(e.sourceEvent,r)}}}).filter(e=>{let t=e.target;return!e.button&&(!g||!dl(t,`.${g}`,v))&&(!_||dl(t,_,v))});f.call(T)}function _(){f?.on(`.drag`,null)}return{update:g,destroy:_}}function gl(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())Ys(i,Gs(e))>0&&r.push(e);return r}var _l=250;function vl(e,t,n,r){let i=[],a=1/0,o=gl(e,n,t+_l);for(let n of o){let o=[...n.internals.handleBounds?.source??[],...n.internals.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=Hc(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function yl(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===`strict`?o.internals.handleBounds?.[t]:[...o.internals.handleBounds?.source??[],...o.internals.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...Hc(o,c,c.position,!0)}:c}function bl(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function xl(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}var Sl=()=>!0;function Cl(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:a,isTarget:o,domNode:s,nodeLookup:c,lib:l,autoPanOnConnect:u,flowId:d,panBy:f,cancelConnection:p,onConnectStart:m,onConnect:h,onConnectEnd:g,isValidConnection:_=Sl,onReconnectEnd:v,updateConnection:y,getTransform:b,getFromHandle:x,autoPanSpeed:S,dragThreshold:C=1,handleDomNode:w}){let T=gc(e.target),E=0,D,{x:O,y:k}=bc(e),A=bl(a,w),j=s?.getBoundingClientRect(),M=!1;if(!j||!A)return;let N=yl(i,A,r,c,t);if(!N)return;let P=bc(e,j),F=!1,I=null,L=!1,R=null;function z(){if(!u||!j)return;let[e,t]=Vs(P,j,S);f({x:e,y:t}),E=requestAnimationFrame(z)}let B={...N,nodeId:i,type:A,position:N.position},V=c.get(i),H={inProgress:!0,isValid:null,from:Hc(V,B,X.Left,!0),fromHandle:B,fromPosition:B.position,fromNode:V,to:P,toHandle:null,toPosition:Cs[B.position],toNode:null,pointer:P};function U(){M=!0,y(H),m?.(e,{nodeId:i,handleId:r,handleType:A})}C===0&&U();function ee(e){if(!M){let{x:t,y:n}=bc(e),r=t-O,i=n-k;if(!(r*r+i*i>C*C))return;U()}if(!x()||!B){te(e);return}let a=b();P=bc(e,j),D=vl(ec(P,a,!1,[1,1]),n,c,B),F||=(z(),!0);let s=wl(e,{handle:D,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:o?`target`:`source`,isValidConnection:_,doc:T,lib:l,flowId:d,nodeLookup:c});R=s.handleDomNode,I=s.connection,L=xl(!!D,s.isValid);let u=c.get(i),f=u?Hc(u,B,X.Left,!0):H.from,p={...H,from:f,isValid:L,to:s.toHandle&&L?tc({x:s.toHandle.x,y:s.toHandle.y},a):P,toHandle:s.toHandle,toPosition:L&&s.toHandle?s.toHandle.position:Cs[B.position],toNode:s.toHandle?c.get(s.toHandle.nodeId):null,pointer:P};y(p),H=p}function te(e){if(!(`touches`in e&&e.touches.length>0)){if(M){(D||R)&&I&&L&&h?.(I);let{inProgress:t,...n}=H,r={...n,toPosition:H.toHandle?H.toPosition:null};g?.(e,r),a&&v?.(e,r)}p(),cancelAnimationFrame(E),F=!1,L=!1,I=null,R=null,T.removeEventListener(`mousemove`,ee),T.removeEventListener(`mouseup`,te),T.removeEventListener(`touchmove`,ee),T.removeEventListener(`touchend`,te)}}T.addEventListener(`mousemove`,ee),T.addEventListener(`mouseup`,te),T.addEventListener(`touchmove`,ee),T.addEventListener(`touchend`,te)}function wl(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=Sl,nodeLookup:u}){let d=a===`target`,f=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:p,y:m}=bc(e),h=o.elementFromPoint(p,m),g=h?.classList.contains(`${s}-flow__handle`)?h:f,_={handleDomNode:g,isValid:!1,connection:null,toHandle:null};if(g){let e=bl(void 0,g),t=g.getAttribute(`data-nodeid`),a=g.getAttribute(`data-handleid`),o=g.classList.contains(`connectable`),s=g.classList.contains(`connectableend`);if(!t||!e)return _;let c={source:d?t:r,sourceHandle:d?a:i,target:d?r:t,targetHandle:d?i:a};_.connection=c,_.isValid=o&&s&&(n===_s.Strict?d&&e===`source`||!d&&e===`target`:t!==r||a!==i)&&l(c),_.toHandle=yl(t,e,a,u,n,!0)}return _}var Tl={onPointerDown:Cl,isValid:wl};function El({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){let i=Ir(e);function a({translateExtent:e,width:a,height:o,zoomStep:s=1,pannable:c=!0,zoomable:l=!0,inversePan:u=!1}){let d=e=>{if(e.sourceEvent.type!==`wheel`||!t)return;let r=n(),i=e.sourceEvent.ctrlKey&&oc()?10:1,a=-e.sourceEvent.deltaY*(e.sourceEvent.deltaMode===1?.05:e.sourceEvent.deltaMode?1:.002)*s,o=r[2]*2**(a*i);t.scaleTo(o)},f=[0,0],p=fs().on(`start`,e=>{(e.sourceEvent.type===`mousedown`||e.sourceEvent.type===`touchstart`)&&(f=[e.sourceEvent.clientX??e.sourceEvent.touches[0].clientX,e.sourceEvent.clientY??e.sourceEvent.touches[0].clientY])}).on(`zoom`,c?i=>{let s=n();if(i.sourceEvent.type!==`mousemove`&&i.sourceEvent.type!==`touchmove`||!t)return;let c=[i.sourceEvent.clientX??i.sourceEvent.touches[0].clientX,i.sourceEvent.clientY??i.sourceEvent.touches[0].clientY],l=[c[0]-f[0],c[1]-f[1]];f=c;let d=r()*Math.max(s[2],Math.log(s[2]))*(u?-1:1),p={x:s[0]-l[0]*d,y:s[1]-l[1]*d},m=[[0,0],[a,o]];t.setViewportConstrained({x:p.x,y:p.y,zoom:s[2]},m,e)}:null).on(`zoom.wheel`,l?d:null);i.call(p,{})}function o(){i.on(`zoom`,null)}return{update:a,destroy:o,pointer:Bt}}var Dl=e=>({x:e.x,y:e.y,zoom:e.k}),Ol=({x:e,y:t,zoom:n})=>ns.translate(e,t).scale(n),kl=(e,t)=>e.target.closest(`.${t}`),Al=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),jl=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Ml=(e,t=0,n=jl,r=()=>{})=>{let i=typeof t==`number`&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on(`end`,r):e},Nl=e=>{let t=e.ctrlKey&&oc()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Pl({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:a,zoomOnPinch:o,onPanZoomStart:s,onPanZoom:c,onPanZoomEnd:l}){return u=>{if(kl(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();let d=n.property(`__zoom`).k||1;if(u.ctrlKey&&o){let e=Bt(u),t=d*2**Nl(u);r.scaleTo(n,t,e,u);return}let f=u.deltaMode===1?20:1,p=i===vs.Vertical?0:u.deltaX*f,m=i===vs.Horizontal?0:u.deltaY*f;!oc()&&u.shiftKey&&i!==vs.Vertical&&(p=u.deltaY*f,m=0),r.translateBy(n,-(p/d)*a,-(m/d)*a,{internal:!0});let h=Dl(n.property(`__zoom`));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c?.(u,h),e.panScrollTimeout=setTimeout(()=>{l?.(u,h),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,s?.(u,h))}}function Fl({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){let a=r.type===`wheel`,o=!t&&a&&!r.ctrlKey,s=kl(r,e);if(r.ctrlKey&&a&&s&&r.preventDefault(),o||s)return null;r.preventDefault(),n.call(this,r,i)}}function Il({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;let i=Dl(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type===`mousedown`&&t(!0),n&&n?.(r.sourceEvent,i)}}function Ll({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return a=>{e.usedRightMouseButton=!!(n&&Al(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),i&&!a.sourceEvent?.internal&&i?.(a.sourceEvent,Dl(a.transform))}}function Rl({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:a}){return o=>{if(!o.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&Al(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&a(o.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){let t=Dl(o.transform);e.prevViewport=t,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(o.sourceEvent,t)},n?150:0)}}}function zl({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:a,userSelectionActive:o,noWheelClassName:s,noPanClassName:c,lib:l,connectionInProgress:u}){return d=>{let f=e||t,p=n&&d.ctrlKey,m=d.type===`wheel`;if(d.button===1&&d.type===`mousedown`&&(kl(d,`${l}-flow__node`)||kl(d,`${l}-flow__edge`)))return!0;if(!r&&!f&&!i&&!a&&!n||o||u&&!m||kl(d,s)&&m||kl(d,c)&&(!m||i&&m&&!e)||!n&&d.ctrlKey&&m)return!1;if(!n&&d.type===`touchstart`&&d.touches?.length>1)return d.preventDefault(),!1;if(!f&&!i&&!p&&m||!r&&(d.type===`mousedown`||d.type===`touchstart`)||Array.isArray(r)&&!r.includes(d.button)&&d.type===`mousedown`)return!1;let h=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||m)&&h}}function Bl({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:i,onPanZoom:a,onPanZoomStart:o,onPanZoomEnd:s,onDraggingChange:c}){let l={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),d=fs().scaleExtent([t,n]).translateExtent(r),f=Ir(e).call(d);v({x:i.x,y:i.y,zoom:Ls(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);let p=f.on(`wheel.zoom`),m=f.on(`dblclick.zoom`);d.wheelDelta(Nl);async function h(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?Zi:da).transform(Ml(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function g({noWheelClassName:e,noPanClassName:t,onPaneContextMenu:n,userSelectionActive:r,panOnScroll:i,panOnDrag:u,panOnScrollMode:h,panOnScrollSpeed:g,preventScrolling:v,zoomOnPinch:y,zoomOnScroll:b,zoomOnDoubleClick:x,zoomActivationKeyPressed:S,lib:C,onTransformChange:w,connectionInProgress:T,paneClickDistance:E,selectionOnDrag:D}){r&&!l.isZoomingOrPanning&&_();let O=i&&!S&&!r;d.clickDistance(D?1/0:!Zs(E)||E<0?0:E);let k=O?Pl({zoomPanValues:l,noWheelClassName:e,d3Selection:f,d3Zoom:d,panOnScrollMode:h,panOnScrollSpeed:g,zoomOnPinch:y,onPanZoomStart:o,onPanZoom:a,onPanZoomEnd:s}):Fl({noWheelClassName:e,preventScrolling:v,d3ZoomHandler:p});f.on(`wheel.zoom`,k,{passive:!1});let A=Il({zoomPanValues:l,onDraggingChange:c,onPanZoomStart:o});d.on(`start`,A);let j=Ll({zoomPanValues:l,panOnDrag:u,onPaneContextMenu:!!n,onPanZoom:a,onTransformChange:w});d.on(`zoom`,j);let M=Rl({zoomPanValues:l,panOnDrag:u,panOnScroll:i,onPaneContextMenu:n,onPanZoomEnd:s,onDraggingChange:c});d.on(`end`,M);let N=zl({zoomActivationKeyPressed:S,panOnDrag:u,zoomOnScroll:b,panOnScroll:i,zoomOnDoubleClick:x,zoomOnPinch:y,userSelectionActive:r,noPanClassName:t,noWheelClassName:e,lib:C,connectionInProgress:T});d.filter(N),x?f.on(`dblclick.zoom`,m):f.on(`dblclick.zoom`,null)}function _(){d.on(`zoom`,null)}async function v(e,t,n){let r=Ol(e),i=d?.constrain()(r,t,n);return i&&await h(i),i}async function y(e,t){let n=Ol(e);return await h(n,t),n}function b(e){if(f){let t=Ol(e),n=f.property(`__zoom`);(n.k!==e.zoom||n.x!==e.x||n.y!==e.y)&&d?.transform(f,t,null,{sync:!0})}}function x(){let e=f?rs(f.node()):{x:0,y:0,k:1};return{x:e.x,y:e.y,zoom:e.k}}async function S(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?Zi:da).scaleTo(Ml(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}async function C(e,t){return f?new Promise(n=>{d?.interpolate(t?.interpolate===`linear`?Zi:da).scaleBy(Ml(f,t?.duration,t?.ease,()=>n(!0)),e)}):!1}function w(e){d?.scaleExtent(e)}function T(e){d?.translateExtent(e)}function E(e){let t=!Zs(e)||e<0?0:e;d?.clickDistance(t)}return{update:g,destroy:_,setViewport:y,setViewportConstrained:v,getViewport:x,scaleTo:S,scaleBy:C,setScaleExtent:w,setTranslateExtent:T,syncViewport:b,setClickDistance:E}}var Vl;(function(e){e.Line=`line`,e.Handle=`handle`})(Vl||={});function Hl({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:i,affectsY:a}){let o=e-t,s=n-r,c=[o>0?1:o<0?-1:0,s>0?1:s<0?-1:0];return o&&i&&(c[0]*=-1),s&&a&&(c[1]*=-1),c}function Ul(e){return{isHorizontal:e.includes(`right`)||e.includes(`left`),isVertical:e.includes(`bottom`)||e.includes(`top`),affectsX:e.includes(`left`),affectsY:e.includes(`top`)}}function Wl(e,t){return Math.max(0,t-e)}function Gl(e,t){return Math.max(0,e-t)}function Kl(e,t,n){return Math.max(0,t-e,e-n)}function ql(e,t){return e?!t:t}function Jl(e,t,n,r,i,a,o,s){let{affectsX:c,affectsY:l}=t,{isHorizontal:u,isVertical:d}=t,f=u&&d,{xSnapped:p,ySnapped:m}=n,{minWidth:h,maxWidth:g,minHeight:_,maxHeight:v}=r,{x:y,y:b,width:x,height:S,aspectRatio:C}=e,w=Math.floor(u?p-e.pointerX:0),T=Math.floor(d?m-e.pointerY:0),E=x+(c?-w:w),D=S+(l?-T:T),O=-a[0]*x,k=-a[1]*S,A=Kl(E,h,g),j=Kl(D,_,v);if(o){let e=0,t=0;c&&w<0?e=Wl(y+w+O,o[0][0]):!c&&w>0&&(e=Gl(y+E+O,o[1][0])),l&&T<0?t=Wl(b+T+k,o[0][1]):!l&&T>0&&(t=Gl(b+D+k,o[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(s){let e=0,t=0;c&&w>0?e=Gl(y+w,s[0][0]):!c&&w<0&&(e=Wl(y+E,s[1][0])),l&&T>0?t=Gl(b+T,s[0][1]):!l&&T<0&&(t=Wl(b+D,s[1][1])),A=Math.max(A,e),j=Math.max(j,t)}if(i){if(u){let e=Kl(E/C,_,v)*C;if(A=Math.max(A,e),o){let e=0;e=!c&&!l||c&&!l&&f?Gl(b+k+E/C,o[1][1])*C:Wl(b+k+(c?w:-w)/C,o[0][1])*C,A=Math.max(A,e)}if(s){let e=0;e=!c&&!l||c&&!l&&f?Wl(b+E/C,s[1][1])*C:Gl(b+(c?w:-w)/C,s[0][1])*C,A=Math.max(A,e)}}if(d){let e=Kl(D*C,h,g)/C;if(j=Math.max(j,e),o){let e=0;e=!c&&!l||l&&!c&&f?Gl(y+D*C+O,o[1][0])/C:Wl(y+(l?T:-T)*C+O,o[0][0])/C,j=Math.max(j,e)}if(s){let e=0;e=!c&&!l||l&&!c&&f?Wl(y+D*C,s[1][0])/C:Gl(y+(l?T:-T)*C,s[0][0])/C,j=Math.max(j,e)}}}T+=T<0?j:-j,w+=w<0?A:-A,i&&(f?E>D*C?T=(ql(c,l)?-w:w)/C:w=(ql(c,l)?-T:T)*C:u?(T=w/C,l=c):(w=T*C,c=l));let M=c?y+w:y,N=l?b+T:b;return{width:x+(c?-w:w),height:S+(l?-T:T),x:a[0]*w*(c?-1:1)+M,y:a[1]*T*(l?-1:1)+N}}var Yl={width:0,height:0,x:0,y:0},Xl={...Yl,pointerX:0,pointerY:0,aspectRatio:1};function Zl(e,t,n){let r=t.position.x+e.position.x,i=t.position.y+e.position.y,a=e.measured.width??0,o=e.measured.height??0,s=n[0]*a,c=n[1]*o;return[[r-s,i-c],[r+a-s,i+o-c]]}function Ql({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){let a=Ir(e),o={controlDirection:Ul(`bottom-right`),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function s({controlPosition:e,boundaries:s,keepAspectRatio:c,resizeDirection:l,onResizeStart:u,onResize:d,onResizeEnd:f,shouldResize:p}){let m={...Yl},h={...Xl};o={boundaries:s,resizeDirection:l,keepAspectRatio:c,controlDirection:Ul(e)};let g,_=null,v=[],y,b,x,S=!1,C=Yr().on(`start`,e=>{let{nodeLookup:r,transform:i,snapGrid:a,snapToGrid:o,nodeOrigin:s,paneDomNode:c}=n();if(g=r.get(t),!g)return;_=c?.getBoundingClientRect()??null;let{xSnapped:l,ySnapped:d}=mc(e.sourceEvent,{transform:i,snapGrid:a,snapToGrid:o,containerBounds:_});m={width:g.measured.width??0,height:g.measured.height??0,x:g.position.x??0,y:g.position.y??0},h={...m,pointerX:l,pointerY:d,aspectRatio:m.width/m.height},y=void 0,b=sc(g.extent)?g.extent:void 0,g.parentId&&(g.extent===`parent`||g.expandParent)&&(y=r.get(g.parentId)),y&&g.extent===`parent`&&(b=[[0,0],[y.measured.width,y.measured.height]]),v=[],x=void 0;for(let[e,n]of r)if(n.parentId===t&&(v.push({id:e,position:{...n.position},extent:n.extent}),n.extent===`parent`||n.expandParent)){let e=Zl(n,g,n.origin??s);x=x?[[Math.min(e[0][0],x[0][0]),Math.min(e[0][1],x[0][1])],[Math.max(e[1][0],x[1][0]),Math.max(e[1][1],x[1][1])]]:e}u?.(e,{...m})}).on(`drag`,e=>{let{transform:t,snapGrid:i,snapToGrid:a,nodeOrigin:s}=n(),c=mc(e.sourceEvent,{transform:t,snapGrid:i,snapToGrid:a,containerBounds:_}),l=[];if(!g)return;let{x:u,y:f,width:C,height:w}=m,T={},E=g.origin??s,{width:D,height:O,x:k,y:A}=Jl(h,o.controlDirection,c,o.boundaries,o.keepAspectRatio,E,b,x),j=D!==C,M=O!==w,N=k!==u&&j,P=A!==f&&M;if(!N&&!P&&!j&&!M)return;if((N||P||E[0]===1||E[1]===1)&&(T.x=N?k:m.x,T.y=P?A:m.y,m.x=T.x,m.y=T.y,v.length>0)){let e=k-u,t=A-f;for(let n of v)n.position={x:n.position.x-e+E[0]*(D-C),y:n.position.y-t+E[1]*(O-w)},l.push(n)}if((j||M)&&(T.width=j&&(!o.resizeDirection||o.resizeDirection===`horizontal`)?D:m.width,T.height=M&&(!o.resizeDirection||o.resizeDirection===`vertical`)?O:m.height,m.width=T.width,m.height=T.height),y&&g.expandParent){let e=E[0]*(T.width??0);T.x&&T.x<e&&(m.x=e,h.x-=T.x-e);let t=E[1]*(T.height??0);T.y&&T.y<t&&(m.y=t,h.y-=T.y-t)}let F=Hl({width:m.width,prevWidth:C,height:m.height,prevHeight:w,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),I={...m,direction:F};p?.(e,I)!==!1&&(S=!0,d?.(e,I),r(T,l))}).on(`end`,e=>{S&&=(f?.(e,{...m}),i?.({...m}),!1)});a.call(C)}function c(){a.on(`.drag`,null)}return{update:s,destroy:c}}var $l=t((e=>{var t=n();function r(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var i=typeof Object.is==`function`?Object.is:r,a=t.useState,o=t.useEffect,s=t.useLayoutEffect,c=t.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!i(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),eu=t(((e,t)=>{t.exports=$l()})),tu=t((e=>{var t=n(),r=eu();function i(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:i,o=r.useSyncExternalStore,s=t.useRef,c=t.useEffect,l=t.useMemo,u=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),nu=e(t(((e,t)=>{t.exports=tu()}))(),1),ru=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e)),destroy:()=>{n.clear()}},o=t=e(r,i,a);return a},iu=e=>e?ru(e):ru,{useDebugValue:au}=G.default,{useSyncExternalStoreWithSelector:ou}=nu.default,su=e=>e;function cu(e,t=su,n){let r=ou(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return au(r),r}var lu=(e,t)=>{let n=iu(e),r=(e,r=t)=>cu(n,e,r);return Object.assign(r,n),r},uu=(e,t)=>e?lu(e,t):lu;function Z(e,t){if(Object.is(e,t))return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[n,r]of e)if(!Object.is(r,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var du=ue(),fu=(0,G.createContext)(null),pu=fu.Provider,mu=ps.error001(`react`);function Q(e,t){let n=(0,G.useContext)(fu);if(n===null)throw Error(mu);return cu(n,e,t)}function $(){let e=(0,G.useContext)(fu);if(e===null)throw Error(mu);return(0,G.useMemo)(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}var hu={display:`none`},gu={position:`absolute`,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0px, 0px, 0px, 0px)`,clipPath:`inset(100%)`},_u=`react-flow__node-desc`,vu=`react-flow__edge-desc`,yu=`react-flow__aria-live`,bu=e=>e.ariaLiveMessage,xu=e=>e.ariaLabelConfig;function Su({rfId:e}){let t=Q(bu);return(0,K.jsx)(`div`,{id:`${yu}-${e}`,"aria-live":`assertive`,"aria-atomic":`true`,style:gu,children:t})}function Cu({rfId:e,disableKeyboardA11y:t}){let n=Q(xu);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{id:`${_u}-${e}`,style:hu,children:t?n[`node.a11yDescription.default`]:n[`node.a11yDescription.keyboardDisabled`]}),(0,K.jsx)(`div`,{id:`${vu}-${e}`,style:hu,children:n[`edge.a11yDescription.default`]}),!t&&(0,K.jsx)(Su,{rfId:e})]})}var wu=(0,G.forwardRef)(({position:e=`top-left`,children:t,className:n,style:r,...i},a)=>(0,K.jsx)(`div`,{className:J([`react-flow__panel`,n,...`${e}`.split(`-`)]),style:r,ref:a,...i,children:t}));wu.displayName=`Panel`;var Tu=`https://reactflow.dev?utm_source=attribution`;function Eu({proOptions:e,position:t=`bottom-right`}){return e?.hideAttribution?null:(0,K.jsx)(wu,{position:t,className:`react-flow__attribution`,"data-message":`Please only hide this attribution when you are subscribed to React Flow Pro: ${Tu}`,children:(0,K.jsx)(`a`,{href:Tu,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`React Flow attribution`,children:`React Flow`})})}var Du=e=>{let t=[],n=[];for(let[,n]of e.nodeLookup)n.selected&&t.push(n.internals.userNode);for(let[,t]of e.edgeLookup)t.selected&&n.push(t);return{selectedNodes:t,selectedEdges:n}},Ou=e=>e.id;function ku(e,t){return Z(e.selectedNodes.map(Ou),t.selectedNodes.map(Ou))&&Z(e.selectedEdges.map(Ou),t.selectedEdges.map(Ou))}function Au({onSelectionChange:e}){let t=$(),{selectedNodes:n,selectedEdges:r}=Q(Du,ku);return(0,G.useEffect)(()=>{let i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(e=>e(i))},[n,r,e]),null}var ju=e=>!!e.onSelectionChangeHandlers;function Mu({onSelectionChange:e}){let t=Q(ju);return e||t?(0,K.jsx)(Au,{onSelectionChange:e}):null}var Nu=[0,0],Pu={x:0,y:0,zoom:1},Fu=[...`nodes.edges.defaultNodes.defaultEdges.onConnect.onConnectStart.onConnectEnd.onClickConnectStart.onClickConnectEnd.nodesDraggable.autoPanOnNodeFocus.nodesConnectable.nodesFocusable.edgesFocusable.edgesReconnectable.elevateNodesOnSelect.elevateEdgesOnSelect.minZoom.maxZoom.nodeExtent.onNodesChange.onEdgesChange.elementsSelectable.connectionMode.snapGrid.snapToGrid.translateExtent.connectOnClick.defaultEdgeOptions.fitView.fitViewOptions.onNodesDelete.onEdgesDelete.onDelete.onNodeDrag.onNodeDragStart.onNodeDragStop.onSelectionDrag.onSelectionDragStart.onSelectionDragStop.onMoveStart.onMove.onMoveEnd.noPanClassName.nodeOrigin.autoPanOnConnect.autoPanOnNodeDrag.onError.connectionRadius.isValidConnection.selectNodesOnDrag.nodeDragThreshold.connectionDragThreshold.onBeforeDelete.debug.autoPanSpeed.ariaLabelConfig.zIndexMode`.split(`.`),`rfId`],Iu=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),Lu={translateExtent:ms,nodeOrigin:Nu,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:`nopan`,rfId:`1`};function Ru(e){let{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:a,setNodeExtent:o,reset:s,setDefaultNodesAndEdges:c}=Q(Iu,Z),l=$();(0,G.useEffect)(()=>(c(e.defaultNodes,e.defaultEdges),()=>{u.current=Lu,s()}),[]);let u=(0,G.useRef)(Lu);return(0,G.useEffect)(()=>{for(let s of Fu){let c=e[s];c!==u.current[s]&&e[s]!==void 0&&(s===`nodes`?t(c):s===`edges`?n(c):s===`minZoom`?r(c):s===`maxZoom`?i(c):s===`translateExtent`?a(c):s===`nodeExtent`?o(c):s===`ariaLabelConfig`?l.setState({ariaLabelConfig:pc(c)}):s===`fitView`?l.setState({fitViewQueued:c}):s===`fitViewOptions`?l.setState({fitViewOptions:c}):l.setState({[s]:c}))}u.current=e},Fu.map(t=>e[t])),null}function zu(){return typeof window>`u`||!window.matchMedia?null:window.matchMedia(`(prefers-color-scheme: dark)`)}function Bu(e){let[t,n]=(0,G.useState)(e===`system`?null:e);return(0,G.useEffect)(()=>{if(e!==`system`){n(e);return}let t=zu(),r=()=>n(t?.matches?`dark`:`light`);return r(),t?.addEventListener(`change`,r),()=>{t?.removeEventListener(`change`,r)}},[e]),t===null?zu()?.matches?`dark`:`light`:t}var Vu=typeof document<`u`?document:null;function Hu(e=null,t={target:Vu,actInsideInputWithModifier:!0}){let[n,r]=(0,G.useState)(!1),i=(0,G.useRef)(!1),a=(0,G.useRef)(new Set([])),[o,s]=(0,G.useMemo)(()=>{if(e!==null){let t=(Array.isArray(e)?e:[e]).filter(e=>typeof e==`string`).map(e=>e.replace(`+`,`
|
|
2
|
-
`).replace(`
|
|
3
|
-
|
|
4
|
-
`,`
|
|
5
|
-
+`).split(`
|
|
6
|
-
`));return[t,t.reduce((e,t)=>e.concat(...t),[])]}return[[],[]]},[e]);return(0,G.useEffect)(()=>{let n=t?.target??Vu,c=t?.actInsideInputWithModifier??!0;if(e!==null){let e=e=>{if(i.current=e.ctrlKey||e.metaKey||e.shiftKey||e.altKey,(!i.current||i.current&&!c)&&vc(e))return!1;let n=Wu(e.code,s);if(a.current.add(e[n]),Uu(o,a.current,!1)){let n=e.composedPath?.()?.[0]||e.target,a=n?.nodeName===`BUTTON`||n?.nodeName===`A`;t.preventDefault!==!1&&(i.current||!a)&&e.preventDefault(),r(!0)}},l=e=>{let t=Wu(e.code,s);Uu(o,a.current,!0)?(r(!1),a.current.clear()):a.current.delete(e[t]),e.key===`Meta`&&a.current.clear(),i.current=!1},u=()=>{a.current.clear(),r(!1)};return n?.addEventListener(`keydown`,e),n?.addEventListener(`keyup`,l),window.addEventListener(`blur`,u),window.addEventListener(`contextmenu`,u),()=>{n?.removeEventListener(`keydown`,e),n?.removeEventListener(`keyup`,l),window.removeEventListener(`blur`,u),window.removeEventListener(`contextmenu`,u)}}},[e,r]),n}function Uu(e,t,n){return e.filter(e=>n||e.length===t.size).some(e=>e.every(e=>t.has(e)))}function Wu(e,t){return t.includes(e)?`code`:`key`}var Gu=()=>{let e=$();return(0,G.useMemo)(()=>({zoomIn:async t=>{let{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):!1},zoomOut:async t=>{let{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):!1},zoomTo:async(t,n)=>{let{panZoom:r}=e.getState();return r?r.scaleTo(t,n):!1},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{let{transform:[r,i,a],panZoom:o}=e.getState();return o?(await o.setViewport({x:t.x??r,y:t.y??i,zoom:t.zoom??a},n),!0):!1},getViewport:()=>{let[t,n,r]=e.getState().transform;return{x:t,y:n,zoom:r}},setCenter:async(t,n,r)=>e.getState().setCenter(t,n,r),fitBounds:async(t,n)=>{let{width:r,height:i,minZoom:a,maxZoom:o,panZoom:s}=e.getState(),c=ac(t,r,i,a,o,n?.padding??.1);return s?(await s.setViewport(c,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0):!1},screenToFlowPosition:(t,n={})=>{let{transform:r,snapGrid:i,snapToGrid:a,domNode:o}=e.getState();if(!o)return t;let{x:s,y:c}=o.getBoundingClientRect(),l={x:t.x-s,y:t.y-c},u=n.snapGrid??i;return ec(l,r,n.snapToGrid??a,u)},flowToScreenPosition:t=>{let{transform:n,domNode:r}=e.getState();if(!r)return t;let{x:i,y:a}=r.getBoundingClientRect(),o=tc(t,n);return{x:o.x+i,y:o.y+a}}}),[])};function Ku(e,t){let n=[],r=new Map,i=[];for(let t of e)if(t.type===`add`){i.push(t);continue}else if(t.type===`remove`||t.type===`replace`)r.set(t.id,[t]);else{let e=r.get(t.id);e?e.push(t):r.set(t.id,[t])}for(let e of t){let t=r.get(e.id);if(!t){n.push(e);continue}if(t[0].type===`remove`)continue;if(t[0].type===`replace`){n.push({...t[0].item});continue}let i={...e};for(let e of t)qu(e,i);n.push(i)}return i.length&&i.forEach(e=>{e.index===void 0?n.push({...e.item}):n.splice(e.index,0,{...e.item})}),n}function qu(e,t){switch(e.type){case`select`:t.selected=e.selected;break;case`position`:e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case`dimensions`:e.dimensions!==void 0&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes===`width`)&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes===`height`)&&(t.height=e.dimensions.height))),typeof e.resizing==`boolean`&&(t.resizing=e.resizing);break}}function Ju(e,t){return Ku(e,t)}function Yu(e,t){return Ku(e,t)}function Xu(e,t){return{id:e,type:`select`,selected:t}}function Zu(e,t=new Set,n=!1){let r=[];for(let[i,a]of e){let e=t.has(i);!(a.selected===void 0&&!e)&&a.selected!==e&&(n&&(a.selected=e),r.push(Xu(a.id,e)))}return r}function Qu({items:e=[],lookup:t}){let n=[],r=new Map(e.map(e=>[e.id,e]));for(let[r,i]of e.entries()){let e=t.get(i.id),a=e?.internals?.userNode??e;a!==void 0&&a!==i&&n.push({id:i.id,item:i,type:`replace`}),a===void 0&&n.push({item:i,type:`add`,index:r})}for(let[e]of t)r.get(e)===void 0&&n.push({id:e,type:`remove`});return n}function $u(e){return{id:e.id,type:`remove`}}var ed=Qs(`React Flow`,`https://reactflow.dev/`);function td(e,t,n={}){return jc(e,t,{...n,onError:n.onError??ed})}var nd=e=>Es(e),rd=e=>Ts(e);function id(e){return(0,G.forwardRef)(e)}var ad=typeof window<`u`?G.useLayoutEffect:G.useEffect;function od(e){let[t,n]=(0,G.useState)(BigInt(0)),[r]=(0,G.useState)(()=>sd(()=>n(e=>e+BigInt(1))));return ad(()=>{let t=r.get();t.length&&(e(t),r.reset())},[t]),r}function sd(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}var cd=(0,G.createContext)(null);function ld({children:e}){let t=$(),n=od((0,G.useCallback)(e=>{let{nodes:n=[],setNodes:r,hasDefaultNodes:i,onNodesChange:a,nodeLookup:o,fitViewQueued:s,onNodesChangeMiddlewareMap:c}=t.getState(),l=n;for(let t of e)l=typeof t==`function`?t(l):t;let u=Qu({items:l,lookup:o});for(let e of c.values())u=e(u);i&&r(l),u.length>0?a?.(u):s&&window.requestAnimationFrame(()=>{let{fitViewQueued:e,nodes:n,setNodes:r}=t.getState();e&&r(n)})},[])),r=od((0,G.useCallback)(e=>{let{edges:n=[],setEdges:r,hasDefaultEdges:i,onEdgesChange:a,edgeLookup:o}=t.getState(),s=n;for(let t of e)s=typeof t==`function`?t(s):t;i?r(s):a&&a(Qu({items:s,lookup:o}))},[])),i=(0,G.useMemo)(()=>({nodeQueue:n,edgeQueue:r}),[]);return(0,K.jsx)(cd.Provider,{value:i,children:e})}function ud(){let e=(0,G.useContext)(cd);if(!e)throw Error(`useBatchContext must be used within a BatchProvider`);return e}var dd=e=>!!e.panZoom;function fd(){let e=Gu(),t=$(),n=ud(),r=Q(dd),i=(0,G.useMemo)(()=>{let e=e=>t.getState().nodeLookup.get(e),r=e=>{n.nodeQueue.push(e)},i=e=>{n.edgeQueue.push(e)},a=e=>{let{nodeLookup:n,nodeOrigin:r}=t.getState(),i=nd(e)?e:n.get(e.id),a=i.parentId?uc(i.position,i.measured,i.parentId,n,r):i.position;return Gs({...i,position:a,width:i.measured?.width??i.width,height:i.measured?.height??i.height})},o=(e,t,n={replace:!1})=>{r(r=>r.map(r=>{if(r.id===e){let e=typeof t==`function`?t(r):t;return n.replace&&nd(e)?e:{...r,...e}}return r}))},s=(e,t,n={replace:!1})=>{i(r=>r.map(r=>{if(r.id===e){let e=typeof t==`function`?t(r):t;return n.replace&&rd(e)?e:{...r,...e}}return r}))};return{getNodes:()=>t.getState().nodes.map(e=>({...e})),getNode:t=>e(t)?.internals.userNode,getInternalNode:e,getEdges:()=>{let{edges:e=[]}=t.getState();return e.map(e=>({...e}))},getEdge:e=>t.getState().edgeLookup.get(e),setNodes:r,setEdges:i,addNodes:e=>{let t=Array.isArray(e)?e:[e];n.nodeQueue.push(e=>[...e,...t])},addEdges:e=>{let t=Array.isArray(e)?e:[e];n.edgeQueue.push(e=>[...e,...t])},toObject:()=>{let{nodes:e=[],edges:n=[],transform:r}=t.getState(),[i,a,o]=r;return{nodes:e.map(e=>({...e})),edges:n.map(e=>({...e})),viewport:{x:i,y:a,zoom:o}}},deleteElements:async({nodes:e=[],edges:n=[]})=>{let{nodes:r,edges:i,onNodesDelete:a,onEdgesDelete:o,triggerNodeChanges:s,triggerEdgeChanges:c,onDelete:l,onBeforeDelete:u}=t.getState(),{nodes:d,edges:f}=await Is({nodesToRemove:e,edgesToRemove:n,nodes:r,edges:i,onBeforeDelete:u}),p=f.length>0,m=d.length>0;if(p){let e=f.map($u);o?.(f),c(e)}if(m){let e=d.map($u);a?.(d),s(e)}return(m||p)&&l?.({nodes:d,edges:f}),{deletedNodes:d,deletedEdges:f}},getIntersectingNodes:(e,n=!0,r)=>{let i=Xs(e),o=i?e:a(e),s=r!==void 0;return o?(r||t.getState().nodes).filter(r=>{let a=t.getState().nodeLookup.get(r.id);if(a&&!i&&(r.id===e.id||!a.internals.positionAbsolute))return!1;let c=Gs(s?r:a),l=Ys(c,o);return n&&l>0||l>=c.width*c.height||l>=o.width*o.height}):[]},isNodeIntersecting:(e,t,n=!0)=>{let r=Xs(e)?e:a(e);if(!r)return!1;let i=Ys(r,t);return n&&i>0||i>=t.width*t.height||i>=r.width*r.height},updateNode:o,updateNodeData:(e,t,n={replace:!1})=>{o(e,e=>{let r=typeof t==`function`?t(e):t;return n.replace?{...e,data:r}:{...e,data:{...e.data,...r}}},n)},updateEdge:s,updateEdgeData:(e,t,n={replace:!1})=>{s(e,e=>{let r=typeof t==`function`?t(e):t;return n.replace?{...e,data:r}:{...e,data:{...e.data,...r}}},n)},getNodesBounds:e=>{let{nodeLookup:n,nodeOrigin:r}=t.getState();return ks(e,{nodeLookup:n,nodeOrigin:r})},getHandleConnections:({type:e,id:n,nodeId:r})=>Array.from(t.getState().connectionLookup.get(`${r}-${e}${n?`-${n}`:``}`)?.values()??[]),getNodeConnections:({type:e,handleId:n,nodeId:r})=>Array.from(t.getState().connectionLookup.get(`${r}${e?n?`-${e}-${n}`:`-${e}`:``}`)?.values()??[]),fitView:async e=>{let r=t.getState().fitViewResolver??fc();return t.setState({fitViewQueued:!0,fitViewOptions:e,fitViewResolver:r}),n.nodeQueue.push(e=>[...e]),r.promise}}},[]);return(0,G.useMemo)(()=>({...i,...e,viewportInitialized:r}),[r])}var pd=e=>e.selected,md=typeof window<`u`?window:void 0;function hd({deleteKeyCode:e,multiSelectionKeyCode:t}){let n=$(),{deleteElements:r}=fd(),i=Hu(e,{actInsideInputWithModifier:!1}),a=Hu(t,{target:md});(0,G.useEffect)(()=>{if(i){let{edges:e,nodes:t}=n.getState();r({nodes:t.filter(pd),edges:e.filter(pd)}),n.setState({nodesSelectionActive:!1})}},[i]),(0,G.useEffect)(()=>{n.setState({multiSelectionActive:a})},[a])}function gd(e){let t=$();(0,G.useEffect)(()=>{let n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;let n=hc(e.current);(n.height===0||n.width===0)&&t.getState().onError?.(`004`,ps.error004()),t.setState({width:n.width||500,height:n.height||500})};if(e.current){n(),window.addEventListener(`resize`,n);let t=new ResizeObserver(()=>n());return t.observe(e.current),()=>{window.removeEventListener(`resize`,n),t&&e.current&&t.unobserve(e.current)}}},[])}var _d={position:`absolute`,width:`100%`,height:`100%`,top:0,left:0},vd=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function yd({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:a=vs.Free,zoomOnDoubleClick:o=!0,panOnDrag:s=!0,defaultViewport:c,translateExtent:l,minZoom:u,maxZoom:d,zoomActivationKeyCode:f,preventScrolling:p=!0,children:m,noWheelClassName:h,noPanClassName:g,onViewportChange:_,isControlledViewport:v,paneClickDistance:y,selectionOnDrag:b}){let x=$(),S=(0,G.useRef)(null),{userSelectionActive:C,lib:w,connectionInProgress:T}=Q(vd,Z),E=Hu(f),D=(0,G.useRef)();gd(S);let O=(0,G.useCallback)(e=>{_?.({x:e[0],y:e[1],zoom:e[2]}),v||x.setState({transform:e})},[_,v]);return(0,G.useEffect)(()=>{if(S.current){D.current=Bl({domNode:S.current,minZoom:u,maxZoom:d,translateExtent:l,viewport:c,onDraggingChange:e=>x.setState(t=>t.paneDragging===e?t:{paneDragging:e}),onPanZoomStart:(e,t)=>{let{onViewportChangeStart:n,onMoveStart:r}=x.getState();r?.(e,t),n?.(t)},onPanZoom:(e,t)=>{let{onViewportChange:n,onMove:r}=x.getState();r?.(e,t),n?.(t)},onPanZoomEnd:(e,t)=>{let{onViewportChangeEnd:n,onMoveEnd:r}=x.getState();r?.(e,t),n?.(t)}});let{x:e,y:t,zoom:n}=D.current.getViewport();return x.setState({panZoom:D.current,transform:[e,t,n],domNode:S.current.closest(`.react-flow`)}),()=>{D.current?.destroy()}}},[]),(0,G.useEffect)(()=>{D.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:a,zoomOnDoubleClick:o,panOnDrag:s,zoomActivationKeyPressed:E,preventScrolling:p,noPanClassName:g,userSelectionActive:C,noWheelClassName:h,lib:w,onTransformChange:O,connectionInProgress:T,selectionOnDrag:b,paneClickDistance:y})},[e,t,n,r,i,a,o,s,E,p,g,C,h,w,O,T,b,y]),(0,K.jsx)(`div`,{className:`react-flow__renderer`,ref:S,style:_d,children:m})}var bd=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function xd(){let{userSelectionActive:e,userSelectionRect:t}=Q(bd,Z);return e&&t?(0,K.jsx)(`div`,{className:`react-flow__selection react-flow__container`,style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}var Sd=(e,t)=>n=>{n.target===t.current&&e?.(n)},Cd=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function wd({isSelecting:e,selectionKeyPressed:t,selectionMode:n=ys.Full,panOnDrag:r,autoPanOnSelection:i,paneClickDistance:a,selectionOnDrag:o,onSelectionStart:s,onSelectionEnd:c,onPaneClick:l,onPaneContextMenu:u,onPaneScroll:d,onPaneMouseEnter:f,onPaneMouseMove:p,onPaneMouseLeave:m,children:h}){let g=(0,G.useRef)(0),_=$(),{userSelectionActive:v,elementsSelectable:y,dragging:b,panBy:x,autoPanSpeed:S}=Q(Cd,Z),C=y&&(e||v),w=(0,G.useRef)(null),T=(0,G.useRef)(),E=(0,G.useRef)(new Set),D=(0,G.useRef)(new Set),O=(0,G.useRef)(!1),k=(0,G.useRef)(!1),A=(0,G.useRef)({x:0,y:0}),j=(0,G.useRef)(!1),M=e=>{if(k.current||O.current||_.getState().connection.inProgress){k.current=!1,O.current=!1;return}l?.(e),_.getState().resetSelectedElements(),_.setState({nodesSelectionActive:!1})},N=e=>{if(Array.isArray(r)&&r?.includes(2)){e.preventDefault();return}u?.(e)},P=d?e=>d(e):void 0,F=e=>{k.current&&=(e.stopPropagation(),!1)},I=n=>{let{domNode:r,transform:i}=_.getState();if(T.current=r?.getBoundingClientRect(),!T.current)return;let a=n.target===w.current;if(!a&&n.target.closest(`.nokey`)||!e||!(o&&a||t)||n.button!==0||!n.isPrimary)return;n.target?.setPointerCapture?.(n.pointerId),k.current=!1;let{x:s,y:c}=bc(n.nativeEvent,T.current),l=ec({x:s,y:c},i);_.setState({userSelectionRect:{width:0,height:0,startX:l.x,startY:l.y,x:s,y:c}}),a||(n.stopPropagation(),n.preventDefault())};function L(e,t){let{userSelectionRect:r}=_.getState();if(!r)return;let{transform:i,nodeLookup:a,edgeLookup:o,connectionLookup:s,triggerNodeChanges:c,triggerEdgeChanges:l,defaultEdgeOptions:u}=_.getState(),d={x:r.startX,y:r.startY},{x:f,y:p}=tc(d,i),m={startX:d.x,startY:d.y,x:e<f?e:f,y:t<p?t:p,width:Math.abs(e-f),height:Math.abs(t-p)},h=E.current,g=D.current;E.current=new Set(js(a,m,i,n===ys.Partial,!0).map(e=>e.id)),D.current=new Set;let v=u?.selectable??!0;for(let e of E.current){let t=s.get(e);if(t)for(let{edgeId:e}of t.values()){let t=o.get(e);t&&(t.selectable??v)&&D.current.add(e)}}dc(h,E.current)||c(Zu(a,E.current,!0)),dc(g,D.current)||l(Zu(o,D.current)),_.setState({userSelectionRect:m,userSelectionActive:!0,nodesSelectionActive:!1})}function R(){if(!i||!T.current)return;let[e,t]=Vs(A.current,T.current,S);x({x:e,y:t}).then(e=>{if(!k.current||!e){g.current=requestAnimationFrame(R);return}let{x:t,y:n}=A.current;L(t,n),g.current=requestAnimationFrame(R)})}let z=()=>{cancelAnimationFrame(g.current),g.current=0,j.current=!1};return(0,G.useEffect)(()=>()=>z(),[]),(0,K.jsxs)(`div`,{className:J([`react-flow__pane`,{draggable:r===!0||Array.isArray(r)&&r.includes(0),dragging:b,selection:e}]),onClick:C?void 0:Sd(M,w),onContextMenu:Sd(N,w),onWheel:Sd(P,w),onPointerEnter:C?void 0:f,onPointerMove:C?e=>{let{userSelectionRect:n,transform:r,resetSelectedElements:i}=_.getState();if(!T.current||!n)return;let{x:o,y:c}=bc(e.nativeEvent,T.current);A.current={x:o,y:c};let l=tc({x:n.startX,y:n.startY},r);if(!k.current){let n=t?0:a;if(Math.hypot(o-l.x,c-l.y)<=n)return;i(),s?.(e)}k.current=!0,j.current||=(R(),!0),L(o,c)}:p,onPointerUp:e=>{if(!C){e.target===w.current&&_.getState().connection.inProgress&&(O.current=!0);return}e.button===0&&(e.target?.releasePointerCapture?.(e.pointerId),!v&&e.target===w.current&&_.getState().userSelectionRect&&M?.(e),_.setState({userSelectionActive:!1,userSelectionRect:null}),k.current&&(c?.(e),_.setState({nodesSelectionActive:E.current.size>0})),z())},onPointerCancel:C?e=>{e.target?.releasePointerCapture?.(e.pointerId),z()}:void 0,onPointerDownCapture:C?I:void 0,onClickCapture:C?F:void 0,onPointerLeave:m,ref:w,style:_d,children:[h,(0,K.jsx)(xd,{})]})}function Td({id:e,store:t,unselect:n=!1,nodeRef:r}){let{addSelectedNodes:i,unselectNodesAndEdges:a,multiSelectionActive:o,nodeLookup:s,onError:c}=t.getState(),l=s.get(e);if(!l){c?.(`012`,ps.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(a({nodes:[l],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])}function Ed({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:i,isSelectable:a,nodeClickDistance:o}){let s=$(),[c,l]=(0,G.useState)(!1),u=(0,G.useRef)();return(0,G.useEffect)(()=>{u.current=hl({getStoreItems:()=>s.getState(),onNodeMouseDown:t=>{Td({id:t,store:s,nodeRef:e})},onDragStart:()=>{l(!0)},onDragStop:()=>{l(!1)}})},[]),(0,G.useEffect)(()=>{if(!(t||!e.current||!u.current))return u.current.update({noDragClassName:n,handleSelector:r,domNode:e.current,isSelectable:a,nodeId:i,nodeClickDistance:o}),()=>{u.current?.destroy()}},[n,r,t,a,e,i,o]),c}var Dd=e=>t=>t.selected&&(t.draggable||e&&t.draggable===void 0);function Od(){let e=$();return(0,G.useCallback)(t=>{let{nodeExtent:n,snapToGrid:r,snapGrid:i,nodesDraggable:a,onError:o,updateNodePositions:s,nodeLookup:c,nodeOrigin:l}=e.getState(),u=new Map,d=Dd(a),f=r?i[0]:5,p=r?i[1]:5,m=t.direction.x*f*t.factor,h=t.direction.y*p*t.factor;for(let[,e]of c){if(!d(e))continue;let t={x:e.internals.positionAbsolute.x+m,y:e.internals.positionAbsolute.y+h};r&&(t=$s(t,i));let{position:a,positionAbsolute:s}=Fs({nodeId:e.id,nextPosition:t,nodeLookup:c,nodeExtent:n,nodeOrigin:l,onError:o});e.position=a,e.internals.positionAbsolute=s,u.set(e.id,e)}s(u)},[])}var kd=(0,G.createContext)(null),Ad=kd.Provider;kd.Consumer;var jd=()=>(0,G.useContext)(kd),Md=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),Nd=(0,G.createContext)(null);function Pd({children:e}){let t=Q(Md,Z);return(0,K.jsx)(Nd.Provider,{value:t,children:e})}function Fd(){let e=(0,G.useContext)(Nd);if(!e)throw Error(`useHandleConfig must be used within a HandleConfigProvider`);return e}var Id={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},Ld=(e,t,n)=>r=>{let{connectionClickStartHandle:i,connectionMode:a,connection:o}=r,{fromHandle:s,toHandle:c,isValid:l}=o;if(!s&&!i)return Id;let u=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:s?.nodeId===e&&s?.id===t&&s?.type===n,connectingTo:u,clickConnecting:i?.nodeId===e&&i?.id===t&&i?.type===n,isPossibleEndHandle:a===_s.Strict?s?.type!==n:e!==s?.nodeId||t!==s?.id,connectionInProcess:!!s,clickConnectionInProcess:!!i,valid:u&&l}};function Rd({type:e=`source`,position:t=X.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:a=!0,id:o,onConnect:s,children:c,className:l,onMouseDown:u,onTouchStart:d,...f},p){let m=o||null,h=e===`target`,g=$(),_=jd(),{connectOnClick:v,noPanClassName:y,rfId:b}=Fd(),{connectingFrom:x,connectingTo:S,clickConnecting:C,isPossibleEndHandle:w,connectionInProcess:T,clickConnectionInProcess:E,valid:D}=Q(Ld(_,m,e),Z);_||g.getState().onError?.(`010`,ps.error010());let O=e=>{let{defaultEdgeOptions:t,onConnect:n,hasDefaultEdges:r}=g.getState(),i={...t,...e};if(r){let{edges:e,setEdges:t,onError:n}=g.getState();t(td(i,e,{onError:n}))}n?.(i),s?.(i)},k=e=>{if(!_)return;let t=yc(e.nativeEvent);if(i&&(t&&e.button===0||!t)){let t=g.getState();Tl.onPointerDown(e.nativeEvent,{handleDomNode:e.currentTarget,autoPanOnConnect:t.autoPanOnConnect,connectionMode:t.connectionMode,connectionRadius:t.connectionRadius,domNode:t.domNode,nodeLookup:t.nodeLookup,lib:t.lib,isTarget:h,handleId:m,nodeId:_,flowId:t.rfId,panBy:t.panBy,cancelConnection:t.cancelConnection,onConnectStart:t.onConnectStart,onConnectEnd:(...e)=>g.getState().onConnectEnd?.(...e),updateConnection:t.updateConnection,onConnect:O,isValidConnection:n||((...e)=>g.getState().isValidConnection?.(...e)??!0),getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,autoPanSpeed:t.autoPanSpeed,dragThreshold:t.connectionDragThreshold})}t?u?.(e):d?.(e)};return(0,K.jsx)(`div`,{"data-handleid":m,"data-nodeid":_,"data-handlepos":t,"data-id":`${b}-${_}-${m}-${e}`,className:J([`react-flow__handle`,`react-flow__handle-${t}`,`nodrag`,y,l,{source:!h,target:h,connectable:r,connectablestart:i,connectableend:a,clickconnecting:C,connectingfrom:x,connectingto:S,valid:D,connectionindicator:r&&(!T||w)&&(T||E?a:i)}]),onMouseDown:k,onTouchStart:k,onClick:v?t=>{let{onClickConnectStart:r,onClickConnectEnd:a,connectionClickStartHandle:o,connectionMode:s,isValidConnection:c,lib:l,rfId:u,nodeLookup:d,connection:f}=g.getState();if(!_||!o&&!i)return;if(!o){r?.(t.nativeEvent,{nodeId:_,handleId:m,handleType:e}),g.setState({connectionClickStartHandle:{nodeId:_,type:e,id:m}});return}let p=gc(t.target),h=n||c,{connection:v,isValid:y}=Tl.isValid(t.nativeEvent,{handle:{nodeId:_,id:m,type:e},connectionMode:s,fromNodeId:o.nodeId,fromHandleId:o.id||null,fromType:o.type,isValidConnection:h,flowId:u,doc:p,lib:l,nodeLookup:d});y&&v&&O(v);let b=structuredClone(f);delete b.inProgress,b.toPosition=b.toHandle?b.toHandle.position:null,a?.(t,b),g.setState({connectionClickStartHandle:null})}:void 0,ref:p,...f,children:c})}var zd=(0,G.memo)(id(Rd));function Bd({data:e,isConnectable:t,sourcePosition:n=X.Bottom}){return(0,K.jsxs)(K.Fragment,{children:[e?.label,(0,K.jsx)(zd,{type:`source`,position:n,isConnectable:t})]})}function Vd({data:e,isConnectable:t,targetPosition:n=X.Top,sourcePosition:r=X.Bottom}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(zd,{type:`target`,position:n,isConnectable:t}),e?.label,(0,K.jsx)(zd,{type:`source`,position:r,isConnectable:t})]})}function Hd(){return null}function Ud({data:e,isConnectable:t,targetPosition:n=X.Top}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(zd,{type:`target`,position:n,isConnectable:t}),e?.label]})}var Wd={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Gd={input:Bd,default:Vd,output:Ud,group:Hd};function Kd(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}var qd=e=>{let{width:t,height:n,x:r,y:i}=As(e.nodeLookup,{filter:e=>!!e.selected});return{width:Zs(t)?t:null,height:Zs(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${i}px)`}};function Jd({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){let r=$(),{width:i,height:a,transformString:o,userSelectionActive:s}=Q(qd,Z),c=Od(),l=(0,G.useRef)(null);(0,G.useEffect)(()=>{n||l.current?.focus({preventScroll:!0})},[n]);let u=!s&&i!==null&&a!==null;if(Ed({nodeRef:l,disabled:!u}),!u)return null;let d=e?t=>{e(t,r.getState().nodes.filter(e=>e.selected))}:void 0;return(0,K.jsx)(`div`,{className:J([`react-flow__nodesselection`,`react-flow__container`,t]),style:{transform:o},children:(0,K.jsx)(`div`,{ref:l,className:`react-flow__nodesselection-rect`,onContextMenu:d,tabIndex:n?void 0:-1,onKeyDown:n?void 0:e=>{Object.prototype.hasOwnProperty.call(Wd,e.key)&&(e.preventDefault(),c({direction:Wd[e.key],factor:e.shiftKey?4:1}))},style:{width:i,height:a}})})}var Yd=typeof window<`u`?window:void 0,Xd=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Zd({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:a,onPaneScroll:o,paneClickDistance:s,deleteKeyCode:c,selectionKeyCode:l,selectionOnDrag:u,selectionMode:d,onSelectionStart:f,onSelectionEnd:p,multiSelectionKeyCode:m,panActivationKeyCode:h,zoomActivationKeyCode:g,elementsSelectable:_,zoomOnScroll:v,zoomOnPinch:y,panOnScroll:b,panOnScrollSpeed:x,panOnScrollMode:S,zoomOnDoubleClick:C,panOnDrag:w,autoPanOnSelection:T,defaultViewport:E,translateExtent:D,minZoom:O,maxZoom:k,preventScrolling:A,onSelectionContextMenu:j,noWheelClassName:M,noPanClassName:N,disableKeyboardA11y:P,onViewportChange:F,isControlledViewport:I}){let{nodesSelectionActive:L,userSelectionActive:R}=Q(Xd,Z),z=Hu(l,{target:Yd}),B=Hu(h,{target:Yd}),V=B||w,H=B||b,U=u&&V!==!0,ee=z||R||U;return hd({deleteKeyCode:c,multiSelectionKeyCode:m}),(0,K.jsx)(yd,{onPaneContextMenu:a,elementsSelectable:_,zoomOnScroll:v,zoomOnPinch:y,panOnScroll:H,panOnScrollSpeed:x,panOnScrollMode:S,zoomOnDoubleClick:C,panOnDrag:!z&&V,defaultViewport:E,translateExtent:D,minZoom:O,maxZoom:k,zoomActivationKeyCode:g,preventScrolling:A,noWheelClassName:M,noPanClassName:N,onViewportChange:F,isControlledViewport:I,paneClickDistance:s,selectionOnDrag:U,children:(0,K.jsxs)(wd,{onSelectionStart:f,onSelectionEnd:p,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:a,onPaneScroll:o,panOnDrag:V,autoPanOnSelection:T,isSelecting:!!ee,selectionMode:d,selectionKeyPressed:z,paneClickDistance:s,selectionOnDrag:U,children:[e,L&&(0,K.jsx)(Jd,{onSelectionContextMenu:j,noPanClassName:N,disableKeyboardA11y:P})]})})}Zd.displayName=`FlowRenderer`;var Qd=(0,G.memo)(Zd),$d=e=>t=>e?js(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(e=>e.id):Array.from(t.nodeLookup.keys());function ef(e){return Q((0,G.useCallback)($d(e),[e]),Z)}var tf=e=>e.updateNodeInternals;function nf(){let e=Q(tf),[t]=(0,G.useState)(()=>typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{let n=new Map;t.forEach(e=>{let t=e.target.getAttribute(`data-id`);n.set(t,{id:t,nodeElement:e.target,force:!0})}),e(n)}));return(0,G.useEffect)(()=>()=>{t?.disconnect()},[t]),t}function rf({node:e,nodeType:t,hasDimensions:n,resizeObserver:r}){let i=$(),a=(0,G.useRef)(null),o=(0,G.useRef)(null),s=(0,G.useRef)(e.sourcePosition),c=(0,G.useRef)(e.targetPosition),l=(0,G.useRef)(t),u=n&&!!e.internals.handleBounds;return(0,G.useEffect)(()=>{a.current&&!e.hidden&&(!u||o.current!==a.current)&&(o.current&&r?.unobserve(o.current),r?.observe(a.current),o.current=a.current)},[u,e.hidden]),(0,G.useEffect)(()=>()=>{o.current&&=(r?.unobserve(o.current),null)},[]),(0,G.useEffect)(()=>{if(a.current){let n=l.current!==t,r=s.current!==e.sourcePosition,o=c.current!==e.targetPosition;(n||r||o)&&(l.current=t,s.current=e.sourcePosition,c.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:a.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),a}function af({id:e,onClick:t,onMouseEnter:n,onMouseMove:r,onMouseLeave:i,onContextMenu:a,onDoubleClick:o,nodesDraggable:s,elementsSelectable:c,nodesConnectable:l,nodesFocusable:u,resizeObserver:d,noDragClassName:f,noPanClassName:p,disableKeyboardA11y:m,rfId:h,nodeTypes:g,nodeClickDistance:_,onError:v}){let{node:y,internals:b,isParent:x}=Q(t=>{let n=t.nodeLookup.get(e),r=t.parentLookup.has(e);return{node:n,internals:n.internals,isParent:r}},Z),S=y.type||`default`,C=g?.[S]||Gd[S];C===void 0&&(v?.(`003`,ps.error003(S)),S=`default`,C=g?.default||Gd.default);let w=!!(y.draggable||s&&y.draggable===void 0),T=!!(y.selectable||c&&y.selectable===void 0),E=!!(y.connectable||l&&y.connectable===void 0),D=!!(y.focusable||u&&y.focusable===void 0),O=$(),k=lc(y),A=rf({node:y,nodeType:S,hasDimensions:k,resizeObserver:d}),j=Ed({nodeRef:A,disabled:y.hidden||!w,noDragClassName:f,handleSelector:y.dragHandle,nodeId:e,isSelectable:T,nodeClickDistance:_}),M=Od();if(y.hidden)return null;let N=cc(y),P=Kd(y),F=T||w||t||n||r||i,I=n?e=>n(e,{...b.userNode}):void 0,L=r?e=>r(e,{...b.userNode}):void 0,R=i?e=>i(e,{...b.userNode}):void 0,z=a?e=>a(e,{...b.userNode}):void 0,B=o?e=>o(e,{...b.userNode}):void 0,V=n=>{let{selectNodesOnDrag:r,nodeDragThreshold:i}=O.getState();T&&(!r||!w||i>0)&&Td({id:e,store:O,nodeRef:A}),t&&t(n,{...b.userNode})},H=t=>{if(!(vc(t.nativeEvent)||m)){if(hs.includes(t.key)&&T)Td({id:e,store:O,unselect:t.key===`Escape`,nodeRef:A});else if(w&&y.selected&&Object.prototype.hasOwnProperty.call(Wd,t.key)){t.preventDefault();let{ariaLabelConfig:e}=O.getState();O.setState({ariaLiveMessage:e[`node.a11yDescription.ariaLiveMessage`]({direction:t.key.replace(`Arrow`,``).toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),M({direction:Wd[t.key],factor:t.shiftKey?4:1})}}},U=()=>{if(m||!A.current?.matches(`:focus-visible`))return;let{transform:t,width:n,height:r,autoPanOnNodeFocus:i,setCenter:a}=O.getState();i&&(js(new Map([[e,y]]),{x:0,y:0,width:n,height:r},t,!0).length>0||a(y.position.x+N.width/2,y.position.y+N.height/2,{zoom:t[2]}))};return(0,K.jsx)(`div`,{className:J([`react-flow__node`,`react-flow__node-${S}`,{[p]:w},y.className,{selected:y.selected,selectable:T,parent:x,draggable:w,dragging:j}]),ref:A,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:F?`all`:`none`,visibility:k?`visible`:`hidden`,...y.style,...P},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:I,onMouseMove:L,onMouseLeave:R,onContextMenu:z,onClick:V,onDoubleClick:B,onKeyDown:D?H:void 0,tabIndex:D?0:void 0,onFocus:D?U:void 0,role:y.ariaRole??(D?`group`:void 0),"aria-roledescription":`node`,"aria-describedby":m?void 0:`${_u}-${h}`,"aria-label":y.ariaLabel,...y.domAttributes,children:(0,K.jsx)(Ad,{value:e,children:(0,K.jsx)(C,{id:e,data:y.data,type:S,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:y.selected??!1,selectable:T,draggable:w,deletable:y.deletable??!0,isConnectable:E,sourcePosition:y.sourcePosition,targetPosition:y.targetPosition,dragging:j,dragHandle:y.dragHandle,zIndex:b.z,parentId:y.parentId,...N})})})}var of=(0,G.memo)(af),sf=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function cf(e){let{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:i,onError:a}=Q(sf,Z),o=ef(e.onlyRenderVisibleElements),s=nf();return(0,K.jsx)(`div`,{className:`react-flow__nodes`,style:_d,children:o.map(o=>(0,K.jsx)(of,{id:o,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:s,nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:a},o))})}cf.displayName=`NodeRenderer`;var lf=(0,G.memo)(cf);function uf(e){return Q((0,G.useCallback)(t=>{if(!e)return t.edges.map(e=>e.id);let n=[];if(t.width&&t.height)for(let e of t.edges){let r=t.nodeLookup.get(e.source),i=t.nodeLookup.get(e.target);r&&i&&Oc({sourceNode:r,targetNode:i,width:t.width,height:t.height,transform:t.transform})&&n.push(e.id)}return n},[e]),Z)}var df=({color:e=`none`,strokeWidth:t=1})=>(0,K.jsx)(`polyline`,{className:`arrow`,style:{strokeWidth:t,...e&&{stroke:e}},strokeLinecap:`round`,fill:`none`,strokeLinejoin:`round`,points:`-5,-4 0,0 -5,4`}),ff=({color:e=`none`,strokeWidth:t=1})=>(0,K.jsx)(`polyline`,{className:`arrowclosed`,style:{strokeWidth:t,...e&&{stroke:e,fill:e}},strokeLinecap:`round`,strokeLinejoin:`round`,points:`-5,-4 0,0 -5,4 -5,-4`}),pf={[Ss.Arrow]:df,[Ss.ArrowClosed]:ff};function mf(e){let t=$();return(0,G.useMemo)(()=>Object.prototype.hasOwnProperty.call(pf,e)?pf[e]:(t.getState().onError?.(`009`,ps.error009(e)),null),[e])}var hf=({id:e,type:t,color:n,width:r=12.5,height:i=12.5,markerUnits:a=`strokeWidth`,strokeWidth:o,orient:s=`auto-start-reverse`})=>{let c=mf(t);return c?(0,K.jsx)(`marker`,{className:`react-flow__arrowhead`,id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:`-10 -10 20 20`,markerUnits:a,orient:s,refX:`0`,refY:`0`,children:(0,K.jsx)(c,{color:n,strokeWidth:o})}):null},gf=({defaultColor:e,rfId:t})=>{let n=Q(e=>e.edges),r=Q(e=>e.defaultEdgeOptions),i=(0,G.useMemo)(()=>Gc(n,{id:t,defaultColor:e,defaultMarkerStart:r?.markerStart,defaultMarkerEnd:r?.markerEnd}),[n,r,t,e]);return i.length?(0,K.jsx)(`svg`,{className:`react-flow__marker`,"aria-hidden":`true`,children:(0,K.jsx)(`defs`,{children:i.map(e=>(0,K.jsx)(hf,{id:e.id,type:e.type,color:e.color,width:e.width,height:e.height,markerUnits:e.markerUnits,strokeWidth:e.strokeWidth,orient:e.orient},e.id))})}):null};gf.displayName=`MarkerDefinitions`;var _f=(0,G.memo)(gf);function vf({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:a,labelBgPadding:o=[2,4],labelBgBorderRadius:s=2,children:c,className:l,...u}){let[d,f]=(0,G.useState)({x:1,y:0,width:0,height:0}),p=J([`react-flow__edge-textwrapper`,l]),m=(0,G.useRef)(null);return(0,G.useEffect)(()=>{if(m.current){let e=m.current.getBBox();f({x:e.x,y:e.y,width:e.width,height:e.height})}},[n]),n?(0,K.jsxs)(`g`,{transform:`translate(${e-d.width/2} ${t-d.height/2})`,className:p,visibility:d.width?`visible`:`hidden`,...u,children:[i&&(0,K.jsx)(`rect`,{width:d.width+2*o[0],x:-o[0],y:-o[1],height:d.height+2*o[1],className:`react-flow__edge-textbg`,style:a,rx:s,ry:s}),(0,K.jsx)(`text`,{className:`react-flow__edge-text`,y:d.height/2,dy:`0.3em`,ref:m,style:r,children:n}),c]}):null}vf.displayName=`EdgeText`;var yf=(0,G.memo)(vf);function bf({path:e,labelX:t,labelY:n,label:r,labelStyle:i,labelShowBg:a,labelBgStyle:o,labelBgPadding:s,labelBgBorderRadius:c,interactionWidth:l=20,...u}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`path`,{...u,d:e,fill:`none`,className:J([`react-flow__edge-path`,u.className])}),l?(0,K.jsx)(`path`,{d:e,fill:`none`,strokeOpacity:0,strokeWidth:l,className:`react-flow__edge-interaction`}):null,r&&Zs(t)&&Zs(n)?(0,K.jsx)(yf,{x:t,y:n,label:r,labelStyle:i,labelShowBg:a,labelBgStyle:o,labelBgPadding:s,labelBgBorderRadius:c}):null]})}function xf({pos:e,x1:t,y1:n,x2:r,y2:i}){return e===X.Left||e===X.Right?[.5*(t+r),n]:[t,.5*(n+i)]}function Sf({sourceX:e,sourceY:t,sourcePosition:n=X.Bottom,targetX:r,targetY:i,targetPosition:a=X.Top}){let[o,s]=xf({pos:n,x1:e,y1:t,x2:r,y2:i}),[c,l]=xf({pos:a,x1:r,y1:i,x2:e,y2:t}),[u,d,f,p]=Sc({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:o,sourceControlY:s,targetControlX:c,targetControlY:l});return[`M${e},${t} C${o},${s} ${c},${l} ${r},${i}`,u,d,f,p]}function Cf(e){return(0,G.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o,targetPosition:s,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,interactionWidth:_})=>{let[v,y,b]=Sf({sourceX:n,sourceY:r,sourcePosition:o,targetX:i,targetY:a,targetPosition:s});return(0,K.jsx)(bf,{id:e.isInternal?void 0:t,path:v,labelX:y,labelY:b,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,interactionWidth:_})})}var wf=Cf({isInternal:!1}),Tf=Cf({isInternal:!0});wf.displayName=`SimpleBezierEdge`,Tf.displayName=`SimpleBezierEdgeInternal`;function Ef(e){return(0,G.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,sourcePosition:p=X.Bottom,targetPosition:m=X.Top,markerEnd:h,markerStart:g,pathOptions:_,interactionWidth:v})=>{let[y,b,x]=Rc({sourceX:n,sourceY:r,sourcePosition:p,targetX:i,targetY:a,targetPosition:m,borderRadius:_?.borderRadius,offset:_?.offset,stepPosition:_?.stepPosition});return(0,K.jsx)(bf,{id:e.isInternal?void 0:t,path:y,labelX:b,labelY:x,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,markerEnd:h,markerStart:g,interactionWidth:v})})}var Df=Ef({isInternal:!1}),Of=Ef({isInternal:!0});Df.displayName=`SmoothStepEdge`,Of.displayName=`SmoothStepEdgeInternal`;function kf(e){return(0,G.memo)(({id:t,...n})=>{let r=e.isInternal?void 0:t;return(0,K.jsx)(Df,{...n,id:r,pathOptions:(0,G.useMemo)(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}var Af=kf({isInternal:!1}),jf=kf({isInternal:!0});Af.displayName=`StepEdge`,jf.displayName=`StepEdgeInternal`;function Mf(e){return(0,G.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,markerEnd:p,markerStart:m,interactionWidth:h})=>{let[g,_,v]=Mc({sourceX:n,sourceY:r,targetX:i,targetY:a});return(0,K.jsx)(bf,{id:e.isInternal?void 0:t,path:g,labelX:_,labelY:v,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,markerEnd:p,markerStart:m,interactionWidth:h})})}var Nf=Mf({isInternal:!1}),Pf=Mf({isInternal:!0});Nf.displayName=`StraightEdge`,Pf.displayName=`StraightEdgeInternal`;function Ff(e){return(0,G.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o=X.Bottom,targetPosition:s=X.Top,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,pathOptions:_,interactionWidth:v})=>{let[y,b,x]=Tc({sourceX:n,sourceY:r,sourcePosition:o,targetX:i,targetY:a,targetPosition:s,curvature:_?.curvature});return(0,K.jsx)(bf,{id:e.isInternal?void 0:t,path:y,labelX:b,labelY:x,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,interactionWidth:v})})}var If=Ff({isInternal:!1}),Lf=Ff({isInternal:!0});If.displayName=`BezierEdge`,Lf.displayName=`BezierEdgeInternal`;var Rf={default:Lf,straight:Pf,step:jf,smoothstep:Of,simplebezier:Tf},zf={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},Bf=(e,t,n)=>n===X.Left?e-t:n===X.Right?e+t:e,Vf=(e,t,n)=>n===X.Top?e-t:n===X.Bottom?e+t:e,Hf=`react-flow__edgeupdater`;function Uf({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:i,onMouseEnter:a,onMouseOut:o,type:s}){return(0,K.jsx)(`circle`,{onMouseDown:i,onMouseEnter:a,onMouseOut:o,className:J([Hf,`${Hf}-${s}`]),cx:Bf(t,r,e),cy:Vf(n,r,e),r,stroke:`transparent`,fill:`transparent`})}function Wf({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:r,sourceY:i,targetX:a,targetY:o,sourcePosition:s,targetPosition:c,onReconnect:l,onReconnectStart:u,onReconnectEnd:d,setReconnecting:f,setUpdateHover:p}){let m=$(),h=(e,t)=>{if(e.button!==0)return;let{autoPanOnConnect:r,domNode:i,connectionMode:a,connectionRadius:o,lib:s,onConnectStart:c,cancelConnection:p,nodeLookup:h,rfId:g,panBy:_,updateConnection:v}=m.getState(),y=t.type===`target`;Tl.onPointerDown(e.nativeEvent,{autoPanOnConnect:r,connectionMode:a,connectionRadius:o,domNode:i,handleId:t.id,nodeId:t.nodeId,nodeLookup:h,isTarget:y,edgeUpdaterType:t.type,lib:s,flowId:g,cancelConnection:p,panBy:_,isValidConnection:(...e)=>m.getState().isValidConnection?.(...e)??!0,onConnect:e=>l?.(n,e),onConnectStart:(r,i)=>{f(!0),u?.(e,n,t.type),c?.(r,i)},onConnectEnd:(...e)=>m.getState().onConnectEnd?.(...e),onReconnectEnd:(e,r)=>{f(!1),d?.(e,n,t.type,r)},updateConnection:v,getTransform:()=>m.getState().transform,getFromHandle:()=>m.getState().connection.fromHandle,dragThreshold:m.getState().connectionDragThreshold,handleDomNode:e.currentTarget})},g=e=>h(e,{nodeId:n.target,id:n.targetHandle??null,type:`target`}),_=e=>h(e,{nodeId:n.source,id:n.sourceHandle??null,type:`source`}),v=()=>p(!0),y=()=>p(!1);return(0,K.jsxs)(K.Fragment,{children:[(e===!0||e===`source`)&&(0,K.jsx)(Uf,{position:s,centerX:r,centerY:i,radius:t,onMouseDown:g,onMouseEnter:v,onMouseOut:y,type:`source`}),(e===!0||e===`target`)&&(0,K.jsx)(Uf,{position:c,centerX:a,centerY:o,radius:t,onMouseDown:_,onMouseEnter:v,onMouseOut:y,type:`target`})]})}function Gf({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:r,onClick:i,onDoubleClick:a,onContextMenu:o,onMouseEnter:s,onMouseMove:c,onMouseLeave:l,reconnectRadius:u,onReconnect:d,onReconnectStart:f,onReconnectEnd:p,rfId:m,edgeTypes:h,noPanClassName:g,onError:_,disableKeyboardA11y:v}){let y=Q(t=>t.edgeLookup.get(e)),b=Q(e=>e.defaultEdgeOptions);y=b?{...b,...y}:y;let x=y.type||`default`,S=h?.[x]||Rf[x];S===void 0&&(_?.(`011`,ps.error011(x)),x=`default`,S=h?.default||Rf.default);let C=!!(y.focusable||t&&y.focusable===void 0),w=d!==void 0&&(y.reconnectable||n&&y.reconnectable===void 0),T=!!(y.selectable||r&&y.selectable===void 0),E=(0,G.useRef)(null),[D,O]=(0,G.useState)(!1),[k,A]=(0,G.useState)(!1),j=$(),{zIndex:M=y.zIndex,sourceX:N,sourceY:P,targetX:F,targetY:I,sourcePosition:L,targetPosition:R}=Q((0,G.useCallback)(t=>{let n=t.nodeLookup.get(y.source),r=t.nodeLookup.get(y.target);if(!n||!r)return zf;let i=Bc({id:e,sourceNode:n,targetNode:r,sourceHandle:y.sourceHandle||null,targetHandle:y.targetHandle||null,connectionMode:t.connectionMode,onError:_}),a=Dc({selected:y.selected,zIndex:y.zIndex,sourceNode:n,targetNode:r,elevateOnSelect:t.elevateEdgesOnSelect,zIndexMode:t.zIndexMode});return{...i||zf,zIndex:a}},[y.source,y.target,y.sourceHandle,y.targetHandle,y.selected,y.zIndex]),Z),z=(0,G.useMemo)(()=>y.markerStart?`url('#${Wc(y.markerStart,m)}')`:void 0,[y.markerStart,m]),B=(0,G.useMemo)(()=>y.markerEnd?`url('#${Wc(y.markerEnd,m)}')`:void 0,[y.markerEnd,m]);if(y.hidden||N===null||P===null||F===null||I===null)return null;let V=t=>{let{addSelectedEdges:n,unselectNodesAndEdges:r,multiSelectionActive:a}=j.getState();T&&(j.setState({nodesSelectionActive:!1}),y.selected&&a?(r({nodes:[],edges:[y]}),E.current?.blur()):n([e])),i&&i(t,y)},H=a?e=>{a(e,{...y})}:void 0,U=o?e=>{o(e,{...y})}:void 0,ee=s?e=>{s(e,{...y})}:void 0,te=c?e=>{c(e,{...y})}:void 0,W=l?e=>{l(e,{...y})}:void 0;return(0,K.jsx)(`svg`,{style:{zIndex:M},children:(0,K.jsxs)(`g`,{className:J([`react-flow__edge`,`react-flow__edge-${x}`,y.className,g,{selected:y.selected,animated:y.animated,inactive:!T&&!i,updating:D,selectable:T}]),onClick:V,onDoubleClick:H,onContextMenu:U,onMouseEnter:ee,onMouseMove:te,onMouseLeave:W,onKeyDown:C?t=>{if(!v&&hs.includes(t.key)&&T){let{unselectNodesAndEdges:n,addSelectedEdges:r}=j.getState();t.key===`Escape`?(E.current?.blur(),n({edges:[y]})):r([e])}}:void 0,tabIndex:C?0:void 0,role:y.ariaRole??(C?`group`:`img`),"aria-roledescription":`edge`,"data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":y.ariaLabel===null?void 0:y.ariaLabel||`Edge from ${y.source} to ${y.target}`,"aria-describedby":C?`${vu}-${m}`:void 0,ref:E,...y.domAttributes,children:[!k&&(0,K.jsx)(S,{id:e,source:y.source,target:y.target,type:y.type,selected:y.selected,animated:y.animated,selectable:T,deletable:y.deletable??!0,label:y.label,labelStyle:y.labelStyle,labelShowBg:y.labelShowBg,labelBgStyle:y.labelBgStyle,labelBgPadding:y.labelBgPadding,labelBgBorderRadius:y.labelBgBorderRadius,sourceX:N,sourceY:P,targetX:F,targetY:I,sourcePosition:L,targetPosition:R,data:y.data,style:y.style,sourceHandleId:y.sourceHandle,targetHandleId:y.targetHandle,markerStart:z,markerEnd:B,pathOptions:`pathOptions`in y?y.pathOptions:void 0,interactionWidth:y.interactionWidth}),w&&(0,K.jsx)(Wf,{edge:y,isReconnectable:w,reconnectRadius:u,onReconnect:d,onReconnectStart:f,onReconnectEnd:p,sourceX:N,sourceY:P,targetX:F,targetY:I,sourcePosition:L,targetPosition:R,setUpdateHover:O,setReconnecting:A})]})})}var Kf=(0,G.memo)(Gf),qf=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Jf({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:r,noPanClassName:i,onReconnect:a,onEdgeContextMenu:o,onEdgeMouseEnter:s,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,reconnectRadius:d,onEdgeDoubleClick:f,onReconnectStart:p,onReconnectEnd:m,disableKeyboardA11y:h}){let{edgesFocusable:g,edgesReconnectable:_,elementsSelectable:v,onError:y}=Q(qf,Z),b=uf(t);return(0,K.jsxs)(`div`,{className:`react-flow__edges`,children:[(0,K.jsx)(_f,{defaultColor:e,rfId:n}),b.map(e=>(0,K.jsx)(Kf,{id:e,edgesFocusable:g,edgesReconnectable:_,elementsSelectable:v,noPanClassName:i,onReconnect:a,onContextMenu:o,onMouseEnter:s,onMouseMove:c,onMouseLeave:l,onClick:u,reconnectRadius:d,onDoubleClick:f,onReconnectStart:p,onReconnectEnd:m,rfId:n,onError:y,edgeTypes:r,disableKeyboardA11y:h},e))]})}Jf.displayName=`EdgeRenderer`;var Yf=(0,G.memo)(Jf),Xf=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Zf({children:e}){return(0,K.jsx)(`div`,{className:`react-flow__viewport xyflow__viewport react-flow__container`,style:{transform:Q(Xf)},children:e})}function Qf(e){let t=fd(),n=(0,G.useRef)(!1);(0,G.useEffect)(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}var $f=e=>e.panZoom?.syncViewport;function ep(e){let t=Q($f),n=$();return(0,G.useEffect)(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function tp(e){return e.connection.inProgress?{...e.connection,to:ec(e.connection.to,e.transform)}:{...e.connection}}function np(e){return e?t=>e(tp(t)):tp}function rp(e){return Q(np(e),Z)}var ip=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function ap({containerStyle:e,style:t,type:n,component:r}){let{nodesConnectable:i,width:a,height:o,isValid:s,inProgress:c}=Q(ip,Z);return a&&i&&c?(0,K.jsx)(`svg`,{style:e,width:a,height:o,className:`react-flow__connectionline react-flow__container`,children:(0,K.jsx)(`g`,{className:J([`react-flow__connection`,ws(s)]),children:(0,K.jsx)(op,{style:t,type:n,CustomComponent:r,isValid:s})})}):null}var op=({style:e,type:t=xs.Bezier,CustomComponent:n,isValid:r})=>{let{inProgress:i,from:a,fromNode:o,fromHandle:s,fromPosition:c,to:l,toNode:u,toHandle:d,toPosition:f,pointer:p}=rp();if(!i)return;if(n)return(0,K.jsx)(n,{connectionLineType:t,connectionLineStyle:e,fromNode:o,fromHandle:s,fromX:a.x,fromY:a.y,toX:l.x,toY:l.y,fromPosition:c,toPosition:f,connectionStatus:ws(r),toNode:u,toHandle:d,pointer:p});let m=``,h={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:l.x,targetY:l.y,targetPosition:f};switch(t){case xs.Bezier:[m]=Tc(h);break;case xs.SimpleBezier:[m]=Sf(h);break;case xs.Step:[m]=Rc({...h,borderRadius:0});break;case xs.SmoothStep:[m]=Rc(h);break;default:[m]=Mc(h)}return(0,K.jsx)(`path`,{d:m,fill:`none`,className:`react-flow__connection-path`,style:e})};op.displayName=`ConnectionLine`;var sp={};function cp(e=sp){(0,G.useRef)(e),$(),(0,G.useEffect)(()=>{},[e])}function lp(){$(),(0,G.useRef)(!1),(0,G.useEffect)(()=>{},[])}function up({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:a,onEdgeDoubleClick:o,onNodeMouseEnter:s,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,onSelectionContextMenu:d,onSelectionStart:f,onSelectionEnd:p,connectionLineType:m,connectionLineStyle:h,connectionLineComponent:g,connectionLineContainerStyle:_,selectionKeyCode:v,selectionOnDrag:y,selectionMode:b,multiSelectionKeyCode:x,panActivationKeyCode:S,zoomActivationKeyCode:C,deleteKeyCode:w,onlyRenderVisibleElements:T,elementsSelectable:E,defaultViewport:D,translateExtent:O,minZoom:k,maxZoom:A,preventScrolling:j,defaultMarkerColor:M,zoomOnScroll:N,zoomOnPinch:P,panOnScroll:F,panOnScrollSpeed:I,panOnScrollMode:L,zoomOnDoubleClick:R,panOnDrag:z,autoPanOnSelection:B,onPaneClick:V,onPaneMouseEnter:H,onPaneMouseMove:U,onPaneMouseLeave:ee,onPaneScroll:te,onPaneContextMenu:W,paneClickDistance:ne,nodeClickDistance:re,onEdgeContextMenu:ie,onEdgeMouseEnter:ae,onEdgeMouseMove:oe,onEdgeMouseLeave:se,reconnectRadius:ce,onReconnect:le,onReconnectStart:ue,onReconnectEnd:de,noDragClassName:fe,noWheelClassName:pe,noPanClassName:me,disableKeyboardA11y:he,nodeExtent:G,rfId:ge,viewport:_e,onViewportChange:ve}){return cp(e),cp(t),lp(),Qf(n),ep(_e),(0,K.jsx)(Qd,{onPaneClick:V,onPaneMouseEnter:H,onPaneMouseMove:U,onPaneMouseLeave:ee,onPaneContextMenu:W,onPaneScroll:te,paneClickDistance:ne,deleteKeyCode:w,selectionKeyCode:v,selectionOnDrag:y,selectionMode:b,onSelectionStart:f,onSelectionEnd:p,multiSelectionKeyCode:x,panActivationKeyCode:S,zoomActivationKeyCode:C,elementsSelectable:E,zoomOnScroll:N,zoomOnPinch:P,zoomOnDoubleClick:R,panOnScroll:F,panOnScrollSpeed:I,panOnScrollMode:L,panOnDrag:z,autoPanOnSelection:B,defaultViewport:D,translateExtent:O,minZoom:k,maxZoom:A,onSelectionContextMenu:d,preventScrolling:j,noDragClassName:fe,noWheelClassName:pe,noPanClassName:me,disableKeyboardA11y:he,onViewportChange:ve,isControlledViewport:!!_e,children:(0,K.jsxs)(Zf,{children:[(0,K.jsx)(Yf,{edgeTypes:t,onEdgeClick:i,onEdgeDoubleClick:o,onReconnect:le,onReconnectStart:ue,onReconnectEnd:de,onlyRenderVisibleElements:T,onEdgeContextMenu:ie,onEdgeMouseEnter:ae,onEdgeMouseMove:oe,onEdgeMouseLeave:se,reconnectRadius:ce,defaultMarkerColor:M,noPanClassName:me,disableKeyboardA11y:he,rfId:ge}),(0,K.jsx)(ap,{style:h,type:m,component:g,containerStyle:_}),(0,K.jsx)(`div`,{className:`react-flow__edgelabel-renderer`}),(0,K.jsx)(lf,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:a,onNodeMouseEnter:s,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,nodeClickDistance:re,onlyRenderVisibleElements:T,noPanClassName:me,noDragClassName:fe,disableKeyboardA11y:he,nodeExtent:G,rfId:ge}),(0,K.jsx)(`div`,{className:`react-flow__viewport-portal`})]})})}up.displayName=`GraphView`;var dp=(0,G.memo)(up),fp=Qs(`React Flow`,`https://reactflow.dev/`),pp=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c=.5,maxZoom:l=2,nodeOrigin:u,nodeExtent:d,zIndexMode:f=`basic`}={})=>{let p=new Map,m=new Map,h=new Map,g=new Map,_=r??t??[],v=n??e??[],y=u??[0,0],b=d??ms;ll(h,g,_);let{nodesInitialized:x}=el(v,p,m,{nodeOrigin:y,nodeExtent:b,zIndexMode:f}),S=[0,0,1];if(o&&i&&a){let{x:e,y:t,zoom:n}=ac(As(p,{filter:e=>!!((e.width||e.initialWidth)&&(e.height||e.initialHeight))}),i,a,c,l,s?.padding??.1);S=[e,t,n]}return{rfId:`1`,width:i??0,height:a??0,transform:S,nodes:v,nodesInitialized:x,nodeLookup:p,parentLookup:m,edges:_,edgeLookup:g,connectionLookup:h,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:l,translateExtent:ms,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:_s.Strict,domNode:null,paneDragging:!1,noPanClassName:`nopan`,nodeOrigin:y,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:o??!1,fitViewOptions:s,fitViewResolver:null,connection:{...bs},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:``,autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:fp,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:`react`,debug:!1,ariaLabelConfig:gs,zIndexMode:f,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},mp=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:d,zIndexMode:f})=>uu((p,m)=>{async function h(){let{nodeLookup:e,panZoom:t,fitViewOptions:n,fitViewResolver:r,width:i,height:a,minZoom:o,maxZoom:s}=m();t&&(await Ps({nodes:e,width:i,height:a,panZoom:t,minZoom:o,maxZoom:s},n),r?.resolve(!0),p({fitViewResolver:null}))}return{...pp({nodes:e,edges:t,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:d,defaultNodes:n,defaultEdges:r,zIndexMode:f}),setNodes:e=>{let{nodeLookup:t,parentLookup:n,nodeOrigin:r,elevateNodesOnSelect:i,fitViewQueued:a,zIndexMode:o,nodesSelectionActive:s}=m(),{nodesInitialized:c,hasSelectedNodes:l}=el(e,t,n,{nodeOrigin:r,nodeExtent:d,elevateNodesOnSelect:i,checkEquality:!0,zIndexMode:o}),u=s&&l;a&&c?(h(),p({nodes:e,nodesInitialized:c,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:u})):p({nodes:e,nodesInitialized:c,nodesSelectionActive:u})},setEdges:e=>{let{connectionLookup:t,edgeLookup:n}=m();ll(t,n,e),p({edges:e})},setDefaultNodesAndEdges:(e,t)=>{if(e){let{setNodes:t}=m();t(e),p({hasDefaultNodes:!0})}if(t){let{setEdges:e}=m();e(t),p({hasDefaultEdges:!0})}},updateNodeInternals:e=>{let{triggerNodeChanges:t,nodeLookup:n,parentLookup:r,domNode:i,nodeOrigin:a,nodeExtent:o,debug:s,fitViewQueued:c,zIndexMode:l}=m(),{changes:u,updatedInternals:d}=ol(e,n,r,i,a,o,l);d&&(Zc(n,r,{nodeOrigin:a,nodeExtent:o,zIndexMode:l}),c?(h(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),u?.length>0&&(s&&console.log(`React Flow: trigger node changes`,u),t?.(u)))},updateNodePositions:(e,t=!1)=>{let n=[],r=[],{nodeLookup:i,triggerNodeChanges:a,connection:o,updateConnection:s,onNodesChangeMiddlewareMap:c}=m();for(let[a,c]of e){let e=i.get(a),l=!!(e?.expandParent&&e?.parentId&&c?.position),u={id:a,type:`position`,position:l?{x:Math.max(0,c.position.x),y:Math.max(0,c.position.y)}:c.position,dragging:t};if(e&&o.inProgress&&o.fromNode.id===e.id){let t=Hc(e,o.fromHandle,X.Left,!0);s({...o,from:t})}l&&e.parentId&&n.push({id:a,parentId:e.parentId,rect:{...c.internals.positionAbsolute,width:c.measured.width??0,height:c.measured.height??0}}),r.push(u)}if(n.length>0){let{parentLookup:e,nodeOrigin:t}=m(),a=al(n,i,e,t);r.push(...a)}for(let e of c.values())r=e(r);a(r)},triggerNodeChanges:e=>{let{onNodesChange:t,setNodes:n,nodes:r,hasDefaultNodes:i,debug:a}=m();e?.length&&(i&&n(Ju(e,r)),a&&console.log(`React Flow: trigger node changes`,e),t?.(e))},triggerEdgeChanges:e=>{let{onEdgesChange:t,setEdges:n,edges:r,hasDefaultEdges:i,debug:a}=m();e?.length&&(i&&n(Yu(e,r)),a&&console.log(`React Flow: trigger edge changes`,e),t?.(e))},addSelectedNodes:e=>{let{multiSelectionActive:t,edgeLookup:n,nodeLookup:r,triggerNodeChanges:i,triggerEdgeChanges:a}=m();if(t){i(e.map(e=>Xu(e,!0)));return}i(Zu(r,new Set([...e]),!0)),a(Zu(n))},addSelectedEdges:e=>{let{multiSelectionActive:t,edgeLookup:n,nodeLookup:r,triggerNodeChanges:i,triggerEdgeChanges:a}=m();if(t){a(e.map(e=>Xu(e,!0)));return}a(Zu(n,new Set([...e]))),i(Zu(r,new Set,!0))},unselectNodesAndEdges:({nodes:e,edges:t}={})=>{let{edges:n,nodes:r,nodeLookup:i,triggerNodeChanges:a,triggerEdgeChanges:o}=m(),s=e||r,c=t||n,l=[];for(let e of s){if(!e.selected)continue;let t=i.get(e.id);t&&(t.selected=!1),l.push(Xu(e.id,!1))}let u=[];for(let e of c)e.selected&&u.push(Xu(e.id,!1));a(l),o(u)},setMinZoom:e=>{let{panZoom:t,maxZoom:n}=m();t?.setScaleExtent([e,n]),p({minZoom:e})},setMaxZoom:e=>{let{panZoom:t,minZoom:n}=m();t?.setScaleExtent([n,e]),p({maxZoom:e})},setTranslateExtent:e=>{m().panZoom?.setTranslateExtent(e),p({translateExtent:e})},resetSelectedElements:()=>{let{edges:e,nodes:t,triggerNodeChanges:n,triggerEdgeChanges:r,elementsSelectable:i}=m();if(!i)return;let a=t.reduce((e,t)=>t.selected?[...e,Xu(t.id,!1)]:e,[]),o=e.reduce((e,t)=>t.selected?[...e,Xu(t.id,!1)]:e,[]);n(a),r(o)},setNodeExtent:e=>{let{nodes:t,nodeLookup:n,parentLookup:r,nodeOrigin:i,elevateNodesOnSelect:a,nodeExtent:o,zIndexMode:s}=m();e[0][0]===o[0][0]&&e[0][1]===o[0][1]&&e[1][0]===o[1][0]&&e[1][1]===o[1][1]||(el(t,n,r,{nodeOrigin:i,nodeExtent:e,elevateNodesOnSelect:a,checkEquality:!1,zIndexMode:s}),p({nodeExtent:e}))},panBy:e=>{let{transform:t,width:n,height:r,panZoom:i,translateExtent:a}=m();return sl({delta:e,panZoom:i,transform:t,translateExtent:a,width:n,height:r})},setCenter:async(e,t,n)=>{let{width:r,height:i,maxZoom:a,panZoom:o}=m();if(!o)return!1;let s=n?.zoom===void 0?a:n.zoom;return await o.setViewport({x:r/2-e*s,y:i/2-t*s,zoom:s},{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0},cancelConnection:()=>{p({connection:{...bs}})},updateConnection:e=>{p({connection:e})},reset:()=>p({...pp()})}},Object.is);function hp({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:r,initialWidth:i,initialHeight:a,initialMinZoom:o,initialMaxZoom:s,initialFitViewOptions:c,fitView:l,nodeOrigin:u,nodeExtent:d,zIndexMode:f,children:p}){let[m]=(0,G.useState)(()=>mp({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:l,minZoom:o,maxZoom:s,fitViewOptions:c,nodeOrigin:u,nodeExtent:d,zIndexMode:f}));return(0,K.jsx)(pu,{value:m,children:(0,K.jsx)(ld,{children:(0,K.jsx)(Pd,{children:p})})})}function gp({children:e,nodes:t,edges:n,defaultNodes:r,defaultEdges:i,width:a,height:o,fitView:s,fitViewOptions:c,minZoom:l,maxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:p}){return(0,G.useContext)(fu)?(0,K.jsx)(K.Fragment,{children:e}):(0,K.jsx)(hp,{initialNodes:t,initialEdges:n,defaultNodes:r,defaultEdges:i,initialWidth:a,initialHeight:o,fitView:s,initialFitViewOptions:c,initialMinZoom:l,initialMaxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:p,children:e})}var _p={width:`100%`,height:`100%`,overflow:`hidden`,position:`relative`,zIndex:0};function vp({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:i,nodeTypes:a,edgeTypes:o,onNodeClick:s,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:f,onConnect:p,onConnectStart:m,onConnectEnd:h,onClickConnectStart:g,onClickConnectEnd:_,onNodeMouseEnter:v,onNodeMouseMove:y,onNodeMouseLeave:b,onNodeContextMenu:x,onNodeDoubleClick:S,onNodeDragStart:C,onNodeDrag:w,onNodeDragStop:T,onNodesDelete:E,onEdgesDelete:D,onDelete:O,onSelectionChange:k,onSelectionDragStart:A,onSelectionDrag:j,onSelectionDragStop:M,onSelectionContextMenu:N,onSelectionStart:P,onSelectionEnd:F,onBeforeDelete:I,connectionMode:L,connectionLineType:R=xs.Bezier,connectionLineStyle:z,connectionLineComponent:B,connectionLineContainerStyle:V,deleteKeyCode:H=`Backspace`,selectionKeyCode:U=`Shift`,selectionOnDrag:ee=!1,selectionMode:te=ys.Full,panActivationKeyCode:W=`Space`,multiSelectionKeyCode:ne=oc()?`Meta`:`Control`,zoomActivationKeyCode:re=oc()?`Meta`:`Control`,snapToGrid:ie,snapGrid:ae,onlyRenderVisibleElements:oe=!1,selectNodesOnDrag:se,nodesDraggable:ce,autoPanOnNodeFocus:le,nodesConnectable:ue,nodesFocusable:de,nodeOrigin:fe=Nu,edgesFocusable:pe,edgesReconnectable:me,elementsSelectable:he=!0,defaultViewport:ge=Pu,minZoom:_e=.5,maxZoom:ve=2,translateExtent:ye=ms,preventScrolling:be=!0,nodeExtent:xe,defaultMarkerColor:Se=`#b1b1b7`,zoomOnScroll:Ce=!0,zoomOnPinch:we=!0,panOnScroll:Te=!1,panOnScrollSpeed:Ee=.5,panOnScrollMode:De=vs.Free,zoomOnDoubleClick:Oe=!0,panOnDrag:ke=!0,onPaneClick:Ae,onPaneMouseEnter:je,onPaneMouseMove:Me,onPaneMouseLeave:Ne,onPaneScroll:Pe,onPaneContextMenu:Fe,paneClickDistance:Ie=1,nodeClickDistance:Le=0,children:Re,onReconnect:ze,onReconnectStart:Be,onReconnectEnd:Ve,onEdgeContextMenu:He,onEdgeDoubleClick:Ue,onEdgeMouseEnter:We,onEdgeMouseMove:Ge,onEdgeMouseLeave:Ke,reconnectRadius:qe=10,onNodesChange:Je,onEdgesChange:Ye,noDragClassName:Xe=`nodrag`,noWheelClassName:Ze=`nowheel`,noPanClassName:Qe=`nopan`,fitView:$e,fitViewOptions:et,connectOnClick:tt,attributionPosition:nt,proOptions:rt,defaultEdgeOptions:it,elevateNodesOnSelect:at=!0,elevateEdgesOnSelect:q=!1,disableKeyboardA11y:ot=!1,autoPanOnConnect:st,autoPanOnNodeDrag:ct,autoPanOnSelection:lt=!0,autoPanSpeed:ut,connectionRadius:dt,isValidConnection:ft,onError:pt,style:mt,id:ht,nodeDragThreshold:gt,connectionDragThreshold:_t,viewport:vt,onViewportChange:yt,width:bt,height:xt,colorMode:St=`light`,debug:Ct,onScroll:wt,ariaLabelConfig:Tt,zIndexMode:Et=`basic`,...Dt},Ot){let kt=ht||`1`,At=Bu(St),jt=(0,G.useCallback)(e=>{e.currentTarget.scrollTo({top:0,left:0,behavior:`instant`}),wt?.(e)},[wt]);return(0,K.jsx)(`div`,{"data-testid":`rf__wrapper`,...Dt,onScroll:jt,style:{...mt,..._p},ref:Ot,className:J([`react-flow`,i,At]),id:ht,role:`application`,children:(0,K.jsxs)(gp,{nodes:e,edges:t,width:bt,height:xt,fitView:$e,fitViewOptions:et,minZoom:_e,maxZoom:ve,nodeOrigin:fe,nodeExtent:xe,zIndexMode:Et,children:[(0,K.jsx)(Ru,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:p,onConnectStart:m,onConnectEnd:h,onClickConnectStart:g,onClickConnectEnd:_,nodesDraggable:ce,autoPanOnNodeFocus:le,nodesConnectable:ue,nodesFocusable:de,edgesFocusable:pe,edgesReconnectable:me,elementsSelectable:he,elevateNodesOnSelect:at,elevateEdgesOnSelect:q,minZoom:_e,maxZoom:ve,nodeExtent:xe,onNodesChange:Je,onEdgesChange:Ye,snapToGrid:ie,snapGrid:ae,connectionMode:L,translateExtent:ye,connectOnClick:tt,defaultEdgeOptions:it,fitView:$e,fitViewOptions:et,onNodesDelete:E,onEdgesDelete:D,onDelete:O,onNodeDragStart:C,onNodeDrag:w,onNodeDragStop:T,onSelectionDrag:j,onSelectionDragStart:A,onSelectionDragStop:M,onMove:u,onMoveStart:d,onMoveEnd:f,noPanClassName:Qe,nodeOrigin:fe,rfId:kt,autoPanOnConnect:st,autoPanOnNodeDrag:ct,autoPanSpeed:ut,onError:pt,connectionRadius:dt,isValidConnection:ft,selectNodesOnDrag:se,nodeDragThreshold:gt,connectionDragThreshold:_t,onBeforeDelete:I,debug:Ct,ariaLabelConfig:Tt,zIndexMode:Et}),(0,K.jsx)(dp,{onInit:l,onNodeClick:s,onEdgeClick:c,onNodeMouseEnter:v,onNodeMouseMove:y,onNodeMouseLeave:b,onNodeContextMenu:x,onNodeDoubleClick:S,nodeTypes:a,edgeTypes:o,connectionLineType:R,connectionLineStyle:z,connectionLineComponent:B,connectionLineContainerStyle:V,selectionKeyCode:U,selectionOnDrag:ee,selectionMode:te,deleteKeyCode:H,multiSelectionKeyCode:ne,panActivationKeyCode:W,zoomActivationKeyCode:re,onlyRenderVisibleElements:oe,defaultViewport:ge,translateExtent:ye,minZoom:_e,maxZoom:ve,preventScrolling:be,zoomOnScroll:Ce,zoomOnPinch:we,zoomOnDoubleClick:Oe,panOnScroll:Te,panOnScrollSpeed:Ee,panOnScrollMode:De,panOnDrag:ke,autoPanOnSelection:lt,onPaneClick:Ae,onPaneMouseEnter:je,onPaneMouseMove:Me,onPaneMouseLeave:Ne,onPaneScroll:Pe,onPaneContextMenu:Fe,paneClickDistance:Ie,nodeClickDistance:Le,onSelectionContextMenu:N,onSelectionStart:P,onSelectionEnd:F,onReconnect:ze,onReconnectStart:Be,onReconnectEnd:Ve,onEdgeContextMenu:He,onEdgeDoubleClick:Ue,onEdgeMouseEnter:We,onEdgeMouseMove:Ge,onEdgeMouseLeave:Ke,reconnectRadius:qe,defaultMarkerColor:Se,noDragClassName:Xe,noWheelClassName:Ze,noPanClassName:Qe,rfId:kt,disableKeyboardA11y:ot,nodeExtent:xe,viewport:vt,onViewportChange:yt}),(0,K.jsx)(Mu,{onSelectionChange:k}),Re,(0,K.jsx)(Eu,{proOptions:rt,position:nt}),(0,K.jsx)(Cu,{rfId:kt,disableKeyboardA11y:ot})]})})}var yp=id(vp);function bp(e){let[t,n]=(0,G.useState)(e);return[t,n,(0,G.useCallback)(e=>n(t=>Ju(e,t)),[])]}function xp(e){let[t,n]=(0,G.useState)(e);return[t,n,(0,G.useCallback)(e=>n(t=>Yu(e,t)),[])]}ps.error014();function Sp({dimensions:e,lineWidth:t,variant:n,className:r}){return(0,K.jsx)(`path`,{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:J([`react-flow__background-pattern`,n,r])})}function Cp({radius:e,className:t}){return(0,K.jsx)(`circle`,{cx:e,cy:e,r:e,className:J([`react-flow__background-pattern`,`dots`,t])})}var wp;(function(e){e.Lines=`lines`,e.Dots=`dots`,e.Cross=`cross`})(wp||={});var Tp={[wp.Dots]:1,[wp.Lines]:1,[wp.Cross]:6},Ep=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function Dp({id:e,variant:t=wp.Dots,gap:n=20,size:r,lineWidth:i=1,offset:a=0,color:o,bgColor:s,style:c,className:l,patternClassName:u}){let d=(0,G.useRef)(null),{transform:f,patternId:p}=Q(Ep,Z),m=r||Tp[t],h=t===wp.Dots,g=t===wp.Cross,_=Array.isArray(n)?n:[n,n],v=[_[0]*f[2]||1,_[1]*f[2]||1],y=m*f[2],b=Array.isArray(a)?a:[a,a],x=g?[y,y]:v,S=[b[0]*f[2]||1+x[0]/2,b[1]*f[2]||1+x[1]/2],C=`${p}${e||``}`;return(0,K.jsxs)(`svg`,{className:J([`react-flow__background`,l]),style:{...c,..._d,"--xy-background-color-props":s,"--xy-background-pattern-color-props":o},ref:d,"data-testid":`rf__background`,children:[(0,K.jsx)(`pattern`,{id:C,x:f[0]%v[0],y:f[1]%v[1],width:v[0],height:v[1],patternUnits:`userSpaceOnUse`,patternTransform:`translate(-${S[0]},-${S[1]})`,children:h?(0,K.jsx)(Cp,{radius:y/2,className:u}):(0,K.jsx)(Sp,{dimensions:x,lineWidth:i,variant:t,className:u})}),(0,K.jsx)(`rect`,{x:`0`,y:`0`,width:`100%`,height:`100%`,fill:`url(#${C})`})]})}Dp.displayName=`Background`;var Op=(0,G.memo)(Dp);function kp(){return(0,K.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 32`,children:(0,K.jsx)(`path`,{d:`M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z`})})}function Ap(){return(0,K.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 5`,children:(0,K.jsx)(`path`,{d:`M0 0h32v4.2H0z`})})}function jp(){return(0,K.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 30`,children:(0,K.jsx)(`path`,{d:`M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z`})})}function Mp(){return(0,K.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 25 32`,children:(0,K.jsx)(`path`,{d:`M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z`})})}function Np(){return(0,K.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 25 32`,children:(0,K.jsx)(`path`,{d:`M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z`})})}function Pp({children:e,className:t,...n}){return(0,K.jsx)(`button`,{type:`button`,className:J([`react-flow__controls-button`,t]),...n,children:e})}var Fp=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Ip({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:a,onZoomOut:o,onFitView:s,onInteractiveChange:c,className:l,children:u,position:d=`bottom-left`,orientation:f=`vertical`,"aria-label":p}){let m=$(),{isInteractive:h,minZoomReached:g,maxZoomReached:_,ariaLabelConfig:v}=Q(Fp,Z),{zoomIn:y,zoomOut:b,fitView:x}=fd();return(0,K.jsxs)(wu,{className:J([`react-flow__controls`,f===`horizontal`?`horizontal`:`vertical`,l]),position:d,style:e,"data-testid":`rf__controls`,"aria-label":p??v[`controls.ariaLabel`],children:[t&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Pp,{onClick:()=>{y(),a?.()},className:`react-flow__controls-zoomin`,title:v[`controls.zoomIn.ariaLabel`],"aria-label":v[`controls.zoomIn.ariaLabel`],disabled:_,children:(0,K.jsx)(kp,{})}),(0,K.jsx)(Pp,{onClick:()=>{b(),o?.()},className:`react-flow__controls-zoomout`,title:v[`controls.zoomOut.ariaLabel`],"aria-label":v[`controls.zoomOut.ariaLabel`],disabled:g,children:(0,K.jsx)(Ap,{})})]}),n&&(0,K.jsx)(Pp,{className:`react-flow__controls-fitview`,onClick:()=>{x(i),s?.()},title:v[`controls.fitView.ariaLabel`],"aria-label":v[`controls.fitView.ariaLabel`],children:(0,K.jsx)(jp,{})}),r&&(0,K.jsx)(Pp,{className:`react-flow__controls-interactive`,onClick:()=>{m.setState({nodesDraggable:!h,nodesConnectable:!h,elementsSelectable:!h}),c?.(!h)},title:v[`controls.interactive.ariaLabel`],"aria-label":v[`controls.interactive.ariaLabel`],children:h?(0,K.jsx)(Np,{}):(0,K.jsx)(Mp,{})}),u]})}Ip.displayName=`Controls`;var Lp=(0,G.memo)(Ip);function Rp({id:e,x:t,y:n,width:r,height:i,style:a,color:o,strokeColor:s,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,selected:f,onClick:p}){let{background:m,backgroundColor:h}=a||{},g=o||m||h;return(0,K.jsx)(`rect`,{className:J([`react-flow__minimap-node`,{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:i,style:{fill:g,stroke:s,strokeWidth:c},shapeRendering:d,onClick:p?t=>p(t,e):void 0})}var zp=(0,G.memo)(Rp),Bp=e=>e.nodes.map(e=>e.id),Vp=e=>e instanceof Function?e:()=>e;function Hp({nodeStrokeColor:e,nodeColor:t,nodeClassName:n=``,nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:a=zp,onClick:o}){let s=Q(Bp,Z),c=Vp(t),l=Vp(e),u=Vp(n),d=typeof window>`u`||window.chrome?`crispEdges`:`geometricPrecision`;return(0,K.jsx)(K.Fragment,{children:s.map(e=>(0,K.jsx)(Wp,{id:e,nodeColorFunc:c,nodeStrokeColorFunc:l,nodeClassNameFunc:u,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:a,onClick:o,shapeRendering:d},e))})}function Up({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:a,shapeRendering:o,NodeComponent:s,onClick:c}){let{node:l,x:u,y:d,width:f,height:p}=Q(t=>{let n=t.nodeLookup.get(e);if(!n)return{node:void 0,x:0,y:0,width:0,height:0};let r=n.internals.userNode,{x:i,y:a}=n.internals.positionAbsolute,{width:o,height:s}=cc(r);return{node:r,x:i,y:a,width:o,height:s}},Z);return!l||l.hidden||!lc(l)?null:(0,K.jsx)(s,{x:u,y:d,width:f,height:p,style:l.style,selected:!!l.selected,className:r(l),color:t(l),borderRadius:i,strokeColor:n(l),strokeWidth:a,shapeRendering:o,onClick:c,id:l.id})}var Wp=(0,G.memo)(Up),Gp=(0,G.memo)(Hp),Kp=200,qp=150,Jp=e=>!e.hidden,Yp=e=>{let t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?qs(As(e.nodeLookup,{filter:Jp}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},Xp=`react-flow__minimap-desc`;function Zp({style:e,className:t,nodeStrokeColor:n,nodeColor:r,nodeClassName:i=``,nodeBorderRadius:a=5,nodeStrokeWidth:o,nodeComponent:s,bgColor:c,maskColor:l,maskStrokeColor:u,maskStrokeWidth:d,position:f=`bottom-right`,onClick:p,onNodeClick:m,pannable:h=!1,zoomable:g=!1,ariaLabel:_,inversePan:v,zoomStep:y=1,offsetScale:b=5}){let x=$(),S=(0,G.useRef)(null),{boundingRect:C,viewBB:w,rfId:T,panZoom:E,translateExtent:D,flowWidth:O,flowHeight:k,ariaLabelConfig:A}=Q(Yp,Z),j=e?.width??Kp,M=e?.height??qp,N=C.width/j,P=C.height/M,F=Math.max(N,P),I=F*j,L=F*M,R=b*F,z=C.x-(I-C.width)/2-R,B=C.y-(L-C.height)/2-R,V=I+R*2,H=L+R*2,U=`${Xp}-${T}`,ee=(0,G.useRef)(0),te=(0,G.useRef)();ee.current=F,(0,G.useEffect)(()=>{if(S.current&&E)return te.current=El({domNode:S.current,panZoom:E,getTransform:()=>x.getState().transform,getViewScale:()=>ee.current}),()=>{te.current?.destroy()}},[E]),(0,G.useEffect)(()=>{te.current?.update({translateExtent:D,width:O,height:k,inversePan:v,pannable:h,zoomStep:y,zoomable:g})},[h,g,v,y,D,O,k]);let W=p?e=>{let[t,n]=te.current?.pointer(e)||[0,0];p(e,{x:t,y:n})}:void 0,ne=m?(0,G.useCallback)((e,t)=>{let n=x.getState().nodeLookup.get(t).internals.userNode;m(e,n)},[]):void 0,re=_??A[`minimap.ariaLabel`];return(0,K.jsx)(wu,{position:f,style:{...e,"--xy-minimap-background-color-props":typeof c==`string`?c:void 0,"--xy-minimap-mask-background-color-props":typeof l==`string`?l:void 0,"--xy-minimap-mask-stroke-color-props":typeof u==`string`?u:void 0,"--xy-minimap-mask-stroke-width-props":typeof d==`number`?d*F:void 0,"--xy-minimap-node-background-color-props":typeof r==`string`?r:void 0,"--xy-minimap-node-stroke-color-props":typeof n==`string`?n:void 0,"--xy-minimap-node-stroke-width-props":typeof o==`number`?o:void 0},className:J([`react-flow__minimap`,t]),"data-testid":`rf__minimap`,children:(0,K.jsxs)(`svg`,{width:j,height:M,viewBox:`${z} ${B} ${V} ${H}`,className:`react-flow__minimap-svg`,role:`img`,"aria-labelledby":U,ref:S,onClick:W,children:[re&&(0,K.jsx)(`title`,{id:U,children:re}),(0,K.jsx)(Gp,{onClick:ne,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:i,nodeStrokeWidth:o,nodeComponent:s}),(0,K.jsx)(`path`,{className:`react-flow__minimap-mask`,d:`M${z-R},${B-R}h${V+R*2}v${H+R*2}h${-V-R*2}z
|
|
7
|
-
M${w.x},${w.y}h${w.width}v${w.height}h${-w.width}z`,fillRule:`evenodd`,pointerEvents:`none`})]})})}Zp.displayName=`MiniMap`;var Qp=(0,G.memo)(Zp),$p=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,em={[Vl.Line]:`right`,[Vl.Handle]:`bottom-right`};function tm({nodeId:e,position:t,variant:n=Vl.Handle,className:r,style:i=void 0,children:a,color:o,minWidth:s=10,minHeight:c=10,maxWidth:l=Number.MAX_VALUE,maxHeight:u=Number.MAX_VALUE,keepAspectRatio:d=!1,resizeDirection:f,autoScale:p=!0,shouldResize:m,onResizeStart:h,onResize:g,onResizeEnd:_}){let v=jd(),y=typeof e==`string`?e:v,b=$(),x=(0,G.useRef)(null),S=n===Vl.Handle,C=Q((0,G.useCallback)($p(S&&p),[S,p]),Z),w=(0,G.useRef)(null),T=t??em[n];return(0,G.useEffect)(()=>{if(!(!x.current||!y))return w.current||=Ql({domNode:x.current,nodeId:y,getStoreItems:()=>{let{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,domNode:a}=b.getState();return{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,paneDomNode:a}},onChange:(e,t)=>{let{triggerNodeChanges:n,nodeLookup:r,parentLookup:i,nodeOrigin:a}=b.getState(),o=[],s={x:e.x,y:e.y},c=r.get(y);if(c&&c.expandParent&&c.parentId){let t=c.origin??a,n=e.width??c.measured.width??0,l=e.height??c.measured.height??0,u=al([{id:c.id,parentId:c.parentId,rect:{width:n,height:l,...uc({x:e.x??c.position.x,y:e.y??c.position.y},{width:n,height:l},c.parentId,r,t)}}],r,i,a);o.push(...u),s.x=e.x?Math.max(t[0]*n,e.x):void 0,s.y=e.y?Math.max(t[1]*l,e.y):void 0}if(s.x!==void 0&&s.y!==void 0){let e={id:y,type:`position`,position:{...s}};o.push(e)}if(e.width!==void 0&&e.height!==void 0){let t={id:y,type:`dimensions`,resizing:!0,setAttributes:f?f===`horizontal`?`width`:`height`:!0,dimensions:{width:e.width,height:e.height}};o.push(t)}for(let e of t){let t={...e,type:`position`};o.push(t)}n(o)},onEnd:({width:e,height:t})=>{let n={id:y,type:`dimensions`,resizing:!1,dimensions:{width:e,height:t}};b.getState().triggerNodeChanges([n])}}),w.current.update({controlPosition:T,boundaries:{minWidth:s,minHeight:c,maxWidth:l,maxHeight:u},keepAspectRatio:d,resizeDirection:f,onResizeStart:h,onResize:g,onResizeEnd:_,shouldResize:m}),()=>{w.current?.destroy()}},[T,s,c,l,u,d,h,g,_,m]),(0,K.jsx)(`div`,{className:J([`react-flow__resize-control`,`nodrag`,...T.split(`-`),n,r]),ref:x,style:{...i,scale:C,...o&&{[S?`backgroundColor`:`borderColor`]:o}},children:a})}(0,G.memo)(tm);var nm=null,{min:rm,max:im,abs:am,floor:om}=Math,sm=(e,t,n)=>rm(n,im(t,e)),cm=e=>[...e].sort((e,t)=>e-t),lm=typeof queueMicrotask==`function`?queueMicrotask:e=>{Promise.resolve().then(e)},um=()=>{let e;return[new Promise(t=>{e=t}),e]},dm=e=>{let t;return()=>(e&&=(t=e(),void 0),t)},fm=(e,t,n)=>{let r=n?`unshift`:`push`;for(let n=0;n<t;n++)e[r](-1);return e},pm=(e,t)=>{let n=e.t[t];return n===-1?e.o:n},mm=(e,t,n)=>{let r=e.t[t]===-1;return e.t[t]=n,e.i=rm(t,e.i),r},hm=(e,t)=>{if(!e.l)return 0;if(e.i>=t)return e.u[t];e.i<0&&(e.u[0]=0,e.i=0);let n=e.i,r=e.u[n];for(;n<t;)r+=pm(e,n),e.u[++n]=r;return e.i=t,r},gm=(e,t,n=0,r=e.l-1)=>{let i=n;for(;n<=r;){let a=om((n+r)/2);hm(e,a)<=t?(i=a,n=a+1):r=a-1}return sm(i,0,e.l-1)},_m=(e,t,n)=>{let r=t-e.l;return e.i=n?-1:rm(t-1,e.i),e.l=t,r>0?(fm(e.u,r),fm(e.t,r,n),e.o*r):(e.u.splice(r),(n?e.t.splice(0,-r):e.t.splice(r)).reduce((t,n)=>t-(n===-1?e.o:n),0))},vm=typeof window<`u`,ym=e=>e.documentElement,bm=e=>e.ownerDocument,xm=e=>e.defaultView,Sm=dm(()=>!!/iP(hone|od|ad)/.test(navigator.userAgent)||navigator.platform===`MacIntel`&&navigator.maxTouchPoints>0),Cm=dm(()=>`scrollBehavior`in ym(document).style),wm=e=>im(e.h(),e.p()),Tm=(e,t=40,n=0,r,i=!1)=>{let a=!!n,o=1,s=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0,h=nm,g=[0,a?im(n-1,0):-1],_=0,v=!1,y=((e,t,n)=>({o:t,t:n?fm(n.slice(0,rm(e,n.length)),im(0,e-n.length)):fm([],e),l:e,i:-1,u:fm([],e+1)}))(e,r?r[1]:t,r&&r[0]),b=new Set,x=()=>l-c,S=()=>x()+d+u,C=(e,t)=>((e,t,n,r)=>{if(r=rm(r,e.l-1),hm(e,r)<=t){let i=gm(e,n,r);return[gm(e,t,r,i),i]}{let i=gm(e,t,void 0,r);return[i,gm(e,n,i)]}})(y,e,t,g[0]),w=()=>hm(y,y.l),T=(e,t)=>{let n=hm(y,e)-d;return t?w()-n-E(e):n},E=e=>pm(y,e),D=(e,t=-1)=>y.t[e]===t,O=e=>{e&&(Sm()&&p!==0||h&&m===1?d+=e:u+=e)};return{v:()=>{b.clear()},m:()=>o,_:()=>(e=>[e.t.slice(),e.o])(y),S:(e=200)=>{if(!v||a)return g;let t,n;if(f)[t,n]=g;else{let r=im(0,S()),a=r+s;i||(e=im(0,e),p!==1&&(r-=e),p!==2&&(a+=e)),[t,n]=g=C(im(0,r),im(0,a)),h&&(t=rm(t,h[0]),n=im(n,h[1]))}return[im(t,0),rm(n,y.l-1)]},$:e=>gm(y,e-c),I:D,k:T,R:E,T:()=>y.l,C:()=>l,M:()=>p!==0,p:()=>s,O:()=>c,h:w,H:()=>(f=u,u=0,[f,m===2]),W:(e,t)=>{let n=[e,t];return b.add(n),()=>{b.delete(n)}},B:(e,t)=>{let n,r,g=0;switch(e){case 1:{if(t===l&&m===0)break;let e=f;f=0;let n=t-l,i=am(n);e&&i<am(e)+1||m!==0||(p=n<0?2:1),a&&=!1,l=t,g=4;let o=x();o>=-s&&o<=w()&&(g+=1,r=i>s);break}case 2:g=8,p!==0&&(n=!0,g+=1),p=0,m=0,h=nm;break;case 3:{let e=t.filter(([e,t])=>!D(e,t));if(!e.length)break;O(e.reduce((e,[t,n])=>{let r;if(m===2)r=!0;else if(h&&m===1)r=t<h[0];else{let e=x(),n=T(t),i=E(t);r=p!==1&&m===0?n+i<e:n<e&&n+i<e+s}return r&&(e+=n-E(t)),e},0));for(let[t,n]of e){let e=E(t),r=mm(y,t,n);i&&(_+=r?n:n-e)}i&&s&&_>s&&(O(((e,t)=>{let n=0,r=[];e.t.forEach((e,i)=>{e!==-1&&(r.push(e),i<t&&n++)}),e.i=-1;let i=cm(r),a=i.length,o=a/2|0,s=a%2==0?(i[o-1]+i[o])/2:i[o],c=e.o;return((e.o=s)-c)*im(t-n,0)})(y,gm(y,S()))),i=!1),g=3,r=!0;break}case 4:s!==t&&(s||(v=r=!0),s=t,g=3);break;case 5:t[1]?(O(_m(y,t[0],!0)),m=2,g=1):(_m(y,t[0]),g=1);break;case 6:c=t;break;case 7:m=1;break;case 8:h=C(t,t+s),g=1}g&&(o=1+(2147483647&o),n&&d&&(u+=d,d=0),b.forEach(([e,t])=>{g&e&&t(r)}))}}},Em=setTimeout,Dm=(e,t)=>t?-e:e,Om=(e,t,n,r,i,a)=>{let o=Date.now,s=0,c=!1,l=!1,u=!1,d=!1,f=(()=>{let t,n=()=>{t!=nm&&clearTimeout(t)},r=()=>{n(),t=Em(()=>{t=nm,(()=>{if(c||l)return c=!1,void f();u=!1,e.B(2)})()},150)};return r.J=n,r})(),p=()=>{s=o(),u&&(d=!0),a&&e.B(6,a()),e.B(1,r()),f()},m=t=>{if(c||!e.M()||t.ctrlKey)return;let r=o()-s;150>r&&50<r&&(n?t.deltaX:t.deltaY)&&(c=!0)},h=()=>{l=!0,u=d=!1},g=()=>{l=!1,Sm()&&(u=!0)};return t.addEventListener(`scroll`,p),t.addEventListener(`wheel`,m,{passive:!0}),t.addEventListener(`touchstart`,h,{passive:!0}),t.addEventListener(`touchend`,g,{passive:!0}),{A:()=>{t.removeEventListener(`scroll`,p),t.removeEventListener(`wheel`,m),t.removeEventListener(`touchstart`,h),t.removeEventListener(`touchend`,g),f.J()},L:()=>{let[t,n]=e.H();t&&(i(t,n,d),d=!1,n&&e.p()>e.h()&&e.B(1,r()))}}},km=(e,t,n)=>{let r;return[async(i,a)=>{if(!await t())return;r&&r();let o=()=>{let[t,n]=um();return r=()=>{n(!1)},e.p()&&Em(r,150),[t,e.W(2,()=>{n(!0)})]};if(a&&Cm())e.B(8,i()),lm(async()=>{for(;;){let t=!0;for(let[n,r]=e.S();n<=r;n++)if(e.I(n)){t=!1;break}if(t)break;let[n,r]=o();try{if(!await n)return}finally{r()}}e.B(7),n(i(),a)});else for(;;){let[t,r]=o();try{if(e.B(7),n(i()),!await t)return}finally{r()}}},()=>{r&&r()}]},Am=(e,t)=>{let n,r,i=um(),a=!1,o=t?`scrollLeft`:`scrollTop`,s=t?`overflowX`:`overflowY`,[c,l]=km(e,()=>i[0],(e,r)=>{e=Dm(e,a),r?n.scrollTo({[t?`left`:`top`]:e,behavior:`smooth`}):n[o]=e});return{N(c,u){n=u,t&&(a=getComputedStyle(u).direction===`rtl`),r=Om(e,u,t,()=>Dm(u[o],a),(t,n,r)=>{if(r){let e=u.style,t=e[s];e[s]=`hidden`,Em(()=>{e[s]=t})}u[o]=Dm(e.C()+t,a),n&&l()}),i[1](!0)},v(){r&&r.A(),i[1](!1),i=um()},P:()=>a,V(e){c(()=>e)},X(t){t+=e.C(),c(()=>t)},Y(t,{align:n,smooth:r,offset:i=0}={}){if(t=sm(t,0,e.T()-1),n===`nearest`){let r=e.k(t),i=e.C();if(r<i)n=`start`;else{if(!(r+e.R(t)>i+e.p()))return;n=`end`}}c(()=>i+e.O()+e.k(t)+(n===`end`?e.R(t)-e.p():n===`center`?(e.R(t)-e.p())/2:0),r)},q:()=>{r&&r.L()}}},jm=e=>{let t;return{D(n){(t||=new(xm(bm(n))).ResizeObserver(e)).observe(n)},j(e){t.unobserve(e)},A(){t&&t.disconnect()}}},Mm=(e,t)=>{let n,r=t?`width`:`height`,i=new WeakMap,a=jm(t=>{let a=[];for(let{target:o,contentRect:s}of t)if(o.offsetParent)if(o===n)e.B(4,s[r]);else{let e=i.get(o);e!=nm&&a.push([e,s[r]])}a.length&&e.B(3,a)});return{G(e){a.D(n=e)},U:(e,t)=>(i.set(e,t),a.D(e),()=>{i.delete(e),a.j(e)}),v:a.A}},Nm=vm?G.useLayoutEffect:G.useEffect,Pm=`current`,Fm=(e,t)=>{if(Array.isArray(e))for(let n of e)Fm(n,t);else e==null||typeof e==`boolean`||t.push(e)},Im=(e,t)=>e.key??`_`+t,Lm=e=>{let t=(0,G.useRef)(null);return t[Pm]||(t[Pm]=e())},Rm=e=>{let t=(0,G.useRef)(e);return Nm(()=>{t[Pm]=e},[e]),t},zm=(0,G.memo)(({Z:e,ee:t,te:n,oe:r,ne:i,re:a,ie:o,se:s})=>{let c=(0,G.useRef)(null);Nm(()=>t(c[Pm],n),[n]);let l=(0,G.useMemo)(()=>{let e={contain:`layout style`,position:i&&s?void 0:`absolute`,[o?`height`:`width`]:`100%`,[o?`top`:`left`]:0,[o?`left`:`top`]:r,visibility:!i||s?void 0:`hidden`};return o&&(e.display=`inline-flex`),e},[r,i,s,o]);return(0,K.jsx)(a,typeof a==`string`?{ref:c,style:l,children:e}:{ref:c,style:l,index:n,children:e})}),Bm=(e,t)=>(0,G.useMemo)(()=>{if(typeof e==`function`)return[n=>e(t[n],n),t.length];let n=(e=>{let t=[];return Fm(e,t),t})(e);return[e=>n[e],n.length]},[e,t]),Vm=(0,G.forwardRef)(({children:e,data:t,bufferSize:n,itemSize:r,shift:i,horizontal:a,keepMounted:o,cache:s,startMargin:c=0,ssrCount:l,as:u=`div`,item:d=`div`,scrollRef:f,onScroll:p,onScrollEnd:m},h)=>{let[g,_]=Bm(e,t),v=(0,G.useRef)(null),y=(0,G.useRef)(!!l),b=Rm(p),x=Rm(m),[S,C,w,T]=Lm(()=>{let e=!!a,t=Tm(_,r,l,s,!r);return[t,Mm(t,e),Am(t,e),e]});_!==S.T()&&S.B(5,[_,i]),c!==S.O()&&S.B(6,c);let[E,D]=(0,G.useReducer)(S.m,void 0,S.m),O=S.M(),k=S.h(),A=w.P(),j=[],M=e=>{let t=g(e);return(0,K.jsx)(zm,{ee:C.U,te:e,oe:S.k(e,A),ne:S.I(e),re:d,Z:t,ie:T,se:y[Pm]},Im(t,e))};if(Nm(()=>{y[Pm]=!1,S.W(1,e=>{e?(0,du.flushSync)(D):D()}),S.W(4,()=>{b[Pm]&&b[Pm](S.C())}),S.W(8,()=>{x[Pm]&&x[Pm]()});let e=v[Pm],t=t=>{C.G(t),w.N(e,t)};return f?lm(()=>{f[Pm]&&t(f[Pm])}):t(e.parentElement),()=>{S.v(),C.v(),w.v()}},[]),Nm(()=>{w.q()},[E]),(0,G.useImperativeHandle)(h,()=>({get cache(){return S._()},get scrollOffset(){return S.C()},get scrollSize(){return wm(S)},get viewportSize(){return S.p()},findItemIndex:S.$,getItemOffset:S.k,getItemSize:S.R,scrollToIndex:w.Y,scrollTo:w.V,scrollBy:w.X}),[]),o){let e=new Set(o);for(let[t,r]=S.S(n);t<=r;t++)e.add(t);cm([...e]).forEach(e=>{j.push(M(e))})}else for(let[e,t]=S.S(n);e<=t;e++)j.push(M(e));return(0,K.jsx)(u,{ref:v,style:{contain:`size style`,overflowAnchor:`none`,flex:`none`,position:`relative`,width:T?k:`100%`,height:T?`100%`:k,pointerEvents:O?`none`:void 0},children:j})}),Hm=(0,G.forwardRef)(({children:e,data:t,bufferSize:n,itemSize:r,shift:i,horizontal:a,keepMounted:o,cache:s,ssrCount:c,item:l,onScroll:u,onScrollEnd:d,style:f,...p},m)=>(0,K.jsx)(`div`,{...p,style:{display:a?`inline-block`:`block`,[a?`overflowX`:`overflowY`]:`auto`,contain:`strict`,width:`100%`,height:`100%`,...f},children:(0,K.jsx)(Vm,{ref:m,data:t,bufferSize:n,itemSize:r,shift:i,horizontal:a,keepMounted:o,cache:s,ssrCount:c,item:l,onScroll:u,onScrollEnd:d,children:e})}));function Um(){return{entries:[],seen:new Set,consumedBatches:new Set,openTools:new Map,rev:0}}function Wm(e){return(e.role===`tool`||e.role===`error`)&&e.toolUseId!==void 0&&e.toolInput===void 0}function Gm(e){return e.toolUseId!==void 0&&e.toolInput!==void 0?`tu:${e.toolUseId}`:`${e.ts}|${e.role}|${e.tool??``}|${e.text}`}function Km(e,t){let n={...t};if(Wm(n)){let t=n.toolUseId===void 0?void 0:e.openTools.get(n.toolUseId);if(t!==void 0){let r={...e.entries[t]};r.text=n.text||``,n.durationMs!==void 0&&(r.durationMs=n.durationMs),n.isError&&(r.role=`error`,r.isError=!0),e.entries[t]=r;return}}let r=Gm(n);e.seen.has(r)||(e.seen.add(r),n.role===`tool`&&n.toolUseId!==void 0&&n.toolInput!==void 0&&e.openTools.set(n.toolUseId,e.entries.length),e.entries.push(n))}function qm(e,t){let n=Um();n.rev=e.rev+1;for(let e of t)Km(n,e);return n}function Jm(e,t,n){if(n.length===0)return e;let r=t===void 0?`k:${Gm(n[0])}:${n.length}`:`${t}:${n.length}`;if(e.consumedBatches.has(r))return e;let i={entries:[...e.entries],seen:new Set(e.seen),consumedBatches:new Set(e.consumedBatches),openTools:new Map(e.openTools),rev:e.rev+1};i.consumedBatches.add(r);for(let e of n)Km(i,e);return i}function Ym(e){return e.role===`tool`&&e.toolInput!==void 0&&e.text===``&&e.durationMs===void 0&&e.isError!==!0}function Xm(e,t){return`${t}:${e.ts}:${e.role}:${e.toolUseId??``}`}function Zm(e){let t=[],n=e=>(e.role===`assistant`||e.role===`thinking`)&&e.tool===void 0&&e.toolUseId===void 0&&e.isError!==!0;for(let r of e){let e=t[t.length-1];e!==void 0&&n(r)&&n(e)&&e.role===r.role&&(e.agentId??``)===(r.agentId??``)?t[t.length-1]={...e,text:e.text+r.text}:t.push(r)}return t}function Qm(e){let t=e.kind===`thinking`?`thinking`:e.kind===`tool_use`||e.kind===`tool_result`?`tool`:e.kind===`error`?`error`:e.kind===`system`||e.kind===`status`?`system`:`assistant`;return{ts:e.ts,role:t,text:e.content,...e.toolName===void 0?{}:{tool:e.toolName},...e.kind===`error`?{isError:!0}:{},agentId:e.subagentId}}function $m(e,t){let n=Ve([`events`]),r=t!==null&&t!==`leader`,[i,a]=(0,G.useState)(Um),[o,s]=(0,G.useState)(!1),[c,l]=(0,G.useState)(null),[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)({total:0}),m=(0,G.useRef)(null),[h,g]=(0,G.useState)(!0),_=(0,G.useRef)(!0),v=e=>{_.current=e,g(e)},y=(0,G.useRef)(i);y.current=i;let[b,x]=(0,G.useState)([]),[S,C]=(0,G.useState)(!1);(0,G.useEffect)(()=>{if(x([]),t===null||e===null||!r)return;let n=!1;return C(!0),qe(`/api/sessions/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}/messages?full=1`).then(e=>{n||(x((e.entries??[]).map(e=>({...e,agentId:t}))),p(t=>({...t,source:e.source})),C(!1))}).catch(()=>{n||C(!1)}),()=>{n=!0}},[t,e,r]);let w=(0,G.useMemo)(()=>{if(!r||t===null)return[];let i=n.events.filter(t=>t.type===`agent.message`&&(t.sessionId===void 0||t.sessionId===e)).map(e=>e.payload).filter(e=>e.subagentId===t).map(e=>({...Qm(e),agentId:t})),a=new Set,o=[];for(let e of[...b,...i]){let t=`${e.ts}|${e.role}|${e.text}`;a.has(t)||(a.add(t),o.push(e))}return Zm(o)},[b,n.events,t,e,r]);(0,G.useEffect)(()=>{if(e===null||r)return;let t=!1;return s(!0),l(null),_.current=!0,g(!0),qe(`/api/sessions/${encodeURIComponent(e)}/events?${u?`full=1`:`limit=1000`}`).then(e=>{t||(a(t=>qm(t,e.entries)),p({source:e.source,projectName:e.projectName,total:e.total}),s(!1))}).catch(e=>{t||(l(e.message),s(!1))}),()=>{t=!0}},[e,u,r]),(0,G.useEffect)(()=>{a(Um()),p({total:0}),d(!1)},[e,t]),(0,G.useEffect)(()=>{if(e===null||r)return;let t=y.current;for(let r of n.events){if(r.type!==`session.transcript`||r.sessionId!==e)continue;let n=r.payload;Array.isArray(n.entries)&&(t=Jm(t,n.fromSeq,n.entries))}t!==y.current&&a(t)},[n.events,e,r]);let T=(0,G.useMemo)(()=>Zm(i.entries),[i.entries]),E=r?w:T;(0,G.useEffect)(()=>{_.current&&E.length>0&&m.current?.scrollToIndex(E.length-1,{align:`end`})},[E.length,i.rev]);let D=()=>{let e=m.current;e&&v(e.scrollSize-e.scrollOffset-e.viewportSize<80)},O=()=>{v(!0),m.current?.scrollToIndex(E.length-1,{align:`end`})},k=Math.max(0,E.length-8),A=(e,t)=>Ym(e)&&t>=k,j=(0,G.useMemo)(()=>{let e=0,t=0,n=0;for(let r=0;r<E.length;r++){let i=E[r];i.tool!==void 0&&e++,(i.role===`error`||i.isError)&&t++,Ym(i)&&r>=k&&n++}return{turns:E.length,tools:e,errors:t,running:n}},[E,k]);return{entries:E,loading:r?S:o,error:c,meta:f,full:u,setFull:d,stats:j,isRunningAt:A,listRef:m,onScroll:D,pinned:h,jumpToLatest:O}}function eh({text:e,label:t}){let[n,r]=(0,G.useState)(!1);return(0,K.jsxs)(`button`,{type:`button`,className:`hq-copy-btn`,onClick:()=>{navigator.clipboard?.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1200)},()=>{})},title:`Copy to clipboard`,children:[n?(0,K.jsx)(le,{size:12}):(0,K.jsx)(h,{size:12}),t!==void 0&&(0,K.jsx)(`span`,{children:n?`copied`:t})]})}function th(e){return e==null||typeof e==`boolean`?``:typeof e==`string`||typeof e==`number`?String(e):Array.isArray(e)?e.map(th).join(``):(0,G.isValidElement)(e)?th(e.props.children):``}var nh={a:({children:e,href:t})=>(0,K.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,children:e}),table:({children:e})=>(0,K.jsx)(`div`,{className:`hq-md-table-wrap`,children:(0,K.jsx)(`table`,{children:e})}),pre:({children:e})=>{let t=Array.isArray(e)?e[0]:e,n=(0,G.isValidElement)(t)?t.props:void 0,r=/language-(\w+)/.exec(n?.className??``)?.[1],i=th(n?.children).replace(/\n$/,``),a=i===``?0:i.split(`
|
|
8
|
-
`).length;return(0,K.jsxs)(`div`,{className:`hq-md-code`,children:[(0,K.jsxs)(`div`,{className:`hq-md-code-bar`,children:[(0,K.jsx)(`span`,{className:`hq-md-code-lang`,children:r??`text`}),(0,K.jsxs)(`span`,{className:`hq-md-code-meta`,children:[a,` line`,a===1?``:`s`]}),(0,K.jsx)(eh,{text:i})]}),(0,K.jsx)(`pre`,{children:e})]})}},rh=(0,G.memo)(function({text:e}){return(0,K.jsx)(`div`,{className:`hq-md`,children:(0,K.jsx)(me,{remarkPlugins:[he],rehypePlugins:[pe],components:nh,children:e})})}),ih={file:{color:`#60a5fa`},edit:{color:`#fbbf24`},search:{color:`#a78bfa`},folder:{color:`#38bdf8`},terminal:{color:`#67e8f9`},web:{color:`#34d399`},git:{color:`#a3e635`},tree:{color:`#22d3ee`},code:{color:`#818cf8`},test:{color:`#4ade80`},package:{color:`#f472b6`},document:{color:`#94a3b8`},scaffold:{color:`#c084fc`},todo:{color:`#facc15`},plan:{color:`#2dd4bf`},task:{color:`#5eead4`},meta:{color:`#cbd5e1`},index:{color:`#06b6d4`},json:{color:`#eab308`},diff:{color:`#93c5fd`},logs:{color:`#a3a3a3`},settings:{color:`#9ca3af`},brain:{color:`#e879f9`},fallback:{color:`#9ca3af`}},ah={read:`file`,cat:`file`,view:`file`,write:`file`,create:`file`,edit:`edit`,replace:`edit`,str_replace:`edit`,multi_edit:`edit`,patch:`diff`,grep:`search`,search:`search`,rg:`search`,ripgrep:`search`,glob:`search`,find:`search`,folder:`folder`,ls:`folder`,list:`folder`,set_working_dir:`folder`,tree:`tree`,bash:`terminal`,shell:`terminal`,sh:`terminal`,exec:`terminal`,run:`terminal`,command:`terminal`,fetch:`web`,web_fetch:`web`,web_search:`web`,git:`git`,diff:`diff`,lint:`code`,format:`settings`,typecheck:`code`,language_info:`code`,language:`code`,language_package:`package`,test:`test`,install:`package`,outdated:`package`,audit:`package`,document:`document`,scaffold:`scaffold`,todo:`todo`,plan:`plan`,task:`task`,json:`json`,index:`index`,logs:`logs`,mode:`meta`,tool_search:`meta`,tool_use:`meta`,batch_tool_use:`meta`,tool_help:`meta`,remember:`brain`,forget:`brain`,search_memory:`brain`,find_related_memories:`brain`,memory_for_file:`brain`,memory_for_path:`brain`,memory_search:`brain`,memory_graph:`brain`,memory_verify:`brain`,memory_hygiene:`brain`,memory_candidates:`brain`};function oh(e){return e?ah[e.toLowerCase()]??`fallback`:`fallback`}var sh={file:z,edit:te,search:ne,folder:s,terminal:A,web:se,git:oe,tree:S,code:D,test:_,package:B,document:M,scaffold:j,todo:ee,plan:g,task:I,meta:W,index:R,json:f,diff:a,logs:ae,settings:U,brain:i,fallback:W};function ch(e){let t=oh(e??``);return{Icon:sh[t],color:ih[t].color}}var lh=[`path`,`file_path`,`pattern`,`command`,`cmd`,`url`,`query`,`description`,`content`];function uh(e,t){return e.length>t?`${e.slice(0,t-1)}\u2026`:e}function dh(e){let t=e.file_path??e.path??e.filepath;return typeof t==`string`?t:``}function fh(e){try{return JSON.stringify(e)}catch{return String(e)}}function ph(e){if(typeof e==`string`){let t=e.trim();if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(e&&typeof e==`object`)return{obj:e,raw:e}}catch{}return{obj:null,raw:e}}return e&&typeof e==`object`?{obj:e,raw:e}:{obj:null,raw:e}}function mh(e,t){if(t==null||t===``)return``;let{obj:n,raw:r}=ph(t);if(!n)return uh(String(r),120);let i=(e??``).toLowerCase();if(/^todo(_?write)?$|^todos$/.test(i)||Array.isArray(n.todos)){let e=n.todos??[];if(Array.isArray(e)){let t=e.filter(e=>e?.status===`completed`).length,n=e.filter(e=>e?.status===`in_progress`).length,r=[`${e.length} todo${e.length===1?``:`s`}`];return t>0&&r.push(`${t} done`),n>0&&r.push(`${n} in-progress`),r.join(` · `)}}if(/batch|parallel/.test(i)||Array.isArray(n.tool_uses)||Array.isArray(n.calls)){let e=n.tool_uses??n.calls??n.batch;if(Array.isArray(e)){let t=new Set;for(let n of e)n&&typeof n==`object`&&`name`in n?t.add(String(n.name)):n&&typeof n==`object`&&`tool`in n&&t.add(String(n.tool));let n=[...t].slice(0,3).join(`, `),r=t.size>3?` +${t.size-3}`:``;return`${e.length} sub-tool${e.length===1?``:`s`}${n?` \xB7 ${n}${r}`:``}`}}if(/^(edit|str_replace|edit_file|patch)$/.test(i)){let e=dh(n),t=typeof n.old_string==`string`?n.old_string:``,r=typeof n.new_string==`string`?n.new_string:``,i=t?t.split(`
|
|
9
|
-
`).length:0,a=r?r.split(`
|
|
10
|
-
`).length:0;return`edit ${e||`(file)`}${i||a?` (${i} \u2192 ${a} lines)`:``}`}if(/^(write|write_file|create_file|new_file)$/.test(i)){let e=dh(n),t=typeof n.content==`string`?n.content:``,r=t?t.split(`
|
|
11
|
-
`).length:0;return`write ${e||`(file)`}${r?` \xB7 ${r} lines`:``}`}if(/^(bash|shell|sh|exec|run|run_command|run_shell|command)$/.test(i)){let e=n.command??n.cmd??n.script;if(typeof e==`string`)return`$ ${uh(e,110)}`}if(/^(fetch|http|web|web_fetch|web_search|webfetch|curl|request)$/.test(i)){let e=n.url;if(typeof e==`string`)return`${(n.method??`GET`).toUpperCase()} ${uh(e,100)}`}if(/^(grep|search|ripgrep|rg)$/.test(i)){let e=n.pattern,t=n.path??n.glob??n.type;if(typeof e==`string`)return t?`grep ${uh(e,60)} in ${t}`:`grep ${uh(e,100)}`}if(/^(glob|find)$/.test(i)){let e=n.pattern??n.glob;if(typeof e==`string`)return`glob ${uh(e,80)}`}if(/^(read|read_file|cat|view)$/.test(i)){let e=dh(n),t=n.offset,r=n.limit;if(e&&(typeof t==`number`||typeof r==`number`)){let n=t??0;return`read ${e} (${n}\u2026${typeof r==`number`?n+r:``})`}if(e)return`read ${e}`}for(let e of lh){let t=n[e];if(typeof t==`string`&&t.length>0)return`${e}: ${uh(t,100)}`}return uh(fh(r),120)}[`function __clip(s,n){ s=String(s==null?"":s); return s.length>n ? s.slice(0,n-1)+"\\u2026" : s; }`,`function toolInputSummary(name, rawInput){`,` if(rawInput==null || rawInput==="") return "";`,` var obj=null, raw=rawInput;`,` if(typeof rawInput==="string"){`,` var s=rawInput.trim();`,` if(s.charAt(0)==="{" || s.charAt(0)==="["){ try{ var pj=JSON.parse(s); if(pj && typeof pj==="object"){ obj=pj; raw=pj; } }catch(_e){} }`,` } else if(rawInput && typeof rawInput==="object"){ obj=rawInput; raw=rawInput; }`,` if(!obj) return __clip(String(raw),120);`,` var n=String(name==null?"":name).toLowerCase();`,` if(/^todo(_?write)?$|^todos$/.test(n) || Array.isArray(obj.todos)){`,` var todos=obj.todos||[];`,` if(Array.isArray(todos)){`,` var done=0, wip=0, ti;`,` for(ti=0; ti<todos.length; ti++){ var st=todos[ti]&&todos[ti].status; if(st==="completed") done++; else if(st==="in_progress") wip++; }`,` var tp=[todos.length+" todo"+(todos.length===1?"":"s")];`,` if(done>0) tp.push(done+" done"); if(wip>0) tp.push(wip+" in-progress");`,` return tp.join(" \\u00b7 ");`,` }`,` }`,` if(/batch|parallel/.test(n) || Array.isArray(obj.tool_uses) || Array.isArray(obj.calls)){`,` var list=obj.tool_uses||obj.calls||obj.batch;`,` if(Array.isArray(list)){`,` var names={}, ord=[], li, it, nm;`,` for(li=0; li<list.length; li++){ it=list[li]; if(it && typeof it==="object"){ nm=("name" in it)?it.name:(("tool" in it)?it.tool:null); if(nm!=null){ nm=String(nm); if(!names[nm]){ names[nm]=1; ord.push(nm); } } } }`,` var preview=ord.slice(0,3).join(", ");`,` var more=ord.length>3 ? " +"+(ord.length-3) : "";`,` return list.length+" sub-tool"+(list.length===1?"":"s")+(preview?(" \\u00b7 "+preview+more):"");`,` }`,` }`,` var fp;`,` if(/^(edit|str_replace|edit_file|patch)$/.test(n)){`,` fp=(obj.file_path!=null?obj.file_path:(obj.path!=null?obj.path:obj.filepath));`,` var oldS=typeof obj.old_string==="string"?obj.old_string:"";`,` var newS=typeof obj.new_string==="string"?obj.new_string:"";`,` var ol=oldS?oldS.split("\\n").length:0, nl=newS?newS.split("\\n").length:0;`,` var efp=typeof fp==="string"?fp:"";`,` return "edit "+(efp||"(file)")+((ol||nl)?(" ("+ol+" \\u2192 "+nl+" lines)"):"");`,` }`,` if(/^(write|write_file|create_file|new_file)$/.test(n)){`,` fp=(obj.file_path!=null?obj.file_path:(obj.path!=null?obj.path:obj.filepath));`,` var wc=typeof obj.content==="string"?obj.content:"";`,` var wl=wc?wc.split("\\n").length:0;`,` var wfp=typeof fp==="string"?fp:"";`,` return "write "+(wfp||"(file)")+(wl?(" \\u00b7 "+wl+" lines"):"");`,` }`,` if(/^(bash|shell|sh|exec|run|run_command|run_shell|command)$/.test(n)){`,` var cmd=(obj.command!=null?obj.command:(obj.cmd!=null?obj.cmd:obj.script));`,` if(typeof cmd==="string") return "$ "+__clip(cmd,110);`,` }`,` if(/^(fetch|http|web|web_fetch|web_search|webfetch|curl|request)$/.test(n)){`,` if(typeof obj.url==="string"){ var mth=(typeof obj.method==="string"?obj.method:"GET"); return mth.toUpperCase()+" "+__clip(obj.url,100); }`,` }`,` if(/^(grep|search|ripgrep|rg)$/.test(n)){`,` var pat=obj.pattern, scope=(obj.path!=null?obj.path:(obj.glob!=null?obj.glob:obj.type));`,` if(typeof pat==="string"){ return scope ? ("grep "+__clip(pat,60)+" in "+scope) : ("grep "+__clip(pat,100)); }`,` }`,` if(/^(glob|find)$/.test(n)){`,` var gp=(obj.pattern!=null?obj.pattern:obj.glob);`,` if(typeof gp==="string") return "glob "+__clip(gp,80);`,` }`,` if(/^(read|read_file|cat|view)$/.test(n)){`,` fp=(obj.file_path!=null?obj.file_path:(obj.path!=null?obj.path:obj.filepath));`,` if(typeof fp==="string" && fp){`,` var off=obj.offset, lim=obj.limit;`,` if(typeof off==="number" || typeof lim==="number"){ var start=(typeof off==="number"?off:0); var end=(typeof lim==="number"?(start+lim):""); return "read "+fp+" ("+start+"\\u2026"+end+")"; }`,` return "read "+fp;`,` }`,` }`,` var HEAD=["path","file_path","pattern","command","cmd","url","query","description","content"], hi;`,` for(hi=0; hi<HEAD.length; hi++){ var hv=obj[HEAD[hi]]; if(typeof hv==="string" && hv.length>0){ return HEAD[hi]+": "+__clip(hv,100); } }`,` var jsonStr; try{ jsonStr=JSON.stringify(raw); }catch(_e2){ jsonStr=String(raw); }`,` return __clip(jsonStr,120);`,`}`].join(`
|
|
12
|
-
`);function hh(e){let t=(e??``).toLowerCase().replace(/^mcp__[^_]+__/,``);return/^(edit|str_replace|edit_file|patch|apply_patch|multiedit)$/.test(t)?`edit`:/^(write|write_file|create_file|new_file)$/.test(t)?`write`:/^(bash|shell|exec|run|run_command|run_shell|powershell|terminal)$/.test(t)?`bash`:/^(read|read_file|cat|open)$/.test(t)?`read`:/^(grep|search|ripgrep|glob|find)$/.test(t)?`search`:/^(fetch|http|web|webfetch|websearch|curl|request)$/.test(t)?`fetch`:/todo/.test(t)?`todo`:`generic`}function gh(e){if(e===void 0)return;let t=e.trim();if(!(t===``||t[0]!==`{`&&t[0]!==`[`))try{return JSON.parse(t)}catch{return}}function _h(e,t){return t===void 0||t===``||t===`{}`?``:mh(e,t)}function vh(e){let t=gh(e);if(t===void 0)return e??``;try{return JSON.stringify(t,null,2)}catch{return e??``}}function yh(e){let t=gh(e);if(typeof t!=`object`||!t)return null;let n=t.todos;if(!Array.isArray(n))return null;let r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e,n=t.status===`completed`?`completed`:t.status===`in_progress`?`in_progress`:`pending`,i=typeof t.content==`string`?t.content:typeof t.subject==`string`?t.subject:typeof t.title==`string`?t.title:``;r.push({status:n,content:i})}return r.length>0?r:null}function bh(e){return e===void 0||!Number.isFinite(e)||e<0?``:e<1e3?`${Math.round(e)}ms`:e<6e4?`${(e/1e3).toFixed(+(e<1e4))}s`:`${Math.floor(e/6e4)}m${Math.round(e%6e4/1e3)}s`}function xh(e){return e?e.replace(/^mcp__([^_]+)__/,`$1:`):`tool`}function Sh(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Ch(e){if(typeof e==`string`){let t=e.trim();if(t.startsWith(`{`)||t.startsWith(`[`))try{let e=JSON.parse(t);if(e&&typeof e==`object`)return e}catch{return null}return null}return e&&typeof e==`object`?e:null}function wh(e,t){if(!e)return null;let n=Ch(t);if(!n)return null;let r=e.toLowerCase(),i=String(n.file_path??n.path??``);switch(r){case`edit`:case`str_replace`:case`edit_file`:case`multi_edit`:{let e=typeof n.old_string==`string`?n.old_string:``,t=typeof n.new_string==`string`?n.new_string:``;return!e&&!t?null:{mode:`lcs`,oldText:e,newText:t,caption:`edit ${i}`.trim()}}case`write`:case`write_file`:case`create_file`:{let e=typeof n.content==`string`?n.content:``;return e?{mode:`lcs`,oldText:``,newText:e,caption:`write ${i} (new)`.trim()}:null}case`patch`:{let e=typeof n.patch==`string`?n.patch:``;return e.trim()?{mode:`unified`,patchText:e,caption:i?`patch ${i}`:`patch`}:null}default:return null}}function Th(e,t){let n=e.split(`
|
|
13
|
-
`),r=t.split(`
|
|
14
|
-
`);if(n.length>5e3||r.length>5e3)return null;let i=n.length,a=r.length,o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=i-1;e>=0;e--)for(let t=a-1;t>=0;t--)o[e][t]=n[e]===r[t]?o[e+1][t+1]+1:Math.max(o[e+1][t],o[e][t+1]);let s=[],c=0,l=0;for(;c<i&&l<a;)n[c]===r[l]?(s.push({kind:`ctx`,text:n[c]}),c++,l++):o[c+1][l]>=o[c][l+1]?(s.push({kind:`del`,text:n[c]}),c++):(s.push({kind:`add`,text:r[l]}),l++);for(;c<i;)s.push({kind:`del`,text:n[c++]});for(;l<a;)s.push({kind:`add`,text:r[l++]});return s}function Eh(e){let t=[],n=e.split(`
|
|
15
|
-
`);for(let e of n)e.startsWith(`@@`)||e.startsWith(`--- `)||e.startsWith(`+++ `)||e.startsWith(`diff `)||e.startsWith(`index `)||e.startsWith(`\\ `)?t.push({kind:`meta`,text:e}):e.startsWith(`+`)?t.push({kind:`add`,text:e.slice(1)}):e.startsWith(`-`)?t.push({kind:`del`,text:e.slice(1)}):t.push({kind:`ctx`,text:e.startsWith(` `)?e.slice(1):e});return t.length>0&&t[t.length-1].kind===`ctx`&&t[t.length-1].text===``&&t.pop(),t}function Dh(e,t){let n=wh(e,t);return n?n.mode===`unified`?{caption:n.caption,rows:Eh(n.patchText)}:{caption:n.caption,rows:Th(n.oldText,n.newText)}:null}[`var DIFF_MAX_LINES = 5000;`,`function __diffObj(input){`,` if(typeof input==="string"){ var s=input.trim(); if(s.charAt(0)==="{"||s.charAt(0)==="["){ try{ var p=JSON.parse(s); if(p&&typeof p==="object") return p; }catch(_e){} } return null; }`,` if(input&&typeof input==="object") return input; return null;`,`}`,`function diffFromToolInput(name, input){`,` if(!name) return null;`,` var obj=__diffObj(input); if(!obj) return null;`,` var n=String(name).toLowerCase();`,` var fp=String(obj.file_path!=null?obj.file_path:(obj.path!=null?obj.path:""));`,` if(n==="edit"||n==="str_replace"||n==="edit_file"||n==="multi_edit"){`,` var oldT=typeof obj.old_string==="string"?obj.old_string:"";`,` var newT=typeof obj.new_string==="string"?obj.new_string:"";`,` if(!oldT&&!newT) return null;`,` return { mode:"lcs", oldText:oldT, newText:newT, caption:("edit "+fp).replace(/\\s+$/,"") };`,` }`,` if(n==="write"||n==="write_file"||n==="create_file"){`,` var c=typeof obj.content==="string"?obj.content:"";`,` if(!c) return null;`,` return { mode:"lcs", oldText:"", newText:c, caption:("write "+fp+" (new)").replace(/\\s+/g," ").replace(/\\s+$/,"") };`,` }`,` if(n==="patch"){`,` var pt=typeof obj.patch==="string"?obj.patch:"";`,` if(!pt.replace(/\\s/g,"")) return null;`,` return { mode:"unified", patchText:pt, caption: fp ? ("patch "+fp) : "patch" };`,` }`,` return null;`,`}`,`function computeLineDiff(oldText, newText){`,` var a=oldText.split("\\n"), b=newText.split("\\n");`,` if(a.length>DIFF_MAX_LINES||b.length>DIFF_MAX_LINES) return null;`,` var nn=a.length, mm=b.length, i, j;`,` var dp=new Array(nn+1); for(i=0;i<=nn;i++){ dp[i]=new Array(mm+1); for(j=0;j<=mm;j++) dp[i][j]=0; }`,` for(i=nn-1;i>=0;i--){ for(j=mm-1;j>=0;j--){ dp[i][j]= a[i]===b[j] ? dp[i+1][j+1]+1 : Math.max(dp[i+1][j], dp[i][j+1]); } }`,` var rows=[]; i=0; j=0;`,` while(i<nn&&j<mm){ if(a[i]===b[j]){ rows.push({kind:"ctx",text:a[i]}); i++; j++; } else if(dp[i+1][j]>=dp[i][j+1]){ rows.push({kind:"del",text:a[i]}); i++; } else { rows.push({kind:"add",text:b[j]}); j++; } }`,` while(i<nn){ rows.push({kind:"del",text:a[i]}); i++; }`,` while(j<mm){ rows.push({kind:"add",text:b[j]}); j++; }`,` return rows;`,`}`,`function parseUnifiedDiff(patchText){`,` var rows=[], lines=patchText.split("\\n"), k, raw;`,` for(k=0;k<lines.length;k++){ raw=lines[k];`,` if(raw.indexOf("@@")===0||raw.indexOf("--- ")===0||raw.indexOf("+++ ")===0||raw.indexOf("diff ")===0||raw.indexOf("index ")===0||raw.indexOf("\\\\ ")===0){ rows.push({kind:"meta",text:raw}); }`,` else if(raw.charAt(0)==="+"){ rows.push({kind:"add",text:raw.slice(1)}); }`,` else if(raw.charAt(0)==="-"){ rows.push({kind:"del",text:raw.slice(1)}); }`,` else { rows.push({kind:"ctx",text: raw.charAt(0)===" " ? raw.slice(1) : raw}); }`,` }`,` if(rows.length>0 && rows[rows.length-1].kind==="ctx" && rows[rows.length-1].text===""){ rows.pop(); }`,` return rows;`,`}`,`function diffRowsFromToolInput(name, input){`,` var d=diffFromToolInput(name, input); if(!d) return null;`,` if(d.mode==="unified") return { caption:d.caption, rows:parseUnifiedDiff(d.patchText) };`,` return { caption:d.caption, rows:computeLineDiff(d.oldText, d.newText) };`,`}`].join(`
|
|
16
|
-
`);var Oh={add:`+`,del:`-`,ctx:` `,meta:`@`};function kh({toolName:e,toolInput:t}){let n=(0,G.useMemo)(()=>Dh(e,t),[e,t]);if(!n)return null;let{caption:r,rows:i}=n;if(i===null)return(0,K.jsxs)(`div`,{className:`hq-tool-empty`,children:[`diff too large to render — `,r]});let a=i.filter(e=>e.kind===`add`).length,o=i.filter(e=>e.kind===`del`).length;return(0,K.jsxs)(`div`,{className:`hq-diff`,children:[(0,K.jsxs)(`div`,{className:`hq-diff-stat`,children:[(0,K.jsx)(`span`,{className:`hq-diff-path`,title:r,children:r}),(0,K.jsxs)(`span`,{className:`hq-diff-add-count`,children:[`+`,a]}),(0,K.jsxs)(`span`,{className:`hq-diff-del-count`,children:[`-`,o]})]}),(0,K.jsx)(`pre`,{className:`hq-diff-body`,children:i.map((e,t)=>(0,K.jsxs)(`span`,{className:`hq-diff-line ${e.kind}`,children:[(0,K.jsx)(`span`,{className:`hq-diff-gutter`,children:Oh[e.kind]}),e.text||` `]},t))})]})}function Ah(e,t){return wh(e,t)!==null}var jh=25,Mh=12;function Nh({text:e,isError:t,wrap:n,framed:r=!0}){let i=(0,G.useMemo)(()=>e.split(`
|
|
17
|
-
`),[e]),a=i.length>jh,[o,s]=(0,G.useState)(!a),l=o?e:i.slice(0,Mh).join(`
|
|
18
|
-
`);return(0,K.jsxs)(`div`,{className:`hq-result${r?``:` bare`}`,children:[(0,K.jsx)(`pre`,{className:`hq-result-pre ${n?`wrap`:`nowrap`}${t?` err`:``}`,children:l}),a&&(0,K.jsx)(`button`,{type:`button`,className:`hq-result-toggle`,onClick:()=>s(e=>!e),children:o?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(c,{size:12}),` collapse to `,Mh,` lines`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(d,{size:12}),` show all `,i.length,` lines (+`,i.length-Mh,` more)`]})})]})}function Ph(e,t){let n=t.trim();if(/^\s*\d+→/m.test(t.slice(0,200)))return{kind:`numbered`};if(n.startsWith(`{`)&&n.endsWith(`}`)||n.startsWith(`[`)&&n.endsWith(`]`))try{let e=JSON.parse(n);if(typeof e==`object`&&e)return{kind:`json`,value:e}}catch{}let r=!!e&&/^(bash|shell|exec|run|powershell)/i.test(e),i=t.match(/(?:^|\n)\s*(?:\[?exit(?:\s*code)?\]?\s*[:=]?\s*)(\d+)\s*$/i),a=t.match(/(?:^|\s)(\d+\s*ms|\d+\.\d+s)\s*$/i);if(r||i){let e=t;return i&&(e=t.slice(0,i.index).trimEnd()),{kind:`bash`,stdout:e,exitCode:i?Number(i[1]):void 0,duration:a?.[1]}}return{kind:`plain`}}function Fh({value:e,isError:t}){let n=(0,G.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]),r=n.split(`
|
|
19
|
-
`).length,[i,a]=(0,G.useState)(r<30);return(0,K.jsxs)(`div`,{className:`hq-result${t?` err-frame`:``}`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`hq-result-jsonbar`,onClick:()=>a(e=>!e),children:[(0,K.jsxs)(`span`,{className:`hq-result-jsonbar-left`,children:[i?(0,K.jsx)(b,{size:12}):(0,K.jsx)(m,{size:12}),(0,K.jsxs)(`span`,{children:[`JSON · `,r,` lines`]})]}),(0,K.jsx)(`span`,{children:i?`collapse`:`expand`})]}),i&&(0,K.jsx)(`pre`,{className:`hq-result-pre nowrap${t?` err`:``}`,children:n})]})}function Ih({toolName:e,result:t,isError:n}){let r=(0,G.useMemo)(()=>Ph(e,t),[e,t]);return r.kind===`json`?(0,K.jsx)(Fh,{value:r.value,isError:n}):r.kind===`numbered`?(0,K.jsx)(Nh,{text:t,isError:n,wrap:!1}):r.kind===`bash`?(0,K.jsxs)(`div`,{className:`hq-result hq-result-bash`,children:[r.stdout!==void 0&&r.stdout!==``&&(0,K.jsx)(Nh,{text:r.stdout,isError:n,wrap:!0,framed:!1}),(r.exitCode!==void 0||r.duration!==void 0)&&(0,K.jsxs)(`div`,{className:`hq-result-exit${r.exitCode!==void 0&&r.exitCode!==0?` bad`:``}`,children:[r.exitCode!==void 0&&(0,K.jsxs)(`span`,{children:[`exit code `,r.exitCode]}),r.duration!==void 0&&(0,K.jsx)(`span`,{children:r.duration})]})]}):(0,K.jsx)(Nh,{text:t,isError:n,wrap:!0})}var Lh={completed:`✔`,in_progress:`▶`,pending:`○`};function Rh({todos:e}){let t=e.filter(e=>e.status===`completed`).length;return(0,K.jsxs)(`div`,{className:`hq-tool-section`,children:[(0,K.jsxs)(`div`,{className:`hq-tool-section-label`,children:[`todos · `,t,`/`,e.length,` done`]}),(0,K.jsx)(`ul`,{className:`hq-todo-list`,children:e.map((e,t)=>(0,K.jsxs)(`li`,{className:`hq-todo ${e.status}`,children:[(0,K.jsx)(`span`,{className:`hq-todo-mark`,children:Lh[e.status]}),(0,K.jsx)(`span`,{className:`hq-todo-text`,children:e.content||`(empty)`})]},t))})]})}function zh({entry:e}){let t=hh(e.tool),n=Ah(e.tool,e.toolInput),r=t===`todo`?yh(e.toolInput):null,i=e.text??``,a=i.trim()!==``;return(0,K.jsxs)(`div`,{className:`hq-tool-body`,children:[n?(0,K.jsxs)(`div`,{className:`hq-tool-section`,children:[(0,K.jsx)(`div`,{className:`hq-tool-section-label`,children:`changes`}),(0,K.jsx)(kh,{toolName:e.tool,toolInput:e.toolInput}),a&&!e.isError&&(0,K.jsx)(`div`,{className:`hq-tool-result-note`,children:i.split(`
|
|
20
|
-
`)[0]})]}):r?(0,K.jsx)(Rh,{todos:r}):e.toolInput!==void 0&&e.toolInput!==`{}`&&(0,K.jsxs)(`div`,{className:`hq-tool-section`,children:[(0,K.jsx)(`div`,{className:`hq-tool-section-label`,children:`input`}),(0,K.jsx)(`pre`,{className:`hq-tool-pre`,children:vh(e.toolInput)})]}),!n&&a&&(0,K.jsxs)(`div`,{className:`hq-tool-section`,children:[(0,K.jsxs)(`div`,{className:`hq-tool-section-head`,children:[(0,K.jsx)(`span`,{className:`hq-tool-section-label`,children:e.isError?`error`:`output`}),(0,K.jsx)(eh,{text:i,label:`copy`})]}),(0,K.jsx)(Ih,{toolName:e.tool,result:i,isError:e.isError})]}),!a&&!e.isError&&!r&&!n&&(0,K.jsx)(`div`,{className:`hq-tool-empty`,children:`(no output)`})]})}function Bh({entry:e,running:t}){let[n,r]=(0,G.useState)(!1),i=_h(e.tool,e.toolInput),a=bh(e.durationMs),o=xh(e.tool),{Icon:s,color:c}=ch(e.tool);return(0,K.jsxs)(`div`,{className:`hq-chat-turn tool ${e.isError?`err`:``}`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`hq-tool-head`,onClick:()=>r(e=>!e),children:[(0,K.jsx)(`span`,{className:`hq-tool-caret`,children:n?(0,K.jsx)(b,{size:13}):(0,K.jsx)(m,{size:13})}),(0,K.jsx)(`span`,{className:`hq-tool-icon`,style:{color:c},children:(0,K.jsx)(s,{size:14})}),(0,K.jsx)(`span`,{className:`hq-tool-name`,children:o}),i!==``&&(0,K.jsx)(`span`,{className:`hq-tool-summary`,children:i}),a!==``&&(0,K.jsx)(`span`,{className:`hq-tool-dur`,children:a}),(0,K.jsx)(`span`,{className:`hq-tool-status`,"aria-hidden":!0,children:t?(0,K.jsx)(`span`,{className:`hq-tool-running-dot`,title:`running`}):e.isError?(0,K.jsx)(E,{size:14,className:`hq-status-err`}):(0,K.jsx)(y,{size:14,className:`hq-status-ok`})})]}),n&&(0,K.jsx)(zh,{entry:e})]})}function Vh({entry:e}){let[t,n]=(0,G.useState)(!1),r=e.text.split(`
|
|
21
|
-
`)[0]??``;return(0,K.jsxs)(`div`,{className:`hq-chat-turn thinking`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`hq-thinking-head`,onClick:()=>n(e=>!e),children:[(0,K.jsx)(`span`,{className:`hq-tool-caret`,children:t?(0,K.jsx)(b,{size:13}):(0,K.jsx)(m,{size:13})}),(0,K.jsx)(i,{size:13,className:`hq-thinking-icon`}),(0,K.jsx)(`span`,{className:`hq-thinking-label`,children:`thinking`}),!t&&(0,K.jsx)(`span`,{className:`hq-thinking-peek`,children:r})]}),t&&(0,K.jsx)(`div`,{className:`hq-thinking-body`,children:(0,K.jsx)(rh,{text:e.text})})]})}var Hh=(0,G.memo)(function({entry:e,running:t}){let n=Sh(e.ts);return e.role===`tool`||e.role===`error`&&e.toolInput!==void 0?(0,K.jsx)(Bh,{entry:e,running:t??Ym(e)}):e.role===`thinking`?(0,K.jsx)(Vh,{entry:e}):e.role===`user`?(0,K.jsx)(`div`,{className:`hq-chat-turn user`,children:(0,K.jsxs)(`div`,{className:`hq-chat-bubble user`,children:[(0,K.jsxs)(`div`,{className:`hq-chat-role`,children:[`you`,e.agentId===void 0?``:` · ${e.agentId}`,n!==``&&(0,K.jsx)(`span`,{className:`hq-chat-clock`,children:n})]}),(0,K.jsx)(`div`,{className:`hq-chat-prose`,children:e.text})]})}):e.role===`assistant`?(0,K.jsx)(`div`,{className:`hq-chat-turn assistant`,children:(0,K.jsxs)(`div`,{className:`hq-chat-bubble assistant`,children:[(0,K.jsxs)(`div`,{className:`hq-chat-role`,children:[`agent`,e.agentId===void 0?``:` · ${e.agentId}`,n!==``&&(0,K.jsx)(`span`,{className:`hq-chat-clock`,children:n})]}),(0,K.jsx)(rh,{text:e.text})]})}):e.role===`error`?(0,K.jsx)(`div`,{className:`hq-chat-turn error`,children:(0,K.jsxs)(`div`,{className:`hq-chat-bubble error`,children:[(0,K.jsxs)(`div`,{className:`hq-chat-role err`,children:[`error`,n!==``&&(0,K.jsx)(`span`,{className:`hq-chat-clock`,children:n})]}),(0,K.jsx)(`pre`,{className:`hq-tool-pre err`,children:e.text})]})}):e.text.trim()===``?null:(0,K.jsx)(`div`,{className:`hq-chat-turn system`,children:(0,K.jsxs)(`span`,{className:`hq-chat-system-line`,children:[e.text,n!==``&&(0,K.jsx)(`span`,{className:`hq-chat-clock`,children:n})]})})});function Uh(e){return e===`active`||e===`running`||e===`streaming`?`active`:e===`waiting_user`?`warn`:e===`error`||e===`stale`||e===`closing`?`error`:`info`}function Wh(e){return e.sessionId===void 0?null:{sessionId:e.sessionId,agentId:e.agentId??null,label:e.label,status:e.status}}function Gh({target:e,onClose:t}){let n=$m(e.sessionId,e.agentId),{entries:i}=n;return(0,G.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,K.jsxs)(`aside`,{className:`hq-fleet-drawer`,role:`dialog`,"aria-label":e.label,children:[(0,K.jsxs)(`div`,{className:`hq-fleet-drawer-header`,children:[e.agentId===null?(0,K.jsx)(l,{size:14,className:`hq-chat-header-icon`}):(0,K.jsx)(w,{size:14,className:`hq-chat-header-icon`}),(0,K.jsx)(`span`,{className:`hq-fleet-drawer-title`,title:e.label,children:e.label}),e.status!==void 0&&(0,K.jsx)(`span`,{className:`hq-pill ${Uh(e.status)}`,children:e.status}),(0,K.jsxs)(`span`,{className:`hq-fleet-drawer-actions`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:()=>He(`console`),title:`Open this conversation in the full Console`,children:[(0,K.jsx)(r,{size:12}),` Console`]}),(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,onClick:t,"aria-label":`Close`,title:`Close (Esc)`,children:(0,K.jsx)(H,{size:13})})]})]}),(0,K.jsxs)(`div`,{className:`hq-fleet-drawer-stats`,children:[(0,K.jsxs)(`span`,{className:`hq-pill`,children:[n.stats.turns,` turns`]}),(0,K.jsxs)(`span`,{className:`hq-pill`,children:[n.stats.tools,` tools`]}),n.stats.running>0&&(0,K.jsxs)(`span`,{className:`hq-pill running`,children:[n.stats.running,` running`]}),n.stats.errors>0&&(0,K.jsxs)(`span`,{className:`hq-pill error`,children:[n.stats.errors,` err`]}),n.meta.source!==void 0&&(0,K.jsx)(`span`,{className:`hq-pill`,title:n.meta.source===`disk`?`full history replayed from this machine`:`live ring only (remote or not yet persisted)`,children:n.meta.source===`disk`?`full history`:`live ring`})]}),(0,K.jsxs)(`div`,{className:`hq-chat-scroll hq-fleet-drawer-body`,children:[n.loading&&i.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:`Loading transcript…`}):n.error===null?i.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:e.agentId===null?`No transcript entries yet.`:`No messages from ${e.label} yet.`}):(0,K.jsx)(Hm,{ref:n.listRef,onScroll:n.onScroll,className:`hq-chat-vlist`,children:i.map((e,t)=>(0,K.jsx)(`div`,{className:`hq-chat-rowpad`,children:(0,K.jsx)(Hh,{entry:e,running:n.isRunningAt(e,t)})},Xm(e,t)))}):(0,K.jsxs)(`div`,{className:`hq-empty`,children:[`Error: `,n.error]}),!n.pinned&&i.length>0&&(0,K.jsx)(`button`,{type:`button`,className:`hq-chat-jump`,onClick:n.jumpToLatest,title:`Jump to latest`,children:(0,K.jsx)(u,{size:14})})]})]})}function Kh(e){return e===`machine`?0:e===`project`?1:e===`terminal`?2:3}function qh(e){let t=e.filter(e=>e.kind===`machine`),n=new Map,r=new Map,i=new Map;for(let t of e)if(t.kind===`project`&&t.machineId!==void 0){let e=n.get(t.machineId)??[];e.push(t),n.set(t.machineId,e)}else if(t.kind===`terminal`){let e=Yh(t.machineId??``,t.projectId??``),n=r.get(e)??[];n.push(t),r.set(e,n)}else if(t.kind===`agent`&&t.sessionId!==void 0){let e=i.get(t.sessionId)??[];e.push(t),i.set(t.sessionId,e)}let a=new Map,o=0,s=e=>e.length===0?0:((e[0]??0)+(e[e.length-1]??0))/2;for(let e of t){let t=n.get(e.machineId??``)??[],c=[];for(let e of t){let t=r.get(e.id)??[],n=[];for(let e of t){let t=i.get(e.sessionId??``)??[],r;if(t.length>0){let e=[];for(let n of t)a.set(n.id,o),e.push(o),o+=118;r=s(e)}else r=o,o+=118;a.set(e.id,r),n.push(r),o+=18}let l;n.length>0?l=s(n):(l=o,o+=118),a.set(e.id,l),c.push(l),o+=42}c.length>0?a.set(e.id,s(c)):(a.set(e.id,o),o+=118),o+=64}let c=new Map;for(let t of e)c.set(t.id,{x:Kh(t.kind)*300,y:a.get(t.id)??0});return c}function Jh(e){return`machine:${e}`}function Yh(e,t){return`project:${e}:${t}`}function Xh(e){return`terminal:${e}`}function Zh(e,t){return`agent:${e}:${t}`}function Qh(e,t,n,r){let i=`${n}->${r}`;t.has(i)||(t.add(i),e.push({id:i,source:n,target:r}))}function $h(e,t){return e?.projectName??t?.projectName??`unknown project`}function eg(e,t){let n=e?.projectRootDisplay??t?.projectRoot;if(!(n===void 0||n.length===0))return n.length>54?`…${n.slice(-51)}`:n}function tg(e){return`${e.clientKind.toUpperCase()} · ${e.sessionId.length>18?`…${e.sessionId.slice(-14)}`:e.sessionId}`}function ng(e,t){return{sessionId:e.sessionId??`client:${e.clientId}`,clientKind:e.kind,machineId:e.machineId,...e.hostname===void 0?{}:{hostname:e.hostname},...e.pid===void 0?{}:{pid:e.pid},projectId:e.projectId,projectName:t?.projectName??e.projectId,projectRoot:t?.projectRootDisplay??``,...t?.gitBranch===void 0?{}:{gitBranch:t.gitBranch},status:e.connected?`idle`:`stale`,startedAt:e.connectedAt??e.lastSeenAt,lastActivityAt:e.lastSeenAt,agentCount:0,agents:[]}}function rg(e,t,n,r){let i=t.get(e),a=n.find(t=>t.machineId===e),o=r.find(t=>t.machineId===e),s=i?.hostname??a?.hostname??o?.hostname??e,c=i?.sessionCount??n.filter(t=>t.machineId===e).length,l=i?.agentCount??n.reduce((t,n)=>t+(n.machineId===e?n.agents.length:0),0),u=i?.clientCount??r.filter(t=>t.machineId===e&&t.connected).length;return{label:s,sub:e,chips:[`${u} client${u===1?``:`s`}`,`${c} terminal${c===1?``:`s`}`,`${l} agent${l===1?``:`s`}`]}}function ig(e){if(e===null)return{nodes:[],edges:[]};let t=[],n=[],r=new Set,i=new Set,a=new Map((e.machines??[]).map(e=>[e.machineId,e])),o=new Map((e.projects??[]).map(e=>[e.projectId,e])),s=[...e.liveSessions??[]],c=new Set(s.map(e=>e.sessionId));for(let t of e.clients??[]){if(!t.connected)continue;let e=t.sessionId??`client:${t.clientId}`;c.has(e)||(s.push(ng(t,o.get(t.projectId))),c.add(e))}let l=new Set;for(let t of e.machines??[])l.add(t.machineId);for(let e of s)l.add(e.machineId);for(let t of e.clients??[])t.connected&&l.add(t.machineId);for(let n of l){let i=Jh(n),o=rg(n,a,s,e.clients??[]);t.push({id:i,kind:`machine`,label:o.label,sub:o.sub,chips:o.chips,machineId:n}),r.add(i)}let u=s.sort((e,t)=>{let n=e.machineId.localeCompare(t.machineId);if(n!==0)return n;let r=e.projectName.localeCompare(t.projectName);return r===0?e.sessionId.localeCompare(t.sessionId):r});for(let e of u){let a=e.machineId,s=o.get(e.projectId),c=Yh(a,e.projectId);if(!r.has(c)){let n=[`${s?.activeClients??u.filter(t=>t.machineId===a&&t.projectId===e.projectId).length} client${(s?.activeClients??0)===1?``:`s`}`,`${s?.activeSessions??u.filter(t=>t.machineId===a&&t.projectId===e.projectId).length} terminal${(s?.activeSessions??0)===1?``:`s`}`];s?.gitBranch!==void 0&&n.push(s.gitBranch),t.push({id:c,kind:`project`,label:$h(s,e),sub:eg(s,e),status:s?.status??e.status,chips:n,machineId:a,projectId:e.projectId}),r.add(c)}Qh(n,i,Jh(a),c);let l=Xh(e.sessionId);if(!r.has(l)){let n=e.sessionId.startsWith(`client:`)&&e.agents.length===0,i=[e.clientKind,e.status,`${e.agentCount} agent${e.agentCount===1?``:`s`}`];e.gitBranch!==void 0&&i.push(e.gitBranch),t.push({id:l,kind:`terminal`,label:tg(e),sub:n?`waiting for session telemetry`:e.projectName,status:e.status,chips:i,machineId:a,projectId:e.projectId,sessionId:e.sessionId,clientKind:e.clientKind,session:e,isSyntheticSession:n}),r.add(l)}Qh(n,i,c,l);for(let r of e.agents){let o=Zh(e.sessionId,r.id);t.push({id:o,kind:`agent`,label:r.name||r.id,sub:r.currentTool??r.partialText,status:r.status,chips:[r.status,`${r.iterations} iter`,`${r.toolCalls} tools`,...r.model===void 0?[]:[r.model]],machineId:a,projectId:e.projectId,sessionId:e.sessionId,agentId:r.id,agent:r,session:e}),Qh(n,i,l,o)}}return{nodes:t,edges:n}}var ag=220,og=104;function sg(e,t){return e===`machine`?(0,K.jsx)(ie,{size:14,className:`hq-fleet-node-icon`}):e===`project`?(0,K.jsx)(o,{size:14,className:`hq-fleet-node-icon`}):e===`terminal`?(0,K.jsx)(l,{size:14,className:`hq-fleet-node-icon`}):(0,K.jsx)(w,{size:14,className:`hq-fleet-agent-dot ${t??`idle`}`})}function cg(e){return e===void 0?`idle`:e===`active`||e===`running`||e===`streaming`?`active`:e===`waiting_user`?`warn`:e===`error`||e===`stale`||e===`closing`?`error`:e}function lg(e){return e===`active`||e===`running`||e===`streaming`}function ug({data:e,selected:t}){let n=e.kind===`terminal`||e.kind===`agent`;return(0,K.jsxs)(`div`,{className:`hq-flow-node ${e.kind}${t?` selected`:``}${n?` clickable`:``}`,children:[(0,K.jsx)(zd,{type:`target`,position:X.Left,className:`hq-flow-handle`}),(0,K.jsxs)(`div`,{className:`hq-flow-title`,children:[e.kind===`agent`?(0,K.jsx)(`span`,{className:`hq-flow-dot ${cg(e.status)}`}):sg(e.kind,e.clientKind),(0,K.jsx)(`span`,{className:`hq-flow-label`,children:e.label})]}),e.sub!==void 0&&(0,K.jsx)(`div`,{className:`hq-flow-sub`,children:e.sub}),(0,K.jsx)(`div`,{className:`hq-flow-chips`,children:e.chips.slice(0,4).map(e=>(0,K.jsx)(`span`,{className:`hq-pill ${cg(e)}`,children:e},e))}),(0,K.jsx)(zd,{type:`source`,position:X.Right,className:`hq-flow-handle`})]})}var dg={fleet:ug};function fg(e){let t=qh(e);return e.map(e=>({id:e.id,type:`fleet`,data:e,position:t.get(e.id)??{x:0,y:0},style:{width:ag,minHeight:og}}))}function pg(e){let t=new Map(e.nodes.map(e=>[e.id,e.status]));return e.edges.map(e=>{let n=lg(t.get(e.target));return{...e,type:`smoothstep`,animated:n,markerEnd:{type:Ss.ArrowClosed,width:14,height:14},className:`hq-flow-edge${n?` live`:``}`}})}function mg({topology:e}){let[t,n,r]=bp([]),[i,a,o]=xp([]),{fitView:s}=fd(),c=(0,G.useRef)(!1);(0,G.useEffect)(()=>{let t=fg(e.nodes);n(e=>{if(!c.current)return t;let n=new Map(e.map(e=>[e.id,e.position]));return t.map(e=>{let t=n.get(e.id);return t===void 0?e:{...e,position:t}})}),a(pg(e))},[e,n,a]);let l=(0,G.useCallback)(()=>{c.current=!1,n(fg(e.nodes)),window.setTimeout(()=>void s({padding:.18,duration:400}),50)},[e,n,s]),[u,d]=(0,G.useState)(null);return(0,K.jsxs)(`div`,{className:`hq-flow-canvas`,"data-testid":`hq-react-flow-fleet`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`hq-btn secondary hq-flow-arrange`,onClick:l,title:`Re-run the hierarchical layout and frame the whole fleet`,children:[(0,K.jsx)(F,{size:13}),` Auto arrange`]}),(0,K.jsxs)(yp,{nodes:t,edges:i,nodeTypes:dg,onNodesChange:r,onEdgesChange:o,onNodeDragStop:()=>{c.current=!0},fitView:!0,fitViewOptions:{padding:.18},minZoom:.25,maxZoom:1.4,nodesDraggable:!0,nodesConnectable:!1,elementsSelectable:!0,onNodeClick:(e,t)=>{let n=Wh(t.data);n!==null&&(n.agentId===null?Ue(n.sessionId):We(n.sessionId,n.agentId),d(n))},children:[(0,K.jsx)(Op,{color:`rgba(148, 163, 184, 0.16)`,gap:22}),(0,K.jsx)(Qp,{pannable:!0,zoomable:!0,className:`hq-flow-minimap`,nodeColor:e=>{let t=e.data?.kind;return t===`machine`?`hsl(190 86% 54%)`:t===`project`?`hsl(258 84% 74%)`:t===`terminal`?`hsl(38 94% 58%)`:`hsl(150 64% 46%)`}}),(0,K.jsx)(Lp,{className:`hq-flow-controls`})]}),u!==null&&(0,K.jsx)(Gh,{target:u,onClose:()=>d(null)})]})}function hg(){let e=Ve([`snapshot`,`selectedSessionId`]).snapshot,t=(0,G.useMemo)(()=>ig(e),[e]);if(e===null)return(0,K.jsx)(`div`,{className:`hq-empty`,children:`Waiting for fleet data…`});if(t.nodes.length===0)return(0,K.jsx)(`div`,{className:`hq-empty`,children:`No machines or connected clients yet. Open a WrongStack CLI/TUI/WebUI with HQ running and they appear here automatically.`});let n=e.machines?.length??new Set(t.nodes.map(e=>e.machineId).filter(Boolean)).size,r=t.nodes.filter(e=>e.kind===`terminal`).length,i=t.nodes.filter(e=>e.kind===`agent`).length,a=t.nodes.filter(e=>e.kind===`agent`&&lg(e.status)).length;return(0,K.jsxs)(`div`,{className:`hq-flow-shell`,children:[(0,K.jsxs)(`div`,{className:`hq-flow-toolbar`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`hq-card-title`,style:{margin:0},children:`Fleet Topology`}),(0,K.jsx)(`div`,{className:`hq-row-subtle`,children:`machine → project → terminal/TUI/CLI/WebUI → agent; click a terminal or agent for chat history`})]}),(0,K.jsxs)(`div`,{className:`hq-flow-stats`,children:[(0,K.jsxs)(`span`,{className:`hq-pill info`,children:[n,` machines`]}),(0,K.jsxs)(`span`,{className:`hq-pill info`,children:[r,` terminals`]}),(0,K.jsx)(`span`,{className:`hq-pill ${a>0?`active`:`info`}`,children:a>0?`${a}/${i} agents live`:`${i} agents`})]})]}),(0,K.jsx)(hp,{children:(0,K.jsx)(mg,{topology:t})}),(0,K.jsxs)(`div`,{className:`hq-flow-legend`,children:[(0,K.jsxs)(`span`,{children:[(0,K.jsx)(ie,{size:12}),` machine`]}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(o,{size:12}),` project`]}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(l,{size:12}),` terminal / TUI / CLI / WebUI`]}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(oe,{size:12}),` branch shown as chip when known`]}),(0,K.jsxs)(`span`,{children:[(0,K.jsx)(w,{size:12}),` AMK agent`]})]})]})}function gg(e){let t=ig(e),n=[],r=new Map,i=new Map,a=new Map,o=e=>`machine:${e.machineId}`,s=e=>`project:${e.machineId}:${e.projectId}`;for(let e of t.nodes){if(e.kind!==`machine`)continue;let t={id:e.id,label:e.label,sub:e.sub,projects:[]};r.set(e.id,t),n.push(t)}for(let e of t.nodes){if(e.kind!==`project`)continue;let t=r.get(o(e));if(t===void 0)continue;let n={id:e.id,label:e.label,clients:[]};i.set(e.id,n),t.projects.push(n)}for(let e of t.nodes){if(e.kind!==`terminal`||e.sessionId===void 0)continue;let t=i.get(s(e));if(t===void 0)continue;let n={sessionId:e.sessionId,label:e.label,clientKind:e.clientKind,status:e.status,synthetic:e.isSyntheticSession===!0,agents:[]};a.set(e.sessionId,n),t.clients.push(n)}for(let e of t.nodes){if(e.kind!==`agent`||e.sessionId===void 0||e.agentId===void 0)continue;let t=a.get(e.sessionId);t!==void 0&&t.agents.push({id:e.agentId,label:e.label,status:e.status})}return n.map(e=>({...e,projects:e.projects.filter(e=>e.clients.length>0)})).filter(e=>e.projects.length>0)}function _g(e){return e===`active`||e===`running`||e===`streaming`?`active`:e===`waiting_user`?`warn`:e===`error`||e===`stale`||e===`closing`?`error`:`idle`}function vg({snapshot:e,selectedSessionId:t,selectedAgentId:n}){let r=(0,G.useMemo)(()=>gg(e),[e]),[i,a]=(0,G.useState)(new Set),s=e=>a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return r.length===0?(0,K.jsx)(`div`,{className:`hq-fleetnav`,children:(0,K.jsx)(`div`,{className:`hq-empty`,style:{padding:16,fontSize:12},children:`No live sessions. Open a WrongStack CLI/TUI/WebUI connected to HQ.`})}):(0,K.jsx)(`div`,{className:`hq-fleetnav`,role:`tree`,"aria-label":`Fleet navigator`,children:r.map(e=>{let r=!i.has(e.id);return(0,K.jsxs)(`div`,{className:`hq-nav-machine`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`hq-nav-row machine`,onClick:()=>s(e.id),"aria-expanded":r,children:[(0,K.jsx)(m,{size:12,className:`hq-nav-caret`+(r?` open`:``)}),(0,K.jsx)(ie,{size:13}),(0,K.jsx)(`span`,{className:`hq-nav-label`,title:e.sub??e.label,children:e.label})]}),r&&e.projects.map(e=>{let r=!i.has(e.id);return(0,K.jsxs)(`div`,{className:`hq-nav-project`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`hq-nav-row project`,onClick:()=>s(e.id),"aria-expanded":r,children:[(0,K.jsx)(m,{size:12,className:`hq-nav-caret`+(r?` open`:``)}),(0,K.jsx)(o,{size:13}),(0,K.jsx)(`span`,{className:`hq-nav-label`,title:e.label,children:e.label})]}),r&&e.clients.map(e=>{let r=!i.has(e.sessionId),a=t===e.sessionId&&n===null;return(0,K.jsxs)(`div`,{className:`hq-nav-client`,children:[(0,K.jsxs)(`div`,{className:`hq-nav-clientrow`,children:[e.agents.length>0?(0,K.jsx)(`button`,{type:`button`,className:`hq-nav-caretbtn`,onClick:()=>s(e.sessionId),"aria-label":r?`Collapse`:`Expand`,children:(0,K.jsx)(m,{size:12,className:`hq-nav-caret`+(r?` open`:``)})}):(0,K.jsx)(`span`,{className:`hq-nav-caretbtn`}),(0,K.jsxs)(`button`,{type:`button`,className:`hq-nav-row client`+(a?` selected`:``),onClick:()=>Ue(e.sessionId),title:e.synthetic?`waiting for session telemetry`:e.label,children:[(0,K.jsx)(`span`,{className:`hq-nav-dot `+_g(e.status)}),(0,K.jsx)(l,{size:12}),(0,K.jsx)(`span`,{className:`hq-nav-label`,children:e.label}),e.agents.length>0&&(0,K.jsx)(`span`,{className:`hq-nav-count`,children:e.agents.length})]})]}),r&&e.agents.map(r=>(0,K.jsxs)(`button`,{type:`button`,className:`hq-nav-row agent`+(t===e.sessionId&&n===r.id?` selected`:``),onClick:()=>We(e.sessionId,r.id),title:r.label,children:[(0,K.jsx)(`span`,{className:`hq-nav-dot `+_g(r.status)}),(0,K.jsx)(w,{size:12}),(0,K.jsx)(`span`,{className:`hq-nav-label`,children:r.label})]},r.id))]},e.sessionId)})]},e.id)})]},e.id)})})}function yg(){let e=Ve([`selectedSessionId`,`selectedAgentId`,`snapshot`]),t=e.selectedSessionId,n=e.selectedAgentId,r=n!==null,i=$m(t,n),{entries:a,meta:o,stats:s}=i,c=e.snapshot?.liveSessions??[],l=(0,G.useMemo)(()=>c.flatMap(e=>e.agents).find(e=>e.id===n)??null,[n,c]);return(0,K.jsxs)(`div`,{className:`hq-console-shell`,children:[(0,K.jsx)(vg,{snapshot:e.snapshot??null,selectedSessionId:t,selectedAgentId:n}),(0,K.jsxs)(`div`,{className:`hq-console`,children:[(0,K.jsxs)(`div`,{className:`hq-chat-header`,children:[(0,K.jsx)(N,{size:15,className:`hq-chat-header-icon`}),(0,K.jsx)(`span`,{className:`hq-card-title`,style:{margin:0},children:`Console`}),r&&(0,K.jsxs)(`span`,{className:`hq-pill active`,children:[(0,K.jsx)(w,{size:12}),` `,l?.name??n]}),o.projectName!==void 0&&!r&&(0,K.jsx)(`span`,{className:`hq-pill`,children:o.projectName}),o.source!==void 0&&(0,K.jsx)(`span`,{className:`hq-pill`,title:o.source===`disk`?`disk = full history replayed from this machine`:`stream = live ring only (remote or not yet persisted)`,children:o.source===`disk`?`full history`:`live ring`}),(0,K.jsxs)(`span`,{className:`hq-chat-counts`,children:[(0,K.jsxs)(`span`,{className:`hq-pill`,children:[s.turns,` turns`]}),(0,K.jsxs)(`span`,{className:`hq-pill`,children:[s.tools,` tools`]}),s.running>0&&(0,K.jsxs)(`span`,{className:`hq-pill running`,children:[s.running,` running`]}),s.errors>0&&(0,K.jsxs)(`span`,{className:`hq-pill error`,children:[s.errors,` err`]}),!r&&!i.full&&o.total>a.length&&(0,K.jsxs)(`button`,{type:`button`,className:`hq-btn secondary hq-chat-fullbtn`,onClick:()=>i.setFull(!0),title:`History is truncated — load all ${o.total} turns`,children:[(0,K.jsx)(k,{size:12}),` load all `,o.total]})]})]}),t===null?(0,K.jsx)(`div`,{className:`hq-empty`,children:`Pick a client or agent from the tree on the left.`}):i.loading&&a.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:r?`Loading agent history…`:`Loading transcript…`}):i.error===null?(0,K.jsxs)(`div`,{className:`hq-chat-scroll`,children:[a.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:r?`No messages from ${l?.name??n??`this agent`} yet.`:`No transcript entries yet.`}):(0,K.jsx)(Hm,{ref:i.listRef,onScroll:i.onScroll,className:`hq-chat-vlist`,children:a.map((e,t)=>(0,K.jsx)(`div`,{className:`hq-chat-rowpad`,children:(0,K.jsx)(Hh,{entry:e,running:i.isRunningAt(e,t)})},Xm(e,t)))}),!i.pinned&&a.length>0&&(0,K.jsx)(`button`,{type:`button`,className:`hq-chat-jump`,onClick:i.jumpToLatest,title:`Jump to latest`,children:(0,K.jsx)(u,{size:14})})]}):(0,K.jsxs)(`div`,{className:`hq-empty`,children:[`Error: `,i.error]})]})]})}var bg=[{value:`steer`,label:`steer — redirect the current work`},{value:`btw`,label:`btw — FYI, no action required`},{value:`queue`,label:`queue — note for the next agent`},{value:`broadcast`,label:`broadcast — all agents in the project`}];function xg({projects:e,sender:t}){let n=t??Je,[r,i]=(0,G.useState)(!1),[a,o]=(0,G.useState)(``),[s,c]=(0,G.useState)(`steer`),[l,u]=(0,G.useState)(`leader`),[d,f]=(0,G.useState)(`normal`),[p,m]=(0,G.useState)(``),[h,g]=(0,G.useState)(``),[_,v]=(0,G.useState)({phase:`idle`}),y=a||e[0]?.projectId||``,b=_.phase!==`sending`&&h.trim().length>0&&y.length>0,x=async()=>{if(b){v({phase:`sending`});try{v({phase:`sent`,messageId:(await n({projectId:y,type:s,...s===`broadcast`?{}:{to:l.trim()||`leader`},subject:p.trim()||`HQ prompt`,body:h.trim(),priority:d})).messageId}),g(``)}catch(e){v({phase:`error`,message:e instanceof Error?e.message:String(e)})}}};return r?(0,K.jsxs)(`div`,{className:`hq-card hq-composer`,children:[(0,K.jsxs)(`div`,{className:`hq-row`,style:{alignItems:`baseline`},children:[(0,K.jsx)(`span`,{className:`hq-card-title`,style:{margin:0},children:`Send to project mailbox`}),(0,K.jsx)(`span`,{className:`hq-composer-hint`,children:`lands in the mailbox file — picked up by the next agent, no live client needed`}),(0,K.jsx)(`button`,{type:`button`,className:`hq-toggle`,style:{marginLeft:`auto`},"aria-label":`Collapse composer`,onClick:()=>i(!1),children:`▾`})]}),(0,K.jsxs)(`div`,{className:`hq-composer-grid`,children:[(0,K.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,K.jsx)(`span`,{children:`project`}),(0,K.jsx)(`select`,{className:`hq-select`,value:y,onChange:e=>o(e.target.value),children:e.map(e=>(0,K.jsx)(`option`,{value:e.projectId,children:e.label??e.projectId},e.projectId))})]}),(0,K.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,K.jsx)(`span`,{children:`type`}),(0,K.jsx)(`select`,{className:`hq-select`,value:s,onChange:e=>c(e.target.value),children:bg.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),s!==`broadcast`&&(0,K.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,K.jsx)(`span`,{children:`to`}),(0,K.jsx)(`input`,{className:`hq-input`,value:l,placeholder:`leader`,onChange:e=>u(e.target.value)})]}),(0,K.jsxs)(`label`,{className:`hq-composer-field`,children:[(0,K.jsx)(`span`,{children:`priority`}),(0,K.jsxs)(`select`,{className:`hq-select`,value:d,onChange:e=>f(e.target.value),children:[(0,K.jsx)(`option`,{value:`high`,children:`high`}),(0,K.jsx)(`option`,{value:`normal`,children:`normal`}),(0,K.jsx)(`option`,{value:`low`,children:`low`})]})]})]}),(0,K.jsx)(`input`,{className:`hq-input`,value:p,placeholder:`subject (optional)`,onChange:e=>m(e.target.value)}),(0,K.jsx)(`textarea`,{className:`hq-input hq-composer-body`,value:h,rows:3,placeholder:`Message body — e.g. “after the current task, run the full test suite”`,onChange:e=>g(e.target.value)}),(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:!b,onClick:()=>void x(),children:_.phase===`sending`?`Sending…`:`Send`}),_.phase===`sent`&&(0,K.jsxs)(`span`,{className:`hq-composer-status ok`,children:[`delivered`,_.messageId===void 0?``:` · ${_.messageId.slice(0,8)}`]}),_.phase===`error`&&(0,K.jsx)(`span`,{className:`hq-composer-status err`,title:_.message,children:_.message})]})]}):(0,K.jsxs)(`div`,{className:`hq-composer-bar`,children:[(0,K.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:e.length===0,title:e.length===0?`No projects reported yet — connect a client first`:`Write a message into a project mailbox (works with zero connected agents)`,onClick:()=>i(!0),children:`✉️ Compose`}),_.phase===`sent`&&(0,K.jsxs)(`span`,{className:`hq-composer-status ok`,children:[`delivered`,_.messageId===void 0?``:` · ${_.messageId.slice(0,8)}`]})]})}function Sg(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.mailboxId==`string`&&(t.scope===`project`||t.scope===`global`)&&Array.isArray(t.messages)&&Array.isArray(t.agents)&&typeof t.totals==`object`&&t.totals!==null}function Cg(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.mailboxId==`string`&&typeof t.action==`string`&&(t.message===void 0||typeof t.message==`object`)}function wg(e,t){let n=e.get(t);return n===void 0&&(n={projectId:t,messages:[],countersFromSnapshot:!1,onlineAgentCount:0,highPriorityCount:0,unreadCount:0,incompleteCount:0},e.set(t,n)),n}function Tg(e){let t=0,n=0,r=0;for(let i of e){let e=i.message;e.priority===`high`&&(t+=1),e.completed||(r+=1,(e.readCount??0)===0&&(n+=1))}return{highPriorityCount:t,unreadCount:n,incompleteCount:r}}function Eg(e){let t=new Map;for(let n of e)(t.get(n.message.mailId)===void 0||n.source===`event`)&&t.set(n.message.mailId,n);return Array.from(t.values()).sort((e,t)=>t.message.timestamp.localeCompare(e.message.timestamp))}function Dg(e,t){let n=new Map;if(e!==null)for(let t of e.mailboxes){let e=wg(n,t.projectId);e.mailboxId=t.mailboxId,e.scope=t.scope,e.onlineAgentCount=t.onlineAgentCount,e.highPriorityCount=t.highPriorityCount,e.unreadCount=t.unreadCount,e.incompleteCount=t.incompleteCount,e.countersFromSnapshot=!0}for(let e of t){if(e.type!==`mailbox.snapshot`||!Sg(e.payload))continue;let t=e.payload,r=wg(n,e.projectId);r.mailboxId=t.mailboxId,r.scope=t.scope;for(let n of t.messages)r.messages.push({message:n,source:`snapshot`,key:`s:${e.id}:${n.messageId}`,projectId:e.projectId})}let r=new Map;for(let e of t){if(e.type!==`mailbox.event`||!Cg(e.payload))continue;let t=e.payload,i=wg(n,e.projectId);i.mailboxId=t.mailboxId,i.scope=i.scope??`project`,t.message!==void 0&&!r.has(t.message.mailId)&&(r.set(t.message.mailId,i),i.messages.push({message:t.message,source:`event`,key:`e:${t.message.mailId}:${e.seq}`,projectId:e.projectId})),t.agent?.online&&(i.onlineAgentCount+=1)}for(let e of n.values())if(e.messages=Eg(e.messages),!e.countersFromSnapshot){let t=Tg(e.messages);e.highPriorityCount=t.highPriorityCount,e.unreadCount=t.unreadCount,e.incompleteCount=t.incompleteCount}let i=Array.from(n.values()).sort((e,t)=>{let n=e.messages[0]?.message.timestamp??``;return(t.messages[0]?.message.timestamp??``).localeCompare(n)});return{projects:i,hasAnyActivity:i.some(e=>e.messages.length>0)}}var Og=Object.freeze({types:new Set,priorities:new Set,projectIds:new Set,includeCompleted:!0,query:``});function kg(e,t){switch(t.type){case`toggle-type`:{let n=new Set(e.types);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,types:n}}case`toggle-priority`:{let n=new Set(e.priorities);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,priorities:n}}case`toggle-project`:{let n=new Set(e.projectIds);return n.has(t.value)?n.delete(t.value):n.add(t.value),{...e,projectIds:n}}case`set-query`:return{...e,query:t.value};case`set-include-completed`:return{...e,includeCompleted:t.value};case`clear-all`:return Og;default:return e}}function Ag(e,t={}){let n=t.includeCompleted??!0,r=t.types&&t.types.length>0?new Set(t.types):null,i=t.priorities&&t.priorities.length>0?new Set(t.priorities):null,a=t.projectIds&&t.projectIds.length>0?new Set(t.projectIds):null,o=t.query?.trim().toLowerCase()??``,s=t.limit??500,c=[];for(let t of e){let e=t.message;!n&&e.completed||r&&!r.has(e.type)||i&&!i.has(e.priority)||a||o.length>0&&!`${e.subject}\n${e.from}\n${e.to}\n${e.bodyPreview??``}`.toLowerCase().includes(o)||c.push({key:t.key,flat:t})}c.sort((e,t)=>{let n=t.flat.message.timestamp.localeCompare(e.flat.message.timestamp);return n===0?e.flat.message.mailId.localeCompare(t.flat.message.mailId):n});let l=c.length,u=l>s,d=u?c.slice(0,s):c;return{totalMatched:l,returned:d.length,truncated:u,entries:d}}function jg(e,t,n={}){let{projectIds:r,...i}=n,a=Dg(e,t),o=[],s=r!==void 0&&r.length>0?new Set(r):null;for(let e of a.projects)s&&!s.has(e.projectId)||(o=o.concat(e.messages));return Ag(o,i)}function Mg(e){if(typeof e!=`object`||!e)return!1;let t=e;if(typeof t.error==`string`)return!0;if(typeof t.error!=`object`||t.error===null)return!1;let n=t.error;return typeof n.code==`string`&&typeof n.message==`string`}async function Ng(e){let t=await Te(`/api/mailbox/messages/${encodeURIComponent(e.mailId)}/action`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(t.status===401&&Ke(),!t.ok){let e=`${t.status} ${t.statusText}`;try{let n=await t.json();Mg(n)&&(e=typeof n.error==`string`?n.error:`${n.error.code}: ${n.error.message}`)}catch{}throw Error(`mailbox action failed — ${e}`)}return await t.json()}var Pg={markRead:e=>Ng({...e,action:`mark-read`}),acknowledge:e=>Ng({...e,action:`acknowledge`}),reopen:e=>Ng({...e,action:`reopen`}),softDelete:e=>Ng({...e,action:`soft-delete`}),restore:e=>Ng({...e,action:`restore`})};function Fg({mailId:e,actorId:t,projectId:n,isDeleted:r=!1,onAction:i,disabled:a=!1}){let[o,s]=(0,G.useState)(null),[c,l]=(0,G.useState)(null),u=async(t,n)=>{if(!(a||o!==null)){s(t),l(null);try{await n(),i?.(e,t)}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(null)}}},d={mailId:e,readerId:t,projectId:n};return(0,K.jsxs)(`div`,{className:`hq-msg-actions`,children:[!r&&(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`mark-read`,()=>Pg.markRead(d)),children:o===`mark-read`?`…`:`Mark read`}),!r&&(0,K.jsx)(`button`,{type:`button`,className:`hq-btn`,disabled:a||o!==null,onClick:()=>u(`acknowledge`,()=>Pg.acknowledge(d)),children:o===`acknowledge`?`…`:`Acknowledge`}),!r&&(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`reopen`,()=>Pg.reopen(d)),children:o===`reopen`?`…`:`Reopen`}),!r&&(0,K.jsx)(`button`,{type:`button`,className:`hq-btn danger`,disabled:a||o!==null,onClick:()=>u(`soft-delete`,()=>Pg.softDelete(d)),children:o===`soft-delete`?`…`:`Delete`}),r&&(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:a||o!==null,onClick:()=>u(`restore`,()=>Pg.restore(d)),children:o===`restore`?`…`:`Restore`}),c!==null&&(0,K.jsx)(`span`,{className:`hq-msg-action-error`,title:c,children:c})]})}function Ig(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Lg(e){return e.length<=14?e:`${e.slice(0,8)}…${e.slice(-4)}`}var Rg={note:{icon:`📝`,tone:`info`},ask:{icon:`❓`,tone:`warn`},assign:{icon:`📌`,tone:`warn`},steer:{icon:`🛞`,tone:`warn`},btw:{icon:`💬`,tone:`info`},broadcast:{icon:`📣`,tone:`info`},status:{icon:`📊`,tone:`idle`},result:{icon:`✅`,tone:`running`},review:{icon:`🔍`,tone:`info`},control:{icon:`⚙️`,tone:`error`}};Object.keys(Rg);var zg=`hq-operator`;function Bg({flat:e,defaultExpanded:t}){let[n,r]=(0,G.useState)(!!t),i=e.message,a=i.hasBody||i.bodyPreview!==void 0&&i.bodyPreview.length>0,o=Rg[i.type]??{icon:`✉️`,tone:`info`},s=`${i.from} → ${i.to}`;return(0,K.jsxs)(`div`,{className:`hq-msg`+(i.completed?` done`:``),children:[(0,K.jsxs)(`div`,{className:`hq-msg-head`,onClick:()=>a&&r(e=>!e),children:[(0,K.jsx)(`span`,{className:`hq-msg-icon`,title:i.type,children:o.icon}),(0,K.jsx)(`span`,{className:`hq-pill `+o.tone,children:i.type}),i.priority===`high`&&(0,K.jsx)(`span`,{className:`hq-pill error`,children:`high`}),i.priority===`low`&&(0,K.jsx)(`span`,{className:`hq-pill idle`,children:`low`}),(0,K.jsx)(`span`,{className:`hq-msg-subject`,title:i.subject,children:i.subject||`(no subject)`}),(0,K.jsx)(`span`,{className:`hq-mono hq-msg-route`,children:s}),(0,K.jsx)(`span`,{className:`hq-mono hq-msg-time`,title:i.timestamp,children:Ig(i.timestamp)}),(0,K.jsx)(`span`,{className:`hq-mono hq-msg-id`,children:Lg(i.messageId)}),(0,K.jsx)(`span`,{className:`hq-msg-flag `+(i.completed?`done`:`open`),children:i.completed?`completed${i.completedBy===void 0?``:` by ${i.completedBy}`}`:`open`}),a&&(0,K.jsx)(`button`,{type:`button`,className:`hq-toggle hq-msg-toggle`,onClick:e=>{e.stopPropagation(),r(e=>!e)},"aria-label":n?`Collapse body`:`Expand body`,children:n?`▾`:`▸`})]}),n&&(0,K.jsxs)(`div`,{className:`hq-msg-body`,children:[i.bodyPreview!==void 0&&i.bodyPreview.length>0?(0,K.jsx)(`pre`,{className:`hq-msg-pre`,children:i.bodyPreview}):(0,K.jsx)(`div`,{className:`hq-empty`,style:{padding:8,fontSize:12},children:`(empty body)`}),i.outcomePreview!==void 0&&i.outcomePreview.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`hq-msg-sublabel`,children:`outcome`}),(0,K.jsx)(`pre`,{className:`hq-msg-pre`,children:i.outcomePreview})]}),(0,K.jsxs)(`div`,{className:`hq-msg-meta`,children:[(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`source:`}),` `,e.source]}),i.replyTo!==void 0&&(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`reply to:`}),` `,Lg(i.replyTo)]}),i.senderSessionId!==void 0&&(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`sender session:`}),` `,Lg(i.senderSessionId)]}),(i.readCount??0)>0&&(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`reads:`}),` `,i.readCount]}),i.unreadCount!==void 0&&i.unreadCount>0&&(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`unread:`}),` `,i.unreadCount]}),i.task!==void 0&&(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`strong`,{children:`task:`}),` `,i.task.taskId??`—`,i.task.agentName===void 0?``:` · ${i.task.agentName}`,i.task.status===void 0?``:` (${i.task.status})`]})]}),e.projectId!==void 0&&(0,K.jsx)(Fg,{mailId:i.mailId,actorId:zg,projectId:e.projectId})]})]})}var Vg=[`ask`,`assign`,`steer`,`review`,`result`,`status`,`broadcast`,`note`,`btw`,`control`],Hg=[`high`,`normal`,`low`];function Ug({snapshot:e,events:t}={}){let n=Ve([`snapshot`,`events`]),r=e===void 0?n.snapshot:e,i=t===void 0?n.events:t,a=vt(),[o,s]=(0,G.useReducer)(kg,(0,G.useMemo)(()=>{let e=a.mailbox;return{types:new Set(e.types),priorities:new Set(e.priorities),projectIds:new Set,includeCompleted:e.includeCompleted,query:e.query}},[a.mailbox]));(0,G.useEffect)(()=>{bt({query:o.query,types:Array.from(o.types),priorities:Array.from(o.priorities),includeCompleted:o.includeCompleted})},[o.query,o.types,o.priorities,o.includeCompleted]);let c=(0,G.useMemo)(()=>Dg(r??null,i).projects.map(e=>({projectId:e.projectId,count:e.messages.length})),[r,i]),l=(0,G.useMemo)(()=>jg(r??null,i,{types:Array.from(o.types),priorities:Array.from(o.priorities),projectIds:Array.from(o.projectIds),includeCompleted:o.includeCompleted,query:o.query||void 0,limit:500}),[r,i,o]),u=o.types.size+o.priorities.size+o.projectIds.size+ +!o.includeCompleted+ +(o.query.trim().length>0);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`hq-card-title`,children:[`Live mailbox feed · `,l.returned,` of `,l.totalMatched,` message`,l.totalMatched===1?``:`s`,l.truncated?` · refined to fit`:``]}),(0,K.jsxs)(`div`,{className:`hq-card hq-mailbox-filterbar`,children:[(0,K.jsx)(`label`,{className:`hq-label`,htmlFor:`mailbox-live-query`,children:`Search`}),(0,K.jsx)(`input`,{id:`mailbox-live-query`,className:`hq-input`,value:o.query,onChange:e=>s({type:`set-query`,value:e.target.value}),placeholder:`subject / sender / recipient / body…`}),(0,K.jsx)(Wg,{title:`Types`,children:Vg.map(e=>(0,K.jsx)(Gg,{selected:o.types.has(e),label:e,onClick:()=>s({type:`toggle-type`,value:e})},e))}),(0,K.jsx)(Wg,{title:`Priority`,children:Hg.map(e=>(0,K.jsx)(Gg,{selected:o.priorities.has(e),label:e,tone:e===`high`?`error`:e===`low`?`idle`:`info`,onClick:()=>s({type:`toggle-priority`,value:e})},e))}),c.length>0&&(0,K.jsx)(Wg,{title:`Projects`,children:c.map(e=>(0,K.jsx)(Gg,{selected:o.projectIds.has(e.projectId),label:`${e.projectId} (${e.count})`,onClick:()=>s({type:`toggle-project`,value:e.projectId})},e.projectId))}),(0,K.jsxs)(`div`,{className:`hq-row hq-mailbox-filter-actions`,children:[(0,K.jsxs)(`label`,{className:`hq-check`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:o.includeCompleted,onChange:e=>s({type:`set-include-completed`,value:e.target.checked})}),`include completed`]}),(0,K.jsxs)(`button`,{type:`button`,className:`hq-btn secondary`,disabled:u===0,onClick:()=>s({type:`clear-all`}),children:[`Clear filters`,u>0?` (${u})`:``]})]})]}),l.entries.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:`No mailbox activity matches the current filters.`}):(0,K.jsx)(`div`,{className:`hq-msg-list hq-live-feed`,children:l.entries.map((e,t)=>(0,K.jsx)(Bg,{flat:e.flat,defaultExpanded:t===0&&o.query.trim().length>0},e.key))})]})}function Wg({title:e,children:t}){return(0,K.jsxs)(`div`,{className:`hq-filter-section`,children:[(0,K.jsx)(`div`,{className:`hq-msg-sublabel`,children:e}),(0,K.jsx)(`div`,{className:`hq-filter-chip-row`,children:t})]})}function Gg({selected:e,label:t,onClick:n,tone:r=`info`}){return(0,K.jsx)(`button`,{type:`button`,className:`hq-filter-chip hq-pill ${r}${e?` selected`:``}`,"aria-pressed":e,onClick:n,children:t})}function Kg(){let e=Ve([`snapshot`,`events`]),t=e.snapshot,[n,r]=(0,G.useState)(`live`),{events:i}=Ze(`mailbox.event`,300),a=(0,G.useMemo)(()=>[...i,...e.events.filter(e=>e.type!==`mailbox.event`)],[i,e.events]),{projects:o,hasAnyActivity:s}=(0,G.useMemo)(()=>Dg(t,a),[t,a]),c=t?.totals.unreadMailboxMessages??0,l=t?.totals.incompleteMailboxMessages??0,u=(0,G.useMemo)(()=>{let e=new Map;for(let n of t?.projects??[])e.set(n.projectId,{projectId:n.projectId,label:n.projectName});for(let t of o)e.has(t.projectId)||e.set(t.projectId,{projectId:t.projectId});return Array.from(e.values())},[t,o]);return o.length===0&&u.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:`No mailbox activity reported by connected clients.`}):(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`hq-card-title`,children:[`Mailbox Activity — `,o.length,` project`,o.length===1?``:`s`,` ·`,` `,c,` unread · `,l,` incomplete`,s?` · showing detailed messages`:``]}),(0,K.jsx)(xg,{projects:u}),(0,K.jsxs)(`div`,{className:`hq-mailbox-modebar`,role:`tablist`,"aria-label":`Mailbox view mode`,children:[(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`+(n===`live`?` hq-btn-selected`:``),"aria-selected":n===`live`,onClick:()=>r(`live`),children:`Live feed`}),(0,K.jsx)(`button`,{type:`button`,className:`hq-btn secondary`+(n===`grouped`?` hq-btn-selected`:``),"aria-selected":n===`grouped`,onClick:()=>r(`grouped`),children:`Grouped by project`})]}),n===`live`?(0,K.jsx)(Ug,{snapshot:t,events:a}):o.map(e=>(0,K.jsx)(qg,{group:e},e.projectId))]})}function qg({group:e}){let[t,n]=(0,G.useState)(!0);return(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsxs)(`div`,{className:`hq-row`,style:{alignItems:`baseline`},children:[(0,K.jsx)(`button`,{type:`button`,className:`hq-toggle`,onClick:()=>n(e=>!e),"aria-label":t?`Collapse project messages`:`Expand project messages`,children:t?`▾`:`▸`}),(0,K.jsx)(`span`,{style:{fontWeight:700},children:e.projectId}),e.scope!==void 0&&(0,K.jsx)(`span`,{className:`hq-pill info`,children:e.scope}),e.mailboxId!==void 0&&(0,K.jsx)(`span`,{className:`hq-mono`,style:{color:`var(--dim)`},children:e.mailboxId}),(0,K.jsxs)(`span`,{className:`hq-mono`,style:{color:`var(--dim)`,marginLeft:`auto`},children:[e.messages.length,` message`,e.messages.length===1?``:`s`]})]}),(0,K.jsxs)(`div`,{className:`hq-grid`,style:{gridTemplateColumns:`repeat(5,1fr)`,marginTop:8},children:[(0,K.jsx)(Jg,{label:`messages`,value:e.messages.length}),(0,K.jsx)(Jg,{label:`unread`,value:e.unreadCount,accent:e.unreadCount>0?`amber`:void 0}),(0,K.jsx)(Jg,{label:`incomplete`,value:e.incompleteCount,accent:e.incompleteCount>0?`red`:void 0}),(0,K.jsx)(Jg,{label:`high-priority`,value:e.highPriorityCount,accent:e.highPriorityCount>0?`red`:void 0}),(0,K.jsx)(Jg,{label:`online agents`,value:e.onlineAgentCount,accent:e.onlineAgentCount>0?`green`:void 0})]}),t&&e.messages.length>0&&(0,K.jsx)(`div`,{className:`hq-msg-list`,style:{marginTop:12},children:e.messages.map(e=>(0,K.jsx)(Bg,{flat:e},e.key))}),t&&e.messages.length===0&&(0,K.jsx)(`div`,{className:`hq-empty`,style:{padding:16,fontSize:12},children:`Snapshot counters reported for this project, but no detailed mailbox events have streamed yet.`})]})}function Jg({label:e,value:t,accent:n}){return(0,K.jsxs)(`div`,{style:{textAlign:`center`},children:[(0,K.jsx)(`div`,{className:`hq-stat-num`,style:{color:n===`amber`?`var(--amber)`:n===`red`?`var(--red)`:n===`green`?`var(--green)`:`var(--text)`},children:t}),(0,K.jsx)(`div`,{className:`hq-stat-label`,children:e})]})}function Yg({hadToken:e}){let[t,n]=(0,G.useState)(``),r=()=>{let e=t.trim();e.length!==0&&(xe(e),window.location.reload())};return(0,K.jsx)(`div`,{className:`hq-token-gate`,children:(0,K.jsxs)(`div`,{className:`hq-token-card`,children:[(0,K.jsx)(`div`,{className:`hq-brand`,children:`WrongStack HQ`}),(0,K.jsx)(`div`,{className:`hq-token-title`,children:`Browser token required`}),(0,K.jsx)(`p`,{className:`hq-token-text`,children:e?`The saved token was rejected — it may have been revoked or the server was reset. Paste a current browser token.`:`This HQ server runs in token mode. Paste the browser token printed at startup (the ?token= value in the URL wstack --hq shows).`}),(0,K.jsx)(`input`,{className:`hq-token-input`,type:`password`,autoFocus:!0,placeholder:`browser token`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&r()}}),(0,K.jsx)(`button`,{className:`hq-token-submit`,onClick:r,disabled:t.trim().length===0,children:`Connect`}),(0,K.jsxs)(`p`,{className:`hq-token-hint`,children:[`Manage tokens with `,(0,K.jsx)(`code`,{children:`wstack hq token list`}),` / `,(0,K.jsx)(`code`,{children:`wstack hq token create`}),` `,`— they live in `,(0,K.jsx)(`code`,{children:`~/.wrongstack/hq/auth.json`}),`.`]})]})})}function Xg({points:e,color:t,height:n=140,format:r,emptyLabel:i=`no data`}){let[a,o]=(0,G.useState)(null),s=(0,G.useId)(),c=n,l=c-10-22,u=(0,G.useMemo)(()=>Math.max(...e.map(e=>e.value),0),[e]);if(e.length===0||u<=0)return(0,K.jsx)(`div`,{className:`hq-chart-empty`,children:i});let d=e.length,f=666/d,p=Math.max(2,Math.min(18,f-2)),m=e=>10+l*(1-e/u),h=[u*.25,u*.5,u*.75,u],g=Math.max(1,Math.round(d/5)),_=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),v=a===null?void 0:e[a];return(0,K.jsxs)(`div`,{className:`hq-chart`,children:[(0,K.jsxs)(`svg`,{viewBox:`0 0 720 ${c}`,className:`hq-chart-svg`,role:`img`,onMouseLeave:()=>o(null),children:[(0,K.jsx)(`clipPath`,{id:s,children:(0,K.jsx)(`rect`,{x:46,y:10,width:666,height:l})}),h.map((e,t)=>(0,K.jsxs)(`g`,{children:[(0,K.jsx)(`line`,{x1:46,x2:712,y1:m(e),y2:m(e),className:`hq-chart-grid`}),(0,K.jsx)(`text`,{x:40,y:m(e)+3,className:`hq-chart-ytick`,textAnchor:`end`,children:r(e)})]},t)),(0,K.jsx)(`line`,{x1:46,x2:712,y1:10+l,y2:10+l,className:`hq-chart-axis`}),(0,K.jsx)(`g`,{clipPath:`url(#${s})`,children:e.map((e,n)=>{let r=46+n*f+(f-p)/2,i=m(e.value),o=10+l-i;return o<=0?null:(0,K.jsx)(`rect`,{x:r,y:i,width:p,height:o,rx:Math.min(3,p/2),fill:t,opacity:a===null||a===n?1:.45},n)})}),e.map((e,t)=>t%g===0?(0,K.jsx)(`text`,{x:46+t*f+f/2,y:c-6,className:`hq-chart-xtick`,textAnchor:`middle`,children:_(e.ts)},t):null),e.map((e,t)=>(0,K.jsx)(`rect`,{x:46+t*f,y:10,width:f,height:l,fill:`transparent`,onMouseEnter:()=>o(t)},t))]}),v!==void 0&&(0,K.jsxs)(`div`,{className:`hq-chart-tooltip`,children:[(0,K.jsx)(`span`,{className:`hq-chart-tooltip-swatch`,style:{background:t}}),(0,K.jsx)(`span`,{className:`hq-chart-tooltip-value`,children:r(v.value)}),(0,K.jsx)(`span`,{className:`hq-chart-tooltip-time`,children:_(v.ts)})]})]})}var Zg=[{label:`1h`,ms:3600*1e3},{label:`6h`,ms:360*60*1e3},{label:`24h`,ms:1440*60*1e3},{label:`7d`,ms:10080*60*1e3}];function Qg(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(Math.round(e))}function $g(){let[e,t]=(0,G.useState)([]),[n,r]=(0,G.useState)(null),[i,a]=(0,G.useState)(Zg[2].ms);if((0,G.useEffect)(()=>{let e=!1,n=()=>{qe(`/api/trends/cost`).then(n=>{e||(t(n.samples),r(null))}).catch(t=>{e||r(t.message)})};n();let i=setInterval(n,3e4);return()=>{e=!0,clearInterval(i)}},[]),n!==null)return(0,K.jsxs)(`div`,{className:`hq-empty`,children:[`Error loading trends: `,n]});if(e.length===0)return(0,K.jsx)(`div`,{className:`hq-empty`,children:`No trend data yet. Trends accumulate as cost signals arrive.`});let o=Date.now()-i,s=e.filter(e=>e.ts>=o),c=s.length>0?s:e.slice(-24),l=c.reduce((e,t)=>e+t.costUsd,0),u=c.reduce((e,t)=>e+t.inputTokens+t.outputTokens,0),d=c.reduce((e,t)=>e+t.toolCalls,0);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`hq-filter-row`,children:[Zg.map(e=>(0,K.jsx)(`button`,{type:`button`,className:`hq-pill hq-filter-chip${i===e.ms?` selected`:``}`,onClick:()=>a(e.ms),children:e.label},e.label)),(0,K.jsxs)(`span`,{className:`hq-mono hq-row-subtle`,style:{marginLeft:`auto`},children:[c.length,` × 5-min buckets`]})]}),(0,K.jsxs)(`div`,{className:`hq-kpi-row`,children:[(0,K.jsxs)(`div`,{className:`hq-kpi`,children:[(0,K.jsxs)(`span`,{className:`hq-kpi-value accent-cost`,children:[`$`,l.toFixed(4)]}),(0,K.jsx)(`span`,{className:`hq-kpi-label`,children:`cost`})]}),(0,K.jsxs)(`div`,{className:`hq-kpi`,children:[(0,K.jsx)(`span`,{className:`hq-kpi-value`,children:Qg(u)}),(0,K.jsx)(`span`,{className:`hq-kpi-label`,children:`tokens`})]}),(0,K.jsxs)(`div`,{className:`hq-kpi`,children:[(0,K.jsx)(`span`,{className:`hq-kpi-value`,children:d.toLocaleString()}),(0,K.jsx)(`span`,{className:`hq-kpi-label`,children:`tool calls`})]})]}),(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsx)(`div`,{className:`hq-card-title`,children:`Cost (USD)`}),(0,K.jsx)(Xg,{points:c.map(e=>({ts:e.ts,value:e.costUsd})),color:`var(--chart-1)`,format:e=>`$${e>=1?e.toFixed(2):e.toFixed(4)}`})]}),(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsx)(`div`,{className:`hq-card-title`,children:`Tokens (in + out)`}),(0,K.jsx)(Xg,{points:c.map(e=>({ts:e.ts,value:e.inputTokens+e.outputTokens})),color:`var(--chart-2)`,format:Qg})]}),(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsx)(`div`,{className:`hq-card-title`,children:`Tool calls`}),(0,K.jsx)(Xg,{points:c.map(e=>({ts:e.ts,value:e.toolCalls})),color:`var(--chart-3)`,format:e=>String(Math.round(e))})]})]})}var e_={allocated:{Icon:B,cls:`info`},committed:{Icon:le,cls:`active`},merged:{Icon:x,cls:`active`},conflict:{Icon:T,cls:`warn`},released:{Icon:L,cls:`idle`},failed:{Icon:E,cls:`error`}};function t_({e}){let t=e.payload,n=e_[t.kind]??{Icon:B,cls:`info`};return(0,K.jsxs)(`div`,{className:`hq-row`,children:[(0,K.jsx)(n.Icon,{size:14,className:`hq-kind-icon ${n.cls}`}),(0,K.jsx)(`span`,{style:{fontWeight:700},children:t.kind}),t.branch!==void 0&&(0,K.jsx)(`span`,{className:`hq-pill info`,children:t.branch}),t.kind===`committed`&&(0,K.jsxs)(`span`,{className:`hq-mono hq-diffstat`,children:[(0,K.jsxs)(`span`,{className:`hq-diff-add-count`,children:[`+`,t.insertions??0]}),` `,(0,K.jsxs)(`span`,{className:`hq-diff-del-count`,children:[`−`,t.deletions??0]}),` in `,t.files??0,` file(s)`,` `,t.sha===void 0?``:`(${t.sha.slice(0,7)})`]}),t.kind===`conflict`&&t.conflictFiles!==void 0&&(0,K.jsxs)(`span`,{className:`hq-mono hq-row-error`,children:[`conflicts: `,t.conflictFiles.join(`, `)]}),t.kind===`failed`&&(0,K.jsx)(`span`,{className:`hq-mono hq-row-error`,children:t.error}),(0,K.jsx)(`span`,{className:`hq-mono hq-row-time`,children:new Date(e.timestamp).toLocaleTimeString()})]})}function n_(){let{events:e,loading:t}=Ze(`worktree.event`,300),n=(0,G.useMemo)(()=>{let t=new Map;for(let n of e){let e=n.payload.ownerId??`(unknown)`,r=t.get(e)??[];r.push(n),t.set(e,r)}return Array.from(t.entries()).reverse()},[e]);return n.length===0?(0,K.jsx)(`div`,{className:`hq-empty`,children:t?`Loading worktree history…`:`No worktree events yet. These appear when AutoPhase allocates/merges git worktrees for parallel phases.`}):(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`hq-card-title`,children:[`Worktree Lifecycle (`,n.length,` worktree`,n.length===1?``:`s`,`)`]}),n.map(([e,t])=>{let n=t[t.length-1].payload,r=e_[n.kind]??{Icon:B,cls:`info`};return(0,K.jsxs)(`div`,{className:`hq-card`,children:[(0,K.jsxs)(`div`,{className:`hq-row hq-lane-head`,children:[(0,K.jsx)(`span`,{className:`hq-mono`,style:{fontWeight:700},children:e}),(0,K.jsx)(`span`,{className:`hq-pill ${r.cls}`,children:n.kind}),(0,K.jsxs)(`span`,{className:`hq-mono hq-row-time`,children:[t.length,` events`]})]}),t.map(e=>(0,K.jsx)(t_,{e},e.id))]},e)})]})}var r_=[{id:`cockpit`,label:`Cockpit`,icon:`🛰`},{id:`fleet`,label:`Fleet`,icon:`🖥`},{id:`console`,label:`Console`,icon:`💬`},{id:`mailbox`,label:`Mailbox`,icon:`📬`},{id:`cost`,label:`Cost`,icon:`💰`},{id:`brain`,label:`Brain`,icon:`🧠`},{id:`worktree`,label:`Worktrees`,icon:`🌿`},{id:`trends`,label:`Trends`,icon:`📈`},{id:`alerts`,label:`Alerts`,icon:`🔔`},{id:`control`,label:`Control`,icon:`⚡`}];function i_(){let e=Ve([`snapshot`,`alerts`,`activeView`,`authRequired`]);if((0,G.useEffect)(()=>{qe(`/api/snapshot`).catch(()=>{})},[]),e.authRequired)return(0,K.jsx)(Yg,{hadToken:Se()!==null});let t=e.snapshot?.totals,n=t?.unreadMailboxMessages??0,r=e.alerts.filter(e=>e.severity!==`info`).length;return(0,K.jsxs)(`div`,{className:`hq-app`,children:[(0,K.jsxs)(`header`,{className:`hq-header`,children:[(0,K.jsx)(`div`,{className:`hq-brand`,children:`WrongStack HQ`}),(0,K.jsx)(`span`,{className:`hq-ui-badge`,title:`Served from @wrongstack/webui-hq/dist`,children:`built webui-hq`}),(0,K.jsx)(`div`,{className:`hq-led`,"data-live":e.connected}),(0,K.jsx)(`span`,{className:`hq-conn`,children:e.connected?`connected`:`reconnecting…`}),(0,K.jsxs)(`div`,{className:`hq-stats`,children:[(0,K.jsx)(a_,{label:`machines`,value:t?.activeMachines??0}),(0,K.jsx)(a_,{label:`clients`,value:t?.activeClients??0}),(0,K.jsx)(a_,{label:`sessions`,value:t?.activeSessions??0}),(0,K.jsx)(a_,{label:`agents`,value:t?.activeAgents??0}),(0,K.jsx)(a_,{label:`cost $`,value:(t?.totalCostUsd??0).toFixed(2),accent:`green`})]})]}),(0,K.jsx)(`nav`,{className:`hq-nav`,children:r_.map(t=>(0,K.jsxs)(`button`,{className:`hq-tab`+(e.activeView===t.id?` active`:``),onClick:()=>He(t.id),children:[(0,K.jsx)(`span`,{className:`hq-tab-icon`,children:t.icon}),(0,K.jsx)(`span`,{className:`hq-tab-label`,children:t.label}),t.id===`mailbox`&&n>0?(0,K.jsx)(`span`,{className:`hq-badge`,children:n}):null,t.id===`alerts`&&r>0?(0,K.jsx)(`span`,{className:`hq-badge red`,children:r}):null]},t.id))}),(0,K.jsxs)(`main`,{className:`hq-main`,children:[e.activeView===`cockpit`&&(0,K.jsx)(et,{}),e.activeView===`fleet`&&(0,K.jsx)(hg,{}),e.activeView===`console`&&(0,K.jsx)(yg,{}),e.activeView===`mailbox`&&(0,K.jsx)(Kg,{}),e.activeView===`cost`&&(0,K.jsx)(Ot,{}),e.activeView===`brain`&&(0,K.jsx)($e,{}),e.activeView===`worktree`&&(0,K.jsx)(n_,{}),e.activeView===`trends`&&(0,K.jsx)($g,{}),e.activeView===`alerts`&&(0,K.jsx)(Xe,{}),e.activeView===`control`&&(0,K.jsx)(St,{})]})]})}function a_({label:e,value:t,accent:n}){return(0,K.jsxs)(`div`,{className:`hq-stat`+(n?` ${n}`:``),children:[(0,K.jsx)(`span`,{className:`hq-stat-num`,children:t}),(0,K.jsx)(`span`,{className:`hq-stat-label`,children:e})]})}var o_=document.getElementById(`root`);o_!==null&&(Ce(),je(),(0,ge.createRoot)(o_).render((0,K.jsx)(G.StrictMode,{children:(0,K.jsx)(i_,{})})));
|