@coralai/sps-cli 0.67.3 → 0.67.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/CHANGELOG.md +11 -0
- package/dist/console/routes/providers.d.ts.map +1 -1
- package/dist/console/routes/providers.js +16 -1
- package/dist/console/routes/providers.js.map +1 -1
- package/dist/console-assets/assets/{ShowcasePage-kwFhzWFH.js → ShowcasePage-BqK9HLRZ.js} +1 -1
- package/dist/console-assets/assets/{index-C6Pqgd6L.js → index-bb6Y5lh1.js} +3 -3
- package/dist/console-assets/index.html +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ShowcasePage-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ShowcasePage-BqK9HLRZ.js","assets/ShowcasePage-EkuegwaP.css"])))=>i.map(i=>d[i]);
|
|
2
2
|
var a4=Object.defineProperty;var yN=e=>{throw TypeError(e)};var o4=(e,t,n)=>t in e?a4(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var bN=(e,t,n)=>o4(e,typeof t!="symbol"?t+"":t,n),wb=(e,t,n)=>t.has(e)||yN("Cannot "+n);var J=(e,t,n)=>(wb(e,t,"read from private field"),n?n.call(e):t.get(e)),st=(e,t,n)=>t.has(e)?yN("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),qe=(e,t,n,i)=>(wb(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),kt=(e,t,n)=>(wb(e,t,"access private method"),n);var Uh=(e,t,n,i)=>({set _(s){qe(e,t,s,n)},get _(){return J(e,t,i)}});(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function n(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(s){if(s.ep)return;s.ep=!0;const r=n(s);fetch(s.href,r)}})();function of(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Eb={exports:{}},Zu={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.production.js
|
|
@@ -838,7 +838,7 @@ name: code-review
|
|
|
838
838
|
description: ...
|
|
839
839
|
---
|
|
840
840
|
|
|
841
|
-
# ...`,"aria-label":t("skills.import.body")})]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:f.isPending||!u||!o.trim(),onClick:()=>f.mutate(),children:[f.isPending?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(n1,{size:14,strokeWidth:3}),t("skills.import.submit")]})]})})}function Bie({onClose:e,onSubmit:t}){const n=Ye(),[i,s]=_.useState(""),[r,o]=_.useState(""),c=/^[a-z0-9][a-z0-9-]*$/.test(i);return d.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:d.jsx("div",{className:"w-full max-w-xl my-8",children:d.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[d.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[d.jsx(ao,{size:16,strokeWidth:2.5}),n("skills.ai.title")]}),d.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:d.jsx(vn,{size:14,strokeWidth:3})})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.name")}),d.jsx("input",{type:"text",value:i,onChange:u=>s(u.target.value),placeholder:"rust-error-handling",className:"nb-input w-full font-[family-name:var(--font-mono)]","aria-label":n("skills.ai.name")})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.intent")}),d.jsx("textarea",{value:r,onChange:u=>o(u.target.value),placeholder:n("skills.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("skills.ai.intent")})]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!c||!r.trim(),onClick:()=>t(i,r),children:[d.jsx(ao,{size:14,strokeWidth:2.5}),n("skills.ai.submit")]})]})})})}async function Uie(e){const{files:t}=await Ane(e),n=t["SKILL.md"]??"",i=new Blob([n],{type:"text/markdown"}),s=URL.createObjectURL(i),r=document.createElement("a");r.href=s,r.download=`${e}.SKILL.md`,r.click(),URL.revokeObjectURL(s)}const Fie=[{value:"all",labelKey:"skills.category.all"},{value:"language",labelKey:"skills.category.language"},{value:"domain",labelKey:"skills.category.domain"},{value:"persona",labelKey:"skills.category.persona"},{value:"workflow",labelKey:"skills.category.workflow"},{value:"engine",labelKey:"skills.category.engine"},{value:"genre",labelKey:"skills.category.genre"},{value:"platform",labelKey:"skills.category.platform"},{value:"review",labelKey:"skills.category.review"},{value:"meta",labelKey:"skills.category.meta"},{value:"other",labelKey:"skills.category.other"}],$ie={language:"var(--color-accent-purple)",domain:"var(--color-secondary)",persona:"var(--color-primary)",workflow:"var(--color-accent-mint)",engine:"var(--color-accent-yellow)",genre:"var(--color-accent-pink)",platform:"var(--color-secondary-dark)",review:"var(--color-primary-dark)",meta:"var(--surface-control)",other:"var(--surface-control)"};function qie(){var F,V;const e=Ye(),[t,n]=_.useState("all"),[i,s]=_.useState([]),[r,o]=_.useState(""),[c,u]=_.useState(null),[f,p]=_.useState(!1),[m,b]=_.useState(!1),y=Xt(),v=(((F=Je({queryKey:["gen-jobs"],queryFn:rI,refetchInterval:3e3}).data)==null?void 0:F.data)??[]).filter(D=>D.kind==="skill"),w=v.filter(D=>D.status!=="done"),k=_.useRef(new Set);_.useEffect(()=>{for(const D of v)(D.status==="done"||D.status==="error")&&!k.current.has(D.id)&&(k.current.add(D.id),y.invalidateQueries({queryKey:["skills"]}),y.invalidateQueries({queryKey:["skill-updates"]}))},[v,y]);const C=(D,L)=>{Mne(D,L).then(()=>y.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},j=(((V=Je({queryKey:["skill-updates"],queryFn:jne}).data)==null?void 0:V.data)??[]).filter(D=>D.status!=="same").length,{data:T,isLoading:A}=Je({queryKey:["skills"],queryFn:()=>og()}),M=Je({queryKey:["projects"],queryFn:fo}),R=_.useMemo(()=>((T==null?void 0:T.data)??[]).filter(L=>!(t!=="all"&&L.category!==t||i.length>0&&!L.tags.some(z=>i.includes(z))||r&&!L.name.toLowerCase().includes(r.toLowerCase()))),[T,t,i,r]),P=_.useMemo(()=>{const D=(T==null?void 0:T.data)??[],L={all:D.length};for(const z of D)L[z.category]=(L[z.category]??0)+1;return L},[T]),I=_.useMemo(()=>{const D=new Map;for(const L of(T==null?void 0:T.data)??[])for(const z of L.tags)D.set(z,(D.get(z)??0)+1);return[...D.entries()].sort((L,z)=>z[1]-L[1]||L[0].localeCompare(z[0]))},[T]),B=D=>s(L=>L.includes(D)?L.filter(z=>z!==D):[...L,D]);return d.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[d.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[d.jsxs("div",{children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:"Skills"}),d.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:A?e("common.loading"):e("skills.subtitleCount",{count:(T==null?void 0:T.data.length)??0})})]}),d.jsxs("div",{className:"flex gap-3 items-center",children:[j>0&&d.jsx("span",{className:"nb-badge text-[10px]",title:e("skills.updates.badge",{count:String(j)}),children:e("skills.updates.badge",{count:String(j)})}),d.jsxs("button",{className:"nb-btn",onClick:()=>b(!0),type:"button",children:[d.jsx(ao,{size:14,strokeWidth:2.5}),e("skills.ai")]}),d.jsxs("button",{className:"nb-btn",onClick:()=>p(!0),type:"button",children:[d.jsx(n1,{size:14,strokeWidth:2.5}),e("skills.import")]}),d.jsxs("button",{className:"nb-btn nb-btn-mint",onClick:async()=>{await Nne(),y.invalidateQueries({queryKey:["skills"]}),y.invalidateQueries({queryKey:["skill-updates"]})},type:"button",children:[d.jsx(ro,{size:14,strokeWidth:2.5}),"Sync bundled"]})]})]}),d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs("div",{className:"relative shrink-0 w-full max-w-xs",children:[d.jsx(hf,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),d.jsx("input",{className:"nb-input pl-9 w-full",placeholder:e("skills.search.placeholder"),value:r,onChange:D=>o(D.target.value),"aria-label":e("skills.search.aria")})]}),d.jsx(au,{ariaLabel:"skill categories",className:"flex-1 min-w-0",value:t,onChange:n,options:Fie.filter(D=>D.value==="all"||(P[D.value]??0)>0).map(D=>({value:D.value,label:d.jsxs(d.Fragment,{children:[e(D.labelKey)," ",P[D.value]??0]})}))})]}),I.length>0&&d.jsxs("div",{className:"flex items-start gap-2 flex-wrap",children:[d.jsx("span",{className:"text-xs font-bold text-[var(--color-text-muted)] pt-1.5 uppercase tracking-wider",children:e("skills.tags.title")}),d.jsxs("div",{className:"flex flex-wrap gap-1.5 flex-1",children:[I.map(([D,L])=>{const z=i.includes(D);return d.jsxs("button",{type:"button",onClick:()=>B(D),className:["px-2.5 py-1 rounded-full text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)] transition-colors",z?"bg-[var(--color-text)] text-[var(--color-bg)] font-bold":"bg-[var(--surface-control)] text-[var(--color-text-muted)] hover:bg-[var(--surface-control-hover)]"].join(" "),children:[D," ",d.jsx("span",{className:"opacity-60",children:L})]},D)}),i.length>0&&d.jsx("button",{type:"button",onClick:()=>s([]),className:"px-2.5 py-1 rounded-full text-xs font-bold text-[var(--color-crashed)] hover:underline",children:e("skills.tags.clear")})]})]}),d.jsxs("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:[w.map(D=>d.jsxs("div",{className:`nb-card flex items-center gap-2 ${D.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,children:[D.status==="running"?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(vn,{size:14,strokeWidth:3}),d.jsx("span",{className:"text-sm text-[var(--color-text-muted)] truncate",children:D.status==="running"?`${D.label} · ${e("skills.ai.wait")}`:`${D.label}: ${D.error??e("skills.ai.error")}`})]},D.id)),R.map(D=>{var L;return d.jsx(Hie,{skill:D,projectCount:((L=M.data)==null?void 0:L.data.length)??0,onOpen:()=>u(D.name),onExport:()=>void Uie(D.name)},D.name)})]}),c&&d.jsx(BL,{name:c,onClose:()=>u(null)}),f&&d.jsx(zie,{onClose:()=>p(!1)}),m&&d.jsx(Bie,{onClose:()=>b(!1),onSubmit:(D,L)=>{C(D,L),b(!1)}})]})}function Hie({skill:e,projectCount:t,onOpen:n,onExport:i}){const s=Ye(),r=$ie[e.category];return d.jsxs("article",{className:"nb-card nb-card-interactive relative flex flex-col gap-3",children:[d.jsx("button",{type:"button",onClick:n,"aria-label":`Open ${e.name}`,className:"absolute inset-0 cursor-pointer rounded-[inherit] border-0 bg-transparent"}),d.jsxs("div",{className:"flex items-start justify-between gap-3",children:[d.jsx("h3",{className:"min-w-0 flex-1 overflow-hidden break-all font-[family-name:var(--font-heading)] text-lg font-bold leading-6 line-clamp-2",children:e.name}),d.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[d.jsx("button",{type:"button",className:"nb-btn relative z-10 p-1",onClick:i,"aria-label":s("skills.export"),title:s("skills.export"),children:d.jsx($A,{size:12,strokeWidth:2.5})}),d.jsx("span",{className:"nb-badge text-[10px]",style:{background:r},children:e.category})]})]}),d.jsx("p",{className:"text-sm text-[var(--color-text-muted)] leading-5 line-clamp-3",children:e.description||"(no description)"}),e.tags.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(o=>d.jsx("span",{className:"text-[10px] font-[family-name:var(--font-mono)] px-1.5 py-0.5 rounded-full bg-[var(--surface-control)] border border-[var(--control-border)]",children:o},o))}),d.jsxs("div",{className:"flex items-center justify-between text-xs font-[family-name:var(--font-mono)] pt-2 border-t-[1.5px] border-dashed border-[var(--color-border-light)] mt-auto",children:[d.jsx("span",{className:"font-bold",children:e.linkedProjects.length>0?`● linked in ${e.linkedProjects.length}`:"○ not linked"}),d.jsxs("span",{className:"text-[var(--color-text-subtle)]",children:[t," projects"]})]})]})}function Vie(e){return wt("/api/prompts")}function aI(e){return wt(`/api/prompts/${encodeURIComponent(e)}`)}function Kie(e){return jr("/api/prompts",e)}function Gie(e,t){return Pm(`/api/prompts/${encodeURIComponent(e)}`,t)}function Wie(e){return s1(`/api/prompts/${encodeURIComponent(e)}`)}function Yie(e){return jr("/api/prompts/generate",{intent:e})}function oI(e){const t=new Set,n=[];for(const i of e.matchAll(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g)){const s=i[1];s&&!t.has(s)&&(t.add(s),n.push(s))}return n}function Xie(){var M,R;const e=Ye(),[t,n]=oa("prompts.last",""),[i,s]=_.useState(null),[r,o]=_.useState(!1),[c,u]=_.useState(""),[f,p]=_.useState(new Set),m=Xt(),b=Je({queryKey:["prompts"],queryFn:()=>Vie()}),y=((M=b.data)==null?void 0:M.data)??[],x=_.useMemo(()=>[...new Set(y.flatMap(P=>P.tags))].sort(),[y]),w=(((R=Je({queryKey:["gen-jobs"],queryFn:rI,refetchInterval:3e3}).data)==null?void 0:R.data)??[]).filter(P=>P.kind==="prompt"),k=w.filter(P=>P.status!=="done"),C=_.useRef(new Set),S=_.useRef(null);_.useEffect(()=>{for(const P of w)(P.status==="done"||P.status==="error")&&!C.current.has(P.id)&&(C.current.add(P.id),m.invalidateQueries({queryKey:["prompts"]}),P.status==="done"&&P.result&&n(P.result))},[w,m,n]);const j=P=>{Yie(P).then(()=>m.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},T=_.useMemo(()=>{const P=c.trim().toLowerCase();return y.filter(I=>!(f.size&&![...f].every(B=>I.tags.includes(B))||P&&!(I.name.toLowerCase().includes(P)||I.description.toLowerCase().includes(P)||I.tags.some(F=>F.toLowerCase().includes(P)))))},[y,f,c]);_.useEffect(()=>{t&&y.length&&!y.some(P=>P.name===t)&&n("")},[t,y,n]);const A=P=>p(I=>{const B=new Set(I);return B.has(P)?B.delete(P):B.add(P),B});return d.jsxs("div",{className:"flex flex-col flex-1 min-h-0 w-full gap-3",children:[d.jsxs("div",{className:"shrink-0 flex items-center justify-between gap-3",children:[d.jsxs("div",{children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("prompts.title")}),d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.desc")})]}),d.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[d.jsxs("button",{className:"nb-btn",type:"button",onClick:()=>o(!0),children:[d.jsx(ao,{size:14,strokeWidth:2.5}),e("prompts.ai")]}),d.jsxs("button",{className:"nb-btn nb-btn-mint",type:"button",onClick:()=>s({mode:"new"}),children:[d.jsx(Bn,{size:14,strokeWidth:3}),e("prompts.new")]})]})]}),d.jsxs("div",{className:"shrink-0 flex flex-col gap-2",children:[d.jsxs("label",{className:"nb-input flex items-center gap-2 w-full",children:[d.jsx(hf,{size:14}),d.jsx("input",{type:"text",value:c,onChange:P=>u(P.target.value),placeholder:e("prompts.search"),className:"bg-transparent outline-none flex-1 text-sm","aria-label":e("prompts.search")})]}),x.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1.5",children:x.map(P=>d.jsx("button",{type:"button",onClick:()=>A(P),className:`nb-btn px-2 py-0.5 text-xs ${f.has(P)?"nb-btn-mint":""}`,children:P},P))})]}),d.jsxs("div",{className:"flex gap-5 flex-1 min-h-0",children:[d.jsx("aside",{className:"w-80 shrink-0 nb-card p-3 overflow-hidden flex h-full min-h-0 flex-col gap-2",children:d.jsxs("div",{ref:S,className:"edge-scroll-list flex-1 min-h-0 overflow-y-auto flex flex-col gap-0.5",children:[k.map(P=>d.jsxs("div",{className:`nb-card flex items-center gap-2 ${P.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,style:{padding:"8px 10px"},children:[P.status==="running"?d.jsx(pt,{size:12,className:"animate-spin"}):d.jsx(vn,{size:12,strokeWidth:3}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)] truncate",children:P.status==="running"?e("prompts.ai.wait"):`${e("prompts.ai.error")}: ${P.error??""}`})]},P.id)),b.isLoading?d.jsx("div",{className:"nb-card",children:d.jsx(pt,{size:14,className:"animate-spin"})}):T.length===0?d.jsx("div",{className:"nb-card",children:d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.empty")})}):T.map((P,I)=>d.jsx(ru,{index:I,root:S,children:d.jsxs("button",{type:"button",onClick:()=>n(P.name),className:["dimension-menu-item w-full min-w-0 flex-col items-stretch gap-1 px-3 py-2 pl-4 text-left",t===P.name?"dimension-menu-item-active":""].join(" "),children:[d.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[P.favorite&&d.jsx(QA,{size:12,fill:"currentColor",className:"shrink-0"}),d.jsx("code",{className:"min-w-0 max-w-full truncate font-[family-name:var(--font-mono)] text-sm font-bold",children:P.name})]}),P.description&&d.jsx("span",{className:"block w-full min-w-0 truncate text-xs text-[var(--color-text-muted)]",children:P.description})]})},P.name))]})}),d.jsx("div",{className:"flex-1 min-w-0 min-h-0",children:t?d.jsx(Zie,{name:t,onEdit:()=>s({mode:"edit",name:t}),onDeleted:()=>n("")},t):d.jsx("div",{className:"nb-card",children:d.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("prompts.selectHint")})})})]}),i&&d.jsx(ese,{name:i.mode==="edit"?i.name:null,onClose:()=>s(null),onSaved:P=>{s(null),n(P)}}),r&&d.jsx(Qie,{onClose:()=>o(!1),onSubmit:P=>{j(P),o(!1)}})]})}function Qie({onClose:e,onSubmit:t}){const n=Ye(),[i,s]=_.useState("");return d.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:d.jsx("div",{className:"w-full max-w-xl my-8",children:d.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[d.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[d.jsx(ao,{size:16,strokeWidth:2.5}),n("prompts.ai.title")]}),d.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:d.jsx(vn,{size:14,strokeWidth:3})})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:n("prompts.ai.intent")}),d.jsx("textarea",{value:i,onChange:r=>s(r.target.value),placeholder:n("prompts.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("prompts.ai.intent")})]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!i.trim(),onClick:()=>t(i),children:[d.jsx(ao,{size:14,strokeWidth:2.5}),n("prompts.ai.submit")]})]})})})}function Zie({name:e,onEdit:t,onDeleted:n}){const i=Ye(),s=Xt(),{confirm:r}=Un(),o=Je({queryKey:["prompt",e],queryFn:()=>aI(e)}),c=Dt({mutationFn:()=>Wie(e),onSuccess:()=>{s.invalidateQueries({queryKey:["prompts"]}),n()}});if(o.isLoading)return d.jsx("div",{className:"nb-card",children:d.jsx(pt,{size:14,className:"animate-spin"})});const u=o.data;if(!u)return null;const f=oI(u.body);return d.jsxs("div",{className:"nb-card flex flex-col gap-3 h-full min-h-0",children:[d.jsxs("div",{className:"flex items-start justify-between gap-3 shrink-0",children:[d.jsxs("div",{className:"min-w-0",children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold flex items-center gap-2",children:[u.favorite&&d.jsx(QA,{size:16,fill:"currentColor"}),d.jsx("code",{className:"font-[family-name:var(--font-mono)] truncate",children:u.name})]}),u.description&&d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:u.description})]}),d.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:t,children:[d.jsx(J0,{size:14,strokeWidth:3}),i("common.edit")]}),d.jsx("button",{type:"button",className:"nb-btn",disabled:c.isPending,onClick:async()=>{await r({title:i("prompts.delete"),body:i("prompts.deleteConfirm",{name:e})})&&c.mutate()},"aria-label":i("prompts.delete"),children:d.jsx(cs,{size:14,strokeWidth:3})})]})]}),u.tags.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1.5 shrink-0",children:u.tags.map(p=>d.jsx("span",{className:"nb-badge px-2 py-0.5 text-xs",children:p},p))}),d.jsx("pre",{className:"flex-1 bg-surface-input min-h-0 overflow-auto text-sm font-[family-name:var(--font-mono)] whitespace-pre-wrap break-words bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded p-3",children:u.body}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)] shrink-0",children:f.length?i("prompts.vars",{names:f.join(", ")}):i("prompts.noVars")})]})}function Jie({tags:e,onChange:t}){const n=Ye(),[i,s]=_.useState(""),r=()=>{const o=i.trim();o&&!e.includes(o)&&t([...e,o]),s("")};return d.jsxs("div",{className:"nb-input w-full flex flex-wrap gap-1.5 items-center",children:[e.map(o=>d.jsxs("span",{className:"inline-flex items-center gap-1 text-xs bg-[var(--color-accent-mint)] border-2 border-[var(--color-text)] rounded px-1.5 py-0.5",children:[o,d.jsx("button",{type:"button",onClick:()=>t(e.filter(c=>c!==o)),"aria-label":`remove ${o}`,children:d.jsx(vn,{size:10,strokeWidth:3})})]},o)),d.jsx("input",{className:"flex-1 min-w-[90px] bg-transparent outline-none text-sm",value:i,onChange:o=>s(o.target.value),onKeyDown:o=>{o.key==="Enter"?(o.preventDefault(),r()):o.key==="Backspace"&&!i&&e.length&&t(e.slice(0,-1))},placeholder:e.length?"":n("prompts.tagAdd"),"aria-label":n("prompts.tags")})]})}function ese({name:e,onClose:t,onSaved:n}){const i=Ye(),s=Xt(),{alert:r}=Un(),o=e===null,c=Je({queryKey:["prompt",e],queryFn:()=>aI(e),enabled:!o}),[u,f]=_.useState(o?{name:"",description:"",tags:[],body:"",favorite:!1}:null);_.useEffect(()=>{if(!o&&c.data&&u===null){const y=c.data;f({name:y.name,description:y.description,tags:y.tags,body:y.body,favorite:y.favorite})}},[o,c.data,u]);const p=Dt({mutationFn:()=>{if(!u)throw new Error("no form");const y={description:u.description||void 0,tags:u.tags,favorite:u.favorite,body:u.body};return o?Kie({name:u.name,...y}):Gie(e,y)},onSuccess:y=>{s.invalidateQueries({queryKey:["prompts"]}),s.invalidateQueries({queryKey:["prompt",y.name]}),n(y.name)},onError:y=>void r({title:i("prompts.saveError"),body:y instanceof Error?y.message:String(y)})}),m=_.useMemo(()=>u?/^[a-z0-9][a-z0-9-]*$/.test(u.name):!1,[u]),b=_.useMemo(()=>u?oI(u.body):[],[u]);return d.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:d.jsx("div",{className:"w-full max-w-2xl my-8",children:d.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[d.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold",children:o?i("prompts.new"):e}),d.jsx("button",{type:"button",className:"nb-btn p-2",onClick:t,"aria-label":"close",children:d.jsx(vn,{size:14,strokeWidth:3})})]}),!o&&c.isLoading?d.jsx(pt,{size:14,className:"animate-spin"}):u?d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:i("prompts.name")}),d.jsx("input",{type:"text",value:u.name,disabled:!o,onChange:y=>f({...u,name:y.target.value}),placeholder:i("prompts.namePlaceholder"),className:"nb-input w-full","aria-label":i("prompts.name")}),o&&u.name&&!m&&d.jsx("span",{className:"text-xs text-[var(--color-crashed)]",children:i("prompts.nameError")})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:i("prompts.description")}),d.jsx("input",{type:"text",value:u.description,onChange:y=>f({...u,description:y.target.value}),className:"nb-input w-full","aria-label":i("prompts.description")})]})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:i("prompts.tags")}),d.jsx(Jie,{tags:u.tags,onChange:y=>f({...u,tags:y})})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:i("prompts.body")}),d.jsx("textarea",{value:u.body,onChange:y=>f({...u,body:y.target.value}),placeholder:i("prompts.bodyPlaceholder"),rows:12,className:"nb-input w-full font-[family-name:var(--font-mono)] text-sm","aria-label":i("prompts.body")}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:b.length?i("prompts.vars",{names:b.join(", ")}):i("prompts.noVars")})]}),d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:p.isPending||o&&!m||!u.body.trim(),onClick:()=>p.mutate(),children:[p.isPending?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3}),i("prompts.save")]}),d.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[d.jsx("input",{type:"checkbox",checked:u.favorite,onChange:y=>f({...u,favorite:y.target.checked})}),i("prompts.favorite")]})]})]}):null]})})})}function tse(){return wt("/api/processes").then(e=>e.data)}function nse(e){return jr(`/api/processes/${e}/kill`)}function ise(){return wt("/api/processes/reclaim")}async function sse(e){const t=await fetch("/api/processes/reclaim",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({idleMinutes:e})});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return t.json()}const rse="nb-card";function ase(e){if(!e)return"—";const t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t)||t<0)return"—";const n=Math.floor(t/6e4);if(n<1)return"<1m";if(n<60)return`${n}m`;const i=Math.floor(n/60);return i<24?`${i}h${n%60?` ${n%60}m`:""}`:`${Math.floor(i/24)}d${i%24?` ${i%24}h`:""}`}function Lx(e){return e.project?e.project:e.cwd?e.cwd.split("/").filter(Boolean).pop()??e.slot:e.slot}function wj(e){const t=/^session-chat-(.+)$/.exec(e.slot);return(t==null?void 0:t[1])??null}function ose({p:e}){const t=e.alive?e.sessionState??"alive":"offline",n=e.alive?"bg-[var(--color-accent-mint)]":"bg-[var(--color-bg-cream)] text-[var(--color-text)]/60";return d.jsx("span",{className:`nb-status font-[family-name:var(--font-mono)] ${n}`,children:t})}function lse({embedded:e}={}){var v;const t=Ye(),n=Xt(),[i,s]=_.useState(null),[r,o]=_.useState("all"),c=Je({queryKey:["processes"],queryFn:tse,refetchInterval:5e3}),u=Dt({mutationFn:nse,onSuccess:w=>{s(w.message),n.invalidateQueries({queryKey:["processes"]})},onError:w=>s(w instanceof Error?w.message:String(w))}),f=Je({queryKey:["reclaim"],queryFn:ise}),[p,m]=_.useState("");_.useEffect(()=>{f.data&&p===""&&m(String(f.data.idleMinutes))},[f.data,p]);const b=Dt({mutationFn:w=>sse(w),onSuccess:w=>{s(`自动回收已设为 ${w.idleMinutes} 分钟空闲`),n.invalidateQueries({queryKey:["reclaim"]})},onError:w=>s(w instanceof Error?w.message:String(w))}),x=(c.data??[]).filter(w=>r==="all"?!0:w.kind===r);return d.jsxs("div",{className:"max-w-full flex-1 min-h-0 flex flex-col",children:[!e&&d.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl mb-2 shrink-0",children:t("processes.title")}),i&&d.jsx("div",{className:"nb-card mb-3 px-3 py-2 text-sm font-mono",children:i}),d.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[["all","worker","chat"].map(w=>d.jsx("button",{type:"button","aria-pressed":r===w,onClick:()=>o(w),className:`nb-btn px-3 py-1 text-sm ${r===w?"nb-btn-primary":""}`,children:t(`processes.kind.${w}`)},w)),d.jsxs("button",{type:"button","aria-label":t("processes.refresh"),onClick:()=>n.invalidateQueries({queryKey:["processes"]}),className:"nb-btn px-3 py-1 text-sm",children:[c.isFetching?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(ro,{size:14}),t("processes.refresh")]}),d.jsxs("div",{className:`${rse} px-3 py-1 flex items-center gap-2 shrink-0 ml-auto`,title:"自动回收:会话空闲 N 分钟自动停,下次访问 durable resume 续上,不丢上下文",children:[d.jsx(U6,{size:15,strokeWidth:2.5}),d.jsx("input",{type:"number",min:1,max:1440,value:p,onChange:w=>m(w.target.value),className:"nb-input w-14 px-2 py-1 font-[family-name:var(--font-mono)] text-sm","aria-label":"自动回收空闲分钟数"}),d.jsx("button",{type:"button",disabled:b.isPending||p===""||Number(p)===((v=f.data)==null?void 0:v.idleMinutes),onClick:()=>b.mutate(Math.round(Number(p))),className:"nb-btn nb-btn-primary text-sm disabled:opacity-50",style:{padding:"4px 8px"},"aria-label":"保存自动回收设置",title:"保存自动回收设置",children:b.isPending?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3})})]})]}),d.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] flex-1 min-h-0 overflow-hidden flex flex-col text-sm",children:[d.jsxs("div",{className:"shrink-0 grid grid-cols-[130px_minmax(140px,1.2fr)_minmax(140px,1.5fr)_80px_110px_90px_90px_100px] bg-[var(--surface-table-head)] font-[family-name:var(--font-heading)] border-b-2 border-[var(--color-text)]/15",children:[d.jsx("div",{className:"px-3 py-2",children:t("processes.col.kind")}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.slot")}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.project")}),d.jsx("div",{className:"px-3 py-2",children:"PID"}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.state")}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.memory")}),d.jsx("div",{className:"px-3 py-2",children:"运行时间"}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.action")})]}),d.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto font-[family-name:var(--font-mono)]",children:[x.length===0&&d.jsx("div",{className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:t("processes.empty")}),x.map(w=>d.jsxs("div",{className:"grid grid-cols-[130px_minmax(140px,1.2fr)_minmax(140px,1.5fr)_80px_110px_90px_90px_100px] border-t border-[var(--color-text)]/10 items-center",title:w.cwd??"",children:[d.jsxs("div",{className:"px-3 py-2 flex flex-col gap-0.5",children:[d.jsx("span",{className:`nb-badge text-xs whitespace-nowrap ${w.kind==="worker"?"bg-[var(--color-accent-yellow)]":"bg-[var(--color-accent-purple)]"}`,children:t(`processes.kind.${w.kind}`)}),d.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--color-text)]/45",children:w.tool})]}),d.jsx("div",{className:"px-3 py-2 truncate",children:w.slot}),d.jsx("div",{className:"px-3 py-2 truncate",children:w.kind==="chat"&&wj(w)?d.jsxs(zc,{to:`/chat/${wj(w)}`,className:"inline-flex items-center gap-1 font-semibold text-[var(--color-text)] underline decoration-2 underline-offset-2 hover:opacity-70",title:"打开对话窗口",children:[d.jsx(QU,{size:12,strokeWidth:2.5})," ",Lx(w)]}):w.kind==="worker"&&w.project?d.jsxs(zc,{to:`/board?project=${encodeURIComponent(w.project)}`,className:"inline-flex items-center gap-1 font-semibold text-[var(--color-text)] underline decoration-2 underline-offset-2 hover:opacity-70",title:"打开该项目看板",children:[d.jsx(gU,{size:12,strokeWidth:2.5})," ",Lx(w)]}):d.jsx("span",{children:Lx(w)})}),d.jsx("div",{className:"px-3 py-2",children:w.pid??"—"}),d.jsx("div",{className:"px-3 py-2",children:d.jsx(ose,{p:w})}),d.jsx("div",{className:"px-3 py-2",children:w.memoryMB!=null?`${w.memoryMB} MB`:"—"}),d.jsx("div",{className:"px-3 py-2",children:ase(w.startedAt)}),d.jsx("div",{className:"px-3 py-2",children:w.alive&&w.pid!=null?d.jsxs("button",{type:"button","aria-label":`${t("processes.kill")} ${w.slot}`,onClick:()=>{confirm(t("processes.killConfirm").replace("{slot}",w.slot))&&u.mutate(w.pid)},className:"nb-btn nb-btn-danger px-2.5 py-1 text-xs",children:[d.jsx(UA,{size:13})," ",t("processes.kill")]}):d.jsx("span",{className:"text-[var(--color-text)]/40 text-xs",children:"—"})})]},w.slot))]})]})]})}function cse(e={}){const t=new URLSearchParams;e.project&&t.set("project",e.project),e.action&&t.set("action",e.action);const n=t.toString();return wt(`/api/audit${n?`?${n}`:""}`).then(i=>i.data)}const use={create:"bg-[var(--color-accent-mint)]",modify:"bg-[var(--color-accent-yellow)]",delete:"bg-[var(--color-accent-pink)]",daemon:"bg-[var(--color-accent-purple)]"};function dse({embedded:e}={}){const t=Ye(),n=Xt(),[i,s]=_.useState(""),r=Je({queryKey:["audit",i],queryFn:()=>cse(i?{action:i}:{}),refetchInterval:8e3}),o=r.data??[],c=u=>t(`audit.action.${u}`);return d.jsxs("div",{className:"max-w-full flex-1 min-h-0 flex flex-col",children:[!e&&d.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl mb-2 shrink-0",children:t("audit.title")}),d.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap shrink-0",children:[["","create","modify","delete","daemon"].map(u=>d.jsx("button",{type:"button","aria-pressed":i===u,onClick:()=>s(u),className:`nb-btn px-3 py-1 text-sm ${i===u?"nb-btn-primary":""}`,children:u?c(u):t("audit.filter.all")},u||"all")),d.jsxs("button",{type:"button","aria-label":t("audit.refresh"),onClick:()=>n.invalidateQueries({queryKey:["audit"]}),className:"nb-btn px-3 py-1 text-sm ml-auto",children:[r.isFetching?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(ro,{size:14}),t("audit.refresh")]})]}),d.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] flex-1 min-h-0 overflow-hidden flex flex-col text-sm",children:[d.jsxs("div",{className:"shrink-0 grid grid-cols-[180px_120px_minmax(100px,1fr)_minmax(160px,2fr)] bg-[var(--surface-table-head)] font-[family-name:var(--font-heading)] border-b-2 border-[var(--color-text)]/15",children:[d.jsx("div",{className:"px-3 py-2",children:t("audit.col.time")}),d.jsx("div",{className:"px-3 py-2",children:t("audit.col.action")}),d.jsx("div",{className:"px-3 py-2",children:t("audit.col.project")}),d.jsx("div",{className:"px-3 py-2",children:t("audit.col.detail")})]}),d.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto font-[family-name:var(--font-mono)]",children:[o.length===0&&d.jsx("div",{className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:t("audit.empty")}),o.map((u,f)=>d.jsxs("div",{className:"grid grid-cols-[180px_120px_minmax(100px,1fr)_minmax(160px,2fr)] border-t border-[var(--color-text)]/10 items-center",children:[d.jsx("div",{className:"px-3 py-2 whitespace-nowrap",children:new Date(u.ts).toLocaleString()}),d.jsx("div",{className:"px-3 py-2",children:d.jsx("span",{className:`nb-badge text-xs whitespace-nowrap ${use[u.action]}`,children:c(u.action)})}),d.jsx("div",{className:"px-3 py-2 truncate",title:u.project,children:u.project}),d.jsx("div",{className:"px-3 py-2 text-[var(--color-text)]/70 truncate",title:u.detail??"",children:u.detail??(u.source?`(${u.source})`:"—")})]},`${u.ts}-${f}`))]})]})]})}const lI=[{id:"git",fields:[{key:"GITLAB_URL",type:"text",placeholder:"https://gitlab.com"},{key:"GITLAB_TOKEN",type:"text"}]},{id:"matrix",fields:[{key:"MATRIX_HOMESERVER",type:"text",placeholder:"https://matrix.example.com"},{key:"MATRIX_ACCESS_TOKEN",type:"text"},{key:"MATRIX_ROOM_ID",type:"text",placeholder:"!room:example.com"}]},{id:"memory",fields:[{key:"SPS_MEMORY_MODE",type:"select",defaultValue:"local",options:["local","local+external","external","none"]},{key:"SPS_MEMORY_EXTERNAL_URL",type:"text",placeholder:"http://127.0.0.1:3111"},{key:"SPS_MEMORY_DISTILL",type:"select",options:["","on","off"]},{key:"SPS_MEMORY_IMPORT",type:"select",options:["","on","off"]},{key:"SPS_MEMORY_REDACT",type:"select",options:["","on","off"]}]},{id:"daemon",fields:[{key:"SPS_OPENAI_SANDBOX_PROVIDER",type:"select",options:["","unix_local","docker"]},{key:"SPS_DAEMON_MAX_CONCURRENT_RUNS",type:"number",placeholder:"按内存自动推导"},{key:"SPS_DAEMON_ORIGIN_QUOTAS",type:"text",placeholder:"coral-platform=30,gameforge=20"},{key:"SPS_DAEMON_QUEUE_WAIT_S",type:"number",defaultValue:"20"},{key:"SPS_DAEMON_MAX_QUEUE",type:"number",defaultValue:"200"},{key:"SPS_RUN_IDLE_MINUTES",type:"number",defaultValue:"5"},{key:"SPS_RUN_TOOL_IDLE_MINUTES",type:"number",defaultValue:"12"},{key:"SPS_STUCK_RUN_MINUTES",type:"number",defaultValue:"20"}]},{id:"console",fields:[{key:"SPS_CONSOLE_TOKEN",type:"text"},{key:"SPS_CONSOLE_MEMORY_VIEWER_URL",type:"text",placeholder:"https://memory.example.com"}]}],fse=lI.flatMap(e=>e.fields),Ej=new Set(fse.map(e=>e.key)),hse=[{value:"config",labelKey:"system.tab.config"},{value:"processes",labelKey:"system.tab.processes"},{value:"doctor",labelKey:"system.tab.doctor"},{value:"audit",labelKey:"system.tab.audit"}];function pse(){var s,r;const e=Ye(),t=Je({queryKey:["system-info"],queryFn:oM}),[n,i]=oa("system.tab","config");return d.jsxs("div",{className:"system-page-shell flex flex-col flex-1 min-h-0 w-full",children:[d.jsxs("header",{className:"system-page-header shrink-0 flex items-center justify-between gap-3 flex-wrap",children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("system.h1")}),d.jsx(mse,{platform:(s=t.data)==null?void 0:s.platform,current:(r=t.data)==null?void 0:r.version})]}),d.jsx(au,{ariaLabel:e("system.h1"),className:"max-w-full",value:n,onChange:i,options:hse.map(o=>({value:o.value,label:e(o.labelKey)}))}),d.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[n==="config"&&d.jsx(gse,{}),n==="processes"&&d.jsx(lse,{embedded:!0}),n==="doctor"&&d.jsx(bse,{}),n==="audit"&&d.jsx(dse,{embedded:!0})]})]})}function mse({platform:e,current:t}){const n=Ye(),{confirm:i,alert:s}=Un(),[r,o]=_.useState(!1),c=Je({queryKey:["latest-version"],queryFn:EF,enabled:!1}),u=async()=>{const p=(await c.refetch()).data;if(!p)return;if(p.upToDate){s({title:n("system.upgrade.checkUpdate"),body:n("system.upgrade.upToDate",{version:t??"?"})});return}if(await i({title:n("system.upgrade.confirm.title"),body:n("system.upgrade.confirm.body",{current:t??"?",latest:p.latest}),confirm:n("system.upgrade.confirm.button")})){o(!0);try{const b=await kF();s({title:b.ok?n("system.upgrade.success.title"):n("system.upgrade.notEffective.title"),body:b.ok?n("system.upgrade.success.body",{version:b.installedVersion??"?"}):b.output||""})}catch(b){s({title:n("system.upgrade.error.title"),body:b.message})}finally{o(!1)}}};return d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs("span",{className:"text-xs font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] whitespace-nowrap",children:[e??"—",t?` · v${t}`:""]}),d.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:u,disabled:r||c.isFetching||!t,type:"button","aria-label":n("system.upgrade.checkUpdate"),children:[r||c.isFetching?d.jsx(pt,{size:12,strokeWidth:3,className:"animate-spin"}):d.jsx(ro,{size:12,strokeWidth:2.5}),n("system.upgrade.checkUpdate")]})]})}function gse(){const e=Ye(),t=Xt(),{alert:n}=Un(),{data:i,isLoading:s,isError:r,error:o,dataUpdatedAt:c}=Je({queryKey:["system-env-raw"],queryFn:yF}),[u,f]=_.useState(null),[p,m]=_.useState(""),[b,y]=_.useState(""),x=i?`${i.etag}:${c}`:null;_.useEffect(()=>{if(!i||x===null)return;const P=u!==null&&u.content!==u.baseContent;(u===null||!P&&u.sourceKey!==x)&&(f({content:i.content,baseContent:i.content,etag:i.etag,sourceKey:x}),m(""),y(""))},[i,u,x]);const v=u,w=v!==null&&v.content!==v.baseContent,k=(v==null?void 0:v.content)??(i==null?void 0:i.content)??"",C=(v==null?void 0:v.etag)??(i==null?void 0:i.etag)??null,S=KL(k,Ej),j=p.trim().toUpperCase(),T=WL(j)&&!Ej.has(j)&&!S.some(P=>P.key===j),A=(P,I)=>{f(B=>{const F=B??Ix(i,x);return{...F,content:xm(F.content,P.key,I,P)}})},M=(P,I)=>{f(B=>{const F=B??Ix(i,x);return{...F,content:xm(F.content,P,I)}})},R=Dt({mutationFn:()=>{if(v===null)throw new Error("no draft");return bF(v.content,v.etag)},onSuccess:P=>{f(I=>I===null?I:{...I,baseContent:I.content,etag:P.etag,sourceKey:`${P.etag}:saved`}),t.invalidateQueries({queryKey:["system-env"]}),t.invalidateQueries({queryKey:["system-env-raw"]})},onError:P=>{const I=P.status;n({title:e(I===409?"system.env.error.conflict.title":"system.env.error.save.title"),body:I===409?e("system.env.error.conflict.body"):P instanceof Error?P.message:String(P)})}});return s?d.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("common.loading")}):r?d.jsx("div",{className:"bg-[var(--color-crashed-bg)] border-2 border-[var(--color-crashed)] rounded-lg p-3",children:d.jsx("p",{className:"text-sm",children:o instanceof Error?o.message:String(o)})}):d.jsxs("div",{className:"system-env-settings-editor",children:[d.jsxs("div",{className:"project-config-toolbar",children:[d.jsxs("div",{children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-base font-bold mb-1",children:e("system.tab.config")}),d.jsx("p",{className:"text-xs text-[var(--color-stuck)] font-bold",children:e("system.env.warning")}),C&&d.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] mt-1",children:["etag: ",C,w?e("system.env.dirtyMark"):""]})]}),d.jsx("div",{className:"flex gap-2",children:d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px"},onClick:()=>R.mutate(),disabled:!w||R.isPending,type:"button","aria-label":e("system.env.save.aria"),children:[R.isPending?d.jsx(pt,{size:12,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:12,strokeWidth:3}),e("system.env.save")]})})]}),d.jsxs("div",{className:"project-config-settings","aria-label":e("system.env.settingsAria"),children:[lI.map(P=>d.jsxs("section",{className:"project-config-section",children:[d.jsxs("div",{className:"project-config-section-head",children:[d.jsx("h3",{children:e(`system.env.section.${P.id}`)}),d.jsx("p",{children:e(`system.env.section.${P.id}.hint`)})]}),d.jsx("div",{className:"project-config-grid",children:P.fields.map(I=>d.jsx(yse,{field:I,value:VL(k,I),rawValue:Hd(k,I.key),onChange:B=>A(I,B)},I.key))})]},P.id)),d.jsxs("section",{className:"project-config-section",children:[d.jsxs("div",{className:"project-config-section-head",children:[d.jsx("h3",{children:e("system.env.section.custom")}),d.jsx("p",{children:e("system.env.section.custom.hint")})]}),d.jsxs("div",{className:"project-config-custom-list",children:[S.length===0?d.jsx("p",{className:"project-config-empty",children:e("system.env.custom.empty")}):S.map(P=>d.jsxs("div",{className:"project-config-custom-row",children:[d.jsx("code",{children:P.key}),d.jsx("input",{className:"nb-input",value:P.value,onChange:I=>M(P.key,I.target.value),"aria-label":e("system.env.custom.valueAria",{key:P.key})}),d.jsx("button",{type:"button",className:"nb-btn",onClick:()=>f(I=>{const B=I??Ix(i,x);return{...B,content:GL(B.content,P.key)}}),"aria-label":e("system.env.custom.removeAria",{key:P.key}),children:d.jsx(vn,{size:12,strokeWidth:3})})]},P.key)),d.jsxs("div",{className:"project-config-custom-row project-config-custom-add",children:[d.jsx("input",{className:"nb-input",value:p,onChange:P=>m(P.target.value),placeholder:e("system.env.custom.keyPlaceholder"),"aria-label":e("system.env.custom.keyAria")}),d.jsx("input",{className:"nb-input",value:b,onChange:P=>y(P.target.value),placeholder:e("system.env.custom.valuePlaceholder"),"aria-label":e("system.env.custom.newValueAria")}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:!T||!b,onClick:()=>{M(j,b),m(""),y("")},children:[d.jsx(Bn,{size:12,strokeWidth:3}),e("system.env.custom.add")]})]})]})]})]})]})}function Ix(e,t){const n=(e==null?void 0:e.content)??"",i=(e==null?void 0:e.etag)??"";return{content:n,baseContent:n,etag:i,sourceKey:t??`${i}:empty`}}function yse({field:e,value:t,rawValue:n,onChange:i}){const s=Ye(),r=s(`system.env.field.${e.key}`),o=s(`system.env.field.${e.key}.help`),c=e.type==="boolean",u=(n||e.defaultValue||"").toLowerCase()==="true";return d.jsxs("div",{className:["project-config-field",c?"project-config-field-toggle":""].join(" "),children:[d.jsxs("span",{className:"project-config-label",children:[d.jsx("span",{children:r}),d.jsx("code",{children:e.key})]}),c?d.jsxs("span",{className:"project-config-toggle-row",children:[d.jsx("input",{type:"checkbox",checked:u,onChange:f=>i(String(f.target.checked))}),d.jsx("span",{children:s(u?"common.yes":"common.no")})]}):e.type==="select"?d.jsx("select",{className:"nb-input",value:t,onChange:f=>i(f.target.value),"aria-label":r,children:(e.options??[]).map(f=>d.jsx("option",{value:f,children:f||s("projectDetail.config.option.empty")},f||"__empty"))}):d.jsx("input",{className:"nb-input",type:e.type==="number"?"number":"text",min:e.type==="number"?0:void 0,value:t,onChange:f=>i(f.target.value),placeholder:e.placeholder,"aria-label":r}),d.jsx("span",{className:"project-config-help",children:o})]})}function bse(){var b;const e=Ye(),{alert:t}=Un(),n=Je({queryKey:["projects"],queryFn:fo}),[i,s]=_.useState({}),[r,o]=_.useState({}),[c,u]=_.useState(null),f=(((b=n.data)==null?void 0:b.data)??[]).map(y=>({project:y.name})),p=async(y,x)=>{o(v=>({...v,[y]:x?"fix":"check"}));try{const v=await SF(y,x);s(w=>({...w,[y]:v})),u(y)}catch(v){t({title:e(x?"system.diagnostics.error.fix":"system.diagnostics.error.check"),body:v instanceof Error?v.message:String(v)})}finally{o(v=>({...v,[y]:null}))}},m=async()=>{for(const y of f)await p(y.project,!1)};return d.jsxs("section",{className:"nb-card system-panel system-panel-doctor flex-1 min-h-0",children:[d.jsxs("div",{className:"system-panel-titlebar",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:e("system.diagnostics.title")}),d.jsxs("button",{className:"nb-btn nb-btn-mint",style:{padding:"6px 12px",fontSize:12},onClick:()=>{m()},disabled:f.length===0||Object.values(r).some(Boolean),type:"button",children:[d.jsx(ro,{size:12,strokeWidth:2.5}),e("system.diagnostics.checkAll")]})]}),d.jsx("div",{className:"system-panel-body",children:f.length===0?d.jsx("p",{className:"text-[var(--color-text-muted)] text-sm",children:e("system.diagnostics.empty")}):d.jsx("ul",{className:"system-diagnostics-list",children:f.map(y=>{const x=i[y.project],v=r[y.project],w=x?x.checks.filter(j=>j.status==="fail").length:0,k=x?x.checks.filter(j=>j.status==="warn").length:0,C=c===y.project,S=x!=null;return d.jsxs("li",{className:["system-diagnostics-item",C?"system-diagnostics-item-expanded":""].join(" "),children:[d.jsxs("div",{className:"system-diagnostics-row",children:[d.jsxs("button",{type:"button",onClick:()=>u(C?null:y.project),disabled:!S,className:"system-diagnostics-summary","aria-label":e(C?"system.diagnostics.collapseAria":"system.diagnostics.expandAria"),"aria-expanded":S?C:void 0,children:[d.jsxs("span",{className:"system-diagnostics-project-main",children:[S&&x.ok?d.jsx(gv,{size:16,className:"text-[var(--color-running)] shrink-0",strokeWidth:2.5}):S?d.jsx(Od,{size:16,className:"text-[var(--color-stuck)] shrink-0",strokeWidth:2.5}):d.jsx(gv,{size:16,className:"text-[var(--color-text-subtle)] shrink-0",strokeWidth:2.5}),S&&(C?d.jsx(uo,{size:12}):d.jsx(ff,{size:12})),d.jsx("span",{className:"system-diagnostics-project-name",children:y.project})]}),S?x.ok?d.jsx("span",{className:"system-diagnostics-status system-diagnostics-status-ok",children:"OK"}):d.jsxs("span",{className:"system-diagnostics-status system-diagnostics-status-warn",children:[w," fail · ",k," warn"]}):d.jsx("span",{className:"system-diagnostics-never",children:e("system.diagnostics.never")})]}),d.jsxs("div",{className:"system-diagnostics-actions",children:[d.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>{p(y.project,!1)},disabled:!!v,type:"button","aria-label":e("system.diagnostics.checkAria"),children:[v==="check"?d.jsx(pt,{size:11,strokeWidth:3,className:"animate-spin"}):d.jsx(ro,{size:11,strokeWidth:2.5}),e("system.diagnostics.check")]}),d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>{p(y.project,!0)},disabled:!!v||S&&x.ok,type:"button","aria-label":e("system.diagnostics.fixAria"),title:S&&x.ok?e("system.diagnostics.noFixesNeeded"):e("system.diagnostics.fix.tip"),children:[v==="fix"?d.jsx(pt,{size:11,strokeWidth:3,className:"animate-spin"}):d.jsx(JA,{size:11,strokeWidth:2.5}),e("system.diagnostics.fix")]})]})]}),C&&S&&d.jsxs("div",{className:"system-diagnostics-detail",children:[d.jsx("ul",{className:"system-diagnostics-checks",children:x.checks.map((j,T)=>d.jsx(xse,{check:j},`${j.name}-${T}`))}),x.fixes.length>0&&d.jsxs("div",{className:"mt-3 bg-[var(--color-running-bg)] border-2 border-[var(--color-running)] rounded p-2",children:[d.jsx("div",{className:"text-xs font-bold text-[var(--color-running)] mb-1",children:e("system.diagnostics.fixed")}),d.jsx("ul",{className:"text-xs list-disc pl-4",children:x.fixes.map((j,T)=>d.jsx("li",{children:j},T))})]})]})]},y.project)})})})]})}function xse({check:e}){const t=e.status==="pass"?d.jsx(gv,{size:12,className:"text-[var(--color-running)]",strokeWidth:2.5}):e.status==="fail"?d.jsx(Od,{size:12,className:"text-[var(--color-crashed)]",strokeWidth:2.5}):e.status==="warn"?d.jsx(Od,{size:12,className:"text-[var(--color-stuck)]",strokeWidth:2.5}):d.jsx("span",{className:"system-diagnostics-info-dot"});return d.jsxs("li",{className:"system-diagnostics-check-row",children:[d.jsx("span",{className:"system-diagnostics-check-icon",children:t}),d.jsx("span",{className:"system-diagnostics-check-name",children:e.name}),d.jsx("span",{className:"system-diagnostics-check-message",children:e.message})]})}function Ec({value:e,onChange:t,options:n,ariaLabel:i,disabled:s,className:r="",placeholder:o="选择…",align:c="left"}){var k;const[u,f]=_.useState(!1),p=_.useRef(null),m=_.useRef(null),b=_.useRef(null),[y,x]=_.useState(null),v=()=>{var S;const C=(S=p.current)==null?void 0:S.getBoundingClientRect();C&&x({top:C.bottom+6,left:C.left,right:window.innerWidth-C.right,width:C.width})};_.useLayoutEffect(()=>{u&&v()},[u]),_.useEffect(()=>{if(!u)return;const C=()=>v(),S=j=>{var T,A;(T=p.current)!=null&&T.contains(j.target)||(A=m.current)!=null&&A.contains(j.target)||f(!1)};return window.addEventListener("scroll",C,!0),window.addEventListener("resize",C),document.addEventListener("mousedown",S),()=>{window.removeEventListener("scroll",C,!0),window.removeEventListener("resize",C),document.removeEventListener("mousedown",S)}},[u]);const w=((k=n.find(C=>C.value===e))==null?void 0:k.label)??o;return d.jsxs("div",{className:`relative ${r}`,children:[d.jsxs("button",{ref:p,type:"button",disabled:s,"aria-label":i,"aria-expanded":u,className:"nb-btn w-full justify-between text-sm disabled:opacity-50",onClick:()=>f(C=>!C),children:[d.jsx("span",{className:"truncate",children:w}),d.jsx(uo,{size:14,strokeWidth:2.5,className:["shrink-0 transition-transform",u?"rotate-180":""].join(" ")})]}),u&&y&&IA.createPortal(d.jsx("div",{ref:m,style:{position:"fixed",top:y.top,left:c==="right"?void 0:y.left,right:c==="right"?y.right:void 0,minWidth:y.width},className:"z-[100] nb-card p-1 overflow-hidden bg-[var(--surface-menu)]",children:d.jsx("div",{ref:b,className:"max-h-[60vh] overflow-y-auto",children:n.map((C,S)=>d.jsx(ru,{index:S,root:b,delay:.02,children:d.jsx("button",{type:"button",onClick:()=>{t(C.value),f(!1)},className:["dimension-menu-item w-full text-left px-4 py-2 text-sm font-semibold flex items-center gap-2 whitespace-nowrap",C.value===e?"dimension-menu-item-active":""].join(" "),children:C.label})},C.value))})}),document.body)]})}const vse=["convention","decision","gotcha","pattern","reference","note"],wse=["local","local+external","external","none"];function ww(e){return e!=null&&typeof e=="object"?e:{}}function kc(e){return Array.isArray(e)?e:[]}function Ese(e){switch(e){case"none":return"none";case"agentmemory":case"custom":return"external";case"builtin":default:return"local"}}function kj(e){const t=ww(e);return{mode:typeof t.mode=="string"&&t.mode?t.mode:Ese(t.provider),externalUrl:typeof t.externalUrl=="string"?t.externalUrl:typeof t.url=="string"?t.url:"",modeOptions:kc(t.modeOptions).length>0?kc(t.modeOptions):wse}}function kse(e){const t=ww(e),n=t.scope==="global"||t.scope==="project"||t.scope==="agent"?t.scope:null;return n?{scope:n,project:typeof t.project=="string"?t.project:void 0,agentId:typeof t.agentId=="string"?t.agentId:void 0,count:typeof t.count=="number"?t.count:0,updated:typeof t.updated=="string"?t.updated:""}:null}function Sse(e){const t=ww(e);if(typeof t.id!="string")return null;const n=t.scope==="global"||t.scope==="project"||t.scope==="agent"?t.scope:"global";return{id:t.id,title:typeof t.title=="string"?t.title:t.id,scope:n,category:typeof t.category=="string"?t.category:"note",tags:kc(t.tags),salience:typeof t.salience=="number"?t.salience:3,source:typeof t.source=="string"?t.source:"human",project:typeof t.project=="string"?t.project:void 0,agentId:typeof t.agentId=="string"?t.agentId:void 0,created:typeof t.created=="string"?t.created:"",updated:typeof t.updated=="string"?t.updated:"",body:typeof t.body=="string"?t.body:""}}function Po(e){return`${e.scope}:${e.project??e.agentId??""}`}function fp(e){return e.scope==="global"?`全局 (${e.count})`:e.scope==="project"?`项目:${e.project} (${e.count})`:`会话:${e.agentId} (${e.count})`}function zo(e){const t={scope:e.scope};return e.project&&(t.project=e.project),e.agentId&&(t.agentId=e.agentId),t}async function hr(e,t){const n=await fetch(e,t);if(!n.ok){const i=await n.json().catch(()=>null);throw new Error((i==null?void 0:i.detail)||(i==null?void 0:i.title)||`HTTP ${n.status}`)}return await n.json()}const Nse=()=>({title:"",body:"",category:"note",tags:"",salience:3});function _se(){var le,pe,Te;const e=Ye(),[t,n]=_.useState([]),[i,s]=_.useState(null),[r,o]=_.useState(!1),[c,u]=_.useState([]),[f,p]=_.useState(null),[m,b]=_.useState(!1),[y,x]=_.useState(""),[v,w]=_.useState(!0),[k,C]=_.useState([]),[S,j]=_.useState(null),[T,A]=_.useState(null),[M,R]=_.useState(null),[P,I]=_.useState(null),[B,F]=_.useState(""),[V,D]=_.useState(""),L=_.useCallback(async()=>{try{const{scopes:ne}=await hr("/api/memory/scopes"),oe=kc(ne).map(kse).filter(xe=>xe!=null);n(oe),s(xe=>xe??oe[0]??null)}catch(ne){p(ne instanceof Error?ne.message:String(ne))}},[]),z=_.useCallback(async ne=>{try{const oe=new URLSearchParams(zo(ne)).toString(),{data:xe}=await hr(`/api/memory/entries?${oe}`);u(kc(xe).map(Sse).filter(fe=>fe!=null))}catch(oe){p(oe instanceof Error?oe.message:String(oe))}},[]);_.useEffect(()=>{L(),hr("/api/system/memory").then(ne=>{const oe=kj(ne);I(oe),F(oe.mode),D(oe.externalUrl)}).catch(()=>{})},[L]),_.useEffect(()=>{i&&z(i),(i==null?void 0:i.scope)==="project"&&i.project?hr(`/api/memory/external?project=${encodeURIComponent(i.project)}`).then(ne=>R(ne)).catch(()=>R(null)):R(null)},[i,z]);const W=_.useCallback(async()=>{if(!y.trim()){C([]);return}b(!0),p(null);try{const ne=new URLSearchParams({q:y,limit:"20"});if(v)ne.set("all","1");else if(i)for(const[xe,fe]of Object.entries(zo(i)))ne.set(xe,fe);const{results:oe}=await hr(`/api/memory/recall?${ne.toString()}`);C(kc(oe))}catch(ne){p(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}},[y,v,i]),X=_.useCallback(async()=>{if(!(!i||!S)){b(!0),p(null);try{await hr("/api/memory/entries",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...zo(i),id:S.id,title:S.title,body:S.body,category:S.category,tags:S.tags.split(",").map(ne=>ne.trim()).filter(Boolean),salience:S.salience})}),j(null),await Promise.all([z(i),L()])}catch(ne){p(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}}},[i,S,z,L]),G=_.useCallback(async ne=>{if(i){b(!0),p(null);try{const oe=new URLSearchParams(zo(i)).toString();await hr(`/api/memory/entries/${encodeURIComponent(ne)}?${oe}`,{method:"DELETE"}),await Promise.all([z(i),L()])}catch(oe){p(oe instanceof Error?oe.message:String(oe))}finally{b(!1)}}},[i,z,L]),U=_.useCallback(async(ne,oe,xe)=>{if(i){b(!0),p(null);try{await hr("/api/memory/promote",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({from:zo(i),id:ne.id,to:zo(oe),move:xe})}),A(null),await Promise.all([z(i),L()])}catch(fe){p(fe instanceof Error?fe.message:String(fe))}finally{b(!1)}}},[i,z,L]),q=_.useCallback(async()=>{if(i){b(!0),p(null);try{const oe=(await hr("/api/memory/gc",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(zo(i))})).results[0];oe&&p(`收敛完成:清 tombstone ${oe.purged}、去重 ${oe.deduped}、剩余 ${oe.kept}`),await Promise.all([z(i),L()])}catch(ne){p(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}}},[i,z,L]),Y=_.useCallback(async()=>{b(!0),p(null);try{const ne=kj(await hr("/api/system/memory",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({mode:B,externalUrl:V})}));I(ne),F(ne.mode),D(ne.externalUrl),p("模式已保存(重启 worker 生效)")}catch(ne){p(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}},[B,V]),$=P!=null&&(B!==P.mode||V!==P.externalUrl),ie=B==="external"||B==="local+external",be=_.useMemo(()=>T?t.filter(ne=>Po(ne)!==Po(i??{scope:""})):[],[T,t,i]),ce=Array.isArray((le=M==null?void 0:M.profile)==null?void 0:le.topConcepts)?M.profile.topConcepts:[],_e=Array.isArray((pe=M==null?void 0:M.graph)==null?void 0:pe.edges)?M.graph.edges.length:0;return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl text-[var(--color-text)]",children:e("nav.memory")}),d.jsx("span",{className:"text-xs text-[var(--color-text)] opacity-60",children:"本地记忆 v2 · markdown 真源"})]}),P&&d.jsxs("section",{className:"nb-card flex flex-wrap items-end gap-3",children:[d.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[d.jsx("span",{className:"font-bold",children:"记忆模式"}),d.jsx(Ec,{value:B,onChange:F,ariaLabel:"记忆模式",options:P.modeOptions.map(ne=>({value:ne,label:ne}))})]}),ie&&d.jsxs("label",{className:"flex flex-col gap-1 text-sm flex-1 min-w-[220px]",children:[d.jsx("span",{className:"font-bold",children:"外部后端地址"}),d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",value:V,onChange:ne=>D(ne.target.value),placeholder:"http://127.0.0.1:3113",spellCheck:!1,"aria-label":"外部后端地址"})]}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:Y,disabled:m||!$,"aria-label":"保存模式",children:"保存模式"})]}),(()=>{const ne=new Date(Date.now()-6048e5).toISOString(),oe=i?Po(i):"",xe=r?t:t.filter(te=>te.scope!=="project"||te.updated>=ne||Po(te)===oe),fe=t.length-xe.length;return d.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[d.jsx("input",{value:y,onChange:te=>x(te.target.value),onKeyDown:te=>te.key==="Enter"&&W(),placeholder:"检索记忆…","aria-label":"检索记忆",className:"nb-input flex-1 min-w-[200px] font-[family-name:var(--font-mono)] text-sm"}),d.jsxs("label",{className:"flex items-center gap-1 text-sm font-semibold",children:[d.jsx("input",{type:"checkbox",checked:v,onChange:te=>w(te.target.checked),"aria-label":"全局检索"}),"全局"]}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:W,disabled:m,"aria-label":"检索",children:m?"…":"检索"}),d.jsx(Ec,{className:"min-w-[180px]",value:oe,onChange:te=>s(t.find(we=>Po(we)===te)??null),ariaLabel:"选择作用域",placeholder:"选择作用域",options:xe.map(te=>({value:Po(te),label:fp(te)}))}),(fe>0||r)&&d.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>o(te=>!te),"aria-label":r?"收起更早项目":"显示更早项目",children:r?"收起更早":`含更早 (${fe})`}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>j(Nse()),disabled:!i,"aria-label":"新建记忆",children:"+ 新建"}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-yellow",onClick:q,disabled:m||!i,"aria-label":"收敛去重",children:"收敛"})]})})(),f&&d.jsxs("div",{className:"text-sm text-[var(--color-text)] font-semibold nb-card py-2",children:["ℹ ",f]}),k.length>0&&d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:["检索结果(",k.length,")"]}),k.map(ne=>d.jsxs("div",{className:"nb-card",children:[d.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)]",children:[d.jsx("span",{className:"nb-badge",children:ne.source==="external"?"🌐 外部":"📁 本地"}),d.jsx("span",{children:ne.source==="external"?ne.type??"":ne.scope==="project"?`项目:${ne.project}`:ne.scope}),ne.category&&d.jsxs(d.Fragment,{children:[d.jsx("span",{children:"·"}),d.jsx("span",{children:ne.category})]})]}),d.jsx("div",{className:"font-bold text-sm mt-1",children:ne.title}),d.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:ne.snippet.slice(0,300)})]},ne.id))]}),M&&(ce.length||_e)?d.jsxs("section",{className:"nb-card flex flex-col gap-1",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:"🌐 外部智能(agentmemory)"}),ce.length?d.jsxs("div",{className:"text-xs",children:[d.jsx("span",{className:"font-bold",children:"概念:"}),ce.slice(0,8).map(ne=>d.jsx("span",{className:"nb-badge ml-1",children:ne.concept},ne.concept))]}):null,d.jsxs("div",{className:"text-xs opacity-70 font-[family-name:var(--font-mono)]",children:["知识图谱 ",_e," 条边 · 观测 ",((Te=M.profile)==null?void 0:Te.totalObservations)??0]})]}):null,S&&d.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-40 flex items-center justify-center p-6 bg-black/30 overflow-hidden",onMouseDown:ne=>{ne.target===ne.currentTarget&&j(null)},children:d.jsxs("div",{className:"nb-card w-full max-w-2xl flex flex-col gap-2",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:S.id?"编辑记忆":"新建记忆"}),d.jsx("input",{className:"nb-input text-sm",value:S.title,onChange:ne=>j({...S,title:ne.target.value}),placeholder:"标题","aria-label":"标题"}),d.jsxs("div",{className:"flex gap-2 flex-wrap items-end",children:[d.jsx(Ec,{className:"min-w-[140px]",value:S.category,onChange:ne=>j({...S,category:ne}),ariaLabel:"类别",options:vse.map(ne=>({value:ne,label:ne}))}),d.jsx("input",{className:"nb-input flex-1 min-w-[160px] text-sm",value:S.tags,onChange:ne=>j({...S,tags:ne.target.value}),placeholder:"标签(逗号分隔)","aria-label":"标签"}),d.jsxs("label",{className:"flex items-center gap-1 text-sm",children:["显著度",d.jsx("input",{className:"nb-input w-16",type:"number",min:1,max:5,value:S.salience,onChange:ne=>j({...S,salience:Number(ne.target.value)}),"aria-label":"显著度"})]})]}),d.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm min-h-[120px]",value:S.body,onChange:ne=>j({...S,body:ne.target.value}),placeholder:"正文","aria-label":"正文"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:X,disabled:m||!S.title.trim()||!S.body.trim(),"aria-label":"保存",children:"保存"}),d.jsx("button",{type:"button",className:"nb-btn",onClick:()=>j(null),"aria-label":"取消",children:"取消"})]})]})}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:i?fp(i):"条目"}),c.length===0&&d.jsx("div",{className:"nb-card text-sm opacity-60",children:"(无记忆)"}),c.map(ne=>d.jsxs("div",{className:"nb-card",children:[d.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)] flex-wrap",children:[d.jsx("span",{className:"nb-badge",children:ne.category}),d.jsxs("span",{children:["s",ne.salience]}),d.jsx("span",{children:"·"}),d.jsx("span",{children:ne.source}),ne.tags.map(oe=>d.jsxs("span",{children:["#",oe]},oe))]}),d.jsx("div",{className:"font-bold text-sm mt-1",children:ne.title}),d.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:ne.body.slice(0,400)}),d.jsxs("div",{className:"flex gap-2 mt-2",children:[d.jsx("button",{type:"button",className:"nb-btn nb-btn-blue text-xs",onClick:()=>j({id:ne.id,title:ne.title,body:ne.body,category:ne.category,tags:ne.tags.join(", "),salience:ne.salience}),"aria-label":"编辑",children:"编辑"}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-purple text-xs",onClick:()=>A(ne),"aria-label":"提升",children:"提升"}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-danger text-xs",onClick:()=>G(ne.id),"aria-label":"删除",children:"删除"})]}),(T==null?void 0:T.id)===ne.id&&d.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 border-t-[3px] border-[var(--color-text)] pt-2",children:[d.jsx("span",{className:"text-xs font-bold",children:"提升到:"}),be.map(oe=>d.jsx("button",{type:"button",className:"nb-btn nb-btn-mint text-xs",onClick:()=>U(ne,oe,!1),"aria-label":`复制到${fp(oe)}`,children:fp(oe)},Po(oe))),be.length===0&&d.jsx("span",{className:"text-xs opacity-60",children:"(无其它作用域)"}),d.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>A(null),"aria-label":"取消提升",children:"取消"})]})]},ne.id))]})]})}async function Cse(){return(await wt("/api/plugins")).data??[]}async function jse(e,t){return jr("/api/plugins",{spec:e})}async function Tse(e,t){return gF(`/api/plugins/${encodeURIComponent(e)}`,{disabled:t})}async function Ase(e){return mF(`/api/plugins/${encodeURIComponent(e)}`)}function Px(e){if(e instanceof rM&&e.detail&&typeof e.detail=="object"){const t=e.detail;if(t.error)return{error:t.error,kind:t.kind??"unknown",detail:t.detail}}return{error:e instanceof Error?e.message:String(e),kind:"unknown"}}const Sj={network:"装不上是网络问题 —— 检查代理或 registry 后重试。",auth:"registry 要凭据 —— 配好 npm 认证再试。","not-found":"这个名字或版本在 registry 上不存在。","not-plugin":"它装上了,但不是 Cordis 插件(没有 apply 导出)。装配档没有被改。",apply:"插件自己的代码抛了 —— 这是插件作者的问题。",conflict:"和已有的插件撞了(同名 id,或它提供的服务已经被别人占了)。"};function Nj({fail:e,title:t}){const[n,i]=_.useState(!1);return d.jsx("div",{className:"nb-card !border-[var(--color-danger)] text-sm",children:d.jsxs("div",{className:"flex items-start gap-2",children:[d.jsx(q6,{size:16,className:"mt-0.5 shrink-0 text-[var(--color-danger)]"}),d.jsxs("div",{className:"min-w-0 flex-1",children:[d.jsxs("p",{className:"font-medium",children:[t,":",e.error]}),d.jsxs("p",{className:"mt-1 text-[var(--color-text-muted)]",children:[d.jsx("code",{className:"text-xs",children:e.kind}),Sj[e.kind]?` · ${Sj[e.kind]}`:""]}),e.detail?d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:"mt-2 text-xs underline text-[var(--color-text-muted)]",onClick:()=>i(s=>!s),children:n?"收起原文":"展开原文"}),n?d.jsx("pre",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap rounded bg-black/20 p-2 text-xs",children:e.detail}):null]}):null]})]})})}function Mse({panelFor:e}){const t=Xt(),[n,i]=_.useState(""),[s,r]=_.useState(null),[o,c]=_.useState(null),[u,f]=_.useState(null),{data:p=[],isLoading:m}=Je({queryKey:["plugins"],queryFn:Cse}),b=u?p.find(C=>C.key===u)??null:null,y=C=>{r(null),c(C??null),t.invalidateQueries({queryKey:["plugins"]})},x=Dt({mutationFn:()=>jse(n.trim()),onSuccess:C=>{i(""),y(C.warning)},onError:C=>r({title:"安装失败",fail:Px(C)})}),v=Dt({mutationFn:({key:C,disabled:S})=>Tse(C,S),onSuccess:C=>y(C.warning),onError:C=>r({title:"启停失败",fail:Px(C)})}),w=Dt({mutationFn:C=>Ase(C),onSuccess:C=>y(C.warning),onError:C=>r({title:"卸载失败",fail:Px(C)})}),k=x.isPending||v.isPending||w.isPending;return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"nb-card",children:[d.jsx("label",{htmlFor:"plugin-spec",className:"text-sm font-medium",children:"装一个插件"}),d.jsxs("p",{className:"mt-1 text-xs text-[var(--color-text-muted)]",children:["填 npm 包名(可带 ",d.jsx("code",{children:"@版本"}),")或本地路径。装完**当场生效**,不用重启。"]}),d.jsxs("div",{className:"mt-3 flex gap-2",children:[d.jsx("input",{id:"plugin-spec",value:n,onChange:C=>i(C.target.value),placeholder:"@scope/coral-plugin-xxx",className:"nb-input flex-1 text-sm",disabled:k}),d.jsxs("button",{type:"button",onClick:()=>x.mutate(),disabled:k||!n.trim(),className:"nb-btn nb-btn-primary",children:[x.isPending?d.jsx(pt,{size:16,className:"animate-spin"}):d.jsx(Bn,{size:16}),"安装"]})]})]}),s?d.jsx(Nj,{fail:s.fail,title:s.title}):null,o?d.jsx(Nj,{fail:o,title:"操作完成,但有一件事没做成"}):null,m?d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"读取中…"}):d.jsx("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:p.map(C=>d.jsx(Rse,{row:C,busy:k,configurable:!!(e!=null&&e(C)),onConfig:()=>f(C.key),onToggle:()=>v.mutate({key:C.key,disabled:!C.disabled}),onRemove:()=>w.mutate(C.key)},C.key))}),b&&(e!=null&&e(b))?d.jsx(Ew,{onClose:()=>f(null),children:d.jsxs("div",{className:"flex max-h-[88vh] w-fit max-w-[min(1040px,94vw)] flex-col gap-2 overflow-y-auto",children:[d.jsx("div",{className:"flex justify-end",children:d.jsx("button",{type:"button",onClick:()=>f(null),"aria-label":"关闭配置",title:"关闭",className:"nb-btn !px-2 !py-1",children:d.jsx(vn,{size:14,strokeWidth:2.5})})}),e(b)]})}):null]})}function Rse({row:e,busy:t,configurable:n,onConfig:i,onToggle:s,onRemove:r}){const o=e.disabled?{text:"已停用",cls:"bg-[var(--color-text-muted)]/15 text-[var(--color-text-muted)]"}:e.mounted?{text:"运行中",cls:"bg-[var(--color-success)]/20 text-[var(--color-success)]"}:{text:"未挂上",cls:"bg-[var(--color-danger)]/20 text-[var(--color-danger)]"};return d.jsxs("article",{className:`nb-card relative flex flex-col gap-3 ${n?"nb-card-interactive":""}`,children:[n?d.jsx("button",{type:"button",onClick:i,"aria-label":`配置 ${e.key}`,className:"absolute inset-0 cursor-pointer rounded-[inherit] border-0 bg-transparent"}):null,d.jsxs("div",{className:"flex items-start justify-between gap-2",children:[d.jsx("h3",{className:"min-w-0 flex-1 overflow-hidden break-all font-[family-name:var(--font-heading)] text-base font-bold",children:e.key}),d.jsx("span",{className:`nb-badge shrink-0 text-[10px] ${o.cls}`,title:e.disabled?"人主动停用的":e.mounted?"这个进程里正挂着":"装配档里有它,但没挂起来 —— 多半是它启动时抛了",children:o.text})]}),d.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.category?d.jsx("span",{className:"nb-badge text-[10px]",children:e.category}):null,d.jsx("span",{className:"nb-badge text-[10px] opacity-70",children:e.layer==="factory"?"内建":"已装"})]}),d.jsx("p",{className:"line-clamp-3 text-sm leading-5 text-[var(--color-text-muted)]",children:e.description||"(无简介)"}),d.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-[var(--color-border-light)] pt-2",children:[d.jsxs("span",{className:"min-w-0 flex-1 truncate font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",title:e.pkg??e.name,children:[e.pkg??e.name,e.version?` · ${e.version}`:""]}),d.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n?d.jsx(T6,{size:13,strokeWidth:2.5,"aria-hidden":!0,className:"text-[var(--color-text-subtle)]"}):null,d.jsx("button",{type:"button",className:"nb-btn relative z-10 !px-2 !py-1",onClick:s,disabled:t,"aria-label":e.disabled?`启用 ${e.key}`:`停用 ${e.key}`,title:e.disabled?"启用":"停用",children:d.jsx(p6,{size:13,strokeWidth:2.5})}),d.jsx("button",{type:"button",className:"nb-btn relative z-10 !px-2 !py-1",onClick:r,disabled:t||e.layer==="factory","aria-label":`卸载 ${e.key}`,title:e.layer==="factory"?"内建插件不能卸载,只能停用":"卸载",children:d.jsx(cs,{size:13,strokeWidth:2.5})})]})]})]})}async function Dse(){return(await wt("/api/channels")).data??{console:{},adapters:[]}}async function Ose(e){return(await Pm("/api/channels",e)).data}function Lse(e){return wt(`/api/media-providers?capability=${encodeURIComponent(e)}`)}async function Ise(e){const t=await fetch("/api/media-providers",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return t.json()}function Pse(e){return s1(`/api/media-providers/${encodeURIComponent(e)}`)}async function zse(e,t){const n=await fetch(`/api/media-providers/default/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`${n.status}: ${await n.text()}`);return n.json()}const v0={image:"图片",video:"视频",music:"音乐",voice:"语音","3d":"3D",embedding:"向量(Embedding)",rerank:"重排(Rerank)"},Bse={image:["codex","openai","volcengine","minimax","tripo","agnes","bailian","openrouter"],video:["volcengine"],music:["minimax"],voice:["doubao"],"3d":["tripo"],embedding:["openai-compatible"],rerank:["openai-compatible"]},cI={codex:"",openai:"https://api.openai.com/v1",tripo:"https://openapi.tripo3d.ai",volcengine:"https://ark.cn-beijing.volces.com/api/v3",minimax:"https://api.minimaxi.com",doubao:"https://openspeech.bytedance.com",agnes:"https://apihub.agnes-ai.com",bailian:"https://dashscope.aliyuncs.com",openrouter:"https://openrouter.ai/api/v1","openai-compatible":""},Use=new Set(["codex"]);function Fse({capability:e}){var w,k,C;const t=Xt(),{alert:n,confirm:i}=Un(),s=Je({queryKey:["media-providers",e],queryFn:()=>Lse(e)}),[r,o]=_.useState(null),c=Bse[e]??[],u=((w=s.data)==null?void 0:w.providers)??[],f=(C=(k=s.data)==null?void 0:k.defaults)==null?void 0:C[e],p=Dt({mutationFn:S=>Ise(S),onSuccess:()=>{o(null),t.invalidateQueries({queryKey:["media-providers",e]})},onError:S=>void n({title:"保存失败",body:S instanceof Error?S.message:String(S)})}),m=Dt({mutationFn:S=>Pse(S),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:S=>void n({title:"删除失败",body:S instanceof Error?S.message:String(S)})}),b=Dt({mutationFn:S=>zse(e,S),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:S=>void n({title:"设默认失败",body:S instanceof Error?S.message:String(S)})}),y=(S,j)=>(f==null?void 0:f.providerId)===S&&(f==null?void 0:f.model)===j,x=()=>o({isNew:!0,entry:{id:"",name:"",capability:e,adapter:c[0]??"",baseUrl:c[0]?cI[c[0]]??"":"",apiKey:"",models:[]}}),v=S=>o({isNew:!1,entry:{id:S.id,name:S.name,capability:e,adapter:S.adapter,baseUrl:S.baseUrl,apiKey:"",models:S.models}});return d.jsxs("section",{className:"nb-card",children:[d.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[d.jsxs("div",{children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:[v0[e],"供应商"]}),d.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["增删该能力的第三方生成端点(adapter + Base URL + key + models)。**点模型标签设为该能力默认**;✓ = 当前默认。",f?d.jsxs(d.Fragment,{children:[" ","当前默认:",d.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:f.providerId}),f.model?d.jsxs(d.Fragment,{children:[" · ",d.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:f.model})]}):null]}):" 当前默认:未设置"]})]}),d.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",onClick:x,"aria-label":`添加${v0[e]}供应商`,children:[d.jsx(Bn,{size:14,strokeWidth:3})," 添加供应商"]})]}),d.jsxs("div",{className:"flex flex-col gap-2 mt-4",children:[s.isLoading&&d.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"})," 加载中…"]}),!s.isLoading&&u.length===0&&d.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无供应商)"}),u.map(S=>d.jsxs("div",{className:"rounded-lg px-3 py-2 border-2 border-[var(--color-text)]",children:[d.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d.jsxs("div",{className:"min-w-0",children:[d.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:S.id}),d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",S.name]}),d.jsx("span",{className:"ml-2 text-[10px] font-bold px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)]",children:S.adapter}),d.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[S.baseUrl," · key ",S.keyMasked||"未设置"]})]}),d.jsxs("div",{className:"flex gap-1 shrink-0",children:[d.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>v(S),"aria-label":`编辑 ${S.id}`,children:d.jsx(e1,{size:12,strokeWidth:3})}),d.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除供应商",body:`删除 ${S.id}?`,danger:!0})&&m.mutate(S.id)},"aria-label":`删除 ${S.id}`,children:d.jsx(cs,{size:12,strokeWidth:3})})]})]}),S.models.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:S.models.map(j=>{const T=y(S.id,j);return d.jsxs("button",{type:"button",onClick:()=>b.mutate({providerId:S.id,model:j}),disabled:b.isPending,"aria-pressed":T,className:["nb-btn px-2 py-0.5 text-xs font-[family-name:var(--font-mono)]",T?"nb-btn-mint":""].join(" "),title:T?"当前默认":"设为该能力默认",children:[j,T?" ✓":""]},j)})})]},S.id))]}),r&&d.jsx(Ew,{onClose:()=>o(null),children:d.jsx(qse,{state:r,adapters:c,onChange:S=>o({...r,entry:S}),onCancel:()=>o(null),onSave:S=>p.mutate(S),saving:p.isPending})})]})}function $se(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const s=i.trim();s&&!n.includes(s)&&n.push(s)}return n}function qse({state:e,adapters:t,onChange:n,onCancel:i,onSave:s,saving:r}){const o=e.entry,[c,u]=_.useState(""),f=y=>n({...o,...y}),p=Use.has(o.adapter),m=/^[a-zA-Z0-9_-]+$/.test(o.id)&&!!o.name.trim()&&!!o.adapter.trim()&&(p||!!o.baseUrl.trim()),b=y=>{f({adapter:y,baseUrl:cI[y]??""})};return d.jsxs("div",{className:"border-[3px] border-[var(--color-text)] rounded-2xl p-6 bg-[var(--color-bg-cream)] shadow-[6px_6px_0_var(--color-text)] flex flex-col gap-4 w-[min(92vw,640px)] max-h-[88vh] overflow-y-auto",children:[d.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增供应商":`编辑 ${o.id}`,d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:[" (",v0[o.capability],")"]})]}),d.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:o.id,disabled:!e.isNew,onChange:y=>f({id:y.target.value}),placeholder:"如 my-tripo",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",d.jsx("input",{className:"nb-input",value:o.name,onChange:y=>f({name:y.target.value}),placeholder:"显示名"})]})]}),d.jsxs("div",{className:"flex flex-col gap-1 text-sm font-bold",children:["adapter",d.jsx(Ec,{value:o.adapter,onChange:b,ariaLabel:"adapter",options:t.map(y=>({value:y,label:y}))})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",p&&"(订阅无需,可留空)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:o.baseUrl,onChange:y=>f({baseUrl:y.target.value}),placeholder:p?"订阅走本地凭据,无需填":"https://api.example.com",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",p?"(订阅无需)":!e.isNew&&"(留空=保留)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:o.apiKey??"",onChange:y=>f({apiKey:y.target.value}),placeholder:p?"订阅无需":e.isNew?"sk-...":"留空保留",spellCheck:!1})]}),d.jsxs("div",{className:"flex flex-col gap-1",children:[d.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),d.jsx(uI,{models:o.models,draft:c,onModelsChange:y=>f({models:y}),onDraftChange:u}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),d.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[d.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:i,children:"取消"}),d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!m||r,onClick:()=>s({...o,models:$se(o.models,c)}),children:[r?d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3})," 保存"]})]})]})}async function Hse(){return(await wt("/api/mcp-tools")).tools}const Vse=[{key:"plugin",labelKey:"plugins.tab.plugin"},{key:"model",labelKey:"plugins.tab.model"},{key:"tool",labelKey:"plugins.tab.tool"}];function Kse(e){return e.key==="memory"?d.jsx(Wse,{}):e.key==="im"?d.jsx(tre,{}):null}function Gse(){const e=Ye(),[t,n]=_.useState("plugin");return d.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[d.jsxs("header",{children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("plugins.h1")}),d.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:e("plugins.desc")})]}),d.jsx(au,{ariaLabel:e("plugins.h1"),className:"",value:t,onChange:n,options:Vse.map(i=>({value:i.key,label:e(i.labelKey)}))}),d.jsx("div",{role:"tabpanel",children:t==="plugin"?d.jsx(Mse,{panelFor:Kse}):t==="model"?d.jsx(Qse,{}):d.jsx(are,{})})]})}function Wse(){var x,v,w;const e=Ye(),t=Xt(),{alert:n}=Un(),i=Je({queryKey:["system-memory"],queryFn:xF}),[s,r]=_.useState(null),[o,c]=_.useState(null);_.useEffect(()=>{i.data&&s===null&&(r(i.data.provider),c(i.data.url))},[i.data,s]);const u=s??((x=i.data)==null?void 0:x.provider)??"agentmemory",f=o??((v=i.data)==null?void 0:v.url)??"",p=i.data!=null&&(u!==i.data.provider||u==="custom"&&f!==i.data.url),m=k=>{const C=`system.memory.opt.${k}`;return e(C)},b=Dt({mutationFn:()=>vF(u,u==="custom"?f:""),onSuccess:()=>{t.invalidateQueries({queryKey:["system-memory"]}),t.invalidateQueries({queryKey:["system-env"]})},onError:k=>{n({title:e("system.memory.error"),body:k instanceof Error?k.message:String(k)})}}),y=((w=i.data)==null?void 0:w.options)??["none","builtin","agentmemory","custom"];return d.jsxs("section",{className:"nb-card",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:e("system.memory.title")}),d.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-3",children:e("system.memory.desc")}),d.jsxs("div",{className:"flex flex-col gap-3 max-w-md",children:[d.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[d.jsx("span",{className:"font-bold",children:e("system.memory.provider")}),d.jsx(Ec,{value:u,onChange:r,ariaLabel:e("system.memory.provider"),options:y.map(k=>({value:k,label:m(k)}))})]}),u==="custom"&&d.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[d.jsx("span",{className:"font-bold",children:e("system.memory.url")}),d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",type:"text",value:f,onChange:k=>c(k.target.value),placeholder:e("system.memory.url.placeholder"),spellCheck:!1,"aria-label":e("system.memory.url")})]}),d.jsx("div",{className:"flex justify-end",children:d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px",fontSize:12},onClick:()=>b.mutate(),disabled:!p||b.isPending,type:"button","aria-label":e("system.memory.save.aria"),children:[b.isPending?d.jsx(pt,{size:12,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:12,strokeWidth:3}),b.isSuccess&&!p?e("system.memory.saved"):e("system.memory.save")]})})]})]})}const Yse=[{key:"llm",label:"sps agent"},{key:"image",label:"图片"},{key:"video",label:"视频"},{key:"music",label:"音乐"},{key:"voice",label:"语音"},{key:"3d",label:"3D"},{key:"embedding",label:"Embedding"},{key:"rerank",label:"Rerank"}];function Xse(){const e=Ye(),t=Xt(),n=_.useRef(null),[i,s]=_.useState(!1),r=async()=>{s(!0);try{const c=await wt("/api/model-config/export"),u=new Blob([JSON.stringify(c,null,2)],{type:"application/json"}),f=document.createElement("a");f.href=URL.createObjectURL(u),f.download=`sps-model-config-${new Date().toISOString().slice(0,10)}.json`,f.click(),URL.revokeObjectURL(f.href)}catch(c){window.alert(`${e("plugins.model.export.failed")}: ${c instanceof Error?c.message:String(c)}`)}finally{s(!1)}},o=async c=>{s(!0);try{const u=JSON.parse(await c.text());if(!window.confirm(e("plugins.model.import.confirm")))return;const p=(await jr("/api/model-config/import",u)).summary;window.alert(e("plugins.model.import.done",{llm:String(Number(p.llmAnthropic??0)+Number(p.llmOpenai??0)),media:String(p.media??0),skipped:String(p.skipped??0)})),t.invalidateQueries()}catch(u){window.alert(`${e("plugins.model.import.failed")}: ${u instanceof Error?u.message:String(u)}`)}finally{s(!1),n.current&&(n.current.value="")}};return d.jsxs("div",{className:"flex gap-2 items-center ml-auto",children:[d.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px"},disabled:i,onClick:()=>void r(),title:e("plugins.model.export.hint"),children:[d.jsx($A,{size:14,strokeWidth:2.5})," ",e("plugins.model.export")]}),d.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px"},disabled:i,onClick:()=>{var c;return(c=n.current)==null?void 0:c.click()},title:e("plugins.model.import.hint"),children:[d.jsx(n1,{size:14,strokeWidth:2.5})," ",e("plugins.model.import")]}),d.jsx("input",{ref:n,type:"file",accept:"application/json,.json",className:"hidden",onChange:c=>{var f;const u=(f=c.target.files)==null?void 0:f[0];u&&o(u)}})]})}function Qse(){const[e,t]=_.useState("llm");return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"flex flex-wrap gap-2 items-center",role:"tablist","aria-label":"模型/资源供应商",children:[Yse.map(n=>{const i=e===n.key;return d.jsx("button",{type:"button",role:"tab","aria-selected":i,onClick:()=>t(n.key),className:["nb-btn",i?"nb-btn-primary":""].join(" "),style:{padding:"6px 14px"},children:n.label},n.key)}),d.jsx(Xse,{})]}),e==="llm"?d.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["Anthropic 兼容 ",d.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 Claude 订阅"})]}),d.jsx(_j,{only:"anthropic"})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["OpenAI 兼容 ",d.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 codex 订阅"})]}),d.jsx(_j,{only:"openai"})]})]}):d.jsx(Fse,{capability:e})]})}function _j({only:e}={}){var C,S,j;const t=Xt(),{alert:n,confirm:i}=Un(),s=Je({queryKey:["providers"],queryFn:j1}),o=(C=Je({queryKey:["system-agents"],queryFn:r1}).data)==null?void 0:C.agents,[c,u]=_.useState(null),f=Dt({mutationFn:T=>kY(c.kind,T),onSuccess:()=>{u(null),t.invalidateQueries({queryKey:["providers"]})},onError:T=>void n({title:"保存失败",body:T instanceof Error?T.message:String(T)})}),p=Dt({mutationFn:T=>SY(T.kind,T.id),onSuccess:()=>void t.invalidateQueries({queryKey:["providers"]}),onError:T=>void n({title:"删除失败",body:T instanceof Error?T.message:String(T)})}),m=Dt({mutationFn:T=>wF(T),onSuccess:()=>void t.invalidateQueries({queryKey:["system-agents"]}),onError:T=>void n({title:"设默认失败",body:T instanceof Error?T.message:String(T)})}),b=(T,A,M)=>{if(!o)return!1;const R=T==="anthropic"?o.worker:o.reviewer;return(R.providerId||"official")===A&&R.model===M},y=(T,A,M)=>{if(!o)return;let R;if(T==="anthropic"){const P={...o.worker,model:M};A==="official"?delete P.providerId:P.providerId=A,R={...o,worker:P}}else R={...o,reviewer:{...o.reviewer,providerId:A,model:M}};m.mutate(R)},x=[{kind:"anthropic",title:"Anthropic 兼容(worker / claude)",items:((S=s.data)==null?void 0:S.anthropic)??[]},{kind:"openai",title:"OpenAI 兼容(reviewer / openai agent)",items:((j=s.data)==null?void 0:j.openai)??[]}],v=e?x.filter(T=>T.kind===e):x,w=T=>u({kind:T,isNew:!0,entry:{id:"",name:"",baseUrl:"",apiKey:"",models:[]}}),k=(T,A)=>u({kind:T,isNew:!1,entry:{id:A.id,name:A.name,baseUrl:A.baseUrl,apiKey:"",models:A.models}});return d.jsxs("section",{className:"nb-card",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:"模型 API 端点"}),d.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-4",children:"本地官方订阅(已登录验证)自动置顶,不可编辑;下方可增删第三方兼容端点。**点模型标签设为默认**(anthropic→worker / openai→监工);✓ = 当前默认。"}),d.jsx("div",{className:["grid grid-cols-1 gap-5",e?"":"lg:grid-cols-2"].join(" "),children:v.map(T=>d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("span",{className:"font-bold text-sm",children:T.title}),d.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:()=>w(T.kind),"aria-label":`添加 ${T.title} 端点`,children:[d.jsx(Bn,{size:12,strokeWidth:3})," 添加"]})]}),T.items.length===0&&d.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无端点)"}),T.items.map(A=>d.jsxs("div",{className:["rounded-lg px-3 py-2 border-2",(A.builtin,"border-[var(--color-text)]")].join(" "),children:[d.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d.jsxs("div",{className:"min-w-0",children:[d.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:A.id}),d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",A.name]}),A.builtin?d.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:["本地订阅",A.detail?` · ${A.detail}`:""," · 已验证可用"]}):d.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[A.baseUrl," · key ",A.hasKey?A.apiKey:"未设置"]})]}),A.builtin?d.jsx("span",{className:"shrink-0 text-[10px] font-bold px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)]",children:"内置"}):d.jsxs("div",{className:"flex gap-1 shrink-0",children:[d.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>k(T.kind,A),"aria-label":`编辑 ${A.id}`,children:d.jsx(e1,{size:12,strokeWidth:3})}),d.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除端点",body:`删除 ${A.id}?`,danger:!0})&&p.mutate({kind:T.kind,id:A.id})},"aria-label":`删除 ${A.id}`,children:d.jsx(cs,{size:12,strokeWidth:3})})]})]}),A.models.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:A.models.map(M=>{const R=b(T.kind,A.id,M);return d.jsxs("button",{type:"button",onClick:()=>y(T.kind,A.id,M),disabled:m.isPending,"aria-pressed":R,className:["nb-btn px-2 py-0.5 text-xs font-[family-name:var(--font-mono)]",R?"nb-btn-mint":""].join(" "),title:R?"当前默认":"设为默认",children:[M,R?" ✓":""]},M)})})]},A.id))]},T.kind))}),c&&d.jsx(Ew,{onClose:()=>u(null),children:d.jsx(Zse,{state:c,onChange:T=>u({...c,entry:T}),onCancel:()=>u(null),onSave:T=>f.mutate(T),saving:f.isPending})})]})}function w0(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const s=i.trim();s&&!n.includes(s)&&n.push(s)}return n}function uI({models:e,draft:t,onModelsChange:n,onDraftChange:i}){const s=r=>{n(w0(e,r)),i("")};return d.jsxs("div",{className:"nb-input min-h-[46px] w-full flex flex-wrap gap-1.5 items-center px-2.5 py-2",children:[e.map(r=>d.jsxs("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-md border border-[var(--color-border-light)] bg-[var(--surface-control)] px-2 py-1 text-xs font-[family-name:var(--font-mono)]",children:[d.jsx("span",{className:"max-w-[480px] truncate",children:r}),d.jsx("button",{type:"button",className:"shrink-0 text-[var(--color-text-muted)] hover:text-[var(--color-text)]",onClick:()=>n(e.filter(o=>o!==r)),"aria-label":`删除模型 ${r}`,children:d.jsx(vn,{size:12,strokeWidth:2.5})})]},r)),d.jsx("input",{id:"provider-models",className:"min-w-[180px] flex-1 bg-transparent px-1 py-0.5 text-sm outline-none font-[family-name:var(--font-mono)]",value:t,onChange:r=>{const o=r.target.value,c=o.split(/[,,\n\r]/);if(c.length===1){i(o);return}const u=c.pop()??"";n(w0(e,c.join(","))),i(u)},onKeyDown:r=>{r.key==="Enter"&&!r.nativeEvent.isComposing?(r.preventDefault(),s(t)):r.key==="Backspace"&&!t&&e.length>0&&n(e.slice(0,-1))},placeholder:e.length>0?"继续添加模型":"输入模型名后按 Enter","aria-label":"Models",spellCheck:!1})]})}function Zse({state:e,onChange:t,onCancel:n,onSave:i,saving:s}){const r=e.entry,[o,c]=_.useState(""),u=p=>t({...r,...p}),f=/^[a-zA-Z0-9_-]+$/.test(r.id)&&r.name.trim()&&r.baseUrl.trim();return d.jsxs("div",{className:"border-[3px] border-[var(--color-text)] rounded-2xl p-6 bg-[var(--color-bg-cream)] shadow-[6px_6px_0_var(--color-text)] flex flex-col gap-4 w-[min(92vw,640px)] max-h-[88vh] overflow-y-auto",children:[d.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增端点":`编辑 ${r.id}`,d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:["(",e.kind,")"]})]}),d.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:r.id,disabled:!e.isNew,onChange:p=>u({id:p.target.value}),placeholder:"如 my-openai",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",d.jsx("input",{className:"nb-input",value:r.name,onChange:p=>u({name:p.target.value}),placeholder:"显示名"})]})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:r.baseUrl,onChange:p=>u({baseUrl:p.target.value}),placeholder:"https://api.example.com/v1",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",!e.isNew&&"(留空=保留)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:r.apiKey??"",onChange:p=>u({apiKey:p.target.value}),placeholder:e.isNew?"sk-...":"••••(留空不改)",spellCheck:!1})]}),d.jsxs("div",{className:"flex flex-col gap-1",children:[d.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),d.jsx(uI,{models:r.models,draft:o,onModelsChange:p=>u({models:p}),onDraftChange:c}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),d.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[d.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:n,children:"取消"}),d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!f||s,onClick:()=>i({...r,models:w0(r.models,o)}),children:[s?d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3})," 保存"]})]})]})}function Ew({children:e,onClose:t}){return IA.createPortal(d.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/50 p-4",onClick:t,children:d.jsx("div",{onClick:n=>n.stopPropagation(),children:e})}),document.body)}const Jse=["telegram","dingtalk","matrix","slack","discord","feishu"],Vd={telegram:"Telegram",dingtalk:"钉钉 (Stream)",matrix:"Matrix",slack:"Slack",discord:"Discord",feishu:"飞书 / Lark"},ere={telegram:[{key:"token",label:"Bot Token(@BotFather)",type:"password",placeholder:"123456:ABC-..."},{key:"allowedChatIds",label:"允许的 Chat ID(白名单,空=全放)",type:"list",placeholder:"逗号/换行分隔"}],dingtalk:[{key:"clientId",label:"Client ID(AppKey)",type:"text"},{key:"clientSecret",label:"Client Secret(AppSecret)",type:"password"},{key:"allowedConversations",label:"允许的会话 ID(白名单,空=全放)",type:"list"}],matrix:[{key:"homeserver",label:"Homeserver URL",type:"text",placeholder:"https://matrix.org"},{key:"accessToken",label:"Access Token",type:"password"},{key:"allowedRooms",label:"允许的 Room ID(白名单,空=全放)",type:"list"}],slack:[{key:"appToken",label:"App Token(xapp-,Socket Mode)",type:"password",placeholder:"xapp-..."},{key:"botToken",label:"Bot Token(xoxb-)",type:"password",placeholder:"xoxb-..."},{key:"allowedChannels",label:"允许的 Channel(白名单,空=全放)",type:"list"}],discord:[{key:"token",label:"Bot Token",type:"password"},{key:"allowedChannels",label:"允许的 Channel ID(白名单,空=全放)",type:"list"}],feishu:[{key:"appId",label:"App ID",type:"text"},{key:"appSecret",label:"App Secret",type:"password"},{key:"verificationToken",label:"Verification Token",type:"text"},{key:"encryptKey",label:"Encrypt Key(设了则事件 AES 解密)",type:"password"},{key:"port",label:"本机监听端口(默认 9800)",type:"number",placeholder:"9800"},{key:"path",label:"监听路径(默认 /feishu)",type:"text",placeholder:"/feishu"},{key:"allowedChats",label:"允许的 chat_id(白名单,空=全放)",type:"list"}]};function tre(){var x,v,w;const e=Xt(),{alert:t}=Un(),n=Je({queryKey:["channels"],queryFn:Dse}),[i,s]=_.useState(null),[r,o]=_.useState({type:"console"});_.useEffect(()=>{n.data&&!i&&s({console:n.data.console??{},adapters:n.data.adapters??[]})},[n.data,i]);const c=Dt({mutationFn:()=>Ose(i),onSuccess:k=>{s({console:k.console??{},adapters:k.adapters??[]}),e.invalidateQueries({queryKey:["channels"]})},onError:k=>void t({title:"保存失败",body:k instanceof Error?k.message:String(k)})});if(!i)return d.jsx("section",{className:"nb-card",children:d.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"})," 加载频道配置…"]})});const u=i.adapters??[],f=JSON.stringify(i)!==JSON.stringify({console:((x=n.data)==null?void 0:x.console)??{},adapters:((v=n.data)==null?void 0:v.adapters)??[]}),p=k=>{const C=[...u,{kind:k,enabled:!0}];s({...i,adapters:C}),o({type:"adapter",index:C.length-1})},m=k=>{const C=u.filter((S,j)=>j!==k);s({...i,adapters:C}),o({type:"console"})},b=(k,C)=>{const S=u.map((j,T)=>T===k?{...j,...C}:j);s({...i,adapters:S})},y=k=>s({...i,console:{...i.console,...k}});return d.jsxs("section",{className:"nb-card",children:[d.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[d.jsxs("div",{children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"频道(IM 网关)"}),d.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["接入 Telegram / 钉钉 / 飞书 / Slack / Discord / Matrix。左侧选频道,右侧改设置。保存后 ",d.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps im"})," 重启生效。"]})]}),d.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",disabled:!f||c.isPending,onClick:()=>c.mutate(),"aria-label":"保存频道配置",children:[c.isPending?d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3})," 保存"]})]}),d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[220px_1fr] gap-5 mt-4",children:[d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] p-2 flex flex-col gap-1",children:[d.jsx(Cj,{label:"console 桥接",sub:((w=i.console)==null?void 0:w.url)||"未配置",active:r.type==="console",onClick:()=>o({type:"console"})}),d.jsx("div",{className:"h-px bg-[var(--color-text)] opacity-15 my-0.5"}),u.length===0&&d.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-2 py-1",children:"(无频道)"}),u.map((k,C)=>d.jsx(Cj,{label:Vd[k.kind]??k.kind,sub:k.enabled===!1?"已停用":"启用",active:r.type==="adapter"&&r.index===C,onClick:()=>o({type:"adapter",index:C})},C))]}),d.jsx(nre,{onAdd:p})]}),d.jsx("div",{className:"border-2 bg-surface-input border-[var(--color-text)] rounded-xl p-4 bg-[var(--color-bg-cream)]",children:(()=>{if(r.type!=="adapter")return d.jsx(jj,{console:i.console??{},onChange:y});const k=u[r.index];if(!k)return d.jsx(jj,{console:i.console??{},onChange:y});const C=r.index;return d.jsx(ire,{adapter:k,onChange:S=>b(C,S),onRemove:()=>m(C)})})()})]})]})}function nre({onAdd:e}){const[t,n]=_.useState(!1),i=_.useRef(null),s=_.useRef(null);return _.useEffect(()=>{const r=o=>{var c;(c=i.current)!=null&&c.contains(o.target)||n(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[]),d.jsxs("div",{className:"relative",ref:i,children:[d.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary w-full justify-center",onClick:()=>n(r=>!r),"aria-expanded":t,"aria-label":"添加频道",children:[d.jsx(Bn,{size:13,strokeWidth:3})," 添加频道",d.jsx(uo,{size:13,strokeWidth:2.5,className:["transition-transform",t?"rotate-180":""].join(" ")})]}),t&&d.jsx("div",{className:"absolute z-30 mt-2 left-0 min-w-full nb-card p-1 overflow-hidden bg-[var(--surface-menu)]",children:d.jsx("div",{ref:s,className:"max-h-[50vh] overflow-y-auto",children:Jse.map((r,o)=>d.jsx(ru,{index:o,root:s,delay:.02,children:d.jsxs("button",{type:"button",className:"dimension-menu-item w-full text-left px-4 py-2 text-sm font-semibold flex items-center gap-2",onClick:()=>{e(r),n(!1)},"aria-label":`添加 ${Vd[r]} 频道`,children:[d.jsx(Bn,{size:12,strokeWidth:3,className:"shrink-0"})," ",Vd[r]]})},r))})})]})}function Cj({label:e,sub:t,active:n,onClick:i}){return d.jsxs("button",{type:"button",onClick:i,"aria-pressed":n,className:["dimension-menu-item flex-col items-start gap-0.5 px-3 py-2 text-left",n?"dimension-menu-item-active":""].join(" "),children:[d.jsx("div",{className:"font-bold text-sm",children:e}),d.jsx("div",{className:"text-xs text-[var(--color-text-muted)] truncate w-full font-[family-name:var(--font-mono)]",children:t})]})}function jj({console:e,onChange:t}){return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{children:[d.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"console 桥接"}),d.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:"IM 纯文本消息桥接到项目 agent 对话。设了 URL 才启用桥接;token 为 console 鉴权令牌。"})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console URL",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:e.url??"",onChange:n=>t({url:n.target.value}),placeholder:"http://localhost:4321",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console Token(SPS_CONSOLE_TOKEN)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:e.token??"",onChange:n=>t({token:n.target.value}),placeholder:"鉴权令牌(可空)",spellCheck:!1})]}),d.jsxs("div",{className:"flex flex-col gap-1 text-sm font-bold",children:["对话后端",d.jsx(Ec,{value:e.agentKind??"claude",onChange:n=>t({agentKind:n}),ariaLabel:"对话后端",options:[{value:"claude",label:"claude"},{value:"openai",label:"openai"}]})]})]})}function ire({adapter:e,onChange:t,onRemove:n}){const{confirm:i}=Un(),s=ere[e.kind]??[],r=e.enabled!==!1;return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"flex items-start justify-between gap-2",children:[d.jsxs("div",{children:[d.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:Vd[e.kind]??e.kind}),d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-[family-name:var(--font-mono)]",children:[" · ",e.kind]})]}),d.jsxs("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:async()=>{await i({title:"删除频道",body:`删除 ${Vd[e.kind]??e.kind} 频道?`,danger:!0})&&n()},"aria-label":"删除频道",children:[d.jsx(cs,{size:12,strokeWidth:3})," 删除"]})]}),d.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[d.jsx("input",{type:"checkbox",checked:r,onChange:o=>t({enabled:o.target.checked})}),"启用此频道"]}),s.map(o=>d.jsx(sre,{spec:o,value:e[o.key],onChange:c=>t({[o.key]:c})},o.key))]})}function sre({spec:e,value:t,onChange:n}){if(e.type==="list"){const i=Array.isArray(t)?t.map(String):[];return d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,d.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",rows:2,value:i.join(", "),onChange:s=>{const r=s.target.value.split(/[,\n]/).map(o=>o.trim()).filter(Boolean);n(r.length?r:void 0)},placeholder:e.placeholder,spellCheck:!1})]})}return d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:e.type==="password"?"password":"text",value:t==null?"":String(t),onChange:i=>{const s=i.target.value;e.type==="number"?n(s.trim()===""?void 0:Number(s)):n(s===""?void 0:s)},placeholder:e.placeholder,spellCheck:!1})]})}const rre=["skill","asset","project","interaction","memory","agent","other"];function are(){const e=Ye(),t=Je({queryKey:["mcp-tools"],queryFn:Hse});if(t.isLoading)return d.jsx("section",{className:"nb-card",children:d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.loading")})});if(t.isError)return d.jsx("section",{className:"nb-card",children:d.jsxs("p",{className:"text-sm text-[var(--color-crashed)]",children:[e("plugins.tool.failed"),":",t.error instanceof Error?t.error.message:String(t.error)]})});const n=t.data??[],i=rre.map(s=>({key:s,items:n.filter(r=>r.group===s)})).filter(s=>s.items.length>0);return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsx("section",{className:"nb-card",children:d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.desc",{count:String(n.length)})})}),i.map(s=>d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:[e(`plugins.tool.group.${s.key}`),d.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)] ml-2",children:s.items.length})]}),d.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:s.items.map(r=>d.jsxs("section",{className:"nb-card flex flex-col gap-2",children:[d.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[d.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold",children:r.name}),!r.viaMcpOnOpenai&&d.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] bg-[var(--color-secondary)]",children:e("plugins.tool.nativeOnOpenai")})]}),d.jsx("p",{className:"text-sm leading-5",children:r.description}),r.params.length>0&&d.jsx("ul",{className:"flex flex-col gap-1 m-0 p-0 list-none",children:r.params.map(o=>d.jsxs("li",{className:"text-xs text-[var(--color-text-muted)] leading-4",children:[d.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[var(--color-text)]",children:o.name}),d.jsx("span",{className:"ml-1",children:o.type}),o.required&&d.jsx("span",{className:"ml-1 font-bold",children:e("plugins.tool.required")}),o.description&&d.jsxs("span",{className:"ml-1",children:["— ",o.description]})]},o.name))}),d.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",children:r.qualifiedName})]},r.name))})]},s.key))]})}function Wn(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,i;n<e.length;n++)(i=Wn(e[n]))!==""&&(t+=(t&&" ")+i);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var ore={value:()=>{}};function ug(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new Fp(n)}function Fp(e){this._=e}function lre(e,t){return e.trim().split(/^|\s+/).map(function(n){var i="",s=n.indexOf(".");if(s>=0&&(i=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}Fp.prototype=ug.prototype={constructor:Fp,on:function(e,t){var n=this._,i=lre(e+"",n),s,r=-1,o=i.length;if(arguments.length<2){for(;++r<o;)if((s=(e=i[r]).type)&&(s=cre(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++r<o;)if(s=(e=i[r]).type)n[s]=Tj(n[s],e.name,t);else if(t==null)for(s in n)n[s]=Tj(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Fp(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),i=0,s,r;i<s;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(r=this._[e],i=0,s=r.length;i<s;++i)r[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],s=0,r=i.length;s<r;++s)i[s].value.apply(t,n)}};function cre(e,t){for(var n=0,i=e.length,s;n<i;++n)if((s=e[n]).name===t)return s.value}function Tj(e,t,n){for(var i=0,s=e.length;i<s;++i)if(e[i].name===t){e[i]=ore,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var E0="http://www.w3.org/1999/xhtml";const Aj={svg:"http://www.w3.org/2000/svg",xhtml:E0,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function dg(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Aj.hasOwnProperty(t)?{space:Aj[t],local:e}:e}function ure(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===E0&&t.documentElement.namespaceURI===E0?t.createElement(e):t.createElementNS(n,e)}}function dre(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function dI(e){var t=dg(e);return(t.local?dre:ure)(t)}function fre(){}function kw(e){return e==null?fre:function(){return this.querySelector(e)}}function hre(e){typeof e!="function"&&(e=kw(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=new Array(o),u,f,p=0;p<o;++p)(u=r[p])&&(f=e.call(u,u.__data__,p,r))&&("__data__"in u&&(f.__data__=u.__data__),c[p]=f);return new os(i,this._parents)}function pre(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function mre(){return[]}function fI(e){return e==null?mre:function(){return this.querySelectorAll(e)}}function gre(e){return function(){return pre(e.apply(this,arguments))}}function yre(e){typeof e=="function"?e=gre(e):e=fI(e);for(var t=this._groups,n=t.length,i=[],s=[],r=0;r<n;++r)for(var o=t[r],c=o.length,u,f=0;f<c;++f)(u=o[f])&&(i.push(e.call(u,u.__data__,f,o)),s.push(u));return new os(i,s)}function hI(e){return function(){return this.matches(e)}}function pI(e){return function(t){return t.matches(e)}}var bre=Array.prototype.find;function xre(e){return function(){return bre.call(this.children,e)}}function vre(){return this.firstElementChild}function wre(e){return this.select(e==null?vre:xre(typeof e=="function"?e:pI(e)))}var Ere=Array.prototype.filter;function kre(){return Array.from(this.children)}function Sre(e){return function(){return Ere.call(this.children,e)}}function Nre(e){return this.selectAll(e==null?kre:Sre(typeof e=="function"?e:pI(e)))}function _re(e){typeof e!="function"&&(e=hI(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=[],u,f=0;f<o;++f)(u=r[f])&&e.call(u,u.__data__,f,r)&&c.push(u);return new os(i,this._parents)}function mI(e){return new Array(e.length)}function Cre(){return new os(this._enter||this._groups.map(mI),this._parents)}function Em(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Em.prototype={constructor:Em,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 jre(e){return function(){return e}}function Tre(e,t,n,i,s,r){for(var o=0,c,u=t.length,f=r.length;o<f;++o)(c=t[o])?(c.__data__=r[o],i[o]=c):n[o]=new Em(e,r[o]);for(;o<u;++o)(c=t[o])&&(s[o]=c)}function Are(e,t,n,i,s,r,o){var c,u,f=new Map,p=t.length,m=r.length,b=new Array(p),y;for(c=0;c<p;++c)(u=t[c])&&(b[c]=y=o.call(u,u.__data__,c,t)+"",f.has(y)?s[c]=u:f.set(y,u));for(c=0;c<m;++c)y=o.call(e,r[c],c,r)+"",(u=f.get(y))?(i[c]=u,u.__data__=r[c],f.delete(y)):n[c]=new Em(e,r[c]);for(c=0;c<p;++c)(u=t[c])&&f.get(b[c])===u&&(s[c]=u)}function Mre(e){return e.__data__}function Rre(e,t){if(!arguments.length)return Array.from(this,Mre);var n=t?Are:Tre,i=this._parents,s=this._groups;typeof e!="function"&&(e=jre(e));for(var r=s.length,o=new Array(r),c=new Array(r),u=new Array(r),f=0;f<r;++f){var p=i[f],m=s[f],b=m.length,y=Dre(e.call(p,p&&p.__data__,f,i)),x=y.length,v=c[f]=new Array(x),w=o[f]=new Array(x),k=u[f]=new Array(b);n(p,m,v,w,k,y,t);for(var C=0,S=0,j,T;C<x;++C)if(j=v[C]){for(C>=S&&(S=C+1);!(T=w[S])&&++S<x;);j._next=T||null}}return o=new os(o,i),o._enter=c,o._exit=u,o}function Dre(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Ore(){return new os(this._exit||this._groups.map(mI),this._parents)}function Lre(e,t,n){var i=this.enter(),s=this,r=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?r.remove():n(r),i&&s?i.merge(s).order():s}function Ire(e){for(var t=e.selection?e.selection():e,n=this._groups,i=t._groups,s=n.length,r=i.length,o=Math.min(s,r),c=new Array(s),u=0;u<o;++u)for(var f=n[u],p=i[u],m=f.length,b=c[u]=new Array(m),y,x=0;x<m;++x)(y=f[x]||p[x])&&(b[x]=y);for(;u<s;++u)c[u]=n[u];return new os(c,this._parents)}function Pre(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var i=e[t],s=i.length-1,r=i[s],o;--s>=0;)(o=i[s])&&(r&&o.compareDocumentPosition(r)^4&&r.parentNode.insertBefore(o,r),r=o);return this}function zre(e){e||(e=Bre);function t(m,b){return m&&b?e(m.__data__,b.__data__):!m-!b}for(var n=this._groups,i=n.length,s=new Array(i),r=0;r<i;++r){for(var o=n[r],c=o.length,u=s[r]=new Array(c),f,p=0;p<c;++p)(f=o[p])&&(u[p]=f);u.sort(t)}return new os(s,this._parents).order()}function Bre(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Ure(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Fre(){return Array.from(this)}function $re(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,r=i.length;s<r;++s){var o=i[s];if(o)return o}return null}function qre(){let e=0;for(const t of this)++e;return e}function Hre(){return!this.node()}function Vre(e){for(var t=this._groups,n=0,i=t.length;n<i;++n)for(var s=t[n],r=0,o=s.length,c;r<o;++r)(c=s[r])&&e.call(c,c.__data__,r,s);return this}function Kre(e){return function(){this.removeAttribute(e)}}function Gre(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Wre(e,t){return function(){this.setAttribute(e,t)}}function Yre(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Xre(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Qre(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 Zre(e,t){var n=dg(e);if(arguments.length<2){var i=this.node();return n.local?i.getAttributeNS(n.space,n.local):i.getAttribute(n)}return this.each((t==null?n.local?Gre:Kre:typeof t=="function"?n.local?Qre:Xre:n.local?Yre:Wre)(n,t))}function gI(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Jre(e){return function(){this.style.removeProperty(e)}}function eae(e,t,n){return function(){this.style.setProperty(e,t,n)}}function tae(e,t,n){return function(){var i=t.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,n)}}function nae(e,t,n){return arguments.length>1?this.each((t==null?Jre:typeof t=="function"?tae:eae)(e,t,n??"")):Vc(this.node(),e)}function Vc(e,t){return e.style.getPropertyValue(t)||gI(e).getComputedStyle(e,null).getPropertyValue(t)}function iae(e){return function(){delete this[e]}}function sae(e,t){return function(){this[e]=t}}function rae(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function aae(e,t){return arguments.length>1?this.each((t==null?iae:typeof t=="function"?rae:sae)(e,t)):this.node()[e]}function yI(e){return e.trim().split(/^|\s+/)}function Sw(e){return e.classList||new bI(e)}function bI(e){this._node=e,this._names=yI(e.getAttribute("class")||"")}bI.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 xI(e,t){for(var n=Sw(e),i=-1,s=t.length;++i<s;)n.add(t[i])}function vI(e,t){for(var n=Sw(e),i=-1,s=t.length;++i<s;)n.remove(t[i])}function oae(e){return function(){xI(this,e)}}function lae(e){return function(){vI(this,e)}}function cae(e,t){return function(){(t.apply(this,arguments)?xI:vI)(this,e)}}function uae(e,t){var n=yI(e+"");if(arguments.length<2){for(var i=Sw(this.node()),s=-1,r=n.length;++s<r;)if(!i.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?cae:t?oae:lae)(n,t))}function dae(){this.textContent=""}function fae(e){return function(){this.textContent=e}}function hae(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function pae(e){return arguments.length?this.each(e==null?dae:(typeof e=="function"?hae:fae)(e)):this.node().textContent}function mae(){this.innerHTML=""}function gae(e){return function(){this.innerHTML=e}}function yae(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function bae(e){return arguments.length?this.each(e==null?mae:(typeof e=="function"?yae:gae)(e)):this.node().innerHTML}function xae(){this.nextSibling&&this.parentNode.appendChild(this)}function vae(){return this.each(xae)}function wae(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Eae(){return this.each(wae)}function kae(e){var t=typeof e=="function"?e:dI(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function Sae(){return null}function Nae(e,t){var n=typeof e=="function"?e:dI(e),i=t==null?Sae:typeof t=="function"?t:kw(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})}function _ae(){var e=this.parentNode;e&&e.removeChild(this)}function Cae(){return this.each(_ae)}function jae(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Tae(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Aae(e){return this.select(e?Tae:jae)}function Mae(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Rae(e){return function(t){e.call(this,t,this.__data__)}}function Dae(e){return e.trim().split(/^|\s+/).map(function(t){var n="",i=t.indexOf(".");return i>=0&&(n=t.slice(i+1),t=t.slice(0,i)),{type:t,name:n}})}function Oae(e){return function(){var t=this.__on;if(t){for(var n=0,i=-1,s=t.length,r;n<s;++n)r=t[n],(!e.type||r.type===e.type)&&r.name===e.name?this.removeEventListener(r.type,r.listener,r.options):t[++i]=r;++i?t.length=i:delete this.__on}}}function Lae(e,t,n){return function(){var i=this.__on,s,r=Rae(t);if(i){for(var o=0,c=i.length;o<c;++o)if((s=i[o]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=r,s.options=n),s.value=t;return}}this.addEventListener(e.type,r,n),s={type:e.type,name:e.name,value:t,listener:r,options:n},i?i.push(s):this.__on=[s]}}function Iae(e,t,n){var i=Dae(e+""),s,r=i.length,o;if(arguments.length<2){var c=this.node().__on;if(c){for(var u=0,f=c.length,p;u<f;++u)for(s=0,p=c[u];s<r;++s)if((o=i[s]).type===p.type&&o.name===p.name)return p.value}return}for(c=t?Lae:Oae,s=0;s<r;++s)this.each(c(i[s],t,n));return this}function wI(e,t,n){var i=gI(e),s=i.CustomEvent;typeof s=="function"?s=new s(t,n):(s=i.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function Pae(e,t){return function(){return wI(this,e,t)}}function zae(e,t){return function(){return wI(this,e,t.apply(this,arguments))}}function Bae(e,t){return this.each((typeof t=="function"?zae:Pae)(e,t))}function*Uae(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,r=i.length,o;s<r;++s)(o=i[s])&&(yield o)}var EI=[null];function os(e,t){this._groups=e,this._parents=t}function _f(){return new os([[document.documentElement]],EI)}function Fae(){return this}os.prototype=_f.prototype={constructor:os,select:hre,selectAll:yre,selectChild:wre,selectChildren:Nre,filter:_re,data:Rre,enter:Cre,exit:Ore,join:Lre,merge:Ire,selection:Fae,order:Pre,sort:zre,call:Ure,nodes:Fre,node:$re,size:qre,empty:Hre,each:Vre,attr:Zre,style:nae,property:aae,classed:uae,text:pae,html:bae,raise:vae,lower:Eae,append:kae,insert:Nae,remove:Cae,clone:Aae,datum:Mae,on:Iae,dispatch:Bae,[Symbol.iterator]:Uae};function ss(e){return typeof e=="string"?new os([[document.querySelector(e)]],[document.documentElement]):new os([[e]],EI)}function $ae(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Gs(e,t){if(e=$ae(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var i=n.createSVGPoint();return i.x=e.clientX,i.y=e.clientY,i=i.matrixTransform(t.getScreenCTM().inverse()),[i.x,i.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const qae={passive:!1},Kd={capture:!0,passive:!1};function zx(e){e.stopImmediatePropagation()}function Sc(e){e.preventDefault(),e.stopImmediatePropagation()}function kI(e){var t=e.document.documentElement,n=ss(e).on("dragstart.drag",Sc,Kd);"onselectstart"in t?n.on("selectstart.drag",Sc,Kd):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function SI(e,t){var n=e.document.documentElement,i=ss(e).on("dragstart.drag",null);t&&(i.on("click.drag",Sc,Kd),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const hp=e=>()=>e;function k0(e,{sourceEvent:t,subject:n,target:i,identifier:s,active:r,x:o,y:c,dx:u,dy:f,dispatch:p}){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:i,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:r,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:c,enumerable:!0,configurable:!0},dx:{value:u,enumerable:!0,configurable:!0},dy:{value:f,enumerable:!0,configurable:!0},_:{value:p}})}k0.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Hae(e){return!e.ctrlKey&&!e.button}function Vae(){return this.parentNode}function Kae(e,t){return t??{x:e.x,y:e.y}}function Gae(){return navigator.maxTouchPoints||"ontouchstart"in this}function NI(){var e=Hae,t=Vae,n=Kae,i=Gae,s={},r=ug("start","drag","end"),o=0,c,u,f,p,m=0;function b(j){j.on("mousedown.drag",y).filter(i).on("touchstart.drag",w).on("touchmove.drag",k,qae).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(j,T){if(!(p||!e.call(this,j,T))){var A=S(this,t.call(this,j,T),j,T,"mouse");A&&(ss(j.view).on("mousemove.drag",x,Kd).on("mouseup.drag",v,Kd),kI(j.view),zx(j),f=!1,c=j.clientX,u=j.clientY,A("start",j))}}function x(j){if(Sc(j),!f){var T=j.clientX-c,A=j.clientY-u;f=T*T+A*A>m}s.mouse("drag",j)}function v(j){ss(j.view).on("mousemove.drag mouseup.drag",null),SI(j.view,f),Sc(j),s.mouse("end",j)}function w(j,T){if(e.call(this,j,T)){var A=j.changedTouches,M=t.call(this,j,T),R=A.length,P,I;for(P=0;P<R;++P)(I=S(this,M,j,T,A[P].identifier,A[P]))&&(zx(j),I("start",j,A[P]))}}function k(j){var T=j.changedTouches,A=T.length,M,R;for(M=0;M<A;++M)(R=s[T[M].identifier])&&(Sc(j),R("drag",j,T[M]))}function C(j){var T=j.changedTouches,A=T.length,M,R;for(p&&clearTimeout(p),p=setTimeout(function(){p=null},500),M=0;M<A;++M)(R=s[T[M].identifier])&&(zx(j),R("end",j,T[M]))}function S(j,T,A,M,R,P){var I=r.copy(),B=Gs(P||A,T),F,V,D;if((D=n.call(j,new k0("beforestart",{sourceEvent:A,target:b,identifier:R,active:o,x:B[0],y:B[1],dx:0,dy:0,dispatch:I}),M))!=null)return F=D.x-B[0]||0,V=D.y-B[1]||0,function L(z,W,X){var G=B,U;switch(z){case"start":s[R]=L,U=o++;break;case"end":delete s[R],--o;case"drag":B=Gs(X||W,T),U=o;break}I.call(z,j,new k0(z,{sourceEvent:W,subject:D,target:b,identifier:R,active:U,x:B[0]+F,y:B[1]+V,dx:B[0]-G[0],dy:B[1]-G[1],dispatch:I}),M)}}return b.filter=function(j){return arguments.length?(e=typeof j=="function"?j:hp(!!j),b):e},b.container=function(j){return arguments.length?(t=typeof j=="function"?j:hp(j),b):t},b.subject=function(j){return arguments.length?(n=typeof j=="function"?j:hp(j),b):n},b.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:hp(!!j),b):i},b.on=function(){var j=r.on.apply(r,arguments);return j===r?b:j},b.clickDistance=function(j){return arguments.length?(m=(j=+j)*j,b):Math.sqrt(m)},b}function Nw(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function _I(e,t){var n=Object.create(e.prototype);for(var i in t)n[i]=t[i];return n}function Cf(){}var Gd=.7,km=1/Gd,Nc="\\s*([+-]?\\d+)\\s*",Wd="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Sr="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Wae=/^#([0-9a-f]{3,8})$/,Yae=new RegExp(`^rgb\\(${Nc},${Nc},${Nc}\\)$`),Xae=new RegExp(`^rgb\\(${Sr},${Sr},${Sr}\\)$`),Qae=new RegExp(`^rgba\\(${Nc},${Nc},${Nc},${Wd}\\)$`),Zae=new RegExp(`^rgba\\(${Sr},${Sr},${Sr},${Wd}\\)$`),Jae=new RegExp(`^hsl\\(${Wd},${Sr},${Sr}\\)$`),eoe=new RegExp(`^hsla\\(${Wd},${Sr},${Sr},${Wd}\\)$`),Mj={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};Nw(Cf,hl,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Rj,formatHex:Rj,formatHex8:toe,formatHsl:noe,formatRgb:Dj,toString:Dj});function Rj(){return this.rgb().formatHex()}function toe(){return this.rgb().formatHex8()}function noe(){return CI(this).formatHsl()}function Dj(){return this.rgb().formatRgb()}function hl(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=Wae.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Oj(t):n===3?new Hi(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?pp(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?pp(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=Yae.exec(e))?new Hi(t[1],t[2],t[3],1):(t=Xae.exec(e))?new Hi(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Qae.exec(e))?pp(t[1],t[2],t[3],t[4]):(t=Zae.exec(e))?pp(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Jae.exec(e))?Pj(t[1],t[2]/100,t[3]/100,1):(t=eoe.exec(e))?Pj(t[1],t[2]/100,t[3]/100,t[4]):Mj.hasOwnProperty(e)?Oj(Mj[e]):e==="transparent"?new Hi(NaN,NaN,NaN,0):null}function Oj(e){return new Hi(e>>16&255,e>>8&255,e&255,1)}function pp(e,t,n,i){return i<=0&&(e=t=n=NaN),new Hi(e,t,n,i)}function ioe(e){return e instanceof Cf||(e=hl(e)),e?(e=e.rgb(),new Hi(e.r,e.g,e.b,e.opacity)):new Hi}function S0(e,t,n,i){return arguments.length===1?ioe(e):new Hi(e,t,n,i??1)}function Hi(e,t,n,i){this.r=+e,this.g=+t,this.b=+n,this.opacity=+i}Nw(Hi,S0,_I(Cf,{brighter(e){return e=e==null?km:Math.pow(km,e),new Hi(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Gd:Math.pow(Gd,e),new Hi(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Hi(al(this.r),al(this.g),al(this.b),Sm(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:Lj,formatHex:Lj,formatHex8:soe,formatRgb:Ij,toString:Ij}));function Lj(){return`#${Wo(this.r)}${Wo(this.g)}${Wo(this.b)}`}function soe(){return`#${Wo(this.r)}${Wo(this.g)}${Wo(this.b)}${Wo((isNaN(this.opacity)?1:this.opacity)*255)}`}function Ij(){const e=Sm(this.opacity);return`${e===1?"rgb(":"rgba("}${al(this.r)}, ${al(this.g)}, ${al(this.b)}${e===1?")":`, ${e})`}`}function Sm(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function al(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Wo(e){return e=al(e),(e<16?"0":"")+e.toString(16)}function Pj(e,t,n,i){return i<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ws(e,t,n,i)}function CI(e){if(e instanceof Ws)return new Ws(e.h,e.s,e.l,e.opacity);if(e instanceof Cf||(e=hl(e)),!e)return new Ws;if(e instanceof Ws)return e;e=e.rgb();var t=e.r/255,n=e.g/255,i=e.b/255,s=Math.min(t,n,i),r=Math.max(t,n,i),o=NaN,c=r-s,u=(r+s)/2;return c?(t===r?o=(n-i)/c+(n<i)*6:n===r?o=(i-t)/c+2:o=(t-n)/c+4,c/=u<.5?r+s:2-r-s,o*=60):c=u>0&&u<1?0:o,new Ws(o,c,u,e.opacity)}function roe(e,t,n,i){return arguments.length===1?CI(e):new Ws(e,t,n,i??1)}function Ws(e,t,n,i){this.h=+e,this.s=+t,this.l=+n,this.opacity=+i}Nw(Ws,roe,_I(Cf,{brighter(e){return e=e==null?km:Math.pow(km,e),new Ws(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Gd:Math.pow(Gd,e),new Ws(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,i=n+(n<.5?n:1-n)*t,s=2*n-i;return new Hi(Bx(e>=240?e-240:e+120,s,i),Bx(e,s,i),Bx(e<120?e+240:e-120,s,i),this.opacity)},clamp(){return new Ws(zj(this.h),mp(this.s),mp(this.l),Sm(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=Sm(this.opacity);return`${e===1?"hsl(":"hsla("}${zj(this.h)}, ${mp(this.s)*100}%, ${mp(this.l)*100}%${e===1?")":`, ${e})`}`}}));function zj(e){return e=(e||0)%360,e<0?e+360:e}function mp(e){return Math.max(0,Math.min(1,e||0))}function Bx(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 _w=e=>()=>e;function aoe(e,t){return function(n){return e+n*t}}function ooe(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(i){return Math.pow(e+i*t,n)}}function loe(e){return(e=+e)==1?jI:function(t,n){return n-t?ooe(t,n,e):_w(isNaN(t)?n:t)}}function jI(e,t){var n=t-e;return n?aoe(e,n):_w(isNaN(e)?t:e)}const Nm=(function e(t){var n=loe(t);function i(s,r){var o=n((s=S0(s)).r,(r=S0(r)).r),c=n(s.g,r.g),u=n(s.b,r.b),f=jI(s.opacity,r.opacity);return function(p){return s.r=o(p),s.g=c(p),s.b=u(p),s.opacity=f(p),s+""}}return i.gamma=e,i})(1);function coe(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,i=t.slice(),s;return function(r){for(s=0;s<n;++s)i[s]=e[s]*(1-r)+t[s]*r;return i}}function uoe(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function doe(e,t){var n=t?t.length:0,i=e?Math.min(n,e.length):0,s=new Array(i),r=new Array(n),o;for(o=0;o<i;++o)s[o]=Td(e[o],t[o]);for(;o<n;++o)r[o]=t[o];return function(c){for(o=0;o<i;++o)r[o]=s[o](c);return r}}function foe(e,t){var n=new Date;return e=+e,t=+t,function(i){return n.setTime(e*(1-i)+t*i),n}}function wr(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function hoe(e,t){var n={},i={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=Td(e[s],t[s]):i[s]=t[s];return function(r){for(s in n)i[s]=n[s](r);return i}}var N0=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Ux=new RegExp(N0.source,"g");function poe(e){return function(){return e}}function moe(e){return function(t){return e(t)+""}}function TI(e,t){var n=N0.lastIndex=Ux.lastIndex=0,i,s,r,o=-1,c=[],u=[];for(e=e+"",t=t+"";(i=N0.exec(e))&&(s=Ux.exec(t));)(r=s.index)>n&&(r=t.slice(n,r),c[o]?c[o]+=r:c[++o]=r),(i=i[0])===(s=s[0])?c[o]?c[o]+=s:c[++o]=s:(c[++o]=null,u.push({i:o,x:wr(i,s)})),n=Ux.lastIndex;return n<t.length&&(r=t.slice(n),c[o]?c[o]+=r:c[++o]=r),c.length<2?u[0]?moe(u[0].x):poe(t):(t=u.length,function(f){for(var p=0,m;p<t;++p)c[(m=u[p]).i]=m.x(f);return c.join("")})}function Td(e,t){var n=typeof t,i;return t==null||n==="boolean"?_w(t):(n==="number"?wr:n==="string"?(i=hl(t))?(t=i,Nm):TI:t instanceof hl?Nm:t instanceof Date?foe:uoe(t)?coe:Array.isArray(t)?doe:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?hoe:wr)(e,t)}var Bj=180/Math.PI,_0={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function AI(e,t,n,i,s,r){var o,c,u;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(u=e*n+t*i)&&(n-=e*u,i-=t*u),(c=Math.sqrt(n*n+i*i))&&(n/=c,i/=c,u/=c),e*i<t*n&&(e=-e,t=-t,u=-u,o=-o),{translateX:s,translateY:r,rotate:Math.atan2(t,e)*Bj,skewX:Math.atan(u)*Bj,scaleX:o,scaleY:c}}var gp;function goe(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?_0:AI(t.a,t.b,t.c,t.d,t.e,t.f)}function yoe(e){return e==null||(gp||(gp=document.createElementNS("http://www.w3.org/2000/svg","g")),gp.setAttribute("transform",e),!(e=gp.transform.baseVal.consolidate()))?_0:(e=e.matrix,AI(e.a,e.b,e.c,e.d,e.e,e.f))}function MI(e,t,n,i){function s(f){return f.length?f.pop()+" ":""}function r(f,p,m,b,y,x){if(f!==m||p!==b){var v=y.push("translate(",null,t,null,n);x.push({i:v-4,x:wr(f,m)},{i:v-2,x:wr(p,b)})}else(m||b)&&y.push("translate("+m+t+b+n)}function o(f,p,m,b){f!==p?(f-p>180?p+=360:p-f>180&&(f+=360),b.push({i:m.push(s(m)+"rotate(",null,i)-2,x:wr(f,p)})):p&&m.push(s(m)+"rotate("+p+i)}function c(f,p,m,b){f!==p?b.push({i:m.push(s(m)+"skewX(",null,i)-2,x:wr(f,p)}):p&&m.push(s(m)+"skewX("+p+i)}function u(f,p,m,b,y,x){if(f!==m||p!==b){var v=y.push(s(y)+"scale(",null,",",null,")");x.push({i:v-4,x:wr(f,m)},{i:v-2,x:wr(p,b)})}else(m!==1||b!==1)&&y.push(s(y)+"scale("+m+","+b+")")}return function(f,p){var m=[],b=[];return f=e(f),p=e(p),r(f.translateX,f.translateY,p.translateX,p.translateY,m,b),o(f.rotate,p.rotate,m,b),c(f.skewX,p.skewX,m,b),u(f.scaleX,f.scaleY,p.scaleX,p.scaleY,m,b),f=p=null,function(y){for(var x=-1,v=b.length,w;++x<v;)m[(w=b[x]).i]=w.x(y);return m.join("")}}}var boe=MI(goe,"px, ","px)","deg)"),xoe=MI(yoe,", ",")",")"),voe=1e-12;function Uj(e){return((e=Math.exp(e))+1/e)/2}function woe(e){return((e=Math.exp(e))-1/e)/2}function Eoe(e){return((e=Math.exp(2*e))-1)/(e+1)}const $p=(function e(t,n,i){function s(r,o){var c=r[0],u=r[1],f=r[2],p=o[0],m=o[1],b=o[2],y=p-c,x=m-u,v=y*y+x*x,w,k;if(v<voe)k=Math.log(b/f)/t,w=function(M){return[c+M*y,u+M*x,f*Math.exp(t*M*k)]};else{var C=Math.sqrt(v),S=(b*b-f*f+i*v)/(2*f*n*C),j=(b*b-f*f-i*v)/(2*b*n*C),T=Math.log(Math.sqrt(S*S+1)-S),A=Math.log(Math.sqrt(j*j+1)-j);k=(A-T)/t,w=function(M){var R=M*k,P=Uj(T),I=f/(n*C)*(P*Eoe(t*R+T)-woe(T));return[c+I*y,u+I*x,f*P/Uj(t*R+T)]}}return w.duration=k*1e3*t/Math.SQRT2,w}return s.rho=function(r){var o=Math.max(.001,+r),c=o*o,u=c*c;return e(o,c,u)},s})(Math.SQRT2,2,4);var Kc=0,yd=0,cd=0,RI=1e3,_m,bd,Cm=0,pl=0,fg=0,Yd=typeof performance=="object"&&performance.now?performance:Date,DI=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Cw(){return pl||(DI(koe),pl=Yd.now()+fg)}function koe(){pl=0}function jm(){this._call=this._time=this._next=null}jm.prototype=OI.prototype={constructor:jm,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Cw():+n)+(t==null?0:+t),!this._next&&bd!==this&&(bd?bd._next=this:_m=this,bd=this),this._call=e,this._time=n,C0()},stop:function(){this._call&&(this._call=null,this._time=1/0,C0())}};function OI(e,t,n){var i=new jm;return i.restart(e,t,n),i}function Soe(){Cw(),++Kc;for(var e=_m,t;e;)(t=pl-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Kc}function Fj(){pl=(Cm=Yd.now())+fg,Kc=yd=0;try{Soe()}finally{Kc=0,_oe(),pl=0}}function Noe(){var e=Yd.now(),t=e-Cm;t>RI&&(fg-=t,Cm=e)}function _oe(){for(var e,t=_m,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:_m=n);bd=e,C0(i)}function C0(e){if(!Kc){yd&&(yd=clearTimeout(yd));var t=e-pl;t>24?(e<1/0&&(yd=setTimeout(Fj,e-Yd.now()-fg)),cd&&(cd=clearInterval(cd))):(cd||(Cm=Yd.now(),cd=setInterval(Noe,RI)),Kc=1,DI(Fj))}}function $j(e,t,n){var i=new jm;return t=t==null?0:+t,i.restart(s=>{i.stop(),e(s+t)},t,n),i}var Coe=ug("start","end","cancel","interrupt"),joe=[],LI=0,qj=1,j0=2,qp=3,Hj=4,T0=5,Hp=6;function hg(e,t,n,i,s,r){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Toe(e,n,{name:t,index:i,group:s,on:Coe,tween:joe,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:LI})}function jw(e,t){var n=sr(e,t);if(n.state>LI)throw new Error("too late; already scheduled");return n}function Ar(e,t){var n=sr(e,t);if(n.state>qp)throw new Error("too late; already running");return n}function sr(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Toe(e,t,n){var i=e.__transition,s;i[t]=n,n.timer=OI(r,0,n.time);function r(f){n.state=qj,n.timer.restart(o,n.delay,n.time),n.delay<=f&&o(f-n.delay)}function o(f){var p,m,b,y;if(n.state!==qj)return u();for(p in i)if(y=i[p],y.name===n.name){if(y.state===qp)return $j(o);y.state===Hj?(y.state=Hp,y.timer.stop(),y.on.call("interrupt",e,e.__data__,y.index,y.group),delete i[p]):+p<t&&(y.state=Hp,y.timer.stop(),y.on.call("cancel",e,e.__data__,y.index,y.group),delete i[p])}if($j(function(){n.state===qp&&(n.state=Hj,n.timer.restart(c,n.delay,n.time),c(f))}),n.state=j0,n.on.call("start",e,e.__data__,n.index,n.group),n.state===j0){for(n.state=qp,s=new Array(b=n.tween.length),p=0,m=-1;p<b;++p)(y=n.tween[p].value.call(e,e.__data__,n.index,n.group))&&(s[++m]=y);s.length=m+1}}function c(f){for(var p=f<n.duration?n.ease.call(null,f/n.duration):(n.timer.restart(u),n.state=T0,1),m=-1,b=s.length;++m<b;)s[m].call(e,p);n.state===T0&&(n.on.call("end",e,e.__data__,n.index,n.group),u())}function u(){n.state=Hp,n.timer.stop(),delete i[t];for(var f in i)return;delete e.__transition}}function Vp(e,t){var n=e.__transition,i,s,r=!0,o;if(n){t=t==null?null:t+"";for(o in n){if((i=n[o]).name!==t){r=!1;continue}s=i.state>j0&&i.state<T0,i.state=Hp,i.timer.stop(),i.on.call(s?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete n[o]}r&&delete e.__transition}}function Aoe(e){return this.each(function(){Vp(this,e)})}function Moe(e,t){var n,i;return function(){var s=Ar(this,e),r=s.tween;if(r!==n){i=n=r;for(var o=0,c=i.length;o<c;++o)if(i[o].name===t){i=i.slice(),i.splice(o,1);break}}s.tween=i}}function Roe(e,t,n){var i,s;if(typeof n!="function")throw new Error;return function(){var r=Ar(this,e),o=r.tween;if(o!==i){s=(i=o).slice();for(var c={name:t,value:n},u=0,f=s.length;u<f;++u)if(s[u].name===t){s[u]=c;break}u===f&&s.push(c)}r.tween=s}}function Doe(e,t){var n=this._id;if(e+="",arguments.length<2){for(var i=sr(this.node(),n).tween,s=0,r=i.length,o;s<r;++s)if((o=i[s]).name===e)return o.value;return null}return this.each((t==null?Moe:Roe)(n,e,t))}function Tw(e,t,n){var i=e._id;return e.each(function(){var s=Ar(this,i);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return sr(s,i).value[t]}}function II(e,t){var n;return(typeof t=="number"?wr:t instanceof hl?Nm:(n=hl(t))?(t=n,Nm):TI)(e,t)}function Ooe(e){return function(){this.removeAttribute(e)}}function Loe(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Ioe(e,t,n){var i,s=n+"",r;return function(){var o=this.getAttribute(e);return o===s?null:o===i?r:r=t(i=o,n)}}function Poe(e,t,n){var i,s=n+"",r;return function(){var o=this.getAttributeNS(e.space,e.local);return o===s?null:o===i?r:r=t(i=o,n)}}function zoe(e,t,n){var i,s,r;return function(){var o,c=n(this),u;return c==null?void this.removeAttribute(e):(o=this.getAttribute(e),u=c+"",o===u?null:o===i&&u===s?r:(s=u,r=t(i=o,c)))}}function Boe(e,t,n){var i,s,r;return function(){var o,c=n(this),u;return c==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),u=c+"",o===u?null:o===i&&u===s?r:(s=u,r=t(i=o,c)))}}function Uoe(e,t){var n=dg(e),i=n==="transform"?xoe:II;return this.attrTween(e,typeof t=="function"?(n.local?Boe:zoe)(n,i,Tw(this,"attr."+e,t)):t==null?(n.local?Loe:Ooe)(n):(n.local?Poe:Ioe)(n,i,t))}function Foe(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function $oe(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function qoe(e,t){var n,i;function s(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&$oe(e,r)),n}return s._value=t,s}function Hoe(e,t){var n,i;function s(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&Foe(e,r)),n}return s._value=t,s}function Voe(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 i=dg(e);return this.tween(n,(i.local?qoe:Hoe)(i,t))}function Koe(e,t){return function(){jw(this,e).delay=+t.apply(this,arguments)}}function Goe(e,t){return t=+t,function(){jw(this,e).delay=t}}function Woe(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Koe:Goe)(t,e)):sr(this.node(),t).delay}function Yoe(e,t){return function(){Ar(this,e).duration=+t.apply(this,arguments)}}function Xoe(e,t){return t=+t,function(){Ar(this,e).duration=t}}function Qoe(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Yoe:Xoe)(t,e)):sr(this.node(),t).duration}function Zoe(e,t){if(typeof t!="function")throw new Error;return function(){Ar(this,e).ease=t}}function Joe(e){var t=this._id;return arguments.length?this.each(Zoe(t,e)):sr(this.node(),t).ease}function ele(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ar(this,e).ease=n}}function tle(e){if(typeof e!="function")throw new Error;return this.each(ele(this._id,e))}function nle(e){typeof e!="function"&&(e=hI(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=[],u,f=0;f<o;++f)(u=r[f])&&e.call(u,u.__data__,f,r)&&c.push(u);return new fa(i,this._parents,this._name,this._id)}function ile(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,i=t.length,s=n.length,r=Math.min(i,s),o=new Array(i),c=0;c<r;++c)for(var u=t[c],f=n[c],p=u.length,m=o[c]=new Array(p),b,y=0;y<p;++y)(b=u[y]||f[y])&&(m[y]=b);for(;c<i;++c)o[c]=t[c];return new fa(o,this._parents,this._name,this._id)}function sle(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 rle(e,t,n){var i,s,r=sle(t)?jw:Ar;return function(){var o=r(this,e),c=o.on;c!==i&&(s=(i=c).copy()).on(t,n),o.on=s}}function ale(e,t){var n=this._id;return arguments.length<2?sr(this.node(),n).on.on(e):this.each(rle(n,e,t))}function ole(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function lle(){return this.on("end.remove",ole(this._id))}function cle(e){var t=this._name,n=this._id;typeof e!="function"&&(e=kw(e));for(var i=this._groups,s=i.length,r=new Array(s),o=0;o<s;++o)for(var c=i[o],u=c.length,f=r[o]=new Array(u),p,m,b=0;b<u;++b)(p=c[b])&&(m=e.call(p,p.__data__,b,c))&&("__data__"in p&&(m.__data__=p.__data__),f[b]=m,hg(f[b],t,n,b,f,sr(p,n)));return new fa(r,this._parents,t,n)}function ule(e){var t=this._name,n=this._id;typeof e!="function"&&(e=fI(e));for(var i=this._groups,s=i.length,r=[],o=[],c=0;c<s;++c)for(var u=i[c],f=u.length,p,m=0;m<f;++m)if(p=u[m]){for(var b=e.call(p,p.__data__,m,u),y,x=sr(p,n),v=0,w=b.length;v<w;++v)(y=b[v])&&hg(y,t,n,v,b,x);r.push(b),o.push(p)}return new fa(r,o,t,n)}var dle=_f.prototype.constructor;function fle(){return new dle(this._groups,this._parents)}function hle(e,t){var n,i,s;return function(){var r=Vc(this,e),o=(this.style.removeProperty(e),Vc(this,e));return r===o?null:r===n&&o===i?s:s=t(n=r,i=o)}}function PI(e){return function(){this.style.removeProperty(e)}}function ple(e,t,n){var i,s=n+"",r;return function(){var o=Vc(this,e);return o===s?null:o===i?r:r=t(i=o,n)}}function mle(e,t,n){var i,s,r;return function(){var o=Vc(this,e),c=n(this),u=c+"";return c==null&&(u=c=(this.style.removeProperty(e),Vc(this,e))),o===u?null:o===i&&u===s?r:(s=u,r=t(i=o,c))}}function gle(e,t){var n,i,s,r="style."+t,o="end."+r,c;return function(){var u=Ar(this,e),f=u.on,p=u.value[r]==null?c||(c=PI(t)):void 0;(f!==n||s!==p)&&(i=(n=f).copy()).on(o,s=p),u.on=i}}function yle(e,t,n){var i=(e+="")=="transform"?boe:II;return t==null?this.styleTween(e,hle(e,i)).on("end.style."+e,PI(e)):typeof t=="function"?this.styleTween(e,mle(e,i,Tw(this,"style."+e,t))).each(gle(this._id,e)):this.styleTween(e,ple(e,i,t),n).on("end.style."+e,null)}function ble(e,t,n){return function(i){this.style.setProperty(e,t.call(this,i),n)}}function xle(e,t,n){var i,s;function r(){var o=t.apply(this,arguments);return o!==s&&(i=(s=o)&&ble(e,o,n)),i}return r._value=t,r}function vle(e,t,n){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(t==null)return this.tween(i,null);if(typeof t!="function")throw new Error;return this.tween(i,xle(e,t,n??""))}function wle(e){return function(){this.textContent=e}}function Ele(e){return function(){var t=e(this);this.textContent=t??""}}function kle(e){return this.tween("text",typeof e=="function"?Ele(Tw(this,"text",e)):wle(e==null?"":e+""))}function Sle(e){return function(t){this.textContent=e.call(this,t)}}function Nle(e){var t,n;function i(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&Sle(s)),t}return i._value=e,i}function _le(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,Nle(e))}function Cle(){for(var e=this._name,t=this._id,n=zI(),i=this._groups,s=i.length,r=0;r<s;++r)for(var o=i[r],c=o.length,u,f=0;f<c;++f)if(u=o[f]){var p=sr(u,t);hg(u,e,n,f,o,{time:p.time+p.delay+p.duration,delay:0,duration:p.duration,ease:p.ease})}return new fa(i,this._parents,e,n)}function jle(){var e,t,n=this,i=n._id,s=n.size();return new Promise(function(r,o){var c={value:o},u={value:function(){--s===0&&r()}};n.each(function(){var f=Ar(this,i),p=f.on;p!==e&&(t=(e=p).copy(),t._.cancel.push(c),t._.interrupt.push(c),t._.end.push(u)),f.on=t}),s===0&&r()})}var Tle=0;function fa(e,t,n,i){this._groups=e,this._parents=t,this._name=n,this._id=i}function zI(){return++Tle}var Zr=_f.prototype;fa.prototype={constructor:fa,select:cle,selectAll:ule,selectChild:Zr.selectChild,selectChildren:Zr.selectChildren,filter:nle,merge:ile,selection:fle,transition:Cle,call:Zr.call,nodes:Zr.nodes,node:Zr.node,size:Zr.size,empty:Zr.empty,each:Zr.each,on:ale,attr:Uoe,attrTween:Voe,style:yle,styleTween:vle,text:kle,textTween:_le,remove:lle,tween:Doe,delay:Woe,duration:Qoe,ease:Joe,easeVarying:tle,end:jle,[Symbol.iterator]:Zr[Symbol.iterator]};function Ale(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Mle={time:null,delay:0,duration:250,ease:Ale};function Rle(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 Dle(e){var t,n;e instanceof fa?(t=e._id,e=e._name):(t=zI(),(n=Mle).time=Cw(),e=e==null?null:e+"");for(var i=this._groups,s=i.length,r=0;r<s;++r)for(var o=i[r],c=o.length,u,f=0;f<c;++f)(u=o[f])&&hg(u,e,t,f,o,n||Rle(u,t));return new fa(i,this._parents,e,t)}_f.prototype.interrupt=Aoe;_f.prototype.transition=Dle;const yp=e=>()=>e;function Ole(e,{sourceEvent:t,target:n,transform:i,dispatch:s}){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:i,enumerable:!0,configurable:!0},_:{value:s}})}function aa(e,t,n){this.k=e,this.x=t,this.y=n}aa.prototype={constructor:aa,scale:function(e){return e===1?this:new aa(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new aa(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 pg=new aa(1,0,0);BI.prototype=aa.prototype;function BI(e){for(;!e.__zoom;)if(!(e=e.parentNode))return pg;return e.__zoom}function Fx(e){e.stopImmediatePropagation()}function ud(e){e.preventDefault(),e.stopImmediatePropagation()}function Lle(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Ile(){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 Vj(){return this.__zoom||pg}function Ple(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function zle(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ble(e,t,n){var i=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],r=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>i?(i+s)/2:Math.min(0,i)||Math.max(0,s),o>r?(r+o)/2:Math.min(0,r)||Math.max(0,o))}function UI(){var e=Lle,t=Ile,n=Ble,i=Ple,s=zle,r=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],c=250,u=$p,f=ug("start","zoom","end"),p,m,b,y=500,x=150,v=0,w=10;function k(D){D.property("__zoom",Vj).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",P).on("dblclick.zoom",I).filter(s).on("touchstart.zoom",B).on("touchmove.zoom",F).on("touchend.zoom touchcancel.zoom",V).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}k.transform=function(D,L,z,W){var X=D.selection?D.selection():D;X.property("__zoom",Vj),D!==X?T(D,L,z,W):X.interrupt().each(function(){A(this,arguments).event(W).start().zoom(null,typeof L=="function"?L.apply(this,arguments):L).end()})},k.scaleBy=function(D,L,z,W){k.scaleTo(D,function(){var X=this.__zoom.k,G=typeof L=="function"?L.apply(this,arguments):L;return X*G},z,W)},k.scaleTo=function(D,L,z,W){k.transform(D,function(){var X=t.apply(this,arguments),G=this.__zoom,U=z==null?j(X):typeof z=="function"?z.apply(this,arguments):z,q=G.invert(U),Y=typeof L=="function"?L.apply(this,arguments):L;return n(S(C(G,Y),U,q),X,o)},z,W)},k.translateBy=function(D,L,z,W){k.transform(D,function(){return n(this.__zoom.translate(typeof L=="function"?L.apply(this,arguments):L,typeof z=="function"?z.apply(this,arguments):z),t.apply(this,arguments),o)},null,W)},k.translateTo=function(D,L,z,W,X){k.transform(D,function(){var G=t.apply(this,arguments),U=this.__zoom,q=W==null?j(G):typeof W=="function"?W.apply(this,arguments):W;return n(pg.translate(q[0],q[1]).scale(U.k).translate(typeof L=="function"?-L.apply(this,arguments):-L,typeof z=="function"?-z.apply(this,arguments):-z),G,o)},W,X)};function C(D,L){return L=Math.max(r[0],Math.min(r[1],L)),L===D.k?D:new aa(L,D.x,D.y)}function S(D,L,z){var W=L[0]-z[0]*D.k,X=L[1]-z[1]*D.k;return W===D.x&&X===D.y?D:new aa(D.k,W,X)}function j(D){return[(+D[0][0]+ +D[1][0])/2,(+D[0][1]+ +D[1][1])/2]}function T(D,L,z,W){D.on("start.zoom",function(){A(this,arguments).event(W).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(W).end()}).tween("zoom",function(){var X=this,G=arguments,U=A(X,G).event(W),q=t.apply(X,G),Y=z==null?j(q):typeof z=="function"?z.apply(X,G):z,$=Math.max(q[1][0]-q[0][0],q[1][1]-q[0][1]),ie=X.__zoom,be=typeof L=="function"?L.apply(X,G):L,ce=u(ie.invert(Y).concat($/ie.k),be.invert(Y).concat($/be.k));return function(_e){if(_e===1)_e=be;else{var le=ce(_e),pe=$/le[2];_e=new aa(pe,Y[0]-le[0]*pe,Y[1]-le[1]*pe)}U.zoom(null,_e)}})}function A(D,L,z){return!z&&D.__zooming||new M(D,L)}function M(D,L){this.that=D,this.args=L,this.active=0,this.sourceEvent=null,this.extent=t.apply(D,L),this.taps=0}M.prototype={event:function(D){return D&&(this.sourceEvent=D),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(D,L){return this.mouse&&D!=="mouse"&&(this.mouse[1]=L.invert(this.mouse[0])),this.touch0&&D!=="touch"&&(this.touch0[1]=L.invert(this.touch0[0])),this.touch1&&D!=="touch"&&(this.touch1[1]=L.invert(this.touch1[0])),this.that.__zoom=L,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(D){var L=ss(this.that).datum();f.call(D,this.that,new Ole(D,{sourceEvent:this.sourceEvent,target:k,transform:this.that.__zoom,dispatch:f}),L)}};function R(D,...L){if(!e.apply(this,arguments))return;var z=A(this,L).event(D),W=this.__zoom,X=Math.max(r[0],Math.min(r[1],W.k*Math.pow(2,i.apply(this,arguments)))),G=Gs(D);if(z.wheel)(z.mouse[0][0]!==G[0]||z.mouse[0][1]!==G[1])&&(z.mouse[1]=W.invert(z.mouse[0]=G)),clearTimeout(z.wheel);else{if(W.k===X)return;z.mouse=[G,W.invert(G)],Vp(this),z.start()}ud(D),z.wheel=setTimeout(U,x),z.zoom("mouse",n(S(C(W,X),z.mouse[0],z.mouse[1]),z.extent,o));function U(){z.wheel=null,z.end()}}function P(D,...L){if(b||!e.apply(this,arguments))return;var z=D.currentTarget,W=A(this,L,!0).event(D),X=ss(D.view).on("mousemove.zoom",Y,!0).on("mouseup.zoom",$,!0),G=Gs(D,z),U=D.clientX,q=D.clientY;kI(D.view),Fx(D),W.mouse=[G,this.__zoom.invert(G)],Vp(this),W.start();function Y(ie){if(ud(ie),!W.moved){var be=ie.clientX-U,ce=ie.clientY-q;W.moved=be*be+ce*ce>v}W.event(ie).zoom("mouse",n(S(W.that.__zoom,W.mouse[0]=Gs(ie,z),W.mouse[1]),W.extent,o))}function $(ie){X.on("mousemove.zoom mouseup.zoom",null),SI(ie.view,W.moved),ud(ie),W.event(ie).end()}}function I(D,...L){if(e.apply(this,arguments)){var z=this.__zoom,W=Gs(D.changedTouches?D.changedTouches[0]:D,this),X=z.invert(W),G=z.k*(D.shiftKey?.5:2),U=n(S(C(z,G),W,X),t.apply(this,L),o);ud(D),c>0?ss(this).transition().duration(c).call(T,U,W,D):ss(this).call(k.transform,U,W,D)}}function B(D,...L){if(e.apply(this,arguments)){var z=D.touches,W=z.length,X=A(this,L,D.changedTouches.length===W).event(D),G,U,q,Y;for(Fx(D),U=0;U<W;++U)q=z[U],Y=Gs(q,this),Y=[Y,this.__zoom.invert(Y),q.identifier],X.touch0?!X.touch1&&X.touch0[2]!==Y[2]&&(X.touch1=Y,X.taps=0):(X.touch0=Y,G=!0,X.taps=1+!!p);p&&(p=clearTimeout(p)),G&&(X.taps<2&&(m=Y[0],p=setTimeout(function(){p=null},y)),Vp(this),X.start())}}function F(D,...L){if(this.__zooming){var z=A(this,L).event(D),W=D.changedTouches,X=W.length,G,U,q,Y;for(ud(D),G=0;G<X;++G)U=W[G],q=Gs(U,this),z.touch0&&z.touch0[2]===U.identifier?z.touch0[0]=q:z.touch1&&z.touch1[2]===U.identifier&&(z.touch1[0]=q);if(U=z.that.__zoom,z.touch1){var $=z.touch0[0],ie=z.touch0[1],be=z.touch1[0],ce=z.touch1[1],_e=(_e=be[0]-$[0])*_e+(_e=be[1]-$[1])*_e,le=(le=ce[0]-ie[0])*le+(le=ce[1]-ie[1])*le;U=C(U,Math.sqrt(_e/le)),q=[($[0]+be[0])/2,($[1]+be[1])/2],Y=[(ie[0]+ce[0])/2,(ie[1]+ce[1])/2]}else if(z.touch0)q=z.touch0[0],Y=z.touch0[1];else return;z.zoom("touch",n(S(U,q,Y),z.extent,o))}}function V(D,...L){if(this.__zooming){var z=A(this,L).event(D),W=D.changedTouches,X=W.length,G,U;for(Fx(D),b&&clearTimeout(b),b=setTimeout(function(){b=null},y),G=0;G<X;++G)U=W[G],z.touch0&&z.touch0[2]===U.identifier?delete z.touch0:z.touch1&&z.touch1[2]===U.identifier&&delete z.touch1;if(z.touch1&&!z.touch0&&(z.touch0=z.touch1,delete z.touch1),z.touch0)z.touch0[1]=this.__zoom.invert(z.touch0[0]);else if(z.end(),z.taps===2&&(U=Gs(U,this),Math.hypot(m[0]-U[0],m[1]-U[1])<w)){var q=ss(this).on("dblclick.zoom");q&&q.apply(this,arguments)}}}return k.wheelDelta=function(D){return arguments.length?(i=typeof D=="function"?D:yp(+D),k):i},k.filter=function(D){return arguments.length?(e=typeof D=="function"?D:yp(!!D),k):e},k.touchable=function(D){return arguments.length?(s=typeof D=="function"?D:yp(!!D),k):s},k.extent=function(D){return arguments.length?(t=typeof D=="function"?D:yp([[+D[0][0],+D[0][1]],[+D[1][0],+D[1][1]]]),k):t},k.scaleExtent=function(D){return arguments.length?(r[0]=+D[0],r[1]=+D[1],k):[r[0],r[1]]},k.translateExtent=function(D){return arguments.length?(o[0][0]=+D[0][0],o[1][0]=+D[1][0],o[0][1]=+D[0][1],o[1][1]=+D[1][1],k):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},k.constrain=function(D){return arguments.length?(n=D,k):n},k.duration=function(D){return arguments.length?(c=+D,k):c},k.interpolate=function(D){return arguments.length?(u=D,k):u},k.on=function(){var D=f.on.apply(f,arguments);return D===f?k:D},k.clickDistance=function(D){return arguments.length?(v=(D=+D)*D,k):Math.sqrt(v)},k.tapDistance=function(D){return arguments.length?(w=+D,k):w},k}const ls={error001:(e="react")=>`Seems like you have not used ${e==="svelte"?"SvelteFlowProvider":"ReactFlowProvider"} as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:i})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:i}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.",error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},Xd=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],FI=["Enter"," ","Escape"],$I={"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 Gc;(function(e){e.Strict="strict",e.Loose="loose"})(Gc||(Gc={}));var ol;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(ol||(ol={}));var Qd;(function(e){e.Partial="partial",e.Full="full"})(Qd||(Qd={}));const qI={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Va;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Va||(Va={}));var Tm;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Tm||(Tm={}));var tt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(tt||(tt={}));const Kj={[tt.Left]:tt.Right,[tt.Right]:tt.Left,[tt.Top]:tt.Bottom,[tt.Bottom]:tt.Top};function HI(e){return e===null?null:e?"valid":"invalid"}const VI=e=>"id"in e&&"source"in e&&"target"in e,Ule=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Aw=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),jf=(e,t=[0,0])=>{const{width:n,height:i}=pa(e),s=e.origin??t,r=n*s[0],o=i*s[1];return{x:e.position.x-r,y:e.position.y-o}},Fle=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((i,s)=>{const r=typeof s=="string";let o=!t.nodeLookup&&!r?s:void 0;t.nodeLookup&&(o=r?t.nodeLookup.get(s):Aw(s)?s:t.nodeLookup.get(s.id));const c=o?Am(o,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return mg(i,c)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return gg(n)},Tf=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},i=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=mg(n,Am(s)),i=!0)}),i?gg(n):{x:0,y:0,width:0,height:0}},Mw=(e,t,[n,i,s]=[0,0,1],r=!1,o=!1)=>{const c=(t.x-n)/s,u=(t.y-i)/s,f=t.width/s,p=t.height/s,m=[];for(const b of e.values()){const{measured:y,selectable:x=!0,hidden:v=!1}=b;if(o&&!x||v)continue;const w=y.width??b.width??b.initialWidth??0,k=y.height??b.height??b.initialHeight??0,{x:C,y:S}=b.internals.positionAbsolute,j=YI(c,u,f,p,C,S,w,k),T=w*k,A=r&&j>0;(!b.internals.handleBounds||A||j>=T||b.dragging)&&m.push(b)}return m},$le=(e,t)=>{const n=new Set;return e.forEach(i=>{n.add(i.id)}),t.filter(i=>n.has(i.source)||n.has(i.target))};function qle(e,t){const n=new Map,i=t!=null&&t.nodes?new Set(t.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&((t==null?void 0:t.includeHiddenNodes)||!s.hidden)&&(!i||i.has(s.id))&&n.set(s.id,s)}),n}async function Hle({nodes:e,width:t,height:n,panZoom:i,minZoom:s,maxZoom:r},o){if(e.size===0)return!0;const c=qle(e,o),u=Tf(c),f=Dw(u,t,n,(o==null?void 0:o.minZoom)??s,(o==null?void 0:o.maxZoom)??r,(o==null?void 0:o.padding)??.1);return await i.setViewport(f,{duration:o==null?void 0:o.duration,ease:o==null?void 0:o.ease,interpolate:o==null?void 0:o.interpolate}),!0}function KI({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:i=[0,0],nodeExtent:s,onError:r}){const o=n.get(e),c=o.parentId?n.get(o.parentId):void 0,{x:u,y:f}=c?c.internals.positionAbsolute:{x:0,y:0},p=o.origin??i;let m=o.extent||s;if(o.extent==="parent"&&!o.expandParent)if(!c)r==null||r("005",ls.error005());else{const y=c.measured.width,x=c.measured.height;y&&x&&(m=[[u,f],[u+y,f+x]])}else c&&gl(o.extent)&&(m=[[o.extent[0][0]+u,o.extent[0][1]+f],[o.extent[1][0]+u,o.extent[1][1]+f]]);const b=gl(m)?ml(t,m,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&(r==null||r("015",ls.error015())),{position:{x:b.x-u+(o.measured.width??0)*p[0],y:b.y-f+(o.measured.height??0)*p[1]},positionAbsolute:b}}async function Vle({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:i,onBeforeDelete:s}){const r=new Set(e.map(b=>b.id)),o=[];for(const b of n){if(b.deletable===!1)continue;const y=r.has(b.id),x=!y&&b.parentId&&o.find(v=>v.id===b.parentId);(y||x)&&o.push(b)}const c=new Set(t.map(b=>b.id)),u=i.filter(b=>b.deletable!==!1),p=$le(o,u);for(const b of u)c.has(b.id)&&!p.find(x=>x.id===b.id)&&p.push(b);if(!s)return{edges:p,nodes:o};const m=await s({nodes:o,edges:p});return typeof m=="boolean"?m?{edges:p,nodes:o}:{edges:[],nodes:[]}:m}const Wc=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),ml=(e={x:0,y:0},t,n)=>({x:Wc(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:Wc(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function GI(e,t,n){const{width:i,height:s}=pa(n),{x:r,y:o}=n.internals.positionAbsolute;return ml(e,[[r,o],[r+i,o+s]],t)}const Gj=(e,t,n)=>e<t?Wc(Math.abs(e-t),1,t)/t:e>n?-Wc(Math.abs(e-n),1,t)/t:0,Rw=(e,t,n=15,i=40)=>{const s=Gj(e.x,i,t.width-i)*n,r=Gj(e.y,i,t.height-i)*n;return[s,r]},mg=(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)}),A0=({x:e,y:t,width:n,height:i})=>({x:e,y:t,x2:e+n,y2:t+i}),gg=({x:e,y:t,x2:n,y2:i})=>({x:e,y:t,width:n-e,height:i-t}),Zd=(e,t=[0,0])=>{var s,r;const{x:n,y:i}=Aw(e)?e.internals.positionAbsolute:jf(e,t);return{x:n,y:i,width:((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0,height:((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0}},Am=(e,t=[0,0])=>{var s,r;const{x:n,y:i}=Aw(e)?e.internals.positionAbsolute:jf(e,t);return{x:n,y:i,x2:n+(((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0),y2:i+(((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0)}},WI=(e,t)=>gg(mg(A0(e),A0(t))),YI=(e,t,n,i,s,r,o,c)=>{const u=Math.max(0,Math.min(e+n,s+o)-Math.max(e,s)),f=Math.max(0,Math.min(t+i,r+c)-Math.max(t,r));return Math.ceil(u*f)},Mm=(e,t)=>YI(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),Wj=e=>Xs(e.width)&&Xs(e.height)&&Xs(e.x)&&Xs(e.y),Xs=e=>!isNaN(e)&&isFinite(e),XI=(e,t)=>(n,i)=>{},Af=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Mf=({x:e,y:t},[n,i,s],r=!1,o=[1,1])=>{const c={x:(e-n)/s,y:(t-i)/s};return r?Af(c,o):c},Yc=({x:e,y:t},[n,i,s])=>({x:e*s+n,y:t*s+i});function rc(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(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function Kle(e,t,n){if(typeof e=="string"||typeof e=="number"){const i=rc(e,n),s=rc(e,t);return{top:i,right:s,bottom:i,left:s,x:s*2,y:i*2}}if(typeof e=="object"){const i=rc(e.top??e.y??0,n),s=rc(e.bottom??e.y??0,n),r=rc(e.left??e.x??0,t),o=rc(e.right??e.x??0,t);return{top:i,right:o,bottom:s,left:r,x:r+o,y:i+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function Gle(e,t,n,i,s,r){const{x:o,y:c}=Yc(e,[t,n,i]),{x:u,y:f}=Yc({x:e.x+e.width,y:e.y+e.height},[t,n,i]),p=s-u,m=r-f;return{left:Math.floor(o),top:Math.floor(c),right:Math.floor(p),bottom:Math.floor(m)}}const Dw=(e,t,n,i,s,r)=>{const o=Kle(r,t,n),c=(t-o.x)/e.width,u=(n-o.y)/e.height,f=Math.min(c,u),p=Wc(f,i,s),m=e.x+e.width/2,b=e.y+e.height/2,y=t/2-m*p,x=n/2-b*p,v=Gle(e,y,x,p,t,n),w={left:Math.min(v.left-o.left,0),top:Math.min(v.top-o.top,0),right:Math.min(v.right-o.right,0),bottom:Math.min(v.bottom-o.bottom,0)};return{x:y-w.left+w.right,y:x-w.top+w.bottom,zoom:p}},Jd=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function gl(e){return e!=null&&e!=="parent"}function pa(e){var t,n;return{width:((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth??0,height:((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight??0}}function QI(e){var t,n;return(((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth)!==void 0&&(((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight)!==void 0}function ZI(e,t={width:0,height:0},n,i,s){const r={...e},o=i.get(n);if(o){const c=o.origin||s;r.x+=o.internals.positionAbsolute.x-(t.width??0)*c[0],r.y+=o.internals.positionAbsolute.y-(t.height??0)*c[1]}return r}function Yj(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Wle(){let e,t;return{promise:new Promise((i,s)=>{e=i,t=s}),resolve:e,reject:t}}function Yle(e){return{...$I,...e||{}}}function Ad(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:i,containerBounds:s}){const{x:r,y:o}=Qs(e),c=Mf({x:r-((s==null?void 0:s.left)??0),y:o-((s==null?void 0:s.top)??0)},i),{x:u,y:f}=n?Af(c,t):c;return{xSnapped:u,ySnapped:f,...c}}const Ow=e=>({width:e.offsetWidth,height:e.offsetHeight}),JI=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},Xle=["INPUT","SELECT","TEXTAREA"];function eP(e){var i,s;const t=((s=(i=e.composedPath)==null?void 0:i.call(e))==null?void 0:s[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:Xle.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const tP=e=>"clientX"in e,Qs=(e,t)=>{var r,o;const n=tP(e),i=n?e.clientX:(r=e.touches)==null?void 0:r[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:i-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Xj=(e,t,n,i,s)=>{const r=t.querySelectorAll(`.${e}`);return!r||!r.length?null:Array.from(r).map(o=>{const c=o.getBoundingClientRect();return{id:o.getAttribute("data-handleid"),type:e,nodeId:s,position:o.getAttribute("data-handlepos"),x:(c.left-n.left)/i,y:(c.top-n.top)/i,...Ow(o)}})};function nP({sourceX:e,sourceY:t,targetX:n,targetY:i,sourceControlX:s,sourceControlY:r,targetControlX:o,targetControlY:c}){const u=e*.125+s*.375+o*.375+n*.125,f=t*.125+r*.375+c*.375+i*.125,p=Math.abs(u-e),m=Math.abs(f-t);return[u,f,p,m]}function bp(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Qj({pos:e,x1:t,y1:n,x2:i,y2:s,c:r}){switch(e){case tt.Left:return[t-bp(t-i,r),n];case tt.Right:return[t+bp(i-t,r),n];case tt.Top:return[t,n-bp(n-s,r)];case tt.Bottom:return[t,n+bp(s-n,r)]}}function iP({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top,curvature:o=.25}){const[c,u]=Qj({pos:n,x1:e,y1:t,x2:i,y2:s,c:o}),[f,p]=Qj({pos:r,x1:i,y1:s,x2:e,y2:t,c:o}),[m,b,y,x]=nP({sourceX:e,sourceY:t,targetX:i,targetY:s,sourceControlX:c,sourceControlY:u,targetControlX:f,targetControlY:p});return[`M${e},${t} C${c},${u} ${f},${p} ${i},${s}`,m,b,y,x]}function sP({sourceX:e,sourceY:t,targetX:n,targetY:i}){const s=Math.abs(n-e)/2,r=n<e?n+s:n-s,o=Math.abs(i-t)/2,c=i<t?i+o:i-o;return[r,c,s,o]}function Qle({sourceNode:e,targetNode:t,selected:n=!1,zIndex:i=0,elevateOnSelect:s=!1,zIndexMode:r="basic"}){if(r==="manual")return i;const o=s&&n?i+1e3:i,c=Math.max(e.parentId||s&&e.selected?e.internals.z:0,t.parentId||s&&t.selected?t.internals.z:0);return o+c}function Zle({sourceNode:e,targetNode:t,width:n,height:i,transform:s}){const r=mg(Am(e),Am(t));r.x===r.x2&&(r.x2+=1),r.y===r.y2&&(r.y2+=1);const o={x:-s[0]/s[2],y:-s[1]/s[2],width:n/s[2],height:i/s[2]};return Mm(o,gg(r))>0}const rP=({source:e,sourceHandle:t,target:n,targetHandle:i})=>`xy-edge__${e}${t||""}-${n}${i||""}`,Jle=(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)),ece=(e,t,n={})=>{var r;if(!e.source||!e.target)return(r=n.onError)==null||r.call(n,"006",ls.error006()),t;const i=n.getEdgeId||rP;let s;return VI(e)?s={...e}:s={...e,id:i(e)},Jle(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))},tce=(e,t,n,i={shouldReplaceId:!0})=>{var f,p;const{id:s,...r}=e;if(!t.source||!t.target)return(f=i.onError)==null||f.call(i,"006",ls.error006()),n;if(!n.find(m=>m.id===e.id))return(p=i.onError)==null||p.call(i,"007",ls.error007(s)),n;const c=i.getEdgeId||rP,u={...r,id:i.shouldReplaceId?c(t):s,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle};return n.filter(m=>m.id!==s).concat(u)};function aP({sourceX:e,sourceY:t,targetX:n,targetY:i}){const[s,r,o,c]=sP({sourceX:e,sourceY:t,targetX:n,targetY:i});return[`M ${e},${t}L ${n},${i}`,s,r,o,c]}const Zj={[tt.Left]:{x:-1,y:0},[tt.Right]:{x:1,y:0},[tt.Top]:{x:0,y:-1},[tt.Bottom]:{x:0,y:1}},nce=({source:e,sourcePosition:t=tt.Bottom,target:n})=>t===tt.Left||t===tt.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},Jj=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function ice({source:e,sourcePosition:t=tt.Bottom,target:n,targetPosition:i=tt.Top,center:s,offset:r,stepPosition:o}){const c=Zj[t],u=Zj[i],f={x:e.x+c.x*r,y:e.y+c.y*r},p={x:n.x+u.x*r,y:n.y+u.y*r},m=nce({source:f,sourcePosition:t,target:p}),b=m.x!==0?"x":"y",y=m[b];let x=[],v,w;const k={x:0,y:0},C={x:0,y:0},[,,S,j]=sP({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(c[b]*u[b]===-1){b==="x"?(v=s.x??f.x+(p.x-f.x)*o,w=s.y??(f.y+p.y)/2):(v=s.x??(f.x+p.x)/2,w=s.y??f.y+(p.y-f.y)*o);const R=[{x:v,y:f.y},{x:v,y:p.y}],P=[{x:f.x,y:w},{x:p.x,y:w}];c[b]===y?x=b==="x"?R:P:x=b==="x"?P:R}else{const R=[{x:f.x,y:p.y}],P=[{x:p.x,y:f.y}];if(b==="x"?x=c.x===y?P:R:x=c.y===y?R:P,t===i){const D=Math.abs(e[b]-n[b]);if(D<=r){const L=Math.min(r-1,r-D);c[b]===y?k[b]=(f[b]>e[b]?-1:1)*L:C[b]=(p[b]>n[b]?-1:1)*L}}if(t!==i){const D=b==="x"?"y":"x",L=c[b]===u[D],z=f[D]>p[D],W=f[D]<p[D];(c[b]===1&&(!L&&z||L&&W)||c[b]!==1&&(!L&&W||L&&z))&&(x=b==="x"?R:P)}const I={x:f.x+k.x,y:f.y+k.y},B={x:p.x+C.x,y:p.y+C.y},F=Math.max(Math.abs(I.x-x[0].x),Math.abs(B.x-x[0].x)),V=Math.max(Math.abs(I.y-x[0].y),Math.abs(B.y-x[0].y));F>=V?(v=(I.x+B.x)/2,w=x[0].y):(v=x[0].x,w=(I.y+B.y)/2)}const T={x:f.x+k.x,y:f.y+k.y},A={x:p.x+C.x,y:p.y+C.y};return[[e,...T.x!==x[0].x||T.y!==x[0].y?[T]:[],...x,...A.x!==x[x.length-1].x||A.y!==x[x.length-1].y?[A]:[],n],v,w,S,j]}function sce(e,t,n,i){const s=Math.min(Jj(e,t)/2,Jj(t,n)/2,i),{x:r,y:o}=t;if(e.x===r&&r===n.x||e.y===o&&o===n.y)return`L${r} ${o}`;if(e.y===o){const f=e.x<n.x?-1:1,p=e.y<n.y?1:-1;return`L ${r+s*f},${o}Q ${r},${o} ${r},${o+s*p}`}const c=e.x<n.x?1:-1,u=e.y<n.y?-1:1;return`L ${r},${o+s*u}Q ${r},${o} ${r+s*c},${o}`}function M0({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top,borderRadius:o=5,centerX:c,centerY:u,offset:f=20,stepPosition:p=.5}){const[m,b,y,x,v]=ice({source:{x:e,y:t},sourcePosition:n,target:{x:i,y:s},targetPosition:r,center:{x:c,y:u},offset:f,stepPosition:p});let w=`M${m[0].x} ${m[0].y}`;for(let k=1;k<m.length-1;k++)w+=sce(m[k-1],m[k],m[k+1],o);return w+=`L${m[m.length-1].x} ${m[m.length-1].y}`,[w,b,y,x,v]}function eT(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function rce(e){var m;const{sourceNode:t,targetNode:n}=e;if(!eT(t)||!eT(n))return null;const i=t.internals.handleBounds||tT(t.handles),s=n.internals.handleBounds||tT(n.handles),r=nT((i==null?void 0:i.source)??[],e.sourceHandle),o=nT(e.connectionMode===Gc.Strict?(s==null?void 0:s.target)??[]:((s==null?void 0:s.target)??[]).concat((s==null?void 0:s.source)??[]),e.targetHandle);if(!r||!o)return(m=e.onError)==null||m.call(e,"008",ls.error008(r?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const c=(r==null?void 0:r.position)||tt.Bottom,u=(o==null?void 0:o.position)||tt.Top,f=yl(t,r,c),p=yl(n,o,u);return{sourceX:f.x,sourceY:f.y,targetX:p.x,targetY:p.y,sourcePosition:c,targetPosition:u}}function tT(e){if(!e)return null;const t=[],n=[];for(const i of e)i.width=i.width??1,i.height=i.height??1,i.type==="source"?t.push(i):i.type==="target"&&n.push(i);return{source:t,target:n}}function yl(e,t,n=tt.Left,i=!1){const s=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,r=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:o,height:c}=t??pa(e);if(i)return{x:s+o/2,y:r+c/2};switch((t==null?void 0:t.position)??n){case tt.Top:return{x:s+o/2,y:r};case tt.Right:return{x:s+o,y:r+c/2};case tt.Bottom:return{x:s+o/2,y:r+c};case tt.Left:return{x:s,y:r+c/2}}}function nT(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function R0(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(i=>`${i}=${e[i]}`).join("&")}`:""}function ace(e,{id:t,defaultColor:n,defaultMarkerStart:i,defaultMarkerEnd:s}){const r=new Set;return e.reduce((o,c)=>([c.markerStart||i,c.markerEnd||s].forEach(u=>{if(u&&typeof u=="object"){const f=R0(u,t);r.has(f)||(o.push({id:f,color:u.color||n,...u}),r.add(f))}}),o),[]).sort((o,c)=>o.id.localeCompare(c.id))}const oP=1e3,oce=10,Lw={nodeOrigin:[0,0],nodeExtent:Xd,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},lce={...Lw,checkEquality:!0};function Iw(e,t){const n={...e};for(const i in t)t[i]!==void 0&&(n[i]=t[i]);return n}function cce(e,t,n){const i=Iw(Lw,n);for(const s of e.values())if(s.parentId)zw(s,e,t,i);else{const r=jf(s,i.nodeOrigin),o=gl(s.extent)?s.extent:i.nodeExtent,c=ml(r,o,pa(s));s.internals.positionAbsolute=c}}function uce(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],i=[];for(const s of e.handles){const r={id:s.id,width:s.width??1,height:s.height??1,nodeId:e.id,x:s.x,y:s.y,position:s.position,type:s.type};s.type==="source"?n.push(r):s.type==="target"&&i.push(r)}return{source:n,target:i}}function Pw(e){return e==="manual"}function D0(e,t,n,i={}){var p,m;const s=Iw(lce,i),r={i:0},o=new Map(t),c=s!=null&&s.elevateNodesOnSelect&&!Pw(s.zIndexMode)?oP:0;let u=e.length>0,f=!1;t.clear(),n.clear();for(const b of e){let y=o.get(b.id);if(s.checkEquality&&b===(y==null?void 0:y.internals.userNode))t.set(b.id,y);else{const x=jf(b,s.nodeOrigin),v=gl(b.extent)?b.extent:s.nodeExtent,w=ml(x,v,pa(b));y={...s.defaults,...b,measured:{width:(p=b.measured)==null?void 0:p.width,height:(m=b.measured)==null?void 0:m.height},internals:{positionAbsolute:w,handleBounds:uce(b,y),z:lP(b,c,s.zIndexMode),userNode:b}},t.set(b.id,y)}(y.measured===void 0||y.measured.width===void 0||y.measured.height===void 0)&&!y.hidden&&(u=!1),b.parentId&&zw(y,t,n,i,r),f||(f=b.selected??!1)}return{nodesInitialized:u,hasSelectedNodes:f}}function dce(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 zw(e,t,n,i,s){const{elevateNodesOnSelect:r,nodeOrigin:o,nodeExtent:c,zIndexMode:u}=Iw(Lw,i),f=e.parentId,p=t.get(f);if(!p){console.warn(`Parent node ${f} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}dce(e,n),s&&!p.parentId&&p.internals.rootParentIndex===void 0&&u==="auto"&&(p.internals.rootParentIndex=++s.i,p.internals.z=p.internals.z+s.i*oce),s&&p.internals.rootParentIndex!==void 0&&(s.i=p.internals.rootParentIndex);const m=r&&!Pw(u)?oP:0,{x:b,y,z:x}=fce(e,p,o,c,m,u),{positionAbsolute:v}=e.internals,w=b!==v.x||y!==v.y;(w||x!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:b,y}:v,z:x}})}function lP(e,t,n){const i=Xs(e.zIndex)?e.zIndex:0;return Pw(n)?i:i+(e.selected?t:0)}function fce(e,t,n,i,s,r){const{x:o,y:c}=t.internals.positionAbsolute,u=pa(e),f=jf(e,n),p=gl(e.extent)?ml(f,e.extent,u):f;let m=ml({x:o+p.x,y:c+p.y},i,u);e.extent==="parent"&&(m=GI(m,u,t));const b=lP(e,s,r),y=t.internals.z??0;return{x:m.x,y:m.y,z:y>=b?y+1:b}}function Bw(e,t,n,i=[0,0]){var o;const s=[],r=new Map;for(const c of e){const u=t.get(c.parentId);if(!u)continue;const f=((o=r.get(c.parentId))==null?void 0:o.expandedRect)??Zd(u),p=WI(f,c.rect);r.set(c.parentId,{expandedRect:p,parent:u})}return r.size>0&&r.forEach(({expandedRect:c,parent:u},f)=>{var S;const p=u.internals.positionAbsolute,m=pa(u),b=u.origin??i,y=c.x<p.x?Math.round(Math.abs(p.x-c.x)):0,x=c.y<p.y?Math.round(Math.abs(p.y-c.y)):0,v=Math.max(m.width,Math.round(c.width)),w=Math.max(m.height,Math.round(c.height)),k=(v-m.width)*b[0],C=(w-m.height)*b[1];(y>0||x>0||k||C)&&(s.push({id:f,type:"position",position:{x:u.position.x-y+k,y:u.position.y-x+C}}),(S=n.get(f))==null||S.forEach(j=>{e.some(T=>T.id===j.id)||s.push({id:j.id,type:"position",position:{x:j.position.x+y,y:j.position.y+x}})})),(m.width<c.width||m.height<c.height||y||x)&&s.push({id:f,type:"dimensions",setAttributes:!0,dimensions:{width:v+(y?b[0]*y-k:0),height:w+(x?b[1]*x-C:0)}})}),s}function hce(e,t,n,i,s,r,o){const c=i==null?void 0:i.querySelector(".xyflow__viewport");let u=!1;if(!c)return{changes:[],updatedInternals:u};const f=[],p=window.getComputedStyle(c),{m22:m}=new window.DOMMatrixReadOnly(p.transform),b=[];for(const y of e.values()){const x=t.get(y.id);if(!x)continue;if(x.hidden){t.set(x.id,{...x,internals:{...x.internals,handleBounds:void 0}}),u=!0;continue}const v=Ow(y.nodeElement),w=x.measured.width!==v.width||x.measured.height!==v.height;if(!!(v.width&&v.height&&(w||!x.internals.handleBounds||y.force))){const C=y.nodeElement.getBoundingClientRect(),S=gl(x.extent)?x.extent:r;let{positionAbsolute:j}=x.internals;x.parentId&&x.extent==="parent"?j=GI(j,v,t.get(x.parentId)):S&&(j=ml(j,S,v));const T={...x,measured:v,internals:{...x.internals,positionAbsolute:j,handleBounds:{source:Xj("source",y.nodeElement,C,m,x.id),target:Xj("target",y.nodeElement,C,m,x.id)}}};t.set(x.id,T),x.parentId&&zw(T,t,n,{nodeOrigin:s,zIndexMode:o}),u=!0,w&&(f.push({id:x.id,type:"dimensions",dimensions:v}),x.expandParent&&x.parentId&&b.push({id:x.id,parentId:x.parentId,rect:Zd(T,s)}))}}if(b.length>0){const y=Bw(b,t,n,s);f.push(...y)}return{changes:f,updatedInternals:u}}async function pce({delta:e,panZoom:t,transform:n,translateExtent:i,width:s,height:r}){if(!t||!e.x&&!e.y)return!1;const o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[s,r]],i);return!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2])}function iT(e,t,n,i,s,r){let o=s;const c=i.get(o)||new Map;i.set(o,c.set(n,t)),o=`${s}-${e}`;const u=i.get(o)||new Map;if(i.set(o,u.set(n,t)),r){o=`${s}-${e}-${r}`;const f=i.get(o)||new Map;i.set(o,f.set(n,t))}}function cP(e,t,n){e.clear(),t.clear();for(const i of n){const{source:s,target:r,sourceHandle:o=null,targetHandle:c=null}=i,u={edgeId:i.id,source:s,target:r,sourceHandle:o,targetHandle:c},f=`${s}-${o}--${r}-${c}`,p=`${r}-${c}--${s}-${o}`;iT("source",u,p,e,s,o),iT("target",u,f,e,r,c),t.set(i.id,i)}}function uP(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:uP(n,t):!1}function sT(e,t,n){var s;let i=e;do{if((s=i==null?void 0:i.matches)!=null&&s.call(i,t))return!0;if(i===n)return!1;i=i==null?void 0:i.parentElement}while(i);return!1}function mce(e,t,n,i){const s=new Map;for(const[r,o]of e)if((o.selected||o.id===i)&&(!o.parentId||!uP(o,e))&&(o.draggable||t&&typeof o.draggable>"u")){const c=e.get(r);c&&s.set(r,{id:r,position:c.position||{x:0,y:0},distance:{x:n.x-c.internals.positionAbsolute.x,y:n.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:c.measured.width??0,height:c.measured.height??0}})}return s}function $x({nodeId:e,dragItems:t,nodeLookup:n,dragging:i=!0}){var o,c,u;const s=[];for(const[f,p]of t){const m=(o=n.get(f))==null?void 0:o.internals.userNode;m&&s.push({...m,position:p.position,dragging:i})}if(!e)return[s[0],s];const r=(c=n.get(e))==null?void 0:c.internals.userNode;return[r?{...r,position:((u=t.get(e))==null?void 0:u.position)||r.position,dragging:i}:s[0],s]}function gce({dragItems:e,snapGrid:t,x:n,y:i}){const s=e.values().next().value;if(!s)return null;const r={x:n-s.distance.x,y:i-s.distance.y},o=Af(r,t);return{x:o.x-r.x,y:o.y-r.y}}function yce({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:i,onDragStop:s}){let r={x:null,y:null},o=0,c=new Map,u=!1,f={x:0,y:0},p=null,m=!1,b=null,y=!1,x=!1,v=null;function w({noDragClassName:C,handleSelector:S,domNode:j,isSelectable:T,nodeId:A,nodeClickDistance:M=0}){b=ss(j);function R({x:F,y:V}){const{nodeLookup:D,nodeExtent:L,snapGrid:z,snapToGrid:W,nodeOrigin:X,onNodeDrag:G,onSelectionDrag:U,onError:q,updateNodePositions:Y}=t();r={x:F,y:V};let $=!1;const ie=c.size>1,be=ie&&L?A0(Tf(c)):null,ce=ie&&W?gce({dragItems:c,snapGrid:z,x:F,y:V}):null;for(const[_e,le]of c){if(!D.has(_e))continue;let pe={x:F-le.distance.x,y:V-le.distance.y};W&&(pe=ce?{x:Math.round(pe.x+ce.x),y:Math.round(pe.y+ce.y)}:Af(pe,z));let Te=null;if(ie&&L&&!le.extent&&be){const{positionAbsolute:xe}=le.internals,fe=xe.x-be.x+L[0][0],te=xe.x+le.measured.width-be.x2+L[1][0],we=xe.y-be.y+L[0][1],Fe=xe.y+le.measured.height-be.y2+L[1][1];Te=[[fe,we],[te,Fe]]}const{position:ne,positionAbsolute:oe}=KI({nodeId:_e,nextPosition:pe,nodeLookup:D,nodeExtent:Te||L,nodeOrigin:X,onError:q});$=$||le.position.x!==ne.x||le.position.y!==ne.y,le.position=ne,le.internals.positionAbsolute=oe}if(x=x||$,!!$&&(Y(c,!0),v&&(i||G||!A&&U))){const[_e,le]=$x({nodeId:A,dragItems:c,nodeLookup:D});i==null||i(v,c,_e,le),G==null||G(v,_e,le),A||U==null||U(v,le)}}async function P(){if(!p)return;const{transform:F,panBy:V,autoPanSpeed:D,autoPanOnNodeDrag:L}=t();if(!L){u=!1,cancelAnimationFrame(o);return}const[z,W]=Rw(f,p,D);(z!==0||W!==0)&&(r.x=(r.x??0)-z/F[2],r.y=(r.y??0)-W/F[2],await V({x:z,y:W})&&R(r)),o=requestAnimationFrame(P)}function I(F){var ie;const{nodeLookup:V,multiSelectionActive:D,nodesDraggable:L,transform:z,snapGrid:W,snapToGrid:X,selectNodesOnDrag:G,onNodeDragStart:U,onSelectionDragStart:q,unselectNodesAndEdges:Y}=t();m=!0,(!G||!T)&&!D&&A&&((ie=V.get(A))!=null&&ie.selected||Y()),T&&G&&A&&(e==null||e(A));const $=Ad(F.sourceEvent,{transform:z,snapGrid:W,snapToGrid:X,containerBounds:p});if(r=$,c=mce(V,L,$,A),c.size>0&&(n||U||!A&&q)){const[be,ce]=$x({nodeId:A,dragItems:c,nodeLookup:V});n==null||n(F.sourceEvent,c,be,ce),U==null||U(F.sourceEvent,be,ce),A||q==null||q(F.sourceEvent,ce)}}const B=NI().clickDistance(M).on("start",F=>{const{domNode:V,nodeDragThreshold:D,transform:L,snapGrid:z,snapToGrid:W}=t();p=(V==null?void 0:V.getBoundingClientRect())||null,y=!1,x=!1,v=F.sourceEvent,D===0&&I(F),r=Ad(F.sourceEvent,{transform:L,snapGrid:z,snapToGrid:W,containerBounds:p}),f=Qs(F.sourceEvent,p)}).on("drag",F=>{const{autoPanOnNodeDrag:V,transform:D,snapGrid:L,snapToGrid:z,nodeDragThreshold:W,nodeLookup:X}=t(),G=Ad(F.sourceEvent,{transform:D,snapGrid:L,snapToGrid:z,containerBounds:p});if(v=F.sourceEvent,(F.sourceEvent.type==="touchmove"&&F.sourceEvent.touches.length>1||A&&!X.has(A))&&(y=!0),!y){if(!u&&V&&m&&(u=!0,P()),!m){const U=Qs(F.sourceEvent,p),q=U.x-f.x,Y=U.y-f.y;Math.sqrt(q*q+Y*Y)>W&&I(F)}(r.x!==G.xSnapped||r.y!==G.ySnapped)&&c&&m&&(f=Qs(F.sourceEvent,p),R(G))}}).on("end",F=>{if(!m||y){y&&c.size>0&&t().updateNodePositions(c,!1);return}if(u=!1,m=!1,cancelAnimationFrame(o),c.size>0){const{nodeLookup:V,updateNodePositions:D,onNodeDragStop:L,onSelectionDragStop:z}=t();if(x&&(D(c,!1),x=!1),s||L||!A&&z){const[W,X]=$x({nodeId:A,dragItems:c,nodeLookup:V,dragging:!1});s==null||s(F.sourceEvent,c,W,X),L==null||L(F.sourceEvent,W,X),A||z==null||z(F.sourceEvent,X)}}}).filter(F=>{const V=F.target;return!F.button&&(!C||!sT(V,`.${C}`,j))&&(!S||sT(V,S,j))});b.call(B)}function k(){b==null||b.on(".drag",null)}return{update:w,destroy:k}}function bce(e,t,n){const i=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const r of t.values())Mm(s,Zd(r))>0&&i.push(r);return i}const xce=250;function vce(e,t,n,i){var c,u;let s=[],r=1/0;const o=bce(e,n,t+xce);for(const f of o){const p=[...((c=f.internals.handleBounds)==null?void 0:c.source)??[],...((u=f.internals.handleBounds)==null?void 0:u.target)??[]];for(const m of p){if(i.nodeId===m.nodeId&&i.type===m.type&&i.id===m.id)continue;const{x:b,y}=yl(f,m,m.position,!0),x=Math.sqrt(Math.pow(b-e.x,2)+Math.pow(y-e.y,2));x>t||(x<r?(s=[{...m,x:b,y}],r=x):x===r&&s.push({...m,x:b,y}))}}if(!s.length)return null;if(s.length>1){const f=i.type==="source"?"target":"source";return s.find(p=>p.type===f)??s[0]}return s[0]}function dP(e,t,n,i,s,r=!1){var f,p,m;const o=i.get(e);if(!o)return null;const c=s==="strict"?(f=o.internals.handleBounds)==null?void 0:f[t]:[...((p=o.internals.handleBounds)==null?void 0:p.source)??[],...((m=o.internals.handleBounds)==null?void 0:m.target)??[]],u=(n?c==null?void 0:c.find(b=>b.id===n):c==null?void 0:c[0])??null;return u&&r?{...u,...yl(o,u,u.position,!0)}:u}function fP(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function wce(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const hP=()=>!0;function Ece(e,{connectionMode:t,connectionRadius:n,handleId:i,nodeId:s,edgeUpdaterType:r,isTarget:o,domNode:c,nodeLookup:u,lib:f,autoPanOnConnect:p,flowId:m,panBy:b,cancelConnection:y,onConnectStart:x,onConnect:v,onConnectEnd:w,isValidConnection:k=hP,onReconnectEnd:C,updateConnection:S,getTransform:j,getFromHandle:T,autoPanSpeed:A,dragThreshold:M=1,handleDomNode:R}){const P=JI(e.target);let I=0,B;const{x:F,y:V}=Qs(e),D=fP(r,R),L=c==null?void 0:c.getBoundingClientRect();let z=!1;if(!L||!D)return;const W=dP(s,D,i,u,t);if(!W)return;let X=Qs(e,L),G=!1,U=null,q=!1,Y=null;function $(){if(!p||!L)return;const[ne,oe]=Rw(X,L,A);b({x:ne,y:oe}),I=requestAnimationFrame($)}const ie={...W,nodeId:s,type:D,position:W.position},be=u.get(s);let _e={inProgress:!0,isValid:null,from:yl(be,ie,tt.Left,!0),fromHandle:ie,fromPosition:ie.position,fromNode:be,to:X,toHandle:null,toPosition:Kj[ie.position],toNode:null,pointer:X};function le(){z=!0,S(_e),x==null||x(e,{nodeId:s,handleId:i,handleType:D})}M===0&&le();function pe(ne){if(!z){const{x:Fe,y:Le}=Qs(ne),ht=Fe-F,nt=Le-V;if(!(ht*ht+nt*nt>M*M))return;le()}if(!T()||!ie){Te(ne);return}const oe=j();X=Qs(ne,L),B=vce(Mf(X,oe,!1,[1,1]),n,u,ie),G||($(),G=!0);const xe=pP(ne,{handle:B,connectionMode:t,fromNodeId:s,fromHandleId:i,fromType:o?"target":"source",isValidConnection:k,doc:P,lib:f,flowId:m,nodeLookup:u});Y=xe.handleDomNode,U=xe.connection,q=wce(!!B,xe.isValid);const fe=u.get(s),te=fe?yl(fe,ie,tt.Left,!0):_e.from,we={..._e,from:te,isValid:q,to:xe.toHandle&&q?Yc({x:xe.toHandle.x,y:xe.toHandle.y},oe):X,toHandle:xe.toHandle,toPosition:q&&xe.toHandle?xe.toHandle.position:Kj[ie.position],toNode:xe.toHandle?u.get(xe.toHandle.nodeId):null,pointer:X};S(we),_e=we}function Te(ne){if(!("touches"in ne&&ne.touches.length>0)){if(z){(B||Y)&&U&&q&&(v==null||v(U));const{inProgress:oe,...xe}=_e,fe={...xe,toPosition:_e.toHandle?_e.toPosition:null};w==null||w(ne,fe),r&&(C==null||C(ne,fe))}y(),cancelAnimationFrame(I),G=!1,q=!1,U=null,Y=null,P.removeEventListener("mousemove",pe),P.removeEventListener("mouseup",Te),P.removeEventListener("touchmove",pe),P.removeEventListener("touchend",Te)}}P.addEventListener("mousemove",pe),P.addEventListener("mouseup",Te),P.addEventListener("touchmove",pe),P.addEventListener("touchend",Te)}function pP(e,{handle:t,connectionMode:n,fromNodeId:i,fromHandleId:s,fromType:r,doc:o,lib:c,flowId:u,isValidConnection:f=hP,nodeLookup:p}){const m=r==="target",b=t?o.querySelector(`.${c}-flow__handle[data-id="${u}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:y,y:x}=Qs(e),v=o.elementFromPoint(y,x),w=v!=null&&v.classList.contains(`${c}-flow__handle`)?v:b,k={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const C=fP(void 0,w),S=w.getAttribute("data-nodeid"),j=w.getAttribute("data-handleid"),T=w.classList.contains("connectable"),A=w.classList.contains("connectableend");if(!S||!C)return k;const M={source:m?S:i,sourceHandle:m?j:s,target:m?i:S,targetHandle:m?s:j};k.connection=M;const P=T&&A&&(n===Gc.Strict?m&&C==="source"||!m&&C==="target":S!==i||j!==s);k.isValid=P&&f(M),k.toHandle=dP(S,C,j,p,n,!0)}return k}const O0={onPointerDown:Ece,isValid:pP};function kce({domNode:e,panZoom:t,getTransform:n,getViewScale:i}){const s=ss(e);function r({translateExtent:c,width:u,height:f,zoomStep:p=1,pannable:m=!0,zoomable:b=!0,inversePan:y=!1}){const x=S=>{if(S.sourceEvent.type!=="wheel"||!t)return;const j=n(),T=S.sourceEvent.ctrlKey&&Jd()?10:1,A=-S.sourceEvent.deltaY*(S.sourceEvent.deltaMode===1?.05:S.sourceEvent.deltaMode?1:.002)*p,M=j[2]*Math.pow(2,A*T);t.scaleTo(M)};let v=[0,0];const w=S=>{(S.sourceEvent.type==="mousedown"||S.sourceEvent.type==="touchstart")&&(v=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY])},k=S=>{const j=n();if(S.sourceEvent.type!=="mousemove"&&S.sourceEvent.type!=="touchmove"||!t)return;const T=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY],A=[T[0]-v[0],T[1]-v[1]];v=T;const M=i()*Math.max(j[2],Math.log(j[2]))*(y?-1:1),R={x:j[0]-A[0]*M,y:j[1]-A[1]*M},P=[[0,0],[u,f]];t.setViewportConstrained({x:R.x,y:R.y,zoom:j[2]},P,c)},C=UI().on("start",w).on("zoom",m?k:null).on("zoom.wheel",b?x:null);s.call(C,{})}function o(){s.on("zoom",null)}return{update:r,destroy:o,pointer:Gs}}const yg=e=>({x:e.x,y:e.y,zoom:e.k}),qx=({x:e,y:t,zoom:n})=>pg.translate(e,t).scale(n),yc=(e,t)=>e.target.closest(`.${t}`),mP=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Sce=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Hx=(e,t=0,n=Sce,i=()=>{})=>{const s=typeof t=="number"&&t>0;return s||i(),s?e.transition().duration(t).ease(n).on("end",i):e},gP=e=>{const t=e.ctrlKey&&Jd()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Nce({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:i,panOnScrollMode:s,panOnScrollSpeed:r,zoomOnPinch:o,onPanZoomStart:c,onPanZoom:u,onPanZoomEnd:f}){return p=>{if(yc(p,t))return p.ctrlKey&&p.preventDefault(),!1;p.preventDefault(),p.stopImmediatePropagation();const m=n.property("__zoom").k||1;if(p.ctrlKey&&o){const w=Gs(p),k=gP(p),C=m*Math.pow(2,k);i.scaleTo(n,C,w,p);return}const b=p.deltaMode===1?20:1;let y=s===ol.Vertical?0:p.deltaX*b,x=s===ol.Horizontal?0:p.deltaY*b;!Jd()&&p.shiftKey&&s!==ol.Vertical&&(y=p.deltaY*b,x=0),i.translateBy(n,-(y/m)*r,-(x/m)*r,{internal:!0});const v=yg(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(u==null||u(p,v),e.panScrollTimeout=setTimeout(()=>{f==null||f(p,v),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,c==null||c(p,v))}}function _ce({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(i,s){const r=i.type==="wheel",o=!t&&r&&!i.ctrlKey,c=yc(i,e);if(i.ctrlKey&&r&&c&&i.preventDefault(),o||c)return null;i.preventDefault(),n.call(this,i,s)}}function Cce({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return i=>{var r,o,c;if((r=i.sourceEvent)!=null&&r.internal)return;const s=yg(i.transform);e.mouseButton=((o=i.sourceEvent)==null?void 0:o.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=s,((c=i.sourceEvent)==null?void 0:c.type)==="mousedown"&&t(!0),n&&(n==null||n(i.sourceEvent,s))}}function jce({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:i,onPanZoom:s}){return r=>{var o,c;e.usedRightMouseButton=!!(n&&mP(t,e.mouseButton??0)),(o=r.sourceEvent)!=null&&o.sync||i([r.transform.x,r.transform.y,r.transform.k]),s&&!((c=r.sourceEvent)!=null&&c.internal)&&(s==null||s(r.sourceEvent,yg(r.transform)))}}function Tce({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:i,onPanZoomEnd:s,onPaneContextMenu:r}){return o=>{var c;if(!((c=o.sourceEvent)!=null&&c.internal)&&(e.isZoomingOrPanning=!1,r&&mP(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&r(o.sourceEvent),e.usedRightMouseButton=!1,i(!1),s)){const u=yg(o.transform);e.prevViewport=u,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s==null||s(o.sourceEvent,u)},n?150:0)}}}function Ace({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:i,panOnScroll:s,zoomOnDoubleClick:r,userSelectionActive:o,noWheelClassName:c,noPanClassName:u,lib:f,connectionInProgress:p}){return m=>{var w;const b=e||t,y=n&&m.ctrlKey,x=m.type==="wheel";if(m.button===1&&m.type==="mousedown"&&(yc(m,`${f}-flow__node`)||yc(m,`${f}-flow__edge`)))return!0;if(!i&&!b&&!s&&!r&&!n||o||p&&!x||yc(m,c)&&x||yc(m,u)&&(!x||s&&x&&!e)||!n&&m.ctrlKey&&x)return!1;if(!n&&m.type==="touchstart"&&((w=m.touches)==null?void 0:w.length)>1)return m.preventDefault(),!1;if(!b&&!s&&!y&&x||!i&&(m.type==="mousedown"||m.type==="touchstart")||Array.isArray(i)&&!i.includes(m.button)&&m.type==="mousedown")return!1;const v=Array.isArray(i)&&i.includes(m.button)||!m.button||m.button<=1;return(!m.ctrlKey||x)&&v}}function Mce({domNode:e,minZoom:t,maxZoom:n,translateExtent:i,viewport:s,onPanZoom:r,onPanZoomStart:o,onPanZoomEnd:c,onDraggingChange:u}){const f={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},p=e.getBoundingClientRect(),m=UI().scaleExtent([t,n]).translateExtent(i),b=ss(e).call(m);C({x:s.x,y:s.y,zoom:Wc(s.zoom,t,n)},[[0,0],[p.width,p.height]],i);const y=b.on("wheel.zoom"),x=b.on("dblclick.zoom");m.wheelDelta(gP);async function v(B,F){return b?new Promise(V=>{m==null||m.interpolate((F==null?void 0:F.interpolate)==="linear"?Td:$p).transform(Hx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}function w({noWheelClassName:B,noPanClassName:F,onPaneContextMenu:V,userSelectionActive:D,panOnScroll:L,panOnDrag:z,panOnScrollMode:W,panOnScrollSpeed:X,preventScrolling:G,zoomOnPinch:U,zoomOnScroll:q,zoomOnDoubleClick:Y,zoomActivationKeyPressed:$,lib:ie,onTransformChange:be,connectionInProgress:ce,paneClickDistance:_e,selectionOnDrag:le}){D&&!f.isZoomingOrPanning&&k();const pe=L&&!$&&!D;m.clickDistance(le?1/0:!Xs(_e)||_e<0?0:_e);const Te=pe?Nce({zoomPanValues:f,noWheelClassName:B,d3Selection:b,d3Zoom:m,panOnScrollMode:W,panOnScrollSpeed:X,zoomOnPinch:U,onPanZoomStart:o,onPanZoom:r,onPanZoomEnd:c}):_ce({noWheelClassName:B,preventScrolling:G,d3ZoomHandler:y});b.on("wheel.zoom",Te,{passive:!1});const ne=Cce({zoomPanValues:f,onDraggingChange:u,onPanZoomStart:o});m.on("start",ne);const oe=jce({zoomPanValues:f,panOnDrag:z,onPaneContextMenu:!!V,onPanZoom:r,onTransformChange:be});m.on("zoom",oe);const xe=Tce({zoomPanValues:f,panOnDrag:z,panOnScroll:L,onPaneContextMenu:V,onPanZoomEnd:c,onDraggingChange:u});m.on("end",xe);const fe=Ace({zoomActivationKeyPressed:$,panOnDrag:z,zoomOnScroll:q,panOnScroll:L,zoomOnDoubleClick:Y,zoomOnPinch:U,userSelectionActive:D,noPanClassName:F,noWheelClassName:B,lib:ie,connectionInProgress:ce});m.filter(fe),Y?b.on("dblclick.zoom",x):b.on("dblclick.zoom",null)}function k(){m.on("zoom",null)}async function C(B,F,V){const D=qx(B),L=m==null?void 0:m.constrain()(D,F,V);return L&&await v(L),L}async function S(B,F){const V=qx(B);return await v(V,F),V}function j(B){if(b){const F=qx(B),V=b.property("__zoom");(V.k!==B.zoom||V.x!==B.x||V.y!==B.y)&&(m==null||m.transform(b,F,null,{sync:!0}))}}function T(){const B=b?BI(b.node()):{x:0,y:0,k:1};return{x:B.x,y:B.y,zoom:B.k}}async function A(B,F){return b?new Promise(V=>{m==null||m.interpolate((F==null?void 0:F.interpolate)==="linear"?Td:$p).scaleTo(Hx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}async function M(B,F){return b?new Promise(V=>{m==null||m.interpolate((F==null?void 0:F.interpolate)==="linear"?Td:$p).scaleBy(Hx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}function R(B){m==null||m.scaleExtent(B)}function P(B){m==null||m.translateExtent(B)}function I(B){const F=!Xs(B)||B<0?0:B;m==null||m.clickDistance(F)}return{update:w,destroy:k,setViewport:S,setViewportConstrained:C,getViewport:T,scaleTo:A,scaleBy:M,setScaleExtent:R,setTranslateExtent:P,syncViewport:j,setClickDistance:I}}var Xc;(function(e){e.Line="line",e.Handle="handle"})(Xc||(Xc={}));function Rce({width:e,prevWidth:t,height:n,prevHeight:i,affectsX:s,affectsY:r}){const o=e-t,c=n-i,u=[o>0?1:o<0?-1:0,c>0?1:c<0?-1:0];return o&&s&&(u[0]=u[0]*-1),c&&r&&(u[1]=u[1]*-1),u}function rT(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),i=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:i,affectsY:s}}function Ua(e,t){return Math.max(0,t-e)}function Fa(e,t){return Math.max(0,e-t)}function xp(e,t,n){return Math.max(0,t-e,e-n)}function aT(e,t){return e?!t:t}function Dce(e,t,n,i,s,r,o,c){let{affectsX:u,affectsY:f}=t;const{isHorizontal:p,isVertical:m}=t,b=p&&m,{xSnapped:y,ySnapped:x}=n,{minWidth:v,maxWidth:w,minHeight:k,maxHeight:C}=i,{x:S,y:j,width:T,height:A,aspectRatio:M}=e;let R=Math.floor(p?y-e.pointerX:0),P=Math.floor(m?x-e.pointerY:0);const I=T+(u?-R:R),B=A+(f?-P:P),F=-r[0]*T,V=-r[1]*A;let D=xp(I,v,w),L=xp(B,k,C);if(o){let X=0,G=0;u&&R<0?X=Ua(S+R+F,o[0][0]):!u&&R>0&&(X=Fa(S+I+F,o[1][0])),f&&P<0?G=Ua(j+P+V,o[0][1]):!f&&P>0&&(G=Fa(j+B+V,o[1][1])),D=Math.max(D,X),L=Math.max(L,G)}if(c){let X=0,G=0;u&&R>0?X=Fa(S+R,c[0][0]):!u&&R<0&&(X=Ua(S+I,c[1][0])),f&&P>0?G=Fa(j+P,c[0][1]):!f&&P<0&&(G=Ua(j+B,c[1][1])),D=Math.max(D,X),L=Math.max(L,G)}if(s){if(p){const X=xp(I/M,k,C)*M;if(D=Math.max(D,X),o){let G=0;!u&&!f||u&&!f&&b?G=Fa(j+V+I/M,o[1][1])*M:G=Ua(j+V+(u?R:-R)/M,o[0][1])*M,D=Math.max(D,G)}if(c){let G=0;!u&&!f||u&&!f&&b?G=Ua(j+I/M,c[1][1])*M:G=Fa(j+(u?R:-R)/M,c[0][1])*M,D=Math.max(D,G)}}if(m){const X=xp(B*M,v,w)/M;if(L=Math.max(L,X),o){let G=0;!u&&!f||f&&!u&&b?G=Fa(S+B*M+F,o[1][0])/M:G=Ua(S+(f?P:-P)*M+F,o[0][0])/M,L=Math.max(L,G)}if(c){let G=0;!u&&!f||f&&!u&&b?G=Ua(S+B*M,c[1][0])/M:G=Fa(S+(f?P:-P)*M,c[0][0])/M,L=Math.max(L,G)}}}P=P+(P<0?L:-L),R=R+(R<0?D:-D),s&&(b?I>B*M?P=(aT(u,f)?-R:R)/M:R=(aT(u,f)?-P:P)*M:p?(P=R/M,f=u):(R=P*M,u=f));const z=u?S+R:S,W=f?j+P:j;return{width:T+(u?-R:R),height:A+(f?-P:P),x:r[0]*R*(u?-1:1)+z,y:r[1]*P*(f?-1:1)+W}}const yP={width:0,height:0,x:0,y:0},Oce={...yP,pointerX:0,pointerY:0,aspectRatio:1};function Lce(e,t,n){const i=t.position.x+e.position.x,s=t.position.y+e.position.y,r=e.measured.width??0,o=e.measured.height??0,c=n[0]*r,u=n[1]*o;return[[i-c,s-u],[i+r-c,s+o-u]]}function Ice({domNode:e,nodeId:t,getStoreItems:n,onChange:i,onEnd:s}){const r=ss(e);let o={controlDirection:rT("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function c({controlPosition:f,boundaries:p,keepAspectRatio:m,resizeDirection:b,onResizeStart:y,onResize:x,onResizeEnd:v,shouldResize:w}){let k={...yP},C={...Oce};o={boundaries:p,resizeDirection:b,keepAspectRatio:m,controlDirection:rT(f)};let S,j=null,T=[],A,M,R,P=!1;const I=NI().on("start",B=>{const{nodeLookup:F,transform:V,snapGrid:D,snapToGrid:L,nodeOrigin:z,paneDomNode:W}=n();if(S=F.get(t),!S)return;j=(W==null?void 0:W.getBoundingClientRect())??null;const{xSnapped:X,ySnapped:G}=Ad(B.sourceEvent,{transform:V,snapGrid:D,snapToGrid:L,containerBounds:j});k={width:S.measured.width??0,height:S.measured.height??0,x:S.position.x??0,y:S.position.y??0},C={...k,pointerX:X,pointerY:G,aspectRatio:k.width/k.height},A=void 0,M=gl(S.extent)?S.extent:void 0,S.parentId&&(S.extent==="parent"||S.expandParent)&&(A=F.get(S.parentId)),A&&S.extent==="parent"&&(M=[[0,0],[A.measured.width,A.measured.height]]),T=[],R=void 0;for(const[U,q]of F)if(q.parentId===t&&(T.push({id:U,position:{...q.position},extent:q.extent}),q.extent==="parent"||q.expandParent)){const Y=Lce(q,S,q.origin??z);R?R=[[Math.min(Y[0][0],R[0][0]),Math.min(Y[0][1],R[0][1])],[Math.max(Y[1][0],R[1][0]),Math.max(Y[1][1],R[1][1])]]:R=Y}y==null||y(B,{...k})}).on("drag",B=>{const{transform:F,snapGrid:V,snapToGrid:D,nodeOrigin:L}=n(),z=Ad(B.sourceEvent,{transform:F,snapGrid:V,snapToGrid:D,containerBounds:j}),W=[];if(!S)return;const{x:X,y:G,width:U,height:q}=k,Y={},$=S.origin??L,{width:ie,height:be,x:ce,y:_e}=Dce(C,o.controlDirection,z,o.boundaries,o.keepAspectRatio,$,M,R),le=ie!==U,pe=be!==q,Te=ce!==X&&le,ne=_e!==G&&pe;if(!Te&&!ne&&!le&&!pe)return;if((Te||ne||$[0]===1||$[1]===1)&&(Y.x=Te?ce:k.x,Y.y=ne?_e:k.y,k.x=Y.x,k.y=Y.y,T.length>0)){const te=ce-X,we=_e-G;for(const Fe of T)Fe.position={x:Fe.position.x-te+$[0]*(ie-U),y:Fe.position.y-we+$[1]*(be-q)},W.push(Fe)}if((le||pe)&&(Y.width=le&&(!o.resizeDirection||o.resizeDirection==="horizontal")?ie:k.width,Y.height=pe&&(!o.resizeDirection||o.resizeDirection==="vertical")?be:k.height,k.width=Y.width,k.height=Y.height),A&&S.expandParent){const te=$[0]*(Y.width??0);Y.x&&Y.x<te&&(k.x=te,C.x=C.x-(Y.x-te));const we=$[1]*(Y.height??0);Y.y&&Y.y<we&&(k.y=we,C.y=C.y-(Y.y-we))}const oe=Rce({width:k.width,prevWidth:U,height:k.height,prevHeight:q,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),xe={...k,direction:oe};(w==null?void 0:w(B,xe))!==!1&&(P=!0,x==null||x(B,xe),i(Y,W))}).on("end",B=>{P&&(v==null||v(B,{...k}),s==null||s({...k}),P=!1)});r.call(I)}function u(){r.on(".drag",null)}return{update:c,destroy:u}}var Vx={exports:{}},Kx={},Gx={exports:{}},Wx={};/**
|
|
841
|
+
# ...`,"aria-label":t("skills.import.body")})]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:f.isPending||!u||!o.trim(),onClick:()=>f.mutate(),children:[f.isPending?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(n1,{size:14,strokeWidth:3}),t("skills.import.submit")]})]})})}function Bie({onClose:e,onSubmit:t}){const n=Ye(),[i,s]=_.useState(""),[r,o]=_.useState(""),c=/^[a-z0-9][a-z0-9-]*$/.test(i);return d.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:d.jsx("div",{className:"w-full max-w-xl my-8",children:d.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[d.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[d.jsx(ao,{size:16,strokeWidth:2.5}),n("skills.ai.title")]}),d.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:d.jsx(vn,{size:14,strokeWidth:3})})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.name")}),d.jsx("input",{type:"text",value:i,onChange:u=>s(u.target.value),placeholder:"rust-error-handling",className:"nb-input w-full font-[family-name:var(--font-mono)]","aria-label":n("skills.ai.name")})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.intent")}),d.jsx("textarea",{value:r,onChange:u=>o(u.target.value),placeholder:n("skills.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("skills.ai.intent")})]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!c||!r.trim(),onClick:()=>t(i,r),children:[d.jsx(ao,{size:14,strokeWidth:2.5}),n("skills.ai.submit")]})]})})})}async function Uie(e){const{files:t}=await Ane(e),n=t["SKILL.md"]??"",i=new Blob([n],{type:"text/markdown"}),s=URL.createObjectURL(i),r=document.createElement("a");r.href=s,r.download=`${e}.SKILL.md`,r.click(),URL.revokeObjectURL(s)}const Fie=[{value:"all",labelKey:"skills.category.all"},{value:"language",labelKey:"skills.category.language"},{value:"domain",labelKey:"skills.category.domain"},{value:"persona",labelKey:"skills.category.persona"},{value:"workflow",labelKey:"skills.category.workflow"},{value:"engine",labelKey:"skills.category.engine"},{value:"genre",labelKey:"skills.category.genre"},{value:"platform",labelKey:"skills.category.platform"},{value:"review",labelKey:"skills.category.review"},{value:"meta",labelKey:"skills.category.meta"},{value:"other",labelKey:"skills.category.other"}],$ie={language:"var(--color-accent-purple)",domain:"var(--color-secondary)",persona:"var(--color-primary)",workflow:"var(--color-accent-mint)",engine:"var(--color-accent-yellow)",genre:"var(--color-accent-pink)",platform:"var(--color-secondary-dark)",review:"var(--color-primary-dark)",meta:"var(--surface-control)",other:"var(--surface-control)"};function qie(){var F,V;const e=Ye(),[t,n]=_.useState("all"),[i,s]=_.useState([]),[r,o]=_.useState(""),[c,u]=_.useState(null),[f,p]=_.useState(!1),[m,b]=_.useState(!1),y=Xt(),v=(((F=Je({queryKey:["gen-jobs"],queryFn:rI,refetchInterval:3e3}).data)==null?void 0:F.data)??[]).filter(D=>D.kind==="skill"),w=v.filter(D=>D.status!=="done"),k=_.useRef(new Set);_.useEffect(()=>{for(const D of v)(D.status==="done"||D.status==="error")&&!k.current.has(D.id)&&(k.current.add(D.id),y.invalidateQueries({queryKey:["skills"]}),y.invalidateQueries({queryKey:["skill-updates"]}))},[v,y]);const C=(D,L)=>{Mne(D,L).then(()=>y.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},j=(((V=Je({queryKey:["skill-updates"],queryFn:jne}).data)==null?void 0:V.data)??[]).filter(D=>D.status!=="same").length,{data:T,isLoading:A}=Je({queryKey:["skills"],queryFn:()=>og()}),M=Je({queryKey:["projects"],queryFn:fo}),R=_.useMemo(()=>((T==null?void 0:T.data)??[]).filter(L=>!(t!=="all"&&L.category!==t||i.length>0&&!L.tags.some(z=>i.includes(z))||r&&!L.name.toLowerCase().includes(r.toLowerCase()))),[T,t,i,r]),P=_.useMemo(()=>{const D=(T==null?void 0:T.data)??[],L={all:D.length};for(const z of D)L[z.category]=(L[z.category]??0)+1;return L},[T]),I=_.useMemo(()=>{const D=new Map;for(const L of(T==null?void 0:T.data)??[])for(const z of L.tags)D.set(z,(D.get(z)??0)+1);return[...D.entries()].sort((L,z)=>z[1]-L[1]||L[0].localeCompare(z[0]))},[T]),B=D=>s(L=>L.includes(D)?L.filter(z=>z!==D):[...L,D]);return d.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[d.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[d.jsxs("div",{children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:"Skills"}),d.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:A?e("common.loading"):e("skills.subtitleCount",{count:(T==null?void 0:T.data.length)??0})})]}),d.jsxs("div",{className:"flex gap-3 items-center",children:[j>0&&d.jsx("span",{className:"nb-badge text-[10px]",title:e("skills.updates.badge",{count:String(j)}),children:e("skills.updates.badge",{count:String(j)})}),d.jsxs("button",{className:"nb-btn",onClick:()=>b(!0),type:"button",children:[d.jsx(ao,{size:14,strokeWidth:2.5}),e("skills.ai")]}),d.jsxs("button",{className:"nb-btn",onClick:()=>p(!0),type:"button",children:[d.jsx(n1,{size:14,strokeWidth:2.5}),e("skills.import")]}),d.jsxs("button",{className:"nb-btn nb-btn-mint",onClick:async()=>{await Nne(),y.invalidateQueries({queryKey:["skills"]}),y.invalidateQueries({queryKey:["skill-updates"]})},type:"button",children:[d.jsx(ro,{size:14,strokeWidth:2.5}),"Sync bundled"]})]})]}),d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs("div",{className:"relative shrink-0 w-full max-w-xs",children:[d.jsx(hf,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),d.jsx("input",{className:"nb-input pl-9 w-full",placeholder:e("skills.search.placeholder"),value:r,onChange:D=>o(D.target.value),"aria-label":e("skills.search.aria")})]}),d.jsx(au,{ariaLabel:"skill categories",className:"flex-1 min-w-0",value:t,onChange:n,options:Fie.filter(D=>D.value==="all"||(P[D.value]??0)>0).map(D=>({value:D.value,label:d.jsxs(d.Fragment,{children:[e(D.labelKey)," ",P[D.value]??0]})}))})]}),I.length>0&&d.jsxs("div",{className:"flex items-start gap-2 flex-wrap",children:[d.jsx("span",{className:"text-xs font-bold text-[var(--color-text-muted)] pt-1.5 uppercase tracking-wider",children:e("skills.tags.title")}),d.jsxs("div",{className:"flex flex-wrap gap-1.5 flex-1",children:[I.map(([D,L])=>{const z=i.includes(D);return d.jsxs("button",{type:"button",onClick:()=>B(D),className:["px-2.5 py-1 rounded-full text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)] transition-colors",z?"bg-[var(--color-text)] text-[var(--color-bg)] font-bold":"bg-[var(--surface-control)] text-[var(--color-text-muted)] hover:bg-[var(--surface-control-hover)]"].join(" "),children:[D," ",d.jsx("span",{className:"opacity-60",children:L})]},D)}),i.length>0&&d.jsx("button",{type:"button",onClick:()=>s([]),className:"px-2.5 py-1 rounded-full text-xs font-bold text-[var(--color-crashed)] hover:underline",children:e("skills.tags.clear")})]})]}),d.jsxs("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:[w.map(D=>d.jsxs("div",{className:`nb-card flex items-center gap-2 ${D.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,children:[D.status==="running"?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(vn,{size:14,strokeWidth:3}),d.jsx("span",{className:"text-sm text-[var(--color-text-muted)] truncate",children:D.status==="running"?`${D.label} · ${e("skills.ai.wait")}`:`${D.label}: ${D.error??e("skills.ai.error")}`})]},D.id)),R.map(D=>{var L;return d.jsx(Hie,{skill:D,projectCount:((L=M.data)==null?void 0:L.data.length)??0,onOpen:()=>u(D.name),onExport:()=>void Uie(D.name)},D.name)})]}),c&&d.jsx(BL,{name:c,onClose:()=>u(null)}),f&&d.jsx(zie,{onClose:()=>p(!1)}),m&&d.jsx(Bie,{onClose:()=>b(!1),onSubmit:(D,L)=>{C(D,L),b(!1)}})]})}function Hie({skill:e,projectCount:t,onOpen:n,onExport:i}){const s=Ye(),r=$ie[e.category];return d.jsxs("article",{className:"nb-card nb-card-interactive relative flex flex-col gap-3",children:[d.jsx("button",{type:"button",onClick:n,"aria-label":`Open ${e.name}`,className:"absolute inset-0 cursor-pointer rounded-[inherit] border-0 bg-transparent"}),d.jsxs("div",{className:"flex items-start justify-between gap-3",children:[d.jsx("h3",{className:"min-w-0 flex-1 overflow-hidden break-all font-[family-name:var(--font-heading)] text-lg font-bold leading-6 line-clamp-2",children:e.name}),d.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[d.jsx("button",{type:"button",className:"nb-btn relative z-10 p-1",onClick:i,"aria-label":s("skills.export"),title:s("skills.export"),children:d.jsx($A,{size:12,strokeWidth:2.5})}),d.jsx("span",{className:"nb-badge text-[10px]",style:{background:r},children:e.category})]})]}),d.jsx("p",{className:"text-sm text-[var(--color-text-muted)] leading-5 line-clamp-3",children:e.description||"(no description)"}),e.tags.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(o=>d.jsx("span",{className:"text-[10px] font-[family-name:var(--font-mono)] px-1.5 py-0.5 rounded-full bg-[var(--surface-control)] border border-[var(--control-border)]",children:o},o))}),d.jsxs("div",{className:"flex items-center justify-between text-xs font-[family-name:var(--font-mono)] pt-2 border-t-[1.5px] border-dashed border-[var(--color-border-light)] mt-auto",children:[d.jsx("span",{className:"font-bold",children:e.linkedProjects.length>0?`● linked in ${e.linkedProjects.length}`:"○ not linked"}),d.jsxs("span",{className:"text-[var(--color-text-subtle)]",children:[t," projects"]})]})]})}function Vie(e){return wt("/api/prompts")}function aI(e){return wt(`/api/prompts/${encodeURIComponent(e)}`)}function Kie(e){return jr("/api/prompts",e)}function Gie(e,t){return Pm(`/api/prompts/${encodeURIComponent(e)}`,t)}function Wie(e){return s1(`/api/prompts/${encodeURIComponent(e)}`)}function Yie(e){return jr("/api/prompts/generate",{intent:e})}function oI(e){const t=new Set,n=[];for(const i of e.matchAll(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g)){const s=i[1];s&&!t.has(s)&&(t.add(s),n.push(s))}return n}function Xie(){var M,R;const e=Ye(),[t,n]=oa("prompts.last",""),[i,s]=_.useState(null),[r,o]=_.useState(!1),[c,u]=_.useState(""),[f,p]=_.useState(new Set),m=Xt(),b=Je({queryKey:["prompts"],queryFn:()=>Vie()}),y=((M=b.data)==null?void 0:M.data)??[],x=_.useMemo(()=>[...new Set(y.flatMap(P=>P.tags))].sort(),[y]),w=(((R=Je({queryKey:["gen-jobs"],queryFn:rI,refetchInterval:3e3}).data)==null?void 0:R.data)??[]).filter(P=>P.kind==="prompt"),k=w.filter(P=>P.status!=="done"),C=_.useRef(new Set),S=_.useRef(null);_.useEffect(()=>{for(const P of w)(P.status==="done"||P.status==="error")&&!C.current.has(P.id)&&(C.current.add(P.id),m.invalidateQueries({queryKey:["prompts"]}),P.status==="done"&&P.result&&n(P.result))},[w,m,n]);const j=P=>{Yie(P).then(()=>m.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},T=_.useMemo(()=>{const P=c.trim().toLowerCase();return y.filter(I=>!(f.size&&![...f].every(B=>I.tags.includes(B))||P&&!(I.name.toLowerCase().includes(P)||I.description.toLowerCase().includes(P)||I.tags.some(F=>F.toLowerCase().includes(P)))))},[y,f,c]);_.useEffect(()=>{t&&y.length&&!y.some(P=>P.name===t)&&n("")},[t,y,n]);const A=P=>p(I=>{const B=new Set(I);return B.has(P)?B.delete(P):B.add(P),B});return d.jsxs("div",{className:"flex flex-col flex-1 min-h-0 w-full gap-3",children:[d.jsxs("div",{className:"shrink-0 flex items-center justify-between gap-3",children:[d.jsxs("div",{children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("prompts.title")}),d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.desc")})]}),d.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[d.jsxs("button",{className:"nb-btn",type:"button",onClick:()=>o(!0),children:[d.jsx(ao,{size:14,strokeWidth:2.5}),e("prompts.ai")]}),d.jsxs("button",{className:"nb-btn nb-btn-mint",type:"button",onClick:()=>s({mode:"new"}),children:[d.jsx(Bn,{size:14,strokeWidth:3}),e("prompts.new")]})]})]}),d.jsxs("div",{className:"shrink-0 flex flex-col gap-2",children:[d.jsxs("label",{className:"nb-input flex items-center gap-2 w-full",children:[d.jsx(hf,{size:14}),d.jsx("input",{type:"text",value:c,onChange:P=>u(P.target.value),placeholder:e("prompts.search"),className:"bg-transparent outline-none flex-1 text-sm","aria-label":e("prompts.search")})]}),x.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1.5",children:x.map(P=>d.jsx("button",{type:"button",onClick:()=>A(P),className:`nb-btn px-2 py-0.5 text-xs ${f.has(P)?"nb-btn-mint":""}`,children:P},P))})]}),d.jsxs("div",{className:"flex gap-5 flex-1 min-h-0",children:[d.jsx("aside",{className:"w-80 shrink-0 nb-card p-3 overflow-hidden flex h-full min-h-0 flex-col gap-2",children:d.jsxs("div",{ref:S,className:"edge-scroll-list flex-1 min-h-0 overflow-y-auto flex flex-col gap-0.5",children:[k.map(P=>d.jsxs("div",{className:`nb-card flex items-center gap-2 ${P.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,style:{padding:"8px 10px"},children:[P.status==="running"?d.jsx(pt,{size:12,className:"animate-spin"}):d.jsx(vn,{size:12,strokeWidth:3}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)] truncate",children:P.status==="running"?e("prompts.ai.wait"):`${e("prompts.ai.error")}: ${P.error??""}`})]},P.id)),b.isLoading?d.jsx("div",{className:"nb-card",children:d.jsx(pt,{size:14,className:"animate-spin"})}):T.length===0?d.jsx("div",{className:"nb-card",children:d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.empty")})}):T.map((P,I)=>d.jsx(ru,{index:I,root:S,children:d.jsxs("button",{type:"button",onClick:()=>n(P.name),className:["dimension-menu-item w-full min-w-0 flex-col items-stretch gap-1 px-3 py-2 pl-4 text-left",t===P.name?"dimension-menu-item-active":""].join(" "),children:[d.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[P.favorite&&d.jsx(QA,{size:12,fill:"currentColor",className:"shrink-0"}),d.jsx("code",{className:"min-w-0 max-w-full truncate font-[family-name:var(--font-mono)] text-sm font-bold",children:P.name})]}),P.description&&d.jsx("span",{className:"block w-full min-w-0 truncate text-xs text-[var(--color-text-muted)]",children:P.description})]})},P.name))]})}),d.jsx("div",{className:"flex-1 min-w-0 min-h-0",children:t?d.jsx(Zie,{name:t,onEdit:()=>s({mode:"edit",name:t}),onDeleted:()=>n("")},t):d.jsx("div",{className:"nb-card",children:d.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("prompts.selectHint")})})})]}),i&&d.jsx(ese,{name:i.mode==="edit"?i.name:null,onClose:()=>s(null),onSaved:P=>{s(null),n(P)}}),r&&d.jsx(Qie,{onClose:()=>o(!1),onSubmit:P=>{j(P),o(!1)}})]})}function Qie({onClose:e,onSubmit:t}){const n=Ye(),[i,s]=_.useState("");return d.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:d.jsx("div",{className:"w-full max-w-xl my-8",children:d.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[d.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[d.jsx(ao,{size:16,strokeWidth:2.5}),n("prompts.ai.title")]}),d.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:d.jsx(vn,{size:14,strokeWidth:3})})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:n("prompts.ai.intent")}),d.jsx("textarea",{value:i,onChange:r=>s(r.target.value),placeholder:n("prompts.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("prompts.ai.intent")})]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!i.trim(),onClick:()=>t(i),children:[d.jsx(ao,{size:14,strokeWidth:2.5}),n("prompts.ai.submit")]})]})})})}function Zie({name:e,onEdit:t,onDeleted:n}){const i=Ye(),s=Xt(),{confirm:r}=Un(),o=Je({queryKey:["prompt",e],queryFn:()=>aI(e)}),c=Dt({mutationFn:()=>Wie(e),onSuccess:()=>{s.invalidateQueries({queryKey:["prompts"]}),n()}});if(o.isLoading)return d.jsx("div",{className:"nb-card",children:d.jsx(pt,{size:14,className:"animate-spin"})});const u=o.data;if(!u)return null;const f=oI(u.body);return d.jsxs("div",{className:"nb-card flex flex-col gap-3 h-full min-h-0",children:[d.jsxs("div",{className:"flex items-start justify-between gap-3 shrink-0",children:[d.jsxs("div",{className:"min-w-0",children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold flex items-center gap-2",children:[u.favorite&&d.jsx(QA,{size:16,fill:"currentColor"}),d.jsx("code",{className:"font-[family-name:var(--font-mono)] truncate",children:u.name})]}),u.description&&d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:u.description})]}),d.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:t,children:[d.jsx(J0,{size:14,strokeWidth:3}),i("common.edit")]}),d.jsx("button",{type:"button",className:"nb-btn",disabled:c.isPending,onClick:async()=>{await r({title:i("prompts.delete"),body:i("prompts.deleteConfirm",{name:e})})&&c.mutate()},"aria-label":i("prompts.delete"),children:d.jsx(cs,{size:14,strokeWidth:3})})]})]}),u.tags.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1.5 shrink-0",children:u.tags.map(p=>d.jsx("span",{className:"nb-badge px-2 py-0.5 text-xs",children:p},p))}),d.jsx("pre",{className:"flex-1 bg-surface-input min-h-0 overflow-auto text-sm font-[family-name:var(--font-mono)] whitespace-pre-wrap break-words bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded p-3",children:u.body}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)] shrink-0",children:f.length?i("prompts.vars",{names:f.join(", ")}):i("prompts.noVars")})]})}function Jie({tags:e,onChange:t}){const n=Ye(),[i,s]=_.useState(""),r=()=>{const o=i.trim();o&&!e.includes(o)&&t([...e,o]),s("")};return d.jsxs("div",{className:"nb-input w-full flex flex-wrap gap-1.5 items-center",children:[e.map(o=>d.jsxs("span",{className:"inline-flex items-center gap-1 text-xs bg-[var(--color-accent-mint)] border-2 border-[var(--color-text)] rounded px-1.5 py-0.5",children:[o,d.jsx("button",{type:"button",onClick:()=>t(e.filter(c=>c!==o)),"aria-label":`remove ${o}`,children:d.jsx(vn,{size:10,strokeWidth:3})})]},o)),d.jsx("input",{className:"flex-1 min-w-[90px] bg-transparent outline-none text-sm",value:i,onChange:o=>s(o.target.value),onKeyDown:o=>{o.key==="Enter"?(o.preventDefault(),r()):o.key==="Backspace"&&!i&&e.length&&t(e.slice(0,-1))},placeholder:e.length?"":n("prompts.tagAdd"),"aria-label":n("prompts.tags")})]})}function ese({name:e,onClose:t,onSaved:n}){const i=Ye(),s=Xt(),{alert:r}=Un(),o=e===null,c=Je({queryKey:["prompt",e],queryFn:()=>aI(e),enabled:!o}),[u,f]=_.useState(o?{name:"",description:"",tags:[],body:"",favorite:!1}:null);_.useEffect(()=>{if(!o&&c.data&&u===null){const y=c.data;f({name:y.name,description:y.description,tags:y.tags,body:y.body,favorite:y.favorite})}},[o,c.data,u]);const p=Dt({mutationFn:()=>{if(!u)throw new Error("no form");const y={description:u.description||void 0,tags:u.tags,favorite:u.favorite,body:u.body};return o?Kie({name:u.name,...y}):Gie(e,y)},onSuccess:y=>{s.invalidateQueries({queryKey:["prompts"]}),s.invalidateQueries({queryKey:["prompt",y.name]}),n(y.name)},onError:y=>void r({title:i("prompts.saveError"),body:y instanceof Error?y.message:String(y)})}),m=_.useMemo(()=>u?/^[a-z0-9][a-z0-9-]*$/.test(u.name):!1,[u]),b=_.useMemo(()=>u?oI(u.body):[],[u]);return d.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:d.jsx("div",{className:"w-full max-w-2xl my-8",children:d.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[d.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold",children:o?i("prompts.new"):e}),d.jsx("button",{type:"button",className:"nb-btn p-2",onClick:t,"aria-label":"close",children:d.jsx(vn,{size:14,strokeWidth:3})})]}),!o&&c.isLoading?d.jsx(pt,{size:14,className:"animate-spin"}):u?d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:i("prompts.name")}),d.jsx("input",{type:"text",value:u.name,disabled:!o,onChange:y=>f({...u,name:y.target.value}),placeholder:i("prompts.namePlaceholder"),className:"nb-input w-full","aria-label":i("prompts.name")}),o&&u.name&&!m&&d.jsx("span",{className:"text-xs text-[var(--color-crashed)]",children:i("prompts.nameError")})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:i("prompts.description")}),d.jsx("input",{type:"text",value:u.description,onChange:y=>f({...u,description:y.target.value}),className:"nb-input w-full","aria-label":i("prompts.description")})]})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:i("prompts.tags")}),d.jsx(Jie,{tags:u.tags,onChange:y=>f({...u,tags:y})})]}),d.jsxs("label",{className:"flex flex-col gap-1",children:[d.jsx("span",{className:"text-sm font-bold",children:i("prompts.body")}),d.jsx("textarea",{value:u.body,onChange:y=>f({...u,body:y.target.value}),placeholder:i("prompts.bodyPlaceholder"),rows:12,className:"nb-input w-full font-[family-name:var(--font-mono)] text-sm","aria-label":i("prompts.body")}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:b.length?i("prompts.vars",{names:b.join(", ")}):i("prompts.noVars")})]}),d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:p.isPending||o&&!m||!u.body.trim(),onClick:()=>p.mutate(),children:[p.isPending?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3}),i("prompts.save")]}),d.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[d.jsx("input",{type:"checkbox",checked:u.favorite,onChange:y=>f({...u,favorite:y.target.checked})}),i("prompts.favorite")]})]})]}):null]})})})}function tse(){return wt("/api/processes").then(e=>e.data)}function nse(e){return jr(`/api/processes/${e}/kill`)}function ise(){return wt("/api/processes/reclaim")}async function sse(e){const t=await fetch("/api/processes/reclaim",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({idleMinutes:e})});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return t.json()}const rse="nb-card";function ase(e){if(!e)return"—";const t=Date.now()-new Date(e).getTime();if(!Number.isFinite(t)||t<0)return"—";const n=Math.floor(t/6e4);if(n<1)return"<1m";if(n<60)return`${n}m`;const i=Math.floor(n/60);return i<24?`${i}h${n%60?` ${n%60}m`:""}`:`${Math.floor(i/24)}d${i%24?` ${i%24}h`:""}`}function Lx(e){return e.project?e.project:e.cwd?e.cwd.split("/").filter(Boolean).pop()??e.slot:e.slot}function wj(e){const t=/^session-chat-(.+)$/.exec(e.slot);return(t==null?void 0:t[1])??null}function ose({p:e}){const t=e.alive?e.sessionState??"alive":"offline",n=e.alive?"bg-[var(--color-accent-mint)]":"bg-[var(--color-bg-cream)] text-[var(--color-text)]/60";return d.jsx("span",{className:`nb-status font-[family-name:var(--font-mono)] ${n}`,children:t})}function lse({embedded:e}={}){var v;const t=Ye(),n=Xt(),[i,s]=_.useState(null),[r,o]=_.useState("all"),c=Je({queryKey:["processes"],queryFn:tse,refetchInterval:5e3}),u=Dt({mutationFn:nse,onSuccess:w=>{s(w.message),n.invalidateQueries({queryKey:["processes"]})},onError:w=>s(w instanceof Error?w.message:String(w))}),f=Je({queryKey:["reclaim"],queryFn:ise}),[p,m]=_.useState("");_.useEffect(()=>{f.data&&p===""&&m(String(f.data.idleMinutes))},[f.data,p]);const b=Dt({mutationFn:w=>sse(w),onSuccess:w=>{s(`自动回收已设为 ${w.idleMinutes} 分钟空闲`),n.invalidateQueries({queryKey:["reclaim"]})},onError:w=>s(w instanceof Error?w.message:String(w))}),x=(c.data??[]).filter(w=>r==="all"?!0:w.kind===r);return d.jsxs("div",{className:"max-w-full flex-1 min-h-0 flex flex-col",children:[!e&&d.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl mb-2 shrink-0",children:t("processes.title")}),i&&d.jsx("div",{className:"nb-card mb-3 px-3 py-2 text-sm font-mono",children:i}),d.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[["all","worker","chat"].map(w=>d.jsx("button",{type:"button","aria-pressed":r===w,onClick:()=>o(w),className:`nb-btn px-3 py-1 text-sm ${r===w?"nb-btn-primary":""}`,children:t(`processes.kind.${w}`)},w)),d.jsxs("button",{type:"button","aria-label":t("processes.refresh"),onClick:()=>n.invalidateQueries({queryKey:["processes"]}),className:"nb-btn px-3 py-1 text-sm",children:[c.isFetching?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(ro,{size:14}),t("processes.refresh")]}),d.jsxs("div",{className:`${rse} px-3 py-1 flex items-center gap-2 shrink-0 ml-auto`,title:"自动回收:会话空闲 N 分钟自动停,下次访问 durable resume 续上,不丢上下文",children:[d.jsx(U6,{size:15,strokeWidth:2.5}),d.jsx("input",{type:"number",min:1,max:1440,value:p,onChange:w=>m(w.target.value),className:"nb-input w-14 px-2 py-1 font-[family-name:var(--font-mono)] text-sm","aria-label":"自动回收空闲分钟数"}),d.jsx("button",{type:"button",disabled:b.isPending||p===""||Number(p)===((v=f.data)==null?void 0:v.idleMinutes),onClick:()=>b.mutate(Math.round(Number(p))),className:"nb-btn nb-btn-primary text-sm disabled:opacity-50",style:{padding:"4px 8px"},"aria-label":"保存自动回收设置",title:"保存自动回收设置",children:b.isPending?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3})})]})]}),d.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] flex-1 min-h-0 overflow-hidden flex flex-col text-sm",children:[d.jsxs("div",{className:"shrink-0 grid grid-cols-[130px_minmax(140px,1.2fr)_minmax(140px,1.5fr)_80px_110px_90px_90px_100px] bg-[var(--surface-table-head)] font-[family-name:var(--font-heading)] border-b-2 border-[var(--color-text)]/15",children:[d.jsx("div",{className:"px-3 py-2",children:t("processes.col.kind")}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.slot")}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.project")}),d.jsx("div",{className:"px-3 py-2",children:"PID"}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.state")}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.memory")}),d.jsx("div",{className:"px-3 py-2",children:"运行时间"}),d.jsx("div",{className:"px-3 py-2",children:t("processes.col.action")})]}),d.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto font-[family-name:var(--font-mono)]",children:[x.length===0&&d.jsx("div",{className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:t("processes.empty")}),x.map(w=>d.jsxs("div",{className:"grid grid-cols-[130px_minmax(140px,1.2fr)_minmax(140px,1.5fr)_80px_110px_90px_90px_100px] border-t border-[var(--color-text)]/10 items-center",title:w.cwd??"",children:[d.jsxs("div",{className:"px-3 py-2 flex flex-col gap-0.5",children:[d.jsx("span",{className:`nb-badge text-xs whitespace-nowrap ${w.kind==="worker"?"bg-[var(--color-accent-yellow)]":"bg-[var(--color-accent-purple)]"}`,children:t(`processes.kind.${w.kind}`)}),d.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--color-text)]/45",children:w.tool})]}),d.jsx("div",{className:"px-3 py-2 truncate",children:w.slot}),d.jsx("div",{className:"px-3 py-2 truncate",children:w.kind==="chat"&&wj(w)?d.jsxs(zc,{to:`/chat/${wj(w)}`,className:"inline-flex items-center gap-1 font-semibold text-[var(--color-text)] underline decoration-2 underline-offset-2 hover:opacity-70",title:"打开对话窗口",children:[d.jsx(QU,{size:12,strokeWidth:2.5})," ",Lx(w)]}):w.kind==="worker"&&w.project?d.jsxs(zc,{to:`/board?project=${encodeURIComponent(w.project)}`,className:"inline-flex items-center gap-1 font-semibold text-[var(--color-text)] underline decoration-2 underline-offset-2 hover:opacity-70",title:"打开该项目看板",children:[d.jsx(gU,{size:12,strokeWidth:2.5})," ",Lx(w)]}):d.jsx("span",{children:Lx(w)})}),d.jsx("div",{className:"px-3 py-2",children:w.pid??"—"}),d.jsx("div",{className:"px-3 py-2",children:d.jsx(ose,{p:w})}),d.jsx("div",{className:"px-3 py-2",children:w.memoryMB!=null?`${w.memoryMB} MB`:"—"}),d.jsx("div",{className:"px-3 py-2",children:ase(w.startedAt)}),d.jsx("div",{className:"px-3 py-2",children:w.alive&&w.pid!=null?d.jsxs("button",{type:"button","aria-label":`${t("processes.kill")} ${w.slot}`,onClick:()=>{confirm(t("processes.killConfirm").replace("{slot}",w.slot))&&u.mutate(w.pid)},className:"nb-btn nb-btn-danger px-2.5 py-1 text-xs",children:[d.jsx(UA,{size:13})," ",t("processes.kill")]}):d.jsx("span",{className:"text-[var(--color-text)]/40 text-xs",children:"—"})})]},w.slot))]})]})]})}function cse(e={}){const t=new URLSearchParams;e.project&&t.set("project",e.project),e.action&&t.set("action",e.action);const n=t.toString();return wt(`/api/audit${n?`?${n}`:""}`).then(i=>i.data)}const use={create:"bg-[var(--color-accent-mint)]",modify:"bg-[var(--color-accent-yellow)]",delete:"bg-[var(--color-accent-pink)]",daemon:"bg-[var(--color-accent-purple)]"};function dse({embedded:e}={}){const t=Ye(),n=Xt(),[i,s]=_.useState(""),r=Je({queryKey:["audit",i],queryFn:()=>cse(i?{action:i}:{}),refetchInterval:8e3}),o=r.data??[],c=u=>t(`audit.action.${u}`);return d.jsxs("div",{className:"max-w-full flex-1 min-h-0 flex flex-col",children:[!e&&d.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl mb-2 shrink-0",children:t("audit.title")}),d.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap shrink-0",children:[["","create","modify","delete","daemon"].map(u=>d.jsx("button",{type:"button","aria-pressed":i===u,onClick:()=>s(u),className:`nb-btn px-3 py-1 text-sm ${i===u?"nb-btn-primary":""}`,children:u?c(u):t("audit.filter.all")},u||"all")),d.jsxs("button",{type:"button","aria-label":t("audit.refresh"),onClick:()=>n.invalidateQueries({queryKey:["audit"]}),className:"nb-btn px-3 py-1 text-sm ml-auto",children:[r.isFetching?d.jsx(pt,{size:14,className:"animate-spin"}):d.jsx(ro,{size:14}),t("audit.refresh")]})]}),d.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] flex-1 min-h-0 overflow-hidden flex flex-col text-sm",children:[d.jsxs("div",{className:"shrink-0 grid grid-cols-[180px_120px_minmax(100px,1fr)_minmax(160px,2fr)] bg-[var(--surface-table-head)] font-[family-name:var(--font-heading)] border-b-2 border-[var(--color-text)]/15",children:[d.jsx("div",{className:"px-3 py-2",children:t("audit.col.time")}),d.jsx("div",{className:"px-3 py-2",children:t("audit.col.action")}),d.jsx("div",{className:"px-3 py-2",children:t("audit.col.project")}),d.jsx("div",{className:"px-3 py-2",children:t("audit.col.detail")})]}),d.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto font-[family-name:var(--font-mono)]",children:[o.length===0&&d.jsx("div",{className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:t("audit.empty")}),o.map((u,f)=>d.jsxs("div",{className:"grid grid-cols-[180px_120px_minmax(100px,1fr)_minmax(160px,2fr)] border-t border-[var(--color-text)]/10 items-center",children:[d.jsx("div",{className:"px-3 py-2 whitespace-nowrap",children:new Date(u.ts).toLocaleString()}),d.jsx("div",{className:"px-3 py-2",children:d.jsx("span",{className:`nb-badge text-xs whitespace-nowrap ${use[u.action]}`,children:c(u.action)})}),d.jsx("div",{className:"px-3 py-2 truncate",title:u.project,children:u.project}),d.jsx("div",{className:"px-3 py-2 text-[var(--color-text)]/70 truncate",title:u.detail??"",children:u.detail??(u.source?`(${u.source})`:"—")})]},`${u.ts}-${f}`))]})]})]})}const lI=[{id:"git",fields:[{key:"GITLAB_URL",type:"text",placeholder:"https://gitlab.com"},{key:"GITLAB_TOKEN",type:"text"}]},{id:"matrix",fields:[{key:"MATRIX_HOMESERVER",type:"text",placeholder:"https://matrix.example.com"},{key:"MATRIX_ACCESS_TOKEN",type:"text"},{key:"MATRIX_ROOM_ID",type:"text",placeholder:"!room:example.com"}]},{id:"memory",fields:[{key:"SPS_MEMORY_MODE",type:"select",defaultValue:"local",options:["local","local+external","external","none"]},{key:"SPS_MEMORY_EXTERNAL_URL",type:"text",placeholder:"http://127.0.0.1:3111"},{key:"SPS_MEMORY_DISTILL",type:"select",options:["","on","off"]},{key:"SPS_MEMORY_IMPORT",type:"select",options:["","on","off"]},{key:"SPS_MEMORY_REDACT",type:"select",options:["","on","off"]}]},{id:"daemon",fields:[{key:"SPS_OPENAI_SANDBOX_PROVIDER",type:"select",options:["","unix_local","docker"]},{key:"SPS_DAEMON_MAX_CONCURRENT_RUNS",type:"number",placeholder:"按内存自动推导"},{key:"SPS_DAEMON_ORIGIN_QUOTAS",type:"text",placeholder:"coral-platform=30,gameforge=20"},{key:"SPS_DAEMON_QUEUE_WAIT_S",type:"number",defaultValue:"20"},{key:"SPS_DAEMON_MAX_QUEUE",type:"number",defaultValue:"200"},{key:"SPS_RUN_IDLE_MINUTES",type:"number",defaultValue:"5"},{key:"SPS_RUN_TOOL_IDLE_MINUTES",type:"number",defaultValue:"12"},{key:"SPS_STUCK_RUN_MINUTES",type:"number",defaultValue:"20"}]},{id:"console",fields:[{key:"SPS_CONSOLE_TOKEN",type:"text"},{key:"SPS_CONSOLE_MEMORY_VIEWER_URL",type:"text",placeholder:"https://memory.example.com"}]}],fse=lI.flatMap(e=>e.fields),Ej=new Set(fse.map(e=>e.key)),hse=[{value:"config",labelKey:"system.tab.config"},{value:"processes",labelKey:"system.tab.processes"},{value:"doctor",labelKey:"system.tab.doctor"},{value:"audit",labelKey:"system.tab.audit"}];function pse(){var s,r;const e=Ye(),t=Je({queryKey:["system-info"],queryFn:oM}),[n,i]=oa("system.tab","config");return d.jsxs("div",{className:"system-page-shell flex flex-col flex-1 min-h-0 w-full",children:[d.jsxs("header",{className:"system-page-header shrink-0 flex items-center justify-between gap-3 flex-wrap",children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("system.h1")}),d.jsx(mse,{platform:(s=t.data)==null?void 0:s.platform,current:(r=t.data)==null?void 0:r.version})]}),d.jsx(au,{ariaLabel:e("system.h1"),className:"max-w-full",value:n,onChange:i,options:hse.map(o=>({value:o.value,label:e(o.labelKey)}))}),d.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[n==="config"&&d.jsx(gse,{}),n==="processes"&&d.jsx(lse,{embedded:!0}),n==="doctor"&&d.jsx(bse,{}),n==="audit"&&d.jsx(dse,{embedded:!0})]})]})}function mse({platform:e,current:t}){const n=Ye(),{confirm:i,alert:s}=Un(),[r,o]=_.useState(!1),c=Je({queryKey:["latest-version"],queryFn:EF,enabled:!1}),u=async()=>{const p=(await c.refetch()).data;if(!p)return;if(p.upToDate){s({title:n("system.upgrade.checkUpdate"),body:n("system.upgrade.upToDate",{version:t??"?"})});return}if(await i({title:n("system.upgrade.confirm.title"),body:n("system.upgrade.confirm.body",{current:t??"?",latest:p.latest}),confirm:n("system.upgrade.confirm.button")})){o(!0);try{const b=await kF();s({title:b.ok?n("system.upgrade.success.title"):n("system.upgrade.notEffective.title"),body:b.ok?n("system.upgrade.success.body",{version:b.installedVersion??"?"}):b.output||""})}catch(b){s({title:n("system.upgrade.error.title"),body:b.message})}finally{o(!1)}}};return d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsxs("span",{className:"text-xs font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] whitespace-nowrap",children:[e??"—",t?` · v${t}`:""]}),d.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:u,disabled:r||c.isFetching||!t,type:"button","aria-label":n("system.upgrade.checkUpdate"),children:[r||c.isFetching?d.jsx(pt,{size:12,strokeWidth:3,className:"animate-spin"}):d.jsx(ro,{size:12,strokeWidth:2.5}),n("system.upgrade.checkUpdate")]})]})}function gse(){const e=Ye(),t=Xt(),{alert:n}=Un(),{data:i,isLoading:s,isError:r,error:o,dataUpdatedAt:c}=Je({queryKey:["system-env-raw"],queryFn:yF}),[u,f]=_.useState(null),[p,m]=_.useState(""),[b,y]=_.useState(""),x=i?`${i.etag}:${c}`:null;_.useEffect(()=>{if(!i||x===null)return;const P=u!==null&&u.content!==u.baseContent;(u===null||!P&&u.sourceKey!==x)&&(f({content:i.content,baseContent:i.content,etag:i.etag,sourceKey:x}),m(""),y(""))},[i,u,x]);const v=u,w=v!==null&&v.content!==v.baseContent,k=(v==null?void 0:v.content)??(i==null?void 0:i.content)??"",C=(v==null?void 0:v.etag)??(i==null?void 0:i.etag)??null,S=KL(k,Ej),j=p.trim().toUpperCase(),T=WL(j)&&!Ej.has(j)&&!S.some(P=>P.key===j),A=(P,I)=>{f(B=>{const F=B??Ix(i,x);return{...F,content:xm(F.content,P.key,I,P)}})},M=(P,I)=>{f(B=>{const F=B??Ix(i,x);return{...F,content:xm(F.content,P,I)}})},R=Dt({mutationFn:()=>{if(v===null)throw new Error("no draft");return bF(v.content,v.etag)},onSuccess:P=>{f(I=>I===null?I:{...I,baseContent:I.content,etag:P.etag,sourceKey:`${P.etag}:saved`}),t.invalidateQueries({queryKey:["system-env"]}),t.invalidateQueries({queryKey:["system-env-raw"]})},onError:P=>{const I=P.status;n({title:e(I===409?"system.env.error.conflict.title":"system.env.error.save.title"),body:I===409?e("system.env.error.conflict.body"):P instanceof Error?P.message:String(P)})}});return s?d.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("common.loading")}):r?d.jsx("div",{className:"bg-[var(--color-crashed-bg)] border-2 border-[var(--color-crashed)] rounded-lg p-3",children:d.jsx("p",{className:"text-sm",children:o instanceof Error?o.message:String(o)})}):d.jsxs("div",{className:"system-env-settings-editor",children:[d.jsxs("div",{className:"project-config-toolbar",children:[d.jsxs("div",{children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-base font-bold mb-1",children:e("system.tab.config")}),d.jsx("p",{className:"text-xs text-[var(--color-stuck)] font-bold",children:e("system.env.warning")}),C&&d.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] mt-1",children:["etag: ",C,w?e("system.env.dirtyMark"):""]})]}),d.jsx("div",{className:"flex gap-2",children:d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px"},onClick:()=>R.mutate(),disabled:!w||R.isPending,type:"button","aria-label":e("system.env.save.aria"),children:[R.isPending?d.jsx(pt,{size:12,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:12,strokeWidth:3}),e("system.env.save")]})})]}),d.jsxs("div",{className:"project-config-settings","aria-label":e("system.env.settingsAria"),children:[lI.map(P=>d.jsxs("section",{className:"project-config-section",children:[d.jsxs("div",{className:"project-config-section-head",children:[d.jsx("h3",{children:e(`system.env.section.${P.id}`)}),d.jsx("p",{children:e(`system.env.section.${P.id}.hint`)})]}),d.jsx("div",{className:"project-config-grid",children:P.fields.map(I=>d.jsx(yse,{field:I,value:VL(k,I),rawValue:Hd(k,I.key),onChange:B=>A(I,B)},I.key))})]},P.id)),d.jsxs("section",{className:"project-config-section",children:[d.jsxs("div",{className:"project-config-section-head",children:[d.jsx("h3",{children:e("system.env.section.custom")}),d.jsx("p",{children:e("system.env.section.custom.hint")})]}),d.jsxs("div",{className:"project-config-custom-list",children:[S.length===0?d.jsx("p",{className:"project-config-empty",children:e("system.env.custom.empty")}):S.map(P=>d.jsxs("div",{className:"project-config-custom-row",children:[d.jsx("code",{children:P.key}),d.jsx("input",{className:"nb-input",value:P.value,onChange:I=>M(P.key,I.target.value),"aria-label":e("system.env.custom.valueAria",{key:P.key})}),d.jsx("button",{type:"button",className:"nb-btn",onClick:()=>f(I=>{const B=I??Ix(i,x);return{...B,content:GL(B.content,P.key)}}),"aria-label":e("system.env.custom.removeAria",{key:P.key}),children:d.jsx(vn,{size:12,strokeWidth:3})})]},P.key)),d.jsxs("div",{className:"project-config-custom-row project-config-custom-add",children:[d.jsx("input",{className:"nb-input",value:p,onChange:P=>m(P.target.value),placeholder:e("system.env.custom.keyPlaceholder"),"aria-label":e("system.env.custom.keyAria")}),d.jsx("input",{className:"nb-input",value:b,onChange:P=>y(P.target.value),placeholder:e("system.env.custom.valuePlaceholder"),"aria-label":e("system.env.custom.newValueAria")}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:!T||!b,onClick:()=>{M(j,b),m(""),y("")},children:[d.jsx(Bn,{size:12,strokeWidth:3}),e("system.env.custom.add")]})]})]})]})]})]})}function Ix(e,t){const n=(e==null?void 0:e.content)??"",i=(e==null?void 0:e.etag)??"";return{content:n,baseContent:n,etag:i,sourceKey:t??`${i}:empty`}}function yse({field:e,value:t,rawValue:n,onChange:i}){const s=Ye(),r=s(`system.env.field.${e.key}`),o=s(`system.env.field.${e.key}.help`),c=e.type==="boolean",u=(n||e.defaultValue||"").toLowerCase()==="true";return d.jsxs("div",{className:["project-config-field",c?"project-config-field-toggle":""].join(" "),children:[d.jsxs("span",{className:"project-config-label",children:[d.jsx("span",{children:r}),d.jsx("code",{children:e.key})]}),c?d.jsxs("span",{className:"project-config-toggle-row",children:[d.jsx("input",{type:"checkbox",checked:u,onChange:f=>i(String(f.target.checked))}),d.jsx("span",{children:s(u?"common.yes":"common.no")})]}):e.type==="select"?d.jsx("select",{className:"nb-input",value:t,onChange:f=>i(f.target.value),"aria-label":r,children:(e.options??[]).map(f=>d.jsx("option",{value:f,children:f||s("projectDetail.config.option.empty")},f||"__empty"))}):d.jsx("input",{className:"nb-input",type:e.type==="number"?"number":"text",min:e.type==="number"?0:void 0,value:t,onChange:f=>i(f.target.value),placeholder:e.placeholder,"aria-label":r}),d.jsx("span",{className:"project-config-help",children:o})]})}function bse(){var b;const e=Ye(),{alert:t}=Un(),n=Je({queryKey:["projects"],queryFn:fo}),[i,s]=_.useState({}),[r,o]=_.useState({}),[c,u]=_.useState(null),f=(((b=n.data)==null?void 0:b.data)??[]).map(y=>({project:y.name})),p=async(y,x)=>{o(v=>({...v,[y]:x?"fix":"check"}));try{const v=await SF(y,x);s(w=>({...w,[y]:v})),u(y)}catch(v){t({title:e(x?"system.diagnostics.error.fix":"system.diagnostics.error.check"),body:v instanceof Error?v.message:String(v)})}finally{o(v=>({...v,[y]:null}))}},m=async()=>{for(const y of f)await p(y.project,!1)};return d.jsxs("section",{className:"nb-card system-panel system-panel-doctor flex-1 min-h-0",children:[d.jsxs("div",{className:"system-panel-titlebar",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:e("system.diagnostics.title")}),d.jsxs("button",{className:"nb-btn nb-btn-mint",style:{padding:"6px 12px",fontSize:12},onClick:()=>{m()},disabled:f.length===0||Object.values(r).some(Boolean),type:"button",children:[d.jsx(ro,{size:12,strokeWidth:2.5}),e("system.diagnostics.checkAll")]})]}),d.jsx("div",{className:"system-panel-body",children:f.length===0?d.jsx("p",{className:"text-[var(--color-text-muted)] text-sm",children:e("system.diagnostics.empty")}):d.jsx("ul",{className:"system-diagnostics-list",children:f.map(y=>{const x=i[y.project],v=r[y.project],w=x?x.checks.filter(j=>j.status==="fail").length:0,k=x?x.checks.filter(j=>j.status==="warn").length:0,C=c===y.project,S=x!=null;return d.jsxs("li",{className:["system-diagnostics-item",C?"system-diagnostics-item-expanded":""].join(" "),children:[d.jsxs("div",{className:"system-diagnostics-row",children:[d.jsxs("button",{type:"button",onClick:()=>u(C?null:y.project),disabled:!S,className:"system-diagnostics-summary","aria-label":e(C?"system.diagnostics.collapseAria":"system.diagnostics.expandAria"),"aria-expanded":S?C:void 0,children:[d.jsxs("span",{className:"system-diagnostics-project-main",children:[S&&x.ok?d.jsx(gv,{size:16,className:"text-[var(--color-running)] shrink-0",strokeWidth:2.5}):S?d.jsx(Od,{size:16,className:"text-[var(--color-stuck)] shrink-0",strokeWidth:2.5}):d.jsx(gv,{size:16,className:"text-[var(--color-text-subtle)] shrink-0",strokeWidth:2.5}),S&&(C?d.jsx(uo,{size:12}):d.jsx(ff,{size:12})),d.jsx("span",{className:"system-diagnostics-project-name",children:y.project})]}),S?x.ok?d.jsx("span",{className:"system-diagnostics-status system-diagnostics-status-ok",children:"OK"}):d.jsxs("span",{className:"system-diagnostics-status system-diagnostics-status-warn",children:[w," fail · ",k," warn"]}):d.jsx("span",{className:"system-diagnostics-never",children:e("system.diagnostics.never")})]}),d.jsxs("div",{className:"system-diagnostics-actions",children:[d.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>{p(y.project,!1)},disabled:!!v,type:"button","aria-label":e("system.diagnostics.checkAria"),children:[v==="check"?d.jsx(pt,{size:11,strokeWidth:3,className:"animate-spin"}):d.jsx(ro,{size:11,strokeWidth:2.5}),e("system.diagnostics.check")]}),d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>{p(y.project,!0)},disabled:!!v||S&&x.ok,type:"button","aria-label":e("system.diagnostics.fixAria"),title:S&&x.ok?e("system.diagnostics.noFixesNeeded"):e("system.diagnostics.fix.tip"),children:[v==="fix"?d.jsx(pt,{size:11,strokeWidth:3,className:"animate-spin"}):d.jsx(JA,{size:11,strokeWidth:2.5}),e("system.diagnostics.fix")]})]})]}),C&&S&&d.jsxs("div",{className:"system-diagnostics-detail",children:[d.jsx("ul",{className:"system-diagnostics-checks",children:x.checks.map((j,T)=>d.jsx(xse,{check:j},`${j.name}-${T}`))}),x.fixes.length>0&&d.jsxs("div",{className:"mt-3 bg-[var(--color-running-bg)] border-2 border-[var(--color-running)] rounded p-2",children:[d.jsx("div",{className:"text-xs font-bold text-[var(--color-running)] mb-1",children:e("system.diagnostics.fixed")}),d.jsx("ul",{className:"text-xs list-disc pl-4",children:x.fixes.map((j,T)=>d.jsx("li",{children:j},T))})]})]})]},y.project)})})})]})}function xse({check:e}){const t=e.status==="pass"?d.jsx(gv,{size:12,className:"text-[var(--color-running)]",strokeWidth:2.5}):e.status==="fail"?d.jsx(Od,{size:12,className:"text-[var(--color-crashed)]",strokeWidth:2.5}):e.status==="warn"?d.jsx(Od,{size:12,className:"text-[var(--color-stuck)]",strokeWidth:2.5}):d.jsx("span",{className:"system-diagnostics-info-dot"});return d.jsxs("li",{className:"system-diagnostics-check-row",children:[d.jsx("span",{className:"system-diagnostics-check-icon",children:t}),d.jsx("span",{className:"system-diagnostics-check-name",children:e.name}),d.jsx("span",{className:"system-diagnostics-check-message",children:e.message})]})}function Ec({value:e,onChange:t,options:n,ariaLabel:i,disabled:s,className:r="",placeholder:o="选择…",align:c="left"}){var k;const[u,f]=_.useState(!1),p=_.useRef(null),m=_.useRef(null),b=_.useRef(null),[y,x]=_.useState(null),v=()=>{var S;const C=(S=p.current)==null?void 0:S.getBoundingClientRect();C&&x({top:C.bottom+6,left:C.left,right:window.innerWidth-C.right,width:C.width})};_.useLayoutEffect(()=>{u&&v()},[u]),_.useEffect(()=>{if(!u)return;const C=()=>v(),S=j=>{var T,A;(T=p.current)!=null&&T.contains(j.target)||(A=m.current)!=null&&A.contains(j.target)||f(!1)};return window.addEventListener("scroll",C,!0),window.addEventListener("resize",C),document.addEventListener("mousedown",S),()=>{window.removeEventListener("scroll",C,!0),window.removeEventListener("resize",C),document.removeEventListener("mousedown",S)}},[u]);const w=((k=n.find(C=>C.value===e))==null?void 0:k.label)??o;return d.jsxs("div",{className:`relative ${r}`,children:[d.jsxs("button",{ref:p,type:"button",disabled:s,"aria-label":i,"aria-expanded":u,className:"nb-btn w-full justify-between text-sm disabled:opacity-50",onClick:()=>f(C=>!C),children:[d.jsx("span",{className:"truncate",children:w}),d.jsx(uo,{size:14,strokeWidth:2.5,className:["shrink-0 transition-transform",u?"rotate-180":""].join(" ")})]}),u&&y&&IA.createPortal(d.jsx("div",{ref:m,style:{position:"fixed",top:y.top,left:c==="right"?void 0:y.left,right:c==="right"?y.right:void 0,minWidth:y.width},className:"z-[100] nb-card p-1 overflow-hidden bg-[var(--surface-menu)]",children:d.jsx("div",{ref:b,className:"max-h-[60vh] overflow-y-auto",children:n.map((C,S)=>d.jsx(ru,{index:S,root:b,delay:.02,children:d.jsx("button",{type:"button",onClick:()=>{t(C.value),f(!1)},className:["dimension-menu-item w-full text-left px-4 py-2 text-sm font-semibold flex items-center gap-2 whitespace-nowrap",C.value===e?"dimension-menu-item-active":""].join(" "),children:C.label})},C.value))})}),document.body)]})}const vse=["convention","decision","gotcha","pattern","reference","note"],wse=["local","local+external","external","none"];function ww(e){return e!=null&&typeof e=="object"?e:{}}function kc(e){return Array.isArray(e)?e:[]}function Ese(e){switch(e){case"none":return"none";case"agentmemory":case"custom":return"external";case"builtin":default:return"local"}}function kj(e){const t=ww(e);return{mode:typeof t.mode=="string"&&t.mode?t.mode:Ese(t.provider),externalUrl:typeof t.externalUrl=="string"?t.externalUrl:typeof t.url=="string"?t.url:"",modeOptions:kc(t.modeOptions).length>0?kc(t.modeOptions):wse}}function kse(e){const t=ww(e),n=t.scope==="global"||t.scope==="project"||t.scope==="agent"?t.scope:null;return n?{scope:n,project:typeof t.project=="string"?t.project:void 0,agentId:typeof t.agentId=="string"?t.agentId:void 0,count:typeof t.count=="number"?t.count:0,updated:typeof t.updated=="string"?t.updated:""}:null}function Sse(e){const t=ww(e);if(typeof t.id!="string")return null;const n=t.scope==="global"||t.scope==="project"||t.scope==="agent"?t.scope:"global";return{id:t.id,title:typeof t.title=="string"?t.title:t.id,scope:n,category:typeof t.category=="string"?t.category:"note",tags:kc(t.tags),salience:typeof t.salience=="number"?t.salience:3,source:typeof t.source=="string"?t.source:"human",project:typeof t.project=="string"?t.project:void 0,agentId:typeof t.agentId=="string"?t.agentId:void 0,created:typeof t.created=="string"?t.created:"",updated:typeof t.updated=="string"?t.updated:"",body:typeof t.body=="string"?t.body:""}}function Po(e){return`${e.scope}:${e.project??e.agentId??""}`}function fp(e){return e.scope==="global"?`全局 (${e.count})`:e.scope==="project"?`项目:${e.project} (${e.count})`:`会话:${e.agentId} (${e.count})`}function zo(e){const t={scope:e.scope};return e.project&&(t.project=e.project),e.agentId&&(t.agentId=e.agentId),t}async function hr(e,t){const n=await fetch(e,t);if(!n.ok){const i=await n.json().catch(()=>null);throw new Error((i==null?void 0:i.detail)||(i==null?void 0:i.title)||`HTTP ${n.status}`)}return await n.json()}const Nse=()=>({title:"",body:"",category:"note",tags:"",salience:3});function _se(){var le,pe,Te;const e=Ye(),[t,n]=_.useState([]),[i,s]=_.useState(null),[r,o]=_.useState(!1),[c,u]=_.useState([]),[f,p]=_.useState(null),[m,b]=_.useState(!1),[y,x]=_.useState(""),[v,w]=_.useState(!0),[k,C]=_.useState([]),[S,j]=_.useState(null),[T,A]=_.useState(null),[M,R]=_.useState(null),[P,I]=_.useState(null),[B,F]=_.useState(""),[V,D]=_.useState(""),L=_.useCallback(async()=>{try{const{scopes:ne}=await hr("/api/memory/scopes"),oe=kc(ne).map(kse).filter(xe=>xe!=null);n(oe),s(xe=>xe??oe[0]??null)}catch(ne){p(ne instanceof Error?ne.message:String(ne))}},[]),z=_.useCallback(async ne=>{try{const oe=new URLSearchParams(zo(ne)).toString(),{data:xe}=await hr(`/api/memory/entries?${oe}`);u(kc(xe).map(Sse).filter(fe=>fe!=null))}catch(oe){p(oe instanceof Error?oe.message:String(oe))}},[]);_.useEffect(()=>{L(),hr("/api/system/memory").then(ne=>{const oe=kj(ne);I(oe),F(oe.mode),D(oe.externalUrl)}).catch(()=>{})},[L]),_.useEffect(()=>{i&&z(i),(i==null?void 0:i.scope)==="project"&&i.project?hr(`/api/memory/external?project=${encodeURIComponent(i.project)}`).then(ne=>R(ne)).catch(()=>R(null)):R(null)},[i,z]);const W=_.useCallback(async()=>{if(!y.trim()){C([]);return}b(!0),p(null);try{const ne=new URLSearchParams({q:y,limit:"20"});if(v)ne.set("all","1");else if(i)for(const[xe,fe]of Object.entries(zo(i)))ne.set(xe,fe);const{results:oe}=await hr(`/api/memory/recall?${ne.toString()}`);C(kc(oe))}catch(ne){p(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}},[y,v,i]),X=_.useCallback(async()=>{if(!(!i||!S)){b(!0),p(null);try{await hr("/api/memory/entries",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...zo(i),id:S.id,title:S.title,body:S.body,category:S.category,tags:S.tags.split(",").map(ne=>ne.trim()).filter(Boolean),salience:S.salience})}),j(null),await Promise.all([z(i),L()])}catch(ne){p(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}}},[i,S,z,L]),G=_.useCallback(async ne=>{if(i){b(!0),p(null);try{const oe=new URLSearchParams(zo(i)).toString();await hr(`/api/memory/entries/${encodeURIComponent(ne)}?${oe}`,{method:"DELETE"}),await Promise.all([z(i),L()])}catch(oe){p(oe instanceof Error?oe.message:String(oe))}finally{b(!1)}}},[i,z,L]),U=_.useCallback(async(ne,oe,xe)=>{if(i){b(!0),p(null);try{await hr("/api/memory/promote",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({from:zo(i),id:ne.id,to:zo(oe),move:xe})}),A(null),await Promise.all([z(i),L()])}catch(fe){p(fe instanceof Error?fe.message:String(fe))}finally{b(!1)}}},[i,z,L]),q=_.useCallback(async()=>{if(i){b(!0),p(null);try{const oe=(await hr("/api/memory/gc",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(zo(i))})).results[0];oe&&p(`收敛完成:清 tombstone ${oe.purged}、去重 ${oe.deduped}、剩余 ${oe.kept}`),await Promise.all([z(i),L()])}catch(ne){p(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}}},[i,z,L]),Y=_.useCallback(async()=>{b(!0),p(null);try{const ne=kj(await hr("/api/system/memory",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({mode:B,externalUrl:V})}));I(ne),F(ne.mode),D(ne.externalUrl),p("模式已保存(重启 worker 生效)")}catch(ne){p(ne instanceof Error?ne.message:String(ne))}finally{b(!1)}},[B,V]),$=P!=null&&(B!==P.mode||V!==P.externalUrl),ie=B==="external"||B==="local+external",be=_.useMemo(()=>T?t.filter(ne=>Po(ne)!==Po(i??{scope:""})):[],[T,t,i]),ce=Array.isArray((le=M==null?void 0:M.profile)==null?void 0:le.topConcepts)?M.profile.topConcepts:[],_e=Array.isArray((pe=M==null?void 0:M.graph)==null?void 0:pe.edges)?M.graph.edges.length:0;return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl text-[var(--color-text)]",children:e("nav.memory")}),d.jsx("span",{className:"text-xs text-[var(--color-text)] opacity-60",children:"本地记忆 v2 · markdown 真源"})]}),P&&d.jsxs("section",{className:"nb-card flex flex-wrap items-end gap-3",children:[d.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[d.jsx("span",{className:"font-bold",children:"记忆模式"}),d.jsx(Ec,{value:B,onChange:F,ariaLabel:"记忆模式",options:P.modeOptions.map(ne=>({value:ne,label:ne}))})]}),ie&&d.jsxs("label",{className:"flex flex-col gap-1 text-sm flex-1 min-w-[220px]",children:[d.jsx("span",{className:"font-bold",children:"外部后端地址"}),d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",value:V,onChange:ne=>D(ne.target.value),placeholder:"http://127.0.0.1:3113",spellCheck:!1,"aria-label":"外部后端地址"})]}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:Y,disabled:m||!$,"aria-label":"保存模式",children:"保存模式"})]}),(()=>{const ne=new Date(Date.now()-6048e5).toISOString(),oe=i?Po(i):"",xe=r?t:t.filter(te=>te.scope!=="project"||te.updated>=ne||Po(te)===oe),fe=t.length-xe.length;return d.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[d.jsx("input",{value:y,onChange:te=>x(te.target.value),onKeyDown:te=>te.key==="Enter"&&W(),placeholder:"检索记忆…","aria-label":"检索记忆",className:"nb-input flex-1 min-w-[200px] font-[family-name:var(--font-mono)] text-sm"}),d.jsxs("label",{className:"flex items-center gap-1 text-sm font-semibold",children:[d.jsx("input",{type:"checkbox",checked:v,onChange:te=>w(te.target.checked),"aria-label":"全局检索"}),"全局"]}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:W,disabled:m,"aria-label":"检索",children:m?"…":"检索"}),d.jsx(Ec,{className:"min-w-[180px]",value:oe,onChange:te=>s(t.find(we=>Po(we)===te)??null),ariaLabel:"选择作用域",placeholder:"选择作用域",options:xe.map(te=>({value:Po(te),label:fp(te)}))}),(fe>0||r)&&d.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>o(te=>!te),"aria-label":r?"收起更早项目":"显示更早项目",children:r?"收起更早":`含更早 (${fe})`}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>j(Nse()),disabled:!i,"aria-label":"新建记忆",children:"+ 新建"}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-yellow",onClick:q,disabled:m||!i,"aria-label":"收敛去重",children:"收敛"})]})})(),f&&d.jsxs("div",{className:"text-sm text-[var(--color-text)] font-semibold nb-card py-2",children:["ℹ ",f]}),k.length>0&&d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:["检索结果(",k.length,")"]}),k.map(ne=>d.jsxs("div",{className:"nb-card",children:[d.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)]",children:[d.jsx("span",{className:"nb-badge",children:ne.source==="external"?"🌐 外部":"📁 本地"}),d.jsx("span",{children:ne.source==="external"?ne.type??"":ne.scope==="project"?`项目:${ne.project}`:ne.scope}),ne.category&&d.jsxs(d.Fragment,{children:[d.jsx("span",{children:"·"}),d.jsx("span",{children:ne.category})]})]}),d.jsx("div",{className:"font-bold text-sm mt-1",children:ne.title}),d.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:ne.snippet.slice(0,300)})]},ne.id))]}),M&&(ce.length||_e)?d.jsxs("section",{className:"nb-card flex flex-col gap-1",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:"🌐 外部智能(agentmemory)"}),ce.length?d.jsxs("div",{className:"text-xs",children:[d.jsx("span",{className:"font-bold",children:"概念:"}),ce.slice(0,8).map(ne=>d.jsx("span",{className:"nb-badge ml-1",children:ne.concept},ne.concept))]}):null,d.jsxs("div",{className:"text-xs opacity-70 font-[family-name:var(--font-mono)]",children:["知识图谱 ",_e," 条边 · 观测 ",((Te=M.profile)==null?void 0:Te.totalObservations)??0]})]}):null,S&&d.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-40 flex items-center justify-center p-6 bg-black/30 overflow-hidden",onMouseDown:ne=>{ne.target===ne.currentTarget&&j(null)},children:d.jsxs("div",{className:"nb-card w-full max-w-2xl flex flex-col gap-2",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:S.id?"编辑记忆":"新建记忆"}),d.jsx("input",{className:"nb-input text-sm",value:S.title,onChange:ne=>j({...S,title:ne.target.value}),placeholder:"标题","aria-label":"标题"}),d.jsxs("div",{className:"flex gap-2 flex-wrap items-end",children:[d.jsx(Ec,{className:"min-w-[140px]",value:S.category,onChange:ne=>j({...S,category:ne}),ariaLabel:"类别",options:vse.map(ne=>({value:ne,label:ne}))}),d.jsx("input",{className:"nb-input flex-1 min-w-[160px] text-sm",value:S.tags,onChange:ne=>j({...S,tags:ne.target.value}),placeholder:"标签(逗号分隔)","aria-label":"标签"}),d.jsxs("label",{className:"flex items-center gap-1 text-sm",children:["显著度",d.jsx("input",{className:"nb-input w-16",type:"number",min:1,max:5,value:S.salience,onChange:ne=>j({...S,salience:Number(ne.target.value)}),"aria-label":"显著度"})]})]}),d.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm min-h-[120px]",value:S.body,onChange:ne=>j({...S,body:ne.target.value}),placeholder:"正文","aria-label":"正文"}),d.jsxs("div",{className:"flex gap-2",children:[d.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:X,disabled:m||!S.title.trim()||!S.body.trim(),"aria-label":"保存",children:"保存"}),d.jsx("button",{type:"button",className:"nb-btn",onClick:()=>j(null),"aria-label":"取消",children:"取消"})]})]})}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:i?fp(i):"条目"}),c.length===0&&d.jsx("div",{className:"nb-card text-sm opacity-60",children:"(无记忆)"}),c.map(ne=>d.jsxs("div",{className:"nb-card",children:[d.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)] flex-wrap",children:[d.jsx("span",{className:"nb-badge",children:ne.category}),d.jsxs("span",{children:["s",ne.salience]}),d.jsx("span",{children:"·"}),d.jsx("span",{children:ne.source}),ne.tags.map(oe=>d.jsxs("span",{children:["#",oe]},oe))]}),d.jsx("div",{className:"font-bold text-sm mt-1",children:ne.title}),d.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:ne.body.slice(0,400)}),d.jsxs("div",{className:"flex gap-2 mt-2",children:[d.jsx("button",{type:"button",className:"nb-btn nb-btn-blue text-xs",onClick:()=>j({id:ne.id,title:ne.title,body:ne.body,category:ne.category,tags:ne.tags.join(", "),salience:ne.salience}),"aria-label":"编辑",children:"编辑"}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-purple text-xs",onClick:()=>A(ne),"aria-label":"提升",children:"提升"}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-danger text-xs",onClick:()=>G(ne.id),"aria-label":"删除",children:"删除"})]}),(T==null?void 0:T.id)===ne.id&&d.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 border-t-[3px] border-[var(--color-text)] pt-2",children:[d.jsx("span",{className:"text-xs font-bold",children:"提升到:"}),be.map(oe=>d.jsx("button",{type:"button",className:"nb-btn nb-btn-mint text-xs",onClick:()=>U(ne,oe,!1),"aria-label":`复制到${fp(oe)}`,children:fp(oe)},Po(oe))),be.length===0&&d.jsx("span",{className:"text-xs opacity-60",children:"(无其它作用域)"}),d.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>A(null),"aria-label":"取消提升",children:"取消"})]})]},ne.id))]})]})}async function Cse(){return(await wt("/api/plugins")).data??[]}async function jse(e,t){return jr("/api/plugins",{spec:e})}async function Tse(e,t){return gF(`/api/plugins/${encodeURIComponent(e)}`,{disabled:t})}async function Ase(e){return mF(`/api/plugins/${encodeURIComponent(e)}`)}function Px(e){if(e instanceof rM&&e.detail&&typeof e.detail=="object"){const t=e.detail;if(t.error)return{error:t.error,kind:t.kind??"unknown",detail:t.detail}}return{error:e instanceof Error?e.message:String(e),kind:"unknown"}}const Sj={network:"装不上是网络问题 —— 检查代理或 registry 后重试。",auth:"registry 要凭据 —— 配好 npm 认证再试。","not-found":"这个名字或版本在 registry 上不存在。","not-plugin":"它装上了,但不是 Cordis 插件(没有 apply 导出)。装配档没有被改。",apply:"插件自己的代码抛了 —— 这是插件作者的问题。",conflict:"和已有的插件撞了(同名 id,或它提供的服务已经被别人占了)。"};function Nj({fail:e,title:t}){const[n,i]=_.useState(!1);return d.jsx("div",{className:"nb-card !border-[var(--color-danger)] text-sm",children:d.jsxs("div",{className:"flex items-start gap-2",children:[d.jsx(q6,{size:16,className:"mt-0.5 shrink-0 text-[var(--color-danger)]"}),d.jsxs("div",{className:"min-w-0 flex-1",children:[d.jsxs("p",{className:"font-medium",children:[t,":",e.error]}),d.jsxs("p",{className:"mt-1 text-[var(--color-text-muted)]",children:[d.jsx("code",{className:"text-xs",children:e.kind}),Sj[e.kind]?` · ${Sj[e.kind]}`:""]}),e.detail?d.jsxs(d.Fragment,{children:[d.jsx("button",{type:"button",className:"mt-2 text-xs underline text-[var(--color-text-muted)]",onClick:()=>i(s=>!s),children:n?"收起原文":"展开原文"}),n?d.jsx("pre",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap rounded bg-black/20 p-2 text-xs",children:e.detail}):null]}):null]})]})})}function Mse({panelFor:e}){const t=Xt(),[n,i]=_.useState(""),[s,r]=_.useState(null),[o,c]=_.useState(null),[u,f]=_.useState(null),{data:p=[],isLoading:m}=Je({queryKey:["plugins"],queryFn:Cse}),b=u?p.find(C=>C.key===u)??null:null,y=C=>{r(null),c(C??null),t.invalidateQueries({queryKey:["plugins"]})},x=Dt({mutationFn:()=>jse(n.trim()),onSuccess:C=>{i(""),y(C.warning)},onError:C=>r({title:"安装失败",fail:Px(C)})}),v=Dt({mutationFn:({key:C,disabled:S})=>Tse(C,S),onSuccess:C=>y(C.warning),onError:C=>r({title:"启停失败",fail:Px(C)})}),w=Dt({mutationFn:C=>Ase(C),onSuccess:C=>y(C.warning),onError:C=>r({title:"卸载失败",fail:Px(C)})}),k=x.isPending||v.isPending||w.isPending;return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"nb-card",children:[d.jsx("label",{htmlFor:"plugin-spec",className:"text-sm font-medium",children:"装一个插件"}),d.jsxs("p",{className:"mt-1 text-xs text-[var(--color-text-muted)]",children:["填 npm 包名(可带 ",d.jsx("code",{children:"@版本"}),")或本地路径。装完**当场生效**,不用重启。"]}),d.jsxs("div",{className:"mt-3 flex gap-2",children:[d.jsx("input",{id:"plugin-spec",value:n,onChange:C=>i(C.target.value),placeholder:"@scope/coral-plugin-xxx",className:"nb-input flex-1 text-sm",disabled:k}),d.jsxs("button",{type:"button",onClick:()=>x.mutate(),disabled:k||!n.trim(),className:"nb-btn nb-btn-primary",children:[x.isPending?d.jsx(pt,{size:16,className:"animate-spin"}):d.jsx(Bn,{size:16}),"安装"]})]})]}),s?d.jsx(Nj,{fail:s.fail,title:s.title}):null,o?d.jsx(Nj,{fail:o,title:"操作完成,但有一件事没做成"}):null,m?d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"读取中…"}):d.jsx("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:p.map(C=>d.jsx(Rse,{row:C,busy:k,configurable:!!(e!=null&&e(C)),onConfig:()=>f(C.key),onToggle:()=>v.mutate({key:C.key,disabled:!C.disabled}),onRemove:()=>w.mutate(C.key)},C.key))}),b&&(e!=null&&e(b))?d.jsx(Ew,{onClose:()=>f(null),children:d.jsxs("div",{className:"flex max-h-[88vh] w-fit max-w-[min(1040px,94vw)] flex-col gap-2 overflow-y-auto",children:[d.jsx("div",{className:"flex justify-end",children:d.jsx("button",{type:"button",onClick:()=>f(null),"aria-label":"关闭配置",title:"关闭",className:"nb-btn !px-2 !py-1",children:d.jsx(vn,{size:14,strokeWidth:2.5})})}),e(b)]})}):null]})}function Rse({row:e,busy:t,configurable:n,onConfig:i,onToggle:s,onRemove:r}){const o=e.disabled?{text:"已停用",cls:"bg-[var(--color-text-muted)]/15 text-[var(--color-text-muted)]"}:e.mounted?{text:"运行中",cls:"bg-[var(--color-success)]/20 text-[var(--color-success)]"}:{text:"未挂上",cls:"bg-[var(--color-danger)]/20 text-[var(--color-danger)]"};return d.jsxs("article",{className:`nb-card relative flex flex-col gap-3 ${n?"nb-card-interactive":""}`,children:[n?d.jsx("button",{type:"button",onClick:i,"aria-label":`配置 ${e.key}`,className:"absolute inset-0 cursor-pointer rounded-[inherit] border-0 bg-transparent"}):null,d.jsxs("div",{className:"flex items-start justify-between gap-2",children:[d.jsx("h3",{className:"min-w-0 flex-1 overflow-hidden break-all font-[family-name:var(--font-heading)] text-base font-bold",children:e.key}),d.jsx("span",{className:`nb-badge shrink-0 text-[10px] ${o.cls}`,title:e.disabled?"人主动停用的":e.mounted?"这个进程里正挂着":"装配档里有它,但没挂起来 —— 多半是它启动时抛了",children:o.text})]}),d.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.category?d.jsx("span",{className:"nb-badge text-[10px]",children:e.category}):null,d.jsx("span",{className:"nb-badge text-[10px] opacity-70",children:e.layer==="factory"?"内建":"已装"})]}),d.jsx("p",{className:"line-clamp-3 text-sm leading-5 text-[var(--color-text-muted)]",children:e.description||"(无简介)"}),d.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-[var(--color-border-light)] pt-2",children:[d.jsxs("span",{className:"min-w-0 flex-1 truncate font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",title:e.pkg??e.name,children:[e.pkg??e.name,e.version?` · ${e.version}`:""]}),d.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n?d.jsx(T6,{size:13,strokeWidth:2.5,"aria-hidden":!0,className:"text-[var(--color-text-subtle)]"}):null,d.jsx("button",{type:"button",className:"nb-btn relative z-10 !px-2 !py-1",onClick:s,disabled:t,"aria-label":e.disabled?`启用 ${e.key}`:`停用 ${e.key}`,title:e.disabled?"启用":"停用",children:d.jsx(p6,{size:13,strokeWidth:2.5})}),d.jsx("button",{type:"button",className:"nb-btn relative z-10 !px-2 !py-1",onClick:r,disabled:t||e.layer==="factory","aria-label":`卸载 ${e.key}`,title:e.layer==="factory"?"内建插件不能卸载,只能停用":"卸载",children:d.jsx(cs,{size:13,strokeWidth:2.5})})]})]})]})}async function Dse(){return(await wt("/api/channels")).data??{console:{},adapters:[]}}async function Ose(e){return(await Pm("/api/channels",e)).data}function Lse(e){return wt(`/api/media-providers?capability=${encodeURIComponent(e)}`)}async function Ise(e){const t=await fetch("/api/media-providers",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return t.json()}function Pse(e){return s1(`/api/media-providers/${encodeURIComponent(e)}`)}async function zse(e,t){const n=await fetch(`/api/media-providers/default/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`${n.status}: ${await n.text()}`);return n.json()}const v0={image:"图片",video:"视频",music:"音乐",voice:"语音","3d":"3D",embedding:"向量(Embedding)",rerank:"重排(Rerank)"},Bse={image:["codex","openai","volcengine","minimax","tripo","agnes","bailian","openrouter"],video:["volcengine"],music:["minimax"],voice:["doubao"],"3d":["tripo"],embedding:["openai-compatible"],rerank:["openai-compatible"]},cI={codex:"",openai:"https://api.openai.com/v1",tripo:"https://openapi.tripo3d.ai",volcengine:"https://ark.cn-beijing.volces.com/api/v3",minimax:"https://api.minimaxi.com",doubao:"https://openspeech.bytedance.com",agnes:"https://apihub.agnes-ai.com",bailian:"https://dashscope.aliyuncs.com",openrouter:"https://openrouter.ai/api/v1","openai-compatible":""},Use=new Set(["codex"]);function Fse({capability:e}){var w,k,C;const t=Xt(),{alert:n,confirm:i}=Un(),s=Je({queryKey:["media-providers",e],queryFn:()=>Lse(e)}),[r,o]=_.useState(null),c=Bse[e]??[],u=((w=s.data)==null?void 0:w.providers)??[],f=(C=(k=s.data)==null?void 0:k.defaults)==null?void 0:C[e],p=Dt({mutationFn:S=>Ise(S),onSuccess:()=>{o(null),t.invalidateQueries({queryKey:["media-providers",e]})},onError:S=>void n({title:"保存失败",body:S instanceof Error?S.message:String(S)})}),m=Dt({mutationFn:S=>Pse(S),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:S=>void n({title:"删除失败",body:S instanceof Error?S.message:String(S)})}),b=Dt({mutationFn:S=>zse(e,S),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:S=>void n({title:"设默认失败",body:S instanceof Error?S.message:String(S)})}),y=(S,j)=>(f==null?void 0:f.providerId)===S&&(f==null?void 0:f.model)===j,x=()=>o({isNew:!0,entry:{id:"",name:"",capability:e,adapter:c[0]??"",baseUrl:c[0]?cI[c[0]]??"":"",apiKey:"",models:[]}}),v=S=>o({isNew:!1,entry:{id:S.id,name:S.name,capability:e,adapter:S.adapter,baseUrl:S.baseUrl,apiKey:"",models:S.models}});return d.jsxs("section",{className:"nb-card",children:[d.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[d.jsxs("div",{children:[d.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:[v0[e],"供应商"]}),d.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["增删该能力的第三方生成端点(adapter + Base URL + key + models)。**点模型标签设为该能力默认**;✓ = 当前默认。",f?d.jsxs(d.Fragment,{children:[" ","当前默认:",d.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:f.providerId}),f.model?d.jsxs(d.Fragment,{children:[" · ",d.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:f.model})]}):null]}):" 当前默认:未设置"]})]}),d.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",onClick:x,"aria-label":`添加${v0[e]}供应商`,children:[d.jsx(Bn,{size:14,strokeWidth:3})," 添加供应商"]})]}),d.jsxs("div",{className:"flex flex-col gap-2 mt-4",children:[s.isLoading&&d.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"})," 加载中…"]}),!s.isLoading&&u.length===0&&d.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无供应商)"}),u.map(S=>d.jsxs("div",{className:"rounded-lg px-3 py-2 border-2 border-[var(--color-text)]",children:[d.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d.jsxs("div",{className:"min-w-0",children:[d.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:S.id}),d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",S.name]}),d.jsx("span",{className:"ml-2 text-[10px] font-bold px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)]",children:S.adapter}),d.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[S.baseUrl," · key ",S.keyMasked||"未设置"]})]}),d.jsxs("div",{className:"flex gap-1 shrink-0",children:[d.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>v(S),"aria-label":`编辑 ${S.id}`,children:d.jsx(e1,{size:12,strokeWidth:3})}),d.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除供应商",body:`删除 ${S.id}?`,danger:!0})&&m.mutate(S.id)},"aria-label":`删除 ${S.id}`,children:d.jsx(cs,{size:12,strokeWidth:3})})]})]}),S.models.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:S.models.map(j=>{const T=y(S.id,j);return d.jsxs("button",{type:"button",onClick:()=>b.mutate({providerId:S.id,model:j}),disabled:b.isPending,"aria-pressed":T,className:["nb-btn px-2 py-0.5 text-xs font-[family-name:var(--font-mono)]",T?"nb-btn-mint":""].join(" "),title:T?"当前默认":"设为该能力默认",children:[j,T?" ✓":""]},j)})})]},S.id))]}),r&&d.jsx(Ew,{onClose:()=>o(null),children:d.jsx(qse,{state:r,adapters:c,onChange:S=>o({...r,entry:S}),onCancel:()=>o(null),onSave:S=>p.mutate(S),saving:p.isPending})})]})}function $se(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const s=i.trim();s&&!n.includes(s)&&n.push(s)}return n}function qse({state:e,adapters:t,onChange:n,onCancel:i,onSave:s,saving:r}){const o=e.entry,[c,u]=_.useState(""),f=y=>n({...o,...y}),p=Use.has(o.adapter),m=/^[a-zA-Z0-9_-]+$/.test(o.id)&&!!o.name.trim()&&!!o.adapter.trim()&&(p||!!o.baseUrl.trim()),b=y=>{f({adapter:y,baseUrl:cI[y]??""})};return d.jsxs("div",{className:"border-[3px] border-[var(--color-text)] rounded-2xl p-6 bg-[var(--color-bg-cream)] shadow-[6px_6px_0_var(--color-text)] flex flex-col gap-4 w-[min(92vw,640px)] max-h-[88vh] overflow-y-auto",children:[d.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增供应商":`编辑 ${o.id}`,d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:[" (",v0[o.capability],")"]})]}),d.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:o.id,disabled:!e.isNew,onChange:y=>f({id:y.target.value}),placeholder:"如 my-tripo",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",d.jsx("input",{className:"nb-input",value:o.name,onChange:y=>f({name:y.target.value}),placeholder:"显示名"})]})]}),d.jsxs("div",{className:"flex flex-col gap-1 text-sm font-bold",children:["adapter",d.jsx(Ec,{value:o.adapter,onChange:b,ariaLabel:"adapter",options:t.map(y=>({value:y,label:y}))})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",p&&"(订阅无需,可留空)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:o.baseUrl,onChange:y=>f({baseUrl:y.target.value}),placeholder:p?"订阅走本地凭据,无需填":"https://api.example.com",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",p?"(订阅无需)":!e.isNew&&"(留空=保留)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:o.apiKey??"",onChange:y=>f({apiKey:y.target.value}),placeholder:p?"订阅无需":e.isNew?"sk-...":"留空保留",spellCheck:!1})]}),d.jsxs("div",{className:"flex flex-col gap-1",children:[d.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),d.jsx(uI,{models:o.models,draft:c,onModelsChange:y=>f({models:y}),onDraftChange:u}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),d.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[d.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:i,children:"取消"}),d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!m||r,onClick:()=>s({...o,models:$se(o.models,c)}),children:[r?d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3})," 保存"]})]})]})}async function Hse(){return(await wt("/api/mcp-tools")).tools}const Vse=[{key:"plugin",labelKey:"plugins.tab.plugin"},{key:"model",labelKey:"plugins.tab.model"},{key:"tool",labelKey:"plugins.tab.tool"}];function Kse(e){return e.key==="memory"?d.jsx(Wse,{}):e.key==="im"?d.jsx(tre,{}):null}function Gse(){const e=Ye(),[t,n]=_.useState("plugin");return d.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[d.jsxs("header",{children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("plugins.h1")}),d.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:e("plugins.desc")})]}),d.jsx(au,{ariaLabel:e("plugins.h1"),className:"",value:t,onChange:n,options:Vse.map(i=>({value:i.key,label:e(i.labelKey)}))}),d.jsx("div",{role:"tabpanel",children:t==="plugin"?d.jsx(Mse,{panelFor:Kse}):t==="model"?d.jsx(Qse,{}):d.jsx(are,{})})]})}function Wse(){var x,v,w;const e=Ye(),t=Xt(),{alert:n}=Un(),i=Je({queryKey:["system-memory"],queryFn:xF}),[s,r]=_.useState(null),[o,c]=_.useState(null);_.useEffect(()=>{i.data&&s===null&&(r(i.data.provider),c(i.data.url))},[i.data,s]);const u=s??((x=i.data)==null?void 0:x.provider)??"agentmemory",f=o??((v=i.data)==null?void 0:v.url)??"",p=i.data!=null&&(u!==i.data.provider||u==="custom"&&f!==i.data.url),m=k=>{const C=`system.memory.opt.${k}`;return e(C)},b=Dt({mutationFn:()=>vF(u,u==="custom"?f:""),onSuccess:()=>{t.invalidateQueries({queryKey:["system-memory"]}),t.invalidateQueries({queryKey:["system-env"]})},onError:k=>{n({title:e("system.memory.error"),body:k instanceof Error?k.message:String(k)})}}),y=((w=i.data)==null?void 0:w.options)??["none","builtin","agentmemory","custom"];return d.jsxs("section",{className:"nb-card",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:e("system.memory.title")}),d.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-3",children:e("system.memory.desc")}),d.jsxs("div",{className:"flex flex-col gap-3 max-w-md",children:[d.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[d.jsx("span",{className:"font-bold",children:e("system.memory.provider")}),d.jsx(Ec,{value:u,onChange:r,ariaLabel:e("system.memory.provider"),options:y.map(k=>({value:k,label:m(k)}))})]}),u==="custom"&&d.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[d.jsx("span",{className:"font-bold",children:e("system.memory.url")}),d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",type:"text",value:f,onChange:k=>c(k.target.value),placeholder:e("system.memory.url.placeholder"),spellCheck:!1,"aria-label":e("system.memory.url")})]}),d.jsx("div",{className:"flex justify-end",children:d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px",fontSize:12},onClick:()=>b.mutate(),disabled:!p||b.isPending,type:"button","aria-label":e("system.memory.save.aria"),children:[b.isPending?d.jsx(pt,{size:12,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:12,strokeWidth:3}),b.isSuccess&&!p?e("system.memory.saved"):e("system.memory.save")]})})]})]})}const Yse=[{key:"llm",label:"sps agent"},{key:"image",label:"图片"},{key:"video",label:"视频"},{key:"music",label:"音乐"},{key:"voice",label:"语音"},{key:"3d",label:"3D"},{key:"embedding",label:"Embedding"},{key:"rerank",label:"Rerank"}];function Xse(){const e=Ye(),t=Xt(),n=_.useRef(null),[i,s]=_.useState(!1),r=async()=>{s(!0);try{const c=await wt("/api/model-config/export"),u=new Blob([JSON.stringify(c,null,2)],{type:"application/json"}),f=document.createElement("a");f.href=URL.createObjectURL(u),f.download=`sps-model-config-${new Date().toISOString().slice(0,10)}.json`,f.click(),URL.revokeObjectURL(f.href)}catch(c){window.alert(`${e("plugins.model.export.failed")}: ${c instanceof Error?c.message:String(c)}`)}finally{s(!1)}},o=async c=>{s(!0);try{const u=JSON.parse(await c.text());if(!window.confirm(e("plugins.model.import.confirm")))return;const p=(await jr("/api/model-config/import",u)).summary;window.alert(e("plugins.model.import.done",{llm:String(Number(p.llmAnthropic??0)+Number(p.llmOpenai??0)),media:String(p.media??0),skipped:String(p.skipped??0)})),t.invalidateQueries()}catch(u){window.alert(`${e("plugins.model.import.failed")}: ${u instanceof Error?u.message:String(u)}`)}finally{s(!1),n.current&&(n.current.value="")}};return d.jsxs("div",{className:"flex gap-2 items-center ml-auto",children:[d.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px"},disabled:i,onClick:()=>void r(),title:e("plugins.model.export.hint"),children:[d.jsx($A,{size:14,strokeWidth:2.5})," ",e("plugins.model.export")]}),d.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px"},disabled:i,onClick:()=>{var c;return(c=n.current)==null?void 0:c.click()},title:e("plugins.model.import.hint"),children:[d.jsx(n1,{size:14,strokeWidth:2.5})," ",e("plugins.model.import")]}),d.jsx("input",{ref:n,type:"file",accept:"application/json,.json",className:"hidden",onChange:c=>{var f;const u=(f=c.target.files)==null?void 0:f[0];u&&o(u)}})]})}function Qse(){const[e,t]=_.useState("llm");return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"flex flex-wrap gap-2 items-center",role:"tablist","aria-label":"模型/资源供应商",children:[Yse.map(n=>{const i=e===n.key;return d.jsx("button",{type:"button",role:"tab","aria-selected":i,onClick:()=>t(n.key),className:["nb-btn",i?"nb-btn-primary":""].join(" "),style:{padding:"6px 14px"},children:n.label},n.key)}),d.jsx(Xse,{})]}),e==="llm"?d.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["Anthropic 兼容 ",d.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 Claude 订阅"})]}),d.jsx(_j,{only:"anthropic"})]}),d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["OpenAI 兼容 ",d.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 codex 订阅"})]}),d.jsx(_j,{only:"openai"})]})]}):d.jsx(Fse,{capability:e})]})}function _j({only:e}={}){var C,S,j;const t=Xt(),{alert:n,confirm:i}=Un(),s=Je({queryKey:["providers"],queryFn:j1}),o=(C=Je({queryKey:["system-agents"],queryFn:r1}).data)==null?void 0:C.agents,[c,u]=_.useState(null),f=Dt({mutationFn:T=>kY(c.kind,T),onSuccess:()=>{u(null),t.invalidateQueries({queryKey:["providers"]})},onError:T=>void n({title:"保存失败",body:T instanceof Error?T.message:String(T)})}),p=Dt({mutationFn:T=>SY(T.kind,T.id),onSuccess:()=>void t.invalidateQueries({queryKey:["providers"]}),onError:T=>void n({title:"删除失败",body:T instanceof Error?T.message:String(T)})}),m=Dt({mutationFn:T=>wF(T),onSuccess:()=>void t.invalidateQueries({queryKey:["system-agents"]}),onError:T=>void n({title:"设默认失败",body:T instanceof Error?T.message:String(T)})}),b=(T,A,M)=>{if(!o)return!1;const R=T==="anthropic"?o.worker:o.reviewer;return(R.providerId||"official")===A&&R.model===M},y=(T,A,M)=>{if(!o)return;let R;if(T==="anthropic"){const P={...o.worker,model:M};A==="official"?delete P.providerId:P.providerId=A,R={...o,worker:P}}else R={...o,reviewer:{...o.reviewer,providerId:A,model:M}};m.mutate(R)},x=[{kind:"anthropic",title:"Anthropic 兼容(worker / claude)",items:((S=s.data)==null?void 0:S.anthropic)??[]},{kind:"openai",title:"OpenAI 兼容(reviewer / openai agent)",items:((j=s.data)==null?void 0:j.openai)??[]}],v=e?x.filter(T=>T.kind===e):x,w=T=>u({kind:T,isNew:!0,entry:{id:"",name:"",baseUrl:"",apiKey:"",models:[]}}),k=(T,A)=>u({kind:T,isNew:!1,entry:{id:A.id,name:A.name,baseUrl:A.baseUrl,apiKey:"",transport:A.transport,models:A.models}});return d.jsxs("section",{className:"nb-card",children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:"模型 API 端点"}),d.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-4",children:"本地官方订阅(已登录验证)自动置顶,不可编辑;下方可增删第三方兼容端点。**点模型标签设为默认**(anthropic→worker / openai→监工);✓ = 当前默认。"}),d.jsx("div",{className:["grid grid-cols-1 gap-5",e?"":"lg:grid-cols-2"].join(" "),children:v.map(T=>d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsx("span",{className:"font-bold text-sm",children:T.title}),d.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:()=>w(T.kind),"aria-label":`添加 ${T.title} 端点`,children:[d.jsx(Bn,{size:12,strokeWidth:3})," 添加"]})]}),T.items.length===0&&d.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无端点)"}),T.items.map(A=>d.jsxs("div",{className:["rounded-lg px-3 py-2 border-2",(A.builtin,"border-[var(--color-text)]")].join(" "),children:[d.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d.jsxs("div",{className:"min-w-0",children:[d.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:A.id}),d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",A.name]}),A.builtin?d.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:["本地订阅",A.detail?` · ${A.detail}`:""," · 已验证可用"]}):d.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[A.baseUrl," · key ",A.hasKey?A.apiKey:"未设置"]})]}),A.builtin?d.jsx("span",{className:"shrink-0 text-[10px] font-bold px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)]",children:"内置"}):d.jsxs("div",{className:"flex gap-1 shrink-0",children:[d.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>k(T.kind,A),"aria-label":`编辑 ${A.id}`,children:d.jsx(e1,{size:12,strokeWidth:3})}),d.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除端点",body:`删除 ${A.id}?`,danger:!0})&&p.mutate({kind:T.kind,id:A.id})},"aria-label":`删除 ${A.id}`,children:d.jsx(cs,{size:12,strokeWidth:3})})]})]}),A.models.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:A.models.map(M=>{const R=b(T.kind,A.id,M);return d.jsxs("button",{type:"button",onClick:()=>y(T.kind,A.id,M),disabled:m.isPending,"aria-pressed":R,className:["nb-btn px-2 py-0.5 text-xs font-[family-name:var(--font-mono)]",R?"nb-btn-mint":""].join(" "),title:R?"当前默认":"设为默认",children:[M,R?" ✓":""]},M)})})]},A.id))]},T.kind))}),c&&d.jsx(Ew,{onClose:()=>u(null),children:d.jsx(Zse,{state:c,onChange:T=>u({...c,entry:T}),onCancel:()=>u(null),onSave:T=>f.mutate(T),saving:f.isPending})})]})}function w0(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const s=i.trim();s&&!n.includes(s)&&n.push(s)}return n}function uI({models:e,draft:t,onModelsChange:n,onDraftChange:i}){const s=r=>{n(w0(e,r)),i("")};return d.jsxs("div",{className:"nb-input min-h-[46px] w-full flex flex-wrap gap-1.5 items-center px-2.5 py-2",children:[e.map(r=>d.jsxs("span",{className:"inline-flex max-w-full items-center gap-1.5 rounded-md border border-[var(--color-border-light)] bg-[var(--surface-control)] px-2 py-1 text-xs font-[family-name:var(--font-mono)]",children:[d.jsx("span",{className:"max-w-[480px] truncate",children:r}),d.jsx("button",{type:"button",className:"shrink-0 text-[var(--color-text-muted)] hover:text-[var(--color-text)]",onClick:()=>n(e.filter(o=>o!==r)),"aria-label":`删除模型 ${r}`,children:d.jsx(vn,{size:12,strokeWidth:2.5})})]},r)),d.jsx("input",{id:"provider-models",className:"min-w-[180px] flex-1 bg-transparent px-1 py-0.5 text-sm outline-none font-[family-name:var(--font-mono)]",value:t,onChange:r=>{const o=r.target.value,c=o.split(/[,,\n\r]/);if(c.length===1){i(o);return}const u=c.pop()??"";n(w0(e,c.join(","))),i(u)},onKeyDown:r=>{r.key==="Enter"&&!r.nativeEvent.isComposing?(r.preventDefault(),s(t)):r.key==="Backspace"&&!t&&e.length>0&&n(e.slice(0,-1))},placeholder:e.length>0?"继续添加模型":"输入模型名后按 Enter","aria-label":"Models",spellCheck:!1})]})}function Zse({state:e,onChange:t,onCancel:n,onSave:i,saving:s}){const r=e.entry,[o,c]=_.useState(""),u=p=>t({...r,...p}),f=/^[a-zA-Z0-9_-]+$/.test(r.id)&&r.name.trim()&&r.baseUrl.trim();return d.jsxs("div",{className:"border-[3px] border-[var(--color-text)] rounded-2xl p-6 bg-[var(--color-bg-cream)] shadow-[6px_6px_0_var(--color-text)] flex flex-col gap-4 w-[min(92vw,640px)] max-h-[88vh] overflow-y-auto",children:[d.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增端点":`编辑 ${r.id}`,d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:["(",e.kind,")"]})]}),d.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:r.id,disabled:!e.isNew,onChange:p=>u({id:p.target.value}),placeholder:"如 my-openai",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",d.jsx("input",{className:"nb-input",value:r.name,onChange:p=>u({name:p.target.value}),placeholder:"显示名"})]})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:r.baseUrl,onChange:p=>u({baseUrl:p.target.value}),placeholder:"https://api.example.com/v1",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",!e.isNew&&"(留空=保留)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:r.apiKey??"",onChange:p=>u({apiKey:p.target.value}),placeholder:e.isNew?"sk-...":"••••(留空不改)",spellCheck:!1})]}),e.kind==="openai"&&d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["请求方言",d.jsxs("select",{className:"nb-input text-sm",value:r.transport??"chat_completions",onChange:p=>u({transport:p.target.value}),children:[d.jsx("option",{value:"chat_completions",children:"Chat Completions(/v1/chat/completions,默认)"}),d.jsx("option",{value:"responses",children:"Responses(/v1/responses)"})]}),d.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"走 codex 订阅的网关端点(如 gpt-*)必须选 Responses,否则上游 400。"})]}),d.jsxs("div",{className:"flex flex-col gap-1",children:[d.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),d.jsx(uI,{models:r.models,draft:o,onModelsChange:p=>u({models:p}),onDraftChange:c}),d.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),d.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[d.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:n,children:"取消"}),d.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!f||s,onClick:()=>i({...r,models:w0(r.models,o)}),children:[s?d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3})," 保存"]})]})]})}function Ew({children:e,onClose:t}){return IA.createPortal(d.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/50 p-4",onClick:t,children:d.jsx("div",{onClick:n=>n.stopPropagation(),children:e})}),document.body)}const Jse=["telegram","dingtalk","matrix","slack","discord","feishu"],Vd={telegram:"Telegram",dingtalk:"钉钉 (Stream)",matrix:"Matrix",slack:"Slack",discord:"Discord",feishu:"飞书 / Lark"},ere={telegram:[{key:"token",label:"Bot Token(@BotFather)",type:"password",placeholder:"123456:ABC-..."},{key:"allowedChatIds",label:"允许的 Chat ID(白名单,空=全放)",type:"list",placeholder:"逗号/换行分隔"}],dingtalk:[{key:"clientId",label:"Client ID(AppKey)",type:"text"},{key:"clientSecret",label:"Client Secret(AppSecret)",type:"password"},{key:"allowedConversations",label:"允许的会话 ID(白名单,空=全放)",type:"list"}],matrix:[{key:"homeserver",label:"Homeserver URL",type:"text",placeholder:"https://matrix.org"},{key:"accessToken",label:"Access Token",type:"password"},{key:"allowedRooms",label:"允许的 Room ID(白名单,空=全放)",type:"list"}],slack:[{key:"appToken",label:"App Token(xapp-,Socket Mode)",type:"password",placeholder:"xapp-..."},{key:"botToken",label:"Bot Token(xoxb-)",type:"password",placeholder:"xoxb-..."},{key:"allowedChannels",label:"允许的 Channel(白名单,空=全放)",type:"list"}],discord:[{key:"token",label:"Bot Token",type:"password"},{key:"allowedChannels",label:"允许的 Channel ID(白名单,空=全放)",type:"list"}],feishu:[{key:"appId",label:"App ID",type:"text"},{key:"appSecret",label:"App Secret",type:"password"},{key:"verificationToken",label:"Verification Token",type:"text"},{key:"encryptKey",label:"Encrypt Key(设了则事件 AES 解密)",type:"password"},{key:"port",label:"本机监听端口(默认 9800)",type:"number",placeholder:"9800"},{key:"path",label:"监听路径(默认 /feishu)",type:"text",placeholder:"/feishu"},{key:"allowedChats",label:"允许的 chat_id(白名单,空=全放)",type:"list"}]};function tre(){var x,v,w;const e=Xt(),{alert:t}=Un(),n=Je({queryKey:["channels"],queryFn:Dse}),[i,s]=_.useState(null),[r,o]=_.useState({type:"console"});_.useEffect(()=>{n.data&&!i&&s({console:n.data.console??{},adapters:n.data.adapters??[]})},[n.data,i]);const c=Dt({mutationFn:()=>Ose(i),onSuccess:k=>{s({console:k.console??{},adapters:k.adapters??[]}),e.invalidateQueries({queryKey:["channels"]})},onError:k=>void t({title:"保存失败",body:k instanceof Error?k.message:String(k)})});if(!i)return d.jsx("section",{className:"nb-card",children:d.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"})," 加载频道配置…"]})});const u=i.adapters??[],f=JSON.stringify(i)!==JSON.stringify({console:((x=n.data)==null?void 0:x.console)??{},adapters:((v=n.data)==null?void 0:v.adapters)??[]}),p=k=>{const C=[...u,{kind:k,enabled:!0}];s({...i,adapters:C}),o({type:"adapter",index:C.length-1})},m=k=>{const C=u.filter((S,j)=>j!==k);s({...i,adapters:C}),o({type:"console"})},b=(k,C)=>{const S=u.map((j,T)=>T===k?{...j,...C}:j);s({...i,adapters:S})},y=k=>s({...i,console:{...i.console,...k}});return d.jsxs("section",{className:"nb-card",children:[d.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[d.jsxs("div",{children:[d.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"频道(IM 网关)"}),d.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["接入 Telegram / 钉钉 / 飞书 / Slack / Discord / Matrix。左侧选频道,右侧改设置。保存后 ",d.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps im"})," 重启生效。"]})]}),d.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",disabled:!f||c.isPending,onClick:()=>c.mutate(),"aria-label":"保存频道配置",children:[c.isPending?d.jsx(pt,{size:14,strokeWidth:3,className:"animate-spin"}):d.jsx(Rs,{size:14,strokeWidth:3})," 保存"]})]}),d.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[220px_1fr] gap-5 mt-4",children:[d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("div",{className:"rounded-2xl border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] p-2 flex flex-col gap-1",children:[d.jsx(Cj,{label:"console 桥接",sub:((w=i.console)==null?void 0:w.url)||"未配置",active:r.type==="console",onClick:()=>o({type:"console"})}),d.jsx("div",{className:"h-px bg-[var(--color-text)] opacity-15 my-0.5"}),u.length===0&&d.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-2 py-1",children:"(无频道)"}),u.map((k,C)=>d.jsx(Cj,{label:Vd[k.kind]??k.kind,sub:k.enabled===!1?"已停用":"启用",active:r.type==="adapter"&&r.index===C,onClick:()=>o({type:"adapter",index:C})},C))]}),d.jsx(nre,{onAdd:p})]}),d.jsx("div",{className:"border-2 bg-surface-input border-[var(--color-text)] rounded-xl p-4 bg-[var(--color-bg-cream)]",children:(()=>{if(r.type!=="adapter")return d.jsx(jj,{console:i.console??{},onChange:y});const k=u[r.index];if(!k)return d.jsx(jj,{console:i.console??{},onChange:y});const C=r.index;return d.jsx(ire,{adapter:k,onChange:S=>b(C,S),onRemove:()=>m(C)})})()})]})]})}function nre({onAdd:e}){const[t,n]=_.useState(!1),i=_.useRef(null),s=_.useRef(null);return _.useEffect(()=>{const r=o=>{var c;(c=i.current)!=null&&c.contains(o.target)||n(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[]),d.jsxs("div",{className:"relative",ref:i,children:[d.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary w-full justify-center",onClick:()=>n(r=>!r),"aria-expanded":t,"aria-label":"添加频道",children:[d.jsx(Bn,{size:13,strokeWidth:3})," 添加频道",d.jsx(uo,{size:13,strokeWidth:2.5,className:["transition-transform",t?"rotate-180":""].join(" ")})]}),t&&d.jsx("div",{className:"absolute z-30 mt-2 left-0 min-w-full nb-card p-1 overflow-hidden bg-[var(--surface-menu)]",children:d.jsx("div",{ref:s,className:"max-h-[50vh] overflow-y-auto",children:Jse.map((r,o)=>d.jsx(ru,{index:o,root:s,delay:.02,children:d.jsxs("button",{type:"button",className:"dimension-menu-item w-full text-left px-4 py-2 text-sm font-semibold flex items-center gap-2",onClick:()=>{e(r),n(!1)},"aria-label":`添加 ${Vd[r]} 频道`,children:[d.jsx(Bn,{size:12,strokeWidth:3,className:"shrink-0"})," ",Vd[r]]})},r))})})]})}function Cj({label:e,sub:t,active:n,onClick:i}){return d.jsxs("button",{type:"button",onClick:i,"aria-pressed":n,className:["dimension-menu-item flex-col items-start gap-0.5 px-3 py-2 text-left",n?"dimension-menu-item-active":""].join(" "),children:[d.jsx("div",{className:"font-bold text-sm",children:e}),d.jsx("div",{className:"text-xs text-[var(--color-text-muted)] truncate w-full font-[family-name:var(--font-mono)]",children:t})]})}function jj({console:e,onChange:t}){return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{children:[d.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"console 桥接"}),d.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:"IM 纯文本消息桥接到项目 agent 对话。设了 URL 才启用桥接;token 为 console 鉴权令牌。"})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console URL",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:e.url??"",onChange:n=>t({url:n.target.value}),placeholder:"http://localhost:4321",spellCheck:!1})]}),d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console Token(SPS_CONSOLE_TOKEN)",d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:e.token??"",onChange:n=>t({token:n.target.value}),placeholder:"鉴权令牌(可空)",spellCheck:!1})]}),d.jsxs("div",{className:"flex flex-col gap-1 text-sm font-bold",children:["对话后端",d.jsx(Ec,{value:e.agentKind??"claude",onChange:n=>t({agentKind:n}),ariaLabel:"对话后端",options:[{value:"claude",label:"claude"},{value:"openai",label:"openai"}]})]})]})}function ire({adapter:e,onChange:t,onRemove:n}){const{confirm:i}=Un(),s=ere[e.kind]??[],r=e.enabled!==!1;return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsxs("div",{className:"flex items-start justify-between gap-2",children:[d.jsxs("div",{children:[d.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:Vd[e.kind]??e.kind}),d.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-[family-name:var(--font-mono)]",children:[" · ",e.kind]})]}),d.jsxs("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:async()=>{await i({title:"删除频道",body:`删除 ${Vd[e.kind]??e.kind} 频道?`,danger:!0})&&n()},"aria-label":"删除频道",children:[d.jsx(cs,{size:12,strokeWidth:3})," 删除"]})]}),d.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[d.jsx("input",{type:"checkbox",checked:r,onChange:o=>t({enabled:o.target.checked})}),"启用此频道"]}),s.map(o=>d.jsx(sre,{spec:o,value:e[o.key],onChange:c=>t({[o.key]:c})},o.key))]})}function sre({spec:e,value:t,onChange:n}){if(e.type==="list"){const i=Array.isArray(t)?t.map(String):[];return d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,d.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",rows:2,value:i.join(", "),onChange:s=>{const r=s.target.value.split(/[,\n]/).map(o=>o.trim()).filter(Boolean);n(r.length?r:void 0)},placeholder:e.placeholder,spellCheck:!1})]})}return d.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,d.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:e.type==="password"?"password":"text",value:t==null?"":String(t),onChange:i=>{const s=i.target.value;e.type==="number"?n(s.trim()===""?void 0:Number(s)):n(s===""?void 0:s)},placeholder:e.placeholder,spellCheck:!1})]})}const rre=["skill","asset","project","interaction","memory","agent","other"];function are(){const e=Ye(),t=Je({queryKey:["mcp-tools"],queryFn:Hse});if(t.isLoading)return d.jsx("section",{className:"nb-card",children:d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.loading")})});if(t.isError)return d.jsx("section",{className:"nb-card",children:d.jsxs("p",{className:"text-sm text-[var(--color-crashed)]",children:[e("plugins.tool.failed"),":",t.error instanceof Error?t.error.message:String(t.error)]})});const n=t.data??[],i=rre.map(s=>({key:s,items:n.filter(r=>r.group===s)})).filter(s=>s.items.length>0);return d.jsxs("div",{className:"flex flex-col gap-4",children:[d.jsx("section",{className:"nb-card",children:d.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.desc",{count:String(n.length)})})}),i.map(s=>d.jsxs("div",{className:"flex flex-col gap-2",children:[d.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:[e(`plugins.tool.group.${s.key}`),d.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)] ml-2",children:s.items.length})]}),d.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:s.items.map(r=>d.jsxs("section",{className:"nb-card flex flex-col gap-2",children:[d.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[d.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold",children:r.name}),!r.viaMcpOnOpenai&&d.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] bg-[var(--color-secondary)]",children:e("plugins.tool.nativeOnOpenai")})]}),d.jsx("p",{className:"text-sm leading-5",children:r.description}),r.params.length>0&&d.jsx("ul",{className:"flex flex-col gap-1 m-0 p-0 list-none",children:r.params.map(o=>d.jsxs("li",{className:"text-xs text-[var(--color-text-muted)] leading-4",children:[d.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[var(--color-text)]",children:o.name}),d.jsx("span",{className:"ml-1",children:o.type}),o.required&&d.jsx("span",{className:"ml-1 font-bold",children:e("plugins.tool.required")}),o.description&&d.jsxs("span",{className:"ml-1",children:["— ",o.description]})]},o.name))}),d.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",children:r.qualifiedName})]},r.name))})]},s.key))]})}function Wn(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,i;n<e.length;n++)(i=Wn(e[n]))!==""&&(t+=(t&&" ")+i);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var ore={value:()=>{}};function ug(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new Fp(n)}function Fp(e){this._=e}function lre(e,t){return e.trim().split(/^|\s+/).map(function(n){var i="",s=n.indexOf(".");if(s>=0&&(i=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}Fp.prototype=ug.prototype={constructor:Fp,on:function(e,t){var n=this._,i=lre(e+"",n),s,r=-1,o=i.length;if(arguments.length<2){for(;++r<o;)if((s=(e=i[r]).type)&&(s=cre(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++r<o;)if(s=(e=i[r]).type)n[s]=Tj(n[s],e.name,t);else if(t==null)for(s in n)n[s]=Tj(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Fp(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),i=0,s,r;i<s;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(r=this._[e],i=0,s=r.length;i<s;++i)r[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],s=0,r=i.length;s<r;++s)i[s].value.apply(t,n)}};function cre(e,t){for(var n=0,i=e.length,s;n<i;++n)if((s=e[n]).name===t)return s.value}function Tj(e,t,n){for(var i=0,s=e.length;i<s;++i)if(e[i].name===t){e[i]=ore,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var E0="http://www.w3.org/1999/xhtml";const Aj={svg:"http://www.w3.org/2000/svg",xhtml:E0,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function dg(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Aj.hasOwnProperty(t)?{space:Aj[t],local:e}:e}function ure(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===E0&&t.documentElement.namespaceURI===E0?t.createElement(e):t.createElementNS(n,e)}}function dre(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function dI(e){var t=dg(e);return(t.local?dre:ure)(t)}function fre(){}function kw(e){return e==null?fre:function(){return this.querySelector(e)}}function hre(e){typeof e!="function"&&(e=kw(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=new Array(o),u,f,p=0;p<o;++p)(u=r[p])&&(f=e.call(u,u.__data__,p,r))&&("__data__"in u&&(f.__data__=u.__data__),c[p]=f);return new os(i,this._parents)}function pre(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function mre(){return[]}function fI(e){return e==null?mre:function(){return this.querySelectorAll(e)}}function gre(e){return function(){return pre(e.apply(this,arguments))}}function yre(e){typeof e=="function"?e=gre(e):e=fI(e);for(var t=this._groups,n=t.length,i=[],s=[],r=0;r<n;++r)for(var o=t[r],c=o.length,u,f=0;f<c;++f)(u=o[f])&&(i.push(e.call(u,u.__data__,f,o)),s.push(u));return new os(i,s)}function hI(e){return function(){return this.matches(e)}}function pI(e){return function(t){return t.matches(e)}}var bre=Array.prototype.find;function xre(e){return function(){return bre.call(this.children,e)}}function vre(){return this.firstElementChild}function wre(e){return this.select(e==null?vre:xre(typeof e=="function"?e:pI(e)))}var Ere=Array.prototype.filter;function kre(){return Array.from(this.children)}function Sre(e){return function(){return Ere.call(this.children,e)}}function Nre(e){return this.selectAll(e==null?kre:Sre(typeof e=="function"?e:pI(e)))}function _re(e){typeof e!="function"&&(e=hI(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=[],u,f=0;f<o;++f)(u=r[f])&&e.call(u,u.__data__,f,r)&&c.push(u);return new os(i,this._parents)}function mI(e){return new Array(e.length)}function Cre(){return new os(this._enter||this._groups.map(mI),this._parents)}function Em(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Em.prototype={constructor:Em,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 jre(e){return function(){return e}}function Tre(e,t,n,i,s,r){for(var o=0,c,u=t.length,f=r.length;o<f;++o)(c=t[o])?(c.__data__=r[o],i[o]=c):n[o]=new Em(e,r[o]);for(;o<u;++o)(c=t[o])&&(s[o]=c)}function Are(e,t,n,i,s,r,o){var c,u,f=new Map,p=t.length,m=r.length,b=new Array(p),y;for(c=0;c<p;++c)(u=t[c])&&(b[c]=y=o.call(u,u.__data__,c,t)+"",f.has(y)?s[c]=u:f.set(y,u));for(c=0;c<m;++c)y=o.call(e,r[c],c,r)+"",(u=f.get(y))?(i[c]=u,u.__data__=r[c],f.delete(y)):n[c]=new Em(e,r[c]);for(c=0;c<p;++c)(u=t[c])&&f.get(b[c])===u&&(s[c]=u)}function Mre(e){return e.__data__}function Rre(e,t){if(!arguments.length)return Array.from(this,Mre);var n=t?Are:Tre,i=this._parents,s=this._groups;typeof e!="function"&&(e=jre(e));for(var r=s.length,o=new Array(r),c=new Array(r),u=new Array(r),f=0;f<r;++f){var p=i[f],m=s[f],b=m.length,y=Dre(e.call(p,p&&p.__data__,f,i)),x=y.length,v=c[f]=new Array(x),w=o[f]=new Array(x),k=u[f]=new Array(b);n(p,m,v,w,k,y,t);for(var C=0,S=0,j,T;C<x;++C)if(j=v[C]){for(C>=S&&(S=C+1);!(T=w[S])&&++S<x;);j._next=T||null}}return o=new os(o,i),o._enter=c,o._exit=u,o}function Dre(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Ore(){return new os(this._exit||this._groups.map(mI),this._parents)}function Lre(e,t,n){var i=this.enter(),s=this,r=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?r.remove():n(r),i&&s?i.merge(s).order():s}function Ire(e){for(var t=e.selection?e.selection():e,n=this._groups,i=t._groups,s=n.length,r=i.length,o=Math.min(s,r),c=new Array(s),u=0;u<o;++u)for(var f=n[u],p=i[u],m=f.length,b=c[u]=new Array(m),y,x=0;x<m;++x)(y=f[x]||p[x])&&(b[x]=y);for(;u<s;++u)c[u]=n[u];return new os(c,this._parents)}function Pre(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var i=e[t],s=i.length-1,r=i[s],o;--s>=0;)(o=i[s])&&(r&&o.compareDocumentPosition(r)^4&&r.parentNode.insertBefore(o,r),r=o);return this}function zre(e){e||(e=Bre);function t(m,b){return m&&b?e(m.__data__,b.__data__):!m-!b}for(var n=this._groups,i=n.length,s=new Array(i),r=0;r<i;++r){for(var o=n[r],c=o.length,u=s[r]=new Array(c),f,p=0;p<c;++p)(f=o[p])&&(u[p]=f);u.sort(t)}return new os(s,this._parents).order()}function Bre(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Ure(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Fre(){return Array.from(this)}function $re(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,r=i.length;s<r;++s){var o=i[s];if(o)return o}return null}function qre(){let e=0;for(const t of this)++e;return e}function Hre(){return!this.node()}function Vre(e){for(var t=this._groups,n=0,i=t.length;n<i;++n)for(var s=t[n],r=0,o=s.length,c;r<o;++r)(c=s[r])&&e.call(c,c.__data__,r,s);return this}function Kre(e){return function(){this.removeAttribute(e)}}function Gre(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Wre(e,t){return function(){this.setAttribute(e,t)}}function Yre(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Xre(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Qre(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 Zre(e,t){var n=dg(e);if(arguments.length<2){var i=this.node();return n.local?i.getAttributeNS(n.space,n.local):i.getAttribute(n)}return this.each((t==null?n.local?Gre:Kre:typeof t=="function"?n.local?Qre:Xre:n.local?Yre:Wre)(n,t))}function gI(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Jre(e){return function(){this.style.removeProperty(e)}}function eae(e,t,n){return function(){this.style.setProperty(e,t,n)}}function tae(e,t,n){return function(){var i=t.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,n)}}function nae(e,t,n){return arguments.length>1?this.each((t==null?Jre:typeof t=="function"?tae:eae)(e,t,n??"")):Vc(this.node(),e)}function Vc(e,t){return e.style.getPropertyValue(t)||gI(e).getComputedStyle(e,null).getPropertyValue(t)}function iae(e){return function(){delete this[e]}}function sae(e,t){return function(){this[e]=t}}function rae(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function aae(e,t){return arguments.length>1?this.each((t==null?iae:typeof t=="function"?rae:sae)(e,t)):this.node()[e]}function yI(e){return e.trim().split(/^|\s+/)}function Sw(e){return e.classList||new bI(e)}function bI(e){this._node=e,this._names=yI(e.getAttribute("class")||"")}bI.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 xI(e,t){for(var n=Sw(e),i=-1,s=t.length;++i<s;)n.add(t[i])}function vI(e,t){for(var n=Sw(e),i=-1,s=t.length;++i<s;)n.remove(t[i])}function oae(e){return function(){xI(this,e)}}function lae(e){return function(){vI(this,e)}}function cae(e,t){return function(){(t.apply(this,arguments)?xI:vI)(this,e)}}function uae(e,t){var n=yI(e+"");if(arguments.length<2){for(var i=Sw(this.node()),s=-1,r=n.length;++s<r;)if(!i.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?cae:t?oae:lae)(n,t))}function dae(){this.textContent=""}function fae(e){return function(){this.textContent=e}}function hae(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function pae(e){return arguments.length?this.each(e==null?dae:(typeof e=="function"?hae:fae)(e)):this.node().textContent}function mae(){this.innerHTML=""}function gae(e){return function(){this.innerHTML=e}}function yae(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function bae(e){return arguments.length?this.each(e==null?mae:(typeof e=="function"?yae:gae)(e)):this.node().innerHTML}function xae(){this.nextSibling&&this.parentNode.appendChild(this)}function vae(){return this.each(xae)}function wae(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Eae(){return this.each(wae)}function kae(e){var t=typeof e=="function"?e:dI(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function Sae(){return null}function Nae(e,t){var n=typeof e=="function"?e:dI(e),i=t==null?Sae:typeof t=="function"?t:kw(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})}function _ae(){var e=this.parentNode;e&&e.removeChild(this)}function Cae(){return this.each(_ae)}function jae(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Tae(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Aae(e){return this.select(e?Tae:jae)}function Mae(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Rae(e){return function(t){e.call(this,t,this.__data__)}}function Dae(e){return e.trim().split(/^|\s+/).map(function(t){var n="",i=t.indexOf(".");return i>=0&&(n=t.slice(i+1),t=t.slice(0,i)),{type:t,name:n}})}function Oae(e){return function(){var t=this.__on;if(t){for(var n=0,i=-1,s=t.length,r;n<s;++n)r=t[n],(!e.type||r.type===e.type)&&r.name===e.name?this.removeEventListener(r.type,r.listener,r.options):t[++i]=r;++i?t.length=i:delete this.__on}}}function Lae(e,t,n){return function(){var i=this.__on,s,r=Rae(t);if(i){for(var o=0,c=i.length;o<c;++o)if((s=i[o]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=r,s.options=n),s.value=t;return}}this.addEventListener(e.type,r,n),s={type:e.type,name:e.name,value:t,listener:r,options:n},i?i.push(s):this.__on=[s]}}function Iae(e,t,n){var i=Dae(e+""),s,r=i.length,o;if(arguments.length<2){var c=this.node().__on;if(c){for(var u=0,f=c.length,p;u<f;++u)for(s=0,p=c[u];s<r;++s)if((o=i[s]).type===p.type&&o.name===p.name)return p.value}return}for(c=t?Lae:Oae,s=0;s<r;++s)this.each(c(i[s],t,n));return this}function wI(e,t,n){var i=gI(e),s=i.CustomEvent;typeof s=="function"?s=new s(t,n):(s=i.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function Pae(e,t){return function(){return wI(this,e,t)}}function zae(e,t){return function(){return wI(this,e,t.apply(this,arguments))}}function Bae(e,t){return this.each((typeof t=="function"?zae:Pae)(e,t))}function*Uae(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],s=0,r=i.length,o;s<r;++s)(o=i[s])&&(yield o)}var EI=[null];function os(e,t){this._groups=e,this._parents=t}function _f(){return new os([[document.documentElement]],EI)}function Fae(){return this}os.prototype=_f.prototype={constructor:os,select:hre,selectAll:yre,selectChild:wre,selectChildren:Nre,filter:_re,data:Rre,enter:Cre,exit:Ore,join:Lre,merge:Ire,selection:Fae,order:Pre,sort:zre,call:Ure,nodes:Fre,node:$re,size:qre,empty:Hre,each:Vre,attr:Zre,style:nae,property:aae,classed:uae,text:pae,html:bae,raise:vae,lower:Eae,append:kae,insert:Nae,remove:Cae,clone:Aae,datum:Mae,on:Iae,dispatch:Bae,[Symbol.iterator]:Uae};function ss(e){return typeof e=="string"?new os([[document.querySelector(e)]],[document.documentElement]):new os([[e]],EI)}function $ae(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Gs(e,t){if(e=$ae(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var i=n.createSVGPoint();return i.x=e.clientX,i.y=e.clientY,i=i.matrixTransform(t.getScreenCTM().inverse()),[i.x,i.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const qae={passive:!1},Kd={capture:!0,passive:!1};function zx(e){e.stopImmediatePropagation()}function Sc(e){e.preventDefault(),e.stopImmediatePropagation()}function kI(e){var t=e.document.documentElement,n=ss(e).on("dragstart.drag",Sc,Kd);"onselectstart"in t?n.on("selectstart.drag",Sc,Kd):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function SI(e,t){var n=e.document.documentElement,i=ss(e).on("dragstart.drag",null);t&&(i.on("click.drag",Sc,Kd),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in n?i.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const hp=e=>()=>e;function k0(e,{sourceEvent:t,subject:n,target:i,identifier:s,active:r,x:o,y:c,dx:u,dy:f,dispatch:p}){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:i,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:r,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:c,enumerable:!0,configurable:!0},dx:{value:u,enumerable:!0,configurable:!0},dy:{value:f,enumerable:!0,configurable:!0},_:{value:p}})}k0.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Hae(e){return!e.ctrlKey&&!e.button}function Vae(){return this.parentNode}function Kae(e,t){return t??{x:e.x,y:e.y}}function Gae(){return navigator.maxTouchPoints||"ontouchstart"in this}function NI(){var e=Hae,t=Vae,n=Kae,i=Gae,s={},r=ug("start","drag","end"),o=0,c,u,f,p,m=0;function b(j){j.on("mousedown.drag",y).filter(i).on("touchstart.drag",w).on("touchmove.drag",k,qae).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function y(j,T){if(!(p||!e.call(this,j,T))){var A=S(this,t.call(this,j,T),j,T,"mouse");A&&(ss(j.view).on("mousemove.drag",x,Kd).on("mouseup.drag",v,Kd),kI(j.view),zx(j),f=!1,c=j.clientX,u=j.clientY,A("start",j))}}function x(j){if(Sc(j),!f){var T=j.clientX-c,A=j.clientY-u;f=T*T+A*A>m}s.mouse("drag",j)}function v(j){ss(j.view).on("mousemove.drag mouseup.drag",null),SI(j.view,f),Sc(j),s.mouse("end",j)}function w(j,T){if(e.call(this,j,T)){var A=j.changedTouches,M=t.call(this,j,T),R=A.length,P,I;for(P=0;P<R;++P)(I=S(this,M,j,T,A[P].identifier,A[P]))&&(zx(j),I("start",j,A[P]))}}function k(j){var T=j.changedTouches,A=T.length,M,R;for(M=0;M<A;++M)(R=s[T[M].identifier])&&(Sc(j),R("drag",j,T[M]))}function C(j){var T=j.changedTouches,A=T.length,M,R;for(p&&clearTimeout(p),p=setTimeout(function(){p=null},500),M=0;M<A;++M)(R=s[T[M].identifier])&&(zx(j),R("end",j,T[M]))}function S(j,T,A,M,R,P){var I=r.copy(),B=Gs(P||A,T),F,V,D;if((D=n.call(j,new k0("beforestart",{sourceEvent:A,target:b,identifier:R,active:o,x:B[0],y:B[1],dx:0,dy:0,dispatch:I}),M))!=null)return F=D.x-B[0]||0,V=D.y-B[1]||0,function L(z,W,X){var G=B,U;switch(z){case"start":s[R]=L,U=o++;break;case"end":delete s[R],--o;case"drag":B=Gs(X||W,T),U=o;break}I.call(z,j,new k0(z,{sourceEvent:W,subject:D,target:b,identifier:R,active:U,x:B[0]+F,y:B[1]+V,dx:B[0]-G[0],dy:B[1]-G[1],dispatch:I}),M)}}return b.filter=function(j){return arguments.length?(e=typeof j=="function"?j:hp(!!j),b):e},b.container=function(j){return arguments.length?(t=typeof j=="function"?j:hp(j),b):t},b.subject=function(j){return arguments.length?(n=typeof j=="function"?j:hp(j),b):n},b.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:hp(!!j),b):i},b.on=function(){var j=r.on.apply(r,arguments);return j===r?b:j},b.clickDistance=function(j){return arguments.length?(m=(j=+j)*j,b):Math.sqrt(m)},b}function Nw(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function _I(e,t){var n=Object.create(e.prototype);for(var i in t)n[i]=t[i];return n}function Cf(){}var Gd=.7,km=1/Gd,Nc="\\s*([+-]?\\d+)\\s*",Wd="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Sr="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Wae=/^#([0-9a-f]{3,8})$/,Yae=new RegExp(`^rgb\\(${Nc},${Nc},${Nc}\\)$`),Xae=new RegExp(`^rgb\\(${Sr},${Sr},${Sr}\\)$`),Qae=new RegExp(`^rgba\\(${Nc},${Nc},${Nc},${Wd}\\)$`),Zae=new RegExp(`^rgba\\(${Sr},${Sr},${Sr},${Wd}\\)$`),Jae=new RegExp(`^hsl\\(${Wd},${Sr},${Sr}\\)$`),eoe=new RegExp(`^hsla\\(${Wd},${Sr},${Sr},${Wd}\\)$`),Mj={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};Nw(Cf,hl,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Rj,formatHex:Rj,formatHex8:toe,formatHsl:noe,formatRgb:Dj,toString:Dj});function Rj(){return this.rgb().formatHex()}function toe(){return this.rgb().formatHex8()}function noe(){return CI(this).formatHsl()}function Dj(){return this.rgb().formatRgb()}function hl(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=Wae.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Oj(t):n===3?new Hi(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?pp(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?pp(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=Yae.exec(e))?new Hi(t[1],t[2],t[3],1):(t=Xae.exec(e))?new Hi(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Qae.exec(e))?pp(t[1],t[2],t[3],t[4]):(t=Zae.exec(e))?pp(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=Jae.exec(e))?Pj(t[1],t[2]/100,t[3]/100,1):(t=eoe.exec(e))?Pj(t[1],t[2]/100,t[3]/100,t[4]):Mj.hasOwnProperty(e)?Oj(Mj[e]):e==="transparent"?new Hi(NaN,NaN,NaN,0):null}function Oj(e){return new Hi(e>>16&255,e>>8&255,e&255,1)}function pp(e,t,n,i){return i<=0&&(e=t=n=NaN),new Hi(e,t,n,i)}function ioe(e){return e instanceof Cf||(e=hl(e)),e?(e=e.rgb(),new Hi(e.r,e.g,e.b,e.opacity)):new Hi}function S0(e,t,n,i){return arguments.length===1?ioe(e):new Hi(e,t,n,i??1)}function Hi(e,t,n,i){this.r=+e,this.g=+t,this.b=+n,this.opacity=+i}Nw(Hi,S0,_I(Cf,{brighter(e){return e=e==null?km:Math.pow(km,e),new Hi(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Gd:Math.pow(Gd,e),new Hi(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Hi(al(this.r),al(this.g),al(this.b),Sm(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:Lj,formatHex:Lj,formatHex8:soe,formatRgb:Ij,toString:Ij}));function Lj(){return`#${Wo(this.r)}${Wo(this.g)}${Wo(this.b)}`}function soe(){return`#${Wo(this.r)}${Wo(this.g)}${Wo(this.b)}${Wo((isNaN(this.opacity)?1:this.opacity)*255)}`}function Ij(){const e=Sm(this.opacity);return`${e===1?"rgb(":"rgba("}${al(this.r)}, ${al(this.g)}, ${al(this.b)}${e===1?")":`, ${e})`}`}function Sm(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function al(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Wo(e){return e=al(e),(e<16?"0":"")+e.toString(16)}function Pj(e,t,n,i){return i<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ws(e,t,n,i)}function CI(e){if(e instanceof Ws)return new Ws(e.h,e.s,e.l,e.opacity);if(e instanceof Cf||(e=hl(e)),!e)return new Ws;if(e instanceof Ws)return e;e=e.rgb();var t=e.r/255,n=e.g/255,i=e.b/255,s=Math.min(t,n,i),r=Math.max(t,n,i),o=NaN,c=r-s,u=(r+s)/2;return c?(t===r?o=(n-i)/c+(n<i)*6:n===r?o=(i-t)/c+2:o=(t-n)/c+4,c/=u<.5?r+s:2-r-s,o*=60):c=u>0&&u<1?0:o,new Ws(o,c,u,e.opacity)}function roe(e,t,n,i){return arguments.length===1?CI(e):new Ws(e,t,n,i??1)}function Ws(e,t,n,i){this.h=+e,this.s=+t,this.l=+n,this.opacity=+i}Nw(Ws,roe,_I(Cf,{brighter(e){return e=e==null?km:Math.pow(km,e),new Ws(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Gd:Math.pow(Gd,e),new Ws(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,i=n+(n<.5?n:1-n)*t,s=2*n-i;return new Hi(Bx(e>=240?e-240:e+120,s,i),Bx(e,s,i),Bx(e<120?e+240:e-120,s,i),this.opacity)},clamp(){return new Ws(zj(this.h),mp(this.s),mp(this.l),Sm(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=Sm(this.opacity);return`${e===1?"hsl(":"hsla("}${zj(this.h)}, ${mp(this.s)*100}%, ${mp(this.l)*100}%${e===1?")":`, ${e})`}`}}));function zj(e){return e=(e||0)%360,e<0?e+360:e}function mp(e){return Math.max(0,Math.min(1,e||0))}function Bx(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 _w=e=>()=>e;function aoe(e,t){return function(n){return e+n*t}}function ooe(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(i){return Math.pow(e+i*t,n)}}function loe(e){return(e=+e)==1?jI:function(t,n){return n-t?ooe(t,n,e):_w(isNaN(t)?n:t)}}function jI(e,t){var n=t-e;return n?aoe(e,n):_w(isNaN(e)?t:e)}const Nm=(function e(t){var n=loe(t);function i(s,r){var o=n((s=S0(s)).r,(r=S0(r)).r),c=n(s.g,r.g),u=n(s.b,r.b),f=jI(s.opacity,r.opacity);return function(p){return s.r=o(p),s.g=c(p),s.b=u(p),s.opacity=f(p),s+""}}return i.gamma=e,i})(1);function coe(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,i=t.slice(),s;return function(r){for(s=0;s<n;++s)i[s]=e[s]*(1-r)+t[s]*r;return i}}function uoe(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function doe(e,t){var n=t?t.length:0,i=e?Math.min(n,e.length):0,s=new Array(i),r=new Array(n),o;for(o=0;o<i;++o)s[o]=Td(e[o],t[o]);for(;o<n;++o)r[o]=t[o];return function(c){for(o=0;o<i;++o)r[o]=s[o](c);return r}}function foe(e,t){var n=new Date;return e=+e,t=+t,function(i){return n.setTime(e*(1-i)+t*i),n}}function wr(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function hoe(e,t){var n={},i={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=Td(e[s],t[s]):i[s]=t[s];return function(r){for(s in n)i[s]=n[s](r);return i}}var N0=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Ux=new RegExp(N0.source,"g");function poe(e){return function(){return e}}function moe(e){return function(t){return e(t)+""}}function TI(e,t){var n=N0.lastIndex=Ux.lastIndex=0,i,s,r,o=-1,c=[],u=[];for(e=e+"",t=t+"";(i=N0.exec(e))&&(s=Ux.exec(t));)(r=s.index)>n&&(r=t.slice(n,r),c[o]?c[o]+=r:c[++o]=r),(i=i[0])===(s=s[0])?c[o]?c[o]+=s:c[++o]=s:(c[++o]=null,u.push({i:o,x:wr(i,s)})),n=Ux.lastIndex;return n<t.length&&(r=t.slice(n),c[o]?c[o]+=r:c[++o]=r),c.length<2?u[0]?moe(u[0].x):poe(t):(t=u.length,function(f){for(var p=0,m;p<t;++p)c[(m=u[p]).i]=m.x(f);return c.join("")})}function Td(e,t){var n=typeof t,i;return t==null||n==="boolean"?_w(t):(n==="number"?wr:n==="string"?(i=hl(t))?(t=i,Nm):TI:t instanceof hl?Nm:t instanceof Date?foe:uoe(t)?coe:Array.isArray(t)?doe:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?hoe:wr)(e,t)}var Bj=180/Math.PI,_0={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function AI(e,t,n,i,s,r){var o,c,u;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(u=e*n+t*i)&&(n-=e*u,i-=t*u),(c=Math.sqrt(n*n+i*i))&&(n/=c,i/=c,u/=c),e*i<t*n&&(e=-e,t=-t,u=-u,o=-o),{translateX:s,translateY:r,rotate:Math.atan2(t,e)*Bj,skewX:Math.atan(u)*Bj,scaleX:o,scaleY:c}}var gp;function goe(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?_0:AI(t.a,t.b,t.c,t.d,t.e,t.f)}function yoe(e){return e==null||(gp||(gp=document.createElementNS("http://www.w3.org/2000/svg","g")),gp.setAttribute("transform",e),!(e=gp.transform.baseVal.consolidate()))?_0:(e=e.matrix,AI(e.a,e.b,e.c,e.d,e.e,e.f))}function MI(e,t,n,i){function s(f){return f.length?f.pop()+" ":""}function r(f,p,m,b,y,x){if(f!==m||p!==b){var v=y.push("translate(",null,t,null,n);x.push({i:v-4,x:wr(f,m)},{i:v-2,x:wr(p,b)})}else(m||b)&&y.push("translate("+m+t+b+n)}function o(f,p,m,b){f!==p?(f-p>180?p+=360:p-f>180&&(f+=360),b.push({i:m.push(s(m)+"rotate(",null,i)-2,x:wr(f,p)})):p&&m.push(s(m)+"rotate("+p+i)}function c(f,p,m,b){f!==p?b.push({i:m.push(s(m)+"skewX(",null,i)-2,x:wr(f,p)}):p&&m.push(s(m)+"skewX("+p+i)}function u(f,p,m,b,y,x){if(f!==m||p!==b){var v=y.push(s(y)+"scale(",null,",",null,")");x.push({i:v-4,x:wr(f,m)},{i:v-2,x:wr(p,b)})}else(m!==1||b!==1)&&y.push(s(y)+"scale("+m+","+b+")")}return function(f,p){var m=[],b=[];return f=e(f),p=e(p),r(f.translateX,f.translateY,p.translateX,p.translateY,m,b),o(f.rotate,p.rotate,m,b),c(f.skewX,p.skewX,m,b),u(f.scaleX,f.scaleY,p.scaleX,p.scaleY,m,b),f=p=null,function(y){for(var x=-1,v=b.length,w;++x<v;)m[(w=b[x]).i]=w.x(y);return m.join("")}}}var boe=MI(goe,"px, ","px)","deg)"),xoe=MI(yoe,", ",")",")"),voe=1e-12;function Uj(e){return((e=Math.exp(e))+1/e)/2}function woe(e){return((e=Math.exp(e))-1/e)/2}function Eoe(e){return((e=Math.exp(2*e))-1)/(e+1)}const $p=(function e(t,n,i){function s(r,o){var c=r[0],u=r[1],f=r[2],p=o[0],m=o[1],b=o[2],y=p-c,x=m-u,v=y*y+x*x,w,k;if(v<voe)k=Math.log(b/f)/t,w=function(M){return[c+M*y,u+M*x,f*Math.exp(t*M*k)]};else{var C=Math.sqrt(v),S=(b*b-f*f+i*v)/(2*f*n*C),j=(b*b-f*f-i*v)/(2*b*n*C),T=Math.log(Math.sqrt(S*S+1)-S),A=Math.log(Math.sqrt(j*j+1)-j);k=(A-T)/t,w=function(M){var R=M*k,P=Uj(T),I=f/(n*C)*(P*Eoe(t*R+T)-woe(T));return[c+I*y,u+I*x,f*P/Uj(t*R+T)]}}return w.duration=k*1e3*t/Math.SQRT2,w}return s.rho=function(r){var o=Math.max(.001,+r),c=o*o,u=c*c;return e(o,c,u)},s})(Math.SQRT2,2,4);var Kc=0,yd=0,cd=0,RI=1e3,_m,bd,Cm=0,pl=0,fg=0,Yd=typeof performance=="object"&&performance.now?performance:Date,DI=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Cw(){return pl||(DI(koe),pl=Yd.now()+fg)}function koe(){pl=0}function jm(){this._call=this._time=this._next=null}jm.prototype=OI.prototype={constructor:jm,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Cw():+n)+(t==null?0:+t),!this._next&&bd!==this&&(bd?bd._next=this:_m=this,bd=this),this._call=e,this._time=n,C0()},stop:function(){this._call&&(this._call=null,this._time=1/0,C0())}};function OI(e,t,n){var i=new jm;return i.restart(e,t,n),i}function Soe(){Cw(),++Kc;for(var e=_m,t;e;)(t=pl-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Kc}function Fj(){pl=(Cm=Yd.now())+fg,Kc=yd=0;try{Soe()}finally{Kc=0,_oe(),pl=0}}function Noe(){var e=Yd.now(),t=e-Cm;t>RI&&(fg-=t,Cm=e)}function _oe(){for(var e,t=_m,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:_m=n);bd=e,C0(i)}function C0(e){if(!Kc){yd&&(yd=clearTimeout(yd));var t=e-pl;t>24?(e<1/0&&(yd=setTimeout(Fj,e-Yd.now()-fg)),cd&&(cd=clearInterval(cd))):(cd||(Cm=Yd.now(),cd=setInterval(Noe,RI)),Kc=1,DI(Fj))}}function $j(e,t,n){var i=new jm;return t=t==null?0:+t,i.restart(s=>{i.stop(),e(s+t)},t,n),i}var Coe=ug("start","end","cancel","interrupt"),joe=[],LI=0,qj=1,j0=2,qp=3,Hj=4,T0=5,Hp=6;function hg(e,t,n,i,s,r){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;Toe(e,n,{name:t,index:i,group:s,on:Coe,tween:joe,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:LI})}function jw(e,t){var n=sr(e,t);if(n.state>LI)throw new Error("too late; already scheduled");return n}function Ar(e,t){var n=sr(e,t);if(n.state>qp)throw new Error("too late; already running");return n}function sr(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Toe(e,t,n){var i=e.__transition,s;i[t]=n,n.timer=OI(r,0,n.time);function r(f){n.state=qj,n.timer.restart(o,n.delay,n.time),n.delay<=f&&o(f-n.delay)}function o(f){var p,m,b,y;if(n.state!==qj)return u();for(p in i)if(y=i[p],y.name===n.name){if(y.state===qp)return $j(o);y.state===Hj?(y.state=Hp,y.timer.stop(),y.on.call("interrupt",e,e.__data__,y.index,y.group),delete i[p]):+p<t&&(y.state=Hp,y.timer.stop(),y.on.call("cancel",e,e.__data__,y.index,y.group),delete i[p])}if($j(function(){n.state===qp&&(n.state=Hj,n.timer.restart(c,n.delay,n.time),c(f))}),n.state=j0,n.on.call("start",e,e.__data__,n.index,n.group),n.state===j0){for(n.state=qp,s=new Array(b=n.tween.length),p=0,m=-1;p<b;++p)(y=n.tween[p].value.call(e,e.__data__,n.index,n.group))&&(s[++m]=y);s.length=m+1}}function c(f){for(var p=f<n.duration?n.ease.call(null,f/n.duration):(n.timer.restart(u),n.state=T0,1),m=-1,b=s.length;++m<b;)s[m].call(e,p);n.state===T0&&(n.on.call("end",e,e.__data__,n.index,n.group),u())}function u(){n.state=Hp,n.timer.stop(),delete i[t];for(var f in i)return;delete e.__transition}}function Vp(e,t){var n=e.__transition,i,s,r=!0,o;if(n){t=t==null?null:t+"";for(o in n){if((i=n[o]).name!==t){r=!1;continue}s=i.state>j0&&i.state<T0,i.state=Hp,i.timer.stop(),i.on.call(s?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete n[o]}r&&delete e.__transition}}function Aoe(e){return this.each(function(){Vp(this,e)})}function Moe(e,t){var n,i;return function(){var s=Ar(this,e),r=s.tween;if(r!==n){i=n=r;for(var o=0,c=i.length;o<c;++o)if(i[o].name===t){i=i.slice(),i.splice(o,1);break}}s.tween=i}}function Roe(e,t,n){var i,s;if(typeof n!="function")throw new Error;return function(){var r=Ar(this,e),o=r.tween;if(o!==i){s=(i=o).slice();for(var c={name:t,value:n},u=0,f=s.length;u<f;++u)if(s[u].name===t){s[u]=c;break}u===f&&s.push(c)}r.tween=s}}function Doe(e,t){var n=this._id;if(e+="",arguments.length<2){for(var i=sr(this.node(),n).tween,s=0,r=i.length,o;s<r;++s)if((o=i[s]).name===e)return o.value;return null}return this.each((t==null?Moe:Roe)(n,e,t))}function Tw(e,t,n){var i=e._id;return e.each(function(){var s=Ar(this,i);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return sr(s,i).value[t]}}function II(e,t){var n;return(typeof t=="number"?wr:t instanceof hl?Nm:(n=hl(t))?(t=n,Nm):TI)(e,t)}function Ooe(e){return function(){this.removeAttribute(e)}}function Loe(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Ioe(e,t,n){var i,s=n+"",r;return function(){var o=this.getAttribute(e);return o===s?null:o===i?r:r=t(i=o,n)}}function Poe(e,t,n){var i,s=n+"",r;return function(){var o=this.getAttributeNS(e.space,e.local);return o===s?null:o===i?r:r=t(i=o,n)}}function zoe(e,t,n){var i,s,r;return function(){var o,c=n(this),u;return c==null?void this.removeAttribute(e):(o=this.getAttribute(e),u=c+"",o===u?null:o===i&&u===s?r:(s=u,r=t(i=o,c)))}}function Boe(e,t,n){var i,s,r;return function(){var o,c=n(this),u;return c==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),u=c+"",o===u?null:o===i&&u===s?r:(s=u,r=t(i=o,c)))}}function Uoe(e,t){var n=dg(e),i=n==="transform"?xoe:II;return this.attrTween(e,typeof t=="function"?(n.local?Boe:zoe)(n,i,Tw(this,"attr."+e,t)):t==null?(n.local?Loe:Ooe)(n):(n.local?Poe:Ioe)(n,i,t))}function Foe(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function $oe(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function qoe(e,t){var n,i;function s(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&$oe(e,r)),n}return s._value=t,s}function Hoe(e,t){var n,i;function s(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&Foe(e,r)),n}return s._value=t,s}function Voe(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 i=dg(e);return this.tween(n,(i.local?qoe:Hoe)(i,t))}function Koe(e,t){return function(){jw(this,e).delay=+t.apply(this,arguments)}}function Goe(e,t){return t=+t,function(){jw(this,e).delay=t}}function Woe(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Koe:Goe)(t,e)):sr(this.node(),t).delay}function Yoe(e,t){return function(){Ar(this,e).duration=+t.apply(this,arguments)}}function Xoe(e,t){return t=+t,function(){Ar(this,e).duration=t}}function Qoe(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Yoe:Xoe)(t,e)):sr(this.node(),t).duration}function Zoe(e,t){if(typeof t!="function")throw new Error;return function(){Ar(this,e).ease=t}}function Joe(e){var t=this._id;return arguments.length?this.each(Zoe(t,e)):sr(this.node(),t).ease}function ele(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ar(this,e).ease=n}}function tle(e){if(typeof e!="function")throw new Error;return this.each(ele(this._id,e))}function nle(e){typeof e!="function"&&(e=hI(e));for(var t=this._groups,n=t.length,i=new Array(n),s=0;s<n;++s)for(var r=t[s],o=r.length,c=i[s]=[],u,f=0;f<o;++f)(u=r[f])&&e.call(u,u.__data__,f,r)&&c.push(u);return new fa(i,this._parents,this._name,this._id)}function ile(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,i=t.length,s=n.length,r=Math.min(i,s),o=new Array(i),c=0;c<r;++c)for(var u=t[c],f=n[c],p=u.length,m=o[c]=new Array(p),b,y=0;y<p;++y)(b=u[y]||f[y])&&(m[y]=b);for(;c<i;++c)o[c]=t[c];return new fa(o,this._parents,this._name,this._id)}function sle(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 rle(e,t,n){var i,s,r=sle(t)?jw:Ar;return function(){var o=r(this,e),c=o.on;c!==i&&(s=(i=c).copy()).on(t,n),o.on=s}}function ale(e,t){var n=this._id;return arguments.length<2?sr(this.node(),n).on.on(e):this.each(rle(n,e,t))}function ole(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function lle(){return this.on("end.remove",ole(this._id))}function cle(e){var t=this._name,n=this._id;typeof e!="function"&&(e=kw(e));for(var i=this._groups,s=i.length,r=new Array(s),o=0;o<s;++o)for(var c=i[o],u=c.length,f=r[o]=new Array(u),p,m,b=0;b<u;++b)(p=c[b])&&(m=e.call(p,p.__data__,b,c))&&("__data__"in p&&(m.__data__=p.__data__),f[b]=m,hg(f[b],t,n,b,f,sr(p,n)));return new fa(r,this._parents,t,n)}function ule(e){var t=this._name,n=this._id;typeof e!="function"&&(e=fI(e));for(var i=this._groups,s=i.length,r=[],o=[],c=0;c<s;++c)for(var u=i[c],f=u.length,p,m=0;m<f;++m)if(p=u[m]){for(var b=e.call(p,p.__data__,m,u),y,x=sr(p,n),v=0,w=b.length;v<w;++v)(y=b[v])&&hg(y,t,n,v,b,x);r.push(b),o.push(p)}return new fa(r,o,t,n)}var dle=_f.prototype.constructor;function fle(){return new dle(this._groups,this._parents)}function hle(e,t){var n,i,s;return function(){var r=Vc(this,e),o=(this.style.removeProperty(e),Vc(this,e));return r===o?null:r===n&&o===i?s:s=t(n=r,i=o)}}function PI(e){return function(){this.style.removeProperty(e)}}function ple(e,t,n){var i,s=n+"",r;return function(){var o=Vc(this,e);return o===s?null:o===i?r:r=t(i=o,n)}}function mle(e,t,n){var i,s,r;return function(){var o=Vc(this,e),c=n(this),u=c+"";return c==null&&(u=c=(this.style.removeProperty(e),Vc(this,e))),o===u?null:o===i&&u===s?r:(s=u,r=t(i=o,c))}}function gle(e,t){var n,i,s,r="style."+t,o="end."+r,c;return function(){var u=Ar(this,e),f=u.on,p=u.value[r]==null?c||(c=PI(t)):void 0;(f!==n||s!==p)&&(i=(n=f).copy()).on(o,s=p),u.on=i}}function yle(e,t,n){var i=(e+="")=="transform"?boe:II;return t==null?this.styleTween(e,hle(e,i)).on("end.style."+e,PI(e)):typeof t=="function"?this.styleTween(e,mle(e,i,Tw(this,"style."+e,t))).each(gle(this._id,e)):this.styleTween(e,ple(e,i,t),n).on("end.style."+e,null)}function ble(e,t,n){return function(i){this.style.setProperty(e,t.call(this,i),n)}}function xle(e,t,n){var i,s;function r(){var o=t.apply(this,arguments);return o!==s&&(i=(s=o)&&ble(e,o,n)),i}return r._value=t,r}function vle(e,t,n){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(t==null)return this.tween(i,null);if(typeof t!="function")throw new Error;return this.tween(i,xle(e,t,n??""))}function wle(e){return function(){this.textContent=e}}function Ele(e){return function(){var t=e(this);this.textContent=t??""}}function kle(e){return this.tween("text",typeof e=="function"?Ele(Tw(this,"text",e)):wle(e==null?"":e+""))}function Sle(e){return function(t){this.textContent=e.call(this,t)}}function Nle(e){var t,n;function i(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&Sle(s)),t}return i._value=e,i}function _le(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,Nle(e))}function Cle(){for(var e=this._name,t=this._id,n=zI(),i=this._groups,s=i.length,r=0;r<s;++r)for(var o=i[r],c=o.length,u,f=0;f<c;++f)if(u=o[f]){var p=sr(u,t);hg(u,e,n,f,o,{time:p.time+p.delay+p.duration,delay:0,duration:p.duration,ease:p.ease})}return new fa(i,this._parents,e,n)}function jle(){var e,t,n=this,i=n._id,s=n.size();return new Promise(function(r,o){var c={value:o},u={value:function(){--s===0&&r()}};n.each(function(){var f=Ar(this,i),p=f.on;p!==e&&(t=(e=p).copy(),t._.cancel.push(c),t._.interrupt.push(c),t._.end.push(u)),f.on=t}),s===0&&r()})}var Tle=0;function fa(e,t,n,i){this._groups=e,this._parents=t,this._name=n,this._id=i}function zI(){return++Tle}var Zr=_f.prototype;fa.prototype={constructor:fa,select:cle,selectAll:ule,selectChild:Zr.selectChild,selectChildren:Zr.selectChildren,filter:nle,merge:ile,selection:fle,transition:Cle,call:Zr.call,nodes:Zr.nodes,node:Zr.node,size:Zr.size,empty:Zr.empty,each:Zr.each,on:ale,attr:Uoe,attrTween:Voe,style:yle,styleTween:vle,text:kle,textTween:_le,remove:lle,tween:Doe,delay:Woe,duration:Qoe,ease:Joe,easeVarying:tle,end:jle,[Symbol.iterator]:Zr[Symbol.iterator]};function Ale(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Mle={time:null,delay:0,duration:250,ease:Ale};function Rle(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 Dle(e){var t,n;e instanceof fa?(t=e._id,e=e._name):(t=zI(),(n=Mle).time=Cw(),e=e==null?null:e+"");for(var i=this._groups,s=i.length,r=0;r<s;++r)for(var o=i[r],c=o.length,u,f=0;f<c;++f)(u=o[f])&&hg(u,e,t,f,o,n||Rle(u,t));return new fa(i,this._parents,e,t)}_f.prototype.interrupt=Aoe;_f.prototype.transition=Dle;const yp=e=>()=>e;function Ole(e,{sourceEvent:t,target:n,transform:i,dispatch:s}){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:i,enumerable:!0,configurable:!0},_:{value:s}})}function aa(e,t,n){this.k=e,this.x=t,this.y=n}aa.prototype={constructor:aa,scale:function(e){return e===1?this:new aa(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new aa(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 pg=new aa(1,0,0);BI.prototype=aa.prototype;function BI(e){for(;!e.__zoom;)if(!(e=e.parentNode))return pg;return e.__zoom}function Fx(e){e.stopImmediatePropagation()}function ud(e){e.preventDefault(),e.stopImmediatePropagation()}function Lle(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Ile(){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 Vj(){return this.__zoom||pg}function Ple(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function zle(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ble(e,t,n){var i=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],r=e.invertY(t[0][1])-n[0][1],o=e.invertY(t[1][1])-n[1][1];return e.translate(s>i?(i+s)/2:Math.min(0,i)||Math.max(0,s),o>r?(r+o)/2:Math.min(0,r)||Math.max(0,o))}function UI(){var e=Lle,t=Ile,n=Ble,i=Ple,s=zle,r=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],c=250,u=$p,f=ug("start","zoom","end"),p,m,b,y=500,x=150,v=0,w=10;function k(D){D.property("__zoom",Vj).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",P).on("dblclick.zoom",I).filter(s).on("touchstart.zoom",B).on("touchmove.zoom",F).on("touchend.zoom touchcancel.zoom",V).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}k.transform=function(D,L,z,W){var X=D.selection?D.selection():D;X.property("__zoom",Vj),D!==X?T(D,L,z,W):X.interrupt().each(function(){A(this,arguments).event(W).start().zoom(null,typeof L=="function"?L.apply(this,arguments):L).end()})},k.scaleBy=function(D,L,z,W){k.scaleTo(D,function(){var X=this.__zoom.k,G=typeof L=="function"?L.apply(this,arguments):L;return X*G},z,W)},k.scaleTo=function(D,L,z,W){k.transform(D,function(){var X=t.apply(this,arguments),G=this.__zoom,U=z==null?j(X):typeof z=="function"?z.apply(this,arguments):z,q=G.invert(U),Y=typeof L=="function"?L.apply(this,arguments):L;return n(S(C(G,Y),U,q),X,o)},z,W)},k.translateBy=function(D,L,z,W){k.transform(D,function(){return n(this.__zoom.translate(typeof L=="function"?L.apply(this,arguments):L,typeof z=="function"?z.apply(this,arguments):z),t.apply(this,arguments),o)},null,W)},k.translateTo=function(D,L,z,W,X){k.transform(D,function(){var G=t.apply(this,arguments),U=this.__zoom,q=W==null?j(G):typeof W=="function"?W.apply(this,arguments):W;return n(pg.translate(q[0],q[1]).scale(U.k).translate(typeof L=="function"?-L.apply(this,arguments):-L,typeof z=="function"?-z.apply(this,arguments):-z),G,o)},W,X)};function C(D,L){return L=Math.max(r[0],Math.min(r[1],L)),L===D.k?D:new aa(L,D.x,D.y)}function S(D,L,z){var W=L[0]-z[0]*D.k,X=L[1]-z[1]*D.k;return W===D.x&&X===D.y?D:new aa(D.k,W,X)}function j(D){return[(+D[0][0]+ +D[1][0])/2,(+D[0][1]+ +D[1][1])/2]}function T(D,L,z,W){D.on("start.zoom",function(){A(this,arguments).event(W).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(W).end()}).tween("zoom",function(){var X=this,G=arguments,U=A(X,G).event(W),q=t.apply(X,G),Y=z==null?j(q):typeof z=="function"?z.apply(X,G):z,$=Math.max(q[1][0]-q[0][0],q[1][1]-q[0][1]),ie=X.__zoom,be=typeof L=="function"?L.apply(X,G):L,ce=u(ie.invert(Y).concat($/ie.k),be.invert(Y).concat($/be.k));return function(_e){if(_e===1)_e=be;else{var le=ce(_e),pe=$/le[2];_e=new aa(pe,Y[0]-le[0]*pe,Y[1]-le[1]*pe)}U.zoom(null,_e)}})}function A(D,L,z){return!z&&D.__zooming||new M(D,L)}function M(D,L){this.that=D,this.args=L,this.active=0,this.sourceEvent=null,this.extent=t.apply(D,L),this.taps=0}M.prototype={event:function(D){return D&&(this.sourceEvent=D),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(D,L){return this.mouse&&D!=="mouse"&&(this.mouse[1]=L.invert(this.mouse[0])),this.touch0&&D!=="touch"&&(this.touch0[1]=L.invert(this.touch0[0])),this.touch1&&D!=="touch"&&(this.touch1[1]=L.invert(this.touch1[0])),this.that.__zoom=L,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(D){var L=ss(this.that).datum();f.call(D,this.that,new Ole(D,{sourceEvent:this.sourceEvent,target:k,transform:this.that.__zoom,dispatch:f}),L)}};function R(D,...L){if(!e.apply(this,arguments))return;var z=A(this,L).event(D),W=this.__zoom,X=Math.max(r[0],Math.min(r[1],W.k*Math.pow(2,i.apply(this,arguments)))),G=Gs(D);if(z.wheel)(z.mouse[0][0]!==G[0]||z.mouse[0][1]!==G[1])&&(z.mouse[1]=W.invert(z.mouse[0]=G)),clearTimeout(z.wheel);else{if(W.k===X)return;z.mouse=[G,W.invert(G)],Vp(this),z.start()}ud(D),z.wheel=setTimeout(U,x),z.zoom("mouse",n(S(C(W,X),z.mouse[0],z.mouse[1]),z.extent,o));function U(){z.wheel=null,z.end()}}function P(D,...L){if(b||!e.apply(this,arguments))return;var z=D.currentTarget,W=A(this,L,!0).event(D),X=ss(D.view).on("mousemove.zoom",Y,!0).on("mouseup.zoom",$,!0),G=Gs(D,z),U=D.clientX,q=D.clientY;kI(D.view),Fx(D),W.mouse=[G,this.__zoom.invert(G)],Vp(this),W.start();function Y(ie){if(ud(ie),!W.moved){var be=ie.clientX-U,ce=ie.clientY-q;W.moved=be*be+ce*ce>v}W.event(ie).zoom("mouse",n(S(W.that.__zoom,W.mouse[0]=Gs(ie,z),W.mouse[1]),W.extent,o))}function $(ie){X.on("mousemove.zoom mouseup.zoom",null),SI(ie.view,W.moved),ud(ie),W.event(ie).end()}}function I(D,...L){if(e.apply(this,arguments)){var z=this.__zoom,W=Gs(D.changedTouches?D.changedTouches[0]:D,this),X=z.invert(W),G=z.k*(D.shiftKey?.5:2),U=n(S(C(z,G),W,X),t.apply(this,L),o);ud(D),c>0?ss(this).transition().duration(c).call(T,U,W,D):ss(this).call(k.transform,U,W,D)}}function B(D,...L){if(e.apply(this,arguments)){var z=D.touches,W=z.length,X=A(this,L,D.changedTouches.length===W).event(D),G,U,q,Y;for(Fx(D),U=0;U<W;++U)q=z[U],Y=Gs(q,this),Y=[Y,this.__zoom.invert(Y),q.identifier],X.touch0?!X.touch1&&X.touch0[2]!==Y[2]&&(X.touch1=Y,X.taps=0):(X.touch0=Y,G=!0,X.taps=1+!!p);p&&(p=clearTimeout(p)),G&&(X.taps<2&&(m=Y[0],p=setTimeout(function(){p=null},y)),Vp(this),X.start())}}function F(D,...L){if(this.__zooming){var z=A(this,L).event(D),W=D.changedTouches,X=W.length,G,U,q,Y;for(ud(D),G=0;G<X;++G)U=W[G],q=Gs(U,this),z.touch0&&z.touch0[2]===U.identifier?z.touch0[0]=q:z.touch1&&z.touch1[2]===U.identifier&&(z.touch1[0]=q);if(U=z.that.__zoom,z.touch1){var $=z.touch0[0],ie=z.touch0[1],be=z.touch1[0],ce=z.touch1[1],_e=(_e=be[0]-$[0])*_e+(_e=be[1]-$[1])*_e,le=(le=ce[0]-ie[0])*le+(le=ce[1]-ie[1])*le;U=C(U,Math.sqrt(_e/le)),q=[($[0]+be[0])/2,($[1]+be[1])/2],Y=[(ie[0]+ce[0])/2,(ie[1]+ce[1])/2]}else if(z.touch0)q=z.touch0[0],Y=z.touch0[1];else return;z.zoom("touch",n(S(U,q,Y),z.extent,o))}}function V(D,...L){if(this.__zooming){var z=A(this,L).event(D),W=D.changedTouches,X=W.length,G,U;for(Fx(D),b&&clearTimeout(b),b=setTimeout(function(){b=null},y),G=0;G<X;++G)U=W[G],z.touch0&&z.touch0[2]===U.identifier?delete z.touch0:z.touch1&&z.touch1[2]===U.identifier&&delete z.touch1;if(z.touch1&&!z.touch0&&(z.touch0=z.touch1,delete z.touch1),z.touch0)z.touch0[1]=this.__zoom.invert(z.touch0[0]);else if(z.end(),z.taps===2&&(U=Gs(U,this),Math.hypot(m[0]-U[0],m[1]-U[1])<w)){var q=ss(this).on("dblclick.zoom");q&&q.apply(this,arguments)}}}return k.wheelDelta=function(D){return arguments.length?(i=typeof D=="function"?D:yp(+D),k):i},k.filter=function(D){return arguments.length?(e=typeof D=="function"?D:yp(!!D),k):e},k.touchable=function(D){return arguments.length?(s=typeof D=="function"?D:yp(!!D),k):s},k.extent=function(D){return arguments.length?(t=typeof D=="function"?D:yp([[+D[0][0],+D[0][1]],[+D[1][0],+D[1][1]]]),k):t},k.scaleExtent=function(D){return arguments.length?(r[0]=+D[0],r[1]=+D[1],k):[r[0],r[1]]},k.translateExtent=function(D){return arguments.length?(o[0][0]=+D[0][0],o[1][0]=+D[1][0],o[0][1]=+D[0][1],o[1][1]=+D[1][1],k):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},k.constrain=function(D){return arguments.length?(n=D,k):n},k.duration=function(D){return arguments.length?(c=+D,k):c},k.interpolate=function(D){return arguments.length?(u=D,k):u},k.on=function(){var D=f.on.apply(f,arguments);return D===f?k:D},k.clickDistance=function(D){return arguments.length?(v=(D=+D)*D,k):Math.sqrt(v)},k.tapDistance=function(D){return arguments.length?(w=+D,k):w},k}const ls={error001:(e="react")=>`Seems like you have not used ${e==="svelte"?"SvelteFlowProvider":"ReactFlowProvider"} as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:i})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:i}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.",error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},Xd=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],FI=["Enter"," ","Escape"],$I={"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 Gc;(function(e){e.Strict="strict",e.Loose="loose"})(Gc||(Gc={}));var ol;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(ol||(ol={}));var Qd;(function(e){e.Partial="partial",e.Full="full"})(Qd||(Qd={}));const qI={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Va;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Va||(Va={}));var Tm;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Tm||(Tm={}));var tt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(tt||(tt={}));const Kj={[tt.Left]:tt.Right,[tt.Right]:tt.Left,[tt.Top]:tt.Bottom,[tt.Bottom]:tt.Top};function HI(e){return e===null?null:e?"valid":"invalid"}const VI=e=>"id"in e&&"source"in e&&"target"in e,Ule=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Aw=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),jf=(e,t=[0,0])=>{const{width:n,height:i}=pa(e),s=e.origin??t,r=n*s[0],o=i*s[1];return{x:e.position.x-r,y:e.position.y-o}},Fle=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((i,s)=>{const r=typeof s=="string";let o=!t.nodeLookup&&!r?s:void 0;t.nodeLookup&&(o=r?t.nodeLookup.get(s):Aw(s)?s:t.nodeLookup.get(s.id));const c=o?Am(o,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return mg(i,c)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return gg(n)},Tf=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},i=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=mg(n,Am(s)),i=!0)}),i?gg(n):{x:0,y:0,width:0,height:0}},Mw=(e,t,[n,i,s]=[0,0,1],r=!1,o=!1)=>{const c=(t.x-n)/s,u=(t.y-i)/s,f=t.width/s,p=t.height/s,m=[];for(const b of e.values()){const{measured:y,selectable:x=!0,hidden:v=!1}=b;if(o&&!x||v)continue;const w=y.width??b.width??b.initialWidth??0,k=y.height??b.height??b.initialHeight??0,{x:C,y:S}=b.internals.positionAbsolute,j=YI(c,u,f,p,C,S,w,k),T=w*k,A=r&&j>0;(!b.internals.handleBounds||A||j>=T||b.dragging)&&m.push(b)}return m},$le=(e,t)=>{const n=new Set;return e.forEach(i=>{n.add(i.id)}),t.filter(i=>n.has(i.source)||n.has(i.target))};function qle(e,t){const n=new Map,i=t!=null&&t.nodes?new Set(t.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&((t==null?void 0:t.includeHiddenNodes)||!s.hidden)&&(!i||i.has(s.id))&&n.set(s.id,s)}),n}async function Hle({nodes:e,width:t,height:n,panZoom:i,minZoom:s,maxZoom:r},o){if(e.size===0)return!0;const c=qle(e,o),u=Tf(c),f=Dw(u,t,n,(o==null?void 0:o.minZoom)??s,(o==null?void 0:o.maxZoom)??r,(o==null?void 0:o.padding)??.1);return await i.setViewport(f,{duration:o==null?void 0:o.duration,ease:o==null?void 0:o.ease,interpolate:o==null?void 0:o.interpolate}),!0}function KI({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:i=[0,0],nodeExtent:s,onError:r}){const o=n.get(e),c=o.parentId?n.get(o.parentId):void 0,{x:u,y:f}=c?c.internals.positionAbsolute:{x:0,y:0},p=o.origin??i;let m=o.extent||s;if(o.extent==="parent"&&!o.expandParent)if(!c)r==null||r("005",ls.error005());else{const y=c.measured.width,x=c.measured.height;y&&x&&(m=[[u,f],[u+y,f+x]])}else c&&gl(o.extent)&&(m=[[o.extent[0][0]+u,o.extent[0][1]+f],[o.extent[1][0]+u,o.extent[1][1]+f]]);const b=gl(m)?ml(t,m,o.measured):t;return(o.measured.width===void 0||o.measured.height===void 0)&&(r==null||r("015",ls.error015())),{position:{x:b.x-u+(o.measured.width??0)*p[0],y:b.y-f+(o.measured.height??0)*p[1]},positionAbsolute:b}}async function Vle({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:i,onBeforeDelete:s}){const r=new Set(e.map(b=>b.id)),o=[];for(const b of n){if(b.deletable===!1)continue;const y=r.has(b.id),x=!y&&b.parentId&&o.find(v=>v.id===b.parentId);(y||x)&&o.push(b)}const c=new Set(t.map(b=>b.id)),u=i.filter(b=>b.deletable!==!1),p=$le(o,u);for(const b of u)c.has(b.id)&&!p.find(x=>x.id===b.id)&&p.push(b);if(!s)return{edges:p,nodes:o};const m=await s({nodes:o,edges:p});return typeof m=="boolean"?m?{edges:p,nodes:o}:{edges:[],nodes:[]}:m}const Wc=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),ml=(e={x:0,y:0},t,n)=>({x:Wc(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:Wc(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function GI(e,t,n){const{width:i,height:s}=pa(n),{x:r,y:o}=n.internals.positionAbsolute;return ml(e,[[r,o],[r+i,o+s]],t)}const Gj=(e,t,n)=>e<t?Wc(Math.abs(e-t),1,t)/t:e>n?-Wc(Math.abs(e-n),1,t)/t:0,Rw=(e,t,n=15,i=40)=>{const s=Gj(e.x,i,t.width-i)*n,r=Gj(e.y,i,t.height-i)*n;return[s,r]},mg=(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)}),A0=({x:e,y:t,width:n,height:i})=>({x:e,y:t,x2:e+n,y2:t+i}),gg=({x:e,y:t,x2:n,y2:i})=>({x:e,y:t,width:n-e,height:i-t}),Zd=(e,t=[0,0])=>{var s,r;const{x:n,y:i}=Aw(e)?e.internals.positionAbsolute:jf(e,t);return{x:n,y:i,width:((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0,height:((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0}},Am=(e,t=[0,0])=>{var s,r;const{x:n,y:i}=Aw(e)?e.internals.positionAbsolute:jf(e,t);return{x:n,y:i,x2:n+(((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0),y2:i+(((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0)}},WI=(e,t)=>gg(mg(A0(e),A0(t))),YI=(e,t,n,i,s,r,o,c)=>{const u=Math.max(0,Math.min(e+n,s+o)-Math.max(e,s)),f=Math.max(0,Math.min(t+i,r+c)-Math.max(t,r));return Math.ceil(u*f)},Mm=(e,t)=>YI(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),Wj=e=>Xs(e.width)&&Xs(e.height)&&Xs(e.x)&&Xs(e.y),Xs=e=>!isNaN(e)&&isFinite(e),XI=(e,t)=>(n,i)=>{},Af=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Mf=({x:e,y:t},[n,i,s],r=!1,o=[1,1])=>{const c={x:(e-n)/s,y:(t-i)/s};return r?Af(c,o):c},Yc=({x:e,y:t},[n,i,s])=>({x:e*s+n,y:t*s+i});function rc(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(`The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function Kle(e,t,n){if(typeof e=="string"||typeof e=="number"){const i=rc(e,n),s=rc(e,t);return{top:i,right:s,bottom:i,left:s,x:s*2,y:i*2}}if(typeof e=="object"){const i=rc(e.top??e.y??0,n),s=rc(e.bottom??e.y??0,n),r=rc(e.left??e.x??0,t),o=rc(e.right??e.x??0,t);return{top:i,right:o,bottom:s,left:r,x:r+o,y:i+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function Gle(e,t,n,i,s,r){const{x:o,y:c}=Yc(e,[t,n,i]),{x:u,y:f}=Yc({x:e.x+e.width,y:e.y+e.height},[t,n,i]),p=s-u,m=r-f;return{left:Math.floor(o),top:Math.floor(c),right:Math.floor(p),bottom:Math.floor(m)}}const Dw=(e,t,n,i,s,r)=>{const o=Kle(r,t,n),c=(t-o.x)/e.width,u=(n-o.y)/e.height,f=Math.min(c,u),p=Wc(f,i,s),m=e.x+e.width/2,b=e.y+e.height/2,y=t/2-m*p,x=n/2-b*p,v=Gle(e,y,x,p,t,n),w={left:Math.min(v.left-o.left,0),top:Math.min(v.top-o.top,0),right:Math.min(v.right-o.right,0),bottom:Math.min(v.bottom-o.bottom,0)};return{x:y-w.left+w.right,y:x-w.top+w.bottom,zoom:p}},Jd=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function gl(e){return e!=null&&e!=="parent"}function pa(e){var t,n;return{width:((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth??0,height:((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight??0}}function QI(e){var t,n;return(((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth)!==void 0&&(((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight)!==void 0}function ZI(e,t={width:0,height:0},n,i,s){const r={...e},o=i.get(n);if(o){const c=o.origin||s;r.x+=o.internals.positionAbsolute.x-(t.width??0)*c[0],r.y+=o.internals.positionAbsolute.y-(t.height??0)*c[1]}return r}function Yj(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Wle(){let e,t;return{promise:new Promise((i,s)=>{e=i,t=s}),resolve:e,reject:t}}function Yle(e){return{...$I,...e||{}}}function Ad(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:i,containerBounds:s}){const{x:r,y:o}=Qs(e),c=Mf({x:r-((s==null?void 0:s.left)??0),y:o-((s==null?void 0:s.top)??0)},i),{x:u,y:f}=n?Af(c,t):c;return{xSnapped:u,ySnapped:f,...c}}const Ow=e=>({width:e.offsetWidth,height:e.offsetHeight}),JI=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},Xle=["INPUT","SELECT","TEXTAREA"];function eP(e){var i,s;const t=((s=(i=e.composedPath)==null?void 0:i.call(e))==null?void 0:s[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:Xle.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const tP=e=>"clientX"in e,Qs=(e,t)=>{var r,o;const n=tP(e),i=n?e.clientX:(r=e.touches)==null?void 0:r[0].clientX,s=n?e.clientY:(o=e.touches)==null?void 0:o[0].clientY;return{x:i-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Xj=(e,t,n,i,s)=>{const r=t.querySelectorAll(`.${e}`);return!r||!r.length?null:Array.from(r).map(o=>{const c=o.getBoundingClientRect();return{id:o.getAttribute("data-handleid"),type:e,nodeId:s,position:o.getAttribute("data-handlepos"),x:(c.left-n.left)/i,y:(c.top-n.top)/i,...Ow(o)}})};function nP({sourceX:e,sourceY:t,targetX:n,targetY:i,sourceControlX:s,sourceControlY:r,targetControlX:o,targetControlY:c}){const u=e*.125+s*.375+o*.375+n*.125,f=t*.125+r*.375+c*.375+i*.125,p=Math.abs(u-e),m=Math.abs(f-t);return[u,f,p,m]}function bp(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Qj({pos:e,x1:t,y1:n,x2:i,y2:s,c:r}){switch(e){case tt.Left:return[t-bp(t-i,r),n];case tt.Right:return[t+bp(i-t,r),n];case tt.Top:return[t,n-bp(n-s,r)];case tt.Bottom:return[t,n+bp(s-n,r)]}}function iP({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top,curvature:o=.25}){const[c,u]=Qj({pos:n,x1:e,y1:t,x2:i,y2:s,c:o}),[f,p]=Qj({pos:r,x1:i,y1:s,x2:e,y2:t,c:o}),[m,b,y,x]=nP({sourceX:e,sourceY:t,targetX:i,targetY:s,sourceControlX:c,sourceControlY:u,targetControlX:f,targetControlY:p});return[`M${e},${t} C${c},${u} ${f},${p} ${i},${s}`,m,b,y,x]}function sP({sourceX:e,sourceY:t,targetX:n,targetY:i}){const s=Math.abs(n-e)/2,r=n<e?n+s:n-s,o=Math.abs(i-t)/2,c=i<t?i+o:i-o;return[r,c,s,o]}function Qle({sourceNode:e,targetNode:t,selected:n=!1,zIndex:i=0,elevateOnSelect:s=!1,zIndexMode:r="basic"}){if(r==="manual")return i;const o=s&&n?i+1e3:i,c=Math.max(e.parentId||s&&e.selected?e.internals.z:0,t.parentId||s&&t.selected?t.internals.z:0);return o+c}function Zle({sourceNode:e,targetNode:t,width:n,height:i,transform:s}){const r=mg(Am(e),Am(t));r.x===r.x2&&(r.x2+=1),r.y===r.y2&&(r.y2+=1);const o={x:-s[0]/s[2],y:-s[1]/s[2],width:n/s[2],height:i/s[2]};return Mm(o,gg(r))>0}const rP=({source:e,sourceHandle:t,target:n,targetHandle:i})=>`xy-edge__${e}${t||""}-${n}${i||""}`,Jle=(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)),ece=(e,t,n={})=>{var r;if(!e.source||!e.target)return(r=n.onError)==null||r.call(n,"006",ls.error006()),t;const i=n.getEdgeId||rP;let s;return VI(e)?s={...e}:s={...e,id:i(e)},Jle(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))},tce=(e,t,n,i={shouldReplaceId:!0})=>{var f,p;const{id:s,...r}=e;if(!t.source||!t.target)return(f=i.onError)==null||f.call(i,"006",ls.error006()),n;if(!n.find(m=>m.id===e.id))return(p=i.onError)==null||p.call(i,"007",ls.error007(s)),n;const c=i.getEdgeId||rP,u={...r,id:i.shouldReplaceId?c(t):s,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle};return n.filter(m=>m.id!==s).concat(u)};function aP({sourceX:e,sourceY:t,targetX:n,targetY:i}){const[s,r,o,c]=sP({sourceX:e,sourceY:t,targetX:n,targetY:i});return[`M ${e},${t}L ${n},${i}`,s,r,o,c]}const Zj={[tt.Left]:{x:-1,y:0},[tt.Right]:{x:1,y:0},[tt.Top]:{x:0,y:-1},[tt.Bottom]:{x:0,y:1}},nce=({source:e,sourcePosition:t=tt.Bottom,target:n})=>t===tt.Left||t===tt.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},Jj=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function ice({source:e,sourcePosition:t=tt.Bottom,target:n,targetPosition:i=tt.Top,center:s,offset:r,stepPosition:o}){const c=Zj[t],u=Zj[i],f={x:e.x+c.x*r,y:e.y+c.y*r},p={x:n.x+u.x*r,y:n.y+u.y*r},m=nce({source:f,sourcePosition:t,target:p}),b=m.x!==0?"x":"y",y=m[b];let x=[],v,w;const k={x:0,y:0},C={x:0,y:0},[,,S,j]=sP({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(c[b]*u[b]===-1){b==="x"?(v=s.x??f.x+(p.x-f.x)*o,w=s.y??(f.y+p.y)/2):(v=s.x??(f.x+p.x)/2,w=s.y??f.y+(p.y-f.y)*o);const R=[{x:v,y:f.y},{x:v,y:p.y}],P=[{x:f.x,y:w},{x:p.x,y:w}];c[b]===y?x=b==="x"?R:P:x=b==="x"?P:R}else{const R=[{x:f.x,y:p.y}],P=[{x:p.x,y:f.y}];if(b==="x"?x=c.x===y?P:R:x=c.y===y?R:P,t===i){const D=Math.abs(e[b]-n[b]);if(D<=r){const L=Math.min(r-1,r-D);c[b]===y?k[b]=(f[b]>e[b]?-1:1)*L:C[b]=(p[b]>n[b]?-1:1)*L}}if(t!==i){const D=b==="x"?"y":"x",L=c[b]===u[D],z=f[D]>p[D],W=f[D]<p[D];(c[b]===1&&(!L&&z||L&&W)||c[b]!==1&&(!L&&W||L&&z))&&(x=b==="x"?R:P)}const I={x:f.x+k.x,y:f.y+k.y},B={x:p.x+C.x,y:p.y+C.y},F=Math.max(Math.abs(I.x-x[0].x),Math.abs(B.x-x[0].x)),V=Math.max(Math.abs(I.y-x[0].y),Math.abs(B.y-x[0].y));F>=V?(v=(I.x+B.x)/2,w=x[0].y):(v=x[0].x,w=(I.y+B.y)/2)}const T={x:f.x+k.x,y:f.y+k.y},A={x:p.x+C.x,y:p.y+C.y};return[[e,...T.x!==x[0].x||T.y!==x[0].y?[T]:[],...x,...A.x!==x[x.length-1].x||A.y!==x[x.length-1].y?[A]:[],n],v,w,S,j]}function sce(e,t,n,i){const s=Math.min(Jj(e,t)/2,Jj(t,n)/2,i),{x:r,y:o}=t;if(e.x===r&&r===n.x||e.y===o&&o===n.y)return`L${r} ${o}`;if(e.y===o){const f=e.x<n.x?-1:1,p=e.y<n.y?1:-1;return`L ${r+s*f},${o}Q ${r},${o} ${r},${o+s*p}`}const c=e.x<n.x?1:-1,u=e.y<n.y?-1:1;return`L ${r},${o+s*u}Q ${r},${o} ${r+s*c},${o}`}function M0({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top,borderRadius:o=5,centerX:c,centerY:u,offset:f=20,stepPosition:p=.5}){const[m,b,y,x,v]=ice({source:{x:e,y:t},sourcePosition:n,target:{x:i,y:s},targetPosition:r,center:{x:c,y:u},offset:f,stepPosition:p});let w=`M${m[0].x} ${m[0].y}`;for(let k=1;k<m.length-1;k++)w+=sce(m[k-1],m[k],m[k+1],o);return w+=`L${m[m.length-1].x} ${m[m.length-1].y}`,[w,b,y,x,v]}function eT(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function rce(e){var m;const{sourceNode:t,targetNode:n}=e;if(!eT(t)||!eT(n))return null;const i=t.internals.handleBounds||tT(t.handles),s=n.internals.handleBounds||tT(n.handles),r=nT((i==null?void 0:i.source)??[],e.sourceHandle),o=nT(e.connectionMode===Gc.Strict?(s==null?void 0:s.target)??[]:((s==null?void 0:s.target)??[]).concat((s==null?void 0:s.source)??[]),e.targetHandle);if(!r||!o)return(m=e.onError)==null||m.call(e,"008",ls.error008(r?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const c=(r==null?void 0:r.position)||tt.Bottom,u=(o==null?void 0:o.position)||tt.Top,f=yl(t,r,c),p=yl(n,o,u);return{sourceX:f.x,sourceY:f.y,targetX:p.x,targetY:p.y,sourcePosition:c,targetPosition:u}}function tT(e){if(!e)return null;const t=[],n=[];for(const i of e)i.width=i.width??1,i.height=i.height??1,i.type==="source"?t.push(i):i.type==="target"&&n.push(i);return{source:t,target:n}}function yl(e,t,n=tt.Left,i=!1){const s=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,r=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:o,height:c}=t??pa(e);if(i)return{x:s+o/2,y:r+c/2};switch((t==null?void 0:t.position)??n){case tt.Top:return{x:s+o/2,y:r};case tt.Right:return{x:s+o,y:r+c/2};case tt.Bottom:return{x:s+o/2,y:r+c};case tt.Left:return{x:s,y:r+c/2}}}function nT(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function R0(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(i=>`${i}=${e[i]}`).join("&")}`:""}function ace(e,{id:t,defaultColor:n,defaultMarkerStart:i,defaultMarkerEnd:s}){const r=new Set;return e.reduce((o,c)=>([c.markerStart||i,c.markerEnd||s].forEach(u=>{if(u&&typeof u=="object"){const f=R0(u,t);r.has(f)||(o.push({id:f,color:u.color||n,...u}),r.add(f))}}),o),[]).sort((o,c)=>o.id.localeCompare(c.id))}const oP=1e3,oce=10,Lw={nodeOrigin:[0,0],nodeExtent:Xd,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},lce={...Lw,checkEquality:!0};function Iw(e,t){const n={...e};for(const i in t)t[i]!==void 0&&(n[i]=t[i]);return n}function cce(e,t,n){const i=Iw(Lw,n);for(const s of e.values())if(s.parentId)zw(s,e,t,i);else{const r=jf(s,i.nodeOrigin),o=gl(s.extent)?s.extent:i.nodeExtent,c=ml(r,o,pa(s));s.internals.positionAbsolute=c}}function uce(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],i=[];for(const s of e.handles){const r={id:s.id,width:s.width??1,height:s.height??1,nodeId:e.id,x:s.x,y:s.y,position:s.position,type:s.type};s.type==="source"?n.push(r):s.type==="target"&&i.push(r)}return{source:n,target:i}}function Pw(e){return e==="manual"}function D0(e,t,n,i={}){var p,m;const s=Iw(lce,i),r={i:0},o=new Map(t),c=s!=null&&s.elevateNodesOnSelect&&!Pw(s.zIndexMode)?oP:0;let u=e.length>0,f=!1;t.clear(),n.clear();for(const b of e){let y=o.get(b.id);if(s.checkEquality&&b===(y==null?void 0:y.internals.userNode))t.set(b.id,y);else{const x=jf(b,s.nodeOrigin),v=gl(b.extent)?b.extent:s.nodeExtent,w=ml(x,v,pa(b));y={...s.defaults,...b,measured:{width:(p=b.measured)==null?void 0:p.width,height:(m=b.measured)==null?void 0:m.height},internals:{positionAbsolute:w,handleBounds:uce(b,y),z:lP(b,c,s.zIndexMode),userNode:b}},t.set(b.id,y)}(y.measured===void 0||y.measured.width===void 0||y.measured.height===void 0)&&!y.hidden&&(u=!1),b.parentId&&zw(y,t,n,i,r),f||(f=b.selected??!1)}return{nodesInitialized:u,hasSelectedNodes:f}}function dce(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 zw(e,t,n,i,s){const{elevateNodesOnSelect:r,nodeOrigin:o,nodeExtent:c,zIndexMode:u}=Iw(Lw,i),f=e.parentId,p=t.get(f);if(!p){console.warn(`Parent node ${f} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}dce(e,n),s&&!p.parentId&&p.internals.rootParentIndex===void 0&&u==="auto"&&(p.internals.rootParentIndex=++s.i,p.internals.z=p.internals.z+s.i*oce),s&&p.internals.rootParentIndex!==void 0&&(s.i=p.internals.rootParentIndex);const m=r&&!Pw(u)?oP:0,{x:b,y,z:x}=fce(e,p,o,c,m,u),{positionAbsolute:v}=e.internals,w=b!==v.x||y!==v.y;(w||x!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:b,y}:v,z:x}})}function lP(e,t,n){const i=Xs(e.zIndex)?e.zIndex:0;return Pw(n)?i:i+(e.selected?t:0)}function fce(e,t,n,i,s,r){const{x:o,y:c}=t.internals.positionAbsolute,u=pa(e),f=jf(e,n),p=gl(e.extent)?ml(f,e.extent,u):f;let m=ml({x:o+p.x,y:c+p.y},i,u);e.extent==="parent"&&(m=GI(m,u,t));const b=lP(e,s,r),y=t.internals.z??0;return{x:m.x,y:m.y,z:y>=b?y+1:b}}function Bw(e,t,n,i=[0,0]){var o;const s=[],r=new Map;for(const c of e){const u=t.get(c.parentId);if(!u)continue;const f=((o=r.get(c.parentId))==null?void 0:o.expandedRect)??Zd(u),p=WI(f,c.rect);r.set(c.parentId,{expandedRect:p,parent:u})}return r.size>0&&r.forEach(({expandedRect:c,parent:u},f)=>{var S;const p=u.internals.positionAbsolute,m=pa(u),b=u.origin??i,y=c.x<p.x?Math.round(Math.abs(p.x-c.x)):0,x=c.y<p.y?Math.round(Math.abs(p.y-c.y)):0,v=Math.max(m.width,Math.round(c.width)),w=Math.max(m.height,Math.round(c.height)),k=(v-m.width)*b[0],C=(w-m.height)*b[1];(y>0||x>0||k||C)&&(s.push({id:f,type:"position",position:{x:u.position.x-y+k,y:u.position.y-x+C}}),(S=n.get(f))==null||S.forEach(j=>{e.some(T=>T.id===j.id)||s.push({id:j.id,type:"position",position:{x:j.position.x+y,y:j.position.y+x}})})),(m.width<c.width||m.height<c.height||y||x)&&s.push({id:f,type:"dimensions",setAttributes:!0,dimensions:{width:v+(y?b[0]*y-k:0),height:w+(x?b[1]*x-C:0)}})}),s}function hce(e,t,n,i,s,r,o){const c=i==null?void 0:i.querySelector(".xyflow__viewport");let u=!1;if(!c)return{changes:[],updatedInternals:u};const f=[],p=window.getComputedStyle(c),{m22:m}=new window.DOMMatrixReadOnly(p.transform),b=[];for(const y of e.values()){const x=t.get(y.id);if(!x)continue;if(x.hidden){t.set(x.id,{...x,internals:{...x.internals,handleBounds:void 0}}),u=!0;continue}const v=Ow(y.nodeElement),w=x.measured.width!==v.width||x.measured.height!==v.height;if(!!(v.width&&v.height&&(w||!x.internals.handleBounds||y.force))){const C=y.nodeElement.getBoundingClientRect(),S=gl(x.extent)?x.extent:r;let{positionAbsolute:j}=x.internals;x.parentId&&x.extent==="parent"?j=GI(j,v,t.get(x.parentId)):S&&(j=ml(j,S,v));const T={...x,measured:v,internals:{...x.internals,positionAbsolute:j,handleBounds:{source:Xj("source",y.nodeElement,C,m,x.id),target:Xj("target",y.nodeElement,C,m,x.id)}}};t.set(x.id,T),x.parentId&&zw(T,t,n,{nodeOrigin:s,zIndexMode:o}),u=!0,w&&(f.push({id:x.id,type:"dimensions",dimensions:v}),x.expandParent&&x.parentId&&b.push({id:x.id,parentId:x.parentId,rect:Zd(T,s)}))}}if(b.length>0){const y=Bw(b,t,n,s);f.push(...y)}return{changes:f,updatedInternals:u}}async function pce({delta:e,panZoom:t,transform:n,translateExtent:i,width:s,height:r}){if(!t||!e.x&&!e.y)return!1;const o=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[s,r]],i);return!!o&&(o.x!==n[0]||o.y!==n[1]||o.k!==n[2])}function iT(e,t,n,i,s,r){let o=s;const c=i.get(o)||new Map;i.set(o,c.set(n,t)),o=`${s}-${e}`;const u=i.get(o)||new Map;if(i.set(o,u.set(n,t)),r){o=`${s}-${e}-${r}`;const f=i.get(o)||new Map;i.set(o,f.set(n,t))}}function cP(e,t,n){e.clear(),t.clear();for(const i of n){const{source:s,target:r,sourceHandle:o=null,targetHandle:c=null}=i,u={edgeId:i.id,source:s,target:r,sourceHandle:o,targetHandle:c},f=`${s}-${o}--${r}-${c}`,p=`${r}-${c}--${s}-${o}`;iT("source",u,p,e,s,o),iT("target",u,f,e,r,c),t.set(i.id,i)}}function uP(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:uP(n,t):!1}function sT(e,t,n){var s;let i=e;do{if((s=i==null?void 0:i.matches)!=null&&s.call(i,t))return!0;if(i===n)return!1;i=i==null?void 0:i.parentElement}while(i);return!1}function mce(e,t,n,i){const s=new Map;for(const[r,o]of e)if((o.selected||o.id===i)&&(!o.parentId||!uP(o,e))&&(o.draggable||t&&typeof o.draggable>"u")){const c=e.get(r);c&&s.set(r,{id:r,position:c.position||{x:0,y:0},distance:{x:n.x-c.internals.positionAbsolute.x,y:n.y-c.internals.positionAbsolute.y},extent:c.extent,parentId:c.parentId,origin:c.origin,expandParent:c.expandParent,internals:{positionAbsolute:c.internals.positionAbsolute||{x:0,y:0}},measured:{width:c.measured.width??0,height:c.measured.height??0}})}return s}function $x({nodeId:e,dragItems:t,nodeLookup:n,dragging:i=!0}){var o,c,u;const s=[];for(const[f,p]of t){const m=(o=n.get(f))==null?void 0:o.internals.userNode;m&&s.push({...m,position:p.position,dragging:i})}if(!e)return[s[0],s];const r=(c=n.get(e))==null?void 0:c.internals.userNode;return[r?{...r,position:((u=t.get(e))==null?void 0:u.position)||r.position,dragging:i}:s[0],s]}function gce({dragItems:e,snapGrid:t,x:n,y:i}){const s=e.values().next().value;if(!s)return null;const r={x:n-s.distance.x,y:i-s.distance.y},o=Af(r,t);return{x:o.x-r.x,y:o.y-r.y}}function yce({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:i,onDragStop:s}){let r={x:null,y:null},o=0,c=new Map,u=!1,f={x:0,y:0},p=null,m=!1,b=null,y=!1,x=!1,v=null;function w({noDragClassName:C,handleSelector:S,domNode:j,isSelectable:T,nodeId:A,nodeClickDistance:M=0}){b=ss(j);function R({x:F,y:V}){const{nodeLookup:D,nodeExtent:L,snapGrid:z,snapToGrid:W,nodeOrigin:X,onNodeDrag:G,onSelectionDrag:U,onError:q,updateNodePositions:Y}=t();r={x:F,y:V};let $=!1;const ie=c.size>1,be=ie&&L?A0(Tf(c)):null,ce=ie&&W?gce({dragItems:c,snapGrid:z,x:F,y:V}):null;for(const[_e,le]of c){if(!D.has(_e))continue;let pe={x:F-le.distance.x,y:V-le.distance.y};W&&(pe=ce?{x:Math.round(pe.x+ce.x),y:Math.round(pe.y+ce.y)}:Af(pe,z));let Te=null;if(ie&&L&&!le.extent&&be){const{positionAbsolute:xe}=le.internals,fe=xe.x-be.x+L[0][0],te=xe.x+le.measured.width-be.x2+L[1][0],we=xe.y-be.y+L[0][1],Fe=xe.y+le.measured.height-be.y2+L[1][1];Te=[[fe,we],[te,Fe]]}const{position:ne,positionAbsolute:oe}=KI({nodeId:_e,nextPosition:pe,nodeLookup:D,nodeExtent:Te||L,nodeOrigin:X,onError:q});$=$||le.position.x!==ne.x||le.position.y!==ne.y,le.position=ne,le.internals.positionAbsolute=oe}if(x=x||$,!!$&&(Y(c,!0),v&&(i||G||!A&&U))){const[_e,le]=$x({nodeId:A,dragItems:c,nodeLookup:D});i==null||i(v,c,_e,le),G==null||G(v,_e,le),A||U==null||U(v,le)}}async function P(){if(!p)return;const{transform:F,panBy:V,autoPanSpeed:D,autoPanOnNodeDrag:L}=t();if(!L){u=!1,cancelAnimationFrame(o);return}const[z,W]=Rw(f,p,D);(z!==0||W!==0)&&(r.x=(r.x??0)-z/F[2],r.y=(r.y??0)-W/F[2],await V({x:z,y:W})&&R(r)),o=requestAnimationFrame(P)}function I(F){var ie;const{nodeLookup:V,multiSelectionActive:D,nodesDraggable:L,transform:z,snapGrid:W,snapToGrid:X,selectNodesOnDrag:G,onNodeDragStart:U,onSelectionDragStart:q,unselectNodesAndEdges:Y}=t();m=!0,(!G||!T)&&!D&&A&&((ie=V.get(A))!=null&&ie.selected||Y()),T&&G&&A&&(e==null||e(A));const $=Ad(F.sourceEvent,{transform:z,snapGrid:W,snapToGrid:X,containerBounds:p});if(r=$,c=mce(V,L,$,A),c.size>0&&(n||U||!A&&q)){const[be,ce]=$x({nodeId:A,dragItems:c,nodeLookup:V});n==null||n(F.sourceEvent,c,be,ce),U==null||U(F.sourceEvent,be,ce),A||q==null||q(F.sourceEvent,ce)}}const B=NI().clickDistance(M).on("start",F=>{const{domNode:V,nodeDragThreshold:D,transform:L,snapGrid:z,snapToGrid:W}=t();p=(V==null?void 0:V.getBoundingClientRect())||null,y=!1,x=!1,v=F.sourceEvent,D===0&&I(F),r=Ad(F.sourceEvent,{transform:L,snapGrid:z,snapToGrid:W,containerBounds:p}),f=Qs(F.sourceEvent,p)}).on("drag",F=>{const{autoPanOnNodeDrag:V,transform:D,snapGrid:L,snapToGrid:z,nodeDragThreshold:W,nodeLookup:X}=t(),G=Ad(F.sourceEvent,{transform:D,snapGrid:L,snapToGrid:z,containerBounds:p});if(v=F.sourceEvent,(F.sourceEvent.type==="touchmove"&&F.sourceEvent.touches.length>1||A&&!X.has(A))&&(y=!0),!y){if(!u&&V&&m&&(u=!0,P()),!m){const U=Qs(F.sourceEvent,p),q=U.x-f.x,Y=U.y-f.y;Math.sqrt(q*q+Y*Y)>W&&I(F)}(r.x!==G.xSnapped||r.y!==G.ySnapped)&&c&&m&&(f=Qs(F.sourceEvent,p),R(G))}}).on("end",F=>{if(!m||y){y&&c.size>0&&t().updateNodePositions(c,!1);return}if(u=!1,m=!1,cancelAnimationFrame(o),c.size>0){const{nodeLookup:V,updateNodePositions:D,onNodeDragStop:L,onSelectionDragStop:z}=t();if(x&&(D(c,!1),x=!1),s||L||!A&&z){const[W,X]=$x({nodeId:A,dragItems:c,nodeLookup:V,dragging:!1});s==null||s(F.sourceEvent,c,W,X),L==null||L(F.sourceEvent,W,X),A||z==null||z(F.sourceEvent,X)}}}).filter(F=>{const V=F.target;return!F.button&&(!C||!sT(V,`.${C}`,j))&&(!S||sT(V,S,j))});b.call(B)}function k(){b==null||b.on(".drag",null)}return{update:w,destroy:k}}function bce(e,t,n){const i=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const r of t.values())Mm(s,Zd(r))>0&&i.push(r);return i}const xce=250;function vce(e,t,n,i){var c,u;let s=[],r=1/0;const o=bce(e,n,t+xce);for(const f of o){const p=[...((c=f.internals.handleBounds)==null?void 0:c.source)??[],...((u=f.internals.handleBounds)==null?void 0:u.target)??[]];for(const m of p){if(i.nodeId===m.nodeId&&i.type===m.type&&i.id===m.id)continue;const{x:b,y}=yl(f,m,m.position,!0),x=Math.sqrt(Math.pow(b-e.x,2)+Math.pow(y-e.y,2));x>t||(x<r?(s=[{...m,x:b,y}],r=x):x===r&&s.push({...m,x:b,y}))}}if(!s.length)return null;if(s.length>1){const f=i.type==="source"?"target":"source";return s.find(p=>p.type===f)??s[0]}return s[0]}function dP(e,t,n,i,s,r=!1){var f,p,m;const o=i.get(e);if(!o)return null;const c=s==="strict"?(f=o.internals.handleBounds)==null?void 0:f[t]:[...((p=o.internals.handleBounds)==null?void 0:p.source)??[],...((m=o.internals.handleBounds)==null?void 0:m.target)??[]],u=(n?c==null?void 0:c.find(b=>b.id===n):c==null?void 0:c[0])??null;return u&&r?{...u,...yl(o,u,u.position,!0)}:u}function fP(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function wce(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const hP=()=>!0;function Ece(e,{connectionMode:t,connectionRadius:n,handleId:i,nodeId:s,edgeUpdaterType:r,isTarget:o,domNode:c,nodeLookup:u,lib:f,autoPanOnConnect:p,flowId:m,panBy:b,cancelConnection:y,onConnectStart:x,onConnect:v,onConnectEnd:w,isValidConnection:k=hP,onReconnectEnd:C,updateConnection:S,getTransform:j,getFromHandle:T,autoPanSpeed:A,dragThreshold:M=1,handleDomNode:R}){const P=JI(e.target);let I=0,B;const{x:F,y:V}=Qs(e),D=fP(r,R),L=c==null?void 0:c.getBoundingClientRect();let z=!1;if(!L||!D)return;const W=dP(s,D,i,u,t);if(!W)return;let X=Qs(e,L),G=!1,U=null,q=!1,Y=null;function $(){if(!p||!L)return;const[ne,oe]=Rw(X,L,A);b({x:ne,y:oe}),I=requestAnimationFrame($)}const ie={...W,nodeId:s,type:D,position:W.position},be=u.get(s);let _e={inProgress:!0,isValid:null,from:yl(be,ie,tt.Left,!0),fromHandle:ie,fromPosition:ie.position,fromNode:be,to:X,toHandle:null,toPosition:Kj[ie.position],toNode:null,pointer:X};function le(){z=!0,S(_e),x==null||x(e,{nodeId:s,handleId:i,handleType:D})}M===0&&le();function pe(ne){if(!z){const{x:Fe,y:Le}=Qs(ne),ht=Fe-F,nt=Le-V;if(!(ht*ht+nt*nt>M*M))return;le()}if(!T()||!ie){Te(ne);return}const oe=j();X=Qs(ne,L),B=vce(Mf(X,oe,!1,[1,1]),n,u,ie),G||($(),G=!0);const xe=pP(ne,{handle:B,connectionMode:t,fromNodeId:s,fromHandleId:i,fromType:o?"target":"source",isValidConnection:k,doc:P,lib:f,flowId:m,nodeLookup:u});Y=xe.handleDomNode,U=xe.connection,q=wce(!!B,xe.isValid);const fe=u.get(s),te=fe?yl(fe,ie,tt.Left,!0):_e.from,we={..._e,from:te,isValid:q,to:xe.toHandle&&q?Yc({x:xe.toHandle.x,y:xe.toHandle.y},oe):X,toHandle:xe.toHandle,toPosition:q&&xe.toHandle?xe.toHandle.position:Kj[ie.position],toNode:xe.toHandle?u.get(xe.toHandle.nodeId):null,pointer:X};S(we),_e=we}function Te(ne){if(!("touches"in ne&&ne.touches.length>0)){if(z){(B||Y)&&U&&q&&(v==null||v(U));const{inProgress:oe,...xe}=_e,fe={...xe,toPosition:_e.toHandle?_e.toPosition:null};w==null||w(ne,fe),r&&(C==null||C(ne,fe))}y(),cancelAnimationFrame(I),G=!1,q=!1,U=null,Y=null,P.removeEventListener("mousemove",pe),P.removeEventListener("mouseup",Te),P.removeEventListener("touchmove",pe),P.removeEventListener("touchend",Te)}}P.addEventListener("mousemove",pe),P.addEventListener("mouseup",Te),P.addEventListener("touchmove",pe),P.addEventListener("touchend",Te)}function pP(e,{handle:t,connectionMode:n,fromNodeId:i,fromHandleId:s,fromType:r,doc:o,lib:c,flowId:u,isValidConnection:f=hP,nodeLookup:p}){const m=r==="target",b=t?o.querySelector(`.${c}-flow__handle[data-id="${u}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:y,y:x}=Qs(e),v=o.elementFromPoint(y,x),w=v!=null&&v.classList.contains(`${c}-flow__handle`)?v:b,k={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const C=fP(void 0,w),S=w.getAttribute("data-nodeid"),j=w.getAttribute("data-handleid"),T=w.classList.contains("connectable"),A=w.classList.contains("connectableend");if(!S||!C)return k;const M={source:m?S:i,sourceHandle:m?j:s,target:m?i:S,targetHandle:m?s:j};k.connection=M;const P=T&&A&&(n===Gc.Strict?m&&C==="source"||!m&&C==="target":S!==i||j!==s);k.isValid=P&&f(M),k.toHandle=dP(S,C,j,p,n,!0)}return k}const O0={onPointerDown:Ece,isValid:pP};function kce({domNode:e,panZoom:t,getTransform:n,getViewScale:i}){const s=ss(e);function r({translateExtent:c,width:u,height:f,zoomStep:p=1,pannable:m=!0,zoomable:b=!0,inversePan:y=!1}){const x=S=>{if(S.sourceEvent.type!=="wheel"||!t)return;const j=n(),T=S.sourceEvent.ctrlKey&&Jd()?10:1,A=-S.sourceEvent.deltaY*(S.sourceEvent.deltaMode===1?.05:S.sourceEvent.deltaMode?1:.002)*p,M=j[2]*Math.pow(2,A*T);t.scaleTo(M)};let v=[0,0];const w=S=>{(S.sourceEvent.type==="mousedown"||S.sourceEvent.type==="touchstart")&&(v=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY])},k=S=>{const j=n();if(S.sourceEvent.type!=="mousemove"&&S.sourceEvent.type!=="touchmove"||!t)return;const T=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY],A=[T[0]-v[0],T[1]-v[1]];v=T;const M=i()*Math.max(j[2],Math.log(j[2]))*(y?-1:1),R={x:j[0]-A[0]*M,y:j[1]-A[1]*M},P=[[0,0],[u,f]];t.setViewportConstrained({x:R.x,y:R.y,zoom:j[2]},P,c)},C=UI().on("start",w).on("zoom",m?k:null).on("zoom.wheel",b?x:null);s.call(C,{})}function o(){s.on("zoom",null)}return{update:r,destroy:o,pointer:Gs}}const yg=e=>({x:e.x,y:e.y,zoom:e.k}),qx=({x:e,y:t,zoom:n})=>pg.translate(e,t).scale(n),yc=(e,t)=>e.target.closest(`.${t}`),mP=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Sce=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Hx=(e,t=0,n=Sce,i=()=>{})=>{const s=typeof t=="number"&&t>0;return s||i(),s?e.transition().duration(t).ease(n).on("end",i):e},gP=e=>{const t=e.ctrlKey&&Jd()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Nce({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:i,panOnScrollMode:s,panOnScrollSpeed:r,zoomOnPinch:o,onPanZoomStart:c,onPanZoom:u,onPanZoomEnd:f}){return p=>{if(yc(p,t))return p.ctrlKey&&p.preventDefault(),!1;p.preventDefault(),p.stopImmediatePropagation();const m=n.property("__zoom").k||1;if(p.ctrlKey&&o){const w=Gs(p),k=gP(p),C=m*Math.pow(2,k);i.scaleTo(n,C,w,p);return}const b=p.deltaMode===1?20:1;let y=s===ol.Vertical?0:p.deltaX*b,x=s===ol.Horizontal?0:p.deltaY*b;!Jd()&&p.shiftKey&&s!==ol.Vertical&&(y=p.deltaY*b,x=0),i.translateBy(n,-(y/m)*r,-(x/m)*r,{internal:!0});const v=yg(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(u==null||u(p,v),e.panScrollTimeout=setTimeout(()=>{f==null||f(p,v),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,c==null||c(p,v))}}function _ce({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(i,s){const r=i.type==="wheel",o=!t&&r&&!i.ctrlKey,c=yc(i,e);if(i.ctrlKey&&r&&c&&i.preventDefault(),o||c)return null;i.preventDefault(),n.call(this,i,s)}}function Cce({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return i=>{var r,o,c;if((r=i.sourceEvent)!=null&&r.internal)return;const s=yg(i.transform);e.mouseButton=((o=i.sourceEvent)==null?void 0:o.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=s,((c=i.sourceEvent)==null?void 0:c.type)==="mousedown"&&t(!0),n&&(n==null||n(i.sourceEvent,s))}}function jce({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:i,onPanZoom:s}){return r=>{var o,c;e.usedRightMouseButton=!!(n&&mP(t,e.mouseButton??0)),(o=r.sourceEvent)!=null&&o.sync||i([r.transform.x,r.transform.y,r.transform.k]),s&&!((c=r.sourceEvent)!=null&&c.internal)&&(s==null||s(r.sourceEvent,yg(r.transform)))}}function Tce({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:i,onPanZoomEnd:s,onPaneContextMenu:r}){return o=>{var c;if(!((c=o.sourceEvent)!=null&&c.internal)&&(e.isZoomingOrPanning=!1,r&&mP(t,e.mouseButton??0)&&!e.usedRightMouseButton&&o.sourceEvent&&r(o.sourceEvent),e.usedRightMouseButton=!1,i(!1),s)){const u=yg(o.transform);e.prevViewport=u,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s==null||s(o.sourceEvent,u)},n?150:0)}}}function Ace({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:i,panOnScroll:s,zoomOnDoubleClick:r,userSelectionActive:o,noWheelClassName:c,noPanClassName:u,lib:f,connectionInProgress:p}){return m=>{var w;const b=e||t,y=n&&m.ctrlKey,x=m.type==="wheel";if(m.button===1&&m.type==="mousedown"&&(yc(m,`${f}-flow__node`)||yc(m,`${f}-flow__edge`)))return!0;if(!i&&!b&&!s&&!r&&!n||o||p&&!x||yc(m,c)&&x||yc(m,u)&&(!x||s&&x&&!e)||!n&&m.ctrlKey&&x)return!1;if(!n&&m.type==="touchstart"&&((w=m.touches)==null?void 0:w.length)>1)return m.preventDefault(),!1;if(!b&&!s&&!y&&x||!i&&(m.type==="mousedown"||m.type==="touchstart")||Array.isArray(i)&&!i.includes(m.button)&&m.type==="mousedown")return!1;const v=Array.isArray(i)&&i.includes(m.button)||!m.button||m.button<=1;return(!m.ctrlKey||x)&&v}}function Mce({domNode:e,minZoom:t,maxZoom:n,translateExtent:i,viewport:s,onPanZoom:r,onPanZoomStart:o,onPanZoomEnd:c,onDraggingChange:u}){const f={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},p=e.getBoundingClientRect(),m=UI().scaleExtent([t,n]).translateExtent(i),b=ss(e).call(m);C({x:s.x,y:s.y,zoom:Wc(s.zoom,t,n)},[[0,0],[p.width,p.height]],i);const y=b.on("wheel.zoom"),x=b.on("dblclick.zoom");m.wheelDelta(gP);async function v(B,F){return b?new Promise(V=>{m==null||m.interpolate((F==null?void 0:F.interpolate)==="linear"?Td:$p).transform(Hx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}function w({noWheelClassName:B,noPanClassName:F,onPaneContextMenu:V,userSelectionActive:D,panOnScroll:L,panOnDrag:z,panOnScrollMode:W,panOnScrollSpeed:X,preventScrolling:G,zoomOnPinch:U,zoomOnScroll:q,zoomOnDoubleClick:Y,zoomActivationKeyPressed:$,lib:ie,onTransformChange:be,connectionInProgress:ce,paneClickDistance:_e,selectionOnDrag:le}){D&&!f.isZoomingOrPanning&&k();const pe=L&&!$&&!D;m.clickDistance(le?1/0:!Xs(_e)||_e<0?0:_e);const Te=pe?Nce({zoomPanValues:f,noWheelClassName:B,d3Selection:b,d3Zoom:m,panOnScrollMode:W,panOnScrollSpeed:X,zoomOnPinch:U,onPanZoomStart:o,onPanZoom:r,onPanZoomEnd:c}):_ce({noWheelClassName:B,preventScrolling:G,d3ZoomHandler:y});b.on("wheel.zoom",Te,{passive:!1});const ne=Cce({zoomPanValues:f,onDraggingChange:u,onPanZoomStart:o});m.on("start",ne);const oe=jce({zoomPanValues:f,panOnDrag:z,onPaneContextMenu:!!V,onPanZoom:r,onTransformChange:be});m.on("zoom",oe);const xe=Tce({zoomPanValues:f,panOnDrag:z,panOnScroll:L,onPaneContextMenu:V,onPanZoomEnd:c,onDraggingChange:u});m.on("end",xe);const fe=Ace({zoomActivationKeyPressed:$,panOnDrag:z,zoomOnScroll:q,panOnScroll:L,zoomOnDoubleClick:Y,zoomOnPinch:U,userSelectionActive:D,noPanClassName:F,noWheelClassName:B,lib:ie,connectionInProgress:ce});m.filter(fe),Y?b.on("dblclick.zoom",x):b.on("dblclick.zoom",null)}function k(){m.on("zoom",null)}async function C(B,F,V){const D=qx(B),L=m==null?void 0:m.constrain()(D,F,V);return L&&await v(L),L}async function S(B,F){const V=qx(B);return await v(V,F),V}function j(B){if(b){const F=qx(B),V=b.property("__zoom");(V.k!==B.zoom||V.x!==B.x||V.y!==B.y)&&(m==null||m.transform(b,F,null,{sync:!0}))}}function T(){const B=b?BI(b.node()):{x:0,y:0,k:1};return{x:B.x,y:B.y,zoom:B.k}}async function A(B,F){return b?new Promise(V=>{m==null||m.interpolate((F==null?void 0:F.interpolate)==="linear"?Td:$p).scaleTo(Hx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}async function M(B,F){return b?new Promise(V=>{m==null||m.interpolate((F==null?void 0:F.interpolate)==="linear"?Td:$p).scaleBy(Hx(b,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>V(!0)),B)}):!1}function R(B){m==null||m.scaleExtent(B)}function P(B){m==null||m.translateExtent(B)}function I(B){const F=!Xs(B)||B<0?0:B;m==null||m.clickDistance(F)}return{update:w,destroy:k,setViewport:S,setViewportConstrained:C,getViewport:T,scaleTo:A,scaleBy:M,setScaleExtent:R,setTranslateExtent:P,syncViewport:j,setClickDistance:I}}var Xc;(function(e){e.Line="line",e.Handle="handle"})(Xc||(Xc={}));function Rce({width:e,prevWidth:t,height:n,prevHeight:i,affectsX:s,affectsY:r}){const o=e-t,c=n-i,u=[o>0?1:o<0?-1:0,c>0?1:c<0?-1:0];return o&&s&&(u[0]=u[0]*-1),c&&r&&(u[1]=u[1]*-1),u}function rT(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),i=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:i,affectsY:s}}function Ua(e,t){return Math.max(0,t-e)}function Fa(e,t){return Math.max(0,e-t)}function xp(e,t,n){return Math.max(0,t-e,e-n)}function aT(e,t){return e?!t:t}function Dce(e,t,n,i,s,r,o,c){let{affectsX:u,affectsY:f}=t;const{isHorizontal:p,isVertical:m}=t,b=p&&m,{xSnapped:y,ySnapped:x}=n,{minWidth:v,maxWidth:w,minHeight:k,maxHeight:C}=i,{x:S,y:j,width:T,height:A,aspectRatio:M}=e;let R=Math.floor(p?y-e.pointerX:0),P=Math.floor(m?x-e.pointerY:0);const I=T+(u?-R:R),B=A+(f?-P:P),F=-r[0]*T,V=-r[1]*A;let D=xp(I,v,w),L=xp(B,k,C);if(o){let X=0,G=0;u&&R<0?X=Ua(S+R+F,o[0][0]):!u&&R>0&&(X=Fa(S+I+F,o[1][0])),f&&P<0?G=Ua(j+P+V,o[0][1]):!f&&P>0&&(G=Fa(j+B+V,o[1][1])),D=Math.max(D,X),L=Math.max(L,G)}if(c){let X=0,G=0;u&&R>0?X=Fa(S+R,c[0][0]):!u&&R<0&&(X=Ua(S+I,c[1][0])),f&&P>0?G=Fa(j+P,c[0][1]):!f&&P<0&&(G=Ua(j+B,c[1][1])),D=Math.max(D,X),L=Math.max(L,G)}if(s){if(p){const X=xp(I/M,k,C)*M;if(D=Math.max(D,X),o){let G=0;!u&&!f||u&&!f&&b?G=Fa(j+V+I/M,o[1][1])*M:G=Ua(j+V+(u?R:-R)/M,o[0][1])*M,D=Math.max(D,G)}if(c){let G=0;!u&&!f||u&&!f&&b?G=Ua(j+I/M,c[1][1])*M:G=Fa(j+(u?R:-R)/M,c[0][1])*M,D=Math.max(D,G)}}if(m){const X=xp(B*M,v,w)/M;if(L=Math.max(L,X),o){let G=0;!u&&!f||f&&!u&&b?G=Fa(S+B*M+F,o[1][0])/M:G=Ua(S+(f?P:-P)*M+F,o[0][0])/M,L=Math.max(L,G)}if(c){let G=0;!u&&!f||f&&!u&&b?G=Ua(S+B*M,c[1][0])/M:G=Fa(S+(f?P:-P)*M,c[0][0])/M,L=Math.max(L,G)}}}P=P+(P<0?L:-L),R=R+(R<0?D:-D),s&&(b?I>B*M?P=(aT(u,f)?-R:R)/M:R=(aT(u,f)?-P:P)*M:p?(P=R/M,f=u):(R=P*M,u=f));const z=u?S+R:S,W=f?j+P:j;return{width:T+(u?-R:R),height:A+(f?-P:P),x:r[0]*R*(u?-1:1)+z,y:r[1]*P*(f?-1:1)+W}}const yP={width:0,height:0,x:0,y:0},Oce={...yP,pointerX:0,pointerY:0,aspectRatio:1};function Lce(e,t,n){const i=t.position.x+e.position.x,s=t.position.y+e.position.y,r=e.measured.width??0,o=e.measured.height??0,c=n[0]*r,u=n[1]*o;return[[i-c,s-u],[i+r-c,s+o-u]]}function Ice({domNode:e,nodeId:t,getStoreItems:n,onChange:i,onEnd:s}){const r=ss(e);let o={controlDirection:rT("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function c({controlPosition:f,boundaries:p,keepAspectRatio:m,resizeDirection:b,onResizeStart:y,onResize:x,onResizeEnd:v,shouldResize:w}){let k={...yP},C={...Oce};o={boundaries:p,resizeDirection:b,keepAspectRatio:m,controlDirection:rT(f)};let S,j=null,T=[],A,M,R,P=!1;const I=NI().on("start",B=>{const{nodeLookup:F,transform:V,snapGrid:D,snapToGrid:L,nodeOrigin:z,paneDomNode:W}=n();if(S=F.get(t),!S)return;j=(W==null?void 0:W.getBoundingClientRect())??null;const{xSnapped:X,ySnapped:G}=Ad(B.sourceEvent,{transform:V,snapGrid:D,snapToGrid:L,containerBounds:j});k={width:S.measured.width??0,height:S.measured.height??0,x:S.position.x??0,y:S.position.y??0},C={...k,pointerX:X,pointerY:G,aspectRatio:k.width/k.height},A=void 0,M=gl(S.extent)?S.extent:void 0,S.parentId&&(S.extent==="parent"||S.expandParent)&&(A=F.get(S.parentId)),A&&S.extent==="parent"&&(M=[[0,0],[A.measured.width,A.measured.height]]),T=[],R=void 0;for(const[U,q]of F)if(q.parentId===t&&(T.push({id:U,position:{...q.position},extent:q.extent}),q.extent==="parent"||q.expandParent)){const Y=Lce(q,S,q.origin??z);R?R=[[Math.min(Y[0][0],R[0][0]),Math.min(Y[0][1],R[0][1])],[Math.max(Y[1][0],R[1][0]),Math.max(Y[1][1],R[1][1])]]:R=Y}y==null||y(B,{...k})}).on("drag",B=>{const{transform:F,snapGrid:V,snapToGrid:D,nodeOrigin:L}=n(),z=Ad(B.sourceEvent,{transform:F,snapGrid:V,snapToGrid:D,containerBounds:j}),W=[];if(!S)return;const{x:X,y:G,width:U,height:q}=k,Y={},$=S.origin??L,{width:ie,height:be,x:ce,y:_e}=Dce(C,o.controlDirection,z,o.boundaries,o.keepAspectRatio,$,M,R),le=ie!==U,pe=be!==q,Te=ce!==X&&le,ne=_e!==G&&pe;if(!Te&&!ne&&!le&&!pe)return;if((Te||ne||$[0]===1||$[1]===1)&&(Y.x=Te?ce:k.x,Y.y=ne?_e:k.y,k.x=Y.x,k.y=Y.y,T.length>0)){const te=ce-X,we=_e-G;for(const Fe of T)Fe.position={x:Fe.position.x-te+$[0]*(ie-U),y:Fe.position.y-we+$[1]*(be-q)},W.push(Fe)}if((le||pe)&&(Y.width=le&&(!o.resizeDirection||o.resizeDirection==="horizontal")?ie:k.width,Y.height=pe&&(!o.resizeDirection||o.resizeDirection==="vertical")?be:k.height,k.width=Y.width,k.height=Y.height),A&&S.expandParent){const te=$[0]*(Y.width??0);Y.x&&Y.x<te&&(k.x=te,C.x=C.x-(Y.x-te));const we=$[1]*(Y.height??0);Y.y&&Y.y<we&&(k.y=we,C.y=C.y-(Y.y-we))}const oe=Rce({width:k.width,prevWidth:U,height:k.height,prevHeight:q,affectsX:o.controlDirection.affectsX,affectsY:o.controlDirection.affectsY}),xe={...k,direction:oe};(w==null?void 0:w(B,xe))!==!1&&(P=!0,x==null||x(B,xe),i(Y,W))}).on("end",B=>{P&&(v==null||v(B,{...k}),s==null||s({...k}),P=!1)});r.call(I)}function u(){r.on(".drag",null)}return{update:c,destroy:u}}var Vx={exports:{}},Kx={},Gx={exports:{}},Wx={};/**
|
|
842
842
|
* @license React
|
|
843
843
|
* use-sync-external-store-shim.production.js
|
|
844
844
|
*
|
|
@@ -862,4 +862,4 @@ description: ...
|
|
|
862
862
|
`)),p=f.reduce((m,b)=>m.concat(...b),[]);return[f,p]}return[[],[]]},[e]);return _.useEffect(()=>{const u=(t==null?void 0:t.target)??bT,f=(t==null?void 0:t.actInsideInputWithModifier)??!0;if(e!==null){const p=y=>{var w,k;if(s.current=y.ctrlKey||y.metaKey||y.shiftKey||y.altKey,(!s.current||s.current&&!f)&&eP(y))return!1;const v=vT(y.code,c);if(r.current.add(y[v]),xT(o,r.current,!1)){const C=((k=(w=y.composedPath)==null?void 0:w.call(y))==null?void 0:k[0])||y.target,S=(C==null?void 0:C.nodeName)==="BUTTON"||(C==null?void 0:C.nodeName)==="A";t.preventDefault!==!1&&(s.current||!S)&&y.preventDefault(),i(!0)}},m=y=>{const x=vT(y.code,c);xT(o,r.current,!0)?(i(!1),r.current.clear()):r.current.delete(y[x]),y.key==="Meta"&&r.current.clear(),s.current=!1},b=()=>{r.current.clear(),i(!1)};return u==null||u.addEventListener("keydown",p),u==null||u.addEventListener("keyup",m),window.addEventListener("blur",b),window.addEventListener("contextmenu",b),()=>{u==null||u.removeEventListener("keydown",p),u==null||u.removeEventListener("keyup",m),window.removeEventListener("blur",b),window.removeEventListener("contextmenu",b)}}},[e,i]),n}function xT(e,t,n){return e.filter(i=>n||i.length===t.size).some(i=>i.every(s=>t.has(s)))}function vT(e,t){return t.includes(e)?"code":"key"}const hue=()=>{const e=Nn();return _.useMemo(()=>({zoomIn:async t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):!1},zoomOut:async t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):!1},zoomTo:async(t,n)=>{const{panZoom:i}=e.getState();return i?i.scaleTo(t,n):!1},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[i,s,r],panZoom:o}=e.getState();return o?(await o.setViewport({x:t.x??i,y:t.y??s,zoom:t.zoom??r},n),!0):!1},getViewport:()=>{const[t,n,i]=e.getState().transform;return{x:t,y:n,zoom:i}},setCenter:async(t,n,i)=>e.getState().setCenter(t,n,i),fitBounds:async(t,n)=>{const{width:i,height:s,minZoom:r,maxZoom:o,panZoom:c}=e.getState(),u=Dw(t,i,s,r,o,(n==null?void 0:n.padding)??.1);return c?(await c.setViewport(u,{duration:n==null?void 0:n.duration,ease:n==null?void 0:n.ease,interpolate:n==null?void 0:n.interpolate}),!0):!1},screenToFlowPosition:(t,n={})=>{const{transform:i,snapGrid:s,snapToGrid:r,domNode:o}=e.getState();if(!o)return t;const{x:c,y:u}=o.getBoundingClientRect(),f={x:t.x-c,y:t.y-u},p=n.snapGrid??s,m=n.snapToGrid??r;return Mf(f,i,m,p)},flowToScreenPosition:t=>{const{transform:n,domNode:i}=e.getState();if(!i)return t;const{x:s,y:r}=i.getBoundingClientRect(),o=Yc(t,n);return{x:o.x+s,y:o.y+r}}}),[])};function kP(e,t){const n=[],i=new Map,s=[];for(const r of e)if(r.type==="add"){s.push(r);continue}else if(r.type==="remove"||r.type==="replace")i.set(r.id,[r]);else{const o=i.get(r.id);o?o.push(r):i.set(r.id,[r])}for(const r of t){const o=i.get(r.id);if(!o){n.push(r);continue}if(o[0].type==="remove")continue;if(o[0].type==="replace"){n.push({...o[0].item});continue}const c={...r};for(const u of o)pue(u,c);n.push(c)}return s.length&&s.forEach(r=>{r.index!==void 0?n.splice(r.index,0,{...r.item}):n.push({...r.item})}),n}function pue(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 SP(e,t){return kP(e,t)}function NP(e,t){return kP(e,t)}function Uo(e,t){return{id:e,type:"select",selected:t}}function bc(e,t=new Set,n=!1){const i=[];for(const[s,r]of e){const o=t.has(s);!(r.selected===void 0&&!o)&&r.selected!==o&&(n&&(r.selected=o),i.push(Uo(r.id,o)))}return i}function wT({items:e=[],lookup:t}){var s;const n=[],i=new Map(e.map(r=>[r.id,r]));for(const[r,o]of e.entries()){const c=t.get(o.id),u=((s=c==null?void 0:c.internals)==null?void 0:s.userNode)??c;u!==void 0&&u!==o&&n.push({id:o.id,item:o,type:"replace"}),u===void 0&&n.push({item:o,type:"add",index:r})}for(const[r]of t)i.get(r)===void 0&&n.push({id:r,type:"remove"});return n}function ET(e){return{id:e.id,type:"remove"}}const _P=XI();function CP(e,t,n={}){return ece(e,t,{...n,onError:n.onError??_P})}function mue(e,t,n,i={shouldReplaceId:!0}){return tce(e,t,n,{...i,onError:i.onError??_P})}const kT=e=>Ule(e),gue=e=>VI(e);function jP(e){return _.forwardRef(e)}const yue=typeof window<"u"?_.useLayoutEffect:_.useEffect;function ST(e){const[t,n]=_.useState(BigInt(0)),[i]=_.useState(()=>bue(()=>n(s=>s+BigInt(1))));return yue(()=>{const s=i.get();s.length&&(e(s),i.reset())},[t]),i}function bue(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const TP=_.createContext(null);function xue({children:e}){const t=Nn(),n=_.useCallback(c=>{const{nodes:u=[],setNodes:f,hasDefaultNodes:p,onNodesChange:m,nodeLookup:b,fitViewQueued:y,onNodesChangeMiddlewareMap:x}=t.getState();let v=u;for(const k of c)v=typeof k=="function"?k(v):k;let w=wT({items:v,lookup:b});for(const k of x.values())w=k(w);p&&f(v),w.length>0?m==null||m(w):y&&window.requestAnimationFrame(()=>{const{fitViewQueued:k,nodes:C,setNodes:S}=t.getState();k&&S(C)})},[]),i=ST(n),s=_.useCallback(c=>{const{edges:u=[],setEdges:f,hasDefaultEdges:p,onEdgesChange:m,edgeLookup:b}=t.getState();let y=u;for(const x of c)y=typeof x=="function"?x(y):x;p?f(y):m&&m(wT({items:y,lookup:b}))},[]),r=ST(s),o=_.useMemo(()=>({nodeQueue:i,edgeQueue:r}),[]);return d.jsx(TP.Provider,{value:o,children:e})}function vue(){const e=_.useContext(TP);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const wue=e=>!!e.panZoom;function vg(){const e=hue(),t=Nn(),n=vue(),i=Ut(wue),s=_.useMemo(()=>{const r=m=>t.getState().nodeLookup.get(m),o=m=>{n.nodeQueue.push(m)},c=m=>{n.edgeQueue.push(m)},u=m=>{var k,C;const{nodeLookup:b,nodeOrigin:y}=t.getState(),x=kT(m)?m:b.get(m.id),v=x.parentId?ZI(x.position,x.measured,x.parentId,b,y):x.position,w={...x,position:v,width:((k=x.measured)==null?void 0:k.width)??x.width,height:((C=x.measured)==null?void 0:C.height)??x.height};return Zd(w)},f=(m,b,y={replace:!1})=>{o(x=>x.map(v=>{if(v.id===m){const w=typeof b=="function"?b(v):b;return y.replace&&kT(w)?w:{...v,...w}}return v}))},p=(m,b,y={replace:!1})=>{c(x=>x.map(v=>{if(v.id===m){const w=typeof b=="function"?b(v):b;return y.replace&&gue(w)?w:{...v,...w}}return v}))};return{getNodes:()=>t.getState().nodes.map(m=>({...m})),getNode:m=>{var b;return(b=r(m))==null?void 0:b.internals.userNode},getInternalNode:r,getEdges:()=>{const{edges:m=[]}=t.getState();return m.map(b=>({...b}))},getEdge:m=>t.getState().edgeLookup.get(m),setNodes:o,setEdges:c,addNodes:m=>{const b=Array.isArray(m)?m:[m];n.nodeQueue.push(y=>[...y,...b])},addEdges:m=>{const b=Array.isArray(m)?m:[m];n.edgeQueue.push(y=>[...y,...b])},toObject:()=>{const{nodes:m=[],edges:b=[],transform:y}=t.getState(),[x,v,w]=y;return{nodes:m.map(k=>({...k})),edges:b.map(k=>({...k})),viewport:{x,y:v,zoom:w}}},deleteElements:async({nodes:m=[],edges:b=[]})=>{const{nodes:y,edges:x,onNodesDelete:v,onEdgesDelete:w,triggerNodeChanges:k,triggerEdgeChanges:C,onDelete:S,onBeforeDelete:j}=t.getState(),{nodes:T,edges:A}=await Vle({nodesToRemove:m,edgesToRemove:b,nodes:y,edges:x,onBeforeDelete:j}),M=A.length>0,R=T.length>0;if(M){const P=A.map(ET);w==null||w(A),C(P)}if(R){const P=T.map(ET);v==null||v(T),k(P)}return(R||M)&&(S==null||S({nodes:T,edges:A})),{deletedNodes:T,deletedEdges:A}},getIntersectingNodes:(m,b=!0,y)=>{const x=Wj(m),v=x?m:u(m),w=y!==void 0;return v?(y||t.getState().nodes).filter(k=>{const C=t.getState().nodeLookup.get(k.id);if(C&&!x&&(k.id===m.id||!C.internals.positionAbsolute))return!1;const S=Zd(w?k:C),j=Mm(S,v);return b&&j>0||j>=S.width*S.height||j>=v.width*v.height}):[]},isNodeIntersecting:(m,b,y=!0)=>{const v=Wj(m)?m:u(m);if(!v)return!1;const w=Mm(v,b);return y&&w>0||w>=b.width*b.height||w>=v.width*v.height},updateNode:f,updateNodeData:(m,b,y={replace:!1})=>{f(m,x=>{const v=typeof b=="function"?b(x):b;return y.replace?{...x,data:v}:{...x,data:{...x.data,...v}}},y)},updateEdge:p,updateEdgeData:(m,b,y={replace:!1})=>{p(m,x=>{const v=typeof b=="function"?b(x):b;return y.replace?{...x,data:v}:{...x,data:{...x.data,...v}}},y)},getNodesBounds:m=>{const{nodeLookup:b,nodeOrigin:y}=t.getState();return Fle(m,{nodeLookup:b,nodeOrigin:y})},getHandleConnections:({type:m,id:b,nodeId:y})=>{var x;return Array.from(((x=t.getState().connectionLookup.get(`${y}-${m}${b?`-${b}`:""}`))==null?void 0:x.values())??[])},getNodeConnections:({type:m,handleId:b,nodeId:y})=>{var x;return Array.from(((x=t.getState().connectionLookup.get(`${y}${m?b?`-${m}-${b}`:`-${m}`:""}`))==null?void 0:x.values())??[])},fitView:async m=>{const b=t.getState().fitViewResolver??Wle();return t.setState({fitViewQueued:!0,fitViewOptions:m,fitViewResolver:b}),n.nodeQueue.push(y=>[...y]),b.promise}}},[]);return _.useMemo(()=>({...s,...e,viewportInitialized:i}),[i])}const NT=e=>e.selected,Eue=typeof window<"u"?window:void 0;function kue({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=Nn(),{deleteElements:i}=vg(),s=ef(e,{actInsideInputWithModifier:!1}),r=ef(t,{target:Eue});_.useEffect(()=>{if(s){const{edges:o,nodes:c}=n.getState();i({nodes:c.filter(NT),edges:o.filter(NT)}),n.setState({nodesSelectionActive:!1})}},[s]),_.useEffect(()=>{n.setState({multiSelectionActive:r})},[r])}function Sue(e){const t=Nn();_.useEffect(()=>{const n=()=>{var s,r,o,c;if(!e.current||!(((r=(s=e.current).checkVisibility)==null?void 0:r.call(s))??!0))return!1;const i=Ow(e.current);(i.height===0||i.width===0)&&((c=(o=t.getState()).onError)==null||c.call(o,"004",ls.error004())),t.setState({width:i.width||500,height:i.height||500})};if(e.current){n(),window.addEventListener("resize",n);const i=new ResizeObserver(()=>n());return i.observe(e.current),()=>{window.removeEventListener("resize",n),i&&e.current&&i.unobserve(e.current)}}},[])}const wg={position:"absolute",width:"100%",height:"100%",top:0,left:0},Nue=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function _ue({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:i=!1,panOnScrollSpeed:s=.5,panOnScrollMode:r=ol.Free,zoomOnDoubleClick:o=!0,panOnDrag:c=!0,defaultViewport:u,translateExtent:f,minZoom:p,maxZoom:m,zoomActivationKeyCode:b,preventScrolling:y=!0,children:x,noWheelClassName:v,noPanClassName:w,onViewportChange:k,isControlledViewport:C,paneClickDistance:S,selectionOnDrag:j}){const T=Nn(),A=_.useRef(null),{userSelectionActive:M,lib:R,connectionInProgress:P}=Ut(Nue,Sn),I=ef(b),B=_.useRef();Sue(A);const F=_.useCallback(V=>{k==null||k({x:V[0],y:V[1],zoom:V[2]}),C||T.setState({transform:V})},[k,C]);return _.useEffect(()=>{if(A.current){B.current=Mce({domNode:A.current,minZoom:p,maxZoom:m,translateExtent:f,viewport:u,onDraggingChange:z=>T.setState(W=>W.paneDragging===z?W:{paneDragging:z}),onPanZoomStart:(z,W)=>{const{onViewportChangeStart:X,onMoveStart:G}=T.getState();G==null||G(z,W),X==null||X(W)},onPanZoom:(z,W)=>{const{onViewportChange:X,onMove:G}=T.getState();G==null||G(z,W),X==null||X(W)},onPanZoomEnd:(z,W)=>{const{onViewportChangeEnd:X,onMoveEnd:G}=T.getState();G==null||G(z,W),X==null||X(W)}});const{x:V,y:D,zoom:L}=B.current.getViewport();return T.setState({panZoom:B.current,transform:[V,D,L],domNode:A.current.closest(".react-flow")}),()=>{var z;(z=B.current)==null||z.destroy()}}},[]),_.useEffect(()=>{var V;(V=B.current)==null||V.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:i,panOnScrollSpeed:s,panOnScrollMode:r,zoomOnDoubleClick:o,panOnDrag:c,zoomActivationKeyPressed:I,preventScrolling:y,noPanClassName:w,userSelectionActive:M,noWheelClassName:v,lib:R,onTransformChange:F,connectionInProgress:P,selectionOnDrag:j,paneClickDistance:S})},[e,t,n,i,s,r,o,c,I,y,w,M,v,R,F,P,j,S]),d.jsx("div",{className:"react-flow__renderer",ref:A,style:wg,children:x})}const Cue=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function jue(){const{userSelectionActive:e,userSelectionRect:t}=Ut(Cue,Sn);return e&&t?d.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 Yx=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},Tue=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function Aue({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Qd.Full,panOnDrag:i,autoPanOnSelection:s,paneClickDistance:r,selectionOnDrag:o,onSelectionStart:c,onSelectionEnd:u,onPaneClick:f,onPaneContextMenu:p,onPaneScroll:m,onPaneMouseEnter:b,onPaneMouseMove:y,onPaneMouseLeave:x,children:v}){const w=_.useRef(0),k=Nn(),{userSelectionActive:C,elementsSelectable:S,dragging:j,panBy:T,autoPanSpeed:A}=Ut(Tue,Sn),M=S&&(e||C),R=_.useRef(null),P=_.useRef(),I=_.useRef(new Set),B=_.useRef(new Set),F=_.useRef(!1),V=_.useRef(!1),D=_.useRef({x:0,y:0}),L=_.useRef(!1),z=le=>{if(V.current||F.current||k.getState().connection.inProgress){V.current=!1,F.current=!1;return}f==null||f(le),k.getState().resetSelectedElements(),k.setState({nodesSelectionActive:!1})},W=le=>{if(Array.isArray(i)&&(i!=null&&i.includes(2))){le.preventDefault();return}p==null||p(le)},X=m?le=>m(le):void 0,G=le=>{V.current&&(le.stopPropagation(),V.current=!1)},U=le=>{var Fe,Le;const{domNode:pe,transform:Te}=k.getState();if(P.current=pe==null?void 0:pe.getBoundingClientRect(),!P.current)return;const ne=le.target===R.current;if(!ne&&!!le.target.closest(".nokey")||!e||!(o&&ne||t)||le.button!==0||!le.isPrimary)return;(Le=(Fe=le.target)==null?void 0:Fe.setPointerCapture)==null||Le.call(Fe,le.pointerId),V.current=!1;const{x:fe,y:te}=Qs(le.nativeEvent,P.current),we=Mf({x:fe,y:te},Te);k.setState({userSelectionRect:{width:0,height:0,startX:we.x,startY:we.y,x:fe,y:te}}),ne||(le.stopPropagation(),le.preventDefault())};function q(le,pe){const{userSelectionRect:Te}=k.getState();if(!Te)return;const{transform:ne,nodeLookup:oe,edgeLookup:xe,connectionLookup:fe,triggerNodeChanges:te,triggerEdgeChanges:we,defaultEdgeOptions:Fe}=k.getState(),Le={x:Te.startX,y:Te.startY},{x:ht,y:nt}=Yc(Le,ne),At={startX:Le.x,startY:Le.y,x:le<ht?le:ht,y:pe<nt?pe:nt,width:Math.abs(le-ht),height:Math.abs(pe-nt)},Nt=I.current,mt=B.current;I.current=new Set(Mw(oe,At,ne,n===Qd.Partial,!0).map(We=>We.id)),B.current=new Set;const Re=(Fe==null?void 0:Fe.selectable)??!0;for(const We of I.current){const se=fe.get(We);if(se)for(const{edgeId:Ee}of se.values()){const De=xe.get(Ee);De&&(De.selectable??Re)&&B.current.add(Ee)}}if(!Yj(Nt,I.current)){const We=bc(oe,I.current,!0);te(We)}if(!Yj(mt,B.current)){const We=bc(xe,B.current);we(We)}k.setState({userSelectionRect:At,userSelectionActive:!0,nodesSelectionActive:!1})}function Y(){if(!s||!P.current)return;const[le,pe]=Rw(D.current,P.current,A);T({x:le,y:pe}).then(Te=>{if(!V.current||!Te){w.current=requestAnimationFrame(Y);return}const{x:ne,y:oe}=D.current;q(ne,oe),w.current=requestAnimationFrame(Y)})}const $=()=>{cancelAnimationFrame(w.current),w.current=0,L.current=!1};_.useEffect(()=>()=>$(),[]);const ie=le=>{const{userSelectionRect:pe,transform:Te,resetSelectedElements:ne}=k.getState();if(!P.current||!pe)return;const{x:oe,y:xe}=Qs(le.nativeEvent,P.current);D.current={x:oe,y:xe};const fe=Yc({x:pe.startX,y:pe.startY},Te);if(!V.current){const te=t?0:r;if(Math.hypot(oe-fe.x,xe-fe.y)<=te)return;ne(),c==null||c(le)}V.current=!0,L.current||(Y(),L.current=!0),q(oe,xe)},be=le=>{var pe,Te;if(!M){le.target===R.current&&k.getState().connection.inProgress&&(F.current=!0);return}le.button===0&&((Te=(pe=le.target)==null?void 0:pe.releasePointerCapture)==null||Te.call(pe,le.pointerId),!C&&le.target===R.current&&k.getState().userSelectionRect&&(z==null||z(le)),k.setState({userSelectionActive:!1,userSelectionRect:null}),V.current&&(u==null||u(le),k.setState({nodesSelectionActive:I.current.size>0})),$())},ce=le=>{var pe,Te;(Te=(pe=le.target)==null?void 0:pe.releasePointerCapture)==null||Te.call(pe,le.pointerId),$()},_e=i===!0||Array.isArray(i)&&i.includes(0);return d.jsxs("div",{className:Wn(["react-flow__pane",{draggable:_e,dragging:j,selection:e}]),onClick:M?void 0:Yx(z,R),onContextMenu:Yx(W,R),onWheel:Yx(X,R),onPointerEnter:M?void 0:b,onPointerMove:M?ie:y,onPointerUp:be,onPointerCancel:M?ce:void 0,onPointerDownCapture:M?U:void 0,onClickCapture:M?G:void 0,onPointerLeave:x,ref:R,style:wg,children:[v,d.jsx(jue,{})]})}function L0({id:e,store:t,unselect:n=!1,nodeRef:i}){const{addSelectedNodes:s,unselectNodesAndEdges:r,multiSelectionActive:o,nodeLookup:c,onError:u}=t.getState(),f=c.get(e);if(!f){u==null||u("012",ls.error012(e));return}t.setState({nodesSelectionActive:!1}),f.selected?(n||f.selected&&o)&&(r({nodes:[f],edges:[]}),requestAnimationFrame(()=>{var p;return(p=i==null?void 0:i.current)==null?void 0:p.blur()})):s([e])}function AP({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:i,nodeId:s,isSelectable:r,nodeClickDistance:o}){const c=Nn(),[u,f]=_.useState(!1),p=_.useRef();return _.useEffect(()=>{p.current=yce({getStoreItems:()=>c.getState(),onNodeMouseDown:m=>{L0({id:m,store:c,nodeRef:e})},onDragStart:()=>{f(!0)},onDragStop:()=>{f(!1)}})},[]),_.useEffect(()=>{if(!(t||!e.current||!p.current))return p.current.update({noDragClassName:n,handleSelector:i,domNode:e.current,isSelectable:r,nodeId:s,nodeClickDistance:o}),()=>{var m;(m=p.current)==null||m.destroy()}},[n,i,t,r,e,s,o]),u}const Mue=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function MP(){const e=Nn();return _.useCallback(n=>{const{nodeExtent:i,snapToGrid:s,snapGrid:r,nodesDraggable:o,onError:c,updateNodePositions:u,nodeLookup:f,nodeOrigin:p}=e.getState(),m=new Map,b=Mue(o),y=s?r[0]:5,x=s?r[1]:5,v=n.direction.x*y*n.factor,w=n.direction.y*x*n.factor;for(const[,k]of f){if(!b(k))continue;let C={x:k.internals.positionAbsolute.x+v,y:k.internals.positionAbsolute.y+w};s&&(C=Af(C,r));const{position:S,positionAbsolute:j}=KI({nodeId:k.id,nextPosition:C,nodeLookup:f,nodeExtent:i,nodeOrigin:p,onError:c});k.position=S,k.internals.positionAbsolute=j,m.set(k.id,k)}u(m)},[])}const Uw=_.createContext(null),Rue=Uw.Provider;Uw.Consumer;const RP=()=>_.useContext(Uw),Due=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),DP=_.createContext(null);function Oue({children:e}){const t=Ut(Due,Sn);return d.jsx(DP.Provider,{value:t,children:e})}function Lue(){const e=_.useContext(DP);if(!e)throw new Error("useHandleConfig must be used within a HandleConfigProvider");return e}const Iue={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},Pue=(e,t,n)=>i=>{const{connectionClickStartHandle:s,connectionMode:r,connection:o}=i,{fromHandle:c,toHandle:u,isValid:f}=o;if(!c&&!s)return Iue;const p=(u==null?void 0:u.nodeId)===e&&(u==null?void 0:u.id)===t&&(u==null?void 0:u.type)===n;return{connectingFrom:(c==null?void 0:c.nodeId)===e&&(c==null?void 0:c.id)===t&&(c==null?void 0:c.type)===n,connectingTo:p,clickConnecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.id)===t&&(s==null?void 0:s.type)===n,isPossibleEndHandle:r===Gc.Strict?(c==null?void 0:c.type)!==n:e!==(c==null?void 0:c.nodeId)||t!==(c==null?void 0:c.id),connectionInProcess:!!c,clickConnectionInProcess:!!s,valid:p&&f}};function zue({type:e="source",position:t=tt.Top,isValidConnection:n,isConnectable:i=!0,isConnectableStart:s=!0,isConnectableEnd:r=!0,id:o,onConnect:c,children:u,className:f,onMouseDown:p,onTouchStart:m,...b},y){var L,z;const x=o||null,v=e==="target",w=Nn(),k=RP(),{connectOnClick:C,noPanClassName:S,rfId:j}=Lue(),{connectingFrom:T,connectingTo:A,clickConnecting:M,isPossibleEndHandle:R,connectionInProcess:P,clickConnectionInProcess:I,valid:B}=Ut(Pue(k,x,e),Sn);k||(z=(L=w.getState()).onError)==null||z.call(L,"010",ls.error010());const F=W=>{const{defaultEdgeOptions:X,onConnect:G,hasDefaultEdges:U}=w.getState(),q={...X,...W};if(U){const{edges:Y,setEdges:$,onError:ie}=w.getState();$(CP(q,Y,{onError:ie}))}G==null||G(q),c==null||c(q)},V=W=>{if(!k)return;const X=tP(W.nativeEvent);if(s&&(X&&W.button===0||!X)){const G=w.getState();O0.onPointerDown(W.nativeEvent,{handleDomNode:W.currentTarget,autoPanOnConnect:G.autoPanOnConnect,connectionMode:G.connectionMode,connectionRadius:G.connectionRadius,domNode:G.domNode,nodeLookup:G.nodeLookup,lib:G.lib,isTarget:v,handleId:x,nodeId:k,flowId:G.rfId,panBy:G.panBy,cancelConnection:G.cancelConnection,onConnectStart:G.onConnectStart,onConnectEnd:(...U)=>{var q,Y;return(Y=(q=w.getState()).onConnectEnd)==null?void 0:Y.call(q,...U)},updateConnection:G.updateConnection,onConnect:F,isValidConnection:n||((...U)=>{var q,Y;return((Y=(q=w.getState()).isValidConnection)==null?void 0:Y.call(q,...U))??!0}),getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,autoPanSpeed:G.autoPanSpeed,dragThreshold:G.connectionDragThreshold})}X?p==null||p(W):m==null||m(W)},D=W=>{const{onClickConnectStart:X,onClickConnectEnd:G,connectionClickStartHandle:U,connectionMode:q,isValidConnection:Y,lib:$,rfId:ie,nodeLookup:be,connection:ce}=w.getState();if(!k||!U&&!s)return;if(!U){X==null||X(W.nativeEvent,{nodeId:k,handleId:x,handleType:e}),w.setState({connectionClickStartHandle:{nodeId:k,type:e,id:x}});return}const _e=JI(W.target),le=n||Y,{connection:pe,isValid:Te}=O0.isValid(W.nativeEvent,{handle:{nodeId:k,id:x,type:e},connectionMode:q,fromNodeId:U.nodeId,fromHandleId:U.id||null,fromType:U.type,isValidConnection:le,flowId:ie,doc:_e,lib:$,nodeLookup:be});Te&&pe&&F(pe);const ne=structuredClone(ce);delete ne.inProgress,ne.toPosition=ne.toHandle?ne.toHandle.position:null,G==null||G(W,ne),w.setState({connectionClickStartHandle:null})};return d.jsx("div",{"data-handleid":x,"data-nodeid":k,"data-handlepos":t,"data-id":`${j}-${k}-${x}-${e}`,className:Wn(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",S,f,{source:!v,target:v,connectable:i,connectablestart:s,connectableend:r,clickconnecting:M,connectingfrom:T,connectingto:A,valid:B,connectionindicator:i&&(!P||R)&&(P||I?r:s)}]),onMouseDown:V,onTouchStart:V,onClick:C?D:void 0,ref:y,...b,children:u})}const no=_.memo(jP(zue));function Bue({data:e,isConnectable:t,sourcePosition:n=tt.Bottom}){return d.jsxs(d.Fragment,{children:[e==null?void 0:e.label,d.jsx(no,{type:"source",position:n,isConnectable:t})]})}function Uue({data:e,isConnectable:t,targetPosition:n=tt.Top,sourcePosition:i=tt.Bottom}){return d.jsxs(d.Fragment,{children:[d.jsx(no,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,d.jsx(no,{type:"source",position:i,isConnectable:t})]})}function Fue(){return null}function $ue({data:e,isConnectable:t,targetPosition:n=tt.Top}){return d.jsxs(d.Fragment,{children:[d.jsx(no,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label]})}const Rm={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},_T={input:Bue,default:Uue,output:$ue,group:Fue};function que(e){var t,n,i,s;return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??((t=e.style)==null?void 0:t.width),height:e.height??e.initialHeight??((n=e.style)==null?void 0:n.height)}:{width:e.width??((i=e.style)==null?void 0:i.width),height:e.height??((s=e.style)==null?void 0:s.height)}}const Hue=e=>{const{width:t,height:n,x:i,y:s}=Tf(e.nodeLookup,{filter:r=>!!r.selected});return{width:Xs(t)?t:null,height:Xs(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${i}px,${s}px)`}};function Vue({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const i=Nn(),{width:s,height:r,transformString:o,userSelectionActive:c}=Ut(Hue,Sn),u=MP(),f=_.useRef(null);_.useEffect(()=>{var y;n||(y=f.current)==null||y.focus({preventScroll:!0})},[n]);const p=!c&&s!==null&&r!==null;if(AP({nodeRef:f,disabled:!p}),!p)return null;const m=e?y=>{const x=i.getState().nodes.filter(v=>v.selected);e(y,x)}:void 0,b=y=>{Object.prototype.hasOwnProperty.call(Rm,y.key)&&(y.preventDefault(),u({direction:Rm[y.key],factor:y.shiftKey?4:1}))};return d.jsx("div",{className:Wn(["react-flow__nodesselection","react-flow__container",t]),style:{transform:o},children:d.jsx("div",{ref:f,className:"react-flow__nodesselection-rect",onContextMenu:m,tabIndex:n?void 0:-1,onKeyDown:n?void 0:b,style:{width:s,height:r}})})}const CT=typeof window<"u"?window:void 0,Kue=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function OP({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:s,onPaneContextMenu:r,onPaneScroll:o,paneClickDistance:c,deleteKeyCode:u,selectionKeyCode:f,selectionOnDrag:p,selectionMode:m,onSelectionStart:b,onSelectionEnd:y,multiSelectionKeyCode:x,panActivationKeyCode:v,zoomActivationKeyCode:w,elementsSelectable:k,zoomOnScroll:C,zoomOnPinch:S,panOnScroll:j,panOnScrollSpeed:T,panOnScrollMode:A,zoomOnDoubleClick:M,panOnDrag:R,autoPanOnSelection:P,defaultViewport:I,translateExtent:B,minZoom:F,maxZoom:V,preventScrolling:D,onSelectionContextMenu:L,noWheelClassName:z,noPanClassName:W,disableKeyboardA11y:X,onViewportChange:G,isControlledViewport:U}){const{nodesSelectionActive:q,userSelectionActive:Y}=Ut(Kue,Sn),$=ef(f,{target:CT}),ie=ef(v,{target:CT}),be=ie||R,ce=ie||j,_e=p&&be!==!0,le=$||Y||_e;return kue({deleteKeyCode:u,multiSelectionKeyCode:x}),d.jsx(_ue,{onPaneContextMenu:r,elementsSelectable:k,zoomOnScroll:C,zoomOnPinch:S,panOnScroll:ce,panOnScrollSpeed:T,panOnScrollMode:A,zoomOnDoubleClick:M,panOnDrag:!$&&be,defaultViewport:I,translateExtent:B,minZoom:F,maxZoom:V,zoomActivationKeyCode:w,preventScrolling:D,noWheelClassName:z,noPanClassName:W,onViewportChange:G,isControlledViewport:U,paneClickDistance:c,selectionOnDrag:_e,children:d.jsxs(Aue,{onSelectionStart:b,onSelectionEnd:y,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:s,onPaneContextMenu:r,onPaneScroll:o,panOnDrag:be,autoPanOnSelection:P,isSelecting:!!le,selectionMode:m,selectionKeyPressed:$,paneClickDistance:c,selectionOnDrag:_e,children:[e,q&&d.jsx(Vue,{onSelectionContextMenu:L,noPanClassName:W,disableKeyboardA11y:X})]})})}OP.displayName="FlowRenderer";const Gue=_.memo(OP),Wue=e=>t=>e?Mw(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 Yue(e){return Ut(_.useCallback(Wue(e),[e]),Sn)}const Xue=e=>e.updateNodeInternals;function Que(){const e=Ut(Xue),[t]=_.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const i=new Map;n.forEach(s=>{const r=s.target.getAttribute("data-id");i.set(r,{id:r,nodeElement:s.target,force:!0})}),e(i)}));return _.useEffect(()=>()=>{t==null||t.disconnect()},[t]),t}function Zue({node:e,nodeType:t,hasDimensions:n,resizeObserver:i}){const s=Nn(),r=_.useRef(null),o=_.useRef(null),c=_.useRef(e.sourcePosition),u=_.useRef(e.targetPosition),f=_.useRef(t),p=n&&!!e.internals.handleBounds;return _.useEffect(()=>{r.current&&!e.hidden&&(!p||o.current!==r.current)&&(o.current&&(i==null||i.unobserve(o.current)),i==null||i.observe(r.current),o.current=r.current)},[p,e.hidden]),_.useEffect(()=>()=>{o.current&&(i==null||i.unobserve(o.current),o.current=null)},[]),_.useEffect(()=>{if(r.current){const m=f.current!==t,b=c.current!==e.sourcePosition,y=u.current!==e.targetPosition;(m||b||y)&&(f.current=t,c.current=e.sourcePosition,u.current=e.targetPosition,s.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:r.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),r}function Jue({id:e,onClick:t,onMouseEnter:n,onMouseMove:i,onMouseLeave:s,onContextMenu:r,onDoubleClick:o,nodesDraggable:c,elementsSelectable:u,nodesConnectable:f,nodesFocusable:p,resizeObserver:m,noDragClassName:b,noPanClassName:y,disableKeyboardA11y:x,rfId:v,nodeTypes:w,nodeClickDistance:k,onError:C}){const{node:S,internals:j,isParent:T}=Ut(le=>{const pe=le.nodeLookup.get(e),Te=le.parentLookup.has(e);return{node:pe,internals:pe.internals,isParent:Te}},Sn);let A=S.type||"default",M=(w==null?void 0:w[A])||_T[A];M===void 0&&(C==null||C("003",ls.error003(A)),A="default",M=(w==null?void 0:w.default)||_T.default);const R=!!(S.draggable||c&&typeof S.draggable>"u"),P=!!(S.selectable||u&&typeof S.selectable>"u"),I=!!(S.connectable||f&&typeof S.connectable>"u"),B=!!(S.focusable||p&&typeof S.focusable>"u"),F=Nn(),V=QI(S),D=Zue({node:S,nodeType:A,hasDimensions:V,resizeObserver:m}),L=AP({nodeRef:D,disabled:S.hidden||!R,noDragClassName:b,handleSelector:S.dragHandle,nodeId:e,isSelectable:P,nodeClickDistance:k}),z=MP();if(S.hidden)return null;const W=pa(S),X=que(S),G=P||R||t||n||i||s,U=n?le=>n(le,{...j.userNode}):void 0,q=i?le=>i(le,{...j.userNode}):void 0,Y=s?le=>s(le,{...j.userNode}):void 0,$=r?le=>r(le,{...j.userNode}):void 0,ie=o?le=>o(le,{...j.userNode}):void 0,be=le=>{const{selectNodesOnDrag:pe,nodeDragThreshold:Te}=F.getState();P&&(!pe||!R||Te>0)&&L0({id:e,store:F,nodeRef:D}),t&&t(le,{...j.userNode})},ce=le=>{if(!(eP(le.nativeEvent)||x)){if(FI.includes(le.key)&&P){const pe=le.key==="Escape";L0({id:e,store:F,unselect:pe,nodeRef:D})}else if(R&&S.selected&&Object.prototype.hasOwnProperty.call(Rm,le.key)){le.preventDefault();const{ariaLabelConfig:pe}=F.getState();F.setState({ariaLiveMessage:pe["node.a11yDescription.ariaLiveMessage"]({direction:le.key.replace("Arrow","").toLowerCase(),x:~~j.positionAbsolute.x,y:~~j.positionAbsolute.y})}),z({direction:Rm[le.key],factor:le.shiftKey?4:1})}}},_e=()=>{var fe;if(x||!((fe=D.current)!=null&&fe.matches(":focus-visible")))return;const{transform:le,width:pe,height:Te,autoPanOnNodeFocus:ne,setCenter:oe}=F.getState();if(!ne)return;Mw(new Map([[e,S]]),{x:0,y:0,width:pe,height:Te},le,!0).length>0||oe(S.position.x+W.width/2,S.position.y+W.height/2,{zoom:le[2]})};return d.jsx("div",{className:Wn(["react-flow__node",`react-flow__node-${A}`,{[y]:R},S.className,{selected:S.selected,selectable:P,parent:T,draggable:R,dragging:L}]),ref:D,style:{zIndex:j.z,transform:`translate(${j.positionAbsolute.x}px,${j.positionAbsolute.y}px)`,pointerEvents:G?"all":"none",visibility:V?"visible":"hidden",...S.style,...X},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:U,onMouseMove:q,onMouseLeave:Y,onContextMenu:$,onClick:be,onDoubleClick:ie,onKeyDown:B?ce:void 0,tabIndex:B?0:void 0,onFocus:B?_e:void 0,role:S.ariaRole??(B?"group":void 0),"aria-roledescription":"node","aria-describedby":x?void 0:`${vP}-${v}`,"aria-label":S.ariaLabel,...S.domAttributes,children:d.jsx(Rue,{value:e,children:d.jsx(M,{id:e,data:S.data,type:A,positionAbsoluteX:j.positionAbsolute.x,positionAbsoluteY:j.positionAbsolute.y,selected:S.selected??!1,selectable:P,draggable:R,deletable:S.deletable??!0,isConnectable:I,sourcePosition:S.sourcePosition,targetPosition:S.targetPosition,dragging:L,dragHandle:S.dragHandle,zIndex:j.z,parentId:S.parentId,...W})})})}var ede=_.memo(Jue);const tde=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function LP(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:i,elementsSelectable:s,onError:r}=Ut(tde,Sn),o=Yue(e.onlyRenderVisibleElements),c=Que();return d.jsx("div",{className:"react-flow__nodes",style:wg,children:o.map(u=>d.jsx(ede,{id:u,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:c,nodesDraggable:t,nodesConnectable:n,nodesFocusable:i,elementsSelectable:s,nodeClickDistance:e.nodeClickDistance,onError:r},u))})}LP.displayName="NodeRenderer";const nde=_.memo(LP);function ide(e){return Ut(_.useCallback(n=>{if(!e)return n.edges.map(s=>s.id);const i=[];if(n.width&&n.height)for(const s of n.edges){const r=n.nodeLookup.get(s.source),o=n.nodeLookup.get(s.target);r&&o&&Zle({sourceNode:r,targetNode:o,width:n.width,height:n.height,transform:n.transform})&&i.push(s.id)}return i},[e]),Sn)}const sde=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return d.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},rde=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return d.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},jT={[Tm.Arrow]:sde,[Tm.ArrowClosed]:rde};function ade(e){const t=Nn();return _.useMemo(()=>{var s,r;return Object.prototype.hasOwnProperty.call(jT,e)?jT[e]:((r=(s=t.getState()).onError)==null||r.call(s,"009",ls.error009(e)),null)},[e])}const ode=({id:e,type:t,color:n,width:i=12.5,height:s=12.5,markerUnits:r="strokeWidth",strokeWidth:o,orient:c="auto-start-reverse"})=>{const u=ade(t);return u?d.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${i}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:r,orient:c,refX:"0",refY:"0",children:d.jsx(u,{color:n,strokeWidth:o})}):null},IP=({defaultColor:e,rfId:t})=>{const n=Ut(r=>r.edges),i=Ut(r=>r.defaultEdgeOptions),s=_.useMemo(()=>ace(n,{id:t,defaultColor:e,defaultMarkerStart:i==null?void 0:i.markerStart,defaultMarkerEnd:i==null?void 0:i.markerEnd}),[n,i,t,e]);return s.length?d.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:d.jsx("defs",{children:s.map(r=>d.jsx(ode,{id:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient},r.id))})}):null};IP.displayName="MarkerDefinitions";var lde=_.memo(IP);function PP({x:e,y:t,label:n,labelStyle:i,labelShowBg:s=!0,labelBgStyle:r,labelBgPadding:o=[2,4],labelBgBorderRadius:c=2,children:u,className:f,...p}){const[m,b]=_.useState({x:1,y:0,width:0,height:0}),y=Wn(["react-flow__edge-textwrapper",f]),x=_.useRef(null);return _.useEffect(()=>{if(x.current){const v=x.current.getBBox();b({x:v.x,y:v.y,width:v.width,height:v.height})}},[n]),n?d.jsxs("g",{transform:`translate(${e-m.width/2} ${t-m.height/2})`,className:y,visibility:m.width?"visible":"hidden",...p,children:[s&&d.jsx("rect",{width:m.width+2*o[0],x:-o[0],y:-o[1],height:m.height+2*o[1],className:"react-flow__edge-textbg",style:r,rx:c,ry:c}),d.jsx("text",{className:"react-flow__edge-text",y:m.height/2,dy:"0.3em",ref:x,style:i,children:n}),u]}):null}PP.displayName="EdgeText";const cde=_.memo(PP);function Eg({path:e,labelX:t,labelY:n,label:i,labelStyle:s,labelShowBg:r,labelBgStyle:o,labelBgPadding:c,labelBgBorderRadius:u,interactionWidth:f=20,...p}){return d.jsxs(d.Fragment,{children:[d.jsx("path",{...p,d:e,fill:"none",className:Wn(["react-flow__edge-path",p.className])}),f?d.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:f,className:"react-flow__edge-interaction"}):null,i&&Xs(t)&&Xs(n)?d.jsx(cde,{x:t,y:n,label:i,labelStyle:s,labelShowBg:r,labelBgStyle:o,labelBgPadding:c,labelBgBorderRadius:u}):null]})}function TT({pos:e,x1:t,y1:n,x2:i,y2:s}){return e===tt.Left||e===tt.Right?[.5*(t+i),n]:[t,.5*(n+s)]}function zP({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:s,targetPosition:r=tt.Top}){const[o,c]=TT({pos:n,x1:e,y1:t,x2:i,y2:s}),[u,f]=TT({pos:r,x1:i,y1:s,x2:e,y2:t}),[p,m,b,y]=nP({sourceX:e,sourceY:t,targetX:i,targetY:s,sourceControlX:o,sourceControlY:c,targetControlX:u,targetControlY:f});return[`M${e},${t} C${o},${c} ${u},${f} ${i},${s}`,p,m,b,y]}function BP(e){return _.memo(({id:t,sourceX:n,sourceY:i,targetX:s,targetY:r,sourcePosition:o,targetPosition:c,label:u,labelStyle:f,labelShowBg:p,labelBgStyle:m,labelBgPadding:b,labelBgBorderRadius:y,style:x,markerEnd:v,markerStart:w,interactionWidth:k})=>{const[C,S,j]=zP({sourceX:n,sourceY:i,sourcePosition:o,targetX:s,targetY:r,targetPosition:c}),T=e.isInternal?void 0:t;return d.jsx(Eg,{id:T,path:C,labelX:S,labelY:j,label:u,labelStyle:f,labelShowBg:p,labelBgStyle:m,labelBgPadding:b,labelBgBorderRadius:y,style:x,markerEnd:v,markerStart:w,interactionWidth:k})})}const ude=BP({isInternal:!1}),UP=BP({isInternal:!0});ude.displayName="SimpleBezierEdge";UP.displayName="SimpleBezierEdgeInternal";function FP(e){return _.memo(({id:t,sourceX:n,sourceY:i,targetX:s,targetY:r,label:o,labelStyle:c,labelShowBg:u,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:m,style:b,sourcePosition:y=tt.Bottom,targetPosition:x=tt.Top,markerEnd:v,markerStart:w,pathOptions:k,interactionWidth:C})=>{const[S,j,T]=M0({sourceX:n,sourceY:i,sourcePosition:y,targetX:s,targetY:r,targetPosition:x,borderRadius:k==null?void 0:k.borderRadius,offset:k==null?void 0:k.offset,stepPosition:k==null?void 0:k.stepPosition}),A=e.isInternal?void 0:t;return d.jsx(Eg,{id:A,path:S,labelX:j,labelY:T,label:o,labelStyle:c,labelShowBg:u,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:m,style:b,markerEnd:v,markerStart:w,interactionWidth:C})})}const $P=FP({isInternal:!1}),qP=FP({isInternal:!0});$P.displayName="SmoothStepEdge";qP.displayName="SmoothStepEdgeInternal";function HP(e){return _.memo(({id:t,...n})=>{var s;const i=e.isInternal?void 0:t;return d.jsx($P,{...n,id:i,pathOptions:_.useMemo(()=>{var r;return{borderRadius:0,offset:(r=n.pathOptions)==null?void 0:r.offset}},[(s=n.pathOptions)==null?void 0:s.offset])})})}const dde=HP({isInternal:!1}),VP=HP({isInternal:!0});dde.displayName="StepEdge";VP.displayName="StepEdgeInternal";function KP(e){return _.memo(({id:t,sourceX:n,sourceY:i,targetX:s,targetY:r,label:o,labelStyle:c,labelShowBg:u,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:m,style:b,markerEnd:y,markerStart:x,interactionWidth:v})=>{const[w,k,C]=aP({sourceX:n,sourceY:i,targetX:s,targetY:r}),S=e.isInternal?void 0:t;return d.jsx(Eg,{id:S,path:w,labelX:k,labelY:C,label:o,labelStyle:c,labelShowBg:u,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:m,style:b,markerEnd:y,markerStart:x,interactionWidth:v})})}const fde=KP({isInternal:!1}),GP=KP({isInternal:!0});fde.displayName="StraightEdge";GP.displayName="StraightEdgeInternal";function WP(e){return _.memo(({id:t,sourceX:n,sourceY:i,targetX:s,targetY:r,sourcePosition:o=tt.Bottom,targetPosition:c=tt.Top,label:u,labelStyle:f,labelShowBg:p,labelBgStyle:m,labelBgPadding:b,labelBgBorderRadius:y,style:x,markerEnd:v,markerStart:w,pathOptions:k,interactionWidth:C})=>{const[S,j,T]=iP({sourceX:n,sourceY:i,sourcePosition:o,targetX:s,targetY:r,targetPosition:c,curvature:k==null?void 0:k.curvature}),A=e.isInternal?void 0:t;return d.jsx(Eg,{id:A,path:S,labelX:j,labelY:T,label:u,labelStyle:f,labelShowBg:p,labelBgStyle:m,labelBgPadding:b,labelBgBorderRadius:y,style:x,markerEnd:v,markerStart:w,interactionWidth:C})})}const hde=WP({isInternal:!1}),YP=WP({isInternal:!0});hde.displayName="BezierEdge";YP.displayName="BezierEdgeInternal";const AT={default:YP,straight:GP,step:VP,smoothstep:qP,simplebezier:UP},MT={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},pde=(e,t,n)=>n===tt.Left?e-t:n===tt.Right?e+t:e,mde=(e,t,n)=>n===tt.Top?e-t:n===tt.Bottom?e+t:e,RT="react-flow__edgeupdater";function DT({position:e,centerX:t,centerY:n,radius:i=10,onMouseDown:s,onMouseEnter:r,onMouseOut:o,type:c}){return d.jsx("circle",{onMouseDown:s,onMouseEnter:r,onMouseOut:o,className:Wn([RT,`${RT}-${c}`]),cx:pde(t,i,e),cy:mde(n,i,e),r:i,stroke:"transparent",fill:"transparent"})}function gde({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:i,sourceY:s,targetX:r,targetY:o,sourcePosition:c,targetPosition:u,onReconnect:f,onReconnectStart:p,onReconnectEnd:m,setReconnecting:b,setUpdateHover:y}){const x=Nn(),v=(j,T)=>{if(j.button!==0)return;const{autoPanOnConnect:A,domNode:M,connectionMode:R,connectionRadius:P,lib:I,onConnectStart:B,cancelConnection:F,nodeLookup:V,rfId:D,panBy:L,updateConnection:z}=x.getState(),W=T.type==="target",X=(q,Y)=>{b(!1),m==null||m(q,n,T.type,Y)},G=q=>f==null?void 0:f(n,q),U=(q,Y)=>{b(!0),p==null||p(j,n,T.type),B==null||B(q,Y)};O0.onPointerDown(j.nativeEvent,{autoPanOnConnect:A,connectionMode:R,connectionRadius:P,domNode:M,handleId:T.id,nodeId:T.nodeId,nodeLookup:V,isTarget:W,edgeUpdaterType:T.type,lib:I,flowId:D,cancelConnection:F,panBy:L,isValidConnection:(...q)=>{var Y,$;return(($=(Y=x.getState()).isValidConnection)==null?void 0:$.call(Y,...q))??!0},onConnect:G,onConnectStart:U,onConnectEnd:(...q)=>{var Y,$;return($=(Y=x.getState()).onConnectEnd)==null?void 0:$.call(Y,...q)},onReconnectEnd:X,updateConnection:z,getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,dragThreshold:x.getState().connectionDragThreshold,handleDomNode:j.currentTarget})},w=j=>v(j,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),k=j=>v(j,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),C=()=>y(!0),S=()=>y(!1);return d.jsxs(d.Fragment,{children:[(e===!0||e==="source")&&d.jsx(DT,{position:c,centerX:i,centerY:s,radius:t,onMouseDown:w,onMouseEnter:C,onMouseOut:S,type:"source"}),(e===!0||e==="target")&&d.jsx(DT,{position:u,centerX:r,centerY:o,radius:t,onMouseDown:k,onMouseEnter:C,onMouseOut:S,type:"target"})]})}function yde({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:i,onClick:s,onDoubleClick:r,onContextMenu:o,onMouseEnter:c,onMouseMove:u,onMouseLeave:f,reconnectRadius:p,onReconnect:m,onReconnectStart:b,onReconnectEnd:y,rfId:x,edgeTypes:v,noPanClassName:w,onError:k,disableKeyboardA11y:C}){let S=Ut(oe=>oe.edgeLookup.get(e));const j=Ut(oe=>oe.defaultEdgeOptions);S=j?{...j,...S}:S;let T=S.type||"default",A=(v==null?void 0:v[T])||AT[T];A===void 0&&(k==null||k("011",ls.error011(T)),T="default",A=(v==null?void 0:v.default)||AT.default);const M=!!(S.focusable||t&&typeof S.focusable>"u"),R=typeof m<"u"&&(S.reconnectable||n&&typeof S.reconnectable>"u"),P=!!(S.selectable||i&&typeof S.selectable>"u"),I=_.useRef(null),[B,F]=_.useState(!1),[V,D]=_.useState(!1),L=Nn(),{zIndex:z=S.zIndex,sourceX:W,sourceY:X,targetX:G,targetY:U,sourcePosition:q,targetPosition:Y}=Ut(_.useCallback(oe=>{const xe=oe.nodeLookup.get(S.source),fe=oe.nodeLookup.get(S.target);if(!xe||!fe)return MT;const te=rce({id:e,sourceNode:xe,targetNode:fe,sourceHandle:S.sourceHandle||null,targetHandle:S.targetHandle||null,connectionMode:oe.connectionMode,onError:k}),we=Qle({selected:S.selected,zIndex:S.zIndex,sourceNode:xe,targetNode:fe,elevateOnSelect:oe.elevateEdgesOnSelect,zIndexMode:oe.zIndexMode});return{...te||MT,zIndex:we}},[S.source,S.target,S.sourceHandle,S.targetHandle,S.selected,S.zIndex]),Sn),$=_.useMemo(()=>S.markerStart?`url('#${R0(S.markerStart,x)}')`:void 0,[S.markerStart,x]),ie=_.useMemo(()=>S.markerEnd?`url('#${R0(S.markerEnd,x)}')`:void 0,[S.markerEnd,x]);if(S.hidden||W===null||X===null||G===null||U===null)return null;const be=oe=>{var we;const{addSelectedEdges:xe,unselectNodesAndEdges:fe,multiSelectionActive:te}=L.getState();P&&(L.setState({nodesSelectionActive:!1}),S.selected&&te?(fe({nodes:[],edges:[S]}),(we=I.current)==null||we.blur()):xe([e])),s&&s(oe,S)},ce=r?oe=>{r(oe,{...S})}:void 0,_e=o?oe=>{o(oe,{...S})}:void 0,le=c?oe=>{c(oe,{...S})}:void 0,pe=u?oe=>{u(oe,{...S})}:void 0,Te=f?oe=>{f(oe,{...S})}:void 0,ne=oe=>{var xe;if(!C&&FI.includes(oe.key)&&P){const{unselectNodesAndEdges:fe,addSelectedEdges:te}=L.getState();oe.key==="Escape"?((xe=I.current)==null||xe.blur(),fe({edges:[S]})):te([e])}};return d.jsx("svg",{style:{zIndex:z},children:d.jsxs("g",{className:Wn(["react-flow__edge",`react-flow__edge-${T}`,S.className,w,{selected:S.selected,animated:S.animated,inactive:!P&&!s,updating:B,selectable:P}]),onClick:be,onDoubleClick:ce,onContextMenu:_e,onMouseEnter:le,onMouseMove:pe,onMouseLeave:Te,onKeyDown:M?ne:void 0,tabIndex:M?0:void 0,role:S.ariaRole??(M?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":S.ariaLabel===null?void 0:S.ariaLabel||`Edge from ${S.source} to ${S.target}`,"aria-describedby":M?`${wP}-${x}`:void 0,ref:I,...S.domAttributes,children:[!V&&d.jsx(A,{id:e,source:S.source,target:S.target,type:S.type,selected:S.selected,animated:S.animated,selectable:P,deletable:S.deletable??!0,label:S.label,labelStyle:S.labelStyle,labelShowBg:S.labelShowBg,labelBgStyle:S.labelBgStyle,labelBgPadding:S.labelBgPadding,labelBgBorderRadius:S.labelBgBorderRadius,sourceX:W,sourceY:X,targetX:G,targetY:U,sourcePosition:q,targetPosition:Y,data:S.data,style:S.style,sourceHandleId:S.sourceHandle,targetHandleId:S.targetHandle,markerStart:$,markerEnd:ie,pathOptions:"pathOptions"in S?S.pathOptions:void 0,interactionWidth:S.interactionWidth}),R&&d.jsx(gde,{edge:S,isReconnectable:R,reconnectRadius:p,onReconnect:m,onReconnectStart:b,onReconnectEnd:y,sourceX:W,sourceY:X,targetX:G,targetY:U,sourcePosition:q,targetPosition:Y,setUpdateHover:F,setReconnecting:D})]})})}var bde=_.memo(yde);const xde=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function XP({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:i,noPanClassName:s,onReconnect:r,onEdgeContextMenu:o,onEdgeMouseEnter:c,onEdgeMouseMove:u,onEdgeMouseLeave:f,onEdgeClick:p,reconnectRadius:m,onEdgeDoubleClick:b,onReconnectStart:y,onReconnectEnd:x,disableKeyboardA11y:v}){const{edgesFocusable:w,edgesReconnectable:k,elementsSelectable:C,onError:S}=Ut(xde,Sn),j=ide(t);return d.jsxs("div",{className:"react-flow__edges",children:[d.jsx(lde,{defaultColor:e,rfId:n}),j.map(T=>d.jsx(bde,{id:T,edgesFocusable:w,edgesReconnectable:k,elementsSelectable:C,noPanClassName:s,onReconnect:r,onContextMenu:o,onMouseEnter:c,onMouseMove:u,onMouseLeave:f,onClick:p,reconnectRadius:m,onDoubleClick:b,onReconnectStart:y,onReconnectEnd:x,rfId:n,onError:S,edgeTypes:i,disableKeyboardA11y:v},T))]})}XP.displayName="EdgeRenderer";const vde=_.memo(XP),wde=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function Ede({children:e}){const t=Ut(wde);return d.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function kde(e){const t=vg(),n=_.useRef(!1);_.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const Sde=e=>{var t;return(t=e.panZoom)==null?void 0:t.syncViewport};function Nde(e){const t=Ut(Sde),n=Nn();return _.useEffect(()=>{e&&(t==null||t(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function _de(e){return e.connection.inProgress?{...e.connection,to:Mf(e.connection.to,e.transform)}:{...e.connection}}function Cde(e){return _de}function jde(e){const t=Cde();return Ut(t,Sn)}const Tde=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function Ade({containerStyle:e,style:t,type:n,component:i}){const{nodesConnectable:s,width:r,height:o,isValid:c,inProgress:u}=Ut(Tde,Sn);return!(r&&s&&u)?null:d.jsx("svg",{style:e,width:r,height:o,className:"react-flow__connectionline react-flow__container",children:d.jsx("g",{className:Wn(["react-flow__connection",HI(c)]),children:d.jsx(QP,{style:t,type:n,CustomComponent:i,isValid:c})})})}const QP=({style:e,type:t=Va.Bezier,CustomComponent:n,isValid:i})=>{const{inProgress:s,from:r,fromNode:o,fromHandle:c,fromPosition:u,to:f,toNode:p,toHandle:m,toPosition:b,pointer:y}=jde();if(!s)return;if(n)return d.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:o,fromHandle:c,fromX:r.x,fromY:r.y,toX:f.x,toY:f.y,fromPosition:u,toPosition:b,connectionStatus:HI(i),toNode:p,toHandle:m,pointer:y});let x="";const v={sourceX:r.x,sourceY:r.y,sourcePosition:u,targetX:f.x,targetY:f.y,targetPosition:b};switch(t){case Va.Bezier:[x]=iP(v);break;case Va.SimpleBezier:[x]=zP(v);break;case Va.Step:[x]=M0({...v,borderRadius:0});break;case Va.SmoothStep:[x]=M0(v);break;default:[x]=aP(v)}return d.jsx("path",{d:x,fill:"none",className:"react-flow__connection-path",style:e})};QP.displayName="ConnectionLine";const Mde={};function OT(e=Mde){_.useRef(e),Nn(),_.useEffect(()=>{},[e])}function Rde(){Nn(),_.useRef(!1),_.useEffect(()=>{},[])}function ZP({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:i,onEdgeClick:s,onNodeDoubleClick:r,onEdgeDoubleClick:o,onNodeMouseEnter:c,onNodeMouseMove:u,onNodeMouseLeave:f,onNodeContextMenu:p,onSelectionContextMenu:m,onSelectionStart:b,onSelectionEnd:y,connectionLineType:x,connectionLineStyle:v,connectionLineComponent:w,connectionLineContainerStyle:k,selectionKeyCode:C,selectionOnDrag:S,selectionMode:j,multiSelectionKeyCode:T,panActivationKeyCode:A,zoomActivationKeyCode:M,deleteKeyCode:R,onlyRenderVisibleElements:P,elementsSelectable:I,defaultViewport:B,translateExtent:F,minZoom:V,maxZoom:D,preventScrolling:L,defaultMarkerColor:z,zoomOnScroll:W,zoomOnPinch:X,panOnScroll:G,panOnScrollSpeed:U,panOnScrollMode:q,zoomOnDoubleClick:Y,panOnDrag:$,autoPanOnSelection:ie,onPaneClick:be,onPaneMouseEnter:ce,onPaneMouseMove:_e,onPaneMouseLeave:le,onPaneScroll:pe,onPaneContextMenu:Te,paneClickDistance:ne,nodeClickDistance:oe,onEdgeContextMenu:xe,onEdgeMouseEnter:fe,onEdgeMouseMove:te,onEdgeMouseLeave:we,reconnectRadius:Fe,onReconnect:Le,onReconnectStart:ht,onReconnectEnd:nt,noDragClassName:At,noWheelClassName:Nt,noPanClassName:mt,disableKeyboardA11y:Re,nodeExtent:We,rfId:se,viewport:Ee,onViewportChange:De}){return OT(e),OT(t),Rde(),kde(n),Nde(Ee),d.jsx(Gue,{onPaneClick:be,onPaneMouseEnter:ce,onPaneMouseMove:_e,onPaneMouseLeave:le,onPaneContextMenu:Te,onPaneScroll:pe,paneClickDistance:ne,deleteKeyCode:R,selectionKeyCode:C,selectionOnDrag:S,selectionMode:j,onSelectionStart:b,onSelectionEnd:y,multiSelectionKeyCode:T,panActivationKeyCode:A,zoomActivationKeyCode:M,elementsSelectable:I,zoomOnScroll:W,zoomOnPinch:X,zoomOnDoubleClick:Y,panOnScroll:G,panOnScrollSpeed:U,panOnScrollMode:q,panOnDrag:$,autoPanOnSelection:ie,defaultViewport:B,translateExtent:F,minZoom:V,maxZoom:D,onSelectionContextMenu:m,preventScrolling:L,noDragClassName:At,noWheelClassName:Nt,noPanClassName:mt,disableKeyboardA11y:Re,onViewportChange:De,isControlledViewport:!!Ee,children:d.jsxs(Ede,{children:[d.jsx(vde,{edgeTypes:t,onEdgeClick:s,onEdgeDoubleClick:o,onReconnect:Le,onReconnectStart:ht,onReconnectEnd:nt,onlyRenderVisibleElements:P,onEdgeContextMenu:xe,onEdgeMouseEnter:fe,onEdgeMouseMove:te,onEdgeMouseLeave:we,reconnectRadius:Fe,defaultMarkerColor:z,noPanClassName:mt,disableKeyboardA11y:Re,rfId:se}),d.jsx(Ade,{style:v,type:x,component:w,containerStyle:k}),d.jsx("div",{className:"react-flow__edgelabel-renderer"}),d.jsx(nde,{nodeTypes:e,onNodeClick:i,onNodeDoubleClick:r,onNodeMouseEnter:c,onNodeMouseMove:u,onNodeMouseLeave:f,onNodeContextMenu:p,nodeClickDistance:oe,onlyRenderVisibleElements:P,noPanClassName:mt,noDragClassName:At,disableKeyboardA11y:Re,nodeExtent:We,rfId:se}),d.jsx("div",{className:"react-flow__viewport-portal"})]})})}ZP.displayName="GraphView";const Dde=_.memo(ZP),Ode=XI(),LT=({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:s,height:r,fitView:o,fitViewOptions:c,minZoom:u=.5,maxZoom:f=2,nodeOrigin:p,nodeExtent:m,zIndexMode:b="basic"}={})=>{const y=new Map,x=new Map,v=new Map,w=new Map,k=i??t??[],C=n??e??[],S=p??[0,0],j=m??Xd;cP(v,w,k);const{nodesInitialized:T}=D0(C,y,x,{nodeOrigin:S,nodeExtent:j,zIndexMode:b});let A=[0,0,1];if(o&&s&&r){const M=Tf(y,{filter:B=>!!((B.width||B.initialWidth)&&(B.height||B.initialHeight))}),{x:R,y:P,zoom:I}=Dw(M,s,r,u,f,(c==null?void 0:c.padding)??.1);A=[R,P,I]}return{rfId:"1",width:s??0,height:r??0,transform:A,nodes:C,nodesInitialized:T,nodeLookup:y,parentLookup:x,edges:k,edgeLookup:w,connectionLookup:v,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:i!==void 0,panZoom:null,minZoom:u,maxZoom:f,translateExtent:Xd,nodeExtent:j,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Gc.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:S,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:o??!1,fitViewOptions:c,fitViewResolver:null,connection:{...qI},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:Ode,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:$I,zIndexMode:b,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},Lde=({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:s,height:r,fitView:o,fitViewOptions:c,minZoom:u,maxZoom:f,nodeOrigin:p,nodeExtent:m,zIndexMode:b})=>Wce((y,x)=>{async function v(){const{nodeLookup:w,panZoom:k,fitViewOptions:C,fitViewResolver:S,width:j,height:T,minZoom:A,maxZoom:M}=x();k&&(await Hle({nodes:w,width:j,height:T,panZoom:k,minZoom:A,maxZoom:M},C),S==null||S.resolve(!0),y({fitViewResolver:null}))}return{...LT({nodes:e,edges:t,width:s,height:r,fitView:o,fitViewOptions:c,minZoom:u,maxZoom:f,nodeOrigin:p,nodeExtent:m,defaultNodes:n,defaultEdges:i,zIndexMode:b}),setNodes:w=>{const{nodeLookup:k,parentLookup:C,nodeOrigin:S,elevateNodesOnSelect:j,fitViewQueued:T,zIndexMode:A,nodesSelectionActive:M}=x(),{nodesInitialized:R,hasSelectedNodes:P}=D0(w,k,C,{nodeOrigin:S,nodeExtent:m,elevateNodesOnSelect:j,checkEquality:!0,zIndexMode:A}),I=M&&P;T&&R?(v(),y({nodes:w,nodesInitialized:R,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:I})):y({nodes:w,nodesInitialized:R,nodesSelectionActive:I})},setEdges:w=>{const{connectionLookup:k,edgeLookup:C}=x();cP(k,C,w),y({edges:w})},setDefaultNodesAndEdges:(w,k)=>{if(w){const{setNodes:C}=x();C(w),y({hasDefaultNodes:!0})}if(k){const{setEdges:C}=x();C(k),y({hasDefaultEdges:!0})}},updateNodeInternals:w=>{const{triggerNodeChanges:k,nodeLookup:C,parentLookup:S,domNode:j,nodeOrigin:T,nodeExtent:A,debug:M,fitViewQueued:R,zIndexMode:P}=x(),{changes:I,updatedInternals:B}=hce(w,C,S,j,T,A,P);B&&(cce(C,S,{nodeOrigin:T,nodeExtent:A,zIndexMode:P}),R?(v(),y({fitViewQueued:!1,fitViewOptions:void 0})):y({}),(I==null?void 0:I.length)>0&&(M&&console.log("React Flow: trigger node changes",I),k==null||k(I)))},updateNodePositions:(w,k=!1)=>{const C=[];let S=[];const{nodeLookup:j,triggerNodeChanges:T,connection:A,updateConnection:M,onNodesChangeMiddlewareMap:R}=x();for(const[P,I]of w){const B=j.get(P),F=!!(B!=null&&B.expandParent&&(B!=null&&B.parentId)&&(I!=null&&I.position)),V={id:P,type:"position",position:F?{x:Math.max(0,I.position.x),y:Math.max(0,I.position.y)}:I.position,dragging:k};if(B&&A.inProgress&&A.fromNode.id===B.id){const D=yl(B,A.fromHandle,tt.Left,!0);M({...A,from:D})}F&&B.parentId&&C.push({id:P,parentId:B.parentId,rect:{...I.internals.positionAbsolute,width:I.measured.width??0,height:I.measured.height??0}}),S.push(V)}if(C.length>0){const{parentLookup:P,nodeOrigin:I}=x(),B=Bw(C,j,P,I);S.push(...B)}for(const P of R.values())S=P(S);T(S)},triggerNodeChanges:w=>{const{onNodesChange:k,setNodes:C,nodes:S,hasDefaultNodes:j,debug:T}=x();if(w!=null&&w.length){if(j){const A=SP(w,S);C(A)}T&&console.log("React Flow: trigger node changes",w),k==null||k(w)}},triggerEdgeChanges:w=>{const{onEdgesChange:k,setEdges:C,edges:S,hasDefaultEdges:j,debug:T}=x();if(w!=null&&w.length){if(j){const A=NP(w,S);C(A)}T&&console.log("React Flow: trigger edge changes",w),k==null||k(w)}},addSelectedNodes:w=>{const{multiSelectionActive:k,edgeLookup:C,nodeLookup:S,triggerNodeChanges:j,triggerEdgeChanges:T}=x();if(k){const A=w.map(M=>Uo(M,!0));j(A);return}j(bc(S,new Set([...w]),!0)),T(bc(C))},addSelectedEdges:w=>{const{multiSelectionActive:k,edgeLookup:C,nodeLookup:S,triggerNodeChanges:j,triggerEdgeChanges:T}=x();if(k){const A=w.map(M=>Uo(M,!0));T(A);return}T(bc(C,new Set([...w]))),j(bc(S,new Set,!0))},unselectNodesAndEdges:({nodes:w,edges:k}={})=>{const{edges:C,nodes:S,nodeLookup:j,triggerNodeChanges:T,triggerEdgeChanges:A}=x(),M=w||S,R=k||C,P=[];for(const B of M){if(!B.selected)continue;const F=j.get(B.id);F&&(F.selected=!1),P.push(Uo(B.id,!1))}const I=[];for(const B of R)B.selected&&I.push(Uo(B.id,!1));T(P),A(I)},setMinZoom:w=>{const{panZoom:k,maxZoom:C}=x();k==null||k.setScaleExtent([w,C]),y({minZoom:w})},setMaxZoom:w=>{const{panZoom:k,minZoom:C}=x();k==null||k.setScaleExtent([C,w]),y({maxZoom:w})},setTranslateExtent:w=>{var k;(k=x().panZoom)==null||k.setTranslateExtent(w),y({translateExtent:w})},resetSelectedElements:()=>{const{edges:w,nodes:k,triggerNodeChanges:C,triggerEdgeChanges:S,elementsSelectable:j}=x();if(!j)return;const T=k.reduce((M,R)=>R.selected?[...M,Uo(R.id,!1)]:M,[]),A=w.reduce((M,R)=>R.selected?[...M,Uo(R.id,!1)]:M,[]);C(T),S(A)},setNodeExtent:w=>{const{nodes:k,nodeLookup:C,parentLookup:S,nodeOrigin:j,elevateNodesOnSelect:T,nodeExtent:A,zIndexMode:M}=x();w[0][0]===A[0][0]&&w[0][1]===A[0][1]&&w[1][0]===A[1][0]&&w[1][1]===A[1][1]||(D0(k,C,S,{nodeOrigin:j,nodeExtent:w,elevateNodesOnSelect:T,checkEquality:!1,zIndexMode:M}),y({nodeExtent:w}))},panBy:w=>{const{transform:k,width:C,height:S,panZoom:j,translateExtent:T}=x();return pce({delta:w,panZoom:j,transform:k,translateExtent:T,width:C,height:S})},setCenter:async(w,k,C)=>{const{width:S,height:j,maxZoom:T,panZoom:A}=x();if(!A)return!1;const M=typeof(C==null?void 0:C.zoom)<"u"?C.zoom:T;return await A.setViewport({x:S/2-w*M,y:j/2-k*M,zoom:M},{duration:C==null?void 0:C.duration,ease:C==null?void 0:C.ease,interpolate:C==null?void 0:C.interpolate}),!0},cancelConnection:()=>{y({connection:{...qI}})},updateConnection:w=>{y({connection:w})},reset:()=>y({...LT()})}},Object.is);function JP({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:i,initialWidth:s,initialHeight:r,initialMinZoom:o,initialMaxZoom:c,initialFitViewOptions:u,fitView:f,nodeOrigin:p,nodeExtent:m,zIndexMode:b,children:y}){const[x]=_.useState(()=>Lde({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:s,height:r,fitView:f,minZoom:o,maxZoom:c,fitViewOptions:u,nodeOrigin:p,nodeExtent:m,zIndexMode:b}));return d.jsx(Yce,{value:x,children:d.jsx(xue,{children:d.jsx(Oue,{children:y})})})}function Ide({children:e,nodes:t,edges:n,defaultNodes:i,defaultEdges:s,width:r,height:o,fitView:c,fitViewOptions:u,minZoom:f,maxZoom:p,nodeOrigin:m,nodeExtent:b,zIndexMode:y}){return _.useContext(bg)?d.jsx(d.Fragment,{children:e}):d.jsx(JP,{initialNodes:t,initialEdges:n,defaultNodes:i,defaultEdges:s,initialWidth:r,initialHeight:o,fitView:c,initialFitViewOptions:u,initialMinZoom:f,initialMaxZoom:p,nodeOrigin:m,nodeExtent:b,zIndexMode:y,children:e})}const Pde={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function zde({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,className:s,nodeTypes:r,edgeTypes:o,onNodeClick:c,onEdgeClick:u,onInit:f,onMove:p,onMoveStart:m,onMoveEnd:b,onConnect:y,onConnectStart:x,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:k,onNodeMouseEnter:C,onNodeMouseMove:S,onNodeMouseLeave:j,onNodeContextMenu:T,onNodeDoubleClick:A,onNodeDragStart:M,onNodeDrag:R,onNodeDragStop:P,onNodesDelete:I,onEdgesDelete:B,onDelete:F,onSelectionChange:V,onSelectionDragStart:D,onSelectionDrag:L,onSelectionDragStop:z,onSelectionContextMenu:W,onSelectionStart:X,onSelectionEnd:G,onBeforeDelete:U,connectionMode:q,connectionLineType:Y=Va.Bezier,connectionLineStyle:$,connectionLineComponent:ie,connectionLineContainerStyle:be,deleteKeyCode:ce="Backspace",selectionKeyCode:_e="Shift",selectionOnDrag:le=!1,selectionMode:pe=Qd.Full,panActivationKeyCode:Te="Space",multiSelectionKeyCode:ne=Jd()?"Meta":"Control",zoomActivationKeyCode:oe=Jd()?"Meta":"Control",snapToGrid:xe,snapGrid:fe,onlyRenderVisibleElements:te=!1,selectNodesOnDrag:we,nodesDraggable:Fe,autoPanOnNodeFocus:Le,nodesConnectable:ht,nodesFocusable:nt,nodeOrigin:At=EP,edgesFocusable:Nt,edgesReconnectable:mt,elementsSelectable:Re=!0,defaultViewport:We=lue,minZoom:se=.5,maxZoom:Ee=2,translateExtent:De=Xd,preventScrolling:ye=!0,nodeExtent:et,defaultMarkerColor:Pt="#b1b1b7",zoomOnScroll:Wt=!0,zoomOnPinch:me=!0,panOnScroll:ae=!1,panOnScrollSpeed:je=.5,panOnScrollMode:Ae=ol.Free,zoomOnDoubleClick:Qe=!0,panOnDrag:rt=!0,onPaneClick:Ue,onPaneMouseEnter:it,onPaneMouseMove:qt,onPaneMouseLeave:Qt,onPaneScroll:Ot,onPaneContextMenu:Q,paneClickDistance:ke=1,nodeClickDistance:Pe=0,children:ct,onReconnect:Zt,onReconnectStart:Ht,onReconnectEnd:He,onEdgeContextMenu:$e,onEdgeDoubleClick:at,onEdgeMouseEnter:hn,onEdgeMouseMove:on,onEdgeMouseLeave:ki,reconnectRadius:us=10,onNodesChange:ds,onEdgesChange:Di,noDragClassName:pn="nodrag",noWheelClassName:In="nowheel",noPanClassName:Yn="nopan",fitView:Ds,fitViewOptions:Mr,connectOnClick:Os,attributionPosition:Rr,proOptions:fs,defaultEdgeOptions:Dr,elevateNodesOnSelect:Xn=!0,elevateEdgesOnSelect:Ki=!1,disableKeyboardA11y:Si=!1,autoPanOnConnect:hs,autoPanOnNodeDrag:wn,autoPanOnSelection:Or=!0,autoPanSpeed:Qn,connectionRadius:An,isValidConnection:Me,onError:Xe,style:xt,id:zt,nodeDragThreshold:gn,connectionDragThreshold:Fn,viewport:ci,onViewportChange:ti,width:Vt,height:ni,colorMode:Lr="light",debug:ii,onScroll:si,ariaLabelConfig:Ls,zIndexMode:ma="basic",...ri},Gi){const yi=zt||"1",Is=fue(Lr),Mn=_.useCallback(rr=>{rr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),si==null||si(rr)},[si]);return d.jsx("div",{"data-testid":"rf__wrapper",...ri,onScroll:Mn,style:{...xt,...Pde},ref:Gi,className:Wn(["react-flow",s,Is]),id:zt,role:"application",children:d.jsxs(Ide,{nodes:e,edges:t,width:Vt,height:ni,fitView:Ds,fitViewOptions:Mr,minZoom:se,maxZoom:Ee,nodeOrigin:At,nodeExtent:et,zIndexMode:ma,children:[d.jsx(due,{nodes:e,edges:t,defaultNodes:n,defaultEdges:i,onConnect:y,onConnectStart:x,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:k,nodesDraggable:Fe,autoPanOnNodeFocus:Le,nodesConnectable:ht,nodesFocusable:nt,edgesFocusable:Nt,edgesReconnectable:mt,elementsSelectable:Re,elevateNodesOnSelect:Xn,elevateEdgesOnSelect:Ki,minZoom:se,maxZoom:Ee,nodeExtent:et,onNodesChange:ds,onEdgesChange:Di,snapToGrid:xe,snapGrid:fe,connectionMode:q,translateExtent:De,connectOnClick:Os,defaultEdgeOptions:Dr,fitView:Ds,fitViewOptions:Mr,onNodesDelete:I,onEdgesDelete:B,onDelete:F,onNodeDragStart:M,onNodeDrag:R,onNodeDragStop:P,onSelectionDrag:L,onSelectionDragStart:D,onSelectionDragStop:z,onMove:p,onMoveStart:m,onMoveEnd:b,noPanClassName:Yn,nodeOrigin:At,rfId:yi,autoPanOnConnect:hs,autoPanOnNodeDrag:wn,autoPanSpeed:Qn,onError:Xe,connectionRadius:An,isValidConnection:Me,selectNodesOnDrag:we,nodeDragThreshold:gn,connectionDragThreshold:Fn,onBeforeDelete:U,debug:ii,ariaLabelConfig:Ls,zIndexMode:ma}),d.jsx(Dde,{onInit:f,onNodeClick:c,onEdgeClick:u,onNodeMouseEnter:C,onNodeMouseMove:S,onNodeMouseLeave:j,onNodeContextMenu:T,onNodeDoubleClick:A,nodeTypes:r,edgeTypes:o,connectionLineType:Y,connectionLineStyle:$,connectionLineComponent:ie,connectionLineContainerStyle:be,selectionKeyCode:_e,selectionOnDrag:le,selectionMode:pe,deleteKeyCode:ce,multiSelectionKeyCode:ne,panActivationKeyCode:Te,zoomActivationKeyCode:oe,onlyRenderVisibleElements:te,defaultViewport:We,translateExtent:De,minZoom:se,maxZoom:Ee,preventScrolling:ye,zoomOnScroll:Wt,zoomOnPinch:me,zoomOnDoubleClick:Qe,panOnScroll:ae,panOnScrollSpeed:je,panOnScrollMode:Ae,panOnDrag:rt,autoPanOnSelection:Or,onPaneClick:Ue,onPaneMouseEnter:it,onPaneMouseMove:qt,onPaneMouseLeave:Qt,onPaneScroll:Ot,onPaneContextMenu:Q,paneClickDistance:ke,nodeClickDistance:Pe,onSelectionContextMenu:W,onSelectionStart:X,onSelectionEnd:G,onReconnect:Zt,onReconnectStart:Ht,onReconnectEnd:He,onEdgeContextMenu:$e,onEdgeDoubleClick:at,onEdgeMouseEnter:hn,onEdgeMouseMove:on,onEdgeMouseLeave:ki,reconnectRadius:us,defaultMarkerColor:Pt,noDragClassName:pn,noWheelClassName:In,noPanClassName:Yn,rfId:yi,disableKeyboardA11y:Si,nodeExtent:et,viewport:ci,onViewportChange:ti}),d.jsx(oue,{onSelectionChange:V}),ct,d.jsx(nue,{proOptions:fs,position:Rr}),d.jsx(tue,{rfId:yi,disableKeyboardA11y:Si})]})})}var Bde=jP(zde);function Ude(e){const[t,n]=_.useState(e),i=_.useCallback(s=>n(r=>SP(s,r)),[]);return[t,n,i]}function Fde(e){const[t,n]=_.useState(e),i=_.useCallback(s=>n(r=>NP(s,r)),[]);return[t,n,i]}function $de({dimensions:e,lineWidth:t,variant:n,className:i}){return d.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Wn(["react-flow__background-pattern",n,i])})}function qde({radius:e,className:t}){return d.jsx("circle",{cx:e,cy:e,r:e,className:Wn(["react-flow__background-pattern","dots",t])})}var ca;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(ca||(ca={}));const Hde={[ca.Dots]:1,[ca.Lines]:1,[ca.Cross]:6},Vde=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function e3({id:e,variant:t=ca.Dots,gap:n=20,size:i,lineWidth:s=1,offset:r=0,color:o,bgColor:c,style:u,className:f,patternClassName:p}){const m=_.useRef(null),{transform:b,patternId:y}=Ut(Vde,Sn),x=i||Hde[t],v=t===ca.Dots,w=t===ca.Cross,k=Array.isArray(n)?n:[n,n],C=[k[0]*b[2]||1,k[1]*b[2]||1],S=x*b[2],j=Array.isArray(r)?r:[r,r],T=w?[S,S]:C,A=[j[0]*b[2]||1+T[0]/2,j[1]*b[2]||1+T[1]/2],M=`${y}${e||""}`;return d.jsxs("svg",{className:Wn(["react-flow__background",f]),style:{...u,...wg,"--xy-background-color-props":c,"--xy-background-pattern-color-props":o},ref:m,"data-testid":"rf__background",children:[d.jsx("pattern",{id:M,x:b[0]%C[0],y:b[1]%C[1],width:C[0],height:C[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${A[0]},-${A[1]})`,children:v?d.jsx(qde,{radius:S/2,className:p}):d.jsx($de,{dimensions:T,lineWidth:s,variant:t,className:p})}),d.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${M})`})]})}e3.displayName="Background";const Kde=_.memo(e3);function Gde(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:d.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function Wde(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:d.jsx("path",{d:"M0 0h32v4.2H0z"})})}function Yde(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:d.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 Xde(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:d.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 Qde(){return d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:d.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 xd({children:e,className:t,...n}){return d.jsx("button",{type:"button",className:Wn(["react-flow__controls-button",t]),...n,children:e})}const Zde=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function t3({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:i=!0,fitViewOptions:s,onZoomIn:r,onZoomOut:o,onFitView:c,onInteractiveChange:u,className:f,children:p,position:m="bottom-left",orientation:b="vertical","aria-label":y}){const x=Nn(),{isInteractive:v,minZoomReached:w,maxZoomReached:k,ariaLabelConfig:C}=Ut(Zde,Sn),{zoomIn:S,zoomOut:j,fitView:T}=vg(),A=()=>{S(),r==null||r()},M=()=>{j(),o==null||o()},R=()=>{T(s),c==null||c()},P=()=>{x.setState({nodesDraggable:!v,nodesConnectable:!v,elementsSelectable:!v}),u==null||u(!v)},I=b==="horizontal"?"horizontal":"vertical";return d.jsxs(xg,{className:Wn(["react-flow__controls",I,f]),position:m,style:e,"data-testid":"rf__controls","aria-label":y??C["controls.ariaLabel"],children:[t&&d.jsxs(d.Fragment,{children:[d.jsx(xd,{onClick:A,className:"react-flow__controls-zoomin",title:C["controls.zoomIn.ariaLabel"],"aria-label":C["controls.zoomIn.ariaLabel"],disabled:k,children:d.jsx(Gde,{})}),d.jsx(xd,{onClick:M,className:"react-flow__controls-zoomout",title:C["controls.zoomOut.ariaLabel"],"aria-label":C["controls.zoomOut.ariaLabel"],disabled:w,children:d.jsx(Wde,{})})]}),n&&d.jsx(xd,{className:"react-flow__controls-fitview",onClick:R,title:C["controls.fitView.ariaLabel"],"aria-label":C["controls.fitView.ariaLabel"],children:d.jsx(Yde,{})}),i&&d.jsx(xd,{className:"react-flow__controls-interactive",onClick:P,title:C["controls.interactive.ariaLabel"],"aria-label":C["controls.interactive.ariaLabel"],children:v?d.jsx(Qde,{}):d.jsx(Xde,{})}),p]})}t3.displayName="Controls";const Jde=_.memo(t3);function efe({id:e,x:t,y:n,width:i,height:s,style:r,color:o,strokeColor:c,strokeWidth:u,className:f,borderRadius:p,shapeRendering:m,selected:b,onClick:y}){const{background:x,backgroundColor:v}=r||{},w=o||x||v;return d.jsx("rect",{className:Wn(["react-flow__minimap-node",{selected:b},f]),x:t,y:n,rx:p,ry:p,width:i,height:s,style:{fill:w,stroke:c,strokeWidth:u},shapeRendering:m,onClick:y?k=>y(k,e):void 0})}const tfe=_.memo(efe),nfe=e=>e.nodes.map(t=>t.id),Xx=e=>e instanceof Function?e:()=>e;function ife({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:i=5,nodeStrokeWidth:s,nodeComponent:r=tfe,onClick:o}){const c=Ut(nfe,Sn),u=Xx(t),f=Xx(e),p=Xx(n),m=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return d.jsx(d.Fragment,{children:c.map(b=>d.jsx(rfe,{id:b,nodeColorFunc:u,nodeStrokeColorFunc:f,nodeClassNameFunc:p,nodeBorderRadius:i,nodeStrokeWidth:s,NodeComponent:r,onClick:o,shapeRendering:m},b))})}function sfe({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:i,nodeBorderRadius:s,nodeStrokeWidth:r,shapeRendering:o,NodeComponent:c,onClick:u}){const{node:f,x:p,y:m,width:b,height:y}=Ut(x=>{const v=x.nodeLookup.get(e);if(!v)return{node:void 0,x:0,y:0,width:0,height:0};const w=v.internals.userNode,{x:k,y:C}=v.internals.positionAbsolute,{width:S,height:j}=pa(w);return{node:w,x:k,y:C,width:S,height:j}},Sn);return!f||f.hidden||!QI(f)?null:d.jsx(c,{x:p,y:m,width:b,height:y,style:f.style,selected:!!f.selected,className:i(f),color:t(f),borderRadius:s,strokeColor:n(f),strokeWidth:r,shapeRendering:o,onClick:u,id:f.id})}const rfe=_.memo(sfe);var afe=_.memo(ife);const ofe=200,lfe=150,cfe=e=>!e.hidden,ufe=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?WI(Tf(e.nodeLookup,{filter:cfe}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},dfe="react-flow__minimap-desc";function n3({style:e,className:t,nodeStrokeColor:n,nodeColor:i,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:o,nodeComponent:c,bgColor:u,maskColor:f,maskStrokeColor:p,maskStrokeWidth:m,position:b="bottom-right",onClick:y,onNodeClick:x,pannable:v=!1,zoomable:w=!1,ariaLabel:k,inversePan:C,zoomStep:S=1,offsetScale:j=5}){const T=Nn(),A=_.useRef(null),{boundingRect:M,viewBB:R,rfId:P,panZoom:I,translateExtent:B,flowWidth:F,flowHeight:V,ariaLabelConfig:D}=Ut(ufe,Sn),L=(e==null?void 0:e.width)??ofe,z=(e==null?void 0:e.height)??lfe,W=M.width/L,X=M.height/z,G=Math.max(W,X),U=G*L,q=G*z,Y=j*G,$=M.x-(U-M.width)/2-Y,ie=M.y-(q-M.height)/2-Y,be=U+Y*2,ce=q+Y*2,_e=`${dfe}-${P}`,le=_.useRef(0),pe=_.useRef();le.current=G,_.useEffect(()=>{if(A.current&&I)return pe.current=kce({domNode:A.current,panZoom:I,getTransform:()=>T.getState().transform,getViewScale:()=>le.current}),()=>{var xe;(xe=pe.current)==null||xe.destroy()}},[I]),_.useEffect(()=>{var xe;(xe=pe.current)==null||xe.update({translateExtent:B,width:F,height:V,inversePan:C,pannable:v,zoomStep:S,zoomable:w})},[v,w,C,S,B,F,V]);const Te=y?xe=>{var we;const[fe,te]=((we=pe.current)==null?void 0:we.pointer(xe))||[0,0];y(xe,{x:fe,y:te})}:void 0,ne=x?_.useCallback((xe,fe)=>{const te=T.getState().nodeLookup.get(fe).internals.userNode;x(xe,te)},[]):void 0,oe=k??D["minimap.ariaLabel"];return d.jsx(xg,{position:b,style:{...e,"--xy-minimap-background-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-background-color-props":typeof f=="string"?f:void 0,"--xy-minimap-mask-stroke-color-props":typeof p=="string"?p:void 0,"--xy-minimap-mask-stroke-width-props":typeof m=="number"?m*G:void 0,"--xy-minimap-node-background-color-props":typeof i=="string"?i:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof o=="number"?o:void 0},className:Wn(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:d.jsxs("svg",{width:L,height:z,viewBox:`${$} ${ie} ${be} ${ce}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":_e,ref:A,onClick:Te,children:[oe&&d.jsx("title",{id:_e,children:oe}),d.jsx(afe,{onClick:ne,nodeColor:i,nodeStrokeColor:n,nodeBorderRadius:r,nodeClassName:s,nodeStrokeWidth:o,nodeComponent:c}),d.jsx("path",{className:"react-flow__minimap-mask",d:`M${$-Y},${ie-Y}h${be+Y*2}v${ce+Y*2}h${-be-Y*2}z
|
|
863
863
|
M${R.x},${R.y}h${R.width}v${R.height}h${-R.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}n3.displayName="MiniMap";_.memo(n3);const ffe=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,hfe={[Xc.Line]:"right",[Xc.Handle]:"bottom-right"};function pfe({nodeId:e,position:t,variant:n=Xc.Handle,className:i,style:s=void 0,children:r,color:o,minWidth:c=10,minHeight:u=10,maxWidth:f=Number.MAX_VALUE,maxHeight:p=Number.MAX_VALUE,keepAspectRatio:m=!1,resizeDirection:b,autoScale:y=!0,shouldResize:x,onResizeStart:v,onResize:w,onResizeEnd:k}){const C=RP(),S=typeof e=="string"?e:C,j=Nn(),T=_.useRef(null),A=n===Xc.Handle,M=Ut(_.useCallback(ffe(A&&y),[A,y]),Sn),R=_.useRef(null),P=t??hfe[n];_.useEffect(()=>{if(!(!T.current||!S))return R.current||(R.current=Ice({domNode:T.current,nodeId:S,getStoreItems:()=>{const{nodeLookup:B,transform:F,snapGrid:V,snapToGrid:D,nodeOrigin:L,domNode:z}=j.getState();return{nodeLookup:B,transform:F,snapGrid:V,snapToGrid:D,nodeOrigin:L,paneDomNode:z}},onChange:(B,F)=>{const{triggerNodeChanges:V,nodeLookup:D,parentLookup:L,nodeOrigin:z}=j.getState(),W=[],X={x:B.x,y:B.y},G=D.get(S);if(G&&G.expandParent&&G.parentId){const U=G.origin??z,q=B.width??G.measured.width??0,Y=B.height??G.measured.height??0,$={id:G.id,parentId:G.parentId,rect:{width:q,height:Y,...ZI({x:B.x??G.position.x,y:B.y??G.position.y},{width:q,height:Y},G.parentId,D,U)}},ie=Bw([$],D,L,z);W.push(...ie),X.x=B.x?Math.max(U[0]*q,B.x):void 0,X.y=B.y?Math.max(U[1]*Y,B.y):void 0}if(X.x!==void 0&&X.y!==void 0){const U={id:S,type:"position",position:{...X}};W.push(U)}if(B.width!==void 0&&B.height!==void 0){const q={id:S,type:"dimensions",resizing:!0,setAttributes:b?b==="horizontal"?"width":"height":!0,dimensions:{width:B.width,height:B.height}};W.push(q)}for(const U of F){const q={...U,type:"position"};W.push(q)}V(W)},onEnd:({width:B,height:F})=>{const V={id:S,type:"dimensions",resizing:!1,dimensions:{width:B,height:F}};j.getState().triggerNodeChanges([V])}})),R.current.update({controlPosition:P,boundaries:{minWidth:c,minHeight:u,maxWidth:f,maxHeight:p},keepAspectRatio:m,resizeDirection:b,onResizeStart:v,onResize:w,onResizeEnd:k,shouldResize:x}),()=>{var B;(B=R.current)==null||B.destroy()}},[P,c,u,f,p,m,v,w,k,x]);const I=P.split("-");return d.jsx("div",{className:Wn(["react-flow__resize-control","nodrag",...I,n,i]),ref:T,style:{...s,scale:M,...o&&{[A?"backgroundColor":"borderColor"]:o}},children:r})}_.memo(pfe);function mfe(e){return wt(`/api/projects/${encodeURIComponent(e)}/flow`)}function gfe(e,t){return Pm(`/api/projects/${encodeURIComponent(e)}/flow`,t)}const yfe=new Set(["NEEDS-FIX","STALE-UPSTREAM","BLOCKED","CONFLICT","ACK-TIMEOUT"]),IT="AI-PIPELINE",I0={done:"var(--color-running)",doing:"var(--color-running)",todo:"var(--color-text-subtle)",stuck:"var(--color-crashed)"},PT=["var(--color-accent-mint)","var(--color-accent-pink)","var(--color-accent-purple)","var(--color-accent-yellow)","var(--color-running-bg)","var(--color-idle-bg)"];function bfe(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)>>>0;return PT[t%PT.length]}const wp={width:9,height:9,background:"var(--color-bg)",border:"1px solid var(--color-border-light)"},xfe=_.memo(function({id:t,data:n,selected:i}){const s=n,r=s.skills.split(",").map(u=>u.trim()).filter(Boolean),o=(s.labels??"").split(",").map(u=>u.trim()).filter(Boolean),c=o.filter(u=>yfe.has(u));return d.jsxs("div",{className:`flow-node-glow${i?" is-selected":""}${s.status==="doing"?" is-running":""}`,children:[d.jsx(no,{id:"l",type:"target",position:tt.Left,style:wp}),d.jsx(no,{id:"t",type:"target",position:tt.Top,style:wp}),d.jsxs("div",{className:"rounded-2xl border border-[var(--color-border-light)] bg-[var(--color-bg-soft)] overflow-hidden cursor-pointer flex flex-col",style:{width:260,height:158,boxShadow:"var(--surface-card-border) 0 0 0 1px inset"},children:[d.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-[var(--color-border-light)]",style:{background:bfe(t)},children:[d.jsxs("span",{className:"font-[family-name:var(--font-mono)] text-xs font-bold text-[var(--color-text)]",children:["#",s.seq]}),s.kind&&s.kind!=="worker"&&d.jsx("span",{className:"font-[family-name:var(--font-mono)] text-[10px] px-1 rounded bg-[var(--color-bg)] text-[var(--color-text-subtle)] truncate max-w-[7rem]",title:s.tool??s.kind,children:s.kind==="tool"?`⚙ ${s.tool??"tool"}`:`⇥ ${s.kind}`}),d.jsxs("span",{className:"relative shrink-0 ml-auto flex items-center justify-center w-2.5 h-2.5",title:s.status,children:[s.status==="doing"&&d.jsx("span",{className:"absolute inline-flex w-full h-full rounded-full animate-ping opacity-60",style:{background:I0.doing}}),d.jsx("span",{className:"relative w-2.5 h-2.5 rounded-full",style:{background:I0[s.status]??"var(--color-text-subtle)"}})]})]}),d.jsxs("div",{className:"px-2.5 py-2 flex-1 min-h-0 overflow-hidden",children:[d.jsx("p",{className:"text-[13px] font-semibold text-[var(--color-text)] leading-snug line-clamp-3",children:s.title||"任务"}),!o.includes(IT)&&d.jsxs("div",{className:"mt-1.5 text-[10px] font-[family-name:var(--font-mono)] text-[var(--color-crashed)]",children:["无 ",IT," · 不会被派"]}),c.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1 mt-1.5",children:c.map(u=>d.jsx("span",{className:"text-[10px] font-[family-name:var(--font-mono)] px-1.5 py-0.5 rounded border border-[var(--color-crashed)] text-[var(--color-crashed)]",children:u},u))}),r.length>0&&d.jsx("div",{className:"flex flex-wrap gap-1 mt-2 max-h-[46px] overflow-hidden",children:r.slice(0,6).map(u=>d.jsx("span",{className:"text-[10px] font-[family-name:var(--font-mono)] px-1.5 py-0.5 rounded bg-[var(--surface-code)] text-[var(--color-text)]",children:u},u))})]})]}),d.jsx(no,{id:"r",type:"source",position:tt.Right,style:wp}),d.jsx(no,{id:"b",type:"source",position:tt.Bottom,style:wp})]})});function vfe(e){if(!e)return"";const t=e.split(`
|
|
864
864
|
`),n=t.findIndex(s=>/^##\s+描述\s*$/.test(s));if(n===-1)return"";let i=t.length;for(let s=n+1;s<t.length;s+=1)if(/^##\s+/.test(t[s]??"")){i=s;break}return t.slice(n+1,i).join(`
|
|
865
|
-
`).trim()}function wfe(e,t){return t.includes("NEEDS-FIX")?"stuck":e==="Done"?"done":e==="Inprogress"?"doing":"todo"}function Efe({project:e,seq:t,onClose:n,onChanged:i,onDelete:s}){var Te,ne;const r=Ye(),[o,c]=_.useState(!0),[u,f]=_.useState(!1),[p,m]=_.useState(""),[b,y]=_.useState(""),[x,v]=_.useState(new Set),[w,k]=_.useState(""),[C,S]=_.useState("todo"),[j,T]=_.useState(null),[A,M]=_.useState(""),[R,P]=_.useState(void 0),[I,B]=_.useState(void 0),[F,V]=_.useState(void 0),[D,L]=_.useState(void 0),[z,W]=_.useState({value:null,error:"",dirty:!1}),[X,G]=_.useState(null),[U,q]=_.useState(null),Y=U??R,$=Y==="tool"||Y==="join",ie=Je({queryKey:["skills-all",e],queryFn:()=>og(e),enabled:!$}),be=((Te=ie.data)==null?void 0:Te.data)??[],ce=Je({queryKey:["capabilities",e],queryFn:()=>vw(e),enabled:$});_.useEffect(()=>{const oe=xe=>{xe.key==="Escape"&&n()};return window.addEventListener("keydown",oe),()=>window.removeEventListener("keydown",oe)},[n]),_.useEffect(()=>{let oe=!1;return c(!0),QL(e,t).then(xe=>{oe||(m(xe.title),v(new Set(xe.skills??[])),y(vfe(xe.body)),k(xe.state),S(wfe(xe.state,xe.labels??[])),T(typeof xe.order=="number"?xe.order:null),P(xe.kind),B(xe.tool),G(null),q(null),V(xe.input),L(xe.toolResult))}).catch(()=>{}).finally(()=>{oe||c(!1)}),()=>{oe=!0}},[e,t]);const _e=oe=>{v(xe=>{const fe=new Set(xe);return fe.has(oe)?fe.delete(oe):fe.add(oe),fe})},le=async()=>{if(M(""),$&&z.error){M(z.error);return}f(!0);try{await wm(e,t,{title:p.trim()||r("flow.node.default"),...U?{kind:U}:{},...$?{...X||U==="tool"?{tool:X??I??"art.inspect"}:{},...z.dirty||U==="tool"?{input:z.value??{in:""}}:{}}:{description:b,skills:[...x]}}),i(),n()}catch(oe){M(oe instanceof Error?oe.message:String(oe)),f(!1)}},pe=()=>s(t);return d.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-40 flex items-center justify-center p-4 md:p-6 bg-black/30 overflow-hidden",onClick:n,children:d.jsxs("div",{className:"nb-card w-full max-w-4xl flex flex-col bg-[var(--color-bg)]",style:{maxHeight:"calc(100vh - 48px)"},onClick:oe=>oe.stopPropagation(),children:[d.jsxs("header",{className:"flex items-start justify-between gap-4 mb-4 flex-shrink-0",children:[d.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[d.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-xs px-2 py-0.5 bg-[var(--color-accent-purple)] border-2 border-[var(--color-text)] rounded-full",children:["#",t]}),w&&d.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs px-2 py-0.5 border-2 border-[var(--color-text)] rounded-full font-semibold",children:[d.jsx("span",{className:"w-2.5 h-2.5 rounded-full inline-block border border-[var(--color-text)]",style:{background:I0[C]??"gray"}}),w]}),j!=null&&d.jsx("span",{className:"font-[family-name:var(--font-mono)] text-xs px-2 py-0.5 bg-[var(--color-accent-mint)] border-2 border-[var(--color-text)] rounded-full font-semibold",title:r("flow.lane.orderTip"),children:r("flow.lane.wave",{n:j})})]}),d.jsx("button",{onClick:n,className:"nb-btn nb-btn-mint p-2 flex-shrink-0","aria-label":r("flow.node.close"),type:"button",children:d.jsx(vn,{size:14,strokeWidth:3})})]}),o?d.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--color-text-muted)] py-10 justify-center",children:[d.jsx(pt,{size:16,className:"animate-spin"})," …"]}):d.jsxs(d.Fragment,{children:[A&&d.jsx("div",{className:"text-sm text-[var(--color-crashed)] mb-3",children:A}),d.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[d.jsx("span",{className:"text-sm font-bold",children:r("card.kind.label")}),["worker","tool"].map(oe=>d.jsx("button",{type:"button",onClick:()=>q(oe===(R??"worker")?null:oe),"aria-pressed":Y===oe||oe==="worker"&&!$,className:["px-2.5 py-1 text-xs rounded-full border-2 transition-all font-[family-name:var(--font-mono)]",(oe==="tool"?$:!$)?"bg-[var(--color-accent-mint)] border-[var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),children:r(oe==="tool"?"card.kind.tool":"card.kind.worker")},oe)),U&&d.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:r("card.kind.pending")})]}),$&&(z.dirty||X)&&D&&d.jsxs("div",{className:"mb-3 text-xs text-[var(--color-text-muted)]",children:["⚠️ ",r("tool.card.staleWarn")]}),d.jsxs("div",{className:$?"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pr-1":"grid min-h-0 flex-1 grid-cols-1 gap-4 overflow-y-auto pr-1 md:grid-cols-[minmax(0,1fr)_minmax(260px,340px)] md:overflow-hidden md:pr-0",children:[d.jsxs("label",{className:$?"flex flex-col gap-1.5":"hidden",children:[d.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),d.jsx("input",{className:"nb-input w-full text-base font-semibold",value:p,onChange:oe=>m(oe.target.value)})]}),$&&d.jsx(vm,{tool:X??I,input:F,toolResult:D,capabilities:((ne=ce.data)==null?void 0:ne.data)??[],onChange:W,onToolChange:G}),!$&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex min-h-0 flex-col gap-4 md:overflow-y-auto md:pr-1",children:[d.jsxs("label",{className:"flex flex-col gap-1.5",children:[d.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),d.jsx("input",{className:"nb-input w-full text-base font-semibold",value:p,onChange:oe=>m(oe.target.value),autoFocus:!0})]}),d.jsxs("label",{className:"flex flex-1 min-h-0 flex-col gap-1.5",children:[d.jsx("span",{className:"text-sm font-bold",children:r("flow.node.desc")}),d.jsx("textarea",{className:"nb-input w-full flex-1 min-h-0",style:{minHeight:200,resize:"vertical"},value:b,onChange:oe=>y(oe.target.value)})]})]}),d.jsxs("section",{className:"flex min-h-[200px] flex-col gap-2 md:min-h-0 md:overflow-hidden",children:[d.jsx("span",{className:"text-sm font-bold",children:r("flow.node.skills")}),d.jsx("div",{className:"scroll-frame min-h-0 flex-1 rounded-lg border-2 border-[var(--color-border-light)] bg-[var(--color-bg-cream)]",children:d.jsxs("div",{className:"scroll-frame-body h-full p-2",children:[ie.isLoading&&d.jsx(pt,{size:14,className:"animate-spin text-[var(--color-text-muted)]"}),be.length>0&&d.jsx("div",{className:"flex flex-wrap gap-2",children:be.map(oe=>{const xe=x.has(oe.name);return d.jsx("button",{type:"button",onClick:()=>_e(oe.name),className:["max-w-full break-all px-2.5 py-1 text-left text-xs font-[family-name:var(--font-mono)] rounded-full border-2 transition-all",xe?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[2px_2px_0_var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),"aria-pressed":xe,children:oe.name},oe.name)})})]})}),x.size>0&&d.jsx("p",{className:"max-h-14 overflow-y-auto break-words text-xs text-[var(--color-text-muted)]",children:[...x].join(", ")})]})]})]}),d.jsxs("div",{className:"flex gap-2 justify-between mt-4 pt-3 border-t-2 border-dashed border-[var(--color-text)] flex-shrink-0",children:[d.jsxs("button",{type:"button",className:"nb-btn nb-btn-danger",onClick:()=>void pe(),disabled:u,children:[d.jsx(cs,{size:14,strokeWidth:2.4})," ",r("flow.node.delete")]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta",onClick:()=>void le(),disabled:u||$&&z.error!=="",children:[u?d.jsx(pt,{size:14,className:"animate-spin"}):null,r("flow.node.save")]})]})]})]})})}const kfe=_.memo(function({data:t}){const n=t;return d.jsxs("div",{className:"relative w-full h-full rounded-2xl border-2 border-dashed border-[var(--color-text)]",children:[d.jsx("div",{className:"absolute inset-0 rounded-2xl",style:{background:n.color,opacity:.16}}),d.jsxs("span",{className:"absolute top-1.5 left-2.5 inline-flex items-center gap-1.5 px-2 py-0.5 text-[11px] font-bold rounded-md border-2 border-[var(--color-text)] bg-[var(--color-bg)] text-[var(--color-text)] whitespace-nowrap max-w-[90%]",children:[d.jsx("span",{className:"truncate",children:n.label}),n.sub&&d.jsx("span",{className:"font-normal text-[var(--color-text-muted)]",children:n.sub})]})]})});function Sfe(e){const t=e;if(typeof t.seq=="number")return t.seq;const n=/#(\d+)/.exec(t.output??"");return n?Number(n[1]):null}const Nfe={task:xfe,waveBox:kfe},zT="sps.flow.lastProject",BT="sps.flow.mode";function UT(e){return(e.labels??[]).includes("NEEDS-FIX")?"stuck":e.state==="Done"?"done":e.state==="Inprogress"?"doing":"todo"}function _fe(e){return e==="done"?{animated:!1,style:{stroke:"var(--color-running)",strokeWidth:2.5}}:e==="doing"?{animated:!1,className:"arrange-flow-edge-working",style:{stroke:"var(--color-running)",strokeWidth:3,strokeDasharray:"8 6"}}:e==="stuck"?{animated:!1,style:{stroke:"var(--color-crashed)",strokeWidth:2.5,strokeDasharray:"6 4"}}:{animated:!1,style:{stroke:"var(--color-accent-yellow)",strokeWidth:2.5,strokeDasharray:"6 4"}}}const ll=260,cl=158,Dm=28,Ep=ll+120,Qx=cl+28,FT=16,$T=44,kp=60,Zx=100,qT=["var(--color-accent-mint)","var(--color-accent-pink)","var(--color-accent-yellow)","var(--color-accent-purple)","var(--color-running-bg)","var(--color-idle-bg)"];function dd(e){const t=new Map;for(const n of e){const i=t.get(n.order)??[];i.push(n),t.set(n.order,i)}return[...t.entries()].sort((n,i)=>n[0]-i[0]).map(([,n])=>n.sort((i,s)=>i.seq-s.seq))}function Cfe(e,t){return Math.abs(e.x-t.x)<ll+Dm&&Math.abs(e.y-t.y)<cl+Dm}function jfe(e){for(let t=0;t<80;t+=1)for(let n=0;n<8;n+=1){const i={x:60+n*(ll+Dm),y:60+t*(cl+Dm)};if(!e.some(s=>Cfe(i,s)))return i}return{x:60,y:60}}function HT(e){return{x:e.position.x+ll/2,y:e.position.y+cl/2}}function Tfe(e,t,n){const i=n.x-t.x,s=n.y-t.y,r=i*i+s*s;if(r===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*i+(e.y-t.y)*s)/r;return o=Math.max(0,Math.min(1,o)),Math.hypot(e.x-(t.x+o*i),e.y-(t.y+o*s))}function Afe(){var ye,et,Pt,Wt;const e=Ye(),t=Xt(),n=bl(),{confirm:i}=Un(),{screenToFlowPosition:s,fitView:r}=vg(),o=_.useRef([]),[c,u]=_.useState(()=>localStorage.getItem(zT)??""),[f,p]=_.useState(()=>localStorage.getItem(BT)==="lanes"?"lanes":"free"),[m,b]=_.useState(!1),[y,x,v]=Ude([]),[w,k,C]=Fde([]),[S,j]=_.useState(null),[T,A]=_.useState(null),[M,R]=_.useState(!1),[P,I]=_.useState(""),[B,F]=_.useState(null),[V,D]=_.useState(null),[L,z]=_.useState(0),W=_.useRef({}),X=_.useRef(w);X.current=w;const G=_.useRef(y);G.current=y;const U=_.useRef(null),q=_.useRef(null),Y=_.useRef(new Set),$=_.useRef(""),ie=_.useRef(null);eI(c||null);const be=Je({queryKey:["cards",c],queryFn:()=>XL(c),enabled:!!c,refetchInterval:3e3}),ce=((ye=be.data)==null?void 0:ye.data)??[],le=((Wt=(Pt=(et=Je({queryKey:["projects"],queryFn:fo,refetchInterval:3e3}).data)==null?void 0:et.data)==null?void 0:Pt.find(me=>me.name===c))==null?void 0:Wt.pipelineStatus)==="running",pe=_.useMemo(()=>{const me={};for(const ae of ce)me[String(ae.seq)]=UT(ae);return me},[ce]),Te=_.useMemo(()=>{if(f!=="lanes")return[];const me=dd(ce),ae=[];for(let je=1;je<me.length;je+=1)for(const Ae of me[je-1]??[])for(const Qe of me[je]??[])ae.push({id:`w${Ae.seq}-${Qe.seq}`,source:String(Ae.seq),target:String(Qe.seq),sourceHandle:"r",targetHandle:"l",animated:!1,selectable:!1,deletable:!1});return ae},[f,ce]),ne=_.useMemo(()=>(f==="lanes"?Te:w).map(me=>{const ae=_fe(pe[me.target]);return me.selected?{...me,...ae,style:{...ae.style,strokeWidth:6}}:{...me,...ae}}),[f,Te,w,pe]),oe=_.useCallback(()=>{t.invalidateQueries({queryKey:["cards",c]})},[t,c]),xe=_.useCallback(()=>{!c||U.current!==c||(ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{gfe(c,{positions:W.current,edges:X.current.map(me=>({id:me.id,source:me.source,target:me.target,sourceHandle:me.sourceHandle??null,targetHandle:me.targetHandle??null}))}).catch(()=>{})},600))},[c]);_.useEffect(()=>{if(U.current=null,j(null),D(null),W.current={},Y.current=new Set,$.current="",x([]),k([]),!c)return;localStorage.setItem(zT,c);let me=!1;return mfe(c).then(ae=>{me||(W.current=ae.positions??{},k((ae.edges??[]).map(je=>({id:je.id,source:je.source,target:je.target,sourceHandle:je.sourceHandle??void 0,targetHandle:je.targetHandle??void 0,animated:!1}))))}).catch(()=>{}).finally(()=>{me||(U.current=c,z(ae=>ae+1))}),()=>{me=!0}},[c,x,k]),_.useEffect(()=>{if(!c||U.current!==c)return;const me=`${f}|`+ce.map(Ue=>`${Ue.seq}:${Ue.title}:${Ue.state}:${Ue.order}:${(Ue.skills??[]).join("|")}`).join(",");if(me===$.current)return;$.current=me;const ae=Ue=>({seq:String(Ue.seq),title:Ue.title,skills:(Ue.skills??[]).join(", "),labels:(Ue.labels??[]).join(", "),status:UT(Ue),label:Ue.title,desc:"",...Ue.kind?{kind:Ue.kind}:{},...Ue.tool?{tool:Ue.tool}:{}});if(f==="lanes"){const Ue=dd(ce),it=Ue.map((Qt,Ot)=>({id:`wave-${Ot}`,type:"waveBox",position:{x:kp+Ot*Ep-FT,y:Zx-$T},data:{label:e("flow.lane.wave",{n:Ot+1}),sub:Qt.length>1?e("flow.lane.parallel",{n:Qt.length}):"",color:qT[Ot%qT.length]},style:{width:ll+FT*2,height:$T+(Qt.length-1)*Qx+cl+14},draggable:!1,selectable:!1,zIndex:0})),qt=Ue.flatMap((Qt,Ot)=>Qt.map((Q,ke)=>({id:String(Q.seq),type:"task",position:{x:kp+Ot*Ep,y:Zx+ke*Qx},deletable:!1,zIndex:1,data:ae(Q)})));x([...it,...qt]);return}const je=new Map(G.current.map(Ue=>[Ue.id,Ue.position])),Ae=[];for(const Ue of ce){const it=je.get(String(Ue.seq))??W.current[String(Ue.seq)];it&&Ae.push(it)}let Qe=!1;const rt=ce.map(Ue=>{const it=String(Ue.seq);let qt=je.get(it)??W.current[it];return qt||(qt=jfe(Ae),Ae.push(qt),Qe=!0),W.current[it]=qt,{id:it,type:"task",position:qt,deletable:!1,data:ae(Ue)}});x(rt),Qe&&xe()},[ce,c,f,L,x,xe,e]),_.useEffect(()=>{if(U.current!==c)return;const me=new Set(ce.map(ae=>String(ae.seq)));k(ae=>{const je=ae.filter(Ae=>me.has(Ae.source)&&me.has(Ae.target));return je.length!==ae.length&&xe(),je.length===ae.length?ae:je})},[ce,c,k,xe]),_.useEffect(()=>{if(!c||U.current!==c||f!=="free"||ce.length<2)return;const me=dd(ce),ae=[];for(let Qe=1;Qe<me.length;Qe+=1)for(const rt of me[Qe-1]??[])for(const Ue of me[Qe]??[])ae.push({id:`seed-${rt.seq}-${Ue.seq}`,source:String(rt.seq),target:String(Ue.seq),sourceHandle:"r",targetHandle:"l",animated:!1});const je=X.current,Ae=q.current!==c;if(q.current=c,Ae&&je.length===0)ae.length>0&&(k(ae),xe());else{const Qe=new Set;for(const it of je)Qe.add(it.source),Qe.add(it.target);const rt=new Set(je.map(it=>`${it.source}->${it.target}`)),Ue=new Set(ce.map(it=>String(it.seq)).filter(it=>!Y.current.has(it)&&!Qe.has(it)));if(Ue.size>0){const it=ae.filter(qt=>(Ue.has(qt.source)||Ue.has(qt.target))&&!rt.has(`${qt.source}->${qt.target}`));it.length>0&&(k([...je,...it]),xe())}}Y.current=new Set(ce.map(Qe=>String(Qe.seq)))},[ce,c,f,L,k,xe]);const fe=_.useCallback(me=>{if(v(me),f!=="free")return;let ae=!1;for(const je of me)je.type==="position"&&je.position&&(W.current[je.id]=je.position,ae=!0);ae&&xe()},[v,xe,f]),te=_.useCallback(me=>{f==="free"&&(k(ae=>CP({...me,animated:!1},ae)),xe())},[k,xe,f]),we=_.useCallback(()=>{if(f!=="free"||ce.length===0)return;const me=dd(ce),ae={},je=[];me.forEach((Ae,Qe)=>{if(Ae.forEach((rt,Ue)=>{ae[String(rt.seq)]={x:kp+Qe*Ep,y:Zx+Ue*Qx}}),Qe>0)for(const rt of me[Qe-1]??[])for(const Ue of Ae)je.push({id:`seed-${rt.seq}-${Ue.seq}`,source:String(rt.seq),target:String(Ue.seq),sourceHandle:"r",targetHandle:"l",animated:!1})}),W.current={...W.current,...ae},x(Ae=>Ae.map(Qe=>ae[Qe.id]?{...Qe,position:ae[Qe.id]}:Qe)),k(je),xe(),setTimeout(()=>r({padding:.2,duration:300}),60)},[f,ce,x,k,xe,r]),Fe=_.useCallback(async me=>{if(!await i({title:e("flow.confirm.deleteTitle"),body:e("flow.confirm.deleteBody",{seq:me}),danger:!0,confirm:e("flow.node.delete")}))return;I("");const je=X.current.filter(Ae=>Ae.source===String(me)||Ae.target===String(me)).map(Ae=>({...Ae}));try{await ZL(c,me),o.current.push({seq:me,edges:je})}catch(Ae){I(Ae instanceof Error?Ae.message:String(Ae))}finally{j(Ae=>Ae===me?null:Ae),A(Ae=>Ae===me?null:Ae),$.current="",z(Ae=>Ae+1),oe()}},[c,i,e,oe]),Le=_.useCallback(async()=>{const me=o.current.pop();if(me){I("");try{await mie(c,me.seq),k(ae=>{const je=new Set(ae.map(Ae=>Ae.id));return[...ae,...me.edges.filter(Ae=>!je.has(Ae.id))]}),xe(),oe()}catch(ae){I(ae instanceof Error?ae.message:String(ae))}}},[c,k,xe,oe]),ht=_.useCallback((me,ae)=>{var rt;if(f!=="free"||ae.isValid)return;const je=ae.fromNode;if(!je||!c)return;const Ae="changedTouches"in me?me.changedTouches[0]:me;if(!Ae)return;const Qe=s({x:Ae.clientX,y:Ae.clientY});F({fromId:je.id,fromHandle:((rt=ae.fromHandle)==null?void 0:rt.id)??null,clientX:Ae.clientX,clientY:Ae.clientY,flowX:Qe.x,flowY:Qe.y})},[f,c,s]),nt=_.useCallback(async()=>{const me=B;if(F(null),!(!me||!c))try{const ae=await b0(c,{title:`${e("flow.node.default")} ${ce.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),je=Sfe(ae);if(je==null)return;const Ae=String(je);W.current[Ae]={x:me.flowX-ll/2,y:me.flowY-cl/2},k(Qe=>[...Qe,{id:`e-${me.fromId}-${Ae}-drop`,source:me.fromId,target:Ae,sourceHandle:me.fromHandle??void 0,animated:!1}]),xe(),oe()}catch(ae){I(ae instanceof Error?ae.message:String(ae))}},[B,c,ce.length,k,xe,e,oe]);_.useEffect(()=>{if(!B)return;const me=ae=>{ae.key==="Escape"&&F(null)};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[B]);const At=_.useCallback((me,ae)=>{f==="free"&&(k(je=>mue(me,ae,je)),xe())},[f,k,xe]);_.useEffect(()=>{const me=ae=>{if(ae.key!=="Delete"&&ae.key!=="Backspace"||T!=null)return;const je=ae.target;je&&(je.tagName==="INPUT"||je.tagName==="TEXTAREA"||je.isContentEditable)||S!=null&&(ae.preventDefault(),Fe(S))};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[S,T,Fe]),_.useEffect(()=>{const me=ae=>{if(!(ae.metaKey||ae.ctrlKey)||ae.key!=="z"&&ae.key!=="Z"||T!=null)return;const je=ae.target;je&&(je.tagName==="INPUT"||je.tagName==="TEXTAREA"||je.isContentEditable)||(ae.preventDefault(),Le())};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[T,Le]);const Nt=_.useCallback(async me=>{if(c){b(!0),I("");try{const ae=new Map(ce.map(je=>[je.seq,je.order]));for(let je=0;je<me.length;je+=1)for(const Ae of me[je]??[])ae.get(Ae)!==je+1&&await wm(c,Ae,{order:je+1});oe()}catch(ae){I(ae instanceof Error?ae.message:String(ae))}finally{b(!1)}}},[c,ce,oe]),mt=_.useCallback(me=>{const ae=Number(me.id);if(!Number.isInteger(ae))return;const je=dd(ce).map(Ue=>Ue.map(it=>it.seq)),Ae=(me.position.x-kp)/Ep,Qe=Math.round(Ae),rt=je.map(Ue=>Ue.filter(it=>it!==ae));if(Qe>=0&&Qe<je.length&&Math.abs(Ae-Qe)<=.35)rt[Qe].push(ae);else{const Ue=Math.max(0,Math.min(rt.length,Math.ceil(Ae)));rt.splice(Ue,0,[ae])}Nt(rt.filter(Ue=>Ue.length>0)).finally(()=>{$.current="",z(Ue=>Ue+1)})},[ce,Nt]),Re=_.useCallback((me,ae)=>{if(f==="lanes"){mt(ae);return}const je=new Map(G.current.map(it=>[it.id,it])),Ae={x:ae.position.x+ll/2,y:ae.position.y+cl/2};let Qe=null,rt=40;for(const it of X.current){if(it.source===ae.id||it.target===ae.id)continue;const qt=je.get(it.source),Qt=je.get(it.target);if(!qt||!Qt)continue;const Ot=Tfe(Ae,HT(qt),HT(Qt));Ot<rt&&(rt=Ot,Qe=it)}if(!Qe)return;const Ue=Qe;k(it=>[...it.filter(qt=>qt.id!==Ue.id),{id:`e-${Ue.source}-${ae.id}-${Ue.id}`,source:Ue.source,target:ae.id,animated:!1},{id:`e-${ae.id}-${Ue.target}-${Ue.id}`,source:ae.id,target:Ue.target,animated:!1}]),xe()},[f,mt,k,xe]),We=_.useCallback(me=>{p(me),localStorage.setItem(BT,me)},[]);_.useEffect(()=>{const me=setTimeout(()=>{r({padding:.2,duration:300})},80);return()=>clearTimeout(me)},[f,r]);const se=async()=>{if(c){I("");try{await b0(c,{title:`${e("flow.node.default")} ${ce.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),oe()}catch(me){I(me instanceof Error?me.message:String(me))}}},Ee=async()=>{if(I(""),D(null),!c)return I(e("flow.err.noProject"));if(ce.length===0)return I(e("flow.err.noNodes"));R(!0);try{const me=ce.filter(Ae=>Ae.state==="Planning"),ae=me.length;let je=0;D({phase:"creating",made:je,total:ae});for(const Ae of me)await wm(c,Ae.seq,{state:"Backlog",labels:Array.from(new Set([...Ae.labels??[],"AI-PIPELINE"]))}),je+=1,D({phase:"creating",made:je,total:ae});D({phase:"starting",made:je,total:ae}),await JL(c),oe(),D({phase:"done",made:je,total:ae})}catch(me){I(me instanceof Error?me.message:String(me))}finally{R(!1)}},De=be.isLoading&&!!c;return d.jsxs("div",{className:"flex flex-col h-full",children:[d.jsxs("header",{className:"flex items-center gap-3 flex-wrap px-4 py-3 border-b border-[var(--surface-card-border)]",children:[d.jsxs("h1",{className:"text-lg font-[family-name:var(--font-heading)] flex items-center gap-2",children:[d.jsx(XN,{size:18,strokeWidth:2.4}),e("nav.arrange")]}),d.jsx(iI,{current:c,onChange:u}),d.jsxs("div",{className:"flex gap-1",role:"group","aria-label":e("flow.mode.aria"),children:[d.jsxs("button",{type:"button",className:["nb-btn",f==="free"?"nb-btn-primary":""].join(" "),"aria-pressed":f==="free",onClick:()=>We("free"),children:[d.jsx(XN,{size:14,strokeWidth:2.4})," ",e("flow.mode.free")]}),d.jsxs("button",{type:"button",className:["nb-btn",f==="lanes"?"nb-btn-primary":""].join(" "),"aria-pressed":f==="lanes",onClick:()=>We("lanes"),children:[d.jsx(hU,{size:14,strokeWidth:2.4})," ",e("flow.mode.lanes")]})]}),De&&d.jsx(pt,{size:15,className:"animate-spin text-[var(--color-text-muted)]"}),d.jsxs("button",{type:"button",className:"nb-btn",onClick:()=>void se(),disabled:!c||De,children:[d.jsx(Bn,{size:15,strokeWidth:2.4})," ",e("flow.addNode")]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta ml-auto",onClick:()=>void Ee(),disabled:M||le||De||!c,title:le?e("flow.pipelineRunning"):void 0,children:[M||le?d.jsx(pt,{size:15,className:"animate-spin"}):d.jsx(Im,{size:15,strokeWidth:2.4}),e(M?"flow.running":le?"flow.pipelineRunning":"flow.run")]})]}),!c&&d.jsx("div",{className:"px-4 py-2 text-sm text-[var(--color-text-muted)] border-b border-[var(--surface-card-border)]",children:e("flow.pickProject")}),P&&d.jsx("div",{className:"px-4 py-2 text-sm text-[var(--color-crashed)] bg-[var(--color-crashed-bg)] border-b border-[var(--surface-card-border)]",children:P}),V&&d.jsxs("div",{className:"px-4 py-2 text-sm flex items-center gap-3 bg-[var(--surface-input)] border-b border-[var(--surface-card-border)]",children:[V.phase==="creating"&&d.jsxs("span",{children:[e("flow.status.creating")," ",V.made,"/",V.total,"…"]}),V.phase==="starting"&&d.jsx("span",{children:e("flow.status.starting")}),V.phase==="done"&&d.jsxs(d.Fragment,{children:[d.jsxs("span",{className:"text-[var(--color-running)] font-bold",children:["✓ ",e("flow.status.done").replace("{n}",String(V.made))]}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>n(`/board?project=${encodeURIComponent(c)}`),children:e("flow.goBoard")})]})]}),d.jsx("div",{className:"flex-1 min-h-0 arrange-flow-shell",children:d.jsxs(Bde,{nodes:y,edges:ne,nodeTypes:Nfe,connectionRadius:160,nodesConnectable:f==="free",edgesReconnectable:f==="free",deleteKeyCode:T!=null?null:["Delete","Backspace"],onNodesChange:fe,onEdgesChange:me=>{f==="free"&&(C(me),xe())},onConnect:te,onConnectEnd:ht,onReconnect:At,onNodeClick:(me,ae)=>{const je=Number(ae.id);Number.isInteger(je)&&A(je)},onNodeDragStop:Re,onSelectionChange:({nodes:me})=>{const ae=me[0]?Number(me[0].id):null;j(ae!=null&&Number.isInteger(ae)?ae:null)},fitView:!0,children:[d.jsx(Kde,{variant:ca.Dots,gap:18,size:1}),d.jsx(Jde,{children:f==="free"&&d.jsx(xd,{onClick:we,title:e("flow.tidy"),"aria-label":e("flow.tidy"),children:d.jsx(GA,{size:14,strokeWidth:2.4})})})]})}),B&&d.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>F(null),children:d.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta absolute -translate-x-1/2 -translate-y-1/2",style:{left:B.clientX,top:B.clientY},onClick:me=>{me.stopPropagation(),nt()},children:[d.jsx(Bn,{size:14,strokeWidth:2.4})," ",e("flow.pending.create")]})}),m&&d.jsxs("div",{className:"px-4 py-1 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)] flex items-center gap-2",children:[d.jsx(pt,{size:12,className:"animate-spin"})," ",e("flow.lane.applying")]}),d.jsx("footer",{className:"px-4 py-2 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)]",children:e(f==="free"?"flow.hint":"flow.lane.hint")}),T!=null&&c&&d.jsx(Efe,{project:c,seq:T,onClose:()=>A(null),onChanged:oe,onDelete:me=>void Fe(me)})]})}function Mfe(){return d.jsx(JP,{children:d.jsx(Afe,{})})}function Rfe(){const e=Ye();return d.jsxs("div",{className:"nb-card max-w-2xl mt-12",children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold mb-2",children:e("notFound.title")}),d.jsx("p",{className:"text-[var(--color-text-muted)] mb-6",children:e("notFound.body")}),d.jsx(zc,{to:"/",className:"nb-btn nb-btn-mint inline-flex",children:e("notFound.home")})]})}const Dfe=_.lazy(()=>IB(()=>import("./ShowcasePage-kwFhzWFH.js"),__vite__mapDeps([0,1])));function Ofe(){return d.jsx(UF,{children:d.jsxs(eB,{children:[d.jsx(oi,{path:"/showcase",element:d.jsx(_.Suspense,{fallback:null,children:d.jsx(Dfe,{})})}),d.jsxs(oi,{element:d.jsx(e_,{contentMode:"workspace"}),children:[d.jsx(oi,{index:!0,element:d.jsx(wx,{})}),d.jsx(oi,{path:"/projects",element:d.jsx(bj,{})}),d.jsx(oi,{path:"/projects/:name",element:d.jsx(bj,{})}),d.jsx(oi,{path:"/board",element:d.jsx(Iie,{})}),d.jsx(oi,{path:"/prompts",element:d.jsx(Xie,{})}),d.jsx(oi,{path:"/chat",element:d.jsx(wx,{})}),d.jsx(oi,{path:"/chat/:sessionId",element:d.jsx(wx,{})}),d.jsx(oi,{path:"/arrange",element:d.jsx(Mfe,{})})]}),d.jsxs(oi,{element:d.jsx(e_,{contentMode:"document"}),children:[d.jsx(oi,{path:"/projects/new",element:d.jsx(YL,{})}),d.jsx(oi,{path:"/skills",element:d.jsx(qie,{})}),d.jsx(oi,{path:"/system",element:d.jsx(pse,{})}),d.jsx(oi,{path:"/memory",element:d.jsx(_se,{})}),d.jsx(oi,{path:"/plugins",element:d.jsx(Gse,{})}),d.jsx(oi,{path:"*",element:d.jsx(Rfe,{})})]})]})})}BF();dF();const Lfe=new $4({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!1}}}),i3=document.getElementById("root");if(!i3)throw new Error("#root not found");y4.createRoot(i3).render(d.jsx(_.StrictMode,{children:d.jsx(tF,{children:d.jsx(q4,{client:Lfe,children:d.jsx(NB,{children:d.jsx(_Y,{children:d.jsx(Ofe,{})})})})})}));export{zA as A,uU as C,qA as E,zc as L,J0 as P,yv as S,VB as a,ze as c,d as j,_ as r,nM as u};
|
|
865
|
+
`).trim()}function wfe(e,t){return t.includes("NEEDS-FIX")?"stuck":e==="Done"?"done":e==="Inprogress"?"doing":"todo"}function Efe({project:e,seq:t,onClose:n,onChanged:i,onDelete:s}){var Te,ne;const r=Ye(),[o,c]=_.useState(!0),[u,f]=_.useState(!1),[p,m]=_.useState(""),[b,y]=_.useState(""),[x,v]=_.useState(new Set),[w,k]=_.useState(""),[C,S]=_.useState("todo"),[j,T]=_.useState(null),[A,M]=_.useState(""),[R,P]=_.useState(void 0),[I,B]=_.useState(void 0),[F,V]=_.useState(void 0),[D,L]=_.useState(void 0),[z,W]=_.useState({value:null,error:"",dirty:!1}),[X,G]=_.useState(null),[U,q]=_.useState(null),Y=U??R,$=Y==="tool"||Y==="join",ie=Je({queryKey:["skills-all",e],queryFn:()=>og(e),enabled:!$}),be=((Te=ie.data)==null?void 0:Te.data)??[],ce=Je({queryKey:["capabilities",e],queryFn:()=>vw(e),enabled:$});_.useEffect(()=>{const oe=xe=>{xe.key==="Escape"&&n()};return window.addEventListener("keydown",oe),()=>window.removeEventListener("keydown",oe)},[n]),_.useEffect(()=>{let oe=!1;return c(!0),QL(e,t).then(xe=>{oe||(m(xe.title),v(new Set(xe.skills??[])),y(vfe(xe.body)),k(xe.state),S(wfe(xe.state,xe.labels??[])),T(typeof xe.order=="number"?xe.order:null),P(xe.kind),B(xe.tool),G(null),q(null),V(xe.input),L(xe.toolResult))}).catch(()=>{}).finally(()=>{oe||c(!1)}),()=>{oe=!0}},[e,t]);const _e=oe=>{v(xe=>{const fe=new Set(xe);return fe.has(oe)?fe.delete(oe):fe.add(oe),fe})},le=async()=>{if(M(""),$&&z.error){M(z.error);return}f(!0);try{await wm(e,t,{title:p.trim()||r("flow.node.default"),...U?{kind:U}:{},...$?{...X||U==="tool"?{tool:X??I??"art.inspect"}:{},...z.dirty||U==="tool"?{input:z.value??{in:""}}:{}}:{description:b,skills:[...x]}}),i(),n()}catch(oe){M(oe instanceof Error?oe.message:String(oe)),f(!1)}},pe=()=>s(t);return d.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-40 flex items-center justify-center p-4 md:p-6 bg-black/30 overflow-hidden",onClick:n,children:d.jsxs("div",{className:"nb-card w-full max-w-4xl flex flex-col bg-[var(--color-bg)]",style:{maxHeight:"calc(100vh - 48px)"},onClick:oe=>oe.stopPropagation(),children:[d.jsxs("header",{className:"flex items-start justify-between gap-4 mb-4 flex-shrink-0",children:[d.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[d.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-xs px-2 py-0.5 bg-[var(--color-accent-purple)] border-2 border-[var(--color-text)] rounded-full",children:["#",t]}),w&&d.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs px-2 py-0.5 border-2 border-[var(--color-text)] rounded-full font-semibold",children:[d.jsx("span",{className:"w-2.5 h-2.5 rounded-full inline-block border border-[var(--color-text)]",style:{background:I0[C]??"gray"}}),w]}),j!=null&&d.jsx("span",{className:"font-[family-name:var(--font-mono)] text-xs px-2 py-0.5 bg-[var(--color-accent-mint)] border-2 border-[var(--color-text)] rounded-full font-semibold",title:r("flow.lane.orderTip"),children:r("flow.lane.wave",{n:j})})]}),d.jsx("button",{onClick:n,className:"nb-btn nb-btn-mint p-2 flex-shrink-0","aria-label":r("flow.node.close"),type:"button",children:d.jsx(vn,{size:14,strokeWidth:3})})]}),o?d.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--color-text-muted)] py-10 justify-center",children:[d.jsx(pt,{size:16,className:"animate-spin"})," …"]}):d.jsxs(d.Fragment,{children:[A&&d.jsx("div",{className:"text-sm text-[var(--color-crashed)] mb-3",children:A}),d.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[d.jsx("span",{className:"text-sm font-bold",children:r("card.kind.label")}),["worker","tool"].map(oe=>d.jsx("button",{type:"button",onClick:()=>q(oe===(R??"worker")?null:oe),"aria-pressed":Y===oe||oe==="worker"&&!$,className:["px-2.5 py-1 text-xs rounded-full border-2 transition-all font-[family-name:var(--font-mono)]",(oe==="tool"?$:!$)?"bg-[var(--color-accent-mint)] border-[var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),children:r(oe==="tool"?"card.kind.tool":"card.kind.worker")},oe)),U&&d.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:r("card.kind.pending")})]}),$&&(z.dirty||X)&&D&&d.jsxs("div",{className:"mb-3 text-xs text-[var(--color-text-muted)]",children:["⚠️ ",r("tool.card.staleWarn")]}),d.jsxs("div",{className:$?"flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pr-1":"grid min-h-0 flex-1 grid-cols-1 gap-4 overflow-y-auto pr-1 md:grid-cols-[minmax(0,1fr)_minmax(260px,340px)] md:overflow-hidden md:pr-0",children:[d.jsxs("label",{className:$?"flex flex-col gap-1.5":"hidden",children:[d.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),d.jsx("input",{className:"nb-input w-full text-base font-semibold",value:p,onChange:oe=>m(oe.target.value)})]}),$&&d.jsx(vm,{tool:X??I,input:F,toolResult:D,capabilities:((ne=ce.data)==null?void 0:ne.data)??[],onChange:W,onToolChange:G}),!$&&d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"flex min-h-0 flex-col gap-4 md:overflow-y-auto md:pr-1",children:[d.jsxs("label",{className:"flex flex-col gap-1.5",children:[d.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),d.jsx("input",{className:"nb-input w-full text-base font-semibold",value:p,onChange:oe=>m(oe.target.value),autoFocus:!0})]}),d.jsxs("label",{className:"flex flex-1 min-h-0 flex-col gap-1.5",children:[d.jsx("span",{className:"text-sm font-bold",children:r("flow.node.desc")}),d.jsx("textarea",{className:"nb-input w-full flex-1 min-h-0",style:{minHeight:200,resize:"vertical"},value:b,onChange:oe=>y(oe.target.value)})]})]}),d.jsxs("section",{className:"flex min-h-[200px] flex-col gap-2 md:min-h-0 md:overflow-hidden",children:[d.jsx("span",{className:"text-sm font-bold",children:r("flow.node.skills")}),d.jsx("div",{className:"scroll-frame min-h-0 flex-1 rounded-lg border-2 border-[var(--color-border-light)] bg-[var(--color-bg-cream)]",children:d.jsxs("div",{className:"scroll-frame-body h-full p-2",children:[ie.isLoading&&d.jsx(pt,{size:14,className:"animate-spin text-[var(--color-text-muted)]"}),be.length>0&&d.jsx("div",{className:"flex flex-wrap gap-2",children:be.map(oe=>{const xe=x.has(oe.name);return d.jsx("button",{type:"button",onClick:()=>_e(oe.name),className:["max-w-full break-all px-2.5 py-1 text-left text-xs font-[family-name:var(--font-mono)] rounded-full border-2 transition-all",xe?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[2px_2px_0_var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),"aria-pressed":xe,children:oe.name},oe.name)})})]})}),x.size>0&&d.jsx("p",{className:"max-h-14 overflow-y-auto break-words text-xs text-[var(--color-text-muted)]",children:[...x].join(", ")})]})]})]}),d.jsxs("div",{className:"flex gap-2 justify-between mt-4 pt-3 border-t-2 border-dashed border-[var(--color-text)] flex-shrink-0",children:[d.jsxs("button",{type:"button",className:"nb-btn nb-btn-danger",onClick:()=>void pe(),disabled:u,children:[d.jsx(cs,{size:14,strokeWidth:2.4})," ",r("flow.node.delete")]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta",onClick:()=>void le(),disabled:u||$&&z.error!=="",children:[u?d.jsx(pt,{size:14,className:"animate-spin"}):null,r("flow.node.save")]})]})]})]})})}const kfe=_.memo(function({data:t}){const n=t;return d.jsxs("div",{className:"relative w-full h-full rounded-2xl border-2 border-dashed border-[var(--color-text)]",children:[d.jsx("div",{className:"absolute inset-0 rounded-2xl",style:{background:n.color,opacity:.16}}),d.jsxs("span",{className:"absolute top-1.5 left-2.5 inline-flex items-center gap-1.5 px-2 py-0.5 text-[11px] font-bold rounded-md border-2 border-[var(--color-text)] bg-[var(--color-bg)] text-[var(--color-text)] whitespace-nowrap max-w-[90%]",children:[d.jsx("span",{className:"truncate",children:n.label}),n.sub&&d.jsx("span",{className:"font-normal text-[var(--color-text-muted)]",children:n.sub})]})]})});function Sfe(e){const t=e;if(typeof t.seq=="number")return t.seq;const n=/#(\d+)/.exec(t.output??"");return n?Number(n[1]):null}const Nfe={task:xfe,waveBox:kfe},zT="sps.flow.lastProject",BT="sps.flow.mode";function UT(e){return(e.labels??[]).includes("NEEDS-FIX")?"stuck":e.state==="Done"?"done":e.state==="Inprogress"?"doing":"todo"}function _fe(e){return e==="done"?{animated:!1,style:{stroke:"var(--color-running)",strokeWidth:2.5}}:e==="doing"?{animated:!1,className:"arrange-flow-edge-working",style:{stroke:"var(--color-running)",strokeWidth:3,strokeDasharray:"8 6"}}:e==="stuck"?{animated:!1,style:{stroke:"var(--color-crashed)",strokeWidth:2.5,strokeDasharray:"6 4"}}:{animated:!1,style:{stroke:"var(--color-accent-yellow)",strokeWidth:2.5,strokeDasharray:"6 4"}}}const ll=260,cl=158,Dm=28,Ep=ll+120,Qx=cl+28,FT=16,$T=44,kp=60,Zx=100,qT=["var(--color-accent-mint)","var(--color-accent-pink)","var(--color-accent-yellow)","var(--color-accent-purple)","var(--color-running-bg)","var(--color-idle-bg)"];function dd(e){const t=new Map;for(const n of e){const i=t.get(n.order)??[];i.push(n),t.set(n.order,i)}return[...t.entries()].sort((n,i)=>n[0]-i[0]).map(([,n])=>n.sort((i,s)=>i.seq-s.seq))}function Cfe(e,t){return Math.abs(e.x-t.x)<ll+Dm&&Math.abs(e.y-t.y)<cl+Dm}function jfe(e){for(let t=0;t<80;t+=1)for(let n=0;n<8;n+=1){const i={x:60+n*(ll+Dm),y:60+t*(cl+Dm)};if(!e.some(s=>Cfe(i,s)))return i}return{x:60,y:60}}function HT(e){return{x:e.position.x+ll/2,y:e.position.y+cl/2}}function Tfe(e,t,n){const i=n.x-t.x,s=n.y-t.y,r=i*i+s*s;if(r===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=((e.x-t.x)*i+(e.y-t.y)*s)/r;return o=Math.max(0,Math.min(1,o)),Math.hypot(e.x-(t.x+o*i),e.y-(t.y+o*s))}function Afe(){var ye,et,Pt,Wt;const e=Ye(),t=Xt(),n=bl(),{confirm:i}=Un(),{screenToFlowPosition:s,fitView:r}=vg(),o=_.useRef([]),[c,u]=_.useState(()=>localStorage.getItem(zT)??""),[f,p]=_.useState(()=>localStorage.getItem(BT)==="lanes"?"lanes":"free"),[m,b]=_.useState(!1),[y,x,v]=Ude([]),[w,k,C]=Fde([]),[S,j]=_.useState(null),[T,A]=_.useState(null),[M,R]=_.useState(!1),[P,I]=_.useState(""),[B,F]=_.useState(null),[V,D]=_.useState(null),[L,z]=_.useState(0),W=_.useRef({}),X=_.useRef(w);X.current=w;const G=_.useRef(y);G.current=y;const U=_.useRef(null),q=_.useRef(null),Y=_.useRef(new Set),$=_.useRef(""),ie=_.useRef(null);eI(c||null);const be=Je({queryKey:["cards",c],queryFn:()=>XL(c),enabled:!!c,refetchInterval:3e3}),ce=((ye=be.data)==null?void 0:ye.data)??[],le=((Wt=(Pt=(et=Je({queryKey:["projects"],queryFn:fo,refetchInterval:3e3}).data)==null?void 0:et.data)==null?void 0:Pt.find(me=>me.name===c))==null?void 0:Wt.pipelineStatus)==="running",pe=_.useMemo(()=>{const me={};for(const ae of ce)me[String(ae.seq)]=UT(ae);return me},[ce]),Te=_.useMemo(()=>{if(f!=="lanes")return[];const me=dd(ce),ae=[];for(let je=1;je<me.length;je+=1)for(const Ae of me[je-1]??[])for(const Qe of me[je]??[])ae.push({id:`w${Ae.seq}-${Qe.seq}`,source:String(Ae.seq),target:String(Qe.seq),sourceHandle:"r",targetHandle:"l",animated:!1,selectable:!1,deletable:!1});return ae},[f,ce]),ne=_.useMemo(()=>(f==="lanes"?Te:w).map(me=>{const ae=_fe(pe[me.target]);return me.selected?{...me,...ae,style:{...ae.style,strokeWidth:6}}:{...me,...ae}}),[f,Te,w,pe]),oe=_.useCallback(()=>{t.invalidateQueries({queryKey:["cards",c]})},[t,c]),xe=_.useCallback(()=>{!c||U.current!==c||(ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{gfe(c,{positions:W.current,edges:X.current.map(me=>({id:me.id,source:me.source,target:me.target,sourceHandle:me.sourceHandle??null,targetHandle:me.targetHandle??null}))}).catch(()=>{})},600))},[c]);_.useEffect(()=>{if(U.current=null,j(null),D(null),W.current={},Y.current=new Set,$.current="",x([]),k([]),!c)return;localStorage.setItem(zT,c);let me=!1;return mfe(c).then(ae=>{me||(W.current=ae.positions??{},k((ae.edges??[]).map(je=>({id:je.id,source:je.source,target:je.target,sourceHandle:je.sourceHandle??void 0,targetHandle:je.targetHandle??void 0,animated:!1}))))}).catch(()=>{}).finally(()=>{me||(U.current=c,z(ae=>ae+1))}),()=>{me=!0}},[c,x,k]),_.useEffect(()=>{if(!c||U.current!==c)return;const me=`${f}|`+ce.map(Ue=>`${Ue.seq}:${Ue.title}:${Ue.state}:${Ue.order}:${(Ue.skills??[]).join("|")}`).join(",");if(me===$.current)return;$.current=me;const ae=Ue=>({seq:String(Ue.seq),title:Ue.title,skills:(Ue.skills??[]).join(", "),labels:(Ue.labels??[]).join(", "),status:UT(Ue),label:Ue.title,desc:"",...Ue.kind?{kind:Ue.kind}:{},...Ue.tool?{tool:Ue.tool}:{}});if(f==="lanes"){const Ue=dd(ce),it=Ue.map((Qt,Ot)=>({id:`wave-${Ot}`,type:"waveBox",position:{x:kp+Ot*Ep-FT,y:Zx-$T},data:{label:e("flow.lane.wave",{n:Ot+1}),sub:Qt.length>1?e("flow.lane.parallel",{n:Qt.length}):"",color:qT[Ot%qT.length]},style:{width:ll+FT*2,height:$T+(Qt.length-1)*Qx+cl+14},draggable:!1,selectable:!1,zIndex:0})),qt=Ue.flatMap((Qt,Ot)=>Qt.map((Q,ke)=>({id:String(Q.seq),type:"task",position:{x:kp+Ot*Ep,y:Zx+ke*Qx},deletable:!1,zIndex:1,data:ae(Q)})));x([...it,...qt]);return}const je=new Map(G.current.map(Ue=>[Ue.id,Ue.position])),Ae=[];for(const Ue of ce){const it=je.get(String(Ue.seq))??W.current[String(Ue.seq)];it&&Ae.push(it)}let Qe=!1;const rt=ce.map(Ue=>{const it=String(Ue.seq);let qt=je.get(it)??W.current[it];return qt||(qt=jfe(Ae),Ae.push(qt),Qe=!0),W.current[it]=qt,{id:it,type:"task",position:qt,deletable:!1,data:ae(Ue)}});x(rt),Qe&&xe()},[ce,c,f,L,x,xe,e]),_.useEffect(()=>{if(U.current!==c)return;const me=new Set(ce.map(ae=>String(ae.seq)));k(ae=>{const je=ae.filter(Ae=>me.has(Ae.source)&&me.has(Ae.target));return je.length!==ae.length&&xe(),je.length===ae.length?ae:je})},[ce,c,k,xe]),_.useEffect(()=>{if(!c||U.current!==c||f!=="free"||ce.length<2)return;const me=dd(ce),ae=[];for(let Qe=1;Qe<me.length;Qe+=1)for(const rt of me[Qe-1]??[])for(const Ue of me[Qe]??[])ae.push({id:`seed-${rt.seq}-${Ue.seq}`,source:String(rt.seq),target:String(Ue.seq),sourceHandle:"r",targetHandle:"l",animated:!1});const je=X.current,Ae=q.current!==c;if(q.current=c,Ae&&je.length===0)ae.length>0&&(k(ae),xe());else{const Qe=new Set;for(const it of je)Qe.add(it.source),Qe.add(it.target);const rt=new Set(je.map(it=>`${it.source}->${it.target}`)),Ue=new Set(ce.map(it=>String(it.seq)).filter(it=>!Y.current.has(it)&&!Qe.has(it)));if(Ue.size>0){const it=ae.filter(qt=>(Ue.has(qt.source)||Ue.has(qt.target))&&!rt.has(`${qt.source}->${qt.target}`));it.length>0&&(k([...je,...it]),xe())}}Y.current=new Set(ce.map(Qe=>String(Qe.seq)))},[ce,c,f,L,k,xe]);const fe=_.useCallback(me=>{if(v(me),f!=="free")return;let ae=!1;for(const je of me)je.type==="position"&&je.position&&(W.current[je.id]=je.position,ae=!0);ae&&xe()},[v,xe,f]),te=_.useCallback(me=>{f==="free"&&(k(ae=>CP({...me,animated:!1},ae)),xe())},[k,xe,f]),we=_.useCallback(()=>{if(f!=="free"||ce.length===0)return;const me=dd(ce),ae={},je=[];me.forEach((Ae,Qe)=>{if(Ae.forEach((rt,Ue)=>{ae[String(rt.seq)]={x:kp+Qe*Ep,y:Zx+Ue*Qx}}),Qe>0)for(const rt of me[Qe-1]??[])for(const Ue of Ae)je.push({id:`seed-${rt.seq}-${Ue.seq}`,source:String(rt.seq),target:String(Ue.seq),sourceHandle:"r",targetHandle:"l",animated:!1})}),W.current={...W.current,...ae},x(Ae=>Ae.map(Qe=>ae[Qe.id]?{...Qe,position:ae[Qe.id]}:Qe)),k(je),xe(),setTimeout(()=>r({padding:.2,duration:300}),60)},[f,ce,x,k,xe,r]),Fe=_.useCallback(async me=>{if(!await i({title:e("flow.confirm.deleteTitle"),body:e("flow.confirm.deleteBody",{seq:me}),danger:!0,confirm:e("flow.node.delete")}))return;I("");const je=X.current.filter(Ae=>Ae.source===String(me)||Ae.target===String(me)).map(Ae=>({...Ae}));try{await ZL(c,me),o.current.push({seq:me,edges:je})}catch(Ae){I(Ae instanceof Error?Ae.message:String(Ae))}finally{j(Ae=>Ae===me?null:Ae),A(Ae=>Ae===me?null:Ae),$.current="",z(Ae=>Ae+1),oe()}},[c,i,e,oe]),Le=_.useCallback(async()=>{const me=o.current.pop();if(me){I("");try{await mie(c,me.seq),k(ae=>{const je=new Set(ae.map(Ae=>Ae.id));return[...ae,...me.edges.filter(Ae=>!je.has(Ae.id))]}),xe(),oe()}catch(ae){I(ae instanceof Error?ae.message:String(ae))}}},[c,k,xe,oe]),ht=_.useCallback((me,ae)=>{var rt;if(f!=="free"||ae.isValid)return;const je=ae.fromNode;if(!je||!c)return;const Ae="changedTouches"in me?me.changedTouches[0]:me;if(!Ae)return;const Qe=s({x:Ae.clientX,y:Ae.clientY});F({fromId:je.id,fromHandle:((rt=ae.fromHandle)==null?void 0:rt.id)??null,clientX:Ae.clientX,clientY:Ae.clientY,flowX:Qe.x,flowY:Qe.y})},[f,c,s]),nt=_.useCallback(async()=>{const me=B;if(F(null),!(!me||!c))try{const ae=await b0(c,{title:`${e("flow.node.default")} ${ce.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),je=Sfe(ae);if(je==null)return;const Ae=String(je);W.current[Ae]={x:me.flowX-ll/2,y:me.flowY-cl/2},k(Qe=>[...Qe,{id:`e-${me.fromId}-${Ae}-drop`,source:me.fromId,target:Ae,sourceHandle:me.fromHandle??void 0,animated:!1}]),xe(),oe()}catch(ae){I(ae instanceof Error?ae.message:String(ae))}},[B,c,ce.length,k,xe,e,oe]);_.useEffect(()=>{if(!B)return;const me=ae=>{ae.key==="Escape"&&F(null)};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[B]);const At=_.useCallback((me,ae)=>{f==="free"&&(k(je=>mue(me,ae,je)),xe())},[f,k,xe]);_.useEffect(()=>{const me=ae=>{if(ae.key!=="Delete"&&ae.key!=="Backspace"||T!=null)return;const je=ae.target;je&&(je.tagName==="INPUT"||je.tagName==="TEXTAREA"||je.isContentEditable)||S!=null&&(ae.preventDefault(),Fe(S))};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[S,T,Fe]),_.useEffect(()=>{const me=ae=>{if(!(ae.metaKey||ae.ctrlKey)||ae.key!=="z"&&ae.key!=="Z"||T!=null)return;const je=ae.target;je&&(je.tagName==="INPUT"||je.tagName==="TEXTAREA"||je.isContentEditable)||(ae.preventDefault(),Le())};return window.addEventListener("keydown",me),()=>window.removeEventListener("keydown",me)},[T,Le]);const Nt=_.useCallback(async me=>{if(c){b(!0),I("");try{const ae=new Map(ce.map(je=>[je.seq,je.order]));for(let je=0;je<me.length;je+=1)for(const Ae of me[je]??[])ae.get(Ae)!==je+1&&await wm(c,Ae,{order:je+1});oe()}catch(ae){I(ae instanceof Error?ae.message:String(ae))}finally{b(!1)}}},[c,ce,oe]),mt=_.useCallback(me=>{const ae=Number(me.id);if(!Number.isInteger(ae))return;const je=dd(ce).map(Ue=>Ue.map(it=>it.seq)),Ae=(me.position.x-kp)/Ep,Qe=Math.round(Ae),rt=je.map(Ue=>Ue.filter(it=>it!==ae));if(Qe>=0&&Qe<je.length&&Math.abs(Ae-Qe)<=.35)rt[Qe].push(ae);else{const Ue=Math.max(0,Math.min(rt.length,Math.ceil(Ae)));rt.splice(Ue,0,[ae])}Nt(rt.filter(Ue=>Ue.length>0)).finally(()=>{$.current="",z(Ue=>Ue+1)})},[ce,Nt]),Re=_.useCallback((me,ae)=>{if(f==="lanes"){mt(ae);return}const je=new Map(G.current.map(it=>[it.id,it])),Ae={x:ae.position.x+ll/2,y:ae.position.y+cl/2};let Qe=null,rt=40;for(const it of X.current){if(it.source===ae.id||it.target===ae.id)continue;const qt=je.get(it.source),Qt=je.get(it.target);if(!qt||!Qt)continue;const Ot=Tfe(Ae,HT(qt),HT(Qt));Ot<rt&&(rt=Ot,Qe=it)}if(!Qe)return;const Ue=Qe;k(it=>[...it.filter(qt=>qt.id!==Ue.id),{id:`e-${Ue.source}-${ae.id}-${Ue.id}`,source:Ue.source,target:ae.id,animated:!1},{id:`e-${ae.id}-${Ue.target}-${Ue.id}`,source:ae.id,target:Ue.target,animated:!1}]),xe()},[f,mt,k,xe]),We=_.useCallback(me=>{p(me),localStorage.setItem(BT,me)},[]);_.useEffect(()=>{const me=setTimeout(()=>{r({padding:.2,duration:300})},80);return()=>clearTimeout(me)},[f,r]);const se=async()=>{if(c){I("");try{await b0(c,{title:`${e("flow.node.default")} ${ce.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),oe()}catch(me){I(me instanceof Error?me.message:String(me))}}},Ee=async()=>{if(I(""),D(null),!c)return I(e("flow.err.noProject"));if(ce.length===0)return I(e("flow.err.noNodes"));R(!0);try{const me=ce.filter(Ae=>Ae.state==="Planning"),ae=me.length;let je=0;D({phase:"creating",made:je,total:ae});for(const Ae of me)await wm(c,Ae.seq,{state:"Backlog",labels:Array.from(new Set([...Ae.labels??[],"AI-PIPELINE"]))}),je+=1,D({phase:"creating",made:je,total:ae});D({phase:"starting",made:je,total:ae}),await JL(c),oe(),D({phase:"done",made:je,total:ae})}catch(me){I(me instanceof Error?me.message:String(me))}finally{R(!1)}},De=be.isLoading&&!!c;return d.jsxs("div",{className:"flex flex-col h-full",children:[d.jsxs("header",{className:"flex items-center gap-3 flex-wrap px-4 py-3 border-b border-[var(--surface-card-border)]",children:[d.jsxs("h1",{className:"text-lg font-[family-name:var(--font-heading)] flex items-center gap-2",children:[d.jsx(XN,{size:18,strokeWidth:2.4}),e("nav.arrange")]}),d.jsx(iI,{current:c,onChange:u}),d.jsxs("div",{className:"flex gap-1",role:"group","aria-label":e("flow.mode.aria"),children:[d.jsxs("button",{type:"button",className:["nb-btn",f==="free"?"nb-btn-primary":""].join(" "),"aria-pressed":f==="free",onClick:()=>We("free"),children:[d.jsx(XN,{size:14,strokeWidth:2.4})," ",e("flow.mode.free")]}),d.jsxs("button",{type:"button",className:["nb-btn",f==="lanes"?"nb-btn-primary":""].join(" "),"aria-pressed":f==="lanes",onClick:()=>We("lanes"),children:[d.jsx(hU,{size:14,strokeWidth:2.4})," ",e("flow.mode.lanes")]})]}),De&&d.jsx(pt,{size:15,className:"animate-spin text-[var(--color-text-muted)]"}),d.jsxs("button",{type:"button",className:"nb-btn",onClick:()=>void se(),disabled:!c||De,children:[d.jsx(Bn,{size:15,strokeWidth:2.4})," ",e("flow.addNode")]}),d.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta ml-auto",onClick:()=>void Ee(),disabled:M||le||De||!c,title:le?e("flow.pipelineRunning"):void 0,children:[M||le?d.jsx(pt,{size:15,className:"animate-spin"}):d.jsx(Im,{size:15,strokeWidth:2.4}),e(M?"flow.running":le?"flow.pipelineRunning":"flow.run")]})]}),!c&&d.jsx("div",{className:"px-4 py-2 text-sm text-[var(--color-text-muted)] border-b border-[var(--surface-card-border)]",children:e("flow.pickProject")}),P&&d.jsx("div",{className:"px-4 py-2 text-sm text-[var(--color-crashed)] bg-[var(--color-crashed-bg)] border-b border-[var(--surface-card-border)]",children:P}),V&&d.jsxs("div",{className:"px-4 py-2 text-sm flex items-center gap-3 bg-[var(--surface-input)] border-b border-[var(--surface-card-border)]",children:[V.phase==="creating"&&d.jsxs("span",{children:[e("flow.status.creating")," ",V.made,"/",V.total,"…"]}),V.phase==="starting"&&d.jsx("span",{children:e("flow.status.starting")}),V.phase==="done"&&d.jsxs(d.Fragment,{children:[d.jsxs("span",{className:"text-[var(--color-running)] font-bold",children:["✓ ",e("flow.status.done").replace("{n}",String(V.made))]}),d.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>n(`/board?project=${encodeURIComponent(c)}`),children:e("flow.goBoard")})]})]}),d.jsx("div",{className:"flex-1 min-h-0 arrange-flow-shell",children:d.jsxs(Bde,{nodes:y,edges:ne,nodeTypes:Nfe,connectionRadius:160,nodesConnectable:f==="free",edgesReconnectable:f==="free",deleteKeyCode:T!=null?null:["Delete","Backspace"],onNodesChange:fe,onEdgesChange:me=>{f==="free"&&(C(me),xe())},onConnect:te,onConnectEnd:ht,onReconnect:At,onNodeClick:(me,ae)=>{const je=Number(ae.id);Number.isInteger(je)&&A(je)},onNodeDragStop:Re,onSelectionChange:({nodes:me})=>{const ae=me[0]?Number(me[0].id):null;j(ae!=null&&Number.isInteger(ae)?ae:null)},fitView:!0,children:[d.jsx(Kde,{variant:ca.Dots,gap:18,size:1}),d.jsx(Jde,{children:f==="free"&&d.jsx(xd,{onClick:we,title:e("flow.tidy"),"aria-label":e("flow.tidy"),children:d.jsx(GA,{size:14,strokeWidth:2.4})})})]})}),B&&d.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>F(null),children:d.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta absolute -translate-x-1/2 -translate-y-1/2",style:{left:B.clientX,top:B.clientY},onClick:me=>{me.stopPropagation(),nt()},children:[d.jsx(Bn,{size:14,strokeWidth:2.4})," ",e("flow.pending.create")]})}),m&&d.jsxs("div",{className:"px-4 py-1 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)] flex items-center gap-2",children:[d.jsx(pt,{size:12,className:"animate-spin"})," ",e("flow.lane.applying")]}),d.jsx("footer",{className:"px-4 py-2 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)]",children:e(f==="free"?"flow.hint":"flow.lane.hint")}),T!=null&&c&&d.jsx(Efe,{project:c,seq:T,onClose:()=>A(null),onChanged:oe,onDelete:me=>void Fe(me)})]})}function Mfe(){return d.jsx(JP,{children:d.jsx(Afe,{})})}function Rfe(){const e=Ye();return d.jsxs("div",{className:"nb-card max-w-2xl mt-12",children:[d.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold mb-2",children:e("notFound.title")}),d.jsx("p",{className:"text-[var(--color-text-muted)] mb-6",children:e("notFound.body")}),d.jsx(zc,{to:"/",className:"nb-btn nb-btn-mint inline-flex",children:e("notFound.home")})]})}const Dfe=_.lazy(()=>IB(()=>import("./ShowcasePage-BqK9HLRZ.js"),__vite__mapDeps([0,1])));function Ofe(){return d.jsx(UF,{children:d.jsxs(eB,{children:[d.jsx(oi,{path:"/showcase",element:d.jsx(_.Suspense,{fallback:null,children:d.jsx(Dfe,{})})}),d.jsxs(oi,{element:d.jsx(e_,{contentMode:"workspace"}),children:[d.jsx(oi,{index:!0,element:d.jsx(wx,{})}),d.jsx(oi,{path:"/projects",element:d.jsx(bj,{})}),d.jsx(oi,{path:"/projects/:name",element:d.jsx(bj,{})}),d.jsx(oi,{path:"/board",element:d.jsx(Iie,{})}),d.jsx(oi,{path:"/prompts",element:d.jsx(Xie,{})}),d.jsx(oi,{path:"/chat",element:d.jsx(wx,{})}),d.jsx(oi,{path:"/chat/:sessionId",element:d.jsx(wx,{})}),d.jsx(oi,{path:"/arrange",element:d.jsx(Mfe,{})})]}),d.jsxs(oi,{element:d.jsx(e_,{contentMode:"document"}),children:[d.jsx(oi,{path:"/projects/new",element:d.jsx(YL,{})}),d.jsx(oi,{path:"/skills",element:d.jsx(qie,{})}),d.jsx(oi,{path:"/system",element:d.jsx(pse,{})}),d.jsx(oi,{path:"/memory",element:d.jsx(_se,{})}),d.jsx(oi,{path:"/plugins",element:d.jsx(Gse,{})}),d.jsx(oi,{path:"*",element:d.jsx(Rfe,{})})]})]})})}BF();dF();const Lfe=new $4({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!1}}}),i3=document.getElementById("root");if(!i3)throw new Error("#root not found");y4.createRoot(i3).render(d.jsx(_.StrictMode,{children:d.jsx(tF,{children:d.jsx(q4,{client:Lfe,children:d.jsx(NB,{children:d.jsx(_Y,{children:d.jsx(Ofe,{})})})})})}));export{zA as A,uU as C,qA as E,zc as L,J0 as P,yv as S,VB as a,ze as c,d as j,_ as r,nM as u};
|