@coralai/sps-cli 0.50.18 → 0.50.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -474,9 +474,9 @@ ${n.comment}`:n.comment}this.doc.range[2]=n.offset;break}default:this.errors.pus
474
474
  ${g.join(`
475
475
  `)}`:"项目已删除。"}).then(()=>n("/projects"))},onError:y=>{s({title:"删除失败",body:y instanceof Error?y.message:String(y)})}});return m.jsxs("div",{className:"nb-card bg-[var(--color-crashed-bg)]",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-lg font-bold mb-2 text-[var(--color-crashed)]",children:"删除项目"}),m.jsxs("p",{className:"text-sm mb-4",children:["这会清理 ",m.jsxs("code",{className:"font-[family-name:var(--font-mono)] bg-[var(--color-bg)] border-2 border-[var(--color-text)] px-1.5 py-0.5 rounded",children:["~/.coral/projects/",e,"/"]}),"(包括所有卡片、runtime、logs)。"]}),t&&m.jsxs("label",{className:"flex items-start gap-2 mb-4 p-3 bg-[var(--color-bg)] border-2 border-[var(--color-text)] rounded-lg cursor-pointer",children:[m.jsx("input",{type:"checkbox",checked:f,onChange:y=>d(y.target.checked),className:"mt-0.5"}),m.jsxs("div",{className:"flex-1",children:[m.jsx("div",{className:"text-sm font-bold",children:"同时清理 repo 的 .claude/"}),m.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:[t,"/.claude/"]}),m.jsx("div",{className:"text-xs text-[var(--color-text-muted)] mt-1",children:"repo 本身不动,只清这个目录。"})]})]}),m.jsx("div",{className:"mb-4",children:m.jsxs("label",{className:"flex flex-col gap-1.5",children:[m.jsxs("span",{className:"text-sm font-bold",children:["输入项目名 ",m.jsx("code",{className:"font-[family-name:var(--font-mono)] text-xs",children:e})," 确认:"]}),m.jsx("input",{type:"text",className:"nb-input w-full font-[family-name:var(--font-mono)]",value:o,onChange:y=>c(y.target.value),placeholder:e})]})}),m.jsxs("button",{type:"button",className:"nb-btn nb-btn-danger",disabled:o!==e||h.isPending,onClick:()=>h.mutate(),"aria-label":"永久删除项目",children:[h.isPending?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):m.jsx(Il,{size:14,strokeWidth:3}),"永久删除"]})]})}function lg(e){const t=e?`?project=${encodeURIComponent(e)}`:"";return qt(`/api/skills${t}`)}function zO(e){return qt(`/api/skills/${encodeURIComponent(e)}`)}function BO(e,t){return qt(`/api/skills/${encodeURIComponent(e)}/references/${encodeURIComponent(t)}`)}async function Yf(e,t){const n=await fetch(e,{method:"POST",headers:t?{"Content-Type":"application/json"}:void 0,body:t?JSON.stringify(t):void 0});if(!n.ok)throw new Error(`${n.status}: ${await n.text()}`);return n.json().catch(()=>({}))}function UO(e,t){return Yf(`/api/skills/${encodeURIComponent(e)}/link`,{project:t})}function FO(e,t){return fetch(`/api/skills/${encodeURIComponent(e)}/link?project=${encodeURIComponent(t)}`,{method:"DELETE"}).then(n=>{if(!n.ok)throw new Error(`${n.status}`);return n.json()})}function $O(e,t){return Yf(`/api/skills/${encodeURIComponent(e)}/freeze`,{project:t})}function PO(e,t){return Yf(`/api/skills/${encodeURIComponent(e)}/unfreeze`,{project:t})}function qO(){return Yf("/api/skills/sync")}function HO({project:e,isPending:t,onCancel:n,onCreate:a}){var R;const[s,o]=M.useState(""),[c,f]=M.useState(""),[d,h]=M.useState(new Set),[y,g]=M.useState(!0),x=dt({queryKey:["skills-all",e],queryFn:()=>lg(e)});M.useEffect(()=>{const C=D=>{D.key==="Escape"&&n()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[n]);const S=s.trim().length>0&&s.trim().length<=200&&!t,w=C=>{const D=new Set(d);D.has(C)?D.delete(C):D.add(C),h(D)},_=()=>{S&&a({title:s.trim(),description:c.trim(),skills:[...d],labels:y?["AI-PIPELINE"]:[]})},k=((R=x.data)==null?void 0:R.data)??[];return m.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-40 flex items-start justify-center p-6 bg-black/30 overflow-auto",children:m.jsxs("div",{className:"nb-card mt-8 w-full max-w-xl flex flex-col",style:{maxHeight:"calc(100vh - 64px)"},children:[m.jsxs("header",{className:"flex items-center justify-between mb-4 flex-shrink-0",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold",children:"新建卡片"}),m.jsx("button",{className:"nb-btn nb-btn-mint p-2",onClick:n,type:"button","aria-label":"关闭",children:m.jsx(vr,{size:14,strokeWidth:3})})]}),m.jsxs("form",{onSubmit:C=>{C.preventDefault(),_()},className:"flex flex-col gap-4 overflow-auto",children:[m.jsxs("label",{className:"flex flex-col gap-1.5",children:[m.jsx("span",{className:"text-sm font-bold",children:"标题 *"}),m.jsx("input",{type:"text",className:"nb-input w-full",placeholder:"例如:接入 GitHub OAuth 登录",value:s,onChange:C=>o(C.target.value),maxLength:200,autoFocus:!0,required:!0}),m.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"写简短明了的目标(<200 字符)"})]}),m.jsxs("label",{className:"flex flex-col gap-1.5",children:[m.jsx("span",{className:"text-sm font-bold",children:"描述"}),m.jsx("textarea",{className:"nb-input w-full",style:{minHeight:120,resize:"vertical"},placeholder:"用户故事、需求、验收标准、参考资料… Claude 启动时会读这里的内容",value:c,onChange:C=>f(C.target.value)}),m.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"支持 markdown。空的话就只有 title,Claude 只能靠 title 推断要做啥。"})]}),m.jsxs("div",{className:"flex flex-col gap-2",children:[m.jsx("span",{className:"text-sm font-bold",children:"Skills"}),m.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"勾选哪些 skill 会被加载(走 frontmatter `skills:`)。不选也行,Worker 默认加载项目级 skills。"}),x.isLoading&&m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"加载 skill 列表…"}),x.isError&&m.jsxs("p",{className:"text-xs text-[var(--color-crashed)]",children:["skill 列表加载失败,不影响创建:",x.error instanceof Error?x.error.message:String(x.error)]}),k.length>0&&m.jsx("div",{className:"flex flex-wrap gap-2",children:k.map(C=>{const D=d.has(C.name);return m.jsx("button",{type:"button",onClick:()=>w(C.name),className:["px-2.5 py-1 text-xs font-[family-name:var(--font-mono)] rounded-full border-2 transition-all",D?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[2px_2px_0_var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),"aria-pressed":D,children:C.name},C.name)})}),d.size>0&&m.jsxs("p",{className:"text-xs text-[var(--color-text-muted)]",children:["已选 ",d.size," 个:",[...d].join(", ")]})]}),m.jsxs("div",{className:"flex flex-col gap-2",children:[m.jsx("span",{className:"text-sm font-bold",children:"流水线"}),m.jsxs("label",{className:"flex items-center gap-3 cursor-pointer select-none p-3 border-[2px] border-[var(--color-text)] rounded-lg bg-[var(--color-bg-cream)]",children:[m.jsx("input",{type:"checkbox",className:"w-4 h-4 accent-[var(--color-cta)] cursor-pointer",checked:y,onChange:C=>g(C.target.checked)}),m.jsxs("div",{className:"flex-1",children:[m.jsx("div",{className:"text-sm font-bold",children:"加入流水线(`AI-PIPELINE` 标签)"}),m.jsx("div",{className:"text-xs text-[var(--color-text-muted)] mt-0.5",children:"打开后 pipeline 会识别这张卡并派 worker 跑。关闭则只是一个普通 todo,需要人工改标签才会被流水线拾起。"})]})]})]})]}),m.jsxs("div",{className:"flex gap-2 justify-end mt-4 pt-3 border-t-2 border-dashed border-[var(--color-text)] flex-shrink-0",children:[m.jsx("button",{className:"nb-btn",style:{padding:"6px 14px"},onClick:n,disabled:t,type:"button",children:"取消"}),m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 14px"},onClick:_,disabled:!S,type:"button","aria-label":"创建卡片",children:[t?m.jsx(Zt,{size:13,strokeWidth:3,className:"animate-spin"}):m.jsx(Xi,{size:13,strokeWidth:3}),"创建"]})]})]})})}function KO(e){return qt(`/api/projects/${encodeURIComponent(e)}/cards`)}function GO(e,t){return qt(`/api/projects/${encodeURIComponent(e)}/cards/${t}`)}async function ql(e,t){const n=await fetch(e,{method:"POST",headers:t?{"Content-Type":"application/json"}:void 0,body:t?JSON.stringify(t):void 0});if(!n.ok){const a=await n.text();throw new Error(`${n.status} ${n.statusText}: ${a}`)}return n.json().catch(()=>({}))}function QO(e,t){return ql(`/api/projects/${encodeURIComponent(e)}/cards/${t}/reset`)}async function YO(e,t){const n=await fetch(`/api/projects/${encodeURIComponent(e)}/cards/${t}`,{method:"DELETE"});if(!n.ok){const a=await n.text();throw new Error(`${n.status}: ${a}`)}}function VO(e,t){return ql(`/api/projects/${encodeURIComponent(e)}/cards/${t}/launch`)}function XO(e,t){const n=typeof t=="string"?{title:t}:t;return ql(`/api/projects/${encodeURIComponent(e)}/cards`,n)}async function ZO(e,t,n){const a=await fetch(`/api/projects/${encodeURIComponent(e)}/cards/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:n})});if(!a.ok){const s=await a.text();throw new Error(`${a.status}: ${s}`)}}async function WO(e,t,n){const a=await fetch(`/api/projects/${encodeURIComponent(e)}/cards/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!a.ok){const s=await a.text();throw new Error(`${a.status}: ${s}`)}return a.json()}function JO(e){return ql(`/api/projects/${encodeURIComponent(e)}/pipeline/start`)}function eR(e){return ql(`/api/projects/${encodeURIComponent(e)}/pipeline/stop`)}function tR(e,t){return ql(`/api/projects/${encodeURIComponent(e)}/pipeline/reset`,t??{})}function nR(e){const t=Pn();M.useEffect(()=>{if(!e)return;const n=`/stream/projects/${encodeURIComponent(e)}`,a=new EventSource(n),s=f=>{try{const d=JSON.parse(f.data);t.invalidateQueries({queryKey:["cards",d.project]}),t.invalidateQueries({queryKey:["card",d.project,d.seq]}),t.invalidateQueries({queryKey:["projects"]})}catch{}},o=f=>{try{const d=JSON.parse(f.data);t.invalidateQueries({queryKey:["workers",d.project]}),t.invalidateQueries({queryKey:["projects"]})}catch{}},c=f=>{try{const d=JSON.parse(f.data);t.invalidateQueries({queryKey:["pipeline-status",d.project]}),t.invalidateQueries({queryKey:["projects"]})}catch{}};return a.addEventListener("card.created",s),a.addEventListener("card.updated",s),a.addEventListener("card.moved",s),a.addEventListener("card.deleted",s),a.addEventListener("worker.updated",o),a.addEventListener("worker.added",o),a.addEventListener("worker.deleted",o),a.addEventListener("pipeline.status",c),a.addEventListener("pipeline.started",c),a.addEventListener("pipeline.stopped",c),()=>a.close()},[e,t])}const iR=new Set(["python","typescript","golang","rust","kotlin","swift","java"]),aR=new Set(["frontend","backend","mobile","database","devops"]),rR=new Set(["backend-architect","frontend-developer","code-reviewer","database-optimizer","devops-automator","security-engineer","qa-tester","security","qa","architect","db-opt"]),sR=new Set(["coding-standards","tdd-workflow","git-workflow","architecture-decision-records","debugging-workflow"]);function lR(e){return iR.has(e)?"lang":aR.has(e)?"end":rR.has(e)?"persona":sR.has(e)?"workflow":"other"}const oR={lang:"var(--color-accent-purple)",end:"var(--color-secondary)",persona:"var(--color-primary)",workflow:"var(--color-accent-mint)",other:"var(--color-bg)"};function iS({name:e}){const t=oR[lR(e)];return m.jsx("span",{className:"nb-badge",style:{background:t},children:e})}function aS({label:e,kind:t="default"}){const n=t==="warn"?"var(--color-accent-pink)":t==="accent"?"var(--color-accent-yellow)":"var(--color-bg-cream)";return m.jsx("span",{className:"nb-badge",style:{background:n},children:e})}function cR({card:e,onClick:t,done:n,draggable:a}){const s=e.labels.some(o=>o.startsWith("STARTED-"))&&!n;return m.jsxs("article",{onClick:t,onKeyDown:o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),t())},draggable:a,onDragStart:o=>{o.dataTransfer.setData("application/x-sps-card-seq",String(e.seq)),o.dataTransfer.effectAllowed="move"},tabIndex:0,role:"button","aria-label":`Card #${e.seq}: ${e.title}`,className:["bg-[var(--color-bg)] border-[3px] border-[var(--color-text)] rounded-xl p-3","shadow-[3px_3px_0_var(--color-text)] cursor-pointer","transition-[transform,box-shadow] duration-[180ms] ease-out","hover:-translate-x-0.5 hover:-translate-y-0.5 hover:shadow-[5px_5px_0_var(--color-text)]","focus:outline-none focus-visible:ring-[3px] focus-visible:ring-offset-2 focus-visible:ring-[var(--color-text)]",n?"opacity-60":"",a?"active:cursor-grabbing":""].join(" "),children:[m.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[m.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-[11px] px-2 py-0.5 bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-full",children:["#",e.seq]}),s&&m.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:"running"})]}),m.jsx("p",{className:`font-bold text-sm leading-5 mb-2 line-clamp-2 ${n?"line-through decoration-2":""}`,children:e.title}),(e.skills.length>0||e.labels.length>0)&&m.jsxs("div",{className:"flex flex-wrap gap-1 mb-2",children:[e.skills.slice(0,3).map(o=>m.jsx(iS,{name:o},o)),e.labels.filter(o=>o==="NEEDS-FIX").map(o=>m.jsx(aS,{label:o,kind:"warn"},o))]}),e.checklist&&e.checklist.total>0&&m.jsx(uR,{stats:e.checklist}),m.jsxs("div",{className:"pt-2 border-t-[1.5px] border-dashed border-[var(--color-border-light)] flex items-center gap-2 text-[11px] font-[family-name:var(--font-mono)] text-[var(--color-text-subtle)]",children:[m.jsx("span",{children:fR(e.updatedAt??e.createdAt)}),e.branch&&m.jsxs("span",{className:"truncate",children:["· ",e.branch]})]})]})}function uR({stats:e}){return m.jsxs("div",{className:"mb-2",children:[m.jsxs("div",{className:"flex items-center justify-between text-[11px] font-[family-name:var(--font-mono)] mb-1",children:[m.jsxs("span",{className:"font-bold",children:["检查清单 ",e.done,"/",e.total]}),m.jsxs("span",{className:"text-[var(--color-text-subtle)]",children:[e.percent,"%"]})]}),m.jsx("div",{className:"w-full h-1.5 bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-full overflow-hidden mb-1.5",children:m.jsx("div",{className:"h-full bg-[var(--color-cta)] transition-[width] duration-200",style:{width:`${e.percent}%`}})}),m.jsxs("ul",{className:"text-[11px] space-y-0.5",children:[e.items.slice(0,3).map((t,n)=>m.jsxs("li",{className:`flex items-start gap-1 ${t.done?"opacity-60 line-through":""}`,children:[m.jsx("span",{className:"flex-shrink-0 mt-0.5",children:t.done?"✓":"○"}),m.jsx("span",{className:"line-clamp-1",children:t.text})]},n)),e.items.length>3&&m.jsxs("li",{className:"text-[var(--color-text-subtle)] italic pl-3",children:["… 还有 ",e.items.length-3," 条"]})]})]})}function fR(e){if(!e)return"—";const t=new Date(e),n=Date.now()-t.getTime();return n<6e4?"刚才":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:t.toLocaleDateString()}function dR({label:e,bg:t,cards:n,onCardClick:a,onDropCard:s}){const[o,c]=M.useState(!1);return m.jsxs("div",{className:["flex flex-col gap-2 p-3 rounded-2xl border-[3px] min-h-[340px]","transition-all",o?"border-[var(--color-cta)] shadow-[4px_4px_0_var(--color-cta)]":"border-[var(--color-text)]"].join(" "),style:{background:t},onDragOver:f=>{!s||!f.dataTransfer.types.includes("application/x-sps-card-seq")||(f.preventDefault(),f.dataTransfer.dropEffect="move",o||c(!0))},onDragLeave:()=>c(!1),onDrop:f=>{if(c(!1),!s)return;const d=f.dataTransfer.getData("application/x-sps-card-seq"),h=Number.parseInt(d,10);Number.isFinite(h)&&(f.preventDefault(),s(h))},children:[m.jsxs("div",{className:"flex items-center justify-between px-1 pb-2 border-b-2 border-[var(--color-text)]",children:[m.jsx("span",{className:"font-[family-name:var(--font-heading)] font-bold text-sm uppercase tracking-wider",children:e}),m.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-xs px-2 py-0.5 bg-[var(--color-bg)] border-2 border-[var(--color-text)] rounded-full",children:n.length})]}),m.jsxs("div",{className:"flex flex-col gap-2",children:[n.length===0&&m.jsx("div",{className:"text-xs text-[var(--color-text-muted)] text-center py-6 italic",children:"— 空 —"}),n.map(f=>m.jsx(cR,{card:f,onClick:()=>a(f),done:e==="Done",draggable:!!s},f.seq))]})]})}function dp(e,t){if(!e)return"";const n=e.split(`
476
476
  `),a=new RegExp(`^##\\s+${t}\\s*$`),s=n.findIndex(c=>a.test(c));if(s===-1)return"";let o=n.length;for(let c=s+1;c<n.length;c++)if(/^##\s+/.test(n[c]??"")){o=c;break}return n.slice(s+1,o).join(`
477
- `).trim()}function vm(e){return dp(e,"描述")}function hR({project:e,seq:t,onClose:n,onChanged:a}){var ae,W,K,oe,V,me,O,L,J;const s=Pn(),{confirm:o,alert:c}=si(),{data:f,isLoading:d,isError:h,error:y,refetch:g}=dt({queryKey:["card",e,t],queryFn:()=>GO(e,t)}),[x,v]=M.useState(!1),[S,w]=M.useState(""),[_,k]=M.useState(""),[R,C]=M.useState(new Set),[D,$]=M.useState([]),[j,q]=M.useState(""),U=dt({queryKey:["skills-all",e],queryFn:()=>lg(e),enabled:x});M.useEffect(()=>{x&&f&&(w(f.title),k(vm(f.body)),C(new Set(f.skills)),$([...f.labels]))},[x,f]),M.useEffect(()=>{const N=ce=>{ce.key==="Escape"&&(x?v(!1):n())};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[n,x]);const Z=$n({mutationFn:()=>{if(!f)throw new Error("no data");const N={},ce=S.trim();ce&&ce!==f.title&&(N.title=ce);const Ee=vm(f.body);_!==Ee&&(N.description=_);const xe=[...R].sort(),ze=[...f.skills].sort();return JSON.stringify(xe)!==JSON.stringify(ze)&&(N.skills=xe),JSON.stringify(D)!==JSON.stringify(f.labels)&&(N.labels=D),Object.keys(N).length===0?Promise.resolve({ok:!0,noop:!0}):WO(e,t,N)},onSuccess:()=>{s.invalidateQueries({queryKey:["card",e,t]}),s.invalidateQueries({queryKey:["cards",e]}),v(!1),a()},onError:N=>{c({title:"保存失败",body:N instanceof Error?N.message:String(N)})}}),A=M.useMemo(()=>{if(!x||!f)return!1;if(S.trim()!==f.title||_!==vm(f.body))return!0;const N=[...R].sort(),ce=[...f.skills].sort();return JSON.stringify(N)!==JSON.stringify(ce)||JSON.stringify(D)!==JSON.stringify(f.labels)},[x,f,S,_,R,D]),P=N=>{const ce=new Set(R);ce.has(N)?ce.delete(N):ce.add(N),C(ce)},G=()=>{const N=j.trim();if(N){if(D.includes(N)){q("");return}$([...D,N]),q("")}},le=N=>{$(D.filter(ce=>ce!==N))};return m.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"card-modal-title",className:"fixed inset-0 z-40 flex items-start justify-center p-6 bg-black/30 overflow-auto",children:m.jsxs("div",{className:"nb-card mt-12 w-full max-w-3xl bg-[var(--color-bg)]",children:[m.jsxs("header",{className:"flex items-start justify-between gap-4 mb-4",children:[m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[m.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-xs px-2 py-0.5 bg-[var(--color-accent-purple)] border-2 border-[var(--color-text)] rounded-full",children:["#",t]}),(f==null?void 0:f.state)&&m.jsx("span",{className:"font-[family-name:var(--font-mono)] text-xs px-2 py-0.5 bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-full font-semibold",children:f.state}),x&&m.jsx("span",{className:"text-xs font-bold text-[var(--color-stuck)]",children:"⚠ 编辑中"})]}),x?m.jsx("input",{type:"text",className:"nb-input w-full font-[family-name:var(--font-heading)] text-xl font-bold",value:S,onChange:N=>w(N.target.value),maxLength:200,"aria-label":"卡片标题"}):m.jsx("h2",{id:"card-modal-title",className:"font-[family-name:var(--font-heading)] text-2xl font-bold break-words",children:(f==null?void 0:f.title)??"加载中…"})]}),m.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[!x&&f&&m.jsxs("button",{onClick:()=>v(!0),className:"nb-btn",style:{padding:"6px 12px"},type:"button","aria-label":"编辑卡片",children:[m.jsx(Hp,{size:12,strokeWidth:2.5})," 编辑"]}),m.jsx("button",{onClick:n,className:"nb-btn nb-btn-mint p-2","aria-label":"关闭",type:"button",children:m.jsx(vr,{size:14,strokeWidth:3})})]})]}),d&&m.jsx("p",{className:"text-[var(--color-text-muted)]",children:"加载中…"}),h&&m.jsxs("p",{className:"text-[var(--color-crashed)]",children:["加载失败: ",y instanceof Error?y.message:String(y)]}),f&&m.jsxs("div",{className:"flex flex-col gap-4",children:[f.branch&&!x&&m.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[m.jsx(QC,{size:14}),m.jsx("span",{className:"font-[family-name:var(--font-mono)]",children:f.branch})]}),x?m.jsxs(m.Fragment,{children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-bold mb-1.5",children:"Skills"}),U.isLoading&&m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"加载 skill 列表…"}),U.data&&U.data.data.length>0&&m.jsx("div",{className:"flex flex-wrap gap-1.5",children:U.data.data.map(N=>{const ce=R.has(N.name);return m.jsx("button",{type:"button",onClick:()=>P(N.name),"aria-pressed":ce,className:["px-2.5 py-1 text-xs font-[family-name:var(--font-mono)] rounded-full border-2 transition-all",ce?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[2px_2px_0_var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),children:N.name},N.name)})})]}),m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-bold mb-1.5",children:"Labels"}),m.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[D.map(N=>m.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-[family-name:var(--font-mono)] bg-[var(--color-accent-yellow)] border-2 border-[var(--color-text)] rounded-full",children:[N,m.jsx("button",{type:"button",onClick:()=>le(N),className:"hover:text-[var(--color-crashed)]","aria-label":`删除 ${N}`,children:m.jsx(vr,{size:10,strokeWidth:3})})]},N)),m.jsx("input",{type:"text",className:"nb-input",style:{padding:"4px 8px",fontSize:12,width:140},placeholder:"+ 添加 label",value:j,onChange:N=>q(N.target.value),onKeyDown:N=>{N.key==="Enter"&&!N.nativeEvent.isComposing&&(N.preventDefault(),G())}}),j&&m.jsx("button",{type:"button",className:"nb-btn",style:{padding:"2px 6px",fontSize:11},onClick:G,"aria-label":"添加 label",children:m.jsx(Xi,{size:10,strokeWidth:3})})]}),m.jsx("p",{className:"text-[10px] text-[var(--color-text-muted)] mt-1",children:"注意:AI-PIPELINE / STARTED-* / COMPLETED-* / NEEDS-FIX 由流水线自动管理,手动改可能被覆盖"})]})]}):m.jsxs(m.Fragment,{children:[f.skills.length>0&&m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-bold mb-1.5",children:"Skills"}),m.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:f.skills.map(N=>m.jsx(iS,{name:N},N))})]}),f.labels.length>0&&m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-bold mb-1.5",children:"Labels"}),m.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:f.labels.map(N=>m.jsx(aS,{label:N,kind:N==="NEEDS-FIX"?"warn":"default"},N))})]})]}),x?m.jsxs(m.Fragment,{children:[m.jsxs("div",{children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:"描述"}),m.jsx("textarea",{className:"nb-input w-full font-[family-name:var(--font-mono)] text-xs",style:{minHeight:180,resize:"vertical"},value:_,onChange:N=>k(N.target.value),"aria-label":"卡片描述"}),m.jsx("p",{className:"text-[10px] text-[var(--color-text-muted)] mt-1",children:'只替换 "## 描述" 段的内容;检查清单和日志段不动。'})]}),(((me=f.checklist)==null?void 0:me.total)??0)>0&&m.jsxs("div",{className:"nb-card bg-[var(--color-bg-cream)] p-3",children:[m.jsx("div",{className:"flex items-center justify-between mb-2",children:m.jsxs("span",{className:"font-bold text-sm",children:["检查清单 ",((O=f.checklist)==null?void 0:O.done)??0,"/",((L=f.checklist)==null?void 0:L.total)??0]})}),m.jsx("ul",{className:"text-sm space-y-1",children:(((J=f.checklist)==null?void 0:J.items)??[]).map((N,ce)=>m.jsxs("li",{className:`flex items-start gap-2 ${N.done?"opacity-60 line-through":""}`,children:[m.jsx("span",{children:N.done?"✓":"○"}),m.jsx("span",{children:N.text})]},ce))})]})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:"描述"}),m.jsx("pre",{className:"text-xs whitespace-pre-wrap font-[family-name:var(--font-mono)] bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg p-4 max-h-64 overflow-auto",children:dp(f.body,"描述")||"(空)"})]}),(((ae=f.checklist)==null?void 0:ae.total)??0)>0&&m.jsxs("div",{children:[m.jsxs("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:["检查清单 ",m.jsxs("span",{className:"text-[var(--color-text-muted)] normal-case tracking-normal",children:[((W=f.checklist)==null?void 0:W.done)??0,"/",((K=f.checklist)==null?void 0:K.total)??0]})]}),m.jsxs("div",{className:"nb-card bg-[var(--color-bg-cream)] p-3",children:[m.jsx("div",{className:"flex items-center justify-end mb-2",children:m.jsx("div",{className:"w-24 h-2 bg-[var(--color-bg)] border-2 border-[var(--color-text)] rounded-full overflow-hidden",children:m.jsx("div",{className:"h-full bg-[var(--color-cta)]",style:{width:`${((oe=f.checklist)==null?void 0:oe.percent)??0}%`}})})}),m.jsx("ul",{className:"text-sm space-y-1",children:(((V=f.checklist)==null?void 0:V.items)??[]).map((N,ce)=>m.jsxs("li",{className:`flex items-start gap-2 ${N.done?"opacity-60 line-through":""}`,children:[m.jsx("span",{children:N.done?"✓":"○"}),m.jsx("span",{children:N.text})]},ce))})]})]}),m.jsxs("div",{children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:"日志"}),m.jsx("pre",{className:"text-xs whitespace-pre-wrap font-[family-name:var(--font-mono)] bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg p-4 max-h-64 overflow-auto",children:dp(f.body,"日志")||"(空)"})]})]}),m.jsx("div",{className:"flex gap-2 pt-2 border-t-2 border-[var(--color-border-light)] justify-end flex-wrap",children:x?m.jsxs(m.Fragment,{children:[m.jsx("button",{className:"nb-btn",type:"button",onClick:()=>{v(!1),g()},disabled:Z.isPending,children:"取消"}),m.jsxs("button",{className:"nb-btn nb-btn-primary",type:"button",onClick:()=>Z.mutate(),disabled:!A||!S.trim()||Z.isPending,"aria-label":"保存卡片修改",children:[Z.isPending?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):m.jsx(Df,{size:14,strokeWidth:3}),"保存"]})]}):m.jsxs(m.Fragment,{children:[m.jsxs("button",{className:"nb-btn nb-btn-primary",type:"button",onClick:async()=>{try{await VO(e,t),a()}catch(N){c({title:"启动 worker 失败",body:N instanceof Error?N.message:String(N)})}},children:[m.jsx(Kp,{size:14,strokeWidth:3}),"启动 worker"]}),m.jsxs("button",{className:"nb-btn nb-btn-yellow",type:"button",onClick:async()=>{if(await o({title:`重置卡片 #${t}`,body:"卡片状态会回到初始,已做的 checklist 会清空。",confirm:"重置",danger:!0}))try{await QO(e,t),a(),n()}catch(ce){c({title:"重置失败",body:ce instanceof Error?ce.message:String(ce)})}},children:[m.jsx(WE,{size:14,strokeWidth:2.5}),"重置卡片"]}),m.jsxs("button",{className:"nb-btn",style:{background:"var(--color-crashed)",color:"var(--color-bg)"},type:"button",onClick:async()=>{if(!(!await o({title:`删除卡片 #${t}`,body:`即将删除 "${f.title}"。此操作不可恢复(md 文件将被物理删除)。是否继续?`,confirm:"继续",danger:!0})||!await o({title:"最终确认",body:`请再次确认删除卡片 #${t}。`,confirm:"确定删除",danger:!0})))try{await YO(e,t),a(),n()}catch(Ee){c({title:"删除失败",body:Ee instanceof Error?Ee.message:String(Ee)})}},"aria-label":"删除卡片",children:[m.jsx(Il,{size:14,strokeWidth:2.5}),"删除卡片"]})]})})]})]})})}function mR({current:e,onChange:t}){const[n,a]=M.useState(!1),s=M.useRef(null),{data:o}=dt({queryKey:["projects"],queryFn:ds});return M.useEffect(()=>{const c=f=>{var d;(d=s.current)!=null&&d.contains(f.target)||a(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[]),m.jsxs("div",{className:"relative",ref:s,children:[m.jsxs("button",{type:"button",className:"inline-flex items-center gap-2 px-3 py-2 bg-[var(--color-bg)] border-[3px] border-[var(--color-text)] rounded-xl shadow-[3px_3px_0_var(--color-text)] font-[family-name:var(--font-mono)] text-sm font-bold hover:-translate-x-px hover:-translate-y-px hover:shadow-[4px_4px_0_var(--color-text)] transition-[transform,box-shadow] duration-150",onClick:()=>a(c=>!c),children:[e,m.jsx(yc,{size:14,strokeWidth:2.5})]}),n&&o&&m.jsx("div",{className:"absolute right-0 mt-2 z-20 min-w-[200px] bg-[var(--color-bg)] border-[3px] border-[var(--color-text)] rounded-xl shadow-[5px_5px_0_var(--color-text)] overflow-hidden",children:o.data.map(c=>m.jsxs("button",{type:"button",onClick:()=>{t(c.name),a(!1)},className:["w-full text-left px-4 py-2 text-sm font-semibold",c.name===e?"bg-[var(--color-accent-mint)]":"hover:bg-[var(--color-bg-cream)]"].join(" "),children:[m.jsx("span",{className:"font-[family-name:var(--font-mono)]",children:c.name}),m.jsxs("span",{className:"ml-2 text-xs text-[var(--color-text-muted)]",children:[c.cards.total," cards"]})]},c.name))})]})}const pR=[{state:"Planning",label:"Planning",bg:"var(--color-accent-purple)"},{state:"Backlog",label:"Backlog",bg:"var(--color-bg-cream)"},{state:"Todo",label:"Todo",bg:"var(--color-accent-yellow)"},{state:"Inprogress",label:"Inprogress",bg:"var(--color-secondary)"},{state:"QA",label:"QA / Review",bg:"var(--color-accent-pink)"},{state:"Done",label:"Done",bg:"var(--color-accent-mint)"}],rS="sps-console:last-board-project";function gR(){if(typeof window>"u")return null;try{return localStorage.getItem(rS)}catch{return null}}function bR(e){if(!(typeof window>"u"))try{localStorage.setItem(rS,e)}catch{}}function yR(){var W,K,oe;const[e,t]=QE(),n=e.get("project"),[a,s]=M.useState(null),[o,c]=M.useState(""),[f,d]=M.useState(()=>new Set),[h,y]=M.useState(()=>new Set),{confirm:g,alert:x}=si();nR(n);const v=dt({queryKey:["projects"],queryFn:ds}),S=dt({queryKey:["cards",n],queryFn:()=>KO(n??""),enabled:!!n}),w=Pn(),_=()=>{w.invalidateQueries({queryKey:["cards",n]}),w.invalidateQueries({queryKey:["projects"]}),w.invalidateQueries({queryKey:["pipeline-status",n]})},k=V=>{t({project:V})};M.useEffect(()=>{var me;if(n){bR(n);return}const V=gR();V&&((me=v.data)!=null&&me.data.some(O=>O.name===V))&&t({project:V},{replace:!0})},[n,v.data,t]);const R=$n({mutationFn:()=>JO(n),onSuccess:()=>{_()},onError:V=>{x({title:"启动 pipeline 失败",body:V instanceof Error?V.message:String(V)})}}),C=$n({mutationFn:()=>eR(n),onSuccess:()=>_(),onError:V=>{x({title:"停止 pipeline 失败",body:V instanceof Error?V.message:String(V)})}}),D=$n({mutationFn:()=>tR(n,{all:!0}),onSuccess:()=>_(),onError:V=>{x({title:"重置失败",body:V instanceof Error?V.message:String(V)})}}),[$,j]=M.useState(!1),q=$n({mutationFn:V=>XO(n,V),onSuccess:()=>{_(),j(!1)},onError:V=>{x({title:"新建卡片失败",body:V instanceof Error?V.message:String(V)})}}),U=$n({mutationFn:({seq:V,state:me})=>ZO(n,V,me),onMutate:async({seq:V,state:me})=>{await w.cancelQueries({queryKey:["cards",n]});const O=w.getQueryData(["cards",n]);return O&&w.setQueryData(["cards",n],{...O,data:O.data.map(L=>L.seq===V?{...L,state:me}:L)}),{prev:O}},onError:(V,me,O)=>{O!=null&&O.prev&&w.setQueryData(["cards",n],O.prev),x({title:"移动卡片失败",body:V instanceof Error?V.message:String(V)})},onSettled:()=>{w.invalidateQueries({queryKey:["cards",n]})}}),Z=((W=S.data)==null?void 0:W.data)??[],{allSkills:A,allLabels:P}=M.useMemo(()=>{const V=new Set,me=new Set;for(const O of Z){for(const L of O.skills)V.add(L);for(const L of O.labels)me.add(L)}return{allSkills:[...V].sort(),allLabels:[...me].sort()}},[Z]);if(!n)return m.jsxs("div",{className:"flex flex-col gap-6 max-w-4xl",children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:"看板"}),m.jsxs("div",{className:"nb-card bg-[var(--color-accent-yellow)] max-w-2xl",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-3",children:"选择一个项目 🎯"}),m.jsx("p",{className:"text-sm mb-4 text-[var(--color-text-muted)]",children:"看板按项目分。挑一个开始:"}),m.jsx("div",{className:"flex flex-wrap gap-2",children:(K=v.data)==null?void 0:K.data.map(V=>m.jsx("button",{className:"nb-btn nb-btn-blue",onClick:()=>k(V.name),type:"button",children:V.name},V.name))})]})]});const G=Z.filter(V=>{if(o){const me=o.toLowerCase();if(!(V.title.toLowerCase().includes(me)||V.skills.some(L=>L.toLowerCase().includes(me))||V.labels.some(L=>L.toLowerCase().includes(me))))return!1}return!(f.size>0&&!V.skills.some(O=>f.has(O))||h.size>0&&!V.labels.some(O=>h.has(O)))}),le=(oe=v.data)==null?void 0:oe.data.find(V=>V.name===n),ae=(le==null?void 0:le.pipelineStatus)==="running";return m.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[m.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[m.jsxs("div",{children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold tracking-tight",children:"看板 ✨"}),m.jsx("p",{className:"text-[var(--color-text-muted)] text-sm mt-1",children:le?`${le.name} · ${le.cards.total} cards · ${le.workers.active} workers 活跃`:"加载中…"})]}),m.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[m.jsx(mR,{current:n,onChange:k}),m.jsxs("button",{className:ae?"nb-btn nb-btn-danger":"nb-btn nb-btn-primary",onClick:()=>ae?C.mutate():R.mutate(),disabled:R.isPending||C.isPending,type:"button","aria-label":ae?"停止 pipeline":"启动 pipeline",title:ae?"停止 pipeline":"启动 pipeline",children:[R.isPending||C.isPending?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):ae?m.jsx(e1,{size:14,strokeWidth:3}):m.jsx(Kp,{size:14,strokeWidth:3}),ae?"停止":"启动"]}),m.jsxs("button",{className:"nb-btn nb-btn-yellow",type:"button",onClick:async()=>{await g({title:"重置整个流水线",body:"这会清空所有卡片的运行状态、worker marker、分支。不可撤销。",confirm:"重置全部",danger:!0})&&D.mutate()},disabled:D.isPending,children:[D.isPending?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):m.jsx(WE,{size:14,strokeWidth:2.5}),"重置"]}),m.jsxs("button",{className:"nb-btn nb-btn-mint",type:"button",onClick:()=>j(!0),disabled:q.isPending,children:[q.isPending?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):m.jsx(Xi,{size:14,strokeWidth:3}),"新卡片"]})]})]}),m.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[m.jsxs("div",{className:"relative flex-1 max-w-md",children:[m.jsx(xf,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),m.jsx("input",{className:"nb-input pl-9 w-full",placeholder:"搜索标题 / skill / label…",value:o,onChange:V=>c(V.target.value),"aria-label":"搜索卡片"})]}),m.jsx(Jv,{label:"skill",options:A,selected:f,onChange:d}),m.jsx(Jv,{label:"label",options:P,selected:h,onChange:y}),(o||f.size>0||h.size>0)&&m.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>{c(""),d(new Set),y(new Set)},type:"button","aria-label":"清空筛选",children:[m.jsx(vr,{size:11,strokeWidth:3}),"清空"]}),m.jsxs("span",{className:"text-xs text-[var(--color-text-muted)] flex items-center gap-1 font-[family-name:var(--font-mono)]",children:[m.jsx(KC,{size:12}),G.length," / ",Z.length]})]}),S.isError&&m.jsxs("div",{className:"nb-card bg-[var(--color-crashed-bg)]",children:[m.jsx("p",{className:"font-semibold",children:"加载卡片失败"}),m.jsx("p",{className:"text-sm mt-1 text-[var(--color-text-muted)]",children:S.error instanceof Error?S.error.message:String(S.error)})]}),!S.isError&&m.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-3",children:pR.map(V=>m.jsx(dR,{label:V.label,bg:V.bg,cards:G.filter(xR(V.state)),onCardClick:me=>s(me.seq),onDropCard:me=>U.mutate({seq:me,state:V.state})},V.state))}),a!==null&&m.jsx(hR,{project:n,seq:a,onClose:()=>s(null),onChanged:_}),$&&m.jsx(HO,{project:n,isPending:q.isPending,onCancel:()=>j(!1),onCreate:V=>q.mutate(V)})]})}function xR(e){return t=>e==="QA"?t.state==="QA"||t.state==="Review":e==="Done"?t.state==="Done"||t.state==="Canceled":t.state===e}function Jv({label:e,options:t,selected:n,onChange:a}){const[s,o]=M.useState(!1),c=M.useRef(null);M.useEffect(()=>{if(!s)return;const y=x=>{var v;(v=c.current)!=null&&v.contains(x.target)||o(!1)},g=x=>{x.key==="Escape"&&o(!1)};return window.addEventListener("click",y),window.addEventListener("keydown",g),()=>{window.removeEventListener("click",y),window.removeEventListener("keydown",g)}},[s]);const f=y=>{const g=new Set(n);g.has(y)?g.delete(y):g.add(y),a(g)},d=t.length===0,h=n.size;return m.jsxs("div",{ref:c,className:"relative",children:[m.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>!d&&o(y=>!y),disabled:d,"aria-haspopup":"listbox","aria-expanded":s,"aria-label":`按 ${e} 筛选`,children:[e,h>0&&m.jsx("span",{className:"ml-1 px-1.5 py-0.5 text-[10px] font-bold rounded-full bg-[var(--color-primary)] text-[var(--color-text)] border border-[var(--color-text)]",children:h}),m.jsx(yc,{size:11,strokeWidth:3,className:["transition-transform",s?"rotate-180":""].join(" ")})]}),s&&m.jsxs("div",{role:"listbox",className:"absolute left-0 top-full mt-2 z-20 min-w-[200px] max-h-64 overflow-auto nb-card p-2",style:{padding:8},children:[t.map(y=>{const g=n.has(y);return m.jsxs("label",{className:["flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer text-sm font-[family-name:var(--font-mono)]",g?"bg-[var(--color-accent-mint)]":"hover:bg-[var(--color-bg-cream)]"].join(" "),children:[m.jsx("input",{type:"checkbox",checked:g,onChange:()=>f(y),className:"flex-shrink-0"}),m.jsx("span",{className:"truncate",children:y})]},y)}),h>0&&m.jsx("button",{type:"button",className:"w-full mt-2 pt-2 border-t-2 border-dashed border-[var(--color-text)] text-xs font-bold text-[var(--color-crashed)] text-center",onClick:()=>a(new Set),children:"清空选择"})]})]})}function vR(){return qt("/api/workers/all")}function ER(e){return qt(`/api/projects/${encodeURIComponent(e)}/workers`)}function SR(e,t){return qt(`/api/projects/${encodeURIComponent(e)}/workers/${t}`)}async function sS(e,t){const n=await fetch(e,{method:"POST",headers:t?{"Content-Type":"application/json"}:void 0,body:t?JSON.stringify(t):void 0});if(!n.ok)throw new Error(`${n.status}: ${await n.text()}`);return n.json().catch(()=>({}))}function e0(e,t){return sS(`/api/projects/${encodeURIComponent(e)}/workers/${t}/kill`)}function wR(e,t,n){return sS(`/api/projects/${encodeURIComponent(e)}/workers/${t}/launch`,n?{seq:n}:void 0)}function _R(){var o;const e=Pn(),[t,n]=M.useState(null),a=dt({queryKey:["workers-agg"],queryFn:vR,refetchInterval:5e3});M.useEffect(()=>{if(!a.data)return;const c=a.data.capacity.map(d=>d.project),f=[];for(const d of c){const h=new EventSource(`/stream/projects/${encodeURIComponent(d)}`),y=()=>{e.invalidateQueries({queryKey:["workers-agg"]})};h.addEventListener("worker.updated",y),h.addEventListener("worker.added",y),h.addEventListener("worker.deleted",y),h.addEventListener("card.updated",y),f.push(h)}return()=>{for(const d of f)d.close()}},[(o=a.data)==null?void 0:o.capacity.map(c=>c.project).join(","),e]);const s=M.useMemo(()=>{if(!a.data)return{projects:0,running:0,starting:0,stuck:0,crashed:0,idle:0};const c={projects:a.data.capacity.length,running:0,starting:0,stuck:0,crashed:0,idle:0};for(const f of a.data.capacity)c.running+=f.running,c.starting+=f.starting,c.stuck+=f.stuck,c.crashed+=f.crashed,c.idle+=f.idle;return c},[a.data]);return m.jsxs("div",{className:"flex flex-col gap-4 h-[calc(100vh-140px)]",children:[m.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[m.jsxs("div",{children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold tracking-tight",children:"Workers 👷"}),m.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:["跨 ",s.projects," 项目 · ",s.running," 跑 · ",s.starting," 启动 ·"," ",m.jsxs("span",{className:"text-[var(--color-stuck)]",children:[s.stuck," 卡"]})," ·"," ",m.jsxs("span",{className:"text-[var(--color-crashed)]",children:[s.crashed," 崩"]})," · ",s.idle," 闲"]})]}),m.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>a.refetch(),disabled:a.isFetching,type:"button","aria-label":"刷新",children:[a.isFetching?m.jsx(Zt,{size:12,strokeWidth:3,className:"animate-spin"}):m.jsx(Cl,{size:12,strokeWidth:2.5}),"刷新"]})]}),m.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-4 flex-1 min-h-0",children:[m.jsxs("div",{className:"flex flex-col gap-4 overflow-auto pr-2",children:[a.isLoading&&m.jsx("p",{className:"text-[var(--color-text-muted)] italic",children:"加载中…"}),a.isError&&m.jsx("div",{className:"nb-card bg-[var(--color-crashed-bg)]",children:m.jsxs("p",{children:["加载失败: ",a.error instanceof Error?a.error.message:String(a.error)]})}),a.data&&m.jsxs(m.Fragment,{children:[m.jsx(kR,{alerts:a.data.alerts,selected:t,onSelect:(c,f)=>n({project:c,slot:f})}),m.jsx(NR,{active:a.data.active,selected:t,onSelect:(c,f)=>n({project:c,slot:f})}),m.jsx(TR,{capacity:a.data.capacity,selected:t,onSelect:c=>n({project:c})})]})]}),m.jsx("aside",{className:"nb-card p-0 overflow-hidden flex flex-col h-full",children:t?m.jsx(OR,{project:t.project,initialSlot:t.slot,onChange:()=>e.invalidateQueries({queryKey:["workers-agg"]})}):m.jsx("div",{className:"flex-1 flex items-center justify-center p-6 text-center",children:m.jsxs("div",{children:[m.jsx(jf,{size:32,className:"mx-auto mb-3 text-[var(--color-text-subtle)]",strokeWidth:2}),m.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"点击项目 / worker 查看详情"})]})})})]})]})}function kR({alerts:e,selected:t,onSelect:n}){return e.length===0?m.jsxs("div",{className:"nb-card bg-[var(--color-running-bg)] flex items-center gap-3",children:[m.jsx(Pp,{size:18,strokeWidth:2.5,className:"text-[var(--color-running)]"}),m.jsx("span",{className:"text-sm font-bold text-[var(--color-running)]",children:"全部 worker 健康"})]}):m.jsxs("section",{children:[m.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-sm font-bold uppercase tracking-wider mb-2 flex items-center gap-2 text-[var(--color-crashed)]",children:[m.jsx(RA,{size:14,strokeWidth:2.5}),"Alerts (",e.length,")"]}),m.jsx("div",{className:"flex flex-col gap-2",children:e.map(a=>{const s=(t==null?void 0:t.project)===a.project&&(t==null?void 0:t.slot)===a.slot;return m.jsxs("button",{type:"button",onClick:()=>n(a.project,a.slot),className:["nb-card p-3 text-left",a.state==="crashed"?"bg-[var(--color-crashed-bg)]":"bg-[var(--color-stuck-bg)]",s?"ring-4 ring-[var(--color-text)]":""].join(" "),children:[m.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[m.jsx(og,{state:a.state}),m.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold",children:[a.project,"/worker-",a.slot]}),a.card&&m.jsxs("span",{className:"truncate",children:["#",a.card.seq," ",a.card.title]}),m.jsxs("span",{className:"ml-auto text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] flex items-center gap-1",children:[m.jsx(MC,{size:10,strokeWidth:2.5}),cg(a.runtimeMs)]})]}),a.markerUpdatedAt&&m.jsx("div",{className:"text-xs text-[var(--color-text-muted)] mt-1 font-[family-name:var(--font-mono)]",children:a.state==="crashed"?"PID 已死。":`marker 停 ${ug(a.markerUpdatedAt)}。`})]},`${a.project}-${a.slot}`)})})]})}function NR({active:e,selected:t,onSelect:n}){return e.length===0?m.jsx("div",{className:"nb-card bg-[var(--color-bg-cream)]",children:m.jsx("p",{className:"text-sm text-[var(--color-text-muted)] italic",children:"没有 worker 在运行。"})}):m.jsxs("section",{children:[m.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-sm font-bold uppercase tracking-wider mb-2 flex items-center gap-2",children:[m.jsx(jf,{size:14,strokeWidth:2.5}),"Active (",e.length,")"]}),m.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:e.map(a=>{const s=(t==null?void 0:t.project)===a.project&&(t==null?void 0:t.slot)===a.slot;return m.jsxs("button",{type:"button",onClick:()=>n(a.project,a.slot),className:["nb-card p-3 text-left",a.state==="starting"?"bg-[var(--color-secondary)]":"bg-[var(--color-running-bg)]",s?"ring-4 ring-[var(--color-text)]":""].join(" "),children:[m.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[m.jsx(og,{state:a.state}),m.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm flex-1 truncate",children:[a.project,"/worker-",a.slot]}),m.jsx("span",{className:`text-xs font-[family-name:var(--font-mono)] ${jR(a.runtimeMs)}`,children:cg(a.runtimeMs)})]}),a.card&&m.jsxs("div",{className:"text-sm font-semibold mb-1 truncate",children:["#",a.card.seq," · ",a.card.title]}),m.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] flex items-center gap-2 mb-1",children:[a.stage&&m.jsxs("span",{children:["stage: ",a.stage]}),a.markerUpdatedAt&&m.jsxs("span",{className:"ml-auto",children:["marker ",ug(a.markerUpdatedAt)]})]}),a.lastLogLine&&m.jsxs("div",{className:"text-[11px] font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] bg-[var(--color-bg)] border-2 border-[var(--color-text)] rounded px-2 py-1 mt-2 truncate",children:[m.jsx(t1,{size:9,strokeWidth:2.5,className:"inline-block mr-1 align-text-bottom"}),a.lastLogLine.msg]})]},`${a.project}-${a.slot}`)})})]})}function TR({capacity:e,selected:t,onSelect:n}){return e.length===0?null:m.jsxs("section",{children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-sm font-bold uppercase tracking-wider mb-2",children:"Capacity"}),m.jsx("div",{className:"nb-card p-0 overflow-hidden",children:m.jsxs("table",{className:"w-full text-sm",children:[m.jsx("thead",{children:m.jsxs("tr",{className:"bg-[var(--color-bg-cream)] border-b-2 border-[var(--color-text)]",children:[m.jsx("th",{className:"px-3 py-2 text-left font-bold text-xs uppercase tracking-wider",children:"项目"}),m.jsx("th",{className:"px-3 py-2 text-left font-bold text-xs uppercase tracking-wider",children:"占用"}),m.jsx("th",{className:"px-3 py-2 text-right font-bold text-xs uppercase tracking-wider",children:"running"}),m.jsx("th",{className:"px-3 py-2 text-right font-bold text-xs uppercase tracking-wider",children:"其它"}),m.jsx("th",{className:"px-3 py-2"})]})}),m.jsx("tbody",{children:e.map(a=>{const s=a.running+a.starting+a.stuck+a.crashed,o=(t==null?void 0:t.project)===a.project;return m.jsxs("tr",{onClick:()=>n(a.project),className:["border-b border-dashed border-[var(--color-border-light)] last:border-0 cursor-pointer hover:bg-[var(--color-accent-yellow)]",o?"bg-[var(--color-accent-yellow)]":""].join(" "),children:[m.jsx("td",{className:"px-3 py-2 font-[family-name:var(--font-mono)] font-bold",children:a.project}),m.jsx("td",{className:"px-3 py-2",children:m.jsx(CR,{total:a.total,cap:a})}),m.jsxs("td",{className:"px-3 py-2 text-right font-[family-name:var(--font-mono)]",children:[m.jsx("span",{className:"text-[var(--color-running)] font-bold",children:a.running}),m.jsxs("span",{className:"text-[var(--color-text-muted)]",children:["/",a.total]})]}),m.jsxs("td",{className:"px-3 py-2 text-right text-xs font-[family-name:var(--font-mono)] text-[var(--color-text-muted)]",children:[a.starting>0&&m.jsxs("span",{className:"mr-2",children:["starting ",a.starting]}),a.stuck>0&&m.jsxs("span",{className:"text-[var(--color-stuck)] font-bold mr-2",children:["stuck ",a.stuck]}),a.crashed>0&&m.jsxs("span",{className:"text-[var(--color-crashed)] font-bold mr-2",children:["crashed ",a.crashed]}),s===0&&m.jsx("span",{children:"idle"})]}),m.jsx("td",{className:"px-3 py-2 text-right",children:m.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"详情 →"})})]},a.project)})})]})})]})}function CR({total:e,cap:t}){const n=[];for(let a=0;a<t.crashed;a++)n.push("crashed");for(let a=0;a<t.stuck;a++)n.push("stuck");for(let a=0;a<t.starting;a++)n.push("starting");for(let a=0;a<t.running;a++)n.push("running");for(let a=0;a<t.idle;a++)n.push("idle");return m.jsxs("div",{className:"flex gap-1 items-center",children:[n.map((a,s)=>m.jsx("span",{className:"inline-block w-3 h-3 rounded-full border-2 border-[var(--color-text)]",style:{background:AR(a)},title:a},s)),m.jsxs("span",{className:"text-xs text-[var(--color-text-muted)] ml-2 font-[family-name:var(--font-mono)]",children:[e," slot",e!==1?"s":""]})]})}function AR(e){switch(e){case"running":return"var(--color-running-bg)";case"starting":return"var(--color-secondary)";case"stuck":return"var(--color-stuck-bg)";case"crashed":return"var(--color-crashed-bg)";default:return"var(--color-idle-bg)"}}function OR({project:e,initialSlot:t,onChange:n}){var d;const a=dt({queryKey:["workers",e],queryFn:()=>ER(e),refetchInterval:3e3}),s=((d=a.data)==null?void 0:d.data)??[],[o,c]=M.useState(null);M.useEffect(()=>{if(s.length===0){c(null);return}const h=s[0].slot;c(y=>y!=null&&s.some(g=>g.slot===y)?y:t!=null&&s.some(g=>g.slot===t)?t:h)},[e,t,s.length]);const f=s.find(h=>h.slot===o)??null;return m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsxs("div",{className:"px-4 py-3 border-b-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[m.jsxs("div",{className:"flex items-center justify-between mb-2",children:[m.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold truncate",children:e}),m.jsx(fs,{to:`/board?project=${encodeURIComponent(e)}`,className:"text-xs underline text-[var(--color-text-muted)] hover:text-[var(--color-text)]",children:"看板 →"})]}),a.isLoading&&s.length===0?m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"加载 workers…"}):s.length===0?m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"该项目没有 worker slot。"}):m.jsx("div",{className:"flex flex-wrap gap-2",children:s.map(h=>m.jsx(RR,{worker:h,active:h.slot===o,onClick:()=>c(h.slot)},h.slot))})]}),f?m.jsx(MR,{project:e,worker:f,onChange:n}):m.jsx("div",{className:"flex-1 flex items-center justify-center p-6 text-center",children:m.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:s.length===0?"无 worker":"请选择一个 worker"})})]})}function RR({worker:e,active:t,onClick:n}){return m.jsxs("button",{type:"button",onClick:n,className:["nb-card p-2 text-left min-w-[130px] transition-transform",t?"ring-4 ring-[var(--color-text)]":"opacity-80 hover:opacity-100"].join(" "),children:[m.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[m.jsx(og,{state:e.state}),m.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-xs",children:["worker-",e.slot]})]}),e.card?m.jsxs("div",{className:"text-[11px] truncate font-[family-name:var(--font-mono)]",children:["#",e.card.seq," ",e.card.title]}):m.jsx("div",{className:"text-[11px] text-[var(--color-text-muted)] italic",children:"空闲"})]})}function MR({project:e,worker:t,onChange:n}){var h,y;const{confirm:a,alert:s}=si(),o=t.state==="crashed"||t.state==="stuck",c=dt({queryKey:["worker-detail",e,t.slot],queryFn:()=>SR(e,t.slot),refetchInterval:3e3}),f=((h=c.data)==null?void 0:h.recentOutput)??[],d=((y=c.data)==null?void 0:y.recentLogs)??[];return m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex-1 overflow-auto p-4 flex flex-col gap-4",children:[t.card?m.jsxs("div",{children:[m.jsx("div",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-1",children:"当前卡片"}),m.jsxs("div",{className:"text-sm font-semibold break-words",children:["#",t.card.seq," · ",t.card.title]})]}):m.jsx("div",{className:"text-sm text-[var(--color-text-muted)] italic",children:"slot 空闲,没有当前卡片。"}),m.jsxs("dl",{className:"grid grid-cols-[100px_1fr] gap-y-2 text-sm",children:[m.jsx("dt",{className:"font-bold",children:"Stage"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.stage??"—"}),m.jsx("dt",{className:"font-bold",children:"PID"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.pid??"—"}),m.jsx("dt",{className:"font-bold",children:"Runtime"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:cg(t.runtimeMs)}),m.jsx("dt",{className:"font-bold",children:"Started"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)] text-xs",children:t.startedAt?new Date(t.startedAt).toLocaleString():"—"}),m.jsx("dt",{className:"font-bold",children:"Marker"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)] text-xs",children:t.markerUpdatedAt?ug(t.markerUpdatedAt):"—"})]}),m.jsxs("div",{children:[m.jsxs("div",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-1 flex items-center gap-1",children:[m.jsx(t1,{size:10,strokeWidth:2.5}),"Claude 输出 · 最近 ",f.length," 行"]}),c.isLoading&&f.length===0?m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"加载中…"}):f.length===0?m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"还没收到 session 输出。Worker 刚启动时需要几秒。"}):m.jsx("pre",{className:"text-xs font-[family-name:var(--font-mono)] bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded p-2 max-h-80 overflow-auto whitespace-pre-wrap break-words",children:f.map(g=>`${g.ts?`${g.ts} [${g.kind}] `:`[${g.kind}] `}${g.text}`).join(`
477
+ `).trim()}function vm(e){return dp(e,"描述")}function hR({project:e,seq:t,onClose:n,onChanged:a}){var ae,W,K,oe,V,me,O,L,J;const s=Pn(),{confirm:o,alert:c}=si(),{data:f,isLoading:d,isError:h,error:y,refetch:g}=dt({queryKey:["card",e,t],queryFn:()=>GO(e,t)}),[x,v]=M.useState(!1),[S,w]=M.useState(""),[_,k]=M.useState(""),[R,C]=M.useState(new Set),[D,$]=M.useState([]),[j,q]=M.useState(""),U=dt({queryKey:["skills-all",e],queryFn:()=>lg(e),enabled:x});M.useEffect(()=>{x&&f&&(w(f.title),k(vm(f.body)),C(new Set(f.skills)),$([...f.labels]))},[x,f]),M.useEffect(()=>{const N=ce=>{ce.key==="Escape"&&(x?v(!1):n())};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[n,x]);const Z=$n({mutationFn:()=>{if(!f)throw new Error("no data");const N={},ce=S.trim();ce&&ce!==f.title&&(N.title=ce);const Ee=vm(f.body);_!==Ee&&(N.description=_);const xe=[...R].sort(),ze=[...f.skills].sort();return JSON.stringify(xe)!==JSON.stringify(ze)&&(N.skills=xe),JSON.stringify(D)!==JSON.stringify(f.labels)&&(N.labels=D),Object.keys(N).length===0?Promise.resolve({ok:!0,noop:!0}):WO(e,t,N)},onSuccess:()=>{s.invalidateQueries({queryKey:["card",e,t]}),s.invalidateQueries({queryKey:["cards",e]}),v(!1),a()},onError:N=>{c({title:"保存失败",body:N instanceof Error?N.message:String(N)})}}),A=M.useMemo(()=>{if(!x||!f)return!1;if(S.trim()!==f.title||_!==vm(f.body))return!0;const N=[...R].sort(),ce=[...f.skills].sort();return JSON.stringify(N)!==JSON.stringify(ce)||JSON.stringify(D)!==JSON.stringify(f.labels)},[x,f,S,_,R,D]),P=N=>{const ce=new Set(R);ce.has(N)?ce.delete(N):ce.add(N),C(ce)},G=()=>{const N=j.trim();if(N){if(D.includes(N)){q("");return}$([...D,N]),q("")}},le=N=>{$(D.filter(ce=>ce!==N))};return m.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"card-modal-title",className:"fixed inset-0 z-40 flex items-start justify-center p-6 bg-black/30 overflow-auto",children:m.jsxs("div",{className:"nb-card mt-12 w-full max-w-3xl bg-[var(--color-bg)]",children:[m.jsxs("header",{className:"flex items-start justify-between gap-4 mb-4",children:[m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[m.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-xs px-2 py-0.5 bg-[var(--color-accent-purple)] border-2 border-[var(--color-text)] rounded-full",children:["#",t]}),(f==null?void 0:f.state)&&m.jsx("span",{className:"font-[family-name:var(--font-mono)] text-xs px-2 py-0.5 bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-full font-semibold",children:f.state}),x&&m.jsx("span",{className:"text-xs font-bold text-[var(--color-stuck)]",children:"⚠ 编辑中"})]}),x?m.jsx("input",{type:"text",className:"nb-input w-full font-[family-name:var(--font-heading)] text-xl font-bold",value:S,onChange:N=>w(N.target.value),maxLength:200,"aria-label":"卡片标题"}):m.jsx("h2",{id:"card-modal-title",className:"font-[family-name:var(--font-heading)] text-2xl font-bold break-words",children:(f==null?void 0:f.title)??"加载中…"})]}),m.jsxs("div",{className:"flex gap-2 flex-shrink-0",children:[!x&&f&&m.jsxs("button",{onClick:()=>v(!0),className:"nb-btn",style:{padding:"6px 12px"},type:"button","aria-label":"编辑卡片",children:[m.jsx(Hp,{size:12,strokeWidth:2.5})," 编辑"]}),m.jsx("button",{onClick:n,className:"nb-btn nb-btn-mint p-2","aria-label":"关闭",type:"button",children:m.jsx(vr,{size:14,strokeWidth:3})})]})]}),d&&m.jsx("p",{className:"text-[var(--color-text-muted)]",children:"加载中…"}),h&&m.jsxs("p",{className:"text-[var(--color-crashed)]",children:["加载失败: ",y instanceof Error?y.message:String(y)]}),f&&m.jsxs("div",{className:"flex flex-col gap-4",children:[f.branch&&!x&&m.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[m.jsx(QC,{size:14}),m.jsx("span",{className:"font-[family-name:var(--font-mono)]",children:f.branch})]}),x?m.jsxs(m.Fragment,{children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-bold mb-1.5",children:"Skills"}),U.isLoading&&m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"加载 skill 列表…"}),U.data&&U.data.data.length>0&&m.jsx("div",{className:"flex flex-wrap gap-1.5",children:U.data.data.map(N=>{const ce=R.has(N.name);return m.jsx("button",{type:"button",onClick:()=>P(N.name),"aria-pressed":ce,className:["px-2.5 py-1 text-xs font-[family-name:var(--font-mono)] rounded-full border-2 transition-all",ce?"bg-[var(--color-accent-mint)] border-[var(--color-text)] shadow-[2px_2px_0_var(--color-text)] font-bold":"bg-[var(--color-bg)] border-[var(--color-border-light)] hover:border-[var(--color-text)]"].join(" "),children:N.name},N.name)})})]}),m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-bold mb-1.5",children:"Labels"}),m.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[D.map(N=>m.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-[family-name:var(--font-mono)] bg-[var(--color-accent-yellow)] border-2 border-[var(--color-text)] rounded-full",children:[N,m.jsx("button",{type:"button",onClick:()=>le(N),className:"hover:text-[var(--color-crashed)]","aria-label":`删除 ${N}`,children:m.jsx(vr,{size:10,strokeWidth:3})})]},N)),m.jsx("input",{type:"text",className:"nb-input",style:{padding:"4px 8px",fontSize:12,width:140},placeholder:"+ 添加 label",value:j,onChange:N=>q(N.target.value),onKeyDown:N=>{N.key==="Enter"&&!N.nativeEvent.isComposing&&(N.preventDefault(),G())}}),j&&m.jsx("button",{type:"button",className:"nb-btn",style:{padding:"2px 6px",fontSize:11},onClick:G,"aria-label":"添加 label",children:m.jsx(Xi,{size:10,strokeWidth:3})})]}),m.jsx("p",{className:"text-[10px] text-[var(--color-text-muted)] mt-1",children:"注意:AI-PIPELINE / STARTED-* / COMPLETED-* / NEEDS-FIX 由流水线自动管理,手动改可能被覆盖"})]})]}):m.jsxs(m.Fragment,{children:[f.skills.length>0&&m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-bold mb-1.5",children:"Skills"}),m.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:f.skills.map(N=>m.jsx(iS,{name:N},N))})]}),f.labels.length>0&&m.jsxs("div",{children:[m.jsx("div",{className:"text-sm font-bold mb-1.5",children:"Labels"}),m.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:f.labels.map(N=>m.jsx(aS,{label:N,kind:N==="NEEDS-FIX"?"warn":"default"},N))})]})]}),x?m.jsxs(m.Fragment,{children:[m.jsxs("div",{children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:"描述"}),m.jsx("textarea",{className:"nb-input w-full font-[family-name:var(--font-mono)] text-xs",style:{minHeight:180,resize:"vertical"},value:_,onChange:N=>k(N.target.value),"aria-label":"卡片描述"}),m.jsx("p",{className:"text-[10px] text-[var(--color-text-muted)] mt-1",children:'只替换 "## 描述" 段的内容;检查清单和日志段不动。'})]}),(((me=f.checklist)==null?void 0:me.total)??0)>0&&m.jsxs("div",{className:"nb-card bg-[var(--color-bg-cream)] p-3",children:[m.jsx("div",{className:"flex items-center justify-between mb-2",children:m.jsxs("span",{className:"font-bold text-sm",children:["检查清单 ",((O=f.checklist)==null?void 0:O.done)??0,"/",((L=f.checklist)==null?void 0:L.total)??0]})}),m.jsx("ul",{className:"text-sm space-y-1",children:(((J=f.checklist)==null?void 0:J.items)??[]).map((N,ce)=>m.jsxs("li",{className:`flex items-start gap-2 ${N.done?"opacity-60 line-through":""}`,children:[m.jsx("span",{children:N.done?"✓":"○"}),m.jsx("span",{children:N.text})]},ce))})]})]}):m.jsxs(m.Fragment,{children:[m.jsxs("div",{children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:"描述"}),m.jsx("pre",{className:"text-xs whitespace-pre-wrap font-[family-name:var(--font-mono)] bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg p-4 max-h-64 overflow-auto",children:dp(f.body,"描述")||"(空)"})]}),(((ae=f.checklist)==null?void 0:ae.total)??0)>0&&m.jsxs("div",{children:[m.jsxs("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:["检查清单 ",m.jsxs("span",{className:"text-[var(--color-text-muted)] normal-case tracking-normal",children:[((W=f.checklist)==null?void 0:W.done)??0,"/",((K=f.checklist)==null?void 0:K.total)??0]})]}),m.jsxs("div",{className:"nb-card bg-[var(--color-bg-cream)] p-3",children:[m.jsx("div",{className:"flex items-center justify-end mb-2",children:m.jsx("div",{className:"w-24 h-2 bg-[var(--color-bg)] border-2 border-[var(--color-text)] rounded-full overflow-hidden",children:m.jsx("div",{className:"h-full bg-[var(--color-cta)]",style:{width:`${((oe=f.checklist)==null?void 0:oe.percent)??0}%`}})})}),m.jsx("ul",{className:"text-sm space-y-1",children:(((V=f.checklist)==null?void 0:V.items)??[]).map((N,ce)=>m.jsxs("li",{className:`flex items-start gap-2 ${N.done?"opacity-60 line-through":""}`,children:[m.jsx("span",{children:N.done?"✓":"○"}),m.jsx("span",{children:N.text})]},ce))})]})]}),m.jsxs("div",{children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:"日志"}),m.jsx("pre",{className:"text-xs whitespace-pre-wrap font-[family-name:var(--font-mono)] bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg p-4 max-h-64 overflow-auto",children:dp(f.body,"日志")||"(空)"})]})]}),m.jsx("div",{className:"flex gap-2 pt-2 border-t-2 border-[var(--color-border-light)] justify-end flex-wrap",children:x?m.jsxs(m.Fragment,{children:[m.jsx("button",{className:"nb-btn",type:"button",onClick:()=>{v(!1),g()},disabled:Z.isPending,children:"取消"}),m.jsxs("button",{className:"nb-btn nb-btn-primary",type:"button",onClick:()=>Z.mutate(),disabled:!A||!S.trim()||Z.isPending,"aria-label":"保存卡片修改",children:[Z.isPending?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):m.jsx(Df,{size:14,strokeWidth:3}),"保存"]})]}):m.jsxs(m.Fragment,{children:[m.jsxs("button",{className:"nb-btn nb-btn-primary",type:"button",onClick:async()=>{try{await VO(e,t),a()}catch(N){c({title:"启动 worker 失败",body:N instanceof Error?N.message:String(N)})}},children:[m.jsx(Kp,{size:14,strokeWidth:3}),"启动 worker"]}),m.jsxs("button",{className:"nb-btn nb-btn-yellow",type:"button",onClick:async()=>{if(await o({title:`重置卡片 #${t}`,body:"卡片状态会回到初始,已做的 checklist 会清空。",confirm:"重置",danger:!0}))try{await QO(e,t),a(),n()}catch(ce){c({title:"重置失败",body:ce instanceof Error?ce.message:String(ce)})}},children:[m.jsx(WE,{size:14,strokeWidth:2.5}),"重置卡片"]}),m.jsxs("button",{className:"nb-btn",style:{background:"var(--color-crashed)",color:"var(--color-bg)"},type:"button",onClick:async()=>{if(!(!await o({title:`删除卡片 #${t}`,body:`即将删除 "${f.title}"。此操作不可恢复(md 文件将被物理删除)。是否继续?`,confirm:"继续",danger:!0})||!await o({title:"最终确认",body:`请再次确认删除卡片 #${t}。`,confirm:"确定删除",danger:!0})))try{await YO(e,t),a(),n()}catch(Ee){c({title:"删除失败",body:Ee instanceof Error?Ee.message:String(Ee)})}},"aria-label":"删除卡片",children:[m.jsx(Il,{size:14,strokeWidth:2.5}),"删除卡片"]})]})})]})]})})}function mR({current:e,onChange:t}){const[n,a]=M.useState(!1),s=M.useRef(null),{data:o}=dt({queryKey:["projects"],queryFn:ds});return M.useEffect(()=>{const c=f=>{var d;(d=s.current)!=null&&d.contains(f.target)||a(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[]),m.jsxs("div",{className:"relative",ref:s,children:[m.jsxs("button",{type:"button",className:"inline-flex items-center gap-2 px-3 py-2 bg-[var(--color-bg)] border-[3px] border-[var(--color-text)] rounded-xl shadow-[3px_3px_0_var(--color-text)] font-[family-name:var(--font-mono)] text-sm font-bold hover:-translate-x-px hover:-translate-y-px hover:shadow-[4px_4px_0_var(--color-text)] transition-[transform,box-shadow] duration-150",onClick:()=>a(c=>!c),children:[e,m.jsx(yc,{size:14,strokeWidth:2.5})]}),n&&o&&m.jsx("div",{className:"absolute right-0 mt-2 z-20 min-w-[200px] bg-[var(--color-bg)] border-[3px] border-[var(--color-text)] rounded-xl shadow-[5px_5px_0_var(--color-text)] overflow-hidden",children:o.data.map(c=>m.jsxs("button",{type:"button",onClick:()=>{t(c.name),a(!1)},className:["w-full text-left px-4 py-2 text-sm font-semibold",c.name===e?"bg-[var(--color-accent-mint)]":"hover:bg-[var(--color-bg-cream)]"].join(" "),children:[m.jsx("span",{className:"font-[family-name:var(--font-mono)]",children:c.name}),m.jsxs("span",{className:"ml-2 text-xs text-[var(--color-text-muted)]",children:[c.cards.total," cards"]})]},c.name))})]})}const pR=[{state:"Planning",label:"Planning",bg:"var(--color-accent-purple)"},{state:"Backlog",label:"Backlog",bg:"var(--color-bg-cream)"},{state:"Todo",label:"Todo",bg:"var(--color-accent-yellow)"},{state:"Inprogress",label:"Inprogress",bg:"var(--color-secondary)"},{state:"QA",label:"QA / Review",bg:"var(--color-accent-pink)"},{state:"Done",label:"Done",bg:"var(--color-accent-mint)"}],rS="sps-console:last-board-project";function gR(){if(typeof window>"u")return null;try{return localStorage.getItem(rS)}catch{return null}}function bR(e){if(!(typeof window>"u"))try{localStorage.setItem(rS,e)}catch{}}function yR(){var W,K,oe;const[e,t]=QE(),n=e.get("project"),[a,s]=M.useState(null),[o,c]=M.useState(""),[f,d]=M.useState(()=>new Set),[h,y]=M.useState(()=>new Set),{confirm:g,alert:x}=si();nR(n);const v=dt({queryKey:["projects"],queryFn:ds}),S=dt({queryKey:["cards",n],queryFn:()=>KO(n??""),enabled:!!n}),w=Pn(),_=()=>{w.invalidateQueries({queryKey:["cards",n]}),w.invalidateQueries({queryKey:["projects"]}),w.invalidateQueries({queryKey:["pipeline-status",n]})},k=V=>{t({project:V})};M.useEffect(()=>{var me;if(n){bR(n);return}const V=gR();V&&((me=v.data)!=null&&me.data.some(O=>O.name===V))&&t({project:V},{replace:!0})},[n,v.data,t]);const R=$n({mutationFn:()=>JO(n),onSuccess:()=>{_()},onError:V=>{x({title:"启动 pipeline 失败",body:V instanceof Error?V.message:String(V)})}}),C=$n({mutationFn:()=>eR(n),onSuccess:()=>_(),onError:V=>{x({title:"停止 pipeline 失败",body:V instanceof Error?V.message:String(V)})}}),D=$n({mutationFn:()=>tR(n,{all:!0}),onSuccess:()=>_(),onError:V=>{x({title:"重置失败",body:V instanceof Error?V.message:String(V)})}}),[$,j]=M.useState(!1),q=$n({mutationFn:V=>XO(n,V),onSuccess:()=>{_(),j(!1)},onError:V=>{x({title:"新建卡片失败",body:V instanceof Error?V.message:String(V)})}}),U=$n({mutationFn:({seq:V,state:me})=>ZO(n,V,me),onMutate:async({seq:V,state:me})=>{await w.cancelQueries({queryKey:["cards",n]});const O=w.getQueryData(["cards",n]);return O&&w.setQueryData(["cards",n],{...O,data:O.data.map(L=>L.seq===V?{...L,state:me}:L)}),{prev:O}},onError:(V,me,O)=>{O!=null&&O.prev&&w.setQueryData(["cards",n],O.prev),x({title:"移动卡片失败",body:V instanceof Error?V.message:String(V)})},onSettled:()=>{w.invalidateQueries({queryKey:["cards",n]})}}),Z=((W=S.data)==null?void 0:W.data)??[],{allSkills:A,allLabels:P}=M.useMemo(()=>{const V=new Set,me=new Set;for(const O of Z){for(const L of O.skills)V.add(L);for(const L of O.labels)me.add(L)}return{allSkills:[...V].sort(),allLabels:[...me].sort()}},[Z]);if(!n)return m.jsxs("div",{className:"flex flex-col gap-6 max-w-4xl",children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:"看板"}),m.jsxs("div",{className:"nb-card bg-[var(--color-accent-yellow)] max-w-2xl",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-3",children:"选择一个项目 🎯"}),m.jsx("p",{className:"text-sm mb-4 text-[var(--color-text-muted)]",children:"看板按项目分。挑一个开始:"}),m.jsx("div",{className:"flex flex-wrap gap-2",children:(K=v.data)==null?void 0:K.data.map(V=>m.jsx("button",{className:"nb-btn nb-btn-blue",onClick:()=>k(V.name),type:"button",children:V.name},V.name))})]})]});const G=Z.filter(V=>{if(o){const me=o.toLowerCase();if(!(V.title.toLowerCase().includes(me)||V.skills.some(L=>L.toLowerCase().includes(me))||V.labels.some(L=>L.toLowerCase().includes(me))))return!1}return!(f.size>0&&!V.skills.some(O=>f.has(O))||h.size>0&&!V.labels.some(O=>h.has(O)))}),le=(oe=v.data)==null?void 0:oe.data.find(V=>V.name===n),ae=(le==null?void 0:le.pipelineStatus)==="running";return m.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[m.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[m.jsxs("div",{children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold tracking-tight",children:"看板 ✨"}),m.jsx("p",{className:"text-[var(--color-text-muted)] text-sm mt-1",children:le?`${le.name} · ${le.cards.total} cards · ${le.workers.active} workers 活跃`:"加载中…"})]}),m.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[m.jsx(mR,{current:n,onChange:k}),m.jsxs("button",{className:ae?"nb-btn nb-btn-danger":"nb-btn nb-btn-primary",onClick:()=>ae?C.mutate():R.mutate(),disabled:R.isPending||C.isPending,type:"button","aria-label":ae?"停止 pipeline":"启动 pipeline",title:ae?"停止 pipeline":"启动 pipeline",children:[R.isPending||C.isPending?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):ae?m.jsx(e1,{size:14,strokeWidth:3}):m.jsx(Kp,{size:14,strokeWidth:3}),ae?"停止":"启动"]}),m.jsxs("button",{className:"nb-btn nb-btn-yellow",type:"button",onClick:async()=>{await g({title:"重置整个流水线",body:"这会清空所有卡片的运行状态、worker marker、分支。不可撤销。",confirm:"重置全部",danger:!0})&&D.mutate()},disabled:D.isPending,children:[D.isPending?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):m.jsx(WE,{size:14,strokeWidth:2.5}),"重置"]}),m.jsxs("button",{className:"nb-btn nb-btn-mint",type:"button",onClick:()=>j(!0),disabled:q.isPending,children:[q.isPending?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):m.jsx(Xi,{size:14,strokeWidth:3}),"新卡片"]})]})]}),m.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[m.jsxs("div",{className:"relative flex-1 max-w-md",children:[m.jsx(xf,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),m.jsx("input",{className:"nb-input pl-9 w-full",placeholder:"搜索标题 / skill / label…",value:o,onChange:V=>c(V.target.value),"aria-label":"搜索卡片"})]}),m.jsx(Jv,{label:"skill",options:A,selected:f,onChange:d}),m.jsx(Jv,{label:"label",options:P,selected:h,onChange:y}),(o||f.size>0||h.size>0)&&m.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>{c(""),d(new Set),y(new Set)},type:"button","aria-label":"清空筛选",children:[m.jsx(vr,{size:11,strokeWidth:3}),"清空"]}),m.jsxs("span",{className:"text-xs text-[var(--color-text-muted)] flex items-center gap-1 font-[family-name:var(--font-mono)]",children:[m.jsx(KC,{size:12}),G.length," / ",Z.length]})]}),S.isError&&m.jsxs("div",{className:"nb-card bg-[var(--color-crashed-bg)]",children:[m.jsx("p",{className:"font-semibold",children:"加载卡片失败"}),m.jsx("p",{className:"text-sm mt-1 text-[var(--color-text-muted)]",children:S.error instanceof Error?S.error.message:String(S.error)})]}),!S.isError&&m.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-3",children:pR.map(V=>m.jsx(dR,{label:V.label,bg:V.bg,cards:G.filter(xR(V.state)),onCardClick:me=>s(me.seq),onDropCard:me=>U.mutate({seq:me,state:V.state})},V.state))}),a!==null&&m.jsx(hR,{project:n,seq:a,onClose:()=>s(null),onChanged:_}),$&&m.jsx(HO,{project:n,isPending:q.isPending,onCancel:()=>j(!1),onCreate:V=>q.mutate(V)})]})}function xR(e){return t=>e==="QA"?t.state==="QA"||t.state==="Review":e==="Done"?t.state==="Done"||t.state==="Canceled":t.state===e}function Jv({label:e,options:t,selected:n,onChange:a}){const[s,o]=M.useState(!1),c=M.useRef(null);M.useEffect(()=>{if(!s)return;const y=x=>{var v;(v=c.current)!=null&&v.contains(x.target)||o(!1)},g=x=>{x.key==="Escape"&&o(!1)};return window.addEventListener("click",y),window.addEventListener("keydown",g),()=>{window.removeEventListener("click",y),window.removeEventListener("keydown",g)}},[s]);const f=y=>{const g=new Set(n);g.has(y)?g.delete(y):g.add(y),a(g)},d=t.length===0,h=n.size;return m.jsxs("div",{ref:c,className:"relative",children:[m.jsxs("button",{type:"button",className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>!d&&o(y=>!y),disabled:d,"aria-haspopup":"listbox","aria-expanded":s,"aria-label":`按 ${e} 筛选`,children:[e,h>0&&m.jsx("span",{className:"ml-1 px-1.5 py-0.5 text-[10px] font-bold rounded-full bg-[var(--color-primary)] text-[var(--color-text)] border border-[var(--color-text)]",children:h}),m.jsx(yc,{size:11,strokeWidth:3,className:["transition-transform",s?"rotate-180":""].join(" ")})]}),s&&m.jsxs("div",{role:"listbox",className:"absolute left-0 top-full mt-2 z-20 min-w-[200px] max-h-64 overflow-auto nb-card p-2",style:{padding:8},children:[t.map(y=>{const g=n.has(y);return m.jsxs("label",{className:["flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer text-sm font-[family-name:var(--font-mono)]",g?"bg-[var(--color-accent-mint)]":"hover:bg-[var(--color-bg-cream)]"].join(" "),children:[m.jsx("input",{type:"checkbox",checked:g,onChange:()=>f(y),className:"flex-shrink-0"}),m.jsx("span",{className:"truncate",children:y})]},y)}),h>0&&m.jsx("button",{type:"button",className:"w-full mt-2 pt-2 border-t-2 border-dashed border-[var(--color-text)] text-xs font-bold text-[var(--color-crashed)] text-center",onClick:()=>a(new Set),children:"清空选择"})]})]})}function vR(){return qt("/api/workers/all")}function ER(e){return qt(`/api/projects/${encodeURIComponent(e)}/workers`)}function SR(e,t){return qt(`/api/projects/${encodeURIComponent(e)}/workers/${t}`)}async function sS(e,t){const n=await fetch(e,{method:"POST",headers:t?{"Content-Type":"application/json"}:void 0,body:t?JSON.stringify(t):void 0});if(!n.ok)throw new Error(`${n.status}: ${await n.text()}`);return n.json().catch(()=>({}))}function e0(e,t){return sS(`/api/projects/${encodeURIComponent(e)}/workers/${t}/kill`)}function wR(e,t,n){return sS(`/api/projects/${encodeURIComponent(e)}/workers/${t}/launch`,n?{seq:n}:void 0)}function og({state:e}){const n={running:{bg:"var(--color-running-bg)",color:"var(--color-running)",label:"running"},starting:{bg:"var(--color-secondary)",color:"var(--color-text)",label:"starting",icon:m.jsx(Zt,{size:9,strokeWidth:3,className:"animate-spin"})},stuck:{bg:"var(--color-stuck-bg)",color:"var(--color-stuck)",label:"stuck"},crashed:{bg:"var(--color-crashed-bg)",color:"var(--color-crashed)",label:"crashed",icon:m.jsx(SA,{size:9,strokeWidth:2.5})},idle:{bg:"var(--color-idle-bg)",color:"var(--color-idle)",label:"idle"}}[e];return m.jsxs("span",{className:"nb-status inline-flex items-center gap-1",style:{background:n.bg,color:n.color},children:[n.icon,n.label]})}function cg(e){if(e==null||e<=0)return"—";const t=Math.floor(e/1e3),n=Math.floor(t/3600),a=Math.floor(t%3600/60),s=t%60;return n>0?`${n}h ${a}m`:a>0?`${a}m ${s}s`:`${s}s`}function _R(e){if(e==null||e<=0)return"text-[var(--color-text-muted)]";const t=e/6e4;return t<10?"text-[var(--color-running)]":t<60?"text-[var(--color-stuck)]":"text-[var(--color-crashed)]"}function ug(e){const t=Date.now()-new Date(e).getTime();return t<6e4?`${Math.floor(t/1e3)}s 前`:t<36e5?`${Math.floor(t/6e4)}m 前`:`${Math.floor(t/36e5)}h 前`}function kR({alerts:e,selected:t,onSelect:n}){return e.length===0?m.jsxs("div",{className:"nb-card bg-[var(--color-running-bg)] flex items-center gap-3",children:[m.jsx(Pp,{size:18,strokeWidth:2.5,className:"text-[var(--color-running)]"}),m.jsx("span",{className:"text-sm font-bold text-[var(--color-running)]",children:"全部 worker 健康"})]}):m.jsxs("section",{children:[m.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-sm font-bold uppercase tracking-wider mb-2 flex items-center gap-2 text-[var(--color-crashed)]",children:[m.jsx(RA,{size:14,strokeWidth:2.5}),"Alerts (",e.length,")"]}),m.jsx("div",{className:"flex flex-col gap-2",children:e.map(a=>{const s=(t==null?void 0:t.project)===a.project&&(t==null?void 0:t.slot)===a.slot;return m.jsxs("button",{type:"button",onClick:()=>n(a.project,a.slot),className:["nb-card p-3 text-left",a.state==="crashed"?"bg-[var(--color-crashed-bg)]":"bg-[var(--color-stuck-bg)]",s?"ring-4 ring-[var(--color-text)]":""].join(" "),children:[m.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[m.jsx(og,{state:a.state}),m.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold",children:[a.project,"/worker-",a.slot]}),a.card&&m.jsxs("span",{className:"truncate",children:["#",a.card.seq," ",a.card.title]}),m.jsxs("span",{className:"ml-auto text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] flex items-center gap-1",children:[m.jsx(MC,{size:10,strokeWidth:2.5}),cg(a.runtimeMs)]})]}),a.markerUpdatedAt&&m.jsx("div",{className:"text-xs text-[var(--color-text-muted)] mt-1 font-[family-name:var(--font-mono)]",children:a.state==="crashed"?"PID 已死。":`marker 停 ${ug(a.markerUpdatedAt)}。`})]},`${a.project}-${a.slot}`)})})]})}function NR({active:e,selected:t,onSelect:n}){return e.length===0?m.jsx("div",{className:"nb-card bg-[var(--color-bg-cream)]",children:m.jsx("p",{className:"text-sm text-[var(--color-text-muted)] italic",children:"没有 worker 在运行。"})}):m.jsxs("section",{children:[m.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-sm font-bold uppercase tracking-wider mb-2 flex items-center gap-2",children:[m.jsx(jf,{size:14,strokeWidth:2.5}),"Active (",e.length,")"]}),m.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:e.map(a=>{const s=(t==null?void 0:t.project)===a.project&&(t==null?void 0:t.slot)===a.slot;return m.jsxs("button",{type:"button",onClick:()=>n(a.project,a.slot),className:["nb-card p-3 text-left",a.state==="starting"?"bg-[var(--color-secondary)]":"bg-[var(--color-running-bg)]",s?"ring-4 ring-[var(--color-text)]":""].join(" "),children:[m.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[m.jsx(og,{state:a.state}),m.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm flex-1 truncate",children:[a.project,"/worker-",a.slot]}),m.jsx("span",{className:`text-xs font-[family-name:var(--font-mono)] ${_R(a.runtimeMs)}`,children:cg(a.runtimeMs)})]}),a.card&&m.jsxs("div",{className:"text-sm font-semibold mb-1 truncate",children:["#",a.card.seq," · ",a.card.title]}),m.jsxs("div",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] flex items-center gap-2 mb-1",children:[a.stage&&m.jsxs("span",{children:["stage: ",a.stage]}),a.markerUpdatedAt&&m.jsxs("span",{className:"ml-auto",children:["marker ",ug(a.markerUpdatedAt)]})]}),a.lastLogLine&&m.jsxs("div",{className:"text-[11px] font-[family-name:var(--font-mono)] text-[var(--color-text-muted)] bg-[var(--color-bg)] border-2 border-[var(--color-text)] rounded px-2 py-1 mt-2 truncate",children:[m.jsx(t1,{size:9,strokeWidth:2.5,className:"inline-block mr-1 align-text-bottom"}),a.lastLogLine.msg]})]},`${a.project}-${a.slot}`)})})]})}function TR({capacity:e,selected:t,onSelect:n}){return e.length===0?null:m.jsxs("section",{children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-sm font-bold uppercase tracking-wider mb-2",children:"Capacity"}),m.jsx("div",{className:"nb-card p-0 overflow-hidden",children:m.jsxs("table",{className:"w-full text-sm",children:[m.jsx("thead",{children:m.jsxs("tr",{className:"bg-[var(--color-bg-cream)] border-b-2 border-[var(--color-text)]",children:[m.jsx("th",{className:"px-3 py-2 text-left font-bold text-xs uppercase tracking-wider",children:"项目"}),m.jsx("th",{className:"px-3 py-2 text-left font-bold text-xs uppercase tracking-wider",children:"占用"}),m.jsx("th",{className:"px-3 py-2 text-right font-bold text-xs uppercase tracking-wider",children:"running"}),m.jsx("th",{className:"px-3 py-2 text-right font-bold text-xs uppercase tracking-wider",children:"其它"}),m.jsx("th",{className:"px-3 py-2"})]})}),m.jsx("tbody",{children:e.map(a=>{const s=a.running+a.starting+a.stuck+a.crashed,o=(t==null?void 0:t.project)===a.project;return m.jsxs("tr",{onClick:()=>n(a.project),className:["border-b border-dashed border-[var(--color-border-light)] last:border-0 cursor-pointer hover:bg-[var(--color-accent-yellow)]",o?"bg-[var(--color-accent-yellow)]":""].join(" "),children:[m.jsx("td",{className:"px-3 py-2 font-[family-name:var(--font-mono)] font-bold",children:a.project}),m.jsx("td",{className:"px-3 py-2",children:m.jsx(CR,{total:a.total,cap:a})}),m.jsxs("td",{className:"px-3 py-2 text-right font-[family-name:var(--font-mono)]",children:[m.jsx("span",{className:"text-[var(--color-running)] font-bold",children:a.running}),m.jsxs("span",{className:"text-[var(--color-text-muted)]",children:["/",a.total]})]}),m.jsxs("td",{className:"px-3 py-2 text-right text-xs font-[family-name:var(--font-mono)] text-[var(--color-text-muted)]",children:[a.starting>0&&m.jsxs("span",{className:"mr-2",children:["starting ",a.starting]}),a.stuck>0&&m.jsxs("span",{className:"text-[var(--color-stuck)] font-bold mr-2",children:["stuck ",a.stuck]}),a.crashed>0&&m.jsxs("span",{className:"text-[var(--color-crashed)] font-bold mr-2",children:["crashed ",a.crashed]}),s===0&&m.jsx("span",{children:"idle"})]}),m.jsx("td",{className:"px-3 py-2 text-right",children:m.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:"详情 →"})})]},a.project)})})]})})]})}function CR({total:e,cap:t}){const n=[];for(let a=0;a<t.crashed;a++)n.push("crashed");for(let a=0;a<t.stuck;a++)n.push("stuck");for(let a=0;a<t.starting;a++)n.push("starting");for(let a=0;a<t.running;a++)n.push("running");for(let a=0;a<t.idle;a++)n.push("idle");return m.jsxs("div",{className:"flex gap-1 items-center",children:[n.map((a,s)=>m.jsx("span",{className:"inline-block w-3 h-3 rounded-full border-2 border-[var(--color-text)]",style:{background:AR(a)},title:a},s)),m.jsxs("span",{className:"text-xs text-[var(--color-text-muted)] ml-2 font-[family-name:var(--font-mono)]",children:[e," slot",e!==1?"s":""]})]})}function AR(e){switch(e){case"running":return"var(--color-running-bg)";case"starting":return"var(--color-secondary)";case"stuck":return"var(--color-stuck-bg)";case"crashed":return"var(--color-crashed-bg)";default:return"var(--color-idle-bg)"}}function OR({project:e,initialSlot:t,onChange:n}){var d;const a=dt({queryKey:["workers",e],queryFn:()=>ER(e),refetchInterval:3e3}),s=((d=a.data)==null?void 0:d.data)??[],[o,c]=M.useState(null);M.useEffect(()=>{if(s.length===0){c(null);return}const h=s[0].slot;c(y=>y!=null&&s.some(g=>g.slot===y)?y:t!=null&&s.some(g=>g.slot===t)?t:h)},[e,t,s.length]);const f=s.find(h=>h.slot===o)??null;return m.jsxs("div",{className:"flex flex-col h-full",children:[m.jsxs("div",{className:"px-4 py-3 border-b-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[m.jsxs("div",{className:"flex items-center justify-between mb-2",children:[m.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold truncate",children:e}),m.jsx(fs,{to:`/board?project=${encodeURIComponent(e)}`,className:"text-xs underline text-[var(--color-text-muted)] hover:text-[var(--color-text)]",children:"看板 →"})]}),a.isLoading&&s.length===0?m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"加载 workers…"}):s.length===0?m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"该项目没有 worker slot。"}):m.jsx("div",{className:"flex flex-wrap gap-2",children:s.map(h=>m.jsx(RR,{worker:h,active:h.slot===o,onClick:()=>c(h.slot)},h.slot))})]}),f?m.jsx(MR,{project:e,worker:f,onChange:n}):m.jsx("div",{className:"flex-1 flex items-center justify-center p-6 text-center",children:m.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:s.length===0?"无 worker":"请选择一个 worker"})})]})}function RR({worker:e,active:t,onClick:n}){return m.jsxs("button",{type:"button",onClick:n,className:["nb-card p-2 text-left min-w-[130px] transition-transform",t?"ring-4 ring-[var(--color-text)]":"opacity-80 hover:opacity-100"].join(" "),children:[m.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[m.jsx(og,{state:e.state}),m.jsxs("span",{className:"font-[family-name:var(--font-mono)] font-bold text-xs",children:["worker-",e.slot]})]}),e.card?m.jsxs("div",{className:"text-[11px] truncate font-[family-name:var(--font-mono)]",children:["#",e.card.seq," ",e.card.title]}):m.jsx("div",{className:"text-[11px] text-[var(--color-text-muted)] italic",children:"空闲"})]})}function MR({project:e,worker:t,onChange:n}){var h,y;const{confirm:a,alert:s}=si(),o=t.state==="crashed"||t.state==="stuck",c=dt({queryKey:["worker-detail",e,t.slot],queryFn:()=>SR(e,t.slot),refetchInterval:3e3}),f=((h=c.data)==null?void 0:h.recentOutput)??[],d=((y=c.data)==null?void 0:y.recentLogs)??[];return m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex-1 overflow-auto p-4 flex flex-col gap-4",children:[t.card?m.jsxs("div",{children:[m.jsx("div",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-1",children:"当前卡片"}),m.jsxs("div",{className:"text-sm font-semibold break-words",children:["#",t.card.seq," · ",t.card.title]})]}):m.jsx("div",{className:"text-sm text-[var(--color-text-muted)] italic",children:"slot 空闲,没有当前卡片。"}),m.jsxs("dl",{className:"grid grid-cols-[100px_1fr] gap-y-2 text-sm",children:[m.jsx("dt",{className:"font-bold",children:"Stage"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.stage??"—"}),m.jsx("dt",{className:"font-bold",children:"PID"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:t.pid??"—"}),m.jsx("dt",{className:"font-bold",children:"Runtime"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:cg(t.runtimeMs)}),m.jsx("dt",{className:"font-bold",children:"Started"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)] text-xs",children:t.startedAt?new Date(t.startedAt).toLocaleString():"—"}),m.jsx("dt",{className:"font-bold",children:"Marker"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)] text-xs",children:t.markerUpdatedAt?ug(t.markerUpdatedAt):"—"})]}),m.jsxs("div",{children:[m.jsxs("div",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-1 flex items-center gap-1",children:[m.jsx(t1,{size:10,strokeWidth:2.5}),"Claude 输出 · 最近 ",f.length," 行"]}),c.isLoading&&f.length===0?m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"加载中…"}):f.length===0?m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] italic",children:"还没收到 session 输出。Worker 刚启动时需要几秒。"}):m.jsx("pre",{className:"text-xs font-[family-name:var(--font-mono)] bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded p-2 max-h-80 overflow-auto whitespace-pre-wrap break-words",children:f.map(g=>`${g.ts?`${g.ts} [${g.kind}] `:`[${g.kind}] `}${g.text}`).join(`
478
478
  `)})]}),d.length>0&&m.jsxs("div",{children:[m.jsxs("div",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-1 opacity-60",children:["Supervisor 心跳 · 最近 ",d.length," 行"]}),m.jsx("pre",{className:"text-xs font-[family-name:var(--font-mono)] bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded p-2 max-h-40 overflow-auto whitespace-pre-wrap break-words opacity-80",children:d.map(g=>`${g.ts??""} [${g.level}] ${g.msg}`).join(`
479
- `)}),m.jsx(fs,{to:`/logs?project=${encodeURIComponent(e)}&worker=${t.slot}`,className:"text-xs underline text-[var(--color-running)] mt-1 inline-block",children:"查看完整 log →"})]})]}),m.jsxs("div",{className:"px-4 py-3 border-t-2 border-[var(--color-text)] bg-[var(--color-bg-cream)] flex gap-2 justify-end flex-wrap",children:[o&&t.card&&m.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",style:{padding:"4px 10px",fontSize:11},onClick:async()=>{if(await a({title:`重启 worker-${t.slot}`,body:`先杀进程,再重新 launch 到 #${t.card.seq}`,confirm:"重启"})){try{await e0(e,t.slot)}catch{}try{await wR(e,t.slot,t.card.seq),n()}catch(x){s({title:"重启失败",body:x instanceof Error?x.message:String(x)})}}},children:[m.jsx(CA,{size:11,strokeWidth:2.5})," 重启"]}),t.state!=="idle"&&m.jsxs("button",{type:"button",className:"nb-btn nb-btn-danger",style:{padding:"4px 10px",fontSize:11},onClick:async()=>{if(await a({title:`终止 worker-${t.slot}`,body:"当前任务强制中断。",confirm:"终止",danger:!0}))try{await e0(e,t.slot),n()}catch(x){s({title:"终止失败",body:x instanceof Error?x.message:String(x)})}},children:[m.jsx(zA,{size:11,strokeWidth:2.5})," 终止"]})]})]})}function og({state:e}){const n={running:{bg:"var(--color-running-bg)",color:"var(--color-running)",label:"running"},starting:{bg:"var(--color-secondary)",color:"var(--color-text)",label:"starting",icon:m.jsx(Zt,{size:9,strokeWidth:3,className:"animate-spin"})},stuck:{bg:"var(--color-stuck-bg)",color:"var(--color-stuck)",label:"stuck"},crashed:{bg:"var(--color-crashed-bg)",color:"var(--color-crashed)",label:"crashed",icon:m.jsx(SA,{size:9,strokeWidth:2.5})},idle:{bg:"var(--color-idle-bg)",color:"var(--color-idle)",label:"idle"}}[e];return m.jsxs("span",{className:"nb-status inline-flex items-center gap-1",style:{background:n.bg,color:n.color},children:[n.icon,n.label]})}function cg(e){if(e==null||e<=0)return"—";const t=Math.floor(e/1e3),n=Math.floor(t/3600),a=Math.floor(t%3600/60),s=t%60;return n>0?`${n}h ${a}m`:a>0?`${a}m ${s}s`:`${s}s`}function jR(e){if(e==null||e<=0)return"text-[var(--color-text-muted)]";const t=e/6e4;return t<10?"text-[var(--color-running)]":t<60?"text-[var(--color-stuck)]":"text-[var(--color-crashed)]"}function ug(e){const t=Date.now()-new Date(e).getTime();return t<1e4?`${Math.floor(t/1e3)}s 前`:t<6e4?`${Math.floor(t/1e3)}s 前`:t<36e5?`${Math.floor(t/6e4)}m 前`:`${Math.floor(t/36e5)}h 前`}function DR(e){const t=new URLSearchParams;return e.project&&t.set("project",e.project),e.worker&&t.set("worker",e.worker),t.set("limit",String(e.limit)),e.since&&t.set("since",e.since),qt(`/api/logs?${t}`)}function LR(e){const t=new URLSearchParams({project:e.project});return e.worker&&t.set("worker",e.worker),`/stream/logs?${t}`}const IR=["error","warn","info","debug"],zR=["error","warn","info"];function BR(){var U,Z;const[e,t]=QE(),n=e.get("project"),a=e.get("worker")??"",[s,o]=M.useState([]),[c,f]=M.useState(!1),[d,h]=M.useState(!0),[y,g]=M.useState(()=>new Set(zR)),[x,v]=M.useState(""),[S,w]=M.useState("live"),[_,k]=M.useState(()=>{const A=new Date(Date.now()-36e5),P=G=>String(G).padStart(2,"0");return`${A.getFullYear()}-${P(A.getMonth()+1)}-${P(A.getDate())}T${P(A.getHours())}:${P(A.getMinutes())}`}),R=M.useRef(null),C=!n,D=dt({queryKey:["projects"],queryFn:ds}),{data:$,refetch:j}=dt({queryKey:["logs",n??"agg",a,S,S==="history"?_:"live"],queryFn:()=>DR({project:n||void 0,worker:a||void 0,limit:S==="history"?2e3:500,since:S==="history"?new Date(_).toISOString():void 0}),refetchInterval:C&&S==="live"?5e3:!1});M.useEffect(()=>{$!=null&&$.data&&o($.data)},[$]),M.useEffect(()=>{if(!n||S!=="live")return;const A=LR({project:n,worker:a||void 0}),P=new EventSource(A);return P.addEventListener("log.line",G=>{if(!c)try{const le=JSON.parse(G.data);o(ae=>{const W=[...ae,le];return W.length>5e3&&W.splice(0,W.length-5e3),W})}catch{}}),()=>P.close()},[n,a,c,S]),M.useEffect(()=>{if(!d)return;const A=R.current;A&&(A.scrollTop=A.scrollHeight)},[s,d]);const q=M.useMemo(()=>{const A=x.toLowerCase();return s.filter(P=>!(!y.has(P.level)||A&&!P.msg.toLowerCase().includes(A)))},[s,y,x]);return m.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[m.jsx("header",{className:"flex items-center justify-between gap-3 flex-wrap",children:m.jsxs("div",{children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold tracking-tight",children:"Logs 📜"}),m.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:[C?`全部项目(${((U=D.data)==null?void 0:U.data.length)??0})`:n,a&&` · worker-${a}`," · ",C&&S==="live"?"5s 轮询":"tail -f"," · ",s.length," lines",c&&m.jsx("span",{className:"text-[var(--color-stuck)] ml-2 font-bold",children:"⏸ PAUSED"})]})]})}),m.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m.jsxs("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:[m.jsxs("button",{type:"button",onClick:()=>w("live"),"aria-pressed":S==="live",className:["px-3 py-1 rounded-full text-xs font-bold flex items-center gap-1.5",S==="live"?"bg-[var(--color-primary)] text-[var(--color-text)] shadow-[1px_1px_0_var(--color-text)]":"text-[var(--color-text-muted)]"].join(" "),children:[m.jsx(ZE,{size:11,strokeWidth:2.5}),"实时"]}),m.jsxs("button",{type:"button",onClick:()=>w("history"),"aria-pressed":S==="history",className:["px-3 py-1 rounded-full text-xs font-bold flex items-center gap-1.5",S==="history"?"bg-[var(--color-primary)] text-[var(--color-text)] shadow-[1px_1px_0_var(--color-text)]":"text-[var(--color-text-muted)]"].join(" "),children:[m.jsx(ZC,{size:11,strokeWidth:2.5}),"历史"]})]}),S==="history"&&m.jsxs(m.Fragment,{children:[m.jsx("input",{type:"datetime-local",className:"nb-input",style:{padding:"4px 8px",fontSize:12},value:_,onChange:A=>k(A.target.value),"aria-label":"查询起始时间"}),m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px",fontSize:12},onClick:()=>j(),type:"button","aria-label":"查询",children:[m.jsx(xf,{size:11,strokeWidth:3}),"查询"]})]}),m.jsxs("div",{className:"relative",children:[m.jsx(qC,{size:14,strokeWidth:2.5,className:"absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none text-[var(--color-text)]"}),m.jsxs("select",{className:"nb-input appearance-none pl-9 pr-9 font-[family-name:var(--font-mono)] cursor-pointer",style:{padding:"10px 36px 10px 36px",fontSize:13,minWidth:180},value:n??"",onChange:A=>{const P=A.target.value;t(P?{project:P}:{})},"aria-label":"筛选项目",children:[m.jsx("option",{value:"",children:"全部项目"}),(Z=D.data)==null?void 0:Z.data.map(A=>m.jsx("option",{value:A.name,children:A.name},A.name))]}),m.jsx(yc,{size:14,strokeWidth:3,className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-[var(--color-text)]"})]}),m.jsxs("div",{className:"relative flex-1 max-w-md",children:[m.jsx(xf,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),m.jsx("input",{className:"nb-input pl-9 w-full",placeholder:"过滤关键字…",value:x,onChange:A=>v(A.target.value),"aria-label":"过滤日志"})]}),m.jsx("div",{className:"flex items-center gap-1 p-1 bg-[var(--color-bg)] border-[2px] border-[var(--color-text)] rounded-full shadow-[2px_2px_0_var(--color-text)]",children:IR.map(A=>m.jsx(UR,{level:A,enabled:y.has(A),onToggle:()=>{g(P=>{const G=new Set(P);return G.has(A)?G.delete(A):G.add(A),G})}},A))}),m.jsxs("div",{className:"ml-auto flex gap-2",children:[S==="live"&&m.jsxs(m.Fragment,{children:[m.jsx("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>h(A=>!A),type:"button",children:d?"✓ Auto-scroll":"Auto-scroll"}),m.jsx("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>f(A=>!A),type:"button",children:c?m.jsxs(m.Fragment,{children:[m.jsx(Kp,{size:12,strokeWidth:3})," Resume"]}):m.jsxs(m.Fragment,{children:[m.jsx(cA,{size:12,strokeWidth:3})," Pause"]})})]}),m.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>{const A=new Blob([q.map(le=>le.raw).join(`
479
+ `)}),m.jsx(fs,{to:`/logs?project=${encodeURIComponent(e)}&worker=${t.slot}`,className:"text-xs underline text-[var(--color-running)] mt-1 inline-block",children:"查看完整 log →"})]})]}),m.jsxs("div",{className:"px-4 py-3 border-t-2 border-[var(--color-text)] bg-[var(--color-bg-cream)] flex gap-2 justify-end flex-wrap",children:[o&&t.card&&m.jsxs("button",{type:"button",className:"nb-btn nb-btn-mint",style:{padding:"4px 10px",fontSize:11},onClick:async()=>{if(await a({title:`重启 worker-${t.slot}`,body:`先杀进程,再重新 launch 到 #${t.card.seq}`,confirm:"重启"})){try{await e0(e,t.slot)}catch{}try{await wR(e,t.slot,t.card.seq),n()}catch(x){s({title:"重启失败",body:x instanceof Error?x.message:String(x)})}}},children:[m.jsx(CA,{size:11,strokeWidth:2.5})," 重启"]}),t.state!=="idle"&&m.jsxs("button",{type:"button",className:"nb-btn nb-btn-danger",style:{padding:"4px 10px",fontSize:11},onClick:async()=>{if(await a({title:`终止 worker-${t.slot}`,body:"当前任务强制中断。",confirm:"终止",danger:!0}))try{await e0(e,t.slot),n()}catch(x){s({title:"终止失败",body:x instanceof Error?x.message:String(x)})}},children:[m.jsx(zA,{size:11,strokeWidth:2.5})," 终止"]})]})]})}function jR(){var o;const e=Pn(),[t,n]=M.useState(null),a=dt({queryKey:["workers-agg"],queryFn:vR,refetchInterval:5e3});M.useEffect(()=>{if(!a.data)return;const c=a.data.capacity.map(d=>d.project),f=[];for(const d of c){const h=new EventSource(`/stream/projects/${encodeURIComponent(d)}`),y=()=>{e.invalidateQueries({queryKey:["workers-agg"]})};h.addEventListener("worker.updated",y),h.addEventListener("worker.added",y),h.addEventListener("worker.deleted",y),h.addEventListener("card.updated",y),f.push(h)}return()=>{for(const d of f)d.close()}},[(o=a.data)==null?void 0:o.capacity.map(c=>c.project).join(","),e]);const s=M.useMemo(()=>{if(!a.data)return{projects:0,running:0,starting:0,stuck:0,crashed:0,idle:0};const c={projects:a.data.capacity.length,running:0,starting:0,stuck:0,crashed:0,idle:0};for(const f of a.data.capacity)c.running+=f.running,c.starting+=f.starting,c.stuck+=f.stuck,c.crashed+=f.crashed,c.idle+=f.idle;return c},[a.data]);return m.jsxs("div",{className:"flex flex-col gap-4 h-[calc(100vh-140px)]",children:[m.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[m.jsxs("div",{children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold tracking-tight",children:"Workers 👷"}),m.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:["跨 ",s.projects," 项目 · ",s.running," 跑 · ",s.starting," 启动 ·"," ",m.jsxs("span",{className:"text-[var(--color-stuck)]",children:[s.stuck," 卡"]})," ·"," ",m.jsxs("span",{className:"text-[var(--color-crashed)]",children:[s.crashed," 崩"]})," · ",s.idle," 闲"]})]}),m.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>a.refetch(),disabled:a.isFetching,type:"button","aria-label":"刷新",children:[a.isFetching?m.jsx(Zt,{size:12,strokeWidth:3,className:"animate-spin"}):m.jsx(Cl,{size:12,strokeWidth:2.5}),"刷新"]})]}),m.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-4 flex-1 min-h-0",children:[m.jsxs("div",{className:"flex flex-col gap-4 overflow-auto pr-2",children:[a.isLoading&&m.jsx("p",{className:"text-[var(--color-text-muted)] italic",children:"加载中…"}),a.isError&&m.jsx("div",{className:"nb-card bg-[var(--color-crashed-bg)]",children:m.jsxs("p",{children:["加载失败: ",a.error instanceof Error?a.error.message:String(a.error)]})}),a.data&&m.jsxs(m.Fragment,{children:[m.jsx(kR,{alerts:a.data.alerts,selected:t,onSelect:(c,f)=>n({project:c,slot:f})}),m.jsx(NR,{active:a.data.active,selected:t,onSelect:(c,f)=>n({project:c,slot:f})}),m.jsx(TR,{capacity:a.data.capacity,selected:t,onSelect:c=>n({project:c})})]})]}),m.jsx("aside",{className:"nb-card p-0 overflow-hidden flex flex-col h-full",children:t?m.jsx(OR,{project:t.project,initialSlot:t.slot,onChange:()=>e.invalidateQueries({queryKey:["workers-agg"]})}):m.jsx("div",{className:"flex-1 flex items-center justify-center p-6 text-center",children:m.jsxs("div",{children:[m.jsx(jf,{size:32,className:"mx-auto mb-3 text-[var(--color-text-subtle)]",strokeWidth:2}),m.jsx("p",{className:"text-sm text-[var(--color-text-muted)]",children:"点击项目 / worker 查看详情"})]})})})]})]})}function DR(e){const t=new URLSearchParams;return e.project&&t.set("project",e.project),e.worker&&t.set("worker",e.worker),t.set("limit",String(e.limit)),e.since&&t.set("since",e.since),qt(`/api/logs?${t}`)}function LR(e){const t=new URLSearchParams({project:e.project});return e.worker&&t.set("worker",e.worker),`/stream/logs?${t}`}const IR=["error","warn","info","debug"],zR=["error","warn","info"];function BR(){var U,Z;const[e,t]=QE(),n=e.get("project"),a=e.get("worker")??"",[s,o]=M.useState([]),[c,f]=M.useState(!1),[d,h]=M.useState(!0),[y,g]=M.useState(()=>new Set(zR)),[x,v]=M.useState(""),[S,w]=M.useState("live"),[_,k]=M.useState(()=>{const A=new Date(Date.now()-36e5),P=G=>String(G).padStart(2,"0");return`${A.getFullYear()}-${P(A.getMonth()+1)}-${P(A.getDate())}T${P(A.getHours())}:${P(A.getMinutes())}`}),R=M.useRef(null),C=!n,D=dt({queryKey:["projects"],queryFn:ds}),{data:$,refetch:j}=dt({queryKey:["logs",n??"agg",a,S,S==="history"?_:"live"],queryFn:()=>DR({project:n||void 0,worker:a||void 0,limit:S==="history"?2e3:500,since:S==="history"?new Date(_).toISOString():void 0}),refetchInterval:C&&S==="live"?5e3:!1});M.useEffect(()=>{$!=null&&$.data&&o($.data)},[$]),M.useEffect(()=>{if(!n||S!=="live")return;const A=LR({project:n,worker:a||void 0}),P=new EventSource(A);return P.addEventListener("log.line",G=>{if(!c)try{const le=JSON.parse(G.data);o(ae=>{const W=[...ae,le];return W.length>5e3&&W.splice(0,W.length-5e3),W})}catch{}}),()=>P.close()},[n,a,c,S]),M.useEffect(()=>{if(!d)return;const A=R.current;A&&(A.scrollTop=A.scrollHeight)},[s,d]);const q=M.useMemo(()=>{const A=x.toLowerCase();return s.filter(P=>!(!y.has(P.level)||A&&!P.msg.toLowerCase().includes(A)))},[s,y,x]);return m.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[m.jsx("header",{className:"flex items-center justify-between gap-3 flex-wrap",children:m.jsxs("div",{children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold tracking-tight",children:"Logs 📜"}),m.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:[C?`全部项目(${((U=D.data)==null?void 0:U.data.length)??0})`:n,a&&` · worker-${a}`," · ",C&&S==="live"?"5s 轮询":"tail -f"," · ",s.length," lines",c&&m.jsx("span",{className:"text-[var(--color-stuck)] ml-2 font-bold",children:"⏸ PAUSED"})]})]})}),m.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m.jsxs("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:[m.jsxs("button",{type:"button",onClick:()=>w("live"),"aria-pressed":S==="live",className:["px-3 py-1 rounded-full text-xs font-bold flex items-center gap-1.5",S==="live"?"bg-[var(--color-primary)] text-[var(--color-text)] shadow-[1px_1px_0_var(--color-text)]":"text-[var(--color-text-muted)]"].join(" "),children:[m.jsx(ZE,{size:11,strokeWidth:2.5}),"实时"]}),m.jsxs("button",{type:"button",onClick:()=>w("history"),"aria-pressed":S==="history",className:["px-3 py-1 rounded-full text-xs font-bold flex items-center gap-1.5",S==="history"?"bg-[var(--color-primary)] text-[var(--color-text)] shadow-[1px_1px_0_var(--color-text)]":"text-[var(--color-text-muted)]"].join(" "),children:[m.jsx(ZC,{size:11,strokeWidth:2.5}),"历史"]})]}),S==="history"&&m.jsxs(m.Fragment,{children:[m.jsx("input",{type:"datetime-local",className:"nb-input",style:{padding:"4px 8px",fontSize:12},value:_,onChange:A=>k(A.target.value),"aria-label":"查询起始时间"}),m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px",fontSize:12},onClick:()=>j(),type:"button","aria-label":"查询",children:[m.jsx(xf,{size:11,strokeWidth:3}),"查询"]})]}),m.jsxs("div",{className:"relative",children:[m.jsx(qC,{size:14,strokeWidth:2.5,className:"absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none text-[var(--color-text)]"}),m.jsxs("select",{className:"nb-input appearance-none pl-9 pr-9 font-[family-name:var(--font-mono)] cursor-pointer",style:{padding:"10px 36px 10px 36px",fontSize:13,minWidth:180},value:n??"",onChange:A=>{const P=A.target.value;t(P?{project:P}:{})},"aria-label":"筛选项目",children:[m.jsx("option",{value:"",children:"全部项目"}),(Z=D.data)==null?void 0:Z.data.map(A=>m.jsx("option",{value:A.name,children:A.name},A.name))]}),m.jsx(yc,{size:14,strokeWidth:3,className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-[var(--color-text)]"})]}),m.jsxs("div",{className:"relative flex-1 max-w-md",children:[m.jsx(xf,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),m.jsx("input",{className:"nb-input pl-9 w-full",placeholder:"过滤关键字…",value:x,onChange:A=>v(A.target.value),"aria-label":"过滤日志"})]}),m.jsx("div",{className:"flex items-center gap-1 p-1 bg-[var(--color-bg)] border-[2px] border-[var(--color-text)] rounded-full shadow-[2px_2px_0_var(--color-text)]",children:IR.map(A=>m.jsx(UR,{level:A,enabled:y.has(A),onToggle:()=>{g(P=>{const G=new Set(P);return G.has(A)?G.delete(A):G.add(A),G})}},A))}),m.jsxs("div",{className:"ml-auto flex gap-2",children:[S==="live"&&m.jsxs(m.Fragment,{children:[m.jsx("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>h(A=>!A),type:"button",children:d?"✓ Auto-scroll":"Auto-scroll"}),m.jsx("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>f(A=>!A),type:"button",children:c?m.jsxs(m.Fragment,{children:[m.jsx(Kp,{size:12,strokeWidth:3})," Resume"]}):m.jsxs(m.Fragment,{children:[m.jsx(cA,{size:12,strokeWidth:3})," Pause"]})})]}),m.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>{const A=new Blob([q.map(le=>le.raw).join(`
480
480
  `)],{type:"text/plain"}),P=URL.createObjectURL(A),G=document.createElement("a");G.href=P,G.download=`${n}-log-${Date.now()}.log`,G.click(),URL.revokeObjectURL(P)},type:"button",children:[m.jsx(XE,{size:12,strokeWidth:2.5})," Export"]})]})]}),m.jsxs("div",{className:"nb-card p-0 overflow-hidden",children:[m.jsxs("div",{className:"px-4 py-2 bg-[var(--color-bg-cream)] border-b-2 border-[var(--color-text)] flex items-center justify-between font-[family-name:var(--font-mono)] text-xs",children:[m.jsx("span",{className:"text-[var(--color-text-muted)]",children:($==null?void 0:$.file)??"~/.coral/projects/.../logs/*.log"}),S==="live"?m.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:"live"}):m.jsx("span",{className:"nb-status",style:{background:"var(--color-accent-purple)",color:"var(--color-text)"},children:"history"})]}),m.jsxs("div",{ref:R,className:"overflow-auto font-[family-name:var(--font-mono)] text-[12px] leading-[22px] max-h-[70vh] bg-[var(--color-bg)] p-2",onScroll:A=>{const P=A.currentTarget;!(P.scrollHeight-P.scrollTop-P.clientHeight<40)&&d&&h(!1)},children:[q.map((A,P)=>m.jsx(FR,{line:A},P)),q.length===0&&m.jsx("div",{className:"text-center py-12 text-[var(--color-text-subtle)]",children:"没有匹配的日志"})]})]})]})}function UR({level:e,enabled:t,onToggle:n}){const a={error:"var(--color-crashed-bg)",warn:"var(--color-stuck-bg)",info:"var(--color-secondary)",debug:"var(--color-accent-purple)"},s={error:"var(--color-crashed)",warn:"var(--color-stuck)",info:"var(--color-text)",debug:"var(--color-text)"};return m.jsx("button",{type:"button",onClick:n,"aria-pressed":t,className:["px-3 py-0.5 rounded-full font-[family-name:var(--font-mono)] text-[10px] font-bold tracking-widest cursor-pointer",t?"border-[1.5px] border-[var(--color-text)]":"text-[var(--color-text-subtle)]"].join(" "),style:t?{background:a[e],color:s[e]}:{},children:e.toUpperCase()})}function FR({line:e}){var a;const t={error:"bg-[var(--color-crashed)] text-[var(--color-text)]",warn:"bg-[var(--color-stuck)] text-[var(--color-text)]",info:"bg-[var(--color-secondary)] text-[var(--color-text)]",debug:"",trace:""},n=!!e.project;return m.jsxs("div",{className:["grid gap-2 px-2 py-0.5 rounded hover:bg-[var(--color-bg-cream)]",n?"grid-cols-[100px_90px_60px_1fr]":"grid-cols-[100px_60px_1fr]"].join(" "),children:[m.jsx("span",{className:"text-[var(--color-text-subtle)] whitespace-nowrap",children:e.ts?((a=e.ts.split("T")[1])==null?void 0:a.replace("Z",""))??e.ts:"--"}),n&&m.jsx("span",{className:"truncate text-[var(--color-text-muted)] font-bold",title:e.project,children:e.project}),m.jsx("span",{className:`text-center font-bold ${t[e.level]??""}`,style:{borderRadius:4,padding:"0 6px"},children:e.level.toUpperCase()}),m.jsx("span",{className:"truncate text-[var(--color-text)]",children:e.msg})]})}function $R(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const PR=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,qR=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,HR={};function t0(e,t){return(HR.jsx?qR:PR).test(e)}const KR=/[ \t\n\f\r]/g;function GR(e){return typeof e=="object"?e.type==="text"?n0(e.value):!1:n0(e)}function n0(e){return e.replace(KR,"")===""}class Sc{constructor(t,n,a){this.normal=n,this.property=t,a&&(this.space=a)}}Sc.prototype.normal={};Sc.prototype.property={};Sc.prototype.space=void 0;function lS(e,t){const n={},a={};for(const s of e)Object.assign(n,s.property),Object.assign(a,s.normal);return new Sc(n,a,t)}function hp(e){return e.toLowerCase()}class qn{constructor(t,n){this.attribute=n,this.property=t}}qn.prototype.attribute="";qn.prototype.booleanish=!1;qn.prototype.boolean=!1;qn.prototype.commaOrSpaceSeparated=!1;qn.prototype.commaSeparated=!1;qn.prototype.defined=!1;qn.prototype.mustUseProperty=!1;qn.prototype.number=!1;qn.prototype.overloadedBoolean=!1;qn.prototype.property="";qn.prototype.spaceSeparated=!1;qn.prototype.space=void 0;let QR=0;const $e=ps(),Xt=ps(),mp=ps(),fe=ps(),St=ps(),pl=ps(),ti=ps();function ps(){return 2**++QR}const pp=Object.freeze(Object.defineProperty({__proto__:null,boolean:$e,booleanish:Xt,commaOrSpaceSeparated:ti,commaSeparated:pl,number:fe,overloadedBoolean:mp,spaceSeparated:St},Symbol.toStringTag,{value:"Module"})),Em=Object.keys(pp);class fg extends qn{constructor(t,n,a,s){let o=-1;if(super(t,n),i0(this,"space",s),typeof a=="number")for(;++o<Em.length;){const c=Em[o];i0(this,Em[o],(a&pp[c])===pp[c])}}}fg.prototype.defined=!0;function i0(e,t,n){n&&(e[t]=n)}function Hl(e){const t={},n={};for(const[a,s]of Object.entries(e.properties)){const o=new fg(a,e.transform(e.attributes||{},a),s,e.space);e.mustUseProperty&&e.mustUseProperty.includes(a)&&(o.mustUseProperty=!0),t[a]=o,n[hp(a)]=a,n[hp(o.attribute)]=a}return new Sc(t,n,e.space)}const oS=Hl({properties:{ariaActiveDescendant:null,ariaAtomic:Xt,ariaAutoComplete:null,ariaBusy:Xt,ariaChecked:Xt,ariaColCount:fe,ariaColIndex:fe,ariaColSpan:fe,ariaControls:St,ariaCurrent:null,ariaDescribedBy:St,ariaDetails:null,ariaDisabled:Xt,ariaDropEffect:St,ariaErrorMessage:null,ariaExpanded:Xt,ariaFlowTo:St,ariaGrabbed:Xt,ariaHasPopup:null,ariaHidden:Xt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:St,ariaLevel:fe,ariaLive:null,ariaModal:Xt,ariaMultiLine:Xt,ariaMultiSelectable:Xt,ariaOrientation:null,ariaOwns:St,ariaPlaceholder:null,ariaPosInSet:fe,ariaPressed:Xt,ariaReadOnly:Xt,ariaRelevant:null,ariaRequired:Xt,ariaRoleDescription:St,ariaRowCount:fe,ariaRowIndex:fe,ariaRowSpan:fe,ariaSelected:Xt,ariaSetSize:fe,ariaSort:null,ariaValueMax:fe,ariaValueMin:fe,ariaValueNow:fe,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function cS(e,t){return t in e?e[t]:t}function uS(e,t){return cS(e,t.toLowerCase())}const YR=Hl({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:pl,acceptCharset:St,accessKey:St,action:null,allow:null,allowFullScreen:$e,allowPaymentRequest:$e,allowUserMedia:$e,alt:null,as:null,async:$e,autoCapitalize:null,autoComplete:St,autoFocus:$e,autoPlay:$e,blocking:St,capture:null,charSet:null,checked:$e,cite:null,className:St,cols:fe,colSpan:null,content:null,contentEditable:Xt,controls:$e,controlsList:St,coords:fe|pl,crossOrigin:null,data:null,dateTime:null,decoding:null,default:$e,defer:$e,dir:null,dirName:null,disabled:$e,download:mp,draggable:Xt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:$e,formTarget:null,headers:St,height:fe,hidden:mp,high:fe,href:null,hrefLang:null,htmlFor:St,httpEquiv:St,id:null,imageSizes:null,imageSrcSet:null,inert:$e,inputMode:null,integrity:null,is:null,isMap:$e,itemId:null,itemProp:St,itemRef:St,itemScope:$e,itemType:St,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:$e,low:fe,manifest:null,max:null,maxLength:fe,media:null,method:null,min:null,minLength:fe,multiple:$e,muted:$e,name:null,nonce:null,noModule:$e,noValidate:$e,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:$e,optimum:fe,pattern:null,ping:St,placeholder:null,playsInline:$e,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:$e,referrerPolicy:null,rel:St,required:$e,reversed:$e,rows:fe,rowSpan:fe,sandbox:St,scope:null,scoped:$e,seamless:$e,selected:$e,shadowRootClonable:$e,shadowRootDelegatesFocus:$e,shadowRootMode:null,shape:null,size:fe,sizes:null,slot:null,span:fe,spellCheck:Xt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:fe,step:null,style:null,tabIndex:fe,target:null,title:null,translate:null,type:null,typeMustMatch:$e,useMap:null,value:Xt,width:fe,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:St,axis:null,background:null,bgColor:null,border:fe,borderColor:null,bottomMargin:fe,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:$e,declare:$e,event:null,face:null,frame:null,frameBorder:null,hSpace:fe,leftMargin:fe,link:null,longDesc:null,lowSrc:null,marginHeight:fe,marginWidth:fe,noResize:$e,noHref:$e,noShade:$e,noWrap:$e,object:null,profile:null,prompt:null,rev:null,rightMargin:fe,rules:null,scheme:null,scrolling:Xt,standby:null,summary:null,text:null,topMargin:fe,valueType:null,version:null,vAlign:null,vLink:null,vSpace:fe,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:$e,disableRemotePlayback:$e,prefix:null,property:null,results:fe,security:null,unselectable:null},space:"html",transform:uS}),VR=Hl({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:ti,accentHeight:fe,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:fe,amplitude:fe,arabicForm:null,ascent:fe,attributeName:null,attributeType:null,azimuth:fe,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:fe,by:null,calcMode:null,capHeight:fe,className:St,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:fe,diffuseConstant:fe,direction:null,display:null,dur:null,divisor:fe,dominantBaseline:null,download:$e,dx:null,dy:null,edgeMode:null,editable:null,elevation:fe,enableBackground:null,end:null,event:null,exponent:fe,externalResourcesRequired:null,fill:null,fillOpacity:fe,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:pl,g2:pl,glyphName:pl,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:fe,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:fe,horizOriginX:fe,horizOriginY:fe,id:null,ideographic:fe,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:fe,k:fe,k1:fe,k2:fe,k3:fe,k4:fe,kernelMatrix:ti,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:fe,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:fe,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:fe,overlineThickness:fe,paintOrder:null,panose1:null,path:null,pathLength:fe,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:St,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:fe,pointsAtY:fe,pointsAtZ:fe,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:ti,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:ti,rev:ti,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:ti,requiredFeatures:ti,requiredFonts:ti,requiredFormats:ti,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:fe,specularExponent:fe,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:fe,strikethroughThickness:fe,string:null,stroke:null,strokeDashArray:ti,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:fe,strokeOpacity:fe,strokeWidth:null,style:null,surfaceScale:fe,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:ti,tabIndex:fe,tableValues:null,target:null,targetX:fe,targetY:fe,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:ti,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:fe,underlineThickness:fe,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:fe,values:null,vAlphabetic:fe,vMathematical:fe,vectorEffect:null,vHanging:fe,vIdeographic:fe,version:null,vertAdvY:fe,vertOriginX:fe,vertOriginY:fe,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:fe,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:cS}),fS=Hl({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),dS=Hl({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:uS}),hS=Hl({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),XR={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},ZR=/[A-Z]/g,a0=/-[a-z]/g,WR=/^data[-\w.:]+$/i;function JR(e,t){const n=hp(t);let a=t,s=qn;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&WR.test(t)){if(t.charAt(4)==="-"){const o=t.slice(5).replace(a0,tM);a="data"+o.charAt(0).toUpperCase()+o.slice(1)}else{const o=t.slice(4);if(!a0.test(o)){let c=o.replace(ZR,eM);c.charAt(0)!=="-"&&(c="-"+c),t="data"+c}}s=fg}return new s(a,t)}function eM(e){return"-"+e.toLowerCase()}function tM(e){return e.charAt(1).toUpperCase()}const nM=lS([oS,YR,fS,dS,hS],"html"),dg=lS([oS,VR,fS,dS,hS],"svg");function iM(e){return e.join(" ").trim()}var al={},Sm,r0;function aM(){if(r0)return Sm;r0=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,s=/^:\s*/,o=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,f=/^\s+|\s+$/g,d=`
481
481
  `,h="/",y="*",g="",x="comment",v="declaration";function S(_,k){if(typeof _!="string")throw new TypeError("First argument must be a string");if(!_)return[];k=k||{};var R=1,C=1;function D(ae){var W=ae.match(t);W&&(R+=W.length);var K=ae.lastIndexOf(d);C=~K?ae.length-K:C+ae.length}function $(){var ae={line:R,column:C};return function(W){return W.position=new j(ae),Z(),W}}function j(ae){this.start=ae,this.end={line:R,column:C},this.source=k.source}j.prototype.content=_;function q(ae){var W=new Error(k.source+":"+R+":"+C+": "+ae);if(W.reason=ae,W.filename=k.source,W.line=R,W.column=C,W.source=_,!k.silent)throw W}function U(ae){var W=ae.exec(_);if(W){var K=W[0];return D(K),_=_.slice(K.length),W}}function Z(){U(n)}function A(ae){var W;for(ae=ae||[];W=P();)W!==!1&&ae.push(W);return ae}function P(){var ae=$();if(!(h!=_.charAt(0)||y!=_.charAt(1))){for(var W=2;g!=_.charAt(W)&&(y!=_.charAt(W)||h!=_.charAt(W+1));)++W;if(W+=2,g===_.charAt(W-1))return q("End of comment missing");var K=_.slice(2,W-2);return C+=2,D(K),_=_.slice(W),C+=2,ae({type:x,comment:K})}}function G(){var ae=$(),W=U(a);if(W){if(P(),!U(s))return q("property missing ':'");var K=U(o),oe=ae({type:v,property:w(W[0].replace(e,g)),value:K?w(K[0].replace(e,g)):g});return U(c),oe}}function le(){var ae=[];A(ae);for(var W;W=G();)W!==!1&&(ae.push(W),A(ae));return ae}return Z(),le()}function w(_){return _?_.replace(f,g):g}return Sm=S,Sm}var s0;function rM(){if(s0)return al;s0=1;var e=al&&al.__importDefault||function(a){return a&&a.__esModule?a:{default:a}};Object.defineProperty(al,"__esModule",{value:!0}),al.default=n;const t=e(aM());function n(a,s){let o=null;if(!a||typeof a!="string")return o;const c=(0,t.default)(a),f=typeof s=="function";return c.forEach(d=>{if(d.type!=="declaration")return;const{property:h,value:y}=d;f?s(h,y,d):y&&(o=o||{},o[h]=y)}),o}return al}var Ko={},l0;function sM(){if(l0)return Ko;l0=1,Object.defineProperty(Ko,"__esModule",{value:!0}),Ko.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,a=/^-(webkit|moz|ms|o|khtml)-/,s=/^-(ms)-/,o=function(h){return!h||n.test(h)||e.test(h)},c=function(h,y){return y.toUpperCase()},f=function(h,y){return"".concat(y,"-")},d=function(h,y){return y===void 0&&(y={}),o(h)?h:(h=h.toLowerCase(),y.reactCompat?h=h.replace(s,f):h=h.replace(a,f),h.replace(t,c))};return Ko.camelCase=d,Ko}var Go,o0;function lM(){if(o0)return Go;o0=1;var e=Go&&Go.__importDefault||function(s){return s&&s.__esModule?s:{default:s}},t=e(rM()),n=sM();function a(s,o){var c={};return!s||typeof s!="string"||(0,t.default)(s,function(f,d){f&&d&&(c[(0,n.camelCase)(f,o)]=d)}),c}return a.default=a,Go=a,Go}var oM=lM();const cM=Np(oM),mS=pS("end"),hg=pS("start");function pS(e){return t;function t(n){const a=n&&n.position&&n.position[e]||{};if(typeof a.line=="number"&&a.line>0&&typeof a.column=="number"&&a.column>0)return{line:a.line,column:a.column,offset:typeof a.offset=="number"&&a.offset>-1?a.offset:void 0}}}function uM(e){const t=hg(e),n=mS(e);if(t&&n)return{start:t,end:n}}function Jo(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?c0(e.position):"start"in e||"end"in e?c0(e):"line"in e||"column"in e?gp(e):""}function gp(e){return u0(e&&e.line)+":"+u0(e&&e.column)}function c0(e){return gp(e&&e.start)+"-"+gp(e&&e.end)}function u0(e){return e&&typeof e=="number"?e:1}class bn extends Error{constructor(t,n,a){super(),typeof n=="string"&&(a=n,n=void 0);let s="",o={},c=!1;if(n&&("line"in n&&"column"in n?o={place:n}:"start"in n&&"end"in n?o={place:n}:"type"in n?o={ancestors:[n],place:n.position}:o={...n}),typeof t=="string"?s=t:!o.cause&&t&&(c=!0,s=t.message,o.cause=t),!o.ruleId&&!o.source&&typeof a=="string"){const d=a.indexOf(":");d===-1?o.ruleId=a:(o.source=a.slice(0,d),o.ruleId=a.slice(d+1))}if(!o.place&&o.ancestors&&o.ancestors){const d=o.ancestors[o.ancestors.length-1];d&&(o.place=d.position)}const f=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=f?f.column:void 0,this.fatal=void 0,this.file="",this.message=s,this.line=f?f.line:void 0,this.name=Jo(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=c&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}bn.prototype.file="";bn.prototype.name="";bn.prototype.reason="";bn.prototype.message="";bn.prototype.stack="";bn.prototype.column=void 0;bn.prototype.line=void 0;bn.prototype.ancestors=void 0;bn.prototype.cause=void 0;bn.prototype.fatal=void 0;bn.prototype.place=void 0;bn.prototype.ruleId=void 0;bn.prototype.source=void 0;const mg={}.hasOwnProperty,fM=new Map,dM=/[A-Z]/g,hM=new Set(["table","tbody","thead","tfoot","tr"]),mM=new Set(["td","th"]),gS="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function pM(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let a;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");a=wM(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");a=SM(n,t.jsx,t.jsxs)}const s={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:a,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?dg:nM,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},o=bS(s,e,void 0);return o&&typeof o!="string"?o:s.create(e,s.Fragment,{children:o||void 0},void 0)}function bS(e,t,n){if(t.type==="element")return gM(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return bM(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return xM(e,t,n);if(t.type==="mdxjsEsm")return yM(e,t);if(t.type==="root")return vM(e,t,n);if(t.type==="text")return EM(e,t)}function gM(e,t,n){const a=e.schema;let s=a;t.tagName.toLowerCase()==="svg"&&a.space==="html"&&(s=dg,e.schema=s),e.ancestors.push(t);const o=xS(e,t.tagName,!1),c=_M(e,t);let f=gg(e,t);return hM.has(t.tagName)&&(f=f.filter(function(d){return typeof d=="string"?!GR(d):!0})),yS(e,c,o,t),pg(c,f),e.ancestors.pop(),e.schema=a,e.create(t,o,c,n)}function bM(e,t){if(t.data&&t.data.estree&&e.evaluater){const a=t.data.estree.body[0];return a.type,e.evaluater.evaluateExpression(a.expression)}cc(e,t.position)}function yM(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);cc(e,t.position)}function xM(e,t,n){const a=e.schema;let s=a;t.name==="svg"&&a.space==="html"&&(s=dg,e.schema=s),e.ancestors.push(t);const o=t.name===null?e.Fragment:xS(e,t.name,!0),c=kM(e,t),f=gg(e,t);return yS(e,c,o,t),pg(c,f),e.ancestors.pop(),e.schema=a,e.create(t,o,c,n)}function vM(e,t,n){const a={};return pg(a,gg(e,t)),e.create(t,e.Fragment,a,n)}function EM(e,t){return t.value}function yS(e,t,n,a){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=a)}function pg(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function SM(e,t,n){return a;function a(s,o,c,f){const h=Array.isArray(c.children)?n:t;return f?h(o,c,f):h(o,c)}}function wM(e,t){return n;function n(a,s,o,c){const f=Array.isArray(o.children),d=hg(a);return t(s,o,c,f,{columnNumber:d?d.column-1:void 0,fileName:e,lineNumber:d?d.line:void 0},void 0)}}function _M(e,t){const n={};let a,s;for(s in t.properties)if(s!=="children"&&mg.call(t.properties,s)){const o=NM(e,s,t.properties[s]);if(o){const[c,f]=o;e.tableCellAlignToStyle&&c==="align"&&typeof f=="string"&&mM.has(t.tagName)?a=f:n[c]=f}}if(a){const o=n.style||(n.style={});o[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=a}return n}function kM(e,t){const n={};for(const a of t.attributes)if(a.type==="mdxJsxExpressionAttribute")if(a.data&&a.data.estree&&e.evaluater){const o=a.data.estree.body[0];o.type;const c=o.expression;c.type;const f=c.properties[0];f.type,Object.assign(n,e.evaluater.evaluateExpression(f.argument))}else cc(e,t.position);else{const s=a.name;let o;if(a.value&&typeof a.value=="object")if(a.value.data&&a.value.data.estree&&e.evaluater){const f=a.value.data.estree.body[0];f.type,o=e.evaluater.evaluateExpression(f.expression)}else cc(e,t.position);else o=a.value===null?!0:a.value;n[s]=o}return n}function gg(e,t){const n=[];let a=-1;const s=e.passKeys?new Map:fM;for(;++a<t.children.length;){const o=t.children[a];let c;if(e.passKeys){const d=o.type==="element"?o.tagName:o.type==="mdxJsxFlowElement"||o.type==="mdxJsxTextElement"?o.name:void 0;if(d){const h=s.get(d)||0;c=d+"-"+h,s.set(d,h+1)}}const f=bS(e,o,c);f!==void 0&&n.push(f)}return n}function NM(e,t,n){const a=JR(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=a.commaSeparated?$R(n):iM(n)),a.property==="style"){let s=typeof n=="object"?n:TM(e,String(n));return e.stylePropertyNameCase==="css"&&(s=CM(s)),["style",s]}return[e.elementAttributeNameCase==="react"&&a.space?XR[a.property]||a.property:a.attribute,n]}}function TM(e,t){try{return cM(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const a=n,s=new bn("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:a,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw s.file=e.filePath||void 0,s.url=gS+"#cannot-parse-style-attribute",s}}function xS(e,t,n){let a;if(!n)a={type:"Literal",value:t};else if(t.includes(".")){const s=t.split(".");let o=-1,c;for(;++o<s.length;){const f=t0(s[o])?{type:"Identifier",name:s[o]}:{type:"Literal",value:s[o]};c=c?{type:"MemberExpression",object:c,property:f,computed:!!(o&&f.type==="Literal"),optional:!1}:f}a=c}else a=t0(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(a.type==="Literal"){const s=a.value;return mg.call(e.components,s)?e.components[s]:s}if(e.evaluater)return e.evaluater.evaluateExpression(a);cc(e)}function cc(e,t){const n=new bn("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=gS+"#cannot-handle-mdx-estrees-without-createevaluater",n}function CM(e){const t={};let n;for(n in e)mg.call(e,n)&&(t[AM(n)]=e[n]);return t}function AM(e){let t=e.replace(dM,OM);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function OM(e){return"-"+e.toLowerCase()}const wm={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},RM={};function bg(e,t){const n=RM,a=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,s=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return vS(e,a,s)}function vS(e,t,n){if(MM(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return f0(e.children,t,n)}return Array.isArray(e)?f0(e,t,n):""}function f0(e,t,n){const a=[];let s=-1;for(;++s<e.length;)a[s]=vS(e[s],t,n);return a.join("")}function MM(e){return!!(e&&typeof e=="object")}const d0=document.createElement("i");function yg(e){const t="&"+e+";";d0.innerHTML=t;const n=d0.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function ai(e,t,n,a){const s=e.length;let o=0,c;if(t<0?t=-t>s?0:s+t:t=t>s?s:t,n=n>0?n:0,a.length<1e4)c=Array.from(a),c.unshift(t,n),e.splice(...c);else for(n&&e.splice(t,n);o<a.length;)c=a.slice(o,o+1e4),c.unshift(t,0),e.splice(...c),o+=1e4,t+=1e4}function xi(e,t){return e.length>0?(ai(e,e.length,0,t),e):t}const h0={}.hasOwnProperty;function ES(e){const t={};let n=-1;for(;++n<e.length;)jM(t,e[n]);return t}function jM(e,t){let n;for(n in t){const s=(h0.call(e,n)?e[n]:void 0)||(e[n]={}),o=t[n];let c;if(o)for(c in o){h0.call(s,c)||(s[c]=[]);const f=o[c];DM(s[c],Array.isArray(f)?f:f?[f]:[])}}}function DM(e,t){let n=-1;const a=[];for(;++n<t.length;)(t[n].add==="after"?e:a).push(t[n]);ai(e,0,0,a)}function SS(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function Mi(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Nn=_r(/[A-Za-z]/),pn=_r(/[\dA-Za-z]/),LM=_r(/[#-'*+\--9=?A-Z^-~]/);function _f(e){return e!==null&&(e<32||e===127)}const bp=_r(/\d/),IM=_r(/[\dA-Fa-f]/),zM=_r(/[!-/:-@[-`{-~]/);function Te(e){return e!==null&&e<-2}function xt(e){return e!==null&&(e<0||e===32)}function Ge(e){return e===-2||e===-1||e===32}const Vf=_r(new RegExp("\\p{P}|\\p{S}","u")),us=_r(/\s/);function _r(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Kl(e){const t=[];let n=-1,a=0,s=0;for(;++n<e.length;){const o=e.charCodeAt(n);let c="";if(o===37&&pn(e.charCodeAt(n+1))&&pn(e.charCodeAt(n+2)))s=2;else if(o<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(o))||(c=String.fromCharCode(o));else if(o>55295&&o<57344){const f=e.charCodeAt(n+1);o<56320&&f>56319&&f<57344?(c=String.fromCharCode(o,f),s=1):c="�"}else c=String.fromCharCode(o);c&&(t.push(e.slice(a,n),encodeURIComponent(c)),a=n+s+1,c=""),s&&(n+=s,s=0)}return t.join("")+e.slice(a)}function Je(e,t,n,a){const s=a?a-1:Number.POSITIVE_INFINITY;let o=0;return c;function c(d){return Ge(d)?(e.enter(n),f(d)):t(d)}function f(d){return Ge(d)&&o++<s?(e.consume(d),f):(e.exit(n),t(d))}}const BM={tokenize:UM};function UM(e){const t=e.attempt(this.parser.constructs.contentInitial,a,s);let n;return t;function a(f){if(f===null){e.consume(f);return}return e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),Je(e,t,"linePrefix")}function s(f){return e.enter("paragraph"),o(f)}function o(f){const d=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=d),n=d,c(f)}function c(f){if(f===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(f);return}return Te(f)?(e.consume(f),e.exit("chunkText"),o):(e.consume(f),c)}}const FM={tokenize:$M},m0={tokenize:PM};function $M(e){const t=this,n=[];let a=0,s,o,c;return f;function f(C){if(a<n.length){const D=n[a];return t.containerState=D[1],e.attempt(D[0].continuation,d,h)(C)}return h(C)}function d(C){if(a++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,s&&R();const D=t.events.length;let $=D,j;for(;$--;)if(t.events[$][0]==="exit"&&t.events[$][1].type==="chunkFlow"){j=t.events[$][1].end;break}k(a);let q=D;for(;q<t.events.length;)t.events[q][1].end={...j},q++;return ai(t.events,$+1,0,t.events.slice(D)),t.events.length=q,h(C)}return f(C)}function h(C){if(a===n.length){if(!s)return x(C);if(s.currentConstruct&&s.currentConstruct.concrete)return S(C);t.interrupt=!!(s.currentConstruct&&!s._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(m0,y,g)(C)}function y(C){return s&&R(),k(a),x(C)}function g(C){return t.parser.lazy[t.now().line]=a!==n.length,c=t.now().offset,S(C)}function x(C){return t.containerState={},e.attempt(m0,v,S)(C)}function v(C){return a++,n.push([t.currentConstruct,t.containerState]),x(C)}function S(C){if(C===null){s&&R(),k(0),e.consume(C);return}return s=s||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:s,contentType:"flow",previous:o}),w(C)}function w(C){if(C===null){_(e.exit("chunkFlow"),!0),k(0),e.consume(C);return}return Te(C)?(e.consume(C),_(e.exit("chunkFlow")),a=0,t.interrupt=void 0,f):(e.consume(C),w)}function _(C,D){const $=t.sliceStream(C);if(D&&$.push(null),C.previous=o,o&&(o.next=C),o=C,s.defineSkip(C.start),s.write($),t.parser.lazy[C.start.line]){let j=s.events.length;for(;j--;)if(s.events[j][1].start.offset<c&&(!s.events[j][1].end||s.events[j][1].end.offset>c))return;const q=t.events.length;let U=q,Z,A;for(;U--;)if(t.events[U][0]==="exit"&&t.events[U][1].type==="chunkFlow"){if(Z){A=t.events[U][1].end;break}Z=!0}for(k(a),j=q;j<t.events.length;)t.events[j][1].end={...A},j++;ai(t.events,U+1,0,t.events.slice(q)),t.events.length=j}}function k(C){let D=n.length;for(;D-- >C;){const $=n[D];t.containerState=$[1],$[0].exit.call(t,e)}n.length=C}function R(){s.write([null]),o=void 0,s=void 0,t.containerState._closeFlow=void 0}}function PM(e,t,n){return Je(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function Rl(e){if(e===null||xt(e)||us(e))return 1;if(Vf(e))return 2}function Xf(e,t,n){const a=[];let s=-1;for(;++s<e.length;){const o=e[s].resolveAll;o&&!a.includes(o)&&(t=o(t,n),a.push(o))}return t}const yp={name:"attention",resolveAll:qM,tokenize:HM};function qM(e,t){let n=-1,a,s,o,c,f,d,h,y;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(a=n;a--;)if(e[a][0]==="exit"&&e[a][1].type==="attentionSequence"&&e[a][1]._open&&t.sliceSerialize(e[a][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[a][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[a][1].end.offset-e[a][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;d=e[a][1].end.offset-e[a][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const g={...e[a][1].end},x={...e[n][1].start};p0(g,-d),p0(x,d),c={type:d>1?"strongSequence":"emphasisSequence",start:g,end:{...e[a][1].end}},f={type:d>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:x},o={type:d>1?"strongText":"emphasisText",start:{...e[a][1].end},end:{...e[n][1].start}},s={type:d>1?"strong":"emphasis",start:{...c.start},end:{...f.end}},e[a][1].end={...c.start},e[n][1].start={...f.end},h=[],e[a][1].end.offset-e[a][1].start.offset&&(h=xi(h,[["enter",e[a][1],t],["exit",e[a][1],t]])),h=xi(h,[["enter",s,t],["enter",c,t],["exit",c,t],["enter",o,t]]),h=xi(h,Xf(t.parser.constructs.insideSpan.null,e.slice(a+1,n),t)),h=xi(h,[["exit",o,t],["enter",f,t],["exit",f,t],["exit",s,t]]),e[n][1].end.offset-e[n][1].start.offset?(y=2,h=xi(h,[["enter",e[n][1],t],["exit",e[n][1],t]])):y=0,ai(e,a-1,n-a+3,h),n=a+h.length-y-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function HM(e,t){const n=this.parser.constructs.attentionMarkers.null,a=this.previous,s=Rl(a);let o;return c;function c(d){return o=d,e.enter("attentionSequence"),f(d)}function f(d){if(d===o)return e.consume(d),f;const h=e.exit("attentionSequence"),y=Rl(d),g=!y||y===2&&s||n.includes(d),x=!s||s===2&&y||n.includes(a);return h._open=!!(o===42?g:g&&(s||!x)),h._close=!!(o===42?x:x&&(y||!g)),t(d)}}function p0(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const KM={name:"autolink",tokenize:GM};function GM(e,t,n){let a=0;return s;function s(v){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(v),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),o}function o(v){return Nn(v)?(e.consume(v),c):v===64?n(v):h(v)}function c(v){return v===43||v===45||v===46||pn(v)?(a=1,f(v)):h(v)}function f(v){return v===58?(e.consume(v),a=0,d):(v===43||v===45||v===46||pn(v))&&a++<32?(e.consume(v),f):(a=0,h(v))}function d(v){return v===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(v),e.exit("autolinkMarker"),e.exit("autolink"),t):v===null||v===32||v===60||_f(v)?n(v):(e.consume(v),d)}function h(v){return v===64?(e.consume(v),y):LM(v)?(e.consume(v),h):n(v)}function y(v){return pn(v)?g(v):n(v)}function g(v){return v===46?(e.consume(v),a=0,y):v===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(v),e.exit("autolinkMarker"),e.exit("autolink"),t):x(v)}function x(v){if((v===45||pn(v))&&a++<63){const S=v===45?x:g;return e.consume(v),S}return n(v)}}const wc={partial:!0,tokenize:QM};function QM(e,t,n){return a;function a(o){return Ge(o)?Je(e,s,"linePrefix")(o):s(o)}function s(o){return o===null||Te(o)?t(o):n(o)}}const wS={continuation:{tokenize:VM},exit:XM,name:"blockQuote",tokenize:YM};function YM(e,t,n){const a=this;return s;function s(c){if(c===62){const f=a.containerState;return f.open||(e.enter("blockQuote",{_container:!0}),f.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(c),e.exit("blockQuoteMarker"),o}return n(c)}function o(c){return Ge(c)?(e.enter("blockQuotePrefixWhitespace"),e.consume(c),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(c))}}function VM(e,t,n){const a=this;return s;function s(c){return Ge(c)?Je(e,o,"linePrefix",a.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(c):o(c)}function o(c){return e.attempt(wS,t,n)(c)}}function XM(e){e.exit("blockQuote")}const _S={name:"characterEscape",tokenize:ZM};function ZM(e,t,n){return a;function a(o){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(o),e.exit("escapeMarker"),s}function s(o){return zM(o)?(e.enter("characterEscapeValue"),e.consume(o),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(o)}}const kS={name:"characterReference",tokenize:WM};function WM(e,t,n){const a=this;let s=0,o,c;return f;function f(g){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(g),e.exit("characterReferenceMarker"),d}function d(g){return g===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(g),e.exit("characterReferenceMarkerNumeric"),h):(e.enter("characterReferenceValue"),o=31,c=pn,y(g))}function h(g){return g===88||g===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(g),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),o=6,c=IM,y):(e.enter("characterReferenceValue"),o=7,c=bp,y(g))}function y(g){if(g===59&&s){const x=e.exit("characterReferenceValue");return c===pn&&!yg(a.sliceSerialize(x))?n(g):(e.enter("characterReferenceMarker"),e.consume(g),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return c(g)&&s++<o?(e.consume(g),y):n(g)}}const g0={partial:!0,tokenize:ej},b0={concrete:!0,name:"codeFenced",tokenize:JM};function JM(e,t,n){const a=this,s={partial:!0,tokenize:$};let o=0,c=0,f;return d;function d(j){return h(j)}function h(j){const q=a.events[a.events.length-1];return o=q&&q[1].type==="linePrefix"?q[2].sliceSerialize(q[1],!0).length:0,f=j,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),y(j)}function y(j){return j===f?(c++,e.consume(j),y):c<3?n(j):(e.exit("codeFencedFenceSequence"),Ge(j)?Je(e,g,"whitespace")(j):g(j))}function g(j){return j===null||Te(j)?(e.exit("codeFencedFence"),a.interrupt?t(j):e.check(g0,w,D)(j)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),x(j))}function x(j){return j===null||Te(j)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),g(j)):Ge(j)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),Je(e,v,"whitespace")(j)):j===96&&j===f?n(j):(e.consume(j),x)}function v(j){return j===null||Te(j)?g(j):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),S(j))}function S(j){return j===null||Te(j)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),g(j)):j===96&&j===f?n(j):(e.consume(j),S)}function w(j){return e.attempt(s,D,_)(j)}function _(j){return e.enter("lineEnding"),e.consume(j),e.exit("lineEnding"),k}function k(j){return o>0&&Ge(j)?Je(e,R,"linePrefix",o+1)(j):R(j)}function R(j){return j===null||Te(j)?e.check(g0,w,D)(j):(e.enter("codeFlowValue"),C(j))}function C(j){return j===null||Te(j)?(e.exit("codeFlowValue"),R(j)):(e.consume(j),C)}function D(j){return e.exit("codeFenced"),t(j)}function $(j,q,U){let Z=0;return A;function A(W){return j.enter("lineEnding"),j.consume(W),j.exit("lineEnding"),P}function P(W){return j.enter("codeFencedFence"),Ge(W)?Je(j,G,"linePrefix",a.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(W):G(W)}function G(W){return W===f?(j.enter("codeFencedFenceSequence"),le(W)):U(W)}function le(W){return W===f?(Z++,j.consume(W),le):Z>=c?(j.exit("codeFencedFenceSequence"),Ge(W)?Je(j,ae,"whitespace")(W):ae(W)):U(W)}function ae(W){return W===null||Te(W)?(j.exit("codeFencedFence"),q(W)):U(W)}}}function ej(e,t,n){const a=this;return s;function s(c){return c===null?n(c):(e.enter("lineEnding"),e.consume(c),e.exit("lineEnding"),o)}function o(c){return a.parser.lazy[a.now().line]?n(c):t(c)}}const _m={name:"codeIndented",tokenize:nj},tj={partial:!0,tokenize:ij};function nj(e,t,n){const a=this;return s;function s(h){return e.enter("codeIndented"),Je(e,o,"linePrefix",5)(h)}function o(h){const y=a.events[a.events.length-1];return y&&y[1].type==="linePrefix"&&y[2].sliceSerialize(y[1],!0).length>=4?c(h):n(h)}function c(h){return h===null?d(h):Te(h)?e.attempt(tj,c,d)(h):(e.enter("codeFlowValue"),f(h))}function f(h){return h===null||Te(h)?(e.exit("codeFlowValue"),c(h)):(e.consume(h),f)}function d(h){return e.exit("codeIndented"),t(h)}}function ij(e,t,n){const a=this;return s;function s(c){return a.parser.lazy[a.now().line]?n(c):Te(c)?(e.enter("lineEnding"),e.consume(c),e.exit("lineEnding"),s):Je(e,o,"linePrefix",5)(c)}function o(c){const f=a.events[a.events.length-1];return f&&f[1].type==="linePrefix"&&f[2].sliceSerialize(f[1],!0).length>=4?t(c):Te(c)?s(c):n(c)}}const aj={name:"codeText",previous:sj,resolve:rj,tokenize:lj};function rj(e){let t=e.length-4,n=3,a,s;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(a=n;++a<t;)if(e[a][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(a=n-1,t++;++a<=t;)s===void 0?a!==t&&e[a][1].type!=="lineEnding"&&(s=a):(a===t||e[a][1].type==="lineEnding")&&(e[s][1].type="codeTextData",a!==s+2&&(e[s][1].end=e[a-1][1].end,e.splice(s+2,a-s-2),t-=a-s-2,a=s+2),s=void 0);return e}function sj(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function lj(e,t,n){let a=0,s,o;return c;function c(g){return e.enter("codeText"),e.enter("codeTextSequence"),f(g)}function f(g){return g===96?(e.consume(g),a++,f):(e.exit("codeTextSequence"),d(g))}function d(g){return g===null?n(g):g===32?(e.enter("space"),e.consume(g),e.exit("space"),d):g===96?(o=e.enter("codeTextSequence"),s=0,y(g)):Te(g)?(e.enter("lineEnding"),e.consume(g),e.exit("lineEnding"),d):(e.enter("codeTextData"),h(g))}function h(g){return g===null||g===32||g===96||Te(g)?(e.exit("codeTextData"),d(g)):(e.consume(g),h)}function y(g){return g===96?(e.consume(g),s++,y):s===a?(e.exit("codeTextSequence"),e.exit("codeText"),t(g)):(o.type="codeTextData",h(g))}}class oj{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const a=n??Number.POSITIVE_INFINITY;return a<this.left.length?this.left.slice(t,a):t>this.left.length?this.right.slice(this.right.length-a+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-a+this.left.length).reverse())}splice(t,n,a){const s=n||0;this.setCursor(Math.trunc(t));const o=this.right.splice(this.right.length-s,Number.POSITIVE_INFINITY);return a&&Qo(this.left,a),o.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Qo(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Qo(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Qo(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Qo(this.left,n.reverse())}}}function Qo(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function NS(e){const t={};let n=-1,a,s,o,c,f,d,h;const y=new oj(e);for(;++n<y.length;){for(;n in t;)n=t[n];if(a=y.get(n),n&&a[1].type==="chunkFlow"&&y.get(n-1)[1].type==="listItemPrefix"&&(d=a[1]._tokenizer.events,o=0,o<d.length&&d[o][1].type==="lineEndingBlank"&&(o+=2),o<d.length&&d[o][1].type==="content"))for(;++o<d.length&&d[o][1].type!=="content";)d[o][1].type==="chunkText"&&(d[o][1]._isInFirstContentOfListItem=!0,o++);if(a[0]==="enter")a[1].contentType&&(Object.assign(t,cj(y,n)),n=t[n],h=!0);else if(a[1]._container){for(o=n,s=void 0;o--;)if(c=y.get(o),c[1].type==="lineEnding"||c[1].type==="lineEndingBlank")c[0]==="enter"&&(s&&(y.get(s)[1].type="lineEndingBlank"),c[1].type="lineEnding",s=o);else if(!(c[1].type==="linePrefix"||c[1].type==="listItemIndent"))break;s&&(a[1].end={...y.get(s)[1].start},f=y.slice(s,n),f.unshift(a),y.splice(s,n-s+1,f))}}return ai(e,0,Number.POSITIVE_INFINITY,y.slice(0)),!h}function cj(e,t){const n=e.get(t)[1],a=e.get(t)[2];let s=t-1;const o=[];let c=n._tokenizer;c||(c=a.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(c._contentTypeTextTrailing=!0));const f=c.events,d=[],h={};let y,g,x=-1,v=n,S=0,w=0;const _=[w];for(;v;){for(;e.get(++s)[1]!==v;);o.push(s),v._tokenizer||(y=a.sliceStream(v),v.next||y.push(null),g&&c.defineSkip(v.start),v._isInFirstContentOfListItem&&(c._gfmTasklistFirstContentOfListItem=!0),c.write(y),v._isInFirstContentOfListItem&&(c._gfmTasklistFirstContentOfListItem=void 0)),g=v,v=v.next}for(v=n;++x<f.length;)f[x][0]==="exit"&&f[x-1][0]==="enter"&&f[x][1].type===f[x-1][1].type&&f[x][1].start.line!==f[x][1].end.line&&(w=x+1,_.push(w),v._tokenizer=void 0,v.previous=void 0,v=v.next);for(c.events=[],v?(v._tokenizer=void 0,v.previous=void 0):_.pop(),x=_.length;x--;){const k=f.slice(_[x],_[x+1]),R=o.pop();d.push([R,R+k.length-1]),e.splice(R,2,k)}for(d.reverse(),x=-1;++x<d.length;)h[S+d[x][0]]=S+d[x][1],S+=d[x][1]-d[x][0]-1;return h}const uj={resolve:dj,tokenize:hj},fj={partial:!0,tokenize:mj};function dj(e){return NS(e),e}function hj(e,t){let n;return a;function a(f){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),s(f)}function s(f){return f===null?o(f):Te(f)?e.check(fj,c,o)(f):(e.consume(f),s)}function o(f){return e.exit("chunkContent"),e.exit("content"),t(f)}function c(f){return e.consume(f),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,s}}function mj(e,t,n){const a=this;return s;function s(c){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(c),e.exit("lineEnding"),Je(e,o,"linePrefix")}function o(c){if(c===null||Te(c))return n(c);const f=a.events[a.events.length-1];return!a.parser.constructs.disable.null.includes("codeIndented")&&f&&f[1].type==="linePrefix"&&f[2].sliceSerialize(f[1],!0).length>=4?t(c):e.interrupt(a.parser.constructs.flow,n,t)(c)}}function TS(e,t,n,a,s,o,c,f,d){const h=d||Number.POSITIVE_INFINITY;let y=0;return g;function g(k){return k===60?(e.enter(a),e.enter(s),e.enter(o),e.consume(k),e.exit(o),x):k===null||k===32||k===41||_f(k)?n(k):(e.enter(a),e.enter(c),e.enter(f),e.enter("chunkString",{contentType:"string"}),w(k))}function x(k){return k===62?(e.enter(o),e.consume(k),e.exit(o),e.exit(s),e.exit(a),t):(e.enter(f),e.enter("chunkString",{contentType:"string"}),v(k))}function v(k){return k===62?(e.exit("chunkString"),e.exit(f),x(k)):k===null||k===60||Te(k)?n(k):(e.consume(k),k===92?S:v)}function S(k){return k===60||k===62||k===92?(e.consume(k),v):v(k)}function w(k){return!y&&(k===null||k===41||xt(k))?(e.exit("chunkString"),e.exit(f),e.exit(c),e.exit(a),t(k)):y<h&&k===40?(e.consume(k),y++,w):k===41?(e.consume(k),y--,w):k===null||k===32||k===40||_f(k)?n(k):(e.consume(k),k===92?_:w)}function _(k){return k===40||k===41||k===92?(e.consume(k),w):w(k)}}function CS(e,t,n,a,s,o){const c=this;let f=0,d;return h;function h(v){return e.enter(a),e.enter(s),e.consume(v),e.exit(s),e.enter(o),y}function y(v){return f>999||v===null||v===91||v===93&&!d||v===94&&!f&&"_hiddenFootnoteSupport"in c.parser.constructs?n(v):v===93?(e.exit(o),e.enter(s),e.consume(v),e.exit(s),e.exit(a),t):Te(v)?(e.enter("lineEnding"),e.consume(v),e.exit("lineEnding"),y):(e.enter("chunkString",{contentType:"string"}),g(v))}function g(v){return v===null||v===91||v===93||Te(v)||f++>999?(e.exit("chunkString"),y(v)):(e.consume(v),d||(d=!Ge(v)),v===92?x:g)}function x(v){return v===91||v===92||v===93?(e.consume(v),f++,g):g(v)}}function AS(e,t,n,a,s,o){let c;return f;function f(x){return x===34||x===39||x===40?(e.enter(a),e.enter(s),e.consume(x),e.exit(s),c=x===40?41:x,d):n(x)}function d(x){return x===c?(e.enter(s),e.consume(x),e.exit(s),e.exit(a),t):(e.enter(o),h(x))}function h(x){return x===c?(e.exit(o),d(c)):x===null?n(x):Te(x)?(e.enter("lineEnding"),e.consume(x),e.exit("lineEnding"),Je(e,h,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),y(x))}function y(x){return x===c||x===null||Te(x)?(e.exit("chunkString"),h(x)):(e.consume(x),x===92?g:y)}function g(x){return x===c||x===92?(e.consume(x),y):y(x)}}function ec(e,t){let n;return a;function a(s){return Te(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),n=!0,a):Ge(s)?Je(e,a,n?"linePrefix":"lineSuffix")(s):t(s)}}const pj={name:"definition",tokenize:bj},gj={partial:!0,tokenize:yj};function bj(e,t,n){const a=this;let s;return o;function o(v){return e.enter("definition"),c(v)}function c(v){return CS.call(a,e,f,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(v)}function f(v){return s=Mi(a.sliceSerialize(a.events[a.events.length-1][1]).slice(1,-1)),v===58?(e.enter("definitionMarker"),e.consume(v),e.exit("definitionMarker"),d):n(v)}function d(v){return xt(v)?ec(e,h)(v):h(v)}function h(v){return TS(e,y,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(v)}function y(v){return e.attempt(gj,g,g)(v)}function g(v){return Ge(v)?Je(e,x,"whitespace")(v):x(v)}function x(v){return v===null||Te(v)?(e.exit("definition"),a.parser.defined.push(s),t(v)):n(v)}}function yj(e,t,n){return a;function a(f){return xt(f)?ec(e,s)(f):n(f)}function s(f){return AS(e,o,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(f)}function o(f){return Ge(f)?Je(e,c,"whitespace")(f):c(f)}function c(f){return f===null||Te(f)?t(f):n(f)}}const xj={name:"hardBreakEscape",tokenize:vj};function vj(e,t,n){return a;function a(o){return e.enter("hardBreakEscape"),e.consume(o),s}function s(o){return Te(o)?(e.exit("hardBreakEscape"),t(o)):n(o)}}const Ej={name:"headingAtx",resolve:Sj,tokenize:wj};function Sj(e,t){let n=e.length-2,a=3,s,o;return e[a][1].type==="whitespace"&&(a+=2),n-2>a&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(a===n-1||n-4>a&&e[n-2][1].type==="whitespace")&&(n-=a+1===n?2:4),n>a&&(s={type:"atxHeadingText",start:e[a][1].start,end:e[n][1].end},o={type:"chunkText",start:e[a][1].start,end:e[n][1].end,contentType:"text"},ai(e,a,n-a+1,[["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t]])),e}function wj(e,t,n){let a=0;return s;function s(y){return e.enter("atxHeading"),o(y)}function o(y){return e.enter("atxHeadingSequence"),c(y)}function c(y){return y===35&&a++<6?(e.consume(y),c):y===null||xt(y)?(e.exit("atxHeadingSequence"),f(y)):n(y)}function f(y){return y===35?(e.enter("atxHeadingSequence"),d(y)):y===null||Te(y)?(e.exit("atxHeading"),t(y)):Ge(y)?Je(e,f,"whitespace")(y):(e.enter("atxHeadingText"),h(y))}function d(y){return y===35?(e.consume(y),d):(e.exit("atxHeadingSequence"),f(y))}function h(y){return y===null||y===35||xt(y)?(e.exit("atxHeadingText"),f(y)):(e.consume(y),h)}}const _j=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],y0=["pre","script","style","textarea"],kj={concrete:!0,name:"htmlFlow",resolveTo:Cj,tokenize:Aj},Nj={partial:!0,tokenize:Rj},Tj={partial:!0,tokenize:Oj};function Cj(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function Aj(e,t,n){const a=this;let s,o,c,f,d;return h;function h(N){return y(N)}function y(N){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(N),g}function g(N){return N===33?(e.consume(N),x):N===47?(e.consume(N),o=!0,w):N===63?(e.consume(N),s=3,a.interrupt?t:O):Nn(N)?(e.consume(N),c=String.fromCharCode(N),_):n(N)}function x(N){return N===45?(e.consume(N),s=2,v):N===91?(e.consume(N),s=5,f=0,S):Nn(N)?(e.consume(N),s=4,a.interrupt?t:O):n(N)}function v(N){return N===45?(e.consume(N),a.interrupt?t:O):n(N)}function S(N){const ce="CDATA[";return N===ce.charCodeAt(f++)?(e.consume(N),f===ce.length?a.interrupt?t:G:S):n(N)}function w(N){return Nn(N)?(e.consume(N),c=String.fromCharCode(N),_):n(N)}function _(N){if(N===null||N===47||N===62||xt(N)){const ce=N===47,Ee=c.toLowerCase();return!ce&&!o&&y0.includes(Ee)?(s=1,a.interrupt?t(N):G(N)):_j.includes(c.toLowerCase())?(s=6,ce?(e.consume(N),k):a.interrupt?t(N):G(N)):(s=7,a.interrupt&&!a.parser.lazy[a.now().line]?n(N):o?R(N):C(N))}return N===45||pn(N)?(e.consume(N),c+=String.fromCharCode(N),_):n(N)}function k(N){return N===62?(e.consume(N),a.interrupt?t:G):n(N)}function R(N){return Ge(N)?(e.consume(N),R):A(N)}function C(N){return N===47?(e.consume(N),A):N===58||N===95||Nn(N)?(e.consume(N),D):Ge(N)?(e.consume(N),C):A(N)}function D(N){return N===45||N===46||N===58||N===95||pn(N)?(e.consume(N),D):$(N)}function $(N){return N===61?(e.consume(N),j):Ge(N)?(e.consume(N),$):C(N)}function j(N){return N===null||N===60||N===61||N===62||N===96?n(N):N===34||N===39?(e.consume(N),d=N,q):Ge(N)?(e.consume(N),j):U(N)}function q(N){return N===d?(e.consume(N),d=null,Z):N===null||Te(N)?n(N):(e.consume(N),q)}function U(N){return N===null||N===34||N===39||N===47||N===60||N===61||N===62||N===96||xt(N)?$(N):(e.consume(N),U)}function Z(N){return N===47||N===62||Ge(N)?C(N):n(N)}function A(N){return N===62?(e.consume(N),P):n(N)}function P(N){return N===null||Te(N)?G(N):Ge(N)?(e.consume(N),P):n(N)}function G(N){return N===45&&s===2?(e.consume(N),K):N===60&&s===1?(e.consume(N),oe):N===62&&s===4?(e.consume(N),L):N===63&&s===3?(e.consume(N),O):N===93&&s===5?(e.consume(N),me):Te(N)&&(s===6||s===7)?(e.exit("htmlFlowData"),e.check(Nj,J,le)(N)):N===null||Te(N)?(e.exit("htmlFlowData"),le(N)):(e.consume(N),G)}function le(N){return e.check(Tj,ae,J)(N)}function ae(N){return e.enter("lineEnding"),e.consume(N),e.exit("lineEnding"),W}function W(N){return N===null||Te(N)?le(N):(e.enter("htmlFlowData"),G(N))}function K(N){return N===45?(e.consume(N),O):G(N)}function oe(N){return N===47?(e.consume(N),c="",V):G(N)}function V(N){if(N===62){const ce=c.toLowerCase();return y0.includes(ce)?(e.consume(N),L):G(N)}return Nn(N)&&c.length<8?(e.consume(N),c+=String.fromCharCode(N),V):G(N)}function me(N){return N===93?(e.consume(N),O):G(N)}function O(N){return N===62?(e.consume(N),L):N===45&&s===2?(e.consume(N),O):G(N)}function L(N){return N===null||Te(N)?(e.exit("htmlFlowData"),J(N)):(e.consume(N),L)}function J(N){return e.exit("htmlFlow"),t(N)}}function Oj(e,t,n){const a=this;return s;function s(c){return Te(c)?(e.enter("lineEnding"),e.consume(c),e.exit("lineEnding"),o):n(c)}function o(c){return a.parser.lazy[a.now().line]?n(c):t(c)}}function Rj(e,t,n){return a;function a(s){return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),e.attempt(wc,t,n)}}const Mj={name:"htmlText",tokenize:jj};function jj(e,t,n){const a=this;let s,o,c;return f;function f(O){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(O),d}function d(O){return O===33?(e.consume(O),h):O===47?(e.consume(O),$):O===63?(e.consume(O),C):Nn(O)?(e.consume(O),U):n(O)}function h(O){return O===45?(e.consume(O),y):O===91?(e.consume(O),o=0,S):Nn(O)?(e.consume(O),R):n(O)}function y(O){return O===45?(e.consume(O),v):n(O)}function g(O){return O===null?n(O):O===45?(e.consume(O),x):Te(O)?(c=g,oe(O)):(e.consume(O),g)}function x(O){return O===45?(e.consume(O),v):g(O)}function v(O){return O===62?K(O):O===45?x(O):g(O)}function S(O){const L="CDATA[";return O===L.charCodeAt(o++)?(e.consume(O),o===L.length?w:S):n(O)}function w(O){return O===null?n(O):O===93?(e.consume(O),_):Te(O)?(c=w,oe(O)):(e.consume(O),w)}function _(O){return O===93?(e.consume(O),k):w(O)}function k(O){return O===62?K(O):O===93?(e.consume(O),k):w(O)}function R(O){return O===null||O===62?K(O):Te(O)?(c=R,oe(O)):(e.consume(O),R)}function C(O){return O===null?n(O):O===63?(e.consume(O),D):Te(O)?(c=C,oe(O)):(e.consume(O),C)}function D(O){return O===62?K(O):C(O)}function $(O){return Nn(O)?(e.consume(O),j):n(O)}function j(O){return O===45||pn(O)?(e.consume(O),j):q(O)}function q(O){return Te(O)?(c=q,oe(O)):Ge(O)?(e.consume(O),q):K(O)}function U(O){return O===45||pn(O)?(e.consume(O),U):O===47||O===62||xt(O)?Z(O):n(O)}function Z(O){return O===47?(e.consume(O),K):O===58||O===95||Nn(O)?(e.consume(O),A):Te(O)?(c=Z,oe(O)):Ge(O)?(e.consume(O),Z):K(O)}function A(O){return O===45||O===46||O===58||O===95||pn(O)?(e.consume(O),A):P(O)}function P(O){return O===61?(e.consume(O),G):Te(O)?(c=P,oe(O)):Ge(O)?(e.consume(O),P):Z(O)}function G(O){return O===null||O===60||O===61||O===62||O===96?n(O):O===34||O===39?(e.consume(O),s=O,le):Te(O)?(c=G,oe(O)):Ge(O)?(e.consume(O),G):(e.consume(O),ae)}function le(O){return O===s?(e.consume(O),s=void 0,W):O===null?n(O):Te(O)?(c=le,oe(O)):(e.consume(O),le)}function ae(O){return O===null||O===34||O===39||O===60||O===61||O===96?n(O):O===47||O===62||xt(O)?Z(O):(e.consume(O),ae)}function W(O){return O===47||O===62||xt(O)?Z(O):n(O)}function K(O){return O===62?(e.consume(O),e.exit("htmlTextData"),e.exit("htmlText"),t):n(O)}function oe(O){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(O),e.exit("lineEnding"),V}function V(O){return Ge(O)?Je(e,me,"linePrefix",a.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(O):me(O)}function me(O){return e.enter("htmlTextData"),c(O)}}const xg={name:"labelEnd",resolveAll:zj,resolveTo:Bj,tokenize:Uj},Dj={tokenize:Fj},Lj={tokenize:$j},Ij={tokenize:Pj};function zj(e){let t=-1;const n=[];for(;++t<e.length;){const a=e[t][1];if(n.push(e[t]),a.type==="labelImage"||a.type==="labelLink"||a.type==="labelEnd"){const s=a.type==="labelImage"?4:2;a.type="data",t+=s}}return e.length!==n.length&&ai(e,0,e.length,n),e}function Bj(e,t){let n=e.length,a=0,s,o,c,f;for(;n--;)if(s=e[n][1],o){if(s.type==="link"||s.type==="labelLink"&&s._inactive)break;e[n][0]==="enter"&&s.type==="labelLink"&&(s._inactive=!0)}else if(c){if(e[n][0]==="enter"&&(s.type==="labelImage"||s.type==="labelLink")&&!s._balanced&&(o=n,s.type!=="labelLink")){a=2;break}}else s.type==="labelEnd"&&(c=n);const d={type:e[o][1].type==="labelLink"?"link":"image",start:{...e[o][1].start},end:{...e[e.length-1][1].end}},h={type:"label",start:{...e[o][1].start},end:{...e[c][1].end}},y={type:"labelText",start:{...e[o+a+2][1].end},end:{...e[c-2][1].start}};return f=[["enter",d,t],["enter",h,t]],f=xi(f,e.slice(o+1,o+a+3)),f=xi(f,[["enter",y,t]]),f=xi(f,Xf(t.parser.constructs.insideSpan.null,e.slice(o+a+4,c-3),t)),f=xi(f,[["exit",y,t],e[c-2],e[c-1],["exit",h,t]]),f=xi(f,e.slice(c+1)),f=xi(f,[["exit",d,t]]),ai(e,o,e.length,f),e}function Uj(e,t,n){const a=this;let s=a.events.length,o,c;for(;s--;)if((a.events[s][1].type==="labelImage"||a.events[s][1].type==="labelLink")&&!a.events[s][1]._balanced){o=a.events[s][1];break}return f;function f(x){return o?o._inactive?g(x):(c=a.parser.defined.includes(Mi(a.sliceSerialize({start:o.end,end:a.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(x),e.exit("labelMarker"),e.exit("labelEnd"),d):n(x)}function d(x){return x===40?e.attempt(Dj,y,c?y:g)(x):x===91?e.attempt(Lj,y,c?h:g)(x):c?y(x):g(x)}function h(x){return e.attempt(Ij,y,g)(x)}function y(x){return t(x)}function g(x){return o._balanced=!0,n(x)}}function Fj(e,t,n){return a;function a(g){return e.enter("resource"),e.enter("resourceMarker"),e.consume(g),e.exit("resourceMarker"),s}function s(g){return xt(g)?ec(e,o)(g):o(g)}function o(g){return g===41?y(g):TS(e,c,f,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(g)}function c(g){return xt(g)?ec(e,d)(g):y(g)}function f(g){return n(g)}function d(g){return g===34||g===39||g===40?AS(e,h,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(g):y(g)}function h(g){return xt(g)?ec(e,y)(g):y(g)}function y(g){return g===41?(e.enter("resourceMarker"),e.consume(g),e.exit("resourceMarker"),e.exit("resource"),t):n(g)}}function $j(e,t,n){const a=this;return s;function s(f){return CS.call(a,e,o,c,"reference","referenceMarker","referenceString")(f)}function o(f){return a.parser.defined.includes(Mi(a.sliceSerialize(a.events[a.events.length-1][1]).slice(1,-1)))?t(f):n(f)}function c(f){return n(f)}}function Pj(e,t,n){return a;function a(o){return e.enter("reference"),e.enter("referenceMarker"),e.consume(o),e.exit("referenceMarker"),s}function s(o){return o===93?(e.enter("referenceMarker"),e.consume(o),e.exit("referenceMarker"),e.exit("reference"),t):n(o)}}const qj={name:"labelStartImage",resolveAll:xg.resolveAll,tokenize:Hj};function Hj(e,t,n){const a=this;return s;function s(f){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(f),e.exit("labelImageMarker"),o}function o(f){return f===91?(e.enter("labelMarker"),e.consume(f),e.exit("labelMarker"),e.exit("labelImage"),c):n(f)}function c(f){return f===94&&"_hiddenFootnoteSupport"in a.parser.constructs?n(f):t(f)}}const Kj={name:"labelStartLink",resolveAll:xg.resolveAll,tokenize:Gj};function Gj(e,t,n){const a=this;return s;function s(c){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(c),e.exit("labelMarker"),e.exit("labelLink"),o}function o(c){return c===94&&"_hiddenFootnoteSupport"in a.parser.constructs?n(c):t(c)}}const km={name:"lineEnding",tokenize:Qj};function Qj(e,t){return n;function n(a){return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),Je(e,t,"linePrefix")}}const mf={name:"thematicBreak",tokenize:Yj};function Yj(e,t,n){let a=0,s;return o;function o(h){return e.enter("thematicBreak"),c(h)}function c(h){return s=h,f(h)}function f(h){return h===s?(e.enter("thematicBreakSequence"),d(h)):a>=3&&(h===null||Te(h))?(e.exit("thematicBreak"),t(h)):n(h)}function d(h){return h===s?(e.consume(h),a++,d):(e.exit("thematicBreakSequence"),Ge(h)?Je(e,f,"whitespace")(h):f(h))}}const zn={continuation:{tokenize:Wj},exit:eD,name:"list",tokenize:Zj},Vj={partial:!0,tokenize:tD},Xj={partial:!0,tokenize:Jj};function Zj(e,t,n){const a=this,s=a.events[a.events.length-1];let o=s&&s[1].type==="linePrefix"?s[2].sliceSerialize(s[1],!0).length:0,c=0;return f;function f(v){const S=a.containerState.type||(v===42||v===43||v===45?"listUnordered":"listOrdered");if(S==="listUnordered"?!a.containerState.marker||v===a.containerState.marker:bp(v)){if(a.containerState.type||(a.containerState.type=S,e.enter(S,{_container:!0})),S==="listUnordered")return e.enter("listItemPrefix"),v===42||v===45?e.check(mf,n,h)(v):h(v);if(!a.interrupt||v===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),d(v)}return n(v)}function d(v){return bp(v)&&++c<10?(e.consume(v),d):(!a.interrupt||c<2)&&(a.containerState.marker?v===a.containerState.marker:v===41||v===46)?(e.exit("listItemValue"),h(v)):n(v)}function h(v){return e.enter("listItemMarker"),e.consume(v),e.exit("listItemMarker"),a.containerState.marker=a.containerState.marker||v,e.check(wc,a.interrupt?n:y,e.attempt(Vj,x,g))}function y(v){return a.containerState.initialBlankLine=!0,o++,x(v)}function g(v){return Ge(v)?(e.enter("listItemPrefixWhitespace"),e.consume(v),e.exit("listItemPrefixWhitespace"),x):n(v)}function x(v){return a.containerState.size=o+a.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(v)}}function Wj(e,t,n){const a=this;return a.containerState._closeFlow=void 0,e.check(wc,s,o);function s(f){return a.containerState.furtherBlankLines=a.containerState.furtherBlankLines||a.containerState.initialBlankLine,Je(e,t,"listItemIndent",a.containerState.size+1)(f)}function o(f){return a.containerState.furtherBlankLines||!Ge(f)?(a.containerState.furtherBlankLines=void 0,a.containerState.initialBlankLine=void 0,c(f)):(a.containerState.furtherBlankLines=void 0,a.containerState.initialBlankLine=void 0,e.attempt(Xj,t,c)(f))}function c(f){return a.containerState._closeFlow=!0,a.interrupt=void 0,Je(e,e.attempt(zn,t,n),"linePrefix",a.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(f)}}function Jj(e,t,n){const a=this;return Je(e,s,"listItemIndent",a.containerState.size+1);function s(o){const c=a.events[a.events.length-1];return c&&c[1].type==="listItemIndent"&&c[2].sliceSerialize(c[1],!0).length===a.containerState.size?t(o):n(o)}}function eD(e){e.exit(this.containerState.type)}function tD(e,t,n){const a=this;return Je(e,s,"listItemPrefixWhitespace",a.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function s(o){const c=a.events[a.events.length-1];return!Ge(o)&&c&&c[1].type==="listItemPrefixWhitespace"?t(o):n(o)}}const x0={name:"setextUnderline",resolveTo:nD,tokenize:iD};function nD(e,t){let n=e.length,a,s,o;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){a=n;break}e[n][1].type==="paragraph"&&(s=n)}else e[n][1].type==="content"&&e.splice(n,1),!o&&e[n][1].type==="definition"&&(o=n);const c={type:"setextHeading",start:{...e[a][1].start},end:{...e[e.length-1][1].end}};return e[s][1].type="setextHeadingText",o?(e.splice(s,0,["enter",c,t]),e.splice(o+1,0,["exit",e[a][1],t]),e[a][1].end={...e[o][1].end}):e[a][1]=c,e.push(["exit",c,t]),e}function iD(e,t,n){const a=this;let s;return o;function o(h){let y=a.events.length,g;for(;y--;)if(a.events[y][1].type!=="lineEnding"&&a.events[y][1].type!=="linePrefix"&&a.events[y][1].type!=="content"){g=a.events[y][1].type==="paragraph";break}return!a.parser.lazy[a.now().line]&&(a.interrupt||g)?(e.enter("setextHeadingLine"),s=h,c(h)):n(h)}function c(h){return e.enter("setextHeadingLineSequence"),f(h)}function f(h){return h===s?(e.consume(h),f):(e.exit("setextHeadingLineSequence"),Ge(h)?Je(e,d,"lineSuffix")(h):d(h))}function d(h){return h===null||Te(h)?(e.exit("setextHeadingLine"),t(h)):n(h)}}const aD={tokenize:rD};function rD(e){const t=this,n=e.attempt(wc,a,e.attempt(this.parser.constructs.flowInitial,s,Je(e,e.attempt(this.parser.constructs.flow,s,e.attempt(uj,s)),"linePrefix")));return n;function a(o){if(o===null){e.consume(o);return}return e.enter("lineEndingBlank"),e.consume(o),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function s(o){if(o===null){e.consume(o);return}return e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const sD={resolveAll:RS()},lD=OS("string"),oD=OS("text");function OS(e){return{resolveAll:RS(e==="text"?cD:void 0),tokenize:t};function t(n){const a=this,s=this.parser.constructs[e],o=n.attempt(s,c,f);return c;function c(y){return h(y)?o(y):f(y)}function f(y){if(y===null){n.consume(y);return}return n.enter("data"),n.consume(y),d}function d(y){return h(y)?(n.exit("data"),o(y)):(n.consume(y),d)}function h(y){if(y===null)return!0;const g=s[y];let x=-1;if(g)for(;++x<g.length;){const v=g[x];if(!v.previous||v.previous.call(a,a.previous))return!0}return!1}}}function RS(e){return t;function t(n,a){let s=-1,o;for(;++s<=n.length;)o===void 0?n[s]&&n[s][1].type==="data"&&(o=s,s++):(!n[s]||n[s][1].type!=="data")&&(s!==o+2&&(n[o][1].end=n[s-1][1].end,n.splice(o+2,s-o-2),s=o+2),o=void 0);return e?e(n,a):n}}function cD(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const a=e[n-1][1],s=t.sliceStream(a);let o=s.length,c=-1,f=0,d;for(;o--;){const h=s[o];if(typeof h=="string"){for(c=h.length;h.charCodeAt(c-1)===32;)f++,c--;if(c)break;c=-1}else if(h===-2)d=!0,f++;else if(h!==-1){o++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(f=0),f){const h={type:n===e.length||d||f<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:o?c:a.start._bufferIndex+c,_index:a.start._index+o,line:a.end.line,column:a.end.column-f,offset:a.end.offset-f},end:{...a.end}};a.end={...h.start},a.start.offset===a.end.offset?Object.assign(a,h):(e.splice(n,0,["enter",h,t],["exit",h,t]),n+=2)}n++}return e}const uD={42:zn,43:zn,45:zn,48:zn,49:zn,50:zn,51:zn,52:zn,53:zn,54:zn,55:zn,56:zn,57:zn,62:wS},fD={91:pj},dD={[-2]:_m,[-1]:_m,32:_m},hD={35:Ej,42:mf,45:[x0,mf],60:kj,61:x0,95:mf,96:b0,126:b0},mD={38:kS,92:_S},pD={[-5]:km,[-4]:km,[-3]:km,33:qj,38:kS,42:yp,60:[KM,Mj],91:Kj,92:[xj,_S],93:xg,95:yp,96:aj},gD={null:[yp,sD]},bD={null:[42,95]},yD={null:[]},xD=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:bD,contentInitial:fD,disable:yD,document:uD,flow:hD,flowInitial:dD,insideSpan:gD,string:mD,text:pD},Symbol.toStringTag,{value:"Module"}));function vD(e,t,n){let a={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const s={},o=[];let c=[],f=[];const d={attempt:q($),check:q(j),consume:R,enter:C,exit:D,interrupt:q(j,{interrupt:!0})},h={code:null,containerState:{},defineSkip:w,events:[],now:S,parser:e,previous:null,sliceSerialize:x,sliceStream:v,write:g};let y=t.tokenize.call(h,d);return t.resolveAll&&o.push(t),h;function g(P){return c=xi(c,P),_(),c[c.length-1]!==null?[]:(U(t,0),h.events=Xf(o,h.events,h),h.events)}function x(P,G){return SD(v(P),G)}function v(P){return ED(c,P)}function S(){const{_bufferIndex:P,_index:G,line:le,column:ae,offset:W}=a;return{_bufferIndex:P,_index:G,line:le,column:ae,offset:W}}function w(P){s[P.line]=P.column,A()}function _(){let P;for(;a._index<c.length;){const G=c[a._index];if(typeof G=="string")for(P=a._index,a._bufferIndex<0&&(a._bufferIndex=0);a._index===P&&a._bufferIndex<G.length;)k(G.charCodeAt(a._bufferIndex));else k(G)}}function k(P){y=y(P)}function R(P){Te(P)?(a.line++,a.column=1,a.offset+=P===-3?2:1,A()):P!==-1&&(a.column++,a.offset++),a._bufferIndex<0?a._index++:(a._bufferIndex++,a._bufferIndex===c[a._index].length&&(a._bufferIndex=-1,a._index++)),h.previous=P}function C(P,G){const le=G||{};return le.type=P,le.start=S(),h.events.push(["enter",le,h]),f.push(le),le}function D(P){const G=f.pop();return G.end=S(),h.events.push(["exit",G,h]),G}function $(P,G){U(P,G.from)}function j(P,G){G.restore()}function q(P,G){return le;function le(ae,W,K){let oe,V,me,O;return Array.isArray(ae)?J(ae):"tokenize"in ae?J([ae]):L(ae);function L(xe){return ze;function ze(st){const it=st!==null&&xe[st],Wt=st!==null&&xe.null,Hn=[...Array.isArray(it)?it:it?[it]:[],...Array.isArray(Wt)?Wt:Wt?[Wt]:[]];return J(Hn)(st)}}function J(xe){return oe=xe,V=0,xe.length===0?K:N(xe[V])}function N(xe){return ze;function ze(st){return O=Z(),me=xe,xe.partial||(h.currentConstruct=xe),xe.name&&h.parser.constructs.disable.null.includes(xe.name)?Ee():xe.tokenize.call(G?Object.assign(Object.create(h),G):h,d,ce,Ee)(st)}}function ce(xe){return P(me,O),W}function Ee(xe){return O.restore(),++V<oe.length?N(oe[V]):K}}}function U(P,G){P.resolveAll&&!o.includes(P)&&o.push(P),P.resolve&&ai(h.events,G,h.events.length-G,P.resolve(h.events.slice(G),h)),P.resolveTo&&(h.events=P.resolveTo(h.events,h))}function Z(){const P=S(),G=h.previous,le=h.currentConstruct,ae=h.events.length,W=Array.from(f);return{from:ae,restore:K};function K(){a=P,h.previous=G,h.currentConstruct=le,h.events.length=ae,f=W,A()}}function A(){a.line in s&&a.column<2&&(a.column=s[a.line],a.offset+=s[a.line]-1)}}function ED(e,t){const n=t.start._index,a=t.start._bufferIndex,s=t.end._index,o=t.end._bufferIndex;let c;if(n===s)c=[e[n].slice(a,o)];else{if(c=e.slice(n,s),a>-1){const f=c[0];typeof f=="string"?c[0]=f.slice(a):c.shift()}o>0&&c.push(e[s].slice(0,o))}return c}function SD(e,t){let n=-1;const a=[];let s;for(;++n<e.length;){const o=e[n];let c;if(typeof o=="string")c=o;else switch(o){case-5:{c="\r";break}case-4:{c=`
482
482
  `;break}case-3:{c=`\r
@@ -513,4 +513,4 @@ ${g.join(`
513
513
  https://github.com/highlightjs/highlight.js/issues/2277`),Ft=ue,ot=_e),qe===void 0&&(qe=!0);const dn={code:ot,language:Ft};Ar("before:highlight",dn);const Gn=dn.result?dn.result:ea(dn.language,dn.code,qe);return Gn.code=dn.code,Ar("after:highlight",Gn),Gn}function ea(ue,_e,qe,ot){const Ft=Object.create(null);function dn(he,Se){return he.keywords[Se]}function Gn(){if(!Re.keywords){Kt.addText(ct);return}let he=0;Re.keywordPatternRe.lastIndex=0;let Se=Re.keywordPatternRe.exec(ct),Ie="";for(;Se;){Ie+=ct.substring(he,Se.index);const Qe=rn.case_insensitive?Se[0].toLowerCase():Se[0],Rt=dn(Re,Qe);if(Rt){const[oi,Wl]=Rt;if(Kt.addText(Ie),Ie="",Ft[Qe]=(Ft[Qe]||0)+1,Ft[Qe]<=xs&&(Da+=Wl),oi.startsWith("_"))Ie+=Se[0];else{const jc=rn.classNameAliases[oi]||oi;Qn(Se[0],jc)}}else Ie+=Se[0];he=Re.keywordPatternRe.lastIndex,Se=Re.keywordPatternRe.exec(ct)}Ie+=ct.substring(he),Kt.addText(Ie)}function Cn(){if(ct==="")return;let he=null;if(typeof Re.subLanguage=="string"){if(!ie[Re.subLanguage]){Kt.addText(ct);return}he=ea(Re.subLanguage,ct,!0,Mc[Re.subLanguage]),Mc[Re.subLanguage]=he._top}else he=Es(ct,Re.subLanguage.length?Re.subLanguage:null);Re.relevance>0&&(Da+=he.relevance),Kt.__addSublanguage(he._emitter,he.language)}function Et(){Re.subLanguage!=null?Cn():Gn(),ct=""}function Qn(he,Se){he!==""&&(Kt.startScope(Se),Kt.addText(he),Kt.endScope())}function Oc(he,Se){let Ie=1;const Qe=Se.length-1;for(;Ie<=Qe;){if(!he._emit[Ie]){Ie++;continue}const Rt=rn.classNameAliases[he[Ie]]||he[Ie],oi=Se[Ie];Rt?Qn(oi,Rt):(ct=oi,Gn(),ct=""),Ie++}}function ws(he,Se){return he.scope&&typeof he.scope=="string"&&Kt.openNode(rn.classNameAliases[he.scope]||he.scope),he.beginScope&&(he.beginScope._wrap?(Qn(ct,rn.classNameAliases[he.beginScope._wrap]||he.beginScope._wrap),ct=""):he.beginScope._multi&&(Oc(he.beginScope,Se),ct="")),Re=Object.create(he,{parent:{value:Re}}),Re}function Vl(he,Se,Ie){let Qe=C(he.endRe,Ie);if(Qe){if(he["on:end"]){const Rt=new t(he);he["on:end"](Se,Rt),Rt.isMatchIgnored&&(Qe=!1)}if(Qe){for(;he.endsParent&&he.parent;)he=he.parent;return he}}if(he.endsWithParent)return Vl(he.parent,Se,Ie)}function _s(he){return Re.matcher.regexIndex===0?(ct+=he[0],1):(La=!0,0)}function ed(he){const Se=he[0],Ie=he.rule,Qe=new t(Ie),Rt=[Ie.__beforeBegin,Ie["on:begin"]];for(const oi of Rt)if(oi&&(oi(he,Qe),Qe.isMatchIgnored))return _s(Se);return Ie.skip?ct+=Se:(Ie.excludeBegin&&(ct+=Se),Et(),!Ie.returnBegin&&!Ie.excludeBegin&&(ct=Se)),ws(Ie,he),Ie.returnBegin?0:Se.length}function An(he){const Se=he[0],Ie=_e.substring(he.index),Qe=Vl(Re,he,Ie);if(!Qe)return Nr;const Rt=Re;Re.endScope&&Re.endScope._wrap?(Et(),Qn(Se,Re.endScope._wrap)):Re.endScope&&Re.endScope._multi?(Et(),Oc(Re.endScope,he)):Rt.skip?ct+=Se:(Rt.returnEnd||Rt.excludeEnd||(ct+=Se),Et(),Rt.excludeEnd&&(ct=Se));do Re.scope&&Kt.closeNode(),!Re.skip&&!Re.subLanguage&&(Da+=Re.relevance),Re=Re.parent;while(Re!==Qe.parent);return Qe.starts&&ws(Qe.starts,he),Rt.returnEnd?0:Se.length}function Xl(){const he=[];for(let Se=Re;Se!==rn;Se=Se.parent)Se.scope&&he.unshift(Se.scope);he.forEach(Se=>Kt.openNode(Se))}let Or={};function ks(he,Se){const Ie=Se&&Se[0];if(ct+=he,Ie==null)return Et(),0;if(Or.type==="begin"&&Se.type==="end"&&Or.index===Se.index&&Ie===""){if(ct+=_e.slice(Se.index,Se.index+1),!wt){const Qe=new Error(`0 width match regex (${ue})`);throw Qe.languageName=ue,Qe.badRule=Or.rule,Qe}return 1}if(Or=Se,Se.type==="begin")return ed(Se);if(Se.type==="illegal"&&!qe){const Qe=new Error('Illegal lexeme "'+Ie+'" for mode "'+(Re.scope||"<unnamed>")+'"');throw Qe.mode=Re,Qe}else if(Se.type==="end"){const Qe=An(Se);if(Qe!==Nr)return Qe}if(Se.type==="illegal"&&Ie==="")return ct+=`
514
514
  `,1;if(Zl>1e5&&Zl>Se.index*3)throw new Error("potential infinite loop, way more iterations than matches");return ct+=Ie,Ie.length}const rn=vn(ue);if(!rn)throw Ot(bt.replace("{}",ue)),new Error('Unknown language: "'+ue+'"');const Rc=an(rn);let Ns="",Re=ot||Rc;const Mc={},Kt=new be.__emitter(be);Xl();let ct="",Da=0,ia=0,Zl=0,La=!1;try{if(rn.__emitTokens)rn.__emitTokens(_e,Kt);else{for(Re.matcher.considerAll();;){Zl++,La?La=!1:Re.matcher.considerAll(),Re.matcher.lastIndex=ia;const he=Re.matcher.exec(_e);if(!he)break;const Se=_e.substring(ia,he.index),Ie=ks(Se,he);ia=he.index+Ie}ks(_e.substring(ia))}return Kt.finalize(),Ns=Kt.toHTML(),{language:ue,value:Ns,relevance:Da,illegal:!1,_emitter:Kt,_top:Re}}catch(he){if(he.message&&he.message.includes("Illegal"))return{language:ue,value:xn(_e),illegal:!0,relevance:0,_illegalBy:{message:he.message,index:ia,context:_e.slice(ia-100,ia+100),mode:he.mode,resultSoFar:Ns},_emitter:Kt};if(wt)return{language:ue,value:xn(_e),illegal:!1,relevance:0,errorRaised:he,_emitter:Kt,_top:Re};throw he}}function vs(ue){const _e={value:xn(ue),illegal:!1,relevance:0,_top:ve,_emitter:new be.__emitter(be)};return _e._emitter.addText(ue),_e}function Es(ue,_e){_e=_e||be.languages||Object.keys(ie);const qe=vs(ue),ot=_e.filter(vn).filter(Ma).map(Et=>ea(Et,ue,!1));ot.unshift(qe);const Ft=ot.sort((Et,Qn)=>{if(Et.relevance!==Qn.relevance)return Qn.relevance-Et.relevance;if(Et.language&&Qn.language){if(vn(Et.language).supersetOf===Qn.language)return 1;if(vn(Qn.language).supersetOf===Et.language)return-1}return 0}),[dn,Gn]=Ft,Cn=dn;return Cn.secondBest=Gn,Cn}function Bi(ue,_e,qe){const ot=_e&&pe[_e]||qe;ue.classList.add("hljs"),ue.classList.add(`language-${ot}`)}function Ut(ue){let _e=null;const qe=Bt(ue);if(Me(qe))return;if(Ar("before:highlightElement",{el:ue,language:qe}),ue.dataset.highlighted){console.log("Element previously highlighted. To highlight again, first unset `dataset.highlighted`.",ue);return}if(ue.children.length>0&&(be.ignoreUnescapedHTML||(console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk."),console.warn("https://github.com/highlightjs/highlight.js/wiki/security"),console.warn("The element with unescaped HTML:"),console.warn(ue)),be.throwUnescapedHTML))throw new zi("One of your code blocks includes unescaped HTML.",ue.innerHTML);_e=ue;const ot=_e.textContent,Ft=qe?Nt(ot,{language:qe,ignoreIllegals:!0}):Es(ot);ue.innerHTML=Ft.value,ue.dataset.highlighted="yes",Bi(ue,qe,Ft.language),ue.result={language:Ft.language,re:Ft.relevance,relevance:Ft.relevance},Ft.secondBest&&(ue.secondBest={language:Ft.secondBest.language,relevance:Ft.secondBest.relevance}),Ar("after:highlightElement",{el:ue,result:Ft,text:ot})}function fn(ue){be=Nc(be,ue)}const Ra=()=>{Ss(),te("10.6.0","initHighlighting() deprecated. Use highlightAll() now.")};function Ql(){Ss(),te("10.6.0","initHighlightingOnLoad() deprecated. Use highlightAll() now.")}let Tc=!1;function Ss(){function ue(){Ss()}if(document.readyState==="loading"){Tc||window.addEventListener("DOMContentLoaded",ue,!1),Tc=!0;return}document.querySelectorAll(be.cssSelector).forEach(Ut)}function Cc(ue,_e){let qe=null;try{qe=_e(B)}catch(ot){if(Ot("Language definition for '{}' could not be registered.".replace("{}",ue)),wt)Ot(ot);else throw ot;qe=ve}qe.name||(qe.name=ue),ie[ue]=qe,qe.rawDefinition=_e.bind(null,B),qe.aliases&&ta(qe.aliases,{languageName:ue})}function Cr(ue){delete ie[ue];for(const _e of Object.keys(pe))pe[_e]===ue&&delete pe[_e]}function Yl(){return Object.keys(ie)}function vn(ue){return ue=(ue||"").toLowerCase(),ie[ue]||ie[pe[ue]]}function ta(ue,{languageName:_e}){typeof ue=="string"&&(ue=[ue]),ue.forEach(qe=>{pe[qe.toLowerCase()]=_e})}function Ma(ue){const _e=vn(ue);return _e&&!_e.disableAutodetect}function ja(ue){ue["before:highlightBlock"]&&!ue["before:highlightElement"]&&(ue["before:highlightElement"]=_e=>{ue["before:highlightBlock"](Object.assign({block:_e.el},_e))}),ue["after:highlightBlock"]&&!ue["after:highlightElement"]&&(ue["after:highlightElement"]=_e=>{ue["after:highlightBlock"](Object.assign({block:_e.el},_e))})}function Ht(ue){ja(ue),je.push(ue)}function Ac(ue){const _e=je.indexOf(ue);_e!==-1&&je.splice(_e,1)}function Ar(ue,_e){const qe=ue;je.forEach(function(ot){ot[qe]&&ot[qe](_e)})}function na(ue){return te("10.7.0","highlightBlock will be removed entirely in v12.0"),te("10.7.0","Please use highlightElement now."),Ut(ue)}Object.assign(B,{highlight:Nt,highlightAuto:Es,highlightAll:Ss,highlightElement:Ut,highlightBlock:na,configure:fn,initHighlighting:Ra,initHighlightingOnLoad:Ql,registerLanguage:Cc,unregisterLanguage:Cr,listLanguages:Yl,getLanguage:vn,registerAliases:ta,autoDetection:Ma,inherit:Nc,addPlugin:Ht,removePlugin:Ac}),B.debugMode=function(){wt=!1},B.safeMode=function(){wt=!0},B.versionString=lt,B.regex={concat:w,lookahead:x,either:k,optional:S,anyNumberOfTimes:v};for(const ue in Wt)typeof Wt[ue]=="object"&&e(Wt[ue]);return Object.assign(B,Wt),B},Tn=Tr({});return Tn.newInstance=()=>Tr({}),Fm=Tn,Tn.HighlightJS=Tn,Tn.default=Tn,Fm}var H4=q4();const K4=Np(H4),tE={},G4="hljs-";function Q4(e){const t=K4.newInstance();return e&&o(e),{highlight:n,highlightAuto:a,listLanguages:s,register:o,registerAlias:c,registered:f};function n(d,h,y){const g=y||tE,x=typeof g.prefix=="string"?g.prefix:G4;if(!t.getLanguage(d))throw new Error("Unknown language: `"+d+"` is not registered");t.configure({__emitter:Y4,classPrefix:x});const v=t.highlight(h,{ignoreIllegals:!0,language:d});if(v.errorRaised)throw new Error("Could not highlight with `Highlight.js`",{cause:v.errorRaised});const S=v._emitter.root,w=S.data;return w.language=v.language,w.relevance=v.relevance,S}function a(d,h){const g=(h||tE).subset||s();let x=-1,v=0,S;for(;++x<g.length;){const w=g[x];if(!t.getLanguage(w))continue;const _=n(w,d,h);_.data&&_.data.relevance!==void 0&&_.data.relevance>v&&(v=_.data.relevance,S=_)}return S||{type:"root",children:[],data:{language:void 0,relevance:v}}}function s(){return t.listLanguages()}function o(d,h){if(typeof d=="string")t.registerLanguage(d,h);else{let y;for(y in d)Object.hasOwn(d,y)&&t.registerLanguage(y,d[y])}}function c(d,h){if(typeof d=="string")t.registerAliases(typeof h=="string"?h:[...h],{languageName:d});else{let y;for(y in d)if(Object.hasOwn(d,y)){const g=d[y];t.registerAliases(typeof g=="string"?g:[...g],{languageName:y})}}}function f(d){return!!t.getLanguage(d)}}class Y4{constructor(t){this.options=t,this.root={type:"root",children:[],data:{language:void 0,relevance:0}},this.stack=[this.root]}addText(t){if(t==="")return;const n=this.stack[this.stack.length-1],a=n.children[n.children.length-1];a&&a.type==="text"?a.value+=t:n.children.push({type:"text",value:t})}startScope(t){this.openNode(String(t))}endScope(){this.closeNode()}__addSublanguage(t,n){const a=this.stack[this.stack.length-1],s=t.root.children;n?a.children.push({type:"element",tagName:"span",properties:{className:[n]},children:s}):a.children.push(...s)}openNode(t){const n=this,a=t.split(".").map(function(c,f){return f?c+"_".repeat(f):n.options.classPrefix+c}),s=this.stack[this.stack.length-1],o={type:"element",tagName:"span",properties:{className:a},children:[]};s.children.push(o),this.stack.push(o)}closeNode(){this.stack.pop()}finalize(){}toHTML(){return""}}const V4={};function Mg(e){const t=e||V4,n=t.aliases,a=t.detect||!1,s=t.languages||P4,o=t.plainText,c=t.prefix,f=t.subset;let d="hljs";const h=Q4(s);if(n&&h.registerAlias(n),c){const y=c.indexOf("-");d=y===-1?c:c.slice(0,y)}return function(y,g){Jf(y,"element",function(x,v,S){if(x.tagName!=="code"||!S||S.type!=="element"||S.tagName!=="pre")return;const w=X4(x);if(w===!1||!w&&!a||w&&o&&o.includes(w))return;Array.isArray(x.properties.className)||(x.properties.className=[]),x.properties.className.includes(d)||x.properties.className.unshift(d);const _=pz(x,{whitespace:"pre"});let k;try{k=w?h.highlight(w,_,{prefix:c}):h.highlightAuto(_,{prefix:c,subset:f})}catch(R){const C=R;if(w&&/Unknown language/.test(C.message)){g.message("Cannot highlight as `"+w+"`, it’s not registered",{ancestors:[S,x],cause:C,place:x.position,ruleId:"missing-language",source:"rehype-highlight"});return}throw C}!w&&k.data&&k.data.language&&x.properties.className.push("language-"+k.data.language),k.children.length>0&&(x.children=k.children)})}}function X4(e){const t=e.properties.className;let n=-1;if(!Array.isArray(t))return;let a;for(;++n<t.length;){const s=String(t[n]);if(s==="no-highlight"||s==="nohighlight")return!1;!a&&s.slice(0,5)==="lang-"&&(a=s.slice(5)),!a&&s.slice(0,9)==="language-"&&(a=s.slice(9))}return a}function Z4({name:e,projects:t,onClose:n,onChange:a}){const{confirm:s}=si(),{data:o,isLoading:c,isError:f,error:d,refetch:h}=dt({queryKey:["skill",e],queryFn:()=>zO(e)});M.useEffect(()=>{const w=_=>{_.key==="Escape"&&n()};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[n]);const y=async w=>{await UO(e,w),h(),a()},g=async w=>{await s({title:`从 ${w} 移除 ${e}`,body:"skill 链接会被解除,项目后续运行时将无法使用该 skill。",confirm:"移除",danger:!0})&&(await FO(e,w),h(),a())},x=async w=>{await $O(e,w),h(),a()},v=async w=>{await s({title:`解冻 ${e} @ ${w}`,body:"本地对这个 skill 的改动会被覆盖,回到最新共享版本。",confirm:"解冻",danger:!0})&&(await PO(e,w),h(),a())},S=new Map(((o==null?void 0:o.linkedProjects)??[]).map(w=>[w.project,w.state]));return m.jsx("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-40 flex items-start justify-center p-6 bg-black/30 overflow-auto",children:m.jsxs("div",{className:"nb-card mt-8 w-full max-w-4xl",children:[m.jsxs("header",{className:"flex items-start justify-between gap-4 mb-4",children:[m.jsxs("div",{children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-3xl font-bold",children:e}),o&&m.jsxs("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:[o.category," · ",o.origin||"local"]})]}),m.jsx("button",{onClick:n,className:"nb-btn nb-btn-mint p-2","aria-label":"关闭",type:"button",children:m.jsx(vr,{size:16,strokeWidth:3})})]}),c&&m.jsx("p",{children:"加载中…"}),f&&m.jsxs("p",{className:"text-[var(--color-crashed)]",children:["加载失败: ",d instanceof Error?d.message:String(d)]}),o&&m.jsxs("div",{className:"flex flex-col gap-4",children:[m.jsxs("div",{className:"nb-card bg-[var(--color-bg-cream)] p-4",children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-3 uppercase tracking-wider",children:"项目链接状态"}),m.jsxs("div",{className:"flex flex-col gap-2",children:[t.map(w=>{const _=S.get(w);return m.jsxs("div",{className:"flex items-center justify-between gap-3 p-2 bg-[var(--color-bg)] border-2 border-[var(--color-text)] rounded-lg",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[m.jsx("span",{className:"font-[family-name:var(--font-mono)] font-bold text-sm",children:w}),_==="linked"&&m.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:"linked"}),_==="frozen"&&m.jsx("span",{className:"nb-status",style:{background:"var(--color-stuck-bg)",color:"var(--color-stuck)"},children:"frozen"}),!_&&m.jsx("span",{className:"nb-status",style:{background:"var(--color-idle-bg)",color:"var(--color-idle)"},children:"absent"})]}),m.jsxs("div",{className:"flex gap-2",children:[!_&&m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>y(w),type:"button",children:[m.jsx(iA,{size:11})," link"]}),_==="linked"&&m.jsxs(m.Fragment,{children:[m.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>x(w),type:"button",children:[m.jsx(_A,{size:11})," freeze"]}),m.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 10px",fontSize:11},onClick:()=>g(w),type:"button",children:"unlink"})]}),_==="frozen"&&m.jsxs(m.Fragment,{children:[m.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>v(w),type:"button",children:[m.jsx(UC,{size:11})," unfreeze"]}),m.jsx("button",{className:"nb-btn nb-btn-danger",style:{padding:"4px 10px",fontSize:11},onClick:()=>g(w),type:"button",children:"unlink"})]})]})]},w)}),t.length===0&&m.jsx("p",{className:"text-sm text-[var(--color-text-muted)] italic",children:"还没有任何项目。先去创建一个项目。"})]})]}),m.jsxs("div",{children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:"SKILL.md 预览"}),m.jsx("div",{className:"prose-chat bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg p-4 max-h-80 overflow-auto text-sm",children:o.body?m.jsx(kg,{remarkPlugins:[Ag],rehypePlugins:[Mg],children:o.body}):m.jsx("p",{className:"text-[var(--color-text-muted)] italic",children:"(empty)"})})]}),o.references.length>0&&m.jsxs("div",{children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] text-sm font-bold mb-2 uppercase tracking-wider",children:"References"}),m.jsx("ul",{className:"flex flex-col gap-2",children:o.references.map(w=>m.jsx(W4,{skillName:e,file:w.name,lines:w.lines},w.name))})]})]})]})})}function W4({skillName:e,file:t,lines:n}){const[a,s]=M.useState(!1),{data:o,isLoading:c,isError:f,error:d}=dt({queryKey:["skill-ref",e,t],queryFn:()=>BO(e,t),enabled:a,staleTime:1/0});return m.jsxs("li",{className:"border-2 border-[var(--color-text)] rounded-lg overflow-hidden bg-[var(--color-bg-cream)]",children:[m.jsxs("button",{type:"button",onClick:()=>s(h=>!h),"aria-label":`${a?"收起":"展开"} ${t}`,"aria-expanded":a,className:"w-full flex items-center gap-2 px-3 py-2 text-sm font-[family-name:var(--font-mono)] hover:bg-[var(--color-accent-yellow)] transition-colors",children:[m.jsx($p,{size:12,strokeWidth:3,className:["transition-transform",a?"rotate-90":""].join(" ")}),m.jsx(qp,{size:12,strokeWidth:2.5}),m.jsx("span",{className:"flex-1 text-left font-bold",children:t}),m.jsxs("span",{className:"text-xs text-[var(--color-text-subtle)]",children:[n," lines"]})]}),a&&m.jsxs("div",{className:"px-4 py-3 border-t-2 border-[var(--color-text)] bg-[var(--color-bg)] max-h-96 overflow-auto",children:[c&&m.jsx("p",{className:"text-xs text-[var(--color-text-muted)]",children:"加载中…"}),f&&m.jsxs("p",{className:"text-xs text-[var(--color-crashed)]",children:["加载失败: ",d instanceof Error?d.message:String(d)]}),o&&m.jsx("div",{className:"prose-chat text-sm",children:m.jsx(kg,{remarkPlugins:[Ag],rehypePlugins:[Mg],children:o.content})})]})]})}const J4=[{value:"all",label:"全部"},{value:"language",label:"language"},{value:"end",label:"end"},{value:"persona",label:"persona"},{value:"workflow",label:"workflow"},{value:"other",label:"other"}],eB={language:"var(--color-accent-purple)",end:"var(--color-secondary)",persona:"var(--color-primary)",workflow:"var(--color-accent-mint)",other:"var(--color-bg-cream)"};function tB(){var x;const[e,t]=M.useState("all"),[n,a]=M.useState(""),[s,o]=M.useState(null),c=Pn(),{data:f,isLoading:d}=dt({queryKey:["skills"],queryFn:()=>lg()}),h=dt({queryKey:["projects"],queryFn:ds}),y=M.useMemo(()=>((f==null?void 0:f.data)??[]).filter(S=>!(e!=="all"&&S.category!==e||n&&!S.name.toLowerCase().includes(n.toLowerCase()))),[f,e,n]),g=M.useMemo(()=>{const v=(f==null?void 0:f.data)??[],S={all:v.length};for(const w of v)S[w.category]=(S[w.category]??0)+1;return S},[f]);return m.jsxs("div",{className:"flex flex-col gap-4 max-w-full",children:[m.jsxs("header",{className:"flex items-center justify-between flex-wrap gap-3",children:[m.jsxs("div",{children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:"Skills 🎯"}),m.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mt-1",children:d?"加载中…":`${(f==null?void 0:f.data.length)??0} 个 user-level skill`})]}),m.jsx("div",{className:"flex gap-3 items-center",children:m.jsxs("button",{className:"nb-btn nb-btn-mint",onClick:async()=>{await qO(),c.invalidateQueries({queryKey:["skills"]})},type:"button",children:[m.jsx(Cl,{size:14,strokeWidth:2.5}),"Sync bundled"]})})]}),m.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[m.jsxs("div",{className:"relative flex-1 max-w-md",children:[m.jsx(xf,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-subtle)]"}),m.jsx("input",{className:"nb-input pl-9 w-full",placeholder:"搜索 skill…",value:n,onChange:v=>a(v.target.value),"aria-label":"搜索 skill"})]}),m.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:J4.map(v=>m.jsxs("button",{type:"button",onClick:()=>t(v.value),className:["px-3 py-1 rounded-full text-xs font-bold font-[family-name:var(--font-body)]",e===v.value?"bg-[var(--color-text)] text-[var(--color-bg)]":"text-[var(--color-text-muted)] hover:text-[var(--color-text)]"].join(" "),children:[v.label," ",g[v.value]]},v.value))})]}),m.jsx("div",{className:"grid gap-4 grid-cols-[repeat(auto-fill,minmax(280px,1fr))]",children:y.map(v=>{var S;return m.jsx(nB,{skill:v,projectCount:((S=h.data)==null?void 0:S.data.length)??0,onOpen:()=>o(v.name)},v.name)})}),s&&m.jsx(Z4,{name:s,projects:((x=h.data)==null?void 0:x.data.map(v=>v.name))??[],onClose:()=>o(null),onChange:()=>c.invalidateQueries({queryKey:["skills"]})})]})}function nB({skill:e,projectCount:t,onOpen:n}){const a=eB[e.category];return m.jsxs("article",{onClick:n,onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),n())},tabIndex:0,role:"button","aria-label":`Open ${e.name}`,className:"nb-card nb-card-interactive flex flex-col gap-3",children:[m.jsxs("div",{className:"flex items-center justify-between",children:[m.jsx("h3",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:e.name}),m.jsx("span",{className:"nb-badge text-[10px]",style:{background:a},children:e.category})]}),m.jsx("p",{className:"text-sm text-[var(--color-text-muted)] leading-5 line-clamp-3",children:e.description||"(no description)"}),m.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:[m.jsx("span",{className:"font-bold",children:e.linkedProjects.length>0?`● linked in ${e.linkedProjects.length}`:"○ not linked"}),m.jsxs("span",{className:"text-[var(--color-text-subtle)]",children:[t," projects"]})]})]})}function iB(){var s;const e=dt({queryKey:["system-info"],queryFn:r1}),t=dt({queryKey:["system-env"],queryFn:$A}),[n,a]=M.useState(!1);return m.jsxs("div",{className:"flex flex-col gap-6 max-w-4xl",children:[m.jsx("header",{children:m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold",children:"系统 ⚙️"})}),m.jsx(aB,{current:(s=e.data)==null?void 0:s.version}),m.jsxs("section",{className:"nb-card",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold mb-3",children:"运行时"}),e.data?m.jsxs("dl",{className:"grid grid-cols-[160px_1fr] gap-y-2 text-sm",children:[m.jsx("dt",{className:"font-bold",children:"Node"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:e.data.nodeVersion}),m.jsx("dt",{className:"font-bold",children:"Platform"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:e.data.platform}),m.jsx("dt",{className:"font-bold",children:"PID"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:e.data.pid??"—"}),m.jsx("dt",{className:"font-bold",children:"Uptime"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:oB(e.data.uptimeMs)})]}):m.jsx("p",{className:"text-[var(--color-text-muted)]",children:"加载中…"})]}),m.jsxs("section",{className:"nb-card",children:[m.jsxs("div",{className:"flex items-center justify-between mb-3",children:[m.jsxs("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:["全局配置 ",m.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"})]}),n?m.jsx("span",{className:"text-xs text-[var(--color-stuck)] font-bold",children:"⚠ 编辑模式"}):m.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>a(!0),type:"button","aria-label":"编辑 env 文件",children:[m.jsx(Hp,{size:12,strokeWidth:2.5})," 编辑"]})]}),n?m.jsx(rB,{onClose:()=>{a(!1),t.refetch()}}):t.data&&t.data.exists?m.jsx("dl",{className:"grid grid-cols-[220px_1fr] gap-y-1 text-sm font-[family-name:var(--font-mono)]",children:t.data.entries.map(o=>m.jsxs("div",{className:"contents",children:[m.jsxs("dt",{className:"font-bold flex items-center gap-2",children:[o.masked&&m.jsx("span",{className:"text-[var(--color-stuck)]",children:"🔒"}),o.key]}),m.jsx("dd",{className:"text-[var(--color-text-muted)] truncate",children:o.value})]},o.key))}):m.jsxs("p",{className:"text-[var(--color-text-muted)] text-sm",children:['env 文件不存在。点"编辑"或者终端运行 ',m.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"}),"。"]})]}),m.jsx(sB,{})]})}function aB({current:e}){var S;const{confirm:t,alert:n}=si(),[a,s]=M.useState(!1),[o,c]=M.useState(null),f=dt({queryKey:["latest-version"],queryFn:HA,enabled:!1}),[d,h]=M.useState(null),[y,g]=M.useState("npm i -g @coralai/sps-cli@latest"),x=async()=>{var _;if(await t({title:"升级 sps-cli",body:`当前 ${e},升级到 ${(_=f.data)==null?void 0:_.latest}。要求所有 pipeline 已停止。升级后请重启 sps console 生效。`,confirm:"升级"})){s(!0),c(null),h(null);try{const k=await KA();if(c(k.output),h(k.installedVersion),g(k.command),k.ok)n({title:"升级完成",body:`装上了 v${k.installedVersion}。请 \`pkill -f "sps console"\` 再重启以生效。`});else{const R=k.installedVersion&&k.installedVersion===e?`npm 执行完毕但版本没变(仍 ${k.installedVersion})——多半是权限或 registry 问题。可复制下面的命令在终端手动跑。`:"npm 没装上新版本。可复制命令手动跑,或看下面日志定位。";n({title:"升级未生效",body:R})}}catch(k){c(k.message),n({title:"升级失败",body:k.message})}finally{s(!1)}}},v=async()=>{const w=f.data&&!f.data.upToDate?`npm i -g @coralai/sps-cli@${f.data.latest}`:y;try{await navigator.clipboard.writeText(w),n({title:"命令已复制",body:`粘贴到终端运行即可:
515
515
  ${w}`})}catch{n({title:"复制失败",body:`请手动复制:
516
- ${w}`})}};return m.jsxs("section",{className:"nb-card",children:[m.jsxs("div",{className:"flex items-center justify-between mb-3",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"版本"}),m.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>f.refetch(),disabled:f.isFetching||!e,type:"button","aria-label":"检查最新版本",children:[f.isFetching?m.jsx(Zt,{size:12,strokeWidth:3,className:"animate-spin"}):m.jsx(Cl,{size:12,strokeWidth:2.5}),"检查更新"]})]}),m.jsxs("dl",{className:"grid grid-cols-[160px_1fr] gap-y-2 text-sm",children:[m.jsx("dt",{className:"font-bold",children:"sps-cli (当前)"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:e??"—"}),f.data&&m.jsxs(m.Fragment,{children:[m.jsx("dt",{className:"font-bold",children:"npm (最新)"}),m.jsxs("dd",{className:"font-[family-name:var(--font-mono)] flex items-center gap-2 flex-wrap",children:[f.data.latest,f.data.upToDate?m.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:"最新"}):m.jsxs(m.Fragment,{children:[m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"3px 10px",fontSize:11},onClick:x,disabled:a,type:"button","aria-label":"升级到最新版本",children:[a?m.jsx(Zt,{size:11,strokeWidth:3,className:"animate-spin"}):m.jsx(XE,{size:11,strokeWidth:2.5}),"升级"]}),m.jsxs("button",{className:"nb-btn",style:{padding:"3px 10px",fontSize:11},onClick:v,type:"button","aria-label":"复制升级命令",title:"自动升级失败时手动跑",children:[m.jsx(DC,{size:11,strokeWidth:2.5})," 复制命令"]})]})]})]}),d&&m.jsxs(m.Fragment,{children:[m.jsx("dt",{className:"font-bold",children:"已安装"}),m.jsxs("dd",{className:"font-[family-name:var(--font-mono)] flex items-center gap-2",children:[d,d===((S=f.data)==null?void 0:S.latest)?m.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:"已生效(重启 console 后可见)"}):d===e?m.jsx("span",{className:"nb-status",style:{background:"var(--color-stuck-bg)",color:"var(--color-stuck)"},children:"未升级成功"}):null]})]}),f.isError&&m.jsxs(m.Fragment,{children:[m.jsx("dt",{className:"font-bold",children:"检查"}),m.jsx("dd",{className:"text-[var(--color-crashed)] text-xs",children:f.error instanceof Error?f.error.message:String(f.error)})]})]}),o&&m.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:o})]})}function rB({onClose:e}){const t=Pn(),{alert:n}=si(),a=dt({queryKey:["system-env-raw"],queryFn:PA}),[s,o]=M.useState(null),[c,f]=M.useState(null);M.useEffect(()=>{a.data&&s===null&&(o(a.data.content),f(a.data.etag))},[a.data,s]);const d=s!==null&&a.data&&s!==a.data.content,h=$n({mutationFn:()=>{if(s===null)throw new Error("no draft");return qA(s,c??"")},onSuccess:()=>{t.invalidateQueries({queryKey:["system-env"]}),t.invalidateQueries({queryKey:["system-env-raw"]}),e()},onError:y=>{const g=y.status;n({title:g===409?"env 被其他地方修改了":"保存失败",body:g===409?"请点取消后重开编辑。":y instanceof Error?y.message:String(y)})}});return a.isLoading?m.jsx("p",{className:"text-[var(--color-text-muted)]",children:"加载中…"}):m.jsxs("div",{children:[m.jsx("p",{className:"text-xs text-[var(--color-stuck)] font-bold mb-2",children:"⚠ 文件包含凭证明文。保存时保持 0600 权限。"}),m.jsx("textarea",{className:"nb-input w-full font-[family-name:var(--font-mono)] text-xs",style:{minHeight:320,resize:"vertical"},value:s??"",onChange:y=>o(y.target.value),spellCheck:!1,"aria-label":"env 文件编辑器"}),m.jsxs("div",{className:"flex items-center justify-between mt-3",children:[m.jsxs("span",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:[c?`etag: ${c}`:"",d?" · ● 未保存":""]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px"},onClick:e,disabled:h.isPending,type:"button",children:[m.jsx(vr,{size:12,strokeWidth:3})," 取消"]}),m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px"},onClick:()=>h.mutate(),disabled:!d||h.isPending,type:"button","aria-label":"保存 env",children:[h.isPending?m.jsx(Zt,{size:12,strokeWidth:3,className:"animate-spin"}):m.jsx(Df,{size:12,strokeWidth:3}),"保存"]})]})]})]})}function sB(){var g;const{alert:e}=si(),t=dt({queryKey:["projects"],queryFn:ds}),[n,a]=M.useState({}),[s,o]=M.useState({}),[c,f]=M.useState({}),d=(((g=t.data)==null?void 0:g.data)??[]).map(x=>({project:x.name})),h=async(x,v)=>{o(S=>({...S,[x]:v?"fix":"check"}));try{const S=await GA(x,v);a(w=>({...w,[x]:S})),f(w=>({...w,[x]:!0}))}catch(S){e({title:`doctor ${v?"修复":"检查"}失败`,body:S instanceof Error?S.message:String(S)})}finally{o(S=>({...S,[x]:null}))}},y=async()=>{for(const x of d)await h(x.project,!1)};return m.jsxs("section",{className:"nb-card",children:[m.jsxs("div",{className:"flex items-center justify-between mb-3",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"项目健康检查"}),m.jsxs("button",{className:"nb-btn nb-btn-mint",style:{padding:"6px 12px",fontSize:12},onClick:()=>{y()},disabled:d.length===0||Object.values(s).some(Boolean),type:"button",children:[m.jsx(Cl,{size:12,strokeWidth:2.5}),"检查全部"]})]}),d.length===0?m.jsx("p",{className:"text-[var(--color-text-muted)] text-sm",children:"还没有项目。"}):m.jsx("ul",{className:"flex flex-col gap-2",children:d.map(x=>{const v=n[x.project],S=s[x.project],w=v?v.checks.filter(C=>C.status==="fail").length:0,_=v?v.checks.filter(C=>C.status==="warn").length:0,k=c[x.project]??!1,R=v!=null;return m.jsxs("li",{className:"bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg",children:[m.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[m.jsxs("button",{type:"button",onClick:()=>f(C=>({...C,[x.project]:!k})),disabled:!R,className:"flex items-center gap-2 flex-1 text-left min-w-0","aria-label":k?"折叠":"展开",children:[R&&v.ok?m.jsx(ap,{size:16,className:"text-[var(--color-running)] shrink-0",strokeWidth:2.5}):R?m.jsx(rc,{size:16,className:"text-[var(--color-stuck)] shrink-0",strokeWidth:2.5}):m.jsx(ap,{size:16,className:"text-[var(--color-text-subtle)] shrink-0",strokeWidth:2.5}),R&&(k?m.jsx(yc,{size:12}):m.jsx($p,{size:12})),m.jsx("span",{className:"font-bold font-[family-name:var(--font-mono)]",children:x.project}),R?v.ok?m.jsx("span",{className:"text-xs text-[var(--color-running)] font-semibold",children:"OK"}):m.jsxs("span",{className:"text-xs text-[var(--color-stuck)] font-semibold",children:[w," fail · ",_," warn"]}):m.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:'点 "检查" 运行 sps doctor'})]}),m.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>{h(x.project,!1)},disabled:!!S,type:"button","aria-label":"检查",children:[S==="check"?m.jsx(Zt,{size:11,strokeWidth:3,className:"animate-spin"}):m.jsx(Cl,{size:11,strokeWidth:2.5}),"检查"]}),R&&!v.ok&&m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>{h(x.project,!0)},disabled:!!S,type:"button","aria-label":"自动修复",children:[S==="fix"?m.jsx(Zt,{size:11,strokeWidth:3,className:"animate-spin"}):m.jsx(a1,{size:11,strokeWidth:2.5}),"修复"]})]}),k&&R&&m.jsxs("div",{className:"border-t-2 border-dashed border-[var(--color-text)] px-3 py-2",children:[m.jsx("ul",{className:"flex flex-col gap-1 text-xs font-[family-name:var(--font-mono)]",children:v.checks.map((C,D)=>m.jsx(lB,{check:C},`${C.name}-${D}`))}),v.fixes.length>0&&m.jsxs("div",{className:"mt-3 bg-[var(--color-running-bg)] border-2 border-[var(--color-running)] rounded p-2",children:[m.jsx("div",{className:"text-xs font-bold text-[var(--color-running)] mb-1",children:"已修复"}),m.jsx("ul",{className:"text-xs list-disc pl-4",children:v.fixes.map((C,D)=>m.jsx("li",{children:C},D))})]})]})]},x.project)})})]})}function lB({check:e}){const t=e.status==="pass"?m.jsx(ap,{size:12,className:"text-[var(--color-running)]",strokeWidth:2.5}):e.status==="fail"?m.jsx(rc,{size:12,className:"text-[var(--color-crashed)]",strokeWidth:2.5}):e.status==="warn"?m.jsx(rc,{size:12,className:"text-[var(--color-stuck)]",strokeWidth:2.5}):m.jsx("span",{className:"w-3 h-3 rounded-full bg-[var(--color-text-subtle)] inline-block"});return m.jsxs("li",{className:"flex items-start gap-2",children:[m.jsx("span",{className:"pt-0.5 shrink-0",children:t}),m.jsx("span",{className:"font-bold w-32 shrink-0",children:e.name}),m.jsx("span",{className:"text-[var(--color-text-muted)] break-words",children:e.message})]})}function oB(e){const t=Math.floor(e/1e3),n=Math.floor(t/3600),a=Math.floor(t%3600/60),s=t%60;return n>0?`${n}h ${a}m ${s}s`:a>0?`${a}m ${s}s`:`${s}s`}function cB(){return qt("/api/chat/sessions")}function uB(e){return qt(`/api/chat/sessions/${e}`)}async function nE(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 fB(e){const t=await fetch(`/api/chat/sessions/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(`${t.status}`)}async function dB(e,t){const n=await fetch(`/api/chat/sessions/${e}/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!n.ok)throw new Error(`${n.status}: ${await n.text()}`);return await n.json()}async function hB(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 mB(e,t){const n=t?`?since=${encodeURIComponent(t)}`:"";return qt(`/api/chat/sessions/${e}/messages${n}`)}function iE(){var R,C,D,$,j,q;const{sessionId:e}=UE(),t=Sr(),n=Pn(),{confirm:a,alert:s}=si(),o=dt({queryKey:["chat-sessions"],queryFn:cB}),c=dt({queryKey:["chat-session",e],queryFn:()=>uB(e??""),enabled:!!e}),[f,d]=M.useState(null),[h,y]=M.useState(""),[g,x]=M.useState(!1),v=M.useRef(null);M.useEffect(()=>{if(!e)return;const U=new EventSource(`/stream/chat/${encodeURIComponent(e)}`);let Z=!0;return U.addEventListener("open",()=>{if(Z){Z=!1;return}const A=n.getQueryData(["chat-session",e]),P=A!=null&&A.messages.length?A.messages[A.messages.length-1].ts:void 0;mB(e,P).then(G=>{G.data.length!==0&&n.setQueryData(["chat-session",e],le=>{if(!le)return le;const ae=new Set(le.messages.map(K=>K.id)),W=G.data.filter(K=>!ae.has(K.id));return W.length===0?le:{...le,messages:[...le.messages,...W],lastMessageAt:W[W.length-1].ts,messageCount:le.messageCount+W.length}})}).catch(()=>{})}),U.addEventListener("chat.message",A=>{try{const P=JSON.parse(A.data);n.setQueryData(["chat-session",e],G=>{if(!G||G.messages.some(W=>W.id===P.message.id))return G;const ae=G.messages.findIndex(W=>W.role==="user"&&W.id.startsWith("optim-")&&W.content===P.message.content);if(ae>=0){const W=[...G.messages];return W[ae]=P.message,{...G,messages:W}}return{...G,messages:[...G.messages,P.message]}})}catch{}}),U.addEventListener("chat.message.pending",A=>{try{const P=JSON.parse(A.data);d({id:P.assistantId,blocks:[],done:!1,finalMessage:null})}catch{}}),U.addEventListener("chat.message.chunk.text",A=>{try{const P=JSON.parse(A.data);d(G=>{if(!G||G.id!==P.assistantId)return G;const le=[...G.blocks],ae=le[le.length-1];return ae&&ae.type==="text"?le[le.length-1]={...ae,target:ae.target+P.text}:le.push({type:"text",target:P.text,displayed:""}),{...G,blocks:le}})}catch{}}),U.addEventListener("chat.message.chunk.tool_use",A=>{try{const P=JSON.parse(A.data);d(G=>!G||G.id!==P.assistantId?G:{...G,blocks:[...G.blocks,{type:"tool_use",id:P.id,title:P.title,kind:P.kind,status:P.status}]})}catch{}}),U.addEventListener("chat.message.chunk.tool_update",A=>{try{const P=JSON.parse(A.data);d(G=>!G||G.id!==P.assistantId?G:{...G,blocks:G.blocks.map(le=>le.type==="tool_use"&&le.id===P.id?{...le,status:P.status}:le)})}catch{}}),U.addEventListener("chat.message.complete",A=>{try{const P=JSON.parse(A.data);d(G=>G&&G.id===P.assistantId?{...G,done:!0,finalMessage:P.message}:G)}catch{}}),()=>U.close()},[e,n]),M.useEffect(()=>{if(!f)return;const U=f.blocks.reduce((A,P)=>P.type==="text"?A+(P.target.length-P.displayed.length):A,0);if(U<=0){if(f.done&&f.finalMessage){const A=f.finalMessage;n.setQueryData(["chat-session",e],P=>!P||P.messages.some(G=>G.id===A.id)?P:{...P,messages:[...P.messages,A],lastMessageAt:A.ts,messageCount:P.messageCount+1}),n.invalidateQueries({queryKey:["chat-sessions"]}),d(null),x(!1)}return}const Z=setTimeout(()=>{d(A=>{if(!A)return A;let P=Math.max(1,Math.ceil(U/40));const G=A.blocks.map(le=>{if(le.type!=="text"||P<=0)return le;const ae=le.target.length-le.displayed.length;if(ae<=0)return le;const W=Math.min(ae,P);return P-=W,{...le,displayed:le.target.slice(0,le.displayed.length+W)}});return{...A,blocks:G}})},25);return()=>clearTimeout(Z)},[f,n,e]),M.useEffect(()=>{const U=v.current;U&&(U.scrollTop=U.scrollHeight)},[c.data,f]);const S=M.useCallback(async()=>{const U=await nE();n.invalidateQueries({queryKey:["chat-sessions"]}),t(`/chat/${U.id}`)},[n,t]),w=M.useCallback(async()=>{const U=h.trim();if(!U||g)return;let Z=e;if(!Z){const P=await nE();n.invalidateQueries({queryKey:["chat-sessions"]}),Z=P.id,t(`/chat/${Z}`,{replace:!0})}const A={id:`optim-${Date.now()}`,role:"user",content:U,ts:new Date().toISOString(),status:"complete"};n.setQueryData(["chat-session",Z],P=>P?{...P,messages:[...P.messages,A],lastMessageAt:A.ts,messageCount:P.messageCount+1}:{id:Z,createdAt:A.ts,lastMessageAt:A.ts,title:U.slice(0,60),project:null,messageCount:1,messages:[A]}),y(""),x(!0);try{await dB(Z,U)}catch(P){x(!1),console.error("sendMessage failed",P),s({title:"发送失败",body:P instanceof Error?P.message:String(P)})}},[h,g,e,n,t,s]),_=M.useCallback(async U=>{await a({title:"删除对话",body:"对话记录会永久删除,不可恢复。",confirm:"删除",danger:!0})&&(await fB(U),n.invalidateQueries({queryKey:["chat-sessions"]}),e===U&&t("/chat"))},[n,e,t,a]),k=M.useCallback(async()=>{if(e)try{await hB(e)}catch(U){s({title:"中断失败",body:U instanceof Error?U.message:String(U)})}},[e,s]);return m.jsxs("div",{className:"grid grid-cols-[260px_1fr] gap-4 h-[calc(100vh-140px)]",children:[m.jsxs("aside",{className:"nb-card p-3 overflow-auto flex flex-col gap-2",children:[m.jsxs("button",{className:"nb-btn nb-btn-primary w-full justify-center",onClick:S,type:"button",children:[m.jsx(Xi,{size:14,strokeWidth:3}),"新建对话"]}),m.jsxs("div",{className:"mt-2 text-xs font-[family-name:var(--font-heading)] uppercase tracking-wider text-[var(--color-text-muted)] px-2",children:["历史 ",((R=o.data)==null?void 0:R.data.length)??0]}),m.jsxs("div",{className:"flex flex-col gap-1.5 mt-1",children:[(((C=o.data)==null?void 0:C.data)??[]).map(U=>m.jsxs("div",{className:["group flex items-start gap-2 p-2 rounded-lg border-2 border-transparent",e===U.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:[m.jsxs("button",{type:"button","aria-label":`打开对话 ${U.title}`,onClick:()=>t(`/chat/${U.id}`),className:"flex items-start gap-2 flex-1 min-w-0 text-left",children:[m.jsx($v,{size:14,strokeWidth:2.5,className:"mt-0.5 flex-shrink-0"}),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("p",{className:"text-sm font-semibold truncate",children:U.title}),m.jsxs("p",{className:"text-[10px] text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] truncate",children:[U.messageCount," msg · ",Dw(U.lastMessageAt??U.createdAt)]})]})]}),m.jsx("button",{type:"button","aria-label":"删除对话",className:"opacity-0 group-hover:opacity-100 p-1 hover:text-[var(--color-crashed)]",onClick:Z=>{Z.stopPropagation(),_(U.id)},children:m.jsx(Il,{size:12})})]},U.id)),(((D=o.data)==null?void 0:D.data)??[]).length===0&&m.jsx("p",{className:"text-xs text-[var(--color-text-subtle)] italic text-center py-4",children:"还没对话。点上面新建。"})]})]}),m.jsx("div",{className:"nb-card p-0 flex flex-col overflow-hidden",children:e?m.jsxs(m.Fragment,{children:[m.jsxs("header",{className:"px-4 py-3 border-b-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:(($=c.data)==null?void 0:$.title)??"新对话"}),m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:e})]}),m.jsxs("div",{ref:v,className:"flex-1 overflow-auto p-4 flex flex-col gap-4",children:[(((j=c.data)==null?void 0:j.messages)??[]).map(U=>m.jsx(pB,{msg:U},U.id)),f&&m.jsx(gB,{pending:f}),!c.isLoading&&(((q=c.data)==null?void 0:q.messages)??[]).length===0&&!f&&!g&&m.jsx("p",{className:"text-center text-[var(--color-text-subtle)] italic mt-12",children:"下方输入问题开始对话 · Enter 发送 · Shift+Enter 换行"})]}),m.jsx("div",{className:"border-t-2 border-[var(--color-text)] p-3 bg-[var(--color-bg-cream)]",children:m.jsxs("div",{className:"flex gap-2 items-end",children:[m.jsx("textarea",{className:"nb-input flex-1 resize-none",placeholder:"说点什么… (Enter 发送,Shift+Enter 换行)",rows:2,value:h,onChange:U=>y(U.target.value),onKeyDown:U=>{U.key==="Enter"&&!U.shiftKey&&!U.nativeEvent.isComposing&&(U.preventDefault(),w())},"aria-label":"消息输入"}),f?m.jsxs("button",{className:"nb-btn nb-btn-danger",onClick:k,type:"button","aria-label":"中断生成",children:[m.jsx(e1,{size:14,strokeWidth:3}),"中断"]}):m.jsxs("button",{className:"nb-btn nb-btn-primary",onClick:w,disabled:!h.trim()||g,type:"button","aria-label":"发送",children:[g?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):m.jsx(xA,{size:14,strokeWidth:3}),"发送"]})]})})]}):m.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:m.jsxs("div",{className:"text-center max-w-md",children:[m.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:m.jsx($v,{size:32,strokeWidth:2.5})}),m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold mb-2",children:"对话 💬"}),m.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:'点左上角"新建对话"开始一个 session。或直接在下方输入,会自动建 session。'}),m.jsx("p",{className:"text-xs text-[var(--color-text-subtle)] italic",children:"Enter 发送 · Shift+Enter 换行 · 内容流式返回"})]})})})]})}function pB({msg:e}){const t=e.role==="user",n=e.role==="error",a=e.blocks&&e.blocks.length>0?e.blocks:[{type:"text",text:e.content}];return m.jsx("div",{className:t?"self-end max-w-3xl":"self-start max-w-3xl",children:m.jsxs("div",{className:["nb-card",t?"bg-[var(--color-secondary)]":n?"bg-[var(--color-crashed-bg)]":"bg-[var(--color-bg)]"].join(" "),children:[m.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-2 flex items-center gap-2",children:[t?"你":n?"错误":"assistant",m.jsx("span",{className:"font-normal",children:"·"}),m.jsx("span",{className:"font-normal",children:Dw(e.ts)})]}),m.jsx("div",{className:"flex flex-col gap-2",children:a.map((s,o)=>m.jsx(bB,{block:s},o))}),e.truncated&&m.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:"⚠ 输出超过 10MB,已截断"})]})})}function gB({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 m.jsx("div",{className:"self-start max-w-3xl",children:m.jsxs("div",{className:"nb-card bg-[var(--color-bg)]",children:[m.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-2 flex items-center gap-2",children:["assistant",m.jsx("span",{className:"font-normal",children:"·"}),m.jsxs("span",{className:"flex items-center gap-1 font-normal text-[var(--color-running)]",children:[m.jsx(Zt,{size:10,strokeWidth:3,className:"animate-spin"}),"streaming"]})]}),m.jsxs("div",{className:"flex flex-col gap-2",children:[e.blocks.length===0&&m.jsx("p",{className:"text-sm text-[var(--color-text-muted)] italic",children:"…"}),e.blocks.map((n,a)=>{if(n.type==="text"){const s=a===t;return m.jsxs("div",{className:"relative",children:[m.jsx(Mw,{text:n.displayed}),s&&m.jsx("span",{className:"inline-block w-2 h-4 ml-1 bg-[var(--color-text)] animate-pulse align-middle"})]},a)}return m.jsx(jw,{tool:n},a)})]})]})})}function bB({block:e}){return e.type==="text"?m.jsx(Mw,{text:e.text}):m.jsx(jw,{tool:e})}function Mw({text:e}){return e?m.jsx("div",{className:"text-sm font-[family-name:var(--font-body)] break-words prose-chat",children:m.jsx(kg,{remarkPlugins:[Ag],rehypePlugins:[Mg],children:e})}):null}function jw({tool:e}){const[t,n]=M.useState(!1),a=e.status==="completed",s=e.status==="failed",o=!a&&!s;return m.jsxs("div",{className:"border-2 border-[var(--color-text)] rounded-lg overflow-hidden bg-[var(--color-bg-cream)]",children:[m.jsxs("button",{type:"button",onClick:()=>n(c=>!c),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:[m.jsx($p,{size:12,strokeWidth:3,className:["transition-transform",t?"rotate-90":""].join(" ")}),m.jsx(a1,{size:12,strokeWidth:2.5}),m.jsx("span",{className:"font-bold",children:e.kind}),m.jsx("span",{className:"flex-1 text-left text-[var(--color-text-muted)] truncate",children:e.title}),o&&m.jsx(Zt,{size:12,strokeWidth:3,className:"animate-spin text-[var(--color-running)]"}),a&&m.jsx(Pp,{size:12,strokeWidth:2.5,className:"text-[var(--color-running)]"}),s&&m.jsx(OC,{size:12,strokeWidth:2.5,className:"text-[var(--color-crashed)]"})]}),t&&m.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)]",children:[m.jsxs("div",{children:["id: ",m.jsx("span",{className:"text-[var(--color-text)]",children:e.id})]}),m.jsxs("div",{children:["status: ",m.jsx("span",{className:"text-[var(--color-text)]",children:e.status})]})]})]})}function Dw(e){if(!e)return"";const t=new Date(e),n=Date.now()-t.getTime();return n<6e4?"刚才":n<36e5?`${Math.floor(n/6e4)}m`:n<864e5?`${Math.floor(n/36e5)}h`:t.toLocaleDateString()}function yB(){return m.jsxs("div",{className:"nb-card max-w-2xl mt-12",children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold mb-2",children:"404 · 页面不存在"}),m.jsx("p",{className:"text-[var(--color-text-muted)] mb-6",children:"没找到这个页面。可能是链接过期了。"}),m.jsx(fs,{to:"/",className:"nb-btn nb-btn-mint inline-flex",children:"返回首页"})]})}function xB(){return m.jsx(c2,{children:m.jsx(jT,{children:m.jsxs(In,{element:m.jsx(l2,{}),children:[m.jsx(In,{index:!0,element:m.jsx(OT,{to:"/projects",replace:!0})}),m.jsx(In,{path:"/projects",element:m.jsx(u2,{})}),m.jsx(In,{path:"/projects/new",element:m.jsx(x2,{})}),m.jsx(In,{path:"/projects/:name",element:m.jsx(MO,{})}),m.jsx(In,{path:"/board",element:m.jsx(yR,{})}),m.jsx(In,{path:"/workers",element:m.jsx(_R,{})}),m.jsx(In,{path:"/logs",element:m.jsx(BR,{})}),m.jsx(In,{path:"/skills",element:m.jsx(tB,{})}),m.jsx(In,{path:"/system",element:m.jsx(iB,{})}),m.jsx(In,{path:"/chat",element:m.jsx(iE,{})}),m.jsx(In,{path:"/chat/:sessionId",element:m.jsx(iE,{})}),m.jsx(In,{path:"*",element:m.jsx(yB,{})})]})})})}o2();const vB=new vN({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!1}}}),Lw=document.getElementById("root");if(!Lw)throw new Error("#root not found");Vk.createRoot(Lw).render(m.jsx(M.StrictMode,{children:m.jsx(EN,{client:vB,children:m.jsx(aC,{children:m.jsx(g2,{children:m.jsx(xB,{})})})})}));
516
+ ${w}`})}};return m.jsxs("section",{className:"nb-card",children:[m.jsxs("div",{className:"flex items-center justify-between mb-3",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"版本"}),m.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px",fontSize:12},onClick:()=>f.refetch(),disabled:f.isFetching||!e,type:"button","aria-label":"检查最新版本",children:[f.isFetching?m.jsx(Zt,{size:12,strokeWidth:3,className:"animate-spin"}):m.jsx(Cl,{size:12,strokeWidth:2.5}),"检查更新"]})]}),m.jsxs("dl",{className:"grid grid-cols-[160px_1fr] gap-y-2 text-sm",children:[m.jsx("dt",{className:"font-bold",children:"sps-cli (当前)"}),m.jsx("dd",{className:"font-[family-name:var(--font-mono)]",children:e??"—"}),f.data&&m.jsxs(m.Fragment,{children:[m.jsx("dt",{className:"font-bold",children:"npm (最新)"}),m.jsxs("dd",{className:"font-[family-name:var(--font-mono)] flex items-center gap-2 flex-wrap",children:[f.data.latest,f.data.upToDate?m.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:"最新"}):m.jsxs(m.Fragment,{children:[m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"3px 10px",fontSize:11},onClick:x,disabled:a,type:"button","aria-label":"升级到最新版本",children:[a?m.jsx(Zt,{size:11,strokeWidth:3,className:"animate-spin"}):m.jsx(XE,{size:11,strokeWidth:2.5}),"升级"]}),m.jsxs("button",{className:"nb-btn",style:{padding:"3px 10px",fontSize:11},onClick:v,type:"button","aria-label":"复制升级命令",title:"自动升级失败时手动跑",children:[m.jsx(DC,{size:11,strokeWidth:2.5})," 复制命令"]})]})]})]}),d&&m.jsxs(m.Fragment,{children:[m.jsx("dt",{className:"font-bold",children:"已安装"}),m.jsxs("dd",{className:"font-[family-name:var(--font-mono)] flex items-center gap-2",children:[d,d===((S=f.data)==null?void 0:S.latest)?m.jsx("span",{className:"nb-status",style:{background:"var(--color-running-bg)",color:"var(--color-running)"},children:"已生效(重启 console 后可见)"}):d===e?m.jsx("span",{className:"nb-status",style:{background:"var(--color-stuck-bg)",color:"var(--color-stuck)"},children:"未升级成功"}):null]})]}),f.isError&&m.jsxs(m.Fragment,{children:[m.jsx("dt",{className:"font-bold",children:"检查"}),m.jsx("dd",{className:"text-[var(--color-crashed)] text-xs",children:f.error instanceof Error?f.error.message:String(f.error)})]})]}),o&&m.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:o})]})}function rB({onClose:e}){const t=Pn(),{alert:n}=si(),a=dt({queryKey:["system-env-raw"],queryFn:PA}),[s,o]=M.useState(null),[c,f]=M.useState(null);M.useEffect(()=>{a.data&&s===null&&(o(a.data.content),f(a.data.etag))},[a.data,s]);const d=s!==null&&a.data&&s!==a.data.content,h=$n({mutationFn:()=>{if(s===null)throw new Error("no draft");return qA(s,c??"")},onSuccess:()=>{t.invalidateQueries({queryKey:["system-env"]}),t.invalidateQueries({queryKey:["system-env-raw"]}),e()},onError:y=>{const g=y.status;n({title:g===409?"env 被其他地方修改了":"保存失败",body:g===409?"请点取消后重开编辑。":y instanceof Error?y.message:String(y)})}});return a.isLoading?m.jsx("p",{className:"text-[var(--color-text-muted)]",children:"加载中…"}):m.jsxs("div",{children:[m.jsx("p",{className:"text-xs text-[var(--color-stuck)] font-bold mb-2",children:"⚠ 文件包含凭证明文。保存时保持 0600 权限。"}),m.jsx("textarea",{className:"nb-input w-full font-[family-name:var(--font-mono)] text-xs",style:{minHeight:320,resize:"vertical"},value:s??"",onChange:y=>o(y.target.value),spellCheck:!1,"aria-label":"env 文件编辑器"}),m.jsxs("div",{className:"flex items-center justify-between mt-3",children:[m.jsxs("span",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:[c?`etag: ${c}`:"",d?" · ● 未保存":""]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsxs("button",{className:"nb-btn",style:{padding:"6px 12px"},onClick:e,disabled:h.isPending,type:"button",children:[m.jsx(vr,{size:12,strokeWidth:3})," 取消"]}),m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"6px 12px"},onClick:()=>h.mutate(),disabled:!d||h.isPending,type:"button","aria-label":"保存 env",children:[h.isPending?m.jsx(Zt,{size:12,strokeWidth:3,className:"animate-spin"}):m.jsx(Df,{size:12,strokeWidth:3}),"保存"]})]})]})]})}function sB(){var g;const{alert:e}=si(),t=dt({queryKey:["projects"],queryFn:ds}),[n,a]=M.useState({}),[s,o]=M.useState({}),[c,f]=M.useState({}),d=(((g=t.data)==null?void 0:g.data)??[]).map(x=>({project:x.name})),h=async(x,v)=>{o(S=>({...S,[x]:v?"fix":"check"}));try{const S=await GA(x,v);a(w=>({...w,[x]:S})),f(w=>({...w,[x]:!0}))}catch(S){e({title:`doctor ${v?"修复":"检查"}失败`,body:S instanceof Error?S.message:String(S)})}finally{o(S=>({...S,[x]:null}))}},y=async()=>{for(const x of d)await h(x.project,!1)};return m.jsxs("section",{className:"nb-card",children:[m.jsxs("div",{className:"flex items-center justify-between mb-3",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] text-xl font-bold",children:"项目健康检查"}),m.jsxs("button",{className:"nb-btn nb-btn-mint",style:{padding:"6px 12px",fontSize:12},onClick:()=>{y()},disabled:d.length===0||Object.values(s).some(Boolean),type:"button",children:[m.jsx(Cl,{size:12,strokeWidth:2.5}),"检查全部"]})]}),d.length===0?m.jsx("p",{className:"text-[var(--color-text-muted)] text-sm",children:"还没有项目。"}):m.jsx("ul",{className:"flex flex-col gap-2",children:d.map(x=>{const v=n[x.project],S=s[x.project],w=v?v.checks.filter(C=>C.status==="fail").length:0,_=v?v.checks.filter(C=>C.status==="warn").length:0,k=c[x.project]??!1,R=v!=null;return m.jsxs("li",{className:"bg-[var(--color-bg-cream)] border-2 border-[var(--color-text)] rounded-lg",children:[m.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[m.jsxs("button",{type:"button",onClick:()=>f(C=>({...C,[x.project]:!k})),disabled:!R,className:"flex items-center gap-2 flex-1 text-left min-w-0","aria-label":k?"折叠":"展开",children:[R&&v.ok?m.jsx(ap,{size:16,className:"text-[var(--color-running)] shrink-0",strokeWidth:2.5}):R?m.jsx(rc,{size:16,className:"text-[var(--color-stuck)] shrink-0",strokeWidth:2.5}):m.jsx(ap,{size:16,className:"text-[var(--color-text-subtle)] shrink-0",strokeWidth:2.5}),R&&(k?m.jsx(yc,{size:12}):m.jsx($p,{size:12})),m.jsx("span",{className:"font-bold font-[family-name:var(--font-mono)]",children:x.project}),R?v.ok?m.jsx("span",{className:"text-xs text-[var(--color-running)] font-semibold",children:"OK"}):m.jsxs("span",{className:"text-xs text-[var(--color-stuck)] font-semibold",children:[w," fail · ",_," warn"]}):m.jsx("span",{className:"text-xs text-[var(--color-text-muted)]",children:'点 "检查" 运行 sps doctor'})]}),m.jsxs("button",{className:"nb-btn",style:{padding:"4px 10px",fontSize:11},onClick:()=>{h(x.project,!1)},disabled:!!S,type:"button","aria-label":"检查",children:[S==="check"?m.jsx(Zt,{size:11,strokeWidth:3,className:"animate-spin"}):m.jsx(Cl,{size:11,strokeWidth:2.5}),"检查"]}),R&&!v.ok&&m.jsxs("button",{className:"nb-btn nb-btn-primary",style:{padding:"4px 10px",fontSize:11},onClick:()=>{h(x.project,!0)},disabled:!!S,type:"button","aria-label":"自动修复",children:[S==="fix"?m.jsx(Zt,{size:11,strokeWidth:3,className:"animate-spin"}):m.jsx(a1,{size:11,strokeWidth:2.5}),"修复"]})]}),k&&R&&m.jsxs("div",{className:"border-t-2 border-dashed border-[var(--color-text)] px-3 py-2",children:[m.jsx("ul",{className:"flex flex-col gap-1 text-xs font-[family-name:var(--font-mono)]",children:v.checks.map((C,D)=>m.jsx(lB,{check:C},`${C.name}-${D}`))}),v.fixes.length>0&&m.jsxs("div",{className:"mt-3 bg-[var(--color-running-bg)] border-2 border-[var(--color-running)] rounded p-2",children:[m.jsx("div",{className:"text-xs font-bold text-[var(--color-running)] mb-1",children:"已修复"}),m.jsx("ul",{className:"text-xs list-disc pl-4",children:v.fixes.map((C,D)=>m.jsx("li",{children:C},D))})]})]})]},x.project)})})]})}function lB({check:e}){const t=e.status==="pass"?m.jsx(ap,{size:12,className:"text-[var(--color-running)]",strokeWidth:2.5}):e.status==="fail"?m.jsx(rc,{size:12,className:"text-[var(--color-crashed)]",strokeWidth:2.5}):e.status==="warn"?m.jsx(rc,{size:12,className:"text-[var(--color-stuck)]",strokeWidth:2.5}):m.jsx("span",{className:"w-3 h-3 rounded-full bg-[var(--color-text-subtle)] inline-block"});return m.jsxs("li",{className:"flex items-start gap-2",children:[m.jsx("span",{className:"pt-0.5 shrink-0",children:t}),m.jsx("span",{className:"font-bold w-32 shrink-0",children:e.name}),m.jsx("span",{className:"text-[var(--color-text-muted)] break-words",children:e.message})]})}function oB(e){const t=Math.floor(e/1e3),n=Math.floor(t/3600),a=Math.floor(t%3600/60),s=t%60;return n>0?`${n}h ${a}m ${s}s`:a>0?`${a}m ${s}s`:`${s}s`}function cB(){return qt("/api/chat/sessions")}function uB(e){return qt(`/api/chat/sessions/${e}`)}async function nE(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 fB(e){const t=await fetch(`/api/chat/sessions/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(`${t.status}`)}async function dB(e,t){const n=await fetch(`/api/chat/sessions/${e}/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!n.ok)throw new Error(`${n.status}: ${await n.text()}`);return await n.json()}async function hB(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 mB(e,t){const n=t?`?since=${encodeURIComponent(t)}`:"";return qt(`/api/chat/sessions/${e}/messages${n}`)}function iE(){var R,C,D,$,j,q;const{sessionId:e}=UE(),t=Sr(),n=Pn(),{confirm:a,alert:s}=si(),o=dt({queryKey:["chat-sessions"],queryFn:cB}),c=dt({queryKey:["chat-session",e],queryFn:()=>uB(e??""),enabled:!!e}),[f,d]=M.useState(null),[h,y]=M.useState(""),[g,x]=M.useState(!1),v=M.useRef(null);M.useEffect(()=>{if(!e)return;const U=new EventSource(`/stream/chat/${encodeURIComponent(e)}`);let Z=!0;return U.addEventListener("open",()=>{if(Z){Z=!1;return}const A=n.getQueryData(["chat-session",e]),P=A!=null&&A.messages.length?A.messages[A.messages.length-1].ts:void 0;mB(e,P).then(G=>{G.data.length!==0&&n.setQueryData(["chat-session",e],le=>{if(!le)return le;const ae=new Set(le.messages.map(K=>K.id)),W=G.data.filter(K=>!ae.has(K.id));return W.length===0?le:{...le,messages:[...le.messages,...W],lastMessageAt:W[W.length-1].ts,messageCount:le.messageCount+W.length}})}).catch(()=>{})}),U.addEventListener("chat.message",A=>{try{const P=JSON.parse(A.data);n.setQueryData(["chat-session",e],G=>{if(!G||G.messages.some(W=>W.id===P.message.id))return G;const ae=G.messages.findIndex(W=>W.role==="user"&&W.id.startsWith("optim-")&&W.content===P.message.content);if(ae>=0){const W=[...G.messages];return W[ae]=P.message,{...G,messages:W}}return{...G,messages:[...G.messages,P.message]}})}catch{}}),U.addEventListener("chat.message.pending",A=>{try{const P=JSON.parse(A.data);d({id:P.assistantId,blocks:[],done:!1,finalMessage:null})}catch{}}),U.addEventListener("chat.message.chunk.text",A=>{try{const P=JSON.parse(A.data);d(G=>{if(!G||G.id!==P.assistantId)return G;const le=[...G.blocks],ae=le[le.length-1];return ae&&ae.type==="text"?le[le.length-1]={...ae,target:ae.target+P.text}:le.push({type:"text",target:P.text,displayed:""}),{...G,blocks:le}})}catch{}}),U.addEventListener("chat.message.chunk.tool_use",A=>{try{const P=JSON.parse(A.data);d(G=>!G||G.id!==P.assistantId?G:{...G,blocks:[...G.blocks,{type:"tool_use",id:P.id,title:P.title,kind:P.kind,status:P.status}]})}catch{}}),U.addEventListener("chat.message.chunk.tool_update",A=>{try{const P=JSON.parse(A.data);d(G=>!G||G.id!==P.assistantId?G:{...G,blocks:G.blocks.map(le=>le.type==="tool_use"&&le.id===P.id?{...le,status:P.status}:le)})}catch{}}),U.addEventListener("chat.message.complete",A=>{try{const P=JSON.parse(A.data);d(G=>G&&G.id===P.assistantId?{...G,done:!0,finalMessage:P.message}:G)}catch{}}),()=>U.close()},[e,n]),M.useEffect(()=>{if(!f)return;const U=f.blocks.reduce((A,P)=>P.type==="text"?A+(P.target.length-P.displayed.length):A,0);if(U<=0){if(f.done&&f.finalMessage){const A=f.finalMessage;n.setQueryData(["chat-session",e],P=>!P||P.messages.some(G=>G.id===A.id)?P:{...P,messages:[...P.messages,A],lastMessageAt:A.ts,messageCount:P.messageCount+1}),n.invalidateQueries({queryKey:["chat-sessions"]}),d(null),x(!1)}return}const Z=setTimeout(()=>{d(A=>{if(!A)return A;let P=Math.max(1,Math.ceil(U/40));const G=A.blocks.map(le=>{if(le.type!=="text"||P<=0)return le;const ae=le.target.length-le.displayed.length;if(ae<=0)return le;const W=Math.min(ae,P);return P-=W,{...le,displayed:le.target.slice(0,le.displayed.length+W)}});return{...A,blocks:G}})},25);return()=>clearTimeout(Z)},[f,n,e]),M.useEffect(()=>{const U=v.current;U&&(U.scrollTop=U.scrollHeight)},[c.data,f]);const S=M.useCallback(async()=>{const U=await nE();n.invalidateQueries({queryKey:["chat-sessions"]}),t(`/chat/${U.id}`)},[n,t]),w=M.useCallback(async()=>{const U=h.trim();if(!U||g)return;let Z=e;if(!Z){const P=await nE();n.invalidateQueries({queryKey:["chat-sessions"]}),Z=P.id,t(`/chat/${Z}`,{replace:!0})}const A={id:`optim-${Date.now()}`,role:"user",content:U,ts:new Date().toISOString(),status:"complete"};n.setQueryData(["chat-session",Z],P=>P?{...P,messages:[...P.messages,A],lastMessageAt:A.ts,messageCount:P.messageCount+1}:{id:Z,createdAt:A.ts,lastMessageAt:A.ts,title:U.slice(0,60),project:null,messageCount:1,messages:[A]}),y(""),x(!0);try{await dB(Z,U)}catch(P){x(!1),console.error("sendMessage failed",P),s({title:"发送失败",body:P instanceof Error?P.message:String(P)})}},[h,g,e,n,t,s]),_=M.useCallback(async U=>{await a({title:"删除对话",body:"对话记录会永久删除,不可恢复。",confirm:"删除",danger:!0})&&(await fB(U),n.invalidateQueries({queryKey:["chat-sessions"]}),e===U&&t("/chat"))},[n,e,t,a]),k=M.useCallback(async()=>{if(e)try{await hB(e)}catch(U){s({title:"中断失败",body:U instanceof Error?U.message:String(U)})}},[e,s]);return m.jsxs("div",{className:"grid grid-cols-[260px_1fr] gap-4 h-[calc(100vh-140px)]",children:[m.jsxs("aside",{className:"nb-card p-3 overflow-auto flex flex-col gap-2",children:[m.jsxs("button",{className:"nb-btn nb-btn-primary w-full justify-center",onClick:S,type:"button",children:[m.jsx(Xi,{size:14,strokeWidth:3}),"新建对话"]}),m.jsxs("div",{className:"mt-2 text-xs font-[family-name:var(--font-heading)] uppercase tracking-wider text-[var(--color-text-muted)] px-2",children:["历史 ",((R=o.data)==null?void 0:R.data.length)??0]}),m.jsxs("div",{className:"flex flex-col gap-1.5 mt-1",children:[(((C=o.data)==null?void 0:C.data)??[]).map(U=>m.jsxs("div",{className:["group flex items-start gap-2 p-2 rounded-lg border-2 border-transparent",e===U.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:[m.jsxs("button",{type:"button","aria-label":`打开对话 ${U.title}`,onClick:()=>t(`/chat/${U.id}`),className:"flex items-start gap-2 flex-1 min-w-0 text-left",children:[m.jsx($v,{size:14,strokeWidth:2.5,className:"mt-0.5 flex-shrink-0"}),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("p",{className:"text-sm font-semibold truncate",children:U.title}),m.jsxs("p",{className:"text-[10px] text-[var(--color-text-muted)] font-[family-name:var(--font-mono)] truncate",children:[U.messageCount," msg · ",Dw(U.lastMessageAt??U.createdAt)]})]})]}),m.jsx("button",{type:"button","aria-label":"删除对话",className:"opacity-0 group-hover:opacity-100 p-1 hover:text-[var(--color-crashed)]",onClick:Z=>{Z.stopPropagation(),_(U.id)},children:m.jsx(Il,{size:12})})]},U.id)),(((D=o.data)==null?void 0:D.data)??[]).length===0&&m.jsx("p",{className:"text-xs text-[var(--color-text-subtle)] italic text-center py-4",children:"还没对话。点上面新建。"})]})]}),m.jsx("div",{className:"nb-card p-0 flex flex-col overflow-hidden",children:e?m.jsxs(m.Fragment,{children:[m.jsxs("header",{className:"px-4 py-3 border-b-2 border-[var(--color-text)] bg-[var(--color-bg-cream)]",children:[m.jsx("h2",{className:"font-[family-name:var(--font-heading)] font-bold text-lg",children:(($=c.data)==null?void 0:$.title)??"新对话"}),m.jsx("p",{className:"text-xs text-[var(--color-text-muted)] font-[family-name:var(--font-mono)]",children:e})]}),m.jsxs("div",{ref:v,className:"flex-1 overflow-auto p-4 flex flex-col gap-4",children:[(((j=c.data)==null?void 0:j.messages)??[]).map(U=>m.jsx(pB,{msg:U},U.id)),f&&m.jsx(gB,{pending:f}),!c.isLoading&&(((q=c.data)==null?void 0:q.messages)??[]).length===0&&!f&&!g&&m.jsx("p",{className:"text-center text-[var(--color-text-subtle)] italic mt-12",children:"下方输入问题开始对话 · Enter 发送 · Shift+Enter 换行"})]}),m.jsx("div",{className:"border-t-2 border-[var(--color-text)] p-3 bg-[var(--color-bg-cream)]",children:m.jsxs("div",{className:"flex gap-2 items-end",children:[m.jsx("textarea",{className:"nb-input flex-1 resize-none",placeholder:"说点什么… (Enter 发送,Shift+Enter 换行)",rows:2,value:h,onChange:U=>y(U.target.value),onKeyDown:U=>{U.key==="Enter"&&!U.shiftKey&&!U.nativeEvent.isComposing&&(U.preventDefault(),w())},"aria-label":"消息输入"}),f?m.jsxs("button",{className:"nb-btn nb-btn-danger",onClick:k,type:"button","aria-label":"中断生成",children:[m.jsx(e1,{size:14,strokeWidth:3}),"中断"]}):m.jsxs("button",{className:"nb-btn nb-btn-primary",onClick:w,disabled:!h.trim()||g,type:"button","aria-label":"发送",children:[g?m.jsx(Zt,{size:14,strokeWidth:3,className:"animate-spin"}):m.jsx(xA,{size:14,strokeWidth:3}),"发送"]})]})})]}):m.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:m.jsxs("div",{className:"text-center max-w-md",children:[m.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:m.jsx($v,{size:32,strokeWidth:2.5})}),m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-2xl font-bold mb-2",children:"对话 💬"}),m.jsx("p",{className:"text-sm text-[var(--color-text-muted)] mb-4",children:'点左上角"新建对话"开始一个 session。或直接在下方输入,会自动建 session。'}),m.jsx("p",{className:"text-xs text-[var(--color-text-subtle)] italic",children:"Enter 发送 · Shift+Enter 换行 · 内容流式返回"})]})})})]})}function pB({msg:e}){const t=e.role==="user",n=e.role==="error",a=e.blocks&&e.blocks.length>0?e.blocks:[{type:"text",text:e.content}];return m.jsx("div",{className:t?"self-end max-w-3xl":"self-start max-w-3xl",children:m.jsxs("div",{className:["nb-card",t?"bg-[var(--color-secondary)]":n?"bg-[var(--color-crashed-bg)]":"bg-[var(--color-bg)]"].join(" "),children:[m.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-2 flex items-center gap-2",children:[t?"你":n?"错误":"assistant",m.jsx("span",{className:"font-normal",children:"·"}),m.jsx("span",{className:"font-normal",children:Dw(e.ts)})]}),m.jsx("div",{className:"flex flex-col gap-2",children:a.map((s,o)=>m.jsx(bB,{block:s},o))}),e.truncated&&m.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:"⚠ 输出超过 10MB,已截断"})]})})}function gB({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 m.jsx("div",{className:"self-start max-w-3xl",children:m.jsxs("div",{className:"nb-card bg-[var(--color-bg)]",children:[m.jsxs("p",{className:"text-xs font-bold uppercase tracking-wider text-[var(--color-text-muted)] mb-2 flex items-center gap-2",children:["assistant",m.jsx("span",{className:"font-normal",children:"·"}),m.jsxs("span",{className:"flex items-center gap-1 font-normal text-[var(--color-running)]",children:[m.jsx(Zt,{size:10,strokeWidth:3,className:"animate-spin"}),"streaming"]})]}),m.jsxs("div",{className:"flex flex-col gap-2",children:[e.blocks.length===0&&m.jsx("p",{className:"text-sm text-[var(--color-text-muted)] italic",children:"…"}),e.blocks.map((n,a)=>{if(n.type==="text"){const s=a===t;return m.jsxs("div",{className:"relative",children:[m.jsx(Mw,{text:n.displayed}),s&&m.jsx("span",{className:"inline-block w-2 h-4 ml-1 bg-[var(--color-text)] animate-pulse align-middle"})]},a)}return m.jsx(jw,{tool:n},a)})]})]})})}function bB({block:e}){return e.type==="text"?m.jsx(Mw,{text:e.text}):m.jsx(jw,{tool:e})}function Mw({text:e}){return e?m.jsx("div",{className:"text-sm font-[family-name:var(--font-body)] break-words prose-chat",children:m.jsx(kg,{remarkPlugins:[Ag],rehypePlugins:[Mg],children:e})}):null}function jw({tool:e}){const[t,n]=M.useState(!1),a=e.status==="completed",s=e.status==="failed",o=!a&&!s;return m.jsxs("div",{className:"border-2 border-[var(--color-text)] rounded-lg overflow-hidden bg-[var(--color-bg-cream)]",children:[m.jsxs("button",{type:"button",onClick:()=>n(c=>!c),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:[m.jsx($p,{size:12,strokeWidth:3,className:["transition-transform",t?"rotate-90":""].join(" ")}),m.jsx(a1,{size:12,strokeWidth:2.5}),m.jsx("span",{className:"font-bold",children:e.kind}),m.jsx("span",{className:"flex-1 text-left text-[var(--color-text-muted)] truncate",children:e.title}),o&&m.jsx(Zt,{size:12,strokeWidth:3,className:"animate-spin text-[var(--color-running)]"}),a&&m.jsx(Pp,{size:12,strokeWidth:2.5,className:"text-[var(--color-running)]"}),s&&m.jsx(OC,{size:12,strokeWidth:2.5,className:"text-[var(--color-crashed)]"})]}),t&&m.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)]",children:[m.jsxs("div",{children:["id: ",m.jsx("span",{className:"text-[var(--color-text)]",children:e.id})]}),m.jsxs("div",{children:["status: ",m.jsx("span",{className:"text-[var(--color-text)]",children:e.status})]})]})]})}function Dw(e){if(!e)return"";const t=new Date(e),n=Date.now()-t.getTime();return n<6e4?"刚才":n<36e5?`${Math.floor(n/6e4)}m`:n<864e5?`${Math.floor(n/36e5)}h`:t.toLocaleDateString()}function yB(){return m.jsxs("div",{className:"nb-card max-w-2xl mt-12",children:[m.jsx("h1",{className:"font-[family-name:var(--font-heading)] text-4xl font-bold mb-2",children:"404 · 页面不存在"}),m.jsx("p",{className:"text-[var(--color-text-muted)] mb-6",children:"没找到这个页面。可能是链接过期了。"}),m.jsx(fs,{to:"/",className:"nb-btn nb-btn-mint inline-flex",children:"返回首页"})]})}function xB(){return m.jsx(c2,{children:m.jsx(jT,{children:m.jsxs(In,{element:m.jsx(l2,{}),children:[m.jsx(In,{index:!0,element:m.jsx(OT,{to:"/projects",replace:!0})}),m.jsx(In,{path:"/projects",element:m.jsx(u2,{})}),m.jsx(In,{path:"/projects/new",element:m.jsx(x2,{})}),m.jsx(In,{path:"/projects/:name",element:m.jsx(MO,{})}),m.jsx(In,{path:"/board",element:m.jsx(yR,{})}),m.jsx(In,{path:"/workers",element:m.jsx(jR,{})}),m.jsx(In,{path:"/logs",element:m.jsx(BR,{})}),m.jsx(In,{path:"/skills",element:m.jsx(tB,{})}),m.jsx(In,{path:"/system",element:m.jsx(iB,{})}),m.jsx(In,{path:"/chat",element:m.jsx(iE,{})}),m.jsx(In,{path:"/chat/:sessionId",element:m.jsx(iE,{})}),m.jsx(In,{path:"*",element:m.jsx(yB,{})})]})})})}o2();const vB=new vN({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!1}}}),Lw=document.getElementById("root");if(!Lw)throw new Error("#root not found");Vk.createRoot(Lw).render(m.jsx(M.StrictMode,{children:m.jsx(EN,{client:vB,children:m.jsx(aC,{children:m.jsx(g2,{children:m.jsx(xB,{})})})})}));