@agentdocumentformat/cli 0.8.2 → 0.8.4
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 +55 -4
- package/dist/adf.mjs +16 -13
- package/dist/chunks/{App-4AZZJNN2.mjs → App-XOPHZTGN.mjs} +515 -349
- package/dist/chunks/{auth-manager-TBNKCJ45.mjs → auth-manager-2YHTYI3C.mjs} +2 -1
- package/dist/chunks/{build-QF5W473T.mjs → build-BFOCXM5S.mjs} +1 -1
- package/dist/chunks/{chunk-RHBGCOS3.mjs → chunk-22ZGZFOV.mjs} +5 -16
- package/dist/chunks/chunk-26RK7T5L.mjs +20 -0
- package/dist/chunks/{chunk-KCIRFUZH.mjs → chunk-2WIFHJV2.mjs} +2 -2
- package/dist/chunks/{chunk-D7A77SNL.mjs → chunk-3FWPIWYM.mjs} +1 -1
- package/dist/chunks/chunk-4T745GJA.mjs +431 -0
- package/dist/chunks/{chunk-7JZXMDDF.mjs → chunk-7ADDKFT5.mjs} +105 -31
- package/dist/chunks/chunk-A53XYNJL.mjs +26 -0
- package/dist/chunks/{chunk-MZRXFWPQ.mjs → chunk-AN6USKYQ.mjs} +40 -8
- package/dist/chunks/{chunk-2Z7X3UUR.mjs → chunk-DHO5Z6HP.mjs} +14 -12
- package/dist/chunks/{chunk-F5ELW46V.mjs → chunk-GJYMGPH4.mjs} +1 -0
- package/dist/chunks/chunk-HONGRUAE.mjs +175 -0
- package/dist/chunks/{chunk-AEAJDCVK.mjs → chunk-IM5JKLXO.mjs} +1 -1
- package/dist/chunks/chunk-J2N63ZUD.mjs +12 -0
- package/dist/chunks/{chunk-IMVMSU3A.mjs → chunk-JK6K2BMV.mjs} +12 -38
- package/dist/chunks/{chunk-75DC5EWN.mjs → chunk-KBXC5EHK.mjs} +1 -0
- package/dist/chunks/chunk-NRTRTR7C.mjs +43 -0
- package/dist/chunks/{chunk-BS3USVEA.mjs → chunk-P4G5ZEBI.mjs} +1 -1
- package/dist/chunks/{chunk-E7LC6SHP.mjs → chunk-RIAB37IS.mjs} +4 -2
- package/dist/chunks/{chunk-LVF2DRBR.mjs → chunk-TBMQOM7Y.mjs} +247 -610
- package/dist/chunks/{chunk-SOSPQPEN.mjs → chunk-TDRQG5UO.mjs} +1 -162
- package/dist/chunks/{chunk-RJDOVMM4.mjs → chunk-TPA2ITKV.mjs} +49 -33
- package/dist/chunks/{chunk-BHY7QDCM.mjs → chunk-UBWWGUMU.mjs} +1 -0
- package/dist/chunks/{chunk-3AT7IIP7.mjs → chunk-WZ6S3SQP.mjs} +1 -1
- package/dist/chunks/chunk-X6R32YVE.mjs +43 -0
- package/dist/chunks/chunk-XJWGENZ5.mjs +5903 -0
- package/dist/chunks/{chunk-F3WSCAJD.mjs → chunk-XP4U4A2W.mjs} +1 -1
- package/dist/chunks/chunk-XS46KYYY.mjs +31 -0
- package/dist/chunks/{chunk-HBOFZRUS.mjs → chunk-XZQVDY3U.mjs} +9 -1
- package/dist/chunks/chunk-ZECGH3LT.mjs +88 -0
- package/dist/chunks/{claude-subscription-EB4LAAVV.mjs → claude-subscription-42L4YM5L.mjs} +4 -3
- package/dist/chunks/{cli-PCVFB6B4.mjs → cli-JPRYEY4J.mjs} +53 -13
- package/dist/chunks/{commands-KOMPXJZS.mjs → commands-TZW2FSXG.mjs} +5 -2
- package/dist/chunks/context-AZOIJOUG.mjs +5933 -0
- package/dist/chunks/{daemon-HEQ3FUYH.mjs → daemon-DK3KUDZJ.mjs} +3571 -6806
- package/dist/chunks/{daemon-control-MKN7G5M3.mjs → daemon-control-U4OGCAAJ.mjs} +4 -4
- package/dist/chunks/{devtools-H7CI2ZVG.mjs → devtools-AUZWFIPL.mjs} +1 -1
- package/dist/chunks/firewall-service-7RGJN4LD.mjs +163 -0
- package/dist/chunks/{open-3OR6WT4T.mjs → open-T3VGLWGF.mjs} +6 -5
- package/dist/chunks/{pipeline-executor-DRYEEFDR.mjs → pipeline-executor-MHRI7ODL.mjs} +6 -3
- package/dist/chunks/{remote-access-cli-GLEEP7DI.mjs → remote-access-cli-EFVCXFOY.mjs} +22 -6
- package/dist/chunks/{store-55CQSAOX.mjs → store-37YHXFJ6.mjs} +4 -3
- package/dist/chunks/{tui-RAUVFOYY.mjs → tui-NJKGFAKU.mjs} +12 -11
- package/dist/chunks/web-F4XHDGUX.mjs +149 -0
- package/dist/chunks/{whatsapp-YJFFVN4Q.mjs → whatsapp-J7PX7TKT.mjs} +1 -1
- package/package.json +4 -3
- package/web/assets/EditorPanel-5ZGWvexa.js +161 -0
- package/web/assets/MeshGraphView-BZV40eAE.css +1 -0
- package/web/assets/MeshGraphView-Vp2R5TLK.js +23 -0
- package/web/assets/SettingsPage-_uHkBERV.js +6 -0
- package/web/assets/agent-window-B8X7FV4_.js +3 -0
- package/web/assets/agent.store-BHweGGTh.js +1 -0
- package/web/assets/app.store-j_-OuVPe.js +1 -0
- package/web/assets/core-DVezgdzc.js +12 -0
- package/web/assets/css-Z72CF80r.js +1 -0
- package/web/assets/diff-D97Zzqfu.js +1 -0
- package/web/assets/document.store-CMD3_OM0.js +1 -0
- package/web/assets/edit-recovery-Ce8tPQZl.js +3 -0
- package/web/assets/engine-javascript-CuxHA8oH.js +141 -0
- package/web/assets/github-dark-dimmed-DH5Ifo-i.js +1 -0
- package/web/assets/github-light-DAi9KRSo.js +1 -0
- package/web/assets/go-C27-OAKa.js +1 -0
- package/web/assets/html-BlS82ilI.js +1 -0
- package/web/assets/index-B5Eot_tL.js +1 -0
- package/web/assets/index-B5FYMbFc.js +3 -0
- package/web/assets/index-BQIEMvvt.js +2 -0
- package/web/assets/index-C_gf4L3q.js +1 -0
- package/web/assets/index-Ca6bEWGu.js +1 -0
- package/web/assets/index-CuTaWSEs.css +1 -0
- package/web/assets/index-DBFkrLao.js +1 -0
- package/web/assets/index-DF1leTEa.js +11 -0
- package/web/assets/index-DS9H-PJI.js +1 -0
- package/web/assets/index-DkhbLs9K.js +6 -0
- package/web/assets/index-KNnHrO8-.js +13 -0
- package/web/assets/index-nM_Q5x7Q.js +1 -0
- package/web/assets/inter-tight-cyrillic-ext-wght-italic-BJqtfpQe.woff2 +0 -0
- package/web/assets/inter-tight-cyrillic-ext-wght-normal-okcGN4Nq.woff2 +0 -0
- package/web/assets/inter-tight-cyrillic-wght-italic-HmhN1gQv.woff2 +0 -0
- package/web/assets/inter-tight-cyrillic-wght-normal-BS41q_Tv.woff2 +0 -0
- package/web/assets/inter-tight-greek-ext-wght-italic-B_3RbJza.woff2 +0 -0
- package/web/assets/inter-tight-greek-ext-wght-normal-DQgQPNk4.woff2 +0 -0
- package/web/assets/inter-tight-greek-wght-italic-Bb1BGCmL.woff2 +0 -0
- package/web/assets/inter-tight-greek-wght-normal-sS1B39LI.woff2 +0 -0
- package/web/assets/inter-tight-latin-ext-wght-italic-DYqsmiDd.woff2 +0 -0
- package/web/assets/inter-tight-latin-ext-wght-normal-B4u9PlvR.woff2 +0 -0
- package/web/assets/inter-tight-latin-wght-italic-DiXukCDG.woff2 +0 -0
- package/web/assets/inter-tight-latin-wght-normal-DX-nOvPD.woff2 +0 -0
- package/web/assets/inter-tight-vietnamese-wght-italic-CiVF0Juh.woff2 +0 -0
- package/web/assets/inter-tight-vietnamese-wght-normal-TKKdAiBA.woff2 +0 -0
- package/web/assets/javascript-wDzz0qaB.js +1 -0
- package/web/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/web/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/web/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/web/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/web/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/web/assets/json-Cp-IABpG.js +1 -0
- package/web/assets/jsx-g9-lgVsj.js +1 -0
- package/web/assets/main-Zf3qnQYd.css +1 -0
- package/web/assets/main-o2ocfqUC.js +319 -0
- package/web/assets/markdown-Cvjx9yec.js +1 -0
- package/web/assets/message-queue.store-ke_rFZAb.js +2 -0
- package/web/assets/module-RjUF93sV.js +716 -0
- package/web/assets/native-48B9X9Wg.js +1 -0
- package/web/assets/orbital-render.worker-BovOTauk.js +1 -0
- package/web/assets/python-B6aJPvgy.js +1 -0
- package/web/assets/react-D-F9gHrJ.js +1 -0
- package/web/assets/rust-DPvrY3IQ.js +1 -0
- package/web/assets/shellscript-Yzrsuije.js +1 -0
- package/web/assets/sql-DkvoVjww.js +1 -0
- package/web/assets/stix-two-text-cyrillic-wght-italic-BzL1BdzR.woff2 +0 -0
- package/web/assets/stix-two-text-cyrillic-wght-normal-CcrOj1MU.woff2 +0 -0
- package/web/assets/stix-two-text-greek-wght-italic-glgrbyRu.woff2 +0 -0
- package/web/assets/stix-two-text-greek-wght-normal-DAdwyhkq.woff2 +0 -0
- package/web/assets/stix-two-text-latin-ext-wght-italic--XhV508b.woff2 +0 -0
- package/web/assets/stix-two-text-latin-ext-wght-normal-BUpo8gM0.woff2 +0 -0
- package/web/assets/stix-two-text-latin-wght-italic-BDl6bBME.woff2 +0 -0
- package/web/assets/stix-two-text-latin-wght-normal-BTZaHlTl.woff2 +0 -0
- package/web/assets/stix-two-text-vietnamese-wght-italic-B1jFRJrJ.woff2 +0 -0
- package/web/assets/stix-two-text-vietnamese-wght-normal-CfS0RdBA.woff2 +0 -0
- package/web/assets/tsx-COt5Ahok.js +1 -0
- package/web/assets/typescript-BPQ3VLAy.js +1 -0
- package/web/assets/window-kind-mxlpdE1l.js +1 -0
- package/web/assets/with-selector-Ot-ZoUn0.js +1 -0
- package/web/assets/yaml-Buea-lGh.js +1 -0
- package/web/index.html +15 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import{R as Ol,a as k,j as s}from"./index-DF1leTEa.js";import{u as ld}from"./with-selector-Ot-ZoUn0.js";import{bc as pe,bd as J,be as Ps,bf as qe,bg as cd,bh as Wo,bi as Fl,bj as ln,bk as ud,aI as mt,bl as zl,aE as ye,bm as ve,w as Je,aH as Ct,bn as qo,bo as _t,bp as Vo,bq as dd,br as fd,bs as hd,bt as pd,bu as dr,bv as xd,bw as gd,bx as Hl,by as md,bz as za,bA as ca,bB as bd,e as yd,bC as wd,bD as vd,bE as kd,bF as wo,bG as Nd,bH as at,bI as Ha,aF as jd,aG as Sd,bJ as Bl,bK as Md,bL as $d,bM as Ed,aR as Cd,bN as rr,bO as _d,bP as as,bQ as Pd,bR as Ad,bS as Id,bT as Td,bU as Rd,bV as Dd,bW as Ld,bX as Od,T as Wl,bY as Fd,at as zd,bZ as Hd,b_ as Bd,b$ as Wd,c0 as qd,c1 as Ba,c2 as is}from"./main-o2ocfqUC.js";import{b as ua,a as As,s as Vd,u as Xd,o as Wa,c as Yd}from"./agent-window-B8X7FV4_.js";import{b as ql,u as gn}from"./app.store-j_-OuVPe.js";import{useDocumentStore as Vl}from"./document.store-CMD3_OM0.js";import{r as ls,d as Gd,b as Ud,c as Kd}from"./window-kind-mxlpdE1l.js";import{i as kn,p as pr,a as da}from"./message-queue.store-ke_rFZAb.js";import{M as qa}from"./agent.store-BHweGGTh.js";import"./edit-recovery-Ce8tPQZl.js";import"./react-D-F9gHrJ.js";function Ie(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=Ie(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var Zd={value:()=>{}};function Is(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new cs(n)}function cs(e){this._=e}function Qd(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",o=n.indexOf(".");if(o>=0&&(r=n.slice(o+1),n=n.slice(0,o)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}cs.prototype=Is.prototype={constructor:cs,on:function(e,t){var n=this._,r=Qd(e+"",n),o,a=-1,i=r.length;if(arguments.length<2){for(;++a<i;)if((o=(e=r[a]).type)&&(o=Jd(n[o],e.name)))return o;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++a<i;)if(o=(e=r[a]).type)n[o]=Va(n[o],e.name,t);else if(t==null)for(o in n)n[o]=Va(n[o],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new cs(e)},call:function(e,t){if((o=arguments.length-2)>0)for(var n=new Array(o),r=0,o,a;r<o;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(a=this._[e],r=0,o=a.length;r<o;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],o=0,a=r.length;o<a;++o)r[o].value.apply(t,n)}};function Jd(e,t){for(var n=0,r=e.length,o;n<r;++n)if((o=e[n]).name===t)return o.value}function Va(e,t,n){for(var r=0,o=e.length;r<o;++r)if(e[r].name===t){e[r]=Zd,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var Xo="http://www.w3.org/1999/xhtml";const Xa={svg:"http://www.w3.org/2000/svg",xhtml:Xo,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Ts(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Xa.hasOwnProperty(t)?{space:Xa[t],local:e}:e}function ef(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===Xo&&t.documentElement.namespaceURI===Xo?t.createElement(e):t.createElementNS(n,e)}}function tf(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Xl(e){var t=Ts(e);return(t.local?tf:ef)(t)}function nf(){}function fa(e){return e==null?nf:function(){return this.querySelector(e)}}function rf(e){typeof e!="function"&&(e=fa(e));for(var t=this._groups,n=t.length,r=new Array(n),o=0;o<n;++o)for(var a=t[o],i=a.length,l=r[o]=new Array(i),d,c,u=0;u<i;++u)(d=a[u])&&(c=e.call(d,d.__data__,u,a))&&("__data__"in d&&(c.__data__=d.__data__),l[u]=c);return new nt(r,this._parents)}function sf(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function of(){return[]}function Yl(e){return e==null?of:function(){return this.querySelectorAll(e)}}function af(e){return function(){return sf(e.apply(this,arguments))}}function lf(e){typeof e=="function"?e=af(e):e=Yl(e);for(var t=this._groups,n=t.length,r=[],o=[],a=0;a<n;++a)for(var i=t[a],l=i.length,d,c=0;c<l;++c)(d=i[c])&&(r.push(e.call(d,d.__data__,c,i)),o.push(d));return new nt(r,o)}function Gl(e){return function(){return this.matches(e)}}function Ul(e){return function(t){return t.matches(e)}}var cf=Array.prototype.find;function uf(e){return function(){return cf.call(this.children,e)}}function df(){return this.firstElementChild}function ff(e){return this.select(e==null?df:uf(typeof e=="function"?e:Ul(e)))}var hf=Array.prototype.filter;function pf(){return Array.from(this.children)}function xf(e){return function(){return hf.call(this.children,e)}}function gf(e){return this.selectAll(e==null?pf:xf(typeof e=="function"?e:Ul(e)))}function mf(e){typeof e!="function"&&(e=Gl(e));for(var t=this._groups,n=t.length,r=new Array(n),o=0;o<n;++o)for(var a=t[o],i=a.length,l=r[o]=[],d,c=0;c<i;++c)(d=a[c])&&e.call(d,d.__data__,c,a)&&l.push(d);return new nt(r,this._parents)}function Kl(e){return new Array(e.length)}function bf(){return new nt(this._enter||this._groups.map(Kl),this._parents)}function gs(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}gs.prototype={constructor:gs,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 yf(e){return function(){return e}}function wf(e,t,n,r,o,a){for(var i=0,l,d=t.length,c=a.length;i<c;++i)(l=t[i])?(l.__data__=a[i],r[i]=l):n[i]=new gs(e,a[i]);for(;i<d;++i)(l=t[i])&&(o[i]=l)}function vf(e,t,n,r,o,a,i){var l,d,c=new Map,u=t.length,h=a.length,f=new Array(u),m;for(l=0;l<u;++l)(d=t[l])&&(f[l]=m=i.call(d,d.__data__,l,t)+"",c.has(m)?o[l]=d:c.set(m,d));for(l=0;l<h;++l)m=i.call(e,a[l],l,a)+"",(d=c.get(m))?(r[l]=d,d.__data__=a[l],c.delete(m)):n[l]=new gs(e,a[l]);for(l=0;l<u;++l)(d=t[l])&&c.get(f[l])===d&&(o[l]=d)}function kf(e){return e.__data__}function Nf(e,t){if(!arguments.length)return Array.from(this,kf);var n=t?vf:wf,r=this._parents,o=this._groups;typeof e!="function"&&(e=yf(e));for(var a=o.length,i=new Array(a),l=new Array(a),d=new Array(a),c=0;c<a;++c){var u=r[c],h=o[c],f=h.length,m=jf(e.call(u,u&&u.__data__,c,r)),y=m.length,S=l[c]=new Array(y),x=i[c]=new Array(y),b=d[c]=new Array(f);n(u,h,S,x,b,m,t);for(var $=0,v=0,p,M;$<y;++$)if(p=S[$]){for($>=v&&(v=$+1);!(M=x[v])&&++v<y;);p._next=M||null}}return i=new nt(i,r),i._enter=l,i._exit=d,i}function jf(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Sf(){return new nt(this._exit||this._groups.map(Kl),this._parents)}function Mf(e,t,n){var r=this.enter(),o=this,a=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(o=t(o),o&&(o=o.selection())),n==null?a.remove():n(a),r&&o?r.merge(o).order():o}function $f(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,o=n.length,a=r.length,i=Math.min(o,a),l=new Array(o),d=0;d<i;++d)for(var c=n[d],u=r[d],h=c.length,f=l[d]=new Array(h),m,y=0;y<h;++y)(m=c[y]||u[y])&&(f[y]=m);for(;d<o;++d)l[d]=n[d];return new nt(l,this._parents)}function Ef(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],o=r.length-1,a=r[o],i;--o>=0;)(i=r[o])&&(a&&i.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(i,a),a=i);return this}function Cf(e){e||(e=_f);function t(h,f){return h&&f?e(h.__data__,f.__data__):!h-!f}for(var n=this._groups,r=n.length,o=new Array(r),a=0;a<r;++a){for(var i=n[a],l=i.length,d=o[a]=new Array(l),c,u=0;u<l;++u)(c=i[u])&&(d[u]=c);d.sort(t)}return new nt(o,this._parents).order()}function _f(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Pf(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Af(){return Array.from(this)}function If(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],o=0,a=r.length;o<a;++o){var i=r[o];if(i)return i}return null}function Tf(){let e=0;for(const t of this)++e;return e}function Rf(){return!this.node()}function Df(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var o=t[n],a=0,i=o.length,l;a<i;++a)(l=o[a])&&e.call(l,l.__data__,a,o);return this}function Lf(e){return function(){this.removeAttribute(e)}}function Of(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Ff(e,t){return function(){this.setAttribute(e,t)}}function zf(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Hf(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Bf(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 Wf(e,t){var n=Ts(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?Of:Lf:typeof t=="function"?n.local?Bf:Hf:n.local?zf:Ff)(n,t))}function Zl(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function qf(e){return function(){this.style.removeProperty(e)}}function Vf(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Xf(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function Yf(e,t,n){return arguments.length>1?this.each((t==null?qf:typeof t=="function"?Xf:Vf)(e,t,n??"")):Hn(this.node(),e)}function Hn(e,t){return e.style.getPropertyValue(t)||Zl(e).getComputedStyle(e,null).getPropertyValue(t)}function Gf(e){return function(){delete this[e]}}function Uf(e,t){return function(){this[e]=t}}function Kf(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Zf(e,t){return arguments.length>1?this.each((t==null?Gf:typeof t=="function"?Kf:Uf)(e,t)):this.node()[e]}function Ql(e){return e.trim().split(/^|\s+/)}function ha(e){return e.classList||new Jl(e)}function Jl(e){this._node=e,this._names=Ql(e.getAttribute("class")||"")}Jl.prototype={add:function(e){var t=this._names.indexOf(e);t<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 ec(e,t){for(var n=ha(e),r=-1,o=t.length;++r<o;)n.add(t[r])}function tc(e,t){for(var n=ha(e),r=-1,o=t.length;++r<o;)n.remove(t[r])}function Qf(e){return function(){ec(this,e)}}function Jf(e){return function(){tc(this,e)}}function eh(e,t){return function(){(t.apply(this,arguments)?ec:tc)(this,e)}}function th(e,t){var n=Ql(e+"");if(arguments.length<2){for(var r=ha(this.node()),o=-1,a=n.length;++o<a;)if(!r.contains(n[o]))return!1;return!0}return this.each((typeof t=="function"?eh:t?Qf:Jf)(n,t))}function nh(){this.textContent=""}function rh(e){return function(){this.textContent=e}}function sh(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function oh(e){return arguments.length?this.each(e==null?nh:(typeof e=="function"?sh:rh)(e)):this.node().textContent}function ah(){this.innerHTML=""}function ih(e){return function(){this.innerHTML=e}}function lh(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function ch(e){return arguments.length?this.each(e==null?ah:(typeof e=="function"?lh:ih)(e)):this.node().innerHTML}function uh(){this.nextSibling&&this.parentNode.appendChild(this)}function dh(){return this.each(uh)}function fh(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function hh(){return this.each(fh)}function ph(e){var t=typeof e=="function"?e:Xl(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function xh(){return null}function gh(e,t){var n=typeof e=="function"?e:Xl(e),r=t==null?xh:typeof t=="function"?t:fa(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function mh(){var e=this.parentNode;e&&e.removeChild(this)}function bh(){return this.each(mh)}function yh(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function wh(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function vh(e){return this.select(e?wh:yh)}function kh(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Nh(e){return function(t){e.call(this,t,this.__data__)}}function jh(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function Sh(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,o=t.length,a;n<o;++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 Mh(e,t,n){return function(){var r=this.__on,o,a=Nh(t);if(r){for(var i=0,l=r.length;i<l;++i)if((o=r[i]).type===e.type&&o.name===e.name){this.removeEventListener(o.type,o.listener,o.options),this.addEventListener(o.type,o.listener=a,o.options=n),o.value=t;return}}this.addEventListener(e.type,a,n),o={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(o):this.__on=[o]}}function $h(e,t,n){var r=jh(e+""),o,a=r.length,i;if(arguments.length<2){var l=this.node().__on;if(l){for(var d=0,c=l.length,u;d<c;++d)for(o=0,u=l[d];o<a;++o)if((i=r[o]).type===u.type&&i.name===u.name)return u.value}return}for(l=t?Mh:Sh,o=0;o<a;++o)this.each(l(r[o],t,n));return this}function nc(e,t,n){var r=Zl(e),o=r.CustomEvent;typeof o=="function"?o=new o(t,n):(o=r.document.createEvent("Event"),n?(o.initEvent(t,n.bubbles,n.cancelable),o.detail=n.detail):o.initEvent(t,!1,!1)),e.dispatchEvent(o)}function Eh(e,t){return function(){return nc(this,e,t)}}function Ch(e,t){return function(){return nc(this,e,t.apply(this,arguments))}}function _h(e,t){return this.each((typeof t=="function"?Ch:Eh)(e,t))}function*Ph(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],o=0,a=r.length,i;o<a;++o)(i=r[o])&&(yield i)}var rc=[null];function nt(e,t){this._groups=e,this._parents=t}function $r(){return new nt([[document.documentElement]],rc)}function Ah(){return this}nt.prototype=$r.prototype={constructor:nt,select:rf,selectAll:lf,selectChild:ff,selectChildren:gf,filter:mf,data:Nf,enter:bf,exit:Sf,join:Mf,merge:$f,selection:Ah,order:Ef,sort:Cf,call:Pf,nodes:Af,node:If,size:Tf,empty:Rf,each:Df,attr:Wf,style:Yf,property:Zf,classed:th,text:oh,html:ch,raise:dh,lower:hh,append:ph,insert:gh,remove:bh,clone:vh,datum:kh,on:$h,dispatch:_h,[Symbol.iterator]:Ph};function et(e){return typeof e=="string"?new nt([[document.querySelector(e)]],[document.documentElement]):new nt([[e]],rc)}function Ih(e){let t;for(;t=e.sourceEvent;)e=t;return e}function ht(e,t){if(e=Ih(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 o=t.getBoundingClientRect();return[e.clientX-o.left-t.clientLeft,e.clientY-o.top-t.clientTop]}}return[e.pageX,e.pageY]}const Th={passive:!1},xr={capture:!0,passive:!1};function vo(e){e.stopImmediatePropagation()}function Fn(e){e.preventDefault(),e.stopImmediatePropagation()}function sc(e){var t=e.document.documentElement,n=et(e).on("dragstart.drag",Fn,xr);"onselectstart"in t?n.on("selectstart.drag",Fn,xr):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function oc(e,t){var n=e.document.documentElement,r=et(e).on("dragstart.drag",null);t&&(r.on("click.drag",Fn,xr),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Yr=e=>()=>e;function Yo(e,{sourceEvent:t,subject:n,target:r,identifier:o,active:a,x:i,y:l,dx:d,dy:c,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:o,enumerable:!0,configurable:!0},active:{value:a,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:l,enumerable:!0,configurable:!0},dx:{value:d,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}Yo.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Rh(e){return!e.ctrlKey&&!e.button}function Dh(){return this.parentNode}function Lh(e,t){return t??{x:e.x,y:e.y}}function Oh(){return navigator.maxTouchPoints||"ontouchstart"in this}function ac(){var e=Rh,t=Dh,n=Lh,r=Oh,o={},a=Is("start","drag","end"),i=0,l,d,c,u,h=0;function f(p){p.on("mousedown.drag",m).filter(r).on("touchstart.drag",x).on("touchmove.drag",b,Th).on("touchend.drag touchcancel.drag",$).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function m(p,M){if(!(u||!e.call(this,p,M))){var N=v(this,t.call(this,p,M),p,M,"mouse");N&&(et(p.view).on("mousemove.drag",y,xr).on("mouseup.drag",S,xr),sc(p.view),vo(p),c=!1,l=p.clientX,d=p.clientY,N("start",p))}}function y(p){if(Fn(p),!c){var M=p.clientX-l,N=p.clientY-d;c=M*M+N*N>h}o.mouse("drag",p)}function S(p){et(p.view).on("mousemove.drag mouseup.drag",null),oc(p.view,c),Fn(p),o.mouse("end",p)}function x(p,M){if(e.call(this,p,M)){var N=p.changedTouches,w=t.call(this,p,M),g=N.length,E,T;for(E=0;E<g;++E)(T=v(this,w,p,M,N[E].identifier,N[E]))&&(vo(p),T("start",p,N[E]))}}function b(p){var M=p.changedTouches,N=M.length,w,g;for(w=0;w<N;++w)(g=o[M[w].identifier])&&(Fn(p),g("drag",p,M[w]))}function $(p){var M=p.changedTouches,N=M.length,w,g;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),w=0;w<N;++w)(g=o[M[w].identifier])&&(vo(p),g("end",p,M[w]))}function v(p,M,N,w,g,E){var T=a.copy(),j=ht(E||N,M),_,I,C;if((C=n.call(p,new Yo("beforestart",{sourceEvent:N,target:f,identifier:g,active:i,x:j[0],y:j[1],dx:0,dy:0,dispatch:T}),w))!=null)return _=C.x-j[0]||0,I=C.y-j[1]||0,function O(A,L,R){var F=j,W;switch(A){case"start":o[g]=O,W=i++;break;case"end":delete o[g],--i;case"drag":j=ht(R||L,M),W=i;break}T.call(A,p,new Yo(A,{sourceEvent:L,subject:C,target:f,identifier:g,active:W,x:j[0]+_,y:j[1]+I,dx:j[0]-F[0],dy:j[1]-F[1],dispatch:T}),w)}}return f.filter=function(p){return arguments.length?(e=typeof p=="function"?p:Yr(!!p),f):e},f.container=function(p){return arguments.length?(t=typeof p=="function"?p:Yr(p),f):t},f.subject=function(p){return arguments.length?(n=typeof p=="function"?p:Yr(p),f):n},f.touchable=function(p){return arguments.length?(r=typeof p=="function"?p:Yr(!!p),f):r},f.on=function(){var p=a.on.apply(a,arguments);return p===a?f:p},f.clickDistance=function(p){return arguments.length?(h=(p=+p)*p,f):Math.sqrt(h)},f}function pa(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function ic(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function Er(){}var gr=.7,ms=1/gr,zn="\\s*([+-]?\\d+)\\s*",mr="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Et="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Fh=/^#([0-9a-f]{3,8})$/,zh=new RegExp(`^rgb\\(${zn},${zn},${zn}\\)$`),Hh=new RegExp(`^rgb\\(${Et},${Et},${Et}\\)$`),Bh=new RegExp(`^rgba\\(${zn},${zn},${zn},${mr}\\)$`),Wh=new RegExp(`^rgba\\(${Et},${Et},${Et},${mr}\\)$`),qh=new RegExp(`^hsl\\(${mr},${Et},${Et}\\)$`),Vh=new RegExp(`^hsla\\(${mr},${Et},${Et},${mr}\\)$`),Ya={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};pa(Er,Nn,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Ga,formatHex:Ga,formatHex8:Xh,formatHsl:Yh,formatRgb:Ua,toString:Ua});function Ga(){return this.rgb().formatHex()}function Xh(){return this.rgb().formatHex8()}function Yh(){return lc(this).formatHsl()}function Ua(){return this.rgb().formatRgb()}function Nn(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=Fh.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Ka(t):n===3?new Ge(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Gr(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Gr(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=zh.exec(e))?new Ge(t[1],t[2],t[3],1):(t=Hh.exec(e))?new Ge(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Bh.exec(e))?Gr(t[1],t[2],t[3],t[4]):(t=Wh.exec(e))?Gr(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=qh.exec(e))?Ja(t[1],t[2]/100,t[3]/100,1):(t=Vh.exec(e))?Ja(t[1],t[2]/100,t[3]/100,t[4]):Ya.hasOwnProperty(e)?Ka(Ya[e]):e==="transparent"?new Ge(NaN,NaN,NaN,0):null}function Ka(e){return new Ge(e>>16&255,e>>8&255,e&255,1)}function Gr(e,t,n,r){return r<=0&&(e=t=n=NaN),new Ge(e,t,n,r)}function Gh(e){return e instanceof Er||(e=Nn(e)),e?(e=e.rgb(),new Ge(e.r,e.g,e.b,e.opacity)):new Ge}function Go(e,t,n,r){return arguments.length===1?Gh(e):new Ge(e,t,n,r??1)}function Ge(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}pa(Ge,Go,ic(Er,{brighter(e){return e=e==null?ms:Math.pow(ms,e),new Ge(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?gr:Math.pow(gr,e),new Ge(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ge(yn(this.r),yn(this.g),yn(this.b),bs(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:Za,formatHex:Za,formatHex8:Uh,formatRgb:Qa,toString:Qa}));function Za(){return`#${mn(this.r)}${mn(this.g)}${mn(this.b)}`}function Uh(){return`#${mn(this.r)}${mn(this.g)}${mn(this.b)}${mn((isNaN(this.opacity)?1:this.opacity)*255)}`}function Qa(){const e=bs(this.opacity);return`${e===1?"rgb(":"rgba("}${yn(this.r)}, ${yn(this.g)}, ${yn(this.b)}${e===1?")":`, ${e})`}`}function bs(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yn(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function mn(e){return e=yn(e),(e<16?"0":"")+e.toString(16)}function Ja(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new pt(e,t,n,r)}function lc(e){if(e instanceof pt)return new pt(e.h,e.s,e.l,e.opacity);if(e instanceof Er||(e=Nn(e)),!e)return new pt;if(e instanceof pt)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,o=Math.min(t,n,r),a=Math.max(t,n,r),i=NaN,l=a-o,d=(a+o)/2;return l?(t===a?i=(n-r)/l+(n<r)*6:n===a?i=(r-t)/l+2:i=(t-n)/l+4,l/=d<.5?a+o:2-a-o,i*=60):l=d>0&&d<1?0:i,new pt(i,l,d,e.opacity)}function Kh(e,t,n,r){return arguments.length===1?lc(e):new pt(e,t,n,r??1)}function pt(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}pa(pt,Kh,ic(Er,{brighter(e){return e=e==null?ms:Math.pow(ms,e),new pt(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?gr:Math.pow(gr,e),new pt(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,o=2*n-r;return new Ge(ko(e>=240?e-240:e+120,o,r),ko(e,o,r),ko(e<120?e+240:e-120,o,r),this.opacity)},clamp(){return new pt(ei(this.h),Ur(this.s),Ur(this.l),bs(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(){const e=bs(this.opacity);return`${e===1?"hsl(":"hsla("}${ei(this.h)}, ${Ur(this.s)*100}%, ${Ur(this.l)*100}%${e===1?")":`, ${e})`}`}}));function ei(e){return e=(e||0)%360,e<0?e+360:e}function Ur(e){return Math.max(0,Math.min(1,e||0))}function ko(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const xa=e=>()=>e;function Zh(e,t){return function(n){return e+n*t}}function Qh(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Jh(e){return(e=+e)==1?cc:function(t,n){return n-t?Qh(t,n,e):xa(isNaN(t)?n:t)}}function cc(e,t){var n=t-e;return n?Zh(e,n):xa(isNaN(e)?t:e)}const ys=(function e(t){var n=Jh(t);function r(o,a){var i=n((o=Go(o)).r,(a=Go(a)).r),l=n(o.g,a.g),d=n(o.b,a.b),c=cc(o.opacity,a.opacity);return function(u){return o.r=i(u),o.g=l(u),o.b=d(u),o.opacity=c(u),o+""}}return r.gamma=e,r})(1);function e0(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),o;return function(a){for(o=0;o<n;++o)r[o]=e[o]*(1-a)+t[o]*a;return r}}function t0(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function n0(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,o=new Array(r),a=new Array(n),i;for(i=0;i<r;++i)o[i]=fr(e[i],t[i]);for(;i<n;++i)a[i]=t[i];return function(l){for(i=0;i<r;++i)a[i]=o[i](l);return a}}function r0(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function St(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function s0(e,t){var n={},r={},o;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(o in t)o in e?n[o]=fr(e[o],t[o]):r[o]=t[o];return function(a){for(o in n)r[o]=n[o](a);return r}}var Uo=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,No=new RegExp(Uo.source,"g");function o0(e){return function(){return e}}function a0(e){return function(t){return e(t)+""}}function uc(e,t){var n=Uo.lastIndex=No.lastIndex=0,r,o,a,i=-1,l=[],d=[];for(e=e+"",t=t+"";(r=Uo.exec(e))&&(o=No.exec(t));)(a=o.index)>n&&(a=t.slice(n,a),l[i]?l[i]+=a:l[++i]=a),(r=r[0])===(o=o[0])?l[i]?l[i]+=o:l[++i]=o:(l[++i]=null,d.push({i,x:St(r,o)})),n=No.lastIndex;return n<t.length&&(a=t.slice(n),l[i]?l[i]+=a:l[++i]=a),l.length<2?d[0]?a0(d[0].x):o0(t):(t=d.length,function(c){for(var u=0,h;u<t;++u)l[(h=d[u]).i]=h.x(c);return l.join("")})}function fr(e,t){var n=typeof t,r;return t==null||n==="boolean"?xa(t):(n==="number"?St:n==="string"?(r=Nn(t))?(t=r,ys):uc:t instanceof Nn?ys:t instanceof Date?r0:t0(t)?e0:Array.isArray(t)?n0:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?s0:St)(e,t)}var ti=180/Math.PI,Ko={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function dc(e,t,n,r,o,a){var i,l,d;return(i=Math.sqrt(e*e+t*t))&&(e/=i,t/=i),(d=e*n+t*r)&&(n-=e*d,r-=t*d),(l=Math.sqrt(n*n+r*r))&&(n/=l,r/=l,d/=l),e*r<t*n&&(e=-e,t=-t,d=-d,i=-i),{translateX:o,translateY:a,rotate:Math.atan2(t,e)*ti,skewX:Math.atan(d)*ti,scaleX:i,scaleY:l}}var Kr;function i0(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Ko:dc(t.a,t.b,t.c,t.d,t.e,t.f)}function l0(e){return e==null||(Kr||(Kr=document.createElementNS("http://www.w3.org/2000/svg","g")),Kr.setAttribute("transform",e),!(e=Kr.transform.baseVal.consolidate()))?Ko:(e=e.matrix,dc(e.a,e.b,e.c,e.d,e.e,e.f))}function fc(e,t,n,r){function o(c){return c.length?c.pop()+" ":""}function a(c,u,h,f,m,y){if(c!==h||u!==f){var S=m.push("translate(",null,t,null,n);y.push({i:S-4,x:St(c,h)},{i:S-2,x:St(u,f)})}else(h||f)&&m.push("translate("+h+t+f+n)}function i(c,u,h,f){c!==u?(c-u>180?u+=360:u-c>180&&(c+=360),f.push({i:h.push(o(h)+"rotate(",null,r)-2,x:St(c,u)})):u&&h.push(o(h)+"rotate("+u+r)}function l(c,u,h,f){c!==u?f.push({i:h.push(o(h)+"skewX(",null,r)-2,x:St(c,u)}):u&&h.push(o(h)+"skewX("+u+r)}function d(c,u,h,f,m,y){if(c!==h||u!==f){var S=m.push(o(m)+"scale(",null,",",null,")");y.push({i:S-4,x:St(c,h)},{i:S-2,x:St(u,f)})}else(h!==1||f!==1)&&m.push(o(m)+"scale("+h+","+f+")")}return function(c,u){var h=[],f=[];return c=e(c),u=e(u),a(c.translateX,c.translateY,u.translateX,u.translateY,h,f),i(c.rotate,u.rotate,h,f),l(c.skewX,u.skewX,h,f),d(c.scaleX,c.scaleY,u.scaleX,u.scaleY,h,f),c=u=null,function(m){for(var y=-1,S=f.length,x;++y<S;)h[(x=f[y]).i]=x.x(m);return h.join("")}}}var c0=fc(i0,"px, ","px)","deg)"),u0=fc(l0,", ",")",")"),d0=1e-12;function ni(e){return((e=Math.exp(e))+1/e)/2}function f0(e){return((e=Math.exp(e))-1/e)/2}function h0(e){return((e=Math.exp(2*e))-1)/(e+1)}const us=(function e(t,n,r){function o(a,i){var l=a[0],d=a[1],c=a[2],u=i[0],h=i[1],f=i[2],m=u-l,y=h-d,S=m*m+y*y,x,b;if(S<d0)b=Math.log(f/c)/t,x=function(w){return[l+w*m,d+w*y,c*Math.exp(t*w*b)]};else{var $=Math.sqrt(S),v=(f*f-c*c+r*S)/(2*c*n*$),p=(f*f-c*c-r*S)/(2*f*n*$),M=Math.log(Math.sqrt(v*v+1)-v),N=Math.log(Math.sqrt(p*p+1)-p);b=(N-M)/t,x=function(w){var g=w*b,E=ni(M),T=c/(n*$)*(E*h0(t*g+M)-f0(M));return[l+T*m,d+T*y,c*E/ni(t*g+M)]}}return x.duration=b*1e3*t/Math.SQRT2,x}return o.rho=function(a){var i=Math.max(.001,+a),l=i*i,d=l*l;return e(i,l,d)},o})(Math.SQRT2,2,4);var Bn=0,ir=0,sr=0,hc=1e3,ws,lr,vs=0,jn=0,Rs=0,br=typeof performance=="object"&&performance.now?performance:Date,pc=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function ga(){return jn||(pc(p0),jn=br.now()+Rs)}function p0(){jn=0}function ks(){this._call=this._time=this._next=null}ks.prototype=xc.prototype={constructor:ks,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?ga():+n)+(t==null?0:+t),!this._next&&lr!==this&&(lr?lr._next=this:ws=this,lr=this),this._call=e,this._time=n,Zo()},stop:function(){this._call&&(this._call=null,this._time=1/0,Zo())}};function xc(e,t,n){var r=new ks;return r.restart(e,t,n),r}function x0(){ga(),++Bn;for(var e=ws,t;e;)(t=jn-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Bn}function ri(){jn=(vs=br.now())+Rs,Bn=ir=0;try{x0()}finally{Bn=0,m0(),jn=0}}function g0(){var e=br.now(),t=e-vs;t>hc&&(Rs-=t,vs=e)}function m0(){for(var e,t=ws,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:ws=n);lr=e,Zo(r)}function Zo(e){if(!Bn){ir&&(ir=clearTimeout(ir));var t=e-jn;t>24?(e<1/0&&(ir=setTimeout(ri,e-br.now()-Rs)),sr&&(sr=clearInterval(sr))):(sr||(vs=br.now(),sr=setInterval(g0,hc)),Bn=1,pc(ri))}}function si(e,t,n){var r=new ks;return t=t==null?0:+t,r.restart(o=>{r.stop(),e(o+t)},t,n),r}var b0=Is("start","end","cancel","interrupt"),y0=[],gc=0,oi=1,Qo=2,ds=3,ai=4,Jo=5,fs=6;function Ds(e,t,n,r,o,a){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;w0(e,n,{name:t,index:r,group:o,on:b0,tween:y0,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:gc})}function ma(e,t){var n=bt(e,t);if(n.state>gc)throw new Error("too late; already scheduled");return n}function At(e,t){var n=bt(e,t);if(n.state>ds)throw new Error("too late; already running");return n}function bt(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function w0(e,t,n){var r=e.__transition,o;r[t]=n,n.timer=xc(a,0,n.time);function a(c){n.state=oi,n.timer.restart(i,n.delay,n.time),n.delay<=c&&i(c-n.delay)}function i(c){var u,h,f,m;if(n.state!==oi)return d();for(u in r)if(m=r[u],m.name===n.name){if(m.state===ds)return si(i);m.state===ai?(m.state=fs,m.timer.stop(),m.on.call("interrupt",e,e.__data__,m.index,m.group),delete r[u]):+u<t&&(m.state=fs,m.timer.stop(),m.on.call("cancel",e,e.__data__,m.index,m.group),delete r[u])}if(si(function(){n.state===ds&&(n.state=ai,n.timer.restart(l,n.delay,n.time),l(c))}),n.state=Qo,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Qo){for(n.state=ds,o=new Array(f=n.tween.length),u=0,h=-1;u<f;++u)(m=n.tween[u].value.call(e,e.__data__,n.index,n.group))&&(o[++h]=m);o.length=h+1}}function l(c){for(var u=c<n.duration?n.ease.call(null,c/n.duration):(n.timer.restart(d),n.state=Jo,1),h=-1,f=o.length;++h<f;)o[h].call(e,u);n.state===Jo&&(n.on.call("end",e,e.__data__,n.index,n.group),d())}function d(){n.state=fs,n.timer.stop(),delete r[t];for(var c in r)return;delete e.__transition}}function hs(e,t){var n=e.__transition,r,o,a=!0,i;if(n){t=t==null?null:t+"";for(i in n){if((r=n[i]).name!==t){a=!1;continue}o=r.state>Qo&&r.state<Jo,r.state=fs,r.timer.stop(),r.on.call(o?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[i]}a&&delete e.__transition}}function v0(e){return this.each(function(){hs(this,e)})}function k0(e,t){var n,r;return function(){var o=At(this,e),a=o.tween;if(a!==n){r=n=a;for(var i=0,l=r.length;i<l;++i)if(r[i].name===t){r=r.slice(),r.splice(i,1);break}}o.tween=r}}function N0(e,t,n){var r,o;if(typeof n!="function")throw new Error;return function(){var a=At(this,e),i=a.tween;if(i!==r){o=(r=i).slice();for(var l={name:t,value:n},d=0,c=o.length;d<c;++d)if(o[d].name===t){o[d]=l;break}d===c&&o.push(l)}a.tween=o}}function j0(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=bt(this.node(),n).tween,o=0,a=r.length,i;o<a;++o)if((i=r[o]).name===e)return i.value;return null}return this.each((t==null?k0:N0)(n,e,t))}function ba(e,t,n){var r=e._id;return e.each(function(){var o=At(this,r);(o.value||(o.value={}))[t]=n.apply(this,arguments)}),function(o){return bt(o,r).value[t]}}function mc(e,t){var n;return(typeof t=="number"?St:t instanceof Nn?ys:(n=Nn(t))?(t=n,ys):uc)(e,t)}function S0(e){return function(){this.removeAttribute(e)}}function M0(e){return function(){this.removeAttributeNS(e.space,e.local)}}function $0(e,t,n){var r,o=n+"",a;return function(){var i=this.getAttribute(e);return i===o?null:i===r?a:a=t(r=i,n)}}function E0(e,t,n){var r,o=n+"",a;return function(){var i=this.getAttributeNS(e.space,e.local);return i===o?null:i===r?a:a=t(r=i,n)}}function C0(e,t,n){var r,o,a;return function(){var i,l=n(this),d;return l==null?void this.removeAttribute(e):(i=this.getAttribute(e),d=l+"",i===d?null:i===r&&d===o?a:(o=d,a=t(r=i,l)))}}function _0(e,t,n){var r,o,a;return function(){var i,l=n(this),d;return l==null?void this.removeAttributeNS(e.space,e.local):(i=this.getAttributeNS(e.space,e.local),d=l+"",i===d?null:i===r&&d===o?a:(o=d,a=t(r=i,l)))}}function P0(e,t){var n=Ts(e),r=n==="transform"?u0:mc;return this.attrTween(e,typeof t=="function"?(n.local?_0:C0)(n,r,ba(this,"attr."+e,t)):t==null?(n.local?M0:S0)(n):(n.local?E0:$0)(n,r,t))}function A0(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function I0(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function T0(e,t){var n,r;function o(){var a=t.apply(this,arguments);return a!==r&&(n=(r=a)&&I0(e,a)),n}return o._value=t,o}function R0(e,t){var n,r;function o(){var a=t.apply(this,arguments);return a!==r&&(n=(r=a)&&A0(e,a)),n}return o._value=t,o}function D0(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 new Error;var r=Ts(e);return this.tween(n,(r.local?T0:R0)(r,t))}function L0(e,t){return function(){ma(this,e).delay=+t.apply(this,arguments)}}function O0(e,t){return t=+t,function(){ma(this,e).delay=t}}function F0(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?L0:O0)(t,e)):bt(this.node(),t).delay}function z0(e,t){return function(){At(this,e).duration=+t.apply(this,arguments)}}function H0(e,t){return t=+t,function(){At(this,e).duration=t}}function B0(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?z0:H0)(t,e)):bt(this.node(),t).duration}function W0(e,t){if(typeof t!="function")throw new Error;return function(){At(this,e).ease=t}}function q0(e){var t=this._id;return arguments.length?this.each(W0(t,e)):bt(this.node(),t).ease}function V0(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;At(this,e).ease=n}}function X0(e){if(typeof e!="function")throw new Error;return this.each(V0(this._id,e))}function Y0(e){typeof e!="function"&&(e=Gl(e));for(var t=this._groups,n=t.length,r=new Array(n),o=0;o<n;++o)for(var a=t[o],i=a.length,l=r[o]=[],d,c=0;c<i;++c)(d=a[c])&&e.call(d,d.__data__,c,a)&&l.push(d);return new Xt(r,this._parents,this._name,this._id)}function G0(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,o=n.length,a=Math.min(r,o),i=new Array(r),l=0;l<a;++l)for(var d=t[l],c=n[l],u=d.length,h=i[l]=new Array(u),f,m=0;m<u;++m)(f=d[m]||c[m])&&(h[m]=f);for(;l<r;++l)i[l]=t[l];return new Xt(i,this._parents,this._name,this._id)}function U0(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function K0(e,t,n){var r,o,a=U0(t)?ma:At;return function(){var i=a(this,e),l=i.on;l!==r&&(o=(r=l).copy()).on(t,n),i.on=o}}function Z0(e,t){var n=this._id;return arguments.length<2?bt(this.node(),n).on.on(e):this.each(K0(n,e,t))}function Q0(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function J0(){return this.on("end.remove",Q0(this._id))}function ep(e){var t=this._name,n=this._id;typeof e!="function"&&(e=fa(e));for(var r=this._groups,o=r.length,a=new Array(o),i=0;i<o;++i)for(var l=r[i],d=l.length,c=a[i]=new Array(d),u,h,f=0;f<d;++f)(u=l[f])&&(h=e.call(u,u.__data__,f,l))&&("__data__"in u&&(h.__data__=u.__data__),c[f]=h,Ds(c[f],t,n,f,c,bt(u,n)));return new Xt(a,this._parents,t,n)}function tp(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Yl(e));for(var r=this._groups,o=r.length,a=[],i=[],l=0;l<o;++l)for(var d=r[l],c=d.length,u,h=0;h<c;++h)if(u=d[h]){for(var f=e.call(u,u.__data__,h,d),m,y=bt(u,n),S=0,x=f.length;S<x;++S)(m=f[S])&&Ds(m,t,n,S,f,y);a.push(f),i.push(u)}return new Xt(a,i,t,n)}var np=$r.prototype.constructor;function rp(){return new np(this._groups,this._parents)}function sp(e,t){var n,r,o;return function(){var a=Hn(this,e),i=(this.style.removeProperty(e),Hn(this,e));return a===i?null:a===n&&i===r?o:o=t(n=a,r=i)}}function bc(e){return function(){this.style.removeProperty(e)}}function op(e,t,n){var r,o=n+"",a;return function(){var i=Hn(this,e);return i===o?null:i===r?a:a=t(r=i,n)}}function ap(e,t,n){var r,o,a;return function(){var i=Hn(this,e),l=n(this),d=l+"";return l==null&&(d=l=(this.style.removeProperty(e),Hn(this,e))),i===d?null:i===r&&d===o?a:(o=d,a=t(r=i,l))}}function ip(e,t){var n,r,o,a="style."+t,i="end."+a,l;return function(){var d=At(this,e),c=d.on,u=d.value[a]==null?l||(l=bc(t)):void 0;(c!==n||o!==u)&&(r=(n=c).copy()).on(i,o=u),d.on=r}}function lp(e,t,n){var r=(e+="")=="transform"?c0:mc;return t==null?this.styleTween(e,sp(e,r)).on("end.style."+e,bc(e)):typeof t=="function"?this.styleTween(e,ap(e,r,ba(this,"style."+e,t))).each(ip(this._id,e)):this.styleTween(e,op(e,r,t),n).on("end.style."+e,null)}function cp(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function up(e,t,n){var r,o;function a(){var i=t.apply(this,arguments);return i!==o&&(r=(o=i)&&cp(e,i,n)),r}return a._value=t,a}function dp(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 new Error;return this.tween(r,up(e,t,n??""))}function fp(e){return function(){this.textContent=e}}function hp(e){return function(){var t=e(this);this.textContent=t??""}}function pp(e){return this.tween("text",typeof e=="function"?hp(ba(this,"text",e)):fp(e==null?"":e+""))}function xp(e){return function(t){this.textContent=e.call(this,t)}}function gp(e){var t,n;function r(){var o=e.apply(this,arguments);return o!==n&&(t=(n=o)&&xp(o)),t}return r._value=e,r}function mp(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 new Error;return this.tween(t,gp(e))}function bp(){for(var e=this._name,t=this._id,n=yc(),r=this._groups,o=r.length,a=0;a<o;++a)for(var i=r[a],l=i.length,d,c=0;c<l;++c)if(d=i[c]){var u=bt(d,t);Ds(d,e,n,c,i,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Xt(r,this._parents,e,n)}function yp(){var e,t,n=this,r=n._id,o=n.size();return new Promise(function(a,i){var l={value:i},d={value:function(){--o===0&&a()}};n.each(function(){var c=At(this,r),u=c.on;u!==e&&(t=(e=u).copy(),t._.cancel.push(l),t._.interrupt.push(l),t._.end.push(d)),c.on=t}),o===0&&a()})}var wp=0;function Xt(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function yc(){return++wp}var Bt=$r.prototype;Xt.prototype={constructor:Xt,select:ep,selectAll:tp,selectChild:Bt.selectChild,selectChildren:Bt.selectChildren,filter:Y0,merge:G0,selection:rp,transition:bp,call:Bt.call,nodes:Bt.nodes,node:Bt.node,size:Bt.size,empty:Bt.empty,each:Bt.each,on:Z0,attr:P0,attrTween:D0,style:lp,styleTween:dp,text:pp,textTween:mp,remove:J0,tween:j0,delay:F0,duration:B0,ease:q0,easeVarying:X0,end:yp,[Symbol.iterator]:Bt[Symbol.iterator]};function vp(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var kp={time:null,delay:0,duration:250,ease:vp};function Np(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function jp(e){var t,n;e instanceof Xt?(t=e._id,e=e._name):(t=yc(),(n=kp).time=ga(),e=e==null?null:e+"");for(var r=this._groups,o=r.length,a=0;a<o;++a)for(var i=r[a],l=i.length,d,c=0;c<l;++c)(d=i[c])&&Ds(d,e,t,c,i,n||Np(d,t));return new Xt(r,this._parents,e,t)}$r.prototype.interrupt=v0;$r.prototype.transition=jp;const Zr=e=>()=>e;function Sp(e,{sourceEvent:t,target:n,transform:r,dispatch:o}){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:o}})}function Vt(e,t,n){this.k=e,this.x=t,this.y=n}Vt.prototype={constructor:Vt,scale:function(e){return e===1?this:new Vt(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Vt(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 Ls=new Vt(1,0,0);wc.prototype=Vt.prototype;function wc(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Ls;return e.__zoom}function jo(e){e.stopImmediatePropagation()}function or(e){e.preventDefault(),e.stopImmediatePropagation()}function Mp(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function $p(){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 ii(){return this.__zoom||Ls}function Ep(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Cp(){return navigator.maxTouchPoints||"ontouchstart"in this}function _p(e,t,n){var r=e.invertX(t[0][0])-n[0][0],o=e.invertX(t[1][0])-n[1][0],a=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(o>r?(r+o)/2:Math.min(0,r)||Math.max(0,o),i>a?(a+i)/2:Math.min(0,a)||Math.max(0,i))}function vc(){var e=Mp,t=$p,n=_p,r=Ep,o=Cp,a=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],l=250,d=us,c=Is("start","zoom","end"),u,h,f,m=500,y=150,S=0,x=10;function b(C){C.property("__zoom",ii).on("wheel.zoom",g,{passive:!1}).on("mousedown.zoom",E).on("dblclick.zoom",T).filter(o).on("touchstart.zoom",j).on("touchmove.zoom",_).on("touchend.zoom touchcancel.zoom",I).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}b.transform=function(C,O,A,L){var R=C.selection?C.selection():C;R.property("__zoom",ii),C!==R?M(C,O,A,L):R.interrupt().each(function(){N(this,arguments).event(L).start().zoom(null,typeof O=="function"?O.apply(this,arguments):O).end()})},b.scaleBy=function(C,O,A,L){b.scaleTo(C,function(){var R=this.__zoom.k,F=typeof O=="function"?O.apply(this,arguments):O;return R*F},A,L)},b.scaleTo=function(C,O,A,L){b.transform(C,function(){var R=t.apply(this,arguments),F=this.__zoom,W=A==null?p(R):typeof A=="function"?A.apply(this,arguments):A,G=F.invert(W),Y=typeof O=="function"?O.apply(this,arguments):O;return n(v($(F,Y),W,G),R,i)},A,L)},b.translateBy=function(C,O,A,L){b.transform(C,function(){return n(this.__zoom.translate(typeof O=="function"?O.apply(this,arguments):O,typeof A=="function"?A.apply(this,arguments):A),t.apply(this,arguments),i)},null,L)},b.translateTo=function(C,O,A,L,R){b.transform(C,function(){var F=t.apply(this,arguments),W=this.__zoom,G=L==null?p(F):typeof L=="function"?L.apply(this,arguments):L;return n(Ls.translate(G[0],G[1]).scale(W.k).translate(typeof O=="function"?-O.apply(this,arguments):-O,typeof A=="function"?-A.apply(this,arguments):-A),F,i)},L,R)};function $(C,O){return O=Math.max(a[0],Math.min(a[1],O)),O===C.k?C:new Vt(O,C.x,C.y)}function v(C,O,A){var L=O[0]-A[0]*C.k,R=O[1]-A[1]*C.k;return L===C.x&&R===C.y?C:new Vt(C.k,L,R)}function p(C){return[(+C[0][0]+ +C[1][0])/2,(+C[0][1]+ +C[1][1])/2]}function M(C,O,A,L){C.on("start.zoom",function(){N(this,arguments).event(L).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event(L).end()}).tween("zoom",function(){var R=this,F=arguments,W=N(R,F).event(L),G=t.apply(R,F),Y=A==null?p(G):typeof A=="function"?A.apply(R,F):A,ee=Math.max(G[1][0]-G[0][0],G[1][1]-G[0][1]),B=R.__zoom,Z=typeof O=="function"?O.apply(R,F):O,Q=d(B.invert(Y).concat(ee/B.k),Z.invert(Y).concat(ee/Z.k));return function(K){if(K===1)K=Z;else{var U=Q(K),re=ee/U[2];K=new Vt(re,Y[0]-U[0]*re,Y[1]-U[1]*re)}W.zoom(null,K)}})}function N(C,O,A){return!A&&C.__zooming||new w(C,O)}function w(C,O){this.that=C,this.args=O,this.active=0,this.sourceEvent=null,this.extent=t.apply(C,O),this.taps=0}w.prototype={event:function(C){return C&&(this.sourceEvent=C),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(C,O){return this.mouse&&C!=="mouse"&&(this.mouse[1]=O.invert(this.mouse[0])),this.touch0&&C!=="touch"&&(this.touch0[1]=O.invert(this.touch0[0])),this.touch1&&C!=="touch"&&(this.touch1[1]=O.invert(this.touch1[0])),this.that.__zoom=O,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(C){var O=et(this.that).datum();c.call(C,this.that,new Sp(C,{sourceEvent:this.sourceEvent,target:b,transform:this.that.__zoom,dispatch:c}),O)}};function g(C,...O){if(!e.apply(this,arguments))return;var A=N(this,O).event(C),L=this.__zoom,R=Math.max(a[0],Math.min(a[1],L.k*Math.pow(2,r.apply(this,arguments)))),F=ht(C);if(A.wheel)(A.mouse[0][0]!==F[0]||A.mouse[0][1]!==F[1])&&(A.mouse[1]=L.invert(A.mouse[0]=F)),clearTimeout(A.wheel);else{if(L.k===R)return;A.mouse=[F,L.invert(F)],hs(this),A.start()}or(C),A.wheel=setTimeout(W,y),A.zoom("mouse",n(v($(L,R),A.mouse[0],A.mouse[1]),A.extent,i));function W(){A.wheel=null,A.end()}}function E(C,...O){if(f||!e.apply(this,arguments))return;var A=C.currentTarget,L=N(this,O,!0).event(C),R=et(C.view).on("mousemove.zoom",Y,!0).on("mouseup.zoom",ee,!0),F=ht(C,A),W=C.clientX,G=C.clientY;sc(C.view),jo(C),L.mouse=[F,this.__zoom.invert(F)],hs(this),L.start();function Y(B){if(or(B),!L.moved){var Z=B.clientX-W,Q=B.clientY-G;L.moved=Z*Z+Q*Q>S}L.event(B).zoom("mouse",n(v(L.that.__zoom,L.mouse[0]=ht(B,A),L.mouse[1]),L.extent,i))}function ee(B){R.on("mousemove.zoom mouseup.zoom",null),oc(B.view,L.moved),or(B),L.event(B).end()}}function T(C,...O){if(e.apply(this,arguments)){var A=this.__zoom,L=ht(C.changedTouches?C.changedTouches[0]:C,this),R=A.invert(L),F=A.k*(C.shiftKey?.5:2),W=n(v($(A,F),L,R),t.apply(this,O),i);or(C),l>0?et(this).transition().duration(l).call(M,W,L,C):et(this).call(b.transform,W,L,C)}}function j(C,...O){if(e.apply(this,arguments)){var A=C.touches,L=A.length,R=N(this,O,C.changedTouches.length===L).event(C),F,W,G,Y;for(jo(C),W=0;W<L;++W)G=A[W],Y=ht(G,this),Y=[Y,this.__zoom.invert(Y),G.identifier],R.touch0?!R.touch1&&R.touch0[2]!==Y[2]&&(R.touch1=Y,R.taps=0):(R.touch0=Y,F=!0,R.taps=1+!!u);u&&(u=clearTimeout(u)),F&&(R.taps<2&&(h=Y[0],u=setTimeout(function(){u=null},m)),hs(this),R.start())}}function _(C,...O){if(this.__zooming){var A=N(this,O).event(C),L=C.changedTouches,R=L.length,F,W,G,Y;for(or(C),F=0;F<R;++F)W=L[F],G=ht(W,this),A.touch0&&A.touch0[2]===W.identifier?A.touch0[0]=G:A.touch1&&A.touch1[2]===W.identifier&&(A.touch1[0]=G);if(W=A.that.__zoom,A.touch1){var ee=A.touch0[0],B=A.touch0[1],Z=A.touch1[0],Q=A.touch1[1],K=(K=Z[0]-ee[0])*K+(K=Z[1]-ee[1])*K,U=(U=Q[0]-B[0])*U+(U=Q[1]-B[1])*U;W=$(W,Math.sqrt(K/U)),G=[(ee[0]+Z[0])/2,(ee[1]+Z[1])/2],Y=[(B[0]+Q[0])/2,(B[1]+Q[1])/2]}else if(A.touch0)G=A.touch0[0],Y=A.touch0[1];else return;A.zoom("touch",n(v(W,G,Y),A.extent,i))}}function I(C,...O){if(this.__zooming){var A=N(this,O).event(C),L=C.changedTouches,R=L.length,F,W;for(jo(C),f&&clearTimeout(f),f=setTimeout(function(){f=null},m),F=0;F<R;++F)W=L[F],A.touch0&&A.touch0[2]===W.identifier?delete A.touch0:A.touch1&&A.touch1[2]===W.identifier&&delete A.touch1;if(A.touch1&&!A.touch0&&(A.touch0=A.touch1,delete A.touch1),A.touch0)A.touch0[1]=this.__zoom.invert(A.touch0[0]);else if(A.end(),A.taps===2&&(W=ht(W,this),Math.hypot(h[0]-W[0],h[1]-W[1])<x)){var G=et(this).on("dblclick.zoom");G&&G.apply(this,arguments)}}}return b.wheelDelta=function(C){return arguments.length?(r=typeof C=="function"?C:Zr(+C),b):r},b.filter=function(C){return arguments.length?(e=typeof C=="function"?C:Zr(!!C),b):e},b.touchable=function(C){return arguments.length?(o=typeof C=="function"?C:Zr(!!C),b):o},b.extent=function(C){return arguments.length?(t=typeof C=="function"?C:Zr([[+C[0][0],+C[0][1]],[+C[1][0],+C[1][1]]]),b):t},b.scaleExtent=function(C){return arguments.length?(a[0]=+C[0],a[1]=+C[1],b):[a[0],a[1]]},b.translateExtent=function(C){return arguments.length?(i[0][0]=+C[0][0],i[1][0]=+C[1][0],i[0][1]=+C[0][1],i[1][1]=+C[1][1],b):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},b.constrain=function(C){return arguments.length?(n=C,b):n},b.duration=function(C){return arguments.length?(l=+C,b):l},b.interpolate=function(C){return arguments.length?(d=C,b):d},b.on=function(){var C=c.on.apply(c,arguments);return C===c?b:C},b.clickDistance=function(C){return arguments.length?(S=(C=+C)*C,b):Math.sqrt(S)},b.tapDistance=function(C){return arguments.length?(x=+C,b):x},b}const Pt={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.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 React Flow 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."},yr=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],kc=["Enter"," ","Escape"],Nc={"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"};var Wn;(function(e){e.Strict="strict",e.Loose="loose"})(Wn||(Wn={}));var wn;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(wn||(wn={}));var wr;(function(e){e.Partial="partial",e.Full="full"})(wr||(wr={}));const jc={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var on;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(on||(on={}));var Ns;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Ns||(Ns={}));var ue;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ue||(ue={}));const li={[ue.Left]:ue.Right,[ue.Right]:ue.Left,[ue.Top]:ue.Bottom,[ue.Bottom]:ue.Top};function Sc(e){return e===null?null:e?"valid":"invalid"}const Mc=e=>"id"in e&&"source"in e&&"target"in e,Pp=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),ya=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Cr=(e,t=[0,0])=>{const{width:n,height:r}=Yt(e),o=e.origin??t,a=n*o[0],i=r*o[1];return{x:e.position.x-a,y:e.position.y-i}},Ap=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,o)=>{const a=typeof o=="string";let i=!t.nodeLookup&&!a?o:void 0;t.nodeLookup&&(i=a?t.nodeLookup.get(o):ya(o)?o:t.nodeLookup.get(o.id));const l=i?js(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Os(r,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Fs(n)},_r=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(o=>{(t.filter===void 0||t.filter(o))&&(n=Os(n,js(o)),r=!0)}),r?Fs(n):{x:0,y:0,width:0,height:0}},wa=(e,t,[n,r,o]=[0,0,1],a=!1,i=!1)=>{const l={...Ar(t,[n,r,o]),width:t.width/o,height:t.height/o},d=[];for(const c of e.values()){const{measured:u,selectable:h=!0,hidden:f=!1}=c;if(i&&!h||f)continue;const m=u.width??c.width??c.initialWidth??null,y=u.height??c.height??c.initialHeight??null,S=vr(l,Vn(c)),x=(m??0)*(y??0),b=a&&S>0;(!c.internals.handleBounds||b||S>=x||c.dragging)&&d.push(c)}return d},Ip=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function Tp(e,t){const n=new Map,r=t?.nodes?new Set(t.nodes.map(o=>o.id)):null;return e.forEach(o=>{o.measured.width&&o.measured.height&&(t?.includeHiddenNodes||!o.hidden)&&(!r||r.has(o.id))&&n.set(o.id,o)}),n}async function Rp({nodes:e,width:t,height:n,panZoom:r,minZoom:o,maxZoom:a},i){if(e.size===0)return Promise.resolve(!0);const l=Tp(e,i),d=_r(l),c=zs(d,t,n,i?.minZoom??o,i?.maxZoom??a,i?.padding??.1);return await r.setViewport(c,{duration:i?.duration,ease:i?.ease,interpolate:i?.interpolate}),Promise.resolve(!0)}function $c({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:o,onError:a}){const i=n.get(e),l=i.parentId?n.get(i.parentId):void 0,{x:d,y:c}=l?l.internals.positionAbsolute:{x:0,y:0},u=i.origin??r;let h=i.extent||o;if(i.extent==="parent"&&!i.expandParent)if(!l)a?.("005",Pt.error005());else{const m=l.measured.width,y=l.measured.height;m&&y&&(h=[[d,c],[d+m,c+y]])}else l&&Xn(i.extent)&&(h=[[i.extent[0][0]+d,i.extent[0][1]+c],[i.extent[1][0]+d,i.extent[1][1]+c]]);const f=Xn(h)?Sn(t,h,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&a?.("015",Pt.error015()),{position:{x:f.x-d+(i.measured.width??0)*u[0],y:f.y-c+(i.measured.height??0)*u[1]},positionAbsolute:f}}async function Dp({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:o}){const a=new Set(e.map(f=>f.id)),i=[];for(const f of n){if(f.deletable===!1)continue;const m=a.has(f.id),y=!m&&f.parentId&&i.find(S=>S.id===f.parentId);(m||y)&&i.push(f)}const l=new Set(t.map(f=>f.id)),d=r.filter(f=>f.deletable!==!1),u=Ip(i,d);for(const f of d)l.has(f.id)&&!u.find(y=>y.id===f.id)&&u.push(f);if(!o)return{edges:u,nodes:i};const h=await o({nodes:i,edges:u});return typeof h=="boolean"?h?{edges:u,nodes:i}:{edges:[],nodes:[]}:h}const qn=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Sn=(e={x:0,y:0},t,n)=>({x:qn(e.x,t[0][0],t[1][0]-(n?.width??0)),y:qn(e.y,t[0][1],t[1][1]-(n?.height??0))});function Ec(e,t,n){const{width:r,height:o}=Yt(n),{x:a,y:i}=n.internals.positionAbsolute;return Sn(e,[[a,i],[a+r,i+o]],t)}const ci=(e,t,n)=>e<t?qn(Math.abs(e-t),1,t)/t:e>n?-qn(Math.abs(e-n),1,t)/t:0,Cc=(e,t,n=15,r=40)=>{const o=ci(e.x,r,t.width-r)*n,a=ci(e.y,r,t.height-r)*n;return[o,a]},Os=(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)}),ea=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),Fs=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Vn=(e,t=[0,0])=>{const{x:n,y:r}=ya(e)?e.internals.positionAbsolute:Cr(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}},js=(e,t=[0,0])=>{const{x:n,y:r}=ya(e)?e.internals.positionAbsolute:Cr(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)}},_c=(e,t)=>Fs(Os(ea(e),ea(t))),vr=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},ui=e=>xt(e.width)&&xt(e.height)&&xt(e.x)&&xt(e.y),xt=e=>!isNaN(e)&&isFinite(e),Lp=(e,t)=>{},Pr=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Ar=({x:e,y:t},[n,r,o],a=!1,i=[1,1])=>{const l={x:(e-n)/o,y:(t-r)/o};return a?Pr(l,i):l},Ss=({x:e,y:t},[n,r,o])=>({x:e*o+n,y:t*o+r});function Rn(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function Op(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=Rn(e,n),o=Rn(e,t);return{top:r,right:o,bottom:r,left:o,x:o*2,y:r*2}}if(typeof e=="object"){const r=Rn(e.top??e.y??0,n),o=Rn(e.bottom??e.y??0,n),a=Rn(e.left??e.x??0,t),i=Rn(e.right??e.x??0,t);return{top:r,right:i,bottom:o,left:a,x:a+i,y:r+o}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function Fp(e,t,n,r,o,a){const{x:i,y:l}=Ss(e,[t,n,r]),{x:d,y:c}=Ss({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=o-d,h=a-c;return{left:Math.floor(i),top:Math.floor(l),right:Math.floor(u),bottom:Math.floor(h)}}const zs=(e,t,n,r,o,a)=>{const i=Op(a,t,n),l=(t-i.x)/e.width,d=(n-i.y)/e.height,c=Math.min(l,d),u=qn(c,r,o),h=e.x+e.width/2,f=e.y+e.height/2,m=t/2-h*u,y=n/2-f*u,S=Fp(e,m,y,u,t,n),x={left:Math.min(S.left-i.left,0),top:Math.min(S.top-i.top,0),right:Math.min(S.right-i.right,0),bottom:Math.min(S.bottom-i.bottom,0)};return{x:m-x.left+x.right,y:y-x.top+x.bottom,zoom:u}},kr=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function Xn(e){return e!=null&&e!=="parent"}function Yt(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function Pc(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function Ac(e,t={width:0,height:0},n,r,o){const a={...e},i=r.get(n);if(i){const l=i.origin||o;a.x+=i.internals.positionAbsolute.x-(t.width??0)*l[0],a.y+=i.internals.positionAbsolute.y-(t.height??0)*l[1]}return a}function di(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function zp(){let e,t;return{promise:new Promise((r,o)=>{e=r,t=o}),resolve:e,reject:t}}function Hp(e){return{...Nc,...e||{}}}function hr(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:o}){const{x:a,y:i}=gt(e),l=Ar({x:a-(o?.left??0),y:i-(o?.top??0)},r),{x:d,y:c}=n?Pr(l,t):l;return{xSnapped:d,ySnapped:c,...l}}const va=e=>({width:e.offsetWidth,height:e.offsetHeight}),Ic=e=>e?.getRootNode?.()||window?.document,Bp=["INPUT","SELECT","TEXTAREA"];function Tc(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:Bp.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const Rc=e=>"clientX"in e,gt=(e,t)=>{const n=Rc(e),r=n?e.clientX:e.touches?.[0].clientX,o=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:o-(t?.top??0)}},fi=(e,t,n,r,o)=>{const a=t.querySelectorAll(`.${e}`);return!a||!a.length?null:Array.from(a).map(i=>{const l=i.getBoundingClientRect();return{id:i.getAttribute("data-handleid"),type:e,nodeId:o,position:i.getAttribute("data-handlepos"),x:(l.left-n.left)/r,y:(l.top-n.top)/r,...va(i)}})};function Dc({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:o,sourceControlY:a,targetControlX:i,targetControlY:l}){const d=e*.125+o*.375+i*.375+n*.125,c=t*.125+a*.375+l*.375+r*.125,u=Math.abs(d-e),h=Math.abs(c-t);return[d,c,u,h]}function Qr(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function hi({pos:e,x1:t,y1:n,x2:r,y2:o,c:a}){switch(e){case ue.Left:return[t-Qr(t-r,a),n];case ue.Right:return[t+Qr(r-t,a),n];case ue.Top:return[t,n-Qr(n-o,a)];case ue.Bottom:return[t,n+Qr(o-n,a)]}}function Lc({sourceX:e,sourceY:t,sourcePosition:n=ue.Bottom,targetX:r,targetY:o,targetPosition:a=ue.Top,curvature:i=.25}){const[l,d]=hi({pos:n,x1:e,y1:t,x2:r,y2:o,c:i}),[c,u]=hi({pos:a,x1:r,y1:o,x2:e,y2:t,c:i}),[h,f,m,y]=Dc({sourceX:e,sourceY:t,targetX:r,targetY:o,sourceControlX:l,sourceControlY:d,targetControlX:c,targetControlY:u});return[`M${e},${t} C${l},${d} ${c},${u} ${r},${o}`,h,f,m,y]}function Oc({sourceX:e,sourceY:t,targetX:n,targetY:r}){const o=Math.abs(n-e)/2,a=n<e?n+o:n-o,i=Math.abs(r-t)/2,l=r<t?r+i:r-i;return[a,l,o,i]}function Wp({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:o=!1,zIndexMode:a="basic"}){if(a==="manual")return r;const i=o&&n?r+1e3:r,l=Math.max(e.parentId||o&&e.selected?e.internals.z:0,t.parentId||o&&t.selected?t.internals.z:0);return i+l}function qp({sourceNode:e,targetNode:t,width:n,height:r,transform:o}){const a=Os(js(e),js(t));a.x===a.x2&&(a.x2+=1),a.y===a.y2&&(a.y2+=1);const i={x:-o[0]/o[2],y:-o[1]/o[2],width:n/o[2],height:r/o[2]};return vr(i,Fs(a))>0}const Vp=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,Xp=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),Yp=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||Vp;let o;return Mc(e)?o={...e}:o={...e,id:r(e)},Xp(o,t)?t:(o.sourceHandle===null&&delete o.sourceHandle,o.targetHandle===null&&delete o.targetHandle,t.concat(o))};function Fc({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[o,a,i,l]=Oc({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,o,a,i,l]}const pi={[ue.Left]:{x:-1,y:0},[ue.Right]:{x:1,y:0},[ue.Top]:{x:0,y:-1},[ue.Bottom]:{x:0,y:1}},Gp=({source:e,sourcePosition:t=ue.Bottom,target:n})=>t===ue.Left||t===ue.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},xi=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Up({source:e,sourcePosition:t=ue.Bottom,target:n,targetPosition:r=ue.Top,center:o,offset:a,stepPosition:i}){const l=pi[t],d=pi[r],c={x:e.x+l.x*a,y:e.y+l.y*a},u={x:n.x+d.x*a,y:n.y+d.y*a},h=Gp({source:c,sourcePosition:t,target:u}),f=h.x!==0?"x":"y",m=h[f];let y=[],S,x;const b={x:0,y:0},$={x:0,y:0},[,,v,p]=Oc({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[f]*d[f]===-1){f==="x"?(S=o.x??c.x+(u.x-c.x)*i,x=o.y??(c.y+u.y)/2):(S=o.x??(c.x+u.x)/2,x=o.y??c.y+(u.y-c.y)*i);const N=[{x:S,y:c.y},{x:S,y:u.y}],w=[{x:c.x,y:x},{x:u.x,y:x}];l[f]===m?y=f==="x"?N:w:y=f==="x"?w:N}else{const N=[{x:c.x,y:u.y}],w=[{x:u.x,y:c.y}];if(f==="x"?y=l.x===m?w:N:y=l.y===m?N:w,t===r){const _=Math.abs(e[f]-n[f]);if(_<=a){const I=Math.min(a-1,a-_);l[f]===m?b[f]=(c[f]>e[f]?-1:1)*I:$[f]=(u[f]>n[f]?-1:1)*I}}if(t!==r){const _=f==="x"?"y":"x",I=l[f]===d[_],C=c[_]>u[_],O=c[_]<u[_];(l[f]===1&&(!I&&C||I&&O)||l[f]!==1&&(!I&&O||I&&C))&&(y=f==="x"?N:w)}const g={x:c.x+b.x,y:c.y+b.y},E={x:u.x+$.x,y:u.y+$.y},T=Math.max(Math.abs(g.x-y[0].x),Math.abs(E.x-y[0].x)),j=Math.max(Math.abs(g.y-y[0].y),Math.abs(E.y-y[0].y));T>=j?(S=(g.x+E.x)/2,x=y[0].y):(S=y[0].x,x=(g.y+E.y)/2)}return[[e,{x:c.x+b.x,y:c.y+b.y},...y,{x:u.x+$.x,y:u.y+$.y},n],S,x,v,p]}function Kp(e,t,n,r){const o=Math.min(xi(e,t)/2,xi(t,n)/2,r),{x:a,y:i}=t;if(e.x===a&&a===n.x||e.y===i&&i===n.y)return`L${a} ${i}`;if(e.y===i){const c=e.x<n.x?-1:1,u=e.y<n.y?1:-1;return`L ${a+o*c},${i}Q ${a},${i} ${a},${i+o*u}`}const l=e.x<n.x?1:-1,d=e.y<n.y?-1:1;return`L ${a},${i+o*d}Q ${a},${i} ${a+o*l},${i}`}function ta({sourceX:e,sourceY:t,sourcePosition:n=ue.Bottom,targetX:r,targetY:o,targetPosition:a=ue.Top,borderRadius:i=5,centerX:l,centerY:d,offset:c=20,stepPosition:u=.5}){const[h,f,m,y,S]=Up({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:o},targetPosition:a,center:{x:l,y:d},offset:c,stepPosition:u});return[h.reduce((b,$,v)=>{let p="";return v>0&&v<h.length-1?p=Kp(h[v-1],$,h[v+1],i):p=`${v===0?"M":"L"}${$.x} ${$.y}`,b+=p,b},""),f,m,y,S]}function gi(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Zp(e){const{sourceNode:t,targetNode:n}=e;if(!gi(t)||!gi(n))return null;const r=t.internals.handleBounds||mi(t.handles),o=n.internals.handleBounds||mi(n.handles),a=bi(r?.source??[],e.sourceHandle),i=bi(e.connectionMode===Wn.Strict?o?.target??[]:(o?.target??[]).concat(o?.source??[]),e.targetHandle);if(!a||!i)return e.onError?.("008",Pt.error008(a?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=a?.position||ue.Bottom,d=i?.position||ue.Top,c=Mn(t,a,l),u=Mn(n,i,d);return{sourceX:c.x,sourceY:c.y,targetX:u.x,targetY:u.y,sourcePosition:l,targetPosition:d}}function mi(e){if(!e)return null;const t=[],n=[];for(const 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 Mn(e,t,n=ue.Left,r=!1){const o=(t?.x??0)+e.internals.positionAbsolute.x,a=(t?.y??0)+e.internals.positionAbsolute.y,{width:i,height:l}=t??Yt(e);if(r)return{x:o+i/2,y:a+l/2};switch(t?.position??n){case ue.Top:return{x:o+i/2,y:a};case ue.Right:return{x:o+i,y:a+l/2};case ue.Bottom:return{x:o+i/2,y:a+l};case ue.Left:return{x:o,y:a+l/2}}}function bi(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function na(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function Qp(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:o}){const a=new Set;return e.reduce((i,l)=>([l.markerStart||r,l.markerEnd||o].forEach(d=>{if(d&&typeof d=="object"){const c=na(d,t);a.has(c)||(i.push({id:c,color:d.color||n,...d}),a.add(c))}}),i),[]).sort((i,l)=>i.id.localeCompare(l.id))}const zc=1e3,Jp=10,ka={nodeOrigin:[0,0],nodeExtent:yr,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},ex={...ka,checkEquality:!0};function Na(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function tx(e,t,n){const r=Na(ka,n);for(const o of e.values())if(o.parentId)Sa(o,e,t,r);else{const a=Cr(o,r.nodeOrigin),i=Xn(o.extent)?o.extent:r.nodeExtent,l=Sn(a,i,Yt(o));o.internals.positionAbsolute=l}}function nx(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],r=[];for(const o of e.handles){const a={id:o.id,width:o.width??1,height:o.height??1,nodeId:e.id,x:o.x,y:o.y,position:o.position,type:o.type};o.type==="source"?n.push(a):o.type==="target"&&r.push(a)}return{source:n,target:r}}function ja(e){return e==="manual"}function ra(e,t,n,r={}){const o=Na(ex,r),a={i:0},i=new Map(t),l=o?.elevateNodesOnSelect&&!ja(o.zIndexMode)?zc:0;let d=e.length>0;t.clear(),n.clear();for(const c of e){let u=i.get(c.id);if(o.checkEquality&&c===u?.internals.userNode)t.set(c.id,u);else{const h=Cr(c,o.nodeOrigin),f=Xn(c.extent)?c.extent:o.nodeExtent,m=Sn(h,f,Yt(c));u={...o.defaults,...c,measured:{width:c.measured?.width,height:c.measured?.height},internals:{positionAbsolute:m,handleBounds:nx(c,u),z:Hc(c,l,o.zIndexMode),userNode:c}},t.set(c.id,u)}(u.measured===void 0||u.measured.width===void 0||u.measured.height===void 0)&&!u.hidden&&(d=!1),c.parentId&&Sa(u,t,n,r,a)}return d}function rx(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function Sa(e,t,n,r,o){const{elevateNodesOnSelect:a,nodeOrigin:i,nodeExtent:l,zIndexMode:d}=Na(ka,r),c=e.parentId,u=t.get(c);if(!u){console.warn(`Parent node ${c} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}rx(e,n),o&&!u.parentId&&u.internals.rootParentIndex===void 0&&d==="auto"&&(u.internals.rootParentIndex=++o.i,u.internals.z=u.internals.z+o.i*Jp),o&&u.internals.rootParentIndex!==void 0&&(o.i=u.internals.rootParentIndex);const h=a&&!ja(d)?zc:0,{x:f,y:m,z:y}=sx(e,u,i,l,h,d),{positionAbsolute:S}=e.internals,x=f!==S.x||m!==S.y;(x||y!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:x?{x:f,y:m}:S,z:y}})}function Hc(e,t,n){const r=xt(e.zIndex)?e.zIndex:0;return ja(n)?r:r+(e.selected?t:0)}function sx(e,t,n,r,o,a){const{x:i,y:l}=t.internals.positionAbsolute,d=Yt(e),c=Cr(e,n),u=Xn(e.extent)?Sn(c,e.extent,d):c;let h=Sn({x:i+u.x,y:l+u.y},r,d);e.extent==="parent"&&(h=Ec(h,d,t));const f=Hc(e,o,a),m=t.internals.z??0;return{x:h.x,y:h.y,z:m>=f?m+1:f}}function Ma(e,t,n,r=[0,0]){const o=[],a=new Map;for(const i of e){const l=t.get(i.parentId);if(!l)continue;const d=a.get(i.parentId)?.expandedRect??Vn(l),c=_c(d,i.rect);a.set(i.parentId,{expandedRect:c,parent:l})}return a.size>0&&a.forEach(({expandedRect:i,parent:l},d)=>{const c=l.internals.positionAbsolute,u=Yt(l),h=l.origin??r,f=i.x<c.x?Math.round(Math.abs(c.x-i.x)):0,m=i.y<c.y?Math.round(Math.abs(c.y-i.y)):0,y=Math.max(u.width,Math.round(i.width)),S=Math.max(u.height,Math.round(i.height)),x=(y-u.width)*h[0],b=(S-u.height)*h[1];(f>0||m>0||x||b)&&(o.push({id:d,type:"position",position:{x:l.position.x-f+x,y:l.position.y-m+b}}),n.get(d)?.forEach($=>{e.some(v=>v.id===$.id)||o.push({id:$.id,type:"position",position:{x:$.position.x+f,y:$.position.y+m}})})),(u.width<i.width||u.height<i.height||f||m)&&o.push({id:d,type:"dimensions",setAttributes:!0,dimensions:{width:y+(f?h[0]*f-x:0),height:S+(m?h[1]*m-b:0)}})}),o}function ox(e,t,n,r,o,a,i){const l=r?.querySelector(".xyflow__viewport");let d=!1;if(!l)return{changes:[],updatedInternals:d};const c=[],u=window.getComputedStyle(l),{m22:h}=new window.DOMMatrixReadOnly(u.transform),f=[];for(const m of e.values()){const y=t.get(m.id);if(!y)continue;if(y.hidden){t.set(y.id,{...y,internals:{...y.internals,handleBounds:void 0}}),d=!0;continue}const S=va(m.nodeElement),x=y.measured.width!==S.width||y.measured.height!==S.height;if(!!(S.width&&S.height&&(x||!y.internals.handleBounds||m.force))){const $=m.nodeElement.getBoundingClientRect(),v=Xn(y.extent)?y.extent:a;let{positionAbsolute:p}=y.internals;y.parentId&&y.extent==="parent"?p=Ec(p,S,t.get(y.parentId)):v&&(p=Sn(p,v,S));const M={...y,measured:S,internals:{...y.internals,positionAbsolute:p,handleBounds:{source:fi("source",m.nodeElement,$,h,y.id),target:fi("target",m.nodeElement,$,h,y.id)}}};t.set(y.id,M),y.parentId&&Sa(M,t,n,{nodeOrigin:o,zIndexMode:i}),d=!0,x&&(c.push({id:y.id,type:"dimensions",dimensions:S}),y.expandParent&&y.parentId&&f.push({id:y.id,parentId:y.parentId,rect:Vn(M,o)}))}}if(f.length>0){const m=Ma(f,t,n,o);c.push(...m)}return{changes:c,updatedInternals:d}}async function ax({delta:e,panZoom:t,transform:n,translateExtent:r,width:o,height:a}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const i=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[o,a]],r),l=!!i&&(i.x!==n[0]||i.y!==n[1]||i.k!==n[2]);return Promise.resolve(l)}function yi(e,t,n,r,o,a){let i=o;const l=r.get(i)||new Map;r.set(i,l.set(n,t)),i=`${o}-${e}`;const d=r.get(i)||new Map;if(r.set(i,d.set(n,t)),a){i=`${o}-${e}-${a}`;const c=r.get(i)||new Map;r.set(i,c.set(n,t))}}function Bc(e,t,n){e.clear(),t.clear();for(const r of n){const{source:o,target:a,sourceHandle:i=null,targetHandle:l=null}=r,d={edgeId:r.id,source:o,target:a,sourceHandle:i,targetHandle:l},c=`${o}-${i}--${a}-${l}`,u=`${a}-${l}--${o}-${i}`;yi("source",d,u,e,o,i),yi("target",d,c,e,a,l),t.set(r.id,r)}}function Wc(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:Wc(n,t):!1}function wi(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 ix(e,t,n,r){const o=new Map;for(const[a,i]of e)if((i.selected||i.id===r)&&(!i.parentId||!Wc(i,e))&&(i.draggable||t&&typeof i.draggable>"u")){const l=e.get(a);l&&o.set(a,{id:a,position:l.position||{x:0,y:0},distance:{x:n.x-l.internals.positionAbsolute.x,y:n.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return o}function So({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){const o=[];for(const[i,l]of t){const d=n.get(i)?.internals.userNode;d&&o.push({...d,position:l.position,dragging:r})}if(!e)return[o[0],o];const a=n.get(e)?.internals.userNode;return[a?{...a,position:t.get(e)?.position||a.position,dragging:r}:o[0],o]}function lx({dragItems:e,snapGrid:t,x:n,y:r}){const o=e.values().next().value;if(!o)return null;const a={x:n-o.distance.x,y:r-o.distance.y},i=Pr(a,t);return{x:i.x-a.x,y:i.y-a.y}}function cx({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:o}){let a={x:null,y:null},i=0,l=new Map,d=!1,c={x:0,y:0},u=null,h=!1,f=null,m=!1,y=!1,S=null;function x({noDragClassName:$,handleSelector:v,domNode:p,isSelectable:M,nodeId:N,nodeClickDistance:w=0}){f=et(p);function g({x:_,y:I}){const{nodeLookup:C,nodeExtent:O,snapGrid:A,snapToGrid:L,nodeOrigin:R,onNodeDrag:F,onSelectionDrag:W,onError:G,updateNodePositions:Y}=t();a={x:_,y:I};let ee=!1;const B=l.size>1,Z=B&&O?ea(_r(l)):null,Q=B&&L?lx({dragItems:l,snapGrid:A,x:_,y:I}):null;for(const[K,U]of l){if(!C.has(K))continue;let re={x:_-U.distance.x,y:I-U.distance.y};L&&(re=Q?{x:Math.round(re.x+Q.x),y:Math.round(re.y+Q.y)}:Pr(re,A));let ae=null;if(B&&O&&!U.extent&&Z){const{positionAbsolute:ie}=U.internals,V=ie.x-Z.x+O[0][0],oe=ie.x+U.measured.width-Z.x2+O[1][0],de=ie.y-Z.y+O[0][1],be=ie.y+U.measured.height-Z.y2+O[1][1];ae=[[V,de],[oe,be]]}const{position:se,positionAbsolute:le}=$c({nodeId:K,nextPosition:re,nodeLookup:C,nodeExtent:ae||O,nodeOrigin:R,onError:G});ee=ee||U.position.x!==se.x||U.position.y!==se.y,U.position=se,U.internals.positionAbsolute=le}if(y=y||ee,!!ee&&(Y(l,!0),S&&(r||F||!N&&W))){const[K,U]=So({nodeId:N,dragItems:l,nodeLookup:C});r?.(S,l,K,U),F?.(S,K,U),N||W?.(S,U)}}async function E(){if(!u)return;const{transform:_,panBy:I,autoPanSpeed:C,autoPanOnNodeDrag:O}=t();if(!O){d=!1,cancelAnimationFrame(i);return}const[A,L]=Cc(c,u,C);(A!==0||L!==0)&&(a.x=(a.x??0)-A/_[2],a.y=(a.y??0)-L/_[2],await I({x:A,y:L})&&g(a)),i=requestAnimationFrame(E)}function T(_){const{nodeLookup:I,multiSelectionActive:C,nodesDraggable:O,transform:A,snapGrid:L,snapToGrid:R,selectNodesOnDrag:F,onNodeDragStart:W,onSelectionDragStart:G,unselectNodesAndEdges:Y}=t();h=!0,(!F||!M)&&!C&&N&&(I.get(N)?.selected||Y()),M&&F&&N&&e?.(N);const ee=hr(_.sourceEvent,{transform:A,snapGrid:L,snapToGrid:R,containerBounds:u});if(a=ee,l=ix(I,O,ee,N),l.size>0&&(n||W||!N&&G)){const[B,Z]=So({nodeId:N,dragItems:l,nodeLookup:I});n?.(_.sourceEvent,l,B,Z),W?.(_.sourceEvent,B,Z),N||G?.(_.sourceEvent,Z)}}const j=ac().clickDistance(w).on("start",_=>{const{domNode:I,nodeDragThreshold:C,transform:O,snapGrid:A,snapToGrid:L}=t();u=I?.getBoundingClientRect()||null,m=!1,y=!1,S=_.sourceEvent,C===0&&T(_),a=hr(_.sourceEvent,{transform:O,snapGrid:A,snapToGrid:L,containerBounds:u}),c=gt(_.sourceEvent,u)}).on("drag",_=>{const{autoPanOnNodeDrag:I,transform:C,snapGrid:O,snapToGrid:A,nodeDragThreshold:L,nodeLookup:R}=t(),F=hr(_.sourceEvent,{transform:C,snapGrid:O,snapToGrid:A,containerBounds:u});if(S=_.sourceEvent,(_.sourceEvent.type==="touchmove"&&_.sourceEvent.touches.length>1||N&&!R.has(N))&&(m=!0),!m){if(!d&&I&&h&&(d=!0,E()),!h){const W=gt(_.sourceEvent,u),G=W.x-c.x,Y=W.y-c.y;Math.sqrt(G*G+Y*Y)>L&&T(_)}(a.x!==F.xSnapped||a.y!==F.ySnapped)&&l&&h&&(c=gt(_.sourceEvent,u),g(F))}}).on("end",_=>{if(!(!h||m)&&(d=!1,h=!1,cancelAnimationFrame(i),l.size>0)){const{nodeLookup:I,updateNodePositions:C,onNodeDragStop:O,onSelectionDragStop:A}=t();if(y&&(C(l,!1),y=!1),o||O||!N&&A){const[L,R]=So({nodeId:N,dragItems:l,nodeLookup:I,dragging:!1});o?.(_.sourceEvent,l,L,R),O?.(_.sourceEvent,L,R),N||A?.(_.sourceEvent,R)}}}).filter(_=>{const I=_.target;return!_.button&&(!$||!wi(I,`.${$}`,p))&&(!v||wi(I,v,p))});f.call(j)}function b(){f?.on(".drag",null)}return{update:x,destroy:b}}function ux(e,t,n){const r=[],o={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const a of t.values())vr(o,Vn(a))>0&&r.push(a);return r}const dx=250;function fx(e,t,n,r){let o=[],a=1/0;const i=ux(e,n,t+dx);for(const l of i){const d=[...l.internals.handleBounds?.source??[],...l.internals.handleBounds?.target??[]];for(const c of d){if(r.nodeId===c.nodeId&&r.type===c.type&&r.id===c.id)continue;const{x:u,y:h}=Mn(l,c,c.position,!0),f=Math.sqrt(Math.pow(u-e.x,2)+Math.pow(h-e.y,2));f>t||(f<a?(o=[{...c,x:u,y:h}],a=f):f===a&&o.push({...c,x:u,y:h}))}}if(!o.length)return null;if(o.length>1){const l=r.type==="source"?"target":"source";return o.find(d=>d.type===l)??o[0]}return o[0]}function qc(e,t,n,r,o,a=!1){const i=r.get(e);if(!i)return null;const l=o==="strict"?i.internals.handleBounds?.[t]:[...i.internals.handleBounds?.source??[],...i.internals.handleBounds?.target??[]],d=(n?l?.find(c=>c.id===n):l?.[0])??null;return d&&a?{...d,...Mn(i,d,d.position,!0)}:d}function Vc(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function hx(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const Xc=()=>!0;function px(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:o,edgeUpdaterType:a,isTarget:i,domNode:l,nodeLookup:d,lib:c,autoPanOnConnect:u,flowId:h,panBy:f,cancelConnection:m,onConnectStart:y,onConnect:S,onConnectEnd:x,isValidConnection:b=Xc,onReconnectEnd:$,updateConnection:v,getTransform:p,getFromHandle:M,autoPanSpeed:N,dragThreshold:w=1,handleDomNode:g}){const E=Ic(e.target);let T=0,j;const{x:_,y:I}=gt(e),C=Vc(a,g),O=l?.getBoundingClientRect();let A=!1;if(!O||!C)return;const L=qc(o,C,r,d,t);if(!L)return;let R=gt(e,O),F=!1,W=null,G=!1,Y=null;function ee(){if(!u||!O)return;const[se,le]=Cc(R,O,N);f({x:se,y:le}),T=requestAnimationFrame(ee)}const B={...L,nodeId:o,type:C,position:L.position},Z=d.get(o);let K={inProgress:!0,isValid:null,from:Mn(Z,B,ue.Left,!0),fromHandle:B,fromPosition:B.position,fromNode:Z,to:R,toHandle:null,toPosition:li[B.position],toNode:null,pointer:R};function U(){A=!0,v(K),y?.(e,{nodeId:o,handleId:r,handleType:C})}w===0&&U();function re(se){if(!A){const{x:be,y:ke}=gt(se),_e=be-_,Te=ke-I;if(!(_e*_e+Te*Te>w*w))return;U()}if(!M()||!B){ae(se);return}const le=p();R=gt(se,O),j=fx(Ar(R,le,!1,[1,1]),n,d,B),F||(ee(),F=!0);const ie=Yc(se,{handle:j,connectionMode:t,fromNodeId:o,fromHandleId:r,fromType:i?"target":"source",isValidConnection:b,doc:E,lib:c,flowId:h,nodeLookup:d});Y=ie.handleDomNode,W=ie.connection,G=hx(!!j,ie.isValid);const V=d.get(o),oe=V?Mn(V,B,ue.Left,!0):K.from,de={...K,from:oe,isValid:G,to:ie.toHandle&&G?Ss({x:ie.toHandle.x,y:ie.toHandle.y},le):R,toHandle:ie.toHandle,toPosition:G&&ie.toHandle?ie.toHandle.position:li[B.position],toNode:ie.toHandle?d.get(ie.toHandle.nodeId):null,pointer:R};v(de),K=de}function ae(se){if(!("touches"in se&&se.touches.length>0)){if(A){(j||Y)&&W&&G&&S?.(W);const{inProgress:le,...ie}=K,V={...ie,toPosition:K.toHandle?K.toPosition:null};x?.(se,V),a&&$?.(se,V)}m(),cancelAnimationFrame(T),F=!1,G=!1,W=null,Y=null,E.removeEventListener("mousemove",re),E.removeEventListener("mouseup",ae),E.removeEventListener("touchmove",re),E.removeEventListener("touchend",ae)}}E.addEventListener("mousemove",re),E.addEventListener("mouseup",ae),E.addEventListener("touchmove",re),E.addEventListener("touchend",ae)}function Yc(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:o,fromType:a,doc:i,lib:l,flowId:d,isValidConnection:c=Xc,nodeLookup:u}){const h=a==="target",f=t?i.querySelector(`.${l}-flow__handle[data-id="${d}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:m,y}=gt(e),S=i.elementFromPoint(m,y),x=S?.classList.contains(`${l}-flow__handle`)?S:f,b={handleDomNode:x,isValid:!1,connection:null,toHandle:null};if(x){const $=Vc(void 0,x),v=x.getAttribute("data-nodeid"),p=x.getAttribute("data-handleid"),M=x.classList.contains("connectable"),N=x.classList.contains("connectableend");if(!v||!$)return b;const w={source:h?v:r,sourceHandle:h?p:o,target:h?r:v,targetHandle:h?o:p};b.connection=w;const E=M&&N&&(n===Wn.Strict?h&&$==="source"||!h&&$==="target":v!==r||p!==o);b.isValid=E&&c(w),b.toHandle=qc(v,$,p,u,n,!0)}return b}const sa={onPointerDown:px,isValid:Yc};function xx({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const o=et(e);function a({translateExtent:l,width:d,height:c,zoomStep:u=1,pannable:h=!0,zoomable:f=!0,inversePan:m=!1}){const y=v=>{if(v.sourceEvent.type!=="wheel"||!t)return;const p=n(),M=v.sourceEvent.ctrlKey&&kr()?10:1,N=-v.sourceEvent.deltaY*(v.sourceEvent.deltaMode===1?.05:v.sourceEvent.deltaMode?1:.002)*u,w=p[2]*Math.pow(2,N*M);t.scaleTo(w)};let S=[0,0];const x=v=>{(v.sourceEvent.type==="mousedown"||v.sourceEvent.type==="touchstart")&&(S=[v.sourceEvent.clientX??v.sourceEvent.touches[0].clientX,v.sourceEvent.clientY??v.sourceEvent.touches[0].clientY])},b=v=>{const p=n();if(v.sourceEvent.type!=="mousemove"&&v.sourceEvent.type!=="touchmove"||!t)return;const M=[v.sourceEvent.clientX??v.sourceEvent.touches[0].clientX,v.sourceEvent.clientY??v.sourceEvent.touches[0].clientY],N=[M[0]-S[0],M[1]-S[1]];S=M;const w=r()*Math.max(p[2],Math.log(p[2]))*(m?-1:1),g={x:p[0]-N[0]*w,y:p[1]-N[1]*w},E=[[0,0],[d,c]];t.setViewportConstrained({x:g.x,y:g.y,zoom:p[2]},E,l)},$=vc().on("start",x).on("zoom",h?b:null).on("zoom.wheel",f?y:null);o.call($,{})}function i(){o.on("zoom",null)}return{update:a,destroy:i,pointer:ht}}const Hs=e=>({x:e.x,y:e.y,zoom:e.k}),Mo=({x:e,y:t,zoom:n})=>Ls.translate(e,t).scale(n),Ln=(e,t)=>e.target.closest(`.${t}`),Gc=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),gx=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,$o=(e,t=0,n=gx,r=()=>{})=>{const o=typeof t=="number"&&t>0;return o||r(),o?e.transition().duration(t).ease(n).on("end",r):e},Uc=e=>{const t=e.ctrlKey&&kr()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function mx({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:o,panOnScrollSpeed:a,zoomOnPinch:i,onPanZoomStart:l,onPanZoom:d,onPanZoomEnd:c}){return u=>{if(Ln(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();const h=n.property("__zoom").k||1;if(u.ctrlKey&&i){const x=ht(u),b=Uc(u),$=h*Math.pow(2,b);r.scaleTo(n,$,x,u);return}const f=u.deltaMode===1?20:1;let m=o===wn.Vertical?0:u.deltaX*f,y=o===wn.Horizontal?0:u.deltaY*f;!kr()&&u.shiftKey&&o!==wn.Vertical&&(m=u.deltaY*f,y=0),r.translateBy(n,-(m/h)*a,-(y/h)*a,{internal:!0});const S=Hs(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(d?.(u,S),e.panScrollTimeout=setTimeout(()=>{c?.(u,S),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l?.(u,S))}}function bx({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,o){const a=r.type==="wheel",i=!t&&a&&!r.ctrlKey,l=Ln(r,e);if(r.ctrlKey&&a&&l&&r.preventDefault(),i||l)return null;r.preventDefault(),n.call(this,r,o)}}function yx({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;const o=Hs(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=o,r.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(r.sourceEvent,o)}}function wx({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:o}){return a=>{e.usedRightMouseButton=!!(n&&Gc(t,e.mouseButton??0)),a.sourceEvent?.sync||r([a.transform.x,a.transform.y,a.transform.k]),o&&!a.sourceEvent?.internal&&o?.(a.sourceEvent,Hs(a.transform))}}function vx({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:o,onPaneContextMenu:a}){return i=>{if(!i.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,a&&Gc(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&a(i.sourceEvent),e.usedRightMouseButton=!1,r(!1),o)){const l=Hs(i.transform);e.prevViewport=l,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{o?.(i.sourceEvent,l)},n?150:0)}}}function kx({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:o,zoomOnDoubleClick:a,userSelectionActive:i,noWheelClassName:l,noPanClassName:d,lib:c,connectionInProgress:u}){return h=>{const f=e||t,m=n&&h.ctrlKey,y=h.type==="wheel";if(h.button===1&&h.type==="mousedown"&&(Ln(h,`${c}-flow__node`)||Ln(h,`${c}-flow__edge`)))return!0;if(!r&&!f&&!o&&!a&&!n||i||u&&!y||Ln(h,l)&&y||Ln(h,d)&&(!y||o&&y&&!e)||!n&&h.ctrlKey&&y)return!1;if(!n&&h.type==="touchstart"&&h.touches?.length>1)return h.preventDefault(),!1;if(!f&&!o&&!m&&y||!r&&(h.type==="mousedown"||h.type==="touchstart")||Array.isArray(r)&&!r.includes(h.button)&&h.type==="mousedown")return!1;const S=Array.isArray(r)&&r.includes(h.button)||!h.button||h.button<=1;return(!h.ctrlKey||y)&&S}}function Nx({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:o,onPanZoom:a,onPanZoomStart:i,onPanZoomEnd:l,onDraggingChange:d}){const c={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),h=vc().scaleExtent([t,n]).translateExtent(r),f=et(e).call(h);$({x:o.x,y:o.y,zoom:qn(o.zoom,t,n)},[[0,0],[u.width,u.height]],r);const m=f.on("wheel.zoom"),y=f.on("dblclick.zoom");h.wheelDelta(Uc);function S(j,_){return f?new Promise(I=>{h?.interpolate(_?.interpolate==="linear"?fr:us).transform($o(f,_?.duration,_?.ease,()=>I(!0)),j)}):Promise.resolve(!1)}function x({noWheelClassName:j,noPanClassName:_,onPaneContextMenu:I,userSelectionActive:C,panOnScroll:O,panOnDrag:A,panOnScrollMode:L,panOnScrollSpeed:R,preventScrolling:F,zoomOnPinch:W,zoomOnScroll:G,zoomOnDoubleClick:Y,zoomActivationKeyPressed:ee,lib:B,onTransformChange:Z,connectionInProgress:Q,paneClickDistance:K,selectionOnDrag:U}){C&&!c.isZoomingOrPanning&&b();const re=O&&!ee&&!C;h.clickDistance(U?1/0:!xt(K)||K<0?0:K);const ae=re?mx({zoomPanValues:c,noWheelClassName:j,d3Selection:f,d3Zoom:h,panOnScrollMode:L,panOnScrollSpeed:R,zoomOnPinch:W,onPanZoomStart:i,onPanZoom:a,onPanZoomEnd:l}):bx({noWheelClassName:j,preventScrolling:F,d3ZoomHandler:m});if(f.on("wheel.zoom",ae,{passive:!1}),!C){const le=yx({zoomPanValues:c,onDraggingChange:d,onPanZoomStart:i});h.on("start",le);const ie=wx({zoomPanValues:c,panOnDrag:A,onPaneContextMenu:!!I,onPanZoom:a,onTransformChange:Z});h.on("zoom",ie);const V=vx({zoomPanValues:c,panOnDrag:A,panOnScroll:O,onPaneContextMenu:I,onPanZoomEnd:l,onDraggingChange:d});h.on("end",V)}const se=kx({zoomActivationKeyPressed:ee,panOnDrag:A,zoomOnScroll:G,panOnScroll:O,zoomOnDoubleClick:Y,zoomOnPinch:W,userSelectionActive:C,noPanClassName:_,noWheelClassName:j,lib:B,connectionInProgress:Q});h.filter(se),Y?f.on("dblclick.zoom",y):f.on("dblclick.zoom",null)}function b(){h.on("zoom",null)}async function $(j,_,I){const C=Mo(j),O=h?.constrain()(C,_,I);return O&&await S(O),new Promise(A=>A(O))}async function v(j,_){const I=Mo(j);return await S(I,_),new Promise(C=>C(I))}function p(j){if(f){const _=Mo(j),I=f.property("__zoom");(I.k!==j.zoom||I.x!==j.x||I.y!==j.y)&&h?.transform(f,_,null,{sync:!0})}}function M(){const j=f?wc(f.node()):{x:0,y:0,k:1};return{x:j.x,y:j.y,zoom:j.k}}function N(j,_){return f?new Promise(I=>{h?.interpolate(_?.interpolate==="linear"?fr:us).scaleTo($o(f,_?.duration,_?.ease,()=>I(!0)),j)}):Promise.resolve(!1)}function w(j,_){return f?new Promise(I=>{h?.interpolate(_?.interpolate==="linear"?fr:us).scaleBy($o(f,_?.duration,_?.ease,()=>I(!0)),j)}):Promise.resolve(!1)}function g(j){h?.scaleExtent(j)}function E(j){h?.translateExtent(j)}function T(j){const _=!xt(j)||j<0?0:j;h?.clickDistance(_)}return{update:x,destroy:b,setViewport:v,setViewportConstrained:$,getViewport:M,scaleTo:N,scaleBy:w,setScaleExtent:g,setTranslateExtent:E,syncViewport:p,setClickDistance:T}}var Yn;(function(e){e.Line="line",e.Handle="handle"})(Yn||(Yn={}));function jx({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:o,affectsY:a}){const i=e-t,l=n-r,d=[i>0?1:i<0?-1:0,l>0?1:l<0?-1:0];return i&&o&&(d[0]=d[0]*-1),l&&a&&(d[1]=d[1]*-1),d}function vi(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),o=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:o}}function nn(e,t){return Math.max(0,t-e)}function rn(e,t){return Math.max(0,e-t)}function Jr(e,t,n){return Math.max(0,t-e,e-n)}function ki(e,t){return e?!t:t}function Sx(e,t,n,r,o,a,i,l){let{affectsX:d,affectsY:c}=t;const{isHorizontal:u,isVertical:h}=t,f=u&&h,{xSnapped:m,ySnapped:y}=n,{minWidth:S,maxWidth:x,minHeight:b,maxHeight:$}=r,{x:v,y:p,width:M,height:N,aspectRatio:w}=e;let g=Math.floor(u?m-e.pointerX:0),E=Math.floor(h?y-e.pointerY:0);const T=M+(d?-g:g),j=N+(c?-E:E),_=-a[0]*M,I=-a[1]*N;let C=Jr(T,S,x),O=Jr(j,b,$);if(i){let R=0,F=0;d&&g<0?R=nn(v+g+_,i[0][0]):!d&&g>0&&(R=rn(v+T+_,i[1][0])),c&&E<0?F=nn(p+E+I,i[0][1]):!c&&E>0&&(F=rn(p+j+I,i[1][1])),C=Math.max(C,R),O=Math.max(O,F)}if(l){let R=0,F=0;d&&g>0?R=rn(v+g,l[0][0]):!d&&g<0&&(R=nn(v+T,l[1][0])),c&&E>0?F=rn(p+E,l[0][1]):!c&&E<0&&(F=nn(p+j,l[1][1])),C=Math.max(C,R),O=Math.max(O,F)}if(o){if(u){const R=Jr(T/w,b,$)*w;if(C=Math.max(C,R),i){let F=0;!d&&!c||d&&!c&&f?F=rn(p+I+T/w,i[1][1])*w:F=nn(p+I+(d?g:-g)/w,i[0][1])*w,C=Math.max(C,F)}if(l){let F=0;!d&&!c||d&&!c&&f?F=nn(p+T/w,l[1][1])*w:F=rn(p+(d?g:-g)/w,l[0][1])*w,C=Math.max(C,F)}}if(h){const R=Jr(j*w,S,x)/w;if(O=Math.max(O,R),i){let F=0;!d&&!c||c&&!d&&f?F=rn(v+j*w+_,i[1][0])/w:F=nn(v+(c?E:-E)*w+_,i[0][0])/w,O=Math.max(O,F)}if(l){let F=0;!d&&!c||c&&!d&&f?F=nn(v+j*w,l[1][0])/w:F=rn(v+(c?E:-E)*w,l[0][0])/w,O=Math.max(O,F)}}}E=E+(E<0?O:-O),g=g+(g<0?C:-C),o&&(f?T>j*w?E=(ki(d,c)?-g:g)/w:g=(ki(d,c)?-E:E)*w:u?(E=g/w,c=d):(g=E*w,d=c));const A=d?v+g:v,L=c?p+E:p;return{width:M+(d?-g:g),height:N+(c?-E:E),x:a[0]*g*(d?-1:1)+A,y:a[1]*E*(c?-1:1)+L}}const Kc={width:0,height:0,x:0,y:0},Mx={...Kc,pointerX:0,pointerY:0,aspectRatio:1};function $x(e){return[[0,0],[e.measured.width,e.measured.height]]}function Ex(e,t,n){const r=t.position.x+e.position.x,o=t.position.y+e.position.y,a=e.measured.width??0,i=e.measured.height??0,l=n[0]*a,d=n[1]*i;return[[r-l,o-d],[r+a-l,o+i-d]]}function Cx({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:o}){const a=et(e);let i={controlDirection:vi("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:c,boundaries:u,keepAspectRatio:h,resizeDirection:f,onResizeStart:m,onResize:y,onResizeEnd:S,shouldResize:x}){let b={...Kc},$={...Mx};i={boundaries:u,resizeDirection:f,keepAspectRatio:h,controlDirection:vi(c)};let v,p=null,M=[],N,w,g,E=!1;const T=ac().on("start",j=>{const{nodeLookup:_,transform:I,snapGrid:C,snapToGrid:O,nodeOrigin:A,paneDomNode:L}=n();if(v=_.get(t),!v)return;p=L?.getBoundingClientRect()??null;const{xSnapped:R,ySnapped:F}=hr(j.sourceEvent,{transform:I,snapGrid:C,snapToGrid:O,containerBounds:p});b={width:v.measured.width??0,height:v.measured.height??0,x:v.position.x??0,y:v.position.y??0},$={...b,pointerX:R,pointerY:F,aspectRatio:b.width/b.height},N=void 0,v.parentId&&(v.extent==="parent"||v.expandParent)&&(N=_.get(v.parentId),w=N&&v.extent==="parent"?$x(N):void 0),M=[],g=void 0;for(const[W,G]of _)if(G.parentId===t&&(M.push({id:W,position:{...G.position},extent:G.extent}),G.extent==="parent"||G.expandParent)){const Y=Ex(G,v,G.origin??A);g?g=[[Math.min(Y[0][0],g[0][0]),Math.min(Y[0][1],g[0][1])],[Math.max(Y[1][0],g[1][0]),Math.max(Y[1][1],g[1][1])]]:g=Y}m?.(j,{...b})}).on("drag",j=>{const{transform:_,snapGrid:I,snapToGrid:C,nodeOrigin:O}=n(),A=hr(j.sourceEvent,{transform:_,snapGrid:I,snapToGrid:C,containerBounds:p}),L=[];if(!v)return;const{x:R,y:F,width:W,height:G}=b,Y={},ee=v.origin??O,{width:B,height:Z,x:Q,y:K}=Sx($,i.controlDirection,A,i.boundaries,i.keepAspectRatio,ee,w,g),U=B!==W,re=Z!==G,ae=Q!==R&&U,se=K!==F&&re;if(!ae&&!se&&!U&&!re)return;if((ae||se||ee[0]===1||ee[1]===1)&&(Y.x=ae?Q:b.x,Y.y=se?K:b.y,b.x=Y.x,b.y=Y.y,M.length>0)){const oe=Q-R,de=K-F;for(const be of M)be.position={x:be.position.x-oe+ee[0]*(B-W),y:be.position.y-de+ee[1]*(Z-G)},L.push(be)}if((U||re)&&(Y.width=U&&(!i.resizeDirection||i.resizeDirection==="horizontal")?B:b.width,Y.height=re&&(!i.resizeDirection||i.resizeDirection==="vertical")?Z:b.height,b.width=Y.width,b.height=Y.height),N&&v.expandParent){const oe=ee[0]*(Y.width??0);Y.x&&Y.x<oe&&(b.x=oe,$.x=$.x-(Y.x-oe));const de=ee[1]*(Y.height??0);Y.y&&Y.y<de&&(b.y=de,$.y=$.y-(Y.y-de))}const le=jx({width:b.width,prevWidth:W,height:b.height,prevHeight:G,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),ie={...b,direction:le};x?.(j,ie)!==!1&&(E=!0,y?.(j,ie),r(Y,L))}).on("end",j=>{E&&(S?.(j,{...b}),o?.({...b}),E=!1)});a.call(T)}function d(){a.on(".drag",null)}return{update:l,destroy:d}}const _x={},Ni=e=>{let t;const n=new Set,r=(u,h)=>{const f=typeof u=="function"?u(t):u;if(!Object.is(f,t)){const m=t;t=h??(typeof f!="object"||f===null)?f:Object.assign({},t,f),n.forEach(y=>y(t,m))}},o=()=>t,d={setState:r,getState:o,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(_x?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},c=t=e(r,o,d);return d},Px=e=>e?Ni(e):Ni,{useDebugValue:Ax}=Ol,{useSyncExternalStoreWithSelector:Ix}=ld,Tx=e=>e;function Zc(e,t=Tx,n){const r=Ix(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Ax(r),r}const ji=(e,t)=>{const n=Px(e),r=(o,a=t)=>Zc(n,o,a);return Object.assign(r,n),r},Rx=(e,t)=>e?ji(e,t):ji;function Ce(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,o]of e)if(!Object.is(o,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}const Bs=k.createContext(null),Dx=Bs.Provider,Qc=Pt.error001();function we(e,t){const n=k.useContext(Bs);if(n===null)throw new Error(Qc);return Zc(n,e,t)}function Se(){const e=k.useContext(Bs);if(e===null)throw new Error(Qc);return k.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const Si={display:"none"},Lx={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Jc="react-flow__node-desc",eu="react-flow__edge-desc",Ox="react-flow__aria-live",Fx=e=>e.ariaLiveMessage,zx=e=>e.ariaLabelConfig;function Hx({rfId:e}){const t=we(Fx);return s.jsx("div",{id:`${Ox}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:Lx,children:t})}function Bx({rfId:e,disableKeyboardA11y:t}){const n=we(zx);return s.jsxs(s.Fragment,{children:[s.jsx("div",{id:`${Jc}-${e}`,style:Si,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),s.jsx("div",{id:`${eu}-${e}`,style:Si,children:n["edge.a11yDescription.default"]}),!t&&s.jsx(Hx,{rfId:e})]})}const Ws=k.forwardRef(({position:e="top-left",children:t,className:n,style:r,...o},a)=>{const i=`${e}`.split("-");return s.jsx("div",{className:Ie(["react-flow__panel",n,...i]),style:r,ref:a,...o,children:t})});Ws.displayName="Panel";function Wx({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:s.jsx(Ws,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:s.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const qx=e=>{const t=[],n=[];for(const[,r]of e.nodeLookup)r.selected&&t.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&n.push(r);return{selectedNodes:t,selectedEdges:n}},es=e=>e.id;function Vx(e,t){return Ce(e.selectedNodes.map(es),t.selectedNodes.map(es))&&Ce(e.selectedEdges.map(es),t.selectedEdges.map(es))}function Xx({onSelectionChange:e}){const t=Se(),{selectedNodes:n,selectedEdges:r}=we(qx,Vx);return k.useEffect(()=>{const o={nodes:n,edges:r};e?.(o),t.getState().onSelectionChangeHandlers.forEach(a=>a(o))},[n,r,e]),null}const Yx=e=>!!e.onSelectionChangeHandlers;function Gx({onSelectionChange:e}){const t=we(Yx);return e||t?s.jsx(Xx,{onSelectionChange:e}):null}const tu=[0,0],Ux={x:0,y:0,zoom:1},Kx=["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"],Mi=[...Kx,"rfId"],Zx=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}),$i={translateExtent:yr,nodeOrigin:tu,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function Qx(e){const{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:o,setTranslateExtent:a,setNodeExtent:i,reset:l,setDefaultNodesAndEdges:d}=we(Zx,Ce),c=Se();k.useEffect(()=>(d(e.defaultNodes,e.defaultEdges),()=>{u.current=$i,l()}),[]);const u=k.useRef($i);return k.useEffect(()=>{for(const h of Mi){const f=e[h],m=u.current[h];f!==m&&(typeof e[h]>"u"||(h==="nodes"?t(f):h==="edges"?n(f):h==="minZoom"?r(f):h==="maxZoom"?o(f):h==="translateExtent"?a(f):h==="nodeExtent"?i(f):h==="ariaLabelConfig"?c.setState({ariaLabelConfig:Hp(f)}):h==="fitView"?c.setState({fitViewQueued:f}):h==="fitViewOptions"?c.setState({fitViewOptions:f}):c.setState({[h]:f})))}u.current=e},Mi.map(h=>e[h])),null}function Ei(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Jx(e){const[t,n]=k.useState(e==="system"?null:e);return k.useEffect(()=>{if(e!=="system"){n(e);return}const r=Ei(),o=()=>n(r?.matches?"dark":"light");return o(),r?.addEventListener("change",o),()=>{r?.removeEventListener("change",o)}},[e]),t!==null?t:Ei()?.matches?"dark":"light"}const Ci=typeof document<"u"?document:null;function Nr(e=null,t={target:Ci,actInsideInputWithModifier:!0}){const[n,r]=k.useState(!1),o=k.useRef(!1),a=k.useRef(new Set([])),[i,l]=k.useMemo(()=>{if(e!==null){const c=(Array.isArray(e)?e:[e]).filter(h=>typeof h=="string").map(h=>h.replace("+",`
|
|
2
|
+
`).replace(`
|
|
3
|
+
|
|
4
|
+
`,`
|
|
5
|
+
+`).split(`
|
|
6
|
+
`)),u=c.reduce((h,f)=>h.concat(...f),[]);return[c,u]}return[[],[]]},[e]);return k.useEffect(()=>{const d=t?.target??Ci,c=t?.actInsideInputWithModifier??!0;if(e!==null){const u=m=>{if(o.current=m.ctrlKey||m.metaKey||m.shiftKey||m.altKey,(!o.current||o.current&&!c)&&Tc(m))return!1;const S=Pi(m.code,l);if(a.current.add(m[S]),_i(i,a.current,!1)){const x=m.composedPath?.()?.[0]||m.target,b=x?.nodeName==="BUTTON"||x?.nodeName==="A";t.preventDefault!==!1&&(o.current||!b)&&m.preventDefault(),r(!0)}},h=m=>{const y=Pi(m.code,l);_i(i,a.current,!0)?(r(!1),a.current.clear()):a.current.delete(m[y]),m.key==="Meta"&&a.current.clear(),o.current=!1},f=()=>{a.current.clear(),r(!1)};return d?.addEventListener("keydown",u),d?.addEventListener("keyup",h),window.addEventListener("blur",f),window.addEventListener("contextmenu",f),()=>{d?.removeEventListener("keydown",u),d?.removeEventListener("keyup",h),window.removeEventListener("blur",f),window.removeEventListener("contextmenu",f)}}},[e,r]),n}function _i(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(o=>t.has(o)))}function Pi(e,t){return t.includes(e)?"code":"key"}const eg=()=>{const e=Se();return k.useMemo(()=>({zoomIn:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,{duration:t?.duration}):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,{duration:t?.duration}):Promise.resolve(!1)},zoomTo:(t,n)=>{const{panZoom:r}=e.getState();return r?r.scaleTo(t,{duration:n?.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[r,o,a],panZoom:i}=e.getState();return i?(await i.setViewport({x:t.x??r,y:t.y??o,zoom:t.zoom??a},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[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)=>{const{width:r,height:o,minZoom:a,maxZoom:i,panZoom:l}=e.getState(),d=zs(t,r,o,a,i,n?.padding??.1);return l?(await l.setViewport(d,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:r,snapGrid:o,snapToGrid:a,domNode:i}=e.getState();if(!i)return t;const{x:l,y:d}=i.getBoundingClientRect(),c={x:t.x-l,y:t.y-d},u=n.snapGrid??o,h=n.snapToGrid??a;return Ar(c,r,h,u)},flowToScreenPosition:t=>{const{transform:n,domNode:r}=e.getState();if(!r)return t;const{x:o,y:a}=r.getBoundingClientRect(),i=Ss(t,n);return{x:i.x+o,y:i.y+a}}}),[])};function nu(e,t){const n=[],r=new Map,o=[];for(const a of e)if(a.type==="add"){o.push(a);continue}else if(a.type==="remove"||a.type==="replace")r.set(a.id,[a]);else{const i=r.get(a.id);i?i.push(a):r.set(a.id,[a])}for(const a of t){const i=r.get(a.id);if(!i){n.push(a);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const l={...a};for(const d of i)tg(d,l);n.push(l)}return o.length&&o.forEach(a=>{a.index!==void 0?n.splice(a.index,0,{...a.item}):n.push({...a.item})}),n}function tg(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(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 ru(e,t){return nu(e,t)}function su(e,t){return nu(e,t)}function xn(e,t){return{id:e,type:"select",selected:t}}function On(e,t=new Set,n=!1){const r=[];for(const[o,a]of e){const i=t.has(o);!(a.selected===void 0&&!i)&&a.selected!==i&&(n&&(a.selected=i),r.push(xn(a.id,i)))}return r}function Ai({items:e=[],lookup:t}){const n=[],r=new Map(e.map(o=>[o.id,o]));for(const[o,a]of e.entries()){const i=t.get(a.id),l=i?.internals?.userNode??i;l!==void 0&&l!==a&&n.push({id:a.id,item:a,type:"replace"}),l===void 0&&n.push({item:a,type:"add",index:o})}for(const[o]of t)r.get(o)===void 0&&n.push({id:o,type:"remove"});return n}function Ii(e){return{id:e.id,type:"remove"}}const Ti=e=>Pp(e),ng=e=>Mc(e);function ou(e){return k.forwardRef(e)}const rg=typeof window<"u"?k.useLayoutEffect:k.useEffect;function Ri(e){const[t,n]=k.useState(BigInt(0)),[r]=k.useState(()=>sg(()=>n(o=>o+BigInt(1))));return rg(()=>{const o=r.get();o.length&&(e(o),r.reset())},[t]),r}function sg(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const au=k.createContext(null);function og({children:e}){const t=Se(),n=k.useCallback(l=>{const{nodes:d=[],setNodes:c,hasDefaultNodes:u,onNodesChange:h,nodeLookup:f,fitViewQueued:m,onNodesChangeMiddlewareMap:y}=t.getState();let S=d;for(const b of l)S=typeof b=="function"?b(S):b;let x=Ai({items:S,lookup:f});for(const b of y.values())x=b(x);u&&c(S),x.length>0?h?.(x):m&&window.requestAnimationFrame(()=>{const{fitViewQueued:b,nodes:$,setNodes:v}=t.getState();b&&v($)})},[]),r=Ri(n),o=k.useCallback(l=>{const{edges:d=[],setEdges:c,hasDefaultEdges:u,onEdgesChange:h,edgeLookup:f}=t.getState();let m=d;for(const y of l)m=typeof y=="function"?y(m):y;u?c(m):h&&h(Ai({items:m,lookup:f}))},[]),a=Ri(o),i=k.useMemo(()=>({nodeQueue:r,edgeQueue:a}),[]);return s.jsx(au.Provider,{value:i,children:e})}function ag(){const e=k.useContext(au);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const ig=e=>!!e.panZoom;function Ir(){const e=eg(),t=Se(),n=ag(),r=we(ig),o=k.useMemo(()=>{const a=h=>t.getState().nodeLookup.get(h),i=h=>{n.nodeQueue.push(h)},l=h=>{n.edgeQueue.push(h)},d=h=>{const{nodeLookup:f,nodeOrigin:m}=t.getState(),y=Ti(h)?h:f.get(h.id),S=y.parentId?Ac(y.position,y.measured,y.parentId,f,m):y.position,x={...y,position:S,width:y.measured?.width??y.width,height:y.measured?.height??y.height};return Vn(x)},c=(h,f,m={replace:!1})=>{i(y=>y.map(S=>{if(S.id===h){const x=typeof f=="function"?f(S):f;return m.replace&&Ti(x)?x:{...S,...x}}return S}))},u=(h,f,m={replace:!1})=>{l(y=>y.map(S=>{if(S.id===h){const x=typeof f=="function"?f(S):f;return m.replace&&ng(x)?x:{...S,...x}}return S}))};return{getNodes:()=>t.getState().nodes.map(h=>({...h})),getNode:h=>a(h)?.internals.userNode,getInternalNode:a,getEdges:()=>{const{edges:h=[]}=t.getState();return h.map(f=>({...f}))},getEdge:h=>t.getState().edgeLookup.get(h),setNodes:i,setEdges:l,addNodes:h=>{const f=Array.isArray(h)?h:[h];n.nodeQueue.push(m=>[...m,...f])},addEdges:h=>{const f=Array.isArray(h)?h:[h];n.edgeQueue.push(m=>[...m,...f])},toObject:()=>{const{nodes:h=[],edges:f=[],transform:m}=t.getState(),[y,S,x]=m;return{nodes:h.map(b=>({...b})),edges:f.map(b=>({...b})),viewport:{x:y,y:S,zoom:x}}},deleteElements:async({nodes:h=[],edges:f=[]})=>{const{nodes:m,edges:y,onNodesDelete:S,onEdgesDelete:x,triggerNodeChanges:b,triggerEdgeChanges:$,onDelete:v,onBeforeDelete:p}=t.getState(),{nodes:M,edges:N}=await Dp({nodesToRemove:h,edgesToRemove:f,nodes:m,edges:y,onBeforeDelete:p}),w=N.length>0,g=M.length>0;if(w){const E=N.map(Ii);x?.(N),$(E)}if(g){const E=M.map(Ii);S?.(M),b(E)}return(g||w)&&v?.({nodes:M,edges:N}),{deletedNodes:M,deletedEdges:N}},getIntersectingNodes:(h,f=!0,m)=>{const y=ui(h),S=y?h:d(h),x=m!==void 0;return S?(m||t.getState().nodes).filter(b=>{const $=t.getState().nodeLookup.get(b.id);if($&&!y&&(b.id===h.id||!$.internals.positionAbsolute))return!1;const v=Vn(x?b:$),p=vr(v,S);return f&&p>0||p>=v.width*v.height||p>=S.width*S.height}):[]},isNodeIntersecting:(h,f,m=!0)=>{const S=ui(h)?h:d(h);if(!S)return!1;const x=vr(S,f);return m&&x>0||x>=f.width*f.height||x>=S.width*S.height},updateNode:c,updateNodeData:(h,f,m={replace:!1})=>{c(h,y=>{const S=typeof f=="function"?f(y):f;return m.replace?{...y,data:S}:{...y,data:{...y.data,...S}}},m)},updateEdge:u,updateEdgeData:(h,f,m={replace:!1})=>{u(h,y=>{const S=typeof f=="function"?f(y):f;return m.replace?{...y,data:S}:{...y,data:{...y.data,...S}}},m)},getNodesBounds:h=>{const{nodeLookup:f,nodeOrigin:m}=t.getState();return Ap(h,{nodeLookup:f,nodeOrigin:m})},getHandleConnections:({type:h,id:f,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}-${h}${f?`-${f}`:""}`)?.values()??[]),getNodeConnections:({type:h,handleId:f,nodeId:m})=>Array.from(t.getState().connectionLookup.get(`${m}${h?f?`-${h}-${f}`:`-${h}`:""}`)?.values()??[]),fitView:async h=>{const f=t.getState().fitViewResolver??zp();return t.setState({fitViewQueued:!0,fitViewOptions:h,fitViewResolver:f}),n.nodeQueue.push(m=>[...m]),f.promise}}},[]);return k.useMemo(()=>({...o,...e,viewportInitialized:r}),[r])}const Di=e=>e.selected,lg=typeof window<"u"?window:void 0;function cg({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=Se(),{deleteElements:r}=Ir(),o=Nr(e,{actInsideInputWithModifier:!1}),a=Nr(t,{target:lg});k.useEffect(()=>{if(o){const{edges:i,nodes:l}=n.getState();r({nodes:l.filter(Di),edges:i.filter(Di)}),n.setState({nodesSelectionActive:!1})}},[o]),k.useEffect(()=>{n.setState({multiSelectionActive:a})},[a])}function ug(e){const t=Se();k.useEffect(()=>{const n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;const r=va(e.current);(r.height===0||r.width===0)&&t.getState().onError?.("004",Pt.error004()),t.setState({width:r.width||500,height:r.height||500})};if(e.current){n(),window.addEventListener("resize",n);const r=new ResizeObserver(()=>n());return r.observe(e.current),()=>{window.removeEventListener("resize",n),r&&e.current&&r.unobserve(e.current)}}},[])}const qs={position:"absolute",width:"100%",height:"100%",top:0,left:0},dg=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function fg({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:r=!1,panOnScrollSpeed:o=.5,panOnScrollMode:a=wn.Free,zoomOnDoubleClick:i=!0,panOnDrag:l=!0,defaultViewport:d,translateExtent:c,minZoom:u,maxZoom:h,zoomActivationKeyCode:f,preventScrolling:m=!0,children:y,noWheelClassName:S,noPanClassName:x,onViewportChange:b,isControlledViewport:$,paneClickDistance:v,selectionOnDrag:p}){const M=Se(),N=k.useRef(null),{userSelectionActive:w,lib:g,connectionInProgress:E}=we(dg,Ce),T=Nr(f),j=k.useRef();ug(N);const _=k.useCallback(I=>{b?.({x:I[0],y:I[1],zoom:I[2]}),$||M.setState({transform:I})},[b,$]);return k.useEffect(()=>{if(N.current){j.current=Nx({domNode:N.current,minZoom:u,maxZoom:h,translateExtent:c,viewport:d,onDraggingChange:A=>M.setState({paneDragging:A}),onPanZoomStart:(A,L)=>{const{onViewportChangeStart:R,onMoveStart:F}=M.getState();F?.(A,L),R?.(L)},onPanZoom:(A,L)=>{const{onViewportChange:R,onMove:F}=M.getState();F?.(A,L),R?.(L)},onPanZoomEnd:(A,L)=>{const{onViewportChangeEnd:R,onMoveEnd:F}=M.getState();F?.(A,L),R?.(L)}});const{x:I,y:C,zoom:O}=j.current.getViewport();return M.setState({panZoom:j.current,transform:[I,C,O],domNode:N.current.closest(".react-flow")}),()=>{j.current?.destroy()}}},[]),k.useEffect(()=>{j.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:r,panOnScrollSpeed:o,panOnScrollMode:a,zoomOnDoubleClick:i,panOnDrag:l,zoomActivationKeyPressed:T,preventScrolling:m,noPanClassName:x,userSelectionActive:w,noWheelClassName:S,lib:g,onTransformChange:_,connectionInProgress:E,selectionOnDrag:p,paneClickDistance:v})},[e,t,n,r,o,a,i,l,T,m,x,w,S,g,_,E,p,v]),s.jsx("div",{className:"react-flow__renderer",ref:N,style:qs,children:y})}const hg=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function pg(){const{userSelectionActive:e,userSelectionRect:t}=we(hg,Ce);return e&&t?s.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}const Eo=(e,t)=>n=>{n.target===t.current&&e?.(n)},xg=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function gg({isSelecting:e,selectionKeyPressed:t,selectionMode:n=wr.Full,panOnDrag:r,paneClickDistance:o,selectionOnDrag:a,onSelectionStart:i,onSelectionEnd:l,onPaneClick:d,onPaneContextMenu:c,onPaneScroll:u,onPaneMouseEnter:h,onPaneMouseMove:f,onPaneMouseLeave:m,children:y}){const S=Se(),{userSelectionActive:x,elementsSelectable:b,dragging:$,connectionInProgress:v}=we(xg,Ce),p=b&&(e||x),M=k.useRef(null),N=k.useRef(),w=k.useRef(new Set),g=k.useRef(new Set),E=k.useRef(!1),T=R=>{if(E.current||v){E.current=!1;return}d?.(R),S.getState().resetSelectedElements(),S.setState({nodesSelectionActive:!1})},j=R=>{if(Array.isArray(r)&&r?.includes(2)){R.preventDefault();return}c?.(R)},_=u?R=>u(R):void 0,I=R=>{E.current&&(R.stopPropagation(),E.current=!1)},C=R=>{const{domNode:F}=S.getState();if(N.current=F?.getBoundingClientRect(),!N.current)return;const W=R.target===M.current;if(!W&&!!R.target.closest(".nokey")||!e||!(a&&W||t)||R.button!==0||!R.isPrimary)return;R.target?.setPointerCapture?.(R.pointerId),E.current=!1;const{x:ee,y:B}=gt(R.nativeEvent,N.current);S.setState({userSelectionRect:{width:0,height:0,startX:ee,startY:B,x:ee,y:B}}),W||(R.stopPropagation(),R.preventDefault())},O=R=>{const{userSelectionRect:F,transform:W,nodeLookup:G,edgeLookup:Y,connectionLookup:ee,triggerNodeChanges:B,triggerEdgeChanges:Z,defaultEdgeOptions:Q,resetSelectedElements:K}=S.getState();if(!N.current||!F)return;const{x:U,y:re}=gt(R.nativeEvent,N.current),{startX:ae,startY:se}=F;if(!E.current){const de=t?0:o;if(Math.hypot(U-ae,re-se)<=de)return;K(),i?.(R)}E.current=!0;const le={startX:ae,startY:se,x:U<ae?U:ae,y:re<se?re:se,width:Math.abs(U-ae),height:Math.abs(re-se)},ie=w.current,V=g.current;w.current=new Set(wa(G,le,W,n===wr.Partial,!0).map(de=>de.id)),g.current=new Set;const oe=Q?.selectable??!0;for(const de of w.current){const be=ee.get(de);if(be)for(const{edgeId:ke}of be.values()){const _e=Y.get(ke);_e&&(_e.selectable??oe)&&g.current.add(ke)}}if(!di(ie,w.current)){const de=On(G,w.current,!0);B(de)}if(!di(V,g.current)){const de=On(Y,g.current);Z(de)}S.setState({userSelectionRect:le,userSelectionActive:!0,nodesSelectionActive:!1})},A=R=>{R.button===0&&(R.target?.releasePointerCapture?.(R.pointerId),!x&&R.target===M.current&&S.getState().userSelectionRect&&T?.(R),S.setState({userSelectionActive:!1,userSelectionRect:null}),E.current&&(l?.(R),S.setState({nodesSelectionActive:w.current.size>0})))},L=r===!0||Array.isArray(r)&&r.includes(0);return s.jsxs("div",{className:Ie(["react-flow__pane",{draggable:L,dragging:$,selection:e}]),onClick:p?void 0:Eo(T,M),onContextMenu:Eo(j,M),onWheel:Eo(_,M),onPointerEnter:p?void 0:h,onPointerMove:p?O:f,onPointerUp:p?A:void 0,onPointerDownCapture:p?C:void 0,onClickCapture:p?I:void 0,onPointerLeave:m,ref:M,style:qs,children:[y,s.jsx(pg,{})]})}function oa({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:o,unselectNodesAndEdges:a,multiSelectionActive:i,nodeLookup:l,onError:d}=t.getState(),c=l.get(e);if(!c){d?.("012",Pt.error012(e));return}t.setState({nodesSelectionActive:!1}),c.selected?(n||c.selected&&i)&&(a({nodes:[c],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):o([e])}function iu({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:o,isSelectable:a,nodeClickDistance:i}){const l=Se(),[d,c]=k.useState(!1),u=k.useRef();return k.useEffect(()=>{u.current=cx({getStoreItems:()=>l.getState(),onNodeMouseDown:h=>{oa({id:h,store:l,nodeRef:e})},onDragStart:()=>{c(!0)},onDragStop:()=>{c(!1)}})},[]),k.useEffect(()=>{if(t)u.current?.destroy();else if(e.current)return u.current?.update({noDragClassName:n,handleSelector:r,domNode:e.current,isSelectable:a,nodeId:o,nodeClickDistance:i}),()=>{u.current?.destroy()}},[n,r,t,a,e,o]),d}const mg=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function lu(){const e=Se();return k.useCallback(n=>{const{nodeExtent:r,snapToGrid:o,snapGrid:a,nodesDraggable:i,onError:l,updateNodePositions:d,nodeLookup:c,nodeOrigin:u}=e.getState(),h=new Map,f=mg(i),m=o?a[0]:5,y=o?a[1]:5,S=n.direction.x*m*n.factor,x=n.direction.y*y*n.factor;for(const[,b]of c){if(!f(b))continue;let $={x:b.internals.positionAbsolute.x+S,y:b.internals.positionAbsolute.y+x};o&&($=Pr($,a));const{position:v,positionAbsolute:p}=$c({nodeId:b.id,nextPosition:$,nodeLookup:c,nodeExtent:r,nodeOrigin:u,onError:l});b.position=v,b.internals.positionAbsolute=p,h.set(b.id,b)}d(h)},[])}const $a=k.createContext(null),bg=$a.Provider;$a.Consumer;const cu=()=>k.useContext($a),yg=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),wg=(e,t,n)=>r=>{const{connectionClickStartHandle:o,connectionMode:a,connection:i}=r,{fromHandle:l,toHandle:d,isValid:c}=i,u=d?.nodeId===e&&d?.id===t&&d?.type===n;return{connectingFrom:l?.nodeId===e&&l?.id===t&&l?.type===n,connectingTo:u,clickConnecting:o?.nodeId===e&&o?.id===t&&o?.type===n,isPossibleEndHandle:a===Wn.Strict?l?.type!==n:e!==l?.nodeId||t!==l?.id,connectionInProcess:!!l,clickConnectionInProcess:!!o,valid:u&&c}};function vg({type:e="source",position:t=ue.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:o=!0,isConnectableEnd:a=!0,id:i,onConnect:l,children:d,className:c,onMouseDown:u,onTouchStart:h,...f},m){const y=i||null,S=e==="target",x=Se(),b=cu(),{connectOnClick:$,noPanClassName:v,rfId:p}=we(yg,Ce),{connectingFrom:M,connectingTo:N,clickConnecting:w,isPossibleEndHandle:g,connectionInProcess:E,clickConnectionInProcess:T,valid:j}=we(wg(b,y,e),Ce);b||x.getState().onError?.("010",Pt.error010());const _=O=>{const{defaultEdgeOptions:A,onConnect:L,hasDefaultEdges:R}=x.getState(),F={...A,...O};if(R){const{edges:W,setEdges:G}=x.getState();G(Yp(F,W))}L?.(F),l?.(F)},I=O=>{if(!b)return;const A=Rc(O.nativeEvent);if(o&&(A&&O.button===0||!A)){const L=x.getState();sa.onPointerDown(O.nativeEvent,{handleDomNode:O.currentTarget,autoPanOnConnect:L.autoPanOnConnect,connectionMode:L.connectionMode,connectionRadius:L.connectionRadius,domNode:L.domNode,nodeLookup:L.nodeLookup,lib:L.lib,isTarget:S,handleId:y,nodeId:b,flowId:L.rfId,panBy:L.panBy,cancelConnection:L.cancelConnection,onConnectStart:L.onConnectStart,onConnectEnd:L.onConnectEnd,updateConnection:L.updateConnection,onConnect:_,isValidConnection:n||L.isValidConnection,getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,autoPanSpeed:L.autoPanSpeed,dragThreshold:L.connectionDragThreshold})}A?u?.(O):h?.(O)},C=O=>{const{onClickConnectStart:A,onClickConnectEnd:L,connectionClickStartHandle:R,connectionMode:F,isValidConnection:W,lib:G,rfId:Y,nodeLookup:ee,connection:B}=x.getState();if(!b||!R&&!o)return;if(!R){A?.(O.nativeEvent,{nodeId:b,handleId:y,handleType:e}),x.setState({connectionClickStartHandle:{nodeId:b,type:e,id:y}});return}const Z=Ic(O.target),Q=n||W,{connection:K,isValid:U}=sa.isValid(O.nativeEvent,{handle:{nodeId:b,id:y,type:e},connectionMode:F,fromNodeId:R.nodeId,fromHandleId:R.id||null,fromType:R.type,isValidConnection:Q,flowId:Y,doc:Z,lib:G,nodeLookup:ee});U&&K&&_(K);const re=structuredClone(B);delete re.inProgress,re.toPosition=re.toHandle?re.toHandle.position:null,L?.(O,re),x.setState({connectionClickStartHandle:null})};return s.jsx("div",{"data-handleid":y,"data-nodeid":b,"data-handlepos":t,"data-id":`${p}-${b}-${y}-${e}`,className:Ie(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",v,c,{source:!S,target:S,connectable:r,connectablestart:o,connectableend:a,clickconnecting:w,connectingfrom:M,connectingto:N,valid:j,connectionindicator:r&&(!E||g)&&(E||T?a:o)}]),onMouseDown:I,onTouchStart:I,onClick:$?C:void 0,ref:m,...f,children:d})}const ct=k.memo(ou(vg));function kg({data:e,isConnectable:t,sourcePosition:n=ue.Bottom}){return s.jsxs(s.Fragment,{children:[e?.label,s.jsx(ct,{type:"source",position:n,isConnectable:t})]})}function Ng({data:e,isConnectable:t,targetPosition:n=ue.Top,sourcePosition:r=ue.Bottom}){return s.jsxs(s.Fragment,{children:[s.jsx(ct,{type:"target",position:n,isConnectable:t}),e?.label,s.jsx(ct,{type:"source",position:r,isConnectable:t})]})}function jg(){return null}function Sg({data:e,isConnectable:t,targetPosition:n=ue.Top}){return s.jsxs(s.Fragment,{children:[s.jsx(ct,{type:"target",position:n,isConnectable:t}),e?.label]})}const Ms={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Li={input:kg,default:Ng,output:Sg,group:jg};function Mg(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}}const $g=e=>{const{width:t,height:n,x:r,y:o}=_r(e.nodeLookup,{filter:a=>!!a.selected});return{width:xt(t)?t:null,height:xt(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${o}px)`}};function Eg({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=Se(),{width:o,height:a,transformString:i,userSelectionActive:l}=we($g,Ce),d=lu(),c=k.useRef(null);if(k.useEffect(()=>{n||c.current?.focus({preventScroll:!0})},[n]),iu({nodeRef:c}),l||!o||!a)return null;const u=e?f=>{const m=r.getState().nodes.filter(y=>y.selected);e(f,m)}:void 0,h=f=>{Object.prototype.hasOwnProperty.call(Ms,f.key)&&(f.preventDefault(),d({direction:Ms[f.key],factor:f.shiftKey?4:1}))};return s.jsx("div",{className:Ie(["react-flow__nodesselection","react-flow__container",t]),style:{transform:i},children:s.jsx("div",{ref:c,className:"react-flow__nodesselection-rect",onContextMenu:u,tabIndex:n?void 0:-1,onKeyDown:n?void 0:h,style:{width:o,height:a}})})}const Oi=typeof window<"u"?window:void 0,Cg=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function uu({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:o,onPaneContextMenu:a,onPaneScroll:i,paneClickDistance:l,deleteKeyCode:d,selectionKeyCode:c,selectionOnDrag:u,selectionMode:h,onSelectionStart:f,onSelectionEnd:m,multiSelectionKeyCode:y,panActivationKeyCode:S,zoomActivationKeyCode:x,elementsSelectable:b,zoomOnScroll:$,zoomOnPinch:v,panOnScroll:p,panOnScrollSpeed:M,panOnScrollMode:N,zoomOnDoubleClick:w,panOnDrag:g,defaultViewport:E,translateExtent:T,minZoom:j,maxZoom:_,preventScrolling:I,onSelectionContextMenu:C,noWheelClassName:O,noPanClassName:A,disableKeyboardA11y:L,onViewportChange:R,isControlledViewport:F}){const{nodesSelectionActive:W,userSelectionActive:G}=we(Cg,Ce),Y=Nr(c,{target:Oi}),ee=Nr(S,{target:Oi}),B=ee||g,Z=ee||p,Q=u&&B!==!0,K=Y||G||Q;return cg({deleteKeyCode:d,multiSelectionKeyCode:y}),s.jsx(fg,{onPaneContextMenu:a,elementsSelectable:b,zoomOnScroll:$,zoomOnPinch:v,panOnScroll:Z,panOnScrollSpeed:M,panOnScrollMode:N,zoomOnDoubleClick:w,panOnDrag:!Y&&B,defaultViewport:E,translateExtent:T,minZoom:j,maxZoom:_,zoomActivationKeyCode:x,preventScrolling:I,noWheelClassName:O,noPanClassName:A,onViewportChange:R,isControlledViewport:F,paneClickDistance:l,selectionOnDrag:Q,children:s.jsxs(gg,{onSelectionStart:f,onSelectionEnd:m,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:o,onPaneContextMenu:a,onPaneScroll:i,panOnDrag:B,isSelecting:!!K,selectionMode:h,selectionKeyPressed:Y,paneClickDistance:l,selectionOnDrag:Q,children:[e,W&&s.jsx(Eg,{onSelectionContextMenu:C,noPanClassName:A,disableKeyboardA11y:L})]})})}uu.displayName="FlowRenderer";const _g=k.memo(uu),Pg=e=>t=>e?wa(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function Ag(e){return we(k.useCallback(Pg(e),[e]),Ce)}const Ig=e=>e.updateNodeInternals;function Tg(){const e=we(Ig),[t]=k.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const r=new Map;n.forEach(o=>{const a=o.target.getAttribute("data-id");r.set(a,{id:a,nodeElement:o.target,force:!0})}),e(r)}));return k.useEffect(()=>()=>{t?.disconnect()},[t]),t}function Rg({node:e,nodeType:t,hasDimensions:n,resizeObserver:r}){const o=Se(),a=k.useRef(null),i=k.useRef(null),l=k.useRef(e.sourcePosition),d=k.useRef(e.targetPosition),c=k.useRef(t),u=n&&!!e.internals.handleBounds;return k.useEffect(()=>{a.current&&!e.hidden&&(!u||i.current!==a.current)&&(i.current&&r?.unobserve(i.current),r?.observe(a.current),i.current=a.current)},[u,e.hidden]),k.useEffect(()=>()=>{i.current&&(r?.unobserve(i.current),i.current=null)},[]),k.useEffect(()=>{if(a.current){const h=c.current!==t,f=l.current!==e.sourcePosition,m=d.current!==e.targetPosition;(h||f||m)&&(c.current=t,l.current=e.sourcePosition,d.current=e.targetPosition,o.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:a.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),a}function Dg({id:e,onClick:t,onMouseEnter:n,onMouseMove:r,onMouseLeave:o,onContextMenu:a,onDoubleClick:i,nodesDraggable:l,elementsSelectable:d,nodesConnectable:c,nodesFocusable:u,resizeObserver:h,noDragClassName:f,noPanClassName:m,disableKeyboardA11y:y,rfId:S,nodeTypes:x,nodeClickDistance:b,onError:$}){const{node:v,internals:p,isParent:M}=we(U=>{const re=U.nodeLookup.get(e),ae=U.parentLookup.has(e);return{node:re,internals:re.internals,isParent:ae}},Ce);let N=v.type||"default",w=x?.[N]||Li[N];w===void 0&&($?.("003",Pt.error003(N)),N="default",w=x?.default||Li.default);const g=!!(v.draggable||l&&typeof v.draggable>"u"),E=!!(v.selectable||d&&typeof v.selectable>"u"),T=!!(v.connectable||c&&typeof v.connectable>"u"),j=!!(v.focusable||u&&typeof v.focusable>"u"),_=Se(),I=Pc(v),C=Rg({node:v,nodeType:N,hasDimensions:I,resizeObserver:h}),O=iu({nodeRef:C,disabled:v.hidden||!g,noDragClassName:f,handleSelector:v.dragHandle,nodeId:e,isSelectable:E,nodeClickDistance:b}),A=lu();if(v.hidden)return null;const L=Yt(v),R=Mg(v),F=E||g||t||n||r||o,W=n?U=>n(U,{...p.userNode}):void 0,G=r?U=>r(U,{...p.userNode}):void 0,Y=o?U=>o(U,{...p.userNode}):void 0,ee=a?U=>a(U,{...p.userNode}):void 0,B=i?U=>i(U,{...p.userNode}):void 0,Z=U=>{const{selectNodesOnDrag:re,nodeDragThreshold:ae}=_.getState();E&&(!re||!g||ae>0)&&oa({id:e,store:_,nodeRef:C}),t&&t(U,{...p.userNode})},Q=U=>{if(!(Tc(U.nativeEvent)||y)){if(kc.includes(U.key)&&E){const re=U.key==="Escape";oa({id:e,store:_,unselect:re,nodeRef:C})}else if(g&&v.selected&&Object.prototype.hasOwnProperty.call(Ms,U.key)){U.preventDefault();const{ariaLabelConfig:re}=_.getState();_.setState({ariaLiveMessage:re["node.a11yDescription.ariaLiveMessage"]({direction:U.key.replace("Arrow","").toLowerCase(),x:~~p.positionAbsolute.x,y:~~p.positionAbsolute.y})}),A({direction:Ms[U.key],factor:U.shiftKey?4:1})}}},K=()=>{if(y||!C.current?.matches(":focus-visible"))return;const{transform:U,width:re,height:ae,autoPanOnNodeFocus:se,setCenter:le}=_.getState();if(!se)return;wa(new Map([[e,v]]),{x:0,y:0,width:re,height:ae},U,!0).length>0||le(v.position.x+L.width/2,v.position.y+L.height/2,{zoom:U[2]})};return s.jsx("div",{className:Ie(["react-flow__node",`react-flow__node-${N}`,{[m]:g},v.className,{selected:v.selected,selectable:E,parent:M,draggable:g,dragging:O}]),ref:C,style:{zIndex:p.z,transform:`translate(${p.positionAbsolute.x}px,${p.positionAbsolute.y}px)`,pointerEvents:F?"all":"none",visibility:I?"visible":"hidden",...v.style,...R},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:W,onMouseMove:G,onMouseLeave:Y,onContextMenu:ee,onClick:Z,onDoubleClick:B,onKeyDown:j?Q:void 0,tabIndex:j?0:void 0,onFocus:j?K:void 0,role:v.ariaRole??(j?"group":void 0),"aria-roledescription":"node","aria-describedby":y?void 0:`${Jc}-${S}`,"aria-label":v.ariaLabel,...v.domAttributes,children:s.jsx(bg,{value:e,children:s.jsx(w,{id:e,data:v.data,type:N,positionAbsoluteX:p.positionAbsolute.x,positionAbsoluteY:p.positionAbsolute.y,selected:v.selected??!1,selectable:E,draggable:g,deletable:v.deletable??!0,isConnectable:T,sourcePosition:v.sourcePosition,targetPosition:v.targetPosition,dragging:O,dragHandle:v.dragHandle,zIndex:p.z,parentId:v.parentId,...L})})})}var Lg=k.memo(Dg);const Og=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function du(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:o,onError:a}=we(Og,Ce),i=Ag(e.onlyRenderVisibleElements),l=Tg();return s.jsx("div",{className:"react-flow__nodes",style:qs,children:i.map(d=>s.jsx(Lg,{id:d,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:l,nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:o,nodeClickDistance:e.nodeClickDistance,onError:a},d))})}du.displayName="NodeRenderer";const Fg=k.memo(du);function zg(e){return we(k.useCallback(n=>{if(!e)return n.edges.map(o=>o.id);const r=[];if(n.width&&n.height)for(const o of n.edges){const a=n.nodeLookup.get(o.source),i=n.nodeLookup.get(o.target);a&&i&&qp({sourceNode:a,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&r.push(o.id)}return r},[e]),Ce)}const Hg=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return s.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},Bg=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return s.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Fi={[Ns.Arrow]:Hg,[Ns.ArrowClosed]:Bg};function Wg(e){const t=Se();return k.useMemo(()=>Object.prototype.hasOwnProperty.call(Fi,e)?Fi[e]:(t.getState().onError?.("009",Pt.error009(e)),null),[e])}const qg=({id:e,type:t,color:n,width:r=12.5,height:o=12.5,markerUnits:a="strokeWidth",strokeWidth:i,orient:l="auto-start-reverse"})=>{const d=Wg(t);return d?s.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${o}`,viewBox:"-10 -10 20 20",markerUnits:a,orient:l,refX:"0",refY:"0",children:s.jsx(d,{color:n,strokeWidth:i})}):null},fu=({defaultColor:e,rfId:t})=>{const n=we(a=>a.edges),r=we(a=>a.defaultEdgeOptions),o=k.useMemo(()=>Qp(n,{id:t,defaultColor:e,defaultMarkerStart:r?.markerStart,defaultMarkerEnd:r?.markerEnd}),[n,r,t,e]);return o.length?s.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:s.jsx("defs",{children:o.map(a=>s.jsx(qg,{id:a.id,type:a.type,color:a.color,width:a.width,height:a.height,markerUnits:a.markerUnits,strokeWidth:a.strokeWidth,orient:a.orient},a.id))})}):null};fu.displayName="MarkerDefinitions";var Vg=k.memo(fu);function hu({x:e,y:t,label:n,labelStyle:r,labelShowBg:o=!0,labelBgStyle:a,labelBgPadding:i=[2,4],labelBgBorderRadius:l=2,children:d,className:c,...u}){const[h,f]=k.useState({x:1,y:0,width:0,height:0}),m=Ie(["react-flow__edge-textwrapper",c]),y=k.useRef(null);return k.useEffect(()=>{if(y.current){const S=y.current.getBBox();f({x:S.x,y:S.y,width:S.width,height:S.height})}},[n]),n?s.jsxs("g",{transform:`translate(${e-h.width/2} ${t-h.height/2})`,className:m,visibility:h.width?"visible":"hidden",...u,children:[o&&s.jsx("rect",{width:h.width+2*i[0],x:-i[0],y:-i[1],height:h.height+2*i[1],className:"react-flow__edge-textbg",style:a,rx:l,ry:l}),s.jsx("text",{className:"react-flow__edge-text",y:h.height/2,dy:"0.3em",ref:y,style:r,children:n}),d]}):null}hu.displayName="EdgeText";const Xg=k.memo(hu);function Tr({path:e,labelX:t,labelY:n,label:r,labelStyle:o,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:d,interactionWidth:c=20,...u}){return s.jsxs(s.Fragment,{children:[s.jsx("path",{...u,d:e,fill:"none",className:Ie(["react-flow__edge-path",u.className])}),c?s.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:c,className:"react-flow__edge-interaction"}):null,r&&xt(t)&&xt(n)?s.jsx(Xg,{x:t,y:n,label:r,labelStyle:o,labelShowBg:a,labelBgStyle:i,labelBgPadding:l,labelBgBorderRadius:d}):null]})}function zi({pos:e,x1:t,y1:n,x2:r,y2:o}){return e===ue.Left||e===ue.Right?[.5*(t+r),n]:[t,.5*(n+o)]}function pu({sourceX:e,sourceY:t,sourcePosition:n=ue.Bottom,targetX:r,targetY:o,targetPosition:a=ue.Top}){const[i,l]=zi({pos:n,x1:e,y1:t,x2:r,y2:o}),[d,c]=zi({pos:a,x1:r,y1:o,x2:e,y2:t}),[u,h,f,m]=Dc({sourceX:e,sourceY:t,targetX:r,targetY:o,sourceControlX:i,sourceControlY:l,targetControlX:d,targetControlY:c});return[`M${e},${t} C${i},${l} ${d},${c} ${r},${o}`,u,h,f,m]}function xu(e){return k.memo(({id:t,sourceX:n,sourceY:r,targetX:o,targetY:a,sourcePosition:i,targetPosition:l,label:d,labelStyle:c,labelShowBg:u,labelBgStyle:h,labelBgPadding:f,labelBgBorderRadius:m,style:y,markerEnd:S,markerStart:x,interactionWidth:b})=>{const[$,v,p]=pu({sourceX:n,sourceY:r,sourcePosition:i,targetX:o,targetY:a,targetPosition:l}),M=e.isInternal?void 0:t;return s.jsx(Tr,{id:M,path:$,labelX:v,labelY:p,label:d,labelStyle:c,labelShowBg:u,labelBgStyle:h,labelBgPadding:f,labelBgBorderRadius:m,style:y,markerEnd:S,markerStart:x,interactionWidth:b})})}const Yg=xu({isInternal:!1}),gu=xu({isInternal:!0});Yg.displayName="SimpleBezierEdge";gu.displayName="SimpleBezierEdgeInternal";function mu(e){return k.memo(({id:t,sourceX:n,sourceY:r,targetX:o,targetY:a,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:c,labelBgPadding:u,labelBgBorderRadius:h,style:f,sourcePosition:m=ue.Bottom,targetPosition:y=ue.Top,markerEnd:S,markerStart:x,pathOptions:b,interactionWidth:$})=>{const[v,p,M]=ta({sourceX:n,sourceY:r,sourcePosition:m,targetX:o,targetY:a,targetPosition:y,borderRadius:b?.borderRadius,offset:b?.offset,stepPosition:b?.stepPosition}),N=e.isInternal?void 0:t;return s.jsx(Tr,{id:N,path:v,labelX:p,labelY:M,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:c,labelBgPadding:u,labelBgBorderRadius:h,style:f,markerEnd:S,markerStart:x,interactionWidth:$})})}const bu=mu({isInternal:!1}),yu=mu({isInternal:!0});bu.displayName="SmoothStepEdge";yu.displayName="SmoothStepEdgeInternal";function wu(e){return k.memo(({id:t,...n})=>{const r=e.isInternal?void 0:t;return s.jsx(bu,{...n,id:r,pathOptions:k.useMemo(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}const Gg=wu({isInternal:!1}),vu=wu({isInternal:!0});Gg.displayName="StepEdge";vu.displayName="StepEdgeInternal";function ku(e){return k.memo(({id:t,sourceX:n,sourceY:r,targetX:o,targetY:a,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:c,labelBgPadding:u,labelBgBorderRadius:h,style:f,markerEnd:m,markerStart:y,interactionWidth:S})=>{const[x,b,$]=Fc({sourceX:n,sourceY:r,targetX:o,targetY:a}),v=e.isInternal?void 0:t;return s.jsx(Tr,{id:v,path:x,labelX:b,labelY:$,label:i,labelStyle:l,labelShowBg:d,labelBgStyle:c,labelBgPadding:u,labelBgBorderRadius:h,style:f,markerEnd:m,markerStart:y,interactionWidth:S})})}const Ug=ku({isInternal:!1}),Nu=ku({isInternal:!0});Ug.displayName="StraightEdge";Nu.displayName="StraightEdgeInternal";function ju(e){return k.memo(({id:t,sourceX:n,sourceY:r,targetX:o,targetY:a,sourcePosition:i=ue.Bottom,targetPosition:l=ue.Top,label:d,labelStyle:c,labelShowBg:u,labelBgStyle:h,labelBgPadding:f,labelBgBorderRadius:m,style:y,markerEnd:S,markerStart:x,pathOptions:b,interactionWidth:$})=>{const[v,p,M]=Lc({sourceX:n,sourceY:r,sourcePosition:i,targetX:o,targetY:a,targetPosition:l,curvature:b?.curvature}),N=e.isInternal?void 0:t;return s.jsx(Tr,{id:N,path:v,labelX:p,labelY:M,label:d,labelStyle:c,labelShowBg:u,labelBgStyle:h,labelBgPadding:f,labelBgBorderRadius:m,style:y,markerEnd:S,markerStart:x,interactionWidth:$})})}const Kg=ju({isInternal:!1}),Su=ju({isInternal:!0});Kg.displayName="BezierEdge";Su.displayName="BezierEdgeInternal";const Hi={default:Su,straight:Nu,step:vu,smoothstep:yu,simplebezier:gu},Bi={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},Zg=(e,t,n)=>n===ue.Left?e-t:n===ue.Right?e+t:e,Qg=(e,t,n)=>n===ue.Top?e-t:n===ue.Bottom?e+t:e,Wi="react-flow__edgeupdater";function qi({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:o,onMouseEnter:a,onMouseOut:i,type:l}){return s.jsx("circle",{onMouseDown:o,onMouseEnter:a,onMouseOut:i,className:Ie([Wi,`${Wi}-${l}`]),cx:Zg(t,r,e),cy:Qg(n,r,e),r,stroke:"transparent",fill:"transparent"})}function Jg({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:r,sourceY:o,targetX:a,targetY:i,sourcePosition:l,targetPosition:d,onReconnect:c,onReconnectStart:u,onReconnectEnd:h,setReconnecting:f,setUpdateHover:m}){const y=Se(),S=(p,M)=>{if(p.button!==0)return;const{autoPanOnConnect:N,domNode:w,isValidConnection:g,connectionMode:E,connectionRadius:T,lib:j,onConnectStart:_,onConnectEnd:I,cancelConnection:C,nodeLookup:O,rfId:A,panBy:L,updateConnection:R}=y.getState(),F=M.type==="target",W=(ee,B)=>{f(!1),h?.(ee,n,M.type,B)},G=ee=>c?.(n,ee),Y=(ee,B)=>{f(!0),u?.(p,n,M.type),_?.(ee,B)};sa.onPointerDown(p.nativeEvent,{autoPanOnConnect:N,connectionMode:E,connectionRadius:T,domNode:w,handleId:M.id,nodeId:M.nodeId,nodeLookup:O,isTarget:F,edgeUpdaterType:M.type,lib:j,flowId:A,cancelConnection:C,panBy:L,isValidConnection:g,onConnect:G,onConnectStart:Y,onConnectEnd:I,onReconnectEnd:W,updateConnection:R,getTransform:()=>y.getState().transform,getFromHandle:()=>y.getState().connection.fromHandle,dragThreshold:y.getState().connectionDragThreshold,handleDomNode:p.currentTarget})},x=p=>S(p,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),b=p=>S(p,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),$=()=>m(!0),v=()=>m(!1);return s.jsxs(s.Fragment,{children:[(e===!0||e==="source")&&s.jsx(qi,{position:l,centerX:r,centerY:o,radius:t,onMouseDown:x,onMouseEnter:$,onMouseOut:v,type:"source"}),(e===!0||e==="target")&&s.jsx(qi,{position:d,centerX:a,centerY:i,radius:t,onMouseDown:b,onMouseEnter:$,onMouseOut:v,type:"target"})]})}function em({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:r,onClick:o,onDoubleClick:a,onContextMenu:i,onMouseEnter:l,onMouseMove:d,onMouseLeave:c,reconnectRadius:u,onReconnect:h,onReconnectStart:f,onReconnectEnd:m,rfId:y,edgeTypes:S,noPanClassName:x,onError:b,disableKeyboardA11y:$}){let v=we(le=>le.edgeLookup.get(e));const p=we(le=>le.defaultEdgeOptions);v=p?{...p,...v}:v;let M=v.type||"default",N=S?.[M]||Hi[M];N===void 0&&(b?.("011",Pt.error011(M)),M="default",N=S?.default||Hi.default);const w=!!(v.focusable||t&&typeof v.focusable>"u"),g=typeof h<"u"&&(v.reconnectable||n&&typeof v.reconnectable>"u"),E=!!(v.selectable||r&&typeof v.selectable>"u"),T=k.useRef(null),[j,_]=k.useState(!1),[I,C]=k.useState(!1),O=Se(),{zIndex:A,sourceX:L,sourceY:R,targetX:F,targetY:W,sourcePosition:G,targetPosition:Y}=we(k.useCallback(le=>{const ie=le.nodeLookup.get(v.source),V=le.nodeLookup.get(v.target);if(!ie||!V)return{zIndex:v.zIndex,...Bi};const oe=Zp({id:e,sourceNode:ie,targetNode:V,sourceHandle:v.sourceHandle||null,targetHandle:v.targetHandle||null,connectionMode:le.connectionMode,onError:b});return{zIndex:Wp({selected:v.selected,zIndex:v.zIndex,sourceNode:ie,targetNode:V,elevateOnSelect:le.elevateEdgesOnSelect,zIndexMode:le.zIndexMode}),...oe||Bi}},[v.source,v.target,v.sourceHandle,v.targetHandle,v.selected,v.zIndex]),Ce),ee=k.useMemo(()=>v.markerStart?`url('#${na(v.markerStart,y)}')`:void 0,[v.markerStart,y]),B=k.useMemo(()=>v.markerEnd?`url('#${na(v.markerEnd,y)}')`:void 0,[v.markerEnd,y]);if(v.hidden||L===null||R===null||F===null||W===null)return null;const Z=le=>{const{addSelectedEdges:ie,unselectNodesAndEdges:V,multiSelectionActive:oe}=O.getState();E&&(O.setState({nodesSelectionActive:!1}),v.selected&&oe?(V({nodes:[],edges:[v]}),T.current?.blur()):ie([e])),o&&o(le,v)},Q=a?le=>{a(le,{...v})}:void 0,K=i?le=>{i(le,{...v})}:void 0,U=l?le=>{l(le,{...v})}:void 0,re=d?le=>{d(le,{...v})}:void 0,ae=c?le=>{c(le,{...v})}:void 0,se=le=>{if(!$&&kc.includes(le.key)&&E){const{unselectNodesAndEdges:ie,addSelectedEdges:V}=O.getState();le.key==="Escape"?(T.current?.blur(),ie({edges:[v]})):V([e])}};return s.jsx("svg",{style:{zIndex:A},children:s.jsxs("g",{className:Ie(["react-flow__edge",`react-flow__edge-${M}`,v.className,x,{selected:v.selected,animated:v.animated,inactive:!E&&!o,updating:j,selectable:E}]),onClick:Z,onDoubleClick:Q,onContextMenu:K,onMouseEnter:U,onMouseMove:re,onMouseLeave:ae,onKeyDown:w?se:void 0,tabIndex:w?0:void 0,role:v.ariaRole??(w?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":v.ariaLabel===null?void 0:v.ariaLabel||`Edge from ${v.source} to ${v.target}`,"aria-describedby":w?`${eu}-${y}`:void 0,ref:T,...v.domAttributes,children:[!I&&s.jsx(N,{id:e,source:v.source,target:v.target,type:v.type,selected:v.selected,animated:v.animated,selectable:E,deletable:v.deletable??!0,label:v.label,labelStyle:v.labelStyle,labelShowBg:v.labelShowBg,labelBgStyle:v.labelBgStyle,labelBgPadding:v.labelBgPadding,labelBgBorderRadius:v.labelBgBorderRadius,sourceX:L,sourceY:R,targetX:F,targetY:W,sourcePosition:G,targetPosition:Y,data:v.data,style:v.style,sourceHandleId:v.sourceHandle,targetHandleId:v.targetHandle,markerStart:ee,markerEnd:B,pathOptions:"pathOptions"in v?v.pathOptions:void 0,interactionWidth:v.interactionWidth}),g&&s.jsx(Jg,{edge:v,isReconnectable:g,reconnectRadius:u,onReconnect:h,onReconnectStart:f,onReconnectEnd:m,sourceX:L,sourceY:R,targetX:F,targetY:W,sourcePosition:G,targetPosition:Y,setUpdateHover:_,setReconnecting:C})]})})}var tm=k.memo(em);const nm=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Mu({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:r,noPanClassName:o,onReconnect:a,onEdgeContextMenu:i,onEdgeMouseEnter:l,onEdgeMouseMove:d,onEdgeMouseLeave:c,onEdgeClick:u,reconnectRadius:h,onEdgeDoubleClick:f,onReconnectStart:m,onReconnectEnd:y,disableKeyboardA11y:S}){const{edgesFocusable:x,edgesReconnectable:b,elementsSelectable:$,onError:v}=we(nm,Ce),p=zg(t);return s.jsxs("div",{className:"react-flow__edges",children:[s.jsx(Vg,{defaultColor:e,rfId:n}),p.map(M=>s.jsx(tm,{id:M,edgesFocusable:x,edgesReconnectable:b,elementsSelectable:$,noPanClassName:o,onReconnect:a,onContextMenu:i,onMouseEnter:l,onMouseMove:d,onMouseLeave:c,onClick:u,reconnectRadius:h,onDoubleClick:f,onReconnectStart:m,onReconnectEnd:y,rfId:n,onError:v,edgeTypes:r,disableKeyboardA11y:S},M))]})}Mu.displayName="EdgeRenderer";const rm=k.memo(Mu),sm=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function om({children:e}){const t=we(sm);return s.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function am(e){const t=Ir(),n=k.useRef(!1);k.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const im=e=>e.panZoom?.syncViewport;function lm(e){const t=we(im),n=Se();return k.useEffect(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function cm(e){return e.connection.inProgress?{...e.connection,to:Ar(e.connection.to,e.transform)}:{...e.connection}}function um(e){return cm}function dm(e){const t=um();return we(t,Ce)}const fm=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function hm({containerStyle:e,style:t,type:n,component:r}){const{nodesConnectable:o,width:a,height:i,isValid:l,inProgress:d}=we(fm,Ce);return!(a&&o&&d)?null:s.jsx("svg",{style:e,width:a,height:i,className:"react-flow__connectionline react-flow__container",children:s.jsx("g",{className:Ie(["react-flow__connection",Sc(l)]),children:s.jsx($u,{style:t,type:n,CustomComponent:r,isValid:l})})})}const $u=({style:e,type:t=on.Bezier,CustomComponent:n,isValid:r})=>{const{inProgress:o,from:a,fromNode:i,fromHandle:l,fromPosition:d,to:c,toNode:u,toHandle:h,toPosition:f,pointer:m}=dm();if(!o)return;if(n)return s.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:i,fromHandle:l,fromX:a.x,fromY:a.y,toX:c.x,toY:c.y,fromPosition:d,toPosition:f,connectionStatus:Sc(r),toNode:u,toHandle:h,pointer:m});let y="";const S={sourceX:a.x,sourceY:a.y,sourcePosition:d,targetX:c.x,targetY:c.y,targetPosition:f};switch(t){case on.Bezier:[y]=Lc(S);break;case on.SimpleBezier:[y]=pu(S);break;case on.Step:[y]=ta({...S,borderRadius:0});break;case on.SmoothStep:[y]=ta(S);break;default:[y]=Fc(S)}return s.jsx("path",{d:y,fill:"none",className:"react-flow__connection-path",style:e})};$u.displayName="ConnectionLine";const pm={};function Vi(e=pm){k.useRef(e),Se(),k.useEffect(()=>{},[e])}function xm(){Se(),k.useRef(!1),k.useEffect(()=>{},[])}function Eu({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:r,onEdgeClick:o,onNodeDoubleClick:a,onEdgeDoubleClick:i,onNodeMouseEnter:l,onNodeMouseMove:d,onNodeMouseLeave:c,onNodeContextMenu:u,onSelectionContextMenu:h,onSelectionStart:f,onSelectionEnd:m,connectionLineType:y,connectionLineStyle:S,connectionLineComponent:x,connectionLineContainerStyle:b,selectionKeyCode:$,selectionOnDrag:v,selectionMode:p,multiSelectionKeyCode:M,panActivationKeyCode:N,zoomActivationKeyCode:w,deleteKeyCode:g,onlyRenderVisibleElements:E,elementsSelectable:T,defaultViewport:j,translateExtent:_,minZoom:I,maxZoom:C,preventScrolling:O,defaultMarkerColor:A,zoomOnScroll:L,zoomOnPinch:R,panOnScroll:F,panOnScrollSpeed:W,panOnScrollMode:G,zoomOnDoubleClick:Y,panOnDrag:ee,onPaneClick:B,onPaneMouseEnter:Z,onPaneMouseMove:Q,onPaneMouseLeave:K,onPaneScroll:U,onPaneContextMenu:re,paneClickDistance:ae,nodeClickDistance:se,onEdgeContextMenu:le,onEdgeMouseEnter:ie,onEdgeMouseMove:V,onEdgeMouseLeave:oe,reconnectRadius:de,onReconnect:be,onReconnectStart:ke,onReconnectEnd:_e,noDragClassName:Te,noWheelClassName:ze,noPanClassName:Xe,disableKeyboardA11y:He,nodeExtent:Ke,rfId:It,viewport:Be,onViewportChange:Ye}){return Vi(e),Vi(t),xm(),am(n),lm(Be),s.jsx(_g,{onPaneClick:B,onPaneMouseEnter:Z,onPaneMouseMove:Q,onPaneMouseLeave:K,onPaneContextMenu:re,onPaneScroll:U,paneClickDistance:ae,deleteKeyCode:g,selectionKeyCode:$,selectionOnDrag:v,selectionMode:p,onSelectionStart:f,onSelectionEnd:m,multiSelectionKeyCode:M,panActivationKeyCode:N,zoomActivationKeyCode:w,elementsSelectable:T,zoomOnScroll:L,zoomOnPinch:R,zoomOnDoubleClick:Y,panOnScroll:F,panOnScrollSpeed:W,panOnScrollMode:G,panOnDrag:ee,defaultViewport:j,translateExtent:_,minZoom:I,maxZoom:C,onSelectionContextMenu:h,preventScrolling:O,noDragClassName:Te,noWheelClassName:ze,noPanClassName:Xe,disableKeyboardA11y:He,onViewportChange:Ye,isControlledViewport:!!Be,children:s.jsxs(om,{children:[s.jsx(rm,{edgeTypes:t,onEdgeClick:o,onEdgeDoubleClick:i,onReconnect:be,onReconnectStart:ke,onReconnectEnd:_e,onlyRenderVisibleElements:E,onEdgeContextMenu:le,onEdgeMouseEnter:ie,onEdgeMouseMove:V,onEdgeMouseLeave:oe,reconnectRadius:de,defaultMarkerColor:A,noPanClassName:Xe,disableKeyboardA11y:He,rfId:It}),s.jsx(hm,{style:S,type:y,component:x,containerStyle:b}),s.jsx("div",{className:"react-flow__edgelabel-renderer"}),s.jsx(Fg,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:d,onNodeMouseLeave:c,onNodeContextMenu:u,nodeClickDistance:se,onlyRenderVisibleElements:E,noPanClassName:Xe,noDragClassName:Te,disableKeyboardA11y:He,nodeExtent:Ke,rfId:It}),s.jsx("div",{className:"react-flow__viewport-portal"})]})})}Eu.displayName="GraphView";const gm=k.memo(Eu),Xi=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:d=.5,maxZoom:c=2,nodeOrigin:u,nodeExtent:h,zIndexMode:f="basic"}={})=>{const m=new Map,y=new Map,S=new Map,x=new Map,b=r??t??[],$=n??e??[],v=u??[0,0],p=h??yr;Bc(S,x,b);const M=ra($,m,y,{nodeOrigin:v,nodeExtent:p,zIndexMode:f});let N=[0,0,1];if(i&&o&&a){const w=_r(m,{filter:j=>!!((j.width||j.initialWidth)&&(j.height||j.initialHeight))}),{x:g,y:E,zoom:T}=zs(w,o,a,d,c,l?.padding??.1);N=[g,E,T]}return{rfId:"1",width:o??0,height:a??0,transform:N,nodes:$,nodesInitialized:M,nodeLookup:m,parentLookup:y,edges:b,edgeLookup:x,connectionLookup:S,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:d,maxZoom:c,translateExtent:yr,nodeExtent:p,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Wn.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:v,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:i??!1,fitViewOptions:l,fitViewResolver:null,connection:{...jc},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Lp,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Nc,zIndexMode:f,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},mm=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:d,maxZoom:c,nodeOrigin:u,nodeExtent:h,zIndexMode:f})=>Rx((m,y)=>{async function S(){const{nodeLookup:x,panZoom:b,fitViewOptions:$,fitViewResolver:v,width:p,height:M,minZoom:N,maxZoom:w}=y();b&&(await Rp({nodes:x,width:p,height:M,panZoom:b,minZoom:N,maxZoom:w},$),v?.resolve(!0),m({fitViewResolver:null}))}return{...Xi({nodes:e,edges:t,width:o,height:a,fitView:i,fitViewOptions:l,minZoom:d,maxZoom:c,nodeOrigin:u,nodeExtent:h,defaultNodes:n,defaultEdges:r,zIndexMode:f}),setNodes:x=>{const{nodeLookup:b,parentLookup:$,nodeOrigin:v,elevateNodesOnSelect:p,fitViewQueued:M,zIndexMode:N}=y(),w=ra(x,b,$,{nodeOrigin:v,nodeExtent:h,elevateNodesOnSelect:p,checkEquality:!0,zIndexMode:N});M&&w?(S(),m({nodes:x,nodesInitialized:w,fitViewQueued:!1,fitViewOptions:void 0})):m({nodes:x,nodesInitialized:w})},setEdges:x=>{const{connectionLookup:b,edgeLookup:$}=y();Bc(b,$,x),m({edges:x})},setDefaultNodesAndEdges:(x,b)=>{if(x){const{setNodes:$}=y();$(x),m({hasDefaultNodes:!0})}if(b){const{setEdges:$}=y();$(b),m({hasDefaultEdges:!0})}},updateNodeInternals:x=>{const{triggerNodeChanges:b,nodeLookup:$,parentLookup:v,domNode:p,nodeOrigin:M,nodeExtent:N,debug:w,fitViewQueued:g,zIndexMode:E}=y(),{changes:T,updatedInternals:j}=ox(x,$,v,p,M,N,E);j&&(tx($,v,{nodeOrigin:M,nodeExtent:N,zIndexMode:E}),g?(S(),m({fitViewQueued:!1,fitViewOptions:void 0})):m({}),T?.length>0&&(w&&console.log("React Flow: trigger node changes",T),b?.(T)))},updateNodePositions:(x,b=!1)=>{const $=[];let v=[];const{nodeLookup:p,triggerNodeChanges:M,connection:N,updateConnection:w,onNodesChangeMiddlewareMap:g}=y();for(const[E,T]of x){const j=p.get(E),_=!!(j?.expandParent&&j?.parentId&&T?.position),I={id:E,type:"position",position:_?{x:Math.max(0,T.position.x),y:Math.max(0,T.position.y)}:T.position,dragging:b};if(j&&N.inProgress&&N.fromNode.id===j.id){const C=Mn(j,N.fromHandle,ue.Left,!0);w({...N,from:C})}_&&j.parentId&&$.push({id:E,parentId:j.parentId,rect:{...T.internals.positionAbsolute,width:T.measured.width??0,height:T.measured.height??0}}),v.push(I)}if($.length>0){const{parentLookup:E,nodeOrigin:T}=y(),j=Ma($,p,E,T);v.push(...j)}for(const E of g.values())v=E(v);M(v)},triggerNodeChanges:x=>{const{onNodesChange:b,setNodes:$,nodes:v,hasDefaultNodes:p,debug:M}=y();if(x?.length){if(p){const N=ru(x,v);$(N)}M&&console.log("React Flow: trigger node changes",x),b?.(x)}},triggerEdgeChanges:x=>{const{onEdgesChange:b,setEdges:$,edges:v,hasDefaultEdges:p,debug:M}=y();if(x?.length){if(p){const N=su(x,v);$(N)}M&&console.log("React Flow: trigger edge changes",x),b?.(x)}},addSelectedNodes:x=>{const{multiSelectionActive:b,edgeLookup:$,nodeLookup:v,triggerNodeChanges:p,triggerEdgeChanges:M}=y();if(b){const N=x.map(w=>xn(w,!0));p(N);return}p(On(v,new Set([...x]),!0)),M(On($))},addSelectedEdges:x=>{const{multiSelectionActive:b,edgeLookup:$,nodeLookup:v,triggerNodeChanges:p,triggerEdgeChanges:M}=y();if(b){const N=x.map(w=>xn(w,!0));M(N);return}M(On($,new Set([...x]))),p(On(v,new Set,!0))},unselectNodesAndEdges:({nodes:x,edges:b}={})=>{const{edges:$,nodes:v,nodeLookup:p,triggerNodeChanges:M,triggerEdgeChanges:N}=y(),w=x||v,g=b||$,E=w.map(j=>{const _=p.get(j.id);return _&&(_.selected=!1),xn(j.id,!1)}),T=g.map(j=>xn(j.id,!1));M(E),N(T)},setMinZoom:x=>{const{panZoom:b,maxZoom:$}=y();b?.setScaleExtent([x,$]),m({minZoom:x})},setMaxZoom:x=>{const{panZoom:b,minZoom:$}=y();b?.setScaleExtent([$,x]),m({maxZoom:x})},setTranslateExtent:x=>{y().panZoom?.setTranslateExtent(x),m({translateExtent:x})},resetSelectedElements:()=>{const{edges:x,nodes:b,triggerNodeChanges:$,triggerEdgeChanges:v,elementsSelectable:p}=y();if(!p)return;const M=b.reduce((w,g)=>g.selected?[...w,xn(g.id,!1)]:w,[]),N=x.reduce((w,g)=>g.selected?[...w,xn(g.id,!1)]:w,[]);$(M),v(N)},setNodeExtent:x=>{const{nodes:b,nodeLookup:$,parentLookup:v,nodeOrigin:p,elevateNodesOnSelect:M,nodeExtent:N,zIndexMode:w}=y();x[0][0]===N[0][0]&&x[0][1]===N[0][1]&&x[1][0]===N[1][0]&&x[1][1]===N[1][1]||(ra(b,$,v,{nodeOrigin:p,nodeExtent:x,elevateNodesOnSelect:M,checkEquality:!1,zIndexMode:w}),m({nodeExtent:x}))},panBy:x=>{const{transform:b,width:$,height:v,panZoom:p,translateExtent:M}=y();return ax({delta:x,panZoom:p,transform:b,translateExtent:M,width:$,height:v})},setCenter:async(x,b,$)=>{const{width:v,height:p,maxZoom:M,panZoom:N}=y();if(!N)return Promise.resolve(!1);const w=typeof $?.zoom<"u"?$.zoom:M;return await N.setViewport({x:v/2-x*w,y:p/2-b*w,zoom:w},{duration:$?.duration,ease:$?.ease,interpolate:$?.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{m({connection:{...jc}})},updateConnection:x=>{m({connection:x})},reset:()=>m({...Xi()})}},Object.is);function Cu({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:r,initialWidth:o,initialHeight:a,initialMinZoom:i,initialMaxZoom:l,initialFitViewOptions:d,fitView:c,nodeOrigin:u,nodeExtent:h,zIndexMode:f,children:m}){const[y]=k.useState(()=>mm({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:o,height:a,fitView:c,minZoom:i,maxZoom:l,fitViewOptions:d,nodeOrigin:u,nodeExtent:h,zIndexMode:f}));return s.jsx(Dx,{value:y,children:s.jsx(og,{children:m})})}function bm({children:e,nodes:t,edges:n,defaultNodes:r,defaultEdges:o,width:a,height:i,fitView:l,fitViewOptions:d,minZoom:c,maxZoom:u,nodeOrigin:h,nodeExtent:f,zIndexMode:m}){return k.useContext(Bs)?s.jsx(s.Fragment,{children:e}):s.jsx(Cu,{initialNodes:t,initialEdges:n,defaultNodes:r,defaultEdges:o,initialWidth:a,initialHeight:i,fitView:l,initialFitViewOptions:d,initialMinZoom:c,initialMaxZoom:u,nodeOrigin:h,nodeExtent:f,zIndexMode:m,children:e})}const ym={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function wm({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:o,nodeTypes:a,edgeTypes:i,onNodeClick:l,onEdgeClick:d,onInit:c,onMove:u,onMoveStart:h,onMoveEnd:f,onConnect:m,onConnectStart:y,onConnectEnd:S,onClickConnectStart:x,onClickConnectEnd:b,onNodeMouseEnter:$,onNodeMouseMove:v,onNodeMouseLeave:p,onNodeContextMenu:M,onNodeDoubleClick:N,onNodeDragStart:w,onNodeDrag:g,onNodeDragStop:E,onNodesDelete:T,onEdgesDelete:j,onDelete:_,onSelectionChange:I,onSelectionDragStart:C,onSelectionDrag:O,onSelectionDragStop:A,onSelectionContextMenu:L,onSelectionStart:R,onSelectionEnd:F,onBeforeDelete:W,connectionMode:G,connectionLineType:Y=on.Bezier,connectionLineStyle:ee,connectionLineComponent:B,connectionLineContainerStyle:Z,deleteKeyCode:Q="Backspace",selectionKeyCode:K="Shift",selectionOnDrag:U=!1,selectionMode:re=wr.Full,panActivationKeyCode:ae="Space",multiSelectionKeyCode:se=kr()?"Meta":"Control",zoomActivationKeyCode:le=kr()?"Meta":"Control",snapToGrid:ie,snapGrid:V,onlyRenderVisibleElements:oe=!1,selectNodesOnDrag:de,nodesDraggable:be,autoPanOnNodeFocus:ke,nodesConnectable:_e,nodesFocusable:Te,nodeOrigin:ze=tu,edgesFocusable:Xe,edgesReconnectable:He,elementsSelectable:Ke=!0,defaultViewport:It=Ux,minZoom:Be=.5,maxZoom:Ye=2,translateExtent:ut=yr,preventScrolling:Tt=!0,nodeExtent:rt,defaultMarkerColor:En="#b1b1b7",zoomOnScroll:Ys=!0,zoomOnPinch:Gs=!0,panOnScroll:Re=!1,panOnScrollSpeed:Dr=.5,panOnScrollMode:Us=wn.Free,zoomOnDoubleClick:un=!0,panOnDrag:Ee=!0,onPaneClick:Ks,onPaneMouseEnter:Gt,onPaneMouseMove:st,onPaneMouseLeave:Zs,onPaneScroll:Gn,onPaneContextMenu:Qs,paneClickDistance:Js=1,nodeClickDistance:eo=0,children:Ut,onReconnect:to,onReconnectStart:Cn,onReconnectEnd:Rt,onEdgeContextMenu:Kt,onEdgeDoubleClick:Lr,onEdgeMouseEnter:no,onEdgeMouseMove:ro,onEdgeMouseLeave:so,reconnectRadius:Un=10,onNodesChange:oo,onEdgesChange:Dt,noDragClassName:ao="nodrag",noWheelClassName:Or="nowheel",noPanClassName:yt="nopan",fitView:Lt,fitViewOptions:Fr,connectOnClick:io,attributionPosition:ot,proOptions:Zt,defaultEdgeOptions:_n,elevateNodesOnSelect:Qt=!0,elevateEdgesOnSelect:Le=!1,disableKeyboardA11y:Kn=!1,autoPanOnConnect:Jt,autoPanOnNodeDrag:en,autoPanSpeed:wt,connectionRadius:Pn,isValidConnection:zr,onError:lo,style:co,id:Hr,nodeDragThreshold:An,connectionDragThreshold:Oe,viewport:Br,onViewportChange:uo,width:vt,height:In,colorMode:fo="light",debug:ho,onScroll:Ze,ariaLabelConfig:po,zIndexMode:Wr="basic",...xo},go){const Zn=Hr||"1",Qn=Jx(fo),Jn=k.useCallback(dn=>{dn.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),Ze?.(dn)},[Ze]);return s.jsx("div",{"data-testid":"rf__wrapper",...xo,onScroll:Jn,style:{...co,...ym},ref:go,className:Ie(["react-flow",o,Qn]),id:Hr,role:"application",children:s.jsxs(bm,{nodes:e,edges:t,width:vt,height:In,fitView:Lt,fitViewOptions:Fr,minZoom:Be,maxZoom:Ye,nodeOrigin:ze,nodeExtent:rt,zIndexMode:Wr,children:[s.jsx(gm,{onInit:c,onNodeClick:l,onEdgeClick:d,onNodeMouseEnter:$,onNodeMouseMove:v,onNodeMouseLeave:p,onNodeContextMenu:M,onNodeDoubleClick:N,nodeTypes:a,edgeTypes:i,connectionLineType:Y,connectionLineStyle:ee,connectionLineComponent:B,connectionLineContainerStyle:Z,selectionKeyCode:K,selectionOnDrag:U,selectionMode:re,deleteKeyCode:Q,multiSelectionKeyCode:se,panActivationKeyCode:ae,zoomActivationKeyCode:le,onlyRenderVisibleElements:oe,defaultViewport:It,translateExtent:ut,minZoom:Be,maxZoom:Ye,preventScrolling:Tt,zoomOnScroll:Ys,zoomOnPinch:Gs,zoomOnDoubleClick:un,panOnScroll:Re,panOnScrollSpeed:Dr,panOnScrollMode:Us,panOnDrag:Ee,onPaneClick:Ks,onPaneMouseEnter:Gt,onPaneMouseMove:st,onPaneMouseLeave:Zs,onPaneScroll:Gn,onPaneContextMenu:Qs,paneClickDistance:Js,nodeClickDistance:eo,onSelectionContextMenu:L,onSelectionStart:R,onSelectionEnd:F,onReconnect:to,onReconnectStart:Cn,onReconnectEnd:Rt,onEdgeContextMenu:Kt,onEdgeDoubleClick:Lr,onEdgeMouseEnter:no,onEdgeMouseMove:ro,onEdgeMouseLeave:so,reconnectRadius:Un,defaultMarkerColor:En,noDragClassName:ao,noWheelClassName:Or,noPanClassName:yt,rfId:Zn,disableKeyboardA11y:Kn,nodeExtent:rt,viewport:Br,onViewportChange:uo}),s.jsx(Qx,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:m,onConnectStart:y,onConnectEnd:S,onClickConnectStart:x,onClickConnectEnd:b,nodesDraggable:be,autoPanOnNodeFocus:ke,nodesConnectable:_e,nodesFocusable:Te,edgesFocusable:Xe,edgesReconnectable:He,elementsSelectable:Ke,elevateNodesOnSelect:Qt,elevateEdgesOnSelect:Le,minZoom:Be,maxZoom:Ye,nodeExtent:rt,onNodesChange:oo,onEdgesChange:Dt,snapToGrid:ie,snapGrid:V,connectionMode:G,translateExtent:ut,connectOnClick:io,defaultEdgeOptions:_n,fitView:Lt,fitViewOptions:Fr,onNodesDelete:T,onEdgesDelete:j,onDelete:_,onNodeDragStart:w,onNodeDrag:g,onNodeDragStop:E,onSelectionDrag:O,onSelectionDragStart:C,onSelectionDragStop:A,onMove:u,onMoveStart:h,onMoveEnd:f,noPanClassName:yt,nodeOrigin:ze,rfId:Zn,autoPanOnConnect:Jt,autoPanOnNodeDrag:en,autoPanSpeed:wt,onError:lo,connectionRadius:Pn,isValidConnection:zr,selectNodesOnDrag:de,nodeDragThreshold:An,connectionDragThreshold:Oe,onBeforeDelete:W,debug:ho,ariaLabelConfig:po,zIndexMode:Wr}),s.jsx(Gx,{onSelectionChange:I}),Ut,s.jsx(Wx,{proOptions:Zt,position:ot}),s.jsx(Bx,{rfId:Zn,disableKeyboardA11y:Kn})]})})}var vm=ou(wm);function Yi(e){return we(k.useCallback(n=>n.nodeLookup.get(e),[e]),Ce)}function km({dimensions:e,lineWidth:t,variant:n,className:r}){return s.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Ie(["react-flow__background-pattern",n,r])})}function Nm({radius:e,className:t}){return s.jsx("circle",{cx:e,cy:e,r:e,className:Ie(["react-flow__background-pattern","dots",t])})}var cn;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(cn||(cn={}));const jm={[cn.Dots]:1,[cn.Lines]:1,[cn.Cross]:6},Sm=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function _u({id:e,variant:t=cn.Dots,gap:n=20,size:r,lineWidth:o=1,offset:a=0,color:i,bgColor:l,style:d,className:c,patternClassName:u}){const h=k.useRef(null),{transform:f,patternId:m}=we(Sm,Ce),y=r||jm[t],S=t===cn.Dots,x=t===cn.Cross,b=Array.isArray(n)?n:[n,n],$=[b[0]*f[2]||1,b[1]*f[2]||1],v=y*f[2],p=Array.isArray(a)?a:[a,a],M=x?[v,v]:$,N=[p[0]*f[2]||1+M[0]/2,p[1]*f[2]||1+M[1]/2],w=`${m}${e||""}`;return s.jsxs("svg",{className:Ie(["react-flow__background",c]),style:{...d,...qs,"--xy-background-color-props":l,"--xy-background-pattern-color-props":i},ref:h,"data-testid":"rf__background",children:[s.jsx("pattern",{id:w,x:f[0]%$[0],y:f[1]%$[1],width:$[0],height:$[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${N[0]},-${N[1]})`,children:S?s.jsx(Nm,{radius:v/2,className:u}):s.jsx(km,{dimensions:M,lineWidth:o,variant:t,className:u})}),s.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${w})`})]})}_u.displayName="Background";k.memo(_u);function Mm(){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:s.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function $m(){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:s.jsx("path",{d:"M0 0h32v4.2H0z"})})}function Em(){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:s.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 Cm(){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:s.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 _m(){return s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:s.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 bn({children:e,className:t,...n}){return s.jsx("button",{type:"button",className:Ie(["react-flow__controls-button",t]),...n,children:e})}const Pm=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function Pu({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:o,onZoomIn:a,onZoomOut:i,onFitView:l,onInteractiveChange:d,className:c,children:u,position:h="bottom-left",orientation:f="vertical","aria-label":m}){const y=Se(),{isInteractive:S,minZoomReached:x,maxZoomReached:b,ariaLabelConfig:$}=we(Pm,Ce),{zoomIn:v,zoomOut:p,fitView:M}=Ir(),N=()=>{v(),a?.()},w=()=>{p(),i?.()},g=()=>{M(o),l?.()},E=()=>{y.setState({nodesDraggable:!S,nodesConnectable:!S,elementsSelectable:!S}),d?.(!S)},T=f==="horizontal"?"horizontal":"vertical";return s.jsxs(Ws,{className:Ie(["react-flow__controls",T,c]),position:h,style:e,"data-testid":"rf__controls","aria-label":m??$["controls.ariaLabel"],children:[t&&s.jsxs(s.Fragment,{children:[s.jsx(bn,{onClick:N,className:"react-flow__controls-zoomin",title:$["controls.zoomIn.ariaLabel"],"aria-label":$["controls.zoomIn.ariaLabel"],disabled:b,children:s.jsx(Mm,{})}),s.jsx(bn,{onClick:w,className:"react-flow__controls-zoomout",title:$["controls.zoomOut.ariaLabel"],"aria-label":$["controls.zoomOut.ariaLabel"],disabled:x,children:s.jsx($m,{})})]}),n&&s.jsx(bn,{className:"react-flow__controls-fitview",onClick:g,title:$["controls.fitView.ariaLabel"],"aria-label":$["controls.fitView.ariaLabel"],children:s.jsx(Em,{})}),r&&s.jsx(bn,{className:"react-flow__controls-interactive",onClick:E,title:$["controls.interactive.ariaLabel"],"aria-label":$["controls.interactive.ariaLabel"],children:S?s.jsx(_m,{}):s.jsx(Cm,{})}),u]})}Pu.displayName="Controls";const Am=k.memo(Pu);function Im({id:e,x:t,y:n,width:r,height:o,style:a,color:i,strokeColor:l,strokeWidth:d,className:c,borderRadius:u,shapeRendering:h,selected:f,onClick:m}){const{background:y,backgroundColor:S}=a||{},x=i||y||S;return s.jsx("rect",{className:Ie(["react-flow__minimap-node",{selected:f},c]),x:t,y:n,rx:u,ry:u,width:r,height:o,style:{fill:x,stroke:l,strokeWidth:d},shapeRendering:h,onClick:m?b=>m(b,e):void 0})}const Tm=k.memo(Im),Rm=e=>e.nodes.map(t=>t.id),Co=e=>e instanceof Function?e:()=>e;function Dm({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:o,nodeComponent:a=Tm,onClick:i}){const l=we(Rm,Ce),d=Co(t),c=Co(e),u=Co(n),h=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return s.jsx(s.Fragment,{children:l.map(f=>s.jsx(Om,{id:f,nodeColorFunc:d,nodeStrokeColorFunc:c,nodeClassNameFunc:u,nodeBorderRadius:r,nodeStrokeWidth:o,NodeComponent:a,onClick:i,shapeRendering:h},f))})}function Lm({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:r,nodeBorderRadius:o,nodeStrokeWidth:a,shapeRendering:i,NodeComponent:l,onClick:d}){const{node:c,x:u,y:h,width:f,height:m}=we(y=>{const{internals:S}=y.nodeLookup.get(e),x=S.userNode,{x:b,y:$}=S.positionAbsolute,{width:v,height:p}=Yt(x);return{node:x,x:b,y:$,width:v,height:p}},Ce);return!c||c.hidden||!Pc(c)?null:s.jsx(l,{x:u,y:h,width:f,height:m,style:c.style,selected:!!c.selected,className:r(c),color:t(c),borderRadius:o,strokeColor:n(c),strokeWidth:a,shapeRendering:i,onClick:d,id:c.id})}const Om=k.memo(Lm);var Fm=k.memo(Dm);const zm=200,Hm=150,Bm=e=>!e.hidden,Wm=e=>{const 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?_c(_r(e.nodeLookup,{filter:Bm}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},qm="react-flow__minimap-desc";function Au({style:e,className:t,nodeStrokeColor:n,nodeColor:r,nodeClassName:o="",nodeBorderRadius:a=5,nodeStrokeWidth:i,nodeComponent:l,bgColor:d,maskColor:c,maskStrokeColor:u,maskStrokeWidth:h,position:f="bottom-right",onClick:m,onNodeClick:y,pannable:S=!1,zoomable:x=!1,ariaLabel:b,inversePan:$,zoomStep:v=1,offsetScale:p=5}){const M=Se(),N=k.useRef(null),{boundingRect:w,viewBB:g,rfId:E,panZoom:T,translateExtent:j,flowWidth:_,flowHeight:I,ariaLabelConfig:C}=we(Wm,Ce),O=e?.width??zm,A=e?.height??Hm,L=w.width/O,R=w.height/A,F=Math.max(L,R),W=F*O,G=F*A,Y=p*F,ee=w.x-(W-w.width)/2-Y,B=w.y-(G-w.height)/2-Y,Z=W+Y*2,Q=G+Y*2,K=`${qm}-${E}`,U=k.useRef(0),re=k.useRef();U.current=F,k.useEffect(()=>{if(N.current&&T)return re.current=xx({domNode:N.current,panZoom:T,getTransform:()=>M.getState().transform,getViewScale:()=>U.current}),()=>{re.current?.destroy()}},[T]),k.useEffect(()=>{re.current?.update({translateExtent:j,width:_,height:I,inversePan:$,pannable:S,zoomStep:v,zoomable:x})},[S,x,$,v,j,_,I]);const ae=m?ie=>{const[V,oe]=re.current?.pointer(ie)||[0,0];m(ie,{x:V,y:oe})}:void 0,se=y?k.useCallback((ie,V)=>{const oe=M.getState().nodeLookup.get(V).internals.userNode;y(ie,oe)},[]):void 0,le=b??C["minimap.ariaLabel"];return s.jsx(Ws,{position:f,style:{...e,"--xy-minimap-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-stroke-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-stroke-width-props":typeof h=="number"?h*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 i=="number"?i:void 0},className:Ie(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:s.jsxs("svg",{width:O,height:A,viewBox:`${ee} ${B} ${Z} ${Q}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":K,ref:N,onClick:ae,children:[le&&s.jsx("title",{id:K,children:le}),s.jsx(Fm,{onClick:se,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:o,nodeStrokeWidth:i,nodeComponent:l}),s.jsx("path",{className:"react-flow__minimap-mask",d:`M${ee-Y},${B-Y}h${Z+Y*2}v${Q+Y*2}h${-Z-Y*2}z
|
|
7
|
+
M${g.x},${g.y}h${g.width}v${g.height}h${-g.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}Au.displayName="MiniMap";const Vm=k.memo(Au),Xm=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,Ym={[Yn.Line]:"right",[Yn.Handle]:"bottom-right"};function Gm({nodeId:e,position:t,variant:n=Yn.Handle,className:r,style:o=void 0,children:a,color:i,minWidth:l=10,minHeight:d=10,maxWidth:c=Number.MAX_VALUE,maxHeight:u=Number.MAX_VALUE,keepAspectRatio:h=!1,resizeDirection:f,autoScale:m=!0,shouldResize:y,onResizeStart:S,onResize:x,onResizeEnd:b}){const $=cu(),v=typeof e=="string"?e:$,p=Se(),M=k.useRef(null),N=n===Yn.Handle,w=we(k.useCallback(Xm(N&&m),[N,m]),Ce),g=k.useRef(null),E=t??Ym[n];k.useEffect(()=>{if(!(!M.current||!v))return g.current||(g.current=Cx({domNode:M.current,nodeId:v,getStoreItems:()=>{const{nodeLookup:j,transform:_,snapGrid:I,snapToGrid:C,nodeOrigin:O,domNode:A}=p.getState();return{nodeLookup:j,transform:_,snapGrid:I,snapToGrid:C,nodeOrigin:O,paneDomNode:A}},onChange:(j,_)=>{const{triggerNodeChanges:I,nodeLookup:C,parentLookup:O,nodeOrigin:A}=p.getState(),L=[],R={x:j.x,y:j.y},F=C.get(v);if(F&&F.expandParent&&F.parentId){const W=F.origin??A,G=j.width??F.measured.width??0,Y=j.height??F.measured.height??0,ee={id:F.id,parentId:F.parentId,rect:{width:G,height:Y,...Ac({x:j.x??F.position.x,y:j.y??F.position.y},{width:G,height:Y},F.parentId,C,W)}},B=Ma([ee],C,O,A);L.push(...B),R.x=j.x?Math.max(W[0]*G,j.x):void 0,R.y=j.y?Math.max(W[1]*Y,j.y):void 0}if(R.x!==void 0&&R.y!==void 0){const W={id:v,type:"position",position:{...R}};L.push(W)}if(j.width!==void 0&&j.height!==void 0){const G={id:v,type:"dimensions",resizing:!0,setAttributes:f?f==="horizontal"?"width":"height":!0,dimensions:{width:j.width,height:j.height}};L.push(G)}for(const W of _){const G={...W,type:"position"};L.push(G)}I(L)},onEnd:({width:j,height:_})=>{const I={id:v,type:"dimensions",resizing:!1,dimensions:{width:j,height:_}};p.getState().triggerNodeChanges([I])}})),g.current.update({controlPosition:E,boundaries:{minWidth:l,minHeight:d,maxWidth:c,maxHeight:u},keepAspectRatio:h,resizeDirection:f,onResizeStart:S,onResize:x,onResizeEnd:b,shouldResize:y}),()=>{g.current?.destroy()}},[E,l,d,c,u,h,S,x,b,y]);const T=E.split("-");return s.jsx("div",{className:Ie(["react-flow__resize-control","nodrag",...T,n,r]),ref:M,style:{...o,scale:w,...i&&{[N?"backgroundColor":"borderColor"]:i}},children:a})}k.memo(Gm);const Iu=260,Tu=280,Gi=[],Ui=75e3,Um=280,Km=.45,Zm=.35,Qm=e=>e.transform[2]>=Km,Jm=e=>e.transform[2]>=Zm,ts=new Map;function Ru(e,t){const n=ts.get(e);return n===void 0?(ts.size>2e3&&ts.clear(),ts.set(e,Date.now()),t):Date.now()-n<500?t:void 0}const Ki=new Set;function Du({text:e}){const t=e.split(/(`[^`]+`|\*\*[^*]+\*\*)/g);return s.jsx("span",{className:"whitespace-pre-wrap break-words",children:t.map((n,r)=>n.startsWith("`")&&n.endsWith("`")?s.jsx("code",{className:"px-1 py-px rounded bg-neutral-100 dark:bg-neutral-700 font-mono text-[12px]",children:n.slice(1,-1)},r):n.startsWith("**")&&n.endsWith("**")?s.jsx("strong",{children:n.slice(2,-2)},r):n)})}function eb({activities:e}){const[t,n]=k.useState(null),r=k.useRef(null),[o,a]=k.useState(!1),i=k.useRef(null),l=Ps(e,d=>d.type==="turn"&&d.args?.startsWith("“")===!0);return k.useEffect(()=>{if(!l||Ki.has(l.id))return;const d=Date.now()-l.timestamp;if(d>=Ui)return;const c=l.detail??l.args.replace(/^“|”$/g,""),u=c.length>550?c.slice(0,550)+"…":c;n({id:l.id,text:u});const h=setTimeout(()=>n(null),Ui-d);return()=>clearTimeout(h)},[l?.id]),k.useEffect(()=>{const d=r.current?.closest(".react-flow__node");if(d&&t){const c=d.style.zIndex;return d.style.zIndex="20",()=>{d.style.zIndex=c}}},[t]),k.useEffect(()=>{const d=i.current;a(d?d.scrollHeight>d.clientHeight+1:!1)},[t?.id]),t?s.jsxs("div",{ref:r,className:"fleet-say-bubble absolute left-1/2 -translate-x-1/2 w-[340px] flex flex-col items-center",style:{bottom:"102%",animation:Ru(`say:${t.id}`,"meshFadeIn 250ms ease-out")},children:[s.jsxs("div",{className:"pointer-events-none relative px-3.5 py-2.5 rounded-2xl bg-white/95 dark:bg-neutral-800/95 border border-neutral-200 dark:border-neutral-600 shadow-lg text-[14px] leading-snug text-neutral-700 dark:text-neutral-100",children:[s.jsx("div",{ref:i,className:o?"nowheel pointer-events-auto overflow-y-auto":"overflow-y-auto",style:{maxHeight:Um,overscrollBehavior:"contain"},children:s.jsx(Du,{text:t.text})}),s.jsx("button",{onClick:d=>{d.stopPropagation(),Ki.add(t.id),n(null)},className:"pointer-events-auto absolute -top-2 -right-2 w-5 h-5 flex items-center justify-center rounded-full bg-neutral-200 dark:bg-neutral-600 text-neutral-500 dark:text-neutral-300 hover:bg-neutral-300 dark:hover:bg-neutral-500 text-[10px] leading-none shadow",title:"Dismiss",children:"✕"})]}),s.jsx("div",{className:"w-2.5 h-2.5 -mt-1.5 rotate-45 bg-white/95 dark:bg-neutral-800/95 border-r border-b border-neutral-200 dark:border-neutral-600"})]}):null}function tb({filePath:e}){const t=J(o=>!!o.starting[e]),n=J(o=>o.markStarting),r=k.useCallback(o=>{if(o.stopPropagation(),t)return;n([e]);const a=qe(e);a.api.startBackgroundAgent(a.filePath).catch(()=>{})},[e,t,n]);return t?s.jsx("div",{title:"Starting up…",className:"w-7 h-7 flex items-center justify-center rounded-full bg-teal-500/90 text-white shadow",children:s.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",className:"animate-spin",children:s.jsx("path",{d:"M21 12a9 9 0 1 1-6.2-8.56"})})}):s.jsx("button",{onClick:r,title:"Start agent",className:"pointer-events-auto w-7 h-7 flex items-center justify-center rounded-full bg-white/70 dark:bg-neutral-800/70 border border-neutral-300/70 dark:border-neutral-600/70 text-[var(--adf-ui-text-subtle)] dark:text-neutral-400 shadow-sm transition-colors hover:bg-green-500 hover:border-green-500 hover:text-white dark:hover:bg-green-500 dark:hover:border-green-500 dark:hover:text-white",children:s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:s.jsx("path",{d:"M8 5v14l11-7z"})})})}const ns={width:6,height:6,background:"transparent",border:"none"};function Lu(){return s.jsxs(s.Fragment,{children:[s.jsx(ct,{type:"target",position:ue.Top,style:ns}),s.jsx(ct,{type:"source",position:ue.Bottom,style:ns}),s.jsx(ct,{type:"target",position:ue.Left,style:ns,id:"left"}),s.jsx(ct,{type:"source",position:ue.Right,style:ns,id:"right"})]})}const nb=k.memo(function(t){return t.data.culled?s.jsx("div",{className:"relative pointer-events-none",style:{width:Iu,height:Tu},children:s.jsx(Lu,{})}):s.jsx(rb,{...t})});function rb({data:e}){const t=e,{filePath:n,online:r}=t,o=r===!1,a=we(Qm),i=we(Jm),l=pe(c=>!o&&i?c.nodeActivities[n]??Gi:Gi),d=pe(c=>c.pendingInteractions[n]);return s.jsxs("div",{className:"relative pointer-events-none",style:{width:Iu,height:Tu},children:[s.jsx("div",{className:"absolute inset-0 pointer-events-auto cursor-grab active:cursor-grabbing",style:{clipPath:"polygon(293px 140px, 211.5px 281.2px, 48.5px 281.2px, -33px 140px, 48.5px -1.2px, 211.5px -1.2px)"}}),s.jsx(Lu,{}),!o&&i&&s.jsx(eb,{activities:l}),!o&&t.servedUrl&&s.jsx("a",{href:t.servedUrl,target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"pointer-events-auto absolute w-8 h-8 flex items-center justify-center rounded-full bg-white/90 dark:bg-neutral-800/90 border border-sky-300 dark:border-sky-700 shadow text-[15px] hover:scale-110 transition-transform",style:{left:208,top:226},title:`Serving ${t.servedUrl} — click to open`,children:"🌐"}),o&&s.jsx("div",{className:"absolute left-0 right-0 flex justify-center",style:{top:246},children:s.jsx(tb,{filePath:n})}),a&&d&&s.jsx("div",{className:"absolute left-1/2 -translate-x-1/2 z-20 w-[236px] rounded-lg bg-amber-50 dark:bg-neutral-900 border border-amber-300 dark:border-amber-600/60 shadow-md pointer-events-auto cursor-pointer",style:{bottom:-8,animation:Ru(`hil:${n}|${d.requestId}`,"meshFadeIn 200ms ease-out")},onClick:c=>{c.target.closest("button, textarea, input")||(c.stopPropagation(),J.getState().setHilModal(n))},children:s.jsx(sb,{filePath:n,pending:d})})]})}const Ea={llm:{mark:"◈",markColor:"text-indigo-400",nameColor:"text-indigo-500 dark:text-indigo-400"},turn:{mark:"⏎",markColor:"text-emerald-500",nameColor:"text-neutral-500 dark:text-neutral-400"},state:{mark:"→",markColor:"text-[var(--adf-ui-text-subtle)]",nameColor:"text-neutral-500 dark:text-neutral-400"},error:{mark:"!",markColor:"text-red-500",nameColor:"text-red-500 dark:text-red-400"}};function sb({filePath:e,pending:t}){const[n,r]=k.useState(""),[o,a]=k.useState(null),i=ua(),l=e===i,d=pe(p=>p.setPendingInteraction),c=cd(),u=t.type==="ask"?t.questions:[],h=u.length===1&&!u[0].options,f=k.useCallback(async()=>{if(t.type!=="ask"||!n.trim())return;const p=qe(e),M=l?await p.api.respondAsk(t.requestId,[n.trim()]):await p.api.respondBackgroundAgentAsk(p.filePath,t.requestId,[n.trim()]);if(M&&M.success===!1){a(M.error??"The answer was not accepted.");return}a(null),d(e,null),r("")},[t,n,e,l,d]),m=k.useCallback(()=>{const p=qe(e);c(p.filePath,p.runtimeId)},[e,c]),y=k.useCallback((p,M)=>{if(t.type==="approval"){if(l)qe(e).api.respondToolApproval(t.requestId,p,M);else{const N=qe(e);N.api.respondBackgroundAgentToolApproval(N.filePath,t.requestId,p,M)}d(e,null)}},[t,e,l,d]),S=k.useCallback(async p=>{if(t.type!=="approval")return;const M=qe(e),N=l?await M.api.alwaysApproveTool(t.requestId,p):await M.api.alwaysApproveBackgroundAgentTool(M.filePath,t.requestId,p);if(N&&!N.success){console.warn(`[MeshGraphNode] Always approve refused for ${p}: ${N.error}`);return}d(e,null)},[t,e,l,d]);if(t.type==="ask")return s.jsxs("div",{className:"px-3 py-2 space-y-1.5",children:[s.jsx("p",{className:"line-clamp-3 text-[10px] text-neutral-600 dark:text-neutral-300 leading-tight",children:Wo(u)||"Agent is asking..."}),h?s.jsxs("div",{className:"flex gap-1",children:[s.jsx("input",{type:"text",value:n,onChange:p=>{r(p.target.value),a(null)},onKeyDown:p=>{p.key==="Enter"&&f()},placeholder:"Type response...","aria-label":"Answer",className:"flex-1 px-2 py-1 text-[11px] bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-600 rounded focus:outline-none focus:ring-1 focus:ring-amber-400"}),s.jsx("button",{onClick:()=>{f()},disabled:!n.trim(),className:"px-2 py-1 text-[10px] bg-blue-500 text-white rounded hover:bg-blue-600 disabled:opacity-50",children:"Send"})]}):s.jsx("button",{onClick:p=>{p.stopPropagation(),m()},className:"block w-full text-center text-[10px] text-blue-500 dark:text-blue-400 hover:underline",children:"Answer in agent"}),o&&s.jsx("p",{role:"alert",className:"text-[10px] text-red-500 leading-tight",children:o})]});const x=t.input&&typeof t.input=="object"?t.input:void 0,b=x&&typeof x._reason=="string"?x._reason:void 0,$=t.protection?.description,v=J(p=>p.setHilModal);return s.jsxs("div",{className:"px-3 py-2 space-y-1.5",children:[s.jsx("p",{className:"text-[10px] text-neutral-600 dark:text-neutral-300 leading-tight",children:$||s.jsxs(s.Fragment,{children:["Approve ",s.jsx("span",{className:"font-medium text-orange-500",children:t.toolName}),"?"]})}),b&&!$&&s.jsxs("p",{className:"text-[10px] italic text-neutral-500 dark:text-neutral-400 leading-tight",style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",b,"”"]}),s.jsx("button",{onClick:p=>{p.stopPropagation(),v(e)},className:"block w-full text-center text-[10px] text-blue-500 dark:text-blue-400 hover:underline",children:"view full context"}),s.jsx("div",{className:"flex justify-center",children:s.jsx(Fl,{compact:!0,toolName:t.toolName??"tool",onApprove:()=>y(!0),onAlwaysApprove:()=>{S(t.toolName??"tool")},onReject:p=>y(!1,p),alwaysApproveDisabled:t.canAlwaysApprove===!1,alwaysApproveDisabledReason:t.alwaysApproveBlockedReason})})]})}function Ca(e){const t=new Map,n=new Map,r=new Map,o=new Map,a=(x,b,$)=>{const v=x.get(b);v?v.push($):x.set(b,[$])};for(const x of e){x.did&&a(t,x.did,x.filePath);for(const b of x.didHistory??[])a(n,b,x.filePath);x.agentId&&a(r,x.agentId,x.filePath)}for(const[x,b]of t)b.length>1&&o.set(x,[...b]);const i=new Map(e.map(x=>[x.filePath,x])),l=x=>i.get(x)?.createdAt??"",d=(x,b)=>{let $;for(const v of x??[]){if(v===b.filePath)continue;if($===void 0){$=v;continue}const p=i.get($)?.parentDid===b.parentDid,M=i.get(v)?.parentDid===b.parentDid;p!==M?M||($=v):l(v)<l($)&&($=v)}return $},c=new Map,u=new Map,h=[],f=[];for(const x of e){const b=x.parentDid;if(!b){f.push(x.filePath);continue}let $;for(const p of[t,n,r])if($=d(p.get(b),x),$!==void 0)break;if($===void 0){h.push(x.filePath),f.push(x.filePath);continue}c.set(x.filePath,$);const v=u.get($)??[];v.push(x.filePath),u.set($,v)}const m=new Map(e.map((x,b)=>[x.filePath,b])),y=x=>{const b=c.get(x);c.delete(x);const $=u.get(b).filter(v=>v!==x);$.length>0?u.set(b,$):u.delete(b),h.push(x),f.push(x)},S=new Set;for(const x of e){const b=[];let $=x.filePath;for(;$!==void 0&&!S.has($)&&!b.includes($);)b.push($),$=c.get($);if($!==void 0&&b.includes($)){const v=b.slice(b.indexOf($)).reduce((p,M)=>{const N=l(p),w=l(M);return w>N||w===N&&m.get(M)>m.get(p)?M:p});y(v)}for(const v of b)S.add(v)}return{parents:c,children:u,orphaned:h,roots:f,duplicateDids:o}}const jt=260,qt=280,fe=165,Fe=1.5*fe,$e=Math.sqrt(3)*fe,ob=2.4,ab="",_a=e=>!e.includes("/")&&e.includes("\\")?"\\":"/",Vs=e=>e.split(_a(e)).filter(Boolean),Ve=e=>Vs(e).pop()??e;function jr(e){const t=e.lastIndexOf(_a(e));return t>0?e.slice(0,t):""}const Rr=(e,t)=>e.startsWith(t+"/")||e.startsWith(t+"\\"),Ou=(e,t)=>Rr(e,t)||ln(t)!==null&&e.startsWith(t);function ib(e,t){return e.filter(n=>n.filePath===t||Ou(n.filePath,t))}const Sr=(e,t)=>e+_a(e)+t;function tt(e,t){return{x:Fe*e,y:$e*(t+e/2)}}function ft(e,t){const n=e/Fe,r=t/$e-n/2,o=-n-r;let a=Math.round(n),i=Math.round(r);const l=Math.round(o),d=Math.abs(a-n),c=Math.abs(i-r),u=Math.abs(l-o);return d>c&&d>u?a=-i-l:c>u&&(i=-a-l),{q:a,r:i}}function lt(e,t,n=fe){const r=[];for(let o=0;o<6;o++){const a=Math.PI/180*(60*o);r.push(`${(e+n*Math.cos(a)).toFixed(1)},${(t+n*Math.sin(a)).toFixed(1)}`)}return r.join(" ")}const cr=[[1,0],[1,-1],[0,-1],[-1,0],[-1,1],[0,1]];function $n(e){const t=[[0,0]];for(let n=1;t.length<e;n++){let r=cr[4][0]*n,o=cr[4][1]*n;for(let a=0;a<6;a++)for(let i=0;i<n;i++)t.push([r,o]),r+=cr[a][0],o+=cr[a][1]}return t}function aa(e,t){const n=[[1,0],[0,1],[-1,1],[-1,0],[0,-1],[1,-1]],r=new Set(e.map(a=>`${a.q},${a.r}`)),o=[];for(const a of e)for(let i=0;i<6;i++){const[l,d]=n[i];if(r.has(`${a.q+l},${a.r+d}`))continue;const c=i*Math.PI/3,u=(i+1)*Math.PI/3;o.push(`M ${a.x+t*Math.cos(c)} ${a.y+t*Math.sin(c)} L ${a.x+t*Math.cos(u)} ${a.y+t*Math.sin(u)}`)}return o.join(" ")}function lb(e,t){const n=new Set(e.map(u=>u.filePath)),r=new Map(e.map(u=>[u.filePath,u])),o=new Map,a=[];for(const u of e){const h=t.parents.get(u.filePath);if(h!==void 0&&n.has(h)){const f=o.get(h)??[];f.push(u.filePath),o.set(h,f)}else a.push(u.filePath)}const i=(u,h)=>{const f=r.get(u)?.createdAt??"",m=r.get(h)?.createdAt??"";return f<m?-1:f>m?1:u<h?-1:u>h?1:0};a.sort(i);for(const u of o.values())u.sort(i);const l=[],d=new Set,c=u=>{if(d.has(u))return;d.add(u);const h=r.get(u);h&&l.push(h);for(const f of o.get(u)??[])c(f)};for(const u of a)c(u);for(const u of e)d.has(u.filePath)||l.push(u);return l}function ps(e,t){if(!t)return"";if(ln(t)!==null)return ud(e);const n=jr(e);return n===t?"":Rr(n,t)?n.slice(t.length+1):""}function cb(e,t){return e.district??ps(e.filePath,t)}function Fu(e){return mt({did:e.did,filePath:e.filePath})}function ub(e){return{filePath:e.filePath,handle:e.handle,state:e.state,status:e.status,orbitalSeed:Fu(e),model:e.model,online:e.online,servedUrl:e.servedUrl}}function $s(e,t,n,r){const o=e-n,a=t-r;return(Math.abs(o)+Math.abs(o+a)+Math.abs(a))/2}function db(e,t,n,r,o){const a=new Map;for(const p of t){const M=cb(p,e),N=a.get(M)??[];N.push(p),a.set(M,N)}const i=p=>a.get(p).reduce((M,N)=>N.createdAt&&(!M||N.createdAt<M)?N.createdAt:M,""),l=[...a.keys()].sort((p,M)=>{if(p==="")return-1;if(M==="")return 1;const N=i(p),w=i(M);return N!==w?N<w?-1:1:p.localeCompare(M)}),d=(p,M)=>{const N=lb(p,n),w=$n(Math.max(N.length,1));return N.map((g,E)=>({q:w[E][0],r:w[E][1],x:0,y:0,filePath:g.filePath,district:M}))},c=[],u=new Map,h=$n(600),f={};for(const p of l){const M=d(a.get(p),p);let N=0,w=0,g=!1;const E=o?.[p];if(E&&M.every(T=>!u.has(`${T.q+E.q},${T.r+E.r}`))&&(N=E.q,w=E.r,g=!0),!g&&r){const T=M.find(j=>j.filePath&&r.has(j.filePath)&&!r.get(j.filePath).solo);if(T){const j=r.get(T.filePath),_=j.q-T.q,I=j.r-T.r;M.every(C=>!u.has(`${C.q+_},${C.r+I}`))&&(N=_,w=I,g=!0)}}if(!g&&c.length>0)for(const[T,j]of h){let _=1/0;for(const I of M){for(const C of c){const O=$s(I.q+T,I.r+j,C.q,C.r);if(O<_&&(_=O),_<2)break}if(_<2)break}if(_>=2&&_<=3){N=T,w=j;break}}f[p]={q:N,r:w};for(const T of M){const j=T.q+N,_=T.r+w,{x:I,y:C}=tt(j,_),O={...T,q:j,r:_,x:I,y:C};c.push(O),u.set(`${j},${_}`,O)}}if(r)for(const[p,M]of r){const N=c.find(E=>E.filePath===p);if(!N||N.q===M.q&&N.r===M.r)continue;const w=u.get(`${M.q},${M.r}`);if(w?.filePath&&r.has(w.filePath))continue;if(u.delete(`${N.q},${N.r}`),w){w.q=N.q,w.r=N.r;const E=tt(N.q,N.r);w.x=E.x,w.y=E.y,u.set(`${w.q},${w.r}`,w)}N.q=M.q,N.r=M.r;const g=tt(M.q,M.r);N.x=g.x,N.y=g.y,u.set(`${M.q},${M.r}`,N)}for(const p of c)for(const[M,N]of cr){const w=`${p.q+M},${p.r+N}`;if(u.has(w))continue;const{x:g,y:E}=tt(p.q+M,p.r+N);u.set(w,{q:p.q+M,r:p.r+N,x:g,y:E,district:p.district})}const m=new Map;for(const[p,M]of u)M.filePath&&m.set(p,M);const y=[...u.values()],S=Math.min(...y.map(p=>p.x))-fe,x=Math.max(...y.map(p=>p.x))+fe,b=Math.min(...y.map(p=>p.y))-$e/2,$=Math.max(...y.map(p=>p.y))+$e/2,v=new Map;for(const p of m.values())p.filePath&&v.set(p.filePath,{x:p.x,y:p.y});return{dirPath:e,members:t,cells:y,districts:l.filter(p=>p!==""),minX:S,minY:b,width:x-S,height:$-b,agentCenters:v,anchors:f}}function fb(e,t){const n=new Map;if(e.length===0)return n;const r=e.reduce((c,u)=>c+(u.width+t)*(u.height+t),0),o=e.reduce((c,u)=>Math.max(c,u.width),0),a=Math.max(o,Math.sqrt(r*1.7));let i=0,l=0,d=0;for(const c of e)i>0&&i+c.width>a&&(i=0,l+=d+t,d=0),n.set(c.key,{x:i,y:l}),i+=c.width+t,d=Math.max(d,c.height);return n}function hb(e,t){const n=2*Math.round(e/(2*Fe)),r=Math.round(t/$e-n/2);return tt(n,r)}function pb(e,t,n){const r=Ca(e),o=new Map(e.map(w=>[w.filePath,w])),a=new Map;for(const w of e){const g=w.trackedDirRoot??ab,E=a.get(g)??[];E.push(w),a.set(g,E)}const i=[...a.keys()].sort(),l=t?.regionOrigins??{},d=t?.cellPins??{},c=i.map(w=>{const g=a.get(w).slice().sort((I,C)=>I.filePath.localeCompare(C.filePath)),E=l[w];let T;if(E)for(const I of g){const C=d[I.filePath];C&&(T??=new Map,T.set(I.filePath,{q:C.q-E.q,r:C.r-E.r,solo:C.solo}))}let j;const _=`${w}::`;for(const[I,C]of Object.entries(t?.districtAnchors??{}))I.startsWith(_)&&(j??={},j[I.slice(_.length)]=C);return db(w,g,r,T,j)}),u=new Map,h=[],f=(w,g,E)=>{let T=1/0;for(const j of w.cells)if(j.filePath)for(const _ of h){const I=$s(j.q+g,j.r+E,_.q,_.r);if(I<T&&(T=I),T<4)return T}return T},m=(w,g)=>{u.set(w.dirPath,g);for(const E of w.cells)E.filePath&&h.push({q:E.q+g.q,r:E.r+g.r})},y=c.filter(w=>l[w.dirPath]),S=c.filter(w=>!l[w.dirPath]),x=y.length>0||S.length>0?$n(600):[];for(const w of y){const g=l[w.dirPath];let E=null;for(const[T,j]of x){const _=T===0&&j===0,I=f(w,g.q+T,g.r+j);if(_?I>=3:I>=4){E={q:g.q+T,r:g.r+j};break}}m(w,E??g)}const b=[],$=[],v=[];if(u.size===0&&S.length>0){const w=ob*Fe,g=fb(S.map(E=>({key:E.dirPath,width:E.width,height:E.height})),w);for(const E of S){const T=g.get(E.dirPath),j=hb(T.x-E.minX,T.y-E.minY),_=Math.round(j.x/Fe);m(E,{q:_,r:Math.round(j.y/$e-_/2)})}}else for(const w of S){let g=null,E=null;for(const T of w.cells){if(!T.filePath)continue;const j=d[T.filePath];if(!j)continue;const _={q:j.q-T.q,r:j.r-T.r};if(!j.solo){g=_;break}E??=_}if(g??=E,!g){const T=[...u.values()],j=T.length>0?{q:Math.round(T.reduce((_,I)=>_+I.q,0)/T.length),r:Math.round(T.reduce((_,I)=>_+I.r,0)/T.length)}:{q:0,r:0};for(const[_,I]of $n(4e3))if(f(w,j.q+_,j.r+I)>=4){g={q:j.q+_,r:j.r+I};break}g??=j}m(w,g)}for(const w of c){const g=u.get(w.dirPath),E=tt(g.q,g.r),T=E.x+w.minX,j=E.y+w.minY,_={dirPath:w.dirPath,label:n?.label?.(w.dirPath)??(w.dirPath?Ve(w.dirPath):"Untracked"),agentCount:w.members.length,width:w.width,height:w.height,cells:w.cells.map(I=>({...I,x:I.x-w.minX,y:I.y-w.minY})),members:w.members.map(I=>({filePath:I.filePath,handle:I.handle,seed:Fu(I),icon:ql(I.icon,I.agentId||I.filePath)})),districts:w.districts,...n?.muted?.(w.dirPath)?{muted:!0}:{},...n?.remote?.(w.dirPath)?{remote:!0}:{},...n?.managed?.(w.dirPath)?{managed:!0}:{}};b.push({id:`terrain:${w.dirPath||"untracked"}`,type:"terrainNode",position:{x:T,y:j},draggable:!1,selectable:!1,focusable:!1,zIndex:-1,style:{pointerEvents:"none"},initialWidth:w.width,initialHeight:w.height,data:_}),$.push({id:`terrain-label:${w.dirPath||"untracked"}`,type:"terrainLabelNode",position:{x:T,y:j},draggable:!1,selectable:!1,focusable:!1,style:{pointerEvents:"none"},initialWidth:w.width,initialHeight:w.height,data:_});for(const[I,C]of w.agentCenters){const O=o.get(I);O&&v.push({id:O.filePath,type:"meshNode",position:{x:T+(C.x-w.minX)-jt/2,y:j+(C.y-w.minY)-qt/2},draggable:!0,style:{pointerEvents:"none"},initialWidth:jt,initialHeight:qt,data:{...ub(O)}})}}b.push(...$,...v);const p=[];for(const[w,g]of r.parents)!o.has(w)||!o.has(g)||p.push({id:`lin-${g}-${w}`,source:g,target:w,type:"meshEdge",selectable:!1,data:{edgeType:"lineage"}});const M={};for(const[w,g]of u)M[w]=g;const N={};for(const w of c)for(const[g,E]of Object.entries(w.anchors))N[`${w.dirPath}::${g}`]=E;return{nodes:b,lineageEdges:p,lineage:r,regionOrigins:M,districtAnchors:N}}function Es(e){const t=e.measured?.width??e.initialWidth??260,n=e.measured?.height??e.initialHeight??120,{x:r,y:o}=e.internals.positionAbsolute;return{x:r+t/2,y:o+n/2}}function Zi(e){const t=Math.round(e.x/Fe),n=Math.round(e.y/$e-t/2);return{q:t,r:n}}const zu=64,rs=(fe-2)*(Math.sqrt(3)/2);function Qi(e,t){const n=Math.hypot(e,t);return n<1?null:{x:e/n,y:t/n}}function Hu(e,t){const n=Zi(e),r=Zi(t),o=r.q-n.q,a=r.r-n.r;let i=null;if(o!==0&&a!==0)if(Math.sign(o)!==Math.sign(a)){const h=Math.min(Math.abs(o),Math.abs(a))*Math.sign(o);i=tt(n.q+h,n.r-h)}else i=tt(r.q,n.r);const l=Qi((i??t).x-e.x,(i??t).y-e.y),d=Qi(t.x-(i??e).x,t.y-(i??e).y);if(!l||!d)return{s:e,t,bend:i,outDir:null,inDir:null};const c={x:e.x+l.x*rs,y:e.y+l.y*rs},u={x:t.x-d.x*rs,y:t.y-d.y*rs};return{s:c,t:u,bend:i,outDir:l,inDir:d}}const Ji=8;function xb(e){const t=[e.s];if(e.bend){const o=e.bend.x-e.s.x,a=e.bend.y-e.s.y,i=e.t.x-e.bend.x,l=e.t.y-e.bend.y,d=Math.hypot(o,a),c=Math.hypot(i,l);if(d>=1&&c>=1){const u=Math.min(zu,d/2.5,c/2.5),h=e.bend.x-o/d*u,f=e.bend.y-a/d*u,m=e.bend.x+i/c*u,y=e.bend.y+l/c*u;t.push({x:h,y:f});for(let S=1;S<Ji;S++){const x=S/Ji,b=(1-x)*(1-x),$=2*(1-x)*x,v=x*x;t.push({x:b*h+$*e.bend.x+v*m,y:b*f+$*e.bend.y+v*y})}t.push({x:m,y})}}t.push(e.t);const n=[0];let r=0;for(let o=1;o<t.length;o++)r+=Math.hypot(t[o].x-t[o-1].x,t[o].y-t[o-1].y),n.push(r);return{pts:t,cum:n,total:r}}function el(e,t,n){if(!t)return`M ${e.x} ${e.y} L ${n.x} ${n.y}`;const r=t.x-e.x,o=t.y-e.y,a=n.x-t.x,i=n.y-t.y,l=Math.hypot(r,o),d=Math.hypot(a,i);if(l<1||d<1)return`M ${e.x} ${e.y} L ${n.x} ${n.y}`;const c=Math.min(zu,l/2.5,d/2.5),u=t.x-r/l*c,h=t.y-o/l*c,f=t.x+a/d*c,m=t.y+i/d*c;return`M ${e.x} ${e.y} L ${u} ${h} Q ${t.x} ${t.y} ${f} ${m} L ${n.x} ${n.y}`}const gb=14400*1e3,tl="#52525b",_o="#7c3aed",mb=.22;function bb(e,t,n){const r=parseInt(e.slice(1),16),o=parseInt(t.slice(1),16),a=i=>{const l=r>>i&255,d=o>>i&255;return Math.round(l+(d-l)*n)};return`#${(a(16)<<16|a(8)<<8|a(0)).toString(16).padStart(6,"0")}`}function nl(e,t){if(!e)return 0;const n=Math.min(1,Math.max(0,1-(t-e.lastAt)/gb));return Math.min(1,Math.log2(1+e.count)/5)*(.3+.7*n)}const yb=k.memo(function(t){const{id:n,source:r,target:o,sourceX:a,sourceY:i,targetX:l,targetY:d,data:c,style:u}=t,h=c,f=h?.edgeType==="channel",m=h?.edgeType==="message",y=Yi(r),S=Yi(o),x=k.useMemo(()=>!y||!S?null:Hu(Es(y),Es(S)),[y,S,a,i,l,d]),b=k.useMemo(()=>x?el(x.s,x.bend,x.t):"",[x]),$=pe(W=>W.activeAnimationIndex[`${r}|${o}`]??null),v=pe(W=>W.activeAnimationIndex[`${o}|${r}`]??null),p=k.useMemo(()=>$?{...$,reversed:!1}:v?{...v,reversed:!0}:null,[$,v]),M=k.useMemo(()=>!p?.reversed||!x?null:el(x.t,x.bend,x.s),[p?.reversed,x]),N=pe(W=>m?W.edgeHeat[`${r}|${o}`]??null:null),w=pe(W=>m?W.edgeHeat[`${o}|${r}`]??null:null),g=Date.now(),E=nl(N,g),T=nl(w,g),j=Math.max(E,T),_=we(W=>W.transform[2]<.4),I=J(W=>m&&(W.selection.includes(r)||W.selection.includes(o))),C=J(W=>W.selectedStation!=null&&(W.selectedStation===r||W.selectedStation===o)),A=h?.edgeType==="lineage"?{...u,stroke:"#a8a29e",strokeWidth:1.5,strokeDasharray:"6 3",opacity:_?.12:.5}:f?C?{...u,stroke:_o,strokeWidth:2,strokeDasharray:"4 4",opacity:.9}:{...u,stroke:"#94a3b8",strokeWidth:1,strokeDasharray:"4 4",opacity:_?.1:.4}:I||C?{...u,stroke:_o,strokeWidth:(2.5+6*j)*(_?1.8:1),strokeLinecap:"round",opacity:.9}:{...u,stroke:j>0?bb(tl,_o,j):tl,strokeWidth:(1.5+6*j)*(_?1.8:1),strokeLinecap:"round",opacity:_?j<mb?.08:.6+.35*j:.3+.65*j},L=p?{...A,stroke:"#8b5cf6",strokeWidth:Math.max(2.5,1.5+6*j),opacity:1}:A,R=p?.reversed?M:b,F=k.useMemo(()=>{if(!m||!x?.outDir||!x?.inDir)return null;const{s:W,t:G,outDir:Y,inDir:ee}=x,B=9+9*j,Z=4.5+4.5*j,Q=(U,re)=>{const ae=U.x-re.x*B,se=U.y-re.y*B,le=-re.y,ie=re.x;return`${U.x},${U.y} ${ae+le*Z},${se+ie*Z} ${ae-le*Z},${se-ie*Z}`},K=[];return(E>0||T===0)&&K.push(Q(G,ee)),T>0&&K.push(Q(W,{x:-Y.x,y:-Y.y})),{pad:T>0?null:{cx:W.x,cy:W.y,r:3.5+3.5*j},arrows:K}},[m,x,j,E,T]);return x?s.jsxs(s.Fragment,{children:[s.jsx(Tr,{id:n,path:b,style:L}),F&&s.jsxs("g",{fill:L.stroke,opacity:L.opacity,children:[F.pad&&s.jsx("circle",{cx:F.pad.cx,cy:F.pad.cy,r:F.pad.r}),F.arrows.map((W,G)=>s.jsx("polygon",{points:W},G))]}),p&&s.jsx("path",{className:"trace-flow",d:R,fill:"none",stroke:"#a78bfa",strokeWidth:Math.max(3.5,1.5+6*j),strokeLinecap:"round",strokeDasharray:"16 26",style:{animation:`traceFlow ${zl}ms linear forwards`}},p.id)]}):null});function wb({debugInfo:e,onRefresh:t}){const n=pe(d=>d.showLogDrawer),r=pe(d=>d.setShowLogDrawer),[o,a]=k.useState("feed");if(!n)return null;const i=e?.messageLog.length??0,l=e?e.backgroundAgents.length+e.foregroundAgents.length:0;return s.jsxs("div",{className:"absolute top-0 right-0 h-full w-[320px] bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm border-l border-neutral-200 dark:border-neutral-800 shadow-xl z-20 flex flex-col animate-[slideIn_0.2s_ease-out]",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-neutral-200 dark:border-neutral-800 shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-violet-400"}),s.jsx("h3",{className:"text-[11px] font-semibold text-neutral-700 dark:text-neutral-200 tracking-wide",children:"Activity"})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("button",{onClick:t,title:"Refresh",className:"p-1 rounded-full text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-200 hover:bg-neutral-100 dark:hover:bg-neutral-800",children:s.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("path",{d:"M21 12a9 9 0 11-2.64-6.36"}),s.jsx("path",{d:"M21 3v6h-6"})]})}),s.jsx("button",{onClick:()=>r(!1),title:"Close",className:"p-1 rounded-full text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-200 hover:bg-neutral-100 dark:hover:bg-neutral-800",children:s.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:s.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]})]}),s.jsxs("div",{className:"flex items-center gap-1 px-3 py-1.5 border-b border-neutral-200 dark:border-neutral-800 shrink-0",children:[s.jsxs(rl,{active:o==="feed",onClick:()=>a("feed"),children:["Feed",i>0?` · ${i}`:""]}),s.jsxs(rl,{active:o==="bus",onClick:()=>a("bus"),children:["Bus",l>0?` · ${l}`:""]})]}),e?o==="feed"?s.jsx(vb,{messages:e.messageLog}):s.jsx(jb,{debugInfo:e}):s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsx("p",{className:"text-xs text-[var(--adf-ui-text-subtle)]",children:"Loading…"})})]})}function rl({active:e,onClick:t,children:n}){return s.jsx("button",{onClick:t,className:`px-2.5 py-0.5 text-[11px] rounded-full transition-colors ${e?"bg-neutral-900 dark:bg-neutral-100 text-white dark:text-neutral-900 font-medium":"text-neutral-500 dark:text-neutral-400 hover:bg-neutral-100 dark:hover:bg-neutral-800"}`,children:n})}function vb({messages:e}){const[t,n]=k.useState(""),[r,o]=k.useState("all"),[a,i]=k.useState(null),l=Mb(3e4),d=k.useMemo(()=>{const u=t.trim().toLowerCase();return[...e.filter(f=>r==="delivered"&&!f.delivered||r==="failed"&&f.delivered?!1:u?an(f.from).toLowerCase().includes(u)||f.to.some(m=>an(m).toLowerCase().includes(u))||f.deliveredTo.some(m=>an(m).toLowerCase().includes(u))||f.channel.toLowerCase().includes(u)||f.content.toLowerCase().includes(u):!0)].sort((f,m)=>m.timestamp-f.timestamp)},[e,t,r]),c=k.useMemo(()=>e.filter(u=>!u.delivered).length,[e]);return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"px-3 py-2 border-b border-neutral-200 dark:border-neutral-800 space-y-1.5 shrink-0",children:[s.jsxs("div",{className:"relative",children:[s.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2 top-1/2 -translate-y-1/2 text-[var(--adf-ui-text-subtle)] pointer-events-none",children:[s.jsx("circle",{cx:"11",cy:"11",r:"7"}),s.jsx("path",{d:"M21 21l-4.3-4.3"})]}),s.jsx("input",{type:"text",value:t,onChange:u=>n(u.target.value),placeholder:"Filter by agent, channel, content…",className:"w-full pl-7 pr-2 py-1 text-[11px] rounded-full bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-200 placeholder:text-[var(--adf-ui-text-subtle)] border border-transparent focus:border-violet-300 dark:focus:border-violet-700 focus:bg-white dark:focus:bg-neutral-900 outline-none transition-colors"})]}),s.jsx("div",{className:"flex items-center gap-0.5 p-0.5 rounded-full bg-neutral-100 dark:bg-neutral-800 w-fit",children:["all","delivered","failed"].map(u=>s.jsx("button",{onClick:()=>o(u),className:`px-2 py-px text-[10px] rounded-full capitalize transition-colors ${r===u?"bg-white dark:bg-neutral-900 shadow-sm text-neutral-700 dark:text-neutral-200 font-medium":"text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200"}`,children:u==="failed"&&c>0?`failed · ${c}`:u},u))})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:d.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center py-12 px-4 text-center",children:[s.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[var(--adf-ui-icon-muted)] mb-2",children:[s.jsx("path",{d:"M22 2L11 13"}),s.jsx("path",{d:"M22 2l-7 20-4-9-9-4 20-7z"})]}),e.length===0?s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"text-xs text-[var(--adf-ui-text-subtle)]",children:"No messages yet"}),s.jsx("p",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] mt-1",children:"Agent-to-agent traffic will show up here"})]}):s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"text-xs text-[var(--adf-ui-text-subtle)]",children:"Nothing matches"}),s.jsx("p",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] mt-1",children:"Try a different filter"})]})]}):s.jsx("div",{className:"divide-y divide-neutral-100 dark:divide-neutral-800/70",children:d.map(u=>s.jsx(kb,{entry:u,now:l,expanded:a===u.messageId,onToggle:()=>i(h=>h===u.messageId?null:u.messageId)},u.messageId))})})]})}function kb({entry:e,now:t,expanded:n,onToggle:r}){const o=e.deliveredTo.length>0?e.deliveredTo:e.to,a=o.slice(0,2),i=o.length-a.length;return s.jsxs("div",{className:`border-l-2 ${e.delivered?"border-l-transparent":"border-l-red-400 dark:border-l-red-500 bg-red-50/50 dark:bg-red-900/10"}`,children:[s.jsxs("button",{onClick:r,className:"w-full text-left px-3 py-1.5 hover:bg-neutral-50 dark:hover:bg-neutral-800/50 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[s.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-violet-400 dark:text-violet-500 shrink-0",children:[s.jsx("path",{d:"M22 2L11 13"}),s.jsx("path",{d:"M22 2l-7 20-4-9-9-4 20-7z"})]}),s.jsx(Po,{handle:an(e.from)}),s.jsx("span",{className:"text-[var(--adf-ui-icon-muted)] text-[10px] shrink-0",children:"→"}),s.jsxs("span",{className:"flex items-center gap-1 min-w-0 truncate",children:[a.length===0?s.jsx(Po,{handle:"*"}):a.map(l=>s.jsx(Po,{handle:an(l)},l)),i>0&&s.jsxs("span",{className:"text-[9px] text-[var(--adf-ui-text-subtle)] shrink-0",children:["+",i]})]}),s.jsxs("span",{className:"ml-auto flex items-center gap-1.5 shrink-0",children:[e.channel&&e.channel!=="*"&&s.jsxs("span",{className:"px-1.5 py-px rounded-full text-[9px] bg-violet-50 dark:bg-violet-900/30 text-violet-600 dark:text-violet-300 border border-violet-100 dark:border-violet-800/60",children:["#",e.channel]}),s.jsx("span",{className:"text-[9px] text-[var(--adf-ui-text-subtle)] tabular-nums",title:new Date(e.timestamp).toLocaleString(),children:$b(e.timestamp,t)}),s.jsx(Nb,{delivered:e.delivered,error:e.error})]})]}),e.content&&!n&&s.jsx("p",{className:"mt-0.5 pl-4 text-[10px] text-neutral-500 dark:text-neutral-400 truncate",children:e.content})]}),n&&s.jsxs("div",{className:"px-3 pb-2.5 pl-7 space-y-1.5",children:[s.jsx("div",{className:"rounded-lg bg-neutral-50 dark:bg-neutral-800/70 border border-neutral-200 dark:border-neutral-700/70 p-2 text-[10px] text-neutral-700 dark:text-neutral-300 whitespace-pre-wrap break-words max-h-48 overflow-y-auto font-mono",children:e.content||"(empty)"}),e.error&&s.jsx("div",{className:"rounded-lg bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800/60 p-2 text-[10px] text-red-600 dark:text-red-300 whitespace-pre-wrap break-words font-mono",children:e.error}),s.jsxs("div",{className:"grid grid-cols-[auto_1fr] gap-x-2 gap-y-0.5 text-[9px] font-mono",children:[s.jsx("span",{className:"text-[var(--adf-ui-text-subtle)]",children:"to"}),s.jsx("span",{className:"text-neutral-600 dark:text-neutral-300 break-all",children:e.to.map(an).join(", ")||"*"}),s.jsx("span",{className:"text-[var(--adf-ui-text-subtle)]",children:"delivered"}),s.jsx("span",{className:"text-neutral-600 dark:text-neutral-300 break-all",children:e.deliveredTo.map(an).join(", ")||"none"}),s.jsx("span",{className:"text-[var(--adf-ui-text-subtle)]",children:"type"}),s.jsx("span",{className:"text-neutral-600 dark:text-neutral-300",children:e.type}),s.jsx("span",{className:"text-[var(--adf-ui-text-subtle)]",children:"id"}),s.jsx("span",{className:"text-neutral-500 dark:text-neutral-400 break-all",children:e.messageId})]})]})]})}function Po({handle:e}){return s.jsx("span",{className:"px-1.5 py-px rounded-full text-[9px] font-medium bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-300 border border-neutral-200 dark:border-neutral-700 truncate max-w-[80px] shrink-0",children:e})}function Nb({delivered:e,error:t}){return e?s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-500 dark:text-green-400 shrink-0",children:s.jsx("path",{d:"M20 6L9 17l-5-5"})}):s.jsx("span",{title:t||"Delivery failed",className:"shrink-0",children:s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",className:"text-red-500 dark:text-red-400",children:s.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})}function jb({debugInfo:e}){return s.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-4",children:[s.jsxs("section",{children:[s.jsxs("h4",{className:"text-[10px] font-semibold text-[var(--adf-ui-text-subtle)] uppercase tracking-wider mb-1.5",children:["Bus registrations (",e.busRegistrations.length,")"]}),e.busRegistrations.length===0?s.jsx("p",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] italic",children:"No agents registered on the bus"}):s.jsx("div",{className:"space-y-1",children:e.busRegistrations.map((t,n)=>s.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap py-0.5",children:[s.jsx("span",{className:"text-[10px] font-mono text-neutral-600 dark:text-neutral-300",children:an(t.name)}),t.channels.filter(r=>r!=="*").map(r=>s.jsxs("span",{className:"px-1.5 py-px rounded-full text-[9px] bg-violet-50 dark:bg-violet-900/30 text-violet-600 dark:text-violet-300 border border-violet-100 dark:border-violet-800/60",children:["#",r]},r))]},n))})]}),s.jsxs("section",{children:[s.jsxs("h4",{className:"text-[10px] font-semibold text-[var(--adf-ui-text-subtle)] uppercase tracking-wider mb-1.5",children:["Agents (",e.backgroundAgents.length+e.foregroundAgents.length,")"]}),e.backgroundAgents.length===0&&e.foregroundAgents.length===0?s.jsx("p",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] italic",children:"No agents running"}):s.jsxs("div",{className:"space-y-0.5",children:[e.backgroundAgents.map(t=>s.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] py-0.5",children:[s.jsx(Sb,{state:t.state}),s.jsx("span",{className:"text-neutral-700 dark:text-neutral-300 truncate",children:t.name}),s.jsx("span",{className:"ml-auto flex items-center gap-1 shrink-0",children:s.jsx("span",{className:"px-1.5 py-px rounded-full text-[9px] bg-neutral-100 dark:bg-neutral-800 text-[var(--adf-ui-text-subtle-on-fill)] border border-neutral-200 dark:border-neutral-700",children:"bg"})})]},t.filePath)),e.foregroundAgents.map(t=>s.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] py-0.5",children:[s.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-400 shrink-0"}),s.jsx("span",{className:"text-neutral-700 dark:text-neutral-300 truncate",children:t.name}),s.jsx("span",{className:"ml-auto px-1.5 py-px rounded-full text-[9px] bg-blue-50 dark:bg-blue-900/30 text-blue-500 dark:text-blue-300 border border-blue-100 dark:border-blue-800/60 shrink-0",children:"fg"})]},t.filePath))]})]})]})}function Sb({state:e}){const t={active:"bg-yellow-400",idle:"bg-green-400",hibernate:"bg-purple-500",suspended:"bg-red-400",off:"bg-neutral-400",error:"bg-red-400"};return s.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${t[e]??"bg-neutral-400"}`,title:e})}function Mb(e){const[t,n]=k.useState(()=>Date.now());return k.useEffect(()=>{const r=setInterval(()=>n(Date.now()),e);return()=>clearInterval(r)},[e]),t}function $b(e,t){const n=Math.max(0,Math.floor((t-e)/1e3));if(n<10)return"now";if(n<60)return`${n}s`;const r=Math.floor(n/60);if(r<60)return`${r}m`;const o=Math.floor(r/60);return o<24?`${o}h`:`${Math.floor(o/24)}d`}function an(e){return Ve(e).replace(".adf","")}const sl=e=>Symbol.iterator in e,ol=e=>"entries"in e,al=(e,t)=>{const n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(const[o,a]of n)if(!r.has(o)||!Object.is(a,r.get(o)))return!1;return!0},Eb=(e,t)=>{const n=e[Symbol.iterator](),r=t[Symbol.iterator]();let o=n.next(),a=r.next();for(;!o.done&&!a.done;){if(!Object.is(o.value,a.value))return!1;o=n.next(),a=r.next()}return!!o.done&&!!a.done};function Cb(e,t){return Object.is(e,t)?!0:typeof e!="object"||e===null||typeof t!="object"||t===null||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:sl(e)&&sl(t)?ol(e)&&ol(t)?al(e,t):Eb(e,t):al({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function Ue(e){const t=Ol.useRef(void 0);return n=>{const r=e(n);return Cb(t.current,r)?t.current:t.current=r}}function Bu(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return t>>>0}const Mr=e=>40+Bu(e)%280,ia=e=>Bu(e)*137%360,_b={active:"bg-yellow-400",idle:"bg-green-400",error:"bg-red-400"},Xs=()=>document.documentElement.classList.contains("dark");function Wu(e,t){return e.length>t?e.slice(0,t-1)+"…":e}const vn=Je;function qu(e){return{fill:`hsla(40, 90%, ${e?36:74}%, 0.7)`,stroke:"hsla(40, 95%, 50%, 0.9)",strokeWidth:2.5,pulse:!0,dashed:!1}}function Pb(e,t,n,r,o,a){const i={fill:`hsla(220, 8%, ${t?18:90}%, ${t?.35:.45})`,stroke:`hsla(220, 8%, ${t?34:65}%, 0.25)`,strokeWidth:1,pulse:!1,dashed:!1};if(!n)return i;if(e==="burn"){if(n.online===!1||r<=0)return{...i,dashed:n.online===!1};const l=210-190*r;return{fill:`hsla(${l}, ${45+35*r}%, ${t?26+16*r:82-22*r}%, ${.5+.4*r})`,stroke:`hsla(${l}, 70%, ${t?55:45}%, ${.35+.5*r})`,strokeWidth:1+1.5*r,pulse:r>.85,dashed:!1}}if(e==="lineage"){if(!a||a.familySize<2)return{...i,dashed:n.online===!1||a?.duplicate===!0};const l=Math.min(a.depth,4),d=t?26+l*9:46+l*10;return{fill:`hsla(${a.hue}, 52%, ${d}%, 0.8)`,stroke:`hsla(${a.hue}, 58%, ${t?Math.min(72,d+16):Math.max(28,d-18)}%, 0.8)`,strokeWidth:a.depth===0?2.4:1.4,pulse:!1,dashed:a.broken||a.duplicate||n.online===!1}}if(e==="model"){if(!n.model)return{...i,dashed:n.online===!1};const l=ia(n.model),d=n.online===!1;return{fill:`hsla(${l}, ${d?18:48}%, ${t?30:80}%, ${d?.4:.65})`,stroke:`hsla(${l}, 55%, ${t?55:45}%, ${d?.3:.6})`,strokeWidth:1.4,pulse:!1,dashed:d}}return n.state==="error"?{fill:`hsla(0, 72%, ${t?34:74}%, 0.75)`,stroke:"hsla(0, 80%, 55%, 0.9)",strokeWidth:2.5,pulse:!0,dashed:!1}:o?qu(t):n.online===!1?{...i,dashed:!0}:{fill:`hsla(140, 30%, ${t?24:86}%, 0.5)`,stroke:`hsla(140, 35%, ${t?42:55}%, 0.35)`,strokeWidth:1,pulse:!1,dashed:!1}}function Ab(e,t,n,r,o){const a=o>=0?o%3*5+6:0,i=t?26-a*.6:88-a,l=t?30:42;if(!n)return{fill:`hsla(${e}, ${l-12}%, ${i+(t?-6:4)}%, ${t?.4:.5})`,stroke:`hsla(${e}, ${l}%, ${t?40:62}%, 0.28)`,strokeWidth:1,pulse:!1,dashed:!1};if(n.online===!1)return{fill:`hsla(${e}, 12%, ${t?32:85}%, ${t?.55:.65})`,stroke:`hsla(${e}, 16%, ${t?55:50}%, 0.55)`,strokeWidth:1.2,pulse:!1,dashed:!0};const d=Math.max(0,1-(Date.now()-r)/6e4);return n.state==="active"?{fill:`hsla(45, 85%, ${t?40:74}%, 0.5)`,stroke:`hsla(45, 90%, ${t?58:48}%, 0.75)`,strokeWidth:2,pulse:!0,dashed:!1}:n.state==="error"?{fill:`hsla(0, 60%, ${t?32:82}%, 0.55)`,stroke:`hsla(0, 70%, ${t?52:55}%, 0.65)`,strokeWidth:1.5,pulse:!1,dashed:!1}:{fill:`hsla(${e}, ${l+8+d*20}%, ${i+(t?4+d*8:-d*6)}%, ${t?.6:.75})`,stroke:`hsla(${e}, ${l+10}%, ${t?48:55}%, 0.5)`,strokeWidth:1.2,pulse:!1,dashed:!1}}const Vu={filter:"grayscale(1)",opacity:.45},Ib=k.memo(function(t){const n=t.data;return n.culled?s.jsx("div",{className:"pointer-events-none relative",style:{width:n.width,height:n.height}}):n.muted?s.jsx("div",{style:Vu,children:s.jsx(il,{...t})}):s.jsx(il,{...t})});function il({data:e}){const{dirPath:t,width:n,height:r,cells:o,members:a,districts:i,managed:l}=e,d=k.useMemo(()=>Mr(t),[t]),c=Xs(),u=ye(Ue(A=>{const L=new Map(ve(A).map(R=>[R.filePath,R]));return a.map(R=>L.get(R.filePath))})),h=pe(Ue(A=>a.map(L=>A.lastActivityAt[L.filePath]??0))),f=pe(Ue(A=>a.map(L=>!!A.pendingInteractions[L.filePath]))),m=pe(A=>A.focusedFilePath),y=J(A=>A.selection),S=J(A=>A.lens),x=J(A=>A.burn),b=J(A=>A.starting),$=J(A=>A.hoverDir),v=ye(A=>S==="lineage"?ve(A):null),p=k.useMemo(()=>{const A=x?.perAgent;if(!A)return()=>0;let L=0;for(const F of Object.values(A))L=Math.max(L,F.tokensPerMin);if(L<=0)return()=>0;const R=Math.log1p(L);return F=>{const W=A[F]?.tokensPerMin??0;return W>0?Math.log1p(W)/R:0}},[x]),M=k.useMemo(()=>{if(S!=="lineage"||!v)return null;const A=Ca(v),L=new Set(A.orphaned),R=new Set([...A.duplicateDids.values()].flat()),F=new Map,W=new Map;for(const G of v){let Y=G.filePath,ee=0;const B=new Set;for(;ee<32;){const Z=A.parents.get(Y);if(!Z||B.has(Z))break;B.add(Y),Y=Z,ee++}F.set(G.filePath,{rootPath:Y,depth:ee,broken:L.has(G.filePath),duplicate:R.has(G.filePath)}),W.set(Y,(W.get(Y)??0)+1)}return{info:F,rootCounts:W}},[S,v]),N=A=>{if(!M)return null;const L=M.info.get(A);return L?{hue:Mr(L.rootPath),depth:L.depth,familySize:M.rootCounts.get(L.rootPath)??1,broken:L.broken,duplicate:L.duplicate}:null},w=k.useMemo(()=>new Map(a.map((A,L)=>[A.filePath,L])),[a]),g=k.useMemo(()=>new Map(u.filter(A=>!!A).map(A=>[A.filePath,A])),[u]),E=k.useMemo(()=>new Set(y),[y]),T=k.useMemo(()=>new Map(i.map((A,L)=>[A,L])),[i]),j=A=>h[w.get(A)??-1]??0,_=k.useMemo(()=>aa(o,fe-2),[o]),I=$===t,C=$&&Rr($,t)?$.slice(t.length+1):null,O=k.useMemo(()=>{if(!C)return null;const A=o.filter(L=>L.district===C);return A.length>0?aa(A,fe-2):null},[o,C]);return s.jsx("div",{className:"pointer-events-none relative",style:{width:n,height:r},children:s.jsxs("svg",{width:n,height:r,className:"absolute inset-0 overflow-visible",children:[o.map(A=>{const L=A.filePath?g.get(A.filePath):void 0,R=A.filePath?f[w.get(A.filePath)??-1]??!1:!1,F=R?qu(c):S==="terrain"?Ab(d,c,L,A.filePath?j(A.filePath):0,A.district?T.get(A.district)??-1:-1):Pb(S,c,L,A.filePath?p(A.filePath):0,!!R,A.filePath?N(A.filePath):null),W=A.filePath!=null&&A.filePath===m,G=A.filePath!=null&&E.has(A.filePath),Y=A.filePath!=null&&!!b[A.filePath]&&L?.online===!1;return s.jsxs("g",{children:[s.jsx("polygon",{points:lt(A.x,A.y,fe-2),fill:F.fill,stroke:F.stroke,strokeWidth:F.strokeWidth,strokeOpacity:.4,strokeDasharray:F.dashed?"7 5":void 0,style:F.pulse||Y?{animation:"hexPulse 2.4s ease-in-out infinite"}:void 0}),Y&&s.jsx("polygon",{points:lt(A.x,A.y,fe-10),fill:"none",stroke:c?"#5eead4":"#0d9488",strokeWidth:3,strokeDasharray:"26 17",strokeLinecap:"round",style:{animation:"hexDashFlow 3.2s linear infinite"}}),R&&s.jsx("polygon",{points:lt(A.x,A.y,fe-7),fill:"none",stroke:"#f59e0b",strokeWidth:3.5,style:{animation:"hexPulse 1.6s ease-in-out infinite"}}),(W||G)&&!R&&s.jsx("polygon",{points:lt(A.x,A.y,fe-7),fill:"none",stroke:W?"#8b5cf6":"#3b82f6",strokeWidth:2.5,opacity:.85})]},`${A.q},${A.r}`)}),s.jsx("path",{d:_,fill:"none",stroke:I?`hsla(${d}, ${c?45:48}%, ${c?66:36}%, 0.9)`:`hsla(${d}, ${c?32:36}%, ${c?56:40}%, ${c?.55:.5})`,strokeWidth:I?3.5:2.5,strokeLinecap:"round",style:l&&!I?{transition:"stroke 150ms ease, stroke-width 150ms ease",stroke:"var(--ink-faint)"}:{transition:"stroke 150ms ease, stroke-width 150ms ease"}}),O&&s.jsx("path",{d:O,fill:"none",stroke:`hsla(${d}, ${c?45:48}%, ${c?66:36}%, 0.9)`,strokeWidth:3.5,strokeLinecap:"round"})]})})}const Tb=Math.SQRT2,Rb=1/Math.SQRT2,Db=150,Ao=.1;function Xu(e){const{canvas:t,store:n,maxBackingPx:r,maxPad:o,draw:a,zoomInvalidates:i}=e,l=t.getContext("2d");if(!l)return()=>{};let d=null,c;const u=()=>document.documentElement.classList.contains("dark"),h=()=>{const p=t.parentElement?.getBoundingClientRect();if(!p||p.width<1||p.height<1)return;const[M,N,w]=n.getState().transform,g=p.width,E=p.height;let T=Math.min(2,window.devicePixelRatio||1);const j=Math.sqrt(r/(g*E*T*T));let _;j>=1+2*o?_=o:j>=1+2*Ao?_=(j-1)/2:(_=Ao,T*=j/(1+2*Ao));const I=Math.round(g*_),C=Math.round(E*_),O=Math.round((g+2*I)*T),A=Math.round((E+2*C)*T);(t.width!==O||t.height!==A)&&(t.width=O,t.height=A),t.style.left=`${-I}px`,t.style.top=`${-C}px`,t.style.width=`${g+2*I}px`,t.style.height=`${E+2*C}px`,t.style.transform="translate3d(0px, 0px, 0)",d={tx:M,ty:N,zoom:w,W:g,H:E,padW:I,padH:C,dpr:T,dark:u()},a(l,d)},f=()=>{c=void 0;const p=d;if(!p)return;const[M,N,w]=n.getState().transform;(M!==p.tx||N!==p.ty||w!==p.zoom)&&h()},m=()=>{const p=d;if(!p){h();return}const[M,N,w]=n.getState().transform;if(M===p.tx&&N===p.ty&&w===p.zoom)return;c&&clearTimeout(c),c=setTimeout(f,Db);const g=w/p.zoom;let E=g<Rb||g>Tb||(i?.(w,p.zoom)??!1);if(!E){const _=-M/w,I=(p.W-M)/w,C=-N/w,O=(p.H-N)/w,A=(-p.padW-p.tx)/p.zoom,L=(p.W+p.padW-p.tx)/p.zoom,R=(-p.padH-p.ty)/p.zoom,F=(p.H+p.padH-p.ty)/p.zoom;E=_<A||I>L||C<R||O>F}if(E){h();return}const T=(1-g)*p.padW+M-g*p.tx,j=(1-g)*p.padH+N-g*p.ty;t.style.transform=`translate3d(${T}px, ${j}px, 0) scale(${g})`};let y=null;const S=()=>{x(),h()},x=()=>{y?.removeEventListener("change",S),y=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),y.addEventListener("change",S)};x(),h();const b=n.subscribe(m),$=new ResizeObserver(h);t.parentElement&&$.observe(t.parentElement);const v=new MutationObserver(()=>{d&&d.dark!==u()&&h()});return v.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{c&&clearTimeout(c),y?.removeEventListener("change",S),b(),$.disconnect(),v.disconnect()}}const ar=2*Fe,pn=$e;function Lb(e,t,n,r){for(let o=0;o<6;o++){const a=o*Math.PI/3,i=t+r*Math.cos(a),l=n+r*Math.sin(a);o===0?e.moveTo(i,l):e.lineTo(i,l)}e.closePath()}const Ob=e=>`radial-gradient(60% 50% at 82% 85%, ${e?"rgba(167, 139, 250, 0.05)":"rgba(139, 92, 246, 0.035)"} 0%, rgba(167, 139, 250, 0) 100%), radial-gradient(55% 45% at 22% 18%, ${e?"rgba(45, 212, 191, 0.07)":"rgba(20, 184, 166, 0.05)"} 0%, rgba(45, 212, 191, 0) 100%)`,Fb=k.memo(function(){const t=k.useRef(null),n=k.useRef(null),r=Se();return k.useEffect(()=>{const o=n.current;if(!o)return;const a=document.createElement("canvas");let i=null,l=1,d=1;const c=(m,y,S,x)=>{const b=S?"rgba(94, 234, 212, 0.055)":"rgba(15, 118, 110, 0.07)",$=S?"rgba(30, 41, 59, 0.22)":"rgba(245, 245, 244, 0.4)",v=Math.max(1,Math.round(ar*m*y)),p=Math.max(1,Math.round(pn*m*y));a.width=v,a.height=p;const M=a.getContext("2d");if(!M)return;M.setTransform(v/ar,0,0,p/pn,0,0),M.lineWidth=1.2,M.strokeStyle=b,M.fillStyle=$;const N=[[0,0],[Fe,pn/2],[0,pn],[Fe,-pn/2],[ar,0],[ar,pn]];for(const[w,g]of N)M.beginPath(),Lb(M,w,g,fe-2),M.fill(),M.stroke();i=x.createPattern(a,"repeat"),l=ar*m*y/v,d=pn*m*y/p},u=Xu({canvas:o,store:r,maxBackingPx:12e6,maxPad:.25,draw:(m,y)=>{if(c(y.zoom,y.dpr,y.dark,m),m.setTransform(1,0,0,1,0,0),m.clearRect(0,0,o.width,o.height),!i)return;const S=new DOMMatrix().translateSelf((y.tx+y.padW)*y.dpr,(y.ty+y.padH)*y.dpr).scaleSelf(l,d);i.setTransform(S),m.fillStyle=i,m.fillRect(0,0,o.width,o.height)}}),h=()=>{t.current&&(t.current.style.background=Ob(document.documentElement.classList.contains("dark")))};h();const f=new MutationObserver(h);return f.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{u(),f.disconnect()}},[r]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:t,className:"hex-garden-wash absolute inset-0 pointer-events-none",style:{zIndex:-10}}),s.jsx("canvas",{ref:n,className:"absolute pointer-events-none",style:{zIndex:-10,transformOrigin:"0 0",willChange:"transform"}})]})}),zb=k.memo(function({onFocusAgent:t,onSelectGroup:n}){const r=J(j=>j.namedGroups),o=J(j=>j.setNamedGroups),a=J(j=>j.lens),i=J(j=>j.voicesOverride),l=J(j=>j.setVoicesOverride),d=i??a==="terrain",[c,u]=k.useState(null);k.useEffect(()=>{if(!c)return;const j=_=>{_.key==="Escape"&&u(null)};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[c]);const h=async j=>{if(!window.confirm(`Forget group "${j}"? The agents in it are not affected.`))return;const _={...r};delete _[j],o(_);try{await qo({groups:_},_t.getState().runtimes)}catch{}},f=ye(Ue(j=>new Map(ve(j).map(_=>[_.filePath,_.handle])))),m=ye(Ue(j=>new Map(ve(j).map(_=>[_.filePath,mt({did:_.did,filePath:_.filePath})])))),y=ye(Ue(j=>new Map(ve(j).map(_=>[_.filePath,ql(_.icon,_.agentId||_.filePath)])))),S=pe(j=>j.pendingInteractions),x=J(j=>j.burn?.fleet),b=J(j=>j.burn?.perAgent),$=pe(j=>j.activityInWindow)/5,v=pe(j=>j.messageInWindow)/5,p=pe(j=>{let _=0,I=null;for(const[C,O]of Object.entries(j.lastActivityAt))O>_&&(_=O,I=C);return I}),M=k.useMemo(()=>{let j=null,_=0;if(b)for(const[I,C]of Object.entries(b))C.tokensPerMin>_&&(_=C.tokensPerMin,j={filePath:I,label:`${Je(C.tokensPerMin)}/m`});return!j&&p&&(j={filePath:p,label:"active"}),!j||!f.has(j.filePath)?null:{...j,handle:f.get(j.filePath),seed:m.get(j.filePath)??null,icon:y.get(j.filePath)??null}},[b,p,f,m,y]),N=ye(Ue(j=>{let _=0,I=0,C=0,O=0;for(const A of ve(j))A.online?A.state==="active"?_++:A.state==="idle"?I++:A.state==="error"&&C++:O++;return{active:_,idle:I,error:C,offline:O}})),w=k.useMemo(()=>Object.entries(S).sort(([j],[_])=>j.localeCompare(_)).map(([j,_])=>({filePath:j,pending:_,handle:f.get(j)??Ve(j).replace(".adf","")})),[f,S]),g=k.useRef(0),[E,T]=k.useState(0);return k.useEffect(()=>{w.length>g.current&&T(j=>j+1),g.current=w.length},[w.length]),s.jsxs("div",{className:"absolute top-10 left-0 right-0 z-20 flex items-center gap-2 px-4 py-1.5 pointer-events-none",children:[s.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1 rounded-full bg-white/85 dark:bg-neutral-900/85 backdrop-blur-sm border border-neutral-200 dark:border-neutral-800 shadow-sm pointer-events-auto select-none shrink-0 whitespace-nowrap",children:[s.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-neutral-600 dark:text-neutral-300",title:"Active agents",children:[s.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-yellow-400"}),N.active]}),s.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-neutral-600 dark:text-neutral-300",title:"Idle agents (press , to cycle)",children:[s.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-400"}),N.idle]}),N.error>0&&s.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-red-500",title:"Agents in error state",children:[s.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-red-400"}),N.error]}),N.offline>0&&s.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[var(--adf-ui-text-subtle)]",title:"Offline agents (not started)",children:[s.jsx("span",{className:"w-1.5 h-1.5 rounded-full border border-dashed border-neutral-400"}),N.offline]}),x&&x.totalTokens>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"w-px h-3 bg-neutral-200 dark:bg-neutral-700"}),s.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-orange-500 dark:text-orange-400 tabular-nums",title:`Fleet tokens, all time: ${x.totalTokens.toLocaleString()} · ↑ ${Math.round(x.inPerMin??0)} in / ↓ ${Math.round(x.outPerMin??0)} out tokens/min (5-min window)`,children:[s.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"currentColor",children:s.jsx("path",{d:"M13 2L3 14h7l-1 8 10-12h-7l1-8z"})}),"Σ ",Je(x.totalTokens),x.tokensPerMin>0&&s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"text-[var(--adf-ui-text-subtle)]",children:["↑",Je(x.inPerMin??0)]}),s.jsxs("span",{className:"text-orange-400/90 dark:text-orange-500/90",children:["↓",Je(x.outPerMin??0),"/m"]})]})]})]}),($>0||v>0)&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"w-px h-3 bg-neutral-200 dark:bg-neutral-700"}),$>0&&s.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-blue-500 dark:text-blue-400 tabular-nums",title:"Fleet tool calls per minute (5-min window)",children:[s.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:s.jsx("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),$<10?$.toFixed(1):Math.round($),"/m"]}),v>0&&s.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-violet-500 dark:text-violet-400 tabular-nums",title:"Agent-to-agent messages per minute (5-min window)",children:[s.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:s.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})}),v<10?v.toFixed(1):Math.round(v),"/m"]})]})]}),Object.keys(r).length>3&&s.jsxs("div",{className:"relative shrink-0 pointer-events-auto",children:[s.jsxs("button",{onClick:()=>u(c==="groups"?null:"groups"),className:"flex items-center gap-1 px-2.5 py-1 rounded-full bg-white/85 dark:bg-neutral-900/85 backdrop-blur-sm border border-neutral-200 dark:border-neutral-800 shadow-sm select-none text-[11px] font-medium text-neutral-600 dark:text-neutral-300 hover:text-neutral-900 dark:hover:text-white whitespace-nowrap",title:`${Object.keys(r).length} named groups — click to browse`,children:["⬡ groups (",Object.keys(r).length,") ▾"]}),c==="groups"&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10 pointer-events-auto",onClick:()=>u(null)}),s.jsx("div",{className:"absolute top-full left-0 mt-1 rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 shadow-xl py-1 z-20 pointer-events-auto max-h-[60vh] overflow-y-auto min-w-[220px]",children:Object.entries(r).map(([j,_])=>s.jsxs("div",{className:"flex items-center gap-1 pl-3 pr-2 py-1.5 hover:bg-neutral-100 dark:hover:bg-neutral-800",children:[s.jsxs("button",{onClick:()=>{n(_),u(null)},className:"flex-1 flex items-center justify-between gap-2 text-left text-[11px] font-medium text-neutral-600 dark:text-neutral-300 hover:text-neutral-900 dark:hover:text-white whitespace-nowrap",title:`Select ${_.length} agent${_.length!==1?"s":""}`,children:[j,s.jsx("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)]",children:_.length})]}),s.jsx("button",{onClick:()=>h(j),className:"w-3.5 h-3.5 shrink-0 flex items-center justify-center rounded-full text-[var(--adf-ui-icon-muted)] hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/30",title:"Forget group",children:s.jsx("svg",{width:"7",height:"7",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:s.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]},j))})]})]}),s.jsxs("div",{className:"flex-1 min-w-0 overflow-x-auto [scrollbar-width:thin] flex items-center gap-2",children:[Object.keys(r).length>0&&Object.keys(r).length<=3&&s.jsx("div",{className:"flex items-center gap-1 shrink-0 pointer-events-auto",children:Object.entries(r).map(([j,_])=>s.jsxs("span",{className:"group flex items-center gap-1 pl-2.5 pr-1.5 py-1 rounded-full bg-white/85 dark:bg-neutral-900/85 backdrop-blur-sm border border-neutral-200 dark:border-neutral-800 shadow-sm select-none shrink-0 whitespace-nowrap",children:[s.jsxs("button",{onClick:()=>n(_),className:"flex items-center gap-1 text-[11px] font-medium text-neutral-600 dark:text-neutral-300 hover:text-neutral-900 dark:hover:text-white",title:`Select ${_.length} agent${_.length!==1?"s":""}`,children:[j,s.jsx("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)]",children:_.length})]}),s.jsx("button",{onClick:()=>h(j),className:"w-3.5 h-3.5 flex items-center justify-center rounded-full text-[var(--adf-ui-icon-muted)] hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/30 opacity-0 group-hover:opacity-100",title:"Forget group",children:s.jsx("svg",{width:"7",height:"7",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:s.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})]},j))}),s.jsxs("button",{onClick:()=>l(!d),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-full backdrop-blur-sm border shadow-sm pointer-events-auto select-none shrink-0 whitespace-nowrap text-[11px] font-medium transition-colors ${d?"bg-white/85 dark:bg-neutral-900/85 border-neutral-200 dark:border-neutral-800 text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200":"bg-white/60 dark:bg-neutral-900/60 border-dashed border-neutral-300 dark:border-neutral-700 text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-300"}`,title:"Voices — group status chips over the plots. On by default for terrain, hidden on diagnostic lenses. Press V to toggle.",children:[s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:s.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-9 8.4 8.5 8.5 0 0 1-3.4-.7L3 21l1.8-5.6a8.38 8.38 0 0 1-.8-3.9 8.5 8.5 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"})}),"voices",d?"":" off"]}),M&&s.jsxs("button",{onClick:()=>t(M.filePath),className:"flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-white/85 dark:bg-neutral-900/85 backdrop-blur-sm border border-neutral-200 dark:border-neutral-800 shadow-sm pointer-events-auto select-none shrink-0 whitespace-nowrap hover:border-orange-300 dark:hover:border-orange-700",title:"Highest token burn right now — click to fly there",children:[s.jsx("span",{className:"text-[11px]",children:"🔥"}),s.jsx(Ct,{seed:M.seed,icon:M.icon,size:14,emojiSize:12}),s.jsx("span",{className:"text-[11px] font-medium text-neutral-700 dark:text-neutral-200",children:M.handle}),s.jsx("span",{className:"text-[10px] text-orange-500 dark:text-orange-400 tabular-nums",children:M.label})]})]}),w.length>0&&s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 pointer-events-auto rounded-full",style:E>0?{animation:"needsYouFlash 800ms ease-out"}:void 0,children:[w.length<=2?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"text-[11px] font-medium text-amber-600 dark:text-amber-400 shrink-0 select-none whitespace-nowrap",children:["Needs you (",w.length,")"]}),s.jsx("div",{className:"flex items-center gap-1 overflow-x-auto min-w-0",children:w.map(({filePath:j,handle:_,pending:I})=>s.jsxs("button",{onClick:()=>{t(j),I.type==="approval"&&J.getState().setHilModal(j)},className:"flex items-center gap-1 px-2 py-0.5 text-[11px] rounded-full bg-amber-50 dark:bg-amber-900/30 border border-amber-300 dark:border-amber-700 text-amber-700 dark:text-amber-300 hover:bg-amber-100 dark:hover:bg-amber-900/50 whitespace-nowrap shrink-0",title:I.type==="ask"?Wo(I.questions):`Approve ${I.toolName}?`,children:[s.jsx("span",{className:"font-medium",children:_}),s.jsx("span",{className:"text-amber-500 dark:text-amber-400",children:I.type==="ask"?"asks":`wants ${I.toolName}`})]},j))})]}):s.jsxs("div",{className:"relative shrink-0",children:[s.jsxs("button",{onClick:()=>u(c==="needs"?null:"needs"),className:"flex items-center gap-1 px-2.5 py-1 text-[11px] font-medium rounded-full bg-amber-50 dark:bg-amber-900/30 border border-amber-300 dark:border-amber-700 text-amber-700 dark:text-amber-300 hover:bg-amber-100 dark:hover:bg-amber-900/50 whitespace-nowrap select-none",title:`${w.length} agents need your input — click to browse`,children:["Needs you (",w.length,") ▾"]}),c==="needs"&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10 pointer-events-auto",onClick:()=>u(null)}),s.jsx("div",{className:"absolute top-full right-0 mt-1 rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 shadow-xl py-1 z-20 pointer-events-auto max-h-[60vh] overflow-y-auto min-w-[220px]",children:w.map(({filePath:j,handle:_,pending:I})=>s.jsxs("button",{onClick:()=>{t(j),I.type==="approval"&&J.getState().setHilModal(j),u(null)},className:"w-full flex items-center gap-1.5 pl-3 pr-2 py-1.5 text-left text-[11px] hover:bg-amber-50 dark:hover:bg-amber-900/30 whitespace-nowrap",title:I.type==="ask"?Wo(I.questions):`Approve ${I.toolName}?`,children:[s.jsx("span",{className:"font-medium text-amber-700 dark:text-amber-300",children:_}),s.jsx("span",{className:"text-amber-500 dark:text-amber-400",children:I.type==="ask"?"asks":`wants ${I.toolName}`})]},j))})]})]}),s.jsxs("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] shrink-0 select-none whitespace-nowrap hidden sm:inline",children:["press ",s.jsx("kbd",{className:"px-1 rounded border border-neutral-300 dark:border-neutral-700",children:"."})," to cycle"]})]},E)]})}),Io=46,Hb=10,Bb=5*6e4,Wb=6e3,ll=4,qb=2e3,Vb={active:"bg-yellow-400",idle:"bg-green-400",error:"bg-red-400",hibernate:"bg-sky-400",suspended:"bg-orange-400"};function Xb(e){const t=e.latest;if(t&&t.type!=="state"){const n=Ea[t.type];return t.type==="tool_start"?{mark:"·",markColor:t.isError?"text-red-400":"text-[var(--adf-ui-text-subtle)]",text:t.args?`${t.toolName} — ${t.args}`:t.toolName}:t.type==="message_sent"?{mark:">",markColor:"text-purple-400",text:t.args?`msg_send ${t.args}`:"msg_send"}:t.type==="message_recv"?{mark:"<",markColor:"text-purple-400",text:t.args?`msg from ${t.args}`:"msg received"}:{mark:n?.mark??"·",markColor:n?.markColor??"text-[var(--adf-ui-text-subtle)]",text:t.args??t.toolName}}return e.agent.status?{mark:"·",markColor:"text-[var(--adf-ui-text-subtle)]",text:e.agent.status}:t?{mark:"→",markColor:"text-[var(--adf-ui-text-subtle)]",text:(t.args??"").replace(/^→\s*/,"")||e.agent.state}:{mark:"·",markColor:"text-[var(--adf-ui-text-subtle)]",text:e.agent.state}}const Yb=k.memo(function({onFocusAgent:t}){const[n,r]=k.useState(!1),[o,a]=k.useState(0);k.useEffect(()=>{const c=setInterval(()=>a(u=>u+1),2e3);return()=>clearInterval(c)},[]);const i=k.useMemo(()=>{const c=Date.now(),{agentPulse:u,nodeActivities:h}=pe.getState(),{burn:f,burnBaseline:m}=J.getState(),y=f?.perAgent,S=[];for(const x of ve(ye.getState())){const b=u[x.filePath],$=b?b.filter(g=>c-g<Bb).length:0,v=y?.[x.filePath],p=v?.tokensPerMin??0;if($===0&&p===0)continue;const M=h[x.filePath],N=M&&M.length>0?Ps(M,g=>g.type!=="state")??M[M.length-1]:null,w=m[x.filePath]??0;S.push({agent:x,burn:p,inBurn:v?.inPerMin??0,outBurn:v?.outPerMin??0,events:$,lastAt:N?.timestamp??0,latest:N,deviant:p>qb&&w>0&&p>ll*w})}return S.sort((x,b)=>b.burn-x.burn||b.events-x.events||b.lastAt-x.lastAt||x.agent.filePath.localeCompare(b.agent.filePath)),S.slice(0,Hb)},[o]),l=k.useRef(new Map),d=k.useRef(new Map);return k.useEffect(()=>{const c=l.current,u=new Map;i.forEach((h,f)=>{u.set(h.agent.filePath,f);const m=c.get(h.agent.filePath);m!==void 0&&m!==f&&d.current.set(h.agent.filePath,{delta:m-f,at:Date.now()})}),l.current=u},[i]),i.length===0?null:s.jsx("div",{className:"relative w-full pointer-events-auto select-none",children:s.jsxs("div",{className:"rounded-lg bg-white/85 dark:bg-neutral-900/85 backdrop-blur-sm border border-neutral-200 dark:border-neutral-800 shadow-sm overflow-hidden",children:[s.jsxs("button",{onClick:()=>r(!n),className:"w-full flex items-center justify-between px-3 py-1.5 text-[11px] font-medium text-neutral-600 dark:text-neutral-300 hover:bg-neutral-100/60 dark:hover:bg-neutral-800/60 transition-colors",title:"Where the fleet's tokens are going — amber means burn far above the agent's own baseline",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{children:"🔥"}),"Burn"]}),s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-[var(--adf-ui-text-subtle)] transition-transform ${n?"-rotate-90":""}`,children:s.jsx("path",{d:"M6 9l6 6 6-6"})})]}),!n&&s.jsx("div",{className:"relative overflow-y-auto max-h-[55vh]",style:{height:i.length*Io},children:i.map((c,u)=>{const h=c.agent.filePath,f=d.current.get(h),m=f&&Date.now()-f.at<Wb?f.delta:0,y=Xb(c);return s.jsxs("button",{onClick:()=>t(h),className:`absolute left-0 right-0 flex items-center gap-2 px-2.5 text-left transition-[top] duration-700 ease-in-out hover:bg-neutral-100/60 dark:hover:bg-neutral-800/60 ${c.deviant?"bg-amber-50/70 dark:bg-amber-500/10":""}`,style:{top:u*Io,height:Io},title:c.latest?.detail??(c.deviant?`${c.agent.handle} — burn is >${ll}× its usual rate`:`${c.agent.handle} — ${c.events} events / 5 min`),children:[s.jsx("span",{className:"w-5 shrink-0 text-right font-mono text-[11px] tabular-nums text-[var(--adf-ui-text-subtle)]",children:u+1}),s.jsxs("span",{className:"w-3 shrink-0 text-[9px] font-mono",children:[m>0&&s.jsx("span",{className:"text-green-500",children:"▲"}),m<0&&s.jsx("span",{className:"text-red-400",children:"▼"})]}),s.jsx("span",{className:"shrink-0 text-base leading-none",children:s.jsx(Ct,{seed:mt({did:c.agent.did,filePath:c.agent.filePath}),icon:c.agent.icon,iconSeed:c.agent.agentId||c.agent.filePath,size:18,emojiSize:16})}),s.jsxs("span",{className:"flex-1 min-w-0",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-[11px] font-medium text-neutral-700 dark:text-neutral-200",children:c.agent.handle}),s.jsx("span",{className:`w-1.5 h-1.5 shrink-0 rounded-full ${Vb[c.agent.state]??"bg-neutral-400"}`})]}),s.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-neutral-500 dark:text-neutral-400",children:[s.jsx("span",{className:`shrink-0 font-mono ${y.markColor}`,children:y.mark}),s.jsx("span",{className:"truncate",children:y.text})]})]}),c.burn>0?s.jsxs("span",{className:`shrink-0 flex flex-col items-end font-mono text-[9px] leading-[13px] tabular-nums ${c.deviant?"text-amber-600 dark:text-amber-400 font-semibold":""}`,title:"↑ input / ↓ output tokens per minute (5-min window)",children:[s.jsxs("span",{className:c.deviant?"":"text-[var(--adf-ui-text-subtle)]",children:["↑",Je(c.inBurn)]}),s.jsxs("span",{className:c.deviant?"":"text-orange-500/80 dark:text-orange-400/80",children:["↓",Je(c.outBurn)]})]}):s.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-[var(--adf-ui-text-subtle)]",title:"Events in the last 5 min",children:c.events})]},h)})})]})})}),Gb=.35,Ub=.1,Kb=e=>e.transform[2]<Gb,Zb=e=>e.transform[2]<Ub,Qb=[],Cs=(e,t,n)=>Math.min(n,Math.max(t,e));function Jb(e,t){if(e.length<=t)return[e];let n=e.lastIndexOf(" ",t);n<t*.55&&(n=t);const r=e.slice(0,n);let o=e.slice(n).trimStart();return o.length>t&&(o=o.slice(0,t-1)+"…"),[r,o]}function ey(e){const t=e.isError===!0?"✗ ":e.type==="message_sent"?"→ ":e.type==="message_recv"?"← ":"";return Wu(`${t}${e.toolName}${e.args?" "+e.args:""}`,34)}const cl=(e,t,n)=>Math.min(Cs(34/e,30,150),Math.max(26,t*1.1/(.6*Math.max(4,n)))),ty=k.memo(function(t){const n=t.data;return n.culled?s.jsx("div",{className:"pointer-events-none relative",style:{width:n.width,height:n.height}}):n.muted?s.jsx("div",{style:Vu,children:s.jsx(ul,{...t})}):s.jsx(ul,{...t})});function ul({data:e}){const{label:t,dirPath:n,width:r,height:o,cells:a,members:i,districts:l,remote:d}=e,c=k.useMemo(()=>Mr(n),[n]),u=Xs(),h=we(g=>g.transform[2]),f=ye(Ue(g=>{const E=new Map(ve(g).map(T=>[T.filePath,T]));return i.map(T=>E.get(T.filePath))})),m=pe(Ue(g=>i.map(E=>!!g.pendingInteractions[E.filePath]))),y=J(g=>g.hoverDir),S=k.useMemo(()=>new Map(f.filter(g=>!!g).map(g=>[g.filePath,g])),[f]),x=u?`hsla(${c}, 35%, 72%, 0.95)`:`hsla(${c}, 35%, 36%, 0.95)`,b=k.useMemo(()=>{const g=a.filter(I=>I.filePath),E=g.length>0?g:a,T=E.reduce((I,C)=>I+C.x,0)/Math.max(1,E.length),j=Math.max(...E.map(I=>I.y))+$e*.72,_=Math.max(...E.map(I=>I.x))-Math.min(...E.map(I=>I.x))+Fe*2;return{x:T,y:j,span:_}},[a]),$=k.useMemo(()=>{const g=a.filter(T=>T.filePath),E=g.reduce((T,j)=>T+j.y,0)/Math.max(1,g.length);return l.map(T=>{const j=a.filter(F=>F.district===T&&F.filePath);if(j.length===0)return null;const _=j.reduce((F,W)=>F+W.x,0)/j.length,I=j.reduce((F,W)=>F+W.y,0)/j.length,C=Math.max(...j.map(F=>F.y)),O=Math.min(...j.map(F=>F.y)),A=Math.max(...j.map(F=>F.x))-Math.min(...j.map(F=>F.x))+Fe*1.6,L=I<E-$e*.4?"top":"bottom",R=L==="top"?O-$e*.72:C+$e*.92;return{district:T,x:_,y:R,side:L,span:A}}).filter(T=>T!==null)},[l,a]),v=Cs((h-.13)/.15,0,1),p=v*Cs(1.45-.55*h,.6,1),M=(()=>{const g=Math.max(30,Math.min(120,b.span*.1)),E=Math.min(2.4,Math.max(.5,.55/h)),T=b.span*1.15/(.6*Math.max(4,t.length));return Math.max(24,Math.min(280,Math.min(g*E,T)))})();let N=0;if(v>0){const g=Math.max(M*.6*t.length/2,340);for(const E of $){if(E.side!=="bottom")continue;const T=cl(h,E.span,E.district.length),j=Math.max(E.span*.65,T*.6*E.district.length/2);if(Math.abs(E.x-b.x)>j+g)continue;const _=E.y+T*.15;N=Math.max(N,_+Math.max(24,T*.35)-b.y)}}const w=b.y+Math.max(0,N)*Math.min(1,v*2);return s.jsxs("div",{className:"pointer-events-none relative",style:{width:r,height:o},children:[s.jsxs("svg",{width:r,height:o,className:"absolute inset-0 overflow-visible",children:[p===0?null:$.map(g=>{const E=cl(h,g.span,g.district.length),T=y===Sr(n,g.district);return s.jsx("g",{style:{userSelect:"none"},opacity:p,children:s.jsx("text",{x:g.x,y:g.y,textAnchor:"middle",fontSize:E,fontWeight:700,fill:T?u?`hsla(${c}, 45%, 82%, 1)`:`hsla(${c}, 45%, 28%, 1)`:x,children:g.district})},`district-${g.district}`)}),s.jsx(ny,{cells:a,members:i,own:S,memberPending:m,hue:c,dark:u})]}),s.jsx(ry,{label:t,remote:d===!0,hue:c,own:S,pendingCount:m.filter(Boolean).length,anchor:{...b,y:w},nameSize:M,dark:u,zoom:h,dir:n})]})}const ny=k.memo(function({cells:t,members:n,own:r,memberPending:o,hue:a,dark:i}){const l=we(Kb),d=we(Zb),c=Vl(g=>g.filePath),u=J(g=>g.stewards),h=J(g=>g.controlGroups),f=J(g=>g.starting),m=J(g=>l?null:g.burn),y=pe(Ue(g=>l?Qb:n.map(E=>g.nodeActivities[E.filePath]))),S=k.useMemo(()=>new Map(n.map((g,E)=>[g.filePath,E])),[n]),x=k.useMemo(()=>new Map(n.map(g=>[g.filePath,g.seed])),[n]),b=k.useMemo(()=>new Map(n.map(g=>[g.filePath,g.icon])),[n]),$=k.useMemo(()=>{const g=new Set;for(const E of r.values())E.did&&u[jr(E.filePath)]===E.did&&g.add(E.filePath);return g},[r,u]),v=k.useMemo(()=>{const g=new Map;for(const E of Object.keys(h).sort())for(const T of h[E]??[])g.has(T)||g.set(T,E);return g},[h]),p=i?`hsla(${a}, 35%, 72%, 0.95)`:`hsla(${a}, 35%, 36%, 0.95)`,M=i?"rgba(235,235,235,0.95)":"rgba(45,45,45,0.95)",N=i?"rgba(190,190,190,0.75)":"rgba(90,90,90,0.75)",w=i?"rgba(160,160,160,0.6)":"rgba(120,120,120,0.65)";return d?null:s.jsx(s.Fragment,{children:t.map(g=>{if(!g.filePath)return null;const E=r.get(g.filePath),T=x.get(g.filePath),j=b.get(g.filePath),_=E?.online===!1,I=o[S.get(g.filePath)??-1]??!1,C=_?null:E?.state==="active"?"#facc15":E?.state==="error"?"#f87171":E?.state==="idle"?"#4ade80":"#a3a3a3";if(l)return s.jsxs("g",{opacity:_?.45:1,style:{userSelect:"none",filter:_?"grayscale(0.9)":void 0},children:[s.jsx(Vo,{seed:T,icon:j,cx:g.x,cy:g.y-56,size:96}),C&&s.jsx("circle",{cx:g.x,cy:g.y+30,r:8,fill:C}),$.has(g.filePath)&&s.jsx("circle",{cx:g.x-fe*.52,cy:g.y-fe*.62,r:10,fill:p}),g.filePath===c&&s.jsx("circle",{cx:g.x+fe*.52,cy:g.y+fe*.62,r:10,fill:i?"#60a5fa":"#3b82f6"}),I&&s.jsx("circle",{cx:g.x,cy:g.y-fe*.62,r:18,fill:"#f59e0b",stroke:i?"#1c1917":"#ffffff",strokeWidth:3,style:{animation:"hexPulse 1.6s ease-in-out infinite"}})]},`unit-${g.q},${g.r}`);const O=E?.handle??n.find(K=>K.filePath===g.filePath)?.handle??"",A=E?.online===!1&&!!f[g.filePath],L=240/(.62*Math.max(6,O.length)),R=Cs(L,14,26),F=L<14?Wu(O,26):O,W=y[S.get(g.filePath)??-1];let G;if(W)for(let K=W.length-1;K>=0;K--){const U=W[K].type;if(U==="tool_start"||U==="message_sent"||U==="message_recv"){G=W[K];break}}const Y=!_&&E?.state==="active"&&!!G,ee=_?[A?"starting up…":"not started"]:Y?[ey(G)]:Jb(String(E?.status||E?.state||""),30),B=m?.perAgent[g.filePath],Z=B&&B.totalTokens>0?`Σ ${vn(B.totalTokens)}${B.tokensPerMin>0?` · ${vn(B.tokensPerMin)}/m`:""}`:"",Q=!_&&E?.contextTokens&&E?.contextThreshold?Math.min(1,E.contextTokens/E.contextThreshold):null;return s.jsxs("g",{opacity:_?.45:1,style:{userSelect:"none",filter:_?"grayscale(0.9)":void 0},children:[s.jsx(Vo,{seed:T,icon:j,cx:g.x,cy:g.y-56,size:96}),s.jsx("text",{x:g.x,y:g.y+36,textAnchor:"middle",fontSize:R,fontWeight:600,fill:M,children:F}),C&&s.jsx("circle",{cx:g.x-.62*R*F.length/2-12,cy:g.y+36-R*.32,r:5,fill:C,style:E?.state==="active"?{animation:"hexPulse 1.6s ease-in-out infinite"}:void 0}),ee[0]&&s.jsx("text",{x:g.x,y:g.y+62,textAnchor:"middle",fontSize:16,fontStyle:Y?void 0:"italic",fontFamily:Y?"ui-monospace, monospace":void 0,fill:N,children:ee[0]}),ee[1]&&s.jsx("text",{x:g.x,y:g.y+82,textAnchor:"middle",fontSize:16,fontStyle:"italic",fill:N,children:ee[1]}),Z&&s.jsx("text",{x:g.x,y:g.y+104,textAnchor:"middle",fontSize:13,fill:w,children:Z}),Q!==null&&s.jsxs("g",{children:[s.jsx("rect",{x:g.x-55,y:g.y+112,width:110,height:5,rx:2.5,fill:i?"rgba(255,255,255,0.12)":"rgba(0,0,0,0.10)"}),s.jsx("rect",{x:g.x-55,y:g.y+112,width:Math.max(4,110*Q),height:5,rx:2.5,fill:`hsla(${Q>.85?0:Q>.6?40:145}, 70%, ${i?55:45}%, 0.9)`})]}),$.has(g.filePath)&&s.jsxs("g",{transform:`translate(${g.x-fe*.52}, ${g.y-fe*.62})`,children:[s.jsx("circle",{r:16,fill:i?"rgba(64,64,64,0.9)":"rgba(250,250,250,0.9)",stroke:p,strokeWidth:1.5}),s.jsx("text",{y:6,textAnchor:"middle",fontSize:17,fill:p,children:"♛"})]}),g.filePath===c&&s.jsxs("g",{transform:`translate(${g.x+fe*.52}, ${g.y+fe*.62})`,children:[s.jsx("title",{children:"Open in the side panel"}),s.jsx("circle",{r:14,fill:i?"rgba(30,58,138,0.85)":"rgba(219,234,254,0.95)",stroke:i?"#60a5fa":"#3b82f6",strokeWidth:1.5}),s.jsx("rect",{x:-6.5,y:-5,width:13,height:10,rx:1.5,fill:"none",stroke:i?"#bfdbfe":"#1d4ed8",strokeWidth:1.6}),s.jsx("line",{x1:2,y1:-5,x2:2,y2:5,stroke:i?"#bfdbfe":"#1d4ed8",strokeWidth:1.6})]}),v.has(g.filePath)&&s.jsxs("g",{transform:`translate(${g.x-fe*.52}, ${g.y+fe*.62})`,children:[s.jsx("circle",{r:14,fill:i?"rgba(76,29,149,0.85)":"rgba(237,233,254,0.95)",stroke:i?"#a78bfa":"#8b5cf6",strokeWidth:1.5}),s.jsx("text",{y:5.5,textAnchor:"middle",fontSize:15,fontWeight:700,fill:i?"#ddd6fe":"#6d28d9",children:v.get(g.filePath)})]}),I&&s.jsxs("g",{transform:`translate(${g.x}, ${g.y-fe*.62})`,style:{animation:"hexPulse 1.6s ease-in-out infinite"},children:[s.jsx("circle",{r:18,fill:"#f59e0b",stroke:i?"#1c1917":"#ffffff",strokeWidth:3}),s.jsx("text",{y:7,textAnchor:"middle",fontSize:24,fontWeight:800,fill:"#ffffff",children:"!"})]})]},`unit-${g.q},${g.r}`)})})});function ry({label:e,remote:t,hue:n,own:r,pendingCount:o,anchor:a,nameSize:i,dark:l,zoom:d,dir:c}){const u=k.useMemo(()=>{const x={};for(const b of r.values()){const $=b.online?b.state:"offline";x[$]=(x[$]??0)+1}return x},[r]),h=Math.max(14,i*.34),f=Math.max(10,i*.22),m=Math.min(1,Math.max(.1,1-(d-.32)*2.2)),S=J(x=>x.hoverDir===c)?l?`hsla(${n}, 48%, 84%, 1)`:`hsla(${n}, 42%, 26%, 1)`:l?`hsla(${n}, 40%, 76%, 0.95)`:`hsla(${n}, 34%, 34%, 0.9)`;return s.jsxs("div",{className:"absolute flex flex-col items-center select-none w-max",style:{left:a.x,top:a.y,transform:"translateX(-50%)",maxWidth:Math.max(a.span*1.5,640),opacity:m},children:[s.jsxs("span",{className:"flex items-center font-semibold tracking-wide whitespace-nowrap leading-none",style:{color:S,fontSize:i,gap:i*.25},children:[t&&s.jsx("span",{role:"img","aria-label":dd,className:"flex",children:s.jsx(fd,{size:Math.round(i*.8)})}),e]}),s.jsxs("div",{className:"flex items-center mt-2",style:{gap:f*.8,fontSize:h},children:[["active","idle","error"].map(x=>u[x]?s.jsxs("span",{className:"flex items-center font-semibold",style:{gap:f*.35,color:S},children:[s.jsx("span",{className:`rounded-full ${_b[x]}`,style:{width:f,height:f}}),u[x]]},x):null),u.offline?s.jsxs("span",{className:"flex items-center font-semibold opacity-60",style:{gap:f*.35,color:S},children:[s.jsx("span",{className:"rounded-full border-2 border-dashed",style:{width:f,height:f,borderColor:S}}),u.offline]}):null,o>0&&s.jsxs("span",{className:"flex items-center font-semibold text-amber-500",style:{gap:f*.35},children:[s.jsx("span",{className:"rounded-full bg-amber-400 animate-pulse",style:{width:f,height:f}}),o]})]})]})}const Mt=830,$t=660;function _s(e,t,n){for(let r=0;r<n;r++){const o=-t,a=e+t;e=o,t=a}return{q:e,r:t}}const Yu={email:"✉️",imessage:"💬",slack:"💼",web:"🌐",peer:"🛰️"},sy="M9.78 18.65l.28-4.23 7.68-6.92c.34-.31-.07-.46-.52-.19L7.74 13.3 3.64 12c-.88-.25-.89-.86.2-1.3l15.97-6.16c.73-.33 1.43.18 1.15 1.3l-2.72 12.81c-.19.91-.74 1.13-1.5.71L12.6 16.3l-1.99 1.93c-.23.23-.42.42-.83.42z",oy="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189z";function ay({kind:e,cx:t,cy:n}){const o=e==="telegram"?{bg:"#2AABEE",path:sy}:e==="discord"?{bg:"#5865F2",path:oy}:null;if(!o)return null;const a=128*.72/24;return s.jsxs("g",{children:[s.jsx("circle",{cx:t,cy:n,r:64,fill:o.bg}),s.jsx("path",{d:o.path,fill:"#ffffff",transform:`translate(${t-12*a} ${n-12*a}) scale(${a})`})]})}const iy={running:"#4ade80",connected:"#4ade80",error:"#f87171",stopped:"#a3a3a3"},ly=24,cy=[],uy=[],dy=258;function Gu(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)>>>0;return 205+t%46}const dl={width:6,height:6,background:"transparent",border:"none"},fy=k.memo(function(t){return t.data.culled?s.jsxs("div",{className:"relative pointer-events-none",style:{width:Mt,height:$t},children:[s.jsx(ct,{type:"target",position:ue.Top,style:dl}),s.jsx(ct,{type:"source",position:ue.Bottom,style:dl})]}):s.jsx(hy,{...t})});function hy({id:e,data:t}){const{kind:n,label:r,status:o,facing:a=0,peerAgents:i,detail:l,peer:d}=t,c=document.documentElement.classList.contains("dark"),u=J(V=>V.setPeerAgentHover),h=J(V=>V.setPeerReadout),f=J(V=>V.selectedStation===e),m=n==="peer"&&e.startsWith("station:peer:")?e.slice(13):null,y=k.useRef(null),S=pe(V=>V.stationHeat[e]??0),x=Mt/2,b=$t/2,$=n==="peer"?[[-1,1],[1,0],[0,1]]:[[-1,1],[1,0]],v=(V,oe)=>{const de=_s(V,oe,a);return{x:de.q*Fe,y:(de.r+de.q/2)*$e}},p=$.map(([V,oe])=>v(V,oe)),M=[[0,1],[1,-1],[-1,0],[0,-1],[2,-1],[-2,2]],N=new Set($.map(([V,oe])=>`${V},${oe}`)),w=M.filter(([V,oe])=>!N.has(`${V},${oe}`)),g=k.useMemo(()=>{if(n!=="peer"||!i||i.length===0)return{pads:[],overflow:null};const V=i.slice(0,ly),oe=i.length-V.length,de=$n(V.length+(oe>0?1:0)+1).slice(1),be=V.map((_e,Te)=>{const ze=v(de[Te][0],de[Te][1]);return{x:x+ze.x,y:b+ze.y,agent:_e}});let ke=null;if(oe>0){const _e=v(de[V.length][0],de[V.length][1]);ke={x:x+_e.x,y:b+_e.y,count:oe}}return{pads:be,overflow:ke}},[n,i,a]),E=g.pads,T=E.length+(g.overflow?1:0),j=k.useMemo(()=>{let V=0;for(;3*V*(V+1)<T;)V++;return V},[T]),_=pe(Ue(V=>m&&E.length>0?E.map(oe=>Math.max(oe.agent.did?V.peerAgentPings[`${m}|${oe.agent.did}`]??0:0,V.peerAgentPings[`${m}|${oe.agent.handle}`]??0)):cy)),I=pe(Ue(V=>m&&E.length>0?E.map(oe=>(oe.agent.did?V.peerStreetHeat[`${m}|${oe.agent.did}`]:void 0)??V.peerStreetHeat[`${m}|${oe.agent.handle}`]??null):uy)),C=k.useMemo(()=>{const V=[],oe=(de,be)=>{const ke=_s(de,be,a);V.push({q:ke.q,r:ke.r,x:x+ke.q*Fe,y:b+(ke.r+ke.q/2)*$e})};if(oe(0,0),n==="peer"&&E.length>0)for(const[de,be]of $n(T+1).slice(1))oe(de,be);else{for(const[de,be]of $)oe(de,be);for(const[de,be]of w.slice(0,S))oe(de,be)}return V},[n,E.length,T,a,S]),O=k.useMemo(()=>aa(C,fe-2),[C]),A=E.length>0?[]:w.slice(0,S).map(([V,oe])=>v(V,oe)),L=[{x,y:b},...p.filter(V=>!E.some(oe=>oe.x===x+V.x&&oe.y===b+V.y)).map(V=>({x:x+V.x,y:b+V.y})),...A.map(V=>({x:x+V.x,y:b+V.y}))],R=p.reduce((V,oe)=>V+oe.x,0)/p.length,F=p.reduce((V,oe)=>V+oe.y,0)/p.length,W=Math.hypot(R,F)||1,G=R/W,Y=F/W,ee=E.length>0?(j+.85)*$e:W,B=G*ee,Z=Y*ee,Q=c?"rgba(148,163,184,0.55)":"rgba(100,116,139,0.5)",K=c?"rgba(30,41,59,0.55)":"rgba(241,245,249,0.75)",U={width:6,height:6,background:"transparent",border:"none"},re=!!l?.isSelfOwned,ae=re?dy:m?Gu(m):214,se={tileFill:`hsla(${ae}, ${c?45:42}%, ${c?56:48}%, ${c?.16:.11})`,tileStroke:`hsla(${ae}, ${c?62:55}%, ${c?66:50}%, ${c?.34:.3})`,border:`hsla(${ae}, 58%, ${c?66:46}%, ${c?.6:.55})`,label:`hsla(${ae}, ${c?38:46}%, ${c?74:44}%, 0.95)`},le=l?.agentCount!=null,ie=re?null:l?.ownerAlias?{text:l.ownerVerified?`owned by ${l.ownerAlias}`:`${l.ownerAlias} · unverified`,self:!1}:null;return s.jsxs("div",{className:"relative pointer-events-none",style:{width:Mt,height:$t},title:d?"Peer":`${r} — ${o}`,children:[s.jsx(ct,{type:"target",position:ue.Top,style:U}),s.jsx(ct,{type:"source",position:ue.Bottom,style:U}),s.jsx("svg",{width:Mt,height:$t,className:"absolute inset-0 overflow-visible",children:s.jsxs("g",{className:"station-drag-handle",style:{pointerEvents:"auto",cursor:"pointer"},children:[L.map((V,oe)=>s.jsxs("g",{children:[s.jsx("polygon",{points:lt(V.x,V.y,fe-2),fill:K,stroke:Q,strokeWidth:2.5,strokeOpacity:.45}),s.jsx("polygon",{points:lt(V.x,V.y,fe-16),fill:"none",stroke:Q,strokeWidth:1,strokeDasharray:"6 5"})]},oe)),E.map(V=>s.jsxs("g",{onMouseEnter:oe=>{const de=oe.clientX,be=oe.clientY;y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{y.current=null,u({agent:V.agent,peerHost:l?.host??r,peerSource:l?.source,x:de,y:be})},550)},onMouseLeave:()=>{y.current&&(clearTimeout(y.current),y.current=null),u(null)},onClick:oe=>{oe.stopPropagation(),u(null),h({agent:V.agent,peerHost:l?.host??r,peerUrl:l?.url,peerSource:l?.source})},children:[s.jsx("polygon",{points:lt(V.x,V.y,fe-2),fill:se.tileFill,stroke:se.tileStroke,strokeWidth:2}),V.agent.did?s.jsx(Vo,{seed:V.agent.did,icon:V.agent.icon,cx:V.x,cy:V.y-16,size:72}):s.jsx("text",{x:V.x,y:V.y+6,textAnchor:"middle",fontSize:64,style:{userSelect:"none"},children:V.agent.icon||"🤖"}),(()=>{const oe=230/(.62*Math.max(6,V.agent.handle.length)),de=Math.min(26,Math.max(14,oe)),be=oe<14?V.agent.handle.slice(0,25)+"…":V.agent.handle,ke=V.agent.status||V.agent.description;return s.jsxs(s.Fragment,{children:[s.jsx("text",{x:V.x,y:V.y+62,textAnchor:"middle",fontSize:de,fontWeight:600,fill:c?"rgba(203,213,225,0.9)":"rgba(71,85,105,0.9)",style:{userSelect:"none"},children:be}),ke&&s.jsx("text",{x:V.x,y:V.y+88,textAnchor:"middle",fontSize:15,fontStyle:"italic",fill:c?"rgba(148,163,184,0.75)":"rgba(100,116,139,0.75)",style:{userSelect:"none"},children:ke.length>26?ke.slice(0,25)+"…":ke})]})})(),V.agent.card_verified&&s.jsx("circle",{cx:V.x+fe*.52,cy:V.y-fe*.52,r:8,fill:"#4ade80",children:s.jsx("title",{children:"card signature verified"})}),(V.agent.api_routes?.length??0)>0&&l?.url&&s.jsxs("g",{onClick:oe=>{oe.stopPropagation(),window.open(`${l.url.replace(/\/+$/,"")}/${encodeURIComponent(V.agent.handle)}/`,"_blank")},style:{cursor:"pointer"},children:[s.jsx("circle",{cx:V.x-fe*.52,cy:V.y-fe*.52,r:20,fill:c?"rgba(38,38,38,0.9)":"rgba(255,255,255,0.9)",stroke:c?"#0369a1":"#7dd3fc",strokeWidth:2}),s.jsx("text",{x:V.x-fe*.52,y:V.y-fe*.52+9,textAnchor:"middle",fontSize:24,style:{userSelect:"none"},children:"🌐"}),s.jsx("title",{children:`Serving a site — open ${V.agent.handle}/`})]})]},`agent-${V.agent.did??V.agent.handle}`)),g.overflow&&s.jsxs("g",{children:[s.jsx("polygon",{points:lt(g.overflow.x,g.overflow.y,fe-2),fill:se.tileFill,stroke:se.tileStroke,strokeWidth:2,strokeDasharray:"10 7"}),s.jsx("text",{x:g.overflow.x,y:g.overflow.y+14,textAnchor:"middle",fontSize:52,fontWeight:700,fill:se.label,style:{userSelect:"none"},children:`+${g.overflow.count}`}),s.jsx("text",{x:g.overflow.x,y:g.overflow.y+56,textAnchor:"middle",fontSize:18,fontStyle:"italic",fill:c?"rgba(148,163,184,0.75)":"rgba(100,116,139,0.75)",style:{userSelect:"none"},children:"more agents"}),s.jsx("title",{children:`${g.overflow.count} more agents — click the station for the full directory`})]}),m&&E.map((V,oe)=>{const de=I[oe];if(!de)return null;const be=Math.min(1,Math.max(0,1-(Date.now()-de.lastAt)/(14400*1e3))),ke=Math.min(1,Math.log2(1+de.count)/5)*(.3+.7*be);if(ke<=0)return null;const _e=V.x-x,Te=V.y-b,ze=Math.hypot(_e,Te);if(ze<1)return null;const Xe=_e/ze,He=Te/ze,Ke=fe*.6,It=x+Xe*Ke,Be=b+He*Ke,Ye=V.x-Xe*Ke,ut=V.y-He*Ke,Tt=16+10*ke,rt=8+5*ke,En=`hsla(258, ${20+55*ke}%, ${c?62:48}%, ${.35+.6*ke})`;return s.jsxs("g",{style:{pointerEvents:"none"},children:[s.jsx("line",{x1:It,y1:Be,x2:Ye,y2:ut,stroke:En,strokeWidth:3+6*ke,strokeLinecap:"round"}),s.jsx("polygon",{fill:En,points:`${Ye},${ut} ${Ye-Xe*Tt+-He*rt},${ut-He*Tt+Xe*rt} ${Ye-Xe*Tt- -He*rt},${ut-He*Tt-Xe*rt}`})]},`street-${V.agent.did??V.agent.handle}`)}),m&&E.map((V,oe)=>{const de=_[oe]??0;if(!de)return null;const be=c?"rgba(94, 234, 212, 0.95)":"rgba(13, 148, 136, 0.9)";return s.jsxs("g",{style:{pointerEvents:"none"},children:[s.jsx("line",{x1:x,y1:b,x2:V.x,y2:V.y,stroke:be,strokeWidth:6,strokeLinecap:"round",strokeDasharray:"14 10",style:{opacity:0,animation:"stationHopFlow 1.6s ease-out"}}),s.jsx("polygon",{points:lt(V.x,V.y,fe-2),fill:"none",stroke:be,strokeWidth:5,style:{opacity:0,animation:"stationHopRing 1.6s ease-out",transformBox:"fill-box",transformOrigin:"center"}})]},`hop-${V.agent.did??V.agent.handle}-${de}`)}),s.jsx("path",{d:O,fill:"none",stroke:n==="peer"&&E.length>0?se.border:c?"rgba(148, 163, 184, 0.75)":"rgba(100, 116, 139, 0.7)",strokeWidth:3,strokeLinecap:"round",strokeDasharray:n==="peer"?"18 12":void 0,style:d?{stroke:"var(--ink-faint)"}:void 0}),f&&s.jsx("path",{d:O,fill:"none",stroke:"#8b5cf6",strokeWidth:7,strokeLinecap:"round",opacity:.85,style:{pointerEvents:"none"}}),n==="telegram"||n==="discord"?s.jsx(ay,{kind:n,cx:x,cy:b}):s.jsx("text",{x,y:b+32,textAnchor:"middle",fontSize:110,style:{userSelect:"none"},children:Yu[n]??"📡"}),E.length>0?s.jsxs("g",{children:[s.jsx("text",{x,y:b+(j+1)*$e+64,textAnchor:"middle",fontSize:78,fontWeight:800,fill:se.label,style:{userSelect:"none",letterSpacing:"0.04em"},children:r}),s.jsxs("text",{x,y:b+(j+1)*$e+108,textAnchor:"middle",fontSize:26,style:{userSelect:"none"},children:[s.jsx("tspan",{fill:le?"#4ade80":"#fbbf24",children:"●"}),s.jsxs("tspan",{fill:c?"rgba(148,163,184,0.75)":"rgba(100,116,139,0.75)",fontStyle:"italic",children:[" ",o]})]}),ie&&s.jsx("text",{x,y:b+(j+1)*$e+148,textAnchor:"middle",fontSize:26,fontWeight:600,fill:ie.self?se.label:c?"rgba(148,163,184,0.85)":"rgba(71,85,105,0.85)",style:{userSelect:"none"},children:ie.text})]}):s.jsxs("g",{children:[s.jsx("text",{x:x+B,y:b+Z+12,textAnchor:"middle",fontSize:40,fontWeight:700,fill:c?"rgba(203,213,225,0.9)":"rgba(71,85,105,0.9)",style:{userSelect:"none"},children:r}),s.jsx("text",{x:x+B+G*40,y:b+Z+Y*40+12,textAnchor:"middle",fontSize:20,fontStyle:"italic",fill:c?"rgba(148,163,184,0.7)":"rgba(100,116,139,0.7)",style:{userSelect:"none"},children:o}),s.jsx("circle",{cx:x+B+G*72,cy:b+Z+Y*72,r:9,fill:iy[o]??"#a3a3a3"})]})]})})]})}function We({fill:e,stroke:t,dashed:n}){return s.jsx("svg",{width:"16",height:"14",viewBox:"0 0 20 18",className:"shrink-0",children:s.jsx("polygon",{points:"5,1 15,1 19,9 15,17 5,17 1,9",fill:e,stroke:t,strokeWidth:"1.5",strokeDasharray:n?"3 2":void 0})})}function Qe({swatch:e,label:t,hint:n}){return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e,s.jsx("span",{className:"truncate text-[10px] text-neutral-600 dark:text-neutral-300",children:t}),n&&s.jsx("span",{className:"ml-auto shrink-0 text-[9px] text-[var(--adf-ui-text-subtle)] tabular-nums",children:n})]})}const py=k.memo(function({foreignHubs:t=[]}){const n=J(f=>f.lens),r=J(f=>f.cycleLens),o=J(f=>f.burn),a=ye(f=>ve(f)),i=Xs(),[l,d]=k.useState(!1),c=k.useMemo(()=>{if(n!=="model")return[];const f=new Map;for(const m of a)m.model&&f.set(m.model,(f.get(m.model)??0)+1);return[...f.entries()].sort((m,y)=>y[1]-m[1]||m[0].localeCompare(y[0]))},[n,a]),u=k.useMemo(()=>{if(n!=="burn"||!o?.perAgent)return 0;let f=0;for(const m of Object.values(o.perAgent))f=Math.max(f,m.tokensPerMin);return f},[n,o]),h=(()=>{switch(n){case"terrain":return s.jsxs(s.Fragment,{children:[s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(45, 85%, ${i?40:74}%, 0.7)`,stroke:`hsla(45, 90%, ${i?58:48}%, 0.9)`}),label:"active — working now"}),s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(140, 40%, ${i?28:84}%, 0.7)`,stroke:`hsla(140, 45%, ${i?48:55}%, 0.6)`}),label:"idle — ready"}),s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(0, 60%, ${i?32:82}%, 0.7)`,stroke:`hsla(0, 70%, ${i?52:55}%, 0.8)`}),label:"error"}),s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(0, 0%, ${i?32:85}%, 0.6)`,stroke:`hsla(0, 0%, ${i?55:50}%, 0.6)`,dashed:!0}),label:"offline — not started"}),s.jsx(Qe,{swatch:s.jsx(We,{fill:"none",stroke:"#f59e0b"}),label:"needs your attention"})]});case"burn":{const f=[0,.33,.66,1];return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex items-center gap-0.5",children:f.map(m=>s.jsx(We,{fill:`hsla(${210-190*m}, ${45+35*m}%, ${i?26+16*m:82-22*m}%, ${.5+.4*m})`,stroke:`hsla(${210-190*m}, 70%, ${i?55:45}%, ${.35+.5*m})`},m))}),s.jsxs("div",{className:"flex justify-between text-[9px] text-[var(--adf-ui-text-subtle)]",children:[s.jsx("span",{children:"cold"}),s.jsx("span",{children:u>0?`${Je(u)}/m`:"hottest"})]}),s.jsx("span",{className:"text-[9px] text-[var(--adf-ui-text-subtle)]",children:"log scale · hottest tile pulses"})]})}case"model":return c.length===0?s.jsx("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)]",children:"no models reported"}):s.jsxs(s.Fragment,{children:[c.slice(0,8).map(([f,m])=>s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(${ia(f)}, 48%, ${i?30:80}%, 0.8)`,stroke:`hsla(${ia(f)}, 55%, ${i?55:45}%, 0.7)`}),label:f,hint:`${m}`},f)),c.length>8&&s.jsxs("span",{className:"text-[9px] text-[var(--adf-ui-text-subtle)]",children:["+",c.length-8," more"]})]});case"lineage":{const m=y=>i?26+y*9:46+y*10;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex items-center gap-0.5",children:[0,1,2,3].map(y=>s.jsx(We,{fill:`hsla(200, 52%, ${m(y)}%, 0.8)`,stroke:`hsla(200, 58%, ${i?m(y)+16:m(y)-18}%, 0.8)`},y))}),s.jsxs("div",{className:"flex justify-between text-[9px] text-[var(--adf-ui-text-subtle)]",children:[s.jsx("span",{children:"root"}),s.jsx("span",{children:"younger generations"})]}),s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(220, 8%, ${i?18:90}%, 0.4)`,stroke:`hsla(220, 8%, ${i?34:65}%, 0.25)`}),label:"no family — solo agent"}),s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(200, 52%, ${m(1)}%, 0.5)`,stroke:`hsla(200, 58%, ${i?55:40}%, 0.7)`,dashed:!0}),label:"broken chain / shared DID / offline"}),s.jsx("span",{className:"text-[9px] text-[var(--adf-ui-text-subtle)]",children:"one hue per dynasty · darkest = founder"})]})}case"health":return s.jsxs(s.Fragment,{children:[s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(0, 72%, ${i?34:74}%, 0.85)`,stroke:"hsla(0, 80%, 55%, 0.95)"}),label:"error"}),s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(40, 90%, ${i?36:74}%, 0.8)`,stroke:"hsla(40, 95%, 50%, 0.95)"}),label:"needs you"}),s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(220, 8%, ${i?18:90}%, 0.5)`,stroke:`hsla(220, 8%, ${i?34:65}%, 0.4)`,dashed:!0}),label:"offline"}),s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(140, 30%, ${i?24:86}%, 0.6)`,stroke:`hsla(140, 35%, ${i?42:55}%, 0.5)`}),label:"fine"})]})}})();return s.jsx("div",{className:"absolute right-3 top-[4.7rem] z-10 w-[188px] pointer-events-auto select-none",children:s.jsxs("div",{className:"rounded-lg bg-white/85 dark:bg-neutral-900/85 backdrop-blur-sm border border-neutral-200 dark:border-neutral-800 shadow-sm px-3 py-2 space-y-1.5",children:[s.jsxs("div",{className:"w-full flex items-center justify-between gap-2",children:[s.jsxs("button",{onClick:r,className:"group flex items-center gap-1.5 text-left",title:"Change overlay — terrain (state), burn (token heat), model, health, lineage. Press L to cycle.",children:[s.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-neutral-500 dark:text-neutral-400 group-hover:text-neutral-700 dark:group-hover:text-neutral-200",children:n}),s.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-[var(--adf-ui-text-subtle)] group-hover:text-neutral-600 dark:group-hover:text-neutral-300",children:[s.jsx("path",{d:"M17 2l4 4-4 4"}),s.jsx("path",{d:"M3 11v-1a4 4 0 0 1 4-4h14"}),s.jsx("path",{d:"M7 22l-4-4 4-4"}),s.jsx("path",{d:"M21 13v1a4 4 0 0 1-4 4H3"})]}),s.jsx("kbd",{className:"px-1 rounded border border-neutral-300 dark:border-neutral-700 text-[9px] text-[var(--adf-ui-text-subtle)]",children:"L"})]}),s.jsx("button",{onClick:()=>d(!l),className:"p-0.5",title:l?"Expand legend":"Collapse legend",children:s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-[var(--adf-ui-text-subtle)] transition-transform ${l?"-rotate-90":""}`,children:s.jsx("path",{d:"M6 9l6 6 6-6"})})})]}),!l&&h,!l&&t.length>0&&s.jsxs("div",{className:"pt-1.5 mt-0.5 border-t border-neutral-100 dark:border-neutral-800 space-y-1",children:[s.jsx("span",{className:"text-[9px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)]",children:"other servers"}),t.slice(0,4).map(f=>{const m=Gu(f.runtimeId);return s.jsx(Qe,{swatch:s.jsx(We,{fill:`hsla(${m}, ${i?45:42}%, ${i?56:62}%, 0.5)`,stroke:`hsla(${m}, 58%, ${i?66:46}%, 0.9)`}),label:f.label},f.runtimeId)}),t.length>4&&s.jsxs("span",{className:"text-[9px] text-[var(--adf-ui-text-subtle)]",children:["+",t.length-4," more"]})]})]})})});function xy({k:e}){return s.jsx("kbd",{className:"px-1.5 py-0.5 min-w-[22px] text-center rounded border border-neutral-300 dark:border-neutral-600 bg-neutral-50 dark:bg-neutral-800 text-[11px] font-medium text-neutral-600 dark:text-neutral-300",children:e})}function gy({keys:e,label:t}){return s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"flex items-center gap-1 shrink-0 min-w-[104px]",children:e.map(n=>s.jsx(xy,{k:n},n))}),s.jsx("span",{className:"text-[12px] text-neutral-600 dark:text-neutral-300",children:t})]})}function my({title:e,children:t}){return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-[var(--adf-ui-text-subtle)]",children:e}),t]})}const by=k.memo(function({onClose:t}){return s.jsx("div",{className:"absolute inset-0 z-30 flex items-center justify-center bg-white/40 dark:bg-black/40 backdrop-blur-md",style:{animation:"meshFadeIn 150ms ease-out"},onClick:t,children:s.jsxs("div",{className:"grid grid-cols-2 gap-x-10 gap-y-5 px-8 py-6 rounded-2xl bg-white/95 dark:bg-neutral-900/95 border border-neutral-200 dark:border-neutral-700 shadow-2xl",onClick:n=>n.stopPropagation(),children:[s.jsxs("div",{className:"col-span-2 flex items-baseline justify-between",children:[s.jsx("span",{className:"text-sm font-semibold text-neutral-700 dark:text-neutral-200",children:"Keyboard commands"}),s.jsx("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)]",children:"? toggles · Esc closes"})]}),hd.map(n=>s.jsx(my,{title:n.title,children:n.rows.map(r=>{const{keys:o,label:a}=pd(r,dr);return s.jsx(gy,{keys:o,label:a},`${r.keys.join(" ")} ${r.label}`)})},n.title))]})})});function sn({label:e,hint:t,onClick:n,disabled:r,danger:o}){return s.jsxs("button",{onClick:n,disabled:r,className:`flex items-baseline gap-2 px-3 py-1 text-left whitespace-nowrap hover:bg-neutral-100 dark:hover:bg-neutral-800 disabled:opacity-40 disabled:cursor-not-allowed ${o?"text-red-500 dark:text-red-400":"text-neutral-700 dark:text-neutral-200"}`,children:[s.jsx("span",{className:"text-[11px] font-medium",children:e}),s.jsx("span",{className:"text-[9px] text-[var(--adf-ui-text-subtle)]",children:t})]})}function fl({label:e,hint:t,disabled:n,children:r}){const[o,a]=k.useState(!1);return s.jsxs("div",{className:"relative",onMouseEnter:()=>!n&&a(!0),onMouseLeave:()=>a(!1),children:[s.jsxs("button",{disabled:n,className:"w-full flex items-baseline gap-2 px-3 py-1 text-left whitespace-nowrap hover:bg-neutral-100 dark:hover:bg-neutral-800 disabled:opacity-40 disabled:cursor-not-allowed text-neutral-700 dark:text-neutral-200",children:[s.jsx("span",{className:"text-[11px] font-medium",children:e}),s.jsx("span",{className:"text-[9px] text-[var(--adf-ui-text-subtle)]",children:t}),s.jsx("span",{className:"ml-auto pl-2 text-[10px] text-[var(--adf-ui-text-subtle)]",children:"▸"})]}),o&&s.jsx("div",{className:"absolute left-full bottom-0 flex flex-col min-w-[188px] py-1 rounded-xl bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm border border-neutral-200 dark:border-neutral-700 shadow-lg",children:r})]})}const yy=k.memo(function({onDone:t,onOpenAgent:n,onFlyTo:r}){const o=J(B=>B.selection),a=J(B=>B.setSelection),i=J(B=>B.setMoveMode),[l,d]=k.useState(null),c=J(B=>B.composerOpen),u=J(B=>B.setComposerOpen),[h,f]=k.useState(""),[m,y]=k.useState(null),[S,x]=k.useState(null),[b,$]=k.useState(!1),[v,p]=k.useState(!1),[M,N]=k.useState(""),w=J(B=>B.setNamedGroups),g=J(B=>B.stewards),E=J(B=>B.setStewards),T=J(B=>B.markStarting),j=ye(Ue(B=>{const Z=new Map(ve(B).map(Q=>[Q.filePath,Q]));return o.map(Q=>Z.get(Q)).filter(Q=>!!Q)})),_=k.useMemo(()=>j.filter(B=>!B.online),[j]),I=k.useMemo(()=>j.filter(B=>B.online),[j]),C=k.useMemo(()=>I.filter(B=>B.state!=="idle"),[I]),O=k.useMemo(()=>I.filter(B=>B.state!=="hibernate"),[I]),A=k.useCallback(async B=>{const Z=B==="idle"?C:O;if(!(Z.length===0||l)){d(B);try{const Q=xd(Z.map(K=>K.filePath));await Promise.all([...Q].map(async([K,U])=>{try{await As(K).setFleetAgentState(U,B)}catch(re){Q.size>1&&ls(`${gd(K)}: ${U.length} agents not set to ${B}`,re)}}))}catch{}finally{d(null),t()}}},[C,O,l,t]),L=k.useCallback(async()=>{const B=I.map(Z=>Z.filePath);if(!(B.length===0||l)){d("restart"),$(!1);try{T(B);for(const Z of B)try{const Q=qe(Z);await Q.api.stopBackgroundAgent(Q.filePath),await Q.api.startBackgroundAgent(Q.filePath)}catch{}}catch{}finally{d(null),t()}}},[I,l,t,T]),R=o.length===1?j[0]:null,F=k.useMemo(()=>{if(!R)return[];const B=kn(R.filePath)?pr(R.filePath):null,Z=ae=>B?ae.map(se=>({...se,dir:da({runtimeId:B.runtimeId,filePath:se.dir})})):ae,Q=B?R.sourceRoot:R.trackedDirRoot,K=Q?Ve(Q):"";let U=jr(B?B.filePath:R.filePath);const re=[];for(;U;){const ae=!!Q&&(U===Q||Rr(U,Q)),se=ae?U===Q?K:`${K}/${Vs(U.slice(Q.length+1)).join("/")}`:Ve(U);if(re.push({dir:U,label:se}),!ae||U===Q)break;U=jr(U)}return Z(re)},[R]),W=k.useCallback(async(B,Z)=>{if(!R?.did)return;$(!1);const Q={...g};Z?Q[B]=R.did:delete Q[B],E(Q);try{await qo({stewards:Q},_t.getState().runtimes)}catch{}const K=Ve(kn(B)?pr(B).filePath:B),U=ib(ve(ye.getState()),B).filter(se=>se.filePath!==R.filePath).map(se=>se.handle).filter(Boolean),re=U.length>0?U.join(", "):"(no other members yet)",ae=Z?`You have been appointed steward of the "${K}" group. Your status line now speaks for the whole group on the command map, so keep it describing what the GROUP is working on — not just you.
|
|
8
|
+
|
|
9
|
+
Standing duty — set this up now:
|
|
10
|
+
1. Call agent_discover and read the live "status" line of each member of your group. Current members by handle: ${re}.
|
|
11
|
+
2. Distill those into one short summary of what the group is currently working on and write it with sys_set_meta (key "status").
|
|
12
|
+
3. Keep it fresh: schedule a recurring timer with sys_set_timer — schedule type "interval", every_ms 45000, scope "agent", payload telling your future self to re-run agent_discover and refresh the group summary. If sys_set_timer is not in your toolset, refresh the summary at the start of every turn instead.
|
|
13
|
+
|
|
14
|
+
If you are later relieved of stewardship, delete that timer and return your status line to your own work.`:`You have been relieved as steward of the "${K}" group. Delete your recurring group-summary timer (sys_list_timers, then sys_delete_timer) and return your status line (sys_set_meta, key "status") to describing your own work.`;try{if(!R.online){T([R.filePath]);const se=qe(R.filePath);await se.api.startBackgroundAgent(se.filePath)}Vd(R.filePath,R.handle||Ve(R.filePath),ae,x)}catch(se){x(`Orders not sent to ${R.handle||Ve(R.filePath)}: ${se instanceof Error?se.message:String(se)}`)}},[R,g,E,T]),G=k.useCallback(async()=>{const B=M.trim();if(!(!B||o.length===0))try{const Z=_t.getState().runtimes;if(Z.length>1){const U={...J.getState().namedGroups,[B]:o};await qo({groups:U},Z),w(U),N(""),p(!1);return}const K={...(await window.adfApi.getSettings()).fleetGroups??{},[B]:o};await window.adfApi.setSettings({fleetGroups:K}),w(K),N(""),p(!1)}catch{}},[M,o,w]),Y=k.useCallback(async B=>{const Z=B==="start"?_:I;if(Z.length===0||l)return;d(B),B==="start"&&T(Z.map(K=>K.filePath));const Q=[];try{for(const K of Z){const U=K.handle||Gd(K.filePath);try{if(B==="start"){const re=qe(K.filePath),ae=await re.api.startBackgroundAgent(re.filePath);ae?.success||Q.push({name:U,reason:ae?.error})}else await Hl(K.filePath)}catch(re){Q.push({name:U,reason:re})}}}finally{const K=B==="start"?"start":"stop";Q.length===1?ls(`${Q[0].name} did not ${K}`,Q[0].reason):Q.length>1&&ls(`${Q.length} agents did not ${K}: ${Q.map(U=>U.name).join(", ")}`),d(null),t()}},[_,I,l,t,T]),ee=k.useCallback(async()=>{const B=h.trim();if(!B||l)return;d("message"),y(null);const Z=j.filter(Q=>!Q.online).map(Q=>Q.filePath);Z.length>0&&T(Z);try{const Q=await md(o,B),K=Q.failed.length>0?` · ${Q.failed.length} failed`:"";y(`Sent to ${Q.delivered.length}${K}`),f(""),setTimeout(()=>{y(null),u(!1)},2500)}catch{y("Send failed")}finally{d(null),t()}},[o,j,h,l,t,T]);return o.length===0?null:s.jsxs("div",{className:"absolute bottom-6 left-1/2 -translate-x-1/2 z-[35] flex flex-col items-center gap-1.5",children:[S&&s.jsxs("div",{role:"alert",className:"flex items-center gap-1.5 px-2.5 py-1 rounded-2xl bg-white/95 dark:bg-neutral-900/95 border border-red-300 dark:border-red-800 shadow-lg max-w-[420px] text-[11px] text-red-600 dark:text-red-400",children:[s.jsx("span",{className:"flex-1",children:S}),s.jsx("button",{type:"button",onClick:()=>x(null),className:"text-[var(--adf-ui-text-subtle)] hover:text-neutral-700 dark:hover:text-neutral-200","aria-label":"Dismiss",children:"×"})]}),v&&s.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-2xl bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm border border-neutral-200 dark:border-neutral-700 shadow-lg w-[300px]",children:[s.jsx("input",{autoFocus:!0,type:"text",value:M,onChange:B=>N(B.target.value),onKeyDown:B=>{B.key==="Enter"&&G(),B.key==="Escape"&&(B.stopPropagation(),p(!1))},placeholder:`Name this group of ${o.length}…`,className:"flex-1 px-2 py-1 text-[12px] bg-transparent focus:outline-none text-neutral-700 dark:text-neutral-200 placeholder:text-[var(--adf-ui-text-subtle)]"}),s.jsx("button",{onClick:G,disabled:!M.trim(),className:"px-2.5 py-1 text-[11px] rounded-full bg-neutral-700 dark:bg-neutral-200 text-white dark:text-neutral-900 disabled:opacity-40",children:"Save"})]}),c&&s.jsxs("div",{className:"flex items-end gap-1.5 px-2.5 py-1.5 rounded-2xl bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm border border-neutral-200 dark:border-neutral-700 shadow-lg w-[420px]",children:[s.jsx("textarea",{autoFocus:!0,value:h,rows:Math.min(4,Math.max(1,h.split(`
|
|
15
|
+
`).length,Math.ceil(h.length/52))),onChange:B=>f(B.target.value),onKeyDown:B=>{B.key==="Enter"&&!B.shiftKey&&(B.preventDefault(),ee()),B.key==="Escape"&&(B.stopPropagation(),u(!1))},placeholder:`Message ${o.length} agent${o.length!==1?"s":""}…`,className:"flex-1 px-2 py-1 text-[12px] bg-transparent focus:outline-none resize-none text-neutral-700 dark:text-neutral-200 placeholder:text-[var(--adf-ui-text-subtle)]"}),m?s.jsx("span",{className:"text-[10px] text-green-600 dark:text-green-400 whitespace-nowrap px-1",children:m}):s.jsx("button",{onClick:ee,disabled:!h.trim()||l!==null,className:"px-2.5 py-1 text-[11px] rounded-full bg-violet-500 text-white hover:bg-violet-600 disabled:opacity-40",children:l==="message"?"Sending…":"Send"})]}),s.jsxs("div",{className:"flex flex-nowrap items-center gap-2 px-3 py-1.5 rounded-full bg-white/90 dark:bg-neutral-900/90 backdrop-blur-sm border border-neutral-200 dark:border-neutral-700 shadow-lg",children:[s.jsxs("span",{className:"text-[11px] font-medium text-neutral-600 dark:text-neutral-300 select-none whitespace-nowrap",children:[o.length," selected"]}),s.jsx("span",{className:"w-px h-4 bg-neutral-200 dark:bg-neutral-700"}),s.jsx("button",{onClick:()=>n(o[0]),disabled:o.length!==1,className:"px-2.5 py-0.5 text-[11px] rounded-full whitespace-nowrap bg-blue-500 text-white hover:bg-blue-600 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-blue-500",title:o.length===1?"Open this agent's file and loop panel":"Select a single agent",children:"Open"}),s.jsx("button",{onClick:()=>J.getState().setAgentReadout(o[0]),disabled:o.length!==1,className:"px-2.5 py-0.5 text-[11px] rounded-full whitespace-nowrap bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-neutral-100 dark:disabled:hover:bg-neutral-800",title:o.length===1?"Full agent readout (I)":"Select a single agent",children:"Details"}),s.jsx("button",{onClick:()=>r(o),className:"px-2.5 py-0.5 text-[11px] rounded-full whitespace-nowrap bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700",title:"Center the map on the selection",children:"Fly to"}),s.jsx("button",{onClick:()=>Y("start"),disabled:_.length===0||l!==null,className:"px-2.5 py-0.5 text-[11px] rounded-full whitespace-nowrap bg-green-500 text-white hover:bg-green-600 disabled:opacity-40 disabled:cursor-not-allowed",children:l==="start"?"Starting…":`Start${_.length>0?` ${_.length}`:""}`}),s.jsx("button",{onClick:()=>A("idle"),disabled:C.length===0||l!==null,className:"px-2.5 py-0.5 text-[11px] rounded-full whitespace-nowrap bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-200 hover:bg-neutral-200 dark:hover:bg-neutral-700 disabled:opacity-40 disabled:cursor-not-allowed",title:"End the current turn and remain ready for configured triggers",children:l==="idle"?"Idling…":`Idle${C.length>0?` ${C.length}`:""}`}),s.jsx("button",{onClick:()=>A("hibernate"),disabled:O.length===0||l!==null,className:"px-2.5 py-0.5 text-[11px] rounded-full whitespace-nowrap bg-purple-100 dark:bg-purple-900/40 text-purple-700 dark:text-purple-300 hover:bg-purple-200 dark:hover:bg-purple-900/60 disabled:opacity-40 disabled:cursor-not-allowed",title:"End the current turn and enter hibernation",children:l==="hibernate"?"Hibernating…":`Hibernate${O.length>0?` ${O.length}`:""}`}),s.jsx("button",{onClick:()=>Y("stop"),disabled:I.length===0||l!==null,className:"px-2.5 py-0.5 text-[11px] rounded-full whitespace-nowrap bg-red-500 text-white hover:bg-red-600 disabled:opacity-40 disabled:cursor-not-allowed",title:"Stop the executor. Only a manual start can bring it back.",children:l==="stop"?"Stopping…":`Off${I.length>0?` ${I.length}`:""}`}),s.jsx("button",{onClick:()=>u(!c),className:`px-2.5 py-0.5 text-[11px] rounded-full whitespace-nowrap ${c?"bg-violet-500 text-white":"bg-violet-100 dark:bg-violet-900/40 text-violet-600 dark:text-violet-300 hover:bg-violet-200 dark:hover:bg-violet-900/60"}`,children:"Message"}),s.jsxs("div",{className:"relative",children:[s.jsx("button",{onClick:()=>$(B=>!B),className:`px-2 py-0.5 text-[11px] rounded-full whitespace-nowrap ${b?"bg-neutral-300 dark:bg-neutral-600 text-neutral-800 dark:text-neutral-100":"bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700"}`,children:"More ▾"}),b&&s.jsxs("div",{className:"absolute bottom-full mb-1.5 left-1/2 -translate-x-1/2 flex flex-col min-w-[168px] py-1 rounded-xl bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm border border-neutral-200 dark:border-neutral-700 shadow-lg",children:[s.jsx(sn,{label:"Restart",hint:"stop, then start",disabled:I.length===0||l!==null,onClick:L}),s.jsx("div",{className:"my-1 h-px bg-neutral-100 dark:bg-neutral-800"}),F.length>0?s.jsx(fl,{label:"Steward of",hint:"its status speaks for a folder",disabled:!R?.did,children:F.map(({dir:B,label:Z})=>{const Q=!!R?.did&&g[B]===R.did;return s.jsx(sn,{label:Q?`✓ ${Z}`:Z,hint:Q?"remove — folder loses its voice":"appoint",disabled:!R?.did,onClick:()=>W(B,!Q)},B)})}):s.jsx(sn,{label:"Appoint steward",hint:"select a single agent",disabled:!0,onClick:()=>{}}),s.jsx(sn,{label:"Save as group…",hint:"persisted, recall from top bar",disabled:o.length===0,onClick:()=>{$(!1),p(!0)}}),s.jsx("div",{className:"my-1 h-px bg-neutral-100 dark:bg-neutral-800"}),s.jsxs(fl,{label:"Move",hint:"click a hex to place · Esc cancels",disabled:o.length===0,children:[s.jsx(sn,{label:"Agents…",hint:"the selected tiles",onClick:()=>{$(!1),i({kind:"agents"})}}),s.jsx(sn,{label:"Group…",hint:"the first selected agent's folder",onClick:()=>{$(!1),i({kind:"district"})}}),s.jsx(sn,{label:"Territory…",hint:"its whole tracked root",onClick:()=>{$(!1),i({kind:"territory"})}})]}),s.jsx(sn,{label:"Reset layout",hint:"forget every move — re-pack automatically",onClick:()=>{$(!1),window.confirm("Reset the layout? Every move you made is forgotten.")&&J.getState().setPlacement({regionOrigins:{},cellPins:{},districtAnchors:{},stationPins:{}})}})]})]}),s.jsx("span",{className:"w-px h-4 bg-neutral-200 dark:bg-neutral-700"}),s.jsxs("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] select-none hidden xl:flex items-center gap-1 whitespace-nowrap",title:`M message · G start · ⇧S off · Space jump to selection · A select all running · ${za}1-9 assign group · 1-9 recall · arrows pan`,children:[s.jsx("kbd",{className:"px-1 rounded border border-neutral-300 dark:border-neutral-700",children:"M"})," msg ·",s.jsx("kbd",{className:"px-1 rounded border border-neutral-300 dark:border-neutral-700",children:"G"})," start ·",s.jsxs("kbd",{className:"px-1 rounded border border-neutral-300 dark:border-neutral-700",children:[za,"1-9"]})," assign"]}),s.jsx("button",{onClick:()=>a([]),className:"px-2 py-0.5 text-[11px] rounded-full whitespace-nowrap text-neutral-500 dark:text-neutral-400 hover:bg-neutral-100 dark:hover:bg-neutral-800",children:"Clear"})]})]})}),To=300,wy=260,vy={active:"active",idle:"idle",hibernate:"hibernating",suspended:"suspended",error:"error",off:"off"},ky={active:"bg-yellow-400",idle:"bg-green-400",hibernate:"bg-purple-400",suspended:"bg-red-300",error:"bg-red-400",off:"bg-neutral-400"},Ny={fs:"text-blue-500 dark:text-blue-400",db:"text-green-500 dark:text-green-400",msg:"text-purple-500 dark:text-purple-400",sys:"text-orange-500 dark:text-orange-400",loop:"text-neutral-500 dark:text-neutral-400"};function jy(e){const t=Math.round(e/6e4);if(t<1)return"<1m";if(t<60)return`${t}m`;const n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}const Sy=[],My=k.memo(function({filePath:t,x:n,y:r,onPointerStay:o,onPointerAway:a,onInspect:i}){const l=ye(x=>ve(x).find(b=>b.filePath===t)),d=pe(x=>x.nodeActivities[t]??Sy),c=pe(x=>x.pendingInteractions[t]),u=J(x=>x.burn?.perAgent[t]),h=k.useMemo(()=>{const x=n+18+To>window.innerWidth?n-To-18:n+18,b=Math.min(r+14,window.innerHeight-wy);return{left:Math.max(8,x),top:Math.max(8,b)}},[n,r]);if(!l)return null;const f=l.online===!1,m=d.slice(-5).reverse(),y=Ps(d,x=>x.type==="turn"&&x.args?.startsWith("“")===!0),S=y?(y.detail??y.args.replace(/^“|”$/g,"")).replace(/\s+/g," "):null;return s.jsxs("div",{className:"fixed z-30 pointer-events-auto cursor-pointer rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm shadow-xl overflow-hidden",style:{...h,width:To,animation:"meshFadeIn 150ms ease-out"},onMouseEnter:o,onMouseLeave:a,onClick:x=>{x.stopPropagation(),i?.(t)},children:[s.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5",children:[s.jsx("span",{className:`shrink-0 ${f?"grayscale opacity-60":""}`,children:s.jsx(Ct,{seed:mt({did:l.did,filePath:l.filePath}),icon:l.icon,iconSeed:l.agentId||l.filePath,size:28,emojiSize:24})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"text-[13px] font-semibold text-neutral-800 dark:text-neutral-100 truncate",children:l.handle}),s.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${f?"border border-dashed border-neutral-400":ky[l.state]??"bg-neutral-400"}`})]}),s.jsx("div",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 italic truncate",children:f?"not started":l.status||vy[l.state]||l.state})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 pb-2 flex-wrap",children:[l.model&&s.jsx("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400",children:l.model}),l.contextTokens&&l.contextThreshold?(()=>{const x=Math.min(1,l.contextTokens/l.contextThreshold),b=x>.85?"bg-red-50 dark:bg-red-900/30 text-red-500 dark:text-red-400":x>.6?"bg-amber-50 dark:bg-amber-900/30 text-amber-600 dark:text-amber-400":"bg-emerald-50 dark:bg-emerald-900/30 text-emerald-600 dark:text-emerald-400";return s.jsxs("span",{className:`text-[10px] px-1.5 py-px rounded-full tabular-nums ${b}`,title:`Context window: ${Je(l.contextTokens)} of ${Je(l.contextThreshold)} before auto-compact`,children:["ctx ",Math.round(x*100),"%"]})})():null,u&&u.totalTokens>0&&s.jsxs("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-orange-50 dark:bg-orange-900/30 text-orange-500 dark:text-orange-400 tabular-nums",title:"Σ total · ↑ input / ↓ output tokens per minute",children:["Σ ",Je(u.totalTokens),u.tokensPerMin>0?` · ↑${Je(u.inPerMin??0)} ↓${Je(u.outPerMin??0)}/m`:""]}),c&&s.jsx("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-amber-100 dark:bg-amber-900/40 text-amber-600 dark:text-amber-400 font-medium",children:"needs you"}),l.nextWakeAt&&l.nextWakeAt>Date.now()&&s.jsxs("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-sky-50 dark:bg-sky-900/30 text-sky-600 dark:text-sky-400 tabular-nums",title:l.nextWakeLabel?`Next timer: ${l.nextWakeLabel}`:"Next timer",children:["⏰ ",l.nextWakeScope==="system"?"system timer":"wakes agent"," in ",jy(l.nextWakeAt-Date.now()),l.nextWakeLabel?` — ${l.nextWakeLabel.slice(0,24)}`:""]})]}),S&&s.jsxs("div",{className:"px-3.5 pb-2 text-[10px] text-violet-500 dark:text-violet-400 truncate",title:"Last reply — click for full text",children:["💬 ",S.length>90?S.slice(0,90)+"…":S]}),m.length>0&&s.jsx("div",{className:"border-t border-neutral-100 dark:border-neutral-800 px-2 py-1.5 space-y-0.5",children:m.map(x=>{const b=Ea[x.type],$=x.toolName.split("_")[0],v=b?.nameColor??Ny[$]??"text-neutral-500 dark:text-neutral-400",p=b?.mark??(x.type==="message_sent"?">":x.type==="message_recv"?"<":x.isError===!0?"✗":x.isError===!1?"✓":"~"),M=b?.markColor??(x.isError===!0?"text-red-500":x.isError===!1?"text-green-500":"text-[var(--adf-ui-text-subtle)]");return s.jsxs("div",{className:"flex items-center gap-1 text-[10px] leading-tight px-1.5",children:[s.jsx("span",{className:`font-mono shrink-0 w-3 text-center ${M}`,children:p}),s.jsx("span",{className:`font-medium shrink-0 ${v}`,children:x.toolName}),x.args&&s.jsx("span",{className:"text-neutral-500 dark:text-neutral-400 truncate",children:x.args})]},x.id)})}),s.jsx("div",{className:"px-3.5 py-1.5 text-[9px] text-[var(--adf-ui-text-subtle)] border-t border-neutral-100 dark:border-neutral-800",children:"click for details · double-click tile to open"})]})}),Ro=300,$y=240,Ey={telegram:"channel adapter",email:"channel adapter",discord:"channel adapter",imessage:"channel adapter",slack:"channel adapter",web:"web gateway — sys_fetch + WS links",peer:"peer server"},Cy={mdns:"LAN · mDNS",tailnet:"Tailnet",manual:"manual peer"},_y={running:"bg-green-400",connected:"bg-green-400",error:"bg-red-400",stopped:"bg-neutral-400"};function hl(e){const t=Math.round(e/6e4);if(t<1)return"just now";if(t<60)return`${t}m ago`;const n=Math.floor(t/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const Py=k.memo(function({station:t,x:n,y:r,onInspect:o,onPointerStay:a,onPointerAway:i}){const l=ye(f=>ve(f)),d=pe(f=>f.edgeHeat),c=k.useMemo(()=>{let f=0,m=0,y=0;const S=new Map;for(const[$,v]of Object.entries(d)){const[p,M]=$.split("|");if(p!==t.id&&M!==t.id)continue;p===t.id?f+=v.count:m+=v.count,y=Math.max(y,v.lastAt);const N=p===t.id?M:p;S.set(N,(S.get(N)??0)+v.count)}const x=$=>$.startsWith("station:")?$.slice(8):l.find(p=>p.filePath===$)?.handle??Ve($).replace(/\.adf$/,""),b=[...S.entries()].sort(($,v)=>v[1]-$[1]).slice(0,3).map(([$,v])=>({handle:x($),count:v}));return{inbound:f,outbound:m,lastAt:y,top:b}},[d,t.id,l]),u=k.useMemo(()=>{const f=n+18+Ro>window.innerWidth?n-Ro-18:n+18,m=Math.min(r+14,window.innerHeight-$y);return{left:Math.max(8,f),top:Math.max(8,m)}},[n,r]),h=t.detail;return s.jsxs("div",{"data-station-card":!0,className:`fixed z-30 rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm shadow-xl overflow-hidden ${o?"pointer-events-auto cursor-pointer hover:border-neutral-300 dark:hover:border-neutral-600":"pointer-events-none"}`,style:{...u,width:Ro,animation:"meshFadeIn 150ms ease-out"},onClick:o?()=>o(t.id):void 0,onMouseEnter:a,onMouseLeave:i,title:o?"Click for the full station readout":void 0,children:[s.jsx("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5",children:s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"text-[13px] font-semibold text-neutral-800 dark:text-neutral-100 truncate",children:t.label}),s.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${_y[t.status]??"bg-neutral-400"}`}),s.jsx("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] italic shrink-0",children:t.status})]}),s.jsxs("div",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 truncate",children:[Ey[t.kind]??"base station",t.kind==="peer"&&t.detail?.source&&` — ${Cy[t.detail.source]??t.detail.source}`]}),t.kind==="peer"&&(t.detail?.isSelfOwned||t.detail?.ownerAlias)&&s.jsx("div",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 truncate",children:t.detail.isSelfOwned?"✓ your server":t.detail.ownerVerified?`owned by ${t.detail.ownerAlias}`:`${t.detail.ownerAlias} · unverified`})]})}),h&&s.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 pb-2 flex-wrap",children:[h.host&&s.jsx("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400",children:h.host}),h.agentCount!=null&&s.jsxs("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400 tabular-nums",children:[h.agentCount," agents"]}),h.firstSeen&&s.jsxs("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400",children:["first seen ",hl(Date.now()-h.firstSeen)]})]}),s.jsxs("div",{className:"px-3.5 pb-2.5 border-t border-neutral-100 dark:border-neutral-800 pt-2",children:[s.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-neutral-600 dark:text-neutral-300 tabular-nums",children:[s.jsxs("span",{title:"Messages from the outside world into the fleet",children:["↓ ",c.inbound," in"]}),s.jsxs("span",{title:"Messages from the fleet out through this station",children:["↑ ",c.outbound," out"]}),c.lastAt>0&&s.jsx("span",{className:"text-[var(--adf-ui-text-subtle)] ml-auto",children:hl(Date.now()-c.lastAt)})]}),c.top.length>0?s.jsx("div",{className:"mt-1.5 space-y-0.5",children:c.top.map(f=>s.jsxs("div",{className:"flex items-baseline gap-2 text-[11px]",children:[s.jsx("span",{className:"text-neutral-700 dark:text-neutral-200 truncate",children:f.handle}),s.jsxs("span",{className:"text-[var(--adf-ui-text-subtle)] tabular-nums ml-auto shrink-0",children:[f.count," msg",f.count===1?"":"s"]})]},f.handle))}):s.jsx("div",{className:"mt-1.5 text-[11px] italic text-[var(--adf-ui-text-subtle)]",children:"no traffic yet"})]})]})}),Do=320,Ay=260,Iy={mdns:"LAN · mDNS",tailnet:"Tailnet",manual:"manual peer"},Ty=k.memo(function({agent:t,peerHost:n,peerSource:r,x:o,y:a}){const i=k.useMemo(()=>{const d=o+18+Do>window.innerWidth?o-Do-18:o+18,c=Math.min(a+14,window.innerHeight-Ay);return{left:Math.max(8,d),top:Math.max(8,c)}},[o,a]),l=t.did?t.did.length>34?`${t.did.slice(0,22)}…${t.did.slice(-8)}`:t.did:null;return s.jsxs("div",{className:"fixed z-30 pointer-events-none rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm shadow-xl overflow-hidden",style:{...i,width:Do,animation:"meshFadeIn 150ms ease-out"},children:[s.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2.5",children:[s.jsx(ca,{did:t.did,icon:t.icon,size:28,emojiSize:24}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"text-[13px] font-semibold text-neutral-800 dark:text-neutral-100 truncate",children:t.handle}),s.jsxs("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] shrink-0",children:["@ ",n]})]}),t.status?s.jsx("div",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 italic truncate",children:t.status}):s.jsx("div",{className:"text-[11px] text-[var(--adf-ui-text-subtle)] italic",children:"remote agent"})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5 px-3.5 pb-2 flex-wrap",children:[t.card_verified?s.jsx("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-green-50 dark:bg-green-900/30 text-green-600 dark:text-green-400",children:"✓ signed card"}):s.jsx("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-neutral-100 dark:bg-neutral-800 text-[var(--adf-ui-text-subtle-on-fill)]",children:"unverified"}),t.owner_attested&&s.jsx("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-sky-50 dark:bg-sky-900/30 text-sky-600 dark:text-sky-400",children:"owner attested"}),r&&s.jsxs("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-indigo-50 dark:bg-indigo-900/30 text-indigo-600 dark:text-indigo-400",title:"How this server is reached",children:["via ",Iy[r]??r]}),t.api_routes&&t.api_routes.length>0&&s.jsxs("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400 tabular-nums",children:[t.api_routes.length," route",t.api_routes.length===1?"":"s"]}),t.shared&&t.shared.length>0&&s.jsxs("span",{className:"text-[10px] px-1.5 py-px rounded-full bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400 tabular-nums",children:[t.shared.length," shared file",t.shared.length===1?"":"s"]})]}),t.description&&s.jsx("div",{className:"px-3.5 pb-2 border-t border-neutral-100 dark:border-neutral-800 pt-2",children:s.jsx("div",{className:"text-[11px] leading-snug text-neutral-600 dark:text-neutral-300",style:{display:"-webkit-box",WebkitLineClamp:4,WebkitBoxOrient:"vertical",overflow:"hidden"},children:t.description})}),l&&s.jsx("div",{className:"px-3.5 pb-1.5 pt-1",children:s.jsx("span",{className:"font-mono text-[9px] text-[var(--adf-ui-text-subtle)] break-all",title:t.did,children:l})}),s.jsx("div",{className:"px-3.5 pb-2 text-[9px] text-[var(--adf-ui-text-subtle)]",children:"click tile for the full card"})]})}),Ry=["Reading the lattice…","Listening for heartbeats…","Retracing old routes…","Counting what burned…","Waking the stewards…","Settling the dew…","Consulting the ledger…","Warming the wires…","Raising the territories…","Asking the garden what grew…","Following the moss…","Sounding the perimeter…"];function Dy(e){const t=[...e];for(let n=t.length-1;n>0;n--){const r=Math.floor(Math.random()*(n+1));[t[n],t[r]]=[t[r],t[n]]}return t}const Ly=k.memo(function({visible:t}){const[n,r]=k.useState(!1),[o,a]=k.useState(0),[i]=k.useState(()=>Dy(Ry));return k.useEffect(()=>{if(t)return;const l=setTimeout(()=>r(!0),750);return()=>clearTimeout(l)},[t]),k.useEffect(()=>{if(!t)return;const l=setInterval(()=>a(d=>d+1),1400);return()=>clearInterval(l)},[t]),n?null:s.jsxs("div",{className:`absolute inset-0 z-30 flex items-center justify-center bg-neutral-50 dark:bg-neutral-950 transition-opacity duration-700 ${t?"opacity-100":"opacity-0 pointer-events-none"}`,children:[s.jsx("div",{className:"absolute inset-0",style:{background:"radial-gradient(55% 45% at 22% 18%, rgba(45, 212, 191, 0.07), transparent 70%), radial-gradient(60% 50% at 82% 85%, rgba(167, 139, 250, 0.05), transparent 70%)"}}),s.jsxs("div",{className:"relative flex flex-col items-center gap-4 select-none",children:[s.jsxs("svg",{width:"120",height:"120",viewBox:"-60 -60 120 120",className:"overflow-visible",children:[s.jsx("polygon",{points:"52,0 26,45 -26,45 -52,0 -26,-45 26,-45",fill:"none",stroke:"rgba(45, 212, 191, 0.55)",strokeWidth:"2.5",strokeDasharray:"26 17",strokeLinecap:"round",style:{animation:"hexDashFlow 7s linear infinite"}}),s.jsx("polygon",{points:"34,0 17,29.4 -17,29.4 -34,0 -17,-29.4 17,-29.4",fill:"rgba(45, 212, 191, 0.06)",stroke:"rgba(45, 212, 191, 0.3)",strokeWidth:"1.5"}),s.jsx("circle",{r:"6",fill:"rgba(94, 234, 212, 0.9)",style:{animation:"hexPulse 2.2s ease-in-out infinite"}})]}),s.jsx("div",{className:"text-lg font-semibold tracking-wide text-neutral-700 dark:text-neutral-200",children:"Mesh"}),s.jsx("div",{className:"h-4 text-[12px] italic text-neutral-500 dark:text-neutral-400",style:{animation:"meshFadeIn 400ms ease-out"},children:i[o%i.length]},o),s.jsx("div",{className:"mesh-pulse-bar w-44 rounded-full"})]})]})}),Oy={active:"bg-yellow-400",idle:"bg-green-400",error:"bg-red-400",hibernate:"bg-sky-400",suspended:"bg-orange-400"};function pl(e){const t=Math.floor(e/6e4);if(t<1)return"now";if(t<60)return`${t}m ago`;const n=Math.floor(t/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const Fy=k.memo(function({dir:t,onClose:n,onFocusAgent:r}){const o=ye(x=>ve(x)),a=J(x=>x.stewards),i=J(x=>x.burn),l=pe(x=>x.pendingInteractions),d=pe(x=>x.nodeActivities);k.useEffect(()=>{const x=b=>{b.key==="Escape"&&(b.stopPropagation(),n())};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[n]);const{members:c,steward:u,voice:h,stats:f}=k.useMemo(()=>{const x=_=>l[_.filePath]?0:_.state==="error"?1:_.online?_.state==="idle"?3:2:4,b=o.filter(_=>Ou(_.filePath,t)).sort((_,I)=>x(_)-x(I)||_.handle.localeCompare(I.handle)),$=a[t],v=$?b.find(_=>_.did===$):void 0;let p=v;if(!p){let _=-1;for(const I of b){const C=d[I.filePath],O=C&&C.length>0?C[C.length-1].timestamp:0,A=I.state==="active"?O+1e15:O;A>_&&(_=A,p=I)}}let M=0,N=0,w=0,g=0,E=0,T=0,j=0;for(const _ of b){_.online&&M++,_.state==="active"&&N++,_.state==="error"&&w++,l[_.filePath]&&g++;const I=i?.perAgent[_.filePath];I&&(E+=I.totalTokens,T+=I.tokensPerMin);const C=d[_.filePath];C&&C.length>0&&(j=Math.max(j,C[C.length-1].timestamp))}return{members:b,steward:v,voice:p,stats:{online:M,active:N,error:w,pending:g,burnSum:E,burnRate:T,lastActivity:j}}},[o,t,a,i,l,d]),m=Mr(t),y=Vs(ln(t)===null&&kn(t)?pr(t).filePath:t).slice(-2).join("/"),S=(x,b,$)=>s.jsxs("div",{className:"flex flex-col items-center px-4 py-2",children:[s.jsx("span",{className:`text-lg font-semibold tabular-nums ${$??"text-neutral-800 dark:text-neutral-100"}`,children:x}),s.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)]",children:b})]});return s.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-black/40 backdrop-blur-sm",style:{animation:"meshFadeIn 150ms ease-out"},onClick:n,children:s.jsxs("div",{className:"w-[620px] max-w-[90vw] max-h-[80vh] flex flex-col rounded-2xl bg-white/95 dark:bg-neutral-900/95 border border-neutral-200 dark:border-neutral-700 shadow-2xl overflow-hidden",onClick:x=>x.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center gap-3 px-5 pt-4 pb-3",children:[s.jsx("span",{className:"w-3.5 h-3.5 shrink-0",style:{backgroundColor:`hsla(${m}, 45%, 55%, 0.9)`,clipPath:"polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%)"}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("div",{className:"text-[15px] font-semibold text-neutral-800 dark:text-neutral-100 truncate",children:y}),h&&s.jsxs("div",{className:"text-[11px] text-[var(--adf-ui-text-subtle)]",children:[u?"♛ steward":"voice"," · ",h.handle]})]}),s.jsx("button",{onClick:n,className:"w-7 h-7 flex items-center justify-center rounded-full text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-200 hover:bg-neutral-100 dark:hover:bg-neutral-800",title:"Close (Esc)",children:"✕"})]}),h?.status&&s.jsxs("div",{className:"mx-5 mb-3 px-4 py-3 rounded-xl bg-neutral-50 dark:bg-neutral-800/60 border border-neutral-100 dark:border-neutral-700/60",children:[s.jsx("div",{className:"text-[13px] leading-relaxed text-neutral-700 dark:text-neutral-200 whitespace-pre-wrap",children:h.status}),h.statusSince&&s.jsxs("div",{className:"mt-1.5 text-[10px] text-[var(--adf-ui-text-subtle)]",children:["status set ",pl(Date.now()-h.statusSince)]})]}),s.jsxs("div",{className:"mx-5 mb-3 flex flex-wrap justify-center divide-x divide-neutral-100 dark:divide-neutral-800 rounded-xl border border-neutral-100 dark:border-neutral-800",children:[S(`${f.online}/${c.length}`,"online"),S(`${f.active}`,"active",f.active>0?"text-yellow-500":void 0),S(`${f.error}`,"errors",f.error>0?"text-red-500":void 0),S(`${f.pending}`,"need you",f.pending>0?"text-amber-500":void 0),S(vn(f.burnSum),"Σ tokens"),S(`${vn(f.burnRate)}/m`,"burn"),S(f.lastActivity?pl(Date.now()-f.lastActivity):"—","last activity")]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 pb-4",children:[c.map(x=>s.jsxs("button",{onClick:()=>{n(),r(x.filePath)},className:"w-full flex items-center gap-2.5 px-2.5 py-1.5 rounded-lg text-left hover:bg-neutral-100/70 dark:hover:bg-neutral-800/70",title:x.status??x.handle,children:[s.jsx("span",{className:`text-base leading-none shrink-0 ${x.online===!1?"grayscale opacity-60":""}`,children:s.jsx(Ct,{seed:mt({did:x.did,filePath:x.filePath}),icon:x.icon,iconSeed:x.agentId||x.filePath,size:18,emojiSize:16})}),s.jsx("span",{className:"w-28 shrink-0 truncate text-[12px] font-medium text-neutral-700 dark:text-neutral-200",children:x.handle}),s.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${x.online===!1?"border border-dashed border-neutral-400":Oy[x.state]??"bg-neutral-400"}`}),s.jsx("span",{className:"flex-1 min-w-0 truncate text-[11px] text-neutral-500 dark:text-neutral-400 italic",children:x.online===!1?"not started":x.status||x.state})]},x.filePath)),c.length===0&&s.jsx("div",{className:"py-6 text-center text-[12px] text-[var(--adf-ui-text-subtle)]",children:"No agents in this group."})]})]})})}),zy={active:"active",idle:"idle",hibernate:"hibernating",suspended:"suspended",error:"error",off:"off"},Hy={active:"bg-yellow-400",idle:"bg-green-400",hibernate:"bg-purple-400",suspended:"bg-red-300",error:"bg-red-400",off:"bg-neutral-400"},By={fs:"text-blue-500 dark:text-blue-400",db:"text-green-500 dark:text-green-400",msg:"text-purple-500 dark:text-purple-400",sys:"text-orange-500 dark:text-orange-400",loop:"text-neutral-500 dark:text-neutral-400"};function Lo(e){const t=Math.floor(e/1e3);if(t<60)return"just now";const n=Math.floor(t/60);if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function Wy(e){const t=Math.round(e/6e4);if(t<1)return"<1m";if(t<60)return`${t}m`;const n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}const qy=[],Vy=k.memo(function({filePath:t,onClose:n,onOpenAgent:r,onFocusAgent:o}){const a=ye(N=>ve(N).find(w=>w.filePath===t)),i=ye(N=>ve(N)),l=pe(N=>N.nodeActivities[t]??qy),d=pe(N=>N.pendingInteractions[t]),c=J(N=>N.burn?.perAgent[t]),[u,h]=k.useState(null);k.useEffect(()=>{const N=w=>{w.key==="Escape"&&(w.stopPropagation(),n())};return window.addEventListener("keydown",N,!0),()=>window.removeEventListener("keydown",N,!0)},[n]);const{parent:f,children:m,duplicateDid:y}=k.useMemo(()=>{if(!a)return{parent:void 0,children:[],duplicateDid:!1};const N=Ca(i),w=new Map(i.map(_=>[_.filePath,_])),g=N.parents.get(a.filePath),E=g?w.get(g):void 0,T=(N.children.get(a.filePath)??[]).map(_=>w.get(_)).filter(_=>!!_),j=!!a.did&&N.duplicateDids.has(a.did);return{parent:E,children:T,duplicateDid:j}},[a,i]);if(!a)return null;const S=a.online===!1,x=l.slice(-12).reverse(),b=Ps(l,N=>N.type==="turn"&&N.args?.startsWith("“")===!0),$=b?b.detail??b.args.replace(/^“|”$/g,""):null,v=(N,w)=>{navigator.clipboard.writeText(w),h(N),setTimeout(()=>h(null),1200)},p=(N,w,g)=>s.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full ${w}`,title:g,children:N}),M=(N,w)=>s.jsxs("button",{onClick:()=>{n(),o(N.filePath)},className:"flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-violet-50 dark:bg-violet-900/30 text-violet-600 dark:text-violet-300 text-[10px] hover:bg-violet-100 dark:hover:bg-violet-900/50",title:`${w} — fly to ${N.handle}`,children:[s.jsx("span",{className:N.online===!1?"grayscale opacity-60":"",children:s.jsx(Ct,{seed:mt({did:N.did,filePath:N.filePath}),icon:N.icon,iconSeed:N.agentId||N.filePath,size:16,emojiSize:10})}),N.handle]},N.filePath);return s.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-black/40 backdrop-blur-sm",style:{animation:"meshFadeIn 150ms ease-out"},onClick:n,children:s.jsxs("div",{className:"w-[560px] max-w-[90vw] max-h-[82vh] flex flex-col rounded-2xl bg-white/95 dark:bg-neutral-900/95 border border-neutral-200 dark:border-neutral-700 shadow-2xl overflow-hidden",onClick:N=>N.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center gap-3 px-5 pt-4 pb-3",children:[s.jsx("span",{className:`text-3xl leading-none shrink-0 ${S?"grayscale opacity-60":""}`,children:s.jsx(Ct,{seed:mt({did:a.did,filePath:a.filePath}),icon:a.icon,iconSeed:a.agentId||a.filePath,size:32,emojiSize:30})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-[16px] font-semibold text-neutral-800 dark:text-neutral-100 truncate",children:a.handle}),s.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${S?"border border-dashed border-neutral-400":Hy[a.state]??"bg-neutral-400"}`}),s.jsx("span",{className:"text-[11px] text-[var(--adf-ui-text-subtle)]",children:S?"not started":zy[a.state]??a.state})]}),s.jsx("div",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] truncate",title:a.filePath,children:a.filePath})]}),s.jsx("button",{onClick:()=>r(a.filePath),className:"px-3 py-1 text-[11px] rounded-full whitespace-nowrap bg-blue-500 text-white hover:bg-blue-600 shrink-0",title:"Open this agent's file and loop panel",children:"Open"}),Ud&&s.jsx("button",{onClick:()=>Kd({filePath:a.filePath}),className:"px-3 py-1 text-[11px] rounded-full whitespace-nowrap bg-neutral-100 text-neutral-700 hover:bg-neutral-200 dark:bg-neutral-800 dark:text-neutral-200 dark:hover:bg-neutral-700 shrink-0",title:"Open in new window",children:"Open in new window"}),s.jsx("button",{onClick:n,className:"w-7 h-7 flex items-center justify-center rounded-full text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-200 hover:bg-neutral-100 dark:hover:bg-neutral-800 shrink-0",title:"Close (Esc)",children:"✕"})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 pb-4 space-y-3",children:[a.status&&s.jsxs("div",{className:"px-4 py-3 rounded-xl bg-neutral-50 dark:bg-neutral-800/60 border border-neutral-100 dark:border-neutral-700/60",children:[s.jsx("div",{className:"text-[13px] leading-relaxed text-neutral-700 dark:text-neutral-200 whitespace-pre-wrap",children:a.status}),a.statusSince&&s.jsxs("div",{className:"mt-1.5 text-[10px] text-[var(--adf-ui-text-subtle)]",children:["status set ",Lo(Date.now()-a.statusSince)]})]}),s.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[a.model&&p(a.model,"bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400"),c&&c.totalTokens>0&&p(s.jsxs(s.Fragment,{children:["Σ ",vn(c.totalTokens),c.tokensPerMin>0?` · ↑${vn(c.inPerMin??0)} ↓${vn(c.outPerMin??0)}/m`:""]}),"bg-orange-50 dark:bg-orange-900/30 text-orange-500 dark:text-orange-400 tabular-nums","Σ total · ↑ input / ↓ output tokens per minute"),d&&p("needs you","bg-amber-100 dark:bg-amber-900/40 text-amber-600 dark:text-amber-400 font-medium"),a.visibility&&a.visibility!=="off"&&p(`mesh: ${a.visibility}`,"bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400","Mesh visibility"),(a.apiRouteCount??0)>0&&p(`serves ${a.apiRouteCount} route${a.apiRouteCount===1?"":"s"}`,"bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400"),(a.sharedCount??0)>0&&p(`${a.sharedCount} shared file${a.sharedCount===1?"":"s"}`,"bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400"),(a.wsConnections??0)>0&&p(`${a.wsConnections} ws`,"bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400","Active WebSocket connections"),a.servedUrl&&s.jsxs("a",{href:a.servedUrl,target:"_blank",rel:"noreferrer",className:"text-[10px] px-2 py-0.5 rounded-full bg-sky-50 dark:bg-sky-900/30 text-sky-600 dark:text-sky-400 hover:underline",title:`Serving ${a.servedUrl} — click to open`,children:["🌐 ",a.servedUrl.replace(/^https?:\/\//,"")]})]}),$&&s.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-50/60 dark:bg-violet-900/15 border border-violet-100 dark:border-violet-900/40",children:[s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[s.jsx("span",{className:"text-[10px] uppercase tracking-wide text-violet-500/80 dark:text-violet-400/80",children:"last reply"}),s.jsx("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] tabular-nums",children:Lo(Date.now()-b.timestamp)})]}),s.jsx("div",{className:"text-[13px] leading-relaxed text-neutral-700 dark:text-neutral-200 max-h-48 overflow-y-auto",children:s.jsx(Du,{text:$})})]}),a.nextWakeAt&&a.nextWakeAt>Date.now()&&s.jsxs("div",{className:"px-3 py-2 rounded-lg bg-sky-50 dark:bg-sky-900/20 border border-sky-100 dark:border-sky-900/40 text-[11px] text-sky-700 dark:text-sky-300",children:["⏰ ",a.nextWakeScope==="system"?"system timer":"wakes agent"," in ",Wy(a.nextWakeAt-Date.now()),a.nextWakeLabel&&s.jsxs("span",{className:"text-sky-600/80 dark:text-sky-400/80",children:[" — ",a.nextWakeLabel]})]}),(f||m.length>0)&&s.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[s.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)]",children:"family"}),f&&M(f,"parent"),m.map(N=>M(N,"child"))]}),y&&s.jsx("div",{className:"px-3 py-2 rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-100 dark:border-amber-900/40 text-[11px] text-amber-700 dark:text-amber-300",title:"Another live agent file presents this same DID. Lineage resolves to whichever was seen first — regenerate one identity to make them distinct.",children:"⚠ Shares its identity with another agent"}),a.did&&s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] shrink-0",children:"did"}),s.jsx("button",{onClick:()=>v("did",a.did),className:"flex-1 min-w-0 text-left font-mono text-[10px] text-neutral-500 dark:text-neutral-400 truncate hover:text-neutral-700 dark:hover:text-neutral-200",title:"Click to copy",children:a.did}),u==="did"&&s.jsx("span",{className:"text-[10px] text-green-500 shrink-0",children:"copied"})]}),x.length>0&&s.jsxs("div",{children:[s.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] mb-1",children:"recent activity"}),s.jsx("div",{className:"rounded-xl border border-neutral-100 dark:border-neutral-800 divide-y divide-neutral-50 dark:divide-neutral-800/60",children:x.map(N=>{const w=Ea[N.type],g=N.toolName.split("_")[0],E=w?.nameColor??By[g]??"text-neutral-500 dark:text-neutral-400",T=w?.mark??(N.type==="message_sent"?">":N.type==="message_recv"?"<":N.isError===!0?"✗":N.isError===!1?"✓":"~"),j=w?.markColor??(N.isError===!0?"text-red-500":N.isError===!1?"text-green-500":"text-[var(--adf-ui-text-subtle)]");return s.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] leading-tight px-2.5 py-1.5",children:[s.jsx("span",{className:`font-mono shrink-0 w-3 text-center ${j}`,children:T}),s.jsx("span",{className:`font-medium shrink-0 ${E}`,children:N.toolName}),s.jsx("span",{className:"flex-1 min-w-0 text-neutral-500 dark:text-neutral-400 truncate",children:N.args??""}),s.jsx("span",{className:"shrink-0 text-[9px] text-[var(--adf-ui-text-subtle)] tabular-nums",children:Lo(Date.now()-N.timestamp)})]},N.id)})})]}),x.length===0&&s.jsx("div",{className:"py-3 text-center text-[11px] text-[var(--adf-ui-text-subtle)]",children:"No activity recorded this session."})]})]})})}),Xy={active:"bg-yellow-400",idle:"bg-green-400",error:"bg-red-400",hibernate:"bg-sky-400",suspended:"bg-orange-400"};function Yy(e){if(e<6e4)return"now";const t=Math.floor(e/6e4);if(t<60)return`${t}m ago`;const n=Math.floor(t/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const Gy=k.memo(function({onFocusAgent:t}){const[n,r]=k.useState(!1),o=J(c=>c.stewards),a=ye(Ue(c=>{const u=new Set(Object.values(o));return ve(c).filter(h=>h.did&&u.has(h.did))})),[,i]=k.useState(0);k.useEffect(()=>{const c=setInterval(()=>i(u=>u+1),15e3);return()=>clearInterval(c)},[]);const l=k.useMemo(()=>{const c=new Map(a.filter(h=>h.did).map(h=>[h.did,h])),u=[];for(const[h,f]of Object.entries(o)){const m=c.get(f);if(!m)continue;const y=kn(h)?pr(h):null,S=y?y.filePath:h,x=y?m.sourceRoot:m.trackedDirRoot,b=x?Ve(x):"",v=!!x&&(S===x||Rr(S,x))?S===x?b:`${b}/${Vs(S.slice(x.length+1)).join("/")}`:Ve(S);u.push({dir:h,label:v,agent:m})}return u.sort((h,f)=>h.label.localeCompare(f.label)),u},[o,a]);if(l.length===0)return null;const d=Date.now();return s.jsxs("div",{className:"rounded-lg bg-white/85 dark:bg-neutral-900/85 backdrop-blur-sm border border-neutral-200 dark:border-neutral-800 shadow-sm overflow-hidden pointer-events-auto select-none",children:[s.jsxs("button",{onClick:()=>r(!n),className:"w-full flex items-center justify-between px-3 py-1.5 text-[11px] font-medium text-neutral-600 dark:text-neutral-300 hover:bg-neutral-100/60 dark:hover:bg-neutral-800/60 transition-colors",title:"Appointed stewards — each status line speaks for its whole group",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{children:"♛"}),"Stewards"]}),s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-[var(--adf-ui-text-subtle)] transition-transform ${n?"-rotate-90":""}`,children:s.jsx("path",{d:"M6 9l6 6 6-6"})})]}),!n&&s.jsx("div",{className:"overflow-y-auto max-h-[40vh]",children:l.map(c=>{const u=c.agent.online===!1,h=c.agent.statusSince?Yy(d-c.agent.statusSince):null;return s.jsxs("button",{onClick:()=>t(c.agent.filePath),className:"w-full flex items-start gap-2 px-2.5 py-1.5 text-left hover:bg-neutral-100/60 dark:hover:bg-neutral-800/60 border-t border-neutral-100 dark:border-neutral-800/60",title:`${c.agent.handle} — steward of ${c.label}${c.agent.status?`
|
|
16
|
+
${c.agent.status}`:""}`,children:[s.jsx("span",{className:`shrink-0 text-base leading-none mt-px ${u?"grayscale opacity-60":""}`,children:s.jsx(Ct,{seed:mt({did:c.agent.did,filePath:c.agent.filePath}),icon:c.agent.icon,iconSeed:c.agent.agentId||c.agent.filePath,size:18,emojiSize:16})}),s.jsxs("span",{className:"flex-1 min-w-0",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-[11px] font-medium text-neutral-700 dark:text-neutral-200",children:c.label}),s.jsxs("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] truncate",children:["♛ ",c.agent.handle]}),s.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ml-auto ${u?"border border-dashed border-neutral-400":Xy[c.agent.state]??"bg-neutral-400"}`})]}),s.jsxs("span",{className:"flex items-baseline gap-1.5",children:[s.jsx("span",{className:"flex-1 min-w-0 text-[10px] leading-snug text-neutral-500 dark:text-neutral-400",style:{display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:c.agent.status||(u?"not started":"no status reported")}),h&&s.jsx("span",{className:"shrink-0 text-[9px] tabular-nums text-[var(--adf-ui-text-subtle)]",children:h})]})]})]},c.dir)})})]})}),Uy=8;function Ky(e){if(e<=0)return"now";const t=Math.floor(e/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60);if(n<60)return`${n}m`;const r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function Zy(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:e<864e5?`${(e/36e5).toFixed(1).replace(/\.0$/,"")}h`:`${(e/864e5).toFixed(1).replace(/\.0$/,"")}d`}function Qy(e){const t=e.nextWakeSchedule;if(!t)return"";switch(t.mode){case"once":return"once";case"interval":return`every ${Zy(t.every_ms)}`;case"cron":return t.cron}}const Jy=k.memo(function({onFocusAgent:t}){const[n,r]=k.useState(!1),o=ye(d=>ve(d)),[,a]=k.useState(0);k.useEffect(()=>{const d=setInterval(()=>a(c=>c+1),1e3);return()=>clearInterval(d)},[]);const i=Date.now(),l=k.useMemo(()=>o.filter(d=>d.nextWakeAt&&d.nextWakeAt>Date.now()).sort((d,c)=>d.nextWakeAt-c.nextWakeAt).slice(0,Uy),[o,i]);return l.length===0?null:s.jsxs("div",{className:"rounded-lg bg-white/85 dark:bg-neutral-900/85 backdrop-blur-sm border border-neutral-200 dark:border-neutral-800 shadow-sm overflow-hidden pointer-events-auto select-none",children:[s.jsxs("button",{onClick:()=>r(!n),className:"w-full flex items-center justify-between px-3 py-1.5 text-[11px] font-medium text-neutral-600 dark:text-neutral-300 hover:bg-neutral-100/60 dark:hover:bg-neutral-800/60 transition-colors",title:"Upcoming timers across the fleet — the next thing that will trigger on its own",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{children:"⏰"}),"Next up"]}),s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-[var(--adf-ui-text-subtle)] transition-transform ${n?"-rotate-90":""}`,children:s.jsx("path",{d:"M6 9l6 6 6-6"})})]}),!n&&s.jsx("div",{className:"overflow-y-auto max-h-[30vh]",children:l.map((d,c)=>{const u=Qy(d),h=d.nextWakeScope==="system"?"lambda":"wakes agent";return s.jsxs("button",{onClick:()=>t(d.filePath),className:"w-full flex items-center gap-2 px-2.5 py-1.5 text-left hover:bg-neutral-100/60 dark:hover:bg-neutral-800/60 border-t border-neutral-100 dark:border-neutral-800/60",title:`${d.handle} — ${new Date(d.nextWakeAt).toLocaleString()}
|
|
17
|
+
${h}${u?` · ${u}`:""}${d.nextWakeLabel?`
|
|
18
|
+
${d.nextWakeLabel}`:""}`,children:[s.jsx("span",{className:"shrink-0 text-base leading-none",children:s.jsx(Ct,{seed:mt({did:d.did,filePath:d.filePath}),icon:d.icon,iconSeed:d.agentId||d.filePath,size:18,emojiSize:16})}),s.jsxs("span",{className:"flex-1 min-w-0",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"truncate text-[11px] font-medium text-neutral-700 dark:text-neutral-200",children:d.handle}),u&&s.jsx("span",{className:`shrink-0 text-[9px] px-1 py-px rounded bg-neutral-100 dark:bg-neutral-800 text-[var(--adf-ui-text-subtle)] ${d.nextWakeSchedule?.mode==="cron"?"font-mono":""}`,children:u}),d.nextWakeScope==="system"&&s.jsx("span",{className:"shrink-0 text-[9px] text-[var(--adf-ui-text-subtle)]",title:"Runs a system lambda, not the agent loop",children:"λ"})]}),s.jsx("span",{className:"block truncate text-[10px] text-neutral-500 dark:text-neutral-400",children:d.nextWakeLabel||(d.nextWakeScope==="system"?"system lambda":"wake agent loop")})]}),s.jsx("span",{className:`shrink-0 font-mono text-[10px] tabular-nums ${c===0?"text-sky-600 dark:text-sky-400 font-semibold":"text-[var(--adf-ui-text-subtle)]"}`,children:Ky(d.nextWakeAt-i)})]},d.filePath)})})]})}),Uu="94, 234, 212",Ku="15, 118, 110",e1="248, 113, 113",t1="245, 158, 11",n1=700,r1=20,s1=1e3/30,o1=30,a1=22,i1=1e3/15,l1=.4,c1=220;function u1(e,t){const r=document.documentElement.classList.contains("dark")?Uu:Ku;if(t)return{rate:2.5,color:t1,peak:.9};if(!e.online)return null;switch(e.state){case"error":return{rate:1.5,color:e1,peak:.85};case"active":return{rate:4,color:r,peak:.7};case"idle":return{rate:1.1,color:r,peak:.55};case"hibernate":return{rate:.15,color:r,peak:.4};default:return{rate:.3,color:r,peak:.45}}}function d1(e,t){const n=t*Math.PI/3;return{x:e.x+(fe-2)*Math.cos(n),y:e.y+(fe-2)*Math.sin(n)}}function f1(e,t,n){const{q:r,r:o}=ft(e+(n()-.5)*fe*2.2,t+(n()-.5)*fe*2.2),a=tt(r,o),i=Math.floor(n()*6),l=n()<.5?1:-1,d=2+Math.floor(n()*2),c=[];for(let h=0;h<=d;h++)c.push(d1(a,((i+h*l)%6+6)%6));let u=0;for(let h=1;h<c.length;h++)u+=Math.hypot(c[h].x-c[h-1].x,c[h].y-c[h-1].y);return{path:c,length:u}}const h1="167, 139, 250",p1="196, 181, 253",xl=16,x1=8,gl=.95,g1=512;function m1(e,t){const{pts:n,cum:r}=e;for(let o=1;o<n.length;o++)if(t<=r[o]){const a=r[o]-r[o-1],i=a===0?0:(t-r[o-1])/a;return{x:n[o-1].x+(n[o].x-n[o-1].x)*i,y:n[o-1].y+(n[o].y-n[o-1].y)*i}}return n[n.length-1]}function ml(e,t){let n=t;for(let r=1;r<e.path.length;r++){const o=e.path[r-1],a=e.path[r],i=Math.hypot(a.x-o.x,a.y-o.y);if(n<=i){const l=i===0?0:n/i;return{x:o.x+(a.x-o.x)*l,y:o.y+(a.y-o.y)*l}}n-=i}return e.path[e.path.length-1]}const b1=k.memo(function({emitters:t}){const n=k.useRef(null),r=k.useRef(t);r.current=t;const{getViewport:o,getInternalNode:a}=Ir();return k.useEffect(()=>{const i=n.current;if(!i)return;const l=i.getContext("2d");if(!l)return;let d=!1,c=Math.min(2,window.devicePixelRatio||1);const u=()=>{c=d?1:Math.min(2,window.devicePixelRatio||1);const w=i.parentElement?.getBoundingClientRect();w&&(i.width=Math.round(w.width*c),i.height=Math.round(w.height*c))};u();const h=new ResizeObserver(u);i.parentElement&&h.observe(i.parentElement);const f=[],m=new Map,y=new Map;let S=0;const x=Math.random;let b=0,$=performance.now(),v=0,p=1e3/60;const M=(w,g,E,T)=>{if(f.length>=(d?c1:n1))return;const{path:j,length:_}=f1(w,g,x);f.push({path:j,length:_,bornAt:performance.now(),lifeMs:1e3+x()*1200,color:E,peak:T})},N=w=>{b=requestAnimationFrame(N);const g=w-$;$=w,p+=(Math.min(g,200)-p)*.05;const E=d?p>a1:p>o1;if(E!==d&&(d=E,u(),document.documentElement.classList.toggle("fleet-calm",d)),v+=g,v<(d?i1:s1))return;const T=v/1e3*(d?l1:1);if(v=0,document.hidden)return;const j=o(),_=i.width,I=i.height;l.clearRect(0,0,_,I);const C=r.current,O=pe.getState().pendingInteractions;let A=1/0,L=-1/0,R=1/0,F=-1/0;for(const B of C)A=Math.min(A,B.x),L=Math.max(L,B.x),R=Math.min(R,B.y),F=Math.max(F,B.y);for(const B of C){const Z=!!O[B.filePath];if(Z&&j.zoom>=.7)continue;const Q=u1(B,Z);if(!Q)continue;const K=(y.get(B.filePath)??0)+Q.rate*T,U=Math.floor(K);y.set(B.filePath,K-U);for(let re=0;re<U;re++)M(B.x,B.y,Q.color,Q.peak)}if(C.length>0&&Number.isFinite(A)){const B=document.documentElement.classList.contains("dark");S+=r1*T;const Z=Math.floor(S);S-=Z;const Q=fe*6,K=fe*6;for(let U=0;U<Z;U++)M(A-Q+x()*(L-A+Q*2),R-K+x()*(F-R+K*2),B?Uu:Ku,.3)}const W=j.zoom*c,G=j.x*c,Y=j.y*c;l.lineCap="round";for(let B=f.length-1;B>=0;B--){const Z=f[B],Q=w-Z.bornAt;if(Q>=Z.lifeMs){f[B]=f[f.length-1],f.pop();continue}const K=Q/Z.lifeMs,U=Z.peak*(K<.25?K/.25:1-(K-.25)/.75),re=ml(Z,Z.length*K),ae=re.x*W+G,se=re.y*W+Y;if(ae<-40||se<-40||ae>_+40||se>I+40)continue;const le=ml(Z,Math.max(0,Z.length*K-fe*.35));l.strokeStyle=`rgba(${Z.color}, ${U*.5})`,l.lineWidth=1.4*W,l.beginPath(),l.moveTo(le.x*W+G,le.y*W+Y),l.lineTo(ae,se),l.stroke(),d||(l.fillStyle=`rgba(${Z.color}, ${U*.25})`,l.beginPath(),l.arc(ae,se,5.5*W,0,Math.PI*2),l.fill()),l.fillStyle=`rgba(${Z.color}, ${U})`,l.beginPath(),l.arc(ae,se,2.2*W,0,Math.PI*2),l.fill()}const ee=pe.getState().activeAnimations;if(ee.length>0){const B=Date.now();for(const Z of ee){const Q=(B-Z.timestamp)/zl;if(Q<0||Q>=1)continue;const K=Z.from<Z.to,U=a(K?Z.from:Z.to),re=a(K?Z.to:Z.from);if(!U||!re)continue;const ae=Es(U),se=Es(re),le=K?`${Z.from}|${Z.to}`:`${Z.to}|${Z.from}`;let ie=m.get(le);(!ie||ie.sx!==ae.x||ie.sy!==ae.y||ie.tx!==se.x||ie.ty!==se.y)&&(m.size>=g1&&m.clear(),ie={sx:ae.x,sy:ae.y,tx:se.x,ty:se.y,samples:xb(Hu(ae,se))},m.set(le,ie));const{samples:V}=ie;if(V.total<1)continue;const oe=m1(V,K?V.total*Q:V.total*(1-Q)),de=oe.x*W+G,be=oe.y*W+Y,ke=xl*W+8;if(de<-ke||be<-ke||de>_+ke||be>I+ke)continue;const _e=Q<.8?gl:gl*(1-(Q-.8)/.2);l.fillStyle=`rgba(${h1}, ${_e})`,l.beginPath(),l.arc(de,be,xl*W,0,Math.PI*2),l.fill(),l.fillStyle=`rgba(${p1}, ${_e})`,l.beginPath(),l.arc(de,be,x1*W,0,Math.PI*2),l.fill()}}};return b=requestAnimationFrame(N),()=>{cancelAnimationFrame(b),h.disconnect(),document.documentElement.classList.remove("fleet-calm")}},[o,a]),s.jsx("canvas",{ref:n,className:"absolute inset-0 w-full h-full pointer-events-none",style:{zIndex:4}})}),Pa=(e,t,n)=>Math.min(n,Math.max(t,e)),bl=(e,t,n)=>Pa((e-t)/(n-t),0,1),Oo=(e,t,n)=>Pa((n-e)/(n-t),0,1),yl=.3,wl=.44,xs=13,vl=xs*1.35,Fo=340,kl=3,y1=220,Nl=(e,t)=>{if(e.level==="root"){const n=e.hasDistricts?Oo(t,yl,wl):Oo(t,1.05,1.35);return bl(t,.05,.09)*n}return bl(t,yl,wl)*Oo(t,1.05,1.35)},w1=k.memo(function({terrains:t}){const n=Se(),r=ye(w=>ve(w)),o=pe(w=>w.lastActivityAt),a=pe(w=>w.pendingInteractions),i=J(w=>w.stewards),l=J(w=>w.lens),d=J(w=>w.voicesOverride),c=Xs(),u=d??l==="terrain",[h,f]=k.useState(0),m=k.useRef(null),y=k.useRef(new Map),S=k.useRef([]),x=k.useRef(NaN),b=k.useRef(NaN),$=k.useRef(null),v=k.useMemo(()=>{const w=new Map(r.map(j=>[j.filePath,j])),g=new Map(r.filter(j=>j.did).map(j=>[j.did,j])),E=(j,_,I)=>{const C=_?g.get(_):void 0;if(C&&C.filePath!==I)return{voice:C,isSteward:!0};let O,A=-1;for(const L of j){if(L===I)continue;const R=w.get(L);if(!R)continue;const F=o[L]??0,W=R.state==="active"?F+1e15:F;W>A&&(A=W,O=R)}return{voice:O,isSteward:!1}},T=[];for(const j of t){const _=Mr(j.dirPath),I=j.cells.filter(R=>R.filePath);if(I.length===0)continue;const C=R=>{const F=R.reduce((Y,ee)=>Y+ee.x,0)/R.length,W=R.reduce((Y,ee)=>Y+ee.y,0)/R.length,G=Math.max(...R.map(Y=>Y.x))-Math.min(...R.map(Y=>Y.x))+400;return{wx:j.x+F,wy:j.y+W,span:G}},O=I.filter(R=>R.district===""),{voice:A,isSteward:L}=E(j.memberPaths,i[j.dirPath]);A&&(A.status||A.handle)&&T.push({key:`root:${j.dirPath}`,dir:j.dirPath,hoverDir:j.dirPath,hue:_,...C(O.length>0?O:I),voice:A,isSteward:L,level:"root",hasDistricts:j.districts.length>0});for(const R of j.districts){const F=I.filter(ee=>ee.district===R);if(F.length===0)continue;const W=F.map(ee=>ee.filePath).filter(Boolean),G=ln(j.dirPath)!==null?bd(W[0]):Sr(j.dirPath,R),Y=E(W,i[G],A?.filePath);!Y.voice||!Y.voice.status&&!Y.voice.handle||T.push({key:`district:${G}`,dir:G,hoverDir:Sr(j.dirPath,R),hue:_,...C(F),voice:Y.voice,isSteward:Y.isSteward,level:"district",hasDistricts:!1})}}return T},[t,r,o,i]),p=k.useMemo(()=>{const w=n.getState().transform[2];b.current=w;const g=[];for(const T of v){if(a[T.voice.filePath])continue;const j=T.voice.handle.length+(T.voice.status?.length??0)+3,_=Pa(Math.ceil(j*xs*.52/(Fo-20)),1,kl),I=Math.min(Fo,j*xs*.55+22),C=_*vl+12;g.push({...T,w:I,h:C,offY:0})}g.sort((T,j)=>T.wy-j.wy);const E=[];for(const T of g){if(Nl(T,w)<=.02)continue;const j=T.wx*w;let _=T.wy*w;for(const I of E)Math.abs(j-I.sx)<(T.w+I.w)/2*.9&&Math.abs(_-I.sy)<(T.h+I.h)/2&&(_=I.sy+(I.h+T.h)/2+6);E.push({sx:j,sy:_,w:T.w,h:T.h}),T.offY=_-T.wy*w}return g},[v,a,h,n]),M=k.useCallback((w=!1)=>{const g=m.current;if(!g)return;const[E,T,j]=n.getState().transform;if(g.style.transform=`translate(${E}px, ${T}px) scale(${j})`,!(!w&&j===x.current)){x.current=j,g.style.visibility=j<=.05?"hidden":"";for(const _ of S.current){const I=y.current.get(_.key);if(!I)continue;const C=Nl(_,j);I.style.transform=`translate(${_.wx}px, ${_.wy}px) scale(${1/j}) translate(0px, ${_.offY}px) translate(-50%, -50%)`,I.style.opacity=C.toFixed(3),I.style.visibility=C<=.02?"hidden":"",I.style.pointerEvents=C<.15?"none":"auto"}j!==b.current&&($.current&&clearTimeout($.current),$.current=setTimeout(()=>{$.current=null,n.getState().transform[2]!==b.current&&f(_=>_+1)},y1))}},[n]);if(k.useLayoutEffect(()=>{S.current=p,M(!0)},[p,u,M]),k.useEffect(()=>{const w=n.subscribe((g,E)=>{g.transform!==E.transform&&M()});return()=>{w(),$.current&&clearTimeout($.current)}},[n,M]),!u)return null;const N=w=>{const g=document.querySelector(".react-flow__pane");g&&g.dispatchEvent(new WheelEvent("wheel",{deltaX:w.deltaX,deltaY:w.deltaY,deltaMode:w.deltaMode,clientX:w.clientX,clientY:w.clientY,ctrlKey:w.ctrlKey,metaKey:w.metaKey,shiftKey:w.shiftKey,altKey:w.altKey,bubbles:!0,cancelable:!0}))};return s.jsx("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",style:{zIndex:5},onWheel:N,children:s.jsx("div",{ref:m,className:"absolute left-0 top-0",style:{transformOrigin:"0 0",willChange:"transform"},children:p.map(w=>s.jsx("div",{ref:g=>{g?y.current.set(w.key,g):y.current.delete(w.key)},className:"fleet-voice-chip absolute left-0 top-0 cursor-pointer",style:{width:"max-content",maxWidth:Fo,visibility:"hidden",fontSize:xs,lineHeight:1.35,padding:"5px 10px",borderRadius:12,background:c?"rgba(15, 18, 22, 0.85)":"rgba(255, 255, 255, 0.9)",border:`1px solid hsla(${w.hue}, 30%, ${c?55:45}%, 0.45)`,color:c?"rgba(190,190,190,0.85)":"rgba(90,90,90,0.85)",boxShadow:c?"0 2px 10px rgba(0,0,0,0.35)":"0 2px 10px rgba(0,0,0,0.08)"},onClick:()=>J.getState().setReadoutDir(w.dir),onMouseEnter:()=>J.getState().setHoverDir(w.hoverDir),onMouseLeave:()=>J.getState().setHoverDir(null),onWheel:g=>{const E=g.currentTarget.querySelector(".fleet-voice-body");E&&E.scrollHeight>E.clientHeight+1&&g.stopPropagation()},title:"Click for the full group readout",children:s.jsxs("span",{className:"fleet-voice-body",style:{display:"block",maxHeight:kl*vl,overflowY:"auto"},children:[s.jsxs("span",{style:{fontWeight:600,color:c?"rgba(235,235,235,0.95)":"rgba(45,45,45,0.95)"},children:[w.isSteward?"♛ ":"",w.voice.handle]}),w.voice.status?s.jsxs("span",{style:{fontStyle:"italic"},children:[" — ",w.voice.status]}):null]})},w.key))})})}),v1=e=>e-Math.floor(e),ur=(e,t)=>v1(Math.sin(e*127.1+t*311.7)*43758.5453),jl=e=>e*e*(3-2*e);function la(e,t){const n=Math.floor(e),r=Math.floor(t),o=jl(e-n),a=jl(t-r),i=ur(n,r),l=ur(n+1,r),d=ur(n,r+1),c=ur(n+1,r+1);return i+(l-i)*o+(d-i)*a+(i-l-d+c)*o*a}const k1=(e,t)=>.62*la(e*.3,t*.3)+.38*la(e*.73+13.7,t*.73+7.3),N1=(e,t)=>la(e*.16+41.2,t*.16+87.9),zo=.32,j1=k.memo(function(){const t=k.useRef(null),n=Se();return k.useEffect(()=>{const r=t.current;if(r)return Xu({canvas:r,store:n,maxBackingPx:16e6,maxPad:.5,zoomInvalidates:(o,a)=>o>zo!=a>zo,draw:(o,a)=>{const{tx:i,ty:l,zoom:d,W:c,H:u,padW:h,padH:f,dpr:m,dark:y}=a;o.setTransform(1,0,0,1,0,0),o.clearRect(0,0,r.width,r.height),o.setTransform(d*m,0,0,d*m,(i+h)*m,(l+f)*m);const S=(-h-i)/d-fe,x=(c+h-i)/d+fe,b=(-f-l)/d-fe,$=(u+f-l)/d+fe,v=Math.floor(S/Fe),p=Math.ceil(x/Fe),M=y?"45, 212, 191":"13, 148, 136",N=y?"167, 139, 250":"139, 92, 246",w=d>zo;for(let g=v;g<=p;g++){const E=Math.floor(b/$e-g/2),T=Math.ceil($/$e-g/2);for(let j=E;j<=T;j++){const _=k1(g,j);if(_<=.58)continue;const I=g*Fe,C=(j+g/2)*$e,O=N1(g,j)>.72?N:M,A=Math.min(.09,(_-.58)*.45)*(y?1:.8);o.fillStyle=`rgba(${O}, ${A})`,o.beginPath();for(let R=0;R<6;R++){const F=R*Math.PI/3,W=I+(fe-2)*Math.cos(F),G=C+(fe-2)*Math.sin(F);R===0?o.moveTo(W,G):o.lineTo(W,G)}if(o.closePath(),o.fill(),!w)continue;const L=ur(g*3.1,j*5.7);if(L>.9&&_>.66){const F=Math.floor(L*100)%6*Math.PI/3;o.fillStyle=`rgba(${O}, ${y?.28:.22})`,o.beginPath(),o.arc(I+fe*.72*Math.cos(F),C+fe*.72*Math.sin(F),4,0,Math.PI*2),o.fill()}if(L>.82&&L<=.86&&_>.62){const F=Math.floor(L*1e3)%6*Math.PI/3,W=I+fe*.62*Math.cos(F),G=C+fe*.62*Math.sin(F),Y=F+Math.PI,ee=Math.cos(Y),B=Math.sin(Y),Z=-B,Q=ee,K=fe*.22;o.strokeStyle=`rgba(${O}, ${y?.18:.15})`,o.fillStyle=o.strokeStyle,o.lineWidth=2,o.lineCap="round",o.beginPath(),o.moveTo(W,G),o.lineTo(W+ee*K,G+B*K),o.moveTo(W+ee*K*.45,G+B*K*.45),o.lineTo(W+ee*K*.45+(Z*.5+ee*.4)*K*.5,G+B*K*.45+(Q*.5+B*.4)*K*.5),o.moveTo(W+ee*K*.7,G+B*K*.7),o.lineTo(W+ee*K*.7+(-Z*.5+ee*.4)*K*.5,G+B*K*.7+(-Q*.5+B*.4)*K*.5),o.stroke(),o.beginPath(),o.arc(W+ee*K,G+B*K,2.5,0,Math.PI*2),o.fill()}}}}})},[n]),s.jsx("canvas",{ref:t,className:"absolute pointer-events-none",style:{zIndex:-9,transformOrigin:"0 0",willChange:"transform"}})}),S1=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),M1=e=>/\.(md|markdown)$/i.test(e);function ss({title:e,children:t}){return s.jsxs("div",{children:[s.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] mb-1",children:e}),t]})}function Wt({tone:e,children:t}){const n={green:"bg-green-50 dark:bg-green-900/30 text-green-600 dark:text-green-400",sky:"bg-sky-50 dark:bg-sky-900/30 text-sky-600 dark:text-sky-400",violet:"bg-violet-50 dark:bg-violet-900/30 text-violet-600 dark:text-violet-400",amber:"bg-amber-50 dark:bg-amber-900/30 text-amber-600 dark:text-amber-400",neutral:"bg-neutral-100 dark:bg-neutral-800 text-neutral-500 dark:text-neutral-400"};return s.jsx("span",{className:`text-[10px] px-2 py-0.5 rounded-full ${n[e]}`,children:t})}const $1={mdns:"LAN · mDNS",tailnet:"Tailnet",manual:"manual peer"},E1=k.memo(function({agent:t,peerHost:n,peerUrl:r,peerSource:o,onClose:a}){const[i,l]=k.useState(!1),[d,c]=k.useState(!1),[u,h]=k.useState(null),[f,m]=k.useState(null);k.useEffect(()=>{const g=E=>{E.key==="Escape"&&(E.stopPropagation(),a())};return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[a]);const y=()=>{t.did&&navigator.clipboard.writeText(t.did).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},S=r?`${r.replace(/\/+$/,"")}/agents/${encodeURIComponent(t.handle)}`:t.endpoints?.card?.replace(/\/+$/,"").replace(/\/card$/,"");k.useEffect(()=>{const g=S?`${S}/health`:t.endpoints?.health;if(!g||!window.adfApi.getPeerAgentHealth)return;let E=!1;return window.adfApi.getPeerAgentHealth(g).then(T=>{E||m(T.ok?{state:T.state,status:T.status}:"unreachable")}).catch(()=>{E||m("unreachable")}),()=>{E=!0}},[t.handle,r]);const x=g=>{S&&(h({path:g,loading:!0}),window.adfApi.getPeerSharedFile(S,g).then(E=>{h(T=>!T||T.path!==g?T:E.ok?{path:g,loading:!1,content:E.content,binary:E.binary,size:E.size}:{path:g,loading:!1,error:E.error})}).catch(()=>{h(E=>E?.path===g?{path:g,loading:!1,error:"Fetch failed"}:E)}))},b=()=>{if(!u?.content)return;const g=u.binary?Uint8Array.from(atob(u.content),j=>j.charCodeAt(0)):new TextEncoder().encode(u.content),E=new Blob([g]),T=document.createElement("a");T.href=URL.createObjectURL(E),T.download=u.path.split("/").pop()??"file",T.click(),URL.revokeObjectURL(T.href)},$=k.useMemo(()=>!u?.content||u.binary||!M1(u.path)?null:yd.parse(S1(u.content)),[u]),v=Object.entries(t.endpoints??{}).filter(g=>typeof g[1]=="string"&&g[1].length>0),p=(t.policies??[]).some(g=>g.type==="signing"&&(g.receive==="required"||g.send==="required")),M=t.shared??[],N=t.api_routes??[],w=t.signed_at?new Date(t.signed_at):null;return s.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-black/40 backdrop-blur-sm",style:{animation:"meshFadeIn 150ms ease-out"},onClick:a,children:s.jsxs("div",{className:"w-[560px] max-w-[90vw] max-h-[82vh] flex flex-col rounded-2xl bg-white/95 dark:bg-neutral-900/95 border border-neutral-200 dark:border-neutral-700 shadow-2xl overflow-hidden",onClick:g=>g.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center gap-3 px-5 pt-4 pb-3",children:[s.jsx(ca,{did:t.did,icon:t.icon,size:36,emojiSize:30}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"text-[15px] font-semibold text-neutral-800 dark:text-neutral-100 truncate",children:[t.handle,u&&s.jsxs("span",{className:"font-normal text-[var(--adf-ui-text-subtle)]",children:[" / ",u.path]})]}),s.jsxs("div",{className:"text-[11px] text-[var(--adf-ui-text-subtle)]",children:["remote agent · ",n]})]}),u&&u.content&&s.jsx("button",{onClick:b,className:"shrink-0 px-2.5 py-1 text-[11px] rounded-md border border-neutral-200 dark:border-neutral-700 text-neutral-600 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800",children:"↓ download"}),u&&s.jsx("button",{onClick:()=>h(null),className:"shrink-0 px-2.5 py-1 text-[11px] rounded-md border border-neutral-200 dark:border-neutral-700 text-neutral-600 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800",children:"← card"}),s.jsx("button",{onClick:a,className:"w-7 h-7 flex items-center justify-center rounded-full text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-200 hover:bg-neutral-100 dark:hover:bg-neutral-800",title:"Close (Esc)",children:"✕"})]}),u?s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 pb-4",children:[u.loading&&s.jsxs("div",{className:"py-8 text-center text-[12px] text-[var(--adf-ui-text-subtle)]",children:["fetching from ",n,"…"]}),u.error&&s.jsxs("div",{className:"py-8 text-center",children:[s.jsx("div",{className:"text-[12px] text-red-500",children:u.error}),u.error==="HTTP 404"&&s.jsx("div",{className:"mt-1 text-[11px] text-[var(--adf-ui-text-subtle)]",children:"The card lists this file, but the peer isn't serving it right now."})]}),u.content&&u.binary&&s.jsxs("div",{className:"py-8 text-center text-[12px] text-[var(--adf-ui-text-subtle)]",children:["Binary file · ",Math.round((u.size??0)/1024)," KB — use download."]}),$&&s.jsx("div",{className:"loop-markdown text-[13px] leading-relaxed text-neutral-700 dark:text-neutral-200",dangerouslySetInnerHTML:{__html:$}}),u.content&&!u.binary&&!$&&s.jsx("pre",{className:"font-mono text-[11px] leading-[1.6] text-neutral-700 dark:text-neutral-300 whitespace-pre-wrap break-words",children:u.content})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-1.5 px-5 pb-3 flex-wrap",children:[f&&f!=="unreachable"&&s.jsxs(Wt,{tone:"green",children:["● live",f.state?`: ${f.state}`:""]}),f==="unreachable"&&s.jsx(Wt,{tone:"amber",children:"health unreachable"}),t.card_verified?s.jsx(Wt,{tone:"green",children:"✓ signed card"}):s.jsx(Wt,{tone:"neutral",children:"unverified"}),t.owner_attested&&s.jsx(Wt,{tone:"sky",children:"owner attested"}),p&&s.jsx(Wt,{tone:"violet",children:"signing required"}),t.public&&s.jsx(Wt,{tone:"amber",children:"public"}),o&&s.jsxs(Wt,{tone:"violet",children:["via ",$1[o]??o]}),t.visibility&&s.jsxs(Wt,{tone:"neutral",children:["visibility: ",t.visibility]}),S&&N.length>0&&s.jsxs("a",{href:`${S}/`,target:"_blank",rel:"noreferrer",className:"text-[10px] px-2 py-0.5 rounded-full bg-sky-50 dark:bg-sky-900/30 text-sky-600 dark:text-sky-400 hover:underline",title:`Serving ${S}/ — click to open`,children:["🌐 ",S.replace(/^https?:\/\//,""),"/"]})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 pb-4 space-y-3",children:[t.status&&s.jsxs("div",{className:"px-4 py-3 rounded-xl bg-neutral-50 dark:bg-neutral-800/60 border border-neutral-100 dark:border-neutral-700/60",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] mb-1",children:"status"}),s.jsx("div",{className:"text-[13px] leading-relaxed text-neutral-700 dark:text-neutral-200 whitespace-pre-wrap",children:t.status})]}),t.description&&s.jsx(ss,{title:"about",children:s.jsx("div",{className:"text-[12px] leading-relaxed text-neutral-600 dark:text-neutral-300 whitespace-pre-wrap",children:t.description})}),M.length>0&&s.jsx(ss,{title:`shared files · ${M.length}`,children:s.jsx("div",{className:"rounded-lg bg-neutral-50 dark:bg-neutral-800/60 border border-neutral-100 dark:border-neutral-700/60 px-1 py-1 max-h-56 overflow-y-auto",children:M.map(g=>s.jsx("button",{onClick:()=>x(g),disabled:!S,className:"w-full text-left px-1.5 py-0.5 rounded font-mono text-[11px] leading-[1.6] text-neutral-600 dark:text-neutral-300 truncate hover:bg-neutral-100 dark:hover:bg-neutral-700/60 hover:text-blue-600 dark:hover:text-blue-400 disabled:hover:bg-transparent",title:S?`Read ${g}`:g,children:g},g))})}),v.length>0&&s.jsx(ss,{title:"endpoints",children:s.jsx("div",{className:"space-y-1",children:v.map(([g,E])=>s.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 rounded-lg bg-neutral-50 dark:bg-neutral-800/60 border border-neutral-100 dark:border-neutral-700/60",children:[s.jsx("span",{className:"text-[10px] w-11 shrink-0 text-center px-1 py-px rounded bg-neutral-200/70 dark:bg-neutral-700 text-neutral-500 dark:text-neutral-400",children:g}),s.jsx("span",{className:"font-mono text-[11px] text-neutral-600 dark:text-neutral-300 truncate",title:E,children:E})]},g))})}),t.did&&s.jsxs(ss,{title:"did",children:[s.jsxs("button",{onClick:y,className:"w-full text-left px-2.5 py-1.5 rounded-lg bg-neutral-50 dark:bg-neutral-800/60 border border-neutral-100 dark:border-neutral-700/60 hover:border-neutral-300 dark:hover:border-neutral-600",title:"Click to copy",children:[s.jsx("span",{className:"font-mono text-[10px] text-neutral-500 dark:text-neutral-400 break-all",children:t.did}),s.jsx("span",{className:"ml-2 text-[10px] text-blue-500",children:i?"copied ✓":"copy"})]}),(t.attested_owner_did||w)&&s.jsxs("div",{className:"mt-1.5 space-y-0.5",children:[t.attested_owner_did&&s.jsxs("div",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] truncate",title:t.attested_owner_did,children:["owner: ",s.jsx("span",{className:"font-mono",children:t.attested_owner_did})]}),w&&!isNaN(w.getTime())&&s.jsxs("div",{className:"text-[10px] text-[var(--adf-ui-text-subtle)]",children:["card signed ",w.toLocaleString()]})]})]}),N.length>0&&s.jsxs("div",{children:[s.jsxs("button",{onClick:()=>c(g=>!g),className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-300",children:[d?"▾":"▸"," serves · ",N.length," route",N.length===1?"":"s"]}),d&&s.jsx("div",{className:"mt-1 space-y-1",children:N.map((g,E)=>s.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1 rounded-lg bg-neutral-50 dark:bg-neutral-800/60 border border-neutral-100 dark:border-neutral-700/60",children:[s.jsx("span",{className:"text-[10px] font-semibold w-11 shrink-0 text-center px-1 py-px rounded bg-neutral-200/70 dark:bg-neutral-700 text-neutral-500 dark:text-neutral-300",children:g.method}),s.jsx("span",{className:"font-mono text-[11px] text-neutral-600 dark:text-neutral-300 truncate",children:g.path})]},E))})]})]})]})]})})});function C1(e,t){if(!(e.status==="loaded"||t!=null))return e.status==="loading"?"Loading arguments…":e.reason?`Arguments unavailable: ${e.reason}`:"Arguments unavailable"}const _1=k.memo(function({filePath:t,onClose:n,onOpenAgent:r}){const o=ye(S=>ve(S).find(x=>x.filePath===t)),a=pe(S=>S.pendingInteractions[t]),i=pe(S=>S.setPendingInteraction),d=ua()===t,[c,u]=k.useState({status:"loading"}),h=a?.type==="approval"?a.approvalId:void 0,f=a?.type==="approval";k.useEffect(()=>{if(!f)return;if(!h){u({status:"unavailable",reason:"the runtime did not send the request id"});return}const S=qe(t),x=S.api;if(!x?.getApprovalInput){u({status:"unavailable",reason:"this runtime cannot send arguments"});return}u({status:"loading"});let b=!1;return x.getApprovalInput(S.filePath,h).then($=>{b||u($!=null?{status:"loaded",input:$}:{status:"unavailable",reason:"the runtime no longer has this request"})}).catch($=>{b||u({status:"unavailable",reason:$ instanceof Error?$.message:String($)})}),()=>{b=!0}},[t,h,f]),k.useEffect(()=>{(!a||a.type!=="approval")&&n()},[a,n]);const m=k.useCallback((S,x)=>{if(!(!a||a.type!=="approval")){if(d)qe(t).api.respondToolApproval(a.requestId,S,x);else{const b=qe(t);b.api.respondBackgroundAgentToolApproval(b.filePath,a.requestId,S,x)}i(t,null),n()}},[a,t,d,i,n]),y=k.useCallback(async()=>{if(!a||a.type!=="approval")return;const S=a.toolName??"tool",x=qe(t),b=d?await x.api.alwaysApproveTool(a.requestId,S):await x.api.alwaysApproveBackgroundAgentTool(x.filePath,a.requestId,S);if(b&&!b.success){console.warn(`[FleetApprovalModal] Always approve refused for ${S}: ${b.error}`);return}i(t,null),n()},[a,t,d,i,n]);return!a||a.type!=="approval"?null:s.jsx(wd,{variant:"absolute",toolName:a.toolName??"tool",input:c.status==="loaded"?c.input:a.input,inputNotice:C1(c,a.input),awaitingApproval:!0,approvalTitle:a.protection?.description,subtitle:t,headerLead:s.jsxs("span",{className:"flex items-center gap-2 min-w-0 shrink-0",children:[s.jsx("span",{className:"text-2xl leading-none shrink-0",children:s.jsx(Ct,{seed:mt({did:o?.did,filePath:t}),icon:o?.icon,iconSeed:o?.agentId||t,size:28,emojiSize:24})}),s.jsx("span",{className:"text-[14px] font-semibold text-neutral-800 dark:text-neutral-100 truncate max-w-40",children:o?.handle??t.split("/").pop()?.replace(/\.adf$/,"")}),s.jsx("span",{className:"text-[12px] text-[var(--adf-ui-text-subtle)] shrink-0",children:"wants to call"})]}),headerActions:r&&s.jsx("button",{onClick:r,className:"px-2.5 py-1 text-[11px] font-medium rounded-full border border-neutral-200 dark:border-neutral-700 text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 hover:bg-neutral-100 dark:hover:bg-neutral-800 shrink-0 whitespace-nowrap",title:"Open this agent's document and loop — the approval stays pending",children:"Open agent"}),approvalControls:s.jsx(Fl,{dropUp:!0,toolName:a.toolName??"tool",onApprove:()=>m(!0),onAlwaysApprove:()=>{y()},onReject:S=>m(!1,S),alwaysApproveDisabled:a.canAlwaysApprove===!1,alwaysApproveDisabledReason:a.alwaysApproveBlockedReason}),onClose:n})}),P1={mdns:"LAN · mDNS",tailnet:"Tailnet",manual:"manual peer"},A1={telegram:"channel adapter",email:"channel adapter",discord:"channel adapter",imessage:"channel adapter",slack:"channel adapter",web:"web gateway — sys_fetch + WS links"},I1={running:"bg-green-400",connected:"bg-green-400",error:"bg-red-400",stopped:"bg-neutral-400"};function Sl(e){const t=Math.round(e/6e4);if(t<1)return"just now";if(t<60)return`${t}m ago`;const n=Math.floor(t/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}const T1=k.memo(function({stationId:t,data:n,onClose:r,onOpenAgent:o,onOpenLocalAgent:a}){const i=ye(b=>ve(b)),l=pe(b=>b.edgeHeat),[d,c]=k.useState(null);k.useEffect(()=>{const b=$=>{$.key==="Escape"&&(J.getState().peerReadout||($.stopPropagation(),r()))};return window.addEventListener("keydown",b,!0),()=>window.removeEventListener("keydown",b,!0)},[r]);const u=n.detail,h=n.peerAgents??[],f=n.kind==="peer",m=k.useMemo(()=>{let b=0,$=0,v=0;const p=new Map;for(const[N,w]of Object.entries(l)){const[g,E]=N.split("|");if(g!==t&&E!==t)continue;g===t?b+=w.count:$+=w.count,v=Math.max(v,w.lastAt);const T=g===t?E:g;p.set(T,(p.get(T)??0)+w.count)}const M=[...p.entries()].sort((N,w)=>w[1]-N[1]).slice(0,5).map(([N,w])=>{const g=N.startsWith("station:")?void 0:i.find(E=>E.filePath===N);return{key:N,count:w,handle:g?.handle??(N.startsWith("station:")?N.slice(8):Ve(N).replace(/\.adf$/,"")),seed:g?mt({did:g.did,filePath:g.filePath}):null,icon:g?.icon,iconSeed:g?g.agentId||g.filePath:null,localFilePath:g?.filePath}});return{inbound:b,outbound:$,lastAt:v,top:M}},[l,t,i]),y=u?.isSelfOwned?{text:"✓ your server",tone:"text-indigo-600 dark:text-indigo-400"}:u?.ownerAlias?u.ownerVerified?{text:`owned by ${u.ownerAlias}`,tone:"text-neutral-600 dark:text-neutral-300"}:{text:`${u.ownerAlias} · unverified`,tone:"text-[var(--adf-ui-text-subtle)]"}:null,S=u?.agentCount!=null,x=(b,$)=>{navigator.clipboard.writeText($),c(b),setTimeout(()=>c(null),1200)};return s.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-black/40 backdrop-blur-sm",style:{animation:"meshFadeIn 150ms ease-out"},onClick:r,children:s.jsxs("div",{className:"w-[560px] max-w-[90vw] max-h-[82vh] flex flex-col rounded-2xl bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-700 shadow-2xl overflow-hidden",onClick:b=>b.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center gap-3 px-5 pt-4 pb-3",children:[s.jsx("span",{className:"text-3xl leading-none shrink-0",children:f?"🛰️":Yu[n.kind]??"📡"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-[16px] font-semibold text-neutral-800 dark:text-neutral-100 truncate",children:n.label}),f?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${S?"bg-green-400":"bg-amber-400"}`}),s.jsx("span",{className:"text-[11px] text-[var(--adf-ui-text-subtle)]",children:S?`${u?.agentCount} agent${u?.agentCount===1?"":"s"}`:"directory unreachable"})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${I1[n.status]??"bg-neutral-400"}`}),s.jsx("span",{className:"text-[11px] italic text-[var(--adf-ui-text-subtle)]",children:n.status})]})]}),s.jsxs("div",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 truncate",children:[f?"remote server":A1[n.kind]??"base station",u?.source&&` — ${P1[u.source]??u.source}`,y&&s.jsxs("span",{className:`ml-1.5 ${y.tone}`,children:["· ",y.text]})]})]}),s.jsx("button",{onClick:r,className:"w-7 h-7 flex items-center justify-center rounded-full text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-200 hover:bg-neutral-100 dark:hover:bg-neutral-800 shrink-0",title:"Close (Esc)",children:"✕"})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 pb-4 space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[u?.host&&s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] w-10 shrink-0",children:"host"}),s.jsx("span",{className:"font-mono text-[11px] text-neutral-600 dark:text-neutral-300 truncate",children:u.host})]}),u?.url&&s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] w-10 shrink-0",children:"url"}),s.jsx("button",{onClick:()=>x("url",u.url),className:"flex-1 min-w-0 text-left font-mono text-[11px] text-neutral-600 dark:text-neutral-300 truncate hover:text-neutral-800 dark:hover:text-neutral-100",title:"Click to copy",children:u.url}),d==="url"&&s.jsx("span",{className:"text-[10px] text-green-500 shrink-0",children:"copied"})]}),u?.firstSeen&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] w-10 shrink-0",children:"seen"}),s.jsxs("span",{className:"text-[11px] text-neutral-500 dark:text-neutral-400",children:["first discovered ",Sl(Date.now()-u.firstSeen)]})]})]}),h.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] mb-1.5",children:["agents · ",h.length]}),s.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:h.map(b=>s.jsxs("button",{onClick:()=>o(b),className:"flex items-center gap-2 px-2.5 py-1.5 rounded-lg border border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800/60 hover:bg-neutral-100 dark:hover:bg-neutral-800 text-left min-w-0",title:`${b.handle} — open card`,children:[s.jsx(ca,{did:b.did,icon:b.icon,size:20,emojiSize:18}),s.jsxs("span",{className:"flex-1 min-w-0",children:[s.jsx("span",{className:"block text-[12px] font-medium text-neutral-700 dark:text-neutral-200 truncate",children:b.handle}),b.status&&s.jsx("span",{className:"block text-[10px] italic text-[var(--adf-ui-text-subtle)] truncate",children:b.status})]}),b.card_verified&&s.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400 shrink-0",title:"card signature verified"})]},b.did??b.handle))})]}),f&&h.length===0&&s.jsx("div",{className:"py-2 text-center text-[11px] italic text-[var(--adf-ui-text-subtle)]",children:S?"No agents visible to this server.":"Directory unreachable — agent list unknown."}),s.jsxs("div",{className:"pt-1 border-t border-neutral-100 dark:border-neutral-800",children:[s.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[var(--adf-ui-text-subtle)] pt-2",children:f?"traffic with your fleet":"traffic through this station"}),s.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-neutral-600 dark:text-neutral-300 tabular-nums mt-1",children:[s.jsxs("span",{children:["↓ ",m.inbound," ",f?"received from it":"in"]}),s.jsxs("span",{children:["↑ ",m.outbound," ",f?"sent to it":"out"]}),m.lastAt>0&&s.jsxs("span",{className:"text-[var(--adf-ui-text-subtle)] ml-auto",children:["last ",Sl(Date.now()-m.lastAt)]})]}),m.top.length>0?s.jsxs("div",{className:"mt-1.5 space-y-1",children:[s.jsx("div",{className:"text-[10px] text-[var(--adf-ui-text-subtle)]",children:f?"Who talked to this server:":"Who uses this station:"}),m.top.map(b=>b.localFilePath?s.jsxs("button",{onClick:()=>a(b.localFilePath),className:"w-full flex items-center gap-2 px-2 py-1 rounded-lg border border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800/60 hover:bg-neutral-100 dark:hover:bg-neutral-800 text-left",title:`${b.handle} — open its readout`,children:[s.jsx(Ct,{seed:b.seed,icon:b.icon,iconSeed:b.iconSeed,size:16,emojiSize:14}),s.jsx("span",{className:"text-[11px] font-medium text-neutral-700 dark:text-neutral-200 truncate",children:b.handle}),s.jsx("span",{className:"text-[9px] px-1.5 py-px rounded-full bg-indigo-50 dark:bg-indigo-900/30 text-indigo-600 dark:text-indigo-400 shrink-0",children:"your agent"}),s.jsxs("span",{className:"text-[11px] text-[var(--adf-ui-text-subtle)] tabular-nums ml-auto shrink-0",children:[b.count," msg",b.count===1?"":"s"]})]},b.key):s.jsxs("div",{className:"flex items-baseline gap-2 text-[11px] px-2",children:[s.jsx("span",{className:"text-neutral-700 dark:text-neutral-200 truncate",children:b.handle}),s.jsxs("span",{className:"text-[var(--adf-ui-text-subtle)] tabular-nums ml-auto shrink-0",children:[b.count," msg",b.count===1?"":"s"]})]},b.key))]}):s.jsx("div",{className:"mt-1.5 text-[11px] italic text-[var(--adf-ui-text-subtle)]",children:"no traffic yet"})]})]})]})})});function R1(e,t){if(t.type!=="message_routed")return t;const n=t.payload,r=o=>o.startsWith("station:")?o:da({runtimeId:e,filePath:o});return{...t,payload:{...t.payload,...n.filePath?{filePath:r(n.filePath)}:{},...n.toFilePaths?{toFilePaths:n.toFilePaths.map(r)}:{}}}}let D1=0;function it(){return`act-${++D1}`}function L1(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:`${Math.round(e)}`}function Ml(e){const t=(e.usage?.input??0)+(e.usage?.output??0);return`${e.model||"llm"} · ${L1(t)} tok`}function $l(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function El(e){if(!$l(e)||typeof e.model!="string")return!1;const t=e.usage;return!$l(t)||e.estimated!==void 0&&typeof e.estimated!="boolean"?!1:["input","output","cache_read","cache_write","reasoning","cost_usd"].every(r=>t[r]===void 0||typeof t[r]=="number")}function Cl(e){const n=(typeof e.error=="string"?e.error:"unknown error").split(`
|
|
19
|
+
`)[0];return n.length>48?n.slice(0,48)+"…":n}function O1(e){return e.interrupted?"interrupted":typeof e.targetState=="string"?`done → ${e.targetState}`:"done"}function _l(e){if(!e.interrupted&&Array.isArray(e.content)){const t=e.content.filter(n=>n?.type==="text").map(n=>n.text??"").join(`
|
|
20
|
+
`).trim();if(t){const n=t.replace(/\s+/g," ");return{args:n.length>64?`“${n.slice(0,64)}…”`:`“${n}”`,detail:n.length>64?t.slice(0,600):void 0}}}return{args:O1(e)}}const F1=new Set(["thinking","tool_use"]);function Pl(e,t){if(e==="sys_fetch")return"station:web";if(e==="msg_send"){const n=t?.recipient;if(typeof n=="string"){const r=n.match(/^(telegram|discord|email|imessage|slack):/);if(r)return`station:${r[1]}`}}return null}function Ho(e){if(e)try{const t=e;if(typeof t._reason=="string"&&t._reason)return t._reason;const n=typeof e=="string"?e:JSON.stringify(e);return n.length>40?n.slice(0,40)+"...":n}catch{return}}function z1(){const e=pe,t=ye,n=k.useRef(null),r=Xd(),o=_t(a=>a.runtimes.length>1?JSON.stringify(a.runtimes.filter(i=>i.id!=="local").map(i=>i.id)):"[]");k.useEffect(()=>{const a=[];let i=[],l=0;const d=()=>{if(l=0,i.length===0)return;const h=i;i=[];const f={...e.getState()},m={},y=p=>{p&&(Object.assign(f,p),Object.assign(m,p))},S={},x=p=>jd(t.getState(),p).agents,b=p=>{const M=kd(p,x);if(M&&M.type==="message_routed"){const N=M.payload,w=N.filePath,g=N.toFilePaths??[];g.length>0&&y(wo(f,w,g,N.channel)),N.toPeerAgent&&y(Nd(f,N.toPeerAgent.runtimeId,N.toPeerAgent.id)),w.startsWith("station:")||y(at(f,w,{id:it(),toolName:"msg_send",args:N.channel?`#${N.channel}`:void 0,timestamp:Date.now(),type:"message_sent"}))}},$=(p,M)=>{if(p.type==="state_changed"){const w=p.payload.state;if(!w)return;if(F1.has(w)){S[M]="active";return}S[M]=w,y(at(f,M,{id:it(),toolName:"state",args:`→ ${w}`,timestamp:p.timestamp,type:"state"}));return}const N=p.payload;switch(p.type){case"tool_call_start":{y(at(f,M,{id:it(),toolName:N.name??"unknown",args:Ho(N.input),timestamp:p.timestamp,type:"tool_start"}));const w=Pl(N.name??"",N.input);w&&y(wo(f,M,[w]));break}case"tool_call_result":{const w=N.result;y(Ha(f,M,N.name??"unknown",!!w?.isError));break}case"inter_agent_message":y(at(f,M,{id:it(),toolName:"msg_recv",args:Ho(N.from),timestamp:p.timestamp,type:"message_recv"}));break;case"response_metadata":El(N)&&!N.estimated&&y(at(f,M,{id:it(),toolName:"llm",args:Ml(N),timestamp:p.timestamp,type:"llm"}));break;case"turn_complete":{const w=_l(N);y(at(f,M,{id:it(),toolName:"turn",args:w.args,detail:w.detail,timestamp:p.timestamp,type:"turn"}));break}case"error":y(at(f,M,{id:it(),toolName:"error",args:Cl(N),timestamp:p.timestamp,type:"error",isError:!0}));break}},v=(p,M)=>{if(p.type==="agent_state_changed"){const w=p.payload.state;w&&(S[M]=w,y(at(f,M,{id:it(),toolName:"state",args:`→ ${w}`,timestamp:p.timestamp,type:"state"})));return}const N=p.payload;switch(p.type){case"tool_call_start":{y(at(f,M,{id:it(),toolName:N.name??"unknown",args:Ho(N.input),timestamp:p.timestamp,type:"tool_start"}));const w=Pl(N.name??"",N.input);w&&y(wo(f,M,[w]));break}case"tool_call_result":{const w=N.result;y(Ha(f,M,N.name??"unknown",!!w?.isError));break}case"response_metadata":El(N)&&!N.estimated&&y(at(f,M,{id:it(),toolName:"llm",args:Ml(N),timestamp:p.timestamp,type:"llm"}));break;case"turn_complete":{const w=_l(N);y(at(f,M,{id:it(),toolName:"turn",args:w.args,detail:w.detail,timestamp:p.timestamp,type:"turn"}));break}case"error":y(at(f,M,{id:it(),toolName:"error",args:Cl(N),timestamp:p.timestamp,type:"error",isError:!0}));break}};for(const p of h)p.kind==="mesh"?b(p.event):p.kind==="agent"?$(p.event,p.filePath):v(p.event,p.filePath);if(Object.keys(m).length>0&&e.setState(m),Object.keys(S).length>0)if(!Object.keys(S).some(kn))t.getState().updateAgentStates(S);else{const p={};for(const[M,N]of Object.entries(S)){const{runtimeId:w,filePath:g}=kn(M)?pr(M):{runtimeId:"local",filePath:M};(p[w]??={})[g]=N}for(const[M,N]of Object.entries(p))t.getState().updateAgentStates(N,M==="local"?void 0:M)}},c=2e3,u=h=>{if(i.push(h),i.length>=c){l&&cancelAnimationFrame(l),d();return}l||(l=requestAnimationFrame(d))};window.adfApi?.onMeshEvent&&a.push(window.adfApi.onMeshEvent(h=>u({kind:"mesh",event:h}))),Wa()?.onAgentEvent&&a.push(Wa().onAgentEvent(h=>{if((h.loop??qa)!==qa)return;const f=Yd();f&&u({kind:"agent",event:h,filePath:f})})),window.adfApi?.onBackgroundAgentEvents&&a.push(window.adfApi.onBackgroundAgentEvents(h=>{for(const f of h){const m=f.payload.filePath;m&&u({kind:"bg",event:f,filePath:m})}}));for(const h of JSON.parse(o)){const f=As(h);a.push(f.onMeshEvent(m=>u({kind:"mesh",event:R1(h,m)}))),a.push(f.onBackgroundAgentEvents(m=>{for(const y of m)y.payload.filePath&&u({kind:"bg",event:y,filePath:da({runtimeId:h,filePath:y.payload.filePath})})}))}return n.current=setInterval(()=>{e.getState().cleanupAnimations()},vd),()=>{a.forEach(h=>h()),l&&(cancelAnimationFrame(l),d()),n.current&&(clearInterval(n.current),n.current=null)}},[r,o])}const H1={meshNode:nb,terrainNode:Ib,terrainLabelNode:ty,stationNode:fy},B1={meshEdge:yb},W1={padding:.3},q1={hideAttribution:!0},V1=[1],X1={width:140,height:90},Y1=5,Al=e=>{const t=e instanceof Element?e:null;return!(!t?.closest(".mesh-graph-flow")||t.closest(".react-flow__panel")||t.closest("[data-map-chrome]"))},Il=[],G1=.16,U1=800,K1=350,Z1=120;function Q1(e,t,n,r){const o=[],a=new Set,i=(h,f)=>{const m=r.map.get(h.id);return m&&m.sig===f?m.edge:(r.map.set(h.id,{sig:f,edge:h}),h)},l=new Map,d=new Set;for(const h of e){if(d.add(h.filePath),kn(h.filePath))continue;const f=Ve(h.filePath).replace(".adf","");f&&l.set(f,h.filePath),l.set(h.handle,h.filePath)}const c=h=>h.startsWith("station:"),u=(h,f)=>h<f?[h,f]:[f,h];for(const h of Object.values(n)){if(!d.has(h.from)&&!c(h.from)||!d.has(h.to)&&!c(h.to))continue;const[f,m]=u(h.from,h.to),y=`${f}-${m}`;a.has(y)||(a.add(y),o.push(i({id:`msg-${y}`,source:f,target:m,type:"meshEdge",data:{edgeType:"message"}},`${f}|${m}|message|`)))}for(const h of e){if(!h.wsConnections)continue;const f=`ws-${h.filePath}`;a.has(f)||(a.add(f),o.push(i({id:f,source:h.filePath,target:"station:web",type:"meshEdge",selectable:!1,data:{edgeType:"channel"}},"channel")))}if(t?.messageLog)for(const h of t.messageLog){if(!h.delivered)continue;const f=l.get(h.from);if(f)for(const m of h.deliveredTo){const y=l.get(m);if(!y)continue;const[S,x]=u(f,y),b=`${S}-${x}`;a.has(b)||(a.add(b),o.push(i({id:`msg-${b}`,source:S,target:x,type:"meshEdge",data:{edgeType:"message",channel:h.channel}},`${S}|${x}|message|${h.channel??""}`)))}}if(r.map.size>o.length){const h=new Set(o.map(f=>f.id));for(const f of r.map.keys())h.has(f)||r.map.delete(f)}return r.last.length===o.length&&o.every((h,f)=>h===r.last[f])?r.last:(r.last=o,o)}const J1=5e3,ew=5*6e4;async function tw(e,t){const n=_t.getState().runtimes;if(n.length<2)return[];const r=n.filter(a=>a.id!=="local"&&a.state==="connected");return(await Promise.all(r.map(async a=>{try{const i=await As(a.id).getMeshMapPoll(e.seq[a.id]??0);return e.seq[a.id]=typeof i.debug?.logSeq=="number"?i.debug.logSeq:0,delete e.errors[a.id],i.fleet.agents.length>0&&(t?.(a.id),ye.getState().setAgents(i.fleet.agents,a.id)),{runtimeId:a.id,burn:i.burn,peers:i.peers??[]}}catch(i){const l=i instanceof Error?i.message:String(i);return e.errors[a.id]!==l&&(e.errors[a.id]=l,ls(`${a.name}: fleet map not updated`,i)),null}}))).filter(a=>a!==null)}async function nw(e,t=Date.now()){const n=_t.getState().runtimes,r=e.didRetry??={},o=n.filter(a=>a.state==="connected"&&!e.dids[a.id]&&(r[a.id]?.at??0)<=t);await Promise.all(o.map(async a=>{const i=()=>{const l=r[a.id]?Math.min(r[a.id].wait*2,ew):J1;r[a.id]={at:t+l,wait:l}};try{const l=await As(a.id).getOwnerIdentityStatus();e.dids[a.id]=l?.runtimeDid||null,e.dids[a.id]?delete r[a.id]:i()}catch(l){r[a.id]||console.warn(`[Fleet] ${a.name}: its runtime DID was not read; read again with backoff:`,l),i()}}))}function rw(){const e=new Map;for(const t of zd.getState().view?.rows??[])t.kind==="saved"&&t.fingerprint&&e.set(t.id,t.fingerprint);return e}function Zu(e,t,n){const r=rw(),o=new Set(t.map(i=>i.id)),a={};for(const i of t)if(i.kind==="remote"){const l=Md(i.url);a[i.id]=l?[l]:[]}else a[i.id]=(e.localHosts??[]).map(l=>$d(l)).filter(l=>!!l);return{dids:Object.fromEntries(Object.entries(e.dids).filter(([i])=>o.has(i))),remotes:t.filter(i=>i.kind==="remote").map(i=>({id:i.id,fingerprint:r.get(i.id)??null})),agentDids:Ed(n),hosts:a}}async function sw(e){try{const t=window.adfApi?.getMeshServerLanIps?.(),n=t?await Promise.race([t,new Promise(r=>setTimeout(()=>r(null),2e3))]):null;n&&(e.localHosts=n.addresses.map(r=>r.address))}catch{}}async function Tl(e,t,n){const r=_t.getState().runtimes;if(r.length<2)return Ba({}),e;await nw(n),await sw(n);const o=Zu(n,r,ve(ye.getState())),a={},i=Bl([e,...t.map(l=>l.peers)],o,(l,d)=>{a[l]=d});return n.learned=a,Ba(a),i}function ow(e,t){const n=J.getState(),r=n.placement;if(!r)return;const o=Hd(e);if(r.regionOrigins[o])return;const a=Object.keys(t).find(l=>t[l]===e&&r.stationPins?.[`station:peer:${l}`]);if(!a)return;const i=r.stationPins[`station:peer:${a}`];n.updatePlacement({},{[o]:{q:i.q,r:i.r}})}function aw(e){if(e.length<2)return;const t=new Map(e.map(n=>[n.id,n]));return{managed:()=>!0,label:n=>{const r=ln(n);if(!r)return;const o=t.get(r);return o?Cd(o):r.replace(/^remote:/,"")},muted:n=>{const r=ln(n);return!!r&&t.get(r)?.state!=="connected"},remote:n=>{const r=ln(n);return!!r&&t.get(r)?.kind!=="local"}}}function Dn(){try{const{edgeHeat:e,liveRoutes:t,peerStreetHeat:n}=pe.getState(),{burn:r,placement:o}=J.getState();if(!o)return;const a=Date.now()-10080*60*1e3,i={},l={};for(const[$,v]of Object.entries(e)){if(v.lastAt<a)continue;i[$]=v;const p=t[$];p&&(l[$]=p)}const d={};for(const[$,v]of Object.entries(n))v.lastAt>=a&&(d[$]=v);const c={};if(r?.perAgent)for(const[$,v]of Object.entries(r.perAgent))v.totalTokens>0&&(c[$]=v.totalTokens);const u=$=>rr($).local,h=rr(c),f=rr(o.regionOrigins),m=rr(o.cellPins),y=rr(o.districtAnchors??{}),S=Date.now(),x={};for(const $ of new Set([...Object.keys(h.remote),...Object.keys(f.remote),...Object.keys(m.remote),...Object.keys(y.remote)]))x[$]={fleetMapState:{burnTotals:h.remote[$]??{},placement:{regionOrigins:f.remote[$]??{},cellPins:m.remote[$]??{},districtAnchors:y.remote[$]??{}},savedAt:S}};const b=f.local===o.regionOrigins&&m.local===o.cellPins&&y.local===(o.districtAnchors??{})?o:{...o,regionOrigins:f.local,cellPins:m.local,...o.districtAnchors?{districtAnchors:y.local}:{}};window.adfApi.setSettings(_d({fleetMapState:{heat:u(i),routes:u(l),streets:d,burnTotals:h.local,placement:b,savedAt:S}},x,_t.getState().runtimes))}catch{}}function Qu(){const[e,t]=k.useState(!1);return k.useEffect(()=>{let n=!0,r=!1;const o=window.adfApi?.onFullscreenChanged?.(a=>{r=!0,t(a)});return window.adfApi?.getFullscreenState?.().then(a=>{n&&!r&&t(a)}),()=>{n=!1,o?.()}},[]),e}function Bo({title:e,shortcut:t,active:n,onClick:r,children:o}){return s.jsx(Wl,{tip:e,shortcut:t,className:"flex",children:s.jsx("button",{onClick:r,"aria-label":e,"aria-current":n?"page":void 0,className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${n?"bg-blue-100 text-blue-600 dark:bg-blue-900/40 dark:text-blue-400":"text-neutral-500 dark:text-neutral-400 hover:bg-neutral-200 dark:hover:bg-neutral-700"}`,children:o})})}function Ju({onHome:e,onSettings:t,onOpenAgent:n,agentCount:r,agentCluster:o,reserveWindowControls:a=!0,children:i}){const l=Qu(),d=window.adfApi?.platform==="darwin",c=Vl(u=>u.filePath!==null);return s.jsxs("div",{"data-map-chrome":"",className:"absolute top-0 left-0 right-0 z-10 h-10 flex items-center justify-between bg-white/80 dark:bg-neutral-900/80 backdrop-blur-sm border-b border-neutral-200 dark:border-neutral-800 select-none",style:{WebkitAppRegion:"drag",paddingLeft:!l&&d?84:"calc(16px + env(titlebar-area-x, 0px))",paddingRight:l||d||!a?16:"calc(16px + max(0px, 100vw - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100vw)))"},children:[s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[s.jsxs("nav",{className:"flex items-center gap-0.5 shrink-0","aria-label":"Application navigation",style:{WebkitAppRegion:"no-drag"},children:[s.jsx(Bo,{title:"Home",shortcut:as(is.home,dr),onClick:e,children:s.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("path",{d:"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"}),s.jsx("polyline",{points:"9 22 9 12 15 12 15 22"})]})}),s.jsx(Bo,{title:"Mesh",shortcut:as(is.fleetMap,dr),active:!0,children:s.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M12 2l8.66 5v10L12 22l-8.66-5V7z"})})}),s.jsx(Bo,{title:"Settings",shortcut:as(is.settings,dr),onClick:t,children:s.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),s.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),s.jsx(Pd,{align:"left"}),c&&s.jsxs(s.Fragment,{children:[s.jsx("span",{"aria-hidden":!0,className:"mx-1 h-3.5 border-l border-neutral-200 dark:border-neutral-800"}),s.jsx(Ad,{active:!1,onClick:n})]})]}),o??s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300 truncate",children:"Mesh"}),r!=null&&s.jsxs("span",{className:"text-xs text-[var(--adf-ui-text-subtle)] shrink-0",children:[r," agent",r!==1?"s":""]})]})]}),s.jsx("div",{className:"flex items-center gap-2 shrink-0",style:{WebkitAppRegion:"no-drag"},children:i})]})}let Rl=null,Dl="";function iw(e){return e!==Rl&&(Rl=e,Dl=e.map(t=>t.filePath).sort().join("|")),Dl}function Mw(){const e=ye(u=>u.enabled),{enableMesh:t}=Sd(),n=gn(u=>u.setShowMeshGraph),r=gn(u=>u.setShowSettings),o=pe(u=>u.reset),a=J(u=>u.reset),i=gn(u=>u.setShowHome),l=k.useCallback(()=>{Dn(),o(),a(),n(!1)},[o,a,n]),d=k.useCallback(()=>{l(),i(!0)},[l,i]),c=k.useCallback(()=>{l(),r(!0)},[l,r]);return e?s.jsx(Cu,{children:s.jsx(pw,{onHome:d,onSettings:c,onOpenAgent:l})}):s.jsxs("div",{className:"relative w-full h-full bg-neutral-50 dark:bg-neutral-950",children:[s.jsx(Ju,{onHome:d,onSettings:c,onOpenAgent:l}),s.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:s.jsxs("div",{className:"text-center space-y-3",children:[s.jsx("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"mx-auto text-[var(--adf-ui-text-subtle)]",children:s.jsx("path",{d:"M12 2l8.66 5v10L12 22l-8.66-5V7z"})}),s.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400",children:"Mesh is not enabled"}),s.jsx("button",{onClick:()=>t(),className:"px-4 py-2 text-sm font-medium text-white bg-green-500 hover:bg-green-600 rounded-lg transition-colors",children:"Enable Mesh"})]})})]})}function lw({pendingCells:e}){const[t,n,r]=we(l=>l.transform),o=J(l=>l.cursorCell);if(!o||e.has(`${o.q},${o.r}`))return null;const{x:a,y:i}=tt(o.q,o.r);return s.jsx("svg",{className:"absolute inset-0 w-full h-full pointer-events-none z-[5]",style:{overflow:"hidden"},children:s.jsx("g",{transform:`translate(${t} ${n}) scale(${r})`,children:s.jsx("polygon",{points:lt(a,i,fe-2),fill:o.agent?"rgba(139,92,246,0.03)":"none",stroke:o.agent?"rgba(139,92,246,0.35)":"rgba(148,163,184,0.45)",strokeWidth:(o.agent?1.75:1.5)/r})})})}function cw(){const[e,t,n]=we(i=>i.transform),r=J(i=>i.dragGhost);if(!r||r.cells.length===0)return null;const o=r.valid?"rgba(139,92,246,0.85)":"rgba(239,68,68,0.9)",a=r.valid?"rgba(139,92,246,0.10)":"rgba(239,68,68,0.14)";return s.jsx("svg",{className:"absolute inset-0 w-full h-full pointer-events-none z-[6]",style:{overflow:"hidden"},children:s.jsx("g",{transform:`translate(${e} ${t}) scale(${n})`,children:r.cells.map(i=>{const{x:l,y:d}=tt(i.q,i.r);return s.jsx("polygon",{points:lt(l,d,fe-2),fill:a,stroke:o,strokeWidth:2.5/n,strokeDasharray:`${10/n} ${6/n}`},`${i.q},${i.r}`)})})})}function uw({site:e,onCancel:t,onFounded:n}){const[r,o,a]=we(M=>M.transform),[i,l]=k.useState(""),[d,c]=k.useState(!1),[u,h]=k.useState(null),f=k.useRef(null);k.useEffect(()=>{const M=N=>{f.current&&!f.current.contains(N.target)&&t()};return window.addEventListener("mousedown",M),()=>window.removeEventListener("mousedown",M)},[t]);const{x:m,y}=tt(e.q,e.r),S=r+m*a,x=o+y*a,b=Ve(e.dir),$=M=>{if(M.includes("/")){const N=M.lastIndexOf("/");return{dir:Sr(e.dir,M.slice(0,N)),agent:M.slice(N+1)}}return e.ocean?{dir:Sr(e.dir,M),agent:M}:{dir:e.dir,agent:M}},v=i.trim()?$(i.trim()):null,p=async()=>{const M=i.trim();if(!M||d)return;const{dir:N,agent:w}=$(M);if(w.trim()){c(!0),h(null);try{const g=await window.adfApi.foundFleetAgent(N,w,e.newRoot);g.success&&g.filePath?n(g.filePath):(h(g.error??"Could not create agent"),c(!1))}catch(g){h(g instanceof Error?g.message:String(g)),c(!1)}}};return s.jsxs("div",{className:"absolute inset-0 pointer-events-none z-[6] overflow-hidden",children:[s.jsx("svg",{className:"absolute inset-0 w-full h-full",children:s.jsx("g",{transform:`translate(${r} ${o}) scale(${a})`,children:s.jsx("polygon",{points:lt(m,y,fe-2),fill:"rgba(139,92,246,0.08)",stroke:"rgba(139,92,246,0.7)",strokeWidth:2.5/a,strokeDasharray:`${10/a} ${6/a}`,style:{animation:"hexPulse 2s ease-in-out infinite"}})})}),s.jsxs("div",{ref:f,className:"absolute w-[300px] pointer-events-auto -translate-x-1/2 rounded-xl bg-white/95 dark:bg-neutral-900/95 backdrop-blur-sm border border-violet-300 dark:border-violet-700 shadow-xl px-3 py-2.5 space-y-1.5",style:{left:S,top:x+fe*a*.95,animation:"meshFadeIn 150ms ease-out"},children:[s.jsx("div",{className:"text-[11px] font-medium text-neutral-600 dark:text-neutral-300",children:e.newRoot?"Create an agent in a new root folder":e.ocean?`Create an agent in a new group near ${b}`:`Create an agent in ${b}`}),s.jsx("input",{autoFocus:!0,type:"text",value:i,onChange:M=>{l(M.target.value),h(null)},onKeyDown:M=>{M.stopPropagation(),M.key==="Enter"&&p(),M.key==="Escape"&&t()},placeholder:e.ocean?"group-name/agent-name":"agent-name",className:"w-full px-2 py-1 text-[12px] rounded-md bg-neutral-100 dark:bg-neutral-800 focus:outline-none focus:ring-1 focus:ring-violet-400 text-neutral-700 dark:text-neutral-200 placeholder:text-[var(--adf-ui-text-subtle)]"}),s.jsx("div",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] truncate",children:u?s.jsx("span",{className:"text-red-500",children:u}):v?`→ ${Ve(v.dir)}/${v.agent}.adf${e.newRoot?" · new tracked folder":""} · Enter to create`:e.newRoot?`New folder beside ${b} — it becomes its own territory`:"Enter creates the agent and opens its chat"}),d&&s.jsx("div",{className:"text-[10px] text-violet-500",children:"Creating…"})]})]})}let os=null;function dw(){return os||(os=Array.from(document.querySelectorAll(".fleet-say-bubble"),e=>e.getBoundingClientRect()),requestAnimationFrame(()=>{os=null})),os}function Ll(e,t){for(const n of dw())if(e>=n.left&&e<=n.right&&t>=n.top&&t<=n.bottom)return!0;return!1}function fw({id:e,x:t,y:n,width:r,height:o,color:a,borderRadius:i,shapeRendering:l}){const d=pe(c=>{for(const u in c.activeAnimationIndex){const h=u.indexOf("|");if(u.slice(0,h)===e||u.slice(h+1)===e)return!0}return!1});return s.jsxs(s.Fragment,{children:[s.jsx("rect",{x:t,y:n,width:r,height:o,fill:a,rx:i,shapeRendering:l}),d&&s.jsx("circle",{cx:t+r/2,cy:n+o/2,r:Math.max(r,o)*.9,fill:"#8b5cf6",opacity:.85,style:{animation:"hexPulse 0.8s ease-in-out infinite"}})]})}function hw(e){return qd(e.target)}function pw({onHome:e,onSettings:t,onOpenAgent:n}){z1();const r=document.documentElement.classList.contains("dark"),[o,a]=k.useState(!0),i=ye(P=>ve(P).length),l=ye(P=>P.setAgents),d=pe(P=>P.showLogDrawer),c=pe(P=>P.setShowLogDrawer),u=pe(P=>P.setFocusedFilePath),h=J(P=>P.setBurn),f=J(P=>P.setSelection),m=J(P=>P.setFamily),y=gn(P=>P.expandRightPanelToTab),S=gn(P=>P.revealRightPanel),x=gn(P=>P.setShowMeshGraph),{openFile:b,closeFile:$}=Id(),v=k.useCallback(P=>{const z=qe(P);return b(z.filePath,z.runtimeId)},[b]),p=Ir(),M=Se(),N=ua(),w=gn(P=>P.rightPanelCollapsed),g=pe(P=>P.seedActivities),[E,T]=k.useState(null),[j,_]=k.useState([]),[I,C]=k.useState([]),O=k.useRef(null),[A,L]=k.useState(null),R=J(P=>P.peerAgentHover),F=J(P=>P.peerReadout),W=J(P=>P.setPeerReadout),G=J(P=>P.readoutDir),Y=J(P=>P.setReadoutDir),ee=J(P=>P.agentReadout),B=J(P=>P.hilModal),Z=J(P=>P.setHilModal),Q=J(P=>P.stationReadout),K=J(P=>P.setStationReadout),U=J(P=>P.setAgentReadout),re=k.useRef(null),ae=k.useRef(null),se=k.useRef(null),le=k.useRef(!1),ie=k.useRef(null),V=k.useCallback(()=>{ie.current&&(clearTimeout(ie.current),ie.current=null),!le.current&&(le.current=!0,se.current?.classList.add("fleet-panning"),re.current&&(clearTimeout(re.current),re.current=null),L(P=>P?.pinned?P:null))},[]),oe=k.useCallback(()=>{ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{ie.current=null,le.current=!1,se.current?.classList.remove("fleet-panning")},250)},[]),de=k.useRef(0),be=Qu(),ke=k.useRef(!1);ke.current=be,k.useEffect(()=>{if(!be)return;const P=28,z=600;let D=0,H=0,q=null;const X=()=>{if(!q){const ge=se.current?.getBoundingClientRect();q={top:se.current?.querySelector("[data-map-chrome]")?.getBoundingClientRect()?.bottom??ge?.top??0,bottom:ge?.bottom??window.innerHeight},requestAnimationFrame(()=>{q=null})}return q},te=ge=>{const{top:Ne,bottom:Ae}=X();if(ge.clientY<Ne||ge.clientY>Ae){D=0,H=0;return}D=ge.clientX<P?1:ge.clientX>window.innerWidth-P?-1:0,H=ge.clientY<Ne+P?1:ge.clientY>Ae-P?-1:0};let ne=0,he=0,me=!1;const xe=ge=>{const Ne=he?Math.min((ge-he)/1e3,.05):0;he=ge;const Ae=D!==0||H!==0;if(Ae){V();const{x:Me,y:kt,zoom:tn}=p.getViewport();p.setViewport({x:Me+D*z*Ne,y:kt+H*z*Ne,zoom:tn})}else me&&oe();me=Ae,ne=requestAnimationFrame(xe)};return window.addEventListener("mousemove",te),ne=requestAnimationFrame(xe),()=>{window.removeEventListener("mousemove",te),cancelAnimationFrame(ne),me&&oe()}},[be,p,V,oe]);const[_e,Te]=k.useState(!1),ze=k.useRef(!1);ze.current=_e;const Xe=200,He=k.useRef(0),Ke=k.useRef({seq:{},errors:{},dids:{}});k.useEffect(()=>Td(Ke.current),[]);const It=k.useRef([]),Be=k.useCallback(async()=>{try{const P=He.current,z=await window.adfApi.getMeshMapPoll(P),D=z.debug,H=z.fleet,q=z.burn,X=z.adapters??{adapters:[]},te=z.peers??[],ne=typeof D?.logSeq=="number"?D.logSeq:0;He.current=ne<P?0:ne,T(Pe=>{if(!D)return Pe;const Ft=D.logIncremental&&P>0&&Pe?{...D,messageLog:[...Pe.messageLog,...D.messageLog].slice(-Xe)}:D;return JSON.stringify(Pe)===JSON.stringify(Ft)?Pe:Ft});const he=X.adapters??[];_(Pe=>JSON.stringify(Pe)===JSON.stringify(he)?Pe:he);const xe=void 0??te??[];H.agents.length>0&&l(H.agents);const ge=Ke.current;_t.getState().runtimes.length>1&&await Tl(xe,It.current,ge);const Ne=await tw(ge,Pe=>ow(Pe,ge.learned??{}));if(It.current=Ne,Ne.length===0)q&&h(q);else{const Pe=Rd(q,Ne.map(Ft=>({runtimeId:Ft.runtimeId,burn:Ft.burn})));Pe&&h(Pe)}const Ae=await Tl(xe,Ne,Ke.current);C(Pe=>JSON.stringify(Pe)===JSON.stringify(Ae)?Pe:Ae);const{starting:Me,clearStarting:kt}=J.getState(),tn=Object.keys(Me);if(tn.length>0){const Pe=new Set(ve(ye.getState()).filter(Nt=>Nt.online).map(Nt=>Nt.filePath)),Ft=Date.now(),qr=tn.filter(Nt=>Pe.has(Nt)||Ft-Me[Nt]>3e4);qr.length>0&&kt(qr)}}catch{}},[l,h]);k.useEffect(()=>(Be().finally(()=>setTimeout(()=>a(!1),350)),O.current=setInterval(Be,5e3),()=>{O.current&&clearInterval(O.current)}),[]);const Ye=J(P=>P.setNamedGroups),ut=J(P=>P.setStewards);k.useEffect(()=>{window.adfApi.getSettings().then(z=>{const D=z;Dd(D.runtimeFleet);const H=D.runtimeFleet&&typeof D.runtimeFleet=="object"?D.runtimeFleet:{},q=Object.keys(H);q.length===0?(D.fleetGroups&&Ye(D.fleetGroups),D.fleetStewards&&ut(D.fleetStewards)):(Ye(Ld(D.fleetGroups??{},H)),ut(Od(D.fleetStewards??{},H)));const X=te=>Object.assign({},...q.map(ne=>Bd(ne,H[ne]?.fleetMapState?.placement?.[te])));(D.fleetMapState?.heat||D.fleetMapState?.streets)&&pe.getState().hydrateGraphState(D.fleetMapState.heat??{},D.fleetMapState.routes??{},D.fleetMapState.streets),J.getState().setPlacement({regionOrigins:q.length===0?D.fleetMapState?.placement?.regionOrigins??{}:{...D.fleetMapState?.placement?.regionOrigins??{},...X("regionOrigins")},cellPins:q.length===0?D.fleetMapState?.placement?.cellPins??{}:{...D.fleetMapState?.placement?.cellPins??{},...X("cellPins")},districtAnchors:q.length===0?D.fleetMapState?.placement?.districtAnchors??{}:{...D.fleetMapState?.placement?.districtAnchors??{},...X("districtAnchors")},stationPins:D.fleetMapState?.placement?.stationPins??{}})}).catch(()=>{J.getState().setPlacement({regionOrigins:{},cellPins:{}})});const P=setInterval(Dn,6e4);return()=>clearInterval(P)},[Ye,ut]);const Tt=pe(P=>P.liveRoutes),rt=pe(P=>P.pendingInteractions),En=ye(P=>ve(P).map(z=>`${z.filePath}|${z.handle}|${z.wsConnections?1:0}`).join(`
|
|
21
|
+
`)),Ys=k.useRef({map:new Map,last:[]}),Gs=k.useMemo(()=>Q1(ve(ye.getState()),E,Tt,Ys.current),[En,E,Tt]),Re=J(P=>P.placement),Dr=J(P=>P.setPlacement),Us=ye(P=>ve(P).map(z=>[z.filePath,z.trackedDirRoot,z.createdAt,z.parentDid,z.did,z.agentId,z.didHistory?.join(","),z.handle,z.icon].join("|")).sort().join(`
|
|
22
|
+
`)),un=_t(P=>P.runtimes),Ee=k.useMemo(()=>{const P=pb(ve(ye.getState()),Re??void 0,aw(un)),z=P.nodes.map(D=>({...D,measured:{width:D.initialWidth,height:D.initialHeight}}));return{...P,nodes:z}},[Us,Re,un]);k.useEffect(()=>{if(!Re)return;const P={...Re.regionOrigins},z={...Re.districtAnchors??{}};let D=!1;for(const[H,q]of Object.entries(Ee.regionOrigins))P[H]||(P[H]=q,D=!0);for(const[H,q]of Object.entries(Ee.districtAnchors))z[H]||(z[H]=q,D=!0);D&&Dr({...Re,regionOrigins:P,districtAnchors:z})},[Ee,Re,Dr]),k.useEffect(()=>{if(!Re)return;const P=setTimeout(Dn,2e3);return()=>clearTimeout(P)},[Re]);const Ks=k.useRef({map:new Map,last:[]}),Gt=k.useMemo(()=>{if(Ee.nodes.length===0)return Il;const P=137.508,z=un.length>1,H=[...z?Bl([I],Zu(Ke.current,un,ve(ye.getState()))):I].sort((ce,je)=>(ce.first_seen??0)-(je.first_seen??0)),q=[...j.map(ce=>({id:`station:${ce.type}`,kind:ce.type,label:ce.type,status:ce.status})),{id:"station:web",kind:"web",label:"internet",status:"running"},...H.map((ce,je)=>({id:`station:peer:${ce.runtime_id}`,kind:"peer",label:(ce.runtime_alias||ce.host||ce.runtime_id).replace(/\.local\.?$/,"").slice(0,18),status:ce.agent_count!=null?`${ce.agent_count} agents`:"directory unreachable",slotDeg:(15+je*P)%360,detail:{host:ce.host,agentCount:ce.agent_count,firstSeen:ce.first_seen,url:ce.url,source:ce.source,ownerAlias:ce.owner_alias,ownerVerified:ce.owner_verified,isSelfOwned:ce.is_self_owned},peerAgents:ce.agents,...z?{peer:!0}:{}}))];let X=1/0,te=-1/0,ne=1/0,he=-1/0;for(const ce of Ee.nodes){if(ce.type!=="terrainNode")continue;const je=ce.data;X=Math.min(X,ce.position.x),te=Math.max(te,ce.position.x+je.width),ne=Math.min(ne,ce.position.y),he=Math.max(he,ce.position.y+je.height)}if(!Number.isFinite(X))return Il;const me={telegram:-90,email:0,discord:90,web:180,imessage:-45,slack:135},xe=$e*2,ge=Math.round((X+te)/2/xe)*xe,Ne=Math.round((ne+he)/2/xe)*xe;let Ae=0,Me=0,kt=0;for(const ce of Ee.nodes)ce.type==="meshNode"&&(Ae+=ce.position.x+jt/2,Me+=ce.position.y+qt/2,kt++);kt>0?(Ae/=kt,Me/=kt):(Ae=ge,Me=Ne);const tn=Math.ceil(((te-X)/2+$e*3.4)/xe)*xe,Pe=Math.ceil(((he-ne)/2+$e*3.4)/xe)*xe,Ft=Re?.stationPins??{},qr=q.map((ce,je)=>{const De=Ft[ce.id],Ht=(ce.slotDeg??me[ce.kind]??je*67%360)*Math.PI/180,hn=ge+tn*Math.cos(Ht),Vr=Ne+Pe*Math.sin(Ht),Xr=De?{q:De.q,r:De.r}:ft(hn,Vr);return{id:ce.id,cell:Xr,priority:De?De.auto?1:0:2}}),Nt=[],Ia=new Map;for(const ce of[...qr].sort((je,De)=>je.priority-De.priority)){let je=ce.cell;if(Nt.some(De=>$s(je.q,je.r,De.q,De.r)<5))for(const[De,tr]of $n(600)){const Ht={q:ce.cell.q+De,r:ce.cell.r+tr};if(Nt.every(hn=>$s(Ht.q,Ht.r,hn.q,hn.r)>=5)){je=Ht;break}}Nt.push(je),Ia.set(ce.id,je)}const id=q.map(ce=>{const{q:je,r:De}=Ia.get(ce.id),{x:tr,y:Ht}=tt(je,De),hn=Ae-tr,Vr=Me-Ht,Xr=Math.hypot(hn,Vr)||1;let Ta=0,Ra=-1/0;for(let nr=0;nr<6;nr++){const bo=_s(-1,1,nr),yo=_s(1,0,nr),Da=(bo.q+yo.q)/2*(fe*1.5),La=(bo.r+bo.q/2+yo.r+yo.q/2)/2*$e,Oa=Math.hypot(Da,La)||1,Fa=Da/Oa*(hn/Xr)+La/Oa*(Vr/Xr);Fa>Ra&&(Ra=Fa,Ta=nr)}return{id:ce.id,type:"stationNode",position:{x:tr-Mt/2,y:Ht-$t/2},draggable:!0,dragHandle:".station-drag-handle",selectable:!1,focusable:!1,initialWidth:Mt,initialHeight:$t,measured:{width:Mt,height:$t},data:{kind:ce.kind,label:ce.label,status:ce.status,facing:Ta,detail:ce.detail,peerAgents:ce.peerAgents,...ce.peer?{peer:!0}:{}}}}),zt=Ks.current,Tn=id.map(ce=>{const je=JSON.stringify([ce.position,ce.data]),De=zt.map.get(ce.id);return De&&De.sig===je?De.node:(zt.map.set(ce.id,{sig:je,node:ce}),ce)});if(zt.map.size>Tn.length){const ce=new Set(Tn.map(je=>je.id));for(const je of zt.map.keys())ce.has(je)||zt.map.delete(je)}return zt.last.length===Tn.length&&Tn.every((ce,je)=>ce===zt.last[je])?zt.last:(zt.last=Tn,Tn)},[Ee,j,I,Re,un]);k.useEffect(()=>{if(!Re)return;const P={};for(const z of Gt){if(Re.stationPins?.[z.id])continue;const D=ft(z.position.x+Mt/2,z.position.y+$t/2);P[z.id]={q:D.q,r:D.r,auto:!0}}Object.keys(P).length>0&&J.getState().updatePlacement({},void 0,void 0,P)},[Gt,Re]);const st=k.useMemo(()=>{const P=new Map(ve(ye.getState()).map(H=>[H.filePath,H])),z=pe.getState().pendingInteractions;return[...Ee.nodes.map(H=>{let q=H;if(H.type==="meshNode"){const X=P.get(H.id),te=H.data;X&&(te.state!==X.state||te.status!==X.status||te.online!==X.online||te.servedUrl!==X.servedUrl||te.model!==X.model)&&(q={...H,data:{...H.data,state:X.state,status:X.status,online:X.online,servedUrl:X.servedUrl,model:X.model}})}return z[q.id]?{...q,zIndex:100}:q}),...Gt]},[Ee,Gt]),Zs=k.useMemo(()=>{if(st.length===0)return;let P=1/0,z=1/0,D=-1/0,H=-1/0;for(const X of st)P=Math.min(P,X.position.x),z=Math.min(z,X.position.y),D=Math.max(D,X.position.x+(X.width??jt)),H=Math.max(H,X.position.y+(X.height??qt));const q=$e*4;return[[P-q,z-q],[D+q,H+q]]},[st]),Gn=k.useRef({active:!0,deadline:0});k.useEffect(()=>{Gn.current.deadline=Date.now()+1e4;const P=()=>{Gn.current.active=!1};return window.addEventListener("pointerdown",P,!0),window.addEventListener("wheel",P,{capture:!0,passive:!0}),window.addEventListener("keydown",P,!0),()=>{window.removeEventListener("pointerdown",P,!0),window.removeEventListener("wheel",P,!0),window.removeEventListener("keydown",P,!0)}},[]),k.useEffect(()=>{const P=Gn.current;if(!P.active||Date.now()>P.deadline||!Re||Ee.nodes.length===0)return;let z=!1,D=0;const H=()=>{if(z||!P.active)return;if(p.getNodes().some(te=>(te.type==="terrainNode"||te.type==="meshNode")&&(te.measured?.width??te.width)!=null)){p.fitView({padding:.3});return}++D<600&&requestAnimationFrame(H)},q=setTimeout(()=>requestAnimationFrame(H),350);return()=>{z=!0,clearTimeout(q)}},[Ee,Re,p]);const Qs=ye(P=>ve(P).map(z=>`${z.filePath}|${z.state}|${z.online===!1?0:1}`).join(`
|
|
23
|
+
`)),Js=k.useMemo(()=>{const P=new Map(ve(ye.getState()).map(D=>[D.filePath,D])),z=[];for(const D of st){if(D.type!=="meshNode")continue;const H=P.get(D.id),q=D.data;z.push({x:D.position.x+jt/2,y:D.position.y+qt/2,state:H?.state??q.state??"off",online:(H?H.online:q.online)!==!1,filePath:D.id})}return z},[st,Qs]),eo=k.useMemo(()=>{const P=[];for(const z of Ee.nodes){if(z.type!=="terrainNode")continue;const D=z.data;P.push({dirPath:D.dirPath,x:z.position.x,y:z.position.y,cells:D.cells,districts:D.districts,memberPaths:D.members.map(H=>H.filePath)})}return P},[Ee]),Ut=k.useMemo(()=>{const P=new Set;for(const z of Ee.nodes){if(z.type!=="meshNode")continue;const{q:D,r:H}=ft(z.position.x+jt/2,z.position.y+qt/2);P.add(`${D},${H}`)}return P},[Ee]),to=k.useMemo(()=>{const P=new Set;for(const z of Ee.nodes){if(z.type!=="meshNode"||!rt[z.id])continue;const{q:D,r:H}=ft(z.position.x+jt/2,z.position.y+qt/2);P.add(`${D},${H}`)}return P},[Ee,rt]),Cn=k.useMemo(()=>{const P=new Map,z=new Set,D=[];for(const H of Ee.nodes){if(H.type!=="terrainNode")continue;const q=H.data;if(!q.dirPath)continue;const X=ln(q.dirPath)!==null,te=[];for(const ne of q.cells){const he=H.position.x+ne.x,me=H.position.y+ne.y;te.push({x:he,y:me});const{q:xe,r:ge}=ft(he,me);if(X){z.add(`${xe},${ge}`);continue}P.set(`${xe},${ge}`,ne.district?`${q.dirPath}/${ne.district}`:q.dirPath)}X||D.push({rootDir:q.dirPath,pts:te})}return{dirs:P,roots:D,blocked:z}},[Ee]),[Rt,Kt]=k.useState(null),Lr=k.useRef(!1);Lr.current=!!Rt;const no=k.useCallback(P=>{const z=P.target;if(z.closest(".react-flow__node")||!z.closest(".react-flow__pane"))return;const D=p.screenToFlowPosition({x:P.clientX,y:P.clientY}),{q:H,r:q}=ft(D.x,D.y),X=`${H},${q}`;if(Ut.has(X)||Cn.blocked.has(X))return;const te=Cn.dirs.get(X);if(te){Kt({q:H,r:q,dir:te,ocean:!1});return}let ne=null,he=1/0;for(const xe of Cn.roots)for(const ge of xe.pts){const Ne=Math.hypot(ge.x-D.x,ge.y-D.y);Ne<he&&(he=Ne,ne=xe.rootDir)}if(!ne)return;const me=$e*3.5;if(he>me){const xe=jr(ne);xe&&Kt({q:H,r:q,dir:xe,ocean:!0,newRoot:!0})}else Kt({q:H,r:q,dir:ne,ocean:!0})},[p,Ut,Cn]),ro=k.useCallback(async P=>{Rt&&(J.getState().pinCell(P,{q:Rt.q,r:Rt.r}),Dn()),Kt(null),Be(),x(!1),await v(P),y("loop")},[Rt,Be,v,y,x]),so=k.useCallback(P=>{const z=P.target,D=!!z.closest(".react-flow__pane")||!!z.closest(".react-flow__node"),{clientX:H,clientY:q}=P;cancelAnimationFrame(de.current),de.current=requestAnimationFrame(()=>{if(!D||Ll(H,q)){J.getState().setCursorCell(null);return}const X=p.screenToFlowPosition({x:H,y:q}),{q:te,r:ne}=ft(X.x,X.y),he=Ut.has(`${te},${ne}`);J.getState().setCursorCell({q:te,r:ne,agent:he})})},[p,Ut]),Un=Gs,[oo,Dt]=k.useState(st),[ao,Or]=k.useState(Un),yt=k.useCallback(()=>{const P=new Map(ve(ye.getState()).map(D=>[D.filePath,D])),z=pe.getState().pendingInteractions;Dt(D=>{let H=null;for(let q=0;q<D.length;q++){const X=D[q];if(X.type!=="meshNode")continue;const te=P.get(X.id),ne=X.data,he=z[X.id]?100:void 0,me=!!te&&(ne.state!==te.state||ne.status!==te.status||ne.online!==te.online||ne.servedUrl!==te.servedUrl||ne.model!==te.model);!me&&X.zIndex===he||(H||(H=[...D]),H[q]={...X,zIndex:he,data:me&&te?{...X.data,state:te.state,status:te.status,online:te.online,servedUrl:te.servedUrl,model:te.model}:X.data})}return H??D})},[]),Lt=k.useCallback(()=>{if(Zt.current)return;const{transform:P,width:z,height:D}=M.getState(),[H,q,X]=P;if(z<=0||D<=0||X<=0)return;const te=Math.max(U1,K1/X),ne=-H/X-te,he=-q/X-te,me=(z-H)/X+te,xe=(D-q)/X+te;Dt(ge=>{let Ne=null;for(let Ae=0;Ae<ge.length;Ae++){const Me=ge[Ae],kt=Me.initialWidth??jt,tn=Me.initialHeight??qt,Pe=Me.position.x+kt<ne||Me.position.x>me||Me.position.y+tn<he||Me.position.y>xe;Pe!==(Me.data.culled??!1)&&(Ne||(Ne=[...ge]),Ne[Ae]={...Me,data:{...Me.data,culled:Pe}})}return Ne??ge})},[M]),Fr=ye(P=>iw(ve(P)));k.useEffect(()=>{Zt.current||(Dt(P=>{const z=new Set(P.filter(D=>D.selected).map(D=>D.id));return st.map(D=>z.has(D.id)?{...D,selected:!0}:D)}),yt(),Lt())},[st,yt,Lt]),k.useEffect(()=>{Or(Un)},[Un]),k.useEffect(()=>{const P=ye.subscribe((D,H)=>{(D.agents!==H.agents||D.byRuntime!==H.byRuntime)&&yt()}),z=pe.subscribe((D,H)=>{D.pendingInteractions!==H.pendingInteractions&&yt()});return()=>{P(),z()}},[yt]),k.useEffect(()=>{let P=0,z=null;const D=()=>{P=performance.now(),Lt()},H=M.subscribe((q,X)=>{if(q.transform===X.transform&&q.width===X.width&&q.height===X.height||z)return;const te=Z1-(performance.now()-P);if(te<=0){D();return}z=setTimeout(()=>{z=null,D()},te)});return D(),()=>{H(),z&&clearTimeout(z)}},[M,Lt]),k.useEffect(()=>{let P=!1;return window.adfApi.getMeshRecentTools?.().then(z=>{if(P||!z)return;const D={};let H=0;for(const[q,X]of Object.entries(z))D[q]=X.map(te=>({id:`seed-${++H}`,toolName:te.name,args:te.args,timestamp:te.timestamp,type:"tool_start",isError:te.isError}));g(D)}).catch(()=>{}),()=>{P=!0}},[g,Fr]);const io=k.useCallback(P=>{const z=P.filter(D=>D.type!=="dimensions");z.length!==0&&Dt(D=>ru(z,D))},[]),ot=k.useCallback(P=>{J.getState().setDragGhost(P)},[]),Zt=k.useRef(!1),_n=k.useRef(0),Qt=k.useCallback(P=>ft(P.position.x+jt/2,P.position.y+qt/2),[]),Le=k.useCallback(P=>{const z=Ee.nodes.find(D=>D.id===P&&D.type==="meshNode");return z?Qt(z):null},[Ee,Qt]),Kn=P=>P.metaKey||P.ctrlKey?"territory":P.altKey?"district":"agents",Jt=k.useCallback((P,z,D)=>{const H=ve(ye.getState()),q=H.find(te=>te.filePath===z);if(!q)return[];const X=q.trackedDirRoot??"";if(P==="territory")return H.filter(te=>(te.trackedDirRoot??"")===X).map(te=>te.filePath);if(P==="district"){const te=ps(z,X);return H.filter(ne=>(ne.trackedDirRoot??"")===X&&ps(ne.filePath,X)===te).map(ne=>ne.filePath)}return D&&D.length>1&&D.includes(z)?D:[z]},[]),en=k.useCallback((P,z,D)=>{const H=[];for(const q of P){const X=Le(q);X&&H.push({q:X.q+z,r:X.r+D})}return H},[Le]),wt=k.useCallback((P,z,D)=>{const H=new Set,q=[];for(const X of P){const te=Le(X);te&&(q.push(te),H.add(`${te.q},${te.r}`))}for(const X of q){const te=`${X.q+z},${X.r+D}`;if(Ut.has(te)&&!H.has(te))return!1}return!0},[Le,Ut]),Pn=k.useCallback((P,z,D,H,q)=>{const X=J.getState();if(!X.placement)return!1;const te=X.placement.cellPins,ne={};for(const xe of D){const ge=te[xe];ge&&(ne[xe]={...ge,q:ge.q+H,r:ge.r+q})}const me=ve(ye.getState()).find(xe=>xe.filePath===z)?.trackedDirRoot??"";if(P==="territory"){const xe=X.placement.regionOrigins[me];if(!xe)return!1;X.updatePlacement(ne,{[me]:{q:xe.q+H,r:xe.r+q}})}else if(P==="district"){const xe=`${me}::${ps(z,me)}`,ge=X.placement.districtAnchors?.[xe];if(!ge)return!1;X.updatePlacement(ne,void 0,{[xe]:{q:ge.q+H,r:ge.r+q}})}else{for(const xe of D){const ge=Le(xe);ge&&(ne[xe]={q:ge.q+H,r:ge.r+q,solo:!0})}X.updatePlacement(ne)}return Dn(),!0},[Le]),zr=k.useCallback(()=>{Zt.current=!1,cancelAnimationFrame(_n.current),ot(null)},[]),lo=k.useCallback(()=>{Zt.current=!0,re.current&&(clearTimeout(re.current),re.current=null),L(P=>P?.pinned?P:null)},[]),co=k.useCallback((P,z,D)=>{if(cancelAnimationFrame(_n.current),z.type==="stationNode"){const X=ft(z.position.x+Mt/2,z.position.y+$t/2);_n.current=requestAnimationFrame(()=>ot({cells:[X],valid:!0}));return}if(z.type!=="meshNode")return;const H=Kn(P),q=D?.filter(X=>X.type==="meshNode").map(X=>X.id);_n.current=requestAnimationFrame(()=>{const X=Le(z.id);if(!X)return;const te=Qt(z),ne=te.q-X.q,he=te.r-X.r,me=Jt(H,z.id,q);ot({cells:en(me,ne,he),valid:wt(me,ne,he)})})},[Le,Qt,Jt,en,wt]),Hr=k.useCallback((P,z,D)=>{zr();const H=()=>{Dt(Ne=>{const Ae=new Set(Ne.filter(Me=>Me.selected).map(Me=>Me.id));return st.map(Me=>Ae.has(Me.id)?{...Me,selected:!0}:Me)}),yt(),Lt()},q=J.getState();if(!q.placement)return H();if(z.type==="stationNode"){const Ne=ft(z.position.x+Mt/2,z.position.y+$t/2);q.updatePlacement({},void 0,void 0,{[z.id]:Ne}),Dn();return}if(z.type!=="meshNode")return H();const X=Le(z.id);if(!X)return H();const te=Qt(z);if(te.q===X.q&&te.r===X.r)return H();const ne=te.q-X.q,he=te.r-X.r,me=Kn(P),xe=D?.filter(Ne=>Ne.type==="meshNode").map(Ne=>Ne.id),ge=Jt(me,z.id,xe);if(ge.length===0||!wt(ge,ne,he))return ot({cells:en(ge,ne,he),valid:!1}),window.setTimeout(()=>ot(null),400),H();if(!Pn(me,z.id,ge,ne,he))return H()},[zr,st,yt,Lt,Le,Qt,Jt,en,wt,Pn,ot]),An=J(P=>P.moveMode),[Oe,Br]=k.useState(null);k.useEffect(()=>{if(!An){Br(null);return}const P=J.getState().selection[0];if(!P){J.getState().setMoveMode(null);return}Br({kind:An.kind,members:Jt(An.kind,P,J.getState().selection),lead:P})},[An,Jt]),k.useEffect(()=>{if(!Oe){ot(null);return}const P=D=>{if(!D)return;const H=Le(Oe.lead);if(!H){J.getState().setMoveMode(null);return}const q=D.q-H.q,X=D.r-H.r;ot({cells:en(Oe.members,q,X),valid:wt(Oe.members,q,X)})};P(J.getState().cursorCell);const z=J.subscribe((D,H)=>{D.cursorCell!==H.cursorCell&&P(D.cursorCell)});return()=>{z(),ot(null)}},[Oe,Le,en,wt,ot]);const uo=k.useCallback(()=>{Ze.current&&(clearTimeout(Ze.current),Ze.current=null);const P=J.getState().cursorCell;if(!Oe||!P)return;const z=Le(Oe.lead);if(!z){J.getState().setMoveMode(null);return}const D=P.q-z.q,H=P.r-z.r;(D!==0||H!==0)&&wt(Oe.members,D,H)&&Pn(Oe.kind,Oe.lead,Oe.members,D,H),J.getState().setMoveMode(null)},[Oe,Le,wt,Pn]),vt=k.useCallback(()=>{ae.current&&(clearTimeout(ae.current),ae.current=null)},[]),In=k.useCallback(()=>{vt(),ae.current=setTimeout(()=>{ae.current=null,L(P=>P?.pinned?P:null)},260)},[vt]),fo=k.useCallback((P,z)=>{if(z.type!=="meshNode"&&z.type!=="stationNode"||Zt.current||Oe||le.current||Ll(P.clientX,P.clientY))return;vt(),re.current&&clearTimeout(re.current);const D=P.clientX,H=P.clientY;re.current=setTimeout(()=>{Zt.current||le.current||L(q=>q?.pinned?q:{filePath:z.id,x:D,y:H})},550)},[vt,Oe]),ho=k.useCallback(()=>{re.current&&(clearTimeout(re.current),re.current=null),In()},[In]),Ze=k.useRef(null),po=k.useCallback((P,z)=>{if(z.type==="meshNode"){pe.getState().pendingInteractions[z.id]?.type==="approval"&&p.getViewport().zoom<.45&&(Ze.current&&clearTimeout(Ze.current),Ze.current=setTimeout(()=>{Ze.current=null,J.getState().setHilModal(z.id)},300));return}if(z.type==="stationNode"){if(J.getState().setSelectedStation(z.id),z.id.startsWith("station:peer:")){L(null),J.getState().setStationReadout(z.id);return}L({filePath:z.id,x:P.clientX,y:P.clientY,pinned:!0})}},[p]),Wr=k.useCallback(P=>{Or(z=>su(P,z))},[]),xo=k.useCallback(({nodes:P})=>{const z=P.filter(D=>D.type==="meshNode").map(D=>D.id).sort();f(z)},[f]),go=k.useCallback(P=>{if(!P.shiftKey||P.button!==0)return;const D=P.target.closest(".react-flow__node")?.getAttribute("data-id");if(!D||D.startsWith("terrain:"))return;P.preventDefault(),P.stopPropagation();const H=new Set(J.getState().selection);H.has(D)?H.delete(D):H.add(D),Dt(q=>q.map(X=>{if(X.type!=="meshNode")return X;const te=H.has(X.id);return(X.selected??!1)===te?X:{...X,selected:te}})),f([...H].sort())},[f]),Zn=k.useCallback(P=>{const D=P.target.closest(".react-flow__node")?.getAttribute("data-id");!D?.startsWith("station:")&&!P.target.closest("[data-station-card]")&&(L(H=>H?.pinned?null:H),J.getState().setSelectedStation(null)),P.shiftKey&&(!D||D.startsWith("terrain:")||(P.preventDefault(),P.stopPropagation()))},[]),Qn=J(P=>P.selection),Jn=pe(P=>P.focusedFilePath);k.useEffect(()=>{const P=Jn?[...Qn,Jn]:Qn;if(P.length===0){m([]);return}const z=new Set;for(const D of P){const H=Ee.lineage.parents.get(D);H&&z.add(H);for(const q of Ee.lineage.children.get(D)??[])z.add(q)}for(const D of P)z.delete(D);m([...z].sort())},[Qn,Jn,Ee,m]);const dn=k.useCallback((P,z,D)=>{const{height:H}=M.getState(),q=(H||window.innerHeight)/z*G1;p.setCenter(P.position.x+jt/2,P.position.y+140-q,{zoom:z,duration:D})},[p,M]),fn=k.useCallback((P,z)=>{if(P.length===1){const D=p.getNode(P[0]);if(!D)return;const{width:H,height:q,minZoom:X,maxZoom:te}=M.getState(),{zoom:ne}=zs(p.getNodesBounds([D.id]),H,q,X,te,.35);dn(D,ne,z);return}p.fitView({nodes:P.map(D=>({id:D})),duration:z,padding:.35})},[p,M,dn]),dt=k.useCallback((P,z)=>{const D=new Set(P);Dt(H=>H.map(q=>{const X=D.has(q.id);return(q.selected??!1)===X?q:{...q,selected:X}})),f([...P].sort()),P.length>0&&(z?.center??!0)&&fn(P,300)},[fn,f]),ed=k.useCallback((P,z)=>{const D=z.data;if(!(z.type!=="meshNode"||!D?.filePath)){if(Ze.current&&(clearTimeout(Ze.current),Ze.current=null),P.metaKey||P.ctrlKey){const H=ve(ye.getState()),q=H.find(te=>te.filePath===D.filePath);if(!q)return;const X=H.filter(te=>te.online===q.online&&(!q.online||te.state===q.state)).map(te=>te.filePath);dt(X,{center:!1});return}v(D.filePath),S()}},[v,S,dt]),er=k.useRef(null),td=k.useCallback(P=>{if(P.button!==2||er.current||!Al(P.target))return;const z=P.target.closest(".react-flow__node-meshNode")?.getAttribute("data-id")??null,D={pointerId:P.pointerId,startX:P.clientX,startY:P.clientY,lastX:P.clientX,lastY:P.clientY,panning:!1},H=ne=>{if(ne.pointerId!==D.pointerId)return;if(!D.panning){if(Math.hypot(ne.clientX-D.startX,ne.clientY-D.startY)<Y1)return;D.panning=!0,V();try{se.current?.setPointerCapture(D.pointerId)}catch{}se.current&&(se.current.style.cursor="grabbing"),D.lastX=D.startX,D.lastY=D.startY}const he=ne.clientX-D.lastX,me=ne.clientY-D.lastY;D.lastX=ne.clientX,D.lastY=ne.clientY,(he!==0||me!==0)&&M.getState().panBy({x:he,y:me})},q=(ne,he)=>{if(ne.pointerId===D.pointerId){if(er.current?.cleanup(),er.current=null,D.panning){try{se.current?.releasePointerCapture(D.pointerId)}catch{}se.current&&(se.current.style.cursor=""),oe();return}he||!z||(dt([z],{center:!1}),J.getState().setComposerOpen(!0))}},X=ne=>q(ne,!1),te=ne=>q(ne,!0);window.addEventListener("pointermove",H),window.addEventListener("pointerup",X),window.addEventListener("pointercancel",te),er.current={pointerId:D.pointerId,cleanup:()=>{window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",X),window.removeEventListener("pointercancel",te)}}},[M,dt,V,oe]),nd=k.useCallback(P=>{Al(P.target)&&(P.preventDefault(),P.stopPropagation())},[]);k.useEffect(()=>()=>{er.current?.cleanup()},[]);const Ot=k.useCallback(P=>{const z=p.getNode(P);z&&(u(P),dn(z,1,400))},[p,u,dn]),rd=k.useCallback(P=>{v(P),S()},[v,S]),sd=k.useCallback(P=>{fn(P,350)},[fn]),od=k.useCallback(P=>{const z=new Set(ve(ye.getState()).map(D=>D.filePath));dt(P.filter(D=>z.has(D)))},[dt]),mo=k.useRef({}),Aa=k.useRef(null);k.useEffect(()=>{const P=(H,q)=>{if(q.length===0)return;const X=((mo.current[H]??-1)+1)%q.length;mo.current[H]=X,Ot(q[X]),dt([q[X]],{center:!1})},z=H=>{const q=se.current,X=document.activeElement;!q||!q.contains(H.target)||X&&X!==document.body&&!q.contains(X)&&X.blur()},D=H=>{if(hw(H)||H.altKey||!Wd(H.target,se.current,document))return;const q=J.getState(),X=H.code?.startsWith("Digit")?H.code.slice(5):"";if(X>="1"&&X<="9"){if(H.metaKey||H.ctrlKey)q.selection.length>0&&(H.preventDefault(),q.assignControlGroup(X,q.selection));else if(H.shiftKey){if(q.selection.length>0){H.preventDefault();const ne=[...new Set([...q.controlGroups[X]??[],...q.selection])];q.assignControlGroup(X,ne)}}else{const ne=q.controlGroups[X];if(ne&&ne.length>0){H.preventDefault(),dt(ne,{center:!1});const he=Date.now(),me=Aa.current;me&&me.digit===X&&he-me.at<450&&fn(ne,300),Aa.current={digit:X,at:he}}}return}if(H.metaKey||H.ctrlKey)return;const te=pe.getState();if(H.key==="?")H.preventDefault(),Te(ne=>!ne);else if(H.key==="l"||H.key==="L")H.preventDefault(),q.cycleLens();else if(H.key==="f"||H.key==="F")H.preventDefault(),window.adfApi?.setFullscreen?.(!ke.current);else if(H.key==="v"||H.key==="V"){H.preventDefault();const ne=q.voicesOverride??q.lens==="terrain";q.setVoicesOverride(!ne)}else if(H.key.startsWith("Arrow")){H.preventDefault();const{x:ne,y:he,zoom:me}=p.getViewport(),xe=180,ge=H.key==="ArrowLeft"?xe:H.key==="ArrowRight"?-xe:0,Ne=H.key==="ArrowUp"?xe:H.key==="ArrowDown"?-xe:0;p.setViewport({x:ne+ge,y:he+Ne,zoom:me},{duration:120})}else if(H.key==="+"||H.key==="="||H.key==="-")H.preventDefault(),H.key==="-"?p.zoomOut({duration:120}):p.zoomIn({duration:120});else if(H.key==="m"||H.key==="M")q.selection.length>0&&(H.preventDefault(),q.setComposerOpen(!0));else if(H.key==="a"||H.key==="A")H.preventDefault(),dt(ve(ye.getState()).filter(ne=>ne.online).map(ne=>ne.filePath),{center:!1});else if(H.key===" ")H.preventDefault(),q.selection.length>0?fn(q.selection,300):p.fitView({duration:300,padding:.3});else if(H.key==="g"||H.key==="G"){const ne=new Set(q.selection),he=ve(ye.getState()).filter(me=>ne.has(me.filePath)&&!me.online);if(he.length>0){H.preventDefault(),J.getState().markStarting(he.map(me=>me.filePath));for(const me of he){const xe=qe(me.filePath);xe.api.startBackgroundAgent(xe.filePath).catch(()=>{})}}}else if(H.key==="s"||H.key==="S"){const ne=new Set(q.selection),he=ve(ye.getState()).filter(me=>ne.has(me.filePath)&&me.online);if(H.shiftKey&&he.length>0){H.preventDefault();for(const me of he)Hl(me.filePath).catch(()=>{})}}else if(H.key==="."){H.preventDefault();const ne=Object.keys(te.pendingInteractions).sort();P("pending",ne),q.hilModal&&ne.length>0&&q.setHilModal(ne[mo.current.pending])}else if(H.key===","){H.preventDefault();const ne=ve(ye.getState()).filter(he=>he.state==="idle").map(he=>he.filePath).sort();P("idle",ne)}else if(H.key==="Enter"&&te.focusedFilePath)H.preventDefault(),v(te.focusedFilePath),S();else if(H.key==="i"||H.key==="I"){const ne=te.focusedFilePath??(q.selection.length===1?q.selection[0]:null);ne&&(H.preventDefault(),q.setAgentReadout(ne))}else if(H.key==="Escape"){if(Lr.current){Kt(null);return}if(q.moveMode){q.setMoveMode(null);return}if(ze.current){Te(!1);return}if(ke.current){window.adfApi?.setFullscreen?.(!1);return}te.setFocusedFilePath(null),dt([]),q.setSelectedStation(null)}};return window.addEventListener("keydown",D),window.addEventListener("pointerdown",z,!0),()=>{window.removeEventListener("keydown",D),window.removeEventListener("pointerdown",z,!0)}},[Ot,v,S,dt,fn,p]);const ad=k.useCallback(P=>{if(P.type==="terrainNode"||P.type==="terrainLabelNode")return"transparent";if(P.type==="stationNode")return"#94a3b8";const z=P.data;return z?.filePath&&pe.getState().pendingInteractions[z.filePath]?"#f59e0b":z?.online===!1?"#d4d4d8":z?.state==="active"?"#facc15":z?.state==="idle"?"#4ade80":z?.state==="error"?"#f87171":"#94a3b8"},[]);return s.jsx("div",{className:"flex relative w-full h-full",children:s.jsxs("div",{ref:se,className:"relative flex-1 min-w-0 overflow-hidden bg-neutral-50 dark:bg-neutral-950",onMouseDownCapture:go,onPointerDownCapture:td,onContextMenuCapture:nd,onClickCapture:Zn,onDoubleClick:no,onMouseMove:so,onMouseLeave:()=>J.getState().setCursorCell(null),children:[s.jsx(Ju,{onHome:e,onSettings:t,onOpenAgent:n,agentCount:i,reserveWindowControls:!N||w,agentCluster:N?s.jsx(Fd,{avatar:!1,onActivate:()=>Ot(N)}):void 0,children:N&&s.jsx(Wl,{tip:"Close agent",shortcut:as(is.closeAgent,dr),className:"flex",children:s.jsx("button",{onClick:()=>$(),"aria-label":"Close agent",className:"p-1 text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-200",children:s.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:s.jsx("path",{d:"M18 6L6 18M6 6l12 12"})})})})}),s.jsx(zb,{onFocusAgent:Ot,onSelectGroup:od}),s.jsxs("div",{className:"absolute left-3 top-[4.7rem] z-10 w-[280px] flex flex-col gap-2 pointer-events-none",children:[s.jsx(Gy,{onFocusAgent:Ot}),s.jsx(Yb,{onFocusAgent:Ot}),s.jsx(Jy,{onFocusAgent:Ot})]}),s.jsx(py,{foreignHubs:I.map(P=>({runtimeId:P.runtime_id,label:(P.runtime_alias||P.host||P.runtime_id).replace(/\.local\.?$/,"")}))}),s.jsx(lw,{pendingCells:to}),s.jsx(cw,{}),_e&&s.jsx(by,{onClose:()=>Te(!1)}),Rt&&s.jsx(uw,{site:Rt,onCancel:()=>Kt(null),onFounded:ro}),s.jsxs(vm,{nodes:oo,edges:ao,onNodesChange:io,onEdgesChange:Wr,onNodeDoubleClick:ed,onSelectionChange:xo,onNodeMouseEnter:fo,onNodeMouseLeave:ho,onNodeClick:po,onNodeDragStart:lo,onNodeDrag:co,onNodeDragStop:Hr,onPaneClick:uo,onMoveStart:V,onMoveEnd:oe,nodeTypes:H1,edgeTypes:B1,nodesDraggable:!1,selectionOnDrag:!0,selectionKeyCode:null,zoomOnDoubleClick:!1,panOnDrag:V1,panOnScroll:!0,zoomOnScroll:!1,zoomOnPinch:!0,fitView:!0,fitViewOptions:W1,proOptions:q1,minZoom:.06,maxZoom:2,translateExtent:Zs,className:"mesh-graph-flow",children:[s.jsx(Vm,{zoomable:!0,pannable:!0,position:"bottom-right",style:X1,nodeColor:ad,nodeComponent:fw,bgColor:r?"#171717":void 0,maskColor:r?"rgba(64, 64, 64, 0.6)":void 0}),s.jsx(Fb,{}),s.jsx(j1,{}),s.jsxs(Am,{position:"bottom-left",showInteractive:!1,className:"!bg-white dark:!bg-neutral-900 !border-neutral-300 dark:!border-neutral-700 !shadow-sm [&>button]:!bg-white dark:[&>button]:!bg-neutral-900 [&>button]:!border-neutral-300 dark:[&>button]:!border-neutral-700 [&>button>svg]:!fill-neutral-700 dark:[&>button>svg]:!fill-neutral-300",children:[s.jsx(bn,{onClick:()=>Te(P=>!P),title:"Keyboard commands (?)",children:s.jsx("span",{className:"text-[13px] font-semibold !text-neutral-700 dark:!text-neutral-300",children:"?"})}),s.jsx(bn,{onClick:()=>{window.adfApi?.setFullscreen?.(!be)},title:be?"Exit full screen (F)":"Full screen (F)",children:be?s.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",className:"!fill-none text-neutral-700 dark:text-neutral-300",children:[s.jsx("path",{d:"M20 10h-6V4"}),s.jsx("path",{d:"M14 10l7-7"}),s.jsx("path",{d:"M4 14h6v6"}),s.jsx("path",{d:"M10 14l-7 7"})]}):s.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",className:"!fill-none text-neutral-700 dark:text-neutral-300",children:[s.jsx("path",{d:"M15 3h6v6"}),s.jsx("path",{d:"M21 3l-7 7"}),s.jsx("path",{d:"M9 21H3v-6"}),s.jsx("path",{d:"M3 21l7-7"})]})}),s.jsx(bn,{onClick:()=>c(!d),title:"Fleet log drawer",children:s.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",className:`!fill-none ${d?"text-blue-500":"text-neutral-700 dark:text-neutral-300"}`,children:[s.jsx("polyline",{points:"4 17 10 11 4 5"}),s.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})})]})]}),s.jsx(b1,{emitters:Js}),s.jsx(w1,{terrains:eo}),s.jsx(yy,{onDone:Be,onOpenAgent:rd,onFlyTo:sd}),A&&!A.filePath.startsWith("station:")&&!ee&&!rt[A.filePath]&&s.jsx(My,{filePath:A.filePath,x:A.x,y:A.y,onPointerStay:vt,onPointerAway:In,onInspect:P=>{vt(),L(null),U(P)}}),A&&A.filePath.startsWith("station:")&&!R&&(()=>{const P=Gt.find(D=>D.id===A.filePath);if(!P)return null;const z=P.data;return s.jsx(Py,{station:{id:P.id,kind:z.kind,label:z.label,status:z.status,detail:z.detail},x:A.x,y:A.y,onPointerStay:vt,onPointerAway:In,onInspect:D=>{vt(),L(null),K(D)}})})(),s.jsx(Ly,{visible:o}),G&&s.jsx(Fy,{dir:G,onClose:()=>Y(null),onFocusAgent:Ot}),ee&&s.jsx(Vy,{filePath:ee,onClose:()=>U(null),onOpenAgent:P=>{U(null),v(P),S()},onFocusAgent:Ot}),B&&s.jsx(_1,{filePath:B,onClose:()=>Z(null),onOpenAgent:()=>{const P=B;Z(null),v(P),S()}},B),Q&&(()=>{const P=Gt.find(D=>D.id===Q);if(!P)return null;const z=P.data;return s.jsx(T1,{stationId:P.id,data:z,onClose:()=>K(null),onOpenAgent:D=>W({agent:D,peerHost:z.detail?.host??z.label,peerUrl:z.detail?.url,peerSource:z.detail?.source}),onOpenLocalAgent:D=>{K(null),U(D)}})})(),R&&!F&&s.jsx(Ty,{agent:R.agent,peerHost:R.peerHost,peerSource:R.peerSource,x:R.x,y:R.y}),F&&s.jsx(E1,{agent:F.agent,peerHost:F.peerHost,peerUrl:F.peerUrl,peerSource:F.peerSource,onClose:()=>W(null)}),i===0&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:s.jsxs("div",{className:"text-center",children:[s.jsx("p",{className:"text-sm text-[var(--adf-ui-text-subtle)]",children:"No agents found"}),s.jsx("p",{className:"text-xs text-[var(--adf-ui-text-subtle)] mt-1",children:"Add .adf files to tracked directories to see them here"})]})}),s.jsx(wb,{debugInfo:E,onRefresh:Be})]})})}export{J1 as DID_RETRY_FIRST_MS,ew as DID_RETRY_MAX_MS,Mw as MeshGraphView,Q1 as buildEdges,Tl as fleetPeers,Zu as peerMatchOf,aw as regionDecor,ow as regionFromStation,nw as setRuntimeDids};
|