@coralai/sps-cli 0.58.16 → 0.58.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/memoryCommand.d.ts.map +1 -1
- package/dist/commands/memoryCommand.js +11 -10
- package/dist/commands/memoryCommand.js.map +1 -1
- package/dist/console-assets/assets/{index-R6Y8wve3.js → index-BfeVj69o.js} +1 -1
- package/dist/console-assets/index.html +1 -1
- package/dist/core/memory2/capture.d.ts.map +1 -1
- package/dist/core/memory2/capture.js +2 -0
- package/dist/core/memory2/capture.js.map +1 -1
- package/dist/core/memory2/config.d.ts +1 -1
- package/dist/core/memory2/config.js +1 -1
- package/dist/core/memory2/external/agentMemory.d.ts +16 -0
- package/dist/core/memory2/external/agentMemory.d.ts.map +1 -0
- package/dist/core/memory2/external/agentMemory.js +66 -0
- package/dist/core/memory2/external/agentMemory.js.map +1 -0
- package/dist/core/memory2/external/federate.d.ts +23 -0
- package/dist/core/memory2/external/federate.d.ts.map +1 -0
- package/dist/core/memory2/external/federate.js +43 -0
- package/dist/core/memory2/external/federate.js.map +1 -0
- package/dist/core/memory2/ftsIndex.d.ts +8 -0
- package/dist/core/memory2/ftsIndex.d.ts.map +1 -0
- package/dist/core/memory2/ftsIndex.js +172 -0
- package/dist/core/memory2/ftsIndex.js.map +1 -0
- package/dist/core/memory2/retrieve.d.ts +5 -1
- package/dist/core/memory2/retrieve.d.ts.map +1 -1
- package/dist/core/memory2/retrieve.js +11 -2
- package/dist/core/memory2/retrieve.js.map +1 -1
- package/dist/providers/mcp/spsMcpServer.d.ts.map +1 -1
- package/dist/providers/mcp/spsMcpServer.js +9 -6
- package/dist/providers/mcp/spsMcpServer.js.map +1 -1
- package/dist/services/MemoryService.d.ts +2 -4
- package/dist/services/MemoryService.d.ts.map +1 -1
- package/dist/services/MemoryService.js +7 -3
- package/dist/services/MemoryService.js.map +1 -1
- package/package.json +1 -1
|
@@ -645,7 +645,7 @@ description: ...
|
|
|
645
645
|
# ...`,"aria-label":t("skills.import.body")})]}),c.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:h.isPending||!f||!l.trim(),onClick:()=>h.mutate(),children:[h.isPending?c.jsx(Xe,{size:14,className:"animate-spin"}):c.jsx(e_,{size:14,strokeWidth:3}),t("skills.import.submit")]})]})})}function u8({onClose:e,onSubmit:t}){const n=Pe(),[r,a]=j.useState(""),[o,l]=j.useState(""),d=/^[a-z0-9][a-z0-9-]*$/.test(r);return c.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:c.jsx("div",{className:"w-full max-w-xl my-8",children:c.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[c.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[c.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[c.jsx(Pl,{size:16,strokeWidth:2.5}),n("skills.ai.title")]}),c.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:c.jsx(Sn,{size:14,strokeWidth:3})})]}),c.jsxs("label",{className:"flex flex-col gap-1",children:[c.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.name")}),c.jsx("input",{type:"text",value:r,onChange:f=>a(f.target.value),placeholder:"rust-error-handling",className:"nb-input w-full font-[family-name:var(--font-mono)]","aria-label":n("skills.ai.name")})]}),c.jsxs("label",{className:"flex flex-col gap-1",children:[c.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.intent")}),c.jsx("textarea",{value:o,onChange:f=>l(f.target.value),placeholder:n("skills.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("skills.ai.intent")})]}),c.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!d||!o.trim(),onClick:()=>t(r,o),children:[c.jsx(Pl,{size:14,strokeWidth:2.5}),n("skills.ai.submit")]})]})})})}async function d8(e){const{files:t}=await Rz(e),n=t["SKILL.md"]??"",r=new Blob([n],{type:"text/markdown"}),a=URL.createObjectURL(r),o=document.createElement("a");o.href=a,o.download=`${e}.SKILL.md`,o.click(),URL.revokeObjectURL(a)}const f8=[{value:"all",labelKey:"skills.category.all"},{value:"language",labelKey:"skills.category.language"},{value:"end",labelKey:"skills.category.end"},{value:"persona",labelKey:"skills.category.persona"},{value:"workflow",labelKey:"skills.category.workflow"},{value:"other",labelKey:"skills.category.other"}],h8={language:"var(--color-accent-purple)",end:"var(--color-secondary)",persona:"var(--color-primary)",workflow:"var(--color-accent-mint)",other:"var(--color-bg-cream)"};function p8(){var D,U;const e=Pe(),[t,n]=j.useState("all"),[r,a]=j.useState(""),[o,l]=j.useState(null),[d,f]=j.useState(!1),[h,g]=j.useState(!1),m=Gt(),b=(((D=Ye({queryKey:["gen-jobs"],queryFn:y2,refetchInterval:3e3}).data)==null?void 0:D.data)??[]).filter(B=>B.kind==="skill"),w=b.filter(B=>B.status!=="done"),v=j.useRef(new Set);j.useEffect(()=>{for(const B of b)(B.status==="done"||B.status==="error")&&!v.current.has(B.id)&&(v.current.add(B.id),m.invalidateQueries({queryKey:["skills"]}),m.invalidateQueries({queryKey:["skill-updates"]}))},[b,m]);const S=(B,q)=>{Lz(B,q).then(()=>m.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},C=(((U=Ye({queryKey:["skill-updates"],queryFn:Dz}).data)==null?void 0:U.data)??[]).filter(B=>B.status!=="same").length,{data:N,isLoading:_}=Ye({queryKey:["skills"],queryFn:()=>ox()}),M=Ye({queryKey:["projects"],queryFn:ks}),A=j.useMemo(()=>((N==null?void 0:N.data)??[]).filter(q=>!(t!=="all"&&q.category!==t||r&&!q.name.toLowerCase().includes(r.toLowerCase()))),[N,t,r]),O=j.useMemo(()=>{const B=(N==null?void 0:N.data)??[],q={all:B.length};for(const G of B)q[G.category]=(q[G.category]??0)+1;return q},[N]);return c.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[c.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:"Skills 🎯"}),c.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:_?e("common.loading"):e("skills.subtitleCount",{count:(N==null?void 0:N.data.length)??0})})]}),c.jsxs("div",{className:"flex gap-3 items-center",children:[C>0&&c.jsx("span",{className:"nb-badge text-[10px]",title:e("skills.updates.badge",{count:String(C)}),children:e("skills.updates.badge",{count:String(C)})}),c.jsxs("button",{className:"nb-btn",onClick:()=>g(!0),type:"button",children:[c.jsx(Pl,{size:14,strokeWidth:2.5}),e("skills.ai")]}),c.jsxs("button",{className:"nb-btn",onClick:()=>f(!0),type:"button",children:[c.jsx(e_,{size:14,strokeWidth:2.5}),e("skills.import")]}),c.jsxs("button",{className:"nb-btn nb-btn-mint",onClick:async()=>{await Az(),m.invalidateQueries({queryKey:["skills"]}),m.invalidateQueries({queryKey:["skill-updates"]})},type:"button",children:[c.jsx(ya,{size:14,strokeWidth:2.5}),"Sync bundled"]})]})]}),c.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[c.jsxs("div",{className:"relative flex-1 max-w-md",children:[c.jsx(ho,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),c.jsx("input",{className:"nb-input pl-9 w-full",placeholder:e("skills.search.placeholder"),value:r,onChange:B=>a(B.target.value),"aria-label":e("skills.search.aria")})]}),c.jsx("div",{className:"flex gap-1 p-1 bg-[var(--color-bg)] border-[2px] border-[var(--color-text)] rounded-full shadow-[2px_2px_0_var(--color-text)]",children:f8.map(B=>c.jsxs("button",{type:"button",onClick:()=>n(B.value),className:["px-3 py-1 rounded-full text-xs font-bold font-[family-name:var(--font-body)]",t===B.value?"bg-[var(--color-text)] text-[var(--color-bg)]":"text-[var(--color-text-muted)] hover:text-[var(--color-text)]"].join(" "),children:[e(B.labelKey)," ",O[B.value]]},B.value))})]}),c.jsxs("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:[w.map(B=>c.jsxs("div",{className:`nb-card flex items-center gap-2 ${B.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,children:[B.status==="running"?c.jsx(Xe,{size:14,className:"animate-spin"}):c.jsx(Sn,{size:14,strokeWidth:3}),c.jsx("span",{className:"text-sm text-[var(--color-text-muted)] truncate",children:B.status==="running"?`${B.label} · ${e("skills.ai.wait")}`:`${B.label}: ${B.error??e("skills.ai.error")}`})]},B.id)),A.map(B=>{var q;return c.jsx(m8,{skill:B,projectCount:((q=M.data)==null?void 0:q.data.length)??0,onOpen:()=>l(B.name),onExport:()=>void d8(B.name)},B.name)})]}),o&&c.jsx(o8,{name:o,onClose:()=>l(null)}),d&&c.jsx(c8,{onClose:()=>f(!1)}),h&&c.jsx(u8,{onClose:()=>g(!1),onSubmit:(B,q)=>{S(B,q),g(!1)}})]})}function m8({skill:e,projectCount:t,onOpen:n,onExport:r}){const a=Pe(),o=h8[e.category];return c.jsxs("article",{onClick:n,onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),n())},tabIndex:0,role:"button","aria-label":`Open ${e.name}`,className:"nb-card nb-card-interactive flex flex-col gap-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:e.name}),c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("button",{type:"button",className:"nb-btn p-1",onClick:l=>{l.stopPropagation(),r()},"aria-label":a("skills.export"),title:a("skills.export"),children:c.jsx(Uh,{size:12,strokeWidth:2.5})}),c.jsx("span",{className:"nb-badge text-[10px]",style:{background:o},children:e.category})]})]}),c.jsx("p",{className:"text-sm text-[var(--color-text-muted)] leading-5 line-clamp-3",children:e.description||"(no description)"}),c.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)]",children:[c.jsx("span",{className:"font-bold",children:e.linkedProjects.length>0?`● linked in ${e.linkedProjects.length}`:"○ not linked"}),c.jsxs("span",{className:"text-[var(--color-text-subtle)]",children:[t," projects"]})]})]})}function qj(e){const t=e?`?q=${encodeURIComponent(e)}`:"";return ht(`/api/prompts${t}`)}function Ix(e){return ht(`/api/prompts/${encodeURIComponent(e)}`)}function g8(e){return Ri("/api/prompts",e)}function y8(e,t){return qb(`/api/prompts/${encodeURIComponent(e)}`,t)}function b8(e){return A3(`/api/prompts/${encodeURIComponent(e)}`)}function x8(e){return Ri("/api/prompts/generate",{intent:e})}function Hj(e){const t=new Set,n=[];for(const r of e.matchAll(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g)){const a=r[1];a&&!t.has(a)&&(t.add(a),n.push(a))}return n}function v8(){var A,O;const e=Pe(),[t,n]=Kb("prompts.last",""),[r,a]=j.useState(null),[o,l]=j.useState(!1),[d,f]=j.useState(""),[h,g]=j.useState(new Set),m=Gt(),y=Ye({queryKey:["prompts"],queryFn:()=>qj()}),b=((A=y.data)==null?void 0:A.data)??[],w=j.useMemo(()=>[...new Set(b.flatMap(D=>D.tags))].sort(),[b]),S=(((O=Ye({queryKey:["gen-jobs"],queryFn:y2,refetchInterval:3e3}).data)==null?void 0:O.data)??[]).filter(D=>D.kind==="prompt"),E=S.filter(D=>D.status!=="done"),C=j.useRef(new Set);j.useEffect(()=>{for(const D of S)(D.status==="done"||D.status==="error")&&!C.current.has(D.id)&&(C.current.add(D.id),m.invalidateQueries({queryKey:["prompts"]}),D.status==="done"&&D.result&&n(D.result))},[S,m,n]);const N=D=>{x8(D).then(()=>m.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},_=j.useMemo(()=>{const D=d.trim().toLowerCase();return b.filter(U=>!(h.size&&![...h].every(B=>U.tags.includes(B))||D&&!(U.name.toLowerCase().includes(D)||U.description.toLowerCase().includes(D)||U.tags.some(q=>q.toLowerCase().includes(D)))))},[b,h,d]);j.useEffect(()=>{t&&b.length&&!b.some(D=>D.name===t)&&n("")},[t,b,n]);const M=D=>g(U=>{const B=new Set(U);return B.has(D)?B.delete(D):B.add(D),B});return c.jsxs("div",{className:"flex flex-col flex-1 min-h-0 w-full gap-3",children:[c.jsxs("div",{className:"shrink-0 flex items-center justify-between gap-3",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-3xl font-bold",children:e("prompts.title")}),c.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.desc")})]}),c.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[c.jsxs("button",{className:"nb-btn",type:"button",onClick:()=>l(!0),children:[c.jsx(Pl,{size:14,strokeWidth:2.5}),e("prompts.ai")]}),c.jsxs("button",{className:"nb-btn nb-btn-mint",type:"button",onClick:()=>a({mode:"new"}),children:[c.jsx(pr,{size:14,strokeWidth:3}),e("prompts.new")]})]})]}),c.jsxs("div",{className:"shrink-0 flex flex-col gap-2",children:[c.jsxs("label",{className:"nb-input flex items-center gap-2 w-full",style:{padding:"6px 10px"},children:[c.jsx(ho,{size:14}),c.jsx("input",{type:"text",value:d,onChange:D=>f(D.target.value),placeholder:e("prompts.search"),className:"bg-transparent outline-none flex-1 text-sm","aria-label":e("prompts.search")})]}),w.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5",children:w.map(D=>c.jsx("button",{type:"button",onClick:()=>M(D),className:`text-xs border-2 border-[var(--color-text)] rounded-full px-2 py-0.5 ${h.has(D)?"bg-[var(--color-accent-mint)] font-bold":"bg-[var(--color-bg)]"}`,children:D},D))})]}),c.jsxs("div",{className:"flex gap-5 flex-1 min-h-0",children:[c.jsxs("aside",{className:"w-80 shrink-0 min-h-0 overflow-y-auto flex flex-col gap-2 pr-1",children:[E.map(D=>c.jsxs("div",{className:`nb-card flex items-center gap-2 ${D.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,style:{padding:"8px 10px"},children:[D.status==="running"?c.jsx(Xe,{size:12,className:"animate-spin"}):c.jsx(Sn,{size:12,strokeWidth:3}),c.jsx("span",{className:"text-xs text-[var(--color-text-muted)] truncate",children:D.status==="running"?e("prompts.ai.wait"):`${e("prompts.ai.error")}: ${D.error??""}`})]},D.id)),y.isLoading?c.jsx("div",{className:"nb-card",children:c.jsx(Xe,{size:14,className:"animate-spin"})}):_.length===0?c.jsx("div",{className:"nb-card",children:c.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.empty")})}):_.map(D=>c.jsxs("button",{type:"button",onClick:()=>n(D.name),className:`nb-card w-full text-left ${t===D.name?"bg-[var(--color-accent-mint)]":""}`,style:{padding:"8px 10px"},children:[c.jsxs("span",{className:"flex items-center gap-1.5",children:[D.favorite&&c.jsx(ZN,{size:12,fill:"currentColor"}),c.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold truncate",children:D.name})]}),D.description&&c.jsx("span",{className:"block text-xs text-[var(--color-text-muted)] truncate",children:D.description})]},D.name))]}),c.jsx("div",{className:"flex-1 min-w-0 min-h-0",children:t?c.jsx(k8,{name:t,onEdit:()=>a({mode:"edit",name:t}),onDeleted:()=>n("")},t):c.jsx("div",{className:"nb-card",children:c.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("prompts.selectHint")})})})]}),r&&c.jsx(S8,{name:r.mode==="edit"?r.name:null,onClose:()=>a(null),onSaved:D=>{a(null),n(D)}}),o&&c.jsx(w8,{onClose:()=>l(!1),onSubmit:D=>{N(D),l(!1)}})]})}function w8({onClose:e,onSubmit:t}){const n=Pe(),[r,a]=j.useState("");return c.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:c.jsx("div",{className:"w-full max-w-xl my-8",children:c.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[c.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[c.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[c.jsx(Pl,{size:16,strokeWidth:2.5}),n("prompts.ai.title")]}),c.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:c.jsx(Sn,{size:14,strokeWidth:3})})]}),c.jsxs("label",{className:"flex flex-col gap-1",children:[c.jsx("span",{className:"text-sm font-bold",children:n("prompts.ai.intent")}),c.jsx("textarea",{value:r,onChange:o=>a(o.target.value),placeholder:n("prompts.ai.placeholder"),rows:5,className:"nb-input w-full text-sm","aria-label":n("prompts.ai.intent")})]}),c.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!r.trim(),onClick:()=>t(r),children:[c.jsx(Pl,{size:14,strokeWidth:2.5}),n("prompts.ai.submit")]})]})})})}function k8({name:e,onEdit:t,onDeleted:n}){const r=Pe(),a=Gt(),{confirm:o}=un(),l=Ye({queryKey:["prompt",e],queryFn:()=>Ix(e)}),d=Ct({mutationFn:()=>b8(e),onSuccess:()=>{a.invalidateQueries({queryKey:["prompts"]}),n()}});if(l.isLoading)return c.jsx("div",{className:"nb-card",children:c.jsx(Xe,{size:14,className:"animate-spin"})});const f=l.data;if(!f)return null;const h=Hj(f.body);return c.jsxs("div",{className:"nb-card flex flex-col gap-3 h-full min-h-0",children:[c.jsxs("div",{className:"flex items-start justify-between gap-3 shrink-0",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold flex items-center gap-2",children:[f.favorite&&c.jsx(ZN,{size:16,fill:"currentColor"}),c.jsx("code",{className:"font-[family-name:var(--font-mono)] truncate",children:f.name})]}),f.description&&c.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:f.description})]}),c.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[c.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:t,children:[c.jsx(qh,{size:14,strokeWidth:3}),r("common.edit")]}),c.jsx("button",{type:"button",className:"nb-btn",disabled:d.isPending,onClick:async()=>{await o({title:r("prompts.delete"),body:r("prompts.deleteConfirm",{name:e})})&&d.mutate()},"aria-label":r("prompts.delete"),children:c.jsx(fi,{size:14,strokeWidth:3})})]})]}),f.tags.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5 shrink-0",children:f.tags.map(g=>c.jsx("span",{className:"text-xs bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-full px-2 py-0.5",children:g},g))}),c.jsx("pre",{className:"flex-1 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:f.body}),c.jsx("span",{className:"text-xs text-[var(--color-text-muted)] shrink-0",children:h.length?r("prompts.vars",{names:h.join(", ")}):r("prompts.noVars")})]})}function E8({tags:e,onChange:t}){const n=Pe(),[r,a]=j.useState(""),o=()=>{const l=r.trim();l&&!e.includes(l)&&t([...e,l]),a("")};return c.jsxs("div",{className:"nb-input w-full flex flex-wrap gap-1.5 items-center",children:[e.map(l=>c.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:[l,c.jsx("button",{type:"button",onClick:()=>t(e.filter(d=>d!==l)),"aria-label":`remove ${l}`,children:c.jsx(Sn,{size:10,strokeWidth:3})})]},l)),c.jsx("input",{className:"flex-1 min-w-[90px] bg-transparent outline-none text-sm",value:r,onChange:l=>a(l.target.value),onKeyDown:l=>{l.key==="Enter"?(l.preventDefault(),o()):l.key==="Backspace"&&!r&&e.length&&t(e.slice(0,-1))},placeholder:e.length?"":n("prompts.tagAdd"),"aria-label":n("prompts.tags")})]})}function S8({name:e,onClose:t,onSaved:n}){const r=Pe(),a=Gt(),{alert:o}=un(),l=e===null,d=Ye({queryKey:["prompt",e],queryFn:()=>Ix(e),enabled:!l}),[f,h]=j.useState(l?{name:"",description:"",tags:[],body:"",favorite:!1}:null);j.useEffect(()=>{if(!l&&d.data&&f===null){const b=d.data;h({name:b.name,description:b.description,tags:b.tags,body:b.body,favorite:b.favorite})}},[l,d.data,f]);const g=Ct({mutationFn:()=>{if(!f)throw new Error("no form");const b={description:f.description||void 0,tags:f.tags,favorite:f.favorite,body:f.body};return l?g8({name:f.name,...b}):y8(e,b)},onSuccess:b=>{a.invalidateQueries({queryKey:["prompts"]}),a.invalidateQueries({queryKey:["prompt",b.name]}),n(b.name)},onError:b=>void o({title:r("prompts.saveError"),body:b instanceof Error?b.message:String(b)})}),m=j.useMemo(()=>f?/^[a-z0-9][a-z0-9-]*$/.test(f.name):!1,[f]),y=j.useMemo(()=>f?Hj(f.body):[],[f]);return c.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:c.jsx("div",{className:"w-full max-w-2xl my-8",children:c.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[c.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold",children:l?r("prompts.new"):e}),c.jsx("button",{type:"button",className:"nb-btn p-2",onClick:t,"aria-label":"close",children:c.jsx(Sn,{size:14,strokeWidth:3})})]}),!l&&d.isLoading?c.jsx(Xe,{size:14,className:"animate-spin"}):f?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[c.jsxs("label",{className:"flex flex-col gap-1",children:[c.jsx("span",{className:"text-sm font-bold",children:r("prompts.name")}),c.jsx("input",{type:"text",value:f.name,disabled:!l,onChange:b=>h({...f,name:b.target.value}),placeholder:r("prompts.namePlaceholder"),className:"nb-input w-full","aria-label":r("prompts.name")}),l&&f.name&&!m&&c.jsx("span",{className:"text-xs text-[var(--color-crashed)]",children:r("prompts.nameError")})]}),c.jsxs("label",{className:"flex flex-col gap-1",children:[c.jsx("span",{className:"text-sm font-bold",children:r("prompts.description")}),c.jsx("input",{type:"text",value:f.description,onChange:b=>h({...f,description:b.target.value}),className:"nb-input w-full","aria-label":r("prompts.description")})]})]}),c.jsxs("label",{className:"flex flex-col gap-1",children:[c.jsx("span",{className:"text-sm font-bold",children:r("prompts.tags")}),c.jsx(E8,{tags:f.tags,onChange:b=>h({...f,tags:b})})]}),c.jsxs("label",{className:"flex flex-col gap-1",children:[c.jsx("span",{className:"text-sm font-bold",children:r("prompts.body")}),c.jsx("textarea",{value:f.body,onChange:b=>h({...f,body:b.target.value}),placeholder:r("prompts.bodyPlaceholder"),rows:12,className:"nb-input w-full font-[family-name:var(--font-mono)] text-sm","aria-label":r("prompts.body")}),c.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:y.length?r("prompts.vars",{names:y.join(", ")}):r("prompts.noVars")})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:g.isPending||l&&!m||!f.body.trim(),onClick:()=>g.mutate(),children:[g.isPending?c.jsx(Xe,{size:14,className:"animate-spin"}):c.jsx(Oi,{size:14,strokeWidth:3}),r("prompts.save")]}),c.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:f.favorite,onChange:b=>h({...f,favorite:b.target.checked})}),r("prompts.favorite")]})]})]}):null]})})})}function N8(){var o;const e=Pe(),t=Ye({queryKey:["system-info"],queryFn:o_}),n=Ye({queryKey:["system-env"],queryFn:T3}),[r,a]=j.useState(!1);return c.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[c.jsx("header",{children:c.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:e("system.h1")})}),c.jsx(_8,{current:(o=t.data)==null?void 0:o.version}),c.jsxs("section",{className:"nb-card",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-3",children:e("system.runtime")}),t.data?c.jsxs("dl",{className:"grid grid-cols-1 sm:grid-cols-[160px_1fr] gap-y-2 text-sm",children:[c.jsx("dt",{className:"font-bold",children:"Node"}),c.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.data.nodeVersion}),c.jsx("dt",{className:"font-bold",children:"Platform"}),c.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.data.platform}),c.jsx("dt",{className:"font-bold",children:"PID"}),c.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.data.pid??"—"}),c.jsx("dt",{className:"font-bold",children:"Uptime"}),c.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:T8(t.data.uptimeMs)})]}):c.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("common.loading")})]}),c.jsxs("section",{className:"nb-card",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:[e("system.env.title.prefix"),c.jsx("code",{className:"text-sm font-[family-name:var(--font-mono)] font-normal bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] px-2 py-0.5 rounded",children:"~/.coral/env"})]}),r?c.jsx("span",{className:"text-xs text-[var(--color-stuck)] font-bold",children:e("system.env.editing.label")}):c.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>a(!0),type:"button","aria-label":e("system.env.edit.aria"),children:[c.jsx(qh,{size:12,strokeWidth:2.5})," ",e("system.env.edit.button")]})]}),r?c.jsx(j8,{onClose:()=>{a(!1),n.refetch()}}):n.data&&n.data.exists?c.jsx("dl",{className:"grid grid-cols-1 sm:grid-cols-[220px_1fr] gap-y-1 text-sm font-[family-name:var(--font-mono)]",children:n.data.entries.map(l=>c.jsxs("div",{className:"contents",children:[c.jsxs("dt",{className:"font-bold flex items-center gap-2",children:[l.masked&&c.jsx("span",{className:"text-[var(--color-stuck)]",children:"🔒"}),l.key]}),c.jsx("dd",{className:"text-[var(--color-text-muted)] truncate",children:l.value})]},l.key))}):c.jsxs("p",{className:"text-[var(--color-text-muted)] text-sm",children:[e("system.env.empty.before"),c.jsx("code",{className:"bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] px-2 py-0.5 rounded font-[family-name:var(--font-mono)]",children:"sps setup"}),e("system.env.empty.after")]})]}),c.jsx(C8,{})]})}function _8({current:e}){var v;const t=Pe(),{confirm:n,alert:r}=un(),[a,o]=j.useState(!1),[l,d]=j.useState(null),f=Ye({queryKey:["latest-version"],queryFn:I3,enabled:!1}),[h,g]=j.useState(null),[m,y]=j.useState("npm i -g @coralai/sps-cli@latest"),b=async()=>{var E;if(await n({title:t("system.upgrade.confirm.title"),body:t("system.upgrade.confirm.body",{current:e??"?",latest:((E=f.data)==null?void 0:E.latest)??"?"}),confirm:t("system.upgrade.confirm.button")})){o(!0),d(null),g(null);try{const C=await z3();if(d(C.output),g(C.installedVersion),y(C.command),C.ok)r({title:t("system.upgrade.success.title"),body:t("system.upgrade.success.body",{version:C.installedVersion??"?"})});else{const N=C.installedVersion&&C.installedVersion===e?t("system.upgrade.notEffective.same",{version:C.installedVersion}):t("system.upgrade.notEffective.notInstalled");r({title:t("system.upgrade.notEffective.title"),body:N})}}catch(C){d(C.message),r({title:t("system.upgrade.error.title"),body:C.message})}finally{o(!1)}}},w=async()=>{const S=f.data&&!f.data.upToDate?`npm i -g @coralai/sps-cli@${f.data.latest}`:m;try{await navigator.clipboard.writeText(S),r({title:t("system.upgrade.copy.success.title"),body:t("system.upgrade.copy.success.body",{cmd:S})})}catch{r({title:t("system.upgrade.copy.fail.title"),body:t("system.upgrade.copy.fail.body",{cmd:S})})}};return c.jsxs("section",{className:"nb-card",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:t("system.upgrade.title")}),c.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>f.refetch(),disabled:f.isFetching||!e,type:"button","aria-label":t("system.upgrade.checkLatest.aria"),children:[f.isFetching?c.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):c.jsx(ya,{size:12,strokeWidth:2.5}),t("system.upgrade.checkUpdate")]})]}),c.jsxs("dl",{className:"grid grid-cols-1 sm:grid-cols-[160px_1fr] gap-y-2 text-sm",children:[c.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.current")}),c.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:e??"—"}),f.data&&c.jsxs(c.Fragment,{children:[c.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.latest")}),c.jsxs("dd",{className:"font-[family-name:var(--font-mono)] flex items-center gap-2 flex-wrap",children:[f.data.latest,f.data.upToDate?c.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:t("system.upgrade.latestPill")}):c.jsxs(c.Fragment,{children:[c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"3px 10px",fontSize:11},onClick:b,disabled:a,type:"button","aria-label":t("system.upgrade.button.upgradeAria"),children:[a?c.jsx(Xe,{size:11,strokeWidth:3,className:"animate-spin"}):c.jsx(Uh,{size:11,strokeWidth:2.5}),t("system.upgrade.button.upgrade")]}),c.jsxs("button",{className:"nb-btn",style:{padding:"3px 10px",fontSize:11},onClick:w,type:"button","aria-label":t("system.upgrade.button.copyAria"),title:t("system.upgrade.button.copyTitle"),children:[c.jsx(HR,{size:11,strokeWidth:2.5})," ",t("system.upgrade.button.copy")]})]})]})]}),h&&c.jsxs(c.Fragment,{children:[c.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.installed")}),c.jsxs("dd",{className:"font-[family-name:var(--font-mono)] flex items-center gap-2",children:[h,h===((v=f.data)==null?void 0:v.latest)?c.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:t("system.upgrade.installed.ok")}):h===e?c.jsx("span",{className:"nb-status",style:{background:"var(--color-stuck-bg)",color:"var(--color-stuck)"},children:t("system.upgrade.installed.fail")}):null]})]}),f.isError&&c.jsxs(c.Fragment,{children:[c.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.check")}),c.jsx("dd",{className:"text-[var(--color-crashed)] text-xs",children:f.error instanceof Error?f.error.message:String(f.error)})]})]}),l&&c.jsx("pre",{className:"mt-3 text-xs font-[family-name:var(--font-mono)] bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg p-3 max-h-40 overflow-auto whitespace-pre-wrap",children:l})]})}function j8({onClose:e}){const t=Pe(),n=Gt(),{alert:r}=un(),a=Ye({queryKey:["system-env-raw"],queryFn:M3}),[o,l]=j.useState(null),[d,f]=j.useState(null);j.useEffect(()=>{a.data&&o===null&&(l(a.data.content),f(a.data.etag))},[a.data,o]);const h=o!==null&&a.data&&o!==a.data.content,g=Ct({mutationFn:()=>{if(o===null)throw new Error("no draft");return D3(o,d??"")},onSuccess:()=>{n.invalidateQueries({queryKey:["system-env"]}),n.invalidateQueries({queryKey:["system-env-raw"]}),e()},onError:m=>{const y=m.status;r({title:t(y===409?"system.env.error.conflict.title":"system.env.error.save.title"),body:y===409?t("system.env.error.conflict.body"):m instanceof Error?m.message:String(m)})}});return a.isLoading?c.jsx("p",{className:"text-[var(--color-text-muted)]",children:t("common.loading")}):c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-[var(--color-stuck)] font-bold mb-2",children:t("system.env.warning")}),c.jsx("textarea",{className:"nb-input w-full font-[family-name:var(--font-mono)] text-xs",style:{minHeight:320,resize:"vertical"},value:o??"",onChange:m=>l(m.target.value),spellCheck:!1,"aria-label":t("system.env.aria")}),c.jsxs("div",{className:"flex items-center justify-between mt-3",children:[c.jsxs("span",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:[d?`etag: ${d}`:"",h?t("system.env.dirtyMark"):""]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px"},onClick:e,disabled:g.isPending,type:"button",children:[c.jsx(Sn,{size:12,strokeWidth:3})," ",t("system.env.cancel")]}),c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px"},onClick:()=>g.mutate(),disabled:!h||g.isPending,type:"button","aria-label":t("system.env.save.aria"),children:[g.isPending?c.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):c.jsx(Oi,{size:12,strokeWidth:3}),t("system.env.save")]})]})]})]})}function C8(){var y;const e=Pe(),{alert:t}=un(),n=Ye({queryKey:["projects"],queryFn:ks}),[r,a]=j.useState({}),[o,l]=j.useState({}),[d,f]=j.useState({}),h=(((y=n.data)==null?void 0:y.data)??[]).map(b=>({project:b.name})),g=async(b,w)=>{l(v=>({...v,[b]:w?"fix":"check"}));try{const v=await P3(b,w);a(S=>({...S,[b]:v})),f(S=>({...S,[b]:!0}))}catch(v){t({title:e(w?"system.diagnostics.error.fix":"system.diagnostics.error.check"),body:v instanceof Error?v.message:String(v)})}finally{l(v=>({...v,[b]:null}))}},m=async()=>{for(const b of h)await g(b.project,!1)};return c.jsxs("section",{className:"nb-card",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:e("system.diagnostics.title")}),c.jsxs("button",{className:"nb-btn nb-btn-mint",style:{padding:"6px 12px",fontSize:12},onClick:()=>{m()},disabled:h.length===0||Object.values(o).some(Boolean),type:"button",children:[c.jsx(ya,{size:12,strokeWidth:2.5}),e("system.diagnostics.checkAll")]})]}),h.length===0?c.jsx("p",{className:"text-[var(--color-text-muted)] text-sm",children:e("system.diagnostics.empty")}):c.jsx("ul",{className:"flex flex-col gap-2",children:h.map(b=>{const w=r[b.project],v=o[b.project],S=w?w.checks.filter(_=>_.status==="fail").length:0,E=w?w.checks.filter(_=>_.status==="warn").length:0,C=d[b.project]??!1,N=w!=null;return c.jsxs("li",{className:"bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg",children:[c.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[c.jsxs("button",{type:"button",onClick:()=>f(_=>({..._,[b.project]:!C})),disabled:!N,className:"flex items-center gap-2 flex-1 text-left min-w-0","aria-label":e(C?"system.diagnostics.collapseAria":"system.diagnostics.expandAria"),children:[N&&w.ok?c.jsx(fh,{size:16,className:"text-[var(--color-running)] shrink-0",strokeWidth:2.5}):N?c.jsx(ku,{size:16,className:"text-[var(--color-stuck)] shrink-0",strokeWidth:2.5}):c.jsx(fh,{size:16,className:"text-[var(--color-text-subtle)] shrink-0",strokeWidth:2.5}),N&&(C?c.jsx(Vu,{size:12}):c.jsx(Zl,{size:12})),c.jsx("span",{className:"font-bold font-[family-name:var(--font-mono)]",children:b.project}),N?w.ok?c.jsx("span",{className:"text-xs text-[var(--color-running)] font-semibold",children:"OK"}):c.jsxs("span",{className:"text-xs text-[var(--color-stuck)] font-semibold",children:[S," fail · ",E," warn"]}):c.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:e("system.diagnostics.never")})]}),c.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>{g(b.project,!1)},disabled:!!v,type:"button","aria-label":e("system.diagnostics.checkAria"),children:[v==="check"?c.jsx(Xe,{size:11,strokeWidth:3,className:"animate-spin"}):c.jsx(ya,{size:11,strokeWidth:2.5}),e("system.diagnostics.check")]}),c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>{g(b.project,!0)},disabled:!!v||N&&w.ok,type:"button","aria-label":e("system.diagnostics.fixAria"),title:N&&w.ok?e("system.diagnostics.noFixesNeeded"):e("system.diagnostics.fix.tip"),children:[v==="fix"?c.jsx(Xe,{size:11,strokeWidth:3,className:"animate-spin"}):c.jsx(n_,{size:11,strokeWidth:2.5}),e("system.diagnostics.fix")]})]}),C&&N&&c.jsxs("div",{className:"border-t-2 border-dashed border-[var(--color-text)] px-3 py-2",children:[c.jsx("ul",{className:"flex flex-col gap-1 text-xs font-[family-name:var(--font-mono)]",children:w.checks.map((_,M)=>c.jsx(A8,{check:_},`${_.name}-${M}`))}),w.fixes.length>0&&c.jsxs("div",{className:"mt-3 bg-[var(--color-running-bg)] border-2 border-[var(--color-running)] rounded p-2",children:[c.jsx("div",{className:"text-xs font-bold text-[var(--color-running)] mb-1",children:e("system.diagnostics.fixed")}),c.jsx("ul",{className:"text-xs list-disc pl-4",children:w.fixes.map((_,M)=>c.jsx("li",{children:_},M))})]})]})]},b.project)})})]})}function A8({check:e}){const t=e.status==="pass"?c.jsx(fh,{size:12,className:"text-[var(--color-running)]",strokeWidth:2.5}):e.status==="fail"?c.jsx(ku,{size:12,className:"text-[var(--color-crashed)]",strokeWidth:2.5}):e.status==="warn"?c.jsx(ku,{size:12,className:"text-[var(--color-stuck)]",strokeWidth:2.5}):c.jsx("span",{className:"w-3 h-3 rounded-full bg-[var(--color-text-subtle)] inline-block"});return c.jsxs("li",{className:"flex items-start gap-2",children:[c.jsx("span",{className:"pt-0.5 shrink-0",children:t}),c.jsx("span",{className:"font-bold w-32 shrink-0",children:e.name}),c.jsx("span",{className:"text-[var(--color-text-muted)] break-words",children:e.message})]})}function T8(e){const t=Math.floor(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),a=t%60;return n>0?`${n}h ${r}m ${a}s`:r>0?`${r}m ${a}s`:`${a}s`}function M8(){return ht("/api/chat/sessions")}function D8(e){return ht(`/api/chat/sessions/${e}`)}async function oy(e={}){const t=await fetch("/api/chat/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return await t.json()}async function O8(e){const t=await fetch(`/api/chat/sessions/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(`${t.status}`)}async function R8(e,t,n){const r=await fetch(`/api/chat/sessions/${e}/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,attachments:n})});if(!r.ok)throw new Error(`${r.status}: ${await r.text()}`);return await r.json()}async function L8(e){const t=await fetch(`/api/chat/sessions/${e}/interrupt`,{method:"POST"});if(!t.ok&&t.status!==204)throw new Error(`${t.status}: ${await t.text()}`)}function I8(e,t){const n=t?`?since=${encodeURIComponent(t)}`:"";return ht(`/api/chat/sessions/${e}/messages${n}`)}function z8({onInsert:e,disabled:t,className:n="nb-btn"}){var m;const r=Pe(),[a,o]=j.useState(!1),[l,d]=j.useState(""),h=((m=Ye({queryKey:["prompts",l],queryFn:()=>qj(l||void 0),enabled:a}).data)==null?void 0:m.data)??[],g=async y=>{try{const b=await Ix(y);e(b.body)}finally{o(!1),d("")}};return c.jsxs("div",{className:"relative flex-shrink-0",children:[c.jsx("button",{type:"button",className:n,onClick:()=>o(y=>!y),disabled:t,"aria-label":r("prompts.insert"),title:r("prompts.insert"),children:c.jsx(YN,{size:15,strokeWidth:2.5})}),a&&c.jsxs("div",{className:"absolute bottom-full mb-2 left-0 z-20 w-72 nb-card max-h-80 overflow-auto flex flex-col gap-1",children:[c.jsxs("label",{className:"flex items-center gap-2 border-2 border-[var(--color-text)] rounded px-2 py-1",children:[c.jsx(ho,{size:12}),c.jsx("input",{autoFocus:!0,value:l,onChange:y=>d(y.target.value),placeholder:r("prompts.search"),className:"bg-transparent outline-none flex-1 text-sm","aria-label":r("prompts.search")})]}),h.length===0?c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-1 py-2",children:r("prompts.empty")}):h.map(y=>c.jsxs("button",{type:"button",onClick:()=>void g(y.name),className:"text-left px-2 py-1 rounded hover:bg-[var(--color-bg-cream)]",children:[c.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold",children:y.name}),y.description&&c.jsx("span",{className:"block text-xs text-[var(--color-text-muted)] truncate",children:y.description})]},y.name))]})]})}function TE(){var Te,Ie,Oe,le,je,Me,ke,We,Ue;const e=Pe(),{sessionId:t}=Mb(),n=ws(),r=Gt(),{confirm:a,alert:o}=un(),l=Ye({queryKey:["chat-sessions"],queryFn:M8,refetchInterval:5e3}),d=Ye({queryKey:["chat-session",t],queryFn:()=>D8(t??""),enabled:!!t,refetchInterval:4e3}),[f,h]=j.useState(null),g=oe=>`chat-draft:${oe??""}`,[m,y]=j.useState(()=>localStorage.getItem(g(t))??""),b=j.useCallback(oe=>{y(ye=>{const be=typeof oe=="function"?oe(ye):oe;try{t&&localStorage.setItem(g(t),be)}catch{}return be})},[t]);j.useEffect(()=>{y(localStorage.getItem(g(t))??"")},[t]);const[w,v]=j.useState(!1),S=j.useRef(null),E=j.useRef(!0),[C,N]=j.useState(!1),_=()=>{const oe=S.current;return!oe||oe.scrollHeight-oe.scrollTop-oe.clientHeight<40},M=j.useCallback(()=>{const oe=S.current;oe&&(oe.scrollTop=oe.scrollHeight),E.current=!0,N(!1)},[]),A=j.useCallback(()=>{const oe=_();E.current=oe,N(!oe)},[]),O=j.useRef(null);j.useEffect(()=>{const oe=O.current;oe&&(oe.style.height="auto",oe.style.height=`${Math.min(oe.scrollHeight,200)}px`,oe.scrollTop=oe.scrollHeight)},[m]);const D="w-8 h-8 flex items-center justify-center rounded-lg border-2 border-[var(--color-text)] bg-[var(--color-bg-cream)] hover:-translate-x-px hover:-translate-y-px hover:shadow-[2px_2px_0_var(--color-text)] transition-transform disabled:opacity-50 disabled:hover:translate-x-0 disabled:hover:translate-y-0 disabled:hover:shadow-none",[U,B]=j.useState(!1),[q,G]=j.useState([]),[Q,R]=j.useState(!1),[H,L]=j.useState(!1),[V,Y]=j.useState(!1),[K,z]=j.useState(null),[$,P]=j.useState(!1);j.useEffect(()=>{if(!t)return;const oe=new EventSource(`/stream/chat/${encodeURIComponent(t)}`);let ye=!0;return oe.addEventListener("open",()=>{if(ye){ye=!1;return}const be=r.getQueryData(["chat-session",t]),fe=be!=null&&be.messages.length?be.messages[be.messages.length-1].ts:void 0;I8(t,fe).then(Se=>{Se.data.length!==0&&r.setQueryData(["chat-session",t],_e=>{if(!_e)return _e;const Ke=new Set(_e.messages.map(ce=>ce.id)),te=Se.data.filter(ce=>!Ke.has(ce.id));return te.length===0?_e:{..._e,messages:[..._e.messages,...te],lastMessageAt:te[te.length-1].ts,messageCount:_e.messageCount+te.length}})}).catch(()=>{})}),oe.addEventListener("chat.message",be=>{try{const fe=JSON.parse(be.data);r.setQueryData(["chat-session",t],Se=>{if(!Se||Se.messages.some(te=>te.id===fe.message.id))return Se;const Ke=Se.messages.findIndex(te=>te.role==="user"&&te.id.startsWith("optim-")&&te.content===fe.message.content);if(Ke>=0){const te=[...Se.messages];return te[Ke]=fe.message,{...Se,messages:te}}return{...Se,messages:[...Se.messages,fe.message]}})}catch{}}),oe.addEventListener("chat.message.pending",be=>{try{const fe=JSON.parse(be.data);h({sessionId:t,id:fe.assistantId,blocks:[],done:!1,finalMessage:null})}catch{}}),oe.addEventListener("chat.message.chunk.text",be=>{try{const fe=JSON.parse(be.data);h(Se=>{if(!Se||Se.id!==fe.assistantId)return Se;const _e=[...Se.blocks],Ke=_e[_e.length-1];return Ke&&Ke.type==="text"?_e[_e.length-1]={...Ke,target:Ke.target+fe.text}:_e.push({type:"text",target:fe.text,displayed:""}),{...Se,blocks:_e}})}catch{}}),oe.addEventListener("chat.message.chunk.tool_use",be=>{try{const fe=JSON.parse(be.data);h(Se=>!Se||Se.id!==fe.assistantId?Se:{...Se,blocks:[...Se.blocks,{type:"tool_use",id:fe.id,title:fe.title,kind:fe.kind,status:fe.status,input:fe.input,locations:fe.locations}]})}catch{}}),oe.addEventListener("chat.message.chunk.tool_update",be=>{try{const fe=JSON.parse(be.data);h(Se=>!Se||Se.id!==fe.assistantId?Se:{...Se,blocks:Se.blocks.map(_e=>_e.type==="tool_use"&&_e.id===fe.id?{..._e,status:fe.status,input:_e.input??fe.input,locations:_e.locations??fe.locations}:_e)})}catch{}}),oe.addEventListener("chat.message.complete",be=>{try{const fe=JSON.parse(be.data);h(Se=>Se&&Se.id===fe.assistantId?{...Se,done:!0,finalMessage:fe.message}:Se)}catch{}}),()=>oe.close()},[t,r]),j.useEffect(()=>{if(!f||f.sessionId!==t)return;const oe=f.blocks.reduce((be,fe)=>fe.type==="text"?be+(fe.target.length-fe.displayed.length):be,0);if(oe<=0){if(f.done&&f.finalMessage){const be=f.finalMessage;r.setQueryData(["chat-session",t],fe=>!fe||fe.messages.some(Se=>Se.id===be.id)?fe:{...fe,messages:[...fe.messages,be],lastMessageAt:be.ts,messageCount:fe.messageCount+1}),r.invalidateQueries({queryKey:["chat-sessions"]}),r.invalidateQueries({queryKey:["chat-session",t]}),h(null),v(!1)}return}const ye=setTimeout(()=>{h(be=>{if(!be)return be;let fe=Math.max(1,Math.ceil(oe/40));const Se=be.blocks.map(_e=>{if(_e.type!=="text"||fe<=0)return _e;const Ke=_e.target.length-_e.displayed.length;if(Ke<=0)return _e;const te=Math.min(Ke,fe);return fe-=te,{..._e,displayed:_e.target.slice(0,_e.displayed.length+te)}});return{...be,blocks:Se}})},25);return()=>clearTimeout(ye)},[f,r,t]),j.useEffect(()=>{if(E.current){const oe=S.current;oe&&(oe.scrollTop=oe.scrollHeight)}},[d.data,f]),j.useEffect(()=>{E.current=!0,N(!1),v(!1)},[t]);const I=j.useCallback(async(oe={})=>{var ye,be;try{const fe=await oy({cwd:((ye=oe.cwd)==null?void 0:ye.trim())||void 0,title:((be=oe.title)==null?void 0:be.trim())||void 0,agentKind:oe.agentKind,model:oe.model,providerId:oe.providerId});r.invalidateQueries({queryKey:["chat-sessions"]}),n(`/chat/${fe.id}`),B(!1)}catch(fe){o({title:e("chat.error.create.title"),body:fe instanceof Error?fe.message:String(fe)})}},[r,n,o,e]),ae=j.useCallback(async()=>{const oe=m.trim();if(!oe&&q.length===0||w)return;let ye=t;if(!ye){const Se=await oy();r.invalidateQueries({queryKey:["chat-sessions"]}),ye=Se.id,n(`/chat/${ye}`,{replace:!0})}E.current=!0,N(!1);const be=q.map(Se=>Se.path),fe={id:`optim-${Date.now()}`,role:"user",content:oe||e("chat.placeholder.attachment"),ts:new Date().toISOString(),status:"complete",attachments:be.length>0?be:void 0};r.setQueryData(["chat-session",ye],Se=>Se?{...Se,messages:[...Se.messages,fe],lastMessageAt:fe.ts,messageCount:Se.messageCount+1}:{id:ye,createdAt:fe.ts,lastMessageAt:fe.ts,title:oe.slice(0,60)||e("chat.placeholder.attachmentTitle"),project:null,messageCount:1,messages:[fe]}),b(""),G([]),v(!0);try{await R8(ye,oe||e("chat.placeholder.viewAttachment"),be.length>0?be:void 0)}catch(Se){v(!1),console.error("sendMessage failed",Se),o({title:e("chat.error.send.title"),body:Se instanceof Error?Se.message:String(Se)})}},[m,q,w,t,r,n,o,e]),me=j.useCallback(async oe=>{if(oe.size>u2){o({title:e("chat.error.fileTooBig.title"),body:e("chat.error.fileTooBig.body",{size:(oe.size/1024/1024).toFixed(2),name:oe.name})});return}let ye=t;if(!ye){const be=await oy();r.invalidateQueries({queryKey:["chat-sessions"]}),ye=be.id,n(`/chat/${ye}`,{replace:!0})}R(!0);try{const be=await n4(ye,oe);G(fe=>[...fe,{path:be.path,name:be.name}])}catch(be){o({title:e("chat.error.uploadAttachment.title"),body:be instanceof Error?be.message:String(be)})}finally{R(!1)}},[t,r,n,o,e]),ve=j.useCallback(oe=>{G(ye=>ye.filter(be=>be.path!==oe))},[]),we=j.useCallback(async(oe,ye)=>{await a({title:e("chat.delete.confirm.title"),body:e(ye==="cli"?"chat.delete.confirm.body.cli":"chat.delete.confirm.body.console"),confirm:e("chat.delete.confirm.button"),danger:!0})&&(await O8(oe),r.invalidateQueries({queryKey:["chat-sessions"]}),t===oe&&n("/chat"))},[r,t,n,a,e]),J=j.useCallback(async()=>{if(t)try{await L8(t)}catch(oe){o({title:e("chat.error.interrupt.title"),body:oe instanceof Error?oe.message:String(oe)})}},[t,o,e]),de=f&&f.sessionId===t?f:null;return c.jsxs("div",{className:"grid grid-cols-[260px_1fr] gap-4 h-[calc(100vh-140px)]",children:[c.jsxs("aside",{className:"nb-card p-3 overflow-auto flex flex-col gap-2",children:[c.jsxs("button",{className:"nb-btn nb-btn-primary w-full justify-center",onClick:()=>B(!0),type:"button",children:[c.jsx(pr,{size:14,strokeWidth:3}),e("chat.list.new")]}),c.jsx("div",{className:"mt-2 text-xs font-[family-name:var(--font-heading)] uppercase tracking-wider text-[var(--color-text-muted)] px-2",children:e("chat.list.heading",{count:((Te=l.data)==null?void 0:Te.data.length)??0})}),c.jsx("div",{className:"flex flex-col gap-1.5 mt-1",children:(()=>{var te;const oe=((te=l.data)==null?void 0:te.data)??[],ye=Date.now(),be=10080*60*1e3,fe=ce=>new Date(ce.lastMessageAt??ce.createdAt).getTime(),Se=oe.filter(ce=>ye-fe(ce)<=be),_e=oe.filter(ce=>ye-fe(ce)>be),Ke=ce=>c.jsxs("div",{className:["group flex items-start gap-2 p-2 rounded-lg border-2 border-transparent",t===ce.id?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[2px_2px_0_var(--color-text)]":"hover:bg-[var(--color-bg-cream)] hover:border-[var(--color-text)]"].join(" "),children:[c.jsxs("button",{type:"button","aria-label":e("chat.list.openAria",{title:ce.title,cwd:ce.cwd?e("chat.list.cwdSuffix",{cwd:ce.cwd}):""}),onClick:()=>n(`/chat/${ce.id}`),className:"flex items-start gap-2 flex-1 min-w-0 text-left",children:[c.jsx(uk,{size:14,strokeWidth:2.5,className:"mt-0.5 flex-shrink-0"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[c.jsx("p",{className:"text-sm font-semibold truncate flex-1",children:ce.title}),ce.source==="cli"&&c.jsx("span",{className:"flex-shrink-0 px-1.5 py-0 rounded-md bg-[var(--color-accent-purple)] border-2 border-[var(--color-text)] text-[9px] font-[family-name:var(--font-mono)] uppercase tracking-wider leading-tight",title:e("chat.cliBadge.tooltip"),children:e("chat.cliBadge")})]}),c.jsx("p",{className:"text-[10px] text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] truncate",children:e("chat.list.msgs",{count:ce.messageCount,time:Vj(ce.lastMessageAt??ce.createdAt,e)})}),ce.cwd&&c.jsxs("p",{className:"text-[10px] text-[var(--color-text-subtle)] font-[family-name:var(--font-mono)] truncate flex items-center gap-1",title:ce.cwd,children:[c.jsx(ph,{size:9,strokeWidth:2.5,className:"flex-shrink-0"}),c.jsx("span",{className:"truncate",dir:"rtl",children:ce.cwd})]})]})]}),c.jsx("button",{type:"button","aria-label":ce.source==="cli"?e("chat.list.deleteCli.aria"):e("chat.list.delete.aria"),className:"opacity-0 group-hover:opacity-100 p-1 hover:text-[var(--color-crashed)]",onClick:Re=>{Re.stopPropagation(),we(ce.id,ce.source)},children:c.jsx(fi,{size:12})})]},ce.id);return c.jsxs(c.Fragment,{children:[Se.map(Ke),_e.length>0&&c.jsxs(c.Fragment,{children:[c.jsxs("button",{type:"button",onClick:()=>P(ce=>!ce),"aria-expanded":$,className:"flex items-center gap-1 px-2 py-1 mt-1 rounded-lg text-xs font-semibold text-[var(--color-text-muted)] hover:text-[var(--color-text)] hover:bg-[var(--color-bg-cream)] focus-visible:outline focus-visible:outline-2",children:[$?c.jsx(Vu,{size:12,strokeWidth:2.5}):c.jsx(Zl,{size:12,strokeWidth:2.5}),e("chat.list.olderToggle",{count:_e.length})]}),$&&_e.map(Ke)]}),oe.length===0&&c.jsx("p",{className:"text-xs text-[var(--color-text-subtle)] italic text-center py-4",children:e("chat.list.empty")})]})})()})]}),c.jsx("div",{className:"nb-card p-0 flex flex-col overflow-hidden",children:t?c.jsxs(c.Fragment,{children:[c.jsxs("header",{className:"px-4 py-3 border-b-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:((Ie=d.data)==null?void 0:Ie.title)??e("common.loading")}),((Oe=d.data)==null?void 0:Oe.model)&&c.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-md bg-[var(--color-accent-yellow)] border-2 border-[var(--color-text)] text-[10px] font-[family-name:var(--font-mono)] font-bold uppercase tracking-wider",title:e("chat.detail.model.tooltip"),children:[c.jsx(hh,{size:11,strokeWidth:2.5})," ",d.data.model]})]}),c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:t}),((le=d.data)==null?void 0:le.claudeSessionId)&&c.jsxs("p",{className:"text-xs text-[var(--color-text-subtle)] font-[family-name:var(--font-mono)] truncate",title:e("chat.detail.claudeSession.tooltip"),children:["claude: ",d.data.claudeSessionId]}),((je=d.data)==null?void 0:je.cwd)&&c.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] flex items-center gap-1 mt-1",title:d.data.cwd,children:[c.jsx(ph,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}),c.jsx("span",{className:"truncate",children:d.data.cwd})]})]}),c.jsxs("div",{className:"relative flex-1 flex flex-col min-h-0",children:[c.jsxs("div",{ref:S,onScroll:A,className:"flex-1 overflow-auto p-4 flex flex-col gap-4",children:[(((Me=d.data)==null?void 0:Me.messages)??[]).filter(oe=>!(de&&oe.status==="streaming")).map(oe=>c.jsx($8,{msg:oe,sessionId:t??null,onPreviewAttachment:ye=>z(ye)},oe.id)),de&&c.jsx(F8,{pending:de}),!d.isLoading&&(((ke=d.data)==null?void 0:ke.messages)??[]).length===0&&!de&&!w&&c.jsx("p",{className:"text-center text-[var(--color-text-subtle)] italic mt-12",children:e("chat.session.empty")})]}),C&&c.jsx("button",{type:"button",onClick:M,className:"absolute bottom-3 right-4 z-10 w-9 h-9 flex items-center justify-center rounded-full border-2 border-[var(--color-text)] bg-white shadow-[2px_2px_0_var(--color-text)] hover:-translate-y-px hover:shadow-[3px_3px_0_var(--color-text)] active:translate-y-px active:shadow-none transition-transform","aria-label":"滚动到底部",title:"↓ 回到底部",children:c.jsx(NR,{size:18,strokeWidth:3})})]}),((We=d.data)==null?void 0:We.source)==="cli"?c.jsxs("div",{className:"border-t-2 border-[var(--color-text)] p-4 bg-[var(--color-accent-purple)]",children:[c.jsxs("p",{className:"text-sm font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] text-center",children:[c.jsx("strong",{children:e("chat.cli.banner.bold")})," — ",e("chat.cli.banner")]}),c.jsxs("pre",{className:"mt-2 px-3 py-2 bg-[var(--color-bg)] border-2 border-[var(--color-text)] rounded-md text-xs font-[family-name:var(--font-mono)] overflow-x-auto",children:["sps agent --chat --name ",(t??"").replace(/^session-/,"")]})]}):c.jsxs("div",{className:["border-t-2 border-[var(--color-text)] p-3 bg-[var(--color-bg-cream)] transition-colors",V?"bg-[var(--color-accent-mint)]":""].join(" "),onDragOver:oe=>{oe.dataTransfer.types.includes("Files")&&(oe.preventDefault(),oe.dataTransfer.dropEffect="copy",V||Y(!0))},onDragLeave:()=>Y(!1),onDrop:oe=>{if(!oe.dataTransfer.types.includes("Files"))return;oe.preventDefault(),Y(!1);const ye=Array.from(oe.dataTransfer.files??[]);for(const be of ye)me(be)},children:[(q.length>0||Q)&&c.jsxs("div",{className:"flex flex-wrap gap-2 mb-2",children:[q.map(oe=>c.jsxs("button",{type:"button",className:"flex items-center gap-1.5 px-2 py-1 rounded-md bg-[var(--color-bg)] border-2 border-[var(--color-text)] text-xs font-[family-name:var(--font-mono)] hover:bg-[var(--color-accent-mint)] group",onClick:()=>z(oe.path),title:e("chat.attachment.previewTooltip",{name:oe.name,path:oe.path}),children:[Nh(oe.path)?c.jsx(vL,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}):c.jsx(Fh,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}),c.jsx("span",{className:"truncate max-w-[180px]",children:oe.name}),c.jsx("span",{role:"button","aria-label":e("chat.input.removeAttachment",{name:oe.name}),className:"ml-1 hover:text-[var(--color-crashed)] cursor-pointer",onClick:ye=>{ye.stopPropagation(),ve(oe.path)},children:c.jsx(Sn,{size:11,strokeWidth:3})})]},oe.path)),Q&&c.jsxs("span",{className:"flex items-center gap-1.5 px-2 py-1 text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:[c.jsx(Xe,{size:11,strokeWidth:2.5,className:"animate-spin"}),e("chat.input.uploading")]})]}),c.jsxs("div",{className:"flex flex-col gap-2 rounded-2xl border-[3px] border-[var(--color-text)] bg-white px-3 py-2 shadow-[3px_3px_0_var(--color-text)] focus-within:shadow-[4px_4px_0_var(--color-text)] transition-shadow",children:[c.jsx("textarea",{ref:O,className:"w-full resize-none border-0 bg-transparent outline-none text-sm leading-relaxed max-h-[200px] px-1 pt-1",placeholder:e(V?"chat.input.dragOver":"chat.input.placeholder"),rows:1,value:m,onChange:oe=>b(oe.target.value),onKeyDown:oe=>{oe.key==="Enter"&&!oe.shiftKey&&!oe.nativeEvent.isComposing&&(oe.preventDefault(),ae())},onPaste:oe=>{const be=Array.from(oe.clipboardData.items??[]).filter(fe=>fe.kind==="file"&&fe.type.startsWith("image/"));if(be.length!==0){oe.preventDefault();for(const fe of be){const Se=fe.getAsFile();Se&&me(Se)}}},"aria-label":e("chat.input.aria")}),c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("button",{type:"button",className:D,onClick:()=>L(!0),disabled:w,"aria-label":e("chat.input.attach.aria"),title:e("chat.input.attach.title"),children:c.jsx(RL,{size:15,strokeWidth:2.5})}),c.jsx(z8,{className:D,disabled:w,onInsert:oe=>b(ye=>ye.trim()?`${ye}
|
|
646
646
|
${oe}`:oe)}),c.jsx("div",{className:"flex-1"}),de?c.jsx("button",{className:"w-9 h-9 flex items-center justify-center rounded-full border-2 border-[var(--color-text)] bg-[var(--color-crashed)] text-white shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px hover:shadow-[3px_3px_0_var(--color-text)] active:translate-x-px active:translate-y-px active:shadow-none transition-transform",onClick:J,type:"button","aria-label":e("chat.input.interrupt.aria"),title:e("chat.input.interrupt"),children:c.jsx($b,{size:14,strokeWidth:3})}):c.jsx("button",{className:"w-9 h-9 flex items-center justify-center rounded-full border-2 border-[var(--color-text)] bg-[var(--color-cta)] text-white shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px hover:shadow-[3px_3px_0_var(--color-text)] active:translate-x-px active:translate-y-px active:shadow-none transition-transform disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:translate-x-0 disabled:hover:translate-y-0 disabled:hover:shadow-[2px_2px_0_var(--color-text)]",onClick:ae,disabled:!m.trim()&&q.length===0||w,type:"button","aria-label":e("chat.input.send.aria"),title:e("chat.input.send"),children:w?c.jsx(Xe,{size:16,strokeWidth:3,className:"animate-spin"}):c.jsx(UN,{size:18,strokeWidth:3})})]})]})]})]}):c.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:c.jsxs("div",{className:"text-center max-w-md",children:[c.jsx("div",{className:"w-20 h-20 rounded-2xl bg-[var(--color-accent-mint)] border-[3px] border-[var(--color-text)] shadow-[3px_3px_0_var(--color-text)] flex items-center justify-center mx-auto mb-4",children:c.jsx(uk,{size:32,strokeWidth:2.5})}),c.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold mb-2",children:e("chat.empty.title")}),c.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:e("chat.empty.hint")}),c.jsx("p",{className:"text-xs text-[var(--color-text-subtle)] italic",children:e("chat.empty.shortcuts")})]})})}),U&&c.jsx(B8,{onCancel:()=>B(!1),onCreate:oe=>I(oe)}),H&&c.jsx(cx,{mode:"file",title:e("chat.filePicker.title"),initialPath:((Ue=d.data)==null?void 0:Ue.cwd)??void 0,onCancel:()=>L(!1),onSelect:oe=>{G(ye=>{if(ye.some(fe=>fe.path===oe))return ye;const be=oe.split(/[\\/]/).pop()||oe;return[...ye,{path:oe,name:be}]}),L(!1)}}),K&&t&&c.jsx(P8,{sessionId:t,path:K,onClose:()=>z(null)})]})}function Nh(e){return/\.(png|jpe?g|gif|webp|svg|avif)$/i.test(e)}function ME(e){return/\.pdf$/i.test(e)}function ly(e){return/\.(txt|md|log|json|yaml|yml|csv|html|xml|tsx?|jsx?|css|sh|ya?ml|conf|toml|ini|env|gitignore|sql|py|rb|go|rs|java|kt|swift|c|cc|cpp|h|hpp)$/i.test(e)}function P8({sessionId:e,path:t,onClose:n}){const r=Pe(),[a,o]=j.useState(null),[l,d]=j.useState(null);j.useEffect(()=>{const g=m=>{m.key==="Escape"&&(m.preventDefault(),n())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[n]),j.useEffect(()=>{if(!ly(t))return;let g=!1;return fetch(Yy(e,t)).then(async m=>{if(!m.ok)throw new Error(`${m.status}`);return m.text()}).then(m=>{g||o(m.length>2e5?m.slice(0,2e5)+`
|
|
647
647
|
|
|
648
|
-
…(truncated)`:m)}).catch(m=>{g||d(m instanceof Error?m.message:String(m))}),()=>{g=!0}},[e,t]);const f=Yy(e,t),h=t.split(/[\\/]/).pop()??t;return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[rgba(45,55,72,0.6)] p-4",role:"presentation",children:c.jsxs("div",{className:"nb-card bg-[var(--color-bg)] max-w-3xl w-full p-5 flex flex-col",style:{maxHeight:"85vh"},role:"dialog","aria-modal":"true","aria-label":r("chat.attachment.preview.aria",{name:h}),children:[c.jsxs("header",{className:"flex items-center justify-between mb-3 shrink-0",children:[c.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[c.jsx(WR,{size:16,strokeWidth:2.5,className:"flex-shrink-0"}),c.jsx("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base truncate",children:h})]}),c.jsx("button",{type:"button",className:"p-1 hover:bg-[var(--color-bg-cream)] rounded flex-shrink-0",onClick:n,"aria-label":r("chat.attachment.close.aria"),children:c.jsx(Sn,{size:16,strokeWidth:3})})]}),c.jsx("p",{className:"text-[10px] text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] truncate mb-2 shrink-0",title:t,dir:"rtl",children:t}),c.jsxs("div",{className:"flex-1 overflow-auto border-2 border-[var(--color-text)] rounded-lg bg-[var(--color-bg-cream)] min-h-0",children:[Nh(t)&&c.jsx("div",{className:"flex items-center justify-center p-4",children:c.jsx("img",{src:f,alt:`Preview: ${h}`,className:"max-w-full max-h-[60vh] object-contain"})}),ME(t)&&c.jsx("iframe",{src:f,title:`PDF: ${h}`,className:"w-full",style:{height:"60vh",border:0}}),ly(t)&&c.jsx("pre",{className:"p-3 text-xs font-[family-name:var(--font-mono)] whitespace-pre-wrap break-words",children:l?c.jsx("span",{className:"text-[var(--color-crashed)]",children:r("chat.attachment.readErr",{detail:l})}):a===null?c.jsx("span",{className:"text-[var(--color-text-muted)]",children:r("chat.attachment.loading")}):a}),!Nh(t)&&!ME(t)&&!ly(t)&&c.jsxs("div",{className:"p-6 text-center text-sm text-[var(--color-text-muted)]",children:[c.jsx("p",{className:"mb-3",children:r("chat.attachment.unsupported")}),c.jsx("a",{href:f,download:h,className:"nb-btn nb-btn-primary inline-flex",children:r("chat.attachment.download")})]})]})]})})}function B8({onCancel:e,onCreate:t}){var N;const n=Pe(),[r,a]=j.useState(""),[o,l]=j.useState(""),[d,f]=j.useState(""),[h,g]=j.useState(!1),[m,y]=j.useState(!1),[b,w]=j.useState(!1),v=Ye({queryKey:["providers"],queryFn:lx}),S=Ye({queryKey:["system-agents"],queryFn:Hb}),E=l2(((N=v.data)==null?void 0:N.anthropic)??[]);j.useEffect(()=>{var A;if(h)return;const _=(A=S.data)==null?void 0:A.agents.worker;if(!_)return;const M=`${_.providerId||"official"}::${_.model}`;E.some(O=>`${O.providerId}::${O.model}`===M)&&f(M)},[S.data,E,h]),j.useEffect(()=>{if(b)return;const _=M=>{M.key==="Escape"&&(M.preventDefault(),e())};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[e,b]);const C=async()=>{if(!m){y(!0);try{const[_,M]=d?d.split("::"):[void 0,void 0];t({title:r.trim()||void 0,cwd:o.trim()||void 0,agentKind:"claude",model:M,providerId:_})}finally{y(!1)}}};return c.jsxs("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-[rgba(45,55,72,0.4)] p-4",role:"presentation",children:[c.jsxs("div",{className:"nb-card bg-[var(--color-bg)] max-w-md w-full p-5",role:"dialog","aria-modal":"true","aria-label":n("chat.newSession.title.aria"),children:[c.jsxs("header",{className:"flex items-center justify-between mb-4",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:n("chat.newSession.title")}),c.jsx("button",{type:"button",className:"p-1 hover:bg-[var(--color-bg-cream)] rounded",onClick:e,"aria-label":n("chat.newSession.close.aria"),children:c.jsx(Sn,{size:16,strokeWidth:3})})]}),c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{htmlFor:"new-session-model",className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.model")}),c.jsxs("select",{id:"new-session-model",className:"nb-input w-full font-[family-name:var(--font-mono)] text-sm",value:d,onChange:_=>{g(!0),f(_.target.value)},children:[c.jsx("option",{value:"",children:n("chat.newSession.field.model.default")}),E.map(_=>c.jsx("option",{value:`${_.providerId}::${_.model}`,children:_.label},`${_.providerId}::${_.model}`))]})]}),c.jsxs("div",{children:[c.jsx("label",{htmlFor:"new-session-title",className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.title")}),c.jsx("input",{id:"new-session-title",type:"text",className:"nb-input w-full",placeholder:n("chat.newSession.field.title.placeholder"),value:r,onChange:_=>a(_.target.value),autoFocus:!0})]}),c.jsxs("div",{children:[c.jsx("label",{htmlFor:"new-session-cwd",className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.cwd")}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{id:"new-session-cwd",type:"text",className:"nb-input flex-1 font-[family-name:var(--font-mono)] text-sm",placeholder:"/home/coral/projects/my-app",value:o,onChange:_=>l(_.target.value)}),c.jsxs("button",{type:"button",className:"nb-btn flex-shrink-0",onClick:()=>w(!0),"aria-label":n("chat.newSession.field.cwd.browseAria"),title:n("chat.newSession.field.cwd.browseAria"),children:[c.jsx(HN,{size:14,strokeWidth:2.5}),n("chat.newSession.field.cwd.browse")]})]}),c.jsxs("p",{className:"text-[11px] text-[var(--color-text-muted)] mt-1.5 leading-relaxed",children:[c.jsx(ph,{size:10,strokeWidth:2.5,className:"inline mr-1 -mt-0.5"}),n("chat.newSession.field.cwd.help1")," ",n("chat.newSession.field.cwd.help2")]})]}),c.jsxs("div",{className:"flex gap-2 justify-end pt-2",children:[c.jsx("button",{type:"button",className:"nb-btn",onClick:e,children:n("chat.newSession.cancel")}),c.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary",onClick:C,disabled:m,children:[m?c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):c.jsx(pr,{size:14,strokeWidth:3}),n("chat.newSession.create")]})]})]})]}),b&&c.jsx(cx,{initialPath:o.trim()||void 0,onCancel:()=>w(!1),onSelect:_=>{l(_),w(!1)}})]})}function $8({msg:e,sessionId:t,onPreviewAttachment:n}){const r=Pe(),a=e.role==="user",o=e.role==="error",l=e.blocks&&e.blocks.length>0?e.blocks:[{type:"text",text:e.content}],d=e.attachments??[];return c.jsx("div",{className:a?"self-end max-w-3xl":"self-start max-w-3xl",children:c.jsxs("div",{className:["nb-card",a?"bg-[var(--color-secondary)]":o?"bg-[var(--color-crashed-bg)]":"bg-[var(--color-bg)]"].join(" "),children:[c.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-2 flex items-center gap-2",children:[r(a?"chat.message.role.you":o?"chat.message.role.error":"chat.message.role.assistant"),c.jsx("span",{className:"font-normal",children:"·"}),c.jsx("span",{className:"font-normal cursor-help",title:K8(e.ts),children:Vj(e.ts,r)})]}),c.jsx("div",{className:"flex flex-col gap-2",children:l.map((f,h)=>c.jsx(q8,{block:f},h))}),d.length>0&&t&&c.jsx("div",{className:"mt-3 pt-3 border-t-2 border-dashed border-[var(--color-text)]/30 flex flex-wrap gap-2",children:d.map(f=>c.jsx(U8,{sessionId:t,path:f,onPreview:()=>n(f)},f))}),e.truncated&&c.jsx("p",{className:"mt-3 px-3 py-2 bg-[var(--color-stuck-bg)] border-2 border-[var(--color-stuck)] rounded-lg text-xs text-[var(--color-stuck)] font-bold",children:r("chat.message.truncated")})]})})}function U8({sessionId:e,path:t,onPreview:n}){const r=Pe(),a=t.split(/[\\/]/).pop()??t;return Nh(t)?c.jsx("button",{type:"button",onClick:n,className:"block rounded-md overflow-hidden border-2 border-[var(--color-text)] hover:shadow-[2px_2px_0_var(--color-text)] transition-shadow",title:r("chat.attachment.previewSimpleTooltip",{name:a}),children:c.jsx("img",{src:Yy(e,t),alt:a,className:"block max-h-40 max-w-[12rem] object-cover",loading:"lazy"})}):c.jsxs("button",{type:"button",onClick:n,className:"flex items-center gap-1.5 px-2 py-1 rounded-md bg-[var(--color-bg)] border-2 border-[var(--color-text)] text-xs font-[family-name:var(--font-mono)] hover:bg-[var(--color-accent-mint)]",title:r("chat.attachment.previewTooltip",{name:a,path:t}),children:[c.jsx(Fh,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}),c.jsx("span",{className:"truncate max-w-[200px]",children:a})]})}function F8({pending:e}){const t=(()=>{for(let n=e.blocks.length-1;n>=0;n--)if(e.blocks[n].type==="text")return n;return-1})();return c.jsx("div",{className:"self-start max-w-3xl",children:c.jsxs("div",{className:"nb-card bg-[var(--color-bg)]",children:[c.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-2 flex items-center gap-2",children:["assistant",c.jsx("span",{className:"font-normal",children:"·"}),c.jsxs("span",{className:"flex items-center gap-1 font-normal text-[var(--color-running)]",children:[c.jsx(Xe,{size:10,strokeWidth:3,className:"animate-spin"}),"streaming"]})]}),c.jsxs("div",{className:"flex flex-col gap-2",children:[e.blocks.length===0&&c.jsx("p",{className:"text-sm text-[var(--color-text-muted)] italic",children:"…"}),e.blocks.map((n,r)=>{if(n.type==="text"){const a=r===t;return c.jsxs("div",{className:"relative",children:[c.jsx(Kj,{text:n.displayed}),a&&c.jsx("span",{className:"inline-block w-2 h-4 ml-1 bg-[var(--color-text)] animate-pulse align-middle"})]},r)}return c.jsx(Gj,{tool:n},r)})]})]})})}function q8({block:e}){return e.type==="text"?c.jsx(Kj,{text:e.text}):c.jsx(Gj,{tool:e})}function Kj({text:e}){return e?c.jsx("div",{className:"text-sm font-[family-name:var(--font-body)] break-words prose-chat",children:c.jsx(Cx,{remarkPlugins:[Dx],rehypePlugins:[Lx],children:e})}):null}function H8(e){if(e==null||typeof e!="object")return typeof e=="string"?e:"";const t=e,n=a=>typeof t[a]=="string"?t[a]:void 0;return n("file_path")??n("path")??n("notebook_path")??n("command")??n("pattern")??n("query")??n("url")??n("name")??n("description")??n("prompt")??Object.values(t).find(a=>typeof a=="string"&&a.trim())??""}function Gj({tool:e}){const[t,n]=j.useState(!1),r=e.status==="completed"||e.status==="complete",a=e.status==="failed",o=!r&&!a,l=H8(e.input),d=e.input!=null&&(typeof e.input!="object"||Object.keys(e.input).length>0);return c.jsxs("div",{className:"border-2 border-[var(--color-text)] rounded-lg overflow-hidden bg-[var(--color-bg-cream)]",children:[c.jsxs("button",{type:"button",onClick:()=>n(f=>!f),className:"w-full flex items-center gap-2 px-3 py-2 text-xs font-[family-name:var(--font-mono)] hover:bg-[var(--color-accent-yellow)] transition-colors",children:[c.jsx(Zl,{size:12,strokeWidth:3,className:["transition-transform flex-shrink-0",t?"rotate-90":""].join(" ")}),c.jsx(n_,{size:12,strokeWidth:2.5,className:"flex-shrink-0"}),c.jsx("span",{className:"font-bold flex-shrink-0",children:e.title||e.kind}),c.jsx("span",{className:"flex-1 text-left text-[var(--color-text-muted)] truncate",title:l,children:l}),o&&c.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin text-[var(--color-running)] flex-shrink-0"}),r&&c.jsx(Eu,{size:12,strokeWidth:2.5,className:"text-[var(--color-running)] flex-shrink-0"}),a&&c.jsx(FN,{size:12,strokeWidth:2.5,className:"text-[var(--color-crashed)] flex-shrink-0"})]}),t&&c.jsxs("div",{className:"px-3 py-2 text-xs font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] border-t-2 border-[var(--color-text)] space-y-1",children:[d?c.jsx("pre",{className:"whitespace-pre-wrap break-all text-[var(--color-text)] max-h-72 overflow-auto",children:typeof e.input=="string"?e.input:JSON.stringify(e.input,null,2)}):c.jsx("div",{children:"无参数"}),c.jsxs("div",{className:"opacity-60",children:["id: ",e.id," · ",e.status]})]})]})}function Vj(e,t){if(!e)return"";const n=new Date(e),r=Date.now()-n.getTime();return r<6e4?t("kanban.time.justNow"):r<36e5?t("kanban.time.minutes",{n:Math.floor(r/6e4)}):r<864e5?t("kanban.time.hours",{n:Math.floor(r/36e5)}):n.toLocaleDateString()}function K8(e){if(!e)return;const t=new Date(e),n=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}function G8(){return ht("/api/processes").then(e=>e.data)}function V8(e){return Ri(`/api/processes/${e}/kill`)}function Y8(){return ht("/api/processes/reclaim")}async function Q8(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 DE="border-[3px] border-[var(--color-text)] rounded-2xl bg-white shadow-[4px_4px_0_var(--color-text)]";function W8(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 r=Math.floor(n/60);return r<24?`${r}h${n%60?` ${n%60}m`:""}`:`${Math.floor(r/24)}d${r%24?` ${r%24}h`:""}`}function cy(e){return e.project?e.project:e.cwd?e.cwd.split("/").filter(Boolean).pop()??e.slot:e.slot}function OE(e){const t=/^session-chat-(.+)$/.exec(e.slot);return(t==null?void 0:t[1])??null}function X8({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 c.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] text-xs font-bold font-[family-name:var(--font-mono)] ${n}`,children:[c.jsx("span",{className:`w-2 h-2 rounded-full ${e.alive?"bg-green-600":"bg-gray-400"}`}),t]})}function Z8(){var w;const e=Pe(),t=Gt(),[n,r]=j.useState(null),[a,o]=j.useState("all"),l=Ye({queryKey:["processes"],queryFn:G8,refetchInterval:5e3}),d=Ct({mutationFn:V8,onSuccess:v=>{r(v.message),t.invalidateQueries({queryKey:["processes"]})},onError:v=>r(v instanceof Error?v.message:String(v))}),f=Ye({queryKey:["reclaim"],queryFn:Y8}),[h,g]=j.useState("");j.useEffect(()=>{f.data&&h===""&&g(String(f.data.idleMinutes))},[f.data,h]);const m=Ct({mutationFn:v=>Q8(v),onSuccess:v=>{r(`自动回收已设为 ${v.idleMinutes} 分钟空闲`),t.invalidateQueries({queryKey:["reclaim"]})},onError:v=>r(v instanceof Error?v.message:String(v))}),y=l.data??[],b=y.filter(v=>a==="all"?!0:v.kind===a);return c.jsxs("div",{className:"max-w-full",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[c.jsx(hh,{size:22,strokeWidth:2.5}),c.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl",children:e("processes.title")}),c.jsxs("button",{type:"button","aria-label":e("processes.refresh"),onClick:()=>t.invalidateQueries({queryKey:["processes"]}),className:"ml-auto inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl border-2 border-[var(--color-text)] bg-white text-sm font-semibold shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px focus-visible:outline focus-visible:outline-2",children:[l.isFetching?c.jsx(Xe,{size:15,className:"animate-spin"}):c.jsx(ya,{size:15}),e("processes.refresh")]})]}),c.jsxs("p",{className:"text-sm text-[var(--color-text)]/70 mb-3",children:[e("processes.subtitle")," · ",e("processes.aliveCount").replace("{n}",String(y.length))]}),c.jsxs("div",{className:`${DE} px-4 py-3 mb-4 flex flex-wrap items-center gap-2`,style:{boxShadow:"2px 2px 0 var(--color-text)"},children:[c.jsx(c3,{size:16,strokeWidth:2.5}),c.jsx("span",{className:"text-sm font-bold",children:"自动回收"}),c.jsx("span",{className:"text-sm text-[var(--color-text)]/70",children:"会话空闲"}),c.jsx("input",{type:"number",min:1,max:1440,value:h,onChange:v=>g(v.target.value),className:"w-20 px-2 py-1 rounded-lg border-2 border-[var(--color-text)] font-[family-name:var(--font-mono)] text-sm","aria-label":"自动回收空闲分钟数"}),c.jsx("span",{className:"text-sm text-[var(--color-text)]/70",children:"分钟后自动停(下次访问自动续上,不丢上下文)"}),c.jsxs("button",{type:"button",disabled:m.isPending||h===""||Number(h)===((w=f.data)==null?void 0:w.idleMinutes),onClick:()=>m.mutate(Math.round(Number(h))),className:"ml-auto inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border-2 border-[var(--color-text)] bg-[var(--color-accent-mint)] text-sm font-bold shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px disabled:opacity-50 focus-visible:outline focus-visible:outline-2","aria-label":"保存自动回收设置",children:[m.isPending?c.jsx(Xe,{size:14,className:"animate-spin"}):c.jsx(Oi,{size:14,strokeWidth:3}),"保存"]})]}),n&&c.jsx("div",{className:"mb-3 px-3 py-2 rounded-xl border-2 border-[var(--color-text)] bg-[var(--color-bg-cream)] text-sm font-mono",children:n}),c.jsx("div",{className:"flex flex-wrap gap-2 mb-3 items-center",children:["all","worker","chat"].map(v=>c.jsx("button",{type:"button","aria-label":e(`processes.kind.${v}`),onClick:()=>o(v),className:`px-3 py-1 rounded-lg border-2 border-[var(--color-text)] text-sm font-bold shadow-[2px_2px_0_var(--color-text)] focus-visible:outline focus-visible:outline-2 ${a===v?"bg-[var(--color-accent-yellow)]":"bg-white hover:-translate-x-px hover:-translate-y-px"}`,children:e(`processes.kind.${v}`)},v))}),c.jsx("div",{className:`${DE} overflow-hidden`,children:c.jsxs("table",{className:"w-full text-sm",children:[c.jsx("thead",{className:"bg-[var(--color-bg-cream)] font-[family-name:var(--font-heading)]",children:c.jsxs("tr",{className:"text-left",children:[c.jsx("th",{className:"px-3 py-2",children:e("processes.col.kind")}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.slot")}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.project")}),c.jsx("th",{className:"px-3 py-2",children:"PID"}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.state")}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.memory")}),c.jsx("th",{className:"px-3 py-2",children:"运行时间"}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.action")})]})}),c.jsxs("tbody",{className:"font-[family-name:var(--font-mono)]",children:[b.length===0&&c.jsx("tr",{children:c.jsx("td",{colSpan:8,className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:e("processes.empty")})}),b.map(v=>c.jsxs("tr",{className:"border-t-2 border-[var(--color-text)]/10",title:v.cwd??"",children:[c.jsx("td",{className:"px-3 py-2",children:c.jsx("span",{className:`inline-block px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] text-xs font-bold ${v.kind==="worker"?"bg-[var(--color-accent-yellow)]":"bg-[var(--color-accent-purple)]"}`,children:e(`processes.kind.${v.kind}`)})}),c.jsx("td",{className:"px-3 py-2 max-w-[220px] truncate",children:v.slot}),c.jsx("td",{className:"px-3 py-2 max-w-[220px] truncate",children:v.kind==="chat"&&OE(v)?c.jsxs(xs,{to:`/chat/${OE(v)}`,className:"inline-flex items-center gap-1 font-semibold text-[var(--color-text)] underline decoration-2 underline-offset-2 hover:opacity-70",title:"打开对话窗口",children:[c.jsx(GN,{size:12,strokeWidth:2.5})," ",cy(v)]}):v.kind==="worker"&&v.project?c.jsxs(xs,{to:`/board?project=${encodeURIComponent(v.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:[c.jsx(hh,{size:12,strokeWidth:2.5})," ",cy(v)]}):c.jsx("span",{children:cy(v)})}),c.jsx("td",{className:"px-3 py-2",children:v.pid??"—"}),c.jsx("td",{className:"px-3 py-2",children:c.jsx(X8,{p:v})}),c.jsx("td",{className:"px-3 py-2",children:v.memoryMB!=null?`${v.memoryMB} MB`:"—"}),c.jsx("td",{className:"px-3 py-2",children:W8(v.startedAt)}),c.jsx("td",{className:"px-3 py-2",children:v.alive&&v.pid!=null?c.jsxs("button",{type:"button","aria-label":`${e("processes.kill")} ${v.slot}`,onClick:()=>{confirm(e("processes.killConfirm").replace("{slot}",v.slot))&&d.mutate(v.pid)},className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-lg border-2 border-[var(--color-text)] bg-[var(--color-accent-pink)] text-xs font-bold shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px active:translate-x-0.5 active:translate-y-0.5 focus-visible:outline focus-visible:outline-2",children:[c.jsx(FN,{size:13})," ",e("processes.kill")]}):c.jsx("span",{className:"text-[var(--color-text)]/40 text-xs",children:"—"})})]},v.slot))]})]})})]})}function J8(e={}){const t=new URLSearchParams;e.project&&t.set("project",e.project),e.action&&t.set("action",e.action);const n=t.toString();return ht(`/api/audit${n?`?${n}`:""}`).then(r=>r.data)}const eq="border-[3px] border-[var(--color-text)] rounded-2xl bg-white shadow-[4px_4px_0_var(--color-text)]",tq={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 nq(){const e=Pe(),t=Gt(),[n,r]=j.useState(""),a=Ye({queryKey:["audit",n],queryFn:()=>J8(n?{action:n}:{}),refetchInterval:8e3}),o=a.data??[],l=d=>e(`audit.action.${d}`);return c.jsxs("div",{className:"max-w-full",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[c.jsx(Bb,{size:22,strokeWidth:2.5}),c.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl",children:e("audit.title")}),c.jsxs("button",{type:"button","aria-label":e("audit.refresh"),onClick:()=>t.invalidateQueries({queryKey:["audit"]}),className:"ml-auto inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl border-2 border-[var(--color-text)] bg-white text-sm font-semibold shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px focus-visible:outline focus-visible:outline-2",children:[a.isFetching?c.jsx(Xe,{size:15,className:"animate-spin"}):c.jsx(ya,{size:15}),e("audit.refresh")]})]}),c.jsx("p",{className:"text-sm text-[var(--color-text)]/70 mb-4",children:e("audit.subtitle")}),c.jsx("div",{className:"flex gap-2 mb-3",children:["","create","modify","delete","daemon"].map(d=>c.jsx("button",{type:"button","aria-label":d?l(d):e("audit.filter.all"),onClick:()=>r(d),className:`px-3 py-1 rounded-lg border-2 border-[var(--color-text)] text-sm font-bold shadow-[2px_2px_0_var(--color-text)] focus-visible:outline focus-visible:outline-2 ${n===d?"bg-[var(--color-accent-purple)]":"bg-white hover:-translate-x-px hover:-translate-y-px"}`,children:d?l(d):e("audit.filter.all")},d||"all"))}),c.jsx("div",{className:`${eq} overflow-hidden`,children:c.jsxs("table",{className:"w-full text-sm",children:[c.jsx("thead",{className:"bg-[var(--color-bg-cream)] font-[family-name:var(--font-heading)]",children:c.jsxs("tr",{className:"text-left",children:[c.jsx("th",{className:"px-3 py-2",children:e("audit.col.time")}),c.jsx("th",{className:"px-3 py-2",children:e("audit.col.action")}),c.jsx("th",{className:"px-3 py-2",children:e("audit.col.project")}),c.jsx("th",{className:"px-3 py-2",children:e("audit.col.detail")})]})}),c.jsxs("tbody",{className:"font-[family-name:var(--font-mono)]",children:[o.length===0&&c.jsx("tr",{children:c.jsx("td",{colSpan:4,className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:e("audit.empty")})}),o.map((d,f)=>c.jsxs("tr",{className:"border-t-2 border-[var(--color-text)]/10",children:[c.jsx("td",{className:"px-3 py-2 whitespace-nowrap",children:new Date(d.ts).toLocaleString()}),c.jsx("td",{className:"px-3 py-2",children:c.jsx("span",{className:`inline-block px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] text-xs font-bold ${tq[d.action]}`,children:l(d.action)})}),c.jsx("td",{className:"px-3 py-2",children:d.project}),c.jsx("td",{className:"px-3 py-2 text-[var(--color-text)]/70",children:d.detail??(d.source?`(${d.source})`:"—")})]},`${d.ts}-${f}`))]})]})})]})}const rq=["convention","decision","gotcha","pattern","reference","note"];function Gs(e){return`${e.scope}:${e.project??e.agentId??""}`}function Bf(e){return e.scope==="global"?`全局 (${e.count})`:e.scope==="project"?`项目:${e.project} (${e.count})`:`会话:${e.agentId} (${e.count})`}function Vs(e){const t={scope:e.scope};return e.project&&(t.project=e.project),e.agentId&&(t.agentId=e.agentId),t}async function ia(e,t){const n=await fetch(e,t);if(!n.ok){const r=await n.json().catch(()=>null);throw new Error((r==null?void 0:r.detail)||(r==null?void 0:r.title)||`HTTP ${n.status}`)}return await n.json()}const iq=()=>({title:"",body:"",category:"note",tags:"",salience:3});function aq(){const e=Pe(),[t,n]=j.useState([]),[r,a]=j.useState(null),[o,l]=j.useState([]),[d,f]=j.useState(null),[h,g]=j.useState(!1),[m,y]=j.useState(""),[b,w]=j.useState(!0),[v,S]=j.useState([]),[E,C]=j.useState(null),[N,_]=j.useState(null),[M,A]=j.useState(null),[O,D]=j.useState(""),[U,B]=j.useState(""),q=j.useCallback(async()=>{try{const{scopes:P}=await ia("/api/memory/scopes");n(P),a(I=>I??P[0]??null)}catch(P){f(P instanceof Error?P.message:String(P))}},[]),G=j.useCallback(async P=>{try{const I=new URLSearchParams(Vs(P)).toString(),{data:ae}=await ia(`/api/memory/entries?${I}`);l(ae)}catch(I){f(I instanceof Error?I.message:String(I))}},[]);j.useEffect(()=>{q(),ia("/api/system/memory").then(P=>{A(P),D(P.mode),B(P.externalUrl)}).catch(()=>{})},[q]),j.useEffect(()=>{r&&G(r)},[r,G]);const Q=j.useCallback(async()=>{if(!m.trim()){S([]);return}g(!0),f(null);try{const P=new URLSearchParams({q:m,limit:"20"});if(b)P.set("all","1");else if(r)for(const[ae,me]of Object.entries(Vs(r)))P.set(ae,me);const{results:I}=await ia(`/api/memory/recall?${P.toString()}`);S(I)}catch(P){f(P instanceof Error?P.message:String(P))}finally{g(!1)}},[m,b,r]),R=j.useCallback(async()=>{if(!(!r||!E)){g(!0),f(null);try{await ia("/api/memory/entries",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...Vs(r),id:E.id,title:E.title,body:E.body,category:E.category,tags:E.tags.split(",").map(P=>P.trim()).filter(Boolean),salience:E.salience})}),C(null),await Promise.all([G(r),q()])}catch(P){f(P instanceof Error?P.message:String(P))}finally{g(!1)}}},[r,E,G,q]),H=j.useCallback(async P=>{if(r){g(!0),f(null);try{const I=new URLSearchParams(Vs(r)).toString();await ia(`/api/memory/entries/${encodeURIComponent(P)}?${I}`,{method:"DELETE"}),await Promise.all([G(r),q()])}catch(I){f(I instanceof Error?I.message:String(I))}finally{g(!1)}}},[r,G,q]),L=j.useCallback(async(P,I,ae)=>{if(r){g(!0),f(null);try{await ia("/api/memory/promote",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({from:Vs(r),id:P.id,to:Vs(I),move:ae})}),_(null),await Promise.all([G(r),q()])}catch(me){f(me instanceof Error?me.message:String(me))}finally{g(!1)}}},[r,G,q]),V=j.useCallback(async()=>{if(r){g(!0),f(null);try{const I=(await ia("/api/memory/gc",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(Vs(r))})).results[0];I&&f(`收敛完成:清 tombstone ${I.purged}、去重 ${I.deduped}、剩余 ${I.kept}`),await Promise.all([G(r),q()])}catch(P){f(P instanceof Error?P.message:String(P))}finally{g(!1)}}},[r,G,q]),Y=j.useCallback(async()=>{g(!0),f(null);try{const P=await ia("/api/system/memory",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({mode:O,externalUrl:U})});A(P),D(P.mode),B(P.externalUrl),f("模式已保存(重启 worker 生效)")}catch(P){f(P instanceof Error?P.message:String(P))}finally{g(!1)}},[O,U]),K=M!=null&&(O!==M.mode||U!==M.externalUrl),z=O==="external"||O==="local+external",$=j.useMemo(()=>N?t.filter(P=>Gs(P)!==Gs(r??{scope:""})):[],[N,t,r]);return c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[c.jsxs("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl text-[var(--color-text)]",children:["🧠 ",e("nav.memory")]}),c.jsx("span",{className:"text-xs text-[var(--color-text)] opacity-60",children:"本地记忆 v2 · markdown 真源"})]}),M&&c.jsxs("section",{className:"nb-card flex flex-wrap items-end gap-3",children:[c.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[c.jsx("span",{className:"font-bold",children:"记忆模式"}),c.jsx("select",{className:"nb-input",value:O,onChange:P=>D(P.target.value),"aria-label":"记忆模式",children:M.modeOptions.map(P=>c.jsx("option",{value:P,children:P},P))})]}),z&&c.jsxs("label",{className:"flex flex-col gap-1 text-sm flex-1 min-w-[220px]",children:[c.jsx("span",{className:"font-bold",children:"外部后端地址"}),c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",value:U,onChange:P=>B(P.target.value),placeholder:"http://127.0.0.1:3113",spellCheck:!1,"aria-label":"外部后端地址"})]}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:Y,disabled:h||!K,"aria-label":"保存模式",children:"保存模式"})]}),c.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[c.jsx("input",{value:m,onChange:P=>y(P.target.value),onKeyDown:P=>P.key==="Enter"&&Q(),placeholder:"检索记忆…","aria-label":"检索记忆",className:"nb-input flex-1 min-w-[200px] font-[family-name:var(--font-mono)] text-sm"}),c.jsxs("label",{className:"flex items-center gap-1 text-sm font-semibold",children:[c.jsx("input",{type:"checkbox",checked:b,onChange:P=>w(P.target.checked),"aria-label":"全局检索"}),"全局"]}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:Q,disabled:h,"aria-label":"检索",children:h?"…":"检索"})]}),d&&c.jsxs("div",{className:"text-sm text-[var(--color-text)] font-semibold nb-card py-2",children:["ℹ ",d]}),v.length>0&&c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsxs("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:["检索结果(",v.length,")"]}),v.map(({entry:P,score:I})=>c.jsxs("div",{className:"nb-card",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)]",children:[c.jsx("span",{children:P.scope==="project"?`项目:${P.project}`:P.scope}),c.jsx("span",{children:"·"}),c.jsx("span",{children:P.category}),c.jsx("span",{children:"·"}),c.jsxs("span",{children:["score ",I.toFixed(3)]})]}),c.jsx("div",{className:"font-bold text-sm mt-1",children:P.title}),c.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:P.body.slice(0,300)})]},P.id))]}),c.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[c.jsx("select",{className:"nb-input",value:r?Gs(r):"",onChange:P=>a(t.find(I=>Gs(I)===P.target.value)??null),"aria-label":"选择作用域",children:t.map(P=>c.jsx("option",{value:Gs(P),children:Bf(P)},Gs(P)))}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>C(iq()),disabled:!r,"aria-label":"新建记忆",children:"+ 新建"}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-yellow",onClick:V,disabled:h||!r,"aria-label":"收敛去重",children:"收敛"})]}),E&&c.jsxs("section",{className:"nb-card flex flex-col gap-2",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:E.id?"编辑记忆":"新建记忆"}),c.jsx("input",{className:"nb-input text-sm",value:E.title,onChange:P=>C({...E,title:P.target.value}),placeholder:"标题","aria-label":"标题"}),c.jsxs("div",{className:"flex gap-2 flex-wrap",children:[c.jsx("select",{className:"nb-input",value:E.category,onChange:P=>C({...E,category:P.target.value}),"aria-label":"类别",children:rq.map(P=>c.jsx("option",{value:P,children:P},P))}),c.jsx("input",{className:"nb-input flex-1 min-w-[160px] text-sm",value:E.tags,onChange:P=>C({...E,tags:P.target.value}),placeholder:"标签(逗号分隔)","aria-label":"标签"}),c.jsxs("label",{className:"flex items-center gap-1 text-sm",children:["显著度",c.jsx("input",{className:"nb-input w-16",type:"number",min:1,max:5,value:E.salience,onChange:P=>C({...E,salience:Number(P.target.value)}),"aria-label":"显著度"})]})]}),c.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm min-h-[120px]",value:E.body,onChange:P=>C({...E,body:P.target.value}),placeholder:"正文","aria-label":"正文"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:R,disabled:h||!E.title.trim()||!E.body.trim(),"aria-label":"保存",children:"保存"}),c.jsx("button",{type:"button",className:"nb-btn",onClick:()=>C(null),"aria-label":"取消",children:"取消"})]})]}),c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:r?Bf(r):"条目"}),o.length===0&&c.jsx("div",{className:"nb-card text-sm opacity-60",children:"(无记忆)"}),o.map(P=>c.jsxs("div",{className:"nb-card",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)] flex-wrap",children:[c.jsx("span",{className:"nb-badge",children:P.category}),c.jsxs("span",{children:["s",P.salience]}),c.jsx("span",{children:"·"}),c.jsx("span",{children:P.source}),P.tags.map(I=>c.jsxs("span",{children:["#",I]},I))]}),c.jsx("div",{className:"font-bold text-sm mt-1",children:P.title}),c.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:P.body.slice(0,400)}),c.jsxs("div",{className:"flex gap-2 mt-2",children:[c.jsx("button",{type:"button",className:"nb-btn nb-btn-blue text-xs",onClick:()=>C({id:P.id,title:P.title,body:P.body,category:P.category,tags:P.tags.join(", "),salience:P.salience}),"aria-label":"编辑",children:"编辑"}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-purple text-xs",onClick:()=>_(P),"aria-label":"提升",children:"提升"}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-danger text-xs",onClick:()=>H(P.id),"aria-label":"删除",children:"删除"})]}),(N==null?void 0:N.id)===P.id&&c.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 border-t-[3px] border-[var(--color-text)] pt-2",children:[c.jsx("span",{className:"text-xs font-bold",children:"提升到:"}),$.map(I=>c.jsx("button",{type:"button",className:"nb-btn nb-btn-mint text-xs",onClick:()=>L(P,I,!1),"aria-label":`复制到${Bf(I)}`,children:Bf(I)},Gs(I))),$.length===0&&c.jsx("span",{className:"text-xs opacity-60",children:"(无其它作用域)"}),c.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>_(null),"aria-label":"取消提升",children:"取消"})]})]},P.id))]})]})}async function sq(){return(await ht("/api/channels")).data??{console:{},adapters:[]}}async function oq(e){return(await qb("/api/channels",e)).data}async function lq(){return(await ht("/api/codex-proxy")).data}async function cq(){return(await Ri("/api/codex-proxy/install")).data}async function uq(e){const t=await fetch(`/api/codex-proxy?purgeAuth=${e?"1":"0"}`,{method:"DELETE",headers:{Accept:"application/json"}});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return(await t.json()).data}async function dq(){return(await Ri("/api/codex-proxy/auth/start")).data}async function fq(){await Ri("/api/codex-proxy/auth/cancel")}const RE=[{key:"memory",labelKey:"plugins.tab.memory"},{key:"channel",labelKey:"plugins.tab.channel"},{key:"model",labelKey:"plugins.tab.model"},{key:"tool",labelKey:"plugins.tab.tool"}];function hq(){const e=Pe(),[t,n]=j.useState("memory");return c.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[c.jsxs("header",{children:[c.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:e("plugins.h1")}),c.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:e("plugins.desc")})]}),c.jsx("div",{role:"tablist","aria-label":e("plugins.h1"),className:"flex gap-2 flex-wrap",children:RE.map(r=>{const a=t===r.key;return c.jsx("button",{role:"tab","aria-selected":a,type:"button",onClick:()=>n(r.key),className:["px-4 py-2 rounded-xl font-bold text-sm border-2 transition-transform duration-150",a?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[3px_3px_0_var(--color-text)]":"border-[var(--color-text)] bg-white hover:-translate-x-px hover:-translate-y-px hover:shadow-[3px_3px_0_var(--color-text)]"].join(" "),children:e(r.labelKey)},r.key)})}),c.jsx("div",{role:"tabpanel",children:t==="memory"?c.jsx(mq,{}):t==="channel"?c.jsx(wq,{}):t==="model"?c.jsx(gq,{}):c.jsx(pq,{label:e(RE.find(r=>r.key===t).labelKey)})})]})}function pq({label:e}){const t=Pe();return c.jsx("section",{className:"nb-card",children:c.jsxs("p",{className:"text-[var(--color-text-muted)] text-sm",children:[e," — ",t("plugins.comingSoon")]})})}function mq(){var w,v,S;const e=Pe(),t=Gt(),{alert:n}=un(),r=Ye({queryKey:["system-memory"],queryFn:O3}),[a,o]=j.useState(null),[l,d]=j.useState(null);j.useEffect(()=>{r.data&&a===null&&(o(r.data.provider),d(r.data.url))},[r.data,a]);const f=a??((w=r.data)==null?void 0:w.provider)??"agentmemory",h=l??((v=r.data)==null?void 0:v.url)??"",g=r.data!=null&&(f!==r.data.provider||f==="custom"&&h!==r.data.url),m=E=>{const C=`system.memory.opt.${E}`;return e(C)},y=Ct({mutationFn:()=>R3(f,f==="custom"?h:""),onSuccess:()=>{t.invalidateQueries({queryKey:["system-memory"]}),t.invalidateQueries({queryKey:["system-env"]})},onError:E=>{n({title:e("system.memory.error"),body:E instanceof Error?E.message:String(E)})}}),b=((S=r.data)==null?void 0:S.options)??["none","builtin","agentmemory","custom"];return c.jsxs("section",{className:"nb-card",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:e("system.memory.title")}),c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-3",children:e("system.memory.desc")}),c.jsxs("div",{className:"flex flex-col gap-3 max-w-md",children:[c.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[c.jsx("span",{className:"font-bold",children:e("system.memory.provider")}),c.jsx("select",{className:"nb-input",value:f,onChange:E=>o(E.target.value),"aria-label":e("system.memory.provider"),children:b.map(E=>c.jsx("option",{value:E,children:m(E)},E))})]}),f==="custom"&&c.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[c.jsx("span",{className:"font-bold",children:e("system.memory.url")}),c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",type:"text",value:h,onChange:E=>d(E.target.value),placeholder:e("system.memory.url.placeholder"),spellCheck:!1,"aria-label":e("system.memory.url")})]}),c.jsx("div",{className:"flex justify-end",children:c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px",fontSize:12},onClick:()=>y.mutate(),disabled:!g||y.isPending,type:"button","aria-label":e("system.memory.save.aria"),children:[y.isPending?c.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):c.jsx(Oi,{size:12,strokeWidth:3}),y.isSuccess&&!g?e("system.memory.saved"):e("system.memory.save")]})})]})]})}function gq(){var S,E,C;const e=Gt(),{alert:t,confirm:n}=un(),r=Ye({queryKey:["providers"],queryFn:lx}),o=(S=Ye({queryKey:["system-agents"],queryFn:Hb}).data)==null?void 0:S.agents,[l,d]=j.useState(null),f=Ct({mutationFn:()=>Jz(l.kind,l.entry),onSuccess:()=>{d(null),e.invalidateQueries({queryKey:["providers"]})},onError:N=>void t({title:"保存失败",body:N instanceof Error?N.message:String(N)})}),h=Ct({mutationFn:N=>e4(N.kind,N.id),onSuccess:()=>void e.invalidateQueries({queryKey:["providers"]}),onError:N=>void t({title:"删除失败",body:N instanceof Error?N.message:String(N)})}),g=Ct({mutationFn:N=>L3(N),onSuccess:()=>void e.invalidateQueries({queryKey:["system-agents"]}),onError:N=>void t({title:"设默认失败",body:N instanceof Error?N.message:String(N)})}),m=(N,_,M)=>{if(!o)return!1;const A=N==="anthropic"?o.worker:o.reviewer;return(A.providerId||"official")===_&&A.model===M},y=(N,_,M)=>{if(!o)return;let A;if(N==="anthropic"){const O={...o.worker,model:M};_==="official"?delete O.providerId:O.providerId=_,A={...o,worker:O}}else A={...o,reviewer:{...o.reviewer,providerId:_,model:M}};g.mutate(A)},b=[{kind:"anthropic",title:"Anthropic 兼容(worker / claude)",items:((E=r.data)==null?void 0:E.anthropic)??[]},{kind:"openai",title:"OpenAI 兼容(reviewer / openai agent)",items:((C=r.data)==null?void 0:C.openai)??[]}],w=N=>d({kind:N,isNew:!0,entry:{id:"",name:"",baseUrl:"",apiKey:"",models:[]}}),v=(N,_)=>d({kind:N,isNew:!1,entry:{id:_.id,name:_.name,baseUrl:_.baseUrl,apiKey:"",models:_.models}});return c.jsxs("section",{className:"nb-card",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:"模型 API 端点"}),c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-4",children:"本地官方订阅(已登录验证)自动置顶,不可编辑;下方可增删第三方兼容端点。**点模型标签设为默认**(anthropic→worker / openai→监工);✓ = 当前默认。"}),c.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:b.map(N=>c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"font-bold text-sm",children:N.title}),c.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:()=>w(N.kind),"aria-label":`添加 ${N.title} 端点`,children:[c.jsx(pr,{size:12,strokeWidth:3})," 添加"]})]}),N.items.length===0&&c.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无端点)"}),N.items.map(_=>_.id==="codex-proxy"?c.jsx(bq,{isDefault:M=>m(N.kind,_.id,M),pickDefault:M=>y(N.kind,_.id,M),setDefaultPending:g.isPending},_.id):c.jsxs("div",{className:["rounded-lg px-3 py-2 border-2",_.builtin?"border-[var(--color-text)] bg-[var(--color-bg-cream)]":"border-[var(--color-text)]"].join(" "),children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:_.id}),c.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",_.name]}),_.builtin?c.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:["本地订阅",_.detail?` · ${_.detail}`:""," · 已验证可用"]}):c.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[_.baseUrl," · key ",_.hasKey?_.apiKey:"未设置"]})]}),_.builtin?c.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:"内置"}):c.jsxs("div",{className:"flex gap-1 shrink-0",children:[c.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>v(N.kind,_),"aria-label":`编辑 ${_.id}`,children:c.jsx(BL,{size:12,strokeWidth:3})}),c.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await n({title:"删除端点",body:`删除 ${_.id}?`,danger:!0})&&h.mutate({kind:N.kind,id:_.id})},"aria-label":`删除 ${_.id}`,children:c.jsx(fi,{size:12,strokeWidth:3})})]})]}),_.models.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:_.models.map(M=>{const A=m(N.kind,_.id,M);return c.jsxs("button",{type:"button",onClick:()=>y(N.kind,_.id,M),disabled:g.isPending,"aria-pressed":A,className:["px-2 py-0.5 rounded-md text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)]",A?"bg-[var(--color-accent-mint)] font-bold":"bg-[var(--color-bg)] hover:bg-[var(--color-bg-cream)]"].join(" "),title:A?"当前默认":"设为默认",children:[M,A?" ✓":""]},M)})})]},_.id))]},N.kind))}),l&&c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:()=>d(null),children:c.jsx("div",{onClick:N=>N.stopPropagation(),children:c.jsx(yq,{state:l,onChange:N=>d({...l,entry:N}),onCancel:()=>d(null),onSave:()=>f.mutate(),saving:f.isPending})})})]})}function yq({state:e,onChange:t,onCancel:n,onSave:r,saving:a}){const o=e.entry,l=f=>t({...o,...f}),d=/^[a-zA-Z0-9_-]+$/.test(o.id)&&o.name.trim()&&o.baseUrl.trim();return c.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:[c.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增端点":`编辑 ${o.id}`,c.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:["(",e.kind,")"]})]}),c.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:o.id,disabled:!e.isNew,onChange:f=>l({id:f.target.value}),placeholder:"如 my-openai",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",c.jsx("input",{className:"nb-input",value:o.name,onChange:f=>l({name:f.target.value}),placeholder:"显示名"})]})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:o.baseUrl,onChange:f=>l({baseUrl:f.target.value}),placeholder:"https://api.example.com/v1",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",!e.isNew&&"(留空=保留)",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:o.apiKey??"",onChange:f=>l({apiKey:f.target.value}),placeholder:e.isNew?"sk-...":"••••(留空不改)",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Models(逗号或换行分隔)",c.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",rows:5,value:o.models.join(", "),onChange:f=>l({models:f.target.value.split(/[,\n]/).map(h=>h.trim()).filter(Boolean)}),placeholder:"gpt-5.4, gpt-4o",spellCheck:!1})]}),c.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[c.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:n,children:"取消"}),c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!d||a,onClick:r,children:[a?c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):c.jsx(Oi,{size:14,strokeWidth:3})," 保存"]})]})]})}function bq({isDefault:e,pickDefault:t,setDefaultPending:n}){const r=Gt(),{alert:a,confirm:o}=un(),[l,d]=j.useState(!1),[f,h]=j.useState(null),[g,m]=j.useState(!1),[y,b]=j.useState(!1),[w,v]=j.useState(!1),E=Ye({queryKey:["codex-proxy"],queryFn:lq,refetchInterval:l?3e3:!1}).data;j.useEffect(()=>{l&&(E!=null&&E.authed)&&(d(!1),h(null),r.invalidateQueries({queryKey:["codex-proxy"]}))},[l,E==null?void 0:E.authed,r]);const C=Ct({mutationFn:cq,onSuccess:U=>{r.invalidateQueries({queryKey:["codex-proxy"]}),r.invalidateQueries({queryKey:["providers"]}),U.ok||a({title:"安装失败",body:(U.output||"未知错误").slice(-600)})},onError:U=>void a({title:"安装失败",body:U instanceof Error?U.message:String(U)})}),N=Ct({mutationFn:U=>uq(U),onSuccess:U=>{m(!1),b(!1),r.invalidateQueries({queryKey:["codex-proxy"]}),r.invalidateQueries({queryKey:["providers"]}),r.invalidateQueries({queryKey:["system-agents"]}),U.ok||a({title:"卸载未完成",body:U.note??"删除失败(可能需 sudo)"})},onError:U=>void a({title:"卸载失败",body:U instanceof Error?U.message:String(U)})}),_=async()=>{await o({title:"安装 claude-code-proxy",body:"将运行官方安装脚本(curl … install.sh | bash),下载预编译二进制到 ~/.local/bin。继续?"})&&C.mutate()},M=async()=>{d(!0),h(null);try{const U=await dq();h(U)}catch(U){d(!1),a({title:"订阅失败",body:U instanceof Error?U.message:String(U)})}},A=()=>{fq(),d(!1),h(null)},O=C.isPending||(E==null?void 0:E.installing),D=w&&(E!=null&&E.models.all.length)?E.models.all:(E==null?void 0:E.models.curated)??[];return c.jsxs("div",{className:"rounded-lg px-3 py-2 border-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:"codex-proxy"}),c.jsx("span",{className:"text-[var(--color-text-muted)] text-sm",children:" · ChatGPT 订阅"}),c.jsx("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:E?E.binInstalled?E.authed?`已订阅${E.account?` · ${E.account.slice(0,8)}…`:""} · worker 出 GPT`:"已安装 · 未订阅":"未安装 claude-code-proxy":"加载中…"})]}),(E==null?void 0:E.binInstalled)&&c.jsx("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 8px"},type:"button",onClick:()=>m(!0),"aria-label":"卸载 codex-proxy",children:c.jsx(fi,{size:12,strokeWidth:3})})]}),c.jsx("div",{className:"mt-2",children:E?E.binInstalled?E.authed?c.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[D.map(U=>{const B=e(U);return c.jsxs("button",{type:"button",onClick:()=>t(U),disabled:n,"aria-pressed":B,className:["px-2 py-0.5 rounded-md text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)]",B?"bg-[var(--color-accent-mint)] font-bold":"bg-[var(--color-bg)] hover:bg-[var(--color-bg-cream)]"].join(" "),title:B?"当前默认":"设为 worker 默认",children:[U,B?" ✓":""]},U)}),E.models.all.length>E.models.curated.length&&c.jsx("button",{type:"button",className:"text-xs text-[var(--color-text-muted)] underline",onClick:()=>v(U=>!U),children:w?"收起":`显示全部(${E.models.all.length})`})]}):c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 12px",fontSize:12},type:"button",onClick:M,children:[c.jsx(SL,{size:12,strokeWidth:3})," 订阅(授权 ChatGPT)"]}):c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 12px",fontSize:12},type:"button",disabled:!!O,onClick:_,children:[O?c.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):c.jsx(Uh,{size:12,strokeWidth:3}),O?" 安装中…":" 安装插件"]}):c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin text-[var(--color-text-muted)]"})}),l&&c.jsxs(LE,{onClose:A,children:[c.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"订阅 ChatGPT(设备码授权)"}),f!=null&&f.verificationUrl&&(f!=null&&f.userCode)?c.jsxs("div",{className:"flex flex-col gap-3 text-sm",children:[c.jsxs("div",{children:["① 打开"," ",c.jsxs("a",{href:f.verificationUrl,target:"_blank",rel:"noreferrer",className:"font-bold underline inline-flex items-center gap-1",children:[f.verificationUrl," ",c.jsx(YR,{size:12,strokeWidth:3})]})]}),c.jsxs("div",{children:["② 输入验证码:",c.jsx("code",{className:"ml-1 px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)] font-bold font-[family-name:var(--font-mono)]",children:f.userCode})]}),c.jsx("div",{children:"③ 在浏览器完成授权"}),c.jsxs("div",{className:"flex items-center gap-2 text-[var(--color-text-muted)]",children:[c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"})," 等待授权…(完成后自动刷新)"]})]}):c.jsxs("div",{className:"flex flex-col gap-2 text-sm text-[var(--color-text-muted)]",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"})," 正在获取设备码…"]}),c.jsxs("div",{children:["若长时间无响应,可在终端运行 ",c.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps codex-proxy auth"}),",完成后此处自动刷新。"]})]}),c.jsx("div",{className:"flex justify-end pt-1",children:c.jsx("button",{className:"nb-btn",style:{padding:"6px 14px"},type:"button",onClick:A,children:"取消"})})]}),g&&c.jsxs(LE,{onClose:()=>m(!1),children:[c.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"卸载 claude-code-proxy"}),c.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"停止 proxy 并删除二进制。默认保留授权(重装免再授权)。"}),c.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[c.jsx("input",{type:"checkbox",checked:y,onChange:U=>b(U.target.checked)}),"同时清除授权(~/.config/claude-code-proxy)"]}),c.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[c.jsx("button",{className:"nb-btn",style:{padding:"6px 14px"},type:"button",onClick:()=>m(!1),children:"取消"}),c.jsxs("button",{className:"nb-btn nb-btn-danger",style:{padding:"6px 14px"},type:"button",disabled:N.isPending,onClick:()=>N.mutate(y),children:[N.isPending?c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):c.jsx(fi,{size:14,strokeWidth:3})," 卸载"]})]})]})]})}function LE({children:e,onClose:t}){return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:t,children:c.jsx("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,520px)]",onClick:n=>n.stopPropagation(),children:e})})}const xq=["telegram","dingtalk","matrix","slack","discord","feishu"],gu={telegram:"Telegram",dingtalk:"钉钉 (Stream)",matrix:"Matrix",slack:"Slack",discord:"Discord",feishu:"飞书 / Lark"},vq={telegram:[{key:"token",label:"Bot Token(@BotFather)",type:"password",placeholder:"123456:ABC-..."},{key:"allowedChatIds",label:"允许的 Chat ID(白名单,空=全放)",type:"list",placeholder:"逗号/换行分隔"}],dingtalk:[{key:"clientId",label:"Client ID(AppKey)",type:"text"},{key:"clientSecret",label:"Client Secret(AppSecret)",type:"password"},{key:"allowedConversations",label:"允许的会话 ID(白名单,空=全放)",type:"list"}],matrix:[{key:"homeserver",label:"Homeserver URL",type:"text",placeholder:"https://matrix.org"},{key:"accessToken",label:"Access Token",type:"password"},{key:"allowedRooms",label:"允许的 Room ID(白名单,空=全放)",type:"list"}],slack:[{key:"appToken",label:"App Token(xapp-,Socket Mode)",type:"password",placeholder:"xapp-..."},{key:"botToken",label:"Bot Token(xoxb-)",type:"password",placeholder:"xoxb-..."},{key:"allowedChannels",label:"允许的 Channel(白名单,空=全放)",type:"list"}],discord:[{key:"token",label:"Bot Token",type:"password"},{key:"allowedChannels",label:"允许的 Channel ID(白名单,空=全放)",type:"list"}],feishu:[{key:"appId",label:"App ID",type:"text"},{key:"appSecret",label:"App Secret",type:"password"},{key:"verificationToken",label:"Verification Token",type:"text"},{key:"encryptKey",label:"Encrypt Key(设了则事件 AES 解密)",type:"password"},{key:"port",label:"本机监听端口(默认 9800)",type:"number",placeholder:"9800"},{key:"path",label:"监听路径(默认 /feishu)",type:"text",placeholder:"/feishu"},{key:"allowedChats",label:"允许的 chat_id(白名单,空=全放)",type:"list"}]};function wq(){var w,v,S;const e=Gt(),{alert:t}=un(),n=Ye({queryKey:["channels"],queryFn:sq}),[r,a]=j.useState(null),[o,l]=j.useState({type:"console"});j.useEffect(()=>{n.data&&!r&&a({console:n.data.console??{},adapters:n.data.adapters??[]})},[n.data,r]);const d=Ct({mutationFn:()=>oq(r),onSuccess:E=>{a({console:E.console??{},adapters:E.adapters??[]}),e.invalidateQueries({queryKey:["channels"]})},onError:E=>void t({title:"保存失败",body:E instanceof Error?E.message:String(E)})});if(!r)return c.jsx("section",{className:"nb-card",children:c.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"})," 加载频道配置…"]})});const f=r.adapters??[],h=JSON.stringify(r)!==JSON.stringify({console:((w=n.data)==null?void 0:w.console)??{},adapters:((v=n.data)==null?void 0:v.adapters)??[]}),g=E=>{const C=[...f,{kind:E,enabled:!0}];a({...r,adapters:C}),l({type:"adapter",index:C.length-1})},m=E=>{const C=f.filter((N,_)=>_!==E);a({...r,adapters:C}),l({type:"console"})},y=(E,C)=>{const N=f.map((_,M)=>M===E?{..._,...C}:_);a({...r,adapters:N})},b=E=>a({...r,console:{...r.console,...E}});return c.jsxs("section",{className:"nb-card",children:[c.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"频道(IM 网关)"}),c.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["接入 Telegram / 钉钉 / 飞书 / Slack / Discord / Matrix。左侧选频道,右侧改设置。保存后 ",c.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps im"})," 重启生效。"]})]}),c.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",disabled:!h||d.isPending,onClick:()=>d.mutate(),"aria-label":"保存频道配置",children:[d.isPending?c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):c.jsx(Oi,{size:14,strokeWidth:3})," 保存"]})]}),c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[220px_1fr] gap-5 mt-4",children:[c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsx(IE,{label:"console 桥接",sub:((S=r.console)==null?void 0:S.url)||"未配置",active:o.type==="console",onClick:()=>l({type:"console"})}),c.jsx("div",{className:"h-px bg-[var(--color-text)] opacity-20 my-1"}),f.length===0&&c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-1",children:"(无频道)"}),f.map((E,C)=>c.jsx(IE,{label:gu[E.kind]??E.kind,sub:E.enabled===!1?"已停用":"启用",active:o.type==="adapter"&&o.index===C,onClick:()=>l({type:"adapter",index:C})},C)),c.jsxs("div",{className:"mt-2",children:[c.jsx("span",{className:"text-xs font-bold text-[var(--color-text-muted)]",children:"添加频道"}),c.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:xq.map(E=>c.jsxs("button",{className:"nb-btn",style:{padding:"4px 8px",fontSize:12},type:"button",onClick:()=>g(E),"aria-label":`添加 ${gu[E]} 频道`,children:[c.jsx(pr,{size:11,strokeWidth:3})," ",gu[E]]},E))})]})]}),c.jsx("div",{className:"border-2 border-[var(--color-text)] rounded-xl p-4 bg-[var(--color-bg-cream)]",children:(()=>{if(o.type!=="adapter")return c.jsx(zE,{console:r.console??{},onChange:b});const E=f[o.index];if(!E)return c.jsx(zE,{console:r.console??{},onChange:b});const C=o.index;return c.jsx(kq,{adapter:E,onChange:N=>y(C,N),onRemove:()=>m(C)})})()})]})]})}function IE({label:e,sub:t,active:n,onClick:r}){return c.jsxs("button",{type:"button",onClick:r,"aria-pressed":n,className:["text-left rounded-lg px-3 py-2 border-2 border-[var(--color-text)] transition-transform duration-150",n?"bg-[var(--color-accent-mint)] shadow-[3px_3px_0_var(--color-text)]":"bg-white hover:-translate-x-px hover:-translate-y-px hover:shadow-[3px_3px_0_var(--color-text)]"].join(" "),children:[c.jsx("div",{className:"font-bold text-sm",children:e}),c.jsx("div",{className:"text-xs text-[var(--color-text-muted)] truncate font-[family-name:var(--font-mono)]",children:t})]})}function zE({console:e,onChange:t}){return c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"console 桥接"}),c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:"IM 纯文本消息桥接到项目 agent 对话。设了 URL 才启用桥接;token 为 console 鉴权令牌。"})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console URL",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:e.url??"",onChange:n=>t({url:n.target.value}),placeholder:"http://localhost:4321",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console Token(SPS_CONSOLE_TOKEN)",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:e.token??"",onChange:n=>t({token:n.target.value}),placeholder:"鉴权令牌(可空)",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["对话后端",c.jsxs("select",{className:"nb-input",value:e.agentKind??"claude",onChange:n=>t({agentKind:n.target.value}),children:[c.jsx("option",{value:"claude",children:"claude"}),c.jsx("option",{value:"openai",children:"openai"})]})]})]})}function kq({adapter:e,onChange:t,onRemove:n}){const{confirm:r}=un(),a=vq[e.kind]??[],o=e.enabled!==!1;return c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{className:"flex items-start justify-between gap-2",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:gu[e.kind]??e.kind}),c.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-[family-name:var(--font-mono)]",children:[" · ",e.kind]})]}),c.jsxs("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:async()=>{await r({title:"删除频道",body:`删除 ${gu[e.kind]??e.kind} 频道?`,danger:!0})&&n()},"aria-label":"删除频道",children:[c.jsx(fi,{size:12,strokeWidth:3})," 删除"]})]}),c.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[c.jsx("input",{type:"checkbox",checked:o,onChange:l=>t({enabled:l.target.checked})}),"启用此频道"]}),a.map(l=>c.jsx(Eq,{spec:l,value:e[l.key],onChange:d=>t({[l.key]:d})},l.key))]})}function Eq({spec:e,value:t,onChange:n}){if(e.type==="list"){const r=Array.isArray(t)?t.map(String):[];return c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,c.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",rows:2,value:r.join(", "),onChange:a=>{const o=a.target.value.split(/[,\n]/).map(l=>l.trim()).filter(Boolean);n(o.length?o:void 0)},placeholder:e.placeholder,spellCheck:!1})]})}return c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:e.type==="password"?"password":"text",value:t==null?"":String(t),onChange:r=>{const a=r.target.value;e.type==="number"?n(a.trim()===""?void 0:Number(a)):n(a===""?void 0:a)},placeholder:e.placeholder,spellCheck:!1})]})}function Nn(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Nn(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var Sq={value:()=>{}};function cp(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new rh(n)}function rh(e){this._=e}function Nq(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",a=n.indexOf(".");if(a>=0&&(r=n.slice(a+1),n=n.slice(0,a)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}rh.prototype=cp.prototype={constructor:rh,on:function(e,t){var n=this._,r=Nq(e+"",n),a,o=-1,l=r.length;if(arguments.length<2){for(;++o<l;)if((a=(e=r[o]).type)&&(a=_q(n[a],e.name)))return a;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<l;)if(a=(e=r[o]).type)n[a]=PE(n[a],e.name,t);else if(t==null)for(a in n)n[a]=PE(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 rh(e)},call:function(e,t){if((a=arguments.length-2)>0)for(var n=new Array(a),r=0,a,o;r<a;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],r=0,a=o.length;r<a;++r)o[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],a=0,o=r.length;a<o;++a)r[a].value.apply(t,n)}};function _q(e,t){for(var n=0,r=e.length,a;n<r;++n)if((a=e[n]).name===t)return a.value}function PE(e,t,n){for(var r=0,a=e.length;r<a;++r)if(e[r].name===t){e[r]=Sq,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var lb="http://www.w3.org/1999/xhtml";const BE={svg:"http://www.w3.org/2000/svg",xhtml:lb,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function up(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),BE.hasOwnProperty(t)?{space:BE[t],local:e}:e}function jq(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===lb&&t.documentElement.namespaceURI===lb?t.createElement(e):t.createElementNS(n,e)}}function Cq(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Yj(e){var t=up(e);return(t.local?Cq:jq)(t)}function Aq(){}function zx(e){return e==null?Aq:function(){return this.querySelector(e)}}function Tq(e){typeof e!="function"&&(e=zx(e));for(var t=this._groups,n=t.length,r=new Array(n),a=0;a<n;++a)for(var o=t[a],l=o.length,d=r[a]=new Array(l),f,h,g=0;g<l;++g)(f=o[g])&&(h=e.call(f,f.__data__,g,o))&&("__data__"in f&&(h.__data__=f.__data__),d[g]=h);return new Cr(r,this._parents)}function Mq(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Dq(){return[]}function Qj(e){return e==null?Dq:function(){return this.querySelectorAll(e)}}function Oq(e){return function(){return Mq(e.apply(this,arguments))}}function Rq(e){typeof e=="function"?e=Oq(e):e=Qj(e);for(var t=this._groups,n=t.length,r=[],a=[],o=0;o<n;++o)for(var l=t[o],d=l.length,f,h=0;h<d;++h)(f=l[h])&&(r.push(e.call(f,f.__data__,h,l)),a.push(f));return new Cr(r,a)}function Wj(e){return function(){return this.matches(e)}}function Xj(e){return function(t){return t.matches(e)}}var Lq=Array.prototype.find;function Iq(e){return function(){return Lq.call(this.children,e)}}function zq(){return this.firstElementChild}function Pq(e){return this.select(e==null?zq:Iq(typeof e=="function"?e:Xj(e)))}var Bq=Array.prototype.filter;function $q(){return Array.from(this.children)}function Uq(e){return function(){return Bq.call(this.children,e)}}function Fq(e){return this.selectAll(e==null?$q:Uq(typeof e=="function"?e:Xj(e)))}function qq(e){typeof e!="function"&&(e=Wj(e));for(var t=this._groups,n=t.length,r=new Array(n),a=0;a<n;++a)for(var o=t[a],l=o.length,d=r[a]=[],f,h=0;h<l;++h)(f=o[h])&&e.call(f,f.__data__,h,o)&&d.push(f);return new Cr(r,this._parents)}function Zj(e){return new Array(e.length)}function Hq(){return new Cr(this._enter||this._groups.map(Zj),this._parents)}function _h(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}_h.prototype={constructor:_h,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 Kq(e){return function(){return e}}function Gq(e,t,n,r,a,o){for(var l=0,d,f=t.length,h=o.length;l<h;++l)(d=t[l])?(d.__data__=o[l],r[l]=d):n[l]=new _h(e,o[l]);for(;l<f;++l)(d=t[l])&&(a[l]=d)}function Vq(e,t,n,r,a,o,l){var d,f,h=new Map,g=t.length,m=o.length,y=new Array(g),b;for(d=0;d<g;++d)(f=t[d])&&(y[d]=b=l.call(f,f.__data__,d,t)+"",h.has(b)?a[d]=f:h.set(b,f));for(d=0;d<m;++d)b=l.call(e,o[d],d,o)+"",(f=h.get(b))?(r[d]=f,f.__data__=o[d],h.delete(b)):n[d]=new _h(e,o[d]);for(d=0;d<g;++d)(f=t[d])&&h.get(y[d])===f&&(a[d]=f)}function Yq(e){return e.__data__}function Qq(e,t){if(!arguments.length)return Array.from(this,Yq);var n=t?Vq:Gq,r=this._parents,a=this._groups;typeof e!="function"&&(e=Kq(e));for(var o=a.length,l=new Array(o),d=new Array(o),f=new Array(o),h=0;h<o;++h){var g=r[h],m=a[h],y=m.length,b=Wq(e.call(g,g&&g.__data__,h,r)),w=b.length,v=d[h]=new Array(w),S=l[h]=new Array(w),E=f[h]=new Array(y);n(g,m,v,S,E,b,t);for(var C=0,N=0,_,M;C<w;++C)if(_=v[C]){for(C>=N&&(N=C+1);!(M=S[N])&&++N<w;);_._next=M||null}}return l=new Cr(l,r),l._enter=d,l._exit=f,l}function Wq(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Xq(){return new Cr(this._exit||this._groups.map(Zj),this._parents)}function Zq(e,t,n){var r=this.enter(),a=this,o=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(a=t(a),a&&(a=a.selection())),n==null?o.remove():n(o),r&&a?r.merge(a).order():a}function Jq(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,a=n.length,o=r.length,l=Math.min(a,o),d=new Array(a),f=0;f<l;++f)for(var h=n[f],g=r[f],m=h.length,y=d[f]=new Array(m),b,w=0;w<m;++w)(b=h[w]||g[w])&&(y[w]=b);for(;f<a;++f)d[f]=n[f];return new Cr(d,this._parents)}function eH(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],a=r.length-1,o=r[a],l;--a>=0;)(l=r[a])&&(o&&l.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(l,o),o=l);return this}function tH(e){e||(e=nH);function t(m,y){return m&&y?e(m.__data__,y.__data__):!m-!y}for(var n=this._groups,r=n.length,a=new Array(r),o=0;o<r;++o){for(var l=n[o],d=l.length,f=a[o]=new Array(d),h,g=0;g<d;++g)(h=l[g])&&(f[g]=h);f.sort(t)}return new Cr(a,this._parents).order()}function nH(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function rH(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function iH(){return Array.from(this)}function aH(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],a=0,o=r.length;a<o;++a){var l=r[a];if(l)return l}return null}function sH(){let e=0;for(const t of this)++e;return e}function oH(){return!this.node()}function lH(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var a=t[n],o=0,l=a.length,d;o<l;++o)(d=a[o])&&e.call(d,d.__data__,o,a);return this}function cH(e){return function(){this.removeAttribute(e)}}function uH(e){return function(){this.removeAttributeNS(e.space,e.local)}}function dH(e,t){return function(){this.setAttribute(e,t)}}function fH(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function hH(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function pH(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 mH(e,t){var n=up(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?uH:cH:typeof t=="function"?n.local?pH:hH:n.local?fH:dH)(n,t))}function Jj(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function gH(e){return function(){this.style.removeProperty(e)}}function yH(e,t,n){return function(){this.style.setProperty(e,t,n)}}function bH(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function xH(e,t,n){return arguments.length>1?this.each((t==null?gH:typeof t=="function"?bH:yH)(e,t,n??"")):Fl(this.node(),e)}function Fl(e,t){return e.style.getPropertyValue(t)||Jj(e).getComputedStyle(e,null).getPropertyValue(t)}function vH(e){return function(){delete this[e]}}function wH(e,t){return function(){this[e]=t}}function kH(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function EH(e,t){return arguments.length>1?this.each((t==null?vH:typeof t=="function"?kH:wH)(e,t)):this.node()[e]}function eC(e){return e.trim().split(/^|\s+/)}function Px(e){return e.classList||new tC(e)}function tC(e){this._node=e,this._names=eC(e.getAttribute("class")||"")}tC.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 nC(e,t){for(var n=Px(e),r=-1,a=t.length;++r<a;)n.add(t[r])}function rC(e,t){for(var n=Px(e),r=-1,a=t.length;++r<a;)n.remove(t[r])}function SH(e){return function(){nC(this,e)}}function NH(e){return function(){rC(this,e)}}function _H(e,t){return function(){(t.apply(this,arguments)?nC:rC)(this,e)}}function jH(e,t){var n=eC(e+"");if(arguments.length<2){for(var r=Px(this.node()),a=-1,o=n.length;++a<o;)if(!r.contains(n[a]))return!1;return!0}return this.each((typeof t=="function"?_H:t?SH:NH)(n,t))}function CH(){this.textContent=""}function AH(e){return function(){this.textContent=e}}function TH(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function MH(e){return arguments.length?this.each(e==null?CH:(typeof e=="function"?TH:AH)(e)):this.node().textContent}function DH(){this.innerHTML=""}function OH(e){return function(){this.innerHTML=e}}function RH(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function LH(e){return arguments.length?this.each(e==null?DH:(typeof e=="function"?RH:OH)(e)):this.node().innerHTML}function IH(){this.nextSibling&&this.parentNode.appendChild(this)}function zH(){return this.each(IH)}function PH(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function BH(){return this.each(PH)}function $H(e){var t=typeof e=="function"?e:Yj(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function UH(){return null}function FH(e,t){var n=typeof e=="function"?e:Yj(e),r=t==null?UH:typeof t=="function"?t:zx(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function qH(){var e=this.parentNode;e&&e.removeChild(this)}function HH(){return this.each(qH)}function KH(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function GH(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function VH(e){return this.select(e?GH:KH)}function YH(e){return arguments.length?this.property("__data__",e):this.node().__data__}function QH(e){return function(t){e.call(this,t,this.__data__)}}function WH(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function XH(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,a=t.length,o;n<a;++n)o=t[n],(!e.type||o.type===e.type)&&o.name===e.name?this.removeEventListener(o.type,o.listener,o.options):t[++r]=o;++r?t.length=r:delete this.__on}}}function ZH(e,t,n){return function(){var r=this.__on,a,o=QH(t);if(r){for(var l=0,d=r.length;l<d;++l)if((a=r[l]).type===e.type&&a.name===e.name){this.removeEventListener(a.type,a.listener,a.options),this.addEventListener(a.type,a.listener=o,a.options=n),a.value=t;return}}this.addEventListener(e.type,o,n),a={type:e.type,name:e.name,value:t,listener:o,options:n},r?r.push(a):this.__on=[a]}}function JH(e,t,n){var r=WH(e+""),a,o=r.length,l;if(arguments.length<2){var d=this.node().__on;if(d){for(var f=0,h=d.length,g;f<h;++f)for(a=0,g=d[f];a<o;++a)if((l=r[a]).type===g.type&&l.name===g.name)return g.value}return}for(d=t?ZH:XH,a=0;a<o;++a)this.each(d(r[a],t,n));return this}function iC(e,t,n){var r=Jj(e),a=r.CustomEvent;typeof a=="function"?a=new a(t,n):(a=r.document.createEvent("Event"),n?(a.initEvent(t,n.bubbles,n.cancelable),a.detail=n.detail):a.initEvent(t,!1,!1)),e.dispatchEvent(a)}function e7(e,t){return function(){return iC(this,e,t)}}function t7(e,t){return function(){return iC(this,e,t.apply(this,arguments))}}function n7(e,t){return this.each((typeof t=="function"?t7:e7)(e,t))}function*r7(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],a=0,o=r.length,l;a<o;++a)(l=r[a])&&(yield l)}var aC=[null];function Cr(e,t){this._groups=e,this._parents=t}function nd(){return new Cr([[document.documentElement]],aC)}function i7(){return this}Cr.prototype=nd.prototype={constructor:Cr,select:Tq,selectAll:Rq,selectChild:Pq,selectChildren:Fq,filter:qq,data:Qq,enter:Hq,exit:Xq,join:Zq,merge:Jq,selection:i7,order:eH,sort:tH,call:rH,nodes:iH,node:aH,size:sH,empty:oH,each:lH,attr:mH,style:xH,property:EH,classed:jH,text:MH,html:LH,raise:zH,lower:BH,append:$H,insert:FH,remove:HH,clone:VH,datum:YH,on:JH,dispatch:n7,[Symbol.iterator]:r7};function _r(e){return typeof e=="string"?new Cr([[document.querySelector(e)]],[document.documentElement]):new Cr([[e]],aC)}function a7(e){let t;for(;t=e.sourceEvent;)e=t;return e}function si(e,t){if(e=a7(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var a=t.getBoundingClientRect();return[e.clientX-a.left-t.clientLeft,e.clientY-a.top-t.clientTop]}}return[e.pageX,e.pageY]}const s7={passive:!1},Au={capture:!0,passive:!1};function uy(e){e.stopImmediatePropagation()}function Sl(e){e.preventDefault(),e.stopImmediatePropagation()}function sC(e){var t=e.document.documentElement,n=_r(e).on("dragstart.drag",Sl,Au);"onselectstart"in t?n.on("selectstart.drag",Sl,Au):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function oC(e,t){var n=e.document.documentElement,r=_r(e).on("dragstart.drag",null);t&&(r.on("click.drag",Sl,Au),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const $f=e=>()=>e;function cb(e,{sourceEvent:t,subject:n,target:r,identifier:a,active:o,x:l,y:d,dx:f,dy:h,dispatch:g}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:a,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:l,enumerable:!0,configurable:!0},y:{value:d,enumerable:!0,configurable:!0},dx:{value:f,enumerable:!0,configurable:!0},dy:{value:h,enumerable:!0,configurable:!0},_:{value:g}})}cb.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function o7(e){return!e.ctrlKey&&!e.button}function l7(){return this.parentNode}function c7(e,t){return t??{x:e.x,y:e.y}}function u7(){return navigator.maxTouchPoints||"ontouchstart"in this}function lC(){var e=o7,t=l7,n=c7,r=u7,a={},o=cp("start","drag","end"),l=0,d,f,h,g,m=0;function y(_){_.on("mousedown.drag",b).filter(r).on("touchstart.drag",S).on("touchmove.drag",E,s7).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function b(_,M){if(!(g||!e.call(this,_,M))){var A=N(this,t.call(this,_,M),_,M,"mouse");A&&(_r(_.view).on("mousemove.drag",w,Au).on("mouseup.drag",v,Au),sC(_.view),uy(_),h=!1,d=_.clientX,f=_.clientY,A("start",_))}}function w(_){if(Sl(_),!h){var M=_.clientX-d,A=_.clientY-f;h=M*M+A*A>m}a.mouse("drag",_)}function v(_){_r(_.view).on("mousemove.drag mouseup.drag",null),oC(_.view,h),Sl(_),a.mouse("end",_)}function S(_,M){if(e.call(this,_,M)){var A=_.changedTouches,O=t.call(this,_,M),D=A.length,U,B;for(U=0;U<D;++U)(B=N(this,O,_,M,A[U].identifier,A[U]))&&(uy(_),B("start",_,A[U]))}}function E(_){var M=_.changedTouches,A=M.length,O,D;for(O=0;O<A;++O)(D=a[M[O].identifier])&&(Sl(_),D("drag",_,M[O]))}function C(_){var M=_.changedTouches,A=M.length,O,D;for(g&&clearTimeout(g),g=setTimeout(function(){g=null},500),O=0;O<A;++O)(D=a[M[O].identifier])&&(uy(_),D("end",_,M[O]))}function N(_,M,A,O,D,U){var B=o.copy(),q=si(U||A,M),G,Q,R;if((R=n.call(_,new cb("beforestart",{sourceEvent:A,target:y,identifier:D,active:l,x:q[0],y:q[1],dx:0,dy:0,dispatch:B}),O))!=null)return G=R.x-q[0]||0,Q=R.y-q[1]||0,function H(L,V,Y){var K=q,z;switch(L){case"start":a[D]=H,z=l++;break;case"end":delete a[D],--l;case"drag":q=si(Y||V,M),z=l;break}B.call(L,_,new cb(L,{sourceEvent:V,subject:R,target:y,identifier:D,active:z,x:q[0]+G,y:q[1]+Q,dx:q[0]-K[0],dy:q[1]-K[1],dispatch:B}),O)}}return y.filter=function(_){return arguments.length?(e=typeof _=="function"?_:$f(!!_),y):e},y.container=function(_){return arguments.length?(t=typeof _=="function"?_:$f(_),y):t},y.subject=function(_){return arguments.length?(n=typeof _=="function"?_:$f(_),y):n},y.touchable=function(_){return arguments.length?(r=typeof _=="function"?_:$f(!!_),y):r},y.on=function(){var _=o.on.apply(o,arguments);return _===o?y:_},y.clickDistance=function(_){return arguments.length?(m=(_=+_)*_,y):Math.sqrt(m)},y}function Bx(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function cC(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function rd(){}var Tu=.7,jh=1/Tu,Nl="\\s*([+-]?\\d+)\\s*",Mu="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Mi="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",d7=/^#([0-9a-f]{3,8})$/,f7=new RegExp(`^rgb\\(${Nl},${Nl},${Nl}\\)$`),h7=new RegExp(`^rgb\\(${Mi},${Mi},${Mi}\\)$`),p7=new RegExp(`^rgba\\(${Nl},${Nl},${Nl},${Mu}\\)$`),m7=new RegExp(`^rgba\\(${Mi},${Mi},${Mi},${Mu}\\)$`),g7=new RegExp(`^hsl\\(${Mu},${Mi},${Mi}\\)$`),y7=new RegExp(`^hsla\\(${Mu},${Mi},${Mi},${Mu}\\)$`),$E={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};Bx(rd,go,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:UE,formatHex:UE,formatHex8:b7,formatHsl:x7,formatRgb:FE,toString:FE});function UE(){return this.rgb().formatHex()}function b7(){return this.rgb().formatHex8()}function x7(){return uC(this).formatHsl()}function FE(){return this.rgb().formatRgb()}function go(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=d7.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?qE(t):n===3?new hr(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Uf(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Uf(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=f7.exec(e))?new hr(t[1],t[2],t[3],1):(t=h7.exec(e))?new hr(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=p7.exec(e))?Uf(t[1],t[2],t[3],t[4]):(t=m7.exec(e))?Uf(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=g7.exec(e))?GE(t[1],t[2]/100,t[3]/100,1):(t=y7.exec(e))?GE(t[1],t[2]/100,t[3]/100,t[4]):$E.hasOwnProperty(e)?qE($E[e]):e==="transparent"?new hr(NaN,NaN,NaN,0):null}function qE(e){return new hr(e>>16&255,e>>8&255,e&255,1)}function Uf(e,t,n,r){return r<=0&&(e=t=n=NaN),new hr(e,t,n,r)}function v7(e){return e instanceof rd||(e=go(e)),e?(e=e.rgb(),new hr(e.r,e.g,e.b,e.opacity)):new hr}function ub(e,t,n,r){return arguments.length===1?v7(e):new hr(e,t,n,r??1)}function hr(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Bx(hr,ub,cC(rd,{brighter(e){return e=e==null?jh:Math.pow(jh,e),new hr(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Tu:Math.pow(Tu,e),new hr(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new hr(co(this.r),co(this.g),co(this.b),Ch(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:HE,formatHex:HE,formatHex8:w7,formatRgb:KE,toString:KE}));function HE(){return`#${Js(this.r)}${Js(this.g)}${Js(this.b)}`}function w7(){return`#${Js(this.r)}${Js(this.g)}${Js(this.b)}${Js((isNaN(this.opacity)?1:this.opacity)*255)}`}function KE(){const e=Ch(this.opacity);return`${e===1?"rgb(":"rgba("}${co(this.r)}, ${co(this.g)}, ${co(this.b)}${e===1?")":`, ${e})`}`}function Ch(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function co(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Js(e){return e=co(e),(e<16?"0":"")+e.toString(16)}function GE(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new oi(e,t,n,r)}function uC(e){if(e instanceof oi)return new oi(e.h,e.s,e.l,e.opacity);if(e instanceof rd||(e=go(e)),!e)return new oi;if(e instanceof oi)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,a=Math.min(t,n,r),o=Math.max(t,n,r),l=NaN,d=o-a,f=(o+a)/2;return d?(t===o?l=(n-r)/d+(n<r)*6:n===o?l=(r-t)/d+2:l=(t-n)/d+4,d/=f<.5?o+a:2-o-a,l*=60):d=f>0&&f<1?0:l,new oi(l,d,f,e.opacity)}function k7(e,t,n,r){return arguments.length===1?uC(e):new oi(e,t,n,r??1)}function oi(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Bx(oi,k7,cC(rd,{brighter(e){return e=e==null?jh:Math.pow(jh,e),new oi(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Tu:Math.pow(Tu,e),new oi(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,a=2*n-r;return new hr(dy(e>=240?e-240:e+120,a,r),dy(e,a,r),dy(e<120?e+240:e-120,a,r),this.opacity)},clamp(){return new oi(VE(this.h),Ff(this.s),Ff(this.l),Ch(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=Ch(this.opacity);return`${e===1?"hsl(":"hsla("}${VE(this.h)}, ${Ff(this.s)*100}%, ${Ff(this.l)*100}%${e===1?")":`, ${e})`}`}}));function VE(e){return e=(e||0)%360,e<0?e+360:e}function Ff(e){return Math.max(0,Math.min(1,e||0))}function dy(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 $x=e=>()=>e;function E7(e,t){return function(n){return e+n*t}}function S7(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function N7(e){return(e=+e)==1?dC:function(t,n){return n-t?S7(t,n,e):$x(isNaN(t)?n:t)}}function dC(e,t){var n=t-e;return n?E7(e,n):$x(isNaN(e)?t:e)}const Ah=(function e(t){var n=N7(t);function r(a,o){var l=n((a=ub(a)).r,(o=ub(o)).r),d=n(a.g,o.g),f=n(a.b,o.b),h=dC(a.opacity,o.opacity);return function(g){return a.r=l(g),a.g=d(g),a.b=f(g),a.opacity=h(g),a+""}}return r.gamma=e,r})(1);function _7(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),a;return function(o){for(a=0;a<n;++a)r[a]=e[a]*(1-o)+t[a]*o;return r}}function j7(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function C7(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,a=new Array(r),o=new Array(n),l;for(l=0;l<r;++l)a[l]=yu(e[l],t[l]);for(;l<n;++l)o[l]=t[l];return function(d){for(l=0;l<r;++l)o[l]=a[l](d);return o}}function A7(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function Ci(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function T7(e,t){var n={},r={},a;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(a in t)a in e?n[a]=yu(e[a],t[a]):r[a]=t[a];return function(o){for(a in n)r[a]=n[a](o);return r}}var db=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,fy=new RegExp(db.source,"g");function M7(e){return function(){return e}}function D7(e){return function(t){return e(t)+""}}function fC(e,t){var n=db.lastIndex=fy.lastIndex=0,r,a,o,l=-1,d=[],f=[];for(e=e+"",t=t+"";(r=db.exec(e))&&(a=fy.exec(t));)(o=a.index)>n&&(o=t.slice(n,o),d[l]?d[l]+=o:d[++l]=o),(r=r[0])===(a=a[0])?d[l]?d[l]+=a:d[++l]=a:(d[++l]=null,f.push({i:l,x:Ci(r,a)})),n=fy.lastIndex;return n<t.length&&(o=t.slice(n),d[l]?d[l]+=o:d[++l]=o),d.length<2?f[0]?D7(f[0].x):M7(t):(t=f.length,function(h){for(var g=0,m;g<t;++g)d[(m=f[g]).i]=m.x(h);return d.join("")})}function yu(e,t){var n=typeof t,r;return t==null||n==="boolean"?$x(t):(n==="number"?Ci:n==="string"?(r=go(t))?(t=r,Ah):fC:t instanceof go?Ah:t instanceof Date?A7:j7(t)?_7:Array.isArray(t)?C7:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?T7:Ci)(e,t)}var YE=180/Math.PI,fb={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function hC(e,t,n,r,a,o){var l,d,f;return(l=Math.sqrt(e*e+t*t))&&(e/=l,t/=l),(f=e*n+t*r)&&(n-=e*f,r-=t*f),(d=Math.sqrt(n*n+r*r))&&(n/=d,r/=d,f/=d),e*r<t*n&&(e=-e,t=-t,f=-f,l=-l),{translateX:a,translateY:o,rotate:Math.atan2(t,e)*YE,skewX:Math.atan(f)*YE,scaleX:l,scaleY:d}}var qf;function O7(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?fb:hC(t.a,t.b,t.c,t.d,t.e,t.f)}function R7(e){return e==null||(qf||(qf=document.createElementNS("http://www.w3.org/2000/svg","g")),qf.setAttribute("transform",e),!(e=qf.transform.baseVal.consolidate()))?fb:(e=e.matrix,hC(e.a,e.b,e.c,e.d,e.e,e.f))}function pC(e,t,n,r){function a(h){return h.length?h.pop()+" ":""}function o(h,g,m,y,b,w){if(h!==m||g!==y){var v=b.push("translate(",null,t,null,n);w.push({i:v-4,x:Ci(h,m)},{i:v-2,x:Ci(g,y)})}else(m||y)&&b.push("translate("+m+t+y+n)}function l(h,g,m,y){h!==g?(h-g>180?g+=360:g-h>180&&(h+=360),y.push({i:m.push(a(m)+"rotate(",null,r)-2,x:Ci(h,g)})):g&&m.push(a(m)+"rotate("+g+r)}function d(h,g,m,y){h!==g?y.push({i:m.push(a(m)+"skewX(",null,r)-2,x:Ci(h,g)}):g&&m.push(a(m)+"skewX("+g+r)}function f(h,g,m,y,b,w){if(h!==m||g!==y){var v=b.push(a(b)+"scale(",null,",",null,")");w.push({i:v-4,x:Ci(h,m)},{i:v-2,x:Ci(g,y)})}else(m!==1||y!==1)&&b.push(a(b)+"scale("+m+","+y+")")}return function(h,g){var m=[],y=[];return h=e(h),g=e(g),o(h.translateX,h.translateY,g.translateX,g.translateY,m,y),l(h.rotate,g.rotate,m,y),d(h.skewX,g.skewX,m,y),f(h.scaleX,h.scaleY,g.scaleX,g.scaleY,m,y),h=g=null,function(b){for(var w=-1,v=y.length,S;++w<v;)m[(S=y[w]).i]=S.x(b);return m.join("")}}}var L7=pC(O7,"px, ","px)","deg)"),I7=pC(R7,", ",")",")"),z7=1e-12;function QE(e){return((e=Math.exp(e))+1/e)/2}function P7(e){return((e=Math.exp(e))-1/e)/2}function B7(e){return((e=Math.exp(2*e))-1)/(e+1)}const ih=(function e(t,n,r){function a(o,l){var d=o[0],f=o[1],h=o[2],g=l[0],m=l[1],y=l[2],b=g-d,w=m-f,v=b*b+w*w,S,E;if(v<z7)E=Math.log(y/h)/t,S=function(O){return[d+O*b,f+O*w,h*Math.exp(t*O*E)]};else{var C=Math.sqrt(v),N=(y*y-h*h+r*v)/(2*h*n*C),_=(y*y-h*h-r*v)/(2*y*n*C),M=Math.log(Math.sqrt(N*N+1)-N),A=Math.log(Math.sqrt(_*_+1)-_);E=(A-M)/t,S=function(O){var D=O*E,U=QE(M),B=h/(n*C)*(U*B7(t*D+M)-P7(M));return[d+B*b,f+B*w,h*U/QE(t*D+M)]}}return S.duration=E*1e3*t/Math.SQRT2,S}return a.rho=function(o){var l=Math.max(.001,+o),d=l*l,f=d*d;return e(l,d,f)},a})(Math.SQRT2,2,4);var ql=0,uu=0,su=0,mC=1e3,Th,du,Mh=0,yo=0,dp=0,Du=typeof performance=="object"&&performance.now?performance:Date,gC=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Ux(){return yo||(gC($7),yo=Du.now()+dp)}function $7(){yo=0}function Dh(){this._call=this._time=this._next=null}Dh.prototype=yC.prototype={constructor:Dh,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Ux():+n)+(t==null?0:+t),!this._next&&du!==this&&(du?du._next=this:Th=this,du=this),this._call=e,this._time=n,hb()},stop:function(){this._call&&(this._call=null,this._time=1/0,hb())}};function yC(e,t,n){var r=new Dh;return r.restart(e,t,n),r}function U7(){Ux(),++ql;for(var e=Th,t;e;)(t=yo-e._time)>=0&&e._call.call(void 0,t),e=e._next;--ql}function WE(){yo=(Mh=Du.now())+dp,ql=uu=0;try{U7()}finally{ql=0,q7(),yo=0}}function F7(){var e=Du.now(),t=e-Mh;t>mC&&(dp-=t,Mh=e)}function q7(){for(var e,t=Th,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Th=n);du=e,hb(r)}function hb(e){if(!ql){uu&&(uu=clearTimeout(uu));var t=e-yo;t>24?(e<1/0&&(uu=setTimeout(WE,e-Du.now()-dp)),su&&(su=clearInterval(su))):(su||(Mh=Du.now(),su=setInterval(F7,mC)),ql=1,gC(WE))}}function XE(e,t,n){var r=new Dh;return t=t==null?0:+t,r.restart(a=>{r.stop(),e(a+t)},t,n),r}var H7=cp("start","end","cancel","interrupt"),K7=[],bC=0,ZE=1,pb=2,ah=3,JE=4,mb=5,sh=6;function fp(e,t,n,r,a,o){var l=e.__transition;if(!l)e.__transition={};else if(n in l)return;G7(e,n,{name:t,index:r,group:a,on:H7,tween:K7,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:bC})}function Fx(e,t){var n=gi(e,t);if(n.state>bC)throw new Error("too late; already scheduled");return n}function Ii(e,t){var n=gi(e,t);if(n.state>ah)throw new Error("too late; already running");return n}function gi(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function G7(e,t,n){var r=e.__transition,a;r[t]=n,n.timer=yC(o,0,n.time);function o(h){n.state=ZE,n.timer.restart(l,n.delay,n.time),n.delay<=h&&l(h-n.delay)}function l(h){var g,m,y,b;if(n.state!==ZE)return f();for(g in r)if(b=r[g],b.name===n.name){if(b.state===ah)return XE(l);b.state===JE?(b.state=sh,b.timer.stop(),b.on.call("interrupt",e,e.__data__,b.index,b.group),delete r[g]):+g<t&&(b.state=sh,b.timer.stop(),b.on.call("cancel",e,e.__data__,b.index,b.group),delete r[g])}if(XE(function(){n.state===ah&&(n.state=JE,n.timer.restart(d,n.delay,n.time),d(h))}),n.state=pb,n.on.call("start",e,e.__data__,n.index,n.group),n.state===pb){for(n.state=ah,a=new Array(y=n.tween.length),g=0,m=-1;g<y;++g)(b=n.tween[g].value.call(e,e.__data__,n.index,n.group))&&(a[++m]=b);a.length=m+1}}function d(h){for(var g=h<n.duration?n.ease.call(null,h/n.duration):(n.timer.restart(f),n.state=mb,1),m=-1,y=a.length;++m<y;)a[m].call(e,g);n.state===mb&&(n.on.call("end",e,e.__data__,n.index,n.group),f())}function f(){n.state=sh,n.timer.stop(),delete r[t];for(var h in r)return;delete e.__transition}}function oh(e,t){var n=e.__transition,r,a,o=!0,l;if(n){t=t==null?null:t+"";for(l in n){if((r=n[l]).name!==t){o=!1;continue}a=r.state>pb&&r.state<mb,r.state=sh,r.timer.stop(),r.on.call(a?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[l]}o&&delete e.__transition}}function V7(e){return this.each(function(){oh(this,e)})}function Y7(e,t){var n,r;return function(){var a=Ii(this,e),o=a.tween;if(o!==n){r=n=o;for(var l=0,d=r.length;l<d;++l)if(r[l].name===t){r=r.slice(),r.splice(l,1);break}}a.tween=r}}function Q7(e,t,n){var r,a;if(typeof n!="function")throw new Error;return function(){var o=Ii(this,e),l=o.tween;if(l!==r){a=(r=l).slice();for(var d={name:t,value:n},f=0,h=a.length;f<h;++f)if(a[f].name===t){a[f]=d;break}f===h&&a.push(d)}o.tween=a}}function W7(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=gi(this.node(),n).tween,a=0,o=r.length,l;a<o;++a)if((l=r[a]).name===e)return l.value;return null}return this.each((t==null?Y7:Q7)(n,e,t))}function qx(e,t,n){var r=e._id;return e.each(function(){var a=Ii(this,r);(a.value||(a.value={}))[t]=n.apply(this,arguments)}),function(a){return gi(a,r).value[t]}}function xC(e,t){var n;return(typeof t=="number"?Ci:t instanceof go?Ah:(n=go(t))?(t=n,Ah):fC)(e,t)}function X7(e){return function(){this.removeAttribute(e)}}function Z7(e){return function(){this.removeAttributeNS(e.space,e.local)}}function J7(e,t,n){var r,a=n+"",o;return function(){var l=this.getAttribute(e);return l===a?null:l===r?o:o=t(r=l,n)}}function eK(e,t,n){var r,a=n+"",o;return function(){var l=this.getAttributeNS(e.space,e.local);return l===a?null:l===r?o:o=t(r=l,n)}}function tK(e,t,n){var r,a,o;return function(){var l,d=n(this),f;return d==null?void this.removeAttribute(e):(l=this.getAttribute(e),f=d+"",l===f?null:l===r&&f===a?o:(a=f,o=t(r=l,d)))}}function nK(e,t,n){var r,a,o;return function(){var l,d=n(this),f;return d==null?void this.removeAttributeNS(e.space,e.local):(l=this.getAttributeNS(e.space,e.local),f=d+"",l===f?null:l===r&&f===a?o:(a=f,o=t(r=l,d)))}}function rK(e,t){var n=up(e),r=n==="transform"?I7:xC;return this.attrTween(e,typeof t=="function"?(n.local?nK:tK)(n,r,qx(this,"attr."+e,t)):t==null?(n.local?Z7:X7)(n):(n.local?eK:J7)(n,r,t))}function iK(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function aK(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function sK(e,t){var n,r;function a(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&aK(e,o)),n}return a._value=t,a}function oK(e,t){var n,r;function a(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&iK(e,o)),n}return a._value=t,a}function lK(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=up(e);return this.tween(n,(r.local?sK:oK)(r,t))}function cK(e,t){return function(){Fx(this,e).delay=+t.apply(this,arguments)}}function uK(e,t){return t=+t,function(){Fx(this,e).delay=t}}function dK(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?cK:uK)(t,e)):gi(this.node(),t).delay}function fK(e,t){return function(){Ii(this,e).duration=+t.apply(this,arguments)}}function hK(e,t){return t=+t,function(){Ii(this,e).duration=t}}function pK(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?fK:hK)(t,e)):gi(this.node(),t).duration}function mK(e,t){if(typeof t!="function")throw new Error;return function(){Ii(this,e).ease=t}}function gK(e){var t=this._id;return arguments.length?this.each(mK(t,e)):gi(this.node(),t).ease}function yK(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ii(this,e).ease=n}}function bK(e){if(typeof e!="function")throw new Error;return this.each(yK(this._id,e))}function xK(e){typeof e!="function"&&(e=Wj(e));for(var t=this._groups,n=t.length,r=new Array(n),a=0;a<n;++a)for(var o=t[a],l=o.length,d=r[a]=[],f,h=0;h<l;++h)(f=o[h])&&e.call(f,f.__data__,h,o)&&d.push(f);return new ba(r,this._parents,this._name,this._id)}function vK(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,a=n.length,o=Math.min(r,a),l=new Array(r),d=0;d<o;++d)for(var f=t[d],h=n[d],g=f.length,m=l[d]=new Array(g),y,b=0;b<g;++b)(y=f[b]||h[b])&&(m[b]=y);for(;d<r;++d)l[d]=t[d];return new ba(l,this._parents,this._name,this._id)}function wK(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 kK(e,t,n){var r,a,o=wK(t)?Fx:Ii;return function(){var l=o(this,e),d=l.on;d!==r&&(a=(r=d).copy()).on(t,n),l.on=a}}function EK(e,t){var n=this._id;return arguments.length<2?gi(this.node(),n).on.on(e):this.each(kK(n,e,t))}function SK(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function NK(){return this.on("end.remove",SK(this._id))}function _K(e){var t=this._name,n=this._id;typeof e!="function"&&(e=zx(e));for(var r=this._groups,a=r.length,o=new Array(a),l=0;l<a;++l)for(var d=r[l],f=d.length,h=o[l]=new Array(f),g,m,y=0;y<f;++y)(g=d[y])&&(m=e.call(g,g.__data__,y,d))&&("__data__"in g&&(m.__data__=g.__data__),h[y]=m,fp(h[y],t,n,y,h,gi(g,n)));return new ba(o,this._parents,t,n)}function jK(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Qj(e));for(var r=this._groups,a=r.length,o=[],l=[],d=0;d<a;++d)for(var f=r[d],h=f.length,g,m=0;m<h;++m)if(g=f[m]){for(var y=e.call(g,g.__data__,m,f),b,w=gi(g,n),v=0,S=y.length;v<S;++v)(b=y[v])&&fp(b,t,n,v,y,w);o.push(y),l.push(g)}return new ba(o,l,t,n)}var CK=nd.prototype.constructor;function AK(){return new CK(this._groups,this._parents)}function TK(e,t){var n,r,a;return function(){var o=Fl(this,e),l=(this.style.removeProperty(e),Fl(this,e));return o===l?null:o===n&&l===r?a:a=t(n=o,r=l)}}function vC(e){return function(){this.style.removeProperty(e)}}function MK(e,t,n){var r,a=n+"",o;return function(){var l=Fl(this,e);return l===a?null:l===r?o:o=t(r=l,n)}}function DK(e,t,n){var r,a,o;return function(){var l=Fl(this,e),d=n(this),f=d+"";return d==null&&(f=d=(this.style.removeProperty(e),Fl(this,e))),l===f?null:l===r&&f===a?o:(a=f,o=t(r=l,d))}}function OK(e,t){var n,r,a,o="style."+t,l="end."+o,d;return function(){var f=Ii(this,e),h=f.on,g=f.value[o]==null?d||(d=vC(t)):void 0;(h!==n||a!==g)&&(r=(n=h).copy()).on(l,a=g),f.on=r}}function RK(e,t,n){var r=(e+="")=="transform"?L7:xC;return t==null?this.styleTween(e,TK(e,r)).on("end.style."+e,vC(e)):typeof t=="function"?this.styleTween(e,DK(e,r,qx(this,"style."+e,t))).each(OK(this._id,e)):this.styleTween(e,MK(e,r,t),n).on("end.style."+e,null)}function LK(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function IK(e,t,n){var r,a;function o(){var l=t.apply(this,arguments);return l!==a&&(r=(a=l)&&LK(e,l,n)),r}return o._value=t,o}function zK(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,IK(e,t,n??""))}function PK(e){return function(){this.textContent=e}}function BK(e){return function(){var t=e(this);this.textContent=t??""}}function $K(e){return this.tween("text",typeof e=="function"?BK(qx(this,"text",e)):PK(e==null?"":e+""))}function UK(e){return function(t){this.textContent=e.call(this,t)}}function FK(e){var t,n;function r(){var a=e.apply(this,arguments);return a!==n&&(t=(n=a)&&UK(a)),t}return r._value=e,r}function qK(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,FK(e))}function HK(){for(var e=this._name,t=this._id,n=wC(),r=this._groups,a=r.length,o=0;o<a;++o)for(var l=r[o],d=l.length,f,h=0;h<d;++h)if(f=l[h]){var g=gi(f,t);fp(f,e,n,h,l,{time:g.time+g.delay+g.duration,delay:0,duration:g.duration,ease:g.ease})}return new ba(r,this._parents,e,n)}function KK(){var e,t,n=this,r=n._id,a=n.size();return new Promise(function(o,l){var d={value:l},f={value:function(){--a===0&&o()}};n.each(function(){var h=Ii(this,r),g=h.on;g!==e&&(t=(e=g).copy(),t._.cancel.push(d),t._.interrupt.push(d),t._.end.push(f)),h.on=t}),a===0&&o()})}var GK=0;function ba(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function wC(){return++GK}var aa=nd.prototype;ba.prototype={constructor:ba,select:_K,selectAll:jK,selectChild:aa.selectChild,selectChildren:aa.selectChildren,filter:xK,merge:vK,selection:AK,transition:HK,call:aa.call,nodes:aa.nodes,node:aa.node,size:aa.size,empty:aa.empty,each:aa.each,on:EK,attr:rK,attrTween:lK,style:RK,styleTween:zK,text:$K,textTween:qK,remove:NK,tween:W7,delay:dK,duration:pK,ease:gK,easeVarying:bK,end:KK,[Symbol.iterator]:aa[Symbol.iterator]};function VK(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var YK={time:null,delay:0,duration:250,ease:VK};function QK(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 WK(e){var t,n;e instanceof ba?(t=e._id,e=e._name):(t=wC(),(n=YK).time=Ux(),e=e==null?null:e+"");for(var r=this._groups,a=r.length,o=0;o<a;++o)for(var l=r[o],d=l.length,f,h=0;h<d;++h)(f=l[h])&&fp(f,e,t,h,l,n||QK(f,t));return new ba(r,this._parents,e,t)}nd.prototype.interrupt=V7;nd.prototype.transition=WK;const Hf=e=>()=>e;function XK(e,{sourceEvent:t,target:n,transform:r,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:r,enumerable:!0,configurable:!0},_:{value:a}})}function fa(e,t,n){this.k=e,this.x=t,this.y=n}fa.prototype={constructor:fa,scale:function(e){return e===1?this:new fa(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new fa(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 hp=new fa(1,0,0);kC.prototype=fa.prototype;function kC(e){for(;!e.__zoom;)if(!(e=e.parentNode))return hp;return e.__zoom}function hy(e){e.stopImmediatePropagation()}function ou(e){e.preventDefault(),e.stopImmediatePropagation()}function ZK(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function JK(){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 eS(){return this.__zoom||hp}function eG(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function tG(){return navigator.maxTouchPoints||"ontouchstart"in this}function nG(e,t,n){var r=e.invertX(t[0][0])-n[0][0],a=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],l=e.invertY(t[1][1])-n[1][1];return e.translate(a>r?(r+a)/2:Math.min(0,r)||Math.max(0,a),l>o?(o+l)/2:Math.min(0,o)||Math.max(0,l))}function EC(){var e=ZK,t=JK,n=nG,r=eG,a=tG,o=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],d=250,f=ih,h=cp("start","zoom","end"),g,m,y,b=500,w=150,v=0,S=10;function E(R){R.property("__zoom",eS).on("wheel.zoom",D,{passive:!1}).on("mousedown.zoom",U).on("dblclick.zoom",B).filter(a).on("touchstart.zoom",q).on("touchmove.zoom",G).on("touchend.zoom touchcancel.zoom",Q).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}E.transform=function(R,H,L,V){var Y=R.selection?R.selection():R;Y.property("__zoom",eS),R!==Y?M(R,H,L,V):Y.interrupt().each(function(){A(this,arguments).event(V).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},E.scaleBy=function(R,H,L,V){E.scaleTo(R,function(){var Y=this.__zoom.k,K=typeof H=="function"?H.apply(this,arguments):H;return Y*K},L,V)},E.scaleTo=function(R,H,L,V){E.transform(R,function(){var Y=t.apply(this,arguments),K=this.__zoom,z=L==null?_(Y):typeof L=="function"?L.apply(this,arguments):L,$=K.invert(z),P=typeof H=="function"?H.apply(this,arguments):H;return n(N(C(K,P),z,$),Y,l)},L,V)},E.translateBy=function(R,H,L,V){E.transform(R,function(){return n(this.__zoom.translate(typeof H=="function"?H.apply(this,arguments):H,typeof L=="function"?L.apply(this,arguments):L),t.apply(this,arguments),l)},null,V)},E.translateTo=function(R,H,L,V,Y){E.transform(R,function(){var K=t.apply(this,arguments),z=this.__zoom,$=V==null?_(K):typeof V=="function"?V.apply(this,arguments):V;return n(hp.translate($[0],$[1]).scale(z.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof L=="function"?-L.apply(this,arguments):-L),K,l)},V,Y)};function C(R,H){return H=Math.max(o[0],Math.min(o[1],H)),H===R.k?R:new fa(H,R.x,R.y)}function N(R,H,L){var V=H[0]-L[0]*R.k,Y=H[1]-L[1]*R.k;return V===R.x&&Y===R.y?R:new fa(R.k,V,Y)}function _(R){return[(+R[0][0]+ +R[1][0])/2,(+R[0][1]+ +R[1][1])/2]}function M(R,H,L,V){R.on("start.zoom",function(){A(this,arguments).event(V).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(V).end()}).tween("zoom",function(){var Y=this,K=arguments,z=A(Y,K).event(V),$=t.apply(Y,K),P=L==null?_($):typeof L=="function"?L.apply(Y,K):L,I=Math.max($[1][0]-$[0][0],$[1][1]-$[0][1]),ae=Y.__zoom,me=typeof H=="function"?H.apply(Y,K):H,ve=f(ae.invert(P).concat(I/ae.k),me.invert(P).concat(I/me.k));return function(we){if(we===1)we=me;else{var J=ve(we),de=I/J[2];we=new fa(de,P[0]-J[0]*de,P[1]-J[1]*de)}z.zoom(null,we)}})}function A(R,H,L){return!L&&R.__zooming||new O(R,H)}function O(R,H){this.that=R,this.args=H,this.active=0,this.sourceEvent=null,this.extent=t.apply(R,H),this.taps=0}O.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,H){return this.mouse&&R!=="mouse"&&(this.mouse[1]=H.invert(this.mouse[0])),this.touch0&&R!=="touch"&&(this.touch0[1]=H.invert(this.touch0[0])),this.touch1&&R!=="touch"&&(this.touch1[1]=H.invert(this.touch1[0])),this.that.__zoom=H,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(R){var H=_r(this.that).datum();h.call(R,this.that,new XK(R,{sourceEvent:this.sourceEvent,target:E,transform:this.that.__zoom,dispatch:h}),H)}};function D(R,...H){if(!e.apply(this,arguments))return;var L=A(this,H).event(R),V=this.__zoom,Y=Math.max(o[0],Math.min(o[1],V.k*Math.pow(2,r.apply(this,arguments)))),K=si(R);if(L.wheel)(L.mouse[0][0]!==K[0]||L.mouse[0][1]!==K[1])&&(L.mouse[1]=V.invert(L.mouse[0]=K)),clearTimeout(L.wheel);else{if(V.k===Y)return;L.mouse=[K,V.invert(K)],oh(this),L.start()}ou(R),L.wheel=setTimeout(z,w),L.zoom("mouse",n(N(C(V,Y),L.mouse[0],L.mouse[1]),L.extent,l));function z(){L.wheel=null,L.end()}}function U(R,...H){if(y||!e.apply(this,arguments))return;var L=R.currentTarget,V=A(this,H,!0).event(R),Y=_r(R.view).on("mousemove.zoom",P,!0).on("mouseup.zoom",I,!0),K=si(R,L),z=R.clientX,$=R.clientY;sC(R.view),hy(R),V.mouse=[K,this.__zoom.invert(K)],oh(this),V.start();function P(ae){if(ou(ae),!V.moved){var me=ae.clientX-z,ve=ae.clientY-$;V.moved=me*me+ve*ve>v}V.event(ae).zoom("mouse",n(N(V.that.__zoom,V.mouse[0]=si(ae,L),V.mouse[1]),V.extent,l))}function I(ae){Y.on("mousemove.zoom mouseup.zoom",null),oC(ae.view,V.moved),ou(ae),V.event(ae).end()}}function B(R,...H){if(e.apply(this,arguments)){var L=this.__zoom,V=si(R.changedTouches?R.changedTouches[0]:R,this),Y=L.invert(V),K=L.k*(R.shiftKey?.5:2),z=n(N(C(L,K),V,Y),t.apply(this,H),l);ou(R),d>0?_r(this).transition().duration(d).call(M,z,V,R):_r(this).call(E.transform,z,V,R)}}function q(R,...H){if(e.apply(this,arguments)){var L=R.touches,V=L.length,Y=A(this,H,R.changedTouches.length===V).event(R),K,z,$,P;for(hy(R),z=0;z<V;++z)$=L[z],P=si($,this),P=[P,this.__zoom.invert(P),$.identifier],Y.touch0?!Y.touch1&&Y.touch0[2]!==P[2]&&(Y.touch1=P,Y.taps=0):(Y.touch0=P,K=!0,Y.taps=1+!!g);g&&(g=clearTimeout(g)),K&&(Y.taps<2&&(m=P[0],g=setTimeout(function(){g=null},b)),oh(this),Y.start())}}function G(R,...H){if(this.__zooming){var L=A(this,H).event(R),V=R.changedTouches,Y=V.length,K,z,$,P;for(ou(R),K=0;K<Y;++K)z=V[K],$=si(z,this),L.touch0&&L.touch0[2]===z.identifier?L.touch0[0]=$:L.touch1&&L.touch1[2]===z.identifier&&(L.touch1[0]=$);if(z=L.that.__zoom,L.touch1){var I=L.touch0[0],ae=L.touch0[1],me=L.touch1[0],ve=L.touch1[1],we=(we=me[0]-I[0])*we+(we=me[1]-I[1])*we,J=(J=ve[0]-ae[0])*J+(J=ve[1]-ae[1])*J;z=C(z,Math.sqrt(we/J)),$=[(I[0]+me[0])/2,(I[1]+me[1])/2],P=[(ae[0]+ve[0])/2,(ae[1]+ve[1])/2]}else if(L.touch0)$=L.touch0[0],P=L.touch0[1];else return;L.zoom("touch",n(N(z,$,P),L.extent,l))}}function Q(R,...H){if(this.__zooming){var L=A(this,H).event(R),V=R.changedTouches,Y=V.length,K,z;for(hy(R),y&&clearTimeout(y),y=setTimeout(function(){y=null},b),K=0;K<Y;++K)z=V[K],L.touch0&&L.touch0[2]===z.identifier?delete L.touch0:L.touch1&&L.touch1[2]===z.identifier&&delete L.touch1;if(L.touch1&&!L.touch0&&(L.touch0=L.touch1,delete L.touch1),L.touch0)L.touch0[1]=this.__zoom.invert(L.touch0[0]);else if(L.end(),L.taps===2&&(z=si(z,this),Math.hypot(m[0]-z[0],m[1]-z[1])<S)){var $=_r(this).on("dblclick.zoom");$&&$.apply(this,arguments)}}}return E.wheelDelta=function(R){return arguments.length?(r=typeof R=="function"?R:Hf(+R),E):r},E.filter=function(R){return arguments.length?(e=typeof R=="function"?R:Hf(!!R),E):e},E.touchable=function(R){return arguments.length?(a=typeof R=="function"?R:Hf(!!R),E):a},E.extent=function(R){return arguments.length?(t=typeof R=="function"?R:Hf([[+R[0][0],+R[0][1]],[+R[1][0],+R[1][1]]]),E):t},E.scaleExtent=function(R){return arguments.length?(o[0]=+R[0],o[1]=+R[1],E):[o[0],o[1]]},E.translateExtent=function(R){return arguments.length?(l[0][0]=+R[0][0],l[1][0]=+R[1][0],l[0][1]=+R[0][1],l[1][1]=+R[1][1],E):[[l[0][0],l[0][1]],[l[1][0],l[1][1]]]},E.constrain=function(R){return arguments.length?(n=R,E):n},E.duration=function(R){return arguments.length?(d=+R,E):d},E.interpolate=function(R){return arguments.length?(f=R,E):f},E.on=function(){var R=h.on.apply(h,arguments);return R===h?E:R},E.clickDistance=function(R){return arguments.length?(v=(R=+R)*R,E):Math.sqrt(v)},E.tapDistance=function(R){return arguments.length?(S=+R,E):S},E}const hi={error001:(e="react")=>`Seems like you have not used ${e==="svelte"?"SvelteFlowProvider":"ReactFlowProvider"} as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:r}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.",error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},Ou=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],SC=["Enter"," ","Escape"],NC={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Hl;(function(e){e.Strict="strict",e.Loose="loose"})(Hl||(Hl={}));var uo;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(uo||(uo={}));var Ru;(function(e){e.Partial="partial",e.Full="full"})(Ru||(Ru={}));const _C={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var os;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(os||(os={}));var Oh;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Oh||(Oh={}));var He;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(He||(He={}));const tS={[He.Left]:He.Right,[He.Right]:He.Left,[He.Top]:He.Bottom,[He.Bottom]:He.Top};function jC(e){return e===null?null:e?"valid":"invalid"}const CC=e=>"id"in e&&"source"in e&&"target"in e,rG=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Hx=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),id=(e,t=[0,0])=>{const{width:n,height:r}=va(e),a=e.origin??t,o=n*a[0],l=r*a[1];return{x:e.position.x-o,y:e.position.y-l}},iG=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,a)=>{const o=typeof a=="string";let l=!t.nodeLookup&&!o?a:void 0;t.nodeLookup&&(l=o?t.nodeLookup.get(a):Hx(a)?a:t.nodeLookup.get(a.id));const d=l?Rh(l,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return pp(r,d)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return mp(n)},ad=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(a=>{(t.filter===void 0||t.filter(a))&&(n=pp(n,Rh(a)),r=!0)}),r?mp(n):{x:0,y:0,width:0,height:0}},Kx=(e,t,[n,r,a]=[0,0,1],o=!1,l=!1)=>{const d=(t.x-n)/a,f=(t.y-r)/a,h=t.width/a,g=t.height/a,m=[];for(const y of e.values()){const{measured:b,selectable:w=!0,hidden:v=!1}=y;if(l&&!w||v)continue;const S=b.width??y.width??y.initialWidth??0,E=b.height??y.height??y.initialHeight??0,{x:C,y:N}=y.internals.positionAbsolute,_=DC(d,f,h,g,C,N,S,E),M=S*E,A=o&&_>0;(!y.internals.handleBounds||A||_>=M||y.dragging)&&m.push(y)}return m},aG=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function sG(e,t){const n=new Map,r=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)&&(!r||r.has(a.id))&&n.set(a.id,a)}),n}async function oG({nodes:e,width:t,height:n,panZoom:r,minZoom:a,maxZoom:o},l){if(e.size===0)return!0;const d=sG(e,l),f=ad(d),h=Vx(f,t,n,(l==null?void 0:l.minZoom)??a,(l==null?void 0:l.maxZoom)??o,(l==null?void 0:l.padding)??.1);return await r.setViewport(h,{duration:l==null?void 0:l.duration,ease:l==null?void 0:l.ease,interpolate:l==null?void 0:l.interpolate}),!0}function AC({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:a,onError:o}){const l=n.get(e),d=l.parentId?n.get(l.parentId):void 0,{x:f,y:h}=d?d.internals.positionAbsolute:{x:0,y:0},g=l.origin??r;let m=l.extent||a;if(l.extent==="parent"&&!l.expandParent)if(!d)o==null||o("005",hi.error005());else{const b=d.measured.width,w=d.measured.height;b&&w&&(m=[[f,h],[f+b,h+w]])}else d&&xo(l.extent)&&(m=[[l.extent[0][0]+f,l.extent[0][1]+h],[l.extent[1][0]+f,l.extent[1][1]+h]]);const y=xo(m)?bo(t,m,l.measured):t;return(l.measured.width===void 0||l.measured.height===void 0)&&(o==null||o("015",hi.error015())),{position:{x:y.x-f+(l.measured.width??0)*g[0],y:y.y-h+(l.measured.height??0)*g[1]},positionAbsolute:y}}async function lG({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:a}){const o=new Set(e.map(y=>y.id)),l=[];for(const y of n){if(y.deletable===!1)continue;const b=o.has(y.id),w=!b&&y.parentId&&l.find(v=>v.id===y.parentId);(b||w)&&l.push(y)}const d=new Set(t.map(y=>y.id)),f=r.filter(y=>y.deletable!==!1),g=aG(l,f);for(const y of f)d.has(y.id)&&!g.find(w=>w.id===y.id)&&g.push(y);if(!a)return{edges:g,nodes:l};const m=await a({nodes:l,edges:g});return typeof m=="boolean"?m?{edges:g,nodes:l}:{edges:[],nodes:[]}:m}const Kl=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),bo=(e={x:0,y:0},t,n)=>({x:Kl(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:Kl(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function TC(e,t,n){const{width:r,height:a}=va(n),{x:o,y:l}=n.internals.positionAbsolute;return bo(e,[[o,l],[o+r,l+a]],t)}const nS=(e,t,n)=>e<t?Kl(Math.abs(e-t),1,t)/t:e>n?-Kl(Math.abs(e-n),1,t)/t:0,Gx=(e,t,n=15,r=40)=>{const a=nS(e.x,r,t.width-r)*n,o=nS(e.y,r,t.height-r)*n;return[a,o]},pp=(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)}),gb=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),mp=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Lu=(e,t=[0,0])=>{var a,o;const{x:n,y:r}=Hx(e)?e.internals.positionAbsolute:id(e,t);return{x:n,y:r,width:((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0,height:((o=e.measured)==null?void 0:o.height)??e.height??e.initialHeight??0}},Rh=(e,t=[0,0])=>{var a,o;const{x:n,y:r}=Hx(e)?e.internals.positionAbsolute:id(e,t);return{x:n,y:r,x2:n+(((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0),y2:r+(((o=e.measured)==null?void 0:o.height)??e.height??e.initialHeight??0)}},MC=(e,t)=>mp(pp(gb(e),gb(t))),DC=(e,t,n,r,a,o,l,d)=>{const f=Math.max(0,Math.min(e+n,a+l)-Math.max(e,a)),h=Math.max(0,Math.min(t+r,o+d)-Math.max(t,o));return Math.ceil(f*h)},Lh=(e,t)=>DC(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),rS=e=>li(e.width)&&li(e.height)&&li(e.x)&&li(e.y),li=e=>!isNaN(e)&&isFinite(e),OC=(e,t)=>(n,r)=>{},sd=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),od=({x:e,y:t},[n,r,a],o=!1,l=[1,1])=>{const d={x:(e-n)/a,y:(t-r)/a};return o?sd(d,l):d},Gl=({x:e,y:t},[n,r,a])=>({x:e*a+n,y:t*a+r});function ul(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 cG(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=ul(e,n),a=ul(e,t);return{top:r,right:a,bottom:r,left:a,x:a*2,y:r*2}}if(typeof e=="object"){const r=ul(e.top??e.y??0,n),a=ul(e.bottom??e.y??0,n),o=ul(e.left??e.x??0,t),l=ul(e.right??e.x??0,t);return{top:r,right:l,bottom:a,left:o,x:o+l,y:r+a}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function uG(e,t,n,r,a,o){const{x:l,y:d}=Gl(e,[t,n,r]),{x:f,y:h}=Gl({x:e.x+e.width,y:e.y+e.height},[t,n,r]),g=a-f,m=o-h;return{left:Math.floor(l),top:Math.floor(d),right:Math.floor(g),bottom:Math.floor(m)}}const Vx=(e,t,n,r,a,o)=>{const l=cG(o,t,n),d=(t-l.x)/e.width,f=(n-l.y)/e.height,h=Math.min(d,f),g=Kl(h,r,a),m=e.x+e.width/2,y=e.y+e.height/2,b=t/2-m*g,w=n/2-y*g,v=uG(e,b,w,g,t,n),S={left:Math.min(v.left-l.left,0),top:Math.min(v.top-l.top,0),right:Math.min(v.right-l.right,0),bottom:Math.min(v.bottom-l.bottom,0)};return{x:b-S.left+S.right,y:w-S.top+S.bottom,zoom:g}},Iu=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function xo(e){return e!=null&&e!=="parent"}function va(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 RC(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 LC(e,t={width:0,height:0},n,r,a){const o={...e},l=r.get(n);if(l){const d=l.origin||a;o.x+=l.internals.positionAbsolute.x-(t.width??0)*d[0],o.y+=l.internals.positionAbsolute.y-(t.height??0)*d[1]}return o}function iS(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function dG(){let e,t;return{promise:new Promise((r,a)=>{e=r,t=a}),resolve:e,reject:t}}function fG(e){return{...NC,...e||{}}}function bu(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:a}){const{x:o,y:l}=ci(e),d=od({x:o-((a==null?void 0:a.left)??0),y:l-((a==null?void 0:a.top)??0)},r),{x:f,y:h}=n?sd(d,t):d;return{xSnapped:f,ySnapped:h,...d}}const Yx=e=>({width:e.offsetWidth,height:e.offsetHeight}),IC=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},hG=["INPUT","SELECT","TEXTAREA"];function zC(e){var r,a;const t=((a=(r=e.composedPath)==null?void 0:r.call(e))==null?void 0:a[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:hG.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const PC=e=>"clientX"in e,ci=(e,t)=>{var o,l;const n=PC(e),r=n?e.clientX:(o=e.touches)==null?void 0:o[0].clientX,a=n?e.clientY:(l=e.touches)==null?void 0:l[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:a-((t==null?void 0:t.top)??0)}},aS=(e,t,n,r,a)=>{const o=t.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(l=>{const d=l.getBoundingClientRect();return{id:l.getAttribute("data-handleid"),type:e,nodeId:a,position:l.getAttribute("data-handlepos"),x:(d.left-n.left)/r,y:(d.top-n.top)/r,...Yx(l)}})};function BC({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:a,sourceControlY:o,targetControlX:l,targetControlY:d}){const f=e*.125+a*.375+l*.375+n*.125,h=t*.125+o*.375+d*.375+r*.125,g=Math.abs(f-e),m=Math.abs(h-t);return[f,h,g,m]}function Kf(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function sS({pos:e,x1:t,y1:n,x2:r,y2:a,c:o}){switch(e){case He.Left:return[t-Kf(t-r,o),n];case He.Right:return[t+Kf(r-t,o),n];case He.Top:return[t,n-Kf(n-a,o)];case He.Bottom:return[t,n+Kf(a-n,o)]}}function $C({sourceX:e,sourceY:t,sourcePosition:n=He.Bottom,targetX:r,targetY:a,targetPosition:o=He.Top,curvature:l=.25}){const[d,f]=sS({pos:n,x1:e,y1:t,x2:r,y2:a,c:l}),[h,g]=sS({pos:o,x1:r,y1:a,x2:e,y2:t,c:l}),[m,y,b,w]=BC({sourceX:e,sourceY:t,targetX:r,targetY:a,sourceControlX:d,sourceControlY:f,targetControlX:h,targetControlY:g});return[`M${e},${t} C${d},${f} ${h},${g} ${r},${a}`,m,y,b,w]}function UC({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e)/2,o=n<e?n+a:n-a,l=Math.abs(r-t)/2,d=r<t?r+l:r-l;return[o,d,a,l]}function pG({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:a=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const l=a&&n?r+1e3:r,d=Math.max(e.parentId||a&&e.selected?e.internals.z:0,t.parentId||a&&t.selected?t.internals.z:0);return l+d}function mG({sourceNode:e,targetNode:t,width:n,height:r,transform:a}){const o=pp(Rh(e),Rh(t));o.x===o.x2&&(o.x2+=1),o.y===o.y2&&(o.y2+=1);const l={x:-a[0]/a[2],y:-a[1]/a[2],width:n/a[2],height:r/a[2]};return Lh(l,mp(o))>0}const gG=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,yG=(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)),bG=(e,t,n={})=>{var o;if(!e.source||!e.target)return(o=n.onError)==null||o.call(n,"006",hi.error006()),t;const r=n.getEdgeId||gG;let a;return CC(e)?a={...e}:a={...e,id:r(e)},yG(a,t)?t:(a.sourceHandle===null&&delete a.sourceHandle,a.targetHandle===null&&delete a.targetHandle,t.concat(a))};function FC({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[a,o,l,d]=UC({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,a,o,l,d]}const oS={[He.Left]:{x:-1,y:0},[He.Right]:{x:1,y:0},[He.Top]:{x:0,y:-1},[He.Bottom]:{x:0,y:1}},xG=({source:e,sourcePosition:t=He.Bottom,target:n})=>t===He.Left||t===He.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},lS=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vG({source:e,sourcePosition:t=He.Bottom,target:n,targetPosition:r=He.Top,center:a,offset:o,stepPosition:l}){const d=oS[t],f=oS[r],h={x:e.x+d.x*o,y:e.y+d.y*o},g={x:n.x+f.x*o,y:n.y+f.y*o},m=xG({source:h,sourcePosition:t,target:g}),y=m.x!==0?"x":"y",b=m[y];let w=[],v,S;const E={x:0,y:0},C={x:0,y:0},[,,N,_]=UC({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(d[y]*f[y]===-1){y==="x"?(v=a.x??h.x+(g.x-h.x)*l,S=a.y??(h.y+g.y)/2):(v=a.x??(h.x+g.x)/2,S=a.y??h.y+(g.y-h.y)*l);const D=[{x:v,y:h.y},{x:v,y:g.y}],U=[{x:h.x,y:S},{x:g.x,y:S}];d[y]===b?w=y==="x"?D:U:w=y==="x"?U:D}else{const D=[{x:h.x,y:g.y}],U=[{x:g.x,y:h.y}];if(y==="x"?w=d.x===b?U:D:w=d.y===b?D:U,t===r){const R=Math.abs(e[y]-n[y]);if(R<=o){const H=Math.min(o-1,o-R);d[y]===b?E[y]=(h[y]>e[y]?-1:1)*H:C[y]=(g[y]>n[y]?-1:1)*H}}if(t!==r){const R=y==="x"?"y":"x",H=d[y]===f[R],L=h[R]>g[R],V=h[R]<g[R];(d[y]===1&&(!H&&L||H&&V)||d[y]!==1&&(!H&&V||H&&L))&&(w=y==="x"?D:U)}const B={x:h.x+E.x,y:h.y+E.y},q={x:g.x+C.x,y:g.y+C.y},G=Math.max(Math.abs(B.x-w[0].x),Math.abs(q.x-w[0].x)),Q=Math.max(Math.abs(B.y-w[0].y),Math.abs(q.y-w[0].y));G>=Q?(v=(B.x+q.x)/2,S=w[0].y):(v=w[0].x,S=(B.y+q.y)/2)}const M={x:h.x+E.x,y:h.y+E.y},A={x:g.x+C.x,y:g.y+C.y};return[[e,...M.x!==w[0].x||M.y!==w[0].y?[M]:[],...w,...A.x!==w[w.length-1].x||A.y!==w[w.length-1].y?[A]:[],n],v,S,N,_]}function wG(e,t,n,r){const a=Math.min(lS(e,t)/2,lS(t,n)/2,r),{x:o,y:l}=t;if(e.x===o&&o===n.x||e.y===l&&l===n.y)return`L${o} ${l}`;if(e.y===l){const h=e.x<n.x?-1:1,g=e.y<n.y?1:-1;return`L ${o+a*h},${l}Q ${o},${l} ${o},${l+a*g}`}const d=e.x<n.x?1:-1,f=e.y<n.y?-1:1;return`L ${o},${l+a*f}Q ${o},${l} ${o+a*d},${l}`}function yb({sourceX:e,sourceY:t,sourcePosition:n=He.Bottom,targetX:r,targetY:a,targetPosition:o=He.Top,borderRadius:l=5,centerX:d,centerY:f,offset:h=20,stepPosition:g=.5}){const[m,y,b,w,v]=vG({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:a},targetPosition:o,center:{x:d,y:f},offset:h,stepPosition:g});let S=`M${m[0].x} ${m[0].y}`;for(let E=1;E<m.length-1;E++)S+=wG(m[E-1],m[E],m[E+1],l);return S+=`L${m[m.length-1].x} ${m[m.length-1].y}`,[S,y,b,w,v]}function cS(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function kG(e){var m;const{sourceNode:t,targetNode:n}=e;if(!cS(t)||!cS(n))return null;const r=t.internals.handleBounds||uS(t.handles),a=n.internals.handleBounds||uS(n.handles),o=dS((r==null?void 0:r.source)??[],e.sourceHandle),l=dS(e.connectionMode===Hl.Strict?(a==null?void 0:a.target)??[]:((a==null?void 0:a.target)??[]).concat((a==null?void 0:a.source)??[]),e.targetHandle);if(!o||!l)return(m=e.onError)==null||m.call(e,"008",hi.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const d=(o==null?void 0:o.position)||He.Bottom,f=(l==null?void 0:l.position)||He.Top,h=vo(t,o,d),g=vo(n,l,f);return{sourceX:h.x,sourceY:h.y,targetX:g.x,targetY:g.y,sourcePosition:d,targetPosition:f}}function uS(e){if(!e)return null;const t=[],n=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?t.push(r):r.type==="target"&&n.push(r);return{source:t,target:n}}function vo(e,t,n=He.Left,r=!1){const a=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,o=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:l,height:d}=t??va(e);if(r)return{x:a+l/2,y:o+d/2};switch((t==null?void 0:t.position)??n){case He.Top:return{x:a+l/2,y:o};case He.Right:return{x:a+l,y:o+d/2};case He.Bottom:return{x:a+l/2,y:o+d};case He.Left:return{x:a,y:o+d/2}}}function dS(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function bb(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function EG(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:a}){const o=new Set;return e.reduce((l,d)=>([d.markerStart||r,d.markerEnd||a].forEach(f=>{if(f&&typeof f=="object"){const h=bb(f,t);o.has(h)||(l.push({id:h,color:f.color||n,...f}),o.add(h))}}),l),[]).sort((l,d)=>l.id.localeCompare(d.id))}const qC=1e3,SG=10,Qx={nodeOrigin:[0,0],nodeExtent:Ou,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},NG={...Qx,checkEquality:!0};function Wx(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function _G(e,t,n){const r=Wx(Qx,n);for(const a of e.values())if(a.parentId)Zx(a,e,t,r);else{const o=id(a,r.nodeOrigin),l=xo(a.extent)?a.extent:r.nodeExtent,d=bo(o,l,va(a));a.internals.positionAbsolute=d}}function jG(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],r=[];for(const a of e.handles){const o={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(o):a.type==="target"&&r.push(o)}return{source:n,target:r}}function Xx(e){return e==="manual"}function xb(e,t,n,r={}){var g,m;const a=Wx(NG,r),o={i:0},l=new Map(t),d=a!=null&&a.elevateNodesOnSelect&&!Xx(a.zIndexMode)?qC:0;let f=e.length>0,h=!1;t.clear(),n.clear();for(const y of e){let b=l.get(y.id);if(a.checkEquality&&y===(b==null?void 0:b.internals.userNode))t.set(y.id,b);else{const w=id(y,a.nodeOrigin),v=xo(y.extent)?y.extent:a.nodeExtent,S=bo(w,v,va(y));b={...a.defaults,...y,measured:{width:(g=y.measured)==null?void 0:g.width,height:(m=y.measured)==null?void 0:m.height},internals:{positionAbsolute:S,handleBounds:jG(y,b),z:HC(y,d,a.zIndexMode),userNode:y}},t.set(y.id,b)}(b.measured===void 0||b.measured.width===void 0||b.measured.height===void 0)&&!b.hidden&&(f=!1),y.parentId&&Zx(b,t,n,r,o),h||(h=y.selected??!1)}return{nodesInitialized:f,hasSelectedNodes:h}}function CG(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 Zx(e,t,n,r,a){const{elevateNodesOnSelect:o,nodeOrigin:l,nodeExtent:d,zIndexMode:f}=Wx(Qx,r),h=e.parentId,g=t.get(h);if(!g){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}CG(e,n),a&&!g.parentId&&g.internals.rootParentIndex===void 0&&f==="auto"&&(g.internals.rootParentIndex=++a.i,g.internals.z=g.internals.z+a.i*SG),a&&g.internals.rootParentIndex!==void 0&&(a.i=g.internals.rootParentIndex);const m=o&&!Xx(f)?qC:0,{x:y,y:b,z:w}=AG(e,g,l,d,m,f),{positionAbsolute:v}=e.internals,S=y!==v.x||b!==v.y;(S||w!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:S?{x:y,y:b}:v,z:w}})}function HC(e,t,n){const r=li(e.zIndex)?e.zIndex:0;return Xx(n)?r:r+(e.selected?t:0)}function AG(e,t,n,r,a,o){const{x:l,y:d}=t.internals.positionAbsolute,f=va(e),h=id(e,n),g=xo(e.extent)?bo(h,e.extent,f):h;let m=bo({x:l+g.x,y:d+g.y},r,f);e.extent==="parent"&&(m=TC(m,f,t));const y=HC(e,a,o),b=t.internals.z??0;return{x:m.x,y:m.y,z:b>=y?b+1:y}}function Jx(e,t,n,r=[0,0]){var l;const a=[],o=new Map;for(const d of e){const f=t.get(d.parentId);if(!f)continue;const h=((l=o.get(d.parentId))==null?void 0:l.expandedRect)??Lu(f),g=MC(h,d.rect);o.set(d.parentId,{expandedRect:g,parent:f})}return o.size>0&&o.forEach(({expandedRect:d,parent:f},h)=>{var N;const g=f.internals.positionAbsolute,m=va(f),y=f.origin??r,b=d.x<g.x?Math.round(Math.abs(g.x-d.x)):0,w=d.y<g.y?Math.round(Math.abs(g.y-d.y)):0,v=Math.max(m.width,Math.round(d.width)),S=Math.max(m.height,Math.round(d.height)),E=(v-m.width)*y[0],C=(S-m.height)*y[1];(b>0||w>0||E||C)&&(a.push({id:h,type:"position",position:{x:f.position.x-b+E,y:f.position.y-w+C}}),(N=n.get(h))==null||N.forEach(_=>{e.some(M=>M.id===_.id)||a.push({id:_.id,type:"position",position:{x:_.position.x+b,y:_.position.y+w}})})),(m.width<d.width||m.height<d.height||b||w)&&a.push({id:h,type:"dimensions",setAttributes:!0,dimensions:{width:v+(b?y[0]*b-E:0),height:S+(w?y[1]*w-C:0)}})}),a}function TG(e,t,n,r,a,o,l){const d=r==null?void 0:r.querySelector(".xyflow__viewport");let f=!1;if(!d)return{changes:[],updatedInternals:f};const h=[],g=window.getComputedStyle(d),{m22:m}=new window.DOMMatrixReadOnly(g.transform),y=[];for(const b of e.values()){const w=t.get(b.id);if(!w)continue;if(w.hidden){t.set(w.id,{...w,internals:{...w.internals,handleBounds:void 0}}),f=!0;continue}const v=Yx(b.nodeElement),S=w.measured.width!==v.width||w.measured.height!==v.height;if(!!(v.width&&v.height&&(S||!w.internals.handleBounds||b.force))){const C=b.nodeElement.getBoundingClientRect(),N=xo(w.extent)?w.extent:o;let{positionAbsolute:_}=w.internals;w.parentId&&w.extent==="parent"?_=TC(_,v,t.get(w.parentId)):N&&(_=bo(_,N,v));const M={...w,measured:v,internals:{...w.internals,positionAbsolute:_,handleBounds:{source:aS("source",b.nodeElement,C,m,w.id),target:aS("target",b.nodeElement,C,m,w.id)}}};t.set(w.id,M),w.parentId&&Zx(M,t,n,{nodeOrigin:a,zIndexMode:l}),f=!0,S&&(h.push({id:w.id,type:"dimensions",dimensions:v}),w.expandParent&&w.parentId&&y.push({id:w.id,parentId:w.parentId,rect:Lu(M,a)}))}}if(y.length>0){const b=Jx(y,t,n,a);h.push(...b)}return{changes:h,updatedInternals:f}}async function MG({delta:e,panZoom:t,transform:n,translateExtent:r,width:a,height:o}){if(!t||!e.x&&!e.y)return!1;const l=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[a,o]],r);return!!l&&(l.x!==n[0]||l.y!==n[1]||l.k!==n[2])}function fS(e,t,n,r,a,o){let l=a;const d=r.get(l)||new Map;r.set(l,d.set(n,t)),l=`${a}-${e}`;const f=r.get(l)||new Map;if(r.set(l,f.set(n,t)),o){l=`${a}-${e}-${o}`;const h=r.get(l)||new Map;r.set(l,h.set(n,t))}}function KC(e,t,n){e.clear(),t.clear();for(const r of n){const{source:a,target:o,sourceHandle:l=null,targetHandle:d=null}=r,f={edgeId:r.id,source:a,target:o,sourceHandle:l,targetHandle:d},h=`${a}-${l}--${o}-${d}`,g=`${o}-${d}--${a}-${l}`;fS("source",f,g,e,a,l),fS("target",f,h,e,o,d),t.set(r.id,r)}}function GC(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:GC(n,t):!1}function hS(e,t,n){var a;let r=e;do{if((a=r==null?void 0:r.matches)!=null&&a.call(r,t))return!0;if(r===n)return!1;r=r==null?void 0:r.parentElement}while(r);return!1}function DG(e,t,n,r){const a=new Map;for(const[o,l]of e)if((l.selected||l.id===r)&&(!l.parentId||!GC(l,e))&&(l.draggable||t&&typeof l.draggable>"u")){const d=e.get(o);d&&a.set(o,{id:o,position:d.position||{x:0,y:0},distance:{x:n.x-d.internals.positionAbsolute.x,y:n.y-d.internals.positionAbsolute.y},extent:d.extent,parentId:d.parentId,origin:d.origin,expandParent:d.expandParent,internals:{positionAbsolute:d.internals.positionAbsolute||{x:0,y:0}},measured:{width:d.measured.width??0,height:d.measured.height??0}})}return a}function py({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){var l,d,f;const a=[];for(const[h,g]of t){const m=(l=n.get(h))==null?void 0:l.internals.userNode;m&&a.push({...m,position:g.position,dragging:r})}if(!e)return[a[0],a];const o=(d=n.get(e))==null?void 0:d.internals.userNode;return[o?{...o,position:((f=t.get(e))==null?void 0:f.position)||o.position,dragging:r}:a[0],a]}function OG({dragItems:e,snapGrid:t,x:n,y:r}){const a=e.values().next().value;if(!a)return null;const o={x:n-a.distance.x,y:r-a.distance.y},l=sd(o,t);return{x:l.x-o.x,y:l.y-o.y}}function RG({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:a}){let o={x:null,y:null},l=0,d=new Map,f=!1,h={x:0,y:0},g=null,m=!1,y=null,b=!1,w=!1,v=null;function S({noDragClassName:C,handleSelector:N,domNode:_,isSelectable:M,nodeId:A,nodeClickDistance:O=0}){y=_r(_);function D({x:G,y:Q}){const{nodeLookup:R,nodeExtent:H,snapGrid:L,snapToGrid:V,nodeOrigin:Y,onNodeDrag:K,onSelectionDrag:z,onError:$,updateNodePositions:P}=t();o={x:G,y:Q};let I=!1;const ae=d.size>1,me=ae&&H?gb(ad(d)):null,ve=ae&&V?OG({dragItems:d,snapGrid:L,x:G,y:Q}):null;for(const[we,J]of d){if(!R.has(we))continue;let de={x:G-J.distance.x,y:Q-J.distance.y};V&&(de=ve?{x:Math.round(de.x+ve.x),y:Math.round(de.y+ve.y)}:sd(de,L));let Te=null;if(ae&&H&&!J.extent&&me){const{positionAbsolute:le}=J.internals,je=le.x-me.x+H[0][0],Me=le.x+J.measured.width-me.x2+H[1][0],ke=le.y-me.y+H[0][1],We=le.y+J.measured.height-me.y2+H[1][1];Te=[[je,ke],[Me,We]]}const{position:Ie,positionAbsolute:Oe}=AC({nodeId:we,nextPosition:de,nodeLookup:R,nodeExtent:Te||H,nodeOrigin:Y,onError:$});I=I||J.position.x!==Ie.x||J.position.y!==Ie.y,J.position=Ie,J.internals.positionAbsolute=Oe}if(w=w||I,!!I&&(P(d,!0),v&&(r||K||!A&&z))){const[we,J]=py({nodeId:A,dragItems:d,nodeLookup:R});r==null||r(v,d,we,J),K==null||K(v,we,J),A||z==null||z(v,J)}}async function U(){if(!g)return;const{transform:G,panBy:Q,autoPanSpeed:R,autoPanOnNodeDrag:H}=t();if(!H){f=!1,cancelAnimationFrame(l);return}const[L,V]=Gx(h,g,R);(L!==0||V!==0)&&(o.x=(o.x??0)-L/G[2],o.y=(o.y??0)-V/G[2],await Q({x:L,y:V})&&D(o)),l=requestAnimationFrame(U)}function B(G){var ae;const{nodeLookup:Q,multiSelectionActive:R,nodesDraggable:H,transform:L,snapGrid:V,snapToGrid:Y,selectNodesOnDrag:K,onNodeDragStart:z,onSelectionDragStart:$,unselectNodesAndEdges:P}=t();m=!0,(!K||!M)&&!R&&A&&((ae=Q.get(A))!=null&&ae.selected||P()),M&&K&&A&&(e==null||e(A));const I=bu(G.sourceEvent,{transform:L,snapGrid:V,snapToGrid:Y,containerBounds:g});if(o=I,d=DG(Q,H,I,A),d.size>0&&(n||z||!A&&$)){const[me,ve]=py({nodeId:A,dragItems:d,nodeLookup:Q});n==null||n(G.sourceEvent,d,me,ve),z==null||z(G.sourceEvent,me,ve),A||$==null||$(G.sourceEvent,ve)}}const q=lC().clickDistance(O).on("start",G=>{const{domNode:Q,nodeDragThreshold:R,transform:H,snapGrid:L,snapToGrid:V}=t();g=(Q==null?void 0:Q.getBoundingClientRect())||null,b=!1,w=!1,v=G.sourceEvent,R===0&&B(G),o=bu(G.sourceEvent,{transform:H,snapGrid:L,snapToGrid:V,containerBounds:g}),h=ci(G.sourceEvent,g)}).on("drag",G=>{const{autoPanOnNodeDrag:Q,transform:R,snapGrid:H,snapToGrid:L,nodeDragThreshold:V,nodeLookup:Y}=t(),K=bu(G.sourceEvent,{transform:R,snapGrid:H,snapToGrid:L,containerBounds:g});if(v=G.sourceEvent,(G.sourceEvent.type==="touchmove"&&G.sourceEvent.touches.length>1||A&&!Y.has(A))&&(b=!0),!b){if(!f&&Q&&m&&(f=!0,U()),!m){const z=ci(G.sourceEvent,g),$=z.x-h.x,P=z.y-h.y;Math.sqrt($*$+P*P)>V&&B(G)}(o.x!==K.xSnapped||o.y!==K.ySnapped)&&d&&m&&(h=ci(G.sourceEvent,g),D(K))}}).on("end",G=>{if(!m||b){b&&d.size>0&&t().updateNodePositions(d,!1);return}if(f=!1,m=!1,cancelAnimationFrame(l),d.size>0){const{nodeLookup:Q,updateNodePositions:R,onNodeDragStop:H,onSelectionDragStop:L}=t();if(w&&(R(d,!1),w=!1),a||H||!A&&L){const[V,Y]=py({nodeId:A,dragItems:d,nodeLookup:Q,dragging:!1});a==null||a(G.sourceEvent,d,V,Y),H==null||H(G.sourceEvent,V,Y),A||L==null||L(G.sourceEvent,Y)}}}).filter(G=>{const Q=G.target;return!G.button&&(!C||!hS(Q,`.${C}`,_))&&(!N||hS(Q,N,_))});y.call(q)}function E(){y==null||y.on(".drag",null)}return{update:S,destroy:E}}function LG(e,t,n){const r=[],a={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const o of t.values())Lh(a,Lu(o))>0&&r.push(o);return r}const IG=250;function zG(e,t,n,r){var d,f;let a=[],o=1/0;const l=LG(e,n,t+IG);for(const h of l){const g=[...((d=h.internals.handleBounds)==null?void 0:d.source)??[],...((f=h.internals.handleBounds)==null?void 0:f.target)??[]];for(const m of g){if(r.nodeId===m.nodeId&&r.type===m.type&&r.id===m.id)continue;const{x:y,y:b}=vo(h,m,m.position,!0),w=Math.sqrt(Math.pow(y-e.x,2)+Math.pow(b-e.y,2));w>t||(w<o?(a=[{...m,x:y,y:b}],o=w):w===o&&a.push({...m,x:y,y:b}))}}if(!a.length)return null;if(a.length>1){const h=r.type==="source"?"target":"source";return a.find(g=>g.type===h)??a[0]}return a[0]}function VC(e,t,n,r,a,o=!1){var h,g,m;const l=r.get(e);if(!l)return null;const d=a==="strict"?(h=l.internals.handleBounds)==null?void 0:h[t]:[...((g=l.internals.handleBounds)==null?void 0:g.source)??[],...((m=l.internals.handleBounds)==null?void 0:m.target)??[]],f=(n?d==null?void 0:d.find(y=>y.id===n):d==null?void 0:d[0])??null;return f&&o?{...f,...vo(l,f,f.position,!0)}:f}function YC(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function PG(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const QC=()=>!0;function BG(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:a,edgeUpdaterType:o,isTarget:l,domNode:d,nodeLookup:f,lib:h,autoPanOnConnect:g,flowId:m,panBy:y,cancelConnection:b,onConnectStart:w,onConnect:v,onConnectEnd:S,isValidConnection:E=QC,onReconnectEnd:C,updateConnection:N,getTransform:_,getFromHandle:M,autoPanSpeed:A,dragThreshold:O=1,handleDomNode:D}){const U=IC(e.target);let B=0,q;const{x:G,y:Q}=ci(e),R=YC(o,D),H=d==null?void 0:d.getBoundingClientRect();let L=!1;if(!H||!R)return;const V=VC(a,R,r,f,t);if(!V)return;let Y=ci(e,H),K=!1,z=null,$=!1,P=null;function I(){if(!g||!H)return;const[Ie,Oe]=Gx(Y,H,A);y({x:Ie,y:Oe}),B=requestAnimationFrame(I)}const ae={...V,nodeId:a,type:R,position:V.position},me=f.get(a);let we={inProgress:!0,isValid:null,from:vo(me,ae,He.Left,!0),fromHandle:ae,fromPosition:ae.position,fromNode:me,to:Y,toHandle:null,toPosition:tS[ae.position],toNode:null,pointer:Y};function J(){L=!0,N(we),w==null||w(e,{nodeId:a,handleId:r,handleType:R})}O===0&&J();function de(Ie){if(!L){const{x:We,y:Ue}=ci(Ie),oe=We-G,ye=Ue-Q;if(!(oe*oe+ye*ye>O*O))return;J()}if(!M()||!ae){Te(Ie);return}const Oe=_();Y=ci(Ie,H),q=zG(od(Y,Oe,!1,[1,1]),n,f,ae),K||(I(),K=!0);const le=WC(Ie,{handle:q,connectionMode:t,fromNodeId:a,fromHandleId:r,fromType:l?"target":"source",isValidConnection:E,doc:U,lib:h,flowId:m,nodeLookup:f});P=le.handleDomNode,z=le.connection,$=PG(!!q,le.isValid);const je=f.get(a),Me=je?vo(je,ae,He.Left,!0):we.from,ke={...we,from:Me,isValid:$,to:le.toHandle&&$?Gl({x:le.toHandle.x,y:le.toHandle.y},Oe):Y,toHandle:le.toHandle,toPosition:$&&le.toHandle?le.toHandle.position:tS[ae.position],toNode:le.toHandle?f.get(le.toHandle.nodeId):null,pointer:Y};N(ke),we=ke}function Te(Ie){if(!("touches"in Ie&&Ie.touches.length>0)){if(L){(q||P)&&z&&$&&(v==null||v(z));const{inProgress:Oe,...le}=we,je={...le,toPosition:we.toHandle?we.toPosition:null};S==null||S(Ie,je),o&&(C==null||C(Ie,je))}b(),cancelAnimationFrame(B),K=!1,$=!1,z=null,P=null,U.removeEventListener("mousemove",de),U.removeEventListener("mouseup",Te),U.removeEventListener("touchmove",de),U.removeEventListener("touchend",Te)}}U.addEventListener("mousemove",de),U.addEventListener("mouseup",Te),U.addEventListener("touchmove",de),U.addEventListener("touchend",Te)}function WC(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:a,fromType:o,doc:l,lib:d,flowId:f,isValidConnection:h=QC,nodeLookup:g}){const m=o==="target",y=t?l.querySelector(`.${d}-flow__handle[data-id="${f}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:b,y:w}=ci(e),v=l.elementFromPoint(b,w),S=v!=null&&v.classList.contains(`${d}-flow__handle`)?v:y,E={handleDomNode:S,isValid:!1,connection:null,toHandle:null};if(S){const C=YC(void 0,S),N=S.getAttribute("data-nodeid"),_=S.getAttribute("data-handleid"),M=S.classList.contains("connectable"),A=S.classList.contains("connectableend");if(!N||!C)return E;const O={source:m?N:r,sourceHandle:m?_:a,target:m?r:N,targetHandle:m?a:_};E.connection=O;const U=M&&A&&(n===Hl.Strict?m&&C==="source"||!m&&C==="target":N!==r||_!==a);E.isValid=U&&h(O),E.toHandle=VC(N,C,_,g,n,!0)}return E}const vb={onPointerDown:BG,isValid:WC};function $G({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const a=_r(e);function o({translateExtent:d,width:f,height:h,zoomStep:g=1,pannable:m=!0,zoomable:y=!0,inversePan:b=!1}){const w=N=>{if(N.sourceEvent.type!=="wheel"||!t)return;const _=n(),M=N.sourceEvent.ctrlKey&&Iu()?10:1,A=-N.sourceEvent.deltaY*(N.sourceEvent.deltaMode===1?.05:N.sourceEvent.deltaMode?1:.002)*g,O=_[2]*Math.pow(2,A*M);t.scaleTo(O)};let v=[0,0];const S=N=>{(N.sourceEvent.type==="mousedown"||N.sourceEvent.type==="touchstart")&&(v=[N.sourceEvent.clientX??N.sourceEvent.touches[0].clientX,N.sourceEvent.clientY??N.sourceEvent.touches[0].clientY])},E=N=>{const _=n();if(N.sourceEvent.type!=="mousemove"&&N.sourceEvent.type!=="touchmove"||!t)return;const M=[N.sourceEvent.clientX??N.sourceEvent.touches[0].clientX,N.sourceEvent.clientY??N.sourceEvent.touches[0].clientY],A=[M[0]-v[0],M[1]-v[1]];v=M;const O=r()*Math.max(_[2],Math.log(_[2]))*(b?-1:1),D={x:_[0]-A[0]*O,y:_[1]-A[1]*O},U=[[0,0],[f,h]];t.setViewportConstrained({x:D.x,y:D.y,zoom:_[2]},U,d)},C=EC().on("start",S).on("zoom",m?E:null).on("zoom.wheel",y?w:null);a.call(C,{})}function l(){a.on("zoom",null)}return{update:o,destroy:l,pointer:si}}const gp=e=>({x:e.x,y:e.y,zoom:e.k}),my=({x:e,y:t,zoom:n})=>hp.translate(e,t).scale(n),xl=(e,t)=>e.target.closest(`.${t}`),XC=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),UG=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,gy=(e,t=0,n=UG,r=()=>{})=>{const a=typeof t=="number"&&t>0;return a||r(),a?e.transition().duration(t).ease(n).on("end",r):e},ZC=e=>{const t=e.ctrlKey&&Iu()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function FG({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:a,panOnScrollSpeed:o,zoomOnPinch:l,onPanZoomStart:d,onPanZoom:f,onPanZoomEnd:h}){return g=>{if(xl(g,t))return g.ctrlKey&&g.preventDefault(),!1;g.preventDefault(),g.stopImmediatePropagation();const m=n.property("__zoom").k||1;if(g.ctrlKey&&l){const S=si(g),E=ZC(g),C=m*Math.pow(2,E);r.scaleTo(n,C,S,g);return}const y=g.deltaMode===1?20:1;let b=a===uo.Vertical?0:g.deltaX*y,w=a===uo.Horizontal?0:g.deltaY*y;!Iu()&&g.shiftKey&&a!==uo.Vertical&&(b=g.deltaY*y,w=0),r.translateBy(n,-(b/m)*o,-(w/m)*o,{internal:!0});const v=gp(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(f==null||f(g,v),e.panScrollTimeout=setTimeout(()=>{h==null||h(g,v),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,d==null||d(g,v))}}function qG({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,a){const o=r.type==="wheel",l=!t&&o&&!r.ctrlKey,d=xl(r,e);if(r.ctrlKey&&o&&d&&r.preventDefault(),l||d)return null;r.preventDefault(),n.call(this,r,a)}}function HG({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{var o,l,d;if((o=r.sourceEvent)!=null&&o.internal)return;const a=gp(r.transform);e.mouseButton=((l=r.sourceEvent)==null?void 0:l.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=a,((d=r.sourceEvent)==null?void 0:d.type)==="mousedown"&&t(!0),n&&(n==null||n(r.sourceEvent,a))}}function KG({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:a}){return o=>{var l,d;e.usedRightMouseButton=!!(n&&XC(t,e.mouseButton??0)),(l=o.sourceEvent)!=null&&l.sync||r([o.transform.x,o.transform.y,o.transform.k]),a&&!((d=o.sourceEvent)!=null&&d.internal)&&(a==null||a(o.sourceEvent,gp(o.transform)))}}function GG({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:a,onPaneContextMenu:o}){return l=>{var d;if(!((d=l.sourceEvent)!=null&&d.internal)&&(e.isZoomingOrPanning=!1,o&&XC(t,e.mouseButton??0)&&!e.usedRightMouseButton&&l.sourceEvent&&o(l.sourceEvent),e.usedRightMouseButton=!1,r(!1),a)){const f=gp(l.transform);e.prevViewport=f,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{a==null||a(l.sourceEvent,f)},n?150:0)}}}function VG({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:a,zoomOnDoubleClick:o,userSelectionActive:l,noWheelClassName:d,noPanClassName:f,lib:h,connectionInProgress:g}){return m=>{var S;const y=e||t,b=n&&m.ctrlKey,w=m.type==="wheel";if(m.button===1&&m.type==="mousedown"&&(xl(m,`${h}-flow__node`)||xl(m,`${h}-flow__edge`)))return!0;if(!r&&!y&&!a&&!o&&!n||l||g&&!w||xl(m,d)&&w||xl(m,f)&&(!w||a&&w&&!e)||!n&&m.ctrlKey&&w)return!1;if(!n&&m.type==="touchstart"&&((S=m.touches)==null?void 0:S.length)>1)return m.preventDefault(),!1;if(!y&&!a&&!b&&w||!r&&(m.type==="mousedown"||m.type==="touchstart")||Array.isArray(r)&&!r.includes(m.button)&&m.type==="mousedown")return!1;const v=Array.isArray(r)&&r.includes(m.button)||!m.button||m.button<=1;return(!m.ctrlKey||w)&&v}}function YG({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:a,onPanZoom:o,onPanZoomStart:l,onPanZoomEnd:d,onDraggingChange:f}){const h={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},g=e.getBoundingClientRect(),m=EC().scaleExtent([t,n]).translateExtent(r),y=_r(e).call(m);C({x:a.x,y:a.y,zoom:Kl(a.zoom,t,n)},[[0,0],[g.width,g.height]],r);const b=y.on("wheel.zoom"),w=y.on("dblclick.zoom");m.wheelDelta(ZC);async function v(q,G){return y?new Promise(Q=>{m==null||m.interpolate((G==null?void 0:G.interpolate)==="linear"?yu:ih).transform(gy(y,G==null?void 0:G.duration,G==null?void 0:G.ease,()=>Q(!0)),q)}):!1}function S({noWheelClassName:q,noPanClassName:G,onPaneContextMenu:Q,userSelectionActive:R,panOnScroll:H,panOnDrag:L,panOnScrollMode:V,panOnScrollSpeed:Y,preventScrolling:K,zoomOnPinch:z,zoomOnScroll:$,zoomOnDoubleClick:P,zoomActivationKeyPressed:I,lib:ae,onTransformChange:me,connectionInProgress:ve,paneClickDistance:we,selectionOnDrag:J}){R&&!h.isZoomingOrPanning&&E();const de=H&&!I&&!R;m.clickDistance(J?1/0:!li(we)||we<0?0:we);const Te=de?FG({zoomPanValues:h,noWheelClassName:q,d3Selection:y,d3Zoom:m,panOnScrollMode:V,panOnScrollSpeed:Y,zoomOnPinch:z,onPanZoomStart:l,onPanZoom:o,onPanZoomEnd:d}):qG({noWheelClassName:q,preventScrolling:K,d3ZoomHandler:b});y.on("wheel.zoom",Te,{passive:!1});const Ie=HG({zoomPanValues:h,onDraggingChange:f,onPanZoomStart:l});m.on("start",Ie);const Oe=KG({zoomPanValues:h,panOnDrag:L,onPaneContextMenu:!!Q,onPanZoom:o,onTransformChange:me});m.on("zoom",Oe);const le=GG({zoomPanValues:h,panOnDrag:L,panOnScroll:H,onPaneContextMenu:Q,onPanZoomEnd:d,onDraggingChange:f});m.on("end",le);const je=VG({zoomActivationKeyPressed:I,panOnDrag:L,zoomOnScroll:$,panOnScroll:H,zoomOnDoubleClick:P,zoomOnPinch:z,userSelectionActive:R,noPanClassName:G,noWheelClassName:q,lib:ae,connectionInProgress:ve});m.filter(je),P?y.on("dblclick.zoom",w):y.on("dblclick.zoom",null)}function E(){m.on("zoom",null)}async function C(q,G,Q){const R=my(q),H=m==null?void 0:m.constrain()(R,G,Q);return H&&await v(H),H}async function N(q,G){const Q=my(q);return await v(Q,G),Q}function _(q){if(y){const G=my(q),Q=y.property("__zoom");(Q.k!==q.zoom||Q.x!==q.x||Q.y!==q.y)&&(m==null||m.transform(y,G,null,{sync:!0}))}}function M(){const q=y?kC(y.node()):{x:0,y:0,k:1};return{x:q.x,y:q.y,zoom:q.k}}async function A(q,G){return y?new Promise(Q=>{m==null||m.interpolate((G==null?void 0:G.interpolate)==="linear"?yu:ih).scaleTo(gy(y,G==null?void 0:G.duration,G==null?void 0:G.ease,()=>Q(!0)),q)}):!1}async function O(q,G){return y?new Promise(Q=>{m==null||m.interpolate((G==null?void 0:G.interpolate)==="linear"?yu:ih).scaleBy(gy(y,G==null?void 0:G.duration,G==null?void 0:G.ease,()=>Q(!0)),q)}):!1}function D(q){m==null||m.scaleExtent(q)}function U(q){m==null||m.translateExtent(q)}function B(q){const G=!li(q)||q<0?0:q;m==null||m.clickDistance(G)}return{update:S,destroy:E,setViewport:N,setViewportConstrained:C,getViewport:M,scaleTo:A,scaleBy:O,setScaleExtent:D,setTranslateExtent:U,syncViewport:_,setClickDistance:B}}var Vl;(function(e){e.Line="line",e.Handle="handle"})(Vl||(Vl={}));function QG({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:a,affectsY:o}){const l=e-t,d=n-r,f=[l>0?1:l<0?-1:0,d>0?1:d<0?-1:0];return l&&a&&(f[0]=f[0]*-1),d&&o&&(f[1]=f[1]*-1),f}function pS(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),a=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:a}}function rs(e,t){return Math.max(0,t-e)}function is(e,t){return Math.max(0,e-t)}function Gf(e,t,n){return Math.max(0,t-e,e-n)}function mS(e,t){return e?!t:t}function WG(e,t,n,r,a,o,l,d){let{affectsX:f,affectsY:h}=t;const{isHorizontal:g,isVertical:m}=t,y=g&&m,{xSnapped:b,ySnapped:w}=n,{minWidth:v,maxWidth:S,minHeight:E,maxHeight:C}=r,{x:N,y:_,width:M,height:A,aspectRatio:O}=e;let D=Math.floor(g?b-e.pointerX:0),U=Math.floor(m?w-e.pointerY:0);const B=M+(f?-D:D),q=A+(h?-U:U),G=-o[0]*M,Q=-o[1]*A;let R=Gf(B,v,S),H=Gf(q,E,C);if(l){let Y=0,K=0;f&&D<0?Y=rs(N+D+G,l[0][0]):!f&&D>0&&(Y=is(N+B+G,l[1][0])),h&&U<0?K=rs(_+U+Q,l[0][1]):!h&&U>0&&(K=is(_+q+Q,l[1][1])),R=Math.max(R,Y),H=Math.max(H,K)}if(d){let Y=0,K=0;f&&D>0?Y=is(N+D,d[0][0]):!f&&D<0&&(Y=rs(N+B,d[1][0])),h&&U>0?K=is(_+U,d[0][1]):!h&&U<0&&(K=rs(_+q,d[1][1])),R=Math.max(R,Y),H=Math.max(H,K)}if(a){if(g){const Y=Gf(B/O,E,C)*O;if(R=Math.max(R,Y),l){let K=0;!f&&!h||f&&!h&&y?K=is(_+Q+B/O,l[1][1])*O:K=rs(_+Q+(f?D:-D)/O,l[0][1])*O,R=Math.max(R,K)}if(d){let K=0;!f&&!h||f&&!h&&y?K=rs(_+B/O,d[1][1])*O:K=is(_+(f?D:-D)/O,d[0][1])*O,R=Math.max(R,K)}}if(m){const Y=Gf(q*O,v,S)/O;if(H=Math.max(H,Y),l){let K=0;!f&&!h||h&&!f&&y?K=is(N+q*O+G,l[1][0])/O:K=rs(N+(h?U:-U)*O+G,l[0][0])/O,H=Math.max(H,K)}if(d){let K=0;!f&&!h||h&&!f&&y?K=rs(N+q*O,d[1][0])/O:K=is(N+(h?U:-U)*O,d[0][0])/O,H=Math.max(H,K)}}}U=U+(U<0?H:-H),D=D+(D<0?R:-R),a&&(y?B>q*O?U=(mS(f,h)?-D:D)/O:D=(mS(f,h)?-U:U)*O:g?(U=D/O,h=f):(D=U*O,f=h));const L=f?N+D:N,V=h?_+U:_;return{width:M+(f?-D:D),height:A+(h?-U:U),x:o[0]*D*(f?-1:1)+L,y:o[1]*U*(h?-1:1)+V}}const JC={width:0,height:0,x:0,y:0},XG={...JC,pointerX:0,pointerY:0,aspectRatio:1};function ZG(e,t,n){const r=t.position.x+e.position.x,a=t.position.y+e.position.y,o=e.measured.width??0,l=e.measured.height??0,d=n[0]*o,f=n[1]*l;return[[r-d,a-f],[r+o-d,a+l-f]]}function JG({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:a}){const o=_r(e);let l={controlDirection:pS("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function d({controlPosition:h,boundaries:g,keepAspectRatio:m,resizeDirection:y,onResizeStart:b,onResize:w,onResizeEnd:v,shouldResize:S}){let E={...JC},C={...XG};l={boundaries:g,resizeDirection:y,keepAspectRatio:m,controlDirection:pS(h)};let N,_=null,M=[],A,O,D,U=!1;const B=lC().on("start",q=>{const{nodeLookup:G,transform:Q,snapGrid:R,snapToGrid:H,nodeOrigin:L,paneDomNode:V}=n();if(N=G.get(t),!N)return;_=(V==null?void 0:V.getBoundingClientRect())??null;const{xSnapped:Y,ySnapped:K}=bu(q.sourceEvent,{transform:Q,snapGrid:R,snapToGrid:H,containerBounds:_});E={width:N.measured.width??0,height:N.measured.height??0,x:N.position.x??0,y:N.position.y??0},C={...E,pointerX:Y,pointerY:K,aspectRatio:E.width/E.height},A=void 0,O=xo(N.extent)?N.extent:void 0,N.parentId&&(N.extent==="parent"||N.expandParent)&&(A=G.get(N.parentId)),A&&N.extent==="parent"&&(O=[[0,0],[A.measured.width,A.measured.height]]),M=[],D=void 0;for(const[z,$]of G)if($.parentId===t&&(M.push({id:z,position:{...$.position},extent:$.extent}),$.extent==="parent"||$.expandParent)){const P=ZG($,N,$.origin??L);D?D=[[Math.min(P[0][0],D[0][0]),Math.min(P[0][1],D[0][1])],[Math.max(P[1][0],D[1][0]),Math.max(P[1][1],D[1][1])]]:D=P}b==null||b(q,{...E})}).on("drag",q=>{const{transform:G,snapGrid:Q,snapToGrid:R,nodeOrigin:H}=n(),L=bu(q.sourceEvent,{transform:G,snapGrid:Q,snapToGrid:R,containerBounds:_}),V=[];if(!N)return;const{x:Y,y:K,width:z,height:$}=E,P={},I=N.origin??H,{width:ae,height:me,x:ve,y:we}=WG(C,l.controlDirection,L,l.boundaries,l.keepAspectRatio,I,O,D),J=ae!==z,de=me!==$,Te=ve!==Y&&J,Ie=we!==K&&de;if(!Te&&!Ie&&!J&&!de)return;if((Te||Ie||I[0]===1||I[1]===1)&&(P.x=Te?ve:E.x,P.y=Ie?we:E.y,E.x=P.x,E.y=P.y,M.length>0)){const Me=ve-Y,ke=we-K;for(const We of M)We.position={x:We.position.x-Me+I[0]*(ae-z),y:We.position.y-ke+I[1]*(me-$)},V.push(We)}if((J||de)&&(P.width=J&&(!l.resizeDirection||l.resizeDirection==="horizontal")?ae:E.width,P.height=de&&(!l.resizeDirection||l.resizeDirection==="vertical")?me:E.height,E.width=P.width,E.height=P.height),A&&N.expandParent){const Me=I[0]*(P.width??0);P.x&&P.x<Me&&(E.x=Me,C.x=C.x-(P.x-Me));const ke=I[1]*(P.height??0);P.y&&P.y<ke&&(E.y=ke,C.y=C.y-(P.y-ke))}const Oe=QG({width:E.width,prevWidth:z,height:E.height,prevHeight:$,affectsX:l.controlDirection.affectsX,affectsY:l.controlDirection.affectsY}),le={...E,direction:Oe};(S==null?void 0:S(q,le))!==!1&&(U=!0,w==null||w(q,le),r(P,V))}).on("end",q=>{U&&(v==null||v(q,{...E}),a==null||a({...E}),U=!1)});o.call(B)}function f(){o.on(".drag",null)}return{update:d,destroy:f}}var yy={exports:{}},by={},xy={exports:{}},vy={};/**
|
|
648
|
+
…(truncated)`:m)}).catch(m=>{g||d(m instanceof Error?m.message:String(m))}),()=>{g=!0}},[e,t]);const f=Yy(e,t),h=t.split(/[\\/]/).pop()??t;return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-[rgba(45,55,72,0.6)] p-4",role:"presentation",children:c.jsxs("div",{className:"nb-card bg-[var(--color-bg)] max-w-3xl w-full p-5 flex flex-col",style:{maxHeight:"85vh"},role:"dialog","aria-modal":"true","aria-label":r("chat.attachment.preview.aria",{name:h}),children:[c.jsxs("header",{className:"flex items-center justify-between mb-3 shrink-0",children:[c.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[c.jsx(WR,{size:16,strokeWidth:2.5,className:"flex-shrink-0"}),c.jsx("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base truncate",children:h})]}),c.jsx("button",{type:"button",className:"p-1 hover:bg-[var(--color-bg-cream)] rounded flex-shrink-0",onClick:n,"aria-label":r("chat.attachment.close.aria"),children:c.jsx(Sn,{size:16,strokeWidth:3})})]}),c.jsx("p",{className:"text-[10px] text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] truncate mb-2 shrink-0",title:t,dir:"rtl",children:t}),c.jsxs("div",{className:"flex-1 overflow-auto border-2 border-[var(--color-text)] rounded-lg bg-[var(--color-bg-cream)] min-h-0",children:[Nh(t)&&c.jsx("div",{className:"flex items-center justify-center p-4",children:c.jsx("img",{src:f,alt:`Preview: ${h}`,className:"max-w-full max-h-[60vh] object-contain"})}),ME(t)&&c.jsx("iframe",{src:f,title:`PDF: ${h}`,className:"w-full",style:{height:"60vh",border:0}}),ly(t)&&c.jsx("pre",{className:"p-3 text-xs font-[family-name:var(--font-mono)] whitespace-pre-wrap break-words",children:l?c.jsx("span",{className:"text-[var(--color-crashed)]",children:r("chat.attachment.readErr",{detail:l})}):a===null?c.jsx("span",{className:"text-[var(--color-text-muted)]",children:r("chat.attachment.loading")}):a}),!Nh(t)&&!ME(t)&&!ly(t)&&c.jsxs("div",{className:"p-6 text-center text-sm text-[var(--color-text-muted)]",children:[c.jsx("p",{className:"mb-3",children:r("chat.attachment.unsupported")}),c.jsx("a",{href:f,download:h,className:"nb-btn nb-btn-primary inline-flex",children:r("chat.attachment.download")})]})]})]})})}function B8({onCancel:e,onCreate:t}){var N;const n=Pe(),[r,a]=j.useState(""),[o,l]=j.useState(""),[d,f]=j.useState(""),[h,g]=j.useState(!1),[m,y]=j.useState(!1),[b,w]=j.useState(!1),v=Ye({queryKey:["providers"],queryFn:lx}),S=Ye({queryKey:["system-agents"],queryFn:Hb}),E=l2(((N=v.data)==null?void 0:N.anthropic)??[]);j.useEffect(()=>{var A;if(h)return;const _=(A=S.data)==null?void 0:A.agents.worker;if(!_)return;const M=`${_.providerId||"official"}::${_.model}`;E.some(O=>`${O.providerId}::${O.model}`===M)&&f(M)},[S.data,E,h]),j.useEffect(()=>{if(b)return;const _=M=>{M.key==="Escape"&&(M.preventDefault(),e())};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[e,b]);const C=async()=>{if(!m){y(!0);try{const[_,M]=d?d.split("::"):[void 0,void 0];t({title:r.trim()||void 0,cwd:o.trim()||void 0,agentKind:"claude",model:M,providerId:_})}finally{y(!1)}}};return c.jsxs("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-[rgba(45,55,72,0.4)] p-4",role:"presentation",children:[c.jsxs("div",{className:"nb-card bg-[var(--color-bg)] max-w-md w-full p-5",role:"dialog","aria-modal":"true","aria-label":n("chat.newSession.title.aria"),children:[c.jsxs("header",{className:"flex items-center justify-between mb-4",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:n("chat.newSession.title")}),c.jsx("button",{type:"button",className:"p-1 hover:bg-[var(--color-bg-cream)] rounded",onClick:e,"aria-label":n("chat.newSession.close.aria"),children:c.jsx(Sn,{size:16,strokeWidth:3})})]}),c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{htmlFor:"new-session-model",className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.model")}),c.jsxs("select",{id:"new-session-model",className:"nb-input w-full font-[family-name:var(--font-mono)] text-sm",value:d,onChange:_=>{g(!0),f(_.target.value)},children:[c.jsx("option",{value:"",children:n("chat.newSession.field.model.default")}),E.map(_=>c.jsx("option",{value:`${_.providerId}::${_.model}`,children:_.label},`${_.providerId}::${_.model}`))]})]}),c.jsxs("div",{children:[c.jsx("label",{htmlFor:"new-session-title",className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.title")}),c.jsx("input",{id:"new-session-title",type:"text",className:"nb-input w-full",placeholder:n("chat.newSession.field.title.placeholder"),value:r,onChange:_=>a(_.target.value),autoFocus:!0})]}),c.jsxs("div",{children:[c.jsx("label",{htmlFor:"new-session-cwd",className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.cwd")}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{id:"new-session-cwd",type:"text",className:"nb-input flex-1 font-[family-name:var(--font-mono)] text-sm",placeholder:"/home/coral/projects/my-app",value:o,onChange:_=>l(_.target.value)}),c.jsxs("button",{type:"button",className:"nb-btn flex-shrink-0",onClick:()=>w(!0),"aria-label":n("chat.newSession.field.cwd.browseAria"),title:n("chat.newSession.field.cwd.browseAria"),children:[c.jsx(HN,{size:14,strokeWidth:2.5}),n("chat.newSession.field.cwd.browse")]})]}),c.jsxs("p",{className:"text-[11px] text-[var(--color-text-muted)] mt-1.5 leading-relaxed",children:[c.jsx(ph,{size:10,strokeWidth:2.5,className:"inline mr-1 -mt-0.5"}),n("chat.newSession.field.cwd.help1")," ",n("chat.newSession.field.cwd.help2")]})]}),c.jsxs("div",{className:"flex gap-2 justify-end pt-2",children:[c.jsx("button",{type:"button",className:"nb-btn",onClick:e,children:n("chat.newSession.cancel")}),c.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary",onClick:C,disabled:m,children:[m?c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):c.jsx(pr,{size:14,strokeWidth:3}),n("chat.newSession.create")]})]})]})]}),b&&c.jsx(cx,{initialPath:o.trim()||void 0,onCancel:()=>w(!1),onSelect:_=>{l(_),w(!1)}})]})}function $8({msg:e,sessionId:t,onPreviewAttachment:n}){const r=Pe(),a=e.role==="user",o=e.role==="error",l=e.blocks&&e.blocks.length>0?e.blocks:[{type:"text",text:e.content}],d=e.attachments??[];return c.jsx("div",{className:a?"self-end max-w-3xl":"self-start max-w-3xl",children:c.jsxs("div",{className:["nb-card",a?"bg-[var(--color-secondary)]":o?"bg-[var(--color-crashed-bg)]":"bg-[var(--color-bg)]"].join(" "),children:[c.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-2 flex items-center gap-2",children:[r(a?"chat.message.role.you":o?"chat.message.role.error":"chat.message.role.assistant"),c.jsx("span",{className:"font-normal",children:"·"}),c.jsx("span",{className:"font-normal cursor-help",title:K8(e.ts),children:Vj(e.ts,r)})]}),c.jsx("div",{className:"flex flex-col gap-2",children:l.map((f,h)=>c.jsx(q8,{block:f},h))}),d.length>0&&t&&c.jsx("div",{className:"mt-3 pt-3 border-t-2 border-dashed border-[var(--color-text)]/30 flex flex-wrap gap-2",children:d.map(f=>c.jsx(U8,{sessionId:t,path:f,onPreview:()=>n(f)},f))}),e.truncated&&c.jsx("p",{className:"mt-3 px-3 py-2 bg-[var(--color-stuck-bg)] border-2 border-[var(--color-stuck)] rounded-lg text-xs text-[var(--color-stuck)] font-bold",children:r("chat.message.truncated")})]})})}function U8({sessionId:e,path:t,onPreview:n}){const r=Pe(),a=t.split(/[\\/]/).pop()??t;return Nh(t)?c.jsx("button",{type:"button",onClick:n,className:"block rounded-md overflow-hidden border-2 border-[var(--color-text)] hover:shadow-[2px_2px_0_var(--color-text)] transition-shadow",title:r("chat.attachment.previewSimpleTooltip",{name:a}),children:c.jsx("img",{src:Yy(e,t),alt:a,className:"block max-h-40 max-w-[12rem] object-cover",loading:"lazy"})}):c.jsxs("button",{type:"button",onClick:n,className:"flex items-center gap-1.5 px-2 py-1 rounded-md bg-[var(--color-bg)] border-2 border-[var(--color-text)] text-xs font-[family-name:var(--font-mono)] hover:bg-[var(--color-accent-mint)]",title:r("chat.attachment.previewTooltip",{name:a,path:t}),children:[c.jsx(Fh,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}),c.jsx("span",{className:"truncate max-w-[200px]",children:a})]})}function F8({pending:e}){const t=(()=>{for(let n=e.blocks.length-1;n>=0;n--)if(e.blocks[n].type==="text")return n;return-1})();return c.jsx("div",{className:"self-start max-w-3xl",children:c.jsxs("div",{className:"nb-card bg-[var(--color-bg)]",children:[c.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-2 flex items-center gap-2",children:["assistant",c.jsx("span",{className:"font-normal",children:"·"}),c.jsxs("span",{className:"flex items-center gap-1 font-normal text-[var(--color-running)]",children:[c.jsx(Xe,{size:10,strokeWidth:3,className:"animate-spin"}),"streaming"]})]}),c.jsxs("div",{className:"flex flex-col gap-2",children:[e.blocks.length===0&&c.jsx("p",{className:"text-sm text-[var(--color-text-muted)] italic",children:"…"}),e.blocks.map((n,r)=>{if(n.type==="text"){const a=r===t;return c.jsxs("div",{className:"relative",children:[c.jsx(Kj,{text:n.displayed}),a&&c.jsx("span",{className:"inline-block w-2 h-4 ml-1 bg-[var(--color-text)] animate-pulse align-middle"})]},r)}return c.jsx(Gj,{tool:n},r)})]})]})})}function q8({block:e}){return e.type==="text"?c.jsx(Kj,{text:e.text}):c.jsx(Gj,{tool:e})}function Kj({text:e}){return e?c.jsx("div",{className:"text-sm font-[family-name:var(--font-body)] break-words prose-chat",children:c.jsx(Cx,{remarkPlugins:[Dx],rehypePlugins:[Lx],children:e})}):null}function H8(e){if(e==null||typeof e!="object")return typeof e=="string"?e:"";const t=e,n=a=>typeof t[a]=="string"?t[a]:void 0;return n("file_path")??n("path")??n("notebook_path")??n("command")??n("pattern")??n("query")??n("url")??n("name")??n("description")??n("prompt")??Object.values(t).find(a=>typeof a=="string"&&a.trim())??""}function Gj({tool:e}){const[t,n]=j.useState(!1),r=e.status==="completed"||e.status==="complete",a=e.status==="failed",o=!r&&!a,l=H8(e.input),d=e.input!=null&&(typeof e.input!="object"||Object.keys(e.input).length>0);return c.jsxs("div",{className:"border-2 border-[var(--color-text)] rounded-lg overflow-hidden bg-[var(--color-bg-cream)]",children:[c.jsxs("button",{type:"button",onClick:()=>n(f=>!f),className:"w-full flex items-center gap-2 px-3 py-2 text-xs font-[family-name:var(--font-mono)] hover:bg-[var(--color-accent-yellow)] transition-colors",children:[c.jsx(Zl,{size:12,strokeWidth:3,className:["transition-transform flex-shrink-0",t?"rotate-90":""].join(" ")}),c.jsx(n_,{size:12,strokeWidth:2.5,className:"flex-shrink-0"}),c.jsx("span",{className:"font-bold flex-shrink-0",children:e.title||e.kind}),c.jsx("span",{className:"flex-1 text-left text-[var(--color-text-muted)] truncate",title:l,children:l}),o&&c.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin text-[var(--color-running)] flex-shrink-0"}),r&&c.jsx(Eu,{size:12,strokeWidth:2.5,className:"text-[var(--color-running)] flex-shrink-0"}),a&&c.jsx(FN,{size:12,strokeWidth:2.5,className:"text-[var(--color-crashed)] flex-shrink-0"})]}),t&&c.jsxs("div",{className:"px-3 py-2 text-xs font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] border-t-2 border-[var(--color-text)] space-y-1",children:[d?c.jsx("pre",{className:"whitespace-pre-wrap break-all text-[var(--color-text)] max-h-72 overflow-auto",children:typeof e.input=="string"?e.input:JSON.stringify(e.input,null,2)}):c.jsx("div",{children:"无参数"}),c.jsxs("div",{className:"opacity-60",children:["id: ",e.id," · ",e.status]})]})]})}function Vj(e,t){if(!e)return"";const n=new Date(e),r=Date.now()-n.getTime();return r<6e4?t("kanban.time.justNow"):r<36e5?t("kanban.time.minutes",{n:Math.floor(r/6e4)}):r<864e5?t("kanban.time.hours",{n:Math.floor(r/36e5)}):n.toLocaleDateString()}function K8(e){if(!e)return;const t=new Date(e),n=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}function G8(){return ht("/api/processes").then(e=>e.data)}function V8(e){return Ri(`/api/processes/${e}/kill`)}function Y8(){return ht("/api/processes/reclaim")}async function Q8(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 DE="border-[3px] border-[var(--color-text)] rounded-2xl bg-white shadow-[4px_4px_0_var(--color-text)]";function W8(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 r=Math.floor(n/60);return r<24?`${r}h${n%60?` ${n%60}m`:""}`:`${Math.floor(r/24)}d${r%24?` ${r%24}h`:""}`}function cy(e){return e.project?e.project:e.cwd?e.cwd.split("/").filter(Boolean).pop()??e.slot:e.slot}function OE(e){const t=/^session-chat-(.+)$/.exec(e.slot);return(t==null?void 0:t[1])??null}function X8({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 c.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] text-xs font-bold font-[family-name:var(--font-mono)] ${n}`,children:[c.jsx("span",{className:`w-2 h-2 rounded-full ${e.alive?"bg-green-600":"bg-gray-400"}`}),t]})}function Z8(){var w;const e=Pe(),t=Gt(),[n,r]=j.useState(null),[a,o]=j.useState("all"),l=Ye({queryKey:["processes"],queryFn:G8,refetchInterval:5e3}),d=Ct({mutationFn:V8,onSuccess:v=>{r(v.message),t.invalidateQueries({queryKey:["processes"]})},onError:v=>r(v instanceof Error?v.message:String(v))}),f=Ye({queryKey:["reclaim"],queryFn:Y8}),[h,g]=j.useState("");j.useEffect(()=>{f.data&&h===""&&g(String(f.data.idleMinutes))},[f.data,h]);const m=Ct({mutationFn:v=>Q8(v),onSuccess:v=>{r(`自动回收已设为 ${v.idleMinutes} 分钟空闲`),t.invalidateQueries({queryKey:["reclaim"]})},onError:v=>r(v instanceof Error?v.message:String(v))}),y=l.data??[],b=y.filter(v=>a==="all"?!0:v.kind===a);return c.jsxs("div",{className:"max-w-full",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[c.jsx(hh,{size:22,strokeWidth:2.5}),c.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl",children:e("processes.title")}),c.jsxs("button",{type:"button","aria-label":e("processes.refresh"),onClick:()=>t.invalidateQueries({queryKey:["processes"]}),className:"ml-auto inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl border-2 border-[var(--color-text)] bg-white text-sm font-semibold shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px focus-visible:outline focus-visible:outline-2",children:[l.isFetching?c.jsx(Xe,{size:15,className:"animate-spin"}):c.jsx(ya,{size:15}),e("processes.refresh")]})]}),c.jsxs("p",{className:"text-sm text-[var(--color-text)]/70 mb-3",children:[e("processes.subtitle")," · ",e("processes.aliveCount").replace("{n}",String(y.length))]}),c.jsxs("div",{className:`${DE} px-4 py-3 mb-4 flex flex-wrap items-center gap-2`,style:{boxShadow:"2px 2px 0 var(--color-text)"},children:[c.jsx(c3,{size:16,strokeWidth:2.5}),c.jsx("span",{className:"text-sm font-bold",children:"自动回收"}),c.jsx("span",{className:"text-sm text-[var(--color-text)]/70",children:"会话空闲"}),c.jsx("input",{type:"number",min:1,max:1440,value:h,onChange:v=>g(v.target.value),className:"w-20 px-2 py-1 rounded-lg border-2 border-[var(--color-text)] font-[family-name:var(--font-mono)] text-sm","aria-label":"自动回收空闲分钟数"}),c.jsx("span",{className:"text-sm text-[var(--color-text)]/70",children:"分钟后自动停(下次访问自动续上,不丢上下文)"}),c.jsxs("button",{type:"button",disabled:m.isPending||h===""||Number(h)===((w=f.data)==null?void 0:w.idleMinutes),onClick:()=>m.mutate(Math.round(Number(h))),className:"ml-auto inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border-2 border-[var(--color-text)] bg-[var(--color-accent-mint)] text-sm font-bold shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px disabled:opacity-50 focus-visible:outline focus-visible:outline-2","aria-label":"保存自动回收设置",children:[m.isPending?c.jsx(Xe,{size:14,className:"animate-spin"}):c.jsx(Oi,{size:14,strokeWidth:3}),"保存"]})]}),n&&c.jsx("div",{className:"mb-3 px-3 py-2 rounded-xl border-2 border-[var(--color-text)] bg-[var(--color-bg-cream)] text-sm font-mono",children:n}),c.jsx("div",{className:"flex flex-wrap gap-2 mb-3 items-center",children:["all","worker","chat"].map(v=>c.jsx("button",{type:"button","aria-label":e(`processes.kind.${v}`),onClick:()=>o(v),className:`px-3 py-1 rounded-lg border-2 border-[var(--color-text)] text-sm font-bold shadow-[2px_2px_0_var(--color-text)] focus-visible:outline focus-visible:outline-2 ${a===v?"bg-[var(--color-accent-yellow)]":"bg-white hover:-translate-x-px hover:-translate-y-px"}`,children:e(`processes.kind.${v}`)},v))}),c.jsx("div",{className:`${DE} overflow-hidden`,children:c.jsxs("table",{className:"w-full text-sm",children:[c.jsx("thead",{className:"bg-[var(--color-bg-cream)] font-[family-name:var(--font-heading)]",children:c.jsxs("tr",{className:"text-left",children:[c.jsx("th",{className:"px-3 py-2",children:e("processes.col.kind")}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.slot")}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.project")}),c.jsx("th",{className:"px-3 py-2",children:"PID"}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.state")}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.memory")}),c.jsx("th",{className:"px-3 py-2",children:"运行时间"}),c.jsx("th",{className:"px-3 py-2",children:e("processes.col.action")})]})}),c.jsxs("tbody",{className:"font-[family-name:var(--font-mono)]",children:[b.length===0&&c.jsx("tr",{children:c.jsx("td",{colSpan:8,className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:e("processes.empty")})}),b.map(v=>c.jsxs("tr",{className:"border-t-2 border-[var(--color-text)]/10",title:v.cwd??"",children:[c.jsx("td",{className:"px-3 py-2",children:c.jsx("span",{className:`inline-block px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] text-xs font-bold ${v.kind==="worker"?"bg-[var(--color-accent-yellow)]":"bg-[var(--color-accent-purple)]"}`,children:e(`processes.kind.${v.kind}`)})}),c.jsx("td",{className:"px-3 py-2 max-w-[220px] truncate",children:v.slot}),c.jsx("td",{className:"px-3 py-2 max-w-[220px] truncate",children:v.kind==="chat"&&OE(v)?c.jsxs(xs,{to:`/chat/${OE(v)}`,className:"inline-flex items-center gap-1 font-semibold text-[var(--color-text)] underline decoration-2 underline-offset-2 hover:opacity-70",title:"打开对话窗口",children:[c.jsx(GN,{size:12,strokeWidth:2.5})," ",cy(v)]}):v.kind==="worker"&&v.project?c.jsxs(xs,{to:`/board?project=${encodeURIComponent(v.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:[c.jsx(hh,{size:12,strokeWidth:2.5})," ",cy(v)]}):c.jsx("span",{children:cy(v)})}),c.jsx("td",{className:"px-3 py-2",children:v.pid??"—"}),c.jsx("td",{className:"px-3 py-2",children:c.jsx(X8,{p:v})}),c.jsx("td",{className:"px-3 py-2",children:v.memoryMB!=null?`${v.memoryMB} MB`:"—"}),c.jsx("td",{className:"px-3 py-2",children:W8(v.startedAt)}),c.jsx("td",{className:"px-3 py-2",children:v.alive&&v.pid!=null?c.jsxs("button",{type:"button","aria-label":`${e("processes.kill")} ${v.slot}`,onClick:()=>{confirm(e("processes.killConfirm").replace("{slot}",v.slot))&&d.mutate(v.pid)},className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-lg border-2 border-[var(--color-text)] bg-[var(--color-accent-pink)] text-xs font-bold shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px active:translate-x-0.5 active:translate-y-0.5 focus-visible:outline focus-visible:outline-2",children:[c.jsx(FN,{size:13})," ",e("processes.kill")]}):c.jsx("span",{className:"text-[var(--color-text)]/40 text-xs",children:"—"})})]},v.slot))]})]})})]})}function J8(e={}){const t=new URLSearchParams;e.project&&t.set("project",e.project),e.action&&t.set("action",e.action);const n=t.toString();return ht(`/api/audit${n?`?${n}`:""}`).then(r=>r.data)}const eq="border-[3px] border-[var(--color-text)] rounded-2xl bg-white shadow-[4px_4px_0_var(--color-text)]",tq={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 nq(){const e=Pe(),t=Gt(),[n,r]=j.useState(""),a=Ye({queryKey:["audit",n],queryFn:()=>J8(n?{action:n}:{}),refetchInterval:8e3}),o=a.data??[],l=d=>e(`audit.action.${d}`);return c.jsxs("div",{className:"max-w-full",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[c.jsx(Bb,{size:22,strokeWidth:2.5}),c.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl",children:e("audit.title")}),c.jsxs("button",{type:"button","aria-label":e("audit.refresh"),onClick:()=>t.invalidateQueries({queryKey:["audit"]}),className:"ml-auto inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl border-2 border-[var(--color-text)] bg-white text-sm font-semibold shadow-[2px_2px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px focus-visible:outline focus-visible:outline-2",children:[a.isFetching?c.jsx(Xe,{size:15,className:"animate-spin"}):c.jsx(ya,{size:15}),e("audit.refresh")]})]}),c.jsx("p",{className:"text-sm text-[var(--color-text)]/70 mb-4",children:e("audit.subtitle")}),c.jsx("div",{className:"flex gap-2 mb-3",children:["","create","modify","delete","daemon"].map(d=>c.jsx("button",{type:"button","aria-label":d?l(d):e("audit.filter.all"),onClick:()=>r(d),className:`px-3 py-1 rounded-lg border-2 border-[var(--color-text)] text-sm font-bold shadow-[2px_2px_0_var(--color-text)] focus-visible:outline focus-visible:outline-2 ${n===d?"bg-[var(--color-accent-purple)]":"bg-white hover:-translate-x-px hover:-translate-y-px"}`,children:d?l(d):e("audit.filter.all")},d||"all"))}),c.jsx("div",{className:`${eq} overflow-hidden`,children:c.jsxs("table",{className:"w-full text-sm",children:[c.jsx("thead",{className:"bg-[var(--color-bg-cream)] font-[family-name:var(--font-heading)]",children:c.jsxs("tr",{className:"text-left",children:[c.jsx("th",{className:"px-3 py-2",children:e("audit.col.time")}),c.jsx("th",{className:"px-3 py-2",children:e("audit.col.action")}),c.jsx("th",{className:"px-3 py-2",children:e("audit.col.project")}),c.jsx("th",{className:"px-3 py-2",children:e("audit.col.detail")})]})}),c.jsxs("tbody",{className:"font-[family-name:var(--font-mono)]",children:[o.length===0&&c.jsx("tr",{children:c.jsx("td",{colSpan:4,className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:e("audit.empty")})}),o.map((d,f)=>c.jsxs("tr",{className:"border-t-2 border-[var(--color-text)]/10",children:[c.jsx("td",{className:"px-3 py-2 whitespace-nowrap",children:new Date(d.ts).toLocaleString()}),c.jsx("td",{className:"px-3 py-2",children:c.jsx("span",{className:`inline-block px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] text-xs font-bold ${tq[d.action]}`,children:l(d.action)})}),c.jsx("td",{className:"px-3 py-2",children:d.project}),c.jsx("td",{className:"px-3 py-2 text-[var(--color-text)]/70",children:d.detail??(d.source?`(${d.source})`:"—")})]},`${d.ts}-${f}`))]})]})})]})}const rq=["convention","decision","gotcha","pattern","reference","note"];function Gs(e){return`${e.scope}:${e.project??e.agentId??""}`}function Bf(e){return e.scope==="global"?`全局 (${e.count})`:e.scope==="project"?`项目:${e.project} (${e.count})`:`会话:${e.agentId} (${e.count})`}function Vs(e){const t={scope:e.scope};return e.project&&(t.project=e.project),e.agentId&&(t.agentId=e.agentId),t}async function ia(e,t){const n=await fetch(e,t);if(!n.ok){const r=await n.json().catch(()=>null);throw new Error((r==null?void 0:r.detail)||(r==null?void 0:r.title)||`HTTP ${n.status}`)}return await n.json()}const iq=()=>({title:"",body:"",category:"note",tags:"",salience:3});function aq(){const e=Pe(),[t,n]=j.useState([]),[r,a]=j.useState(null),[o,l]=j.useState([]),[d,f]=j.useState(null),[h,g]=j.useState(!1),[m,y]=j.useState(""),[b,w]=j.useState(!0),[v,S]=j.useState([]),[E,C]=j.useState(null),[N,_]=j.useState(null),[M,A]=j.useState(null),[O,D]=j.useState(""),[U,B]=j.useState(""),q=j.useCallback(async()=>{try{const{scopes:P}=await ia("/api/memory/scopes");n(P),a(I=>I??P[0]??null)}catch(P){f(P instanceof Error?P.message:String(P))}},[]),G=j.useCallback(async P=>{try{const I=new URLSearchParams(Vs(P)).toString(),{data:ae}=await ia(`/api/memory/entries?${I}`);l(ae)}catch(I){f(I instanceof Error?I.message:String(I))}},[]);j.useEffect(()=>{q(),ia("/api/system/memory").then(P=>{A(P),D(P.mode),B(P.externalUrl)}).catch(()=>{})},[q]),j.useEffect(()=>{r&&G(r)},[r,G]);const Q=j.useCallback(async()=>{if(!m.trim()){S([]);return}g(!0),f(null);try{const P=new URLSearchParams({q:m,limit:"20"});if(b)P.set("all","1");else if(r)for(const[ae,me]of Object.entries(Vs(r)))P.set(ae,me);const{results:I}=await ia(`/api/memory/recall?${P.toString()}`);S(I)}catch(P){f(P instanceof Error?P.message:String(P))}finally{g(!1)}},[m,b,r]),R=j.useCallback(async()=>{if(!(!r||!E)){g(!0),f(null);try{await ia("/api/memory/entries",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({...Vs(r),id:E.id,title:E.title,body:E.body,category:E.category,tags:E.tags.split(",").map(P=>P.trim()).filter(Boolean),salience:E.salience})}),C(null),await Promise.all([G(r),q()])}catch(P){f(P instanceof Error?P.message:String(P))}finally{g(!1)}}},[r,E,G,q]),H=j.useCallback(async P=>{if(r){g(!0),f(null);try{const I=new URLSearchParams(Vs(r)).toString();await ia(`/api/memory/entries/${encodeURIComponent(P)}?${I}`,{method:"DELETE"}),await Promise.all([G(r),q()])}catch(I){f(I instanceof Error?I.message:String(I))}finally{g(!1)}}},[r,G,q]),L=j.useCallback(async(P,I,ae)=>{if(r){g(!0),f(null);try{await ia("/api/memory/promote",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({from:Vs(r),id:P.id,to:Vs(I),move:ae})}),_(null),await Promise.all([G(r),q()])}catch(me){f(me instanceof Error?me.message:String(me))}finally{g(!1)}}},[r,G,q]),V=j.useCallback(async()=>{if(r){g(!0),f(null);try{const I=(await ia("/api/memory/gc",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(Vs(r))})).results[0];I&&f(`收敛完成:清 tombstone ${I.purged}、去重 ${I.deduped}、剩余 ${I.kept}`),await Promise.all([G(r),q()])}catch(P){f(P instanceof Error?P.message:String(P))}finally{g(!1)}}},[r,G,q]),Y=j.useCallback(async()=>{g(!0),f(null);try{const P=await ia("/api/system/memory",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({mode:O,externalUrl:U})});A(P),D(P.mode),B(P.externalUrl),f("模式已保存(重启 worker 生效)")}catch(P){f(P instanceof Error?P.message:String(P))}finally{g(!1)}},[O,U]),K=M!=null&&(O!==M.mode||U!==M.externalUrl),z=O==="external"||O==="local+external",$=j.useMemo(()=>N?t.filter(P=>Gs(P)!==Gs(r??{scope:""})):[],[N,t,r]);return c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[c.jsxs("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl text-[var(--color-text)]",children:["🧠 ",e("nav.memory")]}),c.jsx("span",{className:"text-xs text-[var(--color-text)] opacity-60",children:"本地记忆 v2 · markdown 真源"})]}),M&&c.jsxs("section",{className:"nb-card flex flex-wrap items-end gap-3",children:[c.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[c.jsx("span",{className:"font-bold",children:"记忆模式"}),c.jsx("select",{className:"nb-input",value:O,onChange:P=>D(P.target.value),"aria-label":"记忆模式",children:M.modeOptions.map(P=>c.jsx("option",{value:P,children:P},P))})]}),z&&c.jsxs("label",{className:"flex flex-col gap-1 text-sm flex-1 min-w-[220px]",children:[c.jsx("span",{className:"font-bold",children:"外部后端地址"}),c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",value:U,onChange:P=>B(P.target.value),placeholder:"http://127.0.0.1:3113",spellCheck:!1,"aria-label":"外部后端地址"})]}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:Y,disabled:h||!K,"aria-label":"保存模式",children:"保存模式"})]}),c.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[c.jsx("input",{value:m,onChange:P=>y(P.target.value),onKeyDown:P=>P.key==="Enter"&&Q(),placeholder:"检索记忆…","aria-label":"检索记忆",className:"nb-input flex-1 min-w-[200px] font-[family-name:var(--font-mono)] text-sm"}),c.jsxs("label",{className:"flex items-center gap-1 text-sm font-semibold",children:[c.jsx("input",{type:"checkbox",checked:b,onChange:P=>w(P.target.checked),"aria-label":"全局检索"}),"全局"]}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:Q,disabled:h,"aria-label":"检索",children:h?"…":"检索"})]}),d&&c.jsxs("div",{className:"text-sm text-[var(--color-text)] font-semibold nb-card py-2",children:["ℹ ",d]}),v.length>0&&c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsxs("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:["检索结果(",v.length,")"]}),v.map(P=>c.jsxs("div",{className:"nb-card",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)]",children:[c.jsx("span",{className:"nb-badge",children:P.source==="external"?"🌐 外部":"📁 本地"}),c.jsx("span",{children:P.source==="external"?P.type??"":P.scope==="project"?`项目:${P.project}`:P.scope}),P.category&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsx("span",{children:P.category})]})]}),c.jsx("div",{className:"font-bold text-sm mt-1",children:P.title}),c.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:P.snippet.slice(0,300)})]},P.id))]}),c.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[c.jsx("select",{className:"nb-input",value:r?Gs(r):"",onChange:P=>a(t.find(I=>Gs(I)===P.target.value)??null),"aria-label":"选择作用域",children:t.map(P=>c.jsx("option",{value:Gs(P),children:Bf(P)},Gs(P)))}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-blue",onClick:()=>C(iq()),disabled:!r,"aria-label":"新建记忆",children:"+ 新建"}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-yellow",onClick:V,disabled:h||!r,"aria-label":"收敛去重",children:"收敛"})]}),E&&c.jsxs("section",{className:"nb-card flex flex-col gap-2",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:E.id?"编辑记忆":"新建记忆"}),c.jsx("input",{className:"nb-input text-sm",value:E.title,onChange:P=>C({...E,title:P.target.value}),placeholder:"标题","aria-label":"标题"}),c.jsxs("div",{className:"flex gap-2 flex-wrap",children:[c.jsx("select",{className:"nb-input",value:E.category,onChange:P=>C({...E,category:P.target.value}),"aria-label":"类别",children:rq.map(P=>c.jsx("option",{value:P,children:P},P))}),c.jsx("input",{className:"nb-input flex-1 min-w-[160px] text-sm",value:E.tags,onChange:P=>C({...E,tags:P.target.value}),placeholder:"标签(逗号分隔)","aria-label":"标签"}),c.jsxs("label",{className:"flex items-center gap-1 text-sm",children:["显著度",c.jsx("input",{className:"nb-input w-16",type:"number",min:1,max:5,value:E.salience,onChange:P=>C({...E,salience:Number(P.target.value)}),"aria-label":"显著度"})]})]}),c.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm min-h-[120px]",value:E.body,onChange:P=>C({...E,body:P.target.value}),placeholder:"正文","aria-label":"正文"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:R,disabled:h||!E.title.trim()||!E.body.trim(),"aria-label":"保存",children:"保存"}),c.jsx("button",{type:"button",className:"nb-btn",onClick:()=>C(null),"aria-label":"取消",children:"取消"})]})]}),c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm",children:r?Bf(r):"条目"}),o.length===0&&c.jsx("div",{className:"nb-card text-sm opacity-60",children:"(无记忆)"}),o.map(P=>c.jsxs("div",{className:"nb-card",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)] flex-wrap",children:[c.jsx("span",{className:"nb-badge",children:P.category}),c.jsxs("span",{children:["s",P.salience]}),c.jsx("span",{children:"·"}),c.jsx("span",{children:P.source}),P.tags.map(I=>c.jsxs("span",{children:["#",I]},I))]}),c.jsx("div",{className:"font-bold text-sm mt-1",children:P.title}),c.jsx("div",{className:"text-sm mt-1 whitespace-pre-wrap opacity-80",children:P.body.slice(0,400)}),c.jsxs("div",{className:"flex gap-2 mt-2",children:[c.jsx("button",{type:"button",className:"nb-btn nb-btn-blue text-xs",onClick:()=>C({id:P.id,title:P.title,body:P.body,category:P.category,tags:P.tags.join(", "),salience:P.salience}),"aria-label":"编辑",children:"编辑"}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-purple text-xs",onClick:()=>_(P),"aria-label":"提升",children:"提升"}),c.jsx("button",{type:"button",className:"nb-btn nb-btn-danger text-xs",onClick:()=>H(P.id),"aria-label":"删除",children:"删除"})]}),(N==null?void 0:N.id)===P.id&&c.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 border-t-[3px] border-[var(--color-text)] pt-2",children:[c.jsx("span",{className:"text-xs font-bold",children:"提升到:"}),$.map(I=>c.jsx("button",{type:"button",className:"nb-btn nb-btn-mint text-xs",onClick:()=>L(P,I,!1),"aria-label":`复制到${Bf(I)}`,children:Bf(I)},Gs(I))),$.length===0&&c.jsx("span",{className:"text-xs opacity-60",children:"(无其它作用域)"}),c.jsx("button",{type:"button",className:"nb-btn text-xs",onClick:()=>_(null),"aria-label":"取消提升",children:"取消"})]})]},P.id))]})]})}async function sq(){return(await ht("/api/channels")).data??{console:{},adapters:[]}}async function oq(e){return(await qb("/api/channels",e)).data}async function lq(){return(await ht("/api/codex-proxy")).data}async function cq(){return(await Ri("/api/codex-proxy/install")).data}async function uq(e){const t=await fetch(`/api/codex-proxy?purgeAuth=${e?"1":"0"}`,{method:"DELETE",headers:{Accept:"application/json"}});if(!t.ok)throw new Error(`${t.status}: ${await t.text()}`);return(await t.json()).data}async function dq(){return(await Ri("/api/codex-proxy/auth/start")).data}async function fq(){await Ri("/api/codex-proxy/auth/cancel")}const RE=[{key:"memory",labelKey:"plugins.tab.memory"},{key:"channel",labelKey:"plugins.tab.channel"},{key:"model",labelKey:"plugins.tab.model"},{key:"tool",labelKey:"plugins.tab.tool"}];function hq(){const e=Pe(),[t,n]=j.useState("memory");return c.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[c.jsxs("header",{children:[c.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:e("plugins.h1")}),c.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:e("plugins.desc")})]}),c.jsx("div",{role:"tablist","aria-label":e("plugins.h1"),className:"flex gap-2 flex-wrap",children:RE.map(r=>{const a=t===r.key;return c.jsx("button",{role:"tab","aria-selected":a,type:"button",onClick:()=>n(r.key),className:["px-4 py-2 rounded-xl font-bold text-sm border-2 transition-transform duration-150",a?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[3px_3px_0_var(--color-text)]":"border-[var(--color-text)] bg-white hover:-translate-x-px hover:-translate-y-px hover:shadow-[3px_3px_0_var(--color-text)]"].join(" "),children:e(r.labelKey)},r.key)})}),c.jsx("div",{role:"tabpanel",children:t==="memory"?c.jsx(mq,{}):t==="channel"?c.jsx(wq,{}):t==="model"?c.jsx(gq,{}):c.jsx(pq,{label:e(RE.find(r=>r.key===t).labelKey)})})]})}function pq({label:e}){const t=Pe();return c.jsx("section",{className:"nb-card",children:c.jsxs("p",{className:"text-[var(--color-text-muted)] text-sm",children:[e," — ",t("plugins.comingSoon")]})})}function mq(){var w,v,S;const e=Pe(),t=Gt(),{alert:n}=un(),r=Ye({queryKey:["system-memory"],queryFn:O3}),[a,o]=j.useState(null),[l,d]=j.useState(null);j.useEffect(()=>{r.data&&a===null&&(o(r.data.provider),d(r.data.url))},[r.data,a]);const f=a??((w=r.data)==null?void 0:w.provider)??"agentmemory",h=l??((v=r.data)==null?void 0:v.url)??"",g=r.data!=null&&(f!==r.data.provider||f==="custom"&&h!==r.data.url),m=E=>{const C=`system.memory.opt.${E}`;return e(C)},y=Ct({mutationFn:()=>R3(f,f==="custom"?h:""),onSuccess:()=>{t.invalidateQueries({queryKey:["system-memory"]}),t.invalidateQueries({queryKey:["system-env"]})},onError:E=>{n({title:e("system.memory.error"),body:E instanceof Error?E.message:String(E)})}}),b=((S=r.data)==null?void 0:S.options)??["none","builtin","agentmemory","custom"];return c.jsxs("section",{className:"nb-card",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:e("system.memory.title")}),c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-3",children:e("system.memory.desc")}),c.jsxs("div",{className:"flex flex-col gap-3 max-w-md",children:[c.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[c.jsx("span",{className:"font-bold",children:e("system.memory.provider")}),c.jsx("select",{className:"nb-input",value:f,onChange:E=>o(E.target.value),"aria-label":e("system.memory.provider"),children:b.map(E=>c.jsx("option",{value:E,children:m(E)},E))})]}),f==="custom"&&c.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[c.jsx("span",{className:"font-bold",children:e("system.memory.url")}),c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-xs",type:"text",value:h,onChange:E=>d(E.target.value),placeholder:e("system.memory.url.placeholder"),spellCheck:!1,"aria-label":e("system.memory.url")})]}),c.jsx("div",{className:"flex justify-end",children:c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px",fontSize:12},onClick:()=>y.mutate(),disabled:!g||y.isPending,type:"button","aria-label":e("system.memory.save.aria"),children:[y.isPending?c.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):c.jsx(Oi,{size:12,strokeWidth:3}),y.isSuccess&&!g?e("system.memory.saved"):e("system.memory.save")]})})]})]})}function gq(){var S,E,C;const e=Gt(),{alert:t,confirm:n}=un(),r=Ye({queryKey:["providers"],queryFn:lx}),o=(S=Ye({queryKey:["system-agents"],queryFn:Hb}).data)==null?void 0:S.agents,[l,d]=j.useState(null),f=Ct({mutationFn:()=>Jz(l.kind,l.entry),onSuccess:()=>{d(null),e.invalidateQueries({queryKey:["providers"]})},onError:N=>void t({title:"保存失败",body:N instanceof Error?N.message:String(N)})}),h=Ct({mutationFn:N=>e4(N.kind,N.id),onSuccess:()=>void e.invalidateQueries({queryKey:["providers"]}),onError:N=>void t({title:"删除失败",body:N instanceof Error?N.message:String(N)})}),g=Ct({mutationFn:N=>L3(N),onSuccess:()=>void e.invalidateQueries({queryKey:["system-agents"]}),onError:N=>void t({title:"设默认失败",body:N instanceof Error?N.message:String(N)})}),m=(N,_,M)=>{if(!o)return!1;const A=N==="anthropic"?o.worker:o.reviewer;return(A.providerId||"official")===_&&A.model===M},y=(N,_,M)=>{if(!o)return;let A;if(N==="anthropic"){const O={...o.worker,model:M};_==="official"?delete O.providerId:O.providerId=_,A={...o,worker:O}}else A={...o,reviewer:{...o.reviewer,providerId:_,model:M}};g.mutate(A)},b=[{kind:"anthropic",title:"Anthropic 兼容(worker / claude)",items:((E=r.data)==null?void 0:E.anthropic)??[]},{kind:"openai",title:"OpenAI 兼容(reviewer / openai agent)",items:((C=r.data)==null?void 0:C.openai)??[]}],w=N=>d({kind:N,isNew:!0,entry:{id:"",name:"",baseUrl:"",apiKey:"",models:[]}}),v=(N,_)=>d({kind:N,isNew:!1,entry:{id:_.id,name:_.name,baseUrl:_.baseUrl,apiKey:"",models:_.models}});return c.jsxs("section",{className:"nb-card",children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:"模型 API 端点"}),c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-4",children:"本地官方订阅(已登录验证)自动置顶,不可编辑;下方可增删第三方兼容端点。**点模型标签设为默认**(anthropic→worker / openai→监工);✓ = 当前默认。"}),c.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:b.map(N=>c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"font-bold text-sm",children:N.title}),c.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:()=>w(N.kind),"aria-label":`添加 ${N.title} 端点`,children:[c.jsx(pr,{size:12,strokeWidth:3})," 添加"]})]}),N.items.length===0&&c.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无端点)"}),N.items.map(_=>_.id==="codex-proxy"?c.jsx(bq,{isDefault:M=>m(N.kind,_.id,M),pickDefault:M=>y(N.kind,_.id,M),setDefaultPending:g.isPending},_.id):c.jsxs("div",{className:["rounded-lg px-3 py-2 border-2",_.builtin?"border-[var(--color-text)] bg-[var(--color-bg-cream)]":"border-[var(--color-text)]"].join(" "),children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:_.id}),c.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",_.name]}),_.builtin?c.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:["本地订阅",_.detail?` · ${_.detail}`:""," · 已验证可用"]}):c.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[_.baseUrl," · key ",_.hasKey?_.apiKey:"未设置"]})]}),_.builtin?c.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:"内置"}):c.jsxs("div",{className:"flex gap-1 shrink-0",children:[c.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>v(N.kind,_),"aria-label":`编辑 ${_.id}`,children:c.jsx(BL,{size:12,strokeWidth:3})}),c.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 8px"},type:"button",onClick:async()=>{await n({title:"删除端点",body:`删除 ${_.id}?`,danger:!0})&&h.mutate({kind:N.kind,id:_.id})},"aria-label":`删除 ${_.id}`,children:c.jsx(fi,{size:12,strokeWidth:3})})]})]}),_.models.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:_.models.map(M=>{const A=m(N.kind,_.id,M);return c.jsxs("button",{type:"button",onClick:()=>y(N.kind,_.id,M),disabled:g.isPending,"aria-pressed":A,className:["px-2 py-0.5 rounded-md text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)]",A?"bg-[var(--color-accent-mint)] font-bold":"bg-[var(--color-bg)] hover:bg-[var(--color-bg-cream)]"].join(" "),title:A?"当前默认":"设为默认",children:[M,A?" ✓":""]},M)})})]},_.id))]},N.kind))}),l&&c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:()=>d(null),children:c.jsx("div",{onClick:N=>N.stopPropagation(),children:c.jsx(yq,{state:l,onChange:N=>d({...l,entry:N}),onCancel:()=>d(null),onSave:()=>f.mutate(),saving:f.isPending})})})]})}function yq({state:e,onChange:t,onCancel:n,onSave:r,saving:a}){const o=e.entry,l=f=>t({...o,...f}),d=/^[a-zA-Z0-9_-]+$/.test(o.id)&&o.name.trim()&&o.baseUrl.trim();return c.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:[c.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增端点":`编辑 ${o.id}`,c.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:["(",e.kind,")"]})]}),c.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:o.id,disabled:!e.isNew,onChange:f=>l({id:f.target.value}),placeholder:"如 my-openai",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",c.jsx("input",{className:"nb-input",value:o.name,onChange:f=>l({name:f.target.value}),placeholder:"显示名"})]})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:o.baseUrl,onChange:f=>l({baseUrl:f.target.value}),placeholder:"https://api.example.com/v1",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",!e.isNew&&"(留空=保留)",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:o.apiKey??"",onChange:f=>l({apiKey:f.target.value}),placeholder:e.isNew?"sk-...":"••••(留空不改)",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Models(逗号或换行分隔)",c.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",rows:5,value:o.models.join(", "),onChange:f=>l({models:f.target.value.split(/[,\n]/).map(h=>h.trim()).filter(Boolean)}),placeholder:"gpt-5.4, gpt-4o",spellCheck:!1})]}),c.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[c.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:n,children:"取消"}),c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!d||a,onClick:r,children:[a?c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):c.jsx(Oi,{size:14,strokeWidth:3})," 保存"]})]})]})}function bq({isDefault:e,pickDefault:t,setDefaultPending:n}){const r=Gt(),{alert:a,confirm:o}=un(),[l,d]=j.useState(!1),[f,h]=j.useState(null),[g,m]=j.useState(!1),[y,b]=j.useState(!1),[w,v]=j.useState(!1),E=Ye({queryKey:["codex-proxy"],queryFn:lq,refetchInterval:l?3e3:!1}).data;j.useEffect(()=>{l&&(E!=null&&E.authed)&&(d(!1),h(null),r.invalidateQueries({queryKey:["codex-proxy"]}))},[l,E==null?void 0:E.authed,r]);const C=Ct({mutationFn:cq,onSuccess:U=>{r.invalidateQueries({queryKey:["codex-proxy"]}),r.invalidateQueries({queryKey:["providers"]}),U.ok||a({title:"安装失败",body:(U.output||"未知错误").slice(-600)})},onError:U=>void a({title:"安装失败",body:U instanceof Error?U.message:String(U)})}),N=Ct({mutationFn:U=>uq(U),onSuccess:U=>{m(!1),b(!1),r.invalidateQueries({queryKey:["codex-proxy"]}),r.invalidateQueries({queryKey:["providers"]}),r.invalidateQueries({queryKey:["system-agents"]}),U.ok||a({title:"卸载未完成",body:U.note??"删除失败(可能需 sudo)"})},onError:U=>void a({title:"卸载失败",body:U instanceof Error?U.message:String(U)})}),_=async()=>{await o({title:"安装 claude-code-proxy",body:"将运行官方安装脚本(curl … install.sh | bash),下载预编译二进制到 ~/.local/bin。继续?"})&&C.mutate()},M=async()=>{d(!0),h(null);try{const U=await dq();h(U)}catch(U){d(!1),a({title:"订阅失败",body:U instanceof Error?U.message:String(U)})}},A=()=>{fq(),d(!1),h(null)},O=C.isPending||(E==null?void 0:E.installing),D=w&&(E!=null&&E.models.all.length)?E.models.all:(E==null?void 0:E.models.curated)??[];return c.jsxs("div",{className:"rounded-lg px-3 py-2 border-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:"codex-proxy"}),c.jsx("span",{className:"text-[var(--color-text-muted)] text-sm",children:" · ChatGPT 订阅"}),c.jsx("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:E?E.binInstalled?E.authed?`已订阅${E.account?` · ${E.account.slice(0,8)}…`:""} · worker 出 GPT`:"已安装 · 未订阅":"未安装 claude-code-proxy":"加载中…"})]}),(E==null?void 0:E.binInstalled)&&c.jsx("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 8px"},type:"button",onClick:()=>m(!0),"aria-label":"卸载 codex-proxy",children:c.jsx(fi,{size:12,strokeWidth:3})})]}),c.jsx("div",{className:"mt-2",children:E?E.binInstalled?E.authed?c.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[D.map(U=>{const B=e(U);return c.jsxs("button",{type:"button",onClick:()=>t(U),disabled:n,"aria-pressed":B,className:["px-2 py-0.5 rounded-md text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)]",B?"bg-[var(--color-accent-mint)] font-bold":"bg-[var(--color-bg)] hover:bg-[var(--color-bg-cream)]"].join(" "),title:B?"当前默认":"设为 worker 默认",children:[U,B?" ✓":""]},U)}),E.models.all.length>E.models.curated.length&&c.jsx("button",{type:"button",className:"text-xs text-[var(--color-text-muted)] underline",onClick:()=>v(U=>!U),children:w?"收起":`显示全部(${E.models.all.length})`})]}):c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 12px",fontSize:12},type:"button",onClick:M,children:[c.jsx(SL,{size:12,strokeWidth:3})," 订阅(授权 ChatGPT)"]}):c.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 12px",fontSize:12},type:"button",disabled:!!O,onClick:_,children:[O?c.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):c.jsx(Uh,{size:12,strokeWidth:3}),O?" 安装中…":" 安装插件"]}):c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin text-[var(--color-text-muted)]"})}),l&&c.jsxs(LE,{onClose:A,children:[c.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"订阅 ChatGPT(设备码授权)"}),f!=null&&f.verificationUrl&&(f!=null&&f.userCode)?c.jsxs("div",{className:"flex flex-col gap-3 text-sm",children:[c.jsxs("div",{children:["① 打开"," ",c.jsxs("a",{href:f.verificationUrl,target:"_blank",rel:"noreferrer",className:"font-bold underline inline-flex items-center gap-1",children:[f.verificationUrl," ",c.jsx(YR,{size:12,strokeWidth:3})]})]}),c.jsxs("div",{children:["② 输入验证码:",c.jsx("code",{className:"ml-1 px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)] font-bold font-[family-name:var(--font-mono)]",children:f.userCode})]}),c.jsx("div",{children:"③ 在浏览器完成授权"}),c.jsxs("div",{className:"flex items-center gap-2 text-[var(--color-text-muted)]",children:[c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"})," 等待授权…(完成后自动刷新)"]})]}):c.jsxs("div",{className:"flex flex-col gap-2 text-sm text-[var(--color-text-muted)]",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"})," 正在获取设备码…"]}),c.jsxs("div",{children:["若长时间无响应,可在终端运行 ",c.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps codex-proxy auth"}),",完成后此处自动刷新。"]})]}),c.jsx("div",{className:"flex justify-end pt-1",children:c.jsx("button",{className:"nb-btn",style:{padding:"6px 14px"},type:"button",onClick:A,children:"取消"})})]}),g&&c.jsxs(LE,{onClose:()=>m(!1),children:[c.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"卸载 claude-code-proxy"}),c.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"停止 proxy 并删除二进制。默认保留授权(重装免再授权)。"}),c.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[c.jsx("input",{type:"checkbox",checked:y,onChange:U=>b(U.target.checked)}),"同时清除授权(~/.config/claude-code-proxy)"]}),c.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[c.jsx("button",{className:"nb-btn",style:{padding:"6px 14px"},type:"button",onClick:()=>m(!1),children:"取消"}),c.jsxs("button",{className:"nb-btn nb-btn-danger",style:{padding:"6px 14px"},type:"button",disabled:N.isPending,onClick:()=>N.mutate(y),children:[N.isPending?c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):c.jsx(fi,{size:14,strokeWidth:3})," 卸载"]})]})]})]})}function LE({children:e,onClose:t}){return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:t,children:c.jsx("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,520px)]",onClick:n=>n.stopPropagation(),children:e})})}const xq=["telegram","dingtalk","matrix","slack","discord","feishu"],gu={telegram:"Telegram",dingtalk:"钉钉 (Stream)",matrix:"Matrix",slack:"Slack",discord:"Discord",feishu:"飞书 / Lark"},vq={telegram:[{key:"token",label:"Bot Token(@BotFather)",type:"password",placeholder:"123456:ABC-..."},{key:"allowedChatIds",label:"允许的 Chat ID(白名单,空=全放)",type:"list",placeholder:"逗号/换行分隔"}],dingtalk:[{key:"clientId",label:"Client ID(AppKey)",type:"text"},{key:"clientSecret",label:"Client Secret(AppSecret)",type:"password"},{key:"allowedConversations",label:"允许的会话 ID(白名单,空=全放)",type:"list"}],matrix:[{key:"homeserver",label:"Homeserver URL",type:"text",placeholder:"https://matrix.org"},{key:"accessToken",label:"Access Token",type:"password"},{key:"allowedRooms",label:"允许的 Room ID(白名单,空=全放)",type:"list"}],slack:[{key:"appToken",label:"App Token(xapp-,Socket Mode)",type:"password",placeholder:"xapp-..."},{key:"botToken",label:"Bot Token(xoxb-)",type:"password",placeholder:"xoxb-..."},{key:"allowedChannels",label:"允许的 Channel(白名单,空=全放)",type:"list"}],discord:[{key:"token",label:"Bot Token",type:"password"},{key:"allowedChannels",label:"允许的 Channel ID(白名单,空=全放)",type:"list"}],feishu:[{key:"appId",label:"App ID",type:"text"},{key:"appSecret",label:"App Secret",type:"password"},{key:"verificationToken",label:"Verification Token",type:"text"},{key:"encryptKey",label:"Encrypt Key(设了则事件 AES 解密)",type:"password"},{key:"port",label:"本机监听端口(默认 9800)",type:"number",placeholder:"9800"},{key:"path",label:"监听路径(默认 /feishu)",type:"text",placeholder:"/feishu"},{key:"allowedChats",label:"允许的 chat_id(白名单,空=全放)",type:"list"}]};function wq(){var w,v,S;const e=Gt(),{alert:t}=un(),n=Ye({queryKey:["channels"],queryFn:sq}),[r,a]=j.useState(null),[o,l]=j.useState({type:"console"});j.useEffect(()=>{n.data&&!r&&a({console:n.data.console??{},adapters:n.data.adapters??[]})},[n.data,r]);const d=Ct({mutationFn:()=>oq(r),onSuccess:E=>{a({console:E.console??{},adapters:E.adapters??[]}),e.invalidateQueries({queryKey:["channels"]})},onError:E=>void t({title:"保存失败",body:E instanceof Error?E.message:String(E)})});if(!r)return c.jsx("section",{className:"nb-card",children:c.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"})," 加载频道配置…"]})});const f=r.adapters??[],h=JSON.stringify(r)!==JSON.stringify({console:((w=n.data)==null?void 0:w.console)??{},adapters:((v=n.data)==null?void 0:v.adapters)??[]}),g=E=>{const C=[...f,{kind:E,enabled:!0}];a({...r,adapters:C}),l({type:"adapter",index:C.length-1})},m=E=>{const C=f.filter((N,_)=>_!==E);a({...r,adapters:C}),l({type:"console"})},y=(E,C)=>{const N=f.map((_,M)=>M===E?{..._,...C}:_);a({...r,adapters:N})},b=E=>a({...r,console:{...r.console,...E}});return c.jsxs("section",{className:"nb-card",children:[c.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"频道(IM 网关)"}),c.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["接入 Telegram / 钉钉 / 飞书 / Slack / Discord / Matrix。左侧选频道,右侧改设置。保存后 ",c.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps im"})," 重启生效。"]})]}),c.jsxs("button",{className:"nb-btn nb-btn-primary shrink-0",style:{padding:"8px 16px"},type:"button",disabled:!h||d.isPending,onClick:()=>d.mutate(),"aria-label":"保存频道配置",children:[d.isPending?c.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):c.jsx(Oi,{size:14,strokeWidth:3})," 保存"]})]}),c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[220px_1fr] gap-5 mt-4",children:[c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsx(IE,{label:"console 桥接",sub:((S=r.console)==null?void 0:S.url)||"未配置",active:o.type==="console",onClick:()=>l({type:"console"})}),c.jsx("div",{className:"h-px bg-[var(--color-text)] opacity-20 my-1"}),f.length===0&&c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-1",children:"(无频道)"}),f.map((E,C)=>c.jsx(IE,{label:gu[E.kind]??E.kind,sub:E.enabled===!1?"已停用":"启用",active:o.type==="adapter"&&o.index===C,onClick:()=>l({type:"adapter",index:C})},C)),c.jsxs("div",{className:"mt-2",children:[c.jsx("span",{className:"text-xs font-bold text-[var(--color-text-muted)]",children:"添加频道"}),c.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:xq.map(E=>c.jsxs("button",{className:"nb-btn",style:{padding:"4px 8px",fontSize:12},type:"button",onClick:()=>g(E),"aria-label":`添加 ${gu[E]} 频道`,children:[c.jsx(pr,{size:11,strokeWidth:3})," ",gu[E]]},E))})]})]}),c.jsx("div",{className:"border-2 border-[var(--color-text)] rounded-xl p-4 bg-[var(--color-bg-cream)]",children:(()=>{if(o.type!=="adapter")return c.jsx(zE,{console:r.console??{},onChange:b});const E=f[o.index];if(!E)return c.jsx(zE,{console:r.console??{},onChange:b});const C=o.index;return c.jsx(kq,{adapter:E,onChange:N=>y(C,N),onRemove:()=>m(C)})})()})]})]})}function IE({label:e,sub:t,active:n,onClick:r}){return c.jsxs("button",{type:"button",onClick:r,"aria-pressed":n,className:["text-left rounded-lg px-3 py-2 border-2 border-[var(--color-text)] transition-transform duration-150",n?"bg-[var(--color-accent-mint)] shadow-[3px_3px_0_var(--color-text)]":"bg-white hover:-translate-x-px hover:-translate-y-px hover:shadow-[3px_3px_0_var(--color-text)]"].join(" "),children:[c.jsx("div",{className:"font-bold text-sm",children:e}),c.jsx("div",{className:"text-xs text-[var(--color-text-muted)] truncate font-[family-name:var(--font-mono)]",children:t})]})}function zE({console:e,onChange:t}){return c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"console 桥接"}),c.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:"IM 纯文本消息桥接到项目 agent 对话。设了 URL 才启用桥接;token 为 console 鉴权令牌。"})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console URL",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:e.url??"",onChange:n=>t({url:n.target.value}),placeholder:"http://localhost:4321",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console Token(SPS_CONSOLE_TOKEN)",c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:e.token??"",onChange:n=>t({token:n.target.value}),placeholder:"鉴权令牌(可空)",spellCheck:!1})]}),c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["对话后端",c.jsxs("select",{className:"nb-input",value:e.agentKind??"claude",onChange:n=>t({agentKind:n.target.value}),children:[c.jsx("option",{value:"claude",children:"claude"}),c.jsx("option",{value:"openai",children:"openai"})]})]})]})}function kq({adapter:e,onChange:t,onRemove:n}){const{confirm:r}=un(),a=vq[e.kind]??[],o=e.enabled!==!1;return c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{className:"flex items-start justify-between gap-2",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:gu[e.kind]??e.kind}),c.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-[family-name:var(--font-mono)]",children:[" · ",e.kind]})]}),c.jsxs("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:async()=>{await r({title:"删除频道",body:`删除 ${gu[e.kind]??e.kind} 频道?`,danger:!0})&&n()},"aria-label":"删除频道",children:[c.jsx(fi,{size:12,strokeWidth:3})," 删除"]})]}),c.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[c.jsx("input",{type:"checkbox",checked:o,onChange:l=>t({enabled:l.target.checked})}),"启用此频道"]}),a.map(l=>c.jsx(Eq,{spec:l,value:e[l.key],onChange:d=>t({[l.key]:d})},l.key))]})}function Eq({spec:e,value:t,onChange:n}){if(e.type==="list"){const r=Array.isArray(t)?t.map(String):[];return c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,c.jsx("textarea",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",rows:2,value:r.join(", "),onChange:a=>{const o=a.target.value.split(/[,\n]/).map(l=>l.trim()).filter(Boolean);n(o.length?o:void 0)},placeholder:e.placeholder,spellCheck:!1})]})}return c.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,c.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:e.type==="password"?"password":"text",value:t==null?"":String(t),onChange:r=>{const a=r.target.value;e.type==="number"?n(a.trim()===""?void 0:Number(a)):n(a===""?void 0:a)},placeholder:e.placeholder,spellCheck:!1})]})}function Nn(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Nn(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var Sq={value:()=>{}};function cp(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new rh(n)}function rh(e){this._=e}function Nq(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",a=n.indexOf(".");if(a>=0&&(r=n.slice(a+1),n=n.slice(0,a)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}rh.prototype=cp.prototype={constructor:rh,on:function(e,t){var n=this._,r=Nq(e+"",n),a,o=-1,l=r.length;if(arguments.length<2){for(;++o<l;)if((a=(e=r[o]).type)&&(a=_q(n[a],e.name)))return a;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<l;)if(a=(e=r[o]).type)n[a]=PE(n[a],e.name,t);else if(t==null)for(a in n)n[a]=PE(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 rh(e)},call:function(e,t){if((a=arguments.length-2)>0)for(var n=new Array(a),r=0,a,o;r<a;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],r=0,a=o.length;r<a;++r)o[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],a=0,o=r.length;a<o;++a)r[a].value.apply(t,n)}};function _q(e,t){for(var n=0,r=e.length,a;n<r;++n)if((a=e[n]).name===t)return a.value}function PE(e,t,n){for(var r=0,a=e.length;r<a;++r)if(e[r].name===t){e[r]=Sq,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var lb="http://www.w3.org/1999/xhtml";const BE={svg:"http://www.w3.org/2000/svg",xhtml:lb,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function up(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),BE.hasOwnProperty(t)?{space:BE[t],local:e}:e}function jq(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===lb&&t.documentElement.namespaceURI===lb?t.createElement(e):t.createElementNS(n,e)}}function Cq(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Yj(e){var t=up(e);return(t.local?Cq:jq)(t)}function Aq(){}function zx(e){return e==null?Aq:function(){return this.querySelector(e)}}function Tq(e){typeof e!="function"&&(e=zx(e));for(var t=this._groups,n=t.length,r=new Array(n),a=0;a<n;++a)for(var o=t[a],l=o.length,d=r[a]=new Array(l),f,h,g=0;g<l;++g)(f=o[g])&&(h=e.call(f,f.__data__,g,o))&&("__data__"in f&&(h.__data__=f.__data__),d[g]=h);return new Cr(r,this._parents)}function Mq(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Dq(){return[]}function Qj(e){return e==null?Dq:function(){return this.querySelectorAll(e)}}function Oq(e){return function(){return Mq(e.apply(this,arguments))}}function Rq(e){typeof e=="function"?e=Oq(e):e=Qj(e);for(var t=this._groups,n=t.length,r=[],a=[],o=0;o<n;++o)for(var l=t[o],d=l.length,f,h=0;h<d;++h)(f=l[h])&&(r.push(e.call(f,f.__data__,h,l)),a.push(f));return new Cr(r,a)}function Wj(e){return function(){return this.matches(e)}}function Xj(e){return function(t){return t.matches(e)}}var Lq=Array.prototype.find;function Iq(e){return function(){return Lq.call(this.children,e)}}function zq(){return this.firstElementChild}function Pq(e){return this.select(e==null?zq:Iq(typeof e=="function"?e:Xj(e)))}var Bq=Array.prototype.filter;function $q(){return Array.from(this.children)}function Uq(e){return function(){return Bq.call(this.children,e)}}function Fq(e){return this.selectAll(e==null?$q:Uq(typeof e=="function"?e:Xj(e)))}function qq(e){typeof e!="function"&&(e=Wj(e));for(var t=this._groups,n=t.length,r=new Array(n),a=0;a<n;++a)for(var o=t[a],l=o.length,d=r[a]=[],f,h=0;h<l;++h)(f=o[h])&&e.call(f,f.__data__,h,o)&&d.push(f);return new Cr(r,this._parents)}function Zj(e){return new Array(e.length)}function Hq(){return new Cr(this._enter||this._groups.map(Zj),this._parents)}function _h(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}_h.prototype={constructor:_h,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 Kq(e){return function(){return e}}function Gq(e,t,n,r,a,o){for(var l=0,d,f=t.length,h=o.length;l<h;++l)(d=t[l])?(d.__data__=o[l],r[l]=d):n[l]=new _h(e,o[l]);for(;l<f;++l)(d=t[l])&&(a[l]=d)}function Vq(e,t,n,r,a,o,l){var d,f,h=new Map,g=t.length,m=o.length,y=new Array(g),b;for(d=0;d<g;++d)(f=t[d])&&(y[d]=b=l.call(f,f.__data__,d,t)+"",h.has(b)?a[d]=f:h.set(b,f));for(d=0;d<m;++d)b=l.call(e,o[d],d,o)+"",(f=h.get(b))?(r[d]=f,f.__data__=o[d],h.delete(b)):n[d]=new _h(e,o[d]);for(d=0;d<g;++d)(f=t[d])&&h.get(y[d])===f&&(a[d]=f)}function Yq(e){return e.__data__}function Qq(e,t){if(!arguments.length)return Array.from(this,Yq);var n=t?Vq:Gq,r=this._parents,a=this._groups;typeof e!="function"&&(e=Kq(e));for(var o=a.length,l=new Array(o),d=new Array(o),f=new Array(o),h=0;h<o;++h){var g=r[h],m=a[h],y=m.length,b=Wq(e.call(g,g&&g.__data__,h,r)),w=b.length,v=d[h]=new Array(w),S=l[h]=new Array(w),E=f[h]=new Array(y);n(g,m,v,S,E,b,t);for(var C=0,N=0,_,M;C<w;++C)if(_=v[C]){for(C>=N&&(N=C+1);!(M=S[N])&&++N<w;);_._next=M||null}}return l=new Cr(l,r),l._enter=d,l._exit=f,l}function Wq(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Xq(){return new Cr(this._exit||this._groups.map(Zj),this._parents)}function Zq(e,t,n){var r=this.enter(),a=this,o=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(a=t(a),a&&(a=a.selection())),n==null?o.remove():n(o),r&&a?r.merge(a).order():a}function Jq(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,a=n.length,o=r.length,l=Math.min(a,o),d=new Array(a),f=0;f<l;++f)for(var h=n[f],g=r[f],m=h.length,y=d[f]=new Array(m),b,w=0;w<m;++w)(b=h[w]||g[w])&&(y[w]=b);for(;f<a;++f)d[f]=n[f];return new Cr(d,this._parents)}function eH(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],a=r.length-1,o=r[a],l;--a>=0;)(l=r[a])&&(o&&l.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(l,o),o=l);return this}function tH(e){e||(e=nH);function t(m,y){return m&&y?e(m.__data__,y.__data__):!m-!y}for(var n=this._groups,r=n.length,a=new Array(r),o=0;o<r;++o){for(var l=n[o],d=l.length,f=a[o]=new Array(d),h,g=0;g<d;++g)(h=l[g])&&(f[g]=h);f.sort(t)}return new Cr(a,this._parents).order()}function nH(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function rH(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function iH(){return Array.from(this)}function aH(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],a=0,o=r.length;a<o;++a){var l=r[a];if(l)return l}return null}function sH(){let e=0;for(const t of this)++e;return e}function oH(){return!this.node()}function lH(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var a=t[n],o=0,l=a.length,d;o<l;++o)(d=a[o])&&e.call(d,d.__data__,o,a);return this}function cH(e){return function(){this.removeAttribute(e)}}function uH(e){return function(){this.removeAttributeNS(e.space,e.local)}}function dH(e,t){return function(){this.setAttribute(e,t)}}function fH(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function hH(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function pH(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 mH(e,t){var n=up(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?uH:cH:typeof t=="function"?n.local?pH:hH:n.local?fH:dH)(n,t))}function Jj(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function gH(e){return function(){this.style.removeProperty(e)}}function yH(e,t,n){return function(){this.style.setProperty(e,t,n)}}function bH(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function xH(e,t,n){return arguments.length>1?this.each((t==null?gH:typeof t=="function"?bH:yH)(e,t,n??"")):Fl(this.node(),e)}function Fl(e,t){return e.style.getPropertyValue(t)||Jj(e).getComputedStyle(e,null).getPropertyValue(t)}function vH(e){return function(){delete this[e]}}function wH(e,t){return function(){this[e]=t}}function kH(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function EH(e,t){return arguments.length>1?this.each((t==null?vH:typeof t=="function"?kH:wH)(e,t)):this.node()[e]}function eC(e){return e.trim().split(/^|\s+/)}function Px(e){return e.classList||new tC(e)}function tC(e){this._node=e,this._names=eC(e.getAttribute("class")||"")}tC.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 nC(e,t){for(var n=Px(e),r=-1,a=t.length;++r<a;)n.add(t[r])}function rC(e,t){for(var n=Px(e),r=-1,a=t.length;++r<a;)n.remove(t[r])}function SH(e){return function(){nC(this,e)}}function NH(e){return function(){rC(this,e)}}function _H(e,t){return function(){(t.apply(this,arguments)?nC:rC)(this,e)}}function jH(e,t){var n=eC(e+"");if(arguments.length<2){for(var r=Px(this.node()),a=-1,o=n.length;++a<o;)if(!r.contains(n[a]))return!1;return!0}return this.each((typeof t=="function"?_H:t?SH:NH)(n,t))}function CH(){this.textContent=""}function AH(e){return function(){this.textContent=e}}function TH(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function MH(e){return arguments.length?this.each(e==null?CH:(typeof e=="function"?TH:AH)(e)):this.node().textContent}function DH(){this.innerHTML=""}function OH(e){return function(){this.innerHTML=e}}function RH(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function LH(e){return arguments.length?this.each(e==null?DH:(typeof e=="function"?RH:OH)(e)):this.node().innerHTML}function IH(){this.nextSibling&&this.parentNode.appendChild(this)}function zH(){return this.each(IH)}function PH(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function BH(){return this.each(PH)}function $H(e){var t=typeof e=="function"?e:Yj(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function UH(){return null}function FH(e,t){var n=typeof e=="function"?e:Yj(e),r=t==null?UH:typeof t=="function"?t:zx(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function qH(){var e=this.parentNode;e&&e.removeChild(this)}function HH(){return this.each(qH)}function KH(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function GH(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function VH(e){return this.select(e?GH:KH)}function YH(e){return arguments.length?this.property("__data__",e):this.node().__data__}function QH(e){return function(t){e.call(this,t,this.__data__)}}function WH(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function XH(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,a=t.length,o;n<a;++n)o=t[n],(!e.type||o.type===e.type)&&o.name===e.name?this.removeEventListener(o.type,o.listener,o.options):t[++r]=o;++r?t.length=r:delete this.__on}}}function ZH(e,t,n){return function(){var r=this.__on,a,o=QH(t);if(r){for(var l=0,d=r.length;l<d;++l)if((a=r[l]).type===e.type&&a.name===e.name){this.removeEventListener(a.type,a.listener,a.options),this.addEventListener(a.type,a.listener=o,a.options=n),a.value=t;return}}this.addEventListener(e.type,o,n),a={type:e.type,name:e.name,value:t,listener:o,options:n},r?r.push(a):this.__on=[a]}}function JH(e,t,n){var r=WH(e+""),a,o=r.length,l;if(arguments.length<2){var d=this.node().__on;if(d){for(var f=0,h=d.length,g;f<h;++f)for(a=0,g=d[f];a<o;++a)if((l=r[a]).type===g.type&&l.name===g.name)return g.value}return}for(d=t?ZH:XH,a=0;a<o;++a)this.each(d(r[a],t,n));return this}function iC(e,t,n){var r=Jj(e),a=r.CustomEvent;typeof a=="function"?a=new a(t,n):(a=r.document.createEvent("Event"),n?(a.initEvent(t,n.bubbles,n.cancelable),a.detail=n.detail):a.initEvent(t,!1,!1)),e.dispatchEvent(a)}function e7(e,t){return function(){return iC(this,e,t)}}function t7(e,t){return function(){return iC(this,e,t.apply(this,arguments))}}function n7(e,t){return this.each((typeof t=="function"?t7:e7)(e,t))}function*r7(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],a=0,o=r.length,l;a<o;++a)(l=r[a])&&(yield l)}var aC=[null];function Cr(e,t){this._groups=e,this._parents=t}function nd(){return new Cr([[document.documentElement]],aC)}function i7(){return this}Cr.prototype=nd.prototype={constructor:Cr,select:Tq,selectAll:Rq,selectChild:Pq,selectChildren:Fq,filter:qq,data:Qq,enter:Hq,exit:Xq,join:Zq,merge:Jq,selection:i7,order:eH,sort:tH,call:rH,nodes:iH,node:aH,size:sH,empty:oH,each:lH,attr:mH,style:xH,property:EH,classed:jH,text:MH,html:LH,raise:zH,lower:BH,append:$H,insert:FH,remove:HH,clone:VH,datum:YH,on:JH,dispatch:n7,[Symbol.iterator]:r7};function _r(e){return typeof e=="string"?new Cr([[document.querySelector(e)]],[document.documentElement]):new Cr([[e]],aC)}function a7(e){let t;for(;t=e.sourceEvent;)e=t;return e}function si(e,t){if(e=a7(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var a=t.getBoundingClientRect();return[e.clientX-a.left-t.clientLeft,e.clientY-a.top-t.clientTop]}}return[e.pageX,e.pageY]}const s7={passive:!1},Au={capture:!0,passive:!1};function uy(e){e.stopImmediatePropagation()}function Sl(e){e.preventDefault(),e.stopImmediatePropagation()}function sC(e){var t=e.document.documentElement,n=_r(e).on("dragstart.drag",Sl,Au);"onselectstart"in t?n.on("selectstart.drag",Sl,Au):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function oC(e,t){var n=e.document.documentElement,r=_r(e).on("dragstart.drag",null);t&&(r.on("click.drag",Sl,Au),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const $f=e=>()=>e;function cb(e,{sourceEvent:t,subject:n,target:r,identifier:a,active:o,x:l,y:d,dx:f,dy:h,dispatch:g}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:a,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:l,enumerable:!0,configurable:!0},y:{value:d,enumerable:!0,configurable:!0},dx:{value:f,enumerable:!0,configurable:!0},dy:{value:h,enumerable:!0,configurable:!0},_:{value:g}})}cb.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function o7(e){return!e.ctrlKey&&!e.button}function l7(){return this.parentNode}function c7(e,t){return t??{x:e.x,y:e.y}}function u7(){return navigator.maxTouchPoints||"ontouchstart"in this}function lC(){var e=o7,t=l7,n=c7,r=u7,a={},o=cp("start","drag","end"),l=0,d,f,h,g,m=0;function y(_){_.on("mousedown.drag",b).filter(r).on("touchstart.drag",S).on("touchmove.drag",E,s7).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function b(_,M){if(!(g||!e.call(this,_,M))){var A=N(this,t.call(this,_,M),_,M,"mouse");A&&(_r(_.view).on("mousemove.drag",w,Au).on("mouseup.drag",v,Au),sC(_.view),uy(_),h=!1,d=_.clientX,f=_.clientY,A("start",_))}}function w(_){if(Sl(_),!h){var M=_.clientX-d,A=_.clientY-f;h=M*M+A*A>m}a.mouse("drag",_)}function v(_){_r(_.view).on("mousemove.drag mouseup.drag",null),oC(_.view,h),Sl(_),a.mouse("end",_)}function S(_,M){if(e.call(this,_,M)){var A=_.changedTouches,O=t.call(this,_,M),D=A.length,U,B;for(U=0;U<D;++U)(B=N(this,O,_,M,A[U].identifier,A[U]))&&(uy(_),B("start",_,A[U]))}}function E(_){var M=_.changedTouches,A=M.length,O,D;for(O=0;O<A;++O)(D=a[M[O].identifier])&&(Sl(_),D("drag",_,M[O]))}function C(_){var M=_.changedTouches,A=M.length,O,D;for(g&&clearTimeout(g),g=setTimeout(function(){g=null},500),O=0;O<A;++O)(D=a[M[O].identifier])&&(uy(_),D("end",_,M[O]))}function N(_,M,A,O,D,U){var B=o.copy(),q=si(U||A,M),G,Q,R;if((R=n.call(_,new cb("beforestart",{sourceEvent:A,target:y,identifier:D,active:l,x:q[0],y:q[1],dx:0,dy:0,dispatch:B}),O))!=null)return G=R.x-q[0]||0,Q=R.y-q[1]||0,function H(L,V,Y){var K=q,z;switch(L){case"start":a[D]=H,z=l++;break;case"end":delete a[D],--l;case"drag":q=si(Y||V,M),z=l;break}B.call(L,_,new cb(L,{sourceEvent:V,subject:R,target:y,identifier:D,active:z,x:q[0]+G,y:q[1]+Q,dx:q[0]-K[0],dy:q[1]-K[1],dispatch:B}),O)}}return y.filter=function(_){return arguments.length?(e=typeof _=="function"?_:$f(!!_),y):e},y.container=function(_){return arguments.length?(t=typeof _=="function"?_:$f(_),y):t},y.subject=function(_){return arguments.length?(n=typeof _=="function"?_:$f(_),y):n},y.touchable=function(_){return arguments.length?(r=typeof _=="function"?_:$f(!!_),y):r},y.on=function(){var _=o.on.apply(o,arguments);return _===o?y:_},y.clickDistance=function(_){return arguments.length?(m=(_=+_)*_,y):Math.sqrt(m)},y}function Bx(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function cC(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function rd(){}var Tu=.7,jh=1/Tu,Nl="\\s*([+-]?\\d+)\\s*",Mu="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Mi="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",d7=/^#([0-9a-f]{3,8})$/,f7=new RegExp(`^rgb\\(${Nl},${Nl},${Nl}\\)$`),h7=new RegExp(`^rgb\\(${Mi},${Mi},${Mi}\\)$`),p7=new RegExp(`^rgba\\(${Nl},${Nl},${Nl},${Mu}\\)$`),m7=new RegExp(`^rgba\\(${Mi},${Mi},${Mi},${Mu}\\)$`),g7=new RegExp(`^hsl\\(${Mu},${Mi},${Mi}\\)$`),y7=new RegExp(`^hsla\\(${Mu},${Mi},${Mi},${Mu}\\)$`),$E={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};Bx(rd,go,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:UE,formatHex:UE,formatHex8:b7,formatHsl:x7,formatRgb:FE,toString:FE});function UE(){return this.rgb().formatHex()}function b7(){return this.rgb().formatHex8()}function x7(){return uC(this).formatHsl()}function FE(){return this.rgb().formatRgb()}function go(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=d7.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?qE(t):n===3?new hr(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Uf(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Uf(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=f7.exec(e))?new hr(t[1],t[2],t[3],1):(t=h7.exec(e))?new hr(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=p7.exec(e))?Uf(t[1],t[2],t[3],t[4]):(t=m7.exec(e))?Uf(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=g7.exec(e))?GE(t[1],t[2]/100,t[3]/100,1):(t=y7.exec(e))?GE(t[1],t[2]/100,t[3]/100,t[4]):$E.hasOwnProperty(e)?qE($E[e]):e==="transparent"?new hr(NaN,NaN,NaN,0):null}function qE(e){return new hr(e>>16&255,e>>8&255,e&255,1)}function Uf(e,t,n,r){return r<=0&&(e=t=n=NaN),new hr(e,t,n,r)}function v7(e){return e instanceof rd||(e=go(e)),e?(e=e.rgb(),new hr(e.r,e.g,e.b,e.opacity)):new hr}function ub(e,t,n,r){return arguments.length===1?v7(e):new hr(e,t,n,r??1)}function hr(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Bx(hr,ub,cC(rd,{brighter(e){return e=e==null?jh:Math.pow(jh,e),new hr(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Tu:Math.pow(Tu,e),new hr(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new hr(co(this.r),co(this.g),co(this.b),Ch(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:HE,formatHex:HE,formatHex8:w7,formatRgb:KE,toString:KE}));function HE(){return`#${Js(this.r)}${Js(this.g)}${Js(this.b)}`}function w7(){return`#${Js(this.r)}${Js(this.g)}${Js(this.b)}${Js((isNaN(this.opacity)?1:this.opacity)*255)}`}function KE(){const e=Ch(this.opacity);return`${e===1?"rgb(":"rgba("}${co(this.r)}, ${co(this.g)}, ${co(this.b)}${e===1?")":`, ${e})`}`}function Ch(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function co(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Js(e){return e=co(e),(e<16?"0":"")+e.toString(16)}function GE(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new oi(e,t,n,r)}function uC(e){if(e instanceof oi)return new oi(e.h,e.s,e.l,e.opacity);if(e instanceof rd||(e=go(e)),!e)return new oi;if(e instanceof oi)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,a=Math.min(t,n,r),o=Math.max(t,n,r),l=NaN,d=o-a,f=(o+a)/2;return d?(t===o?l=(n-r)/d+(n<r)*6:n===o?l=(r-t)/d+2:l=(t-n)/d+4,d/=f<.5?o+a:2-o-a,l*=60):d=f>0&&f<1?0:l,new oi(l,d,f,e.opacity)}function k7(e,t,n,r){return arguments.length===1?uC(e):new oi(e,t,n,r??1)}function oi(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Bx(oi,k7,cC(rd,{brighter(e){return e=e==null?jh:Math.pow(jh,e),new oi(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Tu:Math.pow(Tu,e),new oi(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,a=2*n-r;return new hr(dy(e>=240?e-240:e+120,a,r),dy(e,a,r),dy(e<120?e+240:e-120,a,r),this.opacity)},clamp(){return new oi(VE(this.h),Ff(this.s),Ff(this.l),Ch(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=Ch(this.opacity);return`${e===1?"hsl(":"hsla("}${VE(this.h)}, ${Ff(this.s)*100}%, ${Ff(this.l)*100}%${e===1?")":`, ${e})`}`}}));function VE(e){return e=(e||0)%360,e<0?e+360:e}function Ff(e){return Math.max(0,Math.min(1,e||0))}function dy(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 $x=e=>()=>e;function E7(e,t){return function(n){return e+n*t}}function S7(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function N7(e){return(e=+e)==1?dC:function(t,n){return n-t?S7(t,n,e):$x(isNaN(t)?n:t)}}function dC(e,t){var n=t-e;return n?E7(e,n):$x(isNaN(e)?t:e)}const Ah=(function e(t){var n=N7(t);function r(a,o){var l=n((a=ub(a)).r,(o=ub(o)).r),d=n(a.g,o.g),f=n(a.b,o.b),h=dC(a.opacity,o.opacity);return function(g){return a.r=l(g),a.g=d(g),a.b=f(g),a.opacity=h(g),a+""}}return r.gamma=e,r})(1);function _7(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),a;return function(o){for(a=0;a<n;++a)r[a]=e[a]*(1-o)+t[a]*o;return r}}function j7(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function C7(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,a=new Array(r),o=new Array(n),l;for(l=0;l<r;++l)a[l]=yu(e[l],t[l]);for(;l<n;++l)o[l]=t[l];return function(d){for(l=0;l<r;++l)o[l]=a[l](d);return o}}function A7(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function Ci(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function T7(e,t){var n={},r={},a;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(a in t)a in e?n[a]=yu(e[a],t[a]):r[a]=t[a];return function(o){for(a in n)r[a]=n[a](o);return r}}var db=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,fy=new RegExp(db.source,"g");function M7(e){return function(){return e}}function D7(e){return function(t){return e(t)+""}}function fC(e,t){var n=db.lastIndex=fy.lastIndex=0,r,a,o,l=-1,d=[],f=[];for(e=e+"",t=t+"";(r=db.exec(e))&&(a=fy.exec(t));)(o=a.index)>n&&(o=t.slice(n,o),d[l]?d[l]+=o:d[++l]=o),(r=r[0])===(a=a[0])?d[l]?d[l]+=a:d[++l]=a:(d[++l]=null,f.push({i:l,x:Ci(r,a)})),n=fy.lastIndex;return n<t.length&&(o=t.slice(n),d[l]?d[l]+=o:d[++l]=o),d.length<2?f[0]?D7(f[0].x):M7(t):(t=f.length,function(h){for(var g=0,m;g<t;++g)d[(m=f[g]).i]=m.x(h);return d.join("")})}function yu(e,t){var n=typeof t,r;return t==null||n==="boolean"?$x(t):(n==="number"?Ci:n==="string"?(r=go(t))?(t=r,Ah):fC:t instanceof go?Ah:t instanceof Date?A7:j7(t)?_7:Array.isArray(t)?C7:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?T7:Ci)(e,t)}var YE=180/Math.PI,fb={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function hC(e,t,n,r,a,o){var l,d,f;return(l=Math.sqrt(e*e+t*t))&&(e/=l,t/=l),(f=e*n+t*r)&&(n-=e*f,r-=t*f),(d=Math.sqrt(n*n+r*r))&&(n/=d,r/=d,f/=d),e*r<t*n&&(e=-e,t=-t,f=-f,l=-l),{translateX:a,translateY:o,rotate:Math.atan2(t,e)*YE,skewX:Math.atan(f)*YE,scaleX:l,scaleY:d}}var qf;function O7(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?fb:hC(t.a,t.b,t.c,t.d,t.e,t.f)}function R7(e){return e==null||(qf||(qf=document.createElementNS("http://www.w3.org/2000/svg","g")),qf.setAttribute("transform",e),!(e=qf.transform.baseVal.consolidate()))?fb:(e=e.matrix,hC(e.a,e.b,e.c,e.d,e.e,e.f))}function pC(e,t,n,r){function a(h){return h.length?h.pop()+" ":""}function o(h,g,m,y,b,w){if(h!==m||g!==y){var v=b.push("translate(",null,t,null,n);w.push({i:v-4,x:Ci(h,m)},{i:v-2,x:Ci(g,y)})}else(m||y)&&b.push("translate("+m+t+y+n)}function l(h,g,m,y){h!==g?(h-g>180?g+=360:g-h>180&&(h+=360),y.push({i:m.push(a(m)+"rotate(",null,r)-2,x:Ci(h,g)})):g&&m.push(a(m)+"rotate("+g+r)}function d(h,g,m,y){h!==g?y.push({i:m.push(a(m)+"skewX(",null,r)-2,x:Ci(h,g)}):g&&m.push(a(m)+"skewX("+g+r)}function f(h,g,m,y,b,w){if(h!==m||g!==y){var v=b.push(a(b)+"scale(",null,",",null,")");w.push({i:v-4,x:Ci(h,m)},{i:v-2,x:Ci(g,y)})}else(m!==1||y!==1)&&b.push(a(b)+"scale("+m+","+y+")")}return function(h,g){var m=[],y=[];return h=e(h),g=e(g),o(h.translateX,h.translateY,g.translateX,g.translateY,m,y),l(h.rotate,g.rotate,m,y),d(h.skewX,g.skewX,m,y),f(h.scaleX,h.scaleY,g.scaleX,g.scaleY,m,y),h=g=null,function(b){for(var w=-1,v=y.length,S;++w<v;)m[(S=y[w]).i]=S.x(b);return m.join("")}}}var L7=pC(O7,"px, ","px)","deg)"),I7=pC(R7,", ",")",")"),z7=1e-12;function QE(e){return((e=Math.exp(e))+1/e)/2}function P7(e){return((e=Math.exp(e))-1/e)/2}function B7(e){return((e=Math.exp(2*e))-1)/(e+1)}const ih=(function e(t,n,r){function a(o,l){var d=o[0],f=o[1],h=o[2],g=l[0],m=l[1],y=l[2],b=g-d,w=m-f,v=b*b+w*w,S,E;if(v<z7)E=Math.log(y/h)/t,S=function(O){return[d+O*b,f+O*w,h*Math.exp(t*O*E)]};else{var C=Math.sqrt(v),N=(y*y-h*h+r*v)/(2*h*n*C),_=(y*y-h*h-r*v)/(2*y*n*C),M=Math.log(Math.sqrt(N*N+1)-N),A=Math.log(Math.sqrt(_*_+1)-_);E=(A-M)/t,S=function(O){var D=O*E,U=QE(M),B=h/(n*C)*(U*B7(t*D+M)-P7(M));return[d+B*b,f+B*w,h*U/QE(t*D+M)]}}return S.duration=E*1e3*t/Math.SQRT2,S}return a.rho=function(o){var l=Math.max(.001,+o),d=l*l,f=d*d;return e(l,d,f)},a})(Math.SQRT2,2,4);var ql=0,uu=0,su=0,mC=1e3,Th,du,Mh=0,yo=0,dp=0,Du=typeof performance=="object"&&performance.now?performance:Date,gC=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Ux(){return yo||(gC($7),yo=Du.now()+dp)}function $7(){yo=0}function Dh(){this._call=this._time=this._next=null}Dh.prototype=yC.prototype={constructor:Dh,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Ux():+n)+(t==null?0:+t),!this._next&&du!==this&&(du?du._next=this:Th=this,du=this),this._call=e,this._time=n,hb()},stop:function(){this._call&&(this._call=null,this._time=1/0,hb())}};function yC(e,t,n){var r=new Dh;return r.restart(e,t,n),r}function U7(){Ux(),++ql;for(var e=Th,t;e;)(t=yo-e._time)>=0&&e._call.call(void 0,t),e=e._next;--ql}function WE(){yo=(Mh=Du.now())+dp,ql=uu=0;try{U7()}finally{ql=0,q7(),yo=0}}function F7(){var e=Du.now(),t=e-Mh;t>mC&&(dp-=t,Mh=e)}function q7(){for(var e,t=Th,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Th=n);du=e,hb(r)}function hb(e){if(!ql){uu&&(uu=clearTimeout(uu));var t=e-yo;t>24?(e<1/0&&(uu=setTimeout(WE,e-Du.now()-dp)),su&&(su=clearInterval(su))):(su||(Mh=Du.now(),su=setInterval(F7,mC)),ql=1,gC(WE))}}function XE(e,t,n){var r=new Dh;return t=t==null?0:+t,r.restart(a=>{r.stop(),e(a+t)},t,n),r}var H7=cp("start","end","cancel","interrupt"),K7=[],bC=0,ZE=1,pb=2,ah=3,JE=4,mb=5,sh=6;function fp(e,t,n,r,a,o){var l=e.__transition;if(!l)e.__transition={};else if(n in l)return;G7(e,n,{name:t,index:r,group:a,on:H7,tween:K7,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:bC})}function Fx(e,t){var n=gi(e,t);if(n.state>bC)throw new Error("too late; already scheduled");return n}function Ii(e,t){var n=gi(e,t);if(n.state>ah)throw new Error("too late; already running");return n}function gi(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function G7(e,t,n){var r=e.__transition,a;r[t]=n,n.timer=yC(o,0,n.time);function o(h){n.state=ZE,n.timer.restart(l,n.delay,n.time),n.delay<=h&&l(h-n.delay)}function l(h){var g,m,y,b;if(n.state!==ZE)return f();for(g in r)if(b=r[g],b.name===n.name){if(b.state===ah)return XE(l);b.state===JE?(b.state=sh,b.timer.stop(),b.on.call("interrupt",e,e.__data__,b.index,b.group),delete r[g]):+g<t&&(b.state=sh,b.timer.stop(),b.on.call("cancel",e,e.__data__,b.index,b.group),delete r[g])}if(XE(function(){n.state===ah&&(n.state=JE,n.timer.restart(d,n.delay,n.time),d(h))}),n.state=pb,n.on.call("start",e,e.__data__,n.index,n.group),n.state===pb){for(n.state=ah,a=new Array(y=n.tween.length),g=0,m=-1;g<y;++g)(b=n.tween[g].value.call(e,e.__data__,n.index,n.group))&&(a[++m]=b);a.length=m+1}}function d(h){for(var g=h<n.duration?n.ease.call(null,h/n.duration):(n.timer.restart(f),n.state=mb,1),m=-1,y=a.length;++m<y;)a[m].call(e,g);n.state===mb&&(n.on.call("end",e,e.__data__,n.index,n.group),f())}function f(){n.state=sh,n.timer.stop(),delete r[t];for(var h in r)return;delete e.__transition}}function oh(e,t){var n=e.__transition,r,a,o=!0,l;if(n){t=t==null?null:t+"";for(l in n){if((r=n[l]).name!==t){o=!1;continue}a=r.state>pb&&r.state<mb,r.state=sh,r.timer.stop(),r.on.call(a?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[l]}o&&delete e.__transition}}function V7(e){return this.each(function(){oh(this,e)})}function Y7(e,t){var n,r;return function(){var a=Ii(this,e),o=a.tween;if(o!==n){r=n=o;for(var l=0,d=r.length;l<d;++l)if(r[l].name===t){r=r.slice(),r.splice(l,1);break}}a.tween=r}}function Q7(e,t,n){var r,a;if(typeof n!="function")throw new Error;return function(){var o=Ii(this,e),l=o.tween;if(l!==r){a=(r=l).slice();for(var d={name:t,value:n},f=0,h=a.length;f<h;++f)if(a[f].name===t){a[f]=d;break}f===h&&a.push(d)}o.tween=a}}function W7(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=gi(this.node(),n).tween,a=0,o=r.length,l;a<o;++a)if((l=r[a]).name===e)return l.value;return null}return this.each((t==null?Y7:Q7)(n,e,t))}function qx(e,t,n){var r=e._id;return e.each(function(){var a=Ii(this,r);(a.value||(a.value={}))[t]=n.apply(this,arguments)}),function(a){return gi(a,r).value[t]}}function xC(e,t){var n;return(typeof t=="number"?Ci:t instanceof go?Ah:(n=go(t))?(t=n,Ah):fC)(e,t)}function X7(e){return function(){this.removeAttribute(e)}}function Z7(e){return function(){this.removeAttributeNS(e.space,e.local)}}function J7(e,t,n){var r,a=n+"",o;return function(){var l=this.getAttribute(e);return l===a?null:l===r?o:o=t(r=l,n)}}function eK(e,t,n){var r,a=n+"",o;return function(){var l=this.getAttributeNS(e.space,e.local);return l===a?null:l===r?o:o=t(r=l,n)}}function tK(e,t,n){var r,a,o;return function(){var l,d=n(this),f;return d==null?void this.removeAttribute(e):(l=this.getAttribute(e),f=d+"",l===f?null:l===r&&f===a?o:(a=f,o=t(r=l,d)))}}function nK(e,t,n){var r,a,o;return function(){var l,d=n(this),f;return d==null?void this.removeAttributeNS(e.space,e.local):(l=this.getAttributeNS(e.space,e.local),f=d+"",l===f?null:l===r&&f===a?o:(a=f,o=t(r=l,d)))}}function rK(e,t){var n=up(e),r=n==="transform"?I7:xC;return this.attrTween(e,typeof t=="function"?(n.local?nK:tK)(n,r,qx(this,"attr."+e,t)):t==null?(n.local?Z7:X7)(n):(n.local?eK:J7)(n,r,t))}function iK(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function aK(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function sK(e,t){var n,r;function a(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&aK(e,o)),n}return a._value=t,a}function oK(e,t){var n,r;function a(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&iK(e,o)),n}return a._value=t,a}function lK(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=up(e);return this.tween(n,(r.local?sK:oK)(r,t))}function cK(e,t){return function(){Fx(this,e).delay=+t.apply(this,arguments)}}function uK(e,t){return t=+t,function(){Fx(this,e).delay=t}}function dK(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?cK:uK)(t,e)):gi(this.node(),t).delay}function fK(e,t){return function(){Ii(this,e).duration=+t.apply(this,arguments)}}function hK(e,t){return t=+t,function(){Ii(this,e).duration=t}}function pK(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?fK:hK)(t,e)):gi(this.node(),t).duration}function mK(e,t){if(typeof t!="function")throw new Error;return function(){Ii(this,e).ease=t}}function gK(e){var t=this._id;return arguments.length?this.each(mK(t,e)):gi(this.node(),t).ease}function yK(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ii(this,e).ease=n}}function bK(e){if(typeof e!="function")throw new Error;return this.each(yK(this._id,e))}function xK(e){typeof e!="function"&&(e=Wj(e));for(var t=this._groups,n=t.length,r=new Array(n),a=0;a<n;++a)for(var o=t[a],l=o.length,d=r[a]=[],f,h=0;h<l;++h)(f=o[h])&&e.call(f,f.__data__,h,o)&&d.push(f);return new ba(r,this._parents,this._name,this._id)}function vK(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,a=n.length,o=Math.min(r,a),l=new Array(r),d=0;d<o;++d)for(var f=t[d],h=n[d],g=f.length,m=l[d]=new Array(g),y,b=0;b<g;++b)(y=f[b]||h[b])&&(m[b]=y);for(;d<r;++d)l[d]=t[d];return new ba(l,this._parents,this._name,this._id)}function wK(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 kK(e,t,n){var r,a,o=wK(t)?Fx:Ii;return function(){var l=o(this,e),d=l.on;d!==r&&(a=(r=d).copy()).on(t,n),l.on=a}}function EK(e,t){var n=this._id;return arguments.length<2?gi(this.node(),n).on.on(e):this.each(kK(n,e,t))}function SK(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function NK(){return this.on("end.remove",SK(this._id))}function _K(e){var t=this._name,n=this._id;typeof e!="function"&&(e=zx(e));for(var r=this._groups,a=r.length,o=new Array(a),l=0;l<a;++l)for(var d=r[l],f=d.length,h=o[l]=new Array(f),g,m,y=0;y<f;++y)(g=d[y])&&(m=e.call(g,g.__data__,y,d))&&("__data__"in g&&(m.__data__=g.__data__),h[y]=m,fp(h[y],t,n,y,h,gi(g,n)));return new ba(o,this._parents,t,n)}function jK(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Qj(e));for(var r=this._groups,a=r.length,o=[],l=[],d=0;d<a;++d)for(var f=r[d],h=f.length,g,m=0;m<h;++m)if(g=f[m]){for(var y=e.call(g,g.__data__,m,f),b,w=gi(g,n),v=0,S=y.length;v<S;++v)(b=y[v])&&fp(b,t,n,v,y,w);o.push(y),l.push(g)}return new ba(o,l,t,n)}var CK=nd.prototype.constructor;function AK(){return new CK(this._groups,this._parents)}function TK(e,t){var n,r,a;return function(){var o=Fl(this,e),l=(this.style.removeProperty(e),Fl(this,e));return o===l?null:o===n&&l===r?a:a=t(n=o,r=l)}}function vC(e){return function(){this.style.removeProperty(e)}}function MK(e,t,n){var r,a=n+"",o;return function(){var l=Fl(this,e);return l===a?null:l===r?o:o=t(r=l,n)}}function DK(e,t,n){var r,a,o;return function(){var l=Fl(this,e),d=n(this),f=d+"";return d==null&&(f=d=(this.style.removeProperty(e),Fl(this,e))),l===f?null:l===r&&f===a?o:(a=f,o=t(r=l,d))}}function OK(e,t){var n,r,a,o="style."+t,l="end."+o,d;return function(){var f=Ii(this,e),h=f.on,g=f.value[o]==null?d||(d=vC(t)):void 0;(h!==n||a!==g)&&(r=(n=h).copy()).on(l,a=g),f.on=r}}function RK(e,t,n){var r=(e+="")=="transform"?L7:xC;return t==null?this.styleTween(e,TK(e,r)).on("end.style."+e,vC(e)):typeof t=="function"?this.styleTween(e,DK(e,r,qx(this,"style."+e,t))).each(OK(this._id,e)):this.styleTween(e,MK(e,r,t),n).on("end.style."+e,null)}function LK(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function IK(e,t,n){var r,a;function o(){var l=t.apply(this,arguments);return l!==a&&(r=(a=l)&&LK(e,l,n)),r}return o._value=t,o}function zK(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,IK(e,t,n??""))}function PK(e){return function(){this.textContent=e}}function BK(e){return function(){var t=e(this);this.textContent=t??""}}function $K(e){return this.tween("text",typeof e=="function"?BK(qx(this,"text",e)):PK(e==null?"":e+""))}function UK(e){return function(t){this.textContent=e.call(this,t)}}function FK(e){var t,n;function r(){var a=e.apply(this,arguments);return a!==n&&(t=(n=a)&&UK(a)),t}return r._value=e,r}function qK(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,FK(e))}function HK(){for(var e=this._name,t=this._id,n=wC(),r=this._groups,a=r.length,o=0;o<a;++o)for(var l=r[o],d=l.length,f,h=0;h<d;++h)if(f=l[h]){var g=gi(f,t);fp(f,e,n,h,l,{time:g.time+g.delay+g.duration,delay:0,duration:g.duration,ease:g.ease})}return new ba(r,this._parents,e,n)}function KK(){var e,t,n=this,r=n._id,a=n.size();return new Promise(function(o,l){var d={value:l},f={value:function(){--a===0&&o()}};n.each(function(){var h=Ii(this,r),g=h.on;g!==e&&(t=(e=g).copy(),t._.cancel.push(d),t._.interrupt.push(d),t._.end.push(f)),h.on=t}),a===0&&o()})}var GK=0;function ba(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function wC(){return++GK}var aa=nd.prototype;ba.prototype={constructor:ba,select:_K,selectAll:jK,selectChild:aa.selectChild,selectChildren:aa.selectChildren,filter:xK,merge:vK,selection:AK,transition:HK,call:aa.call,nodes:aa.nodes,node:aa.node,size:aa.size,empty:aa.empty,each:aa.each,on:EK,attr:rK,attrTween:lK,style:RK,styleTween:zK,text:$K,textTween:qK,remove:NK,tween:W7,delay:dK,duration:pK,ease:gK,easeVarying:bK,end:KK,[Symbol.iterator]:aa[Symbol.iterator]};function VK(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var YK={time:null,delay:0,duration:250,ease:VK};function QK(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 WK(e){var t,n;e instanceof ba?(t=e._id,e=e._name):(t=wC(),(n=YK).time=Ux(),e=e==null?null:e+"");for(var r=this._groups,a=r.length,o=0;o<a;++o)for(var l=r[o],d=l.length,f,h=0;h<d;++h)(f=l[h])&&fp(f,e,t,h,l,n||QK(f,t));return new ba(r,this._parents,e,t)}nd.prototype.interrupt=V7;nd.prototype.transition=WK;const Hf=e=>()=>e;function XK(e,{sourceEvent:t,target:n,transform:r,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:r,enumerable:!0,configurable:!0},_:{value:a}})}function fa(e,t,n){this.k=e,this.x=t,this.y=n}fa.prototype={constructor:fa,scale:function(e){return e===1?this:new fa(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new fa(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 hp=new fa(1,0,0);kC.prototype=fa.prototype;function kC(e){for(;!e.__zoom;)if(!(e=e.parentNode))return hp;return e.__zoom}function hy(e){e.stopImmediatePropagation()}function ou(e){e.preventDefault(),e.stopImmediatePropagation()}function ZK(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function JK(){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 eS(){return this.__zoom||hp}function eG(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function tG(){return navigator.maxTouchPoints||"ontouchstart"in this}function nG(e,t,n){var r=e.invertX(t[0][0])-n[0][0],a=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],l=e.invertY(t[1][1])-n[1][1];return e.translate(a>r?(r+a)/2:Math.min(0,r)||Math.max(0,a),l>o?(o+l)/2:Math.min(0,o)||Math.max(0,l))}function EC(){var e=ZK,t=JK,n=nG,r=eG,a=tG,o=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],d=250,f=ih,h=cp("start","zoom","end"),g,m,y,b=500,w=150,v=0,S=10;function E(R){R.property("__zoom",eS).on("wheel.zoom",D,{passive:!1}).on("mousedown.zoom",U).on("dblclick.zoom",B).filter(a).on("touchstart.zoom",q).on("touchmove.zoom",G).on("touchend.zoom touchcancel.zoom",Q).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}E.transform=function(R,H,L,V){var Y=R.selection?R.selection():R;Y.property("__zoom",eS),R!==Y?M(R,H,L,V):Y.interrupt().each(function(){A(this,arguments).event(V).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},E.scaleBy=function(R,H,L,V){E.scaleTo(R,function(){var Y=this.__zoom.k,K=typeof H=="function"?H.apply(this,arguments):H;return Y*K},L,V)},E.scaleTo=function(R,H,L,V){E.transform(R,function(){var Y=t.apply(this,arguments),K=this.__zoom,z=L==null?_(Y):typeof L=="function"?L.apply(this,arguments):L,$=K.invert(z),P=typeof H=="function"?H.apply(this,arguments):H;return n(N(C(K,P),z,$),Y,l)},L,V)},E.translateBy=function(R,H,L,V){E.transform(R,function(){return n(this.__zoom.translate(typeof H=="function"?H.apply(this,arguments):H,typeof L=="function"?L.apply(this,arguments):L),t.apply(this,arguments),l)},null,V)},E.translateTo=function(R,H,L,V,Y){E.transform(R,function(){var K=t.apply(this,arguments),z=this.__zoom,$=V==null?_(K):typeof V=="function"?V.apply(this,arguments):V;return n(hp.translate($[0],$[1]).scale(z.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof L=="function"?-L.apply(this,arguments):-L),K,l)},V,Y)};function C(R,H){return H=Math.max(o[0],Math.min(o[1],H)),H===R.k?R:new fa(H,R.x,R.y)}function N(R,H,L){var V=H[0]-L[0]*R.k,Y=H[1]-L[1]*R.k;return V===R.x&&Y===R.y?R:new fa(R.k,V,Y)}function _(R){return[(+R[0][0]+ +R[1][0])/2,(+R[0][1]+ +R[1][1])/2]}function M(R,H,L,V){R.on("start.zoom",function(){A(this,arguments).event(V).start()}).on("interrupt.zoom end.zoom",function(){A(this,arguments).event(V).end()}).tween("zoom",function(){var Y=this,K=arguments,z=A(Y,K).event(V),$=t.apply(Y,K),P=L==null?_($):typeof L=="function"?L.apply(Y,K):L,I=Math.max($[1][0]-$[0][0],$[1][1]-$[0][1]),ae=Y.__zoom,me=typeof H=="function"?H.apply(Y,K):H,ve=f(ae.invert(P).concat(I/ae.k),me.invert(P).concat(I/me.k));return function(we){if(we===1)we=me;else{var J=ve(we),de=I/J[2];we=new fa(de,P[0]-J[0]*de,P[1]-J[1]*de)}z.zoom(null,we)}})}function A(R,H,L){return!L&&R.__zooming||new O(R,H)}function O(R,H){this.that=R,this.args=H,this.active=0,this.sourceEvent=null,this.extent=t.apply(R,H),this.taps=0}O.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,H){return this.mouse&&R!=="mouse"&&(this.mouse[1]=H.invert(this.mouse[0])),this.touch0&&R!=="touch"&&(this.touch0[1]=H.invert(this.touch0[0])),this.touch1&&R!=="touch"&&(this.touch1[1]=H.invert(this.touch1[0])),this.that.__zoom=H,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(R){var H=_r(this.that).datum();h.call(R,this.that,new XK(R,{sourceEvent:this.sourceEvent,target:E,transform:this.that.__zoom,dispatch:h}),H)}};function D(R,...H){if(!e.apply(this,arguments))return;var L=A(this,H).event(R),V=this.__zoom,Y=Math.max(o[0],Math.min(o[1],V.k*Math.pow(2,r.apply(this,arguments)))),K=si(R);if(L.wheel)(L.mouse[0][0]!==K[0]||L.mouse[0][1]!==K[1])&&(L.mouse[1]=V.invert(L.mouse[0]=K)),clearTimeout(L.wheel);else{if(V.k===Y)return;L.mouse=[K,V.invert(K)],oh(this),L.start()}ou(R),L.wheel=setTimeout(z,w),L.zoom("mouse",n(N(C(V,Y),L.mouse[0],L.mouse[1]),L.extent,l));function z(){L.wheel=null,L.end()}}function U(R,...H){if(y||!e.apply(this,arguments))return;var L=R.currentTarget,V=A(this,H,!0).event(R),Y=_r(R.view).on("mousemove.zoom",P,!0).on("mouseup.zoom",I,!0),K=si(R,L),z=R.clientX,$=R.clientY;sC(R.view),hy(R),V.mouse=[K,this.__zoom.invert(K)],oh(this),V.start();function P(ae){if(ou(ae),!V.moved){var me=ae.clientX-z,ve=ae.clientY-$;V.moved=me*me+ve*ve>v}V.event(ae).zoom("mouse",n(N(V.that.__zoom,V.mouse[0]=si(ae,L),V.mouse[1]),V.extent,l))}function I(ae){Y.on("mousemove.zoom mouseup.zoom",null),oC(ae.view,V.moved),ou(ae),V.event(ae).end()}}function B(R,...H){if(e.apply(this,arguments)){var L=this.__zoom,V=si(R.changedTouches?R.changedTouches[0]:R,this),Y=L.invert(V),K=L.k*(R.shiftKey?.5:2),z=n(N(C(L,K),V,Y),t.apply(this,H),l);ou(R),d>0?_r(this).transition().duration(d).call(M,z,V,R):_r(this).call(E.transform,z,V,R)}}function q(R,...H){if(e.apply(this,arguments)){var L=R.touches,V=L.length,Y=A(this,H,R.changedTouches.length===V).event(R),K,z,$,P;for(hy(R),z=0;z<V;++z)$=L[z],P=si($,this),P=[P,this.__zoom.invert(P),$.identifier],Y.touch0?!Y.touch1&&Y.touch0[2]!==P[2]&&(Y.touch1=P,Y.taps=0):(Y.touch0=P,K=!0,Y.taps=1+!!g);g&&(g=clearTimeout(g)),K&&(Y.taps<2&&(m=P[0],g=setTimeout(function(){g=null},b)),oh(this),Y.start())}}function G(R,...H){if(this.__zooming){var L=A(this,H).event(R),V=R.changedTouches,Y=V.length,K,z,$,P;for(ou(R),K=0;K<Y;++K)z=V[K],$=si(z,this),L.touch0&&L.touch0[2]===z.identifier?L.touch0[0]=$:L.touch1&&L.touch1[2]===z.identifier&&(L.touch1[0]=$);if(z=L.that.__zoom,L.touch1){var I=L.touch0[0],ae=L.touch0[1],me=L.touch1[0],ve=L.touch1[1],we=(we=me[0]-I[0])*we+(we=me[1]-I[1])*we,J=(J=ve[0]-ae[0])*J+(J=ve[1]-ae[1])*J;z=C(z,Math.sqrt(we/J)),$=[(I[0]+me[0])/2,(I[1]+me[1])/2],P=[(ae[0]+ve[0])/2,(ae[1]+ve[1])/2]}else if(L.touch0)$=L.touch0[0],P=L.touch0[1];else return;L.zoom("touch",n(N(z,$,P),L.extent,l))}}function Q(R,...H){if(this.__zooming){var L=A(this,H).event(R),V=R.changedTouches,Y=V.length,K,z;for(hy(R),y&&clearTimeout(y),y=setTimeout(function(){y=null},b),K=0;K<Y;++K)z=V[K],L.touch0&&L.touch0[2]===z.identifier?delete L.touch0:L.touch1&&L.touch1[2]===z.identifier&&delete L.touch1;if(L.touch1&&!L.touch0&&(L.touch0=L.touch1,delete L.touch1),L.touch0)L.touch0[1]=this.__zoom.invert(L.touch0[0]);else if(L.end(),L.taps===2&&(z=si(z,this),Math.hypot(m[0]-z[0],m[1]-z[1])<S)){var $=_r(this).on("dblclick.zoom");$&&$.apply(this,arguments)}}}return E.wheelDelta=function(R){return arguments.length?(r=typeof R=="function"?R:Hf(+R),E):r},E.filter=function(R){return arguments.length?(e=typeof R=="function"?R:Hf(!!R),E):e},E.touchable=function(R){return arguments.length?(a=typeof R=="function"?R:Hf(!!R),E):a},E.extent=function(R){return arguments.length?(t=typeof R=="function"?R:Hf([[+R[0][0],+R[0][1]],[+R[1][0],+R[1][1]]]),E):t},E.scaleExtent=function(R){return arguments.length?(o[0]=+R[0],o[1]=+R[1],E):[o[0],o[1]]},E.translateExtent=function(R){return arguments.length?(l[0][0]=+R[0][0],l[1][0]=+R[1][0],l[0][1]=+R[0][1],l[1][1]=+R[1][1],E):[[l[0][0],l[0][1]],[l[1][0],l[1][1]]]},E.constrain=function(R){return arguments.length?(n=R,E):n},E.duration=function(R){return arguments.length?(d=+R,E):d},E.interpolate=function(R){return arguments.length?(f=R,E):f},E.on=function(){var R=h.on.apply(h,arguments);return R===h?E:R},E.clickDistance=function(R){return arguments.length?(v=(R=+R)*R,E):Math.sqrt(v)},E.tapDistance=function(R){return arguments.length?(S=+R,E):S},E}const hi={error001:(e="react")=>`Seems like you have not used ${e==="svelte"?"SvelteFlowProvider":"ReactFlowProvider"} as an ancestor. Help: https://${e}flow.dev/error#001`,error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:r}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs.",error016:e=>`Edge with id "${e}" does not exist, it may have been removed. This can happen when an edge is deleted before the "onEdgeClick" handler is called.`},Ou=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],SC=["Enter"," ","Escape"],NC={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Hl;(function(e){e.Strict="strict",e.Loose="loose"})(Hl||(Hl={}));var uo;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(uo||(uo={}));var Ru;(function(e){e.Partial="partial",e.Full="full"})(Ru||(Ru={}));const _C={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var os;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(os||(os={}));var Oh;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Oh||(Oh={}));var He;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(He||(He={}));const tS={[He.Left]:He.Right,[He.Right]:He.Left,[He.Top]:He.Bottom,[He.Bottom]:He.Top};function jC(e){return e===null?null:e?"valid":"invalid"}const CC=e=>"id"in e&&"source"in e&&"target"in e,rG=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Hx=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),id=(e,t=[0,0])=>{const{width:n,height:r}=va(e),a=e.origin??t,o=n*a[0],l=r*a[1];return{x:e.position.x-o,y:e.position.y-l}},iG=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,a)=>{const o=typeof a=="string";let l=!t.nodeLookup&&!o?a:void 0;t.nodeLookup&&(l=o?t.nodeLookup.get(a):Hx(a)?a:t.nodeLookup.get(a.id));const d=l?Rh(l,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return pp(r,d)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return mp(n)},ad=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(a=>{(t.filter===void 0||t.filter(a))&&(n=pp(n,Rh(a)),r=!0)}),r?mp(n):{x:0,y:0,width:0,height:0}},Kx=(e,t,[n,r,a]=[0,0,1],o=!1,l=!1)=>{const d=(t.x-n)/a,f=(t.y-r)/a,h=t.width/a,g=t.height/a,m=[];for(const y of e.values()){const{measured:b,selectable:w=!0,hidden:v=!1}=y;if(l&&!w||v)continue;const S=b.width??y.width??y.initialWidth??0,E=b.height??y.height??y.initialHeight??0,{x:C,y:N}=y.internals.positionAbsolute,_=DC(d,f,h,g,C,N,S,E),M=S*E,A=o&&_>0;(!y.internals.handleBounds||A||_>=M||y.dragging)&&m.push(y)}return m},aG=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function sG(e,t){const n=new Map,r=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)&&(!r||r.has(a.id))&&n.set(a.id,a)}),n}async function oG({nodes:e,width:t,height:n,panZoom:r,minZoom:a,maxZoom:o},l){if(e.size===0)return!0;const d=sG(e,l),f=ad(d),h=Vx(f,t,n,(l==null?void 0:l.minZoom)??a,(l==null?void 0:l.maxZoom)??o,(l==null?void 0:l.padding)??.1);return await r.setViewport(h,{duration:l==null?void 0:l.duration,ease:l==null?void 0:l.ease,interpolate:l==null?void 0:l.interpolate}),!0}function AC({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:a,onError:o}){const l=n.get(e),d=l.parentId?n.get(l.parentId):void 0,{x:f,y:h}=d?d.internals.positionAbsolute:{x:0,y:0},g=l.origin??r;let m=l.extent||a;if(l.extent==="parent"&&!l.expandParent)if(!d)o==null||o("005",hi.error005());else{const b=d.measured.width,w=d.measured.height;b&&w&&(m=[[f,h],[f+b,h+w]])}else d&&xo(l.extent)&&(m=[[l.extent[0][0]+f,l.extent[0][1]+h],[l.extent[1][0]+f,l.extent[1][1]+h]]);const y=xo(m)?bo(t,m,l.measured):t;return(l.measured.width===void 0||l.measured.height===void 0)&&(o==null||o("015",hi.error015())),{position:{x:y.x-f+(l.measured.width??0)*g[0],y:y.y-h+(l.measured.height??0)*g[1]},positionAbsolute:y}}async function lG({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:a}){const o=new Set(e.map(y=>y.id)),l=[];for(const y of n){if(y.deletable===!1)continue;const b=o.has(y.id),w=!b&&y.parentId&&l.find(v=>v.id===y.parentId);(b||w)&&l.push(y)}const d=new Set(t.map(y=>y.id)),f=r.filter(y=>y.deletable!==!1),g=aG(l,f);for(const y of f)d.has(y.id)&&!g.find(w=>w.id===y.id)&&g.push(y);if(!a)return{edges:g,nodes:l};const m=await a({nodes:l,edges:g});return typeof m=="boolean"?m?{edges:g,nodes:l}:{edges:[],nodes:[]}:m}const Kl=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),bo=(e={x:0,y:0},t,n)=>({x:Kl(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:Kl(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function TC(e,t,n){const{width:r,height:a}=va(n),{x:o,y:l}=n.internals.positionAbsolute;return bo(e,[[o,l],[o+r,l+a]],t)}const nS=(e,t,n)=>e<t?Kl(Math.abs(e-t),1,t)/t:e>n?-Kl(Math.abs(e-n),1,t)/t:0,Gx=(e,t,n=15,r=40)=>{const a=nS(e.x,r,t.width-r)*n,o=nS(e.y,r,t.height-r)*n;return[a,o]},pp=(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)}),gb=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),mp=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Lu=(e,t=[0,0])=>{var a,o;const{x:n,y:r}=Hx(e)?e.internals.positionAbsolute:id(e,t);return{x:n,y:r,width:((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0,height:((o=e.measured)==null?void 0:o.height)??e.height??e.initialHeight??0}},Rh=(e,t=[0,0])=>{var a,o;const{x:n,y:r}=Hx(e)?e.internals.positionAbsolute:id(e,t);return{x:n,y:r,x2:n+(((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0),y2:r+(((o=e.measured)==null?void 0:o.height)??e.height??e.initialHeight??0)}},MC=(e,t)=>mp(pp(gb(e),gb(t))),DC=(e,t,n,r,a,o,l,d)=>{const f=Math.max(0,Math.min(e+n,a+l)-Math.max(e,a)),h=Math.max(0,Math.min(t+r,o+d)-Math.max(t,o));return Math.ceil(f*h)},Lh=(e,t)=>DC(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),rS=e=>li(e.width)&&li(e.height)&&li(e.x)&&li(e.y),li=e=>!isNaN(e)&&isFinite(e),OC=(e,t)=>(n,r)=>{},sd=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),od=({x:e,y:t},[n,r,a],o=!1,l=[1,1])=>{const d={x:(e-n)/a,y:(t-r)/a};return o?sd(d,l):d},Gl=({x:e,y:t},[n,r,a])=>({x:e*a+n,y:t*a+r});function ul(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 cG(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=ul(e,n),a=ul(e,t);return{top:r,right:a,bottom:r,left:a,x:a*2,y:r*2}}if(typeof e=="object"){const r=ul(e.top??e.y??0,n),a=ul(e.bottom??e.y??0,n),o=ul(e.left??e.x??0,t),l=ul(e.right??e.x??0,t);return{top:r,right:l,bottom:a,left:o,x:o+l,y:r+a}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function uG(e,t,n,r,a,o){const{x:l,y:d}=Gl(e,[t,n,r]),{x:f,y:h}=Gl({x:e.x+e.width,y:e.y+e.height},[t,n,r]),g=a-f,m=o-h;return{left:Math.floor(l),top:Math.floor(d),right:Math.floor(g),bottom:Math.floor(m)}}const Vx=(e,t,n,r,a,o)=>{const l=cG(o,t,n),d=(t-l.x)/e.width,f=(n-l.y)/e.height,h=Math.min(d,f),g=Kl(h,r,a),m=e.x+e.width/2,y=e.y+e.height/2,b=t/2-m*g,w=n/2-y*g,v=uG(e,b,w,g,t,n),S={left:Math.min(v.left-l.left,0),top:Math.min(v.top-l.top,0),right:Math.min(v.right-l.right,0),bottom:Math.min(v.bottom-l.bottom,0)};return{x:b-S.left+S.right,y:w-S.top+S.bottom,zoom:g}},Iu=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function xo(e){return e!=null&&e!=="parent"}function va(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 RC(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 LC(e,t={width:0,height:0},n,r,a){const o={...e},l=r.get(n);if(l){const d=l.origin||a;o.x+=l.internals.positionAbsolute.x-(t.width??0)*d[0],o.y+=l.internals.positionAbsolute.y-(t.height??0)*d[1]}return o}function iS(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function dG(){let e,t;return{promise:new Promise((r,a)=>{e=r,t=a}),resolve:e,reject:t}}function fG(e){return{...NC,...e||{}}}function bu(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:a}){const{x:o,y:l}=ci(e),d=od({x:o-((a==null?void 0:a.left)??0),y:l-((a==null?void 0:a.top)??0)},r),{x:f,y:h}=n?sd(d,t):d;return{xSnapped:f,ySnapped:h,...d}}const Yx=e=>({width:e.offsetWidth,height:e.offsetHeight}),IC=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},hG=["INPUT","SELECT","TEXTAREA"];function zC(e){var r,a;const t=((a=(r=e.composedPath)==null?void 0:r.call(e))==null?void 0:a[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:hG.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const PC=e=>"clientX"in e,ci=(e,t)=>{var o,l;const n=PC(e),r=n?e.clientX:(o=e.touches)==null?void 0:o[0].clientX,a=n?e.clientY:(l=e.touches)==null?void 0:l[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:a-((t==null?void 0:t.top)??0)}},aS=(e,t,n,r,a)=>{const o=t.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(l=>{const d=l.getBoundingClientRect();return{id:l.getAttribute("data-handleid"),type:e,nodeId:a,position:l.getAttribute("data-handlepos"),x:(d.left-n.left)/r,y:(d.top-n.top)/r,...Yx(l)}})};function BC({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:a,sourceControlY:o,targetControlX:l,targetControlY:d}){const f=e*.125+a*.375+l*.375+n*.125,h=t*.125+o*.375+d*.375+r*.125,g=Math.abs(f-e),m=Math.abs(h-t);return[f,h,g,m]}function Kf(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function sS({pos:e,x1:t,y1:n,x2:r,y2:a,c:o}){switch(e){case He.Left:return[t-Kf(t-r,o),n];case He.Right:return[t+Kf(r-t,o),n];case He.Top:return[t,n-Kf(n-a,o)];case He.Bottom:return[t,n+Kf(a-n,o)]}}function $C({sourceX:e,sourceY:t,sourcePosition:n=He.Bottom,targetX:r,targetY:a,targetPosition:o=He.Top,curvature:l=.25}){const[d,f]=sS({pos:n,x1:e,y1:t,x2:r,y2:a,c:l}),[h,g]=sS({pos:o,x1:r,y1:a,x2:e,y2:t,c:l}),[m,y,b,w]=BC({sourceX:e,sourceY:t,targetX:r,targetY:a,sourceControlX:d,sourceControlY:f,targetControlX:h,targetControlY:g});return[`M${e},${t} C${d},${f} ${h},${g} ${r},${a}`,m,y,b,w]}function UC({sourceX:e,sourceY:t,targetX:n,targetY:r}){const a=Math.abs(n-e)/2,o=n<e?n+a:n-a,l=Math.abs(r-t)/2,d=r<t?r+l:r-l;return[o,d,a,l]}function pG({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:a=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const l=a&&n?r+1e3:r,d=Math.max(e.parentId||a&&e.selected?e.internals.z:0,t.parentId||a&&t.selected?t.internals.z:0);return l+d}function mG({sourceNode:e,targetNode:t,width:n,height:r,transform:a}){const o=pp(Rh(e),Rh(t));o.x===o.x2&&(o.x2+=1),o.y===o.y2&&(o.y2+=1);const l={x:-a[0]/a[2],y:-a[1]/a[2],width:n/a[2],height:r/a[2]};return Lh(l,mp(o))>0}const gG=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,yG=(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)),bG=(e,t,n={})=>{var o;if(!e.source||!e.target)return(o=n.onError)==null||o.call(n,"006",hi.error006()),t;const r=n.getEdgeId||gG;let a;return CC(e)?a={...e}:a={...e,id:r(e)},yG(a,t)?t:(a.sourceHandle===null&&delete a.sourceHandle,a.targetHandle===null&&delete a.targetHandle,t.concat(a))};function FC({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[a,o,l,d]=UC({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,a,o,l,d]}const oS={[He.Left]:{x:-1,y:0},[He.Right]:{x:1,y:0},[He.Top]:{x:0,y:-1},[He.Bottom]:{x:0,y:1}},xG=({source:e,sourcePosition:t=He.Bottom,target:n})=>t===He.Left||t===He.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},lS=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function vG({source:e,sourcePosition:t=He.Bottom,target:n,targetPosition:r=He.Top,center:a,offset:o,stepPosition:l}){const d=oS[t],f=oS[r],h={x:e.x+d.x*o,y:e.y+d.y*o},g={x:n.x+f.x*o,y:n.y+f.y*o},m=xG({source:h,sourcePosition:t,target:g}),y=m.x!==0?"x":"y",b=m[y];let w=[],v,S;const E={x:0,y:0},C={x:0,y:0},[,,N,_]=UC({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(d[y]*f[y]===-1){y==="x"?(v=a.x??h.x+(g.x-h.x)*l,S=a.y??(h.y+g.y)/2):(v=a.x??(h.x+g.x)/2,S=a.y??h.y+(g.y-h.y)*l);const D=[{x:v,y:h.y},{x:v,y:g.y}],U=[{x:h.x,y:S},{x:g.x,y:S}];d[y]===b?w=y==="x"?D:U:w=y==="x"?U:D}else{const D=[{x:h.x,y:g.y}],U=[{x:g.x,y:h.y}];if(y==="x"?w=d.x===b?U:D:w=d.y===b?D:U,t===r){const R=Math.abs(e[y]-n[y]);if(R<=o){const H=Math.min(o-1,o-R);d[y]===b?E[y]=(h[y]>e[y]?-1:1)*H:C[y]=(g[y]>n[y]?-1:1)*H}}if(t!==r){const R=y==="x"?"y":"x",H=d[y]===f[R],L=h[R]>g[R],V=h[R]<g[R];(d[y]===1&&(!H&&L||H&&V)||d[y]!==1&&(!H&&V||H&&L))&&(w=y==="x"?D:U)}const B={x:h.x+E.x,y:h.y+E.y},q={x:g.x+C.x,y:g.y+C.y},G=Math.max(Math.abs(B.x-w[0].x),Math.abs(q.x-w[0].x)),Q=Math.max(Math.abs(B.y-w[0].y),Math.abs(q.y-w[0].y));G>=Q?(v=(B.x+q.x)/2,S=w[0].y):(v=w[0].x,S=(B.y+q.y)/2)}const M={x:h.x+E.x,y:h.y+E.y},A={x:g.x+C.x,y:g.y+C.y};return[[e,...M.x!==w[0].x||M.y!==w[0].y?[M]:[],...w,...A.x!==w[w.length-1].x||A.y!==w[w.length-1].y?[A]:[],n],v,S,N,_]}function wG(e,t,n,r){const a=Math.min(lS(e,t)/2,lS(t,n)/2,r),{x:o,y:l}=t;if(e.x===o&&o===n.x||e.y===l&&l===n.y)return`L${o} ${l}`;if(e.y===l){const h=e.x<n.x?-1:1,g=e.y<n.y?1:-1;return`L ${o+a*h},${l}Q ${o},${l} ${o},${l+a*g}`}const d=e.x<n.x?1:-1,f=e.y<n.y?-1:1;return`L ${o},${l+a*f}Q ${o},${l} ${o+a*d},${l}`}function yb({sourceX:e,sourceY:t,sourcePosition:n=He.Bottom,targetX:r,targetY:a,targetPosition:o=He.Top,borderRadius:l=5,centerX:d,centerY:f,offset:h=20,stepPosition:g=.5}){const[m,y,b,w,v]=vG({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:a},targetPosition:o,center:{x:d,y:f},offset:h,stepPosition:g});let S=`M${m[0].x} ${m[0].y}`;for(let E=1;E<m.length-1;E++)S+=wG(m[E-1],m[E],m[E+1],l);return S+=`L${m[m.length-1].x} ${m[m.length-1].y}`,[S,y,b,w,v]}function cS(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function kG(e){var m;const{sourceNode:t,targetNode:n}=e;if(!cS(t)||!cS(n))return null;const r=t.internals.handleBounds||uS(t.handles),a=n.internals.handleBounds||uS(n.handles),o=dS((r==null?void 0:r.source)??[],e.sourceHandle),l=dS(e.connectionMode===Hl.Strict?(a==null?void 0:a.target)??[]:((a==null?void 0:a.target)??[]).concat((a==null?void 0:a.source)??[]),e.targetHandle);if(!o||!l)return(m=e.onError)==null||m.call(e,"008",hi.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const d=(o==null?void 0:o.position)||He.Bottom,f=(l==null?void 0:l.position)||He.Top,h=vo(t,o,d),g=vo(n,l,f);return{sourceX:h.x,sourceY:h.y,targetX:g.x,targetY:g.y,sourcePosition:d,targetPosition:f}}function uS(e){if(!e)return null;const t=[],n=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?t.push(r):r.type==="target"&&n.push(r);return{source:t,target:n}}function vo(e,t,n=He.Left,r=!1){const a=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,o=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:l,height:d}=t??va(e);if(r)return{x:a+l/2,y:o+d/2};switch((t==null?void 0:t.position)??n){case He.Top:return{x:a+l/2,y:o};case He.Right:return{x:a+l,y:o+d/2};case He.Bottom:return{x:a+l/2,y:o+d};case He.Left:return{x:a,y:o+d/2}}}function dS(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function bb(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function EG(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:a}){const o=new Set;return e.reduce((l,d)=>([d.markerStart||r,d.markerEnd||a].forEach(f=>{if(f&&typeof f=="object"){const h=bb(f,t);o.has(h)||(l.push({id:h,color:f.color||n,...f}),o.add(h))}}),l),[]).sort((l,d)=>l.id.localeCompare(d.id))}const qC=1e3,SG=10,Qx={nodeOrigin:[0,0],nodeExtent:Ou,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},NG={...Qx,checkEquality:!0};function Wx(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function _G(e,t,n){const r=Wx(Qx,n);for(const a of e.values())if(a.parentId)Zx(a,e,t,r);else{const o=id(a,r.nodeOrigin),l=xo(a.extent)?a.extent:r.nodeExtent,d=bo(o,l,va(a));a.internals.positionAbsolute=d}}function jG(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],r=[];for(const a of e.handles){const o={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(o):a.type==="target"&&r.push(o)}return{source:n,target:r}}function Xx(e){return e==="manual"}function xb(e,t,n,r={}){var g,m;const a=Wx(NG,r),o={i:0},l=new Map(t),d=a!=null&&a.elevateNodesOnSelect&&!Xx(a.zIndexMode)?qC:0;let f=e.length>0,h=!1;t.clear(),n.clear();for(const y of e){let b=l.get(y.id);if(a.checkEquality&&y===(b==null?void 0:b.internals.userNode))t.set(y.id,b);else{const w=id(y,a.nodeOrigin),v=xo(y.extent)?y.extent:a.nodeExtent,S=bo(w,v,va(y));b={...a.defaults,...y,measured:{width:(g=y.measured)==null?void 0:g.width,height:(m=y.measured)==null?void 0:m.height},internals:{positionAbsolute:S,handleBounds:jG(y,b),z:HC(y,d,a.zIndexMode),userNode:y}},t.set(y.id,b)}(b.measured===void 0||b.measured.width===void 0||b.measured.height===void 0)&&!b.hidden&&(f=!1),y.parentId&&Zx(b,t,n,r,o),h||(h=y.selected??!1)}return{nodesInitialized:f,hasSelectedNodes:h}}function CG(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 Zx(e,t,n,r,a){const{elevateNodesOnSelect:o,nodeOrigin:l,nodeExtent:d,zIndexMode:f}=Wx(Qx,r),h=e.parentId,g=t.get(h);if(!g){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}CG(e,n),a&&!g.parentId&&g.internals.rootParentIndex===void 0&&f==="auto"&&(g.internals.rootParentIndex=++a.i,g.internals.z=g.internals.z+a.i*SG),a&&g.internals.rootParentIndex!==void 0&&(a.i=g.internals.rootParentIndex);const m=o&&!Xx(f)?qC:0,{x:y,y:b,z:w}=AG(e,g,l,d,m,f),{positionAbsolute:v}=e.internals,S=y!==v.x||b!==v.y;(S||w!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:S?{x:y,y:b}:v,z:w}})}function HC(e,t,n){const r=li(e.zIndex)?e.zIndex:0;return Xx(n)?r:r+(e.selected?t:0)}function AG(e,t,n,r,a,o){const{x:l,y:d}=t.internals.positionAbsolute,f=va(e),h=id(e,n),g=xo(e.extent)?bo(h,e.extent,f):h;let m=bo({x:l+g.x,y:d+g.y},r,f);e.extent==="parent"&&(m=TC(m,f,t));const y=HC(e,a,o),b=t.internals.z??0;return{x:m.x,y:m.y,z:b>=y?b+1:y}}function Jx(e,t,n,r=[0,0]){var l;const a=[],o=new Map;for(const d of e){const f=t.get(d.parentId);if(!f)continue;const h=((l=o.get(d.parentId))==null?void 0:l.expandedRect)??Lu(f),g=MC(h,d.rect);o.set(d.parentId,{expandedRect:g,parent:f})}return o.size>0&&o.forEach(({expandedRect:d,parent:f},h)=>{var N;const g=f.internals.positionAbsolute,m=va(f),y=f.origin??r,b=d.x<g.x?Math.round(Math.abs(g.x-d.x)):0,w=d.y<g.y?Math.round(Math.abs(g.y-d.y)):0,v=Math.max(m.width,Math.round(d.width)),S=Math.max(m.height,Math.round(d.height)),E=(v-m.width)*y[0],C=(S-m.height)*y[1];(b>0||w>0||E||C)&&(a.push({id:h,type:"position",position:{x:f.position.x-b+E,y:f.position.y-w+C}}),(N=n.get(h))==null||N.forEach(_=>{e.some(M=>M.id===_.id)||a.push({id:_.id,type:"position",position:{x:_.position.x+b,y:_.position.y+w}})})),(m.width<d.width||m.height<d.height||b||w)&&a.push({id:h,type:"dimensions",setAttributes:!0,dimensions:{width:v+(b?y[0]*b-E:0),height:S+(w?y[1]*w-C:0)}})}),a}function TG(e,t,n,r,a,o,l){const d=r==null?void 0:r.querySelector(".xyflow__viewport");let f=!1;if(!d)return{changes:[],updatedInternals:f};const h=[],g=window.getComputedStyle(d),{m22:m}=new window.DOMMatrixReadOnly(g.transform),y=[];for(const b of e.values()){const w=t.get(b.id);if(!w)continue;if(w.hidden){t.set(w.id,{...w,internals:{...w.internals,handleBounds:void 0}}),f=!0;continue}const v=Yx(b.nodeElement),S=w.measured.width!==v.width||w.measured.height!==v.height;if(!!(v.width&&v.height&&(S||!w.internals.handleBounds||b.force))){const C=b.nodeElement.getBoundingClientRect(),N=xo(w.extent)?w.extent:o;let{positionAbsolute:_}=w.internals;w.parentId&&w.extent==="parent"?_=TC(_,v,t.get(w.parentId)):N&&(_=bo(_,N,v));const M={...w,measured:v,internals:{...w.internals,positionAbsolute:_,handleBounds:{source:aS("source",b.nodeElement,C,m,w.id),target:aS("target",b.nodeElement,C,m,w.id)}}};t.set(w.id,M),w.parentId&&Zx(M,t,n,{nodeOrigin:a,zIndexMode:l}),f=!0,S&&(h.push({id:w.id,type:"dimensions",dimensions:v}),w.expandParent&&w.parentId&&y.push({id:w.id,parentId:w.parentId,rect:Lu(M,a)}))}}if(y.length>0){const b=Jx(y,t,n,a);h.push(...b)}return{changes:h,updatedInternals:f}}async function MG({delta:e,panZoom:t,transform:n,translateExtent:r,width:a,height:o}){if(!t||!e.x&&!e.y)return!1;const l=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[a,o]],r);return!!l&&(l.x!==n[0]||l.y!==n[1]||l.k!==n[2])}function fS(e,t,n,r,a,o){let l=a;const d=r.get(l)||new Map;r.set(l,d.set(n,t)),l=`${a}-${e}`;const f=r.get(l)||new Map;if(r.set(l,f.set(n,t)),o){l=`${a}-${e}-${o}`;const h=r.get(l)||new Map;r.set(l,h.set(n,t))}}function KC(e,t,n){e.clear(),t.clear();for(const r of n){const{source:a,target:o,sourceHandle:l=null,targetHandle:d=null}=r,f={edgeId:r.id,source:a,target:o,sourceHandle:l,targetHandle:d},h=`${a}-${l}--${o}-${d}`,g=`${o}-${d}--${a}-${l}`;fS("source",f,g,e,a,l),fS("target",f,h,e,o,d),t.set(r.id,r)}}function GC(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:GC(n,t):!1}function hS(e,t,n){var a;let r=e;do{if((a=r==null?void 0:r.matches)!=null&&a.call(r,t))return!0;if(r===n)return!1;r=r==null?void 0:r.parentElement}while(r);return!1}function DG(e,t,n,r){const a=new Map;for(const[o,l]of e)if((l.selected||l.id===r)&&(!l.parentId||!GC(l,e))&&(l.draggable||t&&typeof l.draggable>"u")){const d=e.get(o);d&&a.set(o,{id:o,position:d.position||{x:0,y:0},distance:{x:n.x-d.internals.positionAbsolute.x,y:n.y-d.internals.positionAbsolute.y},extent:d.extent,parentId:d.parentId,origin:d.origin,expandParent:d.expandParent,internals:{positionAbsolute:d.internals.positionAbsolute||{x:0,y:0}},measured:{width:d.measured.width??0,height:d.measured.height??0}})}return a}function py({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){var l,d,f;const a=[];for(const[h,g]of t){const m=(l=n.get(h))==null?void 0:l.internals.userNode;m&&a.push({...m,position:g.position,dragging:r})}if(!e)return[a[0],a];const o=(d=n.get(e))==null?void 0:d.internals.userNode;return[o?{...o,position:((f=t.get(e))==null?void 0:f.position)||o.position,dragging:r}:a[0],a]}function OG({dragItems:e,snapGrid:t,x:n,y:r}){const a=e.values().next().value;if(!a)return null;const o={x:n-a.distance.x,y:r-a.distance.y},l=sd(o,t);return{x:l.x-o.x,y:l.y-o.y}}function RG({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:a}){let o={x:null,y:null},l=0,d=new Map,f=!1,h={x:0,y:0},g=null,m=!1,y=null,b=!1,w=!1,v=null;function S({noDragClassName:C,handleSelector:N,domNode:_,isSelectable:M,nodeId:A,nodeClickDistance:O=0}){y=_r(_);function D({x:G,y:Q}){const{nodeLookup:R,nodeExtent:H,snapGrid:L,snapToGrid:V,nodeOrigin:Y,onNodeDrag:K,onSelectionDrag:z,onError:$,updateNodePositions:P}=t();o={x:G,y:Q};let I=!1;const ae=d.size>1,me=ae&&H?gb(ad(d)):null,ve=ae&&V?OG({dragItems:d,snapGrid:L,x:G,y:Q}):null;for(const[we,J]of d){if(!R.has(we))continue;let de={x:G-J.distance.x,y:Q-J.distance.y};V&&(de=ve?{x:Math.round(de.x+ve.x),y:Math.round(de.y+ve.y)}:sd(de,L));let Te=null;if(ae&&H&&!J.extent&&me){const{positionAbsolute:le}=J.internals,je=le.x-me.x+H[0][0],Me=le.x+J.measured.width-me.x2+H[1][0],ke=le.y-me.y+H[0][1],We=le.y+J.measured.height-me.y2+H[1][1];Te=[[je,ke],[Me,We]]}const{position:Ie,positionAbsolute:Oe}=AC({nodeId:we,nextPosition:de,nodeLookup:R,nodeExtent:Te||H,nodeOrigin:Y,onError:$});I=I||J.position.x!==Ie.x||J.position.y!==Ie.y,J.position=Ie,J.internals.positionAbsolute=Oe}if(w=w||I,!!I&&(P(d,!0),v&&(r||K||!A&&z))){const[we,J]=py({nodeId:A,dragItems:d,nodeLookup:R});r==null||r(v,d,we,J),K==null||K(v,we,J),A||z==null||z(v,J)}}async function U(){if(!g)return;const{transform:G,panBy:Q,autoPanSpeed:R,autoPanOnNodeDrag:H}=t();if(!H){f=!1,cancelAnimationFrame(l);return}const[L,V]=Gx(h,g,R);(L!==0||V!==0)&&(o.x=(o.x??0)-L/G[2],o.y=(o.y??0)-V/G[2],await Q({x:L,y:V})&&D(o)),l=requestAnimationFrame(U)}function B(G){var ae;const{nodeLookup:Q,multiSelectionActive:R,nodesDraggable:H,transform:L,snapGrid:V,snapToGrid:Y,selectNodesOnDrag:K,onNodeDragStart:z,onSelectionDragStart:$,unselectNodesAndEdges:P}=t();m=!0,(!K||!M)&&!R&&A&&((ae=Q.get(A))!=null&&ae.selected||P()),M&&K&&A&&(e==null||e(A));const I=bu(G.sourceEvent,{transform:L,snapGrid:V,snapToGrid:Y,containerBounds:g});if(o=I,d=DG(Q,H,I,A),d.size>0&&(n||z||!A&&$)){const[me,ve]=py({nodeId:A,dragItems:d,nodeLookup:Q});n==null||n(G.sourceEvent,d,me,ve),z==null||z(G.sourceEvent,me,ve),A||$==null||$(G.sourceEvent,ve)}}const q=lC().clickDistance(O).on("start",G=>{const{domNode:Q,nodeDragThreshold:R,transform:H,snapGrid:L,snapToGrid:V}=t();g=(Q==null?void 0:Q.getBoundingClientRect())||null,b=!1,w=!1,v=G.sourceEvent,R===0&&B(G),o=bu(G.sourceEvent,{transform:H,snapGrid:L,snapToGrid:V,containerBounds:g}),h=ci(G.sourceEvent,g)}).on("drag",G=>{const{autoPanOnNodeDrag:Q,transform:R,snapGrid:H,snapToGrid:L,nodeDragThreshold:V,nodeLookup:Y}=t(),K=bu(G.sourceEvent,{transform:R,snapGrid:H,snapToGrid:L,containerBounds:g});if(v=G.sourceEvent,(G.sourceEvent.type==="touchmove"&&G.sourceEvent.touches.length>1||A&&!Y.has(A))&&(b=!0),!b){if(!f&&Q&&m&&(f=!0,U()),!m){const z=ci(G.sourceEvent,g),$=z.x-h.x,P=z.y-h.y;Math.sqrt($*$+P*P)>V&&B(G)}(o.x!==K.xSnapped||o.y!==K.ySnapped)&&d&&m&&(h=ci(G.sourceEvent,g),D(K))}}).on("end",G=>{if(!m||b){b&&d.size>0&&t().updateNodePositions(d,!1);return}if(f=!1,m=!1,cancelAnimationFrame(l),d.size>0){const{nodeLookup:Q,updateNodePositions:R,onNodeDragStop:H,onSelectionDragStop:L}=t();if(w&&(R(d,!1),w=!1),a||H||!A&&L){const[V,Y]=py({nodeId:A,dragItems:d,nodeLookup:Q,dragging:!1});a==null||a(G.sourceEvent,d,V,Y),H==null||H(G.sourceEvent,V,Y),A||L==null||L(G.sourceEvent,Y)}}}).filter(G=>{const Q=G.target;return!G.button&&(!C||!hS(Q,`.${C}`,_))&&(!N||hS(Q,N,_))});y.call(q)}function E(){y==null||y.on(".drag",null)}return{update:S,destroy:E}}function LG(e,t,n){const r=[],a={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const o of t.values())Lh(a,Lu(o))>0&&r.push(o);return r}const IG=250;function zG(e,t,n,r){var d,f;let a=[],o=1/0;const l=LG(e,n,t+IG);for(const h of l){const g=[...((d=h.internals.handleBounds)==null?void 0:d.source)??[],...((f=h.internals.handleBounds)==null?void 0:f.target)??[]];for(const m of g){if(r.nodeId===m.nodeId&&r.type===m.type&&r.id===m.id)continue;const{x:y,y:b}=vo(h,m,m.position,!0),w=Math.sqrt(Math.pow(y-e.x,2)+Math.pow(b-e.y,2));w>t||(w<o?(a=[{...m,x:y,y:b}],o=w):w===o&&a.push({...m,x:y,y:b}))}}if(!a.length)return null;if(a.length>1){const h=r.type==="source"?"target":"source";return a.find(g=>g.type===h)??a[0]}return a[0]}function VC(e,t,n,r,a,o=!1){var h,g,m;const l=r.get(e);if(!l)return null;const d=a==="strict"?(h=l.internals.handleBounds)==null?void 0:h[t]:[...((g=l.internals.handleBounds)==null?void 0:g.source)??[],...((m=l.internals.handleBounds)==null?void 0:m.target)??[]],f=(n?d==null?void 0:d.find(y=>y.id===n):d==null?void 0:d[0])??null;return f&&o?{...f,...vo(l,f,f.position,!0)}:f}function YC(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function PG(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const QC=()=>!0;function BG(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:a,edgeUpdaterType:o,isTarget:l,domNode:d,nodeLookup:f,lib:h,autoPanOnConnect:g,flowId:m,panBy:y,cancelConnection:b,onConnectStart:w,onConnect:v,onConnectEnd:S,isValidConnection:E=QC,onReconnectEnd:C,updateConnection:N,getTransform:_,getFromHandle:M,autoPanSpeed:A,dragThreshold:O=1,handleDomNode:D}){const U=IC(e.target);let B=0,q;const{x:G,y:Q}=ci(e),R=YC(o,D),H=d==null?void 0:d.getBoundingClientRect();let L=!1;if(!H||!R)return;const V=VC(a,R,r,f,t);if(!V)return;let Y=ci(e,H),K=!1,z=null,$=!1,P=null;function I(){if(!g||!H)return;const[Ie,Oe]=Gx(Y,H,A);y({x:Ie,y:Oe}),B=requestAnimationFrame(I)}const ae={...V,nodeId:a,type:R,position:V.position},me=f.get(a);let we={inProgress:!0,isValid:null,from:vo(me,ae,He.Left,!0),fromHandle:ae,fromPosition:ae.position,fromNode:me,to:Y,toHandle:null,toPosition:tS[ae.position],toNode:null,pointer:Y};function J(){L=!0,N(we),w==null||w(e,{nodeId:a,handleId:r,handleType:R})}O===0&&J();function de(Ie){if(!L){const{x:We,y:Ue}=ci(Ie),oe=We-G,ye=Ue-Q;if(!(oe*oe+ye*ye>O*O))return;J()}if(!M()||!ae){Te(Ie);return}const Oe=_();Y=ci(Ie,H),q=zG(od(Y,Oe,!1,[1,1]),n,f,ae),K||(I(),K=!0);const le=WC(Ie,{handle:q,connectionMode:t,fromNodeId:a,fromHandleId:r,fromType:l?"target":"source",isValidConnection:E,doc:U,lib:h,flowId:m,nodeLookup:f});P=le.handleDomNode,z=le.connection,$=PG(!!q,le.isValid);const je=f.get(a),Me=je?vo(je,ae,He.Left,!0):we.from,ke={...we,from:Me,isValid:$,to:le.toHandle&&$?Gl({x:le.toHandle.x,y:le.toHandle.y},Oe):Y,toHandle:le.toHandle,toPosition:$&&le.toHandle?le.toHandle.position:tS[ae.position],toNode:le.toHandle?f.get(le.toHandle.nodeId):null,pointer:Y};N(ke),we=ke}function Te(Ie){if(!("touches"in Ie&&Ie.touches.length>0)){if(L){(q||P)&&z&&$&&(v==null||v(z));const{inProgress:Oe,...le}=we,je={...le,toPosition:we.toHandle?we.toPosition:null};S==null||S(Ie,je),o&&(C==null||C(Ie,je))}b(),cancelAnimationFrame(B),K=!1,$=!1,z=null,P=null,U.removeEventListener("mousemove",de),U.removeEventListener("mouseup",Te),U.removeEventListener("touchmove",de),U.removeEventListener("touchend",Te)}}U.addEventListener("mousemove",de),U.addEventListener("mouseup",Te),U.addEventListener("touchmove",de),U.addEventListener("touchend",Te)}function WC(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:a,fromType:o,doc:l,lib:d,flowId:f,isValidConnection:h=QC,nodeLookup:g}){const m=o==="target",y=t?l.querySelector(`.${d}-flow__handle[data-id="${f}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:b,y:w}=ci(e),v=l.elementFromPoint(b,w),S=v!=null&&v.classList.contains(`${d}-flow__handle`)?v:y,E={handleDomNode:S,isValid:!1,connection:null,toHandle:null};if(S){const C=YC(void 0,S),N=S.getAttribute("data-nodeid"),_=S.getAttribute("data-handleid"),M=S.classList.contains("connectable"),A=S.classList.contains("connectableend");if(!N||!C)return E;const O={source:m?N:r,sourceHandle:m?_:a,target:m?r:N,targetHandle:m?a:_};E.connection=O;const U=M&&A&&(n===Hl.Strict?m&&C==="source"||!m&&C==="target":N!==r||_!==a);E.isValid=U&&h(O),E.toHandle=VC(N,C,_,g,n,!0)}return E}const vb={onPointerDown:BG,isValid:WC};function $G({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const a=_r(e);function o({translateExtent:d,width:f,height:h,zoomStep:g=1,pannable:m=!0,zoomable:y=!0,inversePan:b=!1}){const w=N=>{if(N.sourceEvent.type!=="wheel"||!t)return;const _=n(),M=N.sourceEvent.ctrlKey&&Iu()?10:1,A=-N.sourceEvent.deltaY*(N.sourceEvent.deltaMode===1?.05:N.sourceEvent.deltaMode?1:.002)*g,O=_[2]*Math.pow(2,A*M);t.scaleTo(O)};let v=[0,0];const S=N=>{(N.sourceEvent.type==="mousedown"||N.sourceEvent.type==="touchstart")&&(v=[N.sourceEvent.clientX??N.sourceEvent.touches[0].clientX,N.sourceEvent.clientY??N.sourceEvent.touches[0].clientY])},E=N=>{const _=n();if(N.sourceEvent.type!=="mousemove"&&N.sourceEvent.type!=="touchmove"||!t)return;const M=[N.sourceEvent.clientX??N.sourceEvent.touches[0].clientX,N.sourceEvent.clientY??N.sourceEvent.touches[0].clientY],A=[M[0]-v[0],M[1]-v[1]];v=M;const O=r()*Math.max(_[2],Math.log(_[2]))*(b?-1:1),D={x:_[0]-A[0]*O,y:_[1]-A[1]*O},U=[[0,0],[f,h]];t.setViewportConstrained({x:D.x,y:D.y,zoom:_[2]},U,d)},C=EC().on("start",S).on("zoom",m?E:null).on("zoom.wheel",y?w:null);a.call(C,{})}function l(){a.on("zoom",null)}return{update:o,destroy:l,pointer:si}}const gp=e=>({x:e.x,y:e.y,zoom:e.k}),my=({x:e,y:t,zoom:n})=>hp.translate(e,t).scale(n),xl=(e,t)=>e.target.closest(`.${t}`),XC=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),UG=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,gy=(e,t=0,n=UG,r=()=>{})=>{const a=typeof t=="number"&&t>0;return a||r(),a?e.transition().duration(t).ease(n).on("end",r):e},ZC=e=>{const t=e.ctrlKey&&Iu()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function FG({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:a,panOnScrollSpeed:o,zoomOnPinch:l,onPanZoomStart:d,onPanZoom:f,onPanZoomEnd:h}){return g=>{if(xl(g,t))return g.ctrlKey&&g.preventDefault(),!1;g.preventDefault(),g.stopImmediatePropagation();const m=n.property("__zoom").k||1;if(g.ctrlKey&&l){const S=si(g),E=ZC(g),C=m*Math.pow(2,E);r.scaleTo(n,C,S,g);return}const y=g.deltaMode===1?20:1;let b=a===uo.Vertical?0:g.deltaX*y,w=a===uo.Horizontal?0:g.deltaY*y;!Iu()&&g.shiftKey&&a!==uo.Vertical&&(b=g.deltaY*y,w=0),r.translateBy(n,-(b/m)*o,-(w/m)*o,{internal:!0});const v=gp(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(f==null||f(g,v),e.panScrollTimeout=setTimeout(()=>{h==null||h(g,v),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,d==null||d(g,v))}}function qG({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,a){const o=r.type==="wheel",l=!t&&o&&!r.ctrlKey,d=xl(r,e);if(r.ctrlKey&&o&&d&&r.preventDefault(),l||d)return null;r.preventDefault(),n.call(this,r,a)}}function HG({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{var o,l,d;if((o=r.sourceEvent)!=null&&o.internal)return;const a=gp(r.transform);e.mouseButton=((l=r.sourceEvent)==null?void 0:l.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=a,((d=r.sourceEvent)==null?void 0:d.type)==="mousedown"&&t(!0),n&&(n==null||n(r.sourceEvent,a))}}function KG({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:a}){return o=>{var l,d;e.usedRightMouseButton=!!(n&&XC(t,e.mouseButton??0)),(l=o.sourceEvent)!=null&&l.sync||r([o.transform.x,o.transform.y,o.transform.k]),a&&!((d=o.sourceEvent)!=null&&d.internal)&&(a==null||a(o.sourceEvent,gp(o.transform)))}}function GG({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:a,onPaneContextMenu:o}){return l=>{var d;if(!((d=l.sourceEvent)!=null&&d.internal)&&(e.isZoomingOrPanning=!1,o&&XC(t,e.mouseButton??0)&&!e.usedRightMouseButton&&l.sourceEvent&&o(l.sourceEvent),e.usedRightMouseButton=!1,r(!1),a)){const f=gp(l.transform);e.prevViewport=f,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{a==null||a(l.sourceEvent,f)},n?150:0)}}}function VG({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:a,zoomOnDoubleClick:o,userSelectionActive:l,noWheelClassName:d,noPanClassName:f,lib:h,connectionInProgress:g}){return m=>{var S;const y=e||t,b=n&&m.ctrlKey,w=m.type==="wheel";if(m.button===1&&m.type==="mousedown"&&(xl(m,`${h}-flow__node`)||xl(m,`${h}-flow__edge`)))return!0;if(!r&&!y&&!a&&!o&&!n||l||g&&!w||xl(m,d)&&w||xl(m,f)&&(!w||a&&w&&!e)||!n&&m.ctrlKey&&w)return!1;if(!n&&m.type==="touchstart"&&((S=m.touches)==null?void 0:S.length)>1)return m.preventDefault(),!1;if(!y&&!a&&!b&&w||!r&&(m.type==="mousedown"||m.type==="touchstart")||Array.isArray(r)&&!r.includes(m.button)&&m.type==="mousedown")return!1;const v=Array.isArray(r)&&r.includes(m.button)||!m.button||m.button<=1;return(!m.ctrlKey||w)&&v}}function YG({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:a,onPanZoom:o,onPanZoomStart:l,onPanZoomEnd:d,onDraggingChange:f}){const h={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},g=e.getBoundingClientRect(),m=EC().scaleExtent([t,n]).translateExtent(r),y=_r(e).call(m);C({x:a.x,y:a.y,zoom:Kl(a.zoom,t,n)},[[0,0],[g.width,g.height]],r);const b=y.on("wheel.zoom"),w=y.on("dblclick.zoom");m.wheelDelta(ZC);async function v(q,G){return y?new Promise(Q=>{m==null||m.interpolate((G==null?void 0:G.interpolate)==="linear"?yu:ih).transform(gy(y,G==null?void 0:G.duration,G==null?void 0:G.ease,()=>Q(!0)),q)}):!1}function S({noWheelClassName:q,noPanClassName:G,onPaneContextMenu:Q,userSelectionActive:R,panOnScroll:H,panOnDrag:L,panOnScrollMode:V,panOnScrollSpeed:Y,preventScrolling:K,zoomOnPinch:z,zoomOnScroll:$,zoomOnDoubleClick:P,zoomActivationKeyPressed:I,lib:ae,onTransformChange:me,connectionInProgress:ve,paneClickDistance:we,selectionOnDrag:J}){R&&!h.isZoomingOrPanning&&E();const de=H&&!I&&!R;m.clickDistance(J?1/0:!li(we)||we<0?0:we);const Te=de?FG({zoomPanValues:h,noWheelClassName:q,d3Selection:y,d3Zoom:m,panOnScrollMode:V,panOnScrollSpeed:Y,zoomOnPinch:z,onPanZoomStart:l,onPanZoom:o,onPanZoomEnd:d}):qG({noWheelClassName:q,preventScrolling:K,d3ZoomHandler:b});y.on("wheel.zoom",Te,{passive:!1});const Ie=HG({zoomPanValues:h,onDraggingChange:f,onPanZoomStart:l});m.on("start",Ie);const Oe=KG({zoomPanValues:h,panOnDrag:L,onPaneContextMenu:!!Q,onPanZoom:o,onTransformChange:me});m.on("zoom",Oe);const le=GG({zoomPanValues:h,panOnDrag:L,panOnScroll:H,onPaneContextMenu:Q,onPanZoomEnd:d,onDraggingChange:f});m.on("end",le);const je=VG({zoomActivationKeyPressed:I,panOnDrag:L,zoomOnScroll:$,panOnScroll:H,zoomOnDoubleClick:P,zoomOnPinch:z,userSelectionActive:R,noPanClassName:G,noWheelClassName:q,lib:ae,connectionInProgress:ve});m.filter(je),P?y.on("dblclick.zoom",w):y.on("dblclick.zoom",null)}function E(){m.on("zoom",null)}async function C(q,G,Q){const R=my(q),H=m==null?void 0:m.constrain()(R,G,Q);return H&&await v(H),H}async function N(q,G){const Q=my(q);return await v(Q,G),Q}function _(q){if(y){const G=my(q),Q=y.property("__zoom");(Q.k!==q.zoom||Q.x!==q.x||Q.y!==q.y)&&(m==null||m.transform(y,G,null,{sync:!0}))}}function M(){const q=y?kC(y.node()):{x:0,y:0,k:1};return{x:q.x,y:q.y,zoom:q.k}}async function A(q,G){return y?new Promise(Q=>{m==null||m.interpolate((G==null?void 0:G.interpolate)==="linear"?yu:ih).scaleTo(gy(y,G==null?void 0:G.duration,G==null?void 0:G.ease,()=>Q(!0)),q)}):!1}async function O(q,G){return y?new Promise(Q=>{m==null||m.interpolate((G==null?void 0:G.interpolate)==="linear"?yu:ih).scaleBy(gy(y,G==null?void 0:G.duration,G==null?void 0:G.ease,()=>Q(!0)),q)}):!1}function D(q){m==null||m.scaleExtent(q)}function U(q){m==null||m.translateExtent(q)}function B(q){const G=!li(q)||q<0?0:q;m==null||m.clickDistance(G)}return{update:S,destroy:E,setViewport:N,setViewportConstrained:C,getViewport:M,scaleTo:A,scaleBy:O,setScaleExtent:D,setTranslateExtent:U,syncViewport:_,setClickDistance:B}}var Vl;(function(e){e.Line="line",e.Handle="handle"})(Vl||(Vl={}));function QG({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:a,affectsY:o}){const l=e-t,d=n-r,f=[l>0?1:l<0?-1:0,d>0?1:d<0?-1:0];return l&&a&&(f[0]=f[0]*-1),d&&o&&(f[1]=f[1]*-1),f}function pS(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),a=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:a}}function rs(e,t){return Math.max(0,t-e)}function is(e,t){return Math.max(0,e-t)}function Gf(e,t,n){return Math.max(0,t-e,e-n)}function mS(e,t){return e?!t:t}function WG(e,t,n,r,a,o,l,d){let{affectsX:f,affectsY:h}=t;const{isHorizontal:g,isVertical:m}=t,y=g&&m,{xSnapped:b,ySnapped:w}=n,{minWidth:v,maxWidth:S,minHeight:E,maxHeight:C}=r,{x:N,y:_,width:M,height:A,aspectRatio:O}=e;let D=Math.floor(g?b-e.pointerX:0),U=Math.floor(m?w-e.pointerY:0);const B=M+(f?-D:D),q=A+(h?-U:U),G=-o[0]*M,Q=-o[1]*A;let R=Gf(B,v,S),H=Gf(q,E,C);if(l){let Y=0,K=0;f&&D<0?Y=rs(N+D+G,l[0][0]):!f&&D>0&&(Y=is(N+B+G,l[1][0])),h&&U<0?K=rs(_+U+Q,l[0][1]):!h&&U>0&&(K=is(_+q+Q,l[1][1])),R=Math.max(R,Y),H=Math.max(H,K)}if(d){let Y=0,K=0;f&&D>0?Y=is(N+D,d[0][0]):!f&&D<0&&(Y=rs(N+B,d[1][0])),h&&U>0?K=is(_+U,d[0][1]):!h&&U<0&&(K=rs(_+q,d[1][1])),R=Math.max(R,Y),H=Math.max(H,K)}if(a){if(g){const Y=Gf(B/O,E,C)*O;if(R=Math.max(R,Y),l){let K=0;!f&&!h||f&&!h&&y?K=is(_+Q+B/O,l[1][1])*O:K=rs(_+Q+(f?D:-D)/O,l[0][1])*O,R=Math.max(R,K)}if(d){let K=0;!f&&!h||f&&!h&&y?K=rs(_+B/O,d[1][1])*O:K=is(_+(f?D:-D)/O,d[0][1])*O,R=Math.max(R,K)}}if(m){const Y=Gf(q*O,v,S)/O;if(H=Math.max(H,Y),l){let K=0;!f&&!h||h&&!f&&y?K=is(N+q*O+G,l[1][0])/O:K=rs(N+(h?U:-U)*O+G,l[0][0])/O,H=Math.max(H,K)}if(d){let K=0;!f&&!h||h&&!f&&y?K=rs(N+q*O,d[1][0])/O:K=is(N+(h?U:-U)*O,d[0][0])/O,H=Math.max(H,K)}}}U=U+(U<0?H:-H),D=D+(D<0?R:-R),a&&(y?B>q*O?U=(mS(f,h)?-D:D)/O:D=(mS(f,h)?-U:U)*O:g?(U=D/O,h=f):(D=U*O,f=h));const L=f?N+D:N,V=h?_+U:_;return{width:M+(f?-D:D),height:A+(h?-U:U),x:o[0]*D*(f?-1:1)+L,y:o[1]*U*(h?-1:1)+V}}const JC={width:0,height:0,x:0,y:0},XG={...JC,pointerX:0,pointerY:0,aspectRatio:1};function ZG(e,t,n){const r=t.position.x+e.position.x,a=t.position.y+e.position.y,o=e.measured.width??0,l=e.measured.height??0,d=n[0]*o,f=n[1]*l;return[[r-d,a-f],[r+o-d,a+l-f]]}function JG({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:a}){const o=_r(e);let l={controlDirection:pS("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function d({controlPosition:h,boundaries:g,keepAspectRatio:m,resizeDirection:y,onResizeStart:b,onResize:w,onResizeEnd:v,shouldResize:S}){let E={...JC},C={...XG};l={boundaries:g,resizeDirection:y,keepAspectRatio:m,controlDirection:pS(h)};let N,_=null,M=[],A,O,D,U=!1;const B=lC().on("start",q=>{const{nodeLookup:G,transform:Q,snapGrid:R,snapToGrid:H,nodeOrigin:L,paneDomNode:V}=n();if(N=G.get(t),!N)return;_=(V==null?void 0:V.getBoundingClientRect())??null;const{xSnapped:Y,ySnapped:K}=bu(q.sourceEvent,{transform:Q,snapGrid:R,snapToGrid:H,containerBounds:_});E={width:N.measured.width??0,height:N.measured.height??0,x:N.position.x??0,y:N.position.y??0},C={...E,pointerX:Y,pointerY:K,aspectRatio:E.width/E.height},A=void 0,O=xo(N.extent)?N.extent:void 0,N.parentId&&(N.extent==="parent"||N.expandParent)&&(A=G.get(N.parentId)),A&&N.extent==="parent"&&(O=[[0,0],[A.measured.width,A.measured.height]]),M=[],D=void 0;for(const[z,$]of G)if($.parentId===t&&(M.push({id:z,position:{...$.position},extent:$.extent}),$.extent==="parent"||$.expandParent)){const P=ZG($,N,$.origin??L);D?D=[[Math.min(P[0][0],D[0][0]),Math.min(P[0][1],D[0][1])],[Math.max(P[1][0],D[1][0]),Math.max(P[1][1],D[1][1])]]:D=P}b==null||b(q,{...E})}).on("drag",q=>{const{transform:G,snapGrid:Q,snapToGrid:R,nodeOrigin:H}=n(),L=bu(q.sourceEvent,{transform:G,snapGrid:Q,snapToGrid:R,containerBounds:_}),V=[];if(!N)return;const{x:Y,y:K,width:z,height:$}=E,P={},I=N.origin??H,{width:ae,height:me,x:ve,y:we}=WG(C,l.controlDirection,L,l.boundaries,l.keepAspectRatio,I,O,D),J=ae!==z,de=me!==$,Te=ve!==Y&&J,Ie=we!==K&&de;if(!Te&&!Ie&&!J&&!de)return;if((Te||Ie||I[0]===1||I[1]===1)&&(P.x=Te?ve:E.x,P.y=Ie?we:E.y,E.x=P.x,E.y=P.y,M.length>0)){const Me=ve-Y,ke=we-K;for(const We of M)We.position={x:We.position.x-Me+I[0]*(ae-z),y:We.position.y-ke+I[1]*(me-$)},V.push(We)}if((J||de)&&(P.width=J&&(!l.resizeDirection||l.resizeDirection==="horizontal")?ae:E.width,P.height=de&&(!l.resizeDirection||l.resizeDirection==="vertical")?me:E.height,E.width=P.width,E.height=P.height),A&&N.expandParent){const Me=I[0]*(P.width??0);P.x&&P.x<Me&&(E.x=Me,C.x=C.x-(P.x-Me));const ke=I[1]*(P.height??0);P.y&&P.y<ke&&(E.y=ke,C.y=C.y-(P.y-ke))}const Oe=QG({width:E.width,prevWidth:z,height:E.height,prevHeight:$,affectsX:l.controlDirection.affectsX,affectsY:l.controlDirection.affectsY}),le={...E,direction:Oe};(S==null?void 0:S(q,le))!==!1&&(U=!0,w==null||w(q,le),r(P,V))}).on("end",q=>{U&&(v==null||v(q,{...E}),a==null||a({...E}),U=!1)});o.call(B)}function f(){o.on(".drag",null)}return{update:d,destroy:f}}var yy={exports:{}},by={},xy={exports:{}},vy={};/**
|
|
649
649
|
* @license React
|
|
650
650
|
* use-sync-external-store-shim.production.js
|
|
651
651
|
*
|