@tencent-ai/codebuddy-code 2.83.0 → 2.83.1-next.a0f9c9d.20260411

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.
@@ -608,8 +608,8 @@ ${t("terminal.processExited")}\r
608
608
  text-text-primary focus:outline-none focus:border-accent-brand min-w-[180px]`,children:[n.jsx("option",{value:"",children:e("logs.selectWorker")}),i.map(y=>n.jsxs("option",{value:y.pid,children:["PID ",y.pid," — ",y.name||y.kind,y.isCurrent?` (${e("logs.current")})`:""]},y.pid))]}),a.length>0&&n.jsx("div",{className:"flex items-center gap-0.5 bg-bg-tertiary rounded-lg p-0.5",children:a.map(y=>{var S;return n.jsx("button",{onClick:()=>u(y),className:`px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors ${y===d?"bg-bg-primary text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:((S=jv[y])==null?void 0:S[t])||y},y)})}),n.jsx("div",{className:"flex-1"}),n.jsxs("div",{className:"relative",children:[n.jsx(tt,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-text-tertiary"}),n.jsx("input",{type:"text",value:b,onChange:y=>_(y.target.value),placeholder:e("logs.search"),className:`pl-7 pr-7 py-1.5 text-xs rounded-lg border border-border-primary bg-bg-secondary
609
609
  text-text-primary placeholder:text-text-tertiary focus:outline-none focus:border-accent-brand w-[180px]`}),b&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"absolute right-8 top-1/2 -translate-y-1/2 text-[10px] text-text-tertiary",children:x}),n.jsx("button",{onClick:()=>_(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-text-tertiary hover:text-text-primary",children:n.jsx(Ie,{size:12})})]})]}),n.jsxs("button",{onClick:()=>v(!w),className:`flex items-center gap-1 px-2.5 py-1.5 text-xs rounded-lg border transition-colors ${w?"border-accent-brand/40 bg-accent-brand/10 text-accent-brand":"border-border-primary text-text-secondary hover:text-text-primary"}`,title:e("logs.autoRefresh"),children:[n.jsx(dt,{size:12,className:w?"animate-spin":""}),e("logs.autoRefresh")]}),n.jsx("button",{onClick:m,className:"p-1.5 rounded-lg text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors",title:e("logs.refresh"),children:n.jsx(dt,{size:14})})]}),E&&n.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[11px] text-text-tertiary",children:[o&&n.jsx(_t,{path:o,className:"font-mono truncate max-w-[400px]"}),E.url&&n.jsx("a",{href:E.url,target:"_blank",rel:"noopener noreferrer",className:"text-accent-brand hover:underline",children:E.url})]})]}),n.jsx("div",{className:"flex-1 overflow-auto bg-bg-primary",children:p?!l&&a.length===0?n.jsx("div",{className:"flex items-center justify-center h-full text-text-tertiary text-sm",children:e("logs.empty")}):b?n.jsx("div",{ref:h,className:"p-4 font-mono text-xs leading-5 min-h-full",children:f?f.split(`
610
610
  `).map((y,S)=>n.jsx(zv,{line:y,searchText:b},S)):n.jsx("span",{className:"text-text-tertiary",children:e("logs.empty")})}):n.jsx("div",{ref:h,className:"min-h-full",children:n.jsx(Dv,{language:"log",style:r==="dark"?fn:bn,showLineNumbers:!0,wrapLongLines:!0,customStyle:{margin:0,padding:"16px",border:"none",background:"transparent",fontSize:"12px",lineHeight:"1.5"},codeTagProps:{style:{background:"transparent",textShadow:"none"}},lineNumberStyle:{minWidth:"3em",paddingRight:"1em",color:"var(--color-text-tertiary)",userSelect:"none"},children:l||e("logs.empty")})}):n.jsx("div",{className:"flex items-center justify-center h-full text-text-tertiary text-sm",children:e("logs.selectWorker")})})]})}const Fv={ERROR:"text-red-500 dark:text-red-400",WARN:"text-amber-600 dark:text-amber-400",INFO:"text-blue-500 dark:text-blue-400",DEBUG:"text-text-tertiary"},Bv={ERROR:"bg-red-50/50 dark:bg-red-900/10",WARN:"bg-amber-50/50 dark:bg-amber-900/10"},Uv=/^\[(\w+)\]\s/;function zv({line:e,searchText:t}){var o;if(!e.trim())return n.jsx("div",{className:"h-5"});const r=e.match(Uv),i=((o=r==null?void 0:r[1])==null?void 0:o.toUpperCase())||"",s=Fv[i]||"text-text-secondary",l=Bv[i]||"",a=t&&e.toLowerCase().includes(t.toLowerCase())?"bg-yellow-100/60 dark:bg-yellow-900/20":"";return n.jsx("div",{className:`whitespace-pre-wrap break-all px-2 py-px rounded-sm ${l} ${a}`,children:r?n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:`font-semibold ${s}`,children:["[",r[1],"]"]}),n.jsx("span",{className:"text-text-secondary",children:iu(e.slice(r[0].length),t)})]}):n.jsx("span",{className:"text-text-secondary",children:iu(e,t)})})}function iu(e,t){if(!t)return e;const r=e.toLowerCase(),i=t.toLowerCase(),s=[];let l=0,d=r.indexOf(i);for(;d!==-1;)d>l&&s.push(e.slice(l,d)),s.push(n.jsx("mark",{className:"bg-yellow-300 dark:bg-yellow-700 text-text-primary rounded-sm px-px",children:e.slice(d,d+t.length)},d)),l=d+t.length,d=r.indexOf(i,l);return l<e.length&&s.push(e.slice(l)),s.length>0?n.jsx(n.Fragment,{children:s}):e}const Hv=8e3,Gv=$e((e,t)=>({metrics:null,loading:!1,error:null,_pollTimer:null,fetchMetrics:async()=>{e({loading:!t().metrics,error:null});try{const r=await ye("/api/v1/metrics",{headers:ue()});if(!r.ok)throw new Error(`Failed to fetch metrics: ${r.status}`);const i=await r.json();e({metrics:i.data,loading:!1})}catch(r){e({error:r.message,loading:!1})}},startPolling:(r=Hv)=>{const{stopPolling:i,fetchMetrics:s}=t();i(),s();const l=setInterval(s,r);e({_pollTimer:l})},stopPolling:()=>{const{_pollTimer:r}=t();r&&(clearInterval(r),e({_pollTimer:null}))}})),Wv={interactive:"bg-blue-50 text-blue-700 border border-blue-200 dark:bg-blue-500/10 dark:text-blue-400 dark:border-blue-500/20",bg:"bg-purple-50 text-purple-700 border border-purple-200 dark:bg-purple-500/10 dark:text-purple-400 dark:border-purple-500/20",daemon:"bg-green-50 text-green-700 border border-green-200 dark:bg-green-500/10 dark:text-green-400 dark:border-green-500/20","daemon-worker":"bg-orange-50 text-orange-700 border border-orange-200 dark:bg-orange-500/10 dark:text-orange-400 dark:border-orange-500/20"};function qv(){const{t:e}=ne(),{metrics:t,loading:r,error:i,fetchMetrics:s,startPolling:l,stopPolling:d}=Gv(),{workers:a,fetchWorkers:o}=Lc();if(C.useEffect(()=>(l(8e3),o(),()=>d()),[l,d,o]),r&&!t)return n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx(nt,{size:"large",text:e("metrics.loading")})});if(i&&!t)return n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsxs("div",{className:"text-center",children:[n.jsx("div",{className:"text-text-secondary mb-4",children:i}),n.jsx("button",{onClick:s,className:"px-4 py-2 bg-accent-brand text-white rounded-lg text-sm",children:e("metrics.refresh")})]})});const c=Vv((t==null?void 0:t.instances)||[],a);return n.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(gi,{size:20,className:"text-accent-brand"}),n.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:e("metrics.title")})]}),n.jsxs("button",{onClick:()=>{s(),o()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-text-secondary
611
- hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:e("metrics.refresh"),children:[n.jsx(dt,{size:14}),n.jsx("span",{children:e("metrics.refresh")})]})]}),t&&n.jsxs(n.Fragment,{children:[n.jsx(Kv,{metrics:t}),n.jsx(Yv,{workers:c})]})]})}function Vv(e,t){return e.map(r=>{const i=t.find(s=>s.pid===r.pid);return{...r,kind:i==null?void 0:i.kind,name:i==null?void 0:i.name,url:(i==null?void 0:i.url)||(i==null?void 0:i.endpoint),status:i==null?void 0:i.status}})}function Kv({metrics:e}){const{t}=ne(),r=e.memTotalMib>0?e.memUsedMib/e.memTotalMib*100:0,i=e.diskTotal>0?e.diskUsed/e.diskTotal*100:0;return n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[n.jsx(Fn,{icon:n.jsx(Rt,{size:18}),label:t("metrics.cpu"),value:`${e.cpuUsedPct.toFixed(1)}%`,subtext:`${e.cpuCount} ${t("metrics.cores")}`,percent:e.cpuUsedPct,colorClasses:zr(e.cpuUsedPct)}),n.jsx(Fn,{icon:n.jsx(qn,{size:18}),label:t("metrics.memory"),value:`${su(e.memUsedMib)} / ${su(e.memTotalMib)}`,subtext:`${r.toFixed(1)}%`,percent:r,colorClasses:zr(r)}),n.jsx(Fn,{icon:n.jsx(Fm,{size:18}),label:t("metrics.disk"),value:`${au(e.diskUsed)} / ${au(e.diskTotal)}`,subtext:`${i.toFixed(1)}%`,percent:i,colorClasses:zr(i)})]})}function Fn({icon:e,label:t,value:r,subtext:i,percent:s,colorClasses:l}){const[d,a]=l;return n.jsxs("div",{className:"bg-bg-secondary rounded-xl p-4 border border-border-primary",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx("span",{className:d,children:e}),n.jsx("span",{className:"text-sm font-medium text-text-secondary",children:t})]}),n.jsx("div",{className:"text-xl font-semibold text-text-primary mb-1",children:r}),n.jsx("div",{className:"text-xs text-text-tertiary mb-3",children:i}),n.jsx("div",{className:"h-2 bg-bg-tertiary rounded-full overflow-hidden",children:n.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${a}`,style:{width:`${Math.min(s,100)}%`}})})]})}function Yv({workers:e}){const{t}=ne();return e.length===0?n.jsx("div",{className:"text-center py-12 text-text-tertiary",children:t("metrics.noWorkers")}):n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[n.jsx(Rt,{size:18,className:"text-text-secondary"}),n.jsxs("h2",{className:"text-base font-medium text-text-primary",children:["Workers (",e.length,")"]})]}),n.jsx("div",{className:"space-y-3",children:e.map(r=>n.jsx(Xv,{worker:r},r.id))})]})}function Xv({worker:e}){const{t}=ne();return n.jsx("div",{className:`bg-bg-secondary rounded-xl p-4 md:p-5 border transition-colors hover:border-gray-300 dark:hover:border-gray-600 border-border-primary ${e.error?"opacity-60":""}`,children:n.jsxs("div",{className:"flex flex-col gap-4",children:[n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${e.error?"bg-red-400":"bg-green-400"}`}),e.kind&&n.jsx("span",{className:`inline-block px-2.5 py-0.5 text-xs font-medium rounded-md ${Wv[e.kind]||"bg-gray-100 text-gray-600"}`,children:e.kind}),n.jsx("span",{className:"text-sm font-medium text-text-primary",children:e.name||e.hostname}),e.isCurrent&&n.jsx("span",{className:"text-[10px] uppercase font-bold tracking-wider px-1.5 py-0.5 bg-accent-brand/10 text-accent-brand rounded",children:t("metrics.current")}),e.error&&n.jsx("span",{className:"text-xs text-red-400",children:e.error})]}),n.jsxs("span",{className:"text-xs text-text-tertiary font-mono bg-bg-tertiary px-2 py-0.5 rounded-md border border-border-primary/50",children:["PID ",e.pid]})]}),n.jsxs("div",{className:"flex flex-col md:flex-row md:items-start justify-between gap-4 md:gap-6",children:[n.jsxs("div",{className:"flex flex-col gap-2.5 flex-1 min-w-0",children:[n.jsx(_t,{path:e.cwd,className:"text-[13px] text-text-secondary font-mono truncate max-w-full"}),e.url&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx(ct,{size:14,className:"text-text-tertiary flex-none"}),n.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-accent-brand hover:underline truncate",children:e.url})]})]}),e.rssMib>0||e.heapUsedMib>0?n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 flex-none",style:{minWidth:"460px"},children:[n.jsxs("div",{className:"min-w-[100px]",children:[n.jsx(Dt,{icon:n.jsx(qn,{size:14}),label:"RSS",value:`${e.rssMib.toFixed(0)} MiB`}),n.jsx("div",{className:"mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden",children:n.jsx("div",{className:"h-full rounded-full bg-blue-500 transition-all duration-500",style:{width:`${Math.min(e.rssMib/2048*100,100)}%`}})})]}),n.jsxs("div",{className:"min-w-[140px]",children:[n.jsx(Dt,{icon:n.jsx(qn,{size:14}),label:"Heap",value:`${e.heapUsedMib.toFixed(0)} / ${e.heapTotalMib.toFixed(0)} MiB`}),e.heapTotalMib>0&&n.jsx("div",{className:"mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden",children:n.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${zr(e.heapUsedMib/e.heapTotalMib*100)[1]}`,style:{width:`${Math.min(e.heapUsedMib/e.heapTotalMib*100,100)}%`}})})]}),n.jsx("div",{className:"min-w-[80px]",children:n.jsx(Dt,{icon:n.jsx(pr,{size:14}),label:t("metrics.uptime"),value:ou(e.uptimeSeconds)})}),n.jsx("div",{className:"min-w-[60px]",children:n.jsx(Dt,{icon:n.jsx(qr,{size:14}),label:t("metrics.version"),value:e.version||"-"})})]}):n.jsxs("div",{className:"grid grid-cols-2 gap-4 flex-none",style:{minWidth:"200px"},children:[n.jsx("div",{className:"min-w-[80px]",children:n.jsx(Dt,{icon:n.jsx(pr,{size:14}),label:t("metrics.uptime"),value:ou(e.uptimeSeconds)})}),n.jsx("div",{className:"min-w-[60px]",children:n.jsx(Dt,{icon:n.jsx(qr,{size:14}),label:t("metrics.version"),value:e.version||"-"})})]})]})]})})}function Dt({icon:e,label:t,value:r}){return n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-text-tertiary",children:[e,n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider",children:t})]}),n.jsx("div",{className:"text-sm font-semibold text-text-primary",style:{fontVariantNumeric:"tabular-nums"},children:r})]})}function zr(e){return e>=90?["text-red-500","bg-red-500"]:e>=70?["text-amber-500","bg-amber-500"]:["text-green-500","bg-green-500"]}function su(e){return e>=1024?`${(e/1024).toFixed(1)} GiB`:`${e} MiB`}function au(e){if(e===0)return"0 B";const t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function ou(e){if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m ${e%60}s`;const t=Math.floor(e/3600),r=Math.floor(e%3600/60);return t>=24?`${Math.floor(t/24)}d ${t%24}h`:`${t}h ${r}m`}function Zv({onNavigate:e}){const{t}=ne(),[r,i]=C.useState(Xr);if(C.useEffect(()=>{const s=()=>i(Xr());return window.addEventListener("hashchange",s),()=>window.removeEventListener("hashchange",s)},[]),r==="add-wechat"||r!=null&&r.startsWith("rebind-wechat/")){const s=r!=null&&r.startsWith("rebind-wechat/")?r.split("/")[1]:void 0;return n.jsx(Qv,{onBack:()=>bd("remote-control"),t,existingInstanceId:s})}return r==="add-wecom"?n.jsx(eS,{onBack:()=>bd("remote-control"),t}):n.jsx(Jv,{onNavigate:e,t})}function Jv({onNavigate:e,t}){const[r,i]=C.useState([]),[s,l]=C.useState(!0),[d,a]=C.useState(null),[o,c]=C.useState(null),p=C.useCallback(async()=>{try{const y=await ye("/api/v1/channels");if(y.ok){const S=await y.json();i((S.clients||[]).filter(k=>!k.hidden&&!k.instanceId.startsWith("_pending")))}}catch{}finally{l(!1)}},[]);C.useEffect(()=>{p();const y=setInterval(p,5e3);return()=>clearInterval(y)},[p]);const g=C.useCallback(async(y,S,k)=>{const T=`${S}:${k}:${y}`;c(T),a(null);try{const R=y==="delete"?"DELETE":"POST",A=y==="delete"?`/api/v1/channels/${S}/${k}`:`/api/v1/channels/${S}/${k}/${y}`,D=await ye(A,{method:R});if(!D.ok){const B=await D.json().catch(()=>({}));throw new Error(B.error||`Failed: ${D.status}`)}const L=await D.json().catch(()=>({}));if(y==="unbind"&&S==="wechat"&&L.needsQrScan){rr("remote-control",`rebind-wechat/${k}`);return}await p()}catch(R){a((R==null?void 0:R.message)||"Action failed")}finally{c(null)}},[p]),b=y=>y==="connected"?"text-green-500":y==="connecting"?"text-yellow-500":y==="error"?"text-red-500":"text-text-tertiary",_=y=>t(y==="connected"?"remoteControl.connected":y==="connecting"?"remoteControl.connecting":"remoteControl.disconnected"),w=y=>y==="wechat"?n.jsx(Lu,{size:18,className:"text-green-500"}):y==="wecom"?n.jsx(Wr,{size:18,className:"text-accent-brand"}):n.jsx(Yc,{size:18,className:"text-text-tertiary"}),v=y=>y==="wechat"?t("channel.wechat")+t("remoteControl.bot"):y==="wecom"?t("channel.wecom")+t("remoteControl.bot"):y,h=y=>`${v(y.clientType)} #${y.instanceId.slice(0,4)}`,m=r.filter(y=>y.clientType==="wechat"),u=r.filter(y=>y.clientType==="wecom"),f=r.filter(y=>y.clientType!=="wechat"&&y.clientType!=="wecom"),x=y=>{const S=`${y.clientType}:${y.instanceId}`,k=y.status==="connected",T=o==null?void 0:o.startsWith(S);return n.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-bg-secondary hover:bg-bg-hover transition-colors cursor-pointer",onClick:()=>{T||g(k?"stop":"start",y.clientType,y.instanceId)},children:[w(y.clientType),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-text-primary truncate",children:h(y)}),n.jsx("span",{className:`text-xs ${b(y.status)}`,children:_(y.status)})]}),n.jsxs("div",{className:"flex items-center gap-1",onClick:R=>R.stopPropagation(),children:[n.jsx("button",{className:`p-1.5 rounded-md text-text-tertiary transition-colors ${k?"hover:text-orange-500":"hover:text-green-500"} hover:bg-bg-hover`,title:t(k?"remoteControl.disconnect":"remoteControl.connect"),disabled:!!T,onClick:()=>g(k?"stop":"start",y.clientType,y.instanceId),children:k?n.jsx(Yc,{size:14}):n.jsx(Qm,{size:14})}),k&&n.jsx("button",{className:"p-1.5 rounded-md text-text-tertiary hover:text-orange-500 hover:bg-bg-hover transition-colors",title:t("remoteControl.unbind"),disabled:!!T,onClick:()=>g("unbind",y.clientType,y.instanceId),children:n.jsx(dt,{size:14})}),n.jsx("button",{className:"p-1.5 rounded-md text-text-tertiary hover:text-red-500 hover:bg-bg-hover transition-colors",title:t("remoteControl.delete"),disabled:!!T,onClick:()=>g("delete",y.clientType,y.instanceId),children:n.jsx(sn,{size:14})})]})]},S)},E=(y,S,k,T)=>n.jsxs("div",{children:[n.jsx("h2",{className:"text-sm font-medium text-text-secondary mb-2",children:y}),S.length===0?n.jsx("div",{className:"py-4 text-center text-xs text-text-tertiary",children:t("remoteControl.noChannels")}):n.jsx("div",{className:"space-y-2",children:S.map(x)}),k&&n.jsxs("button",{className:"flex items-center gap-1.5 mt-2 px-3 py-1.5 text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover rounded-md transition-colors",onClick:k,children:[n.jsx(bt,{size:12}),T||t("remoteControl.add")]})]});return n.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[n.jsxs("div",{className:"px-6 py-5 border-b border-border-primary",children:[n.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("remoteControl.title")}),n.jsx("p",{className:"text-sm text-text-tertiary mt-1",children:t("remoteControl.subtitle")})]}),n.jsxs("div",{className:"px-6 py-4 flex-1 space-y-6",children:[d&&n.jsx("div",{className:"p-3 rounded-lg bg-red-500/10 text-red-500 text-sm",children:d}),s?n.jsx("div",{className:"text-sm text-text-tertiary py-4",children:t("remoteControl.connecting")}):r.length===0?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"py-8 text-center",children:[n.jsx(Wr,{size:32,className:"mx-auto mb-3 text-text-tertiary opacity-50"}),n.jsx("p",{className:"text-sm text-text-tertiary",children:t("remoteControl.noChannels")}),n.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:t("remoteControl.noChannelsHint")})]}),n.jsxs("div",{className:"flex gap-3",children:[n.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary",onClick:()=>rr("remote-control","add-wechat"),children:[n.jsx(bt,{size:14}),t("remoteControl.addWeChat")]}),n.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary",onClick:()=>rr("remote-control","add-wecom"),children:[n.jsx(bt,{size:14}),t("remoteControl.addWeCom")]})]})]}):n.jsxs(n.Fragment,{children:[E(t("channel.wechat")+t("remoteControl.bot"),m,()=>rr("remote-control","add-wechat"),t("remoteControl.addWeChat")),E(t("channel.wecom")+t("remoteControl.bot"),u,()=>rr("remote-control","add-wecom"),t("remoteControl.addWeCom")),f.length>0&&E(t("remoteControl.plugin"),f)]}),n.jsx("hr",{className:"border-border-primary"}),n.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-lg bg-bg-secondary hover:bg-bg-hover cursor-pointer transition-colors border border-border-primary",onClick:()=>{e?e("plugins"):window.location.hash="#/plugins"},children:[n.jsxs("div",{className:"flex-1",children:[n.jsx("h3",{className:"text-sm font-medium text-text-primary",children:t("remoteControl.installMore")}),n.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:t("remoteControl.installMoreHint")})]}),n.jsx(Ph,{size:16,className:"text-text-tertiary"})]})]})]})}function Qv({onBack:e,t,existingInstanceId:r}){const[i,s]=C.useState(null),[l,d]=C.useState(t("remoteControl.fetchingQr")),[a,o]=C.useState(r??null),[c,p]=C.useState(null),[g,b]=C.useState(!1);return C.useEffect(()=>{let _=!1;return(async()=>{try{let w=r;if(!w){const v=await ye("/api/v1/channels/wechat",{method:"POST"});if(!v.ok)throw new Error((await v.json().catch(()=>({}))).error||"Failed");const h=await v.json();if(_)return;w=h.instanceId,o(w)}for(let v=0;v<180&&!_;v++){await new Promise(h=>setTimeout(h,1e3));try{const h=await fetch(`/api/v1/channels/wechat/${w}/qr`);if(!h.ok)continue;const m=await h.json();if(_)return;if(m.qrUrl&&s(m.qrUrl),m.message&&d(m.message),m.type==="confirmed"){b(!0),d(t("remoteControl.connected")),setTimeout(()=>{_||e()},1500);return}if(m.type==="error"){p(m.message);return}}catch{}}!_&&!g&&p("Timeout")}catch(w){_||p((w==null?void 0:w.message)||"Failed")}})(),()=>{_=!0}},[r]),n.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[n.jsxs("div",{className:"px-6 py-5 border-b border-border-primary flex items-center gap-3",children:[n.jsx("button",{onClick:e,className:"p-1 rounded-md hover:bg-bg-hover transition-colors",children:n.jsx(gr,{size:18})}),n.jsxs("div",{children:[n.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("remoteControl.addWeChat")}),n.jsx("p",{className:"text-sm text-text-tertiary",children:t("remoteControl.scanQr")})]})]}),n.jsx("div",{className:"flex-1 flex flex-col items-center justify-center px-6 py-8",children:c?n.jsxs("div",{className:"text-center space-y-4",children:[n.jsx("p",{className:"text-red-500",children:c}),n.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm border border-border-primary",children:t("remoteControl.cancel")})]}):i?n.jsxs("div",{className:"text-center space-y-4",children:[n.jsx("div",{className:"inline-block p-4 bg-white rounded-xl",children:n.jsx("img",{src:`https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=${encodeURIComponent(i)}`,alt:"QR Code",className:"w-60 h-60"})}),n.jsx("p",{className:"text-sm text-text-secondary",children:l})]}):n.jsxs("div",{className:"text-center space-y-3",children:[n.jsx("div",{className:"w-8 h-8 mx-auto border-2 border-accent-brand border-t-transparent rounded-full animate-spin"}),n.jsx("p",{className:"text-sm text-text-tertiary",children:l})]})})]})}function eS({onBack:e,t}){const[r,i]=C.useState(""),[s,l]=C.useState(""),[d,a]=C.useState("botId"),[o,c]=C.useState(!1),[p,g]=C.useState(null),b=C.useCallback(async()=>{if(!(!r.trim()||!s.trim())){c(!0),g(null);try{const _=await ye("/api/v1/channels/wecom",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({botId:r.trim(),secret:s.trim()})});if(!_.ok){const w=await _.json().catch(()=>({}));throw new Error(w.error||"Failed")}e()}catch(_){g((_==null?void 0:_.message)||"Failed")}finally{c(!1)}}},[r,s,e]);return n.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[n.jsxs("div",{className:"px-6 py-5 border-b border-border-primary flex items-center gap-3",children:[n.jsx("button",{onClick:e,className:"p-1 rounded-md hover:bg-bg-hover transition-colors",children:n.jsx(gr,{size:18})}),n.jsxs("div",{children:[n.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("remoteControl.addWeCom")}),n.jsx("p",{className:"text-sm text-text-tertiary",children:t("remoteControl.wecomBotIdHint")})]})]}),n.jsxs("div",{className:"px-6 py-8 max-w-md mx-auto w-full space-y-6",children:[p&&n.jsx("div",{className:"p-3 rounded-lg bg-red-500/10 text-red-500 text-sm",children:p}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-sm font-medium text-text-primary",children:"Bot ID"}),n.jsx("input",{type:"text",className:"w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors",placeholder:"Enter Bot ID",value:r,onChange:_=>i(_.target.value),autoFocus:!0,disabled:d==="secret",onKeyDown:_=>{_.key==="Enter"&&r.trim()&&a("secret")}})]}),d==="secret"&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-sm font-medium text-text-primary",children:"Secret"}),n.jsx("input",{type:"password",className:"w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors",placeholder:"Enter Secret",value:s,onChange:_=>l(_.target.value),autoFocus:!0,onKeyDown:_=>{_.key==="Enter"&&s.trim()&&b()}}),n.jsx("p",{className:"text-xs text-text-tertiary",children:t("remoteControl.wecomSecretHint")})]}),n.jsxs("div",{className:"flex gap-3 pt-2",children:[d==="botId"?n.jsx("button",{className:"px-4 py-2 rounded-lg bg-accent-brand text-white text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50",disabled:!r.trim(),onClick:()=>a("secret"),children:t("remoteControl.next")}):n.jsx("button",{className:"px-4 py-2 rounded-lg bg-accent-brand text-white text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50",disabled:!s.trim()||o,onClick:b,children:t(o?"remoteControl.connecting":"remoteControl.connect")}),n.jsx("button",{className:"px-4 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-secondary hover:bg-bg-hover transition-colors",onClick:e,children:t("remoteControl.cancel")})]})]})]})}const tS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20clip-path='url(%23copilot-clip-34e811bed903495093b85bf96a98fb1b_0)'%3e%3crect%20width='24'%20height='24'%20rx='12'%20fill='%234C4F6B'%3e%3c/rect%3e%3cpath%20d='M3.4689%2011.0144C3.32344%2011.2025%203.31607%2011.4567%203.4345%2012.0298C3.65883%2013.0748%204.24029%2014.4426%205.15579%2016.0716L5.747%2017.1172L5.72862%2017.511C5.70544%2017.9326%205.72848%2018.5857%205.77921%2019.0271C5.80994%2019.2967%205.8055%2019.3035%205.66483%2019.4638C5.12042%2020.0864%205.03916%2021.1287%205.44787%2022.2839C5.62456%2022.7775%206.16958%2023.6999%206.50726%2024.0756C7.35392%2025.0154%208.35051%2025.4646%209.11147%2025.246C9.25446%2025.2051%209.28403%2025.213%209.47117%2025.3424C10.182%2025.8233%2011.3834%2026.2377%2012.4447%2026.3663C14.2242%2026.5843%2016.2727%2026.143%2018.8281%2024.9925C19.8948%2024.5099%2022.2541%2023.1352%2023.2513%2022.4096C25.1083%2021.0667%2026.4805%2019.6414%2027.251%2018.2635C27.9337%2017.0364%2028.2735%2015.7781%2028.2495%2014.5174C28.2466%2014.2525%2028.2536%2014.2359%2028.3599%2014.1746C28.8797%2013.8703%2029.1497%2013.198%2029.0927%2012.3562C29.075%2012.1165%2029.0266%2011.7946%2028.9902%2011.6448C28.7404%2010.7144%2028.0885%209.59971%2027.4078%208.94729C26.6515%208.22182%2025.7943%207.9129%2025.1958%208.14598C25.0631%208.19758%2025.0452%208.19542%2024.9177%208.08995C24.6357%207.86124%2023.9604%207.43473%2023.5488%207.22673L23.1224%207.01477L22.8206%206.45595C22.0392%205.01609%2020.7826%203.33003%2019.8801%202.50992C19.4937%202.15818%2019.2668%202.03929%2019.019%202.05739C18.866%202.06657%2018.8535%202.07379%2018.645%202.26084C18.0389%202.79819%2017.1889%204.41355%2016.3588%206.60463L16.1271%207.21325L15.7053%207.34845C14.3909%207.76995%2013.2238%208.30219%2012.1896%208.94928C11.1973%209.56799%2010.6591%209.97037%209.84886%2010.688L9.36087%2011.1197L9.13878%2011.0813C7.00072%2010.7039%205.07892%2010.5639%204.19776%2010.7186C3.84772%2010.7832%203.55743%2010.9008%203.4689%2011.0144Z'%20fill='%23D2D3E0'%3e%3c/path%3e%3crect%20x='6.68555'%20y='16.3788'%20width='17.7918'%20height='11.5605'%20rx='4.61469'%20transform='rotate(-30%206.68555%2016.3788)'%20fill='%23212234'%3e%3c/rect%3e%3cg%3e%3crect%20x='12.2119'%20y='17.2593'%20width='2.13173'%20height='4.42744'%20rx='1.06587'%20transform='rotate(-30%2012.2119%2017.2593)'%20fill='%23D2D3E0'%3e%3canimate%20attributeName='height'%20values='4.42744;2.2;4.42744;4.42744;2.2;4.42744'%20dur='0.6s'%20begin='0s;blink134e811bed903495093b85bf96a98fb1b_0.end+3s'%20id='blink134e811bed903495093b85bf96a98fb1b_0'%3e%3c/animate%3e%3canimate%20attributeName='y'%20values='17.2593;18.2593;17.2593;17.2593;18.2593;17.2593'%20dur='0.6s'%20begin='0s;blink134e811bed903495093b85bf96a98fb1b_0.end+3s'%3e%3c/animate%3e%3canimate%20attributeName='opacity'%20values='1;0.2;1;1;0.2;1'%20dur='0.6s'%20begin='0s;blink134e811bed903495093b85bf96a98fb1b_0.end+3s'%3e%3c/animate%3e%3c/rect%3e%3c/g%3e%3cg%3e%3crect%20x='17.9634'%20y='13.9387'%20width='2.13173'%20height='4.42744'%20rx='1.06587'%20transform='rotate(-30%2017.9634%2013.9387)'%20fill='%23D2D3E0'%3e%3canimate%20attributeName='height'%20values='4.42744;2.2;4.42744;4.42744;2.2;4.42744'%20dur='0.6s'%20begin='0s;blink234e811bed903495093b85bf96a98fb1b_0.end+3s'%20id='blink234e811bed903495093b85bf96a98fb1b_0'%3e%3c/animate%3e%3canimate%20attributeName='y'%20values='13.9387;14.9387;13.9387;13.9387;14.9387;13.9387'%20dur='0.6s'%20begin='0s;blink234e811bed903495093b85bf96a98fb1b_0.end+3s'%3e%3c/animate%3e%3canimate%20attributeName='opacity'%20values='1;0.2;1;1;0.2;1'%20dur='0.6s'%20begin='0s;blink234e811bed903495093b85bf96a98fb1b_0.end+3s'%3e%3c/animate%3e%3c/rect%3e%3c/g%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='copilot-clip-34e811bed903495093b85bf96a98fb1b_0'%3e%3crect%20width='24'%20height='24'%20rx='12'%20fill='white'%3e%3c/rect%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",rS="/assets/logo-iZVLr450.svg";function nS({isOpen:e,onClose:t,mainView:r,onNavigate:i}){const{t:s}=ne(),{userInfo:l}=mu(),d=zt(b=>b.info),a=zt(b=>b.fetch),o=ar(b=>b.fileChanges.length);C.useEffect(()=>{d||a()},[a,d]);const c=(l==null?void 0:l.userName)||(d==null?void 0:d.userName)||s("sidebar.user"),p=(d==null?void 0:d.version)||"",g=p&&p!=="dev"&&p!=="0.0.0"?`v${p}`:"";return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:`sidebar-overlay ${e?"":"sidebar-overlay-hidden"}`,onClick:t}),n.jsxs("aside",{className:`sidebar ${e?"":"sidebar-closed"}`,role:"navigation","aria-label":"Main navigation",children:[n.jsxs("div",{className:"sidebar-header",children:[n.jsx("img",{src:rS,alt:"CodeBuddy",className:"sidebar-logo"}),n.jsx("span",{className:"sidebar-brand",children:"CodeBuddy"}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:t,className:"md:hidden w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors","aria-label":"Close sidebar",children:n.jsx(Ie,{size:16})})]}),n.jsxs("nav",{className:"sidebar-nav","aria-label":"Primary",children:[n.jsxs("button",{className:`sidebar-nav-item ${r==="chat"?"active":""}`,onClick:()=>i("chat"),"aria-current":r==="chat"?"page":void 0,children:[n.jsx(fr,{size:16}),n.jsx("span",{children:s("sidebar.chatMode")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="workers"?"active":""}`,onClick:()=>i("workers"),children:[n.jsx(Rt,{size:16}),n.jsx("span",{children:s("sidebar.workers")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="remote-control"?"active":""}`,onClick:()=>i("remote-control"),children:[n.jsx(Wr,{size:16}),n.jsx("span",{children:s("sidebar.remoteControl")})]})]}),n.jsx("div",{className:"sidebar-content",children:n.jsxs("div",{className:"px-3 py-1",children:[n.jsxs("button",{className:`sidebar-nav-item ${r==="tasks"?"active":""}`,onClick:()=>i("tasks"),children:[n.jsx(_i,{size:16}),n.jsx("span",{children:s("sidebar.nav.tasks")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="terminal"?"active":""}`,onClick:()=>i("terminal"),children:[n.jsx(nn,{size:16}),n.jsx("span",{children:s("sidebar.terminalMode")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="editor"?"active":""}`,onClick:()=>i("editor"),children:[n.jsx(Cu,{size:16}),n.jsx("span",{children:s("sidebar.editor")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="changes"?"active":""}`,onClick:()=>i("changes"),children:[n.jsx(rn,{size:16}),n.jsx("span",{children:s("sidebar.changes")}),o>0&&n.jsx("span",{className:"sidebar-badge",children:o})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="plugins"?"active":""}`,onClick:()=>i("plugins"),children:[n.jsx(Ct,{size:16}),n.jsx("span",{children:s("sidebar.nav.plugins")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="metrics"?"active":""}`,onClick:()=>i("metrics"),children:[n.jsx(gi,{size:16}),n.jsx("span",{children:s("sidebar.metrics")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="logs"?"active":""}`,onClick:()=>i("logs"),children:[n.jsx(bi,{size:16}),n.jsx("span",{children:s("sidebar.logs")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="settings"?"active":""}`,onClick:()=>i("settings"),children:[n.jsx(vi,{size:16}),n.jsx("span",{children:s("sidebar.preferences")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="keybindings"?"active":""}`,onClick:()=>i("keybindings"),children:[n.jsx(Ym,{size:16}),n.jsx("span",{children:s("sidebar.keybindings")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="docs"?"active":""}`,onClick:()=>i("docs"),children:[n.jsx(fi,{size:16}),n.jsx("span",{children:s("sidebar.docs")})]})]})}),n.jsx("div",{className:"sidebar-footer",children:n.jsxs("div",{className:"sidebar-user",children:[n.jsx("img",{src:tS,alt:"User",className:"sidebar-user-avatar"}),n.jsxs("div",{className:"sidebar-user-info",children:[n.jsx("div",{className:"sidebar-user-name",children:c}),n.jsx("div",{className:"sidebar-user-status",children:g})]})]})})]})]})}function iS({onMenuClick:e,onNewChat:t,onSplitTerminal:r,onHistory:i,hasHistory:s,rightActions:l}){const{t:d}=ne(),{topic:a,status:o,currentModel:c}=rt(),{mainView:p,layout:g,terminalTitle:b}=Te(),[_,w]=C.useState(!1),v=C.useRef(null),h=p==="terminal",u=Ht(g)<Wp;C.useEffect(()=>{if(!_)return;const S=k=>{v.current&&!v.current.contains(k.target)&&w(!1)};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[_]);const f=C.useCallback(S=>{w(!1),r==null||r(S)},[r]),x=()=>{switch(p){case"chat":return a||d("chat.newChat");case"terminal":return b||d("terminal.title");case"settings":return d("settings.title");case"tasks":return d("tasks.title");case"plugins":return d("sidebar.nav.plugins");case"workers":return d("workers.title");case"metrics":return d("sidebar.metrics");case"logs":return d("sidebar.logs");case"docs":return d("sidebar.docs");case"remote-control":return d("sidebar.remoteControl");case"keybindings":return d("keybindings.title");default:return""}},E=c?c.replace(/^(claude-|gpt-|deepseek-)/,"").split("-").slice(0,2).join("-"):"",y=()=>l||(h?n.jsxs("div",{ref:v,className:"relative",children:[n.jsx("button",{onClick:()=>u&&w(!_),className:`text-text-secondary transition-colors flex items-center justify-center w-8 h-8 rounded-full ${u?"hover:text-text-primary hover:bg-bg-secondary":"opacity-40 cursor-not-allowed"}`,title:u?void 0:d("terminal.maxPanes"),"aria-label":"Split terminal",children:n.jsx(Vc,{size:20})}),_&&n.jsxs("div",{className:"absolute right-0 top-full mt-1 bg-bg-secondary border border-border-muted rounded-lg shadow-lg py-1 z-50 min-w-[140px]",children:[n.jsxs("button",{onClick:()=>f("horizontal"),className:"w-full flex items-center gap-3 px-4 py-2.5 text-[13px] text-text-primary hover:bg-bg-hover transition-colors",children:[n.jsx(Vc,{size:16,className:"text-text-secondary"}),n.jsx("span",{children:d("terminal.splitHorizontal")})]}),n.jsxs("button",{onClick:()=>f("vertical"),className:"w-full flex items-center gap-3 px-4 py-2.5 text-[13px] text-text-primary hover:bg-bg-hover transition-colors",children:[n.jsx(jg,{size:16,className:"text-text-secondary"}),n.jsx("span",{children:d("terminal.splitVertical")})]})]})]}):p==="chat"?n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("button",{onClick:t,className:"text-text-secondary hover:text-text-primary transition-colors flex items-center justify-center w-8 h-8 rounded-full hover:bg-bg-secondary","aria-label":"New chat",children:n.jsx(bt,{size:20})}),s&&n.jsx("button",{onClick:i,className:"text-text-secondary hover:text-text-primary transition-colors flex items-center justify-center w-8 h-8 rounded-full hover:bg-bg-secondary",title:d("sidebar.chatHistory"),"aria-label":"Chat history",children:n.jsx(Nu,{size:18})})]}):null);return n.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 h-14 bg-bg-primary text-xs flex-shrink-0 transition-colors duration-200 sticky top-0 z-10",role:"banner","aria-label":"Status bar",children:[n.jsx("div",{className:"flex items-center gap-4",children:n.jsx("button",{onClick:e,className:"text-text-secondary hover:text-text-primary transition-colors flex items-center justify-center w-8 h-8 rounded-full hover:bg-bg-secondary","aria-label":"Toggle sidebar",children:n.jsx(xi,{size:20})})}),n.jsxs("div",{className:"flex-1 flex flex-col justify-center items-center min-w-0 px-2",children:[n.jsx("span",{className:"font-medium text-text-primary text-[15px] tracking-wide truncate max-w-full",children:x()}),p==="chat"&&(E||o==="connected")&&n.jsx("span",{className:"hidden sm:block text-[10px] text-text-tertiary mt-0.5 truncate max-w-[200px]",children:[o==="connected"?"":"disconnected",E].filter(Boolean).join(" · ")})]}),n.jsx("div",{className:"flex items-center",children:y()})]})}let Bn=1e5;function sS(e){if(!Array.isArray(e))return[];const t=[];let r=null;for(const i of e)if(i.sessionUpdate==="user_message_chunk"){r&&(t.push(r),r=null);const s=i.content,l=(s==null?void 0:s.text)||"";if(!l.trim())continue;t.push({type:"message",id:`member-msg-${++Bn}`,role:"user",content:l,timestamp:Date.now()})}else if(i.sessionUpdate==="agent_message_chunk"){const s=i.content;if((s==null?void 0:s.type)==="thinking")continue;const l=(s==null?void 0:s.text)||"";if(!l)continue;r?r={...r,content:r.content+l}:r={type:"message",id:`member-msg-${++Bn}`,role:"assistant",content:l,timestamp:Date.now()}}else if(i.sessionUpdate==="tool_call"){r&&(t.push(r),r=null);const l=(i._meta||{})["codebuddy.ai/toolName"]||"";t.push({type:"tool_call",id:i.toolCallId||`member-tc-${++Bn}`,name:i.title||l||i.kind||"tool",kind:i.kind||"other",toolName:l,input:i.rawInput||i.input,status:i.status==="completed"?"completed":i.status==="failed"?"failed":"running",locations:i.locations,content:i.content})}else if(i.sessionUpdate==="tool_call_update"){const s=t.findIndex(l=>l.type==="tool_call"&&l.id===i.toolCallId);if(s!==-1){const l=t[s];t[s]={...l,status:i.status==="completed"?"completed":i.status==="failed"?"failed":l.status,result:i.rawOutput||i.toolResult||l.result,...i.content!==void 0?{content:i.content}:{}}}}return r&&t.push(r),t}function aS(){var b;const e=He(_=>_.focusedMemberName),t=He(_=>_.memberHistories),r=He(_=>_.members),i=He(_=>_.setFocusedMember),s=C.useRef(null),l=r.find(_=>_.name===e),d=e&&t[e]||[],a=C.useMemo(()=>sS(d),[d]),o=C.useMemo(()=>wp(a),[a]);C.useEffect(()=>{s.current&&(s.current.scrollTop=s.current.scrollHeight)},[o]);const c=C.useCallback(()=>{i(null)},[i]),p=(l==null?void 0:l.status)==="running"||(l==null?void 0:l.status)==="pending",{t:g}=ne();return n.jsxs("div",{ref:s,className:"absolute inset-0 overflow-y-auto overflow-x-hidden",children:[n.jsx("div",{className:"sticky top-0 z-10 bg-bg-primary/95 backdrop-blur-sm border-b border-border-muted/30",children:n.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-6 py-3 flex items-center gap-3",children:[n.jsx("button",{type:"button",onClick:c,className:"p-1.5 rounded-md hover:bg-bg-secondary text-text-tertiary hover:text-text-secondary transition-colors",title:g("team.backToMain"),children:n.jsx(gr,{size:16})}),n.jsx(Gn,{size:16,className:"text-accent-purple flex-shrink-0"}),n.jsxs("span",{className:"text-[14px] font-semibold text-accent-purple",children:["@",e]}),(l==null?void 0:l.description)&&n.jsx("span",{className:"text-[12px] text-text-tertiary truncate flex-1",children:l.description}),p&&n.jsx(_e,{size:14,className:"animate-spin text-accent-purple flex-shrink-0"}),n.jsx("div",{className:"flex-1"}),l&&n.jsxs("span",{className:"text-[11px] text-text-tertiary flex-shrink-0",children:[l.toolCallCount?g("team.tools").replace("{count}",String(l.toolCallCount)):"",(b=l.tokenUsage)!=null&&b.lastContextWindow?`${l.toolCallCount?" · ":""}${g("team.tokens").replace("{count}",String(Math.round(l.tokenUsage.lastContextWindow/1e3))+"k")}`:""]})]})}),n.jsx("div",{className:"px-4 sm:px-6 pt-4 pb-8",children:n.jsxs("div",{className:"max-w-3xl mx-auto flex flex-col",children:[p&&o.length===0?n.jsxs("div",{className:"flex items-center justify-center gap-2 py-20 text-text-tertiary text-[13px]",children:[n.jsx(_e,{size:16,className:"animate-spin"}),n.jsx("span",{children:g("team.loadingHistory")})]}):o.length===0?n.jsx("div",{className:"flex items-center justify-center py-20 text-text-tertiary text-[13px]",children:g("team.noHistory")}):o.map((_,w)=>{if(_.kind==="user"){const v=_.entry.content?Sp(_.entry.content):void 0;if(v)return v.from==="system"?null:n.jsx("div",{children:n.jsx(kp,{msg:v})},_.entry.id);let h=_.entry.content||"";return h=h.replace(/<system-reminder>[\s\S]*?<\/system-reminder>\s*/g,"").trim(),h?n.jsx("div",{className:"flex justify-end mb-6",children:n.jsx("div",{className:"max-w-[85%] sm:max-w-[75%] px-5 py-3 rounded-2xl rounded-tr-sm bg-bg-user border border-transparent",children:n.jsx("p",{className:"whitespace-pre-wrap break-words text-text-primary text-chat",children:h})})},_.entry.id):null}return _.kind==="assistant_message"?n.jsx("div",{className:"mb-6",children:n.jsx(Cc,{message:_.entry})},_.entry.id):_.kind==="assistant_tools"?n.jsx("div",{className:"mb-6",children:n.jsx(vp,{entries:_.entries})},`tools-${w}`):null}),p&&o.length>0&&n.jsxs("div",{className:"flex items-center gap-2 py-4 text-text-tertiary text-[12px]",children:[n.jsx(_e,{size:12,className:"animate-spin"}),n.jsx("span",{children:g("team.agentRunning")})]})]})})]})}let oS=0;const lS={info:5e3,success:5e3,warn:8e3,error:0},Ft=$e((e,t)=>({toasts:[],addToast:(r,i)=>{const s=`toast-${++oS}`,l={id:s,type:r,message:i,createdAt:Date.now()};e(a=>({toasts:[...a.toasts.slice(-2),l]}));const d=lS[r];d>0&&setTimeout(()=>{t().removeToast(s)},d)},removeToast:r=>{e(i=>({toasts:i.toasts.filter(s=>s.id!==r)}))},clearAll:()=>e({toasts:[]})})),lu={info:e=>Ft.getState().addToast("info",e),warn:e=>Ft.getState().addToast("warn",e),error:e=>Ft.getState().addToast("error",e),success:e=>Ft.getState().addToast("success",e)},cS={info:Vm,success:Zh,warn:lr,error:Gr},dS={info:"text-accent-blue",success:"text-accent-green",warn:"text-accent-yellow",error:"text-accent-red"};function uS({item:e}){const t=Ft(d=>d.removeToast),[r,i]=C.useState(!1),s=cS[e.type],l=()=>{i(!0),setTimeout(()=>t(e.id),200)};return n.jsxs("div",{role:"alert",className:["flex items-start gap-3 px-4 py-3 rounded-xl border border-border-default shadow-lg","bg-bg-card backdrop-blur-sm","max-w-[360px] min-w-[280px]","transition-all duration-200",r?"opacity-0 translate-x-4":"opacity-100 translate-x-0","animate-fadeIn"].join(" "),children:[n.jsx(s,{size:18,className:`${dS[e.type]} shrink-0 mt-0.5`}),n.jsx("p",{className:"flex-1 text-[13px] text-text-primary leading-[1.5] break-words",children:e.message}),n.jsx("button",{onClick:l,"aria-label":"Dismiss",className:"shrink-0 w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-primary transition-colors",children:n.jsx(Ie,{size:14})})]})}function pS(){const e=Ft(t=>t.toasts);return e.length===0?null:n.jsx("div",{className:"fixed bottom-6 right-6 z-[999] flex flex-col-reverse gap-2 pointer-events-auto max-md:bottom-20 max-md:right-4 max-md:left-4 max-md:items-stretch",children:e.map(t=>n.jsx(uS,{item:t},t.id))})}function hS(e,t){const r=[];for(const i of e)i.type==="tool_call"&&r.push(i);for(const i of t.values())r.push(i);return r}function mS(e,t){const r={};for(const i of e){const s=i.input||{},l=i.toolName;if(l==="TaskCreate"){const d=i.result,a=typeof d=="string"?d:d&&typeof d=="object"?String(d.text??d.output??""):"",o=!a&&Array.isArray(i.content)?i.content.reduce((b,_)=>{var w;return b||String(((w=_==null?void 0:_.content)==null?void 0:w.text)??(_==null?void 0:_.text)??"")},""):"",c=(a||o).match(/Task #(\d+)/),p=c?c[1]:`t-${Object.keys(r).length+1}`;let g=s.owner?String(s.owner):void 0;if(!g&&(t!=null&&t.length)){const b=s.subject?String(s.subject).toLowerCase():"",_=s.description?String(s.description).toLowerCase():"",w=b+" "+_;for(const v of t)if(w.includes(v.toLowerCase())){g=v;break}}r[p]={id:p,subject:s.subject?String(s.subject):"",status:"pending",owner:g,activeForm:s.activeForm?String(s.activeForm):void 0}}else if(l==="TaskUpdate"){const d=s.taskId?String(s.taskId):void 0;if(d&&r[d]){const a=r[d];s.status&&s.status!=="deleted"&&(a.status=String(s.status)),s.subject&&(a.subject=String(s.subject)),s.owner!==void 0&&(a.owner=s.owner?String(s.owner):void 0),s.activeForm&&(a.activeForm=String(s.activeForm)),s.status==="deleted"&&delete r[d]}}}return Object.values(r)}function gS(e){return e.filter(t=>t.toolName==="TaskCreate"||t.toolName==="TaskUpdate").length}function fS({status:e}){switch(e){case"completed":return n.jsx(vu,{size:14,className:"text-accent-green flex-shrink-0"});case"in_progress":return n.jsx(_e,{size:14,className:"text-accent-brand flex-shrink-0 animate-spin"});default:return n.jsx(nm,{size:14,className:"text-text-tertiary flex-shrink-0"})}}function bS({member:e,isFocused:t,onClick:r}){var o;const i=e.status==="running"||e.status==="pending",s=e.status==="failed"||e.status==="killed",l=$b(e.color),d=ki(e.color),a=[];return e.toolCallCount&&a.push(`${e.toolCallCount} tools`),(o=e.tokenUsage)!=null&&o.lastContextWindow&&a.push(`${(e.tokenUsage.lastContextWindow/1e3).toFixed(1)}k`),n.jsxs("button",{type:"button",onClick:r,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors cursor-pointer ${t?`${l.bg}`:i?`${l.bg} hover:opacity-80`:s?"bg-accent-red/10 text-accent-red":"bg-bg-secondary/50 text-text-tertiary hover:bg-bg-secondary/70"}`,style:{color:t||i?d:void 0,...t?{boxShadow:`0 0 0 1px ${d}40`}:{}},children:[n.jsxs("span",{className:"font-medium",children:["@",e.name]}),a.length>0&&n.jsx("span",{className:"opacity-70",children:a.join(" · ")}),i&&n.jsx(_e,{size:9,className:"animate-spin flex-shrink-0"}),s&&n.jsx(Gr,{size:9,className:"flex-shrink-0"}),!i&&!s&&n.jsx(Tt,{size:9,className:"flex-shrink-0"})]})}function yS(){const e=Ze(I=>I.timeline),t=Ze(I=>I.childToolCalls),r=Ze(I=>I.isAgentRunning),{t:i}=ne(),[s,l]=C.useState(!0),d=He(I=>I.isInTeam),a=He(I=>I.members),o=He(I=>I.focusedMemberName),c=He(I=>I.setFocusedMember),p=C.useMemo(()=>{const I=new Map;for(const q of a)q.color&&I.set(q.name,q.color);return I},[a]),g=C.useRef(0),[b,_]=C.useState(!1),w=C.useRef(r),v=C.useMemo(()=>hS(e,t),[e,t]),h=C.useMemo(()=>a.map(I=>I.name),[a]),m=C.useMemo(()=>mS(v,h),[v,h]),u=C.useMemo(()=>gS(v),[v]);C.useEffect(()=>{!w.current&&r&&(g.current=u,_(!0)),w.current=r},[r,u]),C.useEffect(()=>{b&&u>g.current&&_(!1)},[b,u]);const f=C.useCallback(()=>l(I=>!I),[]),x=C.useCallback(I=>{I.stopPropagation(),g.current=u,_(!0)},[u]),E=C.useCallback(I=>{c(o===I?null:I)},[o,c]),y=C.useCallback(I=>{I.owner&&p.has(I.owner)&&c(o===I.owner?null:I.owner)},[o,p,c]),S=a.filter(I=>I.status==="running"||I.status==="pending"),k=S.length>0,T=!r&&k,R=d&&a.length>0,A=m.length>0,D=A&&m.every(I=>I.status==="completed"),L=R&&!k&&!r,B=A&&m.every(I=>I.status==="pending")&&!r&&!k,H=A&&!(D||L||B)&&!b,U=R&&(k||o);if(!H&&!U)return null;const F=m.filter(I=>I.status==="completed").length,N=m.length,O=m.find(I=>I.status==="in_progress"),$=O?O.activeForm||O.subject:`${F}/${N}`;return n.jsx("div",{className:"flex-none px-4 sm:px-6 pb-1",children:n.jsx("div",{className:"max-w-3xl mx-auto",children:n.jsxs("div",{className:"rounded-lg border border-border-muted/15 bg-bg-secondary/30 overflow-hidden",children:[n.jsxs("button",{onClick:f,className:"flex items-center gap-2 w-full px-3 py-1.5 hover:bg-bg-hover/30 transition-colors cursor-pointer",children:[T?n.jsx(_e,{size:13,className:"animate-spin text-accent-purple flex-shrink-0"}):U?n.jsx(Fu,{size:13,className:"text-accent-purple flex-shrink-0"}):n.jsx(Ru,{size:13,className:"text-text-tertiary flex-shrink-0"}),T?n.jsx("span",{className:"text-xs font-medium text-accent-purple",children:i("team.waitingForTeammates").replace("{count}",String(S.length)).replace("{s}",S.length>1?"s":"")}):n.jsxs(n.Fragment,{children:[H&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-xs font-medium text-text-primary",children:i("todo.title")}),n.jsxs("span",{className:"text-[11px] text-text-tertiary tabular-nums",children:[F,"/",N]})]}),U&&H&&n.jsx("span",{className:"text-border-muted/40",children:"·"}),U&&n.jsxs("span",{className:"text-[11px] text-text-tertiary",children:[i("team.title")," ",S.length>0?i("team.activeCount").replace("{count}",String(S.length)):""]})]}),!s&&H&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-border-muted/60 select-none",children:"|"}),O&&r&&n.jsx(_e,{size:10,className:"text-accent-brand animate-spin flex-shrink-0"}),n.jsx("span",{className:"text-xs text-text-secondary truncate flex-1 text-left",children:$})]}),n.jsx("span",{className:"flex-1"}),!r&&!T&&n.jsx("span",{role:"button",tabIndex:0,onClick:x,onKeyDown:I=>{I.key==="Enter"&&x(I)},className:"text-text-tertiary hover:text-text-primary p-0.5 rounded transition-colors flex-shrink-0",children:n.jsx(Ie,{size:12})}),s?n.jsx(it,{size:12,className:"text-text-tertiary flex-shrink-0"}):n.jsx(Oe,{size:12,className:"text-text-tertiary flex-shrink-0"})]}),s&&n.jsxs("div",{className:"border-t border-border-muted/40",children:[U&&n.jsx("div",{className:"flex flex-wrap gap-1.5 px-3 py-1.5",children:a.map(I=>n.jsx(bS,{member:I,isFocused:o===I.name,onClick:()=>E(I.name)},I.name))}),H&&n.jsx("div",{className:`px-3 py-1.5 space-y-0.5 max-h-52 overflow-y-auto ${U?"border-t border-border-muted/30":""}`,children:m.map((I,q)=>{const W=I.owner?p.get(I.owner):void 0,Y=!!W,V=W?ki(W):void 0;return n.jsxs("div",{onClick:Y?()=>y(I):void 0,className:`flex items-center gap-2 py-0.5 text-xs ${Y?"cursor-pointer hover:bg-bg-hover/30 rounded px-1 -mx-1":""} ${I.status==="in_progress"?"text-text-primary":I.status==="completed"?"text-text-tertiary":"text-text-secondary"}`,children:[n.jsx(fS,{status:I.status}),n.jsxs("span",{className:`truncate ${I.status==="completed"?"line-through":""}`,children:[q+1,". ",I.status==="in_progress"?I.activeForm||I.subject||i("todo.untitled"):I.subject||i("todo.untitled")]}),W&&n.jsxs("span",{className:"text-[10px] font-medium flex-shrink-0 ml-auto",style:{color:V},children:["@",I.owner]})]},I.id)})})]})]})})})}function _S({title:e,message:t,confirmLabel:r,cancelLabel:i,danger:s,onConfirm:l,onCancel:d}){const{t:a}=ne(),o=C.useRef(null);C.useEffect(()=>{var p;(p=o.current)==null||p.focus()},[]);const c=C.useCallback(p=>{p.key==="Escape"&&(p.preventDefault(),d())},[d]);return n.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center",onKeyDown:c,children:[n.jsx("div",{className:"absolute inset-0 bg-black/30",onClick:d}),n.jsxs("div",{role:"alertdialog","aria-modal":"true","aria-labelledby":"confirm-title",className:"relative bg-bg-card border border-border-default rounded-xl shadow-2xl w-full max-w-[400px] mx-4 overflow-hidden",children:[n.jsxs("div",{className:"px-5 pt-5 pb-4",children:[s&&n.jsx("div",{className:"w-10 h-10 rounded-full bg-error-bg flex items-center justify-center mb-3",children:n.jsx(lr,{size:20,className:"text-accent-red"})}),n.jsx("h3",{id:"confirm-title",className:"text-text-primary text-[15px] font-semibold mb-1",children:e}),t&&n.jsx("p",{className:"text-text-secondary text-[13px] leading-relaxed",children:t})]}),n.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 pb-4",children:[n.jsx("button",{onClick:d,className:"px-4 py-1.5 text-[13px] text-text-secondary hover:text-text-primary rounded-lg hover:bg-bg-hover transition-colors",children:i||a("app.cancel")}),n.jsx("button",{ref:o,onClick:l,className:["px-4 py-1.5 text-[13px] font-medium rounded-lg transition-colors",s?"bg-accent-red text-white hover:opacity-90":"bg-accent-brand text-bg-primary hover:opacity-90"].join(" "),children:r||a("app.confirm")})]})]})]})}const xS=1e4;function vS(){const{t:e}=ne(),{workers:t,daemon:r,loading:i,error:s,fetchWorkers:l,fetchDaemonStatus:d,killWorker:a,startDaemon:o,stopDaemon:c,restartDaemon:p}=Lc();C.useEffect(()=>{l(),d();const m=setInterval(()=>{l(),d()},xS);return()=>clearInterval(m)},[l,d]);const g=C.useCallback(()=>{l(),d()},[l,d]),b=C.useCallback(m=>{window.location.hash=`#/logs?worker=${m.pid}`},[]),[_,w]=C.useState(null),v=C.useCallback(async m=>{w(m)},[]),h=C.useCallback(async()=>{_&&(await a(String(_.pid)),w(null))},[_,a]);return n.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[_&&n.jsx(_S,{title:e("workers.action.kill.confirm"),danger:!0,onConfirm:h,onCancel:()=>w(null)}),n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Rt,{size:20,className:"text-accent-brand"}),n.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:e("workers.title")})]}),n.jsxs("button",{onClick:g,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-text-secondary
612
- hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:e("workers.refresh"),children:[n.jsx(dt,{size:14,className:i?"animate-spin":""}),n.jsx("span",{children:e("workers.refresh")})]})]}),s&&n.jsx("div",{className:"mb-4 p-3 rounded-xl error-banner text-sm",children:s}),n.jsx(SS,{daemon:r,onStart:()=>o(),onStop:c,onRestart:p}),n.jsx(kS,{workers:t,onViewLogs:b,onKill:v})]})}function SS({daemon:e,onStart:t,onStop:r,onRestart:i}){const{t:s}=ne(),l=(e==null?void 0:e.status)==="running",[d,a]=C.useState(null),o=C.useCallback(async(c,p)=>{a(c);try{await p()}finally{a(null)}},[]);return n.jsx("div",{className:`bg-bg-secondary rounded-xl p-4 md:p-5 border mb-6 transition-colors worker-card-hover ${l?"border-green-400/40 ring-1 ring-green-400/10":"border-border-default"}`,children:n.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(qr,{size:18,className:l?"text-green-500":"text-text-tertiary"}),n.jsx("span",{className:"text-base font-semibold text-text-primary",children:s("workers.daemon")}),(e==null?void 0:e.pid)&&n.jsxs("span",{className:"text-xs text-text-tertiary font-mono bg-bg-tertiary px-2 py-0.5 rounded-md ml-2 border border-border-default/50",children:["PID ",e.pid]})]}),n.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[l&&n.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),n.jsx("span",{className:`relative inline-flex rounded-full h-2.5 w-2.5 ${l?"bg-green-500":"bg-gray-400"}`})]}),n.jsx("span",{className:"text-sm font-medium text-text-secondary",children:s(l?"workers.daemon.running":"workers.daemon.stopped")})]}),(e==null?void 0:e.endpoint)&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-border-primary",children:"|"}),n.jsx(ct,{size:14,className:"text-text-tertiary ml-1"}),n.jsx("a",{href:e.endpoint,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-accent-brand hover:underline",children:e.endpoint})]})]})]}),n.jsx("div",{className:"flex items-center gap-2 mt-2 md:mt-0",children:l?n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>o("stop",r),disabled:d!==null,className:`flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-lg border border-border-default
611
+ hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:e("metrics.refresh"),children:[n.jsx(dt,{size:14}),n.jsx("span",{children:e("metrics.refresh")})]})]}),t&&n.jsxs(n.Fragment,{children:[n.jsx(Kv,{metrics:t}),n.jsx(Yv,{workers:c})]})]})}function Vv(e,t){return e.map(r=>{const i=t.find(s=>s.pid===r.pid);return{...r,kind:i==null?void 0:i.kind,name:i==null?void 0:i.name,url:(i==null?void 0:i.url)||(i==null?void 0:i.endpoint),status:i==null?void 0:i.status}})}function Kv({metrics:e}){const{t}=ne(),r=e.memTotalMib>0?e.memUsedMib/e.memTotalMib*100:0,i=e.diskTotal>0?e.diskUsed/e.diskTotal*100:0;return n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[n.jsx(Fn,{icon:n.jsx(Rt,{size:18}),label:t("metrics.cpu"),value:`${e.cpuUsedPct.toFixed(1)}%`,subtext:`${e.cpuCount} ${t("metrics.cores")}`,percent:e.cpuUsedPct,colorClasses:zr(e.cpuUsedPct)}),n.jsx(Fn,{icon:n.jsx(qn,{size:18}),label:t("metrics.memory"),value:`${su(e.memUsedMib)} / ${su(e.memTotalMib)}`,subtext:`${r.toFixed(1)}%`,percent:r,colorClasses:zr(r)}),n.jsx(Fn,{icon:n.jsx(Fm,{size:18}),label:t("metrics.disk"),value:`${au(e.diskUsed)} / ${au(e.diskTotal)}`,subtext:`${i.toFixed(1)}%`,percent:i,colorClasses:zr(i)})]})}function Fn({icon:e,label:t,value:r,subtext:i,percent:s,colorClasses:l}){const[d,a]=l;return n.jsxs("div",{className:"bg-bg-secondary rounded-xl p-4 border border-border-primary",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[n.jsx("span",{className:d,children:e}),n.jsx("span",{className:"text-sm font-medium text-text-secondary",children:t})]}),n.jsx("div",{className:"text-xl font-semibold text-text-primary mb-1",children:r}),n.jsx("div",{className:"text-xs text-text-tertiary mb-3",children:i}),n.jsx("div",{className:"h-2 bg-bg-tertiary rounded-full overflow-hidden",children:n.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${a}`,style:{width:`${Math.min(s,100)}%`}})})]})}function Yv({workers:e}){const{t}=ne();return e.length===0?n.jsx("div",{className:"text-center py-12 text-text-tertiary",children:t("metrics.noWorkers")}):n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[n.jsx(Rt,{size:18,className:"text-text-secondary"}),n.jsxs("h2",{className:"text-base font-medium text-text-primary",children:["Workers (",e.length,")"]})]}),n.jsx("div",{className:"space-y-3",children:e.map(r=>n.jsx(Xv,{worker:r},r.id))})]})}function Xv({worker:e}){const{t}=ne();return n.jsx("div",{className:`bg-bg-secondary rounded-xl p-4 md:p-5 border transition-colors hover:border-gray-300 dark:hover:border-gray-600 border-border-primary ${e.error?"opacity-60":""}`,children:n.jsxs("div",{className:"flex flex-col gap-4",children:[n.jsxs("div",{className:"flex items-start justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${e.error?"bg-red-400":"bg-green-400"}`}),e.kind&&n.jsx("span",{className:`inline-block px-2.5 py-0.5 text-xs font-medium rounded-md ${Wv[e.kind]||"bg-gray-100 text-gray-600"}`,children:e.kind}),n.jsx("span",{className:"text-sm font-medium text-text-primary",children:e.name||e.hostname}),e.isCurrent&&n.jsx("span",{className:"text-[10px] uppercase font-bold tracking-wider px-1.5 py-0.5 bg-accent-brand/10 text-accent-brand rounded",children:t("metrics.current")}),e.error&&n.jsx("span",{className:"text-xs text-red-400",children:e.error})]}),n.jsxs("span",{className:"text-xs text-text-tertiary font-mono bg-bg-tertiary px-2 py-0.5 rounded-md border border-border-primary/50",children:["PID ",e.pid]})]}),n.jsxs("div",{className:"flex flex-col md:flex-row md:items-start justify-between gap-4 md:gap-6",children:[n.jsxs("div",{className:"flex flex-col gap-2.5 flex-1 min-w-0",children:[n.jsx(_t,{path:e.cwd,className:"text-[13px] text-text-secondary font-mono truncate max-w-full"}),e.url&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx(ct,{size:14,className:"text-text-tertiary flex-none"}),n.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-accent-brand hover:underline truncate",children:e.url})]})]}),e.rssMib>0||e.heapUsedMib>0?n.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 flex-none",style:{minWidth:"460px"},children:[n.jsxs("div",{className:"min-w-[100px]",children:[n.jsx(Dt,{icon:n.jsx(qn,{size:14}),label:"RSS",value:`${e.rssMib.toFixed(0)} MiB`}),n.jsx("div",{className:"mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden",children:n.jsx("div",{className:"h-full rounded-full bg-blue-500 transition-all duration-500",style:{width:`${Math.min(e.rssMib/2048*100,100)}%`}})})]}),n.jsxs("div",{className:"min-w-[140px]",children:[n.jsx(Dt,{icon:n.jsx(qn,{size:14}),label:"Heap",value:`${e.heapUsedMib.toFixed(0)} / ${e.heapTotalMib.toFixed(0)} MiB`}),e.heapTotalMib>0&&n.jsx("div",{className:"mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden",children:n.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${zr(e.heapUsedMib/e.heapTotalMib*100)[1]}`,style:{width:`${Math.min(e.heapUsedMib/e.heapTotalMib*100,100)}%`}})})]}),n.jsx("div",{className:"min-w-[80px]",children:n.jsx(Dt,{icon:n.jsx(pr,{size:14}),label:t("metrics.uptime"),value:ou(e.uptimeSeconds)})}),n.jsx("div",{className:"min-w-[60px]",children:n.jsx(Dt,{icon:n.jsx(qr,{size:14}),label:t("metrics.version"),value:e.version||"-"})})]}):n.jsxs("div",{className:"grid grid-cols-2 gap-4 flex-none",style:{minWidth:"200px"},children:[n.jsx("div",{className:"min-w-[80px]",children:n.jsx(Dt,{icon:n.jsx(pr,{size:14}),label:t("metrics.uptime"),value:ou(e.uptimeSeconds)})}),n.jsx("div",{className:"min-w-[60px]",children:n.jsx(Dt,{icon:n.jsx(qr,{size:14}),label:t("metrics.version"),value:e.version||"-"})})]})]})]})})}function Dt({icon:e,label:t,value:r}){return n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-text-tertiary",children:[e,n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider",children:t})]}),n.jsx("div",{className:"text-sm font-semibold text-text-primary",style:{fontVariantNumeric:"tabular-nums"},children:r})]})}function zr(e){return e>=90?["text-red-500","bg-red-500"]:e>=70?["text-amber-500","bg-amber-500"]:["text-green-500","bg-green-500"]}function su(e){return e>=1024?`${(e/1024).toFixed(1)} GiB`:`${e} MiB`}function au(e){if(e===0)return"0 B";const t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function ou(e){if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m ${e%60}s`;const t=Math.floor(e/3600),r=Math.floor(e%3600/60);return t>=24?`${Math.floor(t/24)}d ${t%24}h`:`${t}h ${r}m`}function Zv({onNavigate:e}){const{t}=ne(),[r,i]=C.useState(Xr);if(C.useEffect(()=>{const s=()=>i(Xr());return window.addEventListener("hashchange",s),()=>window.removeEventListener("hashchange",s)},[]),r==="add-wechat"||r!=null&&r.startsWith("rebind-wechat/")){const s=r!=null&&r.startsWith("rebind-wechat/")?r.split("/")[1]:void 0;return n.jsx(Qv,{onBack:()=>bd("remote-control"),t,existingInstanceId:s})}return r==="add-wecom"?n.jsx(eS,{onBack:()=>bd("remote-control"),t}):n.jsx(Jv,{onNavigate:e,t})}function Jv({onNavigate:e,t}){const[r,i]=C.useState([]),[s,l]=C.useState(!0),[d,a]=C.useState(null),[o,c]=C.useState(null),p=C.useCallback(async()=>{try{const y=await ye("/api/v1/channels");if(y.ok){const S=await y.json();i((S.clients||[]).filter(k=>!k.hidden&&!k.instanceId.startsWith("_pending")))}}catch{}finally{l(!1)}},[]);C.useEffect(()=>{p();const y=setInterval(p,5e3);return()=>clearInterval(y)},[p]);const g=C.useCallback(async(y,S,k)=>{const T=`${S}:${k}:${y}`;c(T),a(null);try{const R=y==="delete"?"DELETE":"POST",A=y==="delete"?`/api/v1/channels/${S}/${k}`:`/api/v1/channels/${S}/${k}/${y}`,D=await ye(A,{method:R});if(!D.ok){const B=await D.json().catch(()=>({}));throw new Error(B.error||`Failed: ${D.status}`)}const L=await D.json().catch(()=>({}));if(y==="unbind"&&S==="wechat"&&L.needsQrScan){rr("remote-control",`rebind-wechat/${k}`);return}await p()}catch(R){a((R==null?void 0:R.message)||"Action failed")}finally{c(null)}},[p]),b=y=>y==="connected"?"text-green-500":y==="connecting"?"text-yellow-500":y==="error"?"text-red-500":"text-text-tertiary",_=y=>t(y==="connected"?"remoteControl.connected":y==="connecting"?"remoteControl.connecting":"remoteControl.disconnected"),w=y=>y==="wechat"?n.jsx(Lu,{size:18,className:"text-green-500"}):y==="wecom"?n.jsx(Wr,{size:18,className:"text-accent-brand"}):n.jsx(Yc,{size:18,className:"text-text-tertiary"}),v=y=>y==="wechat"?t("channel.wechat")+t("remoteControl.bot"):y==="wecom"?t("channel.wecom")+t("remoteControl.bot"):y,h=y=>`${v(y.clientType)} #${y.instanceId.slice(0,4)}`,m=r.filter(y=>y.clientType==="wechat"),u=r.filter(y=>y.clientType==="wecom"),f=r.filter(y=>y.clientType!=="wechat"&&y.clientType!=="wecom"),x=y=>{const S=`${y.clientType}:${y.instanceId}`,k=y.status==="connected",T=o==null?void 0:o.startsWith(S);return n.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-bg-secondary hover:bg-bg-hover transition-colors cursor-pointer",onClick:()=>{T||g(k?"stop":"start",y.clientType,y.instanceId)},children:[w(y.clientType),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("div",{className:"text-sm font-medium text-text-primary truncate",children:h(y)}),n.jsx("span",{className:`text-xs ${b(y.status)}`,children:_(y.status)})]}),n.jsxs("div",{className:"flex items-center gap-1",onClick:R=>R.stopPropagation(),children:[n.jsx("button",{className:`p-1.5 rounded-md text-text-tertiary transition-colors ${k?"hover:text-orange-500":"hover:text-green-500"} hover:bg-bg-hover`,title:t(k?"remoteControl.disconnect":"remoteControl.connect"),disabled:!!T,onClick:()=>g(k?"stop":"start",y.clientType,y.instanceId),children:k?n.jsx(Yc,{size:14}):n.jsx(Qm,{size:14})}),k&&n.jsx("button",{className:"p-1.5 rounded-md text-text-tertiary hover:text-orange-500 hover:bg-bg-hover transition-colors",title:t("remoteControl.unbind"),disabled:!!T,onClick:()=>g("unbind",y.clientType,y.instanceId),children:n.jsx(dt,{size:14})}),n.jsx("button",{className:"p-1.5 rounded-md text-text-tertiary hover:text-red-500 hover:bg-bg-hover transition-colors",title:t("remoteControl.delete"),disabled:!!T,onClick:()=>g("delete",y.clientType,y.instanceId),children:n.jsx(sn,{size:14})})]})]},S)},E=(y,S,k,T)=>n.jsxs("div",{children:[n.jsx("h2",{className:"text-sm font-medium text-text-secondary mb-2",children:y}),S.length===0?n.jsx("div",{className:"py-4 text-center text-xs text-text-tertiary",children:t("remoteControl.noChannels")}):n.jsx("div",{className:"space-y-2",children:S.map(x)}),k&&n.jsxs("button",{className:"flex items-center gap-1.5 mt-2 px-3 py-1.5 text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover rounded-md transition-colors",onClick:k,children:[n.jsx(bt,{size:12}),T||t("remoteControl.add")]})]});return n.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[n.jsxs("div",{className:"px-6 py-5 border-b border-border-primary",children:[n.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("remoteControl.title")}),n.jsx("p",{className:"text-sm text-text-tertiary mt-1",children:t("remoteControl.subtitle")})]}),n.jsxs("div",{className:"px-6 py-4 flex-1 space-y-6",children:[d&&n.jsx("div",{className:"p-3 rounded-lg bg-red-500/10 text-red-500 text-sm",children:d}),s?n.jsx("div",{className:"text-sm text-text-tertiary py-4",children:t("remoteControl.connecting")}):r.length===0?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"py-8 text-center",children:[n.jsx(Wr,{size:32,className:"mx-auto mb-3 text-text-tertiary opacity-50"}),n.jsx("p",{className:"text-sm text-text-tertiary",children:t("remoteControl.noChannels")}),n.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:t("remoteControl.noChannelsHint")})]}),n.jsxs("div",{className:"flex gap-3",children:[n.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary",onClick:()=>rr("remote-control","add-wechat"),children:[n.jsx(bt,{size:14}),t("remoteControl.addWeChat")]}),n.jsxs("button",{className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary",onClick:()=>rr("remote-control","add-wecom"),children:[n.jsx(bt,{size:14}),t("remoteControl.addWeCom")]})]})]}):n.jsxs(n.Fragment,{children:[E(t("channel.wechat")+t("remoteControl.bot"),m,()=>rr("remote-control","add-wechat"),t("remoteControl.addWeChat")),E(t("channel.wecom")+t("remoteControl.bot"),u,()=>rr("remote-control","add-wecom"),t("remoteControl.addWeCom")),f.length>0&&E(t("remoteControl.plugin"),f)]}),n.jsx("hr",{className:"border-border-primary"}),n.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-lg bg-bg-secondary hover:bg-bg-hover cursor-pointer transition-colors border border-border-primary",onClick:()=>{e?e("plugins"):window.location.hash="#/plugins"},children:[n.jsxs("div",{className:"flex-1",children:[n.jsx("h3",{className:"text-sm font-medium text-text-primary",children:t("remoteControl.installMore")}),n.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:t("remoteControl.installMoreHint")})]}),n.jsx(Ph,{size:16,className:"text-text-tertiary"})]})]})]})}function Qv({onBack:e,t,existingInstanceId:r}){const[i,s]=C.useState(null),[l,d]=C.useState(t("remoteControl.fetchingQr")),[a,o]=C.useState(r??null),[c,p]=C.useState(null),[g,b]=C.useState(!1);return C.useEffect(()=>{let _=!1;return(async()=>{try{let w=r;if(!w){const v=await ye("/api/v1/channels/wechat",{method:"POST"});if(!v.ok)throw new Error((await v.json().catch(()=>({}))).error||"Failed");const h=await v.json();if(_)return;w=h.instanceId,o(w)}for(let v=0;v<180&&!_;v++){await new Promise(h=>setTimeout(h,1e3));try{const h=await fetch(`/api/v1/channels/wechat/${w}/qr`);if(!h.ok)continue;const m=await h.json();if(_)return;if(m.qrUrl&&s(m.qrUrl),m.message&&d(m.message),m.type==="confirmed"){b(!0),d(t("remoteControl.connected")),setTimeout(()=>{_||e()},1500);return}if(m.type==="error"){p(m.message);return}}catch{}}!_&&!g&&p("Timeout")}catch(w){_||p((w==null?void 0:w.message)||"Failed")}})(),()=>{_=!0}},[r]),n.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[n.jsxs("div",{className:"px-6 py-5 border-b border-border-primary flex items-center gap-3",children:[n.jsx("button",{onClick:e,className:"p-1 rounded-md hover:bg-bg-hover transition-colors",children:n.jsx(gr,{size:18})}),n.jsxs("div",{children:[n.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("remoteControl.addWeChat")}),n.jsx("p",{className:"text-sm text-text-tertiary",children:t("remoteControl.scanQr")})]})]}),n.jsx("div",{className:"flex-1 flex flex-col items-center justify-center px-6 py-8",children:c?n.jsxs("div",{className:"text-center space-y-4",children:[n.jsx("p",{className:"text-red-500",children:c}),n.jsx("button",{onClick:e,className:"px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm border border-border-primary",children:t("remoteControl.cancel")})]}):i?n.jsxs("div",{className:"text-center space-y-4",children:[n.jsx("div",{className:"inline-block p-4 bg-white rounded-xl",children:n.jsx("img",{src:`https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=${encodeURIComponent(i)}`,alt:"QR Code",className:"w-60 h-60"})}),n.jsx("p",{className:"text-sm text-text-secondary",children:l})]}):n.jsxs("div",{className:"text-center space-y-3",children:[n.jsx("div",{className:"w-8 h-8 mx-auto border-2 border-accent-brand border-t-transparent rounded-full animate-spin"}),n.jsx("p",{className:"text-sm text-text-tertiary",children:l})]})})]})}function eS({onBack:e,t}){const[r,i]=C.useState(""),[s,l]=C.useState(""),[d,a]=C.useState("botId"),[o,c]=C.useState(!1),[p,g]=C.useState(null),b=C.useCallback(async()=>{if(!(!r.trim()||!s.trim())){c(!0),g(null);try{const _=await ye("/api/v1/channels/wecom",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({botId:r.trim(),secret:s.trim()})});if(!_.ok){const w=await _.json().catch(()=>({}));throw new Error(w.error||"Failed")}e()}catch(_){g((_==null?void 0:_.message)||"Failed")}finally{c(!1)}}},[r,s,e]);return n.jsxs("div",{className:"flex flex-col h-full overflow-y-auto",children:[n.jsxs("div",{className:"px-6 py-5 border-b border-border-primary flex items-center gap-3",children:[n.jsx("button",{onClick:e,className:"p-1 rounded-md hover:bg-bg-hover transition-colors",children:n.jsx(gr,{size:18})}),n.jsxs("div",{children:[n.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("remoteControl.addWeCom")}),n.jsx("p",{className:"text-sm text-text-tertiary",children:t("remoteControl.wecomBotIdHint")})]})]}),n.jsxs("div",{className:"px-6 py-8 max-w-md mx-auto w-full space-y-6",children:[p&&n.jsx("div",{className:"p-3 rounded-lg bg-red-500/10 text-red-500 text-sm",children:p}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-sm font-medium text-text-primary",children:"Bot ID"}),n.jsx("input",{type:"text",className:"w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors",placeholder:"Enter Bot ID",value:r,onChange:_=>i(_.target.value),autoFocus:!0,disabled:d==="secret",onKeyDown:_=>{_.key==="Enter"&&r.trim()&&a("secret")}})]}),d==="secret"&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("label",{className:"text-sm font-medium text-text-primary",children:"Secret"}),n.jsx("input",{type:"password",className:"w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors",placeholder:"Enter Secret",value:s,onChange:_=>l(_.target.value),autoFocus:!0,onKeyDown:_=>{_.key==="Enter"&&s.trim()&&b()}}),n.jsx("p",{className:"text-xs text-text-tertiary",children:t("remoteControl.wecomSecretHint")})]}),n.jsxs("div",{className:"flex gap-3 pt-2",children:[d==="botId"?n.jsx("button",{className:"px-4 py-2 rounded-lg bg-accent-brand text-white text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50",disabled:!r.trim(),onClick:()=>a("secret"),children:t("remoteControl.next")}):n.jsx("button",{className:"px-4 py-2 rounded-lg bg-accent-brand text-white text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50",disabled:!s.trim()||o,onClick:b,children:t(o?"remoteControl.connecting":"remoteControl.connect")}),n.jsx("button",{className:"px-4 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-secondary hover:bg-bg-hover transition-colors",onClick:e,children:t("remoteControl.cancel")})]})]})]})}const tS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20clip-path='url(%23copilot-clip-34e811bed903495093b85bf96a98fb1b_0)'%3e%3crect%20width='24'%20height='24'%20rx='12'%20fill='%234C4F6B'%3e%3c/rect%3e%3cpath%20d='M3.4689%2011.0144C3.32344%2011.2025%203.31607%2011.4567%203.4345%2012.0298C3.65883%2013.0748%204.24029%2014.4426%205.15579%2016.0716L5.747%2017.1172L5.72862%2017.511C5.70544%2017.9326%205.72848%2018.5857%205.77921%2019.0271C5.80994%2019.2967%205.8055%2019.3035%205.66483%2019.4638C5.12042%2020.0864%205.03916%2021.1287%205.44787%2022.2839C5.62456%2022.7775%206.16958%2023.6999%206.50726%2024.0756C7.35392%2025.0154%208.35051%2025.4646%209.11147%2025.246C9.25446%2025.2051%209.28403%2025.213%209.47117%2025.3424C10.182%2025.8233%2011.3834%2026.2377%2012.4447%2026.3663C14.2242%2026.5843%2016.2727%2026.143%2018.8281%2024.9925C19.8948%2024.5099%2022.2541%2023.1352%2023.2513%2022.4096C25.1083%2021.0667%2026.4805%2019.6414%2027.251%2018.2635C27.9337%2017.0364%2028.2735%2015.7781%2028.2495%2014.5174C28.2466%2014.2525%2028.2536%2014.2359%2028.3599%2014.1746C28.8797%2013.8703%2029.1497%2013.198%2029.0927%2012.3562C29.075%2012.1165%2029.0266%2011.7946%2028.9902%2011.6448C28.7404%2010.7144%2028.0885%209.59971%2027.4078%208.94729C26.6515%208.22182%2025.7943%207.9129%2025.1958%208.14598C25.0631%208.19758%2025.0452%208.19542%2024.9177%208.08995C24.6357%207.86124%2023.9604%207.43473%2023.5488%207.22673L23.1224%207.01477L22.8206%206.45595C22.0392%205.01609%2020.7826%203.33003%2019.8801%202.50992C19.4937%202.15818%2019.2668%202.03929%2019.019%202.05739C18.866%202.06657%2018.8535%202.07379%2018.645%202.26084C18.0389%202.79819%2017.1889%204.41355%2016.3588%206.60463L16.1271%207.21325L15.7053%207.34845C14.3909%207.76995%2013.2238%208.30219%2012.1896%208.94928C11.1973%209.56799%2010.6591%209.97037%209.84886%2010.688L9.36087%2011.1197L9.13878%2011.0813C7.00072%2010.7039%205.07892%2010.5639%204.19776%2010.7186C3.84772%2010.7832%203.55743%2010.9008%203.4689%2011.0144Z'%20fill='%23D2D3E0'%3e%3c/path%3e%3crect%20x='6.68555'%20y='16.3788'%20width='17.7918'%20height='11.5605'%20rx='4.61469'%20transform='rotate(-30%206.68555%2016.3788)'%20fill='%23212234'%3e%3c/rect%3e%3cg%3e%3crect%20x='12.2119'%20y='17.2593'%20width='2.13173'%20height='4.42744'%20rx='1.06587'%20transform='rotate(-30%2012.2119%2017.2593)'%20fill='%23D2D3E0'%3e%3canimate%20attributeName='height'%20values='4.42744;2.2;4.42744;4.42744;2.2;4.42744'%20dur='0.6s'%20begin='0s;blink134e811bed903495093b85bf96a98fb1b_0.end+3s'%20id='blink134e811bed903495093b85bf96a98fb1b_0'%3e%3c/animate%3e%3canimate%20attributeName='y'%20values='17.2593;18.2593;17.2593;17.2593;18.2593;17.2593'%20dur='0.6s'%20begin='0s;blink134e811bed903495093b85bf96a98fb1b_0.end+3s'%3e%3c/animate%3e%3canimate%20attributeName='opacity'%20values='1;0.2;1;1;0.2;1'%20dur='0.6s'%20begin='0s;blink134e811bed903495093b85bf96a98fb1b_0.end+3s'%3e%3c/animate%3e%3c/rect%3e%3c/g%3e%3cg%3e%3crect%20x='17.9634'%20y='13.9387'%20width='2.13173'%20height='4.42744'%20rx='1.06587'%20transform='rotate(-30%2017.9634%2013.9387)'%20fill='%23D2D3E0'%3e%3canimate%20attributeName='height'%20values='4.42744;2.2;4.42744;4.42744;2.2;4.42744'%20dur='0.6s'%20begin='0s;blink234e811bed903495093b85bf96a98fb1b_0.end+3s'%20id='blink234e811bed903495093b85bf96a98fb1b_0'%3e%3c/animate%3e%3canimate%20attributeName='y'%20values='13.9387;14.9387;13.9387;13.9387;14.9387;13.9387'%20dur='0.6s'%20begin='0s;blink234e811bed903495093b85bf96a98fb1b_0.end+3s'%3e%3c/animate%3e%3canimate%20attributeName='opacity'%20values='1;0.2;1;1;0.2;1'%20dur='0.6s'%20begin='0s;blink234e811bed903495093b85bf96a98fb1b_0.end+3s'%3e%3c/animate%3e%3c/rect%3e%3c/g%3e%3c/g%3e%3cdefs%3e%3cclipPath%20id='copilot-clip-34e811bed903495093b85bf96a98fb1b_0'%3e%3crect%20width='24'%20height='24'%20rx='12'%20fill='white'%3e%3c/rect%3e%3c/clipPath%3e%3c/defs%3e%3c/svg%3e",rS="/assets/logo-iZVLr450.svg";function nS({isOpen:e,onClose:t,mainView:r,onNavigate:i}){const{t:s}=ne(),{userInfo:l}=mu(),d=zt(b=>b.info),a=zt(b=>b.fetch),o=ar(b=>b.fileChanges.length);C.useEffect(()=>{d||a()},[a,d]);const c=(l==null?void 0:l.userName)||(d==null?void 0:d.userName)||s("sidebar.user"),p=(d==null?void 0:d.version)||"",g=p&&p!=="dev"&&p!=="0.0.0"?`v${p}`:"";return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:`sidebar-overlay ${e?"":"sidebar-overlay-hidden"}`,onClick:t}),n.jsxs("aside",{className:`sidebar ${e?"":"sidebar-closed"}`,role:"navigation","aria-label":"Main navigation",children:[n.jsxs("div",{className:"sidebar-header",children:[n.jsx("img",{src:rS,alt:"CodeBuddy",className:"sidebar-logo"}),n.jsx("span",{className:"sidebar-brand",children:"CodeBuddy"}),n.jsx("div",{className:"flex-1"}),n.jsx("button",{onClick:t,className:"md:hidden w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors","aria-label":"Close sidebar",children:n.jsx(Ie,{size:16})})]}),n.jsxs("nav",{className:"sidebar-nav","aria-label":"Primary",children:[n.jsxs("button",{className:`sidebar-nav-item ${r==="chat"?"active":""}`,onClick:()=>i("chat"),"aria-current":r==="chat"?"page":void 0,children:[n.jsx(fr,{size:16}),n.jsx("span",{children:s("sidebar.chatMode")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="workers"?"active":""}`,onClick:()=>i("workers"),children:[n.jsx(Rt,{size:16}),n.jsx("span",{children:s("sidebar.workers")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="remote-control"?"active":""}`,onClick:()=>i("remote-control"),children:[n.jsx(Wr,{size:16}),n.jsx("span",{children:s("sidebar.remoteControl")})]})]}),n.jsx("div",{className:"sidebar-content",children:n.jsxs("div",{className:"px-3 py-1",children:[n.jsxs("button",{className:`sidebar-nav-item ${r==="tasks"?"active":""}`,onClick:()=>i("tasks"),children:[n.jsx(_i,{size:16}),n.jsx("span",{children:s("sidebar.nav.tasks")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="terminal"?"active":""}`,onClick:()=>i("terminal"),children:[n.jsx(nn,{size:16}),n.jsx("span",{children:s("sidebar.terminalMode")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="editor"?"active":""}`,onClick:()=>i("editor"),children:[n.jsx(Cu,{size:16}),n.jsx("span",{children:s("sidebar.editor")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="changes"?"active":""}`,onClick:()=>i("changes"),children:[n.jsx(rn,{size:16}),n.jsx("span",{children:s("sidebar.changes")}),o>0&&n.jsx("span",{className:"sidebar-badge",children:o})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="plugins"?"active":""}`,onClick:()=>i("plugins"),children:[n.jsx(Ct,{size:16}),n.jsx("span",{children:s("sidebar.nav.plugins")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="metrics"?"active":""}`,onClick:()=>i("metrics"),children:[n.jsx(gi,{size:16}),n.jsx("span",{children:s("sidebar.metrics")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="logs"?"active":""}`,onClick:()=>i("logs"),children:[n.jsx(bi,{size:16}),n.jsx("span",{children:s("sidebar.logs")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="settings"?"active":""}`,onClick:()=>i("settings"),children:[n.jsx(vi,{size:16}),n.jsx("span",{children:s("sidebar.preferences")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="keybindings"?"active":""}`,onClick:()=>i("keybindings"),children:[n.jsx(Ym,{size:16}),n.jsx("span",{children:s("sidebar.keybindings")})]}),n.jsxs("button",{className:`sidebar-nav-item ${r==="docs"?"active":""}`,onClick:()=>i("docs"),children:[n.jsx(fi,{size:16}),n.jsx("span",{children:s("sidebar.docs")})]})]})}),n.jsx("div",{className:"sidebar-footer",children:n.jsxs("div",{className:"sidebar-user",children:[n.jsx("img",{src:tS,alt:"User",className:"sidebar-user-avatar"}),n.jsxs("div",{className:"sidebar-user-info",children:[n.jsx("div",{className:"sidebar-user-name",children:c}),n.jsx("div",{className:"sidebar-user-status",children:g})]})]})})]})]})}function iS({onMenuClick:e,onNewChat:t,onSplitTerminal:r,onHistory:i,hasHistory:s,rightActions:l}){const{t:d}=ne(),{topic:a,status:o,currentModel:c}=rt(),{mainView:p,layout:g,terminalTitle:b}=Te(),[_,w]=C.useState(!1),v=C.useRef(null),h=p==="terminal",u=Ht(g)<Wp;C.useEffect(()=>{if(!_)return;const S=k=>{v.current&&!v.current.contains(k.target)&&w(!1)};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[_]);const f=C.useCallback(S=>{w(!1),r==null||r(S)},[r]),x=()=>{switch(p){case"chat":return a||d("chat.newChat");case"terminal":return b||d("terminal.title");case"settings":return d("settings.title");case"tasks":return d("tasks.title");case"plugins":return d("sidebar.nav.plugins");case"workers":return d("workers.title");case"metrics":return d("sidebar.metrics");case"logs":return d("sidebar.logs");case"docs":return d("sidebar.docs");case"remote-control":return d("sidebar.remoteControl");case"keybindings":return d("keybindings.title");default:return""}},E=c?c.replace(/^(claude-|gpt-|deepseek-)/,"").split("-").slice(0,2).join("-"):"",y=()=>l||(h?n.jsxs("div",{ref:v,className:"relative",children:[n.jsx("button",{onClick:()=>u&&w(!_),className:`text-text-secondary transition-colors flex items-center justify-center w-8 h-8 rounded-full ${u?"hover:text-text-primary hover:bg-bg-secondary":"opacity-40 cursor-not-allowed"}`,title:u?void 0:d("terminal.maxPanes"),"aria-label":"Split terminal",children:n.jsx(Vc,{size:20})}),_&&n.jsxs("div",{className:"absolute right-0 top-full mt-1 bg-bg-secondary border border-border-muted rounded-lg shadow-lg py-1 z-50 min-w-[140px]",children:[n.jsxs("button",{onClick:()=>f("horizontal"),className:"w-full flex items-center gap-3 px-4 py-2.5 text-[13px] text-text-primary hover:bg-bg-hover transition-colors",children:[n.jsx(Vc,{size:16,className:"text-text-secondary"}),n.jsx("span",{children:d("terminal.splitHorizontal")})]}),n.jsxs("button",{onClick:()=>f("vertical"),className:"w-full flex items-center gap-3 px-4 py-2.5 text-[13px] text-text-primary hover:bg-bg-hover transition-colors",children:[n.jsx(jg,{size:16,className:"text-text-secondary"}),n.jsx("span",{children:d("terminal.splitVertical")})]})]})]}):p==="chat"?n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("button",{onClick:t,className:"text-text-secondary hover:text-text-primary transition-colors flex items-center justify-center w-8 h-8 rounded-full hover:bg-bg-secondary","aria-label":"New chat",children:n.jsx(bt,{size:20})}),s&&n.jsx("button",{onClick:i,className:"text-text-secondary hover:text-text-primary transition-colors flex items-center justify-center w-8 h-8 rounded-full hover:bg-bg-secondary",title:d("sidebar.chatHistory"),"aria-label":"Chat history",children:n.jsx(Nu,{size:18})})]}):null);return n.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 h-14 bg-bg-primary text-xs flex-shrink-0 transition-colors duration-200 sticky top-0 z-10",role:"banner","aria-label":"Status bar",children:[n.jsx("div",{className:"flex items-center gap-4",children:n.jsx("button",{onClick:e,className:"text-text-secondary hover:text-text-primary transition-colors flex items-center justify-center w-8 h-8 rounded-full hover:bg-bg-secondary","aria-label":"Toggle sidebar",children:n.jsx(xi,{size:20})})}),n.jsxs("div",{className:"flex-1 flex flex-col justify-center items-center min-w-0 px-2",children:[n.jsx("span",{className:"font-medium text-text-primary text-[15px] tracking-wide truncate max-w-full",children:x()}),p==="chat"&&(E||o==="connected")&&n.jsx("span",{className:"hidden sm:block text-[10px] text-text-tertiary mt-0.5 truncate max-w-[200px]",children:[o==="connected"?"":"disconnected",E].filter(Boolean).join(" · ")})]}),n.jsx("div",{className:"flex items-center",children:y()})]})}let Bn=1e5;function sS(e){if(!Array.isArray(e))return[];const t=[];let r=null;for(const i of e)if(i.sessionUpdate==="user_message_chunk"){r&&(t.push(r),r=null);const s=i.content,l=(s==null?void 0:s.text)||"";if(!l.trim())continue;t.push({type:"message",id:`member-msg-${++Bn}`,role:"user",content:l,timestamp:Date.now()})}else if(i.sessionUpdate==="agent_message_chunk"){const s=i.content;if((s==null?void 0:s.type)==="thinking")continue;const l=(s==null?void 0:s.text)||"";if(!l)continue;r?r={...r,content:r.content+l}:r={type:"message",id:`member-msg-${++Bn}`,role:"assistant",content:l,timestamp:Date.now()}}else if(i.sessionUpdate==="tool_call"){r&&(t.push(r),r=null);const l=(i._meta||{})["codebuddy.ai/toolName"]||"";t.push({type:"tool_call",id:i.toolCallId||`member-tc-${++Bn}`,name:i.title||l||i.kind||"tool",kind:i.kind||"other",toolName:l,input:i.rawInput||i.input,status:i.status==="completed"?"completed":i.status==="failed"?"failed":"running",locations:i.locations,content:i.content})}else if(i.sessionUpdate==="tool_call_update"){const s=t.findIndex(l=>l.type==="tool_call"&&l.id===i.toolCallId);if(s!==-1){const l=t[s];t[s]={...l,status:i.status==="completed"?"completed":i.status==="failed"?"failed":l.status,result:i.rawOutput||i.toolResult||l.result,...i.content!==void 0?{content:i.content}:{}}}}return r&&t.push(r),t}function aS(){var b;const e=He(_=>_.focusedMemberName),t=He(_=>_.memberHistories),r=He(_=>_.members),i=He(_=>_.setFocusedMember),s=C.useRef(null),l=r.find(_=>_.name===e),d=e&&t[e]||[],a=C.useMemo(()=>sS(d),[d]),o=C.useMemo(()=>wp(a),[a]);C.useEffect(()=>{s.current&&(s.current.scrollTop=s.current.scrollHeight)},[o]);const c=C.useCallback(()=>{i(null)},[i]),p=(l==null?void 0:l.status)==="running"||(l==null?void 0:l.status)==="pending",{t:g}=ne();return n.jsxs("div",{ref:s,className:"absolute inset-0 overflow-y-auto overflow-x-hidden",children:[n.jsx("div",{className:"sticky top-0 z-10 bg-bg-primary/95 backdrop-blur-sm border-b border-border-muted/30",children:n.jsxs("div",{className:"max-w-3xl mx-auto px-4 sm:px-6 py-3 flex items-center gap-3",children:[n.jsx("button",{type:"button",onClick:c,className:"p-1.5 rounded-md hover:bg-bg-secondary text-text-tertiary hover:text-text-secondary transition-colors",title:g("team.backToMain"),children:n.jsx(gr,{size:16})}),n.jsx(Gn,{size:16,className:"text-accent-purple flex-shrink-0"}),n.jsxs("span",{className:"text-[14px] font-semibold text-accent-purple",children:["@",e]}),(l==null?void 0:l.description)&&n.jsx("span",{className:"text-[12px] text-text-tertiary truncate flex-1",children:l.description}),p&&n.jsx(_e,{size:14,className:"animate-spin text-accent-purple flex-shrink-0"}),n.jsx("div",{className:"flex-1"}),l&&n.jsxs("span",{className:"text-[11px] text-text-tertiary flex-shrink-0",children:[l.toolCallCount?g("team.tools").replace("{count}",String(l.toolCallCount)):"",(b=l.tokenUsage)!=null&&b.lastContextWindow?`${l.toolCallCount?" · ":""}${g("team.tokens").replace("{count}",String(Math.round(l.tokenUsage.lastContextWindow/1e3))+"k")}`:""]})]})}),n.jsx("div",{className:"px-4 sm:px-6 pt-4 pb-8",children:n.jsxs("div",{className:"max-w-3xl mx-auto flex flex-col",children:[p&&o.length===0?n.jsxs("div",{className:"flex items-center justify-center gap-2 py-20 text-text-tertiary text-[13px]",children:[n.jsx(_e,{size:16,className:"animate-spin"}),n.jsx("span",{children:g("team.loadingHistory")})]}):o.length===0?n.jsx("div",{className:"flex items-center justify-center py-20 text-text-tertiary text-[13px]",children:g("team.noHistory")}):o.map((_,w)=>{if(_.kind==="user"){const v=_.entry.content?Sp(_.entry.content):void 0;if(v)return v.from==="system"?null:n.jsx("div",{children:n.jsx(kp,{msg:v})},_.entry.id);let h=_.entry.content||"";return h=h.replace(/<system-reminder>[\s\S]*?<\/system-reminder>\s*/g,"").trim(),h?n.jsx("div",{className:"flex justify-end mb-6",children:n.jsx("div",{className:"max-w-[85%] sm:max-w-[75%] px-5 py-3 rounded-2xl rounded-tr-sm bg-bg-user border border-transparent",children:n.jsx("p",{className:"whitespace-pre-wrap break-words text-text-primary text-chat",children:h})})},_.entry.id):null}return _.kind==="assistant_message"?n.jsx("div",{className:"mb-6",children:n.jsx(Cc,{message:_.entry})},_.entry.id):_.kind==="assistant_tools"?n.jsx("div",{className:"mb-6",children:n.jsx(vp,{entries:_.entries})},`tools-${w}`):null}),p&&o.length>0&&n.jsxs("div",{className:"flex items-center gap-2 py-4 text-text-tertiary text-[12px]",children:[n.jsx(_e,{size:12,className:"animate-spin"}),n.jsx("span",{children:g("team.agentRunning")})]})]})})]})}let oS=0;const lS={info:5e3,success:5e3,warn:8e3,error:0},Ft=$e((e,t)=>({toasts:[],addToast:(r,i)=>{const s=`toast-${++oS}`,l={id:s,type:r,message:i,createdAt:Date.now()};e(a=>({toasts:[...a.toasts.slice(-2),l]}));const d=lS[r];d>0&&setTimeout(()=>{t().removeToast(s)},d)},removeToast:r=>{e(i=>({toasts:i.toasts.filter(s=>s.id!==r)}))},clearAll:()=>e({toasts:[]})})),lu={info:e=>Ft.getState().addToast("info",e),warn:e=>Ft.getState().addToast("warn",e),error:e=>Ft.getState().addToast("error",e),success:e=>Ft.getState().addToast("success",e)},cS={info:Vm,success:Zh,warn:lr,error:Gr},dS={info:"text-accent-blue",success:"text-accent-green",warn:"text-accent-yellow",error:"text-accent-red"};function uS({item:e}){const t=Ft(d=>d.removeToast),[r,i]=C.useState(!1),s=cS[e.type],l=()=>{i(!0),setTimeout(()=>t(e.id),200)};return n.jsxs("div",{role:"alert",className:["flex items-start gap-3 px-4 py-3 rounded-xl border border-border-default shadow-lg","bg-bg-card backdrop-blur-sm","max-w-[360px] min-w-[280px]","transition-all duration-200",r?"opacity-0 translate-x-4":"opacity-100 translate-x-0","animate-fadeIn"].join(" "),children:[n.jsx(s,{size:18,className:`${dS[e.type]} shrink-0 mt-0.5`}),n.jsx("p",{className:"flex-1 text-[13px] text-text-primary leading-[1.5] break-words",children:e.message}),n.jsx("button",{onClick:l,"aria-label":"Dismiss",className:"shrink-0 w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-primary transition-colors",children:n.jsx(Ie,{size:14})})]})}function pS(){const e=Ft(t=>t.toasts);return e.length===0?null:n.jsx("div",{className:"fixed bottom-6 right-6 z-[999] flex flex-col-reverse gap-2 pointer-events-auto max-md:bottom-20 max-md:right-4 max-md:left-4 max-md:items-stretch",children:e.map(t=>n.jsx(uS,{item:t},t.id))})}function hS(e,t){const r=[];for(const i of e)i.type==="tool_call"&&r.push(i);for(const i of t.values())r.push(i);return r}function mS(e,t){const r={};for(const i of e){const s=i.input||{},l=i.toolName;if(l==="TaskCreate"){const d=i.result,a=typeof d=="string"?d:d&&typeof d=="object"?String(d.text??d.output??""):"",o=!a&&Array.isArray(i.content)?i.content.reduce((b,_)=>{var w;return b||String(((w=_==null?void 0:_.content)==null?void 0:w.text)??(_==null?void 0:_.text)??"")},""):"",c=(a||o).match(/Task #(\d+)/),p=c?c[1]:`t-${Object.keys(r).length+1}`;let g=s.owner?String(s.owner):void 0;if(!g&&(t!=null&&t.length)){const b=s.subject?String(s.subject).toLowerCase():"",_=s.description?String(s.description).toLowerCase():"",w=b+" "+_;for(const v of t)if(w.includes(v.toLowerCase())){g=v;break}}r[p]={id:p,subject:s.subject?String(s.subject):"",status:"pending",owner:g,activeForm:s.activeForm?String(s.activeForm):void 0}}else if(l==="TaskUpdate"){const d=s.taskId?String(s.taskId):void 0;if(d&&r[d]){const a=r[d];s.status&&s.status!=="deleted"&&(a.status=String(s.status)),s.subject&&(a.subject=String(s.subject)),s.owner!==void 0&&(a.owner=s.owner?String(s.owner):void 0),s.activeForm&&(a.activeForm=String(s.activeForm)),s.status==="deleted"&&delete r[d]}}}return Object.values(r)}function gS(e){return e.filter(t=>t.toolName==="TaskCreate"||t.toolName==="TaskUpdate").length}function fS({status:e}){switch(e){case"completed":return n.jsx(vu,{size:14,className:"text-accent-green flex-shrink-0"});case"in_progress":return n.jsx(_e,{size:14,className:"text-accent-brand flex-shrink-0 animate-spin"});default:return n.jsx(nm,{size:14,className:"text-text-tertiary flex-shrink-0"})}}function bS({member:e,isFocused:t,onClick:r}){var o;const i=e.status==="running"||e.status==="pending",s=e.status==="failed"||e.status==="killed",l=$b(e.color),d=ki(e.color),a=[];return e.toolCallCount&&a.push(`${e.toolCallCount} tools`),(o=e.tokenUsage)!=null&&o.lastContextWindow&&a.push(`${(e.tokenUsage.lastContextWindow/1e3).toFixed(1)}k`),n.jsxs("button",{type:"button",onClick:r,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors cursor-pointer ${t?`${l.bg}`:i?`${l.bg} hover:opacity-80`:s?"bg-accent-red/10 text-accent-red":"bg-bg-secondary/50 text-text-tertiary hover:bg-bg-secondary/70"}`,style:{color:t||i?d:void 0,...t?{boxShadow:`0 0 0 1px ${d}40`}:{}},children:[n.jsxs("span",{className:"font-medium",children:["@",e.name]}),a.length>0&&n.jsx("span",{className:"opacity-70",children:a.join(" · ")}),i&&n.jsx(_e,{size:9,className:"animate-spin flex-shrink-0"}),s&&n.jsx(Gr,{size:9,className:"flex-shrink-0"}),!i&&!s&&n.jsx(Tt,{size:9,className:"flex-shrink-0"})]})}function yS(){const e=Ze(I=>I.timeline),t=Ze(I=>I.childToolCalls),r=Ze(I=>I.isAgentRunning),{t:i}=ne(),[s,l]=C.useState(!0),d=He(I=>I.isInTeam),a=He(I=>I.members),o=He(I=>I.focusedMemberName),c=He(I=>I.setFocusedMember),p=C.useMemo(()=>{const I=new Map;for(const q of a)q.color&&I.set(q.name,q.color);return I},[a]),g=C.useRef(0),[b,_]=C.useState(!1),w=C.useRef(r),v=C.useMemo(()=>hS(e,t),[e,t]),h=C.useMemo(()=>a.map(I=>I.name),[a]),m=C.useMemo(()=>mS(v,h),[v,h]),u=C.useMemo(()=>gS(v),[v]);C.useEffect(()=>{!w.current&&r&&(g.current=u,_(!0)),w.current=r},[r,u]),C.useEffect(()=>{b&&u>g.current&&_(!1)},[b,u]);const f=C.useCallback(()=>l(I=>!I),[]),x=C.useCallback(I=>{I.stopPropagation(),g.current=u,_(!0)},[u]),E=C.useCallback(I=>{c(o===I?null:I)},[o,c]),y=C.useCallback(I=>{I.owner&&p.has(I.owner)&&c(o===I.owner?null:I.owner)},[o,p,c]),S=a.filter(I=>I.status==="running"||I.status==="pending"),k=S.length>0,T=!r&&k,R=d&&a.length>0,A=m.length>0,D=A&&m.every(I=>I.status==="completed"),L=R&&!k&&!r,B=A&&m.every(I=>I.status==="pending")&&!r&&!k,H=A&&!(D||L||B)&&!b,U=R&&(k||o);if(!H&&!U)return null;const F=m.filter(I=>I.status==="completed").length,N=m.length,O=m.find(I=>I.status==="in_progress"),$=O?O.activeForm||O.subject:`${F}/${N}`;return n.jsx("div",{className:"flex-none px-4 sm:px-6 pb-1",children:n.jsx("div",{className:"max-w-3xl mx-auto",children:n.jsxs("div",{className:"rounded-lg border border-border-muted/15 bg-bg-secondary/30 overflow-hidden",children:[n.jsxs("button",{onClick:f,className:"flex items-center gap-2 w-full px-3 py-1.5 hover:bg-bg-hover/30 transition-colors cursor-pointer",children:[T?n.jsx(_e,{size:13,className:"animate-spin text-accent-purple flex-shrink-0"}):U?n.jsx(Fu,{size:13,className:"text-accent-purple flex-shrink-0"}):n.jsx(Ru,{size:13,className:"text-text-tertiary flex-shrink-0"}),T?n.jsx("span",{className:"text-xs font-medium text-accent-purple",children:i("team.waitingForTeammates").replace("{count}",String(S.length)).replace("{s}",S.length>1?"s":"")}):n.jsxs(n.Fragment,{children:[H&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-xs font-medium text-text-primary",children:i("todo.title")}),n.jsxs("span",{className:"text-[11px] text-text-tertiary tabular-nums",children:[F,"/",N]})]}),U&&H&&n.jsx("span",{className:"text-border-muted/40",children:"·"}),U&&n.jsxs("span",{className:"text-[11px] text-text-tertiary",children:[i("team.title")," ",S.length>0?i("team.activeCount").replace("{count}",String(S.length)):""]})]}),!s&&H&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-border-muted/60 select-none",children:"|"}),O&&r&&n.jsx(_e,{size:10,className:"text-accent-brand animate-spin flex-shrink-0"}),n.jsx("span",{className:"text-xs text-text-secondary truncate flex-1 text-left",children:$})]}),n.jsx("span",{className:"flex-1"}),!r&&!T&&n.jsx("span",{role:"button",tabIndex:0,onClick:x,onKeyDown:I=>{I.key==="Enter"&&x(I)},className:"text-text-tertiary hover:text-text-primary p-0.5 rounded transition-colors flex-shrink-0",children:n.jsx(Ie,{size:12})}),s?n.jsx(it,{size:12,className:"text-text-tertiary flex-shrink-0"}):n.jsx(Oe,{size:12,className:"text-text-tertiary flex-shrink-0"})]}),s&&n.jsxs("div",{className:"border-t border-border-muted/40",children:[U&&n.jsx("div",{className:"flex flex-wrap gap-1.5 px-3 py-1.5",children:a.map(I=>n.jsx(bS,{member:I,isFocused:o===I.name,onClick:()=>E(I.name)},I.name))}),H&&n.jsx("div",{className:`px-3 py-1.5 space-y-0.5 max-h-52 overflow-y-auto ${U?"border-t border-border-muted/30":""}`,children:m.map((I,q)=>{const W=I.owner?p.get(I.owner):void 0,Y=!!W,V=W?ki(W):void 0;return n.jsxs("div",{onClick:Y?()=>y(I):void 0,className:`flex items-center gap-2 py-0.5 text-xs ${Y?"cursor-pointer hover:bg-bg-hover/30 rounded px-1 -mx-1":""} ${I.status==="in_progress"?"text-text-primary":I.status==="completed"?"text-text-tertiary":"text-text-secondary"}`,children:[n.jsx(fS,{status:I.status}),n.jsxs("span",{className:`truncate ${I.status==="completed"?"line-through":""}`,children:[q+1,". ",I.status==="in_progress"?I.activeForm||I.subject||i("todo.untitled"):I.subject||i("todo.untitled")]}),W&&n.jsxs("span",{className:"text-[10px] font-medium flex-shrink-0 ml-auto",style:{color:V},children:["@",I.owner]})]},I.id)})})]})]})})})}function _S(e){try{const t=new URL(e),r=window.location.hostname;return t.hostname===r?e:(t.hostname=r,t.toString())}catch(t){return console.warn("Failed to resolve worker URL, using original:",e,t),e}}function xS({title:e,message:t,confirmLabel:r,cancelLabel:i,danger:s,onConfirm:l,onCancel:d}){const{t:a}=ne(),o=C.useRef(null);C.useEffect(()=>{var p;(p=o.current)==null||p.focus()},[]);const c=C.useCallback(p=>{p.key==="Escape"&&(p.preventDefault(),d())},[d]);return n.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center",onKeyDown:c,children:[n.jsx("div",{className:"absolute inset-0 bg-black/30",onClick:d}),n.jsxs("div",{role:"alertdialog","aria-modal":"true","aria-labelledby":"confirm-title",className:"relative bg-bg-card border border-border-default rounded-xl shadow-2xl w-full max-w-[400px] mx-4 overflow-hidden",children:[n.jsxs("div",{className:"px-5 pt-5 pb-4",children:[s&&n.jsx("div",{className:"w-10 h-10 rounded-full bg-error-bg flex items-center justify-center mb-3",children:n.jsx(lr,{size:20,className:"text-accent-red"})}),n.jsx("h3",{id:"confirm-title",className:"text-text-primary text-[15px] font-semibold mb-1",children:e}),t&&n.jsx("p",{className:"text-text-secondary text-[13px] leading-relaxed",children:t})]}),n.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 pb-4",children:[n.jsx("button",{onClick:d,className:"px-4 py-1.5 text-[13px] text-text-secondary hover:text-text-primary rounded-lg hover:bg-bg-hover transition-colors",children:i||a("app.cancel")}),n.jsx("button",{ref:o,onClick:l,className:["px-4 py-1.5 text-[13px] font-medium rounded-lg transition-colors",s?"bg-accent-red text-white hover:opacity-90":"bg-accent-brand text-bg-primary hover:opacity-90"].join(" "),children:r||a("app.confirm")})]})]})]})}const vS=1e4;function SS(){const{t:e}=ne(),{workers:t,daemon:r,loading:i,error:s,fetchWorkers:l,fetchDaemonStatus:d,killWorker:a,startDaemon:o,stopDaemon:c,restartDaemon:p}=Lc();C.useEffect(()=>{l(),d();const m=setInterval(()=>{l(),d()},vS);return()=>clearInterval(m)},[l,d]);const g=C.useCallback(()=>{l(),d()},[l,d]),b=C.useCallback(m=>{window.location.hash=`#/logs?worker=${m.pid}`},[]),[_,w]=C.useState(null),v=C.useCallback(async m=>{w(m)},[]),h=C.useCallback(async()=>{_&&(await a(String(_.pid)),w(null))},[_,a]);return n.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[_&&n.jsx(xS,{title:e("workers.action.kill.confirm"),danger:!0,onConfirm:h,onCancel:()=>w(null)}),n.jsxs("div",{className:"flex items-center justify-between mb-6",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Rt,{size:20,className:"text-accent-brand"}),n.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:e("workers.title")})]}),n.jsxs("button",{onClick:g,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-text-secondary
612
+ hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:e("workers.refresh"),children:[n.jsx(dt,{size:14,className:i?"animate-spin":""}),n.jsx("span",{children:e("workers.refresh")})]})]}),s&&n.jsx("div",{className:"mb-4 p-3 rounded-xl error-banner text-sm",children:s}),n.jsx(kS,{daemon:r,onStart:()=>o(),onStop:c,onRestart:p}),n.jsx(wS,{workers:t,onViewLogs:b,onKill:v})]})}function kS({daemon:e,onStart:t,onStop:r,onRestart:i}){const{t:s}=ne(),l=(e==null?void 0:e.status)==="running",[d,a]=C.useState(null),o=C.useCallback(async(c,p)=>{a(c);try{await p()}finally{a(null)}},[]);return n.jsx("div",{className:`bg-bg-secondary rounded-xl p-4 md:p-5 border mb-6 transition-colors worker-card-hover ${l?"border-green-400/40 ring-1 ring-green-400/10":"border-border-default"}`,children:n.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(qr,{size:18,className:l?"text-green-500":"text-text-tertiary"}),n.jsx("span",{className:"text-base font-semibold text-text-primary",children:s("workers.daemon")}),(e==null?void 0:e.pid)&&n.jsxs("span",{className:"text-xs text-text-tertiary font-mono bg-bg-tertiary px-2 py-0.5 rounded-md ml-2 border border-border-default/50",children:["PID ",e.pid]})]}),n.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[l&&n.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),n.jsx("span",{className:`relative inline-flex rounded-full h-2.5 w-2.5 ${l?"bg-green-500":"bg-gray-400"}`})]}),n.jsx("span",{className:"text-sm font-medium text-text-secondary",children:s(l?"workers.daemon.running":"workers.daemon.stopped")})]}),(e==null?void 0:e.endpoint)&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-border-primary",children:"|"}),n.jsx(ct,{size:14,className:"text-text-tertiary ml-1"}),n.jsx("a",{href:e.endpoint,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-accent-brand hover:underline",children:e.endpoint})]})]})]}),n.jsx("div",{className:"flex items-center gap-2 mt-2 md:mt-0",children:l?n.jsxs(n.Fragment,{children:[n.jsxs("button",{onClick:()=>o("stop",r),disabled:d!==null,className:`flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-lg border border-border-default
613
613
  bg-bg-primary text-text-secondary daemon-stop-btn transition-all disabled:opacity-50`,children:[d==="stop"?n.jsx(_e,{size:14,className:"animate-spin"}):n.jsx(Mu,{size:14}),s("workers.daemon.stop")]}),n.jsxs("button",{onClick:()=>o("restart",i),disabled:d!==null,className:`flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-lg border border-border-default
614
614
  bg-bg-primary text-text-secondary hover:text-text-primary hover:bg-bg-hover transition-all disabled:opacity-50`,children:[d==="restart"?n.jsx(_e,{size:14,className:"animate-spin"}):n.jsx(Vn,{size:14}),s("workers.daemon.restart")]})]}):n.jsxs("button",{onClick:()=>o("start",t),disabled:d!==null,className:`flex items-center gap-1.5 px-4 py-2 text-sm font-medium rounded-lg shadow-sm
615
- daemon-start-btn transition-all disabled:opacity-70`,children:[d==="start"?n.jsx(_e,{size:14,className:"animate-spin"}):n.jsx(Cg,{size:14}),s(d==="start"?"workers.daemon.starting":"workers.daemon.start")]})})]})})}function kS({workers:e,onViewLogs:t,onKill:r}){const{t:i}=ne();return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[n.jsx(Rt,{size:18,className:"text-text-secondary"}),n.jsxs("h2",{className:"text-base font-medium text-text-primary",children:[i("workers.active")," (",e.length,")"]})]}),e.length===0?n.jsx("div",{className:"text-center py-12 text-text-tertiary",children:i("workers.empty")}):n.jsx("div",{className:"space-y-4",children:[...e].sort((s,l)=>(l.isCurrent?1:0)-(s.isCurrent?1:0)).map(s=>n.jsx(ES,{worker:s,onViewLogs:t,onKill:r},`${s.pid}-${s.hostname}`))})]})}const wS={interactive:"kind-badge kind-badge-blue",bg:"kind-badge kind-badge-purple",daemon:"kind-badge kind-badge-green","daemon-worker":"kind-badge kind-badge-orange"};function ES({worker:e,onViewLogs:t,onKill:r}){const{t:i}=ne();return n.jsxs("div",{className:"group bg-bg-secondary rounded-xl p-4 md:p-5 border border-border-default transition-colors worker-card-hover",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:`inline-block px-2.5 py-0.5 text-xs font-medium rounded-md ${wS[e.kind]||"bg-gray-100 text-gray-600"}`,children:e.kind}),e.isCurrent&&n.jsx("span",{className:"text-[10px] uppercase font-bold tracking-wider px-1.5 py-0.5 rounded current-badge",children:"current"}),n.jsxs("span",{className:"text-xs text-text-tertiary font-mono",children:["PID ",e.pid]}),e.name&&e.name!=="-"&&n.jsx("span",{className:"text-sm font-medium text-text-primary",children:e.name})]}),n.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.url&&n.jsx("a",{href:cu(e),target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md text-text-tertiary hover:text-accent-brand hover:bg-bg-hover transition-colors",title:i("workers.action.open"),children:n.jsx(ct,{size:14})}),!e.manual&&n.jsx("button",{onClick:()=>t(e),className:"p-1.5 rounded-md text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors",title:i("workers.action.logs"),children:n.jsx(st,{size:14})}),!e.isCurrent&&n.jsx("button",{onClick:()=>r(e),className:"p-1.5 rounded-md text-text-tertiary daemon-kill-btn transition-colors",title:i("workers.action.kill"),children:n.jsx(Du,{size:14})})]})]}),n.jsxs("div",{className:"flex flex-col md:flex-row md:items-start justify-between gap-3 md:gap-6",children:[n.jsxs("div",{className:"flex flex-col gap-1.5 flex-1 min-w-0",children:[n.jsx(_t,{path:e.cwd,className:"text-[13px] text-text-secondary font-mono truncate max-w-full"}),e.url&&n.jsxs("a",{href:cu(e),target:"_blank",rel:"noopener noreferrer",className:"text-xs text-text-tertiary hover:text-accent-brand truncate inline-flex items-center gap-1",title:e.url,children:[n.jsx(ct,{size:10,className:"flex-none"}),e.url]})]}),n.jsxs("div",{className:"flex flex-wrap gap-x-8 gap-y-3 shrink-0",children:[n.jsx(Un,{icon:n.jsx(pr,{size:14}),label:"Started",value:TS(e.startedAt)}),e.version&&n.jsx(Un,{icon:n.jsx(Rt,{size:14}),label:"Version",value:e.version}),e.hostname&&n.jsx(Un,{icon:n.jsx(qr,{size:14}),label:"Host",value:e.hostname})]})]})]})}function Un({icon:e,label:t,value:r,valueClassName:i}){return n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-text-tertiary",children:[e,n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider",children:t})]}),n.jsx("div",{className:`text-sm font-semibold text-text-primary ${i||""}`,children:r})]})}function CS(e){try{const t=new URL(e).hostname;return t==="127.0.0.1"||t==="localhost"||t==="::1"}catch{return!1}}function cu(e){if(!e.url)return"#";if(CS(e.url))return e.url;const t=$v(String(e.pid));if(!t)return e.url;try{const r=new URL(e.url);return r.searchParams.set("password",t),r.toString()}catch{return e.url}}function TS(e){const t=Math.floor((Date.now()-e)/1e3);if(t<60)return`${t}s ago`;const r=Math.floor(t/60);if(r<60)return`${r}m ago`;const i=Math.floor(r/60);return i<24?`${i}h ${r%60}m`:`${Math.floor(i/24)}d ${i%24}h`}function NS(){const{viewState:e,checkAuth:t}=hu(),{status:r,sessionId:i,topic:s,setPromptSuggestion:l,setTopic:d}=rt(),{connect:a}=Th(),{clearChat:o}=Ze(),c=He(F=>F.focusedMemberName),{t:p,resolved:g}=ne(),[b,_]=C.useState(()=>{try{const F=sessionStorage.getItem("codebuddy_sidebar_open");return F!==null?window.innerWidth>=768?F==="true":!1:window.innerWidth>=768}catch{return window.innerWidth>=768}}),w=C.useRef(b),[v,h]=C.useState(!1),[m,u]=C.useState(!1),[f,x]=C.useState(!1),{splitPane:E,mainView:y,setMainView:S}=Te(),k=C.useCallback(F=>{_(N=>{const O=typeof F=="function"?F(N):F;w.current=O;try{sessionStorage.setItem("codebuddy_sidebar_open",String(O))}catch{}return O})},[]);C.useEffect(()=>{const F=window.matchMedia("(min-width: 768px)"),N=O=>{O.matches?_(w.current):_(!1)};return F.addEventListener("change",N),()=>F.removeEventListener("change",N)},[]),C.useEffect(()=>{const F=N=>ze.handleKeyDown(N);return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]),C.useEffect(()=>{r==="connected"&&Tc.getState().loadBindings()},[r]);const[T,R]=C.useState(!1),A=C.useRef();C.useEffect(()=>r!=="connected"?void 0:((()=>{fetch("/api/v1/sessions",{headers:ue()}).then(N=>N.ok?N.json():null).then(N=>{N!=null&&N.sessions&&R(N.sessions.length>1)}).catch(()=>{})})(),()=>{A.current&&clearTimeout(A.current)}),[r,i]);const D=C.useCallback(F=>{E(F)},[E]),L=C.useCallback(async()=>{if(i){try{await Ne().prompt(i,"/clear")}catch{lu.error(p("error.newChatFailed"))}o(),d(null),l(null),S("chat"),window.location.hash="/chat"}},[i,o,d,l,S]),B=C.useCallback(async F=>{if(i){try{await Ne().prompt(i,`/resume ${F}`)}catch{lu.error(p("error.switchSessionFailed"))}S("chat"),window.location.hash="/chat"}},[i,S]),P=C.useCallback(F=>{S(F),window.location.hash=`/${F}`,window.innerWidth<768&&_(!1)},[S]);if(C.useEffect(()=>{const F=[ze.register({id:"commandPalette.toggle",key:"p",meta:!0,shift:!0,handler:()=>x(N=>!N)}),ze.register({id:"sidebar.toggle",key:"b",meta:!0,handler:()=>k(N=>!N)}),ze.register({id:"terminal.toggle",key:"j",meta:!0,handler:()=>{const N=y==="terminal"?"chat":"terminal";S(N),window.location.hash="/"+N}}),ze.register({id:"newChat",key:"n",meta:!0,handler:()=>L()}),ze.register({id:"settings",key:",",meta:!0,handler:()=>{S("settings"),window.location.hash="/settings"}}),ze.registerAction("app:commandPalette",()=>x(N=>!N)),ze.registerAction("app:toggleSidebar",()=>k(N=>!N)),ze.registerAction("app:toggleTerminal",()=>{const N=y==="terminal"?"chat":"terminal";S(N),window.location.hash="/"+N}),ze.registerAction("app:newChat",()=>L()),ze.registerAction("app:settings",()=>{S("settings"),window.location.hash="/settings"}),ze.registerAction("app:focusInput",()=>{const N=document.querySelector("textarea");N==null||N.focus()}),ze.registerAction("app:keybindings",()=>{S("keybindings"),window.location.hash="/keybindings"})];return()=>F.forEach(N=>N())},[y,L,S,k]),C.useEffect(()=>{const F=new URLSearchParams(window.location.search),N=F.get("password"),O=F.get("token");if(N||O){pu(N||O),F.delete("password"),F.delete("token");const $=F.toString()?`${window.location.pathname}?${F.toString()}`:window.location.pathname;window.history.replaceState({},"",$)}t()},[t]),C.useEffect(()=>{if(e==="authenticated"){const F=Ec();S(F),(!window.location.hash||window.location.hash==="#")&&(window.location.hash=`/${F}`)}},[e,S]),C.useEffect(()=>My(N=>{S(N)}),[S]),C.useEffect(()=>{if(e==="authenticated"){const F=qt()||void 0;a({token:F,continue:!0})}},[e,a]),C.useEffect(()=>{document.documentElement.lang=g,document.title=s?`${s} - CodeBuddy Code`:p("page.title")},[g,p,s]),e==="loading")return n.jsx("div",{className:"flex h-screen h-[100dvh] bg-bg-primary text-text-primary transition-colors duration-200 font-sans overflow-hidden",children:n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx(nt,{size:"large",text:p("app.connecting")})})});if(e==="login")return n.jsx(Iv,{});const H=()=>{if(r==="connecting")return n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx(nt,{size:"large",text:p("app.connecting")})});if(r!=="connected"&&y!=="settings"&&y!=="docs")return n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsxs("div",{className:"text-center",children:[n.jsx("div",{className:"text-text-secondary mb-4 font-medium",children:p("app.connectFailed")}),n.jsx("button",{onClick:()=>a(),className:["px-6 py-2.5 bg-accent-brand text-white rounded-full","text-sm font-medium transition-all hover:bg-accent-brand/90","hover:scale-105 active:scale-95 shadow-sm"].join(" "),children:p("app.retry")})]})});switch(y){case"chat":return n.jsx(qe,{viewName:"chat",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex-1 overflow-hidden w-full relative",children:c?n.jsx(aS,{}):n.jsx(I_,{onClickCloseBottomSheet:()=>u(!1)})}),n.jsx(yS,{}),n.jsx("div",{className:"flex-none bg-bg-primary",children:n.jsx(Cv,{onNavigate:P,onNewChat:L,onHistory:()=>h(!0),mainView:y,showBottomSheet:m,setShowBottomSheet:u})})]})});case"tasks":return n.jsx(qe,{viewName:"tasks",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Xp,{})});case"plugins":return n.jsx(qe,{viewName:"plugins",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(zp,{})});case"terminal":return null;case"remote-control":return n.jsx(qe,{viewName:"remote-control",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Zv,{onNavigate:P})});case"editor":return n.jsx(qe,{viewName:"editor",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Fx,{onMenuClick:()=>k(F=>!F)})});case"changes":return n.jsx(qe,{viewName:"changes",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Ju,{onMenuClick:()=>k(F=>!F)})});case"settings":return n.jsx(qe,{viewName:"settings",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Gp,{})});case"keybindings":return n.jsx(qe,{viewName:"keybindings",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Nv,{})});case"metrics":return n.jsx(qe,{viewName:"metrics",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(qv,{})});case"workers":return n.jsx(qe,{viewName:"workers",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(vS,{})});case"logs":return n.jsx(qe,{viewName:"logs",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Pv,{})});case"docs":return n.jsx(qe,{viewName:"docs",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Pd,{})});default:return null}};return y==="docs"&&window.location.hash.includes("standalone")?n.jsx("div",{className:"flex h-screen h-[100dvh] bg-bg-primary text-text-primary transition-colors duration-200 font-sans overflow-hidden",children:n.jsx(Pd,{})}):n.jsxs("div",{className:"flex h-screen h-[100dvh] bg-bg-primary text-text-primary transition-colors duration-200 font-sans overflow-hidden",children:[n.jsx(nS,{isOpen:b,onClose:()=>k(!1),mainView:y,onNavigate:P}),n.jsxs("div",{className:"flex-1 flex flex-col min-w-0 relative transition-all duration-300 h-full",children:[y!=="editor"&&y!=="changes"&&n.jsx(iS,{onMenuClick:()=>k(F=>!F),onNewChat:L,onSplitTerminal:D,onHistory:()=>h(!0),hasHistory:T}),n.jsxs("div",{className:"flex-1 flex flex-col w-full overflow-hidden relative",children:[n.jsx("div",{className:"flex-1 flex flex-col w-full",style:{display:y==="terminal"?"flex":"none"},children:n.jsx(Jp,{})}),y!=="terminal"&&H()]}),n.jsx(Ux,{isOpen:v,onClose:()=>h(!1),onSwitchSession:B})]}),n.jsx(pS,{}),n.jsx(z_,{isOpen:f,onClose:()=>x(!1),onNavigate:P,onNewChat:L})]})}xh.createRoot(document.getElementById("root")).render(n.jsx(C.StrictMode,{children:n.jsx(qe,{children:n.jsx(NS,{})})}));
615
+ daemon-start-btn transition-all disabled:opacity-70`,children:[d==="start"?n.jsx(_e,{size:14,className:"animate-spin"}):n.jsx(Cg,{size:14}),s(d==="start"?"workers.daemon.starting":"workers.daemon.start")]})})]})})}function wS({workers:e,onViewLogs:t,onKill:r}){const{t:i}=ne();return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[n.jsx(Rt,{size:18,className:"text-text-secondary"}),n.jsxs("h2",{className:"text-base font-medium text-text-primary",children:[i("workers.active")," (",e.length,")"]})]}),e.length===0?n.jsx("div",{className:"text-center py-12 text-text-tertiary",children:i("workers.empty")}):n.jsx("div",{className:"space-y-4",children:[...e].sort((s,l)=>(l.isCurrent?1:0)-(s.isCurrent?1:0)).map(s=>n.jsx(CS,{worker:s,onViewLogs:t,onKill:r},`${s.pid}-${s.hostname}`))})]})}const ES={interactive:"kind-badge kind-badge-blue",bg:"kind-badge kind-badge-purple",daemon:"kind-badge kind-badge-green","daemon-worker":"kind-badge kind-badge-orange"};function CS({worker:e,onViewLogs:t,onKill:r}){const{t:i}=ne();return n.jsxs("div",{className:"group bg-bg-secondary rounded-xl p-4 md:p-5 border border-border-default transition-colors worker-card-hover",children:[n.jsxs("div",{className:"flex items-center justify-between mb-3",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("span",{className:`inline-block px-2.5 py-0.5 text-xs font-medium rounded-md ${ES[e.kind]||"bg-gray-100 text-gray-600"}`,children:e.kind}),e.isCurrent&&n.jsx("span",{className:"text-[10px] uppercase font-bold tracking-wider px-1.5 py-0.5 rounded current-badge",children:"current"}),n.jsxs("span",{className:"text-xs text-text-tertiary font-mono",children:["PID ",e.pid]}),e.name&&e.name!=="-"&&n.jsx("span",{className:"text-sm font-medium text-text-primary",children:e.name})]}),n.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.url&&n.jsx("a",{href:cu(e),target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-md text-text-tertiary hover:text-accent-brand hover:bg-bg-hover transition-colors",title:i("workers.action.open"),children:n.jsx(ct,{size:14})}),!e.manual&&n.jsx("button",{onClick:()=>t(e),className:"p-1.5 rounded-md text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors",title:i("workers.action.logs"),children:n.jsx(st,{size:14})}),!e.isCurrent&&n.jsx("button",{onClick:()=>r(e),className:"p-1.5 rounded-md text-text-tertiary daemon-kill-btn transition-colors",title:i("workers.action.kill"),children:n.jsx(Du,{size:14})})]})]}),n.jsxs("div",{className:"flex flex-col md:flex-row md:items-start justify-between gap-3 md:gap-6",children:[n.jsxs("div",{className:"flex flex-col gap-1.5 flex-1 min-w-0",children:[n.jsx(_t,{path:e.cwd,className:"text-[13px] text-text-secondary font-mono truncate max-w-full"}),e.url&&n.jsxs("a",{href:cu(e),target:"_blank",rel:"noopener noreferrer",className:"text-xs text-text-tertiary hover:text-accent-brand truncate inline-flex items-center gap-1",title:e.url,children:[n.jsx(ct,{size:10,className:"flex-none"}),e.url]})]}),n.jsxs("div",{className:"flex flex-wrap gap-x-8 gap-y-3 shrink-0",children:[n.jsx(Un,{icon:n.jsx(pr,{size:14}),label:"Started",value:NS(e.startedAt)}),e.version&&n.jsx(Un,{icon:n.jsx(Rt,{size:14}),label:"Version",value:e.version}),e.hostname&&n.jsx(Un,{icon:n.jsx(qr,{size:14}),label:"Host",value:e.hostname})]})]})]})}function Un({icon:e,label:t,value:r,valueClassName:i}){return n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-text-tertiary",children:[e,n.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider",children:t})]}),n.jsx("div",{className:`text-sm font-semibold text-text-primary ${i||""}`,children:r})]})}function TS(e){try{const t=new URL(e).hostname;return t==="127.0.0.1"||t==="localhost"||t==="::1"}catch{return!1}}function cu(e){if(!e.url)return"#";const t=_S(e.url);if(TS(t))return t;const r=$v(String(e.pid));if(!r)return t;try{const i=new URL(t);return i.searchParams.set("password",r),i.toString()}catch(i){return console.warn("Failed to build worker URL with password:",t,i),t}}function NS(e){const t=Math.floor((Date.now()-e)/1e3);if(t<60)return`${t}s ago`;const r=Math.floor(t/60);if(r<60)return`${r}m ago`;const i=Math.floor(r/60);return i<24?`${i}h ${r%60}m`:`${Math.floor(i/24)}d ${i%24}h`}function AS(){const{viewState:e,checkAuth:t}=hu(),{status:r,sessionId:i,topic:s,setPromptSuggestion:l,setTopic:d}=rt(),{connect:a}=Th(),{clearChat:o}=Ze(),c=He(F=>F.focusedMemberName),{t:p,resolved:g}=ne(),[b,_]=C.useState(()=>{try{const F=sessionStorage.getItem("codebuddy_sidebar_open");return F!==null?window.innerWidth>=768?F==="true":!1:window.innerWidth>=768}catch{return window.innerWidth>=768}}),w=C.useRef(b),[v,h]=C.useState(!1),[m,u]=C.useState(!1),[f,x]=C.useState(!1),{splitPane:E,mainView:y,setMainView:S}=Te(),k=C.useCallback(F=>{_(N=>{const O=typeof F=="function"?F(N):F;w.current=O;try{sessionStorage.setItem("codebuddy_sidebar_open",String(O))}catch{}return O})},[]);C.useEffect(()=>{const F=window.matchMedia("(min-width: 768px)"),N=O=>{O.matches?_(w.current):_(!1)};return F.addEventListener("change",N),()=>F.removeEventListener("change",N)},[]),C.useEffect(()=>{const F=N=>ze.handleKeyDown(N);return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[]),C.useEffect(()=>{r==="connected"&&Tc.getState().loadBindings()},[r]);const[T,R]=C.useState(!1),A=C.useRef();C.useEffect(()=>r!=="connected"?void 0:((()=>{fetch("/api/v1/sessions",{headers:ue()}).then(N=>N.ok?N.json():null).then(N=>{N!=null&&N.sessions&&R(N.sessions.length>1)}).catch(()=>{})})(),()=>{A.current&&clearTimeout(A.current)}),[r,i]);const D=C.useCallback(F=>{E(F)},[E]),L=C.useCallback(async()=>{if(i){try{await Ne().prompt(i,"/clear")}catch{lu.error(p("error.newChatFailed"))}o(),d(null),l(null),S("chat"),window.location.hash="/chat"}},[i,o,d,l,S]),B=C.useCallback(async F=>{if(i){try{await Ne().prompt(i,`/resume ${F}`)}catch{lu.error(p("error.switchSessionFailed"))}S("chat"),window.location.hash="/chat"}},[i,S]),P=C.useCallback(F=>{S(F),window.location.hash=`/${F}`,window.innerWidth<768&&_(!1)},[S]);if(C.useEffect(()=>{const F=[ze.register({id:"commandPalette.toggle",key:"p",meta:!0,shift:!0,handler:()=>x(N=>!N)}),ze.register({id:"sidebar.toggle",key:"b",meta:!0,handler:()=>k(N=>!N)}),ze.register({id:"terminal.toggle",key:"j",meta:!0,handler:()=>{const N=y==="terminal"?"chat":"terminal";S(N),window.location.hash="/"+N}}),ze.register({id:"newChat",key:"n",meta:!0,handler:()=>L()}),ze.register({id:"settings",key:",",meta:!0,handler:()=>{S("settings"),window.location.hash="/settings"}}),ze.registerAction("app:commandPalette",()=>x(N=>!N)),ze.registerAction("app:toggleSidebar",()=>k(N=>!N)),ze.registerAction("app:toggleTerminal",()=>{const N=y==="terminal"?"chat":"terminal";S(N),window.location.hash="/"+N}),ze.registerAction("app:newChat",()=>L()),ze.registerAction("app:settings",()=>{S("settings"),window.location.hash="/settings"}),ze.registerAction("app:focusInput",()=>{const N=document.querySelector("textarea");N==null||N.focus()}),ze.registerAction("app:keybindings",()=>{S("keybindings"),window.location.hash="/keybindings"})];return()=>F.forEach(N=>N())},[y,L,S,k]),C.useEffect(()=>{const F=new URLSearchParams(window.location.search),N=F.get("password"),O=F.get("token");if(N||O){pu(N||O),F.delete("password"),F.delete("token");const $=F.toString()?`${window.location.pathname}?${F.toString()}`:window.location.pathname;window.history.replaceState({},"",$)}t()},[t]),C.useEffect(()=>{if(e==="authenticated"){const F=Ec();S(F),(!window.location.hash||window.location.hash==="#")&&(window.location.hash=`/${F}`)}},[e,S]),C.useEffect(()=>My(N=>{S(N)}),[S]),C.useEffect(()=>{if(e==="authenticated"){const F=qt()||void 0;a({token:F,continue:!0})}},[e,a]),C.useEffect(()=>{document.documentElement.lang=g,document.title=s?`${s} - CodeBuddy Code`:p("page.title")},[g,p,s]),e==="loading")return n.jsx("div",{className:"flex h-screen h-[100dvh] bg-bg-primary text-text-primary transition-colors duration-200 font-sans overflow-hidden",children:n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx(nt,{size:"large",text:p("app.connecting")})})});if(e==="login")return n.jsx(Iv,{});const H=()=>{if(r==="connecting")return n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsx(nt,{size:"large",text:p("app.connecting")})});if(r!=="connected"&&y!=="settings"&&y!=="docs")return n.jsx("div",{className:"flex-1 flex items-center justify-center",children:n.jsxs("div",{className:"text-center",children:[n.jsx("div",{className:"text-text-secondary mb-4 font-medium",children:p("app.connectFailed")}),n.jsx("button",{onClick:()=>a(),className:["px-6 py-2.5 bg-accent-brand text-white rounded-full","text-sm font-medium transition-all hover:bg-accent-brand/90","hover:scale-105 active:scale-95 shadow-sm"].join(" "),children:p("app.retry")})]})});switch(y){case"chat":return n.jsx(qe,{viewName:"chat",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"flex-1 overflow-hidden w-full relative",children:c?n.jsx(aS,{}):n.jsx(I_,{onClickCloseBottomSheet:()=>u(!1)})}),n.jsx(yS,{}),n.jsx("div",{className:"flex-none bg-bg-primary",children:n.jsx(Cv,{onNavigate:P,onNewChat:L,onHistory:()=>h(!0),mainView:y,showBottomSheet:m,setShowBottomSheet:u})})]})});case"tasks":return n.jsx(qe,{viewName:"tasks",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Xp,{})});case"plugins":return n.jsx(qe,{viewName:"plugins",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(zp,{})});case"terminal":return null;case"remote-control":return n.jsx(qe,{viewName:"remote-control",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Zv,{onNavigate:P})});case"editor":return n.jsx(qe,{viewName:"editor",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Fx,{onMenuClick:()=>k(F=>!F)})});case"changes":return n.jsx(qe,{viewName:"changes",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Ju,{onMenuClick:()=>k(F=>!F)})});case"settings":return n.jsx(qe,{viewName:"settings",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Gp,{})});case"keybindings":return n.jsx(qe,{viewName:"keybindings",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Nv,{})});case"metrics":return n.jsx(qe,{viewName:"metrics",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(qv,{})});case"workers":return n.jsx(qe,{viewName:"workers",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(SS,{})});case"logs":return n.jsx(qe,{viewName:"logs",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Pv,{})});case"docs":return n.jsx(qe,{viewName:"docs",errorTitle:p("error.viewCrashed"),retryLabel:p("app.retry"),children:n.jsx(Pd,{})});default:return null}};return y==="docs"&&window.location.hash.includes("standalone")?n.jsx("div",{className:"flex h-screen h-[100dvh] bg-bg-primary text-text-primary transition-colors duration-200 font-sans overflow-hidden",children:n.jsx(Pd,{})}):n.jsxs("div",{className:"flex h-screen h-[100dvh] bg-bg-primary text-text-primary transition-colors duration-200 font-sans overflow-hidden",children:[n.jsx(nS,{isOpen:b,onClose:()=>k(!1),mainView:y,onNavigate:P}),n.jsxs("div",{className:"flex-1 flex flex-col min-w-0 relative transition-all duration-300 h-full",children:[y!=="editor"&&y!=="changes"&&n.jsx(iS,{onMenuClick:()=>k(F=>!F),onNewChat:L,onSplitTerminal:D,onHistory:()=>h(!0),hasHistory:T}),n.jsxs("div",{className:"flex-1 flex flex-col w-full overflow-hidden relative",children:[n.jsx("div",{className:"flex-1 flex flex-col w-full",style:{display:y==="terminal"?"flex":"none"},children:n.jsx(Jp,{})}),y!=="terminal"&&H()]}),n.jsx(Ux,{isOpen:v,onClose:()=>h(!1),onSwitchSession:B})]}),n.jsx(pS,{}),n.jsx(z_,{isOpen:f,onClose:()=>x(!1),onNavigate:P,onNewChat:L})]})}xh.createRoot(document.getElementById("root")).render(n.jsx(C.StrictMode,{children:n.jsx(qe,{children:n.jsx(AS,{})})}));
@@ -18,7 +18,7 @@
18
18
  <link rel="preconnect" href="https://fonts.googleapis.com">
19
19
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
20
20
  <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
21
- <script type="module" crossorigin src="/assets/index-CoP0gamp.js"></script>
21
+ <script type="module" crossorigin src="/assets/index-B3kQit7h.js"></script>
22
22
  <link rel="modulepreload" crossorigin href="/assets/markdown-Ce2Umeb2.js">
23
23
  <link rel="modulepreload" crossorigin href="/assets/vendor-DpYitQz5.js">
24
24
  <link rel="stylesheet" crossorigin href="/assets/index-r9a-SZcP.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencent-ai/codebuddy-code",
3
- "version": "2.83.0",
3
+ "version": "2.83.1-next.a0f9c9d.20260411",
4
4
  "description": "Use CodeBuddy, Tencent's AI assistant, right from your terminal. CodeBuddy can understand your codebase, edit files, run terminal commands, and handle entire workflows for you.",
5
5
  "main": "lib/node/index.js",
6
6
  "typings": "lib/node/index.d.ts",
@@ -29,7 +29,8 @@
29
29
  "url": "https://cnb.cool/codebuddy/codebuddy-code/-/issues"
30
30
  },
31
31
  "publishConfig": {
32
- "access": "public"
32
+ "access": "public",
33
+ "tag": "next"
33
34
  },
34
35
  "scripts": {},
35
36
  "devDependencies": {},
@@ -421,6 +421,6 @@
421
421
  "ImageGen": true,
422
422
  "ScheduledTasks": true
423
423
  },
424
- "commit": "d1a9d14926c3ae999260efe38a3266851e0918e2",
425
- "date": "2026-04-10T07:15:33.533Z"
424
+ "commit": "a0f9c9d77e8c9b57c8acbbf8406a126821968fc0",
425
+ "date": "2026-04-11T10:16:45.589Z"
426
426
  }
@@ -588,6 +588,6 @@
588
588
  }
589
589
  }
590
590
  },
591
- "commit": "d1a9d14926c3ae999260efe38a3266851e0918e2",
592
- "date": "2026-04-10T07:15:33.587Z"
591
+ "commit": "a0f9c9d77e8c9b57c8acbbf8406a126821968fc0",
592
+ "date": "2026-04-11T10:16:45.516Z"
593
593
  }
package/product.ioa.json CHANGED
@@ -955,6 +955,6 @@
955
955
  }
956
956
  }
957
957
  },
958
- "commit": "d1a9d14926c3ae999260efe38a3266851e0918e2",
959
- "date": "2026-04-10T07:15:33.507Z"
958
+ "commit": "a0f9c9d77e8c9b57c8acbbf8406a126821968fc0",
959
+ "date": "2026-04-11T10:16:45.723Z"
960
960
  }
package/product.json CHANGED
@@ -1510,6 +1510,6 @@
1510
1510
  "description": "Send a reply to a WeCom (企业微信) user. For text: pass text (markdown supported)."
1511
1511
  }
1512
1512
  ],
1513
- "commit": "d1a9d14926c3ae999260efe38a3266851e0918e2",
1514
- "date": "2026-04-10T07:15:33.634Z"
1513
+ "commit": "a0f9c9d77e8c9b57c8acbbf8406a126821968fc0",
1514
+ "date": "2026-04-11T10:16:45.644Z"
1515
1515
  }
@@ -310,6 +310,6 @@
310
310
  "DeferToolLoading": true,
311
311
  "ScheduledTasks": true
312
312
  },
313
- "commit": "d1a9d14926c3ae999260efe38a3266851e0918e2",
314
- "date": "2026-04-10T07:15:33.593Z"
313
+ "commit": "a0f9c9d77e8c9b57c8acbbf8406a126821968fc0",
314
+ "date": "2026-04-11T10:16:45.533Z"
315
315
  }