@wrongstack/webui 0.282.0 → 0.282.2

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.
Files changed (47) hide show
  1. package/dist/assets/{AnalyticsDashboard-BrQc2ss-.js → AnalyticsDashboard-CPLSpHzV.js} +1 -1
  2. package/dist/assets/{AutoPhaseView-8NTdnZ0a.js → AutoPhaseView-HIzNPExo.js} +1 -1
  3. package/dist/assets/{CodeEditor-C-pJLtUR.js → CodeEditor-dOQDoCfn.js} +1 -1
  4. package/dist/assets/{DebugDashboard-BHpiEOcf.js → DebugDashboard-CQCI-B4W.js} +1 -1
  5. package/dist/assets/{DesignGalleryView-M6Hp7s9b.js → DesignGalleryView-BxTlrmrr.js} +1 -1
  6. package/dist/assets/{KanbanView-nMv98m0N.js → KanbanView-2uDRr6Qd.js} +1 -1
  7. package/dist/assets/{MailboxDetailView-g3IQx4DB.js → MailboxDetailView-B0DCs5lu.js} +1 -1
  8. package/dist/assets/OfficeMapPanel-lGSaptet.js +4 -0
  9. package/dist/assets/{ProcessMonitor-CbfQYneY.js → ProcessMonitor-eTb8_-ZW.js} +1 -1
  10. package/dist/assets/{QueuePanel-eGK1SSKx.js → QueuePanel-TbbkNAx_.js} +1 -1
  11. package/dist/assets/{RefreshDebugView-BXq2P3wo.js → RefreshDebugView-CX6x-xHs.js} +1 -1
  12. package/dist/assets/SddBoardView-BXQsH6fr.js +2 -0
  13. package/dist/assets/{SddFlowGraph-CtMpzU4S.js → SddFlowGraph-DTWV-DPB.js} +1 -1
  14. package/dist/assets/SddWizard-1ZhDgcgM.js +1 -0
  15. package/dist/assets/{SessionsDashboard-Dqsrp5CK.js → SessionsDashboard-CfNbqjeh.js} +1 -1
  16. package/dist/assets/SkillDetailView-UzixISza.js +2 -0
  17. package/dist/assets/{SpecsView-BnUsqkrG.js → SpecsView-BO8yG6ID.js} +1 -1
  18. package/dist/assets/{TerminalPanel-BCpddej2.js → TerminalPanel-Bjbu9ktV.js} +1 -1
  19. package/dist/assets/{chat-store-CIMOL6-x.js → chat-store-7ekEnPAf.js} +1 -1
  20. package/dist/assets/{i18n-CNo6A2vu.js → i18n-BCQuDmQo.js} +2 -2
  21. package/dist/assets/index-Cb-hw9qG.js +147 -0
  22. package/dist/assets/index-ZtF5f7wy.css +1 -0
  23. package/dist/assets/{session-store-DN1UYDL9.js → session-store-KCJiKVqL.js} +1 -1
  24. package/dist/assets/settings-wb322bGN.js +1 -0
  25. package/dist/assets/{ui-store-BdOsq6T-.js → ui-store-CcznRsiV.js} +1 -1
  26. package/dist/assets/utils-C3qJEm2b.js +1 -0
  27. package/dist/assets/{vendor-Ch4m_qLI.js → vendor-Cm3Womkr.js} +25 -25
  28. package/dist/assets/{ws-client-BAV7SLzK.js → ws-client-9j1mjm9I.js} +1 -1
  29. package/dist/assets/{xyflow-D5_yey7w.js → xyflow-Dy5Edi88.js} +3 -3
  30. package/dist/index.html +10 -10
  31. package/dist/index.js +4168 -3743
  32. package/dist/index.js.map +1 -1
  33. package/dist/providers.json +2 -2
  34. package/dist/server/entry.js +342 -16
  35. package/dist/server/entry.js.map +1 -1
  36. package/dist/server/index.js +342 -16
  37. package/dist/server/index.js.map +1 -1
  38. package/dist/types.d.ts +28 -0
  39. package/package.json +6 -6
  40. package/dist/assets/OfficeMapPanel-D3VE7UCd.js +0 -4
  41. package/dist/assets/SddBoardView-DvuH4f4e.js +0 -2
  42. package/dist/assets/SddWizard-G55Yw9Bb.js +0 -1
  43. package/dist/assets/SkillDetailView-CX9zeWBG.js +0 -2
  44. package/dist/assets/index-BhO3caLf.js +0 -146
  45. package/dist/assets/index-D7_FeyCA.css +0 -1
  46. package/dist/assets/settings-CGhOOFpI.js +0 -1
  47. package/dist/assets/utils-DBns3uMk.js +0 -1
@@ -1,146 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProcessMonitor-CbfQYneY.js","assets/rolldown-runtime-QTnfLwEv.js","assets/markdown-D0X23O-i.js","assets/vendor-Ch4m_qLI.js","assets/vendor-CcOzUMQS.css","assets/i18n-CNo6A2vu.js","assets/activity-DT93tsyC.js","assets/chat-DCAGDU3F.js","assets/commandPalette-DUootORZ.js","assets/common-D7usadq4.js","assets/settings-CGhOOFpI.js","assets/setup-Dr2UDb8s.js","assets/toasts-BL_8kH4B.js","assets/monaco-DqY9Mr3N.js","assets/monaco-Br_kD0ds.css","assets/utils-DBns3uMk.js","assets/ws-client-BAV7SLzK.js","assets/session-store-DN1UYDL9.js","assets/AnalyticsDashboard-BrQc2ss-.js","assets/AutoPhaseView-8NTdnZ0a.js","assets/chat-store-CIMOL6-x.js","assets/CodeEditor-C-pJLtUR.js","assets/DebugDashboard-BHpiEOcf.js","assets/DesignGalleryView-M6Hp7s9b.js","assets/MailboxDetailView-g3IQx4DB.js","assets/ui-store-BdOsq6T-.js","assets/KanbanView-nMv98m0N.js","assets/OfficeMapPanel-D3VE7UCd.js","assets/xyflow-D5_yey7w.js","assets/xyflow-DtxX27Jz.css","assets/QueuePanel-eGK1SSKx.js","assets/RefreshDebugView-BXq2P3wo.js","assets/SddBoardView-DvuH4f4e.js","assets/SddFlowGraph-CtMpzU4S.js","assets/SddWizard-G55Yw9Bb.js","assets/SessionsDashboard-Dqsrp5CK.js","assets/SkillDetailView-CX9zeWBG.js","assets/SpecsView-BnUsqkrG.js","assets/TerminalPanel-BCpddej2.js","assets/xterm-B9RXJkIu.js","assets/xterm-BrP-ENHg.css"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{i as t,n,r,t as i}from"./chat-store-CIMOL6-x.js";import{c as a,m as o,o as s,p as c,s as l}from"./markdown-D0X23O-i.js";import{$ as u,$n as d,$r as f,$t as p,A as m,An as h,At as g,B as _,Bn as v,Br as y,Bt as b,C as x,Cn as S,Ct as C,D as w,Dn as T,Dr as E,Dt as D,E as O,En as k,Er as A,Et as j,F as M,Fn as N,Ft as P,G as F,Gn as I,Gt as L,H as ee,Hn as te,Hr as ne,Ht as re,I as ie,In as ae,Ir as oe,It as se,Jn as ce,Jr as le,K as ue,Kn as de,Kr as fe,Kt as pe,L as me,Ln as he,Lr as ge,Lt as _e,M as ve,Mn as ye,Mr as be,Mt as xe,N as Se,Nn as Ce,Nr as we,Nt as Te,O as Ee,On as De,Ot as Oe,P as ke,Pn as Ae,Pr as je,Pt as Me,Q as Ne,Qn as Pe,Qr as Fe,R as Ie,Rn as Le,Rr as Re,Rt as ze,S as Be,Sn as Ve,Sr as He,St as Ue,T as We,Tn as Ge,U as Ke,Un as qe,Ur as Je,Ut as Ye,V as Xe,Vn as Ze,Vr as R,Vt as Qe,W as $e,Wn as et,Wr as tt,Wt as nt,X as rt,Xn as it,Xr as at,Xt as ot,Yn as st,Yr as ct,Yt as lt,Z as ut,Zn as dt,Zr as ft,Zt as pt,_ as mt,_n as ht,_r as gt,_t,ai as vt,an as yt,ar as bt,at as xt,b as St,bn as Ct,br as wt,bt as Tt,ci as z,cn as Et,cr as Dt,di as B,dn as Ot,dr as kt,dt as At,ei as jt,en as Mt,er as Nt,et as Pt,fi as Ft,fr as It,ft as Lt,g as Rt,gn as zt,gr as Bt,gt as Vt,h as Ht,hr as Ut,ii as Wt,in as Gt,ir as Kt,it as qt,j as Jt,jn as Yt,jr as Xt,jt as Zt,k as Qt,kn as $t,kr as en,kt as tn,ln as nn,lr as rn,lt as an,m as on,mn as sn,mr as cn,mt as ln,ni as un,nn as dn,nr as fn,nt as pn,oi as mn,on as hn,or as gn,pn as _n,pr as vn,pt as yn,q as bn,qn as V,qr as xn,qt as Sn,ri as Cn,rn as wn,rr as Tn,rt as En,si as Dn,sn as On,sr as kn,st as An,ti as jn,tn as Mn,tr as Nn,tt as Pn,un as Fn,ur as In,ut as Ln,v as Rn,vr as zn,vt as Bn,w as Vn,wr as Hn,wt as Un,x as Wn,xn as Gn,y as Kn,yn as qn,yr as Jn,yt as Yn,z as Xn,zr as Zn}from"./vendor-Ch4m_qLI.js";import{n as Qn,t as $n}from"./i18n-CNo6A2vu.js";import{c as er,i as tr,l as nr,s as rr,t as ir}from"./monaco-DqY9Mr3N.js";import{a as ar,c as or,i as H,l as sr,o as cr,r as lr,s as ur,t as U}from"./ws-client-BAV7SLzK.js";import{t as W}from"./session-store-DN1UYDL9.js";import{n as G,t as dr}from"./ui-store-BdOsq6T-.js";import{t as K}from"./utils-DBns3uMk.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var q=e(o(),1),fr=e(Ft(),1),pr=`#4f46e5`;function mr(e){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
3
- <rect x="2" y="2" width="60" height="60" rx="14" fill="${pr}" />
4
- <text x="32" y="44" text-anchor="middle" font-family="-apple-system,Segoe UI,Roboto,sans-serif" font-size="38" font-weight="700" fill="#fff">W</text>
5
- ${e===`ready`?`<circle cx="50" cy="14" r="14" fill="#22c55e" stroke="#fff" stroke-width="3" />`:e===`error`?`<circle cx="50" cy="14" r="14" fill="#ef4444" stroke="#fff" stroke-width="3" />`:e===`running`?`<circle cx="50" cy="14" r="14" fill="#f59e0b" stroke="#fff" stroke-width="3" />`:e===`attention`?`<circle cx="50" cy="14" r="14" fill="#eab308" stroke="#fff" stroke-width="3"><animate attributeName="opacity" values="1;0.3;1" dur="1s" repeatCount="indefinite"/></circle>`:``}
6
- </svg>`}function hr(e){return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`}function gr(){if(typeof document>`u`)return null;let e=document.querySelector(`link[rel="icon"]`);return e||(e=document.createElement(`link`),e.rel=`icon`,e.type=`image/svg+xml`,document.head.appendChild(e)),e}var _r=`idle`;function vr(e){_r=e;let t=gr();t&&(t.href=hr(mr(e)))}var yr=!1;function br(){yr||typeof document>`u`||(yr=!0,document.addEventListener(`visibilitychange`,()=>{!document.hidden&&(_r===`ready`||_r===`error`||_r===`attention`)&&vr(`idle`)}))}var xr=Dn()(e=>({phases:[],activePhaseId:null,overallPercent:0,autonomous:!1,title:null,goal:null,status:`idle`,lastEvent:null,lastError:null,graphs:[],progress:null,setState:t=>e(e=>({phases:t.phases??e.phases,activePhaseId:t.activePhaseId===void 0?e.activePhaseId:t.activePhaseId,overallPercent:t.overallPercent??e.overallPercent,autonomous:t.autonomous??e.autonomous,title:t.title===void 0?e.title:t.title,goal:t.goal===void 0?e.goal:t.goal,status:t.status??e.status,lastEvent:t.lastEvent===void 0?e.lastEvent:t.lastEvent,lastError:t.lastError===void 0?e.lastError:t.lastError,graphs:t.graphs??e.graphs,progress:t.progress===void 0?e.progress:t.progress})),clear:()=>e({phases:[],activePhaseId:null,overallPercent:0,autonomous:!1,title:null,goal:null,status:`idle`,lastEvent:null,lastError:null,graphs:[],progress:null}),hydrateFromServer:e=>{e({type:`autophase.list`}),e({type:`autophase.state`})}})),J=Dn()(mn(e=>({provider:`anthropic`,model:`claude-sonnet-4-20250514`,wsUrl:lr(),wsConnected:!1,wsStatus:{state:`connecting`},theme:`system`,autoConnect:!0,soundOnComplete:!1,setProvider:t=>e({provider:t}),setModel:t=>e({model:t}),setConfig:t=>e(t),setTheme:t=>e({theme:t}),setWsConnected:t=>e({wsConnected:t}),setWsStatus:t=>e({wsStatus:t,wsConnected:t.state===`open`}),setSoundOnComplete:t=>e({soundOnComplete:t})}),{name:`wrongstack-config`,partialize:e=>({provider:e.provider,model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,theme:e.theme,autoConnect:e.autoConnect,soundOnComplete:e.soundOnComplete}),merge:(e,t)=>({...t,...e,wsUrl:lr(),wsConnected:!1,wsStatus:{state:`connecting`}})}));function Sr(e,t){return t>=100?`danger`:`warning`}function Cr(e,t){switch(e){case`budget.threshold_reached`:{let e=t,n=e.limit>0?Math.round(e.used/e.limit*100):0;return`${e.subagentId} [${e.kind}] ${n}% (${e.used}/${e.limit})`}case`budget.decision`:{let e=t;return`${e.subagentId} [${e.kind}] → ${e.decision}`}case`consensus.vote_initiated`:{let e=t;return`Vote: "${e.title}" — ${e.eligible.length} voters`}case`consensus.vote_cast`:{let e=t;return`${e.voterId} voted ${e.value}`}case`consensus.vote_resolved`:{let e=t;return`${e.result} — ✅${e.approveCount} ❌${e.rejectCount}`}case`task.pending`:return`Task queued: "${t.description.slice(0,60)}"`;case`task.started`:{let e=t;return`${e.subagentId} started ${e.taskId}`}case`task.completed`:{let e=t;return`Task ${e.taskId} ${e.status} (${e.durationMs}ms)`}case`task.failed`:{let e=t;return`Task ${e.taskId} failed: ${e.error.slice(0,60)}`}case`subagent.budget_extended`:{let e=t;return`${e.subagentId} [${e.kind}] extended → ${e.extendedTo}ms`}default:return e}}var wr=200,Tr=50,Er=300,Dr=200,Or=100;function kr(e,t,n){if(!(e.size<=t)){if(n)for(let[r,i]of e){if(e.size<=t)break;n(i)&&e.delete(r)}for(let n of e.keys()){if(e.size<=t)break;e.delete(n)}}}var Ar=Dn()(e=>({coordinatorStatus:`idle`,subagents:new Map,events:[],consensusVotes:new Map,tasks:new Map,taskCounts:{pending:0,running:0,completed:0,failed:0},budgetAlerts:[],lastUpdated:Date.now(),setCoordinatorStatus:(t,n)=>e(e=>({coordinatorStatus:t,coordinatorMode:n,lastUpdated:Date.now()})),updateCoordinatorStats:t=>e(e=>{let n=new Map(e.subagents);for(let e of t.subagentStatuses??[]){let t=n.get(e.id);n.set(e.id,{id:e.id,name:e.name,role:t?.role??`agent`,status:e.status,currentTask:e.currentTask,budgetLimits:t?.budgetLimits,budgetUsage:t?.budgetUsage,lastSeen:t?.lastSeen??Date.now()})}return kr(n,Dr,e=>e.status===`stopped`),{subagents:n,taskCounts:{pending:t.pending,running:t.inFlight,completed:t.completed,failed:0},lastUpdated:Date.now()}}),updateSubagentBudget:(t,n)=>e(e=>{let r=new Map(e.subagents),i=r.get(t);return r.set(t,{id:t,name:i?.name??t,role:i?.role??`agent`,status:i?.status??`idle`,...i,...n,lastSeen:Date.now()}),kr(r,Dr,e=>e.status===`stopped`),{subagents:r,lastUpdated:Date.now()}}),pushEvent:(t,n,r,i,a)=>e(e=>{let o=n.kind??t,s=(t.includes(`budget`)||t.includes(`threshold`))&&typeof n.limit==`number`&&n.limit>0?Math.round(n.used/n.limit*100):void 0,c=s===void 0?t.includes(`consensus.vote_resolved`)?`info`:t.includes(`consensus.vote_initiated`)?`warning`:`info`:s>=100?`danger`:s>=85?`warning`:`info`;return{events:[{id:`${r}-${t}`,ts:r,type:t,subagentId:i,taskId:a,payload:n,kind:o,level:c,message:Cr(t,n)},...e.events].slice(0,wr),lastUpdated:Date.now()}}),pushConsensusVote:(t,n,r)=>e(e=>{let i=new Map(e.consensusVotes);return i.set(t,{changeId:t,title:n,status:`pending`,eligible:r,votes:[],approveCount:0,rejectCount:0,abstainCount:0,expiresAt:Date.now()+300*1e3}),kr(i,Or,e=>e.status!==`pending`),{consensusVotes:i,lastUpdated:Date.now()}}),recordConsensusVote:(t,n,r,i)=>e(e=>{let a=new Map(e.consensusVotes),o=a.get(t);if(!o)return{};let s={...o,votes:[...o.votes.filter(e=>e.agentId!==n),{agentId:n,agentName:r,value:i,votedAt:Date.now()}],approveCount:i===`approve`?o.approveCount+1:o.approveCount,rejectCount:i===`reject`?o.rejectCount+1:o.rejectCount,abstainCount:i===`abstain`?o.abstainCount+1:o.abstainCount};return a.set(t,s),{consensusVotes:a,lastUpdated:Date.now()}}),resolveConsensusVote:(t,n,r,i)=>e(e=>{let a=new Map(e.consensusVotes),o=a.get(t);return o?(a.set(t,{...o,status:n,approveCount:r,rejectCount:i,resolvedAt:Date.now()}),{consensusVotes:a,lastUpdated:Date.now()}):{}}),pushTaskPending:(t,n,r)=>e(e=>{let i=new Map(e.tasks);return i.set(t,{id:t,description:n,status:`pending`,priority:r,queuedAt:Date.now()}),kr(i,Er,e=>e.status===`completed`||e.status===`failed`),{tasks:i,taskCounts:{...e.taskCounts,pending:e.taskCounts.pending+1},lastUpdated:Date.now()}}),startTask:(t,n)=>e(e=>{let r=new Map(e.tasks),i=r.get(t);return i?r.set(t,{...i,status:`running`,subagentId:n,startedAt:Date.now()}):r.set(t,{id:t,description:``,status:`running`,subagentId:n,startedAt:Date.now()}),{tasks:r,taskCounts:{...e.taskCounts,pending:Math.max(0,e.taskCounts.pending-1),running:e.taskCounts.running+1},lastUpdated:Date.now()}}),completeTask:(t,n,r)=>e(e=>{let i=new Map(e.tasks),a=i.get(t);return a&&i.set(t,{...a,status:n,completedAt:Date.now(),durationMs:r}),kr(i,Er,e=>e.status===`completed`||e.status===`failed`),{tasks:i,taskCounts:{...e.taskCounts,running:Math.max(0,e.taskCounts.running-1),completed:n===`completed`?e.taskCounts.completed+1:e.taskCounts.completed,failed:n===`failed`?e.taskCounts.failed+1:e.taskCounts.failed},lastUpdated:Date.now()}}),failTask:(t,n)=>e(e=>{let r=new Map(e.tasks),i=r.get(t);return i&&r.set(t,{...i,status:`failed`,error:n,completedAt:Date.now()}),kr(r,Er,e=>e.status===`completed`||e.status===`failed`),{tasks:r,taskCounts:{...e.taskCounts,running:Math.max(0,e.taskCounts.running-1),failed:e.taskCounts.failed+1},lastUpdated:Date.now()}}),recordBudgetDecision:(t,n,r,i)=>e(e=>{let a=new Map(e.budgetAlerts.reduce((e,r)=>(r.subagentId===t&&r.kind===n||e.set(`${r.subagentId}:${r.kind}`,r),e),new Map)),o=`${t}:${n}`,s=a.get(o);return s&&a.set(o,{...s,decision:r,newLimit:i,level:r===`extend`?`warning`:`danger`}),{budgetAlerts:Array.from(a.values()),lastUpdated:Date.now()}}),recordBudgetAlert:(t,n,r,i)=>e(e=>{let a=`${Date.now()}-${t}-${n}`,o=i>0?Math.round(r/i*100):0;return{budgetAlerts:[{id:a,ts:Date.now(),subagentId:t,kind:n,level:Sr(n,o),used:r,limit:i,pct:o},...e.budgetAlerts].slice(0,Tr),lastUpdated:Date.now()}}),recordBudgetExtended:(t,n,r)=>e(e=>{let i=new Map(e.subagents),a=i.get(t);if(a?.budgetLimits){let e={...a.budgetLimits};n===`timeout`&&r&&(e.timeoutMs=r),n===`iterations`&&(e.maxIterations=r),n===`tool_calls`&&(e.maxToolCalls=r),i.set(t,{...a,budgetLimits:e,lastSeen:Date.now()})}return{subagents:i,lastUpdated:Date.now()}}),clear:()=>e({coordinatorStatus:`idle`,coordinatorMode:void 0,subagents:new Map,events:[],consensusVotes:new Map,tasks:new Map,taskCounts:{pending:0,running:0,completed:0,failed:0},budgetAlerts:[],lastUpdated:Date.now()})}));function jr(){return`ref_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Mr(e){switch(e.split(`.`).pop()?.toLowerCase()??``){case`ts`:case`tsx`:return`typescript`;case`js`:case`jsx`:return`javascript`;case`json`:return`json`;case`md`:case`mdx`:return`markdown`;case`css`:return`css`;case`scss`:return`scss`;case`html`:case`htm`:return`html`;case`py`:return`python`;case`rs`:return`rust`;case`go`:return`go`;case`rb`:return`ruby`;case`java`:return`java`;case`c`:return`c`;case`cpp`:case`hpp`:return`cpp`;case`h`:return`c`;case`sh`:case`bash`:return`bash`;case`sql`:return`sql`;case`yaml`:case`yml`:return`yaml`;case`toml`:return`toml`;default:return``}}function Nr(e,t=20,n=2e3){let r=e.split(`
7
- `),i=!1,a=e;return r.length>t&&(a=r.slice(0,t).join(`
8
- `),i=!0),a.length>n&&(a=a.slice(0,n),i=!0),i&&(a=a.replace(/\s+$/,``)+`
9
- …`),a}function Pr(e){if(e.length===0)return``;let t=[];for(let n of e){if(n.kind===`file`){t.push(`@${n.path}`);continue}let e=Mr(n.path),r=e?`\`\`\`${e}`:"```",i=`// ${n.path}:${n.startLine}-${n.endLine}`,a=n.kind===`snippet`?Nr(n.content):Nr(n.preview);t.push(`${r}\n${i}\n${a}\n\`\`\``)}return t.join(`
10
-
11
- `)}var Fr=Dn()((e,t)=>({refs:[],addRef:n=>{let r=t();if(n.kind===`file`&&r.refs.find(e=>e.kind===`file`&&e.path===n.path))return;let i={...n,id:jr()};e({refs:[...r.refs,i]})},removeRef:t=>{e(e=>({refs:e.refs.filter(e=>e.id!==t)}))},clearRefs:()=>e({refs:[]})})),Ir=Dn()((e,t)=>({projectRoot:``,tree:[],openFiles:[],activeFilePath:null,treeLoading:!1,error:null,setTree:(t,n)=>e({projectRoot:t,tree:n,treeLoading:!1,error:null}),openFile:(n,r)=>{let i=t();if(i.openFiles.find(e=>e.path===n)){e({openFiles:i.openFiles.map(e=>e.path===n?{...e,content:r,dirty:!1,savedContent:r}:e),activeFilePath:n});return}e({openFiles:[...i.openFiles,{path:n,content:r,dirty:!1,savedContent:r}],activeFilePath:n})},closeFile:n=>{let r=t(),i=r.openFiles.findIndex(e=>e.path===n);if(i===-1)return;let a=[...r.openFiles];a.splice(i,1);let o=r.activeFilePath;r.activeFilePath===n&&(o=a.length===0?null:i<a.length?a[i].path:a[a.length-1].path),e({openFiles:a,activeFilePath:o})},setActiveFile:t=>e({activeFilePath:t}),updateContent:(t,n)=>{e(e=>({openFiles:e.openFiles.map(e=>e.path===t?{...e,content:n,dirty:n!==e.savedContent}:e)}))},markSaved:t=>{e(e=>({openFiles:e.openFiles.map(e=>e.path===t?{...e,dirty:!1,savedContent:e.content}:e)}))},setTreeLoading:t=>e({treeLoading:t}),setError:t=>e({error:t})})),Y=c(),Lr=/(?:💡\s*Next steps?|<next_steps>)\s*\n+/i,Rr=/^(?:(\d+)[.)]\s*|[-*•]\s*)(.+?)(\s+auto="true")?$/,zr=6;function Br(e,t=!0){let n=t?Lr.exec(e):Hr().exec(e);if(!n)return{steps:[],stripped:e};let r=n.index+n[0].length,i=e.slice(r),a=i.split(`
12
- `),o=[],s=new Set,c=0,l=0;for(let e of a){let t=e.trim();if(t===`</next_steps>`){c+=e.length+1;break}if(!t){c+=e.length+1;continue}let n=Rr.exec(t);if(!n)break;let r=n[1],i=n[2].trim(),a=!!n[3],u=r===void 0?o.length+1:Number.parseInt(r,10);if(s.has(u)){c+=e.length+1;continue}if(s.add(u),o.push(a?{index:u,text:i,auto:!0}:{index:u,text:i}),c+=e.length+1,l++,l>=zr)break}if(o.length===0||t&&/<next_steps>/i.test(n[0])&&!i.includes(`</next_steps>`))return{steps:[],stripped:e};let u=n.index,d=r+c;return{steps:o,stripped:(e.slice(0,u)+e.slice(d)).replace(/\n{3,}/g,`
13
-
14
- `).trim()}}var Vr=[{re:/💡\s*Next steps?\s*\n+/i,label:`emoji`},{re:/##?\s*Next steps?\s*\n+/i,label:`markdown`},{re:/\n{1,2}Next steps?\s*\n+/i,label:`plain`},{re:/<next_steps>\s*\n+/i,label:`xml-tag`}];function Hr(){let e=Vr.map(({re:e})=>`(?:${e.source})`).join(`|`);return new RegExp(e,`i`)}function Ur(e){return e.replace(/<next_steps\b[^>]*>[\s\S]*?<\/next_steps>/gi,``).replace(/<next_steps\b[^>]*\/?>/gi,``).replace(/\n{3,}/g,`
15
-
16
- `).trim()}function Wr(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function Gr({delayMs:e,onComplete:t}){let[n,r]=(0,q.useState)(Math.ceil(e/1e3));return(0,q.useEffect)(()=>{if(n<=0){t();return}let e=setTimeout(()=>r(e=>e-1),1e3);return()=>clearTimeout(e)},[n,t]),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-primary font-medium`,children:[(0,Y.jsx)(Lt,{className:`h-3 w-3`}),n,`s`]})}function Kr({steps:e,yoloMode:t=!1,autoMode:n=!1,autoDelayMs:r=3e4,onAutoSubmit:i,canAutoSubmit:a=!0}){let{t:o}=z();if(e.length===0)return null;let s=t&&n&&a,c=s?e.find(e=>e.auto):void 0;return(0,Y.jsxs)(`div`,{className:`mt-4 rounded-xl border border-primary/20 bg-primary/[0.03] overflow-hidden animate-message`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3.5 py-2 border-b border-primary/10 bg-primary/[0.04]`,children:[(0,Y.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md bg-primary/15 text-primary`,children:(0,Y.jsx)(ht,{className:`h-3 w-3`})}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-foreground/90`,children:o(`activity:nextSteps.header`)}),s&&c?(0,Y.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-xs text-primary`,children:[(0,Y.jsx)(Lt,{className:`h-3 w-3`}),o(`activity:nextSteps.autoSubmitting`),` `,(0,Y.jsx)(Gr,{delayMs:r,onComplete:()=>i?.(c.text)})]}):(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:o(`activity:nextSteps.clickToFill`)})]}),(0,Y.jsx)(`div`,{className:`flex flex-col p-2 gap-1`,children:e.map(e=>{let t=s&&e.auto;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Wr(e.text),className:`group flex items-center gap-2.5 w-full text-left px-3 py-2 rounded-lg transition-all border ${t?`bg-primary/10 border-primary/30 ring-1 ring-primary/20`:`border-transparent hover:bg-primary/[0.08] hover:shadow-sm hover:border-primary/20`}`,title:o(`activity:nextSteps.clickToFillTitle`,{text:e.text}),children:[(0,Y.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md text-[11px] font-mono font-semibold tabular-nums shrink-0 transition-colors ${t?`bg-primary/30 text-primary`:`bg-muted/80 group-hover:bg-primary/20 text-muted-foreground group-hover:text-primary`}`,children:e.index}),(0,Y.jsx)(A,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`text-primary`:`text-muted-foreground/60 group-hover:text-primary group-hover:translate-x-0.5`}`}),(0,Y.jsx)(`span`,{className:`text-sm leading-snug flex-1 min-w-0 transition-colors ${t?`text-foreground font-medium`:`text-foreground/80 group-hover:text-foreground`}`,children:e.text}),e.auto&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-primary/70`,children:[n&&e.index===1&&!s?(0,Y.jsx)(`span`,{title:o(`activity:nextSteps.willAutoSubmit`),children:`⏩`}):(0,Y.jsx)(Lt,{className:`h-3 w-3`}),o(`activity:nextSteps.auto`)]}),(0,Y.jsx)(p,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`opacity-100 text-primary/60`:`opacity-0 group-hover:opacity-100 text-primary/60`}`})]},e.index)})})]})}var qr=12,Jr=20,Yr=500,Xr=[];function Zr(e,t,n){return{id:e,name:t?.trim()||e,sessionId:n,status:`running`,iteration:0,toolCalls:0,costUsd:0,ctxPct:0,ctxTokens:0,maxContext:0,extensions:0,startedAt:Date.now(),toolLog:[],sparklineBins:Array(qr).fill(0)}}var Qr=0;function $r(){return`tl_${Date.now()}_${++Qr}`}function ei(e,t){return[t,...e].slice(0,Jr)}function ti(e){switch(e){case`text`:case`thinking`:case`tool_use`:case`tool_result`:case`error`:case`status`:case`system`:return e;default:return`status`}}function ni(e,t){return e.subagentId!==t.subagentId||e.kind!==t.kind||e.iteration!==t.iteration||e.toolName!==t.toolName?!1:e.kind===`text`||e.kind===`thinking`}function ri(e,t){let n=e[e.length-1];return n&&ni(n,t)?[...e.slice(0,-1),{...n,content:`${n.content}${t.content}`,ts:t.ts}].slice(-1e3):[...e,t].slice(-1e3)}function ii(e){return[e[0]+1,...e.slice(0,qr-1)]}function ai(e){return Number.isFinite(e)?Math.max(0,Math.min(100,e)):0}var X=Dn()((e,t)=>({agents:new Map,leaderId:void 0,fleetTokensIn:0,fleetTokensOut:0,fleetConcurrency:0,fleetConcurrencyMax:4,eventTimeline:[],agentTimeline:[],agentTranscripts:new Map,pushAgentTimelineEntry:t=>e(e=>{let n={id:`agent_tl_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,...t,kind:ti(t.kind)},r=new Map(e.agentTranscripts);return r.set(n.subagentId,ri(r.get(n.subagentId)??[],n)),{agentTimeline:[n,...e.agentTimeline].slice(0,Yr),agentTranscripts:r}}),clear:()=>e({agents:new Map,leaderId:void 0,fleetTokensIn:0,fleetTokensOut:0,fleetConcurrency:0,eventTimeline:[],agentTimeline:[],agentTranscripts:new Map}),getAgentsBySession:e=>{let n=[];for(let r of t().agents.values())r.sessionId===e&&n.push(r);return n},getAgentTranscript:e=>t().agentTranscripts.get(e)??Xr,applyEvent:t=>e(e=>{let n=new Map(e.agents),r=new Map(e.agentTranscripts),i=e.eventTimeline,a=e.leaderId,o=e.fleetTokensIn,s=e.fleetTokensOut;if(t.kind===`session_stopped`&&t.sessionId){let i=new Set;for(let[e,a]of n)a.sessionId===t.sessionId&&(n.delete(e),r.delete(e),i.add(e));return{agents:n,agentTranscripts:r,agentTimeline:e.agentTimeline.filter(e=>!i.has(e.subagentId)),leaderId:void 0,fleetTokensIn:0,fleetTokensOut:0}}if(t.kind===`leader_updated`&&t.subagentId){let r=e.leaderId;if(r&&r!==t.subagentId){let e=n.get(r);e&&n.set(r,{...e,isLeader:!1})}a=t.subagentId;let o=n.get(t.subagentId)??Zr(t.subagentId,t.name,t.sessionId);return n.set(t.subagentId,{...o,isLeader:!0,name:t.name?.trim()||o.name}),i=ei(i,{id:$r(),kind:`leader_updated`,agentId:t.subagentId,agentName:t.name??a,timestamp:Date.now(),message:`${t.name??t.subagentId} became leader`}),{agents:n,leaderId:a,eventTimeline:i}}if(!t.subagentId)return e;let c=n.get(t.subagentId)??Zr(t.subagentId,t.name,t.sessionId),l={...c},u=Date.now();switch(t.kind){case`spawned`:l.name=t.name?.trim()||l.name,l.provider=t.provider??l.provider,l.model=t.model??l.model,l.description=t.description??l.description,l.taskId=t.taskId??l.taskId,l.sessionId=t.sessionId??l.sessionId,l.status=`running`,l.sparklineBins=Array(qr).fill(0),i=ei(i,{id:$r(),kind:`spawned`,agentId:t.subagentId,agentName:l.name,timestamp:u,message:`${l.name} spawned`});break;case`task_started`:l.description=t.description??l.description,l.taskId=t.taskId??l.taskId,l.status=`running`,i=ei(i,{id:$r(),kind:`task_started`,agentId:t.subagentId,agentName:l.name,timestamp:u,message:`${l.name} started: ${t.description??`new task`}`});break;case`tool_executed`:{let e=typeof t.ok==`boolean`?t.ok:!0,n=typeof t.durationMs==`number`?t.durationMs:0;l.lastTool=t.toolName??l.lastTool,l.toolCalls+=1,l.toolLog=[{name:t.toolName??`unknown`,ok:e,durationMs:n,at:u},...l.toolLog].slice(0,50),l.sparklineBins=ii(l.sparklineBins),i=ei(i,{id:$r(),kind:`tool_executed`,agentId:t.subagentId,agentName:l.name,timestamp:u,message:`${l.name} ${e?`✓`:`✗`} ${t.toolName??`tool`}`,value:n});break}case`iteration_summary`:l.iteration=t.iteration??l.iteration,typeof t.toolCalls==`number`&&(l.toolCalls=t.toolCalls),typeof t.costUsd==`number`&&(l.costUsd=t.costUsd),l.currentTool=t.currentTool??l.currentTool,typeof t.partialText==`string`&&t.partialText&&(l.partialText=t.partialText),l.sparklineBins=ii(l.sparklineBins),i=ei(i,{id:$r(),kind:`iteration_summary`,agentId:t.subagentId,agentName:l.name,timestamp:u,message:`${l.name} iter ${t.iteration??l.iteration} · ${t.currentTool?`${t.currentTool}`:``}`,value:t.costUsd});break;case`budget_warning`:{let e=t.budgetKind??`budget`,n=typeof t.used==`number`?t.used:0,r=typeof t.limit==`number`?t.limit:0;l.budgetWarning={kind:e,used:n,limit:r},i=ei(i,{id:$r(),kind:`budget_warning`,agentId:t.subagentId,agentName:l.name,timestamp:u,message:`${l.name} hit ${e} budget ${n}/${r}`,value:n});break}case`budget_extended`:l.extensions=t.totalExtensions??l.extensions+1,l.budgetWarning=void 0,i=ei(i,{id:$r(),kind:`budget_extended`,agentId:t.subagentId,agentName:l.name,timestamp:u,message:`${l.name} extended budget ⚡×${l.extensions}`});break;case`ctx_pct`:l.ctxPct=ai(Math.round(Math.max(0,t.load??0)*100)),l.ctxTokens=t.tokens??l.ctxTokens,l.maxContext=t.maxContext??l.maxContext,l.ctxPct>=80&&!l.budgetWarning&&(l.budgetWarning=l.ctxPct>=100?{kind:`hard`,used:l.ctxPct,limit:100}:{kind:`soft`,used:l.ctxPct,limit:100}),typeof t.costUsd==`number`&&(l.costUsd=t.costUsd),typeof t.tokensIn==`number`&&(l.tokensIn=t.tokensIn,o=o-(c.tokensIn??0)+t.tokensIn),typeof t.tokensOut==`number`&&(l.tokensOut=t.tokensOut,s=s-(c.tokensOut??0)+t.tokensOut),i=ei(i,{id:$r(),kind:`ctx_pct`,agentId:t.subagentId,agentName:l.name,timestamp:u,message:`${l.name} ctx ${l.ctxPct}%`,value:l.ctxPct});break;case`task_completed`:{l.status=t.status===`success`?`completed`:t.status??`completed`,typeof t.iterations==`number`&&(l.iteration=t.iterations),typeof t.toolCalls==`number`&&(l.toolCalls=t.toolCalls),l.error=t.error,l.currentTool=void 0,l.completedAt=u,l.failureReason=t.failureReason??l.failureReason,typeof t.finalText==`string`&&t.finalText&&(l.finalText=Ur(t.finalText));let e=t.status===`success`?`✓ completed`:t.status===`failed`?`✗ failed${t.failureReason?` (${t.failureReason})`:``}`:t.status===`timeout`?`⏱ timeout${t.failureReason?` (${t.failureReason})`:``}`:`stopped`;i=ei(i,{id:$r(),kind:`task_completed`,agentId:t.subagentId,agentName:l.name,timestamp:u,message:`${l.name} ${e}`,value:l.costUsd});break}}return n.set(t.subagentId,l),{agents:n,leaderId:a,fleetTokensIn:o,fleetTokensOut:s,eventTimeline:i}})})),oi=Dn()(e=>({files:[],error:null,loadingList:!1,selectedPath:null,diff:null,loadingDiff:!1,setFiles:(t,n)=>e({files:t,error:n,loadingList:!1}),setListLoading:t=>e({loadingList:t}),select:t=>e({selectedPath:t,diff:null,loadingDiff:!!t}),setDiff:t=>e({diff:t,loadingDiff:!1}),setDiffLoading:t=>e({loadingDiff:t}),clear:()=>e({files:[],error:null,selectedPath:null,diff:null,loadingDiff:!1})})),si=Dn()(e=>({info:null,setInfo:t=>e({info:t}),clear:()=>e({info:null})}));function ci(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return!(typeof t.iteration!=`number`||!Number.isFinite(t.iteration)||t.task!==void 0&&typeof t.task!=`string`||t.status!==void 0&&typeof t.status!=`string`||t.progress!==void 0&&(typeof t.progress!=`number`||!Number.isFinite(t.progress))||t.progressNote!==void 0&&typeof t.progressNote!=`string`||t.timestamp!==void 0&&typeof t.timestamp!=`string`)}function li(e){return!e||typeof e.goal!=`string`||!e.goal.trim()?null:{goal:e.goal,refinedGoal:typeof e.refinedGoal==`string`?e.refinedGoal:void 0,goalState:[`active`,`paused`,`completed`,`failed`,`abandoned`].includes(e.goalState)?e.goalState:`active`,iterations:typeof e.iterations==`number`?e.iterations:0,progress:typeof e.progress==`number`?e.progress:0,progressNote:typeof e.progressNote==`string`?e.progressNote:void 0,progressTrend:e.progressTrend===`accelerating`?`up`:e.progressTrend===`stalling`?`down`:e.progressTrend===`steady`?`stable`:void 0,deliverables:Array.isArray(e.deliverables)?e.deliverables.map((e,t)=>typeof e==`string`?{id:`d${t}`,text:e,status:/^\[[x✓]\]|✅|\(done\)/i.test(e)?`done`:`pending`}:e):void 0,journal:Array.isArray(e.journal)?e.journal.filter(ci):void 0,lastTask:typeof e.lastTask==`string`?e.lastTask:void 0,lastStatus:typeof e.lastStatus==`string`?e.lastStatus:void 0}}var ui=Dn()(e=>({goal:null,setGoal:t=>e({goal:li(t)}),clear:()=>e({goal:null}),appendJournalEntry:t=>e(e=>e.goal?{goal:{...e.goal,iterations:Math.max(e.goal.iterations,t.iteration),lastTask:t.task??e.goal.lastTask,lastStatus:t.status??e.goal.lastStatus,journal:[t,...e.goal.journal??[]].slice(0,200)}}:e),refresh:()=>{try{U()?.send?.({type:`goal.get`})}catch{}}})),di=Dn()(e=>({entries:[],loading:!1,error:null,setEntries:(t,n=null)=>e({entries:t,error:n,loading:!1}),setLoading:t=>e({loading:t}),removeEntry:t=>e(e=>({entries:e.entries.filter(e=>e.id!==t)})),updateEntryName:(t,n)=>e(e=>({entries:e.entries.map(e=>{if(e.id!==t)return e;let r=n.trim();if(!r){let{name:t,...n}=e;return n}return{...e,name:r}})})),clearHistory:()=>e({entries:[]})})),fi=Dn()((e,t)=>({boards:[],activeBoardId:null,activeBoard:null,loading:!1,error:null,setLoading:t=>e({loading:t}),setActiveBoardId:t=>e({activeBoardId:t}),setError:t=>e({error:t}),handleResult:(n,r)=>{if(!r.success){e({loading:!1,error:r.error??`Kanban request failed`});return}let i=r.data;if(n===`kanban.list`){e({boards:Array.isArray(i)?i:[],loading:!1,error:null});return}if(n===`kanban.delete`){let n=t().activeBoardId,r=i?.removed===!0;e(e=>({boards:r?e.boards.filter(e=>e.id!==n):e.boards,activeBoardId:r?null:e.activeBoardId,activeBoard:r?null:e.activeBoard,loading:!1,error:null}));return}if(pi(i)){let t=gi(i);e(e=>({boards:_i(e.boards,t),activeBoardId:i.id,activeBoard:i,loading:!1,error:null}));return}if(mi(i)){e(e=>({activeBoard:e.activeBoard?vi(e.activeBoard,i):e.activeBoard,loading:!1,error:null}));return}if(Array.isArray(i)&&i.every(hi)){e(e=>({activeBoard:e.activeBoard?{...e.activeBoard,columns:i}:e.activeBoard,loading:!1,error:null}));return}if(n===`kanban.task.remove`){e(e=>({activeBoard:e.activeBoard?{...e.activeBoard,tasks:e.activeBoard.tasks.filter(e=>e.id!==(i?.taskId??``))}:e.activeBoard,loading:!1,error:null}));return}e({loading:!1,error:null})}}));function pi(e){return!!e&&typeof e==`object`&&Array.isArray(e.columns)&&Array.isArray(e.tasks)}function mi(e){return!!e&&typeof e==`object`&&typeof e.title==`string`}function hi(e){return!!e&&typeof e==`object`&&typeof e.id==`string`}function gi(e){return{id:e.id,title:e.title,description:e.description,tags:e.tags,createdAt:e.createdAt,updatedAt:e.updatedAt,columnCount:e.columns.length,taskCount:e.tasks.length,completedTaskCount:e.tasks.filter(e=>e.status===`completed`).length}}function _i(e,t){return[t,...e.filter(e=>e.id!==t.id)].sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt))}function vi(e,t){let n=e.tasks.some(e=>e.id===t.id)?e.tasks.map(e=>e.id===t.id?t:e):[...e.tasks,t];return{...e,tasks:n}}var yi=Dn()(e=>({messages:[],agents:[],setMessages:t=>e({messages:t}),setAgents:t=>e({agents:t})}));function bi(e){return e.messages.filter(e=>!e.completed&&(e.readByCount??0)===0).length}function xi(e){switch(e){case`tui`:return`tui`;case`cli`:case`repl`:return`repl`;case`webui`:return`webui`;default:return`webui`}}function Si(e){let t={tui:0,webui:0,repl:0},n=0,r=0,i={toolCalls:0,costUsd:0,tokensIn:0,tokensOut:0};for(let a of e){t[xi(a.clientType)]+=1;for(let e of a.agents)n+=1,(e.status===`running`||e.status===`streaming`)&&(r+=1),i.toolCalls+=e.toolCalls??0,i.costUsd+=e.costUsd??0,i.tokensIn+=e.tokensIn??0,i.tokensOut+=e.tokensOut??0}return{clientCounts:t,totalAgents:n,activeAgents:r,aggregate:i}}function Ci(e){if(e!==void 0)return Number.isFinite(e)?Math.max(0,Math.min(100,Math.round(e))):0}function wi(e){return e.map(e=>({...e,agents:e.agents.map(e=>({...e,ctxPct:Ci(e.ctxPct)}))}))}var Ti=0,Ei=Dn()(e=>({clientCounts:{tui:0,webui:0,repl:0},mailActivity:[],totalMessages:0,openMessages:0,unreadMessages:0,totalAgents:0,activeAgents:0,currentSession:{},liveSessions:[],aggregate:{toolCalls:0,costUsd:0,tokensIn:0,tokensOut:0},lastUpdated:Date.now(),setClientCounts:t=>e({clientCounts:t,lastUpdated:Date.now()}),setLiveSessions:t=>{let n=wi(t);e({liveSessions:n,...Si(n),lastUpdated:Date.now()})},addMailActivity:t=>e(e=>({mailActivity:[{...t,seq:t.seq??++Ti},...e.mailActivity].slice(0,50),lastUpdated:Date.now()})),setMailStats:(t,n,r)=>e({totalMessages:t,openMessages:n,unreadMessages:r,lastUpdated:Date.now()}),setAgentStats:(t,n)=>e({totalAgents:t,activeAgents:n,lastUpdated:Date.now()}),setCurrentSession:t=>e({currentSession:{...Ei.getState().currentSession,...t},lastUpdated:Date.now()}),clear:()=>e({clientCounts:{tui:0,webui:0,repl:0},mailActivity:[],totalMessages:0,openMessages:0,unreadMessages:0,totalAgents:0,activeAgents:0,currentSession:{},liveSessions:[],aggregate:{toolCalls:0,costUsd:0,tokensIn:0,tokensOut:0},lastUpdated:Date.now()})})),Di=Dn()(mn(e=>({showHud:!0,showLegend:!0,showMinimap:!0,showControls:!0,animateEdges:!0,showFeed:!0,background:`dots`,setShowHud:t=>e({showHud:t}),setShowLegend:t=>e({showLegend:t}),setShowMinimap:t=>e({showMinimap:t}),setShowControls:t=>e({showControls:t}),setAnimateEdges:t=>e({animateEdges:t}),setShowFeed:t=>e({showFeed:t}),setBackground:t=>e({background:t})}),{name:`wrongstack-officemap`})),Oi=Dn()(e=>({snapshot:null,boards:[],lifecycleResult:null,destroying:!1,setSnapshot:t=>e({snapshot:t}),setBoards:t=>e({boards:t}),setLifecycleResult:t=>e({lifecycleResult:t}),setDestroying:t=>e({destroying:t})})),ki=Dn()(e=>({snapshot:null,agentText:``,error:null,startedRunId:null,setSnapshot:t=>e({snapshot:t,error:null}),setAgentText:t=>e({agentText:t}),setError:t=>e({error:t}),setStartedRunId:t=>e({startedRunId:t}),reset:()=>e({snapshot:null,agentText:``,error:null,startedRunId:null})})),Ai=Dn(e=>({sideEffects:[],loading:!1,setSideEffects:t=>e({sideEffects:t,loading:!1}),setLoading:t=>e({loading:t}),clear:()=>e({sideEffects:[],loading:!1})})),ji=Dn()(e=>({specs:[],detail:null,expandedSpecId:null,setSpecs:t=>e({specs:t}),setDetail:t=>e({detail:t}),setExpanded:t=>e({expandedSpecId:t,detail:null})})),Mi=Dn()(e=>({worktrees:[],baseBranch:``,activity:[],orphans:[],canClean:!1,cleanResult:null,mergeResult:null,diffByDir:{},setSnapshot:(t,n)=>e({worktrees:t,baseBranch:n}),pushEvent:t=>e(e=>({activity:[...e.activity,t].slice(-40)})),setOrphans:(t,n,r)=>e({orphans:t,canClean:n,cleanBlockedReason:r}),setCleanResult:t=>e({cleanResult:t}),setMergeResult:t=>e({mergeResult:t}),setDiff:(t,n)=>e(e=>({diffByDir:{...e.diffByDir,[t]:n}}))}));function Ni(){return`toast_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}`}var Pi=8e3,Fi=Dn(e=>({toasts:[],push:t=>{let n=Ni();return e(e=>({toasts:[...e.toasts,{...t,id:n}]})),n},dismiss:t=>e(e=>({toasts:e.toasts.filter(e=>e.id!==t)}))})),Z={success:(e,t=3500)=>Fi.getState().push({message:e,variant:`success`,ttl:t}),error:(e,t=6e3)=>Fi.getState().push({message:e,variant:`error`,ttl:t}),warn:(e,t=4500)=>Fi.getState().push({message:e,variant:`warn`,ttl:t}),info:(e,t=3500)=>Fi.getState().push({message:e,variant:`info`,ttl:t}),undoable:(e,t,n=B.t(`common:action.undo`),r=Pi)=>Fi.getState().push({message:e,variant:`info`,ttl:r,action:{label:n,onClick:t}}),dismiss:e=>Fi.getState().dismiss(e)};function Ii({variant:e}){return e===`success`?(0,Y.jsx)(jn,{className:`h-4 w-4 text-green-500`}):e===`error`?(0,Y.jsx)(f,{className:`h-4 w-4 text-destructive`}):e===`warn`?(0,Y.jsx)(je,{className:`h-4 w-4 text-amber-500`}):(0,Y.jsx)(S,{className:`h-4 w-4 text-blue-500`})}function Li({entry:e}){let{t}=z(),n=Fi(e=>e.dismiss);return(0,q.useEffect)(()=>{let t=setTimeout(()=>n(e.id),e.ttl);return()=>clearTimeout(t)},[e.id,e.ttl,n]),(0,Y.jsxs)(`div`,{className:K(`flex items-start gap-2 rounded-lg border bg-popover shadow-lg px-3 py-2 text-sm max-w-sm`,`animate-message`,e.variant===`error`&&`border-destructive/40`,e.variant===`warn`&&`border-amber-500/40`,e.variant===`success`&&`border-green-500/40`),children:[(0,Y.jsx)(Ii,{variant:e.variant}),(0,Y.jsx)(`div`,{className:`flex-1 min-w-0 whitespace-pre-wrap break-words leading-snug`,children:e.message}),e.action&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{e.action?.onClick(),n(e.id)},className:`shrink-0 font-medium text-primary hover:underline`,children:e.action.label}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>n(e.id),className:`text-muted-foreground hover:text-foreground`,title:t(`activity:toast.dismiss`),children:(0,Y.jsx)(ut,{className:`h-3.5 w-3.5`})})]})}function Ri(){let e=Fi(e=>e.toasts);return e.length===0?null:(0,Y.jsx)(`div`,{className:`fixed bottom-4 right-4 z-[60] flex flex-col gap-2 pointer-events-auto`,children:e.map(e=>(0,Y.jsx)(Li,{entry:e},e.id))})}var zi=null;function Bi(){if(typeof window>`u`)return null;if(zi)return zi;let e=window.AudioContext||window.webkitAudioContext;if(!e)return null;try{zi=new e}catch{return null}return zi}function Vi(e,t,n){let r=Bi();if(!r)return;let i=r.currentTime+t,a=r.createOscillator(),o=r.createGain();a.type=`sine`,a.frequency.value=e,o.gain.setValueAtTime(0,i),o.gain.linearRampToValueAtTime(.18,i+.01),o.gain.exponentialRampToValueAtTime(1e-4,i+n),a.connect(o).connect(r.destination),a.start(i),a.stop(i+n+.02)}function Hi(){Vi(659.25,0,.18),Vi(880,.12,.24)}function Ui(){Vi(523.25,0,.15),Vi(659.25,.1,.15),Vi(783.99,.2,.25)}var Wi=`default`;Wi=typeof window<`u`&&`Notification`in window?Notification.permission:`unsupported`;async function Gi(){if(Wi===`unsupported`||Wi===`granted`||Wi===`denied`)return Wi;try{let e=await Notification.requestPermission();return Wi=e,e}catch{return`denied`}}function Ki(e,t,n){if(!(typeof document>`u`||!document.hidden)&&Wi===`granted`)try{let r=new Notification(e,{body:t,icon:`/favicon.ico`,tag:n??`wrongstack-run`,requireInteraction:n===`wrongstack-confirm`});r.onclick=()=>{window.focus(),r.close()}}catch{}}var qi={"iteration.started":Ji,"provider.text_delta":Yi,"provider.thinking_delta":Xi,"tool.started":Zi,"tool.progress":Qi,"tool.executed":$i,"tool.confirm_needed":ea,"run.result":ta};function Ji(e){if(!H(e))return;ar(e);let t=e.payload;W.getState().setIteration({index:t.index,max:t.maxIterations??0}),i.getState().setLoading(!0),typeof document<`u`&&document.hidden&&vr(`running`),i.getState().runStart===null&&i.getState().setRunStart({at:Date.now(),cost:W.getState().cost}),i.getState().setCurrentAssistantMessage(null)}function Yi(e){if(!H(e))return;let t=cr(e,{text:`string`,messageId:`string`});if(!t)return;sr.flush(`__thinking__`),i.getState().clearThinking();let n=i.getState().currentAssistantMessageId;n||(n=i.getState().addMessage({role:`assistant`,content:``,streaming:!0}),i.getState().setCurrentAssistantMessage(n)),sr.push(n,t.text,(e,t)=>i.getState().appendToMessage(e,t))}function Xi(e){if(!H(e))return;let t=e.payload;t.text&&sr.push(`__thinking__`,t.text,(e,t)=>i.getState().appendThinking(t))}function Zi(e){if(!H(e))return;ar(e);let t=e.payload,n=i.getState().getToolMessageId(t.id);if(n){i.getState().setCurrentToolId(n);return}sr.flushAll(),i.getState().clearThinking();let r=i.getState().currentAssistantMessageId;r&&i.getState().finalizeMessage(r),i.getState().setCurrentAssistantMessage(null);let a=i.getState().addMessage({role:`tool`,content:``,toolName:t.name,toolInput:t.input,toolUseId:t.id});i.getState().setCurrentToolId(a),i.getState().addExecution({id:t.id,name:t.name,input:t.input,ok:!0,startedAt:Date.now()})}function Qi(e){if(!H(e))return;let t=e.payload,n=(t.event?.text??``).trim();if(!n)return;let r=i.getState().getToolMessageId(t.id);if(!r)return;let a=t.event?.type===`warning`?`⚠ `:``;sr.push(r,`${a}${n}\n`,(e,n)=>i.getState().appendToolProgressLinesByUseId(t.id,n.split(`
17
- `).filter(e=>e.length>0)))}function $i(e){if(!H(e))return;ar(e);let t=e.payload,{currentToolId:n}=i.getState(),r=t.id?i.getState().getToolMessageId(t.id):n;r&&(sr.drop(r),t.id?i.getState().setToolResultByUseId(t.id,t.output??``,t.ok):i.getState().setToolResult(r,t.output??``,t.ok),i.getState().updateMessage(r,{toolDurationMs:t.durationMs})),t.id&&i.getState().updateExecution(t.id,{completedAt:Date.now(),durationMs:t.durationMs,output:t.output,ok:t.ok}),n&&r===n&&i.getState().setCurrentToolId(null)}function ea(e){if(!H(e))return;let t=e.payload;if($n.getState().yolo===!0&&t.riskTier!==`destructive`&&t.decisionSource!==`yolo_destructive`){U(J.getState().wsUrl).sendConfirm(t.id,`yes`),G.getState().hideConfirm();return}G.getState().showConfirm({id:t.id,toolName:t.toolName,input:t.input,suggestedPattern:t.suggestedPattern,decisionSource:t.decisionSource,riskTier:t.riskTier});try{Ui()}catch{}Gi(),Ki(`${W.getState().projectName||`Agent`} needs approval`,`Tool "${t.toolName}" is waiting for your decision.`,`agent-confirm`),typeof document<`u`&&document.hidden&&vr(`attention`)}function ta(e){if(!H(e))return;let t=cr(e,{status:`string`},{iterations:`number`,finalText:`string`,error:`object`});if(!t)return;let r=t.iterations??1;sr.flushAll(),i.getState().flushThinkingLog(Math.max(1,r)),W.getState().setIteration(null),i.getState().setLoading(!1);let a=i.getState().currentAssistantMessageId,o=t.status===`done`?t.finalText?.trim():void 0;if(a){let e=i.getState().messages.find(e=>e.id===a);i.getState().updateMessage(a,{content:e?.content?.trim()?e.content:o??e?.content??``,streaming:!1})}else if(o){let e=i.getState().runStart;i.getState().messages.some(t=>t.role===`assistant`&&(!e||t.timestamp>=e.at)&&t.content.trim()===o)||i.getState().addMessage({role:`assistant`,content:o})}i.getState().setCurrentAssistantMessage(null),i.getState().clearThinking();let s=i.getState().runStart;if(s&&t.status===`done`){let e=i.getState().messages,t=-1,a=0;for(let r=e.length-1;r>=0;r--){let i=n(e[r]);if(i.role===`assistant`&&t===-1&&i.content&&(t=r),i.role===`tool`&&i.timestamp>=s.at&&(a+=1),i.role===`user`&&i.timestamp<=s.at)break}if(t!==-1){let n=W.getState().cost;i.getState().updateMessage(e[t]?.id,{runSummary:{iterations:r,tools:a,durationMs:Date.now()-s.at,costDelta:Math.max(0,n-s.cost)}})}}if(i.getState().setRunStart(null),t.status!==`done`&&t.error)i.getState().addMessage({role:`assistant`,content:`Error: ${t.error.message}`,isError:!0}),Z.error(`Run ended: ${t.error.message}`),Ki(`${W.getState().projectName||`Agent`} run failed`,t.error.message),typeof document<`u`&&document.hidden&&vr(`error`);else if(t.status===`done`&&(typeof document<`u`&&document.hidden&&(Z.success(`Run completed in ${r} iteration${r===1?``:`s`}`),Ki(`${W.getState().projectName||`Agent`} run finished`,`Completed in ${r} iteration${r===1?``:`s`}.`),vr(`ready`)),Gi(),J.getState().soundOnComplete))try{Hi()}catch{}let c=i.getState().dequeue();if(c){let e=U(J.getState().wsUrl);i.getState().addMessage({role:`user`,content:c.text}),i.getState().setLoading(!0),e.sendMessage(c.text)}}var na={"coordinator.status":e=>{let t=e.payload;Ar.getState().setCoordinatorStatus(t.status,t.mode),t.taskQueue&&Ar.getState().updateCoordinatorStats({total:t.subagentCount??0,running:0,idle:0,stopped:0,inFlight:t.taskQueue.running,pending:t.taskQueue.pending,completed:t.taskQueue.completed})},"coordinator.stats":e=>{let t=e.payload;Ar.getState().updateCoordinatorStats(t)},"budget.threshold_reached":e=>{let t=e.payload;Ar.getState().pushEvent(`budget.threshold_reached`,t,t.ts??Date.now(),t.subagentId,t.taskId),t.limit>0&&t.used/t.limit*100>=85&&Ar.getState().recordBudgetAlert(t.subagentId,t.kind,t.used,t.limit),Ar.getState().updateSubagentBudget(t.subagentId,{budgetUsage:{iterations:0,toolCalls:0,tokens:0,costUsd:0,elapsedMs:t.used??0}})},"budget.decision":e=>{let t=e.payload,n=t.extended?.timeoutMs??t.extended?.maxIterations??t.extended?.maxToolCalls;Ar.getState().recordBudgetDecision(t.subagentId,t.kind,t.decision,n),Ar.getState().pushEvent(`budget.decision`,{subagentId:t.subagentId,kind:t.kind,decision:t.decision,newLimit:n},Date.now(),t.subagentId)},"subagent.budget_extended":e=>{let t=e.payload;Ar.getState().recordBudgetExtended(t.subagentId,t.kind,t.extendedTo),Ar.getState().pushEvent(`subagent.budget_extended`,t,Date.now(),t.subagentId)},"consensus.vote_initiated":e=>{let t=e.payload;Ar.getState().pushConsensusVote(t.changeId,t.title,t.eligible),Ar.getState().pushEvent(`consensus.vote_initiated`,t,Date.now()),Z.info(`Vote started: `+t.title)},"consensus.vote_cast":e=>{let t=e.payload,n=Ar.getState().consensusVotes.get(t.changeId)?.eligible.find(e=>e.agentId===t.voterId);Ar.getState().recordConsensusVote(t.changeId,t.voterId,n?.agentName??t.voterId,t.value),Ar.getState().pushEvent(`consensus.vote_cast`,t,Date.now(),t.voterId)},"consensus.vote_resolved":e=>{let t=e.payload;Ar.getState().resolveConsensusVote(t.changeId,t.result,t.approveCount,t.rejectCount),Ar.getState().pushEvent(`consensus.vote_resolved`,t,Date.now()),Z.info(`Vote resolved: `+t.result+` (y`+t.approveCount+` n`+t.rejectCount+`)`)},"task.pending":e=>{let t=e.payload;Ar.getState().pushTaskPending(t.taskId,t.description,t.priority),Ar.getState().pushEvent(`task.pending`,t,Date.now())},"task.started":e=>{let t=e.payload;Ar.getState().startTask(t.taskId,t.subagentId),Ar.getState().pushEvent(`task.started`,t,Date.now(),t.subagentId)},"task.completed":e=>{let t=e.payload;Ar.getState().completeTask(t.taskId,t.status,t.durationMs),Ar.getState().pushEvent(`task.completed`,t,Date.now(),t.subagentId)},"task.failed":e=>{let t=e.payload;Ar.getState().failTask(t.taskId,t.error),Ar.getState().pushEvent(`task.failed`,{taskId:t.taskId,subagentId:t.subagentId,error:String(t.error).slice(0,120)},Date.now(),t.subagentId),Z.error(`Task failed: `+String(t.error).slice(0,80))}};function ra(){let e=U();e?.send?.({type:`mailbox.messages`,payload:{limit:30,incompleteOnly:!0}}),e?.send?.({type:`mailbox.agents`,payload:{}})}function ia(e){let t=e.payload;if(t.error){Ir.getState().setError(t.error);return}Ir.getState().setTree(t.root,t.tree)}function aa(e){let t=e.payload;if(t.error){Ir.getState().setError(t.error);return}Ir.getState().openFile(t.filePath,t.content)}function oa(e){let t=e.payload;t.success?Ir.getState().markSaved(t.filePath):t.error&&Ir.getState().setError(`Save failed: ${t.error}`)}function sa(e){let t=or(`mailbox.event`,e.payload);t&&(ur.getState().pushEvent(t),ur.getState().setActive(!0)),ra()}function ca(e){let t=e.payload;t?.messages&&yi.getState().setMessages(t.messages)}function la(e){let t=e.payload;t?.agents&&yi.getState().setAgents(t.agents)}function ua(e){let t=or(`mailbox.received`,e.payload);t&&(ur.getState().pushEvent(t),ur.getState().setActive(!0)),ra()}function da(e){ra()}function fa(e){yi.getState().setMessages([]),ra()}function pa(e){ra()}var ma={"files.tree":ia,"files.read":aa,"files.written":oa,"mailbox.event":sa,"mailbox.messages":ca,"mailbox.agents":la,"mailbox.received":ua,"mailbox.agent_registered":da,"mailbox.cleared":fa,"mailbox.purged":pa};function ha(e){let t=e.payload;Mi.getState().setSnapshot(t.worktrees??[],t.baseBranch??``)}function ga(e){let t=e.payload;Mi.getState().pushEvent(t)}function _a(e){let t=e.payload;Mi.getState().setOrphans(t.orphans??[],t.canClean??!1,t.reason)}function va(e){let t=e.payload;Mi.getState().setCleanResult({...t,at:Date.now()})}function ya(e){let t=e.payload;Mi.getState().setMergeResult({...t,at:Date.now()})}function ba(e){let t=e.payload;Mi.getState().setDiff(t.dir,t.summary)}function xa(e){X.getState().applyEvent(e.payload);let t=or(`subagent.event`,e.payload);t&&(ur.getState().pushEvent(t),ur.getState().setActive(!0))}function Sa(e){let t=e.payload;X.setState({fleetConcurrency:t.fleetConcurrency,fleetConcurrencyMax:t.fleetConcurrencyMax})}function Ca(e){let t=e.payload;Ei.getState().setCurrentSession({clientType:t.clientType,clientId:t.clientId,agentCount:t.agentCount,model:t.model,mode:t.mode,toolCalls:t.toolCalls,inputTokens:t.inputTokens,outputTokens:t.outputTokens,cacheTokens:t.cacheTokens,costUsd:t.costUsd,timestamp:t.timestamp})}function wa(e){let t=e.payload;Ei.getState().setLiveSessions(t?.sessions??[]);let n=or(`sessions.status_update`,e.payload);n&&(ur.getState().pushEvent(n),ur.getState().setActive(!0))}var Ta={"worktree.state":ha,"worktree.event":ga,"worktree.orphans":_a,"worktree.cleanup_result":va,"worktree.merge_result":ya,"worktree.diff_result":ba,"subagent.event":xa,"fleet.concurrency_update":Sa,"client.status_update":Ca,"sessions.status_update":wa};function Ea(e){if(!e||e.length===0)return;let t=e.map(e=>e.status);return t.some(e=>e===`failed`)?`failed`:t.every(e=>e===`completed`||e===`skipped`)?`completed`:t.some(e=>e===`paused`)?`paused`:`running`}function Da(e){let t=e.payload,n=Array.isArray(t.phases)?t.phases:void 0,r=Ea(n);xr.getState().setState({phases:n,activePhaseId:typeof t.activePhaseId==`string`?t.activePhaseId:void 0,overallPercent:typeof t.overallPercent==`number`?t.overallPercent:void 0,autonomous:typeof t.autonomous==`boolean`?t.autonomous:void 0,title:typeof t.title==`string`?t.title:void 0,goal:typeof t.goal==`string`?t.goal:void 0,status:r,lastError:r===`failed`?xr.getState().lastError:null})}function Oa(e){let t=e.payload,n={totalPhases:typeof t.totalPhases==`number`?t.totalPhases:0,completed:typeof t.completed==`number`?t.completed:0,failed:typeof t.failed==`number`?t.failed:0,totalTasks:typeof t.totalTasks==`number`?t.totalTasks:0,completedTasks:typeof t.completedTasks==`number`?t.completedTasks:0,failedTasks:typeof t.failedTasks==`number`?t.failedTasks:0};xr.getState().setState({progress:n,overallPercent:typeof t.percentComplete==`number`?Math.round(t.percentComplete):void 0,status:n.failed>0||n.failedTasks>0?`failed`:`running`,lastEvent:`progress`})}function ka(e){let t=e.payload,n=typeof t.title==`string`&&t.title?t.title:`AutoPhase`,r=typeof t.error==`string`&&t.error?t.error:void 0;if(e.type===`autophase.paused`){xr.getState().setState({status:`paused`,autonomous:!1,lastEvent:`paused`}),Z.info(`AutoPhase paused`);return}if(e.type===`autophase.resumed`){xr.getState().setState({status:`running`,autonomous:!0,lastEvent:`resumed`}),Z.info(`AutoPhase resumed`);return}if(e.type===`autophase.stopped`){xr.getState().setState({status:`stopped`,autonomous:!1,lastEvent:`stopped`}),Z.warn(`AutoPhase stopped`);return}if(e.type===`autophase.cleared`){xr.getState().clear();return}if(e.type===`autophase.reverted`){let e=t.ok===!0,n=typeof t.reverted==`number`?t.reverted:0,r=typeof t.reason==`string`?t.reason:void 0;e?Z.success(n>0?`Reverted ${n} commit${n===1?``:`s`}`:`Nothing to revert`):Z.error(`Revert failed: ${r??`unknown error`}`),xr.getState().setState({lastEvent:`reverted`});return}if(e.type===`autophase.saved`){xr.getState().setState({lastEvent:`saved`}),Z.success(`AutoPhase graph saved`);return}if(e.type===`autophase.completed`){xr.getState().setState({status:`completed`,autonomous:!1,overallPercent:100,lastEvent:`completed`,lastError:null}),Z.success(`${n} completed`);return}if(e.type===`autophase.failed`||e.type===`autophase.error`){let e=r??(typeof t.message==`string`?t.message:`${n} failed`);xr.getState().setState({status:`failed`,autonomous:!1,lastEvent:`failed`,lastError:e}),Z.error(e)}}function Aa(e){let t=e.payload;xr.getState().setState({lastEvent:`list`,graphs:Array.isArray(t.graphs)?t.graphs:[]})}function ja(e){let t=e.payload;ui.getState().setGoal(t)}function Ma(e){let t=e.payload;if($n.getState().set(t),t.yolo===!0){let e=G.getState().confirmInfo;e&&e.riskTier!==`destructive`&&e.decisionSource!==`yolo_destructive`&&G.getState().hideConfirm()}}function Na(e){if(!H(e))return;let t=e.payload,n=[`🧠 **Brain** — policy → LLM decision chain`,``,`Autonomy ceiling: \`${t.maxAutoRisk}\` _(change with \`/brain risk <off|low|medium|high|all>\`)_`];if(t.log.length===0)n.push(``,`_No decisions recorded yet this session._`);else{n.push(``,`Recent decisions (${t.log.length}):`);for(let e of t.log.slice(-10)){let t=Math.max(0,Math.round((Date.now()-e.at)/1e3)),r=t<60?`${t}s`:t<3600?`${Math.round(t/60)}m`:`${Math.round(t/3600)}h`,i=e.question.length>70?`${e.question.slice(0,67)}…`:e.question;n.push(`- \`${r} ago\` **${e.kind}** — ${i}${e.outcome?` → _${e.outcome}_`:``}`)}}i.getState().addMessage({role:`assistant`,content:n.join(`
18
- `)})}function Pa(e){if(!H(e))return;let t=e.payload,n;if(t.decision.type===`answer`){let e=t.decision.rationale&&t.decision.rationale!==t.decision.text?`\n\n_${t.decision.rationale}_`:``;n=`🧠 ${t.decision.text??``}${e}`}else n=t.decision.type===`deny`?`🧠 Denied: ${t.decision.reason??``}`:`🧠 The Brain escalated this question back to you — it needs human judgement.`;i.getState().addMessage({role:`assistant`,content:n})}function Fa(e){if(!H(e))return;let t=e.payload;if(t.event===`brain.intervention`){let e=t.decision?.rationale??t.decision?.text??``,n=t.intervened?`🧠 **Brain intervention** — corrective guidance was sent to the agent.`:`🧠 **Brain check** — a distress signal was reviewed; no action needed.`;i.getState().addMessage({role:`assistant`,content:[n,t.request?.question??``,e?`_${e}_`:``].filter(Boolean).join(`
19
-
20
- `)}),t.intervened&&Z.info(`Brain intervened: agent steered`)}else t.event===`brain.decision_denied`&&Z.warn(`Brain denied: ${t.decision?.reason??t.request?.question??`request`}`)}function Ia(e){let t=e.payload,n=typeof t.kind==`string`?t.kind:typeof t.event==`string`?t.event:`collab.event`;ur.getState().pushEvent({id:`collab_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,kind:`collab:event`,timestamp:Date.now(),source:`collab`,target:typeof t.sessionId==`string`?t.sessionId:`session`,label:n,magnitude:1,data:t,raw:e.payload,color:`hsl(200, 70%, 55%)`,flowGroup:`collab`}),ur.getState().setActive(!0)}function La(e){Ia(e);let t=e.payload;t?.phase===`consumed`?Z.success(`Tool injection applied${t.toolName?` to ${t.toolName}`:``}`):Z.info(`Collab tool injection queued`)}function Ra(e){let t=e.payload?.entry;if(!t)return;let n=typeof t.iteration==`number`?t.iteration:0,r=typeof t.task==`string`?t.task:void 0,i=typeof t.status==`string`?t.status:void 0,a=typeof t.at==`string`?t.at:new Date().toISOString();ui.getState().appendJournalEntry({iteration:n,task:r,status:i,timestamp:a}),ur.getState().pushEvent({id:`eternal_${Date.now()}_${n}`,kind:`eternal:iteration`,timestamp:Date.now(),source:`eternal`,target:`goal`,label:r?`L${n}: ${r}`:`Eternal iteration ${n}`,magnitude:typeof t.costUsd==`number`?t.costUsd:1,data:t,raw:e.payload,color:i===`failure`?`hsl(0, 80%, 55%)`:`hsl(220, 80%, 60%)`,flowGroup:`eternal`}),ur.getState().setActive(!0)}function za(e){let t=e.payload;W.getState().setEnv({cwd:t.cwd,projectRoot:t.projectRoot,projectName:t.projectRoot.split(/[/\\]/).pop()||t.projectRoot}),Ir.getState().setTreeLoading(!0),U().send({type:`files.tree`,payload:{path:t.cwd}})}function Ba(e){let t=e.payload,n=G.getState().refinePanel;if(!n)return;if(t.error){Z.error(`Refinement failed: ${t.error}`);let{original:e}=n;G.getState().setRefinePanel(null),i.getState().addMessage({role:`user`,content:e}),i.getState().setLoading(!0),U().sendMessage(e);return}let a=n.original;if(r(t.refined,a)){G.getState().setRefinePanel(null),i.getState().addMessage({role:`user`,content:a}),i.getState().setLoading(!0),U().sendMessage(a);return}G.getState().setRefinePanel({...n,refined:t.refined,english:t.english})}function Va(e){let t=e.payload;si.getState().setInfo({...t,fetchedAt:Date.now()})}function Ha(e){let t=e.payload;oi.getState().setFiles(t.files??[],t.error??null)}function Ua(e){let t=e.payload;oi.getState().selectedPath===t.path&&oi.getState().setDiff({path:t.path,oldText:t.oldText??``,newText:t.newText??``,binary:t.binary,tooLarge:t.tooLarge,error:t.error})}var Wa={"goal.updated":ja,"prefs.updated":Ma,"autophase.state":Da,"autophase.progress":Oa,"autophase.paused":ka,"autophase.resumed":ka,"autophase.stopped":ka,"autophase.cleared":ka,"autophase.reverted":ka,"autophase.saved":ka,"autophase.completed":ka,"autophase.failed":ka,"autophase.error":ka,"autophase.list":Aa,"brain.status":Na,"brain.answer":Pa,"brain.event":Fa,"collab.event":Ia,"collab.injection.granted":La,"eternal.iteration":Ra,"working_dir.changed":za,"model.refine_result":Ba,"git.info":Va,"git.changes":Ha,"git.diff":Ua};function Ga(e,t){if(t)return!0;try{return new URLSearchParams(e).get(`shell`)===`desktop`}catch{return!1}}function Ka(){return typeof window>`u`?!1:Ga(window.location.search,!!window.wrongstackDesktopHost)}var qa={chat:`chat`,agents:`chat`,history:`sessions`,files:`files`,changes:`changes`,mailbox:`mailbox`,skills:`skill`,worktrees:`chat`,design:`design-gallery`,officemap:`officemap`},Ja={chat:`chat`,files:`files`,changes:`changes`,sessions:`history`,mailbox:`mailbox`,skill:`skills`,officemap:`officemap`,"design-gallery":`design`},Ya={1:`chat`,2:`agents`,3:`history`,4:`files`,5:`changes`,6:`mailbox`,7:`skills`,8:`officemap`,0:`design`},Xa={chat:`Ctrl+1`,agents:`Ctrl+2`,history:`Ctrl+3`,files:`Ctrl+4`,changes:`Ctrl+5`,mailbox:`Ctrl+6`,skills:`Ctrl+7`,worktrees:`Ctrl+Shift+W`,design:`Ctrl+0`,officemap:`Ctrl+8`};function Za(e){return qa[e]??`chat`}function Qa(e){return Xa[e]??``}function $a(e){let t=G.getState();t.currentView!==e&&t.setCurrentView(e)}function Q(e){let t=G.getState();t.setSidebarOpen(!0),t.selectActivity(e),$a(Za(e))}function eo(e){let t=G.getState();if(!t.sidebarOpen)t.setSidebarOpen(!0),t.selectActivity(e);else if(t.activeActivity===e){t.setSidebarOpen(!1);return}else t.selectActivity(e);$a(Za(e))}function to(e){let t=G.getState();if(t.currentView===e){Q(`chat`);return}t.setSidebarOpen(!1),$a(e)}function no(e){let t=Ja[e];if(t){Q(t);return}G.getState().setSidebarOpen(!1),$a(e)}function ro(e){if(typeof e!=`string`)return Date.now();let t=Date.parse(e);return Number.isFinite(t)?t:Date.now()}function io(e){return`replay_${Date.now()}_${e}`}function ao(e){return typeof e==`string`?e:JSON.stringify(e)}function oo(e){return typeof e==`string`?e:Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`&&e.type===`text`&&typeof e.text==`string`).map(e=>e.text).join(`
21
- `):``}function so(e){let t=[],n=new Map,r=0,i=(e,n,r)=>{n&&t.push({id:io(t.length),role:e,content:n,timestamp:r})},a=(e,n)=>{let i=e.trim();i&&(r+=1,t.push({id:io(t.length),role:`system`,content:``,timestamp:n,thinkingLog:{iteration:r,text:i,startedAt:n,durationMs:0,replayed:!0}}))};for(let r of e){if(r.role!==`user`&&r.role!==`assistant`&&r.role!==`system`)continue;let e=r.role,o=ro(r.ts);if(typeof r.content==`string`){i(e,r.content,o);continue}if(!Array.isArray(r.content))continue;let s=``,c=[];for(let a of r.content){if(a.type===`thinking`&&typeof a.thinking==`string`){c.push(a.thinking);continue}if(a.type===`text`&&typeof a.text==`string`){s+=(s?`
22
- `:``)+a.text;continue}if(a.type===`tool_use`){i(e,s,o),s=``;let r=String(a.id??``),c={id:io(t.length),role:`tool`,content:``,toolName:String(a.name??`tool`),toolInput:a.input,toolUseId:r,timestamp:o};t.push(c),r&&n.set(r,c);continue}if(a.type===`tool_result`){let e=String(a.tool_use_id??``),t=n.get(e);t&&(t.toolResult=ao(a.content),t.isError=!!a.is_error)}}i(e,s,o),e===`assistant`&&c.length>0&&a(c.join(`
23
-
24
- `),o)}return t}var co=new Set;function lo(e,t=140){return e.length>t?`${e.slice(0,t-1)}…`:e}function uo(){sr.flush(`__thinking__`);let e=W.getState().iteration;i.getState().flushThinkingLog(Math.max(1,e?.index??1)),i.getState().clearThinking()}function fo(e){let t=or(`session.start`,e.payload);t&&(ur.getState().pushEvent(t),ur.getState().setActive(!0));let n=e.payload,r=W.getState().session?.id,a=!r||r!==n.sessionId||n.reset;if(n.needsSetup&&no(`setup`),a?W.getState().startSession({id:n.sessionId,startedAt:Date.now(),model:n.model,provider:n.provider}):W.getState().setSession({id:n.sessionId,startedAt:W.getState().session?.startedAt??Date.now(),model:n.model,provider:n.provider}),W.getState().setEnv({maxContext:n.maxContext,projectRoot:n.projectRoot??``,projectName:n.projectName,cwd:n.cwd,mode:n.mode,contextMode:n.contextMode,inputCost:n.inputCost,outputCost:n.outputCost,cacheReadCost:n.cacheReadCost}),J.getState().setConfig({provider:n.provider,model:n.model}),a){!n.needsSetup&&Ka()&&dr({sidebarOpen:!1}),sr.dropAll(),i.getState().clearMessages(),i.getState().setBoundSessionId(n.sessionId),G.getState().setSearchActiveMessageId(null),i.getState().setLoading(!1),W.setState({todos:[]}),vr(`ready`);let e=X.getState();if(n.clearedSessionId){let t=new Map;for(let[r,i]of e.agents)i.sessionId!==n.clearedSessionId&&t.set(r,i);X.setState({agents:t})}else e.clear();Ir.getState().setTreeLoading(!0),U().send({type:`files.tree`,payload:{path:W.getState().cwd}})}let o=n.replayMessages;if(o&&o.length>0&&(i.getState().setMessages(so(o)),i.getState().setBoundSessionId(n.sessionId)),o){let e=n.replayUsage;if(e){let t=W.getState(),n=e.input??0,r=e.output??0,i=e.cacheRead??0,a=e.cacheWrite??0;W.setState({totalTokens:{input:n,output:r,cacheRead:i,cacheWrite:a},cost:(n*t.inputCost+r*t.outputCost+i*t.cacheReadCost)/1e6})}a&&!n.needsSetup&&(Ka()?dr({sidebarOpen:!1}):G.getState().currentView!==`chat`&&Q(`chat`)),typeof window<`u`&&window.matchMedia?.(`(max-width: 768px)`).matches&&G.getState().setSidebarOpen(!1)}}function po(e){if(!H(e))return;let t=e.payload,n=e=>e.toLocaleString(),r=[...t.tools.breakdown].sort((e,t)=>t.tokens-e.tokens).slice(0,8),a=[...t.messages.breakdown].sort((e,t)=>t.tokens-e.tokens).slice(0,8);i.getState().addMessage({role:`assistant`,content:[`📊 **Context breakdown** (heuristic — 4 chars/token)`,``,`**Total estimate:** ${n(t.total)} tokens`,`• System prompt: ${n(t.systemPrompt)}`,`• Tool schemas: ${n(t.tools.total)} (${t.tools.count} tools)`,`• Messages: ${n(t.messages.total)} (${t.messages.count} messages)`,``,`**Top tool schemas:**`,...r.map(e=>` · ${e.name}: ${n(e.tokens)}`),``,`**Top messages:**`,...a.map(e=>` · #${e.index} ${e.role}: ${n(e.tokens)} — ${e.preview||`(empty)`}`)].join(`
25
- `)})}function mo(e){let t=e.payload;t.success?Z.success(t.message):Z.error(t.message),U(J.getState().wsUrl).listSavedProviders()}function ho(e){if(!H(e))return;ar(e);let t=e.payload,n=t.reductions.length?t.reductions.map(e=>`${e.phase}: ${e.saved}`).join(`, `):`no-op`;t.repaired&&(n+=`; repaired ${t.repaired.removedToolUses?.length??0} tool_use, ${t.repaired.removedToolResults?.length??0} tool_result, ${t.repaired.removedMessages} empty messages`),i.getState().addMessage({role:`assistant`,content:`🗜️ Context compacted: ${t.before} → ${t.after} tokens (saved ~${t.saved}). ${n}`}),W.setState({lastInputTokens:t.after})}function go(e){if(!H(e))return;ar(e);let t=e.payload,n,r;t.budget&&t.budget.availableInputTokens>0?(n=Math.min(100,Math.max(0,Math.round(t.budget.load*100))),r=`input budget`):(n=t.maxContext>0?Math.min(100,Math.max(0,Math.round(t.tokens/t.maxContext*100))):0,r=`context`),i.getState().addMessage({role:`assistant`,content:`Compaction failed at ${t.level} (${n}% ${r}): ${t.message}`,isError:t.fatal}),Z.error(`Compaction failed: ${t.message}`)}function _o(e){if(!H(e))return;ar(e);let t=e.payload,n=oo(t.content),r=t.usage,a=(r.input??0)+(r.cacheWrite??0)-(r.cacheRead??0);a>0&&W.setState({lastInputTokens:a}),W.getState().updateUsage(t.usage);let{inputCost:o,outputCost:s,cacheReadCost:c}=W.getState(),l=(t.usage.input*o+t.usage.output*s+(t.usage.cacheRead??0)*c)/1e6;l>0&&W.getState().addCost(l),t.stopReason!==`tool_use`&&t.stopReason!==`tool_call`&&i.getState().setLoading(!1);let u=i.getState().currentAssistantMessageId;if(u){sr.flush(u);let e=i.getState().messages.find(e=>e.id===u)?.content??``;n.trim()&&(e.trim()?n.startsWith(e)&&n.length>e.length&&i.getState().updateMessage(u,{content:n}):i.getState().updateMessage(u,{content:n})),i.getState().finalizeMessage(u),t.usage.output>0&&i.getState().updateMessage(u,{usage:t.usage})}else if(n.trim()){let e=i.getState().addMessage({role:`assistant`,content:n,usage:t.usage.output>0?t.usage:void 0});i.getState().finalizeMessage(e)}i.getState().setCurrentAssistantMessage(null),sr.flush(`__thinking__`),i.getState().clearThinking()}function vo(e){if(!H(e))return;ar(e);let t=e.payload;sr.flush(`__thinking__`),i.getState().flushThinkingLog(t.index),i.getState().clearThinking();let n=W.getState().iteration;n&&W.getState().setIteration({index:t.index,max:n.max})}function yo(e){if(!H(e))return;let t=e.payload;i.getState().addMessage({role:`assistant`,content:`Iteration limit reached: ${t.currentIterations}/${t.currentLimit}.`,isError:!0}),Z.warn(`Iteration limit reached (${t.currentIterations}/${t.currentLimit})`)}function bo(e){if(!H(e))return;let t=e.payload,n=Math.max(0,Math.round(t.delayMs/100)/10);Z.warn(`${t.providerId} retry ${t.attempt} after ${n}s (${t.status})`)}function xo(e){if(!H(e))return;let t=e.payload;i.getState().addMessage({role:`assistant`,content:[`Provider error from \`${t.providerId}\` (${t.status}).`,t.description,t.retryable?`_Retryable; WrongStack may recover automatically._`:``].filter(Boolean).join(`
26
-
27
- `),isError:!0}),Z.error(`${t.providerId} provider error (${t.status})`)}function So(e){if(!H(e))return;let t=e.payload,n=`${t.from.providerId}/${t.from.model}`,r=`${t.to.providerId}/${t.to.model}`;i.getState().addMessage({role:`assistant`,content:`Provider fallback: \`${n}\` returned ${t.status}; switching to \`${r}\`${t.providerSwitched?` with provider change`:``}.`}),Z.warn(`Fallback to ${r}`)}function Co(e){if(!H(e))return;ar(e);let t=e.payload;Z.warn(`Provider stream event skipped: ${t.eventType}`),i.getState().addMessage({role:`assistant`,content:`Provider stream warning (${t.eventType}): ${t.message}`,isError:!0})}function wo(e){if(!H(e))return;ar(e);let t=e.payload,n=t.tools||t.kind||`assistant response`;i.getState().addMessage({role:`assistant`,content:`Loop guard triggered: ${n} repeated ${t.repeatCount} time(s) at iteration ${t.iteration}.`,isError:!0}),Z.warn(`Loop guard triggered`)}function To(e){if(!H(e))return;ar(e);let t=e.payload,n=lo(t.task,180);i.getState().addMessage({role:`assistant`,content:`Delegating to \`${t.target}\`: ${n}`}),X.getState().pushAgentTimelineEntry({subagentId:t.target,agentName:t.target,content:n,kind:`status`,iteration:0,ts:new Date().toISOString(),status:`delegating`})}function Eo(e){if(!H(e))return;ar(e);let t=e.payload,n=Math.max(0,Math.round(t.durationMs/100)/10),r=typeof t.costUsd==`number`&&t.costUsd>0?` · $${t.costUsd.toFixed(4)}`:``,a=`${t.iterations} iteration(s), ${t.toolCalls} tool call(s), ${n}s${r}`;i.getState().addMessage({role:`assistant`,content:[`Delegate ${t.ok?`completed`:`failed`} for \`${t.target}\`${t.status?` (${t.status})`:``}.`,t.summary,a].join(`
28
- `),isError:!t.ok}),X.getState().pushAgentTimelineEntry({subagentId:t.subagentId??t.target,agentName:t.target,content:t.summary,kind:t.ok?`status`:`error`,iteration:t.iterations,ts:new Date().toISOString(),status:t.status??(t.ok?`completed`:`failed`)}),t.ok||Z.warn(`Delegate failed: ${t.target}`)}function Do(e){if(!H(e))return;let t=e.payload,n=`${t.tool}: ${t.pattern}`;t.decision===`always`?Z.success(`Always allowed ${n}`):Z.warn(`Denied ${n}`)}function Oo(e){if(!H(e))return;ar(e);let t=e.payload,n=t.removedToolUses.length+t.removedToolResults.length+t.removedMessages,r=t.beforeMessages!==void 0&&t.afterMessages!==void 0?` Messages: ${t.beforeMessages} -> ${t.afterMessages}.`:``;i.getState().addMessage({role:`assistant`,content:`Context repaired: removed ${n} orphan protocol item(s).${r} tool_use ${t.removedToolUses.length}, tool_result ${t.removedToolResults.length}.`})}function ko(e){if(!H(e))return;ar(e);let t=e.payload;W.getState().setContextUsage(t.tokens,t.maxContext)}function Ao(e){if(!H(e))return;let t=e.payload;W.getState().setEnv({maxContext:t.maxContext})}function jo(e){if(!H(e))return;let t=e.payload;W.getState().setContextUsage(t.used,t.limit);let n=t.limit>0?Math.round(t.used/t.limit*100):0;Z.warn(`Token threshold reached (${n}%)`)}function Mo(e){if(!H(e))return;let t=e.payload.model||`<unknown>`;co.has(t)||(co.add(t),Z.warn(`Cost estimate unavailable for ${t}`))}function No(e){if(!H(e))return;let t=e.payload;i.getState().addMessage({role:`assistant`,content:`Session ${t.sessionId} is damaged: ${t.detail}`,isError:!0}),Z.error(`Session damage detected`)}function Po(e){if(!H(e))return;let t=e.payload;i.getState().addMessage({role:`assistant`,content:`Session rewound to prompt #${t.toPromptIndex}. Removed ${t.removedEvents} event(s); reverted ${t.revertedFiles.length} file(s).`}),Z.info(`Session rewound`)}function Fo(e){if(!H(e))return;let t=e.payload;Z.success(`Checkpoint #${t.promptIndex} written (${t.fileCount} file(s))`)}function Io(e){if(!H(e))return;let t=e.payload;ur.getState().pushEvent({id:`inflight_${Date.now()}`,kind:`session:start`,timestamp:Date.now(),source:`session`,target:`leader`,label:`In-flight: ${t.context}`,magnitude:1,data:t,raw:e.payload,flowGroup:`session`})}function Lo(e){H(e)&&e.payload.reason===`recovered`&&Z.info(`Recovered previous in-flight operation`)}function Ro(){J.getState().setWsConnected(!1)}function zo(e){if(!H(e))return;let t=e.payload;W.getState().setContextModes(t.modes.map(e=>({id:e.id,name:e.name,description:e.description,thresholds:e.thresholds,preserveK:e.preserveK,eliseThreshold:e.eliseThreshold,custom:e.custom}))),W.getState().setEnv({contextMode:t.activeId})}function Bo(e){if(!H(e))return;let t=e.payload;W.getState().setEnv({contextMode:t.id})}function Vo(e){let t=e.payload;di.getState().setEntries(t.sessions??[],t.error??null)}function Ho(e){if(!H(e))return;let t=e.payload;uo(),i.getState().addMessage({role:`assistant`,content:`[${t.phase}] ${t.message}`,isError:!0}),i.getState().setLoading(!1)}var Uo={"context.debug":po,"key.operation_result":mo,"context.compacted":ho,"compaction.failed":go,"provider.response":_o,"iteration.completed":vo,"iteration.limit_reached":yo,"provider.retry":bo,"provider.error":xo,"provider.fallback":So,"provider.stream_error":Co,"tool.loop_detected":wo,"delegate.started":To,"delegate.completed":Eo,"trust.persisted":Do,"context.repaired":Oo,"ctx.pct":ko,"ctx.max_context":Ao,"token.threshold":jo,"token.cost_estimate_unavailable":Mo,"session.end":Ro,"session.damaged":No,"session.rewound":Po,"checkpoint.written":Fo,"in_flight.started":Io,"in_flight.ended":Lo,"context.modes.list":zo,"context.mode.changed":Bo,"sessions.list":Vo,error:Ho};function Wo(e){let t=e.payload;i.getState().addMessage({role:`assistant`,content:[`🛠️ **Registered tools** (${t.tools.length})`,``,...t.tools.map(e=>`• \`${e.name}\`${e.params.length?` (${e.params.join(`, `)})`:``} — ${e.description||`_no description_`}`)].join(`
29
- `)})}function Go(e){let t=e.payload,n=t.text?.trim();i.getState().addMessage({role:`assistant`,content:t.error?`Memory read failed: ${t.error}`:n?`🧠 **Memory** \n\n${n}`:`🧠 **Memory**
30
-
31
- _empty — nothing remembered yet_`})}function Ko(e){let t=e.payload;if(!t.enabled){i.getState().addMessage({role:`assistant`,content:`🎯 **Skills**
32
-
33
- _disabled (config.features.skills = false)_`});return}let n=[`🎯 **Skills** (${t.skills.length})`,``,...t.skills.length===0?[`_none registered_`]:t.skills.map(e=>`• \`${e.name}\`${e.version?` v${e.version}`:``} _(${e.source})_ — ${e.description||e.trigger||`_no description_`}`)];t.error&&n.push(``,`⚠ ${t.error}`),i.getState().addMessage({role:`assistant`,content:n.join(`
34
- `)})}function qo(e){if(!H(e))return;let t=e.payload;i.getState().addMessage({role:`assistant`,content:[`🩺 **Runtime diagnostics**`,``,`**Provider:** \`${t.provider}\` / \`${t.model}\``,`**Mode:** \`${t.mode}\``,`**Session:** \`${t.sessionId}\``,`**CWD:** \`${t.cwd}\``,``,`**Tools:** ${t.tools.count}`,`**Messages:** ${t.messages} · **Todos:** ${t.todos}`,`**Usage:** ${t.usage.input.toLocaleString()} in · ${t.usage.output.toLocaleString()} out${t.usage.cacheRead?` · ${t.usage.cacheRead.toLocaleString()} cache`:``}`,``,`**Features:** memory=${t.features.memory?`✓`:`✗`} · skills=${t.features.skills?`✓`:`✗`} · modelsRegistry=${t.features.modelsRegistry?`✓`:`✗`}`].join(`
35
- `)})}function Jo(e){if(!H(e))return;let t=e.payload,n=Math.floor(t.elapsedMs/1e3),r=n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m ${n%60}s`:`${Math.floor(n/3600)}h ${Math.floor(n%3600/60)}m`;i.getState().addMessage({role:`assistant`,content:[`📈 **Session stats**`,``,`**Session:** \`${t.sessionId}\``,`**Provider/Model:** \`${t.provider}\` / \`${t.model}\``,`**Elapsed:** ${r}`,``,`**Usage:** ${t.usage.input.toLocaleString()} in · ${t.usage.output.toLocaleString()} out`,...t.cache&&t.cache.readTokens>0?[`**Cache:** ${t.cache.readTokens.toLocaleString()} read · ${t.cache.writeTokens.toLocaleString()} write · hit ratio ${(t.cache.hitRatio*100).toFixed(1)}%`]:[],`**Cost:** ${t.cost.toFixed(4)}`,``,`**Messages:** ${t.messages} · **Files read:** ${t.readFiles} · **Tools available:** ${t.tools}`,...t.sideEffectCount?[`**Side effects:** ⚠ ${t.sideEffectCount}`]:[]].join(`
36
- `)})}function Yo(e){if(!H(e))return;let t=e.payload;W.getState().setTodos(t.todos??[])}function Xo(e){let t=e.payload;W.getState().setModes(t.modes.map(e=>({id:e.id,name:e.name,description:e.description}))),W.getState().setEnv({mode:t.activeId})}function Zo(e){fi.getState().handleResult(e.type,e.payload)}var Qo={...qi,...Uo,...Ta,...ma,...Wa,...na,"session.start":e=>{fo(e),ra()},"specs.list":e=>{let t=e.payload;ji.getState().setSpecs(t.specs??[])},"specs.detail":e=>{ji.getState().setDetail(e.payload)},"sdd.board.snapshot":e=>{Oi.getState().setSnapshot(e.payload)},"sdd.board.list":e=>{let t=e.payload;Oi.getState().setBoards(t.boards??[])},"sdd.board.lifecycle_result":e=>{let t=e.payload,n=Oi.getState();n.setLifecycleResult({...t,at:Date.now()}),n.setDestroying(!1)},"sdd.spec.snapshot":e=>{ki.getState().setSnapshot(e.payload)},"sdd.spec.agent_text":e=>{ki.getState().setAgentText(e.payload.text??``)},"sdd.spec.error":e=>{ki.getState().setError(e.payload.message??`Error`)},"sdd.run.started":e=>{ki.getState().setStartedRunId(e.payload.runId??null)},"kanban.list":Zo,"kanban.get":Zo,"kanban.create":Zo,"kanban.duplicate":Zo,"kanban.update":Zo,"kanban.delete":Zo,"kanban.generate":Zo,"kanban.task.add":Zo,"kanban.task.update":Zo,"kanban.task.move":Zo,"kanban.task.copy":Zo,"kanban.task.transfer":Zo,"kanban.task.assign":Zo,"kanban.task.dispatch":Zo,"kanban.task.remove":Zo,"kanban.task.get":Zo,"kanban.column.add":Zo,"kanban.column.remove":Zo,"tools.list":Wo,"memory.list":Go,"skills.list":Ko,"diag.get":qo,"stats.get":Jo,side_effects:e=>{if(!H(e))return;let t=e.payload;Ai.getState().setSideEffects(t.sideEffects??[])},"todos.updated":Yo,"todos.cleared":e=>{H(e)&&W.getState().setTodos([])},"agent.timeline.message":e=>{if(!H(e))return;let t=e.payload;X.getState().pushAgentTimelineEntry({subagentId:t.subagentId,agentName:t.agentName,content:t.content,kind:t.kind,iteration:t.iteration,ts:t.ts,toolName:t.toolName,costUsd:t.costUsd})},"agent.status_changed":e=>{if(!H(e))return;let t=e.payload;X.getState().pushAgentTimelineEntry({subagentId:t.subagentId,agentName:t.agentName,content:t.summary??t.status,kind:`status`,iteration:0,ts:t.ts,status:t.status})},"tasks.updated":e=>{},"plan.updated":e=>{},"modes.list":Xo,"session.checkpoints":e=>{},"process.list":e=>{},"projects.list":e=>{},"projects.added":e=>{},"projects.selected":e=>{}};function $o(e){let t=[];for(let[n,r]of Object.entries(Qo))r&&t.push(e.on(n,r));return()=>{for(let e of t)e()}}function es(){let{autoConnect:e,wsUrl:t}=J(),n=J(e=>e.setWsStatus);(0,q.useEffect)(()=>{if(!e)return;br();let r=U(t),i=!1,a=r.onStatus(e=>{i||n(e)});r.connect().then(()=>{i||r.getPrefs()}).catch(e=>{i||console.warn(JSON.stringify({level:`warn`,event:`webui.ws_connection_failed`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))});let o=$o(r);return()=>{i=!0,o(),a()}},[e,t,n])}function ts(){let{wsUrl:e}=J(),t=U(e),n=(0,q.useCallback)((e,n)=>t.isConnected?t.sendMessage(e,n):null,[t]),r=(0,q.useCallback)(()=>t.sendAbort(),[t]),{hideConfirm:i}=G(),a=(0,q.useCallback)((e,n)=>{t.sendConfirm(e,n),i()},[t,i]),o=(0,q.useCallback)((e,n)=>t.switchModel(e,n),[t]),s=(0,q.useCallback)(()=>t.listProviders(),[t]),c=(0,q.useCallback)(e=>t.listProviderModels(e),[t]),l=(0,q.useCallback)(()=>t.listSavedProviders(),[t]),u=(0,q.useCallback)((e,n,r)=>t.addKey(e,n,r),[t]),d=(0,q.useCallback)((e,n,r)=>t.updateKey(e,n,r),[t]),f=(0,q.useCallback)((e,n)=>t.deleteKey(e,n),[t]),p=(0,q.useCallback)((e,n)=>t.setActiveKey(e,n),[t]),m=(0,q.useCallback)((e,n,r,i)=>t.addProvider(e,n,r,i),[t]),h=(0,q.useCallback)(e=>t.removeProvider(e),[t]),g=(0,q.useCallback)(e=>{di.getState().setLoading(!0),t.listSessions(e)},[t]),_=(0,q.useCallback)(e=>{di.getState().removeEntry(e),t.deleteSession(e)},[t]),v=(0,q.useCallback)((e,n)=>{di.getState().updateEntryName(e,n),t.renameSession(e,n)},[t]),y=(0,q.useCallback)(e=>t.resumeSessionById(e),[t]),b=(0,q.useCallback)(()=>t.saveSession(),[t]),x=(0,q.useCallback)(()=>t.listTools(),[t]),S=(0,q.useCallback)(()=>t.listMemory(),[t]),C=(0,q.useCallback)(()=>t.listSkills(),[t]),w=(0,q.useCallback)(()=>t.getDiag(),[t]),T=(0,q.useCallback)(()=>t.getStats(),[t]),E=(0,q.useCallback)(()=>t.getPlan(),[t]),D=(0,q.useCallback)(()=>t.listModes(),[t]),O=(0,q.useCallback)(e=>t.switchMode(e),[t]),k=(0,q.useCallback)(()=>t.listContextModes(),[t]),A=(0,q.useCallback)(e=>t.switchContextMode(e),[t]),j=(0,q.useCallback)(e=>t.createContextMode(e),[t]),M=(0,q.useCallback)((e,n)=>t.updateContextMode(e,n),[t]),N=(0,q.useCallback)(e=>t.deleteContextMode(e),[t]),P=(0,q.useCallback)(()=>t.repairContext(),[t]),F=(0,q.useCallback)(e=>t.refineModel(e),[t]),I=(0,q.useCallback)(e=>t.switchAutonomy(e),[t]),L=(0,q.useCallback)(e=>t.updatePrefs(e),[t]);return{client:t,sendMessage:n,sendAbort:r,sendConfirm:a,switchModel:o,listProviders:s,listProviderModels:c,listSavedProviders:l,addKey:u,updateKey:d,deleteKey:f,setActiveKey:p,addProvider:m,removeProvider:h,listSessions:g,deleteSession:_,renameSession:v,resumeSession:y,saveSession:b,listTools:x,listMemory:S,listSkills:C,getDiag:w,getStats:T,getPlan:E,listModes:D,switchMode:O,listContextModes:k,switchContextMode:A,createContextMode:j,updateContextMode:M,deleteContextMode:N,repairContext:P,toggleAutoPhaseAutonomous:(0,q.useCallback)(e=>{t.send({type:`autophase.toggleAutonomous`,payload:{autonomous:e}})},[t]),startAutoPhase:(0,q.useCallback)((e,n,r=!0)=>{t.send({type:`autophase.start`,payload:{title:e,phases:n,autonomous:r}})},[t]),pauseAutoPhase:(0,q.useCallback)(()=>{t.send({type:`autophase.pause`,payload:{}})},[t]),resumeAutoPhase:(0,q.useCallback)(()=>{t.send({type:`autophase.resume`,payload:{}})},[t]),stopAutoPhase:(0,q.useCallback)(()=>{t.send({type:`autophase.stop`,payload:{}})},[t]),selectAutoPhase:(0,q.useCallback)(e=>{t.send({type:`autophase.selectPhase`,payload:{phaseId:e}})},[t]),switchAutonomy:I,updatePrefs:L,refineModel:F}}var ns=new Set([`chat`,`settings`,`autophase`,`specs`,`kanban`,`sddboard`,`sddwizard`,`files`,`changes`,`sessions`,`setup`,`skill`,`officemap`,`mailbox`,`debug`,`design-gallery`,`refresh-debug`,`analytics`]),rs=new Set([`autophase`,`goal`,`fleet`,`work`,`worktrees`,`collab`]),is=new Set([`todos`,`tasks`,`plan`]);function as(){if(typeof window>`u`)return;let e=window.wrongstackDesktopHost;if(!e?.setPrefs)return;let t=$n.getState();e.setPrefs({yolo:t.yolo,nextPrediction:t.nextPrediction,contextAutoCompact:t.contextAutoCompact})}function os(e){typeof window>`u`||window.wrongstackDesktopHost?.setReady?.(e)}function ss(e,t,n){typeof window>`u`||typeof e!=`string`||window.wrongstackDesktopHost?.ackCommand?.(e,t,n)}function cs(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}var ls=e=>{let t=new Date(e);return`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`};function us(e,t){let n=new Date(e),r=new Date(t),i=new Date(t-864e5);return ls(e)===ls(r.getTime())?`Today`:ls(e)===ls(i.getTime())?`Yesterday`:n.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,year:n.getFullYear()===r.getFullYear()?void 0:`numeric`})}function ds(e,t=Date.now()){let r=[];for(let t=0;t<e.length;t++){let i=n(e[t]);if(i.role===`tool`){let e=r[r.length-1];e&&e.kind===`tools`?e.tools.push(i):r.push({kind:`tools`,tools:[i],key:i.id})}else{let n=e[t-1];r.push({kind:`msg`,message:i,isFirst:!n||n.role!==i.role})}}let i=[];for(let e of r){if(e.kind===`msg`&&e.message.role===`user`){i.push({kind:`user`,message:e.message,key:e.message.id});continue}let t=i[i.length-1];if(t&&t.kind===`agent`)t.items.push(e);else{let t=e.kind===`msg`?e.message.id:e.key;i.push({kind:`agent`,items:[e],key:t})}}let a=e=>{if(e.kind===`user`)return e.message.timestamp;let t=n(e.items[0]);return t.kind===`msg`?t.message.timestamp:t.tools[0]?.timestamp??0},o=[],s=null;for(let e=0;e<i.length;e++){let r=n(i[e]),c=a(r),l=ls(c);if(l!==s&&(o.push({kind:`day`,key:`day-${l}-${e}`,label:us(c,t)}),s=l),r.kind===`user`){o.push({kind:`user`,key:r.key,message:r.message});continue}let u=e===i.length-1,d=r.items.map((e,t)=>{let n=t>0;return e.kind===`msg`?{kind:`msg`,key:e.message.id,message:e.message,isFirst:!n&&e.isFirst,isContinuation:n}:{kind:`tools`,key:e.key,tools:e.tools,isContinuation:n,isLastGroup:t===r.items.length-1,hasRunningTool:e.tools.some(e=>e.toolResult===void 0)}});o.push({kind:`agent`,key:r.key,items:d,isLastTurn:u})}return o}var fs={0:``,1:`▏`,2:`▎`,3:`▍`,4:`▌`,5:`▋`,6:`▊`,7:`▉`,8:`█`};function ps(e){return e>=75?`bg-destructive`:e>=60?`bg-[hsl(var(--warning))]`:`bg-[hsl(var(--success))]`}function ms(e){return e>=75?`text-destructive`:e>=60?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`}function hs(e){return Number.isFinite(e)?Math.max(0,Math.min(100,e)):0}function gs({pct:e,tokens:t,maxTokens:n,segments:r=10,showTokens:i=!0,className:a,onClick:o}){let{t:s}=z(),c=hs(e),l=Math.round(c/100*r*8),u=[],d=l;for(let e=0;e<r;e++){let e=Math.min(8,d);u.push({fill:e}),d-=e}let f=`${Math.round(c)}%`,p=i&&t!==void 0&&n!==void 0&&n>0?` ${cs(t)}/${cs(n)}`:``;return(0,Y.jsxs)(`span`,{className:K(`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-mono font-medium shrink-0`,o&&`cursor-pointer hover:ring-1 hover:ring-ring transition-shadow`,ms(c),c>=75?`bg-red-500/10`:c>=60?`bg-amber-500/10`:`bg-emerald-500/10`,a),title:(t!==void 0&&n!==void 0?s(`activity:context.barWithTokens`,{tokens:t.toLocaleString(),max:n.toLocaleString(),pct:f}):s(`activity:context.barPct`,{pct:f}))+(o?s(`activity:context.barClick`):``),onClick:o?e=>{e.stopPropagation(),o()}:void 0,onKeyDown:o?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),o())}:void 0,role:o?`button`:void 0,tabIndex:o?0:void 0,children:[(0,Y.jsx)(`span`,{className:`inline-flex font-mono text-[10px] leading-none tracking-tight`,children:u.map((e,t)=>(0,Y.jsx)(`span`,{className:K(`tabular-nums w-[0.55em] text-center`,e.fill>0?ms(c):`text-muted-foreground/30`),children:fs[e.fill]??` `},t))}),(0,Y.jsx)(`span`,{children:f}),p&&(0,Y.jsx)(`span`,{className:`tabular-nums`,children:p})]})}function _s({pct:e,tokens:t,maxTokens:n,showTokens:r=!0,className:i,onClick:a}){let{t:o}=z(),s=hs(e),c=`${Math.round(s)}%`,l=r&&t!==void 0&&n!==void 0&&n>0?` ${cs(t)}/${cs(n)}`:``;return(0,Y.jsxs)(`span`,{className:K(`inline-flex items-center gap-1.5`,a&&`cursor-pointer hover:opacity-80 transition-opacity`,i),title:(t!==void 0&&n!==void 0?o(`activity:context.barWithTokens`,{tokens:t.toLocaleString(),max:n.toLocaleString(),pct:c}):o(`activity:context.barPct`,{pct:c}))+(a?o(`activity:context.barClick`):``),onClick:a?e=>{e.stopPropagation(),a()}:void 0,onKeyDown:a?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),a())}:void 0,role:a?`button`:void 0,tabIndex:a?0:void 0,children:[(0,Y.jsx)(`span`,{className:`h-1.5 w-16 overflow-hidden rounded-full bg-muted shrink-0`,children:(0,Y.jsx)(`span`,{className:K(`h-full rounded-full transition-all duration-300`,ps(s)),style:{width:`${Math.max(2,s)}%`}})}),(0,Y.jsx)(`span`,{className:K(`text-[11px] font-mono tabular-nums font-medium`,ms(s)),children:c}),l&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:l})]})}var vs={text:{labelKey:`kindAssistant`,icon:yt,tone:`text-primary`,bubble:`border-border bg-card`},thinking:{labelKey:`kindThinking`,icon:Jn,tone:`text-violet-500`,bubble:`border-violet-500/20 bg-violet-500/5`},tool_use:{labelKey:`kindToolCall`,icon:Ne,tone:`text-amber-500`,bubble:`border-amber-500/20 bg-amber-500/5`},tool_result:{labelKey:`kindToolResult`,icon:gt,tone:`text-emerald-500`,bubble:`border-emerald-500/20 bg-emerald-500/5`},error:{labelKey:`kindError`,icon:un,tone:`text-destructive`,bubble:`border-destructive/25 bg-destructive/5`},status:{labelKey:`kindStatus`,icon:S,tone:`text-muted-foreground`,bubble:`border-border bg-muted/25`},system:{labelKey:`kindSystem`,icon:In,tone:`text-muted-foreground`,bubble:`border-border bg-muted/25`}};function ys(e){let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):``}function bs(e){return e.map(e=>{let t=vs[e.kind]??vs.status,n=ys(e.ts),r=e.toolName?` [${e.toolName}]`:``;return`[${n}] ${e.agentName} · ${B.t(`activity:transcript.${t.labelKey}`)}${r}\n${e.content}`}).join(`
37
-
38
- `)}function xs({entries:e,agentName:t,className:n,compact:r=!1,maxHeightClassName:i,title:a,showHeader:o=!0}){let{t:s}=z(),[c,l]=(0,q.useState)(!1),u=(0,q.useMemo)(()=>bs(e),[e]),d=(0,q.useCallback)(async()=>{if(u)try{await navigator.clipboard.writeText(u),l(!0),setTimeout(()=>l(!1),1600)}catch{}},[u]);return(0,Y.jsxs)(`div`,{className:K(`rounded-lg border bg-card`,n),children:[o&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b bg-muted/25 px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Y.jsx)(wt,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,Y.jsx)(`span`,{className:`truncate text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:a??s(`activity:transcript.title`)}),t&&(0,Y.jsx)(`span`,{className:`truncate text-[10px] text-muted-foreground`,children:t}),(0,Y.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[9px] tabular-nums text-muted-foreground`,children:e.length})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:d,disabled:e.length===0,className:`flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40`,title:s(`activity:transcript.copyTitle`),children:[c?(0,Y.jsx)(gt,{className:`h-3 w-3 text-emerald-500`}):(0,Y.jsx)(bt,{className:`h-3 w-3`}),s(c?`common:action.copied`:`common:action.copy`)]})]}),(0,Y.jsx)(`div`,{className:K(`space-y-2 overflow-y-auto p-2`,i??(r?`max-h-72`:`max-h-[32rem]`)),children:e.length===0?(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed border-border p-3 text-center text-xs text-muted-foreground`,children:s(`activity:transcript.empty`)}):e.map(e=>{let t=vs[e.kind]??vs.status,n=t.icon;return(0,Y.jsxs)(`div`,{className:K(`rounded-md border px-3 py-2`,t.bubble,r?`space-y-1`:`space-y-1.5`),children:[(0,Y.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Y.jsx)(n,{className:K(`h-3.5 w-3.5 shrink-0`,t.tone)}),(0,Y.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium uppercase tracking-wider text-muted-foreground`,children:s(`activity:transcript.${t.labelKey}`)}),e.toolName&&(0,Y.jsx)(`span`,{className:`min-w-0 truncate rounded bg-background/70 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:e.toolName}),(0,Y.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] tabular-nums text-muted-foreground`,children:ys(e.ts)})]}),(0,Y.jsx)(`pre`,{className:K(`whitespace-pre-wrap break-words font-mono text-foreground/85`,r?`text-[10px] leading-relaxed`:`text-xs leading-relaxed`),children:e.content})]},e.id)})})]})}var Ss=[` `,`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],Cs=12;function ws(e,t){return t===0?0:Math.min(8,Math.round(e/t*8))}function Ts({bins:e,className:t}){let{t:n}=z(),r=Array.from({length:Cs},(t,n)=>e.at(-(Cs-n))??0),i=Math.max(...r,1);return i===1&&r.every(e=>e===0)?(0,Y.jsx)(`span`,{className:t,"aria-label":n(`common:sparkline.noActivity`),title:n(`common:sparkline.noActivityYet`),children:`—`}):(0,Y.jsx)(`span`,{className:t,"aria-label":n(`common:sparkline.activityMax`,{count:i}),title:n(`common:sparkline.activityPeak`,{count:i}),children:r.map((e,t)=>{let n=ws(e,i),r=Ss[n];return(0,Y.jsx)(`span`,{style:{color:n>=7?`hsl(var(--success))`:`hsl(var(--muted-foreground))`,opacity:n>0?void 0:.3},children:r},t)})})}var Es=_,Ds=F,Os=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)($e,{ref:n,className:K(`fixed inset-0 z-50 bg-black/50 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));Os.displayName=$e.displayName;var ks=Xn(`fixed z-50 gap-4 bg-background shadow-2xl transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-200 data-[state=open]:duration-300`,{variants:{side:{top:`inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top`,bottom:`inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom`,left:`inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-md`,right:`inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-md`}},defaultVariants:{side:`right`}}),As=q.forwardRef(({side:e=`right`,className:t,children:n,...r},i)=>(0,Y.jsxs)(Ds,{children:[(0,Y.jsx)(Os,{}),(0,Y.jsxs)(ee,{ref:i,className:K(ks({side:e}),t),...r,children:[n,(0,Y.jsxs)(Xe,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none`,children:[(0,Y.jsx)(ut,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));As.displayName=ee.displayName;var js=({className:e,...t})=>(0,Y.jsx)(`div`,{className:K(`flex flex-col space-y-1.5 text-left p-4 border-b`,e),...t});js.displayName=`SheetHeader`;var Ms=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(ue,{ref:n,className:K(`text-base font-semibold leading-none tracking-tight`,e),...t}));Ms.displayName=ue.displayName;var Ns=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(Ke,{ref:n,className:K(`text-xs text-muted-foreground`,e),...t}));Ns.displayName=Ke.displayName;function Ps(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function Fs(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}var Is={running:{led:`bg-[hsl(var(--success))]`,pulse:!0,badge:`bg-[hsl(var(--success))]/15 text-[hsl(var(--success))]`},completed:{led:`bg-[hsl(var(--success))]`,pulse:!1,badge:`bg-muted text-muted-foreground`},failed:{led:`bg-destructive`,pulse:!1,badge:`bg-destructive/15 text-destructive`},timeout:{led:`bg-[hsl(var(--warning))]`,pulse:!1,badge:`bg-amber-500/15 text-amber-500`},stopped:{led:`bg-muted-foreground`,pulse:!1,badge:`bg-muted text-muted-foreground`}};function Ls({agent:e,isLeader:t}){let n=Is[e.status],{t:r}=z(),i=e.status===`running`,a=Date.now()-e.startedAt,o=X(t=>t.agentTranscripts.get(e.id)??Xr),s=[...e.toolLog.slice(0,8)].reverse();return(0,Y.jsxs)(`div`,{className:K(`rounded-xl border p-4 space-y-3`,i?`border-primary/20 bg-primary/[0.02]`:`border-border bg-card`,t&&`ring-2 ring-amber-500/30`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:K(`led`,n.led,n.pulse&&`led-pulse`,`mt-0.5`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold`,children:e.name}),t&&(0,Y.jsx)(Nn,{className:`h-3.5 w-3.5 text-amber-500`,"aria-label":r(`activity:fleet.leader`)}),e.extensions>0&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-amber-500/15 text-[10px] text-amber-600 dark:text-amber-400 font-medium`,children:[(0,Y.jsx)(rt,{className:`h-2.5 w-2.5`}),`×`,e.extensions]})]}),(0,Y.jsx)(`span`,{className:K(`inline-block mt-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium`,n.badge),children:r(`activity:fleet.status.${e.status}`)})]})]}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:t&&(0,Y.jsx)(`span`,{className:`text-[9px] bg-amber-500/15 text-amber-600 dark:text-amber-400 px-1.5 py-0.5 rounded`,children:r(`activity:agentsMonitor.leaderBadge`)})})]}),e.description&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2`,children:e.description}),e.budgetWarning&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,Y.jsx)(rt,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r(`activity:fleet.budgetWarning`,{kind:e.budgetWarning.kind,used:e.budgetWarning.used,limit:e.budgetWarning.limit})})]}),e.failureReason&&(0,Y.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-destructive/10 border border-destructive/20 text-xs`,children:(0,Y.jsxs)(`span`,{className:`text-destructive font-medium`,children:[`✗ `,e.failureReason]})}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:agentsMonitor.iters`)}),(0,Y.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.iteration})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:agentsMonitor.tools`)}),(0,Y.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.toolCalls})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:fleet.cost`)}),(0,Y.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:Ps(e.costUsd)})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:fleet.elapsed`)}),(0,Y.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:Fs(a)})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:agentsMonitor.activityBins`)}),(0,Y.jsx)(Ts,{bins:e.sparklineBins,className:`font-mono text-[9px]`})]}),(0,Y.jsx)(gs,{pct:e.ctxPct,tokens:e.ctxTokens,maxTokens:e.maxContext})]}),(e.provider||e.model)&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(Tn,{className:`h-3 w-3`}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(e.currentTool||e.lastTool)&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(Ne,{className:K(`h-3 w-3`,i&&`animate-pulse text-primary`)}),(0,Y.jsx)(`span`,{className:`font-mono`,children:e.currentTool??e.lastTool}),i&&(0,Y.jsx)(R,{className:`h-3 w-3 animate-spin`})]}),(0,Y.jsx)(xs,{entries:o,agentName:e.name,compact:!0,maxHeightClassName:`max-h-80`}),e.partialText&&i&&(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,Y.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:r(`activity:agentsMonitor.streamingOutput`)}),(0,Y.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-3 leading-relaxed`,children:e.partialText})]}),s.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:r(`activity:agentsMonitor.recentTools`)}),(0,Y.jsx)(`div`,{className:`space-y-0.5`,children:s.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-mono`,children:[(0,Y.jsx)(`span`,{className:K(`shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`),children:e.ok?`✓`:`✗`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.name}),(0,Y.jsx)(`span`,{className:`ml-auto tabular-nums text-muted-foreground shrink-0`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(1)}s`:`${e.durationMs}ms`})]},t))})]}),e.finalText&&!i&&(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,Y.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:r(`activity:agentsMonitor.finalOutput`)}),(0,Y.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-4 leading-relaxed`,children:e.finalText})]})]})}function Rs({onClose:e}){let t=X(e=>e.agents),{t:n}=z(),r=X(e=>e.leaderId),[i,a]=(0,q.useState)(0),o=(0,q.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{if(e.id===r)return-1;if(t.id===r)return 1;let n=e.status===`running`?0:1,i=t.status===`running`?0:1;return n===i?e.startedAt-t.startedAt:n-i}),e},[t,r]),s=(0,q.useCallback)(t=>{if(t.key===`Escape`){e();return}if(t.key===`ArrowDown`){t.preventDefault(),a(e=>Math.min(e+1,o.length-1));return}if(t.key===`ArrowUp`){t.preventDefault(),a(e=>Math.max(e-1,0));return}},[o.length,e]),c=o[i]??null;return(0,Y.jsx)(Es,{open:!0,onOpenChange:t=>{t||e()},children:(0,Y.jsxs)(As,{side:`right`,className:`w-[600px] max-w-[90vw] sm:max-w-[90vw] flex flex-col p-0 gap-0`,onKeyDown:s,tabIndex:-1,children:[(0,Y.jsx)(Ms,{className:`sr-only`,children:n(`activity:agentsMonitor.heading`)}),(0,Y.jsx)(Ns,{className:`sr-only`,children:n(`activity:agentsMonitor.heading`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(wt,{className:`h-5 w-5 text-primary`}),(0,Y.jsx)(`h2`,{className:`text-sm font-semibold`,children:n(`activity:agentsMonitor.heading`)}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`activity:agents.totalCount`,{count:o.length})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(e=>Math.max(e-1,0)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:i===0,"aria-label":n(`activity:agentsMonitor.prevAgent`),children:(0,Y.jsx)(Ut,{className:`h-4 w-4`})}),(0,Y.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground font-mono`,children:o.length>0?`${i+1}/${o.length}`:`0/0`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(e=>Math.min(e+1,o.length-1)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:i>=o.length-1,"aria-label":n(`activity:agentsMonitor.nextAgent`),children:(0,Y.jsx)(vn,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors ml-2`,"aria-label":n(`activity:agentsMonitor.closeAria`),children:(0,Y.jsx)(ut,{className:`h-4 w-4`})})]})]}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto p-4`,children:o.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,Y.jsx)(wt,{className:`h-12 w-12 mb-3 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:n(`activity:inspector.noAgentsActive`)})]}):c?(0,Y.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,Y.jsx)(Ls,{agent:c,isLeader:c.id===r})}):null}),o.length>0&&(0,Y.jsxs)(`div`,{className:`border-t bg-card/80 backdrop-blur shrink-0`,children:[(0,Y.jsx)(`div`,{className:`px-4 py-2 flex items-center gap-2 overflow-x-auto`,children:o.map((e,t)=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(t),className:K(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,t===i?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),children:[(0,Y.jsx)(`span`,{className:K(`led`,Is[e.status].led,Is[e.status].pulse&&`led-pulse`,`shrink-0`)}),(0,Y.jsx)(`span`,{children:e.name}),e.id===r&&(0,Y.jsx)(Nn,{className:`h-2.5 w-2.5 text-amber-500 shrink-0`})]},e.id))}),(0,Y.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,Y.jsx)(`span`,{children:n(`activity:agentsMonitor.hintPage`)}),(0,Y.jsx)(`span`,{children:n(`activity:agentsMonitor.hintNavigate`)}),(0,Y.jsx)(`span`,{children:n(`activity:agentsMonitor.hintEsc`)})]})]})]})})}var zs=(0,q.createContext)(void 0);function Bs({children:e,defaultTheme:t=`system`,storageKey:n=`wrongstack-theme`}){let r=J(e=>e.setTheme),[i,a]=(0,q.useState)(()=>typeof window<`u`&&localStorage.getItem(n)||t);(0,q.useEffect)(()=>{let e=window.document.documentElement;if(e.classList.remove(`light`,`dark`),i===`system`){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`;e.classList.add(t)}else e.classList.add(i)},[i]);let o={theme:i,setTheme:e=>{localStorage.setItem(n,e),a(e),r(e)}};return(0,Y.jsx)(zs.Provider,{value:o,children:e})}function Vs(){let e=(0,q.useContext)(zs);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e}var Hs=ke,Us=Ie,Ws=ve,Gs=q.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,Y.jsxs)(me,{ref:i,className:K(`flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent`,t&&`pl-8`,e),...r,children:[n,(0,Y.jsx)(vn,{className:`ml-auto h-4 w-4`})]}));Gs.displayName=me.displayName;var Ks=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(ie,{ref:n,className:K(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...t}));Ks.displayName=ie.displayName;var qs=q.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,Y.jsx)(Jt,{children:(0,Y.jsx)(w,{ref:r,sideOffset:t,className:K(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n})}));qs.displayName=w.displayName;var Js=q.forwardRef(({className:e,inset:t,...n},r)=>(0,Y.jsx)(Ee,{ref:r,className:K(`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0`,t&&`pl-8`,e),...n}));Js.displayName=Ee.displayName;var Ys=q.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,Y.jsxs)(O,{ref:i,className:K(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),checked:n,...r,children:[(0,Y.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,Y.jsx)(Qt,{children:(0,Y.jsx)(gt,{className:`h-4 w-4`})})}),t]}));Ys.displayName=O.displayName;var Xs=q.forwardRef(({className:e,children:t,...n},r)=>(0,Y.jsxs)(Se,{ref:r,className:K(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,Y.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,Y.jsx)(Qt,{children:(0,Y.jsx)(rn,{className:`h-2 w-2 fill-current`})})}),t]}));Xs.displayName=Se.displayName;var Zs=q.forwardRef(({className:e,inset:t,...n},r)=>(0,Y.jsx)(m,{ref:r,className:K(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));Zs.displayName=m.displayName;var Qs=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(M,{ref:n,className:K(`-mx-1 my-1 h-px bg-muted`,e),...t}));Qs.displayName=M.displayName;var $s=({className:e,...t})=>(0,Y.jsx)(`span`,{className:K(`ml-auto text-xs tracking-widest opacity-60`,e),...t});$s.displayName=`DropdownMenuShortcut`;var ec=[{id:`chat`,icon:(0,Y.jsx)(Gt,{size:16}),label:`Session`},{id:`agents`,icon:(0,Y.jsx)(wt,{size:16}),label:`Agents`},{id:`history`,icon:(0,Y.jsx)(kn,{size:16}),label:`History`},{id:`files`,icon:(0,Y.jsx)(he,{size:16}),label:`Files`},{id:`changes`,icon:(0,Y.jsx)(h,{size:16}),label:`Changes`},{id:`mailbox`,icon:(0,Y.jsx)(Et,{size:16}),label:`Mailbox`},{id:`skills`,icon:(0,Y.jsx)(oe,{size:16}),label:`Skills`},{id:`worktrees`,icon:(0,Y.jsx)(Yt,{size:16}),label:`Worktrees`},{id:`design`,icon:(0,Y.jsx)(lt,{size:16}),label:`Design Studio`},{id:`officemap`,icon:(0,Y.jsx)(zn,{size:16}),label:`Office Map`}],tc=[{id:`sddwizard`,icon:(0,Y.jsx)(we,{size:16}),label:`New SDD Project`},{id:`specs`,icon:(0,Y.jsx)(qe,{size:16}),label:`Specs`},{id:`kanban`,icon:(0,Y.jsx)(at,{size:16}),label:`Kanban`},{id:`sddboard`,icon:(0,Y.jsx)(be,{size:16}),label:`Live Board`},{id:`autophase`,icon:(0,Y.jsx)(_e,{size:16}),label:`Phases`},{id:`settings`,icon:(0,Y.jsx)(tn,{size:16}),label:`Settings`}],nc=[`chat`,`agents`,`files`,`changes`,`mailbox`],rc=[...nc,`history`,`skills`,`worktrees`,`officemap`,`design`],ic=132,ac=38;function oc(e){let t=ec.length+tc.length,n=Math.floor(((Number.isFinite(e)?e:720)-ic)/ac);return Math.max(nc.length,Math.min(t,n))}function sc(e){let t=ec.length+tc.length,n=Math.max(nc.length,Math.min(t,Math.floor(e))),r=Math.min(ec.length,n),i=new Set(rc.slice(0,r)),a=ec.map(e=>e.id).filter(e=>i.has(e)),o=ec.map(e=>e.id).filter(e=>!i.has(e)),s=Math.max(0,n-a.length),c=tc.slice(0,s).map(e=>e.id),l=new Set(c);return{visiblePanelIds:a,overflowPanelIds:o,visibleViewIds:c,overflowViewIds:tc.map(e=>e.id).filter(e=>!l.has(e))}}var cc=ec.map(e=>e.id);function lc(){return typeof window>`u`?720:window.visualViewport?.height??window.innerHeight}function uc(e){let[t,n]=(0,q.useState)(lc);return(0,q.useEffect)(()=>{if(!e||typeof window>`u`)return;let t=()=>n(lc());return t(),window.addEventListener(`resize`,t),window.visualViewport?.addEventListener(`resize`,t),()=>{window.removeEventListener(`resize`,t),window.visualViewport?.removeEventListener(`resize`,t)}},[e]),e?oc(t):ec.length+tc.length}function dc({desktopShell:e=!1}){let t=G(e=>e.activeActivity),n=G(e=>e.sidebarOpen),r=G(e=>e.currentView),i=W(e=>e.projectName),a=W(e=>e.cwd),o=J(e=>e.wsConnected),{t:s}=z(),c=(e,t)=>s(`activity:nav.${e}`,t),l=X(e=>Array.from(e.agents.values()).filter(e=>e.status===`running`).length),u=yi(bi),d=G(e=>e.inspectorOpen),f=G(e=>e.inspectorTab),p=uc(e),m=(0,q.useMemo)(()=>sc(p),[p]),h=(0,q.useMemo)(()=>new Set(m.visiblePanelIds),[m.visiblePanelIds]),g=(0,q.useMemo)(()=>new Set(m.overflowPanelIds),[m.overflowPanelIds]),_=(0,q.useMemo)(()=>new Set(m.visibleViewIds),[m.visibleViewIds]),v=(0,q.useMemo)(()=>new Set(m.overflowViewIds),[m.overflowViewIds]),y=e?ec.filter(e=>h.has(e.id)):ec,b=e?ec.filter(e=>g.has(e.id)):[],x=e?tc.filter(e=>_.has(e.id)):tc,S=e?tc.filter(e=>v.has(e.id)):[],C=e=>{if(e===`agents`)return l||void 0;if(e===`mailbox`)return u||void 0};return(0,Y.jsxs)(`div`,{className:K(`flex h-full min-h-0 shrink-0 flex-col border-r bg-card/60`,e?`w-10`:`w-12`),children:[(0,Y.jsxs)(`div`,{className:K(`flex flex-col items-center border-b border-border/50 shrink-0`,e?`pt-2 pb-1.5`:`pt-2.5 pb-2`),children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{Q(`chat`)},title:i?s(`activity:brand.returnToChat`,{name:i}):s(`activity:brand.returnToChatDefault`),className:K(`relative rounded-md bg-primary flex items-center justify-center shadow-[0_0_0_1px_hsl(var(--primary)/0.4),0_2px_8px_-2px_hsl(var(--primary)/0.5)] hover:shadow-[0_0_0_1px_hsl(var(--primary)/0.6),0_3px_12px_-2px_hsl(var(--primary)/0.6)] transition-shadow`,e?`w-7 h-7`:`w-8 h-8`),children:(0,Y.jsx)(rt,{className:K(`text-primary-foreground`,e?`h-3.5 w-3.5`:`h-4 w-4`),strokeWidth:2.4})}),!e&&(0,Y.jsx)(`span`,{className:`mt-1.5 text-[8px] font-semibold tracking-tight text-muted-foreground text-center leading-tight w-10 truncate`,title:a||i||`WrongStack`,children:i||`WS`}),(0,Y.jsx)(`span`,{className:K(`inline-block w-1.5 h-1.5 rounded-full`,e?`mt-1.5`:`mt-1`,o?`bg-[hsl(var(--success))] shadow-[0_0_4px_hsl(var(--success)/0.6)]`:`bg-[hsl(var(--warning))]`),title:s(o?`activity:status.connected`:`activity:status.disconnected`)})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto no-scrollbar flex flex-col items-center pt-2 pb-1`,children:[y.map(r=>(0,Y.jsx)(pc,{compact:e,icon:r.icon,label:`${c(r.id,r.label)} (${Qa(r.id)})`,active:n&&t===r.id,badge:C(r.id),onClick:()=>eo(r.id)},r.id)),x.length>0&&(0,Y.jsx)(`div`,{className:`my-1.5 h-px w-6 bg-border/60 shrink-0`}),x.map(t=>(0,Y.jsx)(pc,{compact:e,icon:t.icon,label:c(t.id,t.label),active:r===t.id,onClick:()=>to(t.id)},t.id))]}),(0,Y.jsx)(`div`,{className:`flex flex-col items-center shrink-0 pt-1 pb-2 border-t border-border/50`,children:(0,Y.jsx)(fc,{compact:e,monitorOpen:d&&(f===`fleet`||f===`agents`),overflowPanels:b,overflowViews:S})})]})}function fc({compact:e=!1,monitorOpen:t,overflowPanels:n,overflowViews:r}){let{theme:i,setTheme:a}=Vs(),{t:o}=z(),s=G(e=>e.activeActivity),c=G(e=>e.sidebarOpen),l=G(e=>e.currentView),u=G(e=>e.inspectorOpen),d=G(e=>e.inspectorTab),f=n.length+r.length,p=n.some(e=>c&&s===e.id),m=r.some(e=>l===e.id),h=p||m,g=e=>{let t=G.getState();t.inspectorOpen&&t.inspectorTab===e?t.setInspectorOpen(!1):(t.setInspectorTab(e),t.setInspectorOpen(!0))};return(0,Y.jsxs)(Hs,{children:[(0,Y.jsx)(Us,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,"aria-label":f>0?o(`activity:menu.moreWithHidden`,{count:f}):o(`activity:menu.moreOptions`),title:e&&f>0?o(`activity:menu.moreCompactHidden`,{count:f}):o(e?`activity:menu.moreCompact`:`activity:menu.moreFull`),className:K(`relative flex items-center justify-center rounded-lg transition-colors`,e?`w-9 h-9`:`w-10 h-10`,`text-muted-foreground hover:text-foreground hover:bg-muted/70`,`data-[state=open]:text-primary data-[state=open]:bg-primary/10`,(t||h)&&`text-primary`),children:[(0,Y.jsx)(`span`,{className:`h-5 w-5 flex items-center justify-center`,children:(0,Y.jsx)(ct,{size:16})}),f>0&&(0,Y.jsx)(`span`,{className:K(`absolute -top-0.5 -right-0.5 min-w-[15px] h-[15px] flex items-center justify-center rounded-full px-1 text-[8px] font-bold leading-none tabular`,h?`bg-primary text-primary-foreground`:`bg-muted-foreground text-background`),children:f>9?`9+`:f}),t&&f===0&&(0,Y.jsx)(`span`,{className:`absolute top-1 right-1 w-1.5 h-1.5 rounded-full bg-primary`})]})}),(0,Y.jsxs)(qs,{side:`right`,align:`end`,sideOffset:8,className:`w-56`,children:[(0,Y.jsxs)(Js,{onSelect:()=>G.getState().setPaletteOpen(!0),children:[(0,Y.jsx)(gn,{size:16}),(0,Y.jsx)(`span`,{children:o(`activity:menu.commandPalette`)}),(0,Y.jsx)($s,{children:`⌘K`})]}),(0,Y.jsxs)(Js,{onSelect:()=>G.getState().setShortcutsOpen(!0),children:[(0,Y.jsx)(Ct,{size:16}),(0,Y.jsx)(`span`,{children:o(`activity:menu.keyboardShortcuts`)}),(0,Y.jsx)($s,{children:`?`})]}),n.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Qs,{}),(0,Y.jsx)(Zs,{className:`text-[11px] uppercase tracking-wide text-muted-foreground`,children:o(`activity:menu.panels`)}),n.map(e=>(0,Y.jsxs)(Js,{onSelect:()=>Q(e.id),children:[e.icon,(0,Y.jsx)(`span`,{children:o(`activity:nav.${e.id}`,e.label)}),c&&s===e.id?(0,Y.jsx)(`span`,{className:`ml-auto w-1.5 h-1.5 rounded-full bg-primary`}):(0,Y.jsx)($s,{children:Qa(e.id)})]},e.id))]}),r.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Qs,{}),(0,Y.jsx)(Zs,{className:`text-[11px] uppercase tracking-wide text-muted-foreground`,children:o(`activity:menu.views`)}),r.map(e=>(0,Y.jsxs)(Js,{onSelect:()=>to(e.id),children:[e.icon,(0,Y.jsx)(`span`,{children:o(`activity:nav.${e.id}`,e.label)}),l===e.id&&(0,Y.jsx)(`span`,{className:`ml-auto w-1.5 h-1.5 rounded-full bg-primary`})]},e.id))]}),(0,Y.jsx)(Qs,{}),(0,Y.jsx)(Zs,{className:`text-[11px] uppercase tracking-wide text-muted-foreground`,children:o(`activity:menu.theme`)}),(0,Y.jsxs)(Ws,{value:i,onValueChange:e=>a(e),children:[(0,Y.jsxs)(Xs,{value:`light`,children:[(0,Y.jsx)(_t,{size:16,className:`mr-2`}),o(`settings:appearance.themeLight`)]}),(0,Y.jsxs)(Xs,{value:`dark`,children:[(0,Y.jsx)(Mt,{size:16,className:`mr-2`}),o(`settings:appearance.themeDark`)]}),(0,Y.jsxs)(Xs,{value:`system`,children:[(0,Y.jsx)(Mn,{size:16,className:`mr-2`}),o(`settings:appearance.themeSystem`)]})]}),(0,Y.jsx)(Qs,{}),(0,Y.jsx)(Zs,{className:`text-[11px] uppercase tracking-wide text-muted-foreground`,children:o(`activity:menu.monitors`)}),(0,Y.jsxs)(Js,{onSelect:()=>g(`fleet`),children:[(0,Y.jsx)(qn,{size:16}),(0,Y.jsx)(`span`,{children:o(`activity:menu.fleetMonitor`)}),u&&d===`fleet`?(0,Y.jsx)(`span`,{className:`ml-auto w-1.5 h-1.5 rounded-full bg-primary`}):(0,Y.jsx)($s,{children:`⇧⌘M`})]}),(0,Y.jsxs)(Js,{onSelect:()=>g(`agents`),children:[(0,Y.jsx)(be,{size:16}),(0,Y.jsx)(`span`,{children:o(`activity:menu.agentsMonitor`)}),u&&d===`agents`?(0,Y.jsx)(`span`,{className:`ml-auto w-1.5 h-1.5 rounded-full bg-primary`}):(0,Y.jsx)($s,{children:`⇧⌘A`})]})]})]})}function pc({compact:e=!1,icon:t,label:n,active:r,badge:i,onClick:a}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:a,title:n,className:K(`relative flex items-center justify-center rounded-lg transition-colors`,e?`w-9 h-9`:`w-10 h-10`,`text-muted-foreground hover:text-foreground hover:bg-muted/70`,r&&`text-primary bg-primary/10`),children:[r&&(0,Y.jsx)(`span`,{className:`absolute left-0 top-1/2 -translate-y-1/2 w-0.5 h-6 rounded-r-full bg-primary`}),(0,Y.jsx)(`span`,{className:`h-5 w-5`,children:t}),i!==void 0&&i>0&&(0,Y.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 min-w-[15px] h-[15px] flex items-center justify-center rounded-full bg-primary text-[8px] font-bold text-primary-foreground leading-none px-1 tabular`,children:i>99?`99+`:i})]})}var mc=(0,q.memo)(function({oldText:e,newText:t,caption:n,fill:r}){let{t:i}=z(),a=(0,q.useMemo)(()=>gc(e,t),[e,t]);if(a===null)return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2`,children:i(`activity:diff.tooLarge`)});let o=a.filter(e=>e.kind===`add`).length,s=a.filter(e=>e.kind===`del`).length;return(0,Y.jsxs)(`div`,{className:K(`rounded-lg border bg-background/40 overflow-hidden text-xs`,r&&`flex h-full min-h-0 min-w-0 flex-col`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b bg-muted/40 shrink-0`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-muted-foreground truncate`,children:n??`diff`}),(0,Y.jsxs)(`span`,{className:`font-mono shrink-0`,children:[(0,Y.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,o]}),(0,Y.jsx)(`span`,{className:`text-muted-foreground mx-1 opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{className:`text-rose-600 dark:text-rose-400`,children:[`-`,s]})]})]}),(0,Y.jsx)(`div`,{className:K(`font-mono leading-relaxed overflow-auto`,r?`min-h-0 flex-1`:`max-h-96`),children:a.map((e,t)=>(0,Y.jsxs)(`div`,{className:K(`flex`,e.kind===`add`&&`bg-emerald-500/10`,e.kind===`del`&&`bg-rose-500/10`),children:[(0,Y.jsx)(`span`,{className:K(`w-6 shrink-0 text-center select-none`,e.kind===`add`&&`text-emerald-600 dark:text-emerald-400`,e.kind===`del`&&`text-rose-600 dark:text-rose-400`,e.kind===`ctx`&&`text-muted-foreground/40`),children:e.kind===`add`?`+`:e.kind===`del`?`-`:` `}),(0,Y.jsx)(`pre`,{className:K(`whitespace-pre-wrap break-all flex-1 px-2`,e.kind===`ctx`&&`text-muted-foreground/70`),children:e.text||`\xA0`})]},t))})]})}),hc=5e3;function gc(e,t){let r=e.split(`
39
- `),i=t.split(`
40
- `);if(r.length>hc||i.length>hc)return null;let a=r.length,o=i.length,s=Array.from({length:a+1},()=>Array(o+1).fill(0));for(let e=a-1;e>=0;e--)for(let t=o-1;t>=0;t--)r[e]===i[t]?n(s[e])[t]=n(s[e+1]?.[t+1])+1:n(s[e])[t]=Math.max(n(s[e+1]?.[t]),n(s[e]?.[t+1]));let c=[],l=0,u=0;for(;l<a&&u<o;)r[l]===i[u]?(c.push({kind:`ctx`,text:n(r[l])}),l++,u++):n(s[l+1]?.[u])>=n(s[l]?.[u+1])?(c.push({kind:`del`,text:n(r[l])}),l++):(c.push({kind:`add`,text:n(i[u])}),u++);for(;l<a;)c.push({kind:`del`,text:n(r[l++])});for(;u<o;)c.push({kind:`add`,text:n(i[u++])});return c}function _c(e,t){if(!e||typeof t!=`object`||!t)return null;let n=t,r=String(n.file_path??n.path??``);switch(e){case`edit`:case`str_replace`:case`edit_file`:{let e=typeof n.old_string==`string`?n.old_string:``,t=typeof n.new_string==`string`?n.new_string:``;return!e&&!t?null:{oldText:e,newText:t,caption:`edit ${r}`}}case`write`:case`write_file`:case`create_file`:return{oldText:``,newText:typeof n.content==`string`?n.content:``,caption:`write ${r} (new)`};default:return null}}tr.defineTheme(`wrongstack-dark`,{base:`vs-dark`,inherit:!0,rules:[{token:`comment`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.line`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.block`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`6e717a`,fontStyle:`italic`},{token:`string`,foreground:`64d488`},{token:`string.escape`,foreground:`49d3c5`},{token:`string.template`,foreground:`64d488`},{token:`number`,foreground:`f2a23a`},{token:`number.hex`,foreground:`f2a23a`},{token:`number.float`,foreground:`f2a23a`},{token:`keyword`,foreground:`f28dbc`},{token:`keyword.control`,foreground:`f28dbc`},{token:`keyword.operator`,foreground:`9ea0a8`},{token:`type`,foreground:`6cb6ff`},{token:`type.identifier`,foreground:`6cb6ff`},{token:`type.parameter`,foreground:`eeede7`},{token:`function`,foreground:`6cb6ff`},{token:`predefined`,foreground:`6cb6ff`},{token:`variable`,foreground:`eeede7`},{token:`variable.parameter`,foreground:`f2a23a`},{token:`variable.readonly`,foreground:`f2a23a`},{token:`variable.language`,foreground:`f28dbc`},{token:`tag`,foreground:`f47a95`},{token:`metatag`,foreground:`f47a95`},{token:`tag.html`,foreground:`f47a95`},{token:`tag.jsx`,foreground:`f47a95`},{token:`tag.tsx`,foreground:`f47a95`},{token:`attribute.name`,foreground:`ffb055`},{token:`attribute.value`,foreground:`64d488`},{token:`attribute.name.html`,foreground:`ffb055`},{token:`attribute.name.jsx`,foreground:`ffb055`},{token:`regexp`,foreground:`49d3c5`},{token:`delimiter`,foreground:`9ea0a8`},{token:`delimiter.bracket`,foreground:`9ea0a8`},{token:`delimiter.parenthesis`,foreground:`9ea0a8`},{token:`delimiter.curly`,foreground:`9ea0a8`},{token:`delimiter.square`,foreground:`9ea0a8`},{token:`delimiter.array`,foreground:`9ea0a8`},{token:`operator`,foreground:`9ea0a8`},{token:`constant`,foreground:`f2a23a`},{token:`constant.language`,foreground:`f28dbc`},{token:`support`,foreground:`6cb6ff`},{token:`support.function`,foreground:`6cb6ff`},{token:`support.type`,foreground:`6cb6ff`},{token:`support.constant`,foreground:`f2a23a`},{token:`support.variable`,foreground:`eeede7`},{token:`storage`,foreground:`f28dbc`},{token:`storage.modifier`,foreground:`f28dbc`},{token:`storage.type`,foreground:`6cb6ff`},{token:`entity.name.type`,foreground:`6cb6ff`},{token:`entity.name.function`,foreground:`6cb6ff`},{token:`entity.other.inherited-class`,foreground:`6cb6ff`},{token:`entity.name.tag`,foreground:`f47a95`},{token:`entity.other.attribute-name`,foreground:`ffb055`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`6cb6ff`,fontStyle:`bold`},{token:`link`,foreground:`49d3c5`,fontStyle:`underline`},{token:`class`,foreground:`6cb6ff`},{token:`interface`,foreground:`49d3c5`},{token:`enum`,foreground:`f2a23a`},{token:`enumMember`,foreground:`f2a23a`},{token:`typeParameter`,foreground:`f2a23a`},{token:`namespace`,foreground:`6cb6ff`},{token:`method`,foreground:`6cb6ff`},{token:`property`,foreground:`eeede7`},{token:`property.readonly`,foreground:`f2a23a`},{token:`property.static`,foreground:`eeede7`},{token:`parameter`,foreground:`f2a23a`},{token:`variable.defaultLibrary`,foreground:`6cb6ff`},{token:`function.defaultLibrary`,foreground:`6cb6ff`},{token:`macro`,foreground:`c4a0ff`},{token:`decorator`,foreground:`c4a0ff`},{token:`label`,foreground:`f2a23a`},{token:`comment.deprecated`,foreground:`6e717a`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`6e717a`,fontStyle:`strikethrough`}],colors:{"editor.background":`#121318`,"editor.foreground":`#eeede7`,"editorCursor.foreground":`#f2a23a`,"editor.selectionBackground":`#f2a23a25`,"editor.selectionHighlightBackground":`#f2a23a15`,"editor.inactiveSelectionBackground":`#f2a23a10`,"editor.lineHighlightBackground":`#1a1c23`,"editorLineNumber.foreground":`#4a4d55`,"editorLineNumber.activeForeground":`#9ea0a8`,"editorRuler.foreground":`#1e2028`,"editorBracketMatch.background":`#f2a23a15`,"editorBracketMatch.border":`#f2a23a30`,"editor.findMatchBackground":`#f2a23a30`,"editor.findMatchHighlightBackground":`#f2a23a15`,"editorWidget.background":`#1a1c23`,"editorWidget.border":`#262830`,"editorSuggestWidget.background":`#1a1c23`,"editorSuggestWidget.border":`#262830`,"editorSuggestWidget.selectedBackground":`#262830`,"editorHoverWidget.background":`#1a1c23`,"editorHoverWidget.border":`#262830`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#4a4d5530`,"scrollbarSlider.hoverBackground":`#f2a23a50`,"scrollbarSlider.activeBackground":`#f2a23a70`,"minimap.background":`#121318`,"diffEditor.insertedTextBackground":`#64d48815`,"diffEditor.removedTextBackground":`#d63c3c15`,"sideBar.background":`#121318`,"sideBar.border":`#1e2028`,"input.background":`#1a1c23`,"input.border":`#262830`,"input.foreground":`#eeede7`,"input.placeholderForeground":`#6e717a`,focusBorder:`#f2a23a40`,"list.activeSelectionBackground":`#262830`,"list.hoverBackground":`#1e2028`,"dropdown.background":`#1a1c23`,"dropdown.border":`#262830`,"badge.background":`#f2a23a`,"badge.foreground":`#1a1208`,"editorBracketHighlighting.foreground1":`#f2a23a`,"editorBracketHighlighting.foreground2":`#6cb6ff`,"editorBracketHighlighting.foreground3":`#f28dbc`,"editorBracketHighlighting.foreground4":`#64d488`,"editorBracketHighlighting.foreground5":`#49d3c5`,"editorBracketHighlighting.foreground6":`#c4a0ff`,"editorBracketPairGuide.background1":`#f2a23a18`,"editorBracketPairGuide.background2":`#6cb6ff18`,"editorBracketPairGuide.background3":`#f28dbc18`,"editorBracketPairGuide.background4":`#64d48818`,"editorBracketPairGuide.background5":`#49d3c518`,"editorBracketPairGuide.background6":`#c4a0ff18`,"editorBracketPairGuide.activeBackground1":`#f2a23a30`,"editorBracketPairGuide.activeBackground2":`#6cb6ff30`,"editorBracketPairGuide.activeBackground3":`#f28dbc30`,"editorBracketPairGuide.activeBackground4":`#64d48830`,"editorBracketPairGuide.activeBackground5":`#49d3c530`,"editorBracketPairGuide.activeBackground6":`#c4a0ff30`}}),tr.defineTheme(`wrongstack-light`,{base:`vs`,inherit:!0,rules:[{token:`comment`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.line`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.block`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`9a9d99`,fontStyle:`italic`},{token:`string`,foreground:`3b8c5a`},{token:`string.escape`,foreground:`17998e`},{token:`string.template`,foreground:`3b8c5a`},{token:`number`,foreground:`d97a12`},{token:`number.hex`,foreground:`d97a12`},{token:`number.float`,foreground:`d97a12`},{token:`keyword`,foreground:`d65a9a`},{token:`keyword.control`,foreground:`d65a9a`},{token:`keyword.operator`,foreground:`6b6d72`},{token:`type`,foreground:`3178c6`},{token:`type.identifier`,foreground:`3178c6`},{token:`type.parameter`,foreground:`1a1c23`},{token:`function`,foreground:`3178c6`},{token:`predefined`,foreground:`3178c6`},{token:`variable`,foreground:`1a1c23`},{token:`variable.parameter`,foreground:`d97a12`},{token:`variable.readonly`,foreground:`d97a12`},{token:`variable.language`,foreground:`d65a9a`},{token:`tag`,foreground:`c93a5e`},{token:`metatag`,foreground:`c93a5e`},{token:`tag.html`,foreground:`c93a5e`},{token:`tag.jsx`,foreground:`c93a5e`},{token:`tag.tsx`,foreground:`c93a5e`},{token:`attribute.name`,foreground:`d4893a`},{token:`attribute.value`,foreground:`3b8c5a`},{token:`attribute.name.html`,foreground:`d4893a`},{token:`attribute.name.jsx`,foreground:`d4893a`},{token:`regexp`,foreground:`17998e`},{token:`delimiter`,foreground:`6b6d72`},{token:`delimiter.bracket`,foreground:`6b6d72`},{token:`delimiter.parenthesis`,foreground:`6b6d72`},{token:`delimiter.curly`,foreground:`6b6d72`},{token:`delimiter.square`,foreground:`6b6d72`},{token:`delimiter.array`,foreground:`6b6d72`},{token:`operator`,foreground:`6b6d72`},{token:`constant`,foreground:`d97a12`},{token:`constant.language`,foreground:`d65a9a`},{token:`support`,foreground:`3178c6`},{token:`support.function`,foreground:`3178c6`},{token:`support.type`,foreground:`3178c6`},{token:`support.constant`,foreground:`d97a12`},{token:`support.variable`,foreground:`1a1c23`},{token:`storage`,foreground:`d65a9a`},{token:`storage.modifier`,foreground:`d65a9a`},{token:`storage.type`,foreground:`3178c6`},{token:`entity.name.type`,foreground:`3178c6`},{token:`entity.name.function`,foreground:`3178c6`},{token:`entity.other.inherited-class`,foreground:`3178c6`},{token:`entity.name.tag`,foreground:`c93a5e`},{token:`entity.other.attribute-name`,foreground:`d4893a`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`3178c6`,fontStyle:`bold`},{token:`link`,foreground:`17998e`,fontStyle:`underline`},{token:`class`,foreground:`3178c6`},{token:`interface`,foreground:`17998e`},{token:`enum`,foreground:`d97a12`},{token:`enumMember`,foreground:`d97a12`},{token:`typeParameter`,foreground:`d97a12`},{token:`namespace`,foreground:`3178c6`},{token:`method`,foreground:`3178c6`},{token:`property`,foreground:`1a1c23`},{token:`property.readonly`,foreground:`d97a12`},{token:`property.static`,foreground:`1a1c23`},{token:`parameter`,foreground:`d97a12`},{token:`variable.defaultLibrary`,foreground:`3178c6`},{token:`function.defaultLibrary`,foreground:`3178c6`},{token:`macro`,foreground:`8b5cf6`},{token:`decorator`,foreground:`8b5cf6`},{token:`label`,foreground:`d97a12`},{token:`comment.deprecated`,foreground:`9a9d99`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`9a9d99`,fontStyle:`strikethrough`}],colors:{"editor.background":`#f7f7f5`,"editor.foreground":`#1a1c23`,"editorCursor.foreground":`#e07b0e`,"editor.selectionBackground":`#e07b0e18`,"editor.selectionHighlightBackground":`#e07b0e10`,"editor.inactiveSelectionBackground":`#e07b0e08`,"editor.lineHighlightBackground":`#f0efe9`,"editorLineNumber.foreground":`#bab8b0`,"editorLineNumber.activeForeground":`#6b6d72`,"editorRuler.foreground":`#e8e6de`,"editorBracketMatch.background":`#e07b0e12`,"editorBracketMatch.border":`#e07b0e25`,"editor.findMatchBackground":`#e07b0e25`,"editor.findMatchHighlightBackground":`#e07b0e12`,"editorWidget.background":`#f7f7f5`,"editorWidget.border":`#ddd9d0`,"editorSuggestWidget.background":`#f7f7f5`,"editorSuggestWidget.border":`#ddd9d0`,"editorSuggestWidget.selectedBackground":`#eeece2`,"editorHoverWidget.background":`#f7f7f5`,"editorHoverWidget.border":`#ddd9d0`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#bab8b040`,"scrollbarSlider.hoverBackground":`#e07b0e50`,"scrollbarSlider.activeBackground":`#e07b0e70`,"minimap.background":`#f7f7f5`,"diffEditor.insertedTextBackground":`#3b8c5a12`,"diffEditor.removedTextBackground":`#d63c3c12`,"sideBar.background":`#f7f7f5`,"sideBar.border":`#e8e6de`,"input.background":`#ffffff`,"input.border":`#ddd9d0`,"input.foreground":`#1a1c23`,"input.placeholderForeground":`#9a9d99`,focusBorder:`#e07b0e35`,"list.activeSelectionBackground":`#eeece2`,"list.hoverBackground":`#f0efe9`,"dropdown.background":`#ffffff`,"dropdown.border":`#ddd9d0`,"badge.background":`#e07b0e`,"badge.foreground":`#ffffff`,"editorBracketHighlighting.foreground1":`#d97a12`,"editorBracketHighlighting.foreground2":`#3178c6`,"editorBracketHighlighting.foreground3":`#d65a9a`,"editorBracketHighlighting.foreground4":`#3b8c5a`,"editorBracketHighlighting.foreground5":`#17998e`,"editorBracketHighlighting.foreground6":`#8b5cf6`,"editorBracketPairGuide.background1":`#d97a1215`,"editorBracketPairGuide.background2":`#3178c615`,"editorBracketPairGuide.background3":`#d65a9a15`,"editorBracketPairGuide.background4":`#3b8c5a15`,"editorBracketPairGuide.background5":`#17998e15`,"editorBracketPairGuide.background6":`#8b5cf615`,"editorBracketPairGuide.activeBackground1":`#d97a1228`,"editorBracketPairGuide.activeBackground2":`#3178c628`,"editorBracketPairGuide.activeBackground3":`#d65a9a28`,"editorBracketPairGuide.activeBackground4":`#3b8c5a28`,"editorBracketPairGuide.activeBackground5":`#17998e28`,"editorBracketPairGuide.activeBackground6":`#8b5cf628`}});function vc(){return typeof document>`u`||document.documentElement.classList.contains(`dark`)?`wrongstack-dark`:`wrongstack-light`}er.config({monaco:ir});var yc={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,mjs:`javascript`,json:`json`,css:`css`,scss:`scss`,html:`html`,md:`markdown`,py:`python`,go:`go`,rs:`rust`,java:`java`,c:`c`,cpp:`cpp`,cs:`csharp`,rb:`ruby`,php:`php`,sh:`shell`,bash:`shell`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sql:`sql`};function bc(e){return yc[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function xc({path:e,oldText:t,newText:n}){let{t:r}=z(),i=(0,q.useRef)(null),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(null);(0,q.useEffect)(()=>{o(!1),c(!1),u(null)},[]);let d=(0,q.useCallback)(e=>{i.current=e,tr.setTheme(vc()),e.getModifiedEditor().onDidChangeModelContent(()=>o(!0))},[]),f=(0,q.useCallback)(()=>{let t=i.current?.getModifiedEditor().getValue();if(t==null)return;c(!0);let n=U(J.getState().wsUrl),r=n.on(`files.written`,t=>{t.type===`files.written`&&t.payload.filePath===e&&(r(),clearTimeout(a),c(!1),t.payload.success&&(o(!1),u(Date.now())))}),a=setTimeout(()=>{r(),c(!1)},5e3);n.send({type:`files.write`,payload:{filePath:e,content:t}})},[e]),p=bc(e);return(0,Y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2 px-2 py-1.5 border-b border-border/40`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:e}),(0,Y.jsxs)(`button`,{type:`button`,onClick:f,disabled:!a||s,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md border border-border text-xs font-medium disabled:opacity-40 enabled:hover:bg-muted transition-colors`,title:r(`activity:monacoDiff.applyTitle`),children:[s?(0,Y.jsx)(R,{className:`h-3.5 w-3.5 animate-spin`}):l&&!a?(0,Y.jsx)(gt,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,Y.jsx)(Me,{className:`h-3.5 w-3.5`}),r(s?`activity:monacoDiff.applying`:l&&!a?`activity:monacoDiff.applied`:`activity:monacoDiff.apply`)]})]}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,Y.jsx)(rr,{original:t,modified:n,language:p,theme:vc(),onMount:d,options:{renderSideBySide:!0,readOnly:!1,originalEditable:!1,minimap:{enabled:!1},fontSize:13,scrollBeyondLastLine:!1,automaticLayout:!0}})})]})}function Sc({className:e}){let{t}=z(),n=oi(e=>e.selectedPath),r=oi(e=>e.diff),i=oi(e=>e.loadingDiff),[a,o]=(0,q.useState)(`unified`);if(!n)return(0,Y.jsxs)(`div`,{className:K(`flex min-h-0 min-w-0 flex-1 flex-col items-center justify-center gap-3 text-muted-foreground`,e),children:[(0,Y.jsx)(de,{className:`h-10 w-10 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:t(`activity:changes.selectPrompt`)})]});let s=r&&!r.error&&!r.binary&&!r.tooLarge;return(0,Y.jsxs)(`div`,{className:K(`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden p-3`,e),children:[s&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1 pb-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>o(`unified`),title:t(`activity:changes.unifiedTitle`),className:K(`inline-flex items-center gap-1 h-7 px-2 rounded-md border text-xs transition-colors`,a===`unified`?`border-primary/40 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,Y.jsx)(ge,{className:`h-3.5 w-3.5`}),` `,t(`activity:changes.unified`)]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>o(`edit`),title:t(`activity:changes.editTitle`),className:K(`inline-flex items-center gap-1 h-7 px-2 rounded-md border text-xs transition-colors`,a===`edit`?`border-primary/40 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,Y.jsx)(ft,{className:`h-3.5 w-3.5`}),` `,t(`activity:changes.edit`)]})]}),i||!r?(0,Y.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 animate-spin`}),` `,t(`activity:changes.loadingDiff`)]}):r.error?(0,Y.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-rose-500`,children:r.error}):r.binary?(0,Y.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:t(`activity:changes.binary`)}):r.tooLarge?(0,Y.jsx)(`div`,{className:`flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground`,children:t(`activity:changes.tooLarge`)}):a===`edit`?(0,Y.jsx)(xc,{path:r.path,oldText:r.oldText??``,newText:r.newText??``},r.path):(0,Y.jsx)(mc,{oldText:r.oldText,newText:r.newText,caption:r.path,fill:!0})]})}var Cc=[{mode:`off`,label:`Off`,descKey:`descOff`,icon:(0,Y.jsx)(Sn,{className:`h-3.5 w-3.5`})},{mode:`suggest`,label:`Suggest`,descKey:`descSuggest`,icon:(0,Y.jsx)(E,{className:`h-3.5 w-3.5`})},{mode:`auto`,label:`Auto`,descKey:`descAuto`,icon:(0,Y.jsx)(Ye,{className:`h-3.5 w-3.5`})},{mode:`eternal`,label:`Eternal`,descKey:`descEternal`,icon:(0,Y.jsx)(be,{className:`h-3.5 w-3.5`})},{mode:`eternal-parallel`,label:`Eternal Parallel`,descKey:`descEternalParallel`,icon:(0,Y.jsx)(be,{className:`h-3.5 w-3.5`})}];function wc({value:e,onChange:t,className:n,compact:r=!1}){let{t:i}=z(),[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),(0,q.useEffect)(()=>{if(!a)return;let e=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[a]);let c=Cc.find(t=>t.mode===e);return(0,Y.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:K(`flex items-center gap-1 px-2 py-0.5 rounded-md border text-[11px] font-medium transition-colors hover:opacity-80`,e===`eternal`||e===`eternal-parallel`?`bg-rose-500/15 text-rose-600 dark:text-rose-400 border-rose-500/30`:e===`auto`?`bg-amber-500/15 text-amber-600 dark:text-amber-400 border-amber-500/30`:e===`suggest`?`bg-blue-500/15 text-blue-600 dark:text-blue-400 border-blue-500/30`:`bg-muted text-muted-foreground border-transparent`,n),title:i(`activity:autonomy.titlePrefix`,{label:c?.label??e}),children:[c?.icon,!r&&(0,Y.jsx)(`span`,{className:`truncate max-w-[7rem]`,children:c?.label??e}),(0,Y.jsx)(Bt,{className:`h-3 w-3 opacity-60`})]}),a&&(0,Y.jsxs)(`div`,{className:`absolute top-full mt-1 right-0 z-50 w-56 rounded-lg border bg-popover shadow-lg p-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1`,children:i(`activity:autonomy.heading`)}),Cc.map(n=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{t(n.mode),o(!1)},className:K(`w-full flex items-start gap-2 px-3 py-2 rounded text-left transition-colors`,e===n.mode?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,Y.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:n.icon}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:n.label}),(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground leading-snug`,children:i(`activity:autonomy.${n.descKey}`)})]}),e===n.mode&&(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary mt-2 shrink-0`})]},n.mode))]})]})}var Tc={ts:V,tsx:V,js:V,jsx:V,mjs:V,cjs:V,json:le,lock:tt,css:qe,scss:qe,less:qe,html:te,htm:te,svg:I,xml:te,md:qe,mdx:qe,txt:qe,yml:qe,yaml:qe,toml:fe,env:fe,gitignore:fe,editorconfig:fe,sh:V,bash:V,zsh:V,fish:V,ps1:V,bat:V,py:V,pyi:V,pyx:V,rs:V,go:V,rb:V,java:V,c:V,cpp:V,h:V,hpp:V,sql:V,graphql:V,png:I,jpg:I,jpeg:I,gif:I,webp:I,ico:I};function Ec(e,t){if(t){let t=e.toLowerCase();return t===`.git`?`text-orange-500/80 dark:text-orange-400/80`:t===`node_modules`?`text-red-400/60 dark:text-red-500/60`:t===`src`||t===`lib`||t===`packages`?`text-amber-500/70 dark:text-amber-400/70`:t===`tests`||t===`test`||t===`__tests__`?`text-emerald-500/70 dark:text-emerald-400/70`:t===`dist`||t===`build`||t===`.next`?`text-muted-foreground/50`:`text-amber-500/70 dark:text-amber-400/70`}let n=e.split(`.`).pop()?.toLowerCase()??``;return/^(ts|tsx|js|jsx|mjs|cjs)$/.test(n)?`text-blue-500 dark:text-blue-400`:/^(json|lock)$/.test(n)?`text-amber-500 dark:text-amber-400`:/^(css|scss|less|sass)$/.test(n)?`text-teal-500 dark:text-teal-400`:/^(html|htm|xml|svg)$/.test(n)?`text-rose-500 dark:text-rose-400`:/^(md|mdx)$/.test(n)?`text-violet-500 dark:text-violet-400`:/^(yml|yaml|toml|env)$/.test(n)?`text-emerald-500 dark:text-emerald-400`:/^(sh|bash|zsh|fish|ps1|bat)$/.test(n)?`text-orange-400 dark:text-orange-300`:/^(py|pyi|pyx)$/.test(n)?`text-cyan-500 dark:text-cyan-400`:n===`rs`?`text-orange-500 dark:text-orange-400`:n===`go`?`text-sky-500 dark:text-sky-400`:n===`rb`?`text-red-400 dark:text-red-400`:/^(c|h|cpp|hpp|cc|hh)$/.test(n)?`text-slate-500 dark:text-slate-400`:/^(png|jpe?g|gif|webp|ico)$/.test(n)?`text-purple-500 dark:text-purple-400`:/^(gitignore|editorconfig|prettierrc|eslintrc)$/.test(n)?`text-muted-foreground/60`:`text-muted-foreground`}function Dc(e){return Tc[e.split(`.`).pop()?.toLowerCase()??``]??Ze}function Oc(e){return e.replace(/\\/g,`/`).split(`/`).pop()??e}function kc(e){if(e.kind===`file`)return e.path;let t=e.kind===`snippet`?e.content:e.preview,n=t.split(`
41
- `).slice(0,6).join(`
42
- `);return`${e.path}:${e.startLine}-${e.endLine}\n${n}${t.split(`
43
- `).length>6?`
44
- …`:``}`}function Ac({ref:e,onRemove:t}){let{t:n}=z(),r=Oc(e.path),i=Dc(r),a=Ec(r,!1),o=e.kind===`file`?r:`${r}:${e.startLine}-${e.endLine}`,s=e.kind===`snippet`?e.content.split(`
45
- `).length:0,c=s>0?n(`activity:fileRef.linesCount`,{count:s}):null;return(0,Y.jsxs)(`div`,{title:kc(e),className:K(`inline-flex items-center gap-1.5 max-w-[180px] shrink-0`,`rounded-full border border-border bg-muted/60 pl-2 pr-1 py-0.5`,`text-xs text-foreground hover:bg-muted transition-colors`),children:[(0,Y.jsx)(i,{className:K(`h-3 w-3 shrink-0`,a)}),(0,Y.jsx)(`span`,{className:`truncate font-mono text-[11px]`,children:o}),c&&(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground shrink-0`,children:c}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`inline-flex items-center justify-center h-4 w-4 rounded-full text-muted-foreground hover:bg-background hover:text-foreground transition-colors shrink-0`,title:n(`activity:fileRef.removeTitle`),children:(0,Y.jsx)(ut,{className:`h-3 w-3`})})]})}var jc=0,Mc=!1;function Nc(){let e=$n(e=>e.autoProceedMaxIterations),t=$n(e=>e.autonomy),n=(0,q.useRef)(jc),r=(0,q.useRef)(Mc),i=(0,q.useRef)(t);(0,q.useEffect)(()=>{n.current=jc,r.current=Mc}),(0,q.useEffect)(()=>{i.current!==`auto`&&t===`auto`&&(Mc=!1,r.current=!1),i.current=t},[t]);let a=(0,q.useCallback)(()=>e<=0?!0:n.current<e,[e]),o=(0,q.useCallback)(()=>{let t=e;return t>0&&n.current>=t?!1:(jc=++n.current,t>0&&jc>=t&&(Mc=!0,r.current=!0),!0)},[e]),s=(0,q.useCallback)(()=>{jc=0,n.current=0,Mc=!1,r.current=!1},[]),c=(0,q.useCallback)(()=>{Mc=!1,r.current=!1},[]);return{streak:n.current,capWarned:r.current,canAutoSubmit:a,recordAutoSubmit:o,reset:s,resetCapWarned:c}}function Pc({query:e,onPick:t,onClose:r}){let{t:i}=z(),a=ts(),o=J(e=>e.wsUrl),[s,c]=(0,q.useState)([]),[l,u]=(0,q.useState)(0),d=(0,q.useRef)(null),f=(0,q.useRef)(null);return(0,q.useEffect)(()=>{let e=U(o).on(`files.list`,e=>{let t=e.payload;c(t.files??[]),u(0),f.current?.resolve(t.files??[]),f.current=null});return()=>e()},[o]),(0,q.useEffect)(()=>(d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{a.client.listFiles(e,50)},80),()=>{d.current&&clearTimeout(d.current)}),[e,a.client]),(0,q.useEffect)(()=>{let e=e=>{if(e.key===`ArrowDown`)e.preventDefault(),u(e=>(e+1)%Math.max(1,s.length));else if(e.key===`ArrowUp`)e.preventDefault(),u(e=>(e-1+Math.max(1,s.length))%Math.max(1,s.length));else if(e.key===`Enter`||e.key===`Tab`){if(s.length===0)return;e.preventDefault(),t(n(s[l]))}else e.key===`Escape`&&(e.preventDefault(),r())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[s,l,t,r]),(0,Y.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 mb-2 rounded-lg border bg-popover shadow-md p-1 text-sm max-h-72 overflow-auto`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1 flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{children:[i(`activity:filePicker.heading`),` `,e&&`· "${e}"`]}),(0,Y.jsx)(`span`,{children:`↑/↓ select · ↵ insert · Esc dismiss`})]}),s.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground italic`,children:e?i(`activity:filePicker.noMatch`,{query:e}):i(`activity:filePicker.searching`)}):s.map((e,n)=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>t(e),onMouseEnter:()=>u(n),className:K(`w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-2 font-mono text-xs`,n===l?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[e.includes(`/`)?(0,Y.jsx)(N,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Y.jsx)(qe,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e})]},e))]})}function Fc({atMention:e,input:t,textareaRef:n,setInput:r,setAtMention:i}){let{addRef:a}=Fr.getState();return e?(0,Y.jsx)(Pc,{query:e.query,onClose:()=>i(null),onPick:o=>{r(`${t.slice(0,e.start)}${t.slice(e.start+1+e.query.length)}`.replace(/\s+/g,` `).trim()),i(null),a({kind:`file`,path:o}),requestAnimationFrame(()=>{let t=n.current;if(t){let n=e.start;t.focus(),t.setSelectionRange(n,n),t.style.height=`auto`,t.style.height=`${Math.min(t.scrollHeight,200)}px`}})}}):null}var Ic={btw:{label:`btw`,tone:`bg-sky-500/10 text-sky-700 dark:text-sky-300 border-sky-500/30`,titleKey:`btwTitle`},steer:{label:`steer`,tone:`bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/30`,titleKey:`steerTitle`},queue:{label:`queue`,tone:`bg-indigo-500/10 text-indigo-700 dark:text-indigo-300 border-indigo-500/30`,titleKey:`queueTitle`}};function Lc({queue:e,onClear:t,onRemove:n}){let{t:r}=z(),[i,a]=(0,q.useState)(`oldest`),o=(0,q.useMemo)(()=>{let t=e.slice();return t.sort((e,t)=>i===`newest`?t.addedAt-e.addedAt:e.addedAt-t.addedAt),t},[e,i]);return e.length===0?null:(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2 text-xs`,"data-testid":`inline-queue`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 gap-2`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium shrink-0`,children:[r(`activity:queue.heading`),` (`,e.length,`)`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>e===`newest`?`oldest`:`newest`),className:K(`inline-flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors px-1.5 py-0.5 rounded text-[10px]`,`hover:bg-muted`),title:r(i===`newest`?`activity:queue.sortNewestTitle`:`activity:queue.sortOldestTitle`),"data-testid":`inline-queue-sort`,children:[i===`newest`?(0,Y.jsx)(vt,{className:`h-3 w-3`}):(0,Y.jsx)(Wt,{className:`h-3 w-3`}),r(i===`newest`?`activity:queue.newest`:`activity:queue.oldest`)]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:t,className:`inline-flex items-center gap-1 text-muted-foreground hover:text-destructive transition-colors px-1.5 py-0.5 rounded text-[10px]`,title:r(`activity:queue.clearTitle`),"data-testid":`inline-queue-clear-all`,children:[(0,Y.jsx)(At,{className:`h-3 w-3`}),r(`activity:queue.clear`)]})]})]}),(0,Y.jsx)(`ul`,{className:`space-y-1`,children:o.map(t=>{let i=e.indexOf(t),a=Ic[t.mode];return(0,Y.jsxs)(`li`,{className:`flex items-start justify-between gap-2 rounded bg-background/60 border px-2 py-1`,"data-testid":`inline-queue-item`,"data-queue-mode":t.mode,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:K(`shrink-0 inline-flex items-center justify-center text-[9px] font-semibold uppercase tracking-wider px-1 py-px rounded border mt-0.5`,a.tone),title:r(`activity:queue.${a.titleKey}`),children:a.label}),(0,Y.jsx)(`span`,{className:`truncate flex-1 min-w-0`,children:t.text})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>n(i),className:`text-muted-foreground hover:text-destructive shrink-0`,title:r(`activity:queue.removeTitle`),"data-testid":`inline-queue-remove-${i}`,children:`×`})]},`${t.addedAt}-${i}`)})})]})}var Rc=[{name:`/new`,category:`Session`,description:`Start a brand-new session (fresh on disk and in memory)`},{name:`/clear`,category:`Session`,description:`Wipe current context (keeps session id, disk record stays)`},{name:`/compact`,category:`Session`,description:`Shrink context — elide ancient tool output`},{name:`/compact!`,category:`Session`,description:`Aggressively shrink context now`},{name:`/repair`,category:`Session`,description:`Repair orphan tool-use / tool-result protocol blocks`},{name:`/save`,category:`Session`,description:`Force-flush the session (auto-saved already)`},{name:`/load`,category:`Session`,aliases:[`/resume`],description:`Resume a previous session from disk`},{name:`/export`,category:`Session`,description:`Download the current chat as markdown`},{name:`/debug`,category:`Inspect`,aliases:[`/context`],description:`Context size breakdown per section`},{name:`/tools`,category:`Inspect`,description:`List every registered tool the model can call`},{name:`/memory`,category:`Inspect`,description:`Manage memory: show, remember, forget, clear, stats`},{name:`/todos`,category:`Inspect`,description:`List current todos`},{name:`/stats`,category:`Inspect`,description:`Session stats: tokens, cost, elapsed`},{name:`/skill`,category:`Inspect`,aliases:[`/skills`],description:`List active skills`},{name:`/prompt`,category:`Inspect`,aliases:[`/prompts`],description:`Browse & insert prompts from the library`},{name:`/diag`,category:`Inspect`,description:`Runtime diagnostics (provider, tools, mode, usage)`},{name:`/agents`,category:`Inspect`,description:`Show status of spawned subagents`},{name:`/brain`,category:`Inspect`,description:`Brain status, risk ceiling (risk <level>), or decision support (ask <question>)`},{name:`/plan`,category:`Inspect`,description:`Strategic plan board: show, add, start, done, promote, clear`},{name:`/suggest`,category:`Inspect`,aliases:[`/next-steps`],description:`Ask the agent for concrete next steps`},{name:`/next`,category:`Inspect`,description:`Show or run numbered next-step suggestions`},{name:`/review`,category:`Agent`,aliases:[`/cr`],description:`Ask the agent to review the pending changes (optional focus)`},{name:`/fix`,category:`Agent`,description:`Diagnose and fix an error (paste it) or the latest failure`},{name:`/autonomy`,category:`Agent`,description:`Switch self-driving mode: off | suggest | auto | eternal | eternal-parallel`},{name:`/goal`,category:`Agent`,description:`Show the current goal (opens the Goal dock chip)`},{name:`/fleet`,category:`Agent`,description:`Open the Fleet orchestration monitor`},{name:`/terminal`,category:`App`,aliases:[`/term`],description:"Open the integrated terminal (Ctrl+`)"},{name:`/collab`,category:`Agent`,description:`Open the live collaboration panel`},{name:`/worktree`,category:`Agent`,aliases:[`/worktrees`],description:`Open the worktree view`},{name:`/autophase`,category:`Agent`,description:`AutoPhase: start <title> | pause | resume | stop`},{name:`/mode`,category:`Agent`,description:`Switch session mode (no arg lists available modes)`},{name:`/mcp`,category:`Agent`,description:`Open MCP server settings and refresh the server list`},{name:`/working-dir`,category:`Agent`,aliases:[`/cwd`],description:`Show or change the working directory`},{name:`/settings`,category:`Config`,aliases:[`/model`],description:`Open settings (provider/model/keys)`},{name:`/setup`,category:`Config`,description:`Open the provider setup screen to add or change API keys`},{name:`/enhance`,category:`Config`,description:`Toggle prompt refinement before sending`},{name:`/interrupt`,category:`Run`,aliases:[`/abort`,`/stop`,`/int`],description:`Stop the current run (abort the in-flight request)`},{name:`/help`,category:`App`,description:`Show every slash command and what it does`},{name:`/exit`,category:`App`,description:`Exit the session and close WebUI`},{name:`/f`,category:`App`,description:`Open F-key panels (F1–F12). Type /f for numbered options.`},{name:`/f1`,category:`App`,description:`Session panel`,hidden:!0},{name:`/f2`,category:`App`,description:`Fleet orchestration monitor`,hidden:!0},{name:`/f3`,category:`App`,description:`Agents live monitor`,hidden:!0},{name:`/f4`,category:`App`,description:`Worktree monitor`,hidden:!0},{name:`/f5`,category:`App`,description:`Plan panel`,hidden:!0},{name:`/f6`,category:`App`,description:`Todos monitor overlay`,hidden:!0},{name:`/f7`,category:`App`,description:`Queue panel`,hidden:!0},{name:`/f8`,category:`App`,description:`Process list overlay`,hidden:!0},{name:`/f9`,category:`App`,description:`Goal panel`,hidden:!0},{name:`/f10`,category:`App`,description:`Live sessions panel`,hidden:!0},{name:`/f11`,category:`App`,description:`Coordinator monitor`,hidden:!0},{name:`/f12`,category:`App`,description:`Status line picker`,hidden:!0}],zc=[`Run`,`Session`,`Inspect`,`Agent`,`Config`,`App`];function Bc(e){let t=e.toLowerCase();return t===`/`||t===``?Rc.filter(e=>!e.hidden):Rc.filter(e=>e.name.startsWith(t)||(e.aliases?.some(e=>e.startsWith(t))??!1))}function Vc(e,t){let r=t-1;for(;r>=0;){let i=n(e[r]);if(i===`@`){let n=r>0?e[r-1]:``;return r===0||/\s/.test(n??``)?{start:r,query:e.slice(r+1,t)}:null}if(/\s/.test(i))return null;r--}return null}var Hc=_,Uc=F,Wc=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)($e,{ref:n,className:K(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));Wc.displayName=$e.displayName;var Gc=q.forwardRef(({className:e,children:t,showCloseButton:n=!0,...r},i)=>(0,Y.jsxs)(Uc,{children:[(0,Y.jsx)(Wc,{}),(0,Y.jsxs)(ee,{ref:i,className:K(`fixed left-[50%] top-[50%] z-50 grid max-h-[calc(100dvh-2rem)] w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...r,children:[t,n&&(0,Y.jsxs)(Xe,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`,children:[(0,Y.jsx)(ut,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));Gc.displayName=ee.displayName;var Kc=({className:e,...t})=>(0,Y.jsx)(`div`,{className:K(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});Kc.displayName=`DialogHeader`;var qc=({className:e,...t})=>(0,Y.jsx)(`div`,{className:K(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});qc.displayName=`DialogFooter`;var Jc=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(ue,{ref:n,className:K(`text-lg font-semibold leading-none tracking-tight`,e),...t}));Jc.displayName=ue.displayName;var Yc=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(Ke,{ref:n,className:K(`text-sm text-muted-foreground`,e),...t}));Yc.displayName=Ke.displayName;function Xc(e){let t=e.thinkingLog;if(!t)return``;if(t.replayed)return`replay`;let n=Math.max(.1,t.durationMs/1e3);return`${n.toFixed(+(n<10))}s`}function Zc(e){let t=Math.max(3,...Array.from(e.matchAll(/`+/g),e=>e[0].length+1));return"`".repeat(t)}function Qc(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}function $c(){let e=i.getState().messages,t=[],n=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`),r=W.getState().projectName||`chat`,a=W.getState().session?.title||r;t.push(`# ${a} — chat export`),t.push(`*Exported: ${new Date().toISOString()}*`),t.push(``);for(let n of e)if(n.thinkingLog){let e=Zc(n.thinkingLog.text),r=n.thinkingLog.text.split(`
46
- `).length;t.push(`### 🧠 Thinking process — iteration ${n.thinkingLog.iteration}`),t.push(``),t.push(`_${Xc(n)} · ${r} line${r===1?``:`s`}_`),t.push(``),t.push(`<details><summary>Log</summary>`),t.push(``),t.push(`${e}text`),t.push(n.thinkingLog.text),t.push(e),t.push(``),t.push(`</details>`),t.push(``)}else if(n.role===`user`)t.push(`## 👤 User`),t.push(``),t.push(n.content),t.push(``);else if(n.role===`assistant`)t.push(`## 🤖 Assistant`),t.push(``),t.push(n.content),t.push(``);else if(n.role===`tool`){let e=n.isError?`❌`:n.toolResult===void 0?`⏳`:`✅`;t.push(`### 🔧 Tool: \`${n.toolName??`unknown`}\` ${e}`),n.toolInput!==void 0&&(t.push("```json"),t.push(JSON.stringify(n.toolInput,null,2)),t.push("```")),n.toolResult&&(t.push(`<details><summary>Output</summary>`),t.push(``),t.push("```"),t.push(n.toolResult),t.push("```"),t.push(`</details>`)),t.push(``)}let o=new Blob([t.join(`
47
- `)],{type:`text/markdown`}),s=URL.createObjectURL(o),c=document.createElement(`a`);c.href=s,c.download=`${r.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}-chat-${n}.md`,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(s)}function el(){let e=i.getState().messages,t=W.getState(),n=t.projectName||`chat`,r=Qc(t.session?.title||n),a=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`),o=e.map(e=>{if(e.thinkingLog){let t=e.thinkingLog.text.split(`
48
- `).length;return`
49
- <section class="bubble thinking">
50
- <header><span class="icon">🧠</span><strong>Thinking process</strong> <span class="meta-chip">iter ${e.thinkingLog.iteration} · ${Qc(Xc(e))} · ${t} line${t===1?``:`s`}</span></header>
51
- <details open><summary>Log</summary><pre>${Qc(e.thinkingLog.text)}</pre></details>
52
- </section>`}if(e.role===`tool`){let t=e.isError?`❌`:e.toolResult===void 0?`⏳`:`✅`;return`
53
- <section class="bubble tool ${e.isError?`error`:``}">
54
- <header><span class="icon">🔧</span><code>${Qc(e.toolName??`tool`)}</code> ${t}</header>
55
- ${e.toolInput===void 0?``:`<details><summary>Input</summary><pre>${Qc(JSON.stringify(e.toolInput,null,2))}</pre></details>`}
56
- ${e.toolResult?`<details><summary>Output</summary><pre>${Qc(e.toolResult)}</pre></details>`:``}
57
- </section>`}return`
58
- <section class="bubble ${e.role===`user`?`user`:`assistant`}">
59
- <header><span class="icon">${e.role===`user`?`👤`:`🤖`}</span><strong>${e.role===`user`?`User`:`Assistant`}</strong></header>
60
- <pre class="content">${Qc(e.content)}</pre>
61
- </section>`}),s=`<!doctype html>
62
- <html lang="en"><head>
63
- <meta charset="utf-8">
64
- <title>${r} — chat export</title>
65
- <style>
66
- :root { color-scheme: light dark; }
67
- body { font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; max-width: 920px; margin: 24px auto; padding: 0 16px; }
68
- h1 { font-size: 20px; margin-bottom: 4px; }
69
- .meta { color: #666; font-size: 12px; margin-bottom: 24px; }
70
- .bubble { margin: 12px 0; padding: 10px 14px; border-radius: 10px; border: 1px solid #ddd; }
71
- .bubble header { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #666; margin-bottom: 6px; }
72
- .bubble header .icon { margin-right: 4px; }
73
- .bubble.user { background: #eef4ff; border-color: #c8d8f5; }
74
- .bubble.assistant { background: #fff; }
75
- .bubble.thinking { background: #fbf7ff; border-color: #dcc7ff; }
76
- .bubble.tool { background: #fafafa; }
77
- .bubble.tool.error { background: #fff5f5; border-color: #f5c8c8; }
78
- .meta-chip { text-transform: none; letter-spacing: 0; font-weight: 400; }
79
- pre.content, .bubble pre { white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; margin: 0; }
80
- details summary { cursor: pointer; color: #555; font-size: 12px; }
81
- details pre { margin-top: 6px; background: #f4f4f4; padding: 8px; border-radius: 6px; max-height: 360px; overflow: auto; }
82
- @media (prefers-color-scheme: dark) {
83
- body { background: #0d0d0f; color: #e6e6e6; }
84
- .bubble { border-color: #2a2a2e; }
85
- .bubble.user { background: #16213a; border-color: #2a3d6b; }
86
- .bubble.assistant { background: #161618; }
87
- .bubble.thinking { background: #1d1728; border-color: #4b3673; }
88
- .bubble.tool { background: #131315; }
89
- .bubble.tool.error { background: #2a1717; border-color: #5c2a2a; }
90
- details pre { background: #1a1a1c; }
91
- .meta, .bubble header, details summary { color: #999; }
92
- }
93
- </style>
94
- </head><body>
95
- <h1>${r} — chat export</h1>
96
- <div class="meta">
97
- Exported ${new Date().toISOString()}${t.session?.provider?` · ${Qc(t.session.provider)}/${Qc(t.session.model)}`:``} · ${e.length} message${e.length===1?``:`s`}
98
- </div>
99
- ${o.join(``)}
100
- </body></html>`,c=new Blob([s],{type:`text/html;charset=utf-8`}),l=URL.createObjectURL(c),u=document.createElement(`a`);u.href=l,u.download=`${n.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}-chat-${a}.html`,document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(l)}function tl(){let e=G(e=>e.paletteOpen),t=G(e=>e.setPaletteOpen),n=J(e=>e.setTheme),r=di(e=>e.entries),{addMessage:a,clearMessages:o}=i(We(e=>({addMessage:e.addMessage,clearMessages:e.clearMessages}))),s=ts(),{t:c}=z(),[l,u]=(0,q.useState)(``),[d,f]=(0,q.useState)(0),p=(0,q.useRef)(null);(0,q.useEffect)(()=>{e&&(u(``),f(0),requestAnimationFrame(()=>p.current?.focus()))},[e]),(0,q.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`&&(e.preventDefault(),t(!G.getState().paletteOpen))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let m=(0,q.useMemo)(()=>{let e=[{id:`help`,category:`Command`,label:c(`commandPalette:cmd.help`),icon:k,keywords:[`help`,`commands`,`?`],run:()=>{a({role:`assistant`,content:"Type `/` in the message box to see every slash command."})}},{id:`tools`,category:`Command`,label:c(`commandPalette:cmd.tools`),icon:Ne,keywords:[`tools`,`list`],run:()=>s.listTools()},{id:`memory`,category:`Command`,label:c(`commandPalette:cmd.memory`),icon:Jn,keywords:[`memory`,`remember`,`notes`],run:()=>s.listMemory()},{id:`skills`,category:`Command`,label:c(`commandPalette:cmd.skills`),icon:oe,keywords:[`skills`],run:()=>s.listSkills()},{id:`diag`,category:`Command`,label:c(`commandPalette:cmd.diag`),icon:Bn,keywords:[`diag`,`diagnostics`,`debug`],run:()=>s.getDiag()},{id:`stats`,category:`Command`,label:c(`commandPalette:cmd.stats`),icon:Cn,keywords:[`stats`,`tokens`,`cost`,`cache`],run:()=>s.getStats()},{id:`clear`,category:`Session`,label:c(`commandPalette:cmd.clear`),hint:c(`commandPalette:cmd.clearHint`),icon:At,keywords:[`clear`,`reset`,`wipe`],run:()=>{sr.dropAll(),o(),s.client?.clearContext?.()}},{id:`new`,category:`Session`,label:c(`commandPalette:cmd.new`),hint:c(`commandPalette:cmd.newHint`),icon:se,keywords:[`new`,`fresh`,`session`],run:()=>{s.client?.newSession?.(),Q(`chat`)}},{id:`compact`,category:`Session`,label:c(`commandPalette:cmd.compact`),icon:Nt,keywords:[`compact`,`shrink`,`context`],run:()=>s.client?.compactContext?.()},{id:`repair-context`,category:`Session`,label:c(`commandPalette:cmd.repairContext`),hint:c(`commandPalette:cmd.repairContextHint`),icon:Ne,keywords:[`repair`,`context`,`tool_use`,`tool_result`],run:()=>s.client?.repairContext?.()},{id:`export`,category:`Session`,label:c(`commandPalette:cmd.export`),icon:Pe,keywords:[`export`,`save`,`markdown`,`download`],run:()=>$c()},{id:`export-html`,category:`Session`,label:c(`commandPalette:cmd.exportHtml`),hint:c(`commandPalette:cmd.exportHtmlHint`),icon:Pe,keywords:[`export`,`html`,`download`,`archive`],run:()=>el()},{id:`history`,category:`Command`,label:c(`commandPalette:cmd.history`),icon:Ge,keywords:[`history`,`sessions`],run:()=>{Q(`history`)}},{id:`settings`,category:`Command`,label:c(`commandPalette:cmd.settings`),icon:tn,keywords:[`settings`,`config`],run:()=>to(`settings`)},{id:`model`,category:`Command`,label:c(`commandPalette:cmd.model`),icon:Tn,keywords:[`model`,`provider`,`change`],run:()=>G.getState().setModelSwitcherOpen(!0)},{id:`theme-light`,category:`Theme`,label:c(`commandPalette:cmd.themeLight`),icon:_t,keywords:[`theme`,`light`,`mode`],run:()=>n(`light`)},{id:`theme-dark`,category:`Theme`,label:c(`commandPalette:cmd.themeDark`),icon:Mt,keywords:[`theme`,`dark`,`mode`],run:()=>n(`dark`)},{id:`theme-system`,category:`Theme`,label:c(`commandPalette:cmd.themeSystem`),icon:Mn,keywords:[`theme`,`system`,`auto`],run:()=>n(`system`)},{id:`compact-toggle`,category:`Command`,label:c(`commandPalette:cmd.compactToggle`),icon:On,hint:`Ctrl+Shift+D`,keywords:[`compact`,`dense`,`density`,`size`],run:()=>G.getState().toggleCompactMode()},{id:`sound-toggle`,category:`Command`,label:J.getState().soundOnComplete?c(`commandPalette:cmd.soundOn`):c(`commandPalette:cmd.soundOff`),icon:J.getState().soundOnComplete?pn:Pn,hint:c(`commandPalette:cmd.soundHint`),keywords:[`sound`,`audio`,`chime`,`notify`,`beep`],run:()=>{let e=!J.getState().soundOnComplete;J.getState().setSoundOnComplete(e),e&&Hi()}},{id:`autophase-open`,category:`Command`,label:c(`commandPalette:cmd.autophaseOpen`),icon:_e,keywords:[`autophase`,`autonomous`,`phases`,`rocket`],run:()=>to(`autophase`)},{id:`autophase-toggle`,category:`Command`,label:xr.getState().autonomous?c(`commandPalette:cmd.autoOn`):c(`commandPalette:cmd.autoOff`),icon:xr.getState().autonomous?Sn:Ye,hint:c(`commandPalette:cmd.autoHint`),keywords:[`autonomous`,`autophase`,`auto`,`pause`,`resume`],run:()=>{let e=!xr.getState().autonomous;s.toggleAutoPhaseAutonomous(e)}},{id:`autophase-stop`,category:`Command`,label:c(`commandPalette:cmd.autophaseStop`),icon:Tt,keywords:[`autophase`,`stop`,`autonomous`,`end`],run:()=>s.stopAutoPhase()}],t=e=>{let t=i.getState(),n=G.getState();return{raw:e,addMessage:a,clearMessages:o,client:s.client,queue:t.queue,sendAbort:s.sendAbort,sendMsg:e=>{if(t.isLoading){t.enqueue(e);return}t.addMessage({role:`user`,content:e}),s.sendMessage(e)&&t.setLoading(!0)},setLoading:t.setLoading,setCurrentView:e=>no(e),toggleRefineEnabled:n.toggleRefineEnabled,setProcessMonitorOpen:n.setProcessMonitorOpen,setQueuePanelOpen:n.setQueuePanelOpen,ws:s,onOpenBreakdown:()=>no(`debug`),handleNextList:()=>!1,handleNextSelect:()=>!1}};for(let n of Rc)n.hidden||e.push({id:`slash-${n.name}`,category:`Slash`,label:n.name,hint:n.description,icon:k,keywords:[`slash`,n.name.replace(`/`,``),...(n.aliases??[]).map(e=>e.replace(`/`,``))],run:()=>{rl(t(n.name))}});for(let t of r.slice(0,10))t.isCurrent||e.push({id:`resume-${t.id}`,category:`Session`,label:c(`commandPalette:cmd.resume`,{title:t.title||c(`commandPalette:cmd.emptyTitle`)}),hint:`${t.provider}/${t.model}`,icon:Xt,keywords:[`resume`,t.title,t.id,t.provider,t.model],run:()=>s.resumeSession(t.id)});return e},[r,s,n,a,o,c]),h=(0,q.useMemo)(()=>{let e=l.toLowerCase().trim();return e?m.filter(t=>[t.label,t.hint??``,t.category,...t.keywords??[]].join(` `).toLowerCase().includes(e)):m},[m,l]);(0,q.useEffect)(()=>{d>=h.length&&f(0)},[h.length,d]);let g=e=>{e&&(t(!1),e.run())};return(0,Y.jsx)(Hc,{open:e,onOpenChange:e=>{e||t(!1)},children:(0,Y.jsxs)(Gc,{className:`max-w-2xl gap-0 p-0 overflow-hidden pt-[14dvh]`,showCloseButton:!1,onOpenAutoFocus:e=>{e.preventDefault(),p.current?.focus()},children:[(0,Y.jsx)(Jc,{className:`sr-only`,children:c(`commandPalette:title`)}),(0,Y.jsx)(Yc,{className:`sr-only`,children:c(`commandPalette:placeholder`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b`,children:[(0,Y.jsx)(xe,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`input`,{ref:p,value:l,onChange:e=>u(e.target.value),placeholder:c(`commandPalette:placeholder`),"aria-label":c(`commandPalette:placeholder`),className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`,onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),f(e=>(e+1)%Math.max(1,h.length))):e.key===`ArrowUp`?(e.preventDefault(),f(e=>(e-1+Math.max(1,h.length))%Math.max(1,h.length))):e.key===`Enter`&&(e.preventDefault(),g(h[d]))}}),(0,Y.jsx)(`kbd`,{className:`text-[10px] text-muted-foreground border rounded px-1.5 py-0.5`,children:`Esc`})]}),(0,Y.jsx)(`div`,{className:`max-h-[60dvh] overflow-y-auto`,children:h.length===0?(0,Y.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:c(`commandPalette:noMatches`,{query:l})}):nl(h,d,g,f)}),(0,Y.jsxs)(`div`,{className:`border-t px-4 py-2 text-[10px] uppercase tracking-wider text-muted-foreground flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{children:c(`commandPalette:footer.navigate`)}),(0,Y.jsx)(`span`,{children:c(`commandPalette:footer.select`)}),(0,Y.jsx)(`span`,{children:c(`commandPalette:footer.dismiss`)})]})]})})}function nl(e,t,n,r){let i={};return e.forEach((e,t)=>{i[e.category]||(i[e.category]=[]),i[e.category]?.push({item:e,globalIdx:t})}),(0,Y.jsx)(`div`,{className:`p-1`,children:Object.entries(i).map(([e,i])=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:B.t(`commandPalette:cat.${e}`,{defaultValue:e})}),i.map(({item:e,globalIdx:i})=>{let a=e.icon,o=i===t;return(0,Y.jsxs)(`button`,{type:`button`,onMouseEnter:()=>r(i),onClick:()=>n(e),className:K(`w-full flex items-center gap-3 px-3 py-2 rounded text-left text-sm transition-colors`,o?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,Y.jsx)(a,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`truncate`,children:e.label}),e.hint&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.hint})]}),o&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`↵`})]},e.id)})]},e))})}function rl(e){let{raw:t,addMessage:n,clearMessages:r,client:i,queue:a,sendAbort:o,sendMsg:s,setLoading:c,toggleRefineEnabled:l,setProcessMonitorOpen:u,setQueuePanelOpen:d,ws:f,onOpenBreakdown:p,handleNextList:m,handleNextSelect:h}=e,g=t.trim(),_=g.indexOf(` `),v=(_===-1?g:g.slice(0,_)).toLowerCase(),y=_===-1?``:g.slice(_+1).trim(),b=v,x=e=>{let t=G.getState();Q(`chat`),t.setDockSection(`work`),t.setWorkDashboardTab(e)};switch(b){case`/help`:return n({role:`assistant`,content:[`📖 **Slash commands**`,``,...Rc.map(e=>`• \`${e.name}\`${e.aliases?.length?` (${e.aliases.map(e=>`\`${e}\``).join(`, `)})`:``} — ${e.description}`)].join(`
101
- `)}),!0;case`/clear`:return sr.dropAll(),r(),i?.clearContext?.(),!0;case`/new`:return i?.newSession?.(),Q(`chat`),!0;case`/exit`:return i?.send?.({type:`webui.shutdown`}),n({role:`assistant`,content:`👋 Shutting down WebUI server…`}),!0;case`/compact`:case`/compact!`:return i?.compactContext?.(b===`/compact!`),!0;case`/repair`:return i?.repairContext?.(),!0;case`/debug`:case`/context`:return p?.(),!0;case`/tools`:return f.listTools(),!0;case`/memory`:return f.listMemory(),!0;case`/skill`:case`/skills`:return f.listSkills(),!0;case`/prompt`:case`/prompts`:return G.getState().setPromptLibraryOpen(!0),!0;case`/diag`:return f.getDiag(),!0;case`/stats`:return f.getStats(),!0;case`/save`:return f.saveSession(),!0;case`/load`:case`/resume`:return f.listSessions(50),Q(`history`),!0;case`/agents`:return G.getState().setAgentsMonitorOpen(!0),!0;case`/autonomy`:{let e=y.trim().toLowerCase(),t=[`off`,`suggest`,`auto`,`eternal`,`eternal-parallel`];return e?t.includes(e)?(i?.send?.({type:`autonomy.switch`,payload:{mode:e}}),n({role:`assistant`,content:`🤖 Autonomy mode → **${e}**.`}),!0):(n({role:`assistant`,content:`Unknown autonomy mode \`${e}\`. Try: ${t.join(`, `)}.`}),!0):(n({role:`assistant`,content:`Usage: \`/autonomy <mode>\` — one of: ${t.map(e=>`\`${e}\``).join(`, `)}.`}),!0)}case`/goal`:return i?.send?.({type:`goal.get`}),Q(`chat`),G.getState().setDockSection(`goal`),!0;case`/fleet`:return G.getState().setFleetMonitorOpen(!0),!0;case`/terminal`:case`/term`:return G.getState().setTerminalOpen(!0),!0;case`/collab`:return Q(`chat`),G.getState().setDockSection(`collab`),!0;case`/worktree`:case`/worktrees`:return Q(`worktrees`),G.getState().setDockSection(`worktrees`),!0;case`/mode`:{let e=y.trim();return e?(i?.send?.({type:`mode.switch`,payload:{id:e}}),n({role:`assistant`,content:`Mode → **${e}**.`}),!0):(i?.send?.({type:`modes.list`}),n({role:`assistant`,content:"Fetching available modes… (or pass `/mode <name>` to switch)."}),!0)}case`/mcp`:return i?.send?.({type:`mcp.list`}),to(`settings`),!0;case`/working-dir`:case`/cwd`:{let e=y.trim();if(!e){let e=W.getState().cwd;return n({role:`assistant`,content:e?`📂 Working directory: \`${e}\`\n\n_Pass \`/working-dir <path>\` to change it._`:"Working directory unknown. Pass `/working-dir <path>` to set it."}),!0}return i?.send?.({type:`working_dir.set`,payload:{path:e}}),n({role:`assistant`,content:`📂 Working directory → \`${e}\`.`}),!0}case`/autophase`:{let[e,...t]=y.split(/\s+/).filter(Boolean),r=(e??``).toLowerCase();if(r===`start`){let e=t.join(` `).trim();return e?(i?.send?.({type:`autophase.start`,payload:{title:e}}),to(`autophase`),!0):(n({role:`assistant`,content:"Usage: `/autophase start <title>`"}),!0)}return r===`pause`?(i?.send?.({type:`autophase.pause`,payload:{}}),!0):r===`resume`?(i?.send?.({type:`autophase.resume`,payload:{}}),!0):r===`stop`?(i?.send?.({type:`autophase.stop`,payload:{}}),!0):(to(`autophase`),!0)}case`/brain`:{let[e,...t]=y.split(/\s+/).filter(Boolean),r=(e??``).toLowerCase();if(r===`risk`)i?.send?.({type:`brain.risk`,payload:{level:(t[0]??``).toLowerCase()}});else if(r===`ask`){let e=t.join(` `).trim();e?i?.send?.({type:`brain.ask`,payload:{question:e}}):n({role:`assistant`,content:"Usage: `/brain ask <question>`"})}else i?.send?.({type:`brain.status`});return!0}case`/plan`:return f.getPlan(),x(`plan`),!0;case`/todos`:{if(y.toLowerCase()===`clear`)return i?.clearTodos?.(),!0;x(`todos`);let e=W.getState().todos;if(e.length===0)return n({role:`assistant`,content:`✅ **Todos** — _empty. Ask the agent to plan something and they'll show up here._`}),!0;let t=[`✅ **Todos** (${e.filter(e=>e.status===`completed`).length}/${e.length} done)`,``];for(let n of e){let e=n.status===`completed`?`[x]`:n.status===`in_progress`?`[~]`:`[ ]`,r=n.status===`in_progress`&&n.activeForm?n.activeForm:n.content;t.push(`- ${e} ${r}`)}return t.push(``,"_Use `/todos clear` to wipe the list._"),n({role:`assistant`,content:t.join(`
102
- `)}),!0}case`/export`:return $c(),n({role:`assistant`,content:`📥 Chat exported to your downloads folder.`}),!0;case`/interrupt`:case`/abort`:case`/stop`:case`/int`:return o(),c(!1),!0;case`/settings`:case`/model`:return to(`settings`),!0;case`/setup`:return no(`setup`),!0;case`/enhance`:{let e=!G.getState().refineEnabled;return l(),n({role:`assistant`,content:`Prompt refinement ${e?`enabled`:`disabled`}.`}),!0}case`/suggest`:case`/next-steps`:return s(`What are the next steps I should take? Be specific and actionable.`),!0;case`/review`:case`/cr`:{let e=y.trim();return s(`Review the pending git changes (run \`git diff\` and \`git status\` to see them). ${e?`Focus especially on: ${e}.`:`Cover correctness bugs, security issues, performance, and obvious simplifications.`} For each finding give the file, a short description, severity, and a concrete fix. If there are no changes, review the most recently edited files instead.`),!0}case`/fix`:{let e=y.trim();return s(e?`Diagnose and fix this error. Find the root cause, then apply the fix and explain it:\n\n${e}`:`Investigate the most recent error or failing test, find the root cause, fix it, and verify the fix.`),!0}case`/kill`:case`/ps`:return u(!0),!0;case`/queue`:{let e=a;if(e.length===0)n({role:`assistant`,content:`📋 **Message Queue** — empty.
103
-
104
- Type while the agent is running to queue messages; they are sent automatically when the agent finishes.`});else{let t=[`📋 **Message Queue** (${e.length} queued)`,``];e.forEach((e,n)=>{let r=e.text.length>80?`${e.text.slice(0,77)}…`:e.text;t.push(`${n+1}. ${r}`)}),t.push(``,"_Use `/queue open` to manage, or `/queue clear` to wipe._"),n({role:`assistant`,content:t.join(`
105
- `)})}return y.toLowerCase()===`open`&&d(!0),!0}case`/next`:{let e=y.trim().toLowerCase();return!e||e===`list`||e===`ls`||e===`show`?m():e===`clear`||e===`reset`?(n({role:`assistant`,content:`💡 _Suggestion list cleared._`}),!0):h(y.trim())}case`/f`:case`/f1`:case`/f2`:case`/f3`:case`/f4`:case`/f5`:case`/f6`:case`/f7`:case`/f8`:case`/f9`:case`/f10`:case`/f11`:case`/f12`:{let e={"/f":``,"/f1":`sessionPanel`,"/f2":`fleetMonitor`,"/f3":`agentsMonitor`,"/f4":`worktreeMonitor`,"/f5":`planPanel`,"/f6":`todosMonitor`,"/f7":`queuePanel`,"/f8":`processList`,"/f9":`goalPanel`,"/f10":`sessionsPanel`,"/f11":`coordinatorMonitor`,"/f12":`statuslinePicker`},t=b===`/f`&&y?e[`/f${y.trim()}`]:e[b];if(!t)return n({role:`assistant`,content:[`🎛️ **F-key panels**`,``,`/f 1 — Session panel`,`/f 2 — Fleet orchestration monitor`,`/f 3 — Agents live monitor`,`/f 4 — Worktree monitor`,`/f 5 — Plan panel`,`/f 6 — Todos monitor overlay`,`/f 7 — Queue panel`,`/f 8 — Process list overlay`,`/f 9 — Goal panel`,`/f 10 — Live sessions panel`,`/f 11 — Coordinator monitor`,`/f 12 — Status line picker`,``,`_Or use /f1 … /f12 directly._`].join(`
106
- `)}),!0;let r=G.getState();return Q(`chat`),r.setDockCustomizeOpen(!1),t===`sessionPanel`?(Q(`chat`),!0):t===`fleetMonitor`?(r.setFleetMonitorOpen(!0),!0):t===`agentsMonitor`?(r.setAgentsMonitorOpen(!0),!0):t===`worktreeMonitor`?(Q(`worktrees`),r.setDockSection(`worktrees`),!0):t===`planPanel`?(f.getPlan(),r.setDockSection(`work`),r.setWorkDashboardTab(`plan`),!0):t===`todosMonitor`?(r.setDockSection(`work`),r.setWorkDashboardTab(`todos`),!0):t===`queuePanel`?(r.setQueuePanelOpen(!0),!0):t===`processList`?(r.setProcessMonitorOpen(!0),!0):t===`goalPanel`?(i?.send?.({type:`goal.get`}),Q(`chat`),r.setDockSection(`goal`),!0):t===`sessionsPanel`?(f.listSessions(50),Q(`history`),!0):t===`coordinatorMonitor`?(Q(`officemap`),!0):t===`statuslinePicker`?(Q(`chat`),r.setDockSection(`work`),r.setDockCustomizeOpen(!0),!0):!0}default:return!1}}var il=[{lang:`typescript`,patterns:[{regex:/:\s*(string|number|boolean|void|never|any|unknown|Promise|Array|Record|Map|Set)\b/,weight:4},{regex:/\b(interface|type|enum|namespace|implements|extends|as|satisfies|infer)\b/,weight:3},{regex:/\b(import|export)\s+/,weight:3},{regex:/\b(const|let|var)\s+\w+\s*[:=]/,weight:2},{regex:/=>/,weight:1},{regex:/\.tsx?['"]/,weight:2}]},{lang:`javascript`,patterns:[{regex:/\b(import|export|require)\s*[({]/,weight:3},{regex:/\b(const|let|var)\s+\w+\s*=\s*require/,weight:2},{regex:/\bmodule\.exports/,weight:3},{regex:/\.jsx?['"]/,weight:2}]},{lang:`python`,patterns:[{regex:/^\s*def\s+\w+\s*\(/,weight:4},{regex:/^\s*class\s+\w+.*:/,weight:3},{regex:/\bimport\s+\w+/,weight:2},{regex:/\bfrom\s+\w+\s+import/,weight:3},{regex:/\bprint\(/,weight:1},{regex:/\bself\./,weight:2},{regex:/if\s+__name__\s*==\s*['"]__main__['"]/,weight:4}]},{lang:`rust`,patterns:[{regex:/\bfn\s+\w+\s*[<(]/,weight:4},{regex:/\blet\s+mut\s/,weight:3},{regex:/\b(struct|enum|impl|trait|mod)\s+\w+/,weight:3},{regex:/\bpub\s+(fn|struct|enum)/,weight:3},{regex:/->\s*\w+/,weight:1},{regex:/::\w+/,weight:1}]},{lang:`go`,patterns:[{regex:/\bfunc\s+\w+\s*\(/,weight:4},{regex:/\bpackage\s+\w+/,weight:4},{regex:/\bimport\s*\(/,weight:3},{regex:/\b(err|nil)\b/,weight:2},{regex:/:=/,weight:2},{regex:/\bdefer\s/,weight:2}]},{lang:`json`,patterns:[{regex:/^\s*[{[]/,weight:3},{regex:/"[^"]+"\s*:\s*/,weight:3},{regex:/^\s*[}\]]\s*$/,weight:1}]},{lang:`yaml`,patterns:[{regex:/^---\s*$/,weight:4},{regex:/^\s*\w[\w.-]*:\s/,weight:2},{regex:/^\s*-\s+\w/,weight:1}]},{lang:`html`,patterns:[{regex:/<(!DOCTYPE|html|head|body|div|span|a|p|ul|li|table)/i,weight:4},{regex:/<\/?\w+[\s>]/,weight:2},{regex:/\b(class|id|href|src)="/,weight:2}]},{lang:`css`,patterns:[{regex:/[{]\s*$/,weight:1},{regex:/^\s*[.#@]\S+\s*[{]/,weight:3},{regex:/\b(\d+px|\d+em|\d+rem|\d+vh|\d+vw)\b/,weight:3},{regex:/:\s*\w+\s*!important/,weight:3},{regex:/@(media|keyframes|import|apply)/,weight:3}]},{lang:`sql`,patterns:[{regex:/\b(SELECT|INSERT|UPDATE|DELETE|CREATE TABLE|ALTER TABLE|DROP TABLE)\b/i,weight:4},{regex:/\bFROM\s+\w+/i,weight:2},{regex:/\bWHERE\s+/i,weight:2},{regex:/\b(JOIN|INNER JOIN|LEFT JOIN)\b/i,weight:2}]},{lang:`bash`,patterns:[{regex:/^#!\/.*(bash|sh|zsh)/,weight:5},{regex:/\becho\s/,weight:2},{regex:/\bexport\s+\w+=/,weight:2},{regex:/\bif\s+\[\[?\s/,weight:2},{regex:/\$\{?\w+/,weight:1},{regex:/&&|\|\|/,weight:1}]},{lang:`toml`,patterns:[{regex:/^\s*\[.*\]\s*$/,weight:3},{regex:/^\s*\w+\s*=\s*['"]/,weight:2},{regex:/^\s*\[\[.*\]\]\s*$/,weight:3}]}],al=6,ol=3,sl=180;function cl(e){let t=e.split(`
107
- `);if(t.length<ol)return!1;let n=0,r=0;for(let e of t){let t=e.trim();t.length!==0&&(t.length>sl&&r++,/^ {2,}/.test(e)&&n++,/[.!?]$/.test(t)&&r++,/[{}();=<>[\]]/.test(t)&&n++,/[#$]/.test(t)&&!/^# /.test(t)&&n++)}return n>=r&&n>=2}function ll(e){if(!cl(e))return null;let t={};for(let n of il){let r=0;for(let{regex:t,weight:i}of n.patterns){let n=e.match(new RegExp(t.source,t.flags.includes(`g`)?t.flags:`${t.flags}g`));n&&(r+=n.length*i)}r>0&&(t[n.lang]=r)}t.javascript&&t.typescript&&(t.typescript>=t.javascript?delete t.javascript:t.javascript>t.typescript&&delete t.typescript);let n=null,r=0;for(let[e,i]of Object.entries(t))i>r&&(r=i,n=e);return r>=al?n:null}function ul(e){let t=e.trim();return/^```[\s\S]*```\s*$/.test(t)}function dl(e){if(ul(e))return null;let t=ll(e);return t?{fenced:`\`\`\`${t}\n${e}\n\`\`\``,lang:t}:null}function fl(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function pl({input:e,textareaRef:t,setInput:n}){let[r,i]=(0,q.useState)(null),[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null),[c,l]=(0,q.useState)(null),u=e=>{s.current=e,l(e)};return(0,q.useEffect)(()=>{let e=t.current;if(!e)return;let n=async e=>{let t=e.clipboardData?.items;if(t){for(let n of t)if(n.type.startsWith(`image/`)){e.preventDefault();try{let e=n.getAsFile();if(!e)continue;let t=new FileReader;t.onload=()=>{u(t.result)},t.readAsDataURL(e)}catch{}return}}};return e.addEventListener(`paste`,n),()=>e.removeEventListener(`paste`,n)},[t]),{draggingOver:a,onDragEnter:e=>{!e.dataTransfer||!Array.from(e.dataTransfer.types).includes(`Files`)||(e.preventDefault(),o(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||o(!1)},onDragOver:e=>{!e.dataTransfer||!Array.from(e.dataTransfer.types).includes(`Files`)||(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDrop:e=>{if(!e.dataTransfer)return;let t=Array.from(e.dataTransfer.files??[]);if(t.length===0){o(!1);return}e.preventDefault(),o(!1);let n=t.find(e=>e.type?.startsWith(`image/`));n&&fl(n).then(e=>u(e)).catch(()=>{});let r=t.filter(e=>!e.type?.startsWith(`image/`));if(r.length===0)return;let{addRef:i}=Fr.getState();for(let e of r)i({kind:`file`,path:e.name})},onTextPaste:r=>{let a=r.clipboardData?.getData(`text`)??``;if(!a)return;let o=dl(a);if(o){r.preventDefault();let s=t.current;if(!s)return;let c=s.selectionStart,l=s.selectionEnd,u=e.slice(0,c),d=e.slice(l),f=o.fenced;n(u+f+d);let p=a.split(`
108
- `).length;i({chars:a.length,lines:p,lang:o.lang,undoFence:()=>{n(u+a+d),i(null),requestAnimationFrame(()=>{s&&(s.focus(),s.style.height=`auto`,s.style.height=`${Math.min(s.scrollHeight,200)}px`)})}}),setTimeout(()=>i(null),6e3),requestAnimationFrame(()=>{s.style.height=`auto`,s.style.height=`${Math.min(s.scrollHeight,200)}px`;let e=u.length+f.length;s.setSelectionRange(e,e)});return}if(a.length>800){let e=a.split(`
109
- `).length;i({chars:a.length,lines:e}),setTimeout(()=>i(null),4e3)}},pasteHint:r,pendingImageRef:s,pendingImage:c,clearPendingImage:()=>u(null),setPasteHint:i}}var ml=Xn(`inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,outline:`border border-input bg-background hover:bg-accent hover:text-accent-foreground`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-10 px-4 py-2`,sm:`h-9 rounded-md px-3`,lg:`h-11 rounded-md px-8`,icon:`h-10 w-10`}},defaultVariants:{variant:`default`,size:`default`}}),$=q.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},a)=>(0,Y.jsx)(r?bn:`button`,{className:K(ml({variant:t,size:n,className:e})),ref:a,...i}));$.displayName=`Button`;function hl({original:e,refined:t,english:n,onDecision:r,autoSendDelayMs:i=0}){let a=G(e=>e.setRefinePanel),{t:o}=z(),[s,c]=(0,q.useState)(i>0?Math.ceil(i/1e3):null),[l,u]=(0,q.useState)(t),[d,f]=(0,q.useState)(!1),p=(0,q.useRef)(null),m=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!(i<=0||d))return p.current=setInterval(()=>{c(e=>e===null||e<=1?(clearInterval(p.current),r(`refined`),null):e-1)},1e3),()=>{p.current&&clearInterval(p.current)}},[i,d,r]),(0,q.useEffect)(()=>{let e=e=>{if(!(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement))switch(e.key){case`Enter`:d||(e.preventDefault(),r(`refined`));break;case`e`:case`E`:d||(e.preventDefault(),r(`english`));break;case`o`:case`O`:d||(e.preventDefault(),r(`original`));break;case`t`:case`T`:d||(e.preventDefault(),f(!0));break;case`Escape`:e.preventDefault(),d?(f(!1),u(t)):(a(null),r(`original`));break}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[d,r,t,a]),(0,q.useEffect)(()=>{d&&m.current&&m.current.querySelector(`textarea`)?.focus()},[d]);let h=e=>{p.current&&clearInterval(p.current),a(null),r(e)};return(0,Y.jsxs)(`div`,{ref:m,className:`rounded-lg border bg-card text-card-foreground shadow-sm overflow-hidden animate-message`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:o(`activity:refine.header`)}),s!==null&&!d&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o(`activity:refine.autoSend`,{count:s})})]}),(0,Y.jsx)(`button`,{onClick:()=>h(`original`),className:`text-muted-foreground hover:text-foreground transition-colors`,title:o(`activity:refine.cancelTitle`),children:(0,Y.jsx)(ut,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`div`,{className:`p-4 space-y-3`,children:d?(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground font-medium`,children:o(`activity:refine.editLabel`)}),(0,Y.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),className:`w-full min-h-[80px] rounded-md border border-input bg-background px-3 py-2 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-ring`,placeholder:o(`activity:refine.editPlaceholder`)}),(0,Y.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,Y.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>{f(!1),u(t)},children:o(`common:action.cancel`)}),(0,Y.jsxs)($,{size:`sm`,onClick:()=>{l.trim()&&h(`edit`)},disabled:!l.trim(),children:[(0,Y.jsx)(gt,{className:`h-3 w-3 mr-1`}),o(`activity:refine.useEdit`)]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground font-medium uppercase tracking-wider`,children:o(`activity:refine.original`)}),(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground bg-muted/30 rounded-md px-3 py-2`,children:e.length>200?e.slice(0,200)+`...`:e})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-yellow-600 dark:text-yellow-400 font-medium uppercase tracking-wider`,children:[o(`activity:refine.refined`),` `,(0,Y.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:o(`activity:refine.yourLanguage`)})]}),(0,Y.jsx)(`div`,{className:K(`text-sm bg-yellow-500/10 border border-yellow-500/20 rounded-md px-3 py-2 cursor-pointer`,`hover:bg-yellow-500/20 transition-colors`),onClick:()=>h(`refined`),title:o(`activity:refine.refinedTitle`),children:t.length>300?t.slice(0,300)+`...`:t})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 font-medium uppercase tracking-wider`,children:[(0,Y.jsx)(De,{className:`h-3 w-3`}),o(`activity:refine.english`)]}),(0,Y.jsx)(`div`,{className:K(`text-sm bg-blue-500/10 border border-blue-500/20 rounded-md px-3 py-2 cursor-pointer`,`hover:bg-blue-500/20 transition-colors`),onClick:()=>h(`english`),title:o(`activity:refine.englishTitle`),children:n.length>300?n.slice(0,300)+`...`:n})]})]})}),!d&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-4 py-3 border-t bg-muted/20`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-1 text-xs text-muted-foreground`,children:[(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono`,children:`Enter`}),(0,Y.jsx)(`span`,{children:o(`activity:refine.hintRefined`)}),(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`e`}),(0,Y.jsx)(`span`,{children:o(`activity:refine.hintEnglish`)}),(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`o`}),(0,Y.jsx)(`span`,{children:o(`activity:refine.hintOriginal`)}),(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`t`}),(0,Y.jsx)(`span`,{children:o(`activity:refine.hintEdit`)})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>h(`original`),className:`text-xs`,children:[(0,Y.jsx)(ut,{className:`h-3 w-3 mr-1`}),o(`activity:refine.original`)]}),(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>f(!0),className:`text-xs`,children:[(0,Y.jsx)(Re,{className:`h-3 w-3 mr-1`}),o(`activity:refine.edit`)]}),(0,Y.jsxs)($,{size:`sm`,onClick:()=>h(`refined`),className:`text-xs bg-yellow-600 hover:bg-yellow-700 text-white`,children:[(0,Y.jsx)(gt,{className:`h-3 w-3 mr-1`}),o(`activity:refine.useRefined`)]})]})]})]})}var gl={builtin:`📦`,user:`👤`,project:`📁`,synced:`☁`},_l={title:``,description:``,category:``,tagsCsv:``,content:``,vars:[]};function vl(e,t){return e.replace(/\{\{\s*([\w.-]+)\s*\}\}/g,(e,n)=>Object.hasOwn(t,n.trim())&&t[n.trim()]?t[n.trim()]:e)}function yl(){let{t:e}=z(),{client:t}=ts(),n=G(e=>e.promptLibraryOpen),r=G(e=>e.setPromptLibraryOpen),i=G(e=>e.requestPromptInsert),[a,o]=(0,q.useState)([]),[s,c]=(0,q.useState)([]),[l,u]=(0,q.useState)(``),[d,f]=(0,q.useState)(null),[p,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)([]),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(``),[C,w]=(0,q.useState)({}),T=(0,q.useRef)(null),[E,D]=(0,q.useState)(!1),[O,k]=(0,q.useState)(_l),[A,j]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(!n||!t)return;let e=e=>{let t=e.payload;o(t.prompts??[]),c(t.categories??[])};return t.on(`prompts.list`,e),t.send({type:`prompts.list`}),setTimeout(()=>T.current?.focus(),50),()=>t.off(`prompts.list`,e)},[n,t]),(0,q.useEffect)(()=>{if(!y||!t)return;S(``),w(Object.fromEntries((y.variables??[]).map(e=>[e.name,e.default??``])));let e=e=>{let t=e.payload;t.slug===y.slug&&t.found&&S(t.content)};return t.on(`prompts.content`,e),t.send({type:`prompts.content`,payload:{slug:y.slug}}),()=>t.off(`prompts.content`,e)},[y,t]),(0,q.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&r(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,r]),(0,q.useEffect)(()=>{if(!n||!t||!h)return;let e=e=>{v(e.payload.slugs??[])};return t.on(`prompts.recent`,e),t.send({type:`prompts.recent`}),()=>t.off(`prompts.recent`,e)},[n,t,h]);let M=(0,q.useMemo)(()=>{let e=l.trim().toLowerCase(),t=t=>!e||t.title.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.slug.includes(e)||t.tags.some(t=>t.toLowerCase().includes(e));if(h){let e=new Map(a.map(e=>[e.slug,e]));return _.map(t=>e.get(t)).filter(e=>!!e).filter(t)}return a.filter(e=>p&&!e.favorite||d&&e.category!==d?!1:t(e))},[a,l,d,p,h,_]),N=(0,q.useMemo)(()=>(y?.variables??[]).filter(e=>e.required&&!C[e.name]).map(e=>e.name),[y,C]),P=(0,q.useCallback)(()=>{!y||!x||(t?.send({type:`prompts.used`,payload:{slug:y.slug}}),i(vl(x,C)))},[y,x,C,i,t]),F=(0,q.useCallback)(e=>{t&&(t.send({type:`prompts.favorite`,payload:{slug:e.slug,favorite:!e.favorite}}),o(t=>t.map(t=>t.slug===e.slug?{...t,favorite:!t.favorite}:t)))},[t]);(0,q.useEffect)(()=>{if(!n||!t)return;let e=e=>{let n=e.payload;n.success?(D(!1),k(_l),j(null),t.send({type:`prompts.list`})):j(n.error??B.t(`activity:promptLib.saveFailed`))};return t.on(`prompts.created`,e),()=>t.off(`prompts.created`,e)},[n,t]);let I=(0,q.useCallback)(()=>{if(!t)return;if(!O.title.trim()||!O.content.trim()){j(B.t(`activity:promptLib.titleContentRequired`));return}let e=O.vars.filter(e=>e.name.trim()).map(e=>{let t=e.enumCsv.split(`,`).map(e=>e.trim()).filter(Boolean);return{name:e.name.trim(),...e.description.trim()?{description:e.description.trim()}:{},required:e.required,...e.multiline?{multiline:!0}:{},...t.length>0?{enum:t}:{}}});t.send({type:`prompts.create`,payload:{title:O.title.trim(),content:O.content,description:O.description.trim(),category:O.category.trim()||void 0,tags:O.tagsCsv.split(`,`).map(e=>e.trim()).filter(Boolean),...e.length>0?{variables:e}:{}}})},[t,O]);return(0,Y.jsx)(Hc,{open:n,onOpenChange:e=>{e||r(!1)},children:(0,Y.jsxs)(Gc,{className:`max-w-4xl h-[80dvh] p-0 gap-0 overflow-hidden`,showCloseButton:!1,onOpenAutoFocus:e=>{e.preventDefault(),T.current?.focus()},children:[(0,Y.jsx)(Jc,{className:`sr-only`,children:e(`activity:promptLib.heading`)}),(0,Y.jsx)(Yc,{className:`sr-only`,children:e(`activity:promptLib.searchPlaceholder`)}),(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 w-full overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 w-1/2 flex-col border-r border-border`,children:[(0,Y.jsxs)(`div`,{className:`border-b border-border p-3`,children:[(0,Y.jsx)(`input`,{ref:T,value:l,onChange:e=>u(e.target.value),placeholder:e(`activity:promptLib.searchPlaceholder`),className:`w-full rounded border border-border bg-background px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-primary`}),(0,Y.jsx)(`button`,{onClick:()=>{D(!0),b(null),j(null),k(_l)},className:`mt-2 w-full rounded border border-dashed border-border px-2 py-1 text-xs text-muted-foreground hover:bg-accent hover:text-foreground`,children:e(`activity:promptLib.newPrompt`)}),(0,Y.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>{f(null),m(!1),g(!1)},className:`rounded px-2 py-0.5 text-xs ${d===null&&!p&&!h?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`}`,children:e(`activity:promptLib.all`)}),(0,Y.jsx)(`button`,{onClick:()=>{g(e=>!e),m(!1),f(null)},className:`rounded px-2 py-0.5 text-xs ${h?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`}`,children:e(`activity:promptLib.recent`)}),(0,Y.jsx)(`button`,{onClick:()=>{m(e=>!e),g(!1),f(null)},className:`rounded px-2 py-0.5 text-xs ${p?`bg-yellow-500 text-black`:`bg-muted text-muted-foreground hover:bg-accent`}`,children:e(`activity:promptLib.favorites`)}),s.map(e=>(0,Y.jsxs)(`button`,{onClick:()=>{f(e.id),g(!1),m(!1)},className:`rounded px-2 py-0.5 text-xs ${d===e.id?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`}`,children:[e.label,` (`,e.count,`)`]},e.id))]})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-auto`,children:[M.map(e=>(0,Y.jsxs)(`button`,{onClick:()=>b(e),className:`flex w-full flex-col items-start gap-0.5 border-b border-border/50 px-3 py-2 text-left hover:bg-accent ${y?.slug===e.slug?`bg-accent`:``}`,children:[(0,Y.jsxs)(`div`,{className:`flex w-full items-center gap-1 text-sm`,children:[(0,Y.jsx)(`span`,{children:gl[e.source]??`•`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.title}),e.favorite&&(0,Y.jsx)(`span`,{className:`text-yellow-500`,children:`★`})]}),(0,Y.jsx)(`div`,{className:`line-clamp-1 text-xs text-muted-foreground`,children:e.description})]},e.slug)),M.length===0&&(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:e(`activity:promptLib.noMatch`)})]})]}),(0,Y.jsx)(`div`,{className:`flex min-h-0 min-w-0 w-1/2 flex-col`,children:E?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border p-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold`,children:e(`activity:promptLib.newPromptHeading`)}),(0,Y.jsx)(`button`,{onClick:()=>{D(!1),j(null)},className:`text-xs text-muted-foreground hover:text-foreground`,children:e(`common:action.cancel`)})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 space-y-2 overflow-auto p-3 text-xs`,children:[(0,Y.jsx)(`input`,{value:O.title,onChange:e=>k(t=>({...t,title:e.target.value})),placeholder:e(`activity:promptLib.titlePlaceholder`),className:`w-full rounded border border-border bg-background px-2 py-1 outline-none`}),(0,Y.jsx)(`input`,{value:O.description,onChange:e=>k(t=>({...t,description:e.target.value})),placeholder:e(`activity:promptLib.descPlaceholder`),className:`w-full rounded border border-border bg-background px-2 py-1 outline-none`}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{list:`prompt-category-list`,value:O.category,onChange:e=>k(t=>({...t,category:e.target.value})),placeholder:e(`activity:promptLib.categoryPlaceholder`),className:`w-1/2 rounded border border-border bg-background px-2 py-1 outline-none`}),(0,Y.jsx)(`datalist`,{id:`prompt-category-list`,children:s.map(e=>(0,Y.jsx)(`option`,{value:e.id},e.id))}),(0,Y.jsx)(`input`,{value:O.tagsCsv,onChange:e=>k(t=>({...t,tagsCsv:e.target.value})),placeholder:e(`activity:promptLib.tagsPlaceholder`),className:`w-1/2 rounded border border-border bg-background px-2 py-1 outline-none`})]}),(0,Y.jsx)(`textarea`,{value:O.content,onChange:e=>k(t=>({...t,content:e.target.value})),placeholder:e(`activity:promptLib.contentPlaceholder`),rows:6,className:`w-full resize-y rounded border border-border bg-background px-2 py-1 font-mono outline-none`}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-1`,children:[(0,Y.jsx)(`span`,{className:`font-semibold text-muted-foreground`,children:e(`activity:promptLib.variables`)}),(0,Y.jsx)(`button`,{onClick:()=>k(e=>({...e,vars:[...e.vars,{name:``,description:``,required:!0,multiline:!1,enumCsv:``}]})),className:`rounded border border-border px-1.5 py-0.5 hover:bg-accent`,children:e(`activity:promptLib.addVar`)})]}),O.vars.map((t,n)=>(0,Y.jsxs)(`div`,{className:`space-y-1 rounded border border-border/60 p-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Y.jsx)(`input`,{value:t.name,onChange:e=>k(t=>({...t,vars:t.vars.map((t,r)=>r===n?{...t,name:e.target.value}:t)})),placeholder:e(`activity:promptLib.varNamePlaceholder`),className:`w-1/3 rounded border border-border bg-background px-1.5 py-0.5 outline-none`}),(0,Y.jsx)(`input`,{value:t.description,onChange:e=>k(t=>({...t,vars:t.vars.map((t,r)=>r===n?{...t,description:e.target.value}:t)})),placeholder:e(`activity:promptLib.varDescPlaceholder`),className:`flex-1 rounded border border-border bg-background px-1.5 py-0.5 outline-none`}),(0,Y.jsx)(`button`,{onClick:()=>k(e=>({...e,vars:e.vars.filter((e,t)=>t!==n)})),className:`rounded border border-border px-1.5 text-muted-foreground hover:bg-accent`,title:e(`activity:promptLib.removeVarTitle`),children:`✕`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-1 text-muted-foreground`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:t.required,onChange:e=>k(t=>({...t,vars:t.vars.map((t,r)=>r===n?{...t,required:e.target.checked}:t)}))}),e(`activity:promptLib.required`)]}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-1 text-muted-foreground`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:t.multiline,onChange:e=>k(t=>({...t,vars:t.vars.map((t,r)=>r===n?{...t,multiline:e.target.checked}:t)}))}),e(`activity:promptLib.multiline`)]}),(0,Y.jsx)(`input`,{value:t.enumCsv,onChange:e=>k(t=>({...t,vars:t.vars.map((t,r)=>r===n?{...t,enumCsv:e.target.value}:t)})),placeholder:e(`activity:promptLib.enumPlaceholder`),className:`flex-1 rounded border border-border bg-background px-1.5 py-0.5 outline-none`})]})]},n))]}),(0,Y.jsxs)(`div`,{className:`border-t border-border p-3`,children:[A&&(0,Y.jsx)(`div`,{className:`mb-2 text-xs text-red-500`,children:A}),(0,Y.jsx)(`button`,{onClick:I,disabled:!O.title.trim()||!O.content.trim(),className:`w-full rounded bg-primary px-3 py-2 text-sm text-primary-foreground disabled:opacity-50`,children:e(`activity:promptLib.savePrompt`)})]})]}):y?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between border-b border-border p-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold`,children:y.title}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[y.category,` · `,y.slug]})]}),(0,Y.jsx)(`button`,{onClick:()=>F(y),className:`text-lg`,title:e(`activity:promptLib.toggleFavoriteTitle`),children:y.favorite?`★`:`☆`})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-auto p-3`,children:[(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:x||`…`}),(y.variables??[]).length>0&&(0,Y.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground`,children:e(`activity:promptLib.variables`)}),y.variables.map(t=>{let n=(0,Y.jsxs)(`label`,{className:`text-xs text-muted-foreground`,children:[t.name,t.required?` *`:``,t.description?` — ${t.description}`:``]}),r=e=>w(n=>({...n,[t.name]:e})),i=`mt-0.5 w-full rounded border border-border bg-background px-2 py-1 text-xs outline-none`;return t.enum&&t.enum.length>0?(0,Y.jsxs)(`div`,{children:[n,(0,Y.jsxs)(`select`,{value:C[t.name]??``,onChange:e=>r(e.target.value),className:i,children:[(0,Y.jsx)(`option`,{value:``,children:e(`activity:promptLib.selectOption`)}),t.enum.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]})]},t.name):t.multiline?(0,Y.jsxs)(`div`,{children:[n,(0,Y.jsx)(`textarea`,{value:C[t.name]??``,onChange:e=>r(e.target.value),rows:4,className:`${i} resize-y font-mono`})]},t.name):(0,Y.jsxs)(`div`,{children:[n,(0,Y.jsx)(`input`,{value:C[t.name]??``,onChange:e=>r(e.target.value),className:i})]},t.name)})]})]}),(0,Y.jsx)(`div`,{className:`border-t border-border p-3`,children:(0,Y.jsx)(`button`,{onClick:P,disabled:!x||N.length>0,className:`w-full rounded bg-primary px-3 py-2 text-sm text-primary-foreground disabled:opacity-50`,children:N.length>0?e(`activity:promptLib.fillMissing`,{missing:N.join(`, `)}):e(`activity:promptLib.insertIntoChat`)})})]}):(0,Y.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-4 text-sm text-muted-foreground`,children:e(`activity:promptLib.selectPromptHint`)})})]})]})})}function bl({onOpenBreakdown:e}={}){let{isLoading:r,setLoading:a,addMessage:o,clearMessages:s}=i(We(e=>({isLoading:e.isLoading,setLoading:e.setLoading,addMessage:e.addMessage,clearMessages:e.clearMessages}))),c=i(e=>e.messages).length>0,l=i(e=>e.queue),u=i(e=>e.enqueue),d=i(e=>e.removeQueued),f=i(e=>e.clearQueue),p=G(e=>e.setCurrentView),m=G(e=>e.pushPrompt),h=G(e=>e.promptHistory),g=ts(),{sendMessage:_,sendAbort:v,client:y,refineModel:b}=g,{t:x}=z(),S=G(e=>e.refineEnabled),C=G(e=>e.refinePanel),w=G(e=>e.promptInsertRequest),T=G(e=>e.clearPromptInsert),E=G(e=>e.toggleRefineEnabled),D=G(e=>e.setRefinePanel),O=G(e=>e.setProcessMonitorOpen),k=G(e=>e.setQueuePanelOpen),{reset:A}=Nc(),j=W(e=>e.lastInputTokens),M=W(e=>e.maxContext),[N,F]=(0,q.useState)(``),[I,L]=(0,q.useState)(0),[ee,te]=(0,q.useState)(-1),[ne,re]=(0,q.useState)(null),ie=(0,q.useRef)(null),ae=Fr(e=>e.refs),{removeRef:se,clearRefs:ce}=Fr.getState(),le=ae.length>0,{draggingOver:ue,onDragEnter:de,onDragLeave:fe,onDragOver:me,onDrop:he,onTextPaste:ge,pasteHint:_e,pendingImageRef:ve,pendingImage:ye,clearPendingImage:be,setPasteHint:xe}=pl({input:N,textareaRef:ie,setInput:F});(0,q.useEffect)(()=>{w!=null&&(F(e=>e.trim()?`${e}\n${w}`:w),T(),requestAnimationFrame(()=>ie.current?.focus()))},[w,T]);let Se=(0,q.useCallback)(t=>rl({raw:t,addMessage:o,clearMessages:s,client:y,queue:l,sendAbort:v,sendMsg:Ee,setLoading:a,setCurrentView:p,toggleRefineEnabled:E,setProcessMonitorOpen:O,setQueuePanelOpen:k,ws:g,onOpenBreakdown:e,handleNextList:De,handleNextSelect:Oe}),[o,s,y,l,v,a,p,E,O,k,g,e]),Ce=/💡\s*Next steps?\s*\n+((?:\d+\.\s+.+\n?)+)/i;function we(e){let t=Ce.exec(e);if(!t?.[1])return[];let n=[];for(let e of t[1].split(`
110
- `).filter(Boolean)){let t=/^(\d+)\.\s+(.+)$/.exec(e.trim());t&&n.push({index:Number.parseInt(t[1],10),text:t[2].trim()})}return n.slice(0,6)}function Te(){let e=i.getState().messages;for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.role===`assistant`&&n.content)return we(n.content)}return[]}function Ee(e){if(r){u(e);return}o({role:`user`,content:e}),_(e)&&a(!0)}function De(){let e=i.getState().messages,t=``;for(let n=e.length-1;n>=0;n--){let r=e[n];if(r?.role===`assistant`&&r.content){t=r.content;break}}let n=we(t);if(n.length===0)return o({role:`assistant`,content:"💡 _No next-step suggestions found. Use `/suggest` to generate some._"}),!0;let r=[`💡 **Next steps**`,``];for(let e of n)r.push(`${e.index}. ${e.text}`);return r.push(``,"_Use `/next 1`, `/next 1 2 3` to execute._"),o({role:`assistant`,content:r.join(`
111
- `)}),!0}function Oe(e){let t=Te();if(t.length===0)return o({role:`assistant`,content:"💡 _No suggestions available. Use `/suggest` first._"}),!0;let n=e.split(/[\s,]+/).filter(Boolean).map(e=>Number.parseInt(e,10)).filter(e=>!Number.isNaN(e)&&e>0);if(n.length===0)return o({role:`assistant`,content:`💡 _No valid suggestion numbers._`}),!0;let r=n.filter(e=>e>t.length);if(r.length>0)return o({role:`assistant`,content:`💡 _Invalid suggestion(s): ${r.join(`, `)}. Valid range: 1–${t.length}._`}),!0;for(let e of n){let n=t[e-1];n&&Ee(n.text)}return!0}let ke=N.startsWith(`/`)&&!N.includes(` `)?Bc(N):[];(0,q.useEffect)(()=>{I>=ke.length&&L(0)},[ke.length,I]);let Ae=(0,q.useCallback)(()=>{let e=ie.current;e&&(e.value=``,e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,r||e.focus())},[r]),je=(0,q.useCallback)(async e=>{if(A(),!N.trim()&&!ve.current&&ae.length===0)return;let n=ve.current;be();let i=N.trim(),s=[i,Pr(ae)].filter(Boolean).join(`
112
-
113
- `);if(ce(),i.startsWith(`/`)&&Se(i)){m(i),F(``),te(-1),Ae();return}F(``),te(-1),Ae(),m(i),Ae();let c=n?`![pasted image](${n})\n\n${s}`:s;if(e===`queue`){u(c,`queue`);return}let l=e===`steer`&&r;if(e===`btw`&&r){u(c,`btw`);return}l&&v();try{y?.isConnected?S&&b?(D({original:s,refined:s,english:s,resolve:e=>{}}),b(s)):(o({role:`user`,content:c}),a(!0),_(s,n??void 0)):console.warn(JSON.stringify({level:`warn`,event:`ws_send_failed`,reason:`not_connected`,timestamp:new Date().toISOString()}))}catch(e){console.warn(JSON.stringify({level:`warn`,event:`ws_send_error`,error:t(e),timestamp:new Date().toISOString()})),a(!1)}},[N,ae,r,u,y,_,v,b,S,D,o,a,Se,m,Ae,A,be,ve]),Me=(0,q.useCallback)(e=>{e.preventDefault(),je(`btw`)},[je]),Ne=(0,q.useCallback)(()=>{je(`btw`)},[je]),Pe=(0,q.useCallback)(()=>{je(`steer`)},[je]),Fe=(0,q.useCallback)(()=>{je(`queue`)},[je]),Ie=(0,q.useCallback)(()=>{v(),a(!1)},[v,a]),Le=(0,q.useCallback)(()=>{v(),a(!1);let e=i.getState().messages;for(let t=e.length-1;t>=0;t--){let r=n(e[t]);if(r.role===`user`&&r.content){F(r.content),requestAnimationFrame(()=>{let e=ie.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,e.focus(),e.setSelectionRange(r.content.length,r.content.length))});return}}},[v,a]),Re=(0,q.useCallback)(e=>{if(ke.length===0&&!ne&&h.length>0){if(e.key===`ArrowUp`){let t=e.currentTarget,n=t.value.slice(0,t.selectionStart);if(ee>=0||n.indexOf(`
114
- `)===-1){e.preventDefault();let t=Math.min(h.length-1,ee+1);te(t);let n=h[t]??``;F(n),requestAnimationFrame(()=>{let e=ie.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,e.setSelectionRange(n.length,n.length))});return}}if(e.key===`ArrowDown`&&ee>=0){e.preventDefault();let t=ee-1;if(t<0)te(-1),F(``);else{te(t);let e=h[t]??``;F(e),requestAnimationFrame(()=>{let t=ie.current;t&&(t.style.height=`auto`,t.style.height=`${Math.min(t.scrollHeight,200)}px`,t.setSelectionRange(e.length,e.length))})}return}}if(ke.length>0){if(e.key===`ArrowDown`){e.preventDefault(),L(e=>(e+1)%ke.length);return}if(e.key===`ArrowUp`){e.preventDefault(),L(e=>(e-1+ke.length)%ke.length);return}if(e.key===`Tab`){e.preventDefault();let t=ke[I];t&&(F(t.name+` `),L(0));return}if(e.key===`Enter`&&!e.shiftKey){let t=ke[I];if(t&&t.name!==N.toLowerCase().trim()){e.preventDefault(),F(``),Se(t.name);return}}if(e.key===`Escape`){e.preventDefault(),F(``);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Me(e))},[ke,I,ne,h,ee,N,Se,Me]),ze=()=>{let e=ie.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)};return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(yl,{}),_e&&(0,Y.jsxs)(`div`,{className:K(`rounded-md border px-2.5 py-1.5 text-xs flex items-center justify-between gap-2 animate-message`,_e.lang?`border-emerald-500/30 bg-emerald-500/5 text-emerald-700 dark:text-emerald-300`:`border-amber-500/30 bg-amber-500/5 text-amber-700 dark:text-amber-300`),children:[(0,Y.jsx)(`span`,{children:_e.lang?(0,Y.jsxs)(Y.Fragment,{children:[x(`chat:input.autoFencedAs`),` `,(0,Y.jsx)(`span`,{className:`font-mono font-semibold`,children:_e.lang}),` — `,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:_e.chars.toLocaleString()}),` `,x(`chat:input.charsWord`),` (`,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:_e.lines}),` `,x(`chat:input.linesWord`),`)`]}):(0,Y.jsxs)(Y.Fragment,{children:[x(`chat:input.pastedWord`),` `,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:_e.chars.toLocaleString()}),` `,x(`chat:input.charsWord`),` (`,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:_e.lines}),` `,x(`chat:input.linesWord`),`) `,x(`chat:input.fencedHintPrefix`),` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:"```"}),`.`]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[_e.undoFence&&(0,Y.jsx)(`button`,{type:`button`,onClick:_e.undoFence,className:`underline underline-offset-2 hover:opacity-80`,title:x(`chat:input.removeFencesTitle`),children:x(`common:action.undo`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>xe(null),className:`opacity-60 hover:opacity-100 shrink-0`,title:x(`chat:input.dismissTitle`),children:`×`})]})]}),ye&&(0,Y.jsxs)(`div`,{className:`mb-2 inline-flex items-center gap-2 rounded-lg border border-border bg-muted/40 px-2 py-1.5`,children:[(0,Y.jsx)(`img`,{src:ye,alt:x(`chat:input.pendingAttachmentAlt`),className:`h-12 w-12 rounded object-cover border border-border/50`}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:x(`chat:input.imageAttached`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:be,title:x(`chat:input.removeImageTitle`),className:`inline-flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:bg-muted hover:text-foreground transition-colors`,children:`×`})]}),(0,Y.jsx)(Lc,{queue:l,onClear:f,onRemove:d}),C&&(0,Y.jsx)(hl,{original:C.original,refined:C.refined,english:C.english,onDecision:e=>{let{original:t,refined:n,english:r}=C,i=t;if(e===`refined`?i=n:e===`english`?i=r:e===`edit`&&(i=n),e===`edit`){F(n);return}D(null),y?.isConnected&&(o({role:`user`,content:i}),a(!0),_(i))}}),le&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-1`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground shrink-0`,children:x(`chat:input.referencesLabel`)}),ae.map(e=>(0,Y.jsx)(Ac,{ref:e,onRemove:()=>se(e.id)},e.id)),(0,Y.jsx)(`button`,{type:`button`,onClick:ce,className:`text-[10px] text-muted-foreground hover:text-foreground underline underline-offset-2 shrink-0`,children:x(`chat:input.clearAll`)})]}),(0,Y.jsxs)(`form`,{onSubmit:Me,onDragEnter:de,onDragOver:me,onDragLeave:fe,onDrop:he,className:K(`flex items-end gap-2 relative rounded-lg transition-colors`,ue&&`ring-2 ring-primary ring-offset-2 ring-offset-background bg-primary/5`),children:[ue&&(0,Y.jsxs)(`div`,{className:`absolute inset-0 z-20 flex items-center justify-center pointer-events-none rounded-lg bg-primary/10 text-primary text-sm font-medium`,children:[`Drop file`,`(s)`,` to attach as @-mention`]}),(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(Fc,{atMention:ne,input:N,textareaRef:ie,setInput:F,setAtMention:re}),!ne&&ke.length>0&&(()=>{let e={};ke.forEach((t,n)=>{e[t.category]||(e[t.category]=[]),e[t.category]?.push({cmd:t,idx:n})});let t=zc.filter(t=>e[t]?.length);return(0,Y.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 mb-2 rounded-lg border bg-popover shadow-md p-1 text-sm max-h-72 overflow-auto`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1`,children:`↑/↓ select · Tab complete · Enter dispatch · Esc dismiss`}),t.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 pt-1 pb-0.5 text-[10px] uppercase tracking-wider text-muted-foreground/70 font-semibold`,children:t}),e[t]?.map(({cmd:e,idx:t})=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{F(``),Se(e.name)},onMouseEnter:()=>L(t),className:K(`w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-3`,t===I?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,Y.jsx)(`span`,{className:`font-mono shrink-0`,children:e.name}),e.aliases?.length?(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground/70 font-mono shrink-0`,children:[`(`,e.aliases.join(`, `),`)`]}):null,(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground truncate`,children:[`— `,e.description]})]},e.name))]},t))]})})(),(0,Y.jsx)(`textarea`,{ref:ie,value:N,onChange:e=>{let t=e.target.value;F(t),ze(),ee>=0&&te(-1),re(Vc(t,e.target.selectionStart??t.length))},onSelect:e=>{let t=e.currentTarget;re(Vc(t.value,t.selectionStart))},onKeyDown:Re,onPaste:ge,placeholder:y?.isConnected?x(r?`chat:inputPlaceholderLoading`:`chat:inputPlaceholder`):x(`chat:inputPlaceholderConnecting`),className:K(`flex min-h-[44px] w-full resize-none rounded-lg border border-input bg-background px-4 py-3 pr-12`,`text-sm ring-offset-background placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:cursor-not-allowed disabled:opacity-50`,`scrollbar-thin`),rows:1,disabled:!y?.isConnected}),N.length>0&&(()=>{let e=N.length>=400,t=Math.ceil(N.length/4),n=`text-muted-foreground`,r;if(M>0&&e){let e=(j+t+64)/M*100;e>=100?(n=`text-red-600 dark:text-red-400 font-medium`,r=`Projected ${Math.round(e)}% of ${M.toLocaleString()} ctx — will likely error or compact.`):e>=85?(n=`text-amber-600 dark:text-amber-400 font-medium`,r=`Projected ${Math.round(e)}% of ${M.toLocaleString()} ctx — getting tight.`):r=`≈ ${t.toLocaleString()} tokens · projected ${Math.round(e)}% of ${M.toLocaleString()} ctx.`}else e&&(r=`≈ ${t.toLocaleString()} tokens (4-char heuristic)`);return(0,Y.jsxs)(`span`,{className:K(`absolute bottom-1.5 right-12 text-xs tabular-nums`,n),title:r,children:[N.length,e&&(0,Y.jsxs)(`span`,{className:`ml-1 opacity-70`,children:[`· ≈`,t>=1e3?`${(t/1e3).toFixed(1)}k`:t,`t`]})]})})()]}),(0,Y.jsxs)(`div`,{className:`flex gap-1`,children:[r&&c?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)($,{type:`button`,size:`icon`,variant:`outline`,onClick:Le,className:`h-[44px] w-[44px] rounded-lg`,title:x(`chat:input.stopEditTitle`),"data-testid":`stop-and-edit`,children:(0,Y.jsx)(pe,{className:`h-4 w-4`})}),(0,Y.jsx)($,{type:`button`,size:`icon`,variant:`destructive`,onClick:Ie,className:`h-[44px] w-[44px] rounded-lg`,title:x(`chat:input.abortTitle`),"data-testid":`stop`,children:(0,Y.jsx)(Tt,{className:`h-4 w-4 fill-current`})})]}):(0,Y.jsx)($,{type:`button`,size:`icon`,variant:S?`default`:`outline`,disabled:!y?.isConnected,onClick:E,className:K(`h-[44px] w-[44px] rounded-lg transition-colors`,S&&`bg-yellow-500/20 hover:bg-yellow-500/30 text-yellow-600 dark:text-yellow-400 border-yellow-500/50`),title:x(S?`chat:input.refineEnabledTitle`:`chat:input.refineDisabledTitle`),children:(0,Y.jsx)(oe,{className:`h-4 w-4`})}),(0,Y.jsx)($,{type:`submit`,size:`icon`,variant:`default`,disabled:!N.trim()||!y?.isConnected,className:`h-[44px] w-[44px] rounded-lg bg-sky-600 hover:bg-sky-700 text-white dark:bg-sky-500 dark:hover:bg-sky-600`,title:x(`chat:sendTitle`),"data-testid":`send-submit`,children:(0,Y.jsx)(Zt,{className:`h-4 w-4`})}),c&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)($,{type:`button`,size:`icon`,variant:`default`,disabled:!N.trim()||!y?.isConnected,onClick:Ne,className:`h-[44px] w-[44px] rounded-lg bg-sky-600 hover:bg-sky-700 text-white dark:bg-sky-500 dark:hover:bg-sky-600`,title:x(r?`chat:input.btwRunningTitle`:`chat:input.btwIdleTitle`),"data-testid":`send-btw`,children:(0,Y.jsx)(He,{className:`h-4 w-4`})}),(0,Y.jsx)($,{type:`button`,size:`icon`,variant:`outline`,disabled:!N.trim()||!y?.isConnected,onClick:Pe,className:`h-[44px] w-[44px] rounded-lg border-amber-500/50 text-amber-700 dark:text-amber-400 hover:bg-amber-500/10`,title:x(r?`chat:input.steerRunningTitle`:`chat:input.steerIdleTitle`),"data-testid":`send-steer`,children:(0,Y.jsx)(P,{className:`h-4 w-4`})}),(0,Y.jsx)($,{type:`button`,size:`icon`,variant:`outline`,disabled:!N.trim()||!y?.isConnected,onClick:Fe,className:`h-[44px] w-[44px] rounded-lg border-indigo-500/50 text-indigo-700 dark:text-indigo-400 hover:bg-indigo-500/10`,title:x(`chat:input.addQueueTitle`),"data-testid":`send-queue`,children:(0,Y.jsx)(sn,{className:`h-4 w-4`})})]})]})]})]})}function xl({open:e,onClose:t,className:n}){let{t:r}=z(),[i,a]=(0,q.useState)([]),[o,s]=(0,q.useState)(!1),c=ts(),l=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!(!e||!c.client?.isConnected))return c.client.send?.({type:`session.checkpoints`}),l.current=c.client.on?.(`session.checkpoints`,e=>{let t=e?.payload;t?.checkpoints&&a(t.checkpoints)})??null,()=>{l.current?.()}},[e,c.client]);let u=(0,q.useCallback)(async e=>{s(!0),c.client.send?.({type:`session.rewind`,payload:{checkpointIndex:e}}),setTimeout(()=>{t(),s(!1)},800)},[c.client,t]);return(0,Y.jsx)(Hc,{open:e,onOpenChange:e=>{e||t()},children:(0,Y.jsxs)(Gc,{className:K(`max-w-md gap-0 p-0 overflow-hidden flex flex-col max-h-[75dvh] pt-[10dvh]`,n),children:[(0,Y.jsx)(Jc,{className:`sr-only`,children:r(`activity:checkpoint.heading`)}),(0,Y.jsx)(Yc,{className:`sr-only`,children:r(`activity:checkpoint.countSuffix`,{count:i.length})}),(0,Y.jsx)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Y.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-lg bg-violet-500/10 text-violet-600 dark:text-violet-400`,children:(0,Y.jsx)(Ge,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold`,children:r(`activity:checkpoint.heading`)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:r(`activity:checkpoint.countSuffix`,{count:i.length})})]})]})}),(0,Y.jsx)(`div`,{className:`px-4 py-2.5 border-b bg-muted/20 text-[10px] text-muted-foreground leading-relaxed`,children:r(`activity:checkpoint.description`)}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:i.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,Y.jsx)(kn,{className:`h-10 w-10 opacity-15`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:r(`activity:checkpoint.emptyTitle`)}),(0,Y.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:r(`activity:checkpoint.emptyBody`)})]}):(0,Y.jsx)(`div`,{className:`py-1`,children:[...i].reverse().map((e,t)=>{let n=t===0;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>u(e.index),disabled:o,className:K(`w-full flex items-start gap-3 px-4 py-3 text-left transition-colors group`,n?`bg-primary/5 hover:bg-primary/10`:`hover:bg-accent/40`,o&&`opacity-50 pointer-events-none`),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col items-center mt-1.5`,children:[(0,Y.jsx)(`div`,{className:K(`w-2.5 h-2.5 rounded-full border-2 shrink-0 transition-colors`,n?`border-primary bg-primary/20 shadow-[0_0_0_3px_hsl(var(--primary)/0.25)]`:`border-muted-foreground/30 bg-background group-hover:border-primary/40`)}),t<i.length-1&&(0,Y.jsx)(`div`,{className:`w-px flex-1 min-h-[20px] bg-border/50`})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground tabular-nums shrink-0`,children:[`#`,e.index]}),(0,Y.jsx)(`span`,{className:`text-xs font-medium truncate`,children:e.label}),n&&(0,Y.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium shrink-0`,children:r(`activity:checkpoint.latest`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`tabular-nums`,children:r(`activity:checkpoint.msgSuffix`,{count:e.messageCount})}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[`~`,e.tokens.toLocaleString(),` tok`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[`iter `,e.iteration]})]})]}),(0,Y.jsx)(`span`,{className:`shrink-0 mt-1.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Y.jsx)(ze,{className:`h-4 w-4 text-violet-500`})})]},e.index)})})}),(0,Y.jsxs)(`div`,{className:`border-t px-4 py-2 text-[10px] text-muted-foreground text-center shrink-0`,children:[r(`activity:checkpoint.footerPre`),` ·`,` `,(0,Y.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted font-mono text-[9px]`,children:`Esc`}),` `,r(`activity:checkpoint.footerPost`)]})]})})}function Sl(){let{t:e}=z(),t=W(e=>e.contextMode),r=W(e=>e.contextModes),{listContextModes:i,switchContextMode:a,client:o}=ts(),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(!1),d=(0,q.useRef)(null),f=(0,q.useRef)(null);(0,q.useEffect)(()=>{s&&i()},[s,i]),(0,q.useEffect)(()=>{if(!s)return;let e=e=>{d.current?.contains(e.target)||c(!1)},t=e=>{e.key===`Escape`&&c(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[s]),(0,q.useEffect)(()=>{if(!l)return;let e=e=>{f.current?.contains(e.target)||u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]);let p=(0,q.useCallback)(e=>{o?.compactContext?.(e),u(!1),c(!1)},[o]),m=(0,q.useCallback)(()=>{o?.repairContext?.(),u(!1),c(!1)},[o]),h=r.length>0?r:[{id:`balanced`,name:e(`activity:ctxMode.fallbackName`),description:e(`activity:ctxMode.fallbackDesc`),thresholds:{warn:.6,soft:.75,hard:.9},preserveK:10,eliseThreshold:2e3}],g=h.find(e=>e.id===t)??n(h[0]);return(0,Y.jsxs)(`div`,{ref:d,className:`relative shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:K(`flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 hover:bg-emerald-500/15 transition-colors border border-transparent hover:border-emerald-500/30`),title:e(`activity:ctxMode.triggerTitle`),children:[(0,Y.jsx)(Ce,{className:`h-3 w-3`}),e(`activity:ctxMode.ctxPrefix`),` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:t||g.id}),(0,Y.jsx)(Bt,{className:`h-3 w-3 opacity-60`})]}),(0,Y.jsxs)(`div`,{ref:f,className:`relative`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>u(e=>!e),className:K(`flex items-center justify-center h-5 w-5 rounded-full`,`text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors`,l&&`bg-accent/50 text-foreground`),title:e(`activity:ctxMode.opsHeading`),children:(0,Y.jsx)(Ne,{className:`h-3 w-3`})}),l&&(0,Y.jsxs)(`div`,{className:`absolute top-full right-0 mt-1 w-52 rounded-md border bg-popover shadow-lg z-40 py-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:e(`activity:ctxMode.opsHeading`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p(!1),className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,Y.jsx)(rt,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs`,children:e(`activity:ctxMode.compactNow`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e(`activity:ctxMode.compactNowDesc`)})]})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p(!0),className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,Y.jsx)(rt,{className:`h-3.5 w-3.5 shrink-0 text-red-400`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs`,children:e(`activity:ctxMode.compactAggressive`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e(`activity:ctxMode.compactAggressiveDesc`)})]})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:m,className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,Y.jsx)(Ne,{className:`h-3.5 w-3.5 shrink-0 text-blue-400`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs`,children:e(`activity:ctxMode.repairContext`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e(`activity:ctxMode.repairDesc`)})]})]}),(0,Y.jsx)(`div`,{className:`border-t mt-1 pt-1 px-3 py-1.5`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{document.dispatchEvent(new CustomEvent(`open:context-breakdown`)),u(!1),c(!1)},className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,Y.jsx)(et,{className:`h-3.5 w-3.5 shrink-0 text-green-400`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs`,children:e(`activity:ctxMode.debugContext`)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e(`activity:ctxMode.debugDesc`)})]})]})})]})]})]}),s&&(0,Y.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 w-80 rounded-md border bg-popover shadow-lg z-30 py-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:e(`activity:ctxMode.windowHeading`)}),h.map(n=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{a(n.id),c(!1)},className:K(`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2`,n.id===t&&`bg-accent/30`),children:[(0,Y.jsx)(gt,{className:K(`h-3.5 w-3.5 mt-0.5 shrink-0`,n.id===t?`opacity-100 text-primary`:`opacity-0`)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-mono`,children:n.id}),n.thresholds?.warn!==void 0&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[Math.round(n.thresholds.warn*100),`/`,Math.round(n.thresholds.soft*100),`/`,Math.round(n.thresholds.hard*100),`%`]})]}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:n.description}),(n.preserveK||n.eliseThreshold)&&(0,Y.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground/80`,children:e(`activity:ctxMode.keepElide`,{k:n.preserveK??`-`,t:n.eliseThreshold??`-`})})]})]},n.id))]})]})}function Cl({open:e,onClose:t}){let n=J(e=>e.wsUrl),{lastInputTokens:r,maxContext:i}=W(We(e=>({lastInputTokens:e.lastInputTokens,maxContext:e.maxContext}))),{t:a}=z(),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(null);if((0,q.useEffect)(()=>{if(!e){s(null),d(null);return}l(!0),d(null),s(null);let t=U(n);if(!t?.send){d(B.t(`activity:context.wsNotConnected`)),l(!1);return}t.send({type:`context.debug`});let r=t.on(`context.debug`,e=>{e.type===`context.debug`&&(s(e.payload),l(!1))}),i=setTimeout(()=>{c&&(l(!1),d(B.t(`activity:context.noData`)))},5e3);return()=>{clearTimeout(i),r()}},[e,n]),(0,q.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let f=i>0&&r>0?Math.min(100,Math.round(r/i*100)):0;return(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10dvh] bg-black/40 backdrop-blur-sm`,children:(0,Y.jsxs)(`div`,{className:`w-full max-w-2xl max-h-[80dvh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b sticky top-0 bg-card z-10`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(je,{className:`h-4 w-4 text-[hsl(var(--warning))]`}),a(`activity:context.title`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,Y.jsx)(ut,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:a(`activity:context.windowUsage`)}),(0,Y.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[cs(r),` / `,cs(i),` (`,f,`%)`]})]}),(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:a(`activity:context.contextMode`)}),(0,Y.jsx)(`span`,{className:`block text-sm font-mono font-medium`,children:o?.mode??`—`})]})]}),c?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground py-4`,children:[(0,Y.jsx)(b,{className:`h-4 w-4 animate-spin`}),a(`activity:context.fetching`)]}):u?(0,Y.jsx)(`div`,{className:`rounded-md bg-destructive/10 border border-destructive/20 p-3 text-sm text-destructive`,children:u}):o?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,Y.jsx)(qe,{className:`h-3 w-3`}),a(`activity:context.systemPrompt`)]}),(0,Y.jsx)(`span`,{className:`block text-sm font-mono font-medium`,children:cs(o.systemPrompt)})]}),(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,Y.jsx)(Ne,{className:`h-3 w-3`}),a(`activity:context.tools`)]}),(0,Y.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[cs(o.tools.total),` (`,o.tools.count,`)`]})]}),(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,Y.jsx)(Gt,{className:`h-3 w-3`}),a(`activity:context.messages`)]}),(0,Y.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[cs(o.messages.total),` (`,o.messages.count,`)`]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:a(`activity:context.tokenAllocation`)}),(0,Y.jsx)(`div`,{className:`mt-1.5 h-3 w-full overflow-hidden rounded-full bg-muted flex`,children:o.total>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`h-full bg-blue-500/70 transition-all`,style:{width:`${o.systemPrompt/o.total*100}%`},title:a(`activity:context.systemTitle`,{tokens:cs(o.systemPrompt)})}),(0,Y.jsx)(`span`,{className:`h-full bg-amber-500/70 transition-all`,style:{width:`${o.tools.total/o.total*100}%`},title:a(`activity:context.toolsTitle`,{tokens:cs(o.tools.total)})}),(0,Y.jsx)(`span`,{className:`h-full bg-emerald-500/70 transition-all`,style:{width:`${o.messages.total/o.total*100}%`},title:a(`activity:context.messagesTitle`,{tokens:cs(o.messages.total)})})]})}),(0,Y.jsxs)(`div`,{className:`flex gap-3 mt-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500/70`}),` `,a(`activity:context.system`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-amber-500/70`}),` `,a(`activity:context.tools`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-500/70`}),` `,a(`activity:context.messages`)]})]})]}),o.tools.breakdown.length>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:a(`activity:context.toolBreakdown`)}),(0,Y.jsx)(`div`,{className:`mt-1 space-y-0.5`,children:o.tools.breakdown.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-xs py-0.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.name}),(0,Y.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[e.tokens.toLocaleString(),` tok`]})]},e.name))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:a(`activity:context.messagesSummary`,{count:o.messages.count,total:cs(o.messages.total)})}),(0,Y.jsx)(`div`,{className:`mt-1 space-y-0.5 max-h-40 overflow-y-auto`,children:o.messages.breakdown.slice(0,20).map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs py-0.5`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground font-mono w-6 text-right`,children:e.index}),(0,Y.jsx)(`span`,{className:`text-muted-foreground font-mono w-14`,children:e.role}),(0,Y.jsxs)(`span`,{className:`tabular-nums text-muted-foreground w-14`,children:[e.tokens.toLocaleString(),` tok`]}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/70 truncate flex-1`,children:e.preview.slice(0,80)})]},e.index))})]})]}):null]})]})})}function wl(){let{t:e}=z(),t=W(e=>e.cost),n=W(e=>e.inputCost),r=W(e=>e.outputCost),a=W(e=>e.cacheReadCost),o=i(e=>e.messages),[s,c]=(0,q.useState)(!1),l=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!s)return;let e=e=>{l.current?.contains(e.target)||c(!1)},t=e=>{e.key===`Escape`&&c(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[s]);let u=(()=>{let e=[];for(let t of o)t.role===`assistant`&&t.runSummary&&t.runSummary.costDelta>0&&e.push({id:t.id,preview:t.content.slice(0,80).replace(/\s+/g,` `).trim()||`(empty)`,cost:t.runSummary.costDelta,tools:t.runSummary.tools,ms:t.runSummary.durationMs,ts:t.timestamp});return e.sort((e,t)=>t.cost-e.cost),e.slice(0,5)})(),d=e=>e>=.01?`$${e.toFixed(4)}`:e>0?`$${e.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:`$0`,f=n>0||r>0;return(0,Y.jsxs)(`div`,{ref:l,className:`relative inline-block`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:K(`font-medium text-green-600 dark:text-green-400 hover:underline tabular-nums`),title:e(`activity:cost.clickTitle`),children:[`$`,t.toFixed(4)]}),s&&(0,Y.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-30 w-80 rounded-md border bg-popover shadow-lg p-3 text-foreground`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:e(`activity:cost.heading`)}),(0,Y.jsx)(`span`,{className:`font-mono tabular-nums text-sm font-semibold text-green-600 dark:text-green-400`,children:d(t)})]}),f?(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground font-mono mb-3 border-b pb-2`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{children:`input /1M`}),(0,Y.jsxs)(`span`,{children:[`$`,n.toFixed(2)]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{children:`output /1M`}),(0,Y.jsxs)(`span`,{children:[`$`,r.toFixed(2)]})]}),a>0&&(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{children:`cache /1M`}),(0,Y.jsxs)(`span`,{children:[`$`,a.toFixed(2)]})]})]}):(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic mb-3 border-b pb-2`,children:e(`activity:cost.noPricing`)}),u.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e(`activity:cost.noTurns`)}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground/80 mb-1`,children:e(`activity:cost.topExpensive`,{count:u.length})}),(0,Y.jsx)(`ul`,{className:`space-y-1`,children:u.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=document.querySelector(`[data-message-id="${e.id}"]`);t&&t.scrollIntoView({behavior:`smooth`,block:`center`}),c(!1)},className:`w-full text-left rounded px-2 py-1.5 hover:bg-accent/40 transition-colors`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs truncate`,children:e.preview}),(0,Y.jsx)(`span`,{className:`text-xs font-mono tabular-nums text-green-600 dark:text-green-400 shrink-0`,children:d(e.cost)})]}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-0.5`,children:[e.tools,` tool`,e.tools===1?``:`s`,` · `,(e.ms/1e3).toFixed(1),`s`]})]})},e.id))})]})]})]})}var Tl=[`path`,`file_path`,`pattern`,`command`,`cmd`,`url`,`query`,`description`,`content`];function El(e,t){if(t==null)return``;if(typeof t!=`object`)return Dl(String(t),120);let n=t,r=(e??``).toLowerCase();if(/^todo(_?write)?$|^todos$/i.test(r)||Array.isArray(n.todos)){let e=n.todos??[];if(Array.isArray(e)){let t=e.filter(e=>e.status===`completed`).length,n=e.filter(e=>e.status===`in_progress`).length,r=[`${e.length} todo${e.length===1?``:`s`}`];return t>0&&r.push(`${t} done`),n>0&&r.push(`${n} in-progress`),r.join(` · `)}}if(/batch|parallel/.test(r)||Array.isArray(n.tool_uses)||Array.isArray(n.calls)){let e=n.tool_uses??n.calls??n.batch;if(Array.isArray(e)){let t=new Set;for(let n of e)n&&typeof n==`object`&&`name`in n&&t.add(String(n.name));let n=[...t].slice(0,3).join(`, `),r=t.size>3?` +${t.size-3}`:``;return`${e.length} sub-tool${e.length===1?``:`s`}${n?` · ${n}${r}`:``}`}}if(/^(edit|str_replace|edit_file|patch)$/.test(r)){let e=Ol(n),t=typeof n.old_string==`string`?n.old_string:``,r=typeof n.new_string==`string`?n.new_string:``,i=t?t.split(`
115
- `).length:0,a=r?r.split(`
116
- `).length:0;return`edit ${e||`(file)`}${i||a?` (${i} → ${a} lines)`:``}`}if(/^(write|write_file|create_file|new_file)$/.test(r)){let e=Ol(n),t=typeof n.content==`string`?n.content:``,r=t?t.split(`
117
- `).length:0;return`write ${e||`(file)`}${r?` · ${r} lines`:``}`}if(/^(bash|shell|exec|run|run_command|run_shell)$/.test(r)){let e=n.command??n.cmd??n.script;if(typeof e==`string`)return`$ ${Dl(e,110)}`}if(/^(fetch|http|web|webfetch|curl|request)$/.test(r)){let e=n.url;if(typeof e==`string`)return`${(n.method??`GET`).toUpperCase()} ${Dl(e,100)}`}if(/^(grep|search|ripgrep)$/.test(r)){let e=n.pattern,t=n.path??n.glob??n.type;if(typeof e==`string`)return t?`grep ${Dl(e,60)} in ${t}`:`grep ${Dl(e,100)}`}if(/^(glob|find)$/.test(r)){let e=n.pattern??n.glob;if(typeof e==`string`)return`glob ${Dl(e,100)}`}if(/^(read|read_file|cat)$/.test(r)){let e=Ol(n),t=n.offset,r=n.limit;if(e&&(typeof t==`number`||typeof r==`number`)){let n=t??0;return`read ${e} (${n}…${typeof r==`number`?n+r:``})`}if(e)return`read ${e}`}for(let e of Tl){let t=n[e];if(typeof t==`string`&&t.length>0)return`${e}: ${Dl(t,100)}`}return Dl(kl(t),120)}function Dl(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}function Ol(e){let t=e.file_path??e.path??e.filepath;return typeof t==`string`?t:``}function kl(e){try{return JSON.stringify(e)}catch{return String(e)}}var Al={file:{color:`#60a5fa`},edit:{color:`#fbbf24`},search:{color:`#a78bfa`},folder:{color:`#38bdf8`},terminal:{color:`#67e8f9`},web:{color:`#34d399`},git:{color:`#a3e635`},tree:{color:`#22d3ee`},code:{color:`#818cf8`},test:{color:`#4ade80`},package:{color:`#f472b6`},document:{color:`#94a3b8`},scaffold:{color:`#c084fc`},todo:{color:`#facc15`},plan:{color:`#2dd4bf`},task:{color:`#5eead4`},meta:{color:`#cbd5e1`},index:{color:`#06b6d4`},json:{color:`#eab308`},diff:{color:`#93c5fd`},logs:{color:`#a3a3a3`},settings:{color:`#9ca3af`},brain:{color:`#e879f9`},fallback:{color:`#9ca3af`}},jl={read:`file`,cat:`file`,view:`file`,write:`file`,create:`file`,edit:`edit`,replace:`edit`,str_replace:`edit`,multi_edit:`edit`,patch:`diff`,grep:`search`,search:`search`,rg:`search`,ripgrep:`search`,glob:`search`,find:`search`,folder:`folder`,ls:`folder`,list:`folder`,set_working_dir:`folder`,tree:`tree`,bash:`terminal`,shell:`terminal`,sh:`terminal`,exec:`terminal`,run:`terminal`,command:`terminal`,fetch:`web`,web_fetch:`web`,web_search:`web`,git:`git`,diff:`diff`,lint:`code`,format:`settings`,typecheck:`code`,test:`test`,install:`package`,outdated:`package`,audit:`package`,document:`document`,scaffold:`scaffold`,todo:`todo`,plan:`plan`,task:`task`,json:`json`,index:`index`,logs:`logs`,mode:`meta`,tool_search:`meta`,tool_use:`meta`,batch_tool_use:`meta`,tool_help:`meta`,remember:`brain`,forget:`brain`,search_memory:`brain`,find_related_memories:`brain`};function Ml(e){return e?jl[e.toLowerCase()]??`fallback`:`fallback`}var Nl={file:qe,edit:Je,search:xe,folder:he,terminal:D,web:De,git:Yt,tree:ae,code:Fe,test:v,package:ot,document:Te,scaffold:T,todo:_n,plan:Dt,task:zt,meta:Ne,index:Nt,json:le,diff:h,logs:k,settings:tn,brain:Jn,fallback:Ne};function Pl(e){let t=Ml(e);return{Icon:Nl[t],color:Al[t].color}}var Fl={file:`file read/write`,edit:`file editing`,search:`search & grep`,folder:`folder navigation`,terminal:`shell commands`,web:`web fetch`,git:`git operations`,tree:`directory tree`,code:`code quality`,test:`testing`,package:`package management`,document:`documentation`,scaffold:`project scaffolding`,todo:`todo tracking`,plan:`planning`,task:`task management`,meta:`tool orchestration`,index:`code indexing`,json:`JSON data`,diff:`diff & patch`,logs:`log viewing`,settings:`configuration`,brain:`memory`,fallback:`external tool`};function Il(e){let t=Ml(e),n=Ll(Al[t].color);return`${Fl[t]} — ${n}`}function Ll(e){return{"#60a5fa":`blue`,"#fbbf24":`amber`,"#a78bfa":`violet`,"#38bdf8":`sky`,"#67e8f9":`cyan-light`,"#a3e635":`lime`,"#34d399":`emerald`,"#22d3ee":`cyan`,"#818cf8":`indigo`,"#4ade80":`green`,"#f472b6":`pink`,"#94a3b8":`slate`,"#c084fc":`purple`,"#facc15":`yellow`,"#2dd4bf":`teal`,"#5eead4":`teal-light`,"#cbd5e1":`slate-light`,"#06b6d4":`cyan-dark`,"#eab308":`yellow-dark`,"#93c5fd":`blue-light`,"#a3a3a3":`neutral`,"#9ca3af":`gray`,"#e879f9":`fuchsia`}[e]??`colored`}var Rl=25,zl=12;function Bl({text:e,isError:t,className:n,wrapClass:r,showLineNumbers:i,defaultCollapsed:a}){let o=(0,q.useMemo)(()=>e.split(`
118
- `),[e]),s=o.length>Rl,[c,l]=(0,q.useState)(a?!1:!s),{t:u}=z(),d=c?e:o.slice(0,zl).join(`
119
- `),f=!!i&&s&&c;return(0,Y.jsxs)(`div`,{className:K(`rounded-md border bg-background/40 overflow-hidden`,n),children:[f?(0,Y.jsxs)(`div`,{className:`flex max-h-96 overflow-auto`,children:[(0,Y.jsx)(`pre`,{"aria-hidden":!0,className:`text-xs font-mono leading-[1.4] py-2 pl-2 pr-2 text-muted-foreground/50 select-none border-r border-border/40 bg-muted/20 tabular-nums text-right whitespace-pre shrink-0`,children:o.map((e,t)=>`${t+1}`).join(`
120
- `)}),(0,Y.jsx)(`pre`,{className:K(`text-xs font-mono leading-[1.4] py-2 px-2 flex-1 whitespace-pre`,t?`text-destructive`:`text-foreground`),children:d})]}):(0,Y.jsx)(`pre`,{className:K(`text-xs font-mono p-2 max-h-96 overflow-auto`,r,t?`text-destructive`:`text-foreground`),children:d}),s&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`w-full flex items-center justify-center gap-1 px-2 py-1 border-t bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground transition-colors`,children:c?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(kt,{className:`h-3 w-3`}),u(`activity:toolResult.collapseToLines`,{count:zl})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(It,{className:`h-3 w-3`}),u(`activity:toolResult.showAllLines`,{total:o.length,more:o.length-zl})]})})]})}var Vl=(0,q.memo)(function({toolName:e,result:t,isError:n,className:r,renderMode:i}){let a=(0,q.useMemo)(()=>Hl(e,t),[e,t]),{t:o}=z(),s=i===`simple`;return a.kind===`json`?(0,Y.jsx)(Ul,{value:a.value,isError:n,className:r,defaultCollapsed:s}):a.kind===`numbered`?(0,Y.jsx)(Bl,{text:t,isError:n,className:r,wrapClass:`whitespace-pre`,defaultCollapsed:s}):a.kind===`bash`?(0,Y.jsxs)(`div`,{className:K(`rounded-md border bg-background/40 overflow-hidden`,r),children:[a.stdout&&(0,Y.jsx)(Bl,{text:a.stdout,isError:n,className:`border-0 rounded-none bg-transparent`,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0,defaultCollapsed:s}),(a.exitCode!==void 0||a.duration)&&(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-3 text-[11px] px-2 py-1 border-t bg-muted/30 tabular-nums`,a.exitCode&&a.exitCode!==0?`text-destructive`:`text-muted-foreground`),children:[a.exitCode!==void 0&&(0,Y.jsxs)(`span`,{children:[o(`activity:toolResult.exitCode`),` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:a.exitCode})]}),a.duration&&(0,Y.jsx)(`span`,{children:a.duration})]})]}):(0,Y.jsx)(Bl,{text:t,isError:n,className:r,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0,defaultCollapsed:s})});function Hl(e,t){let n=t.trim();if(/^\s*\d+→/m.test(t.slice(0,200)))return{kind:`numbered`};if(n.startsWith(`{`)&&n.endsWith(`}`)||n.startsWith(`[`)&&n.endsWith(`]`))try{let e=JSON.parse(n);if(typeof e==`object`&&e)return{kind:`json`,value:e}}catch{}let r=!!e&&/^(bash|shell|exec|run)/i.test(e),i=t.match(/(?:^|\n)\s*(?:\[?exit(?:\s*code)?\]?\s*[:=]?\s*)(\d+)\s*$/i),a=t.match(/(?:^|\s)(\d+\s*ms|\d+\.\d+s)\s*$/i);if(r||i){let e=t;return i&&(e=t.slice(0,i.index).trimEnd()),{kind:`bash`,stdout:e,exitCode:i?Number(i[1]):void 0,duration:a?.[1]}}return{kind:`plain`}}function Ul({value:e,isError:t,className:n,defaultCollapsed:r}){let{t:i}=z(),a=(0,q.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]),o=a.split(`
121
- `).length,[s,c]=(0,q.useState)(r?!1:o<30);return(0,Y.jsxs)(`div`,{className:K(`rounded-md border bg-background/40 overflow-hidden`,t&&`border-destructive/40`,n),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`w-full flex items-center justify-between px-2 py-1 border-b bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[s?(0,Y.jsx)(Bt,{className:`h-3 w-3`}):(0,Y.jsx)(vn,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:i(`activity:toolResult.jsonLines`,{count:o})})]}),(0,Y.jsx)(`span`,{children:i(s?`activity:toolResult.collapse`:`activity:toolResult.expand`)})]}),s&&(0,Y.jsx)(`pre`,{className:K(`text-xs font-mono whitespace-pre p-2 max-h-96 overflow-auto`,t?`text-destructive`:`text-foreground`),children:a})]})}async function Wl(e){try{if(typeof navigator<`u`&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function Gl(e,t){if(typeof document>`u`)return;let n=new Blob([t],{type:`text/plain;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function Kl(e){let t=(e??``).toLowerCase();return/bash|shell|exec|run/.test(t)?`log`:(/grep|search|find/.test(t),`txt`)}function ql(e){return e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}var Jl=[s];function Yl({text:e}){let{t}=z(),[n,r]=(0,q.useState)(!1);return(0,Y.jsxs)(`button`,{type:`button`,onClick:(0,q.useCallback)(async()=>{await Wl(e)&&(r(!0),setTimeout(()=>r(!1),1500))},[e]),className:K(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] transition-colors`,`hover:bg-muted-foreground/10`,n?`text-emerald-500`:`text-muted-foreground hover:text-foreground`),title:t(n?`common:action.copied`:`common:action.copy`),children:[n?(0,Y.jsx)(gt,{className:`h-3 w-3`}):(0,Y.jsx)(bt,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:t(n?`common:action.copied`:`common:action.copy`)})]})}var Xl={code({inline:e,className:t,children:n,...r}){let i=/language-(\w+)/.exec(t??``),a=String(n??``).replace(/\n$/,``);if(e||!i)return(0,Y.jsx)(`code`,{className:K(`rounded border border-border/60 px-1.5 py-0.5 text-[0.85em] font-mono`,t),...r,children:n});let o=(0,q.useMemo)(()=>a.split(`
122
- `),[a]),s=o.length>1;return(0,Y.jsxs)(`div`,{className:`not-prose relative my-3 rounded-lg border border-border overflow-hidden group/codeblock`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1 border-b border-border text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(xn,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-muted-foreground font-medium`,children:i[1]}),o.length>0&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums`,children:[o.length,` line`,o.length===1?``:`s`]})]}),(0,Y.jsx)(Yl,{text:a})]}),s?(0,Y.jsxs)(`div`,{className:`flex max-h-[40rem] overflow-auto`,children:[(0,Y.jsx)(`pre`,{"aria-hidden":!0,className:`text-xs font-mono leading-[1.55] py-3 pl-3 pr-2 text-muted-foreground/40 select-none border-r border-border/30 tabular-nums text-right shrink-0`,children:o.map((e,t)=>(0,Y.jsx)(`div`,{children:t+1},t))}),(0,Y.jsx)(`pre`,{className:`overflow-x-auto py-3 px-3 text-xs leading-[1.55] font-mono flex-1`,children:(0,Y.jsx)(`code`,{className:K(`hljs`,t),...r,children:n})})]}):(0,Y.jsx)(`pre`,{className:`overflow-x-auto p-3 text-xs leading-relaxed font-mono max-h-[40rem]`,children:(0,Y.jsx)(`code`,{className:K(`hljs`,t),...r,children:n})}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute bottom-8 left-0 right-0 h-8 bg-gradient-to-t from-black/10 to-transparent opacity-0 group-hover/codeblock:opacity-100 transition-opacity`})]})}};function Zl({text:e,className:t,label:n}){let{t:r}=z(),[i,a]=(0,q.useState)(!1),o=n??r(`common:action.copy`);return(0,Y.jsx)(`button`,{type:`button`,onClick:async t=>{t.stopPropagation(),await Wl(e)&&(a(!0),setTimeout(()=>a(!1),1400))},className:K(`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,t),title:o,children:i?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(gt,{className:`h-3 w-3 text-green-500`}),(0,Y.jsx)(`span`,{children:r(`common:action.copied`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(bt,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:o})]})})}function Ql(e){let t=e.split(`
123
- `);for(let e=0;e<t.length;e++){let r=n(t[e]);if(/^\s*at\s+\S+.*\(.*:\d+:\d+\)\s*$/.test(r)||/^\s*at\s+\S+\.\S+\(\S+\.java:\d+\)\s*$/.test(r)||/^\s+File "[^"]+", line \d+/.test(r))return e}return-1}function $l({text:e}){let{t}=z(),n=Ql(e),[r,i]=(0,q.useState)(!1);if(n===-1)return(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:e});let a=e.split(`
124
- `),o=a.slice(0,n).join(`
125
- `).trim(),s=a.slice(n).join(`
126
- `),c=s.split(`
127
- `).filter(e=>e.trim().length>0).length;return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[o&&(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:o}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`inline-flex items-center gap-1 text-xs text-destructive hover:text-destructive/80 font-medium`,children:[r?`▾`:`▸`,` `,t(r?`activity:errorBody.hideStack`:`activity:errorBody.showStack`,{count:c})]}),r&&(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[11px] leading-snug bg-destructive/5 border border-destructive/20 rounded p-2 max-h-80 overflow-auto`,children:s})]})}function eu({input:e}){let{t}=z(),[n,r]=(0,q.useState)({});if(typeof e!=`object`||!e||Array.isArray(e))return(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-all text-xs font-mono`,children:JSON.stringify(e,null,2)});let i=Object.entries(e);return i.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:t(`activity:toolInput.noParams`)}):(0,Y.jsx)(`div`,{className:`text-xs font-mono`,children:i.map(([e,i])=>{if(i==null||typeof i==`string`||typeof i==`number`||typeof i==`boolean`){let t=i===null?`null`:i===void 0?`undefined`:typeof i==`string`?i:String(i),n=typeof i==`string`&&(t.length>80||t.includes(`
128
- `));return(0,Y.jsxs)(`div`,{className:K(`py-0.5`,n?`flex flex-col gap-0.5`:`flex items-baseline gap-2`),children:[(0,Y.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`span`,{className:K(`text-foreground`,n?`whitespace-pre-wrap break-all bg-muted/40 rounded px-1.5 py-1`:`truncate`,typeof i==`string`?``:`text-amber-600 dark:text-amber-400`),title:typeof i==`string`&&!n?t:void 0,children:t})]},e)}let a=!!n[e],o=Array.isArray(i)?`[${t(`activity:toolInput.itemCount`,{count:i.length})}]`:`{${t(`activity:toolInput.keyCount`,{count:Object.keys(i).length})}}`;return(0,Y.jsxs)(`div`,{className:`py-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r(t=>({...t,[e]:!t[e]})),className:`flex items-baseline gap-2 hover:bg-muted/30 rounded px-1 -mx-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground/60 text-[10px]`,children:a?`▾`:`▸`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,Y.jsx)(`span`,{className:`text-violet-600 dark:text-violet-400`,children:o})]}),a&&(0,Y.jsx)(`pre`,{className:`ml-3 mt-1 whitespace-pre-wrap break-all text-[11px] bg-muted/40 rounded px-2 py-1.5`,children:JSON.stringify(i,null,2)})]},e)})})}var tu=(0,q.memo)(function({message:e,isFirst:t=!1,isContinuation:r=!1}){let{t:o}=z(),[s,c]=(0,q.useState)({}),[u,d]=(0,q.useState)(!1),[p,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(``),[_,v]=(0,q.useState)(!1),y=e.role===`user`,b=e.role===`tool`,x=!!e.thinkingLog;e.role;let S=i(e=>e.truncateAfter),C=i(e=>e.addMessage),w=i(e=>e.setLoading),T=i(e=>e.isLoading),E=J(e=>e.wsUrl),D=G(e=>e.pinnedIds),O=G(e=>e.togglePin),k=G(e=>e.compactMode),A=G(e=>e.searchOpen),j=G(e=>e.searchActiveMessageId),M=D.includes(e.id),N=W(e=>e.inputCost),P=W(e=>e.outputCost),F=W(e=>e.cacheReadCost),I=$n(),{autonomy:ee,yolo:te}=I,{canAutoSubmit:ne,recordAutoSubmit:re,capWarned:ie}=Nc(),ae=I.autoProceedMaxIterations<=0||ne(),oe=e=>{if(!ne()){ie||C({role:`assistant`,content:o(`activity:message.autoPaused`)});return}re(),C({role:`user`,content:e}),w(!0),U(E).sendMessage(e),Wr(``)},ce=(()=>{if(e.role!==`assistant`||T)return!1;let t=i.getState().messages;for(let r=t.length-1;r>=0;r--){let i=n(t[r]);if(i.role===`assistant`)return i.id===e.id}return!1})(),le=(0,q.useMemo)(()=>ce&&e.content?Br(e.content):null,[ce,e.content]);(0,q.useEffect)(()=>{if(!e.thinkingLog||!A||j!==e.id)return;let t=G.getState().searchQuery.trim().toLowerCase();t&&e.thinkingLog.text.toLowerCase().includes(t)&&d(!0)},[e.id,e.thinkingLog,j,A]);let ue=()=>{let t=i.getState().messages,r=t.findIndex(t=>t.id===e.id);if(r===-1)return;let a=-1;for(let e=r-1;e>=0;e--)if(t[e]?.role===`user`){a=e;break}if(a===-1)return;let o=n(t[a]);S(o.id),C({role:`user`,content:o.content}),w(!0),U(E).sendMessage(o.content)},de=e=>{c(t=>({...t,[e]:!t[e]}))},fe=()=>{g(e.content),m(!0)},me=()=>{m(!1),g(``)},he=()=>{let t=h.trim();if(!t){me();return}S(e.id),C({role:`user`,content:t}),w(!0),U(E).sendMessage(t),m(!1),g(``)};return(0,Y.jsxs)(`div`,{"data-message-id":e.id,"data-pinned":M?`1`:void 0,className:K(`group flex msg-bubble animate-message rounded-lg transition-shadow`,k?`gap-2`:`gap-3`,y?`flex-row-reverse`:`flex-row`,M&&`ring-1 ring-amber-500/30 bg-amber-500/[0.02] px-1 -mx-1`),children:[r?(0,Y.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,Y.jsx)(`div`,{className:K(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,`ring-2 ring-offset-2 ring-offset-background`,y?`bg-primary text-primary-foreground ring-primary/20`:b?`bg-secondary text-secondary-foreground ring-secondary/20`:x?`bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-violet-500/20`:`bg-accent text-accent-foreground ring-accent/20`),children:y?(0,Y.jsx)(qt,{className:`h-4 w-4`}):b?(0,Y.jsx)(yn,{className:`h-4 w-4`}):x?(0,Y.jsx)(Jn,{className:`h-4 w-4`}):(0,Y.jsx)(wt,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{className:K(`flex flex-col gap-1.5 max-w-[85%]`,y&&`items-end`),children:[t&&!r&&(0,Y.jsx)(`span`,{className:K(`text-xs font-medium px-1`,y?`text-primary`:b?`text-secondary`:x?`text-violet-600 dark:text-violet-400`:`text-muted-foreground`),children:o(y?`activity:message.roleYou`:b?`activity:message.roleTool`:x?`activity:message.roleThinking`:`activity:message.roleAssistant`)}),b&&e.toolName&&(()=>{let{Icon:t,color:n}=Pl(e.toolName),r=Il(e.toolName);return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>de(e.id),className:K(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1 -mx-2 transition-colors`,e.isError?`text-destructive`:`text-foreground`),title:r,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:s[e.id]?(0,Y.jsx)(Bt,{className:`h-3 w-3`}):(0,Y.jsx)(vn,{className:`h-3 w-3`})}),(0,Y.jsx)(t,{className:`h-3 w-3`,style:{color:n}}),(0,Y.jsx)(`span`,{className:`font-mono`,style:{color:n},children:e.toolName}),e.toolResult===void 0?(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500 animate-pulse`,"aria-hidden":!0}):e.isError?(0,Y.jsx)(f,{className:`h-3 w-3 text-destructive`}):(0,Y.jsx)(jn,{className:`h-3 w-3 text-green-500`}),typeof e.toolDurationMs==`number`&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:ql(e.toolDurationMs)})]})})(),(0,Y.jsx)(`div`,{className:K(`rounded-2xl`,k?`px-3 py-1.5`:`px-4 py-3`,y?`bg-primary text-primary-foreground rounded-br-md`:b?e.isError?`bg-destructive/5 border border-destructive/20 text-destructive`:`bg-muted/80 text-foreground`:`bg-card border text-foreground`,e.isError&&!b&&`border-destructive/20`,y&&e.status===`failed`&&`opacity-60 ring-1 ring-destructive/30`),children:b?(()=>{let t=!!s[e.id],n=e.toolInput===void 0?``:El(e.toolName,e.toolInput),r=e.toolResult?e.toolResult.split(`
129
- `).length:0;return(0,Y.jsxs)(`div`,{className:`space-y-1 tool-details`,children:[n&&!t&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono truncate`,children:n}),e.toolResult===void 0&&e.progressLines&&e.progressLines.length>0&&(0,Y.jsx)(`div`,{className:`mt-1 rounded-md border border-amber-500/20 bg-amber-500/5 p-1.5 text-[11px] font-mono leading-snug max-h-32 overflow-auto`,children:(()=>{let t=new Map;return e.progressLines.slice(-6).map(e=>{let n=t.get(e)??0;return t.set(e,n+1),(0,Y.jsx)(`div`,{className:`truncate text-muted-foreground`,children:e},`${e}-${n}`)})})()}),t&&e.toolInput!==void 0&&(()=>{let t=_c(e.toolName,e.toolInput);return t?(0,Y.jsx)(mc,{oldText:t.oldText,newText:t.newText,caption:t.caption}):(0,Y.jsxs)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-muted-foreground mb-2 text-xs`,children:[(0,Y.jsx)(kn,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:o(`activity:message.inputLabel`)})]}),(0,Y.jsx)(eu,{input:e.toolInput})]})})(),t&&e.toolResult!==void 0&&e.toolResult.length>0&&(0,Y.jsxs)(`div`,{className:`relative group/tool`,children:[(0,Y.jsx)(Vl,{toolName:e.toolName,result:e.toolResult,isError:e.isError}),(0,Y.jsxs)(`div`,{className:`absolute top-1.5 right-1.5 flex items-center gap-1 opacity-0 group-hover/tool:opacity-100 transition-opacity`,children:[(0,Y.jsx)(Zl,{text:e.toolResult,label:``,className:`bg-background/80 border rounded px-1.5 py-0.5`}),e.toolResult.split(`
130
- `).length>5&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation();let n=Kl(e.toolName);Gl(`${(e.toolName??`output`).replace(/[^a-z0-9_-]+/gi,`-`).toLowerCase()}-${new Date().toISOString().replace(/[:.]/g,`-`)}.${n}`,e.toolResult??``)},className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground bg-background/80 border rounded px-1.5 py-0.5`,title:o(`activity:message.downloadTitle`),children:(0,Y.jsx)(Pe,{className:`h-3 w-3`})})]})]}),t&&e.toolResult!==void 0&&e.toolResult.length===0&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:o(`activity:message.empty`)}),!t&&e.isError&&e.toolResult&&(0,Y.jsx)(`div`,{className:`text-xs font-mono text-destructive truncate`,children:e.toolResult.split(`
131
- `)[0]}),(e.toolResult!==void 0&&e.toolResult.length>0||e.toolInput!==void 0&&Object.keys(e.toolInput??{}).length>0)&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>de(e.id),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:t?o(`activity:message.hideDetails`):r>0?o(`activity:message.showDetailsLines`,{count:r}):o(`activity:message.showDetails`)})]})})():p&&y?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-[280px]`,children:[(0,Y.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),me()):e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),he())},rows:Math.min(8,Math.max(2,h.split(`
132
- `).length)),className:`w-full resize-none rounded-md border bg-background text-foreground px-2 py-1.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-ring`}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-primary-foreground/60`,children:o(`activity:message.editHint`)}),(0,Y.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:me,className:`text-xs px-2 py-0.5 rounded border border-primary-foreground/30 hover:bg-primary-foreground/10`,children:o(`common:action.cancel`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:he,disabled:!h.trim(),className:`text-xs px-2 py-0.5 rounded bg-primary-foreground text-primary disabled:opacity-50`,children:o(`activity:message.saveResend`)})]})]})]}):e.thinkingLog?(()=>{let t=e.thinkingLog,n=t.text.split(`
133
- `).length,r=Math.max(.1,t.durationMs/1e3),i=t.replayed?o(`activity:message.replay`):`${r.toFixed(+(r<10))}s`,a=t.text.split(`
134
- `).slice(-4).join(`
135
- `).trim();return(0,Y.jsxs)(`div`,{className:`min-w-0 max-w-[min(720px,85vw)]`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`flex w-full flex-wrap items-center gap-x-2 gap-y-1 text-left text-sm font-medium text-violet-600 dark:text-violet-400`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground/60`,children:u?(0,Y.jsx)(Bt,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(vn,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(Jn,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`min-w-0`,children:o(`activity:message.thinkingProcess`)}),(0,Y.jsx)(`span`,{className:`ml-0 text-[10px] font-mono font-normal text-muted-foreground sm:ml-auto`,children:o(`activity:message.thinkingMeta`,{iter:t.iteration,dur:i,lines:o(`activity:message.linesSuffix`,{count:n})})})]}),(0,Y.jsx)(`pre`,{className:K(`mt-2 whitespace-pre-wrap break-words rounded-lg border border-violet-500/20 bg-violet-500/[0.04] p-3 font-mono text-xs leading-relaxed text-foreground/80`,u?`max-h-[32rem] overflow-auto`:`max-h-24 overflow-hidden`),children:u?t.text:a||t.text}),(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,Y.jsx)(Zl,{text:t.text,label:o(`activity:message.copyLog`),className:`opacity-70 hover:opacity-100 transition-opacity`}),!u&&n>4&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>d(!0),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:o(`activity:message.showFullLog`)})]})]})})():(()=>{let t=le?le.stripped:e.content;return(0,Y.jsx)(`div`,{className:K(`text-sm leading-relaxed markdown-content`,e.streaming&&`streaming-cursor`),children:t?_&&e.role===`assistant`?(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground/90 max-h-[40rem] overflow-auto`,children:e.content}):e.role===`assistant`&&e.isError?(0,Y.jsx)($l,{text:e.content}):(0,Y.jsx)(a,{remarkPlugins:[l],rehypePlugins:Jl,components:Xl,children:t}):e.streaming?(0,Y.jsx)(`span`,{className:`inline-block animate-pulse text-muted-foreground`,children:o(`activity:message.typing`)}):(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:o(`activity:message.noContent`)})})})()}),y&&e.status===`failed`&&(0,Y.jsx)(`span`,{className:`text-[10px] font-medium text-destructive flex items-center gap-1 px-1`,children:o(`activity:message.failedToSend`)}),le&&le.steps.length>0&&(0,Y.jsx)(Kr,{steps:le.steps,yoloMode:te,autoMode:ee===`auto`,autoDelayMs:I.autonomyDelayMs,onAutoSubmit:oe,canAutoSubmit:ae}),(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-2 px-1`,y?`flex-row-reverse`:`flex-row`),children:[(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground/50`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),(0,Y.jsx)(`span`,{className:`w-px h-3 bg-border/60 shrink-0`,"aria-hidden":!0}),e.runSummary&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[o(`activity:message.rsIterations`,{n:e.runSummary.iterations}),o(`activity:message.rsTools`,{n:e.runSummary.tools}),o(`activity:message.rsElapsed`,{s:`${(e.runSummary.durationMs/1e3).toFixed(2)}s`}),e.runSummary.costDelta>0?o(`activity:message.rsCost`,{c:e.runSummary.costDelta.toFixed(4)}):``].filter(Boolean).join(` · `),children:[e.runSummary.iterations,` iter`,e.runSummary.tools>0?` · ${e.runSummary.tools} tool${e.runSummary.tools===1?``:`s`}`:``,` · `,e.runSummary.durationMs<6e4?`${(e.runSummary.durationMs/1e3).toFixed(1)}s`:`${Math.floor(e.runSummary.durationMs/6e4)}m ${Math.floor(e.runSummary.durationMs%6e4/1e3)}s`,e.runSummary.costDelta>0?` · ${e.runSummary.costDelta>=.01?e.runSummary.costDelta.toFixed(4):e.runSummary.costDelta.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``]}),e.usage&&(e.usage.input>0||e.usage.output>0)&&(()=>{let t=e.usage,n=(t.input*N+t.output*P+(t.cacheRead??0)*F)/1e6,r=N>0||P>0,i=n>=.01?`${n.toFixed(4)}`:n>0?`${n.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``;return(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[o(`activity:message.useInput`,{n:t.input.toLocaleString()}),o(`activity:message.useOutput`,{n:t.output.toLocaleString()}),t.cacheRead?o(`activity:message.useCacheRead`,{n:t.cacheRead.toLocaleString()}):``,r?o(`activity:message.useCost`,{c:i}):``].filter(Boolean).join(` · `),children:[t.input.toLocaleString(),`→`,t.output.toLocaleString(),t.cacheRead?` · ${t.cacheRead.toLocaleString()} ↺`:``,r&&i?` · ${i}`:``]})})(),!b&&e.content&&!e.streaming&&(0,Y.jsx)(Zl,{text:e.content,label:o(`common:action.copy`),className:`opacity-50 hover:opacity-100 transition-opacity`}),e.role===`assistant`&&e.content&&!e.streaming&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),title:o(_?`activity:message.showRenderedTitle`:`activity:message.showRawTitle`),className:K(`text-xs inline-flex items-center gap-1 transition-opacity`,_?`text-primary hover:text-primary/80 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[(0,Y.jsx)(xn,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:o(_?`activity:message.renderedLabel`:`activity:message.rawLabel`)})]}),y&&!p&&!T&&e.content&&(0,Y.jsxs)(`button`,{type:`button`,onClick:fe,title:o(`activity:message.editTitle`),className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,Y.jsx)(pe,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:o(`activity:message.editLabel`)})]}),e.role===`assistant`&&e.content&&!e.streaming&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>O(e.id),title:o(M?`activity:message.unpinTitle`:`activity:message.pinTitle`),className:K(`text-xs inline-flex items-center gap-1 transition-opacity`,M?`text-amber-500 hover:text-amber-600 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[M?(0,Y.jsx)(L,{className:`h-3 w-3`}):(0,Y.jsx)(nt,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:o(M?`activity:message.pinnedLabel`:`activity:message.pinLabel`)})]}),ce&&e.content&&!e.streaming&&(0,Y.jsxs)(`button`,{type:`button`,onClick:ue,title:o(`activity:message.regenerateTitle`),className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,Y.jsx)(se,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:o(`activity:message.retryLabel`)})]})]})]})]})});function nu(){let{t:e}=z(),t=W(e=>e.mode),n=W(e=>e.modes),{listModes:r,switchMode:i}=ts(),[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);(0,q.useEffect)(()=>{a&&r()},[a,r]),(0,q.useEffect)(()=>{if(!a)return;let e=e=>{s.current?.contains(e.target)||o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=n.length>0?n:[{id:`default`,name:e(`activity:mode.defaultName`),description:e(`activity:mode.defaultDesc`)}];return(0,Y.jsxs)(`div`,{ref:s,className:`relative shrink-0`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:K(`flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-accent/40 text-foreground hover:bg-accent transition-colors border border-transparent hover:border-primary/30`),title:e(`activity:mode.activeTitle`),children:[e(`activity:mode.modePrefix`),` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:t||`default`}),(0,Y.jsx)(Bt,{className:`h-3 w-3 opacity-60`})]}),a&&(0,Y.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 w-64 rounded-md border bg-popover shadow-lg z-30 py-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:e(`activity:mode.heading`)}),c.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{i(e.id),o(!1)},className:K(`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2`,e.id===t&&`bg-accent/30`),children:[(0,Y.jsx)(gt,{className:K(`h-3.5 w-3.5 mt-0.5 shrink-0`,e.id===t?`opacity-100 text-primary`:`opacity-0`)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-mono`,children:e.id}),e.description&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:e.description})]})]},e.id))]})]})}var ru=`
136
- ::highlight(chat-search) { background-color: hsl(var(--primary) / 0.3); color: inherit; }
137
- ::highlight(chat-search-active) { background-color: hsl(var(--primary) / 0.85); color: hsl(var(--primary-foreground)); }
138
- `;function iu(e){return e.thinkingLog?[e.content,e.thinkingLog.text].filter(Boolean).join(`
139
- `):e.role===`tool`?[e.toolName??``,e.toolResult??``,JSON.stringify(e.toolInput??``)].join(`
140
- `):e.content}function au(){let{t:e}=z(),t=G(e=>e.searchOpen),n=G(e=>e.setSearchOpen),r=G(e=>e.searchQuery),a=G(e=>e.setSearchQuery),o=i(e=>e.messages),s=G(e=>e.requestScrollToMessage),c=G(e=>e.setSearchActiveMessageId),l=(0,q.useRef)(null),[u,d]=(0,q.useState)(0),[f,p]=(0,q.useState)(0);(0,q.useEffect)(()=>{t&&requestAnimationFrame(()=>l.current?.focus())},[t]),(0,q.useEffect)(()=>{let e=document.createElement(`style`);return e.textContent=ru,document.head.appendChild(e),()=>{document.head.removeChild(e)}},[]);let m=(0,q.useMemo)(()=>{let e=r.trim().toLowerCase();return e?o.filter(t=>iu(t).toLowerCase().includes(e)).map(e=>e.id):[]},[o,r]);if((0,q.useEffect)(()=>{u>=m.length&&d(0)},[m,u]),(0,q.useEffect)(()=>{c(t&&r.trim()?m[u]??null:null)},[t,r,m,u,c]),(0,q.useEffect)(()=>{let e=window,n=e.CSS?.highlights,i=e.Highlight;if(!n||!i)return;let a=()=>{n.delete(`chat-search`),n.delete(`chat-search-active`)},o=r.trim();if(!o||!t){a();return}let s=o.toLowerCase(),c=[],l=[],d=m[u];for(let e of document.querySelectorAll(`[data-message-id]`)){let t=e.dataset.messageId===d,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=n.nextNode();for(;r;){let e=r.nodeValue??``;if(e.length>0){let n=e.toLowerCase(),i=0;for(;i<=n.length-s.length;){let e=n.indexOf(s,i);if(e===-1)break;let a=document.createRange();a.setStart(r,e),a.setEnd(r,e+s.length),c.push(a),t&&l.push(a),i=e+s.length}}r=n.nextNode()}}return c.length>0?n.set(`chat-search`,new i(...c)):n.delete(`chat-search`),l.length>0?n.set(`chat-search-active`,new i(...l)):n.delete(`chat-search-active`),a},[r,m,u,t,f]),(0,q.useEffect)(()=>{let e=m[u];if(!e)return;s(e);let t=0,n=requestAnimationFrame(function e(){p(e=>e+1),++t<3&&(n=requestAnimationFrame(e))});return()=>cancelAnimationFrame(n)},[m,u,s]),!t)return null;let h=e=>{m.length!==0&&d(t=>(t+e+m.length)%m.length)};return(0,Y.jsx)(`div`,{className:`absolute top-2 right-4 z-30 w-[28rem] max-w-[calc(100%-2rem)] rounded-lg border bg-popover shadow-xl`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,Y.jsx)(xe,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,Y.jsx)(`input`,{ref:l,value:r,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),n(!1)):e.key===`Enter`?(e.preventDefault(),h(e.shiftKey?-1:1)):e.key===`ArrowDown`?(e.preventDefault(),h(1)):e.key===`ArrowUp`&&(e.preventDefault(),h(-1))},placeholder:e(`activity:search.placeholder`),className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums shrink-0`,children:m.length===0?r?`0`:``:`${u+1} / ${m.length}`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>h(-1),disabled:m.length===0,className:K(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:e(`activity:search.prevHit`),children:(0,Y.jsx)(Hn,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>h(1),disabled:m.length===0,className:K(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:e(`activity:search.nextHit`),children:(0,Y.jsx)(en,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>n(!1),className:`p-1 rounded hover:bg-muted text-muted-foreground`,title:e(`activity:search.close`),children:(0,Y.jsx)(ut,{className:`h-3.5 w-3.5`})})]})})}function ou(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m${Math.floor(e%6e4/1e3)}s`}var su=(0,q.memo)(function({tools:e,defaultOpen:t=!1,isContinuation:r=!1}){let{t:i}=z(),[a,o]=(0,q.useState)(t);if(e.length===1)return(0,Y.jsx)(tu,{message:n(e[0]),isFirst:!0,isContinuation:r});let s=e.filter(e=>e.toolResult===void 0).length,c=e.filter(e=>e.isError).length,l=e.reduce((e,t)=>e+(t.toolDurationMs??0),0),u=Array.from(new Set(e.map(e=>e.toolName).filter(Boolean))),d=u.slice(0,3).join(`, `),p=u.length>3?` +${u.length-3}`:``;return(0,Y.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[r?(0,Y.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,Y.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-secondary text-secondary-foreground ring-2 ring-offset-2 ring-offset-background ring-secondary/20`,children:(0,Y.jsx)(yn,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] flex-1 min-w-0`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:K(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1.5 -mx-2 transition-colors`,`border border-border/40 bg-muted/30`),children:[a?(0,Y.jsx)(Bt,{className:`h-3.5 w-3.5 text-muted-foreground`}):(0,Y.jsx)(vn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(yn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:i(`activity:toolGroup.toolCalls`,{count:e.length})}),s>0?(0,Y.jsx)(R,{className:`h-3 w-3 animate-spin text-amber-500`}):c>0?(0,Y.jsx)(f,{className:`h-3 w-3 text-destructive`}):(0,Y.jsx)(jn,{className:`h-3 w-3 text-green-500`}),l>0&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:ou(l)}),d&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 font-mono truncate`,children:[`· `,d,p]})]}),a&&(0,Y.jsx)(`div`,{className:`space-y-2 pl-3 border-l-2 border-border/40 ml-2 tool-details`,children:e.map(e=>(0,Y.jsx)(tu,{message:e,isFirst:!1},e.id))})]})]})}),cu=3,lu=[{id:`understand`,icon:xe,title:`Understand`,hint:`Explore and analyze the codebase`,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/20`,pool:[`Map out the structure of this codebase: what are the main modules or components, how do they depend on each other, and what are the key patterns used throughout?`,`Find and document the public API surface — all exported interfaces, functions, and types that other parts of the system depend on.`,`Trace the flow of data through the system for a typical operation. Where does input validation happen? Where are side effects triggered?`,`Give me a guided tour of this codebase as if I just joined the team — where should I start reading, and what are the handful of files I should understand first?`,`Explain the overall architecture and the main design decisions behind it. What trade-offs were made, and why?`,`Identify the core domain concepts and how they map to the code. What vocabulary do I need to understand this project?`,`Where does execution begin? Trace the entry point through startup, configuration loading, and into the main loop or request handler.`,`What external dependencies and integrations does this project rely on, and how does the code talk to each of them?`,`How is state managed and where does it live? Walk me through the lifecycle of the most important piece of data in the system.`,`Summarize what this project does, who it is for, and how the pieces fit together — in plain language, no jargon.`,`Which parts of this codebase are the most complex or the hardest to change safely, and what makes them that way?`,`Show me how a single request or command flows end to end, from the outer boundary down to where the real work happens.`]},{id:`create`,icon:ht,title:`Create`,hint:`Build new features and functionality`,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20`,pool:[`Add a new feature that covers the full stack: data model, business logic, and any UI or API layers. Follow existing patterns in this codebase.`,`Write comprehensive tests for a module with low coverage. Include happy paths, edge cases, and error scenarios.`,`Add observability to a critical path — structured logging, error tracking, or metrics that help diagnose issues in production.`,`Scaffold a new module following the existing conventions — same structure, naming, and patterns as the rest of the codebase.`,`Add input validation and clear error messages to a user-facing entry point that currently trusts its inputs.`,`Write documentation for a part of the code that lacks it — usage examples, edge cases, and the gotchas worth warning about.`,`Take a value that is currently hardcoded and turn it into a proper configuration option, wired through cleanly with a sensible default.`,`Build a small CLI or script that automates a repetitive task in this project.`,`Create an integration test that exercises a real end-to-end path instead of mocking everything away.`,`Add a health check or self-diagnostic that reports whether the system’s dependencies are reachable and configured correctly.`,`Introduce a feature-flag mechanism so new behavior can be rolled out gradually and switched off without a redeploy.`,`Add pagination, filtering, or sorting to a data-listing path that currently returns everything at once.`]},{id:`investigate`,icon:fn,title:`Investigate`,hint:`Debug issues and find root causes`,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/20`,pool:[`Something isn't working as expected — help me trace from the symptom to the root cause. Follow the code path and identify where behavior diverges from intent.`,`There's a difference between how this works locally versus in production or CI. Check for environment differences, configuration issues, or hidden assumptions.`,`Performance is degrading. Identify the bottlenecks — whether N+1 queries, blocking I/O, unnecessary allocations, or something else — and propose targeted fixes.`,`Help me reproduce an intermittent bug: what timing, ordering, or conditions could make it flaky, and how do I make it deterministic?`,`This code throws or misbehaves under some inputs. Find the exact conditions that trigger it and explain why they do.`,`Memory or resource usage keeps growing over time. Look for leaks — unclosed handles, unbounded caches, or retained references.`,`A recent change broke something. Help me narrow down what introduced the regression and why it slipped through.`,`Two parts of the system disagree about the same data. Find where they diverge and determine which one is actually wrong.`,`Add targeted logging or assertions to narrow down where this bug really happens, then help me interpret the output.`,`This test is failing or flaky. Figure out whether it's the test that's wrong or the code it's checking.`,`Walk a confusing edge case through the code and tell me whether the resulting behavior is a genuine bug or intended.`,`I suspect a race condition or ordering issue. Look for shared state that’s read or written without proper coordination.`]},{id:`improve`,icon:oe,title:`Improve`,hint:`Refactor and optimize existing code`,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20`,pool:[`Find duplicated or similar logic that could be consolidated into shared utilities. Extract the common parts and update the call sites.`,`Identify modules that have grown too large or handle too many responsibilities. Propose a cleaner separation that can be done incrementally.`,`Review error handling across the codebase: are errors consistent, well-contextualized, and properly propagated? Suggest improvements to the worst cases.`,`Reduce complexity in the most tangled function you can find — simplify the control flow without changing its behavior.`,`Improve the naming and readability of a confusing area so the next person understands it faster.`,`Find and remove dead code, unused exports, and obsolete branches that no longer serve a purpose.`,`Tighten up the types (or add types) in a loosely-typed area so more bugs are caught at compile time instead of at runtime.`,`Optimize a hot path for speed or memory — but measure before and after so the win is real, not assumed.`,`Replace a fragile pattern — magic numbers, stringly-typed values, deep nesting — with something safer and clearer.`,`Improve test quality: hunt down weak assertions, over-mocking, and tests that pass without really verifying anything.`,`Make an inconsistent API consistent — align naming, argument order, and return shapes across similar functions.`,`Harden the code against invalid states — make illegal states unrepresentable wherever the design allows it.`]}];function uu(e,t){let n=e.slice();for(let e=n.length-1;e>0;e--){let t=Math.floor(Math.random()*(e+1));[n[e],n[t]]=[n[t],n[e]]}return n.slice(0,Math.min(t,n.length))}function du(){let e={};for(let t of lu)e[t.id]=uu(t.pool,cu);return e}var fu=[{id:`help`,name:`/help`,hint:`list every slash command`},{id:`diag`,name:`/diag`,hint:`runtime diagnostics`},{id:`stats`,name:`/stats`,hint:`tokens · cache · cost · elapsed`},{id:`tools`,name:`/tools`,hint:`show registered tools`},{id:`memory`,name:`/memory`,hint:`show remembered notes`},{id:`compact`,name:`/compact`,hint:`shrink context`},{id:`clear`,name:`/clear`,hint:`wipe current context`},{id:`new`,name:`/new`,hint:`fresh session`}];function pu(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function mu(){let{t:e}=z(),{projectName:t,cwd:n}=W(We(e=>({projectName:e.projectName,cwd:e.cwd}))),{provider:r,model:i}=J(We(e=>({provider:e.provider,model:e.model}))),a=J(e=>e.wsConnected),o=J(e=>e.wsUrl),[s,c]=(0,q.useState)(void 0);(0,q.useEffect)(()=>{if(!a)return;let e=U(o),t=e.on(`providers.saved`,e=>{let t=e.payload;c(t.providers?.length??0)});return e.listSavedProviders(),()=>{t()}},[a,o]);let l=G(e=>e.promptHistory).slice(0,6),{listSessions:u,resumeSession:d}=ts(),f=di(e=>e.entries);(0,q.useEffect)(()=>{a&&f.length===0&&u(10)},[a]);let p=G(e=>e.sessionNicknames),m=f.filter(e=>!e.isCurrent).slice(0,4),[h,g]=(0,q.useState)(du),_=(0,q.useCallback)(()=>g(du()),[]);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-8 py-8 px-2 max-w-5xl mx-auto w-full`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-3`,children:[(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`w-14 h-14 rounded-2xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center shadow-lg shadow-primary/20`,children:(0,Y.jsx)(rt,{className:`h-7 w-7 text-primary-foreground`})}),(0,Y.jsx)(`div`,{className:`absolute -inset-3 bg-gradient-to-r from-transparent via-primary/10 to-transparent animate-pulse rounded-full -z-10`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:t?e(`setup:welcome.heroTitleInProject`,{name:t}):e(`setup:welcome.heroTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-2xl mx-auto leading-relaxed`,children:e(`setup:welcome.heroSubtitle`)}),r&&i&&(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground/70 mt-2 font-mono`,children:[r,` / `,i]}),n&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/50 mt-1 font-mono`,title:n,children:e(`setup:welcome.workingDirectory`,{cwd:n})})]})]}),a&&s===0&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>to(`settings`),className:K(`group rounded-xl border bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-transparent`,`border-amber-500/30 hover:border-amber-500/50 transition-colors`,`p-4 flex items-center gap-4 text-left`),children:[(0,Y.jsx)(`span`,{className:`flex items-center justify-center w-12 h-12 rounded-lg bg-amber-500/15 text-amber-600 dark:text-amber-400 shrink-0`,children:(0,Y.jsx)(Ve,{className:`h-6 w-6`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:e(`setup:welcome.noKeyTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:e(`setup:welcome.noKeyBody`)})]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400 font-medium shrink-0 group-hover:translate-x-0.5 transition-transform`,children:[e(`setup:welcome.openSettings`),` `,(0,Y.jsx)(A,{className:`h-3.5 w-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:e(`setup:welcome.startingPrompts`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:_,className:`group/shuffle flex items-center gap-1.5 rounded-lg border border-border/50 bg-background/60 px-2.5 py-1.5 text-xs text-muted-foreground hover:text-foreground hover:border-primary/40 hover:bg-accent/40 transition-colors`,title:e(`setup:welcome.shufflePromptsHint`),children:[(0,Y.jsx)(b,{className:`h-3.5 w-3.5 transition-transform group-hover/shuffle:rotate-180 duration-300`}),e(`setup:welcome.shufflePrompts`)]})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4 max-h-[calc(100dvh-16rem)] lg:max-h-none overflow-y-auto`,children:lu.map((t,n)=>{let r=t.icon;return(0,Y.jsxs)(`div`,{className:`rounded-xl border bg-card/40 backdrop-blur-sm p-4 flex flex-col gap-3 animate-message hover:border-primary/20 hover:shadow-sm transition-all`,style:{animationDelay:`${n*80}ms`},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:K(`flex items-center justify-center w-8 h-8 rounded-lg border`,t.tone),children:(0,Y.jsx)(r,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`setup:welcome.card.${t.id}.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`setup:welcome.card.${t.id}.hint`)})]})]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(h[t.id]??[]).map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>pu(e),className:`text-left text-xs leading-relaxed text-foreground/80 hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-muted/40 transition-colors line-clamp-3`,title:e,children:e},e))})]},t.id)})})]}),m.length>0&&(0,Y.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(Xt,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:e(`setup:welcome.pickBackUp`)})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:m.map(t=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>d(t.id),className:`text-left rounded-lg border border-border/40 bg-background/60 hover:border-primary/40 hover:bg-accent/30 px-3 py-2 transition-colors group/sess`,title:t.title,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium truncate text-foreground group-hover/sess:text-primary`,children:p[t.id]||t.title||e(`setup:welcome.empty`)}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[t.provider,`/`,t.model,t.tokenTotal>0&&(0,Y.jsxs)(`span`,{className:`ml-2`,children:[`· `,t.tokenTotal.toLocaleString(),` tok`]})]})]},t.id))})]}),l.length>0&&(0,Y.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(kn,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:e(`setup:welcome.recentPrompts`)})]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:l.filter(e=>!e.startsWith(`/`)).slice(0,5).map((e,t)=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>pu(e),className:`text-left text-xs leading-relaxed text-muted-foreground hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-background/60 transition-colors line-clamp-2`,title:e,children:e},t))})]}),(0,Y.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(Ct,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:e(`setup:welcome.quickCommands`)})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2`,children:fu.map(t=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>pu(t.name),className:`text-left flex flex-col gap-0.5 rounded-md border border-border/40 bg-background/60 px-3 py-2 hover:border-primary/40 hover:bg-accent/40 transition-colors`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-xs text-foreground`,children:t.name}),(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground truncate`,children:e(`setup:welcome.slashRef.${t.id}`)})]},t.name))})]})]})}function hu(){let{t:e}=z(),t=i(e=>e.thinkingBuffer);if(!t)return null;let n=t.split(`
141
- `).slice(-6).join(`
142
- `).trim();return(0,Y.jsxs)(`div`,{className:`flex gap-3 animate-message thinking-bubble`,"aria-live":`polite`,children:[(0,Y.jsxs)(`div`,{className:`thinking-orb flex-shrink-0`,"aria-hidden":!0,children:[(0,Y.jsx)(`span`,{className:`thinking-orb__ring`}),(0,Y.jsx)(`span`,{className:`thinking-orb__ring thinking-orb__ring--delay`}),(0,Y.jsx)(`span`,{className:`thinking-orb__spark thinking-orb__spark--one`}),(0,Y.jsx)(`span`,{className:`thinking-orb__spark thinking-orb__spark--two`}),(0,Y.jsx)(Jn,{className:`thinking-orb__icon h-4 w-4`})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1 max-w-[85%] min-w-0`,children:[(0,Y.jsxs)(`span`,{className:`thinking-label text-xs font-medium text-primary px-1`,children:[(0,Y.jsx)(`span`,{children:e(`chat:thinking`)}),(0,Y.jsxs)(`span`,{className:`thinking-dots`,"aria-hidden":!0,children:[(0,Y.jsx)(`span`,{}),(0,Y.jsx)(`span`,{}),(0,Y.jsx)(`span`,{})]})]}),(0,Y.jsxs)(`div`,{className:`thinking-panel rounded-2xl rounded-bl-md px-3 py-2 border text-foreground/80`,children:[(0,Y.jsxs)(`div`,{className:`thinking-wave`,"aria-hidden":!0,children:[(0,Y.jsx)(`span`,{}),(0,Y.jsx)(`span`,{}),(0,Y.jsx)(`span`,{}),(0,Y.jsx)(`span`,{}),(0,Y.jsx)(`span`,{})]}),(0,Y.jsx)(`pre`,{className:`thinking-text whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden`,children:n||`…`})]})]})]})}var gu=(0,q.lazy)(()=>nr(()=>import(`./ProcessMonitor-CbfQYneY.js`).then(e=>({default:e.ProcessMonitor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),_u=(0,q.memo)(function({row:e,isLoading:t,compactMode:n,isFirstRow:r}){let i=K(`mx-auto max-w-5xl w-full px-4`,r&&`pt-4`,n?`pb-3`:`pb-6`);return e.kind===`day`?(0,Y.jsx)(`div`,{className:i,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 py-1 text-[11px] text-muted-foreground/70 uppercase tracking-wider font-medium`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-px bg-border/50`}),(0,Y.jsx)(`span`,{children:e.label}),(0,Y.jsx)(`div`,{className:`flex-1 h-px bg-border/50`})]})}):e.kind===`user`?(0,Y.jsx)(`div`,{className:i,children:(0,Y.jsx)(tu,{message:e.message,isFirst:!0})}):(0,Y.jsx)(`div`,{className:i,children:(0,Y.jsx)(`div`,{className:K(`chat-turn`,n?`space-y-1`:`space-y-1.5`),children:e.items.map(n=>{if(n.kind===`msg`)return(0,Y.jsx)(tu,{message:n.message,isFirst:n.isFirst,isContinuation:n.isContinuation},n.key);let r=e.isLastTurn&&n.isLastGroup&&t&&n.hasRunningTool;return(0,Y.jsx)(su,{tools:n.tools,defaultOpen:r,isContinuation:n.isContinuation},n.key)})})})});function vu(){let{t:e}=z(),t=i(e=>e.messages),n=i(e=>e.isLoading),r=G(e=>e.sidebarOpen),a=G(e=>e.toggleSidebar),o=G(e=>e.compactMode),{totalTokens:s,startTime:c,lastInputTokens:l,maxContext:u,iteration:d}=W(We(e=>({totalTokens:e.totalTokens,startTime:e.startTime,lastInputTokens:e.lastInputTokens,maxContext:e.maxContext,iteration:e.iteration}))),f=W(e=>e.session),p=f?.id,m=G(e=>p?e.sessionNicknames[p]:void 0),h=G(e=>e.setSessionNickname),g=f?.title,[_,v]=(0,q.useState)(!1),[y,b]=(0,q.useState)(``),x=di(e=>e.entries),[S,C]=(0,q.useState)(!1),w=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!S)return;let e=e=>{w.current?.contains(e.target)||C(!1)},t=e=>{e.key===`Escape`&&C(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[S]);let{provider:T,model:E}=J(We(e=>({provider:e.provider,model:e.model}))),D=(0,q.useRef)(null),O=(0,q.useMemo)(()=>ds(t),[t]),k=(0,q.useRef)(0);k.current=O.length+1;let A=(0,q.useMemo)(()=>{let e=new Map;return O.forEach((t,n)=>{if(t.kind===`user`)e.set(t.message.id,n);else if(t.kind===`agent`)for(let r of t.items)if(r.kind===`msg`)e.set(r.message.id,n);else for(let t of r.tools)e.set(t.id,n)}),e},[O]),j=G(e=>e.scrollTarget),M=$n(e=>e.autonomy),N=(0,q.useCallback)(e=>{$n.getState().set({autonomy:e}),U()?.send?.({type:`autonomy.switch`,payload:{mode:e}})},[]),[P,F]=(0,q.useState)(!1),[I,L]=(0,q.useState)(!1),[ee,te]=(0,q.useState)(!1);(0,q.useEffect)(()=>{let e=()=>te(!0);return document.addEventListener(`open:context-breakdown`,e),()=>document.removeEventListener(`open:context-breakdown`,e)},[]);let ne=u>0&&l>0?Math.min(100,Math.round(l/u*100)):0,[re,ie]=(0,q.useState)(!0),[ae,oe]=(0,q.useState)(0),[se,ce]=(0,q.useState)(!1),le=(0,q.useRef)(t.length),ue=(0,q.useCallback)(()=>{let e=D.current;if(!e)return;let t=e.scrollSize-e.scrollOffset-e.viewportSize<120;ie(t),t&&(oe(0),le.current=i.getState().messages.length),ce(e.scrollOffset>e.viewportSize&&e.scrollSize>e.viewportSize*2.5)},[]),de=(0,q.useCallback)(e=>{U()?.resumeSession?.(e),C(!1)},[]);(0,q.useEffect)(()=>{let e=D.current;if(e)if(re)e.scrollToIndex(k.current-1,{align:`end`}),le.current=t.length;else{let e=t.length-le.current;e>0&&oe(e)}},[t,re]),(0,q.useEffect)(()=>{ie(!0),oe(0),le.current=i.getState().messages.length,requestAnimationFrame(()=>{D.current?.scrollToIndex(k.current-1,{align:`end`})})},[p]),(0,q.useEffect)(()=>{if(!j)return;let e=A.get(j.id);e!==void 0&&D.current?.scrollToIndex(e,{align:`center`,smooth:!0})},[j,A]);let fe=(0,q.useCallback)(()=>{D.current?.scrollToIndex(k.current-1,{align:`end`,smooth:!0}),ie(!0),oe(0),le.current=i.getState().messages.length},[]),me=(0,q.useCallback)(()=>{D.current?.scrollToIndex(0,{align:`start`,smooth:!0})},[]),[he,ge]=(0,q.useState)(null),[_e,ve]=(0,q.useState)(()=>Date.now()),ye=(0,q.useRef)(null),xe=(0,q.useMemo)(()=>{let e=t[t.length-1],n=t.filter(e=>e.role===`tool`&&e.toolResult===void 0),r=`Thinking…`;if(n.length>0){let e=Array.from(new Set(n.map(e=>e.toolName).filter(Boolean))),t=e.slice(0,2).join(`, `),i=e.length>2?` +${e.length-2}`:``;r=n.length===1?`Running ${t||`tool`}…`:`Running ${n.length} tools (${t}${i})…`}else e?.role===`assistant`&&e.content?r=`Writing reply…`:e?.role===`tool`&&e.toolResult!==void 0&&(r=`Thinking about the next step…`);let i=he?Math.max(0,Math.floor((_e-he)/1e3)):0,a=i<60?`${i}s`:`${Math.floor(i/60)}m ${i%60}s`,o=``,s=e?.role===`assistant`&&e.streaming&&e.content?e:null;if(s){let e=ye.current;if(!e||e.id!==s.id)ye.current={id:s.id,at:Date.now(),len:s.content.length};else{let t=Math.max(1,_e-e.at),n=Math.max(0,s.content.length-e.len);if(t>500&&n>0){let e=n*1e3/t;o=e>=1e3?`${(e/1e3).toFixed(1)}k ch/s`:`${Math.round(e)} ch/s`}}}else ye.current&&=null;return{label:r,elapsed:a,speedLabel:o}},[t,_e,he]);(0,q.useEffect)(()=>{n&&he===null&&ge(Date.now()),!n&&he!==null&&ge(null)},[n,he]),(0,q.useEffect)(()=>{if(!n)return;let e=setInterval(()=>ve(Date.now()),500);return()=>clearInterval(e)},[n]);let Se=e=>{if(!e)return`--`;let t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},Ce=(()=>{if(!n)return`idle`;let e=t[t.length-1];return e?.role===`assistant`&&e.content&&e.streaming?`streaming`:`thinking`})(),we=Ce===`idle`?`bg-muted text-muted-foreground`:Ce===`streaming`?`bg-blue-500/10 text-blue-600 dark:text-blue-400`:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,Te=u>0&&l>0||s.input>0||!!c;return(0,Y.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col border-b bg-card/95 backdrop-blur-sm supports-[backdrop-filter]:bg-card/80 shrink-0 sticky top-0 z-20`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1 overflow-hidden`,children:[!r&&(0,Y.jsx)($,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:a,title:e(`chat:header.openSidebarTitle`),children:(0,Y.jsx)(Zn,{className:`h-4 w-4`})}),!r&&(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 mr-1`,children:(0,Y.jsx)(`div`,{className:`w-5 h-5 rounded bg-primary flex items-center justify-center`,children:(0,Y.jsx)(rt,{className:`h-3 w-3 text-primary-foreground`})})}),(0,Y.jsxs)(`span`,{className:K(`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 tabular-nums`,we),title:`Agent state: ${Ce}`,children:[Ce!==`idle`&&(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-current animate-pulse`}),(0,Y.jsx)(`span`,{children:Ce})]}),p&&(_?(0,Y.jsx)(`input`,{value:y,onChange:e=>b(e.target.value),onBlur:()=>{y.trim()&&h(p,y),v(!1)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),y.trim()&&h(p,y),v(!1)):e.key===`Escape`&&(e.preventDefault(),v(!1))},placeholder:e(`chat:sessionNamePlaceholder`),className:`h-5 px-1.5 text-[11px] bg-background border border-primary/40 rounded focus:outline-none focus:ring-1 focus:ring-ring shrink-0 w-32`,autoFocus:!0}):(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{b(m||g||``),v(!0)},className:`flex items-center gap-1 text-[11px] font-medium text-foreground/80 hover:text-foreground truncate max-w-[12rem] shrink-0 px-1 -mx-1 rounded hover:bg-muted/50 transition-colors`,title:e(`chat:header.renameTitle`),children:[(0,Y.jsx)(pe,{className:`h-2.5 w-2.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:m||g||e(`chat:header.untitled`)})]}))]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[x.length>1&&(0,Y.jsxs)(`div`,{ref:w,className:`relative shrink-0`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>C(e=>!e),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:e(`chat:switchSession`),children:[(0,Y.jsx)(Ge,{className:`h-3 w-3`}),(0,Y.jsx)(Bt,{className:`h-2.5 w-2.5`})]}),S&&(0,Y.jsx)(`div`,{className:`absolute left-0 top-full mt-1 z-40 w-64 rounded-md border bg-popover shadow-lg p-1 max-h-60 overflow-y-auto`,children:x.slice(0,15).map(t=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>de(t.id),className:K(`w-full text-left px-2 py-1.5 rounded text-xs hover:bg-accent transition-colors`,t.isCurrent&&`bg-primary/10`),children:[(0,Y.jsx)(`div`,{className:`font-medium truncate`,children:t.title||e(`chat:empty`)}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[t.provider,`/`,t.model,` · `,t.tokenTotal.toLocaleString(),` tok`]})]},t.id))})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>G.getState().setModelSwitcherOpen(!0),className:`group hidden sm:flex items-center gap-1 px-2 py-0.5 rounded-md border bg-background/50 hover:bg-accent hover:border-primary/40 transition-colors text-[11px] min-w-0 shrink-0`,title:e(`chat:header.changeModelTitle`),children:[(0,Y.jsx)(Tn,{className:`h-3 w-3 text-muted-foreground group-hover:text-foreground shrink-0`}),(0,Y.jsxs)(`span`,{className:`font-mono truncate max-w-[9rem] xl:max-w-[16rem]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:T||e(`chat:header.noProvider`)}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/40 mx-0.5`,children:`/`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:E||e(`chat:header.noModel`)})]})]}),(0,Y.jsxs)(`div`,{className:`hidden md:flex items-center gap-1.5 shrink-0`,children:[(0,Y.jsx)(nu,{}),(0,Y.jsx)(Sl,{})]}),d&&(0,Y.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium bg-primary/10 text-primary shrink-0 hover:bg-primary/20 transition-colors cursor-pointer`,title:e(`chat:header.iterationTitle`),onClick:()=>document.getElementById(`chat-activity`)?.scrollIntoView({behavior:`smooth`,block:`center`}),children:[(0,Y.jsx)(be,{className:`h-3 w-3 animate-pulse`}),`iter `,d.index,d.max>0?`/${d.max}`:``]}),(0,Y.jsx)(wc,{value:M,onChange:N,compact:!0})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,Y.jsxs)($,{variant:P?`secondary`:`ghost`,size:`icon`,className:K(`h-7 w-7 relative`,P&&`bg-amber-500/10 text-amber-600 dark:text-amber-400`),onClick:()=>F(e=>!e),title:e(`chat:header.runningProcessesTitle`),children:[(0,Y.jsx)(yn,{className:`h-4 w-4`}),P&&(0,Y.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-amber-500`})]}),(0,Y.jsxs)($,{variant:I?`secondary`:`ghost`,size:`icon`,className:K(`h-7 w-7 relative`,I&&`bg-violet-500/10 text-violet-600 dark:text-violet-400`),onClick:()=>L(e=>!e),title:e(`chat:header.checkpointsTitle`),children:[(0,Y.jsx)(Ge,{className:`h-4 w-4`}),I&&(0,Y.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-violet-500`})]})]})]}),Te&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-1 border-t bg-muted/20 text-[11px] text-muted-foreground`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 tabular-nums`,children:[l>0&&(0,Y.jsx)(_s,{pct:ne,tokens:l,maxTokens:u>0?u:void 0,onClick:()=>te(!0)}),s.input>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:cs(s.input)}),(0,Y.jsx)(`span`,{children:`in`})]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:cs(s.output)}),(0,Y.jsx)(`span`,{children:`out`})]}),s.cacheRead&&s.cacheRead>0&&(()=>{let e=(s.cacheRead??0)+s.input,t=e>0?Math.round((s.cacheRead??0)/e*100):0;return(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Cache hit ratio: ${t}%`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:cs(s.cacheRead)}),(0,Y.jsxs)(`span`,{children:[`cache (`,t,`%)`]})]})})(),(0,Y.jsx)(wl,{})]})]}),c&&(0,Y.jsx)(`span`,{className:`text-muted-foreground/70 tabular-nums shrink-0`,children:Se(c)})]})]}),(0,Y.jsxs)(`div`,{className:`relative min-h-0 min-w-0 flex-1 overflow-hidden`,children:[(0,Y.jsx)(au,{}),!re&&(0,Y.jsxs)(`button`,{type:`button`,onClick:fe,className:K(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 jump-bottom`,`flex items-center gap-2 px-4 py-2 rounded-full shadow-lg`,`bg-primary text-primary-foreground text-xs font-medium`,`hover:bg-primary/90 transition-colors animate-message`),children:[(0,Y.jsx)(en,{className:`h-3.5 w-3.5`}),ae>0?`${ae} new message${ae===1?``:`s`}`:`Jump to latest`]}),se&&(0,Y.jsxs)(`button`,{type:`button`,onClick:me,title:e(`chat:header.scrollTopTitle`),className:K(`absolute top-3 right-3 z-10`,`flex items-center gap-1 px-2.5 py-1 rounded-full shadow-md border`,`bg-background/90 backdrop-blur-sm text-[11px] text-muted-foreground`,`hover:text-foreground hover:bg-background transition-colors animate-message`),children:[(0,Y.jsx)(Hn,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:`Top`})]}),O.length===0&&!n?(0,Y.jsx)(`div`,{className:`h-full overflow-y-auto overscroll-contain`,children:(0,Y.jsx)(`div`,{className:`mx-auto max-w-5xl w-full px-4 pt-4 pb-8`,children:(0,Y.jsx)(mu,{})})}):(0,Y.jsxs)(Vn,{ref:D,className:`h-full`,onScroll:ue,children:[O.map((e,t)=>(0,Y.jsx)(_u,{row:e,isLoading:n,compactMode:o,isFirstRow:t===0},e.key)),(0,Y.jsxs)(`div`,{id:`chat-activity`,className:K(`mx-auto max-w-5xl w-full px-4`,o?`pb-3`:`pb-8`),children:[(0,Y.jsx)(hu,{}),n&&(0,Y.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,Y.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-accent text-accent-foreground ring-2 ring-offset-2 ring-offset-background ring-accent/20`,children:(0,Y.jsx)(wt,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,Y.jsx)(`div`,{className:`rounded-2xl px-4 py-3 bg-card border text-foreground`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,Y.jsxs)(`span`,{className:`flex gap-1`,children:[(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]`}),(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]`}),(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce`})]}),(0,Y.jsx)(`span`,{className:`text-foreground/90`,children:xe.label}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:xe.elapsed}),d&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[`· iter `,d.index,d.max>0?`/${d.max}`:``]}),xe.speedLabel&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 tabular-nums`,children:[`· `,xe.speedLabel]})]})})})]})]},`__live`)]})]}),(0,Y.jsxs)(`div`,{className:`border-t bg-card/50 backdrop-blur supports-[backdrop-filter]:bg-card/50 shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`ws-shortcut-hints max-w-5xl mx-auto px-4 pt-1.5 flex items-center gap-3 text-[10px] text-muted-foreground/50 select-none overflow-x-auto`,children:[(0,Y.jsxs)(`span`,{title:`Enter`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Enter`}),` send`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Shift+Enter`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Shift`}),`+`,(0,Y.jsx)(`kbd`,{children:`↵`}),` newline`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+\\\\`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+\\`}),` sidebar`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+F`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+F`}),` search`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+K`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+K`}),` palette`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+L / Ctrl+N`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+L`}),` clear`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{title:e(`chat:header.jkNavigateTitle`),className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`j`}),(0,Y.jsx)(`kbd`,{children:`k`}),` navigate`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+M`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+M`}),` model`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+Shift+D`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+⇧D`}),` density`]})]}),(0,Y.jsx)(`div`,{className:`ws-chat-input-wrap p-4`,children:(0,Y.jsx)(`div`,{className:`max-w-5xl mx-auto`,children:(0,Y.jsx)(bl,{onOpenBreakdown:()=>te(!0)})})})]}),(0,Y.jsx)(q.Suspense,{fallback:null,children:(0,Y.jsx)(gu,{open:P,onClose:()=>F(!1)})}),(0,Y.jsx)(xl,{open:I,onClose:()=>L(!1)}),(0,Y.jsx)(Cl,{open:ee,onClose:()=>te(!1)})]})}function yu(e){return/edit|write|create|patch/i.test(e)?Je:/bash|shell|exec|run|command/i.test(e)?yn:/fetch|http|web|curl|request/i.test(e)?De:Ne}function bu({toolName:e,input:t}){let{t:n}=z(),r=_c(e,t);if(r)return(0,Y.jsx)(`div`,{className:`rounded-lg overflow-hidden border`,children:(0,Y.jsx)(mc,{oldText:r.oldText,newText:r.newText,caption:r.caption})});if(typeof t==`object`&&t){let e=t,r=e.command??e.cmd??e.script;if(typeof r==`string`&&r.trim().length>0)return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b bg-muted/40 flex items-center gap-1.5`,children:[(0,Y.jsx)(yn,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:n(`confirm.command`)})]}),(0,Y.jsx)(`pre`,{className:`px-3 py-2 text-xs font-mono whitespace-pre-wrap break-all max-h-40 overflow-auto`,children:r})]});let i=e.url;if(typeof i==`string`)return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-background/40 px-3 py-2 text-xs font-mono`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:(e.method??`GET`).toUpperCase()}),` `,(0,Y.jsx)(`span`,{className:`break-all`,children:i})]})}return(0,Y.jsxs)(`div`,{className:`p-3 rounded-lg bg-muted/50 border text-xs font-mono`,children:[(0,Y.jsx)(`div`,{className:`text-muted-foreground mb-2`,children:n(`confirm.inputLabel`)}),(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-all max-h-60 overflow-auto`,children:JSON.stringify(t,null,2)})]})}function xu(){let{showConfirmDialog:e,confirmInfo:t,hideConfirm:n}=G(We(e=>({showConfirmDialog:e.showConfirmDialog,confirmInfo:e.confirmInfo,hideConfirm:e.hideConfirm}))),{t:r}=z(),i=$n(e=>e.yolo),a=$n(e=>e.set),{sendConfirm:o,updatePrefs:s}=ts(),c=(0,q.useRef)(null),l=(0,q.useRef)(!1);(0,q.useEffect)(()=>{e&&t&&(l.current=!1)},[e,t?.id,t]);let u=e=>{l.current||(l.current=!0,t&&o(t.id,e),n())},d=e=>{if(!e){if(t){u(`no`);return}n()}},f=()=>{a({yolo:!0}),s({yolo:!0})};if((0,q.useEffect)(()=>{!e||!t||!i||t.riskTier!==`destructive`&&t.decisionSource!==`yolo_destructive`&&u(`yes`)},[e,t?.id,t?.decisionSource,t?.riskTier,i]),(0,q.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target?.tagName?.toLowerCase();t===`input`||t===`textarea`||(e.key===`y`||e.key===`Y`?(e.preventDefault(),u(`yes`)):e.key===`n`||e.key===`N`||e.key===`Escape`?(e.preventDefault(),u(`no`)):e.key===`a`||e.key===`A`?(e.preventDefault(),u(`always`)):(e.key===`d`||e.key===`D`)&&(e.preventDefault(),u(`deny`)))};return window.addEventListener(`keydown`,t),c.current?.focus(),()=>window.removeEventListener(`keydown`,t)},[e,t?.id]),!t)return null;let p=yu(t.toolName),m=/edit|write/i.test(t.toolName),h=t.riskTier??`standard`;return(0,Y.jsx)(Hc,{open:e,onOpenChange:d,children:(0,Y.jsxs)(Gc,{className:`sm:max-w-2xl max-h-[min(88dvh,760px)] overflow-hidden !flex flex-col border-yellow-500/50`,ref:c,tabIndex:-1,children:[(0,Y.jsxs)(Kc,{className:`shrink-0`,children:[(0,Y.jsxs)(Jc,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(j,{className:`h-5 w-5 text-yellow-500 animate-pulse`}),r(`confirm.title`,{tool:t.toolName})]}),(0,Y.jsx)(Yc,{children:r(m?`confirm.descriptionEdit`:`confirm.descriptionTool`)})]}),(0,Y.jsxs)(`div`,{className:`py-2 pr-1 space-y-3 overflow-y-auto min-h-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-muted`,children:[(0,Y.jsx)(p,{className:`h-5 w-5 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`font-medium font-mono truncate`,children:t.toolName}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[r(m?`confirm.fileModification`:`confirm.toolExecution`),` —`,` `,r(`confirm.riskSuffix`,{risk:h})]})]})]}),t.input!==void 0&&(0,Y.jsx)(bu,{toolName:t.toolName,input:t.input}),t.suggestedPattern&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20`,children:[(0,Y.jsx)(je,{className:`h-4 w-4 text-yellow-600 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{className:`text-sm min-w-0`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-yellow-800 dark:text-yellow-200`,children:r(`confirm.trustSuggestionTitle`)}),(0,Y.jsx)(`div`,{className:`font-mono text-xs mt-1 break-all`,children:t.suggestedPattern}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:r(`confirm.trustSuggestionHint`)})]})]}),i&&(t.riskTier===`destructive`||t.decisionSource===`yolo_destructive`)&&(0,Y.jsx)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:r(`confirm.yoloDestructiveNote`)}),!i&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-primary/5 border border-primary/20`,children:[(0,Y.jsx)(rt,{className:`h-4 w-4 text-primary mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{className:`text-sm min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:r(`confirm.skipApprovalsTitle`)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:r(`confirm.skipApprovalsHint`)})]}),(0,Y.jsx)($,{variant:`outline`,size:`sm`,onClick:f,title:r(`confirm.enableYoloTitle`),className:`shrink-0`,children:r(`confirm.enableYoloBtn`)})]})]}),(0,Y.jsxs)(qc,{className:`gap-2 sm:gap-2 flex-wrap shrink-0`,children:[(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>u(`deny`),title:r(`confirm.denyAlwaysTitle`),children:[r(`confirm.denyAlways`),` `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`d`})]}),(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>u(`no`),title:r(`confirm.noTitle`),children:[r(`action.no`),` `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`n`})]}),(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>u(`always`),title:r(`confirm.alwaysTitle`),children:[r(`action.always`),` `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`a`})]}),(0,Y.jsxs)($,{size:`sm`,onClick:()=>u(`yes`),title:r(`confirm.yesTitle`),children:[r(`action.yes`),` `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`y`})]})]})]})})}var Su=q.forwardRef(({className:e,type:t,...n},r)=>(0,Y.jsx)(`input`,{type:t,className:K(`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));Su.displayName=`Input`;var Cu=Dn()((e,t)=>({request:null,open:n=>{t().request?.resolve(!1),e({request:n})},settle:n=>{t().request?.resolve(n),e({request:null})}}));function wu(e){return new Promise(t=>{Cu.getState().open({...e,resolve:t})})}function Tu(){let{t:e}=z(),t=Cu(e=>e.request),n=Cu(e=>e.settle);return(0,q.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Enter`&&(e.preventDefault(),Cu.getState().settle(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,Y.jsx)(Hc,{open:t!==null,onOpenChange:e=>{e||n(!1)},children:(0,Y.jsxs)(Gc,{className:`max-w-md`,children:[(0,Y.jsxs)(Kc,{children:[(0,Y.jsx)(Jc,{children:t?.title}),t?.message&&(0,Y.jsx)(Yc,{children:t.message})]}),(0,Y.jsxs)(qc,{className:`gap-2`,children:[(0,Y.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>n(!1),children:t?.cancelLabel??e(`common:action.cancel`)}),(0,Y.jsx)($,{variant:t?.danger?`destructive`:`default`,size:`sm`,autoFocus:!0,onClick:()=>n(!0),children:t?.confirmLabel??e(`common:action.confirm`)})]})]})})}var Eu=Dn()((e,t)=>({request:null,open:n=>{t().request?.resolve(null),e({request:n})},settle:n=>{t().request?.resolve(n),e({request:null})}}));function Du(e){return new Promise(t=>{Eu.getState().open({...e,resolve:t})})}function Ou(){let{t:e}=z(),t=Eu(e=>e.request),n=Eu(e=>e.settle),[r,i]=(0,q.useState)(``);(0,q.useEffect)(()=>{i(t?.defaultValue??``)},[t]);let a=()=>{let e=r.trim();n(e.length>0?e:null)};return(0,Y.jsx)(Hc,{open:t!==null,onOpenChange:e=>{e||n(null)},children:(0,Y.jsxs)(Gc,{className:`max-w-md`,children:[(0,Y.jsxs)(Kc,{children:[(0,Y.jsx)(Jc,{children:t?.title}),t?.message&&(0,Y.jsx)(Yc,{children:t.message})]}),(0,Y.jsx)(Su,{autoFocus:!0,value:r,placeholder:t?.placeholder,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),a())}}),(0,Y.jsxs)(qc,{className:`gap-2`,children:[(0,Y.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>n(null),children:t?.cancelLabel??e(`common:action.cancel`)}),(0,Y.jsx)($,{size:`sm`,disabled:r.trim().length===0,onClick:a,children:t?.confirmLabel??e(`common:action.ok`)})]})]})})}function ku(){let{t:e}=z(),t=J(e=>e.wsStatus),n=J(e=>e.wsUrl),[r,i]=(0,q.useState)(!1),[a,o]=(0,q.useState)(Date.now());if((0,q.useEffect)(()=>{if(t.state!==`reconnecting`)return;let e=setInterval(()=>o(Date.now()),500);return()=>clearInterval(e)},[t.state]),(0,q.useEffect)(()=>{t.state===`open`&&i(!1)},[t.state]),t.state===`open`||t.state===`connecting`||r)return null;let s=()=>U(n).retryNow(),c=t.state===`reconnecting`,l=t.state===`closed`?t.error:t.state===`reconnecting`?t.lastError:void 0,u=c?Math.max(0,Math.ceil((t.nextRetryAt-a)/1e3)):0;return(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-3 px-4 py-2 border-b text-sm`,c?`bg-orange-500/10 text-orange-700 dark:text-orange-300 border-orange-500/30`:`bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/30`),children:[c?(0,Y.jsx)(R,{className:`h-4 w-4 animate-spin shrink-0`}):(0,Y.jsx)(Pt,{className:`h-4 w-4 shrink-0`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:c?e(`activity:connection.reconnecting`,{attempt:t.attempt,remaining:u}):e(`activity:connection.disconnected`)}),l&&(0,Y.jsx)(`div`,{className:`text-xs opacity-80 truncate`,children:l})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:s,className:K(`inline-flex items-center gap-1 px-2.5 py-1 rounded-md border text-xs font-medium`,`hover:bg-background/30 transition-colors shrink-0`,c?`border-orange-500/40`:`border-red-500/40`),title:e(`activity:connection.retryTitle`),children:[(0,Y.jsx)(se,{className:`h-3 w-3`}),e(`activity:connection.retry`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>i(!0),className:`text-current/60 hover:text-current shrink-0`,title:e(`activity:connection.dismissTitle`),children:(0,Y.jsx)(ut,{className:`h-4 w-4`})})]})}var Au=class extends q.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary]`,e,t.componentStack),this.props.onError?.(e,t)}handleReset=()=>{this.setState({error:null})};render(){return this.state.error?(this.props.level??`app`)===`panel`?(0,Y.jsxs)(`div`,{role:`alert`,className:`flex min-h-[200px] flex-1 min-h-0 min-w-0 flex-col items-center justify-center gap-3 bg-background p-6 text-center`,children:[(0,Y.jsx)(je,{className:`h-8 w-8 text-destructive`}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-semibold`,children:this.props.name?B.t(`common:error.panelTitle`,{name:this.props.name,defaultValue:`${this.props.name} hit an error`}):B.t(`common:error.title`)}),(0,Y.jsx)(`pre`,{className:`max-w-md truncate text-xs font-mono text-muted-foreground`,children:this.state.error.message})]}),(0,Y.jsxs)($,{size:`sm`,variant:`outline`,onClick:this.handleReset,children:[(0,Y.jsx)(b,{className:`mr-1 h-3.5 w-3.5`}),B.t(`common:error.tryAgain`)]})]}):(0,Y.jsx)(`div`,{className:`flex min-h-[100dvh] items-center justify-center bg-background`,children:(0,Y.jsxs)(`div`,{className:`flex max-w-md flex-col items-center gap-4 p-8 text-center`,children:[(0,Y.jsx)(je,{className:`h-12 w-12 text-destructive`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:B.t(`common:error.title`)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:B.t(`common:error.body`)}),(0,Y.jsx)(`pre`,{className:`max-h-32 w-full overflow-auto rounded bg-muted/50 p-3 text-left text-xs font-mono text-muted-foreground`,children:this.state.error.message}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>window.location.reload(),children:[(0,Y.jsx)(b,{className:`mr-1 h-4 w-4`}),B.t(`common:error.reload`)]}),(0,Y.jsx)($,{size:`sm`,onClick:this.handleReset,children:B.t(`common:error.tryAgain`)})]})]})}):this.props.children}},ju=q.forwardRef(({className:e,children:t,...n},r)=>(0,Y.jsxs)(St,{ref:r,className:K(`relative overflow-hidden`,e),...n,children:[(0,Y.jsx)(x,{className:`h-full w-full rounded-[inherit]`,children:t}),(0,Y.jsx)(Mu,{}),(0,Y.jsx)(Kn,{})]}));ju.displayName=St.displayName;var Mu=q.forwardRef(({className:e,orientation:t=`vertical`,...n},r)=>(0,Y.jsx)(Wn,{ref:r,orientation:t,className:K(`flex touch-none select-none transition-colors`,t===`vertical`&&`h-full w-2.5 border-l border-l-transparent p-[1px]`,t===`horizontal`&&`h-2.5 flex-col border-t border-t-transparent p-[1px]`,e),...n,children:(0,Y.jsx)(Be,{className:`relative flex-1 rounded-full bg-border`})}));Mu.displayName=Wn.displayName;var Nu=mt,Pu=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(Rt,{ref:n,className:K(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,e),...t}));Pu.displayName=Rt.displayName;var Fu=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(Rn,{ref:n,className:K(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm`,e),...t}));Fu.displayName=Rn.displayName;var Iu=q.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(Ht,{ref:n,className:K(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));Iu.displayName=Ht.displayName;function Lu({current:e,max:t,className:n,showLabel:r=!0}){let i=Math.min(e,t),a=Math.max(0,t-i),o=t>0?i/t*100:0,s=o>=90?`text-destructive`:o>=70?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`;return(0,Y.jsxs)(`span`,{className:n,title:`Fleet concurrency: ${e}/${t}`,children:[(0,Y.jsxs)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] tracking-tight`,children:[`[`,(0,Y.jsx)(`span`,{className:s,children:`█`.repeat(i)}),(0,Y.jsx)(`span`,{className:`text-[hsl(var(--muted))]`,children:`░`.repeat(a)}),`]`]}),r&&(0,Y.jsxs)(`span`,{className:`ml-1.5 tabular-nums text-[10px] text-muted-foreground font-mono`,children:[e,`/`,t]})]})}function Ru(e){let t=Date.now()-e;return t<5e3?B.t(`common:time.justNow`):t<6e4?B.t(`common:time.compactSecondsAgo`,{count:Math.floor(t/1e3)}):t<36e5?B.t(`common:time.compactMinutesAgo`,{count:Math.floor(t/6e4)}):B.t(`common:time.compactHoursAgo`,{count:Math.floor(t/36e5)})}var zu={spawned:`🚀`,task_started:`▶`,tool_executed:`⚡`,iteration_summary:`🔄`,budget_warning:`!`,budget_extended:`⚡`,task_completed:`✅`,ctx_pct:`💬`,leader_updated:`👑`};function Bu({events:e,max:t=20,className:n}){let{t:r}=z(),i=e.slice(0,t);return i.length===0?(0,Y.jsx)(`div`,{className:`py-4 text-center text-xs text-muted-foreground ${n??``}`,children:r(`activity:timeline.noEvents`)}):(0,Y.jsx)(`div`,{className:`space-y-0.5 overflow-y-auto max-h-48 ${n??``}`,children:i.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 text-[10px] leading-tight py-0.5 px-1 rounded hover:bg-accent/50 transition-colors`,children:[(0,Y.jsx)(`span`,{className:`shrink-0 w-5 text-center`,"aria-hidden":`true`,children:zu[e.kind]??`·`}),(0,Y.jsx)(`span`,{className:`shrink-0 w-12 text-right text-muted-foreground font-mono tabular-nums`,children:Ru(e.timestamp)}),(0,Y.jsx)(`span`,{className:`truncate text-foreground/90`,children:e.message}),e.value!==void 0&&e.kind===`tool_executed`&&(0,Y.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:e.value>=1e3?`${(e.value/1e3).toFixed(1)}s`:`${e.value}ms`}),e.value!==void 0&&e.kind===`ctx_pct`&&(0,Y.jsxs)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:[e.value,`%`]})]},e.id))})}function Vu(e){return e===`running`}function Hu(e,t){let n=+!Vu(e.status),r=+!Vu(t.status);return n===r?e.startedAt-t.startedAt:n-r}function Uu(e){let t=0,n=0,r=0;for(let i of e)i.status===`running`?t++:i.status===`completed`?n++:(i.status===`failed`||i.status===`timeout`)&&r++;return{running:t,completed:n,failed:r,total:e.length}}function Wu(e){return e==null||!Number.isFinite(e)||e<0?`$0.0000`:e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function Gu(e){return e==null||!Number.isFinite(e)?`0`:e<1e3?String(Math.round(e)):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function Ku(e){if(e==null||!Number.isFinite(e)||e<0)return`—`;let t=Math.round(e/1e3);return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h`}var qu={running:{led:`bg-emerald-500`,labelKey:`statusRunning`,pulse:!0,color:`text-emerald-500`},completed:{led:`bg-emerald-500`,labelKey:`statusDone`,pulse:!1,color:`text-emerald-500`},failed:{led:`bg-destructive`,labelKey:`statusFailed`,pulse:!1,color:`text-destructive`},timeout:{led:`bg-amber-500`,labelKey:`statusTimeout`,pulse:!1,color:`text-amber-500`},stopped:{led:`bg-muted-foreground`,labelKey:`statusStopped`,pulse:!1,color:`text-muted-foreground`}};function Ju({agent:e,now:t}){let{t:n}=z(),[r,i]=(0,q.useState)(!1),[a,o]=(0,q.useState)(!1),s=X(t=>t.agentTranscripts.get(e.id)??Xr),c=qu[e.status],l=e.status===`running`,u=Math.min(100,Math.max(0,e.ctxPct)),p=(0,q.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),2e3)}catch{}},[]),m=e.toolLog.reduce((e,t)=>e+t.durationMs,0),h=e.toolLog.length>0?Math.round(m/e.toolLog.length):0,g=(0,q.useMemo)(()=>{let t=new Set;for(let n of e.toolLog)t.add(n.name);return t.size},[e.toolLog]),_=e.partialText||e.finalText||void 0,v=!e.finalText&&!!e.partialText;return(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Y.jsxs)(`div`,{className:`shrink-0 border-b bg-card p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,Y.jsx)(wt,{className:`h-5 w-5 text-primary`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),(0,Y.jsx)(`span`,{className:K(`px-2 py-0.5 rounded text-[10px] font-medium uppercase tracking-wider`,e.status===`running`?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:e.status===`failed`||e.status===`timeout`?`bg-destructive/15 text-destructive`:`bg-muted text-muted-foreground`),children:n(`activity:fleet.${c.labelKey}`)})]}),(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[n(`activity:fleet.sessionPrefix`),` `,e.sessionId?.slice(0,12),`…`]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[l&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Lt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`tabular-nums font-mono`,children:Ku(Math.max(0,t-e.startedAt))})]}),(0,Y.jsx)(`span`,{className:K(`led`,c.led,l&&`led-pulse`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/30`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:fleet.activity`)}),(0,Y.jsx)(Ts,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,Y.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-amber-500`,children:[(0,Y.jsx)(rt,{className:`h-3 w-3`}),n(`activity:fleet.budgetWarning`)]})]}),e.description&&(0,Y.jsxs)(`div`,{className:`px-3 py-2 rounded-lg bg-muted/20 border border-border/50`,children:[(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:n(`activity:fleet.currentTask`)}),(0,Y.jsx)(`p`,{className:`text-xs mt-1 text-foreground/80`,children:e.description})]})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,Y.jsx)(Tn,{className:`h-3 w-3`}),` `,n(`activity:fleet.providerModel`)]}),(0,Y.jsxs)(`div`,{className:`text-sm font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,Y.jsx)(be,{className:`h-3 w-3`}),` `,n(`activity:fleet.performance`)]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:fleet.iterations`)}),(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:e.iteration})]}),(0,Y.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:fleet.toolCalls`)}),(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:e.toolCalls})]}),(0,Y.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:fleet.uniqueTools`)}),(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:g})]})]})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,Y.jsx)(d,{className:`h-3 w-3`}),` `,n(`activity:fleet.cost`)]}),(0,Y.jsx)(`div`,{className:`text-lg font-mono font-bold text-emerald-500`,children:Wu(e.costUsd)}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:n(`activity:fleet.avgPerTool`,{ms:h})})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,Y.jsx)(Nt,{className:`h-3 w-3`}),` `,n(`activity:fleet.context`)]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:fleet.tokens`)}),(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:Gu(e.ctxTokens)})]}),(0,Y.jsx)(`div`,{className:`h-2 w-full rounded-full bg-muted overflow-hidden`,children:(0,Y.jsx)(`div`,{className:K(`h-full rounded-full transition-all`,u>=85?`bg-destructive`:u>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${u}%`}})}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:n(`activity:fleet.ctxUsed`,{pct:u})})]})]})]}),(0,Y.jsx)(xs,{entries:s,agentName:e.name,maxHeightClassName:`max-h-[28rem]`}),e.currentTool&&(0,Y.jsxs)(`div`,{className:K(`rounded-lg border px-4 py-3 flex items-center gap-3`,l?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,Y.jsx)(Ne,{className:K(`h-4 w-4`,l?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,Y.jsx)(`span`,{className:`text-sm font-mono font-medium`,children:e.currentTool}),l?(0,Y.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 text-[10px] text-primary`,children:[(0,Y.jsx)(R,{className:`h-3 w-3 animate-spin`}),` `,n(`activity:fleet.running`)]}):(0,Y.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:n(`activity:fleet.completed`)})]}),_?(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:v?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500 animate-pulse`}),n(`activity:fleet.liveOutput`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(he,{className:`h-3 w-3`}),n(`activity:fleet.finalOutput`)]})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>p(_),className:`flex items-center gap-1 px-2 py-1 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:r?`✓ ${n(`common:action.copied`)}`:n(`common:action.copy`)})]}),(0,Y.jsx)(`pre`,{className:`p-4 text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:_})]}):l?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,children:[(0,Y.jsx)(R,{className:`h-6 w-6 mx-auto mb-2 text-muted-foreground/50 animate-spin`}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`activity:fleet.waitingOutput`)})]}):null,e.budgetWarning&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,Y.jsx)(rt,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium text-amber-600 dark:text-amber-400`,children:n(`activity:fleet.budgetWarningTitle`)}),(0,Y.jsx)(`p`,{className:`text-[11px] text-amber-600/80 dark:text-amber-400/80 mt-0.5`,children:n(`activity:fleet.hittingLimit`,{kind:e.budgetWarning.kind,used:e.budgetWarning.used,limit:e.budgetWarning.limit})})]})]}),e.extensions>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,Y.jsx)(rt,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:n(`activity:fleet.budgetExt`,{count:e.extensions})}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:n(`activity:fleet.extendedTimes`,{count:e.extensions})})]})]}),e.error&&(0,Y.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Y.jsx)(f,{className:`h-4 w-4 text-destructive`}),(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:n(`activity:fleet.errorLabel`)})]}),(0,Y.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.error.message})]}),e.failureReason&&(0,Y.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Y.jsx)(f,{className:`h-4 w-4 text-destructive`}),(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:n(`activity:fleet.failureReason`)})]}),(0,Y.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.failureReason})]}),e.toolLog.length>0&&(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>o(!a),className:`w-full flex items-center justify-between px-4 py-2 border-b bg-muted/30 hover:bg-muted/50 transition-colors`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,Y.jsx)(Ne,{className:`h-3 w-3`}),n(`activity:fleet.toolLog`,{count:e.toolLog.length})]}),(0,Y.jsx)(vn,{className:K(`h-4 w-4 text-muted-foreground transition-transform`,a&&`rotate-90`)})]}),(0,Y.jsx)(`div`,{className:K(`overflow-hidden transition-all`,a?`max-h-[500px]`:`max-h-48`),children:(0,Y.jsx)(`div`,{className:`p-2 space-y-0.5`,children:e.toolLog.map((e,t)=>(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-3 rounded px-3 py-2 text-[11px]`,e.ok?`bg-muted/30 hover:bg-muted/50`:`bg-destructive/5 border border-destructive/20`),children:[(0,Y.jsx)(`span`,{className:K(`led shrink-0`,e.ok?`bg-emerald-500`:`bg-destructive`)}),(0,Y.jsx)(`span`,{className:K(`font-mono font-medium w-20 shrink-0`,e.ok?`text-foreground`:`text-destructive`),children:e.name}),(0,Y.jsx)(`span`,{className:`text-muted-foreground tabular-nums text-[10px]`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(2)}s`:`${e.durationMs}ms`}),!e.ok&&(0,Y.jsx)(`span`,{className:`ml-auto text-[10px] text-destructive font-medium`,children:n(`activity:fleet.failed`)}),(0,Y.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground tabular-nums`,children:new Date(e.at).toLocaleTimeString()})]},`${e.name}-${e.at}-${t}`))})})]})]})]})}function Yu({agent:e,isSelected:t,isLeader:n,onClick:r}){let{t:i}=z(),a=qu[e.status],o=e.status===`running`,s=Math.min(100,Math.max(0,e.ctxPct));return(0,Y.jsxs)(`button`,{type:`button`,onClick:r,className:K(`min-w-[650px] w-full text-left grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] items-center gap-x-2 px-3 py-1.5 rounded-md text-xs transition-colors`,t?`bg-primary/15 ring-1 ring-primary/40`:`hover:bg-accent/50`,o&&!t&&`bg-muted/30`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:K(`led shrink-0`,a.led,a.pulse&&`led-pulse`)}),(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),n&&(0,Y.jsx)(Nn,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":i(`activity:fleet.leader`)})]}),(0,Y.jsx)(`span`,{className:K(`text-[10px] tabular-nums`,o?`text-emerald-500`:`text-muted-foreground`),children:i(`activity:fleet.${a.labelKey}`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,Y.jsx)(Ts,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,Y.jsx)(`span`,{title:i(`activity:fleet.hittingLimitTitle`,{kind:e.budgetWarning.kind,used:e.budgetWarning.used,limit:e.budgetWarning.limit}),children:(0,Y.jsx)(rt,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":i(`common:status.budgetWarning`)})})]}),(0,Y.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.iteration,`it`]}),(0,Y.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.toolCalls,`tc`]}),(0,Y.jsx)(`span`,{className:`tabular-nums font-mono text-[10px]`,children:Wu(e.costUsd)}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`h-1.5 w-full rounded-full bg-muted overflow-hidden`,children:(0,Y.jsx)(`div`,{className:K(`h-full rounded-full transition-all`,s>=85?`bg-destructive`:s>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${s}%`}})}),(0,Y.jsx)(`span`,{className:`text-[9px] tabular-nums text-muted-foreground font-mono leading-none`,children:e.maxContext>0?`${s}%`:`—`})]}),(0,Y.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:e.extensions>0?`⚡×${e.extensions}`:`—`}),(0,Y.jsx)(`span`,{className:`text-[9px] text-destructive truncate`,title:e.failureReason,children:e.failureReason??``})]})}function Xu({onClose:e,onSelectAgent:t}){let{t:n}=z(),r=X(e=>e.agents),i=X(e=>e.leaderId),a=X(e=>e.fleetTokensIn),o=X(e=>e.fleetTokensOut),s=X(e=>e.fleetConcurrency),c=X(e=>e.fleetConcurrencyMax),l=X(e=>e.eventTimeline),u=X(e=>e.agentTimeline),[d,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(Date.now());(0,q.useEffect)(()=>{let e=setInterval(()=>h(Date.now()),1e3);return()=>clearInterval(e)},[]);let g=(0,q.useMemo)(()=>{let e=Array.from(r.values());return e.sort((e,t)=>e.id===i?-1:t.id===i?1:Hu(e,t)),e},[r,i]),_=(0,q.useMemo)(()=>Array.from(r.values()).reduce((e,t)=>e+t.costUsd,0),[r]),v=Uu(g).running,y=d===null?null:g[d],b=(0,q.useCallback)(e=>p(t=>t===e?null:e),[]);return(0,Y.jsx)(Es,{open:!0,onOpenChange:t=>{t||e()},children:(0,Y.jsxs)(As,{side:`right`,className:`w-[720px] max-w-[95vw] sm:max-w-[95vw] flex flex-col p-0 gap-0`,onKeyDown:(0,q.useCallback)(n=>{if(n.key===`Escape`){d===null?e&&e():p(null);return}if(n.key===`ArrowDown`){n.preventDefault(),p(e=>Math.min((e??-1)+1,g.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),p(e=>Math.max((e??0)-1,0));return}n.key===`Enter`&&g[d??0]&&t?.(g[d??0])},[g,d,e,t]),tabIndex:-1,children:[(0,Y.jsx)(Ms,{className:`sr-only`,children:n(`activity:fleet.fleetMonitor`)}),(0,Y.jsx)(Ns,{className:`sr-only`,children:n(`activity:fleet.runningCount`,{count:v})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(wt,{className:`h-5 w-5 text-primary`}),(0,Y.jsxs)(`h2`,{className:`text-sm font-semibold flex items-center gap-2`,children:[n(`activity:fleet.fleetMonitor`),v>0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-emerald-500 font-normal`,children:[(0,Y.jsx)(`span`,{className:`led led-pulse bg-emerald-500`}),n(`activity:fleet.runningCount`,{count:v})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Y.jsx)(`span`,{children:n(`activity:fleet.totalAgents`,{count:g.length})}),(0,Y.jsx)(Lu,{current:s,max:c,showLabel:!0})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:[`↓`,Gu(a),` ↑`,Gu(o),` · `,Wu(_)]}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:i?`👑 ${r.get(i)?.name??i}`:n(`activity:fleet.noLeader`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,"aria-label":n(`activity:fleet.closeFleet`),children:(0,Y.jsx)(f,{className:`h-4 w-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 overflow-x-auto overflow-y-hidden`,children:[(0,Y.jsxs)(`div`,{className:K(`flex min-h-0 min-w-0 flex-col border-r transition-all duration-200`,y?`w-[500px] max-w-full shrink-0`:`w-full`),children:[(0,Y.jsx)(`div`,{className:`border-b bg-card/80 px-3 py-2 overflow-x-auto`,children:(0,Y.jsxs)(`div`,{className:`grid min-w-[650px] grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] gap-x-2 text-[9px] uppercase tracking-wider text-muted-foreground font-medium`,children:[(0,Y.jsx)(`span`,{children:n(`activity:fleet.colName`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.colStatus`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.colActivity`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.colIters`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.colTools`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.colCost`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.colCtx`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.colExt`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.colReason`)})]})}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-auto`,children:g.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,Y.jsx)(En,{className:`h-12 w-12 mb-3 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:n(`activity:fleet.noAgentsActive`)}),(0,Y.jsx)(`p`,{className:`text-xs mt-1`,children:n(`activity:fleet.agentsAppear`)})]}):(0,Y.jsx)(`div`,{className:`p-2 space-y-0.5`,children:g.map((e,t)=>(0,Y.jsx)(Yu,{agent:e,isSelected:t===d,isLeader:e.id===i,onClick:()=>b(t)},e.id))})}),(0,Y.jsxs)(`div`,{className:`border-t bg-card/80 shrink-0`,children:[(0,Y.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,Y.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium flex items-center gap-2`,children:[(0,Y.jsx)(kn,{className:`h-3 w-3`}),n(`activity:fleet.agentTimeline`)]})}),(0,Y.jsx)(`div`,{className:`px-4 py-2 max-h-32 overflow-y-auto`,children:(0,Y.jsx)(Bu,{events:l,max:10})}),(0,Y.jsx)(`div`,{className:`border-t border-dashed`}),(0,Y.jsx)(`div`,{className:`px-4 py-2 max-h-40 overflow-y-auto`,children:u.length===0?(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:n(`activity:fleet.noAgentEvents`)}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:u.slice(0,15).map(e=>{let t={text:`💬`,thinking:`🧠`,tool_use:`🔧`,tool_result:`✅`,error:`❌`,status:`💬`,system:`●`}[e.kind]??`●`,n=e.status===`running`||e.status===`spawned`?`text-emerald-500`:e.status===`failed`||e.status===`timeout`?`text-destructive`:`text-muted-foreground`;return(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] leading-tight`,children:[(0,Y.jsx)(`span`,{className:`shrink-0`,children:t}),(0,Y.jsx)(`span`,{className:`font-medium text-primary shrink-0`,children:e.agentName}),e.status&&(0,Y.jsx)(`span`,{className:`${n} shrink-0`,children:e.status}),e.toolName&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[`[`,e.toolName,`]`]}),(0,Y.jsx)(`span`,{className:`min-w-0 text-muted-foreground line-clamp-2 whitespace-pre-wrap break-words`,children:e.content})]},e.id)})})}),(0,Y.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,Y.jsx)(`span`,{children:n(`activity:fleet.navHint`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.selectDetailHint`)}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.escHint`)})]})]})]}),y&&(0,Y.jsx)(`div`,{className:`min-h-0 min-w-[360px] flex-1 overflow-hidden bg-card/50`,children:(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Y.jsxs)(`div`,{className:`shrink-0 px-4 py-2 border-b bg-card/80 flex items-center gap-2`,children:[(0,Y.jsx)(A,{className:`h-4 w-4 text-primary`}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-primary`,children:y.name}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`activity:fleet.detailedView`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>p(null),className:`ml-auto text-[10px] text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1`,children:n(`activity:fleet.closeBtn`)})]}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,Y.jsx)(Ju,{agent:y,now:m})})]})}),!y&&g.length>0&&(0,Y.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 items-center justify-center bg-muted/20`,children:(0,Y.jsxs)(`div`,{className:`text-center space-y-3 max-w-sm`,children:[(0,Y.jsx)(En,{className:`h-12 w-12 text-muted-foreground/30 mx-auto`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`activity:fleet.selectAgentDetail`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:n(`activity:fleet.selectAgentBody`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-4 pt-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↑`}),(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↓`}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.navigateWord`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Enter`}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.selectWord`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Esc`}),(0,Y.jsx)(`span`,{children:n(`activity:fleet.deselectWord`)})]})]})]})})]})]})})}var Zu={shell:yn,package:ot,network:De,"fs.write":be,config:be},Qu={shell:`text-orange-400`,package:`text-blue-400`,network:`text-green-400`,"fs.write":`text-purple-400`,config:`text-yellow-400`},$u=[`all`,`shell`,`package`,`network`,`fs.write`,`config`];function ed(e){try{return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return e.slice(11,19)}}function td(e){if(e.input.command)return String(e.input.command).slice(0,80);if(e.input.url)return String(e.input.url).slice(0,80);if(e.input.packages){let t=e.input.packages;return Array.isArray(t)?t.join(`, `).slice(0,80):String(t).slice(0,80)}return JSON.stringify(e.input).slice(0,80)}function nd(e){return/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function rd(e){let t=[`timestamp,tool,risk,detail,outcome`,...e.map(e=>{let t=e.input.command??e.input.url??e.input.packages??JSON.stringify(e.input);return[nd(e.ts),nd(e.toolName),nd(e.risk),nd(String(t)),nd(e.outcome??``)].join(`,`)})].join(`
143
- `),n=new Blob([t],{type:`text/csv;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`side-effects-${new Date().toISOString().slice(0,19).replace(/[:.]/g,`-`)}.csv`,i.click(),URL.revokeObjectURL(r)}function id(){let e=Ai(e=>e.sideEffects),t=Ai(e=>e.loading),{t:n}=z(),[r,i]=(0,q.useState)(`all`),[a,o]=(0,q.useState)(`time`),[s,c]=(0,q.useState)(`desc`);(0,q.useEffect)(()=>{Ai.getState().setLoading(!0),nr(async()=>{let{getWSClient:e}=await import(`./ws-client-BAV7SLzK.js`).then(e=>e.n);return{getWSClient:e}},__vite__mapDeps([16,1,3,2,4,17])).then(({getWSClient:e})=>{e().send({type:`side_effects.list`})})},[]);let l=()=>{Ai.getState().setLoading(!0),nr(async()=>{let{getWSClient:e}=await import(`./ws-client-BAV7SLzK.js`).then(e=>e.n);return{getWSClient:e}},__vite__mapDeps([16,1,3,2,4,17])).then(({getWSClient:e})=>{e().send({type:`side_effects.list`})})},u=e=>{a===e?c(s===`asc`?`desc`:`asc`):(o(e),c(e===`time`?`desc`:`asc`))},d=(0,q.useMemo)(()=>{let t=r===`all`?[...e]:e.filter(e=>e.risk===r);return t.sort((e,t)=>{let n=0;return a===`time`?n=e.ts.localeCompare(t.ts):a===`tool`?n=e.toolName.localeCompare(t.toolName):a===`risk`&&(n=e.risk.localeCompare(t.risk)),s===`asc`?n:-n}),t},[e,r,a,s]);if(e.length===0&&!t)return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-zinc-500`,children:[(0,Y.jsx)(be,{className:`h-8 w-8 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:n(`activity:sideEffects.empty`)}),(0,Y.jsx)(`p`,{className:`text-xs text-zinc-600`,children:n(`activity:sideEffects.emptyHint`)})]});let f=({column:e})=>a===e?s===`asc`?(0,Y.jsx)(cn,{className:`inline h-3 w-3`}):(0,Y.jsx)(Bt,{className:`inline h-3 w-3`}):(0,Y.jsx)(`span`,{className:`opacity-30`,children:`↕`});return(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b border-zinc-800 px-3 py-2`,children:[(0,Y.jsxs)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-zinc-400`,children:[n(`activity:sideEffects.heading`),` (`,d.length,r===`all`?``:`/${e.length}`,`)`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsxs)(`button`,{onClick:()=>rd(d),disabled:d.length===0,className:`flex items-center gap-1 rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300 disabled:opacity-30 disabled:cursor-not-allowed`,title:n(`activity:sideEffects.exportTitle`),children:[(0,Y.jsx)(Pe,{className:`h-3 w-3`}),`CSV`]}),(0,Y.jsxs)(`button`,{onClick:l,className:`flex items-center gap-1 rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300`,children:[(0,Y.jsx)(b,{className:K(`h-3 w-3`,t&&`animate-spin`)}),n(`common:action.refresh`)]})]})]}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1 border-b border-zinc-800/50 px-2 py-1`,children:$u.map(e=>(0,Y.jsx)(`button`,{onClick:()=>i(e),className:K(`rounded px-2 py-0.5 text-[10px] font-medium uppercase transition-colors`,r===e?`bg-zinc-700 text-zinc-200`:`text-zinc-500 hover:bg-zinc-800 hover:text-zinc-400`),children:e===`all`?n(`activity:sideEffects.all`):e},e))}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`sticky top-0 bg-zinc-900 text-zinc-500`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsxs)(`th`,{className:`cursor-pointer select-none px-2 py-1 text-left font-medium hover:text-zinc-300`,onClick:()=>u(`time`),children:[n(`activity:sideEffects.colTime`),` `,(0,Y.jsx)(f,{column:`time`})]}),(0,Y.jsxs)(`th`,{className:`cursor-pointer select-none px-2 py-1 text-left font-medium hover:text-zinc-300`,onClick:()=>u(`tool`),children:[n(`activity:sideEffects.colTool`),` `,(0,Y.jsx)(f,{column:`tool`})]}),(0,Y.jsxs)(`th`,{className:`cursor-pointer select-none px-2 py-1 text-left font-medium hover:text-zinc-300`,onClick:()=>u(`risk`),children:[n(`activity:sideEffects.colRisk`),` `,(0,Y.jsx)(f,{column:`risk`})]}),(0,Y.jsx)(`th`,{className:`px-2 py-1 text-left font-medium`,children:n(`activity:sideEffects.colDetail`)}),(0,Y.jsx)(`th`,{className:`px-2 py-1 text-left font-medium`,children:n(`activity:sideEffects.colOutcome`)})]})}),(0,Y.jsx)(`tbody`,{children:d.map((e,t)=>{let n=Zu[e.risk]??be,r=Qu[e.risk]??`text-zinc-400`;return(0,Y.jsxs)(`tr`,{className:`border-b border-zinc-900 hover:bg-zinc-800/50`,children:[(0,Y.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 text-zinc-500`,children:ed(e.ts)}),(0,Y.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 font-medium text-zinc-300`,children:e.toolName}),(0,Y.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5`,children:(0,Y.jsxs)(`span`,{className:K(`flex items-center gap-1`,r),children:[(0,Y.jsx)(n,{className:`h-3 w-3`}),e.risk]})}),(0,Y.jsx)(`td`,{className:`max-w-xs truncate px-2 py-1.5 font-mono text-zinc-400`,children:td(e)}),(0,Y.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 text-zinc-500`,children:e.outcome??``})]},`${e.toolUseId}-${t}`)})})]})})]})}var ad=320;function od(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function sd(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function cd(e,t){let n=Array.from(e.values());return n.sort((e,n)=>{if(e.id===t)return-1;if(n.id===t)return 1;let r=e.status===`running`?0:1,i=n.status===`running`?0:1;return r===i?e.startedAt-n.startedAt:r-i}),n}function ld(){let e=G(e=>e.inspectorOpen),t=G(e=>e.inspectorTab),n=G(e=>e.toggleInspector),r=G(e=>e.setInspectorOpen),i=G(e=>e.setInspectorTab),{t:a}=z(),o=X(e=>e.agents),s=X(e=>e.leaderId),c=X(e=>e.fleetTokensIn),l=X(e=>e.fleetTokensOut),u=X(e=>e.fleetConcurrency),d=X(e=>e.fleetConcurrencyMax),f=X(e=>e.eventTimeline),p=(0,q.useMemo)(()=>cd(o,s),[o,s]),m=p.filter(e=>e.status===`running`).length,h=p.reduce((e,t)=>e+t.costUsd,0),g=p.length,[_,v]=(0,q.useState)(null),y=(0,q.useMemo)(()=>_?o.get(_)??p[0]??null:p[0]??null,[_,p,o]),b=()=>i(`fleet`),x=()=>i(`agents`),S=()=>i(`sideEffects`),C=Ai(e=>e.sideEffects.length);return(0,Y.jsxs)(`div`,{className:`shrink-0 border-t bg-card flex flex-col`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:n,className:K(`group w-full flex items-center justify-between gap-2 px-3 h-7 text-[11px]`,`text-muted-foreground hover:text-foreground hover:bg-accent/40 transition-colors`),title:a(e?`activity:inspector.hidePanel`:`activity:inspector.showPanel`),children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[e?(0,Y.jsx)(Bt,{className:`h-3.5 w-3.5 shrink-0`}):(0,Y.jsx)(cn,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`font-medium uppercase tracking-wider`,children:a(`activity:inspector.label`)}),g>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:K(`h-1.5 w-1.5 rounded-full`,m>0?`bg-emerald-500 animate-pulse`:`bg-muted-foreground/50`)}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[m,`/`,g]})]}),(0,Y.jsx)(`span`,{className:`opacity-40 hidden sm:inline`,children:`·`}),(0,Y.jsxs)(`span`,{className:`tabular-nums font-mono hidden sm:inline`,children:[`↓`,sd(c),` ↑`,sd(l),` · `,od(h)]})]}),C>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,Y.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),r(!0),i(`sideEffects`)},className:`flex items-center gap-1 text-yellow-500 hover:text-yellow-400 transition-colors`,title:a(`activity:inspector.openAudit`),children:[(0,Y.jsx)(be,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`tabular-nums`,children:C})]})]})]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0 opacity-70 group-hover:opacity-100`,children:[(0,Y.jsx)(wt,{className:`h-3 w-3`}),(0,Y.jsx)(En,{className:`h-3 w-3`}),(0,Y.jsx)(be,{className:`h-3 w-3`})]})]}),(0,Y.jsx)(`div`,{className:`overflow-hidden transition-[height] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]`,style:{height:e?ad:0},children:(0,Y.jsxs)(`div`,{className:`flex flex-col`,style:{height:ad},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 px-2 h-8 border-b bg-muted/30 shrink-0`,children:[(0,Y.jsx)(ud,{active:t===`fleet`,onClick:b,icon:(0,Y.jsx)(wt,{className:`h-3.5 w-3.5`}),label:a(`activity:inspector.tabFleet`),count:g,running:m}),(0,Y.jsx)(ud,{active:t===`agents`,onClick:x,icon:(0,Y.jsx)(En,{className:`h-3.5 w-3.5`}),label:a(`activity:inspector.tabAgents`),count:g}),(0,Y.jsx)(ud,{active:t===`sideEffects`,onClick:S,icon:(0,Y.jsx)(be,{className:`h-3.5 w-3.5`}),label:a(`activity:inspector.tabAudit`),count:C}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>r(!1),className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,"aria-label":a(`activity:inspector.collapseAria`),title:a(`activity:inspector.collapseTitle`),children:(0,Y.jsx)(Bt,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:t===`fleet`?(0,Y.jsx)(dd,{fleetList:p,leaderId:s,selectedAgentId:_,runningCount:m,fleetConcurrency:u,fleetConcurrencyMax:d,fleetTokensIn:c,fleetTokensOut:l,totalCost:h,eventTimeline:f,onSelectAgent:e=>{v(e.id),x()}}):t===`agents`?(0,Y.jsx)(fd,{fleetList:p,selectedAgent:y,leaderId:s,selectedAgentId:y?.id??null,onSelectAgent:v}):(0,Y.jsx)(id,{})})]})})]})}function ud({active:e,onClick:t,icon:n,label:r,count:i,running:a}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:t,className:K(`flex items-center gap-1.5 px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors`,e?`bg-background text-foreground shadow-sm ring-1 ring-border`:`text-muted-foreground hover:text-foreground hover:bg-background/60`),children:[n,r,i>0&&(0,Y.jsx)(`span`,{className:K(`tabular-nums text-[10px] px-1 rounded-full`,a&&a>0?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:`bg-muted text-muted-foreground`),children:a===void 0?i:`${a}/${i}`})]})}function dd({fleetList:e,leaderId:t,selectedAgentId:n,runningCount:r,fleetConcurrency:i,fleetConcurrencyMax:a,fleetTokensIn:o,fleetTokensOut:s,totalCost:c,eventTimeline:l,onSelectAgent:u}){let{t:d}=z();return(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1.5 border-b text-[11px] text-muted-foreground shrink-0`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[r>0&&(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse`}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[d(`activity:agents.runningCount`,{count:r}),` · `,d(`activity:agents.totalCount`,{count:e.length})]})]}),(0,Y.jsx)(Lu,{current:i,max:a,showLabel:!0}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(`span`,{className:`tabular-nums font-mono`,children:[`↓`,sd(o),` ↑`,sd(s),` · `,od(c)]})]}),e.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,Y.jsx)(En,{className:`h-8 w-8 mb-2 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-xs font-medium`,children:d(`activity:inspector.noAgentsActive`)}),(0,Y.jsx)(`p`,{className:`text-[11px] mt-0.5`,children:d(`activity:inspector.agentsAppearHint`)})]}):(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto p-1.5`,children:e.map(e=>(0,Y.jsx)(Yu,{agent:e,isSelected:n===e.id,isLeader:e.id===t,onClick:()=>u(e)},e.id))}),l.length>0&&(0,Y.jsx)(`div`,{className:`border-t px-3 py-1.5 shrink-0`,children:(0,Y.jsx)(Bu,{events:l,max:4})})]})}function fd({fleetList:e,selectedAgent:t,leaderId:n,selectedAgentId:r,onSelectAgent:i}){let{t:a}=z();if(e.length===0)return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,Y.jsx)(wt,{className:`h-8 w-8 mb-2 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-xs font-medium`,children:a(`activity:inspector.noAgentsActive`)})]});if(!t)return null;let o=Math.max(0,e.findIndex(e=>e.id===r));return(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto p-3`,children:(0,Y.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,Y.jsx)(Ls,{agent:t,isLeader:t.id===n})})}),(0,Y.jsx)(`div`,{className:`border-t px-2 py-1.5 shrink-0`,children:(0,Y.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto pb-0.5`,children:e.map((e,n)=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:K(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,e.id===t?.id?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),title:n===o?a(`activity:inspector.selected`,{name:e.name}):e.name,children:[(0,Y.jsx)(`span`,{className:K(`h-1.5 w-1.5 rounded-full shrink-0`,e.status===`running`?`bg-emerald-500 animate-pulse`:e.status===`failed`?`bg-destructive`:`bg-muted-foreground/50`)}),(0,Y.jsx)(`span`,{className:`truncate max-w-[8rem]`,children:e.name})]},e.id))})})]})}function pd(e,t,n,r,i){let a=[];for(let n of e){let e=t[n.id]??[];for(let t of e)a.push({provider:n.id,model:t.id,modelName:t.name||t.id,contextWindow:t.contextWindow,isCurrent:n.id===r&&t.id===i})}let o=n.toLowerCase().trim();return(o?a.filter(e=>e.provider.toLowerCase().includes(o)||e.model.toLowerCase().includes(o)||e.modelName.toLowerCase().includes(o)):a).sort((e,t)=>e.isCurrent===t.isCurrent?e.provider.localeCompare(t.provider)||e.model.localeCompare(t.model):e.isCurrent?-1:1)}function md(){let{t:e}=z(),t=G(e=>e.modelSwitcherOpen),n=G(e=>e.setModelSwitcherOpen),[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)(0),[s,c]=(0,q.useState)([]),[l,u]=(0,q.useState)({}),d=(0,q.useRef)(null),f=J(e=>e.wsUrl),p=J(e=>e.provider),m=J(e=>e.model),h=G(e=>e.paletteOpen),{listSavedProviders:g,listProviderModels:_,switchModel:v}=ts();(0,q.useEffect)(()=>{let e=e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`m`&&!e.shiftKey&&!e.altKey){if(h)return;e.preventDefault(),n(!t);return}e.key===`Escape`&&t&&(e.preventDefault(),n(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,h]),(0,q.useEffect)(()=>{let e=U(f),t=e.on(`providers.saved`,e=>{let t=e.payload;c(t.providers??[])}),n=e.on(`provider.models`,e=>{let t=e.payload;u(e=>({...e,[t.provider]:t.models}))});return()=>{t(),n()}},[f]),(0,q.useEffect)(()=>{t&&(i(``),o(0),g(),requestAnimationFrame(()=>d.current?.focus()))},[t,g]),(0,q.useEffect)(()=>{if(t)for(let e of s)l[e.id]||_(e.id)},[t,s,l,_]);let y=(0,q.useMemo)(()=>pd(s,l,r,p,m),[s,l,r,p,m]);(0,q.useEffect)(()=>{a>=y.length&&o(0)},[y.length,a]);let b=e=>{let t=y[e];t&&(v(t.provider,t.model),n(!1))};return(0,Y.jsx)(Hc,{open:t,onOpenChange:e=>{e||n(!1)},children:(0,Y.jsxs)(Gc,{className:`max-w-xl gap-0 p-0 overflow-hidden pt-[15dvh]`,showCloseButton:!1,onOpenAutoFocus:e=>{e.preventDefault(),d.current?.focus()},children:[(0,Y.jsx)(Jc,{className:`sr-only`,children:e(`activity:modelSwitcher.heading`)}),(0,Y.jsx)(Yc,{className:`sr-only`,children:e(`activity:modelSwitcher.filterPlaceholder`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Y.jsx)(xe,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`input`,{ref:d,value:r,onChange:e=>{i(e.target.value),o(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),o(e=>Math.min(y.length-1,e+1))):e.key===`ArrowUp`?(e.preventDefault(),o(e=>Math.max(0,e-1))):e.key===`Enter`&&(e.preventDefault(),b(a))},placeholder:e(`activity:modelSwitcher.filterPlaceholder`),"aria-label":e(`activity:modelSwitcher.filterPlaceholder`),className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:`↑↓ · Enter · Esc`})]}),(0,Y.jsx)(`div`,{className:`max-h-[50dvh] overflow-y-auto py-1`,children:y.length===0?(0,Y.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:s.length===0?e(`activity:modelSwitcher.noSavedProviders`):e(`activity:model.loading`)}):y.map((t,n)=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>b(n),onMouseEnter:()=>o(n),className:K(`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors`,n===a?`bg-accent text-accent-foreground`:`hover:bg-accent/40`,t.isCurrent&&`font-medium`),children:[(0,Y.jsx)(Tn,{className:K(`h-4 w-4 shrink-0`,t.isCurrent?`text-primary`:`text-muted-foreground`)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:t.provider}),(0,Y.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`·`}),(0,Y.jsx)(`span`,{children:t.modelName})]}),t.contextWindow&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono`,children:[t.model,` · ctx `,t.contextWindow.toLocaleString()]})]}),t.isCurrent?(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-primary font-semibold`,children:e(`activity:modelSwitcher.active`)}):(0,Y.jsx)(A,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100`})]},`${t.provider}:${t.model}`))})]})})}function hd(e){let t=J(e=>e.wsUrl),{listSavedProviders:n,listProviderModels:r}=ts(),[i,a]=(0,q.useState)([]),[o,s]=(0,q.useState)({});return(0,q.useEffect)(()=>{let e=U(t),n=e.on(`providers.saved`,e=>{let t=e.payload;a((t.providers??[]).map(e=>e.id))}),r=e.on(`provider.models`,e=>{let t=e.payload;s(e=>({...e,[t.provider]:t.models??[]}))});return()=>{n(),r()}},[t]),(0,q.useEffect)(()=>{e&&n()},[e,n]),(0,q.useEffect)(()=>{if(e)for(let e of i)o[e]||r(e)},[e,i,o,r]),(0,q.useMemo)(()=>{let e=[];for(let t of i)for(let n of o[t]??[])e.push({provider:t,model:n.id,label:n.name??n.id,description:n.description,contextWindow:n.contextWindow});return e},[i,o])}var gd=[{phase:`discovery`,label:`Discovery`,roles:[{role:`explore`,name:`Explore`},{role:`search`,name:`Search`},{role:`research`,name:`Research`}]},{phase:`planning`,label:`Planning`,roles:[{role:`analyst`,name:`Analyst`},{role:`planner`,name:`Planner`},{role:`architect`,name:`Architect`},{role:`critic`,name:`Critic`},{role:`refactor-planner`,name:`Refactor Planner`}]},{phase:`build`,label:`Build`,roles:[{role:`executor`,name:`Executor`},{role:`refactor`,name:`Refactor`},{role:`simplifier`,name:`Simplifier`},{role:`migration`,name:`Migration`},{role:`vision`,name:`Vision`},{role:`debugger`,name:`Debugger`},{role:`tracer`,name:`Tracer`}]},{phase:`verify`,label:`Verify`,roles:[{role:`verifier`,name:`Verifier`},{role:`test`,name:`Test`},{role:`e2e`,name:`E2E`},{role:`browser`,name:`Browser`},{role:`performance`,name:`Performance`},{role:`chaos`,name:`Chaos`},{role:`security-scanner`,name:`Security Scanner`},{role:`bug-hunter`,name:`Bug Hunter`},{role:`audit-log`,name:`Audit Log`}]},{phase:`review`,label:`Review`,roles:[{role:`reviewer`,name:`Reviewer`},{role:`code-reviewer`,name:`Code Reviewer`},{role:`security-reviewer`,name:`Security Reviewer`},{role:`accessibility`,name:`Accessibility`},{role:`compliance`,name:`Compliance`}]},{phase:`domain`,label:`Domain`,roles:[{role:`database`,name:`Database`},{role:`api`,name:`API`},{role:`auth`,name:`Auth`},{role:`data`,name:`Data`},{role:`frontend`,name:`Frontend`},{role:`backend`,name:`Backend`},{role:`designer`,name:`Designer`}]},{phase:`knowledge`,label:`Knowledge`,roles:[{role:`document`,name:`Document`},{role:`uml`,name:`UML`},{role:`i18n`,name:`I18n`},{role:`prompt`,name:`Prompt`}]},{phase:`delivery`,label:`Delivery`,roles:[{role:`git`,name:`Git`},{role:`release`,name:`Release`},{role:`devops`,name:`DevOps`},{role:`observability`,name:`Observability`},{role:`dependency`,name:`Dependency`}]},{phase:`meta`,label:`Meta`,roles:[{role:`skill-manage`,name:`Skill Manager`},{role:`self-improving`,name:`Self-Improving`},{role:`context`,name:`Context`},{role:`cost`,name:`Cost`},{role:`tech-stack`,name:`Tech Stack Validator`}]}],_d=gd.map(e=>e.phase),vd=gd.flatMap(e=>[...e.roles]),yd=vd.map(e=>e.role),bd=[`*`,..._d,...yd];function xd(e){if(e===`*`)return`Default (*)`;let t=gd.find(t=>t.phase===e);if(t)return`Phase: ${t.label} (${t.phase})`;let n=vd.find(t=>t.role===e);return n?`${n.name} (${n.role})`:`Custom: ${e}`}function Sd({value:e,provider:t,candidates:n,placeholder:r,resetLabel:i,onPick:a,onReset:o,className:s}){let{t:c}=z(),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(``),p=(0,q.useRef)(null);(0,q.useEffect)(()=>{if(!l)return;let e=e=>{p.current&&!p.current.contains(e.target)&&u(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[l]);let m=(0,q.useMemo)(()=>{let e=d.trim().toLowerCase();return(e?n.filter(t=>`${t.provider}/${t.model} ${t.label}`.toLowerCase().includes(e)):n).slice(0,60)},[n,d]);return(0,Y.jsxs)(`div`,{ref:p,className:K(`relative`,s),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>u(e=>!e),className:`flex w-full items-center gap-1.5 rounded-md border border-border bg-muted px-2 py-1.5 text-left text-xs hover:border-violet-500/50`,children:[(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5 shrink-0 text-violet-400`}),(0,Y.jsx)(`span`,{className:K(`min-w-0 flex-1 truncate`,e?`text-foreground`:`text-muted-foreground`),children:e?t?`${t}/${e}`:e:r??c(`activity:model.runDefault`)}),(0,Y.jsx)(Bt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),l&&(0,Y.jsxs)(`div`,{className:`sdd-rise absolute z-50 mt-1 max-h-72 w-full min-w-[240px] overflow-hidden rounded-md border border-border bg-popover shadow-xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-border px-2 py-1.5`,children:[(0,Y.jsx)(`input`,{autoFocus:!0,value:d,onChange:e=>f(e.target.value),placeholder:c(`activity:model.filterPlaceholder`),className:`min-w-0 flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground`}),d&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(``),className:`text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(ut,{className:`h-3 w-3`})})]}),(0,Y.jsxs)(`div`,{className:`max-h-60 overflow-y-auto py-1`,children:[o&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{o(),u(!1)},className:`flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted`,children:[(0,Y.jsx)(se,{className:`h-3 w-3`}),` `,i??c(`activity:model.useRunDefault`)]}),m.map(n=>{let r=n.model===e&&(!t||n.provider===t);return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{a(n.model,n.provider),u(!1)},className:K(`flex w-full items-start gap-1.5 px-2 py-1.5 text-left text-xs hover:bg-muted`,r?`text-violet-700 dark:text-violet-200`:`text-foreground`),children:[r?(0,Y.jsx)(gt,{className:`mt-0.5 h-3 w-3 shrink-0 text-violet-400`}):(0,Y.jsx)(`span`,{className:`w-3 shrink-0`}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block truncate`,children:n.label}),n.description&&(0,Y.jsx)(`span`,{className:`mt-0.5 block truncate text-[10px] text-muted-foreground`,children:n.description})]}),(0,Y.jsx)(`span`,{className:`mt-0.5 shrink-0 font-mono text-[9px] text-muted-foreground`,children:n.provider})]},`${n.provider}/${n.model}`)}),m.length===0&&(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-[11px] text-muted-foreground`,children:n.length===0?c(`activity:model.loading`):c(`activity:model.noMatch`)})]})]})]})}function Cd({value:e,candidates:t,onChange:n,placeholder:r,emptyHint:i}){let{t:a}=z(),[o,s]=(0,q.useState)(``),c=(t,r)=>{let i=t+r;if(i<0||i>=e.length)return;let a=[...e];[a[t],a[i]]=[a[i],a[t]],n(a)},l=t=>n(e.filter((e,n)=>n!==t)),u=(t,r)=>{let i=`${r}/${t}`;e.includes(i)||n([...e,i])},d=()=>{let t=o.trim().replace(/\s*\/\s*/g,`/`).replace(/\s+/g,` `);t&&(e.includes(t)||n([...e,t]),s(``))};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[e.length>0&&(0,Y.jsx)(`ol`,{className:`space-y-1`,children:e.map((t,n)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-muted px-2 py-1 text-xs`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:n+1}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-foreground`,children:t}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>c(n,-1),disabled:n===0,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,title:a(`activity:fallback.moveUp`),children:(0,Y.jsx)(Hn,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>c(n,1),disabled:n===e.length-1,className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,title:a(`activity:fallback.moveDown`),children:(0,Y.jsx)(en,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>l(n),className:`text-muted-foreground hover:text-red-400`,title:a(`common:action.remove`),children:(0,Y.jsx)(ut,{className:`h-3 w-3`})})]},`${t}-${n}`))}),(0,Y.jsx)(Sd,{candidates:t,placeholder:r??a(`activity:fallback.placeholder`),onPick:u}),(0,Y.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Y.jsx)(`input`,{value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&d()},placeholder:a(`activity:fallback.manualPlaceholder`),className:`min-w-0 flex-1 rounded-md border border-border bg-background px-2 py-1.5 font-mono text-xs outline-none placeholder:text-muted-foreground`}),(0,Y.jsx)(`button`,{type:`button`,onClick:d,className:`rounded-md border border-border px-2 py-1.5 text-xs hover:bg-muted`,title:a(`activity:fallback.addTitle`),children:(0,Y.jsx)(re,{className:`h-3.5 w-3.5`})})]}),e.length===0&&(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(re,{className:`h-2.5 w-2.5`}),` `,i??a(`activity:fallback.emptyHint`)]})]})}var wd=Xn(`inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground hover:bg-primary/80`,secondary:`border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80`,destructive:`border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80`,outline:`text-foreground`}},defaultVariants:{variant:`default`}});function Td({className:e,variant:t,...n}){return(0,Y.jsx)(`div`,{className:K(wd({variant:t}),e),...n})}var Ed=[{name:`filesystem`,description:`Read, write, and navigate the local filesystem. Good for exploring projects.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-filesystem`,`.`]},{name:`github`,description:`GitHub API — issues, PRs, repos, search, and file operations.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-github`],requiresEnvVars:[`GITHUB_PERSONAL_ACCESS_TOKEN`],badge:`Popular`},{name:`context7`,description:`Codebase-aware documentation and Q&A grounded in your actual library versions.`,transport:`streamable-http`,url:`https://mcp.context7.com/mcp`,badge:`New`},{name:`brave-search`,description:`Web search via Brave Browser. Free tier: 2,000 queries/month.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-brave-search`],requiresEnvVars:[`BRAVE_SEARCH_API_KEY`]},{name:`google-maps`,description:`Directions, geocoding, places, and distance matrix via Google Maps.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-google-maps`],requiresEnvVars:[`GOOGLE_MAPS_API_KEY`]},{name:`aws`,description:`AWS — EC2, S3, Lambda, IAM, CloudFormation, and cost management.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-aws`],requiresEnvVars:[`AWS_ACCESS_KEY_ID`,`AWS_SECRET_ACCESS_KEY`]},{name:`slack`,description:`Slack — messaging, channels, and search.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-slack`],requiresEnvVars:[`SLACK_BOT_TOKEN`]},{name:`everart`,description:`AI image generation via multiple providers.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-everart`],requiresEnvVars:[`EVERART_API_KEY`]},{name:`sentinel`,description:`Security vulnerability scanning via Sentinel.`,transport:`streamable-http`,url:`https://mcp.sentinel.ai`,badge:`Security`},{name:`playwright`,description:`Browser automation — navigate, click, type, screenshot, evaluate JS (headless Chromium).`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-playwright`],badge:`Browser`},{name:`zai-vision`,description:`Image analysis, screenshot understanding, and diagram interpretation.`,transport:`stdio`,command:`npx`,args:[`-y`,`@z_ai/mcp-server@latest`],env:{Z_AI_MODE:`ZAI`},requiresEnvVars:[`Z_AI_API_KEY`],allowedTools:[`image_analysis`,`extract_text_from_screenshot`,`diagnose_error_screenshot`,`understand_technical_diagram`,`analyze_data_visualization`,`ui_diff_check`],badge:`Vision`},{name:`minimax-vision`,description:`MiniMax image understanding via understand_image (read-only, safe for auto-run).`,transport:`stdio`,command:`uvx`,args:[`minimax-coding-plan-mcp`,`-y`],env:{MINIMAX_MCP_BASE_PATH:`./.wrongstack/minimax-output`,MINIMAX_API_HOST:`https://api.minimax.io`,MINIMAX_API_RESOURCE_MODE:`url`},requiresEnvVars:[`MINIMAX_API_KEY`],allowedTools:[`understand_image`],badge:`Vision`},{name:`block`,description:`Postgres database access via SQL (Block MCP server).`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-block`],requiresEnvVars:[`DATABASE_URL`]}];function Dd(e,t=!1){return{name:e.name,description:e.description,transport:e.transport,command:e.command,args:e.args,url:e.url,env:e.env,allowedTools:e.allowedTools,enabled:t}}function Od(e){switch(e){case`connected`:return{color:`bg-green-500`};case`connecting`:return{color:`bg-yellow-500`};case`sleeping`:return{color:`bg-blue-500`};case`discovering`:return{color:`bg-purple-500`};case`error`:return{color:`bg-red-500`};case`stopped`:return{color:`bg-gray-500`};default:return{color:`bg-gray-400`}}}function kd({status:e}){let{color:t}=Od(e);return(0,Y.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full ${t}`})}function Ad({server:e,onWake:t,onSleep:n,onDiscover:r,onEdit:i,onRemove:a}){let[o,s]=(0,q.useState)(!1),{color:c}=Od(e.status),{t:l}=z();return(0,Y.jsxs)(`div`,{className:`border rounded-lg p-3 bg-card`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`button`,{className:`flex items-center gap-2 flex-1 text-left`,onClick:()=>s(!o),children:[o?(0,Y.jsx)(Bt,{className:`w-4 h-4`}):(0,Y.jsx)(vn,{className:`w-4 h-4`}),(0,Y.jsx)(kd,{status:e.status}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.transport}),!e.enabled&&(0,Y.jsx)(Td,{variant:`outline`,className:`text-xs`,children:l(`settings:mcp.disabled`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[e.status===`sleeping`&&(0,Y.jsx)($,{variant:`ghost`,size:`sm`,onClick:t,title:l(`settings:mcp.wakeTitle`),children:(0,Y.jsx)(_t,{className:`w-4 h-4`})}),(e.status===`connected`||e.status===`connecting`)&&(0,Y.jsx)($,{variant:`ghost`,size:`sm`,onClick:n,title:l(`settings:mcp.sleepTitle`),children:(0,Y.jsx)(Mt,{className:`w-4 h-4`})}),(e.status===`stopped`||e.status===`sleeping`)&&(0,Y.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,title:l(`settings:mcp.discoverTitle`),children:(0,Y.jsx)(xe,{className:`w-4 h-4`})}),(0,Y.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,title:l(`settings:mcp.editTitle`),children:(0,Y.jsx)(Re,{className:`w-4 h-4`})}),(0,Y.jsx)($,{variant:`ghost`,size:`sm`,onClick:a,title:l(`settings:mcp.removeTitle`),className:`text-destructive hover:text-destructive`,children:(0,Y.jsx)(At,{className:`w-4 h-4`})})]})]}),o&&(0,Y.jsxs)(`div`,{className:`mt-3 pl-6 text-sm space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:l(`settings:mcp.statusLabel`)}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full ${c}`}),l(`settings:mcp.status.${e.status}`,{defaultValue:e.status})]}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:l(`settings:mcp.enabledLabel`)}),(0,Y.jsx)(`span`,{children:e.enabled?l(`settings:mcp.yes`):l(`settings:mcp.no`)}),e.description&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:l(`settings:mcp.descriptionLabel`)}),(0,Y.jsx)(`span`,{children:e.description})]}),e.pid&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:l(`settings:mcp.pidLabel`)}),(0,Y.jsx)(`span`,{children:e.pid})]}),e.error&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:l(`settings:mcp.errorLabel`)}),(0,Y.jsx)(`span`,{className:`text-destructive`,children:e.error})]})]}),e.tools&&e.tools.length>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:l(`settings:mcp.toolsLabel`,{count:e.tools.length})}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.tools.map(e=>(0,Y.jsx)(Td,{variant:`secondary`,className:`text-xs`,children:e},e))})]}),(!e.tools||e.tools.length===0)&&e.status===`connected`&&(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:l(`settings:mcp.noTools`)})]})]})}function jd({open:e,onOpenChange:t,server:n,onSave:r,prefillConfig:i}){let{t:a}=z(),[o,s]=(0,q.useState)(n?.name??i?.name??``),[c,l]=(0,q.useState)(n?.transport??i?.transport??`stdio`),[u,d]=(0,q.useState)(n?.description??i?.description??``),[f,p]=(0,q.useState)(i?.command??``),[m,h]=(0,q.useState)(i?.args?.join(` `)??``),[g,_]=(0,q.useState)(``),[v,y]=(0,q.useState)(i?.url??``),[b,x]=(0,q.useState)(n?.enabled??!0),[S,C]=(0,q.useState)(n?.lazy??i?.lazy??!1);(0,q.useEffect)(()=>{e&&(n?(s(n.name),l(n.transport),d(n.description??``),x(n.enabled),C(n.lazy??!1),p(``),h(``),_(``),y(``)):i?(s(i.name),l(i.transport),d(i.description??``),x(!0),C(i.lazy??!1),p(i.command??``),h(i.args?.join(` `)??``),_(i.env?Object.entries(i.env).map(([e,t])=>`${e}=${t}`).join(`
144
- `):``),y(i.url??``)):(s(``),l(`stdio`),d(``),x(!0),C(!1),p(``),h(``),_(``),y(``)))},[n,i,e]);let w=()=>{if(!o.trim()){Z.error(a(`settings:mcp.serverNameRequired`));return}let e={};if(g.trim())for(let t of g.trim().split(`
145
- `)){let n=t.indexOf(`=`);n>0&&(e[t.slice(0,n).trim()]=t.slice(n+1).trim())}r({name:o.trim(),transport:c,description:u.trim()||void 0,enabled:b,command:f.trim()||void 0,args:m.trim()?m.trim().split(/\s+/):void 0,env:Object.keys(e).length>0?e:void 0,url:v.trim()||void 0,lazy:S}),t(!1)},T=!!n,E=!!i;return(0,Y.jsx)(Hc,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Gc,{children:[(0,Y.jsx)(Kc,{children:(0,Y.jsx)(Jc,{children:a(T?`settings:mcp.dialogTitleEdit`:E?`settings:mcp.dialogTitleAdd`:`settings:mcp.dialogTitleAddCustom`)})}),(0,Y.jsxs)(`div`,{className:`space-y-4 py-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldName`)}),(0,Y.jsx)(Su,{value:o,onChange:e=>s(e.target.value),placeholder:a(`settings:mcp.fieldNamePlaceholder`),disabled:T||E})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldTransport`)}),(0,Y.jsxs)(`select`,{className:`w-full h-10 px-3 rounded-md border border-input bg-background text-sm`,value:c,onChange:e=>l(e.target.value),disabled:E,children:[(0,Y.jsx)(`option`,{value:`stdio`,children:`stdio`}),(0,Y.jsx)(`option`,{value:`sse`,children:`sse`}),(0,Y.jsx)(`option`,{value:`streamable-http`,children:`streamable-http`}),(0,Y.jsx)(`option`,{value:`http`,children:`http`})]})]}),(c===`streamable-http`||c===`sse`||c===`http`)&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldUrl`)}),(0,Y.jsx)(Su,{value:v,onChange:e=>y(e.target.value),placeholder:`https://mcp.example.com/mcp`,disabled:E})]}),c===`stdio`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldCommand`)}),(0,Y.jsx)(Su,{value:f,onChange:e=>p(e.target.value),placeholder:a(`settings:mcp.fieldCommandPlaceholder`),disabled:E})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`label`,{className:`text-sm font-medium`,children:[a(`settings:mcp.fieldArgs`),` `,(0,Y.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:a(`settings:mcp.fieldArgsHint`)})]}),(0,Y.jsx)(Su,{value:m,onChange:e=>h(e.target.value),placeholder:a(`settings:mcp.fieldArgsPlaceholder`),disabled:E})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`label`,{className:`text-sm font-medium`,children:[a(`settings:mcp.fieldEnv`),` `,(0,Y.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:a(`settings:mcp.fieldEnvHint`)})]}),(0,Y.jsx)(`textarea`,{className:`w-full h-20 px-3 py-2 rounded-md border border-input bg-background text-sm font-mono resize-none`,value:g,onChange:e=>_(e.target.value),placeholder:`GITHUB_TOKEN=ghp_...
146
- AWS_REGION=us-east-1`})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldDescription`)}),(0,Y.jsx)(Su,{value:u,onChange:e=>d(e.target.value),placeholder:a(`settings:mcp.fieldDescriptionPlaceholder`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,id:`server-enabled`,checked:b,onChange:e=>x(e.target.checked),className:`rounded`}),(0,Y.jsx)(`label`,{htmlFor:`server-enabled`,className:`text-sm`,children:a(`settings:mcp.enableServer`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,id:`server-lazy`,checked:S,onChange:e=>C(e.target.checked),className:`rounded`}),(0,Y.jsxs)(`label`,{htmlFor:`server-lazy`,className:`text-sm`,children:[a(`settings:mcp.lazyConnect`),` `,(0,Y.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:a(`settings:mcp.lazyConnectHint`)})]})]})]}),(0,Y.jsxs)(qc,{children:[(0,Y.jsx)($,{variant:`outline`,onClick:()=>t(!1),children:a(`common:action.cancel`)}),(0,Y.jsx)($,{onClick:w,children:a(T?`settings:mcp.saveChanges`:`settings:mcp.addServer`)})]})]})})}function Md({server:e,isAdded:t,onAdd:n}){let{t:r}=z();return(0,Y.jsxs)(`div`,{className:`border rounded-lg p-3 bg-card flex items-start justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),e.badge&&(0,Y.jsx)(Td,{variant:`secondary`,className:`text-xs shrink-0`,children:e.badge}),(0,Y.jsx)(Td,{variant:`outline`,className:`text-xs shrink-0`,children:e.transport})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description}),e.requiresEnvVars&&e.requiresEnvVars.length>0&&(0,Y.jsx)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400 mt-1`,children:r(`settings:mcp.requires`,{vars:e.requiresEnvVars.join(`, `)})})]}),(0,Y.jsx)(`div`,{className:`shrink-0`,children:t?(0,Y.jsxs)($,{variant:`ghost`,size:`sm`,disabled:!0,children:[(0,Y.jsx)(gt,{className:`w-4 h-4 mr-1`}),r(`settings:mcp.added`)]}):(0,Y.jsxs)($,{size:`sm`,variant:`outline`,onClick:n,children:[(0,Y.jsx)(re,{className:`w-4 h-4 mr-1`}),r(`common:action.add`)]})})]})}function Nd(){let e=ts(),{t}=z(),[n,r]=(0,q.useState)([]),[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(`list`),[c,l]=(0,q.useState)(),[u,d]=(0,q.useState)(!1),[f,p]=(0,q.useState)(!1),[m,h]=(0,q.useState)(),[_,v]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(!e.client)return;let t=e=>{if(e.type===`mcp.list`){let t=e.payload;r(t.servers??[]),a(!1)}},n=e=>{if(e.type===`mcp.server.added`){let t=e.payload;r(e=>[...e.filter(e=>e.name!==t.server.name),t.server]),Z.success(B.t(`settings:mcp.toastAdded`,{name:t.server.name}))}},i=e=>{if(e.type===`mcp.server.removed`){let t=e.payload;r(e=>e.filter(e=>e.name!==t.name)),Z.success(B.t(`settings:mcp.toastRemoved`,{name:t.name}))}},o=e=>{if(e.type===`mcp.server.updated`){let t=e.payload;r(e=>e.map(e=>e.name===t.server.name?t.server:e))}},s=e=>{if(e.type===`mcp.server.discovered`){let t=e.payload;r(e=>e.map(e=>e.name===t.name?{...e,status:`sleeping`,tools:t.tools}:e)),v(null),Z.success(B.t(`settings:mcp.toastDiscovered`,{count:t.tools.length,name:t.name}))}},c=e=>{if(e.type===`mcp.server.sleeping`){let t=e.payload;r(e=>e.map(e=>e.name===t.name?{...e,status:`sleeping`}:e)),v(null),Z.info(B.t(`settings:mcp.toastSleeping`,{name:t.name}))}},l=e=>{if(e.type===`mcp.server.waking`){let t=e.payload;r(e=>e.map(e=>e.name===t.name?{...e,status:`connecting`}:e))}},u=e=>{if(e.type===`mcp.server.connected`){let t=e.payload;r(e=>e.map(e=>e.name===t.name?{...e,status:`connected`,pid:t.pid,error:void 0,lastError:void 0}:e)),v(null),Z.success(B.t(`settings:mcp.toastConnected`,{name:t.name}))}},d=e=>{if(e.type===`mcp.server.reconnected`){let t=e.payload;r(e=>e.map(e=>e.name===t.name?{...e,status:`connected`,error:void 0,lastError:void 0}:e)),v(null),Z.success(B.t(`settings:mcp.toastReconnected`,{name:t.name}))}},f=e=>{if(e.type===`mcp.server.disconnected`){let t=e.payload;r(e=>e.map(e=>e.name===t.name?{...e,status:`error`,error:t.reason,lastError:t.reason,pid:void 0}:e)),v(null),Z.warn(B.t(`settings:mcp.toastDisconnected`,{name:t.name,reason:t.reason}))}},p=e=>{if(e.type===`mcp.server.error`){let t=e.payload;r(e=>e.map(e=>e.name===t.name?{...e,status:`error`,error:t.error}:e)),v(null),Z.error(B.t(`settings:mcp.toastError`,{name:t.name,error:t.error}))}},m=e=>{if(e.type===`mcp.operation_result`){let t=e.payload;t.success||Z.error(t.message),v(null)}},h=e.client.on(`mcp.list`,t),g=e.client.on(`mcp.server.added`,n),_=e.client.on(`mcp.server.removed`,i),y=e.client.on(`mcp.server.updated`,o),b=e.client.on(`mcp.server.discovered`,s),x=e.client.on(`mcp.server.sleeping`,c),S=e.client.on(`mcp.server.waking`,l),C=e.client.on(`mcp.server.connected`,u),w=e.client.on(`mcp.server.error`,p),T=e.client.on(`mcp.operation_result`,m),E=e.client.on(`mcp.server.reconnected`,d),D=e.client.on(`mcp.server.disconnected`,f);return a(!0),e.client?.listMcpServers(),()=>{h?.(),g?.(),_?.(),y?.(),b?.(),x?.(),S?.(),C?.(),w?.(),T?.(),E?.(),D?.()}},[e.client]);let y=(0,q.useCallback)(t=>{e.client?.addMcpServer(t)},[e]),b=(0,q.useCallback)(e=>{h(Dd(e,!1)),p(!0)},[]),x=(0,q.useCallback)(n=>{wu({title:t(`settings:mcp.removeConfirmTitle`,{name:n}),message:t(`settings:mcp.removeConfirmBody`),confirmLabel:t(`common:action.remove`),danger:!0}).then(t=>{t&&e.client?.removeMcpServer(n)})},[e]),S=(0,q.useCallback)(e=>{l(e),h(void 0),d(!0)},[]),C=(0,q.useCallback)(t=>{e.client?.updateMcpServer(t)},[e]),w=(0,q.useCallback)(t=>{v(t),e.client?.wakeMcpServer(t)},[e]),T=(0,q.useCallback)(t=>{v(t),e.client?.sleepMcpServer(t)},[e]),E=(0,q.useCallback)(t=>{v(t),e.client?.discoverMcpServer(t)},[e]),D=(0,q.useCallback)(()=>{a(!0),e.client?.listMcpServers()},[e]),O=n.filter(e=>e.status===`connected`).length,k=n.filter(e=>e.status===`sleeping`).length,A=new Set(n.map(e=>e.name));return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(g,{className:`w-5 h-5`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold`,children:t(`settings:mcp.heading`)}),n.length>0&&(0,Y.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:t(`settings:mcp.summary`,{connected:O,sleeping:k,total:n.length})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:D,disabled:i,children:[i?(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}):null,t(`common:action.refresh`)]}),(0,Y.jsxs)($,{size:`sm`,onClick:()=>{h(void 0),p(!0)},children:[(0,Y.jsx)(re,{className:`w-4 h-4 mr-1`}),t(`settings:mcp.addCustom`)]})]})]}),(0,Y.jsxs)(Nu,{value:o,onValueChange:e=>s(e),children:[(0,Y.jsxs)(Pu,{children:[(0,Y.jsxs)(Fu,{value:`recommended`,children:[(0,Y.jsx)(Yn,{className:`w-3.5 h-3.5 mr-1`}),t(`settings:mcp.tabRecommended`)]}),(0,Y.jsx)(Fu,{value:`list`,children:t(`settings:mcp.tabServers`)}),(0,Y.jsx)(Fu,{value:`add`,children:t(`settings:mcp.tabAddCustom`)})]}),(0,Y.jsxs)(Iu,{value:`recommended`,className:`space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(`settings:mcp.recommendedBody`)}),(0,Y.jsx)(`div`,{className:`grid gap-2`,children:Ed.map(e=>(0,Y.jsx)(Md,{server:e,isAdded:A.has(e.name),onAdd:()=>b(e)},e.name))})]}),(0,Y.jsx)(Iu,{value:`list`,className:`space-y-3`,children:i&&n.length===0?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground`,children:[(0,Y.jsx)(R,{className:`w-5 h-5 animate-spin mr-2`}),t(`settings:mcp.loadingServers`)]}):n.length===0?(0,Y.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Y.jsx)(g,{className:`w-10 h-10 mx-auto mb-2 opacity-50`}),(0,Y.jsx)(`p`,{children:t(`settings:mcp.noServers`)}),(0,Y.jsx)(`p`,{className:`text-sm`,children:t(`settings:mcp.noServersHint`)})]}):n.map(e=>(0,Y.jsx)(Ad,{server:e,onWake:()=>w(e.name),onSleep:()=>T(e.name),onDiscover:()=>E(e.name),onEdit:()=>S(e),onRemove:()=>x(e.name)},e.name))}),(0,Y.jsx)(Iu,{value:`add`,children:(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[(0,Y.jsx)(`p`,{children:t(`settings:mcp.addCustomBody`)}),(0,Y.jsx)(`p`,{className:`mt-1`,children:t(`settings:mcp.addCustomBodyHint`)})]})})]}),(0,Y.jsx)(jd,{open:f,onOpenChange:e=>{e||(p(!1),h(void 0))},prefillConfig:m,onSave:y}),(0,Y.jsx)(jd,{open:u,onOpenChange:d,server:c,onSave:C})]})}function Pd({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,setIsLoadingModels:i,onModelSelect:a,refreshModels:o}){let s=J(e=>e.model),{t:c}=z();return(0,Y.jsx)(`div`,{className:`space-y-4`,children:e?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:n?.name||e}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]}),(0,Y.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{i(!0),o(e)},children:(0,Y.jsx)(b,{className:K(`h-4 w-4`,r&&`animate-spin`)})})]}),r&&!t[e]?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,Y.jsx)(R,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:c(`settings:model.loading`)})]}):(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(t[e]||[]).map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:K(`w-full flex items-center justify-between p-3 rounded-lg border text-left transition-all`,s===e.id?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border hover:bg-muted`),children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.name||e.id}),(0,Y.jsx)(`div`,{className:`flex gap-2 mt-1`,children:e.capabilities.map(e=>(0,Y.jsx)(`span`,{className:`text-xs bg-muted px-1.5 py-0.5 rounded`,children:e},e))})]}),(0,Y.jsxs)(`div`,{className:`text-right text-xs text-muted-foreground`,children:[e.contextWindow&&(0,Y.jsx)(`div`,{children:c(`settings:model.context`,{count:e.contextWindow/1e3})}),e.inputCost&&e.outputCost&&(0,Y.jsxs)(`div`,{children:[`$`,e.inputCost,`/$`,e.outputCost]}),s===e.id&&(0,Y.jsx)(jn,{className:`h-4 w-4 text-primary mt-1`})]})]},e.id)),t[e]?.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:c(`settings:model.notFound`)})]})]}):(0,Y.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Y.jsx)(Tn,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,Y.jsx)(`p`,{children:c(`settings:model.selectProviderFirst`)})]})})}function Fd({label:e,hint:t,value:n,min:r,max:i,step:a=1,onChange:o,unit:s}){return(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Y.jsx)(`input`,{type:`range`,min:r,max:i,step:a,value:n,onChange:e=>o(Number(e.target.value)),className:`w-24 h-1.5 accent-primary`}),(0,Y.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-right text-muted-foreground`,children:[n,s??``]})]})]})}function Id({label:e,hint:t,value:n,options:r,onChange:i}){return(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,Y.jsx)(`select`,{value:n,onChange:e=>i(e.target.value),className:`shrink-0 h-8 rounded-md border bg-background px-2 text-xs`,children:r.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Ld({label:e,hint:t,selector:n,onChange:r,configKey:i,value:a}){let o=typeof a==`boolean`,s=G(e=>n?n(e):!1),c=J(e=>i?e[i]:!1),l=o?a:n?s:c;return(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,Y.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":l,onClick:()=>{if(o)r?.();else if(n)r?.();else if(i===`soundOnComplete`){let e=!J.getState().soundOnComplete;J.getState().setSoundOnComplete(e),e&&Hi()}},className:K(`shrink-0 relative inline-flex h-5 w-9 rounded-full border transition-colors`,l?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,Y.jsx)(`span`,{className:K(`absolute top-0.5 left-0.5 h-3.5 w-3.5 rounded-full bg-background shadow transition-transform`,l&&`translate-x-4`)})})]})}var Rd=`openai-compatible`,zd=[{id:`omniroute`,label:`OmniRoute`,defaultBaseUrl:`http://localhost:20128/v1`,noAuth:!0,hint:`WrongStack local gateway · port 20128 · no key · auto-discovers models`},{id:`ollama`,label:`Ollama`,defaultBaseUrl:`http://localhost:11434/v1`,noAuth:!0,hint:`ollama.com · port 11434 · no key`},{id:`vllm`,label:`vLLM`,defaultBaseUrl:`http://localhost:8000/v1`,noAuth:!1,hint:`docs.vllm.ai · port 8000 · optional key`},{id:`lmstudio`,label:`LM Studio`,defaultBaseUrl:`http://localhost:1234/v1`,noAuth:!1,hint:`lmstudio.ai · port 1234 · optional key`}],Bd=[{kind:`chatgpt`,label:`ChatGPT`,subtitle:`Plus / Pro / Team → openai-codex`,icon:(0,Y.jsx)(oe,{className:`h-5 w-5`})},{kind:`claude`,label:`Claude`,subtitle:`Pro / Max → anthropic-oauth`,icon:(0,Y.jsx)(wt,{className:`h-5 w-5`})},{kind:`copilot`,label:`GitHub Copilot`,subtitle:`Copilot → github-copilot`,icon:(0,Y.jsx)(Fe,{className:`h-5 w-5`})}],Vd=[`awaiting_browser`,`awaiting_code`,`exchanging`,`fetching_models`];function Hd({ws:e}){let{t}=z(),[n,r]=(0,q.useState)({chatgpt:{phase:`idle`},claude:{phase:`idle`},copilot:{phase:`idle`}}),[i,a]=(0,q.useState)(``),[o,s]=(0,q.useState)(null);(0,q.useEffect)(()=>{let t=e.on(`auth.oauth.status`,e=>{if(e.type!==`auth.oauth.status`)return;let t=e.payload;r(e=>({...e,[t.kind]:{...t}})),t.phase===`success`?(Z.success(t.message??B.t(`settings:oauth.signedInToast`,{provider:t.providerId??t.kind})),s(null),a(``)):t.phase===`error`&&Z.error(t.message??B.t(`settings:oauth.signInFailed`))});return()=>t?.()},[e]);let c=(0,q.useCallback)(t=>{r(e=>({...e,[t]:{phase:t===`copilot`?`awaiting_code`:`awaiting_browser`}})),e.startOAuth(t)},[e]),l=(0,q.useCallback)(t=>{e.cancelOAuth(t),r(e=>({...e,[t]:{phase:`idle`}})),s(null)},[e]),u=(0,q.useCallback)(t=>{let n=i.trim();n&&(e.submitOAuthCode(t,n),r(e=>({...e,[t]:{...e[t],phase:`exchanging`}})))},[i,e]);return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-3`,children:(0,Y.jsx)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,children:t(`settings:oauth.termsWarning`)})}),Bd.map(e=>{let r=n[e.kind],d=Vd.includes(r.phase);return(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e.icon}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.subtitle})]})]}),d?(0,Y.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>l(e.kind),children:t(`common:action.cancel`)}):(0,Y.jsx)($,{size:`sm`,onClick:()=>c(e.kind),children:t(`settings:oauth.signIn`)})]}),r.phase===`awaiting_browser`&&(0,Y.jsxs)(`div`,{className:`mt-3 space-y-2 border-t pt-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 animate-spin text-muted-foreground`}),(0,Y.jsx)(`span`,{children:t(`settings:oauth.waitingBrowser`)})]}),r.authorizeUrl&&(0,Y.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>window.open(r.authorizeUrl,`_blank`,`noopener,noreferrer`),children:[(0,Y.jsx)(it,{className:`h-3.5 w-3.5 mr-1`}),t(`settings:oauth.openSignIn`)]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`button`,{type:`button`,className:`text-xs text-muted-foreground underline`,onClick:()=>s(o===e.kind?null:e.kind),children:r.bound===!1?t(`settings:oauth.pasteLoopbackBusy`):t(`settings:oauth.pasteCantReach`)}),o===e.kind&&(0,Y.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Y.jsx)(Su,{placeholder:`http://localhost:.../callback?code=…`,value:i,onChange:e=>a(e.target.value),className:`font-mono text-xs`,onKeyDown:t=>{t.key===`Enter`&&u(e.kind)}}),(0,Y.jsx)($,{size:`sm`,onClick:()=>u(e.kind),disabled:!i.trim(),children:t(`settings:oauth.submit`)})]})]})]}),r.phase===`awaiting_code`&&(0,Y.jsxs)(`div`,{className:`mt-3 space-y-2 border-t pt-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(`settings:oauth.enterCode`)}),(0,Y.jsx)(`div`,{className:`font-mono text-2xl font-bold tracking-widest`,children:r.userCode??`…`}),r.verificationUri&&(0,Y.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>window.open(r.verificationUri,`_blank`,`noopener,noreferrer`),children:[(0,Y.jsx)(it,{className:`h-3.5 w-3.5 mr-1`}),t(`settings:oauth.openVerification`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Y.jsx)(R,{className:`h-3.5 w-3.5 animate-spin`}),(0,Y.jsx)(`span`,{children:t(`settings:oauth.waitingCode`)})]})]}),(r.phase===`exchanging`||r.phase===`fetching_models`)&&(0,Y.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t pt-3 text-sm`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 animate-spin text-muted-foreground`}),(0,Y.jsx)(`span`,{children:r.phase===`exchanging`?t(`settings:oauth.exchanging`):t(`settings:oauth.fetchingModels`)})]}),r.phase===`success`&&(0,Y.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t pt-3 text-sm text-green-600`,children:[(0,Y.jsx)(jn,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:r.message??t(`settings:oauth.signedIn`)})]}),r.phase===`error`&&r.message&&(0,Y.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t pt-3 text-sm text-destructive`,children:[(0,Y.jsx)(f,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:r.message})]})]},e.kind)})]})}function Ud({open:e,providerId:t,modelCount:n,onConfirm:r,onCancel:i}){let a=(0,q.useRef)(null),{t:o}=z();return(0,q.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Enter`?(e.preventDefault(),r()):e.key===`Escape`&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,t),a.current?.focus(),()=>window.removeEventListener(`keydown`,t)},[e,r,i]),(0,Y.jsx)(Hc,{open:e,onOpenChange:e=>{e||i()},children:(0,Y.jsxs)(Gc,{className:`sm:max-w-md border-amber-500/50`,ref:a,tabIndex:-1,"data-clear-allowlist-dialog":!0,children:[(0,Y.jsxs)(Kc,{children:[(0,Y.jsxs)(Jc,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(je,{className:`h-5 w-5 text-amber-500`}),o(`settings:allowlist.title`)]}),(0,Y.jsx)(Yc,{children:o(`settings:allowlist.body`,{count:n,provider:t})})]}),(0,Y.jsx)(`div`,{className:`rounded-md bg-muted/50 border border-border/60 px-3 py-2 text-xs text-muted-foreground`,children:o(`settings:allowlist.undoHint`)}),(0,Y.jsxs)(qc,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:i,title:o(`settings:allowlist.keepTitle`),"data-action":`cancel`,children:[o(`common:action.cancel`),` `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`Esc`})]}),(0,Y.jsxs)($,{variant:`destructive`,size:`sm`,onClick:r,title:o(`settings:allowlist.clearTitle`),"data-action":`confirm`,children:[o(`settings:allowlist.clear`),` `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`↵`})]})]})]})})}function Wd(){return{inFlight:!1,last:null,picked:null}}function Gd(e){return{providerId:e.providerId,ok:e.ok,status:e.status,...e.httpStatus===void 0?{}:{httpStatus:e.httpStatus},...e.elapsedMs===void 0?{}:{elapsedMs:e.elapsedMs},...e.modelCount===void 0?{}:{modelCount:e.modelCount},...e.modelIds===void 0?{}:{modelIds:e.modelIds},...e.detail===void 0?{}:{detail:e.detail}}}function Kd(e,t,n){return e.picked?e.picked:e.last?.ok&&e.last.modelIds&&e.last.modelIds.length>0&&e.last.modelIds[0]?e.last.modelIds[0]:t||(n&&n.length>0&&n[0]?n[0]:``)}function qd(e){if(e.inFlight)return{text:`Probing…`,tone:`muted`};let t=e.last;if(!t)return{text:`Click "Refresh from server" to re-probe /v1/models.`,tone:`muted`};let n=t.elapsedMs===void 0?``:` (${t.elapsedMs}ms)`;switch(t.status){case`ok`:{let e=t.modelCount??t.modelIds?.length??0;return{text:`ok — ${e} model${e===1?``:`s`}${n}`,tone:`success`}}case`unreachable`:return{text:`server unreachable${t.detail?` — ${t.detail}`:``}`,tone:`error`};case`timeout`:return{text:`timed out${t.detail?` — ${t.detail}`:``}`,tone:`error`};case`http_error`:return{text:`got${t.httpStatus===void 0?``:` HTTP ${t.httpStatus}`}${t.detail?` — ${t.detail}`:``}`,tone:`warning`};case`invalid_response`:return{text:t.detail?`unexpected response — ${t.detail}`:`unexpected response shape`,tone:`warning`};case`no_provider`:return{text:`no saved provider — the config may have been removed`,tone:`error`};case`no_base_url`:return{text:`no baseUrl configured`,tone:`warning`}}}function Jd(e,t){return e.last?.ok&&e.last.modelIds&&e.last.modelIds.length>0?e.last.modelIds:t??[]}function Yd(e,t){if(!e.last?.ok)return!1;let n=e.last.modelIds;if(!n||n.length===0)return!1;let r=t??[];if(r.length!==n.length)return!0;for(let e=0;e<n.length;e++)if(r[e]!==n[e])return!0;return!1}function Xd(e){return(e?.length??0)>0}function Zd(e,t){return`Allowlist cleared for ${e} — ${t} model${t===1?``:`s`} removed`}function Qd(e){return e.length>0}function $d(e){return e.previousModels.length===0?{kind:`skip`}:e.onUndoClear?{kind:`callback`,providerId:e.providerId,previousModels:e.previousModels}:{kind:`ws-default`,providerId:e.providerId,previousModels:e.previousModels}}var ef=3e3;function tf({providerId:e,savedPickedModelId:t,savedModels:n,ws:r,onPickModel:i,onClearModels:a,onUndoClear:o}){let[s,c]=(0,q.useState)(()=>Wd()),{t:l}=z(),[u,d]=(0,q.useState)(!1);(0,q.useEffect)(()=>r.on(`provider.probe`,t=>{t.type===`provider.probe`&&t.payload.providerId===e&&c(e=>({...e,inFlight:!1,last:Gd(t.payload)}))}),[r,e]);let f=(0,q.useCallback)(()=>{c(e=>({...e,inFlight:!0})),r.probeProvider(e,ef)},[r,e]),p=(0,q.useCallback)(t=>{c(e=>({...e,picked:t})),i?.(e,t)},[i,e]),m=(0,q.useCallback)(()=>{d(!0)},[]),h=(0,q.useCallback)(()=>{d(!1)},[]),g=(0,q.useCallback)(()=>{d(!1);let t=n?[...n]:[];c(e=>({...e,picked:null,last:null})),a?a(e):r.clearProviderModels(e),Qd(t)&&Z.undoable(Zd(e,t.length),()=>{let n=$d({providerId:e,previousModels:t,onUndoClear:o});switch(n.kind){case`skip`:return;case`callback`:o?.(n.providerId,n.previousModels);return;case`ws-default`:r.undoProviderClear(n.providerId,n.previousModels);return}})},[a,o,r,e,n]),_=(0,q.useMemo)(()=>Kd(s,t,n),[s,t,n]),v=(0,q.useMemo)(()=>Jd(s,n),[s,n]),y=(0,q.useMemo)(()=>qd(s),[s]),b=(0,q.useMemo)(()=>Yd(s,n),[s,n]),x=(0,q.useMemo)(()=>Xd(n),[n]);return(0,Y.jsxs)(`div`,{className:`rounded-md border border-border/60 bg-muted/30 px-3 py-2`,"data-provider-models-panel":e,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:l(`activity:providerModels.using`)}),_?(0,Y.jsx)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-primary/10 text-primary`,children:_}):(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:l(`activity:providerModels.noModelPicked`)})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[x&&(0,Y.jsx)($,{variant:`ghost`,size:`sm`,onClick:m,"aria-label":l(`activity:providerModels.clearAllowlistAria`,{provider:e}),"data-action":`clear-models`,children:l(`activity:providerModels.clearAllowlist`)}),(0,Y.jsx)($,{variant:`ghost`,size:`sm`,onClick:f,disabled:s.inFlight,"aria-label":l(`activity:providerModels.refreshAria`,{provider:e}),children:s.inFlight?l(`activity:providerModels.probing`):l(`activity:providerModels.refresh`)})]})]}),(0,Y.jsx)(nf,{formatted:y}),v.length>0&&(0,Y.jsx)(`ul`,{className:`mt-2 flex flex-wrap gap-1.5`,"data-provider-models-list":e,children:v.map(t=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:t===_?`text-xs font-mono px-2 py-0.5 rounded bg-primary/10 text-primary`:`text-xs font-mono px-2 py-0.5 rounded border border-border text-foreground/80`,children:t}),t!==_&&(0,Y.jsx)($,{variant:`link`,size:`sm`,onClick:()=>p(t),className:`text-xs h-5 px-1`,"aria-label":l(`activity:providerModels.useModelAria`,{model:t,provider:e}),children:l(`activity:providerModels.use`)})]},t))}),b&&(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:l(`activity:providerModels.differsHint`,{command:`wstack auth local --model first`})}),(0,Y.jsx)(Ud,{open:u,providerId:e,modelCount:n?.length??0,onConfirm:g,onCancel:h})]})}function nf({formatted:e}){return(0,Y.jsx)(`p`,{className:`mt-1 text-xs ${e.tone===`success`?`text-emerald-600 dark:text-emerald-400`:e.tone===`warning`?`text-amber-600 dark:text-amber-400`:e.tone===`error`?`text-rose-600 dark:text-rose-400`:`text-muted-foreground`}`,"data-probe-tone":e.tone,children:e.text})}var rf=[`anthropic`,`openai`,`google`,`openai-compatible`];function af({activeProvider:e,catalogProviders:t,isLoadingCatalog:n,savedProviders:r,isLoadingSaved:i,providerTab:a,setProviderTab:o,onSelectProvider:s,onAddKey:c,onDeleteKey:l,onSetActiveKey:u,onAddProvider:d,onRemoveProvider:p,onPickProviderModel:m,ws:h,catalogQuery:g,setCatalogQuery:_}){let{t:v}=z(),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(``),[C,w]=(0,q.useState)(``),[T,E]=(0,q.useState)(!1),[D,O]=(0,q.useState)(!1),[k,A]=(0,q.useState)(``),[j,M]=(0,q.useState)(`openai-compatible`),[N,P]=(0,q.useState)(``),[F,I]=(0,q.useState)(``),L=(0,q.useCallback)(e=>{!x.trim()||!C.trim()||(c(e,x.trim(),C.trim()),S(``),w(``),b(null))},[c,x,C]),ee=(0,q.useCallback)(()=>{k.trim()&&(d(k.trim(),j,N||void 0,F||void 0),A(``),M(`openai-compatible`),P(``),I(``),O(!1))},[d,k,j,N,F]),te=(0,q.useCallback)(e=>{A(e.id),M(Rd),P(e.defaultBaseUrl),e.noAuth&&I(``)},[]),[ne,ie]=(0,q.useState)(null),[ae,oe]=(0,q.useState)(``),[se,le]=(0,q.useState)(!1),[ue,de]=(0,q.useState)({}),fe=(0,q.useMemo)(()=>new Set(r.map(e=>e.id)),[r]);(0,q.useEffect)(()=>{let e=h.on(`provider.probe`,e=>{if(e.type!==`provider.probe`)return;let t=e.payload;t.status===`no_base_url`||t.status===`no_provider`||de(e=>({...e,[t.providerId]:{ok:t.ok,status:t.status,detail:t.detail}}))});return()=>e?.()},[h]);let pe=(0,q.useCallback)(e=>{let t=ae.trim();t&&(fe.has(e.id)?c(e.id,`default`,t):d(e.id,e.family,e.apiBase??void 0,t),oe(``),ie(null),le(!1),Z.success(v(`settings:provider.savedToast`,{name:e.name})),e.apiBase&&setTimeout(()=>h.probeProvider(e.id,6e3),700))},[ae,fe,c,d,h]),me=g.trim()?t.filter(e=>{let t=g.trim().toLowerCase();return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||e.family.toLowerCase().includes(t)}):t,he=me.reduce((e,t)=>(e[t.family]||(e[t.family]=[]),e[t.family]?.push(t),e),{});return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(Gn,{className:`h-4 w-4 text-muted-foreground`}),v(`settings:provider.subscriptionHeading`)]}),(0,Y.jsx)(Hd,{ws:h})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-1 flex items-center gap-2`,children:[(0,Y.jsx)(De,{className:`h-4 w-4 text-muted-foreground`}),v(`settings:provider.apiKeysHeading`)]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:v(`settings:provider.apiKeysBody`)})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,Y.jsxs)($,{variant:a===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>o(`catalog`),children:[(0,Y.jsx)(De,{className:`h-4 w-4 mr-1`}),v(`settings:provider.tabCatalog`)]}),(0,Y.jsxs)($,{variant:a===`saved`?`default`:`outline`,size:`sm`,onClick:()=>o(`saved`),children:[(0,Y.jsx)(Gn,{className:`h-4 w-4 mr-1`}),v(`settings:provider.tabSaved`,{count:r.length})]})]}),a===`catalog`&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(Su,{placeholder:v(`settings:provider.searchPlaceholder`,{count:t.length}),value:g,onChange:e=>_(e.target.value),className:`text-sm`}),n&&t.length===0?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,Y.jsx)(R,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:v(`settings:provider.loadingCatalog`)})]}):me.length===0&&g?(0,Y.jsx)(`div`,{className:`text-center py-8 text-muted-foreground text-sm`,children:v(`settings:provider.noMatch`,{query:g})}):rf.map(t=>{let n=he[t];return n?.length?(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:t}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:n.map(t=>{let n=ue[t.id],r=e===t.id;return(0,Y.jsxs)(`div`,{className:K(`rounded-lg border transition-all`,r?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border`),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(t.id),className:K(`flex w-full flex-col items-start p-3 text-left rounded-lg`,!r&&`hover:bg-muted`),children:[(0,Y.jsxs)(`div`,{className:`flex w-full justify-between items-start`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,Y.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,t.id,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.hasApiKey&&(0,Y.jsxs)(`span`,{className:`text-xs bg-green-500/10 text-green-600 px-2 py-0.5 rounded`,children:[(0,Y.jsx)(Gn,{className:`h-3 w-3 inline mr-1`}),v(`settings:provider.configured`)]}),n&&(0,Y.jsxs)(`span`,{className:K(`text-xs px-2 py-0.5 rounded inline-flex items-center gap-1`,n.ok?`bg-green-500/10 text-green-600`:`bg-destructive/10 text-destructive`),title:n.detail??n.status,children:[n.ok?(0,Y.jsx)(jn,{className:`h-3 w-3`}):(0,Y.jsx)(f,{className:`h-3 w-3`}),n.ok?v(`settings:provider.reachable`):n.status]}),t.envVars[0]&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:v(`settings:provider.envVar`,{var:t.envVars[0]})}),r&&(0,Y.jsx)(jn,{className:`h-4 w-4 text-primary`})]})]}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[v(`settings:provider.modelCount`,{count:t.modelCount}),t.apiBase&&` · ${t.apiBase}`]})]}),r&&!t.hasApiKey&&(0,Y.jsx)(`div`,{className:`px-3 pb-3 -mt-1 space-y-2`,children:ne===t.id?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(Su,{autoFocus:!0,type:se?`text`:`password`,placeholder:v(`settings:provider.keyPlaceholder`,{name:t.name}),value:ae,onChange:e=>oe(e.target.value),className:`text-sm`,onKeyDown:e=>{e.key===`Enter`&&pe(t)}}),(0,Y.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>le(e=>!e),children:se?(0,Y.jsx)(st,{className:`h-4 w-4`}):(0,Y.jsx)(ce,{className:`h-4 w-4`})}),(0,Y.jsx)($,{size:`sm`,onClick:()=>pe(t),disabled:!ae.trim(),children:v(`common:action.save`)})]}),t.envVars[0]&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:v(`settings:provider.orEnv`,{env:t.envVars[0]})})]}):(0,Y.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>{ie(t.id),oe(``)},children:[(0,Y.jsx)(Gn,{className:`h-3.5 w-3.5 mr-1`}),v(`settings:provider.addApiKey`)]})})]},t.id)})})]},t):null})]}),a===`saved`&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:v(`settings:provider.manageKeys`)}),(0,Y.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>O(!D),children:[(0,Y.jsx)(re,{className:`h-4 w-4 mr-1`}),v(`settings:provider.addProvider`)]})]}),D&&(0,Y.jsxs)(`div`,{className:`p-4 border rounded-lg space-y-3 bg-muted/50`,children:[(0,Y.jsx)(`h4`,{className:`font-medium`,children:v(`settings:provider.addCustomHeading`)}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:v(`settings:provider.localServers`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:zd.map(e=>(0,Y.jsx)($,{type:`button`,size:`sm`,variant:k===e.id?`default`:`outline`,onClick:()=>te(e),title:e.hint,children:e.label},e.id))})]}),(0,Y.jsx)(Su,{placeholder:v(`settings:provider.providerIdPlaceholder`),value:k,onChange:e=>A(e.target.value)}),(0,Y.jsxs)(`select`,{className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:j,onChange:e=>M(e.target.value),children:[(0,Y.jsx)(`option`,{value:`anthropic`,children:`Anthropic`}),(0,Y.jsx)(`option`,{value:`openai`,children:`OpenAI`}),(0,Y.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI Compatible`}),(0,Y.jsx)(`option`,{value:`google`,children:`Google`})]}),(0,Y.jsx)(Su,{placeholder:`Base URL (optional, e.g. http://localhost:11434/v1)`,value:N,onChange:e=>P(e.target.value)}),(0,Y.jsx)(Su,{type:`password`,placeholder:v(`settings:provider.apiKeyOptionalPlaceholder`),value:F,onChange:e=>I(e.target.value)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)($,{size:`sm`,onClick:ee,disabled:!k.trim(),children:v(`common:action.add`)}),(0,Y.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>O(!1),children:v(`common:action.cancel`)})]})]}),i?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Y.jsx)(R,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):r.length===0?(0,Y.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Y.jsx)(Gn,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,Y.jsx)(`p`,{children:v(`settings:provider.noSaved`)}),(0,Y.jsx)(`p`,{className:`text-sm`,children:v(`settings:provider.noSavedHint`)})]}):r.map(e=>(0,Y.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between items-start`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h4`,{className:`font-medium`,children:e.id}),e.family&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.family})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>p(e.id),children:(0,Y.jsx)(At,{className:`h-4 w-4 text-destructive`})})})]}),e.baseUrl&&(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,Y.jsx)(De,{className:`h-3 w-3 inline mr-1`}),e.baseUrl]}),(0,Y.jsx)(tf,{providerId:e.id,savedPickedModelId:e.pickedModelId,savedModels:e.models,ws:h,onPickModel:m}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:v(`settings:provider.apiKeysLabel`)}),(0,Y.jsxs)($,{size:`sm`,variant:`ghost`,onClick:()=>b(y===e.id?null:e.id),children:[(0,Y.jsx)(re,{className:`h-3 w-3 mr-1`}),v(`settings:provider.addKey`)]})]}),e.apiKeys.length===0&&!y&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:v(`settings:provider.noKeys`)}),e.apiKeys.map(t=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-muted/50 rounded`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:t.label}),t.isActive&&(0,Y.jsx)(`span`,{className:`ml-2 text-xs bg-green-500/10 text-green-600 px-1.5 py-0.5 rounded`,children:v(`settings:provider.active`)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.maskedKey})]}),(0,Y.jsxs)(`div`,{className:`flex gap-1`,children:[!t.isActive&&(0,Y.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>u(e.id,t.label),children:v(`settings:provider.setActive`)}),(0,Y.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>l(e.id,t.label),children:(0,Y.jsx)(At,{className:`h-3 w-3 text-destructive`})})]})]},t.label)),y===e.id&&(0,Y.jsxs)(`div`,{className:`p-3 border rounded space-y-2 bg-background`,children:[(0,Y.jsx)(Su,{placeholder:v(`settings:provider.keyLabelPlaceholder`),value:x,onChange:e=>S(e.target.value)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(Su,{type:T?`text`:`password`,placeholder:v(`settings:provider.apiKeyPlaceholder`),value:C,onChange:e=>w(e.target.value)}),(0,Y.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>E(!T),children:T?(0,Y.jsx)(st,{className:`h-4 w-4`}):(0,Y.jsx)(ce,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)($,{size:`sm`,onClick:()=>L(e.id),disabled:!x.trim()||!C.trim(),children:v(`settings:provider.saveKey`)}),(0,Y.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>{b(null),S(``),w(``)},children:v(`common:action.cancel`)})]})]})]})]},e.id))]})]})}var of=[{value:``,label:`mode: inherit`},{value:`auto`,label:`mode: auto`},{value:`on`,label:`mode: on`},{value:`off`,label:`mode: off`}],sf=[{value:``,label:`effort: inherit`},{value:`none`,label:`effort: none`},{value:`minimal`,label:`effort: minimal`},{value:`low`,label:`effort: low`},{value:`medium`,label:`effort: medium`},{value:`high`,label:`effort: high`},{value:`xhigh`,label:`effort: xhigh`},{value:`max`,label:`effort: max`}],cf=[{value:``,label:`preserve: inherit`},{value:`on`,label:`preserve: on`},{value:`off`,label:`preserve: off`}],lf=new Set(bd);function uf(e,t,n){let r={};return e&&(r.mode=e),t&&(r.effort=t),n&&(r.preserve=n===`on`),Object.keys(r).length>0?{reasoning:r}:void 0}function df(e){return e?[e.mode?`mode:${e.mode}`:``,e.effort?`effort:${e.effort}`:``,e.preserve===void 0?``:`preserve:${e.preserve?`on`:`off`}`].filter(Boolean):[]}function ff(){let{provider:e,model:t,setProvider:n,setModel:r,setConfig:i,wsConnected:a,wsUrl:o}=J(We(e=>({provider:e.provider,model:e.model,setProvider:e.setProvider,setModel:e.setModel,setConfig:e.setConfig,wsConnected:e.wsConnected,wsUrl:e.wsUrl}))),{theme:s,setTheme:c}=Vs(),l=ts(),u=l.client,{updatePrefs:d,switchAutonomy:f}=l,p=$n(),{t:m}=z(),h=hd(!0),_=(0,q.useCallback)((e,t)=>{p.set({[e]:t}),d({[e]:t})},[p,d]),v=(0,q.useCallback)(e=>{p.set({uiLocale:e}),B.language!==e&&B.changeLanguage(e),_(`uiLocale`,e)},[p,_]),[y,b]=(0,q.useState)([]),[x,S]=(0,q.useState)({}),[C,w]=(0,q.useState)([]),[T,E]=(0,q.useState)(!1),[D,O]=(0,q.useState)(!1),[k,A]=(0,q.useState)(!1),[j,M]=(0,q.useState)(`catalog`),[N,P]=(0,q.useState)(``),[F,I]=(0,q.useState)(``),[L,ee]=(0,q.useState)(`*`),[te,re]=(0,q.useState)(``),[ie,ae]=(0,q.useState)(``),[oe,se]=(0,q.useState)(``),[ce,le]=(0,q.useState)(``),ue=y.find(t=>t.id===e);(0,q.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;b(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),E(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;S(e=>({...e,[t.provider]:t.models})),O(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));w(t),A(!1),t.length>0&&M(`saved`)}};if(!a||!u)return;let r=u.on(`provider.catalog`,e),i=u.on(`provider.models`,t),o=u.on(`providers.saved`,n);return E(!0),A(!0),u.listProviders(),u.listSavedProviders(),()=>{r?.(),i?.(),o?.()}},[a,u]);let de=(0,q.useCallback)(e=>{n(e),x[e]||(O(!0),l.listProviderModels?.(e))},[x,n,l]),fe=(0,q.useCallback)(e=>{r(e);let t=J.getState().provider;l.switchModel?.(t,e),Z.success(B.t(`settings:toast.switchingTo`,{provider:t,model:e}))},[r,l]),pe=(0,q.useCallback)((e,t,n)=>{l.addKey?.(e,t,n)},[l]),me=(0,q.useCallback)((e,t)=>{l.deleteKey?.(e,t)},[l]),he=(0,q.useCallback)((e,t)=>{l.setActiveKey?.(e,t)},[l]),ge=(0,q.useCallback)((e,t,n,r)=>{l.addProvider?.(e,t,n,r)},[l]),_e=(0,q.useCallback)(e=>{l.removeProvider?.(e)},[l]),ve=(0,q.useCallback)((e,t)=>{l.client.updateProvider({id:e,models:[t]}),e===J.getState().provider&&r(t)},[r,l.client]),ye=(0,q.useCallback)(e=>_(`fallbackProfiles`,e),[_]),xe=(0,q.useCallback)(()=>{let e=F.trim();if(e){if(p.fallbackProfiles[e]){Z.error(B.t(`settings:toast.fallbackExists`,{name:e}));return}ye({...p.fallbackProfiles,[e]:[]}),I(``)}},[p.fallbackProfiles,F,ye]),Se=(0,q.useCallback)(()=>{let n=e&&t?`${e}/${t}`:``;if(!n){Z.error(B.t(`settings:toast.selectProviderModelFirst`));return}let r=[n,...p.fallbackModels].filter((e,t,n)=>e&&n.indexOf(e)===t);ye({...p.fallbackProfiles,default:r}),Z.success(B.t(`settings:toast.defaultProfileCreated`))},[t,p.fallbackModels,p.fallbackProfiles,e,ye]);(0,q.useEffect)(()=>{if(Object.keys(p.fallbackProfiles).length>0)return;let n=e&&t?`${e}/${t}`:``;n&&ye({default:[n,...p.fallbackModels].filter((e,t,n)=>e&&n.indexOf(e)===t)})},[t,p.fallbackModels,p.fallbackProfiles,e,ye]);let Ce=(0,q.useCallback)((e,t)=>{ye({...p.fallbackProfiles,[e]:t})},[p.fallbackProfiles,ye]),we=(0,q.useCallback)(e=>{let{[e]:t,...n}=p.fallbackProfiles;ye(n)},[p.fallbackProfiles,ye]),Te=(0,q.useCallback)(e=>{_(`fallbackModels`,p.fallbackProfiles[e]??[])},[p.fallbackProfiles,_]),Ee=(0,q.useCallback)(t=>{let i=p.fallbackProfiles[t]??[],a=i[0];if(!a){Z.error(B.t(`settings:toast.profileEmpty`,{name:t}));return}let o=a.indexOf(`/`),s=o>0?a.slice(0,o):e,c=o>0?a.slice(o+1):a;n(s),r(c),l.switchModel?.(s,c),_(`fallbackModels`,i.slice(1)),Z.success(B.t(`settings:toast.leaderSetFrom`,{name:t}))},[p.fallbackProfiles,e,r,n,_,l]),Oe=(0,q.useCallback)(e=>_(`modelMatrix`,e),[_]),ke=(0,q.useCallback)(()=>{let e=L.trim(),t=te.trim(),n=uf(ie,oe,ce);if(!e||!t&&!n)return;let r=t?p.fallbackProfiles[t]?{fallbackProfile:t}:t.includes(`/`)?{provider:t.slice(0,t.indexOf(`/`)),model:t.slice(t.indexOf(`/`)+1)}:{model:t}:{},i=p.modelMatrix[e]?.modelRuntime;n?r.modelRuntime=n:i&&(r.modelRuntime=i),Oe({...p.modelMatrix,[e]:r}),re(``),ae(``),se(``),le(``)},[p.fallbackProfiles,p.modelMatrix,L,ce,oe,ie,te,Oe]),Ae=(0,q.useCallback)(e=>{let{[e]:t,...n}=p.modelMatrix;Oe(n)},[p.modelMatrix,Oe]),je=(0,q.useCallback)((e,t,n)=>{let r={...p.modelMatrix},i={...r[e]??{}},a={...i.modelRuntime??{}},o={...a.reasoning??{}};t===`mode`?n?o.mode=n:delete o.mode:t===`effort`?n?o.effort=n:delete o.effort:n?o.preserve=n===`on`:delete o.preserve,Object.keys(o).length>0?a.reasoning=o:delete a.reasoning,Object.keys(a).length>0?i.modelRuntime=a:delete i.modelRuntime,i.model||i.fallbackProfile||i.modelRuntime?r[e]=i:delete r[e],Oe(r)},[p.modelMatrix,Oe]),Me=e=>{let t=e.provider&&e.model?`${e.provider}/${e.model}`:e.model,n=e.modelRuntime?.reasoning;return[t??(!e.fallbackProfile&&n?m(`settings:agent.leaderModel`):``),e.fallbackProfile?`profile:${e.fallbackProfile}`:``,...df(n)].filter(Boolean).join(` + `)},Ne=Array.from(new Set([...Object.keys(p.modelMatrix),L].filter(e=>e&&!lf.has(e)))).sort((e,t)=>e.localeCompare(t));return(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Y.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card shrink-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:m(`settings:title`)}),(0,Y.jsx)($,{variant:`ghost`,size:`icon`,onClick:()=>Q(`chat`),children:(0,Y.jsx)(ut,{className:`h-4 w-4`})})]}),(0,Y.jsx)(ju,{className:`min-h-0 flex-1`,children:(0,Y.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,Y.jsxs)(Nu,{defaultValue:`provider`,children:[(0,Y.jsxs)(Pu,{className:`w-full justify-start mb-6 grid grid-cols-6`,children:[(0,Y.jsxs)(Fu,{value:`provider`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(pt,{className:`h-3.5 w-3.5`}),m(`settings:tabs.provider`)]}),(0,Y.jsxs)(Fu,{value:`connection`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(De,{className:`h-3.5 w-3.5`}),m(`settings:tabs.connection`)]}),(0,Y.jsxs)(Fu,{value:`appearance`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(lt,{className:`h-3.5 w-3.5`}),m(`settings:tabs.appearance`)]}),(0,Y.jsxs)(Fu,{value:`agent`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(wt,{className:`h-3.5 w-3.5`}),m(`settings:tabs.agent`)]}),(0,Y.jsxs)(Fu,{value:`features`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(Qe,{className:`h-3.5 w-3.5`}),m(`settings:tabs.features`)]}),(0,Y.jsxs)(Fu,{value:`mcp`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(g,{className:`h-3.5 w-3.5`}),m(`settings:tabs.mcp`)]})]}),(0,Y.jsxs)(Iu,{value:`provider`,className:`space-y-4`,children:[(0,Y.jsx)(af,{activeProvider:e,catalogProviders:y,isLoadingCatalog:T,savedProviders:C,isLoadingSaved:k,providerTab:j,setProviderTab:M,onSelectProvider:de,onAddKey:pe,onDeleteKey:me,onSetActiveKey:he,onAddProvider:ge,onRemoveProvider:_e,onPickProviderModel:ve,ws:l.client,catalogQuery:N,setCatalogQuery:P}),(0,Y.jsxs)(`div`,{className:`pt-4 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,Y.jsx)(Tn,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.modelHeading`)]}),(0,Y.jsx)(Pd,{provider:e,catalogModels:x,currentCatalogProvider:ue,isLoadingModels:D,setIsLoadingModels:O,onModelSelect:fe,refreshModels:e=>l.listProviderModels?.(e)})]})]}),(0,Y.jsxs)(Iu,{value:`connection`,className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`label`,{htmlFor:`websocket-url`,className:`text-sm font-medium flex items-center gap-2`,children:[(0,Y.jsx)(De,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:connection.wsUrlLabel`)]}),(0,Y.jsx)(Su,{id:`websocket-url`,value:o,onChange:e=>i({wsUrl:e.target.value}),placeholder:m(`settings:connection.wsUrlPlaceholder`),className:`font-mono text-sm`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:m(`settings:connection.wsUrlHint`)})]}),(0,Y.jsxs)(`div`,{className:`p-4 rounded-lg border bg-muted/50`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:m(`settings:connection.startingHeading`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:m(`settings:connection.startingBody`)})]})]}),(0,Y.jsxs)(Iu,{value:`appearance`,className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:m(`settings:appearance.themeHeading`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-md`,children:[(0,Y.jsxs)($,{variant:s===`light`?`default`:`outline`,size:`sm`,onClick:()=>c(`light`),children:[(0,Y.jsx)(_t,{className:`h-4 w-4 mr-1`}),m(`settings:appearance.themeLight`)]}),(0,Y.jsxs)($,{variant:s===`dark`?`default`:`outline`,size:`sm`,onClick:()=>c(`dark`),children:[(0,Y.jsx)(Mt,{className:`h-4 w-4 mr-1`}),m(`settings:appearance.themeDark`)]}),(0,Y.jsxs)($,{variant:s===`system`?`default`:`outline`,size:`sm`,onClick:()=>c(`system`),children:[(0,Y.jsx)(Mn,{className:`h-4 w-4 mr-1`}),m(`settings:appearance.themeSystem`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:m(`settings:appearance.themeSystemHint`)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold mb-3 mt-3`,children:m(`settings:appearance.languageHeading`)}),(0,Y.jsx)(Id,{label:m(`settings:appearance.languageLabel`),hint:m(`settings:appearance.languageHint`),value:p.uiLocale,options:Qn.map(e=>({value:e.code,label:e.name})),onChange:v})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold mb-3 mt-3`,children:m(`settings:appearance.preferencesHeading`)}),(0,Y.jsx)(Ld,{label:m(`settings:appearance.compactDensity`),hint:m(`settings:appearance.compactDensityHint`),selector:e=>e.compactMode,onChange:()=>G.getState().toggleCompactMode()}),(0,Y.jsx)(Ld,{label:m(`settings:appearance.soundOnComplete`),hint:m(`settings:appearance.soundOnCompleteHint`),selector:null,configKey:`soundOnComplete`}),(0,Y.jsx)(Ld,{label:m(`settings:appearance.titleAnimation`),hint:m(`settings:appearance.titleAnimationHint`),value:p.titleAnimation,onChange:()=>_(`titleAnimation`,!p.titleAnimation)})]})]}),(0,Y.jsxs)(Iu,{value:`agent`,className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,Y.jsx)(be,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.autonomyHeading`)]}),(0,Y.jsx)(Id,{label:m(`settings:agent.autonomyModeLabel`),hint:m(`settings:agent.autonomyModeHint`),value:p.autonomy,options:[{value:`off`,label:m(`settings:agent.autonomyModeOff`)},{value:`suggest`,label:m(`settings:agent.autonomyModeSuggest`)},{value:`auto`,label:m(`settings:agent.autonomyModeAuto`)},{value:`eternal`,label:m(`settings:agent.autonomyModeEternal`)},{value:`eternal-parallel`,label:m(`settings:agent.autonomyModeEternalParallel`)}],onChange:e=>{p.set({autonomy:e}),f(e)}}),(0,Y.jsx)(Fd,{label:m(`settings:agent.autoProceedDelayLabel`),hint:m(`settings:agent.autoProceedDelayHint`),value:p.autonomyDelayMs,min:0,max:1e4,step:500,unit:`ms`,onChange:e=>_(`autonomyDelayMs`,e)}),(0,Y.jsx)(Ld,{label:m(`settings:agent.yoloLabel`),hint:m(`settings:agent.yoloHint`),value:p.yolo,onChange:()=>_(`yolo`,!p.yolo)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(rt,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.refineHeading`)]}),(0,Y.jsx)(Ld,{label:m(`settings:agent.enableRefineLabel`),hint:m(`settings:agent.enableRefineHint`),value:p.enhanceEnabled,onChange:()=>_(`enhanceEnabled`,!p.enhanceEnabled)}),(0,Y.jsx)(Fd,{label:m(`settings:agent.refineDelayLabel`),hint:m(`settings:agent.refineDelayHint`),value:p.enhanceDelayMs,min:3e4,max:12e4,step:15e3,unit:`ms`,onChange:e=>_(`enhanceDelayMs`,e)}),(0,Y.jsx)(Id,{label:m(`settings:agent.refineLanguageLabel`),hint:m(`settings:agent.refineLanguageHint`),value:p.enhanceLanguage,options:[{value:`original`,label:m(`settings:agent.refineLanguageOriginal`)},{value:`english`,label:m(`settings:agent.refineLanguageEnglish`)}],onChange:e=>_(`enhanceLanguage`,e)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(Tn,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.reasoningHeading`)]}),(0,Y.jsx)(Id,{label:m(`settings:agent.reasoningModeLabel`),hint:m(`settings:agent.reasoningModeHint`),value:p.reasoningMode,options:[{value:`auto`,label:m(`settings:agent.reasoningModeAuto`)},{value:`on`,label:m(`settings:agent.reasoningModeOn`)},{value:`off`,label:m(`settings:agent.reasoningModeOff`)}],onChange:e=>_(`reasoningMode`,e)}),(0,Y.jsx)(Id,{label:m(`settings:agent.reasoningEffortLabel`),hint:m(`settings:agent.reasoningEffortHint`),value:p.reasoningEffort,options:[{value:`none`,label:m(`settings:agent.reasoningEffortNone`)},{value:`minimal`,label:m(`settings:agent.reasoningEffortMinimal`)},{value:`low`,label:m(`settings:agent.reasoningEffortLow`)},{value:`medium`,label:m(`settings:agent.reasoningEffortMedium`)},{value:`high`,label:m(`settings:agent.reasoningEffortHigh`)},{value:`xhigh`,label:m(`settings:agent.reasoningEffortXhigh`)},{value:`max`,label:m(`settings:agent.reasoningEffortMax`)}],onChange:e=>_(`reasoningEffort`,e)}),(0,Y.jsx)(Ld,{label:m(`settings:agent.preserveThinkingLabel`),hint:m(`settings:agent.preserveThinkingHint`),value:p.reasoningPreserve,onChange:()=>_(`reasoningPreserve`,!p.reasoningPreserve)}),(0,Y.jsx)(Id,{label:m(`settings:agent.cacheTtlLabel`),hint:m(`settings:agent.cacheTtlHint`),value:p.cacheTtl,options:[{value:`default`,label:m(`settings:agent.cacheTtlDefault`)},{value:`5m`,label:m(`settings:agent.cacheTtl5m`)},{value:`1h`,label:m(`settings:agent.cacheTtl1h`)}],onChange:e=>_(`cacheTtl`,e)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:m(`settings:agent.capsHint`)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(Tn,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.fallbackHeading`)]}),(0,Y.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:m(`settings:agent.fallbackBody`)}),(0,Y.jsx)(Cd,{value:p.fallbackModels,candidates:h,onChange:e=>_(`fallbackModels`,e)}),(0,Y.jsxs)(`div`,{className:`pt-1`,children:[(0,Y.jsx)(Ld,{label:m(`settings:agent.autoFallbackLabel`),hint:m(`settings:agent.autoFallbackHint`),value:p.fallbackAuto,onChange:()=>_(`fallbackAuto`,!p.fallbackAuto)}),(0,Y.jsx)(Ld,{label:m(`settings:agent.favoritesOnlyLabel`),hint:m(`settings:agent.favoritesOnlyHint`),value:p.favoriteModelsOnly,onChange:()=>_(`favoriteModelsOnly`,!p.favoriteModelsOnly)})]})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(sn,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.profilesHeading`)]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(Su,{value:F,onChange:e=>I(e.target.value),placeholder:`fallback1`,className:`font-mono text-sm`,onKeyDown:e=>{e.key===`Enter`&&xe()}}),(0,Y.jsx)($,{type:`button`,variant:`outline`,onClick:xe,children:m(`settings:agent.addProfile`)})]}),(0,Y.jsx)(`div`,{className:`mt-3 space-y-3`,children:Object.keys(p.fallbackProfiles).length===0?(0,Y.jsxs)(`div`,{className:`rounded-md border border-dashed border-border p-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:m(`settings:agent.noProfiles`)}),(0,Y.jsx)($,{type:`button`,variant:`outline`,size:`sm`,className:`mt-2`,onClick:Se,children:m(`settings:agent.createDefault`)})]}):Object.entries(p.fallbackProfiles).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>(0,Y.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,Y.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-sm font-medium`,children:e}),(0,Y.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Y.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Te(e),children:m(`settings:agent.useChain`)}),(0,Y.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Ee(e),children:m(`settings:agent.setLeader`)}),(0,Y.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>we(e),children:m(`common:action.remove`)})]})]}),(0,Y.jsx)(Cd,{value:t,candidates:h,placeholder:m(`settings:agent.addModelToProfile`),emptyHint:m(`settings:agent.profileEmpty`),onChange:t=>Ce(e,t)})]},e))})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(Tn,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.favoritesHeading`)]}),(0,Y.jsx)(Cd,{value:p.favoriteModels,candidates:h,placeholder:m(`settings:agent.addFavoriteModel`),emptyHint:m(`settings:agent.favoritesEmpty`),onChange:e=>_(`favoriteModels`,e)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(ne,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.routingHeading`)]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[minmax(0,180px)_1fr_auto]`,children:[(0,Y.jsxs)(`select`,{"aria-label":m(`settings:agent.routingRouteKey`),value:L,onChange:e=>ee(e.target.value),className:`h-9 min-w-0 rounded-md border bg-background px-3 font-mono text-sm`,children:[(0,Y.jsx)(`option`,{value:`*`,children:xd(`*`)}),(0,Y.jsx)(`optgroup`,{label:m(`settings:agent.routingPhasesGroup`),children:gd.map(e=>(0,Y.jsx)(`option`,{value:e.phase,children:xd(e.phase)},e.phase))}),gd.map(e=>(0,Y.jsx)(`optgroup`,{label:m(`settings:agent.routingRolesGroup`,{label:e.label}),children:e.roles.map(e=>(0,Y.jsx)(`option`,{value:e.role,children:xd(e.role)},e.role))},e.phase)),Ne.length>0?(0,Y.jsx)(`optgroup`,{label:m(`settings:agent.routingCustomGroup`),children:Ne.map(e=>(0,Y.jsx)(`option`,{value:e,children:xd(e)},e))}):null]}),(0,Y.jsx)(Su,{value:te,onChange:e=>re(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ke()},placeholder:m(`settings:agent.routingTargetPlaceholder`),className:`font-mono text-sm`}),(0,Y.jsx)($,{type:`button`,variant:`outline`,onClick:ke,children:m(`settings:agent.routingSet`)})]}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[(0,Y.jsx)(`select`,{"aria-label":m(`settings:agent.routingReasoningModeAria`),value:ie,onChange:e=>ae(e.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:of.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Y.jsx)(`select`,{"aria-label":m(`settings:agent.routingReasoningEffortAria`),value:oe,onChange:e=>se(e.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:sf.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Y.jsx)(`select`,{"aria-label":m(`settings:agent.routingReasoningPreserveAria`),value:ce,onChange:e=>le(e.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:cf.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))})]}),(0,Y.jsx)(`div`,{className:`mt-3 space-y-1.5`,children:Object.keys(p.modelMatrix).length===0?(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:m(`settings:agent.noRoutes`)}):Object.entries(p.modelMatrix).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>(0,Y.jsxs)(`div`,{className:`rounded-md border border-border bg-muted px-2 py-1.5 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-40 shrink-0 truncate font-mono text-muted-foreground`,title:e,children:xd(e)}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,children:Me(t)}),(0,Y.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Ae(e),children:m(`common:action.remove`)})]}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[(0,Y.jsx)(`select`,{"aria-label":m(`settings:agent.routingReasoningModeFor`,{key:e}),value:t.modelRuntime?.reasoning?.mode??``,onChange:t=>je(e,`mode`,t.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:of.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Y.jsx)(`select`,{"aria-label":m(`settings:agent.routingReasoningEffortFor`,{key:e}),value:t.modelRuntime?.reasoning?.effort??``,onChange:t=>je(e,`effort`,t.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:sf.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Y.jsx)(`select`,{"aria-label":m(`settings:agent.routingReasoningPreserveFor`,{key:e}),value:t.modelRuntime?.reasoning?.preserve===void 0?``:t.modelRuntime.reasoning.preserve?`on`:`off`,onChange:t=>je(e,`preserve`,t.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:cf.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))})]})]},e))})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(pt,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.hqHeading`)]}),(0,Y.jsx)(Ld,{label:m(`settings:agent.hqPublishingLabel`),hint:m(`settings:agent.hqPublishingHint`),value:p.hqEnabled,onChange:()=>_(`hqEnabled`,!p.hqEnabled)}),(0,Y.jsxs)(`div`,{className:`space-y-1 py-2`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium`,children:m(`settings:agent.hqUrlLabel`)}),(0,Y.jsx)(Su,{value:p.hqUrl,placeholder:`http://host:3499`,onChange:e=>_(`hqUrl`,e.target.value)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:m(`settings:agent.hqUrlHint`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1 py-2`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium`,children:m(`settings:agent.hqTokenLabel`)}),(0,Y.jsx)(Su,{type:`password`,value:p.hqToken,placeholder:`Client token from wstack --hq`,onChange:e=>_(`hqToken`,e.target.value)})]}),(0,Y.jsx)(Ld,{label:m(`settings:agent.hqRawContentLabel`),hint:m(`settings:agent.hqRawContentHint`),value:p.hqRawContent,onChange:()=>_(`hqRawContent`,!p.hqRawContent)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(rt,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.executionHeading`)]}),(0,Y.jsx)(Fd,{label:m(`settings:agent.maxIterationsLabel`),hint:m(`settings:agent.maxIterationsHint`),value:p.maxIterations,min:10,max:2e3,step:10,onChange:e=>_(`maxIterations`,e)}),(0,Y.jsx)(Fd,{label:m(`settings:agent.autoProceedMaxIterationsLabel`),hint:m(`settings:agent.autoProceedMaxIterationsHint`),value:p.autoProceedMaxIterations,min:0,max:250,step:5,onChange:e=>_(`autoProceedMaxIterations`,e)}),(0,Y.jsx)(Ld,{label:m(`settings:agent.confirmExitLabel`),hint:m(`settings:agent.confirmExitHint`),value:p.confirmExit,onChange:()=>_(`confirmExit`,!p.confirmExit)}),(0,Y.jsx)(Ld,{label:m(`settings:agent.chimeLabel`),hint:m(`settings:agent.chimeHint`),value:p.chime,onChange:()=>_(`chime`,!p.chime)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(ne,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.fleetHeading`)]}),(0,Y.jsx)(Ld,{label:m(`settings:agent.streamFleetLabel`),hint:m(`settings:agent.streamFleetHint`),value:p.streamFleet,onChange:()=>_(`streamFleet`,!p.streamFleet)}),(0,Y.jsx)(Fd,{label:m(`settings:agent.maxConcurrentLabel`),hint:m(`settings:agent.maxConcurrentHint`),value:p.maxConcurrent,min:1,max:50,step:1,onChange:e=>_(`maxConcurrent`,e)}),(0,Y.jsx)(Ld,{label:m(`settings:agent.nextPredictionLabel`),hint:m(`settings:agent.nextPredictionHint`),value:p.nextPrediction,onChange:()=>_(`nextPrediction`,!p.nextPrediction)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(Zt,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:agent.telegramHeading`)]}),p.tgConfigured?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ld,{label:m(`settings:agent.telegramSessionEndLabel`),hint:m(`settings:agent.telegramSessionEndHint`),value:p.tgSessionEnd,onChange:()=>_(`tgSessionEnd`,!p.tgSessionEnd)}),(0,Y.jsx)(Ld,{label:m(`settings:agent.telegramDelegateLabel`),hint:m(`settings:agent.telegramDelegateHint`),value:p.tgDelegate,onChange:()=>_(`tgDelegate`,!p.tgDelegate)}),(0,Y.jsx)(Ld,{label:m(`settings:agent.telegramLongToolLabel`),hint:m(`settings:agent.telegramLongToolHint`,{ms:p.tgLongToolMs}),value:p.tgLongToolMs>0,onChange:()=>_(`tgLongToolMs`,p.tgLongToolMs>0?0:3e4)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:m(`settings:agent.telegramChangesApply`)})]}):(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:m(`settings:agent.telegramNotConfigured`)})]})]}),(0,Y.jsxs)(Iu,{value:`features`,className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,Y.jsx)(Qe,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:features.flagsHeading`)]}),(0,Y.jsx)(Ld,{label:m(`settings:features.mcpLabel`),hint:m(`settings:features.mcpHint`),value:p.featureMcp,onChange:()=>_(`featureMcp`,!p.featureMcp)}),(0,Y.jsx)(Ld,{label:m(`settings:features.pluginsLabel`),hint:m(`settings:features.pluginsHint`),value:p.featurePlugins,onChange:()=>_(`featurePlugins`,!p.featurePlugins)}),(0,Y.jsx)(Ld,{label:m(`settings:features.memoryLabel`),hint:m(`settings:features.memoryHint`),value:p.featureMemory,onChange:()=>_(`featureMemory`,!p.featureMemory)}),(0,Y.jsx)(Ld,{label:m(`settings:features.skillsLabel`),hint:m(`settings:features.skillsHint`),value:p.featureSkills,onChange:()=>_(`featureSkills`,!p.featureSkills)}),(0,Y.jsx)(Ld,{label:m(`settings:features.modelsRegistryLabel`),hint:m(`settings:features.modelsRegistryHint`),value:p.featureModelsRegistry,onChange:()=>_(`featureModelsRegistry`,!p.featureModelsRegistry)}),(0,Y.jsx)(Ld,{label:m(`settings:features.indexOnStartLabel`),hint:m(`settings:features.indexOnStartHint`),value:p.indexOnStart,onChange:()=>_(`indexOnStart`,!p.indexOnStart)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(Un,{className:`h-4 w-4 text-muted-foreground`}),m(`settings:features.contextHeading`)]}),(0,Y.jsx)(Ld,{label:m(`settings:features.autoCompactLabel`),hint:m(`settings:features.autoCompactHint`),value:p.contextAutoCompact,onChange:()=>_(`contextAutoCompact`,!p.contextAutoCompact)}),(0,Y.jsx)(Id,{label:m(`settings:features.compactorStrategyLabel`),hint:m(`settings:features.compactorStrategyHint`),value:p.contextStrategy,options:[{value:`hybrid`,label:m(`settings:features.compactorStrategyHybrid`)},{value:`intelligent`,label:m(`settings:features.compactorStrategyIntelligent`)},{value:`selective`,label:m(`settings:features.compactorStrategySelective`)}],onChange:e=>_(`contextStrategy`,e)}),(0,Y.jsx)(Id,{label:m(`settings:features.contextModeLabel`),hint:m(`settings:features.contextModeHint`),value:p.contextMode,options:[{value:`balanced`,label:m(`settings:features.contextModeBalanced`)},{value:`frugal`,label:m(`settings:features.contextModeFrugal`)},{value:`deep`,label:m(`settings:features.contextModeDeep`)},{value:`archival`,label:m(`settings:features.contextModeArchival`)}],onChange:e=>_(`contextMode`,e)}),(0,Y.jsx)(Id,{label:m(`settings:features.tokenSavingLabel`),hint:m(`settings:features.tokenSavingHint`),value:p.tokenSavingTier,options:[{value:`off`,label:m(`settings:features.tokenSavingOff`)},{value:`minimal`,label:m(`settings:features.tokenSavingMinimal`)},{value:`light`,label:m(`settings:features.tokenSavingLight`)},{value:`medium`,label:m(`settings:features.tokenSavingMedium`)},{value:`aggressive`,label:m(`settings:features.tokenSavingAggressive`)}],onChange:e=>_(`tokenSavingTier`,e)}),(0,Y.jsx)(Id,{label:m(`settings:features.logLevelLabel`),hint:m(`settings:features.logLevelHint`),value:p.logLevel,options:[{value:`debug`,label:m(`settings:features.logLevelDebug`)},{value:`info`,label:m(`settings:features.logLevelInfo`)},{value:`warn`,label:m(`settings:features.logLevelWarn`)},{value:`error`,label:m(`settings:features.logLevelError`)}],onChange:e=>_(`logLevel`,e)}),(0,Y.jsx)(Id,{label:m(`settings:features.auditLevelLabel`),hint:m(`settings:features.auditLevelHint`),value:p.auditLevel,options:[{value:`minimal`,label:m(`settings:features.auditLevelMinimal`)},{value:`standard`,label:m(`settings:features.auditLevelStandard`)},{value:`full`,label:m(`settings:features.auditLevelFull`)}],onChange:e=>_(`auditLevel`,e)})]})]}),(0,Y.jsx)(Iu,{value:`mcp`,className:`space-y-4`,children:p.featureMcp?(0,Y.jsx)(Nd,{}):(0,Y.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Y.jsx)(g,{className:`w-10 h-10 mx-auto mb-2 opacity-50`}),(0,Y.jsx)(`p`,{children:m(`settings:mcp.disabled`)}),(0,Y.jsx)(`p`,{className:`text-sm mt-1`,children:m(`settings:mcp.disabledHint`)})]})})]})})})]})}var pf=[],mf=100,hf=3e4,gf=5,_f=null,vf=!1;function yf(e){pf.push(e),pf.length>mf&&pf.shift(),pf.length>=gf&&!vf&&bf()}async function bf(){if(vf||pf.length===0)return;vf=!0;let e=pf.splice(0,pf.length);try{(await fetch(`/api/analytics`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})).ok||(pf.unshift(...e),pf.length>mf&&(pf.length=mf))}catch{pf.unshift(...e),pf.length>mf&&(pf.length=mf)}finally{vf=!1}}function xf(){_f||=setInterval(()=>{pf.length>0&&bf()},hf)}function Sf(e,t,n){yf({event:e,category:t,label:n?.label,value:n?.value,metadata:n?.metadata,timestamp:new Date().toISOString()})}var Cf=`wrongstack_referral_click`;function wf(e){try{sessionStorage.setItem(Cf,JSON.stringify(e))}catch{}Sf(`referral_link_clicked`,`engagement`,{label:e.providerName,metadata:{providerId:e.providerId,referralCode:e.referralCode,docsUrl:e.docsUrl}})}function Tf(){try{let e=sessionStorage.getItem(Cf);return e?JSON.parse(e):null}catch{return null}}function Ef(){try{sessionStorage.removeItem(Cf)}catch{}}function Df(e,t){let n=Tf();if(n&&n.providerId===e){let r=Date.now()-new Date(n.clickedAt).getTime();Sf(`referral_converted`,`conversion`,{label:t,value:Math.round(r/1e3),metadata:{providerId:e,referralCode:n.referralCode,timeToConvertMs:r,clickedAt:n.clickedAt}}),Ef()}}var Of=e(on(),1),kf=[{id:`openai`,name:`OpenAI`,description:`GPT, o-series, and Codex models`,icon:`🤖`,color:`from-emerald-500/20 to-emerald-500/5 border-emerald-500/30 hover:border-emerald-500/50`,keyPlaceholder:`sk-...`,docsUrl:`https://platform.openai.com/api-keys`,family:`openai`},{id:`anthropic`,name:`Anthropic`,description:`Claude Opus, Sonnet, and Haiku`,icon:`🧠`,color:`from-amber-500/20 to-amber-500/5 border-amber-500/30 hover:border-amber-500/50`,keyPlaceholder:`sk-ant-...`,docsUrl:`https://console.anthropic.com/settings/keys`,family:`anthropic`},{id:`google`,name:`Google`,description:`Gemini Pro, Flash, and Nano`,icon:`✨`,color:`from-blue-500/20 to-blue-500/5 border-blue-500/30 hover:border-blue-500/50`,keyPlaceholder:`AIza...`,docsUrl:`https://aistudio.google.com/apikey`,family:`google`},{id:`deepseek`,name:`DeepSeek`,description:`High-performance reasoning at low cost`,icon:`🐋`,color:`from-sky-500/20 to-sky-500/5 border-sky-500/30 hover:border-sky-500/50`,keyPlaceholder:`sk-...`,docsUrl:`https://platform.deepseek.com/api_keys`,family:`openai-compatible`},{id:`openrouter`,name:`OpenRouter`,description:`All models via one key`,icon:`🔀`,color:`from-violet-500/20 to-violet-500/5 border-violet-500/30 hover:border-violet-500/50`,keyPlaceholder:`sk-or-...`,docsUrl:`https://openrouter.ai/keys`,family:`openai-compatible`},{id:`minimax`,name:`MiniMax`,description:`Subscribe to one plan and unlock the latest models, including frontier coding capabilities, 1M ultra-long context, and native multimodality. Text, image, and speech models all share the same quota. Invite Friends, Win Together: Friends get 10% off plus Builder benefits when they subscribe, while referrers earn 10% cashback plus community perks.`,icon:`🔮`,color:`from-fuchsia-500/20 to-fuchsia-500/5 border-fuchsia-500/30 hover:border-fuchsia-500/50`,keyPlaceholder:`eyJ...`,docsUrl:`https://platform.minimax.io/subscribe/token-plan?code=JrA4R9QAEn&source=link`,family:`openai-compatible`},{id:`kimi`,name:`Kimi`,description:`Moonshot AI long-context models`,icon:`🌙`,color:`from-cyan-500/20 to-cyan-500/5 border-cyan-500/30 hover:border-cyan-500/50`,keyPlaceholder:`sk-...`,docsUrl:`https://www.kimi.com/membership/pricing`,family:`openai-compatible`},{id:`zai`,name:`Z.ai (GLM)`,description:`You've been invited to join the GLM Coding Plan! Enjoy full support for Claude Code, Cline, and 20+ top coding tools — starting at just $18/month. Subscribe now and grab the limited-time deal!`,icon:`🔷`,color:`from-indigo-500/20 to-indigo-500/5 border-indigo-500/30 hover:border-indigo-500/50`,keyPlaceholder:`...`,docsUrl:`https://z.ai/subscribe?ic=JQZ7TPPRA6`,family:`openai-compatible`},{id:`opencode-go`,name:`OpenCode Go`,description:`Global hosted API for 75+ LLM providers — stable access from US, EU, and Singapore`,icon:`🌍`,color:`from-teal-500/20 to-teal-500/5 border-teal-500/30 hover:border-teal-500/50`,keyPlaceholder:`oc-...`,docsUrl:`https://opencode.ai/go?ref=6VZAER87H4`,family:`openai-compatible`}];async function Af(e,t){try{let n=await fetch(e,{signal:t});if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.json();if(!Array.isArray(r))throw Error(`Expected JSON array`);let i=r.filter(e=>typeof e.id==`string`&&typeof e.name==`string`&&typeof e.family==`string`);return i.length>0?i:kf}catch{return kf}}function jf({popular:e,catalogProvider:t,savedProvider:n,onKeySaved:r}){let{t:i}=z(),[a,o]=(0,q.useState)(``),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(!!n?.apiKeys.some(e=>e.isActive)),[d,f]=(0,q.useState)(!1),[p,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(null);(0,q.useEffect)(()=>{h&&e.referral&&Of.toDataURL(e.referral.url,{width:200,margin:2,color:{dark:`#000000`,light:`#ffffff`}}).then(e=>v(e)).catch(()=>v(null))},[h,e.referral]);let y=async()=>{if(a.trim()){c(!0);try{let n=U(J.getState().wsUrl);t?n.addKey(e.id,`default`,a.trim()):n.send({type:`provider.add`,payload:{id:e.id,family:e.family,apiKey:a.trim()}}),u(!0),o(``),Z.success(i(`setup:screen.toasts.keySaved`,{name:e.name})),r(e.id),Sf(`provider_key_saved`,`engagement`,{label:e.name,metadata:{providerId:e.id,providerFamily:e.family,hasReferral:!!e.referral,isNewProvider:!t}}),e.referral&&Df(e.id,e.name)}catch{Z.error(i(`setup:screen.toasts.keySaveFailed`,{name:e.name})),Sf(`provider_key_save_failed`,`error`,{label:e.name,metadata:{providerId:e.id,providerFamily:e.family}})}finally{c(!1)}}},b=e=>{e.key===`Enter`&&a.trim()&&y()},x=async()=>{if(e.referral)try{await navigator.clipboard.writeText(e.referral.url),m(!0),Z.success(i(`setup:screen.toasts.referralCopied`)),setTimeout(()=>m(!1),2e3),Sf(`referral_link_copied`,`engagement`,{label:e.name,metadata:{providerId:e.id,referralCode:e.referral.code,referralUrl:e.referral.url}})}catch{Z.error(i(`setup:screen.toasts.referralCopyFailed`)),Sf(`referral_link_copy_failed`,`error`,{label:e.name,metadata:{providerId:e.id,referralCode:e.referral.code}})}},S=t&&t.modelCount>0;return(0,Y.jsxs)(`div`,{className:K(`rounded-xl border p-4 transition-all`,l?`border-emerald-500/30 bg-emerald-500/5`:`bg-gradient-to-br ${e.color}`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-2xl shrink-0 mt-0.5`,children:e.icon}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),l&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20`,children:[(0,Y.jsx)(gt,{className:`h-2.5 w-2.5`}),i(`setup:screen.card.keySaved`)]}),e.referral&&!l&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/10 text-amber-600 dark:text-amber-400 border border-amber-500/20`,children:[(0,Y.jsx)(ye,{className:`h-2.5 w-2.5`}),i(`setup:screen.card.referral`)]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e.description}),e.referral&&!l&&(0,Y.jsxs)(`p`,{className:`text-[11px] text-amber-600/80 dark:text-amber-400/80 mt-1`,children:[`🎁 `,e.referral.reward]}),l?S?(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>f(!d),className:`mt-2 text-[11px] text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1`,children:[i(`setup:screen.providers.modelsAvailable`,{count:t?.modelCount??0}),d?(0,Y.jsx)(Bt,{className:`h-3 w-3`}):(0,Y.jsx)(vn,{className:`h-3 w-3`})]}):null:(0,Y.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(Su,{type:`password`,placeholder:e.keyPlaceholder,value:a,onChange:e=>o(e.target.value),onKeyDown:b,className:`font-mono text-sm`}),(0,Y.jsx)($,{onClick:y,disabled:!a.trim()||s,size:`sm`,className:`shrink-0`,children:s?(0,Y.jsx)(R,{className:`h-4 w-4 animate-spin`}):i(`setup:screen.card.save`)})]}),e.docsUrl&&(0,Y.jsxs)(`a`,{href:e.docsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground transition-colors`,onClick:()=>{Sf(`provider_docs_link_clicked`,`engagement`,{label:e.name,metadata:{providerId:e.id,docsUrl:e.docsUrl,hasReferral:!!e.referral}}),e.referral&&wf({providerId:e.id,providerName:e.name,referralCode:e.referral.code,clickedAt:new Date().toISOString(),docsUrl:e.docsUrl??``})},children:[i(`setup:screen.card.getKey`),` `,(0,Y.jsx)(it,{className:`h-3 w-3`})]}),e.referral&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:x,className:`inline-flex items-center gap-1 text-[11px] text-amber-600/80 dark:text-amber-400/80 hover:text-amber-700 dark:hover:text-amber-300 transition-colors`,children:p?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(gt,{className:`h-3 w-3`}),` `,i(`setup:screen.card.copied`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(bt,{className:`h-3 w-3`}),` `,i(`setup:screen.card.copyReferral`)]})}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g(!0),className:`inline-flex items-center gap-1 text-[11px] text-amber-600/80 dark:text-amber-400/80 hover:text-amber-700 dark:hover:text-amber-300 transition-colors`,children:[(0,Y.jsx)(Oe,{className:`h-3 w-3`}),` `,i(`setup:screen.card.share`)]})]})]})]})]}),(0,Y.jsx)(Hc,{open:h,onOpenChange:g,children:(0,Y.jsxs)(Gc,{className:`sm:max-w-md`,children:[(0,Y.jsxs)(Kc,{children:[(0,Y.jsxs)(Jc,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(ye,{className:`h-4 w-4 text-amber-500`}),i(`setup:screen.share.title`,{name:e.name})]}),(0,Y.jsx)(Yc,{children:i(`setup:screen.share.description`)})]}),(0,Y.jsx)(`div`,{className:`flex flex-col items-center gap-4 py-4`,children:e.referral&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`text-sm text-center`,children:(0,Y.jsxs)(`p`,{className:`font-medium text-amber-600 dark:text-amber-400`,children:[`🎁 `,e.referral.reward]})}),_?(0,Y.jsx)(`div`,{className:`rounded-lg border border-border p-2 bg-white`,children:(0,Y.jsx)(`img`,{src:_,alt:i(`setup:screen.card.qrAlt`,{name:e.name}),className:`w-[200px] h-[200px]`})}):(0,Y.jsx)(`div`,{className:`w-[200px] h-[200px] rounded-lg border border-border flex items-center justify-center bg-muted`,children:(0,Y.jsx)(R,{className:`h-6 w-6 animate-spin text-muted-foreground`})}),(0,Y.jsxs)(`div`,{className:`w-full space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward}`),n=encodeURIComponent(e.referral.url);window.open(`https://twitter.com/intent/tweet?text=${t}&url=${n}`,`_blank`,`noopener,noreferrer`),Sf(`referral_share_twitter`,`engagement`,{label:e.name,metadata:{providerId:e.id}})},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-slate-900 text-white text-xs hover:bg-slate-800 transition-colors`,title:i(`setup:screen.share.twitter`),children:[(0,Y.jsx)(`svg`,{className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,Y.jsx)(`path`,{d:`M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z`})}),`X`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(e.referral.url),n=encodeURIComponent(`Check out ${e.name}! ${e.referral.reward}`);window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${t}&summary=${n}`,`_blank`,`noopener,noreferrer`),Sf(`referral_share_linkedin`,`engagement`,{label:e.name,metadata:{providerId:e.id}})},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[#0A66C2] text-white text-xs hover:bg-[#0958a8] transition-colors`,title:i(`setup:screen.share.linkedin`),children:[(0,Y.jsx)(`svg`,{className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,Y.jsx)(`path`,{d:`M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z`})}),`LinkedIn`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward} ${e.referral.url}`);window.open(`https://t.me/share/url?url=${t}`,`_blank`,`noopener,noreferrer`),Sf(`referral_share_telegram`,`engagement`,{label:e.name,metadata:{providerId:e.id}})},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[#26A5E4] text-white text-xs hover:bg-[#1e96d1] transition-colors`,title:i(`setup:screen.share.telegram`),children:[(0,Y.jsx)(`svg`,{className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,Y.jsx)(`path`,{d:`M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z`})}),`Telegram`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward}`),n=encodeURIComponent(e.referral.url);window.open(`https://wa.me/?text=${t}%20${n}`,`_blank`,`noopener,noreferrer`),Sf(`referral_share_whatsapp`,`engagement`,{label:e.name,metadata:{providerId:e.id}})},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[#25D366] text-white text-xs hover:bg-[#1fb859] transition-colors`,title:i(`setup:screen.share.whatsapp`),children:[(0,Y.jsx)(`svg`,{className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,Y.jsx)(`path`,{d:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.134 1.585 5.934L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z`})}),`WhatsApp`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(e.referral.url),n=encodeURIComponent(`${e.name} - ${e.referral.reward}`);window.open(`https://www.reddit.com/submit?url=${t}&title=${n}`,`_blank`,`noopener,noreferrer`),Sf(`referral_share_reddit`,`engagement`,{label:e.name,metadata:{providerId:e.id}})},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[#FF4500] text-white text-xs hover:bg-[#e03d00] transition-colors`,title:i(`setup:screen.share.reddit`),children:[(0,Y.jsx)(`svg`,{className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,Y.jsx)(`path`,{d:`M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zm5.01 4.744c.688 0 1.25.561 1.25 1.249a1.25 1.25 0 0 1-2.498.056l-2.597-.547-.8 3.747c1.824.07 3.48.632 4.674 1.488.308-.309.73-.491 1.207-.491.968 0 1.754.786 1.754 1.754 0 .716-.435 1.333-1.01 1.614a3.111 3.111 0 0 1 .042.52c0 2.694-3.13 4.87-7.004 4.87-3.874 0-7.004-2.176-7.004-4.87 0-.183.015-.366.043-.534A1.748 1.748 0 0 1 4.028 12c0-.968.786-1.754 1.754-1.754.463 0 .898.196 1.207.49 1.207-.883 2.878-1.43 4.744-1.487l.885-4.182a.342.342 0 0 1 .14-.197.35.35 0 0 1 .238-.042l2.906.617a1.214 1.214 0 0 0 1.108-.701 1.25 1.25 0 0 1 2.144.33zm-8.811 8.748c-.968 0-1.754.786-1.754 1.754 0 .968.786 1.754 1.754 1.754.968 0 1.754-.786 1.754-1.754 0-.968-.786-1.754-1.754-1.754zm7.944 0c-.968 0-1.754.786-1.754 1.754 0 .968.786 1.754 1.754 1.754.968 0 1.754-.786 1.754-1.754 0-.968-.786-1.754-1.754-1.754z`})}),`Reddit`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward}`),n=encodeURIComponent(e.referral.url);window.open(`https://www.facebook.com/sharer/sharer.php?u=${n}&quote=${t}`,`_blank`,`noopener,noreferrer`),Sf(`referral_share_facebook`,`engagement`,{label:e.name,metadata:{providerId:e.id}})},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-[#1877F2] text-white text-xs hover:bg-[#166fe5] transition-colors`,title:i(`setup:screen.share.facebook`),children:[(0,Y.jsx)(`svg`,{className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,Y.jsx)(`path`,{d:`M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z`})}),`Facebook`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward}`),n=encodeURIComponent(e.referral.url);window.open(`mailto:?subject=${t}&body=${n}`,`_blank`,`noopener,noreferrer`),Sf(`referral_share_email`,`engagement`,{label:e.name,metadata:{providerId:e.id}})},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-muted text-muted-foreground text-xs hover:bg-muted/80 transition-colors`,title:i(`setup:screen.share.email`),children:[(0,Y.jsx)(`svg`,{className:`h-3.5 w-3.5`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,viewBox:`0 0 24 24`,children:(0,Y.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25H4.5a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75`})}),`Email`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Su,{value:e.referral.url,readOnly:!0,className:`font-mono text-xs flex-1`}),(0,Y.jsx)($,{size:`sm`,variant:`outline`,onClick:x,className:`shrink-0`,children:p?(0,Y.jsx)(gt,{className:`h-4 w-4`}):(0,Y.jsx)(bt,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground text-center`,children:i(`setup:screen.share.hint`)})]})]})})]})})]})}function Mf({onKeySaved:e}){let{t}=z(),[n,r]=(0,q.useState)(!1),[i,a]=(0,q.useState)(``),[o,s]=(0,q.useState)(`openai-compatible`),[c,l]=(0,q.useState)(``),[u,d]=(0,q.useState)(``),[f,p]=(0,q.useState)(!1);return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-dashed border-border/60 overflow-hidden`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`w-full flex items-center gap-3 p-4 text-left hover:bg-muted/30 transition-colors`,children:[(0,Y.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-muted/50 flex items-center justify-center`,children:(0,Y.jsx)(re,{className:`h-5 w-5 text-muted-foreground`})}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium`,children:t(`setup:screen.custom.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`setup:screen.custom.description`)})]}),(0,Y.jsx)(vn,{className:K(`h-4 w-4 text-muted-foreground transition-transform`,n&&`rotate-90`)})]}),n&&(0,Y.jsxs)(`div`,{className:`px-4 pb-4 space-y-3 border-t border-border/40`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5 pt-3`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground block`,children:t(`setup:screen.custom.localServers`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:zd.map(e=>(0,Y.jsx)($,{type:`button`,size:`sm`,variant:i===e.id?`default`:`outline`,onClick:()=>{a(e.id),s(`openai-compatible`),l(e.defaultBaseUrl),e.noAuth&&d(``)},title:e.hint,children:e.label},e.id))})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-[11px] font-medium text-muted-foreground mb-1 block`,children:t(`setup:screen.custom.providerId`)}),(0,Y.jsx)(Su,{placeholder:`e.g. my-llm`,value:i,onChange:e=>a(e.target.value),className:`text-sm`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-[11px] font-medium text-muted-foreground mb-1 block`,children:t(`setup:screen.custom.family`)}),(0,Y.jsxs)(`select`,{value:o,onChange:e=>s(e.target.value),className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 text-sm`,children:[(0,Y.jsx)(`option`,{value:`openai-compatible`,children:t(`setup:screen.custom.familyOpenAiCompatible`)}),(0,Y.jsx)(`option`,{value:`openai`,children:`OpenAI`}),(0,Y.jsx)(`option`,{value:`anthropic`,children:`Anthropic`}),(0,Y.jsx)(`option`,{value:`google`,children:`Google`})]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-[11px] font-medium text-muted-foreground mb-1 block`,children:t(`setup:screen.custom.baseUrl`)}),(0,Y.jsx)(Su,{placeholder:`e.g. http://localhost:11434/v1`,value:c,onChange:e=>l(e.target.value),className:`text-sm font-mono`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`text-[11px] font-medium text-muted-foreground mb-1 block`,children:t(`setup:screen.custom.apiKey`)}),(0,Y.jsx)(Su,{type:`password`,placeholder:t(`setup:screen.custom.apiKeyPlaceholder`),value:u,onChange:e=>d(e.target.value),className:`text-sm font-mono`})]}),(0,Y.jsxs)($,{onClick:async()=>{if(i.trim()){p(!0);try{U(J.getState().wsUrl).send({type:`provider.add`,payload:{id:i.trim(),family:o,baseUrl:c.trim()||void 0,apiKey:u.trim()||void 0}}),Z.success(t(`setup:screen.toasts.providerAdded`,{id:i.trim()})),e(i.trim()),a(``),l(``),d(``),r(!1)}catch{Z.error(t(`setup:screen.toasts.providerAddFailed`))}finally{p(!1)}}},disabled:!i.trim()||f,size:`sm`,children:[f?(0,Y.jsx)(R,{className:`h-4 w-4 animate-spin mr-2`}):null,t(`setup:screen.custom.add`)]})]})]})}function Nf(){let{t:e}=z(),{model:t,setProvider:n,setModel:r,wsConnected:i,wsUrl:a}=J(We(e=>({model:e.model,setProvider:e.setProvider,setModel:e.setModel,wsConnected:e.wsConnected,wsUrl:e.wsUrl})));ts();let[o,s]=(0,q.useState)(`keys`),[c,l]=(0,q.useState)([]),[u,d]=(0,q.useState)({}),[f,p]=(0,q.useState)([]),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)(0),[x,S]=(0,q.useState)(new Set),[C,w]=(0,q.useState)(kf),[T,E]=(0,q.useState)(!1),[D,O]=(0,q.useState)(0),[k,j]=(0,q.useState)(0),[M,N]=(0,q.useState)(null),P=(0,q.useRef)(!0);(0,q.useEffect)(()=>{let e=new AbortController,t=`${window.location.origin}/providers.json`,n=`https://raw.githubusercontent.com/WrongStack/WrongStack/main/packages/webui/public/providers.json`;return E(!0),Af(t,e.signal).then(r=>{if(r!==kf){if(w(r),E(!1),Sf(`providers_loaded`,`system`,{label:`local`,metadata:{providerCount:r.length,source:t}}),!P.current){let e=r.length-k;e>0?Z.success(B.t(`setup:screen.toasts.providersLoadedNew`,{count:r.length,diff:e})):e<0?Z.success(B.t(`setup:screen.toasts.providersLoadedRemoved`,{count:r.length,diff:Math.abs(e)})):Z.success(B.t(`setup:screen.toasts.providersLoadedNoChanges`,{count:r.length})),j(r.length)}N(new Date);return}return Af(n,e.signal)}).then(e=>{if(e){if(w(e),Sf(`providers_loaded`,`system`,{label:`github`,metadata:{providerCount:e.length,source:n}}),!P.current){let t=e.length-k;t>0?Z.success(B.t(`setup:screen.toasts.providersLoadedNew`,{count:e.length,diff:t})):t<0?Z.success(B.t(`setup:screen.toasts.providersLoadedRemoved`,{count:e.length,diff:Math.abs(t)})):Z.success(B.t(`setup:screen.toasts.providersLoadedNoChanges`,{count:e.length})),j(e.length)}N(new Date)}}).catch(()=>{Sf(`providers_load_failed`,`error`,{metadata:{localUrl:t,githubUrl:n}}),P.current||Z.error(B.t(`setup:screen.toasts.providersRefreshFailed`))}).finally(()=>{E(!1),P.current=!1}),()=>e.abort()},[D]);let[F,I]=(0,q.useState)(null),[L,ee]=(0,q.useState)(null),[te,ne]=(0,q.useState)(!1);(0,q.useEffect)(()=>{if(!i)return;let e=U(a),n=setTimeout(()=>{n=null,h(!1),_(B.t(`setup:screen.errors.backendNotResponding`))},8e3),r=()=>{n&&=(clearTimeout(n),null)},o=e.on(`provider.catalog`,e=>{e.type===`provider.catalog`&&(r(),_(null),l(e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id))),h(!1))}),s=e.on(`provider.models`,e=>{if(e.type===`provider.models`){let n=e.payload;d(e=>({...e,[n.provider]:n.models})),ne(!1),n.models.length===1?ee(n.models[0].id):t&&n.models.some(e=>e.id===t)&&ee(t)}}),c=e.on(`providers.saved`,e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));p(t),S(new Set(t.filter(e=>e.apiKeys.some(e=>e.isActive)).map(e=>e.id)))}});return _(null),h(!0),e.listProviders(),()=>{r(),o?.(),s?.(),c?.()}},[i,a,t,v]);let re=(0,q.useCallback)(()=>{_(null),y(e=>e+1)},[]),ie=(0,q.useCallback)(()=>{O(e=>e+1),Sf(`providers_refresh_clicked`,`engagement`,{metadata:{currentProviderCount:C.length}})},[C.length]),ae=(0,q.useCallback)(t=>{let n=new Date().getTime()-t.getTime(),r=Math.floor(n/1e3);if(r<10)return e(`setup:screen.time.justNow`);if(r<60)return e(`setup:screen.time.secondsAgo`,{count:r});let i=Math.floor(r/60);if(i<60)return e(`setup:screen.time.minutesAgo`,{count:i});let a=Math.floor(i/60);return a<24?e(`setup:screen.time.hoursAgo`,{count:a}):e(`setup:screen.time.daysAgo`,{count:Math.floor(a/24)})},[e]),se=(0,q.useCallback)(e=>{S(t=>new Set([...t,e]))},[]),ce=x.size>0,le=(0,q.useCallback)(()=>{if(!ce){if(f.length>0){let e=f[0];I(e.id),s(`done`)}return}let e=f.find(e=>e.apiKeys.some(e=>e.isActive));e&&(I(e.id),s(`done`))},[ce,f]);(0,q.useEffect)(()=>{if(!F||!i||o!==`done`)return;let e=U(a);u[F]||(ne(!0),e.listProviderModels(F))},[F,i,a,u,o]);let ue=F?u[F]??[]:[],de=(0,q.useCallback)(()=>{if(!F||!L)return;n(F),r(L);let e=U(a);e.switchModel(F,L);let t=null,i=()=>{t&&clearTimeout(t)},o=e.on(`key.operation_result`,t=>{let n=t.payload;i(),o(),n.success?(e.newSession(),Q(`chat`)):Z.error(n.message)});t=setTimeout(()=>{i(),o(),Z.error(B.t(`setup:screen.errors.modelSwitchTimeout`))},5e3)},[F,L,n,r,a]),fe=new Set(C.map(e=>e.id)),pe=c.filter(e=>!fe.has(e.id)).sort((e,t)=>e.id.localeCompare(t.id));return(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Y.jsxs)(`header`,{className:`flex items-center justify-between px-6 py-4 border-b bg-card shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center`,children:(0,Y.jsx)(rt,{className:`h-5 w-5 text-primary-foreground`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:e(`setup:screen.header.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`setup:screen.header.subtitle`)})]})]}),ce&&(0,Y.jsxs)($,{onClick:le,size:`sm`,children:[e(`setup:screen.header.continue`),(0,Y.jsx)(A,{className:`h-4 w-4 ml-1.5`})]})]}),(0,Y.jsx)(ju,{className:`min-h-0 flex-1`,children:o===`keys`?(0,Y.jsxs)(`div`,{className:`p-6 max-w-3xl mx-auto space-y-8`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-primary font-medium`,children:[(0,Y.jsx)(Ve,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:e(`setup:screen.steps.addKeys`)})]}),(0,Y.jsx)(vn,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(wt,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:e(`setup:screen.steps.pickModel`)})]}),(0,Y.jsx)(vn,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(oe,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:e(`setup:screen.steps.start`)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl border border-primary/20 bg-primary/5 p-4`,children:[(0,Y.jsx)(Un,{className:`h-5 w-5 text-primary shrink-0 mt-0.5`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:e(`setup:screen.security.title`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`setup:screen.security.body`)})]})]}),g?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-4 py-12 rounded-xl border border-destructive/30 bg-destructive/5 px-6`,children:[(0,Y.jsx)(`div`,{className:`w-12 h-12 rounded-xl bg-destructive/10 border border-destructive/30 flex items-center justify-center`,children:(0,Y.jsx)(De,{className:`h-6 w-6 text-destructive`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-destructive`,children:e(`setup:screen.errors.backendUnreachable`)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 max-w-sm`,children:g})]}),(0,Y.jsxs)($,{onClick:re,size:`sm`,variant:`outline`,children:[(0,Y.jsx)(R,{className:`h-4 w-4 mr-2`}),e(`setup:screen.errors.retry`)]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground uppercase tracking-wider`,children:e(`setup:screen.providers.popular`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[T&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(R,{className:`h-3 w-3 animate-spin`}),e(`setup:screen.providers.updating`)]}),M&&!T&&(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,title:M.toLocaleString(),children:ae(M)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:ie,disabled:T,className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,title:e(`setup:screen.providers.refreshTitle`),children:[(0,Y.jsx)(b,{className:K(`h-3 w-3`,T&&`animate-spin`)}),e(`setup:screen.providers.refresh`)]})]})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:C.map(e=>(0,Y.jsx)(jf,{popular:e,catalogProvider:c.find(t=>t.id===e.id),savedProvider:f.find(t=>t.id===e.id),onKeySaved:se},e.id))})]}),pe.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground uppercase tracking-wider`,children:e(`setup:screen.providers.more`)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:pe.map(t=>(0,Y.jsx)(jf,{popular:{id:t.id,name:t.name,description:e(`setup:screen.providers.catalogDescription`,{family:t.family,count:t.modelCount}),icon:`🔗`,color:`from-slate-500/20 to-slate-500/5 border-slate-500/30 hover:border-slate-500/50`,keyPlaceholder:`API key`,family:t.family},catalogProvider:t,savedProvider:f.find(e=>e.id===t.id),onKeySaved:se},t.id))})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground uppercase tracking-wider`,children:e(`setup:screen.providers.selfHosted`)}),(0,Y.jsx)(Mf,{onKeySaved:se})]})]}),m&&(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Y.jsx)(R,{className:`h-6 w-6 animate-spin text-muted-foreground`})}),ce&&(0,Y.jsx)(`div`,{className:`sticky bottom-0 bg-background/80 backdrop-blur-sm py-4 -mx-6 px-6 border-t`,children:(0,Y.jsxs)($,{onClick:le,className:`w-full`,size:`lg`,children:[(0,Y.jsx)(wt,{className:`h-4 w-4 mr-2`}),e(`setup:screen.start.pickAndStart`),(0,Y.jsx)(A,{className:`h-4 w-4 ml-2`})]})})]}):(0,Y.jsxs)(`div`,{className:`p-6 max-w-2xl mx-auto space-y-8`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-emerald-500`,children:[(0,Y.jsx)(gt,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:e(`setup:screen.steps.keys`)})]}),(0,Y.jsx)(vn,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-primary font-medium`,children:[(0,Y.jsx)(wt,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:e(`setup:screen.steps.pickModel`)})]}),(0,Y.jsx)(vn,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(oe,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:e(`setup:screen.steps.start`)})]})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>s(`keys`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:e(`setup:screen.start.addMoreKeys`)}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(wt,{className:`h-4 w-4 text-primary`}),e(`setup:screen.start.chooseProvider`)]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-2`,children:f.map(t=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{I(t.id),ee(null)},className:K(`rounded-lg border p-3 text-left transition-all text-sm`,F===t.id?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border hover:border-primary/40 hover:bg-primary/5`),children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:t.id}),(0,Y.jsx)(`span`,{className:`block text-[11px] text-muted-foreground mt-0.5`,children:e(`setup:screen.start.activeKeys`,{count:t.apiKeys.filter(e=>e.isActive).length})})]},t.id))})]}),F&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(oe,{className:`h-4 w-4 text-primary`}),e(`setup:screen.start.chooseModel`)]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`setup:screen.start.modelsFor`,{provider:F})}),te?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Y.jsx)(R,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):ue.length>0?(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:ue.map(e=>{let t=e.contextWindow?`${(e.contextWindow/1e6).toFixed(0)}M ctx`:null;return(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ee(e.id),className:K(`w-full text-left rounded-xl border p-3 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,L===e.id?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[t&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:t}),e.capabilities.slice(0,3).map(e=>(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary border border-primary/20`,children:e},e))]})]}),L===e.id&&(0,Y.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,Y.jsx)(gt,{className:`h-3 h-3 text-primary-foreground`})})]})},e.id)})}):(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground py-8 text-center`,children:e(`setup:screen.errors.noModels`)})]}),F&&L&&(0,Y.jsxs)(`div`,{className:`sticky bottom-0 bg-background/80 backdrop-blur-sm py-4 -mx-6 px-6 border-t`,children:[(0,Y.jsx)(`div`,{className:`flex items-center justify-between text-sm text-muted-foreground mb-3`,children:(0,Y.jsxs)(`span`,{children:[F,` / `,L]})}),(0,Y.jsxs)($,{onClick:de,className:`w-full`,size:`lg`,children:[(0,Y.jsx)(wt,{className:`h-4 w-4 mr-2`}),e(`setup:screen.start.startSession`),(0,Y.jsx)(A,{className:`h-4 w-4 ml-2`})]})]})]})})]})}var Pf=[{sectionKey:`sectionGlobal`,items:[{keys:[`Ctrl`,`K`],descKey:`dCommandPalette`},{keys:[`?`],descKey:`dShowOverlay`},{keys:[`Ctrl`,`\\`],descKey:`dToggleSidebar`},{keys:[`Ctrl`,`1-8`],descKey:`dOpenPanel`},{keys:[`Ctrl`,`0`],descKey:`dDesignStudio`},{keys:[`Ctrl`,`Shift`,`W`],descKey:`dWorktrees`},{keys:[`Ctrl`,`/`],descKey:`dFocusInput`}]},{sectionKey:`sectionTuiParity`,items:[{keys:[`F1`],descKey:`dSessionPanel`},{keys:[`F2`],descKey:`dFleetOverlay`},{keys:[`F3`],descKey:`dAgentsOverlay`},{keys:[`F4`],descKey:`dWorktreeMonitor`},{keys:[`F5`],descKey:`dPlanPanel`},{keys:[`F6`],descKey:`dTodosPanel`},{keys:[`F7`],descKey:`dQueuePanel`},{keys:[`F8`],descKey:`dProcessMonitor`},{keys:[`F9`],descKey:`dGoalPanel`},{keys:[`F10`],descKey:`dSessionsDashboard`},{keys:[`F11`],descKey:`dOfficeMap`},{keys:[`F12`],descKey:`dDockPicker`}]},{sectionKey:`sectionFleet`,items:[{keys:[`Ctrl`,`Shift`,`M`],descKey:`dOpenFleet`},{keys:[`Ctrl`,`Shift`,`A`],descKey:`dOpenAgents`},{keys:[`↑`,`↓`],descKey:`dNavigateAgents`},{keys:[`Enter`],descKey:`dSelectAgent`},{keys:[`Esc`],descKey:`dCloseOverlay`}]},{sectionKey:`sectionChatInput`,items:[{keys:[`Enter`],descKey:`dSendMessage`},{keys:[`Shift`,`Enter`],descKey:`dNewline`},{keys:[`↑`],descKey:`dRecallPrev`},{keys:[`↓`],descKey:`dRecallNext`},{keys:[`/`],descKey:`dSlashPopup`},{keys:[`Tab`],descKey:`dAutocomplete`},{keys:[`Esc`],descKey:`dDismissPopup`}]},{sectionKey:`sectionChat`,items:[{keys:[`Ctrl`,`F`],descKey:`dSearchChat`},{keys:[`Ctrl`,`L`],descKey:`dClearContext`},{keys:[`Ctrl`,`N`],descKey:`dNewSession`},{keys:[`Ctrl`,`E`],descKey:`dExportMarkdown`},{keys:[`Ctrl`,`M`],descKey:`dModelSwitcher`},{keys:[`Ctrl`,`Shift`,`D`],descKey:`dCompactDensity`},{keys:[`Esc`],descKey:`dAbortRun`}]},{sectionKey:`sectionChatNav`,items:[{keys:[`j`],descKey:`dFocusNext`},{keys:[`k`],descKey:`dFocusPrev`},{keys:[`g`],descKey:`dJumpFirst`},{keys:[`Shift`,`G`],descKey:`dJumpLast`},{keys:[`c`],descKey:`dCopyFocused`},{keys:[`Esc`],descKey:`dClearFocused`}]}];function Ff(){let{t:e}=z(),t=G(e=>e.shortcutsOpen),n=G(e=>e.setShortcutsOpen);return(0,q.useEffect)(()=>{let e=e=>{let t=e.target,r=t?.tagName?.toLowerCase();!(r===`input`||r===`textarea`||t?.isContentEditable)&&e.key===`?`&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(e.preventDefault(),n(!G.getState().shortcutsOpen))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,Y.jsx)(Hc,{open:t,onOpenChange:e=>{e||n(!1)},children:(0,Y.jsxs)(Gc,{className:`max-w-2xl gap-0 p-0 overflow-hidden flex flex-col max-h-[80dvh]`,children:[(0,Y.jsx)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ct,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(Jc,{className:`text-sm font-semibold`,children:e(`activity:shortcuts.heading`)})]})}),(0,Y.jsx)(Yc,{className:`sr-only`,children:e(`activity:shortcuts.heading`)}),(0,Y.jsx)(`div`,{className:`overflow-y-auto px-5 py-4 space-y-6`,children:Pf.map(t=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-2`,children:e(`activity:shortcuts.${t.sectionKey}`)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-1.5`,children:t.items.map(t=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-sm px-2 py-1.5 rounded hover:bg-muted/40`,children:[(0,Y.jsx)(`span`,{className:`text-foreground/80`,children:e(`activity:shortcuts.${t.descKey}`)}),(0,Y.jsx)(`span`,{className:`flex items-center gap-1 shrink-0`,children:t.keys.map((e,t)=>(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[t>0&&(0,Y.jsx)(`span`,{className:`text-muted-foreground/40 text-xs`,children:`+`}),(0,Y.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1.5 py-0.5 bg-background`,children:e})]},e))})]},t.descKey))})]},t.sectionKey))}),(0,Y.jsxs)(`div`,{className:`border-t px-5 py-3 text-xs text-muted-foreground`,children:[e(`activity:shortcuts.footerPre`),` `,(0,Y.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1 py-0.5 bg-background`,children:`?`}),` `,e(`activity:shortcuts.footerPost`)]})]})})}function If({node:e,depth:t,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a,onContextMenu:o}){let{t:s}=z(),[c,l]=(0,q.useState)(t<1),u=Ir(e=>e.activeFilePath),d=e.type===`file`&&e.path===u;if((0,q.useEffect)(()=>{r!==null&&l(r)},[r]),e.type===`directory`){let u=(e.children?.length??0)>0,d=c?he:N,f=e.name===`.git`,p=Ec(e.name,!0);return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>l(e=>!e),onContextMenu:t=>o(t,e),className:K(`flex items-center gap-1 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`),style:{paddingLeft:`${t*14+4}px`},children:[(0,Y.jsx)(vn,{className:K(`h-3 w-3 shrink-0 text-muted-foreground transition-transform`,c&&`rotate-90`)}),f?(0,Y.jsx)(Le,{className:K(`h-3.5 w-3.5 shrink-0`,p)}):(0,Y.jsx)(d,{className:K(`h-3.5 w-3.5 shrink-0`,p)}),(0,Y.jsx)(`span`,{className:`truncate font-medium flex-1 min-w-0`,children:e.name})]}),c&&u&&(0,Y.jsx)(`div`,{children:(e.children??[]).map(e=>(0,Y.jsx)(If,{node:e,depth:t+1,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a,onContextMenu:o},e.path))}),c&&!u&&(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic py-0.5`,style:{paddingLeft:`${(t+1)*14+4}px`},children:s(`activity:fileExplorer.emptyDir`)})]})}let f=Dc(e.name),p=Ec(e.name,!1),m=e.path===n;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e.path),onContextMenu:t=>o(t,e),onDoubleClick:t=>{t.preventDefault(),a(e.path)},className:K(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`,d&&`bg-primary/10 text-primary`,m&&!d&&`bg-muted/70 ring-1 ring-inset ring-border`),style:{paddingLeft:`${t*14+4}px`},children:[(0,Y.jsx)(`span`,{className:`w-3 shrink-0`}),` `,(0,Y.jsx)(f,{className:K(`h-3.5 w-3.5 shrink-0`,p)}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.name})]})}function Lf(){let{t:e}=z(),t=Ir(e=>e.tree),n=Ir(e=>e.treeLoading),r=Ir(e=>e.error),i=Ir(e=>e.openFiles),a=Ir(e=>e.activeFilePath),o=W(e=>e.cwd),s=W(e=>e.projectName),c=o?.includes(`\\`)?`\\`:`/`,l=(e,t=8,n=4)=>e.length<=t+n+2?e:`${e.slice(0,t)}…${e.slice(-n)}`,u=(()=>{if(!o||!s)return!0;let e=o.replace(/\\/g,`/`).split(`/`).filter(Boolean);return(e[e.length-1]??``)===s})(),d=(0,q.useMemo)(()=>{if(!o||!s)return[];let e=o.replace(/\\/g,`/`).split(`/`).filter(Boolean),t=-1;for(let n=e.length-1;n>=0;n--)if(e[n]===s){t=n;break}if(t===-1)return e.map((t,n)=>({label:t,path:`/`+e.slice(0,n+1).join(`/`),isLast:n===e.length-1}));let n=e.slice(t);return n.map((r,i)=>({label:r,path:`/`+e.slice(0,t+i+1).join(`/`),isLast:i===n.length-1}))},[o,s]),f=(0,q.useRef)(null);(0,q.useEffect)(()=>{let e=f.current;e&&d.length>1&&(e.scrollLeft=e.scrollWidth)},[d]);let p=(0,q.useCallback)(e=>{U().send({type:`working_dir.set`,payload:{path:e}})},[]),[m,h]=(0,q.useState)(null),[g,_]=(0,q.useState)(null),v=(0,q.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),_({x:e.clientX,y:e.clientY,node:t})},[]),y=(0,q.useCallback)(e=>{e.type===`file`&&(Fr.getState().addRef({kind:`file`,path:e.path}),Q(`chat`)),_(null)},[]);(0,q.useEffect)(()=>{if(!m&&!g)return;let e=()=>{h(null),_(null)},t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`click`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`keydown`,t)}},[m,g]);let b=(0,q.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),h({x:e.clientX,y:e.clientY,crumb:t})},[]),x=(0,q.useCallback)(e=>{navigator.clipboard.writeText(e),h(null)},[]),S=(0,q.useCallback)(()=>{if(!a)return;let e=a.replace(/\\/g,`/`).split(`/`).slice(0,-1).join(`/`)||`.`;U().send({type:`working_dir.set`,payload:{path:e}})},[a]),C=(0,q.useCallback)((e,t)=>{U().send({type:`shell.open`,payload:{path:e,target:t}}),h(null)},[]),w=(0,q.useCallback)(()=>{if(!o)return;let e=o.replace(/\\/g,`/`),t=e.split(`/`).slice(0,-1).join(`/`)||e;U().send({type:`working_dir.set`,payload:{path:t}})},[o]),[T,E]=(0,q.useState)(!1),D=(0,q.useRef)(null);(0,q.useEffect)(()=>(n?D.current=setTimeout(()=>E(!0),150):(D.current&&clearTimeout(D.current),E(!1)),()=>{D.current&&clearTimeout(D.current)}),[n]);let[O,k]=(0,q.useState)(null),[A,j]=(0,q.useState)(null),M=(0,q.useMemo)(()=>{let e=0,n=t=>{for(let r of t)r.type===`directory`&&e++,r.children&&n(r.children)};return n(t),e},[t]),N=(0,q.useMemo)(()=>{let e=0,n=0;for(let r of t)r.type===`directory`?n++:e++;return{files:e,dirs:n}},[t]),P={value:!1},F=(0,q.useCallback)(()=>{P.value=!0,j(!1),setTimeout(()=>{P.value=!1},400)},[]),I=(0,q.useCallback)(()=>{P.value=!0,j(!0),setTimeout(()=>{P.value=!1},400)},[]),L=(0,q.useCallback)(e=>{if(i.find(t=>t.path===e)){Ir.getState().setActiveFile(e);return}k(t=>t===e?null:e)},[i]),ee=(0,q.useCallback)(e=>{window.dispatchEvent(new CustomEvent(`wrongstack:open-file`,{detail:{filePath:e}})),k(null)},[]);return(0,q.useEffect)(()=>{a&&k(null)},[a]),T?(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full py-8`,children:(0,Y.jsx)(R,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):r?(0,Y.jsx)(`div`,{className:`p-3 text-[11px] text-destructive`,children:e(`activity:fileExplorer.loadFailed`,{error:r})}):(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col overflow-hidden`,children:[t.length>0&&M>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-0.5 border-b shrink-0`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:I,className:K(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:e(`activity:fileExplorer.expandAllTitle`),children:[(0,Y.jsx)(Ae,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e(`activity:fileExplorer.expandAll`)})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:F,className:K(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:e(`activity:fileExplorer.collapseAllTitle`),children:[(0,Y.jsx)(wn,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e(`activity:fileExplorer.collapse`)})]}),(0,Y.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground/50 tabular-nums`,children:e(`activity:fileExplorer.folders`,{count:M})})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto py-1`,children:[d.length>0&&(0,Y.jsxs)(`div`,{ref:f,className:`relative flex items-center gap-0.5 px-1 pb-1 border-b border-border/30 overflow-x-auto`,children:[(0,Y.jsx)(`span`,{className:`sticky left-0 shrink-0 w-3 h-full bg-gradient-to-r from-background to-transparent pointer-events-none`}),d.map((t,n)=>{let r=t.isLast?t.label:l(t.label),i=t.path.replace(/\//g,c),a=o?o.replace(/\\/g,`/`).split(`/`).filter(Boolean):[],u=(()=>{for(let e=a.length-1;e>=0;e--)if(a[e]===s)return e;return-1})(),d=u>=0?a.slice(0,u+n+1):a.slice(0,n+1),f=c===`\\`?d.join(`\\`):`/`+d.join(`/`),m=(u>=0?a.slice(u+1,u+n+1):[]).join(c)||`.`;return(0,Y.jsxs)(`span`,{className:`flex items-center gap-0.5 shrink-0`,children:[n>0&&(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground/40 select-none`,children:c}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>p(t.path),onContextMenu:e=>b(e,{absPath:f,relPath:m}),className:K(`px-1 py-0.5 rounded text-[11px] transition-colors whitespace-nowrap`,t.isLast?`text-foreground font-medium`:`text-muted-foreground hover:text-foreground hover:bg-muted/60`),title:t.isLast?e(`activity:fileExplorer.currentDirTitle`,{path:i}):e(`activity:fileExplorer.navigateToTitle`,{path:i}),children:r})]},t.path)}),t.length>0&&(0,Y.jsxs)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground/50 tabular-nums pl-2`,children:[N.files>0&&e(`activity:fileExplorer.filesSuffix`,{count:N.files}),N.files>0&&N.dirs>0&&`, `,N.dirs>0&&e(`activity:fileExplorer.folders`,{count:N.dirs})]})]}),a&&(0,Y.jsxs)(`button`,{type:`button`,onClick:S,className:`flex items-center gap-1 w-full text-left px-2 py-0.5 border-b border-border/30 text-[10px] text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors`,title:e(`activity:fileExplorer.navigateParentTitle`,{path:a.replace(/\//g,c)}),children:[(0,Y.jsx)(V,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:(()=>{let e=a.replace(/\\/g,`/`).split(`/`);return e[e.length-1]??a})()}),(0,Y.jsx)(`span`,{className:`ml-auto text-[8px] text-muted-foreground/40 shrink-0`,children:e(`activity:fileExplorer.goToDir`)})]}),d.length===0&&!u&&(0,Y.jsxs)(`button`,{type:`button`,onClick:w,className:K(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors text-muted-foreground hover:text-foreground`,`font-medium`),children:[(0,Y.jsx)(Kt,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{children:`..`}),(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground/50 ml-auto`,children:e(`activity:fileExplorer.parentDirectory`)})]}),t.map(e=>(0,Y.jsx)(If,{node:e,depth:0,selectedPath:O,forceExpand:A,onSelect:L,onOpen:ee,onContextMenu:v},e.path)),t.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic p-2`,children:e(`activity:fileExplorer.noFiles`)})]}),m&&(0,Y.jsxs)(`div`,{className:`fixed z-50 min-w-[140px] bg-popover border rounded-md shadow-md py-1 text-[11px]`,style:{left:m.x,top:m.y},children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>x(m.crumb.absPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:e(`activity:fileExplorer.copyAbsPath`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>x(m.crumb.relPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:e(`activity:fileExplorer.copyRelPath`)}),(0,Y.jsx)(`div`,{className:`border-t border-border/50 my-0.5`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>C(m.crumb.absPath,`terminal`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:e(`activity:fileExplorer.openInTerminal`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>C(m.crumb.absPath,`file-manager`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:e(`activity:fileExplorer.openInFileManager`)}),(0,Y.jsx)(`div`,{className:`border-t border-border/50 mt-0.5 pt-0.5`,children:(0,Y.jsx)(`div`,{className:`px-3 py-1 text-[9px] text-muted-foreground/50 truncate max-w-[200px]`,children:m.crumb.absPath})})]}),g&&(0,Y.jsxs)(`div`,{className:`fixed z-50 min-w-[160px] bg-popover border rounded-md shadow-md py-1 text-[11px]`,style:{left:g.x,top:g.y},children:[g.node.type===`file`&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(g.node),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:e(`activity:fileExplorer.mentionInChat`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{navigator.clipboard.writeText(g.node.path),_(null)},className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:e(`activity:fileExplorer.copyPath`)}),(0,Y.jsx)(`div`,{className:`border-t border-border/50 mt-0.5 pt-0.5`,children:(0,Y.jsx)(`div`,{className:`px-3 py-1 text-[9px] text-muted-foreground/50 truncate max-w-[200px]`,children:g.node.path})})]})]})}var Rf={note:qe,ask:jt,assign:Zt,steer:P,btw:He,broadcast:Zt,status:rn,result:jn};function zf(e){let t=new Date(e),n=Date.now()-t.getTime();return n<6e4?B.t(`activity:mailbox.timeNow`):n<36e5?`${Math.round(n/6e4)}m`:n<864e5?`${Math.round(n/36e5)}h`:t.toLocaleDateString()}function Bf({className:e}){let t=yi(e=>e.messages),n=yi(e=>e.agents),[r,i]=(0,q.useState)(!1),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),{client:l}=ts(),{t:u}=z(),[d,f]=(0,q.useState)(l.status.state===`open`);(0,q.useEffect)(()=>{let e=l.onStatus(e=>f(e.state===`open`));return()=>e()},[l]),(0,q.useEffect)(()=>{d&&(l.send({type:`mailbox.messages`,payload:{limit:30}}),l.send({type:`mailbox.agents`,payload:{}}))},[d,l]);let p=G(e=>e.selectedMailMessage),m=G(e=>e.setSelectedMailMessage);function h(e){if(p?.id===e.id){m(null),Q(`chat`);return}m(e),Q(`mailbox`)}let g=t.filter(e=>!e.completed).length,_=n.filter(e=>e.online).length;async function v(){t.length!==0&&await wu({title:u(`activity:mailbox.deleteAllConfirmTitle`,{count:t.length}),message:u(`activity:mailbox.deleteAllConfirmBody`),confirmLabel:u(`activity:mailbox.deleteAll`),danger:!0})&&(o(!0),l.send({type:`mailbox.clear`}))}(0,q.useEffect)(()=>{a&&t.length===0&&o(!1)},[a,t.length]);async function y(){await wu({title:u(`activity:mailbox.purgeConfirmTitle`),message:u(`activity:mailbox.purgeConfirmBody`),confirmLabel:u(`activity:mailbox.purge`),danger:!1})&&(c(!0),l.send({type:`mailbox.purge`}))}return(0,q.useEffect)(()=>{if(s){let e=setTimeout(()=>c(!1),3e3);return()=>clearTimeout(e)}},[s]),(0,Y.jsxs)(`div`,{className:K(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,e),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,Y.jsx)(Et,{className:`h-4 w-4 text-cyan-500`}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:u(`activity:nav.mailbox`)}),g>0&&(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-bold bg-yellow-100 dark:bg-yellow-900/40 text-yellow-700 dark:text-yellow-400`,children:g}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:u(`activity:mailbox.onlineCount`,{count:_})})]}),!r&&(0,Y.jsxs)(`div`,{className:`px-3 pb-3 space-y-2`,children:[t.length>0?(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide`,children:u(`activity:mailbox.messages`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:v,disabled:a,className:`flex items-center gap-1 text-[10px] text-muted-foreground hover:text-red-500 disabled:opacity-40 transition-colors`,title:u(`activity:mailbox.deleteAllTitle`),children:[(0,Y.jsx)(At,{className:`h-3 w-3`}),u(a?`activity:mailbox.deleting`:`activity:mailbox.deleteAll`)]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:y,disabled:s,className:`flex items-center gap-1 text-[10px] text-muted-foreground hover:text-cyan-500 disabled:opacity-40 transition-colors`,title:u(`activity:mailbox.purgeTitle`),children:[(0,Y.jsx)(oe,{className:`h-3 w-3`}),u(s?`activity:mailbox.purging`:`activity:mailbox.purge`)]})]}),t.slice(0,8).map(e=>{let t=Rf[e.type]??Gt,n=e.readByCount>0,r=p?.id===e.id;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>h(e),className:K(`flex items-start gap-2 px-2 py-1.5 rounded text-xs w-full text-left cursor-pointer transition-colors hover:bg-accent/60`,!n&&`bg-yellow-50 dark:bg-yellow-950/20`,r&&`ring-1 ring-primary bg-primary/5`),children:[(0,Y.jsx)(t,{className:K(`h-3.5 w-3.5 mt-0.5 shrink-0`,n?`text-muted-foreground`:`text-yellow-600`)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:K(`font-medium truncate`,!n&&`text-yellow-800 dark:text-yellow-300`),children:e.from}),e.completed&&(0,Y.jsx)(jn,{className:`h-3 w-3 text-green-500 shrink-0`}),!n&&(0,Y.jsx)(`span`,{className:`text-[9px] text-yellow-600 font-bold`,children:u(`activity:mailbox.newLabel`)})]}),(0,Y.jsx)(`div`,{className:`text-muted-foreground truncate`,children:e.subject}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:[e.body.slice(0,60),e.body.length>60?`…`:``]})]}),(0,Y.jsxs)(`div`,{className:`shrink-0 text-[10px] text-muted-foreground flex flex-col items-end gap-0.5`,children:[(0,Y.jsx)(`span`,{children:zf(e.timestamp)}),n&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Y.jsx)(An,{className:`h-3 w-3`}),e.readByCount]})]})]},e.id)})]}):(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground py-2 text-center`,children:[(0,Y.jsx)(nn,{className:`h-4 w-4 mx-auto mb-1 opacity-40`}),u(`activity:mailbox.empty`)]}),n.length>0&&(0,Y.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,Y.jsxs)(`div`,{className:`text-[10px] font-semibold text-muted-foreground mb-1 flex items-center gap-1`,children:[(0,Y.jsx)(En,{className:`h-3 w-3`}),` `,u(`activity:nav.agents`)]}),n.filter(e=>e.online).slice(0,5).map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground py-0.5`,children:[(0,Y.jsx)(`span`,{className:K(`h-1.5 w-1.5 rounded-full`,e.online?`bg-green-500`:`bg-muted-foreground/30`)}),(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e.name}),e.role&&(0,Y.jsxs)(`span`,{className:`opacity-60`,children:[`(`,e.role,`)`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:e.status}),e.currentTool&&(0,Y.jsx)(`span`,{className:`text-cyan-500`,children:e.currentTool}),(0,Y.jsx)(`span`,{className:`ml-auto opacity-50`,children:zf(e.lastSeenAt)})]},e.agentId)),n.filter(e=>!e.online).length>0&&(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground/50 mt-0.5`,children:u(`activity:mailbox.offlineCount`,{count:n.filter(e=>!e.online).length})})]})]})]})}var Vf={running:{led:`text-[hsl(var(--success))]`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,pulse:!1},failed:{led:`text-destructive`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,pulse:!1},stopped:{led:`text-muted-foreground`,pulse:!1}};function Hf({agent:e,onClose:t}){let n=Vf[e.status],{t:r}=z(),i=e.status===`running`,a=e.currentTool??e.lastTool,o=Date.now()-e.startedAt,[s,c]=(0,q.useState)(!1),l=X(e=>e.leaderId),u=e.id===l,d=X(t=>t.agentTranscripts.get(e.id)??Xr),f=Math.min(100,Math.max(0,e.ctxPct)),p=(0,q.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),2e3)}catch{}},[]),m=f>=85?`bg-red-500/15 text-red-600 dark:text-red-400`:f>=70?`bg-amber-500/15 text-amber-600 dark:text-amber-400`:`bg-muted text-muted-foreground`;return(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10dvh] bg-black/40 backdrop-blur-sm`,children:(0,Y.jsxs)(`div`,{className:`w-full max-w-xl max-h-[80dvh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,Y.jsxs)(`div`,{className:K(`flex items-center justify-between px-4 py-3 border-b`,i?`border-primary/20`:`border-border`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:K(`led`,n.led,n.pulse&&`led-pulse`)}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),u&&(0,Y.jsx)(Nn,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`,"aria-label":r(`activity:fleet.leader`)}),(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:r(`activity:fleet.status.${e.status}`)})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,Y.jsx)(ut,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-4`,children:[e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed`,children:e.description}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:fleet.providerModel`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,Y.jsx)(Tn,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsxs)(`span`,{className:`text-xs font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:fleet.elapsed`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,Y.jsx)(kn,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-mono tabular`,children:Ku(o)}),i&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-[hsl(var(--success))]`,children:[`· `,r(`activity:fleet.running`)]})]})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:fleet.iterations`)}),(0,Y.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.iteration})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:fleet.toolCalls`)}),(0,Y.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.toolCalls})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:fleet.cost`)}),(0,Y.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:Wu(e.costUsd)})]}),e.extensions>0&&(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:fleet.budgetExtensions`)}),(0,Y.jsxs)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:[`⚡×`,e.extensions]})]})]}),i&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`activity:fleet.activity`)}),(0,Y.jsx)(Ts,{bins:e.sparklineBins,className:`font-mono`})]}),e.budgetWarning&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,Y.jsx)(rt,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r(`activity:fleet.budgetWarning`,{kind:e.budgetWarning.kind,used:e.budgetWarning.used,limit:e.budgetWarning.limit})})]}),e.maxContext>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:r(`activity:fleet.contextWindow`)}),(0,Y.jsxs)(`span`,{className:K(`tabular font-medium`,m.replace(/bg-\S+\s*/g,``)),children:[f,`%`]})]}),(0,Y.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,Y.jsx)(`div`,{className:K(`h-full rounded-full transition-all`,f>=85?`bg-destructive`:f>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.max(2,f)}%`}})}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground tabular text-right`,children:r(`activity:fleet.tokensUsed`,{used:Gu(e.ctxTokens),max:Gu(e.maxContext)})})]}),a&&(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-2 rounded-lg border px-3 py-2`,i?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,Y.jsx)(Ne,{className:K(`h-3.5 w-3.5`,i?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,Y.jsx)(`span`,{className:`text-xs font-mono`,children:a}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?r(`activity:fleet.toolRunning`):r(`activity:fleet.lastTool`)})]}),(0,Y.jsx)(xs,{entries:d,agentName:e.name,compact:!0,maxHeightClassName:`max-h-80`}),e.error&&(0,Y.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:r(`activity:fleet.error`)}),(0,Y.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1 leading-relaxed`,children:e.error.message})]}),e.finalText?(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:r(`activity:fleet.finalOutput`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p(e.finalText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:r(`activity:fleet.copyOutput`),children:[s?(0,Y.jsx)(gt,{className:`h-3 w-3 text-emerald-500`}):(0,Y.jsx)(bt,{className:`h-3 w-3`}),r(s?`common:action.copied`:`common:action.copy`)]})]}),(0,Y.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:e.finalText})]}):e.partialText?(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:r(`activity:fleet.liveOutput`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p(e.partialText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:r(`activity:fleet.copyOutput`),children:[s?(0,Y.jsx)(gt,{className:`h-3 w-3 text-emerald-500`}):(0,Y.jsx)(bt,{className:`h-3 w-3`}),r(s?`common:action.copied`:`common:action.copy`)]})]}),(0,Y.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-48 overflow-y-auto`,children:e.partialText})]}):i?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-3 text-center`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`activity:fleet.waitingOutput`)}),(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:r(`activity:fleet.outputHint`)})]}):null,e.toolLog.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:r(`activity:fleet.toolLog`,{count:e.toolLog.length})}),(0,Y.jsxs)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5`,children:[e.toolLog.slice(0,15).map((e,t)=>(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-2 rounded px-2 py-1 text-[10px]`,e.ok?`bg-muted/30`:`bg-destructive/5 border border-destructive/20`),children:[(0,Y.jsx)(`span`,{className:K(`led shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`)}),(0,Y.jsx)(`span`,{className:`font-mono truncate flex-1`,children:e.name}),(0,Y.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,Y.jsx)(`span`,{className:`text-destructive font-medium`,children:r(`activity:fleet.fail`)})]},`${e.name}-${e.at}-${t}`)),e.toolLog.length>15&&(0,Y.jsx)(`p`,{className:`text-[9px] text-muted-foreground text-center px-2 py-0.5`,children:r(`activity:fleet.moreTools`,{count:e.toolLog.length-15})})]})]})]})]})})}function Uf({a:e,onClick:t}){let n=Vf[e.status],{t:r}=z(),i=e.status===`running`,a=e.currentTool??e.lastTool,o=Math.min(100,Math.max(0,e.ctxPct));return(0,Y.jsxs)(`button`,{type:`button`,onClick:t,className:K(`flex min-w-[12rem] max-w-[15rem] flex-col gap-1 rounded-lg border p-2 transition-colors text-left cursor-pointer`,`hover:border-primary/40 hover:bg-primary/[0.06]`,i?`border-primary/30 bg-primary/[0.04]`:`border-border bg-card opacity-85`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Y.jsx)(`span`,{className:K(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,Y.jsx)(`span`,{className:`truncate text-[11px] font-semibold text-foreground`,title:e.name,children:e.name}),(0,Y.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it · `,e.toolCalls,`t`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[e.model&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-0.5 text-[10px] text-muted-foreground truncate`,title:`${e.provider??``}/${e.model}`,children:[(0,Y.jsx)(Tn,{className:`h-2.5 w-2.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:e.model})]}),(0,Y.jsx)(`span`,{className:`tabular text-[10px] text-foreground/75 ml-auto`,children:Wu(e.costUsd)})]}),a&&(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-1 text-[10px] truncate`,i?`text-primary`:`text-muted-foreground`),title:e.currentTool?r(`activity:fleet.cardRunning`,{tool:a}):r(`activity:fleet.cardLastTool`,{tool:a}),children:[(0,Y.jsx)(Ne,{className:K(`h-2.5 w-2.5 shrink-0`,i&&`animate-pulse`)}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:a})]}),i&&e.maxContext>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,title:r(`activity:fleet.contextPercent`,{pct:o}),children:[(0,Y.jsx)(`div`,{className:`h-1 flex-1 overflow-hidden rounded-full bg-muted`,children:(0,Y.jsx)(`div`,{className:K(`h-full rounded-full transition-all`,o>=85?`bg-destructive`:o>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.max(2,o)}%`}})}),(0,Y.jsx)(`span`,{className:`tabular text-[9px] text-muted-foreground`,children:e.maxContext>0?`${o}%`:`—`})]}),e.error&&(0,Y.jsx)(`div`,{className:`truncate rounded bg-destructive/10 px-1 py-0.5 text-[9px] text-destructive`,title:e.error.message,children:e.error.message})]})}function Wf({className:e}){let t=X(e=>e.agents),{t:n}=z(),[r,i]=(0,q.useState)(!0),[a,o]=(0,q.useState)(null),s=(0,q.useMemo)(()=>{let e=Array.from(t.values());return e.sort(Hu),e},[t]),c=a?s.find(e=>e.id===a):null;if(s.length===0)return null;let l=Uu(s),u=s.reduce((e,t)=>e+(t.costUsd??0),0),d=r&&s.length>=3;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:K(`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,e),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-muted/30 transition-colors`,children:[(0,Y.jsx)(wt,{className:`h-3.5 w-3.5 text-primary`}),(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground`,children:`Fleet`}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 ml-auto text-[10px]`,children:[l.running>0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-[hsl(var(--success))]`,children:[(0,Y.jsx)(`span`,{className:`led led-pulse text-[hsl(var(--success))]`}),l.running]}),l.completed>0&&(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:fleet.doneCount`,{count:l.completed})}),l.failed>0&&(0,Y.jsx)(`span`,{className:`text-destructive`,children:n(`activity:fleet.errCount`,{count:l.failed})}),u>0&&(0,Y.jsx)(`span`,{className:`tabular text-foreground/70`,children:Wu(u)})]}),d?(0,Y.jsx)(vn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Y.jsx)(Bt,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!d&&(0,Y.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-2 pb-2`,children:s.map(e=>(0,Y.jsx)(Uf,{a:e,onClick:()=>o(e.id)},e.id))})]}),c&&(0,Y.jsx)(Hf,{agent:c,onClose:()=>o(null)})]})}var Gf={running:{led:`text-[hsl(var(--success))]`,label:`running`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,label:`done`,pulse:!1},failed:{led:`text-destructive`,label:`failed`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,label:`timeout`,pulse:!1},stopped:{led:`text-muted-foreground`,label:`stopped`,pulse:!1}};function Kf(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function qf({agent:e,onClick:t}){let n=Gf[e.status],{t:r}=z(),i=e.status===`running`;return(0,Y.jsxs)(`button`,{type:`button`,onClick:t,className:K(`w-full text-left rounded-lg border px-2.5 py-2 transition-colors`,`hover:border-primary/40 hover:bg-primary/[0.04]`,i?`border-primary/30 bg-primary/[0.03]`:`border-border/60 bg-card/40`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Y.jsx)(`span`,{className:K(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,Y.jsx)(`span`,{className:`truncate text-[11px] font-semibold`,title:e.name,children:e.name}),(0,Y.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5 min-w-0`,children:[e.model?(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate font-mono`,children:e.model}):(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:r(`activity:agents.pending`)}),(0,Y.jsx)(`span`,{className:`tabular ml-auto text-[10px] text-foreground/70`,children:Kf(e.costUsd)})]}),(e.currentTool||e.lastTool)&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-1 text-[10px] text-muted-foreground truncate`,children:[(0,Y.jsx)(Ne,{className:K(`h-2.5 w-2.5 shrink-0`,i&&`animate-pulse text-primary`)}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool??e.lastTool})]})]})}function Jf(){let e=X(e=>e.agents),{t}=z(),[n,r]=(0,q.useState)(null),i=(0,q.useMemo)(()=>{let t=Array.from(e.values());return t.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),t},[e]),a=i.filter(e=>e.status===`running`).length,o=n?i.find(e=>e.id===n)??null:null;return i.length===0?(0,Y.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-4`,children:(0,Y.jsxs)(`div`,{className:`text-center text-muted-foreground`,children:[(0,Y.jsx)(wt,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:t(`activity:agents.empty`)}),(0,Y.jsx)(`p`,{className:`text-xs mt-1`,children:t(`activity:agents.emptyHint`)})]})}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`px-3 py-2 border-b text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-semibold uppercase tracking-wider`,children:`Fleet`}),(0,Y.jsxs)(`span`,{className:`ml-auto tabular-nums`,children:[a>0?(0,Y.jsxs)(Y.Fragment,{children:[t(`activity:agents.runningCount`,{count:a}),` · `]}):null,t(`activity:agents.totalCount`,{count:i.length})]})]}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto p-2 space-y-1.5`,children:i.map(e=>(0,Y.jsx)(qf,{agent:e,onClick:()=>r(e.id)},e.id))}),(0,Y.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>G.getState().setAgentsMonitorOpen(!0),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,Y.jsx)(qn,{className:`h-3 w-3`}),t(`activity:agents.openFull`)]})}),o&&(0,Y.jsx)(Hf,{agent:o,onClose:()=>r(null)})]})}var Yf={M:{label:`M`,cls:`text-amber-600 dark:text-amber-400`},A:{label:`A`,cls:`text-emerald-600 dark:text-emerald-400`},D:{label:`D`,cls:`text-rose-600 dark:text-rose-400`},R:{label:`R`,cls:`text-sky-600 dark:text-sky-400`},C:{label:`C`,cls:`text-sky-600 dark:text-sky-400`},U:{label:`U`,cls:`text-orange-600 dark:text-orange-400`},"?":{label:`U`,cls:`text-muted-foreground`}};function Xf(e){let t=e.lastIndexOf(`/`);return t<0?{name:e,dir:``}:{name:e.slice(t+1),dir:e.slice(0,t+1)}}function Zf({file:e,active:t,onSelect:n}){let r=Yf[e.status]??Yf.M,{name:i,dir:a}=Xf(e.path);return(0,Y.jsxs)(`button`,{type:`button`,onClick:n,title:e.path,className:K(`group flex items-center gap-2 w-full px-2 py-1 text-left text-xs rounded hover:bg-accent/60`,t&&`bg-accent`),children:[(0,Y.jsx)(`span`,{className:K(`w-3 shrink-0 text-center font-mono font-bold`,r?.cls),children:r?.label}),(0,Y.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[(0,Y.jsx)(`span`,{className:K(e.status===`D`&&`line-through opacity-70`),children:i}),a&&(0,Y.jsx)(`span`,{className:`text-muted-foreground/60 ml-1 truncate`,children:a})]}),(0,Y.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] tabular-nums`,children:[e.added>0&&(0,Y.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,e.added]}),e.deleted>0&&(0,Y.jsxs)(`span`,{className:`text-rose-600 dark:text-rose-400 ml-1`,children:[`-`,e.deleted]})]})]})}function Qf(){let{client:e}=ts(),{t}=z(),n=J(e=>e.wsConnected),r=oi(e=>e.files),i=oi(e=>e.error),a=oi(e=>e.loadingList),o=oi(e=>e.selectedPath),s=(0,q.useCallback)(()=>{n&&(oi.getState().setListLoading(!0),e?.getGitChanges?.())},[e,n]);(0,q.useEffect)(()=>{s()},[s]);let c=t=>{oi.getState().select(t),e?.getGitDiff?.(t),Q(`changes`)},l=r.reduce((e,t)=>e+t.added,0),u=r.reduce((e,t)=>e+t.deleted,0);return(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b shrink-0`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground font-mono`,children:[t(`activity:changes.fileCount`,{count:r.length}),r.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[` · `,(0,Y.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,l]}),` `,(0,Y.jsxs)(`span`,{className:`text-rose-600 dark:text-rose-400`,children:[`-`,u]})]})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:s,title:t(`activity:changes.refreshTitle`),className:`h-6 w-6 inline-flex items-center justify-center rounded hover:bg-accent text-muted-foreground`,children:a?(0,Y.jsx)(R,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(b,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto p-1.5`,children:i?(0,Y.jsx)(`div`,{className:`px-2 py-6 text-center text-xs text-muted-foreground`,children:i}):r.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,Y.jsx)(h,{className:`h-6 w-6 opacity-40`}),t(a?`activity:changes.loading`:`activity:changes.clean`)]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:r.map(e=>(0,Y.jsx)(Zf,{file:e,active:e.path===o,onSelect:()=>c(e.path)},e.path))})})]})}var $f=e=>{let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Date.now()-t;if(n<6e4)return B.t(`common:time.justNow`);if(n<36e5)return B.t(`common:time.minutesAgo`,{count:Math.floor(n/6e4)});if(n<864e5)return B.t(`common:time.hoursAgo`,{count:Math.floor(n/36e5)});let r=Math.floor(n/864e5);return r<7?B.t(`common:time.daysAgo`,{count:r}):new Date(t).toLocaleDateString()};function ep(e){return e.filter(e=>e.tokenTotal===0&&!e.isCurrent).map(e=>e.id)}function tp({historyQuery:e,setHistoryQuery:t,historyEntries:n,historyLoading:r,historyError:i,wsConnected:a,listSessions:o,resumeSession:s,deleteSession:c,renameSession:l}){let u=G(e=>e.favoriteSessionIds),{t:d}=z(),f=G(e=>e.toggleFavoriteSession),p=G(e=>e.sessionNicknames),m=G(e=>e.setSessionNickname),[h,g]=(0,q.useState)(null),[_,v]=(0,q.useState)(``),y=(0,q.useCallback)((e,t)=>{g(null),m(e,t),l(e,t)},[l,m]),[x,S]=(0,q.useState)(null);(0,q.useEffect)(()=>{x&&n.some(e=>e.id===x&&e.isCurrent)&&S(null)},[x,n]);let C=(0,q.useCallback)(e=>{S(e),s(e),setTimeout(()=>S(t=>t===e?null:t),1e4)},[s]),w=(0,q.useMemo)(()=>ep(n),[n]),T=(0,q.useCallback)(async()=>{if(w.length!==0&&await wu({title:d(`activity:sessions.deleteEmptyTitle`,{count:w.length}),message:d(`activity:sessions.deleteEmptyConfirmBody`),confirmLabel:d(`common:action.delete`),danger:!0}))for(let e of w)c(e)},[w,c]),E=(()=>{let t=e.trim().toLowerCase(),r=t?n.filter(e=>(e.name?.toLowerCase().includes(t)??!1)||e.title.toLowerCase().includes(t)||e.model.toLowerCase().includes(t)||e.provider.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)):n,i=new Date;i.setHours(0,0,0,0);let a=i.getTime(),o=a-864e5,s=a-6*864e5,c={today:[],yesterday:[],week:[],older:[]};for(let e of r){let t=Date.parse(e.startedAt);if(Number.isNaN(t)){c.older.push(e);continue}t>=a?c.today.push(e):t>=o?c.yesterday.push(e):t>=s?c.week.push(e):c.older.push(e)}let l=new Set(u),d=r.filter(e=>l.has(e.id)),f=[];d.length&&f.push({label:`favorites`,rows:d,star:!0});let p=e=>e.filter(e=>!l.has(e.id)),m=p(c.today),h=p(c.yesterday),g=p(c.week),_=p(c.older);return m.length&&f.push({label:`today`,rows:m}),h.length&&f.push({label:`yesterday`,rows:h}),g.length&&f.push({label:`thisWeek`,rows:g}),_.length&&f.push({label:`earlier`,rows:_}),f})();return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b`,children:[(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground`,children:d(`activity:sessions.recentSessions`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[w.length>0&&(0,Y.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted text-muted-foreground hover:text-destructive`,onClick:T,disabled:!a,title:d(`activity:sessions.deleteEmptyTitle`,{count:w.length}),children:(0,Y.jsx)(At,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted`,onClick:()=>o(50),disabled:!a,title:d(`common:action.refresh`),children:r?(0,Y.jsx)(R,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(b,{className:`h-3.5 w-3.5`})})]})]}),n.length>3&&(0,Y.jsx)(`div`,{className:`px-3 py-2 border-b`,children:(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(xe,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground/60`}),(0,Y.jsx)(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:d(`activity:sessions.filterPlaceholder`),className:`w-full pl-7 pr-7 py-1 text-xs rounded-md bg-muted/40 border border-transparent focus:bg-background focus:border-input focus:outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50`}),e&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>t(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-muted-foreground/60 hover:text-foreground p-0.5`,title:d(`activity:sessions.clearFilter`),children:(0,Y.jsx)(ut,{className:`h-3 w-3`})})]})}),i&&(0,Y.jsx)(`div`,{className:`px-4 py-2 text-xs text-destructive bg-destructive/5 border-b`,children:i}),(0,Y.jsx)(ju,{className:`flex-1`,children:n.length===0&&!r?(0,Y.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,Y.jsx)(Ge,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:d(`activity:sessions.noHistory`)}),(0,Y.jsx)(`p`,{className:`text-xs mt-1`,children:d(`activity:sessions.noHistoryHint`)})]}):E.length===0?(0,Y.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,Y.jsx)(xe,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:d(`activity:sessions.noMatches`)}),(0,Y.jsx)(`p`,{className:`text-xs mt-1`,children:d(`activity:sessions.noMatchesHint`)})]}):(0,Y.jsx)(`div`,{className:`p-2 space-y-3`,children:E.map(e=>(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:K(`sticky top-0 z-[1] px-1 pb-1 text-[10px] uppercase tracking-wider font-semibold bg-card/90 backdrop-blur-sm flex items-center gap-1`,e.star?`text-amber-500`:`text-muted-foreground/80`),children:[e.star&&(0,Y.jsx)(Yn,{className:`h-3 w-3 fill-current`}),d(`activity:sessions.group.${e.label}`),` `,(0,Y.jsxs)(`span`,{className:`text-muted-foreground/50 font-normal normal-case ml-1`,children:[`(`,e.rows.length,`)`]})]}),e.rows.map(e=>(0,Y.jsxs)(`div`,{className:K(`group relative rounded-md border text-sm transition-colors`,e.isCurrent?`bg-primary/5 border-primary/40`:`bg-card border-border/60 hover:bg-muted/40 hover:border-primary/40`),children:[(0,Y.jsx)(`button`,{type:`button`,disabled:e.isCurrent||h===e.id||x!==null,onClick:()=>C(e.id),onDoubleClick:t=>{t.stopPropagation(),g(e.id),v(p[e.id]??e.name??e.title??``)},className:`block w-full rounded-md px-3 py-2 pr-16 text-left disabled:cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[h===e.id?(0,Y.jsx)(`input`,{value:_,onChange:e=>v(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>y(e.id,_),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),y(e.id,_)):t.key===`Escape`&&(t.preventDefault(),g(null))},placeholder:e.title||d(`activity:sessions.nicknamePlaceholder`),className:`w-full text-sm bg-background border border-input rounded px-1.5 py-0.5 focus:outline-none focus:ring-1 focus:ring-ring`}):(0,Y.jsx)(`div`,{className:`font-medium truncate text-foreground`,title:p[e.id]??e.name??e.title?d(`activity:sessions.renameTitleNickname`,{nickname:p[e.id]??e.name??e.title,title:e.title}):d(`activity:sessions.renameTitle`,{title:e.title}),children:p[e.id]||e.name||e.title||d(`activity:sessions.empty`)}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground/80 mt-0.5`,children:[x===e.id?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-primary font-medium`,children:[(0,Y.jsx)(R,{className:`h-3 w-3 animate-spin`}),d(`activity:sessions.resuming`)]}):(0,Y.jsx)(`span`,{children:$f(e.startedAt)}),e.tokenTotal>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[e.tokenTotal.toLocaleString(),` tok`]})]}),e.isCurrent&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Y.jsx)(`span`,{className:`text-primary font-medium`,children:d(`activity:sessions.active`)})]})]})]})}),(0,Y.jsxs)(`div`,{className:`absolute right-2 top-2 flex items-center gap-1`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(e.id),className:K(`transition-opacity hover:text-amber-500`,u.includes(e.id)?`opacity-100 text-amber-500`:`opacity-0 group-hover:opacity-100 text-muted-foreground`),title:u.includes(e.id)?d(`activity:sessions.unfavorite`):d(`activity:sessions.markFavorite`),children:(0,Y.jsx)(Yn,{className:K(`h-3.5 w-3.5`,u.includes(e.id)&&`fill-current`)})}),h!==e.id&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),g(e.id),v(p[e.id]??e.name??e.title??``)},className:K(`transition-opacity hover:text-primary`,e.name||p[e.id]?`opacity-100 text-primary/70`:`opacity-0 group-hover:opacity-100 text-muted-foreground`),title:d(`activity:sessions.rename`,{defaultValue:`Rename`}),children:(0,Y.jsx)(pe,{className:`h-3.5 w-3.5`})}),!e.isCurrent&&(0,Y.jsx)(`button`,{type:`button`,onClick:async()=>{await wu({title:d(`activity:sessions.deleteSessionConfirmTitle`),message:d(`activity:sessions.deleteSessionConfirmBody`,{name:p[e.id]||e.title||d(`activity:sessions.empty`)}),confirmLabel:d(`common:action.delete`),danger:!0})&&c(e.id)},className:`opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive`,title:d(`activity:sessions.deleteSessionTitle`),children:(0,Y.jsx)(At,{className:`h-3.5 w-3.5`})})]})]},e.id))]},e.label))})})]})}function np(){let e=J(e=>e.wsConnected),{entries:t,loading:n,error:r}=di(),{listSessions:i,resumeSession:a,deleteSession:o,renameSession:s}=ts(),c=W(e=>e.session?.id),{t:l}=z(),[u,d]=(0,q.useState)(``);return(0,q.useEffect)(()=>{e&&i(50)},[e,c,i]),(0,Y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,Y.jsx)(tp,{historyQuery:u,setHistoryQuery:d,historyEntries:t,historyLoading:n,historyError:r,wsConnected:e,listSessions:i,resumeSession:a,deleteSession:o,renameSession:s}),(0,Y.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Q(`history`),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,Y.jsx)(qn,{className:`h-3 w-3`}),l(`activity:history.openDashboard`)]})})]})}function rp(e){return e<=0?`$0.000`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function ip(e){if(e<=0)return`--`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function ap(e){let t=e.split(`/`).pop()??e;return t.length>18?t.slice(0,18):t}function op({icon:e,label:t,onClick:n,disabled:r,tone:i,title:a}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:n,disabled:r,title:a??t,className:K(`flex items-center justify-center gap-1.5 h-8 rounded-md border text-[11px] font-medium transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed`,i===`primary`?`border-primary/40 bg-primary/10 text-primary hover:bg-primary/20`:i===`danger`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border bg-card hover:bg-accent text-foreground/80`),children:[e,t]})}function sp({label:e,value:t,sub:n}){return(0,Y.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/40 border border-border/40 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold tabular-nums truncate`,children:t}),n&&(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 truncate`,children:n})]})}function cp({icon:e,label:t,right:n}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[e,t]}),n]})}function lp({label:e,value:t,onChange:n,title:r}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,title:r,children:[(0,Y.jsx)(`span`,{className:`text-xs text-foreground/80`,children:e}),(0,Y.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,onClick:n,className:K(`shrink-0 relative inline-flex h-4 w-7 rounded-full border transition-colors`,t?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,Y.jsx)(`span`,{className:K(`absolute top-0.5 left-0.5 h-2.5 w-2.5 rounded-full bg-background shadow transition-transform`,t&&`translate-x-3`)})})]})}function up(){let{client:e,updatePrefs:t,switchAutonomy:n}=ts(),{t:r}=z(),a=J(e=>e.wsConnected),o=J(e=>e.wsUrl),s=J(e=>e.provider),c=J(e=>e.model),l=J(e=>e.soundOnComplete),d=W(e=>e.session),f=W(e=>e.totalTokens),p=W(e=>e.cost),m=W(e=>e.iteration),h=W(e=>e.todos),g=W(e=>e.lastInputTokens),_=W(e=>e.maxContext),v=i(e=>e.messages),y=i(e=>e.isLoading),b=X(e=>e.agents),x=G(e=>e.pinnedIds),S=G(e=>e.unpinAll),w=G(e=>e.setModelSwitcherOpen),T=$n(),E=(0,q.useCallback)((e,n)=>{T.set({[e]:n}),t({[e]:n})},[T,t]),[D,O]=(0,q.useState)(!1),k=d?.startedAt??null,[A,j]=(0,q.useState)(()=>Date.now());(0,q.useEffect)(()=>{if(!k)return;let e=setInterval(()=>j(Date.now()),1e3);return()=>clearInterval(e)},[k]);let M=(0,q.useMemo)(()=>Array.from(b.values()).filter(e=>e.status===`running`).length,[b]),N=_>0&&g>0?Math.min(100,Math.round(g/_*100)):0,P=x.map(e=>v.find(t=>t.id===e)).filter(e=>!!e&&e.content.length>0),F=e=>U(o)?.send?.(e);return(0,Y.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b grid grid-cols-2 gap-1.5`,children:[y?(0,Y.jsx)(op,{icon:(0,Y.jsx)(Tt,{className:`h-3 w-3`}),label:r(`activity:sessionPanel.actions.abort`),tone:`danger`,onClick:()=>F({type:`abort`,payload:{}}),disabled:!a}):(0,Y.jsx)(op,{icon:(0,Y.jsx)(re,{className:`h-3 w-3`}),label:r(`activity:sessionPanel.actions.newSession`),tone:`primary`,onClick:()=>{e?.newSession?.(),Q(`chat`)},disabled:!a,title:r(`activity:sessionPanel.actions.newSessionTitle`)}),(0,Y.jsx)(op,{icon:(0,Y.jsx)(Pe,{className:`h-3 w-3`}),label:r(`activity:sessionPanel.actions.export`),onClick:()=>$c(),title:r(`activity:sessionPanel.actions.exportTitle`)}),(0,Y.jsx)(op,{icon:(0,Y.jsx)(C,{className:`h-3 w-3`}),label:r(`activity:sessionPanel.actions.compact`),onClick:()=>F({type:`context.compact`,payload:{aggressive:!1}}),disabled:!a,title:r(`activity:sessionPanel.actions.compactTitle`)}),(0,Y.jsx)(op,{icon:(0,Y.jsx)(dt,{className:`h-3 w-3`}),label:r(`common:action.clear`),onClick:()=>F({type:`context.clear`}),disabled:!a,title:r(`activity:sessionPanel.actions.clearTitle`)})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>w(!0),className:`w-full px-4 py-2.5 border-b text-left hover:bg-muted/40 transition-colors`,title:r(`activity:sessionPanel.modelTitle`),children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-0.5`,children:r(`activity:sessionPanel.model`)}),(0,Y.jsxs)(`div`,{className:`font-mono text-xs truncate`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:s||`—`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/40 mx-1`,children:`/`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:c||`—`})]})]}),_>0&&(0,Y.jsxs)(`div`,{className:`px-4 py-2.5 border-b space-y-1.5`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>O(!0),className:`w-full block text-left`,title:r(`activity:sessionPanel.contextTitle`),children:(0,Y.jsx)(cp,{icon:null,label:r(`activity:sessionPanel.context`),right:(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[cs(g),`/`,cs(_),` · `,N,`%`]})})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>O(!0),className:`w-full block`,title:r(`activity:sessionPanel.contextTitle`),children:(0,Y.jsx)(_s,{pct:N,tokens:g,maxTokens:_,showTokens:!0})})]}),(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,Y.jsx)(cp,{icon:(0,Y.jsx)(Tn,{className:`h-3 w-3`}),label:r(`activity:sessionPanel.sessionLabel`)}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,Y.jsx)(sp,{label:r(`activity:sessionPanel.stats.messages`),value:v.length}),(0,Y.jsx)(sp,{label:r(`activity:sessionPanel.stats.elapsed`),value:k?ip(A-k):`--`}),(0,Y.jsx)(sp,{label:r(`activity:sessionPanel.stats.tokens`),value:cs(f.input+f.output),sub:r(`activity:sessionPanel.stats.tokensSub`,{in:cs(f.input),out:cs(f.output)})}),(0,Y.jsx)(sp,{label:r(`activity:sessionPanel.stats.cost`),value:rp(p)}),m&&(0,Y.jsx)(sp,{label:r(`activity:sessionPanel.stats.iteration`),value:m.index,sub:m.max?r(`activity:sessionPanel.stats.iterationOf`,{max:m.max}):void 0}),b.size>0&&(0,Y.jsx)(sp,{label:r(`activity:sessionPanel.stats.agents`),value:b.size,sub:M>0?r(`activity:sessionPanel.stats.agentsRunning`,{count:M}):void 0})]})]}),h.length>0&&(()=>{let e=h.filter(e=>e.status===`completed`).length,t=h.filter(e=>e.status===`in_progress`).length,n=Math.round(e/h.length*100),i=e===h.length;return(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,Y.jsx)(cp,{icon:(0,Y.jsx)(_n,{className:`h-3 w-3`}),label:r(`activity:sessionPanel.plan`),right:(0,Y.jsxs)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:[e,`/`,h.length]})}),(0,Y.jsx)(`div`,{className:K(`relative h-1.5 w-full overflow-hidden rounded-full bg-muted`,t>0&&`bar-sweep`),title:r(`activity:sessionPanel.planComplete`,{pct:n}),children:(0,Y.jsx)(`div`,{className:K(`h-full rounded-full transition-all duration-500`,i?`bg-[hsl(var(--success))]`:`bg-primary`),style:{width:`${Math.max(n,t>0?4:0)}%`}})}),(0,Y.jsx)(`ul`,{className:`space-y-0.5 max-h-56 overflow-y-auto pr-1 -mx-1`,children:h.map(e=>{let t=e.status===`completed`?jn:e.status===`in_progress`?In:rn,n=e.status===`in_progress`,r=e.status===`completed`?`text-[hsl(var(--success))] line-through opacity-60`:n?`text-foreground`:`text-muted-foreground`;return(0,Y.jsxs)(`li`,{className:K(`flex items-start gap-2 text-xs leading-snug rounded-md px-1.5 py-1 transition-colors`,n&&`bg-primary/10 ring-1 ring-inset ring-primary/20`,r),children:[(0,Y.jsx)(t,{className:K(`h-3.5 w-3.5 mt-0.5 shrink-0`,n&&`text-primary animate-pulse`)}),(0,Y.jsx)(`span`,{className:`break-words`,children:n&&e.activeForm?e.activeForm:e.content})]},e.id)})})]})})(),P.length>0&&(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,Y.jsx)(cp,{icon:(0,Y.jsx)(nt,{className:`h-3 w-3 text-amber-500`}),label:r(`activity:sessionPanel.pinned`),right:(0,Y.jsx)(`button`,{type:`button`,onClick:S,className:`text-[10px] text-muted-foreground hover:text-destructive`,children:r(`common:action.clear`)})}),(0,Y.jsx)(`ul`,{className:`space-y-1 max-h-48 overflow-y-auto pr-1`,children:P.map(e=>{let t=e.content.replace(/\s+/g,` `).slice(0,80);return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=document.querySelector(`[data-message-id="${e.id}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-amber-500/60`),setTimeout(()=>{t.classList.remove(`ring-2`,`ring-amber-500/60`)},1600))},className:`w-full text-left text-xs px-2 py-1.5 rounded bg-muted/40 hover:bg-muted/70 border border-amber-500/20 leading-snug`,title:e.content.slice(0,400),children:[t,e.content.length>80?`…`:``]})},e.id)})})]}),(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1`,children:[(0,Y.jsx)(cp,{icon:(0,Y.jsx)(Ue,{className:`h-3 w-3`}),label:r(`activity:sessionPanel.quickSettings`)}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-foreground/80`,children:r(`activity:sessionPanel.autonomy`)}),(0,Y.jsxs)(`select`,{value:T.autonomy,onChange:e=>{let t=e.target.value;T.set({autonomy:t}),n(t)},className:`shrink-0 h-6 max-w-[150px] rounded-md border bg-background px-1.5 text-[11px]`,children:[(0,Y.jsx)(`option`,{value:`off`,children:r(`activity:sessionPanel.autonomyOptions.off`)}),(0,Y.jsx)(`option`,{value:`suggest`,children:r(`activity:sessionPanel.autonomyOptions.suggest`)}),(0,Y.jsx)(`option`,{value:`auto`,children:r(`activity:sessionPanel.autonomyOptions.auto`)}),(0,Y.jsx)(`option`,{value:`eternal`,children:r(`activity:sessionPanel.autonomyOptions.eternal`)}),(0,Y.jsx)(`option`,{value:`eternal-parallel`,children:r(`activity:sessionPanel.autonomyOptions.eternal-parallel`)})]})]}),(0,Y.jsx)(lp,{label:r(`activity:sessionPanel.yolo`),title:r(`activity:sessionPanel.yoloTitle`),value:T.yolo,onChange:()=>E(`yolo`,!T.yolo)}),(0,Y.jsx)(lp,{label:r(`activity:sessionPanel.refine`),title:r(`activity:sessionPanel.refineTitle`),value:T.enhanceEnabled,onChange:()=>E(`enhanceEnabled`,!T.enhanceEnabled)}),(0,Y.jsx)(lp,{label:r(`activity:sessionPanel.sound`),title:r(`activity:sessionPanel.soundTitle`),value:l,onChange:()=>{let e=!J.getState().soundOnComplete;J.getState().setSoundOnComplete(e),e&&Hi()}})]}),(0,Y.jsxs)(`div`,{className:`px-4 py-2.5`,children:[(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-2 text-[11px]`,a?`text-[hsl(var(--success))]`:`text-[hsl(var(--warning))]`),children:[a?(0,Y.jsx)(u,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Pt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:r(a?`common:status.connected`:`common:status.disconnected`)}),(0,Y.jsx)(`span`,{className:`text-muted-foreground font-mono truncate ml-auto`,title:o,children:o})]}),d&&(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-1 truncate`,title:d.id,children:r(`activity:sessionPanel.sessionId`,{id:ap(d.id)})})]}),(0,Y.jsx)(Cl,{open:D,onClose:()=>O(!1)})]})}function dp(e,t){switch(t){case`project`:return e(`activity:skillDetail.scopeProject`);case`user`:return e(`activity:skillDetail.scopeGlobal`);case`bundled`:return e(`activity:skillDetail.scopeBundled`);case`foreign`:return e(`activity:skillsList.scopeForeign`)}}function fp(e){return e===`project`||e===`user`||e===`bundled`?e:`foreign`}function pp({source:e}){let{t}=z(),n=fp(e);return(0,Y.jsx)(`span`,{className:K(`inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-semibold uppercase tracking-wide`,n===`project`&&`bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-400`,n===`user`&&`bg-violet-100 text-violet-700 dark:bg-violet-950 dark:text-violet-400`,n===`bundled`&&`bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400`,n===`foreign`&&`bg-amber-100 text-amber-700 dark:bg-amber-950 dark:text-amber-400`),children:dp(t,n)})}function mp({className:e}){let{t}=z(),{client:n}=ts(),r=G(e=>e.skillsState),i=G(e=>e.setSkillsState),[a,o]=(0,q.useState)([]),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(`all`),[d,f]=(0,q.useState)(``),p=(0,q.useRef)(r);p.current=r;let[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(``),[v,y]=(0,q.useState)(!1),[x,S]=(0,q.useState)(!1),[C,w]=(0,q.useState)(null),[T,E]=(0,q.useState)(null),[D,O]=(0,q.useState)(!1),[k,A]=(0,q.useState)(``),[j,M]=(0,q.useState)(``),[N,P]=(0,q.useState)(`project`),[F,I]=(0,q.useState)(!1),[L,ee]=(0,q.useState)(null),[te,ne]=(0,q.useState)(null),[ie,ae]=(0,q.useState)(!1),[se,ce]=(0,q.useState)(!1),le=(0,q.useCallback)(async()=>{if(!n||!g.trim())return;S(!0),w(null),E(null);let e=t=>{let r=t;if(S(!1),r.payload.success){let e=r.payload.results?.map(e=>e.name).join(`, `)??g;E(B.t(`activity:skillsList.installedMsg`,{names:e})),n.send({type:`skills.list`})}else w(r.payload.error??B.t(`activity:skillsList.installFailed`));n.off(`skills.installed`,e)};n.on(`skills.installed`,e),n.installSkill(g.trim(),v)},[n,g,v]),ue=(0,q.useCallback)(()=>{if(!n||!k.trim()||!j.trim())return;I(!0),ee(null),ne(null);let e=t=>{let r=t;I(!1),r.payload.success?(ne(B.t(`activity:skillsList.createdMsg`,{name:r.payload.skill?.name??``})),n.send({type:`skills.list`})):ee(r.payload.error??B.t(`activity:skillsList.createFailed`)),n.off(`skills.created`,e)};n.on(`skills.created`,e),n.createSkill(k.trim(),j.trim(),N)},[n,k,j,N]),de=(0,q.useCallback)(()=>{n&&(ce(!0),n.checkForUpdates(void 0,void 0))},[n]),fe=(0,q.useCallback)(()=>{if(!n)return;ae(!0);let e=t=>{let r=t;if(ae(!1),r.payload.error)console.error(`[skills.export]`,r.payload.error);else{let e=atob(r.payload.zipBase64),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);let n=new Blob([t],{type:`application/zip`}),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=`wrongstack-skills-${Date.now()}.zip`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}n.off(`skills.exported`,e)};n.on(`skills.exported`,e),n.exportAllSkills()},[n]);(0,q.useEffect)(()=>{if(!n)return;c(!0);let e=e=>{let t=e;if(t.payload.enabled&&t.payload.skills){o(t.payload.skills);let e=p.current,n=e.knownRefs,r=0,a={...n};for(let e of t.payload.skills){if(e.source===`bundled`)continue;let t=e.ref;if(!t)continue;let i=n[e.name];a[e.name]=t,i&&i!==t&&r++}i({...e,knownRefs:a,updateAvailableCount:r})}c(!1)},t=e=>{let t=e;if(ce(!1),t.payload.success){let e=p.current,r={...e.knownRefs};for(let e of t.payload.updated??[])r[e.name]=e.newRef;i({...e,knownRefs:r,updateAvailableCount:0}),n.send({type:`skills.list`})}};return n.on(`skills.list`,e),n.on(`skills.updated`,t),n.send({type:`skills.list`}),()=>{n.off(`skills.list`,e),n.off(`skills.updated`,t)}},[n,i]);let pe=(0,q.useCallback)(e=>{i({...p.current,selectedSkill:e,navHistory:[e],historyIndex:0,detailOpen:!0}),Q(`skills`)},[i]),me=(0,q.useMemo)(()=>{let e=a;if(l!==`all`&&(e=e.filter(e=>fp(e.source)===l)),d.trim()){let t=d.toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)||e.trigger.toLowerCase().includes(t))}return e},[a,l,d]),he=(0,q.useMemo)(()=>{let e={project:[],user:[],foreign:[],bundled:[]};for(let t of me)e[fp(t.source)].push(t);return e},[me]),ge=r.selectedSkill?.name;return(0,Y.jsxs)(`div`,{className:K(`flex h-full min-h-0 min-w-0 flex-col overflow-hidden`,e),children:[(0,Y.jsxs)(`div`,{className:`w-full border-b flex items-center gap-1 px-2 py-2`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{_(``),w(null),E(null),y(!1),h(!0)},className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,title:t(`activity:skillsList.installTitle`),children:(0,Y.jsx)(re,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{A(``),M(``),P(`project`),ee(null),ne(null),O(!0)},className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,title:t(`activity:skillsList.createTitle`),children:(0,Y.jsx)(qe,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:fe,disabled:ie||a.length===0,className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-40`,title:t(`activity:skillsList.exportTitle`),children:ie?(0,Y.jsx)(R,{className:`h-4 w-4 animate-spin`}):(0,Y.jsx)(Pe,{className:`h-4 w-4`})}),(0,Y.jsxs)(`button`,{type:`button`,onClick:de,disabled:se,className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-40 relative`,title:t(`activity:skillsList.checkUpdatesTitle`),children:[se?(0,Y.jsx)(R,{className:`h-4 w-4 animate-spin`}):(0,Y.jsx)(b,{className:`h-4 w-4`}),!se&&r.updateAvailableCount>0&&(0,Y.jsx)(`span`,{className:`absolute top-0.5 right-0.5 h-2.5 w-2.5 rounded-full bg-primary text-[8px] font-bold text-primary-foreground flex items-center justify-center`,children:r.updateAvailableCount>9?`9+`:r.updateAvailableCount})]})]}),(0,Y.jsxs)(`div`,{className:`p-2 space-y-2 border-b shrink-0`,children:[(0,Y.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:t(`activity:skillsList.searchPlaceholder`),className:`w-full px-2 py-1.5 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring`}),(0,Y.jsx)(`div`,{className:`flex gap-1 flex-wrap`,children:[`all`,`project`,`user`,`foreign`,`bundled`].map(e=>{let n=e===`all`?me.length:me.filter(t=>fp(t.source)===e).length;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>u(e),className:K(`px-1.5 py-0.5 text-[10px] rounded transition-colors`,l===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),children:[e===`all`?t(`common:action.all`):dp(t,e),(0,Y.jsxs)(`span`,{className:K(`ml-1 font-medium`,l===e?`opacity-90`:`opacity-60`,n===0&&`line-through`),children:[`(`,n,`)`]})]},e)})})]}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto`,children:s?(0,Y.jsx)(`div`,{className:`p-4 text-xs text-muted-foreground text-center`,children:t(`activity:skillsList.loading`)}):me.length===0?(0,Y.jsx)(`div`,{className:`p-4 text-xs text-muted-foreground text-center`,children:a.length===0?t(`activity:skillsList.noSkills`):t(`activity:skillsList.noMatch`)}):(0,Y.jsx)(`div`,{className:`py-1`,children:[`project`,`user`,`foreign`,`bundled`].map(e=>{let n=he[e];return n.length===0?null:(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`px-2 py-1 text-[10px] font-semibold text-muted-foreground uppercase tracking-wide flex items-center gap-1`,children:[(0,Y.jsx)(pp,{source:e}),(0,Y.jsx)(`span`,{className:`ml-auto opacity-60`,children:n.length})]}),n.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>pe(e),className:K(`w-full text-left px-2 py-1.5 text-xs transition-colors`,ge===e.name?`bg-primary/10 text-primary`:`hover:bg-accent/50 text-foreground`),children:[(0,Y.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1`,children:[(0,Y.jsx)(oe,{className:`h-3 w-3 shrink-0`}),e.name]}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground truncate mt-0.5`,children:e.trigger||e.description?.slice(0,50)||t(`activity:skillsList.noDescription`)})]},e.name))]},e)})})}),m&&(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,onClick:e=>{e.target===e.currentTarget&&h(!1)},children:(0,Y.jsxs)(`div`,{className:`flex max-h-[calc(100dvh-2rem)] w-[420px] max-w-[90vw] flex-col overflow-hidden rounded-lg border bg-background shadow-xl`,children:[(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between p-4 border-b`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Pe,{className:`h-4 w-4 text-primary`}),(0,Y.jsx)(`span`,{className:`font-semibold text-sm`,children:t(`activity:skillsList.installHeading`)})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>h(!1),className:`p-1 rounded hover:bg-accent text-muted-foreground cursor-pointer`,children:`✕`})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`activity:skillsList.installHint`)}),(0,Y.jsx)(`input`,{type:`text`,value:g,onChange:e=>{_(e.target.value),w(null),E(null)},onKeyDown:e=>{e.key===`Enter`&&!x&&le()},placeholder:t(`activity:skillsList.installPlaceholder`),className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring`,autoFocus:!0}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:t(`activity:skillsList.installScope`)}),(0,Y.jsxs)(`div`,{className:`flex rounded border border-border overflow-hidden`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(!1),className:K(`px-2 py-1 text-[10px] transition-colors`,v?`bg-background hover:bg-accent`:`bg-primary text-primary-foreground`),children:t(`activity:skillDetail.scopeProject`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(!0),className:K(`px-2 py-1 text-[10px] transition-colors border-l border-border`,v?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:t(`activity:skillDetail.scopeGlobal`)})]})]}),C&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive bg-destructive/10 rounded px-2 py-1`,children:C}),T&&(0,Y.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 rounded px-2 py-1`,children:T})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 p-4 border-t bg-muted/20`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>h(!1),className:`px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors`,children:t(T?`common:action.close`:`common:action.cancel`)}),!T&&(0,Y.jsxs)(`button`,{type:`button`,onClick:le,disabled:x||!g.trim(),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[x&&(0,Y.jsx)(R,{className:`h-3 w-3 animate-spin`}),t(`activity:skillsList.installBtn`)]})]})]})}),D&&(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,onClick:e=>{e.target===e.currentTarget&&O(!1)},children:(0,Y.jsxs)(`div`,{className:`flex max-h-[calc(100dvh-2rem)] w-[480px] max-w-[90vw] flex-col overflow-hidden rounded-lg border bg-background shadow-xl`,children:[(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between p-4 border-b`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(qe,{className:`h-4 w-4 text-primary`}),(0,Y.jsx)(`span`,{className:`font-semibold text-sm`,children:t(`activity:skillsList.createHeading`)})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>O(!1),className:`p-1 rounded hover:bg-accent text-muted-foreground cursor-pointer`,children:`✕`})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 space-y-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`activity:skillsList.createHint`)}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-xs font-medium mb-1`,children:[t(`activity:skillsList.nameLabel`),` `,(0,Y.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,Y.jsx)(`input`,{type:`text`,value:k,onChange:e=>{A(e.target.value.trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``)),ee(null),ne(null)},placeholder:t(`activity:skillsList.namePlaceholder`),className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring font-mono`,autoFocus:!0})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`block text-xs font-medium mb-1`,children:[t(`activity:skillsList.descLabel`),` `,(0,Y.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,Y.jsx)(`textarea`,{value:j,onChange:e=>{M(e.target.value),ee(null),ne(null)},onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&!F&&ue()},placeholder:t(`activity:skillsList.descPlaceholder`),rows:4,className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring resize-y`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:t(`activity:skillsList.saveIn`)}),(0,Y.jsxs)(`div`,{className:`flex rounded border border-border overflow-hidden`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>P(`project`),className:K(`px-2 py-1 text-[10px] transition-colors`,N===`project`?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:t(`activity:skillDetail.scopeProject`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>P(`global`),className:K(`px-2 py-1 text-[10px] transition-colors border-l border-border`,N===`global`?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:t(`activity:skillDetail.scopeGlobal`)})]})]}),L&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive bg-destructive/10 rounded px-2 py-1`,children:L}),te&&(0,Y.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 rounded px-2 py-1`,children:te})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 p-4 border-t bg-muted/20`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>O(!1),className:`px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors`,children:t(te?`common:action.close`:`common:action.cancel`)}),!te&&(0,Y.jsxs)(`button`,{type:`button`,onClick:ue,disabled:F||!k.trim()||!j.trim(),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[F&&(0,Y.jsx)(R,{className:`h-3 w-3 animate-spin`}),t(`activity:skillsList.createBtn`)]})]})]})})]})}var hp=[`web`,`react-native`,`flutter`,`swiftui`,`compose`],gp=[`bg`,`surface`,`primary`,`accent`,`fg`,`border`];function _p({tokens:e,label:t}){let n=gp.filter(t=>e[t]);return n.length===0?null:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground w-7`,children:t}),(0,Y.jsx)(`div`,{className:`flex gap-0.5`,children:n.map(t=>(0,Y.jsx)(`div`,{className:`w-4 h-4 rounded-sm border border-black/10 dark:border-white/10`,style:{backgroundColor:e[t]},title:`${t}: ${e[t]}`},t))})]})}function vp({className:e}){let{client:t}=ts(),{t:n}=z(),[r,i]=(0,q.useState)([]),[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(!0),[l,u]=(0,q.useState)(`web`),[d,f]=(0,q.useState)(null);(0,q.useEffect)(()=>{if(!t)return;let e=e=>{let t=e.payload;i(t?.kits??[]),o(t?.activeKit??null),c(!1)},n=e=>{let t=e.payload;f(null),t?.ok&&t.kit&&o(t.kit)};return t.on(`design.list`,e),t.on(`design.use`,n),t.send({type:`design.list`}),()=>{t.off(`design.list`,e),t.off(`design.use`,n)}},[t]);let p=(0,q.useCallback)(e=>{t&&(f(e),t.send({type:`design.use`,payload:{kit:e,stack:l}}))},[t,l]),m=(0,q.useMemo)(()=>[...r].sort((e,t)=>e.name.localeCompare(t.name)),[r]);return(0,Y.jsxs)(`div`,{className:K(`flex h-full min-h-0 min-w-0 flex-col`,e),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border/50`,children:[(0,Y.jsx)(lt,{className:`w-4 h-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:n(`activity:designStudio.pickHint`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Q(`design`),className:`inline-flex items-center gap-1 text-[11px] px-1.5 py-0.5 rounded border border-border/60 hover:bg-muted`,title:n(`activity:designStudio.galleryTitle`),children:[(0,Y.jsx)(qn,{className:`w-3 h-3`}),` `,n(`activity:designStudio.gallery`)]}),(0,Y.jsx)(`select`,{value:l,onChange:e=>u(e.target.value),className:`text-[11px] bg-transparent border border-border/60 rounded px-1 py-0.5`,title:n(`activity:designStudio.stackTitle`),children:hp.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto p-2 space-y-2`,children:[s&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground p-3`,children:[(0,Y.jsx)(R,{className:`w-4 h-4 animate-spin`}),` `,n(`activity:designStudio.loading`)]}),!s&&m.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground p-3`,children:n(`activity:designStudio.notFound`)}),m.map(e=>{let t=a===e.id;return(0,Y.jsxs)(`div`,{className:K(`rounded-lg border p-3 transition-colors`,t?`border-primary/60 bg-primary/5`:`border-border/60 hover:border-border`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold truncate`,children:e.name}),t&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-[9px] font-semibold uppercase text-primary`,children:[(0,Y.jsx)(gt,{className:`w-3 h-3`}),` `,n(`activity:design.active`)]})]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground leading-snug mt-0.5`,children:e.aesthetic})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>p(e.id),disabled:d===e.id,className:K(`shrink-0 text-[11px] px-2 py-1 rounded font-medium`,t?`bg-primary/10 text-primary`:`bg-primary text-primary-foreground hover:opacity-90`),children:d===e.id?`…`:n(t?`activity:design.reapply`:`activity:design.use`)})]}),(0,Y.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,Y.jsx)(_p,{tokens:e.light,label:n(`activity:designStudio.light`)}),(0,Y.jsx)(_p,{tokens:e.dark,label:n(`activity:designStudio.dark`)})]}),e.bestFor&&(0,Y.jsxs)(`p`,{className:`text-[10px] text-muted-foreground mt-2 leading-snug`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`activity:designStudio.bestFor`)}),` `,e.bestFor]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1.5`,children:e.stacks.map(e=>(0,Y.jsx)(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:e},e))})]},e.id)})]})]})}var yp=new Set([`allocating`,`active`,`committing`,`merging`]),bp={active:`text-amber-500`,committing:`text-cyan-500`,merging:`text-blue-500`,merged:`text-emerald-500`,"needs-review":`text-fuchsia-500`,failed:`text-rose-500`,orphan:`text-zinc-400`};function xp(){let{client:e}=ts(),{t}=z(),n=e=>e?e.replace(/^wstack\/ap\//,``):t(`activity:worktrees.detached`),r=Mi(e=>e.worktrees),i=Mi(e=>e.orphans),a=Mi(e=>e.baseBranch),o=Mi(e=>e.canClean),s=Mi(e=>e.cleanResult),c=Mi(e=>e.mergeResult),l=Mi(e=>e.diffByDir),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(null),m=(0,q.useMemo)(()=>e?e.send.bind(e):void 0,[e]);(0,q.useEffect)(()=>{m?.({type:`worktree.scan`})},[m]),(0,q.useEffect)(()=>{d(null)},[c,s]);let h=(0,q.useMemo)(()=>{let e=new Set(r.map(e=>e.branch)),t=r.map(e=>({branch:e.branch,dir:e.dir,status:e.status,baseBranch:e.baseBranch,insertions:e.insertions,deletions:e.deletions,files:e.files,owner:e.ownerLabel,live:yp.has(e.status)}));for(let n of i)n.branch&&e.has(n.branch)||t.push({branch:n.branch,dir:n.dir,status:`orphan`,insertions:0,deletions:0,files:0,live:!1});return t},[r,i]),g=(e,t)=>{e&&m?.({type:`shell.open`,payload:{path:e,target:t}})},_=e=>{e&&(m?.({type:`worktree.diff`,payload:{dir:e}}),p(t=>t===e?null:e))},v=async e=>{e&&await wu({title:t(`activity:worktrees.mergeConfirmTitle`,{branch:n(e),base:a||t(`activity:worktrees.baseLabel`)}),message:t(`activity:worktrees.mergeConfirmMsg`),confirmLabel:t(`activity:worktrees.mergeAction`)})&&(d(e),m?.({type:`worktree.merge`,payload:{branch:e}}))},y=async e=>{await wu({title:t(`activity:worktrees.removeConfirmTitle`,{branch:n(e.branch)}),message:t(`activity:worktrees.removeConfirmMsg`),confirmLabel:t(`common:action.remove`),danger:!0})&&(d(e.branch??``),m?.({type:`worktree.remove`,payload:{dir:e.dir,branch:e.branch}}))};return(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[t(`activity:worktrees.count`,{count:h.length}),a?t(`activity:worktrees.baseSuffix`,{base:a}):``]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i.length>0&&(0,Y.jsxs)(`button`,{type:`button`,disabled:!o,onClick:()=>m?.({type:`worktree.cleanup`}),title:t(o?`activity:worktrees.cleanOrphansTitle`:`activity:worktrees.liveBusyTitle`),className:`inline-flex items-center gap-1 rounded bg-amber-600/90 px-1.5 py-0.5 text-[11px] font-medium text-white hover:bg-amber-700 disabled:opacity-50`,children:[(0,Y.jsx)(dt,{className:`h-3 w-3`}),` `,t(`activity:worktrees.cleanOrphans`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>m?.({type:`worktree.scan`}),title:t(`activity:worktrees.rescanTitle`),className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Y.jsx)(b,{className:`h-3.5 w-3.5`})})]})]}),s&&(0,Y.jsx)(Cp,{ok:s.ok,children:s.ok?t(`activity:worktrees.removed`,{count:s.removed}):s.reason??t(`activity:worktrees.failed`)}),c&&(0,Y.jsx)(Cp,{ok:c.ok,children:c.ok?t(`activity:worktrees.mergedIntoBase`,{branch:n(c.branch)}):c.conflict?t(`activity:worktrees.conflictMerge`,{branch:n(c.branch),files:(c.conflictFiles??[]).join(`, `)||t(`activity:worktrees.seeGit`)}):t(`activity:worktrees.mergeFailed`,{reason:c.reason??t(`activity:worktrees.unknownReason`)})}),(0,Y.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto px-2 pb-3`,children:h.length===0?(0,Y.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-xs text-muted-foreground`,children:[(0,Y.jsx)(Yt,{className:`h-8 w-8 opacity-30`}),(0,Y.jsx)(`p`,{children:t(`activity:worktrees.empty`)}),(0,Y.jsx)(`p`,{className:`max-w-[200px]`,children:t(`activity:worktrees.emptyHint`)})]}):h.map((e,r)=>{let i=u===(e.branch??``),a=e.dir?l[e.dir]:void 0;return(0,Y.jsxs)(`div`,{className:`mb-1.5 rounded-md border border-border bg-card/60 px-2.5 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Yt,{className:K(`h-3.5 w-3.5 shrink-0`,bp[e.status]??`text-muted-foreground`)}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,title:e.branch,children:n(e.branch)}),(0,Y.jsx)(`span`,{className:K(`shrink-0 text-[10px] uppercase`,bp[e.status]??`text-muted-foreground`),children:e.status})]}),(0,Y.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 pl-5 text-[10px] text-muted-foreground`,children:[e.owner&&(0,Y.jsx)(`span`,{className:`truncate`,children:e.owner}),(e.insertions>0||e.deletions>0)&&(0,Y.jsxs)(`span`,{className:`shrink-0`,children:[(0,Y.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),` `,(0,Y.jsxs)(`span`,{className:`text-rose-500`,children:[`−`,e.deletions]}),` · `,e.files,`f`]})]}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-0.5 pl-5`,children:[(0,Y.jsx)(Sp,{title:t(`activity:worktrees.actOpenTerm`),disabled:!e.dir,onClick:()=>g(e.dir,`terminal`),children:(0,Y.jsx)(yn,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(Sp,{title:t(`activity:worktrees.actOpenFolder`),disabled:!e.dir,onClick:()=>g(e.dir,`file-manager`),children:(0,Y.jsx)(he,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(Sp,{title:t(`activity:worktrees.actViewChanges`),disabled:!e.dir,onClick:()=>_(e.dir),children:(0,Y.jsx)(ce,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(Sp,{title:t(`activity:worktrees.actMerge`),disabled:e.live||!e.branch,onClick:()=>v(e.branch),children:i?(0,Y.jsx)(R,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)($t,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(Sp,{title:t(`activity:worktrees.actRemove`),danger:!0,disabled:e.live,onClick:()=>y(e),children:(0,Y.jsx)(At,{className:`h-3.5 w-3.5`})}),e.live&&(0,Y.jsx)(`span`,{className:`ml-1 text-[10px] text-amber-500`,children:t(`activity:worktrees.live`)})]}),f===e.dir&&a!==void 0&&(0,Y.jsx)(`div`,{className:`mt-1.5 ml-5 rounded bg-muted/50 p-1.5 text-[10px]`,children:a===null||a.files.length===0?(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[t(`activity:worktrees.noUncommitted`),a&&a.commits>0?` · ${t(`activity:worktrees.commitsAhead`,{count:a.commits})}`:``,`.`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`mb-1 text-muted-foreground`,children:[a.commits>0?`${t(`activity:worktrees.commitsAhead`,{count:a.commits})} · `:``,(0,Y.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,a.insertions]}),` `,(0,Y.jsxs)(`span`,{className:`text-rose-500`,children:[`−`,a.deletions]})]}),a.files.slice(0,12).map(e=>(0,Y.jsxs)(`div`,{className:`truncate font-mono`,children:[(0,Y.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),` `,(0,Y.jsxs)(`span`,{className:`text-rose-500`,children:[`−`,e.deletions]}),` `,e.path]},e.path)),a.files.length>12&&(0,Y.jsx)(`div`,{className:`text-muted-foreground`,children:t(`activity:worktrees.more`,{count:a.files.length-12})})]})})]},`${e.branch??e.dir??r}`)})})]})}function Sp({title:e,onClick:t,disabled:n,danger:r,children:i}){return(0,Y.jsx)(`button`,{type:`button`,title:e,disabled:n,onClick:t,className:K(`rounded p-1 text-muted-foreground hover:bg-muted disabled:cursor-not-allowed disabled:opacity-30`,r?`hover:text-rose-500`:`hover:text-foreground`),children:i})}function Cp({ok:e,children:t}){return(0,Y.jsxs)(`div`,{className:K(`flex items-start gap-1.5 border-y px-3 py-1.5 text-[11px]`,e?`border-emerald-500/30 bg-emerald-500/5 text-emerald-600 dark:text-emerald-300`:`border-amber-500/30 bg-amber-500/5 text-amber-600 dark:text-amber-300`),children:[e?(0,Y.jsx)(jn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}):(0,Y.jsx)(je,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1`,children:t}),!e&&(0,Y.jsx)(f,{className:`mt-0.5 h-3 w-3 shrink-0 opacity-40`})]})}function wp({label:e,checked:t,onChange:n}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:`flex w-full items-center justify-between px-2 py-1.5 rounded text-xs hover:bg-accent/50 transition-colors`,children:[(0,Y.jsx)(`span`,{className:`text-foreground`,children:e}),(0,Y.jsx)(`span`,{className:K(`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t?`bg-primary`:`bg-muted`),children:(0,Y.jsx)(`span`,{className:K(`inline-block h-3 w-3 transform rounded-full bg-background transition-transform`,t?`translate-x-3.5`:`translate-x-0.5`)})})]})}var Tp=[{value:`dots`,labelKey:`bgDots`},{value:`lines`,labelKey:`bgLines`},{value:`cross`,labelKey:`bgCross`},{value:`none`,labelKey:`bgNone`}];function Ep(){let{t:e}=z(),{showHud:t,showLegend:n,showMinimap:r,showControls:i,animateEdges:a,background:o,setShowHud:s,setShowLegend:c,setShowMinimap:l,setShowControls:u,setAnimateEdges:d,setBackground:f}=Di(),{clientCounts:p,currentSession:m,totalAgents:h,activeAgents:g}=Ei(We(e=>({clientCounts:e.clientCounts,currentSession:e.currentSession,totalAgents:e.totalAgents,activeAgents:e.activeAgents}))),_=p.tui+p.webui+p.repl;return(0,Y.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col gap-4 overflow-y-auto p-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-2`,children:e(`activity:officeMap.liveHeading`)}),(0,Y.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(En,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.clients`)]}),(0,Y.jsx)(`span`,{className:`font-mono`,children:_})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(wt,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.agents`)]}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[g,(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,h]})]})]}),m.model&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(Tn,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.model`)]}),(0,Y.jsx)(`span`,{className:`font-mono truncate max-w-[140px]`,title:m.model,children:m.model.split(`/`).pop()})]}),m.mode&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(rt,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.mode`)]}),(0,Y.jsx)(`span`,{className:`font-mono uppercase text-[10px]`,children:m.mode})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(be,{className:`h-3.5 w-3.5`}),` `,e(`activity:officeMap.toolCalls`)]}),(0,Y.jsx)(`span`,{className:`font-mono`,children:(e=>e?.toLocaleString()??`0`)(m.toolCalls)})]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1`,children:e(`activity:officeMap.displayHeading`)}),(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsx)(wp,{label:e(`activity:officeMap.statsHud`),checked:t,onChange:s}),(0,Y.jsx)(wp,{label:e(`activity:officeMap.legends`),checked:n,onChange:c}),(0,Y.jsx)(wp,{label:e(`activity:officeMap.minimap`),checked:r,onChange:l}),(0,Y.jsx)(wp,{label:e(`activity:officeMap.zoomControls`),checked:i,onChange:u}),(0,Y.jsx)(wp,{label:e(`activity:officeMap.animateWires`),checked:a,onChange:d})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1.5 px-2`,children:e(`activity:officeMap.backgroundHeading`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 px-2`,children:Tp.map(t=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(t.value),className:K(`px-2 py-1 text-[10px] rounded transition-colors`,o===t.value?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),children:e(`activity:officeMap.${t.labelKey}`)},t.value))})]})]})}function Dp({desktopShell:e=!1}){let t=G(e=>e.activeActivity),n=G(e=>e.setSidebarOpen),r=G(e=>e.sidebarWidth),i=G(e=>e.setSidebarWidth),a=J(e=>e.wsConnected),{client:o}=ts(),{t:s}=z(),c=e?Math.min(r,280):r;return(0,q.useEffect)(()=>{if(t!==`files`||!a)return;Ir.getState().setTreeLoading(!0);let e=W.getState().cwd;o?.send({type:`files.tree`,payload:e?{path:e}:{}})},[t,a,o]),(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:K(`fixed inset-y-0 right-0 z-30 bg-black/20 md:hidden`,e?`left-10`:`left-12`),onClick:()=>n(!1),"aria-hidden":`true`}),(0,Y.jsxs)(`aside`,{style:{width:`${c}px`,maxWidth:e?`min(300px, calc(100vw - 2.5rem))`:`calc(100vw - 3rem)`},className:K(`fixed inset-y-0 z-40 flex min-h-0 min-w-0 shrink-0 flex-col overflow-hidden border-r bg-card shadow-2xl animate-slide-in md:relative md:inset-auto md:z-auto md:shadow-none`,e?`left-10`:`left-12`),children:[(0,Y.jsx)(`div`,{onMouseDown:e=>{e.preventDefault();let t=e.clientX,n=r,a=e=>i(n+(e.clientX-t)),o=()=>{window.removeEventListener(`mousemove`,a),window.removeEventListener(`mouseup`,o),document.body.style.cursor=``,document.body.style.userSelect=``};window.addEventListener(`mousemove`,a),window.addEventListener(`mouseup`,o),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},onDoubleClick:()=>i(304),className:`group/handle absolute top-0 right-0 h-full w-2 cursor-col-resize z-10 flex items-center justify-end`,title:s(`activity:sidePanel.dragHint`),children:(0,Y.jsx)(`div`,{className:`h-full w-px bg-border group-hover/handle:bg-primary/60 group-hover/handle:w-0.5 transition-all`})}),(0,Y.jsxs)(`div`,{className:K(`flex items-center justify-between border-b shrink-0`,e?`px-2.5 py-2`:`px-3 py-2.5`),children:[(0,Y.jsx)(`span`,{className:`text-xs font-semibold tracking-tight text-muted-foreground uppercase`,children:s(`activity:nav.${t}`)}),(0,Y.jsx)($,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>n(!1),title:s(`activity:sidePanel.collapse`),children:(0,Y.jsx)(y,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 min-w-0 flex flex-col overflow-hidden`,children:[t===`chat`&&(0,Y.jsx)(up,{}),t===`agents`&&(0,Y.jsx)(Jf,{}),t===`history`&&(0,Y.jsx)(np,{}),t===`files`&&(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-y-auto`,children:(0,Y.jsx)(Lf,{})}),t===`changes`&&(0,Y.jsx)(Qf,{}),t===`mailbox`&&(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-y-auto p-3`,children:(0,Y.jsx)(Bf,{})}),t===`skills`&&(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(mp,{className:`h-full`})}),t===`design`&&(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(vp,{className:`h-full`})}),t===`worktrees`&&(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(xp,{})}),t===`officemap`&&(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(Ep,{})})]})]})]})}function Op(){let e=si(e=>e.info),{client:t}=ts(),n=(0,q.useRef)(null),r=(0,q.useCallback)(()=>{t?.getGitInfo?.()},[t]);return(0,q.useEffect)(()=>(r(),n.current=setInterval(r,3e4),()=>{n.current&&clearInterval(n.current)}),[r]),e}function kp({sessionId:e,className:t}){let{t:n}=z(),[r,a]=(0,q.useState)([]),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(null),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(0),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(!1),[v,y]=(0,q.useState)(``),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(!1),[w,T]=(0,q.useState)(``),E=U(J(e=>e.wsUrl)),D=i(e=>e.messages).filter(e=>e.role===`tool`&&e.toolResult===void 0&&!!e.toolUseId);(0,q.useEffect)(()=>{let t=[];return t.push(E.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&a(n.participants??[])})),t.push(E.on(`collab.participant.joined`,t=>{let n=t.payload;n.sessionId===e&&a(e=>e.some(e=>e.participantId===n.participantId)?e:[...e,{participantId:n.participantId,role:n.role,joinedAt:n.joinedAt}])})),t.push(E.on(`collab.participant.left`,t=>{let n=t.payload;if(n.sessionId!==e)return;let r=n.participantId;a(e=>e.filter(e=>e.participantId!==r))})),t.push(E.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(d(t.message),s(!1))})),t.push(E.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||p(e=>e+1))})),t.push(E.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&p(e=>Math.max(0,e-1))})),t.push(E.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&h(!0)})),t.push(E.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&h(!1)})),()=>{for(let e of t)e()}},[E,e]);let O=(t=`observer`)=>{d(null),E.send({type:`collab.join`,payload:{sessionId:e,role:t}}),s(!0),l(t)},k=()=>{E.send({type:`collab.request_pause`,payload:{sessionId:e}})},A=()=>{E.send({type:`collab.resume`,payload:{sessionId:e}})},j=()=>{E.send({type:`collab.leave`,payload:{sessionId:e}}),s(!1),a([])},M=t=>{E.send({type:`collab.grant_control`,payload:{sessionId:e,toParticipant:t}})},N=()=>{v&&(E.send({type:`collab.inject_tool`,payload:{sessionId:e,toolUseId:v,content:b,isError:S,reason:w.trim()||B.t(`activity:collab.controllerInjection`)}}),_(!1),y(``),x(``),C(!1),T(``))},P=o&&c===`controller`;return r.length===0&&!u?(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-2 px-3 py-2 rounded-md border border-dashed border-border bg-card/40`,t),children:[(0,Y.jsx)(En,{className:`w-4 h-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`activity:collab.noObservers`)}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>O(`observer`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,title:n(`activity:collab.observerTitle`),children:[(0,Y.jsx)(Ot,{className:`w-3 h-3`}),n(`activity:collab.observerRole`)]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>O(`annotator`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:n(`activity:collab.annotatorTitle`),children:[(0,Y.jsx)(hn,{className:`w-3 h-3`}),n(`activity:collab.annotatorRole`)]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>O(`controller`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:n(`activity:collab.controllerTitle`),children:[(0,Y.jsx)(Sn,{className:`w-3 h-3`}),n(`activity:collab.controllerRole`)]})]})]}):u?(0,Y.jsxs)(`div`,{className:K(`flex items-center gap-2 px-3 py-2 rounded-md border border-destructive/50 bg-destructive/10`,t),role:`alert`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-destructive`,children:n(`activity:collab.errorPrefix`,{error:u})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{d(null),s(!1)},className:`ml-auto text-xs underline text-destructive`,children:n(`activity:collab.dismiss`)})]}):(0,Y.jsxs)(`div`,{className:K(`relative flex items-center gap-2 px-3 py-2 rounded-md border border-emerald-500/40 bg-emerald-500/5`,t),children:[(0,Y.jsxs)(`span`,{className:`relative flex h-2 w-2`,"aria-label":n(`common:status.live`),children:[(0,Y.jsx)(`span`,{className:`absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75 animate-ping`}),(0,Y.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-emerald-500`})]}),(0,Y.jsx)(En,{className:`w-4 h-4 text-emerald-700 dark:text-emerald-400`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium text-emerald-700 dark:text-emerald-300`,children:n(`activity:collab.observers`,{count:r.length})}),f>0&&(0,Y.jsxs)(`span`,{title:n(`activity:collab.annotationsTitle`,{count:f}),className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-700 dark:text-amber-300 border border-amber-500/30`,children:[(0,Y.jsx)(hn,{className:`w-3 h-3`}),n(`activity:collab.notes`,{count:f})]}),m&&(0,Y.jsxs)(`span`,{title:n(`activity:collab.pausedTitle`),className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-700 dark:text-rose-300 border border-rose-500/40`,children:[(0,Y.jsx)(Sn,{className:`w-3 h-3`}),n(`activity:collab.paused`)]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 ml-2`,children:[r.slice(0,3).map(e=>(0,Y.jsxs)(`span`,{title:n(`activity:collab.joinedTitle`,{time:new Date(e.joinedAt).toLocaleTimeString()}),className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`,children:[(0,Y.jsx)(ce,{className:`w-3 h-3`}),e.role,P&&e.role!==`controller`&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>M(e.participantId),title:n(`activity:collab.grantTitle`),className:`ml-0.5 inline-flex items-center rounded hover:bg-emerald-500/20 transition-colors`,children:(0,Y.jsx)(xt,{className:`w-3 h-3`})})]},e.participantId)),r.length>3&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,r.length-3]})]}),P&&(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-sky-500/40 bg-sky-500/10 text-sky-700 dark:text-sky-300 hover:bg-sky-500/20 transition-colors`,title:n(`activity:collab.injectTitle`),children:[(0,Y.jsx)(Vt,{className:`w-3 h-3`}),n(`activity:collab.inject`)]}),m?(0,Y.jsxs)(`button`,{type:`button`,onClick:A,className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:n(`activity:collab.resumeTitle`),children:[(0,Y.jsx)(Ye,{className:`w-3 h-3`}),n(`activity:collab.resume`)]}):(0,Y.jsxs)(`button`,{type:`button`,onClick:k,className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:n(`activity:collab.pauseTitle`),children:[(0,Y.jsx)(Sn,{className:`w-3 h-3`}),n(`activity:collab.pauseAgent`)]})]}),o&&c!==`controller`&&(0,Y.jsxs)(`button`,{type:`button`,onClick:j,className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-border hover:bg-muted transition-colors`,title:n(`activity:collab.leaveTitle`),children:[(0,Y.jsx)(Fn,{className:`w-3 h-3`}),n(`activity:collab.leave`)]}),P&&g&&(0,Y.jsxs)(`div`,{className:`absolute top-full left-0 right-0 mt-1 z-50 flex flex-col gap-2 p-3 rounded-md border border-sky-500/40 bg-card shadow-lg text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Vt,{className:`w-3.5 h-3.5 text-sky-600 dark:text-sky-400`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:n(`activity:collab.injectToolResult`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>_(!1),className:`ml-auto text-muted-foreground hover:text-foreground`,children:n(`activity:collab.close`)})]}),(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:collab.targetTool`)}),(0,Y.jsx)(`input`,{list:`collab-inject-tools`,value:v,onChange:e=>y(e.target.value),placeholder:n(`activity:collab.targetPlaceholder`),className:`px-2 py-1 rounded border border-border bg-background font-mono`}),(0,Y.jsx)(`datalist`,{id:`collab-inject-tools`,children:D.map(e=>{let t=e.toolInput===void 0?``:` — ${JSON.stringify(e.toolInput).slice(0,40)}`;return(0,Y.jsxs)(`option`,{value:e.toolUseId,children:[e.toolName??n(`activity:collab.toolFallback`),t]},e.toolUseId)})}),D.length===0&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`activity:collab.noPendingTools`)})]}),(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:collab.resultContent`)}),(0,Y.jsx)(`textarea`,{value:b,onChange:e=>x(e.target.value),rows:3,placeholder:n(`activity:collab.resultPlaceholder`),className:`px-2 py-1 rounded border border-border bg-background font-mono`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(`label`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked)}),(0,Y.jsx)(`span`,{children:n(`activity:collab.markError`)})]}),(0,Y.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:n(`activity:collab.reasonPlaceholder`),className:`flex-1 px-2 py-1 rounded border border-border bg-background`})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:N,disabled:!v,className:`self-end inline-flex items-center gap-1 text-xs px-3 py-1 rounded bg-sky-600 text-white hover:bg-sky-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,Y.jsx)(Vt,{className:`w-3 h-3`}),n(`activity:collab.queueInjection`)]})]})]})}var Ap={up:(0,Y.jsx)(an,{className:`h-3.5 w-3.5 text-emerald-500`}),down:(0,Y.jsx)(Ln,{className:`h-3.5 w-3.5 text-red-500`}),stable:(0,Y.jsx)(dn,{className:`h-3.5 w-3.5 text-amber-500`})},jp={active:{color:`text-emerald-600 dark:text-emerald-400`,bg:`bg-emerald-100 dark:bg-emerald-900/40`,labelKey:`statusActive`},paused:{color:`text-amber-600 dark:text-amber-400`,bg:`bg-amber-100 dark:bg-amber-900/40`,labelKey:`statusPaused`},completed:{color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-100 dark:bg-blue-900/40`,labelKey:`statusDone`},failed:{color:`text-red-600 dark:text-red-400`,bg:`bg-red-100 dark:bg-red-900/40`,labelKey:`statusFailed`},abandoned:{color:`text-stone-600 dark:text-stone-400`,bg:`bg-stone-100 dark:bg-stone-900/40`,labelKey:`statusAbandoned`}};function Mp({goal:e,className:t}){let{t:n}=z(),[r,i]=(0,q.useState)(!1);if((0,q.useEffect)(()=>{let e=U();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,q.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&i(!0)},[e]),!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let a=jp[e.goalState],o=e.deliverables?.filter(e=>e.status===`done`).length??0,s=e.deliverables?.length??0,c=e.journal?.slice(-5).reverse()??[],l=e.progressTrend?Ap[e.progressTrend]:null;return(0,Y.jsxs)(`div`,{className:K(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,t),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,Y.jsx)(ln,{className:`h-4 w-4 text-rose-500`}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:n(`activity:goal.heading`)}),(0,Y.jsx)(`span`,{className:K(`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium shrink-0`,a.bg,a.color),children:n(`activity:goal.${a.labelKey}`)}),r?(0,Y.jsx)(vn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Y.jsx)(Bt,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!r&&(0,Y.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t pt-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-foreground leading-relaxed whitespace-pre-wrap break-words`,children:e.goal}),e.refinedGoal&&e.refinedGoal!==e.goal&&(0,Y.jsxs)(`div`,{className:`mt-1.5 p-2 rounded bg-accent/40 border border-border/50`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground mb-0.5 uppercase tracking-wider font-medium`,children:n(`activity:goal.refined`)}),(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap break-words`,children:e.refinedGoal})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground uppercase tracking-wider font-medium`,children:n(`activity:goal.progress`)}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums`,children:[l,(0,Y.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.progress,`%`]})]})]}),(0,Y.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:K(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-emerald-500`:e.progress>=50?`bg-amber-500`:`bg-primary`),style:{width:`${e.progress>0?Math.max(2,e.progress):0}%`}})}),e.progressNote&&(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:e.progressNote})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(kn,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`tabular-nums font-medium`,children:e.iterations}),(0,Y.jsx)(`span`,{children:n(`activity:goal.iterations`)}),e.lastStatus&&(0,Y.jsx)(`span`,{className:`text-border`,children:`·`}),e.lastStatus&&(0,Y.jsx)(`span`,{className:`truncate`,children:e.lastStatus})]}),s>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:[(0,Y.jsx)(`span`,{children:n(`activity:goal.deliverables`)}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[o,`/`,s]})]}),(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:e.deliverables?.map(e=>(0,Y.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px]`,children:[e.status===`done`?(0,Y.jsx)(jn,{className:`h-3 w-3 text-emerald-500 mt-0.5 shrink-0`}):(0,Y.jsx)(rn,{className:`h-3 w-3 text-muted-foreground/50 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{className:K(`leading-snug`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground`),children:e.text})]},e.id))})]}),c.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:n(`activity:goal.recentActivity`)}),(0,Y.jsx)(`div`,{className:`space-y-1`,children:c.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{className:`font-mono tabular-nums shrink-0 text-foreground/60`,children:[`#`,e.iteration]}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.task||e.status||e.progressNote||`…`})]},`${e.iteration}-${t}`))})]})]})]})}var Np={in_progress:0,pending:1,completed:2};function Pp(){let{t:e}=z(),[t,n]=(0,q.useState)([]),[r,i]=(0,q.useState)(new Set),a=U(),o=(0,q.useRef)(null);(0,q.useEffect)(()=>(a.send({type:`todos.get`}),o.current=a.on(`todos.updated`,e=>{let t=e?.payload;t?.todos&&n(t.todos)}),()=>{o.current?.()}),[a]);let s=(0,q.useCallback)(e=>{a.removeTodo(e)},[a]),c=(0,q.useCallback)(e=>{if(e.status===`in_progress`)return;let t=e.status===`completed`?`pending`:`completed`;a.updateTodoStatus(e.id,t)},[a]),l=[...t].sort((e,t)=>(Np[e.status]??9)-(Np[t.status]??9)),u=l.filter(e=>e.status===`in_progress`),d=l.filter(e=>e.status===`pending`),f=l.filter(e=>e.status===`completed`),p=f.length>0,m=r.has(`completed`),h=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},g=t=>{let n=t.status===`in_progress`&&t.activeForm?t.activeForm:t.content,r=t.status===`in_progress`,i=t.status===`completed`,a=!r;return(0,Y.jsxs)(`div`,{onClick:()=>a&&c(t),className:K(`px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors`,a&&`cursor-pointer hover:bg-accent/40`,r?`bg-yellow-50/40 dark:bg-yellow-950/25`:i?`bg-emerald-50/20 dark:bg-emerald-950/10`:`bg-background`),role:a?`button`:void 0,"aria-label":a?e(`activity:todos.toggleAria`,{content:t.content}):void 0,tabIndex:a?0:void 0,onKeyDown:e=>{a&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),c(t))},children:[(0,Y.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:i?(0,Y.jsx)(jn,{className:`w-3.5 h-3.5 text-emerald-500`}):r?(0,Y.jsx)(kn,{className:`w-3.5 h-3.5 text-yellow-500 animate-spin`}):(0,Y.jsx)(rn,{className:K(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/40 group-hover:text-emerald-400`)})}),(0,Y.jsx)(`span`,{className:K(`leading-snug flex-1 min-w-0`,r?`text-yellow-800 dark:text-yellow-200 font-medium`:i?`text-muted-foreground line-through`:`text-foreground/80`),children:n}),(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(t.id)},className:`shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-50 hover:opacity-100 hover:bg-destructive/10 transition-all`,title:e(`activity:todos.removeTitle`),"aria-label":e(`activity:todos.removeAria`,{content:t.content}),children:(0,Y.jsx)(At,{className:`w-3 h-3 text-muted-foreground`})})]},t.id)};return t.length===0?null:(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Y.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:e(`activity:work.todos`)}),(0,Y.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[f.length,`/`,t.length]})]}),u.length>0&&(0,Y.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:u.map(g)}),d.length>0&&(0,Y.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:d.map(g)}),p&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>h(`completed`),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,Y.jsxs)(`span`,{className:`tabular`,children:[m?`▶`:`▼`,` `,e(`activity:todos.completedCount`,{count:f.length})]})}),!m&&f.map(g)]})]})}var Fp={pending:{icon:(0,Y.jsx)(rn,{className:`w-3.5 h-3.5`}),labelKey:`statusPending`,color:`text-muted-foreground/50`},in_progress:{icon:(0,Y.jsx)(kn,{className:`w-3.5 h-3.5 animate-spin`}),labelKey:`statusInProgress`,color:`text-yellow-500`},blocked:{icon:(0,Y.jsx)(Sn,{className:`w-3.5 h-3.5`}),labelKey:`statusBlocked`,color:`text-orange-500`},failed:{icon:(0,Y.jsx)(f,{className:`w-3.5 h-3.5`}),labelKey:`statusFailed`,color:`text-red-500`},review:{icon:(0,Y.jsx)(se,{className:`w-3.5 h-3.5`}),labelKey:`statusReview`,color:`text-blue-500`},completed:{icon:(0,Y.jsx)(jn,{className:`w-3.5 h-3.5`}),labelKey:`statusDone`,color:`text-emerald-500`}},Ip={critical:`text-red-600 dark:text-red-400`,high:`text-orange-600 dark:text-orange-400`,medium:`text-yellow-600 dark:text-yellow-400`,low:`text-muted-foreground`},Lp={feature:`⚡`,bugfix:`🐛`,refactor:`♻️`,docs:`📝`,test:`🧪`,chore:`🔧`};function Rp(){let{t:e}=z(),[t,n]=(0,q.useState)([]),[r,i]=(0,q.useState)(new Set),a=U(),o=(0,q.useRef)(null);(0,q.useEffect)(()=>(a.getTasks(),o.current=a.on(`tasks.updated`,e=>{let t=e?.payload;t?.tasks&&n(t.tasks)}),()=>{o.current?.()}),[a]);let s=(0,q.useCallback)(e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),c=(0,q.useCallback)((e,t)=>{a.updateTaskStatus(e,t)},[a]),l=[`in_progress`,`blocked`,`review`,`pending`,`failed`,`completed`],u=new Map;for(let e of t){let t=u.get(e.status)??[];t.push(e),u.set(e.status,t)}let d=u.get(`completed`)?.length??0;return t.length===0?null:(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Y.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:e(`activity:work.tasks`)}),(0,Y.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[d,`/`,t.length]})]}),l.map(t=>{let n=u.get(t);if(!n||n.length===0)return null;let i=Fp[t],a=r.has(t);return(0,Y.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,Y.jsxs)(`span`,{className:`tabular`,children:[a?`▶`:`▼`,` `,n.length,` `,e(`activity:task.${i.labelKey}`)]})}),!a&&n.map(t=>(0,Y.jsxs)(`div`,{className:K(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,t.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,Y.jsx)(`span`,{className:K(`mt-0.5 shrink-0`,i.color),children:i.icon}),(0,Y.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,Y.jsxs)(`span`,{className:K(t.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[Lp[t.type],` `,t.title]}),t.priority!==`medium`&&(0,Y.jsx)(`span`,{className:K(`ml-1 text-[10px]`,Ip[t.priority]),children:t.priority}),t.assignee&&(0,Y.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,t.assignee]}),t.estimateHours&&(0,Y.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[t.estimateHours,`h`]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[t.status!==`in_progress`&&t.status!==`completed`&&(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c(t.id,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:e(`activity:task.startTitle`),children:e(`common:action.start`)}),t.status===`in_progress`&&(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c(t.id,`completed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:e(`activity:task.completeTitle`),children:e(`activity:task.statusDone`)}),t.status!==`completed`&&t.status!==`failed`&&(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c(t.id,`failed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,title:e(`activity:task.failTitle`),children:e(`activity:task.fail`)})]})]},t.id))]},t)})]})}var zp={open:{icon:(0,Y.jsx)(rn,{className:`w-3.5 h-3.5`}),labelKey:`statusOpen`,color:`text-muted-foreground/50`},in_progress:{icon:(0,Y.jsx)(kn,{className:`w-3.5 h-3.5 animate-spin`}),labelKey:`statusInProgress`,color:`text-yellow-500`},done:{icon:(0,Y.jsx)(jn,{className:`w-3.5 h-3.5`}),labelKey:`statusDone`,color:`text-emerald-500`}};function Bp(){let{t:e}=z(),[t,n]=(0,q.useState)([]),[r,i]=(0,q.useState)(new Set),a=U(),o=(0,q.useRef)(null);(0,q.useEffect)(()=>(a.getPlan(),o.current=a.on(`plan.updated`,e=>{let t=e?.payload;t?.plan?.items&&n(t.plan.items)}),()=>{o.current?.()}),[a]);let s=(0,q.useCallback)(e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),c=(0,q.useCallback)((e,t)=>{a.updatePlanItem(e.id,t)},[a]),l=[`in_progress`,`open`,`done`],u=new Map;for(let e of t){let t=u.get(e.status)??[];t.push(e),u.set(e.status,t)}let d=u.get(`done`)?.length??0;return t.length===0?null:(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Y.jsxs)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:[`📋 `,e(`activity:work.plan`)]}),(0,Y.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[d,`/`,t.length]})]}),l.map(t=>{let n=u.get(t);if(!n||n.length===0)return null;let i=zp[t],a=r.has(t);return(0,Y.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,Y.jsxs)(`span`,{className:`tabular`,children:[a?`▶`:`▼`,` `,n.length,` `,e(`activity:plan.${i.labelKey}`)]})}),!a&&n.map(t=>(0,Y.jsxs)(`div`,{className:K(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,t.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,Y.jsx)(`span`,{className:K(`mt-0.5 shrink-0`,i.color),children:i.icon}),(0,Y.jsx)(`span`,{className:K(`leading-snug flex-1 min-w-0`,t.status===`done`?`text-muted-foreground line-through`:`text-foreground/80`),children:t.title}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[t.status===`open`&&(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c(t,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:e(`activity:plan.startTitle`),children:e(`common:action.start`)}),t.status!==`done`&&(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c(t,`done`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:e(`activity:plan.doneTitle`),children:e(`activity:plan.statusDone`)}),t.status===`done`&&(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c(t,`open`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-muted text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,title:e(`activity:plan.reopenTitle`),children:e(`activity:plan.reopen`)})]})]},t.id))]},t)})]})}var Vp=[{id:`todos`,labelKey:`work.todos`,icon:`✅`},{id:`tasks`,labelKey:`work.tasks`,icon:`📋`},{id:`plan`,labelKey:`work.plan`,icon:`🗺️`}];function Hp(){let{t:e}=z(),t=G(e=>e.workDashboardTab),n=G(e=>e.setWorkDashboardTab);return(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Y.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:Vp.map(r=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n(r.id),className:K(`flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium transition-colors`,`border-b-2 -mb-px`,t===r.id?`border-primary text-foreground bg-background`:`border-transparent text-muted-foreground hover:text-foreground hover:bg-accent/30`),children:[(0,Y.jsx)(`span`,{className:`text-xs`,children:r.icon}),e(`activity:${r.labelKey}`)]},r.id))}),(0,Y.jsx)(`div`,{className:K(t===`todos`?`block`:`hidden`),children:(0,Y.jsx)(Pp,{})}),(0,Y.jsx)(`div`,{className:K(t===`tasks`?`block`:`hidden`),children:(0,Y.jsx)(Rp,{})}),(0,Y.jsx)(`div`,{className:K(t===`plan`?`block`:`hidden`),children:(0,Y.jsx)(Bp,{})})]})}var Up=[`#3b82f6`,`#06b6d4`,`#22c55e`,`#eab308`,`#f97316`,`#a855f7`,`#ec4899`],Wp=e=>e.replace(/^wstack\/ap\//,``);function Gp(e){return[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt).map((e,t)=>({handle:e,color:Up[t%Up.length],y:60+t*48}))}var Kp={allocating:{dash:`4 4`,opacity:.4},active:{dash:`4 4`,opacity:.6},committing:{dash:`4 4`,opacity:.8},merging:{dash:`0`,opacity:.9},merged:{dash:`0`,opacity:1},"needs-review":{dash:`2 3`,opacity:.9},failed:{dash:`2 3`,opacity:.6}};function qp({worktrees:e,baseBranch:t}){let{t:r}=z(),i=Gp(e),a=Math.max(120,60+i.length*48+20);return(0,Y.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-[--color-border-dark] bg-[--color-card-dark]/40 p-3`,children:(0,Y.jsxs)(`svg`,{width:`100%`,height:a,viewBox:`0 0 600 ${a}`,className:`min-w-[420px]`,role:`img`,"aria-label":r(`activity:worktree.graphAria`,{base:t||`HEAD`}),children:[(0,Y.jsx)(`title`,{children:r(`activity:worktree.graphAria`,{base:t||`HEAD`})}),(0,Y.jsx)(`line`,{x1:40,y1:20,x2:40,y2:a-10,stroke:`#F93951`,strokeWidth:3}),(0,Y.jsx)(`text`,{x:36,y:14,fontSize:11,fill:`#9ca3af`,children:t||`HEAD`}),(0,Y.jsx)(`circle`,{cx:40,cy:20,r:5,fill:`#F93951`}),i.map(e=>{let i=Kp[e.handle.status]??n(Kp.active),a=e.handle.status===`merged`,o=e.handle.status===`needs-review`||e.handle.status===`failed`;return(0,Y.jsxs)(`g`,{className:`transition-all duration-500`,children:[(0,Y.jsx)(`path`,{d:`M 40 ${e.y-24} C 100 ${e.y-24}, 160 ${e.y}, 220 ${e.y}`,fill:`none`,stroke:e.color,strokeWidth:2,strokeDasharray:i.dash,opacity:i.opacity}),a?(0,Y.jsx)(`path`,{d:`M 220 ${e.y} C 160 ${e.y+20}, 100 ${e.y+24}, 40 ${e.y+24}`,fill:`none`,stroke:`#34d399`,strokeWidth:2,opacity:.9}):null,(0,Y.jsx)(`circle`,{cx:220,cy:e.y,r:5,fill:o?`#e879f9`:e.color}),(0,Y.jsx)(`text`,{x:232,y:e.y-6,fontSize:12,fill:`#e5e7eb`,fontFamily:`monospace`,children:Wp(e.handle.branch)}),(0,Y.jsx)(`text`,{x:232,y:e.y+10,fontSize:10,fill:`#9ca3af`,children:o?`⚠ ${e.handle.status}`:a?r(`activity:worktree.mergedLabel`,{base:t}):`+${e.handle.insertions}/-${e.handle.deletions} · ${e.handle.ownerLabel}`})]},e.handle.handleId)})]})})}var Jp={allocating:{icon:`○`,labelKey:`statusAllocating`,tint:`border-zinc-400/40`,dot:`bg-zinc-400`},active:{icon:`●`,labelKey:`statusActive`,tint:`border-amber-400/40`,dot:`bg-amber-400 animate-pulse`},committing:{icon:`◐`,labelKey:`statusCommitting`,tint:`border-cyan-400/40`,dot:`bg-cyan-400 animate-pulse`},merging:{icon:`⇡`,labelKey:`statusMerging`,tint:`border-blue-400/40`,dot:`bg-blue-400 animate-pulse`},merged:{icon:`✓`,labelKey:`statusMerged`,tint:`border-emerald-400/40`,dot:`bg-emerald-400`},"needs-review":{icon:`⚠`,labelKey:`statusConflict`,tint:`border-fuchsia-400/50`,dot:`bg-fuchsia-400`},failed:{icon:`✗`,labelKey:`statusFailed`,tint:`border-rose-400/50`,dot:`bg-rose-400`}};function Yp(e){return Jp[e]??{icon:`?`,labelKey:``,tint:`border-border`,dot:`bg-muted-foreground`}}var Xp=e=>e.replace(/^wstack\/ap\//,``);function Zp({worktrees:e,baseBranch:t}){let{t:n}=z();if(e.length===0)return null;let r=[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt);return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-card/50 backdrop-blur-sm px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`font-semibold tracking-wide uppercase text-[10px]`,children:n(`activity:worktree.lanesHeading`)}),(0,Y.jsxs)(`span`,{className:`opacity-60`,children:[`· `,n(`activity:worktree.base`)]}),(0,Y.jsx)(`code`,{className:`font-mono text-primary`,children:t||`HEAD`}),(0,Y.jsxs)(`span`,{className:`opacity-60`,children:[`· `,n(`activity:worktree.isolatedCount`,{count:r.length})]})]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>{let t=Yp(e.status),r=e.status===`needs-review`,i=Math.min(100,e.insertions+e.deletions);return(0,Y.jsxs)(`div`,{className:K(`group relative flex items-center gap-3 rounded-lg border px-3 py-2 transition-all duration-500`,`bg-background/60 hover:bg-accent/20`,t.tint),children:[(0,Y.jsx)(`span`,{className:K(`h-2.5 w-2.5 shrink-0 rounded-full`,t.dot),"aria-hidden":!0}),(0,Y.jsx)(`code`,{className:`w-44 shrink-0 truncate font-mono text-sm`,children:Xp(e.branch)}),(0,Y.jsxs)(`span`,{className:`shrink-0 rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:[`⟵ `,e.ownerLabel]}),r?(0,Y.jsx)(`span`,{className:`font-mono text-xs font-bold text-fuchsia-400`,children:n(`activity:worktree.conflictBadge`)}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-xs transition-all duration-500`,children:[(0,Y.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,Y.jsxs)(`span`,{className:`text-rose-500`,children:[`-`,e.deletions]}),(0,Y.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[e.files,`f`]})]}),(0,Y.jsx)(`div`,{className:`ml-auto hidden h-1 w-24 overflow-hidden rounded-full bg-muted sm:block`,children:(0,Y.jsx)(`div`,{className:`h-full bg-gradient-to-r from-emerald-500 to-rose-500 transition-all duration-700`,style:{width:`${i}%`}})}),(0,Y.jsx)(`span`,{className:`w-20 shrink-0 text-right text-xs text-muted-foreground`,children:t.labelKey?n(`activity:worktree.${t.labelKey}`):e.status}),e.recentActivity.length>0?(0,Y.jsxs)(`span`,{className:`absolute -bottom-2 left-9 max-w-[60%] truncate rounded bg-muted px-1.5 text-[10px] text-muted-foreground opacity-0 transition-opacity duration-300 group-hover:opacity-100`,children:[e.recentActivity[e.recentActivity.length-1]?.kind,`: `,e.recentActivity[e.recentActivity.length-1]?.text]}):null]},e.handleId)})})]})}var Qp=e=>e?e.replace(/^wstack\/ap\//,``):``;function $p(){let{t:e}=z(),{client:t}=ts(),n=Mi(e=>e.orphans),r=Mi(e=>e.canClean),i=Mi(e=>e.cleanBlockedReason),a=Mi(e=>e.cleanResult),[o,s]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{t?.send?.({type:`worktree.scan`})},[t]),(0,q.useEffect)(()=>{a&&s(!1)},[a]),n.length===0&&!a?null:(0,Y.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-xs`,children:[n.length>0?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(je,{className:`mt-0.5 h-4 w-4 shrink-0 text-amber-500`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-amber-700 dark:text-amber-300`,children:e(`activity:worktree.orphanCount`,{count:n.length})}),(0,Y.jsxs)(`div`,{className:`mt-0.5 max-h-16 overflow-auto font-mono text-[10px] text-muted-foreground`,children:[n.slice(0,8).map((e,t)=>(0,Y.jsxs)(`div`,{className:`truncate`,children:[e.kind===`branch`?`⌥ `:`▢ `,Qp(e.branch)||e.dir]},`${e.kind}-${e.branch??e.dir??t}`)),n.length>8&&(0,Y.jsx)(`div`,{children:e(`activity:worktree.andMore`,{count:n.length-8})})]})]}),(0,Y.jsxs)(`button`,{type:`button`,disabled:!r||o,onClick:async()=>{let r=n.length;await wu({title:e(`activity:worktree.cleanTitle`,{count:r}),message:e(`activity:worktree.cleanMessage`),confirmLabel:e(`activity:worktree.cleanConfirm`),danger:!0})&&(s(!0),t?.send?.({type:`worktree.cleanup`}))},title:r?e(`activity:worktree.cleanButtonTitle`):i,className:`inline-flex shrink-0 items-center gap-1 rounded bg-amber-600/90 px-2 py-1 font-medium text-white hover:bg-amber-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[o?(0,Y.jsx)(R,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(dt,{className:`h-3.5 w-3.5`}),e(`activity:worktree.cleanConfirm`)]})]}):null,a&&(0,Y.jsx)(`div`,{className:a.ok?`mt-1 text-emerald-600 dark:text-emerald-400`:`mt-1 text-rose-500`,children:a.ok?e(`activity:worktree.removed`,{count:a.removed}):`✗ ${a.reason??e(`activity:worktree.cleanupFailed`)}`})]})}var em={autophase:{active:`bg-primary/15 border-primary/40 text-primary`,idle:`text-primary/80 hover:bg-primary/10`},goal:{active:`bg-rose-500/15 border-rose-500/40 text-rose-600 dark:text-rose-400`,idle:`text-rose-600/80 dark:text-rose-400/80 hover:bg-rose-500/10`},fleet:{active:`bg-emerald-500/15 border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,idle:`text-emerald-600/80 dark:text-emerald-400/80 hover:bg-emerald-500/10`},work:{active:`bg-amber-500/15 border-amber-500/40 text-amber-600 dark:text-amber-400`,idle:`text-amber-600/80 dark:text-amber-400/80 hover:bg-amber-500/10`},worktrees:{active:`bg-violet-500/15 border-violet-500/40 text-violet-600 dark:text-violet-400`,idle:`text-violet-600/80 dark:text-violet-400/80 hover:bg-violet-500/10`},collab:{active:`bg-cyan-500/15 border-cyan-500/40 text-cyan-600 dark:text-cyan-400`,idle:`text-muted-foreground hover:bg-muted/60`}},tm={autophase:`AutoPhase`,goal:`Goal`,fleet:`Fleet`,work:`Work`,worktrees:`Worktrees`,collab:`Collab`},nm=[`autophase`,`goal`,`fleet`,`work`,`worktrees`,`collab`];function rm({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=em[e],{t:c}=z();return(0,Y.jsxs)(`button`,{type:`button`,onClick:o,title:c(i?`activity:dock.collapseChip`:`activity:dock.expandChip`,{label:n}),className:K(`flex items-center gap-2 h-7 px-2.5 rounded-full border text-xs font-medium shrink-0 transition-colors`,i?s.active:K(`border-border/40`,s.idle)),children:[(0,Y.jsx)(`span`,{className:K(a&&`animate-pulse`),children:t}),n,r&&(0,Y.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function im({sessionId:e}){let t=G(e=>e.dockSection),{t:n}=z(),r=G(e=>e.toggleDockSection),i=G(e=>e.hiddenChips),a=G(e=>e.toggleChipHidden),o=G(e=>e.dockCustomizeOpen),s=G(e=>e.setDockCustomizeOpen),c=ui(e=>e.goal),l=xr(e=>e.phases.length),u=xr(e=>e.overallPercent),d=xr(e=>e.activePhaseId),f=Mi(e=>e.worktrees),p=Mi(e=>e.baseBranch),m=W(e=>e.todos),h=X(e=>e.agents),g=Op(),[_,v]=(0,q.useState)(`graph`),y=h.size,b=(0,q.useMemo)(()=>Array.from(h.values()).filter(e=>e.status===`running`).length,[h]),x=m.filter(e=>e.status===`completed`).length,S=m.some(e=>e.status===`in_progress`),C=l>0,w=(0,q.useMemo)(()=>new Set(i),[i]),T={autophase:C,goal:c!==null,fleet:y>0,work:!0,worktrees:f.length>0,collab:!0},E={autophase:(T.autophase||t===`autophase`)&&!w.has(`autophase`),goal:(T.goal||t===`goal`)&&!w.has(`goal`),fleet:(T.fleet||t===`fleet`)&&!w.has(`fleet`),work:(T.work||t===`work`)&&!w.has(`work`),worktrees:(T.worktrees||t===`worktrees`)&&!w.has(`worktrees`),collab:(T.collab||t===`collab`)&&!w.has(`collab`)},D=t&&E[t]?t:null;return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 rounded-lg border border-border/50 bg-muted/20 px-2 py-1.5`,children:[E.autophase&&(0,Y.jsx)(rm,{section:`autophase`,icon:(0,Y.jsx)(_e,{className:`h-3 w-3`}),label:`AutoPhase`,value:`${u}%`,active:!1,pulse:d!=null,onClick:()=>to(`autophase`)}),E.goal&&c&&(0,Y.jsx)(rm,{section:`goal`,icon:(0,Y.jsx)(ln,{className:`h-3 w-3`}),label:`Goal`,value:`${c.progress}%`,active:D===`goal`,pulse:c.goalState===`active`,onClick:()=>r(`goal`)}),E.fleet&&(0,Y.jsx)(rm,{section:`fleet`,icon:(0,Y.jsx)(wt,{className:`h-3 w-3`}),label:`Fleet`,value:`${b}/${y}`,active:D===`fleet`,pulse:b>0,onClick:()=>r(`fleet`)}),(0,Y.jsx)(rm,{section:`work`,icon:(0,Y.jsx)(_n,{className:`h-3 w-3`}),label:`Work`,value:m.length>0?`${x}/${m.length}`:void 0,active:D===`work`,pulse:S,onClick:()=>r(`work`)}),E.worktrees&&(0,Y.jsx)(rm,{section:`worktrees`,icon:(0,Y.jsx)(Yt,{className:`h-3 w-3`}),label:`Worktrees`,value:String(f.length),active:D===`worktrees`,onClick:()=>r(`worktrees`)}),g&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{},className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border border-border/40 text-xs font-mono hover:bg-muted/60 transition-colors`,children:[(0,Y.jsx)(Yt,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-semibold text-foreground`,children:g.branch}),g.ahead>0&&(0,Y.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,title:n(`activity:dock.ahead`,{count:g.ahead}),children:[`↑`,g.ahead]}),g.behind>0&&(0,Y.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,title:n(`activity:dock.behind`,{count:g.behind}),children:[`↓`,g.behind]}),g.added>0&&(0,Y.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,title:n(`activity:dock.linesAdded`,{count:g.added}),children:[`+`,g.added]}),g.deleted>0&&(0,Y.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,title:n(`activity:dock.linesDeleted`,{count:g.deleted}),children:[`-`,g.deleted]}),g.untracked>0&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,title:n(`activity:dock.untrackedFiles`,{count:g.untracked}),children:[g.untracked,`?`]})]}),(0,Y.jsx)(rm,{section:`collab`,icon:(0,Y.jsx)(En,{className:`h-3 w-3`}),label:`Collab`,active:D===`collab`,onClick:()=>r(`collab`)}),(0,Y.jsxs)(Hs,{open:o,onOpenChange:s,children:[(0,Y.jsx)(Us,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,title:n(`activity:dock.customizeTitle`),className:`ml-auto inline-flex items-center justify-center h-7 w-7 rounded-full border border-border/40 text-muted-foreground hover:bg-muted/60 transition-colors shrink-0`,children:(0,Y.jsx)(Ue,{className:`h-3 w-3`})})}),(0,Y.jsxs)(qs,{align:`end`,className:`w-44`,children:[(0,Y.jsx)(Zs,{children:n(`activity:dock.dockChips`)}),(0,Y.jsx)(Qs,{}),nm.map(e=>(0,Y.jsx)(Ys,{checked:!w.has(e),onCheckedChange:()=>a(e),onSelect:e=>e.preventDefault(),children:tm[e]},e))]})]})]}),D&&(0,Y.jsx)(`div`,{className:`border-t border-border/40 pt-2`}),D===`goal`&&(c?(0,Y.jsx)(Mp,{goal:c}):(0,Y.jsx)(am,{title:n(`activity:dock.noActiveGoal`),detail:n(`activity:dock.noActiveGoalDetail`)})),D===`fleet`&&(0,Y.jsx)(Wf,{}),D===`worktrees`&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>v(e),className:K(`text-xs px-2.5 py-0.5 rounded-full border transition-colors capitalize`,_===e?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),(0,Y.jsx)($p,{}),_===`graph`?(0,Y.jsx)(qp,{worktrees:f,baseBranch:p||`HEAD`}):(0,Y.jsx)(Zp,{worktrees:f,baseBranch:p||`HEAD`})]}),(0,Y.jsx)(`div`,{className:K(D===`work`?`block`:`hidden`),id:`panel-work`,children:(0,Y.jsx)(Hp,{})}),(0,Y.jsx)(`div`,{className:K(D===`collab`?`block`:`hidden`),children:(0,Y.jsx)(kp,{sessionId:e})})]})}function am({title:e,detail:t}){return(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border/50 bg-muted/20 px-3 py-2 text-xs`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-foreground`,children:e}),(0,Y.jsx)(`div`,{className:`mt-1 text-muted-foreground`,children:t})]})}var om=(0,q.lazy)(()=>nr(()=>import(`./AnalyticsDashboard-BrQc2ss-.js`).then(e=>({default:e.AnalyticsDashboard})),__vite__mapDeps([18,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17]))),sm=(0,q.lazy)(()=>nr(()=>import(`./AutoPhaseView-8NTdnZ0a.js`).then(e=>({default:e.AutoPhaseView})),__vite__mapDeps([19,1,20,3,2,4,5,6,7,8,9,10,11,12,13,14,15]))),cm=(0,q.lazy)(()=>nr(()=>import(`./CodeEditor-C-pJLtUR.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([21,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,15]))),lm=(0,q.lazy)(()=>nr(()=>import(`./DebugDashboard-BHpiEOcf.js`).then(e=>({default:e.DebugDashboard})),__vite__mapDeps([22,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),um=(0,q.lazy)(()=>nr(()=>import(`./DesignGalleryView-M6Hp7s9b.js`).then(e=>({default:e.DesignGalleryView})),__vite__mapDeps([23,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),dm=(0,q.lazy)(()=>nr(()=>import(`./MailboxDetailView-g3IQx4DB.js`).then(e=>({default:e.MailboxDetailView})),__vite__mapDeps([24,1,2,3,4,5,6,7,8,9,10,11,12,13,14,25,15]))),fm=(0,q.lazy)(()=>nr(()=>import(`./KanbanView-nMv98m0N.js`).then(e=>({default:e.KanbanView})),__vite__mapDeps([26,1,2,3,4,16,17,15]))),pm=(0,q.lazy)(()=>nr(()=>import(`./OfficeMapPanel-D3VE7UCd.js`).then(e=>({default:e.OfficeMapPanel})),__vite__mapDeps([27,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,15,28,29]))),mm=(0,q.lazy)(()=>nr(()=>import(`./ProcessMonitor-CbfQYneY.js`).then(e=>({default:e.ProcessMonitor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),hm=(0,q.lazy)(()=>nr(()=>import(`./QueuePanel-eGK1SSKx.js`).then(e=>({default:e.QueuePanel})),__vite__mapDeps([30,1,20,3,2,4,5,6,7,8,9,10,11,12,13,14,15]))),gm=(0,q.lazy)(()=>nr(()=>import(`./RefreshDebugView-BXq2P3wo.js`).then(e=>({default:e.RefreshDebugView})),__vite__mapDeps([31,1,20,3,2,4,5,6,7,8,9,10,11,12,13,14,17,25]))),_m=(0,q.lazy)(()=>nr(()=>import(`./SddBoardView-DvuH4f4e.js`).then(e=>({default:e.SddBoardView})),__vite__mapDeps([32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,33,28,29]))),vm=(0,q.lazy)(()=>nr(()=>import(`./SddWizard-G55Yw9Bb.js`).then(e=>({default:e.SddWizard})),__vite__mapDeps([34,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,33,28,29]))),ym=(0,q.lazy)(()=>nr(()=>import(`./SessionsDashboard-Dqsrp5CK.js`).then(e=>({default:e.SessionsDashboard})),__vite__mapDeps([35,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),bm=(0,q.lazy)(()=>nr(()=>import(`./SkillDetailView-CX9zeWBG.js`).then(e=>({default:e.SkillDetailView})),__vite__mapDeps([36,1,2,3,4,5,6,7,8,9,10,11,12,13,14,25,15]))),xm=(0,q.lazy)(()=>nr(()=>import(`./SpecsView-BnUsqkrG.js`).then(e=>({default:e.SpecsView})),__vite__mapDeps([37,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Sm=(0,q.lazy)(()=>nr(()=>import(`./TerminalPanel-BCpddej2.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([38,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,25,15,39,40])));function Cm({label:e}){return(0,Y.jsx)(`div`,{className:`flex flex-1 min-h-0 min-w-0 items-center justify-center bg-background text-muted-foreground`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-muted-foreground/30 border-t-primary`}),e?(0,Y.jsx)(`span`,{className:`text-xs`,children:e}):null]})})}function wm(){let{theme:e}=Vs(),t=Ka(),{currentView:r,sidebarOpen:a,toggleSidebar:o,setSearchOpen:s,setSidebarOpen:c,setInspectorTab:l,setPaletteOpen:u,setShortcutsOpen:d,setModelSwitcherOpen:f,setPromptLibraryOpen:p,toggleInspector:m,fleetMonitorOpen:h,agentsMonitorOpen:g,setFleetMonitorOpen:_,setAgentsMonitorOpen:v,processMonitorOpen:y,setProcessMonitorOpen:b,queuePanelOpen:x,setQueuePanelOpen:S,terminalOpen:C,setTerminalOpen:w}=G(),T=i(e=>e.isLoading),E=W(e=>e.iteration),D=W(e=>e.projectName),O=W(e=>e.session?.title),k=W(e=>e.session?.id),A=G(e=>k?e.sessionNicknames[k]:void 0);return(0,q.useEffect)(()=>{t&&dr({sidebarOpen:!1})},[t]),(0,q.useEffect)(()=>{typeof window>`u`||(window.location.pathname===`/debug`?no(`debug`):window.location.pathname===`/analytics`?no(`analytics`):window.location.pathname===`/refresh-debug`&&no(`refresh-debug`))},[]),(0,q.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=U(J.getState().wsUrl);n&&n.send({type:`files.read`,payload:{filePath:t}})};return window.addEventListener(`wrongstack:open-file`,e),()=>window.removeEventListener(`wrongstack:open-file`,e)},[]),(0,q.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=Ir.getState().openFiles.find(e=>e.path===t);if(!n)return;let r=U(J.getState().wsUrl);r&&r.send({type:`files.write`,payload:{filePath:t,content:n.content}})};return window.addEventListener(`wrongstack:save-file`,e),()=>window.removeEventListener(`wrongstack:save-file`,e)},[]),(0,q.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: 768px)`),t=()=>{e.matches&&G.getState().sidebarOpen&&c(!1)};return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[c]),es(),(0,q.useEffect)(()=>(as(),$n.subscribe((e,t)=>{e.yolo===t.yolo&&e.nextPrediction===t.nextPrediction&&e.contextAutoCompact===t.contextAutoCompact||as()})),[]),(0,q.useEffect)(()=>{let e=e=>{let t=e&&typeof e==`object`&&!Array.isArray(e)?e:{},n=G.getState(),r=U(J.getState().wsUrl),a=!1,o=e=>{no(e),e===`sessions`&&r?.listSessions?.(50)},c=t.activity;if(typeof c==`string`&&cc.includes(c)){let e=c;Q(e),a=!0,t.view===void 0&&Za(e)===`sessions`&&r?.listSessions?.(50)}let l=t.view;typeof l==`string`&&ns.has(l)&&(o(l),a=!0);let m=t.action;m===`new-session`?(r?.newSession?.(),Q(`chat`),a=!0):m===`clear-context`?(sr.dropAll(),i.getState().clearMessages(),r?.clearContext?.(),Q(`chat`),a=!0):m===`compact-context`?(r?.compactContext?.(),Q(`chat`),a=!0):m===`repair-context`?(r?.repairContext?.(),Q(`chat`),a=!0):m===`download-chat`?($c(),a=!0):m===`focus-chat`?(Q(`chat`),window.requestAnimationFrame(()=>document.querySelector(`textarea`)?.focus()),a=!0):m===`open-command-palette`?(u(!0),a=!0):m===`open-shortcuts`?(d(!0),a=!0):m===`search-chat`?(s(!0),a=!0):m===`open-model-switcher`?(f(!0),a=!0):m===`open-prompt-library`&&(p(!0),a=!0);let h=t.dockSection;if(typeof h==`string`&&rs.has(h)){let e=h;if(n.showDockChip(e),n.setDockCustomizeOpen(!1),a=!0,h===`autophase`)return to(`autophase`),n.setDockSection(null),a;Q(`chat`),n.setDockSection(e),h===`goal`&&r?.send?.({type:`goal.get`})}let g=t.workTab;typeof g==`string`&&is.has(g)&&(n.showDockChip(`work`),n.setDockCustomizeOpen(!1),Q(`chat`),n.setDockSection(`work`),n.setWorkDashboardTab(g),a=!0,g===`plan`&&r?.getPlan?.());let y=t.overlay;y===`fleet`?(_(!0),a=!0):y===`agents-monitor`?(v(!0),a=!0):y===`processes`?(b(!0),a=!0):y===`queue`&&(S(!0),a=!0),t.terminal===`toggle`?(n.toggleTerminal(),a=!0):t.terminal===`new`?(n.terminalOpen?n.requestTerminalCreate():w(!0),a=!0):t.terminal===!0?(w(!0),a=!0):t.terminal===!1&&(w(!1),a=!0);let x=t.pref;if(x&&typeof x==`object`&&!Array.isArray(x)){let e=x,t=e.key;if(t===`yolo`||t===`nextPrediction`||t===`contextAutoCompact`){let n=$n.getState(),i=e.toggle===!0?!n[t]:e.value;if(typeof i==`boolean`){let e={[t]:i};n.set(e),r?.updatePrefs?.(e),t===`yolo`&&Z.info(`YOLO ${i?`enabled`:`disabled`}`),a=!0}}}return a},t=new Set,n=[],r=e=>{for(t.add(e),n.push(e);n.length>120;){let e=n.shift();e&&t.delete(e)}},a=n=>{let i=(n&&typeof n==`object`&&!Array.isArray(n)?n:{}).requestId;if(typeof i==`string`&&t.has(i)){ss(i,!0);return}try{let t=e(n);t&&typeof i==`string`&&r(i),ss(i,t)}catch(e){ss(i,!1,e instanceof Error?e.message:String(e)),console.error(`Failed to handle desktop command:`,e)}},o=window.wrongstackDesktopCommands?.subscribe?.(e=>{a(e)})??null,c=e=>{a(e.detail)};return window.addEventListener(`wrongstack:desktop-command`,c),window.__wrongstackDesktopReady=!0,os(!0),()=>{window.__wrongstackDesktopReady=!1,os(!1),o&&o(),window.removeEventListener(`wrongstack:desktop-command`,c)}},[v,_,f,u,p,b,S,s,d,w]),(0,q.useEffect)(()=>{let e=()=>{try{let e=[W,i,G,J];for(let t of e){let e=t.persist;e&&typeof e.flush==`function`&&e.flush()}}catch{}};return window.addEventListener(`pagehide`,e),window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`pagehide`,e),window.removeEventListener(`beforeunload`,e)}},[]),(0,q.useEffect)(()=>{if(typeof window>`u`||window.location.pathname===`/refresh-debug`)return;let e=G.getState().currentView;(e===`debug`||e===`analytics`||e===`design-gallery`||e===`setup`)&&Q(`chat`)},[]),(0,q.useEffect)(()=>{let e=[];if(T){let t=E?` iter ${E.index}${E.max?`/${E.max}`:``}`:``;e.push(`●${t}`)}let t=A?.trim()||O?.trim(),n=D?.trim();t&&e.push(t),n&&e.push(n),e.length===0&&e.push(n||`AI Agent`);let r=e.filter(Boolean).join(` · `);return document.title=r,()=>{document.title=D||`AI Agent`}},[T,E,D,O,A]),(0,q.useEffect)(()=>{let e=e=>{let t=e.target,r=t?.tagName?.toLowerCase(),a=r===`input`||r===`textarea`||t?.isContentEditable,c=e.ctrlKey||e.metaKey;if(c&&e.key===`\\`){e.preventDefault(),o();return}if(c&&e.key==="`"){e.preventDefault(),G.getState().toggleTerminal();return}if(c&&!e.shiftKey&&!e.altKey&&Object.hasOwn(Ya,e.key)){let t=Ya[e.key];if(t){e.preventDefault(),eo(t);return}}if(c&&e.shiftKey&&!e.altKey&&e.key.toLowerCase()===`w`){e.preventDefault(),eo(`worktrees`);return}if(!a&&!c&&!e.altKey&&/^F([1-9]|1[0-2])$/.test(e.key)){e.preventDefault();let t=G.getState(),n=U(J.getState().wsUrl),r=Number(e.key.slice(1));switch(t.setDockCustomizeOpen(!1),r){case 1:eo(`chat`);return;case 2:t.setFleetMonitorOpen(!0);return;case 3:t.setAgentsMonitorOpen(!0);return;case 4:Q(`worktrees`),t.setDockSection(`worktrees`);return;case 5:n?.getPlan?.(),Q(`chat`),t.setDockSection(`work`),t.setWorkDashboardTab(`plan`);return;case 6:Q(`chat`),t.setDockSection(`work`),t.setWorkDashboardTab(`todos`);return;case 7:t.setQueuePanelOpen(!0);return;case 8:t.setProcessMonitorOpen(!0);return;case 9:n?.send?.({type:`goal.get`}),Q(`chat`),t.setDockSection(`goal`);return;case 10:n?.listSessions?.(50),Q(`history`);return;case 11:Q(`officemap`);return;case 12:Q(`chat`),t.setDockSection(`work`),t.setDockCustomizeOpen(!0);return}}if(c&&e.key.toLowerCase()===`f`){e.preventDefault(),s(!0);return}if(c&&e.key.toLowerCase()===`/`){e.preventDefault(),document.querySelector(`textarea`)?.focus();return}if(c&&!a&&(e.key.toLowerCase()===`l`?(e.preventDefault(),sr.dropAll(),i.getState().clearMessages(),U(J.getState().wsUrl)?.clearContext?.()):e.key.toLowerCase()===`n`?(e.preventDefault(),U(J.getState().wsUrl)?.newSession?.(),Q(`chat`)):e.key.toLowerCase()===`e`&&(e.preventDefault(),$c())),c&&e.shiftKey&&e.key.toLowerCase()===`d`&&(e.preventDefault(),G.getState().toggleCompactMode()),c&&e.shiftKey&&e.key.toLowerCase()===`m`){e.preventDefault();let t=G.getState();t.inspectorOpen&&t.inspectorTab===`fleet`?m():(l(`fleet`),t.inspectorOpen||m())}if(c&&e.shiftKey&&e.key.toLowerCase()===`a`){e.preventDefault();let t=G.getState();t.inspectorOpen&&t.inspectorTab===`agents`?m():(l(`agents`),t.inspectorOpen||m())}if(c&&e.shiftKey&&e.key.toLowerCase()===`g`&&(e.preventDefault(),no(`debug`)),e.key===`Escape`&&!c&&G.getState().inspectorOpen&&G.getState().setInspectorOpen(!1),!a&&!c&&!e.altKey){let t=Array.from(document.querySelectorAll(`[data-message-id]`));if(t.length===0)return;let r=document.querySelector(`[data-message-id][data-focused="true"]`),i=r?t.indexOf(r):-1,a=e=>{for(let e of t)e.removeAttribute(`data-focused`);e.setAttribute(`data-focused`,`true`),e.scrollIntoView({behavior:`smooth`,block:`center`})};if(e.key===`j`||e.key===`ArrowDown`){let n=t[Math.min(t.length-1,Math.max(0,i+1))];n&&(e.preventDefault(),a(n));return}if(e.key===`k`||e.key===`ArrowUp`){let n=t[Math.max(0,i<=0?0:i-1)];n&&(e.preventDefault(),a(n));return}if(e.key===`g`&&!e.shiftKey){e.preventDefault(),a(n(t[0]));return}if(e.key===`G`||e.key===`g`&&e.shiftKey){e.preventDefault(),a(n(t[t.length-1]));return}if(e.key===`Escape`&&r){e.preventDefault(),r.removeAttribute(`data-focused`);return}if(e.key===`c`&&r){let t=r.querySelector(`.markdown-content`)?.innerText??r.innerText;t&&(navigator.clipboard?.writeText(t).catch(()=>{}),e.preventDefault());return}}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o,s]),(0,Y.jsxs)(`div`,{"data-shell":t?`desktop`:`browser`,className:K(`ws-app-root flex min-h-0 min-w-0 overflow-hidden`,t&&`ws-desktop-shell`,e),children:[r!==`setup`&&(0,Y.jsx)(dc,{desktopShell:t}),a&&r!==`setup`&&(0,Y.jsx)(Dp,{desktopShell:t}),(0,Y.jsxs)(`main`,{className:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[r!==`setup`&&(0,Y.jsx)(ku,{}),r===`chat`&&(0,Y.jsxs)(Y.Fragment,{children:[k&&(0,Y.jsx)(`div`,{className:K(`ws-workspace-dock-wrap px-4 pt-2 shrink-0 overflow-y-auto overscroll-contain`,C?`max-h-[28dvh]`:`max-h-[45dvh]`),children:(0,Y.jsx)(im,{sessionId:k})}),(0,Y.jsx)(Au,{level:`panel`,name:`Chat`,children:(0,Y.jsx)(vu,{})}),(0,Y.jsx)(Au,{level:`panel`,name:`Inspector`,children:(0,Y.jsx)(ld,{})})]}),r===`settings`&&(0,Y.jsx)(Au,{level:`panel`,name:`Settings`,children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(ff,{})})}),r===`setup`&&(0,Y.jsx)(Au,{level:`panel`,name:`Setup`,children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(Nf,{})})}),r===`autophase`&&(0,Y.jsx)(Au,{level:`panel`,name:`AutoPhase`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(sm,{onClose:()=>Q(`chat`)})})})}),r===`specs`&&(0,Y.jsx)(Au,{level:`panel`,name:`Specs`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(xm,{onClose:()=>Q(`chat`)})})})}),r===`kanban`&&(0,Y.jsx)(Au,{level:`panel`,name:`Kanban`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(fm,{onClose:()=>Q(`chat`)})})})}),r===`sddboard`&&(0,Y.jsx)(Au,{level:`panel`,name:`SDD Board`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(_m,{onClose:()=>Q(`chat`)})})})}),r===`sddwizard`&&(0,Y.jsx)(Au,{level:`panel`,name:`SDD Wizard`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(vm,{onClose:()=>Q(`chat`)})})})}),r===`sessions`&&(0,Y.jsx)(Au,{level:`panel`,name:`Sessions`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-y-auto`,children:(0,Y.jsx)(ym,{})})})}),r===`debug`&&(0,Y.jsx)(Au,{level:`panel`,name:`Debug Dashboard`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(lm,{})})})}),r===`refresh-debug`&&(0,Y.jsx)(Au,{level:`panel`,name:`Refresh Debug`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(gm,{})})})}),r===`files`&&(0,Y.jsx)(Au,{level:`panel`,name:`Editor`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{label:`Loading editor…`}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(cm,{})})})}),r===`changes`&&(0,Y.jsx)(Au,{level:`panel`,name:`Changes`,children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(Sc,{className:`h-full min-h-0`})})}),r===`mailbox`&&(0,Y.jsx)(Au,{level:`panel`,name:`Mailbox`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(dm,{className:`h-full min-h-0`})})})}),r===`design-gallery`&&(0,Y.jsx)(Au,{level:`panel`,name:`Design Gallery`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(um,{className:`h-full`})})})}),r===`skill`&&(0,Y.jsx)(Au,{level:`panel`,name:`Skill`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(bm,{className:`h-full`})})})}),r===`officemap`&&(0,Y.jsx)(Au,{level:`panel`,name:`Office Map`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{label:`Loading map…`}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(pm,{})})})}),r===`analytics`&&(0,Y.jsx)(Au,{level:`panel`,name:`Analytics`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{}),children:(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(0,Y.jsx)(om,{})})})}),C&&(0,Y.jsx)(Au,{level:`panel`,name:`Terminal`,children:(0,Y.jsx)(q.Suspense,{fallback:(0,Y.jsx)(Cm,{label:`Loading terminal…`}),children:(0,Y.jsx)(Sm,{desktopShell:t,onClose:()=>w(!1)})})})]}),h&&(0,Y.jsx)(Au,{level:`panel`,name:`Fleet Monitor`,children:(0,Y.jsx)(Xu,{onClose:()=>_(!1)})}),g&&(0,Y.jsx)(Au,{level:`panel`,name:`Agents Monitor`,children:(0,Y.jsx)(q.Suspense,{fallback:null,children:(0,Y.jsx)(Rs,{onClose:()=>v(!1)})})}),y&&(0,Y.jsx)(Au,{level:`panel`,name:`Process Monitor`,children:(0,Y.jsx)(q.Suspense,{fallback:null,children:(0,Y.jsx)(mm,{open:y,onClose:()=>b(!1)})})}),x&&(0,Y.jsx)(Au,{level:`panel`,name:`Queue`,children:(0,Y.jsx)(q.Suspense,{fallback:null,children:(0,Y.jsx)(hm,{open:x,onClose:()=>S(!1)})})}),(0,Y.jsx)(xu,{}),(0,Y.jsx)(Tu,{}),(0,Y.jsx)(Ou,{}),(0,Y.jsx)(tl,{}),(0,Y.jsx)(Ff,{}),(0,Y.jsx)(md,{}),(0,Y.jsx)(Ri,{})]})}function Tm(){return(0,Y.jsx)(Au,{children:(0,Y.jsx)(Bs,{defaultTheme:`system`,children:(0,Y.jsx)(wm,{})})})}xf(),fr.createRoot(n(document.getElementById(`root`))).render((0,Y.jsx)(q.StrictMode,{children:(0,Y.jsx)(Tm,{})}));export{Di as A,ts as C,ji as D,Mi as E,X as F,Ir as I,Fr as L,yi as M,fi as N,ki as O,Xr as P,J as R,xs as S,Q as T,qc as _,Sd as a,vc as b,eu as c,Xl as d,Jl as f,Yc as g,Gc as h,Cd as i,Ei as j,Oi as k,$l as l,Hc as m,Zp as n,hd as o,$ as p,qp as r,Du as s,$p as t,Zl as u,Kc as v,to as w,Vs as x,Jc as y,xr as z};