@wrongstack/webui 1.0.13 → 1.0.14

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 (35) hide show
  1. package/dist/assets/{AgentRosterView-BuAsY8eB.js → AgentRosterView-DMxOg0xX.js} +1 -1
  2. package/dist/assets/{AnalyticsDashboard-iIkpKNGk.js → AnalyticsDashboard-DGQk1vSi.js} +1 -1
  3. package/dist/assets/{AudienceMemoryPanel-CgKWvpxv.js → AudienceMemoryPanel-CyfpggCK.js} +1 -1
  4. package/dist/assets/{ChangesView-Cd3Tl17b.js → ChangesView-C8x8tmpi.js} +1 -1
  5. package/dist/assets/{ChimeraReviewsView-CWo6AV3H.js → ChimeraReviewsView-DencEMIY.js} +1 -1
  6. package/dist/assets/{ChronicleDashboard-D8HEQ32t.js → ChronicleDashboard-CvDPqZKE.js} +1 -1
  7. package/dist/assets/{CodeEditor-BmnUVoHj.js → CodeEditor-s0lHP0DZ.js} +1 -1
  8. package/dist/assets/{CodeMap-CYr1LK2u.js → CodeMap-6mmDO9gJ.js} +1 -1
  9. package/dist/assets/{CronJobsPanel-B9X-N_ft.js → CronJobsPanel-LoDmuRHl.js} +1 -1
  10. package/dist/assets/{DebugDashboard-KEZZY9pu.js → DebugDashboard-BP1Mia-L.js} +1 -1
  11. package/dist/assets/{DesignGalleryView-DWDsOUD3.js → DesignGalleryView-taDxRN63.js} +1 -1
  12. package/dist/assets/{GoalView-CmRWtduc.js → GoalView-CcLxMYXe.js} +1 -1
  13. package/dist/assets/{KanbanView-BVHyGhDq.js → KanbanView-C-K6OBw8.js} +1 -1
  14. package/dist/assets/{MailboxDetailView-COFzilLE.js → MailboxDetailView-N00dLbpr.js} +1 -1
  15. package/dist/assets/{MemoryDrawer-m9ZlZ_xi.js → MemoryDrawer-CuFQypU-.js} +1 -1
  16. package/dist/assets/{MemoryManager-Bb_RMZhJ.js → MemoryManager-Bmz62aEV.js} +1 -1
  17. package/dist/assets/{ProcessMonitor-Btj6_6aw.js → ProcessMonitor-CkAtUjrR.js} +1 -1
  18. package/dist/assets/{ProviderTestView-CVKjGm2z.js → ProviderTestView-Dy7EQEI9.js} +1 -1
  19. package/dist/assets/{QueuePanel-CSlu_Hat.js → QueuePanel-DE9ySxkR.js} +1 -1
  20. package/dist/assets/{RepositoryHistoryView-CIsxftEC.js → RepositoryHistoryView-D0ynYRgu.js} +1 -1
  21. package/dist/assets/{RequirementIntakeView-Dah2aHco.js → RequirementIntakeView-CPRtncuJ.js} +1 -1
  22. package/dist/assets/{SageTabs-GuriCwuB.js → SageTabs-Dwbux3im.js} +2 -2
  23. package/dist/assets/{SddHub-C7IlzHtw.js → SddHub-CoRKeq7Q.js} +1 -1
  24. package/dist/assets/{SessionInspectView-_qPDgZXH.js → SessionInspectView-Bak1hK82.js} +1 -1
  25. package/dist/assets/{SessionList-nn7wHkrG.js → SessionList-xXaygO5X.js} +1 -1
  26. package/dist/assets/{SessionsDashboard-BjevWtcd.js → SessionsDashboard-CaSXukNy.js} +1 -1
  27. package/dist/assets/{SetupScreen-DCupHAif.js → SetupScreen-BSEF1air.js} +1 -1
  28. package/dist/assets/{SkillDetailView-EaPGctff.js → SkillDetailView-OdtAJM43.js} +1 -1
  29. package/dist/assets/{TechStackView-DXoJPVZf.js → TechStackView-BUIbnU2F.js} +1 -1
  30. package/dist/assets/{TerminalPanel-DxAt_S44.js → TerminalPanel-CfoKklMj.js} +1 -1
  31. package/dist/assets/{index-B70B52lT.js → index-3TGBKeBP.js} +5 -5
  32. package/dist/assets/{stores-DxKcenvb.js → stores-RkHrTaRO.js} +1 -1
  33. package/dist/index.html +2 -2
  34. package/dist/index.js +36 -36
  35. package/package.json +9 -9
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/config-store-BAUadwHd.js","assets/rolldown-runtime-hePW80VL.js","assets/react-core-wiHys0m2.js","assets/vendor-V3ydTHqN.js","assets/xyflow-BqDBClm9.js","assets/xyflow-DLioOiRN.css","assets/markdown-CXRzjX3p.js","assets/vendor-jL-bRT8f.css","assets/i18n-CbyUyl6G.js","assets/chat-BITJe8-v.js","assets/commandPalette-BovBiPec.js","assets/common-CmkkiJUR.js","assets/setup-qooXjj4V.js","assets/toasts-DZ6HdKgG.js","assets/vite-preload-BZ1Pz5am.js","assets/utils-CKsqCaP8.js","assets/ui-store-DC3mkswy.js","assets/fonts-DRGbd-AM.js","assets/AnalyticsDashboard-iIkpKNGk.js","assets/stores-DxKcenvb.js","assets/chat-store-DNRce6sE.js","assets/codemap-activity-store-Ha7XbGgq.js","assets/mailbox-store-C49LeBj8.js","assets/AgentRosterView-BuAsY8eB.js","assets/view-navigation-DHtNFXIl.js","assets/roster-ws-z8DKquaN.js","assets/AudienceMemoryPanel-CgKWvpxv.js","assets/dialog-C7EIBM_2.js","assets/button-9ewV4TF3.js","assets/input-ag1CrUiS.js","assets/shared-BFJvAYzX.js","assets/AgentRosterView-Cv9-DYty.css","assets/ChangesView-Cd3Tl17b.js","assets/monaco-CbI7qrVD.js","assets/monaco-Bowa0-zp.css","assets/empty-state-5YP1rmE6.js","assets/monaco-theme-Dr3-rSid.js","assets/RepositoryHistoryView-CIsxftEC.js","assets/ChronicleDashboard-D8HEQ32t.js","assets/CodeEditor-BmnUVoHj.js","assets/MemoryDrawer-m9ZlZ_xi.js","assets/CodeMap-CYr1LK2u.js","assets/DebugDashboard-KEZZY9pu.js","assets/DesignGalleryView-DWDsOUD3.js","assets/GoalView-CmRWtduc.js","assets/KanbanView-BVHyGhDq.js","assets/SddFlowGraph-BZkvlaQ1.js","assets/MailboxDetailView-COFzilLE.js","assets/PromptJournalView-CdC4ldrv.js","assets/RefreshDebugView-Dbq_bHwj.js","assets/SageTabs-GuriCwuB.js","assets/RequirementIntakeView-Dah2aHco.js","assets/SddHub-C7IlzHtw.js","assets/SessionsDashboard-BjevWtcd.js","assets/SessionList-nn7wHkrG.js","assets/SessionInspectView-_qPDgZXH.js","assets/SkillDetailView-EaPGctff.js","assets/TechStackView-DXoJPVZf.js","assets/DeadCodeScanPanel-ByhAW_bl.js","assets/ChimeraReviewsView-CWo6AV3H.js","assets/SetupScreen-DCupHAif.js","assets/ProviderTestView-CVKjGm2z.js","assets/ProcessMonitor-Btj6_6aw.js","assets/TerminalPanel-DxAt_S44.js","assets/xterm-DA3G7037.js","assets/xterm-BrP-ENHg.css","assets/CronJobsPanel-B9X-N_ft.js","assets/QueuePanel-CSlu_Hat.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,At as r,B as i,Bt as a,C as o,Ct as s,D as c,Dt as l,E as u,Et as d,F as f,Ft as p,G as m,Gt as h,H as g,Ht as _,I as v,It as y,J as b,Jt as x,K as S,Kt as C,L as w,Lt as T,M as E,Mt as D,N as O,Nt as k,O as A,Ot as j,P as M,Q as N,R as P,Rt as F,S as I,St as L,T as ee,U as R,Ut as z,V as te,Vt as ne,W as re,Wt as ie,X as ae,Xt as oe,Y as se,Yt as ce,Z as B,_ as le,_t as ue,a as de,at as fe,b as pe,bt as me,c as he,ct as ge,d as _e,dt as ve,et as ye,f as be,ft as xe,g as Se,gt as Ce,h as we,ht as Te,i as Ee,j as De,jt as Oe,k as ke,kt as Ae,l as je,lt as Me,m as Ne,mt as Pe,n as Fe,nt as Ie,o as Le,ot as Re,p as ze,pt as Be,qt as Ve,r as He,rt as Ue,s as We,st as Ge,t as V,tt as H,u as Ke,ut as qe,v as Je,vt as Ye,w as Xe,x as Ze,xt as Qe,y as $e,yt as et,zt as tt}from"./config-store-BAUadwHd.js";import{i as nt,n as rt,t as it}from"./react-core-wiHys0m2.js";import{$ as at,$a as ot,$i as st,$n as ct,$t as lt,Aa as ut,Ai as dt,An as ft,Ar as pt,Ba as mt,Bi as ht,Br as gt,Bt as _t,Ca as vt,Ci as yt,Cn as bt,Cr as xt,Ct as St,Da as Ct,Di as wt,Dn as Tt,Dr as Et,Dt,Ea as Ot,Ei as kt,En as At,Er as jt,Et as Mt,Fa as Nt,Fi as Pt,Fn as Ft,Fr as It,Ft as Lt,G as Rt,Gi as zt,Gn as Bt,Gr as Vt,Gt as Ht,H as Ut,Ha as Wt,Hi as Gt,Hn as Kt,Ht as qt,Ia as Jt,Ii as Yt,In as Xt,It as Zt,J as Qt,Ja as $t,Ji as en,Jn as tn,Jr as nn,Jt as rn,K as an,Ka as on,Kn as sn,Kr as cn,La as ln,Ln as un,Lr as dn,Lt as fn,Ma as pn,Mr as mn,Mt as hn,Na as gn,Nt as _n,Oa as vn,Oi as yn,Or as bn,Pa as xn,Pi as Sn,Pn as Cn,Pr as wn,Pt as Tn,Q as En,Qa as Dn,Qi as On,Qn as kn,Qr as An,Qt as jn,Ra as Mn,Ri as Nn,Rn as Pn,Rr as Fn,Rt as In,Si as Ln,Sr as Rn,St as zn,Ta as Bn,Ti as Vn,Tn as Hn,Tt as Un,U as Wn,Ui as Gn,Ur as Kn,Ut as qn,Va as Jn,Vn as Yn,Vr as Xn,W as Zn,Wa as Qn,Wi as $n,Wn as er,Wr as tr,X as nr,Xa as rr,Xi as ir,Xn as ar,Xr as or,Xt as sr,Y as cr,Yi as lr,Yn as ur,Yt as dr,Z as fr,Za as pr,Zi as mr,Zn as hr,Zr as gr,Zt as _r,_i as vr,_r as yr,_t as br,ai as xr,an as Sr,ao as Cr,ar as wr,at as Tr,ba as Er,bi as Dr,bn as Or,br as kr,bt as Ar,ci as jr,cn as Mr,co as Nr,ct as Pr,da as Fr,dn as Ir,do as Lr,dt as Rr,ea as zr,ei as Br,eo as Vr,et as Hr,fi as Ur,fn as Wr,fr as Gr,ft as Kr,ga as qr,gi as Jr,go as Yr,gr as Xr,gt as Zr,ha as Qr,hi as $r,hn as ei,ho as ti,hr as ni,ht as ri,ia as ii,ii as ai,in as oi,io as si,ir as ci,it as li,ja as ui,ji as di,jn as fi,jr as pi,jt as mi,ka as hi,kn as gi,kr as _i,la as vi,lo as yi,lr as bi,lt as xi,ma as Si,mn as Ci,mo as wi,mr as Ti,mt as Ei,na as Di,ni as Oi,nn as ki,nr as Ai,nt as ji,oa as Mi,oi as Ni,on as Pi,oo as Fi,or as Ii,ot as Li,pa as Ri,pi as zi,pn as Bi,pr as Vi,pt as Hi,q as Ui,qi as Wi,qn as Gi,qr as Ki,qt as qi,ra as Ji,ri as Yi,rn as Xi,ro as Zi,rr as Qi,rt as $i,si as ea,sn as ta,so as na,sr as ra,st as ia,ti as aa,tn as oa,to as sa,tt as ca,ua as la,ui as ua,un as da,uo as fa,ur as pa,ut as ma,vn as ha,vo as ga,vr as _a,vt as va,wa as ya,wi as ba,wn as xa,wo as U,wr as Sa,wt as Ca,xn as wa,xo as W,xr as Ta,xt as Ea,yi as Da,yn as Oa,yr as ka,yt as Aa,zi as ja,zn as Ma,zt as Na}from"./vendor-V3ydTHqN.js";import{i as Pa,n as G,r as Fa,t as Ia}from"./i18n-CbyUyl6G.js";import{t as La}from"./vite-preload-BZ1Pz5am.js";import{t as K}from"./utils-CKsqCaP8.js";import{a as Ra,i as za,n as Ba,o as Va,r as Ha,s as Ua,t as Wa}from"./view-navigation-DHtNFXIl.js";import{a as Ga,i as Ka,n as q,r as qa,t as Ja}from"./ui-store-DC3mkswy.js";import{C as Ya,D as Xa,E as Za,O as Qa,S as $a,T as eo,_ as to,a as no,b as ro,c as io,d as ao,h as oo,i as so,l as co,m as lo,n as uo,o as fo,r as po,s as mo,t as ho,u as go,v as _o,w as vo,x as yo,y as bo}from"./stores-DxKcenvb.js";import{t as J}from"./chat-store-DNRce6sE.js";import{i as xo,n as So}from"./codemap-activity-store-Ha7XbGgq.js";import{C as Co,S as wo,_ as To,a as Eo,b as Do,c as Oo,d as ko,f as Ao,g as jo,h as Mo,i as No,l as Po,m as Fo,n as Io,o as Lo,p as Ro,r as zo,s as Bo,t as Vo,u as Ho,v as Uo,w as Wo,x as Go}from"./fonts-DRGbd-AM.js";import{n as Ko,r as qo,t as Jo}from"./mailbox-store-C49LeBj8.js";import{a as Yo,i as Xo,n as Zo,o as Qo,r as $o,t as es}from"./dialog-C7EIBM_2.js";import{t as Y}from"./button-9ewV4TF3.js";import{t as ts}from"./input-ag1CrUiS.js";import{c as ns,u as rs}from"./markdown-CXRzjX3p.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),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var is=new Set([`mode_changed`,`compaction`,`checkpoint`,`skill_activated`,`skill_deactivated`,`agent_spawned`,`agent_session_linked`,`agent_stopped`,`agent_error`,`delegate_started`,`delegate_completed`,`loop_detected`,`model_switched`,`error`,`provider_retry`,`provider_error`,`message_truncated`]),as=new Set([`checkpoint`,`agent_spawned`,`agent_session_linked`,`agent_stopped`,`agent_error`,`delegate_started`,`delegate_completed`]);new Set([...is].filter(e=>!as.has(e)));function os(e){switch(e.type){case`compaction`:{let t=(e.before/1e3).toFixed(0),n=(e.after/1e3).toFixed(0),r=e.level?` (${e.level})`:``,i=e.reductions&&e.reductions.length>0?` [${e.reductions.map(e=>`${e.phase}: \u2212${e.saved}`).join(`, `)}]`:``;return{ts:e.ts,source:e.type,level:`info`,text:`\u27F2 context compacted${r}: ${t}K \u2192 ${n}K tokens${i}`}}case`error`:return{ts:e.ts,source:e.type,level:`error`,text:e.phase?`[${e.phase}] ${e.message}`:e.message};case`provider_retry`:{let t=(e.delayMs/1e3).toFixed(e.delayMs>=1e3?1:2);return{ts:e.ts,source:e.type,level:`warn`,text:e.status?`\u27F3 retry ${e.attempt} (HTTP ${e.status}) after ${t}s \u2014 ${e.description}`:`\u27F3 retry ${e.attempt} after ${t}s \u2014 ${e.description}`}}case`provider_error`:return{ts:e.ts,source:e.type,level:`error`,text:e.status?`provider error (HTTP ${e.status}, ${e.retryable?`retryable`:`fatal`}): ${e.description}`:`provider error (${e.retryable?`retryable`:`fatal`}): ${e.description}`};case`checkpoint`:return{ts:e.ts,source:e.type,level:`info`,text:`\u2713 checkpoint #${e.promptIndex}: "${e.promptPreview.slice(0,60)}"`};case`agent_spawned`:return{ts:e.ts,source:e.type,level:`info`,text:`spawned as ${e.role}`,agentId:e.agentId};case`agent_session_linked`:return{ts:e.ts,source:e.type,level:`info`,text:`transcript \u2192 ${e.transcriptPath??e.agentSessionId}`,agentId:e.agentId};case`agent_stopped`:return{ts:e.ts,source:e.type,level:`info`,text:`stopped`,agentId:e.agentId};case`delegate_started`:return{ts:e.ts,source:e.type,level:`info`,text:`\u{1F91D} delegating \u2192 ${e.target}: ${e.task.length>100?`${e.task.slice(0,99)}\u2026`:e.task}`,agentId:e.subagentId,detail:{kind:`delegate_started`,target:e.target,task:e.task}};case`delegate_completed`:{let t=e.costUsd&&e.costUsd>0?` \xB7 $${e.costUsd.toFixed(4)}`:``;return{ts:e.ts,source:e.type,level:e.ok?`info`:`error`,text:`${e.ok?`✅`:`❌`} ${e.summary}${t}`,agentId:e.subagentId,detail:{kind:`delegate_completed`,target:e.target,task:e.task,ok:e.ok,status:e.status,summary:e.summary,durationMs:e.durationMs,iterations:e.iterations,toolCalls:e.toolCalls,costUsd:e.costUsd}}}case`loop_detected`:{let t=e.kind===`message`?`the same reply`:e.tools?`\`${e.tools}\``:`the same step`;return{ts:e.ts,source:e.type,level:`warn`,text:e.action===`steer`?`\u{1F501} Loop detected \u2014 ${t} repeated ${e.repeatCount}\xD7 ; the run was steered.`:`\u{1F501} Loop detected \u2014 ${t} repeated ${e.repeatCount}\xD7 ; the run was stopped.`}}case`model_switched`:{let t=`${e.to.providerId}/${e.to.model}`,n=e.from?`${e.from.providerId}/${e.from.model} \u2192 `:``;return{ts:e.ts,source:e.type,level:e.reason===`fallback`?`warn`:`info`,text:e.reason===`fallback`?`\u26A0 fallback${e.status?` (HTTP ${e.status})`:``}: ${n}${t}`:`model: ${n}${t}`}}case`agent_error`:return{ts:e.ts,source:e.type,level:`error`,text:`error: ${e.error.slice(0,80)}`,agentId:e.agentId};case`mode_changed`:return{ts:e.ts,source:e.type,level:`info`,text:`mode: ${e.from} \u2192 ${e.to}`};case`skill_activated`:return{ts:e.ts,source:e.type,level:`info`,text:`skill activated: ${e.skillName}`};case`skill_deactivated`:return{ts:e.ts,source:e.type,level:`info`,text:`skill deactivated: ${e.skillName}`};case`message_truncated`:return{ts:e.ts,source:e.type,level:`warn`,text:e.after<e.before?`message truncated: ${e.before} \u2192 ${e.after} tokens`:`message truncated at ${e.after} tokens`};default:return null}}function ss(e,t=is){let n=[];for(let r of e){if(!t.has(r.type))continue;let e=os(r);e&&n.push(e)}return n}var cs=[`[MAILBOX]`,`[MAILBOX BTW]`,`[BY THE WAY —`,`[QUEUED MESSAGES —`,`[FLEET PULSE]`,`[loop-detector]`,`[tool_history_digest:`,`[session.resume] Request targeted session`];function ls(e){let t=e.trimStart();for(let e of cs)if(t.startsWith(e))return!0;return!1}function us(e){let t=[];for(let n of e)n.type===`tool_call_end`&&t.push({id:n.id,name:n.name,durationMs:n.durationMs,outputBytes:n.outputBytes??n.outputSize,outputTokens:n.outputTokens,outputLines:n.outputLines,ok:n.ok,agentId:n.agentId});return t}function ds(e){let t=new Map;if(!e)return t;for(let n of e)t.set(n.id,n);return t}function fs(e){let t=[];for(let n of e)n.type===`image`&&t.push({mediaType:n.source.media_type,data:n.source.data,url:n.source.url});return t.length>0?t:void 0}function ps(e){return typeof e==`string`?e:JSON.stringify(e)}function ms(e){let{messages:t,events:n,thinkingPlacement:r=`inline`,textBlocks:i=`split`,textSeparator:a=``,hideSystemInjections:o=!0}=e,s=e.markers??(n?ss(n,e.markerSources??is):[]),c=ds(e.toolMeta??(n?us(n):void 0)),l=[],u=new Map,d=0,f=``,p=(e,t,n,r)=>{let i=t.trim();i&&(o&&ls(i)||(e===`assistant`?l.push({kind:`assistant`,ts:n,text:i,final:r}):e===`system`?l.push({kind:`system`,ts:n,text:i}):l.push({kind:`user`,ts:n,text:i})))},m=(e,t)=>{e.trim()&&(d+=1,l.push({kind:`thinking`,ts:t,text:e,index:d}))};for(let e of t){let t=e.ts??f;if(e.ts&&(f=e.ts),typeof e.content==`string`){p(e.role,e.content,t,!0);continue}let n=e.content;if(r===`inline`)for(let e of n)e.type===`thinking`&&m(e.thinking,t);let o=e.role===`user`?fs(n):void 0,s=!n.some(e=>e.type===`tool_use`),d=[],h=()=>{if(i===`join`)return;let n=d.join(a).trim();n&&p(e.role,n,t,s),d.length=0};if(i===`join`){let r=n.filter(e=>e.type===`text`).map(e=>e.text).join(a).trim();r&&p(e.role,r,t,s)}for(let e of n){if(e.type===`text`){d.push(e.text);continue}if(e.type===`tool_use`){h();let n=c.get(e.id),r={kind:`tool`,ts:t,toolUseId:e.id,name:e.name,input:e.input,ok:n?.ok,durationMs:n?.durationMs,outputBytes:n?.outputBytes,outputTokens:n?.outputTokens,outputLines:n?.outputLines,agentId:n?.agentId};l.push(r),u.set(e.id,r);continue}if(e.type!==`tool_result`)continue;h();let n=u.get(e.tool_use_id);if(n){n.output=ps(e.content),n.ok=!e.is_error,u.delete(e.tool_use_id);continue}let r=c.get(e.tool_use_id);l.push({kind:`tool`,ts:t,toolUseId:e.tool_use_id,name:e.name??r?.name??e.tool_use_id,output:ps(e.content),ok:!e.is_error,durationMs:r?.durationMs,outputBytes:r?.outputBytes,outputTokens:r?.outputTokens,outputLines:r?.outputLines,agentId:r?.agentId})}if(h(),r===`merged-after`&&m(n.filter(e=>e.type===`thinking`).map(e=>e.thinking).join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/config-store-BAUadwHd.js","assets/rolldown-runtime-hePW80VL.js","assets/react-core-wiHys0m2.js","assets/vendor-V3ydTHqN.js","assets/xyflow-BqDBClm9.js","assets/xyflow-DLioOiRN.css","assets/markdown-CXRzjX3p.js","assets/vendor-jL-bRT8f.css","assets/i18n-CbyUyl6G.js","assets/chat-BITJe8-v.js","assets/commandPalette-BovBiPec.js","assets/common-CmkkiJUR.js","assets/setup-qooXjj4V.js","assets/toasts-DZ6HdKgG.js","assets/vite-preload-BZ1Pz5am.js","assets/utils-CKsqCaP8.js","assets/ui-store-DC3mkswy.js","assets/fonts-DRGbd-AM.js","assets/AnalyticsDashboard-DGQk1vSi.js","assets/stores-RkHrTaRO.js","assets/chat-store-DNRce6sE.js","assets/codemap-activity-store-Ha7XbGgq.js","assets/mailbox-store-C49LeBj8.js","assets/AgentRosterView-DMxOg0xX.js","assets/view-navigation-DHtNFXIl.js","assets/roster-ws-z8DKquaN.js","assets/AudienceMemoryPanel-CyfpggCK.js","assets/dialog-C7EIBM_2.js","assets/button-9ewV4TF3.js","assets/input-ag1CrUiS.js","assets/shared-BFJvAYzX.js","assets/AgentRosterView-Cv9-DYty.css","assets/ChangesView-C8x8tmpi.js","assets/monaco-CbI7qrVD.js","assets/monaco-Bowa0-zp.css","assets/empty-state-5YP1rmE6.js","assets/monaco-theme-Dr3-rSid.js","assets/RepositoryHistoryView-D0ynYRgu.js","assets/ChronicleDashboard-CvDPqZKE.js","assets/CodeEditor-s0lHP0DZ.js","assets/MemoryDrawer-CuFQypU-.js","assets/CodeMap-6mmDO9gJ.js","assets/DebugDashboard-BP1Mia-L.js","assets/DesignGalleryView-taDxRN63.js","assets/GoalView-CcLxMYXe.js","assets/KanbanView-C-K6OBw8.js","assets/SddFlowGraph-BZkvlaQ1.js","assets/MailboxDetailView-N00dLbpr.js","assets/PromptJournalView-CdC4ldrv.js","assets/RefreshDebugView-Dbq_bHwj.js","assets/SageTabs-Dwbux3im.js","assets/RequirementIntakeView-CPRtncuJ.js","assets/SddHub-CoRKeq7Q.js","assets/SessionsDashboard-CaSXukNy.js","assets/SessionList-xXaygO5X.js","assets/SessionInspectView-Bak1hK82.js","assets/SkillDetailView-OdtAJM43.js","assets/TechStackView-BUIbnU2F.js","assets/DeadCodeScanPanel-ByhAW_bl.js","assets/ChimeraReviewsView-DencEMIY.js","assets/SetupScreen-BSEF1air.js","assets/ProviderTestView-Dy7EQEI9.js","assets/ProcessMonitor-CkAtUjrR.js","assets/TerminalPanel-CfoKklMj.js","assets/xterm-DA3G7037.js","assets/xterm-BrP-ENHg.css","assets/CronJobsPanel-LoDmuRHl.js","assets/QueuePanel-DE9ySxkR.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,At as r,B as i,Bt as a,C as o,Ct as s,D as c,Dt as l,E as u,Et as d,F as f,Ft as p,G as m,Gt as h,H as g,Ht as _,I as v,It as y,J as b,Jt as x,K as S,Kt as C,L as w,Lt as T,M as E,Mt as D,N as O,Nt as k,O as A,Ot as j,P as M,Q as N,R as P,Rt as F,S as I,St as L,T as ee,U as R,Ut as z,V as te,Vt as ne,W as re,Wt as ie,X as ae,Xt as oe,Y as se,Yt as ce,Z as B,_ as le,_t as ue,a as de,at as fe,b as pe,bt as me,c as he,ct as ge,d as _e,dt as ve,et as ye,f as be,ft as xe,g as Se,gt as Ce,h as we,ht as Te,i as Ee,j as De,jt as Oe,k as ke,kt as Ae,l as je,lt as Me,m as Ne,mt as Pe,n as Fe,nt as Ie,o as Le,ot as Re,p as ze,pt as Be,qt as Ve,r as He,rt as Ue,s as We,st as Ge,t as V,tt as H,u as Ke,ut as qe,v as Je,vt as Ye,w as Xe,x as Ze,xt as Qe,y as $e,yt as et,zt as tt}from"./config-store-BAUadwHd.js";import{i as nt,n as rt,t as it}from"./react-core-wiHys0m2.js";import{$ as at,$a as ot,$i as st,$n as ct,$t as lt,Aa as ut,Ai as dt,An as ft,Ar as pt,Ba as mt,Bi as ht,Br as gt,Bt as _t,Ca as vt,Ci as yt,Cn as bt,Cr as xt,Ct as St,Da as Ct,Di as wt,Dn as Tt,Dr as Et,Dt,Ea as Ot,Ei as kt,En as At,Er as jt,Et as Mt,Fa as Nt,Fi as Pt,Fn as Ft,Fr as It,Ft as Lt,G as Rt,Gi as zt,Gn as Bt,Gr as Vt,Gt as Ht,H as Ut,Ha as Wt,Hi as Gt,Hn as Kt,Ht as qt,Ia as Jt,Ii as Yt,In as Xt,It as Zt,J as Qt,Ja as $t,Ji as en,Jn as tn,Jr as nn,Jt as rn,K as an,Ka as on,Kn as sn,Kr as cn,La as ln,Ln as un,Lr as dn,Lt as fn,Ma as pn,Mr as mn,Mt as hn,Na as gn,Nt as _n,Oa as vn,Oi as yn,Or as bn,Pa as xn,Pi as Sn,Pn as Cn,Pr as wn,Pt as Tn,Q as En,Qa as Dn,Qi as On,Qn as kn,Qr as An,Qt as jn,Ra as Mn,Ri as Nn,Rn as Pn,Rr as Fn,Rt as In,Si as Ln,Sr as Rn,St as zn,Ta as Bn,Ti as Vn,Tn as Hn,Tt as Un,U as Wn,Ui as Gn,Ur as Kn,Ut as qn,Va as Jn,Vn as Yn,Vr as Xn,W as Zn,Wa as Qn,Wi as $n,Wn as er,Wr as tr,X as nr,Xa as rr,Xi as ir,Xn as ar,Xr as or,Xt as sr,Y as cr,Yi as lr,Yn as ur,Yt as dr,Z as fr,Za as pr,Zi as mr,Zn as hr,Zr as gr,Zt as _r,_i as vr,_r as yr,_t as br,ai as xr,an as Sr,ao as Cr,ar as wr,at as Tr,ba as Er,bi as Dr,bn as Or,br as kr,bt as Ar,ci as jr,cn as Mr,co as Nr,ct as Pr,da as Fr,dn as Ir,do as Lr,dt as Rr,ea as zr,ei as Br,eo as Vr,et as Hr,fi as Ur,fn as Wr,fr as Gr,ft as Kr,ga as qr,gi as Jr,go as Yr,gr as Xr,gt as Zr,ha as Qr,hi as $r,hn as ei,ho as ti,hr as ni,ht as ri,ia as ii,ii as ai,in as oi,io as si,ir as ci,it as li,ja as ui,ji as di,jn as fi,jr as pi,jt as mi,ka as hi,kn as gi,kr as _i,la as vi,lo as yi,lr as bi,lt as xi,ma as Si,mn as Ci,mo as wi,mr as Ti,mt as Ei,na as Di,ni as Oi,nn as ki,nr as Ai,nt as ji,oa as Mi,oi as Ni,on as Pi,oo as Fi,or as Ii,ot as Li,pa as Ri,pi as zi,pn as Bi,pr as Vi,pt as Hi,q as Ui,qi as Wi,qn as Gi,qr as Ki,qt as qi,ra as Ji,ri as Yi,rn as Xi,ro as Zi,rr as Qi,rt as $i,si as ea,sn as ta,so as na,sr as ra,st as ia,ti as aa,tn as oa,to as sa,tt as ca,ua as la,ui as ua,un as da,uo as fa,ur as pa,ut as ma,vn as ha,vo as ga,vr as _a,vt as va,wa as ya,wi as ba,wn as xa,wo as U,wr as Sa,wt as Ca,xn as wa,xo as W,xr as Ta,xt as Ea,yi as Da,yn as Oa,yr as ka,yt as Aa,zi as ja,zn as Ma,zt as Na}from"./vendor-V3ydTHqN.js";import{i as Pa,n as G,r as Fa,t as Ia}from"./i18n-CbyUyl6G.js";import{t as La}from"./vite-preload-BZ1Pz5am.js";import{t as K}from"./utils-CKsqCaP8.js";import{a as Ra,i as za,n as Ba,o as Va,r as Ha,s as Ua,t as Wa}from"./view-navigation-DHtNFXIl.js";import{a as Ga,i as Ka,n as q,r as qa,t as Ja}from"./ui-store-DC3mkswy.js";import{C as Ya,D as Xa,E as Za,O as Qa,S as $a,T as eo,_ as to,a as no,b as ro,c as io,d as ao,h as oo,i as so,l as co,m as lo,n as uo,o as fo,r as po,s as mo,t as ho,u as go,v as _o,w as vo,x as yo,y as bo}from"./stores-RkHrTaRO.js";import{t as J}from"./chat-store-DNRce6sE.js";import{i as xo,n as So}from"./codemap-activity-store-Ha7XbGgq.js";import{C as Co,S as wo,_ as To,a as Eo,b as Do,c as Oo,d as ko,f as Ao,g as jo,h as Mo,i as No,l as Po,m as Fo,n as Io,o as Lo,p as Ro,r as zo,s as Bo,t as Vo,u as Ho,v as Uo,w as Wo,x as Go}from"./fonts-DRGbd-AM.js";import{n as Ko,r as qo,t as Jo}from"./mailbox-store-C49LeBj8.js";import{a as Yo,i as Xo,n as Zo,o as Qo,r as $o,t as es}from"./dialog-C7EIBM_2.js";import{t as Y}from"./button-9ewV4TF3.js";import{t as ts}from"./input-ag1CrUiS.js";import{c as ns,u as rs}from"./markdown-CXRzjX3p.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),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var is=new Set([`mode_changed`,`compaction`,`checkpoint`,`skill_activated`,`skill_deactivated`,`agent_spawned`,`agent_session_linked`,`agent_stopped`,`agent_error`,`delegate_started`,`delegate_completed`,`loop_detected`,`model_switched`,`error`,`provider_retry`,`provider_error`,`message_truncated`]),as=new Set([`checkpoint`,`agent_spawned`,`agent_session_linked`,`agent_stopped`,`agent_error`,`delegate_started`,`delegate_completed`]);new Set([...is].filter(e=>!as.has(e)));function os(e){switch(e.type){case`compaction`:{let t=(e.before/1e3).toFixed(0),n=(e.after/1e3).toFixed(0),r=e.level?` (${e.level})`:``,i=e.reductions&&e.reductions.length>0?` [${e.reductions.map(e=>`${e.phase}: \u2212${e.saved}`).join(`, `)}]`:``;return{ts:e.ts,source:e.type,level:`info`,text:`\u27F2 context compacted${r}: ${t}K \u2192 ${n}K tokens${i}`}}case`error`:return{ts:e.ts,source:e.type,level:`error`,text:e.phase?`[${e.phase}] ${e.message}`:e.message};case`provider_retry`:{let t=(e.delayMs/1e3).toFixed(e.delayMs>=1e3?1:2);return{ts:e.ts,source:e.type,level:`warn`,text:e.status?`\u27F3 retry ${e.attempt} (HTTP ${e.status}) after ${t}s \u2014 ${e.description}`:`\u27F3 retry ${e.attempt} after ${t}s \u2014 ${e.description}`}}case`provider_error`:return{ts:e.ts,source:e.type,level:`error`,text:e.status?`provider error (HTTP ${e.status}, ${e.retryable?`retryable`:`fatal`}): ${e.description}`:`provider error (${e.retryable?`retryable`:`fatal`}): ${e.description}`};case`checkpoint`:return{ts:e.ts,source:e.type,level:`info`,text:`\u2713 checkpoint #${e.promptIndex}: "${e.promptPreview.slice(0,60)}"`};case`agent_spawned`:return{ts:e.ts,source:e.type,level:`info`,text:`spawned as ${e.role}`,agentId:e.agentId};case`agent_session_linked`:return{ts:e.ts,source:e.type,level:`info`,text:`transcript \u2192 ${e.transcriptPath??e.agentSessionId}`,agentId:e.agentId};case`agent_stopped`:return{ts:e.ts,source:e.type,level:`info`,text:`stopped`,agentId:e.agentId};case`delegate_started`:return{ts:e.ts,source:e.type,level:`info`,text:`\u{1F91D} delegating \u2192 ${e.target}: ${e.task.length>100?`${e.task.slice(0,99)}\u2026`:e.task}`,agentId:e.subagentId,detail:{kind:`delegate_started`,target:e.target,task:e.task}};case`delegate_completed`:{let t=e.costUsd&&e.costUsd>0?` \xB7 $${e.costUsd.toFixed(4)}`:``;return{ts:e.ts,source:e.type,level:e.ok?`info`:`error`,text:`${e.ok?`✅`:`❌`} ${e.summary}${t}`,agentId:e.subagentId,detail:{kind:`delegate_completed`,target:e.target,task:e.task,ok:e.ok,status:e.status,summary:e.summary,durationMs:e.durationMs,iterations:e.iterations,toolCalls:e.toolCalls,costUsd:e.costUsd}}}case`loop_detected`:{let t=e.kind===`message`?`the same reply`:e.tools?`\`${e.tools}\``:`the same step`;return{ts:e.ts,source:e.type,level:`warn`,text:e.action===`steer`?`\u{1F501} Loop detected \u2014 ${t} repeated ${e.repeatCount}\xD7 ; the run was steered.`:`\u{1F501} Loop detected \u2014 ${t} repeated ${e.repeatCount}\xD7 ; the run was stopped.`}}case`model_switched`:{let t=`${e.to.providerId}/${e.to.model}`,n=e.from?`${e.from.providerId}/${e.from.model} \u2192 `:``;return{ts:e.ts,source:e.type,level:e.reason===`fallback`?`warn`:`info`,text:e.reason===`fallback`?`\u26A0 fallback${e.status?` (HTTP ${e.status})`:``}: ${n}${t}`:`model: ${n}${t}`}}case`agent_error`:return{ts:e.ts,source:e.type,level:`error`,text:`error: ${e.error.slice(0,80)}`,agentId:e.agentId};case`mode_changed`:return{ts:e.ts,source:e.type,level:`info`,text:`mode: ${e.from} \u2192 ${e.to}`};case`skill_activated`:return{ts:e.ts,source:e.type,level:`info`,text:`skill activated: ${e.skillName}`};case`skill_deactivated`:return{ts:e.ts,source:e.type,level:`info`,text:`skill deactivated: ${e.skillName}`};case`message_truncated`:return{ts:e.ts,source:e.type,level:`warn`,text:e.after<e.before?`message truncated: ${e.before} \u2192 ${e.after} tokens`:`message truncated at ${e.after} tokens`};default:return null}}function ss(e,t=is){let n=[];for(let r of e){if(!t.has(r.type))continue;let e=os(r);e&&n.push(e)}return n}var cs=[`[MAILBOX]`,`[MAILBOX BTW]`,`[BY THE WAY —`,`[QUEUED MESSAGES —`,`[FLEET PULSE]`,`[loop-detector]`,`[tool_history_digest:`,`[session.resume] Request targeted session`];function ls(e){let t=e.trimStart();for(let e of cs)if(t.startsWith(e))return!0;return!1}function us(e){let t=[];for(let n of e)n.type===`tool_call_end`&&t.push({id:n.id,name:n.name,durationMs:n.durationMs,outputBytes:n.outputBytes??n.outputSize,outputTokens:n.outputTokens,outputLines:n.outputLines,ok:n.ok,agentId:n.agentId});return t}function ds(e){let t=new Map;if(!e)return t;for(let n of e)t.set(n.id,n);return t}function fs(e){let t=[];for(let n of e)n.type===`image`&&t.push({mediaType:n.source.media_type,data:n.source.data,url:n.source.url});return t.length>0?t:void 0}function ps(e){return typeof e==`string`?e:JSON.stringify(e)}function ms(e){let{messages:t,events:n,thinkingPlacement:r=`inline`,textBlocks:i=`split`,textSeparator:a=``,hideSystemInjections:o=!0}=e,s=e.markers??(n?ss(n,e.markerSources??is):[]),c=ds(e.toolMeta??(n?us(n):void 0)),l=[],u=new Map,d=0,f=``,p=(e,t,n,r)=>{let i=t.trim();i&&(o&&ls(i)||(e===`assistant`?l.push({kind:`assistant`,ts:n,text:i,final:r}):e===`system`?l.push({kind:`system`,ts:n,text:i}):l.push({kind:`user`,ts:n,text:i})))},m=(e,t)=>{e.trim()&&(d+=1,l.push({kind:`thinking`,ts:t,text:e,index:d}))};for(let e of t){let t=e.ts??f;if(e.ts&&(f=e.ts),typeof e.content==`string`){p(e.role,e.content,t,!0);continue}let n=e.content;if(r===`inline`)for(let e of n)e.type===`thinking`&&m(e.thinking,t);let o=e.role===`user`?fs(n):void 0,s=!n.some(e=>e.type===`tool_use`),d=[],h=()=>{if(i===`join`)return;let n=d.join(a).trim();n&&p(e.role,n,t,s),d.length=0};if(i===`join`){let r=n.filter(e=>e.type===`text`).map(e=>e.text).join(a).trim();r&&p(e.role,r,t,s)}for(let e of n){if(e.type===`text`){d.push(e.text);continue}if(e.type===`tool_use`){h();let n=c.get(e.id),r={kind:`tool`,ts:t,toolUseId:e.id,name:e.name,input:e.input,ok:n?.ok,durationMs:n?.durationMs,outputBytes:n?.outputBytes,outputTokens:n?.outputTokens,outputLines:n?.outputLines,agentId:n?.agentId};l.push(r),u.set(e.id,r);continue}if(e.type!==`tool_result`)continue;h();let n=u.get(e.tool_use_id);if(n){n.output=ps(e.content),n.ok=!e.is_error,u.delete(e.tool_use_id);continue}let r=c.get(e.tool_use_id);l.push({kind:`tool`,ts:t,toolUseId:e.tool_use_id,name:e.name??r?.name??e.tool_use_id,output:ps(e.content),ok:!e.is_error,durationMs:r?.durationMs,outputBytes:r?.outputBytes,outputTokens:r?.outputTokens,outputLines:r?.outputLines,agentId:r?.agentId})}if(h(),r===`merged-after`&&m(n.filter(e=>e.type===`thinking`).map(e=>e.thinking).join(`
3
3
 
4
4
  `).trim(),t),o){let e=l[l.length-1];e?.kind===`user`&&e.ts===t?e.images=o:l.push({kind:`user`,ts:t,text:``,images:o})}}let h=[],g=0,_=0;for(;g<l.length&&_<s.length;){let e=s[_];e.ts<l[g].ts?(h.push(hs(e)),_+=1):(h.push(l[g]),g+=1)}for(;g<l.length;)h.push(l[g++]);for(;_<s.length;)h.push(hs(s[_++]));return h}function hs(e){return{kind:`marker`,ts:e.ts,source:e.source,level:e.level,text:e.text,agentId:e.agentId,detail:e.detail}}var gs=e(rt(),1),X=e(nt(),1),Z=it(),_s=St,vs=Dt,ys=X.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,Z.jsxs)(Mt,{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,Z.jsx)(ui,{className:`ml-auto h-4 w-4`})]}));ys.displayName=Mt.displayName;var bs=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(Un,{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}));bs.displayName=Un.displayName;var xs=X.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,Z.jsx)(Ea,{children:(0,Z.jsx)(br,{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})}));xs.displayName=br.displayName;var Ss=X.forwardRef(({className:e,inset:t,...n},r)=>(0,Z.jsx)(va,{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}));Ss.displayName=va.displayName;var Cs=X.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,Z.jsxs)(Zr,{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,Z.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,Z.jsx)(Aa,{children:(0,Z.jsx)(xn,{className:`h-4 w-4`})})}),t]}));Cs.displayName=Zr.displayName;var ws=X.forwardRef(({className:e,children:t,...n},r)=>(0,Z.jsxs)(zn,{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,Z.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,Z.jsx)(Aa,{children:(0,Z.jsx)(Qr,{className:`h-2 w-2 fill-current`})})}),t]}));ws.displayName=zn.displayName;var Ts=X.forwardRef(({className:e,inset:t,...n},r)=>(0,Z.jsx)(Ar,{ref:r,className:K(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));Ts.displayName=Ar.displayName;var Es=X.forwardRef(({className:e,...t},n)=>(0,Z.jsx)(Ca,{ref:n,className:K(`-mx-1 my-1 h-px bg-muted`,e),...t}));Es.displayName=Ca.displayName;var Ds=({className:e,...t})=>(0,Z.jsx)(`span`,{className:K(`ml-auto text-xs tracking-widest opacity-60`,e),...t});Ds.displayName=`DropdownMenuShortcut`;var Os=[{id:`chat`,icon:(0,Z.jsx)(ka,{size:16}),label:`Session`},{id:`files`,icon:(0,Z.jsx)(Dr,{size:16}),label:`Files`},{id:`changes`,icon:(0,Z.jsx)(Ni,{size:16}),label:`Changes`},{id:`mailbox`,icon:(0,Z.jsx)(jt,{size:16}),label:`Mailbox`},{id:`skills`,icon:(0,Z.jsx)(Wr,{size:16}),label:`Skills`},{id:`design`,icon:(0,Z.jsx)(Ii,{size:16}),label:`Design Studio`}],ks=[{id:`intake`,icon:(0,Z.jsx)(Ri,{size:16}),label:`Requirements`},{id:`sddhub`,icon:(0,Z.jsx)(Zt,{size:16}),label:`SDD`},{id:`goal`,icon:(0,Z.jsx)(Pn,{size:16}),label:`Goal`},{id:`kanban`,icon:(0,Z.jsx)(ii,{size:16}),label:`Kanban`},{id:`roster`,icon:(0,Z.jsx)(on,{size:16}),label:`Agent Roster`},{id:`codemap`,icon:(0,Z.jsx)(pa,{size:16}),label:`CodeMap`},{id:`techstack`,icon:(0,Z.jsx)(Qn,{size:16}),label:`TechStack`},{id:`provider-test`,icon:(0,Z.jsx)(Ln,{size:16}),label:`Provider Test`},{id:`history`,icon:(0,Z.jsx)(xr,{size:16}),label:`Repository History`},{id:`chronicle`,icon:(0,Z.jsx)(Jt,{size:16}),label:`Chronicle`},{id:`prompts`,icon:(0,Z.jsx)(gi,{size:16}),label:`Prompt Journal`},{id:`chimera`,icon:(0,Z.jsx)(Or,{size:16}),label:`Chimera Reviews`},{id:`memory`,icon:(0,Z.jsx)(Wt,{size:16}),label:`Memory`}],As=[`chat`,`files`,`changes`,`mailbox`],js=new Set(As),Ms=[...As,`skills`,`design`],Ns=132,Ps=38,Fs=165,Is=46;function Ls(e,t){let n=Os.length+ks.length,r=Number.isFinite(e)?e:720,i=t?Ns:Fs,a=t?Ps:Is,o=Math.floor((r-i)/a);return Math.max(As.length,Math.min(n,o))}function Rs(e,t=Os,n=ks){let r=t.length+n.length,i=Math.max(As.length,Math.min(r,Math.floor(e))),a=Math.min(t.length,i),o=new Set(Ms.slice(0,a)),s=t.map(e=>e.id).filter(e=>o.has(e)),c=t.map(e=>e.id).filter(e=>!o.has(e)),l=Math.max(0,i-s.length),u=n.slice(0,l).map(e=>e.id),d=new Set(u);return{visiblePanelIds:s,overflowPanelIds:c,visibleViewIds:u,overflowViewIds:n.map(e=>e.id).filter(e=>!d.has(e))}}var zs=Os.map(e=>e.id);function Bs(e,t){if(!t||t.length===0)return e;let n=new Map(e.map(e=>[e.id,e])),r=new Set,i=[];for(let e of t){let t=n.get(e);t&&!r.has(e)&&(i.push(t),r.add(e))}for(let t of e)r.has(t.id)||i.push(t);return i}function Vs(e,t,n){let r=Bs(e.filter(e=>!n.has(e.id)),t?t.filter(e=>!n.has(e)):void 0),i=[],a=0;for(let t of e)n.has(t.id)?i.push(t):a<r.length&&i.push(r[a++]);return i}function Hs(e,t,n){if(t===n)return e;let r=e.indexOf(t),i=e.indexOf(n);if(r===-1||i===-1)return e;let a=e.slice(),[o]=a.splice(r,1);return a.splice(i,0,o),a}function Us(){return typeof window>`u`?720:window.visualViewport?.height??window.innerHeight}function Ws(e){let[t,n]=(0,X.useState)(Us);return(0,X.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>n(Us());return e(),window.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`resize`,e)}},[]),Ls(t,e)}function Gs({desktopShell:e=!1}){let t=q(e=>e.activeActivity),n=q(e=>e.sidebarOpen),r=q(e=>e.currentView),i=H(e=>e.projectName),a=V(e=>e.wsConnected),{t:o}=W(),s=(e,t)=>o(`activity:nav.${e}`,t),c=qo(Ko),l=le(e=>e.openTabIds.length),u=q(e=>e.inspectorOpen),d=q(e=>e.activityBarOrder),f=q(e=>e.setActivityBarOrder),[p,m]=(0,X.useState)(!1),h=(0,X.useMemo)(()=>Vs(Os,d?.panels,js),[d?.panels]),g=(0,X.useMemo)(()=>Bs(ks,d?.views),[d?.views]),_=Ws(e),v=(0,X.useMemo)(()=>Rs(_,h,g),[_,h,g]),y=(0,X.useMemo)(()=>new Set(v.visiblePanelIds),[v.visiblePanelIds]),b=(0,X.useMemo)(()=>new Set(v.overflowPanelIds),[v.overflowPanelIds]),x=(0,X.useMemo)(()=>new Set(v.visibleViewIds),[v.visibleViewIds]),S=(0,X.useMemo)(()=>new Set(v.overflowViewIds),[v.overflowViewIds]),C=h.filter(e=>y.has(e.id)),w=h.filter(e=>b.has(e.id)),T=g.filter(e=>x.has(e.id)),E=g.filter(e=>S.has(e.id)),D=e=>{if(e===`mailbox`)return c||void 0;if(e===`chat`)return l>0?l:void 0},[O,k]=(0,X.useState)(null),[A,j]=(0,X.useState)(null),M=e=>js.has(e),N=()=>{m(!1),k(null),j(null)},P=()=>{f(null),N()},F=(e,t)=>n=>{if(p){if(e===`panel`&&M(t)){n.preventDefault();return}k(t),j(null),n.dataTransfer.effectAllowed=`move`}},I=(e,t)=>e=>{p&&O!=null&&O!==t&&(M(t)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,A!==t&&j(t)))},L=e=>t=>{A===e&&j(null),t.preventDefault()},ee=(e,t)=>n=>{if(p&&O!=null&&O!==t){if(M(t)){n.preventDefault();return}if(n.preventDefault(),e===`panel`){let e=Hs(h.map(e=>e.id),O,t);f({panels:e,views:g.map(e=>e.id)})}else{let e=Hs(g.map(e=>e.id),O,t);f({panels:h.map(e=>e.id),views:e})}k(null),j(null)}},R=()=>{k(null),j(null)};return(0,Z.jsxs)(`div`,{className:K(`flex h-full min-h-0 shrink-0 flex-col border-r border-border/70 bg-card/75 backdrop-blur-xl`,e?`w-10`:`w-12`),children:[(0,Z.jsx)(`div`,{className:`flex flex-col items-center shrink-0 border-b border-border/60`,children:(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{Va(`chat`)},title:i?o(`activity:brand.returnToChat`,{name:i}):o(`activity:brand.returnToChatDefault`),className:K(`relative flex items-center justify-center overflow-hidden bg-foreground transition-shadow hover:shadow-[0_3px_12px_-2px_hsl(var(--primary)/0.5)]`,e?`w-full h-8`:`w-full h-11`),children:(0,Z.jsx)(`img`,{src:`/wrongstack.svg`,alt:``,"aria-hidden":`true`,draggable:!1,className:`ws-brand-logo h-full w-full`})})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-hidden flex flex-col items-center pt-2 pb-1`,children:[C.map(r=>{let i=M(r.id);return(0,Z.jsx)(qs,{compact:e,icon:r.icon,label:`${s(r.id,r.label)} (${Ra(r.id)})`,active:n&&t===r.id,badge:D(r.id),onClick:()=>za(r.id),reorderMode:p,draggable:p&&!i,locked:i,isDragOver:p&&A===r.id,isDragging:p&&O===r.id,onDragStart:F(`panel`,r.id),onDragOver:I(`panel`,r.id),onDragLeave:L(r.id),onDrop:ee(`panel`,r.id),onDragEnd:R},r.id)}),T.length>0&&(0,Z.jsx)(`div`,{className:`my-1.5 h-px w-6 shrink-0 bg-border/70`}),T.map(t=>(0,Z.jsx)(qs,{compact:e,icon:t.icon,label:s(t.id,t.label),active:r===t.id,onClick:()=>Ha(t.id),reorderMode:p,draggable:p,isDragOver:p&&A===t.id,isDragging:p&&O===t.id,onDragStart:F(`view`,t.id),onDragOver:I(`view`,t.id),onDragLeave:L(t.id),onDrop:ee(`view`,t.id),onDragEnd:R},t.id))]}),(0,Z.jsx)(`div`,{role:`status`,"aria-label":a?o(`activity:connection.connected`,`Connected`):o(`activity:connection.disconnected`,`Disconnected`),className:`flex items-center justify-center py-1`,children:(0,Z.jsx)(`span`,{className:K(`h-1.5 w-1.5 rounded-full`,a?`bg-success`:`bg-muted-foreground/40`),title:a?o(`activity:connection.connected`,`Connected`):o(`activity:connection.disconnected`,`Disconnected`)})}),(0,Z.jsxs)(`div`,{className:`flex flex-col items-center shrink-0 pt-1 pb-2 border-t border-border/60`,children:[p?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,"data-testid":`activity-bar-reorder-done`,onClick:N,"aria-label":o(`activity:reorder.done`,`Done`),title:o(`activity:reorder.done`,`Done`),className:K(`ws-nav-button relative flex shrink-0 items-center justify-center rounded-md transition-colors`,e?`h-9 w-9`:`h-11 w-11`,`text-primary bg-primary/10 ring-1 ring-primary/30 hover:bg-primary/15`),children:(0,Z.jsx)(`span`,{className:`h-5 w-5 shrink-0`,children:(0,Z.jsx)(xn,{size:16})})}),(0,Z.jsx)(`button`,{type:`button`,"data-testid":`activity-bar-reorder-reset`,onClick:P,"aria-label":o(`activity:reorder.reset`,`Reset to default`),title:o(`activity:reorder.reset`,`Reset to default`),className:K(`ws-nav-button relative flex shrink-0 items-center justify-center rounded-md transition-colors`,e?`h-9 w-9`:`h-11 w-11`,`text-muted-foreground hover:border-border/70 hover:text-foreground hover:bg-muted/60`),children:(0,Z.jsx)(`span`,{className:`h-5 w-5 shrink-0`,children:(0,Z.jsx)(Xt,{size:16})})})]}):(0,Z.jsx)(`button`,{type:`button`,"data-testid":`activity-bar-reorder-edit`,onClick:()=>m(!0),"aria-label":o(`activity:reorder.edit`,`Edit order`),title:o(`activity:reorder.edit`,`Edit order`),className:K(`ws-nav-button relative flex shrink-0 items-center justify-center rounded-md transition-colors`,e?`h-9 w-9`:`h-11 w-11`,`text-muted-foreground hover:border-border/70 hover:text-foreground hover:bg-muted/60`),children:(0,Z.jsx)(`span`,{className:`h-5 w-5 shrink-0`,children:(0,Z.jsx)(hr,{size:16})})}),(0,Z.jsx)(Ks,{compact:e,monitorOpen:u,overflowPanels:w,overflowViews:E})]})]})}function Ks({compact:e=!1,monitorOpen:t,overflowPanels:n,overflowViews:r}){let{t:i}=W(),a=q(e=>e.activeActivity),o=q(e=>e.sidebarOpen),s=q(e=>e.currentView),c=q(e=>e.inspectorOpen),l=q(e=>e.inspectorTab),u=n.length+r.length,d=n.some(e=>o&&a===e.id),f=r.some(e=>s===e.id),p=d||f,m=e=>{let t=q.getState();t.inspectorOpen&&t.inspectorTab===e?t.setInspectorOpen(!1):(t.setInspectorTab(e),t.setInspectorOpen(!0))};return(0,Z.jsxs)(_s,{children:[(0,Z.jsx)(vs,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,"aria-label":u>0?i(`activity:menu.moreWithHidden`,{count:u}):i(`activity:menu.moreOptions`),title:e&&u>0?i(`activity:menu.moreCompactHidden`,{count:u}):i(e?`activity:menu.moreCompact`:`activity:menu.moreFull`),className:K(`ws-nav-button relative flex items-center justify-center rounded-md transition-colors`,e?`h-9 w-9`:`h-11 w-11`,`text-muted-foreground hover:border-border/70 hover:text-foreground hover:bg-muted/60`,`data-[state=open]:text-primary data-[state=open]:bg-primary/10 data-[state=open]:border-primary/30`,(t||p)&&`text-primary`),children:[(0,Z.jsx)(`span`,{className:`h-5 w-5 flex items-center justify-center`,children:(0,Z.jsx)($n,{size:16})}),u>0&&(0,Z.jsx)(`span`,{className:K(`absolute -top-0.5 -right-0.5 min-w-[15px] h-[15px] flex items-center justify-center rounded px-1 text-[8px] font-bold leading-none tabular`,p?`bg-primary text-primary-foreground`:`bg-muted-foreground text-background`),children:u>9?`9+`:u}),t&&u===0&&(0,Z.jsx)(`span`,{className:`absolute top-1 right-1 h-1.5 w-1.5 rounded-full bg-primary`})]})}),(0,Z.jsxs)(xs,{side:`right`,align:`end`,sideOffset:8,className:`w-56`,children:[(0,Z.jsxs)(Ss,{onSelect:()=>q.getState().setPaletteOpen(!0),children:[(0,Z.jsx)(Ji,{size:16}),(0,Z.jsx)(`span`,{children:i(`activity:menu.commandPalette`)}),(0,Z.jsx)(Ds,{children:`⌘K`})]}),(0,Z.jsxs)(Ss,{onSelect:()=>q.getState().setShortcutsOpen(!0),children:[(0,Z.jsx)(Vt,{size:16}),(0,Z.jsx)(`span`,{children:i(`activity:menu.keyboardShortcuts`)}),(0,Z.jsx)(Ds,{children:`?`})]}),n.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Es,{}),(0,Z.jsx)(Ts,{className:`text-[11px] uppercase text-muted-foreground`,children:i(`activity:menu.panels`)}),n.map(e=>(0,Z.jsxs)(Ss,{onSelect:()=>Va(e.id),children:[e.icon,(0,Z.jsx)(`span`,{children:i(`activity:nav.${e.id}`,e.label)}),o&&a===e.id?(0,Z.jsx)(`span`,{className:`ml-auto w-1.5 h-1.5 rounded-full bg-primary`}):(0,Z.jsx)(Ds,{children:Ra(e.id)})]},e.id))]}),r.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Es,{}),(0,Z.jsx)(Ts,{className:`text-[11px] uppercase text-muted-foreground`,children:i(`activity:menu.views`)}),r.map(e=>(0,Z.jsxs)(Ss,{onSelect:()=>Ha(e.id),children:[e.icon,(0,Z.jsx)(`span`,{children:i(`activity:nav.${e.id}`,e.label)}),s===e.id&&(0,Z.jsx)(`span`,{className:`ml-auto w-1.5 h-1.5 rounded-full bg-primary`})]},e.id))]}),(0,Z.jsx)(Es,{}),(0,Z.jsx)(Ts,{className:`text-[11px] uppercase text-muted-foreground`,children:i(`activity:nav.settings`,`Settings`)}),(0,Z.jsxs)(Ss,{onSelect:()=>Ha(`settings`),children:[(0,Z.jsx)(bt,{size:16}),(0,Z.jsx)(`span`,{children:i(`activity:nav.settings`,`Settings`)}),(0,Z.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:i(`settings:tabs.general`,`overview`)})]}),[{icon:(0,Z.jsx)(Ii,{size:14}),label:`General`,tab:`general`},{icon:(0,Z.jsx)(pa,{size:14}),label:`Provider`,tab:`provider`},{icon:(0,Z.jsx)(on,{size:14}),label:`Agent`,tab:`agent`},{icon:(0,Z.jsx)(mi,{size:14}),label:`Execution`,tab:`execution`},{icon:(0,Z.jsx)(tr,{size:14}),label:`Fallbacks`,tab:`fallbacks`}].map(({icon:e,label:t,tab:n})=>(0,Z.jsxs)(Ss,{onSelect:()=>{q.getState().setSettingsActiveTab(n),Ha(`settings`)},children:[e,(0,Z.jsx)(`span`,{children:i(`settings:tabs.${n}`,t)})]},n)),(0,Z.jsx)(Es,{}),(0,Z.jsx)(Ts,{className:`text-[11px] uppercase text-muted-foreground`,children:i(`activity:menu.monitors`)}),(0,Z.jsxs)(Ss,{onSelect:()=>m(`fleet`),children:[(0,Z.jsx)(Kn,{size:16}),(0,Z.jsx)(`span`,{children:i(`activity:menu.fleetMonitor`)}),c&&l===`fleet`?(0,Z.jsx)(`span`,{className:`ml-auto w-1.5 h-1.5 rounded-full bg-primary`}):(0,Z.jsx)(Ds,{children:`⇧⌘M`})]}),(0,Z.jsxs)(Ss,{onSelect:()=>m(`sideEffects`),children:[(0,Z.jsx)(mi,{size:16}),(0,Z.jsx)(`span`,{children:i(`activity:inspector.tabAudit`)}),c&&l===`sideEffects`?(0,Z.jsx)(`span`,{className:`ml-auto h-1.5 w-1.5 rounded-full bg-primary`}):null]})]})]})}function qs({compact:e=!1,icon:t,label:n,active:r,badge:i,onClick:a,reorderMode:o=!1,draggable:s=!1,locked:c=!1,isDragOver:l=!1,isDragging:u=!1,onDragStart:d,onDragOver:f,onDragLeave:p,onDrop:m,onDragEnd:h}){return(0,Z.jsxs)(`button`,{type:`button`,onClick:a,"aria-label":n,title:c&&o?`${n} — Sabit`:n,draggable:s,onDragStart:d,onDragOver:f,onDragLeave:p,onDrop:m,onDragEnd:h,"data-reorder-mode":o?`on`:`off`,"data-locked":c?`1`:`0`,"data-drag-over":l?`1`:`0`,"data-dragging":u?`1`:`0`,className:K(`ws-nav-button relative flex shrink-0 items-center justify-center rounded-md transition-colors`,e?`h-9 w-9`:`h-11 w-11`,`text-muted-foreground hover:border-border/70 hover:text-foreground hover:bg-muted/60`,r&&`ws-nav-button-active`,o&&!c&&`cursor-grab active:cursor-grabbing ring-1 ring-primary/40`,o&&c&&`opacity-70 cursor-not-allowed`,l&&`ring-2 ring-primary bg-primary/15 text-foreground`),children:[r&&(0,Z.jsx)(`span`,{className:`absolute left-0 top-1/2 -translate-y-1/2 w-0.5 h-6 rounded-r-full bg-primary`}),(0,Z.jsx)(`span`,{className:`h-5 w-5 shrink-0`,children:t}),c&&o&&(0,Z.jsx)(`span`,{"aria-label":`locked`,className:`absolute -top-1 -left-1 h-3.5 w-3.5 flex items-center justify-center rounded-full bg-background text-muted-foreground ring-1 ring-border`,children:(0,Z.jsx)(pi,{size:9})}),i!==void 0&&i>0&&(0,Z.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 min-w-[15px] h-[15px] flex items-center justify-center rounded bg-primary text-[8px] font-bold text-primary-foreground leading-none px-1 tabular`,children:i>99?`99+`:i})]})}function Js(e){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
5
5
  <rect width="64" height="64" fill="#121210" />
@@ -111,7 +111,7 @@ Type while the agent is running to queue messages; they are sent automatically w
111
111
  `):``),y(n.url??``)):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(`
112
112
  `):``),y(i.url??``)):(s(``),l(`stdio`),d(``),x(!0),C(!1),p(``),h(``),_(``),y(``)))},[n,i,e]);let w=()=>{if(!o.trim()){B.error(a(`settings:mcp.serverNameRequired`));return}let e={};if(g.trim())for(let t of g.trim().split(`
113
113
  `)){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,Z.jsx)(es,{open:e,onOpenChange:t,children:(0,Z.jsxs)(Zo,{children:[(0,Z.jsx)(Yo,{children:(0,Z.jsx)(Qo,{children:a(T?`settings:mcp.dialogTitleEdit`:E?`settings:mcp.dialogTitleAdd`:`settings:mcp.dialogTitleAddCustom`)})}),(0,Z.jsxs)(`div`,{className:`space-y-4 py-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldName`)}),(0,Z.jsx)(ts,{value:o,onChange:e=>s(e.target.value),placeholder:a(`settings:mcp.fieldNamePlaceholder`),disabled:T||E})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldTransport`)}),(0,Z.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,Z.jsx)(`option`,{value:`stdio`,children:`stdio`}),(0,Z.jsx)(`option`,{value:`sse`,children:`sse`}),(0,Z.jsx)(`option`,{value:`streamable-http`,children:`streamable-http`}),(0,Z.jsx)(`option`,{value:`http`,children:`http`})]})]}),(c===`streamable-http`||c===`sse`||c===`http`)&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldUrl`)}),(0,Z.jsx)(ts,{value:v,onChange:e=>y(e.target.value),placeholder:a(`activity:mCPSection.httpsMcpExampleComMcp`),disabled:E})]}),c===`stdio`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldCommand`)}),(0,Z.jsx)(ts,{value:f,onChange:e=>p(e.target.value),placeholder:a(`settings:mcp.fieldCommandPlaceholder`),disabled:E})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`span`,{className:`text-sm font-medium`,children:[a(`settings:mcp.fieldArgs`),` `,(0,Z.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:a(`settings:mcp.fieldArgsHint`)})]}),(0,Z.jsx)(ts,{value:m,onChange:e=>h(e.target.value),placeholder:a(`settings:mcp.fieldArgsPlaceholder`),disabled:E})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`span`,{className:`text-sm font-medium`,children:[a(`settings:mcp.fieldEnv`),` `,(0,Z.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:a(`settings:mcp.fieldEnvHint`)})]}),(0,Z.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_...
114
- AWS_REGION=us-east-1`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldDescription`)}),(0,Z.jsx)(ts,{value:u,onChange:e=>d(e.target.value),placeholder:a(`settings:mcp.fieldDescriptionPlaceholder`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`server-enabled`,checked:b,onChange:e=>x(e.target.checked),className:`rounded`}),(0,Z.jsx)(`label`,{htmlFor:`server-enabled`,className:`text-sm`,children:a(`settings:mcp.enableServer`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`server-lazy`,checked:S,onChange:e=>C(e.target.checked),className:`rounded`}),(0,Z.jsxs)(`label`,{htmlFor:`server-lazy`,className:`text-sm`,children:[a(`settings:mcp.lazyConnect`),` `,(0,Z.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:a(`settings:mcp.lazyConnectHint`)})]})]})]}),(0,Z.jsxs)(Xo,{children:[(0,Z.jsx)(Y,{variant:`outline`,onClick:()=>t(!1),children:a(`common:action.cancel`)}),(0,Z.jsx)(Y,{onClick:w,children:a(T?`settings:mcp.saveChanges`:`settings:mcp.addServer`)})]})]})})}function Av({server:e,isAdded:t,onAdd:n}){let{t:r}=W();return(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 rounded-md border border-border/70 bg-card/70 p-3 transition-colors hover:bg-card`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),e.badge&&(0,Z.jsx)(j_,{variant:`secondary`,className:`text-xs shrink-0`,children:e.badge}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-xs shrink-0`,children:e.transport})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description}),e.requiresEnvVars&&e.requiresEnvVars.length>0&&(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-warning`,children:r(`settings:mcp.requires`,{vars:e.requiresEnvVars.join(`, `)})})]}),(0,Z.jsx)(`div`,{className:`shrink-0`,children:t?(0,Z.jsxs)(Y,{variant:`ghost`,size:`sm`,disabled:!0,children:[(0,Z.jsx)(xn,{className:`w-4 h-4 mr-1`}),r(`settings:mcp.added`)]}):(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:n,children:[(0,Z.jsx)(Gi,{className:`w-4 h-4 mr-1`}),r(`common:action.add`)]})})]})}function jv(){let e=hf(),{t}=W(),[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(`list`),[c,l]=(0,X.useState)(),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(),[g,_]=(0,X.useState)(null);(0,X.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]),B.success(U.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)),B.success(U.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)),_(null),B.success(U.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)),_(null),B.info(U.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)),_(null),B.success(U.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)),_(null),B.success(U.t(`settings:mcp.toastReconnected`,{name:t.name}))}},f=e=>{if(e.type===`mcp.server.disconnected`){let t=e.payload,n=t.reason===`stop`||t.reason===`idle-sleep`||t.reason.endsWith(`(dormant)`);r(e=>e.map(e=>e.name===t.name?n?{...e,status:t.reason===`stop`?`stopped`:`sleeping`,pid:void 0}:{...e,status:`error`,error:t.reason,lastError:t.reason,pid:void 0}:e)),_(null),n||B.warn(U.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)),_(null),B.error(U.t(`settings:mcp.toastError`,{name:t.name,error:t.error}))}},m=e=>{if(e.type===`mcp.operation_result`){let t=e.payload;t.success||B.error(t.message),_(null)}},h=e.client.on(`mcp.list`,t),g=e.client.on(`mcp.server.added`,n),v=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?.(),v?.(),y?.(),b?.(),x?.(),S?.(),C?.(),w?.(),T?.(),E?.(),D?.()}},[e.client]);let v=(0,X.useCallback)(t=>{e.client?.addMcpServer(t)},[e]),y=(0,X.useCallback)(e=>{h(Tv(e,!1)),p(!0)},[]),b=(0,X.useCallback)(n=>{$f({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]),x=(0,X.useCallback)(e=>{l(e),h(void 0),d(!0)},[]),S=(0,X.useCallback)(t=>{e.client?.updateMcpServer(t)},[e]),C=(0,X.useCallback)(t=>{_(t),e.client?.wakeMcpServer(t)},[e]),w=(0,X.useCallback)(t=>{_(t),e.client?.sleepMcpServer(t)},[e]),T=(0,X.useCallback)(t=>{_(t),e.client?.discoverMcpServer(t)},[e]),E=(0,X.useCallback)(()=>{a(!0),e.client?.listMcpServers()},[e]),D=n.filter(e=>e.status===`connected`).length,O=n.filter(e=>e.status===`sleeping`).length,k=new Set(n.map(e=>e.name));return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Hn,{className:`h-5 w-5`})}),(0,Z.jsx)(`h2`,{className:`text-base font-semibold`,children:t(`settings:mcp.heading`)}),n.length>0&&(0,Z.jsx)(`span`,{className:`rounded-md border border-border/60 bg-muted/30 px-2 py-1 text-xs text-muted-foreground`,children:t(`settings:mcp.summary`,{connected:D,sleeping:O,total:n.length})})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:E,disabled:i,children:[i?(0,Z.jsx)(mn,{className:`w-4 h-4 animate-spin`}):null,t(`common:action.refresh`)]}),(0,Z.jsxs)(Y,{size:`sm`,onClick:()=>{h(void 0),p(!0)},children:[(0,Z.jsx)(Gi,{className:`w-4 h-4 mr-1`}),t(`settings:mcp.addCustom`)]})]})]}),(0,Z.jsxs)(Sp,{value:o,onValueChange:e=>s(e),children:[(0,Z.jsxs)(Cp,{children:[(0,Z.jsxs)(wp,{value:`recommended`,children:[(0,Z.jsx)(ta,{className:`w-3.5 h-3.5 mr-1`}),t(`settings:mcp.tabRecommended`)]}),(0,Z.jsx)(wp,{value:`list`,children:t(`settings:mcp.tabServers`)}),(0,Z.jsx)(wp,{value:`add`,children:t(`settings:mcp.tabAddCustom`)})]}),(0,Z.jsxs)(Tp,{value:`recommended`,className:`space-y-3`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(`settings:mcp.recommendedBody`)}),(0,Z.jsx)(`div`,{className:`grid gap-2`,children:wv.map(e=>(0,Z.jsx)(Av,{server:e,isAdded:k.has(e.name),onAdd:()=>y(e)},e.name))})]}),(0,Z.jsx)(Tp,{value:`list`,className:`space-y-3`,children:i&&n.length===0?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(mn,{className:`w-5 h-5 animate-spin mr-2`}),t(`settings:mcp.loadingServers`)]}):n.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(Hn,{className:`w-10 h-10 mx-auto mb-2 opacity-50`}),(0,Z.jsx)(`p`,{children:t(`settings:mcp.noServers`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:t(`settings:mcp.noServersHint`)})]}):n.map(e=>(0,Z.jsx)(Ov,{server:e,onWake:()=>C(e.name),onSleep:()=>w(e.name),onDiscover:()=>T(e.name),onEdit:()=>x(e),onRemove:()=>b(e.name)},e.name))}),(0,Z.jsx)(Tp,{value:`add`,children:(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[(0,Z.jsx)(`p`,{children:t(`settings:mcp.addCustomBody`)}),(0,Z.jsx)(`p`,{className:`mt-1`,children:t(`settings:mcp.addCustomBodyHint`)})]})})]}),(0,Z.jsx)(kv,{open:f,onOpenChange:e=>{e||(p(!1),h(void 0))},prefillConfig:m,onSave:v}),(0,Z.jsx)(kv,{open:u,onOpenChange:d,server:c,onSave:S})]})}function Mv({syncPref:e}){let{t}=W(),n=G();return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Hn,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`settings:integrations.wrongProxyHeading`)})})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)($,{label:t(`settings:integrations.wrongProxyEnabledLabel`),hint:t(`settings:integrations.wrongProxyEnabledHint`),value:n.wrongProxyEnabled,onChange:()=>e(`wrongProxyEnabled`,!n.wrongProxyEnabled)}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:t(`settings:integrations.wrongProxyUrlLabel`)}),(0,Z.jsx)(ts,{value:n.wrongProxyUrl,placeholder:`http://localhost:3444`,onChange:t=>e(`wrongProxyUrl`,t.target.value)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.wrongProxyUrlHint`)})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.wrongProxyChangesApply`)})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Hn,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`settings:integrations.hqHeading`)})})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)($,{label:t(`settings:integrations.hqPublishingLabel`),hint:t(`settings:integrations.hqPublishingHint`),value:n.hqEnabled,onChange:()=>e(`hqEnabled`,!n.hqEnabled)}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:t(`settings:integrations.hqUrlLabel`)}),(0,Z.jsx)(ts,{value:n.hqUrl,placeholder:t(`activity:integrationsSection.httpHost3499`),onChange:t=>e(`hqUrl`,t.target.value)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.hqUrlHint`)})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:t(`settings:integrations.hqTokenLabel`)}),(0,Z.jsx)(ts,{type:`password`,value:n.hqToken,placeholder:t(`activity:integrationsSection.clientTokenFromWstackHq`),onChange:t=>e(`hqToken`,t.target.value)})]}),(0,Z.jsx)($,{label:t(`settings:integrations.hqRawContentLabel`),hint:t(`settings:integrations.hqRawContentHint`),value:n.hqRawContent,onChange:()=>e(`hqRawContent`,!n.hqRawContent)})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Hn,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`activity:integrationsSection.mcpServers`)})})]}),n.featureMcp?(0,Z.jsx)(jv,{}):(0,Z.jsxs)(`div`,{className:`text-center py-6 text-muted-foreground`,children:[(0,Z.jsx)(Hn,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:t(`settings:mcp.disabled`)}),(0,Z.jsx)(`p`,{className:`text-xs mt-1`,children:t(`settings:integrations.disabledHint`)})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(At,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`settings:integrations.telegramHeading`)})})]}),n.tgConfigured?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)($,{label:t(`settings:integrations.telegramSessionEndLabel`),hint:t(`settings:integrations.telegramSessionEndHint`),value:n.tgSessionEnd,onChange:()=>e(`tgSessionEnd`,!n.tgSessionEnd)}),(0,Z.jsx)($,{label:t(`settings:integrations.telegramDelegateLabel`),hint:t(`settings:integrations.telegramDelegateHint`),value:n.tgDelegate,onChange:()=>e(`tgDelegate`,!n.tgDelegate)}),(0,Z.jsx)($,{label:t(`settings:integrations.telegramLongToolLabel`),hint:t(`settings:integrations.telegramLongToolHint`,{ms:n.tgLongToolMs}),value:n.tgLongToolMs>0,onChange:()=>e(`tgLongToolMs`,n.tgLongToolMs>0?0:3e4)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.telegramChangesApply`)})]}):(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.telegramNotConfigured`)})]})]})}function Nv({syncPref:e}){let{t}=W(),n=G();return(0,Z.jsx)(`div`,{className:`space-y-6`,children:(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(mt,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`settings:logs.heading`)})})]}),(0,Z.jsx)(Q,{label:t(`settings:logs.logLevelLabel`),hint:t(`settings:logs.logLevelHint`),value:n.logLevel,options:[{value:`debug`,label:t(`settings:logs.logLevelDebug`)},{value:`info`,label:t(`settings:logs.logLevelInfo`)},{value:`warn`,label:t(`settings:logs.logLevelWarn`)},{value:`error`,label:t(`settings:logs.logLevelError`)}],onChange:t=>e(`logLevel`,t)}),(0,Z.jsx)(Q,{label:t(`settings:logs.auditLevelLabel`),hint:t(`settings:logs.auditLevelHint`),value:n.auditLevel,options:[{value:`minimal`,label:t(`settings:logs.auditLevelMinimal`)},{value:`standard`,label:t(`settings:logs.auditLevelStandard`)},{value:`full`,label:t(`settings:logs.auditLevelFull`)}],onChange:t=>e(`auditLevel`,t)}),(0,Z.jsx)(Q,{label:t(`settings:logs.fsAccessLabel`),hint:t(`settings:logs.fsAccessHint`),value:n.fsAccess,options:[{value:`unrestricted`,label:t(`settings:logs.fsAccessUnrestricted`)},{value:`project`,label:t(`settings:logs.fsAccessProject`)}],onChange:t=>e(`fsAccess`,t)}),(0,Z.jsx)($,{label:t(`settings:logs.debugStreamLabel`),hint:t(`settings:logs.debugStreamHint`),value:n.debugStream,onChange:()=>e(`debugStream`,!n.debugStream)})]})})}function Pv({syncPref:e}){let{t}=W(),n=G(e=>e.reasoningEffort),r=H(e=>e.reasoningEffortLevels),i=Um(r,n).map(e=>({value:e,label:t(Hm(e))}));return(0,Z.jsx)(`div`,{className:`mt-4 border-t border-border/60 pt-4`,children:(0,Z.jsx)(Q,{label:t(`settings:agent.reasoningEffortLabel`),hint:Wm(r,n)?t(`settings:agent.reasoningEffortUnsupported`,{levels:(r??[]).join(`, `)}):r?`${t(`settings:agent.reasoningEffortHint`)} (${t(`settings:agent.reasoningEffortModelSet`)})`:t(`settings:agent.reasoningEffortHint`),value:n,options:i,onChange:t=>e(`reasoningEffort`,t)})})}function Fv({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,isSwitching:i,setIsLoadingModels:a,onModelSelect:o,refreshModels:s}){let c=V(e=>e.model),{t:l}=W();return(0,Z.jsx)(`div`,{className:`space-y-4`,children:e?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:n?.name||e}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>{a(!0),s(e)},children:(0,Z.jsx)(Yn,{className:K(`h-4 w-4`,r&&`animate-spin`)})})]}),r&&!t[e]?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,Z.jsx)(mn,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:l(`settings:model.loading`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(h_,{options:(t[e]||[]).map(e=>({id:e.id,label:e.name||e.id,badges:e.capabilities,detail:[e.contextWindow?`${Math.round(e.contextWindow/1e3)}k`:``,e.inputCost==null?``:`${e.inputCost}/${e.outputCost}`,e.reasoningEffortLevels?.length?`effort ${e.reasoningEffortLevels.join(`/`)}`:``].filter(Boolean).join(` · `),detailHighlight:!0})),selectedId:c,onSelect:o,disabled:i,emptyMessage:l(`settings:model.notFound`)}),i?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`settings:toast.switching`)}):null]})]}):(0,Z.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(On,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,Z.jsx)(`p`,{children:l(`settings:model.selectProviderFirst`)})]})})}var Iv=[{value:`off`,label:`Off`,hint:`The leader never changes its own tier.`},{value:`propose`,label:`Propose`,hint:`The leader asks before switching. Recommended.`},{value:`auto`,label:`Auto`,hint:`The leader switches on its own, still bounded by the guard rails below.`}],Lv={};function Rv({syncPref:e}){let t=G(),n=t.modelTiers??{},r=n.levels??{},i=n.routing??{},a=n.leader??{},o=Object.keys(r),s=Object.keys(t.fallbackProfiles??{}),[c,l]=(0,X.useState)(``),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(``),m=(0,X.useCallback)(t=>e(`modelTiers`,{...n,...t}),[e,n]),h=(0,X.useCallback)((t,i)=>e(`modelTiers`,{...n,levels:{...r,[t]:{...r[t]??{},...i}}}),[e,n,r]),g=(0,X.useCallback)(t=>{let a={...r};delete a[t];let o=Object.fromEntries(Object.entries(i).filter(([,e])=>e!==t));e(`modelTiers`,{...n,levels:a,routing:o})},[e,n,r,i]),_=()=>{let e=c.trim();e&&!r[e]&&(h(e,Lv),l(``))},v=()=>{let e=u.trim();e&&f&&(m({routing:{...i,[e]:f}}),d(``),p(``))},y=e=>{let t={...i};delete t[e],m({routing:t})},b=e=>{let t=e.trim();if(!t)return;let n=Number.parseFloat(t);return Number.isFinite(n)&&n>=0?n:void 0};return(0,Z.jsxs)(`section`,{className:`space-y-3`,"data-testid":`model-tiers-section`,children:[(0,Z.jsxs)(`header`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Mi,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:`Model cost tiers`}),(0,Z.jsxs)(`label`,{className:`ml-auto flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:n.enabled===!0,onChange:e=>m({enabled:e.target.checked}),"data-testid":`model-tiers-enabled`}),`Enabled`]})]}),(0,Z.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:`A tier binds a fallback profile, a spend budget and a runtime setting under one name, then routes work to it by role or phase. Subagents, Kanban dispatch and the leader all read this table. While disabled, everything resolves exactly as it did before tiers existed.`}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,Z.jsx)(`h4`,{className:`text-xs font-medium text-foreground`,children:`Levels`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Order is the ladder — the first row is the cheapest rung.`})]}),o.length===0&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`No levels yet. Add one below, then point it at a fallback profile.`}),o.map((e,t)=>{let n=r[e]??{};return(0,Z.jsxs)(`div`,{className:`space-y-1.5 rounded-md border border-border bg-muted px-2 py-1.5`,"data-testid":`model-tier-row-${e}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:t+1}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 break-words font-mono font-medium text-foreground`,children:e}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:`text-muted-foreground hover:text-destructive`,title:`Remove level`,"data-testid":`model-tier-remove-${e}`,children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Z.jsxs)(`select`,{value:n.fallbackProfile??``,onChange:t=>h(e,{fallbackProfile:t.target.value||void 0}),className:`rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-profile-${e}`,children:[(0,Z.jsx)(`option`,{value:``,children:`profile: (none)`}),s.map(e=>(0,Z.jsxs)(`option`,{value:e,children:[`profile: `,e]},e))]}),(0,Z.jsx)(`input`,{type:`number`,min:0,step:`0.01`,value:n.maxCostUsd??``,onChange:t=>h(e,{maxCostUsd:b(t.target.value)}),placeholder:`max $`,className:`w-20 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-cost-${e}`}),(0,Z.jsx)(`input`,{type:`number`,min:0,value:n.maxIterations??``,onChange:t=>h(e,{maxIterations:b(t.target.value)}),placeholder:`iters`,className:`w-16 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`}),(0,Z.jsx)(`input`,{type:`number`,min:0,value:n.maxToolCalls??``,onChange:t=>h(e,{maxToolCalls:b(t.target.value)}),placeholder:`tools`,className:`w-16 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`})]}),n.maxCostUsd!==void 0&&(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Tightens a role's default budget down to this ceiling; it never raises one, and never overrides a budget passed explicitly to the spawn.`})]},e)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_()},placeholder:`new level name (e.g. budget)`,className:`min-w-0 flex-1 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-new-name`}),(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:_,disabled:!c.trim(),children:[(0,Z.jsx)(Gi,{className:`mr-1 h-3 w-3`}),` Add`]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`h4`,{className:`text-xs font-medium text-foreground`,children:`Routing`}),Object.keys(i).length===0?(0,Z.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`No rules — everything uses the default tier`,n.default?` (${n.default})`:` (standard)`,`.`]}):(0,Z.jsx)(`ul`,{className:`space-y-1`,children:Object.entries(i).map(([e,t])=>(0,Z.jsxs)(`li`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-muted px-2 py-1 text-[11px]`,"data-testid":`model-tier-route-${e}`,children:[(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 break-words font-mono text-foreground`,children:[e,` → `,t]}),!r[t]&&(0,Z.jsx)(`span`,{className:`rounded-sm bg-warning/15 px-1 py-0.5 text-[10px] text-foreground`,children:`missing level`}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>y(e),className:`text-muted-foreground hover:text-destructive`,title:`Remove rule`,children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]},e))}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),placeholder:`role, phase, or *`,className:`min-w-0 flex-1 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-new-route-key`}),(0,Z.jsxs)(`select`,{value:f,onChange:e=>p(e.target.value),className:`rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-new-route-tier`,children:[(0,Z.jsx)(`option`,{value:``,children:`tier…`}),o.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]}),(0,Z.jsx)(Y,{size:`sm`,variant:`outline`,onClick:v,disabled:!u.trim()||!f,children:(0,Z.jsx)(Gi,{className:`h-3 w-3`})})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Default tier`}),(0,Z.jsxs)(`select`,{value:n.default??``,onChange:e=>m({default:e.target.value||void 0}),className:`rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-default`,children:[(0,Z.jsx)(`option`,{value:``,children:`standard`}),o.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`h4`,{className:`text-xs font-medium text-foreground`,children:`Leader self-switching`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Iv.map(e=>{let t=(a.mode??`propose`)===e.value;return(0,Z.jsx)(`button`,{type:`button`,title:e.hint,onClick:()=>m({leader:{...a,mode:e.value}}),className:t?`rounded-sm border border-primary bg-primary/10 px-2 py-0.5 text-[11px] text-foreground`:`rounded-sm border border-border bg-background px-2 py-0.5 text-[11px] text-muted-foreground hover:text-foreground`,"data-testid":`model-tier-leader-${e.value}`,children:e.label},e.value)})}),(0,Z.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:Iv.find(e=>e.value===(a.mode??`propose`))?.hint}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-1 text-muted-foreground`,children:[`dwell`,(0,Z.jsx)(`input`,{type:`number`,min:0,value:a.dwellTurns??``,onChange:e=>m({leader:{...a,dwellTurns:b(e.target.value)}}),placeholder:`6`,className:`w-14 rounded-sm border border-border bg-background px-1.5 py-0.5`,"data-testid":`model-tier-leader-dwell`}),`turns`]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-1 text-muted-foreground`,children:[`min saving $`,(0,Z.jsx)(`input`,{type:`number`,min:0,step:`0.01`,value:a.minSavingsUsd??``,onChange:e=>m({leader:{...a,minSavingsUsd:b(e.target.value)}}),placeholder:`0.10`,className:`w-16 rounded-sm border border-border bg-background px-1.5 py-0.5`})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-1 text-muted-foreground`,children:[`ceiling`,(0,Z.jsxs)(`select`,{value:a.maxTier??``,onChange:e=>m({leader:{...a,maxTier:e.target.value||void 0}}),className:`rounded-sm border border-border bg-background px-1.5 py-0.5`,"data-testid":`model-tier-leader-ceiling`,children:[(0,Z.jsx)(`option`,{value:``,children:`none`}),o.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})]})]}),(0,Z.jsx)(`p`,{className:`text-[10px] leading-relaxed text-muted-foreground`,children:`A switch invalidates the prompt cache, so a downgrade is refused unless the projected saving over the dwell window covers re-reading the conversation on the new model. A downgrade into a context window the session no longer fits is refused outright.`})]})]})}function zv(){let e=(0,X.useRef)([]);return{setFieldRef:(0,X.useCallback)(t=>n=>{e.current[t]=n},[]),handleKeyDown:(0,X.useCallback)((t,n,r)=>{if(t.key===`ArrowDown`){t.preventDefault();for(let t=n+1;t<e.current.length;t++){let n=e.current[t];if(n&&!n.hasAttribute(`disabled`)&&n.getAttribute(`aria-disabled`)!==`true`){if(n.focus(),n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement){let e=n.value.length;n.setSelectionRange(e,e)}return}}return}if(t.key===`ArrowUp`){t.preventDefault();for(let t=n-1;t>=0;t--){let n=e.current[t];if(n&&!n.hasAttribute(`disabled`)&&n.getAttribute(`aria-disabled`)!==`true`){n.focus(),(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement)&&n.setSelectionRange(n.value.length,n.value.length);return}}return}t.key===`Enter`&&r&&(t.preventDefault(),r())},[])}}function Bv({models:e,onChange:t}){let{t:n}=W(),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)([]),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),h=(0,X.useRef)(void 0),g=(0,X.useRef)(null),_=V(e=>e.wsUrl),v=(0,X.useCallback)(e=>{if(!e.trim()){c([]);return}u(!0);let t=S(_),n=t.on(`provider.models.search_result`,t=>{let n=t.payload;n&&n.query===e.trim()&&(c(n.matches??[]),u(!1))});t.searchProviderModels(e.trim(),8),setTimeout(()=>{n?.(),u(!1)},5e3)},[_]);(0,X.useEffect)(()=>{if(h.current&&clearTimeout(h.current),!a.trim()){c([]);return}return h.current=setTimeout(()=>v(a),250),()=>{h.current&&clearTimeout(h.current)}},[a,v]);let y=(0,X.useCallback)((n,r)=>{if(!n||e.some(e=>e.id===n))return;let a={id:n,name:r?.name??r?.modelId??n,...r?.maxOutput?{maxOutput:r.maxOutput}:{},capabilities:{...r?.contextWindow?{maxContext:r.contextWindow}:{},...r?.capabilities.includes(`tools`)?{tools:!0}:{},...r?.capabilities.includes(`vision`)?{vision:!0}:{},...r?.capabilities.includes(`reasoning`)?{reasoning:!0}:{}}};t([...e,a]),o(``),c([]),i(!1)},[e,t]),b=(0,X.useCallback)(n=>{t(e.filter(e=>e.id!==n))},[e,t]),x=(0,X.useCallback)(()=>{let e=p.trim();e&&(y(e),m(``),f(!1))},[p,y]);return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground block`,children:n(`setup:screen.custom.models`)}),e.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,Z.jsxs)(`div`,{className:K(`group inline-flex items-center gap-1 px-2 py-1 text-xs rounded`,`bg-accent/10 text-accent border border-accent/20`),title:e.name&&e.name!==e.id?`${e.name}\n${e.capabilities?.maxContext?`maxContext: ${e.capabilities.maxContext}`:``}${e.maxOutput?`\nmaxOutput: ${e.maxOutput}`:``}`:void 0,children:[(0,Z.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.name&&e.name!==e.id?e.name:e.id}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>b(e.id),className:`opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive`,children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]},e.id))}),r?(0,Z.jsxs)(`div`,{className:`space-y-2 p-3 rounded border border-border/60 bg-muted/20`,children:[(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(Tt,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(ts,{placeholder:n(`setup:screen.custom.modelSearchPlaceholder`),value:a,onChange:e=>o(e.target.value),className:`text-sm pl-8`,autoFocus:!0}),l&&(0,Z.jsx)(mn,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 animate-spin text-muted-foreground`})]}),s.length>0&&(0,Z.jsx)(`div`,{className:`space-y-1 max-h-40 overflow-y-auto`,children:s.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>y(e.modelId,e),className:K(`w-full flex items-start gap-2 p-2 text-left text-xs rounded transition-colors`,`hover:bg-accent/10 border border-transparent hover:border-accent/30`),children:[(0,Z.jsx)(xn,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-muted-foreground`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`font-medium block truncate`,children:e.name}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground block`,children:[e.providerName,` · `,e.modelId,e.contextWindow?` · ${(e.contextWindow/1e3).toFixed(0)}K ctx`:``,e.maxOutput?` · ${e.maxOutput.toLocaleString()} out`:``]})]})]},`${e.providerId}\u0000${e.modelId}`))}),!l&&a.trim()&&s.length===0&&(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground text-center py-2`,children:[n(`setup:screen.custom.noCatalogMatch`),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{f(!0),setTimeout(()=>g.current?.focus(),50)},className:`ml-1 text-accent underline underline-offset-2 hover:text-accent/80`,children:n(`setup:screen.custom.useCustomId`)})]}),d&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ts,{ref:g,placeholder:n(`setup:screen.custom.customModelIdPlaceholder`),value:p,onChange:e=>m(e.target.value),className:`text-sm flex-1`,onKeyDown:e=>{e.key===`Enter`&&x()}}),(0,Z.jsxs)(Y,{type:`button`,size:`sm`,onClick:x,disabled:!p.trim(),children:[(0,Z.jsx)(xn,{className:`h-3.5 w-3.5 mr-1`}),n(`setup:screen.custom.add`)]})]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-2 pt-1`,children:(0,Z.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{i(!1),o(``),c([]),f(!1),m(``)},className:`text-xs`,children:n(`setup:screen.custom.cancel`)})})]}):(0,Z.jsxs)(Y,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>i(!0),className:`text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5 mr-1`}),n(`setup:screen.custom.addModel`)]}),e.length>0&&(0,Z.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[e.length,` `,e.length===1?n(`setup:screen.custom.modelSingular`):n(`setup:screen.custom.modelPlural`)]})]})}function Vv({maskedKey:e,className:t}){let{t:n}=W(),[r,i]=(0,X.useState)(!1),a=(0,X.useCallback)(()=>{navigator.clipboard.writeText(e).then(()=>{i(!0),setTimeout(()=>i(!1),1500)})},[e]);return(0,Z.jsxs)(`div`,{className:K(`group flex items-center gap-1.5 rounded-md border border-border/50 bg-background/50 px-2 py-1 font-mono text-xs text-muted-foreground`,t),children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate tracking-wide`,children:e}),(0,Z.jsx)(`button`,{type:`button`,onClick:a,className:`shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-all hover:text-foreground group-hover:opacity-100 focus:opacity-100`,title:r?`Copied`:`Copy key preview`,"aria-label":n(`activity:apikeydisplay.copyApiKeyToClipboard`),children:r?(0,Z.jsx)(xn,{className:`h-3 w-3 text-success`}):(0,Z.jsx)(zr,{className:`h-3 w-3`})})]})}var Hv={openrouter:{id:`openrouter`,name:`OpenRouter (Metered)`,family:`openai-compatible`,baseUrl:`https://openrouter.ai/api/v1`,envVars:[`OPENROUTER_API_KEY`],models:[`openai/gpt-4o`,`openai/gpt-4o-mini`,`anthropic/claude-sonnet-4-20250514`,`google/gemini-2.0-flash-001`,`meta-llama/llama-4-scout`,`deepseek/deepseek-chat`],usage:`metered-api`,docsUrl:`https://openrouter.ai/docs/quickstart`,autoDiscover:!0,requestPolicy:`openrouter`,catalog:{description:`All models via one key`,icon:`🔀`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`sk-or-...`}},"kimi-for-coding":{id:`kimi-for-coding`,name:`Kimi Code (Subscription)`,family:`openai-compatible`,baseUrl:`https://api.kimi.com/coding/v1`,envVars:[`KIMI_API_KEY`],models:[`kimi-for-coding`,`kimi-for-coding-highspeed`],quirks:{thinkingParam:`kimi-toggle`},usage:`subscription-interactive`,docsUrl:`https://www.kimi.com/code/docs/en/third-party-tools/other-coding-agents.html`,requestPolicy:`kimi`,catalog:{description:`Personal interactive coding with the Kimi Code subscription key. Generate the API key at kimi.com/code/console.`,icon:`🌙`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`sk-...`}},moonshotai:{id:`moonshotai`,name:`Moonshot Platform (Metered)`,family:`openai-compatible`,baseUrl:`https://api.moonshot.ai/v1`,envVars:[`MOONSHOT_API_KEY`],models:[`kimi-k2.7-code`,`kimi-k2.7-code-highspeed`],quirks:{thinkingParam:`always-on`},usage:`metered-api`,docsUrl:`https://platform.kimi.ai/docs/api/overview`,requestPolicy:`kimi`,catalog:{description:`Metered Moonshot Platform API — pay-as-you-go for automation, background work, and commercial use.`,icon:`🌑`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`sk-...`}},"zai-coding-plan":{id:`zai-coding-plan`,name:`Z.AI Coding Plan (Subscription)`,family:`openai-compatible`,baseUrl:`https://api.z.ai/api/coding/paas/v4`,envVars:[`ZHIPU_API_KEY`],models:[`glm-5.2`,`glm-5-turbo`,`glm-4.7`],quirks:{thinkingParam:`zai-glm`},usage:`subscription-interactive`,docsUrl:`https://docs.z.ai/devpack/quick-start`,requestPolicy:`zai`,catalog:{description:`Use your Z.AI Coding Plan subscription. Generate an API key from your Z.AI dashboard.`,icon:`🔷`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`...`}},zai:{id:`zai`,name:`Z.AI API (Metered)`,family:`openai-compatible`,baseUrl:`https://api.z.ai/api/paas/v4`,envVars:[`ZHIPU_API_KEY`],models:[`glm-4.7`,`glm-5-turbo`,`glm-5.2`],quirks:{thinkingParam:`zai-glm`},usage:`metered-api`,docsUrl:`https://docs.z.ai/guides/overview/quick-start`,requestPolicy:`zai`,catalog:{description:`Pay-as-you-go Z.AI GLM access for automation and commercial use.`,icon:`🔷`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`...`,referral:{code:`JQZ7TPPRA6`,reward:`Limited-time deal for GLM Coding Plan subscription`,url:`https://z.ai/subscribe?ic=JQZ7TPPRA6`}}},minimax:{id:`minimax`,name:`MiniMax Token Plan (Subscription)`,family:`openai-compatible`,baseUrl:`https://api.minimax.io/v1`,envVars:[`MINIMAX_API_KEY`],models:[`MiniMax-M3`,`MiniMax-M2.7`,`MiniMax-M2.5`,`MiniMax-M2`],usage:`subscription-interactive`,docsUrl:`https://platform.minimax.io/docs/api-reference/text-chat-openai`,catalog:{description:`Subscribe to one plan and unlock frontier coding, 1M context, and native multimodality.`,icon:`🔮`,color:`from-destructive/10 to-destructive/5 border-destructive/25 hover:border-destructive/45`,keyPlaceholder:`eyJ...`,referral:{code:`JrA4R9QAEn`,reward:`Friends get 10% off + Builder benefits. Referrers earn 10% cashback + community perks.`,url:`https://platform.minimax.io/subscribe/token-plan?code=JrA4R9QAEn&source=link`}}},mistral:{id:`mistral`,name:`Mistral AI API (Metered)`,family:`openai-compatible`,baseUrl:`https://api.mistral.ai/v1`,envVars:[`MISTRAL_API_KEY`],models:[`mistral-large-latest`,`codestral-latest`,`ministral-8b-latest`],usage:`metered-api`,docsUrl:`https://docs.mistral.ai/`,catalog:{description:`Mistral Large, Codestral, and Ministral — open-weight frontier models.`,icon:`🌬️`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`Vz8d...`}},deepseek:{id:`deepseek`,name:`DeepSeek API (Metered)`,family:`openai-compatible`,baseUrl:`https://api.deepseek.com`,envVars:[`DEEPSEEK_API_KEY`],models:[`deepseek-v4-flash`,`deepseek-v4-pro`],usage:`metered-api`,docsUrl:`https://api-docs.deepseek.com/`,requestPolicy:`deepseek`,catalog:{description:`High-performance reasoning at low cost`,icon:`🐋`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`sk-...`}},groq:{id:`groq`,name:`GroqCloud (Metered)`,family:`openai-compatible`,baseUrl:`https://api.groq.com/openai/v1`,envVars:[`GROQ_API_KEY`],models:[`llama-3.3-70b-versatile`,`llama-3.1-8b-instant`,`mixtral-8x7b-32768`,`gemma2-9b-it`],usage:`metered-api`,docsUrl:`https://console.groq.com/docs/api-reference`,requestPolicy:`groq`,catalog:{description:`Ultra-fast inference via LPU hardware — Llama, Mixtral, Gemma, and Qwen models.`,icon:`⚡`,color:`from-warning/12 to-warning/5 border-warning/30 hover:border-warning/50`,keyPlaceholder:`gsk_...`}},perplexity:{id:`perplexity`,name:`Perplexity Sonar API (Metered)`,family:`openai-compatible`,baseUrl:`https://api.perplexity.ai`,envVars:[`PERPLEXITY_API_KEY`],models:[`sonar-pro`,`sonar`,`sonar-reasoning-pro`,`sonar-reasoning`],usage:`metered-api`,docsUrl:`https://docs.perplexity.ai/`,requestPolicy:`perplexity`,catalog:{description:`Web-augmented chat models with built-in search and citations.`,icon:`🔍`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`pplx-...`}},"alibaba-token-plan":{id:`alibaba-token-plan`,name:`Alibaba Token Plan (Personal Edition)`,family:`openai-compatible`,baseUrl:`https://dashscope.aliyuncs.com/compatible-mode/v1`,envVars:[`ALIBABA_API_KEY`,`DASHSCOPE_API_KEY`],models:[`qwen3.8-max-preview`,`qwen3.7-max`,`qwen3.7-plus`,`qwen3.6-flash`,`glm-5.2`,`deepseek-v4-pro`,`wan2.7-image`,`wan2.7-image-pro`,`happyhorse-1.1-t2v`,`happyhorse-1.1-i2v`,`happyhorse-1.1-r2v`],customModels:{"qwen3.8-max-preview":{capabilities:{tools:!0,vision:!0,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"qwen3.7-max":{capabilities:{tools:!0,vision:!1,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"qwen3.7-plus":{capabilities:{tools:!0,vision:!0,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"qwen3.6-flash":{capabilities:{tools:!0,vision:!0,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"glm-5.2":{capabilities:{tools:!0,vision:!1,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"deepseek-v4-pro":{capabilities:{tools:!0,vision:!1,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!1,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"wan2.7-image":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}},"wan2.7-image-pro":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}},"happyhorse-1.1-t2v":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}},"happyhorse-1.1-i2v":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}},"happyhorse-1.1-r2v":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}}},usage:`subscription-interactive`,docsUrl:`https://www.alibabacloud.com/help/en/model-studio/token-plan-personal-overview`,requestPolicy:`alibaba`,catalog:{description:`Monthly Credits subscription for Qwen, DeepSeek, GLM, Wanx image, and HappyHorse video models.`,icon:`☁️`,color:`from-warning/12 to-warning/5 border-warning/30 hover:border-warning/50`,keyPlaceholder:`sk-...`}}};Object.keys(Hv);var Uv=[{id:`openai`,name:`OpenAI`,family:`openai`,envVars:[`OPENAI_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://platform.openai.com/api-keys`,catalog:{description:`GPT, o-series, and Codex models`,icon:`🤖`,color:`from-success/12 to-success/5 border-success/30 hover:border-success/50`,keyPlaceholder:`sk-...`}},{id:`anthropic`,name:`Anthropic`,family:`anthropic`,envVars:[`ANTHROPIC_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://console.anthropic.com/settings/keys`,catalog:{description:`Claude model access`,icon:`🧠`,color:`from-warning/12 to-warning/5 border-warning/30 hover:border-warning/50`,keyPlaceholder:`sk-ant-...`}},{id:`google`,name:`Google`,family:`google`,envVars:[`GOOGLE_GENERATIVE_AI_API_KEY`,`GEMINI_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://aistudio.google.com/apikey`,catalog:{description:`Gemini Pro, Flash, and Nano`,icon:`✨`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`AIza...`}},{id:`openai-codex`,name:`OpenAI Codex OAuth`,family:`openai-codex`,envVars:[],models:[],usage:`subscription-interactive`,docsUrl:`https://developers.openai.com/codex/`},{id:`anthropic-oauth`,name:`Anthropic OAuth`,family:`anthropic-oauth`,envVars:[],models:[],usage:`subscription-interactive`,docsUrl:`https://docs.anthropic.com/`},{id:`github-copilot`,name:`GitHub Copilot`,family:`github-copilot`,envVars:[],models:[],usage:`subscription-interactive`,docsUrl:`https://docs.github.com/en/copilot`},{id:`opencode-go`,name:`OpenCode Go`,family:`openai-compatible`,baseUrl:`https://opencode.ai/zen/go/v1`,envVars:[`OPENCODE_API_KEY`],models:[],usage:`subscription-interactive`,docsUrl:`https://opencode.ai/go?ref=6VZAER87H4`,catalog:{description:`Global hosted API for 75+ LLM providers — stable access from US, EU, and Singapore`,icon:`🌍`,color:`from-success/12 to-success/5 border-success/30 hover:border-success/50`,keyPlaceholder:`oc-...`,referral:{code:`6VZAER87H4`,reward:`Support the project by signing up with this referral link`,url:`https://opencode.ai/go?ref=6VZAER87H4`}}},{id:`xai`,name:`xAI`,family:`openai-compatible`,baseUrl:`https://api.x.ai/v1`,envVars:[`XAI_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://docs.x.ai/`,autoDiscover:!0,modelDiscoveryPath:`language-models`,modelDiscoveryAuthoritative:!0,requestPolicy:`xai`},{id:`ai-gateway`,name:`Vercel AI Gateway`,family:`openai-compatible`,baseUrl:`https://ai-gateway.vercel.sh/v1`,discoveryOnlyBaseUrl:!0,envVars:[`AI_GATEWAY_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://vercel.com/docs/ai-gateway`,autoDiscover:!0,catalog:{description:`Every model behind one key — routed by Vercel AI Gateway`,icon:`▲`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`vck_...`}}],Wv=[{id:`omniroute`,name:`OmniRoute`,family:`openai-compatible`,baseUrl:`http://localhost:20128/v1`,envVars:[],models:[],usage:`local`,quirks:{stripThinkTags:!0},autoDiscover:!0,local:{noAuth:!0,hint:`WrongStack local gateway · port 20128 · no key · auto-discovers models`}},{id:`ollama`,name:`Ollama`,family:`openai-compatible`,baseUrl:`http://localhost:11434/v1`,envVars:[],models:[],usage:`local`,docsUrl:`https://ollama.com`,local:{noAuth:!0,hint:`ollama.com · port 11434 · no key`}},{id:`vllm`,name:`vLLM`,family:`openai-compatible`,baseUrl:`http://localhost:8000/v1`,envVars:[],models:[],usage:`local`,docsUrl:`https://docs.vllm.ai`,local:{noAuth:!1,hint:`docs.vllm.ai · port 8000 · optional key`}},{id:`lmstudio`,name:`LM Studio`,family:`openai-compatible`,baseUrl:`http://localhost:1234/v1`,envVars:[],models:[],usage:`local`,docsUrl:`https://lmstudio.ai`,local:{noAuth:!1,hint:`lmstudio.ai · port 1234 · optional key`}}],Gv=Object.fromEntries([...Uv,...Object.values(Hv),...Wv].map(e=>[e.id,e]));function Kv(){return Wv.map(e=>{if(!e.baseUrl||!e.local)throw Error(`Local provider definition is incomplete: ${e.id}`);return{id:e.id,label:e.name,defaultBaseUrl:e.baseUrl,noAuth:e.local.noAuth,hint:e.local.hint}})}function qv(){return Object.values(Gv).filter(e=>e.catalog!==void 0).map(e=>({id:e.id,name:e.name,family:e.family,description:e.catalog.description,icon:e.catalog.icon,color:e.catalog.color,keyPlaceholder:e.catalog.keyPlaceholder,...e.docsUrl?{docsUrl:e.docsUrl}:{},...e.catalog.referral?{referral:{...e.catalog.referral}}:{}}))}var Jv=`openai-compatible`,Yv=Kv();function Xv(e){return e===`chatgpt`?(0,Z.jsx)(Wr,{className:`h-5 w-5`}):e===`claude`?(0,Z.jsx)(on,{className:`h-5 w-5`}):e===`copilot`?(0,Z.jsx)(vi,{className:`h-5 w-5`}):(0,Z.jsx)(qt,{className:`h-5 w-5`})}var Zv=[`awaiting_browser`,`awaiting_code`,`exchanging`,`fetching_models`];function Qv({ws:e,savedProviders:t=[]}){let{t:n}=W(),[r,i]=(0,X.useState)({}),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(null);(0,X.useEffect)(()=>{let t=e.on(`auth.oauth.providers`,e=>{e.type===`auth.oauth.providers`&&o(e.payload.providers.map(({id:e,providerId:t,label:n,description:r})=>({id:e,providerId:t,label:n,...r?{description:r}:{}})))}),n=e.on(`auth.oauth.status`,e=>{if(e.type!==`auth.oauth.status`)return;let t=e.payload;i(e=>({...e,[t.kind]:{...t}})),t.phase===`success`?(B.success(t.message??U.t(`settings:oauth.signedInToast`,{provider:t.providerId??t.kind})),u(null),c(``),f(null),m(``)):t.phase===`error`&&B.error(t.message??U.t(`settings:oauth.signInFailed`))});return e.listOAuthProviders(),()=>{n?.(),t?.()}},[e]);let _=(0,X.useCallback)(t=>{i(e=>({...e,[t]:{phase:`exchanging`}})),e.startOAuth(t)},[e]),v=(0,X.useCallback)((t,n)=>{i(e=>({...e,[t]:{phase:`exchanging`}})),e.startOAuth(t,n)},[e]),y=(0,X.useCallback)(t=>{let n=p.trim();n&&(i(e=>({...e,[t]:{phase:`exchanging`}})),e.startOAuth(t,n),f(null),m(``))},[e,p]),b=(0,X.useCallback)(t=>{e.cancelOAuth(t),i(e=>({...e,[t]:{phase:`idle`}})),u(null)},[e]),x=(0,X.useCallback)(t=>{let n=s.trim();n&&(e.submitOAuthCode(t,n),i(e=>({...e,[t]:{...e[t],phase:`exchanging`}})))},[s,e]);return(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 p-3`,children:(0,Z.jsx)(`p`,{className:`text-xs leading-5 text-warning`,children:n(`settings:oauth.termsWarning`)})}),(0,Z.jsx)(`div`,{className:`grid grid-cols-1 gap-2 lg:grid-cols-3`,children:a.map(e=>{let i=r[e.id]??{phase:`idle`},a=Zv.includes(i.phase),o=t.filter(t=>t.id===e.providerId||t.id.startsWith(`${e.providerId}-`)),S=o?.length??0,C=h===e.id;return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/70 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 lg:flex-col lg:items-stretch`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:Xv(e.id)}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,Z.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.description??`→ ${e.providerId}`})]})]}),a?(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>b(e.id),className:`shrink-0 lg:w-full`,children:n(`common:action.cancel`)}):(0,Z.jsx)(Y,{size:`sm`,onClick:()=>_(e.id),className:`shrink-0 lg:w-full`,children:n(`settings:oauth.signIn`)})]}),i.phase===`awaiting_browser`&&(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2 border-t pt-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Z.jsx)(mn,{className:`h-4 w-4 animate-spin text-muted-foreground`}),(0,Z.jsx)(`span`,{children:n(`settings:oauth.waitingBrowser`)})]}),i.authorizeUrl&&(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>window.open(i.authorizeUrl,`_blank`,`noopener,noreferrer`),children:[(0,Z.jsx)(Gt,{className:`h-3.5 w-3.5 mr-1`}),n(`settings:oauth.openSignIn`)]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`button`,{type:`button`,className:`text-xs text-muted-foreground underline`,onClick:()=>u(l===e.id?null:e.id),children:i.bound===!1?n(`settings:oauth.pasteLoopbackBusy`):n(`settings:oauth.pasteCantReach`)}),l===e.id&&(0,Z.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Z.jsx)(ts,{placeholder:n(`activity:oauth.httpLocalhostCallbackCode`),value:s,onChange:e=>c(e.target.value),className:`font-mono text-xs`,onKeyDown:t=>{t.key===`Enter`&&x(e.id)}}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>x(e.id),disabled:!s.trim(),children:n(`settings:oauth.submit`)})]})]})]}),i.phase===`awaiting_code`&&(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2 border-t pt-3`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`settings:oauth.enterCode`)}),(0,Z.jsx)(`div`,{className:`font-mono text-2xl font-bold tracking-widest`,children:i.userCode??`…`}),i.verificationUri&&(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>window.open(i.verificationUri,`_blank`,`noopener,noreferrer`),children:[(0,Z.jsx)(Gt,{className:`h-3.5 w-3.5 mr-1`}),n(`settings:oauth.openVerification`)]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(mn,{className:`h-3.5 w-3.5 animate-spin`}),(0,Z.jsx)(`span`,{children:n(`settings:oauth.waitingCode`)})]})]}),(i.phase===`exchanging`||i.phase===`fetching_models`)&&(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t pt-3 text-sm`,children:[(0,Z.jsx)(mn,{className:`h-4 w-4 animate-spin text-muted-foreground`}),(0,Z.jsx)(`span`,{children:i.phase===`exchanging`?n(`settings:oauth.exchanging`):n(`settings:oauth.fetchingModels`)})]}),i.phase===`success`&&(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t pt-3 text-sm text-success`,children:[(0,Z.jsx)(Bn,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:i.message??n(`settings:oauth.signedIn`)})]}),i.phase===`error`&&i.message&&(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t pt-3 text-sm text-destructive`,children:[(0,Z.jsx)(qr,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:i.message})]}),S>0&&!a&&(0,Z.jsxs)(`div`,{className:`mt-3 border-t pt-3`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>g(C?null:e.id),className:`flex w-full items-center justify-between text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Z.jsx)(qt,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{children:n(`settings:oauth.accountCount`,{count:S})})]}),(0,Z.jsx)(`span`,{className:`text-[10px]`,children:C?`▲`:`▼`})]}),C&&o&&(0,Z.jsxs)(`div`,{className:`mt-2 space-y-1.5`,children:[o.map(t=>(0,Z.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border/60 bg-muted/20 px-2.5 py-1.5`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs`,children:t.id}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[t.hasActiveKey?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-success`,children:[(0,Z.jsx)(Bn,{className:`h-3 w-3`}),n(`settings:oauth.active`)]}):(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:n(`settings:oauth.inactive`)}),(0,Z.jsxs)(Y,{size:`sm`,variant:`ghost`,onClick:()=>v(e.id,t.id),className:`h-6 px-1.5 text-[11px]`,title:n(`settings:oauth.retryLogin`),children:[(0,Z.jsx)(Yn,{className:`h-3 w-3 mr-0.5`}),n(`settings:oauth.retry`)]})]})]},t.id)),(0,Z.jsx)(`div`,{className:`pt-1`,children:d===e.id?(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(ts,{autoFocus:!0,placeholder:n(`settings:oauth.aliasPlaceholder`,{default:`${e.providerId}-2`}),value:p,onChange:e=>m(e.target.value),className:`text-xs font-mono`,onKeyDown:t=>{t.key===`Enter`&&y(e.id)}}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>y(e.id),disabled:!p.trim(),children:n(`settings:oauth.signIn`)}),(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>{f(null),m(``)},children:n(`common:action.cancel`)})]}):(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>f(e.id),className:`w-full text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5 mr-1`}),n(`settings:oauth.newAccount`)]})})]})]}),S===0&&!a&&(0,Z.jsx)(`div`,{className:`mt-3 border-t pt-3`,children:d===e.id?(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(ts,{autoFocus:!0,placeholder:n(`settings:oauth.aliasPlaceholder`,{default:`${e.providerId}-2`}),value:p,onChange:e=>m(e.target.value),className:`text-xs font-mono`,onKeyDown:t=>{t.key===`Enter`&&y(e.id)}}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>y(e.id),disabled:!p.trim(),children:n(`settings:oauth.signIn`)}),(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>{f(null),m(``)},children:n(`common:action.cancel`)})]}):(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>f(e.id),className:`w-full text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5 mr-1`}),n(`settings:oauth.newAccount`)]})})]},e.id)})})]})}function $v({open:e,providerId:t,modelCount:n,onConfirm:r,onCancel:i}){let a=(0,X.useRef)(null),{t:o}=W();return(0,X.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,Z.jsx)(es,{open:e,onOpenChange:e=>{e||i()},children:(0,Z.jsxs)(Zo,{className:`sm:max-w-md border-warning/50`,ref:a,tabIndex:-1,"data-clear-allowlist-dialog":!0,children:[(0,Z.jsxs)(Yo,{children:[(0,Z.jsxs)(Qo,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(dr,{className:`h-5 w-5 text-warning`}),o(`settings:allowlist.title`)]}),(0,Z.jsx)($o,{children:o(`settings:allowlist.body`,{count:n,provider:t})})]}),(0,Z.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,Z.jsxs)(Xo,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:i,title:o(`settings:allowlist.keepTitle`),"data-action":`cancel`,children:[o(`common:action.cancel`),` `,(0,Z.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`Esc`})]}),(0,Z.jsxs)(Y,{variant:`destructive`,size:`sm`,onClick:r,title:o(`settings:allowlist.clearTitle`),"data-action":`confirm`,children:[o(`settings:allowlist.clear`),` `,(0,Z.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`↵`})]})]})]})})}function ey({ws:e,onSelect:t,onClose:n}){let{t:r}=W(),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(!1),u=(0,X.useRef)(null),d=(0,X.useRef)(``);(0,X.useEffect)(()=>e.on(`provider.models.search_result`,e=>{if(e.type!==`provider.models.search_result`)return;let t=e.payload;(t.query===void 0||t.query===d.current)&&(s(t.matches??[]),l(!1))}),[e]);let f=(0,X.useCallback)(t=>{if(!t.trim()){s([]),d.current=``;return}d.current=t,l(!0),e.searchProviderModels(t,8)},[e]);(0,X.useEffect)(()=>(u.current&&clearTimeout(u.current),u.current=setTimeout(()=>f(i),300),()=>{u.current&&clearTimeout(u.current)}),[i,f]);let p=(0,X.useCallback)(e=>{let n={name:e.name,...e.description?{description:e.description}:{},...e.releaseDate?{release_date:e.releaseDate}:{},...e.contextWindow||e.maxOutput?{limit:{...e.contextWindow?{context:e.contextWindow}:{},...e.maxOutput?{output:e.maxOutput}:{}}}:{},...e.inputCost||e.outputCost?{cost:{...e.inputCost?{input:e.inputCost}:{},...e.outputCost?{output:e.outputCost}:{}}}:{},...e.capabilities.length>0?{tool_call:e.capabilities.includes(`tools`),reasoning:e.capabilities.includes(`reasoning`),...e.capabilities.includes(`vision`)?{modalities:{input:[`text`,`image`]}}:{}}:{}};t(e.modelId,n)},[t]);return(0,Z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/50`,onClick:n,"aria-label":r(`common:action.close`)}),(0,Z.jsxs)(`div`,{className:`relative max-h-[80vh] w-full max-w-xl overflow-y-auto rounded-lg border border-border bg-background p-4 shadow-lg`,children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`settings:providerModels.catalogSearchTitle`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-foreground`,children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`relative mb-3`,children:[(0,Z.jsx)(Tt,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/60`}),(0,Z.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:r(`settings:providerModels.catalogSearchPlaceholder`),className:`h-10 w-full rounded-md border border-border bg-background pl-9 pr-3 text-sm focus:outline-none focus:ring-1 focus:ring-ring`})]}),c?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Z.jsx)(mn,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):o.length>0?(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:o.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>p(e),className:`block w-full rounded-md border border-border/60 p-2.5 text-left transition-colors hover:border-primary/40 hover:bg-primary/5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-sm font-medium text-foreground`,children:e.modelId}),e.name!==e.modelId&&(0,Z.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.name})]}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:e.providerName})]}),e.description&&(0,Z.jsx)(`p`,{className:`mt-0.5 line-clamp-2 text-xs text-muted-foreground`,children:e.description}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1.5`,children:[e.contextWindow?(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:e.contextWindow>=1e6?`${(e.contextWindow/1e6).toFixed(1)}M ctx`:`${Math.round(e.contextWindow/1e3)}K ctx`}):null,e.capabilities.map(e=>(0,Z.jsx)(`span`,{className:`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:e},e))]})]},`${e.providerId}:${e.modelId}`))}):i.trim()?(0,Z.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:r(`settings:providerModels.noResults`)}):(0,Z.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:r(`settings:providerModels.typeToSearch`)})]})]})}var ty=new Set([`__proto__`,`constructor`,`prototype`,`__defineGetter__`,`__defineSetter__`,`__lookupGetter__`,`__lookupSetter__`]);`document`in globalThis&&fr({jitless:!0});var ny=[`text`,`image`,`audio`,`video`,`pdf`],ry=[`none`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`],iy=Ui().int().nonnegative(),ay=Ui().finite(),oy=an({context:iy.optional(),output:iy.optional(),input:iy.optional()}),sy=an({input:ay.optional(),output:ay.optional(),cache_read:ay.optional(),cache_write:ay.optional(),cache_write_5m:ay.optional(),cache_write_1h:ay.optional(),context_over_200k:ay.optional(),reasoning:ay.optional(),input_audio:ay.optional(),output_audio:ay.optional()}),cy=an({input:Wn(cr().min(1)).optional(),output:Wn(cr().min(1)).optional()}),ly=nr([an({type:Rt(`toggle`)}),an({type:Rt(`effort`),values:Wn(Ut(ry)).optional()}),an({type:Rt(`budget_tokens`),min:Ui().optional(),max:Ui().optional()})]),uy=e=>({message:`${e} id is a forbidden prototype-pollution key`}),dy=an({id:cr().min(1).refine(e=>!ty.has(e),uy(`Model`)),name:cr().min(1),description:cr().optional(),family:cr().optional(),provider:an({npm:cr().optional(),api:cr().optional()}).optional(),attachment:Zn().optional(),reasoning:Zn().optional(),reasoning_options:nr([ly,Wn(ly)]).optional(),interleaved:nr([Zn(),an({field:cr().optional()})]).optional(),tool_call:Zn().optional(),structured_output:Zn().optional(),temperature:Zn().optional(),knowledge:cr().optional(),release_date:cr().optional(),last_updated:cr().optional(),open_weights:Zn().optional(),modalities:cy.optional(),cost:sy.optional(),limit:oy.optional(),status:cr().optional(),experimental:Zn().optional()}),fy=an({id:cr().min(1).refine(e=>!ty.has(e),uy(`Provider`)),name:cr().min(1),env:Wn(cr()).optional(),npm:cr().optional(),api:cr().optional(),doc:cr().optional(),models:Qt(cr(),dy)});Qt(cr(),fy);function py(e,t){let n=t.limit,r=t.cost,i=t.modalities;return{id:e,name:t.name??``,description:t.description??``,family:t.family??``,limitContext:n?.context==null?``:String(n.context),limitOutput:n?.output==null?``:String(n.output),limitInput:n?.input==null?``:String(n.input),costInput:r?.input==null?``:String(r.input),costOutput:r?.output==null?``:String(r.output),inputModalities:Array.isArray(i?.input)?i.input:[],outputModalities:Array.isArray(i?.output)?i.output:[],toolCall:t.tool_call===!0,reasoning:t.reasoning===!0,temperature:t.temperature===!0,attachment:t.attachment===!0,structuredOutput:t.structured_output===!0,openWeights:t.open_weights===!0,releaseDate:t.release_date??``,lastUpdated:t.last_updated??``,knowledge:t.knowledge??``}}function my(e,t){let n={...t};e.name&&(n.name=e.name),e.description&&(n.description=e.description),e.family&&(n.family=e.family),e.knowledge&&(n.knowledge=e.knowledge);let r={};if(e.limitContext){let t=Number(e.limitContext);Number.isFinite(t)&&t>=0&&(r.context=t)}if(e.limitOutput){let t=Number(e.limitOutput);Number.isFinite(t)&&t>=0&&(r.output=t)}if(e.limitInput){let t=Number(e.limitInput);Number.isFinite(t)&&t>=0&&(r.input=t)}Object.keys(r).length>0&&(n.limit={...t.limit??{},...r});let i={};if(e.costInput){let t=Number(e.costInput);Number.isFinite(t)&&t>=0&&(i.input=t)}if(e.costOutput){let t=Number(e.costOutput);Number.isFinite(t)&&t>=0&&(i.output=t)}Object.keys(i).length>0&&(n.cost={...t.cost??{},...i});let a={};e.inputModalities.length>0&&(a.input=e.inputModalities),e.outputModalities.length>0&&(a.output=e.outputModalities),Object.keys(a).length>0&&(n.modalities={...t.modalities??{},...a});for(let[r,i]of[[`toolCall`,`tool_call`],[`reasoning`,`reasoning`],[`temperature`,`temperature`],[`attachment`,`attachment`],[`structuredOutput`,`structured_output`],[`openWeights`,`open_weights`]]){let a=t[i]===!0;e[r]!==a&&(n[i]=e[r])}return e.releaseDate&&(n.release_date=e.releaseDate),e.lastUpdated&&(n.last_updated=e.lastUpdated),n}var hy=[{key:`toolCall`,labelKey:`settings:modelSchema.capToolCall`},{key:`reasoning`,labelKey:`settings:modelSchema.capReasoning`},{key:`temperature`,labelKey:`settings:modelSchema.capTemperature`},{key:`attachment`,labelKey:`settings:modelSchema.capAttachment`},{key:`structuredOutput`,labelKey:`settings:modelSchema.capStructuredOutput`},{key:`openWeights`,labelKey:`settings:modelSchema.capOpenWeights`}];function gy({providerId:e,modelId:t,initialModelsDev:n,onSave:r,onCancel:i}){let{t:a}=W(),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(()=>py(t,n)),[u,d]=(0,X.useState)([]),[f,p]=(0,X.useState)(JSON.stringify({...n,...t?{id:t}:{}},null,2)),[m,h]=(0,X.useState)(null),g=(0,X.useCallback)((e,t)=>{l(n=>({...n,[e]:t}))},[]),_=(0,X.useCallback)((e,t)=>{l(n=>{let r=n[e];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),v=(0,X.useCallback)(()=>{let e=my(c,n),i=dy.safeParse({...e,id:c.id||t});if(!i.success){d(i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`));return}d([]),r(c.id||t,e)},[c,n,t,r]),y=(0,X.useCallback)(()=>{try{let e=JSON.parse(f),n=dy.safeParse({...e,id:t||e.id});if(!n.success){h(n.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `));return}let{id:i,...a}=n.data;h(null),r(t||n.data.id,a)}catch(e){h(e instanceof Error?e.message:String(e))}},[f,t,r]),b=`h-8 w-full rounded-md border border-border bg-background px-2.5 text-sm focus:outline-none focus:ring-1 focus:ring-ring`,x=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-muted-foreground`;return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-1 border-b border-border/50`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>s(!1),className:K(`border-b-2 px-3 py-1 text-xs font-medium transition-colors`,o?`border-transparent text-muted-foreground hover:text-foreground`:`border-primary text-primary`),children:a(`settings:providerModels.tabForm`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:K(`border-b-2 px-3 py-1 text-xs font-medium transition-colors`,o?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`),children:a(`settings:providerModels.tabRawJson`)})]}),o?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),rows:16,className:`w-full rounded-md border border-border bg-muted/20 p-2 font-mono text-xs`,spellCheck:!1}),m&&(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:m})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionIdentity`)}),!t&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-id`,children:`ID`}),(0,Z.jsx)(`input`,{id:`mse-id`,className:b,value:c.id,onChange:e=>g(`id`,e.target.value),placeholder:a(`activity:modelSchema.modelId`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-name`,children:a(`settings:providerModels.fieldName`)}),(0,Z.jsx)(`input`,{id:`mse-name`,className:b,value:c.name,onChange:e=>g(`name`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-desc`,children:a(`settings:providerModels.fieldDescription`)}),(0,Z.jsx)(`input`,{id:`mse-desc`,className:b,value:c.description,onChange:e=>g(`description`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-family`,children:a(`settings:providerModels.fieldFamily`)}),(0,Z.jsx)(`input`,{id:`mse-family`,className:b,value:c.family,onChange:e=>g(`family`,e.target.value)})]})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionLimits`)}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-ctx`,children:a(`settings:providerModels.fieldContext`)}),(0,Z.jsx)(`input`,{id:`mse-ctx`,type:`number`,className:b,value:c.limitContext,onChange:e=>g(`limitContext`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-out`,children:a(`settings:providerModels.fieldOutput`)}),(0,Z.jsx)(`input`,{id:`mse-out`,type:`number`,className:b,value:c.limitOutput,onChange:e=>g(`limitOutput`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-inlim`,children:a(`settings:providerModels.fieldInputLimit`)}),(0,Z.jsx)(`input`,{id:`mse-inlim`,type:`number`,className:b,value:c.limitInput,onChange:e=>g(`limitInput`,e.target.value)})]})]})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionPricing`)}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-costin`,children:a(`settings:providerModels.fieldCostInput`)}),(0,Z.jsx)(`input`,{id:`mse-costin`,type:`number`,step:`0.01`,className:b,value:c.costInput,onChange:e=>g(`costInput`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-costout`,children:a(`settings:providerModels.fieldCostOutput`)}),(0,Z.jsx)(`input`,{id:`mse-costout`,type:`number`,step:`0.01`,className:b,value:c.costOutput,onChange:e=>g(`costOutput`,e.target.value)})]})]})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionModalities`)}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:x,children:a(`settings:providerModels.fieldInputModalities`)}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:ny.map(e=>{let t=c.inputModalities.includes(e);return(0,Z.jsx)(`button`,{type:`button`,onClick:()=>_(`inputModalities`,e),className:K(`rounded-md border px-2 py-1 text-xs transition-colors`,t?`border-primary bg-primary/10 text-primary`:`border-border text-muted-foreground hover:border-primary/30`),children:e},`in-mod-${e}`)})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:x,children:a(`settings:providerModels.fieldOutputModalities`)}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:ny.map(e=>{let t=c.outputModalities.includes(e);return(0,Z.jsx)(`button`,{type:`button`,onClick:()=>_(`outputModalities`,e),className:K(`rounded-md border px-2 py-1 text-xs transition-colors`,t?`border-primary bg-primary/10 text-primary`:`border-border text-muted-foreground hover:border-primary/30`),children:e},`out-mod-${e}`)})})]})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionCapabilities`)}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:hy.map(({key:e,labelKey:t})=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 rounded border-border`,checked:c[e],onChange:t=>g(e,t.target.checked)}),a(t)]},String(e)))})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionDates`)}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-release`,children:a(`settings:providerModels.fieldReleaseDate`)}),(0,Z.jsx)(`input`,{id:`mse-release`,type:`date`,className:b,value:c.releaseDate,onChange:e=>g(`releaseDate`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-updated`,children:a(`settings:providerModels.fieldLastUpdated`)}),(0,Z.jsx)(`input`,{id:`mse-updated`,type:`date`,className:b,value:c.lastUpdated,onChange:e=>g(`lastUpdated`,e.target.value)})]})]})]}),u.length>0&&(0,Z.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 p-2`,children:(0,Z.jsx)(`ul`,{className:`space-y-0.5 text-xs text-destructive`,children:u.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))})})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-border/50 pt-3`,children:[(0,Z.jsxs)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:i,className:`h-8 gap-1.5 text-xs`,children:[(0,Z.jsx)(hn,{className:`h-3.5 w-3.5`}),a(`common:action.cancel`)]}),(0,Z.jsxs)(Y,{type:`button`,size:`sm`,onClick:o?y:v,className:`h-8 gap-1.5 text-xs`,children:[(0,Z.jsx)(xn,{className:`h-3.5 w-3.5`}),a(`common:action.save`)]})]})]})}function _y(e,t){return e.map(e=>{let n=t?.[e],r=n?.modelsDev,i=!!(n&&(n.name||n.maxOutput||n.capabilities||r));return{modelId:e,name:r?.name??n?.name??e,modelsDev:r,maxOutput:n?.maxOutput??r?.limit?.output,capabilities:n?.capabilities,source:i?`overridden`:`catalog`}})}function vy(e){let t=e?.limit?.context;if(typeof t==`number`&&t>0)return t>=1e6?`${(t/1e6).toFixed(1)}M`:`${Math.round(t/1e3)}K`}function yy(e){let t=e?.cost,n=e=>typeof e==`number`&&e>=0?`$${e}`:void 0;return{input:n(t?.input),output:n(t?.output)}}function by(e){let t=e?.modalities;return{input:Array.isArray(t?.input)?t.input:[],output:Array.isArray(t?.output)?t.output:[]}}var xy={text:Vn,image:or,audio:yr,video:Na,pdf:Vn};function Sy({providerId:e,models:t,customModels:n,ws:r,pickedModelId:i,onPickModel:a}){let{t:o}=W(),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),h=(0,X.useMemo)(()=>_y(t,n),[t,n]),g=(0,X.useMemo)(()=>{let e=p.trim().toLowerCase();return e?h.filter(t=>t.modelId.toLowerCase().includes(e)||(t.name?.toLowerCase().includes(e)??!1)):h},[h,p]),_=(0,X.useCallback)(t=>{r.removeCustomModel(e,t),B.success(o(`settings:providerModels.modelRemoved`,{model:t}))},[r,e,o]),v=(0,X.useCallback)((t,n)=>{r.setCustomModel(e,t,{modelsDev:n}),c(null),B.success(o(`settings:providerModels.modelSaved`,{model:t}))},[r,e,o]),y=(0,X.useCallback)((t,n)=>{r.setCustomModel(e,t,{modelsDev:n}),u(!1),B.success(o(`settings:providerModels.modelAdded`,{model:t}))},[r,e,o]);return(0,Z.jsxs)(`div`,{className:`space-y-3`,"data-model-list-editor":e,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:()=>u(!0),className:`h-8 gap-1.5 text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),o(`settings:providerModels.addFromCatalog`)]}),(0,Z.jsxs)(Y,{variant:`ghost`,size:`sm`,onClick:()=>f(!0),className:`h-8 gap-1.5 text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),o(`settings:providerModels.addCustom`)]})]}),h.length>0&&(0,Z.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border/70`,children:[h.length>8&&(0,Z.jsxs)(`div`,{className:`relative border-b border-border/40 bg-muted/10`,children:[(0,Z.jsx)(Tt,{className:`pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground/60`}),(0,Z.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:o(`settings:providerModels.filterPlaceholder`),"aria-label":o(`settings:providerModels.filterPlaceholder`),className:`h-8 w-full bg-transparent pl-9 pr-3 text-xs text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-ring`})]}),(0,Z.jsx)(`div`,{className:`max-h-80 overflow-y-auto`,children:(0,Z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-border/70 bg-muted/30 text-left text-[11px] uppercase tracking-wide text-muted-foreground`,children:[(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colModel`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colContext`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colOutput`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colCost`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colModalities`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colCaps`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colSource`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2`,"aria-label":o(`settings:providerModels.colActions`)})]})}),(0,Z.jsx)(`tbody`,{children:g.map(t=>{let n=vy(t.modelsDev),r=t.maxOutput??t.modelsDev?.limit?.output,l=typeof r==`number`?r.toLocaleString():void 0,u=yy(t.modelsDev),d=by(t.modelsDev),f=t.capabilities,p=s===t.modelId;return(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsxs)(`tr`,{className:`border-b border-border/40 transition-colors hover:bg-muted/20`,children:[(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-xs font-medium text-foreground`,children:t.modelId}),t.name&&t.name!==t.modelId&&(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:t.name})]})}),(0,Z.jsx)(`td`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:n?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(la,{className:`h-3 w-3`}),n]}):(0,Z.jsx)(`span`,{className:`text-muted-foreground/40`,children:`—`})}),(0,Z.jsx)(`td`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:l?(0,Z.jsx)(`span`,{children:l}):(0,Z.jsx)(`span`,{className:`text-muted-foreground/40`,children:`—`})}),(0,Z.jsx)(`td`,{className:`px-3 py-2 text-xs`,children:u.input||u.output?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Z.jsx)(en,{className:`h-3 w-3`}),u.input&&u.output?`${u.input}/${u.output}`:u.input??u.output]}):(0,Z.jsx)(`span`,{className:`text-muted-foreground/40`,children:`—`})}),(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[d.input.map(e=>{let t=xy[e]??Vn;return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-primary/10 px-1 py-0.5 text-[10px] text-primary`,title:`input: ${e}`,children:[(0,Z.jsx)(t,{className:`h-2.5 w-2.5`}),e]},`in-${e}`)}),d.output.map(e=>(0,Z.jsx)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-secondary/20 px-1 py-0.5 text-[10px] text-secondary-foreground`,title:`output: ${e}`,children:e},`out-${e}`))]})}),(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsxs)(`div`,{className:`flex gap-1`,children:[f?.tools&&(0,Z.jsx)(_n,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-label":o(`activity:modelListEditor.tools`)}),f?.reasoning&&(0,Z.jsx)(Jn,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-label":o(`activity:modelListEditor.reasoning`)}),f?.vision&&(0,Z.jsx)(ja,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-label":o(`activity:modelListEditor.vision`)})]})}),(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsx)(`span`,{className:K(`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium`,t.source===`custom`&&`bg-warning/10 text-warning`,t.source===`catalog`&&`bg-info/10 text-info`,t.source===`overridden`&&`bg-primary/10 text-primary`),children:t.source})}),(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[a&&(t.modelId===i?(0,Z.jsx)(`span`,{className:`inline-flex items-center rounded p-1 text-primary`,title:o(`settings:providerModels.usingModel`,{model:t.modelId}),role:`img`,"aria-label":o(`settings:providerModels.usingModel`,{model:t.modelId}),children:(0,Z.jsx)(xn,{className:`h-3.5 w-3.5`})}):(0,Z.jsx)(`button`,{type:`button`,onClick:()=>a(e,t.modelId),className:`rounded p-1 text-muted-foreground transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":o(`settings:providerModels.useModel`,{model:t.modelId}),title:o(`settings:providerModels.useModel`,{model:t.modelId}),children:(0,Z.jsx)(xn,{className:`h-3.5 w-3.5`})})),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>c(p?null:t.modelId),className:`rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,"aria-label":o(`settings:providerModels.editModel`,{model:t.modelId}),children:(0,Z.jsx)(hr,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>_(t.modelId),className:`rounded p-1 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive`,"aria-label":o(`settings:providerModels.removeModel`,{model:t.modelId}),children:(0,Z.jsx)(jn,{className:`h-3.5 w-3.5`})})]})})]}),p&&(0,Z.jsx)(`tr`,{className:`border-b border-border/40 bg-muted/10`,children:(0,Z.jsx)(`td`,{colSpan:8,className:`p-3`,children:(0,Z.jsx)(gy,{providerId:e,modelId:t.modelId,initialModelsDev:t.modelsDev??{},onSave:v,onCancel:()=>c(null)})})},`${t.modelId}-edit`)]},t.modelId)})})]})})]}),h.length===0&&(0,Z.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/50 p-8 text-center`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o(`settings:providerModels.emptyState`)})}),l&&(0,Z.jsx)(ey,{ws:r,onSelect:y,onClose:()=>u(!1)}),d&&(0,Z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/50`,onClick:()=>f(!1),"aria-label":o(`common:action.close`)}),(0,Z.jsxs)(`div`,{className:`relative max-h-[80vh] w-full max-w-2xl overflow-y-auto rounded-lg border border-border bg-background p-4 shadow-lg`,children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:o(`settings:providerModels.addCustomTitle`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>f(!1),className:`text-muted-foreground hover:text-foreground`,children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),(0,Z.jsx)(gy,{providerId:e,modelId:``,initialModelsDev:{},onSave:v,onCancel:()=>f(!1)})]})]})]})}function Cy(){return{inFlight:!1,last:null,picked:null}}function wy(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 Ty(e){if(e.inFlight)return{text:`Checking model endpoint...`,tone:`muted`};let t=e.last;if(!t)return{text:`Saved model list shown`,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:`Server returned ${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:`Provider is no longer saved`,tone:`error`};case`no_base_url`:return{text:`No model endpoint configured`,tone:`warning`}}}function Ey(e){return(e?.length??0)>0}function Dy(e,t){return`Allowlist cleared for ${e} — ${t} model${t===1?``:`s`} removed`}function Oy(e){return e.length>0}function ky(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 Ay=3e3;function jy({providerId:e,savedPickedModelId:t,savedModels:n,savedCustomModels:r,ws:i,onPickModel:a,onClearModels:o,onUndoClear:s}){let[c,l]=(0,X.useState)(()=>Cy()),{t:u}=W(),[d,f]=(0,X.useState)(!1);(0,X.useEffect)(()=>i.on(`provider.probe`,t=>{t.type===`provider.probe`&&t.payload.providerId===e&&l(e=>({...e,inFlight:!1,last:wy(t.payload)}))}),[i,e]);let p=(0,X.useCallback)(()=>{l(e=>({...e,inFlight:!0})),i.probeProvider(e,Ay)},[i,e]),m=(0,X.useCallback)((e,t)=>{l(e=>({...e,picked:t})),a?.(e,t)},[a]),h=(0,X.useCallback)(()=>{f(!0)},[]),g=(0,X.useCallback)(()=>{f(!1)},[]),_=(0,X.useCallback)(()=>{f(!1);let t=n?[...n]:[];l(e=>({...e,picked:null,last:null})),o?o(e):i.clearProviderModels(e),Oy(t)&&B.undoable(Dy(e,t.length),()=>{let n=ky({providerId:e,previousModels:t,onUndoClear:s});switch(n.kind){case`skip`:return;case`callback`:s?.(n.providerId,n.previousModels);return;case`ws-default`:i.undoProviderClear(n.providerId,n.previousModels);return}})},[o,s,i,e,n]),v=(0,X.useMemo)(()=>c.picked??t??n?.[0]??``,[c.picked,t,n]),y=(0,X.useMemo)(()=>Ty(c),[c]),b=(0,X.useMemo)(()=>Ey(n),[n]);return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/75 p-3 shadow-sm shadow-black/[0.02]`,"data-provider-models-panel":e,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,Z.jsx)(Fn,{className:`h-3.5 w-3.5`}),u(`activity:providerModels.allowlistTitle`)]}),n&&n.length>0&&(0,Z.jsx)(`span`,{className:`rounded-full border border-border/70 bg-muted/40 px-2 py-0.5 text-[11px] text-muted-foreground`,children:u(`activity:providerModels.modelCount`,{count:n.length})})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:u(`activity:providerModels.using`)}),v?(0,Z.jsx)(`span`,{className:`max-w-full break-words rounded-md bg-primary/10 px-2 py-0.5 font-mono text-xs text-primary`,children:v}):(0,Z.jsx)(`span`,{className:`text-xs italic text-muted-foreground`,children:u(`activity:providerModels.noModelPicked`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 sm:justify-end`,children:[(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:p,disabled:c.inFlight,"aria-label":u(`activity:providerModels.refreshAria`,{provider:e}),className:`h-8 px-2 text-xs`,children:[c.inFlight?(0,Z.jsx)(mn,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Yn,{className:`h-3.5 w-3.5`}),c.inFlight?u(`activity:providerModels.probing`):u(`activity:providerModels.refresh`)]}),b&&(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:h,"aria-label":u(`activity:providerModels.clearAllowlistAria`,{provider:e}),"data-action":`clear-models`,className:`h-8 px-2 text-xs`,children:u(`activity:providerModels.clearAllowlist`)})]})]}),(0,Z.jsx)(My,{formatted:y}),(0,Z.jsx)(`div`,{className:`mt-3`,children:(0,Z.jsx)(Sy,{providerId:e,models:n??[],customModels:r,ws:i,pickedModelId:v??void 0,onPickModel:m})}),(0,Z.jsx)($v,{open:d,providerId:e,modelCount:n?.length??0,onConfirm:_,onCancel:g})]})}function My({formatted:e}){let t=e.tone===`success`?`text-success`:e.tone===`warning`?`text-warning`:e.tone===`error`?`text-destructive`:`text-muted-foreground`,n=e.tone===`success`?`bg-success`:e.tone===`warning`?`bg-warning`:e.tone===`error`?`bg-destructive`:`bg-muted-foreground/60`;return(0,Z.jsxs)(`p`,{className:`mt-2 flex items-center gap-1.5 text-xs ${t}`,"data-probe-tone":e.tone,children:[(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${n}`}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text})]})}var Ny=[`anthropic`,`openai`,`google`,`openai-compatible`];function Py({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:f,onPickProviderModel:p,ws:m,catalogQuery:h,setCatalogQuery:g}){let{t:_}=W(),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(``),[A,j]=(0,X.useState)(`openai-compatible`),[M,N]=(0,X.useState)(``),[P,F]=(0,X.useState)(``),[I,L]=(0,X.useState)([]),ee=zv(),R=zv(),z=(0,X.useCallback)(e=>{b.trim()&&S.trim()&&(c(e,b.trim(),S.trim()),x(``),C(``),y(null))},[c,b,S]),te=(0,X.useCallback)(()=>{O.trim()&&(d(O.trim(),A,M||void 0,P||void 0,I.length>0?I.map(e=>e.id):void 0,I.length>0?Object.fromEntries(I.filter(e=>e.name||e.maxOutput||e.capabilities&&Object.keys(e.capabilities).length>0).map(e=>[e.id,{...e.name&&e.name!==e.id?{name:e.name}:{},...e.maxOutput?{maxOutput:e.maxOutput}:{},...e.capabilities&&Object.keys(e.capabilities).length>0?{capabilities:e.capabilities}:{}}])):void 0),k(``),j(`openai-compatible`),N(``),F(``),L([]),D(!1))},[d,O,A,M,P,I]),ne=(0,X.useCallback)(e=>{k(e.id),j(Jv),N(e.defaultBaseUrl),e.noAuth&&F(``),L([])},[]),[re,ie]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(``),[se,ce]=(0,X.useState)(!1),[le,ue]=(0,X.useState)({}),de=(0,X.useMemo)(()=>new Set(r.map(e=>e.id)),[r]),fe=(0,X.useMemo)(()=>({keys:r.reduce((e,t)=>e+t.apiKeys.length,0),activeKeys:r.reduce((e,t)=>e+t.apiKeys.filter(e=>e.isActive).length,0),models:r.reduce((e,t)=>e+(t.models?.length??0),0)}),[r]);(0,X.useEffect)(()=>{let e=m.on(`provider.probe`,e=>{if(e.type!==`provider.probe`)return;let t=e.payload;t.status!==`no_base_url`&&t.status!==`no_provider`&&ue(e=>({...e,[t.providerId]:{ok:t.ok,status:t.status,detail:t.detail}}))});return()=>e?.()},[m]);let pe=(0,X.useCallback)(e=>{let t=ae.trim();t&&(de.has(e.id)?c(e.id,`default`,t):d(e.id,e.family,e.apiBase??void 0,t),oe(``),ie(null),ce(!1),B.success(_(`settings:provider.savedToast`,{name:e.name})),e.apiBase&&setTimeout(()=>m.probeProvider(e.id,6e3),700))},[ae,de,c,d,m]),me=h.trim()?t.filter(e=>{let t=h.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,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,Z.jsx)(cn,{className:`h-4 w-4 text-muted-foreground`}),_(`settings:provider.subscriptionHeading`)]}),(0,Z.jsx)(Qv,{ws:m,savedProviders:r.map(e=>({id:e.id,hasActiveKey:e.apiKeys.some(e=>e.isActive)}))})]}),(0,Z.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(Yi,{className:`h-4 w-4 text-muted-foreground`}),_(`settings:provider.apiKeysHeading`)]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:_(`settings:provider.apiKeysBody`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,Z.jsxs)(Y,{variant:a===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>o(`catalog`),children:[(0,Z.jsx)(Yi,{className:`h-4 w-4 mr-1`}),_(`settings:provider.tabCatalog`)]}),(0,Z.jsxs)(Y,{variant:a===`saved`?`default`:`outline`,size:`sm`,onClick:()=>o(`saved`),children:[(0,Z.jsx)(cn,{className:`h-4 w-4 mr-1`}),_(`settings:provider.tabSaved`,{count:r.length})]})]}),a===`catalog`&&(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(ts,{placeholder:_(`settings:provider.searchPlaceholder`,{count:t.length}),value:h,onChange:e=>g(e.target.value),className:`text-sm`}),n&&t.length===0?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,Z.jsx)(mn,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:_(`settings:provider.loadingCatalog`)})]}):me.length===0&&h?(0,Z.jsx)(`div`,{className:`text-center py-8 text-muted-foreground text-sm`,children:_(`settings:provider.noMatch`,{query:h})}):Ny.map(t=>{let n=he[t];return n?.length?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:t}),(0,Z.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:n.map(t=>{let n=le[t.id],r=e===t.id;return(0,Z.jsxs)(`div`,{className:K(`rounded-lg border transition-all`,r?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border`),children:[(0,Z.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,Z.jsxs)(`div`,{className:`flex w-full justify-between items-start`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,Z.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,t.id,`)`]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.hasApiKey&&(0,Z.jsxs)(`span`,{className:`text-xs bg-success/10 text-success px-2 py-0.5 rounded`,children:[(0,Z.jsx)(cn,{className:`h-3 w-3 inline mr-1`}),_(`settings:provider.configured`)]}),n&&(0,Z.jsxs)(`span`,{className:K(`text-xs px-2 py-0.5 rounded inline-flex items-center gap-1`,n.ok?`bg-success/10 text-success`:`bg-destructive/10 text-destructive`),title:n.detail??n.status,children:[n.ok?(0,Z.jsx)(Bn,{className:`h-3 w-3`}):(0,Z.jsx)(qr,{className:`h-3 w-3`}),n.ok?_(`settings:provider.reachable`):n.status]}),t.envVars[0]&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:_(`settings:provider.envVar`,{var:t.envVars[0]})}),r&&(0,Z.jsx)(Bn,{className:`h-4 w-4 text-primary`})]})]}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[_(`settings:provider.modelCount`,{count:t.modelCount}),t.apiBase&&` · ${t.apiBase}`]})]}),r&&!t.hasApiKey&&(0,Z.jsx)(`div`,{className:`px-3 pb-3 -mt-1 space-y-2`,children:re===t.id?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(ts,{autoFocus:!0,type:se?`text`:`password`,placeholder:_(`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,Z.jsx)(Y,{size:`icon`,variant:`ghost`,onClick:()=>ce(e=>!e),children:se?(0,Z.jsx)(ht,{className:`h-4 w-4`}):(0,Z.jsx)(ja,{className:`h-4 w-4`})}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>pe(t),disabled:!ae.trim(),children:_(`common:action.save`)})]}),t.envVars[0]&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:_(`settings:provider.orEnv`,{env:t.envVars[0]})})]}):(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>{ie(t.id),oe(``)},children:[(0,Z.jsx)(cn,{className:`h-3.5 w-3.5 mr-1`}),_(`settings:provider.addApiKey`)]})})]},t.id)})})]},t):null})]}),a===`saved`&&(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:_(`settings:provider.manageKeys`)}),(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-muted/30 px-2 py-1`,children:[(0,Z.jsx)(Hn,{className:`h-3.5 w-3.5`}),_(`settings:provider.savedProviderCount`,{count:r.length})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-muted/30 px-2 py-1`,children:[(0,Z.jsx)(cn,{className:`h-3.5 w-3.5`}),_(`settings:provider.keyCount`,{count:fe.keys})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-muted/30 px-2 py-1`,children:[(0,Z.jsx)(Oa,{className:`h-3.5 w-3.5`}),_(`settings:provider.activeKeyCount`,{count:fe.activeKeys})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-muted/30 px-2 py-1`,children:[(0,Z.jsx)(On,{className:`h-3.5 w-3.5`}),_(`settings:provider.modelCount`,{count:fe.models})]})]})]}),(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>D(!E),children:[(0,Z.jsx)(Gi,{className:`h-4 w-4 mr-1`}),_(`settings:provider.addProvider`)]})]}),E&&(0,Z.jsxs)(`div`,{className:`p-4 border rounded-lg space-y-3 bg-muted/50`,children:[(0,Z.jsx)(`h4`,{className:`font-medium`,children:_(`settings:provider.addCustomHeading`)}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:_(`settings:provider.localServers`)}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Yv.map(e=>(0,Z.jsx)(Y,{type:`button`,size:`sm`,variant:O===e.id?`default`:`outline`,onClick:()=>ne(e),title:e.hint,children:e.label},e.id))})]}),(0,Z.jsx)(ts,{placeholder:_(`settings:provider.providerIdPlaceholder`),value:O,onChange:e=>k(e.target.value),ref:ee.setFieldRef(0),onKeyDown:e=>ee.handleKeyDown(e,0)}),(0,Z.jsxs)(`select`,{className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:A,onChange:e=>j(e.target.value),ref:ee.setFieldRef(1),onKeyDown:e=>ee.handleKeyDown(e,1),children:[(0,Z.jsx)(`option`,{value:`anthropic`,children:_(`activity:provider.anthropic`)}),(0,Z.jsx)(`option`,{value:`openai`,children:_(`activity:provider.openai`)}),(0,Z.jsx)(`option`,{value:`openai-compatible`,children:_(`activity:provider.openaiCompatible`)}),(0,Z.jsx)(`option`,{value:`google`,children:_(`activity:provider.google`)})]}),(0,Z.jsx)(ts,{placeholder:_(`activity:provider.baseUrlOptionalEGHttpLocalhost11434V1`),value:M,onChange:e=>N(e.target.value),ref:ee.setFieldRef(2),onKeyDown:e=>ee.handleKeyDown(e,2)}),(0,Z.jsx)(ts,{type:`password`,placeholder:_(`settings:provider.apiKeyOptionalPlaceholder`),value:P,onChange:e=>F(e.target.value),ref:ee.setFieldRef(3),onKeyDown:e=>ee.handleKeyDown(e,3)}),(0,Z.jsx)(Bv,{models:I,onChange:L}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(Y,{size:`sm`,onClick:te,disabled:!O.trim(),ref:ee.setFieldRef(4),onKeyDown:e=>ee.handleKeyDown(e,4,te),children:_(`common:action.add`)}),(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>D(!1),ref:ee.setFieldRef(5),onKeyDown:e=>ee.handleKeyDown(e,5),children:_(`common:action.cancel`)})]})]}),i?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Z.jsx)(mn,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):r.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(cn,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,Z.jsx)(`p`,{children:_(`settings:provider.noSaved`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:_(`settings:provider.noSavedHint`)})]}):r.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border/80 bg-card/70 p-4 shadow-sm shadow-black/[0.02]`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h4`,{className:`min-w-0 break-words font-mono text-sm font-semibold text-foreground`,children:e.id}),e.family&&(0,Z.jsx)(`span`,{className:`rounded-full border border-border/70 bg-muted/40 px-2 py-0.5 text-[11px] font-medium text-muted-foreground`,children:e.family}),e.apiKeys.some(e=>e.isActive)&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-success/10 px-2 py-0.5 text-[11px] font-medium text-success`,children:[(0,Z.jsx)(Oa,{className:`h-3 w-3`}),_(`settings:provider.active`)]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-xs text-muted-foreground`,children:[e.baseUrl&&(0,Z.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1 rounded-md border border-border/70 bg-background/60 px-2 py-1`,children:[(0,Z.jsx)(Yi,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.baseUrl})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-background/60 px-2 py-1`,children:[(0,Z.jsx)(On,{className:`h-3.5 w-3.5`}),_(`settings:provider.modelCount`,{count:e.models?.length??0})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-background/60 px-2 py-1`,children:[(0,Z.jsx)(cn,{className:`h-3.5 w-3.5`}),_(`settings:provider.keyCount`,{count:e.apiKeys.length})]})]})]}),(0,Z.jsx)(`div`,{className:`flex gap-2 sm:justify-end`,children:(0,Z.jsx)(Y,{size:`icon`,variant:`ghost`,onClick:()=>f(e.id),"aria-label":`Remove provider ${e.id}`,title:`Remove provider ${e.id}`,className:`h-8 w-8 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,Z.jsx)(jn,{className:`h-4 w-4 text-destructive`})})})]}),(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(280px,0.85fr)]`,children:[(0,Z.jsx)(jy,{providerId:e.id,savedPickedModelId:e.pickedModelId,savedModels:e.models,savedCustomModels:e.customModels,ws:m,onPickModel:p}),(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/75 p-3 shadow-sm shadow-black/[0.02]`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-semibold`,children:_(`settings:provider.apiKeysLabel`)}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:_(`settings:provider.keyCount`,{count:e.apiKeys.length})})]}),(0,Z.jsxs)(Y,{size:`sm`,variant:`ghost`,onClick:()=>y(v===e.id?null:e.id),className:`h-8 px-2 text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),_(`settings:provider.addKey`)]})]}),e.apiKeys.length===0&&!v&&(0,Z.jsx)(`p`,{className:`mt-3 rounded-md border border-dashed border-border/70 bg-muted/20 px-3 py-2 text-xs text-muted-foreground`,children:_(`settings:provider.noKeys`)}),e.apiKeys.length>0&&(0,Z.jsx)(`div`,{className:`mt-3 space-y-2`,children:e.apiKeys.map(t=>(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-border/70 bg-muted/20 p-2.5 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,Z.jsx)(`span`,{className:`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-border/70 bg-background text-muted-foreground`,children:(0,Z.jsx)(cn,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.label}),t.isActive&&(0,Z.jsx)(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[11px] font-medium text-success`,children:_(`settings:provider.active`)})]}),(0,Z.jsx)(`div`,{className:`mt-0.5`,children:(0,Z.jsx)(Vv,{maskedKey:t.maskedKey})})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-1`,children:[!t.isActive&&(0,Z.jsx)(Y,{size:`sm`,variant:`outline`,onClick:()=>u(e.id,t.label),className:`h-8 px-2 text-xs`,children:_(`settings:provider.setActive`)}),(0,Z.jsx)(Y,{size:`icon`,variant:`ghost`,onClick:()=>l(e.id,t.label),"aria-label":`Delete key ${t.label}`,title:`Delete key ${t.label}`,className:`h-8 w-8 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,Z.jsx)(jn,{className:`h-3.5 w-3.5 text-destructive`})})]})]},t.label))}),v===e.id&&(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2 rounded-lg border border-border/70 bg-background p-3`,children:[(0,Z.jsx)(ts,{placeholder:_(`settings:provider.keyLabelPlaceholder`),value:b,onChange:e=>x(e.target.value),ref:R.setFieldRef(0),onKeyDown:e=>R.handleKeyDown(e,0)}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(ts,{type:w?`text`:`password`,placeholder:_(`settings:provider.apiKeyPlaceholder`),value:S,onChange:e=>C(e.target.value),ref:R.setFieldRef(1),onKeyDown:e=>R.handleKeyDown(e,1)}),(0,Z.jsx)(Y,{size:`icon`,variant:`ghost`,onClick:()=>T(!w),children:w?(0,Z.jsx)(ht,{className:`h-4 w-4`}):(0,Z.jsx)(ja,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(Y,{size:`sm`,onClick:()=>z(e.id),disabled:!b.trim()||!S.trim(),ref:R.setFieldRef(2),onKeyDown:t=>R.handleKeyDown(t,2,()=>z(e.id)),children:_(`settings:provider.saveKey`)}),(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>{y(null),x(``),C(``)},ref:R.setFieldRef(3),onKeyDown:e=>R.handleKeyDown(e,3),children:_(`common:action.cancel`)})]})]})]})]})]},e.id))]})]})}var Fy=Object.entries({discovery:[[`explore`,`Explore`],[`search`,`Search`],[`research`,`Research`]],planning:[[`analyst`,`Analyst`],[`planner`,`Planner`],[`architect`,`Architect`],[`critic`,`Critic`],[`refactor-planner`,`Refactor Planner`]],build:[[`executor`,`Executor`],[`refactor`,`Refactor`],[`simplifier`,`Simplifier`],[`migration`,`Migration`],[`vision`,`Vision`],[`debugger`,`Debugger`],[`tracer`,`Tracer`],[`concurrency`,`Concurrency`]],verify:[[`realtime`,`Realtime`],[`resilience-engineer`,`Resilience Engineer`],[`chaos-engineer`,`Chaos Engineer`],[`verifier`,`Verifier`],[`test`,`Test`],[`e2e`,`E2E`],[`browser`,`Browser`],[`performance`,`Performance`],[`chaos`,`Chaos`],[`security-scanner`,`Security Scanner`],[`bug-hunter`,`Bug Hunter`],[`audit-log`,`Audit Log`]],review:[[`threat-modeler`,`Threat Modeler`],[`secure-coding-coach`,`Secure Coding Coach`],[`compliance-auditor`,`Compliance Auditor`],[`privacy-engineer`,`Privacy Engineer`],[`reviewer`,`Reviewer`],[`code-reviewer`,`Code Reviewer`],[`security-reviewer`,`Security Reviewer`],[`accessibility`,`Accessibility`],[`compliance`,`Compliance`]],domain:[[`android`,`Android`],[`desktop`,`Desktop`],[`distributed-systems`,`Distributed Systems`],[`database`,`Database`],[`api`,`API`],[`auth`,`Auth`],[`data`,`Data`],[`frontend`,`Frontend`],[`backend`,`Backend`],[`designer`,`Designer`],[`ios`,`iOS`],[`payments`,`Payments`],[`messaging`,`Messaging`],[`search-relevance`,`Search Relevance`],[`storage`,`Storage`],[`ml-engineer`,`ML Engineer`],[`data-governance`,`Data Governance`]],knowledge:[[`document`,`Document`],[`uml`,`UML`],[`i18n`,`I18n`],[`prompt`,`Prompt`]],delivery:[[`platform-engineer`,`Platform Engineer`],[`git`,`Git`],[`release`,`Release`],[`devops`,`DevOps`],[`observability`,`Observability`],[`dependency`,`Dependency`]],meta:[[`skill-manage`,`Skill Manager`],[`self-improving`,`Self-Improving`],[`context`,`Context`],[`cost`,`Cost`],[`tech-stack`,`Tech Stack Validator`],[`plugin-author`,`Plugin Author`],[`tool-author`,`Tool Author`],[`prompt-evaluator`,`Prompt Evaluator`],[`benchmark-engineer`,`Benchmark Engineer`],[`memory-curator`,`Memory Curator`],[`fleet-coordinator`,`Fleet Coordinator`]]}).map(([e,t])=>({phase:e,label:`${e.charAt(0).toUpperCase()}${e.slice(1)}`,roles:t.map(([e,t])=>({role:e,name:t}))})),Iy=Fy.map(e=>e.phase),Ly=Fy.flatMap(e=>[...e.roles]),Ry=Ly.map(e=>e.role),zy=[`*`,...Iy,...Ry];function By(e){if(e===`*`)return`Default (*)`;let t=Fy.find(t=>t.phase===e);if(t)return`Phase: ${t.label} (${t.phase})`;let n=Ly.find(t=>t.role===e);return n?`${n.name} (${n.role})`:`Custom: ${e}`}var Vy=[{value:``,label:`mode: inherit`},{value:`auto`,label:`mode: auto`},{value:`on`,label:`mode: on`},{value:`off`,label:`mode: off`}],Hy=[{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`}],Uy=[{value:``,label:`preserve: inherit`},{value:`on`,label:`preserve: on`},{value:`off`,label:`preserve: off`}],Wy=new Set(zy);function Gy(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 Ky(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 qy({syncPref:e,candidates:t}){let n=G(),{t:r}=W(),[i,a]=(0,X.useState)(`*`),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(``),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(``),m=(0,X.useCallback)(t=>e(`modelMatrix`,t),[e]),h=(0,X.useCallback)(()=>{let e=i.trim(),t=o.trim(),r=Gy(c,u,f);if(!e||!t&&!r)return;let a=t?n.fallbackProfiles[t]?{fallbackProfile:t}:t.includes(`/`)?{provider:t.slice(0,t.indexOf(`/`)),model:t.slice(t.indexOf(`/`)+1)}:{model:t}:{},h=n.modelMatrix[e]?.modelRuntime;r?a.modelRuntime=r:h&&(a.modelRuntime=h),m({...n.modelMatrix,[e]:a}),s(``),l(``),d(``),p(``)},[n.fallbackProfiles,n.modelMatrix,i,f,u,c,o,m]),g=(0,X.useCallback)(e=>{let{[e]:t,...r}=n.modelMatrix;m(r)},[n.modelMatrix,m]),_=(0,X.useCallback)((e,t,r)=>{let i={...n.modelMatrix},a={...i[e]??{}},o={...a.modelRuntime??{}},s={...o.reasoning??{}};t===`mode`?r?s.mode=r:delete s.mode:t===`effort`?r?s.effort=r:delete s.effort:r?s.preserve=r===`on`:delete s.preserve,Object.keys(s).length>0?o.reasoning=s:delete o.reasoning,Object.keys(o).length>0?a.modelRuntime=o:delete a.modelRuntime,a.model||a.fallbackProfile||a.modelRuntime?i[e]=a:delete i[e],m(i)},[n.modelMatrix,m]),v=e=>{let t=e.provider&&e.model?`${e.provider}/${e.model}`:e.model,n=e.modelRuntime?.reasoning;return[t??(!e.fallbackProfile&&n?r(`settings:agent.leaderModel`):``),e.fallbackProfile?`profile:${e.fallbackProfile}`:``,...Ky(n)].filter(Boolean).join(` + `)},y=Array.from(new Set([...Object.keys(n.modelMatrix),i].filter(e=>e&&!Wy.has(e)))).sort((e,t)=>e.localeCompare(t));return(0,Z.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Z.jsx)(tr,{className:`h-4 w-4 text-muted-foreground`}),r(`settings:agent.routingHeading`)]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[minmax(0,180px)_1fr_auto]`,children:[(0,Z.jsxs)(`select`,{"aria-label":r(`settings:agent.routingRouteKey`),value:i,onChange:e=>a(e.target.value),className:`h-9 min-w-0 rounded-md border bg-background px-3 font-mono text-sm`,children:[(0,Z.jsx)(`option`,{value:`*`,children:By(`*`)}),(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingPhasesGroup`),children:Fy.map(e=>(0,Z.jsx)(`option`,{value:e.phase,children:By(e.phase)},e.phase))}),Fy.map(e=>(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingRolesGroup`,{label:e.label}),children:e.roles.map(e=>(0,Z.jsx)(`option`,{value:e.role,children:By(e.role)},e.role))},e.phase)),y.length>0?(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingCustomGroup`),children:y.map(e=>(0,Z.jsx)(`option`,{value:e,children:By(e)},e))}):null]}),(0,Z.jsxs)(`select`,{"aria-label":r(`settings:agent.routingTargetAria`),value:o,onChange:e=>s(e.target.value),className:`h-9 min-w-0 rounded-md border bg-background px-3 font-mono text-sm`,children:[(0,Z.jsx)(`option`,{value:``,children:r(`settings:agent.routingTargetEmpty`)}),Object.keys(n.fallbackProfiles).length>0&&(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingTargetProfilesGroup`),children:Object.keys(n.fallbackProfiles).map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),t&&t.length>0&&(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingTargetModelsGroup`),children:t.map(e=>(0,Z.jsxs)(`option`,{value:`${e.provider}/${e.model}`,children:[e.provider,`/`,e.model]},`${e.provider}/${e.model}`))})]}),(0,Z.jsx)(Y,{type:`button`,variant:`outline`,onClick:h,children:r(`settings:agent.routingSet`)})]}),(0,Z.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningModeAria`),value:c,onChange:e=>l(e.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Vy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningEffortAria`),value:u,onChange:e=>d(e.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Hy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningPreserveAria`),value:f,onChange:e=>p(e.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Uy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))})]}),(0,Z.jsx)(`div`,{className:`mt-3 space-y-1.5`,children:Object.keys(n.modelMatrix).length===0?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`settings:agent.noRoutes`)}):Object.entries(n.modelMatrix).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`rounded-md border border-border bg-muted px-2 py-1.5 text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`w-40 shrink-0 break-words font-mono text-muted-foreground`,title:e,children:By(e)}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 break-words font-mono`,children:v(t)}),(0,Z.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>g(e),children:r(`common:action.remove`)})]}),(0,Z.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningModeFor`,{key:e}),value:t.modelRuntime?.reasoning?.mode??``,onChange:t=>_(e,`mode`,t.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Vy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningEffortFor`,{key:e}),value:t.modelRuntime?.reasoning?.effort??``,onChange:t=>_(e,`effort`,t.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Hy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningPreserveFor`,{key:e}),value:t.modelRuntime?.reasoning?.preserve===void 0?``:t.modelRuntime.reasoning.preserve?`on`:`off`,onChange:t=>_(e,`preserve`,t.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Uy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))})]})]},e))})]})}var Jy=[`off`,`low`,`medium`,`high`,`all`],Yy={off:`bg-muted-foreground`,low:`bg-success`,medium:`bg-warning`,high:`bg-warning ring-2 ring-warning/25`,all:`bg-destructive`},Xy={off:`settings:brain.riskCopy.off`,low:`settings:brain.riskCopy.low`,medium:`settings:brain.riskCopy.medium`,high:`settings:brain.riskCopy.high`,all:`settings:brain.riskCopy.all`},Zy=[`executor`,`skeptic`,`auditor`];function Qy(e){return e&&e.length>0?e.map(e=>({id:e.id,name:e.name,description:e.description})):Zy.map(e=>({id:e,name:e}))}var $y=[{value:`default`,labelKey:`settings:brainOpt.default15s`},{value:`5000`,label:`5s`},{value:`10000`,label:`10s`},{value:`20000`,label:`20s`},{value:`30000`,label:`30s`},{value:`60000`,label:`60s`}],eb=[{value:`off`,labelKey:`settings:brainOpt.waitForever`},{value:`30000`,label:`30s`},{value:`60000`,label:`1m`},{value:`120000`,label:`2m`},{value:`300000`,label:`5m`}],tb=[{value:`default`,labelKey:`settings:brainOpt.defaultHalf`},{value:`0.34`,label:`1/3`},{value:`0.5`,label:`1/2`},{value:`0.67`,label:`2/3`},{value:`0.75`,label:`3/4`},{value:`1`,labelKey:`settings:brainOpt.all`}],nb=[{value:`100`,label:`100`},{value:`200`,labelKey:`settings:brainOpt.n200Default`},{value:`400`,label:`400`},{value:`800`,label:`800`},{value:`1600`,label:`1600`}],rb=[{value:`0`,labelKey:`settings:brainOpt.offDefault`},{value:`0.3`,label:`0.3`},{value:`0.5`,label:`0.5`},{value:`0.7`,label:`0.7`},{value:`0.9`,label:`0.9`}],ib=[{value:`10`,label:`10`},{value:`20`,labelKey:`settings:brainOpt.n20Default`},{value:`50`,label:`50`},{value:`100`,label:`100`}],ab=[{value:`60000`,label:`1m`},{value:`300000`,labelKey:`settings:brainOpt.m5Default`},{value:`900000`,label:`15m`},{value:`3600000`,label:`1h`}],ob=[{value:`50`,label:`50`},{value:`200`,labelKey:`settings:brainOpt.n200Default`},{value:`500`,label:`500`},{value:`1000`,label:`1000`}],sb=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`10000`,label:`10s`},{value:`20000`,label:`20s`},{value:`30000`,label:`30s`},{value:`60000`,label:`60s`}],cb=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`1`,labelKey:`settings:brainOpt.oneSerial`},{value:`2`,label:`2`},{value:`3`,label:`3`},{value:`5`,label:`5`}],lb=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`500`,label:`500`},{value:`1000`,label:`1000`},{value:`2000`,label:`2000`},{value:`4000`,label:`4000`},{value:`8000`,label:`8000`}],ub=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`1`,labelKey:`settings:brainOpt.roundsOff`},{value:`2`,label:`2`},{value:`3`,label:`3`}],db=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`200`,label:`200`},{value:`400`,label:`400`},{value:`800`,label:`800`},{value:`1600`,label:`1600`}],fb=[{value:`default`,labelKey:`settings:brainOpt.default500`},{value:`100`,label:`100`},{value:`500`,label:`500`},{value:`1000`,label:`1000`},{value:`5000`,label:`5000`}],pb=[{value:`default`,labelKey:`settings:brainOpt.default10m`},{value:`120000`,label:`2m`},{value:`600000`,label:`10m`},{value:`1800000`,label:`30m`},{value:`3600000`,label:`1h`}];function mb(e,t){return e.some(e=>e.value===t)?e:[...e,{value:t,label:t}]}function hb(e,t){return e.map(e=>({value:e.value,label:e.labelKey?t(e.labelKey):e.label??e.value}))}function gb(e){return e===void 0?`default`:String(e)}function _b({level:e}){return(0,Z.jsx)(`span`,{className:K(`inline-block h-2.5 w-2.5 rounded-full`,Yy[e])})}function vb(e){return e.provider?`${e.provider}/${e.model}`:e.model}var yb={pool:{title:`settings:brain.pickPoolTitle`,hint:`settings:brain.pickPoolHint`},voter:{title:`settings:brain.pickVoterTitle`,hint:`settings:brain.pickVoterHint`},judge:{title:`settings:brain.pickJudgeTitle`,hint:`settings:brain.pickJudgeHint`}};function bb(){let{t:e}=W(),{client:t}=hf(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)([]),[o,s]=(0,X.useState)(!0),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(null),m=Pe();(0,X.useEffect)(()=>{t.send({type:`brain.status`,payload:t.withSession({})}),t.send({type:`brain.config.get`})},[t,m]),(0,X.useEffect)(()=>{let n=t.on(`brain.status`,e=>{let t=e.payload;if(t.sessionId&&m&&t.sessionId!==m)return;let n=Date.now();a(t.log.slice(-10).map(e=>{let t=Math.max(0,Math.round((n-e.at)/1e3)),r=t<60?`${t}s`:t<3600?`${Math.round(t/60)}m`:`${Math.round(t/3600)}h`;return{kind:e.kind,question:e.question,outcome:e.outcome,age:r}})),s(!1)}),i=t.on(`brain.config`,t=>{let n=t.payload;r(n.config),d(n.persisted?null:n.error??e(`settings:brain.persistError`)),l(!1),s(!1)});return()=>{n(),i()}},[t,e,m]);let h=(0,X.useCallback)(e=>{l(!0),t.send({type:`brain.config.set`,payload:t.withSession({patch:e})})},[t]),g=(0,X.useCallback)(e=>{r(t=>t&&{...t,maxAutoRisk:e}),h({maxAutoRisk:e})},[h]),_=(0,X.useMemo)(()=>n?.council.voters??[],[n]),v=(0,X.useCallback)(e=>{h({council:{voters:e.length>0?e:null}})},[h]),y=(0,X.useMemo)(()=>Qy(n?.personaCatalog),[n?.personaCatalog]),b=Jy.includes(n?.maxAutoRisk??``)?n?.maxAutoRisk??`medium`:`medium`,x=(0,X.useCallback)(e=>{if(!n||!f)return;let t=`${e.provider}/${e.model}`;if(f===`pool`){h({models:[...n.models.map(vb),t]});return}if(f===`judge`){h({council:{judge:t}});return}return v([..._,{provider:e.provider,model:e.model,persona:y[_.length%y.length]?.id??`executor`}]),!0},[n,y,f,h,v,_]);return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(g_,{open:f!==null,mode:`provider-model`,title:f?e(yb[f].title):``,hint:f?e(yb[f].hint):void 0,onPick:e=>{if(e.type===`provider-model`)return x(e)},onClose:()=>p(null)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Jn,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`h3`,{className:`text-base font-semibold`,children:e(`settings:brain.heading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.headingHint`)})]}),(o||c)&&(0,Z.jsx)(mn,{className:`ml-auto h-4 w-4 animate-spin text-muted-foreground`})]}),u&&(0,Z.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:u}),(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.riskHeading`)}),(0,Z.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:Jy.map(e=>(0,Z.jsxs)(Y,{variant:b===e?`default`:`outline`,size:`sm`,className:K(`gap-1.5 text-xs`,b===e&&`shadow-sm`),disabled:c,onClick:()=>g(e),children:[(0,Z.jsx)(_b,{level:e}),e.toUpperCase()]},e))}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(Xy[b])})]}),n&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.escalationHeading`)}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationModeLabel`),hint:e(`settings:brain.escalationModeHint`),value:n.mode,options:[{value:`interactive`,label:e(`settings:brain.optInteractive`)},{value:`headless`,label:e(`settings:brain.optHeadless`)}],onChange:e=>h({mode:e}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationDecisionTimeoutLabel`),hint:e(`settings:brain.escalationDecisionTimeoutHint`),value:n.decisionTimeoutMs?String(n.decisionTimeoutMs):`default`,options:hb($y,e),onChange:e=>h({decisionTimeoutMs:e==="default"?null:Number(e)}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationHumanTimeoutLabel`),hint:e(`settings:brain.escalationHumanTimeoutHint`),value:n.humanTimeoutMs?String(n.humanTimeoutMs):`off`,options:hb(eb,e),onChange:e=>h({humanTimeoutMs:e===`off`?null:Number(e)}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationTerminalPolicyLabel`),hint:e(`settings:brain.escalationTerminalPolicyHint`),value:n.terminalPolicy,options:[{value:`conservative`,label:e(`settings:brain.optConservative`)},{value:`deny-all`,label:e(`settings:brain.optDenyAll`)},{value:`continue-on-recommended`,label:e(`settings:brain.optContinueRecommended`)}],onChange:e=>h({terminalPolicy:e}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationDecisionLogSizeLabel`),hint:e(`settings:brain.escalationDecisionLogSizeHint`),value:String(n.decisionLogMaxEntries),options:hb(mb(ib,String(n.decisionLogMaxEntries)),e),onChange:e=>h({decisionLogMaxEntries:Number(e)}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.rulesHeading`)}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px]`,children:e(`settings:brain.rulesConfigured`,{count:n.rules.length})})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.rulesBody`)}),n.rules.length>0&&(0,Z.jsx)(`div`,{className:`space-y-1`,children:n.rules.map((t,n)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/50 bg-background/40 px-2 py-1.5 text-xs`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground w-4 shrink-0`,children:[n+1,`.`]}),(0,Z.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:t.id}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px] shrink-0`,children:t.then.action}),t.enabled===!1&&(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px] shrink-0`,children:e(`settings:brain.rulesOff`)})]},`${t.id}-${n}`))}),n.ruleErrors.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-warning/40 bg-warning/10 px-2 py-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-warning`,children:e(`settings:brain.rulesDropped`,{count:n.ruleErrors.length})}),n.ruleErrors.map(e=>(0,Z.jsx)(`p`,{className:`text-xs text-warning`,children:e},e))]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.heuristicsHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.heuristicsBody`)}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsLowRiskLabel`),hint:e(`settings:brain.heuristicsLowRiskHint`),value:n.heuristics.lowRiskAutoAnswer,onChange:()=>h({heuristics:{lowRiskAutoAnswer:!n.heuristics.lowRiskAutoAnswer}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsBlockedLabel`),hint:e(`settings:brain.heuristicsBlockedHint`),value:n.heuristics.blockedResolved,onChange:()=>h({heuristics:{blockedResolved:!n.heuristics.blockedResolved}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsDeadlockLabel`),hint:e(`settings:brain.heuristicsDeadlockHint`),value:n.heuristics.deadlockSkip,onChange:()=>h({heuristics:{deadlockSkip:!n.heuristics.deadlockSkip}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsRetryLabel`),hint:e(`settings:brain.heuristicsRetryHint`),value:n.heuristics.retryExhausted,onChange:()=>h({heuristics:{retryExhausted:!n.heuristics.retryExhausted}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsPingLabel`),hint:e(`settings:brain.heuristicsPingHint`),value:n.heuristics.continuePing,onChange:()=>h({heuristics:{continuePing:!n.heuristics.continuePing}}),disabled:c}),n.heuristics.blockedResolvedMarkers&&n.heuristics.blockedResolvedMarkers.length>0&&(0,Z.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:e(`settings:brain.heuristicsMarkers`,{markers:n.heuristics.blockedResolvedMarkers.join(`, `)})})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.qualityHeading`)}),n.circuit&&(0,Z.jsx)(j_,{variant:n.circuit.state===`closed`?`outline`:`default`,className:`text-[10px]`,children:e(`settings:brain.qualityCircuit`,{state:n.circuit.state,count:n.circuit.consecutiveFailures})})]}),(0,Z.jsx)(Q,{label:e(`settings:brain.qualityResponseBudgetLabel`),hint:e(`settings:brain.qualityResponseBudgetHint`),value:String(n.llm.maxTokens),options:hb(mb(nb,String(n.llm.maxTokens)),e),onChange:e=>h({llm:{maxTokens:Number(e)}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.qualityRejectLabel`),hint:e(`settings:brain.qualityRejectHint`),value:n.llm.rejectUncertain,onChange:()=>h({llm:{rejectUncertain:!n.llm.rejectUncertain}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.qualityMinConfidenceLabel`),hint:e(`settings:brain.qualityMinConfidenceHint`),value:String(n.llm.minConfidence),options:hb(mb(rb,String(n.llm.minConfidence)),e),onChange:e=>h({llm:{minConfidence:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.qualityDenyTerminalLabel`),hint:e(`settings:brain.qualityDenyTerminalHint`),value:n.llm.denyIsTerminal,options:[{value:`never`,label:e(`settings:brain.optNeverDefault`)},{value:`when-decided`,label:e(`settings:brain.optWhenDecided`)},{value:`always`,label:e(`settings:brain.optAlways`)}],onChange:e=>h({llm:{denyIsTerminal:e}}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.traceHeading`)}),(0,Z.jsx)($,{label:e(`settings:brain.traceRecordLabel`),hint:e(`settings:brain.traceRecordHint`),value:n.trace.enabled,onChange:()=>h({trace:{enabled:!n.trace.enabled}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.traceContentLabel`),hint:e(`settings:brain.traceContentHint`),value:n.trace.content,options:[{value:`full`,label:e(`settings:brain.optFullDefault`)},{value:`redacted`,label:e(`settings:brain.optRedacted`)},{value:`none`,label:e(`settings:brain.optMetadataOnly`)}],onChange:e=>h({trace:{content:e}}),disabled:c}),n.trace.path&&(0,Z.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:n.trace.path})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.cacheHeading`)}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px]`,children:e(`settings:brain.cacheStats`,{hits:n.cache.hits,misses:n.cache.misses,size:n.cache.size})})]}),(0,Z.jsx)($,{label:e(`settings:brain.cacheReplayLabel`),hint:e(`settings:brain.cacheReplayHint`),value:n.cache.enabled,onChange:()=>h({cache:{enabled:!n.cache.enabled}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.cacheLifetimeLabel`),hint:e(`settings:brain.cacheLifetimeHint`),value:String(n.cache.ttlMs),options:hb(mb(ab,String(n.cache.ttlMs)),e),onChange:e=>h({cache:{ttlMs:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.cacheMaxEntriesLabel`),hint:e(`settings:brain.cacheMaxEntriesHint`),value:String(n.cache.maxEntries),options:hb(mb(ob,String(n.cache.maxEntries)),e),onChange:e=>h({cache:{maxEntries:Number(e)}}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.monitorHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.monitorBody`)}),(0,Z.jsx)($,{label:e(`settings:brain.monitorWatchLabel`),hint:e(`settings:brain.monitorWatchHint`),value:n.monitor.enabled!==!1,onChange:()=>h({monitor:{enabled:n.monitor.enabled===!1}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.monitorPolicyLabel`),hint:e(`settings:brain.monitorPolicyHint`),value:n.monitor.policy??`llm`,options:[{value:`llm`,label:e(`settings:brain.optConsultBrain`)},{value:`steer`,label:e(`settings:brain.optAlwaysSteer`)},{value:`observe`,label:e(`settings:brain.optObserveOnly`)}],onChange:e=>h({monitor:{policy:e}}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.modelsHeading`)}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px]`,children:n.usingSessionModel?e(`settings:brain.modelsSessionBadge`):e(`settings:brain.modelsResolvedBadge`,{resolved:n.poolLabels.length,total:n.models.length})})]}),(0,Z.jsx)($,{label:e(`settings:brain.modelsUseSessionLabel`),hint:e(`settings:brain.modelsUseSessionHint`),value:n.usingSessionModel,onChange:()=>{n.usingSessionModel||h({models:null})},disabled:c}),n.models.length>0&&(0,Z.jsx)(`div`,{className:`space-y-1`,children:n.models.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/50 bg-background/40 px-2 py-1.5 text-xs`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground w-4 shrink-0`,children:[t+1,`.`]}),(0,Z.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:vb(e)}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,disabled:c||t===0,onClick:()=>{let e=n.models.map(vb),r=e.splice(t,1)[0];r&&e.splice(t-1,0,r),h({models:e})},children:(0,Z.jsx)(sa,{className:`h-3 w-3`})}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,disabled:c||t===n.models.length-1,onClick:()=>{let e=n.models.map(vb),r=e.splice(t,1)[0];r&&e.splice(t+1,0,r),h({models:e})},children:(0,Z.jsx)(Nr,{className:`h-3 w-3`})}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-destructive`,disabled:c,onClick:()=>{let e=n.models.map(vb).filter((e,n)=>n!==t);h({models:e.length>0?e:null})},children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]},`${vb(e)}-${t}`))}),(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,className:`gap-1.5 text-xs`,disabled:c,onClick:()=>p(`pool`),children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),` `,e(`settings:brain.modelsAddModel`)]}),n.models.length>1&&(0,Z.jsx)(Q,{label:e(`settings:brain.modelsPoolStrategyLabel`),hint:e(`settings:brain.modelsPoolStrategyHint`),value:n.strategy,options:[{value:`fallback`,label:e(`settings:brain.optFallback`)},{value:`round-robin`,label:e(`settings:brain.optRoundRobin`)}],onChange:e=>h({strategy:e}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.councilHeading`)}),(0,Z.jsx)(j_,{variant:n.council.enabled?`default`:`outline`,className:`text-[10px]`,children:n.council.enabled?e(`settings:brain.councilConvened`):e(`settings:brain.councilDisabled`)})]}),(0,Z.jsx)($,{label:e(`settings:brain.councilEnableLabel`),hint:e(`settings:brain.councilEnableHint`),value:n.council.enabled,onChange:()=>h({council:{enabled:!n.council.enabled}}),disabled:c}),n.council.enabled&&n.councilLabels.length>0&&_.length===0&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.councilSeatsDerived`,{seats:n.councilLabels.join(`, `)})}),_.length>0&&(0,Z.jsx)(`div`,{className:`space-y-1`,children:_.map((t,n)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/50 bg-background/40 px-2 py-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:vb(t)}),(0,Z.jsxs)(`select`,{value:t.persona??y[n%y.length]?.id??``,onChange:e=>v(_.map((t,r)=>r===n?{...t,persona:e.target.value}:t)),className:`h-6 rounded border bg-background px-1 text-[10px]`,title:y.find(e=>e.id===t.persona)?.description??e(`settings:brain.councilCustomLens`),children:[y.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id)),t.persona&&!y.some(e=>e.id===t.persona)&&(0,Z.jsx)(`option`,{value:t.persona,children:e(`settings:brain.councilCustomOption`,{persona:t.persona})})]}),(0,Z.jsx)(Y,{variant:t.veto?`default`:`outline`,size:`sm`,className:`h-6 px-1.5 text-[10px]`,disabled:c,onClick:()=>v(_.map((e,t)=>t===n?{...e,veto:!e.veto}:e)),children:e(`settings:brain.councilVeto`)}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-destructive`,disabled:c,onClick:()=>v(_.filter((e,t)=>t!==n)),children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]},`${vb(t)}-${n}`))}),(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,className:`gap-1.5 text-xs`,disabled:c,onClick:()=>p(`voter`),children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),` `,e(`settings:brain.councilAddVoter`)]}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilRiskFloorLabel`),hint:e(`settings:brain.councilRiskFloorHint`),value:n.council.minRisk,options:[{value:`medium`,label:e(`settings:brain.optMediumPlus`)},{value:`high`,label:e(`settings:brain.optHighPlus`)},{value:`critical`,label:e(`settings:brain.optCriticalOnly`)}],onChange:e=>h({council:{minRisk:e}}),disabled:c}),(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium`,children:e(`settings:brain.councilJudge`)}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e(`settings:brain.councilJudgeDesc`)}),!n.council.judge&&n.judgeLabel&&(0,Z.jsxs)(`div`,{className:`mt-0.5 font-mono text-xs text-muted-foreground`,children:[e(`settings:brain.councilResolved`,{model:n.judgeLabel}),n.judgeIsVoter&&(0,Z.jsx)(`span`,{className:`ml-1 font-sans text-warning`,children:e(`settings:brain.councilAlsoVoter`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`max-w-[180px] truncate font-mono text-xs`,children:n.council.judge?vb(n.council.judge):e(`settings:brain.councilAuto`)}),(0,Z.jsx)(Y,{variant:`outline`,size:`sm`,className:`h-7 text-xs`,disabled:c,onClick:()=>p(`judge`),children:e(`settings:brain.councilPick`)}),n.council.judge&&(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-7 text-xs`,disabled:c,onClick:()=>h({council:{judge:null}}),children:e(`settings:brain.councilAutoReset`)})]})]}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilQuorumLabel`),hint:e(`settings:brain.councilQuorumHint`),value:n.council.quorum===void 0?`default`:String(n.council.quorum),options:hb(tb,e),onChange:e=>h({council:{quorum:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilApprovalLabel`),hint:e(`settings:brain.councilApprovalHint`),value:n.council.approval===void 0?`default`:String(n.council.approval),options:hb(tb,e),onChange:e=>h({council:{approval:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilPerSeatTimeoutLabel`),hint:e(`settings:brain.councilPerSeatTimeoutHint`),value:gb(n.council.perCallTimeoutMs),options:hb(mb(sb,gb(n.council.perCallTimeoutMs)),e),onChange:e=>h({council:{perCallTimeoutMs:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilMaxConcurrencyLabel`),hint:e(`settings:brain.councilMaxConcurrencyHint`),value:gb(n.council.maxConcurrency),options:hb(mb(cb,gb(n.council.maxConcurrency)),e),onChange:e=>h({council:{maxConcurrency:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilDistinctnessLabel`),hint:e(`settings:brain.councilDistinctnessHint`),value:n.council.distinctness,options:[{value:`none`,label:e(`settings:brain.optNoneDefault`)},{value:`model`,label:e(`settings:brain.optDistinctModels`)},{value:`provider`,label:e(`settings:brain.optDistinctProviders`)}],onChange:e=>h({council:{distinctness:e}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilVoterBudgetLabel`),hint:e(`settings:brain.councilVoterBudgetHint`),value:gb(n.council.voterMaxTokens),options:hb(mb(lb,gb(n.council.voterMaxTokens)),e),onChange:e=>h({council:{voterMaxTokens:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilRoundsLabel`),hint:e(`settings:brain.councilRoundsHint`),value:gb(n.council.deliberationRounds),options:hb(mb(ub,gb(n.council.deliberationRounds)),e),onChange:e=>h({council:{deliberationRounds:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilJudgeBudgetLabel`),hint:e(`settings:brain.councilJudgeBudgetHint`),value:gb(n.council.judgeMaxTokens),options:hb(mb(db,gb(n.council.judgeMaxTokens)),e),onChange:e=>h({council:{judgeMaxTokens:e==="default"?null:Number(e)}}),disabled:c}),n.council.seats.length>0&&(0,Z.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[e(`settings:brain.councilSeatTemplate`),` `,n.council.seats.map(t=>t.veto?`${t.persona} (${e(`settings:brain.councilVeto`)})`:t.persona).join(`, `)]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.ledgerHeading`)}),(0,Z.jsx)($,{label:e(`settings:brain.ledgerRecordLabel`),hint:e(`settings:brain.ledgerRecordHint`),value:n.ledger.enabled,onChange:()=>h({ledger:{enabled:!n.ledger.enabled}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.ledgerAutoDenyLabel`),hint:e(`settings:brain.ledgerAutoDenyHint`),value:n.ledger.autoDenyAfterFailures===void 0?`default`:String(n.ledger.autoDenyAfterFailures),options:[{value:`default`,label:e(`settings:brain.optDefault3`)},{value:`0`,label:e(`settings:brain.optOff`)},{value:`2`,label:`2`},{value:`3`,label:`3`},{value:`5`,label:`5`}],onChange:e=>h({ledger:{autoDenyAfterFailures:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.ledgerMemoryEntriesLabel`),hint:e(`settings:brain.ledgerMemoryEntriesHint`),value:gb(n.ledger.maxMemoryEntries),options:hb(mb(fb,gb(n.ledger.maxMemoryEntries)),e),onChange:e=>h({ledger:{maxMemoryEntries:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.ledgerRetryWindowLabel`),hint:e(`settings:brain.ledgerRetryWindowHint`),value:gb(n.ledger.interventionRetryWindowMs),options:hb(mb(pb,gb(n.ledger.interventionRetryWindowMs)),e),onChange:e=>h({ledger:{interventionRetryWindowMs:e==="default"?null:Number(e)}}),disabled:c}),n.ledger.path&&(0,Z.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:n.ledger.path})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-card/70 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.recentHeading`,{count:i.length})}),(0,Z.jsx)(`div`,{className:`space-y-1 max-h-[300px] overflow-y-auto`,children:i.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground py-2`,children:e(`settings:brain.recentEmpty`)}):i.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-border/50 bg-background/40 px-2 py-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 w-8`,children:e.age}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px] shrink-0`,children:e.kind}),(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:e.question}),e.outcome&&(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 italic`,children:e.outcome})]},`${e.age}-${e.kind}-${e.question.slice(0,32)}`))})]})]})}function xb(){let{t:e}=W();return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ja,{className:`h-5 w-5 text-info`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold`,children:e(`activity:shadow.shadowAgent`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`activity:shadow.theShadowAgentMonitorsAllFleet`)}),(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Start and stop it from the chat with`,` `,(0,Z.jsx)(`code`,{className:`font-mono text-xs`,children:`/shadow start`}),` and`,` `,(0,Z.jsx)(`code`,{className:`font-mono text-xs`,children:`/shadow stop`}),`. This panel cannot control it yet.`]})]})}function Sb({disabled:e,direct:t}){let n=e?`bg-muted-foreground`:t?`bg-success`:`bg-info`,r=e?`disabled`:t?`direct provider tool`:`lazy catalog tool`;return(0,Z.jsx)(`span`,{className:`inline-block h-2 w-2 shrink-0 rounded-full ${n}`,title:r})}function Cb({tool:e,onToggle:t,busy:n}){let{t:r}=W(),[i,a]=(0,X.useState)(!1);return(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-card/70 p-3 transition-colors hover:bg-card`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 sm:flex-row sm:items-start`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-2`,children:[(0,Z.jsx)(Sb,{disabled:e.disabled,direct:e.direct}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`code`,{className:`block truncate text-sm font-mono font-semibold`,title:e.name,children:e.name}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-1.5`,children:[(0,Z.jsx)(j_,{variant:`outline`,className:`px-1.5 text-[10px]`,children:e.permission}),(0,Z.jsx)(j_,{variant:`outline`,className:`px-1.5 text-[10px]`,children:e.mutating?`mutating`:`read-only`}),(0,Z.jsx)(j_,{variant:`outline`,className:`px-1.5 text-[10px]`,children:e.disabled?`disabled`:e.direct?`direct`:`lazy`}),(0,Z.jsx)(`span`,{className:`truncate text-[11px] text-muted-foreground`,title:e.owner,children:e.owner})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-1`,children:[(0,Z.jsxs)(Y,{variant:e.disabled?`default`:`secondary`,size:`sm`,className:`h-7 gap-1 px-2 text-xs`,onClick:t,disabled:n,children:[n?(0,Z.jsx)(mn,{className:`h-3 w-3 animate-spin`}):e.disabled?(0,Z.jsx)(Bt,{className:`h-3 w-3`}):(0,Z.jsx)(sn,{className:`h-3 w-3`}),e.disabled?`Enable`:`Disable`]}),(0,Z.jsx)(`button`,{type:`button`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,onClick:()=>a(!i),"aria-label":i?`Collapse`:`Expand`,children:(0,Z.jsx)(gn,{className:`h-4 w-4 transition-transform ${i?`rotate-180`:``}`})})]})]}),i&&(0,Z.jsxs)(`div`,{className:`space-y-1 border-t border-border/60 pt-2 text-xs text-muted-foreground sm:ml-4`,children:[(0,Z.jsx)(`p`,{children:e.description}),e.params.length>0&&(0,Z.jsxs)(`p`,{children:[r(`activity:toolsSec.params`),` `,(0,Z.jsx)(`code`,{className:`break-all font-mono`,children:e.params.join(`, `)})]})]})]})}function wb(){let{t:e}=W(),{client:t}=hf(),[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(!0),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(new Set);(0,X.useEffect)(()=>{let e=t.on(`tools.list`,e=>{let t=e.payload;r(t.tools),a(!1)}),n=e=>{if(e.type===`tool.disabled`||e.type===`tool.enabled`){let n=e.payload;l(e=>{let t=new Set(e);return t.delete(n.name),t}),n.ok?t.send({type:`tools.list`},{echoToChat:!1}):B.error(`Tool "${n.name}" ${e.type===`tool.disabled`?`disable`:`enable`} failed.`)}},i=t.on(`tool.disabled`,n),o=t.on(`tool.enabled`,n);return()=>{e(),i(),o()}},[t]),(0,X.useEffect)(()=>{t.send({type:`tools.list`},{echoToChat:!1})},[t]);let u=(0,X.useCallback)((e,n)=>{l(t=>new Set(t).add(e)),t.send({type:n?`tool.enable`:`tool.disable`,payload:{name:e}})},[t]),d=o?n.filter(e=>e.name.toLowerCase().includes(o.toLowerCase())||e.owner.toLowerCase().includes(o.toLowerCase())):n,f=n.filter(e=>!e.disabled&&e.direct).length,p=n.filter(e=>!e.disabled&&!e.direct).length,m=n.filter(e=>e.disabled).length;return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(_n,{className:`h-5 w-5`})}),(0,Z.jsx)(`h3`,{className:`text-base font-semibold`,children:e(`activity:toolsSec.tools`)})]}),!i&&(0,Z.jsxs)(`span`,{className:`rounded-md border border-border/60 bg-muted/30 px-2 py-1 text-xs text-muted-foreground sm:ml-auto`,children:[f,` direct · `,p,` lazy · `,m,` disabled · `,n.length,` `,`total`]})]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(Tt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(ts,{placeholder:e(`activity:toolsSec.filterToolsByNameOrOwner`),value:o,onChange:e=>s(e.target.value),className:`pl-8 h-9 text-sm`})]}),i?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground gap-2`,children:[(0,Z.jsx)(mn,{className:`h-4 w-4 animate-spin`}),e(`activity:toolsSec.loadingTools`)]}):d.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground py-4 text-center`,children:o?`No tools matching "${o}".`:`No tools registered.`}):(0,Z.jsxs)(`div`,{className:`relative overflow-hidden rounded-lg border border-border/70 bg-background/35 shadow-inner`,children:[(0,Z.jsx)(`ul`,{className:`max-h-[min(58dvh,660px)] space-y-2 overflow-y-auto p-2 pr-3 [scrollbar-gutter:stable]`,"aria-label":e(`activity:toolsSec.toolsList`),children:d.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(Cb,{tool:e,onToggle:()=>u(e.name,e.disabled),busy:c.has(e.name)})},e.name))}),(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 top-0 h-4 bg-gradient-to-b from-background/90 to-transparent`}),(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-0 h-8 bg-gradient-to-t from-background/95 to-transparent`})]})]})}function Tb(){let{t:e}=W();return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 pb-3 border-b border-border/50`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(ja,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`settings:security.brainHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`settings:security.brainHint`)})]})]}),(0,Z.jsx)(bb,{})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 pb-3 border-b border-border/50`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(ja,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`settings:security.shadowHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`settings:security.shadowHint`)})]})]}),(0,Z.jsx)(xb,{})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 pb-3 border-b border-border/50`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(ja,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`settings:security.toolsHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`settings:security.toolsHint`)})]})]}),(0,Z.jsx)(wb,{})]})]})}function Eb({laneIndex:e,currentLane:t,sessionProvider:n,sessionModel:r,open:i,onOpenChange:a,onPick:o}){let{t:s}=W(),{listSavedProviders:c,listProviderModels:l}=hf(),u=V(e=>e.wsUrl),d=G(e=>e.favoriteModels),f=G(e=>e.disabledModels),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)(0),[x,C]=(0,X.useState)([]),[w,T]=(0,X.useState)({}),E=(0,X.useRef)(null);(0,X.useEffect)(()=>{i&&(m(``),g(null),v(!1),b(0),requestAnimationFrame(()=>E.current?.focus()))},[i]),(0,X.useEffect)(()=>{if(!i)return;let e=S(u),t=e.on(`providers.saved`,e=>{let t=e.payload;C(t.providers??[])}),n=e.on(`provider.models`,e=>{let t=e.payload;T(e=>({...e,[t.provider]:t.models??[]}))});return c(),()=>{t(),n()}},[i,u,c]),(0,X.useEffect)(()=>{if(i)for(let e of x)w[e.id]||l(e.id)},[i,x,w,l]);let D=(0,X.useMemo)(()=>[...new Set(x.map(e=>e.id))].sort((e,t)=>e.localeCompare(t)),[x]),O=(0,X.useMemo)(()=>Jm(x,w,p,t.provider??n,t.model??r,h,_,d??[],f??[]),[x,w,p,t.provider,t.model,n,r,h,_,d,f]);(0,X.useEffect)(()=>{y>=O.length&&b(0)},[O.length,y]);let k=e=>{let t=O[e];t&&(o({provider:t.provider,model:t.model}),a(!1))};return(0,Z.jsx)(es,{open:i,onOpenChange:e=>{e||a(!1)},children:(0,Z.jsxs)(Zo,{className:`max-w-xl gap-0 p-0 overflow-hidden pt-[10dvh]`,showCloseButton:!1,onOpenAutoFocus:e=>{e.preventDefault(),E.current?.focus()},children:[(0,Z.jsx)(Qo,{className:`sr-only`,children:s(`activity:modelSwitcher.lanePickerTitle`,{index:e+1})}),(0,Z.jsx)($o,{className:`sr-only`,children:s(`activity:modelSwitcher.lanePickerDescription`,{index:e+1})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Z.jsx)(Tt,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,Z.jsx)(`input`,{ref:E,value:p,onChange:e=>{m(e.target.value),b(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),b(e=>Math.min(O.length-1,e+1))):e.key===`ArrowUp`?(e.preventDefault(),b(e=>Math.max(0,e-1))):e.key===`Enter`&&(e.preventDefault(),k(y))},placeholder:`Search provider or model…`,"aria-label":`Search models for lane ${e+1}`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground min-w-0`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{v(e=>!e),b(0)},title:`Show favorites only`,"aria-label":`Show favorites only`,"aria-pressed":_,className:K(`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors border shrink-0`,_?`bg-warning/15 border-warning/40 text-warning font-medium`:`bg-transparent border-border/70 text-muted-foreground hover:text-foreground hover:bg-muted/50`),children:[(0,Z.jsx)(ta,{className:K(`h-3.5 w-3.5`,_?`fill-warning text-warning`:`text-muted-foreground`)}),(0,Z.jsx)(`span`,{className:`text-[11px] whitespace-nowrap`,children:`Favorites`})]}),D.length>1&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Z.jsx)(zi,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`select`,{value:h??``,onChange:e=>{g(e.target.value||null),b(0)},"aria-label":`Filter by provider`,className:`bg-transparent text-xs text-muted-foreground outline-none cursor-pointer border-0 min-w-0 truncate`,children:[(0,Z.jsx)(`option`,{value:``,children:`All providers`}),D.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})]}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono shrink-0`,children:`↑↓ · Enter · Esc`}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>a(!1),"aria-label":`Close`,className:`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 text-muted-foreground`,children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),(t.tier||t.fallbackProfile)&&(0,Z.jsxs)(`div`,{className:`border-b bg-warning/5 px-3 py-1.5 text-[11px] text-warning`,children:[`Lane #`,e+1,` is currently pinned to`,` `,(0,Z.jsxs)(`span`,{className:`font-mono`,children:[t.tier?`tier:${t.tier}`:null,t.tier&&t.fallbackProfile?` · `:null,t.fallbackProfile?`profile:${t.fallbackProfile}`:null]}),`. Picking a model replaces this pin.`]}),(0,Z.jsxs)(`div`,{className:`max-h-[50dvh] overflow-y-auto py-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{o(null),a(!1)},className:`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors hover:bg-accent/40 text-muted-foreground`,children:[(0,Z.jsx)(On,{className:`h-4 w-4 shrink-0`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{children:`Inherit — routing / session`}),(0,Z.jsx)(`span`,{className:`block text-[10px] font-mono`,children:`leave the lane empty; routing decides`})]})]}),O.length===0?(0,Z.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:x.length===0?`No providers connected yet.`:Object.keys(w).length===0?`Loading models…`:_?d?.length?`No favorites match the search.`:`No favorites configured.`:`No matches.`}):O.map((e,i)=>{let a=e.provider===t.provider&&e.model===t.model,o=n&&r&&e.provider===n&&e.model===r,s=Km(e.provider,e.model,d);return(0,Z.jsxs)(`button`,{type:`button`,"data-lane-candidate":`true`,onClick:()=>k(i),onMouseEnter:()=>b(i),className:K(`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors`,i===y?`bg-accent text-accent-foreground`:`hover:bg-accent/40`,a&&`font-medium`),children:[(0,Z.jsx)(On,{className:K(`h-4 w-4 shrink-0`,a?`text-primary`:`text-muted-foreground`)}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 break-words`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.provider}),(0,Z.jsx)(`span`,{className:`text-muted-foreground/65`,children:`·`}),(0,Z.jsx)(`span`,{children:e.modelName}),s&&(0,Z.jsx)(`span`,{title:`Favorite model`,children:(0,Z.jsx)(ta,{className:`h-3 w-3 fill-warning text-warning shrink-0`})})]}),(e.contextWindow||e.reasoningEffortLevels)&&(0,Z.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono break-words`,children:[e.model,e.contextWindow?` · ctx ${e.contextWindow.toLocaleString()}`:``,e.reasoningEffortLevels?` · effort ${e.reasoningEffortLevels.join(`/`)}`:``]})]}),a?(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-primary font-semibold`,children:`on this lane`}):o?(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground font-semibold`,children:`session model`}):(0,Z.jsx)(Cr,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100`})]},`${e.provider}:${e.model}`)})]})]})})}var Db=16,Ob=8;function kb(e){return e?.provider&&e.model?`${e.provider}/${e.model}`:e?.tier?`tier:${e.tier}`:e?.fallbackProfile?`profile:${e.fallbackProfile}`:``}function Ab(e){return!!(e?.provider||e?.model||e?.tier||e?.fallbackProfile)}function jb({syncPref:e}){let t=G(),[n,r]=(0,X.useState)(null),i=t.subagentModelPlan??{enabled:!0,lock:!0,slots:[]},a=i.slots.length>0?i.slots:Array.from({length:Ob},()=>({})),o=(0,X.useCallback)(t=>e(`subagentModelPlan`,{...i,slots:a,...t}),[a,i,e]),s=(0,X.useCallback)((e,t)=>o({slots:a.map((n,r)=>r===e?t:n)}),[a,o]),c=(0,X.useCallback)(e=>{let t=Math.max(1,Math.min(Db,e));o({slots:t<=a.length?a.slice(0,t):[...a,...Array.from({length:t-a.length},()=>({}))]})},[a,o]),l=a.filter(Ab).length,u=i.followSessionModel===!0,d=n===null?void 0:a[n];return(0,Z.jsxs)(`div`,{className:`pt-2`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold mb-1 mt-3 flex items-center gap-2`,children:[(0,Z.jsx)(Ir,{className:`h-4 w-4 text-muted-foreground`}),`Subagent models (this session)`]}),(0,Z.jsx)(`p`,{className:`mb-3 text-xs text-muted-foreground`,children:`Each running subagent takes the first free lane, so parallel workers run on different models. Scoped to this tab’s session and restored by resume — config.json is untouched. Model routing above is left intact: a role you routed there keeps its model.`}),(0,Z.jsxs)(`label`,{className:`mb-3 flex items-center gap-2 rounded-md border border-border/60 bg-card/50 px-2 py-1.5 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>o({followSessionModel:e.target.checked})}),(0,Z.jsxs)(`span`,{children:[`Use my model for all subagents`,(0,Z.jsx)(`span`,{className:`block text-[10px] text-muted-foreground`,children:`Every plain subagent runs on this session’s model. Outranks the lanes below.`})]})]}),(0,Z.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-4`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:i.enabled!==!1,onChange:e=>o({enabled:e.target.checked})}),`Enabled`]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:i.lock!==!1,onChange:e=>o({lock:e.target.checked})}),`Lanes override the leader`]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[`Lanes`,(0,Z.jsx)(`input`,{type:`number`,min:1,max:Db,value:a.length,disabled:u,onChange:e=>c(Number.parseInt(e.target.value,10)||1),className:`h-8 w-16 rounded-md border bg-background px-2 text-xs`})]}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:l===0?`no lane pinned — spawns resolve as before`:`${l} pinned`})]}),(0,Z.jsx)(`div`,{className:`space-y-1.5 ${u?`pointer-events-none opacity-50`:``}`,children:a.map((e,t)=>{let n=kb(e),i=Ab(e);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1.5 text-xs`,children:[(0,Z.jsxs)(`span`,{className:`w-14 shrink-0 font-mono text-muted-foreground`,children:[`#`,t+1]}),(0,Z.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r(t),"aria-label":`Lane ${t+1} model${i?`: ${n}`:``}`,className:`h-8 min-w-0 flex-1 truncate rounded-md border bg-background px-2 text-left font-mono text-xs hover:border-primary/40 disabled:cursor-not-allowed`,children:i?n:`inherit — routing / session`}),(0,Z.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Clear lane ${t+1}`,disabled:u||!i,onClick:()=>s(t,{}),children:(0,Z.jsx)(hn,{className:`h-3.5 w-3.5`})})]},`lane-${t}`)})}),n!==null&&(0,Z.jsx)(Eb,{laneIndex:n,currentLane:d??{},open:!0,onOpenChange:e=>{e||r(null)},onPick:e=>{s(n,e?{provider:e.provider,model:e.model}:{}),r(null)}})]})}function Mb(e,t,n,r,i){e.set({[r]:i}),t({[r]:i}),r===`contextMode`&&typeof i==`string`&&n(i)}var Nb=[{id:`general`,icon:(0,Z.jsx)(Ii,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.general`,descKey:`settings:tabs.generalDesc`},{id:`fonts`,icon:(0,Z.jsx)(rn,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.fonts`,descKey:`settings:tabs.fontsDesc`},{id:`provider`,icon:(0,Z.jsx)(pa,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.provider`,descKey:`settings:tabs.providerDesc`},{id:`connection`,icon:(0,Z.jsx)(Yi,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.connection`,descKey:`settings:tabs.connectionDesc`},{id:`agent`,icon:(0,Z.jsx)(on,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.agent`,descKey:`settings:tabs.agentDesc`},{id:`execution`,icon:(0,Z.jsx)(mi,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.execution`,descKey:`settings:tabs.executionDesc`},{id:`fallbacks`,icon:(0,Z.jsx)(tr,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.fallbacks`,descKey:`settings:tabs.fallbacksDesc`},{id:`routing`,icon:(0,Z.jsx)(It,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.routing`,descKey:`settings:tabs.routingDesc`},{id:`fleet`,icon:(0,Z.jsx)(Kt,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.fleet`,descKey:`settings:tabs.fleetDesc`},{id:`integrations`,icon:(0,Z.jsx)(er,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.integrations`,descKey:`settings:tabs.integrationsDesc`},{id:`chimera`,icon:(0,Z.jsx)(Jn,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.chimera`,descKey:`settings:tabs.chimeraDesc`},{id:`context`,icon:(0,Z.jsx)(Vn,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.context`,descKey:`settings:tabs.contextDesc`},{id:`logs`,icon:(0,Z.jsx)(mt,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.logs`,descKey:`settings:tabs.logsDesc`},{id:`security`,icon:(0,Z.jsx)(ei,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.security`,descKey:`settings:tabs.securityDesc`},{id:`display`,icon:(0,Z.jsx)(Ii,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.display`,descKey:`settings:tabs.displayDesc`}];function Pb(){let{settingsActiveTab:e,setSettingsActiveTab:t}=q(Yr(e=>({settingsActiveTab:e.settingsActiveTab,setSettingsActiveTab:e.setSettingsActiveTab}))),n=Jg(`settings`),r=(0,X.useRef)(!1),[i,a]=(0,X.useState)(!1),{provider:o,model:s,setProvider:c,setModel:l,wsConnected:u}=V(Yr(e=>({provider:e.provider,model:e.model,setProvider:e.setProvider,setModel:e.setModel,wsConnected:e.wsConnected}))),d=hf(),f=d.client,{updatePrefs:p,switchAutonomy:m,switchContextMode:h}=d,g=G(),{t:_}=W(),v=m_(!0),y=(0,X.useCallback)((e,t)=>{Mb(g,p,h,e,t)},[g,p,h]),[b,x]=(0,X.useState)([]),[S,C]=(0,X.useState)({}),[w,T]=(0,X.useState)([]),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(`catalog`),[P,F]=(0,X.useState)(``),[I,L]=(0,X.useState)(!1),ee=(0,X.useCallback)(()=>{g.reset(),L(!1),window.location.reload()},[g]),R=b.find(e=>e.id===o),z=(0,X.useMemo)(()=>({...S,[o]:(S[o]??[]).filter(e=>!qm(o,e.id,g.disabledModels))}),[S,g.disabledModels,o]),te=Nb.find(t=>t.id===e);(0,X.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;x(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),D(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;C(e=>({...e,[t.provider]:t.models})),k(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));T(t),j(!1),t.length>0&&N(`saved`)}};if(!u||!f)return;let r=f.on(`provider.catalog`,e),i=f.on(`provider.models`,t),a=f.on(`providers.saved`,n);return D(!0),j(!0),f.listProviders(),f.listSavedProviders(),()=>{r?.(),i?.(),a?.()}},[u,f]);let ne=(0,X.useCallback)(e=>{c(e),S[e]||(k(!0),d.listProviderModels?.(e))},[S,c,d]),re=(0,X.useCallback)(async e=>{if(r.current)return;let t=V.getState().model,n=V.getState().provider;if(n&&e!==t){r.current=!0,a(!0),l(e);try{B.info(U.t(`settings:toast.switchingTo`,{provider:n,model:e}));let r=await d.switchModel?.(n,e);r?.success?B.success(U.t(r.runActive?`settings:toast.modelSwitchedRunActive`:`settings:toast.modelSwitchedNextRequest`,{from:`${n} / ${t}`,to:`${n} / ${e}`})):(l(t),B.error(r?.message??U.t(`settings:toast.modelSwitchTimeout`)))}finally{r.current=!1,a(!1)}}},[l,d]),ie=(0,X.useCallback)((e,t,n)=>{d.addKey?.(e,t,n)},[d]),ae=(0,X.useCallback)((e,t)=>{d.deleteKey?.(e,t)},[d]),oe=(0,X.useCallback)((e,t)=>{d.setActiveKey?.(e,t)},[d]),se=(0,X.useCallback)((e,t,n,r,i,a)=>{d.addProvider?.(e,t,n,r,i,a)},[d]),ce=(0,X.useCallback)(e=>{d.removeProvider?.(e)},[d]),le=(0,X.useCallback)((e,t)=>{d.client.updateProvider({id:e,models:[t]}),e===V.getState().provider&&l(t)},[l,d.client]);return(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col bg-gradient-to-b from-background/90 via-background/60 to-background/80`,children:[(0,Z.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-3 border-b border-border/60 bg-card/60 backdrop-blur-xl shrink-0 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(xa,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h1`,{className:`text-lg font-semibold bg-gradient-to-r from-foreground to-foreground/70 bg-clip-text text-transparent`,children:_(`settings:title`)}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:o&&s?`${o} / ${s}`:_(`settings:subtitle`)})]})]}),(0,Z.jsx)(Y,{variant:`ghost`,size:`icon`,onClick:()=>Va(`chat`),children:(0,Z.jsx)(hn,{className:`h-4 w-4`})}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>L(!0),children:_(`settings:resetLabel`)})]}),(0,Z.jsx)(bp,{className:`min-h-0 flex-1`,ref:n,children:(0,Z.jsx)(`div`,{className:`mx-auto max-w-7xl p-4 sm:p-6`,children:(0,Z.jsxs)(Sp,{value:e,onValueChange:t,className:`grid min-h-[calc(100dvh-9rem)] gap-3 lg:grid-cols-[13.5rem_minmax(0,1fr)] lg:gap-5`,children:[(0,Z.jsxs)(`div`,{className:`relative min-w-0`,children:[(0,Z.jsx)(Cp,{className:`flex h-auto w-full justify-start gap-0.5 overflow-x-auto rounded-lg border border-border/60 bg-card/60 p-1.5 shadow-sm [scrollbar-gutter:stable] lg:sticky lg:top-4 lg:flex-col lg:overflow-visible lg:rounded-xl lg:bg-card/60 lg:p-2`,children:Nb.map(e=>(0,Z.jsxs)(wp,{value:e.id,className:`h-9 shrink-0 gap-2.5 rounded-md px-3 text-xs scroll-mt-2 data-[state=active]:bg-primary/10 data-[state=active]:text-primary data-[state=active]:shadow-sm lg:w-full lg:justify-start lg:px-3`,children:[(0,Z.jsx)(`span`,{className:`shrink-0`,children:e.icon}),(0,Z.jsx)(`span`,{className:`truncate`,children:_(e.labelKey)})]},e.id))}),(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-y-1 left-0 z-10 w-8 rounded-l-lg bg-gradient-to-r from-background via-background/90 to-transparent lg:hidden`}),(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-y-1 right-0 z-10 w-8 rounded-r-lg bg-gradient-to-l from-background via-background/90 to-transparent lg:hidden`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-0`,children:[te?.descKey&&(0,Z.jsxs)(`div`,{className:`mb-4 flex items-start gap-3 rounded-xl border border-border/60 bg-card/50 px-4 py-3`,children:[(0,Z.jsx)(`span`,{className:`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:te.icon}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-semibold`,children:_(te.labelKey)}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:_(te.descKey)})]})]}),(0,Z.jsx)(Tp,{value:`general`,className:`mt-0`,children:(0,Z.jsx)(R_,{})}),(0,Z.jsx)(Tp,{value:`fonts`,className:`mt-0`,children:(0,Z.jsx)(Cv,{})}),(0,Z.jsxs)(Tp,{value:`provider`,className:`mt-0 space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-xl border border-primary/25 bg-primary/5 p-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-semibold`,children:`Provider Test`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Test every model on a saved provider or subscription and inspect quota, authentication, latency, and token-limit failures.`})]}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>Ha(`provider-test`),children:`Open Provider Test`})]}),(0,Z.jsx)(Py,{activeProvider:o,catalogProviders:b,isLoadingCatalog:E,savedProviders:w,isLoadingSaved:A,providerTab:M,setProviderTab:N,onSelectProvider:ne,onAddKey:ie,onDeleteKey:ae,onSetActiveKey:oe,onAddProvider:se,onRemoveProvider:ce,onPickProviderModel:le,ws:d.client,catalogQuery:P,setCatalogQuery:F}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold mb-4 flex items-center gap-2`,children:[(0,Z.jsx)(On,{className:`h-4 w-4 text-muted-foreground`}),_(`settings:model.heading`)]}),(0,Z.jsx)(Fv,{provider:o,catalogModels:z,currentCatalogProvider:R,isLoadingModels:O,setIsLoadingModels:k,onModelSelect:re,isSwitching:i,refreshModels:e=>d.listProviderModels?.(e)}),(0,Z.jsx)(Pv,{syncPref:y})]})]}),(0,Z.jsx)(Tp,{value:`connection`,className:`mt-0`,children:(0,Z.jsx)(L_,{})}),(0,Z.jsx)(Tp,{value:`agent`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(x_,{syncPref:y,switchAutonomy:m})}),(0,Z.jsx)(Tp,{value:`execution`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(av,{syncPref:y,fallbackCandidates:v})}),(0,Z.jsx)(Tp,{value:`fallbacks`,className:`mt-0`,children:(0,Z.jsx)(fv,{syncPref:y,candidates:v,provider:o,activeModel:s,setProvider:c,setModel:l,switchModel:d.switchModel})}),(0,Z.jsxs)(Tp,{value:`routing`,className:`mt-0`,children:[(0,Z.jsx)(qy,{syncPref:y,candidates:v}),(0,Z.jsx)(`div`,{className:`mt-6 border-t border-border pt-6`,children:(0,Z.jsx)(Rv,{syncPref:y})}),(0,Z.jsx)(`div`,{className:`mt-6 border-t border-border pt-6`,children:(0,Z.jsx)(jb,{syncPref:y,candidates:v})})]}),(0,Z.jsx)(Tp,{value:`fleet`,className:`mt-0`,children:(0,Z.jsx)(pv,{syncPref:y})}),(0,Z.jsx)(Tp,{value:`integrations`,className:`mt-0`,children:(0,Z.jsx)(Mv,{syncPref:y})}),(0,Z.jsx)(Tp,{value:`chimera`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:(0,Z.jsx)(z_,{syncPref:y,sessionProvider:o,sessionModel:s})})}),(0,Z.jsx)(Tp,{value:`context`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(G_,{syncPref:y})}),(0,Z.jsx)(Tp,{value:`logs`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(Nv,{syncPref:y})}),(0,Z.jsx)(Tp,{value:`security`,className:`mt-0`,children:(0,Z.jsx)(Tb,{})}),(0,Z.jsx)(Tp,{value:`display`,className:`mt-0`,children:(0,Z.jsx)(X_,{syncPref:y})})]})]})})}),(0,Z.jsx)(es,{open:I,onOpenChange:L,children:(0,Z.jsxs)(Zo,{showCloseButton:!1,children:[(0,Z.jsxs)(Yo,{children:[(0,Z.jsx)(Qo,{children:_(`settings:resetConfirmTitle`)}),(0,Z.jsx)($o,{children:_(`settings:resetConfirmBody`)})]}),(0,Z.jsxs)(Xo,{className:`gap-2 sm:gap-0`,children:[(0,Z.jsx)(Y,{variant:`outline`,onClick:()=>L(!1),children:_(`settings:cancel`)}),(0,Z.jsx)(Y,{variant:`destructive`,onClick:ee,children:_(`settings:resetConfirmAction`)})]})]})})]})}var Fb=(0,X.lazy)(()=>La(()=>import(`./AnalyticsDashboard-iIkpKNGk.js`).then(e=>({default:e.AnalyticsDashboard})),__vite__mapDeps([18,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22]))),Ib=(0,X.lazy)(()=>La(()=>import(`./AgentRosterView-BuAsY8eB.js`).then(e=>({default:e.AgentRosterView})),__vite__mapDeps([23,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,25,26,27,28,29,30,31]))),Lb=(0,X.lazy)(()=>La(()=>import(`./ChangesView-Cd3Tl17b.js`).then(e=>({default:e.ChangesView})),__vite__mapDeps([32,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,33,34,35,36]))),Rb=(0,X.lazy)(()=>La(()=>import(`./RepositoryHistoryView-CIsxftEC.js`).then(e=>({default:e.RepositoryHistoryView})),__vite__mapDeps([37,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,27]))),zb=(0,X.lazy)(()=>La(()=>import(`./ChronicleDashboard-D8HEQ32t.js`).then(e=>({default:e.ChronicleDashboard})),__vite__mapDeps([38,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]))),Bb=(0,X.lazy)(()=>La(()=>import(`./CodeEditor-BmnUVoHj.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([39,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,33,34,35,36,40,28,30]))),Vb=(0,X.lazy)(()=>La(()=>import(`./CodeMap-CYr1LK2u.js`).then(e=>({default:e.CodeMap})),__vite__mapDeps([41,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,21,17]))),Hb=(0,X.lazy)(()=>La(()=>import(`./DebugDashboard-KEZZY9pu.js`).then(e=>({default:e.DebugDashboard})),__vite__mapDeps([42,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),Ub=(0,X.lazy)(()=>La(()=>import(`./DesignGalleryView-DWDsOUD3.js`).then(e=>({default:e.DesignGalleryView})),__vite__mapDeps([43,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24]))),Wb=(0,X.lazy)(()=>La(()=>import(`./GoalView-CmRWtduc.js`).then(e=>({default:e.GoalView})),__vite__mapDeps([44,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,24,16,19,0,17,20,21,22,28]))),Gb=(0,X.lazy)(()=>La(()=>import(`./KanbanView-BVHyGhDq.js`).then(e=>({default:e.KanbanView})),__vite__mapDeps([45,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,27,46]))),Kb=(0,X.lazy)(()=>La(()=>import(`./MailboxDetailView-COFzilLE.js`).then(e=>({default:e.MailboxDetailView})),__vite__mapDeps([47,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,24,16,22,35]))),qb=(0,X.lazy)(()=>La(()=>import(`./PromptJournalView-CdC4ldrv.js`).then(e=>({default:e.PromptJournalView})),__vite__mapDeps([48,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]))),Jb=(0,X.lazy)(()=>La(()=>import(`./RefreshDebugView-Dbq_bHwj.js`).then(e=>({default:e.RefreshDebugView})),__vite__mapDeps([49,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,20]))),Yb=(0,X.lazy)(()=>La(()=>import(`./SageTabs-GuriCwuB.js`).then(e=>({default:e.SageTabs})),__vite__mapDeps([50,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Xb=(0,X.lazy)(()=>La(()=>import(`./RequirementIntakeView-Dah2aHco.js`).then(e=>({default:e.RequirementIntakeView})),__vite__mapDeps([51,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,28,29]))),Zb=(0,X.lazy)(()=>La(()=>import(`./SddHub-C7IlzHtw.js`).then(e=>({default:e.SddHub})),__vite__mapDeps([52,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,24,16,19,0,17,20,21,22,27,28,46]))),Qb=(0,X.lazy)(()=>La(()=>import(`./SessionsDashboard-BjevWtcd.js`).then(e=>({default:e.SessionsDashboard})),__vite__mapDeps([53,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,54]))),$b=(0,X.lazy)(()=>La(()=>import(`./SessionInspectView-_qPDgZXH.js`).then(e=>({default:e.SessionInspectView})),__vite__mapDeps([55,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,54,19,20,21,22]))),ex=(0,X.lazy)(()=>La(()=>import(`./SkillDetailView-EaPGctff.js`).then(e=>({default:e.SkillDetailView})),__vite__mapDeps([56,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,24,16,17,27,35]))),tx=(0,X.lazy)(()=>La(()=>import(`./TechStackView-DXoJPVZf.js`).then(e=>({default:e.TechStackView})),__vite__mapDeps([57,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,19,0,16,17,20,21,22,28,29]))),nx=(0,X.lazy)(()=>La(()=>import(`./DeadCodeScanPanel-ByhAW_bl.js`).then(e=>({default:e.DeadCodeScanPanel})),__vite__mapDeps([58,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17]))),rx=(0,X.lazy)(()=>La(()=>import(`./ChimeraReviewsView-CWo6AV3H.js`).then(e=>({default:e.ChimeraReviewsView})),__vite__mapDeps([59,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,35]))),ix=(0,X.lazy)(()=>La(()=>import(`./SetupScreen-DCupHAif.js`).then(e=>({default:e.SetupScreen})),__vite__mapDeps([60,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,27,28,29]))),ax={"provider-test":{Component:(0,X.lazy)(()=>La(()=>import(`./ProviderTestView-CVKjGm2z.js`).then(e=>({default:e.ProviderTestView})),__vite__mapDeps([61,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,27,28,29]))),wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:nav.provider-test`,loadingLabelKey:`activity:nav.provider-test`},settings:{Component:Pb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.settings`,loadingLabelKey:null},memory:{Component:Yb,wrapperClassName:``,boundaryNameKey:`activity:panels.sageMemory`,loadingLabelKey:`activity:panels.sageMemory`},roster:{Component:Ib,wrapperClassName:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,boundaryNameKey:`activity:panels.agentRoster`,loadingLabelKey:`activity:panels.agentRoster`},context:{Component:p_,wrapperClassName:``,boundaryNameKey:`activity:panels.contextDashboard`,loadingLabelKey:null},setup:{Component:ix,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.setup`,loadingLabelKey:null},goal:{Component:Wb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.goal`,loadingLabelKey:null,props:{onClose:`PANEL_CLOSE_TO_CHAT`}},sddhub:{Component:Zb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.sddHub`,loadingLabelKey:null},kanban:{Component:Gb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.kanban`,loadingLabelKey:null,props:{onClose:`PANEL_CLOSE_TO_CHAT`}},sessions:{Component:Qb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.sessions`,loadingLabelKey:null},"session-inspect":{Component:$b,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.sessionInspect`,loadingLabelKey:`activity:panels.sessionInspect`},chronicle:{Component:zb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.chronicle`,loadingLabelKey:null},intake:{Component:Xb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.requirementsIntake`,loadingLabelKey:null},prompts:{Component:qb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:nav.prompts`,loadingLabelKey:`activity:nav.prompts`},debug:{Component:Hb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.debugDashboard`,loadingLabelKey:null},"refresh-debug":{Component:Jb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.refreshDebug`,loadingLabelKey:`activity:panels.refreshDebug`},files:{Component:Bb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.editor`,loadingLabelKey:`activity:panels.editor`},changes:{Component:Lb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.changes`,loadingLabelKey:`activity:panels.changes`,props:{className:`h-full min-h-0`}},history:{Component:Rb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:nav.repositoryHistory`,loadingLabelKey:`activity:nav.repositoryHistory`},mailbox:{Component:Kb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.mailbox`,loadingLabelKey:null,props:{className:`h-full min-h-0`}},"design-gallery":{Component:Ub,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.designGallery`,loadingLabelKey:null,props:{className:`h-full`}},skill:{Component:ex,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.skill`,loadingLabelKey:null,props:{className:`h-full`}},analytics:{Component:Fb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.analytics`,loadingLabelKey:null},codemap:{Component:Vb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.codemap`,loadingLabelKey:`activity:panels.codemap`},techstack:{Component:tx,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.techstack`,loadingLabelKey:`activity:panels.techstack`},deadcode:{Component:nx,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-y-auto`,boundaryNameKey:`activity:panels.deadcode`,loadingLabelKey:`activity:panels.deadcode`},chimera:{Component:rx,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:nav.chimera`,loadingLabelKey:null}};function ox({view:e,onCloseToChat:t}){let{t:n}=W(),r=ax[e];if(!r)return null;let i=r.Component,a={...r.props??{}};for(let[e,n]of Object.entries(a))n===`PANEL_CLOSE_TO_CHAT`&&(a[e]=t);let o=r.wrapperClassName?(0,Z.jsx)(`div`,{className:r.wrapperClassName,children:(0,Z.jsx)(i,{...a})}):(0,Z.jsx)(i,{...a}),s=r.loadingLabelKey?(0,Z.jsx)(qg,{label:n(`common:loadingNamed`,{name:n(r.loadingLabelKey)})}):(0,Z.jsx)(qg,{});return(0,Z.jsx)(_p,{level:`panel`,name:n(r.boundaryNameKey),children:(0,Z.jsx)(X.Suspense,{fallback:s,children:o})})}function sx(){Va(`chat`)}function cx(e){try{return new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return e}}function lx(e){switch(e){case`active`:return`text-success border-success/30 bg-success/[0.06]`;case`injected`:return`text-primary border-primary/30 bg-primary/[0.06]`;case`exited`:return`text-muted-foreground border-border/40 bg-muted/20`;default:return`text-muted-foreground border-border/40 bg-muted/20`}}function ux(e){switch(e){case`fact`:return`text-primary`;case`decision`:return`text-accent2`;case`convention`:return`text-ring`;case`warning`:case`anti_pattern`:return`text-warning`;case`bug_root_cause`:return`text-destructive`;case`preference`:return`text-accent`;default:return`text-muted-foreground`}}function dx(e){return e>=.9?`crit`:e>=.6?`high`:e>=.3?`med`:`low`}var fx=(0,X.memo)(function({open:e,onClose:t}){let{t:n}=W(),r=Ml(e=>e.traces),i=Ml(e=>e.contextMemories),a=Ml(e=>e.transitions),o=Ml(e=>e.clear);(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let s=r[0],c=Object.values(i),l=c.filter(e=>e.state!==`exited`),u=c.length-l.length,d=s?Object.values(s.rejected).reduce((e,t)=>e+t,0):0;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:K(`fixed inset-0 z-40 bg-background/50 backdrop-blur-[1px] transition-opacity duration-200`,e?`opacity-100`:`pointer-events-none opacity-0`),onClick:t,"aria-hidden":!0}),(0,Z.jsx)(`aside`,{className:K(`fixed right-0 top-0 z-50 h-full w-full max-w-md border-l border-border/60 bg-card/95 backdrop-blur-xl shadow-2xl`,`transition-transform duration-300 ease-out`,e?`translate-x-0`:`translate-x-full`),role:`dialog`,"aria-label":n(`activity:sageMemory.injectedHeading`,`Memory Context`),"data-testid":`memory-injector-panel`,children:(0,Z.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/60 px-4 py-3 shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Jn,{className:`size-4 text-primary`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold text-foreground`,children:n(`activity:sageMemory.injectedHeading`,`Memory Context`)}),l.length>0&&(0,Z.jsxs)(`span`,{className:`rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-bold text-primary tabular-nums`,children:[l.length,` active`]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r.length>0&&(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:`rounded-md px-2 py-1 text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:n(`activity:memoryManager.clearTracesTitle`),children:`Clear`}),(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-md p-1.5 text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:n(`activity:memoryManager.closePanelTitle`),children:(0,Z.jsx)(Qi,{className:`size-4`})})]})]}),s&&(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-border/40 bg-muted/20 px-4 py-2`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] tabular-nums`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(ti,{className:`size-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`font-mono text-foreground`,children:s.candidates}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceMatched`)})]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-success`,children:s.injected.length}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceInjected`)})]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-warning`,children:d}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceFiltered`)})]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-ring`,children:l.length}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceActive`)})]}),u>0&&(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:u}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceExited`)})]})]}),(0,Z.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[10px] text-muted-foreground/80`,children:[(0,Z.jsx)(la,{className:`size-3`}),(0,Z.jsx)(`span`,{children:cx(s.at)}),(0,Z.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-mono`,children:s.trigger}),s.toolName&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-mono`,children:s.toolName})]}),(0,Z.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,Z.jsxs)(`span`,{children:[`ctx `,Math.round(s.contextPressure*100),`%`]})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto overscroll-contain`,children:[l.length>0?(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsx)(`div`,{className:`sticky top-0 z-10 bg-card/95 backdrop-blur-sm px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-muted-foreground border-b border-border/40`,children:n(`activity:memoryManager.injectorActiveInContext`)}),l.map(e=>(0,Z.jsxs)(`div`,{className:`border-b border-border/30 px-4 py-3 hover:bg-muted/15 transition-colors`,children:[(0,Z.jsx)(`div`,{className:`flex items-start gap-2`,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 shrink-0`,children:[(0,Z.jsx)(`span`,{className:K(`rounded border px-1 py-0.5 text-[9px] font-bold uppercase`,ux(e.kind)),children:e.kind}),(0,Z.jsx)(`span`,{className:K(`rounded border px-1 py-0.5 text-[9px] font-bold uppercase`,lx(e.state)),children:dx(e.importance)})]})}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[12px] leading-relaxed text-foreground/90 break-words`,children:e.isPlaceholder?(0,Z.jsx)(`span`,{className:`italic text-muted-foreground`,children:e.text}):e.text}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[10px] text-muted-foreground/70`,children:[(0,Z.jsxs)(`span`,{className:`font-mono`,children:[e.id.slice(0,16),`…`]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Z.jsx)(`span`,{className:`opacity-60`,children:n(`activity:memoryManager.traceScore`)}),(0,Z.jsx)(`span`,{className:`font-mono text-foreground/60`,children:e.score.toFixed(2)})]}),e.trigger&&(0,Z.jsx)(`span`,{className:`font-mono`,children:e.trigger}),(0,Z.jsx)(`span`,{children:cx(e.lastSeenAt)})]}),e.tags.length>0&&(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-1`,children:[(0,Z.jsx)(Xi,{className:`size-2.5 text-muted-foreground/50`}),e.tags.slice(0,6).map(e=>(0,Z.jsx)(`span`,{className:`rounded bg-muted/40 px-1 py-0.5 text-[9px] text-muted-foreground/80`,children:e},e))]}),e.anchors.length>0&&(0,Z.jsxs)(`div`,{className:`mt-1 text-[10px] text-muted-foreground/60 font-mono truncate`,children:[`↳ `,e.anchors.slice(0,2).join(`, `)]})]},e.id))]}):(0,Z.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-muted-foreground/60`,children:r.length===0?`No memory injections yet. Memories will appear here when the agent reads files or searches code.`:`No memories currently active in provider context.`}),r.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`sticky top-0 z-10 bg-card/95 backdrop-blur-sm px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-muted-foreground border-t border-border/40 border-b`,children:n(`activity:memoryManager.injectorInjectionHistory`)}),r.slice(0,20).map(e=>{let t=Object.values(e.rejected).reduce((e,t)=>e+t,0);return(0,Z.jsxs)(`div`,{className:`border-b border-border/30 px-4 py-2.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] tabular-nums`,children:[(0,Z.jsx)(la,{className:`size-3 text-muted-foreground/60`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:cx(e.at)}),(0,Z.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-mono text-foreground/80`,children:e.trigger}),e.toolName&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:e.toolName})]})]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-3 text-[10px] tabular-nums text-muted-foreground/70`,children:[(0,Z.jsxs)(`span`,{className:`text-success`,children:[e.injected.length,` injected`]}),(0,Z.jsxs)(`span`,{className:`text-warning`,children:[t,` filtered`]}),(0,Z.jsxs)(`span`,{children:[e.candidates,` candidates`]}),(0,Z.jsxs)(`span`,{children:[`ctx `,Math.round(e.contextPressure*100),`%`]}),e.outcome===`error`&&(0,Z.jsx)(`span`,{className:`text-destructive`,children:n(`activity:memoryManager.traceError`)})]})]},e.runId)})]}),a.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`sticky top-0 z-10 bg-card/95 backdrop-blur-sm px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-muted-foreground border-t border-border/40 border-b`,children:n(`activity:memoryManager.injectorContextTransitions`)}),a.slice(0,15).map(e=>(0,Z.jsxs)(`div`,{className:`border-b border-border/20 px-4 py-1.5 flex items-center gap-2 text-[10px] tabular-nums`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground/60`,children:cx(e.at)}),(0,Z.jsx)(`span`,{className:K(`rounded px-1 py-0.5 text-[9px] font-bold uppercase`,e.action===`injected`&&`bg-primary/10 text-primary`,e.action===`entered`&&`bg-success/10 text-success`,e.action===`exited`&&`bg-muted/40 text-muted-foreground`),children:e.action}),(0,Z.jsxs)(`span`,{className:`font-mono text-muted-foreground truncate`,children:[e.memoryId.slice(0,14),`…`]}),(0,Z.jsx)(`span`,{className:`text-muted-foreground/50 truncate ml-auto`,children:e.reason})]},e.id))]})]})]})})]})});function px(e){return e.replace(/\\/g,`/`).split(`/`).pop()??e}function mx(e){if(e.kind===`file`)return e.path;let t=e.kind===`snippet`?e.content:e.preview,n=t.split(`
114
+ AWS_REGION=us-east-1`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:a(`settings:mcp.fieldDescription`)}),(0,Z.jsx)(ts,{value:u,onChange:e=>d(e.target.value),placeholder:a(`settings:mcp.fieldDescriptionPlaceholder`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`server-enabled`,checked:b,onChange:e=>x(e.target.checked),className:`rounded`}),(0,Z.jsx)(`label`,{htmlFor:`server-enabled`,className:`text-sm`,children:a(`settings:mcp.enableServer`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`server-lazy`,checked:S,onChange:e=>C(e.target.checked),className:`rounded`}),(0,Z.jsxs)(`label`,{htmlFor:`server-lazy`,className:`text-sm`,children:[a(`settings:mcp.lazyConnect`),` `,(0,Z.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:a(`settings:mcp.lazyConnectHint`)})]})]})]}),(0,Z.jsxs)(Xo,{children:[(0,Z.jsx)(Y,{variant:`outline`,onClick:()=>t(!1),children:a(`common:action.cancel`)}),(0,Z.jsx)(Y,{onClick:w,children:a(T?`settings:mcp.saveChanges`:`settings:mcp.addServer`)})]})]})})}function Av({server:e,isAdded:t,onAdd:n}){let{t:r}=W();return(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 rounded-md border border-border/70 bg-card/70 p-3 transition-colors hover:bg-card`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),e.badge&&(0,Z.jsx)(j_,{variant:`secondary`,className:`text-xs shrink-0`,children:e.badge}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-xs shrink-0`,children:e.transport})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description}),e.requiresEnvVars&&e.requiresEnvVars.length>0&&(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-warning`,children:r(`settings:mcp.requires`,{vars:e.requiresEnvVars.join(`, `)})})]}),(0,Z.jsx)(`div`,{className:`shrink-0`,children:t?(0,Z.jsxs)(Y,{variant:`ghost`,size:`sm`,disabled:!0,children:[(0,Z.jsx)(xn,{className:`w-4 h-4 mr-1`}),r(`settings:mcp.added`)]}):(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:n,children:[(0,Z.jsx)(Gi,{className:`w-4 h-4 mr-1`}),r(`common:action.add`)]})})]})}function jv(){let e=hf(),{t}=W(),[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(`list`),[c,l]=(0,X.useState)(),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(),[g,_]=(0,X.useState)(null);(0,X.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]),B.success(U.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)),B.success(U.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)),_(null),B.success(U.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)),_(null),B.info(U.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)),_(null),B.success(U.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)),_(null),B.success(U.t(`settings:mcp.toastReconnected`,{name:t.name}))}},f=e=>{if(e.type===`mcp.server.disconnected`){let t=e.payload,n=t.reason===`stop`||t.reason===`idle-sleep`||t.reason.endsWith(`(dormant)`);r(e=>e.map(e=>e.name===t.name?n?{...e,status:t.reason===`stop`?`stopped`:`sleeping`,pid:void 0}:{...e,status:`error`,error:t.reason,lastError:t.reason,pid:void 0}:e)),_(null),n||B.warn(U.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)),_(null),B.error(U.t(`settings:mcp.toastError`,{name:t.name,error:t.error}))}},m=e=>{if(e.type===`mcp.operation_result`){let t=e.payload;t.success||B.error(t.message),_(null)}},h=e.client.on(`mcp.list`,t),g=e.client.on(`mcp.server.added`,n),v=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?.(),v?.(),y?.(),b?.(),x?.(),S?.(),C?.(),w?.(),T?.(),E?.(),D?.()}},[e.client]);let v=(0,X.useCallback)(t=>{e.client?.addMcpServer(t)},[e]),y=(0,X.useCallback)(e=>{h(Tv(e,!1)),p(!0)},[]),b=(0,X.useCallback)(n=>{$f({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]),x=(0,X.useCallback)(e=>{l(e),h(void 0),d(!0)},[]),S=(0,X.useCallback)(t=>{e.client?.updateMcpServer(t)},[e]),C=(0,X.useCallback)(t=>{_(t),e.client?.wakeMcpServer(t)},[e]),w=(0,X.useCallback)(t=>{_(t),e.client?.sleepMcpServer(t)},[e]),T=(0,X.useCallback)(t=>{_(t),e.client?.discoverMcpServer(t)},[e]),E=(0,X.useCallback)(()=>{a(!0),e.client?.listMcpServers()},[e]),D=n.filter(e=>e.status===`connected`).length,O=n.filter(e=>e.status===`sleeping`).length,k=new Set(n.map(e=>e.name));return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Hn,{className:`h-5 w-5`})}),(0,Z.jsx)(`h2`,{className:`text-base font-semibold`,children:t(`settings:mcp.heading`)}),n.length>0&&(0,Z.jsx)(`span`,{className:`rounded-md border border-border/60 bg-muted/30 px-2 py-1 text-xs text-muted-foreground`,children:t(`settings:mcp.summary`,{connected:D,sleeping:O,total:n.length})})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:E,disabled:i,children:[i?(0,Z.jsx)(mn,{className:`w-4 h-4 animate-spin`}):null,t(`common:action.refresh`)]}),(0,Z.jsxs)(Y,{size:`sm`,onClick:()=>{h(void 0),p(!0)},children:[(0,Z.jsx)(Gi,{className:`w-4 h-4 mr-1`}),t(`settings:mcp.addCustom`)]})]})]}),(0,Z.jsxs)(Sp,{value:o,onValueChange:e=>s(e),children:[(0,Z.jsxs)(Cp,{children:[(0,Z.jsxs)(wp,{value:`recommended`,children:[(0,Z.jsx)(ta,{className:`w-3.5 h-3.5 mr-1`}),t(`settings:mcp.tabRecommended`)]}),(0,Z.jsx)(wp,{value:`list`,children:t(`settings:mcp.tabServers`)}),(0,Z.jsx)(wp,{value:`add`,children:t(`settings:mcp.tabAddCustom`)})]}),(0,Z.jsxs)(Tp,{value:`recommended`,className:`space-y-3`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(`settings:mcp.recommendedBody`)}),(0,Z.jsx)(`div`,{className:`grid gap-2`,children:wv.map(e=>(0,Z.jsx)(Av,{server:e,isAdded:k.has(e.name),onAdd:()=>y(e)},e.name))})]}),(0,Z.jsx)(Tp,{value:`list`,className:`space-y-3`,children:i&&n.length===0?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(mn,{className:`w-5 h-5 animate-spin mr-2`}),t(`settings:mcp.loadingServers`)]}):n.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(Hn,{className:`w-10 h-10 mx-auto mb-2 opacity-50`}),(0,Z.jsx)(`p`,{children:t(`settings:mcp.noServers`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:t(`settings:mcp.noServersHint`)})]}):n.map(e=>(0,Z.jsx)(Ov,{server:e,onWake:()=>C(e.name),onSleep:()=>w(e.name),onDiscover:()=>T(e.name),onEdit:()=>x(e),onRemove:()=>b(e.name)},e.name))}),(0,Z.jsx)(Tp,{value:`add`,children:(0,Z.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[(0,Z.jsx)(`p`,{children:t(`settings:mcp.addCustomBody`)}),(0,Z.jsx)(`p`,{className:`mt-1`,children:t(`settings:mcp.addCustomBodyHint`)})]})})]}),(0,Z.jsx)(kv,{open:f,onOpenChange:e=>{e||(p(!1),h(void 0))},prefillConfig:m,onSave:v}),(0,Z.jsx)(kv,{open:u,onOpenChange:d,server:c,onSave:S})]})}function Mv({syncPref:e}){let{t}=W(),n=G();return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Hn,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`settings:integrations.wrongProxyHeading`)})})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)($,{label:t(`settings:integrations.wrongProxyEnabledLabel`),hint:t(`settings:integrations.wrongProxyEnabledHint`),value:n.wrongProxyEnabled,onChange:()=>e(`wrongProxyEnabled`,!n.wrongProxyEnabled)}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:t(`settings:integrations.wrongProxyUrlLabel`)}),(0,Z.jsx)(ts,{value:n.wrongProxyUrl,placeholder:`http://localhost:3444`,onChange:t=>e(`wrongProxyUrl`,t.target.value)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.wrongProxyUrlHint`)})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.wrongProxyChangesApply`)})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Hn,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`settings:integrations.hqHeading`)})})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)($,{label:t(`settings:integrations.hqPublishingLabel`),hint:t(`settings:integrations.hqPublishingHint`),value:n.hqEnabled,onChange:()=>e(`hqEnabled`,!n.hqEnabled)}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:t(`settings:integrations.hqUrlLabel`)}),(0,Z.jsx)(ts,{value:n.hqUrl,placeholder:t(`activity:integrationsSection.httpHost3499`),onChange:t=>e(`hqUrl`,t.target.value)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.hqUrlHint`)})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:t(`settings:integrations.hqTokenLabel`)}),(0,Z.jsx)(ts,{type:`password`,value:n.hqToken,placeholder:t(`activity:integrationsSection.clientTokenFromWstackHq`),onChange:t=>e(`hqToken`,t.target.value)})]}),(0,Z.jsx)($,{label:t(`settings:integrations.hqRawContentLabel`),hint:t(`settings:integrations.hqRawContentHint`),value:n.hqRawContent,onChange:()=>e(`hqRawContent`,!n.hqRawContent)})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Hn,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`activity:integrationsSection.mcpServers`)})})]}),n.featureMcp?(0,Z.jsx)(jv,{}):(0,Z.jsxs)(`div`,{className:`text-center py-6 text-muted-foreground`,children:[(0,Z.jsx)(Hn,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:t(`settings:mcp.disabled`)}),(0,Z.jsx)(`p`,{className:`text-xs mt-1`,children:t(`settings:integrations.disabledHint`)})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(At,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`settings:integrations.telegramHeading`)})})]}),n.tgConfigured?(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)($,{label:t(`settings:integrations.telegramSessionEndLabel`),hint:t(`settings:integrations.telegramSessionEndHint`),value:n.tgSessionEnd,onChange:()=>e(`tgSessionEnd`,!n.tgSessionEnd)}),(0,Z.jsx)($,{label:t(`settings:integrations.telegramDelegateLabel`),hint:t(`settings:integrations.telegramDelegateHint`),value:n.tgDelegate,onChange:()=>e(`tgDelegate`,!n.tgDelegate)}),(0,Z.jsx)($,{label:t(`settings:integrations.telegramLongToolLabel`),hint:t(`settings:integrations.telegramLongToolHint`,{ms:n.tgLongToolMs}),value:n.tgLongToolMs>0,onChange:()=>e(`tgLongToolMs`,n.tgLongToolMs>0?0:3e4)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.telegramChangesApply`)})]}):(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings:integrations.telegramNotConfigured`)})]})]})}function Nv({syncPref:e}){let{t}=W(),n=G();return(0,Z.jsx)(`div`,{className:`space-y-6`,children:(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(mt,{className:`h-5 w-5`})}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:t(`settings:logs.heading`)})})]}),(0,Z.jsx)(Q,{label:t(`settings:logs.logLevelLabel`),hint:t(`settings:logs.logLevelHint`),value:n.logLevel,options:[{value:`debug`,label:t(`settings:logs.logLevelDebug`)},{value:`info`,label:t(`settings:logs.logLevelInfo`)},{value:`warn`,label:t(`settings:logs.logLevelWarn`)},{value:`error`,label:t(`settings:logs.logLevelError`)}],onChange:t=>e(`logLevel`,t)}),(0,Z.jsx)(Q,{label:t(`settings:logs.auditLevelLabel`),hint:t(`settings:logs.auditLevelHint`),value:n.auditLevel,options:[{value:`minimal`,label:t(`settings:logs.auditLevelMinimal`)},{value:`standard`,label:t(`settings:logs.auditLevelStandard`)},{value:`full`,label:t(`settings:logs.auditLevelFull`)}],onChange:t=>e(`auditLevel`,t)}),(0,Z.jsx)(Q,{label:t(`settings:logs.fsAccessLabel`),hint:t(`settings:logs.fsAccessHint`),value:n.fsAccess,options:[{value:`unrestricted`,label:t(`settings:logs.fsAccessUnrestricted`)},{value:`project`,label:t(`settings:logs.fsAccessProject`)}],onChange:t=>e(`fsAccess`,t)}),(0,Z.jsx)($,{label:t(`settings:logs.debugStreamLabel`),hint:t(`settings:logs.debugStreamHint`),value:n.debugStream,onChange:()=>e(`debugStream`,!n.debugStream)})]})})}function Pv({syncPref:e}){let{t}=W(),n=G(e=>e.reasoningEffort),r=H(e=>e.reasoningEffortLevels),i=Um(r,n).map(e=>({value:e,label:t(Hm(e))}));return(0,Z.jsx)(`div`,{className:`mt-4 border-t border-border/60 pt-4`,children:(0,Z.jsx)(Q,{label:t(`settings:agent.reasoningEffortLabel`),hint:Wm(r,n)?t(`settings:agent.reasoningEffortUnsupported`,{levels:(r??[]).join(`, `)}):r?`${t(`settings:agent.reasoningEffortHint`)} (${t(`settings:agent.reasoningEffortModelSet`)})`:t(`settings:agent.reasoningEffortHint`),value:n,options:i,onChange:t=>e(`reasoningEffort`,t)})})}function Fv({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,isSwitching:i,setIsLoadingModels:a,onModelSelect:o,refreshModels:s}){let c=V(e=>e.model),{t:l}=W();return(0,Z.jsx)(`div`,{className:`space-y-4`,children:e?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:n?.name||e}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>{a(!0),s(e)},children:(0,Z.jsx)(Yn,{className:K(`h-4 w-4`,r&&`animate-spin`)})})]}),r&&!t[e]?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,Z.jsx)(mn,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:l(`settings:model.loading`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(h_,{options:(t[e]||[]).map(e=>({id:e.id,label:e.name||e.id,badges:e.capabilities,detail:[e.contextWindow?`${Math.round(e.contextWindow/1e3)}k`:``,e.inputCost==null?``:`${e.inputCost}/${e.outputCost}`,e.reasoningEffortLevels?.length?`effort ${e.reasoningEffortLevels.join(`/`)}`:``].filter(Boolean).join(` · `),detailHighlight:!0})),selectedId:c,onSelect:o,disabled:i,emptyMessage:l(`settings:model.notFound`)}),i?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`settings:toast.switching`)}):null]})]}):(0,Z.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(On,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,Z.jsx)(`p`,{children:l(`settings:model.selectProviderFirst`)})]})})}var Iv=[{value:`off`,label:`Off`,hint:`The leader never changes its own tier.`},{value:`propose`,label:`Propose`,hint:`The leader asks before switching. Recommended.`},{value:`auto`,label:`Auto`,hint:`The leader switches on its own, still bounded by the guard rails below.`}],Lv={};function Rv({syncPref:e}){let t=G(),n=t.modelTiers??{},r=n.levels??{},i=n.routing??{},a=n.leader??{},o=Object.keys(r),s=Object.keys(t.fallbackProfiles??{}),[c,l]=(0,X.useState)(``),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(``),m=(0,X.useCallback)(t=>e(`modelTiers`,{...n,...t}),[e,n]),h=(0,X.useCallback)((t,i)=>e(`modelTiers`,{...n,levels:{...r,[t]:{...r[t]??{},...i}}}),[e,n,r]),g=(0,X.useCallback)(t=>{let a={...r};delete a[t];let o=Object.fromEntries(Object.entries(i).filter(([,e])=>e!==t));e(`modelTiers`,{...n,levels:a,routing:o})},[e,n,r,i]),_=()=>{let e=c.trim();e&&!r[e]&&(h(e,Lv),l(``))},v=()=>{let e=u.trim();e&&f&&(m({routing:{...i,[e]:f}}),d(``),p(``))},y=e=>{let t={...i};delete t[e],m({routing:t})},b=e=>{let t=e.trim();if(!t)return;let n=Number.parseFloat(t);return Number.isFinite(n)&&n>=0?n:void 0};return(0,Z.jsxs)(`section`,{className:`space-y-3`,"data-testid":`model-tiers-section`,children:[(0,Z.jsxs)(`header`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Mi,{className:`h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:`Model cost tiers`}),(0,Z.jsxs)(`label`,{className:`ml-auto flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:n.enabled===!0,onChange:e=>m({enabled:e.target.checked}),"data-testid":`model-tiers-enabled`}),`Enabled`]})]}),(0,Z.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:`A tier binds a fallback profile, a spend budget and a runtime setting under one name, then routes work to it by role or phase. Subagents, Kanban dispatch and the leader all read this table. While disabled, everything resolves exactly as it did before tiers existed.`}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,Z.jsx)(`h4`,{className:`text-xs font-medium text-foreground`,children:`Levels`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Order is the ladder — the first row is the cheapest rung.`})]}),o.length===0&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`No levels yet. Add one below, then point it at a fallback profile.`}),o.map((e,t)=>{let n=r[e]??{};return(0,Z.jsxs)(`div`,{className:`space-y-1.5 rounded-md border border-border bg-muted px-2 py-1.5`,"data-testid":`model-tier-row-${e}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:t+1}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 break-words font-mono font-medium text-foreground`,children:e}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:`text-muted-foreground hover:text-destructive`,title:`Remove level`,"data-testid":`model-tier-remove-${e}`,children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Z.jsxs)(`select`,{value:n.fallbackProfile??``,onChange:t=>h(e,{fallbackProfile:t.target.value||void 0}),className:`rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-profile-${e}`,children:[(0,Z.jsx)(`option`,{value:``,children:`profile: (none)`}),s.map(e=>(0,Z.jsxs)(`option`,{value:e,children:[`profile: `,e]},e))]}),(0,Z.jsx)(`input`,{type:`number`,min:0,step:`0.01`,value:n.maxCostUsd??``,onChange:t=>h(e,{maxCostUsd:b(t.target.value)}),placeholder:`max $`,className:`w-20 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-cost-${e}`}),(0,Z.jsx)(`input`,{type:`number`,min:0,value:n.maxIterations??``,onChange:t=>h(e,{maxIterations:b(t.target.value)}),placeholder:`iters`,className:`w-16 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`}),(0,Z.jsx)(`input`,{type:`number`,min:0,value:n.maxToolCalls??``,onChange:t=>h(e,{maxToolCalls:b(t.target.value)}),placeholder:`tools`,className:`w-16 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`})]}),n.maxCostUsd!==void 0&&(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Tightens a role's default budget down to this ceiling; it never raises one, and never overrides a budget passed explicitly to the spawn.`})]},e)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&_()},placeholder:`new level name (e.g. budget)`,className:`min-w-0 flex-1 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-new-name`}),(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:_,disabled:!c.trim(),children:[(0,Z.jsx)(Gi,{className:`mr-1 h-3 w-3`}),` Add`]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`h4`,{className:`text-xs font-medium text-foreground`,children:`Routing`}),Object.keys(i).length===0?(0,Z.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`No rules — everything uses the default tier`,n.default?` (${n.default})`:` (standard)`,`.`]}):(0,Z.jsx)(`ul`,{className:`space-y-1`,children:Object.entries(i).map(([e,t])=>(0,Z.jsxs)(`li`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-muted px-2 py-1 text-[11px]`,"data-testid":`model-tier-route-${e}`,children:[(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1 break-words font-mono text-foreground`,children:[e,` → `,t]}),!r[t]&&(0,Z.jsx)(`span`,{className:`rounded-sm bg-warning/15 px-1 py-0.5 text-[10px] text-foreground`,children:`missing level`}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>y(e),className:`text-muted-foreground hover:text-destructive`,title:`Remove rule`,children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]},e))}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),placeholder:`role, phase, or *`,className:`min-w-0 flex-1 rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-new-route-key`}),(0,Z.jsxs)(`select`,{value:f,onChange:e=>p(e.target.value),className:`rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-new-route-tier`,children:[(0,Z.jsx)(`option`,{value:``,children:`tier…`}),o.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]}),(0,Z.jsx)(Y,{size:`sm`,variant:`outline`,onClick:v,disabled:!u.trim()||!f,children:(0,Z.jsx)(Gi,{className:`h-3 w-3`})})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`Default tier`}),(0,Z.jsxs)(`select`,{value:n.default??``,onChange:e=>m({default:e.target.value||void 0}),className:`rounded-sm border border-border bg-background px-1.5 py-0.5 text-[11px]`,"data-testid":`model-tier-default`,children:[(0,Z.jsx)(`option`,{value:``,children:`standard`}),o.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`h4`,{className:`text-xs font-medium text-foreground`,children:`Leader self-switching`}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Iv.map(e=>{let t=(a.mode??`propose`)===e.value;return(0,Z.jsx)(`button`,{type:`button`,title:e.hint,onClick:()=>m({leader:{...a,mode:e.value}}),className:t?`rounded-sm border border-primary bg-primary/10 px-2 py-0.5 text-[11px] text-foreground`:`rounded-sm border border-border bg-background px-2 py-0.5 text-[11px] text-muted-foreground hover:text-foreground`,"data-testid":`model-tier-leader-${e.value}`,children:e.label},e.value)})}),(0,Z.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:Iv.find(e=>e.value===(a.mode??`propose`))?.hint}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 text-[11px]`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-1 text-muted-foreground`,children:[`dwell`,(0,Z.jsx)(`input`,{type:`number`,min:0,value:a.dwellTurns??``,onChange:e=>m({leader:{...a,dwellTurns:b(e.target.value)}}),placeholder:`6`,className:`w-14 rounded-sm border border-border bg-background px-1.5 py-0.5`,"data-testid":`model-tier-leader-dwell`}),`turns`]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-1 text-muted-foreground`,children:[`min saving $`,(0,Z.jsx)(`input`,{type:`number`,min:0,step:`0.01`,value:a.minSavingsUsd??``,onChange:e=>m({leader:{...a,minSavingsUsd:b(e.target.value)}}),placeholder:`0.10`,className:`w-16 rounded-sm border border-border bg-background px-1.5 py-0.5`})]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-1 text-muted-foreground`,children:[`ceiling`,(0,Z.jsxs)(`select`,{value:a.maxTier??``,onChange:e=>m({leader:{...a,maxTier:e.target.value||void 0}}),className:`rounded-sm border border-border bg-background px-1.5 py-0.5`,"data-testid":`model-tier-leader-ceiling`,children:[(0,Z.jsx)(`option`,{value:``,children:`none`}),o.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})]})]}),(0,Z.jsx)(`p`,{className:`text-[10px] leading-relaxed text-muted-foreground`,children:`A switch invalidates the prompt cache, so a downgrade is refused unless the projected saving over the dwell window covers re-reading the conversation on the new model. A downgrade into a context window the session no longer fits is refused outright.`})]})]})}function zv(){let e=(0,X.useRef)([]);return{setFieldRef:(0,X.useCallback)(t=>n=>{e.current[t]=n},[]),handleKeyDown:(0,X.useCallback)((t,n,r)=>{if(t.key===`ArrowDown`){t.preventDefault();for(let t=n+1;t<e.current.length;t++){let n=e.current[t];if(n&&!n.hasAttribute(`disabled`)&&n.getAttribute(`aria-disabled`)!==`true`){if(n.focus(),n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement){let e=n.value.length;n.setSelectionRange(e,e)}return}}return}if(t.key===`ArrowUp`){t.preventDefault();for(let t=n-1;t>=0;t--){let n=e.current[t];if(n&&!n.hasAttribute(`disabled`)&&n.getAttribute(`aria-disabled`)!==`true`){n.focus(),(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement)&&n.setSelectionRange(n.value.length,n.value.length);return}}return}t.key===`Enter`&&r&&(t.preventDefault(),r())},[])}}function Bv({models:e,onChange:t}){let{t:n}=W(),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)([]),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),h=(0,X.useRef)(void 0),g=(0,X.useRef)(null),_=V(e=>e.wsUrl),v=(0,X.useCallback)(e=>{if(!e.trim()){c([]);return}u(!0);let t=S(_),n=t.on(`provider.models.search_result`,t=>{let n=t.payload;n&&n.query===e.trim()&&(c(n.matches??[]),u(!1))});t.searchProviderModels(e.trim(),8),setTimeout(()=>{n?.(),u(!1)},5e3)},[_]);(0,X.useEffect)(()=>{if(h.current&&clearTimeout(h.current),!a.trim()){c([]);return}return h.current=setTimeout(()=>v(a),250),()=>{h.current&&clearTimeout(h.current)}},[a,v]);let y=(0,X.useCallback)((n,r)=>{if(!n||e.some(e=>e.id===n))return;let a={id:n,name:r?.name??r?.modelId??n,...r?.maxOutput?{maxOutput:r.maxOutput}:{},capabilities:{...r?.contextWindow?{maxContext:r.contextWindow}:{},...r?.capabilities.includes(`tools`)?{tools:!0}:{},...r?.capabilities.includes(`vision`)?{vision:!0}:{},...r?.capabilities.includes(`reasoning`)?{reasoning:!0}:{}}};t([...e,a]),o(``),c([]),i(!1)},[e,t]),b=(0,X.useCallback)(n=>{t(e.filter(e=>e.id!==n))},[e,t]),x=(0,X.useCallback)(()=>{let e=p.trim();e&&(y(e),m(``),f(!1))},[p,y]);return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground block`,children:n(`setup:screen.custom.models`)}),e.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,Z.jsxs)(`div`,{className:K(`group inline-flex items-center gap-1 px-2 py-1 text-xs rounded`,`bg-accent/10 text-accent border border-accent/20`),title:e.name&&e.name!==e.id?`${e.name}\n${e.capabilities?.maxContext?`maxContext: ${e.capabilities.maxContext}`:``}${e.maxOutput?`\nmaxOutput: ${e.maxOutput}`:``}`:void 0,children:[(0,Z.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.name&&e.name!==e.id?e.name:e.id}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>b(e.id),className:`opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive`,children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]},e.id))}),r?(0,Z.jsxs)(`div`,{className:`space-y-2 p-3 rounded border border-border/60 bg-muted/20`,children:[(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(Tt,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(ts,{placeholder:n(`setup:screen.custom.modelSearchPlaceholder`),value:a,onChange:e=>o(e.target.value),className:`text-sm pl-8`,autoFocus:!0}),l&&(0,Z.jsx)(mn,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 animate-spin text-muted-foreground`})]}),s.length>0&&(0,Z.jsx)(`div`,{className:`space-y-1 max-h-40 overflow-y-auto`,children:s.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>y(e.modelId,e),className:K(`w-full flex items-start gap-2 p-2 text-left text-xs rounded transition-colors`,`hover:bg-accent/10 border border-transparent hover:border-accent/30`),children:[(0,Z.jsx)(xn,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-muted-foreground`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`font-medium block truncate`,children:e.name}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground block`,children:[e.providerName,` · `,e.modelId,e.contextWindow?` · ${(e.contextWindow/1e3).toFixed(0)}K ctx`:``,e.maxOutput?` · ${e.maxOutput.toLocaleString()} out`:``]})]})]},`${e.providerId}\u0000${e.modelId}`))}),!l&&a.trim()&&s.length===0&&(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground text-center py-2`,children:[n(`setup:screen.custom.noCatalogMatch`),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{f(!0),setTimeout(()=>g.current?.focus(),50)},className:`ml-1 text-accent underline underline-offset-2 hover:text-accent/80`,children:n(`setup:screen.custom.useCustomId`)})]}),d&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ts,{ref:g,placeholder:n(`setup:screen.custom.customModelIdPlaceholder`),value:p,onChange:e=>m(e.target.value),className:`text-sm flex-1`,onKeyDown:e=>{e.key===`Enter`&&x()}}),(0,Z.jsxs)(Y,{type:`button`,size:`sm`,onClick:x,disabled:!p.trim(),children:[(0,Z.jsx)(xn,{className:`h-3.5 w-3.5 mr-1`}),n(`setup:screen.custom.add`)]})]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-2 pt-1`,children:(0,Z.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{i(!1),o(``),c([]),f(!1),m(``)},className:`text-xs`,children:n(`setup:screen.custom.cancel`)})})]}):(0,Z.jsxs)(Y,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>i(!0),className:`text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5 mr-1`}),n(`setup:screen.custom.addModel`)]}),e.length>0&&(0,Z.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[e.length,` `,e.length===1?n(`setup:screen.custom.modelSingular`):n(`setup:screen.custom.modelPlural`)]})]})}function Vv({maskedKey:e,className:t}){let{t:n}=W(),[r,i]=(0,X.useState)(!1),a=(0,X.useCallback)(()=>{navigator.clipboard.writeText(e).then(()=>{i(!0),setTimeout(()=>i(!1),1500)})},[e]);return(0,Z.jsxs)(`div`,{className:K(`group flex items-center gap-1.5 rounded-md border border-border/50 bg-background/50 px-2 py-1 font-mono text-xs text-muted-foreground`,t),children:[(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate tracking-wide`,children:e}),(0,Z.jsx)(`button`,{type:`button`,onClick:a,className:`shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-all hover:text-foreground group-hover:opacity-100 focus:opacity-100`,title:r?`Copied`:`Copy key preview`,"aria-label":n(`activity:apikeydisplay.copyApiKeyToClipboard`),children:r?(0,Z.jsx)(xn,{className:`h-3 w-3 text-success`}):(0,Z.jsx)(zr,{className:`h-3 w-3`})})]})}var Hv={openrouter:{id:`openrouter`,name:`OpenRouter (Metered)`,family:`openai-compatible`,baseUrl:`https://openrouter.ai/api/v1`,envVars:[`OPENROUTER_API_KEY`],models:[`openai/gpt-4o`,`openai/gpt-4o-mini`,`anthropic/claude-sonnet-4-20250514`,`google/gemini-2.0-flash-001`,`meta-llama/llama-4-scout`,`deepseek/deepseek-chat`],usage:`metered-api`,docsUrl:`https://openrouter.ai/docs/quickstart`,autoDiscover:!0,requestPolicy:`openrouter`,catalog:{description:`All models via one key`,icon:`🔀`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`sk-or-...`}},"kimi-for-coding":{id:`kimi-for-coding`,name:`Kimi Code (Subscription)`,family:`openai-compatible`,baseUrl:`https://api.kimi.com/coding/v1`,envVars:[`KIMI_API_KEY`],models:[`kimi-for-coding`,`kimi-for-coding-highspeed`],quirks:{thinkingParam:`kimi-toggle`},usage:`subscription-interactive`,docsUrl:`https://www.kimi.com/code/docs/en/third-party-tools/other-coding-agents.html`,requestPolicy:`kimi`,catalog:{description:`Personal interactive coding with the Kimi Code subscription key. Generate the API key at kimi.com/code/console.`,icon:`🌙`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`sk-...`}},moonshotai:{id:`moonshotai`,name:`Moonshot Platform (Metered)`,family:`openai-compatible`,baseUrl:`https://api.moonshot.ai/v1`,envVars:[`MOONSHOT_API_KEY`],models:[`kimi-k2.7-code`,`kimi-k2.7-code-highspeed`],quirks:{thinkingParam:`always-on`},usage:`metered-api`,docsUrl:`https://platform.kimi.ai/docs/api/overview`,requestPolicy:`kimi`,catalog:{description:`Metered Moonshot Platform API — pay-as-you-go for automation, background work, and commercial use.`,icon:`🌑`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`sk-...`}},"zai-coding-plan":{id:`zai-coding-plan`,name:`Z.AI Coding Plan (Subscription)`,family:`openai-compatible`,baseUrl:`https://api.z.ai/api/coding/paas/v4`,envVars:[`ZHIPU_API_KEY`],models:[`glm-5.2`,`glm-5-turbo`,`glm-4.7`],quirks:{thinkingParam:`zai-glm`},usage:`subscription-interactive`,docsUrl:`https://docs.z.ai/devpack/quick-start`,requestPolicy:`zai`,catalog:{description:`Use your Z.AI Coding Plan subscription. Generate an API key from your Z.AI dashboard.`,icon:`🔷`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`...`}},zai:{id:`zai`,name:`Z.AI API (Metered)`,family:`openai-compatible`,baseUrl:`https://api.z.ai/api/paas/v4`,envVars:[`ZHIPU_API_KEY`],models:[`glm-4.7`,`glm-5-turbo`,`glm-5.2`],quirks:{thinkingParam:`zai-glm`},usage:`metered-api`,docsUrl:`https://docs.z.ai/guides/overview/quick-start`,requestPolicy:`zai`,catalog:{description:`Pay-as-you-go Z.AI GLM access for automation and commercial use.`,icon:`🔷`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`...`,referral:{code:`JQZ7TPPRA6`,reward:`Limited-time deal for GLM Coding Plan subscription`,url:`https://z.ai/subscribe?ic=JQZ7TPPRA6`}}},minimax:{id:`minimax`,name:`MiniMax Token Plan (Subscription)`,family:`openai-compatible`,baseUrl:`https://api.minimax.io/v1`,envVars:[`MINIMAX_API_KEY`],models:[`MiniMax-M3`,`MiniMax-M2.7`,`MiniMax-M2.5`,`MiniMax-M2`],usage:`subscription-interactive`,docsUrl:`https://platform.minimax.io/docs/api-reference/text-chat-openai`,catalog:{description:`Subscribe to one plan and unlock frontier coding, 1M context, and native multimodality.`,icon:`🔮`,color:`from-destructive/10 to-destructive/5 border-destructive/25 hover:border-destructive/45`,keyPlaceholder:`eyJ...`,referral:{code:`JrA4R9QAEn`,reward:`Friends get 10% off + Builder benefits. Referrers earn 10% cashback + community perks.`,url:`https://platform.minimax.io/subscribe/token-plan?code=JrA4R9QAEn&source=link`}}},mistral:{id:`mistral`,name:`Mistral AI API (Metered)`,family:`openai-compatible`,baseUrl:`https://api.mistral.ai/v1`,envVars:[`MISTRAL_API_KEY`],models:[`mistral-large-latest`,`codestral-latest`,`ministral-8b-latest`],usage:`metered-api`,docsUrl:`https://docs.mistral.ai/`,catalog:{description:`Mistral Large, Codestral, and Ministral — open-weight frontier models.`,icon:`🌬️`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`Vz8d...`}},deepseek:{id:`deepseek`,name:`DeepSeek API (Metered)`,family:`openai-compatible`,baseUrl:`https://api.deepseek.com`,envVars:[`DEEPSEEK_API_KEY`],models:[`deepseek-v4-flash`,`deepseek-v4-pro`],usage:`metered-api`,docsUrl:`https://api-docs.deepseek.com/`,requestPolicy:`deepseek`,catalog:{description:`High-performance reasoning at low cost`,icon:`🐋`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`sk-...`}},groq:{id:`groq`,name:`GroqCloud (Metered)`,family:`openai-compatible`,baseUrl:`https://api.groq.com/openai/v1`,envVars:[`GROQ_API_KEY`],models:[`llama-3.3-70b-versatile`,`llama-3.1-8b-instant`,`mixtral-8x7b-32768`,`gemma2-9b-it`],usage:`metered-api`,docsUrl:`https://console.groq.com/docs/api-reference`,requestPolicy:`groq`,catalog:{description:`Ultra-fast inference via LPU hardware — Llama, Mixtral, Gemma, and Qwen models.`,icon:`⚡`,color:`from-warning/12 to-warning/5 border-warning/30 hover:border-warning/50`,keyPlaceholder:`gsk_...`}},perplexity:{id:`perplexity`,name:`Perplexity Sonar API (Metered)`,family:`openai-compatible`,baseUrl:`https://api.perplexity.ai`,envVars:[`PERPLEXITY_API_KEY`],models:[`sonar-pro`,`sonar`,`sonar-reasoning-pro`,`sonar-reasoning`],usage:`metered-api`,docsUrl:`https://docs.perplexity.ai/`,requestPolicy:`perplexity`,catalog:{description:`Web-augmented chat models with built-in search and citations.`,icon:`🔍`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`pplx-...`}},"alibaba-token-plan":{id:`alibaba-token-plan`,name:`Alibaba Token Plan (Personal Edition)`,family:`openai-compatible`,baseUrl:`https://dashscope.aliyuncs.com/compatible-mode/v1`,envVars:[`ALIBABA_API_KEY`,`DASHSCOPE_API_KEY`],models:[`qwen3.8-max-preview`,`qwen3.7-max`,`qwen3.7-plus`,`qwen3.6-flash`,`glm-5.2`,`deepseek-v4-pro`,`wan2.7-image`,`wan2.7-image-pro`,`happyhorse-1.1-t2v`,`happyhorse-1.1-i2v`,`happyhorse-1.1-r2v`],customModels:{"qwen3.8-max-preview":{capabilities:{tools:!0,vision:!0,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"qwen3.7-max":{capabilities:{tools:!0,vision:!1,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"qwen3.7-plus":{capabilities:{tools:!0,vision:!0,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"qwen3.6-flash":{capabilities:{tools:!0,vision:!0,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"glm-5.2":{capabilities:{tools:!0,vision:!1,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!0,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"deepseek-v4-pro":{capabilities:{tools:!0,vision:!1,reasoning:!0,streaming:!0,systemPrompt:!0,jsonMode:!1,promptCache:!0,parallelTools:!0,cacheControl:`auto`}},"wan2.7-image":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}},"wan2.7-image-pro":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}},"happyhorse-1.1-t2v":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}},"happyhorse-1.1-i2v":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}},"happyhorse-1.1-r2v":{capabilities:{tools:!1,vision:!0,reasoning:!1,streaming:!0,systemPrompt:!1,jsonMode:!1,promptCache:!1,parallelTools:!1,cacheControl:`none`}}},usage:`subscription-interactive`,docsUrl:`https://www.alibabacloud.com/help/en/model-studio/token-plan-personal-overview`,requestPolicy:`alibaba`,catalog:{description:`Monthly Credits subscription for Qwen, DeepSeek, GLM, Wanx image, and HappyHorse video models.`,icon:`☁️`,color:`from-warning/12 to-warning/5 border-warning/30 hover:border-warning/50`,keyPlaceholder:`sk-...`}}};Object.keys(Hv);var Uv=[{id:`openai`,name:`OpenAI`,family:`openai`,envVars:[`OPENAI_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://platform.openai.com/api-keys`,catalog:{description:`GPT, o-series, and Codex models`,icon:`🤖`,color:`from-success/12 to-success/5 border-success/30 hover:border-success/50`,keyPlaceholder:`sk-...`}},{id:`anthropic`,name:`Anthropic`,family:`anthropic`,envVars:[`ANTHROPIC_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://console.anthropic.com/settings/keys`,catalog:{description:`Claude model access`,icon:`🧠`,color:`from-warning/12 to-warning/5 border-warning/30 hover:border-warning/50`,keyPlaceholder:`sk-ant-...`}},{id:`google`,name:`Google`,family:`google`,envVars:[`GOOGLE_GENERATIVE_AI_API_KEY`,`GEMINI_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://aistudio.google.com/apikey`,catalog:{description:`Gemini Pro, Flash, and Nano`,icon:`✨`,color:`from-info/12 to-info/5 border-info/30 hover:border-info/50`,keyPlaceholder:`AIza...`}},{id:`openai-codex`,name:`OpenAI Codex OAuth`,family:`openai-codex`,envVars:[],models:[],usage:`subscription-interactive`,docsUrl:`https://developers.openai.com/codex/`},{id:`anthropic-oauth`,name:`Anthropic OAuth`,family:`anthropic-oauth`,envVars:[],models:[],usage:`subscription-interactive`,docsUrl:`https://docs.anthropic.com/`},{id:`github-copilot`,name:`GitHub Copilot`,family:`github-copilot`,envVars:[],models:[],usage:`subscription-interactive`,docsUrl:`https://docs.github.com/en/copilot`},{id:`opencode-go`,name:`OpenCode Go`,family:`openai-compatible`,baseUrl:`https://opencode.ai/zen/go/v1`,envVars:[`OPENCODE_API_KEY`],models:[],usage:`subscription-interactive`,docsUrl:`https://opencode.ai/go?ref=6VZAER87H4`,catalog:{description:`Global hosted API for 75+ LLM providers — stable access from US, EU, and Singapore`,icon:`🌍`,color:`from-success/12 to-success/5 border-success/30 hover:border-success/50`,keyPlaceholder:`oc-...`,referral:{code:`6VZAER87H4`,reward:`Support the project by signing up with this referral link`,url:`https://opencode.ai/go?ref=6VZAER87H4`}}},{id:`xai`,name:`xAI`,family:`openai-compatible`,baseUrl:`https://api.x.ai/v1`,envVars:[`XAI_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://docs.x.ai/`,autoDiscover:!0,modelDiscoveryPath:`language-models`,modelDiscoveryAuthoritative:!0,requestPolicy:`xai`},{id:`ai-gateway`,name:`Vercel AI Gateway`,family:`openai-compatible`,baseUrl:`https://ai-gateway.vercel.sh/v1`,discoveryOnlyBaseUrl:!0,envVars:[`AI_GATEWAY_API_KEY`],models:[],usage:`metered-api`,docsUrl:`https://vercel.com/docs/ai-gateway`,autoDiscover:!0,catalog:{description:`Every model behind one key — routed by Vercel AI Gateway`,icon:`▲`,color:`from-primary/12 to-primary/5 border-primary/30 hover:border-primary/50`,keyPlaceholder:`vck_...`}}],Wv=[{id:`omniroute`,name:`OmniRoute`,family:`openai-compatible`,baseUrl:`http://localhost:20128/v1`,envVars:[],models:[],usage:`local`,quirks:{stripThinkTags:!0},autoDiscover:!0,local:{noAuth:!0,hint:`WrongStack local gateway · port 20128 · no key · auto-discovers models`}},{id:`ollama`,name:`Ollama`,family:`openai-compatible`,baseUrl:`http://localhost:11434/v1`,envVars:[],models:[],usage:`local`,docsUrl:`https://ollama.com`,local:{noAuth:!0,hint:`ollama.com · port 11434 · no key`}},{id:`vllm`,name:`vLLM`,family:`openai-compatible`,baseUrl:`http://localhost:8000/v1`,envVars:[],models:[],usage:`local`,docsUrl:`https://docs.vllm.ai`,local:{noAuth:!1,hint:`docs.vllm.ai · port 8000 · optional key`}},{id:`lmstudio`,name:`LM Studio`,family:`openai-compatible`,baseUrl:`http://localhost:1234/v1`,envVars:[],models:[],usage:`local`,docsUrl:`https://lmstudio.ai`,local:{noAuth:!1,hint:`lmstudio.ai · port 1234 · optional key`}}],Gv=Object.fromEntries([...Uv,...Object.values(Hv),...Wv].map(e=>[e.id,e]));function Kv(){return Wv.map(e=>{if(!e.baseUrl||!e.local)throw Error(`Local provider definition is incomplete: ${e.id}`);return{id:e.id,label:e.name,defaultBaseUrl:e.baseUrl,noAuth:e.local.noAuth,hint:e.local.hint}})}function qv(){return Object.values(Gv).filter(e=>e.catalog!==void 0).map(e=>({id:e.id,name:e.name,family:e.family,description:e.catalog.description,icon:e.catalog.icon,color:e.catalog.color,keyPlaceholder:e.catalog.keyPlaceholder,...e.docsUrl?{docsUrl:e.docsUrl}:{},...e.catalog.referral?{referral:{...e.catalog.referral}}:{}}))}var Jv=`openai-compatible`,Yv=Kv();function Xv(e){return e===`chatgpt`?(0,Z.jsx)(Wr,{className:`h-5 w-5`}):e===`claude`?(0,Z.jsx)(on,{className:`h-5 w-5`}):e===`copilot`?(0,Z.jsx)(vi,{className:`h-5 w-5`}):(0,Z.jsx)(qt,{className:`h-5 w-5`})}var Zv=[`awaiting_browser`,`awaiting_code`,`exchanging`,`fetching_models`];function Qv({ws:e,savedProviders:t=[]}){let{t:n}=W(),[r,i]=(0,X.useState)({}),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(null);(0,X.useEffect)(()=>{let t=e.on(`auth.oauth.providers`,e=>{e.type===`auth.oauth.providers`&&o(e.payload.providers.map(({id:e,providerId:t,label:n,description:r})=>({id:e,providerId:t,label:n,...r?{description:r}:{}})))}),n=e.on(`auth.oauth.status`,e=>{if(e.type!==`auth.oauth.status`)return;let t=e.payload;i(e=>({...e,[t.kind]:{...t}})),t.phase===`success`?(B.success(t.message??U.t(`settings:oauth.signedInToast`,{provider:t.providerId??t.kind})),u(null),c(``),f(null),m(``)):t.phase===`error`&&B.error(t.message??U.t(`settings:oauth.signInFailed`))});return e.listOAuthProviders(),()=>{n?.(),t?.()}},[e]);let _=(0,X.useCallback)(t=>{i(e=>({...e,[t]:{phase:`exchanging`}})),e.startOAuth(t)},[e]),v=(0,X.useCallback)((t,n)=>{i(e=>({...e,[t]:{phase:`exchanging`}})),e.startOAuth(t,n)},[e]),y=(0,X.useCallback)(t=>{let n=p.trim();n&&(i(e=>({...e,[t]:{phase:`exchanging`}})),e.startOAuth(t,n),f(null),m(``))},[e,p]),b=(0,X.useCallback)(t=>{e.cancelOAuth(t),i(e=>({...e,[t]:{phase:`idle`}})),u(null)},[e]),x=(0,X.useCallback)(t=>{let n=s.trim();n&&(e.submitOAuthCode(t,n),i(e=>({...e,[t]:{...e[t],phase:`exchanging`}})))},[s,e]);return(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 p-3`,children:(0,Z.jsx)(`p`,{className:`text-xs leading-5 text-warning`,children:n(`settings:oauth.termsWarning`)})}),(0,Z.jsx)(`div`,{className:`grid grid-cols-1 gap-2 lg:grid-cols-3`,children:a.map(e=>{let i=r[e.id]??{phase:`idle`},a=Zv.includes(i.phase),o=t.filter(t=>t.id===e.providerId||t.id.startsWith(`${e.providerId}-`)),S=o?.length??0,C=h===e.id;return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/70 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 lg:flex-col lg:items-stretch`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:Xv(e.id)}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,Z.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:e.description??`→ ${e.providerId}`})]})]}),a?(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>b(e.id),className:`shrink-0 lg:w-full`,children:n(`common:action.cancel`)}):(0,Z.jsx)(Y,{size:`sm`,onClick:()=>_(e.id),className:`shrink-0 lg:w-full`,children:n(`settings:oauth.signIn`)})]}),i.phase===`awaiting_browser`&&(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2 border-t pt-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Z.jsx)(mn,{className:`h-4 w-4 animate-spin text-muted-foreground`}),(0,Z.jsx)(`span`,{children:n(`settings:oauth.waitingBrowser`)})]}),i.authorizeUrl&&(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>window.open(i.authorizeUrl,`_blank`,`noopener,noreferrer`),children:[(0,Z.jsx)(Gt,{className:`h-3.5 w-3.5 mr-1`}),n(`settings:oauth.openSignIn`)]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`button`,{type:`button`,className:`text-xs text-muted-foreground underline`,onClick:()=>u(l===e.id?null:e.id),children:i.bound===!1?n(`settings:oauth.pasteLoopbackBusy`):n(`settings:oauth.pasteCantReach`)}),l===e.id&&(0,Z.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Z.jsx)(ts,{placeholder:n(`activity:oauth.httpLocalhostCallbackCode`),value:s,onChange:e=>c(e.target.value),className:`font-mono text-xs`,onKeyDown:t=>{t.key===`Enter`&&x(e.id)}}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>x(e.id),disabled:!s.trim(),children:n(`settings:oauth.submit`)})]})]})]}),i.phase===`awaiting_code`&&(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2 border-t pt-3`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`settings:oauth.enterCode`)}),(0,Z.jsx)(`div`,{className:`font-mono text-2xl font-bold tracking-widest`,children:i.userCode??`…`}),i.verificationUri&&(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>window.open(i.verificationUri,`_blank`,`noopener,noreferrer`),children:[(0,Z.jsx)(Gt,{className:`h-3.5 w-3.5 mr-1`}),n(`settings:oauth.openVerification`)]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(mn,{className:`h-3.5 w-3.5 animate-spin`}),(0,Z.jsx)(`span`,{children:n(`settings:oauth.waitingCode`)})]})]}),(i.phase===`exchanging`||i.phase===`fetching_models`)&&(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t pt-3 text-sm`,children:[(0,Z.jsx)(mn,{className:`h-4 w-4 animate-spin text-muted-foreground`}),(0,Z.jsx)(`span`,{children:i.phase===`exchanging`?n(`settings:oauth.exchanging`):n(`settings:oauth.fetchingModels`)})]}),i.phase===`success`&&(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t pt-3 text-sm text-success`,children:[(0,Z.jsx)(Bn,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:i.message??n(`settings:oauth.signedIn`)})]}),i.phase===`error`&&i.message&&(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t pt-3 text-sm text-destructive`,children:[(0,Z.jsx)(qr,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:i.message})]}),S>0&&!a&&(0,Z.jsxs)(`div`,{className:`mt-3 border-t pt-3`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>g(C?null:e.id),className:`flex w-full items-center justify-between text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Z.jsx)(qt,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{children:n(`settings:oauth.accountCount`,{count:S})})]}),(0,Z.jsx)(`span`,{className:`text-[10px]`,children:C?`▲`:`▼`})]}),C&&o&&(0,Z.jsxs)(`div`,{className:`mt-2 space-y-1.5`,children:[o.map(t=>(0,Z.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border/60 bg-muted/20 px-2.5 py-1.5`,children:[(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs`,children:t.id}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[t.hasActiveKey?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-success`,children:[(0,Z.jsx)(Bn,{className:`h-3 w-3`}),n(`settings:oauth.active`)]}):(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:n(`settings:oauth.inactive`)}),(0,Z.jsxs)(Y,{size:`sm`,variant:`ghost`,onClick:()=>v(e.id,t.id),className:`h-6 px-1.5 text-[11px]`,title:n(`settings:oauth.retryLogin`),children:[(0,Z.jsx)(Yn,{className:`h-3 w-3 mr-0.5`}),n(`settings:oauth.retry`)]})]})]},t.id)),(0,Z.jsx)(`div`,{className:`pt-1`,children:d===e.id?(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(ts,{autoFocus:!0,placeholder:n(`settings:oauth.aliasPlaceholder`,{default:`${e.providerId}-2`}),value:p,onChange:e=>m(e.target.value),className:`text-xs font-mono`,onKeyDown:t=>{t.key===`Enter`&&y(e.id)}}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>y(e.id),disabled:!p.trim(),children:n(`settings:oauth.signIn`)}),(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>{f(null),m(``)},children:n(`common:action.cancel`)})]}):(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>f(e.id),className:`w-full text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5 mr-1`}),n(`settings:oauth.newAccount`)]})})]})]}),S===0&&!a&&(0,Z.jsx)(`div`,{className:`mt-3 border-t pt-3`,children:d===e.id?(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(ts,{autoFocus:!0,placeholder:n(`settings:oauth.aliasPlaceholder`,{default:`${e.providerId}-2`}),value:p,onChange:e=>m(e.target.value),className:`text-xs font-mono`,onKeyDown:t=>{t.key===`Enter`&&y(e.id)}}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>y(e.id),disabled:!p.trim(),children:n(`settings:oauth.signIn`)}),(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>{f(null),m(``)},children:n(`common:action.cancel`)})]}):(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>f(e.id),className:`w-full text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5 mr-1`}),n(`settings:oauth.newAccount`)]})})]},e.id)})})]})}function $v({open:e,providerId:t,modelCount:n,onConfirm:r,onCancel:i}){let a=(0,X.useRef)(null),{t:o}=W();return(0,X.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,Z.jsx)(es,{open:e,onOpenChange:e=>{e||i()},children:(0,Z.jsxs)(Zo,{className:`sm:max-w-md border-warning/50`,ref:a,tabIndex:-1,"data-clear-allowlist-dialog":!0,children:[(0,Z.jsxs)(Yo,{children:[(0,Z.jsxs)(Qo,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(dr,{className:`h-5 w-5 text-warning`}),o(`settings:allowlist.title`)]}),(0,Z.jsx)($o,{children:o(`settings:allowlist.body`,{count:n,provider:t})})]}),(0,Z.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,Z.jsxs)(Xo,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:i,title:o(`settings:allowlist.keepTitle`),"data-action":`cancel`,children:[o(`common:action.cancel`),` `,(0,Z.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`Esc`})]}),(0,Z.jsxs)(Y,{variant:`destructive`,size:`sm`,onClick:r,title:o(`settings:allowlist.clearTitle`),"data-action":`confirm`,children:[o(`settings:allowlist.clear`),` `,(0,Z.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`↵`})]})]})]})})}function ey({ws:e,onSelect:t,onClose:n}){let{t:r}=W(),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)([]),[c,l]=(0,X.useState)(!1),u=(0,X.useRef)(null),d=(0,X.useRef)(``);(0,X.useEffect)(()=>e.on(`provider.models.search_result`,e=>{if(e.type!==`provider.models.search_result`)return;let t=e.payload;(t.query===void 0||t.query===d.current)&&(s(t.matches??[]),l(!1))}),[e]);let f=(0,X.useCallback)(t=>{if(!t.trim()){s([]),d.current=``;return}d.current=t,l(!0),e.searchProviderModels(t,8)},[e]);(0,X.useEffect)(()=>(u.current&&clearTimeout(u.current),u.current=setTimeout(()=>f(i),300),()=>{u.current&&clearTimeout(u.current)}),[i,f]);let p=(0,X.useCallback)(e=>{let n={name:e.name,...e.description?{description:e.description}:{},...e.releaseDate?{release_date:e.releaseDate}:{},...e.contextWindow||e.maxOutput?{limit:{...e.contextWindow?{context:e.contextWindow}:{},...e.maxOutput?{output:e.maxOutput}:{}}}:{},...e.inputCost||e.outputCost?{cost:{...e.inputCost?{input:e.inputCost}:{},...e.outputCost?{output:e.outputCost}:{}}}:{},...e.capabilities.length>0?{tool_call:e.capabilities.includes(`tools`),reasoning:e.capabilities.includes(`reasoning`),...e.capabilities.includes(`vision`)?{modalities:{input:[`text`,`image`]}}:{}}:{}};t(e.modelId,n)},[t]);return(0,Z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/50`,onClick:n,"aria-label":r(`common:action.close`)}),(0,Z.jsxs)(`div`,{className:`relative max-h-[80vh] w-full max-w-xl overflow-y-auto rounded-lg border border-border bg-background p-4 shadow-lg`,children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`settings:providerModels.catalogSearchTitle`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-foreground`,children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`relative mb-3`,children:[(0,Z.jsx)(Tt,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground/60`}),(0,Z.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:r(`settings:providerModels.catalogSearchPlaceholder`),className:`h-10 w-full rounded-md border border-border bg-background pl-9 pr-3 text-sm focus:outline-none focus:ring-1 focus:ring-ring`})]}),c?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Z.jsx)(mn,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):o.length>0?(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:o.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>p(e),className:`block w-full rounded-md border border-border/60 p-2.5 text-left transition-colors hover:border-primary/40 hover:bg-primary/5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-sm font-medium text-foreground`,children:e.modelId}),e.name!==e.modelId&&(0,Z.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:e.name})]}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground`,children:e.providerName})]}),e.description&&(0,Z.jsx)(`p`,{className:`mt-0.5 line-clamp-2 text-xs text-muted-foreground`,children:e.description}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap gap-1.5`,children:[e.contextWindow?(0,Z.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:e.contextWindow>=1e6?`${(e.contextWindow/1e6).toFixed(1)}M ctx`:`${Math.round(e.contextWindow/1e3)}K ctx`}):null,e.capabilities.map(e=>(0,Z.jsx)(`span`,{className:`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:e},e))]})]},`${e.providerId}:${e.modelId}`))}):i.trim()?(0,Z.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:r(`settings:providerModels.noResults`)}):(0,Z.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:r(`settings:providerModels.typeToSearch`)})]})]})}var ty=new Set([`__proto__`,`constructor`,`prototype`,`__defineGetter__`,`__defineSetter__`,`__lookupGetter__`,`__lookupSetter__`]);`document`in globalThis&&fr({jitless:!0});var ny=[`text`,`image`,`audio`,`video`,`pdf`],ry=[`none`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`],iy=Ui().int().nonnegative(),ay=Ui().finite(),oy=an({context:iy.optional(),output:iy.optional(),input:iy.optional()}),sy=an({input:ay.optional(),output:ay.optional(),cache_read:ay.optional(),cache_write:ay.optional(),cache_write_5m:ay.optional(),cache_write_1h:ay.optional(),context_over_200k:ay.optional(),reasoning:ay.optional(),input_audio:ay.optional(),output_audio:ay.optional()}),cy=an({input:Wn(cr().min(1)).optional(),output:Wn(cr().min(1)).optional()}),ly=nr([an({type:Rt(`toggle`)}),an({type:Rt(`effort`),values:Wn(Ut(ry)).optional()}),an({type:Rt(`budget_tokens`),min:Ui().optional(),max:Ui().optional()})]),uy=e=>({message:`${e} id is a forbidden prototype-pollution key`}),dy=an({id:cr().min(1).refine(e=>!ty.has(e),uy(`Model`)),name:cr().min(1),description:cr().optional(),family:cr().optional(),provider:an({npm:cr().optional(),api:cr().optional()}).optional(),attachment:Zn().optional(),reasoning:Zn().optional(),reasoning_options:nr([ly,Wn(ly)]).optional(),interleaved:nr([Zn(),an({field:cr().optional()})]).optional(),tool_call:Zn().optional(),structured_output:Zn().optional(),temperature:Zn().optional(),knowledge:cr().optional(),release_date:cr().optional(),last_updated:cr().optional(),open_weights:Zn().optional(),modalities:cy.optional(),cost:sy.optional(),limit:oy.optional(),status:cr().optional(),experimental:Zn().optional()}),fy=an({id:cr().min(1).refine(e=>!ty.has(e),uy(`Provider`)),name:cr().min(1),env:Wn(cr()).optional(),npm:cr().optional(),api:cr().optional(),doc:cr().optional(),models:Qt(cr(),dy)});Qt(cr(),fy);function py(e,t){let n=t.limit,r=t.cost,i=t.modalities;return{id:e,name:t.name??``,description:t.description??``,family:t.family??``,limitContext:n?.context==null?``:String(n.context),limitOutput:n?.output==null?``:String(n.output),limitInput:n?.input==null?``:String(n.input),costInput:r?.input==null?``:String(r.input),costOutput:r?.output==null?``:String(r.output),inputModalities:Array.isArray(i?.input)?i.input:[],outputModalities:Array.isArray(i?.output)?i.output:[],toolCall:t.tool_call===!0,reasoning:t.reasoning===!0,temperature:t.temperature===!0,attachment:t.attachment===!0,structuredOutput:t.structured_output===!0,openWeights:t.open_weights===!0,releaseDate:t.release_date??``,lastUpdated:t.last_updated??``,knowledge:t.knowledge??``}}function my(e,t){let n={...t};e.name&&(n.name=e.name),e.description&&(n.description=e.description),e.family&&(n.family=e.family),e.knowledge&&(n.knowledge=e.knowledge);let r={};if(e.limitContext){let t=Number(e.limitContext);Number.isFinite(t)&&t>=0&&(r.context=t)}if(e.limitOutput){let t=Number(e.limitOutput);Number.isFinite(t)&&t>=0&&(r.output=t)}if(e.limitInput){let t=Number(e.limitInput);Number.isFinite(t)&&t>=0&&(r.input=t)}Object.keys(r).length>0&&(n.limit={...t.limit??{},...r});let i={};if(e.costInput){let t=Number(e.costInput);Number.isFinite(t)&&t>=0&&(i.input=t)}if(e.costOutput){let t=Number(e.costOutput);Number.isFinite(t)&&t>=0&&(i.output=t)}Object.keys(i).length>0&&(n.cost={...t.cost??{},...i});let a={};e.inputModalities.length>0&&(a.input=e.inputModalities),e.outputModalities.length>0&&(a.output=e.outputModalities),Object.keys(a).length>0&&(n.modalities={...t.modalities??{},...a});for(let[r,i]of[[`toolCall`,`tool_call`],[`reasoning`,`reasoning`],[`temperature`,`temperature`],[`attachment`,`attachment`],[`structuredOutput`,`structured_output`],[`openWeights`,`open_weights`]]){let a=t[i]===!0;e[r]!==a&&(n[i]=e[r])}return e.releaseDate&&(n.release_date=e.releaseDate),e.lastUpdated&&(n.last_updated=e.lastUpdated),n}var hy=[{key:`toolCall`,labelKey:`settings:modelSchema.capToolCall`},{key:`reasoning`,labelKey:`settings:modelSchema.capReasoning`},{key:`temperature`,labelKey:`settings:modelSchema.capTemperature`},{key:`attachment`,labelKey:`settings:modelSchema.capAttachment`},{key:`structuredOutput`,labelKey:`settings:modelSchema.capStructuredOutput`},{key:`openWeights`,labelKey:`settings:modelSchema.capOpenWeights`}];function gy({providerId:e,modelId:t,initialModelsDev:n,onSave:r,onCancel:i}){let{t:a}=W(),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(()=>py(t,n)),[u,d]=(0,X.useState)([]),[f,p]=(0,X.useState)(JSON.stringify({...n,...t?{id:t}:{}},null,2)),[m,h]=(0,X.useState)(null),g=(0,X.useCallback)((e,t)=>{l(n=>({...n,[e]:t}))},[]),_=(0,X.useCallback)((e,t)=>{l(n=>{let r=n[e];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),v=(0,X.useCallback)(()=>{let e=my(c,n),i=dy.safeParse({...e,id:c.id||t});if(!i.success){d(i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`));return}d([]),r(c.id||t,e)},[c,n,t,r]),y=(0,X.useCallback)(()=>{try{let e=JSON.parse(f),n=dy.safeParse({...e,id:t||e.id});if(!n.success){h(n.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `));return}let{id:i,...a}=n.data;h(null),r(t||n.data.id,a)}catch(e){h(e instanceof Error?e.message:String(e))}},[f,t,r]),b=`h-8 w-full rounded-md border border-border bg-background px-2.5 text-sm focus:outline-none focus:ring-1 focus:ring-ring`,x=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-muted-foreground`;return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-1 border-b border-border/50`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>s(!1),className:K(`border-b-2 px-3 py-1 text-xs font-medium transition-colors`,o?`border-transparent text-muted-foreground hover:text-foreground`:`border-primary text-primary`),children:a(`settings:providerModels.tabForm`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:K(`border-b-2 px-3 py-1 text-xs font-medium transition-colors`,o?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`),children:a(`settings:providerModels.tabRawJson`)})]}),o?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),rows:16,className:`w-full rounded-md border border-border bg-muted/20 p-2 font-mono text-xs`,spellCheck:!1}),m&&(0,Z.jsx)(`p`,{className:`text-xs text-destructive`,children:m})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionIdentity`)}),!t&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-id`,children:`ID`}),(0,Z.jsx)(`input`,{id:`mse-id`,className:b,value:c.id,onChange:e=>g(`id`,e.target.value),placeholder:a(`activity:modelSchema.modelId`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-name`,children:a(`settings:providerModels.fieldName`)}),(0,Z.jsx)(`input`,{id:`mse-name`,className:b,value:c.name,onChange:e=>g(`name`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-desc`,children:a(`settings:providerModels.fieldDescription`)}),(0,Z.jsx)(`input`,{id:`mse-desc`,className:b,value:c.description,onChange:e=>g(`description`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-family`,children:a(`settings:providerModels.fieldFamily`)}),(0,Z.jsx)(`input`,{id:`mse-family`,className:b,value:c.family,onChange:e=>g(`family`,e.target.value)})]})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionLimits`)}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-ctx`,children:a(`settings:providerModels.fieldContext`)}),(0,Z.jsx)(`input`,{id:`mse-ctx`,type:`number`,className:b,value:c.limitContext,onChange:e=>g(`limitContext`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-out`,children:a(`settings:providerModels.fieldOutput`)}),(0,Z.jsx)(`input`,{id:`mse-out`,type:`number`,className:b,value:c.limitOutput,onChange:e=>g(`limitOutput`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-inlim`,children:a(`settings:providerModels.fieldInputLimit`)}),(0,Z.jsx)(`input`,{id:`mse-inlim`,type:`number`,className:b,value:c.limitInput,onChange:e=>g(`limitInput`,e.target.value)})]})]})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionPricing`)}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-costin`,children:a(`settings:providerModels.fieldCostInput`)}),(0,Z.jsx)(`input`,{id:`mse-costin`,type:`number`,step:`0.01`,className:b,value:c.costInput,onChange:e=>g(`costInput`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-costout`,children:a(`settings:providerModels.fieldCostOutput`)}),(0,Z.jsx)(`input`,{id:`mse-costout`,type:`number`,step:`0.01`,className:b,value:c.costOutput,onChange:e=>g(`costOutput`,e.target.value)})]})]})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionModalities`)}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:x,children:a(`settings:providerModels.fieldInputModalities`)}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:ny.map(e=>{let t=c.inputModalities.includes(e);return(0,Z.jsx)(`button`,{type:`button`,onClick:()=>_(`inputModalities`,e),className:K(`rounded-md border px-2 py-1 text-xs transition-colors`,t?`border-primary bg-primary/10 text-primary`:`border-border text-muted-foreground hover:border-primary/30`),children:e},`in-mod-${e}`)})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:x,children:a(`settings:providerModels.fieldOutputModalities`)}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:ny.map(e=>{let t=c.outputModalities.includes(e);return(0,Z.jsx)(`button`,{type:`button`,onClick:()=>_(`outputModalities`,e),className:K(`rounded-md border px-2 py-1 text-xs transition-colors`,t?`border-primary bg-primary/10 text-primary`:`border-border text-muted-foreground hover:border-primary/30`),children:e},`out-mod-${e}`)})})]})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionCapabilities`)}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:hy.map(({key:e,labelKey:t})=>(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 rounded border-border`,checked:c[e],onChange:t=>g(e,t.target.checked)}),a(t)]},String(e)))})]}),(0,Z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Z.jsx)(`legend`,{className:`text-xs font-semibold text-foreground`,children:a(`settings:providerModels.sectionDates`)}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-release`,children:a(`settings:providerModels.fieldReleaseDate`)}),(0,Z.jsx)(`input`,{id:`mse-release`,type:`date`,className:b,value:c.releaseDate,onChange:e=>g(`releaseDate`,e.target.value)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:x,htmlFor:`mse-updated`,children:a(`settings:providerModels.fieldLastUpdated`)}),(0,Z.jsx)(`input`,{id:`mse-updated`,type:`date`,className:b,value:c.lastUpdated,onChange:e=>g(`lastUpdated`,e.target.value)})]})]})]}),u.length>0&&(0,Z.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 p-2`,children:(0,Z.jsx)(`ul`,{className:`space-y-0.5 text-xs text-destructive`,children:u.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))})})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-border/50 pt-3`,children:[(0,Z.jsxs)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:i,className:`h-8 gap-1.5 text-xs`,children:[(0,Z.jsx)(hn,{className:`h-3.5 w-3.5`}),a(`common:action.cancel`)]}),(0,Z.jsxs)(Y,{type:`button`,size:`sm`,onClick:o?y:v,className:`h-8 gap-1.5 text-xs`,children:[(0,Z.jsx)(xn,{className:`h-3.5 w-3.5`}),a(`common:action.save`)]})]})]})}function _y(e,t){return e.map(e=>{let n=t?.[e],r=n?.modelsDev,i=!!(n&&(n.name||n.maxOutput||n.capabilities||r));return{modelId:e,name:r?.name??n?.name??e,modelsDev:r,maxOutput:n?.maxOutput??r?.limit?.output,capabilities:n?.capabilities,source:i?`overridden`:`catalog`}})}function vy(e){let t=e?.limit?.context;if(typeof t==`number`&&t>0)return t>=1e6?`${(t/1e6).toFixed(1)}M`:`${Math.round(t/1e3)}K`}function yy(e){let t=e?.cost,n=e=>typeof e==`number`&&e>=0?`$${e}`:void 0;return{input:n(t?.input),output:n(t?.output)}}function by(e){let t=e?.modalities;return{input:Array.isArray(t?.input)?t.input:[],output:Array.isArray(t?.output)?t.output:[]}}var xy={text:Vn,image:or,audio:yr,video:Na,pdf:Vn};function Sy({providerId:e,models:t,customModels:n,ws:r,pickedModelId:i,onPickModel:a}){let{t:o}=W(),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),h=(0,X.useMemo)(()=>_y(t,n),[t,n]),g=(0,X.useMemo)(()=>{let e=p.trim().toLowerCase();return e?h.filter(t=>t.modelId.toLowerCase().includes(e)||(t.name?.toLowerCase().includes(e)??!1)):h},[h,p]),_=(0,X.useCallback)(t=>{r.removeCustomModel(e,t),B.success(o(`settings:providerModels.modelRemoved`,{model:t}))},[r,e,o]),v=(0,X.useCallback)((t,n)=>{r.setCustomModel(e,t,{modelsDev:n}),c(null),B.success(o(`settings:providerModels.modelSaved`,{model:t}))},[r,e,o]),y=(0,X.useCallback)((t,n)=>{r.setCustomModel(e,t,{modelsDev:n}),u(!1),B.success(o(`settings:providerModels.modelAdded`,{model:t}))},[r,e,o]);return(0,Z.jsxs)(`div`,{className:`space-y-3`,"data-model-list-editor":e,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:()=>u(!0),className:`h-8 gap-1.5 text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),o(`settings:providerModels.addFromCatalog`)]}),(0,Z.jsxs)(Y,{variant:`ghost`,size:`sm`,onClick:()=>f(!0),className:`h-8 gap-1.5 text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),o(`settings:providerModels.addCustom`)]})]}),h.length>0&&(0,Z.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border/70`,children:[h.length>8&&(0,Z.jsxs)(`div`,{className:`relative border-b border-border/40 bg-muted/10`,children:[(0,Z.jsx)(Tt,{className:`pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground/60`}),(0,Z.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:o(`settings:providerModels.filterPlaceholder`),"aria-label":o(`settings:providerModels.filterPlaceholder`),className:`h-8 w-full bg-transparent pl-9 pr-3 text-xs text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-ring`})]}),(0,Z.jsx)(`div`,{className:`max-h-80 overflow-y-auto`,children:(0,Z.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Z.jsx)(`thead`,{children:(0,Z.jsxs)(`tr`,{className:`border-b border-border/70 bg-muted/30 text-left text-[11px] uppercase tracking-wide text-muted-foreground`,children:[(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colModel`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colContext`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colOutput`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colCost`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colModalities`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colCaps`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:o(`settings:providerModels.colSource`)}),(0,Z.jsx)(`th`,{className:`px-3 py-2`,"aria-label":o(`settings:providerModels.colActions`)})]})}),(0,Z.jsx)(`tbody`,{children:g.map(t=>{let n=vy(t.modelsDev),r=t.maxOutput??t.modelsDev?.limit?.output,l=typeof r==`number`?r.toLocaleString():void 0,u=yy(t.modelsDev),d=by(t.modelsDev),f=t.capabilities,p=s===t.modelId;return(0,Z.jsxs)(X.Fragment,{children:[(0,Z.jsxs)(`tr`,{className:`border-b border-border/40 transition-colors hover:bg-muted/20`,children:[(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-xs font-medium text-foreground`,children:t.modelId}),t.name&&t.name!==t.modelId&&(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:t.name})]})}),(0,Z.jsx)(`td`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:n?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Z.jsx)(la,{className:`h-3 w-3`}),n]}):(0,Z.jsx)(`span`,{className:`text-muted-foreground/40`,children:`—`})}),(0,Z.jsx)(`td`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:l?(0,Z.jsx)(`span`,{children:l}):(0,Z.jsx)(`span`,{className:`text-muted-foreground/40`,children:`—`})}),(0,Z.jsx)(`td`,{className:`px-3 py-2 text-xs`,children:u.input||u.output?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Z.jsx)(en,{className:`h-3 w-3`}),u.input&&u.output?`${u.input}/${u.output}`:u.input??u.output]}):(0,Z.jsx)(`span`,{className:`text-muted-foreground/40`,children:`—`})}),(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[d.input.map(e=>{let t=xy[e]??Vn;return(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-primary/10 px-1 py-0.5 text-[10px] text-primary`,title:`input: ${e}`,children:[(0,Z.jsx)(t,{className:`h-2.5 w-2.5`}),e]},`in-${e}`)}),d.output.map(e=>(0,Z.jsx)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-secondary/20 px-1 py-0.5 text-[10px] text-secondary-foreground`,title:`output: ${e}`,children:e},`out-${e}`))]})}),(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsxs)(`div`,{className:`flex gap-1`,children:[f?.tools&&(0,Z.jsx)(_n,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-label":o(`activity:modelListEditor.tools`)}),f?.reasoning&&(0,Z.jsx)(Jn,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-label":o(`activity:modelListEditor.reasoning`)}),f?.vision&&(0,Z.jsx)(ja,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-label":o(`activity:modelListEditor.vision`)})]})}),(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsx)(`span`,{className:K(`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium`,t.source===`custom`&&`bg-warning/10 text-warning`,t.source===`catalog`&&`bg-info/10 text-info`,t.source===`overridden`&&`bg-primary/10 text-primary`),children:t.source})}),(0,Z.jsx)(`td`,{className:`px-3 py-2`,children:(0,Z.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[a&&(t.modelId===i?(0,Z.jsx)(`span`,{className:`inline-flex items-center rounded p-1 text-primary`,title:o(`settings:providerModels.usingModel`,{model:t.modelId}),role:`img`,"aria-label":o(`settings:providerModels.usingModel`,{model:t.modelId}),children:(0,Z.jsx)(xn,{className:`h-3.5 w-3.5`})}):(0,Z.jsx)(`button`,{type:`button`,onClick:()=>a(e,t.modelId),className:`rounded p-1 text-muted-foreground transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":o(`settings:providerModels.useModel`,{model:t.modelId}),title:o(`settings:providerModels.useModel`,{model:t.modelId}),children:(0,Z.jsx)(xn,{className:`h-3.5 w-3.5`})})),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>c(p?null:t.modelId),className:`rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,"aria-label":o(`settings:providerModels.editModel`,{model:t.modelId}),children:(0,Z.jsx)(hr,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>_(t.modelId),className:`rounded p-1 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive`,"aria-label":o(`settings:providerModels.removeModel`,{model:t.modelId}),children:(0,Z.jsx)(jn,{className:`h-3.5 w-3.5`})})]})})]}),p&&(0,Z.jsx)(`tr`,{className:`border-b border-border/40 bg-muted/10`,children:(0,Z.jsx)(`td`,{colSpan:8,className:`p-3`,children:(0,Z.jsx)(gy,{providerId:e,modelId:t.modelId,initialModelsDev:t.modelsDev??{},onSave:v,onCancel:()=>c(null)})})},`${t.modelId}-edit`)]},t.modelId)})})]})})]}),h.length===0&&(0,Z.jsx)(`div`,{className:`rounded-lg border border-dashed border-border/50 p-8 text-center`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o(`settings:providerModels.emptyState`)})}),l&&(0,Z.jsx)(ey,{ws:r,onSelect:y,onClose:()=>u(!1)}),d&&(0,Z.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/50`,onClick:()=>f(!1),"aria-label":o(`common:action.close`)}),(0,Z.jsxs)(`div`,{className:`relative max-h-[80vh] w-full max-w-2xl overflow-y-auto rounded-lg border border-border bg-background p-4 shadow-lg`,children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:o(`settings:providerModels.addCustomTitle`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>f(!1),className:`text-muted-foreground hover:text-foreground`,children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),(0,Z.jsx)(gy,{providerId:e,modelId:``,initialModelsDev:{},onSave:v,onCancel:()=>f(!1)})]})]})]})}function Cy(){return{inFlight:!1,last:null,picked:null}}function wy(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 Ty(e){if(e.inFlight)return{text:`Checking model endpoint...`,tone:`muted`};let t=e.last;if(!t)return{text:`Saved model list shown`,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:`Server returned ${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:`Provider is no longer saved`,tone:`error`};case`no_base_url`:return{text:`No model endpoint configured`,tone:`warning`}}}function Ey(e){return(e?.length??0)>0}function Dy(e,t){return`Allowlist cleared for ${e} — ${t} model${t===1?``:`s`} removed`}function Oy(e){return e.length>0}function ky(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 Ay=3e3;function jy({providerId:e,savedPickedModelId:t,savedModels:n,savedCustomModels:r,ws:i,onPickModel:a,onClearModels:o,onUndoClear:s}){let[c,l]=(0,X.useState)(()=>Cy()),{t:u}=W(),[d,f]=(0,X.useState)(!1);(0,X.useEffect)(()=>i.on(`provider.probe`,t=>{t.type===`provider.probe`&&t.payload.providerId===e&&l(e=>({...e,inFlight:!1,last:wy(t.payload)}))}),[i,e]);let p=(0,X.useCallback)(()=>{l(e=>({...e,inFlight:!0})),i.probeProvider(e,Ay)},[i,e]),m=(0,X.useCallback)((e,t)=>{l(e=>({...e,picked:t})),a?.(e,t)},[a]),h=(0,X.useCallback)(()=>{f(!0)},[]),g=(0,X.useCallback)(()=>{f(!1)},[]),_=(0,X.useCallback)(()=>{f(!1);let t=n?[...n]:[];l(e=>({...e,picked:null,last:null})),o?o(e):i.clearProviderModels(e),Oy(t)&&B.undoable(Dy(e,t.length),()=>{let n=ky({providerId:e,previousModels:t,onUndoClear:s});switch(n.kind){case`skip`:return;case`callback`:s?.(n.providerId,n.previousModels);return;case`ws-default`:i.undoProviderClear(n.providerId,n.previousModels);return}})},[o,s,i,e,n]),v=(0,X.useMemo)(()=>c.picked??t??n?.[0]??``,[c.picked,t,n]),y=(0,X.useMemo)(()=>Ty(c),[c]),b=(0,X.useMemo)(()=>Ey(n),[n]);return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/75 p-3 shadow-sm shadow-black/[0.02]`,"data-provider-models-panel":e,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,Z.jsx)(Fn,{className:`h-3.5 w-3.5`}),u(`activity:providerModels.allowlistTitle`)]}),n&&n.length>0&&(0,Z.jsx)(`span`,{className:`rounded-full border border-border/70 bg-muted/40 px-2 py-0.5 text-[11px] text-muted-foreground`,children:u(`activity:providerModels.modelCount`,{count:n.length})})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:u(`activity:providerModels.using`)}),v?(0,Z.jsx)(`span`,{className:`max-w-full break-words rounded-md bg-primary/10 px-2 py-0.5 font-mono text-xs text-primary`,children:v}):(0,Z.jsx)(`span`,{className:`text-xs italic text-muted-foreground`,children:u(`activity:providerModels.noModelPicked`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 sm:justify-end`,children:[(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,onClick:p,disabled:c.inFlight,"aria-label":u(`activity:providerModels.refreshAria`,{provider:e}),className:`h-8 px-2 text-xs`,children:[c.inFlight?(0,Z.jsx)(mn,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Yn,{className:`h-3.5 w-3.5`}),c.inFlight?u(`activity:providerModels.probing`):u(`activity:providerModels.refresh`)]}),b&&(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:h,"aria-label":u(`activity:providerModels.clearAllowlistAria`,{provider:e}),"data-action":`clear-models`,className:`h-8 px-2 text-xs`,children:u(`activity:providerModels.clearAllowlist`)})]})]}),(0,Z.jsx)(My,{formatted:y}),(0,Z.jsx)(`div`,{className:`mt-3`,children:(0,Z.jsx)(Sy,{providerId:e,models:n??[],customModels:r,ws:i,pickedModelId:v??void 0,onPickModel:m})}),(0,Z.jsx)($v,{open:d,providerId:e,modelCount:n?.length??0,onConfirm:_,onCancel:g})]})}function My({formatted:e}){let t=e.tone===`success`?`text-success`:e.tone===`warning`?`text-warning`:e.tone===`error`?`text-destructive`:`text-muted-foreground`,n=e.tone===`success`?`bg-success`:e.tone===`warning`?`bg-warning`:e.tone===`error`?`bg-destructive`:`bg-muted-foreground/60`;return(0,Z.jsxs)(`p`,{className:`mt-2 flex items-center gap-1.5 text-xs ${t}`,"data-probe-tone":e.tone,children:[(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${n}`}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate`,children:e.text})]})}var Ny=[`anthropic`,`openai`,`google`,`openai-compatible`];function Py({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:f,onPickProviderModel:p,ws:m,catalogQuery:h,setCatalogQuery:g}){let{t:_}=W(),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(``),[A,j]=(0,X.useState)(`openai-compatible`),[M,N]=(0,X.useState)(``),[P,F]=(0,X.useState)(``),[I,L]=(0,X.useState)([]),ee=zv(),R=zv(),z=(0,X.useCallback)(e=>{b.trim()&&S.trim()&&(c(e,b.trim(),S.trim()),x(``),C(``),y(null))},[c,b,S]),te=(0,X.useCallback)(()=>{O.trim()&&(d(O.trim(),A,M||void 0,P||void 0,I.length>0?I.map(e=>e.id):void 0,I.length>0?Object.fromEntries(I.filter(e=>e.name||e.maxOutput||e.capabilities&&Object.keys(e.capabilities).length>0).map(e=>[e.id,{...e.name&&e.name!==e.id?{name:e.name}:{},...e.maxOutput?{maxOutput:e.maxOutput}:{},...e.capabilities&&Object.keys(e.capabilities).length>0?{capabilities:e.capabilities}:{}}])):void 0),k(``),j(`openai-compatible`),N(``),F(``),L([]),D(!1))},[d,O,A,M,P,I]),ne=(0,X.useCallback)(e=>{k(e.id),j(Jv),N(e.defaultBaseUrl),e.noAuth&&F(``),L([])},[]),[re,ie]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(``),[se,ce]=(0,X.useState)(!1),[le,ue]=(0,X.useState)({}),de=(0,X.useMemo)(()=>new Set(r.map(e=>e.id)),[r]),fe=(0,X.useMemo)(()=>({keys:r.reduce((e,t)=>e+t.apiKeys.length,0),activeKeys:r.reduce((e,t)=>e+t.apiKeys.filter(e=>e.isActive).length,0),models:r.reduce((e,t)=>e+(t.models?.length??0),0)}),[r]);(0,X.useEffect)(()=>{let e=m.on(`provider.probe`,e=>{if(e.type!==`provider.probe`)return;let t=e.payload;t.status!==`no_base_url`&&t.status!==`no_provider`&&ue(e=>({...e,[t.providerId]:{ok:t.ok,status:t.status,detail:t.detail}}))});return()=>e?.()},[m]);let pe=(0,X.useCallback)(e=>{let t=ae.trim();t&&(de.has(e.id)?c(e.id,`default`,t):d(e.id,e.family,e.apiBase??void 0,t),oe(``),ie(null),ce(!1),B.success(_(`settings:provider.savedToast`,{name:e.name})),e.apiBase&&setTimeout(()=>m.probeProvider(e.id,6e3),700))},[ae,de,c,d,m]),me=h.trim()?t.filter(e=>{let t=h.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,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,Z.jsx)(cn,{className:`h-4 w-4 text-muted-foreground`}),_(`settings:provider.subscriptionHeading`)]}),(0,Z.jsx)(Qv,{ws:m,savedProviders:r.map(e=>({id:e.id,hasActiveKey:e.apiKeys.some(e=>e.isActive)}))})]}),(0,Z.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(Yi,{className:`h-4 w-4 text-muted-foreground`}),_(`settings:provider.apiKeysHeading`)]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:_(`settings:provider.apiKeysBody`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,Z.jsxs)(Y,{variant:a===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>o(`catalog`),children:[(0,Z.jsx)(Yi,{className:`h-4 w-4 mr-1`}),_(`settings:provider.tabCatalog`)]}),(0,Z.jsxs)(Y,{variant:a===`saved`?`default`:`outline`,size:`sm`,onClick:()=>o(`saved`),children:[(0,Z.jsx)(cn,{className:`h-4 w-4 mr-1`}),_(`settings:provider.tabSaved`,{count:r.length})]})]}),a===`catalog`&&(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(ts,{placeholder:_(`settings:provider.searchPlaceholder`,{count:t.length}),value:h,onChange:e=>g(e.target.value),className:`text-sm`}),n&&t.length===0?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,Z.jsx)(mn,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:_(`settings:provider.loadingCatalog`)})]}):me.length===0&&h?(0,Z.jsx)(`div`,{className:`text-center py-8 text-muted-foreground text-sm`,children:_(`settings:provider.noMatch`,{query:h})}):Ny.map(t=>{let n=he[t];return n?.length?(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:t}),(0,Z.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:n.map(t=>{let n=le[t.id],r=e===t.id;return(0,Z.jsxs)(`div`,{className:K(`rounded-lg border transition-all`,r?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border`),children:[(0,Z.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,Z.jsxs)(`div`,{className:`flex w-full justify-between items-start`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,Z.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,t.id,`)`]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.hasApiKey&&(0,Z.jsxs)(`span`,{className:`text-xs bg-success/10 text-success px-2 py-0.5 rounded`,children:[(0,Z.jsx)(cn,{className:`h-3 w-3 inline mr-1`}),_(`settings:provider.configured`)]}),n&&(0,Z.jsxs)(`span`,{className:K(`text-xs px-2 py-0.5 rounded inline-flex items-center gap-1`,n.ok?`bg-success/10 text-success`:`bg-destructive/10 text-destructive`),title:n.detail??n.status,children:[n.ok?(0,Z.jsx)(Bn,{className:`h-3 w-3`}):(0,Z.jsx)(qr,{className:`h-3 w-3`}),n.ok?_(`settings:provider.reachable`):n.status]}),t.envVars[0]&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:_(`settings:provider.envVar`,{var:t.envVars[0]})}),r&&(0,Z.jsx)(Bn,{className:`h-4 w-4 text-primary`})]})]}),(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[_(`settings:provider.modelCount`,{count:t.modelCount}),t.apiBase&&` · ${t.apiBase}`]})]}),r&&!t.hasApiKey&&(0,Z.jsx)(`div`,{className:`px-3 pb-3 -mt-1 space-y-2`,children:re===t.id?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(ts,{autoFocus:!0,type:se?`text`:`password`,placeholder:_(`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,Z.jsx)(Y,{size:`icon`,variant:`ghost`,onClick:()=>ce(e=>!e),children:se?(0,Z.jsx)(ht,{className:`h-4 w-4`}):(0,Z.jsx)(ja,{className:`h-4 w-4`})}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>pe(t),disabled:!ae.trim(),children:_(`common:action.save`)})]}),t.envVars[0]&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:_(`settings:provider.orEnv`,{env:t.envVars[0]})})]}):(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>{ie(t.id),oe(``)},children:[(0,Z.jsx)(cn,{className:`h-3.5 w-3.5 mr-1`}),_(`settings:provider.addApiKey`)]})})]},t.id)})})]},t):null})]}),a===`saved`&&(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:_(`settings:provider.manageKeys`)}),(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-muted/30 px-2 py-1`,children:[(0,Z.jsx)(Hn,{className:`h-3.5 w-3.5`}),_(`settings:provider.savedProviderCount`,{count:r.length})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-muted/30 px-2 py-1`,children:[(0,Z.jsx)(cn,{className:`h-3.5 w-3.5`}),_(`settings:provider.keyCount`,{count:fe.keys})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-muted/30 px-2 py-1`,children:[(0,Z.jsx)(Oa,{className:`h-3.5 w-3.5`}),_(`settings:provider.activeKeyCount`,{count:fe.activeKeys})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-muted/30 px-2 py-1`,children:[(0,Z.jsx)(On,{className:`h-3.5 w-3.5`}),_(`settings:provider.modelCount`,{count:fe.models})]})]})]}),(0,Z.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>D(!E),children:[(0,Z.jsx)(Gi,{className:`h-4 w-4 mr-1`}),_(`settings:provider.addProvider`)]})]}),E&&(0,Z.jsxs)(`div`,{className:`p-4 border rounded-lg space-y-3 bg-muted/50`,children:[(0,Z.jsx)(`h4`,{className:`font-medium`,children:_(`settings:provider.addCustomHeading`)}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:_(`settings:provider.localServers`)}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:Yv.map(e=>(0,Z.jsx)(Y,{type:`button`,size:`sm`,variant:O===e.id?`default`:`outline`,onClick:()=>ne(e),title:e.hint,children:e.label},e.id))})]}),(0,Z.jsx)(ts,{placeholder:_(`settings:provider.providerIdPlaceholder`),value:O,onChange:e=>k(e.target.value),ref:ee.setFieldRef(0),onKeyDown:e=>ee.handleKeyDown(e,0)}),(0,Z.jsxs)(`select`,{className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:A,onChange:e=>j(e.target.value),ref:ee.setFieldRef(1),onKeyDown:e=>ee.handleKeyDown(e,1),children:[(0,Z.jsx)(`option`,{value:`anthropic`,children:_(`activity:provider.anthropic`)}),(0,Z.jsx)(`option`,{value:`openai`,children:_(`activity:provider.openai`)}),(0,Z.jsx)(`option`,{value:`openai-compatible`,children:_(`activity:provider.openaiCompatible`)}),(0,Z.jsx)(`option`,{value:`google`,children:_(`activity:provider.google`)})]}),(0,Z.jsx)(ts,{placeholder:_(`activity:provider.baseUrlOptionalEGHttpLocalhost11434V1`),value:M,onChange:e=>N(e.target.value),ref:ee.setFieldRef(2),onKeyDown:e=>ee.handleKeyDown(e,2)}),(0,Z.jsx)(ts,{type:`password`,placeholder:_(`settings:provider.apiKeyOptionalPlaceholder`),value:P,onChange:e=>F(e.target.value),ref:ee.setFieldRef(3),onKeyDown:e=>ee.handleKeyDown(e,3)}),(0,Z.jsx)(Bv,{models:I,onChange:L}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(Y,{size:`sm`,onClick:te,disabled:!O.trim(),ref:ee.setFieldRef(4),onKeyDown:e=>ee.handleKeyDown(e,4,te),children:_(`common:action.add`)}),(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>D(!1),ref:ee.setFieldRef(5),onKeyDown:e=>ee.handleKeyDown(e,5),children:_(`common:action.cancel`)})]})]}),i?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Z.jsx)(mn,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):r.length===0?(0,Z.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Z.jsx)(cn,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,Z.jsx)(`p`,{children:_(`settings:provider.noSaved`)}),(0,Z.jsx)(`p`,{className:`text-sm`,children:_(`settings:provider.noSavedHint`)})]}):r.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border/80 bg-card/70 p-4 shadow-sm shadow-black/[0.02]`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`h4`,{className:`min-w-0 break-words font-mono text-sm font-semibold text-foreground`,children:e.id}),e.family&&(0,Z.jsx)(`span`,{className:`rounded-full border border-border/70 bg-muted/40 px-2 py-0.5 text-[11px] font-medium text-muted-foreground`,children:e.family}),e.apiKeys.some(e=>e.isActive)&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-success/10 px-2 py-0.5 text-[11px] font-medium text-success`,children:[(0,Z.jsx)(Oa,{className:`h-3 w-3`}),_(`settings:provider.active`)]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2 text-xs text-muted-foreground`,children:[e.baseUrl&&(0,Z.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1 rounded-md border border-border/70 bg-background/60 px-2 py-1`,children:[(0,Z.jsx)(Yi,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.baseUrl})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-background/60 px-2 py-1`,children:[(0,Z.jsx)(On,{className:`h-3.5 w-3.5`}),_(`settings:provider.modelCount`,{count:e.models?.length??0})]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border/70 bg-background/60 px-2 py-1`,children:[(0,Z.jsx)(cn,{className:`h-3.5 w-3.5`}),_(`settings:provider.keyCount`,{count:e.apiKeys.length})]})]})]}),(0,Z.jsx)(`div`,{className:`flex gap-2 sm:justify-end`,children:(0,Z.jsx)(Y,{size:`icon`,variant:`ghost`,onClick:()=>f(e.id),"aria-label":`Remove provider ${e.id}`,title:`Remove provider ${e.id}`,className:`h-8 w-8 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,Z.jsx)(jn,{className:`h-4 w-4 text-destructive`})})})]}),(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(280px,0.85fr)]`,children:[(0,Z.jsx)(jy,{providerId:e.id,savedPickedModelId:e.pickedModelId,savedModels:e.models,savedCustomModels:e.customModels,ws:m,onPickModel:p}),(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-background/75 p-3 shadow-sm shadow-black/[0.02]`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-semibold`,children:_(`settings:provider.apiKeysLabel`)}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:_(`settings:provider.keyCount`,{count:e.apiKeys.length})})]}),(0,Z.jsxs)(Y,{size:`sm`,variant:`ghost`,onClick:()=>y(v===e.id?null:e.id),className:`h-8 px-2 text-xs`,children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),_(`settings:provider.addKey`)]})]}),e.apiKeys.length===0&&!v&&(0,Z.jsx)(`p`,{className:`mt-3 rounded-md border border-dashed border-border/70 bg-muted/20 px-3 py-2 text-xs text-muted-foreground`,children:_(`settings:provider.noKeys`)}),e.apiKeys.length>0&&(0,Z.jsx)(`div`,{className:`mt-3 space-y-2`,children:e.apiKeys.map(t=>(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-border/70 bg-muted/20 p-2.5 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,Z.jsx)(`span`,{className:`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-border/70 bg-background text-muted-foreground`,children:(0,Z.jsx)(cn,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate text-sm font-medium`,children:t.label}),t.isActive&&(0,Z.jsx)(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[11px] font-medium text-success`,children:_(`settings:provider.active`)})]}),(0,Z.jsx)(`div`,{className:`mt-0.5`,children:(0,Z.jsx)(Vv,{maskedKey:t.maskedKey})})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-1`,children:[!t.isActive&&(0,Z.jsx)(Y,{size:`sm`,variant:`outline`,onClick:()=>u(e.id,t.label),className:`h-8 px-2 text-xs`,children:_(`settings:provider.setActive`)}),(0,Z.jsx)(Y,{size:`icon`,variant:`ghost`,onClick:()=>l(e.id,t.label),"aria-label":`Delete key ${t.label}`,title:`Delete key ${t.label}`,className:`h-8 w-8 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,Z.jsx)(jn,{className:`h-3.5 w-3.5 text-destructive`})})]})]},t.label))}),v===e.id&&(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2 rounded-lg border border-border/70 bg-background p-3`,children:[(0,Z.jsx)(ts,{placeholder:_(`settings:provider.keyLabelPlaceholder`),value:b,onChange:e=>x(e.target.value),ref:R.setFieldRef(0),onKeyDown:e=>R.handleKeyDown(e,0)}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(ts,{type:w?`text`:`password`,placeholder:_(`settings:provider.apiKeyPlaceholder`),value:S,onChange:e=>C(e.target.value),ref:R.setFieldRef(1),onKeyDown:e=>R.handleKeyDown(e,1)}),(0,Z.jsx)(Y,{size:`icon`,variant:`ghost`,onClick:()=>T(!w),children:w?(0,Z.jsx)(ht,{className:`h-4 w-4`}):(0,Z.jsx)(ja,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(Y,{size:`sm`,onClick:()=>z(e.id),disabled:!b.trim()||!S.trim(),ref:R.setFieldRef(2),onKeyDown:t=>R.handleKeyDown(t,2,()=>z(e.id)),children:_(`settings:provider.saveKey`)}),(0,Z.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>{y(null),x(``),C(``)},ref:R.setFieldRef(3),onKeyDown:e=>R.handleKeyDown(e,3),children:_(`common:action.cancel`)})]})]})]})]})]},e.id))]})]})}var Fy=Object.entries({discovery:[[`explore`,`Explore`],[`search`,`Search`],[`research`,`Research`]],planning:[[`analyst`,`Analyst`],[`planner`,`Planner`],[`architect`,`Architect`],[`critic`,`Critic`],[`refactor-planner`,`Refactor Planner`]],build:[[`executor`,`Executor`],[`refactor`,`Refactor`],[`simplifier`,`Simplifier`],[`migration`,`Migration`],[`vision`,`Vision`],[`debugger`,`Debugger`],[`tracer`,`Tracer`],[`concurrency`,`Concurrency`]],verify:[[`realtime`,`Realtime`],[`resilience-engineer`,`Resilience Engineer`],[`chaos-engineer`,`Chaos Engineer`],[`verifier`,`Verifier`],[`test`,`Test`],[`e2e`,`E2E`],[`browser`,`Browser`],[`performance`,`Performance`],[`chaos`,`Chaos`],[`security-scanner`,`Security Scanner`],[`bug-hunter`,`Bug Hunter`],[`audit-log`,`Audit Log`]],review:[[`threat-modeler`,`Threat Modeler`],[`secure-coding-coach`,`Secure Coding Coach`],[`compliance-auditor`,`Compliance Auditor`],[`privacy-engineer`,`Privacy Engineer`],[`reviewer`,`Reviewer`],[`code-reviewer`,`Code Reviewer`],[`security-reviewer`,`Security Reviewer`],[`accessibility`,`Accessibility`],[`compliance`,`Compliance`]],domain:[[`android`,`Android`],[`desktop`,`Desktop`],[`distributed-systems`,`Distributed Systems`],[`database`,`Database`],[`api`,`API`],[`auth`,`Auth`],[`data`,`Data`],[`frontend`,`Frontend`],[`backend`,`Backend`],[`designer`,`Designer`],[`ios`,`iOS`],[`payments`,`Payments`],[`messaging`,`Messaging`],[`search-relevance`,`Search Relevance`],[`storage`,`Storage`],[`ml-engineer`,`ML Engineer`],[`data-governance`,`Data Governance`]],knowledge:[[`document`,`Document`],[`uml`,`UML`],[`i18n`,`I18n`],[`prompt`,`Prompt`]],delivery:[[`platform-engineer`,`Platform Engineer`],[`git`,`Git`],[`release`,`Release`],[`devops`,`DevOps`],[`observability`,`Observability`],[`dependency`,`Dependency`]],meta:[[`skill-manage`,`Skill Manager`],[`self-improving`,`Self-Improving`],[`context`,`Context`],[`cost`,`Cost`],[`tech-stack`,`Tech Stack Validator`],[`plugin-author`,`Plugin Author`],[`tool-author`,`Tool Author`],[`prompt-evaluator`,`Prompt Evaluator`],[`benchmark-engineer`,`Benchmark Engineer`],[`memory-curator`,`Memory Curator`],[`fleet-coordinator`,`Fleet Coordinator`]]}).map(([e,t])=>({phase:e,label:`${e.charAt(0).toUpperCase()}${e.slice(1)}`,roles:t.map(([e,t])=>({role:e,name:t}))})),Iy=Fy.map(e=>e.phase),Ly=Fy.flatMap(e=>[...e.roles]),Ry=Ly.map(e=>e.role),zy=[`*`,...Iy,...Ry];function By(e){if(e===`*`)return`Default (*)`;let t=Fy.find(t=>t.phase===e);if(t)return`Phase: ${t.label} (${t.phase})`;let n=Ly.find(t=>t.role===e);return n?`${n.name} (${n.role})`:`Custom: ${e}`}var Vy=[{value:``,label:`mode: inherit`},{value:`auto`,label:`mode: auto`},{value:`on`,label:`mode: on`},{value:`off`,label:`mode: off`}],Hy=[{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`}],Uy=[{value:``,label:`preserve: inherit`},{value:`on`,label:`preserve: on`},{value:`off`,label:`preserve: off`}],Wy=new Set(zy);function Gy(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 Ky(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 qy({syncPref:e,candidates:t}){let n=G(),{t:r}=W(),[i,a]=(0,X.useState)(`*`),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(``),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(``),m=(0,X.useCallback)(t=>e(`modelMatrix`,t),[e]),h=(0,X.useCallback)(()=>{let e=i.trim(),t=o.trim(),r=Gy(c,u,f);if(!e||!t&&!r)return;let a=t?n.fallbackProfiles[t]?{fallbackProfile:t}:t.includes(`/`)?{provider:t.slice(0,t.indexOf(`/`)),model:t.slice(t.indexOf(`/`)+1)}:{model:t}:{},h=n.modelMatrix[e]?.modelRuntime;r?a.modelRuntime=r:h&&(a.modelRuntime=h),m({...n.modelMatrix,[e]:a}),s(``),l(``),d(``),p(``)},[n.fallbackProfiles,n.modelMatrix,i,f,u,c,o,m]),g=(0,X.useCallback)(e=>{let{[e]:t,...r}=n.modelMatrix;m(r)},[n.modelMatrix,m]),_=(0,X.useCallback)((e,t,r)=>{let i={...n.modelMatrix},a={...i[e]??{}},o={...a.modelRuntime??{}},s={...o.reasoning??{}};t===`mode`?r?s.mode=r:delete s.mode:t===`effort`?r?s.effort=r:delete s.effort:r?s.preserve=r===`on`:delete s.preserve,Object.keys(s).length>0?o.reasoning=s:delete o.reasoning,Object.keys(o).length>0?a.modelRuntime=o:delete a.modelRuntime,a.model||a.fallbackProfile||a.modelRuntime?i[e]=a:delete i[e],m(i)},[n.modelMatrix,m]),v=e=>{let t=e.provider&&e.model?`${e.provider}/${e.model}`:e.model,n=e.modelRuntime?.reasoning;return[t??(!e.fallbackProfile&&n?r(`settings:agent.leaderModel`):``),e.fallbackProfile?`profile:${e.fallbackProfile}`:``,...Ky(n)].filter(Boolean).join(` + `)},y=Array.from(new Set([...Object.keys(n.modelMatrix),i].filter(e=>e&&!Wy.has(e)))).sort((e,t)=>e.localeCompare(t));return(0,Z.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Z.jsx)(tr,{className:`h-4 w-4 text-muted-foreground`}),r(`settings:agent.routingHeading`)]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[minmax(0,180px)_1fr_auto]`,children:[(0,Z.jsxs)(`select`,{"aria-label":r(`settings:agent.routingRouteKey`),value:i,onChange:e=>a(e.target.value),className:`h-9 min-w-0 rounded-md border bg-background px-3 font-mono text-sm`,children:[(0,Z.jsx)(`option`,{value:`*`,children:By(`*`)}),(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingPhasesGroup`),children:Fy.map(e=>(0,Z.jsx)(`option`,{value:e.phase,children:By(e.phase)},e.phase))}),Fy.map(e=>(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingRolesGroup`,{label:e.label}),children:e.roles.map(e=>(0,Z.jsx)(`option`,{value:e.role,children:By(e.role)},e.role))},e.phase)),y.length>0?(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingCustomGroup`),children:y.map(e=>(0,Z.jsx)(`option`,{value:e,children:By(e)},e))}):null]}),(0,Z.jsxs)(`select`,{"aria-label":r(`settings:agent.routingTargetAria`),value:o,onChange:e=>s(e.target.value),className:`h-9 min-w-0 rounded-md border bg-background px-3 font-mono text-sm`,children:[(0,Z.jsx)(`option`,{value:``,children:r(`settings:agent.routingTargetEmpty`)}),Object.keys(n.fallbackProfiles).length>0&&(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingTargetProfilesGroup`),children:Object.keys(n.fallbackProfiles).map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),t&&t.length>0&&(0,Z.jsx)(`optgroup`,{label:r(`settings:agent.routingTargetModelsGroup`),children:t.map(e=>(0,Z.jsxs)(`option`,{value:`${e.provider}/${e.model}`,children:[e.provider,`/`,e.model]},`${e.provider}/${e.model}`))})]}),(0,Z.jsx)(Y,{type:`button`,variant:`outline`,onClick:h,children:r(`settings:agent.routingSet`)})]}),(0,Z.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningModeAria`),value:c,onChange:e=>l(e.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Vy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningEffortAria`),value:u,onChange:e=>d(e.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Hy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningPreserveAria`),value:f,onChange:e=>p(e.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Uy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))})]}),(0,Z.jsx)(`div`,{className:`mt-3 space-y-1.5`,children:Object.keys(n.modelMatrix).length===0?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`settings:agent.noRoutes`)}):Object.entries(n.modelMatrix).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>(0,Z.jsxs)(`div`,{className:`rounded-md border border-border bg-muted px-2 py-1.5 text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`w-40 shrink-0 break-words font-mono text-muted-foreground`,title:e,children:By(e)}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 break-words font-mono`,children:v(t)}),(0,Z.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>g(e),children:r(`common:action.remove`)})]}),(0,Z.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-2 sm:grid-cols-3`,children:[(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningModeFor`,{key:e}),value:t.modelRuntime?.reasoning?.mode??``,onChange:t=>_(e,`mode`,t.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Vy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningEffortFor`,{key:e}),value:t.modelRuntime?.reasoning?.effort??``,onChange:t=>_(e,`effort`,t.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Hy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))}),(0,Z.jsx)(`select`,{"aria-label":r(`settings:agent.routingReasoningPreserveFor`,{key:e}),value:t.modelRuntime?.reasoning?.preserve===void 0?``:t.modelRuntime.reasoning.preserve?`on`:`off`,onChange:t=>_(e,`preserve`,t.target.value),className:`h-8 min-w-0 rounded-md border bg-background px-2 text-xs`,children:Uy.map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value||`inherit`))})]})]},e))})]})}var Jy=[`off`,`low`,`medium`,`high`,`all`],Yy={off:`bg-muted-foreground`,low:`bg-success`,medium:`bg-warning`,high:`bg-warning ring-2 ring-warning/25`,all:`bg-destructive`},Xy={off:`settings:brain.riskCopy.off`,low:`settings:brain.riskCopy.low`,medium:`settings:brain.riskCopy.medium`,high:`settings:brain.riskCopy.high`,all:`settings:brain.riskCopy.all`},Zy=[`executor`,`skeptic`,`auditor`];function Qy(e){return e&&e.length>0?e.map(e=>({id:e.id,name:e.name,description:e.description})):Zy.map(e=>({id:e,name:e}))}var $y=[{value:`default`,labelKey:`settings:brainOpt.default15s`},{value:`5000`,label:`5s`},{value:`10000`,label:`10s`},{value:`20000`,label:`20s`},{value:`30000`,label:`30s`},{value:`60000`,label:`60s`}],eb=[{value:`off`,labelKey:`settings:brainOpt.waitForever`},{value:`30000`,label:`30s`},{value:`60000`,label:`1m`},{value:`120000`,label:`2m`},{value:`300000`,label:`5m`}],tb=[{value:`default`,labelKey:`settings:brainOpt.defaultHalf`},{value:`0.34`,label:`1/3`},{value:`0.5`,label:`1/2`},{value:`0.67`,label:`2/3`},{value:`0.75`,label:`3/4`},{value:`1`,labelKey:`settings:brainOpt.all`}],nb=[{value:`100`,label:`100`},{value:`200`,labelKey:`settings:brainOpt.n200Default`},{value:`400`,label:`400`},{value:`800`,label:`800`},{value:`1600`,label:`1600`}],rb=[{value:`0`,labelKey:`settings:brainOpt.offDefault`},{value:`0.3`,label:`0.3`},{value:`0.5`,label:`0.5`},{value:`0.7`,label:`0.7`},{value:`0.9`,label:`0.9`}],ib=[{value:`10`,label:`10`},{value:`20`,labelKey:`settings:brainOpt.n20Default`},{value:`50`,label:`50`},{value:`100`,label:`100`}],ab=[{value:`60000`,label:`1m`},{value:`300000`,labelKey:`settings:brainOpt.m5Default`},{value:`900000`,label:`15m`},{value:`3600000`,label:`1h`}],ob=[{value:`50`,label:`50`},{value:`200`,labelKey:`settings:brainOpt.n200Default`},{value:`500`,label:`500`},{value:`1000`,label:`1000`}],sb=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`10000`,label:`10s`},{value:`20000`,label:`20s`},{value:`30000`,label:`30s`},{value:`60000`,label:`60s`}],cb=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`1`,labelKey:`settings:brainOpt.oneSerial`},{value:`2`,label:`2`},{value:`3`,label:`3`},{value:`5`,label:`5`}],lb=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`500`,label:`500`},{value:`1000`,label:`1000`},{value:`2000`,label:`2000`},{value:`4000`,label:`4000`},{value:`8000`,label:`8000`}],ub=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`1`,labelKey:`settings:brainOpt.roundsOff`},{value:`2`,label:`2`},{value:`3`,label:`3`}],db=[{value:`default`,labelKey:`settings:brainOpt.default`},{value:`200`,label:`200`},{value:`400`,label:`400`},{value:`800`,label:`800`},{value:`1600`,label:`1600`}],fb=[{value:`default`,labelKey:`settings:brainOpt.default500`},{value:`100`,label:`100`},{value:`500`,label:`500`},{value:`1000`,label:`1000`},{value:`5000`,label:`5000`}],pb=[{value:`default`,labelKey:`settings:brainOpt.default10m`},{value:`120000`,label:`2m`},{value:`600000`,label:`10m`},{value:`1800000`,label:`30m`},{value:`3600000`,label:`1h`}];function mb(e,t){return e.some(e=>e.value===t)?e:[...e,{value:t,label:t}]}function hb(e,t){return e.map(e=>({value:e.value,label:e.labelKey?t(e.labelKey):e.label??e.value}))}function gb(e){return e===void 0?`default`:String(e)}function _b({level:e}){return(0,Z.jsx)(`span`,{className:K(`inline-block h-2.5 w-2.5 rounded-full`,Yy[e])})}function vb(e){return e.provider?`${e.provider}/${e.model}`:e.model}var yb={pool:{title:`settings:brain.pickPoolTitle`,hint:`settings:brain.pickPoolHint`},voter:{title:`settings:brain.pickVoterTitle`,hint:`settings:brain.pickVoterHint`},judge:{title:`settings:brain.pickJudgeTitle`,hint:`settings:brain.pickJudgeHint`}};function bb(){let{t:e}=W(),{client:t}=hf(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)([]),[o,s]=(0,X.useState)(!0),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(null),m=Pe();(0,X.useEffect)(()=>{t.send({type:`brain.status`,payload:t.withSession({})}),t.send({type:`brain.config.get`})},[t,m]),(0,X.useEffect)(()=>{let n=t.on(`brain.status`,e=>{let t=e.payload;if(t.sessionId&&m&&t.sessionId!==m)return;let n=Date.now();a(t.log.slice(-10).map(e=>{let t=Math.max(0,Math.round((n-e.at)/1e3)),r=t<60?`${t}s`:t<3600?`${Math.round(t/60)}m`:`${Math.round(t/3600)}h`;return{kind:e.kind,question:e.question,outcome:e.outcome,age:r}})),s(!1)}),i=t.on(`brain.config`,t=>{let n=t.payload;r(n.config),d(n.persisted?null:n.error??e(`settings:brain.persistError`)),l(!1),s(!1)});return()=>{n(),i()}},[t,e,m]);let h=(0,X.useCallback)(e=>{l(!0),t.send({type:`brain.config.set`,payload:t.withSession({patch:e})})},[t]),g=(0,X.useCallback)(e=>{r(t=>t&&{...t,maxAutoRisk:e}),h({maxAutoRisk:e})},[h]),_=(0,X.useMemo)(()=>n?.council.voters??[],[n]),v=(0,X.useCallback)(e=>{h({council:{voters:e.length>0?e:null}})},[h]),y=(0,X.useMemo)(()=>Qy(n?.personaCatalog),[n?.personaCatalog]),b=Jy.includes(n?.maxAutoRisk??``)?n?.maxAutoRisk??`medium`:`medium`,x=(0,X.useCallback)(e=>{if(!n||!f)return;let t=`${e.provider}/${e.model}`;if(f===`pool`){h({models:[...n.models.map(vb),t]});return}if(f===`judge`){h({council:{judge:t}});return}return v([..._,{provider:e.provider,model:e.model,persona:y[_.length%y.length]?.id??`executor`}]),!0},[n,y,f,h,v,_]);return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsx)(g_,{open:f!==null,mode:`provider-model`,title:f?e(yb[f].title):``,hint:f?e(yb[f].hint):void 0,onPick:e=>{if(e.type===`provider-model`)return x(e)},onClose:()=>p(null)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(Jn,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`h3`,{className:`text-base font-semibold`,children:e(`settings:brain.heading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.headingHint`)})]}),(o||c)&&(0,Z.jsx)(mn,{className:`ml-auto h-4 w-4 animate-spin text-muted-foreground`})]}),u&&(0,Z.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:u}),(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.riskHeading`)}),(0,Z.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:Jy.map(e=>(0,Z.jsxs)(Y,{variant:b===e?`default`:`outline`,size:`sm`,className:K(`gap-1.5 text-xs`,b===e&&`shadow-sm`),disabled:c,onClick:()=>g(e),children:[(0,Z.jsx)(_b,{level:e}),e.toUpperCase()]},e))}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(Xy[b])})]}),n&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.escalationHeading`)}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationModeLabel`),hint:e(`settings:brain.escalationModeHint`),value:n.mode,options:[{value:`interactive`,label:e(`settings:brain.optInteractive`)},{value:`headless`,label:e(`settings:brain.optHeadless`)}],onChange:e=>h({mode:e}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationDecisionTimeoutLabel`),hint:e(`settings:brain.escalationDecisionTimeoutHint`),value:n.decisionTimeoutMs?String(n.decisionTimeoutMs):`default`,options:hb($y,e),onChange:e=>h({decisionTimeoutMs:e==="default"?null:Number(e)}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationHumanTimeoutLabel`),hint:e(`settings:brain.escalationHumanTimeoutHint`),value:n.humanTimeoutMs?String(n.humanTimeoutMs):`off`,options:hb(eb,e),onChange:e=>h({humanTimeoutMs:e===`off`?null:Number(e)}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationTerminalPolicyLabel`),hint:e(`settings:brain.escalationTerminalPolicyHint`),value:n.terminalPolicy,options:[{value:`conservative`,label:e(`settings:brain.optConservative`)},{value:`deny-all`,label:e(`settings:brain.optDenyAll`)},{value:`continue-on-recommended`,label:e(`settings:brain.optContinueRecommended`)}],onChange:e=>h({terminalPolicy:e}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.escalationDecisionLogSizeLabel`),hint:e(`settings:brain.escalationDecisionLogSizeHint`),value:String(n.decisionLogMaxEntries),options:hb(mb(ib,String(n.decisionLogMaxEntries)),e),onChange:e=>h({decisionLogMaxEntries:Number(e)}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.rulesHeading`)}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px]`,children:e(`settings:brain.rulesConfigured`,{count:n.rules.length})})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.rulesBody`)}),n.rules.length>0&&(0,Z.jsx)(`div`,{className:`space-y-1`,children:n.rules.map((t,n)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/50 bg-background/40 px-2 py-1.5 text-xs`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground w-4 shrink-0`,children:[n+1,`.`]}),(0,Z.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:t.id}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px] shrink-0`,children:t.then.action}),t.enabled===!1&&(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px] shrink-0`,children:e(`settings:brain.rulesOff`)})]},`${t.id}-${n}`))}),n.ruleErrors.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-warning/40 bg-warning/10 px-2 py-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-warning`,children:e(`settings:brain.rulesDropped`,{count:n.ruleErrors.length})}),n.ruleErrors.map(e=>(0,Z.jsx)(`p`,{className:`text-xs text-warning`,children:e},e))]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.heuristicsHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.heuristicsBody`)}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsLowRiskLabel`),hint:e(`settings:brain.heuristicsLowRiskHint`),value:n.heuristics.lowRiskAutoAnswer,onChange:()=>h({heuristics:{lowRiskAutoAnswer:!n.heuristics.lowRiskAutoAnswer}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsBlockedLabel`),hint:e(`settings:brain.heuristicsBlockedHint`),value:n.heuristics.blockedResolved,onChange:()=>h({heuristics:{blockedResolved:!n.heuristics.blockedResolved}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsDeadlockLabel`),hint:e(`settings:brain.heuristicsDeadlockHint`),value:n.heuristics.deadlockSkip,onChange:()=>h({heuristics:{deadlockSkip:!n.heuristics.deadlockSkip}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsRetryLabel`),hint:e(`settings:brain.heuristicsRetryHint`),value:n.heuristics.retryExhausted,onChange:()=>h({heuristics:{retryExhausted:!n.heuristics.retryExhausted}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.heuristicsPingLabel`),hint:e(`settings:brain.heuristicsPingHint`),value:n.heuristics.continuePing,onChange:()=>h({heuristics:{continuePing:!n.heuristics.continuePing}}),disabled:c}),n.heuristics.blockedResolvedMarkers&&n.heuristics.blockedResolvedMarkers.length>0&&(0,Z.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:e(`settings:brain.heuristicsMarkers`,{markers:n.heuristics.blockedResolvedMarkers.join(`, `)})})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.qualityHeading`)}),n.circuit&&(0,Z.jsx)(j_,{variant:n.circuit.state===`closed`?`outline`:`default`,className:`text-[10px]`,children:e(`settings:brain.qualityCircuit`,{state:n.circuit.state,count:n.circuit.consecutiveFailures})})]}),(0,Z.jsx)(Q,{label:e(`settings:brain.qualityResponseBudgetLabel`),hint:e(`settings:brain.qualityResponseBudgetHint`),value:String(n.llm.maxTokens),options:hb(mb(nb,String(n.llm.maxTokens)),e),onChange:e=>h({llm:{maxTokens:Number(e)}}),disabled:c}),(0,Z.jsx)($,{label:e(`settings:brain.qualityRejectLabel`),hint:e(`settings:brain.qualityRejectHint`),value:n.llm.rejectUncertain,onChange:()=>h({llm:{rejectUncertain:!n.llm.rejectUncertain}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.qualityMinConfidenceLabel`),hint:e(`settings:brain.qualityMinConfidenceHint`),value:String(n.llm.minConfidence),options:hb(mb(rb,String(n.llm.minConfidence)),e),onChange:e=>h({llm:{minConfidence:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.qualityDenyTerminalLabel`),hint:e(`settings:brain.qualityDenyTerminalHint`),value:n.llm.denyIsTerminal,options:[{value:`never`,label:e(`settings:brain.optNeverDefault`)},{value:`when-decided`,label:e(`settings:brain.optWhenDecided`)},{value:`always`,label:e(`settings:brain.optAlways`)}],onChange:e=>h({llm:{denyIsTerminal:e}}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.traceHeading`)}),(0,Z.jsx)($,{label:e(`settings:brain.traceRecordLabel`),hint:e(`settings:brain.traceRecordHint`),value:n.trace.enabled,onChange:()=>h({trace:{enabled:!n.trace.enabled}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.traceContentLabel`),hint:e(`settings:brain.traceContentHint`),value:n.trace.content,options:[{value:`full`,label:e(`settings:brain.optFullDefault`)},{value:`redacted`,label:e(`settings:brain.optRedacted`)},{value:`none`,label:e(`settings:brain.optMetadataOnly`)}],onChange:e=>h({trace:{content:e}}),disabled:c}),n.trace.path&&(0,Z.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:n.trace.path})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.cacheHeading`)}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px]`,children:e(`settings:brain.cacheStats`,{hits:n.cache.hits,misses:n.cache.misses,size:n.cache.size})})]}),(0,Z.jsx)($,{label:e(`settings:brain.cacheReplayLabel`),hint:e(`settings:brain.cacheReplayHint`),value:n.cache.enabled,onChange:()=>h({cache:{enabled:!n.cache.enabled}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.cacheLifetimeLabel`),hint:e(`settings:brain.cacheLifetimeHint`),value:String(n.cache.ttlMs),options:hb(mb(ab,String(n.cache.ttlMs)),e),onChange:e=>h({cache:{ttlMs:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.cacheMaxEntriesLabel`),hint:e(`settings:brain.cacheMaxEntriesHint`),value:String(n.cache.maxEntries),options:hb(mb(ob,String(n.cache.maxEntries)),e),onChange:e=>h({cache:{maxEntries:Number(e)}}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.monitorHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.monitorBody`)}),(0,Z.jsx)($,{label:e(`settings:brain.monitorWatchLabel`),hint:e(`settings:brain.monitorWatchHint`),value:n.monitor.enabled!==!1,onChange:()=>h({monitor:{enabled:n.monitor.enabled===!1}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.monitorPolicyLabel`),hint:e(`settings:brain.monitorPolicyHint`),value:n.monitor.policy??`llm`,options:[{value:`llm`,label:e(`settings:brain.optConsultBrain`)},{value:`steer`,label:e(`settings:brain.optAlwaysSteer`)},{value:`observe`,label:e(`settings:brain.optObserveOnly`)}],onChange:e=>h({monitor:{policy:e}}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.modelsHeading`)}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px]`,children:n.usingSessionModel?e(`settings:brain.modelsSessionBadge`):e(`settings:brain.modelsResolvedBadge`,{resolved:n.poolLabels.length,total:n.models.length})})]}),(0,Z.jsx)($,{label:e(`settings:brain.modelsUseSessionLabel`),hint:e(`settings:brain.modelsUseSessionHint`),value:n.usingSessionModel,onChange:()=>{n.usingSessionModel||h({models:null})},disabled:c}),n.models.length>0&&(0,Z.jsx)(`div`,{className:`space-y-1`,children:n.models.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/50 bg-background/40 px-2 py-1.5 text-xs`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground w-4 shrink-0`,children:[t+1,`.`]}),(0,Z.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:vb(e)}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,disabled:c||t===0,onClick:()=>{let e=n.models.map(vb),r=e.splice(t,1)[0];r&&e.splice(t-1,0,r),h({models:e})},children:(0,Z.jsx)(sa,{className:`h-3 w-3`})}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,disabled:c||t===n.models.length-1,onClick:()=>{let e=n.models.map(vb),r=e.splice(t,1)[0];r&&e.splice(t+1,0,r),h({models:e})},children:(0,Z.jsx)(Nr,{className:`h-3 w-3`})}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-destructive`,disabled:c,onClick:()=>{let e=n.models.map(vb).filter((e,n)=>n!==t);h({models:e.length>0?e:null})},children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]},`${vb(e)}-${t}`))}),(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,className:`gap-1.5 text-xs`,disabled:c,onClick:()=>p(`pool`),children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),` `,e(`settings:brain.modelsAddModel`)]}),n.models.length>1&&(0,Z.jsx)(Q,{label:e(`settings:brain.modelsPoolStrategyLabel`),hint:e(`settings:brain.modelsPoolStrategyHint`),value:n.strategy,options:[{value:`fallback`,label:e(`settings:brain.optFallback`)},{value:`round-robin`,label:e(`settings:brain.optRoundRobin`)}],onChange:e=>h({strategy:e}),disabled:c})]}),(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.councilHeading`)}),(0,Z.jsx)(j_,{variant:n.council.enabled?`default`:`outline`,className:`text-[10px]`,children:n.council.enabled?e(`settings:brain.councilConvened`):e(`settings:brain.councilDisabled`)})]}),(0,Z.jsx)($,{label:e(`settings:brain.councilEnableLabel`),hint:e(`settings:brain.councilEnableHint`),value:n.council.enabled,onChange:()=>h({council:{enabled:!n.council.enabled}}),disabled:c}),n.council.enabled&&n.councilLabels.length>0&&_.length===0&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`settings:brain.councilSeatsDerived`,{seats:n.councilLabels.join(`, `)})}),_.length>0&&(0,Z.jsx)(`div`,{className:`space-y-1`,children:_.map((t,n)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/50 bg-background/40 px-2 py-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:vb(t)}),(0,Z.jsxs)(`select`,{value:t.persona??y[n%y.length]?.id??``,onChange:e=>v(_.map((t,r)=>r===n?{...t,persona:e.target.value}:t)),className:`h-6 rounded border bg-background px-1 text-[10px]`,title:y.find(e=>e.id===t.persona)?.description??e(`settings:brain.councilCustomLens`),children:[y.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id)),t.persona&&!y.some(e=>e.id===t.persona)&&(0,Z.jsx)(`option`,{value:t.persona,children:e(`settings:brain.councilCustomOption`,{persona:t.persona})})]}),(0,Z.jsx)(Y,{variant:t.veto?`default`:`outline`,size:`sm`,className:`h-6 px-1.5 text-[10px]`,disabled:c,onClick:()=>v(_.map((e,t)=>t===n?{...e,veto:!e.veto}:e)),children:e(`settings:brain.councilVeto`)}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-destructive`,disabled:c,onClick:()=>v(_.filter((e,t)=>t!==n)),children:(0,Z.jsx)(hn,{className:`h-3 w-3`})})]},`${vb(t)}-${n}`))}),(0,Z.jsxs)(Y,{variant:`outline`,size:`sm`,className:`gap-1.5 text-xs`,disabled:c,onClick:()=>p(`voter`),children:[(0,Z.jsx)(Gi,{className:`h-3.5 w-3.5`}),` `,e(`settings:brain.councilAddVoter`)]}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilRiskFloorLabel`),hint:e(`settings:brain.councilRiskFloorHint`),value:n.council.minRisk,options:[{value:`medium`,label:e(`settings:brain.optMediumPlus`)},{value:`high`,label:e(`settings:brain.optHighPlus`)},{value:`critical`,label:e(`settings:brain.optCriticalOnly`)}],onChange:e=>h({council:{minRisk:e}}),disabled:c}),(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium`,children:e(`settings:brain.councilJudge`)}),(0,Z.jsx)(`div`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e(`settings:brain.councilJudgeDesc`)}),!n.council.judge&&n.judgeLabel&&(0,Z.jsxs)(`div`,{className:`mt-0.5 font-mono text-xs text-muted-foreground`,children:[e(`settings:brain.councilResolved`,{model:n.judgeLabel}),n.judgeIsVoter&&(0,Z.jsx)(`span`,{className:`ml-1 font-sans text-warning`,children:e(`settings:brain.councilAlsoVoter`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`max-w-[180px] truncate font-mono text-xs`,children:n.council.judge?vb(n.council.judge):e(`settings:brain.councilAuto`)}),(0,Z.jsx)(Y,{variant:`outline`,size:`sm`,className:`h-7 text-xs`,disabled:c,onClick:()=>p(`judge`),children:e(`settings:brain.councilPick`)}),n.council.judge&&(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,className:`h-7 text-xs`,disabled:c,onClick:()=>h({council:{judge:null}}),children:e(`settings:brain.councilAutoReset`)})]})]}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilQuorumLabel`),hint:e(`settings:brain.councilQuorumHint`),value:n.council.quorum===void 0?`default`:String(n.council.quorum),options:hb(tb,e),onChange:e=>h({council:{quorum:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilApprovalLabel`),hint:e(`settings:brain.councilApprovalHint`),value:n.council.approval===void 0?`default`:String(n.council.approval),options:hb(tb,e),onChange:e=>h({council:{approval:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilPerSeatTimeoutLabel`),hint:e(`settings:brain.councilPerSeatTimeoutHint`),value:gb(n.council.perCallTimeoutMs),options:hb(mb(sb,gb(n.council.perCallTimeoutMs)),e),onChange:e=>h({council:{perCallTimeoutMs:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilMaxConcurrencyLabel`),hint:e(`settings:brain.councilMaxConcurrencyHint`),value:gb(n.council.maxConcurrency),options:hb(mb(cb,gb(n.council.maxConcurrency)),e),onChange:e=>h({council:{maxConcurrency:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilDistinctnessLabel`),hint:e(`settings:brain.councilDistinctnessHint`),value:n.council.distinctness,options:[{value:`none`,label:e(`settings:brain.optNoneDefault`)},{value:`model`,label:e(`settings:brain.optDistinctModels`)},{value:`provider`,label:e(`settings:brain.optDistinctProviders`)}],onChange:e=>h({council:{distinctness:e}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilVoterBudgetLabel`),hint:e(`settings:brain.councilVoterBudgetHint`),value:gb(n.council.voterMaxTokens),options:hb(mb(lb,gb(n.council.voterMaxTokens)),e),onChange:e=>h({council:{voterMaxTokens:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilRoundsLabel`),hint:e(`settings:brain.councilRoundsHint`),value:gb(n.council.deliberationRounds),options:hb(mb(ub,gb(n.council.deliberationRounds)),e),onChange:e=>h({council:{deliberationRounds:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.councilJudgeBudgetLabel`),hint:e(`settings:brain.councilJudgeBudgetHint`),value:gb(n.council.judgeMaxTokens),options:hb(mb(db,gb(n.council.judgeMaxTokens)),e),onChange:e=>h({council:{judgeMaxTokens:e==="default"?null:Number(e)}}),disabled:c}),n.council.seats.length>0&&(0,Z.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[e(`settings:brain.councilSeatTemplate`),` `,n.council.seats.map(t=>t.veto?`${t.persona} (${e(`settings:brain.councilVeto`)})`:t.persona).join(`, `)]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1 rounded-md border border-border/70 bg-muted/20 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.ledgerHeading`)}),(0,Z.jsx)($,{label:e(`settings:brain.ledgerRecordLabel`),hint:e(`settings:brain.ledgerRecordHint`),value:n.ledger.enabled,onChange:()=>h({ledger:{enabled:!n.ledger.enabled}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.ledgerAutoDenyLabel`),hint:e(`settings:brain.ledgerAutoDenyHint`),value:n.ledger.autoDenyAfterFailures===void 0?`default`:String(n.ledger.autoDenyAfterFailures),options:[{value:`default`,label:e(`settings:brain.optDefault3`)},{value:`0`,label:e(`settings:brain.optOff`)},{value:`2`,label:`2`},{value:`3`,label:`3`},{value:`5`,label:`5`}],onChange:e=>h({ledger:{autoDenyAfterFailures:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.ledgerMemoryEntriesLabel`),hint:e(`settings:brain.ledgerMemoryEntriesHint`),value:gb(n.ledger.maxMemoryEntries),options:hb(mb(fb,gb(n.ledger.maxMemoryEntries)),e),onChange:e=>h({ledger:{maxMemoryEntries:e==="default"?null:Number(e)}}),disabled:c}),(0,Z.jsx)(Q,{label:e(`settings:brain.ledgerRetryWindowLabel`),hint:e(`settings:brain.ledgerRetryWindowHint`),value:gb(n.ledger.interventionRetryWindowMs),options:hb(mb(pb,gb(n.ledger.interventionRetryWindowMs)),e),onChange:e=>h({ledger:{interventionRetryWindowMs:e==="default"?null:Number(e)}}),disabled:c}),n.ledger.path&&(0,Z.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:n.ledger.path})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-card/70 p-3`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e(`settings:brain.recentHeading`,{count:i.length})}),(0,Z.jsx)(`div`,{className:`space-y-1 max-h-[300px] overflow-y-auto`,children:i.length===0?(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground py-2`,children:e(`settings:brain.recentEmpty`)}):i.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-border/50 bg-background/40 px-2 py-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 w-8`,children:e.age}),(0,Z.jsx)(j_,{variant:`outline`,className:`text-[10px] shrink-0`,children:e.kind}),(0,Z.jsx)(`span`,{className:`flex-1 truncate`,children:e.question}),e.outcome&&(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 italic`,children:e.outcome})]},`${e.age}-${e.kind}-${e.question.slice(0,32)}`))})]})]})}function xb(){let{t:e}=W();return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ja,{className:`h-5 w-5 text-info`}),(0,Z.jsx)(`h3`,{className:`text-lg font-semibold`,children:e(`activity:shadow.shadowAgent`)})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`activity:shadow.theShadowAgentMonitorsAllFleet`)}),(0,Z.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Start and stop it from the chat with`,` `,(0,Z.jsx)(`code`,{className:`font-mono text-xs`,children:`/shadow start`}),` and`,` `,(0,Z.jsx)(`code`,{className:`font-mono text-xs`,children:`/shadow stop`}),`. This panel cannot control it yet.`]})]})}function Sb({disabled:e,direct:t}){let n=e?`bg-muted-foreground`:t?`bg-success`:`bg-info`,r=e?`disabled`:t?`direct provider tool`:`lazy catalog tool`;return(0,Z.jsx)(`span`,{className:`inline-block h-2 w-2 shrink-0 rounded-full ${n}`,title:r})}function Cb({tool:e,onToggle:t,busy:n}){let{t:r}=W(),[i,a]=(0,X.useState)(!1);return(0,Z.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border/70 bg-card/70 p-3 transition-colors hover:bg-card`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 sm:flex-row sm:items-start`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-2`,children:[(0,Z.jsx)(Sb,{disabled:e.disabled,direct:e.direct}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`code`,{className:`block truncate text-sm font-mono font-semibold`,title:e.name,children:e.name}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-1.5`,children:[(0,Z.jsx)(j_,{variant:`outline`,className:`px-1.5 text-[10px]`,children:e.permission}),(0,Z.jsx)(j_,{variant:`outline`,className:`px-1.5 text-[10px]`,children:e.mutating?`mutating`:`read-only`}),(0,Z.jsx)(j_,{variant:`outline`,className:`px-1.5 text-[10px]`,children:e.disabled?`disabled`:e.direct?`direct`:`lazy`}),(0,Z.jsx)(`span`,{className:`truncate text-[11px] text-muted-foreground`,title:e.owner,children:e.owner})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-1`,children:[(0,Z.jsxs)(Y,{variant:e.disabled?`default`:`secondary`,size:`sm`,className:`h-7 gap-1 px-2 text-xs`,onClick:t,disabled:n,children:[n?(0,Z.jsx)(mn,{className:`h-3 w-3 animate-spin`}):e.disabled?(0,Z.jsx)(Bt,{className:`h-3 w-3`}):(0,Z.jsx)(sn,{className:`h-3 w-3`}),e.disabled?`Enable`:`Disable`]}),(0,Z.jsx)(`button`,{type:`button`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,onClick:()=>a(!i),"aria-label":i?`Collapse`:`Expand`,children:(0,Z.jsx)(gn,{className:`h-4 w-4 transition-transform ${i?`rotate-180`:``}`})})]})]}),i&&(0,Z.jsxs)(`div`,{className:`space-y-1 border-t border-border/60 pt-2 text-xs text-muted-foreground sm:ml-4`,children:[(0,Z.jsx)(`p`,{children:e.description}),e.params.length>0&&(0,Z.jsxs)(`p`,{children:[r(`activity:toolsSec.params`),` `,(0,Z.jsx)(`code`,{className:`break-all font-mono`,children:e.params.join(`, `)})]})]})]})}function wb(){let{t:e}=W(),{client:t}=hf(),[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(!0),[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(new Set);(0,X.useEffect)(()=>{let e=t.on(`tools.list`,e=>{let t=e.payload;r(t.tools),a(!1)}),n=e=>{if(e.type===`tool.disabled`||e.type===`tool.enabled`){let n=e.payload;l(e=>{let t=new Set(e);return t.delete(n.name),t}),n.ok?t.send({type:`tools.list`},{echoToChat:!1}):B.error(`Tool "${n.name}" ${e.type===`tool.disabled`?`disable`:`enable`} failed.`)}},i=t.on(`tool.disabled`,n),o=t.on(`tool.enabled`,n);return()=>{e(),i(),o()}},[t]),(0,X.useEffect)(()=>{t.send({type:`tools.list`},{echoToChat:!1})},[t]);let u=(0,X.useCallback)((e,n)=>{l(t=>new Set(t).add(e)),t.send({type:n?`tool.enable`:`tool.disable`,payload:{name:e}})},[t]),d=o?n.filter(e=>e.name.toLowerCase().includes(o.toLowerCase())||e.owner.toLowerCase().includes(o.toLowerCase())):n,f=n.filter(e=>!e.disabled&&e.direct).length,p=n.filter(e=>!e.disabled&&!e.direct).length,m=n.filter(e=>e.disabled).length;return(0,Z.jsxs)(`div`,{className:`space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(_n,{className:`h-5 w-5`})}),(0,Z.jsx)(`h3`,{className:`text-base font-semibold`,children:e(`activity:toolsSec.tools`)})]}),!i&&(0,Z.jsxs)(`span`,{className:`rounded-md border border-border/60 bg-muted/30 px-2 py-1 text-xs text-muted-foreground sm:ml-auto`,children:[f,` direct · `,p,` lazy · `,m,` disabled · `,n.length,` `,`total`]})]}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(Tt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground`}),(0,Z.jsx)(ts,{placeholder:e(`activity:toolsSec.filterToolsByNameOrOwner`),value:o,onChange:e=>s(e.target.value),className:`pl-8 h-9 text-sm`})]}),i?(0,Z.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground gap-2`,children:[(0,Z.jsx)(mn,{className:`h-4 w-4 animate-spin`}),e(`activity:toolsSec.loadingTools`)]}):d.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground py-4 text-center`,children:o?`No tools matching "${o}".`:`No tools registered.`}):(0,Z.jsxs)(`div`,{className:`relative overflow-hidden rounded-lg border border-border/70 bg-background/35 shadow-inner`,children:[(0,Z.jsx)(`ul`,{className:`max-h-[min(58dvh,660px)] space-y-2 overflow-y-auto p-2 pr-3 [scrollbar-gutter:stable]`,"aria-label":e(`activity:toolsSec.toolsList`),children:d.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(Cb,{tool:e,onToggle:()=>u(e.name,e.disabled),busy:c.has(e.name)})},e.name))}),(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 top-0 h-4 bg-gradient-to-b from-background/90 to-transparent`}),(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-0 h-8 bg-gradient-to-t from-background/95 to-transparent`})]})]})}function Tb(){let{t:e}=W();return(0,Z.jsxs)(`div`,{className:`space-y-6`,children:[(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 pb-3 border-b border-border/50`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(ja,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`settings:security.brainHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`settings:security.brainHint`)})]})]}),(0,Z.jsx)(bb,{})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 pb-3 border-b border-border/50`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(ja,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`settings:security.shadowHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`settings:security.shadowHint`)})]})]}),(0,Z.jsx)(xb,{})]}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 pb-3 border-b border-border/50`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(ja,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:e(`settings:security.toolsHeading`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`settings:security.toolsHint`)})]})]}),(0,Z.jsx)(wb,{})]})]})}function Eb({laneIndex:e,currentLane:t,sessionProvider:n,sessionModel:r,open:i,onOpenChange:a,onPick:o}){let{t:s}=W(),{listSavedProviders:c,listProviderModels:l}=hf(),u=V(e=>e.wsUrl),d=G(e=>e.favoriteModels),f=G(e=>e.disabledModels),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)(0),[x,C]=(0,X.useState)([]),[w,T]=(0,X.useState)({}),E=(0,X.useRef)(null);(0,X.useEffect)(()=>{i&&(m(``),g(null),v(!1),b(0),requestAnimationFrame(()=>E.current?.focus()))},[i]),(0,X.useEffect)(()=>{if(!i)return;let e=S(u),t=e.on(`providers.saved`,e=>{let t=e.payload;C(t.providers??[])}),n=e.on(`provider.models`,e=>{let t=e.payload;T(e=>({...e,[t.provider]:t.models??[]}))});return c(),()=>{t(),n()}},[i,u,c]),(0,X.useEffect)(()=>{if(i)for(let e of x)w[e.id]||l(e.id)},[i,x,w,l]);let D=(0,X.useMemo)(()=>[...new Set(x.map(e=>e.id))].sort((e,t)=>e.localeCompare(t)),[x]),O=(0,X.useMemo)(()=>Jm(x,w,p,t.provider??n,t.model??r,h,_,d??[],f??[]),[x,w,p,t.provider,t.model,n,r,h,_,d,f]);(0,X.useEffect)(()=>{y>=O.length&&b(0)},[O.length,y]);let k=e=>{let t=O[e];t&&(o({provider:t.provider,model:t.model}),a(!1))};return(0,Z.jsx)(es,{open:i,onOpenChange:e=>{e||a(!1)},children:(0,Z.jsxs)(Zo,{className:`max-w-xl gap-0 p-0 overflow-hidden pt-[10dvh]`,showCloseButton:!1,onOpenAutoFocus:e=>{e.preventDefault(),E.current?.focus()},children:[(0,Z.jsx)(Qo,{className:`sr-only`,children:s(`activity:modelSwitcher.lanePickerTitle`,{index:e+1})}),(0,Z.jsx)($o,{className:`sr-only`,children:s(`activity:modelSwitcher.lanePickerDescription`,{index:e+1})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Z.jsx)(Tt,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,Z.jsx)(`input`,{ref:E,value:p,onChange:e=>{m(e.target.value),b(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),b(e=>Math.min(O.length-1,e+1))):e.key===`ArrowUp`?(e.preventDefault(),b(e=>Math.max(0,e-1))):e.key===`Enter`&&(e.preventDefault(),k(y))},placeholder:`Search provider or model…`,"aria-label":`Search models for lane ${e+1}`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground min-w-0`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{v(e=>!e),b(0)},title:`Show favorites only`,"aria-label":`Show favorites only`,"aria-pressed":_,className:K(`flex items-center gap-1 rounded-md px-2 py-1 text-xs transition-colors border shrink-0`,_?`bg-warning/15 border-warning/40 text-warning font-medium`:`bg-transparent border-border/70 text-muted-foreground hover:text-foreground hover:bg-muted/50`),children:[(0,Z.jsx)(ta,{className:K(`h-3.5 w-3.5`,_?`fill-warning text-warning`:`text-muted-foreground`)}),(0,Z.jsx)(`span`,{className:`text-[11px] whitespace-nowrap`,children:`Favorites`})]}),D.length>1&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Z.jsx)(zi,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Z.jsxs)(`select`,{value:h??``,onChange:e=>{g(e.target.value||null),b(0)},"aria-label":`Filter by provider`,className:`bg-transparent text-xs text-muted-foreground outline-none cursor-pointer border-0 min-w-0 truncate`,children:[(0,Z.jsx)(`option`,{value:``,children:`All providers`}),D.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]})]}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono shrink-0`,children:`↑↓ · Enter · Esc`}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>a(!1),"aria-label":`Close`,className:`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 text-muted-foreground`,children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),(t.tier||t.fallbackProfile)&&(0,Z.jsxs)(`div`,{className:`border-b bg-warning/5 px-3 py-1.5 text-[11px] text-warning`,children:[`Lane #`,e+1,` is currently pinned to`,` `,(0,Z.jsxs)(`span`,{className:`font-mono`,children:[t.tier?`tier:${t.tier}`:null,t.tier&&t.fallbackProfile?` · `:null,t.fallbackProfile?`profile:${t.fallbackProfile}`:null]}),`. Picking a model replaces this pin.`]}),(0,Z.jsxs)(`div`,{className:`max-h-[50dvh] overflow-y-auto py-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{o(null),a(!1)},className:`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors hover:bg-accent/40 text-muted-foreground`,children:[(0,Z.jsx)(On,{className:`h-4 w-4 shrink-0`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{children:`Inherit — routing / session`}),(0,Z.jsx)(`span`,{className:`block text-[10px] font-mono`,children:`leave the lane empty; routing decides`})]})]}),O.length===0?(0,Z.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:x.length===0?`No providers connected yet.`:Object.keys(w).length===0?`Loading models…`:_?d?.length?`No favorites match the search.`:`No favorites configured.`:`No matches.`}):O.map((e,i)=>{let a=e.provider===t.provider&&e.model===t.model,o=n&&r&&e.provider===n&&e.model===r,s=Km(e.provider,e.model,d);return(0,Z.jsxs)(`button`,{type:`button`,"data-lane-candidate":`true`,onClick:()=>k(i),onMouseEnter:()=>b(i),className:K(`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors`,i===y?`bg-accent text-accent-foreground`:`hover:bg-accent/40`,a&&`font-medium`),children:[(0,Z.jsx)(On,{className:K(`h-4 w-4 shrink-0`,a?`text-primary`:`text-muted-foreground`)}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 break-words`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.provider}),(0,Z.jsx)(`span`,{className:`text-muted-foreground/65`,children:`·`}),(0,Z.jsx)(`span`,{children:e.modelName}),s&&(0,Z.jsx)(`span`,{title:`Favorite model`,children:(0,Z.jsx)(ta,{className:`h-3 w-3 fill-warning text-warning shrink-0`})})]}),(e.contextWindow||e.reasoningEffortLevels)&&(0,Z.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono break-words`,children:[e.model,e.contextWindow?` · ctx ${e.contextWindow.toLocaleString()}`:``,e.reasoningEffortLevels?` · effort ${e.reasoningEffortLevels.join(`/`)}`:``]})]}),a?(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-primary font-semibold`,children:`on this lane`}):o?(0,Z.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground font-semibold`,children:`session model`}):(0,Z.jsx)(Cr,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100`})]},`${e.provider}:${e.model}`)})]})]})})}var Db=16,Ob=8;function kb(e){return e?.provider&&e.model?`${e.provider}/${e.model}`:e?.tier?`tier:${e.tier}`:e?.fallbackProfile?`profile:${e.fallbackProfile}`:``}function Ab(e){return!!(e?.provider||e?.model||e?.tier||e?.fallbackProfile)}function jb({syncPref:e}){let t=G(),[n,r]=(0,X.useState)(null),i=t.subagentModelPlan??{enabled:!0,lock:!0,slots:[]},a=i.slots.length>0?i.slots:Array.from({length:Ob},()=>({})),o=(0,X.useCallback)(t=>e(`subagentModelPlan`,{...i,slots:a,...t}),[a,i,e]),s=(0,X.useCallback)((e,t)=>o({slots:a.map((n,r)=>r===e?t:n)}),[a,o]),c=(0,X.useCallback)(e=>{let t=Math.max(1,Math.min(Db,e));o({slots:t<=a.length?a.slice(0,t):[...a,...Array.from({length:t-a.length},()=>({}))]})},[a,o]),l=a.filter(Ab).length,u=i.followSessionModel===!0,d=n===null?void 0:a[n];return(0,Z.jsxs)(`div`,{className:`pt-2`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold mb-1 mt-3 flex items-center gap-2`,children:[(0,Z.jsx)(Ir,{className:`h-4 w-4 text-muted-foreground`}),`Subagent models (this session)`]}),(0,Z.jsx)(`p`,{className:`mb-3 text-xs text-muted-foreground`,children:`Each running subagent takes the first free lane, so parallel workers run on different models. Scoped to this tab’s session and restored by resume — config.json is untouched. Model routing above is left intact: a role you routed there keeps its model.`}),(0,Z.jsxs)(`label`,{className:`mb-3 flex items-center gap-2 rounded-md border border-border/60 bg-card/50 px-2 py-1.5 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>o({followSessionModel:e.target.checked})}),(0,Z.jsxs)(`span`,{children:[`Use my model for all subagents`,(0,Z.jsx)(`span`,{className:`block text-[10px] text-muted-foreground`,children:`Every plain subagent runs on this session’s model. Outranks the lanes below.`})]})]}),(0,Z.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-4`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:i.enabled!==!1,onChange:e=>o({enabled:e.target.checked})}),`Enabled`]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:i.lock!==!1,onChange:e=>o({lock:e.target.checked})}),`Lanes override the leader`]}),(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[`Lanes`,(0,Z.jsx)(`input`,{type:`number`,min:1,max:Db,value:a.length,disabled:u,onChange:e=>c(Number.parseInt(e.target.value,10)||1),className:`h-8 w-16 rounded-md border bg-background px-2 text-xs`})]}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:l===0?`no lane pinned — spawns resolve as before`:`${l} pinned`})]}),(0,Z.jsx)(`div`,{className:`space-y-1.5 ${u?`pointer-events-none opacity-50`:``}`,children:a.map((e,t)=>{let n=kb(e),i=Ab(e);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1.5 text-xs`,children:[(0,Z.jsxs)(`span`,{className:`w-14 shrink-0 font-mono text-muted-foreground`,children:[`#`,t+1]}),(0,Z.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r(t),"aria-label":`Lane ${t+1} model${i?`: ${n}`:``}`,className:`h-8 min-w-0 flex-1 truncate rounded-md border bg-background px-2 text-left font-mono text-xs hover:border-primary/40 disabled:cursor-not-allowed`,children:i?n:`inherit — routing / session`}),(0,Z.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Clear lane ${t+1}`,disabled:u||!i,onClick:()=>s(t,{}),children:(0,Z.jsx)(hn,{className:`h-3.5 w-3.5`})})]},`lane-${t}`)})}),n!==null&&(0,Z.jsx)(Eb,{laneIndex:n,currentLane:d??{},open:!0,onOpenChange:e=>{e||r(null)},onPick:e=>{s(n,e?{provider:e.provider,model:e.model}:{}),r(null)}})]})}function Mb(e,t,n,r,i){e.set({[r]:i}),t({[r]:i}),r===`contextMode`&&typeof i==`string`&&n(i)}var Nb=[{id:`general`,icon:(0,Z.jsx)(Ii,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.general`,descKey:`settings:tabs.generalDesc`},{id:`fonts`,icon:(0,Z.jsx)(rn,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.fonts`,descKey:`settings:tabs.fontsDesc`},{id:`provider`,icon:(0,Z.jsx)(pa,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.provider`,descKey:`settings:tabs.providerDesc`},{id:`connection`,icon:(0,Z.jsx)(Yi,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.connection`,descKey:`settings:tabs.connectionDesc`},{id:`agent`,icon:(0,Z.jsx)(on,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.agent`,descKey:`settings:tabs.agentDesc`},{id:`execution`,icon:(0,Z.jsx)(mi,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.execution`,descKey:`settings:tabs.executionDesc`},{id:`fallbacks`,icon:(0,Z.jsx)(tr,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.fallbacks`,descKey:`settings:tabs.fallbacksDesc`},{id:`routing`,icon:(0,Z.jsx)(It,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.routing`,descKey:`settings:tabs.routingDesc`},{id:`fleet`,icon:(0,Z.jsx)(Kt,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.fleet`,descKey:`settings:tabs.fleetDesc`},{id:`integrations`,icon:(0,Z.jsx)(er,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.integrations`,descKey:`settings:tabs.integrationsDesc`},{id:`chimera`,icon:(0,Z.jsx)(Jn,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.chimera`,descKey:`settings:tabs.chimeraDesc`},{id:`context`,icon:(0,Z.jsx)(Vn,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.context`,descKey:`settings:tabs.contextDesc`},{id:`logs`,icon:(0,Z.jsx)(mt,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.logs`,descKey:`settings:tabs.logsDesc`},{id:`security`,icon:(0,Z.jsx)(ei,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.security`,descKey:`settings:tabs.securityDesc`},{id:`display`,icon:(0,Z.jsx)(Ii,{className:`h-3.5 w-3.5`}),labelKey:`settings:tabs.display`,descKey:`settings:tabs.displayDesc`}];function Pb(){let{settingsActiveTab:e,setSettingsActiveTab:t}=q(Yr(e=>({settingsActiveTab:e.settingsActiveTab,setSettingsActiveTab:e.setSettingsActiveTab}))),n=Jg(`settings`),r=(0,X.useRef)(!1),[i,a]=(0,X.useState)(!1),{provider:o,model:s,setProvider:c,setModel:l,wsConnected:u}=V(Yr(e=>({provider:e.provider,model:e.model,setProvider:e.setProvider,setModel:e.setModel,wsConnected:e.wsConnected}))),d=hf(),f=d.client,{updatePrefs:p,switchAutonomy:m,switchContextMode:h}=d,g=G(),{t:_}=W(),v=m_(!0),y=(0,X.useCallback)((e,t)=>{Mb(g,p,h,e,t)},[g,p,h]),[b,x]=(0,X.useState)([]),[S,C]=(0,X.useState)({}),[w,T]=(0,X.useState)([]),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(`catalog`),[P,F]=(0,X.useState)(``),[I,L]=(0,X.useState)(!1),ee=(0,X.useCallback)(()=>{g.reset(),L(!1),window.location.reload()},[g]),R=b.find(e=>e.id===o),z=(0,X.useMemo)(()=>({...S,[o]:(S[o]??[]).filter(e=>!qm(o,e.id,g.disabledModels))}),[S,g.disabledModels,o]),te=Nb.find(t=>t.id===e);(0,X.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;x(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),D(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;C(e=>({...e,[t.provider]:t.models})),k(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));T(t),j(!1),t.length>0&&N(`saved`)}};if(!u||!f)return;let r=f.on(`provider.catalog`,e),i=f.on(`provider.models`,t),a=f.on(`providers.saved`,n);return D(!0),j(!0),f.listProviders(),f.listSavedProviders(),()=>{r?.(),i?.(),a?.()}},[u,f]);let ne=(0,X.useCallback)(e=>{c(e),S[e]||(k(!0),d.listProviderModels?.(e))},[S,c,d]),re=(0,X.useCallback)(async e=>{if(r.current)return;let t=V.getState().model,n=V.getState().provider;if(n&&e!==t){r.current=!0,a(!0),l(e);try{B.info(U.t(`settings:toast.switchingTo`,{provider:n,model:e}));let r=await d.switchModel?.(n,e);r?.success?B.success(U.t(r.runActive?`settings:toast.modelSwitchedRunActive`:`settings:toast.modelSwitchedNextRequest`,{from:`${n} / ${t}`,to:`${n} / ${e}`})):(l(t),B.error(r?.message??U.t(`settings:toast.modelSwitchTimeout`)))}finally{r.current=!1,a(!1)}}},[l,d]),ie=(0,X.useCallback)((e,t,n)=>{d.addKey?.(e,t,n)},[d]),ae=(0,X.useCallback)((e,t)=>{d.deleteKey?.(e,t)},[d]),oe=(0,X.useCallback)((e,t)=>{d.setActiveKey?.(e,t)},[d]),se=(0,X.useCallback)((e,t,n,r,i,a)=>{d.addProvider?.(e,t,n,r,i,a)},[d]),ce=(0,X.useCallback)(e=>{d.removeProvider?.(e)},[d]),le=(0,X.useCallback)((e,t)=>{d.client.updateProvider({id:e,models:[t]}),e===V.getState().provider&&l(t)},[l,d.client]);return(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col bg-gradient-to-b from-background/90 via-background/60 to-background/80`,children:[(0,Z.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-3 border-b border-border/60 bg-card/60 backdrop-blur-xl shrink-0 shadow-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(xa,{className:`h-5 w-5`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h1`,{className:`text-lg font-semibold bg-gradient-to-r from-foreground to-foreground/70 bg-clip-text text-transparent`,children:_(`settings:title`)}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:o&&s?`${o} / ${s}`:_(`settings:subtitle`)})]})]}),(0,Z.jsx)(Y,{variant:`ghost`,size:`icon`,onClick:()=>Va(`chat`),children:(0,Z.jsx)(hn,{className:`h-4 w-4`})}),(0,Z.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:()=>L(!0),children:_(`settings:resetLabel`)})]}),(0,Z.jsx)(bp,{className:`min-h-0 flex-1`,ref:n,children:(0,Z.jsx)(`div`,{className:`mx-auto max-w-7xl p-4 sm:p-6`,children:(0,Z.jsxs)(Sp,{value:e,onValueChange:t,className:`grid min-h-[calc(100dvh-9rem)] gap-3 lg:grid-cols-[13.5rem_minmax(0,1fr)] lg:gap-5`,children:[(0,Z.jsxs)(`div`,{className:`relative min-w-0`,children:[(0,Z.jsx)(Cp,{className:`flex h-auto w-full justify-start gap-0.5 overflow-x-auto rounded-lg border border-border/60 bg-card/60 p-1.5 shadow-sm [scrollbar-gutter:stable] lg:sticky lg:top-4 lg:flex-col lg:overflow-visible lg:rounded-xl lg:bg-card/60 lg:p-2`,children:Nb.map(e=>(0,Z.jsxs)(wp,{value:e.id,className:`h-9 shrink-0 gap-2.5 rounded-md px-3 text-xs scroll-mt-2 data-[state=active]:bg-primary/10 data-[state=active]:text-primary data-[state=active]:shadow-sm lg:w-full lg:justify-start lg:px-3`,children:[(0,Z.jsx)(`span`,{className:`shrink-0`,children:e.icon}),(0,Z.jsx)(`span`,{className:`truncate`,children:_(e.labelKey)})]},e.id))}),(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-y-1 left-0 z-10 w-8 rounded-l-lg bg-gradient-to-r from-background via-background/90 to-transparent lg:hidden`}),(0,Z.jsx)(`div`,{className:`pointer-events-none absolute inset-y-1 right-0 z-10 w-8 rounded-r-lg bg-gradient-to-l from-background via-background/90 to-transparent lg:hidden`})]}),(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-0`,children:[te?.descKey&&(0,Z.jsxs)(`div`,{className:`mb-4 flex items-start gap-3 rounded-xl border border-border/60 bg-card/50 px-4 py-3`,children:[(0,Z.jsx)(`span`,{className:`mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary`,children:te.icon}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-semibold`,children:_(te.labelKey)}),(0,Z.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:_(te.descKey)})]})]}),(0,Z.jsx)(Tp,{value:`general`,className:`mt-0`,children:(0,Z.jsx)(R_,{})}),(0,Z.jsx)(Tp,{value:`fonts`,className:`mt-0`,children:(0,Z.jsx)(Cv,{})}),(0,Z.jsxs)(Tp,{value:`provider`,className:`mt-0 space-y-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-xl border border-primary/25 bg-primary/5 p-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-sm font-semibold`,children:`Provider Test`}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Test every model on a saved provider or subscription and inspect quota, authentication, latency, and token-limit failures.`})]}),(0,Z.jsx)(Y,{size:`sm`,onClick:()=>Ha(`provider-test`),children:`Open Provider Test`})]}),(0,Z.jsx)(Py,{activeProvider:o,catalogProviders:b,isLoadingCatalog:E,savedProviders:w,isLoadingSaved:A,providerTab:M,setProviderTab:N,onSelectProvider:ne,onAddKey:ie,onDeleteKey:ae,onSetActiveKey:oe,onAddProvider:se,onRemoveProvider:ce,onPickProviderModel:le,ws:d.client,catalogQuery:P,setCatalogQuery:F}),(0,Z.jsxs)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:[(0,Z.jsxs)(`h3`,{className:`text-sm font-semibold mb-4 flex items-center gap-2`,children:[(0,Z.jsx)(On,{className:`h-4 w-4 text-muted-foreground`}),_(`settings:model.heading`)]}),(0,Z.jsx)(Fv,{provider:o,catalogModels:z,currentCatalogProvider:R,isLoadingModels:O,setIsLoadingModels:k,onModelSelect:re,isSwitching:i,refreshModels:e=>d.listProviderModels?.(e)}),(0,Z.jsx)(Pv,{syncPref:y})]})]}),(0,Z.jsx)(Tp,{value:`connection`,className:`mt-0`,children:(0,Z.jsx)(L_,{})}),(0,Z.jsx)(Tp,{value:`agent`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(x_,{syncPref:y,switchAutonomy:m})}),(0,Z.jsx)(Tp,{value:`execution`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(av,{syncPref:y,fallbackCandidates:v})}),(0,Z.jsx)(Tp,{value:`fallbacks`,className:`mt-0`,children:(0,Z.jsx)(fv,{syncPref:y,candidates:v,provider:o,activeModel:s,setProvider:c,setModel:l,switchModel:d.switchModel})}),(0,Z.jsxs)(Tp,{value:`routing`,className:`mt-0`,children:[(0,Z.jsx)(qy,{syncPref:y,candidates:v}),(0,Z.jsx)(`div`,{className:`mt-6 border-t border-border pt-6`,children:(0,Z.jsx)(Rv,{syncPref:y})}),(0,Z.jsx)(`div`,{className:`mt-6 border-t border-border pt-6`,children:(0,Z.jsx)(jb,{syncPref:y,candidates:v})})]}),(0,Z.jsx)(Tp,{value:`fleet`,className:`mt-0`,children:(0,Z.jsx)(pv,{syncPref:y})}),(0,Z.jsx)(Tp,{value:`integrations`,className:`mt-0`,children:(0,Z.jsx)(Mv,{syncPref:y})}),(0,Z.jsx)(Tp,{value:`chimera`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(`div`,{className:`rounded-xl border border-border/70 bg-card/80 p-5 shadow-sm`,children:(0,Z.jsx)(z_,{syncPref:y,sessionProvider:o,sessionModel:s})})}),(0,Z.jsx)(Tp,{value:`context`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(G_,{syncPref:y})}),(0,Z.jsx)(Tp,{value:`logs`,className:`mt-0 space-y-6`,children:(0,Z.jsx)(Nv,{syncPref:y})}),(0,Z.jsx)(Tp,{value:`security`,className:`mt-0`,children:(0,Z.jsx)(Tb,{})}),(0,Z.jsx)(Tp,{value:`display`,className:`mt-0`,children:(0,Z.jsx)(X_,{syncPref:y})})]})]})})}),(0,Z.jsx)(es,{open:I,onOpenChange:L,children:(0,Z.jsxs)(Zo,{showCloseButton:!1,children:[(0,Z.jsxs)(Yo,{children:[(0,Z.jsx)(Qo,{children:_(`settings:resetConfirmTitle`)}),(0,Z.jsx)($o,{children:_(`settings:resetConfirmBody`)})]}),(0,Z.jsxs)(Xo,{className:`gap-2 sm:gap-0`,children:[(0,Z.jsx)(Y,{variant:`outline`,onClick:()=>L(!1),children:_(`settings:cancel`)}),(0,Z.jsx)(Y,{variant:`destructive`,onClick:ee,children:_(`settings:resetConfirmAction`)})]})]})})]})}var Fb=(0,X.lazy)(()=>La(()=>import(`./AnalyticsDashboard-DGQk1vSi.js`).then(e=>({default:e.AnalyticsDashboard})),__vite__mapDeps([18,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22]))),Ib=(0,X.lazy)(()=>La(()=>import(`./AgentRosterView-DMxOg0xX.js`).then(e=>({default:e.AgentRosterView})),__vite__mapDeps([23,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,25,26,27,28,29,30,31]))),Lb=(0,X.lazy)(()=>La(()=>import(`./ChangesView-C8x8tmpi.js`).then(e=>({default:e.ChangesView})),__vite__mapDeps([32,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,33,34,35,36]))),Rb=(0,X.lazy)(()=>La(()=>import(`./RepositoryHistoryView-D0ynYRgu.js`).then(e=>({default:e.RepositoryHistoryView})),__vite__mapDeps([37,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,27]))),zb=(0,X.lazy)(()=>La(()=>import(`./ChronicleDashboard-CvDPqZKE.js`).then(e=>({default:e.ChronicleDashboard})),__vite__mapDeps([38,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]))),Bb=(0,X.lazy)(()=>La(()=>import(`./CodeEditor-s0lHP0DZ.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([39,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,33,34,35,36,40,28,30]))),Vb=(0,X.lazy)(()=>La(()=>import(`./CodeMap-6mmDO9gJ.js`).then(e=>({default:e.CodeMap})),__vite__mapDeps([41,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,21,17]))),Hb=(0,X.lazy)(()=>La(()=>import(`./DebugDashboard-BP1Mia-L.js`).then(e=>({default:e.DebugDashboard})),__vite__mapDeps([42,1,2,3,4,5,6,7,8,9,10,11,12,13,14]))),Ub=(0,X.lazy)(()=>La(()=>import(`./DesignGalleryView-taDxRN63.js`).then(e=>({default:e.DesignGalleryView})),__vite__mapDeps([43,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24]))),Wb=(0,X.lazy)(()=>La(()=>import(`./GoalView-CcLxMYXe.js`).then(e=>({default:e.GoalView})),__vite__mapDeps([44,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,24,16,19,0,17,20,21,22,28]))),Gb=(0,X.lazy)(()=>La(()=>import(`./KanbanView-C-K6OBw8.js`).then(e=>({default:e.KanbanView})),__vite__mapDeps([45,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,27,46]))),Kb=(0,X.lazy)(()=>La(()=>import(`./MailboxDetailView-N00dLbpr.js`).then(e=>({default:e.MailboxDetailView})),__vite__mapDeps([47,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,24,16,22,35]))),qb=(0,X.lazy)(()=>La(()=>import(`./PromptJournalView-CdC4ldrv.js`).then(e=>({default:e.PromptJournalView})),__vite__mapDeps([48,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]))),Jb=(0,X.lazy)(()=>La(()=>import(`./RefreshDebugView-Dbq_bHwj.js`).then(e=>({default:e.RefreshDebugView})),__vite__mapDeps([49,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,20]))),Yb=(0,X.lazy)(()=>La(()=>import(`./SageTabs-Dwbux3im.js`).then(e=>({default:e.SageTabs})),__vite__mapDeps([50,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Xb=(0,X.lazy)(()=>La(()=>import(`./RequirementIntakeView-CPRtncuJ.js`).then(e=>({default:e.RequirementIntakeView})),__vite__mapDeps([51,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,28,29]))),Zb=(0,X.lazy)(()=>La(()=>import(`./SddHub-CoRKeq7Q.js`).then(e=>({default:e.SddHub})),__vite__mapDeps([52,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,24,16,19,0,17,20,21,22,27,28,46]))),Qb=(0,X.lazy)(()=>La(()=>import(`./SessionsDashboard-CaSXukNy.js`).then(e=>({default:e.SessionsDashboard})),__vite__mapDeps([53,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,54]))),$b=(0,X.lazy)(()=>La(()=>import(`./SessionInspectView-Bak1hK82.js`).then(e=>({default:e.SessionInspectView})),__vite__mapDeps([55,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,54,19,20,21,22]))),ex=(0,X.lazy)(()=>La(()=>import(`./SkillDetailView-OdtAJM43.js`).then(e=>({default:e.SkillDetailView})),__vite__mapDeps([56,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,24,16,17,27,35]))),tx=(0,X.lazy)(()=>La(()=>import(`./TechStackView-BUIbnU2F.js`).then(e=>({default:e.TechStackView})),__vite__mapDeps([57,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,19,0,16,17,20,21,22,28,29]))),nx=(0,X.lazy)(()=>La(()=>import(`./DeadCodeScanPanel-ByhAW_bl.js`).then(e=>({default:e.DeadCodeScanPanel})),__vite__mapDeps([58,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17]))),rx=(0,X.lazy)(()=>La(()=>import(`./ChimeraReviewsView-DencEMIY.js`).then(e=>({default:e.ChimeraReviewsView})),__vite__mapDeps([59,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,35]))),ix=(0,X.lazy)(()=>La(()=>import(`./SetupScreen-BSEF1air.js`).then(e=>({default:e.SetupScreen})),__vite__mapDeps([60,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,27,28,29]))),ax={"provider-test":{Component:(0,X.lazy)(()=>La(()=>import(`./ProviderTestView-Dy7EQEI9.js`).then(e=>({default:e.ProviderTestView})),__vite__mapDeps([61,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,24,19,20,21,22,27,28,29]))),wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:nav.provider-test`,loadingLabelKey:`activity:nav.provider-test`},settings:{Component:Pb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.settings`,loadingLabelKey:null},memory:{Component:Yb,wrapperClassName:``,boundaryNameKey:`activity:panels.sageMemory`,loadingLabelKey:`activity:panels.sageMemory`},roster:{Component:Ib,wrapperClassName:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,boundaryNameKey:`activity:panels.agentRoster`,loadingLabelKey:`activity:panels.agentRoster`},context:{Component:p_,wrapperClassName:``,boundaryNameKey:`activity:panels.contextDashboard`,loadingLabelKey:null},setup:{Component:ix,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.setup`,loadingLabelKey:null},goal:{Component:Wb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.goal`,loadingLabelKey:null,props:{onClose:`PANEL_CLOSE_TO_CHAT`}},sddhub:{Component:Zb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.sddHub`,loadingLabelKey:null},kanban:{Component:Gb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.kanban`,loadingLabelKey:null,props:{onClose:`PANEL_CLOSE_TO_CHAT`}},sessions:{Component:Qb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.sessions`,loadingLabelKey:null},"session-inspect":{Component:$b,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.sessionInspect`,loadingLabelKey:`activity:panels.sessionInspect`},chronicle:{Component:zb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.chronicle`,loadingLabelKey:null},intake:{Component:Xb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.requirementsIntake`,loadingLabelKey:null},prompts:{Component:qb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:nav.prompts`,loadingLabelKey:`activity:nav.prompts`},debug:{Component:Hb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.debugDashboard`,loadingLabelKey:null},"refresh-debug":{Component:Jb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.refreshDebug`,loadingLabelKey:`activity:panels.refreshDebug`},files:{Component:Bb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.editor`,loadingLabelKey:`activity:panels.editor`},changes:{Component:Lb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.changes`,loadingLabelKey:`activity:panels.changes`,props:{className:`h-full min-h-0`}},history:{Component:Rb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:nav.repositoryHistory`,loadingLabelKey:`activity:nav.repositoryHistory`},mailbox:{Component:Kb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.mailbox`,loadingLabelKey:null,props:{className:`h-full min-h-0`}},"design-gallery":{Component:Ub,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.designGallery`,loadingLabelKey:null,props:{className:`h-full`}},skill:{Component:ex,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.skill`,loadingLabelKey:null,props:{className:`h-full`}},analytics:{Component:Fb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.analytics`,loadingLabelKey:null},codemap:{Component:Vb,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.codemap`,loadingLabelKey:`activity:panels.codemap`},techstack:{Component:tx,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:panels.techstack`,loadingLabelKey:`activity:panels.techstack`},deadcode:{Component:nx,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-y-auto`,boundaryNameKey:`activity:panels.deadcode`,loadingLabelKey:`activity:panels.deadcode`},chimera:{Component:rx,wrapperClassName:`flex-1 min-h-0 min-w-0 overflow-hidden`,boundaryNameKey:`activity:nav.chimera`,loadingLabelKey:null}};function ox({view:e,onCloseToChat:t}){let{t:n}=W(),r=ax[e];if(!r)return null;let i=r.Component,a={...r.props??{}};for(let[e,n]of Object.entries(a))n===`PANEL_CLOSE_TO_CHAT`&&(a[e]=t);let o=r.wrapperClassName?(0,Z.jsx)(`div`,{className:r.wrapperClassName,children:(0,Z.jsx)(i,{...a})}):(0,Z.jsx)(i,{...a}),s=r.loadingLabelKey?(0,Z.jsx)(qg,{label:n(`common:loadingNamed`,{name:n(r.loadingLabelKey)})}):(0,Z.jsx)(qg,{});return(0,Z.jsx)(_p,{level:`panel`,name:n(r.boundaryNameKey),children:(0,Z.jsx)(X.Suspense,{fallback:s,children:o})})}function sx(){Va(`chat`)}function cx(e){try{return new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return e}}function lx(e){switch(e){case`active`:return`text-success border-success/30 bg-success/[0.06]`;case`injected`:return`text-primary border-primary/30 bg-primary/[0.06]`;case`exited`:return`text-muted-foreground border-border/40 bg-muted/20`;default:return`text-muted-foreground border-border/40 bg-muted/20`}}function ux(e){switch(e){case`fact`:return`text-primary`;case`decision`:return`text-accent2`;case`convention`:return`text-ring`;case`warning`:case`anti_pattern`:return`text-warning`;case`bug_root_cause`:return`text-destructive`;case`preference`:return`text-accent`;default:return`text-muted-foreground`}}function dx(e){return e>=.9?`crit`:e>=.6?`high`:e>=.3?`med`:`low`}var fx=(0,X.memo)(function({open:e,onClose:t}){let{t:n}=W(),r=Ml(e=>e.traces),i=Ml(e=>e.contextMemories),a=Ml(e=>e.transitions),o=Ml(e=>e.clear);(0,X.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]);let s=r[0],c=Object.values(i),l=c.filter(e=>e.state!==`exited`),u=c.length-l.length,d=s?Object.values(s.rejected).reduce((e,t)=>e+t,0):0;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:K(`fixed inset-0 z-40 bg-background/50 backdrop-blur-[1px] transition-opacity duration-200`,e?`opacity-100`:`pointer-events-none opacity-0`),onClick:t,"aria-hidden":!0}),(0,Z.jsx)(`aside`,{className:K(`fixed right-0 top-0 z-50 h-full w-full max-w-md border-l border-border/60 bg-card/95 backdrop-blur-xl shadow-2xl`,`transition-transform duration-300 ease-out`,e?`translate-x-0`:`translate-x-full`),role:`dialog`,"aria-label":n(`activity:sageMemory.injectedHeading`,`Memory Context`),"data-testid":`memory-injector-panel`,children:(0,Z.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/60 px-4 py-3 shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Jn,{className:`size-4 text-primary`}),(0,Z.jsx)(`h2`,{className:`text-sm font-semibold text-foreground`,children:n(`activity:sageMemory.injectedHeading`,`Memory Context`)}),l.length>0&&(0,Z.jsxs)(`span`,{className:`rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-bold text-primary tabular-nums`,children:[l.length,` active`]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r.length>0&&(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:`rounded-md px-2 py-1 text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:n(`activity:memoryManager.clearTracesTitle`),children:`Clear`}),(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-md p-1.5 text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:n(`activity:memoryManager.closePanelTitle`),children:(0,Z.jsx)(Qi,{className:`size-4`})})]})]}),s&&(0,Z.jsxs)(`div`,{className:`shrink-0 border-b border-border/40 bg-muted/20 px-4 py-2`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] tabular-nums`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(ti,{className:`size-3 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`font-mono text-foreground`,children:s.candidates}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceMatched`)})]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-success`,children:s.injected.length}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceInjected`)})]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-warning`,children:d}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceFiltered`)})]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-ring`,children:l.length}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceActive`)})]}),u>0&&(0,Z.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:u}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:memoryManager.traceExited`)})]})]}),(0,Z.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[10px] text-muted-foreground/80`,children:[(0,Z.jsx)(la,{className:`size-3`}),(0,Z.jsx)(`span`,{children:cx(s.at)}),(0,Z.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-mono`,children:s.trigger}),s.toolName&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-mono`,children:s.toolName})]}),(0,Z.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,Z.jsxs)(`span`,{children:[`ctx `,Math.round(s.contextPressure*100),`%`]})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto overscroll-contain`,children:[l.length>0?(0,Z.jsxs)(`div`,{className:`space-y-0`,children:[(0,Z.jsx)(`div`,{className:`sticky top-0 z-10 bg-card/95 backdrop-blur-sm px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-muted-foreground border-b border-border/40`,children:n(`activity:memoryManager.injectorActiveInContext`)}),l.map(e=>(0,Z.jsxs)(`div`,{className:`border-b border-border/30 px-4 py-3 hover:bg-muted/15 transition-colors`,children:[(0,Z.jsx)(`div`,{className:`flex items-start gap-2`,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 shrink-0`,children:[(0,Z.jsx)(`span`,{className:K(`rounded border px-1 py-0.5 text-[9px] font-bold uppercase`,ux(e.kind)),children:e.kind}),(0,Z.jsx)(`span`,{className:K(`rounded border px-1 py-0.5 text-[9px] font-bold uppercase`,lx(e.state)),children:dx(e.importance)})]})}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[12px] leading-relaxed text-foreground/90 break-words`,children:e.isPlaceholder?(0,Z.jsx)(`span`,{className:`italic text-muted-foreground`,children:e.text}):e.text}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[10px] text-muted-foreground/70`,children:[(0,Z.jsxs)(`span`,{className:`font-mono`,children:[e.id.slice(0,16),`…`]}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Z.jsx)(`span`,{className:`opacity-60`,children:n(`activity:memoryManager.traceScore`)}),(0,Z.jsx)(`span`,{className:`font-mono text-foreground/60`,children:e.score.toFixed(2)})]}),e.trigger&&(0,Z.jsx)(`span`,{className:`font-mono`,children:e.trigger}),(0,Z.jsx)(`span`,{children:cx(e.lastSeenAt)})]}),e.tags.length>0&&(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-1`,children:[(0,Z.jsx)(Xi,{className:`size-2.5 text-muted-foreground/50`}),e.tags.slice(0,6).map(e=>(0,Z.jsx)(`span`,{className:`rounded bg-muted/40 px-1 py-0.5 text-[9px] text-muted-foreground/80`,children:e},e))]}),e.anchors.length>0&&(0,Z.jsxs)(`div`,{className:`mt-1 text-[10px] text-muted-foreground/60 font-mono truncate`,children:[`↳ `,e.anchors.slice(0,2).join(`, `)]})]},e.id))]}):(0,Z.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-muted-foreground/60`,children:r.length===0?`No memory injections yet. Memories will appear here when the agent reads files or searches code.`:`No memories currently active in provider context.`}),r.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`sticky top-0 z-10 bg-card/95 backdrop-blur-sm px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-muted-foreground border-t border-border/40 border-b`,children:n(`activity:memoryManager.injectorInjectionHistory`)}),r.slice(0,20).map(e=>{let t=Object.values(e.rejected).reduce((e,t)=>e+t,0);return(0,Z.jsxs)(`div`,{className:`border-b border-border/30 px-4 py-2.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] tabular-nums`,children:[(0,Z.jsx)(la,{className:`size-3 text-muted-foreground/60`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:cx(e.at)}),(0,Z.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-mono text-foreground/80`,children:e.trigger}),e.toolName&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Z.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:e.toolName})]})]}),(0,Z.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-3 text-[10px] tabular-nums text-muted-foreground/70`,children:[(0,Z.jsxs)(`span`,{className:`text-success`,children:[e.injected.length,` injected`]}),(0,Z.jsxs)(`span`,{className:`text-warning`,children:[t,` filtered`]}),(0,Z.jsxs)(`span`,{children:[e.candidates,` candidates`]}),(0,Z.jsxs)(`span`,{children:[`ctx `,Math.round(e.contextPressure*100),`%`]}),e.outcome===`error`&&(0,Z.jsx)(`span`,{className:`text-destructive`,children:n(`activity:memoryManager.traceError`)})]})]},e.runId)})]}),a.length>0&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`sticky top-0 z-10 bg-card/95 backdrop-blur-sm px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-muted-foreground border-t border-border/40 border-b`,children:n(`activity:memoryManager.injectorContextTransitions`)}),a.slice(0,15).map(e=>(0,Z.jsxs)(`div`,{className:`border-b border-border/20 px-4 py-1.5 flex items-center gap-2 text-[10px] tabular-nums`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground/60`,children:cx(e.at)}),(0,Z.jsx)(`span`,{className:K(`rounded px-1 py-0.5 text-[9px] font-bold uppercase`,e.action===`injected`&&`bg-primary/10 text-primary`,e.action===`entered`&&`bg-success/10 text-success`,e.action===`exited`&&`bg-muted/40 text-muted-foreground`),children:e.action}),(0,Z.jsxs)(`span`,{className:`font-mono text-muted-foreground truncate`,children:[e.memoryId.slice(0,14),`…`]}),(0,Z.jsx)(`span`,{className:`text-muted-foreground/50 truncate ml-auto`,children:e.reason})]},e.id))]})]})]})})]})});function px(e){return e.replace(/\\/g,`/`).split(`/`).pop()??e}function mx(e){if(e.kind===`file`)return e.path;let t=e.kind===`snippet`?e.content:e.preview,n=t.split(`
115
115
  `).slice(0,6).join(`
116
116
  `);return`${e.path}:${e.startLine}-${e.endLine}\n${n}${t.split(`
117
117
  `).length>6?`
@@ -126,7 +126,7 @@ AWS_REGION=us-east-1`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,
126
126
  `);if(u.startsWith(`/`)&&b(m)){re(),f(u);return}let h=!1,g=k.reduce((e,t)=>e+ +(t.role===`user`),0);if(r===`btw`&&!o&&E?.isConnected&&E.supportsCapability(`context.topic-boundary`)&&g>=5){_.current=!0,y(!0);let e=new AbortController;v.current=e;try{let t=await O(m);if(e.signal.aborted)return;if(t.suggestNewContext){let n=await ep({title:S(`chat:input.topicShiftTitle`),message:S(`chat:input.topicShiftMessage`,{reason:t.reason,topic:t.nextTopic??S(`chat:input.topicShiftUnnamed`)}),confirmLabel:S(`chat:input.topicShiftFresh`),cancelLabel:S(`chat:input.topicShiftSame`),defaultAction:`cancel`});if(e.signal.aborted||n===`dismiss`)return;h=n===`confirm`}}catch{}finally{_.current=!1,y(!1),v.current===e&&(v.current=null)}}re(),f(u);let x=i.current,D=x.map(e=>({id:e.id,kind:`image`,dataUrl:e.dataUrl,mediaType:e.mediaType,bytes:e.bytes,name:e.name}));if(r===`queue`){l(m,`queue`,x.length>0?x:void 0),a();return}let M=r===`steer`&&o;if(r===`btw`&&o){if(x.length>0){l(m,`queue`,x),a();return}if(E?.isConnected){let e=!1;try{T({type:`btw`,to:`leader`,subject:`btw from WebUI`,body:m,priority:`normal`,audience:`all`}),e=!0}catch(e){console.warn(JSON.stringify({level:`warn`,event:`ws_btw_send_failed`,reason:`send_error`,error:Pa(e),timestamp:new Date().toISOString()}))}l(m,`btw`,void 0,e)}else console.warn(JSON.stringify({level:`warn`,event:`ws_btw_send_failed`,reason:`not_connected`,timestamp:new Date().toISOString()})),l(m,`btw`);a();return}M&&w();try{if(E?.isConnected){if(d&&x.length===0){let e=L?ee[L]?.[0]:void 0,t=e?.indexOf(`/`)??-1,r=e?t>0?e.slice(0,t):N:F||N,i=e?t>0?e.slice(t+1):e:I||P;z({original:m,refined:m,english:m,status:`countdown`,resolve:e=>{},provider:r,model:i,...n?{sessionId:n}:{},...h?{freshContext:!0}:{}})}else{let e=x.length>0?Ga(x):void 0,t=h?C(m,e,!0):C(m,e);if(!t){B.error(S(`chat:input.notConnectedDraftKept`));return}c({id:t,role:`user`,content:m,...D.length>0?{attachments:D}:{}}),s(!0),a()}}else t(m),B.error(S(`chat:input.notConnectedDraftKept`)),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:Pa(e),timestamp:new Date().toISOString()})),s(!1)}},[e,j,o,l,E,C,w,T,d,z,c,s,b,f,x,re,te,a,i,N,P,S,k,O,M,A,ee,L,F,I,n,t,p,h,v,_,y]);return{sendMsg:ne,submitWith:ie,handleSubmit:(0,X.useCallback)(e=>{e.preventDefault(),ie(`btw`)},[ie]),handleBtw:(0,X.useCallback)(()=>{ie(`btw`)},[ie]),handleSteer:(0,X.useCallback)(()=>{ie(`steer`)},[ie]),handleAddQueue:(0,X.useCallback)(()=>{ie(`queue`)},[ie]),handleAbort:(0,X.useCallback)(()=>{w(),s(!1)},[w,s]),handleStopAndEdit:(0,X.useCallback)(()=>{w(),s(!1);let e=J.getState().messages;for(let n=e.length-1;n>=0;n--){let i=oe(e[n]);if(i.role===`user`&&i.content){t(i.content),requestAnimationFrame(()=>{let e=r.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,e.focus(),e.setSelectionRange(i.content.length,i.content.length))});return}}},[w,s,t,r])}}var tS=[{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}]}],nS=6,rS=3,iS=180;function aS(e){let t=e.split(`
127
127
  `);if(t.length<rS)return!1;let n=0,r=0;for(let e of t){let t=e.trim();t.length!==0&&(t.length>iS&&r++,/^ {2,}/.test(e)&&n++,/[.!?]$/.test(t)&&r++,/[{}();=<>[\]]/.test(t)&&n++,/[#$]/.test(t)&&!/^# /.test(t)&&n++)}return n>=r&&n>=2}function oS(e){if(!aS(e))return null;let t={};for(let n of tS){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>=nS?n:null}function sS(e){let t=e.trim();return/^```[\s\S]*```\s*$/.test(t)}function cS(e){if(sS(e))return null;let t=oS(e);return t?{fenced:`\`\`\`${t}\n${e}\n\`\`\``,lang:t}:null}function lS({input:e,textareaRef:t,setInput:n,errorText:r}){let[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),c=(0,X.useRef)(q.getState().draftImages),[l,u]=(0,X.useState)(()=>q.getState().draftImages),d=e=>{c.current=e,u(e),q.getState().setDraftImages(e)},f=(0,X.useRef)(r);f.current=r;let p=async e=>{let t=f.current;for(let n of e){if(c.current.length>=8){B.error(t.tooManyImages(8));return}try{let e=await Ka(n);d([...c.current,e])}catch(e){e instanceof qa&&e.reason===`too_large`?B.error(t.imageTooLarge(n.name||`image`)):B.error(t.imageProcessFailed(n.name||`image`))}}};return(0,X.useEffect)(()=>{let e=t.current;if(!e)return;let n=e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.type.startsWith(`image/`)){let t=e.getAsFile();t&&n.push(t)}n.length!==0&&(e.preventDefault(),p(n))};return e.addEventListener(`paste`,n),()=>e.removeEventListener(`paste`,n)},[t]),{draggingOver:o,onDragEnter:e=>{e.dataTransfer&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),s(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||s(!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){s(!1);return}e.preventDefault(),s(!1);let n=t.filter(e=>e.type?.startsWith(`image/`));n.length>0&&p(n);let r=t.filter(e=>!e.type?.startsWith(`image/`));if(r.length===0)return;let i=r.map(e=>e.name).join(`, `);B.info(`Dropped file(s): ${i} — use @ in chat to pick the correct project path.`)},onTextPaste:r=>{let i=r.clipboardData?.getData(`text`)??``;if(!i)return;let o=cS(i);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=i.split(`
128
128
  `).length;a({chars:i.length,lines:p,lang:o.lang,undoFence:()=>{n(u+i+d),a(null),requestAnimationFrame(()=>{s&&(s.focus(),s.style.height=`auto`,s.style.height=`${Math.min(s.scrollHeight,200)}px`)})}}),setTimeout(()=>a(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(i.length>800){let e=i.split(`
129
- `).length;a({chars:i.length,lines:e}),setTimeout(()=>a(null),4e3)}},pasteHint:i,pendingImagesRef:c,pendingImages:l,addImageFiles:p,removeImage:e=>{d(c.current.filter(t=>t.id!==e))},clearPendingImages:()=>d([]),setPendingImages:d,setPasteHint:a}}function uS({clientConnected:e,t,sendMessage:n,setInput:r}){let i=q(e=>e.refinePanel),a=q(e=>e.setRefinePanel),o=J(e=>e.enqueue),s=J(e=>e.addMessage),c=J(e=>e.setLoading);(0,X.useEffect)(()=>{if(!i||(i.status??`refining`)!==`refining`)return;let l=i.retried?21e4:105e3,u=setTimeout(()=>{let i=q.getState().refinePanel;if(i&&(i.status??`refining`)===`refining`){if(a(null),B.info(t(`chat:input.refineTimeoutFallback`)),i.mode!==void 0&&J.getState().isLoading){let e=i.images,t=e&&e.length>0&&i.mode===`btw`?`queue`:i.mode;o(i.original,t,e);return}e?(s({role:`user`,content:i.original}),c(!0),i.freshContext===!0?n(i.original,void 0,!0):n(i.original)):(r(i.original),B.error(t(`chat:input.notConnectedDraftKept`)))}},l);return()=>clearTimeout(u)},[i,e,s,c,n,a,o,r,t])}function dS({onTranscript:e}){let[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(!1),a=(0,X.useRef)(null);return(0,X.useEffect)(()=>{if(typeof window>`u`)return;let e=window.SpeechRecognition||window.webkitSpeechRecognition;i(!!e)},[]),{isListening:t,isSupported:r,toggleListening:(0,X.useCallback)(()=>{if(typeof window>`u`)return;let r=window.SpeechRecognition||window.webkitSpeechRecognition;if(r){if(t){a.current?.stop(),n(!1);return}try{let t=new r;t.continuous=!0,t.interimResults=!1,t.lang=navigator.language||`en-US`,t.onresult=t=>{let n=``;for(let e=t.resultIndex;e<t.results.length;++e){let r=t.results[e];r?.isFinal&&r[0]&&(n+=r[0].transcript)}n.trim()&&e(n.trim())},t.onerror=()=>{n(!1)},t.onend=()=>{n(!1)},t.start(),a.current=t,n(!0)}catch{n(!1)}}},[t,e]),stopListening:(0,X.useCallback)(()=>{a.current?.abort?.(),a.current?.stop?.(),a.current=null,n(!1)},[])}}function fS({onOpenBreakdown:e}={}){let{isLoading:t,setLoading:n,addMessage:r,clearMessages:i}=J(Yr(e=>({isLoading:e.isLoading,setLoading:e.setLoading,addMessage:e.addMessage,clearMessages:e.clearMessages}))),a=J(e=>e.messages).length>0,o=J(e=>e.queue),s=J(e=>e.enqueue),c=J(e=>e.removeQueued),l=J(e=>e.clearQueue),u=q(e=>e.setCurrentView),d=q(e=>e.setPromptLibraryOpen),f=q(e=>e.pushPrompt),p=q(e=>e.promptHistory),m=q(e=>e.promptInsertRequest),h=q(e=>e.clearPromptInsert),g=q(e=>e.setProcessMonitorOpen),_=q(e=>e.setQueuePanelOpen),v=hf(),{sendMessage:y,sendAbort:b,client:x,refineModel:S,updatePrefs:C}=v,{t:w}=W(),T=G(e=>e.enhanceEnabled),E=H(e=>e.session?.provider),D=H(e=>e.session?.model),O=V(e=>e.provider),k=V(e=>e.model),[A,j]=(0,X.useState)(()=>q.getState().draftInput??``),M=(0,X.useRef)(null),{isListening:N,isSupported:P,toggleListening:F,stopListening:I}=dS({onTranscript:e=>{j(t=>t?`${t} ${e}`:e)}});uS({clientConnected:x?.isConnected,t:w,sendMessage:y,setInput:j}),Qx({client:x,sendMessage:y});let L=H(e=>e.lastInputTokens),ee=H(e=>e.maxContext),[R,z]=(0,X.useState)(null),[te,ne]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(!1),ae=(0,X.useRef)(!1),oe=(0,X.useRef)(null),se=(0,X.useRef)(null),ce=$a(e=>e.refs),{removeRef:le,clearRefs:ue}=$a.getState(),{draggingOver:de,onDragEnter:fe,onDragLeave:pe,onDragOver:me,onDrop:he,onTextPaste:ge,pasteHint:_e,pendingImagesRef:ve,pendingImages:ye,addImageFiles:be,removeImage:xe,clearPendingImages:Se,setPendingImages:Ce,setPasteHint:we}=lS({input:A,textareaRef:se,setInput:j,errorText:{tooManyImages:e=>w(`chat:input.tooManyImages`,{max:e}),imageProcessFailed:e=>w(`chat:input.imageProcessFailed`,{name:e}),imageTooLarge:e=>w(`chat:input.imageTooLarge`,{name:e})}}),Te=(0,X.useRef)(null);(0,X.useEffect)(()=>{q.getState().setDraftInput(A)},[A]),(0,X.useEffect)(()=>()=>{M.current!==null&&clearTimeout(M.current)},[]);let Ee=Pe(),De=(0,X.useCallback)(()=>{Yx(Ee);let e=se.current;e&&(e.value=``,e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,t||e.focus())},[t,Ee]),Oe=(0,X.useCallback)(()=>{let e=!T;G.getState().set({enhanceEnabled:e}),C({enhanceEnabled:e})},[T,C]),ke=(0,X.useRef)(()=>!1),{sendMsg:Ae,handleSubmit:je,handleBtw:Me,handleSteer:Ne,handleAddQueue:Fe,handleAbort:Ie,handleStopAndEdit:Le}=eS({input:A,setInput:j,sessionId:Ee,textareaRef:se,pendingImagesRef:ve,clearPendingImages:Se,isLoading:t,setLoading:n,addMessage:r,enqueue:s,ws:v,enhanceEnabled:T,pushPrompt:f,setHistoryIdx:e=>Ue(e),stickyDraftRef:{get current(){return We.current},set current(e){We.current=e}},refineBackstopTimerRef:M,topicCheckBusyRef:ae,topicCheckAbortRef:oe,setTopicCheckBusy:ie,runSlashCommand:e=>ke.current(e),clearTextarea:De,t:w}),Re=(0,X.useCallback)(a=>Ef({raw:a,addMessage:r,clearMessages:i,isLoading:t,client:x,queue:o,sendAbort:b,sendMsg:Ae,setLoading:n,setCurrentView:u,toggleRefineEnabled:Oe,setProcessMonitorOpen:g,setQueuePanelOpen:_,ws:v,onOpenBreakdown:e,handleNextList:zx,handleNextSelect:e=>Bx(e,Ae)}),[r,i,t,x,o,b,Ae,n,u,Oe,g,_,v,e]);ke.current=Re;let{slashIndex:ze,setSlashIndex:Be,slashSuggestions:Ve,historyIdx:He,setHistoryIdx:Ue,stickyDraftRef:We,handleKeyDown:Ge}=$x({input:A,setInput:j,textareaRef:se,atMention:R,promptHistory:p,runSlashCommand:Re,handleSubmit:je});Xx({sessionId:Ee,input:A,setInput:j,pendingImages:ye,setPendingImages:Ce,clearPendingImages:Se,fileRefs:ce,clearRefs:ue,setHistoryIdx:Ue,stickyDraftRef:We,setAtMention:z,setPasteHint:we,stopSpeech:I,topicCheckAbortRef:oe,topicCheckBusyRef:ae,setTopicCheckBusy:ie,refineBackstopTimerRef:M,textareaRef:se}),(0,X.useEffect)(()=>{m!=null&&(j(e=>e.trim()?`${e}\n${m}`:m),h(),requestAnimationFrame(()=>se.current?.focus()))},[m,h]);let Ke=()=>{let e=se.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)};return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(Fm,{}),_e&&(0,Z.jsx)(Sx,{pasteHint:_e,onDismiss:()=>we(null),t:w}),(0,Z.jsx)(Cx,{pendingImages:ye,onRemove:xe,onClearAll:Se,t:w}),(0,Z.jsx)(Hx,{queue:o,onClear:l,onRemove:c}),(0,Z.jsx)(Kx,{enhanceEnabled:T,refinePickOpen:te,setRefinePickOpen:ne,refineModel:S,clientConnected:x?.isConnected===!0,addUserMessage:e=>r({role:`user`,content:e}),setLoading:n,sendMessage:y,isLoading:t,enqueue:s,setInput:j,resolveCancelInput:qx,notConnectedDraftKept:()=>B.error(w(`chat:input.notConnectedDraftKept`))}),(0,Z.jsx)(Tx,{sessionProvider:E,sessionModel:D,fallbackProvider:O,fallbackModel:k,onOpenPromptLibrary:()=>d(!0),onOpenModelSwitcher:()=>q.getState().setModelSwitcherOpen(!0),t:w}),(0,Z.jsx)(wx,{fileRefs:ce,onRemove:le,onClearAll:ue,t:w}),re&&(0,Z.jsx)(`div`,{className:`px-1 text-xs text-muted-foreground`,role:`status`,children:w(`chat:input.topicShiftChecking`)}),(0,Z.jsxs)(`form`,{onSubmit:je,onDragEnter:fe,onDragOver:me,onDragLeave:pe,onDrop:he,"data-session-id":Ee??void 0,"data-running":t?`true`:`false`,"data-chat-started":a?`true`:`false`,"data-has-draft":A.trim()||ye.length>0?`true`:`false`,className:K(`relative flex flex-col gap-2 rounded-xl border border-border/70 bg-background/85 p-2 shadow-lg shadow-black/5 transition-colors sm:flex-row sm:items-end`,t&&`border-warning/45 bg-warning/5 shadow-warning/10`,!a&&!t&&`border-border/50 bg-card/55 shadow-none`,de&&`ring-2 ring-primary ring-offset-2 ring-offset-background bg-primary/5`),children:[de&&(0,Z.jsx)(`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:w(`chat:input.dropOverlay`)}),(0,Z.jsxs)(`div`,{className:`relative w-full flex-1`,children:[(0,Z.jsx)(jx,{atMention:R,input:A,textareaRef:se,setInput:j,setAtMention:z}),!R&&(0,Z.jsx)(Zx,{suggestions:Ve,selectedIndex:ze,onSelectIndex:Be,onRun:e=>{j(``),Re(e)}}),(0,Z.jsx)(`textarea`,{ref:se,"data-chat-textarea":!0,value:A,onChange:e=>{let t=e.target.value;j(t),Ke(),He>=0&&(Ue(-1),We.current=null);let n=e.target.selectionStart??t.length;z(bf(t,n))},onSelect:e=>{let t=e.currentTarget;z(bf(t.value,t.selectionStart))},onKeyDown:Ge,onPaste:ge,placeholder:x?.isConnected?w(t?`chat:inputPlaceholderLoading`:`chat:inputPlaceholder`):w(`chat:inputPlaceholderConnecting`),className:K(`flex min-h-[64px] w-full resize-none overflow-y-auto rounded-lg border border-input bg-card/80 px-4 py-3 pr-12 shadow-sm sm:min-h-[44px]`,`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:!x?.isConnected||re}),(0,Z.jsx)(kx,{input:A,lastInputTokens:L,maxContext:ee})]}),(0,Z.jsx)(Ox,{imagePickerRef:Te,disabled:!x?.isConnected||re,topicCheckBusy:re,clientConnected:x?.isConnected===!0,isLoading:t,chatStarted:a,input:A,pendingImages:ye,addImageFiles:be,handleStopAndEdit:Le,handleAbort:Ie,handleBtw:Me,handleSteer:Ne,handleAddQueue:Fe,updatePrefs:C,t:w,isListening:N,isSpeechSupported:P,onToggleSpeech:F})]})]})}function pS(e){return{index:e.promptIndex,iteration:e.promptIndex,timestamp:e.ts??``,label:e.promptPreview??``,messageCount:0,tokens:0,fileCount:e.fileCount??0}}function mS({open:e,onClose:t,className:n}){let{t:r}=W(),[i,a]=(0,X.useState)([]),[o,s]=(0,X.useState)(!1),c=hf(),l=V(e=>e.wsConnected),u=(0,X.useRef)(null),d=Pe();(0,X.useEffect)(()=>{if(e&&l&&c.client?.isConnected)return a([]),c.client.send?.({type:`session.checkpoints`,payload:c.client.withSession({})}),u.current=c.client.on?.(`session.checkpoints`,e=>{let t=e?.payload;(t?.sessionId===void 0||d===void 0||t.sessionId===d)&&t?.checkpoints&&a(t.checkpoints.map(pS))})??null,()=>{u.current?.()}},[e,l,c.client,d]);let f=(0,X.useCallback)(async e=>{s(!0),c.client.send?.({type:`session.rewind`,payload:c.client.withSession({checkpointIndex:e})}),setTimeout(()=>{t(),s(!1)},800)},[c.client,t]);return(0,Z.jsx)(es,{open:e,onOpenChange:e=>{e||t()},children:(0,Z.jsxs)(Zo,{className:K(`max-w-md gap-0 overflow-hidden border-border/80 bg-card p-0 pt-[10dvh] flex flex-col max-h-[75dvh]`,n),children:[(0,Z.jsx)(Qo,{className:`sr-only`,children:r(`activity:checkpoint.heading`)}),(0,Z.jsx)($o,{className:`sr-only`,children:r(`activity:checkpoint.countSuffix`,{count:i.length})}),(0,Z.jsx)(`div`,{className:`flex items-center justify-between border-b border-border/70 bg-card/95 px-4 py-3 shrink-0`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Z.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(un,{className:`h-4 w-4`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:r(`activity:checkpoint.heading`)}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:r(`activity:checkpoint.countSuffix`,{count:i.length})})]})]})}),(0,Z.jsx)(`div`,{className:`border-b border-border/70 bg-muted/25 px-4 py-2.5 text-[10px] text-muted-foreground leading-relaxed`,children:r(`activity:checkpoint.description`)}),(0,Z.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain`,children:i.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,Z.jsx)(la,{className:`h-10 w-10 opacity-15`}),(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:r(`activity:checkpoint.emptyTitle`)}),(0,Z.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:r(`activity:checkpoint.emptyBody`)})]}):(0,Z.jsx)(`div`,{className:`py-1`,children:[...i].reverse().map((e,t)=>{let n=t===0;return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>f(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,Z.jsxs)(`div`,{className:`flex flex-col items-center mt-1.5`,children:[(0,Z.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,Z.jsx)(`div`,{className:`w-px flex-1 min-h-[20px] bg-border/50`})]}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground tabular-nums shrink-0`,children:[`#`,e.index]}),(0,Z.jsx)(`span`,{className:`text-xs font-medium truncate`,children:e.label}),n&&(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[10px] text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`tabular-nums`,children:r(`activity:checkpoint.msgSuffix`,{count:e.messageCount})}),(0,Z.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Z.jsxs)(`span`,{className:`tabular-nums`,children:[e.fileCount??0,` files`]}),(0,Z.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Z.jsxs)(`span`,{className:`tabular-nums`,children:[`iter `,e.iteration]})]})]}),(0,Z.jsx)(`span`,{className:`shrink-0 mt-1.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Z.jsx)(Ma,{className:`h-4 w-4 text-primary`})})]},e.index)})})}),(0,Z.jsxs)(`div`,{className:`border-t border-border/70 bg-muted/20 px-4 py-2 text-[10px] text-muted-foreground text-center shrink-0`,children:[r(`activity:checkpoint.footerPre`),` ·`,` `,(0,Z.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted font-mono text-[9px]`,children:`Esc`}),` `,r(`activity:checkpoint.footerPost`)]})]})})}function hS(e){return!!(e?.role===`user`&&Array.isArray(e.content)&&e.content.length>0&&e.content.every(e=>e.type===`tool_result`))}function gS(e,t){if(e[t]?.role!==`user`||hS(e[t]))return[];let n=[];for(let r=t+1;r<e.length;r+=1){let t=e[r];if(t?.role===`user`&&!hS(t))break;t?.role===`assistant`&&n.push(r)}return n}function _S(e,t){return e.messageBreakdown.find(e=>e.index===t)?.pairedAssistantIndices??gS(e.messages,t)}function vS(e,t,n){let r=new Set(t);return e.messages.forEach((i,a)=>{if(i.role===`user`&&(t.has(a)||n.some(e=>e.messageIndex===a)))for(let t of _S(e,a))r.add(t)}),r}function yS(e){let t=new Map;for(let n of e){let e=`${n.messageIndex}:${n.blockIndex??`string`}`;t.set(e,[...t.get(e)??[],n])}return[...t.values()].flatMap(e=>{let t=e.sort((e,t)=>(e.start??0)-(t.start??0)),n=[];for(let e of t){let t=n.at(-1);t?.end!==void 0&&e.start!==void 0&&e.end!==void 0&&e.start<=t.end?t.end=Math.max(t.end,e.end):n.push({...e})}return n})}function bS(e,t){if(t<=0||t>=e.length)return!1;let n=e.charCodeAt(t-1),r=e.charCodeAt(t);return n>=55296&&n<=56319&&r>=56320&&r<=57343}function xS(e,t){if(t.start===void 0||t.end===void 0)return;let n=e[t.messageIndex];if(!n)return;if(t.blockIndex===void 0&&typeof n.content==`string`){n.content=n.content.slice(0,t.start)+n.content.slice(t.end);return}if(!Array.isArray(n.content)||t.blockIndex===void 0)return;let r=n.content[t.blockIndex];r?.type===`text`&&typeof r.text==`string`&&(r.text=r.text.slice(0,t.start)+r.text.slice(t.end))}var SS={phase:`closed`,revision:null,messages:[],readonlyContext:null,messageBreakdown:[],diagnostics:null,removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],validation:null,appliedResult:null,errorMessage:null},CS=Xa(((e,t)=>({...SS,open:()=>e({...SS,phase:`loading_snapshot`,removeMessages:new Set,explicitRemoveMessages:new Set}),close:()=>e({...SS}),loadSnapshot:t=>e(e=>{let n=e.phase===`applied_success`&&e.appliedResult!==null;return{phase:n?`applied_success`:`clean_snapshot`,revision:t.revision,messages:t.messages,readonlyContext:t.readonlyContext,messageBreakdown:t.messageBreakdown,diagnostics:t.diagnostics,removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],validation:null,appliedResult:n?e.appliedResult:null,errorMessage:null}}),toggleRemoveMessage:n=>{let r=t();if(r.phase===`validating`||r.phase===`applying`)return;let i=new Set(r.explicitRemoveMessages);if(r.messages[n]?.role===`assistant`&&r.messages.some((e,t)=>e.role===`user`&&(r.explicitRemoveMessages.has(t)||r.removeRanges.some(e=>e.messageIndex===t))&&_S(r,t).includes(n))&&r.removeMessages.has(n))return;i.has(n)?i.delete(n):i.add(n);let a=r.removeRanges,o=vS(r,i,a);e({removeMessages:o,explicitRemoveMessages:i,removeRanges:a,phase:o.size>0||a.length>0?`dirty`:`clean_snapshot`,validation:null})},markRangeForRemoval:n=>{let r=t();if(r.phase===`validating`||r.phase===`applying`||r.explicitRemoveMessages.has(n.messageIndex)||n.start===void 0||n.end===void 0||n.start<0||n.end<=n.start)return;let i=r.messages[n.messageIndex],a;if(n.blockIndex===void 0&&typeof i?.content==`string`)a=i.content;else if(n.blockIndex!==void 0&&Array.isArray(i?.content)){let e=i.content[n.blockIndex];e?.type===`text`&&(a=e.text)}if(a===void 0||n.end>a.length||bS(a,n.start)||bS(a,n.end))return;let o=yS([...r.removeRanges,n]);e({removeMessages:vS(r,r.explicitRemoveMessages,o),removeRanges:o,phase:`dirty`,validation:null})},clearRemovals:()=>e({removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],phase:`clean_snapshot`,validation:null}),beginValidation:()=>e({phase:`validating`,validation:null,errorMessage:null}),beginApply:()=>e({phase:`applying`,errorMessage:null}),setValidation:t=>e({validation:t,phase:t.conflict?`conflicted`:t.ok?`validated`:`invalid`,errorMessage:null}),setApplied:t=>e({appliedResult:t,phase:`applied_success`,removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],validation:null,errorMessage:null}),setError:n=>e({errorMessage:n,phase:n?`apply_failed`:t().phase}),resetToClean:()=>e({phase:`clean_snapshot`,removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],validation:null,errorMessage:null}),getProposedMessages:()=>{let e=t(),n=structuredClone(e.messages);for(let t of[...e.removeRanges].sort((e,t)=>(t.start??0)-(e.start??0)))xS(n,t);return n.filter((t,n)=>!e.removeMessages.has(n))}})));function wS(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function TS(e){let t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return null;let n=t.getRangeAt(0);if(!e.contains(n.commonAncestorContainer))return null;let r=n.cloneRange();r.selectNodeContents(e),r.setEnd(n.startContainer,n.startOffset);let i=r.toString().length,a=i+n.toString().length;return a>i?{start:i,end:a}:null}function ES(e){return e.type===`image`?e.source?.type===`base64`?`${e.source.media_type??`image`} · ${e.source.data?.length??0} base64 chars`:`URL image source`:e.type===`tool_use`?`${e.name??`tool`} · ${e.id??`unknown id`}`:e.type===`tool_result`?`tool result · ${e.tool_use_id??`unknown id`}`:e.type===`thinking`?`thinking · ${e.thinking?.length??0} chars`:e.type}function DS({text:e,blockIndex:t,marked:n,disabled:r,onMarkRange:i}){let[a,o]=(0,X.useState)(null),s=(0,X.useRef)(null),c=(0,X.useCallback)(()=>{if(r)return;let e=s.current;e&&o(TS(e))},[r]);return(0,X.useEffect)(()=>{o(null)},[e]),(0,Z.jsxs)(`div`,{className:K(`rounded-md border bg-background p-3`,n&&`border-destructive/40 bg-destructive/5`),children:[(0,Z.jsx)(`p`,{ref:s,className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground select-text`,onMouseUp:c,onKeyUp:c,tabIndex:r?-1:0,children:e||`(empty)`}),a&&(0,Z.jsx)(`button`,{type:`button`,disabled:r,className:`mt-2 rounded-md border border-destructive/30 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/10 disabled:cursor-not-allowed disabled:opacity-40`,onMouseDown:e=>e.preventDefault(),onClick:()=>{i(t,a.start,a.end),window.getSelection()?.removeAllRanges(),o(null)},children:`Mark for removal`})]})}function OS({index:e,role:t,tokens:n,content:r,blockCount:i,warnings:a,markedForRemoval:o,markedRanges:s,disabled:c,onToggle:l,onMarkRange:u}){let[d,f]=(0,X.useState)(!1),p=t===`user`?`text-primary`:t===`assistant`?`text-success`:`text-muted-foreground`,m=a.length>0;return(0,Z.jsxs)(`div`,{className:K(`group flex items-start gap-3 rounded-lg border bg-card p-3 transition-colors`,o&&`border-destructive/40 bg-destructive/5 opacity-70`,!o&&`hover:border-primary/30`),children:[(0,Z.jsx)(`button`,{type:`button`,onClick:l,disabled:c,className:`mt-0.5 shrink-0 disabled:cursor-not-allowed disabled:opacity-40`,"aria-label":o?`Undo removal`:`Mark for removal`,children:o?(0,Z.jsx)(jn,{className:`h-3.5 w-3.5 text-destructive`}):(0,Z.jsx)(`div`,{className:`h-3.5 w-3.5 rounded-sm border border-border/60 group-hover:border-primary/50 transition-colors`})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[i!==null&&i>0&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>f(e=>!e),className:`text-muted-foreground/60 hover:text-foreground shrink-0`,children:d?(0,Z.jsx)(gn,{className:`h-3 w-3`}):(0,Z.jsx)(ui,{className:`h-3 w-3`})}),(0,Z.jsx)(`span`,{className:K(`font-mono font-medium`,p),children:t}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground/60 tabular-nums`,children:[wS(n),` tok`]}),i!==null&&i>0&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground/50 tabular-nums`,children:[i,` blk`]}),m&&(0,Z.jsx)(dr,{className:`h-3 w-3 text-warning shrink-0`})]}),(0,Z.jsx)(`div`,{className:`mt-3 space-y-2`,children:typeof r==`string`?(0,Z.jsx)(DS,{text:r,marked:s.some(e=>e.blockIndex===void 0),disabled:c,onMarkRange:u}):r.map((t,n)=>(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:t.type}),typeof t.text==`string`&&(0,Z.jsxs)(`span`,{children:[wS(Math.ceil(t.text.length/4)),` tok`]})]}),t.type===`text`&&typeof t.text==`string`?(0,Z.jsx)(DS,{text:t.text,blockIndex:n,marked:s.some(e=>e.blockIndex===n),disabled:c,onMarkRange:u}):(0,Z.jsx)(`div`,{className:`rounded-md border bg-muted/20 p-3 font-mono text-[11px] text-muted-foreground`,children:ES(t)})]},`${e}-${n}`))}),d&&m&&(0,Z.jsx)(`div`,{className:`mt-2 space-y-1`,children:a.map((e,t)=>(0,Z.jsxs)(`div`,{className:K(`flex items-start gap-1 text-[10px] rounded px-1.5 py-0.5`,e.severity===`danger`?`bg-destructive/10 text-destructive`:e.severity===`warning`?`bg-warning/10 text-warning`:`bg-muted text-muted-foreground`),children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:e.code}),(0,Z.jsx)(`span`,{className:`opacity-80`,children:e.message})]},t))})]})]})}var kS=5e3;function AS({open:e,onClose:t}){let{t:n}=W(),r=CS(e=>e.phase),i=CS(e=>e.revision),a=CS(e=>e.messageBreakdown),o=CS(e=>e.readonlyContext),s=CS(e=>e.messages),c=CS(e=>e.removeMessages),l=CS(e=>e.removeRanges),u=CS(e=>e.validation),d=CS(e=>e.appliedResult),f=CS(e=>e.errorMessage),p=CS,m=J(e=>e.isLoading),h=H(e=>e.contextLimitWarning),g=Pe(),_=(0,X.useRef)(null),v=S()?.withSession?.({})?.sessionId??g??He()??void 0;up(`context.editor.snapshot`,e=>{let t=e.payload;t&&typeof t.revision==`string`&&Array.isArray(t.messages)&&p.getState().loadSnapshot(t)},{sessionId:v,deps:[e,p,v]}),up(`context.editor.validation`,e=>{p.getState().setValidation(e.payload)},{sessionId:v,deps:[e,p,v]}),up(`context.editor.applied`,e=>{p.getState().setApplied(e.payload);let t=S();typeof t?.openContextEditor==`function`&&t.openContextEditor()},{sessionId:v,deps:[e,p,v]}),(0,X.useEffect)(()=>{if(!e){p.getState().close();return}(p.getState().phase===`closed`||p.getState().phase===`apply_failed`)&&p.getState().open();let t=S();if(!t?.send||!t?.on){p.getState().setError(U.t(`activity:context.wsNotConnected`));return}t.send({type:`context.editor.open`,payload:t.withSession({})});let n=setTimeout(()=>{p.getState().phase===`loading_snapshot`&&p.getState().setError(U.t(`activity:ctxEditor.snapshotTimedOut`))},kS);return()=>clearTimeout(n)},[e,p,v]);let y=(0,X.useCallback)(()=>{let e=S();if(!e?.send||!i)return;p.getState().beginValidation();let t=p.getState(),n=t.getProposedMessages(),r=[...[...t.removeMessages].map(e=>({messageIndex:e})),...t.removeRanges];e.validateContextEditor(i,n,r,!0)},[i,p]),b=(0,X.useCallback)(()=>{let e=S();if(!e?.send||!i)return;let t=p.getState(),n=t.getProposedMessages(),r=[...[...t.removeMessages].map(e=>({messageIndex:e})),...t.removeRanges];p.getState().beginApply(),e.applyContextEditor(i,n,r,!0)},[i,p]);if(!e)return null;let x=r===`applying`||r===`validating`,C=c.size>0||l.length>0,w=r===`validated`&&!m,T=C&&!x&&!m,E=!x&&!(r===`dirty`&&C),D=()=>{E&&t()};return(0,Z.jsx)(es,{open:e,onOpenChange:e=>!e&&D(),children:(0,Z.jsxs)(Zo,{showCloseButton:!1,className:`max-h-[calc(100dvh-3rem)] max-w-4xl flex flex-col gap-0 overflow-hidden p-0 sm:p-0`,onOpenAutoFocus:()=>{let e=document.activeElement;_.current=e instanceof HTMLElement?e:null},onCloseAutoFocus:e=>{let t=_.current;t?.isConnected&&(e.preventDefault(),t.focus())},onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>{E||e.preventDefault()},children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3 shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Zt,{className:`h-4 w-4 text-primary`}),(0,Z.jsx)(Qo,{className:`text-sm font-semibold`,children:n(`activity:ctxEditor.contextWindowEditor`)}),i&&(0,Z.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground/60 ml-2`,children:[`rev `,i.slice(0,8),`…`]})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:D,disabled:!E,className:`p-1.5 rounded-md hover:bg-accent hover:text-accent-foreground transition-colors disabled:opacity-40`,"aria-label":n(`common:action.close`),children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),h&&(0,Z.jsxs)(`div`,{role:`status`,className:`mx-4 mt-3 flex items-start gap-2 rounded-md border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:[(0,Z.jsx)(dr,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Z.jsx)(`span`,{children:n(`activity:ctxEditor.providerLimitDecreased`,{previous:wS(h.previousMaxContext),current:wS(h.maxContext)})})]}),o&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-4 gap-2 px-4 py-2 border-b bg-muted/20 text-[11px] shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground/60`,children:n(`activity:ctxEditor.system`)}),(0,Z.jsx)(`span`,{className:`font-mono font-medium`,children:wS(o.systemPromptTokens)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[`Tools (`,o.toolCount,`)`]}),(0,Z.jsx)(`span`,{className:`font-mono font-medium`,children:wS(o.toolSchemaTokens)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground/60`,children:n(`activity:ctxEditor.messages`)}),(0,Z.jsx)(`span`,{className:`font-mono font-medium`,children:wS(o.messageTokens)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground/60`,children:n(`activity:ctxEditor.total`)}),(0,Z.jsx)(`span`,{className:`font-mono font-medium text-primary`,children:wS(o.totalTokens)})]})]}),r===`loading_snapshot`&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-muted-foreground py-12`,children:[(0,Z.jsx)(mn,{className:`h-4 w-4 animate-spin`}),n(`activity:ctxEditor.loadingContextSnapshot`)]}),r!==`loading_snapshot`&&a.length===0&&!f&&(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0 flex-col items-center justify-center gap-2 px-6 py-12 text-center text-sm text-muted-foreground`,children:[(0,Z.jsx)(Vn,{className:`h-5 w-5 text-muted-foreground/60`}),(0,Z.jsx)(`p`,{children:n(`activity:ctxEditor.emptyConversation`)})]}),f&&r===`apply_failed`&&(0,Z.jsx)(`div`,{className:`m-4 rounded-md bg-destructive/10 border border-destructive/20 p-3 text-sm text-destructive`,children:f}),r===`applied_success`&&d&&(0,Z.jsxs)(`div`,{className:`m-4 rounded-md bg-success/10 border border-success/20 p-3 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-success font-medium`,children:[(0,Z.jsx)(Bn,{className:`h-4 w-4`}),`Context updated: `,d.before.messages,` → `,d.after.messages,` `,`messages`]}),(0,Z.jsxs)(`div`,{className:`mt-1 text-muted-foreground text-xs`,children:[`Saved`,` `,wS(d.before.fullRequestTokens-d.after.fullRequestTokens),` `,`tokens`,d.removed.toolUses.length>0&&` · ${d.removed.toolUses.length} tool calls repaired`]})]}),u?.conflict&&(0,Z.jsxs)(`div`,{className:`m-4 rounded-md bg-warning/10 border border-warning/20 p-3 text-sm text-warning`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[(0,Z.jsx)(dr,{className:`h-4 w-4`}),u.conflict.code===`CONTEXT_REVISION_CONFLICT`?`Context changed while editor was open.`:`Agent is currently running.`]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs opacity-80`,children:u.conflict.message})]}),r!==`loading_snapshot`&&a.length>0&&(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 space-y-3 overflow-y-auto overscroll-contain bg-muted/10 p-4`,children:a.map(e=>(0,Z.jsx)(OS,{index:e.index,role:e.role,tokens:e.tokens,content:s[e.index]?.content??``,blockCount:e.blockCount,warnings:e.warnings,markedForRemoval:c.has(e.index),markedRanges:l.filter(t=>t.messageIndex===e.index),disabled:x,onToggle:()=>p.getState().toggleRemoveMessage(e.index),onMarkRange:(t,n,r)=>p.getState().markRangeForRemoval({messageIndex:e.index,...t===void 0?{}:{blockIndex:t},start:n,end:r})},e.index))}),u?.ok===!1&&u.validationErrors.length>0&&(0,Z.jsxs)(`div`,{className:`border-t px-4 py-2 bg-destructive/5 shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`text-[11px] font-medium text-destructive mb-1`,children:[`Validation errors (`,u.validationErrors.length,`)`]}),u.validationErrors.slice(0,5).map((e,t)=>(0,Z.jsxs)(`div`,{className:`text-[10px] text-destructive/80 font-mono`,children:[e.path,`: `,e.message]},t))]}),u?.ok&&u.repair.changed&&(0,Z.jsx)(`div`,{className:`border-t px-4 py-2 bg-warning/5 shrink-0`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[(0,Z.jsx)(mi,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:n(`activity:ctxEditor.repairPreviewWillRemove`)}),u.repair.removedToolUses.length>0&&(0,Z.jsxs)(`span`,{children:[u.repair.removedToolUses.length,` orphan tool_use(s)`]}),u.repair.removedToolResults.length>0&&(0,Z.jsxs)(`span`,{children:[u.repair.removedToolResults.length,` orphan tool_result(s)`]}),u.repair.removedMessages>0&&(0,Z.jsxs)(`span`,{children:[u.repair.removedMessages,` empty message(s)`]})]})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t px-4 py-3 shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground`,children:[C&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(jn,{className:`h-3 w-3 text-destructive`}),(0,Z.jsxs)(`span`,{children:[c.size,` message`,c.size===1?``:`s`,` and`,` `,l.length,` range`,l.length===1?``:`s`,` marked`]})]}),m&&(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-warning`,children:[(0,Z.jsx)(la,{className:`h-3 w-3`}),n(`activity:ctxEditor.agentRunningApplyDisabled`)]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[C&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>p.getState().clearRemovals(),className:`text-[11px] text-muted-foreground hover:text-foreground transition-colors`,disabled:x,children:n(`activity:ctxEditor.clear`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:y,disabled:!T,className:K(`flex items-center gap-1.5 rounded-md px-3 py-1.5 text-[11px] font-medium transition-colors`,T?`bg-secondary text-secondary-foreground hover:bg-secondary/80`:`bg-muted text-muted-foreground/40 cursor-not-allowed`),children:[r===`validating`?(0,Z.jsx)(mn,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Vn,{className:`h-3 w-3`}),`Validate`]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:b,disabled:!w,className:K(`flex items-center gap-1.5 rounded-md px-3 py-1.5 text-[11px] font-medium transition-colors`,w?`bg-primary text-primary-foreground hover:bg-primary/90`:`bg-muted text-muted-foreground/40 cursor-not-allowed`),children:[r===`applying`?(0,Z.jsx)(mn,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Bn,{className:`h-3 w-3`}),`Apply Changes`]})]})]})]})})}function jS(e,t){if(!e)return`reset time unknown`;let n=Math.max(0,Math.ceil((e-t)/1e3));if(n===0)return`rechecking now`;if(n<60)return`${n}s`;let r=Math.floor(n/60);return r<60?`${r}m ${n%60}s`:`${Math.floor(r/60)}h ${r%60}m`}function MS(e,t){if(!e)return``;let n=Math.max(0,Math.floor((t-e)/1e3));if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ${r%60}m ago`}var NS=/Sibling quarantine:.*?\bon\s+([^\s/]+\/\S+)/;function PS(e){return NS.exec(e.lastErrorMessage??``)?.[1]??null}function FS(){let{t:e}=W(),t=mo(e=>e.entries);mo(e=>e.summary);let n=mo(e=>e.removeEntry),r=mo(e=>e.audit),i=G(e=>e.modelAvailabilitySchedule),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(Date.now()),p=(0,X.useMemo)(()=>Object.values(t).sort((e,t)=>(e.stateExpiresAt??0)-(t.stateExpiresAt??0)),[t]),m=(0,X.useMemo)(()=>p.filter(e=>e.state!==`healthy`),[p]),h=(0,X.useMemo)(()=>nv(i,new Date(d)),[i,d]),g=(0,X.useCallback)(()=>{S().getProviderStatus()},[]),_=(0,X.useCallback)(()=>{u(e=>{let t=!e;return t&&S().getProviderAuditHistory(20),t})},[]),v=(0,X.useCallback)((e,t)=>{S().retryProviderModel(e,t),n(e,t)},[n]),y=(0,X.useCallback)((e,t)=>{S().clearProviderStatus(e,t),n(e,t)},[n]);if((0,X.useEffect)(()=>{if(m.length===0&&h.length===0)return;let e=window.setInterval(()=>f(Date.now()),1e3);return()=>window.clearInterval(e)},[h.length,m.length]),(0,X.useEffect)(()=>{a&&g()},[a,g]),m.length===0&&h.length===0)return null;let b=m.filter(e=>e.state===`blocked`).length,x=m.length-b;return s&&t[s],(0,Z.jsxs)(`div`,{className:`mx-auto mb-2 max-w-6xl rounded-lg border border-warning/25 bg-warning/5 text-xs`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-warning/5`,onClick:()=>o(e=>!e),"aria-expanded":a,children:[(0,Z.jsx)(dr,{className:`h-3.5 w-3.5 text-warning`}),(0,Z.jsx)(`span`,{className:`font-medium text-foreground`,children:e(`activity:providerWait.providerModelAvailability`)}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[b,` blocked · `,x,` degraded · `,h.length,` scheduled`]}),(0,Z.jsx)(`button`,{type:`button`,className:`ml-auto inline-flex items-center gap-1 text-muted-foreground transition-colors hover:text-foreground`,onClick:e=>{e.stopPropagation(),g()},title:e(`activity:providerWait.refreshStatus`),children:(0,Z.jsx)(Yn,{className:`h-3 w-3`})}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:a?`Hide`:`Details`})]}),a&&(0,Z.jsxs)(`div`,{className:`border-t border-warning/15 px-3 py-2`,children:[m.map(t=>{let n=`${t.providerId}\u0000${t.model}`,r=s===n,i=PS(t);return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`button`,{type:`button`,className:`flex flex-wrap cursor-pointer items-center gap-x-2 gap-y-1 py-1.5 hover:bg-warning/5`,onClick:()=>c(r?null:n),children:[t.state===`blocked`?(0,Z.jsx)(Fr,{className:`h-3.5 w-3.5 text-warning`}):(0,Z.jsx)(Bn,{className:`h-3.5 w-3.5 text-warning`}),(0,Z.jsxs)(`code`,{className:`text-foreground`,children:[t.providerId,`/`,t.model]}),(0,Z.jsx)(`span`,{className:`rounded bg-warning/10 px-1.5 py-0.5 text-warning`,children:t.state}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:t.reason.replaceAll(`_`,` `)}),i&&(0,Z.jsxs)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-muted-foreground`,children:[`via `,i]}),(0,Z.jsx)(`span`,{className:`ml-auto tabular-nums text-muted-foreground`,children:jS(t.stateExpiresAt,d)})]}),r&&(0,Z.jsxs)(`div`,{className:`ml-6 mb-2 rounded border border-border/50 bg-background/50 p-2`,children:[t.lastErrorMessage&&(0,Z.jsxs)(`div`,{className:`mb-1.5 text-destructive`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[e(`activity:providerWait.lastError`),` `]}),t.lastErrorMessage.slice(0,300)]}),(0,Z.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap gap-x-3 gap-y-0.5 text-muted-foreground`,children:[t.totalFailures!==void 0&&(0,Z.jsxs)(`span`,{children:[`failures: `,t.totalFailures]}),t.rateLimitHits!==void 0&&t.rateLimitHits>0&&(0,Z.jsxs)(`span`,{children:[`rate-limits: `,t.rateLimitHits]}),t.consecutiveFailures!==void 0&&(0,Z.jsxs)(`span`,{children:[`streak: `,t.consecutiveFailures]}),t.lastErrorStatus!==void 0&&(0,Z.jsxs)(`span`,{children:[`HTTP: `,t.lastErrorStatus]}),t.lastSessionId&&(0,Z.jsxs)(`span`,{children:[`session: `,t.lastSessionId.slice(0,12),`…`]}),t.lastAgentId&&(0,Z.jsxs)(`span`,{children:[`agent: `,t.lastAgentId.slice(0,16),`…`]}),t.lastFailureAt&&(0,Z.jsx)(`span`,{children:MS(t.lastFailureAt,d)})]}),t.recentErrors&&t.recentErrors.length>0&&(0,Z.jsxs)(`details`,{className:`mb-1.5`,children:[(0,Z.jsxs)(`summary`,{className:`cursor-pointer text-muted-foreground hover:text-foreground`,children:[`Error history (`,t.recentErrors.length,`)`]}),(0,Z.jsx)(`div`,{className:`mt-1 max-h-32 overflow-y-auto text-[11px] text-muted-foreground`,children:t.recentErrors.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex gap-2 border-b border-border/20 py-0.5`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums text-warning/70`,children:e.kind}),(0,Z.jsxs)(`span`,{className:`shrink-0 tabular-nums`,children:[`HTTP `,e.status]}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.message.slice(0,200)}),(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums`,children:MS(e.timestamp,d)})]},t))})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border bg-background px-2 py-1 text-[11px] font-medium text-foreground transition-colors hover:bg-accent`,onClick:()=>v(t.providerId,t.model),children:[(0,Z.jsx)(Xt,{className:`h-3 w-3`}),e(`activity:providerWait.reopenHalfOpenProbe`)]}),(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border bg-background px-2 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:text-foreground`,onClick:()=>y(t.providerId,t.model),children:[(0,Z.jsx)(jn,{className:`h-3 w-3`}),e(`activity:providerWait.clearTracking`)]})]})]})]},n)}),h.map(e=>(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 py-1.5`,children:[(0,Z.jsx)(Fr,{className:`h-3.5 w-3.5 text-info`}),(0,Z.jsx)(`code`,{className:`text-foreground`,children:tv(e)}),(0,Z.jsx)(`span`,{className:`rounded bg-info/10 px-1.5 py-0.5 text-info`,children:`scheduled`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.label??`calendar blackout`}),(0,Z.jsxs)(`span`,{className:`ml-auto tabular-nums text-muted-foreground`,children:[e.start,`–`,e.end,` · `,e.timezone??`local time`]})]},e.id)),(0,Z.jsxs)(`button`,{type:`button`,className:`mt-1 flex w-full items-center gap-2 border-t border-border/30 py-1.5 text-left hover:bg-warning/5`,onClick:_,"aria-expanded":l,children:[(0,Z.jsx)(Fr,{className:`h-3.5 w-3.5 text-warning`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:providerWait.recentBlockOpenEvents`,{count:r.length})}),(0,Z.jsx)(`span`,{className:`ml-auto text-muted-foreground`,children:l?`Hide`:`Show`})]}),l&&(0,Z.jsx)(`div`,{className:`pt-1`,children:r.length===0?(0,Z.jsx)(`div`,{className:`py-1 text-muted-foreground`,children:e(`activity:providerWait.noBlockOpenEventsYet`)}):r.map((e,t)=>{let n=e.to!==`blocked`,r=[e.error?.sessionId,e.error?.agentId].filter(e=>typeof e==`string`&&e.length>0).map(e=>`${e.slice(0,12)}…`).join(` / `);return(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 py-0.5`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:MS(e.ts,d)}),(0,Z.jsxs)(`code`,{className:`text-foreground`,children:[e.providerId,`/`,e.model]}),(0,Z.jsxs)(`span`,{className:n?`text-info`:`text-warning`,children:[e.from,` → `,e.to]}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.reason.replaceAll(`_`,` `)}),e.error&&(0,Z.jsxs)(`span`,{className:`text-destructive`,children:[e.error.kind,e.error.status==null?``:` ${e.error.status}`]}),r&&(0,Z.jsx)(`span`,{className:`ml-auto text-muted-foreground`,children:r})]},`${e.ts}-${t}`)})}),(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-muted-foreground`,children:e(`activity:providerWait.wrongstackRoutesAroundActiveSchedulesAnd`)})]})]})}var IS=`
129
+ `).length;a({chars:i.length,lines:e}),setTimeout(()=>a(null),4e3)}},pasteHint:i,pendingImagesRef:c,pendingImages:l,addImageFiles:p,removeImage:e=>{d(c.current.filter(t=>t.id!==e))},clearPendingImages:()=>d([]),setPendingImages:d,setPasteHint:a}}function uS({clientConnected:e,t,sendMessage:n,setInput:r}){let i=q(e=>e.refinePanel),a=q(e=>e.setRefinePanel),o=J(e=>e.enqueue),s=J(e=>e.addMessage),c=J(e=>e.setLoading);(0,X.useEffect)(()=>{if(!i||(i.status??`refining`)!==`refining`)return;let l=i.retried?21e4:105e3,u=setTimeout(()=>{let i=q.getState().refinePanel;if(i&&(i.status??`refining`)===`refining`){if(a(null),B.info(t(`chat:input.refineTimeoutFallback`)),i.mode!==void 0&&J.getState().isLoading){let e=i.images,t=e&&e.length>0&&i.mode===`btw`?`queue`:i.mode;o(i.original,t,e);return}e?(s({role:`user`,content:i.original}),c(!0),i.freshContext===!0?n(i.original,void 0,!0):n(i.original)):(r(i.original),B.error(t(`chat:input.notConnectedDraftKept`)))}},l);return()=>clearTimeout(u)},[i,e,s,c,n,a,o,r,t])}function dS({onTranscript:e}){let[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(!1),a=(0,X.useRef)(null);return(0,X.useEffect)(()=>{if(typeof window>`u`)return;let e=window.SpeechRecognition||window.webkitSpeechRecognition;i(!!e)},[]),{isListening:t,isSupported:r,toggleListening:(0,X.useCallback)(()=>{if(typeof window>`u`)return;let r=window.SpeechRecognition||window.webkitSpeechRecognition;if(r){if(t){a.current?.stop(),n(!1);return}try{let t=new r;t.continuous=!0,t.interimResults=!1,t.lang=navigator.language||`en-US`,t.onresult=t=>{let n=``;for(let e=t.resultIndex;e<t.results.length;++e){let r=t.results[e];r?.isFinal&&r[0]&&(n+=r[0].transcript)}n.trim()&&e(n.trim())},t.onerror=()=>{n(!1)},t.onend=()=>{n(!1)},t.start(),a.current=t,n(!0)}catch{n(!1)}}},[t,e]),stopListening:(0,X.useCallback)(()=>{a.current?.abort?.(),a.current?.stop?.(),a.current=null,n(!1)},[])}}function fS({onOpenBreakdown:e}={}){let{isLoading:t,setLoading:n,addMessage:r,clearMessages:i}=J(Yr(e=>({isLoading:e.isLoading,setLoading:e.setLoading,addMessage:e.addMessage,clearMessages:e.clearMessages}))),a=J(e=>e.messages).length>0,o=J(e=>e.queue),s=J(e=>e.enqueue),c=J(e=>e.removeQueued),l=J(e=>e.clearQueue),u=q(e=>e.setCurrentView),d=q(e=>e.setPromptLibraryOpen),f=q(e=>e.pushPrompt),p=q(e=>e.promptHistory),m=q(e=>e.promptInsertRequest),h=q(e=>e.clearPromptInsert),g=q(e=>e.setProcessMonitorOpen),_=q(e=>e.setQueuePanelOpen),v=hf(),{sendMessage:y,sendAbort:b,client:x,refineModel:S,updatePrefs:C}=v,{t:w}=W(),T=G(e=>e.enhanceEnabled),E=H(e=>e.session?.provider),D=H(e=>e.session?.model),O=V(e=>e.provider),k=V(e=>e.model),[A,j]=(0,X.useState)(()=>q.getState().draftInput??``),M=(0,X.useRef)(null),{isListening:N,isSupported:P,toggleListening:F,stopListening:I}=dS({onTranscript:e=>{j(t=>t?`${t} ${e}`:e)}});uS({clientConnected:x?.isConnected,t:w,sendMessage:y,setInput:j}),Qx({client:x,sendMessage:y});let L=H(e=>e.lastInputTokens),ee=H(e=>e.maxContext),[R,z]=(0,X.useState)(null),[te,ne]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(!1),ae=(0,X.useRef)(!1),oe=(0,X.useRef)(null),se=(0,X.useRef)(null),ce=$a(e=>e.refs),{removeRef:le,clearRefs:ue}=$a.getState(),{draggingOver:de,onDragEnter:fe,onDragLeave:pe,onDragOver:me,onDrop:he,onTextPaste:ge,pasteHint:_e,pendingImagesRef:ve,pendingImages:ye,addImageFiles:be,removeImage:xe,clearPendingImages:Se,setPendingImages:Ce,setPasteHint:we}=lS({input:A,textareaRef:se,setInput:j,errorText:{tooManyImages:e=>w(`chat:input.tooManyImages`,{max:e}),imageProcessFailed:e=>w(`chat:input.imageProcessFailed`,{name:e}),imageTooLarge:e=>w(`chat:input.imageTooLarge`,{name:e})}}),Te=(0,X.useRef)(null);(0,X.useEffect)(()=>{q.getState().setDraftInput(A)},[A]),(0,X.useEffect)(()=>()=>{M.current!==null&&clearTimeout(M.current)},[]);let Ee=Pe(),De=(0,X.useCallback)(()=>{Yx(Ee);let e=se.current;e&&(e.value=``,e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,t||e.focus())},[t,Ee]),Oe=(0,X.useCallback)(()=>{let e=!T;G.getState().set({enhanceEnabled:e}),C({enhanceEnabled:e})},[T,C]),ke=(0,X.useRef)(()=>!1),{sendMsg:Ae,handleSubmit:je,handleBtw:Me,handleSteer:Ne,handleAddQueue:Fe,handleAbort:Ie,handleStopAndEdit:Le}=eS({input:A,setInput:j,sessionId:Ee,textareaRef:se,pendingImagesRef:ve,clearPendingImages:Se,isLoading:t,setLoading:n,addMessage:r,enqueue:s,ws:v,enhanceEnabled:T,pushPrompt:f,setHistoryIdx:e=>Ue(e),stickyDraftRef:{get current(){return We.current},set current(e){We.current=e}},refineBackstopTimerRef:M,topicCheckBusyRef:ae,topicCheckAbortRef:oe,setTopicCheckBusy:ie,runSlashCommand:e=>ke.current(e),clearTextarea:De,t:w}),Re=(0,X.useCallback)(a=>Ef({raw:a,addMessage:r,clearMessages:i,isLoading:t,client:x,queue:o,sendAbort:b,sendMsg:Ae,setLoading:n,setCurrentView:u,toggleRefineEnabled:Oe,setProcessMonitorOpen:g,setQueuePanelOpen:_,ws:v,onOpenBreakdown:e,handleNextList:zx,handleNextSelect:e=>Bx(e,Ae)}),[r,i,t,x,o,b,Ae,n,u,Oe,g,_,v,e]);ke.current=Re;let{slashIndex:ze,setSlashIndex:Be,slashSuggestions:Ve,historyIdx:He,setHistoryIdx:Ue,stickyDraftRef:We,handleKeyDown:Ge}=$x({input:A,setInput:j,textareaRef:se,atMention:R,promptHistory:p,runSlashCommand:Re,handleSubmit:je});Xx({sessionId:Ee,input:A,setInput:j,pendingImages:ye,setPendingImages:Ce,clearPendingImages:Se,fileRefs:ce,clearRefs:ue,setHistoryIdx:Ue,stickyDraftRef:We,setAtMention:z,setPasteHint:we,stopSpeech:I,topicCheckAbortRef:oe,topicCheckBusyRef:ae,setTopicCheckBusy:ie,refineBackstopTimerRef:M,textareaRef:se}),(0,X.useEffect)(()=>{m!=null&&(j(e=>e.trim()?`${e}\n${m}`:m),h(),requestAnimationFrame(()=>se.current?.focus()))},[m,h]);let Ke=()=>{let e=se.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)};return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(Fm,{}),_e&&(0,Z.jsx)(Sx,{pasteHint:_e,onDismiss:()=>we(null),t:w}),(0,Z.jsx)(Cx,{pendingImages:ye,onRemove:xe,onClearAll:Se,t:w}),(0,Z.jsx)(Hx,{queue:o,onClear:l,onRemove:c}),(0,Z.jsx)(Kx,{enhanceEnabled:T,refinePickOpen:te,setRefinePickOpen:ne,refineModel:S,clientConnected:x?.isConnected===!0,addUserMessage:e=>r({role:`user`,content:e}),setLoading:n,sendMessage:y,isLoading:t,enqueue:s,setInput:j,resolveCancelInput:qx,notConnectedDraftKept:()=>B.error(w(`chat:input.notConnectedDraftKept`))}),(0,Z.jsx)(Tx,{sessionProvider:E,sessionModel:D,fallbackProvider:O,fallbackModel:k,onOpenPromptLibrary:()=>d(!0),onOpenModelSwitcher:()=>q.getState().setModelSwitcherOpen(!0),t:w}),(0,Z.jsx)(wx,{fileRefs:ce,onRemove:le,onClearAll:ue,t:w}),re&&(0,Z.jsx)(`div`,{className:`px-1 text-xs text-muted-foreground`,role:`status`,children:w(`chat:input.topicShiftChecking`)}),(0,Z.jsxs)(`form`,{onSubmit:je,onDragEnter:fe,onDragOver:me,onDragLeave:pe,onDrop:he,"data-session-id":Ee??void 0,"data-running":t?`true`:`false`,"data-chat-started":a?`true`:`false`,"data-has-draft":A.trim()||ye.length>0?`true`:`false`,className:K(`relative flex flex-col gap-2 rounded-xl border border-border/70 bg-background/85 p-2 shadow-lg shadow-black/5 transition-colors sm:flex-row sm:items-end`,t&&`border-warning/45 bg-warning/5 shadow-warning/10`,!a&&!t&&`border-border/50 bg-card/55 shadow-none`,de&&`ring-2 ring-primary ring-offset-2 ring-offset-background bg-primary/5`),children:[de&&(0,Z.jsx)(`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:w(`chat:input.dropOverlay`)}),(0,Z.jsxs)(`div`,{className:`relative w-full flex-1`,children:[(0,Z.jsx)(jx,{atMention:R,input:A,textareaRef:se,setInput:j,setAtMention:z}),!R&&(0,Z.jsx)(Zx,{suggestions:Ve,selectedIndex:ze,onSelectIndex:Be,onRun:e=>{j(``),Re(e)}}),(0,Z.jsx)(`textarea`,{ref:se,"data-chat-textarea":!0,value:A,onChange:e=>{let t=e.target.value;j(t),Ke(),He>=0&&(Ue(-1),We.current=null);let n=e.target.selectionStart??t.length;z(bf(t,n))},onSelect:e=>{let t=e.currentTarget;z(bf(t.value,t.selectionStart))},onKeyDown:Ge,onPaste:ge,placeholder:x?.isConnected?w(t?`chat:inputPlaceholderLoading`:`chat:inputPlaceholder`):w(`chat:inputPlaceholderConnecting`),className:K(`flex min-h-[64px] w-full resize-none overflow-y-auto rounded-lg border border-input bg-card/80 px-4 py-3 pr-12 shadow-sm sm:min-h-[44px]`,`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:!x?.isConnected||re}),(0,Z.jsx)(kx,{input:A,lastInputTokens:L,maxContext:ee})]}),(0,Z.jsx)(Ox,{imagePickerRef:Te,disabled:!x?.isConnected||re,topicCheckBusy:re,clientConnected:x?.isConnected===!0,isLoading:t,chatStarted:a,input:A,pendingImages:ye,addImageFiles:be,handleStopAndEdit:Le,handleAbort:Ie,handleBtw:Me,handleSteer:Ne,handleAddQueue:Fe,updatePrefs:C,t:w,isListening:N,isSpeechSupported:P,onToggleSpeech:F})]})]})}function pS(e){return{index:e.promptIndex,iteration:e.promptIndex,timestamp:e.ts??``,label:e.promptPreview??``,messageCount:0,tokens:0,fileCount:e.fileCount??0}}function mS({open:e,onClose:t,className:n}){let{t:r}=W(),[i,a]=(0,X.useState)([]),[o,s]=(0,X.useState)(!1),c=hf(),l=V(e=>e.wsConnected),u=(0,X.useRef)(null),d=Pe();(0,X.useEffect)(()=>{if(e&&l&&c.client?.isConnected)return a([]),c.client.send?.({type:`session.checkpoints`,payload:c.client.withSession({})}),u.current=c.client.on?.(`session.checkpoints`,e=>{let t=e?.payload;(t?.sessionId===void 0||d===void 0||t.sessionId===d)&&t?.checkpoints&&a(t.checkpoints.map(pS))})??null,()=>{u.current?.()}},[e,l,c.client,d]);let f=(0,X.useCallback)(async e=>{s(!0),c.client.send?.({type:`session.rewind`,payload:c.client.withSession({checkpointIndex:e})}),setTimeout(()=>{t(),s(!1)},800)},[c.client,t]);return(0,Z.jsx)(es,{open:e,onOpenChange:e=>{e||t()},children:(0,Z.jsxs)(Zo,{className:K(`max-w-md gap-0 overflow-hidden border-border/80 bg-card p-0 pt-[10dvh] flex flex-col max-h-[75dvh]`,n),children:[(0,Z.jsx)(Qo,{className:`sr-only`,children:r(`activity:checkpoint.heading`)}),(0,Z.jsx)($o,{className:`sr-only`,children:r(`activity:checkpoint.countSuffix`,{count:i.length})}),(0,Z.jsx)(`div`,{className:`flex items-center justify-between border-b border-border/70 bg-card/95 px-4 py-3 shrink-0`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Z.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-md border border-primary/20 bg-primary/10 text-primary`,children:(0,Z.jsx)(un,{className:`h-4 w-4`})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold`,children:r(`activity:checkpoint.heading`)}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:r(`activity:checkpoint.countSuffix`,{count:i.length})})]})]})}),(0,Z.jsx)(`div`,{className:`border-b border-border/70 bg-muted/25 px-4 py-2.5 text-[10px] text-muted-foreground leading-relaxed`,children:r(`activity:checkpoint.description`)}),(0,Z.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain`,children:i.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,Z.jsx)(la,{className:`h-10 w-10 opacity-15`}),(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:r(`activity:checkpoint.emptyTitle`)}),(0,Z.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:r(`activity:checkpoint.emptyBody`)})]}):(0,Z.jsx)(`div`,{className:`py-1`,children:[...i].reverse().map((e,t)=>{let n=t===0;return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>f(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,Z.jsxs)(`div`,{className:`flex flex-col items-center mt-1.5`,children:[(0,Z.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,Z.jsx)(`div`,{className:`w-px flex-1 min-h-[20px] bg-border/50`})]}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground tabular-nums shrink-0`,children:[`#`,e.index]}),(0,Z.jsx)(`span`,{className:`text-xs font-medium truncate`,children:e.label}),n&&(0,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[10px] text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`tabular-nums`,children:r(`activity:checkpoint.msgSuffix`,{count:e.messageCount})}),(0,Z.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Z.jsxs)(`span`,{className:`tabular-nums`,children:[e.fileCount??0,` files`]}),(0,Z.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,Z.jsxs)(`span`,{className:`tabular-nums`,children:[`iter `,e.iteration]})]})]}),(0,Z.jsx)(`span`,{className:`shrink-0 mt-1.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Z.jsx)(Ma,{className:`h-4 w-4 text-primary`})})]},e.index)})})}),(0,Z.jsxs)(`div`,{className:`border-t border-border/70 bg-muted/20 px-4 py-2 text-[10px] text-muted-foreground text-center shrink-0`,children:[r(`activity:checkpoint.footerPre`),` ·`,` `,(0,Z.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted font-mono text-[9px]`,children:`Esc`}),` `,r(`activity:checkpoint.footerPost`)]})]})})}function hS(e){return!!(e?.role===`user`&&Array.isArray(e.content)&&e.content.length>0&&e.content.every(e=>e.type===`tool_result`))}function gS(e,t){if(e[t]?.role!==`user`||hS(e[t]))return[];let n=[];for(let r=t+1;r<e.length;r+=1){let t=e[r];if(t?.role===`user`&&!hS(t))break;t?.role===`assistant`&&n.push(r)}return n}function _S(e,t){return e.messageBreakdown.find(e=>e.index===t)?.pairedAssistantIndices??gS(e.messages,t)}function vS(e,t,n){let r=new Set(t);return e.messages.forEach((i,a)=>{if(i.role===`user`&&(t.has(a)||n.some(e=>e.messageIndex===a)))for(let t of _S(e,a))r.add(t)}),r}function yS(e){let t=new Map;for(let n of e){let e=`${n.messageIndex}:${n.blockIndex??`string`}`;t.set(e,[...t.get(e)??[],n])}return[...t.values()].flatMap(e=>{let t=e.sort((e,t)=>(e.start??0)-(t.start??0)),n=[];for(let e of t){let t=n.at(-1);t?.end!==void 0&&e.start!==void 0&&e.end!==void 0&&e.start<=t.end?t.end=Math.max(t.end,e.end):n.push({...e})}return n})}function bS(e,t){if(t<=0||t>=e.length)return!1;let n=e.charCodeAt(t-1),r=e.charCodeAt(t);return n>=55296&&n<=56319&&r>=56320&&r<=57343}function xS(e,t){if(t.start===void 0||t.end===void 0)return;let n=e[t.messageIndex];if(!n)return;if(t.blockIndex===void 0&&typeof n.content==`string`){n.content=n.content.slice(0,t.start)+n.content.slice(t.end);return}if(!Array.isArray(n.content)||t.blockIndex===void 0)return;let r=n.content[t.blockIndex];r?.type===`text`&&typeof r.text==`string`&&(r.text=r.text.slice(0,t.start)+r.text.slice(t.end))}var SS={phase:`closed`,revision:null,messages:[],readonlyContext:null,messageBreakdown:[],diagnostics:null,removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],validation:null,appliedResult:null,errorMessage:null},CS=Xa(((e,t)=>({...SS,open:()=>e({...SS,phase:`loading_snapshot`,removeMessages:new Set,explicitRemoveMessages:new Set}),close:()=>e({...SS}),loadSnapshot:t=>e(e=>{let n=e.phase===`applied_success`&&e.appliedResult!==null;return{phase:n?`applied_success`:`clean_snapshot`,revision:t.revision,messages:t.messages,readonlyContext:t.readonlyContext,messageBreakdown:t.messageBreakdown,diagnostics:t.diagnostics,removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],validation:null,appliedResult:n?e.appliedResult:null,errorMessage:null}}),toggleRemoveMessage:n=>{let r=t();if(r.phase===`validating`||r.phase===`applying`)return;let i=new Set(r.explicitRemoveMessages);if(r.messages[n]?.role===`assistant`&&r.messages.some((e,t)=>e.role===`user`&&(r.explicitRemoveMessages.has(t)||r.removeRanges.some(e=>e.messageIndex===t))&&_S(r,t).includes(n))&&r.removeMessages.has(n))return;i.has(n)?i.delete(n):i.add(n);let a=r.removeRanges,o=vS(r,i,a);e({removeMessages:o,explicitRemoveMessages:i,removeRanges:a,phase:o.size>0||a.length>0?`dirty`:`clean_snapshot`,validation:null})},markRangeForRemoval:n=>{let r=t();if(r.phase===`validating`||r.phase===`applying`||r.explicitRemoveMessages.has(n.messageIndex)||n.start===void 0||n.end===void 0||n.start<0||n.end<=n.start)return;let i=r.messages[n.messageIndex],a;if(n.blockIndex===void 0&&typeof i?.content==`string`)a=i.content;else if(n.blockIndex!==void 0&&Array.isArray(i?.content)){let e=i.content[n.blockIndex];e?.type===`text`&&(a=e.text)}if(a===void 0||n.end>a.length||bS(a,n.start)||bS(a,n.end))return;let o=yS([...r.removeRanges,n]);e({removeMessages:vS(r,r.explicitRemoveMessages,o),removeRanges:o,phase:`dirty`,validation:null})},clearRemovals:()=>e({removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],phase:`clean_snapshot`,validation:null}),beginValidation:()=>e({phase:`validating`,validation:null,errorMessage:null}),beginApply:()=>e({phase:`applying`,errorMessage:null}),setValidation:t=>e({validation:t,phase:t.conflict?`conflicted`:t.ok?`validated`:`invalid`,errorMessage:null}),setApplied:t=>e({appliedResult:t,phase:`applied_success`,removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],validation:null,errorMessage:null}),setError:n=>e({errorMessage:n,phase:n?`apply_failed`:t().phase}),resetToClean:()=>e({phase:`clean_snapshot`,removeMessages:new Set,explicitRemoveMessages:new Set,removeRanges:[],validation:null,errorMessage:null}),getProposedMessages:()=>{let e=t(),n=structuredClone(e.messages);for(let t of[...e.removeRanges].sort((e,t)=>(t.start??0)-(e.start??0)))xS(n,t);return n.filter((t,n)=>!e.removeMessages.has(n))}})));function wS(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function TS(e){let t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return null;let n=t.getRangeAt(0);if(!e.contains(n.commonAncestorContainer))return null;let r=n.cloneRange();r.selectNodeContents(e),r.setEnd(n.startContainer,n.startOffset);let i=r.toString().length,a=i+n.toString().length;return a>i?{start:i,end:a}:null}function ES(e){return e.type===`image`?e.source?.type===`base64`?`${e.source.media_type??`image`} · ${e.source.data?.length??0} base64 chars`:`URL image source`:e.type===`tool_use`?`${e.name??`tool`} · ${e.id??`unknown id`}`:e.type===`tool_result`?`tool result · ${e.tool_use_id??`unknown id`}`:e.type===`thinking`?`thinking · ${e.thinking?.length??0} chars`:e.type}function DS({text:e,blockIndex:t,marked:n,disabled:r,onMarkRange:i}){let[a,o]=(0,X.useState)(null),s=(0,X.useRef)(null),c=(0,X.useCallback)(()=>{if(r)return;let e=s.current;e&&o(TS(e))},[r]);return(0,X.useEffect)(()=>{o(null)},[e]),(0,Z.jsxs)(`div`,{className:K(`rounded-md border bg-background p-3`,n&&`border-destructive/40 bg-destructive/5`),children:[(0,Z.jsx)(`p`,{ref:s,className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground select-text`,onMouseUp:c,onKeyUp:c,tabIndex:r?-1:0,children:e||`(empty)`}),a&&(0,Z.jsx)(`button`,{type:`button`,disabled:r,className:`mt-2 rounded-md border border-destructive/30 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/10 disabled:cursor-not-allowed disabled:opacity-40`,onMouseDown:e=>e.preventDefault(),onClick:()=>{i(t,a.start,a.end),window.getSelection()?.removeAllRanges(),o(null)},children:`Mark for removal`})]})}function OS({index:e,role:t,tokens:n,content:r,blockCount:i,warnings:a,markedForRemoval:o,markedRanges:s,disabled:c,onToggle:l,onMarkRange:u}){let[d,f]=(0,X.useState)(!1),p=t===`user`?`text-primary`:t===`assistant`?`text-success`:`text-muted-foreground`,m=a.length>0;return(0,Z.jsxs)(`div`,{className:K(`group flex items-start gap-3 rounded-lg border bg-card p-3 transition-colors`,o&&`border-destructive/40 bg-destructive/5 opacity-70`,!o&&`hover:border-primary/30`),children:[(0,Z.jsx)(`button`,{type:`button`,onClick:l,disabled:c,className:`mt-0.5 shrink-0 disabled:cursor-not-allowed disabled:opacity-40`,"aria-label":o?`Undo removal`:`Mark for removal`,children:o?(0,Z.jsx)(jn,{className:`h-3.5 w-3.5 text-destructive`}):(0,Z.jsx)(`div`,{className:`h-3.5 w-3.5 rounded-sm border border-border/60 group-hover:border-primary/50 transition-colors`})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[i!==null&&i>0&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>f(e=>!e),className:`text-muted-foreground/60 hover:text-foreground shrink-0`,children:d?(0,Z.jsx)(gn,{className:`h-3 w-3`}):(0,Z.jsx)(ui,{className:`h-3 w-3`})}),(0,Z.jsx)(`span`,{className:K(`font-mono font-medium`,p),children:t}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground/60 tabular-nums`,children:[wS(n),` tok`]}),i!==null&&i>0&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground/50 tabular-nums`,children:[i,` blk`]}),m&&(0,Z.jsx)(dr,{className:`h-3 w-3 text-warning shrink-0`})]}),(0,Z.jsx)(`div`,{className:`mt-3 space-y-2`,children:typeof r==`string`?(0,Z.jsx)(DS,{text:r,marked:s.some(e=>e.blockIndex===void 0),disabled:c,onMarkRange:u}):r.map((t,n)=>(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:t.type}),typeof t.text==`string`&&(0,Z.jsxs)(`span`,{children:[wS(Math.ceil(t.text.length/4)),` tok`]})]}),t.type===`text`&&typeof t.text==`string`?(0,Z.jsx)(DS,{text:t.text,blockIndex:n,marked:s.some(e=>e.blockIndex===n),disabled:c,onMarkRange:u}):(0,Z.jsx)(`div`,{className:`rounded-md border bg-muted/20 p-3 font-mono text-[11px] text-muted-foreground`,children:ES(t)})]},`${e}-${n}`))}),d&&m&&(0,Z.jsx)(`div`,{className:`mt-2 space-y-1`,children:a.map((e,t)=>(0,Z.jsxs)(`div`,{className:K(`flex items-start gap-1 text-[10px] rounded px-1.5 py-0.5`,e.severity===`danger`?`bg-destructive/10 text-destructive`:e.severity===`warning`?`bg-warning/10 text-warning`:`bg-muted text-muted-foreground`),children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:e.code}),(0,Z.jsx)(`span`,{className:`opacity-80`,children:e.message})]},t))})]})]})}var kS=5e3;function AS({open:e,onClose:t}){let{t:n}=W(),r=CS(e=>e.phase),i=CS(e=>e.revision),a=CS(e=>e.messageBreakdown),o=CS(e=>e.readonlyContext),s=CS(e=>e.messages),c=CS(e=>e.removeMessages),l=CS(e=>e.removeRanges),u=CS(e=>e.validation),d=CS(e=>e.appliedResult),f=CS(e=>e.errorMessage),p=CS,m=J(e=>e.isLoading),h=H(e=>e.contextLimitWarning),g=Pe(),_=(0,X.useRef)(null),v=S()?.withSession?.({})?.sessionId??g??He()??void 0;up(`context.editor.snapshot`,e=>{let t=e.payload;t&&typeof t.revision==`string`&&Array.isArray(t.messages)&&p.getState().loadSnapshot(t)},{sessionId:v,deps:[e,p,v]}),up(`context.editor.validation`,e=>{p.getState().setValidation(e.payload)},{sessionId:v,deps:[e,p,v]}),up(`context.editor.applied`,e=>{p.getState().setApplied(e.payload);let t=S();typeof t?.openContextEditor==`function`&&t.openContextEditor()},{sessionId:v,deps:[e,p,v]}),(0,X.useEffect)(()=>{if(!e){p.getState().close();return}(p.getState().phase===`closed`||p.getState().phase===`apply_failed`)&&p.getState().open();let t=S();if(!t?.send||!t?.on){p.getState().setError(U.t(`activity:context.wsNotConnected`));return}t.send({type:`context.editor.open`,payload:t.withSession({})});let n=setTimeout(()=>{p.getState().phase===`loading_snapshot`&&p.getState().setError(U.t(`activity:ctxEditor.snapshotTimedOut`))},kS);return()=>clearTimeout(n)},[e,p,v]);let y=(0,X.useCallback)(()=>{let e=S();if(!e?.send||!i)return;p.getState().beginValidation();let t=p.getState(),n=t.getProposedMessages(),r=[...[...t.removeMessages].map(e=>({messageIndex:e})),...t.removeRanges];e.validateContextEditor(i,n,r,!0)},[i,p]),b=(0,X.useCallback)(()=>{let e=S();if(!e?.send||!i)return;let t=p.getState(),n=t.getProposedMessages(),r=[...[...t.removeMessages].map(e=>({messageIndex:e})),...t.removeRanges];p.getState().beginApply(),e.applyContextEditor(i,n,r,!0)},[i,p]);if(!e)return null;let x=r===`applying`||r===`validating`,C=c.size>0||l.length>0,w=r===`validated`&&!m,T=C&&!x&&!m,E=!x&&!(r===`dirty`&&C),D=()=>{E&&t()};return(0,Z.jsx)(es,{open:e,onOpenChange:e=>!e&&D(),children:(0,Z.jsxs)(Zo,{showCloseButton:!1,className:`max-h-[calc(100dvh-3rem)] max-w-4xl flex flex-col gap-0 overflow-hidden p-0 sm:p-0`,onOpenAutoFocus:()=>{let e=document.activeElement;_.current=e instanceof HTMLElement?e:null},onCloseAutoFocus:e=>{let t=_.current;t?.isConnected&&(e.preventDefault(),t.focus())},onPointerDownOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>{E||e.preventDefault()},children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-b px-4 py-3 shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Zt,{className:`h-4 w-4 text-primary`}),(0,Z.jsx)(Qo,{className:`text-sm font-semibold`,children:n(`activity:ctxEditor.contextWindowEditor`)}),i&&(0,Z.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground/60 ml-2`,children:[`rev `,i.slice(0,8),`…`]})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:D,disabled:!E,className:`p-1.5 rounded-md hover:bg-accent hover:text-accent-foreground transition-colors disabled:opacity-40`,"aria-label":n(`common:action.close`),children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),h&&(0,Z.jsxs)(`div`,{role:`status`,className:`mx-4 mt-3 flex items-start gap-2 rounded-md border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:[(0,Z.jsx)(dr,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Z.jsx)(`span`,{children:n(`activity:ctxEditor.providerLimitDecreased`,{previous:wS(h.previousMaxContext),current:wS(h.maxContext)})})]}),o&&(0,Z.jsxs)(`div`,{className:`grid grid-cols-4 gap-2 px-4 py-2 border-b bg-muted/20 text-[11px] shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground/60`,children:n(`activity:ctxEditor.system`)}),(0,Z.jsx)(`span`,{className:`font-mono font-medium`,children:wS(o.systemPromptTokens)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[`Tools (`,o.toolCount,`)`]}),(0,Z.jsx)(`span`,{className:`font-mono font-medium`,children:wS(o.toolSchemaTokens)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground/60`,children:n(`activity:ctxEditor.messages`)}),(0,Z.jsx)(`span`,{className:`font-mono font-medium`,children:wS(o.messageTokens)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground/60`,children:n(`activity:ctxEditor.total`)}),(0,Z.jsx)(`span`,{className:`font-mono font-medium text-primary`,children:wS(o.totalTokens)})]})]}),r===`loading_snapshot`&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-muted-foreground py-12`,children:[(0,Z.jsx)(mn,{className:`h-4 w-4 animate-spin`}),n(`activity:ctxEditor.loadingContextSnapshot`)]}),r!==`loading_snapshot`&&a.length===0&&!f&&(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0 flex-col items-center justify-center gap-2 px-6 py-12 text-center text-sm text-muted-foreground`,children:[(0,Z.jsx)(Vn,{className:`h-5 w-5 text-muted-foreground/60`}),(0,Z.jsx)(`p`,{children:n(`activity:ctxEditor.emptyConversation`)})]}),f&&r===`apply_failed`&&(0,Z.jsx)(`div`,{className:`m-4 rounded-md bg-destructive/10 border border-destructive/20 p-3 text-sm text-destructive`,children:f}),r===`applied_success`&&d&&(0,Z.jsxs)(`div`,{className:`m-4 rounded-md bg-success/10 border border-success/20 p-3 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-success font-medium`,children:[(0,Z.jsx)(Bn,{className:`h-4 w-4`}),`Context updated: `,d.before.messages,` → `,d.after.messages,` `,`messages`]}),(0,Z.jsxs)(`div`,{className:`mt-1 text-muted-foreground text-xs`,children:[`Saved`,` `,wS(d.before.fullRequestTokens-d.after.fullRequestTokens),` `,`tokens`,d.removed.toolUses.length>0&&` · ${d.removed.toolUses.length} tool calls repaired`]})]}),u?.conflict&&(0,Z.jsxs)(`div`,{className:`m-4 rounded-md bg-warning/10 border border-warning/20 p-3 text-sm text-warning`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[(0,Z.jsx)(dr,{className:`h-4 w-4`}),u.conflict.code===`CONTEXT_REVISION_CONFLICT`?`Context changed while editor was open.`:`Agent is currently running.`]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs opacity-80`,children:u.conflict.message})]}),r!==`loading_snapshot`&&a.length>0&&(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 space-y-3 overflow-y-auto overscroll-contain bg-muted/10 p-4`,children:a.map(e=>(0,Z.jsx)(OS,{index:e.index,role:e.role,tokens:e.tokens,content:s[e.index]?.content??``,blockCount:e.blockCount,warnings:e.warnings,markedForRemoval:c.has(e.index),markedRanges:l.filter(t=>t.messageIndex===e.index),disabled:x,onToggle:()=>p.getState().toggleRemoveMessage(e.index),onMarkRange:(t,n,r)=>p.getState().markRangeForRemoval({messageIndex:e.index,...t===void 0?{}:{blockIndex:t},start:n,end:r})},e.index))}),u?.ok===!1&&u.validationErrors.length>0&&(0,Z.jsxs)(`div`,{className:`border-t px-4 py-2 bg-destructive/5 shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`text-[11px] font-medium text-destructive mb-1`,children:[`Validation errors (`,u.validationErrors.length,`)`]}),u.validationErrors.slice(0,5).map((e,t)=>(0,Z.jsxs)(`div`,{className:`text-[10px] text-destructive/80 font-mono`,children:[e.path,`: `,e.message]},t))]}),u?.ok&&u.repair.changed&&(0,Z.jsx)(`div`,{className:`border-t px-4 py-2 bg-warning/5 shrink-0`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[(0,Z.jsx)(mi,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:n(`activity:ctxEditor.repairPreviewWillRemove`)}),u.repair.removedToolUses.length>0&&(0,Z.jsxs)(`span`,{children:[u.repair.removedToolUses.length,` orphan tool_use(s)`]}),u.repair.removedToolResults.length>0&&(0,Z.jsxs)(`span`,{children:[u.repair.removedToolResults.length,` orphan tool_result(s)`]}),u.repair.removedMessages>0&&(0,Z.jsxs)(`span`,{children:[u.repair.removedMessages,` empty message(s)`]})]})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t px-4 py-3 shrink-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground`,children:[C&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(jn,{className:`h-3 w-3 text-destructive`}),(0,Z.jsxs)(`span`,{children:[c.size,` message`,c.size===1?``:`s`,` and`,` `,l.length,` range`,l.length===1?``:`s`,` marked`]})]}),m&&(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-warning`,children:[(0,Z.jsx)(la,{className:`h-3 w-3`}),n(`activity:ctxEditor.agentRunningApplyDisabled`)]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[C&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>p.getState().clearRemovals(),className:`text-[11px] text-muted-foreground hover:text-foreground transition-colors`,disabled:x,children:n(`activity:ctxEditor.clear`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:y,disabled:!T,className:K(`flex items-center gap-1.5 rounded-md px-3 py-1.5 text-[11px] font-medium transition-colors`,T?`bg-secondary text-secondary-foreground hover:bg-secondary/80`:`bg-muted text-muted-foreground/40 cursor-not-allowed`),children:[r===`validating`?(0,Z.jsx)(mn,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Vn,{className:`h-3 w-3`}),`Validate`]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:b,disabled:!w,className:K(`flex items-center gap-1.5 rounded-md px-3 py-1.5 text-[11px] font-medium transition-colors`,w?`bg-primary text-primary-foreground hover:bg-primary/90`:`bg-muted text-muted-foreground/40 cursor-not-allowed`),children:[r===`applying`?(0,Z.jsx)(mn,{className:`h-3 w-3 animate-spin`}):(0,Z.jsx)(Bn,{className:`h-3 w-3`}),`Apply Changes`]})]})]})]})})}function jS(e,t){if(!e)return`reset time unknown`;let n=Math.max(0,Math.ceil((e-t)/1e3));if(n===0)return`rechecking now`;if(n<60)return`${n}s`;let r=Math.floor(n/60);return r<60?`${r}m ${n%60}s`:`${Math.floor(r/60)}h ${r%60}m`}function MS(e,t){if(!e)return``;let n=Math.max(0,Math.floor((t-e)/1e3));if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ${r%60}m ago`}var NS=/Sibling quarantine:.*?\bon\s+([^\s/]+\/\S+)/;function PS(e){return NS.exec(e.lastErrorMessage??``)?.[1]??null}function FS(){let{t:e}=W(),t=mo(e=>e.entries);mo(e=>e.summary);let n=mo(e=>e.removeEntry),r=mo(e=>e.audit),i=G(e=>e.modelAvailabilitySchedule),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(Date.now()),p=(0,X.useMemo)(()=>Object.values(t).sort((e,t)=>(e.stateExpiresAt??0)-(t.stateExpiresAt??0)),[t]),m=(0,X.useMemo)(()=>p.filter(e=>e.state!==`healthy`),[p]),h=(0,X.useMemo)(()=>nv(i,new Date(d)),[i,d]),g=(0,X.useCallback)(()=>{S().getProviderStatus()},[]),_=(0,X.useCallback)(()=>{u(e=>{let t=!e;return t&&S().getProviderAuditHistory(20),t})},[]),v=(0,X.useCallback)((e,t)=>{S().retryProviderModel(e,t),n(e,t)},[n]),y=(0,X.useCallback)((e,t)=>{S().clearProviderStatus(e,t),n(e,t)},[n]);if((0,X.useEffect)(()=>{if(m.length===0&&h.length===0)return;let e=window.setInterval(()=>f(Date.now()),1e3);return()=>window.clearInterval(e)},[h.length,m.length]),(0,X.useEffect)(()=>{a&&g()},[a,g]),m.length===0&&h.length===0)return null;let b=m.filter(e=>e.state===`blocked`).length,x=m.length-b;return s&&t[s],(0,Z.jsxs)(`div`,{className:`mx-auto mb-2 max-w-6xl rounded-lg border border-warning/25 bg-warning/5 text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex w-full items-center gap-2 px-3 py-2 hover:bg-warning/5`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`flex flex-1 items-center gap-2 text-left`,onClick:()=>o(e=>!e),"aria-expanded":a,children:[(0,Z.jsx)(dr,{className:`h-3.5 w-3.5 text-warning`}),(0,Z.jsx)(`span`,{className:`font-medium text-foreground`,children:e(`activity:providerWait.providerModelAvailability`)}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[b,` blocked · `,x,` degraded · `,h.length,` scheduled`]}),(0,Z.jsx)(`span`,{className:`ml-auto text-muted-foreground`,children:a?`Hide`:`Details`})]}),(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-muted-foreground transition-colors hover:text-foreground`,onClick:g,title:e(`activity:providerWait.refreshStatus`),"aria-label":e(`activity:providerWait.refreshStatus`),children:(0,Z.jsx)(Yn,{className:`h-3 w-3`})})]}),a&&(0,Z.jsxs)(`div`,{className:`border-t border-warning/15 px-3 py-2`,children:[m.map(t=>{let n=`${t.providerId}\u0000${t.model}`,r=s===n,i=PS(t);return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`button`,{type:`button`,className:`flex flex-wrap cursor-pointer items-center gap-x-2 gap-y-1 py-1.5 hover:bg-warning/5`,onClick:()=>c(r?null:n),children:[t.state===`blocked`?(0,Z.jsx)(Fr,{className:`h-3.5 w-3.5 text-warning`}):(0,Z.jsx)(Bn,{className:`h-3.5 w-3.5 text-warning`}),(0,Z.jsxs)(`code`,{className:`text-foreground`,children:[t.providerId,`/`,t.model]}),(0,Z.jsx)(`span`,{className:`rounded bg-warning/10 px-1.5 py-0.5 text-warning`,children:t.state}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:t.reason.replaceAll(`_`,` `)}),i&&(0,Z.jsxs)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-muted-foreground`,children:[`via `,i]}),(0,Z.jsx)(`span`,{className:`ml-auto tabular-nums text-muted-foreground`,children:jS(t.stateExpiresAt,d)})]}),r&&(0,Z.jsxs)(`div`,{className:`ml-6 mb-2 rounded border border-border/50 bg-background/50 p-2`,children:[t.lastErrorMessage&&(0,Z.jsxs)(`div`,{className:`mb-1.5 text-destructive`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[e(`activity:providerWait.lastError`),` `]}),t.lastErrorMessage.slice(0,300)]}),(0,Z.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap gap-x-3 gap-y-0.5 text-muted-foreground`,children:[t.totalFailures!==void 0&&(0,Z.jsxs)(`span`,{children:[`failures: `,t.totalFailures]}),t.rateLimitHits!==void 0&&t.rateLimitHits>0&&(0,Z.jsxs)(`span`,{children:[`rate-limits: `,t.rateLimitHits]}),t.consecutiveFailures!==void 0&&(0,Z.jsxs)(`span`,{children:[`streak: `,t.consecutiveFailures]}),t.lastErrorStatus!==void 0&&(0,Z.jsxs)(`span`,{children:[`HTTP: `,t.lastErrorStatus]}),t.lastSessionId&&(0,Z.jsxs)(`span`,{children:[`session: `,t.lastSessionId.slice(0,12),`…`]}),t.lastAgentId&&(0,Z.jsxs)(`span`,{children:[`agent: `,t.lastAgentId.slice(0,16),`…`]}),t.lastFailureAt&&(0,Z.jsx)(`span`,{children:MS(t.lastFailureAt,d)})]}),t.recentErrors&&t.recentErrors.length>0&&(0,Z.jsxs)(`details`,{className:`mb-1.5`,children:[(0,Z.jsxs)(`summary`,{className:`cursor-pointer text-muted-foreground hover:text-foreground`,children:[`Error history (`,t.recentErrors.length,`)`]}),(0,Z.jsx)(`div`,{className:`mt-1 max-h-32 overflow-y-auto text-[11px] text-muted-foreground`,children:t.recentErrors.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex gap-2 border-b border-border/20 py-0.5`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums text-warning/70`,children:e.kind}),(0,Z.jsxs)(`span`,{className:`shrink-0 tabular-nums`,children:[`HTTP `,e.status]}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.message.slice(0,200)}),(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums`,children:MS(e.timestamp,d)})]},t))})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border bg-background px-2 py-1 text-[11px] font-medium text-foreground transition-colors hover:bg-accent`,onClick:()=>v(t.providerId,t.model),children:[(0,Z.jsx)(Xt,{className:`h-3 w-3`}),e(`activity:providerWait.reopenHalfOpenProbe`)]}),(0,Z.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-border bg-background px-2 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:text-foreground`,onClick:()=>y(t.providerId,t.model),children:[(0,Z.jsx)(jn,{className:`h-3 w-3`}),e(`activity:providerWait.clearTracking`)]})]})]})]},n)}),h.map(e=>(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 py-1.5`,children:[(0,Z.jsx)(Fr,{className:`h-3.5 w-3.5 text-info`}),(0,Z.jsx)(`code`,{className:`text-foreground`,children:tv(e)}),(0,Z.jsx)(`span`,{className:`rounded bg-info/10 px-1.5 py-0.5 text-info`,children:`scheduled`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.label??`calendar blackout`}),(0,Z.jsxs)(`span`,{className:`ml-auto tabular-nums text-muted-foreground`,children:[e.start,`–`,e.end,` · `,e.timezone??`local time`]})]},e.id)),(0,Z.jsxs)(`button`,{type:`button`,className:`mt-1 flex w-full items-center gap-2 border-t border-border/30 py-1.5 text-left hover:bg-warning/5`,onClick:_,"aria-expanded":l,children:[(0,Z.jsx)(Fr,{className:`h-3.5 w-3.5 text-warning`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e(`activity:providerWait.recentBlockOpenEvents`,{count:r.length})}),(0,Z.jsx)(`span`,{className:`ml-auto text-muted-foreground`,children:l?`Hide`:`Show`})]}),l&&(0,Z.jsx)(`div`,{className:`pt-1`,children:r.length===0?(0,Z.jsx)(`div`,{className:`py-1 text-muted-foreground`,children:e(`activity:providerWait.noBlockOpenEventsYet`)}):r.map((e,t)=>{let n=e.to!==`blocked`,r=[e.error?.sessionId,e.error?.agentId].filter(e=>typeof e==`string`&&e.length>0).map(e=>`${e.slice(0,12)}…`).join(` / `);return(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 py-0.5`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:MS(e.ts,d)}),(0,Z.jsxs)(`code`,{className:`text-foreground`,children:[e.providerId,`/`,e.model]}),(0,Z.jsxs)(`span`,{className:n?`text-info`:`text-warning`,children:[e.from,` → `,e.to]}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e.reason.replaceAll(`_`,` `)}),e.error&&(0,Z.jsxs)(`span`,{className:`text-destructive`,children:[e.error.kind,e.error.status==null?``:` ${e.error.status}`]}),r&&(0,Z.jsx)(`span`,{className:`ml-auto text-muted-foreground`,children:r})]},`${e.ts}-${t}`)})}),(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-muted-foreground`,children:e(`activity:providerWait.wrongstackRoutesAroundActiveSchedulesAnd`)})]})]})}var IS=`
130
130
  ::highlight(chat-search) { background-color: hsl(var(--primary) / 0.3); color: inherit; }
131
131
  ::highlight(chat-search-active) { background-color: hsl(var(--primary) / 0.85); color: hsl(var(--primary-foreground)); }
132
132
  `;function LS(e){return e.thinkingLog?[e.content,e.thinkingLog.text].filter(Boolean).join(`
@@ -174,4 +174,4 @@ Record the baseline, every attempt, and every keep/revert verdict in \`PERF_LOG.
174
174
  `).slice(-4).join(`
175
175
  `).trim();return(0,Z.jsxs)(`div`,{className:`ws-reasoning min-w-0 max-w-full py-0.5 sm:max-w-[720px]`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex w-full flex-wrap items-center gap-x-2 gap-y-0.5 text-left font-mono text-xs`,"aria-expanded":i,children:[(0,Z.jsx)(`span`,{className:`ws-reasoning__mark text-sm leading-none`,"aria-hidden":!0,children:`✦`}),(0,Z.jsx)(`span`,{className:`font-semibold uppercase tracking-wide text-primary`,children:r(`activity:message.thinkingProcess`)}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:r(`activity:message.thinkingMeta`,{iter:t.iteration,dur:s,lines:r(`activity:message.linesSuffix`,{count:n})})}),(0,Z.jsx)(`span`,{className:`ml-auto text-muted-foreground/60`,children:i?(0,Z.jsx)(gn,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(ui,{className:`h-3.5 w-3.5`})})]}),(0,Z.jsx)(`pre`,{className:K(`mt-1.5 whitespace-pre-wrap break-words font-mono text-xs italic leading-relaxed text-foreground/65`,i?`max-h-[32rem] overflow-auto`:`max-h-24 overflow-hidden`),children:i?t.text:c||t.text}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,Z.jsx)(NC,{text:t.text,label:r(`activity:message.copyLog`),className:`text-[10px] text-muted-foreground/60 opacity-70 transition-opacity hover:opacity-100`}),!i&&n>4&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`text-[10px] text-muted-foreground/70 transition-colors hover:text-foreground`,children:r(`activity:message.showFullLog`)})]})]})})():(()=>{if(ce)return null;let t=e.content,n=!!e.attachments&&e.attachments.length>0;return(0,Z.jsxs)(`div`,{className:K(`text-sm leading-relaxed markdown-content`,e.streaming&&`streaming-cursor`),children:[n&&(0,Z.jsx)(MC,{attachments:e.attachments??[],notRetainedLabel:r(`activity:message.imageNotRetained`)}),t?u&&e.role===`assistant`?(0,Z.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,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(FC,{text:e.content}),de&&!e.streaming&&!D&&(0,Z.jsx)(zC,{text:e.content,timestamp:e.timestamp})]}):e.streaming?(0,Z.jsx)(WC,{text:t}):(0,Z.jsx)(VC,{remarkPlugins:[ns],rehypePlugins:jh,components:Ph,children:t}):e.streaming?(0,Z.jsx)(`span`,{className:`inline-block animate-pulse text-muted-foreground`,children:r(`activity:message.typing`)}):n||fe.length>0?null:(0,Z.jsx)(`span`,{className:`text-muted-foreground italic`,children:r(`activity:message.noContent`)})]})})()}),f&&e.status===`failed`&&(0,Z.jsx)(`span`,{className:`text-[10px] font-medium text-destructive flex items-center gap-1 px-1`,children:r(`activity:message.failedToSend`)}),de&&!D&&fe.length>0&&(0,Z.jsx)(Ix,{steps:fe,yoloMode:z,autoMode:R===`auto`,autoDelayMs:ee.autonomyDelayMs,onAutoSubmit:le,canAutoSubmit:se,onBatchSubmit:ue,isLatest:de,sessionEndAutoFill:!0}),(0,Z.jsxs)(`div`,{className:K(`flex max-w-full flex-wrap items-center gap-2 px-1`,f?`flex-row-reverse`:`flex-row`),children:[!ce&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground/70`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),(0,Z.jsx)(`span`,{className:`w-px h-3 bg-border/60 shrink-0`,"aria-hidden":!0})]}),e.runSummary&&(0,Z.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/75 font-mono tabular-nums`,title:[r(`activity:message.rsIterations`,{n:e.runSummary.iterations}),r(`activity:message.rsTools`,{n:e.runSummary.tools}),r(`activity:message.rsElapsed`,{s:`${(e.runSummary.durationMs/1e3).toFixed(2)}s`}),e.runSummary.costDelta>0?r(`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+(t.cacheWrite??0))*F+t.output*I+(t.cacheRead??0)*L)/1e6,i=F>0||I>0,a=n>=.01?`${n.toFixed(4)}`:n>0?`${n.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``;return(0,Z.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/75 font-mono tabular-nums`,title:[r(`activity:message.useInput`,{n:t.input.toLocaleString()}),r(`activity:message.useOutput`,{n:t.output.toLocaleString()}),t.cacheRead?r(`activity:message.useCacheRead`,{n:t.cacheRead.toLocaleString()}):``,i?r(`activity:message.useCost`,{c:a}):``].filter(Boolean).join(` · `),children:[t.input.toLocaleString(),`→`,t.output.toLocaleString(),t.cacheRead?` · ${t.cacheRead.toLocaleString()} ↺`:``,i&&a?` · ${a}`:``]})})(),!y&&!v&&e.content&&!e.streaming&&(0,Z.jsx)(NC,{text:e.content,label:r(`common:action.copy`),className:`opacity-50 hover:opacity-100 transition-opacity`}),e.role===`assistant`&&e.content&&!e.streaming&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),title:r(u?`activity:message.showRenderedTitle`:`activity:message.showRawTitle`),className:K(`text-xs inline-flex items-center gap-1 transition-opacity`,u?`text-primary hover:text-primary/80 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[(0,Z.jsx)(Yt,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:r(u?`activity:message.renderedLabel`:`activity:message.rawLabel`)})]}),f&&!v&&!o&&!D&&(0,Z.jsxs)(Z.Fragment,{children:[e.status===`failed`&&(0,Z.jsxs)(`button`,{type:`button`,onClick:me,title:r(`activity:message.retryLabel`,`Retry`),className:`opacity-75 hover:opacity-100 transition-opacity text-xs text-destructive hover:text-destructive/80 inline-flex items-center gap-1 font-medium`,children:[(0,Z.jsx)(Xt,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:r(`activity:message.retryLabel`,`Retry`)})]}),e.content&&(0,Z.jsxs)(`button`,{type:`button`,onClick:ge,title:r(`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,Z.jsx)(hr,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:r(`activity:message.editLabel`)})]})]}),e.role===`assistant`&&e.content&&!e.streaming&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(e.id),title:r(P?`activity:message.unpinTitle`:`activity:message.pinTitle`),className:K(`text-xs inline-flex items-center gap-1 transition-opacity`,P?`text-warning hover:text-warning/85 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[P?(0,Z.jsx)(ur,{className:`h-3 w-3`}):(0,Z.jsx)(ar,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:r(P?`activity:message.pinnedLabel`:`activity:message.pinLabel`)})]}),(de||e.isError)&&e.content&&!e.streaming&&!D&&(0,Z.jsxs)(`button`,{type:`button`,onClick:he,title:r(`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,Z.jsx)(Xt,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:r(`activity:message.retryLabel`)})]})]})]})]})});function kw(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`}function Aw(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(+(e<10240))} KiB`:`${(e/1048576).toFixed(1)} MiB`}var jw=(0,X.memo)(function({tools:e,defaultOpen:t=!1,isContinuation:n=!1}){let{t:r}=W(),[i,a]=(0,X.useState)(t),[o,s]=(0,X.useState)(`all`);if(e.length===1)return(0,Z.jsx)(Ow,{message:oe(e[0]),isFirst:!0,isContinuation:n});let c=e.filter(e=>e.toolResult===void 0).length,l=e.filter(e=>e.isError).length,u=e.length-c-l,d=e.reduce((e,t)=>e+(t.toolDurationMs??0),0),f=e.reduce((e,t)=>e+(t.toolOutputBytes??0),0),p=e.filter(e=>o===`failed`?!!e.isError:o!==`running`||e.toolResult===void 0),m=Array.from(new Set(e.map(e=>e.toolName).filter(Boolean))),h=m.slice(0,3).join(`, `),g=m.length>3?` +${m.length-3}`:``;return(0,Z.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[n?(0,Z.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,Z.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,Z.jsx)(oa,{className:`h-4 w-4`})}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] flex-1 min-w-0`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:K(`flex flex-wrap 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:[i?(0,Z.jsx)(gn,{className:`h-3.5 w-3.5 text-muted-foreground`}):(0,Z.jsx)(ui,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(oa,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`font-mono text-xs`,children:r(`activity:toolGroup.toolCalls`,{count:e.length})}),c>0?(0,Z.jsx)(mn,{className:`h-3 w-3 animate-spin text-warning`}):l>0?(0,Z.jsx)(qr,{className:`h-3 w-3 text-destructive`}):(0,Z.jsx)(Bn,{className:`h-3 w-3 text-success`}),u>0&&(0,Z.jsx)(`span`,{className:`rounded border border-success/30 bg-success/[0.06] px-1 py-0.5 font-mono text-[10px] font-medium text-success`,children:r(`activity:toolGroup.succeeded`,{count:u,defaultValue:`{{count}} succeeded`})}),l>0&&(0,Z.jsx)(`span`,{className:`rounded border border-destructive/30 bg-destructive/[0.06] px-1 py-0.5 font-mono text-[10px] font-medium text-destructive`,children:r(`activity:toolGroup.failed`,{count:l,defaultValue:`{{count}} failed`})}),c>0&&(0,Z.jsx)(`span`,{className:`rounded border border-warning/30 bg-warning/[0.06] px-1 py-0.5 font-mono text-[10px] font-medium text-warning`,children:r(`activity:toolGroup.running`,{count:c,defaultValue:`{{count}} running`})}),d>0&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:kw(d)}),f>0&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:Aw(f)}),h&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 font-mono truncate`,children:[`· `,h,g]})]}),i&&(0,Z.jsxs)(`div`,{className:`space-y-2 pl-3 border-l-2 border-border/40 ml-2 tool-details`,children:[(l>0||c>0)&&(0,Z.jsx)(`div`,{"aria-label":r(`activity:toolGroup.filterLabel`,`Filter tool calls`),className:`flex flex-wrap items-center gap-1 border-b border-border/30 pb-2`,role:`toolbar`,children:[[`all`,e.length,`filterAll`,`All ({{count}})`],[`failed`,l,`filterFailed`,`Failed ({{count}})`],[`running`,c,`filterRunning`,`Running ({{count}})`]].filter(([,e])=>e>0).map(([e,t,n,i])=>(0,Z.jsx)(`button`,{"aria-pressed":o===e,className:K(`rounded border px-1.5 py-0.5 font-mono text-[10px] transition-colors`,o===e?`border-primary/40 bg-primary/10 text-primary`:`border-border/50 bg-background/50 text-muted-foreground hover:text-foreground`),onClick:()=>s(e),type:`button`,children:r(`activity:toolGroup.${n}`,{count:t,defaultValue:i})},e))}),p.length>0?p.map(e=>(0,Z.jsx)(Ow,{message:e,isFirst:!1},e.id)):(0,Z.jsx)(`p`,{className:`font-mono text-[11px] italic text-muted-foreground`,children:r(`activity:toolGroup.noMatchingCalls`,`No matching tool calls`)})]})]})]})}),Mw=!1;function Nw(){if(Mw)return;let e=S();e&&(e.on(`chimera.reports`,e=>{let t=e.payload;(t?.isQuery||t?.reports)&&Pw.setState({reports:t.reports??[],loading:!1})}),e.on(`chimera.report.detail`,e=>{let t=e.payload;Pw.setState({detail:t.error?null:t,error:t.error??null,detailLoading:!1})}),e.on(`chimera.report.updated`,()=>{Pw.getState().fetchReports();let e=Pw.getState().selectedReportId;e&&Pw.getState().selectReport(e)}),e.on(`chimera.report.note_added`,()=>{let e=Pw.getState().selectedReportId;e&&Pw.getState().selectReport(e)}),e.on(`chimera.finding.updated`,()=>{Pw.getState().fetchReports();let e=Pw.getState().selectedReportId;e&&Pw.getState().selectReport(e)}),e.on(`chimera.report_available`,()=>{Pw.getState().fetchReports()}),Mw=!0)}var Pw=ga((e,t)=>({reports:[],selectedReportId:null,detail:null,loading:!1,detailLoading:!1,error:null,filterSessionId:``,filterLifecycle:``,searchQuery:``,fetchReports:()=>{Nw();let n=S();if(!n.isConnected){e({loading:!1});return}e({loading:!0,error:null});let{filterSessionId:r,filterLifecycle:i}=t();n.send({type:`chimera.reports.list`,payload:{all:!0,sessionId:r||void 0,lifecycle:i||void 0}})},selectReport:t=>{if(Nw(),e({selectedReportId:t}),!t){e({detail:null,detailLoading:!1});return}let n=S();n.isConnected&&(e({detailLoading:!0,error:null}),n.send({type:`chimera.report.get`,payload:{reportId:t}}))},setFilterSessionId:n=>{e({filterSessionId:n}),t().fetchReports()},setFilterLifecycle:n=>{e({filterLifecycle:n}),t().fetchReports()},setSearchQuery:t=>{e({searchQuery:t})},transitionReport:(e,t,n)=>{let r=S();r.isConnected&&r.send({type:`chimera.report.transition`,payload:{reportId:e,to:t,reason:n}})},addReportNote:(e,t)=>{let n=S();n.isConnected&&n.send({type:`chimera.report.add_note`,payload:{reportId:e,note:t}})},transitionFinding:(e,t,n,r)=>{let i=S();i.isConnected&&i.send({type:`chimera.finding.transition`,payload:{findingId:e,to:t,outcome:n,reason:r}})}})),Fw=(0,X.memo)(function({message:e,sessionId:t}){let n=e.chimeraReport,r=tt(e=>e.lanes[t]?.isLoading??!1);if(!n)return null;let i=n.actionedAt!=null;return(0,Z.jsx)(`div`,{className:`mx-auto max-w-6xl w-full px-3 sm:px-5 lg:px-6 py-1`,"data-chimera-report-card":n.reportId,children:(0,Z.jsxs)(`div`,{className:`rounded-xl border border-warning/30 bg-warning/[0.06] px-4 py-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2 text-sm font-semibold min-w-0`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,children:`🦂`}),(0,Z.jsx)(`span`,{className:`shrink-0`,children:`Chimera report — action needed`}),(0,Z.jsxs)(`span`,{className:`text-xs font-normal text-muted-foreground truncate`,children:[`report `,n.reportId]})]}),(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground whitespace-pre-wrap break-words`,children:e.content}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{if(i||r)return;let a=`Take a look at the tasks mentioned in this Chimera report (${n.reportId}) — review the findings it flagged for this session and address them.`,o=Ae(t);o.addMessage({role:`user`,content:a}),o.patch({isLoading:!0}),S().sendMessage(a,void 0,!1,t===`__unbound__`?void 0:t),o.updateMessage(e.id,{chimeraReport:{...n,actionedAt:Date.now()}}),s.getState().markActioned(t,n.reportId,Date.now())},disabled:i||r,title:i?`Prompt sent to the leader`:r?`Waiting for the leader to finish its current run`:`Send the leader a prompt to work through this report`,className:K(`inline-flex min-h-11 items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium transition-colors`,i||r?`cursor-not-allowed border border-border bg-muted text-muted-foreground`:`bg-primary text-primary-foreground hover:bg-primary/90 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`),children:i?`Prompt sent ✓`:r?`Leader is running…`:`Take action — have the leader review it`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{Pw.getState().selectReport(n.reportId),Ha(`chimera`)},className:`inline-flex min-h-11 items-center gap-1.5 rounded-lg border border-border bg-background px-3 py-2 text-xs font-medium text-foreground hover:bg-muted transition-colors`,children:[(0,Z.jsx)(Or,{size:14}),(0,Z.jsx)(`span`,{children:`Open in Chimera Hub`})]})]})]})})}),Iw=(0,X.memo)(function({row:e,isLoading:t,compactMode:n,isFirstRow:r,groupToolCalls:i,sessionId:a}){let o=K(`mx-auto max-w-6xl w-full px-3 sm:px-5 lg:px-6`,r&&`pt-4`,n?`pb-3`:`pb-6`);return e.kind===`day`?(0,Z.jsx)(`div`,{className:o,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 py-1 text-[11px] text-muted-foreground/70 uppercase tracking-wider font-medium`,children:[(0,Z.jsx)(`div`,{className:`flex-1 h-px bg-border/50`}),(0,Z.jsx)(`span`,{children:e.label}),(0,Z.jsx)(`div`,{className:`flex-1 h-px bg-border/50`})]})}):e.kind===`user`?(0,Z.jsx)(`div`,{className:o,children:(0,Z.jsx)(Ow,{message:e.message,isFirst:!0})}):(0,Z.jsx)(`div`,{className:o,children:(0,Z.jsx)(`div`,{className:K(`chat-turn`,n?`space-y-1`:`space-y-1.5`),children:e.items.flatMap(n=>{if(n.kind===`msg`)return n.message.chimeraReport?[(0,Z.jsx)(Fw,{message:n.message,sessionId:a},n.key)]:n.message.councilDecision||OC(n.message.content)?[(0,Z.jsx)(jC,{message:n.message},n.key)]:n.message.brainDecision||wC(n.message.content)?[(0,Z.jsx)(EC,{message:n.message},n.key)]:[(0,Z.jsx)(Ow,{message:n.message,isFirst:n.isFirst,isContinuation:n.isContinuation},n.key)];if(i){let r=e.isLastTurn&&n.isLastGroup&&t&&n.hasRunningTool;return[(0,Z.jsx)(jw,{tools:n.tools,defaultOpen:r,isContinuation:n.isContinuation},n.key)]}return n.tools.map(e=>(0,Z.jsx)(Ow,{message:e,isFirst:!1,isContinuation:n.isContinuation},e.id))})})})}),Lw={running:`bg-success/10 text-success`,completed:`bg-success/10 text-success`,failed:`bg-destructive/10 text-destructive`,timeout:`bg-warning/10 text-warning`,stopped:`bg-muted text-muted-foreground`};function Rw(e){let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):``}var zw=(0,X.memo)(function({entry:e}){let{t}=W(),n=Rw(e.ts);if(e.kind===`text`)return(0,Z.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Z.jsx)(`div`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-accent text-accent-foreground ring-accent/20 ring-offset-background ring-2 ring-offset-2`,children:(0,Z.jsx)(on,{className:`h-4 w-4`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1 rounded-lg border border-border/70 bg-card px-4 py-3 shadow-sm`,children:[(0,Z.jsx)(VC,{children:e.content}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] tabular-nums text-muted-foreground/60`,children:[e.iteration>0&&(0,Z.jsxs)(`span`,{children:[`iter `,e.iteration]}),n&&(0,Z.jsx)(`span`,{className:`ml-auto font-mono`,children:n})]})]})]});if(e.kind===`thinking`)return(0,Z.jsxs)(`details`,{className:`group rounded-lg border border-primary/20 bg-primary/5 px-3 py-2`,children:[(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer select-none items-center gap-2 text-[10px] font-medium uppercase tracking-wider text-primary/80 marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,Z.jsx)(Jn,{className:`h-3.5 w-3.5 shrink-0`}),t(`activity:transcript.kindThinking`),e.iteration>0&&(0,Z.jsxs)(`span`,{className:`rounded bg-primary/10 px-1 py-0.5 text-[9px] normal-case tabular-nums`,children:[`iter `,e.iteration]}),n&&(0,Z.jsx)(`span`,{className:`ml-auto font-mono text-[9px] normal-case text-muted-foreground`,children:n})]}),(0,Z.jsx)(`pre`,{className:`mt-2 whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-foreground/75`,children:e.content})]});if(e.kind===`tool_use`||e.kind===`tool_result`){let r=e.kind===`tool_use`,i=e.toolOk!==!1,a=r?_n:i?xn:hn;return(0,Z.jsxs)(`div`,{className:K(`rounded-lg border px-3 py-2`,r?`border-warning/20 bg-warning/5`:i?`border-success/20 bg-success/5`:`border-destructive/25 bg-destructive/5`),children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(a,{className:K(`h-3.5 w-3.5 shrink-0`,r?`text-warning`:i?`text-success`:`text-destructive`)}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium uppercase tracking-wider text-muted-foreground`,children:t(r?`activity:transcript.kindToolCall`:`activity:transcript.kindToolResult`)}),e.toolName&&(0,Z.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}),n&&(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] tabular-nums text-muted-foreground`,children:n})]}),e.content&&(0,Z.jsx)(`pre`,{className:`mt-1.5 max-h-64 overflow-y-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-foreground/80`,children:e.content})]})}if(e.kind===`error`)return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-destructive/25 bg-destructive/5 px-3 py-2`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(Ct,{className:`h-3.5 w-3.5 shrink-0 text-destructive`}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium uppercase tracking-wider text-destructive`,children:t(`activity:transcript.kindError`)}),n&&(0,Z.jsx)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] tabular-nums text-muted-foreground`,children:n})]}),(0,Z.jsx)(`pre`,{className:`mt-1.5 whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-destructive/90`,children:e.content})]});let r=e.kind===`status`?nn:ya;return(0,Z.jsx)(`div`,{className:`flex justify-center`,children:(0,Z.jsxs)(`div`,{className:`flex max-w-full items-center gap-1.5 rounded-full border border-border/50 bg-muted/25 px-3 py-1 text-[10px] text-muted-foreground`,children:[(0,Z.jsx)(r,{className:`h-3 w-3 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.content}),n&&(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-[9px] tabular-nums opacity-70`,children:n})]})})});function Bw({agentId:e}){let{t}=W(),n=M(t=>t.agents.get(e)),r=M(t=>t.agentTranscripts.get(e)??De),i=q(e=>e.setSubagentChatFocus),[a,o]=(0,X.useState)(!1),s=(0,X.useRef)(null),c=(0,X.useRef)(!0),l=r[r.length-1],u=l?.content.length??0;return(0,X.useEffect)(()=>{c.current=!0},[e]),(0,X.useEffect)(()=>{let e=s.current;e&&c.current&&(e.scrollTop=e.scrollHeight)},[r.length,u,l?.id,e]),(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,"data-testid":`subagent-transcript-view`,children:[(0,Z.jsxs)(`div`,{"data-testid":`subagent-task-strip`,className:`flex h-8 max-h-8 shrink-0 items-center gap-1.5 overflow-hidden border-b border-border/60 bg-muted/20 px-3 text-xs`,children:[(0,Z.jsx)(on,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,Z.jsx)(`span`,{className:`max-w-[9rem] shrink-0 truncate font-semibold text-foreground`,children:n?.name??e}),n&&(0,Z.jsx)(`span`,{className:K(`shrink-0 rounded px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wider`,Lw[n.status]??Lw.stopped),children:n.status}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[9px] font-medium uppercase tracking-wider text-muted-foreground/80`,children:t(`activity:transcript.readOnly`)}),n?.description?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-border`,"aria-hidden":`true`,children:`·`}),(0,Z.jsx)(`span`,{className:`shrink-0 font-semibold uppercase tracking-wide text-foreground/70`,children:t(`activity:transcript.taskLabel`)}),(0,Z.jsx)(`button`,{type:`button`,"data-testid":`subagent-task-preview`,onClick:()=>o(!0),title:t(`activity:transcript.taskExpandTitle`),className:`min-w-0 flex-1 truncate text-left text-muted-foreground hover:text-foreground`,children:se(n.description)}),n.description.length>140&&(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums text-[10px] text-muted-foreground/70`,children:t(`activity:transcript.taskChars`,{count:n.description.length})}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>o(!0),title:t(`activity:transcript.taskExpandTitle`),"aria-label":t(`activity:transcript.taskExpandTitle`),"aria-expanded":a,className:`flex shrink-0 items-center gap-1 rounded border border-border/60 bg-background/70 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground transition-colors hover:border-primary/40 hover:text-foreground`,children:[(0,Z.jsx)(Sa,{className:`h-3 w-3`}),t(`activity:transcript.taskExpand`)]})]}):(0,Z.jsx)(`span`,{className:`flex-1`}),n!=null&&(0,Z.jsxs)(`span`,{className:`shrink-0 tabular-nums text-[10px] text-muted-foreground`,children:[`iter `,n.iteration,` · `,n.toolCalls,` `,t(`activity:agents.tcSuffix`),` · $`,n.costUsd.toFixed(4)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>i(null,n?.sessionId),"aria-label":t(`activity:transcript.returnToLeader`),className:`ml-0.5 inline-flex shrink-0 items-center gap-0.5 rounded bg-primary/15 px-1.5 py-0.5 text-[10px] font-medium text-primary transition-colors hover:bg-primary/25`,children:[(0,Z.jsx)(hn,{className:`h-3 w-3`}),t(`activity:transcript.returnToLeader`)]})]}),(0,Z.jsx)(`div`,{ref:s,onScroll:e=>{let t=e.currentTarget;c.current=t.scrollHeight-t.scrollTop-t.clientHeight<80},role:`log`,"aria-label":t(`activity:chatView.chatTranscript`),"aria-live":`polite`,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:r.length===0?(0,Z.jsx)(`div`,{className:`mx-auto max-w-6xl px-3 pt-6 sm:px-5 lg:px-6`,children:(0,Z.jsx)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center text-xs text-muted-foreground`,children:t(`activity:transcript.empty`)})}):(0,Z.jsx)(`div`,{className:`mx-auto max-w-6xl space-y-2.5 px-3 pb-8 pt-3 sm:px-5 lg:px-6`,children:r.map(e=>(0,Z.jsx)(zw,{entry:e},e.id))})}),n?.description&&(0,Z.jsx)(es,{open:a,onOpenChange:o,children:(0,Z.jsxs)(Zo,{className:`flex max-h-[85dvh] max-w-3xl flex-col gap-3 overflow-hidden`,children:[(0,Z.jsxs)(Yo,{children:[(0,Z.jsxs)(Qo,{className:`flex items-center gap-2 pr-6 text-base`,children:[(0,Z.jsx)(on,{className:`h-4 w-4 shrink-0 text-primary`}),(0,Z.jsxs)(`span`,{className:`truncate`,children:[n.name??e,` · `,t(`activity:transcript.taskModalTitle`)]})]}),(0,Z.jsx)($o,{className:`sr-only`,children:t(`activity:transcript.taskModalDescription`)})]}),(0,Z.jsx)(`pre`,{"data-testid":`subagent-task-full`,className:`min-h-0 flex-1 overflow-y-auto whitespace-pre-wrap break-words rounded-md border border-border/60 bg-muted/30 px-3 py-2.5 font-mono text-xs leading-relaxed text-foreground/85`,children:n.description})]})})]})}function Vw(){let{t:e}=W(),t=J(e=>e.thinkingBuffer);if(!t)return null;let n=t.split(`
176
176
  `).slice(-6).join(`
177
- `).trim();return(0,Z.jsxs)(`div`,{className:`flex gap-3 animate-message thinking-bubble`,"aria-live":`polite`,children:[(0,Z.jsxs)(`div`,{className:`thinking-orb flex-shrink-0`,"aria-hidden":!0,children:[(0,Z.jsx)(`span`,{className:`thinking-orb__ring`}),(0,Z.jsx)(`span`,{className:`thinking-orb__ring thinking-orb__ring--delay`}),(0,Z.jsx)(`span`,{className:`thinking-orb__spark thinking-orb__spark--one`}),(0,Z.jsx)(`span`,{className:`thinking-orb__spark thinking-orb__spark--two`}),(0,Z.jsx)(Jn,{className:`thinking-orb__icon h-4 w-4`})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 max-w-[85%] min-w-0`,children:[(0,Z.jsxs)(`span`,{className:`thinking-label text-xs font-medium text-primary px-1`,children:[(0,Z.jsx)(`span`,{children:e(`chat:thinking`)}),(0,Z.jsxs)(`span`,{className:`thinking-dots`,"aria-hidden":!0,children:[(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{})]})]}),(0,Z.jsxs)(`div`,{className:`thinking-panel rounded-2xl rounded-bl-md px-3 py-2 border text-foreground/80`,children:[(0,Z.jsxs)(`div`,{className:`thinking-wave`,"aria-hidden":!0,children:[(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{})]}),(0,Z.jsx)(`pre`,{className:`thinking-text whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden`,children:n||`…`})]})]})]})}function Hw(e){let{hasMessages:t,autoCollapseInput:n,sessionChanged:r,prevHadMessages:i,prevAutoCollapse:a}=e;return n&&t&&(r||!i||!a)}function Uw(e,t){return typeof e==`function`?e(t):e}function Ww(){let{t:e}=W(),t=J(e=>e.messages),r=J(e=>e.isLoading),i=q(e=>e.sidebarOpen),a=q(e=>e.toggleSidebar),o=q(e=>e.compactMode),{totalTokens:s,startTime:c,lastInputTokens:l,maxContext:u,contextLimitWarning:d,cacheStats:f,iteration:p}=H(Yr(e=>({totalTokens:e.totalTokens,startTime:e.startTime,lastInputTokens:e.lastInputTokens,maxContext:e.maxContext,contextLimitWarning:e.contextLimitWarning,cacheStats:e.cacheStats,iteration:e.iteration}))),m=H(e=>e.session),h=Pe()??m?.id,g=q(e=>h?e.sessionNicknames[h]:void 0),_=q(e=>e.setSessionNickname),v=m?.title,[y,b]=(0,X.useState)(!1),[x,C]=(0,X.useState)(``),w=n(e=>e.entries),T=q(e=>e.chatSwitcherOpen),E=q(e=>e.setChatSwitcherOpen),D=(0,X.useCallback)(e=>{E(Uw(e,q.getState().chatSwitcherOpen))},[E]),O=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(!T)return;let e=e=>{O.current?.contains(e.target)||D(!1)},t=e=>{e.key===`Escape`&&D(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[T]);let{configProvider:k,configModel:A}=V(Yr(e=>({configProvider:e.provider,configModel:e.model}))),j=m?.provider||k,M=m?.model||A,N=(0,X.useRef)(null),P=(0,X.useMemo)(()=>lp(t),[t]),F=(0,X.useRef)(0);F.current=P.length+1;let I=(0,X.useMemo)(()=>{let e=new Map;return P.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},[P]),L=q(e=>e.scrollTarget),ee=G(e=>e.autonomy),R=G(e=>e.groupToolCalls),z=G(e=>e.autoCollapseInput),te=(0,X.useCallback)(e=>{G.getState().set({autonomy:e});try{let t=S();if(typeof t.switchAutonomy==`function`){t.switchAutonomy(e);return}t.send?.({type:`autonomy.switch`,payload:t.withSession?.({mode:e})??{mode:e}})}catch{}},[]),[ne,re]=(0,X.useState)(!1),ie=q(e=>e.chatCheckpointOpen),ae=q(e=>e.setChatCheckpointOpen),oe=(0,X.useCallback)(e=>{ae(Uw(e,q.getState().chatCheckpointOpen))},[ae]),se=q(e=>e.chatMemoryPanelOpen),ce=q(e=>e.setChatMemoryPanelOpen),B=(0,X.useCallback)(e=>{ce(Uw(e,q.getState().chatMemoryPanelOpen))},[ce]),ue=q(e=>e.chatInputCollapsed),de=q(e=>e.setChatInputCollapsed),fe=(0,X.useCallback)(e=>{de(Uw(e,q.getState().chatInputCollapsed))},[de]),pe=(0,X.useRef)(r),me=(0,X.useRef)(t.length>0),he=(0,X.useRef)(h),ge=(0,X.useRef)(z),_e=q(e=>e.chatContextBreakdownOpen),ve=q(e=>e.setChatContextBreakdownOpen),ye=q(e=>e.chatToolStatsOpen),be=q(e=>e.setChatToolStatsOpen),xe=(0,X.useCallback)(e=>{be(Uw(e,q.getState().chatToolStatsOpen))},[be]),Se=q(e=>e.chatContextEditorOpen),Ce=q(e=>e.setChatContextEditorOpen),we=Ml(e=>Object.values(e.contextMemories).filter(e=>e.state!==`exited`).length);(0,X.useEffect)(()=>{let e=()=>B(!0);return window.addEventListener(`open:memory-panel`,e),()=>window.removeEventListener(`open:memory-panel`,e)},[]),(0,X.useEffect)(()=>{let e=()=>ve(!0);return document.addEventListener(`open:context-breakdown`,e),()=>document.removeEventListener(`open:context-breakdown`,e)},[]),(0,X.useEffect)(()=>{let e=()=>Ce(!0);return document.addEventListener(`open:context-editor`,e),()=>document.removeEventListener(`open:context-editor`,e)},[]),(0,X.useEffect)(()=>{let e=()=>fe(!1);return document.addEventListener(`chat:session-end`,e),document.addEventListener(`chat:next-step-countdown`,e),()=>{document.removeEventListener(`chat:session-end`,e),document.removeEventListener(`chat:next-step-countdown`,e)}},[]),(0,X.useEffect)(()=>{pe.current&&!r&&fe(!1),pe.current=r},[r]),(0,X.useEffect)(()=>{let e=t.length>0,n=h!=null&&h!==he.current;!r&&Hw({hasMessages:e,autoCollapseInput:z,sessionChanged:n,prevHadMessages:me.current,prevAutoCollapse:ge.current})&&fe(!0),he.current=h,me.current=e,ge.current=z},[t.length,z,h,r]);let Te=(0,X.useCallback)(()=>{let e=!G.getState().autoCollapseInput;G.getState().set({autoCollapseInput:e}),e||fe(!1)},[]),Ee=u>0&&l>0?Math.min(100,Math.round(l/u*100)):0,[De,Oe]=(0,X.useState)(!0),[ke,Ae]=(0,X.useState)(0),[je,Me]=(0,X.useState)(!1),Ne=(0,X.useRef)(t.length),Fe=(0,X.useCallback)(()=>{let e=N.current;if(!e)return;let t=e.scrollSize-e.scrollOffset-e.viewportSize<120;Oe(t),t&&(Ae(0),Ne.current=J.getState().messages.length),Me(e.scrollOffset>e.viewportSize&&e.scrollSize>e.viewportSize*2.5)},[]),Ie=(0,X.useCallback)(e=>{let t=S();le.getState().openTab(e,{resumeSession:e=>t.resumeSession?.(e)}),D(!1)},[]);(0,X.useEffect)(()=>{let e=N.current;if(e){if(De)e.scrollToIndex(F.current-1,{align:`end`}),Ne.current=t.length;else{let e=t.length-Ne.current;e>0&&Ae(e)}}},[t,De]),(0,X.useEffect)(()=>{Oe(!0),Ae(0),Ne.current=J.getState().messages.length,re(!1),b(!1),requestAnimationFrame(()=>{N.current?.scrollToIndex(F.current-1,{align:`end`})})},[h]),(0,X.useEffect)(()=>{if(!L)return;let e=I.get(L.id);e!==void 0&&N.current?.scrollToIndex(e,{align:`center`,smooth:!0})},[L,I]);let Le=(0,X.useCallback)(()=>{N.current?.scrollToIndex(F.current-1,{align:`end`,smooth:!0}),Oe(!0),Ae(0),Ne.current=J.getState().messages.length},[]),Re=(0,X.useCallback)(()=>{N.current?.scrollToIndex(0,{align:`start`,smooth:!0})},[]),[ze,Be]=(0,X.useState)(null),[Ve,He]=(0,X.useState)(()=>Date.now()),Ue=(0,X.useRef)(null),We=t[t.length-1],Ge=We?.role===`assistant`&&We.streaming&&We.content?We:null;(0,X.useEffect)(()=>{if(Ge){let e=Ue.current;(!e||e.id!==Ge.id)&&(Ue.current={id:Ge.id,at:Date.now(),len:Ge.content.length})}else Ue.current&&=null},[Ge]);let Ke=(0,X.useMemo)(()=>{let n=t[t.length-1],r=t.filter(e=>e.role===`tool`&&e.toolResult===void 0),i=e(`activity:chatView.thinking`);if(r.length>0){let t=Array.from(new Set(r.map(e=>e.toolName).filter(Boolean))),n=t.slice(0,2).join(`, `),a=t.length>2?` +${t.length-2}`:``;i=r.length===1?e(`activity:chatView.runningTool`,{tool:n||e(`activity:chatView.toolWord`)}):e(`activity:chatView.runningTools`,{count:r.length,preview:`${n}${a}`})}else n?.role===`assistant`&&n.content?i=e(`activity:chatView.writingReply`):n?.role===`tool`&&n.toolResult!==void 0&&(i=e(`activity:chatView.thinkingNextStep`));let a=ze?Math.max(0,Math.floor((Ve-ze)/1e3)):0,o=a<60?`${a}s`:`${Math.floor(a/60)}m ${a%60}s`,s=``;if(Ge){let e=Ue.current;if(e&&e.id===Ge.id){let t=Math.max(1,Ve-e.at),n=Math.max(0,Ge.content.length-e.len);if(t>500&&n>0){let e=n*1e3/t;s=e>=1e3?`${(e/1e3).toFixed(1)}k ch/s`:`${Math.round(e)} ch/s`}}}return{label:i,elapsed:o,speedLabel:s}},[t,Ve,ze,e,Ge]);(0,X.useEffect)(()=>{r&&ze===null&&Be(Date.now()),!r&&ze!==null&&Be(null)},[r,ze]),(0,X.useEffect)(()=>{if(!r)return;let e=setInterval(()=>He(Date.now()),500);return()=>clearInterval(e)},[r]);let qe=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`},Je=(()=>{if(!r)return`idle`;let e=t[t.length-1];return e?.role===`assistant`&&e.content&&e.streaming?`streaming`:`thinking`})();return{messages:t,isLoading:r,sidebarOpen:i,toggleSidebar:a,compactMode:o,totalTokens:s,startTime:c,lastInputTokens:l,maxContext:u,contextLimitWarning:d,cacheStats:f,iteration:p,sessionId:h,nickname:g,sessionTitle:v,renamingTitle:y,setRenamingTitle:b,titleDraft:x,setTitleDraft:C,setSessionNickname:_,historyEntries:w,switcherOpen:T,setSwitcherOpen:D,switcherRef:O,handleHistorySelect:Ie,provider:j,model:M,vlistRef:N,rows:P,autonomy:ee,groupToolCallsPref:R,autoCollapseInput:z,handleAutonomyChange:te,processOpen:ne,setProcessOpen:re,checkpointOpen:ie,setCheckpointOpen:oe,memoryPanelOpen:se,setMemoryPanelOpen:B,inputCollapsed:ue,setInputCollapsed:fe,breakdownOpen:_e,setBreakdownOpen:ve,toolStatsOpen:ye,setToolStatsOpen:xe,editorOpen:Se,setEditorOpen:Ce,activeMemoryCount:we,handleToggleAutoCollapse:Te,ctxPct:Ee,pinnedToBottom:De,unreadCount:ke,scrolledDeep:je,handleScroll:Fe,scrollToBottom:Le,scrollToTop:Re,runningStatus:Ke,formatDuration:qe,agentState:Je,stateTone:Je===`idle`?`bg-muted text-muted-foreground`:Je===`streaming`?`bg-primary/10 text-primary`:`bg-warning/10 text-warning`,hasStatusContent:u>0&&l>0||s.input>0||!!c}}var Gw=(0,X.lazy)(()=>La(()=>import(`./ProcessMonitor-Btj6_6aw.js`).then(e=>({default:e.ProcessMonitor})),__vite__mapDeps([62,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,27])));function Kw(){let{t:e}=W(),t=Ww(),n=Pe(),r=q(e=>e.subagentChatFocusId),i=q(e=>e.setSubagentChatFocus),a=q(e=>e.setSearchOpen),o=v(n??void 0),s=M(e=>r==null?void 0:e.agents.get(r)),l=!s||R(s.sessionId,n),d=!!s&&l,f=r!=null&&d&&r!==o;(0,X.useEffect)(()=>{(pC(r,d)||r!=null&&r===o)&&i(null,n)},[r,d,o,i,n]),(0,X.useEffect)(()=>{f&&a(!1)},[f,a]);let p=V(e=>e.wsStatus),m=t.sessionId,h=A(e=>t.sessionId?e.startedAt[t.sessionId]!==void 0:!1),g=A(e=>t.sessionId?e.progress[t.sessionId]:void 0),_=u(g),y=c(g?.stage);return(0,X.useEffect)(()=>{m&&p.state===`open`&&S().getChimeraReports(m)},[m,p]),(0,Z.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0 bg-[hsl(var(--surface-2)/0.45)]`,children:[(0,Z.jsx)(SC,{sidebarOpen:t.sidebarOpen,toggleSidebar:t.toggleSidebar,agentState:t.agentState,stateTone:t.stateTone,sessionId:t.sessionId,renamingTitle:t.renamingTitle,setRenamingTitle:t.setRenamingTitle,titleDraft:t.titleDraft,setTitleDraft:t.setTitleDraft,nickname:t.nickname,sessionTitle:t.sessionTitle,setSessionNickname:t.setSessionNickname,historyEntries:t.historyEntries,switcherRef:t.switcherRef,switcherOpen:t.switcherOpen,setSwitcherOpen:t.setSwitcherOpen,handleHistorySelect:t.handleHistorySelect,iteration:t.iteration,autonomy:t.autonomy,handleAutonomyChange:t.handleAutonomyChange,memoryPanelOpen:t.memoryPanelOpen,setMemoryPanelOpen:t.setMemoryPanelOpen,activeMemoryCount:t.activeMemoryCount,processOpen:t.processOpen,setProcessOpen:t.setProcessOpen,checkpointOpen:t.checkpointOpen,setCheckpointOpen:t.setCheckpointOpen,toolStatsOpen:t.toolStatsOpen,setToolStatsOpen:t.setToolStatsOpen,hasStatusContent:t.hasStatusContent,lastInputTokens:t.lastInputTokens,ctxPct:t.ctxPct,maxContext:t.maxContext,cacheStats:t.cacheStats,setBreakdownOpen:t.setBreakdownOpen,contextLimitWarning:t.contextLimitWarning,setEditorOpen:t.setEditorOpen,totalTokens:t.totalTokens,startTime:t.startTime,formatDuration:t.formatDuration}),(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(`div`,{className:K(`ws-view-pane relative mx-2 mt-2 flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-xl border border-border/70 bg-card/55 shadow-sm sm:mx-3 lg:mx-4 lg:mt-3`,!f&&`ws-view-parked`),...f?{}:{inert:!0,"aria-hidden":!0},children:(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:f&&r!=null&&(0,Z.jsx)(Bw,{agentId:r},r)})}),(0,Z.jsxs)(`div`,{className:K(`ws-view-pane relative mx-2 mt-2 min-h-0 min-w-0 flex-1 overflow-hidden rounded-xl border border-border/70 bg-card/55 shadow-sm sm:mx-3 lg:mx-4 lg:mt-3`,f&&`ws-view-parked`),...f?{inert:!0,"aria-hidden":!0}:{},children:[(0,Z.jsx)(RS,{}),!t.pinnedToBottom&&(0,Z.jsxs)(`button`,{type:`button`,onClick:t.scrollToBottom,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-md shadow-lg`,`bg-primary text-primary-foreground text-xs font-medium`,`hover:bg-primary/90 transition-colors animate-message`),children:[(0,Z.jsx)(Nr,{className:`h-3.5 w-3.5`}),t.unreadCount>0?`${t.unreadCount} new message${t.unreadCount===1?``:`s`}`:`Jump to latest`]}),t.scrolledDeep&&(0,Z.jsxs)(`button`,{type:`button`,onClick:t.scrollToTop,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-md 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,Z.jsx)(sa,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e(`activity:chatView.top`)})]}),t.rows.length===0&&!t.isLoading?(0,Z.jsx)(`div`,{className:`h-full overflow-y-auto overscroll-contain`,children:(0,Z.jsx)(`div`,{className:`mx-auto max-w-6xl w-full px-3 sm:px-5 lg:px-6 pt-4 pb-8`,children:h?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-16 text-center`,role:`status`,"aria-live":`polite`,children:[(0,Z.jsxs)(`div`,{className:`relative h-12 w-12`,"aria-hidden":`true`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-muted-foreground/20`}),(0,Z.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin`}),(0,Z.jsx)(`div`,{className:`absolute inset-1.5 rounded-full bg-background/80`}),(0,Z.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-[11px] font-semibold tabular-nums text-foreground`,children:_===null?`...`:`${_}%`})]}),(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:e(`activity:chatView.restoringTranscript`)}),(0,Z.jsxs)(`div`,{className:`w-full max-w-sm`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-3 text-[11px] text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:y}),g&&g.totalBytes>0?(0,Z.jsxs)(`span`,{className:`shrink-0 tabular-nums`,children:[ee(g.loadedBytes),` /`,` `,ee(g.totalBytes)]}):(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:`reading...`})]}),(0,Z.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width] duration-200 ease-out`,style:{width:`${_??12}%`}})})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground max-w-sm`,children:e(`activity:chatView.restoringTranscriptHint`)})]}):(0,Z.jsx)(cC,{})})}):(0,Z.jsxs)(En,{ref:t.vlistRef,className:`h-full`,onScroll:t.handleScroll,role:`log`,"aria-label":e(`activity:chatView.chatTranscript`),"aria-live":`polite`,children:[t.rows.map((e,n)=>(0,Z.jsx)(Iw,{row:e,isLoading:t.isLoading,compactMode:t.compactMode,isFirstRow:n===0,groupToolCalls:t.groupToolCallsPref,sessionId:t.sessionId??`__unbound__`},e.key)),(0,Z.jsxs)(`div`,{id:`chat-activity`,className:K(`mx-auto max-w-6xl w-full px-3 sm:px-5 lg:px-6`,t.compactMode?`pb-3`:`pb-8`),children:[(0,Z.jsx)(Vw,{}),t.isLoading&&(0,Z.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,Z.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,Z.jsx)(on,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,Z.jsx)(`div`,{className:`rounded-lg px-4 py-3 bg-card border border-border/70 text-foreground shadow-sm`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,Z.jsxs)(`span`,{className:`flex gap-1`,children:[(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]`}),(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]`}),(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce`})]}),(0,Z.jsx)(`span`,{className:`text-foreground/90`,children:t.runningStatus.label}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:t.runningStatus.elapsed}),t.iteration&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[`· iter `,t.iteration.index,t.iteration.max>0?`/${t.iteration.max}`:``]}),t.runningStatus.speedLabel&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 tabular-nums`,children:[`· `,t.runningStatus.speedLabel]})]})})})]})]},`__live`)]},t.sessionId??`__unbound__`)]})]}),(0,Z.jsx)(`div`,{className:K(`ws-view-pane shrink-0 bg-[hsl(var(--surface-2)/0.45)] px-2 pb-2 pt-2 sm:px-3 lg:px-4 lg:pb-3`,f&&`ws-view-parked`),...f?{inert:!0,"aria-hidden":!0}:{},children:t.inputCollapsed&&t.messages.length>0?(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 rounded-lg border border-border/60 bg-card/40 px-3 py-1.5 hover:bg-card/70 hover:border-border/80 transition-colors`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>t.setInputCollapsed(!1),className:`flex flex-1 items-center gap-2 text-xs text-muted-foreground/60 hover:text-foreground/80 transition-colors`,children:[(0,Z.jsx)(ut,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{children:e(`chat:input.expandInput`,`Expand input`)}),t.rows.length>0&&(0,Z.jsxs)(`span`,{className:`ml-auto tabular-nums text-[10px] text-muted-foreground/40`,children:[t.rows.length,` msgs ·`,` `,op(t.totalTokens.input+t.totalTokens.output)]})]}),t.isLoading&&(0,Z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S().sendAbort(t.sessionId??void 0),J.getState().setLoading(!1)},className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-medium bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,title:e(`chat:input.abortTitle`,`Stop/Abort`),"data-testid":`collapsed-stop`,children:[(0,Z.jsx)(Mr,{className:`h-3 w-3 fill-current`}),(0,Z.jsx)(`span`,{children:e(`common:action.stop`,`Stop`)})]}),(0,Z.jsx)(mC,{label:e(`activity:chatView.autoCollapse`),value:t.autoCollapseInput,onChange:t.handleToggleAutoCollapse})]}):(0,Z.jsxs)(Z.Fragment,{children:[t.messages.length>0&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>t.setInputCollapsed(!0),className:`mb-1 flex w-full items-center gap-1.5 rounded px-2 py-0.5 text-[10px] text-muted-foreground/50 hover:text-muted-foreground/80 transition-colors`,children:[(0,Z.jsx)(gn,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e(`chat:input.collapseInput`,`Collapse`)})]}),(0,Z.jsx)(FS,{}),(0,Z.jsx)(hC,{hasStatusContent:t.hasStatusContent,totalTokens:t.totalTokens,rowsCount:t.rows.length,iteration:t.iteration,startTime:t.startTime,formatDuration:t.formatDuration,onToggleAutoCollapse:t.handleToggleAutoCollapse}),(0,Z.jsx)(`div`,{className:`ws-chat-input-wrap p-0`,children:(0,Z.jsx)(`div`,{className:`max-w-6xl mx-auto`,children:(0,Z.jsx)(fS,{onOpenBreakdown:()=>t.setBreakdownOpen(!0)})})})]})}),(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(Gw,{open:t.processOpen,onClose:()=>t.setProcessOpen(!1)})}),(0,Z.jsx)(mS,{open:t.checkpointOpen,onClose:()=>t.setCheckpointOpen(!1)}),(0,Z.jsx)(hp,{open:t.breakdownOpen,onClose:()=>t.setBreakdownOpen(!1)}),(0,Z.jsx)(nC,{open:t.toolStatsOpen,onClose:()=>t.setToolStatsOpen(!1)}),(0,Z.jsx)(AS,{open:t.editorOpen,onClose:()=>t.setEditorOpen(!1)}),(0,Z.jsx)(fx,{open:t.memoryPanelOpen,onClose:()=>t.setMemoryPanelOpen(!1)})]})}function qw(){let e=ro(e=>e.info),{client:t}=hf(),n=(0,X.useRef)(null),r=(0,X.useCallback)(()=>{t?.getGitInfo?.()},[t]);return(0,X.useEffect)(()=>(r(),n.current=setInterval(r,3e4),()=>{n.current&&clearInterval(n.current)}),[r]),e}var Jw=new Map,Yw=new Set;k(e=>{Jw.delete(e),Yw.add(e)});function Xw({sessionId:e,className:t}){let{t:n}=W(),[r,i]=(0,X.useState)([]),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(0),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(``),[x,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(``),E=(0,X.useRef)(e),D=V(e=>e.wsUrl),O=S(D),k=J(e=>e.messages).filter(e=>e.role===`tool`&&e.toolResult===void 0&&!!e.toolUseId);(0,X.useLayoutEffect)(()=>{let t=E.current;Yw.has(t)||Jw.set(t,{participants:r,joined:a,joinedRole:s,error:l,openAnnotationCount:d,paused:p,injectOpen:h,injectToolUseId:_,injectContent:y,injectIsError:x,injectReason:w});let n=Jw.get(e);Yw.delete(e),i(n?.participants??[]),o(n?.joined??!1),c(n?.joinedRole??null),u(n?.error??null),f(n?.openAnnotationCount??0),m(n?.paused??!1),g(n?.injectOpen??!1),v(n?.injectToolUseId??``),b(n?.injectContent??``),C(n?.injectIsError??!1),T(n?.injectReason??``),E.current=e},[e]),(0,X.useEffect)(()=>{let t=[];return t.push(O.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&i(n.participants??[])})),t.push(O.on(`collab.participant.joined`,t=>{let n=t.payload;n.sessionId===e&&i(e=>e.some(e=>e.participantId===n.participantId)?e:[...e,{participantId:n.participantId,role:n.role,joinedAt:n.joinedAt}])})),t.push(O.on(`collab.participant.left`,t=>{let n=t.payload;if(n.sessionId!==e)return;let r=n.participantId;i(e=>e.filter(e=>e.participantId!==r))})),t.push(O.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(u(t.message),o(!1))})),t.push(O.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||f(e=>e+1))})),t.push(O.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&f(e=>Math.max(0,e-1))})),t.push(O.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&m(!0)})),t.push(O.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&m(!1)})),()=>{for(let e of t)e()}},[O,e]);let A=(t=`observer`)=>{u(null),O.send({type:`collab.join`,payload:{sessionId:e,role:t}}),o(!0),c(t)},j=()=>{O.send({type:`collab.request_pause`,payload:{sessionId:e}})},M=()=>{O.send({type:`collab.resume`,payload:{sessionId:e}})},N=()=>{O.send({type:`collab.leave`,payload:{sessionId:e}}),o(!1),i([])},P=t=>{O.send({type:`collab.grant_control`,payload:{sessionId:e,toParticipant:t}})},F=()=>{_&&(O.send({type:`collab.inject_tool`,payload:{sessionId:e,toolUseId:_,content:y,isError:x,reason:w.trim()||U.t(`activity:collab.controllerInjection`)}}),g(!1),v(``),b(``),C(!1),T(``))},I=a&&s===`controller`;return r.length===0&&!l?(0,Z.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,Z.jsx)(_t,{className:`w-4 h-4 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`activity:collab.noObservers`)}),(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(`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,Z.jsx)(pt,{className:`w-3 h-3`}),n(`activity:collab.observerRole`)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(`annotator`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-warning/40 bg-warning/10 text-warning hover:bg-warning/20 transition-colors`,title:n(`activity:collab.annotatorTitle`),children:[(0,Z.jsx)(kr,{className:`w-3 h-3`}),n(`activity:collab.annotatorRole`)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(`controller`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20 transition-colors`,title:n(`activity:collab.controllerTitle`),children:[(0,Z.jsx)(ct,{className:`w-3 h-3`}),n(`activity:collab.controllerRole`)]})]})]}):l?(0,Z.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,Z.jsx)(`span`,{className:`text-xs text-destructive`,children:n(`activity:collab.errorPrefix`,{error:l})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{u(null),o(!1)},className:`ml-auto text-xs underline text-destructive`,children:n(`activity:collab.dismiss`)})]}):(0,Z.jsxs)(`div`,{className:K(`relative flex items-center gap-2 px-3 py-2 rounded-md border border-success/40 bg-success/5`,t),children:[(0,Z.jsxs)(`span`,{className:`relative flex h-2 w-2`,role:`img`,"aria-label":n(`common:status.live`),children:[(0,Z.jsx)(`span`,{className:`absolute inline-flex h-full w-full rounded-full bg-success opacity-75 animate-ping`}),(0,Z.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-success`})]}),(0,Z.jsx)(_t,{className:`w-4 h-4 text-success`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium text-success`,children:n(`activity:collab.observers`,{count:r.length})}),d>0&&(0,Z.jsxs)(`span`,{title:n(`activity:collab.annotationsTitle`,{count:d}),className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-warning/15 text-warning border border-warning/30`,children:[(0,Z.jsx)(kr,{className:`w-3 h-3`}),n(`activity:collab.notes`,{count:d})]}),p&&(0,Z.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-destructive/15 text-destructive border border-destructive/40`,children:[(0,Z.jsx)(ct,{className:`w-3 h-3`}),n(`activity:collab.paused`)]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 ml-2`,children:[r.slice(0,3).map(e=>(0,Z.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-success/10 text-success`,children:[(0,Z.jsx)(ja,{className:`w-3 h-3`}),e.role,I&&e.role!==`controller`&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>P(e.participantId),title:n(`activity:collab.grantTitle`),className:`ml-0.5 inline-flex items-center rounded hover:bg-success/20 transition-colors`,children:(0,Z.jsx)(qn,{className:`w-3 h-3`})})]},e.participantId)),r.length>3&&(0,Z.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,r.length-3]})]}),I&&(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-info/40 bg-info/10 text-info hover:bg-info/20 transition-colors`,title:n(`activity:collab.injectTitle`),children:[(0,Z.jsx)(oi,{className:`w-3 h-3`}),n(`activity:collab.inject`)]}),p?(0,Z.jsxs)(`button`,{type:`button`,onClick:M,className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20 transition-colors`,title:n(`activity:collab.resumeTitle`),children:[(0,Z.jsx)(tn,{className:`w-3 h-3`}),n(`activity:collab.resume`)]}):(0,Z.jsxs)(`button`,{type:`button`,onClick:j,className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-warning/40 bg-warning/10 text-warning hover:bg-warning/20 transition-colors`,title:n(`activity:collab.pauseTitle`),children:[(0,Z.jsx)(ct,{className:`w-3 h-3`}),n(`activity:collab.pauseAgent`)]})]}),a&&s!==`controller`&&(0,Z.jsxs)(`button`,{type:`button`,onClick:N,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,Z.jsx)(_i,{className:`w-3 h-3`}),n(`activity:collab.leave`)]}),I&&h&&(0,Z.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-info/40 bg-card shadow-lg text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(oi,{className:`w-3.5 h-3.5 text-info`}),(0,Z.jsx)(`span`,{className:`font-medium`,children:n(`activity:collab.injectToolResult`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>g(!1),className:`ml-auto text-muted-foreground hover:text-foreground`,children:n(`activity:collab.close`)})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:collab.targetTool`)}),(0,Z.jsx)(`input`,{list:`collab-inject-tools`,value:_,onChange:e=>v(e.target.value),placeholder:n(`activity:collab.targetPlaceholder`),className:`px-2 py-1 rounded border border-border bg-background font-mono`}),(0,Z.jsx)(`datalist`,{id:`collab-inject-tools`,children:k.map(e=>{let t=e.toolInput===void 0?``:` — ${JSON.stringify(e.toolInput).slice(0,40)}`;return(0,Z.jsxs)(`option`,{value:e.toolUseId,children:[e.toolName??n(`activity:collab.toolFallback`),t]},e.toolUseId)})}),k.length===0&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`activity:collab.noPendingTools`)})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:collab.resultContent`)}),(0,Z.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:3,placeholder:n(`activity:collab.resultPlaceholder`),className:`px-2 py-1 rounded border border-border bg-background font-mono`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>C(e.target.checked)}),(0,Z.jsx)(`span`,{children:n(`activity:collab.markError`)})]}),(0,Z.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,Z.jsxs)(`button`,{type:`button`,onClick:F,disabled:!_,className:`self-end inline-flex items-center gap-1 text-xs px-3 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,Z.jsx)(oi,{className:`w-3 h-3`}),n(`activity:collab.queueInjection`)]})]})]})}var Zw={running:{led:`bg-success led-pulse`,badge:`border-success/30 bg-success/10 text-success`,labelKey:`activity:fleet.statusRunning`},completed:{led:`bg-success`,badge:`border-border bg-muted/40 text-muted-foreground`,labelKey:`activity:fleet.statusDone`},failed:{led:`bg-destructive`,badge:`border-destructive/30 bg-destructive/10 text-destructive`,labelKey:`activity:fleet.statusFailed`},timeout:{led:`bg-warning`,badge:`border-warning/30 bg-warning/10 text-warning`,labelKey:`activity:fleet.statusTimeout`},stopped:{led:`bg-muted-foreground`,badge:`border-border bg-muted text-muted-foreground`,labelKey:`activity:fleet.statusStopped`}};function Qw({className:e}){let{t}=W(),n=M(e=>e.agents),r=Pe(),[i,a]=(0,X.useState)(null),o=(0,X.useMemo)(()=>{let e=Array.from(n.values()).filter(e=>R(e.sessionId,r));return e.sort(w),e},[n,r]),s=(0,X.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(t),a(e),setTimeout(()=>a(null),2e3)}catch{}},[]),c=(0,X.useCallback)(e=>{q.getState().setSubagentChatFocus(e,r??void 0),q.getState().setDockSection(null)},[r]);if(o.length===0)return(0,Z.jsx)(`div`,{className:K(`p-4 text-center text-xs text-muted-foreground`,e),children:t(`activity:agents.noAgentsRunning`)});let l=g(o),u=o.reduce((e,t)=>e+(t.costUsd??0),0);return(0,Z.jsxs)(`div`,{className:K(`flex flex-col gap-3`,e),children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border/70 bg-card/60 px-3 py-2 text-xs backdrop-blur-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(on,{className:`h-4 w-4 text-primary shrink-0`}),(0,Z.jsx)(`span`,{className:`font-semibold`,children:t(`activity:dock.fleet`)}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,o.length,`)`]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[l.running>0&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-medium text-success`,children:[(0,Z.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-success animate-pulse`}),l.running,` `,t(`activity:fleet.statusRunning`)]}),l.completed>0&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[l.completed,` `,t(`activity:fleet.statusDone`)]}),l.failed>0&&(0,Z.jsxs)(`span`,{className:`font-medium text-destructive`,children:[l.failed,` `,t(`activity:fleet.statusFailed`)]}),u>0&&(0,Z.jsx)(`span`,{className:`rounded bg-muted/60 px-1.5 py-0.5 font-mono text-[10px] text-foreground/80`,children:Up(u)})]})]}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:o.map(e=>{let n=Zw[e.status]??Zw.stopped,r=Date.now()-e.startedAt,a=e.description;return(0,Z.jsxs)(`div`,{className:`group flex flex-col gap-2 rounded-lg border border-border/70 bg-card/80 p-3 shadow-xs transition-colors hover:border-primary/40 hover:bg-card`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Z.jsx)(`span`,{className:K(`h-2 w-2 rounded-full shrink-0`,n.led)}),(0,Z.jsx)(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),(e.provider||e.model)&&(0,Z.jsxs)(`span`,{className:`hidden sm:inline-flex items-center gap-1 rounded bg-muted/60 px-1.5 py-0.5 text-[10px] font-mono text-muted-foreground truncate`,children:[(0,Z.jsx)(On,{className:`h-3 w-3 shrink-0`}),e.model??e.provider]}),(0,Z.jsx)(`span`,{className:K(`rounded-md border px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wider shrink-0`,n.badge),children:t(n.labelKey)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] font-mono text-muted-foreground tabular-nums`,children:[(0,Z.jsx)(la,{className:`h-3 w-3`}),Gp(r)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>c(e.id),className:`inline-flex items-center gap-1 rounded-md border border-primary/30 bg-primary/10 px-2 py-1 text-xs font-medium text-primary hover:bg-primary/20 transition-colors cursor-pointer`,title:`Open subagent chat tab`,children:[(0,Z.jsx)(ka,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:`Chat Tab`})]})]})]}),a?(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground line-clamp-2 leading-relaxed`,children:a}):null,(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-t border-border/40 pt-2 text-[11px]`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:e.status===`running`&&(e.currentTool||e.lastTool)?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-primary font-mono text-[10px] bg-primary/10 px-1.5 py-0.5 rounded truncate`,children:[(0,Z.jsx)(_n,{className:`h-3 w-3 shrink-0 animate-pulse`}),e.currentTool?e.currentTool:`last: ${e.lastTool}`]}):e.error?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive text-[10px] truncate`,children:[(0,Z.jsx)(qr,{className:`h-3 w-3 shrink-0`}),e.error.message]}):(0,Z.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[`iter `,e.iteration,` · `,e.toolCalls,` tools`]})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 ml-auto`,children:[e.costUsd>0&&(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:Up(e.costUsd)}),e.finalText&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>s(e.id,e.finalText),className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted px-1.5 py-0.5 rounded transition-colors cursor-pointer`,title:t(`activity:fleet.copyOutput`),children:[i===e.id?(0,Z.jsx)(xn,{className:`h-3 w-3 text-success`}):(0,Z.jsx)(zr,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:i===e.id?t(`common:action.copied`):t(`common:action.copy`)})]})]})]})]},e.id)})})]})}var $w={up:(0,Z.jsx)(sr,{className:`h-3.5 w-3.5 text-success`}),down:(0,Z.jsx)(_r,{className:`h-3.5 w-3.5 text-destructive`}),stable:(0,Z.jsx)(ni,{className:`h-3.5 w-3.5 text-warning`})},eT={active:{color:`text-success`,bg:`bg-success/10`,labelKey:`statusActive`},paused:{color:`text-warning`,bg:`bg-warning/10`,labelKey:`statusPaused`},completed:{color:`text-info`,bg:`bg-info/10`,labelKey:`statusDone`},failed:{color:`text-destructive`,bg:`bg-destructive/10`,labelKey:`statusFailed`},abandoned:{color:`text-muted-foreground`,bg:`bg-muted`,labelKey:`statusAbandoned`}};function tT({goal:e,className:t}){let{t:n}=W(),[r,i]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let e=S();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,X.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&i(!0)},[e]);let a=e?.deliverables??[],o=[...e?.journal??[]].reverse();if(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let s=eT[e.goalState],c=e.deliverables?.filter(e=>e.status===`done`).length??0,l=e.deliverables?.length??0,u=e.progressTrend?$w[e.progressTrend]:null;return(0,Z.jsxs)(`div`,{className:K(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,t),children:[(0,Z.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,Z.jsx)(ki,{className:`h-4 w-4 text-primary`}),(0,Z.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:n(`activity:goal.heading`)}),(0,Z.jsx)(`span`,{className:K(`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium shrink-0`,s.bg,s.color),children:n(`activity:goal.${s.labelKey}`)}),r?(0,Z.jsx)(ui,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Z.jsx)(gn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!r&&(0,Z.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t pt-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-xs text-foreground leading-relaxed whitespace-pre-wrap break-words`,children:e.goal}),e.refinedGoal&&e.refinedGoal!==e.goal&&(0,Z.jsxs)(`div`,{className:`mt-1.5 p-2 rounded bg-accent/40 border border-border/50`,children:[(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground mb-0.5 uppercase tracking-wider font-medium`,children:n(`activity:goal.refined`)}),(0,Z.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap break-words`,children:e.refinedGoal})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground uppercase tracking-wider font-medium`,children:n(`activity:goal.progress`)}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums`,children:[u,(0,Z.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.progress,`%`]})]})]}),(0,Z.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,Z.jsx)(`div`,{className:K(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-success`:e.progress>=50?`bg-warning`:`bg-primary`),style:{width:`${e.progress>0?Math.max(2,e.progress):0}%`}})}),e.progressNote&&(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:e.progressNote})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Z.jsx)(la,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{className:`tabular-nums font-medium`,children:e.iterations}),(0,Z.jsx)(`span`,{children:n(`activity:goal.iterations`)}),e.lastStatus&&(0,Z.jsx)(`span`,{className:`text-border`,children:`·`}),e.lastStatus&&(0,Z.jsx)(`span`,{className:`truncate`,children:e.lastStatus})]}),l>0&&(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:[(0,Z.jsx)(`span`,{children:n(`activity:goal.deliverables`)}),(0,Z.jsxs)(`span`,{className:`tabular-nums`,children:[c,`/`,l]})]}),(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:a.map(e=>(0,Z.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px]`,children:[e.status===`done`?(0,Z.jsx)(Bn,{className:`h-3 w-3 text-success mt-0.5 shrink-0`}):(0,Z.jsx)(Qr,{className:`h-3 w-3 text-muted-foreground/70 mt-0.5 shrink-0`}),(0,Z.jsx)(`span`,{className:K(`leading-snug`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground`),children:e.text})]},e.id))})]}),o.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:n(`activity:goal.recentActivity`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:o.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{className:`font-mono tabular-nums shrink-0 text-foreground/60`,children:[`#`,e.iteration]}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.task||e.status||e.progressNote||`…`})]},`${e.iteration}-${t}`))})]})]})]})}var nT={in_progress:0,pending:1,completed:2},rT=`__no_session__`,iT=new Map,aT=new Set;k(e=>{iT.delete(e),aT.add(e)});function oT(){let{t:e}=W(),t=H(e=>e.todos),n=Pe(),[r,i]=(0,X.useState)(new Set),a=S(),o=(0,X.useRef)(n??rT);(0,X.useLayoutEffect)(()=>{aT.has(o.current)||iT.set(o.current,new Set(r));let e=n??rT;aT.delete(e),i(new Set(iT.get(e)??[])),o.current=e},[n]),(0,X.useEffect)(()=>{n&&a.send({type:`todos.get`,payload:{sessionId:n}})},[n,a]);let s=(0,X.useCallback)(e=>{a.removeTodo(e)},[a]),c=(0,X.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)=>(nT[e.status]??9)-(nT[t.status]??9)),u=l.filter(e=>e.status===`completed`).length,d=l.filter(e=>e.status===`in_progress`),f=l.filter(e=>e.status===`pending`),p=l.filter(e=>e.status===`completed`),m=p.length>0,h=r.has(`completed`),g=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=t=>{let n=t.status===`in_progress`&&t.activeForm?t.activeForm:t.content,r=t.status===`in_progress`,i=t.status===`completed`,a=!!(t.kanbanBoardId&&t.kanbanTaskId),o=!r&&!(a&&i);return(0,Z.jsxs)(`div`,{className:K(`relative px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors`,o&&`hover:bg-accent/40`,r?`bg-warning/8`:i?`bg-success/5`:`bg-background`),children:[o&&(0,Z.jsx)(`button`,{type:`button`,className:`absolute inset-0 cursor-pointer`,"aria-label":e(`activity:todos.toggleAria`,{content:t.content}),onClick:()=>c(t)}),(0,Z.jsx)(`span`,{className:`pointer-events-none relative mt-0.5 shrink-0`,children:i?(0,Z.jsx)(Bn,{className:`w-3.5 h-3.5 text-success`}):r?(0,Z.jsx)(la,{className:`w-3.5 h-3.5 text-warning animate-spin`}):(0,Z.jsx)(Qr,{className:K(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/65 group-hover:text-success`)})}),(0,Z.jsxs)(`span`,{className:K(`pointer-events-none relative leading-snug flex-1 min-w-0`,r?`text-warning font-medium`:i?`text-muted-foreground line-through`:`text-foreground/80`),children:[n,t.blockedBy?.length?(0,Z.jsx)(`span`,{className:`mt-0.5 block text-[11px] text-destructive`,children:e(`activity:todos.blockedBy`,{work:t.blockedBy.join(`; `)})}):null]}),!a&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>s(t.id),className:`relative 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,Z.jsx)(jn,{className:`w-3 h-3 text-muted-foreground`})})]},t.id)};return t.length===0?null:(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Z.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:e(`activity:work.todos`)}),(0,Z.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,t.length]})]}),d.length>0&&(0,Z.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:d.map(_)}),f.length>0&&(0,Z.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:f.map(_)}),m&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>g(`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,Z.jsxs)(`span`,{className:`tabular`,children:[h?`▶`:`▼`,` `,e(`activity:todos.completedCount`,{count:p.length})]})}),!h&&p.map(_)]})]})}var sT={pending:{icon:(0,Z.jsx)(Qr,{className:`w-3.5 h-3.5`}),labelKey:`statusPending`,color:`text-muted-foreground/70`},in_progress:{icon:(0,Z.jsx)(la,{className:`w-3.5 h-3.5 animate-spin`}),labelKey:`statusInProgress`,color:`text-warning`},blocked:{icon:(0,Z.jsx)(ct,{className:`w-3.5 h-3.5`}),labelKey:`statusBlocked`,color:`text-warning`},failed:{icon:(0,Z.jsx)(qr,{className:`w-3.5 h-3.5`}),labelKey:`statusFailed`,color:`text-destructive`},review:{icon:(0,Z.jsx)(Xt,{className:`w-3.5 h-3.5`}),labelKey:`statusReview`,color:`text-info`},completed:{icon:(0,Z.jsx)(Bn,{className:`w-3.5 h-3.5`}),labelKey:`statusDone`,color:`text-success`}},cT={critical:`text-destructive`,high:`text-warning`,medium:`text-warning/85`,low:`text-muted-foreground`},lT={feature:`⚡`,bugfix:`🐛`,refactor:`♻️`,docs:`📝`,test:`🧪`,chore:`🔧`},uT=`__no_session__`,dT=new Map,fT=new Set;k(e=>{dT.delete(e),fT.add(e)});function pT(){let{t:e}=W(),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(new Set),a=S(),o=Pe(),s=(0,X.useRef)(o??uT);(0,X.useLayoutEffect)(()=>{fT.has(s.current)||dT.set(s.current,new Set(r));let e=o??uT;fT.delete(e),i(new Set(dT.get(e)??[])),s.current=e},[o]),up(`tasks.updated`,e=>{let t=e.payload;t?.sessionId&&o&&t.sessionId!==o||t?.tasks&&n(t.tasks)},{sessionId:o,deps:[o]}),(0,X.useEffect)(()=>{n([]),a.getTasks()},[o,a]);let c=(0,X.useCallback)(e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),l=(0,X.useCallback)((e,t)=>{a.updateTaskStatus(e,t)},[a]),u=[`in_progress`,`blocked`,`review`,`pending`,`failed`,`completed`],d=[...t].sort((e,t)=>u.indexOf(e.status)-u.indexOf(t.status)),f=new Map;for(let e of d){let t=f.get(e.status)??[];t.push(e),f.set(e.status,t)}let p=t.filter(e=>e.status===`completed`).length;return t.length===0?null:(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Z.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:e(`activity:work.tasks`)}),(0,Z.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[p,`/`,t.length]})]}),u.map(t=>{let n=f.get(t);if(!n||n.length===0)return null;let i=sT[t],a=r.has(t);return(0,Z.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>c(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,Z.jsxs)(`span`,{className:`tabular`,children:[a?`▶`:`▼`,` `,n.length,` `,e(`activity:task.${i.labelKey}`)]})}),!a&&n.map(t=>(0,Z.jsxs)(`div`,{className:K(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,t.status===`in_progress`?`bg-warning/8`:``),children:[(0,Z.jsx)(`span`,{className:K(`mt-0.5 shrink-0`,i.color),children:i.icon}),(0,Z.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,Z.jsxs)(`span`,{className:K(t.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[lT[t.type],` `,t.title]}),t.priority!==`medium`&&(0,Z.jsx)(`span`,{className:K(`ml-1 text-[10px]`,cT[t.priority]),children:t.priority}),t.assignee&&(0,Z.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,t.assignee]}),t.estimateHours&&(0,Z.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[t.estimateHours,`h`]})]}),(0,Z.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,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(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,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(t.id,`completed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-success/15 text-success hover:bg-success/25 transition-colors`,title:e(`activity:task.completeTitle`),children:e(`activity:task.statusDone`)}),t.status!==`completed`&&t.status!==`failed`&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(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 mT={open:{icon:(0,Z.jsx)(Qr,{className:`w-3.5 h-3.5`}),labelKey:`statusOpen`,color:`text-muted-foreground/70`},in_progress:{icon:(0,Z.jsx)(la,{className:`w-3.5 h-3.5 animate-spin`}),labelKey:`statusInProgress`,color:`text-warning`},done:{icon:(0,Z.jsx)(Bn,{className:`w-3.5 h-3.5`}),labelKey:`statusDone`,color:`text-success`}},hT=`__no_session__`,gT=new Map,_T=new Set;k(e=>{gT.delete(e),_T.add(e)});function vT(){let{t:e}=W(),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(new Set),a=S(),o=Pe(),s=(0,X.useRef)(o??hT);(0,X.useLayoutEffect)(()=>{_T.has(s.current)||gT.set(s.current,new Set(r));let e=o??hT;_T.delete(e),i(new Set(gT.get(e)??[])),s.current=e},[o]),(0,X.useEffect)(()=>{n([]),a.getPlan();let e=a.on(`plan.updated`,e=>{let t=e?.payload;t?.sessionId&&o&&t.sessionId!==o||t?.plan?.items&&n(t.plan.items)});return()=>{e()}},[o,a]);let c=(0,X.useCallback)(e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),l=(0,X.useCallback)((e,t)=>{a.updatePlanItem(e.id,t)},[a]),u=[`in_progress`,`open`,`done`],d=[...t].sort((e,t)=>u.indexOf(e.status)-u.indexOf(t.status)),f=new Map;for(let e of d){let t=f.get(e.status)??[];t.push(e),f.set(e.status,t)}let p=t.filter(e=>e.status===`done`).length;return t.length===0?null:(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Z.jsxs)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:[`📋 `,e(`activity:work.plan`)]}),(0,Z.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[p,`/`,t.length]})]}),u.map(t=>{let n=f.get(t);if(!n||n.length===0)return null;let i=mT[t],a=r.has(t);return(0,Z.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>c(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,Z.jsxs)(`span`,{className:`tabular`,children:[a?`▶`:`▼`,` `,n.length,` `,e(`activity:plan.${i.labelKey}`)]})}),!a&&n.map(t=>(0,Z.jsxs)(`div`,{className:K(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,t.status===`in_progress`?`bg-warning/8`:``),children:[(0,Z.jsx)(`span`,{className:K(`mt-0.5 shrink-0`,i.color),children:i.icon}),(0,Z.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,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[t.status===`open`&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(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,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(t,`done`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-success/15 text-success hover:bg-success/25 transition-colors`,title:e(`activity:plan.doneTitle`),children:e(`activity:plan.statusDone`)}),t.status===`done`&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(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 yT=[{id:`todos`,labelKey:`work.todos`,icon:`✅`},{id:`tasks`,labelKey:`work.tasks`,icon:`📋`},{id:`plan`,labelKey:`work.plan`,icon:`🗺️`}];function bT(){let{t:e}=W(),t=q(e=>e.workDashboardTab),n=q(e=>e.setWorkDashboardTab);return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:yT.map(r=>(0,Z.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,Z.jsx)(`span`,{className:`text-xs`,children:r.icon}),e(`activity:${r.labelKey}`)]},r.id))}),(0,Z.jsx)(`div`,{className:K(t===`todos`?`block`:`hidden`),children:(0,Z.jsx)(oT,{})}),(0,Z.jsx)(`div`,{className:K(t===`tasks`?`block`:`hidden`),children:(0,Z.jsx)(pT,{})}),(0,Z.jsx)(`div`,{className:K(t===`plan`?`block`:`hidden`),children:(0,Z.jsx)(vT,{})})]})}var xT={primary:`hsl(var(--primary))`,info:`hsl(var(--info))`,success:`hsl(var(--success))`,warning:`hsl(var(--warning))`,destructive:`hsl(var(--destructive))`,muted:`hsl(var(--muted-foreground))`,foreground:`hsl(var(--foreground))`},ST=[xT.primary,xT.info,xT.success,xT.warning,xT.destructive,xT.muted],CT=e=>e.replace(/^wstack\/ap\//,``);function wT(e){return[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt).map((e,t)=>({handle:e,color:ST[t%ST.length],y:60+t*48}))}var TT={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 ET({worktrees:e,baseBranch:t}){let{t:n}=W(),r=wT(e),i=Math.max(120,60+r.length*48+20);return(0,Z.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-border/70 bg-card/70 p-3`,children:(0,Z.jsxs)(`svg`,{width:`100%`,height:i,viewBox:`0 0 600 ${i}`,className:`min-w-[420px]`,role:`img`,"aria-label":n(`activity:worktree.graphAria`,{base:t||`HEAD`}),children:[(0,Z.jsx)(`title`,{children:n(`activity:worktree.graphAria`,{base:t||`HEAD`})}),(0,Z.jsx)(`line`,{x1:40,y1:20,x2:40,y2:i-10,stroke:xT.primary,strokeWidth:3}),(0,Z.jsx)(`text`,{x:36,y:14,style:{fontSize:wo(11)},fill:xT.muted,children:t||`HEAD`}),(0,Z.jsx)(`circle`,{cx:40,cy:20,r:5,fill:xT.primary}),r.map(e=>{let r=TT[e.handle.status]??oe(TT.active),i=e.handle.status===`merged`,a=e.handle.status===`needs-review`||e.handle.status===`failed`;return(0,Z.jsxs)(`g`,{className:`transition-all duration-500`,children:[(0,Z.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:r.dash,opacity:r.opacity}),i?(0,Z.jsx)(`path`,{d:`M 220 ${e.y} C 160 ${e.y+20}, 100 ${e.y+24}, 40 ${e.y+24}`,fill:`none`,stroke:xT.success,strokeWidth:2,opacity:.9}):null,(0,Z.jsx)(`circle`,{cx:220,cy:e.y,r:5,fill:a?xT.destructive:e.color}),(0,Z.jsx)(`text`,{x:232,y:e.y-6,style:{fontSize:wo(12),fontFamily:`var(--font-mono)`},fill:xT.foreground,children:CT(e.handle.branch)}),(0,Z.jsx)(`text`,{x:232,y:e.y+10,style:{fontSize:wo(10)},fill:xT.muted,children:a?`⚠ ${e.handle.status}`:i?n(`activity:worktree.mergedLabel`,{base:t}):`+${e.handle.insertions}/-${e.handle.deletions} · ${e.handle.ownerLabel}`})]},e.handle.handleId)})]})})}var DT={allocating:{icon:`○`,labelKey:`statusAllocating`,tint:`border-muted-foreground/40`,dot:`bg-muted-foreground`},active:{icon:`●`,labelKey:`statusActive`,tint:`border-warning/40`,dot:`bg-warning animate-pulse`},committing:{icon:`◐`,labelKey:`statusCommitting`,tint:`border-primary/40`,dot:`bg-primary animate-pulse`},merging:{icon:`⇡`,labelKey:`statusMerging`,tint:`border-info/40`,dot:`bg-info animate-pulse`},merged:{icon:`✓`,labelKey:`statusMerged`,tint:`border-success/40`,dot:`bg-success`},"needs-review":{icon:`⚠`,labelKey:`statusConflict`,tint:`border-destructive/50`,dot:`bg-destructive`},failed:{icon:`✗`,labelKey:`statusFailed`,tint:`border-destructive/50`,dot:`bg-destructive`}};function OT(e){return DT[e]??{icon:`?`,labelKey:``,tint:`border-border`,dot:`bg-muted-foreground`}}var kT=e=>e.replace(/^wstack\/ap\//,``);function AT({worktrees:e,baseBranch:t}){let{t:n}=W(),r=[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt);return(0,Z.jsxs)(`div`,{className:`rounded-lg border bg-card/50 backdrop-blur-sm px-3 py-3`,children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`font-semibold tracking-wide uppercase text-[10px]`,children:n(`activity:worktree.lanesHeading`)}),(0,Z.jsxs)(`span`,{className:`opacity-60`,children:[`· `,n(`activity:worktree.base`)]}),(0,Z.jsx)(`code`,{className:`font-mono text-primary`,children:t||`HEAD`}),(0,Z.jsxs)(`span`,{className:`opacity-60`,children:[`· `,n(`activity:worktree.isolatedCount`,{count:r.length})]})]}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>{let t=OT(e.status),r=e.status===`needs-review`,i=Math.min(100,e.insertions+e.deletions);return(0,Z.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,Z.jsx)(`span`,{className:K(`h-2.5 w-2.5 shrink-0 rounded-full`,t.dot),"aria-hidden":!0}),(0,Z.jsx)(`code`,{className:`w-44 shrink-0 truncate font-mono text-sm`,children:kT(e.branch)}),(0,Z.jsxs)(`span`,{className:`shrink-0 rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:[`⟵ `,e.ownerLabel]}),r?(0,Z.jsx)(`span`,{className:`font-mono text-xs font-bold text-destructive`,children:n(`activity:worktree.conflictBadge`)}):(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-xs transition-all duration-500`,children:[(0,Z.jsxs)(`span`,{className:`text-success`,children:[`+`,e.insertions]}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,Z.jsxs)(`span`,{className:`text-destructive`,children:[`-`,e.deletions]}),(0,Z.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[e.files,`f`]})]}),(0,Z.jsx)(`div`,{className:`ml-auto hidden h-1 w-24 overflow-hidden rounded-full bg-muted sm:block`,children:(0,Z.jsx)(`div`,{className:`h-full bg-gradient-to-r from-success to-destructive transition-all duration-700`,style:{width:`${i}%`}})}),(0,Z.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,Z.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 jT=e=>e?e.replace(/^wstack\/ap\//,``):``;function MT(){let{t:e}=W(),{client:t}=hf(),n=ho(e=>e.orphans),r=ho(e=>e.canClean),i=ho(e=>e.cleanBlockedReason),a=ho(e=>e.cleanResult),[o,s]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{t?.send?.({type:`worktree.scan`})},[t]),(0,X.useEffect)(()=>{a&&s(!1)},[a]),n.length===0&&!a?null:(0,Z.jsxs)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-xs`,children:[n.length>0?(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(dr,{className:`mt-0.5 h-4 w-4 shrink-0 text-warning`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-warning`,children:e(`activity:worktree.orphanCount`,{count:n.length})}),(0,Z.jsx)(`div`,{className:`mt-0.5 max-h-16 overflow-auto font-mono text-[10px] text-muted-foreground`,children:n.map((e,t)=>(0,Z.jsxs)(`div`,{className:`truncate`,children:[e.kind===`branch`?`⌥ `:`▢ `,jT(e.branch)||e.dir]},`${e.kind}-${e.branch??e.dir??t}`))})]}),(0,Z.jsxs)(`button`,{type:`button`,disabled:!r||o,onClick:async()=>{let r=n.length;await $f({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-warning px-2 py-1 font-medium text-primary-foreground hover:bg-warning/90 disabled:cursor-not-allowed disabled:opacity-50`,children:[o?(0,Z.jsx)(mn,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Gn,{className:`h-3.5 w-3.5`}),e(`activity:worktree.cleanConfirm`)]})]}):null,a&&(0,Z.jsx)(`div`,{className:a.ok?`mt-1 text-success`:`mt-1 text-destructive`,children:a.ok?e(`activity:worktree.removed`,{count:a.removed}):`✗ ${a.reason??e(`activity:worktree.cleanupFailed`)}`})]})}var NT={goal:{active:`bg-primary/12 border-primary/40 text-primary shadow-sm`,idle:`text-primary/80 hover:bg-primary/10`},"goal-state":{active:`bg-destructive/10 border-destructive/35 text-destructive shadow-sm`,idle:`text-destructive/80 hover:bg-destructive/10`},fleet:{active:`bg-success/12 border-success/35 text-success shadow-sm`,idle:`text-success/80 hover:bg-success/10`},work:{active:`bg-warning/12 border-warning/35 text-warning shadow-sm`,idle:`text-warning/80 hover:bg-warning/10`},worktrees:{active:`bg-info/12 border-info/35 text-info shadow-sm`,idle:`text-info/80 hover:bg-info/10`},collab:{active:`bg-accent border-primary/25 text-accent-foreground shadow-sm`,idle:`text-muted-foreground hover:bg-muted/60`}},PT={goal:`Goal`,"goal-state":`Goal State`,fleet:`Fleet`,work:`Work`,worktrees:`Worktrees`,collab:`Collab`},FT=[`goal`,`goal-state`,`fleet`,`work`,`worktrees`,`collab`];function IT({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=NT[e],{t:c}=W();return(0,Z.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-md border text-xs font-medium shrink-0 transition-colors`,i?s.active:K(`border-border/40`,s.idle)),children:[(0,Z.jsx)(`span`,{className:K(a&&`animate-pulse`),children:t}),n,r&&(0,Z.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function LT(){let e=q(e=>e.dockSection),{t}=W(),n=q(e=>e.toggleDockSection),r=q(e=>e.hiddenChips),i=q(e=>e.toggleChipHidden),a=q(e=>e.dockCustomizeOpen),o=q(e=>e.setDockCustomizeOpen),s=Pe(),c=to(e=>e.goal),l=_o(e=>e.phases.length),u=_o(e=>e.overallPercent),d=_o(e=>e.activePhaseId),f=ho(e=>e.worktrees),p=H(e=>e.todos),m=M(e=>e.agents),h=qw(),g=(0,X.useMemo)(()=>Array.from(m.values()).filter(e=>R(e.sessionId,s)),[m,s]),_=g.length,v=(0,X.useMemo)(()=>g.filter(e=>e.status===`running`).length,[g]),y=p.filter(e=>e.status===`completed`).length,b=p.some(e=>e.status===`in_progress`),x=l>0,S=(0,X.useMemo)(()=>new Set(r),[r]),C={goal:x,"goal-state":c!==null,fleet:_>0,work:!0,worktrees:f.length>0,collab:!0},w={goal:(C.goal||e===`goal`)&&!S.has(`goal`),"goal-state":(C[`goal-state`]||e===`goal-state`)&&!S.has(`goal-state`),fleet:(C.fleet||e===`fleet`)&&!S.has(`fleet`),work:(C.work||e===`work`)&&!S.has(`work`),worktrees:(C.worktrees||e===`worktrees`)&&!S.has(`worktrees`),collab:(C.collab||e===`collab`)&&!S.has(`collab`)},T=e&&w[e]?e:null;return(0,Z.jsx)(`div`,{children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 rounded-lg border border-border/70 bg-card/70 px-2 py-1.5 shadow-sm`,children:[w.goal&&(0,Z.jsx)(IT,{section:`goal`,icon:(0,Z.jsx)(Pn,{className:`h-3 w-3`}),label:t(`activity:dock.goal`),value:`${u}%`,active:!1,pulse:d!=null,onClick:()=>Ha(`goal`)}),w[`goal-state`]&&c&&(0,Z.jsx)(IT,{section:`goal-state`,icon:(0,Z.jsx)(ki,{className:`h-3 w-3`}),label:t(`activity:dock.goalState`),value:`${c.progress}%`,active:T===`goal-state`,pulse:c.goalState===`active`,onClick:()=>n(`goal-state`)}),w.fleet&&(0,Z.jsx)(IT,{section:`fleet`,icon:(0,Z.jsx)(on,{className:`h-3 w-3`}),label:t(`activity:dock.fleet`),value:`${v}/${_}`,active:T===`fleet`,pulse:v>0,onClick:()=>n(`fleet`)}),(0,Z.jsx)(IT,{section:`work`,icon:(0,Z.jsx)(wn,{className:`h-3 w-3`}),label:t(`activity:dock.work`),value:p.length>0?`${y}/${p.length}`:void 0,active:T===`work`,pulse:b,onClick:()=>n(`work`)}),w.worktrees&&(0,Z.jsx)(IT,{section:`worktrees`,icon:(0,Z.jsx)(jr,{className:`h-3 w-3`}),label:t(`activity:dock.worktrees`),value:String(f.length),active:T===`worktrees`,onClick:()=>n(`worktrees`)}),h&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{},className:`inline-flex h-8 max-w-full min-w-0 items-center gap-1.5 rounded-md border border-border/50 px-2.5 text-xs font-mono transition-colors hover:bg-muted/60 sm:h-7`,children:[(0,Z.jsx)(jr,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-semibold text-foreground`,children:h.branch}),h.ahead>0&&(0,Z.jsxs)(`span`,{className:`text-success`,title:t(`activity:dock.ahead`,{count:h.ahead}),children:[`↑`,h.ahead]}),h.behind>0&&(0,Z.jsxs)(`span`,{className:`text-warning`,title:t(`activity:dock.behind`,{count:h.behind}),children:[`↓`,h.behind]}),h.added>0&&(0,Z.jsxs)(`span`,{className:`text-success`,title:t(`activity:dock.linesAdded`,{count:h.added}),children:[`+`,h.added]}),h.deleted>0&&(0,Z.jsxs)(`span`,{className:`text-destructive`,title:t(`activity:dock.linesDeleted`,{count:h.deleted}),children:[`-`,h.deleted]}),h.untracked>0&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,title:t(`activity:dock.untrackedFiles`,{count:h.untracked}),children:[h.untracked,`?`]})]}),(0,Z.jsx)(IT,{section:`collab`,icon:(0,Z.jsx)(_t,{className:`h-3 w-3`}),label:t(`activity:dock.collab`),active:T===`collab`,onClick:()=>n(`collab`)}),(0,Z.jsxs)(_s,{open:a,onOpenChange:o,children:[(0,Z.jsx)(vs,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,title:t(`activity:dock.customizeTitle`),className:`ml-auto inline-flex items-center justify-center h-7 w-7 rounded-md border border-border/50 text-muted-foreground hover:bg-muted/60 transition-colors shrink-0`,children:(0,Z.jsx)(Bi,{className:`h-3 w-3`})})}),(0,Z.jsxs)(xs,{align:`end`,className:`w-44`,children:[(0,Z.jsx)(Ts,{children:t(`activity:dock.dockChips`)}),(0,Z.jsx)(Es,{}),FT.map(e=>(0,Z.jsx)(Cs,{checked:!S.has(e),onCheckedChange:()=>i(e),onSelect:e=>e.preventDefault(),children:PT[e]},e))]})]})]})})}var RT={"goal-state":{titleKey:`activity:dock.goalState`,detailKey:`activity:dock.goalStateDetail`},fleet:{titleKey:`activity:dock.fleet`,detailKey:`activity:dock.fleetDetail`},work:{titleKey:`activity:dock.work`,detailKey:`activity:dock.workDetail`},worktrees:{titleKey:`activity:dock.worktrees`,detailKey:`activity:dock.worktreesDetail`},collab:{titleKey:`activity:dock.collab`,detailKey:`activity:dock.collabDetail`}};function zT({sessionId:e}){let t=q(e=>e.dockSection),n=q(e=>e.setDockSection),r=q(e=>e.inspectorOpen),i=to(e=>e.goal),a=ho(e=>e.worktrees),o=ho(e=>e.baseBranch),[s,c]=(0,X.useState)(`graph`),{t:l}=W(),u=t!==null&&t!==`goal`,d=u?t:null,f=d?RT[d]:null,p=r&&u?`sm:right-[min(680px,48vw)]`:``;return(0,X.useEffect)(()=>{if(!u)return;let e=e=>{e.key===`Escape`&&n(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,n]),(0,Z.jsxs)(`aside`,{id:`workspace-dock-inspector`,"data-testid":u?`workspace-dock-inspector`:void 0,"data-escape-owns":u?`true`:void 0,"aria-hidden":!u,inert:!u||void 0,"aria-label":f?l(`activity:dock.inspectorNamed`,{name:l(f.titleKey)}):l(`activity:dock.inspector`),className:K(`fixed inset-y-0 right-0 z-40 flex w-[calc(100vw-3rem)] max-w-none flex-col overflow-hidden border-l border-border/80 bg-card/96 shadow-[-24px_0_64px_-36px_hsl(var(--shadow-color)/0.65)] backdrop-blur-xl transition-transform duration-200 sm:w-[min(680px,48vw)] sm:max-w-[680px]`,p,u?`translate-x-0`:`pointer-events-none translate-x-full`),children:[(0,Z.jsxs)(`header`,{className:`relative shrink-0 border-b border-border/70 bg-muted/20 px-4 py-3 pr-12`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-foreground`,children:[(0,Z.jsx)(Ai,{className:`h-4 w-4 text-primary`}),l(f?f.titleKey:`activity:dock.workspace`)]}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:l(f?f.detailKey:`activity:dock.workspaceDetails`)}),(0,Z.jsx)(`button`,{type:`button`,"data-testid":`workspace-dock-inspector-close`,onClick:()=>n(null),className:`absolute right-3 top-3 inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,"aria-label":l(`activity:dock.closeWorkspaceInspector`),title:l(`activity:dock.closeWorkspaceInspector`),children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain p-3 sm:p-4`,children:[d===`goal-state`&&(i?(0,Z.jsx)(tT,{goal:i}):(0,Z.jsx)(BT,{title:l(`activity:dock.noActiveGoal`),detail:l(`activity:dock.noActiveGoalDetail`)})),d===`fleet`&&(0,Z.jsx)(Qw,{}),d===`worktrees`&&(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>c(e),className:K(`rounded-md border px-2.5 py-1 text-xs capitalize transition-colors`,s===e?`border-primary/30 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),(0,Z.jsx)(MT,{}),s===`graph`?(0,Z.jsx)(ET,{worktrees:a,baseBranch:o||`HEAD`}):(0,Z.jsx)(AT,{worktrees:a,baseBranch:o||`HEAD`})]}),(0,Z.jsx)(`div`,{className:K(d===`work`?`block`:`hidden`),id:`panel-work`,children:(0,Z.jsx)(bT,{})}),(0,Z.jsx)(`div`,{className:K(d===`collab`?`block`:`hidden`),children:(0,Z.jsx)(Xw,{sessionId:e})})]})]})}function BT({title:e,detail:t}){return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-muted/20 px-3 py-2 text-xs`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-foreground`,children:e}),(0,Z.jsx)(`div`,{className:`mt-1 text-muted-foreground`,children:t})]})}function VT({sessionId:e,desktopShell:t}){let{t:n}=W(),{currentView:r,terminalOpen:i,setTerminalOpen:a}=q(Yr(e=>({currentView:e.currentView,terminalOpen:e.terminalOpen,setTerminalOpen:e.setTerminalOpen}))),o=e,s=sx;return(0,Z.jsxs)(Z.Fragment,{children:[o&&(0,Z.jsxs)(`div`,{className:K(`flex flex-col`,r!==`chat`&&`ws-view-parked`),...r===`chat`?{}:{inert:!0,"aria-hidden":!0},children:[(0,Z.jsx)(`div`,{className:`ws-workspace-dock-wrap shrink-0 px-3 pt-2 sm:px-4`,children:(0,Z.jsx)(LT,{})}),(0,Z.jsx)(fC,{})]}),(0,Z.jsx)(`div`,{className:K(`flex min-h-0 min-w-0 flex-1 flex-col`,r!==`chat`&&`ws-view-parked`),...r===`chat`?{}:{inert:!0,"aria-hidden":!0},children:(0,Z.jsx)(_p,{level:`panel`,name:n(`activity:panels.chat`),children:(0,Z.jsx)(Kw,{})})}),r!==`chat`&&(0,Z.jsx)(ox,{view:r,onCloseToChat:s}),i&&(0,Z.jsx)(_p,{level:`panel`,name:n(`activity:panels.terminal`),children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(qg,{label:n(`common:loadingNamed`,{name:n(`activity:panels.terminal`)})}),children:(0,Z.jsx)(HT,{desktopShell:t,onClose:()=>a(!1)})})})]})}var HT=(0,X.lazy)(()=>La(()=>import(`./TerminalPanel-DxAt_S44.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([63,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,64,65])));async function UT(e,t){let n=await fetch(`/api/integrations/${e}/status`,{method:`GET`,signal:t,headers:{accept:`application/json`}}),r=await n.json();return{connected:n.ok&&r.connected===!0,...typeof r.latencyMs==`number`?{latencyMs:r.latencyMs}:{},...typeof r.error==`string`?{error:r.error}:{}}}function WT(){let e=G(e=>e.wrongProxyEnabled),t=G(e=>e.wrongProxyUrl),[n,r]=(0,X.useState)(()=>({status:e?`checking`:`disabled`,latencyMs:null,url:t||`http://localhost:3444`}));return(0,X.useEffect)(()=>{if(!e||!t){r({status:`disabled`,latencyMs:null,url:t||`http://localhost:3444`});return}let n=!1,i=async()=>{let e=t.trim().replace(/\/+$/,``),i=Date.now(),a=new AbortController,o=setTimeout(()=>a.abort(),2e3);try{let t=await UT(`wrong-proxy`,a.signal);if(clearTimeout(o),n)return;let s=t.connected;r({status:s?`connected`:`error`,latencyMs:t.latencyMs??Date.now()-i,url:e,error:s?void 0:t.error??`Unreachable`})}catch(t){if(clearTimeout(o),n)return;r({status:`error`,latencyMs:Date.now()-i,url:e,error:t instanceof Error?t.message:`Unreachable`})}};i();let a=setInterval(()=>void i(),1e4);return()=>{n=!0,clearInterval(a)}},[e,t]),n}function GT(){let e=G(e=>e.hqEnabled),t=G(e=>e.hqUrl),n=G(e=>e.hqToken),[r,i]=(0,X.useState)(()=>({status:e&&t?`checking`:`disabled`,latencyMs:null,url:t||``}));return(0,X.useEffect)(()=>{if(!e||!t){i({status:`disabled`,latencyMs:null,url:t||``});return}let n=!1,r=async()=>{let e=t.trim().replace(/\/+$/,``),r=Date.now(),a=new AbortController,o=setTimeout(()=>a.abort(),2e3);try{let t=await UT(`hq`,a.signal);if(clearTimeout(o),n)return;let s=t.connected;i({status:s?`connected`:`error`,latencyMs:t.latencyMs??Date.now()-r,url:e,error:s?void 0:t.error??`Unreachable`})}catch(t){if(clearTimeout(o),n)return;i({status:`error`,latencyMs:Date.now()-r,url:e,error:t instanceof Error?t.message:`Unreachable`})}};r();let a=setInterval(()=>void r(),1e4);return()=>{n=!0,clearInterval(a)}},[e,t,n]),r}function KT(){let e=Ya(e=>e.snapshot),t=q(e=>e.setCronJobsOpen),n=e?.jobs??[],r=n.filter(e=>e.overdue).length,i=n.filter(e=>e.enabled&&!e.overdue).length,a=n.length;return a===0?null:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>t(!0),className:K(`relative inline-flex h-8 items-center gap-1.5 rounded-md border px-2 text-xs transition-colors`,r>0?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/15`:`border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`),title:`${a} cron job${a===1?``:`s`}${r>0?`, ${r} overdue`:``}`,children:[(0,Z.jsx)(Ft,{className:`h-3.5 w-3.5`}),(0,Z.jsxs)(`span`,{className:`hidden lg:inline`,children:[i,`/`,a]}),r>0?(0,Z.jsx)(`span`,{className:`min-w-4 bg-destructive/15 px-1 text-[10px] font-semibold tabular-nums text-destructive`,children:r>99?`99+`:r}):null]})}function qT(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/1e3);if(r<10)return t(`toasts:menu.justNow`,{defaultValue:`Just now`});if(r<60)return t(`toasts:menu.secondsAgo`,{count:r,defaultValue:`${r}s ago`});let i=Math.floor(r/60);if(i<60)return t(`toasts:menu.minutesAgo`,{count:i,defaultValue:`${i}m ago`});let a=Math.floor(i/60);if(a<24)return t(`toasts:menu.hoursAgo`,{count:a,defaultValue:`${a}h ago`});let o=Math.floor(a/24);return t(`toasts:menu.daysAgo`,{count:o,defaultValue:`${o}d ago`})}function JT({variant:e}){return e===`success`?(0,Z.jsx)(xn,{className:`h-4 w-4 text-success shrink-0`}):e===`error`?(0,Z.jsx)(qr,{className:`h-4 w-4 text-destructive shrink-0`}):e===`warn`?(0,Z.jsx)(dr,{className:`h-4 w-4 text-warning shrink-0`}):(0,Z.jsx)(nn,{className:`h-4 w-4 text-info shrink-0`})}function YT({item:e,onMarkAsRead:t,onRemove:n}){let{t:r}=W(),i=(0,X.useMemo)(()=>qT(e.timestamp,r),[e.timestamp,r]),a=(0,X.useMemo)(()=>new Date(e.timestamp).toLocaleString(),[e.timestamp]);return(0,Z.jsxs)(`div`,{role:`menuitem`,tabIndex:0,onClick:()=>{e.read||t()},onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e.read||t())},className:K(`group relative flex items-start gap-2.5 px-3 py-2.5 text-xs transition-colors cursor-pointer outline-none select-none`,`hover:bg-accent/50 focus-visible:bg-accent/60`,e.read?`opacity-85`:`bg-primary/[0.04]`),children:[(0,Z.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:(0,Z.jsx)(JT,{variant:e.variant})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0 pr-1`,children:[(0,Z.jsx)(`div`,{className:K(`whitespace-pre-wrap break-words leading-relaxed text-foreground`,!e.read&&`font-medium`),children:e.message}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,title:a,children:[(0,Z.jsx)(la,{className:`h-3 w-3 opacity-70`}),i]}),e.action&&(0,Z.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),e.action?.onClick(),t()},className:`font-medium text-primary hover:underline`,children:e.action.label})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[!e.read&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t()},className:`rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground`,title:r(`toasts:menu.markAsRead`,{defaultValue:`Mark as read`}),"aria-label":r(`toasts:menu.markAsRead`,{defaultValue:`Mark as read`}),children:(0,Z.jsx)(xn,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n()},className:`rounded p-0.5 text-muted-foreground opacity-60 hover:opacity-100 hover:bg-destructive/10 hover:text-destructive transition-opacity`,title:r(`toasts:menu.remove`,{defaultValue:`Remove notification`}),"aria-label":r(`toasts:menu.remove`,{defaultValue:`Remove notification`}),children:(0,Z.jsx)(hn,{className:`h-3 w-3`})}),!e.read&&(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary shrink-0`,"aria-label":`Unread indicator`})]})]})}function XT({defaultOpen:e,open:t,onOpenChange:n}={}){let{t:r}=W(),i=N(e=>e.notifications),a=N(e=>e.markAsRead),o=N(e=>e.markAllAsRead),s=N(e=>e.clearAll),c=N(e=>e.removeNotification),[l,u]=(0,X.useState)(`all`),d=(0,X.useMemo)(()=>i.filter(e=>!e.read).length,[i]),f=(0,X.useMemo)(()=>l===`unread`?i.filter(e=>!e.read):i,[i,l]),p=(0,X.useCallback)(()=>{o()},[o]),m=(0,X.useCallback)(()=>{s()},[s]);return(0,Z.jsxs)(_s,{defaultOpen:e,open:t,onOpenChange:n,children:[(0,Z.jsx)(vs,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`notification-menu-trigger`,className:K(`relative inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground`,d>0&&`text-foreground`),title:d>0?`${r(`toasts:menu.title`,{defaultValue:`Notifications`})} (${d} ${r(`toasts:menu.unreadCount`,{count:d,defaultValue:`${d} unread`})})`:r(`toasts:menu.title`,{defaultValue:`Notifications`}),"aria-label":r(`toasts:menu.title`,{defaultValue:`Notifications`}),children:[d>0?(0,Z.jsx)(pr,{className:`h-3.5 w-3.5 text-primary`}):(0,Z.jsx)(rr,{className:`h-3.5 w-3.5`}),d>0&&(0,Z.jsx)(`span`,{"data-testid":`notification-badge`,className:`absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-destructive px-1 text-[10px] font-bold text-destructive-foreground shadow-sm`,children:d>99?`99+`:d})]})}),(0,Z.jsxs)(xs,{align:`end`,sideOffset:6,className:`w-80 sm:w-96 max-w-[calc(100vw-1rem)] p-0 rounded-xl border border-border/80 bg-card/95 backdrop-blur-xl shadow-2xl overflow-hidden text-card-foreground`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/60 px-3.5 py-2.5 bg-muted/30`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`font-semibold text-xs text-foreground`,children:r(`toasts:menu.title`,{defaultValue:`Notifications`})}),d>0?(0,Z.jsxs)(`span`,{className:`rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary tabular-nums`,children:[d,` `,r(`toasts:menu.tabUnread`,{defaultValue:`Unread`}).toLowerCase()]}):null]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,disabled:d===0,onClick:p,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground disabled:opacity-40 disabled:pointer-events-none`,title:r(`toasts:menu.markAllRead`,{defaultValue:`Mark all as read`}),children:[(0,Z.jsx)(Nt,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{children:r(`toasts:menu.markAllRead`,{defaultValue:`Mark all as read`})})]}),(0,Z.jsxs)(`button`,{type:`button`,disabled:i.length===0,onClick:m,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive disabled:opacity-40 disabled:pointer-events-none`,title:r(`toasts:menu.clearAll`,{defaultValue:`Clear all`}),children:[(0,Z.jsx)(jn,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{children:r(`toasts:menu.clearAll`,{defaultValue:`Clear all`})})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex border-b border-border/50 bg-background/50 px-3 py-1.5 gap-1.5 text-xs`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>u(`all`),className:K(`flex-1 rounded-md px-2.5 py-1 text-center font-medium transition-all`,l===`all`?`bg-accent text-accent-foreground shadow-xs`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[r(`toasts:menu.tabAll`,{defaultValue:`All`}),` (`,i.length,`)`]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>u(`unread`),className:K(`flex-1 rounded-md px-2.5 py-1 text-center font-medium transition-all`,l===`unread`?`bg-accent text-accent-foreground shadow-xs`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[r(`toasts:menu.tabUnread`,{defaultValue:`Unread`}),` (`,d,`)`]})]}),(0,Z.jsx)(`div`,{role:`list`,className:`max-h-[340px] overflow-y-auto divide-y divide-border/30`,"aria-label":r(`toasts:menu.title`,{defaultValue:`Notifications`}),children:f.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center px-4 py-8 text-center text-muted-foreground`,children:[(0,Z.jsx)(Dn,{className:`h-7 w-7 text-muted-foreground/40 mb-2`}),(0,Z.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:l===`unread`&&i.length>0?r(`toasts:menu.allRead`,{defaultValue:`All caught up`}):r(`toasts:menu.empty`,{defaultValue:`No notifications`})}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5 max-w-[220px]`,children:l===`unread`&&i.length>0?r(`toasts:menu.allRead`,{defaultValue:`All caught up`}):r(`toasts:menu.emptyHint`,{defaultValue:`Toasts and system notifications will appear here.`})})]}):f.map(e=>(0,Z.jsx)(YT,{item:e,onMarkAsRead:()=>a(e.id),onRemove:()=>c(e.id)},e.id))})]})]})}function ZT(e){return e.split(`-`).map(e=>e.slice(0,1).toUpperCase()+e.slice(1)).join(` `)}function QT(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${Math.round(e/1024**2)} MB`:e>=1024?`${Math.round(e/1024)} KB`:`${Math.round(e)} B`}function $T(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!1,n=async()=>{try{let n=await fetch(`/debug/system`,{cache:`no-store`});if(!n.ok)return;let r=await n.json();!e&&Number.isFinite(r.memoryUsage?.rss)&&t(r)}catch{}};n();let r=window.setInterval(()=>void n(),5e3);return()=>{e=!0,window.clearInterval(r)}},[]),e}function eE({currentView:e,projectName:t,sessionLabel:n,isLoading:r,iteration:i,onPalette:a,onSettings:o}){let{t:s}=W(),{theme:c,setTheme:l,palette:u,setPalette:d}=Fg(),f=V(e=>e.wsConnected),p=H(e=>e.appVersion),m=H(e=>e.latestVersion),h=H(e=>e.updateAvailable),g=H(e=>e.droppedTools),_=c===`system`?typeof window<`u`&&window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:c,v=(0,X.useCallback)(()=>{l(_===`dark`?`light`:`dark`)},[_,l]),y=q(e=>e.toggleSidebar),b=WT(),x=GT(),S=b.status===`connected`?`WrongProxy: Connected${b.latencyMs==null?``:` (${b.latencyMs}ms)`} · ${b.url}`:b.status===`error`?`WrongProxy: Unreachable · ${b.url}${b.error?` (${b.error})`:``}`:b.status===`checking`?`WrongProxy: Checking · ${b.url}`:`WrongProxy: Disabled`,C=x.status===`connected`?`HQ: Connected${x.latencyMs==null?``:` (${x.latencyMs}ms)`} · ${x.url}`:x.status===`error`?`HQ: Unreachable · ${x.url}${x.error?` (${x.error})`:``}`:x.status===`checking`?`HQ: Checking · ${x.url}`:`HQ: Disabled`,w=$T(),T=w?w.memoryUsage.heapUsed/w.heapLimit:0,E=w?.codebaseIndexServer,D=E?.health,O=D?.server;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-border/70 bg-card/85 px-2.5 py-1.5 shadow-sm backdrop-blur-xl md:hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:y,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,"aria-label":`Toggle navigation menu`,title:`Toggle navigation`,children:(0,Z.jsx)(Rn,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`min-w-0`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`truncate text-xs font-semibold`,children:t||`WrongStack`}),(0,Z.jsx)(`span`,{className:`rounded bg-muted/60 px-1 py-0.5 text-[10px] text-muted-foreground font-mono`,children:ZT(e)}),r&&(0,Z.jsx)(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] font-medium text-primary`,children:(0,Z.jsx)(on,{className:`h-3 w-3 animate-pulse`})})]})})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Z.jsx)(Em,{}),(0,Z.jsx)(XT,{}),(0,Z.jsx)(`button`,{type:`button`,onClick:v,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:_===`dark`?`Switch to light theme`:`Switch to dark theme`,children:_===`dark`?(0,Z.jsx)(Sr,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Vi,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(_s,{children:[(0,Z.jsx)(vs,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:`More options`,"aria-label":`More options`,children:(0,Z.jsx)(zt,{className:`h-3.5 w-3.5`})})}),(0,Z.jsxs)(xs,{align:`end`,className:`w-48`,children:[(0,Z.jsxs)(Ss,{onSelect:a,className:`gap-2`,children:[(0,Z.jsx)(Ji,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:s(`activity:topbar.command`)})]}),(0,Z.jsxs)(Ss,{onSelect:o,className:`gap-2`,children:[(0,Z.jsx)(bt,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:s(`activity:topbar.settings`)})]}),(0,Z.jsxs)(`div`,{className:`border-t border-border/60 my-1 px-2 py-1 space-y-1 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{children:`Backend WS`}),(0,Z.jsx)(`span`,{className:K(`font-mono font-medium`,f?`text-success`:`text-warning`),children:f?`Connected`:`Offline`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{children:`WrongProxy`}),(0,Z.jsx)(`span`,{className:K(`font-mono font-medium`,b.status===`connected`?`text-success`:b.status===`error`?`text-destructive`:`text-muted-foreground`),children:b.status===`connected`?`Connected`:b.status===`error`?`Offline`:`Disabled`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{children:`HQ`}),(0,Z.jsx)(`span`,{className:K(`font-mono font-medium`,x.status===`connected`?`text-success`:x.status===`error`?`text-destructive`:`text-muted-foreground`),children:x.status===`connected`?`Connected`:x.status===`error`?`Offline`:`Disabled`})]})]})]})]})]})]}),(0,Z.jsx)(`div`,{className:`hidden shrink-0 border-b border-border/70 bg-card/85 px-3 py-2 shadow-sm backdrop-blur-xl md:block`,children:(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate text-sm font-semibold`,children:t||`WrongStack`}),p?(0,Z.jsxs)(`span`,{className:K(`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 text-[11px] font-medium tabular-nums`,h&&m&&m!==p?`border-warning/40 bg-warning/10 text-warning`:`border-border/70 bg-muted/50 text-muted-foreground`),title:h&&m&&m!==p?`Update available: v${p} → v${m} — run wstack update`:`WrongStack v${p}`,children:[`v`,p,h&&m&&m!==p?(0,Z.jsxs)(`span`,{className:`text-[10px] opacity-80`,children:[`→ v`,m]}):null]}):null,(0,Z.jsx)(`span`,{className:`rounded-md border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:ZT(e)}),(0,Z.jsxs)(`span`,{className:K(`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] font-medium`,r?`bg-primary/10 text-primary`:`bg-muted text-muted-foreground`),children:[r?(0,Z.jsx)(on,{className:`h-3 w-3 animate-pulse`}):(0,Z.jsx)(Wr,{className:`h-3 w-3`}),r?`Running`:`Ready`,i?(0,Z.jsxs)(`span`,{className:`tabular`,children:[i.index,i.max>0?`/${i.max}`:``]}):null]}),(0,Z.jsx)(Em,{showCountWhenZero:!0}),w?(0,Z.jsxs)(`span`,{className:K(`rounded-md border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium tabular-nums`,T>=.85?`text-destructive`:T>=.6?`text-warning`:`text-success`),title:`WebUI server PID ${w.pid} · heap ${QT(w.memoryUsage.heapUsed)} / ${QT(w.heapLimit)}`,children:[`RAM `,QT(w.memoryUsage.rss)]}):null,E?(0,Z.jsxs)(`span`,{className:K(`rounded-md border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium tabular-nums`,E.status===`connected`?`text-success`:E.status===`unresponsive`||E.status===`error`?`text-destructive`:E.status===`degraded`||E.status===`connecting`||E.status===`stopping`?`text-warning`:`text-muted-foreground`),title:[`Codebase index: ${D?.status??E.status}`,E.pid?`PID ${E.pid}`:null,D?.latencyMs==null?null:`RTT ${D.latencyMs}ms`,O?`RAM ${QT(O.memory.rss)}`:null,D?.missedHeartbeats?`missed ${D.missedHeartbeats}`:null].filter(Boolean).join(` · `),children:[`Index `,D?.status??E.status]}):null,g>0?(0,Z.jsxs)(`span`,{className:`rounded-md border border-warning/40 bg-warning/10 px-1.5 py-0.5 text-[11px] font-medium tabular-nums text-warning`,title:`${g} tool(s) dropped from provider requests due to maxTools limit`,children:[`-`,g,` tools`]}):null]}),(0,Z.jsx)(`div`,{className:`mt-0.5 truncate text-[11px] text-muted-foreground`,children:n||`No named session`})]})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex h-8 items-center gap-1.5 rounded-md border border-border/70 bg-background/60 px-2 text-xs text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:s(`activity:topbar.commandPalette`),children:[(0,Z.jsx)(Ji,{className:`h-3.5 w-3.5`}),s(`activity:topbar.command`)]}),(0,Z.jsx)(`button`,{type:`button`,onClick:v,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:_===`dark`?`Switch to light theme`:`Switch to dark theme`,children:_===`dark`?(0,Z.jsx)(Sr,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Vi,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(_s,{children:[(0,Z.jsx)(vs,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:`${s(`settings:general.paletteSwitcherTitle`)}: ${s(me(u).labelKey)}`,"aria-label":`${s(`settings:general.paletteSwitcherTitle`)}: ${s(me(u).labelKey)}`,children:(0,Z.jsx)(Ii,{className:`h-3.5 w-3.5`})})}),(0,Z.jsxs)(xs,{align:`end`,className:`w-56`,children:[(0,Z.jsx)(Ts,{children:s(`settings:general.paletteHeading`)}),ue.map(e=>(0,Z.jsxs)(Ss,{onSelect:()=>d(e.id),className:`gap-2`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`h-4 w-4 shrink-0 rounded-[3px] border border-border/70`,style:{background:`linear-gradient(90deg, ${e.swatch} 0 50%, ${e.swatchSecondary} 50% 100%)`}}),(0,Z.jsx)(`span`,{className:`flex-1`,children:s(e.labelKey)}),u===e.id?(0,Z.jsx)(xn,{className:`h-3.5 w-3.5 text-primary`,"aria-hidden":!0}):null]},e.id))]})]}),(0,Z.jsx)(KT,{}),(0,Z.jsx)(XT,{}),(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:K(`inline-flex h-8 w-8 items-center justify-center rounded-md border bg-background/60 transition-colors`,b.status===`connected`?`border-border/70 text-success hover:bg-accent/60`:b.status===`error`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border/50 text-muted-foreground/40 hover:text-muted-foreground hover:bg-accent/60`),title:S,"aria-label":S,"data-testid":`wrongproxy-status-button`,children:(0,Z.jsx)(Cn,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:K(`inline-flex h-8 w-8 items-center justify-center rounded-md border bg-background/60 transition-colors`,x.status===`connected`?`border-border/70 text-success hover:bg-accent/60`:x.status===`error`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border/50 text-muted-foreground/40 hover:text-muted-foreground hover:bg-accent/60`),title:C,"aria-label":C,"data-testid":`hq-status-button`,children:(0,Z.jsx)(Kt,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`span`,{role:`status`,"aria-label":f?`Connected`:`Disconnected`,className:K(`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60`,f?`text-success`:`text-warning`),title:f?`Connected`:`Disconnected`,"data-testid":`ws-status-indicator`,children:f?(0,Z.jsx)(Tn,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Lt,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:s(`activity:topbar.settings`),children:(0,Z.jsx)(bt,{className:`h-3.5 w-3.5`})})]})]})})]})}var tE=(0,X.lazy)(()=>La(()=>import(`./CronJobsPanel-B9X-N_ft.js`).then(e=>({default:e.CronJobsPanel})),__vite__mapDeps([66,1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,0,15,16,17,20,21,22,27]))),nE=(0,X.lazy)(()=>La(()=>import(`./ProcessMonitor-Btj6_6aw.js`).then(e=>({default:e.ProcessMonitor})),__vite__mapDeps([62,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,27]))),rE=(0,X.lazy)(()=>La(()=>import(`./QueuePanel-CSlu_Hat.js`).then(e=>({default:e.QueuePanel})),__vite__mapDeps([67,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,27])));function iE(){let{t:e}=W(),{theme:t}=Fg(),n=Ru(),{currentView:r,sidebarOpen:i,toggleSidebar:a,setSearchOpen:o,setSidebarOpen:s,setInspectorTab:c,setPaletteOpen:l,setShortcutsOpen:u,setModelSwitcherOpen:d,setPromptLibraryOpen:f,toggleInspector:p,setFleetMonitorOpen:m,setAgentsMonitorOpen:h,processMonitorOpen:g,setProcessMonitorOpen:_,queuePanelOpen:v,setQueuePanelOpen:y,cronJobsOpen:b,setCronJobsOpen:x,setTerminalOpen:C}=q(Yr(e=>({currentView:e.currentView,sidebarOpen:e.sidebarOpen,toggleSidebar:e.toggleSidebar,setSearchOpen:e.setSearchOpen,setSidebarOpen:e.setSidebarOpen,setInspectorTab:e.setInspectorTab,setPaletteOpen:e.setPaletteOpen,setShortcutsOpen:e.setShortcutsOpen,setModelSwitcherOpen:e.setModelSwitcherOpen,setPromptLibraryOpen:e.setPromptLibraryOpen,toggleInspector:e.toggleInspector,setFleetMonitorOpen:e.setFleetMonitorOpen,setAgentsMonitorOpen:e.setAgentsMonitorOpen,processMonitorOpen:e.processMonitorOpen,setProcessMonitorOpen:e.setProcessMonitorOpen,queuePanelOpen:e.queuePanelOpen,setQueuePanelOpen:e.setQueuePanelOpen,cronJobsOpen:e.cronJobsOpen,setCronJobsOpen:e.setCronJobsOpen,setTerminalOpen:e.setTerminalOpen}))),w=J(e=>e.isLoading),T=J(e=>e.messages.length),E=Xe(e=>e.info),D=Xe(e=>e.promptedThisSession);(0,X.useEffect)(()=>{E&&!E.chosen&&E.variants.length!==0&&(T>0||D||Xe.getState().openPicker())},[E,T,D]);let O=H(e=>e.iteration),k=H(e=>e.projectName),A=H(e=>e.session?.title),j=H(e=>e.session?.id),N=Pe()??j,P=q(e=>N?e.sessionNicknames[N]:void 0),F=q(e=>e.sideContextBreakdownOpen),I=q(e=>e.setSideContextBreakdownOpen);M(e=>e.agents),If({setPaletteOpen:l,setSearchOpen:o,setShortcutsOpen:u,setModelSwitcherOpen:d,setPromptLibraryOpen:f,setFleetMonitorOpen:m,setAgentsMonitorOpen:h,setProcessMonitorOpen:_,setQueuePanelOpen:y,setCronJobsOpen:x,setTerminalOpen:C}),(0,X.useEffect)(()=>{typeof window>`u`||(window.location.pathname===`/debug`?Ba(`debug`):window.location.pathname===`/analytics`?Ba(`analytics`):window.location.pathname===`/refresh-debug`&&Ba(`refresh-debug`))},[]),(0,X.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail;q.getState().setCurrentView(`files`);let n=S(V.getState().wsUrl);n&&n.send({type:`files.read`,payload:n.withSession({filePath:t})})};return window.addEventListener(`wrongstack:open-file`,e),()=>window.removeEventListener(`wrongstack:open-file`,e)},[]),(0,X.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=Ue.getState().openFiles.find(e=>e.path===t);if(!n)return;let r=S(V.getState().wsUrl);r&&r.send({type:`files.write`,payload:r.withSession({filePath:t,content:n.content})})};return window.addEventListener(`wrongstack:save-file`,e),()=>window.removeEventListener(`wrongstack:save-file`,e)},[]);let{isMobile:L}=Fu();(0,X.useEffect)(()=>{L&&q.getState().sidebarOpen&&s(!1)},[L,s]);let ee=L&&i;return mf(),Bf(),Rf(),(0,X.useEffect)(()=>{let e=[];if(w){let t=O?` iter ${O.index}${O.max?`/${O.max}`:``}`:``;e.push(`●${t}`)}let t=P?.trim()||A?.trim(),n=k?.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=k||`AI Agent`}},[w,O,k,A,P]),zf({toggleSidebar:a,setSearchOpen:o,toggleInspector:p,setInspectorTab:c}),(0,Z.jsxs)(`div`,{"data-shell":n?`desktop`:`browser`,className:K(`ws-app-root flex min-h-0 min-w-0 overflow-hidden`,n&&`ws-desktop-shell`,t),children:[(0,Z.jsx)(`a`,{href:`#main-content`,className:`sr-only focus:not-sr-only focus:absolute focus:top-2 focus:left-2 focus:z-[100] focus:rounded-md focus:bg-background focus:px-3 focus:py-1.5 focus:text-sm focus:font-medium focus:shadow-lg focus:ring-2 focus:ring-primary`,children:e(`activity:app.skipToContent`)}),r!==`setup`&&(0,Z.jsx)(Gs,{desktopShell:n}),i&&r!==`setup`&&(0,Z.jsx)(jg,{desktopShell:n}),(0,Z.jsxs)(`main`,{id:`main-content`,className:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden bg-background/70`,...ee?{inert:!0}:{},children:[r!==`setup`&&(0,Z.jsx)(eE,{currentView:r,projectName:k,sessionLabel:P||A||N||void 0,isLoading:w,iteration:O??null,onPalette:()=>l(!0),onSettings:()=>Ha(`settings`)}),r!==`setup`&&(0,Z.jsx)(`div`,{className:K(r!==`chat`&&`ws-view-parked`),...r===`chat`?{}:{inert:!0,"aria-hidden":!0},children:(0,Z.jsx)(oh,{})}),r!==`setup`&&(0,Z.jsx)(ap,{}),r!==`setup`&&(0,Z.jsx)(Lg,{}),(0,Z.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:(0,Z.jsx)(VT,{sessionId:N??null,desktopShell:n})})]}),r!==`setup`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.inspector`),children:(0,Z.jsx)(Dm,{})}),N&&(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.workspaceInspector`),children:(0,Z.jsx)(zT,{sessionId:N})})]}),g&&(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.processMonitor`),children:(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(nE,{open:g,onClose:()=>_(!1)})})}),v&&(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.queue`),children:(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(rE,{open:v,onClose:()=>y(!1)})})}),b&&(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.cronJobs`),children:(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(tE,{open:b,onClose:()=>x(!1)})})}),(0,Z.jsx)(Fm,{}),F&&(0,Z.jsx)(hp,{open:F,onClose:()=>I(!1)}),(0,Z.jsx)(Zf,{}),(0,Z.jsx)(Bg,{}),(0,Z.jsx)(Mg,{}),(0,Z.jsx)(tp,{}),(0,Z.jsx)(Zm,{}),(0,Z.jsx)(ip,{}),(0,Z.jsx)(Df,{}),(0,Z.jsx)(ch,{}),(0,Z.jsx)(Ym,{}),(0,Z.jsx)(vp,{}),(0,Z.jsx)(ae,{})]})}function aE(){return(0,Z.jsx)(_p,{children:(0,Z.jsx)(Pg,{defaultTheme:`system`,children:(0,Z.jsx)(iE,{})})})}gs.createRoot(oe(document.getElementById(`root`))).render((0,Z.jsx)(X.StrictMode,{children:(0,Z.jsx)(aE,{})}));export{Cp as A,xs as B,qm as C,sm as D,pm as E,Gf as F,vs as H,Uf as I,hf as L,bp as M,$f as N,Sp as O,rp as P,tc as R,jh as S,mm as T,Ss as V,j_ as _,Cw as a,Fg as b,NC as c,qv as d,Bv as f,uv as g,dv as h,Pw as i,wp as j,Tp as k,Jv as l,mv as m,AT as n,VC as o,zv as p,ET as r,FC as s,MT as t,Yv as u,m_ as v,Km as w,Ph as x,Jg as y,_s as z};
177
+ `).trim();return(0,Z.jsxs)(`div`,{className:`flex gap-3 animate-message thinking-bubble`,"aria-live":`polite`,children:[(0,Z.jsxs)(`div`,{className:`thinking-orb flex-shrink-0`,"aria-hidden":!0,children:[(0,Z.jsx)(`span`,{className:`thinking-orb__ring`}),(0,Z.jsx)(`span`,{className:`thinking-orb__ring thinking-orb__ring--delay`}),(0,Z.jsx)(`span`,{className:`thinking-orb__spark thinking-orb__spark--one`}),(0,Z.jsx)(`span`,{className:`thinking-orb__spark thinking-orb__spark--two`}),(0,Z.jsx)(Jn,{className:`thinking-orb__icon h-4 w-4`})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 max-w-[85%] min-w-0`,children:[(0,Z.jsxs)(`span`,{className:`thinking-label text-xs font-medium text-primary px-1`,children:[(0,Z.jsx)(`span`,{children:e(`chat:thinking`)}),(0,Z.jsxs)(`span`,{className:`thinking-dots`,"aria-hidden":!0,children:[(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{})]})]}),(0,Z.jsxs)(`div`,{className:`thinking-panel rounded-2xl rounded-bl-md px-3 py-2 border text-foreground/80`,children:[(0,Z.jsxs)(`div`,{className:`thinking-wave`,"aria-hidden":!0,children:[(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{}),(0,Z.jsx)(`span`,{})]}),(0,Z.jsx)(`pre`,{className:`thinking-text whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden`,children:n||`…`})]})]})]})}function Hw(e){let{hasMessages:t,autoCollapseInput:n,sessionChanged:r,prevHadMessages:i,prevAutoCollapse:a}=e;return n&&t&&(r||!i||!a)}function Uw(e,t){return typeof e==`function`?e(t):e}function Ww(){let{t:e}=W(),t=J(e=>e.messages),r=J(e=>e.isLoading),i=q(e=>e.sidebarOpen),a=q(e=>e.toggleSidebar),o=q(e=>e.compactMode),{totalTokens:s,startTime:c,lastInputTokens:l,maxContext:u,contextLimitWarning:d,cacheStats:f,iteration:p}=H(Yr(e=>({totalTokens:e.totalTokens,startTime:e.startTime,lastInputTokens:e.lastInputTokens,maxContext:e.maxContext,contextLimitWarning:e.contextLimitWarning,cacheStats:e.cacheStats,iteration:e.iteration}))),m=H(e=>e.session),h=Pe()??m?.id,g=q(e=>h?e.sessionNicknames[h]:void 0),_=q(e=>e.setSessionNickname),v=m?.title,[y,b]=(0,X.useState)(!1),[x,C]=(0,X.useState)(``),w=n(e=>e.entries),T=q(e=>e.chatSwitcherOpen),E=q(e=>e.setChatSwitcherOpen),D=(0,X.useCallback)(e=>{E(Uw(e,q.getState().chatSwitcherOpen))},[E]),O=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(!T)return;let e=e=>{O.current?.contains(e.target)||D(!1)},t=e=>{e.key===`Escape`&&D(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[T]);let{configProvider:k,configModel:A}=V(Yr(e=>({configProvider:e.provider,configModel:e.model}))),j=m?.provider||k,M=m?.model||A,N=(0,X.useRef)(null),P=(0,X.useMemo)(()=>lp(t),[t]),F=(0,X.useRef)(0);F.current=P.length+1;let I=(0,X.useMemo)(()=>{let e=new Map;return P.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},[P]),L=q(e=>e.scrollTarget),ee=G(e=>e.autonomy),R=G(e=>e.groupToolCalls),z=G(e=>e.autoCollapseInput),te=(0,X.useCallback)(e=>{G.getState().set({autonomy:e});try{let t=S();if(typeof t.switchAutonomy==`function`){t.switchAutonomy(e);return}t.send?.({type:`autonomy.switch`,payload:t.withSession?.({mode:e})??{mode:e}})}catch{}},[]),[ne,re]=(0,X.useState)(!1),ie=q(e=>e.chatCheckpointOpen),ae=q(e=>e.setChatCheckpointOpen),oe=(0,X.useCallback)(e=>{ae(Uw(e,q.getState().chatCheckpointOpen))},[ae]),se=q(e=>e.chatMemoryPanelOpen),ce=q(e=>e.setChatMemoryPanelOpen),B=(0,X.useCallback)(e=>{ce(Uw(e,q.getState().chatMemoryPanelOpen))},[ce]),ue=q(e=>e.chatInputCollapsed),de=q(e=>e.setChatInputCollapsed),fe=(0,X.useCallback)(e=>{de(Uw(e,q.getState().chatInputCollapsed))},[de]),pe=(0,X.useRef)(r),me=(0,X.useRef)(t.length>0),he=(0,X.useRef)(h),ge=(0,X.useRef)(z),_e=q(e=>e.chatContextBreakdownOpen),ve=q(e=>e.setChatContextBreakdownOpen),ye=q(e=>e.chatToolStatsOpen),be=q(e=>e.setChatToolStatsOpen),xe=(0,X.useCallback)(e=>{be(Uw(e,q.getState().chatToolStatsOpen))},[be]),Se=q(e=>e.chatContextEditorOpen),Ce=q(e=>e.setChatContextEditorOpen),we=Ml(e=>Object.values(e.contextMemories).filter(e=>e.state!==`exited`).length);(0,X.useEffect)(()=>{let e=()=>B(!0);return window.addEventListener(`open:memory-panel`,e),()=>window.removeEventListener(`open:memory-panel`,e)},[]),(0,X.useEffect)(()=>{let e=()=>ve(!0);return document.addEventListener(`open:context-breakdown`,e),()=>document.removeEventListener(`open:context-breakdown`,e)},[]),(0,X.useEffect)(()=>{let e=()=>Ce(!0);return document.addEventListener(`open:context-editor`,e),()=>document.removeEventListener(`open:context-editor`,e)},[]),(0,X.useEffect)(()=>{let e=()=>fe(!1);return document.addEventListener(`chat:session-end`,e),document.addEventListener(`chat:next-step-countdown`,e),()=>{document.removeEventListener(`chat:session-end`,e),document.removeEventListener(`chat:next-step-countdown`,e)}},[]),(0,X.useEffect)(()=>{pe.current&&!r&&fe(!1),pe.current=r},[r]),(0,X.useEffect)(()=>{let e=t.length>0,n=h!=null&&h!==he.current;!r&&Hw({hasMessages:e,autoCollapseInput:z,sessionChanged:n,prevHadMessages:me.current,prevAutoCollapse:ge.current})&&fe(!0),he.current=h,me.current=e,ge.current=z},[t.length,z,h,r]);let Te=(0,X.useCallback)(()=>{let e=!G.getState().autoCollapseInput;G.getState().set({autoCollapseInput:e}),e||fe(!1)},[]),Ee=u>0&&l>0?Math.min(100,Math.round(l/u*100)):0,[De,Oe]=(0,X.useState)(!0),[ke,Ae]=(0,X.useState)(0),[je,Me]=(0,X.useState)(!1),Ne=(0,X.useRef)(t.length),Fe=(0,X.useCallback)(()=>{let e=N.current;if(!e)return;let t=e.scrollSize-e.scrollOffset-e.viewportSize<120;Oe(t),t&&(Ae(0),Ne.current=J.getState().messages.length),Me(e.scrollOffset>e.viewportSize&&e.scrollSize>e.viewportSize*2.5)},[]),Ie=(0,X.useCallback)(e=>{let t=S();le.getState().openTab(e,{resumeSession:e=>t.resumeSession?.(e)}),D(!1)},[]);(0,X.useEffect)(()=>{let e=N.current;if(e){if(De)e.scrollToIndex(F.current-1,{align:`end`}),Ne.current=t.length;else{let e=t.length-Ne.current;e>0&&Ae(e)}}},[t,De]),(0,X.useEffect)(()=>{Oe(!0),Ae(0),Ne.current=J.getState().messages.length,re(!1),b(!1),requestAnimationFrame(()=>{N.current?.scrollToIndex(F.current-1,{align:`end`})})},[h]),(0,X.useEffect)(()=>{if(!L)return;let e=I.get(L.id);e!==void 0&&N.current?.scrollToIndex(e,{align:`center`,smooth:!0})},[L,I]);let Le=(0,X.useCallback)(()=>{N.current?.scrollToIndex(F.current-1,{align:`end`,smooth:!0}),Oe(!0),Ae(0),Ne.current=J.getState().messages.length},[]),Re=(0,X.useCallback)(()=>{N.current?.scrollToIndex(0,{align:`start`,smooth:!0})},[]),[ze,Be]=(0,X.useState)(null),[Ve,He]=(0,X.useState)(()=>Date.now()),Ue=(0,X.useRef)(null),We=t[t.length-1],Ge=We?.role===`assistant`&&We.streaming&&We.content?We:null;(0,X.useEffect)(()=>{if(Ge){let e=Ue.current;(!e||e.id!==Ge.id)&&(Ue.current={id:Ge.id,at:Date.now(),len:Ge.content.length})}else Ue.current&&=null},[Ge]);let Ke=(0,X.useMemo)(()=>{let n=t[t.length-1],r=t.filter(e=>e.role===`tool`&&e.toolResult===void 0),i=e(`activity:chatView.thinking`);if(r.length>0){let t=Array.from(new Set(r.map(e=>e.toolName).filter(Boolean))),n=t.slice(0,2).join(`, `),a=t.length>2?` +${t.length-2}`:``;i=r.length===1?e(`activity:chatView.runningTool`,{tool:n||e(`activity:chatView.toolWord`)}):e(`activity:chatView.runningTools`,{count:r.length,preview:`${n}${a}`})}else n?.role===`assistant`&&n.content?i=e(`activity:chatView.writingReply`):n?.role===`tool`&&n.toolResult!==void 0&&(i=e(`activity:chatView.thinkingNextStep`));let a=ze?Math.max(0,Math.floor((Ve-ze)/1e3)):0,o=a<60?`${a}s`:`${Math.floor(a/60)}m ${a%60}s`,s=``;if(Ge){let e=Ue.current;if(e&&e.id===Ge.id){let t=Math.max(1,Ve-e.at),n=Math.max(0,Ge.content.length-e.len);if(t>500&&n>0){let e=n*1e3/t;s=e>=1e3?`${(e/1e3).toFixed(1)}k ch/s`:`${Math.round(e)} ch/s`}}}return{label:i,elapsed:o,speedLabel:s}},[t,Ve,ze,e,Ge]);(0,X.useEffect)(()=>{r&&ze===null&&Be(Date.now()),!r&&ze!==null&&Be(null)},[r,ze]),(0,X.useEffect)(()=>{if(!r)return;let e=setInterval(()=>He(Date.now()),500);return()=>clearInterval(e)},[r]);let qe=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`},Je=(()=>{if(!r)return`idle`;let e=t[t.length-1];return e?.role===`assistant`&&e.content&&e.streaming?`streaming`:`thinking`})();return{messages:t,isLoading:r,sidebarOpen:i,toggleSidebar:a,compactMode:o,totalTokens:s,startTime:c,lastInputTokens:l,maxContext:u,contextLimitWarning:d,cacheStats:f,iteration:p,sessionId:h,nickname:g,sessionTitle:v,renamingTitle:y,setRenamingTitle:b,titleDraft:x,setTitleDraft:C,setSessionNickname:_,historyEntries:w,switcherOpen:T,setSwitcherOpen:D,switcherRef:O,handleHistorySelect:Ie,provider:j,model:M,vlistRef:N,rows:P,autonomy:ee,groupToolCallsPref:R,autoCollapseInput:z,handleAutonomyChange:te,processOpen:ne,setProcessOpen:re,checkpointOpen:ie,setCheckpointOpen:oe,memoryPanelOpen:se,setMemoryPanelOpen:B,inputCollapsed:ue,setInputCollapsed:fe,breakdownOpen:_e,setBreakdownOpen:ve,toolStatsOpen:ye,setToolStatsOpen:xe,editorOpen:Se,setEditorOpen:Ce,activeMemoryCount:we,handleToggleAutoCollapse:Te,ctxPct:Ee,pinnedToBottom:De,unreadCount:ke,scrolledDeep:je,handleScroll:Fe,scrollToBottom:Le,scrollToTop:Re,runningStatus:Ke,formatDuration:qe,agentState:Je,stateTone:Je===`idle`?`bg-muted text-muted-foreground`:Je===`streaming`?`bg-primary/10 text-primary`:`bg-warning/10 text-warning`,hasStatusContent:u>0&&l>0||s.input>0||!!c}}var Gw=(0,X.lazy)(()=>La(()=>import(`./ProcessMonitor-CkAtUjrR.js`).then(e=>({default:e.ProcessMonitor})),__vite__mapDeps([62,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,27])));function Kw(){let{t:e}=W(),t=Ww(),n=Pe(),r=q(e=>e.subagentChatFocusId),i=q(e=>e.setSubagentChatFocus),a=q(e=>e.setSearchOpen),o=v(n??void 0),s=M(e=>r==null?void 0:e.agents.get(r)),l=!s||R(s.sessionId,n),d=!!s&&l,f=r!=null&&d&&r!==o;(0,X.useEffect)(()=>{(pC(r,d)||r!=null&&r===o)&&i(null,n)},[r,d,o,i,n]),(0,X.useEffect)(()=>{f&&a(!1)},[f,a]);let p=V(e=>e.wsStatus),m=t.sessionId,h=A(e=>t.sessionId?e.startedAt[t.sessionId]!==void 0:!1),g=A(e=>t.sessionId?e.progress[t.sessionId]:void 0),_=u(g),y=c(g?.stage);return(0,X.useEffect)(()=>{m&&p.state===`open`&&S().getChimeraReports(m)},[m,p]),(0,Z.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0 bg-[hsl(var(--surface-2)/0.45)]`,children:[(0,Z.jsx)(SC,{sidebarOpen:t.sidebarOpen,toggleSidebar:t.toggleSidebar,agentState:t.agentState,stateTone:t.stateTone,sessionId:t.sessionId,renamingTitle:t.renamingTitle,setRenamingTitle:t.setRenamingTitle,titleDraft:t.titleDraft,setTitleDraft:t.setTitleDraft,nickname:t.nickname,sessionTitle:t.sessionTitle,setSessionNickname:t.setSessionNickname,historyEntries:t.historyEntries,switcherRef:t.switcherRef,switcherOpen:t.switcherOpen,setSwitcherOpen:t.setSwitcherOpen,handleHistorySelect:t.handleHistorySelect,iteration:t.iteration,autonomy:t.autonomy,handleAutonomyChange:t.handleAutonomyChange,memoryPanelOpen:t.memoryPanelOpen,setMemoryPanelOpen:t.setMemoryPanelOpen,activeMemoryCount:t.activeMemoryCount,processOpen:t.processOpen,setProcessOpen:t.setProcessOpen,checkpointOpen:t.checkpointOpen,setCheckpointOpen:t.setCheckpointOpen,toolStatsOpen:t.toolStatsOpen,setToolStatsOpen:t.setToolStatsOpen,hasStatusContent:t.hasStatusContent,lastInputTokens:t.lastInputTokens,ctxPct:t.ctxPct,maxContext:t.maxContext,cacheStats:t.cacheStats,setBreakdownOpen:t.setBreakdownOpen,contextLimitWarning:t.contextLimitWarning,setEditorOpen:t.setEditorOpen,totalTokens:t.totalTokens,startTime:t.startTime,formatDuration:t.formatDuration}),(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(`div`,{className:K(`ws-view-pane relative mx-2 mt-2 flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-xl border border-border/70 bg-card/55 shadow-sm sm:mx-3 lg:mx-4 lg:mt-3`,!f&&`ws-view-parked`),...f?{}:{inert:!0,"aria-hidden":!0},children:(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:f&&r!=null&&(0,Z.jsx)(Bw,{agentId:r},r)})}),(0,Z.jsxs)(`div`,{className:K(`ws-view-pane relative mx-2 mt-2 min-h-0 min-w-0 flex-1 overflow-hidden rounded-xl border border-border/70 bg-card/55 shadow-sm sm:mx-3 lg:mx-4 lg:mt-3`,f&&`ws-view-parked`),...f?{inert:!0,"aria-hidden":!0}:{},children:[(0,Z.jsx)(RS,{}),!t.pinnedToBottom&&(0,Z.jsxs)(`button`,{type:`button`,onClick:t.scrollToBottom,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-md shadow-lg`,`bg-primary text-primary-foreground text-xs font-medium`,`hover:bg-primary/90 transition-colors animate-message`),children:[(0,Z.jsx)(Nr,{className:`h-3.5 w-3.5`}),t.unreadCount>0?`${t.unreadCount} new message${t.unreadCount===1?``:`s`}`:`Jump to latest`]}),t.scrolledDeep&&(0,Z.jsxs)(`button`,{type:`button`,onClick:t.scrollToTop,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-md 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,Z.jsx)(sa,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e(`activity:chatView.top`)})]}),t.rows.length===0&&!t.isLoading?(0,Z.jsx)(`div`,{className:`h-full overflow-y-auto overscroll-contain`,children:(0,Z.jsx)(`div`,{className:`mx-auto max-w-6xl w-full px-3 sm:px-5 lg:px-6 pt-4 pb-8`,children:h?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-16 text-center`,role:`status`,"aria-live":`polite`,children:[(0,Z.jsxs)(`div`,{className:`relative h-12 w-12`,"aria-hidden":`true`,children:[(0,Z.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-muted-foreground/20`}),(0,Z.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-transparent border-t-primary animate-spin`}),(0,Z.jsx)(`div`,{className:`absolute inset-1.5 rounded-full bg-background/80`}),(0,Z.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-[11px] font-semibold tabular-nums text-foreground`,children:_===null?`...`:`${_}%`})]}),(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:e(`activity:chatView.restoringTranscript`)}),(0,Z.jsxs)(`div`,{className:`w-full max-w-sm`,children:[(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-3 text-[11px] text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`truncate`,children:y}),g&&g.totalBytes>0?(0,Z.jsxs)(`span`,{className:`shrink-0 tabular-nums`,children:[ee(g.loadedBytes),` /`,` `,ee(g.totalBytes)]}):(0,Z.jsx)(`span`,{className:`shrink-0 tabular-nums`,children:`reading...`})]}),(0,Z.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full bg-primary transition-[width] duration-200 ease-out`,style:{width:`${_??12}%`}})})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground max-w-sm`,children:e(`activity:chatView.restoringTranscriptHint`)})]}):(0,Z.jsx)(cC,{})})}):(0,Z.jsxs)(En,{ref:t.vlistRef,className:`h-full`,onScroll:t.handleScroll,role:`log`,"aria-label":e(`activity:chatView.chatTranscript`),"aria-live":`polite`,children:[t.rows.map((e,n)=>(0,Z.jsx)(Iw,{row:e,isLoading:t.isLoading,compactMode:t.compactMode,isFirstRow:n===0,groupToolCalls:t.groupToolCallsPref,sessionId:t.sessionId??`__unbound__`},e.key)),(0,Z.jsxs)(`div`,{id:`chat-activity`,className:K(`mx-auto max-w-6xl w-full px-3 sm:px-5 lg:px-6`,t.compactMode?`pb-3`:`pb-8`),children:[(0,Z.jsx)(Vw,{}),t.isLoading&&(0,Z.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,Z.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,Z.jsx)(on,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,Z.jsx)(`div`,{className:`rounded-lg px-4 py-3 bg-card border border-border/70 text-foreground shadow-sm`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,Z.jsxs)(`span`,{className:`flex gap-1`,children:[(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]`}),(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]`}),(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce`})]}),(0,Z.jsx)(`span`,{className:`text-foreground/90`,children:t.runningStatus.label}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:t.runningStatus.elapsed}),t.iteration&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[`· iter `,t.iteration.index,t.iteration.max>0?`/${t.iteration.max}`:``]}),t.runningStatus.speedLabel&&(0,Z.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 tabular-nums`,children:[`· `,t.runningStatus.speedLabel]})]})})})]})]},`__live`)]},t.sessionId??`__unbound__`)]})]}),(0,Z.jsx)(`div`,{className:K(`ws-view-pane shrink-0 bg-[hsl(var(--surface-2)/0.45)] px-2 pb-2 pt-2 sm:px-3 lg:px-4 lg:pb-3`,f&&`ws-view-parked`),...f?{inert:!0,"aria-hidden":!0}:{},children:t.inputCollapsed&&t.messages.length>0?(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 rounded-lg border border-border/60 bg-card/40 px-3 py-1.5 hover:bg-card/70 hover:border-border/80 transition-colors`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>t.setInputCollapsed(!1),className:`flex flex-1 items-center gap-2 text-xs text-muted-foreground/60 hover:text-foreground/80 transition-colors`,children:[(0,Z.jsx)(ut,{className:`h-3.5 w-3.5 shrink-0`}),(0,Z.jsx)(`span`,{children:e(`chat:input.expandInput`,`Expand input`)}),t.rows.length>0&&(0,Z.jsxs)(`span`,{className:`ml-auto tabular-nums text-[10px] text-muted-foreground/40`,children:[t.rows.length,` msgs ·`,` `,op(t.totalTokens.input+t.totalTokens.output)]})]}),t.isLoading&&(0,Z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S().sendAbort(t.sessionId??void 0),J.getState().setLoading(!1)},className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-medium bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,title:e(`chat:input.abortTitle`,`Stop/Abort`),"data-testid":`collapsed-stop`,children:[(0,Z.jsx)(Mr,{className:`h-3 w-3 fill-current`}),(0,Z.jsx)(`span`,{children:e(`common:action.stop`,`Stop`)})]}),(0,Z.jsx)(mC,{label:e(`activity:chatView.autoCollapse`),value:t.autoCollapseInput,onChange:t.handleToggleAutoCollapse})]}):(0,Z.jsxs)(Z.Fragment,{children:[t.messages.length>0&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>t.setInputCollapsed(!0),className:`mb-1 flex w-full items-center gap-1.5 rounded px-2 py-0.5 text-[10px] text-muted-foreground/50 hover:text-muted-foreground/80 transition-colors`,children:[(0,Z.jsx)(gn,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:e(`chat:input.collapseInput`,`Collapse`)})]}),(0,Z.jsx)(FS,{}),(0,Z.jsx)(hC,{hasStatusContent:t.hasStatusContent,totalTokens:t.totalTokens,rowsCount:t.rows.length,iteration:t.iteration,startTime:t.startTime,formatDuration:t.formatDuration,onToggleAutoCollapse:t.handleToggleAutoCollapse}),(0,Z.jsx)(`div`,{className:`ws-chat-input-wrap p-0`,children:(0,Z.jsx)(`div`,{className:`max-w-6xl mx-auto`,children:(0,Z.jsx)(fS,{onOpenBreakdown:()=>t.setBreakdownOpen(!0)})})})]})}),(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(Gw,{open:t.processOpen,onClose:()=>t.setProcessOpen(!1)})}),(0,Z.jsx)(mS,{open:t.checkpointOpen,onClose:()=>t.setCheckpointOpen(!1)}),(0,Z.jsx)(hp,{open:t.breakdownOpen,onClose:()=>t.setBreakdownOpen(!1)}),(0,Z.jsx)(nC,{open:t.toolStatsOpen,onClose:()=>t.setToolStatsOpen(!1)}),(0,Z.jsx)(AS,{open:t.editorOpen,onClose:()=>t.setEditorOpen(!1)}),(0,Z.jsx)(fx,{open:t.memoryPanelOpen,onClose:()=>t.setMemoryPanelOpen(!1)})]})}function qw(){let e=ro(e=>e.info),{client:t}=hf(),n=(0,X.useRef)(null),r=(0,X.useCallback)(()=>{t?.getGitInfo?.()},[t]);return(0,X.useEffect)(()=>(r(),n.current=setInterval(r,3e4),()=>{n.current&&clearInterval(n.current)}),[r]),e}var Jw=new Map,Yw=new Set;k(e=>{Jw.delete(e),Yw.add(e)});function Xw({sessionId:e,className:t}){let{t:n}=W(),[r,i]=(0,X.useState)([]),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(0),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(``),[x,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(``),E=(0,X.useRef)(e),D=V(e=>e.wsUrl),O=S(D),k=J(e=>e.messages).filter(e=>e.role===`tool`&&e.toolResult===void 0&&!!e.toolUseId);(0,X.useLayoutEffect)(()=>{let t=E.current;Yw.has(t)||Jw.set(t,{participants:r,joined:a,joinedRole:s,error:l,openAnnotationCount:d,paused:p,injectOpen:h,injectToolUseId:_,injectContent:y,injectIsError:x,injectReason:w});let n=Jw.get(e);Yw.delete(e),i(n?.participants??[]),o(n?.joined??!1),c(n?.joinedRole??null),u(n?.error??null),f(n?.openAnnotationCount??0),m(n?.paused??!1),g(n?.injectOpen??!1),v(n?.injectToolUseId??``),b(n?.injectContent??``),C(n?.injectIsError??!1),T(n?.injectReason??``),E.current=e},[e]),(0,X.useEffect)(()=>{let t=[];return t.push(O.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&i(n.participants??[])})),t.push(O.on(`collab.participant.joined`,t=>{let n=t.payload;n.sessionId===e&&i(e=>e.some(e=>e.participantId===n.participantId)?e:[...e,{participantId:n.participantId,role:n.role,joinedAt:n.joinedAt}])})),t.push(O.on(`collab.participant.left`,t=>{let n=t.payload;if(n.sessionId!==e)return;let r=n.participantId;i(e=>e.filter(e=>e.participantId!==r))})),t.push(O.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(u(t.message),o(!1))})),t.push(O.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||f(e=>e+1))})),t.push(O.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&f(e=>Math.max(0,e-1))})),t.push(O.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&m(!0)})),t.push(O.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&m(!1)})),()=>{for(let e of t)e()}},[O,e]);let A=(t=`observer`)=>{u(null),O.send({type:`collab.join`,payload:{sessionId:e,role:t}}),o(!0),c(t)},j=()=>{O.send({type:`collab.request_pause`,payload:{sessionId:e}})},M=()=>{O.send({type:`collab.resume`,payload:{sessionId:e}})},N=()=>{O.send({type:`collab.leave`,payload:{sessionId:e}}),o(!1),i([])},P=t=>{O.send({type:`collab.grant_control`,payload:{sessionId:e,toParticipant:t}})},F=()=>{_&&(O.send({type:`collab.inject_tool`,payload:{sessionId:e,toolUseId:_,content:y,isError:x,reason:w.trim()||U.t(`activity:collab.controllerInjection`)}}),g(!1),v(``),b(``),C(!1),T(``))},I=a&&s===`controller`;return r.length===0&&!l?(0,Z.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,Z.jsx)(_t,{className:`w-4 h-4 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n(`activity:collab.noObservers`)}),(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(`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,Z.jsx)(pt,{className:`w-3 h-3`}),n(`activity:collab.observerRole`)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(`annotator`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-warning/40 bg-warning/10 text-warning hover:bg-warning/20 transition-colors`,title:n(`activity:collab.annotatorTitle`),children:[(0,Z.jsx)(kr,{className:`w-3 h-3`}),n(`activity:collab.annotatorRole`)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(`controller`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20 transition-colors`,title:n(`activity:collab.controllerTitle`),children:[(0,Z.jsx)(ct,{className:`w-3 h-3`}),n(`activity:collab.controllerRole`)]})]})]}):l?(0,Z.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,Z.jsx)(`span`,{className:`text-xs text-destructive`,children:n(`activity:collab.errorPrefix`,{error:l})}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{u(null),o(!1)},className:`ml-auto text-xs underline text-destructive`,children:n(`activity:collab.dismiss`)})]}):(0,Z.jsxs)(`div`,{className:K(`relative flex items-center gap-2 px-3 py-2 rounded-md border border-success/40 bg-success/5`,t),children:[(0,Z.jsxs)(`span`,{className:`relative flex h-2 w-2`,role:`img`,"aria-label":n(`common:status.live`),children:[(0,Z.jsx)(`span`,{className:`absolute inline-flex h-full w-full rounded-full bg-success opacity-75 animate-ping`}),(0,Z.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-success`})]}),(0,Z.jsx)(_t,{className:`w-4 h-4 text-success`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium text-success`,children:n(`activity:collab.observers`,{count:r.length})}),d>0&&(0,Z.jsxs)(`span`,{title:n(`activity:collab.annotationsTitle`,{count:d}),className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-warning/15 text-warning border border-warning/30`,children:[(0,Z.jsx)(kr,{className:`w-3 h-3`}),n(`activity:collab.notes`,{count:d})]}),p&&(0,Z.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-destructive/15 text-destructive border border-destructive/40`,children:[(0,Z.jsx)(ct,{className:`w-3 h-3`}),n(`activity:collab.paused`)]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 ml-2`,children:[r.slice(0,3).map(e=>(0,Z.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-success/10 text-success`,children:[(0,Z.jsx)(ja,{className:`w-3 h-3`}),e.role,I&&e.role!==`controller`&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>P(e.participantId),title:n(`activity:collab.grantTitle`),className:`ml-0.5 inline-flex items-center rounded hover:bg-success/20 transition-colors`,children:(0,Z.jsx)(qn,{className:`w-3 h-3`})})]},e.participantId)),r.length>3&&(0,Z.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,r.length-3]})]}),I&&(0,Z.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-info/40 bg-info/10 text-info hover:bg-info/20 transition-colors`,title:n(`activity:collab.injectTitle`),children:[(0,Z.jsx)(oi,{className:`w-3 h-3`}),n(`activity:collab.inject`)]}),p?(0,Z.jsxs)(`button`,{type:`button`,onClick:M,className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20 transition-colors`,title:n(`activity:collab.resumeTitle`),children:[(0,Z.jsx)(tn,{className:`w-3 h-3`}),n(`activity:collab.resume`)]}):(0,Z.jsxs)(`button`,{type:`button`,onClick:j,className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-warning/40 bg-warning/10 text-warning hover:bg-warning/20 transition-colors`,title:n(`activity:collab.pauseTitle`),children:[(0,Z.jsx)(ct,{className:`w-3 h-3`}),n(`activity:collab.pauseAgent`)]})]}),a&&s!==`controller`&&(0,Z.jsxs)(`button`,{type:`button`,onClick:N,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,Z.jsx)(_i,{className:`w-3 h-3`}),n(`activity:collab.leave`)]}),I&&h&&(0,Z.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-info/40 bg-card shadow-lg text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(oi,{className:`w-3.5 h-3.5 text-info`}),(0,Z.jsx)(`span`,{className:`font-medium`,children:n(`activity:collab.injectToolResult`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>g(!1),className:`ml-auto text-muted-foreground hover:text-foreground`,children:n(`activity:collab.close`)})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:collab.targetTool`)}),(0,Z.jsx)(`input`,{list:`collab-inject-tools`,value:_,onChange:e=>v(e.target.value),placeholder:n(`activity:collab.targetPlaceholder`),className:`px-2 py-1 rounded border border-border bg-background font-mono`}),(0,Z.jsx)(`datalist`,{id:`collab-inject-tools`,children:k.map(e=>{let t=e.toolInput===void 0?``:` — ${JSON.stringify(e.toolInput).slice(0,40)}`;return(0,Z.jsxs)(`option`,{value:e.toolUseId,children:[e.toolName??n(`activity:collab.toolFallback`),t]},e.toolUseId)})}),k.length===0&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:n(`activity:collab.noPendingTools`)})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:n(`activity:collab.resultContent`)}),(0,Z.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:3,placeholder:n(`activity:collab.resultPlaceholder`),className:`px-2 py-1 rounded border border-border bg-background font-mono`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsxs)(`label`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>C(e.target.checked)}),(0,Z.jsx)(`span`,{children:n(`activity:collab.markError`)})]}),(0,Z.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,Z.jsxs)(`button`,{type:`button`,onClick:F,disabled:!_,className:`self-end inline-flex items-center gap-1 text-xs px-3 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,Z.jsx)(oi,{className:`w-3 h-3`}),n(`activity:collab.queueInjection`)]})]})]})}var Zw={running:{led:`bg-success led-pulse`,badge:`border-success/30 bg-success/10 text-success`,labelKey:`activity:fleet.statusRunning`},completed:{led:`bg-success`,badge:`border-border bg-muted/40 text-muted-foreground`,labelKey:`activity:fleet.statusDone`},failed:{led:`bg-destructive`,badge:`border-destructive/30 bg-destructive/10 text-destructive`,labelKey:`activity:fleet.statusFailed`},timeout:{led:`bg-warning`,badge:`border-warning/30 bg-warning/10 text-warning`,labelKey:`activity:fleet.statusTimeout`},stopped:{led:`bg-muted-foreground`,badge:`border-border bg-muted text-muted-foreground`,labelKey:`activity:fleet.statusStopped`}};function Qw({className:e}){let{t}=W(),n=M(e=>e.agents),r=Pe(),[i,a]=(0,X.useState)(null),o=(0,X.useMemo)(()=>{let e=Array.from(n.values()).filter(e=>R(e.sessionId,r));return e.sort(w),e},[n,r]),s=(0,X.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(t),a(e),setTimeout(()=>a(null),2e3)}catch{}},[]),c=(0,X.useCallback)(e=>{q.getState().setSubagentChatFocus(e,r??void 0),q.getState().setDockSection(null)},[r]);if(o.length===0)return(0,Z.jsx)(`div`,{className:K(`p-4 text-center text-xs text-muted-foreground`,e),children:t(`activity:agents.noAgentsRunning`)});let l=g(o),u=o.reduce((e,t)=>e+(t.costUsd??0),0);return(0,Z.jsxs)(`div`,{className:K(`flex flex-col gap-3`,e),children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border/70 bg-card/60 px-3 py-2 text-xs backdrop-blur-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(on,{className:`h-4 w-4 text-primary shrink-0`}),(0,Z.jsx)(`span`,{className:`font-semibold`,children:t(`activity:dock.fleet`)}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,o.length,`)`]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[l.running>0&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-medium text-success`,children:[(0,Z.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-success animate-pulse`}),l.running,` `,t(`activity:fleet.statusRunning`)]}),l.completed>0&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[l.completed,` `,t(`activity:fleet.statusDone`)]}),l.failed>0&&(0,Z.jsxs)(`span`,{className:`font-medium text-destructive`,children:[l.failed,` `,t(`activity:fleet.statusFailed`)]}),u>0&&(0,Z.jsx)(`span`,{className:`rounded bg-muted/60 px-1.5 py-0.5 font-mono text-[10px] text-foreground/80`,children:Up(u)})]})]}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:o.map(e=>{let n=Zw[e.status]??Zw.stopped,r=Date.now()-e.startedAt,a=e.description;return(0,Z.jsxs)(`div`,{className:`group flex flex-col gap-2 rounded-lg border border-border/70 bg-card/80 p-3 shadow-xs transition-colors hover:border-primary/40 hover:bg-card`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,Z.jsx)(`span`,{className:K(`h-2 w-2 rounded-full shrink-0`,n.led)}),(0,Z.jsx)(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),(e.provider||e.model)&&(0,Z.jsxs)(`span`,{className:`hidden sm:inline-flex items-center gap-1 rounded bg-muted/60 px-1.5 py-0.5 text-[10px] font-mono text-muted-foreground truncate`,children:[(0,Z.jsx)(On,{className:`h-3 w-3 shrink-0`}),e.model??e.provider]}),(0,Z.jsx)(`span`,{className:K(`rounded-md border px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wider shrink-0`,n.badge),children:t(n.labelKey)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] font-mono text-muted-foreground tabular-nums`,children:[(0,Z.jsx)(la,{className:`h-3 w-3`}),Gp(r)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>c(e.id),className:`inline-flex items-center gap-1 rounded-md border border-primary/30 bg-primary/10 px-2 py-1 text-xs font-medium text-primary hover:bg-primary/20 transition-colors cursor-pointer`,title:`Open subagent chat tab`,children:[(0,Z.jsx)(ka,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:`Chat Tab`})]})]})]}),a?(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground line-clamp-2 leading-relaxed`,children:a}):null,(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-t border-border/40 pt-2 text-[11px]`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:e.status===`running`&&(e.currentTool||e.lastTool)?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-primary font-mono text-[10px] bg-primary/10 px-1.5 py-0.5 rounded truncate`,children:[(0,Z.jsx)(_n,{className:`h-3 w-3 shrink-0 animate-pulse`}),e.currentTool?e.currentTool:`last: ${e.lastTool}`]}):e.error?(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive text-[10px] truncate`,children:[(0,Z.jsx)(qr,{className:`h-3 w-3 shrink-0`}),e.error.message]}):(0,Z.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[`iter `,e.iteration,` · `,e.toolCalls,` tools`]})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 ml-auto`,children:[e.costUsd>0&&(0,Z.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:Up(e.costUsd)}),e.finalText&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>s(e.id,e.finalText),className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted px-1.5 py-0.5 rounded transition-colors cursor-pointer`,title:t(`activity:fleet.copyOutput`),children:[i===e.id?(0,Z.jsx)(xn,{className:`h-3 w-3 text-success`}):(0,Z.jsx)(zr,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{children:i===e.id?t(`common:action.copied`):t(`common:action.copy`)})]})]})]})]},e.id)})})]})}var $w={up:(0,Z.jsx)(sr,{className:`h-3.5 w-3.5 text-success`}),down:(0,Z.jsx)(_r,{className:`h-3.5 w-3.5 text-destructive`}),stable:(0,Z.jsx)(ni,{className:`h-3.5 w-3.5 text-warning`})},eT={active:{color:`text-success`,bg:`bg-success/10`,labelKey:`statusActive`},paused:{color:`text-warning`,bg:`bg-warning/10`,labelKey:`statusPaused`},completed:{color:`text-info`,bg:`bg-info/10`,labelKey:`statusDone`},failed:{color:`text-destructive`,bg:`bg-destructive/10`,labelKey:`statusFailed`},abandoned:{color:`text-muted-foreground`,bg:`bg-muted`,labelKey:`statusAbandoned`}};function tT({goal:e,className:t}){let{t:n}=W(),[r,i]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let e=S();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,X.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&i(!0)},[e]);let a=e?.deliverables??[],o=[...e?.journal??[]].reverse();if(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let s=eT[e.goalState],c=e.deliverables?.filter(e=>e.status===`done`).length??0,l=e.deliverables?.length??0,u=e.progressTrend?$w[e.progressTrend]:null;return(0,Z.jsxs)(`div`,{className:K(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,t),children:[(0,Z.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,Z.jsx)(ki,{className:`h-4 w-4 text-primary`}),(0,Z.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:n(`activity:goal.heading`)}),(0,Z.jsx)(`span`,{className:K(`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium shrink-0`,s.bg,s.color),children:n(`activity:goal.${s.labelKey}`)}),r?(0,Z.jsx)(ui,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Z.jsx)(gn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!r&&(0,Z.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t pt-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-xs text-foreground leading-relaxed whitespace-pre-wrap break-words`,children:e.goal}),e.refinedGoal&&e.refinedGoal!==e.goal&&(0,Z.jsxs)(`div`,{className:`mt-1.5 p-2 rounded bg-accent/40 border border-border/50`,children:[(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground mb-0.5 uppercase tracking-wider font-medium`,children:n(`activity:goal.refined`)}),(0,Z.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap break-words`,children:e.refinedGoal})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground uppercase tracking-wider font-medium`,children:n(`activity:goal.progress`)}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums`,children:[u,(0,Z.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.progress,`%`]})]})]}),(0,Z.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,Z.jsx)(`div`,{className:K(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-success`:e.progress>=50?`bg-warning`:`bg-primary`),style:{width:`${e.progress>0?Math.max(2,e.progress):0}%`}})}),e.progressNote&&(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:e.progressNote})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Z.jsx)(la,{className:`h-3 w-3`}),(0,Z.jsx)(`span`,{className:`tabular-nums font-medium`,children:e.iterations}),(0,Z.jsx)(`span`,{children:n(`activity:goal.iterations`)}),e.lastStatus&&(0,Z.jsx)(`span`,{className:`text-border`,children:`·`}),e.lastStatus&&(0,Z.jsx)(`span`,{className:`truncate`,children:e.lastStatus})]}),l>0&&(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:[(0,Z.jsx)(`span`,{children:n(`activity:goal.deliverables`)}),(0,Z.jsxs)(`span`,{className:`tabular-nums`,children:[c,`/`,l]})]}),(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:a.map(e=>(0,Z.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px]`,children:[e.status===`done`?(0,Z.jsx)(Bn,{className:`h-3 w-3 text-success mt-0.5 shrink-0`}):(0,Z.jsx)(Qr,{className:`h-3 w-3 text-muted-foreground/70 mt-0.5 shrink-0`}),(0,Z.jsx)(`span`,{className:K(`leading-snug`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground`),children:e.text})]},e.id))})]}),o.length>0&&(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:n(`activity:goal.recentActivity`)}),(0,Z.jsx)(`div`,{className:`space-y-1`,children:o.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{className:`font-mono tabular-nums shrink-0 text-foreground/60`,children:[`#`,e.iteration]}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.task||e.status||e.progressNote||`…`})]},`${e.iteration}-${t}`))})]})]})]})}var nT={in_progress:0,pending:1,completed:2},rT=`__no_session__`,iT=new Map,aT=new Set;k(e=>{iT.delete(e),aT.add(e)});function oT(){let{t:e}=W(),t=H(e=>e.todos),n=Pe(),[r,i]=(0,X.useState)(new Set),a=S(),o=(0,X.useRef)(n??rT);(0,X.useLayoutEffect)(()=>{aT.has(o.current)||iT.set(o.current,new Set(r));let e=n??rT;aT.delete(e),i(new Set(iT.get(e)??[])),o.current=e},[n]),(0,X.useEffect)(()=>{n&&a.send({type:`todos.get`,payload:{sessionId:n}})},[n,a]);let s=(0,X.useCallback)(e=>{a.removeTodo(e)},[a]),c=(0,X.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)=>(nT[e.status]??9)-(nT[t.status]??9)),u=l.filter(e=>e.status===`completed`).length,d=l.filter(e=>e.status===`in_progress`),f=l.filter(e=>e.status===`pending`),p=l.filter(e=>e.status===`completed`),m=p.length>0,h=r.has(`completed`),g=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=t=>{let n=t.status===`in_progress`&&t.activeForm?t.activeForm:t.content,r=t.status===`in_progress`,i=t.status===`completed`,a=!!(t.kanbanBoardId&&t.kanbanTaskId),o=!r&&!(a&&i);return(0,Z.jsxs)(`div`,{className:K(`relative px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors`,o&&`hover:bg-accent/40`,r?`bg-warning/8`:i?`bg-success/5`:`bg-background`),children:[o&&(0,Z.jsx)(`button`,{type:`button`,className:`absolute inset-0 cursor-pointer`,"aria-label":e(`activity:todos.toggleAria`,{content:t.content}),onClick:()=>c(t)}),(0,Z.jsx)(`span`,{className:`pointer-events-none relative mt-0.5 shrink-0`,children:i?(0,Z.jsx)(Bn,{className:`w-3.5 h-3.5 text-success`}):r?(0,Z.jsx)(la,{className:`w-3.5 h-3.5 text-warning animate-spin`}):(0,Z.jsx)(Qr,{className:K(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/65 group-hover:text-success`)})}),(0,Z.jsxs)(`span`,{className:K(`pointer-events-none relative leading-snug flex-1 min-w-0`,r?`text-warning font-medium`:i?`text-muted-foreground line-through`:`text-foreground/80`),children:[n,t.blockedBy?.length?(0,Z.jsx)(`span`,{className:`mt-0.5 block text-[11px] text-destructive`,children:e(`activity:todos.blockedBy`,{work:t.blockedBy.join(`; `)})}):null]}),!a&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>s(t.id),className:`relative 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,Z.jsx)(jn,{className:`w-3 h-3 text-muted-foreground`})})]},t.id)};return t.length===0?null:(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Z.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:e(`activity:work.todos`)}),(0,Z.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,t.length]})]}),d.length>0&&(0,Z.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:d.map(_)}),f.length>0&&(0,Z.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:f.map(_)}),m&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>g(`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,Z.jsxs)(`span`,{className:`tabular`,children:[h?`▶`:`▼`,` `,e(`activity:todos.completedCount`,{count:p.length})]})}),!h&&p.map(_)]})]})}var sT={pending:{icon:(0,Z.jsx)(Qr,{className:`w-3.5 h-3.5`}),labelKey:`statusPending`,color:`text-muted-foreground/70`},in_progress:{icon:(0,Z.jsx)(la,{className:`w-3.5 h-3.5 animate-spin`}),labelKey:`statusInProgress`,color:`text-warning`},blocked:{icon:(0,Z.jsx)(ct,{className:`w-3.5 h-3.5`}),labelKey:`statusBlocked`,color:`text-warning`},failed:{icon:(0,Z.jsx)(qr,{className:`w-3.5 h-3.5`}),labelKey:`statusFailed`,color:`text-destructive`},review:{icon:(0,Z.jsx)(Xt,{className:`w-3.5 h-3.5`}),labelKey:`statusReview`,color:`text-info`},completed:{icon:(0,Z.jsx)(Bn,{className:`w-3.5 h-3.5`}),labelKey:`statusDone`,color:`text-success`}},cT={critical:`text-destructive`,high:`text-warning`,medium:`text-warning/85`,low:`text-muted-foreground`},lT={feature:`⚡`,bugfix:`🐛`,refactor:`♻️`,docs:`📝`,test:`🧪`,chore:`🔧`},uT=`__no_session__`,dT=new Map,fT=new Set;k(e=>{dT.delete(e),fT.add(e)});function pT(){let{t:e}=W(),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(new Set),a=S(),o=Pe(),s=(0,X.useRef)(o??uT);(0,X.useLayoutEffect)(()=>{fT.has(s.current)||dT.set(s.current,new Set(r));let e=o??uT;fT.delete(e),i(new Set(dT.get(e)??[])),s.current=e},[o]),up(`tasks.updated`,e=>{let t=e.payload;t?.sessionId&&o&&t.sessionId!==o||t?.tasks&&n(t.tasks)},{sessionId:o,deps:[o]}),(0,X.useEffect)(()=>{n([]),a.getTasks()},[o,a]);let c=(0,X.useCallback)(e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),l=(0,X.useCallback)((e,t)=>{a.updateTaskStatus(e,t)},[a]),u=[`in_progress`,`blocked`,`review`,`pending`,`failed`,`completed`],d=[...t].sort((e,t)=>u.indexOf(e.status)-u.indexOf(t.status)),f=new Map;for(let e of d){let t=f.get(e.status)??[];t.push(e),f.set(e.status,t)}let p=t.filter(e=>e.status===`completed`).length;return t.length===0?null:(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Z.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:e(`activity:work.tasks`)}),(0,Z.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[p,`/`,t.length]})]}),u.map(t=>{let n=f.get(t);if(!n||n.length===0)return null;let i=sT[t],a=r.has(t);return(0,Z.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>c(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,Z.jsxs)(`span`,{className:`tabular`,children:[a?`▶`:`▼`,` `,n.length,` `,e(`activity:task.${i.labelKey}`)]})}),!a&&n.map(t=>(0,Z.jsxs)(`div`,{className:K(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,t.status===`in_progress`?`bg-warning/8`:``),children:[(0,Z.jsx)(`span`,{className:K(`mt-0.5 shrink-0`,i.color),children:i.icon}),(0,Z.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,Z.jsxs)(`span`,{className:K(t.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[lT[t.type],` `,t.title]}),t.priority!==`medium`&&(0,Z.jsx)(`span`,{className:K(`ml-1 text-[10px]`,cT[t.priority]),children:t.priority}),t.assignee&&(0,Z.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,t.assignee]}),t.estimateHours&&(0,Z.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[t.estimateHours,`h`]})]}),(0,Z.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,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(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,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(t.id,`completed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-success/15 text-success hover:bg-success/25 transition-colors`,title:e(`activity:task.completeTitle`),children:e(`activity:task.statusDone`)}),t.status!==`completed`&&t.status!==`failed`&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(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 mT={open:{icon:(0,Z.jsx)(Qr,{className:`w-3.5 h-3.5`}),labelKey:`statusOpen`,color:`text-muted-foreground/70`},in_progress:{icon:(0,Z.jsx)(la,{className:`w-3.5 h-3.5 animate-spin`}),labelKey:`statusInProgress`,color:`text-warning`},done:{icon:(0,Z.jsx)(Bn,{className:`w-3.5 h-3.5`}),labelKey:`statusDone`,color:`text-success`}},hT=`__no_session__`,gT=new Map,_T=new Set;k(e=>{gT.delete(e),_T.add(e)});function vT(){let{t:e}=W(),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(new Set),a=S(),o=Pe(),s=(0,X.useRef)(o??hT);(0,X.useLayoutEffect)(()=>{_T.has(s.current)||gT.set(s.current,new Set(r));let e=o??hT;_T.delete(e),i(new Set(gT.get(e)??[])),s.current=e},[o]),(0,X.useEffect)(()=>{n([]),a.getPlan();let e=a.on(`plan.updated`,e=>{let t=e?.payload;t?.sessionId&&o&&t.sessionId!==o||t?.plan?.items&&n(t.plan.items)});return()=>{e()}},[o,a]);let c=(0,X.useCallback)(e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),l=(0,X.useCallback)((e,t)=>{a.updatePlanItem(e.id,t)},[a]),u=[`in_progress`,`open`,`done`],d=[...t].sort((e,t)=>u.indexOf(e.status)-u.indexOf(t.status)),f=new Map;for(let e of d){let t=f.get(e.status)??[];t.push(e),f.set(e.status,t)}let p=t.filter(e=>e.status===`done`).length;return t.length===0?null:(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Z.jsxs)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:[`📋 `,e(`activity:work.plan`)]}),(0,Z.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[p,`/`,t.length]})]}),u.map(t=>{let n=f.get(t);if(!n||n.length===0)return null;let i=mT[t],a=r.has(t);return(0,Z.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>c(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,Z.jsxs)(`span`,{className:`tabular`,children:[a?`▶`:`▼`,` `,n.length,` `,e(`activity:plan.${i.labelKey}`)]})}),!a&&n.map(t=>(0,Z.jsxs)(`div`,{className:K(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,t.status===`in_progress`?`bg-warning/8`:``),children:[(0,Z.jsx)(`span`,{className:K(`mt-0.5 shrink-0`,i.color),children:i.icon}),(0,Z.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,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[t.status===`open`&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(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,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(t,`done`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-success/15 text-success hover:bg-success/25 transition-colors`,title:e(`activity:plan.doneTitle`),children:e(`activity:plan.statusDone`)}),t.status===`done`&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l(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 yT=[{id:`todos`,labelKey:`work.todos`,icon:`✅`},{id:`tasks`,labelKey:`work.tasks`,icon:`📋`},{id:`plan`,labelKey:`work.plan`,icon:`🗺️`}];function bT(){let{t:e}=W(),t=q(e=>e.workDashboardTab),n=q(e=>e.setWorkDashboardTab);return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:yT.map(r=>(0,Z.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,Z.jsx)(`span`,{className:`text-xs`,children:r.icon}),e(`activity:${r.labelKey}`)]},r.id))}),(0,Z.jsx)(`div`,{className:K(t===`todos`?`block`:`hidden`),children:(0,Z.jsx)(oT,{})}),(0,Z.jsx)(`div`,{className:K(t===`tasks`?`block`:`hidden`),children:(0,Z.jsx)(pT,{})}),(0,Z.jsx)(`div`,{className:K(t===`plan`?`block`:`hidden`),children:(0,Z.jsx)(vT,{})})]})}var xT={primary:`hsl(var(--primary))`,info:`hsl(var(--info))`,success:`hsl(var(--success))`,warning:`hsl(var(--warning))`,destructive:`hsl(var(--destructive))`,muted:`hsl(var(--muted-foreground))`,foreground:`hsl(var(--foreground))`},ST=[xT.primary,xT.info,xT.success,xT.warning,xT.destructive,xT.muted],CT=e=>e.replace(/^wstack\/ap\//,``);function wT(e){return[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt).map((e,t)=>({handle:e,color:ST[t%ST.length],y:60+t*48}))}var TT={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 ET({worktrees:e,baseBranch:t}){let{t:n}=W(),r=wT(e),i=Math.max(120,60+r.length*48+20);return(0,Z.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-border/70 bg-card/70 p-3`,children:(0,Z.jsxs)(`svg`,{width:`100%`,height:i,viewBox:`0 0 600 ${i}`,className:`min-w-[420px]`,role:`img`,"aria-label":n(`activity:worktree.graphAria`,{base:t||`HEAD`}),children:[(0,Z.jsx)(`title`,{children:n(`activity:worktree.graphAria`,{base:t||`HEAD`})}),(0,Z.jsx)(`line`,{x1:40,y1:20,x2:40,y2:i-10,stroke:xT.primary,strokeWidth:3}),(0,Z.jsx)(`text`,{x:36,y:14,style:{fontSize:wo(11)},fill:xT.muted,children:t||`HEAD`}),(0,Z.jsx)(`circle`,{cx:40,cy:20,r:5,fill:xT.primary}),r.map(e=>{let r=TT[e.handle.status]??oe(TT.active),i=e.handle.status===`merged`,a=e.handle.status===`needs-review`||e.handle.status===`failed`;return(0,Z.jsxs)(`g`,{className:`transition-all duration-500`,children:[(0,Z.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:r.dash,opacity:r.opacity}),i?(0,Z.jsx)(`path`,{d:`M 220 ${e.y} C 160 ${e.y+20}, 100 ${e.y+24}, 40 ${e.y+24}`,fill:`none`,stroke:xT.success,strokeWidth:2,opacity:.9}):null,(0,Z.jsx)(`circle`,{cx:220,cy:e.y,r:5,fill:a?xT.destructive:e.color}),(0,Z.jsx)(`text`,{x:232,y:e.y-6,style:{fontSize:wo(12),fontFamily:`var(--font-mono)`},fill:xT.foreground,children:CT(e.handle.branch)}),(0,Z.jsx)(`text`,{x:232,y:e.y+10,style:{fontSize:wo(10)},fill:xT.muted,children:a?`⚠ ${e.handle.status}`:i?n(`activity:worktree.mergedLabel`,{base:t}):`+${e.handle.insertions}/-${e.handle.deletions} · ${e.handle.ownerLabel}`})]},e.handle.handleId)})]})})}var DT={allocating:{icon:`○`,labelKey:`statusAllocating`,tint:`border-muted-foreground/40`,dot:`bg-muted-foreground`},active:{icon:`●`,labelKey:`statusActive`,tint:`border-warning/40`,dot:`bg-warning animate-pulse`},committing:{icon:`◐`,labelKey:`statusCommitting`,tint:`border-primary/40`,dot:`bg-primary animate-pulse`},merging:{icon:`⇡`,labelKey:`statusMerging`,tint:`border-info/40`,dot:`bg-info animate-pulse`},merged:{icon:`✓`,labelKey:`statusMerged`,tint:`border-success/40`,dot:`bg-success`},"needs-review":{icon:`⚠`,labelKey:`statusConflict`,tint:`border-destructive/50`,dot:`bg-destructive`},failed:{icon:`✗`,labelKey:`statusFailed`,tint:`border-destructive/50`,dot:`bg-destructive`}};function OT(e){return DT[e]??{icon:`?`,labelKey:``,tint:`border-border`,dot:`bg-muted-foreground`}}var kT=e=>e.replace(/^wstack\/ap\//,``);function AT({worktrees:e,baseBranch:t}){let{t:n}=W(),r=[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt);return(0,Z.jsxs)(`div`,{className:`rounded-lg border bg-card/50 backdrop-blur-sm px-3 py-3`,children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Z.jsx)(`span`,{className:`font-semibold tracking-wide uppercase text-[10px]`,children:n(`activity:worktree.lanesHeading`)}),(0,Z.jsxs)(`span`,{className:`opacity-60`,children:[`· `,n(`activity:worktree.base`)]}),(0,Z.jsx)(`code`,{className:`font-mono text-primary`,children:t||`HEAD`}),(0,Z.jsxs)(`span`,{className:`opacity-60`,children:[`· `,n(`activity:worktree.isolatedCount`,{count:r.length})]})]}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>{let t=OT(e.status),r=e.status===`needs-review`,i=Math.min(100,e.insertions+e.deletions);return(0,Z.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,Z.jsx)(`span`,{className:K(`h-2.5 w-2.5 shrink-0 rounded-full`,t.dot),"aria-hidden":!0}),(0,Z.jsx)(`code`,{className:`w-44 shrink-0 truncate font-mono text-sm`,children:kT(e.branch)}),(0,Z.jsxs)(`span`,{className:`shrink-0 rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:[`⟵ `,e.ownerLabel]}),r?(0,Z.jsx)(`span`,{className:`font-mono text-xs font-bold text-destructive`,children:n(`activity:worktree.conflictBadge`)}):(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-xs transition-all duration-500`,children:[(0,Z.jsxs)(`span`,{className:`text-success`,children:[`+`,e.insertions]}),(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,Z.jsxs)(`span`,{className:`text-destructive`,children:[`-`,e.deletions]}),(0,Z.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[e.files,`f`]})]}),(0,Z.jsx)(`div`,{className:`ml-auto hidden h-1 w-24 overflow-hidden rounded-full bg-muted sm:block`,children:(0,Z.jsx)(`div`,{className:`h-full bg-gradient-to-r from-success to-destructive transition-all duration-700`,style:{width:`${i}%`}})}),(0,Z.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,Z.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 jT=e=>e?e.replace(/^wstack\/ap\//,``):``;function MT(){let{t:e}=W(),{client:t}=hf(),n=ho(e=>e.orphans),r=ho(e=>e.canClean),i=ho(e=>e.cleanBlockedReason),a=ho(e=>e.cleanResult),[o,s]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{t?.send?.({type:`worktree.scan`})},[t]),(0,X.useEffect)(()=>{a&&s(!1)},[a]),n.length===0&&!a?null:(0,Z.jsxs)(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-xs`,children:[n.length>0?(0,Z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Z.jsx)(dr,{className:`mt-0.5 h-4 w-4 shrink-0 text-warning`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-warning`,children:e(`activity:worktree.orphanCount`,{count:n.length})}),(0,Z.jsx)(`div`,{className:`mt-0.5 max-h-16 overflow-auto font-mono text-[10px] text-muted-foreground`,children:n.map((e,t)=>(0,Z.jsxs)(`div`,{className:`truncate`,children:[e.kind===`branch`?`⌥ `:`▢ `,jT(e.branch)||e.dir]},`${e.kind}-${e.branch??e.dir??t}`))})]}),(0,Z.jsxs)(`button`,{type:`button`,disabled:!r||o,onClick:async()=>{let r=n.length;await $f({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-warning px-2 py-1 font-medium text-primary-foreground hover:bg-warning/90 disabled:cursor-not-allowed disabled:opacity-50`,children:[o?(0,Z.jsx)(mn,{className:`h-3.5 w-3.5 animate-spin`}):(0,Z.jsx)(Gn,{className:`h-3.5 w-3.5`}),e(`activity:worktree.cleanConfirm`)]})]}):null,a&&(0,Z.jsx)(`div`,{className:a.ok?`mt-1 text-success`:`mt-1 text-destructive`,children:a.ok?e(`activity:worktree.removed`,{count:a.removed}):`✗ ${a.reason??e(`activity:worktree.cleanupFailed`)}`})]})}var NT={goal:{active:`bg-primary/12 border-primary/40 text-primary shadow-sm`,idle:`text-primary/80 hover:bg-primary/10`},"goal-state":{active:`bg-destructive/10 border-destructive/35 text-destructive shadow-sm`,idle:`text-destructive/80 hover:bg-destructive/10`},fleet:{active:`bg-success/12 border-success/35 text-success shadow-sm`,idle:`text-success/80 hover:bg-success/10`},work:{active:`bg-warning/12 border-warning/35 text-warning shadow-sm`,idle:`text-warning/80 hover:bg-warning/10`},worktrees:{active:`bg-info/12 border-info/35 text-info shadow-sm`,idle:`text-info/80 hover:bg-info/10`},collab:{active:`bg-accent border-primary/25 text-accent-foreground shadow-sm`,idle:`text-muted-foreground hover:bg-muted/60`}},PT={goal:`Goal`,"goal-state":`Goal State`,fleet:`Fleet`,work:`Work`,worktrees:`Worktrees`,collab:`Collab`},FT=[`goal`,`goal-state`,`fleet`,`work`,`worktrees`,`collab`];function IT({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=NT[e],{t:c}=W();return(0,Z.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-md border text-xs font-medium shrink-0 transition-colors`,i?s.active:K(`border-border/40`,s.idle)),children:[(0,Z.jsx)(`span`,{className:K(a&&`animate-pulse`),children:t}),n,r&&(0,Z.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function LT(){let e=q(e=>e.dockSection),{t}=W(),n=q(e=>e.toggleDockSection),r=q(e=>e.hiddenChips),i=q(e=>e.toggleChipHidden),a=q(e=>e.dockCustomizeOpen),o=q(e=>e.setDockCustomizeOpen),s=Pe(),c=to(e=>e.goal),l=_o(e=>e.phases.length),u=_o(e=>e.overallPercent),d=_o(e=>e.activePhaseId),f=ho(e=>e.worktrees),p=H(e=>e.todos),m=M(e=>e.agents),h=qw(),g=(0,X.useMemo)(()=>Array.from(m.values()).filter(e=>R(e.sessionId,s)),[m,s]),_=g.length,v=(0,X.useMemo)(()=>g.filter(e=>e.status===`running`).length,[g]),y=p.filter(e=>e.status===`completed`).length,b=p.some(e=>e.status===`in_progress`),x=l>0,S=(0,X.useMemo)(()=>new Set(r),[r]),C={goal:x,"goal-state":c!==null,fleet:_>0,work:!0,worktrees:f.length>0,collab:!0},w={goal:(C.goal||e===`goal`)&&!S.has(`goal`),"goal-state":(C[`goal-state`]||e===`goal-state`)&&!S.has(`goal-state`),fleet:(C.fleet||e===`fleet`)&&!S.has(`fleet`),work:(C.work||e===`work`)&&!S.has(`work`),worktrees:(C.worktrees||e===`worktrees`)&&!S.has(`worktrees`),collab:(C.collab||e===`collab`)&&!S.has(`collab`)},T=e&&w[e]?e:null;return(0,Z.jsx)(`div`,{children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 rounded-lg border border-border/70 bg-card/70 px-2 py-1.5 shadow-sm`,children:[w.goal&&(0,Z.jsx)(IT,{section:`goal`,icon:(0,Z.jsx)(Pn,{className:`h-3 w-3`}),label:t(`activity:dock.goal`),value:`${u}%`,active:!1,pulse:d!=null,onClick:()=>Ha(`goal`)}),w[`goal-state`]&&c&&(0,Z.jsx)(IT,{section:`goal-state`,icon:(0,Z.jsx)(ki,{className:`h-3 w-3`}),label:t(`activity:dock.goalState`),value:`${c.progress}%`,active:T===`goal-state`,pulse:c.goalState===`active`,onClick:()=>n(`goal-state`)}),w.fleet&&(0,Z.jsx)(IT,{section:`fleet`,icon:(0,Z.jsx)(on,{className:`h-3 w-3`}),label:t(`activity:dock.fleet`),value:`${v}/${_}`,active:T===`fleet`,pulse:v>0,onClick:()=>n(`fleet`)}),(0,Z.jsx)(IT,{section:`work`,icon:(0,Z.jsx)(wn,{className:`h-3 w-3`}),label:t(`activity:dock.work`),value:p.length>0?`${y}/${p.length}`:void 0,active:T===`work`,pulse:b,onClick:()=>n(`work`)}),w.worktrees&&(0,Z.jsx)(IT,{section:`worktrees`,icon:(0,Z.jsx)(jr,{className:`h-3 w-3`}),label:t(`activity:dock.worktrees`),value:String(f.length),active:T===`worktrees`,onClick:()=>n(`worktrees`)}),h&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{},className:`inline-flex h-8 max-w-full min-w-0 items-center gap-1.5 rounded-md border border-border/50 px-2.5 text-xs font-mono transition-colors hover:bg-muted/60 sm:h-7`,children:[(0,Z.jsx)(jr,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,Z.jsx)(`span`,{className:`min-w-0 truncate font-semibold text-foreground`,children:h.branch}),h.ahead>0&&(0,Z.jsxs)(`span`,{className:`text-success`,title:t(`activity:dock.ahead`,{count:h.ahead}),children:[`↑`,h.ahead]}),h.behind>0&&(0,Z.jsxs)(`span`,{className:`text-warning`,title:t(`activity:dock.behind`,{count:h.behind}),children:[`↓`,h.behind]}),h.added>0&&(0,Z.jsxs)(`span`,{className:`text-success`,title:t(`activity:dock.linesAdded`,{count:h.added}),children:[`+`,h.added]}),h.deleted>0&&(0,Z.jsxs)(`span`,{className:`text-destructive`,title:t(`activity:dock.linesDeleted`,{count:h.deleted}),children:[`-`,h.deleted]}),h.untracked>0&&(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,title:t(`activity:dock.untrackedFiles`,{count:h.untracked}),children:[h.untracked,`?`]})]}),(0,Z.jsx)(IT,{section:`collab`,icon:(0,Z.jsx)(_t,{className:`h-3 w-3`}),label:t(`activity:dock.collab`),active:T===`collab`,onClick:()=>n(`collab`)}),(0,Z.jsxs)(_s,{open:a,onOpenChange:o,children:[(0,Z.jsx)(vs,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,title:t(`activity:dock.customizeTitle`),className:`ml-auto inline-flex items-center justify-center h-7 w-7 rounded-md border border-border/50 text-muted-foreground hover:bg-muted/60 transition-colors shrink-0`,children:(0,Z.jsx)(Bi,{className:`h-3 w-3`})})}),(0,Z.jsxs)(xs,{align:`end`,className:`w-44`,children:[(0,Z.jsx)(Ts,{children:t(`activity:dock.dockChips`)}),(0,Z.jsx)(Es,{}),FT.map(e=>(0,Z.jsx)(Cs,{checked:!S.has(e),onCheckedChange:()=>i(e),onSelect:e=>e.preventDefault(),children:PT[e]},e))]})]})]})})}var RT={"goal-state":{titleKey:`activity:dock.goalState`,detailKey:`activity:dock.goalStateDetail`},fleet:{titleKey:`activity:dock.fleet`,detailKey:`activity:dock.fleetDetail`},work:{titleKey:`activity:dock.work`,detailKey:`activity:dock.workDetail`},worktrees:{titleKey:`activity:dock.worktrees`,detailKey:`activity:dock.worktreesDetail`},collab:{titleKey:`activity:dock.collab`,detailKey:`activity:dock.collabDetail`}};function zT({sessionId:e}){let t=q(e=>e.dockSection),n=q(e=>e.setDockSection),r=q(e=>e.inspectorOpen),i=to(e=>e.goal),a=ho(e=>e.worktrees),o=ho(e=>e.baseBranch),[s,c]=(0,X.useState)(`graph`),{t:l}=W(),u=t!==null&&t!==`goal`,d=u?t:null,f=d?RT[d]:null,p=r&&u?`sm:right-[min(680px,48vw)]`:``;return(0,X.useEffect)(()=>{if(!u)return;let e=e=>{e.key===`Escape`&&n(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,n]),(0,Z.jsxs)(`aside`,{id:`workspace-dock-inspector`,"data-testid":u?`workspace-dock-inspector`:void 0,"data-escape-owns":u?`true`:void 0,"aria-hidden":!u,inert:!u||void 0,"aria-label":f?l(`activity:dock.inspectorNamed`,{name:l(f.titleKey)}):l(`activity:dock.inspector`),className:K(`fixed inset-y-0 right-0 z-40 flex w-[calc(100vw-3rem)] max-w-none flex-col overflow-hidden border-l border-border/80 bg-card/96 shadow-[-24px_0_64px_-36px_hsl(var(--shadow-color)/0.65)] backdrop-blur-xl transition-transform duration-200 sm:w-[min(680px,48vw)] sm:max-w-[680px]`,p,u?`translate-x-0`:`pointer-events-none translate-x-full`),children:[(0,Z.jsxs)(`header`,{className:`relative shrink-0 border-b border-border/70 bg-muted/20 px-4 py-3 pr-12`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-foreground`,children:[(0,Z.jsx)(Ai,{className:`h-4 w-4 text-primary`}),l(f?f.titleKey:`activity:dock.workspace`)]}),(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:l(f?f.detailKey:`activity:dock.workspaceDetails`)}),(0,Z.jsx)(`button`,{type:`button`,"data-testid":`workspace-dock-inspector-close`,onClick:()=>n(null),className:`absolute right-3 top-3 inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,"aria-label":l(`activity:dock.closeWorkspaceInspector`),title:l(`activity:dock.closeWorkspaceInspector`),children:(0,Z.jsx)(hn,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain p-3 sm:p-4`,children:[d===`goal-state`&&(i?(0,Z.jsx)(tT,{goal:i}):(0,Z.jsx)(BT,{title:l(`activity:dock.noActiveGoal`),detail:l(`activity:dock.noActiveGoalDetail`)})),d===`fleet`&&(0,Z.jsx)(Qw,{}),d===`worktrees`&&(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,Z.jsx)(`button`,{type:`button`,onClick:()=>c(e),className:K(`rounded-md border px-2.5 py-1 text-xs capitalize transition-colors`,s===e?`border-primary/30 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),(0,Z.jsx)(MT,{}),s===`graph`?(0,Z.jsx)(ET,{worktrees:a,baseBranch:o||`HEAD`}):(0,Z.jsx)(AT,{worktrees:a,baseBranch:o||`HEAD`})]}),(0,Z.jsx)(`div`,{className:K(d===`work`?`block`:`hidden`),id:`panel-work`,children:(0,Z.jsx)(bT,{})}),(0,Z.jsx)(`div`,{className:K(d===`collab`?`block`:`hidden`),children:(0,Z.jsx)(Xw,{sessionId:e})})]})]})}function BT({title:e,detail:t}){return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-border/70 bg-muted/20 px-3 py-2 text-xs`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-foreground`,children:e}),(0,Z.jsx)(`div`,{className:`mt-1 text-muted-foreground`,children:t})]})}function VT({sessionId:e,desktopShell:t}){let{t:n}=W(),{currentView:r,terminalOpen:i,setTerminalOpen:a}=q(Yr(e=>({currentView:e.currentView,terminalOpen:e.terminalOpen,setTerminalOpen:e.setTerminalOpen}))),o=e,s=sx;return(0,Z.jsxs)(Z.Fragment,{children:[o&&(0,Z.jsxs)(`div`,{className:K(`flex flex-col`,r!==`chat`&&`ws-view-parked`),...r===`chat`?{}:{inert:!0,"aria-hidden":!0},children:[(0,Z.jsx)(`div`,{className:`ws-workspace-dock-wrap shrink-0 px-3 pt-2 sm:px-4`,children:(0,Z.jsx)(LT,{})}),(0,Z.jsx)(fC,{})]}),(0,Z.jsx)(`div`,{className:K(`flex min-h-0 min-w-0 flex-1 flex-col`,r!==`chat`&&`ws-view-parked`),...r===`chat`?{}:{inert:!0,"aria-hidden":!0},children:(0,Z.jsx)(_p,{level:`panel`,name:n(`activity:panels.chat`),children:(0,Z.jsx)(Kw,{})})}),r!==`chat`&&(0,Z.jsx)(ox,{view:r,onCloseToChat:s}),i&&(0,Z.jsx)(_p,{level:`panel`,name:n(`activity:panels.terminal`),children:(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(qg,{label:n(`common:loadingNamed`,{name:n(`activity:panels.terminal`)})}),children:(0,Z.jsx)(HT,{desktopShell:t,onClose:()=>a(!1)})})})]})}var HT=(0,X.lazy)(()=>La(()=>import(`./TerminalPanel-CfoKklMj.js`).then(e=>({default:e.TerminalPanel})),__vite__mapDeps([63,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,64,65])));async function UT(e,t){let n=await fetch(`/api/integrations/${e}/status`,{method:`GET`,signal:t,headers:{accept:`application/json`}}),r=await n.json();return{connected:n.ok&&r.connected===!0,...typeof r.latencyMs==`number`?{latencyMs:r.latencyMs}:{},...typeof r.error==`string`?{error:r.error}:{}}}function WT(){let e=G(e=>e.wrongProxyEnabled),t=G(e=>e.wrongProxyUrl),[n,r]=(0,X.useState)(()=>({status:e?`checking`:`disabled`,latencyMs:null,url:t||`http://localhost:3444`}));return(0,X.useEffect)(()=>{if(!e||!t){r({status:`disabled`,latencyMs:null,url:t||`http://localhost:3444`});return}let n=!1,i=async()=>{let e=t.trim().replace(/\/+$/,``),i=Date.now(),a=new AbortController,o=setTimeout(()=>a.abort(),2e3);try{let t=await UT(`wrong-proxy`,a.signal);if(clearTimeout(o),n)return;let s=t.connected;r({status:s?`connected`:`error`,latencyMs:t.latencyMs??Date.now()-i,url:e,error:s?void 0:t.error??`Unreachable`})}catch(t){if(clearTimeout(o),n)return;r({status:`error`,latencyMs:Date.now()-i,url:e,error:t instanceof Error?t.message:`Unreachable`})}};i();let a=setInterval(()=>void i(),1e4);return()=>{n=!0,clearInterval(a)}},[e,t]),n}function GT(){let e=G(e=>e.hqEnabled),t=G(e=>e.hqUrl),n=G(e=>e.hqToken),[r,i]=(0,X.useState)(()=>({status:e&&t?`checking`:`disabled`,latencyMs:null,url:t||``}));return(0,X.useEffect)(()=>{if(!e||!t){i({status:`disabled`,latencyMs:null,url:t||``});return}let n=!1,r=async()=>{let e=t.trim().replace(/\/+$/,``),r=Date.now(),a=new AbortController,o=setTimeout(()=>a.abort(),2e3);try{let t=await UT(`hq`,a.signal);if(clearTimeout(o),n)return;let s=t.connected;i({status:s?`connected`:`error`,latencyMs:t.latencyMs??Date.now()-r,url:e,error:s?void 0:t.error??`Unreachable`})}catch(t){if(clearTimeout(o),n)return;i({status:`error`,latencyMs:Date.now()-r,url:e,error:t instanceof Error?t.message:`Unreachable`})}};r();let a=setInterval(()=>void r(),1e4);return()=>{n=!0,clearInterval(a)}},[e,t,n]),r}function KT(){let e=Ya(e=>e.snapshot),t=q(e=>e.setCronJobsOpen),n=e?.jobs??[],r=n.filter(e=>e.overdue).length,i=n.filter(e=>e.enabled&&!e.overdue).length,a=n.length;return a===0?null:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>t(!0),className:K(`relative inline-flex h-8 items-center gap-1.5 rounded-md border px-2 text-xs transition-colors`,r>0?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/15`:`border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`),title:`${a} cron job${a===1?``:`s`}${r>0?`, ${r} overdue`:``}`,children:[(0,Z.jsx)(Ft,{className:`h-3.5 w-3.5`}),(0,Z.jsxs)(`span`,{className:`hidden lg:inline`,children:[i,`/`,a]}),r>0?(0,Z.jsx)(`span`,{className:`min-w-4 bg-destructive/15 px-1 text-[10px] font-semibold tabular-nums text-destructive`,children:r>99?`99+`:r}):null]})}function qT(e,t){let n=Math.max(0,Date.now()-e),r=Math.floor(n/1e3);if(r<10)return t(`toasts:menu.justNow`,{defaultValue:`Just now`});if(r<60)return t(`toasts:menu.secondsAgo`,{count:r,defaultValue:`${r}s ago`});let i=Math.floor(r/60);if(i<60)return t(`toasts:menu.minutesAgo`,{count:i,defaultValue:`${i}m ago`});let a=Math.floor(i/60);if(a<24)return t(`toasts:menu.hoursAgo`,{count:a,defaultValue:`${a}h ago`});let o=Math.floor(a/24);return t(`toasts:menu.daysAgo`,{count:o,defaultValue:`${o}d ago`})}function JT({variant:e}){return e===`success`?(0,Z.jsx)(xn,{className:`h-4 w-4 text-success shrink-0`}):e===`error`?(0,Z.jsx)(qr,{className:`h-4 w-4 text-destructive shrink-0`}):e===`warn`?(0,Z.jsx)(dr,{className:`h-4 w-4 text-warning shrink-0`}):(0,Z.jsx)(nn,{className:`h-4 w-4 text-info shrink-0`})}function YT({item:e,onMarkAsRead:t,onRemove:n}){let{t:r}=W(),i=(0,X.useMemo)(()=>qT(e.timestamp,r),[e.timestamp,r]),a=(0,X.useMemo)(()=>new Date(e.timestamp).toLocaleString(),[e.timestamp]);return(0,Z.jsxs)(`div`,{role:`menuitem`,tabIndex:0,onClick:()=>{e.read||t()},onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e.read||t())},className:K(`group relative flex items-start gap-2.5 px-3 py-2.5 text-xs transition-colors cursor-pointer outline-none select-none`,`hover:bg-accent/50 focus-visible:bg-accent/60`,e.read?`opacity-85`:`bg-primary/[0.04]`),children:[(0,Z.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:(0,Z.jsx)(JT,{variant:e.variant})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0 pr-1`,children:[(0,Z.jsx)(`div`,{className:K(`whitespace-pre-wrap break-words leading-relaxed text-foreground`,!e.read&&`font-medium`),children:e.message}),(0,Z.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-0.5`,title:a,children:[(0,Z.jsx)(la,{className:`h-3 w-3 opacity-70`}),i]}),e.action&&(0,Z.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),e.action?.onClick(),t()},className:`font-medium text-primary hover:underline`,children:e.action.label})]})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[!e.read&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t()},className:`rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground`,title:r(`toasts:menu.markAsRead`,{defaultValue:`Mark as read`}),"aria-label":r(`toasts:menu.markAsRead`,{defaultValue:`Mark as read`}),children:(0,Z.jsx)(xn,{className:`h-3 w-3`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n()},className:`rounded p-0.5 text-muted-foreground opacity-60 hover:opacity-100 hover:bg-destructive/10 hover:text-destructive transition-opacity`,title:r(`toasts:menu.remove`,{defaultValue:`Remove notification`}),"aria-label":r(`toasts:menu.remove`,{defaultValue:`Remove notification`}),children:(0,Z.jsx)(hn,{className:`h-3 w-3`})}),!e.read&&(0,Z.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary shrink-0`,"aria-label":`Unread indicator`})]})]})}function XT({defaultOpen:e,open:t,onOpenChange:n}={}){let{t:r}=W(),i=N(e=>e.notifications),a=N(e=>e.markAsRead),o=N(e=>e.markAllAsRead),s=N(e=>e.clearAll),c=N(e=>e.removeNotification),[l,u]=(0,X.useState)(`all`),d=(0,X.useMemo)(()=>i.filter(e=>!e.read).length,[i]),f=(0,X.useMemo)(()=>l===`unread`?i.filter(e=>!e.read):i,[i,l]),p=(0,X.useCallback)(()=>{o()},[o]),m=(0,X.useCallback)(()=>{s()},[s]);return(0,Z.jsxs)(_s,{defaultOpen:e,open:t,onOpenChange:n,children:[(0,Z.jsx)(vs,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`notification-menu-trigger`,className:K(`relative inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground`,d>0&&`text-foreground`),title:d>0?`${r(`toasts:menu.title`,{defaultValue:`Notifications`})} (${d} ${r(`toasts:menu.unreadCount`,{count:d,defaultValue:`${d} unread`})})`:r(`toasts:menu.title`,{defaultValue:`Notifications`}),"aria-label":r(`toasts:menu.title`,{defaultValue:`Notifications`}),children:[d>0?(0,Z.jsx)(pr,{className:`h-3.5 w-3.5 text-primary`}):(0,Z.jsx)(rr,{className:`h-3.5 w-3.5`}),d>0&&(0,Z.jsx)(`span`,{"data-testid":`notification-badge`,className:`absolute -top-1 -right-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-destructive px-1 text-[10px] font-bold text-destructive-foreground shadow-sm`,children:d>99?`99+`:d})]})}),(0,Z.jsxs)(xs,{align:`end`,sideOffset:6,className:`w-80 sm:w-96 max-w-[calc(100vw-1rem)] p-0 rounded-xl border border-border/80 bg-card/95 backdrop-blur-xl shadow-2xl overflow-hidden text-card-foreground`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/60 px-3.5 py-2.5 bg-muted/30`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`font-semibold text-xs text-foreground`,children:r(`toasts:menu.title`,{defaultValue:`Notifications`})}),d>0?(0,Z.jsxs)(`span`,{className:`rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary tabular-nums`,children:[d,` `,r(`toasts:menu.tabUnread`,{defaultValue:`Unread`}).toLowerCase()]}):null]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,disabled:d===0,onClick:p,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground disabled:opacity-40 disabled:pointer-events-none`,title:r(`toasts:menu.markAllRead`,{defaultValue:`Mark all as read`}),children:[(0,Z.jsx)(Nt,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{children:r(`toasts:menu.markAllRead`,{defaultValue:`Mark all as read`})})]}),(0,Z.jsxs)(`button`,{type:`button`,disabled:i.length===0,onClick:m,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive disabled:opacity-40 disabled:pointer-events-none`,title:r(`toasts:menu.clearAll`,{defaultValue:`Clear all`}),children:[(0,Z.jsx)(jn,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{children:r(`toasts:menu.clearAll`,{defaultValue:`Clear all`})})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex border-b border-border/50 bg-background/50 px-3 py-1.5 gap-1.5 text-xs`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>u(`all`),className:K(`flex-1 rounded-md px-2.5 py-1 text-center font-medium transition-all`,l===`all`?`bg-accent text-accent-foreground shadow-xs`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[r(`toasts:menu.tabAll`,{defaultValue:`All`}),` (`,i.length,`)`]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>u(`unread`),className:K(`flex-1 rounded-md px-2.5 py-1 text-center font-medium transition-all`,l===`unread`?`bg-accent text-accent-foreground shadow-xs`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[r(`toasts:menu.tabUnread`,{defaultValue:`Unread`}),` (`,d,`)`]})]}),(0,Z.jsx)(`div`,{role:`list`,className:`max-h-[340px] overflow-y-auto divide-y divide-border/30`,"aria-label":r(`toasts:menu.title`,{defaultValue:`Notifications`}),children:f.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center px-4 py-8 text-center text-muted-foreground`,children:[(0,Z.jsx)(Dn,{className:`h-7 w-7 text-muted-foreground/40 mb-2`}),(0,Z.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:l===`unread`&&i.length>0?r(`toasts:menu.allRead`,{defaultValue:`All caught up`}):r(`toasts:menu.empty`,{defaultValue:`No notifications`})}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5 max-w-[220px]`,children:l===`unread`&&i.length>0?r(`toasts:menu.allRead`,{defaultValue:`All caught up`}):r(`toasts:menu.emptyHint`,{defaultValue:`Toasts and system notifications will appear here.`})})]}):f.map(e=>(0,Z.jsx)(YT,{item:e,onMarkAsRead:()=>a(e.id),onRemove:()=>c(e.id)},e.id))})]})]})}function ZT(e){return e.split(`-`).map(e=>e.slice(0,1).toUpperCase()+e.slice(1)).join(` `)}function QT(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${Math.round(e/1024**2)} MB`:e>=1024?`${Math.round(e/1024)} KB`:`${Math.round(e)} B`}function $T(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!1,n=async()=>{try{let n=await fetch(`/debug/system`,{cache:`no-store`});if(!n.ok)return;let r=await n.json();!e&&Number.isFinite(r.memoryUsage?.rss)&&t(r)}catch{}};n();let r=window.setInterval(()=>void n(),5e3);return()=>{e=!0,window.clearInterval(r)}},[]),e}function eE({currentView:e,projectName:t,sessionLabel:n,isLoading:r,iteration:i,onPalette:a,onSettings:o}){let{t:s}=W(),{theme:c,setTheme:l,palette:u,setPalette:d}=Fg(),f=V(e=>e.wsConnected),p=H(e=>e.appVersion),m=H(e=>e.latestVersion),h=H(e=>e.updateAvailable),g=H(e=>e.droppedTools),_=c===`system`?typeof window<`u`&&window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:c,v=(0,X.useCallback)(()=>{l(_===`dark`?`light`:`dark`)},[_,l]),y=q(e=>e.toggleSidebar),b=WT(),x=GT(),S=b.status===`connected`?`WrongProxy: Connected${b.latencyMs==null?``:` (${b.latencyMs}ms)`} · ${b.url}`:b.status===`error`?`WrongProxy: Unreachable · ${b.url}${b.error?` (${b.error})`:``}`:b.status===`checking`?`WrongProxy: Checking · ${b.url}`:`WrongProxy: Disabled`,C=x.status===`connected`?`HQ: Connected${x.latencyMs==null?``:` (${x.latencyMs}ms)`} · ${x.url}`:x.status===`error`?`HQ: Unreachable · ${x.url}${x.error?` (${x.error})`:``}`:x.status===`checking`?`HQ: Checking · ${x.url}`:`HQ: Disabled`,w=$T(),T=w?w.memoryUsage.heapUsed/w.heapLimit:0,E=w?.codebaseIndexServer,D=E?.health,O=D?.server;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-border/70 bg-card/85 px-2.5 py-1.5 shadow-sm backdrop-blur-xl md:hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:y,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,"aria-label":`Toggle navigation menu`,title:`Toggle navigation`,children:(0,Z.jsx)(Rn,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`min-w-0`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`truncate text-xs font-semibold`,children:t||`WrongStack`}),(0,Z.jsx)(`span`,{className:`rounded bg-muted/60 px-1 py-0.5 text-[10px] text-muted-foreground font-mono`,children:ZT(e)}),r&&(0,Z.jsx)(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] font-medium text-primary`,children:(0,Z.jsx)(on,{className:`h-3 w-3 animate-pulse`})})]})})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Z.jsx)(Em,{}),(0,Z.jsx)(XT,{}),(0,Z.jsx)(`button`,{type:`button`,onClick:v,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:_===`dark`?`Switch to light theme`:`Switch to dark theme`,children:_===`dark`?(0,Z.jsx)(Sr,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Vi,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(_s,{children:[(0,Z.jsx)(vs,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:`More options`,"aria-label":`More options`,children:(0,Z.jsx)(zt,{className:`h-3.5 w-3.5`})})}),(0,Z.jsxs)(xs,{align:`end`,className:`w-48`,children:[(0,Z.jsxs)(Ss,{onSelect:a,className:`gap-2`,children:[(0,Z.jsx)(Ji,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:s(`activity:topbar.command`)})]}),(0,Z.jsxs)(Ss,{onSelect:o,className:`gap-2`,children:[(0,Z.jsx)(bt,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{children:s(`activity:topbar.settings`)})]}),(0,Z.jsxs)(`div`,{className:`border-t border-border/60 my-1 px-2 py-1 space-y-1 text-[11px] text-muted-foreground`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{children:`Backend WS`}),(0,Z.jsx)(`span`,{className:K(`font-mono font-medium`,f?`text-success`:`text-warning`),children:f?`Connected`:`Offline`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{children:`WrongProxy`}),(0,Z.jsx)(`span`,{className:K(`font-mono font-medium`,b.status===`connected`?`text-success`:b.status===`error`?`text-destructive`:`text-muted-foreground`),children:b.status===`connected`?`Connected`:b.status===`error`?`Offline`:`Disabled`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{children:`HQ`}),(0,Z.jsx)(`span`,{className:K(`font-mono font-medium`,x.status===`connected`?`text-success`:x.status===`error`?`text-destructive`:`text-muted-foreground`),children:x.status===`connected`?`Connected`:x.status===`error`?`Offline`:`Disabled`})]})]})]})]})]})]}),(0,Z.jsx)(`div`,{className:`hidden shrink-0 border-b border-border/70 bg-card/85 px-3 py-2 shadow-sm backdrop-blur-xl md:block`,children:(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate text-sm font-semibold`,children:t||`WrongStack`}),p?(0,Z.jsxs)(`span`,{className:K(`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 text-[11px] font-medium tabular-nums`,h&&m&&m!==p?`border-warning/40 bg-warning/10 text-warning`:`border-border/70 bg-muted/50 text-muted-foreground`),title:h&&m&&m!==p?`Update available: v${p} → v${m} — run wstack update`:`WrongStack v${p}`,children:[`v`,p,h&&m&&m!==p?(0,Z.jsxs)(`span`,{className:`text-[10px] opacity-80`,children:[`→ v`,m]}):null]}):null,(0,Z.jsx)(`span`,{className:`rounded-md border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:ZT(e)}),(0,Z.jsxs)(`span`,{className:K(`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[11px] font-medium`,r?`bg-primary/10 text-primary`:`bg-muted text-muted-foreground`),children:[r?(0,Z.jsx)(on,{className:`h-3 w-3 animate-pulse`}):(0,Z.jsx)(Wr,{className:`h-3 w-3`}),r?`Running`:`Ready`,i?(0,Z.jsxs)(`span`,{className:`tabular`,children:[i.index,i.max>0?`/${i.max}`:``]}):null]}),(0,Z.jsx)(Em,{showCountWhenZero:!0}),w?(0,Z.jsxs)(`span`,{className:K(`rounded-md border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium tabular-nums`,T>=.85?`text-destructive`:T>=.6?`text-warning`:`text-success`),title:`WebUI server PID ${w.pid} · heap ${QT(w.memoryUsage.heapUsed)} / ${QT(w.heapLimit)}`,children:[`RAM `,QT(w.memoryUsage.rss)]}):null,E?(0,Z.jsxs)(`span`,{className:K(`rounded-md border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium tabular-nums`,E.status===`connected`?`text-success`:E.status===`unresponsive`||E.status===`error`?`text-destructive`:E.status===`degraded`||E.status===`connecting`||E.status===`stopping`?`text-warning`:`text-muted-foreground`),title:[`Codebase index: ${D?.status??E.status}`,E.pid?`PID ${E.pid}`:null,D?.latencyMs==null?null:`RTT ${D.latencyMs}ms`,O?`RAM ${QT(O.memory.rss)}`:null,D?.missedHeartbeats?`missed ${D.missedHeartbeats}`:null].filter(Boolean).join(` · `),children:[`Index `,D?.status??E.status]}):null,g>0?(0,Z.jsxs)(`span`,{className:`rounded-md border border-warning/40 bg-warning/10 px-1.5 py-0.5 text-[11px] font-medium tabular-nums text-warning`,title:`${g} tool(s) dropped from provider requests due to maxTools limit`,children:[`-`,g,` tools`]}):null]}),(0,Z.jsx)(`div`,{className:`mt-0.5 truncate text-[11px] text-muted-foreground`,children:n||`No named session`})]})}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex h-8 items-center gap-1.5 rounded-md border border-border/70 bg-background/60 px-2 text-xs text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:s(`activity:topbar.commandPalette`),children:[(0,Z.jsx)(Ji,{className:`h-3.5 w-3.5`}),s(`activity:topbar.command`)]}),(0,Z.jsx)(`button`,{type:`button`,onClick:v,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:_===`dark`?`Switch to light theme`:`Switch to dark theme`,children:_===`dark`?(0,Z.jsx)(Sr,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Vi,{className:`h-3.5 w-3.5`})}),(0,Z.jsxs)(_s,{children:[(0,Z.jsx)(vs,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:`${s(`settings:general.paletteSwitcherTitle`)}: ${s(me(u).labelKey)}`,"aria-label":`${s(`settings:general.paletteSwitcherTitle`)}: ${s(me(u).labelKey)}`,children:(0,Z.jsx)(Ii,{className:`h-3.5 w-3.5`})})}),(0,Z.jsxs)(xs,{align:`end`,className:`w-56`,children:[(0,Z.jsx)(Ts,{children:s(`settings:general.paletteHeading`)}),ue.map(e=>(0,Z.jsxs)(Ss,{onSelect:()=>d(e.id),className:`gap-2`,children:[(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`h-4 w-4 shrink-0 rounded-[3px] border border-border/70`,style:{background:`linear-gradient(90deg, ${e.swatch} 0 50%, ${e.swatchSecondary} 50% 100%)`}}),(0,Z.jsx)(`span`,{className:`flex-1`,children:s(e.labelKey)}),u===e.id?(0,Z.jsx)(xn,{className:`h-3.5 w-3.5 text-primary`,"aria-hidden":!0}):null]},e.id))]})]}),(0,Z.jsx)(KT,{}),(0,Z.jsx)(XT,{}),(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:K(`inline-flex h-8 w-8 items-center justify-center rounded-md border bg-background/60 transition-colors`,b.status===`connected`?`border-border/70 text-success hover:bg-accent/60`:b.status===`error`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border/50 text-muted-foreground/40 hover:text-muted-foreground hover:bg-accent/60`),title:S,"aria-label":S,"data-testid":`wrongproxy-status-button`,children:(0,Z.jsx)(Cn,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:K(`inline-flex h-8 w-8 items-center justify-center rounded-md border bg-background/60 transition-colors`,x.status===`connected`?`border-border/70 text-success hover:bg-accent/60`:x.status===`error`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border/50 text-muted-foreground/40 hover:text-muted-foreground hover:bg-accent/60`),title:C,"aria-label":C,"data-testid":`hq-status-button`,children:(0,Z.jsx)(Kt,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`span`,{role:`status`,"aria-label":f?`Connected`:`Disconnected`,className:K(`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60`,f?`text-success`:`text-warning`),title:f?`Connected`:`Disconnected`,"data-testid":`ws-status-indicator`,children:f?(0,Z.jsx)(Tn,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(Lt,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{type:`button`,onClick:o,className:`inline-flex h-8 w-8 items-center justify-center rounded-md border border-border/70 bg-background/60 text-muted-foreground hover:bg-accent/60 hover:text-foreground`,title:s(`activity:topbar.settings`),children:(0,Z.jsx)(bt,{className:`h-3.5 w-3.5`})})]})]})})]})}var tE=(0,X.lazy)(()=>La(()=>import(`./CronJobsPanel-LoDmuRHl.js`).then(e=>({default:e.CronJobsPanel})),__vite__mapDeps([66,1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,0,15,16,17,20,21,22,27]))),nE=(0,X.lazy)(()=>La(()=>import(`./ProcessMonitor-CkAtUjrR.js`).then(e=>({default:e.ProcessMonitor})),__vite__mapDeps([62,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,27]))),rE=(0,X.lazy)(()=>La(()=>import(`./QueuePanel-DE9ySxkR.js`).then(e=>({default:e.QueuePanel})),__vite__mapDeps([67,1,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,27])));function iE(){let{t:e}=W(),{theme:t}=Fg(),n=Ru(),{currentView:r,sidebarOpen:i,toggleSidebar:a,setSearchOpen:o,setSidebarOpen:s,setInspectorTab:c,setPaletteOpen:l,setShortcutsOpen:u,setModelSwitcherOpen:d,setPromptLibraryOpen:f,toggleInspector:p,setFleetMonitorOpen:m,setAgentsMonitorOpen:h,processMonitorOpen:g,setProcessMonitorOpen:_,queuePanelOpen:v,setQueuePanelOpen:y,cronJobsOpen:b,setCronJobsOpen:x,setTerminalOpen:C}=q(Yr(e=>({currentView:e.currentView,sidebarOpen:e.sidebarOpen,toggleSidebar:e.toggleSidebar,setSearchOpen:e.setSearchOpen,setSidebarOpen:e.setSidebarOpen,setInspectorTab:e.setInspectorTab,setPaletteOpen:e.setPaletteOpen,setShortcutsOpen:e.setShortcutsOpen,setModelSwitcherOpen:e.setModelSwitcherOpen,setPromptLibraryOpen:e.setPromptLibraryOpen,toggleInspector:e.toggleInspector,setFleetMonitorOpen:e.setFleetMonitorOpen,setAgentsMonitorOpen:e.setAgentsMonitorOpen,processMonitorOpen:e.processMonitorOpen,setProcessMonitorOpen:e.setProcessMonitorOpen,queuePanelOpen:e.queuePanelOpen,setQueuePanelOpen:e.setQueuePanelOpen,cronJobsOpen:e.cronJobsOpen,setCronJobsOpen:e.setCronJobsOpen,setTerminalOpen:e.setTerminalOpen}))),w=J(e=>e.isLoading),T=J(e=>e.messages.length),E=Xe(e=>e.info),D=Xe(e=>e.promptedThisSession);(0,X.useEffect)(()=>{E&&!E.chosen&&E.variants.length!==0&&(T>0||D||Xe.getState().openPicker())},[E,T,D]);let O=H(e=>e.iteration),k=H(e=>e.projectName),A=H(e=>e.session?.title),j=H(e=>e.session?.id),N=Pe()??j,P=q(e=>N?e.sessionNicknames[N]:void 0),F=q(e=>e.sideContextBreakdownOpen),I=q(e=>e.setSideContextBreakdownOpen);M(e=>e.agents),If({setPaletteOpen:l,setSearchOpen:o,setShortcutsOpen:u,setModelSwitcherOpen:d,setPromptLibraryOpen:f,setFleetMonitorOpen:m,setAgentsMonitorOpen:h,setProcessMonitorOpen:_,setQueuePanelOpen:y,setCronJobsOpen:x,setTerminalOpen:C}),(0,X.useEffect)(()=>{typeof window>`u`||(window.location.pathname===`/debug`?Ba(`debug`):window.location.pathname===`/analytics`?Ba(`analytics`):window.location.pathname===`/refresh-debug`&&Ba(`refresh-debug`))},[]),(0,X.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail;q.getState().setCurrentView(`files`);let n=S(V.getState().wsUrl);n&&n.send({type:`files.read`,payload:n.withSession({filePath:t})})};return window.addEventListener(`wrongstack:open-file`,e),()=>window.removeEventListener(`wrongstack:open-file`,e)},[]),(0,X.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=Ue.getState().openFiles.find(e=>e.path===t);if(!n)return;let r=S(V.getState().wsUrl);r&&r.send({type:`files.write`,payload:r.withSession({filePath:t,content:n.content})})};return window.addEventListener(`wrongstack:save-file`,e),()=>window.removeEventListener(`wrongstack:save-file`,e)},[]);let{isMobile:L}=Fu();(0,X.useEffect)(()=>{L&&q.getState().sidebarOpen&&s(!1)},[L,s]);let ee=L&&i;return mf(),Bf(),Rf(),(0,X.useEffect)(()=>{let e=[];if(w){let t=O?` iter ${O.index}${O.max?`/${O.max}`:``}`:``;e.push(`●${t}`)}let t=P?.trim()||A?.trim(),n=k?.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=k||`AI Agent`}},[w,O,k,A,P]),zf({toggleSidebar:a,setSearchOpen:o,toggleInspector:p,setInspectorTab:c}),(0,Z.jsxs)(`div`,{"data-shell":n?`desktop`:`browser`,className:K(`ws-app-root flex min-h-0 min-w-0 overflow-hidden`,n&&`ws-desktop-shell`,t),children:[(0,Z.jsx)(`a`,{href:`#main-content`,className:`sr-only focus:not-sr-only focus:absolute focus:top-2 focus:left-2 focus:z-[100] focus:rounded-md focus:bg-background focus:px-3 focus:py-1.5 focus:text-sm focus:font-medium focus:shadow-lg focus:ring-2 focus:ring-primary`,children:e(`activity:app.skipToContent`)}),r!==`setup`&&(0,Z.jsx)(Gs,{desktopShell:n}),i&&r!==`setup`&&(0,Z.jsx)(jg,{desktopShell:n}),(0,Z.jsxs)(`main`,{id:`main-content`,className:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden bg-background/70`,...ee?{inert:!0}:{},children:[r!==`setup`&&(0,Z.jsx)(eE,{currentView:r,projectName:k,sessionLabel:P||A||N||void 0,isLoading:w,iteration:O??null,onPalette:()=>l(!0),onSettings:()=>Ha(`settings`)}),r!==`setup`&&(0,Z.jsx)(`div`,{className:K(r!==`chat`&&`ws-view-parked`),...r===`chat`?{}:{inert:!0,"aria-hidden":!0},children:(0,Z.jsx)(oh,{})}),r!==`setup`&&(0,Z.jsx)(ap,{}),r!==`setup`&&(0,Z.jsx)(Lg,{}),(0,Z.jsx)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:(0,Z.jsx)(VT,{sessionId:N??null,desktopShell:n})})]}),r!==`setup`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.inspector`),children:(0,Z.jsx)(Dm,{})}),N&&(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.workspaceInspector`),children:(0,Z.jsx)(zT,{sessionId:N})})]}),g&&(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.processMonitor`),children:(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(nE,{open:g,onClose:()=>_(!1)})})}),v&&(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.queue`),children:(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(rE,{open:v,onClose:()=>y(!1)})})}),b&&(0,Z.jsx)(_p,{level:`panel`,name:e(`activity:panels.cronJobs`),children:(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(tE,{open:b,onClose:()=>x(!1)})})}),(0,Z.jsx)(Fm,{}),F&&(0,Z.jsx)(hp,{open:F,onClose:()=>I(!1)}),(0,Z.jsx)(Zf,{}),(0,Z.jsx)(Bg,{}),(0,Z.jsx)(Mg,{}),(0,Z.jsx)(tp,{}),(0,Z.jsx)(Zm,{}),(0,Z.jsx)(ip,{}),(0,Z.jsx)(Df,{}),(0,Z.jsx)(ch,{}),(0,Z.jsx)(Ym,{}),(0,Z.jsx)(vp,{}),(0,Z.jsx)(ae,{})]})}function aE(){return(0,Z.jsx)(_p,{children:(0,Z.jsx)(Pg,{defaultTheme:`system`,children:(0,Z.jsx)(iE,{})})})}gs.createRoot(oe(document.getElementById(`root`))).render((0,Z.jsx)(X.StrictMode,{children:(0,Z.jsx)(aE,{})}));export{Cp as A,xs as B,qm as C,sm as D,pm as E,Gf as F,vs as H,Uf as I,hf as L,bp as M,$f as N,Sp as O,rp as P,tc as R,jh as S,mm as T,Ss as V,j_ as _,Cw as a,Fg as b,NC as c,qv as d,Bv as f,uv as g,dv as h,Pw as i,wp as j,Tp as k,Jv as l,mv as m,AT as n,VC as o,zv as p,ET as r,FC as s,MT as t,Yv as u,m_ as v,Km as w,Ph as x,Jg as y,_s as z};