@coralai/sps-cli 0.58.4 → 0.58.5

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.
@@ -642,7 +642,7 @@ name: code-review
642
642
  description: ...
643
643
  ---
644
644
 
645
- # ...`,"aria-label":t("skills.import.body")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:h.isPending||!f||!l.trim(),onClick:()=>h.mutate(),children:[h.isPending?u.jsx(Xe,{size:14,className:"animate-spin"}):u.jsx(WN,{size:14,strokeWidth:3}),t("skills.import.submit")]})]})})}function o8({onClose:e,onSubmit:t}){const n=Be(),[r,a]=C.useState(""),[o,l]=C.useState(""),d=/^[a-z0-9][a-z0-9-]*$/.test(r);return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[u.jsx(Ll,{size:16,strokeWidth:2.5}),n("skills.ai.title")]}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:u.jsx(Nn,{size:14,strokeWidth:3})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.name")}),u.jsx("input",{type:"text",value: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")})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.intent")}),u.jsx("textarea",{value: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")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!d||!o.trim(),onClick:()=>t(r,o),children:[u.jsx(Ll,{size:14,strokeWidth:2.5}),n("skills.ai.submit")]})]})})})}async function l8(e){const{files:t}=await Ez(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 c8=[{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"}],u8={language:"var(--color-accent-purple)",end:"var(--color-secondary)",persona:"var(--color-primary)",workflow:"var(--color-accent-mint)",other:"var(--color-bg-cream)"};function d8(){var R,F;const e=Be(),[t,n]=C.useState("all"),[r,a]=C.useState(""),[o,l]=C.useState(null),[d,f]=C.useState(!1),[h,g]=C.useState(!1),m=Gt(),b=(((R=Ye({queryKey:["gen-jobs"],queryFn:h2,refetchInterval:3e3}).data)==null?void 0:R.data)??[]).filter(z=>z.kind==="skill"),k=b.filter(z=>z.status!=="done"),v=C.useRef(new Set);C.useEffect(()=>{for(const z of b)(z.status==="done"||z.status==="error")&&!v.current.has(z.id)&&(v.current.add(z.id),m.invalidateQueries({queryKey:["skills"]}),m.invalidateQueries({queryKey:["skill-updates"]}))},[b,m]);const N=(z,$)=>{Sz(z,$).then(()=>m.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},j=(((F=Ye({queryKey:["skill-updates"],queryFn:wz}).data)==null?void 0:F.data)??[]).filter(z=>z.status!=="same").length,{data:S,isLoading:_}=Ye({queryKey:["skills"],queryFn:()=>rx()}),M=Ye({queryKey:["projects"],queryFn:ba}),T=C.useMemo(()=>((S==null?void 0:S.data)??[]).filter($=>!(t!=="all"&&$.category!==t||r&&!$.name.toLowerCase().includes(r.toLowerCase()))),[S,t,r]),L=C.useMemo(()=>{const z=(S==null?void 0:S.data)??[],$={all:z.length};for(const q of z)$[q.category]=($[q.category]??0)+1;return $},[S]);return u.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[u.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:"Skills 🎯"}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:_?e("common.loading"):e("skills.subtitleCount",{count:(S==null?void 0:S.data.length)??0})})]}),u.jsxs("div",{className:"flex gap-3 items-center",children:[j>0&&u.jsx("span",{className:"nb-badge text-[10px]",title:e("skills.updates.badge",{count:String(j)}),children:e("skills.updates.badge",{count:String(j)})}),u.jsxs("button",{className:"nb-btn",onClick:()=>g(!0),type:"button",children:[u.jsx(Ll,{size:14,strokeWidth:2.5}),e("skills.ai")]}),u.jsxs("button",{className:"nb-btn",onClick:()=>f(!0),type:"button",children:[u.jsx(WN,{size:14,strokeWidth:2.5}),e("skills.import")]}),u.jsxs("button",{className:"nb-btn nb-btn-mint",onClick:async()=>{await bz(),m.invalidateQueries({queryKey:["skills"]}),m.invalidateQueries({queryKey:["skill-updates"]})},type:"button",children:[u.jsx(ga,{size:14,strokeWidth:2.5}),"Sync bundled"]})]})]}),u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsxs("div",{className:"relative flex-1 max-w-md",children:[u.jsx(co,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),u.jsx("input",{className:"nb-input pl-9 w-full",placeholder:e("skills.search.placeholder"),value:r,onChange:z=>a(z.target.value),"aria-label":e("skills.search.aria")})]}),u.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:c8.map(z=>u.jsxs("button",{type:"button",onClick:()=>n(z.value),className:["px-3 py-1 rounded-full text-xs font-bold font-[family-name:var(--font-body)]",t===z.value?"bg-[var(--color-text)] text-[var(--color-bg)]":"text-[var(--color-text-muted)] hover:text-[var(--color-text)]"].join(" "),children:[e(z.labelKey)," ",L[z.value]]},z.value))})]}),u.jsxs("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:[k.map(z=>u.jsxs("div",{className:`nb-card flex items-center gap-2 ${z.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,children:[z.status==="running"?u.jsx(Xe,{size:14,className:"animate-spin"}):u.jsx(Nn,{size:14,strokeWidth:3}),u.jsx("span",{className:"text-sm text-[var(--color-text-muted)] truncate",children:z.status==="running"?`${z.label} · ${e("skills.ai.wait")}`:`${z.label}: ${z.error??e("skills.ai.error")}`})]},z.id)),T.map(z=>{var $;return u.jsx(f8,{skill:z,projectCount:(($=M.data)==null?void 0:$.data.length)??0,onOpen:()=>l(z.name),onExport:()=>void l8(z.name)},z.name)})]}),o&&u.jsx(i8,{name:o,onClose:()=>l(null)}),d&&u.jsx(s8,{onClose:()=>f(!1)}),h&&u.jsx(o8,{onClose:()=>g(!1),onSubmit:(z,$)=>{N(z,$),g(!1)}})]})}function f8({skill:e,projectCount:t,onOpen:n,onExport:r}){const a=Be(),o=u8[e.category];return u.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:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:e.name}),u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("button",{type:"button",className:"nb-btn p-1",onClick:l=>{l.stopPropagation(),r()},"aria-label":a("skills.export"),title:a("skills.export"),children:u.jsx(Ph,{size:12,strokeWidth:2.5})}),u.jsx("span",{className:"nb-badge text-[10px]",style:{background:o},children:e.category})]})]}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] leading-5 line-clamp-3",children:e.description||"(no description)"}),u.jsxs("div",{className:"flex items-center justify-between text-xs font-[family-name:var(--font-mono)] pt-2 border-t-[1.5px] border-dashed border-[var(--color-border-light)]",children:[u.jsx("span",{className:"font-bold",children:e.linkedProjects.length>0?`● linked in ${e.linkedProjects.length}`:"○ not linked"}),u.jsxs("span",{className:"text-[var(--color-text-subtle)]",children:[t," projects"]})]})]})}function Bj(e){const t=e?`?q=${encodeURIComponent(e)}`:"";return ht(`/api/prompts${t}`)}function Dx(e){return ht(`/api/prompts/${encodeURIComponent(e)}`)}function h8(e){return Ri("/api/prompts",e)}function p8(e,t){return Bb(`/api/prompts/${encodeURIComponent(e)}`,t)}function m8(e){return N3(`/api/prompts/${encodeURIComponent(e)}`)}function g8(e){return Ri("/api/prompts/generate",{intent:e})}function $j(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 y8(){var T,L;const e=Be(),[t,n]=$b("prompts.last",""),[r,a]=C.useState(null),[o,l]=C.useState(!1),[d,f]=C.useState(""),[h,g]=C.useState(new Set),m=Gt(),y=Ye({queryKey:["prompts"],queryFn:()=>Bj()}),b=((T=y.data)==null?void 0:T.data)??[],k=C.useMemo(()=>[...new Set(b.flatMap(R=>R.tags))].sort(),[b]),N=(((L=Ye({queryKey:["gen-jobs"],queryFn:h2,refetchInterval:3e3}).data)==null?void 0:L.data)??[]).filter(R=>R.kind==="prompt"),E=N.filter(R=>R.status!=="done"),j=C.useRef(new Set);C.useEffect(()=>{for(const R of N)(R.status==="done"||R.status==="error")&&!j.current.has(R.id)&&(j.current.add(R.id),m.invalidateQueries({queryKey:["prompts"]}),R.status==="done"&&R.result&&n(R.result))},[N,m,n]);const S=R=>{g8(R).then(()=>m.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},_=C.useMemo(()=>{const R=d.trim().toLowerCase();return b.filter(F=>!(h.size&&![...h].every(z=>F.tags.includes(z))||R&&!(F.name.toLowerCase().includes(R)||F.description.toLowerCase().includes(R)||F.tags.some($=>$.toLowerCase().includes(R)))))},[b,h,d]);C.useEffect(()=>{t&&b.length&&!b.some(R=>R.name===t)&&n("")},[t,b,n]);const M=R=>g(F=>{const z=new Set(F);return z.has(R)?z.delete(R):z.add(R),z});return u.jsxs("div",{className:"flex flex-col flex-1 min-h-0 w-full gap-3",children:[u.jsxs("div",{className:"shrink-0 flex items-center justify-between gap-3",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-3xl font-bold",children:e("prompts.title")}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.desc")})]}),u.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[u.jsxs("button",{className:"nb-btn",type:"button",onClick:()=>l(!0),children:[u.jsx(Ll,{size:14,strokeWidth:2.5}),e("prompts.ai")]}),u.jsxs("button",{className:"nb-btn nb-btn-mint",type:"button",onClick:()=>a({mode:"new"}),children:[u.jsx(pr,{size:14,strokeWidth:3}),e("prompts.new")]})]})]}),u.jsxs("div",{className:"shrink-0 flex flex-col gap-2",children:[u.jsxs("label",{className:"nb-input flex items-center gap-2 w-full",style:{padding:"6px 10px"},children:[u.jsx(co,{size:14}),u.jsx("input",{type:"text",value:d,onChange:R=>f(R.target.value),placeholder:e("prompts.search"),className:"bg-transparent outline-none flex-1 text-sm","aria-label":e("prompts.search")})]}),k.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(R=>u.jsx("button",{type:"button",onClick:()=>M(R),className:`text-xs border-2 border-[var(--color-text)] rounded-full px-2 py-0.5 ${h.has(R)?"bg-[var(--color-accent-mint)] font-bold":"bg-[var(--color-bg)]"}`,children:R},R))})]}),u.jsxs("div",{className:"flex gap-5 flex-1 min-h-0",children:[u.jsxs("aside",{className:"w-80 shrink-0 min-h-0 overflow-y-auto flex flex-col gap-2 pr-1",children:[E.map(R=>u.jsxs("div",{className:`nb-card flex items-center gap-2 ${R.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,style:{padding:"8px 10px"},children:[R.status==="running"?u.jsx(Xe,{size:12,className:"animate-spin"}):u.jsx(Nn,{size:12,strokeWidth:3}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)] truncate",children:R.status==="running"?e("prompts.ai.wait"):`${e("prompts.ai.error")}: ${R.error??""}`})]},R.id)),y.isLoading?u.jsx("div",{className:"nb-card",children:u.jsx(Xe,{size:14,className:"animate-spin"})}):_.length===0?u.jsx("div",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.empty")})}):_.map(R=>u.jsxs("button",{type:"button",onClick:()=>n(R.name),className:`nb-card w-full text-left ${t===R.name?"bg-[var(--color-accent-mint)]":""}`,style:{padding:"8px 10px"},children:[u.jsxs("span",{className:"flex items-center gap-1.5",children:[R.favorite&&u.jsx(YN,{size:12,fill:"currentColor"}),u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold truncate",children:R.name})]}),R.description&&u.jsx("span",{className:"block text-xs text-[var(--color-text-muted)] truncate",children:R.description})]},R.name))]}),u.jsx("div",{className:"flex-1 min-w-0 min-h-0",children:t?u.jsx(x8,{name:t,onEdit:()=>a({mode:"edit",name:t}),onDeleted:()=>n("")},t):u.jsx("div",{className:"nb-card",children:u.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("prompts.selectHint")})})})]}),r&&u.jsx(w8,{name:r.mode==="edit"?r.name:null,onClose:()=>a(null),onSaved:R=>{a(null),n(R)}}),o&&u.jsx(b8,{onClose:()=>l(!1),onSubmit:R=>{S(R),l(!1)}})]})}function b8({onClose:e,onSubmit:t}){const n=Be(),[r,a]=C.useState("");return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[u.jsx(Ll,{size:16,strokeWidth:2.5}),n("prompts.ai.title")]}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:u.jsx(Nn,{size:14,strokeWidth:3})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("prompts.ai.intent")}),u.jsx("textarea",{value: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")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!r.trim(),onClick:()=>t(r),children:[u.jsx(Ll,{size:14,strokeWidth:2.5}),n("prompts.ai.submit")]})]})})})}function x8({name:e,onEdit:t,onDeleted:n}){const r=Be(),a=Gt(),{confirm:o}=un(),l=Ye({queryKey:["prompt",e],queryFn:()=>Dx(e)}),d=Ct({mutationFn:()=>m8(e),onSuccess:()=>{a.invalidateQueries({queryKey:["prompts"]}),n()}});if(l.isLoading)return u.jsx("div",{className:"nb-card",children:u.jsx(Xe,{size:14,className:"animate-spin"})});const f=l.data;if(!f)return null;const h=$j(f.body);return u.jsxs("div",{className:"nb-card flex flex-col gap-3 h-full min-h-0",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 shrink-0",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold flex items-center gap-2",children:[f.favorite&&u.jsx(YN,{size:16,fill:"currentColor"}),u.jsx("code",{className:"font-[family-name:var(--font-mono)] truncate",children:f.name})]}),f.description&&u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:f.description})]}),u.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:t,children:[u.jsx(Bh,{size:14,strokeWidth:3}),r("common.edit")]}),u.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:u.jsx(fi,{size:14,strokeWidth:3})})]})]}),f.tags.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 shrink-0",children:f.tags.map(g=>u.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))}),u.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}),u.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 v8({tags:e,onChange:t}){const n=Be(),[r,a]=C.useState(""),o=()=>{const l=r.trim();l&&!e.includes(l)&&t([...e,l]),a("")};return u.jsxs("div",{className:"nb-input w-full flex flex-wrap gap-1.5 items-center",children:[e.map(l=>u.jsxs("span",{className:"inline-flex items-center gap-1 text-xs bg-[var(--color-accent-mint)] border-2 border-[var(--color-text)] rounded px-1.5 py-0.5",children:[l,u.jsx("button",{type:"button",onClick:()=>t(e.filter(d=>d!==l)),"aria-label":`remove ${l}`,children:u.jsx(Nn,{size:10,strokeWidth:3})})]},l)),u.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 w8({name:e,onClose:t,onSaved:n}){const r=Be(),a=Gt(),{alert:o}=un(),l=e===null,d=Ye({queryKey:["prompt",e],queryFn:()=>Dx(e),enabled:!l}),[f,h]=C.useState(l?{name:"",description:"",tags:[],body:"",favorite:!1}:null);C.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?h8({name:f.name,...b}):p8(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=C.useMemo(()=>f?/^[a-z0-9][a-z0-9-]*$/.test(f.name):!1,[f]),y=C.useMemo(()=>f?$j(f.body):[],[f]);return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-2xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold",children:l?r("prompts.new"):e}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:t,"aria-label":"close",children:u.jsx(Nn,{size:14,strokeWidth:3})})]}),!l&&d.isLoading?u.jsx(Xe,{size:14,className:"animate-spin"}):f?u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:r("prompts.name")}),u.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&&u.jsx("span",{className:"text-xs text-[var(--color-crashed)]",children:r("prompts.nameError")})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:r("prompts.description")}),u.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")})]})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:r("prompts.tags")}),u.jsx(v8,{tags:f.tags,onChange:b=>h({...f,tags:b})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:r("prompts.body")}),u.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")}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:y.length?r("prompts.vars",{names:y.join(", ")}):r("prompts.noVars")})]}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:g.isPending||l&&!m||!f.body.trim(),onClick:()=>g.mutate(),children:[g.isPending?u.jsx(Xe,{size:14,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:3}),r("prompts.save")]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:f.favorite,onChange:b=>h({...f,favorite:b.target.checked})}),r("prompts.favorite")]})]})]}):null]})})})}function k8(){var o;const e=Be(),t=Ye({queryKey:["system-info"],queryFn:r_}),n=Ye({queryKey:["system-env"],queryFn:_3}),[r,a]=C.useState(!1);return u.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[u.jsx("header",{children:u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:e("system.h1")})}),u.jsx(E8,{current:(o=t.data)==null?void 0:o.version}),u.jsxs("section",{className:"nb-card",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-3",children:e("system.runtime")}),t.data?u.jsxs("dl",{className:"grid grid-cols-1 sm:grid-cols-[160px_1fr] gap-y-2 text-sm",children:[u.jsx("dt",{className:"font-bold",children:"Node"}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.data.nodeVersion}),u.jsx("dt",{className:"font-bold",children:"Platform"}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.data.platform}),u.jsx("dt",{className:"font-bold",children:"PID"}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.data.pid??"—"}),u.jsx("dt",{className:"font-bold",children:"Uptime"}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:j8(t.data.uptimeMs)})]}):u.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("common.loading")})]}),u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center justify-between mb-3",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:[e("system.env.title.prefix"),u.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?u.jsx("span",{className:"text-xs text-[var(--color-stuck)] font-bold",children:e("system.env.editing.label")}):u.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>a(!0),type:"button","aria-label":e("system.env.edit.aria"),children:[u.jsx(Bh,{size:12,strokeWidth:2.5})," ",e("system.env.edit.button")]})]}),r?u.jsx(S8,{onClose:()=>{a(!1),n.refetch()}}):n.data&&n.data.exists?u.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=>u.jsxs("div",{className:"contents",children:[u.jsxs("dt",{className:"font-bold flex items-center gap-2",children:[l.masked&&u.jsx("span",{className:"text-[var(--color-stuck)]",children:"🔒"}),l.key]}),u.jsx("dd",{className:"text-[var(--color-text-muted)] truncate",children:l.value})]},l.key))}):u.jsxs("p",{className:"text-[var(--color-text-muted)] text-sm",children:[e("system.env.empty.before"),u.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")]})]}),u.jsx(N8,{})]})}function E8({current:e}){var v;const t=Be(),{confirm:n,alert:r}=un(),[a,o]=C.useState(!1),[l,d]=C.useState(null),f=Ye({queryKey:["latest-version"],queryFn:D3,enabled:!1}),[h,g]=C.useState(null),[m,y]=C.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 j=await O3();if(d(j.output),g(j.installedVersion),y(j.command),j.ok)r({title:t("system.upgrade.success.title"),body:t("system.upgrade.success.body",{version:j.installedVersion??"?"})});else{const S=j.installedVersion&&j.installedVersion===e?t("system.upgrade.notEffective.same",{version:j.installedVersion}):t("system.upgrade.notEffective.notInstalled");r({title:t("system.upgrade.notEffective.title"),body:S})}}catch(j){d(j.message),r({title:t("system.upgrade.error.title"),body:j.message})}finally{o(!1)}}},k=async()=>{const N=f.data&&!f.data.upToDate?`npm i -g @coralai/sps-cli@${f.data.latest}`:m;try{await navigator.clipboard.writeText(N),r({title:t("system.upgrade.copy.success.title"),body:t("system.upgrade.copy.success.body",{cmd:N})})}catch{r({title:t("system.upgrade.copy.fail.title"),body:t("system.upgrade.copy.fail.body",{cmd:N})})}};return u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center justify-between mb-3",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:t("system.upgrade.title")}),u.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?u.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(ga,{size:12,strokeWidth:2.5}),t("system.upgrade.checkUpdate")]})]}),u.jsxs("dl",{className:"grid grid-cols-1 sm:grid-cols-[160px_1fr] gap-y-2 text-sm",children:[u.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.current")}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:e??"—"}),f.data&&u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.latest")}),u.jsxs("dd",{className:"font-[family-name:var(--font-mono)] flex items-center gap-2 flex-wrap",children:[f.data.latest,f.data.upToDate?u.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:t("system.upgrade.latestPill")}):u.jsxs(u.Fragment,{children:[u.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?u.jsx(Xe,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(Ph,{size:11,strokeWidth:2.5}),t("system.upgrade.button.upgrade")]}),u.jsxs("button",{className:"nb-btn",style:{padding:"3px 10px",fontSize:11},onClick:k,type:"button","aria-label":t("system.upgrade.button.copyAria"),title:t("system.upgrade.button.copyTitle"),children:[u.jsx($R,{size:11,strokeWidth:2.5})," ",t("system.upgrade.button.copy")]})]})]})]}),h&&u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.installed")}),u.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)?u.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:t("system.upgrade.installed.ok")}):h===e?u.jsx("span",{className:"nb-status",style:{background:"var(--color-stuck-bg)",color:"var(--color-stuck)"},children:t("system.upgrade.installed.fail")}):null]})]}),f.isError&&u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.check")}),u.jsx("dd",{className:"text-[var(--color-crashed)] text-xs",children:f.error instanceof Error?f.error.message:String(f.error)})]})]}),l&&u.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 S8({onClose:e}){const t=Be(),n=Gt(),{alert:r}=un(),a=Ye({queryKey:["system-env-raw"],queryFn:j3}),[o,l]=C.useState(null),[d,f]=C.useState(null);C.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 C3(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?u.jsx("p",{className:"text-[var(--color-text-muted)]",children:t("common.loading")}):u.jsxs("div",{children:[u.jsx("p",{className:"text-xs text-[var(--color-stuck)] font-bold mb-2",children:t("system.env.warning")}),u.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")}),u.jsxs("div",{className:"flex items-center justify-between mt-3",children:[u.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"):""]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px"},onClick:e,disabled:g.isPending,type:"button",children:[u.jsx(Nn,{size:12,strokeWidth:3})," ",t("system.env.cancel")]}),u.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?u.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(Oi,{size:12,strokeWidth:3}),t("system.env.save")]})]})]})]})}function N8(){var y;const e=Be(),{alert:t}=un(),n=Ye({queryKey:["projects"],queryFn:ba}),[r,a]=C.useState({}),[o,l]=C.useState({}),[d,f]=C.useState({}),h=(((y=n.data)==null?void 0:y.data)??[]).map(b=>({project:b.name})),g=async(b,k)=>{l(v=>({...v,[b]:k?"fix":"check"}));try{const v=await R3(b,k);a(N=>({...N,[b]:v})),f(N=>({...N,[b]:!0}))}catch(v){t({title:e(k?"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 u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center justify-between mb-3",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:e("system.diagnostics.title")}),u.jsxs("button",{className:"nb-btn nb-btn-mint",style:{padding:"6px 12px",fontSize:12},onClick:()=>{m()},disabled:h.length===0||Object.values(o).some(Boolean),type:"button",children:[u.jsx(ga,{size:12,strokeWidth:2.5}),e("system.diagnostics.checkAll")]})]}),h.length===0?u.jsx("p",{className:"text-[var(--color-text-muted)] text-sm",children:e("system.diagnostics.empty")}):u.jsx("ul",{className:"flex flex-col gap-2",children:h.map(b=>{const k=r[b.project],v=o[b.project],N=k?k.checks.filter(_=>_.status==="fail").length:0,E=k?k.checks.filter(_=>_.status==="warn").length:0,j=d[b.project]??!1,S=k!=null;return u.jsxs("li",{className:"bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg",children:[u.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[u.jsxs("button",{type:"button",onClick:()=>f(_=>({..._,[b.project]:!j})),disabled:!S,className:"flex items-center gap-2 flex-1 text-left min-w-0","aria-label":e(j?"system.diagnostics.collapseAria":"system.diagnostics.expandAria"),children:[S&&k.ok?u.jsx(uh,{size:16,className:"text-[var(--color-running)] shrink-0",strokeWidth:2.5}):S?u.jsx(vu,{size:16,className:"text-[var(--color-stuck)] shrink-0",strokeWidth:2.5}):u.jsx(uh,{size:16,className:"text-[var(--color-text-subtle)] shrink-0",strokeWidth:2.5}),S&&(j?u.jsx(Ql,{size:12}):u.jsx(Wl,{size:12})),u.jsx("span",{className:"font-bold font-[family-name:var(--font-mono)]",children:b.project}),S?k.ok?u.jsx("span",{className:"text-xs text-[var(--color-running)] font-semibold",children:"OK"}):u.jsxs("span",{className:"text-xs text-[var(--color-stuck)] font-semibold",children:[N," fail · ",E," warn"]}):u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:e("system.diagnostics.never")})]}),u.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"?u.jsx(Xe,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(ga,{size:11,strokeWidth:2.5}),e("system.diagnostics.check")]}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>{g(b.project,!0)},disabled:!!v||S&&k.ok,type:"button","aria-label":e("system.diagnostics.fixAria"),title:S&&k.ok?e("system.diagnostics.noFixesNeeded"):e("system.diagnostics.fix.tip"),children:[v==="fix"?u.jsx(Xe,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(ZN,{size:11,strokeWidth:2.5}),e("system.diagnostics.fix")]})]}),j&&S&&u.jsxs("div",{className:"border-t-2 border-dashed border-[var(--color-text)] px-3 py-2",children:[u.jsx("ul",{className:"flex flex-col gap-1 text-xs font-[family-name:var(--font-mono)]",children:k.checks.map((_,M)=>u.jsx(_8,{check:_},`${_.name}-${M}`))}),k.fixes.length>0&&u.jsxs("div",{className:"mt-3 bg-[var(--color-running-bg)] border-2 border-[var(--color-running)] rounded p-2",children:[u.jsx("div",{className:"text-xs font-bold text-[var(--color-running)] mb-1",children:e("system.diagnostics.fixed")}),u.jsx("ul",{className:"text-xs list-disc pl-4",children:k.fixes.map((_,M)=>u.jsx("li",{children:_},M))})]})]})]},b.project)})})]})}function _8({check:e}){const t=e.status==="pass"?u.jsx(uh,{size:12,className:"text-[var(--color-running)]",strokeWidth:2.5}):e.status==="fail"?u.jsx(vu,{size:12,className:"text-[var(--color-crashed)]",strokeWidth:2.5}):e.status==="warn"?u.jsx(vu,{size:12,className:"text-[var(--color-stuck)]",strokeWidth:2.5}):u.jsx("span",{className:"w-3 h-3 rounded-full bg-[var(--color-text-subtle)] inline-block"});return u.jsxs("li",{className:"flex items-start gap-2",children:[u.jsx("span",{className:"pt-0.5 shrink-0",children:t}),u.jsx("span",{className:"font-bold w-32 shrink-0",children:e.name}),u.jsx("span",{className:"text-[var(--color-text-muted)] break-words",children:e.message})]})}function j8(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 C8(){return ht("/api/chat/sessions")}function A8(e){return ht(`/api/chat/sessions/${e}`)}async function ry(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 T8(e){const t=await fetch(`/api/chat/sessions/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(`${t.status}`)}async function M8(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 D8(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 O8(e,t){const n=t?`?since=${encodeURIComponent(t)}`:"";return ht(`/api/chat/sessions/${e}/messages${n}`)}function R8({onInsert:e,disabled:t,className:n="nb-btn"}){var m;const r=Be(),[a,o]=C.useState(!1),[l,d]=C.useState(""),h=((m=Ye({queryKey:["prompts",l],queryFn:()=>Bj(l||void 0),enabled:a}).data)==null?void 0:m.data)??[],g=async y=>{try{const b=await Dx(y);e(b.body)}finally{o(!1),d("")}};return u.jsxs("div",{className:"relative flex-shrink-0",children:[u.jsx("button",{type:"button",className:n,onClick:()=>o(y=>!y),disabled:t,"aria-label":r("prompts.insert"),title:r("prompts.insert"),children:u.jsx(qN,{size:15,strokeWidth:2.5})}),a&&u.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:[u.jsxs("label",{className:"flex items-center gap-2 border-2 border-[var(--color-text)] rounded px-2 py-1",children:[u.jsx(co,{size:12}),u.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?u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-1 py-2",children:r("prompts.empty")}):h.map(y=>u.jsxs("button",{type:"button",onClick:()=>void g(y.name),className:"text-left px-2 py-1 rounded hover:bg-[var(--color-bg-cream)]",children:[u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold",children:y.name}),y.description&&u.jsx("span",{className:"block text-xs text-[var(--color-text-muted)] truncate",children:y.description})]},y.name))]})]})}function NE(){var de,Ce,Re,De,le,Ne,Te,ke,We;const e=Be(),{sessionId:t}=Cb(),n=vs(),r=Gt(),{confirm:a,alert:o}=un(),l=Ye({queryKey:["chat-sessions"],queryFn:C8,refetchInterval:5e3}),d=Ye({queryKey:["chat-session",t],queryFn:()=>A8(t??""),enabled:!!t,refetchInterval:4e3}),[f,h]=C.useState(null),g=re=>`chat-draft:${re??""}`,[m,y]=C.useState(()=>localStorage.getItem(g(t))??""),b=C.useCallback(re=>{y(Ae=>{const ue=typeof re=="function"?re(Ae):re;try{t&&localStorage.setItem(g(t),ue)}catch{}return ue})},[t]);C.useEffect(()=>{y(localStorage.getItem(g(t))??"")},[t]);const[k,v]=C.useState(!1),N=C.useRef(null),E=C.useRef(!0),[j,S]=C.useState(!1),_=()=>{const re=N.current;return!re||re.scrollHeight-re.scrollTop-re.clientHeight<40},M=C.useCallback(()=>{const re=N.current;re&&(re.scrollTop=re.scrollHeight),E.current=!0,S(!1)},[]),T=C.useCallback(()=>{const re=_();E.current=re,S(!re)},[]),L=C.useRef(null);C.useEffect(()=>{const re=L.current;re&&(re.style.height="auto",re.style.height=`${Math.min(re.scrollHeight,200)}px`,re.scrollTop=re.scrollHeight)},[m]);const R="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",[F,z]=C.useState(!1),[$,q]=C.useState([]),[Y,D]=C.useState(!1),[H,O]=C.useState(!1),[V,Q]=C.useState(!1),[K,I]=C.useState(null),[P,G]=C.useState(!1);C.useEffect(()=>{if(!t)return;const re=new EventSource(`/stream/chat/${encodeURIComponent(t)}`);let Ae=!0;return re.addEventListener("open",()=>{if(Ae){Ae=!1;return}const ue=r.getQueryData(["chat-session",t]),he=ue!=null&&ue.messages.length?ue.messages[ue.messages.length-1].ts:void 0;O8(t,he).then(ge=>{ge.data.length!==0&&r.setQueryData(["chat-session",t],Le=>{if(!Le)return Le;const ze=new Set(Le.messages.map(te=>te.id)),Fe=ge.data.filter(te=>!ze.has(te.id));return Fe.length===0?Le:{...Le,messages:[...Le.messages,...Fe],lastMessageAt:Fe[Fe.length-1].ts,messageCount:Le.messageCount+Fe.length}})}).catch(()=>{})}),re.addEventListener("chat.message",ue=>{try{const he=JSON.parse(ue.data);r.setQueryData(["chat-session",t],ge=>{if(!ge||ge.messages.some(Fe=>Fe.id===he.message.id))return ge;const ze=ge.messages.findIndex(Fe=>Fe.role==="user"&&Fe.id.startsWith("optim-")&&Fe.content===he.message.content);if(ze>=0){const Fe=[...ge.messages];return Fe[ze]=he.message,{...ge,messages:Fe}}return{...ge,messages:[...ge.messages,he.message]}})}catch{}}),re.addEventListener("chat.message.pending",ue=>{try{const he=JSON.parse(ue.data);h({id:he.assistantId,blocks:[],done:!1,finalMessage:null})}catch{}}),re.addEventListener("chat.message.chunk.text",ue=>{try{const he=JSON.parse(ue.data);h(ge=>{if(!ge||ge.id!==he.assistantId)return ge;const Le=[...ge.blocks],ze=Le[Le.length-1];return ze&&ze.type==="text"?Le[Le.length-1]={...ze,target:ze.target+he.text}:Le.push({type:"text",target:he.text,displayed:""}),{...ge,blocks:Le}})}catch{}}),re.addEventListener("chat.message.chunk.tool_use",ue=>{try{const he=JSON.parse(ue.data);h(ge=>!ge||ge.id!==he.assistantId?ge:{...ge,blocks:[...ge.blocks,{type:"tool_use",id:he.id,title:he.title,kind:he.kind,status:he.status,input:he.input,locations:he.locations}]})}catch{}}),re.addEventListener("chat.message.chunk.tool_update",ue=>{try{const he=JSON.parse(ue.data);h(ge=>!ge||ge.id!==he.assistantId?ge:{...ge,blocks:ge.blocks.map(Le=>Le.type==="tool_use"&&Le.id===he.id?{...Le,status:he.status,input:Le.input??he.input,locations:Le.locations??he.locations}:Le)})}catch{}}),re.addEventListener("chat.message.complete",ue=>{try{const he=JSON.parse(ue.data);h(ge=>ge&&ge.id===he.assistantId?{...ge,done:!0,finalMessage:he.message}:ge)}catch{}}),()=>re.close()},[t,r]),C.useEffect(()=>{if(!f)return;const re=f.blocks.reduce((ue,he)=>he.type==="text"?ue+(he.target.length-he.displayed.length):ue,0);if(re<=0){if(f.done&&f.finalMessage){const ue=f.finalMessage;r.setQueryData(["chat-session",t],he=>!he||he.messages.some(ge=>ge.id===ue.id)?he:{...he,messages:[...he.messages,ue],lastMessageAt:ue.ts,messageCount:he.messageCount+1}),r.invalidateQueries({queryKey:["chat-sessions"]}),r.invalidateQueries({queryKey:["chat-session",t]}),h(null),v(!1)}return}const Ae=setTimeout(()=>{h(ue=>{if(!ue)return ue;let he=Math.max(1,Math.ceil(re/40));const ge=ue.blocks.map(Le=>{if(Le.type!=="text"||he<=0)return Le;const ze=Le.target.length-Le.displayed.length;if(ze<=0)return Le;const Fe=Math.min(ze,he);return he-=Fe,{...Le,displayed:Le.target.slice(0,Le.displayed.length+Fe)}});return{...ue,blocks:ge}})},25);return()=>clearTimeout(Ae)},[f,r,t]),C.useEffect(()=>{if(E.current){const re=N.current;re&&(re.scrollTop=re.scrollHeight)}},[d.data,f]),C.useEffect(()=>{E.current=!0,S(!1)},[t]);const B=C.useCallback(async(re={})=>{var Ae,ue;try{const he=await ry({cwd:((Ae=re.cwd)==null?void 0:Ae.trim())||void 0,title:((ue=re.title)==null?void 0:ue.trim())||void 0,agentKind:re.agentKind,model:re.model,providerId:re.providerId});r.invalidateQueries({queryKey:["chat-sessions"]}),n(`/chat/${he.id}`),z(!1)}catch(he){o({title:e("chat.error.create.title"),body:he instanceof Error?he.message:String(he)})}},[r,n,o,e]),oe=C.useCallback(async()=>{const re=m.trim();if(!re&&$.length===0||k)return;let Ae=t;if(!Ae){const ge=await ry();r.invalidateQueries({queryKey:["chat-sessions"]}),Ae=ge.id,n(`/chat/${Ae}`,{replace:!0})}E.current=!0,S(!1);const ue=$.map(ge=>ge.path),he={id:`optim-${Date.now()}`,role:"user",content:re||e("chat.placeholder.attachment"),ts:new Date().toISOString(),status:"complete",attachments:ue.length>0?ue:void 0};r.setQueryData(["chat-session",Ae],ge=>ge?{...ge,messages:[...ge.messages,he],lastMessageAt:he.ts,messageCount:ge.messageCount+1}:{id:Ae,createdAt:he.ts,lastMessageAt:he.ts,title:re.slice(0,60)||e("chat.placeholder.attachmentTitle"),project:null,messageCount:1,messages:[he]}),b(""),q([]),v(!0);try{await M8(Ae,re||e("chat.placeholder.viewAttachment"),ue.length>0?ue:void 0)}catch(ge){v(!1),console.error("sendMessage failed",ge),o({title:e("chat.error.send.title"),body:ge instanceof Error?ge.message:String(ge)})}},[m,$,k,t,r,n,o,e]),be=C.useCallback(async re=>{if(re.size>s2){o({title:e("chat.error.fileTooBig.title"),body:e("chat.error.fileTooBig.body",{size:(re.size/1024/1024).toFixed(2),name:re.name})});return}let Ae=t;if(!Ae){const ue=await ry();r.invalidateQueries({queryKey:["chat-sessions"]}),Ae=ue.id,n(`/chat/${Ae}`,{replace:!0})}D(!0);try{const ue=await Gz(Ae,re);q(he=>[...he,{path:ue.path,name:ue.name}])}catch(ue){o({title:e("chat.error.uploadAttachment.title"),body:ue instanceof Error?ue.message:String(ue)})}finally{D(!1)}},[t,r,n,o,e]),xe=C.useCallback(re=>{q(Ae=>Ae.filter(ue=>ue.path!==re))},[]),we=C.useCallback(async(re,Ae)=>{await a({title:e("chat.delete.confirm.title"),body:e(Ae==="cli"?"chat.delete.confirm.body.cli":"chat.delete.confirm.body.console"),confirm:e("chat.delete.confirm.button"),danger:!0})&&(await T8(re),r.invalidateQueries({queryKey:["chat-sessions"]}),t===re&&n("/chat"))},[r,t,n,a,e]),J=C.useCallback(async()=>{if(t)try{await D8(t)}catch(re){o({title:e("chat.error.interrupt.title"),body:re instanceof Error?re.message:String(re)})}},[t,o,e]);return u.jsxs("div",{className:"grid grid-cols-[260px_1fr] gap-4 h-[calc(100vh-140px)]",children:[u.jsxs("aside",{className:"nb-card p-3 overflow-auto flex flex-col gap-2",children:[u.jsxs("button",{className:"nb-btn nb-btn-primary w-full justify-center",onClick:()=>z(!0),type:"button",children:[u.jsx(pr,{size:14,strokeWidth:3}),e("chat.list.new")]}),u.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:((de=l.data)==null?void 0:de.data.length)??0})}),u.jsx("div",{className:"flex flex-col gap-1.5 mt-1",children:(()=>{var Fe;const re=((Fe=l.data)==null?void 0:Fe.data)??[],Ae=Date.now(),ue=10080*60*1e3,he=te=>new Date(te.lastMessageAt??te.createdAt).getTime(),ge=re.filter(te=>Ae-he(te)<=ue),Le=re.filter(te=>Ae-he(te)>ue),ze=te=>u.jsxs("div",{className:["group flex items-start gap-2 p-2 rounded-lg border-2 border-transparent",t===te.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:[u.jsxs("button",{type:"button","aria-label":e("chat.list.openAria",{title:te.title,cwd:te.cwd?e("chat.list.cwdSuffix",{cwd:te.cwd}):""}),onClick:()=>n(`/chat/${te.id}`),className:"flex items-start gap-2 flex-1 min-w-0 text-left",children:[u.jsx(sk,{size:14,strokeWidth:2.5,className:"mt-0.5 flex-shrink-0"}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[u.jsx("p",{className:"text-sm font-semibold truncate flex-1",children:te.title}),te.source==="cli"&&u.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")})]}),u.jsx("p",{className:"text-[10px] text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] truncate",children:e("chat.list.msgs",{count:te.messageCount,time:qj(te.lastMessageAt??te.createdAt,e)})}),te.cwd&&u.jsxs("p",{className:"text-[10px] text-[var(--color-text-subtle)] font-[family-name:var(--font-mono)] truncate flex items-center gap-1",title:te.cwd,children:[u.jsx(ku,{size:9,strokeWidth:2.5,className:"flex-shrink-0"}),u.jsx("span",{className:"truncate",dir:"rtl",children:te.cwd})]})]})]}),u.jsx("button",{type:"button","aria-label":te.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:ve=>{ve.stopPropagation(),we(te.id,te.source)},children:u.jsx(fi,{size:12})})]},te.id);return u.jsxs(u.Fragment,{children:[ge.map(ze),Le.length>0&&u.jsxs(u.Fragment,{children:[u.jsxs("button",{type:"button",onClick:()=>G(te=>!te),"aria-expanded":P,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:[P?u.jsx(Ql,{size:12,strokeWidth:2.5}):u.jsx(Wl,{size:12,strokeWidth:2.5}),e("chat.list.olderToggle",{count:Le.length})]}),P&&Le.map(ze)]}),re.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-subtle)] italic text-center py-4",children:e("chat.list.empty")})]})})()})]}),u.jsx("div",{className:"nb-card p-0 flex flex-col overflow-hidden",children:t?u.jsxs(u.Fragment,{children:[u.jsxs("header",{className:"px-4 py-3 border-b-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:((Ce=d.data)==null?void 0:Ce.title)??e("common.loading")}),((Re=d.data)==null?void 0:Re.model)&&u.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:[u.jsx(dh,{size:11,strokeWidth:2.5})," ",d.data.model]})]}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:t}),((De=d.data)==null?void 0:De.claudeSessionId)&&u.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]}),((le=d.data)==null?void 0:le.cwd)&&u.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:[u.jsx(ku,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}),u.jsx("span",{className:"truncate",children:d.data.cwd})]})]}),u.jsxs("div",{className:"relative flex-1 flex flex-col min-h-0",children:[u.jsxs("div",{ref:N,onScroll:T,className:"flex-1 overflow-auto p-4 flex flex-col gap-4",children:[(((Ne=d.data)==null?void 0:Ne.messages)??[]).filter(re=>!(f&&re.status==="streaming")).map(re=>u.jsx(z8,{msg:re,sessionId:t??null,onPreviewAttachment:Ae=>I(Ae)},re.id)),f&&u.jsx(B8,{pending:f}),!d.isLoading&&(((Te=d.data)==null?void 0:Te.messages)??[]).length===0&&!f&&!k&&u.jsx("p",{className:"text-center text-[var(--color-text-subtle)] italic mt-12",children:e("chat.session.empty")})]}),j&&u.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:u.jsx(wR,{size:18,strokeWidth:3})})]}),((ke=d.data)==null?void 0:ke.source)==="cli"?u.jsxs("div",{className:"border-t-2 border-[var(--color-text)] p-4 bg-[var(--color-accent-purple)]",children:[u.jsxs("p",{className:"text-sm font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] text-center",children:[u.jsx("strong",{children:e("chat.cli.banner.bold")})," — ",e("chat.cli.banner")]}),u.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-/,"")]})]}):u.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:re=>{re.dataTransfer.types.includes("Files")&&(re.preventDefault(),re.dataTransfer.dropEffect="copy",V||Q(!0))},onDragLeave:()=>Q(!1),onDrop:re=>{if(!re.dataTransfer.types.includes("Files"))return;re.preventDefault(),Q(!1);const Ae=Array.from(re.dataTransfer.files??[]);for(const ue of Ae)be(ue)},children:[($.length>0||Y)&&u.jsxs("div",{className:"flex flex-wrap gap-2 mb-2",children:[$.map(re=>u.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:()=>I(re.path),title:e("chat.attachment.previewTooltip",{name:re.name,path:re.path}),children:[kh(re.path)?u.jsx(gL,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}):u.jsx(Gu,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}),u.jsx("span",{className:"truncate max-w-[180px]",children:re.name}),u.jsx("span",{role:"button","aria-label":e("chat.input.removeAttachment",{name:re.name}),className:"ml-1 hover:text-[var(--color-crashed)] cursor-pointer",onClick:Ae=>{Ae.stopPropagation(),xe(re.path)},children:u.jsx(Nn,{size:11,strokeWidth:3})})]},re.path)),Y&&u.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:[u.jsx(Xe,{size:11,strokeWidth:2.5,className:"animate-spin"}),e("chat.input.uploading")]})]}),u.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:[u.jsx("textarea",{ref:L,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:re=>b(re.target.value),onKeyDown:re=>{re.key==="Enter"&&!re.shiftKey&&!re.nativeEvent.isComposing&&(re.preventDefault(),oe())},onPaste:re=>{const ue=Array.from(re.clipboardData.items??[]).filter(he=>he.kind==="file"&&he.type.startsWith("image/"));if(ue.length!==0){re.preventDefault();for(const he of ue){const ge=he.getAsFile();ge&&be(ge)}}},"aria-label":e("chat.input.aria")}),u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("button",{type:"button",className:R,onClick:()=>O(!0),disabled:k,"aria-label":e("chat.input.attach.aria"),title:e("chat.input.attach.title"),children:u.jsx(TL,{size:15,strokeWidth:2.5})}),u.jsx(R8,{className:R,disabled:k,onInsert:re=>b(Ae=>Ae.trim()?`${Ae}
645
+ # ...`,"aria-label":t("skills.import.body")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:h.isPending||!f||!l.trim(),onClick:()=>h.mutate(),children:[h.isPending?u.jsx(Xe,{size:14,className:"animate-spin"}):u.jsx(WN,{size:14,strokeWidth:3}),t("skills.import.submit")]})]})})}function o8({onClose:e,onSubmit:t}){const n=Be(),[r,a]=C.useState(""),[o,l]=C.useState(""),d=/^[a-z0-9][a-z0-9-]*$/.test(r);return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[u.jsx(Ll,{size:16,strokeWidth:2.5}),n("skills.ai.title")]}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:u.jsx(Nn,{size:14,strokeWidth:3})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.name")}),u.jsx("input",{type:"text",value: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")})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("skills.ai.intent")}),u.jsx("textarea",{value: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")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!d||!o.trim(),onClick:()=>t(r,o),children:[u.jsx(Ll,{size:14,strokeWidth:2.5}),n("skills.ai.submit")]})]})})})}async function l8(e){const{files:t}=await Ez(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 c8=[{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"}],u8={language:"var(--color-accent-purple)",end:"var(--color-secondary)",persona:"var(--color-primary)",workflow:"var(--color-accent-mint)",other:"var(--color-bg-cream)"};function d8(){var R,F;const e=Be(),[t,n]=C.useState("all"),[r,a]=C.useState(""),[o,l]=C.useState(null),[d,f]=C.useState(!1),[h,g]=C.useState(!1),m=Gt(),b=(((R=Ye({queryKey:["gen-jobs"],queryFn:h2,refetchInterval:3e3}).data)==null?void 0:R.data)??[]).filter(z=>z.kind==="skill"),k=b.filter(z=>z.status!=="done"),v=C.useRef(new Set);C.useEffect(()=>{for(const z of b)(z.status==="done"||z.status==="error")&&!v.current.has(z.id)&&(v.current.add(z.id),m.invalidateQueries({queryKey:["skills"]}),m.invalidateQueries({queryKey:["skill-updates"]}))},[b,m]);const N=(z,$)=>{Sz(z,$).then(()=>m.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},j=(((F=Ye({queryKey:["skill-updates"],queryFn:wz}).data)==null?void 0:F.data)??[]).filter(z=>z.status!=="same").length,{data:S,isLoading:_}=Ye({queryKey:["skills"],queryFn:()=>rx()}),M=Ye({queryKey:["projects"],queryFn:ba}),T=C.useMemo(()=>((S==null?void 0:S.data)??[]).filter($=>!(t!=="all"&&$.category!==t||r&&!$.name.toLowerCase().includes(r.toLowerCase()))),[S,t,r]),L=C.useMemo(()=>{const z=(S==null?void 0:S.data)??[],$={all:z.length};for(const q of z)$[q.category]=($[q.category]??0)+1;return $},[S]);return u.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[u.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:"Skills 🎯"}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:_?e("common.loading"):e("skills.subtitleCount",{count:(S==null?void 0:S.data.length)??0})})]}),u.jsxs("div",{className:"flex gap-3 items-center",children:[j>0&&u.jsx("span",{className:"nb-badge text-[10px]",title:e("skills.updates.badge",{count:String(j)}),children:e("skills.updates.badge",{count:String(j)})}),u.jsxs("button",{className:"nb-btn",onClick:()=>g(!0),type:"button",children:[u.jsx(Ll,{size:14,strokeWidth:2.5}),e("skills.ai")]}),u.jsxs("button",{className:"nb-btn",onClick:()=>f(!0),type:"button",children:[u.jsx(WN,{size:14,strokeWidth:2.5}),e("skills.import")]}),u.jsxs("button",{className:"nb-btn nb-btn-mint",onClick:async()=>{await bz(),m.invalidateQueries({queryKey:["skills"]}),m.invalidateQueries({queryKey:["skill-updates"]})},type:"button",children:[u.jsx(ga,{size:14,strokeWidth:2.5}),"Sync bundled"]})]})]}),u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsxs("div",{className:"relative flex-1 max-w-md",children:[u.jsx(co,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),u.jsx("input",{className:"nb-input pl-9 w-full",placeholder:e("skills.search.placeholder"),value:r,onChange:z=>a(z.target.value),"aria-label":e("skills.search.aria")})]}),u.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:c8.map(z=>u.jsxs("button",{type:"button",onClick:()=>n(z.value),className:["px-3 py-1 rounded-full text-xs font-bold font-[family-name:var(--font-body)]",t===z.value?"bg-[var(--color-text)] text-[var(--color-bg)]":"text-[var(--color-text-muted)] hover:text-[var(--color-text)]"].join(" "),children:[e(z.labelKey)," ",L[z.value]]},z.value))})]}),u.jsxs("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:[k.map(z=>u.jsxs("div",{className:`nb-card flex items-center gap-2 ${z.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,children:[z.status==="running"?u.jsx(Xe,{size:14,className:"animate-spin"}):u.jsx(Nn,{size:14,strokeWidth:3}),u.jsx("span",{className:"text-sm text-[var(--color-text-muted)] truncate",children:z.status==="running"?`${z.label} · ${e("skills.ai.wait")}`:`${z.label}: ${z.error??e("skills.ai.error")}`})]},z.id)),T.map(z=>{var $;return u.jsx(f8,{skill:z,projectCount:(($=M.data)==null?void 0:$.data.length)??0,onOpen:()=>l(z.name),onExport:()=>void l8(z.name)},z.name)})]}),o&&u.jsx(i8,{name:o,onClose:()=>l(null)}),d&&u.jsx(s8,{onClose:()=>f(!1)}),h&&u.jsx(o8,{onClose:()=>g(!1),onSubmit:(z,$)=>{N(z,$),g(!1)}})]})}function f8({skill:e,projectCount:t,onOpen:n,onExport:r}){const a=Be(),o=u8[e.category];return u.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:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:e.name}),u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("button",{type:"button",className:"nb-btn p-1",onClick:l=>{l.stopPropagation(),r()},"aria-label":a("skills.export"),title:a("skills.export"),children:u.jsx(Ph,{size:12,strokeWidth:2.5})}),u.jsx("span",{className:"nb-badge text-[10px]",style:{background:o},children:e.category})]})]}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] leading-5 line-clamp-3",children:e.description||"(no description)"}),u.jsxs("div",{className:"flex items-center justify-between text-xs font-[family-name:var(--font-mono)] pt-2 border-t-[1.5px] border-dashed border-[var(--color-border-light)]",children:[u.jsx("span",{className:"font-bold",children:e.linkedProjects.length>0?`● linked in ${e.linkedProjects.length}`:"○ not linked"}),u.jsxs("span",{className:"text-[var(--color-text-subtle)]",children:[t," projects"]})]})]})}function Bj(e){const t=e?`?q=${encodeURIComponent(e)}`:"";return ht(`/api/prompts${t}`)}function Dx(e){return ht(`/api/prompts/${encodeURIComponent(e)}`)}function h8(e){return Ri("/api/prompts",e)}function p8(e,t){return Bb(`/api/prompts/${encodeURIComponent(e)}`,t)}function m8(e){return N3(`/api/prompts/${encodeURIComponent(e)}`)}function g8(e){return Ri("/api/prompts/generate",{intent:e})}function $j(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 y8(){var T,L;const e=Be(),[t,n]=$b("prompts.last",""),[r,a]=C.useState(null),[o,l]=C.useState(!1),[d,f]=C.useState(""),[h,g]=C.useState(new Set),m=Gt(),y=Ye({queryKey:["prompts"],queryFn:()=>Bj()}),b=((T=y.data)==null?void 0:T.data)??[],k=C.useMemo(()=>[...new Set(b.flatMap(R=>R.tags))].sort(),[b]),N=(((L=Ye({queryKey:["gen-jobs"],queryFn:h2,refetchInterval:3e3}).data)==null?void 0:L.data)??[]).filter(R=>R.kind==="prompt"),E=N.filter(R=>R.status!=="done"),j=C.useRef(new Set);C.useEffect(()=>{for(const R of N)(R.status==="done"||R.status==="error")&&!j.current.has(R.id)&&(j.current.add(R.id),m.invalidateQueries({queryKey:["prompts"]}),R.status==="done"&&R.result&&n(R.result))},[N,m,n]);const S=R=>{g8(R).then(()=>m.invalidateQueries({queryKey:["gen-jobs"]})).catch(()=>{})},_=C.useMemo(()=>{const R=d.trim().toLowerCase();return b.filter(F=>!(h.size&&![...h].every(z=>F.tags.includes(z))||R&&!(F.name.toLowerCase().includes(R)||F.description.toLowerCase().includes(R)||F.tags.some($=>$.toLowerCase().includes(R)))))},[b,h,d]);C.useEffect(()=>{t&&b.length&&!b.some(R=>R.name===t)&&n("")},[t,b,n]);const M=R=>g(F=>{const z=new Set(F);return z.has(R)?z.delete(R):z.add(R),z});return u.jsxs("div",{className:"flex flex-col flex-1 min-h-0 w-full gap-3",children:[u.jsxs("div",{className:"shrink-0 flex items-center justify-between gap-3",children:[u.jsxs("div",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-3xl font-bold",children:e("prompts.title")}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.desc")})]}),u.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[u.jsxs("button",{className:"nb-btn",type:"button",onClick:()=>l(!0),children:[u.jsx(Ll,{size:14,strokeWidth:2.5}),e("prompts.ai")]}),u.jsxs("button",{className:"nb-btn nb-btn-mint",type:"button",onClick:()=>a({mode:"new"}),children:[u.jsx(pr,{size:14,strokeWidth:3}),e("prompts.new")]})]})]}),u.jsxs("div",{className:"shrink-0 flex flex-col gap-2",children:[u.jsxs("label",{className:"nb-input flex items-center gap-2 w-full",style:{padding:"6px 10px"},children:[u.jsx(co,{size:14}),u.jsx("input",{type:"text",value:d,onChange:R=>f(R.target.value),placeholder:e("prompts.search"),className:"bg-transparent outline-none flex-1 text-sm","aria-label":e("prompts.search")})]}),k.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(R=>u.jsx("button",{type:"button",onClick:()=>M(R),className:`text-xs border-2 border-[var(--color-text)] rounded-full px-2 py-0.5 ${h.has(R)?"bg-[var(--color-accent-mint)] font-bold":"bg-[var(--color-bg)]"}`,children:R},R))})]}),u.jsxs("div",{className:"flex gap-5 flex-1 min-h-0",children:[u.jsxs("aside",{className:"w-80 shrink-0 min-h-0 overflow-y-auto flex flex-col gap-2 pr-1",children:[E.map(R=>u.jsxs("div",{className:`nb-card flex items-center gap-2 ${R.status==="error"?"bg-[var(--color-crashed-bg)]":"opacity-70"}`,style:{padding:"8px 10px"},children:[R.status==="running"?u.jsx(Xe,{size:12,className:"animate-spin"}):u.jsx(Nn,{size:12,strokeWidth:3}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)] truncate",children:R.status==="running"?e("prompts.ai.wait"):`${e("prompts.ai.error")}: ${R.error??""}`})]},R.id)),y.isLoading?u.jsx("div",{className:"nb-card",children:u.jsx(Xe,{size:14,className:"animate-spin"})}):_.length===0?u.jsx("div",{className:"nb-card",children:u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:e("prompts.empty")})}):_.map(R=>u.jsxs("button",{type:"button",onClick:()=>n(R.name),className:`nb-card w-full text-left ${t===R.name?"bg-[var(--color-accent-mint)]":""}`,style:{padding:"8px 10px"},children:[u.jsxs("span",{className:"flex items-center gap-1.5",children:[R.favorite&&u.jsx(YN,{size:12,fill:"currentColor"}),u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold truncate",children:R.name})]}),R.description&&u.jsx("span",{className:"block text-xs text-[var(--color-text-muted)] truncate",children:R.description})]},R.name))]}),u.jsx("div",{className:"flex-1 min-w-0 min-h-0",children:t?u.jsx(x8,{name:t,onEdit:()=>a({mode:"edit",name:t}),onDeleted:()=>n("")},t):u.jsx("div",{className:"nb-card",children:u.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("prompts.selectHint")})})})]}),r&&u.jsx(w8,{name:r.mode==="edit"?r.name:null,onClose:()=>a(null),onSaved:R=>{a(null),n(R)}}),o&&u.jsx(b8,{onClose:()=>l(!1),onSubmit:R=>{S(R),l(!1)}})]})}function b8({onClose:e,onSubmit:t}){const n=Be(),[r,a]=C.useState("");return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold flex items-center gap-2",children:[u.jsx(Ll,{size:16,strokeWidth:2.5}),n("prompts.ai.title")]}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:e,"aria-label":"close",children:u.jsx(Nn,{size:14,strokeWidth:3})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:n("prompts.ai.intent")}),u.jsx("textarea",{value: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")})]}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint self-start",disabled:!r.trim(),onClick:()=>t(r),children:[u.jsx(Ll,{size:14,strokeWidth:2.5}),n("prompts.ai.submit")]})]})})})}function x8({name:e,onEdit:t,onDeleted:n}){const r=Be(),a=Gt(),{confirm:o}=un(),l=Ye({queryKey:["prompt",e],queryFn:()=>Dx(e)}),d=Ct({mutationFn:()=>m8(e),onSuccess:()=>{a.invalidateQueries({queryKey:["prompts"]}),n()}});if(l.isLoading)return u.jsx("div",{className:"nb-card",children:u.jsx(Xe,{size:14,className:"animate-spin"})});const f=l.data;if(!f)return null;const h=$j(f.body);return u.jsxs("div",{className:"nb-card flex flex-col gap-3 h-full min-h-0",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 shrink-0",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold flex items-center gap-2",children:[f.favorite&&u.jsx(YN,{size:16,fill:"currentColor"}),u.jsx("code",{className:"font-[family-name:var(--font-mono)] truncate",children:f.name})]}),f.description&&u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:f.description})]}),u.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",onClick:t,children:[u.jsx(Bh,{size:14,strokeWidth:3}),r("common.edit")]}),u.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:u.jsx(fi,{size:14,strokeWidth:3})})]})]}),f.tags.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 shrink-0",children:f.tags.map(g=>u.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))}),u.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}),u.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 v8({tags:e,onChange:t}){const n=Be(),[r,a]=C.useState(""),o=()=>{const l=r.trim();l&&!e.includes(l)&&t([...e,l]),a("")};return u.jsxs("div",{className:"nb-input w-full flex flex-wrap gap-1.5 items-center",children:[e.map(l=>u.jsxs("span",{className:"inline-flex items-center gap-1 text-xs bg-[var(--color-accent-mint)] border-2 border-[var(--color-text)] rounded px-1.5 py-0.5",children:[l,u.jsx("button",{type:"button",onClick:()=>t(e.filter(d=>d!==l)),"aria-label":`remove ${l}`,children:u.jsx(Nn,{size:10,strokeWidth:3})})]},l)),u.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 w8({name:e,onClose:t,onSaved:n}){const r=Be(),a=Gt(),{alert:o}=un(),l=e===null,d=Ye({queryKey:["prompt",e],queryFn:()=>Dx(e),enabled:!l}),[f,h]=C.useState(l?{name:"",description:"",tags:[],body:"",favorite:!1}:null);C.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?h8({name:f.name,...b}):p8(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=C.useMemo(()=>f?/^[a-z0-9][a-z0-9-]*$/.test(f.name):!1,[f]),y=C.useMemo(()=>f?$j(f.body):[],[f]);return u.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center bg-black/30 p-4 overflow-auto",children:u.jsx("div",{className:"w-full max-w-2xl my-8",children:u.jsxs("div",{className:"nb-card flex flex-col gap-3",children:[u.jsxs("div",{className:"flex items-center justify-between shrink-0",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold",children:l?r("prompts.new"):e}),u.jsx("button",{type:"button",className:"nb-btn p-2",onClick:t,"aria-label":"close",children:u.jsx(Nn,{size:14,strokeWidth:3})})]}),!l&&d.isLoading?u.jsx(Xe,{size:14,className:"animate-spin"}):f?u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:r("prompts.name")}),u.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&&u.jsx("span",{className:"text-xs text-[var(--color-crashed)]",children:r("prompts.nameError")})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:r("prompts.description")}),u.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")})]})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:r("prompts.tags")}),u.jsx(v8,{tags:f.tags,onChange:b=>h({...f,tags:b})})]}),u.jsxs("label",{className:"flex flex-col gap-1",children:[u.jsx("span",{className:"text-sm font-bold",children:r("prompts.body")}),u.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")}),u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:y.length?r("prompts.vars",{names:y.join(", ")}):r("prompts.noVars")})]}),u.jsxs("div",{className:"flex items-center gap-3",children:[u.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",disabled:g.isPending||l&&!m||!f.body.trim(),onClick:()=>g.mutate(),children:[g.isPending?u.jsx(Xe,{size:14,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:3}),r("prompts.save")]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:f.favorite,onChange:b=>h({...f,favorite:b.target.checked})}),r("prompts.favorite")]})]})]}):null]})})})}function k8(){var o;const e=Be(),t=Ye({queryKey:["system-info"],queryFn:r_}),n=Ye({queryKey:["system-env"],queryFn:_3}),[r,a]=C.useState(!1);return u.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[u.jsx("header",{children:u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:e("system.h1")})}),u.jsx(E8,{current:(o=t.data)==null?void 0:o.version}),u.jsxs("section",{className:"nb-card",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-3",children:e("system.runtime")}),t.data?u.jsxs("dl",{className:"grid grid-cols-1 sm:grid-cols-[160px_1fr] gap-y-2 text-sm",children:[u.jsx("dt",{className:"font-bold",children:"Node"}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.data.nodeVersion}),u.jsx("dt",{className:"font-bold",children:"Platform"}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.data.platform}),u.jsx("dt",{className:"font-bold",children:"PID"}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.data.pid??"—"}),u.jsx("dt",{className:"font-bold",children:"Uptime"}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:j8(t.data.uptimeMs)})]}):u.jsx("p",{className:"text-[var(--color-text-muted)]",children:e("common.loading")})]}),u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center justify-between mb-3",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:[e("system.env.title.prefix"),u.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?u.jsx("span",{className:"text-xs text-[var(--color-stuck)] font-bold",children:e("system.env.editing.label")}):u.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>a(!0),type:"button","aria-label":e("system.env.edit.aria"),children:[u.jsx(Bh,{size:12,strokeWidth:2.5})," ",e("system.env.edit.button")]})]}),r?u.jsx(S8,{onClose:()=>{a(!1),n.refetch()}}):n.data&&n.data.exists?u.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=>u.jsxs("div",{className:"contents",children:[u.jsxs("dt",{className:"font-bold flex items-center gap-2",children:[l.masked&&u.jsx("span",{className:"text-[var(--color-stuck)]",children:"🔒"}),l.key]}),u.jsx("dd",{className:"text-[var(--color-text-muted)] truncate",children:l.value})]},l.key))}):u.jsxs("p",{className:"text-[var(--color-text-muted)] text-sm",children:[e("system.env.empty.before"),u.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")]})]}),u.jsx(N8,{})]})}function E8({current:e}){var v;const t=Be(),{confirm:n,alert:r}=un(),[a,o]=C.useState(!1),[l,d]=C.useState(null),f=Ye({queryKey:["latest-version"],queryFn:D3,enabled:!1}),[h,g]=C.useState(null),[m,y]=C.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 j=await O3();if(d(j.output),g(j.installedVersion),y(j.command),j.ok)r({title:t("system.upgrade.success.title"),body:t("system.upgrade.success.body",{version:j.installedVersion??"?"})});else{const S=j.installedVersion&&j.installedVersion===e?t("system.upgrade.notEffective.same",{version:j.installedVersion}):t("system.upgrade.notEffective.notInstalled");r({title:t("system.upgrade.notEffective.title"),body:S})}}catch(j){d(j.message),r({title:t("system.upgrade.error.title"),body:j.message})}finally{o(!1)}}},k=async()=>{const N=f.data&&!f.data.upToDate?`npm i -g @coralai/sps-cli@${f.data.latest}`:m;try{await navigator.clipboard.writeText(N),r({title:t("system.upgrade.copy.success.title"),body:t("system.upgrade.copy.success.body",{cmd:N})})}catch{r({title:t("system.upgrade.copy.fail.title"),body:t("system.upgrade.copy.fail.body",{cmd:N})})}};return u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center justify-between mb-3",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:t("system.upgrade.title")}),u.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?u.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(ga,{size:12,strokeWidth:2.5}),t("system.upgrade.checkUpdate")]})]}),u.jsxs("dl",{className:"grid grid-cols-1 sm:grid-cols-[160px_1fr] gap-y-2 text-sm",children:[u.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.current")}),u.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:e??"—"}),f.data&&u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.latest")}),u.jsxs("dd",{className:"font-[family-name:var(--font-mono)] flex items-center gap-2 flex-wrap",children:[f.data.latest,f.data.upToDate?u.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:t("system.upgrade.latestPill")}):u.jsxs(u.Fragment,{children:[u.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?u.jsx(Xe,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(Ph,{size:11,strokeWidth:2.5}),t("system.upgrade.button.upgrade")]}),u.jsxs("button",{className:"nb-btn",style:{padding:"3px 10px",fontSize:11},onClick:k,type:"button","aria-label":t("system.upgrade.button.copyAria"),title:t("system.upgrade.button.copyTitle"),children:[u.jsx($R,{size:11,strokeWidth:2.5})," ",t("system.upgrade.button.copy")]})]})]})]}),h&&u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.installed")}),u.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)?u.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:t("system.upgrade.installed.ok")}):h===e?u.jsx("span",{className:"nb-status",style:{background:"var(--color-stuck-bg)",color:"var(--color-stuck)"},children:t("system.upgrade.installed.fail")}):null]})]}),f.isError&&u.jsxs(u.Fragment,{children:[u.jsx("dt",{className:"font-bold",children:t("system.upgrade.label.check")}),u.jsx("dd",{className:"text-[var(--color-crashed)] text-xs",children:f.error instanceof Error?f.error.message:String(f.error)})]})]}),l&&u.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 S8({onClose:e}){const t=Be(),n=Gt(),{alert:r}=un(),a=Ye({queryKey:["system-env-raw"],queryFn:j3}),[o,l]=C.useState(null),[d,f]=C.useState(null);C.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 C3(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?u.jsx("p",{className:"text-[var(--color-text-muted)]",children:t("common.loading")}):u.jsxs("div",{children:[u.jsx("p",{className:"text-xs text-[var(--color-stuck)] font-bold mb-2",children:t("system.env.warning")}),u.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")}),u.jsxs("div",{className:"flex items-center justify-between mt-3",children:[u.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"):""]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px"},onClick:e,disabled:g.isPending,type:"button",children:[u.jsx(Nn,{size:12,strokeWidth:3})," ",t("system.env.cancel")]}),u.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?u.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(Oi,{size:12,strokeWidth:3}),t("system.env.save")]})]})]})]})}function N8(){var y;const e=Be(),{alert:t}=un(),n=Ye({queryKey:["projects"],queryFn:ba}),[r,a]=C.useState({}),[o,l]=C.useState({}),[d,f]=C.useState({}),h=(((y=n.data)==null?void 0:y.data)??[]).map(b=>({project:b.name})),g=async(b,k)=>{l(v=>({...v,[b]:k?"fix":"check"}));try{const v=await R3(b,k);a(N=>({...N,[b]:v})),f(N=>({...N,[b]:!0}))}catch(v){t({title:e(k?"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 u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-center justify-between mb-3",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:e("system.diagnostics.title")}),u.jsxs("button",{className:"nb-btn nb-btn-mint",style:{padding:"6px 12px",fontSize:12},onClick:()=>{m()},disabled:h.length===0||Object.values(o).some(Boolean),type:"button",children:[u.jsx(ga,{size:12,strokeWidth:2.5}),e("system.diagnostics.checkAll")]})]}),h.length===0?u.jsx("p",{className:"text-[var(--color-text-muted)] text-sm",children:e("system.diagnostics.empty")}):u.jsx("ul",{className:"flex flex-col gap-2",children:h.map(b=>{const k=r[b.project],v=o[b.project],N=k?k.checks.filter(_=>_.status==="fail").length:0,E=k?k.checks.filter(_=>_.status==="warn").length:0,j=d[b.project]??!1,S=k!=null;return u.jsxs("li",{className:"bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg",children:[u.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[u.jsxs("button",{type:"button",onClick:()=>f(_=>({..._,[b.project]:!j})),disabled:!S,className:"flex items-center gap-2 flex-1 text-left min-w-0","aria-label":e(j?"system.diagnostics.collapseAria":"system.diagnostics.expandAria"),children:[S&&k.ok?u.jsx(uh,{size:16,className:"text-[var(--color-running)] shrink-0",strokeWidth:2.5}):S?u.jsx(vu,{size:16,className:"text-[var(--color-stuck)] shrink-0",strokeWidth:2.5}):u.jsx(uh,{size:16,className:"text-[var(--color-text-subtle)] shrink-0",strokeWidth:2.5}),S&&(j?u.jsx(Ql,{size:12}):u.jsx(Wl,{size:12})),u.jsx("span",{className:"font-bold font-[family-name:var(--font-mono)]",children:b.project}),S?k.ok?u.jsx("span",{className:"text-xs text-[var(--color-running)] font-semibold",children:"OK"}):u.jsxs("span",{className:"text-xs text-[var(--color-stuck)] font-semibold",children:[N," fail · ",E," warn"]}):u.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:e("system.diagnostics.never")})]}),u.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"?u.jsx(Xe,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(ga,{size:11,strokeWidth:2.5}),e("system.diagnostics.check")]}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>{g(b.project,!0)},disabled:!!v||S&&k.ok,type:"button","aria-label":e("system.diagnostics.fixAria"),title:S&&k.ok?e("system.diagnostics.noFixesNeeded"):e("system.diagnostics.fix.tip"),children:[v==="fix"?u.jsx(Xe,{size:11,strokeWidth:3,className:"animate-spin"}):u.jsx(ZN,{size:11,strokeWidth:2.5}),e("system.diagnostics.fix")]})]}),j&&S&&u.jsxs("div",{className:"border-t-2 border-dashed border-[var(--color-text)] px-3 py-2",children:[u.jsx("ul",{className:"flex flex-col gap-1 text-xs font-[family-name:var(--font-mono)]",children:k.checks.map((_,M)=>u.jsx(_8,{check:_},`${_.name}-${M}`))}),k.fixes.length>0&&u.jsxs("div",{className:"mt-3 bg-[var(--color-running-bg)] border-2 border-[var(--color-running)] rounded p-2",children:[u.jsx("div",{className:"text-xs font-bold text-[var(--color-running)] mb-1",children:e("system.diagnostics.fixed")}),u.jsx("ul",{className:"text-xs list-disc pl-4",children:k.fixes.map((_,M)=>u.jsx("li",{children:_},M))})]})]})]},b.project)})})]})}function _8({check:e}){const t=e.status==="pass"?u.jsx(uh,{size:12,className:"text-[var(--color-running)]",strokeWidth:2.5}):e.status==="fail"?u.jsx(vu,{size:12,className:"text-[var(--color-crashed)]",strokeWidth:2.5}):e.status==="warn"?u.jsx(vu,{size:12,className:"text-[var(--color-stuck)]",strokeWidth:2.5}):u.jsx("span",{className:"w-3 h-3 rounded-full bg-[var(--color-text-subtle)] inline-block"});return u.jsxs("li",{className:"flex items-start gap-2",children:[u.jsx("span",{className:"pt-0.5 shrink-0",children:t}),u.jsx("span",{className:"font-bold w-32 shrink-0",children:e.name}),u.jsx("span",{className:"text-[var(--color-text-muted)] break-words",children:e.message})]})}function j8(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 C8(){return ht("/api/chat/sessions")}function A8(e){return ht(`/api/chat/sessions/${e}`)}async function ry(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 T8(e){const t=await fetch(`/api/chat/sessions/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(`${t.status}`)}async function M8(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 D8(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 O8(e,t){const n=t?`?since=${encodeURIComponent(t)}`:"";return ht(`/api/chat/sessions/${e}/messages${n}`)}function R8({onInsert:e,disabled:t,className:n="nb-btn"}){var m;const r=Be(),[a,o]=C.useState(!1),[l,d]=C.useState(""),h=((m=Ye({queryKey:["prompts",l],queryFn:()=>Bj(l||void 0),enabled:a}).data)==null?void 0:m.data)??[],g=async y=>{try{const b=await Dx(y);e(b.body)}finally{o(!1),d("")}};return u.jsxs("div",{className:"relative flex-shrink-0",children:[u.jsx("button",{type:"button",className:n,onClick:()=>o(y=>!y),disabled:t,"aria-label":r("prompts.insert"),title:r("prompts.insert"),children:u.jsx(qN,{size:15,strokeWidth:2.5})}),a&&u.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:[u.jsxs("label",{className:"flex items-center gap-2 border-2 border-[var(--color-text)] rounded px-2 py-1",children:[u.jsx(co,{size:12}),u.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?u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-1 py-2",children:r("prompts.empty")}):h.map(y=>u.jsxs("button",{type:"button",onClick:()=>void g(y.name),className:"text-left px-2 py-1 rounded hover:bg-[var(--color-bg-cream)]",children:[u.jsx("code",{className:"font-[family-name:var(--font-mono)] text-sm font-bold",children:y.name}),y.description&&u.jsx("span",{className:"block text-xs text-[var(--color-text-muted)] truncate",children:y.description})]},y.name))]})]})}function NE(){var de,Ce,Re,De,le,Ne,Te,ke,We;const e=Be(),{sessionId:t}=Cb(),n=vs(),r=Gt(),{confirm:a,alert:o}=un(),l=Ye({queryKey:["chat-sessions"],queryFn:C8,refetchInterval:5e3}),d=Ye({queryKey:["chat-session",t],queryFn:()=>A8(t??""),enabled:!!t,refetchInterval:4e3}),[f,h]=C.useState(null),g=re=>`chat-draft:${re??""}`,[m,y]=C.useState(()=>localStorage.getItem(g(t))??""),b=C.useCallback(re=>{y(Ae=>{const ue=typeof re=="function"?re(Ae):re;try{t&&localStorage.setItem(g(t),ue)}catch{}return ue})},[t]);C.useEffect(()=>{y(localStorage.getItem(g(t))??"")},[t]);const[k,v]=C.useState(!1),N=C.useRef(null),E=C.useRef(!0),[j,S]=C.useState(!1),_=()=>{const re=N.current;return!re||re.scrollHeight-re.scrollTop-re.clientHeight<40},M=C.useCallback(()=>{const re=N.current;re&&(re.scrollTop=re.scrollHeight),E.current=!0,S(!1)},[]),T=C.useCallback(()=>{const re=_();E.current=re,S(!re)},[]),L=C.useRef(null);C.useEffect(()=>{const re=L.current;re&&(re.style.height="auto",re.style.height=`${Math.min(re.scrollHeight,200)}px`,re.scrollTop=re.scrollHeight)},[m]);const R="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",[F,z]=C.useState(!1),[$,q]=C.useState([]),[Y,D]=C.useState(!1),[H,O]=C.useState(!1),[V,Q]=C.useState(!1),[K,I]=C.useState(null),[P,G]=C.useState(!1);C.useEffect(()=>{if(h(null),!t)return;const re=new EventSource(`/stream/chat/${encodeURIComponent(t)}`);let Ae=!0;return re.addEventListener("open",()=>{if(Ae){Ae=!1;return}const ue=r.getQueryData(["chat-session",t]),he=ue!=null&&ue.messages.length?ue.messages[ue.messages.length-1].ts:void 0;O8(t,he).then(ge=>{ge.data.length!==0&&r.setQueryData(["chat-session",t],Le=>{if(!Le)return Le;const ze=new Set(Le.messages.map(te=>te.id)),Fe=ge.data.filter(te=>!ze.has(te.id));return Fe.length===0?Le:{...Le,messages:[...Le.messages,...Fe],lastMessageAt:Fe[Fe.length-1].ts,messageCount:Le.messageCount+Fe.length}})}).catch(()=>{})}),re.addEventListener("chat.message",ue=>{try{const he=JSON.parse(ue.data);r.setQueryData(["chat-session",t],ge=>{if(!ge||ge.messages.some(Fe=>Fe.id===he.message.id))return ge;const ze=ge.messages.findIndex(Fe=>Fe.role==="user"&&Fe.id.startsWith("optim-")&&Fe.content===he.message.content);if(ze>=0){const Fe=[...ge.messages];return Fe[ze]=he.message,{...ge,messages:Fe}}return{...ge,messages:[...ge.messages,he.message]}})}catch{}}),re.addEventListener("chat.message.pending",ue=>{try{const he=JSON.parse(ue.data);h({id:he.assistantId,blocks:[],done:!1,finalMessage:null})}catch{}}),re.addEventListener("chat.message.chunk.text",ue=>{try{const he=JSON.parse(ue.data);h(ge=>{if(!ge||ge.id!==he.assistantId)return ge;const Le=[...ge.blocks],ze=Le[Le.length-1];return ze&&ze.type==="text"?Le[Le.length-1]={...ze,target:ze.target+he.text}:Le.push({type:"text",target:he.text,displayed:""}),{...ge,blocks:Le}})}catch{}}),re.addEventListener("chat.message.chunk.tool_use",ue=>{try{const he=JSON.parse(ue.data);h(ge=>!ge||ge.id!==he.assistantId?ge:{...ge,blocks:[...ge.blocks,{type:"tool_use",id:he.id,title:he.title,kind:he.kind,status:he.status,input:he.input,locations:he.locations}]})}catch{}}),re.addEventListener("chat.message.chunk.tool_update",ue=>{try{const he=JSON.parse(ue.data);h(ge=>!ge||ge.id!==he.assistantId?ge:{...ge,blocks:ge.blocks.map(Le=>Le.type==="tool_use"&&Le.id===he.id?{...Le,status:he.status,input:Le.input??he.input,locations:Le.locations??he.locations}:Le)})}catch{}}),re.addEventListener("chat.message.complete",ue=>{try{const he=JSON.parse(ue.data);h(ge=>ge&&ge.id===he.assistantId?{...ge,done:!0,finalMessage:he.message}:ge)}catch{}}),()=>re.close()},[t,r]),C.useEffect(()=>{if(!f)return;const re=f.blocks.reduce((ue,he)=>he.type==="text"?ue+(he.target.length-he.displayed.length):ue,0);if(re<=0){if(f.done&&f.finalMessage){const ue=f.finalMessage;r.setQueryData(["chat-session",t],he=>!he||he.messages.some(ge=>ge.id===ue.id)?he:{...he,messages:[...he.messages,ue],lastMessageAt:ue.ts,messageCount:he.messageCount+1}),r.invalidateQueries({queryKey:["chat-sessions"]}),r.invalidateQueries({queryKey:["chat-session",t]}),h(null),v(!1)}return}const Ae=setTimeout(()=>{h(ue=>{if(!ue)return ue;let he=Math.max(1,Math.ceil(re/40));const ge=ue.blocks.map(Le=>{if(Le.type!=="text"||he<=0)return Le;const ze=Le.target.length-Le.displayed.length;if(ze<=0)return Le;const Fe=Math.min(ze,he);return he-=Fe,{...Le,displayed:Le.target.slice(0,Le.displayed.length+Fe)}});return{...ue,blocks:ge}})},25);return()=>clearTimeout(Ae)},[f,r,t]),C.useEffect(()=>{if(E.current){const re=N.current;re&&(re.scrollTop=re.scrollHeight)}},[d.data,f]),C.useEffect(()=>{E.current=!0,S(!1)},[t]);const B=C.useCallback(async(re={})=>{var Ae,ue;try{const he=await ry({cwd:((Ae=re.cwd)==null?void 0:Ae.trim())||void 0,title:((ue=re.title)==null?void 0:ue.trim())||void 0,agentKind:re.agentKind,model:re.model,providerId:re.providerId});r.invalidateQueries({queryKey:["chat-sessions"]}),n(`/chat/${he.id}`),z(!1)}catch(he){o({title:e("chat.error.create.title"),body:he instanceof Error?he.message:String(he)})}},[r,n,o,e]),oe=C.useCallback(async()=>{const re=m.trim();if(!re&&$.length===0||k)return;let Ae=t;if(!Ae){const ge=await ry();r.invalidateQueries({queryKey:["chat-sessions"]}),Ae=ge.id,n(`/chat/${Ae}`,{replace:!0})}E.current=!0,S(!1);const ue=$.map(ge=>ge.path),he={id:`optim-${Date.now()}`,role:"user",content:re||e("chat.placeholder.attachment"),ts:new Date().toISOString(),status:"complete",attachments:ue.length>0?ue:void 0};r.setQueryData(["chat-session",Ae],ge=>ge?{...ge,messages:[...ge.messages,he],lastMessageAt:he.ts,messageCount:ge.messageCount+1}:{id:Ae,createdAt:he.ts,lastMessageAt:he.ts,title:re.slice(0,60)||e("chat.placeholder.attachmentTitle"),project:null,messageCount:1,messages:[he]}),b(""),q([]),v(!0);try{await M8(Ae,re||e("chat.placeholder.viewAttachment"),ue.length>0?ue:void 0)}catch(ge){v(!1),console.error("sendMessage failed",ge),o({title:e("chat.error.send.title"),body:ge instanceof Error?ge.message:String(ge)})}},[m,$,k,t,r,n,o,e]),be=C.useCallback(async re=>{if(re.size>s2){o({title:e("chat.error.fileTooBig.title"),body:e("chat.error.fileTooBig.body",{size:(re.size/1024/1024).toFixed(2),name:re.name})});return}let Ae=t;if(!Ae){const ue=await ry();r.invalidateQueries({queryKey:["chat-sessions"]}),Ae=ue.id,n(`/chat/${Ae}`,{replace:!0})}D(!0);try{const ue=await Gz(Ae,re);q(he=>[...he,{path:ue.path,name:ue.name}])}catch(ue){o({title:e("chat.error.uploadAttachment.title"),body:ue instanceof Error?ue.message:String(ue)})}finally{D(!1)}},[t,r,n,o,e]),xe=C.useCallback(re=>{q(Ae=>Ae.filter(ue=>ue.path!==re))},[]),we=C.useCallback(async(re,Ae)=>{await a({title:e("chat.delete.confirm.title"),body:e(Ae==="cli"?"chat.delete.confirm.body.cli":"chat.delete.confirm.body.console"),confirm:e("chat.delete.confirm.button"),danger:!0})&&(await T8(re),r.invalidateQueries({queryKey:["chat-sessions"]}),t===re&&n("/chat"))},[r,t,n,a,e]),J=C.useCallback(async()=>{if(t)try{await D8(t)}catch(re){o({title:e("chat.error.interrupt.title"),body:re instanceof Error?re.message:String(re)})}},[t,o,e]);return u.jsxs("div",{className:"grid grid-cols-[260px_1fr] gap-4 h-[calc(100vh-140px)]",children:[u.jsxs("aside",{className:"nb-card p-3 overflow-auto flex flex-col gap-2",children:[u.jsxs("button",{className:"nb-btn nb-btn-primary w-full justify-center",onClick:()=>z(!0),type:"button",children:[u.jsx(pr,{size:14,strokeWidth:3}),e("chat.list.new")]}),u.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:((de=l.data)==null?void 0:de.data.length)??0})}),u.jsx("div",{className:"flex flex-col gap-1.5 mt-1",children:(()=>{var Fe;const re=((Fe=l.data)==null?void 0:Fe.data)??[],Ae=Date.now(),ue=10080*60*1e3,he=te=>new Date(te.lastMessageAt??te.createdAt).getTime(),ge=re.filter(te=>Ae-he(te)<=ue),Le=re.filter(te=>Ae-he(te)>ue),ze=te=>u.jsxs("div",{className:["group flex items-start gap-2 p-2 rounded-lg border-2 border-transparent",t===te.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:[u.jsxs("button",{type:"button","aria-label":e("chat.list.openAria",{title:te.title,cwd:te.cwd?e("chat.list.cwdSuffix",{cwd:te.cwd}):""}),onClick:()=>n(`/chat/${te.id}`),className:"flex items-start gap-2 flex-1 min-w-0 text-left",children:[u.jsx(sk,{size:14,strokeWidth:2.5,className:"mt-0.5 flex-shrink-0"}),u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[u.jsx("p",{className:"text-sm font-semibold truncate flex-1",children:te.title}),te.source==="cli"&&u.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")})]}),u.jsx("p",{className:"text-[10px] text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] truncate",children:e("chat.list.msgs",{count:te.messageCount,time:qj(te.lastMessageAt??te.createdAt,e)})}),te.cwd&&u.jsxs("p",{className:"text-[10px] text-[var(--color-text-subtle)] font-[family-name:var(--font-mono)] truncate flex items-center gap-1",title:te.cwd,children:[u.jsx(ku,{size:9,strokeWidth:2.5,className:"flex-shrink-0"}),u.jsx("span",{className:"truncate",dir:"rtl",children:te.cwd})]})]})]}),u.jsx("button",{type:"button","aria-label":te.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:ve=>{ve.stopPropagation(),we(te.id,te.source)},children:u.jsx(fi,{size:12})})]},te.id);return u.jsxs(u.Fragment,{children:[ge.map(ze),Le.length>0&&u.jsxs(u.Fragment,{children:[u.jsxs("button",{type:"button",onClick:()=>G(te=>!te),"aria-expanded":P,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:[P?u.jsx(Ql,{size:12,strokeWidth:2.5}):u.jsx(Wl,{size:12,strokeWidth:2.5}),e("chat.list.olderToggle",{count:Le.length})]}),P&&Le.map(ze)]}),re.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-subtle)] italic text-center py-4",children:e("chat.list.empty")})]})})()})]}),u.jsx("div",{className:"nb-card p-0 flex flex-col overflow-hidden",children:t?u.jsxs(u.Fragment,{children:[u.jsxs("header",{className:"px-4 py-3 border-b-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:((Ce=d.data)==null?void 0:Ce.title)??e("common.loading")}),((Re=d.data)==null?void 0:Re.model)&&u.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:[u.jsx(dh,{size:11,strokeWidth:2.5})," ",d.data.model]})]}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:t}),((De=d.data)==null?void 0:De.claudeSessionId)&&u.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]}),((le=d.data)==null?void 0:le.cwd)&&u.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:[u.jsx(ku,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}),u.jsx("span",{className:"truncate",children:d.data.cwd})]})]}),u.jsxs("div",{className:"relative flex-1 flex flex-col min-h-0",children:[u.jsxs("div",{ref:N,onScroll:T,className:"flex-1 overflow-auto p-4 flex flex-col gap-4",children:[(((Ne=d.data)==null?void 0:Ne.messages)??[]).filter(re=>!(f&&re.status==="streaming")).map(re=>u.jsx(z8,{msg:re,sessionId:t??null,onPreviewAttachment:Ae=>I(Ae)},re.id)),f&&u.jsx(B8,{pending:f}),!d.isLoading&&(((Te=d.data)==null?void 0:Te.messages)??[]).length===0&&!f&&!k&&u.jsx("p",{className:"text-center text-[var(--color-text-subtle)] italic mt-12",children:e("chat.session.empty")})]}),j&&u.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:u.jsx(wR,{size:18,strokeWidth:3})})]}),((ke=d.data)==null?void 0:ke.source)==="cli"?u.jsxs("div",{className:"border-t-2 border-[var(--color-text)] p-4 bg-[var(--color-accent-purple)]",children:[u.jsxs("p",{className:"text-sm font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] text-center",children:[u.jsx("strong",{children:e("chat.cli.banner.bold")})," — ",e("chat.cli.banner")]}),u.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-/,"")]})]}):u.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:re=>{re.dataTransfer.types.includes("Files")&&(re.preventDefault(),re.dataTransfer.dropEffect="copy",V||Q(!0))},onDragLeave:()=>Q(!1),onDrop:re=>{if(!re.dataTransfer.types.includes("Files"))return;re.preventDefault(),Q(!1);const Ae=Array.from(re.dataTransfer.files??[]);for(const ue of Ae)be(ue)},children:[($.length>0||Y)&&u.jsxs("div",{className:"flex flex-wrap gap-2 mb-2",children:[$.map(re=>u.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:()=>I(re.path),title:e("chat.attachment.previewTooltip",{name:re.name,path:re.path}),children:[kh(re.path)?u.jsx(gL,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}):u.jsx(Gu,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}),u.jsx("span",{className:"truncate max-w-[180px]",children:re.name}),u.jsx("span",{role:"button","aria-label":e("chat.input.removeAttachment",{name:re.name}),className:"ml-1 hover:text-[var(--color-crashed)] cursor-pointer",onClick:Ae=>{Ae.stopPropagation(),xe(re.path)},children:u.jsx(Nn,{size:11,strokeWidth:3})})]},re.path)),Y&&u.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:[u.jsx(Xe,{size:11,strokeWidth:2.5,className:"animate-spin"}),e("chat.input.uploading")]})]}),u.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:[u.jsx("textarea",{ref:L,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:re=>b(re.target.value),onKeyDown:re=>{re.key==="Enter"&&!re.shiftKey&&!re.nativeEvent.isComposing&&(re.preventDefault(),oe())},onPaste:re=>{const ue=Array.from(re.clipboardData.items??[]).filter(he=>he.kind==="file"&&he.type.startsWith("image/"));if(ue.length!==0){re.preventDefault();for(const he of ue){const ge=he.getAsFile();ge&&be(ge)}}},"aria-label":e("chat.input.aria")}),u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("button",{type:"button",className:R,onClick:()=>O(!0),disabled:k,"aria-label":e("chat.input.attach.aria"),title:e("chat.input.attach.title"),children:u.jsx(TL,{size:15,strokeWidth:2.5})}),u.jsx(R8,{className:R,disabled:k,onInsert:re=>b(Ae=>Ae.trim()?`${Ae}
646
646
  ${re}`:re)}),u.jsx("div",{className:"flex-1"}),f?u.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:u.jsx(Ib,{size:14,strokeWidth:3})}):u.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:oe,disabled:!m.trim()&&$.length===0||k,type:"button","aria-label":e("chat.input.send.aria"),title:e("chat.input.send"),children:k?u.jsx(Xe,{size:16,strokeWidth:3,className:"animate-spin"}):u.jsx(IN,{size:18,strokeWidth:3})})]})]})]})]}):u.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:u.jsxs("div",{className:"text-center max-w-md",children:[u.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:u.jsx(sk,{size:32,strokeWidth:2.5})}),u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold mb-2",children:e("chat.empty.title")}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:e("chat.empty.hint")}),u.jsx("p",{className:"text-xs text-[var(--color-text-subtle)] italic",children:e("chat.empty.shortcuts")})]})})}),F&&u.jsx(I8,{onCancel:()=>z(!1),onCreate:re=>B(re)}),H&&u.jsx(ax,{mode:"file",title:e("chat.filePicker.title"),initialPath:((We=d.data)==null?void 0:We.cwd)??void 0,onCancel:()=>O(!1),onSelect:re=>{q(Ae=>{if(Ae.some(he=>he.path===re))return Ae;const ue=re.split(/[\\/]/).pop()||re;return[...Ae,{path:re,name:ue}]}),O(!1)}}),K&&t&&u.jsx(L8,{sessionId:t,path:K,onClose:()=>I(null)})]})}function kh(e){return/\.(png|jpe?g|gif|webp|svg|avif)$/i.test(e)}function _E(e){return/\.pdf$/i.test(e)}function iy(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 L8({sessionId:e,path:t,onClose:n}){const r=Be(),[a,o]=C.useState(null),[l,d]=C.useState(null);C.useEffect(()=>{const g=m=>{m.key==="Escape"&&(m.preventDefault(),n())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[n]),C.useEffect(()=>{if(!iy(t))return;let g=!1;return fetch(Ky(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
648
  …(truncated)`:m)}).catch(m=>{g||d(m instanceof Error?m.message:String(m))}),()=>{g=!0}},[e,t]);const f=Ky(e,t),h=t.split(/[\\/]/).pop()??t;return u.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:u.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:[u.jsxs("header",{className:"flex items-center justify-between mb-3 shrink-0",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[u.jsx(GR,{size:16,strokeWidth:2.5,className:"flex-shrink-0"}),u.jsx("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-base truncate",children:h})]}),u.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:u.jsx(Nn,{size:16,strokeWidth:3})})]}),u.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}),u.jsxs("div",{className:"flex-1 overflow-auto border-2 border-[var(--color-text)] rounded-lg bg-[var(--color-bg-cream)] min-h-0",children:[kh(t)&&u.jsx("div",{className:"flex items-center justify-center p-4",children:u.jsx("img",{src:f,alt:`Preview: ${h}`,className:"max-w-full max-h-[60vh] object-contain"})}),_E(t)&&u.jsx("iframe",{src:f,title:`PDF: ${h}`,className:"w-full",style:{height:"60vh",border:0}}),iy(t)&&u.jsx("pre",{className:"p-3 text-xs font-[family-name:var(--font-mono)] whitespace-pre-wrap break-words",children:l?u.jsx("span",{className:"text-[var(--color-crashed)]",children:r("chat.attachment.readErr",{detail:l})}):a===null?u.jsx("span",{className:"text-[var(--color-text-muted)]",children:r("chat.attachment.loading")}):a}),!kh(t)&&!_E(t)&&!iy(t)&&u.jsxs("div",{className:"p-6 text-center text-sm text-[var(--color-text-muted)]",children:[u.jsx("p",{className:"mb-3",children:r("chat.attachment.unsupported")}),u.jsx("a",{href:f,download:h,className:"nb-btn nb-btn-primary inline-flex",children:r("chat.attachment.download")})]})]})]})})}function I8({onCancel:e,onCreate:t}){var j;const n=Be(),[r,a]=C.useState(""),[o,l]=C.useState(""),[d,f]=C.useState("claude"),[h,g]=C.useState(""),[m,y]=C.useState(!1),[b,k]=C.useState(!1),v=Ye({queryKey:["providers"],queryFn:ix}),N=i2(((j=v.data)==null?void 0:j.anthropic)??[]);C.useEffect(()=>{if(b)return;const S=_=>{_.key==="Escape"&&(_.preventDefault(),e())};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[e,b]);const E=async()=>{if(!m){y(!0);try{const[S,_]=d==="claude"&&h?h.split("::"):[void 0,void 0];t({title:r.trim()||void 0,cwd:o.trim()||void 0,agentKind:d,model:_,providerId:S})}finally{y(!1)}}};return u.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:[u.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:[u.jsxs("header",{className:"flex items-center justify-between mb-4",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:n("chat.newSession.title")}),u.jsx("button",{type:"button",className:"p-1 hover:bg-[var(--color-bg-cream)] rounded",onClick:e,"aria-label":n("chat.newSession.close.aria"),children:u.jsx(Nn,{size:16,strokeWidth:3})})]}),u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{children:[u.jsx("span",{className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.agent")}),u.jsx("div",{className:"grid grid-cols-2 gap-2",children:["claude","openai"].map(S=>{const _=d===S;return u.jsx("button",{type:"button",onClick:()=>f(S),"aria-pressed":_,className:["rounded-xl border-2 px-3 py-2 text-sm font-bold transition-all",_?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[3px_3px_0_var(--color-text)]":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),children:S==="claude"?"Claude":"OpenAI"},S)})})]}),d==="claude"&&u.jsxs("div",{children:[u.jsx("label",{htmlFor:"new-session-model",className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.model")}),u.jsxs("select",{id:"new-session-model",className:"nb-input w-full font-[family-name:var(--font-mono)] text-sm",value:h,onChange:S=>g(S.target.value),children:[u.jsx("option",{value:"",children:n("chat.newSession.field.model.default")}),N.map(S=>u.jsx("option",{value:`${S.providerId}::${S.model}`,children:S.label},`${S.providerId}::${S.model}`))]})]}),u.jsxs("div",{children:[u.jsx("label",{htmlFor:"new-session-title",className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.title")}),u.jsx("input",{id:"new-session-title",type:"text",className:"nb-input w-full",placeholder:n("chat.newSession.field.title.placeholder"),value:r,onChange:S=>a(S.target.value),autoFocus:!0})]}),u.jsxs("div",{children:[u.jsx("label",{htmlFor:"new-session-cwd",className:"block text-xs font-bold mb-1.5 uppercase tracking-wider",children:n("chat.newSession.field.cwd")}),u.jsxs("div",{className:"flex gap-2",children:[u.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:S=>l(S.target.value)}),u.jsxs("button",{type:"button",className:"nb-btn flex-shrink-0",onClick:()=>k(!0),"aria-label":n("chat.newSession.field.cwd.browseAria"),title:n("chat.newSession.field.cwd.browseAria"),children:[u.jsx(BN,{size:14,strokeWidth:2.5}),n("chat.newSession.field.cwd.browse")]})]}),u.jsxs("p",{className:"text-[11px] text-[var(--color-text-muted)] mt-1.5 leading-relaxed",children:[u.jsx(ku,{size:10,strokeWidth:2.5,className:"inline mr-1 -mt-0.5"}),n("chat.newSession.field.cwd.help1")," ",n("chat.newSession.field.cwd.help2")]})]}),u.jsxs("div",{className:"flex gap-2 justify-end pt-2",children:[u.jsx("button",{type:"button",className:"nb-btn",onClick:e,children:n("chat.newSession.cancel")}),u.jsxs("button",{type:"button",className:"nb-btn nb-btn-primary",onClick:E,disabled:m,children:[m?u.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(pr,{size:14,strokeWidth:3}),n("chat.newSession.create")]})]})]})]}),b&&u.jsx(ax,{initialPath:o.trim()||void 0,onCancel:()=>k(!1),onSelect:S=>{l(S),k(!1)}})]})}function z8({msg:e,sessionId:t,onPreviewAttachment:n}){const r=Be(),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 u.jsx("div",{className:a?"self-end max-w-3xl":"self-start max-w-3xl",children:u.jsxs("div",{className:["nb-card",a?"bg-[var(--color-secondary)]":o?"bg-[var(--color-crashed-bg)]":"bg-[var(--color-bg)]"].join(" "),children:[u.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"),u.jsx("span",{className:"font-normal",children:"·"}),u.jsx("span",{className:"font-normal cursor-help",title:F8(e.ts),children:qj(e.ts,r)})]}),u.jsx("div",{className:"flex flex-col gap-2",children:l.map((f,h)=>u.jsx($8,{block:f},h))}),d.length>0&&t&&u.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=>u.jsx(P8,{sessionId:t,path:f,onPreview:()=>n(f)},f))}),e.truncated&&u.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 P8({sessionId:e,path:t,onPreview:n}){const r=Be(),a=t.split(/[\\/]/).pop()??t;return kh(t)?u.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:u.jsx("img",{src:Ky(e,t),alt:a,className:"block max-h-40 max-w-[12rem] object-cover",loading:"lazy"})}):u.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:[u.jsx(Gu,{size:11,strokeWidth:2.5,className:"flex-shrink-0"}),u.jsx("span",{className:"truncate max-w-[200px]",children:a})]})}function B8({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 u.jsx("div",{className:"self-start max-w-3xl",children:u.jsxs("div",{className:"nb-card bg-[var(--color-bg)]",children:[u.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-2 flex items-center gap-2",children:["assistant",u.jsx("span",{className:"font-normal",children:"·"}),u.jsxs("span",{className:"flex items-center gap-1 font-normal text-[var(--color-running)]",children:[u.jsx(Xe,{size:10,strokeWidth:3,className:"animate-spin"}),"streaming"]})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[e.blocks.length===0&&u.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 u.jsxs("div",{className:"relative",children:[u.jsx(Uj,{text:n.displayed}),a&&u.jsx("span",{className:"inline-block w-2 h-4 ml-1 bg-[var(--color-text)] animate-pulse align-middle"})]},r)}return u.jsx(Fj,{tool:n},r)})]})]})})}function $8({block:e}){return e.type==="text"?u.jsx(Uj,{text:e.text}):u.jsx(Fj,{tool:e})}function Uj({text:e}){return e?u.jsx("div",{className:"text-sm font-[family-name:var(--font-body)] break-words prose-chat",children:u.jsx(Sx,{remarkPlugins:[Cx],rehypePlugins:[Mx],children:e})}):null}function U8(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 Fj({tool:e}){const[t,n]=C.useState(!1),r=e.status==="completed"||e.status==="complete",a=e.status==="failed",o=!r&&!a,l=U8(e.input),d=e.input!=null&&(typeof e.input!="object"||Object.keys(e.input).length>0);return u.jsxs("div",{className:"border-2 border-[var(--color-text)] rounded-lg overflow-hidden bg-[var(--color-bg-cream)]",children:[u.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:[u.jsx(Wl,{size:12,strokeWidth:3,className:["transition-transform flex-shrink-0",t?"rotate-90":""].join(" ")}),u.jsx(ZN,{size:12,strokeWidth:2.5,className:"flex-shrink-0"}),u.jsx("span",{className:"font-bold flex-shrink-0",children:e.title||e.kind}),u.jsx("span",{className:"flex-1 text-left text-[var(--color-text-muted)] truncate",title:l,children:l}),o&&u.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin text-[var(--color-running)] flex-shrink-0"}),r&&u.jsx(wu,{size:12,strokeWidth:2.5,className:"text-[var(--color-running)] flex-shrink-0"}),a&&u.jsx(zN,{size:12,strokeWidth:2.5,className:"text-[var(--color-crashed)] flex-shrink-0"})]}),t&&u.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?u.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)}):u.jsx("div",{children:"无参数"}),u.jsxs("div",{className:"opacity-60",children:["id: ",e.id," · ",e.status]})]})]})}function qj(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 F8(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 q8(){return ht("/api/processes").then(e=>e.data)}function H8(e){return Ri(`/api/processes/${e}/kill`)}function K8(){return ht("/api/processes/reclaim")}async function G8(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 jE="border-[3px] border-[var(--color-text)] rounded-2xl bg-white shadow-[4px_4px_0_var(--color-text)]";function V8(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 ay(e){return e.project?e.project:e.cwd?e.cwd.split("/").filter(Boolean).pop()??e.slot:e.slot}function CE(e){const t=/^session-chat-(.+)$/.exec(e.slot);return(t==null?void 0:t[1])??null}function Y8({p:e}){const t=e.alive?e.sessionState??"alive":"offline",n=e.alive?"bg-[var(--color-accent-mint)]":"bg-[var(--color-bg-cream)] text-[var(--color-text)]/60";return u.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:[u.jsx("span",{className:`w-2 h-2 rounded-full ${e.alive?"bg-green-600":"bg-gray-400"}`}),t]})}function Q8(){var k;const e=Be(),t=Gt(),[n,r]=C.useState(null),[a,o]=C.useState("all"),l=Ye({queryKey:["processes"],queryFn:q8,refetchInterval:5e3}),d=Ct({mutationFn:H8,onSuccess:v=>{r(v.message),t.invalidateQueries({queryKey:["processes"]})},onError:v=>r(v instanceof Error?v.message:String(v))}),f=Ye({queryKey:["reclaim"],queryFn:K8}),[h,g]=C.useState("");C.useEffect(()=>{f.data&&h===""&&g(String(f.data.idleMinutes))},[f.data,h]);const m=Ct({mutationFn:v=>G8(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 u.jsxs("div",{className:"max-w-full",children:[u.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[u.jsx(dh,{size:22,strokeWidth:2.5}),u.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl",children:e("processes.title")}),u.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?u.jsx(Xe,{size:15,className:"animate-spin"}):u.jsx(ga,{size:15}),e("processes.refresh")]})]}),u.jsxs("p",{className:"text-sm text-[var(--color-text)]/70 mb-3",children:[e("processes.subtitle")," · ",e("processes.aliveCount").replace("{n}",String(y.length))]}),u.jsxs("div",{className:`${jE} px-4 py-3 mb-4 flex flex-wrap items-center gap-2`,style:{boxShadow:"2px 2px 0 var(--color-text)"},children:[u.jsx(a3,{size:16,strokeWidth:2.5}),u.jsx("span",{className:"text-sm font-bold",children:"自动回收"}),u.jsx("span",{className:"text-sm text-[var(--color-text)]/70",children:"会话空闲"}),u.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":"自动回收空闲分钟数"}),u.jsx("span",{className:"text-sm text-[var(--color-text)]/70",children:"分钟后自动停(下次访问自动续上,不丢上下文)"}),u.jsxs("button",{type:"button",disabled:m.isPending||h===""||Number(h)===((k=f.data)==null?void 0:k.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?u.jsx(Xe,{size:14,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:3}),"保存"]})]}),n&&u.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}),u.jsx("div",{className:"flex flex-wrap gap-2 mb-3 items-center",children:["all","worker","chat"].map(v=>u.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))}),u.jsx("div",{className:`${jE} overflow-hidden`,children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{className:"bg-[var(--color-bg-cream)] font-[family-name:var(--font-heading)]",children:u.jsxs("tr",{className:"text-left",children:[u.jsx("th",{className:"px-3 py-2",children:e("processes.col.kind")}),u.jsx("th",{className:"px-3 py-2",children:e("processes.col.slot")}),u.jsx("th",{className:"px-3 py-2",children:e("processes.col.project")}),u.jsx("th",{className:"px-3 py-2",children:"PID"}),u.jsx("th",{className:"px-3 py-2",children:e("processes.col.state")}),u.jsx("th",{className:"px-3 py-2",children:e("processes.col.memory")}),u.jsx("th",{className:"px-3 py-2",children:"运行时间"}),u.jsx("th",{className:"px-3 py-2",children:e("processes.col.action")})]})}),u.jsxs("tbody",{className:"font-[family-name:var(--font-mono)]",children:[b.length===0&&u.jsx("tr",{children:u.jsx("td",{colSpan:8,className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:e("processes.empty")})}),b.map(v=>u.jsxs("tr",{className:"border-t-2 border-[var(--color-text)]/10",title:v.cwd??"",children:[u.jsx("td",{className:"px-3 py-2",children:u.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}`)})}),u.jsx("td",{className:"px-3 py-2 max-w-[220px] truncate",children:v.slot}),u.jsx("td",{className:"px-3 py-2 max-w-[220px] truncate",children:v.kind==="chat"&&CE(v)?u.jsxs(bs,{to:`/chat/${CE(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:[u.jsx(UN,{size:12,strokeWidth:2.5})," ",ay(v)]}):v.kind==="worker"&&v.project?u.jsxs(bs,{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:[u.jsx(dh,{size:12,strokeWidth:2.5})," ",ay(v)]}):u.jsx("span",{children:ay(v)})}),u.jsx("td",{className:"px-3 py-2",children:v.pid??"—"}),u.jsx("td",{className:"px-3 py-2",children:u.jsx(Y8,{p:v})}),u.jsx("td",{className:"px-3 py-2",children:v.memoryMB!=null?`${v.memoryMB} MB`:"—"}),u.jsx("td",{className:"px-3 py-2",children:V8(v.startedAt)}),u.jsx("td",{className:"px-3 py-2",children:v.alive&&v.pid!=null?u.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:[u.jsx(zN,{size:13})," ",e("processes.kill")]}):u.jsx("span",{className:"text-[var(--color-text)]/40 text-xs",children:"—"})})]},v.slot))]})]})})]})}function W8(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 X8="border-[3px] border-[var(--color-text)] rounded-2xl bg-white shadow-[4px_4px_0_var(--color-text)]",Z8={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 J8(){const e=Be(),t=Gt(),[n,r]=C.useState(""),a=Ye({queryKey:["audit",n],queryFn:()=>W8(n?{action:n}:{}),refetchInterval:8e3}),o=a.data??[],l=d=>e(`audit.action.${d}`);return u.jsxs("div",{className:"max-w-full",children:[u.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[u.jsx(KN,{size:22,strokeWidth:2.5}),u.jsx("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl",children:e("audit.title")}),u.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?u.jsx(Xe,{size:15,className:"animate-spin"}):u.jsx(ga,{size:15}),e("audit.refresh")]})]}),u.jsx("p",{className:"text-sm text-[var(--color-text)]/70 mb-4",children:e("audit.subtitle")}),u.jsx("div",{className:"flex gap-2 mb-3",children:["","create","modify","delete","daemon"].map(d=>u.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"))}),u.jsx("div",{className:`${X8} overflow-hidden`,children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{className:"bg-[var(--color-bg-cream)] font-[family-name:var(--font-heading)]",children:u.jsxs("tr",{className:"text-left",children:[u.jsx("th",{className:"px-3 py-2",children:e("audit.col.time")}),u.jsx("th",{className:"px-3 py-2",children:e("audit.col.action")}),u.jsx("th",{className:"px-3 py-2",children:e("audit.col.project")}),u.jsx("th",{className:"px-3 py-2",children:e("audit.col.detail")})]})}),u.jsxs("tbody",{className:"font-[family-name:var(--font-mono)]",children:[o.length===0&&u.jsx("tr",{children:u.jsx("td",{colSpan:4,className:"px-3 py-6 text-center text-[var(--color-text)]/50",children:e("audit.empty")})}),o.map((d,f)=>u.jsxs("tr",{className:"border-t-2 border-[var(--color-text)]/10",children:[u.jsx("td",{className:"px-3 py-2 whitespace-nowrap",children:new Date(d.ts).toLocaleString()}),u.jsx("td",{className:"px-3 py-2",children:u.jsx("span",{className:`inline-block px-2 py-0.5 rounded-lg border-2 border-[var(--color-text)] text-xs font-bold ${Z8[d.action]}`,children:l(d.action)})}),u.jsx("td",{className:"px-3 py-2",children:d.project}),u.jsx("td",{className:"px-3 py-2 text-[var(--color-text)]/70",children:d.detail??(d.source?`(${d.source})`:"—")})]},`${d.ts}-${f}`))]})]})})]})}const sy="rounded-xl border-[3px] border-[var(--color-text)] shadow-[3px_3px_0_var(--color-text)] bg-white p-3";function eq(){const e=Be(),[t,n]=C.useState(""),[r,a]=C.useState([]),[o,l]=C.useState([]),[d,f]=C.useState(!1),[h,g]=C.useState(null),[m,y]=C.useState(null);C.useEffect(()=>{fetch("/api/memory-cfg").then(v=>v.json()).then(v=>y(v.viewerUrl??"")).catch(()=>y(""))},[]);async function b(){try{const v=await fetch("/api/memory/sessions");if(!v.ok)throw new Error(`HTTP ${v.status}`);const N=await v.json();l((N.sessions??N??[]).slice(0,30))}catch(v){g(v instanceof Error?v.message:String(v))}}C.useEffect(()=>{b()},[]);async function k(){if(t.trim()){f(!0),g(null);try{const v=await fetch("/api/memory/smart-search",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({query:t,limit:15})});if(!v.ok)throw new Error(`HTTP ${v.status}`);const N=await v.json();a(N.results??N.hits??[])}catch(v){g(v instanceof Error?v.message:String(v))}finally{f(!1)}}}return m===null?null:m?u.jsxs("div",{className:"flex flex-col gap-4 h-full min-h-0",children:[u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsxs("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl text-[var(--color-text)]",children:["🧠 ",e("nav.memory")]}),u.jsxs("a",{href:m,target:"_blank",rel:"noreferrer",className:"text-sm font-semibold underline decoration-2 underline-offset-2 text-[var(--color-text)] hover:opacity-70",children:["↗ ",m]})]}),u.jsx("div",{className:"flex-1 min-h-0 rounded-2xl border-[3px] border-[var(--color-text)] shadow-[4px_4px_0_var(--color-text)] overflow-hidden bg-white",children:u.jsx("iframe",{src:m,title:"agentmemory dashboard",className:"w-full h-full border-0",style:{minHeight:"calc(100vh - 160px)"}})})]}):u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsxs("h1",{className:"font-[family-name:var(--font-heading)] font-bold text-2xl text-[var(--color-text)]",children:["🧠 ",e("nav.memory")]}),u.jsx("span",{className:"text-xs text-[var(--color-text)] opacity-60",children:e("memory.sub")})]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx("input",{value:t,onChange:v=>n(v.target.value),onKeyDown:v=>v.key==="Enter"&&k(),placeholder:e("memory.searchPlaceholder"),"aria-label":e("memory.searchPlaceholder"),className:"flex-1 rounded-xl border-[3px] border-[var(--color-text)] px-3 py-2 font-[family-name:var(--font-mono)] text-sm focus-visible:shadow-[3px_3px_0_var(--color-text)] outline-none"}),u.jsx("button",{type:"button",onClick:k,disabled:d,"aria-label":e("memory.search"),className:"rounded-xl border-[3px] border-[var(--color-text)] bg-[var(--color-accent-mint)] px-4 py-2 font-bold text-sm shadow-[3px_3px_0_var(--color-text)] hover:-translate-x-px hover:-translate-y-px hover:shadow-[4px_4px_0_var(--color-text)] active:translate-x-0.5 active:translate-y-0.5 active:shadow-[1px_1px_0_var(--color-text)] disabled:opacity-50",children:d?"…":e("memory.search")})]}),h&&u.jsxs("div",{className:"text-sm text-[var(--color-accent-pink,#d6336c)] font-semibold",children:["⚠ ",h]}),r.length>0&&u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm text-[var(--color-text)]",children:[e("memory.results"),"(",r.length,")"]}),r.map(v=>{var N;return u.jsxs("div",{className:sy,children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs opacity-60 font-[family-name:var(--font-mono)]",children:[u.jsx("span",{children:v.type||v.title}),u.jsx("span",{children:"·"}),u.jsx("span",{children:new Date(v.timestamp).toLocaleString()}),u.jsx("span",{children:"·"}),u.jsxs("span",{children:["score ",(N=v.score)==null?void 0:N.toFixed(3)]})]}),u.jsx("div",{className:"text-sm mt-1 text-[var(--color-text)]",children:v.text||v.content||v.summary||u.jsx("span",{className:"opacity-50 italic",children:e("memory.rawHint")})})]},v.obsId)})]}),u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-sm text-[var(--color-text)]",children:[e("memory.sessions"),"(",o.length,")"]}),o.length===0&&u.jsx("div",{className:`${sy} text-sm opacity-60`,children:e("memory.empty")}),o.map((v,N)=>{var E;return u.jsxs("div",{className:sy,children:[u.jsx("div",{className:"font-[family-name:var(--font-mono)] text-xs text-[var(--color-text)]",children:(v.cwd??"").split("/").pop()||((E=v.sessionId)==null?void 0:E.slice(0,8))||"?"}),v.firstPrompt&&u.jsx("div",{className:"text-xs opacity-60 mt-1 line-clamp-2",children:v.firstPrompt.slice(0,160)})]},v.sessionId??N)})]})]})}async function tq(){return(await ht("/api/channels")).data??{console:{},adapters:[]}}async function nq(e){return(await Bb("/api/channels",e)).data}async function rq(){return(await ht("/api/codex-proxy")).data}async function iq(){return(await Ri("/api/codex-proxy/install")).data}async function aq(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 sq(){return(await Ri("/api/codex-proxy/auth/start")).data}async function oq(){await Ri("/api/codex-proxy/auth/cancel")}const AE=[{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 lq(){const e=Be(),[t,n]=C.useState("memory");return u.jsxs("div",{className:"flex flex-col gap-6 w-full",children:[u.jsxs("header",{children:[u.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:e("plugins.h1")}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:e("plugins.desc")})]}),u.jsx("div",{role:"tablist","aria-label":e("plugins.h1"),className:"flex gap-2 flex-wrap",children:AE.map(r=>{const a=t===r.key;return u.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)})}),u.jsx("div",{role:"tabpanel",children:t==="memory"?u.jsx(uq,{}):t==="channel"?u.jsx(gq,{}):t==="model"?u.jsx(dq,{}):u.jsx(cq,{label:e(AE.find(r=>r.key===t).labelKey)})})]})}function cq({label:e}){const t=Be();return u.jsx("section",{className:"nb-card",children:u.jsxs("p",{className:"text-[var(--color-text-muted)] text-sm",children:[e," — ",t("plugins.comingSoon")]})})}function uq(){var k,v,N;const e=Be(),t=Gt(),{alert:n}=un(),r=Ye({queryKey:["system-memory"],queryFn:A3}),[a,o]=C.useState(null),[l,d]=C.useState(null);C.useEffect(()=>{r.data&&a===null&&(o(r.data.provider),d(r.data.url))},[r.data,a]);const f=a??((k=r.data)==null?void 0:k.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 j=`system.memory.opt.${E}`;return e(j)},y=Ct({mutationFn:()=>T3(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=((N=r.data)==null?void 0:N.options)??["none","builtin","agentmemory","custom"];return u.jsxs("section",{className:"nb-card",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:e("system.memory.title")}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-3",children:e("system.memory.desc")}),u.jsxs("div",{className:"flex flex-col gap-3 max-w-md",children:[u.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[u.jsx("span",{className:"font-bold",children:e("system.memory.provider")}),u.jsx("select",{className:"nb-input",value:f,onChange:E=>o(E.target.value),"aria-label":e("system.memory.provider"),children:b.map(E=>u.jsx("option",{value:E,children:m(E)},E))})]}),f==="custom"&&u.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[u.jsx("span",{className:"font-bold",children:e("system.memory.url")}),u.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")})]}),u.jsx("div",{className:"flex justify-end",children:u.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?u.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(Oi,{size:12,strokeWidth:3}),y.isSuccess&&!g?e("system.memory.saved"):e("system.memory.save")]})})]})]})}function dq(){var N,E,j;const e=Gt(),{alert:t,confirm:n}=un(),r=Ye({queryKey:["providers"],queryFn:ix}),o=(N=Ye({queryKey:["system-agents"],queryFn:i_}).data)==null?void 0:N.agents,[l,d]=C.useState(null),f=Ct({mutationFn:()=>qz(l.kind,l.entry),onSuccess:()=>{d(null),e.invalidateQueries({queryKey:["providers"]})},onError:S=>void t({title:"保存失败",body:S instanceof Error?S.message:String(S)})}),h=Ct({mutationFn:S=>Hz(S.kind,S.id),onSuccess:()=>void e.invalidateQueries({queryKey:["providers"]}),onError:S=>void t({title:"删除失败",body:S instanceof Error?S.message:String(S)})}),g=Ct({mutationFn:S=>M3(S),onSuccess:()=>void e.invalidateQueries({queryKey:["system-agents"]}),onError:S=>void t({title:"设默认失败",body:S instanceof Error?S.message:String(S)})}),m=(S,_,M)=>{if(!o)return!1;const T=S==="anthropic"?o.worker:o.reviewer;return(T.providerId||"official")===_&&T.model===M},y=(S,_,M)=>{if(!o)return;let T;if(S==="anthropic"){const L={...o.worker,model:M};_==="official"?delete L.providerId:L.providerId=_,T={...o,worker:L}}else T={...o,reviewer:{...o.reviewer,providerId:_,model:M}};g.mutate(T)},b=[{kind:"anthropic",title:"Anthropic 兼容(worker / claude)",items:((E=r.data)==null?void 0:E.anthropic)??[]},{kind:"openai",title:"OpenAI 兼容(reviewer / openai agent)",items:((j=r.data)==null?void 0:j.openai)??[]}],k=S=>d({kind:S,isNew:!0,entry:{id:"",name:"",baseUrl:"",apiKey:"",models:[]}}),v=(S,_)=>d({kind:S,isNew:!1,entry:{id:_.id,name:_.name,baseUrl:_.baseUrl,apiKey:"",models:_.models}});return u.jsxs("section",{className:"nb-card",children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-1",children:"模型 API 端点"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mb-4",children:"本地官方订阅(已登录验证)自动置顶,不可编辑;下方可增删第三方兼容端点。**点模型标签设为默认**(anthropic→worker / openai→监工);✓ = 当前默认。"}),u.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:b.map(S=>u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("span",{className:"font-bold text-sm",children:S.title}),u.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:()=>k(S.kind),"aria-label":`添加 ${S.title} 端点`,children:[u.jsx(pr,{size:12,strokeWidth:3})," 添加"]})]}),S.items.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"(无端点)"}),S.items.map(_=>_.id==="codex-proxy"?u.jsx(hq,{isDefault:M=>m(S.kind,_.id,M),pickDefault:M=>y(S.kind,_.id,M),setDefaultPending:g.isPending},_.id):u.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:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:_.id}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm",children:[" · ",_.name]}),_.builtin?u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:["本地订阅",_.detail?` · ${_.detail}`:""," · 已验证可用"]}):u.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] truncate",children:[_.baseUrl," · key ",_.hasKey?_.apiKey:"未设置"]})]}),_.builtin?u.jsx("span",{className:"shrink-0 text-[10px] font-bold px-2 py-0.5 rounded-md border-2 border-[var(--color-text)] bg-[var(--color-accent-yellow)]",children:"内置"}):u.jsxs("div",{className:"flex gap-1 shrink-0",children:[u.jsx("button",{className:"nb-btn",style:{padding:"4px 8px"},type:"button",onClick:()=>v(S.kind,_),"aria-label":`编辑 ${_.id}`,children:u.jsx(LL,{size:12,strokeWidth:3})}),u.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:S.kind,id:_.id})},"aria-label":`删除 ${_.id}`,children:u.jsx(fi,{size:12,strokeWidth:3})})]})]}),_.models.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:_.models.map(M=>{const T=m(S.kind,_.id,M);return u.jsxs("button",{type:"button",onClick:()=>y(S.kind,_.id,M),disabled:g.isPending,"aria-pressed":T,className:["px-2 py-0.5 rounded-md text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)]",T?"bg-[var(--color-accent-mint)] font-bold":"bg-[var(--color-bg)] hover:bg-[var(--color-bg-cream)]"].join(" "),title:T?"当前默认":"设为默认",children:[M,T?" ✓":""]},M)})})]},_.id))]},S.kind))}),l&&u.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:()=>d(null),children:u.jsx("div",{onClick:S=>S.stopPropagation(),children:u.jsx(fq,{state:l,onChange:S=>d({...l,entry:S}),onCancel:()=>d(null),onSave:()=>f.mutate(),saving:f.isPending})})})]})}function fq({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 u.jsxs("div",{className:"border-[3px] border-[var(--color-text)] rounded-2xl p-6 bg-[var(--color-bg-cream)] shadow-[6px_6px_0_var(--color-text)] flex flex-col gap-4 w-[min(92vw,640px)] max-h-[88vh] overflow-y-auto",children:[u.jsxs("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:[e.isNew?"新增端点":`编辑 ${o.id}`,u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-normal",children:["(",e.kind,")"]})]}),u.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["id(英数 _ -)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)]",value:o.id,disabled:!e.isNew,onChange:f=>l({id:f.target.value}),placeholder:"如 my-openai",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["名称",u.jsx("input",{className:"nb-input",value:o.name,onChange:f=>l({name:f.target.value}),placeholder:"显示名"})]})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Base URL",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",value:o.baseUrl,onChange:f=>l({baseUrl:f.target.value}),placeholder:"https://api.example.com/v1",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["API Key",!e.isNew&&"(留空=保留)",u.jsx("input",{className:"nb-input font-[family-name:var(--font-mono)] text-sm",type:"password",value:o.apiKey??"",onChange:f=>l({apiKey:f.target.value}),placeholder:e.isNew?"sk-...":"••••(留空不改)",spellCheck:!1})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Models(逗号或换行分隔)",u.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})]}),u.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[u.jsx("button",{className:"nb-btn",style:{padding:"8px 16px"},type:"button",onClick:n,children:"取消"}),u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"8px 16px"},type:"button",disabled:!d||a,onClick:r,children:[a?u.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:3})," 保存"]})]})]})}function hq({isDefault:e,pickDefault:t,setDefaultPending:n}){const r=Gt(),{alert:a,confirm:o}=un(),[l,d]=C.useState(!1),[f,h]=C.useState(null),[g,m]=C.useState(!1),[y,b]=C.useState(!1),[k,v]=C.useState(!1),E=Ye({queryKey:["codex-proxy"],queryFn:rq,refetchInterval:l?3e3:!1}).data;C.useEffect(()=>{l&&(E!=null&&E.authed)&&(d(!1),h(null),r.invalidateQueries({queryKey:["codex-proxy"]}))},[l,E==null?void 0:E.authed,r]);const j=Ct({mutationFn:iq,onSuccess:F=>{r.invalidateQueries({queryKey:["codex-proxy"]}),r.invalidateQueries({queryKey:["providers"]}),F.ok||a({title:"安装失败",body:(F.output||"未知错误").slice(-600)})},onError:F=>void a({title:"安装失败",body:F instanceof Error?F.message:String(F)})}),S=Ct({mutationFn:F=>aq(F),onSuccess:F=>{m(!1),b(!1),r.invalidateQueries({queryKey:["codex-proxy"]}),r.invalidateQueries({queryKey:["providers"]}),r.invalidateQueries({queryKey:["system-agents"]}),F.ok||a({title:"卸载未完成",body:F.note??"删除失败(可能需 sudo)"})},onError:F=>void a({title:"卸载失败",body:F instanceof Error?F.message:String(F)})}),_=async()=>{await o({title:"安装 claude-code-proxy",body:"将运行官方安装脚本(curl … install.sh | bash),下载预编译二进制到 ~/.local/bin。继续?"})&&j.mutate()},M=async()=>{d(!0),h(null);try{const F=await sq();h(F)}catch(F){d(!1),a({title:"订阅失败",body:F instanceof Error?F.message:String(F)})}},T=()=>{oq(),d(!1),h(null)},L=j.isPending||(E==null?void 0:E.installing),R=k&&(E!=null&&E.models.all.length)?E.models.all:(E==null?void 0:E.models.curated)??[];return u.jsxs("div",{className:"rounded-lg px-3 py-2 border-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[u.jsxs("div",{className:"flex items-center justify-between gap-2",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:"codex-proxy"}),u.jsx("span",{className:"text-[var(--color-text-muted)] text-sm",children:" · ChatGPT 订阅"}),u.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)&&u.jsx("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 8px"},type:"button",onClick:()=>m(!0),"aria-label":"卸载 codex-proxy",children:u.jsx(fi,{size:12,strokeWidth:3})})]}),u.jsx("div",{className:"mt-2",children:E?E.binInstalled?E.authed?u.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[R.map(F=>{const z=e(F);return u.jsxs("button",{type:"button",onClick:()=>t(F),disabled:n,"aria-pressed":z,className:["px-2 py-0.5 rounded-md text-xs font-[family-name:var(--font-mono)] border-2 border-[var(--color-text)]",z?"bg-[var(--color-accent-mint)] font-bold":"bg-[var(--color-bg)] hover:bg-[var(--color-bg-cream)]"].join(" "),title:z?"当前默认":"设为 worker 默认",children:[F,z?" ✓":""]},F)}),E.models.all.length>E.models.curated.length&&u.jsx("button",{type:"button",className:"text-xs text-[var(--color-text-muted)] underline",onClick:()=>v(F=>!F),children:k?"收起":`显示全部(${E.models.all.length})`})]}):u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 12px",fontSize:12},type:"button",onClick:M,children:[u.jsx(vL,{size:12,strokeWidth:3})," 订阅(授权 ChatGPT)"]}):u.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 12px",fontSize:12},type:"button",disabled:!!L,onClick:_,children:[L?u.jsx(Xe,{size:12,strokeWidth:3,className:"animate-spin"}):u.jsx(Ph,{size:12,strokeWidth:3}),L?" 安装中…":" 安装插件"]}):u.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin text-[var(--color-text-muted)]"})}),l&&u.jsxs(TE,{onClose:T,children:[u.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"订阅 ChatGPT(设备码授权)"}),f!=null&&f.verificationUrl&&(f!=null&&f.userCode)?u.jsxs("div",{className:"flex flex-col gap-3 text-sm",children:[u.jsxs("div",{children:["① 打开"," ",u.jsxs("a",{href:f.verificationUrl,target:"_blank",rel:"noreferrer",className:"font-bold underline inline-flex items-center gap-1",children:[f.verificationUrl," ",u.jsx(HR,{size:12,strokeWidth:3})]})]}),u.jsxs("div",{children:["② 输入验证码:",u.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})]}),u.jsx("div",{children:"③ 在浏览器完成授权"}),u.jsxs("div",{className:"flex items-center gap-2 text-[var(--color-text-muted)]",children:[u.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"})," 等待授权…(完成后自动刷新)"]})]}):u.jsxs("div",{className:"flex flex-col gap-2 text-sm text-[var(--color-text-muted)]",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"})," 正在获取设备码…"]}),u.jsxs("div",{children:["若长时间无响应,可在终端运行 ",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps codex-proxy auth"}),",完成后此处自动刷新。"]})]}),u.jsx("div",{className:"flex justify-end pt-1",children:u.jsx("button",{className:"nb-btn",style:{padding:"6px 14px"},type:"button",onClick:T,children:"取消"})})]}),g&&u.jsxs(TE,{onClose:()=>m(!1),children:[u.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"卸载 claude-code-proxy"}),u.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"停止 proxy 并删除二进制。默认保留授权(重装免再授权)。"}),u.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[u.jsx("input",{type:"checkbox",checked:y,onChange:F=>b(F.target.checked)}),"同时清除授权(~/.config/claude-code-proxy)"]}),u.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[u.jsx("button",{className:"nb-btn",style:{padding:"6px 14px"},type:"button",onClick:()=>m(!1),children:"取消"}),u.jsxs("button",{className:"nb-btn nb-btn-danger",style:{padding:"6px 14px"},type:"button",disabled:S.isPending,onClick:()=>S.mutate(y),children:[S.isPending?u.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(fi,{size:14,strokeWidth:3})," 卸载"]})]})]})]})}function TE({children:e,onClose:t}){return u.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:t,children:u.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 pq=["telegram","dingtalk","matrix","slack","discord","feishu"],pu={telegram:"Telegram",dingtalk:"钉钉 (Stream)",matrix:"Matrix",slack:"Slack",discord:"Discord",feishu:"飞书 / Lark"},mq={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 gq(){var k,v,N;const e=Gt(),{alert:t}=un(),n=Ye({queryKey:["channels"],queryFn:tq}),[r,a]=C.useState(null),[o,l]=C.useState({type:"console"});C.useEffect(()=>{n.data&&!r&&a({console:n.data.console??{},adapters:n.data.adapters??[]})},[n.data,r]);const d=Ct({mutationFn:()=>nq(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 u.jsx("section",{className:"nb-card",children:u.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] flex items-center gap-2",children:[u.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"})," 加载频道配置…"]})});const f=r.adapters??[],h=JSON.stringify(r)!==JSON.stringify({console:((k=n.data)==null?void 0:k.console)??{},adapters:((v=n.data)==null?void 0:v.adapters)??[]}),g=E=>{const j=[...f,{kind:E,enabled:!0}];a({...r,adapters:j}),l({type:"adapter",index:j.length-1})},m=E=>{const j=f.filter((S,_)=>_!==E);a({...r,adapters:j}),l({type:"console"})},y=(E,j)=>{const S=f.map((_,M)=>M===E?{..._,...j}:_);a({...r,adapters:S})},b=E=>a({...r,console:{...r.console,...E}});return u.jsxs("section",{className:"nb-card",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1",children:[u.jsxs("div",{children:[u.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"频道(IM 网关)"}),u.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:["接入 Telegram / 钉钉 / 飞书 / Slack / Discord / Matrix。左侧选频道,右侧改设置。保存后 ",u.jsx("code",{className:"font-[family-name:var(--font-mono)]",children:"sps im"})," 重启生效。"]})]}),u.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?u.jsx(Xe,{size:14,strokeWidth:3,className:"animate-spin"}):u.jsx(Oi,{size:14,strokeWidth:3})," 保存"]})]}),u.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[220px_1fr] gap-5 mt-4",children:[u.jsxs("div",{className:"flex flex-col gap-2",children:[u.jsx(ME,{label:"console 桥接",sub:((N=r.console)==null?void 0:N.url)||"未配置",active:o.type==="console",onClick:()=>l({type:"console"})}),u.jsx("div",{className:"h-px bg-[var(--color-text)] opacity-20 my-1"}),f.length===0&&u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] px-1",children:"(无频道)"}),f.map((E,j)=>u.jsx(ME,{label:pu[E.kind]??E.kind,sub:E.enabled===!1?"已停用":"启用",active:o.type==="adapter"&&o.index===j,onClick:()=>l({type:"adapter",index:j})},j)),u.jsxs("div",{className:"mt-2",children:[u.jsx("span",{className:"text-xs font-bold text-[var(--color-text-muted)]",children:"添加频道"}),u.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:pq.map(E=>u.jsxs("button",{className:"nb-btn",style:{padding:"4px 8px",fontSize:12},type:"button",onClick:()=>g(E),"aria-label":`添加 ${pu[E]} 频道`,children:[u.jsx(pr,{size:11,strokeWidth:3})," ",pu[E]]},E))})]})]}),u.jsx("div",{className:"border-2 border-[var(--color-text)] rounded-xl p-4 bg-[var(--color-bg-cream)]",children:(()=>{if(o.type!=="adapter")return u.jsx(DE,{console:r.console??{},onChange:b});const E=f[o.index];if(!E)return u.jsx(DE,{console:r.console??{},onChange:b});const j=o.index;return u.jsx(yq,{adapter:E,onChange:S=>y(j,S),onRemove:()=>m(j)})})()})]})]})}function ME({label:e,sub:t,active:n,onClick:r}){return u.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:[u.jsx("div",{className:"font-bold text-sm",children:e}),u.jsx("div",{className:"text-xs text-[var(--color-text-muted)] truncate font-[family-name:var(--font-mono)]",children:t})]})}function DE({console:e,onChange:t}){return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{children:[u.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:"console 桥接"}),u.jsx("p",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:"IM 纯文本消息桥接到项目 agent 对话。设了 URL 才启用桥接;token 为 console 鉴权令牌。"})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console URL",u.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})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["Console Token(SPS_CONSOLE_TOKEN)",u.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})]}),u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:["对话后端",u.jsxs("select",{className:"nb-input",value:e.agentKind??"claude",onChange:n=>t({agentKind:n.target.value}),children:[u.jsx("option",{value:"claude",children:"claude"}),u.jsx("option",{value:"openai",children:"openai"})]})]})]})}function yq({adapter:e,onChange:t,onRemove:n}){const{confirm:r}=un(),a=mq[e.kind]??[],o=e.enabled!==!1;return u.jsxs("div",{className:"flex flex-col gap-4",children:[u.jsxs("div",{className:"flex items-start justify-between gap-2",children:[u.jsxs("div",{children:[u.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:pu[e.kind]??e.kind}),u.jsxs("span",{className:"text-[var(--color-text-muted)] text-sm font-[family-name:var(--font-mono)]",children:[" · ",e.kind]})]}),u.jsxs("button",{className:"nb-btn nb-btn-danger shrink-0",style:{padding:"4px 10px",fontSize:12},type:"button",onClick:async()=>{await r({title:"删除频道",body:`删除 ${pu[e.kind]??e.kind} 频道?`,danger:!0})&&n()},"aria-label":"删除频道",children:[u.jsx(fi,{size:12,strokeWidth:3})," 删除"]})]}),u.jsxs("label",{className:"flex items-center gap-2 text-sm font-bold",children:[u.jsx("input",{type:"checkbox",checked:o,onChange:l=>t({enabled:l.target.checked})}),"启用此频道"]}),a.map(l=>u.jsx(bq,{spec:l,value:e[l.key],onChange:d=>t({[l.key]:d})},l.key))]})}function bq({spec:e,value:t,onChange:n}){if(e.type==="list"){const r=Array.isArray(t)?t.map(String):[];return u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,u.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 u.jsxs("label",{className:"flex flex-col gap-1 text-sm font-bold",children:[e.label,u.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 _n(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=_n(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var xq={value:()=>{}};function ap(){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 th(n)}function th(e){this._=e}function vq(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}})}th.prototype=ap.prototype={constructor:th,on:function(e,t){var n=this._,r=vq(e+"",n),a,o=-1,l=r.length;if(arguments.length<2){for(;++o<l;)if((a=(e=r[o]).type)&&(a=wq(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]=OE(n[a],e.name,t);else if(t==null)for(a in n)n[a]=OE(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 th(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 wq(e,t){for(var n=0,r=e.length,a;n<r;++n)if((a=e[n]).name===t)return a.value}function OE(e,t,n){for(var r=0,a=e.length;r<a;++r)if(e[r].name===t){e[r]=xq,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var ab="http://www.w3.org/1999/xhtml";const RE={svg:"http://www.w3.org/2000/svg",xhtml:ab,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function sp(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),RE.hasOwnProperty(t)?{space:RE[t],local:e}:e}function kq(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===ab&&t.documentElement.namespaceURI===ab?t.createElement(e):t.createElementNS(n,e)}}function Eq(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Hj(e){var t=sp(e);return(t.local?Eq:kq)(t)}function Sq(){}function Ox(e){return e==null?Sq:function(){return this.querySelector(e)}}function Nq(e){typeof e!="function"&&(e=Ox(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 _q(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function jq(){return[]}function Kj(e){return e==null?jq:function(){return this.querySelectorAll(e)}}function Cq(e){return function(){return _q(e.apply(this,arguments))}}function Aq(e){typeof e=="function"?e=Cq(e):e=Kj(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 Gj(e){return function(){return this.matches(e)}}function Vj(e){return function(t){return t.matches(e)}}var Tq=Array.prototype.find;function Mq(e){return function(){return Tq.call(this.children,e)}}function Dq(){return this.firstElementChild}function Oq(e){return this.select(e==null?Dq:Mq(typeof e=="function"?e:Vj(e)))}var Rq=Array.prototype.filter;function Lq(){return Array.from(this.children)}function Iq(e){return function(){return Rq.call(this.children,e)}}function zq(e){return this.selectAll(e==null?Lq:Iq(typeof e=="function"?e:Vj(e)))}function Pq(e){typeof e!="function"&&(e=Gj(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 Yj(e){return new Array(e.length)}function Bq(){return new Cr(this._enter||this._groups.map(Yj),this._parents)}function Eh(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Eh.prototype={constructor:Eh,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 $q(e){return function(){return e}}function Uq(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 Eh(e,o[l]);for(;l<f;++l)(d=t[l])&&(a[l]=d)}function Fq(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 Eh(e,o[d]);for(d=0;d<g;++d)(f=t[d])&&h.get(y[d])===f&&(a[d]=f)}function qq(e){return e.__data__}function Hq(e,t){if(!arguments.length)return Array.from(this,qq);var n=t?Fq:Uq,r=this._parents,a=this._groups;typeof e!="function"&&(e=$q(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=Kq(e.call(g,g&&g.__data__,h,r)),k=b.length,v=d[h]=new Array(k),N=l[h]=new Array(k),E=f[h]=new Array(y);n(g,m,v,N,E,b,t);for(var j=0,S=0,_,M;j<k;++j)if(_=v[j]){for(j>=S&&(S=j+1);!(M=N[S])&&++S<k;);_._next=M||null}}return l=new Cr(l,r),l._enter=d,l._exit=f,l}function Kq(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Gq(){return new Cr(this._exit||this._groups.map(Yj),this._parents)}function Vq(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 Yq(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,k=0;k<m;++k)(b=h[k]||g[k])&&(y[k]=b);for(;f<a;++f)d[f]=n[f];return new Cr(d,this._parents)}function Qq(){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 Wq(e){e||(e=Xq);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 Xq(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Zq(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Jq(){return Array.from(this)}function eH(){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 tH(){let e=0;for(const t of this)++e;return e}function nH(){return!this.node()}function rH(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 iH(e){return function(){this.removeAttribute(e)}}function aH(e){return function(){this.removeAttributeNS(e.space,e.local)}}function sH(e,t){return function(){this.setAttribute(e,t)}}function oH(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function lH(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function cH(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 uH(e,t){var n=sp(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?aH:iH:typeof t=="function"?n.local?cH:lH:n.local?oH:sH)(n,t))}function Qj(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function dH(e){return function(){this.style.removeProperty(e)}}function fH(e,t,n){return function(){this.style.setProperty(e,t,n)}}function hH(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function pH(e,t,n){return arguments.length>1?this.each((t==null?dH:typeof t=="function"?hH:fH)(e,t,n??"")):Bl(this.node(),e)}function Bl(e,t){return e.style.getPropertyValue(t)||Qj(e).getComputedStyle(e,null).getPropertyValue(t)}function mH(e){return function(){delete this[e]}}function gH(e,t){return function(){this[e]=t}}function yH(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function bH(e,t){return arguments.length>1?this.each((t==null?mH:typeof t=="function"?yH:gH)(e,t)):this.node()[e]}function Wj(e){return e.trim().split(/^|\s+/)}function Rx(e){return e.classList||new Xj(e)}function Xj(e){this._node=e,this._names=Wj(e.getAttribute("class")||"")}Xj.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 Zj(e,t){for(var n=Rx(e),r=-1,a=t.length;++r<a;)n.add(t[r])}function Jj(e,t){for(var n=Rx(e),r=-1,a=t.length;++r<a;)n.remove(t[r])}function xH(e){return function(){Zj(this,e)}}function vH(e){return function(){Jj(this,e)}}function wH(e,t){return function(){(t.apply(this,arguments)?Zj:Jj)(this,e)}}function kH(e,t){var n=Wj(e+"");if(arguments.length<2){for(var r=Rx(this.node()),a=-1,o=n.length;++a<o;)if(!r.contains(n[a]))return!1;return!0}return this.each((typeof t=="function"?wH:t?xH:vH)(n,t))}function EH(){this.textContent=""}function SH(e){return function(){this.textContent=e}}function NH(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function _H(e){return arguments.length?this.each(e==null?EH:(typeof e=="function"?NH:SH)(e)):this.node().textContent}function jH(){this.innerHTML=""}function CH(e){return function(){this.innerHTML=e}}function AH(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function TH(e){return arguments.length?this.each(e==null?jH:(typeof e=="function"?AH:CH)(e)):this.node().innerHTML}function MH(){this.nextSibling&&this.parentNode.appendChild(this)}function DH(){return this.each(MH)}function OH(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function RH(){return this.each(OH)}function LH(e){var t=typeof e=="function"?e:Hj(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function IH(){return null}function zH(e,t){var n=typeof e=="function"?e:Hj(e),r=t==null?IH:typeof t=="function"?t:Ox(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function PH(){var e=this.parentNode;e&&e.removeChild(this)}function BH(){return this.each(PH)}function $H(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function UH(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function FH(e){return this.select(e?UH:$H)}function qH(e){return arguments.length?this.property("__data__",e):this.node().__data__}function HH(e){return function(t){e.call(this,t,this.__data__)}}function KH(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 GH(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 VH(e,t,n){return function(){var r=this.__on,a,o=HH(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 YH(e,t,n){var r=KH(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?VH:GH,a=0;a<o;++a)this.each(d(r[a],t,n));return this}function eC(e,t,n){var r=Qj(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 QH(e,t){return function(){return eC(this,e,t)}}function WH(e,t){return function(){return eC(this,e,t.apply(this,arguments))}}function XH(e,t){return this.each((typeof t=="function"?WH:QH)(e,t))}function*ZH(){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 tC=[null];function Cr(e,t){this._groups=e,this._parents=t}function td(){return new Cr([[document.documentElement]],tC)}function JH(){return this}Cr.prototype=td.prototype={constructor:Cr,select:Nq,selectAll:Aq,selectChild:Oq,selectChildren:zq,filter:Pq,data:Hq,enter:Bq,exit:Gq,join:Vq,merge:Yq,selection:JH,order:Qq,sort:Wq,call:Zq,nodes:Jq,node:eH,size:tH,empty:nH,each:rH,attr:uH,style:pH,property:bH,classed:kH,text:_H,html:TH,raise:DH,lower:RH,append:LH,insert:zH,remove:BH,clone:FH,datum:qH,on:YH,dispatch:XH,[Symbol.iterator]:ZH};function _r(e){return typeof e=="string"?new Cr([[document.querySelector(e)]],[document.documentElement]):new Cr([[e]],tC)}function e7(e){let t;for(;t=e.sourceEvent;)e=t;return e}function si(e,t){if(e=e7(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 t7={passive:!1},Cu={capture:!0,passive:!1};function oy(e){e.stopImmediatePropagation()}function wl(e){e.preventDefault(),e.stopImmediatePropagation()}function nC(e){var t=e.document.documentElement,n=_r(e).on("dragstart.drag",wl,Cu);"onselectstart"in t?n.on("selectstart.drag",wl,Cu):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function rC(e,t){var n=e.document.documentElement,r=_r(e).on("dragstart.drag",null);t&&(r.on("click.drag",wl,Cu),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 Pf=e=>()=>e;function sb(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}})}sb.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function n7(e){return!e.ctrlKey&&!e.button}function r7(){return this.parentNode}function i7(e,t){return t??{x:e.x,y:e.y}}function a7(){return navigator.maxTouchPoints||"ontouchstart"in this}function iC(){var e=n7,t=r7,n=i7,r=a7,a={},o=ap("start","drag","end"),l=0,d,f,h,g,m=0;function y(_){_.on("mousedown.drag",b).filter(r).on("touchstart.drag",N).on("touchmove.drag",E,t7).on("touchend.drag touchcancel.drag",j).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function b(_,M){if(!(g||!e.call(this,_,M))){var T=S(this,t.call(this,_,M),_,M,"mouse");T&&(_r(_.view).on("mousemove.drag",k,Cu).on("mouseup.drag",v,Cu),nC(_.view),oy(_),h=!1,d=_.clientX,f=_.clientY,T("start",_))}}function k(_){if(wl(_),!h){var M=_.clientX-d,T=_.clientY-f;h=M*M+T*T>m}a.mouse("drag",_)}function v(_){_r(_.view).on("mousemove.drag mouseup.drag",null),rC(_.view,h),wl(_),a.mouse("end",_)}function N(_,M){if(e.call(this,_,M)){var T=_.changedTouches,L=t.call(this,_,M),R=T.length,F,z;for(F=0;F<R;++F)(z=S(this,L,_,M,T[F].identifier,T[F]))&&(oy(_),z("start",_,T[F]))}}function E(_){var M=_.changedTouches,T=M.length,L,R;for(L=0;L<T;++L)(R=a[M[L].identifier])&&(wl(_),R("drag",_,M[L]))}function j(_){var M=_.changedTouches,T=M.length,L,R;for(g&&clearTimeout(g),g=setTimeout(function(){g=null},500),L=0;L<T;++L)(R=a[M[L].identifier])&&(oy(_),R("end",_,M[L]))}function S(_,M,T,L,R,F){var z=o.copy(),$=si(F||T,M),q,Y,D;if((D=n.call(_,new sb("beforestart",{sourceEvent:T,target:y,identifier:R,active:l,x:$[0],y:$[1],dx:0,dy:0,dispatch:z}),L))!=null)return q=D.x-$[0]||0,Y=D.y-$[1]||0,function H(O,V,Q){var K=$,I;switch(O){case"start":a[R]=H,I=l++;break;case"end":delete a[R],--l;case"drag":$=si(Q||V,M),I=l;break}z.call(O,_,new sb(O,{sourceEvent:V,subject:D,target:y,identifier:R,active:I,x:$[0]+q,y:$[1]+Y,dx:$[0]-K[0],dy:$[1]-K[1],dispatch:z}),L)}}return y.filter=function(_){return arguments.length?(e=typeof _=="function"?_:Pf(!!_),y):e},y.container=function(_){return arguments.length?(t=typeof _=="function"?_:Pf(_),y):t},y.subject=function(_){return arguments.length?(n=typeof _=="function"?_:Pf(_),y):n},y.touchable=function(_){return arguments.length?(r=typeof _=="function"?_:Pf(!!_),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 Lx(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function aC(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function nd(){}var Au=.7,Sh=1/Au,kl="\\s*([+-]?\\d+)\\s*",Tu="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Mi="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",s7=/^#([0-9a-f]{3,8})$/,o7=new RegExp(`^rgb\\(${kl},${kl},${kl}\\)$`),l7=new RegExp(`^rgb\\(${Mi},${Mi},${Mi}\\)$`),c7=new RegExp(`^rgba\\(${kl},${kl},${kl},${Tu}\\)$`),u7=new RegExp(`^rgba\\(${Mi},${Mi},${Mi},${Tu}\\)$`),d7=new RegExp(`^hsl\\(${Tu},${Mi},${Mi}\\)$`),f7=new RegExp(`^hsla\\(${Tu},${Mi},${Mi},${Tu}\\)$`),LE={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};Lx(nd,ho,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:IE,formatHex:IE,formatHex8:h7,formatHsl:p7,formatRgb:zE,toString:zE});function IE(){return this.rgb().formatHex()}function h7(){return this.rgb().formatHex8()}function p7(){return sC(this).formatHsl()}function zE(){return this.rgb().formatRgb()}function ho(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=s7.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?PE(t):n===3?new hr(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Bf(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Bf(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=o7.exec(e))?new hr(t[1],t[2],t[3],1):(t=l7.exec(e))?new hr(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=c7.exec(e))?Bf(t[1],t[2],t[3],t[4]):(t=u7.exec(e))?Bf(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=d7.exec(e))?UE(t[1],t[2]/100,t[3]/100,1):(t=f7.exec(e))?UE(t[1],t[2]/100,t[3]/100,t[4]):LE.hasOwnProperty(e)?PE(LE[e]):e==="transparent"?new hr(NaN,NaN,NaN,0):null}function PE(e){return new hr(e>>16&255,e>>8&255,e&255,1)}function Bf(e,t,n,r){return r<=0&&(e=t=n=NaN),new hr(e,t,n,r)}function m7(e){return e instanceof nd||(e=ho(e)),e?(e=e.rgb(),new hr(e.r,e.g,e.b,e.opacity)):new hr}function ob(e,t,n,r){return arguments.length===1?m7(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}Lx(hr,ob,aC(nd,{brighter(e){return e=e==null?Sh:Math.pow(Sh,e),new hr(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Au:Math.pow(Au,e),new hr(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new hr(so(this.r),so(this.g),so(this.b),Nh(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:BE,formatHex:BE,formatHex8:g7,formatRgb:$E,toString:$E}));function BE(){return`#${Ws(this.r)}${Ws(this.g)}${Ws(this.b)}`}function g7(){return`#${Ws(this.r)}${Ws(this.g)}${Ws(this.b)}${Ws((isNaN(this.opacity)?1:this.opacity)*255)}`}function $E(){const e=Nh(this.opacity);return`${e===1?"rgb(":"rgba("}${so(this.r)}, ${so(this.g)}, ${so(this.b)}${e===1?")":`, ${e})`}`}function Nh(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function so(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Ws(e){return e=so(e),(e<16?"0":"")+e.toString(16)}function UE(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 sC(e){if(e instanceof oi)return new oi(e.h,e.s,e.l,e.opacity);if(e instanceof nd||(e=ho(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 y7(e,t,n,r){return arguments.length===1?sC(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}Lx(oi,y7,aC(nd,{brighter(e){return e=e==null?Sh:Math.pow(Sh,e),new oi(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Au:Math.pow(Au,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(ly(e>=240?e-240:e+120,a,r),ly(e,a,r),ly(e<120?e+240:e-120,a,r),this.opacity)},clamp(){return new oi(FE(this.h),$f(this.s),$f(this.l),Nh(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=Nh(this.opacity);return`${e===1?"hsl(":"hsla("}${FE(this.h)}, ${$f(this.s)*100}%, ${$f(this.l)*100}%${e===1?")":`, ${e})`}`}}));function FE(e){return e=(e||0)%360,e<0?e+360:e}function $f(e){return Math.max(0,Math.min(1,e||0))}function ly(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 Ix=e=>()=>e;function b7(e,t){return function(n){return e+n*t}}function x7(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 v7(e){return(e=+e)==1?oC:function(t,n){return n-t?x7(t,n,e):Ix(isNaN(t)?n:t)}}function oC(e,t){var n=t-e;return n?b7(e,n):Ix(isNaN(e)?t:e)}const _h=(function e(t){var n=v7(t);function r(a,o){var l=n((a=ob(a)).r,(o=ob(o)).r),d=n(a.g,o.g),f=n(a.b,o.b),h=oC(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 w7(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 k7(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function E7(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]=mu(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 S7(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 N7(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]=mu(e[a],t[a]):r[a]=t[a];return function(o){for(a in n)r[a]=n[a](o);return r}}var lb=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,cy=new RegExp(lb.source,"g");function _7(e){return function(){return e}}function j7(e){return function(t){return e(t)+""}}function lC(e,t){var n=lb.lastIndex=cy.lastIndex=0,r,a,o,l=-1,d=[],f=[];for(e=e+"",t=t+"";(r=lb.exec(e))&&(a=cy.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=cy.lastIndex;return n<t.length&&(o=t.slice(n),d[l]?d[l]+=o:d[++l]=o),d.length<2?f[0]?j7(f[0].x):_7(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 mu(e,t){var n=typeof t,r;return t==null||n==="boolean"?Ix(t):(n==="number"?Ci:n==="string"?(r=ho(t))?(t=r,_h):lC:t instanceof ho?_h:t instanceof Date?S7:k7(t)?w7:Array.isArray(t)?E7:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?N7:Ci)(e,t)}var qE=180/Math.PI,cb={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function cC(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)*qE,skewX:Math.atan(f)*qE,scaleX:l,scaleY:d}}var Uf;function C7(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?cb:cC(t.a,t.b,t.c,t.d,t.e,t.f)}function A7(e){return e==null||(Uf||(Uf=document.createElementNS("http://www.w3.org/2000/svg","g")),Uf.setAttribute("transform",e),!(e=Uf.transform.baseVal.consolidate()))?cb:(e=e.matrix,cC(e.a,e.b,e.c,e.d,e.e,e.f))}function uC(e,t,n,r){function a(h){return h.length?h.pop()+" ":""}function o(h,g,m,y,b,k){if(h!==m||g!==y){var v=b.push("translate(",null,t,null,n);k.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,k){if(h!==m||g!==y){var v=b.push(a(b)+"scale(",null,",",null,")");k.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 k=-1,v=y.length,N;++k<v;)m[(N=y[k]).i]=N.x(b);return m.join("")}}}var T7=uC(C7,"px, ","px)","deg)"),M7=uC(A7,", ",")",")"),D7=1e-12;function HE(e){return((e=Math.exp(e))+1/e)/2}function O7(e){return((e=Math.exp(e))-1/e)/2}function R7(e){return((e=Math.exp(2*e))-1)/(e+1)}const nh=(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,k=m-f,v=b*b+k*k,N,E;if(v<D7)E=Math.log(y/h)/t,N=function(L){return[d+L*b,f+L*k,h*Math.exp(t*L*E)]};else{var j=Math.sqrt(v),S=(y*y-h*h+r*v)/(2*h*n*j),_=(y*y-h*h-r*v)/(2*y*n*j),M=Math.log(Math.sqrt(S*S+1)-S),T=Math.log(Math.sqrt(_*_+1)-_);E=(T-M)/t,N=function(L){var R=L*E,F=HE(M),z=h/(n*j)*(F*R7(t*R+M)-O7(M));return[d+z*b,f+z*k,h*F/HE(t*R+M)]}}return N.duration=E*1e3*t/Math.SQRT2,N}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 $l=0,lu=0,iu=0,dC=1e3,jh,cu,Ch=0,po=0,op=0,Mu=typeof performance=="object"&&performance.now?performance:Date,fC=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function zx(){return po||(fC(L7),po=Mu.now()+op)}function L7(){po=0}function Ah(){this._call=this._time=this._next=null}Ah.prototype=hC.prototype={constructor:Ah,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?zx():+n)+(t==null?0:+t),!this._next&&cu!==this&&(cu?cu._next=this:jh=this,cu=this),this._call=e,this._time=n,ub()},stop:function(){this._call&&(this._call=null,this._time=1/0,ub())}};function hC(e,t,n){var r=new Ah;return r.restart(e,t,n),r}function I7(){zx(),++$l;for(var e=jh,t;e;)(t=po-e._time)>=0&&e._call.call(void 0,t),e=e._next;--$l}function KE(){po=(Ch=Mu.now())+op,$l=lu=0;try{I7()}finally{$l=0,P7(),po=0}}function z7(){var e=Mu.now(),t=e-Ch;t>dC&&(op-=t,Ch=e)}function P7(){for(var e,t=jh,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:jh=n);cu=e,ub(r)}function ub(e){if(!$l){lu&&(lu=clearTimeout(lu));var t=e-po;t>24?(e<1/0&&(lu=setTimeout(KE,e-Mu.now()-op)),iu&&(iu=clearInterval(iu))):(iu||(Ch=Mu.now(),iu=setInterval(z7,dC)),$l=1,fC(KE))}}function GE(e,t,n){var r=new Ah;return t=t==null?0:+t,r.restart(a=>{r.stop(),e(a+t)},t,n),r}var B7=ap("start","end","cancel","interrupt"),$7=[],pC=0,VE=1,db=2,rh=3,YE=4,fb=5,ih=6;function lp(e,t,n,r,a,o){var l=e.__transition;if(!l)e.__transition={};else if(n in l)return;U7(e,n,{name:t,index:r,group:a,on:B7,tween:$7,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:pC})}function Px(e,t){var n=gi(e,t);if(n.state>pC)throw new Error("too late; already scheduled");return n}function Ii(e,t){var n=gi(e,t);if(n.state>rh)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 U7(e,t,n){var r=e.__transition,a;r[t]=n,n.timer=hC(o,0,n.time);function o(h){n.state=VE,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!==VE)return f();for(g in r)if(b=r[g],b.name===n.name){if(b.state===rh)return GE(l);b.state===YE?(b.state=ih,b.timer.stop(),b.on.call("interrupt",e,e.__data__,b.index,b.group),delete r[g]):+g<t&&(b.state=ih,b.timer.stop(),b.on.call("cancel",e,e.__data__,b.index,b.group),delete r[g])}if(GE(function(){n.state===rh&&(n.state=YE,n.timer.restart(d,n.delay,n.time),d(h))}),n.state=db,n.on.call("start",e,e.__data__,n.index,n.group),n.state===db){for(n.state=rh,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=fb,1),m=-1,y=a.length;++m<y;)a[m].call(e,g);n.state===fb&&(n.on.call("end",e,e.__data__,n.index,n.group),f())}function f(){n.state=ih,n.timer.stop(),delete r[t];for(var h in r)return;delete e.__transition}}function ah(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>db&&r.state<fb,r.state=ih,r.timer.stop(),r.on.call(a?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[l]}o&&delete e.__transition}}function F7(e){return this.each(function(){ah(this,e)})}function q7(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 H7(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 K7(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?q7:H7)(n,e,t))}function Bx(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 mC(e,t){var n;return(typeof t=="number"?Ci:t instanceof ho?_h:(n=ho(t))?(t=n,_h):lC)(e,t)}function G7(e){return function(){this.removeAttribute(e)}}function V7(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Y7(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 Q7(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 W7(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 X7(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 Z7(e,t){var n=sp(e),r=n==="transform"?M7:mC;return this.attrTween(e,typeof t=="function"?(n.local?X7:W7)(n,r,Bx(this,"attr."+e,t)):t==null?(n.local?V7:G7)(n):(n.local?Q7:Y7)(n,r,t))}function J7(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function eK(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function tK(e,t){var n,r;function a(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&eK(e,o)),n}return a._value=t,a}function nK(e,t){var n,r;function a(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&J7(e,o)),n}return a._value=t,a}function rK(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=sp(e);return this.tween(n,(r.local?tK:nK)(r,t))}function iK(e,t){return function(){Px(this,e).delay=+t.apply(this,arguments)}}function aK(e,t){return t=+t,function(){Px(this,e).delay=t}}function sK(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?iK:aK)(t,e)):gi(this.node(),t).delay}function oK(e,t){return function(){Ii(this,e).duration=+t.apply(this,arguments)}}function lK(e,t){return t=+t,function(){Ii(this,e).duration=t}}function cK(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?oK:lK)(t,e)):gi(this.node(),t).duration}function uK(e,t){if(typeof t!="function")throw new Error;return function(){Ii(this,e).ease=t}}function dK(e){var t=this._id;return arguments.length?this.each(uK(t,e)):gi(this.node(),t).ease}function fK(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ii(this,e).ease=n}}function hK(e){if(typeof e!="function")throw new Error;return this.each(fK(this._id,e))}function pK(e){typeof e!="function"&&(e=Gj(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 ya(r,this._parents,this._name,this._id)}function mK(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 ya(l,this._parents,this._name,this._id)}function gK(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 yK(e,t,n){var r,a,o=gK(t)?Px:Ii;return function(){var l=o(this,e),d=l.on;d!==r&&(a=(r=d).copy()).on(t,n),l.on=a}}function bK(e,t){var n=this._id;return arguments.length<2?gi(this.node(),n).on.on(e):this.each(yK(n,e,t))}function xK(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function vK(){return this.on("end.remove",xK(this._id))}function wK(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Ox(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,lp(h[y],t,n,y,h,gi(g,n)));return new ya(o,this._parents,t,n)}function kK(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Kj(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,k=gi(g,n),v=0,N=y.length;v<N;++v)(b=y[v])&&lp(b,t,n,v,y,k);o.push(y),l.push(g)}return new ya(o,l,t,n)}var EK=td.prototype.constructor;function SK(){return new EK(this._groups,this._parents)}function NK(e,t){var n,r,a;return function(){var o=Bl(this,e),l=(this.style.removeProperty(e),Bl(this,e));return o===l?null:o===n&&l===r?a:a=t(n=o,r=l)}}function gC(e){return function(){this.style.removeProperty(e)}}function _K(e,t,n){var r,a=n+"",o;return function(){var l=Bl(this,e);return l===a?null:l===r?o:o=t(r=l,n)}}function jK(e,t,n){var r,a,o;return function(){var l=Bl(this,e),d=n(this),f=d+"";return d==null&&(f=d=(this.style.removeProperty(e),Bl(this,e))),l===f?null:l===r&&f===a?o:(a=f,o=t(r=l,d))}}function CK(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=gC(t)):void 0;(h!==n||a!==g)&&(r=(n=h).copy()).on(l,a=g),f.on=r}}function AK(e,t,n){var r=(e+="")=="transform"?T7:mC;return t==null?this.styleTween(e,NK(e,r)).on("end.style."+e,gC(e)):typeof t=="function"?this.styleTween(e,jK(e,r,Bx(this,"style."+e,t))).each(CK(this._id,e)):this.styleTween(e,_K(e,r,t),n).on("end.style."+e,null)}function TK(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function MK(e,t,n){var r,a;function o(){var l=t.apply(this,arguments);return l!==a&&(r=(a=l)&&TK(e,l,n)),r}return o._value=t,o}function DK(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,MK(e,t,n??""))}function OK(e){return function(){this.textContent=e}}function RK(e){return function(){var t=e(this);this.textContent=t??""}}function LK(e){return this.tween("text",typeof e=="function"?RK(Bx(this,"text",e)):OK(e==null?"":e+""))}function IK(e){return function(t){this.textContent=e.call(this,t)}}function zK(e){var t,n;function r(){var a=e.apply(this,arguments);return a!==n&&(t=(n=a)&&IK(a)),t}return r._value=e,r}function PK(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,zK(e))}function BK(){for(var e=this._name,t=this._id,n=yC(),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);lp(f,e,n,h,l,{time:g.time+g.delay+g.duration,delay:0,duration:g.duration,ease:g.ease})}return new ya(r,this._parents,e,n)}function $K(){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 UK=0;function ya(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function yC(){return++UK}var ia=td.prototype;ya.prototype={constructor:ya,select:wK,selectAll:kK,selectChild:ia.selectChild,selectChildren:ia.selectChildren,filter:pK,merge:mK,selection:SK,transition:BK,call:ia.call,nodes:ia.nodes,node:ia.node,size:ia.size,empty:ia.empty,each:ia.each,on:bK,attr:Z7,attrTween:rK,style:AK,styleTween:DK,text:LK,textTween:PK,remove:vK,tween:K7,delay:sK,duration:cK,ease:dK,easeVarying:hK,end:$K,[Symbol.iterator]:ia[Symbol.iterator]};function FK(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var qK={time:null,delay:0,duration:250,ease:FK};function HK(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 KK(e){var t,n;e instanceof ya?(t=e._id,e=e._name):(t=yC(),(n=qK).time=zx(),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])&&lp(f,e,t,h,l,n||HK(f,t));return new ya(r,this._parents,e,t)}td.prototype.interrupt=F7;td.prototype.transition=KK;const Ff=e=>()=>e;function GK(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 da(e,t,n){this.k=e,this.x=t,this.y=n}da.prototype={constructor:da,scale:function(e){return e===1?this:new da(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new da(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 cp=new da(1,0,0);bC.prototype=da.prototype;function bC(e){for(;!e.__zoom;)if(!(e=e.parentNode))return cp;return e.__zoom}function uy(e){e.stopImmediatePropagation()}function au(e){e.preventDefault(),e.stopImmediatePropagation()}function VK(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function YK(){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 QE(){return this.__zoom||cp}function QK(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function WK(){return navigator.maxTouchPoints||"ontouchstart"in this}function XK(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 xC(){var e=VK,t=YK,n=XK,r=QK,a=WK,o=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],d=250,f=nh,h=ap("start","zoom","end"),g,m,y,b=500,k=150,v=0,N=10;function E(D){D.property("__zoom",QE).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",F).on("dblclick.zoom",z).filter(a).on("touchstart.zoom",$).on("touchmove.zoom",q).on("touchend.zoom touchcancel.zoom",Y).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}E.transform=function(D,H,O,V){var Q=D.selection?D.selection():D;Q.property("__zoom",QE),D!==Q?M(D,H,O,V):Q.interrupt().each(function(){T(this,arguments).event(V).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},E.scaleBy=function(D,H,O,V){E.scaleTo(D,function(){var Q=this.__zoom.k,K=typeof H=="function"?H.apply(this,arguments):H;return Q*K},O,V)},E.scaleTo=function(D,H,O,V){E.transform(D,function(){var Q=t.apply(this,arguments),K=this.__zoom,I=O==null?_(Q):typeof O=="function"?O.apply(this,arguments):O,P=K.invert(I),G=typeof H=="function"?H.apply(this,arguments):H;return n(S(j(K,G),I,P),Q,l)},O,V)},E.translateBy=function(D,H,O,V){E.transform(D,function(){return n(this.__zoom.translate(typeof H=="function"?H.apply(this,arguments):H,typeof O=="function"?O.apply(this,arguments):O),t.apply(this,arguments),l)},null,V)},E.translateTo=function(D,H,O,V,Q){E.transform(D,function(){var K=t.apply(this,arguments),I=this.__zoom,P=V==null?_(K):typeof V=="function"?V.apply(this,arguments):V;return n(cp.translate(P[0],P[1]).scale(I.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof O=="function"?-O.apply(this,arguments):-O),K,l)},V,Q)};function j(D,H){return H=Math.max(o[0],Math.min(o[1],H)),H===D.k?D:new da(H,D.x,D.y)}function S(D,H,O){var V=H[0]-O[0]*D.k,Q=H[1]-O[1]*D.k;return V===D.x&&Q===D.y?D:new da(D.k,V,Q)}function _(D){return[(+D[0][0]+ +D[1][0])/2,(+D[0][1]+ +D[1][1])/2]}function M(D,H,O,V){D.on("start.zoom",function(){T(this,arguments).event(V).start()}).on("interrupt.zoom end.zoom",function(){T(this,arguments).event(V).end()}).tween("zoom",function(){var Q=this,K=arguments,I=T(Q,K).event(V),P=t.apply(Q,K),G=O==null?_(P):typeof O=="function"?O.apply(Q,K):O,B=Math.max(P[1][0]-P[0][0],P[1][1]-P[0][1]),oe=Q.__zoom,be=typeof H=="function"?H.apply(Q,K):H,xe=f(oe.invert(G).concat(B/oe.k),be.invert(G).concat(B/be.k));return function(we){if(we===1)we=be;else{var J=xe(we),de=B/J[2];we=new da(de,G[0]-J[0]*de,G[1]-J[1]*de)}I.zoom(null,we)}})}function T(D,H,O){return!O&&D.__zooming||new L(D,H)}function L(D,H){this.that=D,this.args=H,this.active=0,this.sourceEvent=null,this.extent=t.apply(D,H),this.taps=0}L.prototype={event:function(D){return D&&(this.sourceEvent=D),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(D,H){return this.mouse&&D!=="mouse"&&(this.mouse[1]=H.invert(this.mouse[0])),this.touch0&&D!=="touch"&&(this.touch0[1]=H.invert(this.touch0[0])),this.touch1&&D!=="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(D){var H=_r(this.that).datum();h.call(D,this.that,new GK(D,{sourceEvent:this.sourceEvent,target:E,transform:this.that.__zoom,dispatch:h}),H)}};function R(D,...H){if(!e.apply(this,arguments))return;var O=T(this,H).event(D),V=this.__zoom,Q=Math.max(o[0],Math.min(o[1],V.k*Math.pow(2,r.apply(this,arguments)))),K=si(D);if(O.wheel)(O.mouse[0][0]!==K[0]||O.mouse[0][1]!==K[1])&&(O.mouse[1]=V.invert(O.mouse[0]=K)),clearTimeout(O.wheel);else{if(V.k===Q)return;O.mouse=[K,V.invert(K)],ah(this),O.start()}au(D),O.wheel=setTimeout(I,k),O.zoom("mouse",n(S(j(V,Q),O.mouse[0],O.mouse[1]),O.extent,l));function I(){O.wheel=null,O.end()}}function F(D,...H){if(y||!e.apply(this,arguments))return;var O=D.currentTarget,V=T(this,H,!0).event(D),Q=_r(D.view).on("mousemove.zoom",G,!0).on("mouseup.zoom",B,!0),K=si(D,O),I=D.clientX,P=D.clientY;nC(D.view),uy(D),V.mouse=[K,this.__zoom.invert(K)],ah(this),V.start();function G(oe){if(au(oe),!V.moved){var be=oe.clientX-I,xe=oe.clientY-P;V.moved=be*be+xe*xe>v}V.event(oe).zoom("mouse",n(S(V.that.__zoom,V.mouse[0]=si(oe,O),V.mouse[1]),V.extent,l))}function B(oe){Q.on("mousemove.zoom mouseup.zoom",null),rC(oe.view,V.moved),au(oe),V.event(oe).end()}}function z(D,...H){if(e.apply(this,arguments)){var O=this.__zoom,V=si(D.changedTouches?D.changedTouches[0]:D,this),Q=O.invert(V),K=O.k*(D.shiftKey?.5:2),I=n(S(j(O,K),V,Q),t.apply(this,H),l);au(D),d>0?_r(this).transition().duration(d).call(M,I,V,D):_r(this).call(E.transform,I,V,D)}}function $(D,...H){if(e.apply(this,arguments)){var O=D.touches,V=O.length,Q=T(this,H,D.changedTouches.length===V).event(D),K,I,P,G;for(uy(D),I=0;I<V;++I)P=O[I],G=si(P,this),G=[G,this.__zoom.invert(G),P.identifier],Q.touch0?!Q.touch1&&Q.touch0[2]!==G[2]&&(Q.touch1=G,Q.taps=0):(Q.touch0=G,K=!0,Q.taps=1+!!g);g&&(g=clearTimeout(g)),K&&(Q.taps<2&&(m=G[0],g=setTimeout(function(){g=null},b)),ah(this),Q.start())}}function q(D,...H){if(this.__zooming){var O=T(this,H).event(D),V=D.changedTouches,Q=V.length,K,I,P,G;for(au(D),K=0;K<Q;++K)I=V[K],P=si(I,this),O.touch0&&O.touch0[2]===I.identifier?O.touch0[0]=P:O.touch1&&O.touch1[2]===I.identifier&&(O.touch1[0]=P);if(I=O.that.__zoom,O.touch1){var B=O.touch0[0],oe=O.touch0[1],be=O.touch1[0],xe=O.touch1[1],we=(we=be[0]-B[0])*we+(we=be[1]-B[1])*we,J=(J=xe[0]-oe[0])*J+(J=xe[1]-oe[1])*J;I=j(I,Math.sqrt(we/J)),P=[(B[0]+be[0])/2,(B[1]+be[1])/2],G=[(oe[0]+xe[0])/2,(oe[1]+xe[1])/2]}else if(O.touch0)P=O.touch0[0],G=O.touch0[1];else return;O.zoom("touch",n(S(I,P,G),O.extent,l))}}function Y(D,...H){if(this.__zooming){var O=T(this,H).event(D),V=D.changedTouches,Q=V.length,K,I;for(uy(D),y&&clearTimeout(y),y=setTimeout(function(){y=null},b),K=0;K<Q;++K)I=V[K],O.touch0&&O.touch0[2]===I.identifier?delete O.touch0:O.touch1&&O.touch1[2]===I.identifier&&delete O.touch1;if(O.touch1&&!O.touch0&&(O.touch0=O.touch1,delete O.touch1),O.touch0)O.touch0[1]=this.__zoom.invert(O.touch0[0]);else if(O.end(),O.taps===2&&(I=si(I,this),Math.hypot(m[0]-I[0],m[1]-I[1])<N)){var P=_r(this).on("dblclick.zoom");P&&P.apply(this,arguments)}}}return E.wheelDelta=function(D){return arguments.length?(r=typeof D=="function"?D:Ff(+D),E):r},E.filter=function(D){return arguments.length?(e=typeof D=="function"?D:Ff(!!D),E):e},E.touchable=function(D){return arguments.length?(a=typeof D=="function"?D:Ff(!!D),E):a},E.extent=function(D){return arguments.length?(t=typeof D=="function"?D:Ff([[+D[0][0],+D[0][1]],[+D[1][0],+D[1][1]]]),E):t},E.scaleExtent=function(D){return arguments.length?(o[0]=+D[0],o[1]=+D[1],E):[o[0],o[1]]},E.translateExtent=function(D){return arguments.length?(l[0][0]=+D[0][0],l[1][0]=+D[1][0],l[0][1]=+D[0][1],l[1][1]=+D[1][1],E):[[l[0][0],l[0][1]],[l[1][0],l[1][1]]]},E.constrain=function(D){return arguments.length?(n=D,E):n},E.duration=function(D){return arguments.length?(d=+D,E):d},E.interpolate=function(D){return arguments.length?(f=D,E):f},E.on=function(){var D=h.on.apply(h,arguments);return D===h?E:D},E.clickDistance=function(D){return arguments.length?(v=(D=+D)*D,E):Math.sqrt(v)},E.tapDistance=function(D){return arguments.length?(N=+D,E):N},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.`},Du=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],vC=["Enter"," ","Escape"],wC={"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 Ul;(function(e){e.Strict="strict",e.Loose="loose"})(Ul||(Ul={}));var oo;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(oo||(oo={}));var Ou;(function(e){e.Partial="partial",e.Full="full"})(Ou||(Ou={}));const kC={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var ss;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(ss||(ss={}));var Th;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Th||(Th={}));var Ke;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(Ke||(Ke={}));const WE={[Ke.Left]:Ke.Right,[Ke.Right]:Ke.Left,[Ke.Top]:Ke.Bottom,[Ke.Bottom]:Ke.Top};function EC(e){return e===null?null:e?"valid":"invalid"}const SC=e=>"id"in e&&"source"in e&&"target"in e,ZK=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),$x=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),rd=(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}},JK=(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):$x(a)?a:t.nodeLookup.get(a.id));const d=l?Mh(l,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return up(r,d)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return dp(n)},id=(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=up(n,Mh(a)),r=!0)}),r?dp(n):{x:0,y:0,width:0,height:0}},Ux=(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:k=!0,hidden:v=!1}=y;if(l&&!k||v)continue;const N=b.width??y.width??y.initialWidth??0,E=b.height??y.height??y.initialHeight??0,{x:j,y:S}=y.internals.positionAbsolute,_=CC(d,f,h,g,j,S,N,E),M=N*E,T=o&&_>0;(!y.internals.handleBounds||T||_>=M||y.dragging)&&m.push(y)}return m},eG=(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 tG(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 nG({nodes:e,width:t,height:n,panZoom:r,minZoom:a,maxZoom:o},l){if(e.size===0)return!0;const d=tG(e,l),f=id(d),h=qx(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 NC({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,k=d.measured.height;b&&k&&(m=[[f,h],[f+b,h+k]])}else d&&go(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=go(m)?mo(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 rG({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),k=!b&&y.parentId&&l.find(v=>v.id===y.parentId);(b||k)&&l.push(y)}const d=new Set(t.map(y=>y.id)),f=r.filter(y=>y.deletable!==!1),g=eG(l,f);for(const y of f)d.has(y.id)&&!g.find(k=>k.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 Fl=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),mo=(e={x:0,y:0},t,n)=>({x:Fl(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:Fl(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function _C(e,t,n){const{width:r,height:a}=va(n),{x:o,y:l}=n.internals.positionAbsolute;return mo(e,[[o,l],[o+r,l+a]],t)}const XE=(e,t,n)=>e<t?Fl(Math.abs(e-t),1,t)/t:e>n?-Fl(Math.abs(e-n),1,t)/t:0,Fx=(e,t,n=15,r=40)=>{const a=XE(e.x,r,t.width-r)*n,o=XE(e.y,r,t.height-r)*n;return[a,o]},up=(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)}),hb=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),dp=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Ru=(e,t=[0,0])=>{var a,o;const{x:n,y:r}=$x(e)?e.internals.positionAbsolute:rd(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}},Mh=(e,t=[0,0])=>{var a,o;const{x:n,y:r}=$x(e)?e.internals.positionAbsolute:rd(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)}},jC=(e,t)=>dp(up(hb(e),hb(t))),CC=(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)},Dh=(e,t)=>CC(e.x,e.y,e.width,e.height,t.x,t.y,t.width,t.height),ZE=e=>li(e.width)&&li(e.height)&&li(e.x)&&li(e.y),li=e=>!isNaN(e)&&isFinite(e),AC=(e,t)=>(n,r)=>{},ad=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),sd=({x:e,y:t},[n,r,a],o=!1,l=[1,1])=>{const d={x:(e-n)/a,y:(t-r)/a};return o?ad(d,l):d},ql=({x:e,y:t},[n,r,a])=>({x:e*a+n,y:t*a+r});function ol(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 iG(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=ol(e,n),a=ol(e,t);return{top:r,right:a,bottom:r,left:a,x:a*2,y:r*2}}if(typeof e=="object"){const r=ol(e.top??e.y??0,n),a=ol(e.bottom??e.y??0,n),o=ol(e.left??e.x??0,t),l=ol(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 aG(e,t,n,r,a,o){const{x:l,y:d}=ql(e,[t,n,r]),{x:f,y:h}=ql({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 qx=(e,t,n,r,a,o)=>{const l=iG(o,t,n),d=(t-l.x)/e.width,f=(n-l.y)/e.height,h=Math.min(d,f),g=Fl(h,r,a),m=e.x+e.width/2,y=e.y+e.height/2,b=t/2-m*g,k=n/2-y*g,v=aG(e,b,k,g,t,n),N={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-N.left+N.right,y:k-N.top+N.bottom,zoom:g}},Lu=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function go(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 TC(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 MC(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 JE(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function sG(){let e,t;return{promise:new Promise((r,a)=>{e=r,t=a}),resolve:e,reject:t}}function oG(e){return{...wC,...e||{}}}function gu(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:a}){const{x:o,y:l}=ci(e),d=sd({x:o-((a==null?void 0:a.left)??0),y:l-((a==null?void 0:a.top)??0)},r),{x:f,y:h}=n?ad(d,t):d;return{xSnapped:f,ySnapped:h,...d}}const Hx=e=>({width:e.offsetWidth,height:e.offsetHeight}),DC=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},lG=["INPUT","SELECT","TEXTAREA"];function OC(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:lG.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const RC=e=>"clientX"in e,ci=(e,t)=>{var o,l;const n=RC(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)}},eS=(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,...Hx(l)}})};function LC({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 qf(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function tS({pos:e,x1:t,y1:n,x2:r,y2:a,c:o}){switch(e){case Ke.Left:return[t-qf(t-r,o),n];case Ke.Right:return[t+qf(r-t,o),n];case Ke.Top:return[t,n-qf(n-a,o)];case Ke.Bottom:return[t,n+qf(a-n,o)]}}function IC({sourceX:e,sourceY:t,sourcePosition:n=Ke.Bottom,targetX:r,targetY:a,targetPosition:o=Ke.Top,curvature:l=.25}){const[d,f]=tS({pos:n,x1:e,y1:t,x2:r,y2:a,c:l}),[h,g]=tS({pos:o,x1:r,y1:a,x2:e,y2:t,c:l}),[m,y,b,k]=LC({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,k]}function zC({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 cG({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 uG({sourceNode:e,targetNode:t,width:n,height:r,transform:a}){const o=up(Mh(e),Mh(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 Dh(l,dp(o))>0}const dG=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,fG=(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)),hG=(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||dG;let a;return SC(e)?a={...e}:a={...e,id:r(e)},fG(a,t)?t:(a.sourceHandle===null&&delete a.sourceHandle,a.targetHandle===null&&delete a.targetHandle,t.concat(a))};function PC({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[a,o,l,d]=zC({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,a,o,l,d]}const nS={[Ke.Left]:{x:-1,y:0},[Ke.Right]:{x:1,y:0},[Ke.Top]:{x:0,y:-1},[Ke.Bottom]:{x:0,y:1}},pG=({source:e,sourcePosition:t=Ke.Bottom,target:n})=>t===Ke.Left||t===Ke.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},rS=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function mG({source:e,sourcePosition:t=Ke.Bottom,target:n,targetPosition:r=Ke.Top,center:a,offset:o,stepPosition:l}){const d=nS[t],f=nS[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=pG({source:h,sourcePosition:t,target:g}),y=m.x!==0?"x":"y",b=m[y];let k=[],v,N;const E={x:0,y:0},j={x:0,y:0},[,,S,_]=zC({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,N=a.y??(h.y+g.y)/2):(v=a.x??(h.x+g.x)/2,N=a.y??h.y+(g.y-h.y)*l);const R=[{x:v,y:h.y},{x:v,y:g.y}],F=[{x:h.x,y:N},{x:g.x,y:N}];d[y]===b?k=y==="x"?R:F:k=y==="x"?F:R}else{const R=[{x:h.x,y:g.y}],F=[{x:g.x,y:h.y}];if(y==="x"?k=d.x===b?F:R:k=d.y===b?R:F,t===r){const D=Math.abs(e[y]-n[y]);if(D<=o){const H=Math.min(o-1,o-D);d[y]===b?E[y]=(h[y]>e[y]?-1:1)*H:j[y]=(g[y]>n[y]?-1:1)*H}}if(t!==r){const D=y==="x"?"y":"x",H=d[y]===f[D],O=h[D]>g[D],V=h[D]<g[D];(d[y]===1&&(!H&&O||H&&V)||d[y]!==1&&(!H&&V||H&&O))&&(k=y==="x"?R:F)}const z={x:h.x+E.x,y:h.y+E.y},$={x:g.x+j.x,y:g.y+j.y},q=Math.max(Math.abs(z.x-k[0].x),Math.abs($.x-k[0].x)),Y=Math.max(Math.abs(z.y-k[0].y),Math.abs($.y-k[0].y));q>=Y?(v=(z.x+$.x)/2,N=k[0].y):(v=k[0].x,N=(z.y+$.y)/2)}const M={x:h.x+E.x,y:h.y+E.y},T={x:g.x+j.x,y:g.y+j.y};return[[e,...M.x!==k[0].x||M.y!==k[0].y?[M]:[],...k,...T.x!==k[k.length-1].x||T.y!==k[k.length-1].y?[T]:[],n],v,N,S,_]}function gG(e,t,n,r){const a=Math.min(rS(e,t)/2,rS(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 pb({sourceX:e,sourceY:t,sourcePosition:n=Ke.Bottom,targetX:r,targetY:a,targetPosition:o=Ke.Top,borderRadius:l=5,centerX:d,centerY:f,offset:h=20,stepPosition:g=.5}){const[m,y,b,k,v]=mG({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:a},targetPosition:o,center:{x:d,y:f},offset:h,stepPosition:g});let N=`M${m[0].x} ${m[0].y}`;for(let E=1;E<m.length-1;E++)N+=gG(m[E-1],m[E],m[E+1],l);return N+=`L${m[m.length-1].x} ${m[m.length-1].y}`,[N,y,b,k,v]}function iS(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function yG(e){var m;const{sourceNode:t,targetNode:n}=e;if(!iS(t)||!iS(n))return null;const r=t.internals.handleBounds||aS(t.handles),a=n.internals.handleBounds||aS(n.handles),o=sS((r==null?void 0:r.source)??[],e.sourceHandle),l=sS(e.connectionMode===Ul.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)||Ke.Bottom,f=(l==null?void 0:l.position)||Ke.Top,h=yo(t,o,d),g=yo(n,l,f);return{sourceX:h.x,sourceY:h.y,targetX:g.x,targetY:g.y,sourcePosition:d,targetPosition:f}}function aS(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 yo(e,t,n=Ke.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 Ke.Top:return{x:a+l/2,y:o};case Ke.Right:return{x:a+l,y:o+d/2};case Ke.Bottom:return{x:a+l/2,y:o+d};case Ke.Left:return{x:a,y:o+d/2}}}function sS(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function mb(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function bG(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=mb(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 BC=1e3,xG=10,Kx={nodeOrigin:[0,0],nodeExtent:Du,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},vG={...Kx,checkEquality:!0};function Gx(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function wG(e,t,n){const r=Gx(Kx,n);for(const a of e.values())if(a.parentId)Yx(a,e,t,r);else{const o=rd(a,r.nodeOrigin),l=go(a.extent)?a.extent:r.nodeExtent,d=mo(o,l,va(a));a.internals.positionAbsolute=d}}function kG(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 Vx(e){return e==="manual"}function gb(e,t,n,r={}){var g,m;const a=Gx(vG,r),o={i:0},l=new Map(t),d=a!=null&&a.elevateNodesOnSelect&&!Vx(a.zIndexMode)?BC: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 k=rd(y,a.nodeOrigin),v=go(y.extent)?y.extent:a.nodeExtent,N=mo(k,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:N,handleBounds:kG(y,b),z:$C(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&&Yx(b,t,n,r,o),h||(h=y.selected??!1)}return{nodesInitialized:f,hasSelectedNodes:h}}function EG(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 Yx(e,t,n,r,a){const{elevateNodesOnSelect:o,nodeOrigin:l,nodeExtent:d,zIndexMode:f}=Gx(Kx,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}EG(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*xG),a&&g.internals.rootParentIndex!==void 0&&(a.i=g.internals.rootParentIndex);const m=o&&!Vx(f)?BC:0,{x:y,y:b,z:k}=SG(e,g,l,d,m,f),{positionAbsolute:v}=e.internals,N=y!==v.x||b!==v.y;(N||k!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:N?{x:y,y:b}:v,z:k}})}function $C(e,t,n){const r=li(e.zIndex)?e.zIndex:0;return Vx(n)?r:r+(e.selected?t:0)}function SG(e,t,n,r,a,o){const{x:l,y:d}=t.internals.positionAbsolute,f=va(e),h=rd(e,n),g=go(e.extent)?mo(h,e.extent,f):h;let m=mo({x:l+g.x,y:d+g.y},r,f);e.extent==="parent"&&(m=_C(m,f,t));const y=$C(e,a,o),b=t.internals.z??0;return{x:m.x,y:m.y,z:b>=y?b+1:y}}function Qx(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)??Ru(f),g=jC(h,d.rect);o.set(d.parentId,{expandedRect:g,parent:f})}return o.size>0&&o.forEach(({expandedRect:d,parent:f},h)=>{var S;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,k=d.y<g.y?Math.round(Math.abs(g.y-d.y)):0,v=Math.max(m.width,Math.round(d.width)),N=Math.max(m.height,Math.round(d.height)),E=(v-m.width)*y[0],j=(N-m.height)*y[1];(b>0||k>0||E||j)&&(a.push({id:h,type:"position",position:{x:f.position.x-b+E,y:f.position.y-k+j}}),(S=n.get(h))==null||S.forEach(_=>{e.some(M=>M.id===_.id)||a.push({id:_.id,type:"position",position:{x:_.position.x+b,y:_.position.y+k}})})),(m.width<d.width||m.height<d.height||b||k)&&a.push({id:h,type:"dimensions",setAttributes:!0,dimensions:{width:v+(b?y[0]*b-E:0),height:N+(k?y[1]*k-j:0)}})}),a}function NG(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 k=t.get(b.id);if(!k)continue;if(k.hidden){t.set(k.id,{...k,internals:{...k.internals,handleBounds:void 0}}),f=!0;continue}const v=Hx(b.nodeElement),N=k.measured.width!==v.width||k.measured.height!==v.height;if(!!(v.width&&v.height&&(N||!k.internals.handleBounds||b.force))){const j=b.nodeElement.getBoundingClientRect(),S=go(k.extent)?k.extent:o;let{positionAbsolute:_}=k.internals;k.parentId&&k.extent==="parent"?_=_C(_,v,t.get(k.parentId)):S&&(_=mo(_,S,v));const M={...k,measured:v,internals:{...k.internals,positionAbsolute:_,handleBounds:{source:eS("source",b.nodeElement,j,m,k.id),target:eS("target",b.nodeElement,j,m,k.id)}}};t.set(k.id,M),k.parentId&&Yx(M,t,n,{nodeOrigin:a,zIndexMode:l}),f=!0,N&&(h.push({id:k.id,type:"dimensions",dimensions:v}),k.expandParent&&k.parentId&&y.push({id:k.id,parentId:k.parentId,rect:Ru(M,a)}))}}if(y.length>0){const b=Qx(y,t,n,a);h.push(...b)}return{changes:h,updatedInternals:f}}async function _G({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 oS(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 UC(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}`;oS("source",f,g,e,a,l),oS("target",f,h,e,o,d),t.set(r.id,r)}}function FC(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:FC(n,t):!1}function lS(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 jG(e,t,n,r){const a=new Map;for(const[o,l]of e)if((l.selected||l.id===r)&&(!l.parentId||!FC(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 dy({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 CG({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=ad(o,t);return{x:l.x-o.x,y:l.y-o.y}}function AG({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,k=!1,v=null;function N({noDragClassName:j,handleSelector:S,domNode:_,isSelectable:M,nodeId:T,nodeClickDistance:L=0}){y=_r(_);function R({x:q,y:Y}){const{nodeLookup:D,nodeExtent:H,snapGrid:O,snapToGrid:V,nodeOrigin:Q,onNodeDrag:K,onSelectionDrag:I,onError:P,updateNodePositions:G}=t();o={x:q,y:Y};let B=!1;const oe=d.size>1,be=oe&&H?hb(id(d)):null,xe=oe&&V?CG({dragItems:d,snapGrid:O,x:q,y:Y}):null;for(const[we,J]of d){if(!D.has(we))continue;let de={x:q-J.distance.x,y:Y-J.distance.y};V&&(de=xe?{x:Math.round(de.x+xe.x),y:Math.round(de.y+xe.y)}:ad(de,O));let Ce=null;if(oe&&H&&!J.extent&&be){const{positionAbsolute:le}=J.internals,Ne=le.x-be.x+H[0][0],Te=le.x+J.measured.width-be.x2+H[1][0],ke=le.y-be.y+H[0][1],We=le.y+J.measured.height-be.y2+H[1][1];Ce=[[Ne,ke],[Te,We]]}const{position:Re,positionAbsolute:De}=NC({nodeId:we,nextPosition:de,nodeLookup:D,nodeExtent:Ce||H,nodeOrigin:Q,onError:P});B=B||J.position.x!==Re.x||J.position.y!==Re.y,J.position=Re,J.internals.positionAbsolute=De}if(k=k||B,!!B&&(G(d,!0),v&&(r||K||!T&&I))){const[we,J]=dy({nodeId:T,dragItems:d,nodeLookup:D});r==null||r(v,d,we,J),K==null||K(v,we,J),T||I==null||I(v,J)}}async function F(){if(!g)return;const{transform:q,panBy:Y,autoPanSpeed:D,autoPanOnNodeDrag:H}=t();if(!H){f=!1,cancelAnimationFrame(l);return}const[O,V]=Fx(h,g,D);(O!==0||V!==0)&&(o.x=(o.x??0)-O/q[2],o.y=(o.y??0)-V/q[2],await Y({x:O,y:V})&&R(o)),l=requestAnimationFrame(F)}function z(q){var oe;const{nodeLookup:Y,multiSelectionActive:D,nodesDraggable:H,transform:O,snapGrid:V,snapToGrid:Q,selectNodesOnDrag:K,onNodeDragStart:I,onSelectionDragStart:P,unselectNodesAndEdges:G}=t();m=!0,(!K||!M)&&!D&&T&&((oe=Y.get(T))!=null&&oe.selected||G()),M&&K&&T&&(e==null||e(T));const B=gu(q.sourceEvent,{transform:O,snapGrid:V,snapToGrid:Q,containerBounds:g});if(o=B,d=jG(Y,H,B,T),d.size>0&&(n||I||!T&&P)){const[be,xe]=dy({nodeId:T,dragItems:d,nodeLookup:Y});n==null||n(q.sourceEvent,d,be,xe),I==null||I(q.sourceEvent,be,xe),T||P==null||P(q.sourceEvent,xe)}}const $=iC().clickDistance(L).on("start",q=>{const{domNode:Y,nodeDragThreshold:D,transform:H,snapGrid:O,snapToGrid:V}=t();g=(Y==null?void 0:Y.getBoundingClientRect())||null,b=!1,k=!1,v=q.sourceEvent,D===0&&z(q),o=gu(q.sourceEvent,{transform:H,snapGrid:O,snapToGrid:V,containerBounds:g}),h=ci(q.sourceEvent,g)}).on("drag",q=>{const{autoPanOnNodeDrag:Y,transform:D,snapGrid:H,snapToGrid:O,nodeDragThreshold:V,nodeLookup:Q}=t(),K=gu(q.sourceEvent,{transform:D,snapGrid:H,snapToGrid:O,containerBounds:g});if(v=q.sourceEvent,(q.sourceEvent.type==="touchmove"&&q.sourceEvent.touches.length>1||T&&!Q.has(T))&&(b=!0),!b){if(!f&&Y&&m&&(f=!0,F()),!m){const I=ci(q.sourceEvent,g),P=I.x-h.x,G=I.y-h.y;Math.sqrt(P*P+G*G)>V&&z(q)}(o.x!==K.xSnapped||o.y!==K.ySnapped)&&d&&m&&(h=ci(q.sourceEvent,g),R(K))}}).on("end",q=>{if(!m||b){b&&d.size>0&&t().updateNodePositions(d,!1);return}if(f=!1,m=!1,cancelAnimationFrame(l),d.size>0){const{nodeLookup:Y,updateNodePositions:D,onNodeDragStop:H,onSelectionDragStop:O}=t();if(k&&(D(d,!1),k=!1),a||H||!T&&O){const[V,Q]=dy({nodeId:T,dragItems:d,nodeLookup:Y,dragging:!1});a==null||a(q.sourceEvent,d,V,Q),H==null||H(q.sourceEvent,V,Q),T||O==null||O(q.sourceEvent,Q)}}}).filter(q=>{const Y=q.target;return!q.button&&(!j||!lS(Y,`.${j}`,_))&&(!S||lS(Y,S,_))});y.call($)}function E(){y==null||y.on(".drag",null)}return{update:N,destroy:E}}function TG(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())Dh(a,Ru(o))>0&&r.push(o);return r}const MG=250;function DG(e,t,n,r){var d,f;let a=[],o=1/0;const l=TG(e,n,t+MG);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}=yo(h,m,m.position,!0),k=Math.sqrt(Math.pow(y-e.x,2)+Math.pow(b-e.y,2));k>t||(k<o?(a=[{...m,x:y,y:b}],o=k):k===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 qC(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,...yo(l,f,f.position,!0)}:f}function HC(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function OG(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const KC=()=>!0;function RG(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:k,onConnect:v,onConnectEnd:N,isValidConnection:E=KC,onReconnectEnd:j,updateConnection:S,getTransform:_,getFromHandle:M,autoPanSpeed:T,dragThreshold:L=1,handleDomNode:R}){const F=DC(e.target);let z=0,$;const{x:q,y:Y}=ci(e),D=HC(o,R),H=d==null?void 0:d.getBoundingClientRect();let O=!1;if(!H||!D)return;const V=qC(a,D,r,f,t);if(!V)return;let Q=ci(e,H),K=!1,I=null,P=!1,G=null;function B(){if(!g||!H)return;const[Re,De]=Fx(Q,H,T);y({x:Re,y:De}),z=requestAnimationFrame(B)}const oe={...V,nodeId:a,type:D,position:V.position},be=f.get(a);let we={inProgress:!0,isValid:null,from:yo(be,oe,Ke.Left,!0),fromHandle:oe,fromPosition:oe.position,fromNode:be,to:Q,toHandle:null,toPosition:WE[oe.position],toNode:null,pointer:Q};function J(){O=!0,S(we),k==null||k(e,{nodeId:a,handleId:r,handleType:D})}L===0&&J();function de(Re){if(!O){const{x:We,y:re}=ci(Re),Ae=We-q,ue=re-Y;if(!(Ae*Ae+ue*ue>L*L))return;J()}if(!M()||!oe){Ce(Re);return}const De=_();Q=ci(Re,H),$=DG(sd(Q,De,!1,[1,1]),n,f,oe),K||(B(),K=!0);const le=GC(Re,{handle:$,connectionMode:t,fromNodeId:a,fromHandleId:r,fromType:l?"target":"source",isValidConnection:E,doc:F,lib:h,flowId:m,nodeLookup:f});G=le.handleDomNode,I=le.connection,P=OG(!!$,le.isValid);const Ne=f.get(a),Te=Ne?yo(Ne,oe,Ke.Left,!0):we.from,ke={...we,from:Te,isValid:P,to:le.toHandle&&P?ql({x:le.toHandle.x,y:le.toHandle.y},De):Q,toHandle:le.toHandle,toPosition:P&&le.toHandle?le.toHandle.position:WE[oe.position],toNode:le.toHandle?f.get(le.toHandle.nodeId):null,pointer:Q};S(ke),we=ke}function Ce(Re){if(!("touches"in Re&&Re.touches.length>0)){if(O){($||G)&&I&&P&&(v==null||v(I));const{inProgress:De,...le}=we,Ne={...le,toPosition:we.toHandle?we.toPosition:null};N==null||N(Re,Ne),o&&(j==null||j(Re,Ne))}b(),cancelAnimationFrame(z),K=!1,P=!1,I=null,G=null,F.removeEventListener("mousemove",de),F.removeEventListener("mouseup",Ce),F.removeEventListener("touchmove",de),F.removeEventListener("touchend",Ce)}}F.addEventListener("mousemove",de),F.addEventListener("mouseup",Ce),F.addEventListener("touchmove",de),F.addEventListener("touchend",Ce)}function GC(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:a,fromType:o,doc:l,lib:d,flowId:f,isValidConnection:h=KC,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:k}=ci(e),v=l.elementFromPoint(b,k),N=v!=null&&v.classList.contains(`${d}-flow__handle`)?v:y,E={handleDomNode:N,isValid:!1,connection:null,toHandle:null};if(N){const j=HC(void 0,N),S=N.getAttribute("data-nodeid"),_=N.getAttribute("data-handleid"),M=N.classList.contains("connectable"),T=N.classList.contains("connectableend");if(!S||!j)return E;const L={source:m?S:r,sourceHandle:m?_:a,target:m?r:S,targetHandle:m?a:_};E.connection=L;const F=M&&T&&(n===Ul.Strict?m&&j==="source"||!m&&j==="target":S!==r||_!==a);E.isValid=F&&h(L),E.toHandle=qC(S,j,_,g,n,!0)}return E}const yb={onPointerDown:RG,isValid:GC};function LG({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 k=S=>{if(S.sourceEvent.type!=="wheel"||!t)return;const _=n(),M=S.sourceEvent.ctrlKey&&Lu()?10:1,T=-S.sourceEvent.deltaY*(S.sourceEvent.deltaMode===1?.05:S.sourceEvent.deltaMode?1:.002)*g,L=_[2]*Math.pow(2,T*M);t.scaleTo(L)};let v=[0,0];const N=S=>{(S.sourceEvent.type==="mousedown"||S.sourceEvent.type==="touchstart")&&(v=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY])},E=S=>{const _=n();if(S.sourceEvent.type!=="mousemove"&&S.sourceEvent.type!=="touchmove"||!t)return;const M=[S.sourceEvent.clientX??S.sourceEvent.touches[0].clientX,S.sourceEvent.clientY??S.sourceEvent.touches[0].clientY],T=[M[0]-v[0],M[1]-v[1]];v=M;const L=r()*Math.max(_[2],Math.log(_[2]))*(b?-1:1),R={x:_[0]-T[0]*L,y:_[1]-T[1]*L},F=[[0,0],[f,h]];t.setViewportConstrained({x:R.x,y:R.y,zoom:_[2]},F,d)},j=xC().on("start",N).on("zoom",m?E:null).on("zoom.wheel",y?k:null);a.call(j,{})}function l(){a.on("zoom",null)}return{update:o,destroy:l,pointer:si}}const fp=e=>({x:e.x,y:e.y,zoom:e.k}),fy=({x:e,y:t,zoom:n})=>cp.translate(e,t).scale(n),gl=(e,t)=>e.target.closest(`.${t}`),VC=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),IG=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,hy=(e,t=0,n=IG,r=()=>{})=>{const a=typeof t=="number"&&t>0;return a||r(),a?e.transition().duration(t).ease(n).on("end",r):e},YC=e=>{const t=e.ctrlKey&&Lu()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function zG({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:a,panOnScrollSpeed:o,zoomOnPinch:l,onPanZoomStart:d,onPanZoom:f,onPanZoomEnd:h}){return g=>{if(gl(g,t))return g.ctrlKey&&g.preventDefault(),!1;g.preventDefault(),g.stopImmediatePropagation();const m=n.property("__zoom").k||1;if(g.ctrlKey&&l){const N=si(g),E=YC(g),j=m*Math.pow(2,E);r.scaleTo(n,j,N,g);return}const y=g.deltaMode===1?20:1;let b=a===oo.Vertical?0:g.deltaX*y,k=a===oo.Horizontal?0:g.deltaY*y;!Lu()&&g.shiftKey&&a!==oo.Vertical&&(b=g.deltaY*y,k=0),r.translateBy(n,-(b/m)*o,-(k/m)*o,{internal:!0});const v=fp(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 PG({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,a){const o=r.type==="wheel",l=!t&&o&&!r.ctrlKey,d=gl(r,e);if(r.ctrlKey&&o&&d&&r.preventDefault(),l||d)return null;r.preventDefault(),n.call(this,r,a)}}function BG({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{var o,l,d;if((o=r.sourceEvent)!=null&&o.internal)return;const a=fp(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 $G({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:a}){return o=>{var l,d;e.usedRightMouseButton=!!(n&&VC(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,fp(o.transform)))}}function UG({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&&VC(t,e.mouseButton??0)&&!e.usedRightMouseButton&&l.sourceEvent&&o(l.sourceEvent),e.usedRightMouseButton=!1,r(!1),a)){const f=fp(l.transform);e.prevViewport=f,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{a==null||a(l.sourceEvent,f)},n?150:0)}}}function FG({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 N;const y=e||t,b=n&&m.ctrlKey,k=m.type==="wheel";if(m.button===1&&m.type==="mousedown"&&(gl(m,`${h}-flow__node`)||gl(m,`${h}-flow__edge`)))return!0;if(!r&&!y&&!a&&!o&&!n||l||g&&!k||gl(m,d)&&k||gl(m,f)&&(!k||a&&k&&!e)||!n&&m.ctrlKey&&k)return!1;if(!n&&m.type==="touchstart"&&((N=m.touches)==null?void 0:N.length)>1)return m.preventDefault(),!1;if(!y&&!a&&!b&&k||!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||k)&&v}}function qG({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=xC().scaleExtent([t,n]).translateExtent(r),y=_r(e).call(m);j({x:a.x,y:a.y,zoom:Fl(a.zoom,t,n)},[[0,0],[g.width,g.height]],r);const b=y.on("wheel.zoom"),k=y.on("dblclick.zoom");m.wheelDelta(YC);async function v($,q){return y?new Promise(Y=>{m==null||m.interpolate((q==null?void 0:q.interpolate)==="linear"?mu:nh).transform(hy(y,q==null?void 0:q.duration,q==null?void 0:q.ease,()=>Y(!0)),$)}):!1}function N({noWheelClassName:$,noPanClassName:q,onPaneContextMenu:Y,userSelectionActive:D,panOnScroll:H,panOnDrag:O,panOnScrollMode:V,panOnScrollSpeed:Q,preventScrolling:K,zoomOnPinch:I,zoomOnScroll:P,zoomOnDoubleClick:G,zoomActivationKeyPressed:B,lib:oe,onTransformChange:be,connectionInProgress:xe,paneClickDistance:we,selectionOnDrag:J}){D&&!h.isZoomingOrPanning&&E();const de=H&&!B&&!D;m.clickDistance(J?1/0:!li(we)||we<0?0:we);const Ce=de?zG({zoomPanValues:h,noWheelClassName:$,d3Selection:y,d3Zoom:m,panOnScrollMode:V,panOnScrollSpeed:Q,zoomOnPinch:I,onPanZoomStart:l,onPanZoom:o,onPanZoomEnd:d}):PG({noWheelClassName:$,preventScrolling:K,d3ZoomHandler:b});y.on("wheel.zoom",Ce,{passive:!1});const Re=BG({zoomPanValues:h,onDraggingChange:f,onPanZoomStart:l});m.on("start",Re);const De=$G({zoomPanValues:h,panOnDrag:O,onPaneContextMenu:!!Y,onPanZoom:o,onTransformChange:be});m.on("zoom",De);const le=UG({zoomPanValues:h,panOnDrag:O,panOnScroll:H,onPaneContextMenu:Y,onPanZoomEnd:d,onDraggingChange:f});m.on("end",le);const Ne=FG({zoomActivationKeyPressed:B,panOnDrag:O,zoomOnScroll:P,panOnScroll:H,zoomOnDoubleClick:G,zoomOnPinch:I,userSelectionActive:D,noPanClassName:q,noWheelClassName:$,lib:oe,connectionInProgress:xe});m.filter(Ne),G?y.on("dblclick.zoom",k):y.on("dblclick.zoom",null)}function E(){m.on("zoom",null)}async function j($,q,Y){const D=fy($),H=m==null?void 0:m.constrain()(D,q,Y);return H&&await v(H),H}async function S($,q){const Y=fy($);return await v(Y,q),Y}function _($){if(y){const q=fy($),Y=y.property("__zoom");(Y.k!==$.zoom||Y.x!==$.x||Y.y!==$.y)&&(m==null||m.transform(y,q,null,{sync:!0}))}}function M(){const $=y?bC(y.node()):{x:0,y:0,k:1};return{x:$.x,y:$.y,zoom:$.k}}async function T($,q){return y?new Promise(Y=>{m==null||m.interpolate((q==null?void 0:q.interpolate)==="linear"?mu:nh).scaleTo(hy(y,q==null?void 0:q.duration,q==null?void 0:q.ease,()=>Y(!0)),$)}):!1}async function L($,q){return y?new Promise(Y=>{m==null||m.interpolate((q==null?void 0:q.interpolate)==="linear"?mu:nh).scaleBy(hy(y,q==null?void 0:q.duration,q==null?void 0:q.ease,()=>Y(!0)),$)}):!1}function R($){m==null||m.scaleExtent($)}function F($){m==null||m.translateExtent($)}function z($){const q=!li($)||$<0?0:$;m==null||m.clickDistance(q)}return{update:N,destroy:E,setViewport:S,setViewportConstrained:j,getViewport:M,scaleTo:T,scaleBy:L,setScaleExtent:R,setTranslateExtent:F,syncViewport:_,setClickDistance:z}}var Hl;(function(e){e.Line="line",e.Handle="handle"})(Hl||(Hl={}));function HG({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 cS(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 ns(e,t){return Math.max(0,t-e)}function rs(e,t){return Math.max(0,e-t)}function Hf(e,t,n){return Math.max(0,t-e,e-n)}function uS(e,t){return e?!t:t}function KG(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:k}=n,{minWidth:v,maxWidth:N,minHeight:E,maxHeight:j}=r,{x:S,y:_,width:M,height:T,aspectRatio:L}=e;let R=Math.floor(g?b-e.pointerX:0),F=Math.floor(m?k-e.pointerY:0);const z=M+(f?-R:R),$=T+(h?-F:F),q=-o[0]*M,Y=-o[1]*T;let D=Hf(z,v,N),H=Hf($,E,j);if(l){let Q=0,K=0;f&&R<0?Q=ns(S+R+q,l[0][0]):!f&&R>0&&(Q=rs(S+z+q,l[1][0])),h&&F<0?K=ns(_+F+Y,l[0][1]):!h&&F>0&&(K=rs(_+$+Y,l[1][1])),D=Math.max(D,Q),H=Math.max(H,K)}if(d){let Q=0,K=0;f&&R>0?Q=rs(S+R,d[0][0]):!f&&R<0&&(Q=ns(S+z,d[1][0])),h&&F>0?K=rs(_+F,d[0][1]):!h&&F<0&&(K=ns(_+$,d[1][1])),D=Math.max(D,Q),H=Math.max(H,K)}if(a){if(g){const Q=Hf(z/L,E,j)*L;if(D=Math.max(D,Q),l){let K=0;!f&&!h||f&&!h&&y?K=rs(_+Y+z/L,l[1][1])*L:K=ns(_+Y+(f?R:-R)/L,l[0][1])*L,D=Math.max(D,K)}if(d){let K=0;!f&&!h||f&&!h&&y?K=ns(_+z/L,d[1][1])*L:K=rs(_+(f?R:-R)/L,d[0][1])*L,D=Math.max(D,K)}}if(m){const Q=Hf($*L,v,N)/L;if(H=Math.max(H,Q),l){let K=0;!f&&!h||h&&!f&&y?K=rs(S+$*L+q,l[1][0])/L:K=ns(S+(h?F:-F)*L+q,l[0][0])/L,H=Math.max(H,K)}if(d){let K=0;!f&&!h||h&&!f&&y?K=ns(S+$*L,d[1][0])/L:K=rs(S+(h?F:-F)*L,d[0][0])/L,H=Math.max(H,K)}}}F=F+(F<0?H:-H),R=R+(R<0?D:-D),a&&(y?z>$*L?F=(uS(f,h)?-R:R)/L:R=(uS(f,h)?-F:F)*L:g?(F=R/L,h=f):(R=F*L,f=h));const O=f?S+R:S,V=h?_+F:_;return{width:M+(f?-R:R),height:T+(h?-F:F),x:o[0]*R*(f?-1:1)+O,y:o[1]*F*(h?-1:1)+V}}const QC={width:0,height:0,x:0,y:0},GG={...QC,pointerX:0,pointerY:0,aspectRatio:1};function VG(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 YG({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:a}){const o=_r(e);let l={controlDirection:cS("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:k,onResizeEnd:v,shouldResize:N}){let E={...QC},j={...GG};l={boundaries:g,resizeDirection:y,keepAspectRatio:m,controlDirection:cS(h)};let S,_=null,M=[],T,L,R,F=!1;const z=iC().on("start",$=>{const{nodeLookup:q,transform:Y,snapGrid:D,snapToGrid:H,nodeOrigin:O,paneDomNode:V}=n();if(S=q.get(t),!S)return;_=(V==null?void 0:V.getBoundingClientRect())??null;const{xSnapped:Q,ySnapped:K}=gu($.sourceEvent,{transform:Y,snapGrid:D,snapToGrid:H,containerBounds:_});E={width:S.measured.width??0,height:S.measured.height??0,x:S.position.x??0,y:S.position.y??0},j={...E,pointerX:Q,pointerY:K,aspectRatio:E.width/E.height},T=void 0,L=go(S.extent)?S.extent:void 0,S.parentId&&(S.extent==="parent"||S.expandParent)&&(T=q.get(S.parentId)),T&&S.extent==="parent"&&(L=[[0,0],[T.measured.width,T.measured.height]]),M=[],R=void 0;for(const[I,P]of q)if(P.parentId===t&&(M.push({id:I,position:{...P.position},extent:P.extent}),P.extent==="parent"||P.expandParent)){const G=VG(P,S,P.origin??O);R?R=[[Math.min(G[0][0],R[0][0]),Math.min(G[0][1],R[0][1])],[Math.max(G[1][0],R[1][0]),Math.max(G[1][1],R[1][1])]]:R=G}b==null||b($,{...E})}).on("drag",$=>{const{transform:q,snapGrid:Y,snapToGrid:D,nodeOrigin:H}=n(),O=gu($.sourceEvent,{transform:q,snapGrid:Y,snapToGrid:D,containerBounds:_}),V=[];if(!S)return;const{x:Q,y:K,width:I,height:P}=E,G={},B=S.origin??H,{width:oe,height:be,x:xe,y:we}=KG(j,l.controlDirection,O,l.boundaries,l.keepAspectRatio,B,L,R),J=oe!==I,de=be!==P,Ce=xe!==Q&&J,Re=we!==K&&de;if(!Ce&&!Re&&!J&&!de)return;if((Ce||Re||B[0]===1||B[1]===1)&&(G.x=Ce?xe:E.x,G.y=Re?we:E.y,E.x=G.x,E.y=G.y,M.length>0)){const Te=xe-Q,ke=we-K;for(const We of M)We.position={x:We.position.x-Te+B[0]*(oe-I),y:We.position.y-ke+B[1]*(be-P)},V.push(We)}if((J||de)&&(G.width=J&&(!l.resizeDirection||l.resizeDirection==="horizontal")?oe:E.width,G.height=de&&(!l.resizeDirection||l.resizeDirection==="vertical")?be:E.height,E.width=G.width,E.height=G.height),T&&S.expandParent){const Te=B[0]*(G.width??0);G.x&&G.x<Te&&(E.x=Te,j.x=j.x-(G.x-Te));const ke=B[1]*(G.height??0);G.y&&G.y<ke&&(E.y=ke,j.y=j.y-(G.y-ke))}const De=HG({width:E.width,prevWidth:I,height:E.height,prevHeight:P,affectsX:l.controlDirection.affectsX,affectsY:l.controlDirection.affectsY}),le={...E,direction:De};(N==null?void 0:N($,le))!==!1&&(F=!0,k==null||k($,le),r(G,V))}).on("end",$=>{F&&(v==null||v($,{...E}),a==null||a({...E}),F=!1)});o.call(z)}function f(){o.on(".drag",null)}return{update:d,destroy:f}}var py={exports:{}},my={},gy={exports:{}},yy={};/**
@@ -7,7 +7,7 @@
7
7
  <link rel="preconnect" href="https://fonts.googleapis.com">
8
8
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
9
  <link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
10
- <script type="module" crossorigin src="/assets/index-B_KG6-po.js"></script>
10
+ <script type="module" crossorigin src="/assets/index-DlBZNsFw.js"></script>
11
11
  <link rel="stylesheet" crossorigin href="/assets/index-DVnv2TaM.css">
12
12
  </head>
13
13
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralai/sps-cli",
3
- "version": "0.58.4",
3
+ "version": "0.58.5",
4
4
  "description": "SPS CLI — AI-driven development pipeline orchestrator",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",