@coralai/sps-cli 0.89.17 → 0.89.19

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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ShowcasePage-BwvNPx33.js","assets/ShowcasePage-EkuegwaP.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ShowcasePage-DjCtHHhI.js","assets/ShowcasePage-EkuegwaP.css"])))=>i.map(i=>d[i]);
2
2
  var sde=Object.defineProperty;var rW=e=>{throw TypeError(e)};var lde=(e,t,n)=>t in e?sde(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var QP=(e,t,n)=>lde(e,typeof t!="symbol"?t+"":t,n),ZP=(e,t,n)=>t.has(e)||rW("Cannot "+n);var Z=(e,t,n)=>(ZP(e,t,"read from private field"),n?n.call(e):t.get(e)),Ve=(e,t,n)=>t.has(e)?rW("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),ze=(e,t,n,i)=>(ZP(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),pt=(e,t,n)=>(ZP(e,t,"access private method"),n);var sy=(e,t,n,i)=>({set _(a){ze(e,t,a,n)},get _(){return Z(e,t,i)}});function NH(e,t){for(var n=0;n<t.length;n++){const i=t[n];if(typeof i!="string"&&!Array.isArray(i)){for(const a in i)if(a!=="default"&&!(a in e)){const r=Object.getOwnPropertyDescriptor(i,a);r&&Object.defineProperty(e,a,r.get?r:{enumerable:!0,get:()=>i[a]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))i(a);new MutationObserver(a=>{for(const r of a)if(r.type==="childList")for(const s of r.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&i(s)}).observe(document,{childList:!0,subtree:!0});function n(a){const r={};return a.integrity&&(r.integrity=a.integrity),a.referrerPolicy&&(r.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?r.credentials="include":a.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(a){if(a.ep)return;a.ep=!0;const r=n(a);fetch(a.href,r)}})();function O1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var JP={exports:{}},Pf={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -8630,7 +8630,7 @@ description: ...
8630
8630
 
8631
8631
  # ...`,"aria-label":t("skills.import.body")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:h.isPending||!d||!s.trim(),onClick:()=>h.mutate(),children:[h.isPending?u.jsx(lt,{size:14,className:"animate-spin"}):u.jsx(x1,{size:14,strokeWidth:3}),t("skills.import.submit")]})]})})}function uJe({onClose:e,onSubmit:t}){const n=Ze(),[i,a]=E.useState(""),[r,s]=E.useState(""),c=/^[a-z0-9][a-z0-9-]*$/.test(i);return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[u.jsx(Ii,{size:16,strokeWidth:2.5}),n("skills.ai.title")]}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:u.jsx(nn,{size:14,strokeWidth:3})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.name")}),u.jsx("input",{type:"text",value:i,onChange:d=>a(d.target.value),placeholder:"rust-error-handling",className:"nb-input w-full font-[family-name:var(--font-mono)]","aria-label":n("skills.ai.name")})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.intent")}),u.jsx("textarea",{value:r,onChange:d=>s(d.target.value),placeholder:n("skills.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("skills.ai.intent")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!c||!r.trim(),onClick:()=>t(i,r),children:[u.jsx(Ii,{size:14,strokeWidth:2.5}),n("skills.ai.submit")]})]})})})}async function hJe(e){const{files:t}=await lZe(e),n=t["SKILL.md"]??"",i=new Blob([n],{type:"text/markdown"}),a=URL.createObjectURL(i),r=document.createElement("a");r.href=a,r.download=`${e}.SKILL.md`,r.click(),URL.revokeObjectURL(a)}const pJe=[{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"}],fJe={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 mJe(){var H,K;const e=Ze(),[t,n]=E.useState("all"),[i,a]=E.useState([]),[r,s]=E.useState(""),[c,d]=E.useState(null),[h,m]=E.useState(!1),[f,k]=E.useState(!1),g=Rt(),v=(((H=nt({queryKey:["gen-jobs"],queryFn:noe,refetchInterval:3e3}).data)==null?void 0:H.data)??[]).filter(R=>R.kind==="skill"),w=v.filter(R=>R.status!=="done"),S=E.useRef(new Set);E.useEffect(()=>{for(const R of v)(R.status==="done"||R.status==="error")&&!S.current.has(R.id)&&(S.current.add(R.id),g.invalidateQueries({queryKey:["skills"]}),g.invalidateQueries({queryKey:["skill-updates"]}))},[v,g]);const C=(R,z)=>{cZe(R,z).then(()=>g.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},L=(((K=nt({queryKey:["skill-updates"],queryFn:oZe}).data)==null?void 0:K.data)??[]).filter(R=>R.status!=="same").length,{data:j,isLoading:A}=nt({queryKey:["skills"],queryFn:()=>zO()}),I=nt({queryKey:["projects"],queryFn:Vs}),T=E.useMemo(()=>((j==null?void 0:j.data)??[]).filter(z=>!(t!=="all"&&z.category!==t||i.length>0&&!z.tags.some($=>i.includes($))||r&&!z.name.toLowerCase().includes(r.toLowerCase()))),[j,t,i,r]),P=E.useMemo(()=>{const R=(j==null?void 0:j.data)??[],z={all:R.length};for(const $ of R)z[$.category]=(z[$.category]??0)+1;return z},[j]),D=E.useMemo(()=>{const R=new Map;for(const z of(j==null?void 0:j.data)??[])for(const $ of z.tags)R.set($,(R.get($)??0)+1);return[...R.entries()].sort((z,$)=>$[1]-z[1]||z[0].localeCompare($[0]))},[j]),q=R=>a(z=>z.includes(R)?z.filter($=>$!==R):[...z,R]);return u.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[u.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:"Skills"}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:A?e("common.loading"):e("skills.subtitleCount",{count:(j==null?void 0:j.data.length)??0})})]}),u.jsxs("div",{className:"flex gap-3 items-center",children:[L>0&&u.jsx("span",{className:"nb-badge text-[10px]",title:e("skills.updates.badge",{count:String(L)}),children:e("skills.updates.badge",{count:String(L)})}),u.jsxs("button",{className:"nb-btn",onClick:()=>k(!0),type:"button",children:[u.jsx(Ii,{size:14,strokeWidth:2.5}),e("skills.ai")]}),u.jsxs("button",{className:"nb-btn",onClick:()=>m(!0),type:"button",children:[u.jsx(x1,{size:14,strokeWidth:2.5}),e("skills.import")]}),u.jsxs("button",{className:"nb-btn nb-btn-mint",onClick:async()=>{await iZe(),g.invalidateQueries({queryKey:["skills"]}),g.invalidateQueries({queryKey:["skill-updates"]})},type:"button",children:[u.jsx(Da,{size:14,strokeWidth:2.5}),"Sync bundled"]})]})]}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("div",{className:"relative shrink-0 w-full max-w-xs",children:[u.jsx(Hr,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),u.jsx("input",{className:"nb-input pl-9 w-full",placeholder:e("skills.search.placeholder"),value:r,onChange:R=>s(R.target.value),"aria-label":e("skills.search.aria")})]}),u.jsx($1,{ariaLabel:"skill categories",className:"flex-1 min-w-0",value:t,onChange:n,options:pJe.filter(R=>R.value==="all"||(P[R.value]??0)>0).map(R=>({value:R.value,label:u.jsxs(u.Fragment,{children:[e(R.labelKey)," ",P[R.value]??0]})}))})]}),D.length>0&&u.jsxs("div",{className:"flex items-start gap-2 flex-wrap",children:[u.jsx("span",{className:"text-xs font-bold text-[var(--color-text-muted)] pt-1.5 uppercase tracking-wider",children:e("skills.tags.title")}),u.jsxs("div",{className:"flex flex-wrap gap-1.5 flex-1",children:[D.map(([R,z])=>{const $=i.includes(R);return u.jsxs("button",{type:"button",onClick:()=>q(R),className:["px-2.5 py-1 rounded-full text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)] transition-colors",$?"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:[R," ",u.jsx("span",{className:"opacity-60",children:z})]},R)}),i.length>0&&u.jsx("button",{type:"button",onClick:()=>a([]),className:"px-2.5 py-1 rounded-full text-xs font-bold text-[var(--color-crashed)] hover:underline",children:e("skills.tags.clear")})]})]}),u.jsxs("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:[w.map(R=>u.jsxs("div",{className:`nb-card flex items-center gap-2 ${R.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,children:[R.status==="running"?u.jsx(lt,{size:14,className:"animate-spin"}):u.jsx(nn,{size:14,strokeWidth:3}),u.jsx("span",{className:"text-sm text-[var(--color-text-muted)] truncate",children:R.status==="running"?`${R.label} · ${e("skills.ai.wait")}`:`${R.label}: ${R.error??e("skills.ai.error")}`})]},R.id)),T.map(R=>{var z;return u.jsx(yJe,{skill:R,projectCount:((z=I.data)==null?void 0:z.data.length)??0,onOpen:()=>d(R.name),onExport:()=>void hJe(R.name)},R.name)})]}),c&&u.jsx(Pre,{name:c,onClose:()=>d(null)}),h&&u.jsx(dJe,{onClose:()=>m(!1)}),f&&u.jsx(uJe,{onClose:()=>k(!1),onSubmit:(R,z)=>{C(R,z),k(!1)}})]})}function yJe({skill:e,projectCount:t,onOpen:n,onExport:i}){const a=Ze(),r=fJe[e.category];return u.jsxs("article",{className:"nb-card nb-card-interactive relative flex flex-col gap-3",children:[u.jsx("button",{type:"button",onClick:n,"aria-label":`Open ${e.name}`,className:"absolute inset-0 cursor-pointer rounded-[inherit] border-0 bg-transparent"}),u.jsxs("div",{className:"flex items-start justify-between gap-3",children:[u.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}),u.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[u.jsx("button",{type:"button",className:"nb-btn relative z-10 p-1",onClick:i,"aria-label":a("skills.export"),title:a("skills.export"),children:u.jsx(Fh,{size:12,strokeWidth:2.5})}),u.jsx("span",{className:"nb-badge text-[10px]",style:{background:r},children:e.category})]})]}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] leading-5 line-clamp-3",children:e.description||"(no description)"}),e.tags.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1",children:e.tags.map(s=>u.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:s},s))}),u.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:[u.jsx("span",{className:"font-bold",children:e.linkedProjects.length>0?`● linked in ${e.linkedProjects.length}`:"○ not linked"}),u.jsxs("span",{className:"text-[var(--color-text-subtle)]",children:[t," projects"]})]})]})}function gJe(e){return _t("/api/prompts")}function ioe(e){return _t(`/api/prompts/${encodeURIComponent(e)}`)}function kJe(e){return fr("/api/prompts",e)}function xJe(e,t){return $2(`/api/prompts/${encodeURIComponent(e)}`,t)}function bJe(e){return gO(`/api/prompts/${encodeURIComponent(e)}`)}function vJe(e){return fr("/api/prompts/generate",{intent:e})}function aoe(e){const t=new Set,n=[];for(const i of e.matchAll(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g)){const a=i[1];a&&!t.has(a)&&(t.add(a),n.push(a))}return n}function wJe(){var I,T;const e=Ze(),[t,n]=Io("prompts.last",""),[i,a]=E.useState(null),[r,s]=E.useState(!1),[c,d]=E.useState(""),[h,m]=E.useState(new Set),f=Rt(),k=nt({queryKey:["prompts"],queryFn:()=>gJe()}),g=((I=k.data)==null?void 0:I.data)??[],b=E.useMemo(()=>[...new Set(g.flatMap(P=>P.tags))].sort(),[g]),w=(((T=nt({queryKey:["gen-jobs"],queryFn:noe,refetchInterval:3e3}).data)==null?void 0:T.data)??[]).filter(P=>P.kind==="prompt"),S=w.filter(P=>P.status!=="done"),C=E.useRef(new Set),M=E.useRef(null);E.useEffect(()=>{for(const P of w)(P.status==="done"||P.status==="error")&&!C.current.has(P.id)&&(C.current.add(P.id),f.invalidateQueries({queryKey:["prompts"]}),P.status==="done"&&P.result&&n(P.result))},[w,f,n]);const L=P=>{vJe(P).then(()=>f.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},j=E.useMemo(()=>{const P=c.trim().toLowerCase();return g.filter(D=>!(h.size&&![...h].every(q=>D.tags.includes(q))||P&&!(D.name.toLowerCase().includes(P)||D.description.toLowerCase().includes(P)||D.tags.some(H=>H.toLowerCase().includes(P)))))},[g,h,c]);E.useEffect(()=>{t&&g.length&&!g.some(P=>P.name===t)&&n("")},[t,g,n]);const A=P=>m(D=>{const q=new Set(D);return q.has(P)?q.delete(P):q.add(P),q});return u.jsxs("div",{className:"flex flex-col flex-1 min-h-0 w-full gap-3",children:[u.jsxs("div",{className:"shrink-0 flex items-center justify-between gap-3",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("prompts.title")}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.desc")})]}),u.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[u.jsxs("button",{className:"nb-btn",type:"button",onClick:()=>s(!0),children:[u.jsx(Ii,{size:14,strokeWidth:2.5}),e("prompts.ai")]}),u.jsxs("button",{className:"nb-btn nb-btn-mint",type:"button",onClick:()=>a({mode:"new"}),children:[u.jsx(jn,{size:14,strokeWidth:3}),e("prompts.new")]})]})]}),u.jsxs("div",{className:"shrink-0 flex flex-col gap-2",children:[u.jsxs("label",{className:"nb-input flex items-center gap-2 w-full",children:[u.jsx(Hr,{size:14}),u.jsx("input",{type:"text",value:c,onChange:P=>d(P.target.value),placeholder:e("prompts.search"),className:"bg-transparent outline-none flex-1 text-sm","aria-label":e("prompts.search")})]}),b.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:b.map(P=>u.jsx("button",{type:"button",onClick:()=>A(P),className:`nb-btn px-2 py-0.5 text-xs ${h.has(P)?"nb-btn-mint":""}`,children:P},P))})]}),u.jsxs("div",{className:"flex gap-5 flex-1 min-h-0",children:[u.jsx("aside",{className:"w-80 shrink-0 nb-card p-3 overflow-hidden flex h-full min-h-0 flex-col gap-2",children:u.jsxs("div",{ref:M,className:"edge-scroll-list flex-1 min-h-0 overflow-y-auto flex flex-col gap-0.5",children:[S.map(P=>u.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"?u.jsx(lt,{size:12,className:"animate-spin"}):u.jsx(nn,{size:12,strokeWidth:3}),u.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)),k.isLoading?u.jsx("div",{className:"nb-card",children:u.jsx(lt,{size:14,className:"animate-spin"})}):j.length===0?u.jsx("div",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.empty")})}):j.map((P,D)=>u.jsx(Fp,{index:D,root:M,children:u.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:[u.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[P.favorite&&u.jsx(ep,{size:12,fill:"currentColor",className:"shrink-0"}),u.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&&u.jsx("span",{className:"block w-full min-w-0 truncate text-xs text-[var(--color-text-muted)]",children:P.description})]})},P.name))]})}),u.jsx("div",{className:"flex-1 min-w-0 min-h-0",children:t?u.jsx(_Je,{name:t,onEdit:()=>a({mode:"edit",name:t}),onDeleted:()=>n("")},t):u.jsx("div",{className:"nb-card",children:u.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("prompts.selectHint")})})})]}),i&&u.jsx(NJe,{name:i.mode==="edit"?i.name:null,onClose:()=>a(null),onSaved:P=>{a(null),n(P)}}),r&&u.jsx(MJe,{onClose:()=>s(!1),onSubmit:P=>{L(P),s(!1)}})]})}function MJe({onClose:e,onSubmit:t}){const n=Ze(),[i,a]=E.useState("");return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[u.jsx(Ii,{size:16,strokeWidth:2.5}),n("prompts.ai.title")]}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:u.jsx(nn,{size:14,strokeWidth:3})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("prompts.ai.intent")}),u.jsx("textarea",{value:i,onChange:r=>a(r.target.value),placeholder:n("prompts.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("prompts.ai.intent")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!i.trim(),onClick:()=>t(i),children:[u.jsx(Ii,{size:14,strokeWidth:2.5}),n("prompts.ai.submit")]})]})})})}function _Je({name:e,onEdit:t,onDeleted:n}){const i=Ze(),a=Rt(),{confirm:r}=ni(),s=nt({queryKey:["prompt",e],queryFn:()=>ioe(e)}),c=Tt({mutationFn:()=>bJe(e),onSuccess:()=>{a.invalidateQueries({queryKey:["prompts"]}),n()}});if(s.isLoading)return u.jsx("div",{className:"nb-card",children:u.jsx(lt,{size:14,className:"animate-spin"})});const d=s.data;if(!d)return null;const h=aoe(d.body);return u.jsxs("div",{className:"nb-card flex flex-col gap-3 h-full min-h-0",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 shrink-0",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold flex items-center gap-2",children:[d.favorite&&u.jsx(ep,{size:16,fill:"currentColor"}),u.jsx("code",{className:"font-[family-name:var(--font-mono)] truncate",children:d.name})]}),d.description&&u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:d.description})]}),u.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:t,children:[u.jsx($r,{size:14,strokeWidth:3}),i("common.edit")]}),u.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:u.jsx(Mi,{size:14,strokeWidth:3})})]})]}),d.tags.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 shrink-0",children:d.tags.map(m=>u.jsx("span",{className:"nb-badge px-2 py-0.5 text-xs",children:m},m))}),u.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:d.body}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)] shrink-0",children:h.length?i("prompts.vars",{names:h.join(", ")}):i("prompts.noVars")})]})}function SJe({tags:e,onChange:t}){const n=Ze(),[i,a]=E.useState(""),r=()=>{const s=i.trim();s&&!e.includes(s)&&t([...e,s]),a("")};return u.jsxs("div",{className:"nb-input w-full flex flex-wrap gap-1.5 items-center",children:[e.map(s=>u.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:[s,u.jsx("button",{type:"button",onClick:()=>t(e.filter(c=>c!==s)),"aria-label":`remove ${s}`,children:u.jsx(nn,{size:10,strokeWidth:3})})]},s)),u.jsx("input",{className:"flex-1 min-w-[90px] bg-transparent outline-none text-sm",value:i,onChange:s=>a(s.target.value),onKeyDown:s=>{s.key==="Enter"?(s.preventDefault(),r()):s.key==="Backspace"&&!i&&e.length&&t(e.slice(0,-1))},placeholder:e.length?"":n("prompts.tagAdd"),"aria-label":n("prompts.tags")})]})}function NJe({name:e,onClose:t,onSaved:n}){const i=Ze(),a=Rt(),{alert:r}=ni(),s=e===null,c=nt({queryKey:["prompt",e],queryFn:()=>ioe(e),enabled:!s}),[d,h]=E.useState(s?{name:"",description:"",tags:[],body:"",favorite:!1}:null);E.useEffect(()=>{if(!s&&c.data&&d===null){const g=c.data;h({name:g.name,description:g.description,tags:g.tags,body:g.body,favorite:g.favorite})}},[s,c.data,d]);const m=Tt({mutationFn:()=>{if(!d)throw new Error("no form");const g={description:d.description||void 0,tags:d.tags,favorite:d.favorite,body:d.body};return s?kJe({name:d.name,...g}):xJe(e,g)},onSuccess:g=>{a.invalidateQueries({queryKey:["prompts"]}),a.invalidateQueries({queryKey:["prompt",g.name]}),n(g.name)},onError:g=>void r({title:i("prompts.saveError"),body:g instanceof Error?g.message:String(g)})}),f=E.useMemo(()=>d?/^[a-z0-9][a-z0-9-]*$/.test(d.name):!1,[d]),k=E.useMemo(()=>d?aoe(d.body):[],[d]);return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-2xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold",children:s?i("prompts.new"):e}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:t,"aria-label":"close",children:u.jsx(nn,{size:14,strokeWidth:3})})]}),!s&&c.isLoading?u.jsx(lt,{size:14,className:"animate-spin"}):d?u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:i("prompts.name")}),u.jsx("input",{type:"text",value:d.name,disabled:!s,onChange:g=>h({...d,name:g.target.value}),placeholder:i("prompts.namePlaceholder"),className:"nb-input w-full","aria-label":i("prompts.name")}),s&&d.name&&!f&&u.jsx("span",{className:"text-xs text-[var(--color-crashed)]",children:i("prompts.nameError")})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:i("prompts.description")}),u.jsx("input",{type:"text",value:d.description,onChange:g=>h({...d,description:g.target.value}),className:"nb-input w-full","aria-label":i("prompts.description")})]})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:i("prompts.tags")}),u.jsx(SJe,{tags:d.tags,onChange:g=>h({...d,tags:g})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:i("prompts.body")}),u.jsx("textarea",{value:d.body,onChange:g=>h({...d,body:g.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")}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:k.length?i("prompts.vars",{names:k.join(", ")}):i("prompts.noVars")})]}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:m.isPending||s&&!f||!d.body.trim(),onClick:()=>m.mutate(),children:[m.isPending?u.jsx(lt,{size:14,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:3}),i("prompts.save")]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:d.favorite,onChange:g=>h({...d,favorite:g.target.checked})}),i("prompts.favorite")]})]})]}):null]})})})}function EJe(){return _t("/api/processes").then(e=>e.data)}function CJe(e){return fr(`/api/processes/${e}/kill`)}function LJe(){return _t("/api/processes/reclaim")}async function jJe(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 AJe="nb-card";function IJe(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 hq(e){return e.project?e.project:e.cwd?e.cwd.split("/").filter(Boolean).pop()??e.slot:e.slot}function eZ(e){const t=/^session-chat-(.+)$/.exec(e.slot);return(t==null?void 0:t[1])??null}function TJe({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 u.jsx("span",{className:`nb-status font-[family-name:var(--font-mono)] ${n}`,children:t})}function RJe({embedded:e}={}){var v;const t=Ze(),n=Rt(),[i,a]=E.useState(null),[r,s]=E.useState("all"),c=nt({queryKey:["processes"],queryFn:EJe,refetchInterval:5e3}),d=Tt({mutationFn:CJe,onSuccess:w=>{a(w.message),n.invalidateQueries({queryKey:["processes"]})},onError:w=>a(w instanceof Error?w.message:String(w))}),h=nt({queryKey:["reclaim"],queryFn:LJe}),[m,f]=E.useState("");E.useEffect(()=>{h.data&&m===""&&f(String(h.data.idleMinutes))},[h.data,m]);const k=Tt({mutationFn:w=>jJe(w),onSuccess:w=>{a(`自动回收已设为 ${w.idleMinutes} 分钟空闲`),n.invalidateQueries({queryKey:["reclaim"]})},onError:w=>a(w instanceof Error?w.message:String(w))}),b=(c.data??[]).filter(w=>r==="all"?!0:w.kind===r);return u.jsxs("div",{className:"max-w-full flex-1 min-h-0 flex flex-col",children:[!e&&u.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl mb-2 shrink-0",children:t("processes.title")}),i&&u.jsx("div",{className:"nb-card mb-3 px-3 py-2 text-sm font-mono",children:i}),u.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[["all","worker","chat"].map(w=>u.jsx("button",{type:"button","aria-pressed":r===w,onClick:()=>s(w),className:`nb-btn px-3 py-1 text-sm ${r===w?"nb-btn-primary":""}`,children:t(`processes.kind.${w}`)},w)),u.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?u.jsx(lt,{size:14,className:"animate-spin"}):u.jsx(Da,{size:14}),t("processes.refresh")]}),u.jsxs("div",{className:`${AJe} px-3 py-1 flex items-center gap-2 shrink-0 ml-auto`,title:"自动回收:会话空闲 N 分钟自动停,下次访问 durable resume 续上,不丢上下文",children:[u.jsx(O0,{size:15,strokeWidth:2.5}),u.jsx("input",{type:"number",min:1,max:1440,value:m,onChange:w=>f(w.target.value),className:"nb-input w-14 px-2 py-1 font-[family-name:var(--font-mono)] text-sm","aria-label":"自动回收空闲分钟数"}),u.jsx("button",{type:"button",disabled:k.isPending||m===""||Number(m)===((v=h.data)==null?void 0:v.idleMinutes),onClick:()=>k.mutate(Math.round(Number(m))),className:"nb-btn nb-btn-primary text-sm disabled:opacity-50",style:{padding:"4px 8px"},"aria-label":"保存自动回收设置",title:"保存自动回收设置",children:k.isPending?u.jsx(lt,{size:14,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:3})})]})]}),u.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:[u.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:[u.jsx("div",{className:"px-3 py-2",children:t("processes.col.kind")}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.slot")}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.project")}),u.jsx("div",{className:"px-3 py-2",children:"PID"}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.state")}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.memory")}),u.jsx("div",{className:"px-3 py-2",children:"运行时间"}),u.jsx("div",{className:"px-3 py-2",children:t("processes.col.action")})]}),u.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto font-[family-name:var(--font-mono)]",children:[b.length===0&&u.jsx("div",{className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:t("processes.empty")}),b.map(w=>u.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:[u.jsxs("div",{className:"px-3 py-2 flex flex-col gap-0.5",children:[u.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}`)}),u.jsx("span",{className:"text-[10px] uppercase tracking-wide text-[var(--color-text)]/45",children:w.tool})]}),u.jsx("div",{className:"px-3 py-2 truncate",children:w.slot}),u.jsx("div",{className:"px-3 py-2 truncate",children:w.kind==="chat"&&eZ(w)?u.jsxs(Sp,{to:`/chat/${eZ(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:[u.jsx(_0,{size:12,strokeWidth:2.5})," ",hq(w)]}):w.kind==="worker"&&w.project?u.jsxs(Sp,{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:[u.jsx(p0,{size:12,strokeWidth:2.5})," ",hq(w)]}):u.jsx("span",{children:hq(w)})}),u.jsx("div",{className:"px-3 py-2",children:w.pid??"—"}),u.jsx("div",{className:"px-3 py-2",children:u.jsx(TJe,{p:w})}),u.jsx("div",{className:"px-3 py-2",children:w.memoryMB!=null?`${w.memoryMB} MB`:"—"}),u.jsx("div",{className:"px-3 py-2",children:IJe(w.startedAt)}),u.jsx("div",{className:"px-3 py-2",children:w.alive&&w.pid!=null?u.jsxs("button",{type:"button","aria-label":`${t("processes.kill")} ${w.slot}`,onClick:()=>{confirm(t("processes.killConfirm").replace("{slot}",w.slot))&&d.mutate(w.pid)},className:"nb-btn nb-btn-danger px-2.5 py-1 text-xs",children:[u.jsx(wo,{size:13})," ",t("processes.kill")]}):u.jsx("span",{className:"text-[var(--color-text)]/40 text-xs",children:"—"})})]},w.slot))]})]})]})}function DJe(e={}){const t=new URLSearchParams;e.project&&t.set("project",e.project),e.action&&t.set("action",e.action);const n=t.toString();return _t(`/api/audit${n?`?${n}`:""}`).then(i=>i.data)}const OJe={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 zJe({embedded:e}={}){const t=Ze(),n=Rt(),[i,a]=E.useState(""),r=nt({queryKey:["audit",i],queryFn:()=>DJe(i?{action:i}:{}),refetchInterval:8e3}),s=r.data??[],c=d=>t(`audit.action.${d}`);return u.jsxs("div",{className:"max-w-full flex-1 min-h-0 flex flex-col",children:[!e&&u.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl mb-2 shrink-0",children:t("audit.title")}),u.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap shrink-0",children:[["","create","modify","delete","daemon"].map(d=>u.jsx("button",{type:"button","aria-pressed":i===d,onClick:()=>a(d),className:`nb-btn px-3 py-1 text-sm ${i===d?"nb-btn-primary":""}`,children:d?c(d):t("audit.filter.all")},d||"all")),u.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?u.jsx(lt,{size:14,className:"animate-spin"}):u.jsx(Da,{size:14}),t("audit.refresh")]})]}),u.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:[u.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:[u.jsx("div",{className:"px-3 py-2",children:t("audit.col.time")}),u.jsx("div",{className:"px-3 py-2",children:t("audit.col.action")}),u.jsx("div",{className:"px-3 py-2",children:t("audit.col.project")}),u.jsx("div",{className:"px-3 py-2",children:t("audit.col.detail")})]}),u.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto font-[family-name:var(--font-mono)]",children:[s.length===0&&u.jsx("div",{className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:t("audit.empty")}),s.map((d,h)=>u.jsxs("div",{className:"grid grid-cols-[180px_120px_minmax(100px,1fr)_minmax(160px,2fr)] border-t border-[var(--color-text)]/10 items-center",children:[u.jsx("div",{className:"px-3 py-2 whitespace-nowrap",children:new Date(d.ts).toLocaleString()}),u.jsx("div",{className:"px-3 py-2",children:u.jsx("span",{className:`nb-badge text-xs whitespace-nowrap ${OJe[d.action]}`,children:c(d.action)})}),u.jsx("div",{className:"px-3 py-2 truncate",title:d.project,children:d.project}),u.jsx("div",{className:"px-3 py-2 text-[var(--color-text)]/70 truncate",title:d.detail??"",children:d.detail??(d.source?`(${d.source})`:"—")})]},`${d.ts}-${h}`))]})]})]})}const roe=[{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"}]}],PJe=roe.flatMap(e=>e.fields),tZ=new Set(PJe.map(e=>e.key)),$Je=[{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 qJe(){var a,r;const e=Ze(),t=nt({queryKey:["system-info"],queryFn:Fne}),[n,i]=Io("system.tab","config");return u.jsxs("div",{className:"system-page-shell flex flex-col flex-1 min-h-0 w-full",children:[u.jsxs("header",{className:"system-page-header shrink-0 flex items-center justify-between gap-3 flex-wrap",children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("system.h1")}),u.jsx(BJe,{platform:(a=t.data)==null?void 0:a.platform,current:(r=t.data)==null?void 0:r.version})]}),u.jsx($1,{ariaLabel:e("system.h1"),className:"max-w-full",value:n,onChange:i,options:$Je.map(s=>({value:s.value,label:e(s.labelKey)}))}),u.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[n==="config"&&u.jsx(HJe,{}),n==="processes"&&u.jsx(RJe,{embedded:!0}),n==="doctor"&&u.jsx(VJe,{}),n==="audit"&&u.jsx(zJe,{embedded:!0})]})]})}function BJe({platform:e,current:t}){const n=Ze(),{confirm:i,alert:a}=ni(),[r,s]=E.useState(!1),c=nt({queryKey:["latest-version"],queryFn:GPe,enabled:!1}),d=async()=>{const m=(await c.refetch()).data;if(!m)return;if(m.upToDate){a({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:m.latest}),confirm:n("system.upgrade.confirm.button")})){s(!0);try{const k=await WPe();a({title:k.ok?n("system.upgrade.success.title"):n("system.upgrade.notEffective.title"),body:k.ok?n("system.upgrade.success.body",{version:k.installedVersion??"?"}):k.output||""})}catch(k){a({title:n("system.upgrade.error.title"),body:k.message})}finally{s(!1)}}};return u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"text-xs font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] whitespace-nowrap",children:[e??"—",t?` · v${t}`:""]}),u.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:d,disabled:r||c.isFetching||!t,type:"button","aria-label":n("system.upgrade.checkUpdate"),children:[r||c.isFetching?u.jsx(lt,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(Da,{size:12,strokeWidth:2.5}),n("system.upgrade.checkUpdate")]})]})}function HJe(){const e=Ze(),t=Rt(),{alert:n}=ni(),{data:i,isLoading:a,isError:r,error:s,dataUpdatedAt:c}=nt({queryKey:["system-env-raw"],queryFn:VPe}),[d,h]=E.useState(null),[m,f]=E.useState(""),[k,g]=E.useState(""),b=i?`${i.etag}:${c}`:null;E.useEffect(()=>{if(!i||b===null)return;const P=d!==null&&d.content!==d.baseContent;(d===null||!P&&d.sourceKey!==b)&&(h({content:i.content,baseContent:i.content,etag:i.etag,sourceKey:b}),f(""),g(""))},[i,d,b]);const v=d,w=v!==null&&v.content!==v.baseContent,S=(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,M=Ure(S,tZ),L=m.trim().toUpperCase(),j=Gre(L)&&!tZ.has(L)&&!M.some(P=>P.key===L),A=(P,D)=>{h(q=>{const H=q??pq(i,b);return{...H,content:VD(H.content,P.key,D,P)}})},I=(P,D)=>{h(q=>{const H=q??pq(i,b);return{...H,content:VD(H.content,P,D)}})},T=Tt({mutationFn:()=>{if(v===null)throw new Error("no draft");return UPe(v.content,v.etag)},onSuccess:P=>{h(D=>D===null?D:{...D,baseContent:D.content,etag:P.etag,sourceKey:`${P.etag}:saved`}),t.invalidateQueries({queryKey:["system-env"]}),t.invalidateQueries({queryKey:["system-env-raw"]})},onError:P=>{const D=P.status;n({title:e(D===409?"system.env.error.conflict.title":"system.env.error.save.title"),body:D===409?e("system.env.error.conflict.body"):P instanceof Error?P.message:String(P)})}});return a?u.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("common.loading")}):r?u.jsx("div",{className:"bg-[var(--color-crashed-bg)] border-2 border-[var(--color-crashed)] rounded-lg p-3",children:u.jsx("p",{className:"text-sm",children:s instanceof Error?s.message:String(s)})}):u.jsxs("div",{className:"system-env-settings-editor",children:[u.jsxs("div",{className:"project-config-toolbar",children:[u.jsxs("div",{children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-base font-bold mb-1",children:e("system.tab.config")}),u.jsx("p",{className:"text-xs text-[var(--color-stuck)] font-bold",children:e("system.env.warning")}),C&&u.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"):""]})]}),u.jsx("div",{className:"flex gap-2",children:u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px"},onClick:()=>T.mutate(),disabled:!w||T.isPending,type:"button","aria-label":e("system.env.save.aria"),children:[T.isPending?u.jsx(lt,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(Oi,{size:12,strokeWidth:3}),e("system.env.save")]})})]}),u.jsxs("div",{className:"project-config-settings","aria-label":e("system.env.settingsAria"),children:[roe.map(P=>u.jsxs("section",{className:"project-config-section",children:[u.jsxs("div",{className:"project-config-section-head",children:[u.jsx("h3",{children:e(`system.env.section.${P.id}`)}),u.jsx("p",{children:e(`system.env.section.${P.id}.hint`)})]}),u.jsx("div",{className:"project-config-grid",children:P.fields.map(D=>u.jsx(FJe,{field:D,value:Vre(S,D),rawValue:d2(S,D.key),onChange:q=>A(D,q)},D.key))})]},P.id)),u.jsxs("section",{className:"project-config-section",children:[u.jsxs("div",{className:"project-config-section-head",children:[u.jsx("h3",{children:e("system.env.section.custom")}),u.jsx("p",{children:e("system.env.section.custom.hint")})]}),u.jsxs("div",{className:"project-config-custom-list",children:[M.length===0?u.jsx("p",{className:"project-config-empty",children:e("system.env.custom.empty")}):M.map(P=>u.jsxs("div",{className:"project-config-custom-row",children:[u.jsx("code",{children:P.key}),u.jsx("input",{className:"nb-input",value:P.value,onChange:D=>I(P.key,D.target.value),"aria-label":e("system.env.custom.valueAria",{key:P.key})}),u.jsx("button",{type:"button",className:"nb-btn",onClick:()=>h(D=>{const q=D??pq(i,b);return{...q,content:Kre(q.content,P.key)}}),"aria-label":e("system.env.custom.removeAria",{key:P.key}),children:u.jsx(nn,{size:12,strokeWidth:3})})]},P.key)),u.jsxs("div",{className:"project-config-custom-row project-config-custom-add",children:[u.jsx("input",{className:"nb-input",value:m,onChange:P=>f(P.target.value),placeholder:e("system.env.custom.keyPlaceholder"),"aria-label":e("system.env.custom.keyAria")}),u.jsx("input",{className:"nb-input",value:k,onChange:P=>g(P.target.value),placeholder:e("system.env.custom.valuePlaceholder"),"aria-label":e("system.env.custom.newValueAria")}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:!j||!k,onClick:()=>{I(L,k),f(""),g("")},children:[u.jsx(jn,{size:12,strokeWidth:3}),e("system.env.custom.add")]})]})]})]})]})]})}function pq(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 FJe({field:e,value:t,rawValue:n,onChange:i}){const a=Ze(),r=a(`system.env.field.${e.key}`),s=a(`system.env.field.${e.key}.help`),c=e.type==="boolean",d=(n||e.defaultValue||"").toLowerCase()==="true";return u.jsxs("div",{className:["project-config-field",c?"project-config-field-toggle":""].join(" "),children:[u.jsxs("span",{className:"project-config-label",children:[u.jsx("span",{children:r}),u.jsx("code",{children:e.key})]}),c?u.jsxs("span",{className:"project-config-toggle-row",children:[u.jsx("input",{type:"checkbox",checked:d,onChange:h=>i(String(h.target.checked))}),u.jsx("span",{children:a(d?"common.yes":"common.no")})]}):e.type==="select"?u.jsx("select",{className:"nb-input",value:t,onChange:h=>i(h.target.value),"aria-label":r,children:(e.options??[]).map(h=>u.jsx("option",{value:h,children:h||a("projectDetail.config.option.empty")},h||"__empty"))}):u.jsx("input",{className:"nb-input",type:e.type==="number"?"number":"text",min:e.type==="number"?0:void 0,value:t,onChange:h=>i(h.target.value),placeholder:e.placeholder,"aria-label":r}),u.jsx("span",{className:"project-config-help",children:s})]})}function VJe(){var k;const e=Ze(),{alert:t}=ni(),n=nt({queryKey:["projects"],queryFn:Vs}),[i,a]=E.useState({}),[r,s]=E.useState({}),[c,d]=E.useState(null),h=(((k=n.data)==null?void 0:k.data)??[]).map(g=>({project:g.name})),m=async(g,b)=>{s(v=>({...v,[g]:b?"fix":"check"}));try{const v=await XPe(g,b);a(w=>({...w,[g]:v})),d(g)}catch(v){t({title:e(b?"system.diagnostics.error.fix":"system.diagnostics.error.check"),body:v instanceof Error?v.message:String(v)})}finally{s(v=>({...v,[g]:null}))}},f=async()=>{for(const g of h)await m(g.project,!1)};return u.jsxs("section",{className:"nb-card system-panel system-panel-doctor flex-1 min-h-0",children:[u.jsxs("div",{className:"system-panel-titlebar",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:e("system.diagnostics.title")}),u.jsxs("button",{className:"nb-btn nb-btn-mint",style:{padding:"6px 12px",fontSize:12},onClick:()=>{f()},disabled:h.length===0||Object.values(r).some(Boolean),type:"button",children:[u.jsx(Da,{size:12,strokeWidth:2.5}),e("system.diagnostics.checkAll")]})]}),u.jsx("div",{className:"system-panel-body",children:h.length===0?u.jsx("p",{className:"text-[var(--color-text-muted)] text-sm",children:e("system.diagnostics.empty")}):u.jsx("ul",{className:"system-diagnostics-list",children:h.map(g=>{const b=i[g.project],v=r[g.project],w=b?b.checks.filter(L=>L.status==="fail").length:0,S=b?b.checks.filter(L=>L.status==="warn").length:0,C=c===g.project,M=b!=null;return u.jsxs("li",{className:["system-diagnostics-item",C?"system-diagnostics-item-expanded":""].join(" "),children:[u.jsxs("div",{className:"system-diagnostics-row",children:[u.jsxs("button",{type:"button",onClick:()=>d(C?null:g.project),disabled:!M,className:"system-diagnostics-summary","aria-label":e(C?"system.diagnostics.collapseAria":"system.diagnostics.expandAria"),"aria-expanded":M?C:void 0,children:[u.jsxs("span",{className:"system-diagnostics-project-main",children:[M&&b.ok?u.jsx(Pr,{size:16,className:"text-[var(--color-running)] shrink-0",strokeWidth:2.5}):M?u.jsx(Ia,{size:16,className:"text-[var(--color-stuck)] shrink-0",strokeWidth:2.5}):u.jsx(Pr,{size:16,className:"text-[var(--color-text-subtle)] shrink-0",strokeWidth:2.5}),M&&(C?u.jsx(lr,{size:12}):u.jsx(To,{size:12})),u.jsx("span",{className:"system-diagnostics-project-name",children:g.project})]}),M?b.ok?u.jsx("span",{className:"system-diagnostics-status system-diagnostics-status-ok",children:"OK"}):u.jsxs("span",{className:"system-diagnostics-status system-diagnostics-status-warn",children:[w," fail · ",S," warn"]}):u.jsx("span",{className:"system-diagnostics-never",children:e("system.diagnostics.never")})]}),u.jsxs("div",{className:"system-diagnostics-actions",children:[u.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>{m(g.project,!1)},disabled:!!v,type:"button","aria-label":e("system.diagnostics.checkAria"),children:[v==="check"?u.jsx(lt,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(Da,{size:11,strokeWidth:2.5}),e("system.diagnostics.check")]}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>{m(g.project,!0)},disabled:!!v||M&&b.ok,type:"button","aria-label":e("system.diagnostics.fixAria"),title:M&&b.ok?e("system.diagnostics.noFixesNeeded"):e("system.diagnostics.fix.tip"),children:[v==="fix"?u.jsx(lt,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(v1,{size:11,strokeWidth:2.5}),e("system.diagnostics.fix")]})]})]}),C&&M&&u.jsxs("div",{className:"system-diagnostics-detail",children:[u.jsx("ul",{className:"system-diagnostics-checks",children:b.checks.map((L,j)=>u.jsx(UJe,{check:L},`${L.name}-${j}`))}),b.fixes.length>0&&u.jsxs("div",{className:"mt-3 bg-[var(--color-running-bg)] border-2 border-[var(--color-running)] rounded p-2",children:[u.jsx("div",{className:"text-xs font-bold text-[var(--color-running)] mb-1",children:e("system.diagnostics.fixed")}),u.jsx("ul",{className:"text-xs list-disc pl-4",children:b.fixes.map((L,j)=>u.jsx("li",{children:L},j))})]})]})]},g.project)})})})]})}function UJe({check:e}){const t=e.status==="pass"?u.jsx(Pr,{size:12,className:"text-[var(--color-running)]",strokeWidth:2.5}):e.status==="fail"?u.jsx(Ia,{size:12,className:"text-[var(--color-crashed)]",strokeWidth:2.5}):e.status==="warn"?u.jsx(Ia,{size:12,className:"text-[var(--color-stuck)]",strokeWidth:2.5}):u.jsx("span",{className:"system-diagnostics-info-dot"});return u.jsxs("li",{className:"system-diagnostics-check-row",children:[u.jsx("span",{className:"system-diagnostics-check-icon",children:t}),u.jsx("span",{className:"system-diagnostics-check-name",children:e.name}),u.jsx("span",{className:"system-diagnostics-check-message",children:e.message})]})}const KJe=["convention","decision","gotcha","pattern","reference","note"],GJe=["local","local+external","external","none"];function cV(e){return e!=null&&typeof e=="object"?e:{}}function rp(e){return Array.isArray(e)?e:[]}function WJe(e){switch(e){case"none":return"none";case"agentmemory":case"custom":return"external";case"builtin":default:return"local"}}function nZ(e){const t=cV(e);return{mode:typeof t.mode=="string"&&t.mode?t.mode:WJe(t.provider),externalUrl:typeof t.externalUrl=="string"?t.externalUrl:typeof t.url=="string"?t.url:"",modeOptions:rp(t.modeOptions).length>0?rp(t.modeOptions):GJe}}function XJe(e){const t=cV(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 YJe(e){const t=cV(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:rp(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 fl(e){return`${e.scope}:${e.project??e.agentId??""}`}function Ty(e){return e.scope==="global"?`全局 (${e.count})`:e.scope==="project"?`项目:${e.project} (${e.count})`:`会话:${e.agentId} (${e.count})`}function ml(e){const t={scope:e.scope};return e.project&&(t.project=e.project),e.agentId&&(t.agentId=e.agentId),t}async function Sr(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 QJe=()=>({title:"",body:"",category:"note",tags:"",salience:3});function ZJe(){var ce,me,je;const e=Ze(),[t,n]=E.useState([]),[i,a]=E.useState(null),[r,s]=E.useState(!1),[c,d]=E.useState([]),[h,m]=E.useState(null),[f,k]=E.useState(!1),[g,b]=E.useState(""),[v,w]=E.useState(!0),[S,C]=E.useState([]),[M,L]=E.useState(null),[j,A]=E.useState(null),[I,T]=E.useState(null),[P,D]=E.useState(null),[q,H]=E.useState(""),[K,R]=E.useState(""),z=E.useCallback(async()=>{try{const{scopes:ie}=await Sr("/api/memory/scopes"),le=rp(ie).map(XJe).filter(be=>be!=null);n(le),a(be=>be??le[0]??null)}catch(ie){m(ie instanceof Error?ie.message:String(ie))}},[]),$=E.useCallback(async ie=>{try{const le=new URLSearchParams(ml(ie)).toString(),{data:be}=await Sr(`/api/memory/entries?${le}`);d(rp(be).map(YJe).filter(pe=>pe!=null))}catch(le){m(le instanceof Error?le.message:String(le))}},[]);E.useEffect(()=>{z(),Sr("/api/system/memory").then(ie=>{const le=nZ(ie);D(le),H(le.mode),R(le.externalUrl)}).catch(()=>{})},[z]),E.useEffect(()=>{i&&$(i),(i==null?void 0:i.scope)==="project"&&i.project?Sr(`/api/memory/external?project=${encodeURIComponent(i.project)}`).then(ie=>T(ie)).catch(()=>T(null)):T(null)},[i,$]);const X=E.useCallback(async()=>{if(!g.trim()){C([]);return}k(!0),m(null);try{const ie=new URLSearchParams({q:g,limit:"20"});if(v)ie.set("all","1");else if(i)for(const[be,pe]of Object.entries(ml(i)))ie.set(be,pe);const{results:le}=await Sr(`/api/memory/recall?${ie.toString()}`);C(rp(le))}catch(ie){m(ie instanceof Error?ie.message:String(ie))}finally{k(!1)}},[g,v,i]),Q=E.useCallback(async()=>{if(!(!i||!M)){k(!0),m(null);try{await Sr("/api/memory/entries",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...ml(i),id:M.id,title:M.title,body:M.body,category:M.category,tags:M.tags.split(",").map(ie=>ie.trim()).filter(Boolean),salience:M.salience})}),L(null),await Promise.all([$(i),z()])}catch(ie){m(ie instanceof Error?ie.message:String(ie))}finally{k(!1)}}},[i,M,$,z]),W=E.useCallback(async ie=>{if(i){k(!0),m(null);try{const le=new URLSearchParams(ml(i)).toString();await Sr(`/api/memory/entries/${encodeURIComponent(ie)}?${le}`,{method:"DELETE"}),await Promise.all([$(i),z()])}catch(le){m(le instanceof Error?le.message:String(le))}finally{k(!1)}}},[i,$,z]),B=E.useCallback(async(ie,le,be)=>{if(i){k(!0),m(null);try{await Sr("/api/memory/promote",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({from:ml(i),id:ie.id,to:ml(le),move:be})}),A(null),await Promise.all([$(i),z()])}catch(pe){m(pe instanceof Error?pe.message:String(pe))}finally{k(!1)}}},[i,$,z]),V=E.useCallback(async()=>{if(i){k(!0),m(null);try{const le=(await Sr("/api/memory/gc",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(ml(i))})).results[0];le&&m(`收敛完成:清 tombstone ${le.purged}、去重 ${le.deduped}、剩余 ${le.kept}`),await Promise.all([$(i),z()])}catch(ie){m(ie instanceof Error?ie.message:String(ie))}finally{k(!1)}}},[i,$,z]),Y=E.useCallback(async()=>{k(!0),m(null);try{const ie=nZ(await Sr("/api/system/memory",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({mode:q,externalUrl:K})}));D(ie),H(ie.mode),R(ie.externalUrl),m("模式已保存(重启 worker 生效)")}catch(ie){m(ie instanceof Error?ie.message:String(ie))}finally{k(!1)}},[q,K]),F=P!=null&&(q!==P.mode||K!==P.externalUrl),ae=q==="external"||q==="local+external",xe=E.useMemo(()=>j?t.filter(ie=>fl(ie)!==fl(i??{scope:""})):[],[j,t,i]),de=Array.isArray((ce=I==null?void 0:I.profile)==null?void 0:ce.topConcepts)?I.profile.topConcepts:[],Ee=Array.isArray((me=I==null?void 0:I.graph)==null?void 0:me.edges)?I.graph.edges.length:0;return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl text-[var(--color-text)]",children:e("nav.memory")}),u.jsx("span",{className:"text-xs text-[var(--color-text)] opacity-60",children:"本地记忆 v2 · markdown 真源"})]}),P&&u.jsxs("section",{className:"nb-card flex flex-wrap items-end gap-3",children:[u.jsxs("div",{className:"flex flex-col gap-1 text-sm",children:[u.jsx("span",{className:"font-bold",children:"记忆模式"}),u.jsx(H0,{value:q,onChange:H,ariaLabel:"记忆模式",options:P.modeOptions.map(ie=>({value:ie,label:ie}))})]}),ae&&u.jsxs("label",{className:"flex flex-col gap-1 text-sm flex-1 min-w-[220px]",children:[u.jsx("span",{className:"font-bold",children:"外部后端地址"}),u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",value:K,onChange:ie=>R(ie.target.value),placeholder:"http://127.0.0.1:3113",spellCheck:!1,"aria-label":"外部后端地址"})]}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:Y,disabled:f||!F,"aria-label":"保存模式",children:"保存模式"})]}),(()=>{const ie=new Date(Date.now()-6048e5).toISOString(),le=i?fl(i):"",be=r?t:t.filter(ne=>ne.scope!=="project"||ne.updated>=ie||fl(ne)===le),pe=t.length-be.length;return u.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[u.jsx("input",{value:g,onChange:ne=>b(ne.target.value),onKeyDown:ne=>ne.key==="Enter"&&X(),placeholder:"检索记忆…","aria-label":"检索记忆",className:"nb-input flex-1 min-w-[200px] font-[family-name:var(--font-mono)] text-sm"}),u.jsxs("label",{className:"flex items-center gap-1 text-sm font-semibold",children:[u.jsx("input",{type:"checkbox",checked:v,onChange:ne=>w(ne.target.checked),"aria-label":"全局检索"}),"全局"]}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:X,disabled:f,"aria-label":"检索",children:f?"…":"检索"}),u.jsx(H0,{className:"min-w-[180px]",value:le,onChange:ne=>a(t.find(we=>fl(we)===ne)??null),ariaLabel:"选择作用域",placeholder:"选择作用域",options:be.map(ne=>({value:fl(ne),label:Ty(ne)}))}),(pe>0||r)&&u.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>s(ne=>!ne),"aria-label":r?"收起更早项目":"显示更早项目",children:r?"收起更早":`含更早 (${pe})`}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>L(QJe()),disabled:!i,"aria-label":"新建记忆",children:"+ 新建"}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-yellow",onClick:V,disabled:f||!i,"aria-label":"收敛去重",children:"收敛"})]})})(),h&&u.jsxs("div",{className:"text-sm text-[var(--color-text)] font-semibold nb-card py-2",children:["ℹ ",h]}),S.length>0&&u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:["检索结果(",S.length,")"]}),S.map(ie=>u.jsxs("div",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)]",children:[u.jsx("span",{className:"nb-badge",children:ie.source==="external"?"🌐 外部":"📁 本地"}),u.jsx("span",{children:ie.source==="external"?ie.type??"":ie.scope==="project"?`项目:${ie.project}`:ie.scope}),ie.category&&u.jsxs(u.Fragment,{children:[u.jsx("span",{children:"·"}),u.jsx("span",{children:ie.category})]})]}),u.jsx("div",{className:"font-bold text-sm mt-1",children:ie.title}),u.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:ie.snippet.slice(0,300)})]},ie.id))]}),I&&(de.length||Ee)?u.jsxs("section",{className:"nb-card flex flex-col gap-1",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:"🌐 外部智能(agentmemory)"}),de.length?u.jsxs("div",{className:"text-xs",children:[u.jsx("span",{className:"font-bold",children:"概念:"}),de.slice(0,8).map(ie=>u.jsx("span",{className:"nb-badge ml-1",children:ie.concept},ie.concept))]}):null,u.jsxs("div",{className:"text-xs opacity-70 font-[family-name:var(--font-mono)]",children:["知识图谱 ",Ee," 条边 · 观测 ",((je=I.profile)==null?void 0:je.totalObservations)??0]})]}):null,M&&u.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:ie=>{ie.target===ie.currentTarget&&L(null)},children:u.jsxs("div",{className:"nb-card w-full max-w-2xl flex flex-col gap-2",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:M.id?"编辑记忆":"新建记忆"}),u.jsx("input",{className:"nb-input text-sm",value:M.title,onChange:ie=>L({...M,title:ie.target.value}),placeholder:"标题","aria-label":"标题"}),u.jsxs("div",{className:"flex gap-2 flex-wrap items-end",children:[u.jsx(H0,{className:"min-w-[140px]",value:M.category,onChange:ie=>L({...M,category:ie}),ariaLabel:"类别",options:KJe.map(ie=>({value:ie,label:ie}))}),u.jsx("input",{className:"nb-input flex-1 min-w-[160px] text-sm",value:M.tags,onChange:ie=>L({...M,tags:ie.target.value}),placeholder:"标签(逗号分隔)","aria-label":"标签"}),u.jsxs("label",{className:"flex items-center gap-1 text-sm",children:["显著度",u.jsx("input",{className:"nb-input w-16",type:"number",min:1,max:5,value:M.salience,onChange:ie=>L({...M,salience:Number(ie.target.value)}),"aria-label":"显著度"})]})]}),u.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm min-h-[120px]",value:M.body,onChange:ie=>L({...M,body:ie.target.value}),placeholder:"正文","aria-label":"正文"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:Q,disabled:f||!M.title.trim()||!M.body.trim(),"aria-label":"保存",children:"保存"}),u.jsx("button",{type:"button",className:"nb-btn",onClick:()=>L(null),"aria-label":"取消",children:"取消"})]})]})}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:i?Ty(i):"条目"}),c.length===0&&u.jsx("div",{className:"nb-card text-sm opacity-60",children:"(无记忆)"}),c.map(ie=>u.jsxs("div",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)] flex-wrap",children:[u.jsx("span",{className:"nb-badge",children:ie.category}),u.jsxs("span",{children:["s",ie.salience]}),u.jsx("span",{children:"·"}),u.jsx("span",{children:ie.source}),ie.tags.map(le=>u.jsxs("span",{children:["#",le]},le))]}),u.jsx("div",{className:"font-bold text-sm mt-1",children:ie.title}),u.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:ie.body.slice(0,400)}),u.jsxs("div",{className:"flex gap-2 mt-2",children:[u.jsx("button",{type:"button",className:"nb-btn nb-btn-blue text-xs",onClick:()=>L({id:ie.id,title:ie.title,body:ie.body,category:ie.category,tags:ie.tags.join(", "),salience:ie.salience}),"aria-label":"编辑",children:"编辑"}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-purple text-xs",onClick:()=>A(ie),"aria-label":"提升",children:"提升"}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-danger text-xs",onClick:()=>W(ie.id),"aria-label":"删除",children:"删除"})]}),(j==null?void 0:j.id)===ie.id&&u.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 border-t-[3px] border-[var(--color-text)] pt-2",children:[u.jsx("span",{className:"text-xs font-bold",children:"提升到:"}),xe.map(le=>u.jsx("button",{type:"button",className:"nb-btn nb-btn-mint text-xs",onClick:()=>B(ie,le,!1),"aria-label":`复制到${Ty(le)}`,children:Ty(le)},fl(le))),xe.length===0&&u.jsx("span",{className:"text-xs opacity-60",children:"(无其它作用域)"}),u.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>A(null),"aria-label":"取消提升",children:"取消"})]})]},ie.id))]})]})}function ooe(e){return e.trim().replace(/[`*_[\]()#]/g,"").replace(/\s+/g,"-").slice(0,60)}function iZ(e){return e.replace(/^\||\|$/g,"").split("|").map(t=>t.trim())}function JJe(e){const t=e.split(`
8632
8632
  `),n=[];let i=0;const a=s=>{const c=s.join(" ").trim();c&&n.push({kind:"para",text:c})};let r=[];for(;i<t.length;){const s=t[i]??"";if(s.startsWith("```")){a(r),r=[];const d=s.slice(3).trim(),h=[];for(i+=1;i<t.length&&!(t[i]??"").startsWith("```");)h.push(t[i]??""),i+=1;i+=1,n.push({kind:"code",lang:d,code:h.join(`
8633
- `)});continue}if(/^\s*\|/.test(s)&&i+1<t.length&&/^\s*\|[\s:|-]+\|?\s*$/.test(t[i+1]??"")){a(r),r=[];const d=iZ(s);i+=2;const h=[];for(;i<t.length&&/^\s*\|/.test(t[i]??"");)h.push(iZ(t[i]??"")),i+=1;n.push({kind:"table",head:d,rows:h});continue}const c=/^(#{2,3})\s+(.+)$/.exec(s);if(c){a(r),r=[];const d=(c[2]??"").trim();n.push({kind:"heading",level:(c[1]??"").length===2?2:3,text:d,id:ooe(d)}),i+=1;continue}if(/^>\s?/.test(s)){a(r),r=[];const d=[];for(;i<t.length&&/^>\s?/.test(t[i]??"");)d.push((t[i]??"").replace(/^>\s?/,"")),i+=1;n.push({kind:"quote",text:d.join(" ").trim()});continue}if(/^\s*([-*]|\d+\.)\s+/.test(s)){a(r),r=[];const d=/^\s*\d+\./.test(s),h=[];for(;i<t.length&&/^\s*([-*]|\d+\.)\s+/.test(t[i]??"");)h.push((t[i]??"").replace(/^\s*([-*]|\d+\.)\s+/,"").trim()),i+=1;n.push({kind:"list",ordered:d,items:h});continue}if(!s.trim()){a(r),r=[],i+=1;continue}if(/^#\s+/.test(s)){i+=1;continue}r.push(s.trim()),i+=1}return a(r),n}function eet(e){const t=[],n=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\[[^\]]+\]\([^)]+\))/g;let i=0;for(const a of e.matchAll(n)){const r=a.index??0;r>i&&t.push({t:"text",v:e.slice(i,r)});const s=a[0];if(s.startsWith("`"))t.push({t:"code",v:s.slice(1,-1)});else if(s.startsWith("**"))t.push({t:"bold",v:s.slice(2,-2)});else{const c=/\[([^\]]+)\]\(([^)]+)\)/.exec(s);c!=null&&c[1]&&c[2]&&t.push({t:"link",v:c[1],href:c[2]})}i=r+s.length}return i<e.length&&t.push({t:"text",v:e.slice(i)}),t}function Nh({text:e}){const t=E.useMemo(()=>eet(e),[e]);return u.jsx(u.Fragment,{children:t.map((n,i)=>{const a=`${n.t}-${i}`;return n.t==="code"?u.jsx("code",{className:"rounded-[6px] border border-[var(--color-border-light)] bg-[var(--surface-control)] px-1.5 py-0.5 font-[family-name:var(--font-mono)] text-[0.85em]",children:n.v},a):n.t==="bold"?u.jsx("strong",{className:"font-bold",children:n.v},a):n.t==="link"?u.jsx("a",{href:n.href,className:"underline decoration-2 underline-offset-2 hover:opacity-70",children:n.v},a):u.jsx("span",{children:n.v},a)})})}function tet({code:e,lang:t}){const[n,i]=E.useState(!1),a=()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>{i(!0),setTimeout(()=>i(!1),1500)},()=>{})};return u.jsxs("div",{className:"relative my-4 rounded-[12px] border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] shadow-[var(--shadow-nb-sm)]",children:[u.jsxs("div",{className:"flex items-center justify-between border-b border-[var(--surface-table-border)] px-3 py-1.5",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",children:t||"shell"}),u.jsxs("button",{type:"button",onClick:a,"aria-label":n?"已复制":"复制代码",className:"flex items-center gap-1 rounded-[6px] px-2 py-0.5 text-[11px] text-[var(--color-text-muted)] transition hover:bg-[var(--color-text)]/10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--color-text)]",children:[n?u.jsx(p1,{size:12}):u.jsx(f1,{size:12}),n?"已复制":"复制"]})]}),u.jsx("pre",{className:"overflow-x-auto p-3",children:u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[12.5px] leading-relaxed text-[var(--color-text)]",children:e})})]})}function net({b:e}){if(e.kind==="heading"){const t=e.level===2?"h2":"h3";return u.jsx(t,{id:e.id,className:e.level===2?"mt-9 mb-3 scroll-mt-24 border-b border-[var(--surface-table-border)] pb-1.5 font-[family-name:var(--font-heading)] text-xl font-bold":"mt-6 mb-2 scroll-mt-24 font-[family-name:var(--font-heading)] text-base font-bold",children:u.jsx(Nh,{text:e.text})})}if(e.kind==="code")return u.jsx(tet,{code:e.code,lang:e.lang});if(e.kind==="quote")return u.jsx("blockquote",{className:"my-4 rounded-[12px] border border-[var(--color-border-light)] bg-[var(--color-stuck-bg)] px-4 py-3 text-sm",children:u.jsx(Nh,{text:e.text})});if(e.kind==="table")return u.jsx("div",{className:"my-4 overflow-x-auto rounded-[12px] border border-[var(--surface-card-border)]",children:u.jsxs("table",{className:"w-full border-collapse text-sm",children:[u.jsx("thead",{children:u.jsx("tr",{className:"bg-[var(--surface-control)]",children:e.head.map(t=>u.jsx("th",{className:"border-b border-[var(--surface-table-border)] px-3 py-2 text-left font-bold",children:u.jsx(Nh,{text:t})},t))})}),u.jsx("tbody",{children:e.rows.map(t=>u.jsx("tr",{className:"border-b border-[var(--surface-table-border)] last:border-0",children:t.map((n,i)=>u.jsx("td",{className:"px-3 py-2 align-top",children:u.jsx(Nh,{text:n})},`${i}-${n}`))},t.join("|")))})]})});if(e.kind==="list"){const t=e.ordered?"ol":"ul";return u.jsx(t,{className:`my-3 space-y-1.5 pl-5 text-sm ${e.ordered?"list-decimal":"list-disc"}`,children:e.items.map(n=>u.jsx("li",{children:u.jsx(Nh,{text:n})},n))})}return u.jsx("p",{className:"my-3 text-sm leading-7",children:u.jsx(Nh,{text:e.text})})}function iet(){const[e,t]=E.useState([]),[n,i]=E.useState(""),[a,r]=E.useState(""),[s,c]=E.useState(""),[d,h]=E.useState(!1),[m,f]=E.useState(""),[k,g]=E.useState(""),b=E.useRef(null);E.useEffect(()=>{fetch("/api/help").then(C=>C.ok?C.json():C.json().then(M=>Promise.reject(M))).then(C=>{const M=C.data??[];t(M),M.length>0&&M[0]&&i(M[0].id)}).catch(C=>g((C==null?void 0:C.detail)||(C==null?void 0:C.title)||"帮助目录加载失败"))},[]),E.useEffect(()=>{n&&fetch(`/api/help/${n}`).then(C=>C.ok?C.json():C.json().then(M=>Promise.reject(M))).then(C=>{var M,L,j,A,I;r(((M=C.data)==null?void 0:M.body)??""),c(((L=C.data)==null?void 0:L.title)??n),h(!!((j=C.data)!=null&&j.generated)),(I=(A=b.current)==null?void 0:A.closest("main"))==null||I.scrollTo({top:0,behavior:"smooth"})}).catch(C=>g((C==null?void 0:C.detail)||(C==null?void 0:C.title)||"文档加载失败"))},[n]);const v=E.useMemo(()=>JJe(a),[a]),w=E.useMemo(()=>v.filter(C=>C.kind==="heading"&&C.level===2),[v]),S=E.useMemo(()=>{const C=m.trim().toLowerCase();return C?v.filter(M=>JSON.stringify(M).toLowerCase().includes(C)):v},[v,m]);return k?u.jsx("div",{className:"rounded-[12px] border border-[var(--color-border-light)] bg-[var(--color-crashed-bg)] p-4 text-sm",children:k}):u.jsxs("div",{className:"flex w-full flex-col gap-6",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:"帮助中心"}),u.jsx("p",{className:"mt-1 text-sm text-[var(--color-text-muted)]",children:"安装部署、命令、控制台、插件与开放 API —— 命令与 API 两篇由代码自动生成,不会过期。"})]}),u.jsxs("div",{className:"flex flex-col gap-5 lg:flex-row lg:items-start",children:[u.jsx("aside",{className:"w-full shrink-0 lg:sticky lg:top-0 lg:max-h-[calc(100dvh-6rem)] lg:w-60 lg:overflow-y-auto",children:u.jsx("nav",{className:"rounded-[12px] border border-[var(--surface-card-border)] bg-[var(--surface-control)] p-2 shadow-[var(--shadow-nb)]",children:e.map(C=>u.jsxs("div",{children:[u.jsxs("button",{type:"button",onClick:()=>{i(C.id),f("")},"aria-current":C.id===n?"page":void 0,className:`flex w-full items-center gap-2 rounded-[8px] px-2.5 py-2 text-left text-sm transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--color-text)] ${C.id===n?"bg-[var(--color-primary)]/20 font-bold":"hover:bg-[var(--color-text)]/5"}`,children:[C.generated?u.jsx(v1,{size:14}):u.jsx(cr,{size:14}),u.jsx("span",{className:"min-w-0 flex-1 truncate",children:C.title})]}),C.id===n&&w.length>0&&u.jsx("ul",{className:"mt-1 mb-2 ml-3 border-l-2 border-[var(--color-text)]/20 pl-2",children:w.map(M=>u.jsx("li",{children:u.jsx("a",{href:`#${M.id}`,className:"block truncate rounded px-1.5 py-1 text-xs text-[var(--color-text-muted)] hover:bg-[var(--color-text)]/5 hover:text-[var(--color-text)]",children:M.text.replace(/[`*]/g,"")})},M.id))})]},C.id))})}),u.jsxs("section",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-3",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold",children:s}),d&&u.jsx("span",{className:"rounded-[6px] border border-[var(--color-border-light)] bg-[var(--color-info-bg)] px-2 py-0.5 text-[11px] font-bold",children:"自动生成 · 与代码同步"}),u.jsxs("label",{className:"ml-auto flex items-center gap-1.5 rounded-[8px] border border-[var(--control-border)] bg-[var(--surface-control)] px-2 py-1",children:[u.jsx(Hr,{size:14}),u.jsx("input",{value:m,onChange:C=>f(C.target.value),placeholder:"在本篇中查找","aria-label":"在本篇中查找",className:"w-40 bg-transparent text-sm outline-none"})]})]}),u.jsx("div",{ref:b,className:"rounded-[12px] border border-[var(--surface-card-border)] bg-[var(--surface-control)] px-5 py-4 shadow-[var(--shadow-nb)]",children:S.length===0?u.jsxs("p",{className:"py-8 text-center text-sm text-[var(--color-text-muted)]",children:["本篇中没有匹配「",m,"」的内容"]}):S.map((C,M)=>u.jsx(net,{b:C},`${C.kind}-${M}-${ooe(JSON.stringify(C).slice(0,40))}`))})]})]})]})}async function soe(){return(await _t("/api/plugins")).data??[]}async function aet(e,t){return fr("/api/plugins",{spec:e})}async function ret(e,t){return Bne(`/api/plugins/${encodeURIComponent(e)}`,{disabled:t})}async function oet(e){return qne(`/api/plugins/${encodeURIComponent(e)}`)}async function set(e,t){return $2(`/api/plugins/${encodeURIComponent(e)}/config`,{config:t})}const aH=1,cet=["react","react-dom","react/jsx-runtime","@tanstack/react-query","lucide-react","@coralai/console-ui","@coralai/console-slots"],_1=new Map,rH=new Set;function GD(){for(const e of rH)e()}function det(e){return rH.add(e),()=>rH.delete(e)}function uet(){return[..._1.values()]}function het(e){return t=>{switch(t){case"react":return fde;case"react/jsx-runtime":return hde;case"react-dom":return V1e;case"@tanstack/react-query":return cue;case"lucide-react":return mTe;case"@coralai/console-ui":return FPe;case"@coralai/console-slots":return{registerSlot:(n,i)=>sYe(n,{owner:e,order:i.order??100,...typeof i.match=="function"?{match:i.match}:{},...i.takeover===!0?{takeover:!0}:{},render:i.render}),contractVersion:aH};default:throw new Error(`插件 ${e} 要的模块 "${t}" 不在宿主模块表里(可用:${cet.join("、")})`)}}}function pet(){const e=globalThis;e.__SpsModuleLoader__||(e.__SpsModuleLoader__={load(t){const n=t.contractVersion??1;if(n!==aH){_1.set(t.id,{id:t.id,ok:!1,error:`插槽契约版本不匹配:插件按 v${n} 编译,当前是 v${aH}`}),GD();return}try{t.factory(het(t.id)),_1.set(t.id,{id:t.id,ok:!0})}catch(i){lYe(t.id),_1.set(t.id,{id:t.id,ok:!1,error:i instanceof Error?i.message:String(i)})}GD()}})}function fet(e){return new Promise(t=>{const n=document.createElement("script");n.src=`/api/plugins/${encodeURIComponent(e)}/client.js`,n.async=!0,n.dataset.spsPlugin=e,n.onerror=()=>{_1.set(e,{id:e,ok:!1,error:"脚本加载失败"}),GD(),t()},n.onload=()=>{_1.has(e)||(_1.set(e,{id:e,ok:!1,error:"脚本跑完了但没有调用 __SpsModuleLoader__.load()"}),GD()),t()},document.head.append(n)})}const met={slots:0};let aZ=new Map,rZ="";function oZ(){const e=uet(),t=pYe(),n=JSON.stringify([e,t]);if(n===rZ)return aZ;const i=new Map;for(const a of e)i.set(a.id,{ok:a.ok,...a.error?{error:a.error}:{},slots:0});for(const a of t)for(const r of a.owners){const s=i.get(r)??{slots:0};i.set(r,{...s,slots:s.slots+1})}return aZ=i,rZ=n,i}function yet(e){const t=det(e),n=UF(e);return()=>{t(),n()}}function loe(e){return E.useSyncExternalStore(yet,oZ,oZ).get(e)??met}function get(e){return!!e&&typeof e=="object"&&"refs"in e&&"uid"in e}const n1=(e,t)=>t===void 0?void 0:e.refs[String(t)];function ket(e){const t=n1(e,e.uid);return!t||t.type!=="object"||!t.dict?!1:Object.values(t.dict).every(n=>{var a;const i=n1(e,n);return i?["string","number","boolean"].includes(i.type)?!0:i.type==="union"?(i.list??[]).every(r=>{var s;return((s=n1(e,r))==null?void 0:s.type)==="const"}):i.type==="array"?((a=n1(e,i.inner))==null?void 0:a.type)==="string":!1:!1})}function xet({schema:e,value:t,onChange:n}){const i=get(e)?e:null,a=E.useMemo(()=>i?ket(i):!1,[i]),[r,s]=E.useState(()=>JSON.stringify(t??{},null,2)),[c,d]=E.useState(null);if(!i||!a)return u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx("label",{htmlFor:"plugin-config-raw",className:"text-sm font-bold",children:"配置(JSON)"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:i?"这个插件的配置里有通用表单认不出来的类型,先用 JSON 编辑。":"这个插件没有声明 Config —— 仍然可以直接写 JSON。"}),u.jsx("textarea",{id:"plugin-config-raw",className:"nb-input min-h-[180px] font-[family-name:var(--font-mono)] text-xs",value:r,onChange:f=>{s(f.target.value);try{n(JSON.parse(f.target.value||"{}")),d(null)}catch(k){d(k instanceof Error?k.message:String(k))}}}),c?u.jsxs("span",{className:"text-xs text-[var(--color-danger)]",children:["JSON 有误:",c]}):null]});const h=n1(i,i.uid),m=(f,k)=>n({...t,[f]:k});return u.jsx("div",{className:"flex flex-col gap-4",children:Object.entries(h.dict??{}).map(([f,k])=>{var C,M,L,j,A,I,T;const g=n1(i,k),b=t[f]??((C=g.meta)==null?void 0:C.default),v=u.jsxs("span",{className:"text-sm font-bold",children:[f,(M=g.meta)!=null&&M.required?u.jsx("span",{className:"text-[var(--color-danger)]",children:" *"}):null]}),w=(L=g.meta)!=null&&L.description?u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:g.meta.description}):null;if(g.type==="boolean")return u.jsxs("label",{className:"flex items-center gap-2",children:[u.jsx("input",{type:"checkbox",checked:!!b,onChange:P=>m(f,P.target.checked)}),u.jsxs("span",{className:"flex flex-col",children:[v,w]})]},f);if(g.type==="union"){const P=(g.list??[]).map(D=>{var q;return(q=n1(i,D))==null?void 0:q.value}).filter(D=>D!==void 0);return u.jsxs("label",{className:"flex flex-col gap-1",children:[v,w,u.jsx("select",{className:"nb-input text-sm",value:String(b??""),onChange:D=>m(f,D.target.value),children:P.map(D=>u.jsx("option",{value:String(D),children:String(D)},String(D)))})]},f)}if(g.type==="array"){const P=Array.isArray(b)?b:[];return u.jsxs("label",{className:"flex flex-col gap-1",children:[v,u.jsxs("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:[(j=g.meta)!=null&&j.description?`${g.meta.description} · `:"","一行一个"]}),u.jsx("textarea",{className:"nb-input min-h-[80px] font-[family-name:var(--font-mono)] text-xs",value:P.join(`
8633
+ `)});continue}if(/^\s*\|/.test(s)&&i+1<t.length&&/^\s*\|[\s:|-]+\|?\s*$/.test(t[i+1]??"")){a(r),r=[];const d=iZ(s);i+=2;const h=[];for(;i<t.length&&/^\s*\|/.test(t[i]??"");)h.push(iZ(t[i]??"")),i+=1;n.push({kind:"table",head:d,rows:h});continue}const c=/^(#{2,3})\s+(.+)$/.exec(s);if(c){a(r),r=[];const d=(c[2]??"").trim();n.push({kind:"heading",level:(c[1]??"").length===2?2:3,text:d,id:ooe(d)}),i+=1;continue}if(/^>\s?/.test(s)){a(r),r=[];const d=[];for(;i<t.length&&/^>\s?/.test(t[i]??"");)d.push((t[i]??"").replace(/^>\s?/,"")),i+=1;n.push({kind:"quote",text:d.join(" ").trim()});continue}if(/^\s*([-*]|\d+\.)\s+/.test(s)){a(r),r=[];const d=/^\s*\d+\./.test(s),h=[];for(;i<t.length&&/^\s*([-*]|\d+\.)\s+/.test(t[i]??"");)h.push((t[i]??"").replace(/^\s*([-*]|\d+\.)\s+/,"").trim()),i+=1;n.push({kind:"list",ordered:d,items:h});continue}if(!s.trim()){a(r),r=[],i+=1;continue}if(/^#\s+/.test(s)){i+=1;continue}r.push(s.trim()),i+=1}return a(r),n}function eet(e){const t=[],n=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\[[^\]]+\]\([^)]+\))/g;let i=0;for(const a of e.matchAll(n)){const r=a.index??0;r>i&&t.push({t:"text",v:e.slice(i,r)});const s=a[0];if(s.startsWith("`"))t.push({t:"code",v:s.slice(1,-1)});else if(s.startsWith("**"))t.push({t:"bold",v:s.slice(2,-2)});else{const c=/\[([^\]]+)\]\(([^)]+)\)/.exec(s);c!=null&&c[1]&&c[2]&&t.push({t:"link",v:c[1],href:c[2]})}i=r+s.length}return i<e.length&&t.push({t:"text",v:e.slice(i)}),t}function Nh({text:e}){const t=E.useMemo(()=>eet(e),[e]);return u.jsx(u.Fragment,{children:t.map((n,i)=>{const a=`${n.t}-${i}`;return n.t==="code"?u.jsx("code",{className:"rounded-[6px] border border-[var(--color-border-light)] bg-[var(--surface-control)] px-1.5 py-0.5 font-[family-name:var(--font-mono)] text-[0.85em]",children:n.v},a):n.t==="bold"?u.jsx("strong",{className:"font-bold",children:n.v},a):n.t==="link"?u.jsx("a",{href:n.href,className:"underline decoration-2 underline-offset-2 hover:opacity-70",children:n.v},a):u.jsx("span",{children:n.v},a)})})}function tet({code:e,lang:t}){const[n,i]=E.useState(!1),a=()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>{i(!0),setTimeout(()=>i(!1),1500)},()=>{})};return u.jsxs("div",{className:"relative my-4 rounded-[12px] border border-[var(--surface-card-border)] bg-[var(--color-bg-soft)] shadow-[var(--shadow-nb-sm)]",children:[u.jsxs("div",{className:"flex items-center justify-between border-b border-[var(--surface-table-border)] px-3 py-1.5",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",children:t||"shell"}),u.jsxs("button",{type:"button",onClick:a,"aria-label":n?"已复制":"复制代码",className:"flex items-center gap-1 rounded-[6px] px-2 py-0.5 text-[11px] text-[var(--color-text-muted)] transition hover:bg-[var(--color-text)]/10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--color-text)]",children:[n?u.jsx(p1,{size:12}):u.jsx(f1,{size:12}),n?"已复制":"复制"]})]}),u.jsx("pre",{className:"overflow-x-auto overflow-y-hidden p-3",children:u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[12.5px] leading-relaxed text-[var(--color-text)]",children:e})})]})}function net({b:e}){if(e.kind==="heading"){const t=e.level===2?"h2":"h3";return u.jsx(t,{id:e.id,className:e.level===2?"mt-9 mb-3 scroll-mt-24 border-b border-[var(--surface-table-border)] pb-1.5 font-[family-name:var(--font-heading)] text-xl font-bold":"mt-6 mb-2 scroll-mt-24 font-[family-name:var(--font-heading)] text-base font-bold",children:u.jsx(Nh,{text:e.text})})}if(e.kind==="code")return u.jsx(tet,{code:e.code,lang:e.lang});if(e.kind==="quote")return u.jsx("blockquote",{className:"my-4 rounded-[12px] border border-[var(--color-border-light)] bg-[var(--color-stuck-bg)] px-4 py-3 text-sm",children:u.jsx(Nh,{text:e.text})});if(e.kind==="table")return u.jsx("div",{className:"my-4 overflow-x-auto overflow-y-hidden rounded-[12px] border border-[var(--surface-card-border)]",children:u.jsxs("table",{className:"w-full border-collapse text-sm",children:[u.jsx("thead",{children:u.jsx("tr",{className:"bg-[var(--surface-control)]",children:e.head.map(t=>u.jsx("th",{className:"border-b border-[var(--surface-table-border)] px-3 py-2 text-left font-bold",children:u.jsx(Nh,{text:t})},t))})}),u.jsx("tbody",{children:e.rows.map(t=>u.jsx("tr",{className:"border-b border-[var(--surface-table-border)] last:border-0",children:t.map((n,i)=>u.jsx("td",{className:"px-3 py-2 align-top",children:u.jsx(Nh,{text:n})},`${i}-${n}`))},t.join("|")))})]})});if(e.kind==="list"){const t=e.ordered?"ol":"ul";return u.jsx(t,{className:`my-3 space-y-1.5 pl-5 text-sm ${e.ordered?"list-decimal":"list-disc"}`,children:e.items.map(n=>u.jsx("li",{children:u.jsx(Nh,{text:n})},n))})}return u.jsx("p",{className:"my-3 text-sm leading-7",children:u.jsx(Nh,{text:e.text})})}function iet(){const[e,t]=E.useState([]),[n,i]=E.useState(""),[a,r]=E.useState(""),[s,c]=E.useState(""),[d,h]=E.useState(!1),[m,f]=E.useState(""),[k,g]=E.useState(""),b=E.useRef(null);E.useEffect(()=>{fetch("/api/help").then(C=>C.ok?C.json():C.json().then(M=>Promise.reject(M))).then(C=>{const M=C.data??[];t(M),M.length>0&&M[0]&&i(M[0].id)}).catch(C=>g((C==null?void 0:C.detail)||(C==null?void 0:C.title)||"帮助目录加载失败"))},[]),E.useEffect(()=>{n&&fetch(`/api/help/${n}`).then(C=>C.ok?C.json():C.json().then(M=>Promise.reject(M))).then(C=>{var M,L,j,A,I;r(((M=C.data)==null?void 0:M.body)??""),c(((L=C.data)==null?void 0:L.title)??n),h(!!((j=C.data)!=null&&j.generated)),(I=(A=b.current)==null?void 0:A.closest("main"))==null||I.scrollTo({top:0,behavior:"smooth"})}).catch(C=>g((C==null?void 0:C.detail)||(C==null?void 0:C.title)||"文档加载失败"))},[n]);const v=E.useMemo(()=>JJe(a),[a]),w=E.useMemo(()=>v.filter(C=>C.kind==="heading"&&C.level===2),[v]),S=E.useMemo(()=>{const C=m.trim().toLowerCase();return C?v.filter(M=>JSON.stringify(M).toLowerCase().includes(C)):v},[v,m]);return k?u.jsx("div",{className:"rounded-[12px] border border-[var(--color-border-light)] bg-[var(--color-crashed-bg)] p-4 text-sm",children:k}):u.jsxs("div",{className:"flex w-full flex-col gap-6",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:"帮助中心"}),u.jsx("p",{className:"mt-1 text-sm text-[var(--color-text-muted)]",children:"安装部署、命令、控制台、插件与开放 API —— 命令与 API 两篇由代码自动生成,不会过期。"})]}),u.jsxs("div",{className:"flex flex-col gap-5 lg:flex-row lg:items-start",children:[u.jsx("aside",{className:"w-full shrink-0 lg:sticky lg:top-0 lg:max-h-[calc(100dvh-6rem)] lg:w-60 lg:overflow-y-auto",children:u.jsx("nav",{className:"rounded-[12px] border border-[var(--surface-card-border)] bg-[var(--surface-control)] p-2 shadow-[var(--shadow-nb)]",children:e.map(C=>u.jsxs("div",{children:[u.jsxs("button",{type:"button",onClick:()=>{i(C.id),f("")},"aria-current":C.id===n?"page":void 0,className:`flex w-full items-center gap-2 rounded-[8px] px-2.5 py-2 text-left text-sm transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--color-text)] ${C.id===n?"bg-[var(--color-primary)]/20 font-bold":"hover:bg-[var(--color-text)]/5"}`,children:[C.generated?u.jsx(v1,{size:14}):u.jsx(cr,{size:14}),u.jsx("span",{className:"min-w-0 flex-1 truncate",children:C.title})]}),C.id===n&&w.length>0&&u.jsx("ul",{className:"mt-1 mb-2 ml-3 border-l-2 border-[var(--color-text)]/20 pl-2",children:w.map(M=>u.jsx("li",{children:u.jsx("a",{href:`#${M.id}`,className:"block truncate rounded px-1.5 py-1 text-xs text-[var(--color-text-muted)] hover:bg-[var(--color-text)]/5 hover:text-[var(--color-text)]",children:M.text.replace(/[`*]/g,"")})},M.id))})]},C.id))})}),u.jsxs("section",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-3",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold",children:s}),d&&u.jsx("span",{className:"rounded-[6px] border border-[var(--color-border-light)] bg-[var(--color-info-bg)] px-2 py-0.5 text-[11px] font-bold",children:"自动生成 · 与代码同步"}),u.jsxs("label",{className:"ml-auto flex items-center gap-1.5 rounded-[8px] border border-[var(--control-border)] bg-[var(--surface-control)] px-2 py-1",children:[u.jsx(Hr,{size:14}),u.jsx("input",{value:m,onChange:C=>f(C.target.value),placeholder:"在本篇中查找","aria-label":"在本篇中查找",className:"w-40 bg-transparent text-sm outline-none"})]})]}),u.jsx("div",{ref:b,className:"rounded-[12px] border border-[var(--surface-card-border)] bg-[var(--surface-control)] px-5 py-4 shadow-[var(--shadow-nb)]",children:S.length===0?u.jsxs("p",{className:"py-8 text-center text-sm text-[var(--color-text-muted)]",children:["本篇中没有匹配「",m,"」的内容"]}):S.map((C,M)=>u.jsx(net,{b:C},`${C.kind}-${M}-${ooe(JSON.stringify(C).slice(0,40))}`))})]})]})]})}async function soe(){return(await _t("/api/plugins")).data??[]}async function aet(e,t){return fr("/api/plugins",{spec:e})}async function ret(e,t){return Bne(`/api/plugins/${encodeURIComponent(e)}`,{disabled:t})}async function oet(e){return qne(`/api/plugins/${encodeURIComponent(e)}`)}async function set(e,t){return $2(`/api/plugins/${encodeURIComponent(e)}/config`,{config:t})}const aH=1,cet=["react","react-dom","react/jsx-runtime","@tanstack/react-query","lucide-react","@coralai/console-ui","@coralai/console-slots"],_1=new Map,rH=new Set;function GD(){for(const e of rH)e()}function det(e){return rH.add(e),()=>rH.delete(e)}function uet(){return[..._1.values()]}function het(e){return t=>{switch(t){case"react":return fde;case"react/jsx-runtime":return hde;case"react-dom":return V1e;case"@tanstack/react-query":return cue;case"lucide-react":return mTe;case"@coralai/console-ui":return FPe;case"@coralai/console-slots":return{registerSlot:(n,i)=>sYe(n,{owner:e,order:i.order??100,...typeof i.match=="function"?{match:i.match}:{},...i.takeover===!0?{takeover:!0}:{},render:i.render}),contractVersion:aH};default:throw new Error(`插件 ${e} 要的模块 "${t}" 不在宿主模块表里(可用:${cet.join("、")})`)}}}function pet(){const e=globalThis;e.__SpsModuleLoader__||(e.__SpsModuleLoader__={load(t){const n=t.contractVersion??1;if(n!==aH){_1.set(t.id,{id:t.id,ok:!1,error:`插槽契约版本不匹配:插件按 v${n} 编译,当前是 v${aH}`}),GD();return}try{t.factory(het(t.id)),_1.set(t.id,{id:t.id,ok:!0})}catch(i){lYe(t.id),_1.set(t.id,{id:t.id,ok:!1,error:i instanceof Error?i.message:String(i)})}GD()}})}function fet(e){return new Promise(t=>{const n=document.createElement("script");n.src=`/api/plugins/${encodeURIComponent(e)}/client.js`,n.async=!0,n.dataset.spsPlugin=e,n.onerror=()=>{_1.set(e,{id:e,ok:!1,error:"脚本加载失败"}),GD(),t()},n.onload=()=>{_1.has(e)||(_1.set(e,{id:e,ok:!1,error:"脚本跑完了但没有调用 __SpsModuleLoader__.load()"}),GD()),t()},document.head.append(n)})}const met={slots:0};let aZ=new Map,rZ="";function oZ(){const e=uet(),t=pYe(),n=JSON.stringify([e,t]);if(n===rZ)return aZ;const i=new Map;for(const a of e)i.set(a.id,{ok:a.ok,...a.error?{error:a.error}:{},slots:0});for(const a of t)for(const r of a.owners){const s=i.get(r)??{slots:0};i.set(r,{...s,slots:s.slots+1})}return aZ=i,rZ=n,i}function yet(e){const t=det(e),n=UF(e);return()=>{t(),n()}}function loe(e){return E.useSyncExternalStore(yet,oZ,oZ).get(e)??met}function get(e){return!!e&&typeof e=="object"&&"refs"in e&&"uid"in e}const n1=(e,t)=>t===void 0?void 0:e.refs[String(t)];function ket(e){const t=n1(e,e.uid);return!t||t.type!=="object"||!t.dict?!1:Object.values(t.dict).every(n=>{var a;const i=n1(e,n);return i?["string","number","boolean"].includes(i.type)?!0:i.type==="union"?(i.list??[]).every(r=>{var s;return((s=n1(e,r))==null?void 0:s.type)==="const"}):i.type==="array"?((a=n1(e,i.inner))==null?void 0:a.type)==="string":!1:!1})}function xet({schema:e,value:t,onChange:n}){const i=get(e)?e:null,a=E.useMemo(()=>i?ket(i):!1,[i]),[r,s]=E.useState(()=>JSON.stringify(t??{},null,2)),[c,d]=E.useState(null);if(!i||!a)return u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx("label",{htmlFor:"plugin-config-raw",className:"text-sm font-bold",children:"配置(JSON)"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:i?"这个插件的配置里有通用表单认不出来的类型,先用 JSON 编辑。":"这个插件没有声明 Config —— 仍然可以直接写 JSON。"}),u.jsx("textarea",{id:"plugin-config-raw",className:"nb-input min-h-[180px] font-[family-name:var(--font-mono)] text-xs",value:r,onChange:f=>{s(f.target.value);try{n(JSON.parse(f.target.value||"{}")),d(null)}catch(k){d(k instanceof Error?k.message:String(k))}}}),c?u.jsxs("span",{className:"text-xs text-[var(--color-danger)]",children:["JSON 有误:",c]}):null]});const h=n1(i,i.uid),m=(f,k)=>n({...t,[f]:k});return u.jsx("div",{className:"flex flex-col gap-4",children:Object.entries(h.dict??{}).map(([f,k])=>{var C,M,L,j,A,I,T;const g=n1(i,k),b=t[f]??((C=g.meta)==null?void 0:C.default),v=u.jsxs("span",{className:"text-sm font-bold",children:[f,(M=g.meta)!=null&&M.required?u.jsx("span",{className:"text-[var(--color-danger)]",children:" *"}):null]}),w=(L=g.meta)!=null&&L.description?u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:g.meta.description}):null;if(g.type==="boolean")return u.jsxs("label",{className:"flex items-center gap-2",children:[u.jsx("input",{type:"checkbox",checked:!!b,onChange:P=>m(f,P.target.checked)}),u.jsxs("span",{className:"flex flex-col",children:[v,w]})]},f);if(g.type==="union"){const P=(g.list??[]).map(D=>{var q;return(q=n1(i,D))==null?void 0:q.value}).filter(D=>D!==void 0);return u.jsxs("label",{className:"flex flex-col gap-1",children:[v,w,u.jsx("select",{className:"nb-input text-sm",value:String(b??""),onChange:D=>m(f,D.target.value),children:P.map(D=>u.jsx("option",{value:String(D),children:String(D)},String(D)))})]},f)}if(g.type==="array"){const P=Array.isArray(b)?b:[];return u.jsxs("label",{className:"flex flex-col gap-1",children:[v,u.jsxs("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:[(j=g.meta)!=null&&j.description?`${g.meta.description} · `:"","一行一个"]}),u.jsx("textarea",{className:"nb-input min-h-[80px] font-[family-name:var(--font-mono)] text-xs",value:P.join(`
8634
8634
  `),onChange:D=>m(f,D.target.value.split(`
8635
8635
  `).map(q=>q.trim()).filter(Boolean))})]},f)}const S=((A=g.meta)==null?void 0:A.role)==="secret";return u.jsxs("label",{className:"flex flex-col gap-1",children:[v,w,u.jsx("input",{className:"nb-input text-sm",type:S?"password":g.type==="number"?"number":"text",value:b==null?"":String(b),...g.type==="number"?{min:(I=g.meta)==null?void 0:I.min,max:(T=g.meta)==null?void 0:T.max}:{},onChange:P=>m(f,g.type==="number"?Number(P.target.value):P.target.value)})]},f)})})}function dD(e){if(e instanceof xF&&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 sZ={network:"装不上是网络问题 —— 检查代理或 registry 后重试。",auth:"registry 要凭据 —— 配好 npm 认证再试。","not-found":"这个名字或版本在 registry 上不存在。","not-plugin":"它装上了,但不是 Cordis 插件(没有 apply 导出)。装配档没有被改。",apply:"插件自己的代码抛了 —— 这是插件作者的问题。",conflict:"和已有的插件撞了(同名 id,或它提供的服务已经被别人占了)。"};function lZ({fail:e,title:t}){const[n,i]=E.useState(!1);return u.jsx("div",{className:"nb-card !border-[var(--color-danger)] text-sm",children:u.jsxs("div",{className:"flex items-start gap-2",children:[u.jsx(xs,{size:16,className:"mt-0.5 shrink-0 text-[var(--color-danger)]"}),u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("p",{className:"font-medium",children:[t,":",e.error]}),u.jsxs("p",{className:"mt-1 text-[var(--color-text-muted)]",children:[u.jsx("code",{className:"text-xs",children:e.kind}),sZ[e.kind]?` · ${sZ[e.kind]}`:""]}),e.detail?u.jsxs(u.Fragment,{children:[u.jsx("button",{type:"button",className:"mt-2 text-xs underline text-[var(--color-text-muted)]",onClick:()=>i(a=>!a),children:n?"收起原文":"展开原文"}),n?u.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]})]})})}const bet=[{key:"user",title:"已装扩展",hint:"你自己装的插件。"},{key:"backend",title:"可换后端",hint:"换一行 name 就换掉实现;消费方一行不改。"},{key:"builtin",title:"内建能力包",hint:"把内建实现注册进对应的注册表。停用 = 那一类内建全部让路(比如让第三方生图适配器独占)。"},{key:"registry",title:"注册表(插座)",hint:"别人往里注册东西的挂载点,本身不需要配置。停用会让插在上面的一起失效。"}],vet=new Set(["tools","agents","repo","capabilities","media","im"]);function wet(e){return e.layer==="user"?"user":vet.has(e.key)?"registry":e.key.endsWith("-builtin")||e.key.startsWith("capabilities-")?"builtin":"backend"}function Met(e,t){return!!(t!=null&&t(e))||e.schema!==null}function _et({panelFor:e}){const t=Rt(),[n,i]=E.useState(""),[a,r]=E.useState(null),[s,c]=E.useState(null),[d,h]=E.useState(null),{data:m=[],isLoading:f}=nt({queryKey:["plugins"],queryFn:soe}),k=d?m.find(C=>C.key===d)??null:null,g=C=>{r(null),c(C??null),t.invalidateQueries({queryKey:["plugins"]})},b=Tt({mutationFn:()=>aet(n.trim()),onSuccess:C=>{i(""),g(C.warning)},onError:C=>r({title:"安装失败",fail:dD(C)})}),v=Tt({mutationFn:({key:C,disabled:M})=>ret(C,M),onSuccess:C=>g(C.warning),onError:C=>r({title:"启停失败",fail:dD(C)})}),w=Tt({mutationFn:C=>oet(C),onSuccess:C=>g(C.warning),onError:C=>r({title:"卸载失败",fail:dD(C)})}),S=b.isPending||v.isPending||w.isPending;return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"nb-card",children:[u.jsx("label",{htmlFor:"plugin-spec",className:"text-sm font-medium",children:"装一个插件"}),u.jsxs("p",{className:"mt-1 text-xs text-[var(--color-text-muted)]",children:["填 npm 包名(可带 ",u.jsx("code",{children:"@版本"}),")或本地路径。装完**当场生效**,不用重启。"]}),u.jsxs("div",{className:"mt-3 flex gap-2",children:[u.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:S}),u.jsxs("button",{type:"button",onClick:()=>b.mutate(),disabled:S||!n.trim(),className:"nb-btn nb-btn-primary",children:[b.isPending?u.jsx(lt,{size:16,className:"animate-spin"}):u.jsx(jn,{size:16}),"安装"]})]})]}),a?u.jsx(lZ,{fail:a.fail,title:a.title}):null,s?u.jsx(lZ,{fail:s,title:"操作完成,但有一件事没做成"}):null,f?u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"读取中…"}):u.jsx(o2,{name:"plugins.list",props:{rows:m,busy:S,onConfig:C=>h(C),onToggle:C=>{const M=m.find(L=>L.key===C);M&&v.mutate({key:C,disabled:!M.disabled})},onRemove:C=>w.mutate(C)},children:bet.map(C=>{const M=m.filter(L=>wet(L)===C.key);return M.length===0?null:u.jsxs("section",{className:"flex flex-col gap-3",children:[u.jsxs("header",{children:[u.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-base font-bold",children:C.title}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:C.hint})]}),u.jsx("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:M.map(L=>{const j={row:L,busy:S,hasConfig:Met(L,e),onConfig:()=>h(L.key),onToggle:()=>v.mutate({key:L.key,disabled:!L.disabled}),onRemove:()=>w.mutate(L.key)};return u.jsx(o2,{name:"plugins.card",props:j,children:u.jsx(Eet,{...j})},L.key)})})]},C.key)})}),k?u.jsx(dV,{onClose:()=>h(null),children:u.jsxs("div",{className:"nb-card flex max-h-[88vh] w-full max-w-[min(1040px,94vw)] flex-col overflow-hidden !p-0",children:[u.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-4 border-b border-[var(--color-border-light)] px-5 py-3",children:[u.jsx("h2",{className:"min-w-0 truncate font-[family-name:var(--font-heading)] text-base font-bold",children:k.key}),u.jsx("button",{type:"button",onClick:()=>h(null),"aria-label":"关闭",title:"关闭",className:"nb-btn shrink-0 !px-2 !py-1",children:u.jsx(nn,{size:14,strokeWidth:2.5})})]}),u.jsxs("div",{className:"flex flex-col divide-y divide-[var(--color-border-light)] overflow-y-auto",children:[(()=>{const C=(e==null?void 0:e(k))??(k.schema!==null?u.jsx(Cet,{row:k,onSaved:M=>{h(null),g(M)},onFail:r}):null);return C?u.jsx("div",{className:"px-5 py-4",children:C}):null})(),u.jsx("div",{className:"px-5 py-4",children:u.jsx(Net,{row:k})})]})]})}):null]})}function Net({row:e}){const t=loe(e.key),n=[["包",e.pkg??e.name],["版本",e.version??"—"],["来源",e.layer==="factory"?"内建(随包出厂,只能停用)":"你装的"],["分类",e.category??"—"],["状态",e.disabled?"已停用":e.mounted?"运行中":"未挂上(装配档里有,但没启动起来)"],...e.essential?[["内核依赖",`停不掉 —— ${e.essential}`]]:[],["界面",e.clientFormat===null?"没有浏览器半区":e.clientFormat==="dsh"?"dsh 格式,没有装(需要移植)":t.ok===!1?`没加载起来:${t.error}`:`已加载 · 贡献了 ${t.slots} 个界面块`]];return u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-base font-bold",children:"插件信息"}),u.jsx("p",{className:"text-sm leading-5 text-[var(--color-text-muted)]",children:e.description||"(这个插件没写简介)"}),u.jsx("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-xs",children:n.map(([i,a])=>u.jsxs(E.Fragment,{children:[u.jsx("dt",{className:"text-[var(--color-text-subtle)]",children:i}),u.jsx("dd",{className:"break-all font-[family-name:var(--font-mono)]",children:a})]},i))}),e.schema===null?u.jsx("p",{className:"text-xs text-[var(--color-text-subtle)]",children:"这个插件没有声明可配置项 —— 只能开关。"}):null]})}function Eet({row:e,busy:t,hasConfig:n,onConfig:i,onToggle:a,onRemove:r}){const s=loe(e.key),c=E.useSyncExternalStore(UF,uZ,uZ).filter(h=>h.owner===e.key),d=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 u.jsxs("article",{className:"nb-card nb-card-interactive relative flex flex-col gap-3",children:[u.jsx("button",{type:"button",onClick:i,"aria-label":`${n?"配置":"查看"} ${e.key}`,className:"absolute inset-0 cursor-pointer rounded-[inherit] border-0 bg-transparent"}),u.jsxs("div",{className:"flex items-start justify-between gap-2",children:[u.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}),u.jsx("span",{className:`nb-badge shrink-0 text-[10px] ${d.cls}`,title:e.disabled?"人主动停用的":e.mounted?"这个进程里正挂着":"装配档里有它,但没挂起来 —— 多半是它启动时抛了",children:d.text})]}),u.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.category?u.jsx("span",{className:"nb-badge text-[10px]",children:e.category}):null,e.essential?u.jsx("span",{className:"nb-badge text-[10px] opacity-70",title:e.essential,children:"内核依赖"}):null,u.jsx("span",{className:"nb-badge text-[10px] opacity-70",children:e.layer==="factory"?"内建":"已装"})]}),u.jsx("p",{className:"line-clamp-3 text-sm leading-5 text-[var(--color-text-muted)]",children:e.description||"(无简介)"}),e.clientFormat==="dsh"?u.jsxs("div",{className:"rounded-md border border-[var(--color-border-light)] bg-[var(--color-bg-soft)] px-2 py-1.5",children:[u.jsx("p",{className:"text-[11px] font-bold",children:"界面部分是 dsh 格式,没有装"}),u.jsxs("p",{className:"mt-0.5 text-[10px] text-[var(--color-text-muted)]",children:["它调 ",u.jsx("code",{children:"__ModuleLoader__"})," 并用 dsh 的槽名,需要移植。",u.jsx("b",{children:"工具/宿主部分不受影响。"})]})]}):s.ok===!1?u.jsxs("div",{className:"rounded-md border border-[var(--color-danger)] bg-[var(--color-danger)]/10 px-2 py-1.5",children:[u.jsx("p",{className:"text-[11px] font-bold",children:"界面部分没加载起来"}),u.jsx("p",{className:"mt-0.5 break-words text-[10px] text-[var(--color-text-muted)]",children:s.error})]}):s.slots>0?u.jsxs("p",{className:"text-[11px] text-[var(--color-text-muted)]",children:["贡献了 ",s.slots," 个界面块"]}):null,c.length>0?u.jsxs("div",{className:"rounded-md border border-[var(--color-warning,#c90)] bg-[var(--color-warning,#c90)]/10 px-2 py-1.5",children:[u.jsxs("p",{className:"text-[11px] font-bold",children:["接管了 ",c.length," 处界面"]}),u.jsx("ul",{className:"mt-0.5 font-[family-name:var(--font-mono)] text-[10px] text-[var(--color-text-muted)]",children:c.map(h=>u.jsx("li",{className:"truncate",children:h.slot},h.slot))})]}):null,e.takeovers.length>0?u.jsxs("div",{className:"rounded-md border border-[var(--color-warning,#c90)] bg-[var(--color-warning,#c90)]/10 px-2 py-1.5",children:[u.jsxs("p",{className:"text-[11px] font-bold",children:["接管了 ",e.takeovers.length," 条宿主路由"]}),u.jsx("ul",{className:"mt-0.5 font-[family-name:var(--font-mono)] text-[10px] text-[var(--color-text-muted)]",children:e.takeovers.map(h=>u.jsx("li",{className:"truncate",children:h.kind==="prefix"?`${h.path}/*`:h.path},`${h.kind}:${h.path}`))})]}):null,u.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-[var(--color-border-light)] pt-2",children:[u.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}`:""]}),u.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n?u.jsx(R0,{size:13,strokeWidth:2.5,"aria-hidden":!0,className:"text-[var(--color-text-subtle)]"}):null,u.jsx("button",{type:"button",className:"nb-btn relative z-10 !px-2 !py-1",onClick:a,disabled:t||!e.disabled&&e.essential!==null,"aria-label":e.disabled?`启用 ${e.key}`:`停用 ${e.key}`,title:!e.disabled&&e.essential?`内核直接依赖它,停不掉:${e.essential}。要换实现请改装配档那一行的 name。`:e.disabled?"启用":"停用",children:u.jsx(L0,{size:13,strokeWidth:2.5})}),u.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:u.jsx(Mi,{size:13,strokeWidth:2.5})})]})]})]})}function Cet({row:e,onSaved:t,onFail:n}){const[i,a]=E.useState(()=>e.config&&typeof e.config=="object"?{...e.config}:{}),r=Tt({mutationFn:()=>set(e.key,i),onSuccess:s=>t(s.warning),onError:s=>n({title:"保存配置失败",fail:dD(s)})});return u.jsxs("section",{className:"flex flex-col gap-4",children:[u.jsxs("header",{className:"flex items-start justify-between gap-3",children:[u.jsx("div",{className:"min-w-0",children:u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:e.description||"(无简介)"})}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary shrink-0",disabled:r.isPending,onClick:()=>r.mutate(),"aria-label":`保存 ${e.key} 的配置`,children:[r.isPending?u.jsx(lt,{size:14,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:2.5}),"保存"]})]}),u.jsx(xet,{schema:e.schema,value:i,onChange:a}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"保存后**当场重挂**这个插件 —— 配置只在挂载那一刻读一次,不重挂等于没改。"})]})}let cZ=[],dZ="";function uZ(){const e=uYe(),t=JSON.stringify(e);return t!==dZ&&(dZ=t,cZ=e),cZ}function Let(e){return _t(`/api/media-providers?capability=${encodeURIComponent(e)}`)}async function jet(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 Aet(e){return gO(`/api/media-providers/${encodeURIComponent(e)}`)}async function Iet(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 oH={image:"图片",video:"视频",music:"音乐",voice:"语音","3d":"3D",embedding:"向量(Embedding)",rerank:"重排(Rerank)"},Tet={image:["codex","openai","volcengine","minimax","tripo","agnes","bailian","openrouter"],video:["volcengine"],music:["minimax"],voice:["doubao"],"3d":["tripo"],embedding:["openai-compatible"],rerank:["openai-compatible"]},coe={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":""},Ret=new Set(["codex"]);function Det({capability:e}){var w,S,C;const t=Rt(),{alert:n,confirm:i}=ni(),a=nt({queryKey:["media-providers",e],queryFn:()=>Let(e)}),[r,s]=E.useState(null),c=Tet[e]??[],d=((w=a.data)==null?void 0:w.providers)??[],h=(C=(S=a.data)==null?void 0:S.defaults)==null?void 0:C[e],m=Tt({mutationFn:M=>jet(M),onSuccess:()=>{s(null),t.invalidateQueries({queryKey:["media-providers",e]})},onError:M=>void n({title:"保存失败",body:M instanceof Error?M.message:String(M)})}),f=Tt({mutationFn:M=>Aet(M),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:M=>void n({title:"删除失败",body:M instanceof Error?M.message:String(M)})}),k=Tt({mutationFn:M=>Iet(e,M),onSuccess:()=>void t.invalidateQueries({queryKey:["media-providers",e]}),onError:M=>void n({title:"设默认失败",body:M instanceof Error?M.message:String(M)})}),g=(M,L)=>(h==null?void 0:h.providerId)===M&&(h==null?void 0:h.model)===L,b=()=>s({isNew:!0,entry:{id:"",name:"",capability:e,adapter:c[0]??"",baseUrl:c[0]?coe[c[0]]??"":"",apiKey:"",models:[]}}),v=M=>s({isNew:!1,entry:{id:M.id,name:M.name,capability:e,adapter:M.adapter,baseUrl:M.baseUrl,apiKey:"",models:M.models}});return u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[u.jsxs("div",{children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:[oH[e],"供应商"]}),u.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["增删该能力的第三方生成端点(adapter + Base URL + key + models)。**点模型标签设为该能力默认**;✓ = 当前默认。",h?u.jsxs(u.Fragment,{children:[" ","当前默认:",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:h.providerId}),h.model?u.jsxs(u.Fragment,{children:[" · ",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:h.model})]}):null]}):" 当前默认:未设置"]})]}),u.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",onClick:b,"aria-label":`添加${oH[e]}供应商`,children:[u.jsx(jn,{size:14,strokeWidth:3})," 添加供应商"]})]}),u.jsxs("div",{className:"flex flex-col gap-2 mt-4",children:[a.isLoading&&u.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[u.jsx(lt,{size:14,strokeWidth:3,className:"animate-spin"})," 加载中…"]}),!a.isLoading&&d.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无供应商)"}),d.map(M=>u.jsxs("div",{className:"rounded-lg px-3 py-2 border-2 border-[var(--color-text)]",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:M.id}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",M.name]}),u.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:M.adapter}),u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[M.baseUrl," · key ",M.keyMasked||"未设置"]})]}),u.jsxs("div",{className:"flex gap-1 shrink-0",children:[u.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>v(M),"aria-label":`编辑 ${M.id}`,children:u.jsx(y1,{size:12,strokeWidth:3})}),u.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除供应商",body:`删除 ${M.id}?`,danger:!0})&&f.mutate(M.id)},"aria-label":`删除 ${M.id}`,children:u.jsx(Mi,{size:12,strokeWidth:3})})]})]}),M.models.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:M.models.map(L=>{const j=g(M.id,L);return u.jsxs("button",{type:"button",onClick:()=>k.mutate({providerId:M.id,model:L}),disabled:k.isPending,"aria-pressed":j,className:["nb-btn px-2 py-0.5 text-xs font-[family-name:var(--font-mono)]",j?"nb-btn-mint":""].join(" "),title:j?"当前默认":"设为该能力默认",children:[L,j?" ✓":""]},L)})})]},M.id))]}),r&&u.jsx(dV,{onClose:()=>s(null),children:u.jsx(zet,{state:r,adapters:c,onChange:M=>s({...r,entry:M}),onCancel:()=>s(null),onSave:M=>m.mutate(M),saving:m.isPending})})]})}function Oet(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const a=i.trim();a&&!n.includes(a)&&n.push(a)}return n}function zet({state:e,adapters:t,onChange:n,onCancel:i,onSave:a,saving:r}){const s=e.entry,[c,d]=E.useState(""),h=g=>n({...s,...g}),m=Ret.has(s.adapter),f=/^[a-zA-Z0-9_-]+$/.test(s.id)&&!!s.name.trim()&&!!s.adapter.trim()&&(m||!!s.baseUrl.trim()),k=g=>{h({adapter:g,baseUrl:coe[g]??""})};return u.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:[u.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增供应商":`编辑 ${s.id}`,u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:[" (",oH[s.capability],")"]})]}),u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:s.id,disabled:!e.isNew,onChange:g=>h({id:g.target.value}),placeholder:"如 my-tripo",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",u.jsx("input",{className:"nb-input",value:s.name,onChange:g=>h({name:g.target.value}),placeholder:"显示名"})]})]}),u.jsxs("div",{className:"flex flex-col gap-1 text-sm font-bold",children:["adapter",u.jsx(H0,{value:s.adapter,onChange:k,ariaLabel:"adapter",options:t.map(g=>({value:g,label:g}))})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",m&&"(订阅无需,可留空)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:s.baseUrl,onChange:g=>h({baseUrl:g.target.value}),placeholder:m?"订阅走本地凭据,无需填":"https://api.example.com",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",m?"(订阅无需)":!e.isNew&&"(留空=保留)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:s.apiKey??"",onChange:g=>h({apiKey:g.target.value}),placeholder:m?"订阅无需":e.isNew?"sk-...":"留空保留",spellCheck:!1})]}),u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),u.jsx(doe,{models:s.models,draft:c,onModelsChange:g=>h({models:g}),onDraftChange:d}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),u.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[u.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:i,children:"取消"}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!f||r,onClick:()=>a({...s,models:Oet(s.models,c)}),children:[r?u.jsx(lt,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:3})," 保存"]})]})]})}async function Pet(){return(await _t("/api/mcp-tools")).tools}const $et=[{key:"plugin",labelKey:"plugins.tab.plugin"},{key:"model",labelKey:"plugins.tab.model"},{key:"tool",labelKey:"plugins.tab.tool"}];function qet(e){const t={pluginKey:e.key,name:e.name};return cYe("plugin.config",t)?u.jsx(o2,{name:"plugin.config",props:t}):null}function Bet(){const e=Ze(),[t,n]=E.useState("plugin");return u.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[u.jsxs("header",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:e("plugins.h1")}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:e("plugins.desc")})]}),u.jsx($1,{ariaLabel:e("plugins.h1"),className:"",value:t,onChange:n,options:$et.map(i=>({value:i.key,label:e(i.labelKey)}))}),u.jsx("div",{role:"tabpanel",children:t==="plugin"?u.jsx(_et,{panelFor:qet}):t==="model"?u.jsx(Vet,{}):u.jsx(Get,{})})]})}const Het=[{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 Fet(){const e=Ze(),t=Rt(),n=E.useRef(null),[i,a]=E.useState(!1),r=async()=>{a(!0);try{const c=await _t("/api/model-config/export"),d=new Blob([JSON.stringify(c,null,2)],{type:"application/json"}),h=document.createElement("a");h.href=URL.createObjectURL(d),h.download=`sps-model-config-${new Date().toISOString().slice(0,10)}.json`,h.click(),URL.revokeObjectURL(h.href)}catch(c){window.alert(`${e("plugins.model.export.failed")}: ${c instanceof Error?c.message:String(c)}`)}finally{a(!1)}},s=async c=>{a(!0);try{const d=JSON.parse(await c.text());if(!window.confirm(e("plugins.model.import.confirm")))return;const m=(await fr("/api/model-config/import",d)).summary;window.alert(e("plugins.model.import.done",{llm:String(Number(m.llmAnthropic??0)+Number(m.llmOpenai??0)),media:String(m.media??0),skipped:String(m.skipped??0)})),t.invalidateQueries()}catch(d){window.alert(`${e("plugins.model.import.failed")}: ${d instanceof Error?d.message:String(d)}`)}finally{a(!1),n.current&&(n.current.value="")}};return u.jsxs("div",{className:"flex gap-2 items-center ml-auto",children:[u.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px"},disabled:i,onClick:()=>void r(),title:e("plugins.model.export.hint"),children:[u.jsx(Fh,{size:14,strokeWidth:2.5})," ",e("plugins.model.export")]}),u.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:[u.jsx(x1,{size:14,strokeWidth:2.5})," ",e("plugins.model.import")]}),u.jsx("input",{ref:n,type:"file",accept:"application/json,.json",className:"hidden",onChange:c=>{var h;const d=(h=c.target.files)==null?void 0:h[0];d&&s(d)}})]})}function Vet(){const[e,t]=E.useState("llm");return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex flex-wrap gap-2 items-center",role:"tablist","aria-label":"模型/资源供应商",children:[Het.map(n=>{const i=e===n.key;return u.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)}),u.jsx(Fet,{})]}),e==="llm"?u.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["Anthropic 兼容 ",u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 Claude 订阅"})]}),u.jsx(hZ,{only:"anthropic"})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base border-b-2 border-[var(--color-text)] pb-1",children:["OpenAI 兼容 ",u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"· 含 codex 订阅"})]}),u.jsx(hZ,{only:"openai"})]})]}):u.jsx(Det,{capability:e})]})}function hZ({only:e}={}){var C,M,L;const t=Rt(),{alert:n,confirm:i}=ni(),a=nt({queryKey:["providers"],queryFn:FF}),s=(C=nt({queryKey:["system-agents"],queryFn:bF}).data)==null?void 0:C.agents,[c,d]=E.useState(null),h=Tt({mutationFn:j=>WXe(c.kind,j),onSuccess:()=>{d(null),t.invalidateQueries({queryKey:["providers"]})},onError:j=>void n({title:"保存失败",body:j instanceof Error?j.message:String(j)})}),m=Tt({mutationFn:j=>XXe(j.kind,j.id),onSuccess:()=>void t.invalidateQueries({queryKey:["providers"]}),onError:j=>void n({title:"删除失败",body:j instanceof Error?j.message:String(j)})}),f=Tt({mutationFn:j=>KPe(j),onSuccess:()=>void t.invalidateQueries({queryKey:["system-agents"]}),onError:j=>void n({title:"设默认失败",body:j instanceof Error?j.message:String(j)})}),k=(j,A,I)=>{if(!s)return!1;const T=j==="anthropic"?s.worker:s.reviewer;return(T.providerId||"official")===A&&T.model===I},g=(j,A,I)=>{if(!s)return;let T;if(j==="anthropic"){const P={...s.worker,model:I};A==="official"?delete P.providerId:P.providerId=A,T={...s,worker:P}}else T={...s,reviewer:{...s.reviewer,providerId:A,model:I}};f.mutate(T)},b=[{kind:"anthropic",title:"Anthropic 兼容(worker / claude)",items:((M=a.data)==null?void 0:M.anthropic)??[]},{kind:"openai",title:"OpenAI 兼容(reviewer / openai agent)",items:((L=a.data)==null?void 0:L.openai)??[]}],v=e?b.filter(j=>j.kind===e):b,w=j=>d({kind:j,isNew:!0,entry:{id:"",name:"",baseUrl:"",apiKey:"",models:[]}}),S=(j,A)=>d({kind:j,isNew:!1,entry:{id:A.id,name:A.name,baseUrl:A.baseUrl,apiKey:"",transport:A.transport,models:A.models}});return u.jsxs("section",{className:"nb-card",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:"模型 API 端点"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-4",children:"本地官方订阅(已登录验证)自动置顶,不可编辑;下方可增删第三方兼容端点。**点模型标签设为默认**(anthropic→worker / openai→监工);✓ = 当前默认。"}),u.jsx("div",{className:["grid grid-cols-1 gap-5",e?"":"lg:grid-cols-2"].join(" "),children:v.map(j=>u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"font-bold text-sm",children:j.title}),u.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:()=>w(j.kind),"aria-label":`添加 ${j.title} 端点`,children:[u.jsx(jn,{size:12,strokeWidth:3})," 添加"]})]}),j.items.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无端点)"}),j.items.map(A=>u.jsxs("div",{className:["rounded-lg px-3 py-2 border-2",(A.builtin,"border-[var(--color-text)]")].join(" "),children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:A.id}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",A.name]}),A.builtin?u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:["本地订阅",A.detail?` · ${A.detail}`:""," · 已验证可用"]}):u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[A.baseUrl," · key ",A.hasKey?A.apiKey:"未设置"]})]}),A.builtin?u.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:"内置"}):u.jsxs("div",{className:"flex gap-1 shrink-0",children:[u.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>S(j.kind,A),"aria-label":`编辑 ${A.id}`,children:u.jsx(y1,{size:12,strokeWidth:3})}),u.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await i({title:"删除端点",body:`删除 ${A.id}?`,danger:!0})&&m.mutate({kind:j.kind,id:A.id})},"aria-label":`删除 ${A.id}`,children:u.jsx(Mi,{size:12,strokeWidth:3})})]})]}),A.models.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:A.models.map(I=>{const T=k(j.kind,A.id,I);return u.jsxs("button",{type:"button",onClick:()=>g(j.kind,A.id,I),disabled:f.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:[I,T?" ✓":""]},I)})})]},A.id))]},j.kind))}),c&&u.jsx(dV,{onClose:()=>d(null),children:u.jsx(Uet,{state:c,onChange:j=>d({...c,entry:j}),onCancel:()=>d(null),onSave:j=>h.mutate(j),saving:h.isPending})})]})}function sH(e,t){const n=[...e];for(const i of t.split(/[,,\n\r]+/)){const a=i.trim();a&&!n.includes(a)&&n.push(a)}return n}function doe({models:e,draft:t,onModelsChange:n,onDraftChange:i}){const a=r=>{n(sH(e,r)),i("")};return u.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=>u.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:[u.jsx("span",{className:"max-w-[480px] truncate",children:r}),u.jsx("button",{type:"button",className:"shrink-0 text-[var(--color-text-muted)] hover:text-[var(--color-text)]",onClick:()=>n(e.filter(s=>s!==r)),"aria-label":`删除模型 ${r}`,children:u.jsx(nn,{size:12,strokeWidth:2.5})})]},r)),u.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 s=r.target.value,c=s.split(/[,,\n\r]/);if(c.length===1){i(s);return}const d=c.pop()??"";n(sH(e,c.join(","))),i(d)},onKeyDown:r=>{r.key==="Enter"&&!r.nativeEvent.isComposing?(r.preventDefault(),a(t)):r.key==="Backspace"&&!t&&e.length>0&&n(e.slice(0,-1))},placeholder:e.length>0?"继续添加模型":"输入模型名后按 Enter","aria-label":"Models",spellCheck:!1})]})}function Uet({state:e,onChange:t,onCancel:n,onSave:i,saving:a}){const r=e.entry,[s,c]=E.useState(""),d=m=>t({...r,...m}),h=/^[a-zA-Z0-9_-]+$/.test(r.id)&&r.name.trim()&&r.baseUrl.trim();return u.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:[u.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增端点":`编辑 ${r.id}`,u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:["(",e.kind,")"]})]}),u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:r.id,disabled:!e.isNew,onChange:m=>d({id:m.target.value}),placeholder:"如 my-openai",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",u.jsx("input",{className:"nb-input",value:r.name,onChange:m=>d({name:m.target.value}),placeholder:"显示名"})]})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:r.baseUrl,onChange:m=>d({baseUrl:m.target.value}),placeholder:"https://api.example.com/v1",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",!e.isNew&&"(留空=保留)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:r.apiKey??"",onChange:m=>d({apiKey:m.target.value}),placeholder:e.isNew?"sk-...":"••••(留空不改)",spellCheck:!1})]}),e.kind==="openai"&&u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["请求方言",u.jsxs("select",{className:"nb-input text-sm",value:r.transport??"chat_completions",onChange:m=>d({transport:m.target.value}),children:[u.jsx("option",{value:"chat_completions",children:"Chat Completions(/v1/chat/completions,默认)"}),u.jsx("option",{value:"responses",children:"Responses(/v1/responses)"})]}),u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)]",children:"走 codex 订阅的网关端点(如 gpt-*)必须选 Responses,否则上游 400。"})]}),u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("label",{htmlFor:"provider-models",className:"text-sm font-bold",children:"Models"}),u.jsx(doe,{models:r.models,draft:s,onModelsChange:m=>d({models:m}),onDraftChange:c}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"输入模型名,按 Enter 或逗号添加"})]}),u.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[u.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:n,children:"取消"}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!h||a,onClick:()=>i({...r,models:sH(r.models,s)}),children:[a?u.jsx(lt,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:3})," 保存"]})]})]})}function dV({children:e,onClose:t}){return hO.createPortal(u.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/50 p-4",onClick:t,children:u.jsx("div",{onClick:n=>n.stopPropagation(),children:e})}),document.body)}const Ket=["skill","asset","project","interaction","memory","agent","other"];function Get(){const e=Ze(),t=nt({queryKey:["mcp-tools"],queryFn:Pet});if(t.isLoading)return u.jsx("section",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.loading")})});if(t.isError)return u.jsx("section",{className:"nb-card",children:u.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=Ket.map(a=>({key:a,items:n.filter(r=>r.group===a)})).filter(a=>a.items.length>0);return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsx("section",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("plugins.tool.desc",{count:String(n.length)})})}),i.map(a=>u.jsxs("div",{className:"flex flex-col gap-2",children:[u.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.${a.key}`),u.jsx("span",{className:"text-xs font-normal text-[var(--color-text-muted)] ml-2",children:a.items.length})]}),u.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:a.items.map(r=>u.jsxs("section",{className:"nb-card flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-baseline gap-2 flex-wrap",children:[u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold",children:r.name}),!r.viaMcpOnOpenai&&u.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")})]}),u.jsx("p",{className:"text-sm leading-5",children:r.description}),r.params.length>0&&u.jsx("ul",{className:"flex flex-col gap-1 m-0 p-0 list-none",children:r.params.map(s=>u.jsxs("li",{className:"text-xs text-[var(--color-text-muted)] leading-4",children:[u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[var(--color-text)]",children:s.name}),u.jsx("span",{className:"ml-1",children:s.type}),s.required&&u.jsx("span",{className:"ml-1 font-bold",children:e("plugins.tool.required")}),s.description&&u.jsxs("span",{className:"ml-1",children:["— ",s.description]})]},s.name))}),u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-[11px] text-[var(--color-text-subtle)]",children:r.qualifiedName})]},r.name))})]},a.key))]})}function Xn(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=Xn(e[n]))!==""&&(t+=(t&&" ")+i);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var Wet={value:()=>{}};function qO(){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 uD(n)}function uD(e){this._=e}function Xet(e,t){return e.trim().split(/^|\s+/).map(function(n){var i="",a=n.indexOf(".");if(a>=0&&(i=n.slice(a+1),n=n.slice(0,a)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}uD.prototype=qO.prototype={constructor:uD,on:function(e,t){var n=this._,i=Xet(e+"",n),a,r=-1,s=i.length;if(arguments.length<2){for(;++r<s;)if((a=(e=i[r]).type)&&(a=Yet(n[a],e.name)))return a;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++r<s;)if(a=(e=i[r]).type)n[a]=pZ(n[a],e.name,t);else if(t==null)for(a in n)n[a]=pZ(n[a],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new uD(e)},call:function(e,t){if((a=arguments.length-2)>0)for(var n=new Array(a),i=0,a,r;i<a;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(r=this._[e],i=0,a=r.length;i<a;++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],a=0,r=i.length;a<r;++a)i[a].value.apply(t,n)}};function Yet(e,t){for(var n=0,i=e.length,a;n<i;++n)if((a=e[n]).name===t)return a.value}function pZ(e,t,n){for(var i=0,a=e.length;i<a;++i)if(e[i].name===t){e[i]=Wet,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var lH="http://www.w3.org/1999/xhtml";const fZ={svg:"http://www.w3.org/2000/svg",xhtml:lH,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function BO(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),fZ.hasOwnProperty(t)?{space:fZ[t],local:e}:e}function Qet(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===lH&&t.documentElement.namespaceURI===lH?t.createElement(e):t.createElementNS(n,e)}}function Zet(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function uoe(e){var t=BO(e);return(t.local?Zet:Qet)(t)}function Jet(){}function uV(e){return e==null?Jet:function(){return this.querySelector(e)}}function ett(e){typeof e!="function"&&(e=uV(e));for(var t=this._groups,n=t.length,i=new Array(n),a=0;a<n;++a)for(var r=t[a],s=r.length,c=i[a]=new Array(s),d,h,m=0;m<s;++m)(d=r[m])&&(h=e.call(d,d.__data__,m,r))&&("__data__"in d&&(h.__data__=d.__data__),c[m]=h);return new pa(i,this._parents)}function ttt(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function ntt(){return[]}function hoe(e){return e==null?ntt:function(){return this.querySelectorAll(e)}}function itt(e){return function(){return ttt(e.apply(this,arguments))}}function att(e){typeof e=="function"?e=itt(e):e=hoe(e);for(var t=this._groups,n=t.length,i=[],a=[],r=0;r<n;++r)for(var s=t[r],c=s.length,d,h=0;h<c;++h)(d=s[h])&&(i.push(e.call(d,d.__data__,h,s)),a.push(d));return new pa(i,a)}function poe(e){return function(){return this.matches(e)}}function foe(e){return function(t){return t.matches(e)}}var rtt=Array.prototype.find;function ott(e){return function(){return rtt.call(this.children,e)}}function stt(){return this.firstElementChild}function ltt(e){return this.select(e==null?stt:ott(typeof e=="function"?e:foe(e)))}var ctt=Array.prototype.filter;function dtt(){return Array.from(this.children)}function utt(e){return function(){return ctt.call(this.children,e)}}function htt(e){return this.selectAll(e==null?dtt:utt(typeof e=="function"?e:foe(e)))}function ptt(e){typeof e!="function"&&(e=poe(e));for(var t=this._groups,n=t.length,i=new Array(n),a=0;a<n;++a)for(var r=t[a],s=r.length,c=i[a]=[],d,h=0;h<s;++h)(d=r[h])&&e.call(d,d.__data__,h,r)&&c.push(d);return new pa(i,this._parents)}function moe(e){return new Array(e.length)}function ftt(){return new pa(this._enter||this._groups.map(moe),this._parents)}function WD(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}WD.prototype={constructor:WD,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 mtt(e){return function(){return e}}function ytt(e,t,n,i,a,r){for(var s=0,c,d=t.length,h=r.length;s<h;++s)(c=t[s])?(c.__data__=r[s],i[s]=c):n[s]=new WD(e,r[s]);for(;s<d;++s)(c=t[s])&&(a[s]=c)}function gtt(e,t,n,i,a,r,s){var c,d,h=new Map,m=t.length,f=r.length,k=new Array(m),g;for(c=0;c<m;++c)(d=t[c])&&(k[c]=g=s.call(d,d.__data__,c,t)+"",h.has(g)?a[c]=d:h.set(g,d));for(c=0;c<f;++c)g=s.call(e,r[c],c,r)+"",(d=h.get(g))?(i[c]=d,d.__data__=r[c],h.delete(g)):n[c]=new WD(e,r[c]);for(c=0;c<m;++c)(d=t[c])&&h.get(k[c])===d&&(a[c]=d)}function ktt(e){return e.__data__}function xtt(e,t){if(!arguments.length)return Array.from(this,ktt);var n=t?gtt:ytt,i=this._parents,a=this._groups;typeof e!="function"&&(e=mtt(e));for(var r=a.length,s=new Array(r),c=new Array(r),d=new Array(r),h=0;h<r;++h){var m=i[h],f=a[h],k=f.length,g=btt(e.call(m,m&&m.__data__,h,i)),b=g.length,v=c[h]=new Array(b),w=s[h]=new Array(b),S=d[h]=new Array(k);n(m,f,v,w,S,g,t);for(var C=0,M=0,L,j;C<b;++C)if(L=v[C]){for(C>=M&&(M=C+1);!(j=w[M])&&++M<b;);L._next=j||null}}return s=new pa(s,i),s._enter=c,s._exit=d,s}function btt(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function vtt(){return new pa(this._exit||this._groups.map(moe),this._parents)}function wtt(e,t,n){var i=this.enter(),a=this,r=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),t!=null&&(a=t(a),a&&(a=a.selection())),n==null?r.remove():n(r),i&&a?i.merge(a).order():a}function Mtt(e){for(var t=e.selection?e.selection():e,n=this._groups,i=t._groups,a=n.length,r=i.length,s=Math.min(a,r),c=new Array(a),d=0;d<s;++d)for(var h=n[d],m=i[d],f=h.length,k=c[d]=new Array(f),g,b=0;b<f;++b)(g=h[b]||m[b])&&(k[b]=g);for(;d<a;++d)c[d]=n[d];return new pa(c,this._parents)}function _tt(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var i=e[t],a=i.length-1,r=i[a],s;--a>=0;)(s=i[a])&&(r&&s.compareDocumentPosition(r)^4&&r.parentNode.insertBefore(s,r),r=s);return this}function Stt(e){e||(e=Ntt);function t(f,k){return f&&k?e(f.__data__,k.__data__):!f-!k}for(var n=this._groups,i=n.length,a=new Array(i),r=0;r<i;++r){for(var s=n[r],c=s.length,d=a[r]=new Array(c),h,m=0;m<c;++m)(h=s[m])&&(d[m]=h);d.sort(t)}return new pa(a,this._parents).order()}function Ntt(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Ett(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Ctt(){return Array.from(this)}function Ltt(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],a=0,r=i.length;a<r;++a){var s=i[a];if(s)return s}return null}function jtt(){let e=0;for(const t of this)++e;return e}function Att(){return!this.node()}function Itt(e){for(var t=this._groups,n=0,i=t.length;n<i;++n)for(var a=t[n],r=0,s=a.length,c;r<s;++r)(c=a[r])&&e.call(c,c.__data__,r,a);return this}function Ttt(e){return function(){this.removeAttribute(e)}}function Rtt(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Dtt(e,t){return function(){this.setAttribute(e,t)}}function Ott(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function ztt(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Ptt(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 $tt(e,t){var n=BO(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?Rtt:Ttt:typeof t=="function"?n.local?Ptt:ztt:n.local?Ott:Dtt)(n,t))}function yoe(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function qtt(e){return function(){this.style.removeProperty(e)}}function Btt(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Htt(e,t,n){return function(){var i=t.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,n)}}function Ftt(e,t,n){return arguments.length>1?this.each((t==null?qtt:typeof t=="function"?Htt:Btt)(e,t,n??"")):Ap(this.node(),e)}function Ap(e,t){return e.style.getPropertyValue(t)||yoe(e).getComputedStyle(e,null).getPropertyValue(t)}function Vtt(e){return function(){delete this[e]}}function Utt(e,t){return function(){this[e]=t}}function Ktt(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Gtt(e,t){return arguments.length>1?this.each((t==null?Vtt:typeof t=="function"?Ktt:Utt)(e,t)):this.node()[e]}function goe(e){return e.trim().split(/^|\s+/)}function hV(e){return e.classList||new koe(e)}function koe(e){this._node=e,this._names=goe(e.getAttribute("class")||"")}koe.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 xoe(e,t){for(var n=hV(e),i=-1,a=t.length;++i<a;)n.add(t[i])}function boe(e,t){for(var n=hV(e),i=-1,a=t.length;++i<a;)n.remove(t[i])}function Wtt(e){return function(){xoe(this,e)}}function Xtt(e){return function(){boe(this,e)}}function Ytt(e,t){return function(){(t.apply(this,arguments)?xoe:boe)(this,e)}}function Qtt(e,t){var n=goe(e+"");if(arguments.length<2){for(var i=hV(this.node()),a=-1,r=n.length;++a<r;)if(!i.contains(n[a]))return!1;return!0}return this.each((typeof t=="function"?Ytt:t?Wtt:Xtt)(n,t))}function Ztt(){this.textContent=""}function Jtt(e){return function(){this.textContent=e}}function ent(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function tnt(e){return arguments.length?this.each(e==null?Ztt:(typeof e=="function"?ent:Jtt)(e)):this.node().textContent}function nnt(){this.innerHTML=""}function int(e){return function(){this.innerHTML=e}}function ant(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function rnt(e){return arguments.length?this.each(e==null?nnt:(typeof e=="function"?ant:int)(e)):this.node().innerHTML}function ont(){this.nextSibling&&this.parentNode.appendChild(this)}function snt(){return this.each(ont)}function lnt(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function cnt(){return this.each(lnt)}function dnt(e){var t=typeof e=="function"?e:uoe(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function unt(){return null}function hnt(e,t){var n=typeof e=="function"?e:uoe(e),i=t==null?unt:typeof t=="function"?t:uV(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})}function pnt(){var e=this.parentNode;e&&e.removeChild(this)}function fnt(){return this.each(pnt)}function mnt(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function ynt(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function gnt(e){return this.select(e?ynt:mnt)}function knt(e){return arguments.length?this.property("__data__",e):this.node().__data__}function xnt(e){return function(t){e.call(this,t,this.__data__)}}function bnt(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 vnt(e){return function(){var t=this.__on;if(t){for(var n=0,i=-1,a=t.length,r;n<a;++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 wnt(e,t,n){return function(){var i=this.__on,a,r=xnt(t);if(i){for(var s=0,c=i.length;s<c;++s)if((a=i[s]).type===e.type&&a.name===e.name){this.removeEventListener(a.type,a.listener,a.options),this.addEventListener(a.type,a.listener=r,a.options=n),a.value=t;return}}this.addEventListener(e.type,r,n),a={type:e.type,name:e.name,value:t,listener:r,options:n},i?i.push(a):this.__on=[a]}}function Mnt(e,t,n){var i=bnt(e+""),a,r=i.length,s;if(arguments.length<2){var c=this.node().__on;if(c){for(var d=0,h=c.length,m;d<h;++d)for(a=0,m=c[d];a<r;++a)if((s=i[a]).type===m.type&&s.name===m.name)return m.value}return}for(c=t?wnt:vnt,a=0;a<r;++a)this.each(c(i[a],t,n));return this}function voe(e,t,n){var i=yoe(e),a=i.CustomEvent;typeof a=="function"?a=new a(t,n):(a=i.document.createEvent("Event"),n?(a.initEvent(t,n.bubbles,n.cancelable),a.detail=n.detail):a.initEvent(t,!1,!1)),e.dispatchEvent(a)}function _nt(e,t){return function(){return voe(this,e,t)}}function Snt(e,t){return function(){return voe(this,e,t.apply(this,arguments))}}function Nnt(e,t){return this.each((typeof t=="function"?Snt:_nt)(e,t))}function*Ent(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],a=0,r=i.length,s;a<r;++a)(s=i[a])&&(yield s)}var woe=[null];function pa(e,t){this._groups=e,this._parents=t}function G2(){return new pa([[document.documentElement]],woe)}function Cnt(){return this}pa.prototype=G2.prototype={constructor:pa,select:ett,selectAll:att,selectChild:ltt,selectChildren:htt,filter:ptt,data:xtt,enter:ftt,exit:vtt,join:wtt,merge:Mtt,selection:Cnt,order:_tt,sort:Stt,call:Ett,nodes:Ctt,node:Ltt,size:jtt,empty:Att,each:Itt,attr:$tt,style:Ftt,property:Gtt,classed:Qtt,text:tnt,html:rnt,raise:snt,lower:cnt,append:dnt,insert:hnt,remove:fnt,clone:gnt,datum:knt,on:Mnt,dispatch:Nnt,[Symbol.iterator]:Ent};function da(e){return typeof e=="string"?new pa([[document.querySelector(e)]],[document.documentElement]):new pa([[e]],woe)}function Lnt(e){let t;for(;t=e.sourceEvent;)e=t;return e}function tr(e,t){if(e=Lnt(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 a=t.getBoundingClientRect();return[e.clientX-a.left-t.clientLeft,e.clientY-a.top-t.clientTop]}}return[e.pageX,e.pageY]}const jnt={passive:!1},u2={capture:!0,passive:!1};function fq(e){e.stopImmediatePropagation()}function op(e){e.preventDefault(),e.stopImmediatePropagation()}function Moe(e){var t=e.document.documentElement,n=da(e).on("dragstart.drag",op,u2);"onselectstart"in t?n.on("selectstart.drag",op,u2):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function _oe(e,t){var n=e.document.documentElement,i=da(e).on("dragstart.drag",null);t&&(i.on("click.drag",op,u2),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 Ry=e=>()=>e;function cH(e,{sourceEvent:t,subject:n,target:i,identifier:a,active:r,x:s,y:c,dx:d,dy:h,dispatch:m}){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:a,enumerable:!0,configurable:!0},active:{value:r,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:c,enumerable:!0,configurable:!0},dx:{value:d,enumerable:!0,configurable:!0},dy:{value:h,enumerable:!0,configurable:!0},_:{value:m}})}cH.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Ant(e){return!e.ctrlKey&&!e.button}function Int(){return this.parentNode}function Tnt(e,t){return t??{x:e.x,y:e.y}}function Rnt(){return navigator.maxTouchPoints||"ontouchstart"in this}function Soe(){var e=Ant,t=Int,n=Tnt,i=Rnt,a={},r=qO("start","drag","end"),s=0,c,d,h,m,f=0;function k(L){L.on("mousedown.drag",g).filter(i).on("touchstart.drag",w).on("touchmove.drag",S,jnt).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function g(L,j){if(!(m||!e.call(this,L,j))){var A=M(this,t.call(this,L,j),L,j,"mouse");A&&(da(L.view).on("mousemove.drag",b,u2).on("mouseup.drag",v,u2),Moe(L.view),fq(L),h=!1,c=L.clientX,d=L.clientY,A("start",L))}}function b(L){if(op(L),!h){var j=L.clientX-c,A=L.clientY-d;h=j*j+A*A>f}a.mouse("drag",L)}function v(L){da(L.view).on("mousemove.drag mouseup.drag",null),_oe(L.view,h),op(L),a.mouse("end",L)}function w(L,j){if(e.call(this,L,j)){var A=L.changedTouches,I=t.call(this,L,j),T=A.length,P,D;for(P=0;P<T;++P)(D=M(this,I,L,j,A[P].identifier,A[P]))&&(fq(L),D("start",L,A[P]))}}function S(L){var j=L.changedTouches,A=j.length,I,T;for(I=0;I<A;++I)(T=a[j[I].identifier])&&(op(L),T("drag",L,j[I]))}function C(L){var j=L.changedTouches,A=j.length,I,T;for(m&&clearTimeout(m),m=setTimeout(function(){m=null},500),I=0;I<A;++I)(T=a[j[I].identifier])&&(fq(L),T("end",L,j[I]))}function M(L,j,A,I,T,P){var D=r.copy(),q=tr(P||A,j),H,K,R;if((R=n.call(L,new cH("beforestart",{sourceEvent:A,target:k,identifier:T,active:s,x:q[0],y:q[1],dx:0,dy:0,dispatch:D}),I))!=null)return H=R.x-q[0]||0,K=R.y-q[1]||0,function z($,X,Q){var W=q,B;switch($){case"start":a[T]=z,B=s++;break;case"end":delete a[T],--s;case"drag":q=tr(Q||X,j),B=s;break}D.call($,L,new cH($,{sourceEvent:X,subject:R,target:k,identifier:T,active:B,x:q[0]+H,y:q[1]+K,dx:q[0]-W[0],dy:q[1]-W[1],dispatch:D}),I)}}return k.filter=function(L){return arguments.length?(e=typeof L=="function"?L:Ry(!!L),k):e},k.container=function(L){return arguments.length?(t=typeof L=="function"?L:Ry(L),k):t},k.subject=function(L){return arguments.length?(n=typeof L=="function"?L:Ry(L),k):n},k.touchable=function(L){return arguments.length?(i=typeof L=="function"?L:Ry(!!L),k):i},k.on=function(){var L=r.on.apply(r,arguments);return L===r?k:L},k.clickDistance=function(L){return arguments.length?(f=(L=+L)*L,k):Math.sqrt(f)},k}function pV(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Noe(e,t){var n=Object.create(e.prototype);for(var i in t)n[i]=t[i];return n}function W2(){}var h2=.7,XD=1/h2,sp="\\s*([+-]?\\d+)\\s*",p2="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Ur="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Dnt=/^#([0-9a-f]{3,8})$/,Ont=new RegExp(`^rgb\\(${sp},${sp},${sp}\\)$`),znt=new RegExp(`^rgb\\(${Ur},${Ur},${Ur}\\)$`),Pnt=new RegExp(`^rgba\\(${sp},${sp},${sp},${p2}\\)$`),$nt=new RegExp(`^rgba\\(${Ur},${Ur},${Ur},${p2}\\)$`),qnt=new RegExp(`^hsl\\(${p2},${Ur},${Ur}\\)$`),Bnt=new RegExp(`^hsla\\(${p2},${Ur},${Ur},${p2}\\)$`),mZ={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};pV(W2,A1,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:yZ,formatHex:yZ,formatHex8:Hnt,formatHsl:Fnt,formatRgb:gZ,toString:gZ});function yZ(){return this.rgb().formatHex()}function Hnt(){return this.rgb().formatHex8()}function Fnt(){return Eoe(this).formatHsl()}function gZ(){return this.rgb().formatRgb()}function A1(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=Dnt.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?kZ(t):n===3?new Wi(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Dy(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Dy(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=Ont.exec(e))?new Wi(t[1],t[2],t[3],1):(t=znt.exec(e))?new Wi(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Pnt.exec(e))?Dy(t[1],t[2],t[3],t[4]):(t=$nt.exec(e))?Dy(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=qnt.exec(e))?vZ(t[1],t[2]/100,t[3]/100,1):(t=Bnt.exec(e))?vZ(t[1],t[2]/100,t[3]/100,t[4]):mZ.hasOwnProperty(e)?kZ(mZ[e]):e==="transparent"?new Wi(NaN,NaN,NaN,0):null}function kZ(e){return new Wi(e>>16&255,e>>8&255,e&255,1)}function Dy(e,t,n,i){return i<=0&&(e=t=n=NaN),new Wi(e,t,n,i)}function Vnt(e){return e instanceof W2||(e=A1(e)),e?(e=e.rgb(),new Wi(e.r,e.g,e.b,e.opacity)):new Wi}function dH(e,t,n,i){return arguments.length===1?Vnt(e):new Wi(e,t,n,i??1)}function Wi(e,t,n,i){this.r=+e,this.g=+t,this.b=+n,this.opacity=+i}pV(Wi,dH,Noe(W2,{brighter(e){return e=e==null?XD:Math.pow(XD,e),new Wi(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?h2:Math.pow(h2,e),new Wi(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Wi(S1(this.r),S1(this.g),S1(this.b),YD(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:xZ,formatHex:xZ,formatHex8:Unt,formatRgb:bZ,toString:bZ}));function xZ(){return`#${i1(this.r)}${i1(this.g)}${i1(this.b)}`}function Unt(){return`#${i1(this.r)}${i1(this.g)}${i1(this.b)}${i1((isNaN(this.opacity)?1:this.opacity)*255)}`}function bZ(){const e=YD(this.opacity);return`${e===1?"rgb(":"rgba("}${S1(this.r)}, ${S1(this.g)}, ${S1(this.b)}${e===1?")":`, ${e})`}`}function YD(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function S1(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function i1(e){return e=S1(e),(e<16?"0":"")+e.toString(16)}function vZ(e,t,n,i){return i<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new ir(e,t,n,i)}function Eoe(e){if(e instanceof ir)return new ir(e.h,e.s,e.l,e.opacity);if(e instanceof W2||(e=A1(e)),!e)return new ir;if(e instanceof ir)return e;e=e.rgb();var t=e.r/255,n=e.g/255,i=e.b/255,a=Math.min(t,n,i),r=Math.max(t,n,i),s=NaN,c=r-a,d=(r+a)/2;return c?(t===r?s=(n-i)/c+(n<i)*6:n===r?s=(i-t)/c+2:s=(t-n)/c+4,c/=d<.5?r+a:2-r-a,s*=60):c=d>0&&d<1?0:s,new ir(s,c,d,e.opacity)}function Knt(e,t,n,i){return arguments.length===1?Eoe(e):new ir(e,t,n,i??1)}function ir(e,t,n,i){this.h=+e,this.s=+t,this.l=+n,this.opacity=+i}pV(ir,Knt,Noe(W2,{brighter(e){return e=e==null?XD:Math.pow(XD,e),new ir(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?h2:Math.pow(h2,e),new ir(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,a=2*n-i;return new Wi(mq(e>=240?e-240:e+120,a,i),mq(e,a,i),mq(e<120?e+240:e-120,a,i),this.opacity)},clamp(){return new ir(wZ(this.h),Oy(this.s),Oy(this.l),YD(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=YD(this.opacity);return`${e===1?"hsl(":"hsla("}${wZ(this.h)}, ${Oy(this.s)*100}%, ${Oy(this.l)*100}%${e===1?")":`, ${e})`}`}}));function wZ(e){return e=(e||0)%360,e<0?e+360:e}function Oy(e){return Math.max(0,Math.min(1,e||0))}function mq(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 fV=e=>()=>e;function Gnt(e,t){return function(n){return e+n*t}}function Wnt(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 Xnt(e){return(e=+e)==1?Coe:function(t,n){return n-t?Wnt(t,n,e):fV(isNaN(t)?n:t)}}function Coe(e,t){var n=t-e;return n?Gnt(e,n):fV(isNaN(e)?t:e)}const QD=(function e(t){var n=Xnt(t);function i(a,r){var s=n((a=dH(a)).r,(r=dH(r)).r),c=n(a.g,r.g),d=n(a.b,r.b),h=Coe(a.opacity,r.opacity);return function(m){return a.r=s(m),a.g=c(m),a.b=d(m),a.opacity=h(m),a+""}}return i.gamma=e,i})(1);function Ynt(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,i=t.slice(),a;return function(r){for(a=0;a<n;++a)i[a]=e[a]*(1-r)+t[a]*r;return i}}function Qnt(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Znt(e,t){var n=t?t.length:0,i=e?Math.min(n,e.length):0,a=new Array(i),r=new Array(n),s;for(s=0;s<i;++s)a[s]=W0(e[s],t[s]);for(;s<n;++s)r[s]=t[s];return function(c){for(s=0;s<i;++s)r[s]=a[s](c);return r}}function Jnt(e,t){var n=new Date;return e=+e,t=+t,function(i){return n.setTime(e*(1-i)+t*i),n}}function Br(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function eit(e,t){var n={},i={},a;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(a in t)a in e?n[a]=W0(e[a],t[a]):i[a]=t[a];return function(r){for(a in n)i[a]=n[a](r);return i}}var uH=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,yq=new RegExp(uH.source,"g");function tit(e){return function(){return e}}function nit(e){return function(t){return e(t)+""}}function Loe(e,t){var n=uH.lastIndex=yq.lastIndex=0,i,a,r,s=-1,c=[],d=[];for(e=e+"",t=t+"";(i=uH.exec(e))&&(a=yq.exec(t));)(r=a.index)>n&&(r=t.slice(n,r),c[s]?c[s]+=r:c[++s]=r),(i=i[0])===(a=a[0])?c[s]?c[s]+=a:c[++s]=a:(c[++s]=null,d.push({i:s,x:Br(i,a)})),n=yq.lastIndex;return n<t.length&&(r=t.slice(n),c[s]?c[s]+=r:c[++s]=r),c.length<2?d[0]?nit(d[0].x):tit(t):(t=d.length,function(h){for(var m=0,f;m<t;++m)c[(f=d[m]).i]=f.x(h);return c.join("")})}function W0(e,t){var n=typeof t,i;return t==null||n==="boolean"?fV(t):(n==="number"?Br:n==="string"?(i=A1(t))?(t=i,QD):Loe:t instanceof A1?QD:t instanceof Date?Jnt:Qnt(t)?Ynt:Array.isArray(t)?Znt:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?eit:Br)(e,t)}var MZ=180/Math.PI,hH={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function joe(e,t,n,i,a,r){var s,c,d;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(d=e*n+t*i)&&(n-=e*d,i-=t*d),(c=Math.sqrt(n*n+i*i))&&(n/=c,i/=c,d/=c),e*i<t*n&&(e=-e,t=-t,d=-d,s=-s),{translateX:a,translateY:r,rotate:Math.atan2(t,e)*MZ,skewX:Math.atan(d)*MZ,scaleX:s,scaleY:c}}var zy;function iit(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?hH:joe(t.a,t.b,t.c,t.d,t.e,t.f)}function ait(e){return e==null||(zy||(zy=document.createElementNS("http://www.w3.org/2000/svg","g")),zy.setAttribute("transform",e),!(e=zy.transform.baseVal.consolidate()))?hH:(e=e.matrix,joe(e.a,e.b,e.c,e.d,e.e,e.f))}function Aoe(e,t,n,i){function a(h){return h.length?h.pop()+" ":""}function r(h,m,f,k,g,b){if(h!==f||m!==k){var v=g.push("translate(",null,t,null,n);b.push({i:v-4,x:Br(h,f)},{i:v-2,x:Br(m,k)})}else(f||k)&&g.push("translate("+f+t+k+n)}function s(h,m,f,k){h!==m?(h-m>180?m+=360:m-h>180&&(h+=360),k.push({i:f.push(a(f)+"rotate(",null,i)-2,x:Br(h,m)})):m&&f.push(a(f)+"rotate("+m+i)}function c(h,m,f,k){h!==m?k.push({i:f.push(a(f)+"skewX(",null,i)-2,x:Br(h,m)}):m&&f.push(a(f)+"skewX("+m+i)}function d(h,m,f,k,g,b){if(h!==f||m!==k){var v=g.push(a(g)+"scale(",null,",",null,")");b.push({i:v-4,x:Br(h,f)},{i:v-2,x:Br(m,k)})}else(f!==1||k!==1)&&g.push(a(g)+"scale("+f+","+k+")")}return function(h,m){var f=[],k=[];return h=e(h),m=e(m),r(h.translateX,h.translateY,m.translateX,m.translateY,f,k),s(h.rotate,m.rotate,f,k),c(h.skewX,m.skewX,f,k),d(h.scaleX,h.scaleY,m.scaleX,m.scaleY,f,k),h=m=null,function(g){for(var b=-1,v=k.length,w;++b<v;)f[(w=k[b]).i]=w.x(g);return f.join("")}}}var rit=Aoe(iit,"px, ","px)","deg)"),oit=Aoe(ait,", ",")",")"),sit=1e-12;function _Z(e){return((e=Math.exp(e))+1/e)/2}function lit(e){return((e=Math.exp(e))-1/e)/2}function cit(e){return((e=Math.exp(2*e))-1)/(e+1)}const hD=(function e(t,n,i){function a(r,s){var c=r[0],d=r[1],h=r[2],m=s[0],f=s[1],k=s[2],g=m-c,b=f-d,v=g*g+b*b,w,S;if(v<sit)S=Math.log(k/h)/t,w=function(I){return[c+I*g,d+I*b,h*Math.exp(t*I*S)]};else{var C=Math.sqrt(v),M=(k*k-h*h+i*v)/(2*h*n*C),L=(k*k-h*h-i*v)/(2*k*n*C),j=Math.log(Math.sqrt(M*M+1)-M),A=Math.log(Math.sqrt(L*L+1)-L);S=(A-j)/t,w=function(I){var T=I*S,P=_Z(j),D=h/(n*C)*(P*cit(t*T+j)-lit(j));return[c+D*g,d+D*b,h*P/_Z(t*T+j)]}}return w.duration=S*1e3*t/Math.SQRT2,w}return a.rho=function(r){var s=Math.max(.001,+r),c=s*s,d=c*c;return e(s,c,d)},a})(Math.SQRT2,2,4);var Ip=0,n0=0,Xf=0,Ioe=1e3,ZD,i0,JD=0,I1=0,HO=0,f2=typeof performance=="object"&&performance.now?performance:Date,Toe=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function mV(){return I1||(Toe(dit),I1=f2.now()+HO)}function dit(){I1=0}function eO(){this._call=this._time=this._next=null}eO.prototype=Roe.prototype={constructor:eO,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?mV():+n)+(t==null?0:+t),!this._next&&i0!==this&&(i0?i0._next=this:ZD=this,i0=this),this._call=e,this._time=n,pH()},stop:function(){this._call&&(this._call=null,this._time=1/0,pH())}};function Roe(e,t,n){var i=new eO;return i.restart(e,t,n),i}function uit(){mV(),++Ip;for(var e=ZD,t;e;)(t=I1-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Ip}function SZ(){I1=(JD=f2.now())+HO,Ip=n0=0;try{uit()}finally{Ip=0,pit(),I1=0}}function hit(){var e=f2.now(),t=e-JD;t>Ioe&&(HO-=t,JD=e)}function pit(){for(var e,t=ZD,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:ZD=n);i0=e,pH(i)}function pH(e){if(!Ip){n0&&(n0=clearTimeout(n0));var t=e-I1;t>24?(e<1/0&&(n0=setTimeout(SZ,e-f2.now()-HO)),Xf&&(Xf=clearInterval(Xf))):(Xf||(JD=f2.now(),Xf=setInterval(hit,Ioe)),Ip=1,Toe(SZ))}}function NZ(e,t,n){var i=new eO;return t=t==null?0:+t,i.restart(a=>{i.stop(),e(a+t)},t,n),i}var fit=qO("start","end","cancel","interrupt"),mit=[],Doe=0,EZ=1,fH=2,pD=3,CZ=4,mH=5,fD=6;function FO(e,t,n,i,a,r){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;yit(e,n,{name:t,index:i,group:a,on:fit,tween:mit,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:Doe})}function yV(e,t){var n=yr(e,t);if(n.state>Doe)throw new Error("too late; already scheduled");return n}function Yr(e,t){var n=yr(e,t);if(n.state>pD)throw new Error("too late; already running");return n}function yr(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function yit(e,t,n){var i=e.__transition,a;i[t]=n,n.timer=Roe(r,0,n.time);function r(h){n.state=EZ,n.timer.restart(s,n.delay,n.time),n.delay<=h&&s(h-n.delay)}function s(h){var m,f,k,g;if(n.state!==EZ)return d();for(m in i)if(g=i[m],g.name===n.name){if(g.state===pD)return NZ(s);g.state===CZ?(g.state=fD,g.timer.stop(),g.on.call("interrupt",e,e.__data__,g.index,g.group),delete i[m]):+m<t&&(g.state=fD,g.timer.stop(),g.on.call("cancel",e,e.__data__,g.index,g.group),delete i[m])}if(NZ(function(){n.state===pD&&(n.state=CZ,n.timer.restart(c,n.delay,n.time),c(h))}),n.state=fH,n.on.call("start",e,e.__data__,n.index,n.group),n.state===fH){for(n.state=pD,a=new Array(k=n.tween.length),m=0,f=-1;m<k;++m)(g=n.tween[m].value.call(e,e.__data__,n.index,n.group))&&(a[++f]=g);a.length=f+1}}function c(h){for(var m=h<n.duration?n.ease.call(null,h/n.duration):(n.timer.restart(d),n.state=mH,1),f=-1,k=a.length;++f<k;)a[f].call(e,m);n.state===mH&&(n.on.call("end",e,e.__data__,n.index,n.group),d())}function d(){n.state=fD,n.timer.stop(),delete i[t];for(var h in i)return;delete e.__transition}}function mD(e,t){var n=e.__transition,i,a,r=!0,s;if(n){t=t==null?null:t+"";for(s in n){if((i=n[s]).name!==t){r=!1;continue}a=i.state>fH&&i.state<mH,i.state=fD,i.timer.stop(),i.on.call(a?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete n[s]}r&&delete e.__transition}}function git(e){return this.each(function(){mD(this,e)})}function kit(e,t){var n,i;return function(){var a=Yr(this,e),r=a.tween;if(r!==n){i=n=r;for(var s=0,c=i.length;s<c;++s)if(i[s].name===t){i=i.slice(),i.splice(s,1);break}}a.tween=i}}function xit(e,t,n){var i,a;if(typeof n!="function")throw new Error;return function(){var r=Yr(this,e),s=r.tween;if(s!==i){a=(i=s).slice();for(var c={name:t,value:n},d=0,h=a.length;d<h;++d)if(a[d].name===t){a[d]=c;break}d===h&&a.push(c)}r.tween=a}}function bit(e,t){var n=this._id;if(e+="",arguments.length<2){for(var i=yr(this.node(),n).tween,a=0,r=i.length,s;a<r;++a)if((s=i[a]).name===e)return s.value;return null}return this.each((t==null?kit:xit)(n,e,t))}function gV(e,t,n){var i=e._id;return e.each(function(){var a=Yr(this,i);(a.value||(a.value={}))[t]=n.apply(this,arguments)}),function(a){return yr(a,i).value[t]}}function Ooe(e,t){var n;return(typeof t=="number"?Br:t instanceof A1?QD:(n=A1(t))?(t=n,QD):Loe)(e,t)}function vit(e){return function(){this.removeAttribute(e)}}function wit(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Mit(e,t,n){var i,a=n+"",r;return function(){var s=this.getAttribute(e);return s===a?null:s===i?r:r=t(i=s,n)}}function _it(e,t,n){var i,a=n+"",r;return function(){var s=this.getAttributeNS(e.space,e.local);return s===a?null:s===i?r:r=t(i=s,n)}}function Sit(e,t,n){var i,a,r;return function(){var s,c=n(this),d;return c==null?void this.removeAttribute(e):(s=this.getAttribute(e),d=c+"",s===d?null:s===i&&d===a?r:(a=d,r=t(i=s,c)))}}function Nit(e,t,n){var i,a,r;return function(){var s,c=n(this),d;return c==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),d=c+"",s===d?null:s===i&&d===a?r:(a=d,r=t(i=s,c)))}}function Eit(e,t){var n=BO(e),i=n==="transform"?oit:Ooe;return this.attrTween(e,typeof t=="function"?(n.local?Nit:Sit)(n,i,gV(this,"attr."+e,t)):t==null?(n.local?wit:vit)(n):(n.local?_it:Mit)(n,i,t))}function Cit(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Lit(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function jit(e,t){var n,i;function a(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&Lit(e,r)),n}return a._value=t,a}function Ait(e,t){var n,i;function a(){var r=t.apply(this,arguments);return r!==i&&(n=(i=r)&&Cit(e,r)),n}return a._value=t,a}function Iit(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=BO(e);return this.tween(n,(i.local?jit:Ait)(i,t))}function Tit(e,t){return function(){yV(this,e).delay=+t.apply(this,arguments)}}function Rit(e,t){return t=+t,function(){yV(this,e).delay=t}}function Dit(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Tit:Rit)(t,e)):yr(this.node(),t).delay}function Oit(e,t){return function(){Yr(this,e).duration=+t.apply(this,arguments)}}function zit(e,t){return t=+t,function(){Yr(this,e).duration=t}}function Pit(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Oit:zit)(t,e)):yr(this.node(),t).duration}function $it(e,t){if(typeof t!="function")throw new Error;return function(){Yr(this,e).ease=t}}function qit(e){var t=this._id;return arguments.length?this.each($it(t,e)):yr(this.node(),t).ease}function Bit(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Yr(this,e).ease=n}}function Hit(e){if(typeof e!="function")throw new Error;return this.each(Bit(this._id,e))}function Fit(e){typeof e!="function"&&(e=poe(e));for(var t=this._groups,n=t.length,i=new Array(n),a=0;a<n;++a)for(var r=t[a],s=r.length,c=i[a]=[],d,h=0;h<s;++h)(d=r[h])&&e.call(d,d.__data__,h,r)&&c.push(d);return new Po(i,this._parents,this._name,this._id)}function Vit(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,i=t.length,a=n.length,r=Math.min(i,a),s=new Array(i),c=0;c<r;++c)for(var d=t[c],h=n[c],m=d.length,f=s[c]=new Array(m),k,g=0;g<m;++g)(k=d[g]||h[g])&&(f[g]=k);for(;c<i;++c)s[c]=t[c];return new Po(s,this._parents,this._name,this._id)}function Uit(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 Kit(e,t,n){var i,a,r=Uit(t)?yV:Yr;return function(){var s=r(this,e),c=s.on;c!==i&&(a=(i=c).copy()).on(t,n),s.on=a}}function Git(e,t){var n=this._id;return arguments.length<2?yr(this.node(),n).on.on(e):this.each(Kit(n,e,t))}function Wit(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Xit(){return this.on("end.remove",Wit(this._id))}function Yit(e){var t=this._name,n=this._id;typeof e!="function"&&(e=uV(e));for(var i=this._groups,a=i.length,r=new Array(a),s=0;s<a;++s)for(var c=i[s],d=c.length,h=r[s]=new Array(d),m,f,k=0;k<d;++k)(m=c[k])&&(f=e.call(m,m.__data__,k,c))&&("__data__"in m&&(f.__data__=m.__data__),h[k]=f,FO(h[k],t,n,k,h,yr(m,n)));return new Po(r,this._parents,t,n)}function Qit(e){var t=this._name,n=this._id;typeof e!="function"&&(e=hoe(e));for(var i=this._groups,a=i.length,r=[],s=[],c=0;c<a;++c)for(var d=i[c],h=d.length,m,f=0;f<h;++f)if(m=d[f]){for(var k=e.call(m,m.__data__,f,d),g,b=yr(m,n),v=0,w=k.length;v<w;++v)(g=k[v])&&FO(g,t,n,v,k,b);r.push(k),s.push(m)}return new Po(r,s,t,n)}var Zit=G2.prototype.constructor;function Jit(){return new Zit(this._groups,this._parents)}function eat(e,t){var n,i,a;return function(){var r=Ap(this,e),s=(this.style.removeProperty(e),Ap(this,e));return r===s?null:r===n&&s===i?a:a=t(n=r,i=s)}}function zoe(e){return function(){this.style.removeProperty(e)}}function tat(e,t,n){var i,a=n+"",r;return function(){var s=Ap(this,e);return s===a?null:s===i?r:r=t(i=s,n)}}function nat(e,t,n){var i,a,r;return function(){var s=Ap(this,e),c=n(this),d=c+"";return c==null&&(d=c=(this.style.removeProperty(e),Ap(this,e))),s===d?null:s===i&&d===a?r:(a=d,r=t(i=s,c))}}function iat(e,t){var n,i,a,r="style."+t,s="end."+r,c;return function(){var d=Yr(this,e),h=d.on,m=d.value[r]==null?c||(c=zoe(t)):void 0;(h!==n||a!==m)&&(i=(n=h).copy()).on(s,a=m),d.on=i}}function aat(e,t,n){var i=(e+="")=="transform"?rit:Ooe;return t==null?this.styleTween(e,eat(e,i)).on("end.style."+e,zoe(e)):typeof t=="function"?this.styleTween(e,nat(e,i,gV(this,"style."+e,t))).each(iat(this._id,e)):this.styleTween(e,tat(e,i,t),n).on("end.style."+e,null)}function rat(e,t,n){return function(i){this.style.setProperty(e,t.call(this,i),n)}}function oat(e,t,n){var i,a;function r(){var s=t.apply(this,arguments);return s!==a&&(i=(a=s)&&rat(e,s,n)),i}return r._value=t,r}function sat(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,oat(e,t,n??""))}function lat(e){return function(){this.textContent=e}}function cat(e){return function(){var t=e(this);this.textContent=t??""}}function dat(e){return this.tween("text",typeof e=="function"?cat(gV(this,"text",e)):lat(e==null?"":e+""))}function uat(e){return function(t){this.textContent=e.call(this,t)}}function hat(e){var t,n;function i(){var a=e.apply(this,arguments);return a!==n&&(t=(n=a)&&uat(a)),t}return i._value=e,i}function pat(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,hat(e))}function fat(){for(var e=this._name,t=this._id,n=Poe(),i=this._groups,a=i.length,r=0;r<a;++r)for(var s=i[r],c=s.length,d,h=0;h<c;++h)if(d=s[h]){var m=yr(d,t);FO(d,e,n,h,s,{time:m.time+m.delay+m.duration,delay:0,duration:m.duration,ease:m.ease})}return new Po(i,this._parents,e,n)}function mat(){var e,t,n=this,i=n._id,a=n.size();return new Promise(function(r,s){var c={value:s},d={value:function(){--a===0&&r()}};n.each(function(){var h=Yr(this,i),m=h.on;m!==e&&(t=(e=m).copy(),t._.cancel.push(c),t._.interrupt.push(c),t._.end.push(d)),h.on=t}),a===0&&r()})}var yat=0;function Po(e,t,n,i){this._groups=e,this._parents=t,this._name=n,this._id=i}function Poe(){return++yat}var xo=G2.prototype;Po.prototype={constructor:Po,select:Yit,selectAll:Qit,selectChild:xo.selectChild,selectChildren:xo.selectChildren,filter:Fit,merge:Vit,selection:Jit,transition:fat,call:xo.call,nodes:xo.nodes,node:xo.node,size:xo.size,empty:xo.empty,each:xo.each,on:Git,attr:Eit,attrTween:Iit,style:aat,styleTween:sat,text:dat,textTween:pat,remove:Xit,tween:bit,delay:Dit,duration:Pit,ease:qit,easeVarying:Hit,end:mat,[Symbol.iterator]:xo[Symbol.iterator]};function gat(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var kat={time:null,delay:0,duration:250,ease:gat};function xat(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 bat(e){var t,n;e instanceof Po?(t=e._id,e=e._name):(t=Poe(),(n=kat).time=mV(),e=e==null?null:e+"");for(var i=this._groups,a=i.length,r=0;r<a;++r)for(var s=i[r],c=s.length,d,h=0;h<c;++h)(d=s[h])&&FO(d,e,t,h,s,n||xat(d,t));return new Po(i,this._parents,e,t)}G2.prototype.interrupt=git;G2.prototype.transition=bat;const Py=e=>()=>e;function vat(e,{sourceEvent:t,target:n,transform:i,dispatch:a}){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:a}})}function Ao(e,t,n){this.k=e,this.x=t,this.y=n}Ao.prototype={constructor:Ao,scale:function(e){return e===1?this:new Ao(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Ao(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 VO=new Ao(1,0,0);$oe.prototype=Ao.prototype;function $oe(e){for(;!e.__zoom;)if(!(e=e.parentNode))return VO;return e.__zoom}function gq(e){e.stopImmediatePropagation()}function Yf(e){e.preventDefault(),e.stopImmediatePropagation()}function wat(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Mat(){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 LZ(){return this.__zoom||VO}function _at(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Sat(){return navigator.maxTouchPoints||"ontouchstart"in this}function Nat(e,t,n){var i=e.invertX(t[0][0])-n[0][0],a=e.invertX(t[1][0])-n[1][0],r=e.invertY(t[0][1])-n[0][1],s=e.invertY(t[1][1])-n[1][1];return e.translate(a>i?(i+a)/2:Math.min(0,i)||Math.max(0,a),s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s))}function qoe(){var e=wat,t=Mat,n=Nat,i=_at,a=Sat,r=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],c=250,d=hD,h=qO("start","zoom","end"),m,f,k,g=500,b=150,v=0,w=10;function S(R){R.property("__zoom",LZ).on("wheel.zoom",T,{passive:!1}).on("mousedown.zoom",P).on("dblclick.zoom",D).filter(a).on("touchstart.zoom",q).on("touchmove.zoom",H).on("touchend.zoom touchcancel.zoom",K).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}S.transform=function(R,z,$,X){var Q=R.selection?R.selection():R;Q.property("__zoom",LZ),R!==Q?j(R,z,$,X):Q.interrupt().each(function(){A(this,arguments).event(X).start().zoom(null,typeof z=="function"?z.apply(this,arguments):z).end()})},S.scaleBy=function(R,z,$,X){S.scaleTo(R,function(){var Q=this.__zoom.k,W=typeof z=="function"?z.apply(this,arguments):z;return Q*W},$,X)},S.scaleTo=function(R,z,$,X){S.transform(R,function(){var Q=t.apply(this,arguments),W=this.__zoom,B=$==null?L(Q):typeof $=="function"?$.apply(this,arguments):$,V=W.invert(B),Y=typeof z=="function"?z.apply(this,arguments):z;return n(M(C(W,Y),B,V),Q,s)},$,X)},S.translateBy=function(R,z,$,X){S.transform(R,function(){return n(this.__zoom.translate(typeof z=="function"?z.apply(this,arguments):z,typeof $=="function"?$.apply(this,arguments):$),t.apply(this,arguments),s)},null,X)},S.translateTo=function(R,z,$,X,Q){S.transform(R,function(){var W=t.apply(this,arguments),B=this.__zoom,V=X==null?L(W):typeof X=="function"?X.apply(this,arguments):X;return n(VO.translate(V[0],V[1]).scale(B.k).translate(typeof z=="function"?-z.apply(this,arguments):-z,typeof $=="function"?-$.apply(this,arguments):-$),W,s)},X,Q)};function C(R,z){return z=Math.max(r[0],Math.min(r[1],z)),z===R.k?R:new Ao(z,R.x,R.y)}function M(R,z,$){var X=z[0]-$[0]*R.k,Q=z[1]-$[1]*R.k;return X===R.x&&Q===R.y?R:new Ao(R.k,X,Q)}function L(R){return[(+R[0][0]+ +R[1][0])/2,(+R[0][1]+ +R[1][1])/2]}function j(R,z,$,X){R.on("start.zoom",function(){A(this,arguments).event(X).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(X).end()}).tween("zoom",function(){var Q=this,W=arguments,B=A(Q,W).event(X),V=t.apply(Q,W),Y=$==null?L(V):typeof $=="function"?$.apply(Q,W):$,F=Math.max(V[1][0]-V[0][0],V[1][1]-V[0][1]),ae=Q.__zoom,xe=typeof z=="function"?z.apply(Q,W):z,de=d(ae.invert(Y).concat(F/ae.k),xe.invert(Y).concat(F/xe.k));return function(Ee){if(Ee===1)Ee=xe;else{var ce=de(Ee),me=F/ce[2];Ee=new Ao(me,Y[0]-ce[0]*me,Y[1]-ce[1]*me)}B.zoom(null,Ee)}})}function A(R,z,$){return!$&&R.__zooming||new I(R,z)}function I(R,z){this.that=R,this.args=z,this.active=0,this.sourceEvent=null,this.extent=t.apply(R,z),this.taps=0}I.prototype={event:function(R){return R&&(this.sourceEvent=R),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(R,z){return this.mouse&&R!=="mouse"&&(this.mouse[1]=z.invert(this.mouse[0])),this.touch0&&R!=="touch"&&(this.touch0[1]=z.invert(this.touch0[0])),this.touch1&&R!=="touch"&&(this.touch1[1]=z.invert(this.touch1[0])),this.that.__zoom=z,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(R){var z=da(this.that).datum();h.call(R,this.that,new vat(R,{sourceEvent:this.sourceEvent,target:S,transform:this.that.__zoom,dispatch:h}),z)}};function T(R,...z){if(!e.apply(this,arguments))return;var $=A(this,z).event(R),X=this.__zoom,Q=Math.max(r[0],Math.min(r[1],X.k*Math.pow(2,i.apply(this,arguments)))),W=tr(R);if($.wheel)($.mouse[0][0]!==W[0]||$.mouse[0][1]!==W[1])&&($.mouse[1]=X.invert($.mouse[0]=W)),clearTimeout($.wheel);else{if(X.k===Q)return;$.mouse=[W,X.invert(W)],mD(this),$.start()}Yf(R),$.wheel=setTimeout(B,b),$.zoom("mouse",n(M(C(X,Q),$.mouse[0],$.mouse[1]),$.extent,s));function B(){$.wheel=null,$.end()}}function P(R,...z){if(k||!e.apply(this,arguments))return;var $=R.currentTarget,X=A(this,z,!0).event(R),Q=da(R.view).on("mousemove.zoom",Y,!0).on("mouseup.zoom",F,!0),W=tr(R,$),B=R.clientX,V=R.clientY;Moe(R.view),gq(R),X.mouse=[W,this.__zoom.invert(W)],mD(this),X.start();function Y(ae){if(Yf(ae),!X.moved){var xe=ae.clientX-B,de=ae.clientY-V;X.moved=xe*xe+de*de>v}X.event(ae).zoom("mouse",n(M(X.that.__zoom,X.mouse[0]=tr(ae,$),X.mouse[1]),X.extent,s))}function F(ae){Q.on("mousemove.zoom mouseup.zoom",null),_oe(ae.view,X.moved),Yf(ae),X.event(ae).end()}}function D(R,...z){if(e.apply(this,arguments)){var $=this.__zoom,X=tr(R.changedTouches?R.changedTouches[0]:R,this),Q=$.invert(X),W=$.k*(R.shiftKey?.5:2),B=n(M(C($,W),X,Q),t.apply(this,z),s);Yf(R),c>0?da(this).transition().duration(c).call(j,B,X,R):da(this).call(S.transform,B,X,R)}}function q(R,...z){if(e.apply(this,arguments)){var $=R.touches,X=$.length,Q=A(this,z,R.changedTouches.length===X).event(R),W,B,V,Y;for(gq(R),B=0;B<X;++B)V=$[B],Y=tr(V,this),Y=[Y,this.__zoom.invert(Y),V.identifier],Q.touch0?!Q.touch1&&Q.touch0[2]!==Y[2]&&(Q.touch1=Y,Q.taps=0):(Q.touch0=Y,W=!0,Q.taps=1+!!m);m&&(m=clearTimeout(m)),W&&(Q.taps<2&&(f=Y[0],m=setTimeout(function(){m=null},g)),mD(this),Q.start())}}function H(R,...z){if(this.__zooming){var $=A(this,z).event(R),X=R.changedTouches,Q=X.length,W,B,V,Y;for(Yf(R),W=0;W<Q;++W)B=X[W],V=tr(B,this),$.touch0&&$.touch0[2]===B.identifier?$.touch0[0]=V:$.touch1&&$.touch1[2]===B.identifier&&($.touch1[0]=V);if(B=$.that.__zoom,$.touch1){var F=$.touch0[0],ae=$.touch0[1],xe=$.touch1[0],de=$.touch1[1],Ee=(Ee=xe[0]-F[0])*Ee+(Ee=xe[1]-F[1])*Ee,ce=(ce=de[0]-ae[0])*ce+(ce=de[1]-ae[1])*ce;B=C(B,Math.sqrt(Ee/ce)),V=[(F[0]+xe[0])/2,(F[1]+xe[1])/2],Y=[(ae[0]+de[0])/2,(ae[1]+de[1])/2]}else if($.touch0)V=$.touch0[0],Y=$.touch0[1];else return;$.zoom("touch",n(M(B,V,Y),$.extent,s))}}function K(R,...z){if(this.__zooming){var $=A(this,z).event(R),X=R.changedTouches,Q=X.length,W,B;for(gq(R),k&&clearTimeout(k),k=setTimeout(function(){k=null},g),W=0;W<Q;++W)B=X[W],$.touch0&&$.touch0[2]===B.identifier?delete $.touch0:$.touch1&&$.touch1[2]===B.identifier&&delete $.touch1;if($.touch1&&!$.touch0&&($.touch0=$.touch1,delete $.touch1),$.touch0)$.touch0[1]=this.__zoom.invert($.touch0[0]);else if($.end(),$.taps===2&&(B=tr(B,this),Math.hypot(f[0]-B[0],f[1]-B[1])<w)){var V=da(this).on("dblclick.zoom");V&&V.apply(this,arguments)}}}return S.wheelDelta=function(R){return arguments.length?(i=typeof R=="function"?R:Py(+R),S):i},S.filter=function(R){return arguments.length?(e=typeof R=="function"?R:Py(!!R),S):e},S.touchable=function(R){return arguments.length?(a=typeof R=="function"?R:Py(!!R),S):a},S.extent=function(R){return arguments.length?(t=typeof R=="function"?R:Py([[+R[0][0],+R[0][1]],[+R[1][0],+R[1][1]]]),S):t},S.scaleExtent=function(R){return arguments.length?(r[0]=+R[0],r[1]=+R[1],S):[r[0],r[1]]},S.translateExtent=function(R){return arguments.length?(s[0][0]=+R[0][0],s[1][0]=+R[1][0],s[0][1]=+R[0][1],s[1][1]=+R[1][1],S):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},S.constrain=function(R){return arguments.length?(n=R,S):n},S.duration=function(R){return arguments.length?(c=+R,S):c},S.interpolate=function(R){return arguments.length?(d=R,S):d},S.on=function(){var R=h.on.apply(h,arguments);return R===h?S:R},S.clickDistance=function(R){return arguments.length?(v=(R=+R)*R,S):Math.sqrt(v)},S.tapDistance=function(R){return arguments.length?(w=+R,S):w},S}const fa={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.`},m2=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Boe=["Enter"," ","Escape"],Hoe={"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 Tp;(function(e){e.Strict="strict",e.Loose="loose"})(Tp||(Tp={}));var N1;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(N1||(N1={}));var y2;(function(e){e.Partial="partial",e.Full="full"})(y2||(y2={}));const Foe={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var vs;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(vs||(vs={}));var tO;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(tO||(tO={}));var tt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(tt||(tt={}));const jZ={[tt.Left]:tt.Right,[tt.Right]:tt.Left,[tt.Top]:tt.Bottom,[tt.Bottom]:tt.Top};function Voe(e){return e===null?null:e?"valid":"invalid"}const Uoe=e=>"id"in e&&"source"in e&&"target"in e,Eat=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),kV=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),X2=(e,t=[0,0])=>{const{width:n,height:i}=qo(e),a=e.origin??t,r=n*a[0],s=i*a[1];return{x:e.position.x-r,y:e.position.y-s}},Cat=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((i,a)=>{const r=typeof a=="string";let s=!t.nodeLookup&&!r?a:void 0;t.nodeLookup&&(s=r?t.nodeLookup.get(a):kV(a)?a:t.nodeLookup.get(a.id));const c=s?nO(s,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return UO(i,c)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return KO(n)},Y2=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},i=!1;return e.forEach(a=>{(t.filter===void 0||t.filter(a))&&(n=UO(n,nO(a)),i=!0)}),i?KO(n):{x:0,y:0,width:0,height:0}},xV=(e,t,[n,i,a]=[0,0,1],r=!1,s=!1)=>{const c=(t.x-n)/a,d=(t.y-i)/a,h=t.width/a,m=t.height/a,f=[];for(const k of e.values()){const{measured:g,selectable:b=!0,hidden:v=!1}=k;if(s&&!b||v)continue;const w=g.width??k.width??k.initialWidth??0,S=g.height??k.height??k.initialHeight??0,{x:C,y:M}=k.internals.positionAbsolute,L=Xoe(c,d,h,m,C,M,w,S),j=w*S,A=r&&L>0;(!k.internals.handleBounds||A||L>=j||k.dragging)&&f.push(k)}return f},Lat=(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 jat(e,t){const n=new Map,i=t!=null&&t.nodes?new Set(t.nodes.map(a=>a.id)):null;return e.forEach(a=>{a.measured.width&&a.measured.height&&((t==null?void 0:t.includeHiddenNodes)||!a.hidden)&&(!i||i.has(a.id))&&n.set(a.id,a)}),n}async function Aat({nodes:e,width:t,height:n,panZoom:i,minZoom:a,maxZoom:r},s){if(e.size===0)return!0;const c=jat(e,s),d=Y2(c),h=vV(d,t,n,(s==null?void 0:s.minZoom)??a,(s==null?void 0:s.maxZoom)??r,(s==null?void 0:s.padding)??.1);return await i.setViewport(h,{duration:s==null?void 0:s.duration,ease:s==null?void 0:s.ease,interpolate:s==null?void 0:s.interpolate}),!0}function Koe({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:i=[0,0],nodeExtent:a,onError:r}){const s=n.get(e),c=s.parentId?n.get(s.parentId):void 0,{x:d,y:h}=c?c.internals.positionAbsolute:{x:0,y:0},m=s.origin??i;let f=s.extent||a;if(s.extent==="parent"&&!s.expandParent)if(!c)r==null||r("005",fa.error005());else{const g=c.measured.width,b=c.measured.height;g&&b&&(f=[[d,h],[d+g,h+b]])}else c&&R1(s.extent)&&(f=[[s.extent[0][0]+d,s.extent[0][1]+h],[s.extent[1][0]+d,s.extent[1][1]+h]]);const k=R1(f)?T1(t,f,s.measured):t;return(s.measured.width===void 0||s.measured.height===void 0)&&(r==null||r("015",fa.error015())),{position:{x:k.x-d+(s.measured.width??0)*m[0],y:k.y-h+(s.measured.height??0)*m[1]},positionAbsolute:k}}async function Iat({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:i,onBeforeDelete:a}){const r=new Set(e.map(k=>k.id)),s=[];for(const k of n){if(k.deletable===!1)continue;const g=r.has(k.id),b=!g&&k.parentId&&s.find(v=>v.id===k.parentId);(g||b)&&s.push(k)}const c=new Set(t.map(k=>k.id)),d=i.filter(k=>k.deletable!==!1),m=Lat(s,d);for(const k of d)c.has(k.id)&&!m.find(b=>b.id===k.id)&&m.push(k);if(!a)return{edges:m,nodes:s};const f=await a({nodes:s,edges:m});return typeof f=="boolean"?f?{edges:m,nodes:s}:{edges:[],nodes:[]}:f}const Rp=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),T1=(e={x:0,y:0},t,n)=>({x:Rp(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:Rp(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function Goe(e,t,n){const{width:i,height:a}=qo(n),{x:r,y:s}=n.internals.positionAbsolute;return T1(e,[[r,s],[r+i,s+a]],t)}const AZ=(e,t,n)=>e<t?Rp(Math.abs(e-t),1,t)/t:e>n?-Rp(Math.abs(e-n),1,t)/t:0,bV=(e,t,n=15,i=40)=>{const a=AZ(e.x,i,t.width-i)*n,r=AZ(e.y,i,t.height-i)*n;return[a,r]},UO=(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)}),yH=({x:e,y:t,width:n,height:i})=>({x:e,y:t,x2:e+n,y2:t+i}),KO=({x:e,y:t,x2:n,y2:i})=>({x:e,y:t,width:n-e,height:i-t}),g2=(e,t=[0,0])=>{var a,r;const{x:n,y:i}=kV(e)?e.internals.positionAbsolute:X2(e,t);return{x:n,y:i,width:((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0,height:((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0}},nO=(e,t=[0,0])=>{var a,r;const{x:n,y:i}=kV(e)?e.internals.positionAbsolute:X2(e,t);return{x:n,y:i,x2:n+(((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0),y2:i+(((r=e.measured)==null?void 0:r.height)??e.height??e.initialHeight??0)}},Woe=(e,t)=>KO(UO(yH(e),yH(t))),Xoe=(e,t,n,i,a,r,s,c)=>{const d=Math.max(0,Math.min(e+n,a+s)-Math.max(e,a)),h=Math.max(0,Math.min(t+i,r+c)-Math.max(t,r));return Math.ceil(d*h)},iO=(e,t)=>Xoe(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),IZ=e=>rr(e.width)&&rr(e.height)&&rr(e.x)&&rr(e.y),rr=e=>!isNaN(e)&&isFinite(e),Yoe=(e,t)=>(n,i)=>{},Q2=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Z2=({x:e,y:t},[n,i,a],r=!1,s=[1,1])=>{const c={x:(e-n)/a,y:(t-i)/a};return r?Q2(c,s):c},Dp=({x:e,y:t},[n,i,a])=>({x:e*a+n,y:t*a+i});function Eh(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 Tat(e,t,n){if(typeof e=="string"||typeof e=="number"){const i=Eh(e,n),a=Eh(e,t);return{top:i,right:a,bottom:i,left:a,x:a*2,y:i*2}}if(typeof e=="object"){const i=Eh(e.top??e.y??0,n),a=Eh(e.bottom??e.y??0,n),r=Eh(e.left??e.x??0,t),s=Eh(e.right??e.x??0,t);return{top:i,right:s,bottom:a,left:r,x:r+s,y:i+a}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function Rat(e,t,n,i,a,r){const{x:s,y:c}=Dp(e,[t,n,i]),{x:d,y:h}=Dp({x:e.x+e.width,y:e.y+e.height},[t,n,i]),m=a-d,f=r-h;return{left:Math.floor(s),top:Math.floor(c),right:Math.floor(m),bottom:Math.floor(f)}}const vV=(e,t,n,i,a,r)=>{const s=Tat(r,t,n),c=(t-s.x)/e.width,d=(n-s.y)/e.height,h=Math.min(c,d),m=Rp(h,i,a),f=e.x+e.width/2,k=e.y+e.height/2,g=t/2-f*m,b=n/2-k*m,v=Rat(e,g,b,m,t,n),w={left:Math.min(v.left-s.left,0),top:Math.min(v.top-s.top,0),right:Math.min(v.right-s.right,0),bottom:Math.min(v.bottom-s.bottom,0)};return{x:g-w.left+w.right,y:b-w.top+w.bottom,zoom:m}},k2=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function R1(e){return e!=null&&e!=="parent"}function qo(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 Qoe(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 Zoe(e,t={width:0,height:0},n,i,a){const r={...e},s=i.get(n);if(s){const c=s.origin||a;r.x+=s.internals.positionAbsolute.x-(t.width??0)*c[0],r.y+=s.internals.positionAbsolute.y-(t.height??0)*c[1]}return r}function TZ(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function Dat(){let e,t;return{promise:new Promise((i,a)=>{e=i,t=a}),resolve:e,reject:t}}function Oat(e){return{...Hoe,...e||{}}}function X0(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:i,containerBounds:a}){const{x:r,y:s}=or(e),c=Z2({x:r-((a==null?void 0:a.left)??0),y:s-((a==null?void 0:a.top)??0)},i),{x:d,y:h}=n?Q2(c,t):c;return{xSnapped:d,ySnapped:h,...c}}const wV=e=>({width:e.offsetWidth,height:e.offsetHeight}),Joe=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},zat=["INPUT","SELECT","TEXTAREA"];function ese(e){var i,a;const t=((a=(i=e.composedPath)==null?void 0:i.call(e))==null?void 0:a[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:zat.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const tse=e=>"clientX"in e,or=(e,t)=>{var r,s;const n=tse(e),i=n?e.clientX:(r=e.touches)==null?void 0:r[0].clientX,a=n?e.clientY:(s=e.touches)==null?void 0:s[0].clientY;return{x:i-((t==null?void 0:t.left)??0),y:a-((t==null?void 0:t.top)??0)}},RZ=(e,t,n,i,a)=>{const r=t.querySelectorAll(`.${e}`);return!r||!r.length?null:Array.from(r).map(s=>{const c=s.getBoundingClientRect();return{id:s.getAttribute("data-handleid"),type:e,nodeId:a,position:s.getAttribute("data-handlepos"),x:(c.left-n.left)/i,y:(c.top-n.top)/i,...wV(s)}})};function nse({sourceX:e,sourceY:t,targetX:n,targetY:i,sourceControlX:a,sourceControlY:r,targetControlX:s,targetControlY:c}){const d=e*.125+a*.375+s*.375+n*.125,h=t*.125+r*.375+c*.375+i*.125,m=Math.abs(d-e),f=Math.abs(h-t);return[d,h,m,f]}function $y(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function DZ({pos:e,x1:t,y1:n,x2:i,y2:a,c:r}){switch(e){case tt.Left:return[t-$y(t-i,r),n];case tt.Right:return[t+$y(i-t,r),n];case tt.Top:return[t,n-$y(n-a,r)];case tt.Bottom:return[t,n+$y(a-n,r)]}}function ise({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:a,targetPosition:r=tt.Top,curvature:s=.25}){const[c,d]=DZ({pos:n,x1:e,y1:t,x2:i,y2:a,c:s}),[h,m]=DZ({pos:r,x1:i,y1:a,x2:e,y2:t,c:s}),[f,k,g,b]=nse({sourceX:e,sourceY:t,targetX:i,targetY:a,sourceControlX:c,sourceControlY:d,targetControlX:h,targetControlY:m});return[`M${e},${t} C${c},${d} ${h},${m} ${i},${a}`,f,k,g,b]}function ase({sourceX:e,sourceY:t,targetX:n,targetY:i}){const a=Math.abs(n-e)/2,r=n<e?n+a:n-a,s=Math.abs(i-t)/2,c=i<t?i+s:i-s;return[r,c,a,s]}function Pat({sourceNode:e,targetNode:t,selected:n=!1,zIndex:i=0,elevateOnSelect:a=!1,zIndexMode:r="basic"}){if(r==="manual")return i;const s=a&&n?i+1e3:i,c=Math.max(e.parentId||a&&e.selected?e.internals.z:0,t.parentId||a&&t.selected?t.internals.z:0);return s+c}function $at({sourceNode:e,targetNode:t,width:n,height:i,transform:a}){const r=UO(nO(e),nO(t));r.x===r.x2&&(r.x2+=1),r.y===r.y2&&(r.y2+=1);const s={x:-a[0]/a[2],y:-a[1]/a[2],width:n/a[2],height:i/a[2]};return iO(s,KO(r))>0}const rse=({source:e,sourceHandle:t,target:n,targetHandle:i})=>`xy-edge__${e}${t||""}-${n}${i||""}`,qat=(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)),Bat=(e,t,n={})=>{var r;if(!e.source||!e.target)return(r=n.onError)==null||r.call(n,"006",fa.error006()),t;const i=n.getEdgeId||rse;let a;return Uoe(e)?a={...e}:a={...e,id:i(e)},qat(a,t)?t:(a.sourceHandle===null&&delete a.sourceHandle,a.targetHandle===null&&delete a.targetHandle,t.concat(a))},Hat=(e,t,n,i={shouldReplaceId:!0})=>{var h,m;const{id:a,...r}=e;if(!t.source||!t.target)return(h=i.onError)==null||h.call(i,"006",fa.error006()),n;if(!n.find(f=>f.id===e.id))return(m=i.onError)==null||m.call(i,"007",fa.error007(a)),n;const c=i.getEdgeId||rse,d={...r,id:i.shouldReplaceId?c(t):a,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle};return n.filter(f=>f.id!==a).concat(d)};function ose({sourceX:e,sourceY:t,targetX:n,targetY:i}){const[a,r,s,c]=ase({sourceX:e,sourceY:t,targetX:n,targetY:i});return[`M ${e},${t}L ${n},${i}`,a,r,s,c]}const OZ={[tt.Left]:{x:-1,y:0},[tt.Right]:{x:1,y:0},[tt.Top]:{x:0,y:-1},[tt.Bottom]:{x:0,y:1}},Fat=({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},zZ=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Vat({source:e,sourcePosition:t=tt.Bottom,target:n,targetPosition:i=tt.Top,center:a,offset:r,stepPosition:s}){const c=OZ[t],d=OZ[i],h={x:e.x+c.x*r,y:e.y+c.y*r},m={x:n.x+d.x*r,y:n.y+d.y*r},f=Fat({source:h,sourcePosition:t,target:m}),k=f.x!==0?"x":"y",g=f[k];let b=[],v,w;const S={x:0,y:0},C={x:0,y:0},[,,M,L]=ase({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(c[k]*d[k]===-1){k==="x"?(v=a.x??h.x+(m.x-h.x)*s,w=a.y??(h.y+m.y)/2):(v=a.x??(h.x+m.x)/2,w=a.y??h.y+(m.y-h.y)*s);const T=[{x:v,y:h.y},{x:v,y:m.y}],P=[{x:h.x,y:w},{x:m.x,y:w}];c[k]===g?b=k==="x"?T:P:b=k==="x"?P:T}else{const T=[{x:h.x,y:m.y}],P=[{x:m.x,y:h.y}];if(k==="x"?b=c.x===g?P:T:b=c.y===g?T:P,t===i){const R=Math.abs(e[k]-n[k]);if(R<=r){const z=Math.min(r-1,r-R);c[k]===g?S[k]=(h[k]>e[k]?-1:1)*z:C[k]=(m[k]>n[k]?-1:1)*z}}if(t!==i){const R=k==="x"?"y":"x",z=c[k]===d[R],$=h[R]>m[R],X=h[R]<m[R];(c[k]===1&&(!z&&$||z&&X)||c[k]!==1&&(!z&&X||z&&$))&&(b=k==="x"?T:P)}const D={x:h.x+S.x,y:h.y+S.y},q={x:m.x+C.x,y:m.y+C.y},H=Math.max(Math.abs(D.x-b[0].x),Math.abs(q.x-b[0].x)),K=Math.max(Math.abs(D.y-b[0].y),Math.abs(q.y-b[0].y));H>=K?(v=(D.x+q.x)/2,w=b[0].y):(v=b[0].x,w=(D.y+q.y)/2)}const j={x:h.x+S.x,y:h.y+S.y},A={x:m.x+C.x,y:m.y+C.y};return[[e,...j.x!==b[0].x||j.y!==b[0].y?[j]:[],...b,...A.x!==b[b.length-1].x||A.y!==b[b.length-1].y?[A]:[],n],v,w,M,L]}function Uat(e,t,n,i){const a=Math.min(zZ(e,t)/2,zZ(t,n)/2,i),{x:r,y:s}=t;if(e.x===r&&r===n.x||e.y===s&&s===n.y)return`L${r} ${s}`;if(e.y===s){const h=e.x<n.x?-1:1,m=e.y<n.y?1:-1;return`L ${r+a*h},${s}Q ${r},${s} ${r},${s+a*m}`}const c=e.x<n.x?1:-1,d=e.y<n.y?-1:1;return`L ${r},${s+a*d}Q ${r},${s} ${r+a*c},${s}`}function gH({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:a,targetPosition:r=tt.Top,borderRadius:s=5,centerX:c,centerY:d,offset:h=20,stepPosition:m=.5}){const[f,k,g,b,v]=Vat({source:{x:e,y:t},sourcePosition:n,target:{x:i,y:a},targetPosition:r,center:{x:c,y:d},offset:h,stepPosition:m});let w=`M${f[0].x} ${f[0].y}`;for(let S=1;S<f.length-1;S++)w+=Uat(f[S-1],f[S],f[S+1],s);return w+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[w,k,g,b,v]}function PZ(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Kat(e){var f;const{sourceNode:t,targetNode:n}=e;if(!PZ(t)||!PZ(n))return null;const i=t.internals.handleBounds||$Z(t.handles),a=n.internals.handleBounds||$Z(n.handles),r=qZ((i==null?void 0:i.source)??[],e.sourceHandle),s=qZ(e.connectionMode===Tp.Strict?(a==null?void 0:a.target)??[]:((a==null?void 0:a.target)??[]).concat((a==null?void 0:a.source)??[]),e.targetHandle);if(!r||!s)return(f=e.onError)==null||f.call(e,"008",fa.error008(r?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const c=(r==null?void 0:r.position)||tt.Bottom,d=(s==null?void 0:s.position)||tt.Top,h=D1(t,r,c),m=D1(n,s,d);return{sourceX:h.x,sourceY:h.y,targetX:m.x,targetY:m.y,sourcePosition:c,targetPosition:d}}function $Z(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 D1(e,t,n=tt.Left,i=!1){const a=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,r=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:s,height:c}=t??qo(e);if(i)return{x:a+s/2,y:r+c/2};switch((t==null?void 0:t.position)??n){case tt.Top:return{x:a+s/2,y:r};case tt.Right:return{x:a+s,y:r+c/2};case tt.Bottom:return{x:a+s/2,y:r+c};case tt.Left:return{x:a,y:r+c/2}}}function qZ(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function kH(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(i=>`${i}=${e[i]}`).join("&")}`:""}function Gat(e,{id:t,defaultColor:n,defaultMarkerStart:i,defaultMarkerEnd:a}){const r=new Set;return e.reduce((s,c)=>([c.markerStart||i,c.markerEnd||a].forEach(d=>{if(d&&typeof d=="object"){const h=kH(d,t);r.has(h)||(s.push({id:h,color:d.color||n,...d}),r.add(h))}}),s),[]).sort((s,c)=>s.id.localeCompare(c.id))}const sse=1e3,Wat=10,MV={nodeOrigin:[0,0],nodeExtent:m2,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Xat={...MV,checkEquality:!0};function _V(e,t){const n={...e};for(const i in t)t[i]!==void 0&&(n[i]=t[i]);return n}function Yat(e,t,n){const i=_V(MV,n);for(const a of e.values())if(a.parentId)NV(a,e,t,i);else{const r=X2(a,i.nodeOrigin),s=R1(a.extent)?a.extent:i.nodeExtent,c=T1(r,s,qo(a));a.internals.positionAbsolute=c}}function Qat(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],i=[];for(const a of e.handles){const r={id:a.id,width:a.width??1,height:a.height??1,nodeId:e.id,x:a.x,y:a.y,position:a.position,type:a.type};a.type==="source"?n.push(r):a.type==="target"&&i.push(r)}return{source:n,target:i}}function SV(e){return e==="manual"}function xH(e,t,n,i={}){var m,f;const a=_V(Xat,i),r={i:0},s=new Map(t),c=a!=null&&a.elevateNodesOnSelect&&!SV(a.zIndexMode)?sse:0;let d=e.length>0,h=!1;t.clear(),n.clear();for(const k of e){let g=s.get(k.id);if(a.checkEquality&&k===(g==null?void 0:g.internals.userNode))t.set(k.id,g);else{const b=X2(k,a.nodeOrigin),v=R1(k.extent)?k.extent:a.nodeExtent,w=T1(b,v,qo(k));g={...a.defaults,...k,measured:{width:(m=k.measured)==null?void 0:m.width,height:(f=k.measured)==null?void 0:f.height},internals:{positionAbsolute:w,handleBounds:Qat(k,g),z:lse(k,c,a.zIndexMode),userNode:k}},t.set(k.id,g)}(g.measured===void 0||g.measured.width===void 0||g.measured.height===void 0)&&!g.hidden&&(d=!1),k.parentId&&NV(g,t,n,i,r),h||(h=k.selected??!1)}return{nodesInitialized:d,hasSelectedNodes:h}}function Zat(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 NV(e,t,n,i,a){const{elevateNodesOnSelect:r,nodeOrigin:s,nodeExtent:c,zIndexMode:d}=_V(MV,i),h=e.parentId,m=t.get(h);if(!m){console.warn(`Parent node ${h} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}Zat(e,n),a&&!m.parentId&&m.internals.rootParentIndex===void 0&&d==="auto"&&(m.internals.rootParentIndex=++a.i,m.internals.z=m.internals.z+a.i*Wat),a&&m.internals.rootParentIndex!==void 0&&(a.i=m.internals.rootParentIndex);const f=r&&!SV(d)?sse:0,{x:k,y:g,z:b}=Jat(e,m,s,c,f,d),{positionAbsolute:v}=e.internals,w=k!==v.x||g!==v.y;(w||b!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:k,y:g}:v,z:b}})}function lse(e,t,n){const i=rr(e.zIndex)?e.zIndex:0;return SV(n)?i:i+(e.selected?t:0)}function Jat(e,t,n,i,a,r){const{x:s,y:c}=t.internals.positionAbsolute,d=qo(e),h=X2(e,n),m=R1(e.extent)?T1(h,e.extent,d):h;let f=T1({x:s+m.x,y:c+m.y},i,d);e.extent==="parent"&&(f=Goe(f,d,t));const k=lse(e,a,r),g=t.internals.z??0;return{x:f.x,y:f.y,z:g>=k?g+1:k}}function EV(e,t,n,i=[0,0]){var s;const a=[],r=new Map;for(const c of e){const d=t.get(c.parentId);if(!d)continue;const h=((s=r.get(c.parentId))==null?void 0:s.expandedRect)??g2(d),m=Woe(h,c.rect);r.set(c.parentId,{expandedRect:m,parent:d})}return r.size>0&&r.forEach(({expandedRect:c,parent:d},h)=>{var M;const m=d.internals.positionAbsolute,f=qo(d),k=d.origin??i,g=c.x<m.x?Math.round(Math.abs(m.x-c.x)):0,b=c.y<m.y?Math.round(Math.abs(m.y-c.y)):0,v=Math.max(f.width,Math.round(c.width)),w=Math.max(f.height,Math.round(c.height)),S=(v-f.width)*k[0],C=(w-f.height)*k[1];(g>0||b>0||S||C)&&(a.push({id:h,type:"position",position:{x:d.position.x-g+S,y:d.position.y-b+C}}),(M=n.get(h))==null||M.forEach(L=>{e.some(j=>j.id===L.id)||a.push({id:L.id,type:"position",position:{x:L.position.x+g,y:L.position.y+b}})})),(f.width<c.width||f.height<c.height||g||b)&&a.push({id:h,type:"dimensions",setAttributes:!0,dimensions:{width:v+(g?k[0]*g-S:0),height:w+(b?k[1]*b-C:0)}})}),a}function ert(e,t,n,i,a,r,s){const c=i==null?void 0:i.querySelector(".xyflow__viewport");let d=!1;if(!c)return{changes:[],updatedInternals:d};const h=[],m=window.getComputedStyle(c),{m22:f}=new window.DOMMatrixReadOnly(m.transform),k=[];for(const g of e.values()){const b=t.get(g.id);if(!b)continue;if(b.hidden){t.set(b.id,{...b,internals:{...b.internals,handleBounds:void 0}}),d=!0;continue}const v=wV(g.nodeElement),w=b.measured.width!==v.width||b.measured.height!==v.height;if(!!(v.width&&v.height&&(w||!b.internals.handleBounds||g.force))){const C=g.nodeElement.getBoundingClientRect(),M=R1(b.extent)?b.extent:r;let{positionAbsolute:L}=b.internals;b.parentId&&b.extent==="parent"?L=Goe(L,v,t.get(b.parentId)):M&&(L=T1(L,M,v));const j={...b,measured:v,internals:{...b.internals,positionAbsolute:L,handleBounds:{source:RZ("source",g.nodeElement,C,f,b.id),target:RZ("target",g.nodeElement,C,f,b.id)}}};t.set(b.id,j),b.parentId&&NV(j,t,n,{nodeOrigin:a,zIndexMode:s}),d=!0,w&&(h.push({id:b.id,type:"dimensions",dimensions:v}),b.expandParent&&b.parentId&&k.push({id:b.id,parentId:b.parentId,rect:g2(j,a)}))}}if(k.length>0){const g=EV(k,t,n,a);h.push(...g)}return{changes:h,updatedInternals:d}}async function trt({delta:e,panZoom:t,transform:n,translateExtent:i,width:a,height:r}){if(!t||!e.x&&!e.y)return!1;const s=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[a,r]],i);return!!s&&(s.x!==n[0]||s.y!==n[1]||s.k!==n[2])}function BZ(e,t,n,i,a,r){let s=a;const c=i.get(s)||new Map;i.set(s,c.set(n,t)),s=`${a}-${e}`;const d=i.get(s)||new Map;if(i.set(s,d.set(n,t)),r){s=`${a}-${e}-${r}`;const h=i.get(s)||new Map;i.set(s,h.set(n,t))}}function cse(e,t,n){e.clear(),t.clear();for(const i of n){const{source:a,target:r,sourceHandle:s=null,targetHandle:c=null}=i,d={edgeId:i.id,source:a,target:r,sourceHandle:s,targetHandle:c},h=`${a}-${s}--${r}-${c}`,m=`${r}-${c}--${a}-${s}`;BZ("source",d,m,e,a,s),BZ("target",d,h,e,r,c),t.set(i.id,i)}}function dse(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:dse(n,t):!1}function HZ(e,t,n){var a;let i=e;do{if((a=i==null?void 0:i.matches)!=null&&a.call(i,t))return!0;if(i===n)return!1;i=i==null?void 0:i.parentElement}while(i);return!1}function nrt(e,t,n,i){const a=new Map;for(const[r,s]of e)if((s.selected||s.id===i)&&(!s.parentId||!dse(s,e))&&(s.draggable||t&&typeof s.draggable>"u")){const c=e.get(r);c&&a.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 a}function kq({nodeId:e,dragItems:t,nodeLookup:n,dragging:i=!0}){var s,c,d;const a=[];for(const[h,m]of t){const f=(s=n.get(h))==null?void 0:s.internals.userNode;f&&a.push({...f,position:m.position,dragging:i})}if(!e)return[a[0],a];const r=(c=n.get(e))==null?void 0:c.internals.userNode;return[r?{...r,position:((d=t.get(e))==null?void 0:d.position)||r.position,dragging:i}:a[0],a]}function irt({dragItems:e,snapGrid:t,x:n,y:i}){const a=e.values().next().value;if(!a)return null;const r={x:n-a.distance.x,y:i-a.distance.y},s=Q2(r,t);return{x:s.x-r.x,y:s.y-r.y}}function art({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:i,onDragStop:a}){let r={x:null,y:null},s=0,c=new Map,d=!1,h={x:0,y:0},m=null,f=!1,k=null,g=!1,b=!1,v=null;function w({noDragClassName:C,handleSelector:M,domNode:L,isSelectable:j,nodeId:A,nodeClickDistance:I=0}){k=da(L);function T({x:H,y:K}){const{nodeLookup:R,nodeExtent:z,snapGrid:$,snapToGrid:X,nodeOrigin:Q,onNodeDrag:W,onSelectionDrag:B,onError:V,updateNodePositions:Y}=t();r={x:H,y:K};let F=!1;const ae=c.size>1,xe=ae&&z?yH(Y2(c)):null,de=ae&&X?irt({dragItems:c,snapGrid:$,x:H,y:K}):null;for(const[Ee,ce]of c){if(!R.has(Ee))continue;let me={x:H-ce.distance.x,y:K-ce.distance.y};X&&(me=de?{x:Math.round(me.x+de.x),y:Math.round(me.y+de.y)}:Q2(me,$));let je=null;if(ae&&z&&!ce.extent&&xe){const{positionAbsolute:be}=ce.internals,pe=be.x-xe.x+z[0][0],ne=be.x+ce.measured.width-xe.x2+z[1][0],we=be.y-xe.y+z[0][1],Be=be.y+ce.measured.height-xe.y2+z[1][1];je=[[pe,we],[ne,Be]]}const{position:ie,positionAbsolute:le}=Koe({nodeId:Ee,nextPosition:me,nodeLookup:R,nodeExtent:je||z,nodeOrigin:Q,onError:V});F=F||ce.position.x!==ie.x||ce.position.y!==ie.y,ce.position=ie,ce.internals.positionAbsolute=le}if(b=b||F,!!F&&(Y(c,!0),v&&(i||W||!A&&B))){const[Ee,ce]=kq({nodeId:A,dragItems:c,nodeLookup:R});i==null||i(v,c,Ee,ce),W==null||W(v,Ee,ce),A||B==null||B(v,ce)}}async function P(){if(!m)return;const{transform:H,panBy:K,autoPanSpeed:R,autoPanOnNodeDrag:z}=t();if(!z){d=!1,cancelAnimationFrame(s);return}const[$,X]=bV(h,m,R);($!==0||X!==0)&&(r.x=(r.x??0)-$/H[2],r.y=(r.y??0)-X/H[2],await K({x:$,y:X})&&T(r)),s=requestAnimationFrame(P)}function D(H){var ae;const{nodeLookup:K,multiSelectionActive:R,nodesDraggable:z,transform:$,snapGrid:X,snapToGrid:Q,selectNodesOnDrag:W,onNodeDragStart:B,onSelectionDragStart:V,unselectNodesAndEdges:Y}=t();f=!0,(!W||!j)&&!R&&A&&((ae=K.get(A))!=null&&ae.selected||Y()),j&&W&&A&&(e==null||e(A));const F=X0(H.sourceEvent,{transform:$,snapGrid:X,snapToGrid:Q,containerBounds:m});if(r=F,c=nrt(K,z,F,A),c.size>0&&(n||B||!A&&V)){const[xe,de]=kq({nodeId:A,dragItems:c,nodeLookup:K});n==null||n(H.sourceEvent,c,xe,de),B==null||B(H.sourceEvent,xe,de),A||V==null||V(H.sourceEvent,de)}}const q=Soe().clickDistance(I).on("start",H=>{const{domNode:K,nodeDragThreshold:R,transform:z,snapGrid:$,snapToGrid:X}=t();m=(K==null?void 0:K.getBoundingClientRect())||null,g=!1,b=!1,v=H.sourceEvent,R===0&&D(H),r=X0(H.sourceEvent,{transform:z,snapGrid:$,snapToGrid:X,containerBounds:m}),h=or(H.sourceEvent,m)}).on("drag",H=>{const{autoPanOnNodeDrag:K,transform:R,snapGrid:z,snapToGrid:$,nodeDragThreshold:X,nodeLookup:Q}=t(),W=X0(H.sourceEvent,{transform:R,snapGrid:z,snapToGrid:$,containerBounds:m});if(v=H.sourceEvent,(H.sourceEvent.type==="touchmove"&&H.sourceEvent.touches.length>1||A&&!Q.has(A))&&(g=!0),!g){if(!d&&K&&f&&(d=!0,P()),!f){const B=or(H.sourceEvent,m),V=B.x-h.x,Y=B.y-h.y;Math.sqrt(V*V+Y*Y)>X&&D(H)}(r.x!==W.xSnapped||r.y!==W.ySnapped)&&c&&f&&(h=or(H.sourceEvent,m),T(W))}}).on("end",H=>{if(!f||g){g&&c.size>0&&t().updateNodePositions(c,!1);return}if(d=!1,f=!1,cancelAnimationFrame(s),c.size>0){const{nodeLookup:K,updateNodePositions:R,onNodeDragStop:z,onSelectionDragStop:$}=t();if(b&&(R(c,!1),b=!1),a||z||!A&&$){const[X,Q]=kq({nodeId:A,dragItems:c,nodeLookup:K,dragging:!1});a==null||a(H.sourceEvent,c,X,Q),z==null||z(H.sourceEvent,X,Q),A||$==null||$(H.sourceEvent,Q)}}}).filter(H=>{const K=H.target;return!H.button&&(!C||!HZ(K,`.${C}`,L))&&(!M||HZ(K,M,L))});k.call(q)}function S(){k==null||k.on(".drag",null)}return{update:w,destroy:S}}function rrt(e,t,n){const i=[],a={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const r of t.values())iO(a,g2(r))>0&&i.push(r);return i}const ort=250;function srt(e,t,n,i){var c,d;let a=[],r=1/0;const s=rrt(e,n,t+ort);for(const h of s){const m=[...((c=h.internals.handleBounds)==null?void 0:c.source)??[],...((d=h.internals.handleBounds)==null?void 0:d.target)??[]];for(const f of m){if(i.nodeId===f.nodeId&&i.type===f.type&&i.id===f.id)continue;const{x:k,y:g}=D1(h,f,f.position,!0),b=Math.sqrt(Math.pow(k-e.x,2)+Math.pow(g-e.y,2));b>t||(b<r?(a=[{...f,x:k,y:g}],r=b):b===r&&a.push({...f,x:k,y:g}))}}if(!a.length)return null;if(a.length>1){const h=i.type==="source"?"target":"source";return a.find(m=>m.type===h)??a[0]}return a[0]}function use(e,t,n,i,a,r=!1){var h,m,f;const s=i.get(e);if(!s)return null;const c=a==="strict"?(h=s.internals.handleBounds)==null?void 0:h[t]:[...((m=s.internals.handleBounds)==null?void 0:m.source)??[],...((f=s.internals.handleBounds)==null?void 0:f.target)??[]],d=(n?c==null?void 0:c.find(k=>k.id===n):c==null?void 0:c[0])??null;return d&&r?{...d,...D1(s,d,d.position,!0)}:d}function hse(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function lrt(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const pse=()=>!0;function crt(e,{connectionMode:t,connectionRadius:n,handleId:i,nodeId:a,edgeUpdaterType:r,isTarget:s,domNode:c,nodeLookup:d,lib:h,autoPanOnConnect:m,flowId:f,panBy:k,cancelConnection:g,onConnectStart:b,onConnect:v,onConnectEnd:w,isValidConnection:S=pse,onReconnectEnd:C,updateConnection:M,getTransform:L,getFromHandle:j,autoPanSpeed:A,dragThreshold:I=1,handleDomNode:T}){const P=Joe(e.target);let D=0,q;const{x:H,y:K}=or(e),R=hse(r,T),z=c==null?void 0:c.getBoundingClientRect();let $=!1;if(!z||!R)return;const X=use(a,R,i,d,t);if(!X)return;let Q=or(e,z),W=!1,B=null,V=!1,Y=null;function F(){if(!m||!z)return;const[ie,le]=bV(Q,z,A);k({x:ie,y:le}),D=requestAnimationFrame(F)}const ae={...X,nodeId:a,type:R,position:X.position},xe=d.get(a);let Ee={inProgress:!0,isValid:null,from:D1(xe,ae,tt.Left,!0),fromHandle:ae,fromPosition:ae.position,fromNode:xe,to:Q,toHandle:null,toPosition:jZ[ae.position],toNode:null,pointer:Q};function ce(){$=!0,M(Ee),b==null||b(e,{nodeId:a,handleId:i,handleType:R})}I===0&&ce();function me(ie){if(!$){const{x:Be,y:Oe}=or(ie),ft=Be-H,it=Oe-K;if(!(ft*ft+it*it>I*I))return;ce()}if(!j()||!ae){je(ie);return}const le=L();Q=or(ie,z),q=srt(Z2(Q,le,!1,[1,1]),n,d,ae),W||(F(),W=!0);const be=fse(ie,{handle:q,connectionMode:t,fromNodeId:a,fromHandleId:i,fromType:s?"target":"source",isValidConnection:S,doc:P,lib:h,flowId:f,nodeLookup:d});Y=be.handleDomNode,B=be.connection,V=lrt(!!q,be.isValid);const pe=d.get(a),ne=pe?D1(pe,ae,tt.Left,!0):Ee.from,we={...Ee,from:ne,isValid:V,to:be.toHandle&&V?Dp({x:be.toHandle.x,y:be.toHandle.y},le):Q,toHandle:be.toHandle,toPosition:V&&be.toHandle?be.toHandle.position:jZ[ae.position],toNode:be.toHandle?d.get(be.toHandle.nodeId):null,pointer:Q};M(we),Ee=we}function je(ie){if(!("touches"in ie&&ie.touches.length>0)){if($){(q||Y)&&B&&V&&(v==null||v(B));const{inProgress:le,...be}=Ee,pe={...be,toPosition:Ee.toHandle?Ee.toPosition:null};w==null||w(ie,pe),r&&(C==null||C(ie,pe))}g(),cancelAnimationFrame(D),W=!1,V=!1,B=null,Y=null,P.removeEventListener("mousemove",me),P.removeEventListener("mouseup",je),P.removeEventListener("touchmove",me),P.removeEventListener("touchend",je)}}P.addEventListener("mousemove",me),P.addEventListener("mouseup",je),P.addEventListener("touchmove",me),P.addEventListener("touchend",je)}function fse(e,{handle:t,connectionMode:n,fromNodeId:i,fromHandleId:a,fromType:r,doc:s,lib:c,flowId:d,isValidConnection:h=pse,nodeLookup:m}){const f=r==="target",k=t?s.querySelector(`.${c}-flow__handle[data-id="${d}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:g,y:b}=or(e),v=s.elementFromPoint(g,b),w=v!=null&&v.classList.contains(`${c}-flow__handle`)?v:k,S={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const C=hse(void 0,w),M=w.getAttribute("data-nodeid"),L=w.getAttribute("data-handleid"),j=w.classList.contains("connectable"),A=w.classList.contains("connectableend");if(!M||!C)return S;const I={source:f?M:i,sourceHandle:f?L:a,target:f?i:M,targetHandle:f?a:L};S.connection=I;const P=j&&A&&(n===Tp.Strict?f&&C==="source"||!f&&C==="target":M!==i||L!==a);S.isValid=P&&h(I),S.toHandle=use(M,C,L,m,n,!0)}return S}const bH={onPointerDown:crt,isValid:fse};function drt({domNode:e,panZoom:t,getTransform:n,getViewScale:i}){const a=da(e);function r({translateExtent:c,width:d,height:h,zoomStep:m=1,pannable:f=!0,zoomable:k=!0,inversePan:g=!1}){const b=M=>{if(M.sourceEvent.type!=="wheel"||!t)return;const L=n(),j=M.sourceEvent.ctrlKey&&k2()?10:1,A=-M.sourceEvent.deltaY*(M.sourceEvent.deltaMode===1?.05:M.sourceEvent.deltaMode?1:.002)*m,I=L[2]*Math.pow(2,A*j);t.scaleTo(I)};let v=[0,0];const w=M=>{(M.sourceEvent.type==="mousedown"||M.sourceEvent.type==="touchstart")&&(v=[M.sourceEvent.clientX??M.sourceEvent.touches[0].clientX,M.sourceEvent.clientY??M.sourceEvent.touches[0].clientY])},S=M=>{const L=n();if(M.sourceEvent.type!=="mousemove"&&M.sourceEvent.type!=="touchmove"||!t)return;const j=[M.sourceEvent.clientX??M.sourceEvent.touches[0].clientX,M.sourceEvent.clientY??M.sourceEvent.touches[0].clientY],A=[j[0]-v[0],j[1]-v[1]];v=j;const I=i()*Math.max(L[2],Math.log(L[2]))*(g?-1:1),T={x:L[0]-A[0]*I,y:L[1]-A[1]*I},P=[[0,0],[d,h]];t.setViewportConstrained({x:T.x,y:T.y,zoom:L[2]},P,c)},C=qoe().on("start",w).on("zoom",f?S:null).on("zoom.wheel",k?b:null);a.call(C,{})}function s(){a.on("zoom",null)}return{update:r,destroy:s,pointer:tr}}const GO=e=>({x:e.x,y:e.y,zoom:e.k}),xq=({x:e,y:t,zoom:n})=>VO.translate(e,t).scale(n),qh=(e,t)=>e.target.closest(`.${t}`),mse=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),urt=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,bq=(e,t=0,n=urt,i=()=>{})=>{const a=typeof t=="number"&&t>0;return a||i(),a?e.transition().duration(t).ease(n).on("end",i):e},yse=e=>{const t=e.ctrlKey&&k2()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function hrt({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:i,panOnScrollMode:a,panOnScrollSpeed:r,zoomOnPinch:s,onPanZoomStart:c,onPanZoom:d,onPanZoomEnd:h}){return m=>{if(qh(m,t))return m.ctrlKey&&m.preventDefault(),!1;m.preventDefault(),m.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(m.ctrlKey&&s){const w=tr(m),S=yse(m),C=f*Math.pow(2,S);i.scaleTo(n,C,w,m);return}const k=m.deltaMode===1?20:1;let g=a===N1.Vertical?0:m.deltaX*k,b=a===N1.Horizontal?0:m.deltaY*k;!k2()&&m.shiftKey&&a!==N1.Vertical&&(g=m.deltaY*k,b=0),i.translateBy(n,-(g/f)*r,-(b/f)*r,{internal:!0});const v=GO(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(d==null||d(m,v),e.panScrollTimeout=setTimeout(()=>{h==null||h(m,v),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,c==null||c(m,v))}}function prt({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(i,a){const r=i.type==="wheel",s=!t&&r&&!i.ctrlKey,c=qh(i,e);if(i.ctrlKey&&r&&c&&i.preventDefault(),s||c)return null;i.preventDefault(),n.call(this,i,a)}}function frt({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return i=>{var r,s,c;if((r=i.sourceEvent)!=null&&r.internal)return;const a=GO(i.transform);e.mouseButton=((s=i.sourceEvent)==null?void 0:s.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=a,((c=i.sourceEvent)==null?void 0:c.type)==="mousedown"&&t(!0),n&&(n==null||n(i.sourceEvent,a))}}function mrt({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:i,onPanZoom:a}){return r=>{var s,c;e.usedRightMouseButton=!!(n&&mse(t,e.mouseButton??0)),(s=r.sourceEvent)!=null&&s.sync||i([r.transform.x,r.transform.y,r.transform.k]),a&&!((c=r.sourceEvent)!=null&&c.internal)&&(a==null||a(r.sourceEvent,GO(r.transform)))}}function yrt({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:i,onPanZoomEnd:a,onPaneContextMenu:r}){return s=>{var c;if(!((c=s.sourceEvent)!=null&&c.internal)&&(e.isZoomingOrPanning=!1,r&&mse(t,e.mouseButton??0)&&!e.usedRightMouseButton&&s.sourceEvent&&r(s.sourceEvent),e.usedRightMouseButton=!1,i(!1),a)){const d=GO(s.transform);e.prevViewport=d,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{a==null||a(s.sourceEvent,d)},n?150:0)}}}function grt({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:i,panOnScroll:a,zoomOnDoubleClick:r,userSelectionActive:s,noWheelClassName:c,noPanClassName:d,lib:h,connectionInProgress:m}){return f=>{var w;const k=e||t,g=n&&f.ctrlKey,b=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(qh(f,`${h}-flow__node`)||qh(f,`${h}-flow__edge`)))return!0;if(!i&&!k&&!a&&!r&&!n||s||m&&!b||qh(f,c)&&b||qh(f,d)&&(!b||a&&b&&!e)||!n&&f.ctrlKey&&b)return!1;if(!n&&f.type==="touchstart"&&((w=f.touches)==null?void 0:w.length)>1)return f.preventDefault(),!1;if(!k&&!a&&!g&&b||!i&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(i)&&!i.includes(f.button)&&f.type==="mousedown")return!1;const v=Array.isArray(i)&&i.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||b)&&v}}function krt({domNode:e,minZoom:t,maxZoom:n,translateExtent:i,viewport:a,onPanZoom:r,onPanZoomStart:s,onPanZoomEnd:c,onDraggingChange:d}){const h={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},m=e.getBoundingClientRect(),f=qoe().scaleExtent([t,n]).translateExtent(i),k=da(e).call(f);C({x:a.x,y:a.y,zoom:Rp(a.zoom,t,n)},[[0,0],[m.width,m.height]],i);const g=k.on("wheel.zoom"),b=k.on("dblclick.zoom");f.wheelDelta(yse);async function v(q,H){return k?new Promise(K=>{f==null||f.interpolate((H==null?void 0:H.interpolate)==="linear"?W0:hD).transform(bq(k,H==null?void 0:H.duration,H==null?void 0:H.ease,()=>K(!0)),q)}):!1}function w({noWheelClassName:q,noPanClassName:H,onPaneContextMenu:K,userSelectionActive:R,panOnScroll:z,panOnDrag:$,panOnScrollMode:X,panOnScrollSpeed:Q,preventScrolling:W,zoomOnPinch:B,zoomOnScroll:V,zoomOnDoubleClick:Y,zoomActivationKeyPressed:F,lib:ae,onTransformChange:xe,connectionInProgress:de,paneClickDistance:Ee,selectionOnDrag:ce}){R&&!h.isZoomingOrPanning&&S();const me=z&&!F&&!R;f.clickDistance(ce?1/0:!rr(Ee)||Ee<0?0:Ee);const je=me?hrt({zoomPanValues:h,noWheelClassName:q,d3Selection:k,d3Zoom:f,panOnScrollMode:X,panOnScrollSpeed:Q,zoomOnPinch:B,onPanZoomStart:s,onPanZoom:r,onPanZoomEnd:c}):prt({noWheelClassName:q,preventScrolling:W,d3ZoomHandler:g});k.on("wheel.zoom",je,{passive:!1});const ie=frt({zoomPanValues:h,onDraggingChange:d,onPanZoomStart:s});f.on("start",ie);const le=mrt({zoomPanValues:h,panOnDrag:$,onPaneContextMenu:!!K,onPanZoom:r,onTransformChange:xe});f.on("zoom",le);const be=yrt({zoomPanValues:h,panOnDrag:$,panOnScroll:z,onPaneContextMenu:K,onPanZoomEnd:c,onDraggingChange:d});f.on("end",be);const pe=grt({zoomActivationKeyPressed:F,panOnDrag:$,zoomOnScroll:V,panOnScroll:z,zoomOnDoubleClick:Y,zoomOnPinch:B,userSelectionActive:R,noPanClassName:H,noWheelClassName:q,lib:ae,connectionInProgress:de});f.filter(pe),Y?k.on("dblclick.zoom",b):k.on("dblclick.zoom",null)}function S(){f.on("zoom",null)}async function C(q,H,K){const R=xq(q),z=f==null?void 0:f.constrain()(R,H,K);return z&&await v(z),z}async function M(q,H){const K=xq(q);return await v(K,H),K}function L(q){if(k){const H=xq(q),K=k.property("__zoom");(K.k!==q.zoom||K.x!==q.x||K.y!==q.y)&&(f==null||f.transform(k,H,null,{sync:!0}))}}function j(){const q=k?$oe(k.node()):{x:0,y:0,k:1};return{x:q.x,y:q.y,zoom:q.k}}async function A(q,H){return k?new Promise(K=>{f==null||f.interpolate((H==null?void 0:H.interpolate)==="linear"?W0:hD).scaleTo(bq(k,H==null?void 0:H.duration,H==null?void 0:H.ease,()=>K(!0)),q)}):!1}async function I(q,H){return k?new Promise(K=>{f==null||f.interpolate((H==null?void 0:H.interpolate)==="linear"?W0:hD).scaleBy(bq(k,H==null?void 0:H.duration,H==null?void 0:H.ease,()=>K(!0)),q)}):!1}function T(q){f==null||f.scaleExtent(q)}function P(q){f==null||f.translateExtent(q)}function D(q){const H=!rr(q)||q<0?0:q;f==null||f.clickDistance(H)}return{update:w,destroy:S,setViewport:M,setViewportConstrained:C,getViewport:j,scaleTo:A,scaleBy:I,setScaleExtent:T,setTranslateExtent:P,syncViewport:L,setClickDistance:D}}var Op;(function(e){e.Line="line",e.Handle="handle"})(Op||(Op={}));function xrt({width:e,prevWidth:t,height:n,prevHeight:i,affectsX:a,affectsY:r}){const s=e-t,c=n-i,d=[s>0?1:s<0?-1:0,c>0?1:c<0?-1:0];return s&&a&&(d[0]=d[0]*-1),c&&r&&(d[1]=d[1]*-1),d}function FZ(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),i=e.includes("left"),a=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:i,affectsY:a}}function hs(e,t){return Math.max(0,t-e)}function ps(e,t){return Math.max(0,e-t)}function qy(e,t,n){return Math.max(0,t-e,e-n)}function VZ(e,t){return e?!t:t}function brt(e,t,n,i,a,r,s,c){let{affectsX:d,affectsY:h}=t;const{isHorizontal:m,isVertical:f}=t,k=m&&f,{xSnapped:g,ySnapped:b}=n,{minWidth:v,maxWidth:w,minHeight:S,maxHeight:C}=i,{x:M,y:L,width:j,height:A,aspectRatio:I}=e;let T=Math.floor(m?g-e.pointerX:0),P=Math.floor(f?b-e.pointerY:0);const D=j+(d?-T:T),q=A+(h?-P:P),H=-r[0]*j,K=-r[1]*A;let R=qy(D,v,w),z=qy(q,S,C);if(s){let Q=0,W=0;d&&T<0?Q=hs(M+T+H,s[0][0]):!d&&T>0&&(Q=ps(M+D+H,s[1][0])),h&&P<0?W=hs(L+P+K,s[0][1]):!h&&P>0&&(W=ps(L+q+K,s[1][1])),R=Math.max(R,Q),z=Math.max(z,W)}if(c){let Q=0,W=0;d&&T>0?Q=ps(M+T,c[0][0]):!d&&T<0&&(Q=hs(M+D,c[1][0])),h&&P>0?W=ps(L+P,c[0][1]):!h&&P<0&&(W=hs(L+q,c[1][1])),R=Math.max(R,Q),z=Math.max(z,W)}if(a){if(m){const Q=qy(D/I,S,C)*I;if(R=Math.max(R,Q),s){let W=0;!d&&!h||d&&!h&&k?W=ps(L+K+D/I,s[1][1])*I:W=hs(L+K+(d?T:-T)/I,s[0][1])*I,R=Math.max(R,W)}if(c){let W=0;!d&&!h||d&&!h&&k?W=hs(L+D/I,c[1][1])*I:W=ps(L+(d?T:-T)/I,c[0][1])*I,R=Math.max(R,W)}}if(f){const Q=qy(q*I,v,w)/I;if(z=Math.max(z,Q),s){let W=0;!d&&!h||h&&!d&&k?W=ps(M+q*I+H,s[1][0])/I:W=hs(M+(h?P:-P)*I+H,s[0][0])/I,z=Math.max(z,W)}if(c){let W=0;!d&&!h||h&&!d&&k?W=hs(M+q*I,c[1][0])/I:W=ps(M+(h?P:-P)*I,c[0][0])/I,z=Math.max(z,W)}}}P=P+(P<0?z:-z),T=T+(T<0?R:-R),a&&(k?D>q*I?P=(VZ(d,h)?-T:T)/I:T=(VZ(d,h)?-P:P)*I:m?(P=T/I,h=d):(T=P*I,d=h));const $=d?M+T:M,X=h?L+P:L;return{width:j+(d?-T:T),height:A+(h?-P:P),x:r[0]*T*(d?-1:1)+$,y:r[1]*P*(h?-1:1)+X}}const gse={width:0,height:0,x:0,y:0},vrt={...gse,pointerX:0,pointerY:0,aspectRatio:1};function wrt(e,t,n){const i=t.position.x+e.position.x,a=t.position.y+e.position.y,r=e.measured.width??0,s=e.measured.height??0,c=n[0]*r,d=n[1]*s;return[[i-c,a-d],[i+r-c,a+s-d]]}function Mrt({domNode:e,nodeId:t,getStoreItems:n,onChange:i,onEnd:a}){const r=da(e);let s={controlDirection:FZ("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function c({controlPosition:h,boundaries:m,keepAspectRatio:f,resizeDirection:k,onResizeStart:g,onResize:b,onResizeEnd:v,shouldResize:w}){let S={...gse},C={...vrt};s={boundaries:m,resizeDirection:k,keepAspectRatio:f,controlDirection:FZ(h)};let M,L=null,j=[],A,I,T,P=!1;const D=Soe().on("start",q=>{const{nodeLookup:H,transform:K,snapGrid:R,snapToGrid:z,nodeOrigin:$,paneDomNode:X}=n();if(M=H.get(t),!M)return;L=(X==null?void 0:X.getBoundingClientRect())??null;const{xSnapped:Q,ySnapped:W}=X0(q.sourceEvent,{transform:K,snapGrid:R,snapToGrid:z,containerBounds:L});S={width:M.measured.width??0,height:M.measured.height??0,x:M.position.x??0,y:M.position.y??0},C={...S,pointerX:Q,pointerY:W,aspectRatio:S.width/S.height},A=void 0,I=R1(M.extent)?M.extent:void 0,M.parentId&&(M.extent==="parent"||M.expandParent)&&(A=H.get(M.parentId)),A&&M.extent==="parent"&&(I=[[0,0],[A.measured.width,A.measured.height]]),j=[],T=void 0;for(const[B,V]of H)if(V.parentId===t&&(j.push({id:B,position:{...V.position},extent:V.extent}),V.extent==="parent"||V.expandParent)){const Y=wrt(V,M,V.origin??$);T?T=[[Math.min(Y[0][0],T[0][0]),Math.min(Y[0][1],T[0][1])],[Math.max(Y[1][0],T[1][0]),Math.max(Y[1][1],T[1][1])]]:T=Y}g==null||g(q,{...S})}).on("drag",q=>{const{transform:H,snapGrid:K,snapToGrid:R,nodeOrigin:z}=n(),$=X0(q.sourceEvent,{transform:H,snapGrid:K,snapToGrid:R,containerBounds:L}),X=[];if(!M)return;const{x:Q,y:W,width:B,height:V}=S,Y={},F=M.origin??z,{width:ae,height:xe,x:de,y:Ee}=brt(C,s.controlDirection,$,s.boundaries,s.keepAspectRatio,F,I,T),ce=ae!==B,me=xe!==V,je=de!==Q&&ce,ie=Ee!==W&&me;if(!je&&!ie&&!ce&&!me)return;if((je||ie||F[0]===1||F[1]===1)&&(Y.x=je?de:S.x,Y.y=ie?Ee:S.y,S.x=Y.x,S.y=Y.y,j.length>0)){const ne=de-Q,we=Ee-W;for(const Be of j)Be.position={x:Be.position.x-ne+F[0]*(ae-B),y:Be.position.y-we+F[1]*(xe-V)},X.push(Be)}if((ce||me)&&(Y.width=ce&&(!s.resizeDirection||s.resizeDirection==="horizontal")?ae:S.width,Y.height=me&&(!s.resizeDirection||s.resizeDirection==="vertical")?xe:S.height,S.width=Y.width,S.height=Y.height),A&&M.expandParent){const ne=F[0]*(Y.width??0);Y.x&&Y.x<ne&&(S.x=ne,C.x=C.x-(Y.x-ne));const we=F[1]*(Y.height??0);Y.y&&Y.y<we&&(S.y=we,C.y=C.y-(Y.y-we))}const le=xrt({width:S.width,prevWidth:B,height:S.height,prevHeight:V,affectsX:s.controlDirection.affectsX,affectsY:s.controlDirection.affectsY}),be={...S,direction:le};(w==null?void 0:w(q,be))!==!1&&(P=!0,b==null||b(q,be),i(Y,X))}).on("end",q=>{P&&(v==null||v(q,{...S}),a==null||a({...S}),P=!1)});r.call(D)}function d(){r.on(".drag",null)}return{update:c,destroy:d}}var vq={exports:{}},wq={},Mq={exports:{}},_q={};/**
8636
8636
  * @license React
@@ -8656,4 +8656,4 @@ description: ...
8656
8656
  `)),m=h.reduce((f,k)=>f.concat(...k),[]);return[h,m]}return[[],[]]},[e]);return E.useEffect(()=>{const d=(t==null?void 0:t.target)??nJ,h=(t==null?void 0:t.actInsideInputWithModifier)??!0;if(e!==null){const m=g=>{var w,S;if(a.current=g.ctrlKey||g.metaKey||g.shiftKey||g.altKey,(!a.current||a.current&&!h)&&ese(g))return!1;const v=aJ(g.code,c);if(r.current.add(g[v]),iJ(s,r.current,!1)){const C=((S=(w=g.composedPath)==null?void 0:w.call(g))==null?void 0:S[0])||g.target,M=(C==null?void 0:C.nodeName)==="BUTTON"||(C==null?void 0:C.nodeName)==="A";t.preventDefault!==!1&&(a.current||!M)&&g.preventDefault(),i(!0)}},f=g=>{const b=aJ(g.code,c);iJ(s,r.current,!0)?(i(!1),r.current.clear()):r.current.delete(g[b]),g.key==="Meta"&&r.current.clear(),a.current=!1},k=()=>{r.current.clear(),i(!1)};return d==null||d.addEventListener("keydown",m),d==null||d.addEventListener("keyup",f),window.addEventListener("blur",k),window.addEventListener("contextmenu",k),()=>{d==null||d.removeEventListener("keydown",m),d==null||d.removeEventListener("keyup",f),window.removeEventListener("blur",k),window.removeEventListener("contextmenu",k)}}},[e,i]),n}function iJ(e,t,n){return e.filter(i=>n||i.length===t.size).some(i=>i.every(a=>t.has(a)))}function aJ(e,t){return t.includes(e)?"code":"key"}const eot=()=>{const e=Nn();return E.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,a,r],panZoom:s}=e.getState();return s?(await s.setViewport({x:t.x??i,y:t.y??a,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:a,minZoom:r,maxZoom:s,panZoom:c}=e.getState(),d=vV(t,i,a,r,s,(n==null?void 0:n.padding)??.1);return c?(await c.setViewport(d,{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:a,snapToGrid:r,domNode:s}=e.getState();if(!s)return t;const{x:c,y:d}=s.getBoundingClientRect(),h={x:t.x-c,y:t.y-d},m=n.snapGrid??a,f=n.snapToGrid??r;return Z2(h,i,f,m)},flowToScreenPosition:t=>{const{transform:n,domNode:i}=e.getState();if(!i)return t;const{x:a,y:r}=i.getBoundingClientRect(),s=Dp(t,n);return{x:s.x+a,y:s.y+r}}}),[])};function Mse(e,t){const n=[],i=new Map,a=[];for(const r of e)if(r.type==="add"){a.push(r);continue}else if(r.type==="remove"||r.type==="replace")i.set(r.id,[r]);else{const s=i.get(r.id);s?s.push(r):i.set(r.id,[r])}for(const r of t){const s=i.get(r.id);if(!s){n.push(r);continue}if(s[0].type==="remove")continue;if(s[0].type==="replace"){n.push({...s[0].item});continue}const c={...r};for(const d of s)tot(d,c);n.push(c)}return a.length&&a.forEach(r=>{r.index!==void 0?n.splice(r.index,0,{...r.item}):n.push({...r.item})}),n}function tot(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 _se(e,t){return Mse(e,t)}function Sse(e,t){return Mse(e,t)}function Xu(e,t){return{id:e,type:"select",selected:t}}function Bh(e,t=new Set,n=!1){const i=[];for(const[a,r]of e){const s=t.has(a);!(r.selected===void 0&&!s)&&r.selected!==s&&(n&&(r.selected=s),i.push(Xu(r.id,s)))}return i}function rJ({items:e=[],lookup:t}){var a;const n=[],i=new Map(e.map(r=>[r.id,r]));for(const[r,s]of e.entries()){const c=t.get(s.id),d=((a=c==null?void 0:c.internals)==null?void 0:a.userNode)??c;d!==void 0&&d!==s&&n.push({id:s.id,item:s,type:"replace"}),d===void 0&&n.push({item:s,type:"add",index:r})}for(const[r]of t)i.get(r)===void 0&&n.push({id:r,type:"remove"});return n}function oJ(e){return{id:e.id,type:"remove"}}const Nse=Yoe();function Ese(e,t,n={}){return Bat(e,t,{...n,onError:n.onError??Nse})}function not(e,t,n,i={shouldReplaceId:!0}){return Hat(e,t,n,{...i,onError:i.onError??Nse})}const sJ=e=>Eat(e),iot=e=>Uoe(e);function Cse(e){return E.forwardRef(e)}const aot=typeof window<"u"?E.useLayoutEffect:E.useEffect;function lJ(e){const[t,n]=E.useState(BigInt(0)),[i]=E.useState(()=>rot(()=>n(a=>a+BigInt(1))));return aot(()=>{const a=i.get();a.length&&(e(a),i.reset())},[t]),i}function rot(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const Lse=E.createContext(null);function oot({children:e}){const t=Nn(),n=E.useCallback(c=>{const{nodes:d=[],setNodes:h,hasDefaultNodes:m,onNodesChange:f,nodeLookup:k,fitViewQueued:g,onNodesChangeMiddlewareMap:b}=t.getState();let v=d;for(const S of c)v=typeof S=="function"?S(v):S;let w=rJ({items:v,lookup:k});for(const S of b.values())w=S(w);m&&h(v),w.length>0?f==null||f(w):g&&window.requestAnimationFrame(()=>{const{fitViewQueued:S,nodes:C,setNodes:M}=t.getState();S&&M(C)})},[]),i=lJ(n),a=E.useCallback(c=>{const{edges:d=[],setEdges:h,hasDefaultEdges:m,onEdgesChange:f,edgeLookup:k}=t.getState();let g=d;for(const b of c)g=typeof b=="function"?b(g):b;m?h(g):f&&f(rJ({items:g,lookup:k}))},[]),r=lJ(a),s=E.useMemo(()=>({nodeQueue:i,edgeQueue:r}),[]);return u.jsx(Lse.Provider,{value:s,children:e})}function sot(){const e=E.useContext(Lse);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const lot=e=>!!e.panZoom;function YO(){const e=eot(),t=Nn(),n=sot(),i=Ht(lot),a=E.useMemo(()=>{const r=f=>t.getState().nodeLookup.get(f),s=f=>{n.nodeQueue.push(f)},c=f=>{n.edgeQueue.push(f)},d=f=>{var S,C;const{nodeLookup:k,nodeOrigin:g}=t.getState(),b=sJ(f)?f:k.get(f.id),v=b.parentId?Zoe(b.position,b.measured,b.parentId,k,g):b.position,w={...b,position:v,width:((S=b.measured)==null?void 0:S.width)??b.width,height:((C=b.measured)==null?void 0:C.height)??b.height};return g2(w)},h=(f,k,g={replace:!1})=>{s(b=>b.map(v=>{if(v.id===f){const w=typeof k=="function"?k(v):k;return g.replace&&sJ(w)?w:{...v,...w}}return v}))},m=(f,k,g={replace:!1})=>{c(b=>b.map(v=>{if(v.id===f){const w=typeof k=="function"?k(v):k;return g.replace&&iot(w)?w:{...v,...w}}return v}))};return{getNodes:()=>t.getState().nodes.map(f=>({...f})),getNode:f=>{var k;return(k=r(f))==null?void 0:k.internals.userNode},getInternalNode:r,getEdges:()=>{const{edges:f=[]}=t.getState();return f.map(k=>({...k}))},getEdge:f=>t.getState().edgeLookup.get(f),setNodes:s,setEdges:c,addNodes:f=>{const k=Array.isArray(f)?f:[f];n.nodeQueue.push(g=>[...g,...k])},addEdges:f=>{const k=Array.isArray(f)?f:[f];n.edgeQueue.push(g=>[...g,...k])},toObject:()=>{const{nodes:f=[],edges:k=[],transform:g}=t.getState(),[b,v,w]=g;return{nodes:f.map(S=>({...S})),edges:k.map(S=>({...S})),viewport:{x:b,y:v,zoom:w}}},deleteElements:async({nodes:f=[],edges:k=[]})=>{const{nodes:g,edges:b,onNodesDelete:v,onEdgesDelete:w,triggerNodeChanges:S,triggerEdgeChanges:C,onDelete:M,onBeforeDelete:L}=t.getState(),{nodes:j,edges:A}=await Iat({nodesToRemove:f,edgesToRemove:k,nodes:g,edges:b,onBeforeDelete:L}),I=A.length>0,T=j.length>0;if(I){const P=A.map(oJ);w==null||w(A),C(P)}if(T){const P=j.map(oJ);v==null||v(j),S(P)}return(T||I)&&(M==null||M({nodes:j,edges:A})),{deletedNodes:j,deletedEdges:A}},getIntersectingNodes:(f,k=!0,g)=>{const b=IZ(f),v=b?f:d(f),w=g!==void 0;return v?(g||t.getState().nodes).filter(S=>{const C=t.getState().nodeLookup.get(S.id);if(C&&!b&&(S.id===f.id||!C.internals.positionAbsolute))return!1;const M=g2(w?S:C),L=iO(M,v);return k&&L>0||L>=M.width*M.height||L>=v.width*v.height}):[]},isNodeIntersecting:(f,k,g=!0)=>{const v=IZ(f)?f:d(f);if(!v)return!1;const w=iO(v,k);return g&&w>0||w>=k.width*k.height||w>=v.width*v.height},updateNode:h,updateNodeData:(f,k,g={replace:!1})=>{h(f,b=>{const v=typeof k=="function"?k(b):k;return g.replace?{...b,data:v}:{...b,data:{...b.data,...v}}},g)},updateEdge:m,updateEdgeData:(f,k,g={replace:!1})=>{m(f,b=>{const v=typeof k=="function"?k(b):k;return g.replace?{...b,data:v}:{...b,data:{...b.data,...v}}},g)},getNodesBounds:f=>{const{nodeLookup:k,nodeOrigin:g}=t.getState();return Cat(f,{nodeLookup:k,nodeOrigin:g})},getHandleConnections:({type:f,id:k,nodeId:g})=>{var b;return Array.from(((b=t.getState().connectionLookup.get(`${g}-${f}${k?`-${k}`:""}`))==null?void 0:b.values())??[])},getNodeConnections:({type:f,handleId:k,nodeId:g})=>{var b;return Array.from(((b=t.getState().connectionLookup.get(`${g}${f?k?`-${f}-${k}`:`-${f}`:""}`))==null?void 0:b.values())??[])},fitView:async f=>{const k=t.getState().fitViewResolver??Dat();return t.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:k}),n.nodeQueue.push(g=>[...g]),k.promise}}},[]);return E.useMemo(()=>({...a,...e,viewportInitialized:i}),[i])}const cJ=e=>e.selected,cot=typeof window<"u"?window:void 0;function dot({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=Nn(),{deleteElements:i}=YO(),a=x2(e,{actInsideInputWithModifier:!1}),r=x2(t,{target:cot});E.useEffect(()=>{if(a){const{edges:s,nodes:c}=n.getState();i({nodes:c.filter(cJ),edges:s.filter(cJ)}),n.setState({nodesSelectionActive:!1})}},[a]),E.useEffect(()=>{n.setState({multiSelectionActive:r})},[r])}function uot(e){const t=Nn();E.useEffect(()=>{const n=()=>{var a,r,s,c;if(!e.current||!(((r=(a=e.current).checkVisibility)==null?void 0:r.call(a))??!0))return!1;const i=wV(e.current);(i.height===0||i.width===0)&&((c=(s=t.getState()).onError)==null||c.call(s,"004",fa.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 QO={position:"absolute",width:"100%",height:"100%",top:0,left:0},hot=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function pot({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:i=!1,panOnScrollSpeed:a=.5,panOnScrollMode:r=N1.Free,zoomOnDoubleClick:s=!0,panOnDrag:c=!0,defaultViewport:d,translateExtent:h,minZoom:m,maxZoom:f,zoomActivationKeyCode:k,preventScrolling:g=!0,children:b,noWheelClassName:v,noPanClassName:w,onViewportChange:S,isControlledViewport:C,paneClickDistance:M,selectionOnDrag:L}){const j=Nn(),A=E.useRef(null),{userSelectionActive:I,lib:T,connectionInProgress:P}=Ht(hot,Sn),D=x2(k),q=E.useRef();uot(A);const H=E.useCallback(K=>{S==null||S({x:K[0],y:K[1],zoom:K[2]}),C||j.setState({transform:K})},[S,C]);return E.useEffect(()=>{if(A.current){q.current=krt({domNode:A.current,minZoom:m,maxZoom:f,translateExtent:h,viewport:d,onDraggingChange:$=>j.setState(X=>X.paneDragging===$?X:{paneDragging:$}),onPanZoomStart:($,X)=>{const{onViewportChangeStart:Q,onMoveStart:W}=j.getState();W==null||W($,X),Q==null||Q(X)},onPanZoom:($,X)=>{const{onViewportChange:Q,onMove:W}=j.getState();W==null||W($,X),Q==null||Q(X)},onPanZoomEnd:($,X)=>{const{onViewportChangeEnd:Q,onMoveEnd:W}=j.getState();W==null||W($,X),Q==null||Q(X)}});const{x:K,y:R,zoom:z}=q.current.getViewport();return j.setState({panZoom:q.current,transform:[K,R,z],domNode:A.current.closest(".react-flow")}),()=>{var $;($=q.current)==null||$.destroy()}}},[]),E.useEffect(()=>{var K;(K=q.current)==null||K.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:i,panOnScrollSpeed:a,panOnScrollMode:r,zoomOnDoubleClick:s,panOnDrag:c,zoomActivationKeyPressed:D,preventScrolling:g,noPanClassName:w,userSelectionActive:I,noWheelClassName:v,lib:T,onTransformChange:H,connectionInProgress:P,selectionOnDrag:L,paneClickDistance:M})},[e,t,n,i,a,r,s,c,D,g,w,I,v,T,H,P,L,M]),u.jsx("div",{className:"react-flow__renderer",ref:A,style:QO,children:b})}const fot=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function mot(){const{userSelectionActive:e,userSelectionRect:t}=Ht(fot,Sn);return e&&t?u.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 Sq=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},yot=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function got({isSelecting:e,selectionKeyPressed:t,selectionMode:n=y2.Full,panOnDrag:i,autoPanOnSelection:a,paneClickDistance:r,selectionOnDrag:s,onSelectionStart:c,onSelectionEnd:d,onPaneClick:h,onPaneContextMenu:m,onPaneScroll:f,onPaneMouseEnter:k,onPaneMouseMove:g,onPaneMouseLeave:b,children:v}){const w=E.useRef(0),S=Nn(),{userSelectionActive:C,elementsSelectable:M,dragging:L,panBy:j,autoPanSpeed:A}=Ht(yot,Sn),I=M&&(e||C),T=E.useRef(null),P=E.useRef(),D=E.useRef(new Set),q=E.useRef(new Set),H=E.useRef(!1),K=E.useRef(!1),R=E.useRef({x:0,y:0}),z=E.useRef(!1),$=ce=>{if(K.current||H.current||S.getState().connection.inProgress){K.current=!1,H.current=!1;return}h==null||h(ce),S.getState().resetSelectedElements(),S.setState({nodesSelectionActive:!1})},X=ce=>{if(Array.isArray(i)&&(i!=null&&i.includes(2))){ce.preventDefault();return}m==null||m(ce)},Q=f?ce=>f(ce):void 0,W=ce=>{K.current&&(ce.stopPropagation(),K.current=!1)},B=ce=>{var Be,Oe;const{domNode:me,transform:je}=S.getState();if(P.current=me==null?void 0:me.getBoundingClientRect(),!P.current)return;const ie=ce.target===T.current;if(!ie&&!!ce.target.closest(".nokey")||!e||!(s&&ie||t)||ce.button!==0||!ce.isPrimary)return;(Oe=(Be=ce.target)==null?void 0:Be.setPointerCapture)==null||Oe.call(Be,ce.pointerId),K.current=!1;const{x:pe,y:ne}=or(ce.nativeEvent,P.current),we=Z2({x:pe,y:ne},je);S.setState({userSelectionRect:{width:0,height:0,startX:we.x,startY:we.y,x:pe,y:ne}}),ie||(ce.stopPropagation(),ce.preventDefault())};function V(ce,me){const{userSelectionRect:je}=S.getState();if(!je)return;const{transform:ie,nodeLookup:le,edgeLookup:be,connectionLookup:pe,triggerNodeChanges:ne,triggerEdgeChanges:we,defaultEdgeOptions:Be}=S.getState(),Oe={x:je.startX,y:je.startY},{x:ft,y:it}=Dp(Oe,ie),jt={startX:Oe.x,startY:Oe.y,x:ce<ft?ce:ft,y:me<it?me:it,width:Math.abs(ce-ft),height:Math.abs(me-it)},St=D.current,yt=q.current;D.current=new Set(xV(le,jt,ie,n===y2.Partial,!0).map(Xe=>Xe.id)),q.current=new Set;const Te=(Be==null?void 0:Be.selectable)??!0;for(const Xe of D.current){const re=pe.get(Xe);if(re)for(const{edgeId:_e}of re.values()){const Re=be.get(_e);Re&&(Re.selectable??Te)&&q.current.add(_e)}}if(!TZ(St,D.current)){const Xe=Bh(le,D.current,!0);ne(Xe)}if(!TZ(yt,q.current)){const Xe=Bh(be,q.current);we(Xe)}S.setState({userSelectionRect:jt,userSelectionActive:!0,nodesSelectionActive:!1})}function Y(){if(!a||!P.current)return;const[ce,me]=bV(R.current,P.current,A);j({x:ce,y:me}).then(je=>{if(!K.current||!je){w.current=requestAnimationFrame(Y);return}const{x:ie,y:le}=R.current;V(ie,le),w.current=requestAnimationFrame(Y)})}const F=()=>{cancelAnimationFrame(w.current),w.current=0,z.current=!1};E.useEffect(()=>()=>F(),[]);const ae=ce=>{const{userSelectionRect:me,transform:je,resetSelectedElements:ie}=S.getState();if(!P.current||!me)return;const{x:le,y:be}=or(ce.nativeEvent,P.current);R.current={x:le,y:be};const pe=Dp({x:me.startX,y:me.startY},je);if(!K.current){const ne=t?0:r;if(Math.hypot(le-pe.x,be-pe.y)<=ne)return;ie(),c==null||c(ce)}K.current=!0,z.current||(Y(),z.current=!0),V(le,be)},xe=ce=>{var me,je;if(!I){ce.target===T.current&&S.getState().connection.inProgress&&(H.current=!0);return}ce.button===0&&((je=(me=ce.target)==null?void 0:me.releasePointerCapture)==null||je.call(me,ce.pointerId),!C&&ce.target===T.current&&S.getState().userSelectionRect&&($==null||$(ce)),S.setState({userSelectionActive:!1,userSelectionRect:null}),K.current&&(d==null||d(ce),S.setState({nodesSelectionActive:D.current.size>0})),F())},de=ce=>{var me,je;(je=(me=ce.target)==null?void 0:me.releasePointerCapture)==null||je.call(me,ce.pointerId),F()},Ee=i===!0||Array.isArray(i)&&i.includes(0);return u.jsxs("div",{className:Xn(["react-flow__pane",{draggable:Ee,dragging:L,selection:e}]),onClick:I?void 0:Sq($,T),onContextMenu:Sq(X,T),onWheel:Sq(Q,T),onPointerEnter:I?void 0:k,onPointerMove:I?ae:g,onPointerUp:xe,onPointerCancel:I?de:void 0,onPointerDownCapture:I?B:void 0,onClickCapture:I?W:void 0,onPointerLeave:b,ref:T,style:QO,children:[v,u.jsx(mot,{})]})}function vH({id:e,store:t,unselect:n=!1,nodeRef:i}){const{addSelectedNodes:a,unselectNodesAndEdges:r,multiSelectionActive:s,nodeLookup:c,onError:d}=t.getState(),h=c.get(e);if(!h){d==null||d("012",fa.error012(e));return}t.setState({nodesSelectionActive:!1}),h.selected?(n||h.selected&&s)&&(r({nodes:[h],edges:[]}),requestAnimationFrame(()=>{var m;return(m=i==null?void 0:i.current)==null?void 0:m.blur()})):a([e])}function jse({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:i,nodeId:a,isSelectable:r,nodeClickDistance:s}){const c=Nn(),[d,h]=E.useState(!1),m=E.useRef();return E.useEffect(()=>{m.current=art({getStoreItems:()=>c.getState(),onNodeMouseDown:f=>{vH({id:f,store:c,nodeRef:e})},onDragStart:()=>{h(!0)},onDragStop:()=>{h(!1)}})},[]),E.useEffect(()=>{if(!(t||!e.current||!m.current))return m.current.update({noDragClassName:n,handleSelector:i,domNode:e.current,isSelectable:r,nodeId:a,nodeClickDistance:s}),()=>{var f;(f=m.current)==null||f.destroy()}},[n,i,t,r,e,a,s]),d}const kot=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function Ase(){const e=Nn();return E.useCallback(n=>{const{nodeExtent:i,snapToGrid:a,snapGrid:r,nodesDraggable:s,onError:c,updateNodePositions:d,nodeLookup:h,nodeOrigin:m}=e.getState(),f=new Map,k=kot(s),g=a?r[0]:5,b=a?r[1]:5,v=n.direction.x*g*n.factor,w=n.direction.y*b*n.factor;for(const[,S]of h){if(!k(S))continue;let C={x:S.internals.positionAbsolute.x+v,y:S.internals.positionAbsolute.y+w};a&&(C=Q2(C,r));const{position:M,positionAbsolute:L}=Koe({nodeId:S.id,nextPosition:C,nodeLookup:h,nodeExtent:i,nodeOrigin:m,onError:c});S.position=M,S.internals.positionAbsolute=L,f.set(S.id,S)}d(f)},[])}const CV=E.createContext(null),xot=CV.Provider;CV.Consumer;const Ise=()=>E.useContext(CV),bot=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),Tse=E.createContext(null);function vot({children:e}){const t=Ht(bot,Sn);return u.jsx(Tse.Provider,{value:t,children:e})}function wot(){const e=E.useContext(Tse);if(!e)throw new Error("useHandleConfig must be used within a HandleConfigProvider");return e}const Mot={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},_ot=(e,t,n)=>i=>{const{connectionClickStartHandle:a,connectionMode:r,connection:s}=i,{fromHandle:c,toHandle:d,isValid:h}=s;if(!c&&!a)return Mot;const m=(d==null?void 0:d.nodeId)===e&&(d==null?void 0:d.id)===t&&(d==null?void 0:d.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:m,clickConnecting:(a==null?void 0:a.nodeId)===e&&(a==null?void 0:a.id)===t&&(a==null?void 0:a.type)===n,isPossibleEndHandle:r===Tp.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:!!a,valid:m&&h}};function Sot({type:e="source",position:t=tt.Top,isValidConnection:n,isConnectable:i=!0,isConnectableStart:a=!0,isConnectableEnd:r=!0,id:s,onConnect:c,children:d,className:h,onMouseDown:m,onTouchStart:f,...k},g){var z,$;const b=s||null,v=e==="target",w=Nn(),S=Ise(),{connectOnClick:C,noPanClassName:M,rfId:L}=wot(),{connectingFrom:j,connectingTo:A,clickConnecting:I,isPossibleEndHandle:T,connectionInProcess:P,clickConnectionInProcess:D,valid:q}=Ht(_ot(S,b,e),Sn);S||($=(z=w.getState()).onError)==null||$.call(z,"010",fa.error010());const H=X=>{const{defaultEdgeOptions:Q,onConnect:W,hasDefaultEdges:B}=w.getState(),V={...Q,...X};if(B){const{edges:Y,setEdges:F,onError:ae}=w.getState();F(Ese(V,Y,{onError:ae}))}W==null||W(V),c==null||c(V)},K=X=>{if(!S)return;const Q=tse(X.nativeEvent);if(a&&(Q&&X.button===0||!Q)){const W=w.getState();bH.onPointerDown(X.nativeEvent,{handleDomNode:X.currentTarget,autoPanOnConnect:W.autoPanOnConnect,connectionMode:W.connectionMode,connectionRadius:W.connectionRadius,domNode:W.domNode,nodeLookup:W.nodeLookup,lib:W.lib,isTarget:v,handleId:b,nodeId:S,flowId:W.rfId,panBy:W.panBy,cancelConnection:W.cancelConnection,onConnectStart:W.onConnectStart,onConnectEnd:(...B)=>{var V,Y;return(Y=(V=w.getState()).onConnectEnd)==null?void 0:Y.call(V,...B)},updateConnection:W.updateConnection,onConnect:H,isValidConnection:n||((...B)=>{var V,Y;return((Y=(V=w.getState()).isValidConnection)==null?void 0:Y.call(V,...B))??!0}),getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,autoPanSpeed:W.autoPanSpeed,dragThreshold:W.connectionDragThreshold})}Q?m==null||m(X):f==null||f(X)},R=X=>{const{onClickConnectStart:Q,onClickConnectEnd:W,connectionClickStartHandle:B,connectionMode:V,isValidConnection:Y,lib:F,rfId:ae,nodeLookup:xe,connection:de}=w.getState();if(!S||!B&&!a)return;if(!B){Q==null||Q(X.nativeEvent,{nodeId:S,handleId:b,handleType:e}),w.setState({connectionClickStartHandle:{nodeId:S,type:e,id:b}});return}const Ee=Joe(X.target),ce=n||Y,{connection:me,isValid:je}=bH.isValid(X.nativeEvent,{handle:{nodeId:S,id:b,type:e},connectionMode:V,fromNodeId:B.nodeId,fromHandleId:B.id||null,fromType:B.type,isValidConnection:ce,flowId:ae,doc:Ee,lib:F,nodeLookup:xe});je&&me&&H(me);const ie=structuredClone(de);delete ie.inProgress,ie.toPosition=ie.toHandle?ie.toHandle.position:null,W==null||W(X,ie),w.setState({connectionClickStartHandle:null})};return u.jsx("div",{"data-handleid":b,"data-nodeid":S,"data-handlepos":t,"data-id":`${L}-${S}-${b}-${e}`,className:Xn(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",M,h,{source:!v,target:v,connectable:i,connectablestart:a,connectableend:r,clickconnecting:I,connectingfrom:j,connectingto:A,valid:q,connectionindicator:i&&(!P||T)&&(P||D?r:a)}]),onMouseDown:K,onTouchStart:K,onClick:C?R:void 0,ref:g,...k,children:d})}const Rs=E.memo(Cse(Sot));function Not({data:e,isConnectable:t,sourcePosition:n=tt.Bottom}){return u.jsxs(u.Fragment,{children:[e==null?void 0:e.label,u.jsx(Rs,{type:"source",position:n,isConnectable:t})]})}function Eot({data:e,isConnectable:t,targetPosition:n=tt.Top,sourcePosition:i=tt.Bottom}){return u.jsxs(u.Fragment,{children:[u.jsx(Rs,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,u.jsx(Rs,{type:"source",position:i,isConnectable:t})]})}function Cot(){return null}function Lot({data:e,isConnectable:t,targetPosition:n=tt.Top}){return u.jsxs(u.Fragment,{children:[u.jsx(Rs,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label]})}const aO={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},dJ={input:Not,default:Eot,output:Lot,group:Cot};function jot(e){var t,n,i,a;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??((a=e.style)==null?void 0:a.height)}}const Aot=e=>{const{width:t,height:n,x:i,y:a}=Y2(e.nodeLookup,{filter:r=>!!r.selected});return{width:rr(t)?t:null,height:rr(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${i}px,${a}px)`}};function Iot({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const i=Nn(),{width:a,height:r,transformString:s,userSelectionActive:c}=Ht(Aot,Sn),d=Ase(),h=E.useRef(null);E.useEffect(()=>{var g;n||(g=h.current)==null||g.focus({preventScroll:!0})},[n]);const m=!c&&a!==null&&r!==null;if(jse({nodeRef:h,disabled:!m}),!m)return null;const f=e?g=>{const b=i.getState().nodes.filter(v=>v.selected);e(g,b)}:void 0,k=g=>{Object.prototype.hasOwnProperty.call(aO,g.key)&&(g.preventDefault(),d({direction:aO[g.key],factor:g.shiftKey?4:1}))};return u.jsx("div",{className:Xn(["react-flow__nodesselection","react-flow__container",t]),style:{transform:s},children:u.jsx("div",{ref:h,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:n?void 0:-1,onKeyDown:n?void 0:k,style:{width:a,height:r}})})}const uJ=typeof window<"u"?window:void 0,Tot=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Rse({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:a,onPaneContextMenu:r,onPaneScroll:s,paneClickDistance:c,deleteKeyCode:d,selectionKeyCode:h,selectionOnDrag:m,selectionMode:f,onSelectionStart:k,onSelectionEnd:g,multiSelectionKeyCode:b,panActivationKeyCode:v,zoomActivationKeyCode:w,elementsSelectable:S,zoomOnScroll:C,zoomOnPinch:M,panOnScroll:L,panOnScrollSpeed:j,panOnScrollMode:A,zoomOnDoubleClick:I,panOnDrag:T,autoPanOnSelection:P,defaultViewport:D,translateExtent:q,minZoom:H,maxZoom:K,preventScrolling:R,onSelectionContextMenu:z,noWheelClassName:$,noPanClassName:X,disableKeyboardA11y:Q,onViewportChange:W,isControlledViewport:B}){const{nodesSelectionActive:V,userSelectionActive:Y}=Ht(Tot,Sn),F=x2(h,{target:uJ}),ae=x2(v,{target:uJ}),xe=ae||T,de=ae||L,Ee=m&&xe!==!0,ce=F||Y||Ee;return dot({deleteKeyCode:d,multiSelectionKeyCode:b}),u.jsx(pot,{onPaneContextMenu:r,elementsSelectable:S,zoomOnScroll:C,zoomOnPinch:M,panOnScroll:de,panOnScrollSpeed:j,panOnScrollMode:A,zoomOnDoubleClick:I,panOnDrag:!F&&xe,defaultViewport:D,translateExtent:q,minZoom:H,maxZoom:K,zoomActivationKeyCode:w,preventScrolling:R,noWheelClassName:$,noPanClassName:X,onViewportChange:W,isControlledViewport:B,paneClickDistance:c,selectionOnDrag:Ee,children:u.jsxs(got,{onSelectionStart:k,onSelectionEnd:g,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:i,onPaneMouseLeave:a,onPaneContextMenu:r,onPaneScroll:s,panOnDrag:xe,autoPanOnSelection:P,isSelecting:!!ce,selectionMode:f,selectionKeyPressed:F,paneClickDistance:c,selectionOnDrag:Ee,children:[e,V&&u.jsx(Iot,{onSelectionContextMenu:z,noPanClassName:X,disableKeyboardA11y:Q})]})})}Rse.displayName="FlowRenderer";const Rot=E.memo(Rse),Dot=e=>t=>e?xV(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 Oot(e){return Ht(E.useCallback(Dot(e),[e]),Sn)}const zot=e=>e.updateNodeInternals;function Pot(){const e=Ht(zot),[t]=E.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const i=new Map;n.forEach(a=>{const r=a.target.getAttribute("data-id");i.set(r,{id:r,nodeElement:a.target,force:!0})}),e(i)}));return E.useEffect(()=>()=>{t==null||t.disconnect()},[t]),t}function $ot({node:e,nodeType:t,hasDimensions:n,resizeObserver:i}){const a=Nn(),r=E.useRef(null),s=E.useRef(null),c=E.useRef(e.sourcePosition),d=E.useRef(e.targetPosition),h=E.useRef(t),m=n&&!!e.internals.handleBounds;return E.useEffect(()=>{r.current&&!e.hidden&&(!m||s.current!==r.current)&&(s.current&&(i==null||i.unobserve(s.current)),i==null||i.observe(r.current),s.current=r.current)},[m,e.hidden]),E.useEffect(()=>()=>{s.current&&(i==null||i.unobserve(s.current),s.current=null)},[]),E.useEffect(()=>{if(r.current){const f=h.current!==t,k=c.current!==e.sourcePosition,g=d.current!==e.targetPosition;(f||k||g)&&(h.current=t,c.current=e.sourcePosition,d.current=e.targetPosition,a.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:r.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),r}function qot({id:e,onClick:t,onMouseEnter:n,onMouseMove:i,onMouseLeave:a,onContextMenu:r,onDoubleClick:s,nodesDraggable:c,elementsSelectable:d,nodesConnectable:h,nodesFocusable:m,resizeObserver:f,noDragClassName:k,noPanClassName:g,disableKeyboardA11y:b,rfId:v,nodeTypes:w,nodeClickDistance:S,onError:C}){const{node:M,internals:L,isParent:j}=Ht(ce=>{const me=ce.nodeLookup.get(e),je=ce.parentLookup.has(e);return{node:me,internals:me.internals,isParent:je}},Sn);let A=M.type||"default",I=(w==null?void 0:w[A])||dJ[A];I===void 0&&(C==null||C("003",fa.error003(A)),A="default",I=(w==null?void 0:w.default)||dJ.default);const T=!!(M.draggable||c&&typeof M.draggable>"u"),P=!!(M.selectable||d&&typeof M.selectable>"u"),D=!!(M.connectable||h&&typeof M.connectable>"u"),q=!!(M.focusable||m&&typeof M.focusable>"u"),H=Nn(),K=Qoe(M),R=$ot({node:M,nodeType:A,hasDimensions:K,resizeObserver:f}),z=jse({nodeRef:R,disabled:M.hidden||!T,noDragClassName:k,handleSelector:M.dragHandle,nodeId:e,isSelectable:P,nodeClickDistance:S}),$=Ase();if(M.hidden)return null;const X=qo(M),Q=jot(M),W=P||T||t||n||i||a,B=n?ce=>n(ce,{...L.userNode}):void 0,V=i?ce=>i(ce,{...L.userNode}):void 0,Y=a?ce=>a(ce,{...L.userNode}):void 0,F=r?ce=>r(ce,{...L.userNode}):void 0,ae=s?ce=>s(ce,{...L.userNode}):void 0,xe=ce=>{const{selectNodesOnDrag:me,nodeDragThreshold:je}=H.getState();P&&(!me||!T||je>0)&&vH({id:e,store:H,nodeRef:R}),t&&t(ce,{...L.userNode})},de=ce=>{if(!(ese(ce.nativeEvent)||b)){if(Boe.includes(ce.key)&&P){const me=ce.key==="Escape";vH({id:e,store:H,unselect:me,nodeRef:R})}else if(T&&M.selected&&Object.prototype.hasOwnProperty.call(aO,ce.key)){ce.preventDefault();const{ariaLabelConfig:me}=H.getState();H.setState({ariaLiveMessage:me["node.a11yDescription.ariaLiveMessage"]({direction:ce.key.replace("Arrow","").toLowerCase(),x:~~L.positionAbsolute.x,y:~~L.positionAbsolute.y})}),$({direction:aO[ce.key],factor:ce.shiftKey?4:1})}}},Ee=()=>{var pe;if(b||!((pe=R.current)!=null&&pe.matches(":focus-visible")))return;const{transform:ce,width:me,height:je,autoPanOnNodeFocus:ie,setCenter:le}=H.getState();if(!ie)return;xV(new Map([[e,M]]),{x:0,y:0,width:me,height:je},ce,!0).length>0||le(M.position.x+X.width/2,M.position.y+X.height/2,{zoom:ce[2]})};return u.jsx("div",{className:Xn(["react-flow__node",`react-flow__node-${A}`,{[g]:T},M.className,{selected:M.selected,selectable:P,parent:j,draggable:T,dragging:z}]),ref:R,style:{zIndex:L.z,transform:`translate(${L.positionAbsolute.x}px,${L.positionAbsolute.y}px)`,pointerEvents:W?"all":"none",visibility:K?"visible":"hidden",...M.style,...Q},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:B,onMouseMove:V,onMouseLeave:Y,onContextMenu:F,onClick:xe,onDoubleClick:ae,onKeyDown:q?de:void 0,tabIndex:q?0:void 0,onFocus:q?Ee:void 0,role:M.ariaRole??(q?"group":void 0),"aria-roledescription":"node","aria-describedby":b?void 0:`${bse}-${v}`,"aria-label":M.ariaLabel,...M.domAttributes,children:u.jsx(xot,{value:e,children:u.jsx(I,{id:e,data:M.data,type:A,positionAbsoluteX:L.positionAbsolute.x,positionAbsoluteY:L.positionAbsolute.y,selected:M.selected??!1,selectable:P,draggable:T,deletable:M.deletable??!0,isConnectable:D,sourcePosition:M.sourcePosition,targetPosition:M.targetPosition,dragging:z,dragHandle:M.dragHandle,zIndex:L.z,parentId:M.parentId,...X})})})}var Bot=E.memo(qot);const Hot=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Dse(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:i,elementsSelectable:a,onError:r}=Ht(Hot,Sn),s=Oot(e.onlyRenderVisibleElements),c=Pot();return u.jsx("div",{className:"react-flow__nodes",style:QO,children:s.map(d=>u.jsx(Bot,{id:d,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:c,nodesDraggable:t,nodesConnectable:n,nodesFocusable:i,elementsSelectable:a,nodeClickDistance:e.nodeClickDistance,onError:r},d))})}Dse.displayName="NodeRenderer";const Fot=E.memo(Dse);function Vot(e){return Ht(E.useCallback(n=>{if(!e)return n.edges.map(a=>a.id);const i=[];if(n.width&&n.height)for(const a of n.edges){const r=n.nodeLookup.get(a.source),s=n.nodeLookup.get(a.target);r&&s&&$at({sourceNode:r,targetNode:s,width:n.width,height:n.height,transform:n.transform})&&i.push(a.id)}return i},[e]),Sn)}const Uot=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return u.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},Kot=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return u.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},hJ={[tO.Arrow]:Uot,[tO.ArrowClosed]:Kot};function Got(e){const t=Nn();return E.useMemo(()=>{var a,r;return Object.prototype.hasOwnProperty.call(hJ,e)?hJ[e]:((r=(a=t.getState()).onError)==null||r.call(a,"009",fa.error009(e)),null)},[e])}const Wot=({id:e,type:t,color:n,width:i=12.5,height:a=12.5,markerUnits:r="strokeWidth",strokeWidth:s,orient:c="auto-start-reverse"})=>{const d=Got(t);return d?u.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${i}`,markerHeight:`${a}`,viewBox:"-10 -10 20 20",markerUnits:r,orient:c,refX:"0",refY:"0",children:u.jsx(d,{color:n,strokeWidth:s})}):null},Ose=({defaultColor:e,rfId:t})=>{const n=Ht(r=>r.edges),i=Ht(r=>r.defaultEdgeOptions),a=E.useMemo(()=>Gat(n,{id:t,defaultColor:e,defaultMarkerStart:i==null?void 0:i.markerStart,defaultMarkerEnd:i==null?void 0:i.markerEnd}),[n,i,t,e]);return a.length?u.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:u.jsx("defs",{children:a.map(r=>u.jsx(Wot,{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};Ose.displayName="MarkerDefinitions";var Xot=E.memo(Ose);function zse({x:e,y:t,label:n,labelStyle:i,labelShowBg:a=!0,labelBgStyle:r,labelBgPadding:s=[2,4],labelBgBorderRadius:c=2,children:d,className:h,...m}){const[f,k]=E.useState({x:1,y:0,width:0,height:0}),g=Xn(["react-flow__edge-textwrapper",h]),b=E.useRef(null);return E.useEffect(()=>{if(b.current){const v=b.current.getBBox();k({x:v.x,y:v.y,width:v.width,height:v.height})}},[n]),n?u.jsxs("g",{transform:`translate(${e-f.width/2} ${t-f.height/2})`,className:g,visibility:f.width?"visible":"hidden",...m,children:[a&&u.jsx("rect",{width:f.width+2*s[0],x:-s[0],y:-s[1],height:f.height+2*s[1],className:"react-flow__edge-textbg",style:r,rx:c,ry:c}),u.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:b,style:i,children:n}),d]}):null}zse.displayName="EdgeText";const Yot=E.memo(zse);function ZO({path:e,labelX:t,labelY:n,label:i,labelStyle:a,labelShowBg:r,labelBgStyle:s,labelBgPadding:c,labelBgBorderRadius:d,interactionWidth:h=20,...m}){return u.jsxs(u.Fragment,{children:[u.jsx("path",{...m,d:e,fill:"none",className:Xn(["react-flow__edge-path",m.className])}),h?u.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:h,className:"react-flow__edge-interaction"}):null,i&&rr(t)&&rr(n)?u.jsx(Yot,{x:t,y:n,label:i,labelStyle:a,labelShowBg:r,labelBgStyle:s,labelBgPadding:c,labelBgBorderRadius:d}):null]})}function pJ({pos:e,x1:t,y1:n,x2:i,y2:a}){return e===tt.Left||e===tt.Right?[.5*(t+i),n]:[t,.5*(n+a)]}function Pse({sourceX:e,sourceY:t,sourcePosition:n=tt.Bottom,targetX:i,targetY:a,targetPosition:r=tt.Top}){const[s,c]=pJ({pos:n,x1:e,y1:t,x2:i,y2:a}),[d,h]=pJ({pos:r,x1:i,y1:a,x2:e,y2:t}),[m,f,k,g]=nse({sourceX:e,sourceY:t,targetX:i,targetY:a,sourceControlX:s,sourceControlY:c,targetControlX:d,targetControlY:h});return[`M${e},${t} C${s},${c} ${d},${h} ${i},${a}`,m,f,k,g]}function $se(e){return E.memo(({id:t,sourceX:n,sourceY:i,targetX:a,targetY:r,sourcePosition:s,targetPosition:c,label:d,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:k,labelBgBorderRadius:g,style:b,markerEnd:v,markerStart:w,interactionWidth:S})=>{const[C,M,L]=Pse({sourceX:n,sourceY:i,sourcePosition:s,targetX:a,targetY:r,targetPosition:c}),j=e.isInternal?void 0:t;return u.jsx(ZO,{id:j,path:C,labelX:M,labelY:L,label:d,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:k,labelBgBorderRadius:g,style:b,markerEnd:v,markerStart:w,interactionWidth:S})})}const Qot=$se({isInternal:!1}),qse=$se({isInternal:!0});Qot.displayName="SimpleBezierEdge";qse.displayName="SimpleBezierEdgeInternal";function Bse(e){return E.memo(({id:t,sourceX:n,sourceY:i,targetX:a,targetY:r,label:s,labelStyle:c,labelShowBg:d,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:f,style:k,sourcePosition:g=tt.Bottom,targetPosition:b=tt.Top,markerEnd:v,markerStart:w,pathOptions:S,interactionWidth:C})=>{const[M,L,j]=gH({sourceX:n,sourceY:i,sourcePosition:g,targetX:a,targetY:r,targetPosition:b,borderRadius:S==null?void 0:S.borderRadius,offset:S==null?void 0:S.offset,stepPosition:S==null?void 0:S.stepPosition}),A=e.isInternal?void 0:t;return u.jsx(ZO,{id:A,path:M,labelX:L,labelY:j,label:s,labelStyle:c,labelShowBg:d,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:f,style:k,markerEnd:v,markerStart:w,interactionWidth:C})})}const Hse=Bse({isInternal:!1}),Fse=Bse({isInternal:!0});Hse.displayName="SmoothStepEdge";Fse.displayName="SmoothStepEdgeInternal";function Vse(e){return E.memo(({id:t,...n})=>{var a;const i=e.isInternal?void 0:t;return u.jsx(Hse,{...n,id:i,pathOptions:E.useMemo(()=>{var r;return{borderRadius:0,offset:(r=n.pathOptions)==null?void 0:r.offset}},[(a=n.pathOptions)==null?void 0:a.offset])})})}const Zot=Vse({isInternal:!1}),Use=Vse({isInternal:!0});Zot.displayName="StepEdge";Use.displayName="StepEdgeInternal";function Kse(e){return E.memo(({id:t,sourceX:n,sourceY:i,targetX:a,targetY:r,label:s,labelStyle:c,labelShowBg:d,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:f,style:k,markerEnd:g,markerStart:b,interactionWidth:v})=>{const[w,S,C]=ose({sourceX:n,sourceY:i,targetX:a,targetY:r}),M=e.isInternal?void 0:t;return u.jsx(ZO,{id:M,path:w,labelX:S,labelY:C,label:s,labelStyle:c,labelShowBg:d,labelBgStyle:h,labelBgPadding:m,labelBgBorderRadius:f,style:k,markerEnd:g,markerStart:b,interactionWidth:v})})}const Jot=Kse({isInternal:!1}),Gse=Kse({isInternal:!0});Jot.displayName="StraightEdge";Gse.displayName="StraightEdgeInternal";function Wse(e){return E.memo(({id:t,sourceX:n,sourceY:i,targetX:a,targetY:r,sourcePosition:s=tt.Bottom,targetPosition:c=tt.Top,label:d,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:k,labelBgBorderRadius:g,style:b,markerEnd:v,markerStart:w,pathOptions:S,interactionWidth:C})=>{const[M,L,j]=ise({sourceX:n,sourceY:i,sourcePosition:s,targetX:a,targetY:r,targetPosition:c,curvature:S==null?void 0:S.curvature}),A=e.isInternal?void 0:t;return u.jsx(ZO,{id:A,path:M,labelX:L,labelY:j,label:d,labelStyle:h,labelShowBg:m,labelBgStyle:f,labelBgPadding:k,labelBgBorderRadius:g,style:b,markerEnd:v,markerStart:w,interactionWidth:C})})}const est=Wse({isInternal:!1}),Xse=Wse({isInternal:!0});est.displayName="BezierEdge";Xse.displayName="BezierEdgeInternal";const fJ={default:Xse,straight:Gse,step:Use,smoothstep:Fse,simplebezier:qse},mJ={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},tst=(e,t,n)=>n===tt.Left?e-t:n===tt.Right?e+t:e,nst=(e,t,n)=>n===tt.Top?e-t:n===tt.Bottom?e+t:e,yJ="react-flow__edgeupdater";function gJ({position:e,centerX:t,centerY:n,radius:i=10,onMouseDown:a,onMouseEnter:r,onMouseOut:s,type:c}){return u.jsx("circle",{onMouseDown:a,onMouseEnter:r,onMouseOut:s,className:Xn([yJ,`${yJ}-${c}`]),cx:tst(t,i,e),cy:nst(n,i,e),r:i,stroke:"transparent",fill:"transparent"})}function ist({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:i,sourceY:a,targetX:r,targetY:s,sourcePosition:c,targetPosition:d,onReconnect:h,onReconnectStart:m,onReconnectEnd:f,setReconnecting:k,setUpdateHover:g}){const b=Nn(),v=(L,j)=>{if(L.button!==0)return;const{autoPanOnConnect:A,domNode:I,connectionMode:T,connectionRadius:P,lib:D,onConnectStart:q,cancelConnection:H,nodeLookup:K,rfId:R,panBy:z,updateConnection:$}=b.getState(),X=j.type==="target",Q=(V,Y)=>{k(!1),f==null||f(V,n,j.type,Y)},W=V=>h==null?void 0:h(n,V),B=(V,Y)=>{k(!0),m==null||m(L,n,j.type),q==null||q(V,Y)};bH.onPointerDown(L.nativeEvent,{autoPanOnConnect:A,connectionMode:T,connectionRadius:P,domNode:I,handleId:j.id,nodeId:j.nodeId,nodeLookup:K,isTarget:X,edgeUpdaterType:j.type,lib:D,flowId:R,cancelConnection:H,panBy:z,isValidConnection:(...V)=>{var Y,F;return((F=(Y=b.getState()).isValidConnection)==null?void 0:F.call(Y,...V))??!0},onConnect:W,onConnectStart:B,onConnectEnd:(...V)=>{var Y,F;return(F=(Y=b.getState()).onConnectEnd)==null?void 0:F.call(Y,...V)},onReconnectEnd:Q,updateConnection:$,getTransform:()=>b.getState().transform,getFromHandle:()=>b.getState().connection.fromHandle,dragThreshold:b.getState().connectionDragThreshold,handleDomNode:L.currentTarget})},w=L=>v(L,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),S=L=>v(L,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),C=()=>g(!0),M=()=>g(!1);return u.jsxs(u.Fragment,{children:[(e===!0||e==="source")&&u.jsx(gJ,{position:c,centerX:i,centerY:a,radius:t,onMouseDown:w,onMouseEnter:C,onMouseOut:M,type:"source"}),(e===!0||e==="target")&&u.jsx(gJ,{position:d,centerX:r,centerY:s,radius:t,onMouseDown:S,onMouseEnter:C,onMouseOut:M,type:"target"})]})}function ast({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:i,onClick:a,onDoubleClick:r,onContextMenu:s,onMouseEnter:c,onMouseMove:d,onMouseLeave:h,reconnectRadius:m,onReconnect:f,onReconnectStart:k,onReconnectEnd:g,rfId:b,edgeTypes:v,noPanClassName:w,onError:S,disableKeyboardA11y:C}){let M=Ht(le=>le.edgeLookup.get(e));const L=Ht(le=>le.defaultEdgeOptions);M=L?{...L,...M}:M;let j=M.type||"default",A=(v==null?void 0:v[j])||fJ[j];A===void 0&&(S==null||S("011",fa.error011(j)),j="default",A=(v==null?void 0:v.default)||fJ.default);const I=!!(M.focusable||t&&typeof M.focusable>"u"),T=typeof f<"u"&&(M.reconnectable||n&&typeof M.reconnectable>"u"),P=!!(M.selectable||i&&typeof M.selectable>"u"),D=E.useRef(null),[q,H]=E.useState(!1),[K,R]=E.useState(!1),z=Nn(),{zIndex:$=M.zIndex,sourceX:X,sourceY:Q,targetX:W,targetY:B,sourcePosition:V,targetPosition:Y}=Ht(E.useCallback(le=>{const be=le.nodeLookup.get(M.source),pe=le.nodeLookup.get(M.target);if(!be||!pe)return mJ;const ne=Kat({id:e,sourceNode:be,targetNode:pe,sourceHandle:M.sourceHandle||null,targetHandle:M.targetHandle||null,connectionMode:le.connectionMode,onError:S}),we=Pat({selected:M.selected,zIndex:M.zIndex,sourceNode:be,targetNode:pe,elevateOnSelect:le.elevateEdgesOnSelect,zIndexMode:le.zIndexMode});return{...ne||mJ,zIndex:we}},[M.source,M.target,M.sourceHandle,M.targetHandle,M.selected,M.zIndex]),Sn),F=E.useMemo(()=>M.markerStart?`url('#${kH(M.markerStart,b)}')`:void 0,[M.markerStart,b]),ae=E.useMemo(()=>M.markerEnd?`url('#${kH(M.markerEnd,b)}')`:void 0,[M.markerEnd,b]);if(M.hidden||X===null||Q===null||W===null||B===null)return null;const xe=le=>{var we;const{addSelectedEdges:be,unselectNodesAndEdges:pe,multiSelectionActive:ne}=z.getState();P&&(z.setState({nodesSelectionActive:!1}),M.selected&&ne?(pe({nodes:[],edges:[M]}),(we=D.current)==null||we.blur()):be([e])),a&&a(le,M)},de=r?le=>{r(le,{...M})}:void 0,Ee=s?le=>{s(le,{...M})}:void 0,ce=c?le=>{c(le,{...M})}:void 0,me=d?le=>{d(le,{...M})}:void 0,je=h?le=>{h(le,{...M})}:void 0,ie=le=>{var be;if(!C&&Boe.includes(le.key)&&P){const{unselectNodesAndEdges:pe,addSelectedEdges:ne}=z.getState();le.key==="Escape"?((be=D.current)==null||be.blur(),pe({edges:[M]})):ne([e])}};return u.jsx("svg",{style:{zIndex:$},children:u.jsxs("g",{className:Xn(["react-flow__edge",`react-flow__edge-${j}`,M.className,w,{selected:M.selected,animated:M.animated,inactive:!P&&!a,updating:q,selectable:P}]),onClick:xe,onDoubleClick:de,onContextMenu:Ee,onMouseEnter:ce,onMouseMove:me,onMouseLeave:je,onKeyDown:I?ie:void 0,tabIndex:I?0:void 0,role:M.ariaRole??(I?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":M.ariaLabel===null?void 0:M.ariaLabel||`Edge from ${M.source} to ${M.target}`,"aria-describedby":I?`${vse}-${b}`:void 0,ref:D,...M.domAttributes,children:[!K&&u.jsx(A,{id:e,source:M.source,target:M.target,type:M.type,selected:M.selected,animated:M.animated,selectable:P,deletable:M.deletable??!0,label:M.label,labelStyle:M.labelStyle,labelShowBg:M.labelShowBg,labelBgStyle:M.labelBgStyle,labelBgPadding:M.labelBgPadding,labelBgBorderRadius:M.labelBgBorderRadius,sourceX:X,sourceY:Q,targetX:W,targetY:B,sourcePosition:V,targetPosition:Y,data:M.data,style:M.style,sourceHandleId:M.sourceHandle,targetHandleId:M.targetHandle,markerStart:F,markerEnd:ae,pathOptions:"pathOptions"in M?M.pathOptions:void 0,interactionWidth:M.interactionWidth}),T&&u.jsx(ist,{edge:M,isReconnectable:T,reconnectRadius:m,onReconnect:f,onReconnectStart:k,onReconnectEnd:g,sourceX:X,sourceY:Q,targetX:W,targetY:B,sourcePosition:V,targetPosition:Y,setUpdateHover:H,setReconnecting:R})]})})}var rst=E.memo(ast);const ost=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Yse({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:i,noPanClassName:a,onReconnect:r,onEdgeContextMenu:s,onEdgeMouseEnter:c,onEdgeMouseMove:d,onEdgeMouseLeave:h,onEdgeClick:m,reconnectRadius:f,onEdgeDoubleClick:k,onReconnectStart:g,onReconnectEnd:b,disableKeyboardA11y:v}){const{edgesFocusable:w,edgesReconnectable:S,elementsSelectable:C,onError:M}=Ht(ost,Sn),L=Vot(t);return u.jsxs("div",{className:"react-flow__edges",children:[u.jsx(Xot,{defaultColor:e,rfId:n}),L.map(j=>u.jsx(rst,{id:j,edgesFocusable:w,edgesReconnectable:S,elementsSelectable:C,noPanClassName:a,onReconnect:r,onContextMenu:s,onMouseEnter:c,onMouseMove:d,onMouseLeave:h,onClick:m,reconnectRadius:f,onDoubleClick:k,onReconnectStart:g,onReconnectEnd:b,rfId:n,onError:M,edgeTypes:i,disableKeyboardA11y:v},j))]})}Yse.displayName="EdgeRenderer";const sst=E.memo(Yse),lst=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function cst({children:e}){const t=Ht(lst);return u.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function dst(e){const t=YO(),n=E.useRef(!1);E.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const ust=e=>{var t;return(t=e.panZoom)==null?void 0:t.syncViewport};function hst(e){const t=Ht(ust),n=Nn();return E.useEffect(()=>{e&&(t==null||t(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function pst(e){return e.connection.inProgress?{...e.connection,to:Z2(e.connection.to,e.transform)}:{...e.connection}}function fst(e){return pst}function mst(e){const t=fst();return Ht(t,Sn)}const yst=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function gst({containerStyle:e,style:t,type:n,component:i}){const{nodesConnectable:a,width:r,height:s,isValid:c,inProgress:d}=Ht(yst,Sn);return!(r&&a&&d)?null:u.jsx("svg",{style:e,width:r,height:s,className:"react-flow__connectionline react-flow__container",children:u.jsx("g",{className:Xn(["react-flow__connection",Voe(c)]),children:u.jsx(Qse,{style:t,type:n,CustomComponent:i,isValid:c})})})}const Qse=({style:e,type:t=vs.Bezier,CustomComponent:n,isValid:i})=>{const{inProgress:a,from:r,fromNode:s,fromHandle:c,fromPosition:d,to:h,toNode:m,toHandle:f,toPosition:k,pointer:g}=mst();if(!a)return;if(n)return u.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:s,fromHandle:c,fromX:r.x,fromY:r.y,toX:h.x,toY:h.y,fromPosition:d,toPosition:k,connectionStatus:Voe(i),toNode:m,toHandle:f,pointer:g});let b="";const v={sourceX:r.x,sourceY:r.y,sourcePosition:d,targetX:h.x,targetY:h.y,targetPosition:k};switch(t){case vs.Bezier:[b]=ise(v);break;case vs.SimpleBezier:[b]=Pse(v);break;case vs.Step:[b]=gH({...v,borderRadius:0});break;case vs.SmoothStep:[b]=gH(v);break;default:[b]=ose(v)}return u.jsx("path",{d:b,fill:"none",className:"react-flow__connection-path",style:e})};Qse.displayName="ConnectionLine";const kst={};function kJ(e=kst){E.useRef(e),Nn(),E.useEffect(()=>{},[e])}function xst(){Nn(),E.useRef(!1),E.useEffect(()=>{},[])}function Zse({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:i,onEdgeClick:a,onNodeDoubleClick:r,onEdgeDoubleClick:s,onNodeMouseEnter:c,onNodeMouseMove:d,onNodeMouseLeave:h,onNodeContextMenu:m,onSelectionContextMenu:f,onSelectionStart:k,onSelectionEnd:g,connectionLineType:b,connectionLineStyle:v,connectionLineComponent:w,connectionLineContainerStyle:S,selectionKeyCode:C,selectionOnDrag:M,selectionMode:L,multiSelectionKeyCode:j,panActivationKeyCode:A,zoomActivationKeyCode:I,deleteKeyCode:T,onlyRenderVisibleElements:P,elementsSelectable:D,defaultViewport:q,translateExtent:H,minZoom:K,maxZoom:R,preventScrolling:z,defaultMarkerColor:$,zoomOnScroll:X,zoomOnPinch:Q,panOnScroll:W,panOnScrollSpeed:B,panOnScrollMode:V,zoomOnDoubleClick:Y,panOnDrag:F,autoPanOnSelection:ae,onPaneClick:xe,onPaneMouseEnter:de,onPaneMouseMove:Ee,onPaneMouseLeave:ce,onPaneScroll:me,onPaneContextMenu:je,paneClickDistance:ie,nodeClickDistance:le,onEdgeContextMenu:be,onEdgeMouseEnter:pe,onEdgeMouseMove:ne,onEdgeMouseLeave:we,reconnectRadius:Be,onReconnect:Oe,onReconnectStart:ft,onReconnectEnd:it,noDragClassName:jt,noWheelClassName:St,noPanClassName:yt,disableKeyboardA11y:Te,nodeExtent:Xe,rfId:re,viewport:_e,onViewportChange:Re}){return kJ(e),kJ(t),xst(),dst(n),hst(_e),u.jsx(Rot,{onPaneClick:xe,onPaneMouseEnter:de,onPaneMouseMove:Ee,onPaneMouseLeave:ce,onPaneContextMenu:je,onPaneScroll:me,paneClickDistance:ie,deleteKeyCode:T,selectionKeyCode:C,selectionOnDrag:M,selectionMode:L,onSelectionStart:k,onSelectionEnd:g,multiSelectionKeyCode:j,panActivationKeyCode:A,zoomActivationKeyCode:I,elementsSelectable:D,zoomOnScroll:X,zoomOnPinch:Q,zoomOnDoubleClick:Y,panOnScroll:W,panOnScrollSpeed:B,panOnScrollMode:V,panOnDrag:F,autoPanOnSelection:ae,defaultViewport:q,translateExtent:H,minZoom:K,maxZoom:R,onSelectionContextMenu:f,preventScrolling:z,noDragClassName:jt,noWheelClassName:St,noPanClassName:yt,disableKeyboardA11y:Te,onViewportChange:Re,isControlledViewport:!!_e,children:u.jsxs(cst,{children:[u.jsx(sst,{edgeTypes:t,onEdgeClick:a,onEdgeDoubleClick:s,onReconnect:Oe,onReconnectStart:ft,onReconnectEnd:it,onlyRenderVisibleElements:P,onEdgeContextMenu:be,onEdgeMouseEnter:pe,onEdgeMouseMove:ne,onEdgeMouseLeave:we,reconnectRadius:Be,defaultMarkerColor:$,noPanClassName:yt,disableKeyboardA11y:Te,rfId:re}),u.jsx(gst,{style:v,type:b,component:w,containerStyle:S}),u.jsx("div",{className:"react-flow__edgelabel-renderer"}),u.jsx(Fot,{nodeTypes:e,onNodeClick:i,onNodeDoubleClick:r,onNodeMouseEnter:c,onNodeMouseMove:d,onNodeMouseLeave:h,onNodeContextMenu:m,nodeClickDistance:le,onlyRenderVisibleElements:P,noPanClassName:yt,noDragClassName:jt,disableKeyboardA11y:Te,nodeExtent:Xe,rfId:re}),u.jsx("div",{className:"react-flow__viewport-portal"})]})})}Zse.displayName="GraphView";const bst=E.memo(Zse),vst=Yoe(),xJ=({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:a,height:r,fitView:s,fitViewOptions:c,minZoom:d=.5,maxZoom:h=2,nodeOrigin:m,nodeExtent:f,zIndexMode:k="basic"}={})=>{const g=new Map,b=new Map,v=new Map,w=new Map,S=i??t??[],C=n??e??[],M=m??[0,0],L=f??m2;cse(v,w,S);const{nodesInitialized:j}=xH(C,g,b,{nodeOrigin:M,nodeExtent:L,zIndexMode:k});let A=[0,0,1];if(s&&a&&r){const I=Y2(g,{filter:q=>!!((q.width||q.initialWidth)&&(q.height||q.initialHeight))}),{x:T,y:P,zoom:D}=vV(I,a,r,d,h,(c==null?void 0:c.padding)??.1);A=[T,P,D]}return{rfId:"1",width:a??0,height:r??0,transform:A,nodes:C,nodesInitialized:j,nodeLookup:g,parentLookup:b,edges:S,edgeLookup:w,connectionLookup:v,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:i!==void 0,panZoom:null,minZoom:d,maxZoom:h,translateExtent:m2,nodeExtent:L,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Tp.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:M,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:s??!1,fitViewOptions:c,fitViewResolver:null,connection:{...Foe},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:vst,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:Hoe,zIndexMode:k,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},wst=({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:a,height:r,fitView:s,fitViewOptions:c,minZoom:d,maxZoom:h,nodeOrigin:m,nodeExtent:f,zIndexMode:k})=>Drt((g,b)=>{async function v(){const{nodeLookup:w,panZoom:S,fitViewOptions:C,fitViewResolver:M,width:L,height:j,minZoom:A,maxZoom:I}=b();S&&(await Aat({nodes:w,width:L,height:j,panZoom:S,minZoom:A,maxZoom:I},C),M==null||M.resolve(!0),g({fitViewResolver:null}))}return{...xJ({nodes:e,edges:t,width:a,height:r,fitView:s,fitViewOptions:c,minZoom:d,maxZoom:h,nodeOrigin:m,nodeExtent:f,defaultNodes:n,defaultEdges:i,zIndexMode:k}),setNodes:w=>{const{nodeLookup:S,parentLookup:C,nodeOrigin:M,elevateNodesOnSelect:L,fitViewQueued:j,zIndexMode:A,nodesSelectionActive:I}=b(),{nodesInitialized:T,hasSelectedNodes:P}=xH(w,S,C,{nodeOrigin:M,nodeExtent:f,elevateNodesOnSelect:L,checkEquality:!0,zIndexMode:A}),D=I&&P;j&&T?(v(),g({nodes:w,nodesInitialized:T,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:D})):g({nodes:w,nodesInitialized:T,nodesSelectionActive:D})},setEdges:w=>{const{connectionLookup:S,edgeLookup:C}=b();cse(S,C,w),g({edges:w})},setDefaultNodesAndEdges:(w,S)=>{if(w){const{setNodes:C}=b();C(w),g({hasDefaultNodes:!0})}if(S){const{setEdges:C}=b();C(S),g({hasDefaultEdges:!0})}},updateNodeInternals:w=>{const{triggerNodeChanges:S,nodeLookup:C,parentLookup:M,domNode:L,nodeOrigin:j,nodeExtent:A,debug:I,fitViewQueued:T,zIndexMode:P}=b(),{changes:D,updatedInternals:q}=ert(w,C,M,L,j,A,P);q&&(Yat(C,M,{nodeOrigin:j,nodeExtent:A,zIndexMode:P}),T?(v(),g({fitViewQueued:!1,fitViewOptions:void 0})):g({}),(D==null?void 0:D.length)>0&&(I&&console.log("React Flow: trigger node changes",D),S==null||S(D)))},updateNodePositions:(w,S=!1)=>{const C=[];let M=[];const{nodeLookup:L,triggerNodeChanges:j,connection:A,updateConnection:I,onNodesChangeMiddlewareMap:T}=b();for(const[P,D]of w){const q=L.get(P),H=!!(q!=null&&q.expandParent&&(q!=null&&q.parentId)&&(D!=null&&D.position)),K={id:P,type:"position",position:H?{x:Math.max(0,D.position.x),y:Math.max(0,D.position.y)}:D.position,dragging:S};if(q&&A.inProgress&&A.fromNode.id===q.id){const R=D1(q,A.fromHandle,tt.Left,!0);I({...A,from:R})}H&&q.parentId&&C.push({id:P,parentId:q.parentId,rect:{...D.internals.positionAbsolute,width:D.measured.width??0,height:D.measured.height??0}}),M.push(K)}if(C.length>0){const{parentLookup:P,nodeOrigin:D}=b(),q=EV(C,L,P,D);M.push(...q)}for(const P of T.values())M=P(M);j(M)},triggerNodeChanges:w=>{const{onNodesChange:S,setNodes:C,nodes:M,hasDefaultNodes:L,debug:j}=b();if(w!=null&&w.length){if(L){const A=_se(w,M);C(A)}j&&console.log("React Flow: trigger node changes",w),S==null||S(w)}},triggerEdgeChanges:w=>{const{onEdgesChange:S,setEdges:C,edges:M,hasDefaultEdges:L,debug:j}=b();if(w!=null&&w.length){if(L){const A=Sse(w,M);C(A)}j&&console.log("React Flow: trigger edge changes",w),S==null||S(w)}},addSelectedNodes:w=>{const{multiSelectionActive:S,edgeLookup:C,nodeLookup:M,triggerNodeChanges:L,triggerEdgeChanges:j}=b();if(S){const A=w.map(I=>Xu(I,!0));L(A);return}L(Bh(M,new Set([...w]),!0)),j(Bh(C))},addSelectedEdges:w=>{const{multiSelectionActive:S,edgeLookup:C,nodeLookup:M,triggerNodeChanges:L,triggerEdgeChanges:j}=b();if(S){const A=w.map(I=>Xu(I,!0));j(A);return}j(Bh(C,new Set([...w]))),L(Bh(M,new Set,!0))},unselectNodesAndEdges:({nodes:w,edges:S}={})=>{const{edges:C,nodes:M,nodeLookup:L,triggerNodeChanges:j,triggerEdgeChanges:A}=b(),I=w||M,T=S||C,P=[];for(const q of I){if(!q.selected)continue;const H=L.get(q.id);H&&(H.selected=!1),P.push(Xu(q.id,!1))}const D=[];for(const q of T)q.selected&&D.push(Xu(q.id,!1));j(P),A(D)},setMinZoom:w=>{const{panZoom:S,maxZoom:C}=b();S==null||S.setScaleExtent([w,C]),g({minZoom:w})},setMaxZoom:w=>{const{panZoom:S,minZoom:C}=b();S==null||S.setScaleExtent([C,w]),g({maxZoom:w})},setTranslateExtent:w=>{var S;(S=b().panZoom)==null||S.setTranslateExtent(w),g({translateExtent:w})},resetSelectedElements:()=>{const{edges:w,nodes:S,triggerNodeChanges:C,triggerEdgeChanges:M,elementsSelectable:L}=b();if(!L)return;const j=S.reduce((I,T)=>T.selected?[...I,Xu(T.id,!1)]:I,[]),A=w.reduce((I,T)=>T.selected?[...I,Xu(T.id,!1)]:I,[]);C(j),M(A)},setNodeExtent:w=>{const{nodes:S,nodeLookup:C,parentLookup:M,nodeOrigin:L,elevateNodesOnSelect:j,nodeExtent:A,zIndexMode:I}=b();w[0][0]===A[0][0]&&w[0][1]===A[0][1]&&w[1][0]===A[1][0]&&w[1][1]===A[1][1]||(xH(S,C,M,{nodeOrigin:L,nodeExtent:w,elevateNodesOnSelect:j,checkEquality:!1,zIndexMode:I}),g({nodeExtent:w}))},panBy:w=>{const{transform:S,width:C,height:M,panZoom:L,translateExtent:j}=b();return trt({delta:w,panZoom:L,transform:S,translateExtent:j,width:C,height:M})},setCenter:async(w,S,C)=>{const{width:M,height:L,maxZoom:j,panZoom:A}=b();if(!A)return!1;const I=typeof(C==null?void 0:C.zoom)<"u"?C.zoom:j;return await A.setViewport({x:M/2-w*I,y:L/2-S*I,zoom:I},{duration:C==null?void 0:C.duration,ease:C==null?void 0:C.ease,interpolate:C==null?void 0:C.interpolate}),!0},cancelConnection:()=>{g({connection:{...Foe}})},updateConnection:w=>{g({connection:w})},reset:()=>g({...xJ()})}},Object.is);function Jse({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:i,initialWidth:a,initialHeight:r,initialMinZoom:s,initialMaxZoom:c,initialFitViewOptions:d,fitView:h,nodeOrigin:m,nodeExtent:f,zIndexMode:k,children:g}){const[b]=E.useState(()=>wst({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,width:a,height:r,fitView:h,minZoom:s,maxZoom:c,fitViewOptions:d,nodeOrigin:m,nodeExtent:f,zIndexMode:k}));return u.jsx(Ort,{value:b,children:u.jsx(oot,{children:u.jsx(vot,{children:g})})})}function Mst({children:e,nodes:t,edges:n,defaultNodes:i,defaultEdges:a,width:r,height:s,fitView:c,fitViewOptions:d,minZoom:h,maxZoom:m,nodeOrigin:f,nodeExtent:k,zIndexMode:g}){return E.useContext(WO)?u.jsx(u.Fragment,{children:e}):u.jsx(Jse,{initialNodes:t,initialEdges:n,defaultNodes:i,defaultEdges:a,initialWidth:r,initialHeight:s,fitView:c,initialFitViewOptions:d,initialMinZoom:h,initialMaxZoom:m,nodeOrigin:f,nodeExtent:k,zIndexMode:g,children:e})}const _st={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function Sst({nodes:e,edges:t,defaultNodes:n,defaultEdges:i,className:a,nodeTypes:r,edgeTypes:s,onNodeClick:c,onEdgeClick:d,onInit:h,onMove:m,onMoveStart:f,onMoveEnd:k,onConnect:g,onConnectStart:b,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:S,onNodeMouseEnter:C,onNodeMouseMove:M,onNodeMouseLeave:L,onNodeContextMenu:j,onNodeDoubleClick:A,onNodeDragStart:I,onNodeDrag:T,onNodeDragStop:P,onNodesDelete:D,onEdgesDelete:q,onDelete:H,onSelectionChange:K,onSelectionDragStart:R,onSelectionDrag:z,onSelectionDragStop:$,onSelectionContextMenu:X,onSelectionStart:Q,onSelectionEnd:W,onBeforeDelete:B,connectionMode:V,connectionLineType:Y=vs.Bezier,connectionLineStyle:F,connectionLineComponent:ae,connectionLineContainerStyle:xe,deleteKeyCode:de="Backspace",selectionKeyCode:Ee="Shift",selectionOnDrag:ce=!1,selectionMode:me=y2.Full,panActivationKeyCode:je="Space",multiSelectionKeyCode:ie=k2()?"Meta":"Control",zoomActivationKeyCode:le=k2()?"Meta":"Control",snapToGrid:be,snapGrid:pe,onlyRenderVisibleElements:ne=!1,selectNodesOnDrag:we,nodesDraggable:Be,autoPanOnNodeFocus:Oe,nodesConnectable:ft,nodesFocusable:it,nodeOrigin:jt=wse,edgesFocusable:St,edgesReconnectable:yt,elementsSelectable:Te=!0,defaultViewport:Xe=Xrt,minZoom:re=.5,maxZoom:_e=2,translateExtent:Re=m2,preventScrolling:ke=!0,nodeExtent:et,defaultMarkerColor:zt="#b1b1b7",zoomOnScroll:Yt=!0,zoomOnPinch:ye=!0,panOnScroll:se=!1,panOnScrollSpeed:Le=.5,panOnScrollMode:Ae=N1.Free,zoomOnDoubleClick:Je=!0,panOnDrag:ot=!0,onPaneClick:mt,onPaneMouseEnter:He,onPaneMouseMove:Pt,onPaneMouseLeave:Ut,onPaneScroll:$t,onPaneContextMenu:J,paneClickDistance:Me=1,nodeClickDistance:Pe=0,children:ct,onReconnect:Zt,onReconnectStart:Kt,onReconnectEnd:Ue,onEdgeContextMenu:Fe,onEdgeDoubleClick:at,onEdgeMouseEnter:fn,onEdgeMouseMove:ln,onEdgeMouseLeave:Ni,reconnectRadius:ma=10,onNodesChange:ya,onEdgesChange:zi,noDragClassName:mn="nodrag",noWheelClassName:Pn="nowheel",noPanClassName:Yn="nopan",fitView:qa,fitViewOptions:Qr,connectOnClick:Ba,attributionPosition:Zr,proOptions:ga,defaultEdgeOptions:Jr,elevateNodesOnSelect:Qn=!0,elevateEdgesOnSelect:Yi=!1,disableKeyboardA11y:Ei=!1,autoPanOnConnect:ka,autoPanOnNodeDrag:wn,autoPanOnSelection:eo=!0,autoPanSpeed:Zn,connectionRadius:In,isValidConnection:Ie,onError:Ye,style:bt,id:qt,nodeDragThreshold:gn,connectionDragThreshold:Hn,viewport:di,onViewportChange:ii,width:Gt,height:ai,colorMode:to="light",debug:ri,onScroll:oi,ariaLabelConfig:Ha,zIndexMode:Bo="basic",...si},Qi){const xi=qt||"1",Fa=Jrt(to),Tn=E.useCallback(gr=>{gr.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),oi==null||oi(gr)},[oi]);return u.jsx("div",{"data-testid":"rf__wrapper",...si,onScroll:Tn,style:{...bt,..._st},ref:Qi,className:Xn(["react-flow",a,Fa]),id:qt,role:"application",children:u.jsxs(Mst,{nodes:e,edges:t,width:Gt,height:ai,fitView:qa,fitViewOptions:Qr,minZoom:re,maxZoom:_e,nodeOrigin:jt,nodeExtent:et,zIndexMode:Bo,children:[u.jsx(Zrt,{nodes:e,edges:t,defaultNodes:n,defaultEdges:i,onConnect:g,onConnectStart:b,onConnectEnd:v,onClickConnectStart:w,onClickConnectEnd:S,nodesDraggable:Be,autoPanOnNodeFocus:Oe,nodesConnectable:ft,nodesFocusable:it,edgesFocusable:St,edgesReconnectable:yt,elementsSelectable:Te,elevateNodesOnSelect:Qn,elevateEdgesOnSelect:Yi,minZoom:re,maxZoom:_e,nodeExtent:et,onNodesChange:ya,onEdgesChange:zi,snapToGrid:be,snapGrid:pe,connectionMode:V,translateExtent:Re,connectOnClick:Ba,defaultEdgeOptions:Jr,fitView:qa,fitViewOptions:Qr,onNodesDelete:D,onEdgesDelete:q,onDelete:H,onNodeDragStart:I,onNodeDrag:T,onNodeDragStop:P,onSelectionDrag:z,onSelectionDragStart:R,onSelectionDragStop:$,onMove:m,onMoveStart:f,onMoveEnd:k,noPanClassName:Yn,nodeOrigin:jt,rfId:xi,autoPanOnConnect:ka,autoPanOnNodeDrag:wn,autoPanSpeed:Zn,onError:Ye,connectionRadius:In,isValidConnection:Ie,selectNodesOnDrag:we,nodeDragThreshold:gn,connectionDragThreshold:Hn,onBeforeDelete:B,debug:ri,ariaLabelConfig:Ha,zIndexMode:Bo}),u.jsx(bst,{onInit:h,onNodeClick:c,onEdgeClick:d,onNodeMouseEnter:C,onNodeMouseMove:M,onNodeMouseLeave:L,onNodeContextMenu:j,onNodeDoubleClick:A,nodeTypes:r,edgeTypes:s,connectionLineType:Y,connectionLineStyle:F,connectionLineComponent:ae,connectionLineContainerStyle:xe,selectionKeyCode:Ee,selectionOnDrag:ce,selectionMode:me,deleteKeyCode:de,multiSelectionKeyCode:ie,panActivationKeyCode:je,zoomActivationKeyCode:le,onlyRenderVisibleElements:ne,defaultViewport:Xe,translateExtent:Re,minZoom:re,maxZoom:_e,preventScrolling:ke,zoomOnScroll:Yt,zoomOnPinch:ye,zoomOnDoubleClick:Je,panOnScroll:se,panOnScrollSpeed:Le,panOnScrollMode:Ae,panOnDrag:ot,autoPanOnSelection:eo,onPaneClick:mt,onPaneMouseEnter:He,onPaneMouseMove:Pt,onPaneMouseLeave:Ut,onPaneScroll:$t,onPaneContextMenu:J,paneClickDistance:Me,nodeClickDistance:Pe,onSelectionContextMenu:X,onSelectionStart:Q,onSelectionEnd:W,onReconnect:Zt,onReconnectStart:Kt,onReconnectEnd:Ue,onEdgeContextMenu:Fe,onEdgeDoubleClick:at,onEdgeMouseEnter:fn,onEdgeMouseMove:ln,onEdgeMouseLeave:Ni,reconnectRadius:ma,defaultMarkerColor:zt,noDragClassName:mn,noWheelClassName:Pn,noPanClassName:Yn,rfId:xi,disableKeyboardA11y:Ei,nodeExtent:et,viewport:di,onViewportChange:ii}),u.jsx(Wrt,{onSelectionChange:K}),ct,u.jsx(Frt,{proOptions:ga,position:Zr}),u.jsx(Hrt,{rfId:xi,disableKeyboardA11y:Ei})]})})}var Nst=Cse(Sst);function Est(e){const[t,n]=E.useState(e),i=E.useCallback(a=>n(r=>_se(a,r)),[]);return[t,n,i]}function Cst(e){const[t,n]=E.useState(e),i=E.useCallback(a=>n(r=>Sse(a,r)),[]);return[t,n,i]}function Lst({dimensions:e,lineWidth:t,variant:n,className:i}){return u.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Xn(["react-flow__background-pattern",n,i])})}function jst({radius:e,className:t}){return u.jsx("circle",{cx:e,cy:e,r:e,className:Xn(["react-flow__background-pattern","dots",t])})}var Do;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Do||(Do={}));const Ast={[Do.Dots]:1,[Do.Lines]:1,[Do.Cross]:6},Ist=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function ele({id:e,variant:t=Do.Dots,gap:n=20,size:i,lineWidth:a=1,offset:r=0,color:s,bgColor:c,style:d,className:h,patternClassName:m}){const f=E.useRef(null),{transform:k,patternId:g}=Ht(Ist,Sn),b=i||Ast[t],v=t===Do.Dots,w=t===Do.Cross,S=Array.isArray(n)?n:[n,n],C=[S[0]*k[2]||1,S[1]*k[2]||1],M=b*k[2],L=Array.isArray(r)?r:[r,r],j=w?[M,M]:C,A=[L[0]*k[2]||1+j[0]/2,L[1]*k[2]||1+j[1]/2],I=`${g}${e||""}`;return u.jsxs("svg",{className:Xn(["react-flow__background",h]),style:{...d,...QO,"--xy-background-color-props":c,"--xy-background-pattern-color-props":s},ref:f,"data-testid":"rf__background",children:[u.jsx("pattern",{id:I,x:k[0]%C[0],y:k[1]%C[1],width:C[0],height:C[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${A[0]},-${A[1]})`,children:v?u.jsx(jst,{radius:M/2,className:m}):u.jsx(Lst,{dimensions:j,lineWidth:a,variant:t,className:m})}),u.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${I})`})]})}ele.displayName="Background";const Tst=E.memo(ele);function Rst(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:u.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function Dst(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:u.jsx("path",{d:"M0 0h32v4.2H0z"})})}function Ost(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:u.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 zst(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:u.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 Pst(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:u.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 a0({children:e,className:t,...n}){return u.jsx("button",{type:"button",className:Xn(["react-flow__controls-button",t]),...n,children:e})}const $st=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function tle({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:i=!0,fitViewOptions:a,onZoomIn:r,onZoomOut:s,onFitView:c,onInteractiveChange:d,className:h,children:m,position:f="bottom-left",orientation:k="vertical","aria-label":g}){const b=Nn(),{isInteractive:v,minZoomReached:w,maxZoomReached:S,ariaLabelConfig:C}=Ht($st,Sn),{zoomIn:M,zoomOut:L,fitView:j}=YO(),A=()=>{M(),r==null||r()},I=()=>{L(),s==null||s()},T=()=>{j(a),c==null||c()},P=()=>{b.setState({nodesDraggable:!v,nodesConnectable:!v,elementsSelectable:!v}),d==null||d(!v)},D=k==="horizontal"?"horizontal":"vertical";return u.jsxs(XO,{className:Xn(["react-flow__controls",D,h]),position:f,style:e,"data-testid":"rf__controls","aria-label":g??C["controls.ariaLabel"],children:[t&&u.jsxs(u.Fragment,{children:[u.jsx(a0,{onClick:A,className:"react-flow__controls-zoomin",title:C["controls.zoomIn.ariaLabel"],"aria-label":C["controls.zoomIn.ariaLabel"],disabled:S,children:u.jsx(Rst,{})}),u.jsx(a0,{onClick:I,className:"react-flow__controls-zoomout",title:C["controls.zoomOut.ariaLabel"],"aria-label":C["controls.zoomOut.ariaLabel"],disabled:w,children:u.jsx(Dst,{})})]}),n&&u.jsx(a0,{className:"react-flow__controls-fitview",onClick:T,title:C["controls.fitView.ariaLabel"],"aria-label":C["controls.fitView.ariaLabel"],children:u.jsx(Ost,{})}),i&&u.jsx(a0,{className:"react-flow__controls-interactive",onClick:P,title:C["controls.interactive.ariaLabel"],"aria-label":C["controls.interactive.ariaLabel"],children:v?u.jsx(Pst,{}):u.jsx(zst,{})}),m]})}tle.displayName="Controls";const qst=E.memo(tle);function Bst({id:e,x:t,y:n,width:i,height:a,style:r,color:s,strokeColor:c,strokeWidth:d,className:h,borderRadius:m,shapeRendering:f,selected:k,onClick:g}){const{background:b,backgroundColor:v}=r||{},w=s||b||v;return u.jsx("rect",{className:Xn(["react-flow__minimap-node",{selected:k},h]),x:t,y:n,rx:m,ry:m,width:i,height:a,style:{fill:w,stroke:c,strokeWidth:d},shapeRendering:f,onClick:g?S=>g(S,e):void 0})}const Hst=E.memo(Bst),Fst=e=>e.nodes.map(t=>t.id),Nq=e=>e instanceof Function?e:()=>e;function Vst({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:i=5,nodeStrokeWidth:a,nodeComponent:r=Hst,onClick:s}){const c=Ht(Fst,Sn),d=Nq(t),h=Nq(e),m=Nq(n),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return u.jsx(u.Fragment,{children:c.map(k=>u.jsx(Kst,{id:k,nodeColorFunc:d,nodeStrokeColorFunc:h,nodeClassNameFunc:m,nodeBorderRadius:i,nodeStrokeWidth:a,NodeComponent:r,onClick:s,shapeRendering:f},k))})}function Ust({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:i,nodeBorderRadius:a,nodeStrokeWidth:r,shapeRendering:s,NodeComponent:c,onClick:d}){const{node:h,x:m,y:f,width:k,height:g}=Ht(b=>{const v=b.nodeLookup.get(e);if(!v)return{node:void 0,x:0,y:0,width:0,height:0};const w=v.internals.userNode,{x:S,y:C}=v.internals.positionAbsolute,{width:M,height:L}=qo(w);return{node:w,x:S,y:C,width:M,height:L}},Sn);return!h||h.hidden||!Qoe(h)?null:u.jsx(c,{x:m,y:f,width:k,height:g,style:h.style,selected:!!h.selected,className:i(h),color:t(h),borderRadius:a,strokeColor:n(h),strokeWidth:r,shapeRendering:s,onClick:d,id:h.id})}const Kst=E.memo(Ust);var Gst=E.memo(Vst);const Wst=200,Xst=150,Yst=e=>!e.hidden,Qst=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?Woe(Y2(e.nodeLookup,{filter:Yst}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},Zst="react-flow__minimap-desc";function nle({style:e,className:t,nodeStrokeColor:n,nodeColor:i,nodeClassName:a="",nodeBorderRadius:r=5,nodeStrokeWidth:s,nodeComponent:c,bgColor:d,maskColor:h,maskStrokeColor:m,maskStrokeWidth:f,position:k="bottom-right",onClick:g,onNodeClick:b,pannable:v=!1,zoomable:w=!1,ariaLabel:S,inversePan:C,zoomStep:M=1,offsetScale:L=5}){const j=Nn(),A=E.useRef(null),{boundingRect:I,viewBB:T,rfId:P,panZoom:D,translateExtent:q,flowWidth:H,flowHeight:K,ariaLabelConfig:R}=Ht(Qst,Sn),z=(e==null?void 0:e.width)??Wst,$=(e==null?void 0:e.height)??Xst,X=I.width/z,Q=I.height/$,W=Math.max(X,Q),B=W*z,V=W*$,Y=L*W,F=I.x-(B-I.width)/2-Y,ae=I.y-(V-I.height)/2-Y,xe=B+Y*2,de=V+Y*2,Ee=`${Zst}-${P}`,ce=E.useRef(0),me=E.useRef();ce.current=W,E.useEffect(()=>{if(A.current&&D)return me.current=drt({domNode:A.current,panZoom:D,getTransform:()=>j.getState().transform,getViewScale:()=>ce.current}),()=>{var be;(be=me.current)==null||be.destroy()}},[D]),E.useEffect(()=>{var be;(be=me.current)==null||be.update({translateExtent:q,width:H,height:K,inversePan:C,pannable:v,zoomStep:M,zoomable:w})},[v,w,C,M,q,H,K]);const je=g?be=>{var we;const[pe,ne]=((we=me.current)==null?void 0:we.pointer(be))||[0,0];g(be,{x:pe,y:ne})}:void 0,ie=b?E.useCallback((be,pe)=>{const ne=j.getState().nodeLookup.get(pe).internals.userNode;b(be,ne)},[]):void 0,le=S??R["minimap.ariaLabel"];return u.jsx(XO,{position:k,style:{...e,"--xy-minimap-background-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-background-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-color-props":typeof m=="string"?m:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*W: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 s=="number"?s:void 0},className:Xn(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:u.jsxs("svg",{width:z,height:$,viewBox:`${F} ${ae} ${xe} ${de}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":Ee,ref:A,onClick:je,children:[le&&u.jsx("title",{id:Ee,children:le}),u.jsx(Gst,{onClick:ie,nodeColor:i,nodeStrokeColor:n,nodeBorderRadius:r,nodeClassName:a,nodeStrokeWidth:s,nodeComponent:c}),u.jsx("path",{className:"react-flow__minimap-mask",d:`M${F-Y},${ae-Y}h${xe+Y*2}v${de+Y*2}h${-xe-Y*2}z
8657
8657
  M${T.x},${T.y}h${T.width}v${T.height}h${-T.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}nle.displayName="MiniMap";E.memo(nle);const Jst=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,elt={[Op.Line]:"right",[Op.Handle]:"bottom-right"};function tlt({nodeId:e,position:t,variant:n=Op.Handle,className:i,style:a=void 0,children:r,color:s,minWidth:c=10,minHeight:d=10,maxWidth:h=Number.MAX_VALUE,maxHeight:m=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:k,autoScale:g=!0,shouldResize:b,onResizeStart:v,onResize:w,onResizeEnd:S}){const C=Ise(),M=typeof e=="string"?e:C,L=Nn(),j=E.useRef(null),A=n===Op.Handle,I=Ht(E.useCallback(Jst(A&&g),[A,g]),Sn),T=E.useRef(null),P=t??elt[n];E.useEffect(()=>{if(!(!j.current||!M))return T.current||(T.current=Mrt({domNode:j.current,nodeId:M,getStoreItems:()=>{const{nodeLookup:q,transform:H,snapGrid:K,snapToGrid:R,nodeOrigin:z,domNode:$}=L.getState();return{nodeLookup:q,transform:H,snapGrid:K,snapToGrid:R,nodeOrigin:z,paneDomNode:$}},onChange:(q,H)=>{const{triggerNodeChanges:K,nodeLookup:R,parentLookup:z,nodeOrigin:$}=L.getState(),X=[],Q={x:q.x,y:q.y},W=R.get(M);if(W&&W.expandParent&&W.parentId){const B=W.origin??$,V=q.width??W.measured.width??0,Y=q.height??W.measured.height??0,F={id:W.id,parentId:W.parentId,rect:{width:V,height:Y,...Zoe({x:q.x??W.position.x,y:q.y??W.position.y},{width:V,height:Y},W.parentId,R,B)}},ae=EV([F],R,z,$);X.push(...ae),Q.x=q.x?Math.max(B[0]*V,q.x):void 0,Q.y=q.y?Math.max(B[1]*Y,q.y):void 0}if(Q.x!==void 0&&Q.y!==void 0){const B={id:M,type:"position",position:{...Q}};X.push(B)}if(q.width!==void 0&&q.height!==void 0){const V={id:M,type:"dimensions",resizing:!0,setAttributes:k?k==="horizontal"?"width":"height":!0,dimensions:{width:q.width,height:q.height}};X.push(V)}for(const B of H){const V={...B,type:"position"};X.push(V)}K(X)},onEnd:({width:q,height:H})=>{const K={id:M,type:"dimensions",resizing:!1,dimensions:{width:q,height:H}};L.getState().triggerNodeChanges([K])}})),T.current.update({controlPosition:P,boundaries:{minWidth:c,minHeight:d,maxWidth:h,maxHeight:m},keepAspectRatio:f,resizeDirection:k,onResizeStart:v,onResize:w,onResizeEnd:S,shouldResize:b}),()=>{var q;(q=T.current)==null||q.destroy()}},[P,c,d,h,m,f,v,w,S,b]);const D=P.split("-");return u.jsx("div",{className:Xn(["react-flow__resize-control","nodrag",...D,n,i]),ref:j,style:{...a,scale:I,...s&&{[A?"backgroundColor":"borderColor"]:s}},children:r})}E.memo(tlt);function nlt(e){return _t(`/api/projects/${encodeURIComponent(e)}/flow`)}function ilt(e,t){return $2(`/api/projects/${encodeURIComponent(e)}/flow`,t)}const alt=new Set(["NEEDS-FIX","STALE-UPSTREAM","BLOCKED","CONFLICT","ACK-TIMEOUT"]),bJ="AI-PIPELINE",wH={done:"var(--color-running)",doing:"var(--color-running)",todo:"var(--color-text-subtle)",stuck:"var(--color-crashed)"},vJ=["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 rlt(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)>>>0;return vJ[t%vJ.length]}const Hy={width:9,height:9,background:"var(--color-bg)",border:"1px solid var(--color-border-light)"},olt=E.memo(function({id:t,data:n,selected:i}){const a=n,r=a.skills.split(",").map(d=>d.trim()).filter(Boolean),s=(a.labels??"").split(",").map(d=>d.trim()).filter(Boolean),c=s.filter(d=>alt.has(d));return u.jsxs("div",{className:`flow-node-glow${i?" is-selected":""}${a.status==="doing"?" is-running":""}`,children:[u.jsx(Rs,{id:"l",type:"target",position:tt.Left,style:Hy}),u.jsx(Rs,{id:"t",type:"target",position:tt.Top,style:Hy}),u.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:[u.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-1.5 border-b border-[var(--color-border-light)]",style:{background:rlt(t)},children:[u.jsxs("span",{className:"font-[family-name:var(--font-mono)] text-xs font-bold text-[var(--color-text)]",children:["#",a.seq]}),a.kind&&a.kind!=="worker"&&u.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:a.tool??a.kind,children:a.kind==="tool"?`⚙ ${a.tool??"tool"}`:`⇥ ${a.kind}`}),u.jsxs("span",{className:"relative shrink-0 ml-auto flex items-center justify-center w-2.5 h-2.5",title:a.status,children:[a.status==="doing"&&u.jsx("span",{className:"absolute inline-flex w-full h-full rounded-full animate-ping opacity-60",style:{background:wH.doing}}),u.jsx("span",{className:"relative w-2.5 h-2.5 rounded-full",style:{background:wH[a.status]??"var(--color-text-subtle)"}})]})]}),u.jsxs("div",{className:"px-2.5 py-2 flex-1 min-h-0 overflow-hidden",children:[u.jsx("p",{className:"text-[13px] font-semibold text-[var(--color-text)] leading-snug line-clamp-3",children:a.title||"任务"}),!s.includes(bJ)&&u.jsxs("div",{className:"mt-1.5 text-[10px] font-[family-name:var(--font-mono)] text-[var(--color-crashed)]",children:["无 ",bJ," · 不会被派"]}),c.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mt-1.5",children:c.map(d=>u.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:d},d))}),r.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mt-2 max-h-[46px] overflow-hidden",children:r.slice(0,6).map(d=>u.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:d},d))})]})]}),u.jsx(Rs,{id:"r",type:"source",position:tt.Right,style:Hy}),u.jsx(Rs,{id:"b",type:"source",position:tt.Bottom,style:Hy})]})});function slt(e){if(!e)return"";const t=e.split(`
8658
8658
  `),n=t.findIndex(a=>/^##\s+描述\s*$/.test(a));if(n===-1)return"";let i=t.length;for(let a=n+1;a<t.length;a+=1)if(/^##\s+/.test(t[a]??"")){i=a;break}return t.slice(n+1,i).join(`
8659
- `).trim()}function llt(e,t){return t.includes("NEEDS-FIX")?"stuck":e==="Done"?"done":e==="Inprogress"?"doing":"todo"}function clt({project:e,seq:t,onClose:n,onChanged:i,onDelete:a}){var je,ie;const r=Ze(),[s,c]=E.useState(!0),[d,h]=E.useState(!1),[m,f]=E.useState(""),[k,g]=E.useState(""),[b,v]=E.useState(new Set),[w,S]=E.useState(""),[C,M]=E.useState("todo"),[L,j]=E.useState(null),[A,I]=E.useState(""),[T,P]=E.useState(void 0),[D,q]=E.useState(void 0),[H,K]=E.useState(void 0),[R,z]=E.useState(void 0),[$,X]=E.useState({value:null,error:"",dirty:!1}),[Q,W]=E.useState(null),[B,V]=E.useState(null),Y=B??T,F=Y==="tool"||Y==="join",ae=nt({queryKey:["skills-all",e],queryFn:()=>zO(e),enabled:!F}),xe=((je=ae.data)==null?void 0:je.data)??[],de=nt({queryKey:["capabilities",e],queryFn:()=>lV(e),enabled:F});E.useEffect(()=>{const le=be=>{be.key==="Escape"&&n()};return window.addEventListener("keydown",le),()=>window.removeEventListener("keydown",le)},[n]),E.useEffect(()=>{let le=!1;return c(!0),Yre(e,t).then(be=>{le||(f(be.title),v(new Set(be.skills??[])),g(slt(be.body)),S(be.state),M(llt(be.state,be.labels??[])),j(typeof be.order=="number"?be.order:null),P(be.kind),q(be.tool),W(null),V(null),K(be.input),z(be.toolResult))}).catch(()=>{}).finally(()=>{le||c(!1)}),()=>{le=!0}},[e,t]);const Ee=le=>{v(be=>{const pe=new Set(be);return pe.has(le)?pe.delete(le):pe.add(le),pe})},ce=async()=>{if(I(""),F&&$.error){I($.error);return}h(!0);try{await KD(e,t,{title:m.trim()||r("flow.node.default"),...B?{kind:B}:{},...F?{...Q||B==="tool"?{tool:Q??D??"art.inspect"}:{},...$.dirty||B==="tool"?{input:$.value??{in:""}}:{}}:{description:k,skills:[...b]}}),i(),n()}catch(le){I(le instanceof Error?le.message:String(le)),h(!1)}},me=()=>a(t);return u.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:u.jsxs("div",{className:"nb-card w-full max-w-4xl flex flex-col bg-[var(--color-bg)]",style:{maxHeight:"calc(100vh - 48px)"},onClick:le=>le.stopPropagation(),children:[u.jsxs("header",{className:"flex items-start justify-between gap-4 mb-4 flex-shrink-0",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.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&&u.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:[u.jsx("span",{className:"w-2.5 h-2.5 rounded-full inline-block border border-[var(--color-text)]",style:{background:wH[C]??"gray"}}),w]}),L!=null&&u.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:L})})]}),u.jsx("button",{onClick:n,className:"nb-btn nb-btn-mint p-2 flex-shrink-0","aria-label":r("flow.node.close"),type:"button",children:u.jsx(nn,{size:14,strokeWidth:3})})]}),s?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--color-text-muted)] py-10 justify-center",children:[u.jsx(lt,{size:16,className:"animate-spin"})," …"]}):u.jsxs(u.Fragment,{children:[A&&u.jsx("div",{className:"text-sm text-[var(--color-crashed)] mb-3",children:A}),u.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[u.jsx("span",{className:"text-sm font-bold",children:r("card.kind.label")}),["worker","tool"].map(le=>u.jsx("button",{type:"button",onClick:()=>V(le===(T??"worker")?null:le),"aria-pressed":Y===le||le==="worker"&&!F,className:["px-2.5 py-1 text-xs rounded-full border-2 transition-all font-[family-name:var(--font-mono)]",(le==="tool"?F:!F)?"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(le==="tool"?"card.kind.tool":"card.kind.worker")},le)),B&&u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:r("card.kind.pending")})]}),F&&($.dirty||Q)&&R&&u.jsxs("div",{className:"mb-3 text-xs text-[var(--color-text-muted)]",children:["⚠️ ",r("tool.card.staleWarn")]}),u.jsxs("div",{className:F?"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:[u.jsxs("label",{className:F?"flex flex-col gap-1.5":"hidden",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),u.jsx("input",{className:"nb-input w-full text-base font-semibold",value:m,onChange:le=>f(le.target.value)})]}),F&&u.jsx(UD,{tool:Q??D,input:H,toolResult:R,capabilities:((ie=de.data)==null?void 0:ie.data)??[],onChange:X,onToolChange:W}),!F&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex min-h-0 flex-col gap-4 md:overflow-y-auto md:pr-1",children:[u.jsxs("label",{className:"flex flex-col gap-1.5",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),u.jsx("input",{className:"nb-input w-full text-base font-semibold",value:m,onChange:le=>f(le.target.value),autoFocus:!0})]}),u.jsxs("label",{className:"flex flex-1 min-h-0 flex-col gap-1.5",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.desc")}),u.jsx("textarea",{className:"nb-input w-full flex-1 min-h-0",style:{minHeight:200,resize:"vertical"},value:k,onChange:le=>g(le.target.value)})]})]}),u.jsxs("section",{className:"flex min-h-[200px] flex-col gap-2 md:min-h-0 md:overflow-hidden",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.skills")}),u.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:u.jsxs("div",{className:"scroll-frame-body h-full p-2",children:[ae.isLoading&&u.jsx(lt,{size:14,className:"animate-spin text-[var(--color-text-muted)]"}),xe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:xe.map(le=>{const be=b.has(le.name);return u.jsx("button",{type:"button",onClick:()=>Ee(le.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",be?"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":be,children:le.name},le.name)})})]})}),b.size>0&&u.jsx("p",{className:"max-h-14 overflow-y-auto break-words text-xs text-[var(--color-text-muted)]",children:[...b].join(", ")})]})]})]}),u.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:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-danger",onClick:()=>void me(),disabled:d,children:[u.jsx(Mi,{size:14,strokeWidth:2.4})," ",r("flow.node.delete")]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta",onClick:()=>void ce(),disabled:d||F&&$.error!=="",children:[d?u.jsx(lt,{size:14,className:"animate-spin"}):null,r("flow.node.save")]})]})]})]})})}const dlt=E.memo(function({data:t}){const n=t;return u.jsxs("div",{className:"relative w-full h-full rounded-2xl border-2 border-dashed border-[var(--color-text)]",children:[u.jsx("div",{className:"absolute inset-0 rounded-2xl",style:{background:n.color,opacity:.16}}),u.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:[u.jsx("span",{className:"truncate",children:n.label}),n.sub&&u.jsx("span",{className:"font-normal text-[var(--color-text-muted)]",children:n.sub})]})]})});function ult(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 hlt={task:olt,waveBox:dlt},wJ="sps.flow.lastProject",MJ="sps.flow.mode";function _J(e){return(e.labels??[]).includes("NEEDS-FIX")?"stuck":e.state==="Done"?"done":e.state==="Inprogress"?"doing":"todo"}function plt(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 E1=260,C1=158,rO=28,yD=E1+120,MH=C1+28,SJ=16,NJ=44,gD=60,_H=100,EJ=["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 Ih(e){const t=new Map;for(const n of e){const i=typeof n.order=="number"?n.order:Number(n.seq),a=t.get(i)??[];a.push(n),t.set(i,a)}return[...t.entries()].sort((n,i)=>n[0]-i[0]).map(([,n])=>n.sort((i,a)=>i.seq-a.seq))}function flt(e,t,n){const i=t.get(e);return i&&!n.some(a=>ile(i,a))?i:mlt(n)}function CJ(e){const t=new Map;return Ih(e).forEach((n,i)=>{n.forEach((a,r)=>{t.set(String(a.seq),{x:gD+i*yD,y:_H+r*MH})})}),t}function ile(e,t){return Math.abs(e.x-t.x)<E1+rO&&Math.abs(e.y-t.y)<C1+rO}function mlt(e){for(let t=0;t<80;t+=1)for(let n=0;n<8;n+=1){const i={x:60+n*(E1+rO),y:60+t*(C1+rO)};if(!e.some(a=>ile(i,a)))return i}return{x:60,y:60}}function LJ(e){return{x:e.position.x+E1/2,y:e.position.y+C1/2}}function ylt(e,t,n){const i=n.x-t.x,a=n.y-t.y,r=i*i+a*a;if(r===0)return Math.hypot(e.x-t.x,e.y-t.y);let s=((e.x-t.x)*i+(e.y-t.y)*a)/r;return s=Math.max(0,Math.min(1,s)),Math.hypot(e.x-(t.x+s*i),e.y-(t.y+s*a))}function glt(){var ke,et,zt,Yt;const e=Ze(),t=Rt(),n=P1(),{confirm:i}=ni(),{screenToFlowPosition:a,fitView:r}=YO(),s=E.useRef([]),[c,d]=E.useState(()=>localStorage.getItem(wJ)??""),[h,m]=E.useState(()=>localStorage.getItem(MJ)==="lanes"?"lanes":"free"),[f,k]=E.useState(!1),[g,b,v]=Est([]),[w,S,C]=Cst([]),[M,L]=E.useState(null),[j,A]=E.useState(null),[I,T]=E.useState(!1),[P,D]=E.useState(""),[q,H]=E.useState(null),[K,R]=E.useState(null),[z,$]=E.useState(0),X=E.useRef({}),Q=E.useRef(w);Q.current=w;const W=E.useRef(g);W.current=g;const B=E.useRef(null),V=E.useRef(null),Y=E.useRef(new Set),F=E.useRef(""),ae=E.useRef(null);Jre(c||null);const xe=nt({queryKey:["cards",c],queryFn:()=>Xre(c),enabled:!!c,refetchInterval:3e3}),de=((ke=xe.data)==null?void 0:ke.data)??[],ce=((Yt=(zt=(et=nt({queryKey:["projects"],queryFn:Vs,refetchInterval:3e3}).data)==null?void 0:et.data)==null?void 0:zt.find(ye=>ye.name===c))==null?void 0:Yt.pipelineStatus)==="running",me=E.useMemo(()=>{const ye={};for(const se of de)ye[String(se.seq)]=_J(se);return ye},[de]),je=E.useMemo(()=>{if(h!=="lanes")return[];const ye=Ih(de),se=[];for(let Le=1;Le<ye.length;Le+=1)for(const Ae of ye[Le-1]??[])for(const Je of ye[Le]??[])se.push({id:`w${Ae.seq}-${Je.seq}`,source:String(Ae.seq),target:String(Je.seq),sourceHandle:"r",targetHandle:"l",animated:!1,selectable:!1,deletable:!1});return se},[h,de]),ie=E.useMemo(()=>(h==="lanes"?je:w).map(ye=>{const se=plt(me[ye.target]);return ye.selected?{...ye,...se,style:{...se.style,strokeWidth:6}}:{...ye,...se}}),[h,je,w,me]),le=E.useCallback(()=>{t.invalidateQueries({queryKey:["cards",c]})},[t,c]),be=E.useCallback(()=>{!c||B.current!==c||(ae.current&&clearTimeout(ae.current),ae.current=setTimeout(()=>{ilt(c,{positions:X.current,edges:Q.current.map(ye=>({id:ye.id,source:ye.source,target:ye.target,sourceHandle:ye.sourceHandle??null,targetHandle:ye.targetHandle??null}))}).catch(()=>{})},600))},[c]);E.useEffect(()=>{if(B.current=null,L(null),R(null),X.current={},Y.current=new Set,F.current="",b([]),S([]),!c)return;localStorage.setItem(wJ,c);let ye=!1;return nlt(c).then(se=>{ye||(X.current=se.positions??{},S((se.edges??[]).map(Le=>({id:Le.id,source:Le.source,target:Le.target,sourceHandle:Le.sourceHandle??void 0,targetHandle:Le.targetHandle??void 0,animated:!1}))))}).catch(()=>{}).finally(()=>{ye||(B.current=c,$(se=>se+1))}),()=>{ye=!0}},[c,b,S]),E.useEffect(()=>{if(!c||B.current!==c)return;const ye=`${h}|`+de.map(He=>`${He.seq}:${He.title}:${He.state}:${He.order}:${(He.skills??[]).join("|")}`).join(",");if(ye===F.current)return;F.current=ye;const se=He=>({seq:String(He.seq),title:He.title,skills:(He.skills??[]).join(", "),labels:(He.labels??[]).join(", "),status:_J(He),label:He.title,desc:"",...He.kind?{kind:He.kind}:{},...He.tool?{tool:He.tool}:{}});if(h==="lanes"){const He=Ih(de),Pt=He.map(($t,J)=>({id:`wave-${J}`,type:"waveBox",position:{x:gD+J*yD-SJ,y:_H-NJ},data:{label:e("flow.lane.wave",{n:J+1}),sub:$t.length>1?e("flow.lane.parallel",{n:$t.length}):"",color:EJ[J%EJ.length]},style:{width:E1+SJ*2,height:NJ+($t.length-1)*MH+C1+14},draggable:!1,selectable:!1,zIndex:0})),Ut=He.flatMap(($t,J)=>$t.map((Me,Pe)=>({id:String(Me.seq),type:"task",position:{x:gD+J*yD,y:_H+Pe*MH},deletable:!1,zIndex:1,data:se(Me)})));b([...Pt,...Ut]);return}const Le=new Map(W.current.map(He=>[He.id,He.position])),Ae=[];for(const He of de){const Pt=Le.get(String(He.seq))??X.current[String(He.seq)];Pt&&Ae.push(Pt)}const Je=CJ(de);let ot=!1;const mt=de.map(He=>{const Pt=String(He.seq);let Ut=Le.get(Pt)??X.current[Pt];return Ut||(Ut=flt(Pt,Je,Ae),Ae.push(Ut),ot=!0),X.current[Pt]=Ut,{id:Pt,type:"task",position:Ut,deletable:!1,data:se(He)}});b(mt),ot&&be()},[de,c,h,z,b,be,e]),E.useEffect(()=>{if(B.current!==c)return;const ye=new Set(de.map(se=>String(se.seq)));S(se=>{const Le=se.filter(Ae=>ye.has(Ae.source)&&ye.has(Ae.target));return Le.length!==se.length&&be(),Le.length===se.length?se:Le})},[de,c,S,be]),E.useEffect(()=>{if(!c||B.current!==c||h!=="free"||de.length<2)return;const ye=Ih(de),se=[];for(let Je=1;Je<ye.length;Je+=1)for(const ot of ye[Je-1]??[])for(const mt of ye[Je]??[])se.push({id:`seed-${ot.seq}-${mt.seq}`,source:String(ot.seq),target:String(mt.seq),sourceHandle:"r",targetHandle:"l",animated:!1});const Le=Q.current,Ae=V.current!==c;if(V.current=c,Ae&&Le.length===0)se.length>0&&(S(se),be());else{const Je=new Set;for(const He of Le)Je.add(He.source),Je.add(He.target);const ot=new Set(Le.map(He=>`${He.source}->${He.target}`)),mt=new Set(de.map(He=>String(He.seq)).filter(He=>!Y.current.has(He)&&!Je.has(He)));if(mt.size>0){const He=se.filter(Pt=>(mt.has(Pt.source)||mt.has(Pt.target))&&!ot.has(`${Pt.source}->${Pt.target}`));He.length>0&&(S([...Le,...He]),be())}}Y.current=new Set(de.map(Je=>String(Je.seq)))},[de,c,h,z,S,be]);const pe=E.useCallback(ye=>{if(v(ye),h!=="free")return;let se=!1;for(const Le of ye)Le.type==="position"&&Le.position&&(X.current[Le.id]=Le.position,se=!0);se&&be()},[v,be,h]),ne=E.useCallback(ye=>{h==="free"&&(S(se=>Ese({...ye,animated:!1},se)),be())},[S,be,h]),we=E.useCallback(()=>{if(h!=="free"||de.length===0)return;const ye=Ih(de),se=Object.fromEntries(CJ(de)),Le=[];ye.forEach((Ae,Je)=>{if(Je>0)for(const ot of ye[Je-1]??[])for(const mt of Ae)Le.push({id:`seed-${ot.seq}-${mt.seq}`,source:String(ot.seq),target:String(mt.seq),sourceHandle:"r",targetHandle:"l",animated:!1})}),X.current={...X.current,...se},b(Ae=>Ae.map(Je=>se[Je.id]?{...Je,position:se[Je.id]}:Je)),S(Le),be(),setTimeout(()=>r({padding:.2,duration:300}),60)},[h,de,b,S,be,r]),Be=E.useCallback(async ye=>{if(!await i({title:e("flow.confirm.deleteTitle"),body:e("flow.confirm.deleteBody",{seq:ye}),danger:!0,confirm:e("flow.node.delete")}))return;D("");const Le=Q.current.filter(Ae=>Ae.source===String(ye)||Ae.target===String(ye)).map(Ae=>({...Ae}));try{await Qre(c,ye),s.current.push({seq:ye,edges:Le})}catch(Ae){D(Ae instanceof Error?Ae.message:String(Ae))}finally{L(Ae=>Ae===ye?null:Ae),A(Ae=>Ae===ye?null:Ae),F.current="",$(Ae=>Ae+1),le()}},[c,i,e,le]),Oe=E.useCallback(async()=>{const ye=s.current.pop();if(ye){D("");try{await GZe(c,ye.seq),S(se=>{const Le=new Set(se.map(Ae=>Ae.id));return[...se,...ye.edges.filter(Ae=>!Le.has(Ae.id))]}),be(),le()}catch(se){D(se instanceof Error?se.message:String(se))}}},[c,S,be,le]),ft=E.useCallback((ye,se)=>{var ot;if(h!=="free"||se.isValid)return;const Le=se.fromNode;if(!Le||!c)return;const Ae="changedTouches"in ye?ye.changedTouches[0]:ye;if(!Ae)return;const Je=a({x:Ae.clientX,y:Ae.clientY});H({fromId:Le.id,fromHandle:((ot=se.fromHandle)==null?void 0:ot.id)??null,clientX:Ae.clientX,clientY:Ae.clientY,flowX:Je.x,flowY:Je.y})},[h,c,a]),it=E.useCallback(async()=>{const ye=q;if(H(null),!(!ye||!c))try{const se=await nH(c,{title:`${e("flow.node.default")} ${de.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),Le=ult(se);if(Le==null)return;const Ae=String(Le);X.current[Ae]={x:ye.flowX-E1/2,y:ye.flowY-C1/2},S(Je=>[...Je,{id:`e-${ye.fromId}-${Ae}-drop`,source:ye.fromId,target:Ae,sourceHandle:ye.fromHandle??void 0,animated:!1}]),be(),le()}catch(se){D(se instanceof Error?se.message:String(se))}},[q,c,de.length,S,be,e,le]);E.useEffect(()=>{if(!q)return;const ye=se=>{se.key==="Escape"&&H(null)};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},[q]);const jt=E.useCallback((ye,se)=>{h==="free"&&(S(Le=>not(ye,se,Le)),be())},[h,S,be]);E.useEffect(()=>{const ye=se=>{if(se.key!=="Delete"&&se.key!=="Backspace"||j!=null)return;const Le=se.target;Le&&(Le.tagName==="INPUT"||Le.tagName==="TEXTAREA"||Le.isContentEditable)||M!=null&&(se.preventDefault(),Be(M))};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},[M,j,Be]),E.useEffect(()=>{const ye=se=>{if(!(se.metaKey||se.ctrlKey)||se.key!=="z"&&se.key!=="Z"||j!=null)return;const Le=se.target;Le&&(Le.tagName==="INPUT"||Le.tagName==="TEXTAREA"||Le.isContentEditable)||(se.preventDefault(),Oe())};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},[j,Oe]);const St=E.useCallback(async ye=>{if(c){k(!0),D("");try{const se=new Map(de.map(Le=>[Le.seq,Le.order]));for(let Le=0;Le<ye.length;Le+=1)for(const Ae of ye[Le]??[])se.get(Ae)!==Le+1&&await KD(c,Ae,{order:Le+1});le()}catch(se){D(se instanceof Error?se.message:String(se))}finally{k(!1)}}},[c,de,le]),yt=E.useCallback(ye=>{const se=Number(ye.id);if(!Number.isInteger(se))return;const Le=Ih(de).map(mt=>mt.map(He=>He.seq)),Ae=(ye.position.x-gD)/yD,Je=Math.round(Ae),ot=Le.map(mt=>mt.filter(He=>He!==se));if(Je>=0&&Je<Le.length&&Math.abs(Ae-Je)<=.35)ot[Je].push(se);else{const mt=Math.max(0,Math.min(ot.length,Math.ceil(Ae)));ot.splice(mt,0,[se])}St(ot.filter(mt=>mt.length>0)).finally(()=>{F.current="",$(mt=>mt+1)})},[de,St]),Te=E.useCallback((ye,se)=>{if(h==="lanes"){yt(se);return}const Le=new Map(W.current.map(He=>[He.id,He])),Ae={x:se.position.x+E1/2,y:se.position.y+C1/2};let Je=null,ot=40;for(const He of Q.current){if(He.source===se.id||He.target===se.id)continue;const Pt=Le.get(He.source),Ut=Le.get(He.target);if(!Pt||!Ut)continue;const $t=ylt(Ae,LJ(Pt),LJ(Ut));$t<ot&&(ot=$t,Je=He)}if(!Je)return;const mt=Je;S(He=>[...He.filter(Pt=>Pt.id!==mt.id),{id:`e-${mt.source}-${se.id}-${mt.id}`,source:mt.source,target:se.id,animated:!1},{id:`e-${se.id}-${mt.target}-${mt.id}`,source:se.id,target:mt.target,animated:!1}]),be()},[h,yt,S,be]),Xe=E.useCallback(ye=>{m(ye),localStorage.setItem(MJ,ye)},[]);E.useEffect(()=>{const ye=setTimeout(()=>{r({padding:.2,duration:300})},80);return()=>clearTimeout(ye)},[h,r]);const re=async()=>{if(c){D("");try{await nH(c,{title:`${e("flow.node.default")} ${de.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),le()}catch(ye){D(ye instanceof Error?ye.message:String(ye))}}},_e=async()=>{if(D(""),R(null),!c)return D(e("flow.err.noProject"));if(de.length===0)return D(e("flow.err.noNodes"));T(!0);try{const ye=de.filter(Ae=>Ae.state==="Planning"),se=ye.length;let Le=0;R({phase:"creating",made:Le,total:se});for(const Ae of ye)await KD(c,Ae.seq,{state:"Backlog",labels:Array.from(new Set([...Ae.labels??[],"AI-PIPELINE"]))}),Le+=1,R({phase:"creating",made:Le,total:se});R({phase:"starting",made:Le,total:se}),await Zre(c),le(),R({phase:"done",made:Le,total:se})}catch(ye){D(ye instanceof Error?ye.message:String(ye))}finally{T(!1)}},Re=xe.isLoading&&!!c;return u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("header",{className:"flex items-center gap-3 flex-wrap px-4 py-3 border-b border-[var(--surface-card-border)]",children:[u.jsxs("h1",{className:"text-lg font-[family-name:var(--font-heading)] flex items-center gap-2",children:[u.jsx(Gh,{size:18,strokeWidth:2.4}),e("nav.arrange")]}),u.jsx(eoe,{current:c,onChange:d}),u.jsxs("div",{className:"flex gap-1",role:"group","aria-label":e("flow.mode.aria"),children:[u.jsxs("button",{type:"button",className:["nb-btn",h==="free"?"nb-btn-primary":""].join(" "),"aria-pressed":h==="free",onClick:()=>Xe("free"),children:[u.jsx(Gh,{size:14,strokeWidth:2.4})," ",e("flow.mode.free")]}),u.jsxs("button",{type:"button",className:["nb-btn",h==="lanes"?"nb-btn-primary":""].join(" "),"aria-pressed":h==="lanes",onClick:()=>Xe("lanes"),children:[u.jsx(ys,{size:14,strokeWidth:2.4})," ",e("flow.mode.lanes")]})]}),Re&&u.jsx(lt,{size:15,className:"animate-spin text-[var(--color-text-muted)]"}),u.jsxs("button",{type:"button",className:"nb-btn",onClick:()=>void re(),disabled:!c||Re,children:[u.jsx(jn,{size:15,strokeWidth:2.4})," ",e("flow.addNode")]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta ml-auto",onClick:()=>void _e(),disabled:I||ce||Re||!c,title:ce?e("flow.pipelineRunning"):void 0,children:[I||ce?u.jsx(lt,{size:15,className:"animate-spin"}):u.jsx(Os,{size:15,strokeWidth:2.4}),e(I?"flow.running":ce?"flow.pipelineRunning":"flow.run")]})]}),!c&&u.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&&u.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}),K&&u.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:[K.phase==="creating"&&u.jsxs("span",{children:[e("flow.status.creating")," ",K.made,"/",K.total,"…"]}),K.phase==="starting"&&u.jsx("span",{children:e("flow.status.starting")}),K.phase==="done"&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-[var(--color-running)] font-bold",children:["✓ ",e("flow.status.done").replace("{n}",String(K.made))]}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>n(`/board?project=${encodeURIComponent(c)}`),children:e("flow.goBoard")})]})]}),u.jsx("div",{className:"flex-1 min-h-0 arrange-flow-shell",children:u.jsxs(Nst,{nodes:g,edges:ie,nodeTypes:hlt,connectionRadius:160,nodesConnectable:h==="free",edgesReconnectable:h==="free",deleteKeyCode:j!=null?null:["Delete","Backspace"],onNodesChange:pe,onEdgesChange:ye=>{h==="free"&&(C(ye),be())},onConnect:ne,onConnectEnd:ft,onReconnect:jt,onNodeClick:(ye,se)=>{const Le=Number(se.id);Number.isInteger(Le)&&A(Le)},onNodeDragStop:Te,onSelectionChange:({nodes:ye})=>{const se=ye[0]?Number(ye[0].id):null;L(se!=null&&Number.isInteger(se)?se:null)},fitView:!0,children:[u.jsx(Tst,{variant:Do.Dots,gap:18,size:1}),u.jsx(qst,{children:h==="free"&&u.jsx(a0,{onClick:we,title:e("flow.tidy"),"aria-label":e("flow.tidy"),children:u.jsx(Xh,{size:14,strokeWidth:2.4})})})]})}),q&&u.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>H(null),children:u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta absolute -translate-x-1/2 -translate-y-1/2",style:{left:q.clientX,top:q.clientY},onClick:ye=>{ye.stopPropagation(),it()},children:[u.jsx(jn,{size:14,strokeWidth:2.4})," ",e("flow.pending.create")]})}),f&&u.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:[u.jsx(lt,{size:12,className:"animate-spin"})," ",e("flow.lane.applying")]}),u.jsx("footer",{className:"px-4 py-2 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)]",children:e(h==="free"?"flow.hint":"flow.lane.hint")}),j!=null&&c&&u.jsx(clt,{project:c,seq:j,onClose:()=>A(null),onChanged:le,onDelete:ye=>void Be(ye)})]})}function klt(){return u.jsx(Jse,{children:u.jsx(glt,{})})}function xlt(){const e=Ze();return u.jsxs("div",{className:"nb-card max-w-2xl mt-12",children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold mb-2",children:e("notFound.title")}),u.jsx("p",{className:"text-[var(--color-text-muted)] mb-6",children:e("notFound.body")}),u.jsx(Sp,{to:"/",className:"nb-btn nb-btn-mint inline-flex",children:e("notFound.home")})]})}const blt=E.lazy(()=>G1e(()=>import("./ShowcasePage-BwvNPx33.js"),__vite__mapDeps([0,1])));function vlt(){return u.jsx(u$e,{children:u.jsxs(c1e,{children:[u.jsx(ei,{path:"/showcase",element:u.jsx(E.Suspense,{fallback:null,children:u.jsx(blt,{})})}),u.jsxs(ei,{element:u.jsx(GX,{contentMode:"workspace"}),children:[u.jsx(ei,{index:!0,element:u.jsx(Z$,{})}),u.jsx(ei,{path:"/projects",element:u.jsx(QQ,{})}),u.jsx(ei,{path:"/projects/:name",element:u.jsx(QQ,{})}),u.jsx(ei,{path:"/board",element:u.jsx(lJe,{})}),u.jsx(ei,{path:"/prompts",element:u.jsx(wJe,{})}),u.jsx(ei,{path:"/chat",element:u.jsx(Z$,{})}),u.jsx(ei,{path:"/chat/:sessionId",element:u.jsx(Z$,{})}),u.jsx(ei,{path:"/arrange",element:u.jsx(klt,{})})]}),u.jsxs(ei,{element:u.jsx(GX,{contentMode:"document"}),children:[u.jsx(ei,{path:"/projects/new",element:u.jsx(Wre,{})}),u.jsx(ei,{path:"/skills",element:u.jsx(mJe,{})}),u.jsx(ei,{path:"/help",element:u.jsx(iet,{})}),u.jsx(ei,{path:"/system",element:u.jsx(qJe,{})}),u.jsx(ei,{path:"/memory",element:u.jsx(ZJe,{})}),u.jsx(ei,{path:"/plugins",element:u.jsx(Bet,{})}),u.jsx(ei,{path:"*",element:u.jsx(xlt,{})})]})]})})}function wlt(){pet(),(async()=>{try{const e=await soe();await Promise.all(e.filter(t=>t.clientFormat==="sps"&&!t.disabled).map(t=>fet(t.key)))}catch(e){console.error("插件前端加载失败(不影响 console 本体):",e)}})()}d$e();jTe();wlt();const Mlt=new pee({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!1}}}),ale=document.getElementById("root");if(!ale)throw new Error("#root not found");bde.createRoot(ale).render(u.jsx(E.StrictMode,{children:u.jsx(bTe,{children:u.jsx(fee,{client:Mlt,children:u.jsx(R1e,{children:u.jsx(_lt,{children:u.jsx(vlt,{})})})})})}));function _lt({children:e}){const t=Ze();return u.jsx(zne,{defaults:{confirm:t("dialog.confirm.default"),cancel:t("dialog.cancel.default"),alert:t("dialog.alert.default")},children:e})}export{Hh as A,h0 as C,Vh as E,Er as G,Sp as L,v9 as O,$r as P,bL as S,MR as W,k1 as a,UL as b,W4 as c,o0 as d,gk as e,u as j,E as r,Xee as u};
8659
+ `).trim()}function llt(e,t){return t.includes("NEEDS-FIX")?"stuck":e==="Done"?"done":e==="Inprogress"?"doing":"todo"}function clt({project:e,seq:t,onClose:n,onChanged:i,onDelete:a}){var je,ie;const r=Ze(),[s,c]=E.useState(!0),[d,h]=E.useState(!1),[m,f]=E.useState(""),[k,g]=E.useState(""),[b,v]=E.useState(new Set),[w,S]=E.useState(""),[C,M]=E.useState("todo"),[L,j]=E.useState(null),[A,I]=E.useState(""),[T,P]=E.useState(void 0),[D,q]=E.useState(void 0),[H,K]=E.useState(void 0),[R,z]=E.useState(void 0),[$,X]=E.useState({value:null,error:"",dirty:!1}),[Q,W]=E.useState(null),[B,V]=E.useState(null),Y=B??T,F=Y==="tool"||Y==="join",ae=nt({queryKey:["skills-all",e],queryFn:()=>zO(e),enabled:!F}),xe=((je=ae.data)==null?void 0:je.data)??[],de=nt({queryKey:["capabilities",e],queryFn:()=>lV(e),enabled:F});E.useEffect(()=>{const le=be=>{be.key==="Escape"&&n()};return window.addEventListener("keydown",le),()=>window.removeEventListener("keydown",le)},[n]),E.useEffect(()=>{let le=!1;return c(!0),Yre(e,t).then(be=>{le||(f(be.title),v(new Set(be.skills??[])),g(slt(be.body)),S(be.state),M(llt(be.state,be.labels??[])),j(typeof be.order=="number"?be.order:null),P(be.kind),q(be.tool),W(null),V(null),K(be.input),z(be.toolResult))}).catch(()=>{}).finally(()=>{le||c(!1)}),()=>{le=!0}},[e,t]);const Ee=le=>{v(be=>{const pe=new Set(be);return pe.has(le)?pe.delete(le):pe.add(le),pe})},ce=async()=>{if(I(""),F&&$.error){I($.error);return}h(!0);try{await KD(e,t,{title:m.trim()||r("flow.node.default"),...B?{kind:B}:{},...F?{...Q||B==="tool"?{tool:Q??D??"art.inspect"}:{},...$.dirty||B==="tool"?{input:$.value??{in:""}}:{}}:{description:k,skills:[...b]}}),i(),n()}catch(le){I(le instanceof Error?le.message:String(le)),h(!1)}},me=()=>a(t);return u.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:u.jsxs("div",{className:"nb-card w-full max-w-4xl flex flex-col bg-[var(--color-bg)]",style:{maxHeight:"calc(100vh - 48px)"},onClick:le=>le.stopPropagation(),children:[u.jsxs("header",{className:"flex items-start justify-between gap-4 mb-4 flex-shrink-0",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.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&&u.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:[u.jsx("span",{className:"w-2.5 h-2.5 rounded-full inline-block border border-[var(--color-text)]",style:{background:wH[C]??"gray"}}),w]}),L!=null&&u.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:L})})]}),u.jsx("button",{onClick:n,className:"nb-btn nb-btn-mint p-2 flex-shrink-0","aria-label":r("flow.node.close"),type:"button",children:u.jsx(nn,{size:14,strokeWidth:3})})]}),s?u.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--color-text-muted)] py-10 justify-center",children:[u.jsx(lt,{size:16,className:"animate-spin"})," …"]}):u.jsxs(u.Fragment,{children:[A&&u.jsx("div",{className:"text-sm text-[var(--color-crashed)] mb-3",children:A}),u.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[u.jsx("span",{className:"text-sm font-bold",children:r("card.kind.label")}),["worker","tool"].map(le=>u.jsx("button",{type:"button",onClick:()=>V(le===(T??"worker")?null:le),"aria-pressed":Y===le||le==="worker"&&!F,className:["px-2.5 py-1 text-xs rounded-full border-2 transition-all font-[family-name:var(--font-mono)]",(le==="tool"?F:!F)?"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(le==="tool"?"card.kind.tool":"card.kind.worker")},le)),B&&u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:r("card.kind.pending")})]}),F&&($.dirty||Q)&&R&&u.jsxs("div",{className:"mb-3 text-xs text-[var(--color-text-muted)]",children:["⚠️ ",r("tool.card.staleWarn")]}),u.jsxs("div",{className:F?"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:[u.jsxs("label",{className:F?"flex flex-col gap-1.5":"hidden",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),u.jsx("input",{className:"nb-input w-full text-base font-semibold",value:m,onChange:le=>f(le.target.value)})]}),F&&u.jsx(UD,{tool:Q??D,input:H,toolResult:R,capabilities:((ie=de.data)==null?void 0:ie.data)??[],onChange:X,onToolChange:W}),!F&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex min-h-0 flex-col gap-4 md:overflow-y-auto md:pr-1",children:[u.jsxs("label",{className:"flex flex-col gap-1.5",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.title")}),u.jsx("input",{className:"nb-input w-full text-base font-semibold",value:m,onChange:le=>f(le.target.value),autoFocus:!0})]}),u.jsxs("label",{className:"flex flex-1 min-h-0 flex-col gap-1.5",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.desc")}),u.jsx("textarea",{className:"nb-input w-full flex-1 min-h-0",style:{minHeight:200,resize:"vertical"},value:k,onChange:le=>g(le.target.value)})]})]}),u.jsxs("section",{className:"flex min-h-[200px] flex-col gap-2 md:min-h-0 md:overflow-hidden",children:[u.jsx("span",{className:"text-sm font-bold",children:r("flow.node.skills")}),u.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:u.jsxs("div",{className:"scroll-frame-body h-full p-2",children:[ae.isLoading&&u.jsx(lt,{size:14,className:"animate-spin text-[var(--color-text-muted)]"}),xe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:xe.map(le=>{const be=b.has(le.name);return u.jsx("button",{type:"button",onClick:()=>Ee(le.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",be?"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":be,children:le.name},le.name)})})]})}),b.size>0&&u.jsx("p",{className:"max-h-14 overflow-y-auto break-words text-xs text-[var(--color-text-muted)]",children:[...b].join(", ")})]})]})]}),u.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:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-danger",onClick:()=>void me(),disabled:d,children:[u.jsx(Mi,{size:14,strokeWidth:2.4})," ",r("flow.node.delete")]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta",onClick:()=>void ce(),disabled:d||F&&$.error!=="",children:[d?u.jsx(lt,{size:14,className:"animate-spin"}):null,r("flow.node.save")]})]})]})]})})}const dlt=E.memo(function({data:t}){const n=t;return u.jsxs("div",{className:"relative w-full h-full rounded-2xl border-2 border-dashed border-[var(--color-text)]",children:[u.jsx("div",{className:"absolute inset-0 rounded-2xl",style:{background:n.color,opacity:.16}}),u.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:[u.jsx("span",{className:"truncate",children:n.label}),n.sub&&u.jsx("span",{className:"font-normal text-[var(--color-text-muted)]",children:n.sub})]})]})});function ult(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 hlt={task:olt,waveBox:dlt},wJ="sps.flow.lastProject",MJ="sps.flow.mode";function _J(e){return(e.labels??[]).includes("NEEDS-FIX")?"stuck":e.state==="Done"?"done":e.state==="Inprogress"?"doing":"todo"}function plt(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 E1=260,C1=158,rO=28,yD=E1+120,MH=C1+28,SJ=16,NJ=44,gD=60,_H=100,EJ=["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 Ih(e){const t=new Map;for(const n of e){const i=typeof n.order=="number"?n.order:Number(n.seq),a=t.get(i)??[];a.push(n),t.set(i,a)}return[...t.entries()].sort((n,i)=>n[0]-i[0]).map(([,n])=>n.sort((i,a)=>i.seq-a.seq))}function flt(e,t,n){const i=t.get(e);return i&&!n.some(a=>ile(i,a))?i:mlt(n)}function CJ(e){const t=new Map;return Ih(e).forEach((n,i)=>{n.forEach((a,r)=>{t.set(String(a.seq),{x:gD+i*yD,y:_H+r*MH})})}),t}function ile(e,t){return Math.abs(e.x-t.x)<E1+rO&&Math.abs(e.y-t.y)<C1+rO}function mlt(e){for(let t=0;t<80;t+=1)for(let n=0;n<8;n+=1){const i={x:60+n*(E1+rO),y:60+t*(C1+rO)};if(!e.some(a=>ile(i,a)))return i}return{x:60,y:60}}function LJ(e){return{x:e.position.x+E1/2,y:e.position.y+C1/2}}function ylt(e,t,n){const i=n.x-t.x,a=n.y-t.y,r=i*i+a*a;if(r===0)return Math.hypot(e.x-t.x,e.y-t.y);let s=((e.x-t.x)*i+(e.y-t.y)*a)/r;return s=Math.max(0,Math.min(1,s)),Math.hypot(e.x-(t.x+s*i),e.y-(t.y+s*a))}function glt(){var ke,et,zt,Yt;const e=Ze(),t=Rt(),n=P1(),{confirm:i}=ni(),{screenToFlowPosition:a,fitView:r}=YO(),s=E.useRef([]),[c,d]=E.useState(()=>localStorage.getItem(wJ)??""),[h,m]=E.useState(()=>localStorage.getItem(MJ)==="lanes"?"lanes":"free"),[f,k]=E.useState(!1),[g,b,v]=Est([]),[w,S,C]=Cst([]),[M,L]=E.useState(null),[j,A]=E.useState(null),[I,T]=E.useState(!1),[P,D]=E.useState(""),[q,H]=E.useState(null),[K,R]=E.useState(null),[z,$]=E.useState(0),X=E.useRef({}),Q=E.useRef(w);Q.current=w;const W=E.useRef(g);W.current=g;const B=E.useRef(null),V=E.useRef(null),Y=E.useRef(new Set),F=E.useRef(""),ae=E.useRef(null);Jre(c||null);const xe=nt({queryKey:["cards",c],queryFn:()=>Xre(c),enabled:!!c,refetchInterval:3e3}),de=((ke=xe.data)==null?void 0:ke.data)??[],ce=((Yt=(zt=(et=nt({queryKey:["projects"],queryFn:Vs,refetchInterval:3e3}).data)==null?void 0:et.data)==null?void 0:zt.find(ye=>ye.name===c))==null?void 0:Yt.pipelineStatus)==="running",me=E.useMemo(()=>{const ye={};for(const se of de)ye[String(se.seq)]=_J(se);return ye},[de]),je=E.useMemo(()=>{if(h!=="lanes")return[];const ye=Ih(de),se=[];for(let Le=1;Le<ye.length;Le+=1)for(const Ae of ye[Le-1]??[])for(const Je of ye[Le]??[])se.push({id:`w${Ae.seq}-${Je.seq}`,source:String(Ae.seq),target:String(Je.seq),sourceHandle:"r",targetHandle:"l",animated:!1,selectable:!1,deletable:!1});return se},[h,de]),ie=E.useMemo(()=>(h==="lanes"?je:w).map(ye=>{const se=plt(me[ye.target]);return ye.selected?{...ye,...se,style:{...se.style,strokeWidth:6}}:{...ye,...se}}),[h,je,w,me]),le=E.useCallback(()=>{t.invalidateQueries({queryKey:["cards",c]})},[t,c]),be=E.useCallback(()=>{!c||B.current!==c||(ae.current&&clearTimeout(ae.current),ae.current=setTimeout(()=>{ilt(c,{positions:X.current,edges:Q.current.map(ye=>({id:ye.id,source:ye.source,target:ye.target,sourceHandle:ye.sourceHandle??null,targetHandle:ye.targetHandle??null}))}).catch(()=>{})},600))},[c]);E.useEffect(()=>{if(B.current=null,L(null),R(null),X.current={},Y.current=new Set,F.current="",b([]),S([]),!c)return;localStorage.setItem(wJ,c);let ye=!1;return nlt(c).then(se=>{ye||(X.current=se.positions??{},S((se.edges??[]).map(Le=>({id:Le.id,source:Le.source,target:Le.target,sourceHandle:Le.sourceHandle??void 0,targetHandle:Le.targetHandle??void 0,animated:!1}))))}).catch(()=>{}).finally(()=>{ye||(B.current=c,$(se=>se+1))}),()=>{ye=!0}},[c,b,S]),E.useEffect(()=>{if(!c||B.current!==c)return;const ye=`${h}|`+de.map(He=>`${He.seq}:${He.title}:${He.state}:${He.order}:${(He.skills??[]).join("|")}`).join(",");if(ye===F.current)return;F.current=ye;const se=He=>({seq:String(He.seq),title:He.title,skills:(He.skills??[]).join(", "),labels:(He.labels??[]).join(", "),status:_J(He),label:He.title,desc:"",...He.kind?{kind:He.kind}:{},...He.tool?{tool:He.tool}:{}});if(h==="lanes"){const He=Ih(de),Pt=He.map(($t,J)=>({id:`wave-${J}`,type:"waveBox",position:{x:gD+J*yD-SJ,y:_H-NJ},data:{label:e("flow.lane.wave",{n:J+1}),sub:$t.length>1?e("flow.lane.parallel",{n:$t.length}):"",color:EJ[J%EJ.length]},style:{width:E1+SJ*2,height:NJ+($t.length-1)*MH+C1+14},draggable:!1,selectable:!1,zIndex:0})),Ut=He.flatMap(($t,J)=>$t.map((Me,Pe)=>({id:String(Me.seq),type:"task",position:{x:gD+J*yD,y:_H+Pe*MH},deletable:!1,zIndex:1,data:se(Me)})));b([...Pt,...Ut]);return}const Le=new Map(W.current.map(He=>[He.id,He.position])),Ae=[];for(const He of de){const Pt=Le.get(String(He.seq))??X.current[String(He.seq)];Pt&&Ae.push(Pt)}const Je=CJ(de);let ot=!1;const mt=de.map(He=>{const Pt=String(He.seq);let Ut=Le.get(Pt)??X.current[Pt];return Ut||(Ut=flt(Pt,Je,Ae),Ae.push(Ut),ot=!0),X.current[Pt]=Ut,{id:Pt,type:"task",position:Ut,deletable:!1,data:se(He)}});b(mt),ot&&be()},[de,c,h,z,b,be,e]),E.useEffect(()=>{if(B.current!==c)return;const ye=new Set(de.map(se=>String(se.seq)));S(se=>{const Le=se.filter(Ae=>ye.has(Ae.source)&&ye.has(Ae.target));return Le.length!==se.length&&be(),Le.length===se.length?se:Le})},[de,c,S,be]),E.useEffect(()=>{if(!c||B.current!==c||h!=="free"||de.length<2)return;const ye=Ih(de),se=[];for(let Je=1;Je<ye.length;Je+=1)for(const ot of ye[Je-1]??[])for(const mt of ye[Je]??[])se.push({id:`seed-${ot.seq}-${mt.seq}`,source:String(ot.seq),target:String(mt.seq),sourceHandle:"r",targetHandle:"l",animated:!1});const Le=Q.current,Ae=V.current!==c;if(V.current=c,Ae&&Le.length===0)se.length>0&&(S(se),be());else{const Je=new Set;for(const He of Le)Je.add(He.source),Je.add(He.target);const ot=new Set(Le.map(He=>`${He.source}->${He.target}`)),mt=new Set(de.map(He=>String(He.seq)).filter(He=>!Y.current.has(He)&&!Je.has(He)));if(mt.size>0){const He=se.filter(Pt=>(mt.has(Pt.source)||mt.has(Pt.target))&&!ot.has(`${Pt.source}->${Pt.target}`));He.length>0&&(S([...Le,...He]),be())}}Y.current=new Set(de.map(Je=>String(Je.seq)))},[de,c,h,z,S,be]);const pe=E.useCallback(ye=>{if(v(ye),h!=="free")return;let se=!1;for(const Le of ye)Le.type==="position"&&Le.position&&(X.current[Le.id]=Le.position,se=!0);se&&be()},[v,be,h]),ne=E.useCallback(ye=>{h==="free"&&(S(se=>Ese({...ye,animated:!1},se)),be())},[S,be,h]),we=E.useCallback(()=>{if(h!=="free"||de.length===0)return;const ye=Ih(de),se=Object.fromEntries(CJ(de)),Le=[];ye.forEach((Ae,Je)=>{if(Je>0)for(const ot of ye[Je-1]??[])for(const mt of Ae)Le.push({id:`seed-${ot.seq}-${mt.seq}`,source:String(ot.seq),target:String(mt.seq),sourceHandle:"r",targetHandle:"l",animated:!1})}),X.current={...X.current,...se},b(Ae=>Ae.map(Je=>se[Je.id]?{...Je,position:se[Je.id]}:Je)),S(Le),be(),setTimeout(()=>r({padding:.2,duration:300}),60)},[h,de,b,S,be,r]),Be=E.useCallback(async ye=>{if(!await i({title:e("flow.confirm.deleteTitle"),body:e("flow.confirm.deleteBody",{seq:ye}),danger:!0,confirm:e("flow.node.delete")}))return;D("");const Le=Q.current.filter(Ae=>Ae.source===String(ye)||Ae.target===String(ye)).map(Ae=>({...Ae}));try{await Qre(c,ye),s.current.push({seq:ye,edges:Le})}catch(Ae){D(Ae instanceof Error?Ae.message:String(Ae))}finally{L(Ae=>Ae===ye?null:Ae),A(Ae=>Ae===ye?null:Ae),F.current="",$(Ae=>Ae+1),le()}},[c,i,e,le]),Oe=E.useCallback(async()=>{const ye=s.current.pop();if(ye){D("");try{await GZe(c,ye.seq),S(se=>{const Le=new Set(se.map(Ae=>Ae.id));return[...se,...ye.edges.filter(Ae=>!Le.has(Ae.id))]}),be(),le()}catch(se){D(se instanceof Error?se.message:String(se))}}},[c,S,be,le]),ft=E.useCallback((ye,se)=>{var ot;if(h!=="free"||se.isValid)return;const Le=se.fromNode;if(!Le||!c)return;const Ae="changedTouches"in ye?ye.changedTouches[0]:ye;if(!Ae)return;const Je=a({x:Ae.clientX,y:Ae.clientY});H({fromId:Le.id,fromHandle:((ot=se.fromHandle)==null?void 0:ot.id)??null,clientX:Ae.clientX,clientY:Ae.clientY,flowX:Je.x,flowY:Je.y})},[h,c,a]),it=E.useCallback(async()=>{const ye=q;if(H(null),!(!ye||!c))try{const se=await nH(c,{title:`${e("flow.node.default")} ${de.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),Le=ult(se);if(Le==null)return;const Ae=String(Le);X.current[Ae]={x:ye.flowX-E1/2,y:ye.flowY-C1/2},S(Je=>[...Je,{id:`e-${ye.fromId}-${Ae}-drop`,source:ye.fromId,target:Ae,sourceHandle:ye.fromHandle??void 0,animated:!1}]),be(),le()}catch(se){D(se instanceof Error?se.message:String(se))}},[q,c,de.length,S,be,e,le]);E.useEffect(()=>{if(!q)return;const ye=se=>{se.key==="Escape"&&H(null)};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},[q]);const jt=E.useCallback((ye,se)=>{h==="free"&&(S(Le=>not(ye,se,Le)),be())},[h,S,be]);E.useEffect(()=>{const ye=se=>{if(se.key!=="Delete"&&se.key!=="Backspace"||j!=null)return;const Le=se.target;Le&&(Le.tagName==="INPUT"||Le.tagName==="TEXTAREA"||Le.isContentEditable)||M!=null&&(se.preventDefault(),Be(M))};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},[M,j,Be]),E.useEffect(()=>{const ye=se=>{if(!(se.metaKey||se.ctrlKey)||se.key!=="z"&&se.key!=="Z"||j!=null)return;const Le=se.target;Le&&(Le.tagName==="INPUT"||Le.tagName==="TEXTAREA"||Le.isContentEditable)||(se.preventDefault(),Oe())};return window.addEventListener("keydown",ye),()=>window.removeEventListener("keydown",ye)},[j,Oe]);const St=E.useCallback(async ye=>{if(c){k(!0),D("");try{const se=new Map(de.map(Le=>[Le.seq,Le.order]));for(let Le=0;Le<ye.length;Le+=1)for(const Ae of ye[Le]??[])se.get(Ae)!==Le+1&&await KD(c,Ae,{order:Le+1});le()}catch(se){D(se instanceof Error?se.message:String(se))}finally{k(!1)}}},[c,de,le]),yt=E.useCallback(ye=>{const se=Number(ye.id);if(!Number.isInteger(se))return;const Le=Ih(de).map(mt=>mt.map(He=>He.seq)),Ae=(ye.position.x-gD)/yD,Je=Math.round(Ae),ot=Le.map(mt=>mt.filter(He=>He!==se));if(Je>=0&&Je<Le.length&&Math.abs(Ae-Je)<=.35)ot[Je].push(se);else{const mt=Math.max(0,Math.min(ot.length,Math.ceil(Ae)));ot.splice(mt,0,[se])}St(ot.filter(mt=>mt.length>0)).finally(()=>{F.current="",$(mt=>mt+1)})},[de,St]),Te=E.useCallback((ye,se)=>{if(h==="lanes"){yt(se);return}const Le=new Map(W.current.map(He=>[He.id,He])),Ae={x:se.position.x+E1/2,y:se.position.y+C1/2};let Je=null,ot=40;for(const He of Q.current){if(He.source===se.id||He.target===se.id)continue;const Pt=Le.get(He.source),Ut=Le.get(He.target);if(!Pt||!Ut)continue;const $t=ylt(Ae,LJ(Pt),LJ(Ut));$t<ot&&(ot=$t,Je=He)}if(!Je)return;const mt=Je;S(He=>[...He.filter(Pt=>Pt.id!==mt.id),{id:`e-${mt.source}-${se.id}-${mt.id}`,source:mt.source,target:se.id,animated:!1},{id:`e-${se.id}-${mt.target}-${mt.id}`,source:se.id,target:mt.target,animated:!1}]),be()},[h,yt,S,be]),Xe=E.useCallback(ye=>{m(ye),localStorage.setItem(MJ,ye)},[]);E.useEffect(()=>{const ye=setTimeout(()=>{r({padding:.2,duration:300})},80);return()=>clearTimeout(ye)},[h,r]);const re=async()=>{if(c){D("");try{await nH(c,{title:`${e("flow.node.default")} ${de.length+1}`,initialState:"Planning",labels:["AI-PIPELINE"]}),le()}catch(ye){D(ye instanceof Error?ye.message:String(ye))}}},_e=async()=>{if(D(""),R(null),!c)return D(e("flow.err.noProject"));if(de.length===0)return D(e("flow.err.noNodes"));T(!0);try{const ye=de.filter(Ae=>Ae.state==="Planning"),se=ye.length;let Le=0;R({phase:"creating",made:Le,total:se});for(const Ae of ye)await KD(c,Ae.seq,{state:"Backlog",labels:Array.from(new Set([...Ae.labels??[],"AI-PIPELINE"]))}),Le+=1,R({phase:"creating",made:Le,total:se});R({phase:"starting",made:Le,total:se}),await Zre(c),le(),R({phase:"done",made:Le,total:se})}catch(ye){D(ye instanceof Error?ye.message:String(ye))}finally{T(!1)}},Re=xe.isLoading&&!!c;return u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("header",{className:"flex items-center gap-3 flex-wrap px-4 py-3 border-b border-[var(--surface-card-border)]",children:[u.jsxs("h1",{className:"text-lg font-[family-name:var(--font-heading)] flex items-center gap-2",children:[u.jsx(Gh,{size:18,strokeWidth:2.4}),e("nav.arrange")]}),u.jsx(eoe,{current:c,onChange:d}),u.jsxs("div",{className:"flex gap-1",role:"group","aria-label":e("flow.mode.aria"),children:[u.jsxs("button",{type:"button",className:["nb-btn",h==="free"?"nb-btn-primary":""].join(" "),"aria-pressed":h==="free",onClick:()=>Xe("free"),children:[u.jsx(Gh,{size:14,strokeWidth:2.4})," ",e("flow.mode.free")]}),u.jsxs("button",{type:"button",className:["nb-btn",h==="lanes"?"nb-btn-primary":""].join(" "),"aria-pressed":h==="lanes",onClick:()=>Xe("lanes"),children:[u.jsx(ys,{size:14,strokeWidth:2.4})," ",e("flow.mode.lanes")]})]}),Re&&u.jsx(lt,{size:15,className:"animate-spin text-[var(--color-text-muted)]"}),u.jsxs("button",{type:"button",className:"nb-btn",onClick:()=>void re(),disabled:!c||Re,children:[u.jsx(jn,{size:15,strokeWidth:2.4})," ",e("flow.addNode")]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta ml-auto",onClick:()=>void _e(),disabled:I||ce||Re||!c,title:ce?e("flow.pipelineRunning"):void 0,children:[I||ce?u.jsx(lt,{size:15,className:"animate-spin"}):u.jsx(Os,{size:15,strokeWidth:2.4}),e(I?"flow.running":ce?"flow.pipelineRunning":"flow.run")]})]}),!c&&u.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&&u.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}),K&&u.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:[K.phase==="creating"&&u.jsxs("span",{children:[e("flow.status.creating")," ",K.made,"/",K.total,"…"]}),K.phase==="starting"&&u.jsx("span",{children:e("flow.status.starting")}),K.phase==="done"&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-[var(--color-running)] font-bold",children:["✓ ",e("flow.status.done").replace("{n}",String(K.made))]}),u.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>n(`/board?project=${encodeURIComponent(c)}`),children:e("flow.goBoard")})]})]}),u.jsx("div",{className:"flex-1 min-h-0 arrange-flow-shell",children:u.jsxs(Nst,{nodes:g,edges:ie,nodeTypes:hlt,connectionRadius:160,nodesConnectable:h==="free",edgesReconnectable:h==="free",deleteKeyCode:j!=null?null:["Delete","Backspace"],onNodesChange:pe,onEdgesChange:ye=>{h==="free"&&(C(ye),be())},onConnect:ne,onConnectEnd:ft,onReconnect:jt,onNodeClick:(ye,se)=>{const Le=Number(se.id);Number.isInteger(Le)&&A(Le)},onNodeDragStop:Te,onSelectionChange:({nodes:ye})=>{const se=ye[0]?Number(ye[0].id):null;L(se!=null&&Number.isInteger(se)?se:null)},fitView:!0,children:[u.jsx(Tst,{variant:Do.Dots,gap:18,size:1}),u.jsx(qst,{children:h==="free"&&u.jsx(a0,{onClick:we,title:e("flow.tidy"),"aria-label":e("flow.tidy"),children:u.jsx(Xh,{size:14,strokeWidth:2.4})})})]})}),q&&u.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>H(null),children:u.jsxs("button",{type:"button",className:"nb-btn nb-btn-cta absolute -translate-x-1/2 -translate-y-1/2",style:{left:q.clientX,top:q.clientY},onClick:ye=>{ye.stopPropagation(),it()},children:[u.jsx(jn,{size:14,strokeWidth:2.4})," ",e("flow.pending.create")]})}),f&&u.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:[u.jsx(lt,{size:12,className:"animate-spin"})," ",e("flow.lane.applying")]}),u.jsx("footer",{className:"px-4 py-2 text-xs text-[var(--color-text-muted)] border-t border-[var(--surface-card-border)]",children:e(h==="free"?"flow.hint":"flow.lane.hint")}),j!=null&&c&&u.jsx(clt,{project:c,seq:j,onClose:()=>A(null),onChanged:le,onDelete:ye=>void Be(ye)})]})}function klt(){return u.jsx(Jse,{children:u.jsx(glt,{})})}function xlt(){const e=Ze();return u.jsxs("div",{className:"nb-card max-w-2xl mt-12",children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold mb-2",children:e("notFound.title")}),u.jsx("p",{className:"text-[var(--color-text-muted)] mb-6",children:e("notFound.body")}),u.jsx(Sp,{to:"/",className:"nb-btn nb-btn-mint inline-flex",children:e("notFound.home")})]})}const blt=E.lazy(()=>G1e(()=>import("./ShowcasePage-DjCtHHhI.js"),__vite__mapDeps([0,1])));function vlt(){return u.jsx(u$e,{children:u.jsxs(c1e,{children:[u.jsx(ei,{path:"/showcase",element:u.jsx(E.Suspense,{fallback:null,children:u.jsx(blt,{})})}),u.jsxs(ei,{element:u.jsx(GX,{contentMode:"workspace"}),children:[u.jsx(ei,{index:!0,element:u.jsx(Z$,{})}),u.jsx(ei,{path:"/projects",element:u.jsx(QQ,{})}),u.jsx(ei,{path:"/projects/:name",element:u.jsx(QQ,{})}),u.jsx(ei,{path:"/board",element:u.jsx(lJe,{})}),u.jsx(ei,{path:"/prompts",element:u.jsx(wJe,{})}),u.jsx(ei,{path:"/chat",element:u.jsx(Z$,{})}),u.jsx(ei,{path:"/chat/:sessionId",element:u.jsx(Z$,{})}),u.jsx(ei,{path:"/arrange",element:u.jsx(klt,{})})]}),u.jsxs(ei,{element:u.jsx(GX,{contentMode:"document"}),children:[u.jsx(ei,{path:"/projects/new",element:u.jsx(Wre,{})}),u.jsx(ei,{path:"/skills",element:u.jsx(mJe,{})}),u.jsx(ei,{path:"/help",element:u.jsx(iet,{})}),u.jsx(ei,{path:"/system",element:u.jsx(qJe,{})}),u.jsx(ei,{path:"/memory",element:u.jsx(ZJe,{})}),u.jsx(ei,{path:"/plugins",element:u.jsx(Bet,{})}),u.jsx(ei,{path:"*",element:u.jsx(xlt,{})})]})]})})}function wlt(){pet(),(async()=>{try{const e=await soe();await Promise.all(e.filter(t=>t.clientFormat==="sps"&&!t.disabled).map(t=>fet(t.key)))}catch(e){console.error("插件前端加载失败(不影响 console 本体):",e)}})()}d$e();jTe();wlt();const Mlt=new pee({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!1}}}),ale=document.getElementById("root");if(!ale)throw new Error("#root not found");bde.createRoot(ale).render(u.jsx(E.StrictMode,{children:u.jsx(bTe,{children:u.jsx(fee,{client:Mlt,children:u.jsx(R1e,{children:u.jsx(_lt,{children:u.jsx(vlt,{})})})})})}));function _lt({children:e}){const t=Ze();return u.jsx(zne,{defaults:{confirm:t("dialog.confirm.default"),cancel:t("dialog.cancel.default"),alert:t("dialog.alert.default")},children:e})}export{Hh as A,h0 as C,Vh as E,Er as G,Sp as L,v9 as O,$r as P,bL as S,MR as W,k1 as a,UL as b,W4 as c,o0 as d,gk as e,u as j,E as r,Xee as u};