@openchamber/web 1.13.6 → 1.13.7

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 (26) hide show
  1. package/bin/lib/commands-update.test.js +50 -0
  2. package/dist/assets/{DiagramView-C_f1Il8p.js → DiagramView-BJkP8Fjp.js} +1 -1
  3. package/dist/assets/{MarkdownRendererImpl-BR0DXO9F.js → MarkdownRendererImpl-Nq7bOf31.js} +1 -1
  4. package/dist/assets/{MultiRunWindow-WBqBXcts.js → MultiRunWindow-CRKVePMG.js} +1 -1
  5. package/dist/assets/{NewWorktreeDialog-D7l2VA7o.js → NewWorktreeDialog-Dj6KETex.js} +1 -1
  6. package/dist/assets/{OnboardingScreen-ChaxLu9k.js → OnboardingScreen-DRe8UNiS.js} +1 -1
  7. package/dist/assets/{SessionSwitcherDropdown-xaYa-FIx.js → SessionSwitcherDropdown-Cn_yoQrm.js} +1 -1
  8. package/dist/assets/{SettingsWindow-D5aAKCEM.js → SettingsWindow-BIKNrxSK.js} +1 -1
  9. package/dist/assets/{TerminalView-D8GzsMZF.js → TerminalView-BDjzrhGS.js} +1 -1
  10. package/dist/assets/{index-DxqTiFfR.css → index-Bv4711NQ.css} +1 -1
  11. package/dist/assets/{main-DUn82Iwq.js → main-BByFAmjA.js} +3 -3
  12. package/dist/assets/{main-CLkcy9_q.js → main-BJDsJGkp.js} +2 -2
  13. package/dist/assets/miniChat-Ckr71tB9.js +2 -0
  14. package/dist/assets/mobile-DVDtnIcD.js +2 -0
  15. package/dist/assets/{renderElectronMiniChatApp-BTsP-lHc.js → renderElectronMiniChatApp-CXvtB6Rd.js} +2 -2
  16. package/dist/assets/{renderMobileApp-CSEgabkw.js → renderMobileApp-BVAt5rTM.js} +3 -3
  17. package/dist/assets/{useAppFontEffects-BPhei6aO.js → useAppFontEffects-B66TruVB.js} +111 -111
  18. package/dist/index.html +3 -3
  19. package/dist/mini-chat.html +3 -3
  20. package/dist/mobile.html +3 -3
  21. package/package.json +1 -1
  22. package/server/lib/package-manager.js +2 -2
  23. package/server/lib/package-manager.test.js +13 -1
  24. package/dist/assets/miniChat-Ag1CYNF5.js +0 -2
  25. package/dist/assets/mobile-DtojUfiY.js +0 -2
  26. /package/dist/assets/{index-DJHN0H4h.js → index-AsCHiJ5P.js} +0 -0
@@ -1,4 +1,4 @@
1
- import{ak as gc,e as rt,al as hc,j as t,H as ve,am as fc,an as xc,a as rn,d as ta,p as Br,b as Ur,R as l,L as Ss,ab as bc,ac as yc,aa as vc,ad as jc,a8 as wc,a9 as Nc,ae as kc,ao as Sc,ap as Cc,aq as Pc,u as Ic,l as Dc,n as Ac,w as Ec,C as Mc,S as Rc,ar as Tc,a6 as Fc,D as Oc,q as Lc,as as zc,at as Kc,au as $c,av as Bc,aw as Uc,X as Os,ax as Vc,ay as xn,az as Zr,aA as _c,aB as Hc,aC as Wa,aD as Wc,aE as qc,aF as Gc,aG as ei,aH as Ra,aI as ti,k as Na,aJ as ml,aK as Vr,aL as za,aM as ul,aN as si,aO as Jc,aP as Qc,aQ as Yc,aR as Xc,aS as ni,aT as Oe,aU as aa,aV as Zc,aW as ed,aX as td,aY as sd,aZ as nd,a_ as pl,a7 as ad,a$ as ai,b0 as rd,b1 as id,b2 as od,b3 as ld}from"./vendor-.bun-By2L9XvG.js";import{dy as Ka,r as Ta,v as Fa,m as ce,dz as ka,dA as Sa,dB as Ca,D as is,u as dt,I as A,aw as Pt,ax as It,ay as Dt,dC as cd,au as Ws,a_ as $t,aZ as Bt,aY as Ut,bC as Gt,w as wr,bb as _r,p as mn,at as Cs,t as _,cn as gl,B as J,dD as Dn,dE as dd,dF as md,dj as ud,dG as pd,dH as gd,dI as hd,z as Is,dJ as fd,cR as xd,cS as bd,cT as yd,c2 as vd,ap as us,ar as ps,c3 as jd,as as gs,aS as $a,dK as wd,dL as Sn,aX as _t,bo as Wt,bK as Yt,n as ot,dM as Xn,ao as vs,Q as ut,dg as Nd,bD as Mt,bE as Rt,bF as Kt,bG as Tt,bH as gt,b9 as hs,aT as Hr,dN as un,ba as St,dO as hl,dP as kd,dQ as Sd,dR as Ba,dS as Hs,dT as An,aV as fl,dU as Cn,dV as Cd,dW as Pd,dX as Id,dY as Dd,dZ as Ad,d_ as Ed,d$ as Vs,e0 as Md,q as Ua,c8 as ri,k as Rd,ca as Nr,a3 as xl,E as Td,P as bl,G as yl,cc as Fd,O as ii,c_ as Od,de as vl,d3 as jl,d5 as Ld,e1 as zd,cA as Kd,e2 as oi,e3 as $d,e4 as Bd,e5 as li,e6 as Ud,e7 as Vd,e8 as _d,e9 as Hd,av as Wd,ea as qd,H as Gd,K as Jd,a as Wr,aG as ci,eb as di,ec as mi,aJ as $n,ed as qa,ee as Qd,ef as Yd,ac as En,ab as wl,aa as Xd,eg as Zd,eh as ui,ad as em,ae as tm,a5 as sm,aA as nm,aB as am,aC as Nl,ei as Ga,ej as pi,ek as rm,el as im,em as om,en as lm,d6 as Va,R as _s,eo as cm,cb as kl,ep as dm,eq as mm,er as um,es as pm,et as Ja,eu as gi,ev as gm,ew as hm,ex as fm,ey as xm,ez as bm,eA as Qa,eB as ym,eC as hi,eD as Gn,eE as vm,aP as fi,eF as Nn,aO as jm,eG as wm,eH as xi,eI as bi,X as Ys,F as Nm,S as km,eJ as Sm,cl as ra,bg as kr,bh as Sr,bi as Cr,bj as Pr,bk as Us,bl as Rs,bL as Pn,M as Qn,eK as yi,bX as Cm,eL as Sl,bN as Pm,da as Im,f as Dm,eM as Ya,a2 as Am,b3 as ia,bR as Em,eN as Mm,eO as Rm,d4 as Tm,eP as Fm,eQ as Om}from"./useAppFontEffects-BPhei6aO.js";import{D as Zn,e as yt,o as ws,u as ys,a2 as Lm,a3 as vi,a4 as zm,a5 as Km,w as fs,K as dn,b as Ke,j as sa,f as Ct,a as ea,q as zs,h as ds,a6 as $m,F as Bm,a7 as Xa,E as Um,a8 as ji,a9 as Vm,x as _m,aa as wi,ab as Ni,ac as ki,ad as Si,ae as Za,af as Ci,C as Cl,ag as Hm,ah as Wm,ai as qm,a1 as Gm,L as Jm,aj as Qm,ak as Ym,al as Xm}from"./index-DJHN0H4h.js";import{g as Zm,s as eu}from"./mobileLayoutPreference-Dio-WWkI.js";function tu(){return new Worker(gc,{type:"module"})}const su=["typescript","javascript","tsx","jsx","json","markdown"],Ir={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Pi,Ii;const Di=s=>{const e=Ir[s],n=new hc({workerFactory:tu,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:su,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},nu=s=>{if(!(typeof window>"u"))return s==="split"?(Ii??=Di("split"),Ii):(Pi??=Di("unified"),Pi)},au=s=>{const e=rt.c(7),{children:n,renderTheme:a}=s,r=Dr("unified"),i=Dr("split");let o,d;e[0]!==a||e[1]!==i||e[2]!==r?(o=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:Ir.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:Ir.split.lineDiffType})},d=[a,i,r],e[0]=a,e[1]=i,e[2]=r,e[3]=o,e[4]=d):(o=e[3],d=e[4]),ve.useEffect(o,d);let c;return e[5]!==n?(c=t.jsx(t.Fragment,{children:n}),e[5]=n,e[6]=c):c=e[6],c},Av=s=>{const e=rt.c(11),{children:n}=s,a=Ka();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const x=Ta(!1),m=Ta(!0),p=a?.lightThemeId??x.metadata.id,u=a?.darkThemeId??m.metadata.id;i=a?.availableThemes.find(C=>C.metadata.id===p)??x,r=a?.availableThemes.find(C=>C.metadata.id===u)??m,Fa(i),Fa(r),e[0]=a?.availableThemes,e[1]=a?.darkThemeId,e[2]=a?.lightThemeId,e[3]=r,e[4]=i}else r=e[3],i=e[4];let o;e[5]!==r.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:r.metadata.id},e[5]=r.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const d=o;let c;return e[8]!==n||e[9]!==d?(c=t.jsx(au,{renderTheme:d,children:n}),e[8]=n,e[9]=d,e[10]=c):c=e[10],c},Dr=s=>{const e=rt.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=nu(n),e[0]=n,e[1]=a):a=e[1],a};function ru(s){const e=rt.c(4);let n,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=t.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),a=t.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=a):(n=e[0],a=e[1]);let r;return e[2]!==s?(r=t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...s,children:[n,a]}),e[2]=s,e[3]=r):r=e[3],r}const Oa=ve.forwardRef((s,e)=>{const n=rt.c(11);let a,r;n[0]!==s?({className:a,...r}=s,n[0]=s,n[1]=a,n[2]=r):(a=n[1],r=n[2]);let i;n[3]!==a?(i=ce("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",a),n[3]=a,n[4]=i):i=n[4];let o;n[5]===Symbol.for("react.memo_cache_sentinel")?(o={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=o):o=n[5];let d;n[6]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(fc,{className:ce("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=d):d=n[6];let c;return n[7]!==r||n[8]!==e||n[9]!==i?(c=t.jsx(xc,{className:i,style:o,...r,ref:e,children:d}),n[7]=r,n[8]=e,n[9]=i,n[10]=c):c=n[10],c});Oa.displayName="Switch";const oa=()=>{try{const e=is.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=ws.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[McpConfigStore] Error resolving config directory:",s)}return null},Ai=s=>s?Object.entries(s).map(([e,n])=>({key:e,value:n})):[],Ei=s=>{const e=s.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},la=s=>typeof s!="string"?void 0:s.trim()||void 0,er=800,iu=5e3,ou="__default__",Ar=new Map,tr=new Map,Pl=s=>s?.trim()||ou,sr=s=>{Ar.delete(Pl(s))},Rn=rn()(ta(Br((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=oa(),r=Pl(a),i=Date.now(),o=Ar.get(r)??0,d=e().mcpServers.length>0;if(!n?.force&&d&&i-o<iu)return!0;const c=tr.get(r);if(!n?.force&&c)return c;const x=(async()=>{s({isLoading:!0});try{const m=a?`?directory=${encodeURIComponent(a)}`:"",p=await yt(`/api/config/mcp${m}`,{headers:a?{"x-opencode-directory":a}:void 0});if(!p.ok)throw new Error("Failed to load MCP configs");const u=await p.json();return s({mcpServers:u,isLoading:!1}),Ar.set(r,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),s({isLoading:!1}),!1}})();tr.set(r,x);try{return await x}finally{tr.delete(r)}},createMcp:async n=>{ka("Creating MCP server configuration…");let a=!1;try{const r=Mi(n),i=oa(),o=i?`?directory=${encodeURIComponent(i)}`:"",d=await yt(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(r)}),c=await d.json().catch(()=>null);if(!d.ok)throw new Error(c?.error||"Failed to create MCP server");return sr(i),c?.requiresReload?(a=!0,await Sa({message:c.message,delayMs:c.reloadDelayMs??er,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning})}catch(r){return console.error("[McpConfigStore] Failed to create MCP:",r),{ok:!1}}finally{a||Ca()}},updateMcp:async(n,a)=>{ka("Updating MCP server configuration…");let r=!1;try{const i=Mi(a),o=oa(),d=o?`?directory=${encodeURIComponent(o)}`:"",c=await yt(`/api/config/mcp/${encodeURIComponent(n)}${d}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),x=await c.json().catch(()=>null);if(!c.ok)throw new Error(x?.error||"Failed to update MCP server");return sr(o),x?.requiresReload?(r=!0,await Sa({message:x.message,delayMs:x.reloadDelayMs??er,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:x?.reloadFailed===!0,message:x?.message,warning:x?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:x?.reloadFailed===!0,message:x?.message,warning:x?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||Ca()}},deleteMcp:async n=>{ka("Deleting MCP server configuration…");let a=!1;try{const r=oa(),i=r?`?directory=${encodeURIComponent(r)}`:"",o=await yt(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:r?{"x-opencode-directory":r}:void 0}),d=await o.json().catch(()=>null);if(!o.ok)throw new Error(d?.error||"Failed to delete MCP server");return sr(r),d?.requiresReload&&(a=!0,await Sa({message:d.message,delayMs:d.reloadDelayMs??er,scopes:["all"]})),e().selectedMcpName===n&&s({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}}catch(r){return console.error("[McpConfigStore] Failed to delete MCP:",r),{ok:!1}}finally{a||Ca()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:Ur(()=>Zn()),partialize:s=>({selectedMcpName:s.selectedMcpName})}),{name:"mcp-config-store"}));function Mi(s){const e={};if(s.scope!==void 0&&(e.scope=s.scope),s.type!==void 0&&(e.type=s.type),(s.type==="local"||s.command!==void 0)&&(e.command=(s.command??[]).filter(n=>n.trim())),(s.type==="remote"||s.url!==void 0)&&(e.url=s.url?.trim()??""),s.environment!==void 0&&(e.environment=Ei(s.environment)??{}),s.headers!==void 0&&(e.headers=Ei(s.headers)??{}),s.oauthEnabled!==void 0||s.oauthClientId!==void 0||s.oauthClientSecret!==void 0||s.oauthScope!==void 0||s.oauthRedirectUri!==void 0)if(s.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:la(s.oauthClientId),clientSecret:la(s.oauthClientSecret),scope:la(s.oauthScope),redirectUri:la(s.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:s.oauthEnabled?e.oauth={}:e.oauth=!1}if(s.timeout!==void 0){const n=Number(s.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return s.enabled!==void 0&&(e.enabled=s.enabled),e}const lu={},cu={},Bs=s=>{if(typeof s!="string")return null;const e=s.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},jn=s=>Bs(s)??"__global__",on=s=>{const e=Bs(s);return e?ws.getScopedApiClient(e):ws.getApiClient()},ls=rn()(ta((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=jn(n??ys.getState().currentDirectory);return e().byDirectory[a]??lu},getDiagnosticForDirectory:n=>{const a=jn(n??ys.getState().currentDirectory);return e().diagnosticsByDirectory[a]??cu},getErrorForDirectory:n=>{const a=jn(n??ys.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=Bs(n?.directory??ys.getState().currentDirectory),r=jn(a);n?.silent||s(i=>({loadingKeys:{...i.loadingKeys,[r]:!0},lastErrorKeys:{...i.lastErrorKeys,[r]:null}}));try{const d=(await on(a).mcp.status()).data??{};s(c=>({byDirectory:{...c.byDirectory,[r]:d},diagnosticsByDirectory:{...c.diagnosticsByDirectory,[r]:Object.fromEntries(Object.entries(c.diagnosticsByDirectory[r]??{}).filter(([x])=>!d[x]))},loadingKeys:{...c.loadingKeys,[r]:!1},lastErrorKeys:{...c.lastErrorKeys,[r]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";s(d=>({loadingKeys:{...d.loadingKeys,[r]:!1},lastErrorKeys:{...d.lastErrorKeys,[r]:o}}))}},connect:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory),i=jn(r),o=on(r);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(d){const c=d instanceof Error?d.message:"Connection failed";throw s(x=>({diagnosticsByDirectory:{...x.diagnosticsByDirectory,[i]:{...x.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:c}}}})),d}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory);await on(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory),d=(await on(r).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!d)throw new Error("Authorization URL was not returned");return d},completeAuth:async(n,a,r)=>{const i=Bs(r??ys.getState().currentDirectory);await on(i).mcp.auth.callback({name:n,code:a},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory);await on(r).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},testConnection:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory),i=jn(r),o=on(r),c=e().getStatusForDirectory(r)[n]?.status==="connected";let x,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(C){x=C instanceof Error?C.message:"Connection failed",s(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:x??"Connection failed"}}}}))}await e().refresh({directory:r,silent:!0});const p=e().getStatusForDirectory(r)[n],u=p;if(!c&&p?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(C){m=`Connection test succeeded, but cleanup disconnect failed: ${C instanceof Error?C.message:"Disconnect failed"}`}await e().refresh({directory:r,silent:!0})}return{status:u??e().getStatusForDirectory(r)[n],error:x,warning:m}}}))),du=(s,e)=>{if(!s)return e("mcpDropdown.status.unknown");switch(s.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:s.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:s.error||""});default:return s.status}},mu=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Ev=({active:s,className:e,headerAction:n,listClassName:a,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:o}=dt(),c=ys(N=>N.currentDirectory)??null,x=ls(N=>N.getStatusForDirectory(c)),m=ls(N=>N.refresh),p=ls(N=>N.connect),u=ls(N=>N.disconnect),C=Rn(N=>N.mcpServers),f=Rn(N=>N.loadMcpConfigs),[g,h]=l.useState(!1),[D,k]=l.useState(null);l.useEffect(()=>{m({directory:c,silent:!0})},[m,c]),l.useEffect(()=>{f({force:!0})},[f]),l.useEffect(()=>{s&&Promise.all([m({directory:c,silent:!0}),f({force:!0})])},[s,m,c,f]);const w=l.useMemo(()=>{const N=new Set(Object.keys(x));for(const y of C)y?.name&&N.add(y.name);return Array.from(N).sort((y,b)=>y.localeCompare(b))},[C,x]),E=l.useCallback(N=>{if(N?.preventDefault(),g)return;h(!0);const y=new Promise(b=>setTimeout(b,500));Promise.all([m({directory:c}),y]).finally(()=>{h(!1)})},[g,m,c]);return t.jsxs("div",{className:ce("w-full",e),children:[r?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:t.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:o("mcpDropdown.title")}),c&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:c.split("/").pop()||c})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:g,onClick:E,"aria-label":o("mcpDropdown.actions.refreshAria"),children:t.jsx(A,{name:"refresh",className:ce("h-4 w-4",g&&"animate-spin")})})]})]})}),t.jsxs("div",{className:ce("max-h-64 overflow-y-auto py-2",i&&"space-y-1 py-3",a),children:[w.map(N=>{const y=x[N],b=mu(y),P=y?.status==="connected",z=D===N,M=du(y,o);return t.jsxs("div",{className:ce("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",i?"gap-3 px-4 py-3":"gap-2 px-4 py-1.5"),children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx("span",{className:ce("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",b==="success"&&"bg-status-success",b==="error"&&"bg-status-error",b==="warning"&&"bg-status-warning",b==="default"&&"bg-muted-foreground/40"),"aria-label":M})}),t.jsx(Dt,{side:"left",children:t.jsx("p",{children:M})})]}),t.jsx("span",{className:ce("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:N})]})}),t.jsx(Oa,{checked:P,disabled:z,className:"data-[checked]:bg-status-info",onCheckedChange:async I=>{k(N);try{I?await p(N,c):await u(N,c)}finally{k(null)}}})]},N)}),w.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:o("mcpDropdown.empty.configureInConfig")})]})]})};function uu(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=cd();return s}catch{return"unknown"}}function pu(){const s=typeof window<"u"?window.__VSCODE_CONFIG__?.arch?.toLowerCase?.():void 0;if(s==="arm64"||s==="aarch64")return"arm64";if(s==="x64"||s==="amd64"||s==="x86_64")return"x64";const n=(typeof navigator<"u"?navigator.userAgentData:void 0)?.architecture?.toLowerCase?.();if(n==="arm"||n==="arm64"||n==="aarch64")return"arm64";if(n==="x86"||n==="x64"||n==="amd64")return"x64";const a=typeof navigator<"u"?navigator.userAgent.toLowerCase():"";return a.includes("aarch64")||a.includes("arm64")||a.includes("armv")?"arm64":a.includes("x86_64")||a.includes("x64")||a.includes("amd64")||a.includes("win64")?"x64":"unknown"}function gu(){if(typeof navigator>"u")return"web";const s=(navigator.platform||"").toLowerCase();return s.includes("mac")?"macos":s.includes("win")?"windows":s.includes("linux")?"linux":"web"}function hu(s){const e=Ke.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",uu()),n.set("arch",pu()),n.set("platform",gu()),s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",sa()?"local":"remote"),n):s==="vscode"?(n.set("appType","vscode"),n.set("instanceMode","local"),n):(n.set("appType","web"),n.set("instanceMode","unknown"),n)}async function Ri(s,e){try{const n=hu(s),a=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e||s==="vscode"&&a&&n.set("currentVersion",a);const r=await yt(`/api/openchamber/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!r.ok)throw new Error(`Server responded with ${r.status}`);const i=await r.json();return{available:i.available??!1,version:i.version,currentVersion:i.currentVersion??"unknown",body:i.body,nextSuggestedCheckInSec:typeof i.nextSuggestedCheckInSec=="number"&&Number.isFinite(i.nextSuggestedCheckInSec)?i.nextSuggestedCheckInSec:void 0,packageManager:i.packageManager,updateCommand:i.updateCommand}}catch(n){return console.warn("Failed to check for updates:",n),null}}function fu(){return Km()?"desktop":fs()?"vscode":dn()?"web":null}const Ti={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Il=rn()((s,e)=>({...Ti,checkForUpdates:async()=>{const n=fu();if(!n)return null;s({checking:!0,error:null,runtimeType:n});try{let a=null,r=null;if(n==="desktop"){const i=await vi();return s({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null}),r}else n==="web"?(a=await Ri("web"),r=a?.nextSuggestedCheckInSec??null):n==="vscode"&&(r=(await Ri("vscode"))?.nextSuggestedCheckInSec??null);return s({checking:!1,available:n==="vscode"?!1:a?.available??!1,info:n==="vscode"?null:a,lastChecked:Date.now(),nextCheckInSec:r}),r}catch(a){return s({checking:!1,error:a instanceof Error?a.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:a}=e();if(!(a!=="desktop"||!n)){s({downloading:!0,error:null,progress:null});try{const r=await vi();if(!r?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(s(o=>({info:o.info?{...o.info,...r,body:o.info.body||r.body,available:o.info.available}:r})),!await zm(o=>{s({progress:o})}))throw new Error("Desktop update only works on Local instance");s({downloading:!1,downloaded:!0})}catch(r){s({downloading:!1,error:r instanceof Error?r.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:a}=e();if(!(a!=="desktop"||!n))try{if(!await Lm())throw new Error("Desktop restart only works on Local instance")}catch(r){s({error:r instanceof Error?r.message:"Failed to restart"})}},dismiss:()=>{s({available:!1,downloaded:!1,info:null})},reset:()=>{s(Ti)}})),Fi="https://github.com/btriapitsyn/openchamber/releases";function xu(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(_r(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function bu(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Oi(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function yu(s,e){const n=s.split(".").map(r=>Number.parseInt(r,10)),a=e.split(".").map(r=>Number.parseInt(r,10));for(let r=0;r<3;r+=1){const i=Number.isFinite(n[r])?n[r]:0,o=Number.isFinite(a[r])?a[r]:0;if(i!==o)return o-i}return 0}function vu(s){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let a;for(;(a=e.exec(s))!==null;)n.push({version:a[1]??"",date:a[2]??"",start:a.index});return n.length===0?[]:n.map((r,i)=>{const o=n[i+1]?.start??s.length,d=s.slice(r.start,o).trim();return{version:r.version,date:r.date,start:r.start,end:o,raw:d}})}const Li=2e3,ju=600*1e3;async function wu(){try{const s=await yt("/api/openchamber/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});return s.ok?{success:!0,autoRestart:(await s.json().catch(()=>({}))).autoRestart!==!1}:{success:!1,error:(await s.json().catch(()=>({}))).error||`Server error: ${s.status}`}}catch(s){return{success:!1,error:s instanceof Error?s.message:void 0}}}async function Nu(){try{return(await yt("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function ku(s,e=Math.ceil(ju/Li),n=Li){for(let a=0;a<e;a++){try{const r=await yt("/api/openchamber/update-check",{method:"GET",headers:{Accept:"application/json"}});if(r.ok){const i=await r.json().catch(()=>null);if(i&&i.available===!1||i&&typeof i.currentVersion=="string"&&typeof s=="string"&&i.currentVersion!==s)return!0}else if((r.status===401||r.status===403)&&await Nu())return!0}catch{}await new Promise(r=>setTimeout(r,n))}return!1}const zi=({open:s,onOpenChange:e,info:n,downloading:a,downloaded:r,progress:i,error:o,onDownload:d,onRestart:c,runtimeType:x="desktop"})=>{const{t:m}=dt(),[p,u]=ve.useState(!1),[C,f]=ve.useState("idle"),[g,h]=ve.useState(null),D=n?.version?`${Fi}/tag/v${n.version}`:Fi,k=i?.total?Math.round(i.downloaded/i.total*100):0,w=x==="web",E=n?.updateCommand||"openchamber update";ve.useEffect(()=>{s||(f("idle"),h(null))},[s]);const N=async()=>{(await mn(E)).ok&&(u(!0),setTimeout(()=>u(!1),2e3))},y=ve.useCallback(async M=>{await Ws(M)},[]),b=ve.useCallback(async()=>{f("updating"),h(null);const M=await wu();if(!M.success){f("error"),h(M.error||m("updateDialog.error.updateFailed"));return}M.autoRestart&&(f("restarting"),await new Promise(v=>setTimeout(v,2e3))),f("reconnecting"),await ku(n?.currentVersion)?window.location.reload():(f("error"),h(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),P=C!=="idle"&&C!=="error",z=ve.useMemo(()=>{if(!n?.body)return null;const M=n.body.trim();if(!M)return null;const I=vu(M);if(I.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Oi(M)};const v=[...I].sort((j,O)=>yu(j.version,O.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:v.map(j=>({version:j.version,dateLabel:xu(j.date),content:Oi(bu(j.raw)||M)}))}},[n?.body,m]);return t.jsx($t,{open:s,onOpenChange:P?void 0:e,children:t.jsxs(Bt,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[t.jsxs("div",{className:"flex items-center mb-1",children:[t.jsxs(Ut,{className:"flex items-center gap-2.5",children:[t.jsx(A,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),t.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(C==="restarting"||C==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&t.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&t.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&t.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&t.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),t.jsxs("div",{className:"space-y-2",children:[w&&P&&t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(A,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),t.jsxs("div",{className:"typography-ui-label text-foreground",children:[C==="updating"&&m("updateDialog.status.installingUpdate"),C==="restarting"&&m("updateDialog.status.serverRestarting"),C==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),z&&!P&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(Gt,{className:"max-h-[400px] p-0",fillContainer:!1,children:z.kind==="raw"?t.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:M=>{const v=M.target.closest("a");v&&v.href&&(M.preventDefault(),M.stopPropagation(),y(v.href))},children:t.jsx(wr,{content:z.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:z.sections.map(M=>t.jsxs("div",{className:"p-4",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",M.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:M.dateLabel})]}),t.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:I=>{const j=I.target.closest("a");j&&j.href&&(I.preventDefault(),I.stopPropagation(),y(j.href))},children:t.jsx(wr,{content:M.content,disableLinkSafety:!0,enableFileReferences:!1})})]},M.version))})})}),w&&C==="error"&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx(A,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:m("updateDialog.fallback.updateViaTerminal")})]}),t.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[t.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:E}),t.jsx("button",{onClick:N,className:ce("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",p&&"text-[var(--status-success)]"),title:m(p?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:p?t.jsx(A,{name:"check",className:"h-4 w-4"}):t.jsx(A,{name:"clipboard",className:"h-4 w-4"})})]})]}),!w&&a&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),t.jsxs("span",{className:"font-mono text-foreground",children:[k,"%"]})]}),t.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${k}%`}})})]}),(o||g)&&t.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:t.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||g})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:D,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[t.jsx(A,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!w&&!r&&!a&&t.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!w&&a&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!w&&r&&t.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[t.jsx(A,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),w&&!P&&t.jsxs("button",{onClick:b,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),w&&P&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},Ki="https://github.com/openchamber/openchamber",Su="https://discord.gg/ZYRSdnwwKA",$i="https://x.com/openchamber_dev",Cu=800,Dl=({initialUpdateDialogOpen:s=!1})=>{const{t:e}=dt(),[n,a]=l.useState(s),[r,i]=l.useState(!1),[o,d]=l.useState(null),[c,x]=l.useState(null),m=Il(Ss(g=>({info:g.info,checking:g.checking,available:g.available,error:g.error,downloading:g.downloading,downloaded:g.downloaded,progress:g.progress,runtimeType:g.runtimeType,checkForUpdates:g.checkForUpdates,downloadUpdate:g.downloadUpdate,restartToUpdate:g.restartToUpdate}))),{isMobile:p}=Cs(),u=o||m.info?.currentVersion||"unknown";l.useEffect(()=>{let g=!1;return(async()=>{try{const D=await yt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const k=await D.json().catch(()=>null),w=typeof k?.openchamberVersion=="string"&&k.openchamberVersion.trim().length>0?k.openchamberVersion.trim():null;g||d(w)}catch{g||d(null)}})(),()=>{g=!0}},[]),l.useEffect(()=>{let g=!1;return(async()=>{try{const D=await yt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const k=await D.json().catch(()=>null),w=typeof k?.currentVersion=="string"&&k.currentVersion.trim().length>0?k.currentVersion.trim():null;g||x(w)}catch{g||x(null)}})(),()=>{g=!0}},[]);const C=l.useRef(!1);l.useEffect(()=>{if(m.checking)i(!0),C.current=!0;else if(r){const g=setTimeout(()=>{i(!1),C.current&&!m.available&&!m.error&&(_.success(e("settings.openchamber.about.toast.latestVersion")),C.current=!1)},Cu);return()=>clearTimeout(g)}},[e,m.checking,r,m.available,m.error]);const f=m.checking||r;return p?t.jsxs("div",{className:"w-full space-y-6 pb-2",children:[t.jsxs("div",{className:"flex flex-col items-center text-center",children:[t.jsx(gl,{width:72,height:72}),t.jsx("h2",{className:"mt-4 typography-ui-header font-semibold text-foreground",children:"OpenChamber"}),t.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[t.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:u})}),t.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]})]}),t.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&t.jsxs(J,{type:"button",variant:"outline",size:"sm",onClick:()=>m.checkForUpdates(),disabled:f,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[f?t.jsx(A,{name:"loader",className:"size-4 animate-spin"}):t.jsx(A,{name:"refresh",className:"size-4"}),e(f?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!f&&m.available&&t.jsxs(J,{type:"button",variant:"default",size:"sm",onClick:()=>a(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[t.jsx(A,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]})]}),m.error&&t.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:m.error}),t.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[t.jsxs("div",{className:"flex items-center justify-center gap-5",children:[t.jsxs("a",{href:Ki,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(A,{name:"github-fill",className:"size-5"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:Su,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(A,{name:"discord-fill",className:"size-5"}),t.jsx("span",{children:"Discord"})]})]}),t.jsxs("a",{href:$i,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(A,{name:"twitter-xfill",className:"size-5"}),t.jsx("span",{children:"@openchamber_dev"})]})]}),t.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),t.jsx(zi,{open:n,onOpenChange:a,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]}):t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-3 px-1",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:e("settings.openchamber.about.title")})}),t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.version")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:u})]}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.openCodeVersion")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!m.checking&&m.available&&t.jsxs(J,{size:"sm",variant:"default",onClick:()=>a(!0),children:[t.jsx(A,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]}),!m.checking&&!m.available&&!m.error&&t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t.jsx(J,{size:"sm",variant:"outline",onClick:()=>m.checkForUpdates(),disabled:m.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),m.error&&t.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m.error})}),t.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[t.jsxs("a",{href:Ki,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[t.jsx(A,{name:"github-fill",className:"h-4 w-4"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:$i,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[t.jsx(A,{name:"twitter-xfill",className:"h-4 w-4"}),t.jsx("span",{children:"@openchamber_dev"})]})]})]}),t.jsx(zi,{open:n,onOpenChange:a,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]})},Mv=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),Pu=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),Iu=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},Du=s=>!s||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),Bn="opencode-update-available",ca="opencode-upgrade-progress",Au=5e3,Eu=[1e4,6e4],Bi="opencode-update-toast-dismissed-version",Rv=()=>{const{t:s}=dt(),e=Ke(o=>o.showOpenCodeUpdateNotifications),n=ve.useRef(new Set),a=ve.useRef(!1);ve.useEffect(()=>{e||_.dismiss(Bn)},[e]);const r=ve.useCallback(()=>{_.dismiss(ca),Dn({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),i=ve.useCallback(async()=>{if(!a.current){a.current=!0,_.dismiss(Bn),_.message(s("opencodeUpdate.toast.upgrading.title"),{id:ca,description:s("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:t.jsx(A,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const o=await yt("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),d=await o.json().catch(()=>null);if(!o.ok||d?.success===!1)throw new Error(d?.error||o.statusText||s("opencodeUpdate.toast.failed.description"));_.success(s("opencodeUpdate.toast.updated.title"),{id:ca,description:d?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:d.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(o){_.error(s("opencodeUpdate.toast.failed.title"),{id:ca,description:o instanceof Error?o.message:s("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{a.current=!1}}},[r,s]);return ve.useEffect(()=>{const o=p=>{if(!Ke.getState().showOpenCodeUpdateNotifications){_.dismiss(Bn);return}Pu({version:p,dismissedVersion:Zn().getItem(Bi),seenVersions:n.current})&&(n.current.add(p),_.info(s("opencodeUpdate.toast.available.title"),{id:Bn,description:s("opencodeUpdate.toast.available.description",{version:p}),duration:1/0,action:{label:s("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:s("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{Zn().setItem(Bi,p),Ct({openCodeUpdateToastDismissedVersion:p}),_.dismiss(Bn)}}}))},d=p=>{const u=Iu(p.detail);o(u)};let c=!1;const x=[],m=async p=>{try{const u=await yt("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!u.ok)throw new Error(u.statusText||"OpenCode upgrade status check failed");const C=await u.json().catch(()=>null),f=Du(C);!c&&f&&o(f)}catch{const u=Eu[p];!c&&u!==void 0&&x.push(setTimeout(()=>{m(p+1)},u))}};return e&&x.push(setTimeout(()=>{m(0)},Au)),window.addEventListener("openchamber:opencode-update-available",d),()=>{c=!0;for(const p of x)clearTimeout(p);window.removeEventListener("openchamber:opencode-update-available",d)}},[i,e,s]),null},Tv=()=>{const s=rt.c(3),[e,n]=l.useState(Mu),{isUpdating:a}=e;let r,i;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>md(n),i=[],s[0]=r,s[1]=i):(r=s[0],i=s[1]),l.useEffect(r,i),!a)return null;let o;return s[2]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:t.jsx(gl,{width:80,height:80,isAnimated:!0})}),s[2]=o):o=s[2],o};function Mu(){return dd()}class Ru extends l.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(ud,{className:"w-full max-w-md",children:[t.jsx(pd,{className:"text-center",children:t.jsxs(gd,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(A,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(hd,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(J,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function Tu(s){const e=rt.c(22),{t:n}=dt();let a;e[0]!==n?(a=n("chat.errorBoundary.title"),e[0]=n,e[1]=a):a=e[1];let r;e[2]!==n?(r=n("chat.errorBoundary.description"),e[2]=n,e[3]=r):r=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let d;e[8]!==n?(d=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=d):d=e[9];let c;e[10]!==n?(c=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=c):c=e[11];let x;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==o||e[16]!==d||e[17]!==c?(x={title:a,description:r,sessionLabel:i,detailsSummary:o,resetAction:d,persistentHint:c},e[12]=a,e[13]=r,e[14]=i,e[15]=o,e[16]=d,e[17]=c,e[18]=x):x=e[18];let m;return e[19]!==s||e[20]!==x?(m=t.jsx(Ru,{...s,texts:x}),e[19]=s,e[20]=x,e[21]=m):m=e[21],m}const Fv=s=>{const e=rt.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=Is(Fu)||void 0;let o;e[0]!==a?(o=t.jsx(fd,{readOnly:a}),e[0]=a,e[1]=o):o=e[1];let d;return e[2]!==i||e[3]!==o?(d=t.jsx(Tu,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=d):d=e[4],d};function Fu(s){return s.currentSessionId}function en(s){const e=rt.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let a;return e[2]!==n?(a=t.jsx(bc,{...n}),e[2]=n,e[3]=a):a=e[3],a}function tn(s){const e=rt.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let a;return e[2]!==n?(a=t.jsx(yc,{...n}),e[2]=n,e[3]=a):a=e[3],a}function sn(s){const e=rt.c(20);let n,a,r,i,o;e[0]!==s?({className:a,positionerClassName:r,children:n,style:o,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i,e[5]=o):(n=e[1],a=e[2],r=e[3],i=e[4],o=e[5]);let d;e[6]!==r?(d=ce("app-region-no-drag z-50",r),e[6]=r,e[7]=d):d=e[7];let c;e[8]!==o?(c={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",...o},e[8]=o,e[9]=c):c=e[9];let x;e[10]!==a?(x=ce(xd,a),e[10]=a,e[11]=x):x=e[11];let m;e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==x?(m=t.jsx(vc,{"data-slot":"dropdown-menu-content",style:c,className:x,...i,children:n}),e[12]=n,e[13]=i,e[14]=c,e[15]=x,e[16]=m):m=e[16];let p;return e[17]!==d||e[18]!==m?(p=t.jsx(wc,{children:t.jsx(Nc,{className:d,children:m})}),e[17]=d,e[18]=m,e[19]=p):p=e[19],p}function qs(s){const e=rt.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=ce(bd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(jc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}function Ov(s){const e=rt.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=ce(yd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(kc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}const Al=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),na=s=>{const e=rt.c(39),{className:n}=s,{t:a}=dt(),r=is(Ou),i=is(Lu),o=is(zu),d=fs();let c;e[0]!==r?(c=[...r].sort(Ku),e[0]=r,e[1]=c):c=e[1];const x=c;let m;e:{if(x.length===0){m=null;break e}let O;e[2]!==i||e[3]!==x?(O=x.find(T=>T.id===i)??x[0],e[2]=i,e[3]=x,e[4]=O):O=e[4],m=O}const p=m;if(d||x.length===0)return null;let u;e[5]!==p||e[6]!==a?(u=p?.label&&p.label.trim().length>0?p.label:p?.path.split("/").filter(Boolean).pop()||p?.path||a("settings.shared.projectSelector.fallbackProject"),e[5]=p,e[6]=a,e[7]=u):u=e[7];const C=u;let f;e[8]!==C?(f=Al(C),e[8]=C,e[9]=f):f=e[9];const g=f;let h;e[10]!==n?(h=ce(n),e[10]=n,e[11]=h):h=e[11];let D;e[12]!==a?(D=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=D):D=e[13];let k;e[14]!==a?(k=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=k):k=e[15];let w,E;e[16]===Symbol.for("react.memo_cache_sentinel")?(w=ce("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),E=t.jsx(A,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=w,e[17]=E):(w=e[16],E=e[17]);let N;e[18]!==g?(N=t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:g}),e[18]=g,e[19]=N):N=e[19];let y;e[20]===Symbol.for("react.memo_cache_sentinel")?(y=t.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=y):y=e[20];let b;e[21]!==N||e[22]!==D||e[23]!==k?(b=t.jsx(us,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":D,title:k,className:w,children:[E,N,y]})}),e[21]=N,e[22]=D,e[23]=k,e[24]=b):b=e[24];const P=p?.id??"";let z;e[25]!==o?(z=O=>{O&&o(O)},e[25]=o,e[26]=z):z=e[26];let M;e[27]!==x?(M=x.map($u),e[27]=x,e[28]=M):M=e[28];let I;e[29]!==P||e[30]!==z||e[31]!==M?(I=t.jsx(ps,{align:"start",className:"w-auto",children:t.jsx(jd,{value:P,onValueChange:z,children:M})}),e[29]=P,e[30]=z,e[31]=M,e[32]=I):I=e[32];let v;e[33]!==b||e[34]!==I?(v=t.jsxs(gs,{children:[b,I]}),e[33]=b,e[34]=I,e[35]=v):v=e[35];let j;return e[36]!==v||e[37]!==h?(j=t.jsx("div",{className:h,children:v}),e[36]=v,e[37]=h,e[38]=j):j=e[38],j};function Ou(s){return s.projects}function Lu(s){return s.activeProjectId}function zu(s){return s.setActiveProject}function Ku(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function $u(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=Al(e);return t.jsx(vd,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function Bu(s,e){return`opencode:sidebar-group:${s}:${e}`}const Er=s=>{const e=rt.c(33),{label:n,count:a,storageKey:r,defaultExpanded:i,children:o}=s,d=i===void 0?!0:i;let c;e[0]!==n||e[1]!==r?(c=Bu(r,n),e[0]=n,e[1]=r,e[2]=c):c=e[2];const x=c,m=l.useId();let p;e[3]!==d||e[4]!==x?(p=()=>{try{const I=localStorage.getItem(x);if(I!==null)return I==="true"}catch{}return d},e[3]=d,e[4]=x,e[5]=p):p=e[5];const[u,C]=ve.useState(p);let f,g;e[6]!==u||e[7]!==x?(f=()=>{try{localStorage.setItem(x,String(u))}catch{}},g=[x,u],e[6]=u,e[7]=x,e[8]=f,e[9]=g):(f=e[8],g=e[9]),ve.useEffect(f,g);let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=()=>C(Uu),e[10]=h):h=e[10];let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=ce("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=D):D=e[11];const k=!u&&"-rotate-90";let w;e[12]!==k?(w=ce("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",k),e[12]=k,e[13]=w):w=e[13];let E;e[14]!==w?(E=t.jsx(A,{name:"arrow-down-s",className:w}),e[14]=w,e[15]=E):E=e[15];let N;e[16]!==n?(N=t.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=N):N=e[17];let y;e[18]!==a?(y=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=y):y=e[19];let b;e[20]!==m||e[21]!==u||e[22]!==E||e[23]!==N||e[24]!==y?(b=t.jsxs("button",{type:"button",onClick:h,"aria-expanded":u,"aria-controls":m,className:D,children:[E,N,y]}),e[20]=m,e[21]=u,e[22]=E,e[23]=N,e[24]=y,e[25]=b):b=e[25];const P=!u;let z;e[26]!==o||e[27]!==m||e[28]!==P?(z=t.jsx("div",{id:m,hidden:P,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[26]=o,e[27]=m,e[28]=P,e[29]=z):z=e[29];let M;return e[30]!==b||e[31]!==z?(M=t.jsxs("div",{children:[b,z]}),e[30]=b,e[31]=z,e[32]=M):M=e[32],M};function Uu(s){return!s}const Vu=s=>{if(!Array.isArray(s))return[];const e=[];for(const n of s){if(!n||typeof n!="object")continue;const a=n;typeof a.permission!="string"||typeof a.pattern!="string"||typeof a.action!="string"||a.action!=="allow"&&a.action!=="ask"&&a.action!=="deny"||e.push({permission:a.permission,pattern:a.pattern,action:a.action})}return e},_u=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},Ui=s=>{const e=_u(Vu(s));if(e.length===0)return;const n={};for(const r of e)r.permission&&((n[r.permission]||={})[r.pattern]=r.action);const a={};for(const[r,i]of Object.entries(n)){const o=Object.keys(i);if(o.length===1&&o[0]==="*"){a[r]=i["*"];continue}a[r]=i}return Object.keys(a).length>0?a:void 0},Hu=({onItemSelect:s})=>{const{t:e}=dt(),[n,a]=l.useState(null),[r,i]=l.useState(""),[o,d]=l.useState(null),[c,x]=l.useState(null),[m,p]=l.useState(!1),[u,C]=l.useState(null),{selectedAgentName:f,agents:g,setSelectedAgent:h,setAgentDraft:D,createAgent:k,deleteAgent:w,loadAgents:E}=$a(Ss(R=>({selectedAgentName:R.selectedAgentName,agents:R.agents,setSelectedAgent:R.setSelectedAgent,setAgentDraft:R.setAgentDraft,createAgent:R.createAgent,deleteAgent:R.deleteAgent,loadAgents:R.loadAgents})));l.useEffect(()=>{E()},[E]);const N="bg-background",y=()=>{const R="new-agent";let Y=R,F=1;for(;g.some(W=>W.name===Y);)Y=`${R}-${F}`,F++;D({name:Y,scope:"user"}),h(Y),s?.()},b=async R=>{if(Sn(R)){_.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(R),x("delete")},P=async R=>{Sn(R)&&(d(R),x("reset"))},z=()=>{d(null),x(null)},M=async()=>{if(!(!o||!c)){p(!0);try{const R=await w(o.name,o.scope);R.ok?(R.requiresManualRestart?_.warning(e("settings.agents.page.toast.savedManualRestart")):c==="delete"?_.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):_.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),z()):c==="delete"?_.error(e("settings.agents.sidebar.toast.deleteFailed")):_.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(R){const Y=R instanceof Error?R.message:"",F=/built-in|not deletable|not found/i.test(Y);c==="delete"?_.error(e(F?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):_.error(e("settings.agents.sidebar.toast.resetFailed"))}p(!1)}},I=R=>{const Y=R.name;let F=1,W=`${Y}-copy`;for(;g.some(de=>de.name===W);)F++,W=`${Y}-copy-${F}`;const X=R,re=R.model?.providerID&&R.model?.modelID?`${R.model.providerID}/${R.model.modelID}`:null,Z=R;D({name:W,scope:X.scope||"user",description:R.description,model:re,variant:R.variant,temperature:R.temperature,top_p:R.topP,prompt:R.prompt,mode:R.mode,permission:Ui(R.permission),disable:Z.disable}),h(W)},v=R=>{i(R.name),a(R)},j=async()=>{if(!n)return;const R=r.trim().replace(/\s+/g,"-");if(!R){_.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(R===n.name){a(null);return}if(g.some(X=>X.name===R)){_.error(e("settings.agents.sidebar.toast.agentExists"));return}const Y=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,F=n,W=await k({name:R,description:n.description,model:Y,variant:n.variant,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Ui(n.permission),disable:F.disable,scope:F.scope});if(W.ok){const X=await w(n.name,F.scope);X.ok?(W.requiresManualRestart||X.requiresManualRestart?_.warning(e("settings.agents.page.toast.savedManualRestart")):_.success(e("settings.agents.sidebar.toast.agentRenamed",{name:R})),h(R)):_.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else _.error(e("settings.agents.sidebar.toast.renameFailed"));a(null)},O=R=>{switch(R){case"primary":return t.jsx(A,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(A,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(A,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},T=g.filter(R=>!wd(R)),B=T.filter(Sn),U=T.filter(R=>!Sn(R)),{groupedCustomAgents:Q,ungroupedCustomAgents:q}=ve.useMemo(()=>{const R={},Y=[];for(const W of U){const X=W;X.group?(R[X.group]||(R[X.group]=[]),R[X.group].push(W)):Y.push(W)}return{groupedCustomAgents:Object.keys(R).sort((W,X)=>W.localeCompare(X)).map(W=>({name:W,agents:R[W]})),ungroupedCustomAgents:Y}},[U]);return t.jsxs("div",{className:ce("flex h-full flex-col",N),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),t.jsx(na,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:T.length})}),t.jsx(J,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:y,children:t.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Gt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:T.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[B.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),B.map(R=>t.jsx(nr,{agent:R,isSelected:f===R.name,onSelect:()=>{h(R.name),s?.()},onReset:()=>P(R),onDuplicate:()=>I(R),getAgentModeIcon:O,isMenuOpen:u===R.name,onMenuOpenChange:Y=>C(Y?R.name:null)},R.name))]}),U.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),Q.map(({name:R,agents:Y})=>t.jsx(Er,{label:R,count:Y.length,storageKey:"agents",children:Y.map(F=>t.jsx(nr,{agent:F,isSelected:f===F.name,onSelect:()=>{h(F.name),s?.()},onRename:()=>v(F),onDelete:()=>b(F),onDuplicate:()=>I(F),getAgentModeIcon:O,isMenuOpen:u===F.name,onMenuOpenChange:W=>C(W?F.name:null)},F.name))},R)),q.map(R=>t.jsx(nr,{agent:R,isSelected:f===R.name,onSelect:()=>{h(R.name),s?.()},onRename:()=>v(R),onDelete:()=>b(R),onDuplicate:()=>I(R),getAgentModeIcon:O,isMenuOpen:u===R.name,onMenuOpenChange:Y=>C(Y?R.name:null)},R.name))]})]})}),t.jsx($t,{open:o!==null&&c!==null,onOpenChange:R=>{!R&&!m&&z()},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Ut,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(Wt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),t.jsxs(Yt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:z,disabled:m,children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:M,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx($t,{open:n!==null,onOpenChange:R=>!R&&a(null),children:t.jsxs(Bt,{children:[t.jsxs(_t,{children:[t.jsx(Ut,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(Wt,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(ot,{value:r,onChange:R=>i(R.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:R=>{R.key==="Enter"&&j()}}),t.jsxs(Yt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:j,children:e("settings.common.actions.rename")})]})]})})]})},nr=s=>{const e=rt.c(52),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,getAgentModeIcon:x,isMenuOpen:m,onMenuOpenChange:p}=s,{t:u}=dt(),C=n;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Xn(),e[0]=f):f=e[0];const g=f,[h,D]=l.useState(!1);let k;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==u?(k=F=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(F,{onClick:W=>{W.stopPropagation(),d()},children:[t.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),t.jsxs(F,{onClick:W=>{W.stopPropagation(),c()},children:[t.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),o&&t.jsxs(F,{onClick:W=>{W.stopPropagation(),o()},children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),i&&t.jsxs(F,{onClick:W=>{W.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=o,e[5]=u,e[6]=k):k=e[6];const w=k,E=a?"bg-interactive-selection":"hover:bg-interactive-hover";let N;e[7]!==E?(N=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",E),e[7]=E,e[8]=N):N=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=g?void 0:F=>{F.preventDefault(),D(!0)},e[9]=y):y=e[9];let b;e[10]!==N?(b=t.jsx("div",{className:N,onContextMenu:y}),e[10]=N,e[11]=b):b=e[11];let P;e[12]!==n.name?(P=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[12]=n.name,e[13]=P):P=e[13];let z;e[14]!==n.mode||e[15]!==x?(z=x(n.mode),e[14]=n.mode,e[15]=x,e[16]=z):z=e[16];let M;e[17]!==n||e[18]!==C.scope||e[19]!==u?(M=(C.scope||Sn(n))&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Sn(n)?u("settings.agents.sidebar.badge.system"):C.scope}),e[17]=n,e[18]=C.scope,e[19]=u,e[20]=M):M=e[20];let I;e[21]!==P||e[22]!==z||e[23]!==M?(I=t.jsxs("div",{className:"flex items-center gap-1.5",children:[P,z,M]}),e[21]=P,e[22]=z,e[23]=M,e[24]=I):I=e[24];let v;e[25]!==n.description?(v=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[25]=n.description,e[26]=v):v=e[26];let j;e[27]!==r||e[28]!==I||e[29]!==v?(j=t.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[I,v]}),e[27]=r,e[28]=I,e[29]=v,e[30]=j):j=e[30];let O;e[31]!==p?(O=F=>{F&&D(!1),p(F)},e[31]=p,e[32]=O):O=e[32];let T;e[33]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=T):T=e[33];let B;e[34]!==w?(B=t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:w(vs)}),e[34]=w,e[35]=B):B=e[35];let U;e[36]!==m||e[37]!==O||e[38]!==B?(U=t.jsxs(gs,{open:m,onOpenChange:O,children:[T,B]}),e[36]=m,e[37]=O,e[38]=B,e[39]=U):U=e[39];let Q;e[40]!==j||e[41]!==U?(Q=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[j,U]}),e[40]=j,e[41]=U,e[42]=Q):Q=e[42];let q;e[43]!==Q||e[44]!==b?(q=t.jsx(tn,{render:b,children:Q}),e[43]=Q,e[44]=b,e[45]=q):q=e[45];let R;e[46]!==w?(R=t.jsx(sn,{className:"w-fit min-w-20",children:w(qs)}),e[46]=w,e[47]=R):R=e[47];let Y;return e[48]!==h||e[49]!==q||e[50]!==R?(Y=t.jsxs(en,{open:h,onOpenChange:D,children:[q,R]}),e[48]=h,e[49]=q,e[50]=R,e[51]=Y):Y=e[51],Y};function Vi(s,e,n){return Math.min(n,Math.max(e,s))}function Wu(s){if(!Number.isFinite(s))return 0;const e=String(s);if(e.includes("e-")){const[,a]=e.split("e-");return Number(a)||0}const n=e.split(".");return n.length===2?n[1].length:0}function _i(s,e){const n=Wu(e);return n<=0?s:Number(s.toFixed(n))}const bs=ve.forwardRef((s,e)=>{const n=rt.c(125);let a,r,i,o,d,c,x,m,p,u,C,f,g;n[0]!==s?({value:g,onValueChange:x,min:p,max:u,step:C,className:a,containerClassName:r,onBlur:d,disabled:i,fallbackValue:o,onClear:c,emptyLabel:f,...m}=s,n[0]=s,n[1]=a,n[2]=r,n[3]=i,n[4]=o,n[5]=d,n[6]=c,n[7]=x,n[8]=m,n[9]=p,n[10]=u,n[11]=C,n[12]=f,n[13]=g):(a=n[1],r=n[2],i=n[3],o=n[4],d=n[5],c=n[6],x=n[7],m=n[8],p=n[9],u=n[10],C=n[11],f=n[12],g=n[13]);const h=p===void 0?-1/0:p,D=u===void 0?1/0:u,k=C===void 0?1:C,w=f===void 0?"—":f,{t:E}=dt();let N;n[14]!==g?(N=()=>g===void 0?"":String(g),n[14]=g,n[15]=N):N=n[15];const[y,b]=ve.useState(N),{isMobile:P}=Cs(),z=ve.useRef(!1),M=ve.useRef(null);let I;n[16]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{if(typeof document>"u"||typeof window>"u")return;M.current?.();const Ae=Fe=>{Fe.preventDefault(),Fe.stopPropagation(),Fe.stopImmediatePropagation?.(),M.current?.()},Pe=window.setTimeout(()=>{M.current?.()},700),Te=()=>{window.clearTimeout(Pe),document.removeEventListener("click",Ae,!0),M.current=null};M.current=Te,document.addEventListener("click",Ae,!0)},n[16]=I):I=n[16];const v=I;let j,O;n[17]===Symbol.for("react.memo_cache_sentinel")?(j=()=>()=>{M.current?.()},O=[],n[17]=j,n[18]=O):(j=n[17],O=n[18]),ve.useEffect(j,O);let T,B;n[19]!==g?(B=()=>{b(g===void 0?"":String(g))},T=[g],n[19]=g,n[20]=T,n[21]=B):(T=n[20],B=n[21]),ve.useEffect(B,T);let U;e:{if(g!==void 0){U=g;break e}if(o!==void 0){U=o;break e}if(Number.isFinite(h)){U=h;break e}U=0}const Q=U;let q;n[22]!==D||n[23]!==h||n[24]!==x||n[25]!==k?(q=Ae=>{const Pe=Vi(Ae,h,D);x(_i(Pe,k))},n[22]=D,n[23]=h,n[24]=x,n[25]=k,n[26]=q):q=n[26];const R=q;let Y;n[27]!==R||n[28]!==c?(Y=Ae=>{const Pe=Ae.target.value;if(b(Pe),Pe.trim()===""){c?.();return}const Te=Number(Pe);Number.isFinite(Te)&&R(Te)},n[27]=R,n[28]=c,n[29]=Y):Y=n[29];const F=Y;let W;n[30]!==y||n[31]!==D||n[32]!==h||n[33]!==d||n[34]!==c||n[35]!==x||n[36]!==k||n[37]!==g?(W=Ae=>{if(y.trim()===""){c||b(g===void 0?"":String(g)),d?.(Ae);return}const Pe=Number(y);if(!Number.isFinite(Pe))b(g===void 0?"":String(g));else{const Te=Vi(Pe,h,D),Fe=_i(Te,k);Fe!==g&&x(Fe),b(String(Fe))}d?.(Ae)},n[30]=y,n[31]=D,n[32]=h,n[33]=d,n[34]=c,n[35]=x,n[36]=k,n[37]=g,n[38]=W):W=n[38];const X=W,re=!!(i||Q>=D),Z=!!(i||Q<=h);let de;n[39]!==Q||n[40]!==R||n[41]!==Z||n[42]!==k?(de=()=>{Z||R(Q-k)},n[39]=Q,n[40]=R,n[41]=Z,n[42]=k,n[43]=de):de=n[43];const le=de;let ee;n[44]!==Q||n[45]!==R||n[46]!==re||n[47]!==k?(ee=()=>{re||R(Q+k)},n[44]=Q,n[45]=R,n[46]=re,n[47]=k,n[48]=ee):ee=n[48];const xe=ee;let we;if(n[49]!==a||n[50]!==r||n[51]!==Z||n[52]!==y||n[53]!==w||n[54]!==le||n[55]!==xe||n[56]!==re||n[57]!==P||n[58]!==E||n[59]!==g){we=Symbol.for("react.early_return_sentinel");e:{const Ae=Te=>Fe=>{Fe.preventDefault(),Fe.stopPropagation(),z.current=!0,v(),Te()},Pe=Te=>Fe=>{if(z.current){z.current=!1,Fe.preventDefault(),Fe.stopPropagation();return}Te()};if(P){let Te;n[61]!==r?(Te=ce("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",r),n[61]=r,n[62]=Te):Te=n[62];let Fe;n[63]!==E?(Fe=E("numberInput.actions.decreaseAria"),n[63]=E,n[64]=Fe):Fe=n[64];const Be=Ae(le),We=Pe(le),ze=!Z&&"active:bg-interactive-hover";let Qe;n[65]!==ze?(Qe=ce("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",ze),n[65]=ze,n[66]=Qe):Qe=n[66];let oe;n[67]===Symbol.for("react.memo_cache_sentinel")?(oe=t.jsx(A,{name:"subtract",className:"block h-4 w-4"}),n[67]=oe):oe=n[67];const H=t.jsx("button",{type:"button","aria-label":Fe,disabled:Z,onTouchStart:Be,onClick:We,className:Qe,children:oe});let me;n[68]!==a?(me=ce("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",a),n[68]=a,n[69]=me):me=n[69];const Ne=g===void 0?w:y;let Ee;n[70]!==me||n[71]!==Ne?(Ee=t.jsx("div",{className:me,"aria-live":"polite",children:Ne}),n[70]=me,n[71]=Ne,n[72]=Ee):Ee=n[72];let Ce;n[73]!==E?(Ce=E("numberInput.actions.increaseAria"),n[73]=E,n[74]=Ce):Ce=n[74];const _e=Ae(xe),G=Pe(xe),$=!re&&"active:bg-interactive-hover";let fe;n[75]!==$?(fe=ce("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",$),n[75]=$,n[76]=fe):fe=n[76];let L;n[77]===Symbol.for("react.memo_cache_sentinel")?(L=t.jsx(A,{name:"add",className:"block h-4 w-4"}),n[77]=L):L=n[77];const Le=t.jsx("button",{type:"button","aria-label":Ce,disabled:re,onTouchStart:_e,onClick:G,className:fe,children:L});let Je;n[78]!==Te||n[79]!==H||n[80]!==Ee||n[81]!==Le?(Je=t.jsxs("div",{className:Te,children:[H,Ee,Le]}),n[78]=Te,n[79]=H,n[80]=Ee,n[81]=Le,n[82]=Je):Je=n[82],we=Je;break e}}n[49]=a,n[50]=r,n[51]=Z,n[52]=y,n[53]=w,n[54]=le,n[55]=xe,n[56]=re,n[57]=P,n[58]=E,n[59]=g,n[60]=we}else we=n[60];if(we!==Symbol.for("react.early_return_sentinel"))return we;let he;n[83]!==r?(he=ce("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",r),n[83]=r,n[84]=he):he=n[84];let Ie;n[85]!==E?(Ie=E("numberInput.actions.decreaseAria"),n[85]=E,n[86]=Ie):Ie=n[86];let be;n[87]!==Q||n[88]!==R||n[89]!==k?(be=()=>R(Q-k),n[87]=Q,n[88]=R,n[89]=k,n[90]=be):be=n[90];let je,ye;n[91]===Symbol.for("react.memo_cache_sentinel")?(je=ce("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),ye=t.jsx(A,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=je,n[92]=ye):(je=n[91],ye=n[92]);let se;n[93]!==Z||n[94]!==Ie||n[95]!==be?(se=t.jsx("button",{type:"button","aria-label":Ie,disabled:Z,onClick:be,className:je,children:ye}),n[93]=Z,n[94]=Ie,n[95]=be,n[96]=se):se=n[96];const ie=m.inputMode??"numeric";let ge;n[97]!==a?(ge=ce("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",a),n[97]=a,n[98]=ge):ge=n[98];let V;n[99]!==i||n[100]!==y||n[101]!==X||n[102]!==F||n[103]!==m||n[104]!==e||n[105]!==ie||n[106]!==ge?(V=t.jsx("input",{...m,ref:e,type:"text",inputMode:ie,value:y,onChange:F,onBlur:X,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ge}),n[99]=i,n[100]=y,n[101]=X,n[102]=F,n[103]=m,n[104]=e,n[105]=ie,n[106]=ge,n[107]=V):V=n[107];let te;n[108]!==E?(te=E("numberInput.actions.increaseAria"),n[108]=E,n[109]=te):te=n[109];let ne;n[110]!==Q||n[111]!==R||n[112]!==k?(ne=()=>R(Q+k),n[110]=Q,n[111]=R,n[112]=k,n[113]=ne):ne=n[113];let ue,Me;n[114]===Symbol.for("react.memo_cache_sentinel")?(ue=ce("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Me=t.jsx(A,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=ue,n[115]=Me):(ue=n[114],Me=n[115]);let ke;n[116]!==re||n[117]!==te||n[118]!==ne?(ke=t.jsx("button",{type:"button","aria-label":te,disabled:re,onClick:ne,className:ue,children:Me}),n[116]=re,n[117]=te,n[118]=ne,n[119]=ke):ke=n[119];let Re;return n[120]!==he||n[121]!==se||n[122]!==V||n[123]!==ke?(Re=t.jsxs("div",{className:he,children:[se,V,ke]}),n[120]=he,n[121]=se,n[122]=V,n[123]=ke,n[124]=Re):Re=n[124],Re});bs.displayName="NumberInput";const Hi=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Pa=s=>s==="allow"||s==="ask"||s==="deny",cn=(s,e)=>`${s}::${e}`,nn=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&Pa(n.action)&&e.set(cn(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},da=s=>{const e=new Map;for(const n of nn(s))e.set(cn(n.permission,n.pattern),n);return e},Wi=s=>[...s].sort((e,n)=>{const a=e.permission.localeCompare(n.permission);return a!==0?a:e.pattern.localeCompare(n.pattern)}),qu=(s,e)=>{const n=Wi(nn(s)),a=Wi(nn(e));return n.length!==a.length?!1:n.every((r,i)=>{const o=a[i];return r.permission===o.permission&&r.pattern===o.pattern&&r.action===o.action})},Gu=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",Ju=(s,e)=>nn(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),ar=s=>{if(Array.isArray(s))return nn(s);if(Pa(s))return[{permission:"*",pattern:"*",action:s}];if(!s||typeof s!="object"||Array.isArray(s))return[];const e=[];for(const[n,a]of Object.entries(s))if(n!=="__originalKeys"){if(Pa(a)){e.push({permission:n,pattern:"*",action:a});continue}if(a&&typeof a=="object"&&!Array.isArray(a))for(const[r,i]of Object.entries(a))Pa(i)&&e.push({permission:n,pattern:r,action:i})}return e},Qu=(s,e)=>{const n=nn(e),a={};for(const i of n)(a[i.permission]||={})[i.pattern]=i.action;const r={};for(const[i,o]of Object.entries(a))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){r[i]=o["*"];continue}r[i]=o}return Object.keys(r).length===0?s:(s!=="allow"&&(r["*"]=s),r)},Yu=(s,e)=>{const n=un(e);if(!n)return[];const r=s.find(i=>i.id===n.providerId)?.models?.find(i=>i.id===n.modelId);return r?.variants?Object.keys(r.variants):[]},Xu=()=>{const{t:s}=dt(),{isMobile:e}=Cs(),n=ut(H=>H.providers),{selectedAgentName:a,getAgentByName:r,createAgent:i,updateAgent:o,agents:d,agentDraft:c,setAgentDraft:x}=$a(Ss(H=>({selectedAgentName:H.selectedAgentName,getAgentByName:H.getAgentByName,createAgent:H.createAgent,updateAgent:H.updateAgent,agents:H.agents,agentDraft:H.agentDraft,setAgentDraft:H.setAgentDraft}))),m=a?r(a):null,p=!!(c&&c.name===a&&!m),[u,C]=l.useState(""),[f,g]=l.useState("user"),[h,D]=l.useState(""),[k,w]=l.useState("subagent"),[E,N]=l.useState(""),[y,b]=l.useState(""),[P,z]=l.useState(void 0),[M,I]=l.useState(void 0),[v,j]=l.useState(""),[O,T]=l.useState("allow"),[B,U]=l.useState([]),[Q,q]=l.useState([]),[R,Y]=l.useState(""),[F,W]=l.useState("*"),[X,re]=l.useState(!1),[Z,de]=l.useState(!1),le=l.useRef(null),ee=ys(H=>H.currentDirectory??null),[xe,we]=l.useState([]),he=l.useMemo(()=>Yu(n,E),[E,n]),Ie=he.length>0,be=l.useMemo(()=>!y||!he.includes(y)?"__default":y,[y,he]),je=Ie&&(!y||he.includes(y)),ye=Nd(H=>H.permission);l.useEffect(()=>{let H=!1;return(async()=>{const Ne=await ws.listToolIds({directory:ee});if(H)return;const Ee=new Set(["write","patch","multiedit"]),Ce=Ne.map(_e=>typeof _e=="string"?_e.trim():"").filter(Boolean).filter(_e=>_e!=="*").filter(_e=>_e!=="invalid").filter(_e=>!Ee.has(_e));we(Array.from(new Set(Ce)).sort((_e,G)=>_e.localeCompare(G)))})(),()=>{H=!0}},[ee]);const se=l.useMemo(()=>{const H=new Set;for(const me of d){const Ne=nn(ar(me.permission));for(const Ee of Ne)Ee.permission&&Ee.permission!=="*"&&Ee.permission!=="invalid"&&H.add(Ee.permission)}for(const me of Object.values(ye))for(const Ne of me){const Ee=Ne.permission?.trim();Ee&&Ee!=="invalid"&&H.add(Ee)}for(const me of xe)H.add(me);return Array.from(H).sort((me,Ne)=>me.localeCompare(Ne))},[d,ye,xe]),ie=l.useMemo(()=>da(B),[B]),ge=l.useMemo(()=>da(Q),[Q]),V=l.useCallback(H=>ge.get(cn(H,"*"))?.action,[ge]),te=l.useCallback(H=>Q.filter(me=>me.permission===H&&me.pattern!=="*").sort((me,Ne)=>me.pattern.localeCompare(Ne.pattern)),[Q]),ne=l.useMemo(()=>{const H=new Set;for(const me of Hi)H.add(me);for(const me of se)H.add(me);return Array.from(H).sort((me,Ne)=>me.localeCompare(Ne))},[se]),ue=l.useCallback(H=>{const me=H==="*"?O:V(H)??O,Ne=te(H),Ee=!1,Ce=Ne.reduce((G,$)=>(G[$.action]=(G[$.action]??0)+1,G),{allow:0,ask:0,deny:0}),_e=["allow","ask","deny"].filter(G=>Ce[G]>0).map(G=>`${Ce[G]} ${G}`).join(", ");return{defaultAction:me,patternRulesCount:Ne.length,patternSummary:_e,hasDefaultHint:Ee}},[te,V,O]),Me=l.useCallback(H=>s(H==="allow"?"settings.common.permission.allow":H==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),ke=l.useCallback(H=>H==="global"?s("settings.common.scope.global"):Me(H),[Me,s]),Re=l.useMemo(()=>{const H=new Set;for(const me of Hi)H.add(me);for(const me of se)H.add(me);return Array.from(H).sort((me,Ne)=>me.localeCompare(Ne))},[se]),Ae=l.useCallback((H,me,Ne)=>{q(Ee=>{const Ce=da(Ee);return Ce.set(cn(H,me),{permission:H,pattern:me,action:Ne}),Array.from(Ce.values())})},[]),Pe=l.useCallback((H,me)=>{q(Ne=>{const Ee=da(Ne);return Ee.delete(cn(H,me)),Array.from(Ee.values())})},[]),Te=l.useCallback((H,me)=>{const Ne=ie.get(cn(H,me));if(Ne){Ae(H,me,Ne.action);return}Pe(H,me)},[ie,Pe,Ae]),Fe=l.useCallback((H,me,Ne)=>{Ae(H,me,Ne)},[Ae]),Be=l.useCallback(H=>{T(H),q(me=>me.filter(Ne=>!(Ne.pattern==="*"&&Ne.action===H)))},[]),We=l.useCallback(H=>{const me=R.trim();if(!me){_.error(s("settings.agents.page.toast.permissionNameRequired"));return}const Ne=F.trim()||"*";if(me==="*"&&Ne==="*"){Be(H),Y(""),W("*");return}Ne==="*"&&me!=="*"&&H===O?Pe(me,"*"):Ae(me,Ne,H),Y(""),W("*")},[O,R,F,Pe,Be,s,Ae]),ze=l.useCallback(H=>H==="*"?s("settings.agents.page.permissions.defaultLabel"):H==="webfetch"?"WebFetch":H==="websearch"?"WebSearch":H==="codesearch"?"CodeSearch":H==="doom_loop"?"Doom Loop":H==="external_directory"?"External Directory":H==="todowrite"?"TodoWrite":H==="todoread"?"TodoRead":H.split(/[_-]+/g).filter(Boolean).map(me=>me.charAt(0).toUpperCase()+me.slice(1)).join(" "),[s]);l.useEffect(()=>{Y(""),W("*");const H=me=>{const Ne=nn(me),Ee=Gu(Ne),Ce=Ju(Ne,Ee);return T(Ee),U(Ce),q(Ce),{global:Ee,rules:Ce}};if(p&&c){const me=c.name||"",Ne=c.scope||"user",Ee=c.description||"",Ce=c.mode||"subagent",_e=c.model||"",G=c.variant||"",$=c.temperature??void 0,fe=c.top_p??void 0,L=c.prompt||"";C(me),g(Ne),D(Ee),w(Ce),N(_e),b(G),z($),I(fe),j(L);const Le=ar(c.permission),Je=H(Le);le.current={draftName:me,draftScope:Ne,description:Ee,mode:Ce,model:_e,variant:G,temperature:$,topP:fe,prompt:L,globalPermission:Je.global,permissionRules:Je.rules};return}if(m&&a===m.name){const me=m.description||"",Ne=m.mode||"subagent",Ee=m.model?.providerID&&m.model?.modelID?`${m.model.providerID}/${m.model.modelID}`:"",Ce=m.variant||"",_e=m.temperature,G=m.topP,$=m.prompt||"";D(me),w(Ne),N(Ee),b(Ce),z(_e),I(G),j($);const fe=H(ar(m.permission));le.current={draftName:"",draftScope:"user",description:me,mode:Ne,model:Ee,variant:Ce,temperature:_e,topP:G,prompt:$,globalPermission:fe.global,permissionRules:fe.rules}}},[c,p,m,a]);const Qe=l.useMemo(()=>{const H=le.current;return H?!!(p&&(u!==H.draftName||f!==H.draftScope)||h!==H.description||k!==H.mode||E!==H.model||y!==H.variant||P!==H.temperature||M!==H.topP||v!==H.prompt||O!==H.globalPermission||!qu(Q,H.permissionRules)):!1},[h,u,f,O,p,k,E,Q,v,P,M,y]),oe=async()=>{const H=p?u.trim().replace(/\s+/g,"-"):a?.trim();if(!H){_.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(p&&d.some(me=>me.name===H)){_.error(s("settings.agents.sidebar.toast.agentExists"));return}de(!0);try{const me=E.trim(),Ne=y.trim(),Ee=v.trim(),Ce=Qu(O,Q),_e={name:H,description:h.trim()||void 0,mode:k,model:me===""?null:me,variant:Ne===""?null:Ne||void 0,temperature:P??null,top_p:M??null,prompt:Ee||(p?void 0:null),permission:Ce,scope:p?f:void 0};let G;p?(G=await i(_e),G.ok&&x(null)):G=await o(H,_e),G.ok?G.requiresManualRestart?_.warning(s("settings.agents.page.toast.savedManualRestart")):_.success(s(p?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):_.error(s(p?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(me){console.error("Error saving agent:",me);const Ne=me instanceof Error&&me.message?me.message:s("settings.agents.page.toast.saveUnexpectedError");_.error(Ne)}finally{de(!1)}};return a?t.jsx(Gt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p?s("settings.agents.page.title.new"):a}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(p?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.identityRole")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&t.jsxs("div",{"data-settings-item":"agents.name",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.agentName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),t.jsx(ot,{value:u,onChange:H=>C(H.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Mt,{value:f,onValueChange:H=>g(H),children:[t.jsx(Rt,{className:"w-fit min-w-[100px]",children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Tt,{align:"end",children:[t.jsx(gt,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(gt,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(hs,{value:h,onChange:H=>D(H.target.value),placeholder:s("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),t.jsx("div",{"data-settings-item":"agents.mode",className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.mode")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.modeTooltip")})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":k==="primary",onClick:()=>w("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":k==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":k==="all",onClick:()=>w("all"),className:"!font-normal",children:s("settings.agents.page.mode.all")})]})]})})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.modelParameters")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{"data-settings-item":"agents.model",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(Hr,{providerId:un(E)?.providerId??"",modelId:un(E)?.modelId??"",onChange:(H,me)=>{N(H&&me?`${H}/${me}`:""),b("")}})})]}),t.jsxs("div",{"data-settings-item":"agents.variant",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.variant")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.variantTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.variantHint")})]}),t.jsx("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:je?t.jsxs(Mt,{value:be,onValueChange:H=>b(H==="__default"?"":H),children:[t.jsx(Rt,{className:ce("max-w-full",e?"w-full":"w-fit min-w-[10rem]"),children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.variantPlaceholder"),children:H=>H==="__default"?s("chat.modelControls.default"):H})}),t.jsxs(Tt,{children:[t.jsx(gt,{value:"__default",children:s("chat.modelControls.default")}),he.map(H=>t.jsx(gt,{value:H,children:H},H))]})]}):t.jsxs(t.Fragment,{children:[t.jsx(ot,{value:y,onChange:H=>b(H.target.value),placeholder:s("settings.agents.page.field.variantPlaceholder"),disabled:!E&&!y,className:ce("h-7 w-40",e&&"w-full")}),y&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>b(""),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.common.actions.clear"),title:s("settings.common.actions.clear"),children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})})]}),t.jsxs("div",{"data-settings-item":"agents.temperature",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.temperature")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.temperatureTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.temperatureRange")})]}),t.jsxs("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(bs,{value:P,fallbackValue:.7,onValueChange:z,onClear:()=>z(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),P!==void 0&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>z(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTemperatureAria"),title:s("settings.common.actions.clear"),children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{"data-settings-item":"agents.top-p",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.topP")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.topPTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.topPRange")})]}),t.jsxs("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(bs,{value:M,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),M!==void 0&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTopPAria"),title:s("settings.common.actions.clear"),children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),t.jsxs("div",{"data-settings-item":"agents.system-prompt",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.systemPrompt")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(hs,{value:v,onChange:H=>j(H.target.value),placeholder:s("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),t.jsxs("div",{"data-settings-item":"agents.permissions",className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.toolPermissions")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>re(H=>!H),children:s(X?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),X?t.jsxs("div",{className:"space-y-6 px-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.permissions.globalDefault")}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),t.jsxs(Mt,{value:O,onValueChange:H=>Be(H),children:[t.jsx(Rt,{className:"w-[100px]",children:t.jsx(Kt,{children:Me(O)})}),t.jsxs(Tt,{children:[t.jsx(gt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(gt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(gt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:ne.filter(H=>H!=="*").map(H=>{const me=ze(H),{defaultAction:Ne,patternRulesCount:Ee}=ue(H),Ce=V(H),_e=Ce??"global",G=te(H),$=["allow","ask","deny"].filter(fe=>fe!==O);return t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[t.jsxs("div",{className:"flex items-center justify-between py-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:me}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:H})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Ee>0?s("settings.agents.page.permissions.globalSummary",{summary:Ne}):Ne})]}),t.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Ce&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>Te(H,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Mt,{value:_e,onValueChange:fe=>{if(fe==="global"){Pe(H,"*");return}Ae(H,"*",fe)},children:[t.jsx(Rt,{className:"w-[90px]",children:t.jsx(Kt,{children:ke(_e)})}),t.jsxs(Tt,{children:[t.jsx(gt,{value:"global",children:s("settings.common.scope.global")}),$.map(fe=>t.jsx(gt,{value:fe,className:"capitalize",children:Me(fe)},fe))]})]})]}),G.map(fe=>{const L=cn(fe.permission,fe.pattern),Le=ie.get(L),Je=!Le,Xe=!!(Le&&Le.action!==fe.action);return t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:fe.pattern}),Je&&t.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:s("settings.common.badge.new")}),Xe&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:s("settings.common.badge.modified")}),(Je||Xe)&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>Je?Pe(fe.permission,fe.pattern):Te(fe.permission,fe.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Mt,{value:fe.action,onValueChange:et=>Fe(fe.permission,fe.pattern,et),children:[t.jsx(Rt,{className:"w-[90px]",children:t.jsx(Kt,{children:Me(fe.action)})}),t.jsxs(Tt,{children:[t.jsx(gt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(gt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(gt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},L)})]})]},H)})}),t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[t.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:s("settings.agents.page.permissions.addCustomRule")}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[t.jsxs(Mt,{value:R,onValueChange:Y,children:[t.jsx(Rt,{className:"w-full sm:w-[160px]",children:R?t.jsx("span",{className:"truncate",children:ze(R)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Tt,{children:Re.map(H=>t.jsx(gt,{value:H,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:ze(H)})})},H))})]}),t.jsx(ot,{value:F,onChange:H=>W(H.target.value),placeholder:s("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>We("allow"),children:s("settings.common.permission.allow")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>We("ask"),children:s("settings.common.permission.ask")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>We("deny"),children:s("settings.common.permission.deny")})]})]})]})]}):t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ne.map((H,me)=>{const{defaultAction:Ne,patternRulesCount:Ee,patternSummary:Ce,hasDefaultHint:_e}=ue(H),G=ze(H),$=_e?`${Ne} (env blocked)`:Ne;return t.jsxs("div",{className:ce("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",me>0&&"border-t border-[var(--surface-subtle)]"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:G}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:H})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Ee>0?t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.globalSummary",{summary:$})}):t.jsx("span",{className:ce("typography-micro capitalize px-1.5 py-0.5 rounded",$==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":$==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:$}),Ee>0&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.rulesSummary",{summary:Ce})})]})]},H)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:oe,disabled:Z||!Qe,size:"xs",className:"!font-normal",children:s(Z?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.agents.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.agents.page.empty.description")})]})})},Zu="~/.config/opencode/AGENTS.md",El=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},ep=s=>s.length>0&&!s.endsWith(`
1
+ import{ak as gc,e as rt,al as hc,j as t,H as ve,am as fc,an as xc,a as rn,d as ta,p as Br,b as Ur,R as l,L as Ss,ab as bc,ac as yc,aa as vc,ad as jc,a8 as wc,a9 as Nc,ae as kc,ao as Sc,ap as Cc,aq as Pc,u as Ic,l as Dc,n as Ac,w as Ec,C as Mc,S as Rc,ar as Tc,a6 as Fc,D as Oc,q as Lc,as as zc,at as Kc,au as $c,av as Bc,aw as Uc,X as Os,ax as Vc,ay as xn,az as Zr,aA as _c,aB as Hc,aC as Wa,aD as Wc,aE as qc,aF as Gc,aG as ei,aH as Ra,aI as ti,k as Na,aJ as ml,aK as Vr,aL as za,aM as ul,aN as si,aO as Jc,aP as Qc,aQ as Yc,aR as Xc,aS as ni,aT as Oe,aU as aa,aV as Zc,aW as ed,aX as td,aY as sd,aZ as nd,a_ as pl,a7 as ad,a$ as ai,b0 as rd,b1 as id,b2 as od,b3 as ld}from"./vendor-.bun-By2L9XvG.js";import{dy as Ka,r as Ta,v as Fa,m as ce,dz as ka,dA as Sa,dB as Ca,D as is,u as dt,I as A,aw as Pt,ax as It,ay as Dt,dC as cd,au as Ws,a_ as $t,aZ as Bt,aY as Ut,bC as Gt,w as wr,bb as _r,p as mn,at as Cs,t as _,cn as gl,B as J,dD as Dn,dE as dd,dF as md,dj as ud,dG as pd,dH as gd,dI as hd,z as Is,dJ as fd,cR as xd,cS as bd,cT as yd,c2 as vd,ap as us,ar as ps,c3 as jd,as as gs,aS as $a,dK as wd,dL as Sn,aX as _t,bo as Wt,bK as Yt,n as ot,dM as Xn,ao as vs,Q as ut,dg as Nd,bD as Mt,bE as Rt,bF as Kt,bG as Tt,bH as gt,b9 as hs,aT as Hr,dN as un,ba as St,dO as hl,dP as kd,dQ as Sd,dR as Ba,dS as Hs,dT as An,aV as fl,dU as Cn,dV as Cd,dW as Pd,dX as Id,dY as Dd,dZ as Ad,d_ as Ed,d$ as Vs,e0 as Md,q as Ua,c8 as ri,k as Rd,ca as Nr,a3 as xl,E as Td,P as bl,G as yl,cc as Fd,O as ii,c_ as Od,de as vl,d3 as jl,d5 as Ld,e1 as zd,cA as Kd,e2 as oi,e3 as $d,e4 as Bd,e5 as li,e6 as Ud,e7 as Vd,e8 as _d,e9 as Hd,av as Wd,ea as qd,H as Gd,K as Jd,a as Wr,aG as ci,eb as di,ec as mi,aJ as $n,ed as qa,ee as Qd,ef as Yd,ac as En,ab as wl,aa as Xd,eg as Zd,eh as ui,ad as em,ae as tm,a5 as sm,aA as nm,aB as am,aC as Nl,ei as Ga,ej as pi,ek as rm,el as im,em as om,en as lm,d6 as Va,R as _s,eo as cm,cb as kl,ep as dm,eq as mm,er as um,es as pm,et as Ja,eu as gi,ev as gm,ew as hm,ex as fm,ey as xm,ez as bm,eA as Qa,eB as ym,eC as hi,eD as Gn,eE as vm,aP as fi,eF as Nn,aO as jm,eG as wm,eH as xi,eI as bi,X as Ys,F as Nm,S as km,eJ as Sm,cl as ra,bg as kr,bh as Sr,bi as Cr,bj as Pr,bk as Us,bl as Rs,bL as Pn,M as Qn,eK as yi,bX as Cm,eL as Sl,bN as Pm,da as Im,f as Dm,eM as Ya,a2 as Am,b3 as ia,bR as Em,eN as Mm,eO as Rm,d4 as Tm,eP as Fm,eQ as Om}from"./useAppFontEffects-B66TruVB.js";import{D as Zn,e as yt,o as ws,u as ys,a2 as Lm,a3 as vi,a4 as zm,a5 as Km,w as fs,K as dn,b as Ke,j as sa,f as Ct,a as ea,q as zs,h as ds,a6 as $m,F as Bm,a7 as Xa,E as Um,a8 as ji,a9 as Vm,x as _m,aa as wi,ab as Ni,ac as ki,ad as Si,ae as Za,af as Ci,C as Cl,ag as Hm,ah as Wm,ai as qm,a1 as Gm,L as Jm,aj as Qm,ak as Ym,al as Xm}from"./index-AsCHiJ5P.js";import{g as Zm,s as eu}from"./mobileLayoutPreference-Dio-WWkI.js";function tu(){return new Worker(gc,{type:"module"})}const su=["typescript","javascript","tsx","jsx","json","markdown"],Ir={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Pi,Ii;const Di=s=>{const e=Ir[s],n=new hc({workerFactory:tu,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:su,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},nu=s=>{if(!(typeof window>"u"))return s==="split"?(Ii??=Di("split"),Ii):(Pi??=Di("unified"),Pi)},au=s=>{const e=rt.c(7),{children:n,renderTheme:a}=s,r=Dr("unified"),i=Dr("split");let o,d;e[0]!==a||e[1]!==i||e[2]!==r?(o=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:Ir.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:Ir.split.lineDiffType})},d=[a,i,r],e[0]=a,e[1]=i,e[2]=r,e[3]=o,e[4]=d):(o=e[3],d=e[4]),ve.useEffect(o,d);let c;return e[5]!==n?(c=t.jsx(t.Fragment,{children:n}),e[5]=n,e[6]=c):c=e[6],c},Av=s=>{const e=rt.c(11),{children:n}=s,a=Ka();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const x=Ta(!1),m=Ta(!0),p=a?.lightThemeId??x.metadata.id,u=a?.darkThemeId??m.metadata.id;i=a?.availableThemes.find(C=>C.metadata.id===p)??x,r=a?.availableThemes.find(C=>C.metadata.id===u)??m,Fa(i),Fa(r),e[0]=a?.availableThemes,e[1]=a?.darkThemeId,e[2]=a?.lightThemeId,e[3]=r,e[4]=i}else r=e[3],i=e[4];let o;e[5]!==r.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:r.metadata.id},e[5]=r.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const d=o;let c;return e[8]!==n||e[9]!==d?(c=t.jsx(au,{renderTheme:d,children:n}),e[8]=n,e[9]=d,e[10]=c):c=e[10],c},Dr=s=>{const e=rt.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=nu(n),e[0]=n,e[1]=a):a=e[1],a};function ru(s){const e=rt.c(4);let n,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=t.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),a=t.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=a):(n=e[0],a=e[1]);let r;return e[2]!==s?(r=t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...s,children:[n,a]}),e[2]=s,e[3]=r):r=e[3],r}const Oa=ve.forwardRef((s,e)=>{const n=rt.c(11);let a,r;n[0]!==s?({className:a,...r}=s,n[0]=s,n[1]=a,n[2]=r):(a=n[1],r=n[2]);let i;n[3]!==a?(i=ce("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",a),n[3]=a,n[4]=i):i=n[4];let o;n[5]===Symbol.for("react.memo_cache_sentinel")?(o={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=o):o=n[5];let d;n[6]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(fc,{className:ce("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=d):d=n[6];let c;return n[7]!==r||n[8]!==e||n[9]!==i?(c=t.jsx(xc,{className:i,style:o,...r,ref:e,children:d}),n[7]=r,n[8]=e,n[9]=i,n[10]=c):c=n[10],c});Oa.displayName="Switch";const oa=()=>{try{const e=is.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=ws.getDirectory();if(n?.trim())return n.trim()}catch(s){console.warn("[McpConfigStore] Error resolving config directory:",s)}return null},Ai=s=>s?Object.entries(s).map(([e,n])=>({key:e,value:n})):[],Ei=s=>{const e=s.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},la=s=>typeof s!="string"?void 0:s.trim()||void 0,er=800,iu=5e3,ou="__default__",Ar=new Map,tr=new Map,Pl=s=>s?.trim()||ou,sr=s=>{Ar.delete(Pl(s))},Rn=rn()(ta(Br((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=oa(),r=Pl(a),i=Date.now(),o=Ar.get(r)??0,d=e().mcpServers.length>0;if(!n?.force&&d&&i-o<iu)return!0;const c=tr.get(r);if(!n?.force&&c)return c;const x=(async()=>{s({isLoading:!0});try{const m=a?`?directory=${encodeURIComponent(a)}`:"",p=await yt(`/api/config/mcp${m}`,{headers:a?{"x-opencode-directory":a}:void 0});if(!p.ok)throw new Error("Failed to load MCP configs");const u=await p.json();return s({mcpServers:u,isLoading:!1}),Ar.set(r,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),s({isLoading:!1}),!1}})();tr.set(r,x);try{return await x}finally{tr.delete(r)}},createMcp:async n=>{ka("Creating MCP server configuration…");let a=!1;try{const r=Mi(n),i=oa(),o=i?`?directory=${encodeURIComponent(i)}`:"",d=await yt(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(r)}),c=await d.json().catch(()=>null);if(!d.ok)throw new Error(c?.error||"Failed to create MCP server");return sr(i),c?.requiresReload?(a=!0,await Sa({message:c.message,delayMs:c.reloadDelayMs??er,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning})}catch(r){return console.error("[McpConfigStore] Failed to create MCP:",r),{ok:!1}}finally{a||Ca()}},updateMcp:async(n,a)=>{ka("Updating MCP server configuration…");let r=!1;try{const i=Mi(a),o=oa(),d=o?`?directory=${encodeURIComponent(o)}`:"",c=await yt(`/api/config/mcp/${encodeURIComponent(n)}${d}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),x=await c.json().catch(()=>null);if(!c.ok)throw new Error(x?.error||"Failed to update MCP server");return sr(o),x?.requiresReload?(r=!0,await Sa({message:x.message,delayMs:x.reloadDelayMs??er,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:x?.reloadFailed===!0,message:x?.message,warning:x?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:x?.reloadFailed===!0,message:x?.message,warning:x?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||Ca()}},deleteMcp:async n=>{ka("Deleting MCP server configuration…");let a=!1;try{const r=oa(),i=r?`?directory=${encodeURIComponent(r)}`:"",o=await yt(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:r?{"x-opencode-directory":r}:void 0}),d=await o.json().catch(()=>null);if(!o.ok)throw new Error(d?.error||"Failed to delete MCP server");return sr(r),d?.requiresReload&&(a=!0,await Sa({message:d.message,delayMs:d.reloadDelayMs??er,scopes:["all"]})),e().selectedMcpName===n&&s({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}}catch(r){return console.error("[McpConfigStore] Failed to delete MCP:",r),{ok:!1}}finally{a||Ca()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:Ur(()=>Zn()),partialize:s=>({selectedMcpName:s.selectedMcpName})}),{name:"mcp-config-store"}));function Mi(s){const e={};if(s.scope!==void 0&&(e.scope=s.scope),s.type!==void 0&&(e.type=s.type),(s.type==="local"||s.command!==void 0)&&(e.command=(s.command??[]).filter(n=>n.trim())),(s.type==="remote"||s.url!==void 0)&&(e.url=s.url?.trim()??""),s.environment!==void 0&&(e.environment=Ei(s.environment)??{}),s.headers!==void 0&&(e.headers=Ei(s.headers)??{}),s.oauthEnabled!==void 0||s.oauthClientId!==void 0||s.oauthClientSecret!==void 0||s.oauthScope!==void 0||s.oauthRedirectUri!==void 0)if(s.oauthEnabled===!1)e.oauth=!1;else{const n={clientId:la(s.oauthClientId),clientSecret:la(s.oauthClientSecret),scope:la(s.oauthScope),redirectUri:la(s.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:s.oauthEnabled?e.oauth={}:e.oauth=!1}if(s.timeout!==void 0){const n=Number(s.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return s.enabled!==void 0&&(e.enabled=s.enabled),e}const lu={},cu={},Bs=s=>{if(typeof s!="string")return null;const e=s.trim();if(!e)return null;const n=e.replace(/\\/g,"/");return n.length>1?n.replace(/\/+$/,""):n},jn=s=>Bs(s)??"__global__",on=s=>{const e=Bs(s);return e?ws.getScopedApiClient(e):ws.getApiClient()},ls=rn()(ta((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=jn(n??ys.getState().currentDirectory);return e().byDirectory[a]??lu},getDiagnosticForDirectory:n=>{const a=jn(n??ys.getState().currentDirectory);return e().diagnosticsByDirectory[a]??cu},getErrorForDirectory:n=>{const a=jn(n??ys.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=Bs(n?.directory??ys.getState().currentDirectory),r=jn(a);n?.silent||s(i=>({loadingKeys:{...i.loadingKeys,[r]:!0},lastErrorKeys:{...i.lastErrorKeys,[r]:null}}));try{const d=(await on(a).mcp.status()).data??{};s(c=>({byDirectory:{...c.byDirectory,[r]:d},diagnosticsByDirectory:{...c.diagnosticsByDirectory,[r]:Object.fromEntries(Object.entries(c.diagnosticsByDirectory[r]??{}).filter(([x])=>!d[x]))},loadingKeys:{...c.loadingKeys,[r]:!1},lastErrorKeys:{...c.lastErrorKeys,[r]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";s(d=>({loadingKeys:{...d.loadingKeys,[r]:!1},lastErrorKeys:{...d.lastErrorKeys,[r]:o}}))}},connect:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory),i=jn(r),o=on(r);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(d){const c=d instanceof Error?d.message:"Connection failed";throw s(x=>({diagnosticsByDirectory:{...x.diagnosticsByDirectory,[i]:{...x.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:c}}}})),d}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory);await on(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory),d=(await on(r).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!d)throw new Error("Authorization URL was not returned");return d},completeAuth:async(n,a,r)=>{const i=Bs(r??ys.getState().currentDirectory);await on(i).mcp.auth.callback({name:n,code:a},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory);await on(r).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},testConnection:async(n,a)=>{const r=Bs(a??ys.getState().currentDirectory),i=jn(r),o=on(r),c=e().getStatusForDirectory(r)[n]?.status==="connected";let x,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(C){x=C instanceof Error?C.message:"Connection failed",s(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:x??"Connection failed"}}}}))}await e().refresh({directory:r,silent:!0});const p=e().getStatusForDirectory(r)[n],u=p;if(!c&&p?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(C){m=`Connection test succeeded, but cleanup disconnect failed: ${C instanceof Error?C.message:"Disconnect failed"}`}await e().refresh({directory:r,silent:!0})}return{status:u??e().getStatusForDirectory(r)[n],error:x,warning:m}}}))),du=(s,e)=>{if(!s)return e("mcpDropdown.status.unknown");switch(s.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:s.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:s.error||""});default:return s.status}},mu=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Ev=({active:s,className:e,headerAction:n,listClassName:a,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:o}=dt(),c=ys(N=>N.currentDirectory)??null,x=ls(N=>N.getStatusForDirectory(c)),m=ls(N=>N.refresh),p=ls(N=>N.connect),u=ls(N=>N.disconnect),C=Rn(N=>N.mcpServers),f=Rn(N=>N.loadMcpConfigs),[g,h]=l.useState(!1),[D,k]=l.useState(null);l.useEffect(()=>{m({directory:c,silent:!0})},[m,c]),l.useEffect(()=>{f({force:!0})},[f]),l.useEffect(()=>{s&&Promise.all([m({directory:c,silent:!0}),f({force:!0})])},[s,m,c,f]);const w=l.useMemo(()=>{const N=new Set(Object.keys(x));for(const y of C)y?.name&&N.add(y.name);return Array.from(N).sort((y,b)=>y.localeCompare(b))},[C,x]),E=l.useCallback(N=>{if(N?.preventDefault(),g)return;h(!0);const y=new Promise(b=>setTimeout(b,500));Promise.all([m({directory:c}),y]).finally(()=>{h(!1)})},[g,m,c]);return t.jsxs("div",{className:ce("w-full",e),children:[r?null:t.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:t.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[t.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[t.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:o("mcpDropdown.title")}),c&&t.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:c.split("/").pop()||c})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n,t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:g,onClick:E,"aria-label":o("mcpDropdown.actions.refreshAria"),children:t.jsx(A,{name:"refresh",className:ce("h-4 w-4",g&&"animate-spin")})})]})]})}),t.jsxs("div",{className:ce("max-h-64 overflow-y-auto py-2",i&&"space-y-1 py-3",a),children:[w.map(N=>{const y=x[N],b=mu(y),P=y?.status==="connected",z=D===N,M=du(y,o);return t.jsxs("div",{className:ce("flex items-center justify-between rounded-lg hover:bg-interactive-hover/50",i?"gap-3 px-4 py-3":"gap-2 px-4 py-1.5"),children:[t.jsx("div",{className:"min-w-0 flex-1",children:t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx("span",{className:ce("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",b==="success"&&"bg-status-success",b==="error"&&"bg-status-error",b==="warning"&&"bg-status-warning",b==="default"&&"bg-muted-foreground/40"),"aria-label":M})}),t.jsx(Dt,{side:"left",children:t.jsx("p",{children:M})})]}),t.jsx("span",{className:ce("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:N})]})}),t.jsx(Oa,{checked:P,disabled:z,className:"data-[checked]:bg-status-info",onCheckedChange:async I=>{k(N);try{I?await p(N,c):await u(N,c)}finally{k(null)}}})]},N)}),w.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:o("mcpDropdown.empty.configureInConfig")})]})]})};function uu(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=cd();return s}catch{return"unknown"}}function pu(){const s=typeof window<"u"?window.__VSCODE_CONFIG__?.arch?.toLowerCase?.():void 0;if(s==="arm64"||s==="aarch64")return"arm64";if(s==="x64"||s==="amd64"||s==="x86_64")return"x64";const n=(typeof navigator<"u"?navigator.userAgentData:void 0)?.architecture?.toLowerCase?.();if(n==="arm"||n==="arm64"||n==="aarch64")return"arm64";if(n==="x86"||n==="x64"||n==="amd64")return"x64";const a=typeof navigator<"u"?navigator.userAgent.toLowerCase():"";return a.includes("aarch64")||a.includes("arm64")||a.includes("armv")?"arm64":a.includes("x86_64")||a.includes("x64")||a.includes("amd64")||a.includes("win64")?"x64":"unknown"}function gu(){if(typeof navigator>"u")return"web";const s=(navigator.platform||"").toLowerCase();return s.includes("mac")?"macos":s.includes("win")?"windows":s.includes("linux")?"linux":"web"}function hu(s){const e=Ke.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",uu()),n.set("arch",pu()),n.set("platform",gu()),s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",sa()?"local":"remote"),n):s==="vscode"?(n.set("appType","vscode"),n.set("instanceMode","local"),n):(n.set("appType","web"),n.set("instanceMode","unknown"),n)}async function Ri(s,e){try{const n=hu(s),a=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e||s==="vscode"&&a&&n.set("currentVersion",a);const r=await yt(`/api/openchamber/update-check?${n.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!r.ok)throw new Error(`Server responded with ${r.status}`);const i=await r.json();return{available:i.available??!1,version:i.version,currentVersion:i.currentVersion??"unknown",body:i.body,nextSuggestedCheckInSec:typeof i.nextSuggestedCheckInSec=="number"&&Number.isFinite(i.nextSuggestedCheckInSec)?i.nextSuggestedCheckInSec:void 0,packageManager:i.packageManager,updateCommand:i.updateCommand}}catch(n){return console.warn("Failed to check for updates:",n),null}}function fu(){return Km()?"desktop":fs()?"vscode":dn()?"web":null}const Ti={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Il=rn()((s,e)=>({...Ti,checkForUpdates:async()=>{const n=fu();if(!n)return null;s({checking:!0,error:null,runtimeType:n});try{let a=null,r=null;if(n==="desktop"){const i=await vi();return s({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null}),r}else n==="web"?(a=await Ri("web"),r=a?.nextSuggestedCheckInSec??null):n==="vscode"&&(r=(await Ri("vscode"))?.nextSuggestedCheckInSec??null);return s({checking:!1,available:n==="vscode"?!1:a?.available??!1,info:n==="vscode"?null:a,lastChecked:Date.now(),nextCheckInSec:r}),r}catch(a){return s({checking:!1,error:a instanceof Error?a.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:a}=e();if(!(a!=="desktop"||!n)){s({downloading:!0,error:null,progress:null});try{const r=await vi();if(!r?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(s(o=>({info:o.info?{...o.info,...r,body:o.info.body||r.body,available:o.info.available}:r})),!await zm(o=>{s({progress:o})}))throw new Error("Desktop update only works on Local instance");s({downloading:!1,downloaded:!0})}catch(r){s({downloading:!1,error:r instanceof Error?r.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:a}=e();if(!(a!=="desktop"||!n))try{if(!await Lm())throw new Error("Desktop restart only works on Local instance")}catch(r){s({error:r instanceof Error?r.message:"Failed to restart"})}},dismiss:()=>{s({available:!1,downloaded:!1,info:null})},reset:()=>{s(Ti)}})),Fi="https://github.com/btriapitsyn/openchamber/releases";function xu(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(_r(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function bu(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Oi(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function yu(s,e){const n=s.split(".").map(r=>Number.parseInt(r,10)),a=e.split(".").map(r=>Number.parseInt(r,10));for(let r=0;r<3;r+=1){const i=Number.isFinite(n[r])?n[r]:0,o=Number.isFinite(a[r])?a[r]:0;if(i!==o)return o-i}return 0}function vu(s){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let a;for(;(a=e.exec(s))!==null;)n.push({version:a[1]??"",date:a[2]??"",start:a.index});return n.length===0?[]:n.map((r,i)=>{const o=n[i+1]?.start??s.length,d=s.slice(r.start,o).trim();return{version:r.version,date:r.date,start:r.start,end:o,raw:d}})}const Li=2e3,ju=600*1e3;async function wu(){try{const s=await yt("/api/openchamber/update-install",{method:"POST",headers:{"Content-Type":"application/json"}});return s.ok?{success:!0,autoRestart:(await s.json().catch(()=>({}))).autoRestart!==!1}:{success:!1,error:(await s.json().catch(()=>({}))).error||`Server error: ${s.status}`}}catch(s){return{success:!1,error:s instanceof Error?s.message:void 0}}}async function Nu(){try{return(await yt("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function ku(s,e=Math.ceil(ju/Li),n=Li){for(let a=0;a<e;a++){try{const r=await yt("/api/openchamber/update-check",{method:"GET",headers:{Accept:"application/json"}});if(r.ok){const i=await r.json().catch(()=>null);if(i&&i.available===!1||i&&typeof i.currentVersion=="string"&&typeof s=="string"&&i.currentVersion!==s)return!0}else if((r.status===401||r.status===403)&&await Nu())return!0}catch{}await new Promise(r=>setTimeout(r,n))}return!1}const zi=({open:s,onOpenChange:e,info:n,downloading:a,downloaded:r,progress:i,error:o,onDownload:d,onRestart:c,runtimeType:x="desktop"})=>{const{t:m}=dt(),[p,u]=ve.useState(!1),[C,f]=ve.useState("idle"),[g,h]=ve.useState(null),D=n?.version?`${Fi}/tag/v${n.version}`:Fi,k=i?.total?Math.round(i.downloaded/i.total*100):0,w=x==="web",E=n?.updateCommand||"openchamber update";ve.useEffect(()=>{s||(f("idle"),h(null))},[s]);const N=async()=>{(await mn(E)).ok&&(u(!0),setTimeout(()=>u(!1),2e3))},y=ve.useCallback(async M=>{await Ws(M)},[]),b=ve.useCallback(async()=>{f("updating"),h(null);const M=await wu();if(!M.success){f("error"),h(M.error||m("updateDialog.error.updateFailed"));return}M.autoRestart&&(f("restarting"),await new Promise(v=>setTimeout(v,2e3))),f("reconnecting"),await ku(n?.currentVersion)?window.location.reload():(f("error"),h(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),P=C!=="idle"&&C!=="error",z=ve.useMemo(()=>{if(!n?.body)return null;const M=n.body.trim();if(!M)return null;const I=vu(M);if(I.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Oi(M)};const v=[...I].sort((j,O)=>yu(j.version,O.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:v.map(j=>({version:j.version,dateLabel:xu(j.date),content:Oi(bu(j.raw)||M)}))}},[n?.body,m]);return t.jsx($t,{open:s,onOpenChange:P?void 0:e,children:t.jsxs(Bt,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[t.jsxs("div",{className:"flex items-center mb-1",children:[t.jsxs(Ut,{className:"flex items-center gap-2.5",children:[t.jsx(A,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),t.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(C==="restarting"||C==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&t.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&t.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&t.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&t.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),t.jsxs("div",{className:"space-y-2",children:[w&&P&&t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(A,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),t.jsxs("div",{className:"typography-ui-label text-foreground",children:[C==="updating"&&m("updateDialog.status.installingUpdate"),C==="restarting"&&m("updateDialog.status.serverRestarting"),C==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),t.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),z&&!P&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(Gt,{className:"max-h-[400px] p-0",fillContainer:!1,children:z.kind==="raw"?t.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:M=>{const v=M.target.closest("a");v&&v.href&&(M.preventDefault(),M.stopPropagation(),y(v.href))},children:t.jsx(wr,{content:z.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:z.sections.map(M=>t.jsxs("div",{className:"p-4",children:[t.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[t.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",M.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:M.dateLabel})]}),t.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline [&_a:hover]:!underline",onClickCapture:I=>{const j=I.target.closest("a");j&&j.href&&(I.preventDefault(),I.stopPropagation(),y(j.href))},children:t.jsx(wr,{content:M.content,disableLinkSafety:!0,enableFileReferences:!1})})]},M.version))})})}),w&&C==="error"&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[t.jsx(A,{name:"terminal",className:"h-4 w-4"}),t.jsx("span",{children:m("updateDialog.fallback.updateViaTerminal")})]}),t.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[t.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:E}),t.jsx("button",{onClick:N,className:ce("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",p&&"text-[var(--status-success)]"),title:m(p?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:p?t.jsx(A,{name:"check",className:"h-4 w-4"}):t.jsx(A,{name:"clipboard",className:"h-4 w-4"})})]})]}),!w&&a&&t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),t.jsxs("span",{className:"font-mono text-foreground",children:[k,"%"]})]}),t.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${k}%`}})})]}),(o||g)&&t.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:t.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||g})})]}),t.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[t.jsxs("a",{href:D,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[t.jsx(A,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!w&&!r&&!a&&t.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!w&&a&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!w&&r&&t.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[t.jsx(A,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),w&&!P&&t.jsxs("button",{onClick:b,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[t.jsx(A,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),w&&P&&t.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},Ki="https://github.com/openchamber/openchamber",Su="https://discord.gg/ZYRSdnwwKA",$i="https://x.com/openchamber_dev",Cu=800,Dl=({initialUpdateDialogOpen:s=!1})=>{const{t:e}=dt(),[n,a]=l.useState(s),[r,i]=l.useState(!1),[o,d]=l.useState(null),[c,x]=l.useState(null),m=Il(Ss(g=>({info:g.info,checking:g.checking,available:g.available,error:g.error,downloading:g.downloading,downloaded:g.downloaded,progress:g.progress,runtimeType:g.runtimeType,checkForUpdates:g.checkForUpdates,downloadUpdate:g.downloadUpdate,restartToUpdate:g.restartToUpdate}))),{isMobile:p}=Cs(),u=o||m.info?.currentVersion||"unknown";l.useEffect(()=>{let g=!1;return(async()=>{try{const D=await yt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const k=await D.json().catch(()=>null),w=typeof k?.openchamberVersion=="string"&&k.openchamberVersion.trim().length>0?k.openchamberVersion.trim():null;g||d(w)}catch{g||d(null)}})(),()=>{g=!0}},[]),l.useEffect(()=>{let g=!1;return(async()=>{try{const D=await yt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const k=await D.json().catch(()=>null),w=typeof k?.currentVersion=="string"&&k.currentVersion.trim().length>0?k.currentVersion.trim():null;g||x(w)}catch{g||x(null)}})(),()=>{g=!0}},[]);const C=l.useRef(!1);l.useEffect(()=>{if(m.checking)i(!0),C.current=!0;else if(r){const g=setTimeout(()=>{i(!1),C.current&&!m.available&&!m.error&&(_.success(e("settings.openchamber.about.toast.latestVersion")),C.current=!1)},Cu);return()=>clearTimeout(g)}},[e,m.checking,r,m.available,m.error]);const f=m.checking||r;return p?t.jsxs("div",{className:"w-full space-y-6 pb-2",children:[t.jsxs("div",{className:"flex flex-col items-center text-center",children:[t.jsx(gl,{width:72,height:72}),t.jsx("h2",{className:"mt-4 typography-ui-header font-semibold text-foreground",children:"OpenChamber"}),t.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[t.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:u})}),t.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]})]}),t.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&t.jsxs(J,{type:"button",variant:"outline",size:"sm",onClick:()=>m.checkForUpdates(),disabled:f,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[f?t.jsx(A,{name:"loader",className:"size-4 animate-spin"}):t.jsx(A,{name:"refresh",className:"size-4"}),e(f?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!f&&m.available&&t.jsxs(J,{type:"button",variant:"default",size:"sm",onClick:()=>a(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[t.jsx(A,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]})]}),m.error&&t.jsx("p",{className:"rounded-xl border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-3 py-2 typography-meta text-[var(--status-error)]",children:m.error}),t.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[t.jsxs("div",{className:"flex items-center justify-center gap-5",children:[t.jsxs("a",{href:Ki,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(A,{name:"github-fill",className:"size-5"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:Su,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(A,{name:"discord-fill",className:"size-5"}),t.jsx("span",{children:"Discord"})]})]}),t.jsxs("a",{href:$i,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[t.jsx(A,{name:"twitter-xfill",className:"size-5"}),t.jsx("span",{children:"@openchamber_dev"})]})]}),t.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),t.jsx(zi,{open:n,onOpenChange:a,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]}):t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-3 px-1",children:t.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:e("settings.openchamber.about.title")})}),t.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.version")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:u})]}),t.jsxs("div",{className:"flex min-w-0 flex-col",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.openchamber.about.field.openCodeVersion")}),t.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[t.jsx(A,{name:"loader",className:"h-4 w-4 animate-spin"}),t.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!m.checking&&m.available&&t.jsxs(J,{size:"sm",variant:"default",onClick:()=>a(!0),children:[t.jsx(A,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]}),!m.checking&&!m.available&&!m.error&&t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t.jsx(J,{size:"sm",variant:"outline",onClick:()=>m.checkForUpdates(),disabled:m.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),m.error&&t.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:t.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m.error})}),t.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[t.jsxs("a",{href:Ki,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[t.jsx(A,{name:"github-fill",className:"h-4 w-4"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:$i,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[t.jsx(A,{name:"twitter-xfill",className:"h-4 w-4"}),t.jsx("span",{children:"@openchamber_dev"})]})]})]}),t.jsx(zi,{open:n,onOpenChange:a,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]})},Mv=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),Pu=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),Iu=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},Du=s=>!s||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),Bn="opencode-update-available",ca="opencode-upgrade-progress",Au=5e3,Eu=[1e4,6e4],Bi="opencode-update-toast-dismissed-version",Rv=()=>{const{t:s}=dt(),e=Ke(o=>o.showOpenCodeUpdateNotifications),n=ve.useRef(new Set),a=ve.useRef(!1);ve.useEffect(()=>{e||_.dismiss(Bn)},[e]);const r=ve.useCallback(()=>{_.dismiss(ca),Dn({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),i=ve.useCallback(async()=>{if(!a.current){a.current=!0,_.dismiss(Bn),_.message(s("opencodeUpdate.toast.upgrading.title"),{id:ca,description:s("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:t.jsx(A,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const o=await yt("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),d=await o.json().catch(()=>null);if(!o.ok||d?.success===!1)throw new Error(d?.error||o.statusText||s("opencodeUpdate.toast.failed.description"));_.success(s("opencodeUpdate.toast.updated.title"),{id:ca,description:d?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:d.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(A,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(o){_.error(s("opencodeUpdate.toast.failed.title"),{id:ca,description:o instanceof Error?o.message:s("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{a.current=!1}}},[r,s]);return ve.useEffect(()=>{const o=p=>{if(!Ke.getState().showOpenCodeUpdateNotifications){_.dismiss(Bn);return}Pu({version:p,dismissedVersion:Zn().getItem(Bi),seenVersions:n.current})&&(n.current.add(p),_.info(s("opencodeUpdate.toast.available.title"),{id:Bn,description:s("opencodeUpdate.toast.available.description",{version:p}),duration:1/0,action:{label:s("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:s("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{Zn().setItem(Bi,p),Ct({openCodeUpdateToastDismissedVersion:p}),_.dismiss(Bn)}}}))},d=p=>{const u=Iu(p.detail);o(u)};let c=!1;const x=[],m=async p=>{try{const u=await yt("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!u.ok)throw new Error(u.statusText||"OpenCode upgrade status check failed");const C=await u.json().catch(()=>null),f=Du(C);!c&&f&&o(f)}catch{const u=Eu[p];!c&&u!==void 0&&x.push(setTimeout(()=>{m(p+1)},u))}};return e&&x.push(setTimeout(()=>{m(0)},Au)),window.addEventListener("openchamber:opencode-update-available",d),()=>{c=!0;for(const p of x)clearTimeout(p);window.removeEventListener("openchamber:opencode-update-available",d)}},[i,e,s]),null},Tv=()=>{const s=rt.c(3),[e,n]=l.useState(Mu),{isUpdating:a}=e;let r,i;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>md(n),i=[],s[0]=r,s[1]=i):(r=s[0],i=s[1]),l.useEffect(r,i),!a)return null;let o;return s[2]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-background/90",children:t.jsx(gl,{width:80,height:80,isAnimated:!0})}),s[2]=o):o=s[2],o};function Mu(){return dd()}class Ru extends l.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?t.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:t.jsxs(ud,{className:"w-full max-w-md",children:[t.jsx(pd,{className:"text-center",children:t.jsxs(gd,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(A,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(hd,{className:"space-y-4",children:[t.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&t.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[t.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),t.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),t.jsx("div",{className:"flex gap-2",children:t.jsxs(J,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-2"}),this.props.texts.resetAction]})}),t.jsx("div",{className:"text-xs text-muted-foreground text-center",children:this.props.texts.persistentHint})]})]})}):this.props.children}}function Tu(s){const e=rt.c(22),{t:n}=dt();let a;e[0]!==n?(a=n("chat.errorBoundary.title"),e[0]=n,e[1]=a):a=e[1];let r;e[2]!==n?(r=n("chat.errorBoundary.description"),e[2]=n,e[3]=r):r=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let d;e[8]!==n?(d=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=d):d=e[9];let c;e[10]!==n?(c=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=c):c=e[11];let x;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==o||e[16]!==d||e[17]!==c?(x={title:a,description:r,sessionLabel:i,detailsSummary:o,resetAction:d,persistentHint:c},e[12]=a,e[13]=r,e[14]=i,e[15]=o,e[16]=d,e[17]=c,e[18]=x):x=e[18];let m;return e[19]!==s||e[20]!==x?(m=t.jsx(Ru,{...s,texts:x}),e[19]=s,e[20]=x,e[21]=m):m=e[21],m}const Fv=s=>{const e=rt.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=Is(Fu)||void 0;let o;e[0]!==a?(o=t.jsx(fd,{readOnly:a}),e[0]=a,e[1]=o):o=e[1];let d;return e[2]!==i||e[3]!==o?(d=t.jsx(Tu,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=d):d=e[4],d};function Fu(s){return s.currentSessionId}function en(s){const e=rt.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let a;return e[2]!==n?(a=t.jsx(bc,{...n}),e[2]=n,e[3]=a):a=e[3],a}function tn(s){const e=rt.c(4);let n;e[0]!==s?({...n}=s,e[0]=s,e[1]=n):n=e[1];let a;return e[2]!==n?(a=t.jsx(yc,{...n}),e[2]=n,e[3]=a):a=e[3],a}function sn(s){const e=rt.c(20);let n,a,r,i,o;e[0]!==s?({className:a,positionerClassName:r,children:n,style:o,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i,e[5]=o):(n=e[1],a=e[2],r=e[3],i=e[4],o=e[5]);let d;e[6]!==r?(d=ce("app-region-no-drag z-50",r),e[6]=r,e[7]=d):d=e[7];let c;e[8]!==o?(c={backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)",...o},e[8]=o,e[9]=c):c=e[9];let x;e[10]!==a?(x=ce(xd,a),e[10]=a,e[11]=x):x=e[11];let m;e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==x?(m=t.jsx(vc,{"data-slot":"dropdown-menu-content",style:c,className:x,...i,children:n}),e[12]=n,e[13]=i,e[14]=c,e[15]=x,e[16]=m):m=e[16];let p;return e[17]!==d||e[18]!==m?(p=t.jsx(wc,{children:t.jsx(Nc,{className:d,children:m})}),e[17]=d,e[18]=m,e[19]=p):p=e[19],p}function qs(s){const e=rt.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=ce(bd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(jc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}function Ov(s){const e=rt.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=ce(yd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(kc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}const Al=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),na=s=>{const e=rt.c(39),{className:n}=s,{t:a}=dt(),r=is(Ou),i=is(Lu),o=is(zu),d=fs();let c;e[0]!==r?(c=[...r].sort(Ku),e[0]=r,e[1]=c):c=e[1];const x=c;let m;e:{if(x.length===0){m=null;break e}let O;e[2]!==i||e[3]!==x?(O=x.find(T=>T.id===i)??x[0],e[2]=i,e[3]=x,e[4]=O):O=e[4],m=O}const p=m;if(d||x.length===0)return null;let u;e[5]!==p||e[6]!==a?(u=p?.label&&p.label.trim().length>0?p.label:p?.path.split("/").filter(Boolean).pop()||p?.path||a("settings.shared.projectSelector.fallbackProject"),e[5]=p,e[6]=a,e[7]=u):u=e[7];const C=u;let f;e[8]!==C?(f=Al(C),e[8]=C,e[9]=f):f=e[9];const g=f;let h;e[10]!==n?(h=ce(n),e[10]=n,e[11]=h):h=e[11];let D;e[12]!==a?(D=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=D):D=e[13];let k;e[14]!==a?(k=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=k):k=e[15];let w,E;e[16]===Symbol.for("react.memo_cache_sentinel")?(w=ce("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),E=t.jsx(A,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=w,e[17]=E):(w=e[16],E=e[17]);let N;e[18]!==g?(N=t.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:g}),e[18]=g,e[19]=N):N=e[19];let y;e[20]===Symbol.for("react.memo_cache_sentinel")?(y=t.jsx(A,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=y):y=e[20];let b;e[21]!==N||e[22]!==D||e[23]!==k?(b=t.jsx(us,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":D,title:k,className:w,children:[E,N,y]})}),e[21]=N,e[22]=D,e[23]=k,e[24]=b):b=e[24];const P=p?.id??"";let z;e[25]!==o?(z=O=>{O&&o(O)},e[25]=o,e[26]=z):z=e[26];let M;e[27]!==x?(M=x.map($u),e[27]=x,e[28]=M):M=e[28];let I;e[29]!==P||e[30]!==z||e[31]!==M?(I=t.jsx(ps,{align:"start",className:"w-auto",children:t.jsx(jd,{value:P,onValueChange:z,children:M})}),e[29]=P,e[30]=z,e[31]=M,e[32]=I):I=e[32];let v;e[33]!==b||e[34]!==I?(v=t.jsxs(gs,{children:[b,I]}),e[33]=b,e[34]=I,e[35]=v):v=e[35];let j;return e[36]!==v||e[37]!==h?(j=t.jsx("div",{className:h,children:v}),e[36]=v,e[37]=h,e[38]=j):j=e[38],j};function Ou(s){return s.projects}function Lu(s){return s.activeProjectId}function zu(s){return s.setActiveProject}function Ku(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function $u(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=Al(e);return t.jsx(vd,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function Bu(s,e){return`opencode:sidebar-group:${s}:${e}`}const Er=s=>{const e=rt.c(33),{label:n,count:a,storageKey:r,defaultExpanded:i,children:o}=s,d=i===void 0?!0:i;let c;e[0]!==n||e[1]!==r?(c=Bu(r,n),e[0]=n,e[1]=r,e[2]=c):c=e[2];const x=c,m=l.useId();let p;e[3]!==d||e[4]!==x?(p=()=>{try{const I=localStorage.getItem(x);if(I!==null)return I==="true"}catch{}return d},e[3]=d,e[4]=x,e[5]=p):p=e[5];const[u,C]=ve.useState(p);let f,g;e[6]!==u||e[7]!==x?(f=()=>{try{localStorage.setItem(x,String(u))}catch{}},g=[x,u],e[6]=u,e[7]=x,e[8]=f,e[9]=g):(f=e[8],g=e[9]),ve.useEffect(f,g);let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=()=>C(Uu),e[10]=h):h=e[10];let D;e[11]===Symbol.for("react.memo_cache_sentinel")?(D=ce("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=D):D=e[11];const k=!u&&"-rotate-90";let w;e[12]!==k?(w=ce("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",k),e[12]=k,e[13]=w):w=e[13];let E;e[14]!==w?(E=t.jsx(A,{name:"arrow-down-s",className:w}),e[14]=w,e[15]=E):E=e[15];let N;e[16]!==n?(N=t.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=N):N=e[17];let y;e[18]!==a?(y=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=y):y=e[19];let b;e[20]!==m||e[21]!==u||e[22]!==E||e[23]!==N||e[24]!==y?(b=t.jsxs("button",{type:"button",onClick:h,"aria-expanded":u,"aria-controls":m,className:D,children:[E,N,y]}),e[20]=m,e[21]=u,e[22]=E,e[23]=N,e[24]=y,e[25]=b):b=e[25];const P=!u;let z;e[26]!==o||e[27]!==m||e[28]!==P?(z=t.jsx("div",{id:m,hidden:P,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[26]=o,e[27]=m,e[28]=P,e[29]=z):z=e[29];let M;return e[30]!==b||e[31]!==z?(M=t.jsxs("div",{children:[b,z]}),e[30]=b,e[31]=z,e[32]=M):M=e[32],M};function Uu(s){return!s}const Vu=s=>{if(!Array.isArray(s))return[];const e=[];for(const n of s){if(!n||typeof n!="object")continue;const a=n;typeof a.permission!="string"||typeof a.pattern!="string"||typeof a.action!="string"||a.action!=="allow"&&a.action!=="ask"&&a.action!=="deny"||e.push({permission:a.permission,pattern:a.pattern,action:a.action})}return e},_u=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},Ui=s=>{const e=_u(Vu(s));if(e.length===0)return;const n={};for(const r of e)r.permission&&((n[r.permission]||={})[r.pattern]=r.action);const a={};for(const[r,i]of Object.entries(n)){const o=Object.keys(i);if(o.length===1&&o[0]==="*"){a[r]=i["*"];continue}a[r]=i}return Object.keys(a).length>0?a:void 0},Hu=({onItemSelect:s})=>{const{t:e}=dt(),[n,a]=l.useState(null),[r,i]=l.useState(""),[o,d]=l.useState(null),[c,x]=l.useState(null),[m,p]=l.useState(!1),[u,C]=l.useState(null),{selectedAgentName:f,agents:g,setSelectedAgent:h,setAgentDraft:D,createAgent:k,deleteAgent:w,loadAgents:E}=$a(Ss(R=>({selectedAgentName:R.selectedAgentName,agents:R.agents,setSelectedAgent:R.setSelectedAgent,setAgentDraft:R.setAgentDraft,createAgent:R.createAgent,deleteAgent:R.deleteAgent,loadAgents:R.loadAgents})));l.useEffect(()=>{E()},[E]);const N="bg-background",y=()=>{const R="new-agent";let Y=R,F=1;for(;g.some(W=>W.name===Y);)Y=`${R}-${F}`,F++;D({name:Y,scope:"user"}),h(Y),s?.()},b=async R=>{if(Sn(R)){_.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(R),x("delete")},P=async R=>{Sn(R)&&(d(R),x("reset"))},z=()=>{d(null),x(null)},M=async()=>{if(!(!o||!c)){p(!0);try{const R=await w(o.name,o.scope);R.ok?(R.requiresManualRestart?_.warning(e("settings.agents.page.toast.savedManualRestart")):c==="delete"?_.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):_.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),z()):c==="delete"?_.error(e("settings.agents.sidebar.toast.deleteFailed")):_.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(R){const Y=R instanceof Error?R.message:"",F=/built-in|not deletable|not found/i.test(Y);c==="delete"?_.error(e(F?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):_.error(e("settings.agents.sidebar.toast.resetFailed"))}p(!1)}},I=R=>{const Y=R.name;let F=1,W=`${Y}-copy`;for(;g.some(de=>de.name===W);)F++,W=`${Y}-copy-${F}`;const X=R,re=R.model?.providerID&&R.model?.modelID?`${R.model.providerID}/${R.model.modelID}`:null,Z=R;D({name:W,scope:X.scope||"user",description:R.description,model:re,variant:R.variant,temperature:R.temperature,top_p:R.topP,prompt:R.prompt,mode:R.mode,permission:Ui(R.permission),disable:Z.disable}),h(W)},v=R=>{i(R.name),a(R)},j=async()=>{if(!n)return;const R=r.trim().replace(/\s+/g,"-");if(!R){_.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(R===n.name){a(null);return}if(g.some(X=>X.name===R)){_.error(e("settings.agents.sidebar.toast.agentExists"));return}const Y=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,F=n,W=await k({name:R,description:n.description,model:Y,variant:n.variant,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Ui(n.permission),disable:F.disable,scope:F.scope});if(W.ok){const X=await w(n.name,F.scope);X.ok?(W.requiresManualRestart||X.requiresManualRestart?_.warning(e("settings.agents.page.toast.savedManualRestart")):_.success(e("settings.agents.sidebar.toast.agentRenamed",{name:R})),h(R)):_.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else _.error(e("settings.agents.sidebar.toast.renameFailed"));a(null)},O=R=>{switch(R){case"primary":return t.jsx(A,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(A,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(A,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},T=g.filter(R=>!wd(R)),B=T.filter(Sn),U=T.filter(R=>!Sn(R)),{groupedCustomAgents:Q,ungroupedCustomAgents:q}=ve.useMemo(()=>{const R={},Y=[];for(const W of U){const X=W;X.group?(R[X.group]||(R[X.group]=[]),R[X.group].push(W)):Y.push(W)}return{groupedCustomAgents:Object.keys(R).sort((W,X)=>W.localeCompare(X)).map(W=>({name:W,agents:R[W]})),ungroupedCustomAgents:Y}},[U]);return t.jsxs("div",{className:ce("flex h-full flex-col",N),children:[t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.agents.sidebar.title")}),t.jsx(na,{className:"mb-3"}),t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:T.length})}),t.jsx(J,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:y,children:t.jsx(A,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Gt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:T.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[B.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),B.map(R=>t.jsx(nr,{agent:R,isSelected:f===R.name,onSelect:()=>{h(R.name),s?.()},onReset:()=>P(R),onDuplicate:()=>I(R),getAgentModeIcon:O,isMenuOpen:u===R.name,onMenuOpenChange:Y=>C(Y?R.name:null)},R.name))]}),U.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),Q.map(({name:R,agents:Y})=>t.jsx(Er,{label:R,count:Y.length,storageKey:"agents",children:Y.map(F=>t.jsx(nr,{agent:F,isSelected:f===F.name,onSelect:()=>{h(F.name),s?.()},onRename:()=>v(F),onDelete:()=>b(F),onDuplicate:()=>I(F),getAgentModeIcon:O,isMenuOpen:u===F.name,onMenuOpenChange:W=>C(W?F.name:null)},F.name))},R)),q.map(R=>t.jsx(nr,{agent:R,isSelected:f===R.name,onSelect:()=>{h(R.name),s?.()},onRename:()=>v(R),onDelete:()=>b(R),onDuplicate:()=>I(R),getAgentModeIcon:O,isMenuOpen:u===R.name,onMenuOpenChange:Y=>C(Y?R.name:null)},R.name))]})]})}),t.jsx($t,{open:o!==null&&c!==null,onOpenChange:R=>{!R&&!m&&z()},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Ut,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(Wt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),t.jsxs(Yt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:z,disabled:m,children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:M,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx($t,{open:n!==null,onOpenChange:R=>!R&&a(null),children:t.jsxs(Bt,{children:[t.jsxs(_t,{children:[t.jsx(Ut,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(Wt,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(ot,{value:r,onChange:R=>i(R.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:R=>{R.key==="Enter"&&j()}}),t.jsxs(Yt,{children:[t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(J,{size:"sm",onClick:j,children:e("settings.common.actions.rename")})]})]})})]})},nr=s=>{const e=rt.c(52),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,getAgentModeIcon:x,isMenuOpen:m,onMenuOpenChange:p}=s,{t:u}=dt(),C=n;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Xn(),e[0]=f):f=e[0];const g=f,[h,D]=l.useState(!1);let k;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==u?(k=F=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(F,{onClick:W=>{W.stopPropagation(),d()},children:[t.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),t.jsxs(F,{onClick:W=>{W.stopPropagation(),c()},children:[t.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),o&&t.jsxs(F,{onClick:W=>{W.stopPropagation(),o()},children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),i&&t.jsxs(F,{onClick:W=>{W.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=o,e[5]=u,e[6]=k):k=e[6];const w=k,E=a?"bg-interactive-selection":"hover:bg-interactive-hover";let N;e[7]!==E?(N=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",E),e[7]=E,e[8]=N):N=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=g?void 0:F=>{F.preventDefault(),D(!0)},e[9]=y):y=e[9];let b;e[10]!==N?(b=t.jsx("div",{className:N,onContextMenu:y}),e[10]=N,e[11]=b):b=e[11];let P;e[12]!==n.name?(P=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[12]=n.name,e[13]=P):P=e[13];let z;e[14]!==n.mode||e[15]!==x?(z=x(n.mode),e[14]=n.mode,e[15]=x,e[16]=z):z=e[16];let M;e[17]!==n||e[18]!==C.scope||e[19]!==u?(M=(C.scope||Sn(n))&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Sn(n)?u("settings.agents.sidebar.badge.system"):C.scope}),e[17]=n,e[18]=C.scope,e[19]=u,e[20]=M):M=e[20];let I;e[21]!==P||e[22]!==z||e[23]!==M?(I=t.jsxs("div",{className:"flex items-center gap-1.5",children:[P,z,M]}),e[21]=P,e[22]=z,e[23]=M,e[24]=I):I=e[24];let v;e[25]!==n.description?(v=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[25]=n.description,e[26]=v):v=e[26];let j;e[27]!==r||e[28]!==I||e[29]!==v?(j=t.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[I,v]}),e[27]=r,e[28]=I,e[29]=v,e[30]=j):j=e[30];let O;e[31]!==p?(O=F=>{F&&D(!1),p(F)},e[31]=p,e[32]=O):O=e[32];let T;e[33]===Symbol.for("react.memo_cache_sentinel")?(T=t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=T):T=e[33];let B;e[34]!==w?(B=t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:w(vs)}),e[34]=w,e[35]=B):B=e[35];let U;e[36]!==m||e[37]!==O||e[38]!==B?(U=t.jsxs(gs,{open:m,onOpenChange:O,children:[T,B]}),e[36]=m,e[37]=O,e[38]=B,e[39]=U):U=e[39];let Q;e[40]!==j||e[41]!==U?(Q=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[j,U]}),e[40]=j,e[41]=U,e[42]=Q):Q=e[42];let q;e[43]!==Q||e[44]!==b?(q=t.jsx(tn,{render:b,children:Q}),e[43]=Q,e[44]=b,e[45]=q):q=e[45];let R;e[46]!==w?(R=t.jsx(sn,{className:"w-fit min-w-20",children:w(qs)}),e[46]=w,e[47]=R):R=e[47];let Y;return e[48]!==h||e[49]!==q||e[50]!==R?(Y=t.jsxs(en,{open:h,onOpenChange:D,children:[q,R]}),e[48]=h,e[49]=q,e[50]=R,e[51]=Y):Y=e[51],Y};function Vi(s,e,n){return Math.min(n,Math.max(e,s))}function Wu(s){if(!Number.isFinite(s))return 0;const e=String(s);if(e.includes("e-")){const[,a]=e.split("e-");return Number(a)||0}const n=e.split(".");return n.length===2?n[1].length:0}function _i(s,e){const n=Wu(e);return n<=0?s:Number(s.toFixed(n))}const bs=ve.forwardRef((s,e)=>{const n=rt.c(125);let a,r,i,o,d,c,x,m,p,u,C,f,g;n[0]!==s?({value:g,onValueChange:x,min:p,max:u,step:C,className:a,containerClassName:r,onBlur:d,disabled:i,fallbackValue:o,onClear:c,emptyLabel:f,...m}=s,n[0]=s,n[1]=a,n[2]=r,n[3]=i,n[4]=o,n[5]=d,n[6]=c,n[7]=x,n[8]=m,n[9]=p,n[10]=u,n[11]=C,n[12]=f,n[13]=g):(a=n[1],r=n[2],i=n[3],o=n[4],d=n[5],c=n[6],x=n[7],m=n[8],p=n[9],u=n[10],C=n[11],f=n[12],g=n[13]);const h=p===void 0?-1/0:p,D=u===void 0?1/0:u,k=C===void 0?1:C,w=f===void 0?"—":f,{t:E}=dt();let N;n[14]!==g?(N=()=>g===void 0?"":String(g),n[14]=g,n[15]=N):N=n[15];const[y,b]=ve.useState(N),{isMobile:P}=Cs(),z=ve.useRef(!1),M=ve.useRef(null);let I;n[16]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{if(typeof document>"u"||typeof window>"u")return;M.current?.();const Ae=Fe=>{Fe.preventDefault(),Fe.stopPropagation(),Fe.stopImmediatePropagation?.(),M.current?.()},Pe=window.setTimeout(()=>{M.current?.()},700),Te=()=>{window.clearTimeout(Pe),document.removeEventListener("click",Ae,!0),M.current=null};M.current=Te,document.addEventListener("click",Ae,!0)},n[16]=I):I=n[16];const v=I;let j,O;n[17]===Symbol.for("react.memo_cache_sentinel")?(j=()=>()=>{M.current?.()},O=[],n[17]=j,n[18]=O):(j=n[17],O=n[18]),ve.useEffect(j,O);let T,B;n[19]!==g?(B=()=>{b(g===void 0?"":String(g))},T=[g],n[19]=g,n[20]=T,n[21]=B):(T=n[20],B=n[21]),ve.useEffect(B,T);let U;e:{if(g!==void 0){U=g;break e}if(o!==void 0){U=o;break e}if(Number.isFinite(h)){U=h;break e}U=0}const Q=U;let q;n[22]!==D||n[23]!==h||n[24]!==x||n[25]!==k?(q=Ae=>{const Pe=Vi(Ae,h,D);x(_i(Pe,k))},n[22]=D,n[23]=h,n[24]=x,n[25]=k,n[26]=q):q=n[26];const R=q;let Y;n[27]!==R||n[28]!==c?(Y=Ae=>{const Pe=Ae.target.value;if(b(Pe),Pe.trim()===""){c?.();return}const Te=Number(Pe);Number.isFinite(Te)&&R(Te)},n[27]=R,n[28]=c,n[29]=Y):Y=n[29];const F=Y;let W;n[30]!==y||n[31]!==D||n[32]!==h||n[33]!==d||n[34]!==c||n[35]!==x||n[36]!==k||n[37]!==g?(W=Ae=>{if(y.trim()===""){c||b(g===void 0?"":String(g)),d?.(Ae);return}const Pe=Number(y);if(!Number.isFinite(Pe))b(g===void 0?"":String(g));else{const Te=Vi(Pe,h,D),Fe=_i(Te,k);Fe!==g&&x(Fe),b(String(Fe))}d?.(Ae)},n[30]=y,n[31]=D,n[32]=h,n[33]=d,n[34]=c,n[35]=x,n[36]=k,n[37]=g,n[38]=W):W=n[38];const X=W,re=!!(i||Q>=D),Z=!!(i||Q<=h);let de;n[39]!==Q||n[40]!==R||n[41]!==Z||n[42]!==k?(de=()=>{Z||R(Q-k)},n[39]=Q,n[40]=R,n[41]=Z,n[42]=k,n[43]=de):de=n[43];const le=de;let ee;n[44]!==Q||n[45]!==R||n[46]!==re||n[47]!==k?(ee=()=>{re||R(Q+k)},n[44]=Q,n[45]=R,n[46]=re,n[47]=k,n[48]=ee):ee=n[48];const xe=ee;let we;if(n[49]!==a||n[50]!==r||n[51]!==Z||n[52]!==y||n[53]!==w||n[54]!==le||n[55]!==xe||n[56]!==re||n[57]!==P||n[58]!==E||n[59]!==g){we=Symbol.for("react.early_return_sentinel");e:{const Ae=Te=>Fe=>{Fe.preventDefault(),Fe.stopPropagation(),z.current=!0,v(),Te()},Pe=Te=>Fe=>{if(z.current){z.current=!1,Fe.preventDefault(),Fe.stopPropagation();return}Te()};if(P){let Te;n[61]!==r?(Te=ce("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",r),n[61]=r,n[62]=Te):Te=n[62];let Fe;n[63]!==E?(Fe=E("numberInput.actions.decreaseAria"),n[63]=E,n[64]=Fe):Fe=n[64];const Be=Ae(le),We=Pe(le),ze=!Z&&"active:bg-interactive-hover";let Qe;n[65]!==ze?(Qe=ce("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",ze),n[65]=ze,n[66]=Qe):Qe=n[66];let oe;n[67]===Symbol.for("react.memo_cache_sentinel")?(oe=t.jsx(A,{name:"subtract",className:"block h-4 w-4"}),n[67]=oe):oe=n[67];const H=t.jsx("button",{type:"button","aria-label":Fe,disabled:Z,onTouchStart:Be,onClick:We,className:Qe,children:oe});let me;n[68]!==a?(me=ce("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",a),n[68]=a,n[69]=me):me=n[69];const Ne=g===void 0?w:y;let Ee;n[70]!==me||n[71]!==Ne?(Ee=t.jsx("div",{className:me,"aria-live":"polite",children:Ne}),n[70]=me,n[71]=Ne,n[72]=Ee):Ee=n[72];let Ce;n[73]!==E?(Ce=E("numberInput.actions.increaseAria"),n[73]=E,n[74]=Ce):Ce=n[74];const _e=Ae(xe),G=Pe(xe),$=!re&&"active:bg-interactive-hover";let fe;n[75]!==$?(fe=ce("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",$),n[75]=$,n[76]=fe):fe=n[76];let L;n[77]===Symbol.for("react.memo_cache_sentinel")?(L=t.jsx(A,{name:"add",className:"block h-4 w-4"}),n[77]=L):L=n[77];const Le=t.jsx("button",{type:"button","aria-label":Ce,disabled:re,onTouchStart:_e,onClick:G,className:fe,children:L});let Je;n[78]!==Te||n[79]!==H||n[80]!==Ee||n[81]!==Le?(Je=t.jsxs("div",{className:Te,children:[H,Ee,Le]}),n[78]=Te,n[79]=H,n[80]=Ee,n[81]=Le,n[82]=Je):Je=n[82],we=Je;break e}}n[49]=a,n[50]=r,n[51]=Z,n[52]=y,n[53]=w,n[54]=le,n[55]=xe,n[56]=re,n[57]=P,n[58]=E,n[59]=g,n[60]=we}else we=n[60];if(we!==Symbol.for("react.early_return_sentinel"))return we;let he;n[83]!==r?(he=ce("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",r),n[83]=r,n[84]=he):he=n[84];let Ie;n[85]!==E?(Ie=E("numberInput.actions.decreaseAria"),n[85]=E,n[86]=Ie):Ie=n[86];let be;n[87]!==Q||n[88]!==R||n[89]!==k?(be=()=>R(Q-k),n[87]=Q,n[88]=R,n[89]=k,n[90]=be):be=n[90];let je,ye;n[91]===Symbol.for("react.memo_cache_sentinel")?(je=ce("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),ye=t.jsx(A,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=je,n[92]=ye):(je=n[91],ye=n[92]);let se;n[93]!==Z||n[94]!==Ie||n[95]!==be?(se=t.jsx("button",{type:"button","aria-label":Ie,disabled:Z,onClick:be,className:je,children:ye}),n[93]=Z,n[94]=Ie,n[95]=be,n[96]=se):se=n[96];const ie=m.inputMode??"numeric";let ge;n[97]!==a?(ge=ce("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",a),n[97]=a,n[98]=ge):ge=n[98];let V;n[99]!==i||n[100]!==y||n[101]!==X||n[102]!==F||n[103]!==m||n[104]!==e||n[105]!==ie||n[106]!==ge?(V=t.jsx("input",{...m,ref:e,type:"text",inputMode:ie,value:y,onChange:F,onBlur:X,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ge}),n[99]=i,n[100]=y,n[101]=X,n[102]=F,n[103]=m,n[104]=e,n[105]=ie,n[106]=ge,n[107]=V):V=n[107];let te;n[108]!==E?(te=E("numberInput.actions.increaseAria"),n[108]=E,n[109]=te):te=n[109];let ne;n[110]!==Q||n[111]!==R||n[112]!==k?(ne=()=>R(Q+k),n[110]=Q,n[111]=R,n[112]=k,n[113]=ne):ne=n[113];let ue,Me;n[114]===Symbol.for("react.memo_cache_sentinel")?(ue=ce("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Me=t.jsx(A,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=ue,n[115]=Me):(ue=n[114],Me=n[115]);let ke;n[116]!==re||n[117]!==te||n[118]!==ne?(ke=t.jsx("button",{type:"button","aria-label":te,disabled:re,onClick:ne,className:ue,children:Me}),n[116]=re,n[117]=te,n[118]=ne,n[119]=ke):ke=n[119];let Re;return n[120]!==he||n[121]!==se||n[122]!==V||n[123]!==ke?(Re=t.jsxs("div",{className:he,children:[se,V,ke]}),n[120]=he,n[121]=se,n[122]=V,n[123]=ke,n[124]=Re):Re=n[124],Re});bs.displayName="NumberInput";const Hi=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Pa=s=>s==="allow"||s==="ask"||s==="deny",cn=(s,e)=>`${s}::${e}`,nn=s=>{const e=new Map;for(const n of s)!n.permission||n.permission==="invalid"||n.pattern&&Pa(n.action)&&e.set(cn(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},da=s=>{const e=new Map;for(const n of nn(s))e.set(cn(n.permission,n.pattern),n);return e},Wi=s=>[...s].sort((e,n)=>{const a=e.permission.localeCompare(n.permission);return a!==0?a:e.pattern.localeCompare(n.pattern)}),qu=(s,e)=>{const n=Wi(nn(s)),a=Wi(nn(e));return n.length!==a.length?!1:n.every((r,i)=>{const o=a[i];return r.permission===o.permission&&r.pattern===o.pattern&&r.action===o.action})},Gu=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",Ju=(s,e)=>nn(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),ar=s=>{if(Array.isArray(s))return nn(s);if(Pa(s))return[{permission:"*",pattern:"*",action:s}];if(!s||typeof s!="object"||Array.isArray(s))return[];const e=[];for(const[n,a]of Object.entries(s))if(n!=="__originalKeys"){if(Pa(a)){e.push({permission:n,pattern:"*",action:a});continue}if(a&&typeof a=="object"&&!Array.isArray(a))for(const[r,i]of Object.entries(a))Pa(i)&&e.push({permission:n,pattern:r,action:i})}return e},Qu=(s,e)=>{const n=nn(e),a={};for(const i of n)(a[i.permission]||={})[i.pattern]=i.action;const r={};for(const[i,o]of Object.entries(a))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){r[i]=o["*"];continue}r[i]=o}return Object.keys(r).length===0?s:(s!=="allow"&&(r["*"]=s),r)},Yu=(s,e)=>{const n=un(e);if(!n)return[];const r=s.find(i=>i.id===n.providerId)?.models?.find(i=>i.id===n.modelId);return r?.variants?Object.keys(r.variants):[]},Xu=()=>{const{t:s}=dt(),{isMobile:e}=Cs(),n=ut(H=>H.providers),{selectedAgentName:a,getAgentByName:r,createAgent:i,updateAgent:o,agents:d,agentDraft:c,setAgentDraft:x}=$a(Ss(H=>({selectedAgentName:H.selectedAgentName,getAgentByName:H.getAgentByName,createAgent:H.createAgent,updateAgent:H.updateAgent,agents:H.agents,agentDraft:H.agentDraft,setAgentDraft:H.setAgentDraft}))),m=a?r(a):null,p=!!(c&&c.name===a&&!m),[u,C]=l.useState(""),[f,g]=l.useState("user"),[h,D]=l.useState(""),[k,w]=l.useState("subagent"),[E,N]=l.useState(""),[y,b]=l.useState(""),[P,z]=l.useState(void 0),[M,I]=l.useState(void 0),[v,j]=l.useState(""),[O,T]=l.useState("allow"),[B,U]=l.useState([]),[Q,q]=l.useState([]),[R,Y]=l.useState(""),[F,W]=l.useState("*"),[X,re]=l.useState(!1),[Z,de]=l.useState(!1),le=l.useRef(null),ee=ys(H=>H.currentDirectory??null),[xe,we]=l.useState([]),he=l.useMemo(()=>Yu(n,E),[E,n]),Ie=he.length>0,be=l.useMemo(()=>!y||!he.includes(y)?"__default":y,[y,he]),je=Ie&&(!y||he.includes(y)),ye=Nd(H=>H.permission);l.useEffect(()=>{let H=!1;return(async()=>{const Ne=await ws.listToolIds({directory:ee});if(H)return;const Ee=new Set(["write","patch","multiedit"]),Ce=Ne.map(_e=>typeof _e=="string"?_e.trim():"").filter(Boolean).filter(_e=>_e!=="*").filter(_e=>_e!=="invalid").filter(_e=>!Ee.has(_e));we(Array.from(new Set(Ce)).sort((_e,G)=>_e.localeCompare(G)))})(),()=>{H=!0}},[ee]);const se=l.useMemo(()=>{const H=new Set;for(const me of d){const Ne=nn(ar(me.permission));for(const Ee of Ne)Ee.permission&&Ee.permission!=="*"&&Ee.permission!=="invalid"&&H.add(Ee.permission)}for(const me of Object.values(ye))for(const Ne of me){const Ee=Ne.permission?.trim();Ee&&Ee!=="invalid"&&H.add(Ee)}for(const me of xe)H.add(me);return Array.from(H).sort((me,Ne)=>me.localeCompare(Ne))},[d,ye,xe]),ie=l.useMemo(()=>da(B),[B]),ge=l.useMemo(()=>da(Q),[Q]),V=l.useCallback(H=>ge.get(cn(H,"*"))?.action,[ge]),te=l.useCallback(H=>Q.filter(me=>me.permission===H&&me.pattern!=="*").sort((me,Ne)=>me.pattern.localeCompare(Ne.pattern)),[Q]),ne=l.useMemo(()=>{const H=new Set;for(const me of Hi)H.add(me);for(const me of se)H.add(me);return Array.from(H).sort((me,Ne)=>me.localeCompare(Ne))},[se]),ue=l.useCallback(H=>{const me=H==="*"?O:V(H)??O,Ne=te(H),Ee=!1,Ce=Ne.reduce((G,$)=>(G[$.action]=(G[$.action]??0)+1,G),{allow:0,ask:0,deny:0}),_e=["allow","ask","deny"].filter(G=>Ce[G]>0).map(G=>`${Ce[G]} ${G}`).join(", ");return{defaultAction:me,patternRulesCount:Ne.length,patternSummary:_e,hasDefaultHint:Ee}},[te,V,O]),Me=l.useCallback(H=>s(H==="allow"?"settings.common.permission.allow":H==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),ke=l.useCallback(H=>H==="global"?s("settings.common.scope.global"):Me(H),[Me,s]),Re=l.useMemo(()=>{const H=new Set;for(const me of Hi)H.add(me);for(const me of se)H.add(me);return Array.from(H).sort((me,Ne)=>me.localeCompare(Ne))},[se]),Ae=l.useCallback((H,me,Ne)=>{q(Ee=>{const Ce=da(Ee);return Ce.set(cn(H,me),{permission:H,pattern:me,action:Ne}),Array.from(Ce.values())})},[]),Pe=l.useCallback((H,me)=>{q(Ne=>{const Ee=da(Ne);return Ee.delete(cn(H,me)),Array.from(Ee.values())})},[]),Te=l.useCallback((H,me)=>{const Ne=ie.get(cn(H,me));if(Ne){Ae(H,me,Ne.action);return}Pe(H,me)},[ie,Pe,Ae]),Fe=l.useCallback((H,me,Ne)=>{Ae(H,me,Ne)},[Ae]),Be=l.useCallback(H=>{T(H),q(me=>me.filter(Ne=>!(Ne.pattern==="*"&&Ne.action===H)))},[]),We=l.useCallback(H=>{const me=R.trim();if(!me){_.error(s("settings.agents.page.toast.permissionNameRequired"));return}const Ne=F.trim()||"*";if(me==="*"&&Ne==="*"){Be(H),Y(""),W("*");return}Ne==="*"&&me!=="*"&&H===O?Pe(me,"*"):Ae(me,Ne,H),Y(""),W("*")},[O,R,F,Pe,Be,s,Ae]),ze=l.useCallback(H=>H==="*"?s("settings.agents.page.permissions.defaultLabel"):H==="webfetch"?"WebFetch":H==="websearch"?"WebSearch":H==="codesearch"?"CodeSearch":H==="doom_loop"?"Doom Loop":H==="external_directory"?"External Directory":H==="todowrite"?"TodoWrite":H==="todoread"?"TodoRead":H.split(/[_-]+/g).filter(Boolean).map(me=>me.charAt(0).toUpperCase()+me.slice(1)).join(" "),[s]);l.useEffect(()=>{Y(""),W("*");const H=me=>{const Ne=nn(me),Ee=Gu(Ne),Ce=Ju(Ne,Ee);return T(Ee),U(Ce),q(Ce),{global:Ee,rules:Ce}};if(p&&c){const me=c.name||"",Ne=c.scope||"user",Ee=c.description||"",Ce=c.mode||"subagent",_e=c.model||"",G=c.variant||"",$=c.temperature??void 0,fe=c.top_p??void 0,L=c.prompt||"";C(me),g(Ne),D(Ee),w(Ce),N(_e),b(G),z($),I(fe),j(L);const Le=ar(c.permission),Je=H(Le);le.current={draftName:me,draftScope:Ne,description:Ee,mode:Ce,model:_e,variant:G,temperature:$,topP:fe,prompt:L,globalPermission:Je.global,permissionRules:Je.rules};return}if(m&&a===m.name){const me=m.description||"",Ne=m.mode||"subagent",Ee=m.model?.providerID&&m.model?.modelID?`${m.model.providerID}/${m.model.modelID}`:"",Ce=m.variant||"",_e=m.temperature,G=m.topP,$=m.prompt||"";D(me),w(Ne),N(Ee),b(Ce),z(_e),I(G),j($);const fe=H(ar(m.permission));le.current={draftName:"",draftScope:"user",description:me,mode:Ne,model:Ee,variant:Ce,temperature:_e,topP:G,prompt:$,globalPermission:fe.global,permissionRules:fe.rules}}},[c,p,m,a]);const Qe=l.useMemo(()=>{const H=le.current;return H?!!(p&&(u!==H.draftName||f!==H.draftScope)||h!==H.description||k!==H.mode||E!==H.model||y!==H.variant||P!==H.temperature||M!==H.topP||v!==H.prompt||O!==H.globalPermission||!qu(Q,H.permissionRules)):!1},[h,u,f,O,p,k,E,Q,v,P,M,y]),oe=async()=>{const H=p?u.trim().replace(/\s+/g,"-"):a?.trim();if(!H){_.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(p&&d.some(me=>me.name===H)){_.error(s("settings.agents.sidebar.toast.agentExists"));return}de(!0);try{const me=E.trim(),Ne=y.trim(),Ee=v.trim(),Ce=Qu(O,Q),_e={name:H,description:h.trim()||void 0,mode:k,model:me===""?null:me,variant:Ne===""?null:Ne||void 0,temperature:P??null,top_p:M??null,prompt:Ee||(p?void 0:null),permission:Ce,scope:p?f:void 0};let G;p?(G=await i(_e),G.ok&&x(null)):G=await o(H,_e),G.ok?G.requiresManualRestart?_.warning(s("settings.agents.page.toast.savedManualRestart")):_.success(s(p?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):_.error(s(p?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(me){console.error("Error saving agent:",me);const Ne=me instanceof Error&&me.message?me.message:s("settings.agents.page.toast.saveUnexpectedError");_.error(Ne)}finally{de(!1)}};return a?t.jsx(Gt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p?s("settings.agents.page.title.new"):a}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(p?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.identityRole")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&t.jsxs("div",{"data-settings-item":"agents.name",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.agentName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),t.jsx(ot,{value:u,onChange:H=>C(H.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Mt,{value:f,onValueChange:H=>g(H),children:[t.jsx(Rt,{className:"w-fit min-w-[100px]",children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Tt,{align:"end",children:[t.jsx(gt,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(gt,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(hs,{value:h,onChange:H=>D(H.target.value),placeholder:s("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),t.jsx("div",{"data-settings-item":"agents.mode",className:"pb-1.5 pt-0.5",children:t.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.mode")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.modeTooltip")})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[t.jsx(J,{variant:"chip",size:"xs","aria-pressed":k==="primary",onClick:()=>w("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":k==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(J,{variant:"chip",size:"xs","aria-pressed":k==="all",onClick:()=>w("all"),className:"!font-normal",children:s("settings.agents.page.mode.all")})]})]})})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.modelParameters")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{"data-settings-item":"agents.model",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(Hr,{providerId:un(E)?.providerId??"",modelId:un(E)?.modelId??"",onChange:(H,me)=>{N(H&&me?`${H}/${me}`:""),b("")}})})]}),t.jsxs("div",{"data-settings-item":"agents.variant",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.variant")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.variantTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.variantHint")})]}),t.jsx("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:je?t.jsxs(Mt,{value:be,onValueChange:H=>b(H==="__default"?"":H),children:[t.jsx(Rt,{className:ce("max-w-full",e?"w-full":"w-fit min-w-[10rem]"),children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.variantPlaceholder"),children:H=>H==="__default"?s("chat.modelControls.default"):H})}),t.jsxs(Tt,{children:[t.jsx(gt,{value:"__default",children:s("chat.modelControls.default")}),he.map(H=>t.jsx(gt,{value:H,children:H},H))]})]}):t.jsxs(t.Fragment,{children:[t.jsx(ot,{value:y,onChange:H=>b(H.target.value),placeholder:s("settings.agents.page.field.variantPlaceholder"),disabled:!E&&!y,className:ce("h-7 w-40",e&&"w-full")}),y&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>b(""),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.common.actions.clear"),title:s("settings.common.actions.clear"),children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})})]}),t.jsxs("div",{"data-settings-item":"agents.temperature",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.temperature")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.temperatureTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.temperatureRange")})]}),t.jsxs("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(bs,{value:P,fallbackValue:.7,onValueChange:z,onClear:()=>z(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),P!==void 0&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>z(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTemperatureAria"),title:s("settings.common.actions.clear"),children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{"data-settings-item":"agents.top-p",className:ce("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:ce("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.topP")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s("settings.agents.page.field.topPTooltip")})]})]}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:s("settings.agents.page.field.topPRange")})]}),t.jsxs("div",{className:ce("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(bs,{value:M,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),M!==void 0&&t.jsx(J,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":s("settings.agents.page.field.clearTopPAria"),title:s("settings.common.actions.clear"),children:t.jsx(A,{name:"close",className:"h-3.5 w-3.5"})})]})]})]})]}),t.jsxs("div",{"data-settings-item":"agents.system-prompt",className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.systemPrompt")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(hs,{value:v,onChange:H=>j(H.target.value),placeholder:s("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),t.jsxs("div",{"data-settings-item":"agents.permissions",className:"mb-2",children:[t.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.agents.page.section.toolPermissions")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>re(H=>!H),children:s(X?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),X?t.jsxs("div",{className:"space-y-6 px-2",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.permissions.globalDefault")}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),t.jsxs(Mt,{value:O,onValueChange:H=>Be(H),children:[t.jsx(Rt,{className:"w-[100px]",children:t.jsx(Kt,{children:Me(O)})}),t.jsxs(Tt,{children:[t.jsx(gt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(gt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(gt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:ne.filter(H=>H!=="*").map(H=>{const me=ze(H),{defaultAction:Ne,patternRulesCount:Ee}=ue(H),Ce=V(H),_e=Ce??"global",G=te(H),$=["allow","ask","deny"].filter(fe=>fe!==O);return t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[t.jsxs("div",{className:"flex items-center justify-between py-1",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:me}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:H})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Ee>0?s("settings.agents.page.permissions.globalSummary",{summary:Ne}):Ne})]}),t.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Ce&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>Te(H,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Mt,{value:_e,onValueChange:fe=>{if(fe==="global"){Pe(H,"*");return}Ae(H,"*",fe)},children:[t.jsx(Rt,{className:"w-[90px]",children:t.jsx(Kt,{children:ke(_e)})}),t.jsxs(Tt,{children:[t.jsx(gt,{value:"global",children:s("settings.common.scope.global")}),$.map(fe=>t.jsx(gt,{value:fe,className:"capitalize",children:Me(fe)},fe))]})]})]}),G.map(fe=>{const L=cn(fe.permission,fe.pattern),Le=ie.get(L),Je=!Le,Xe=!!(Le&&Le.action!==fe.action);return t.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5 border-t border-[var(--surface-subtle)]",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-micro text-muted-foreground",children:s("settings.agents.page.permissions.pattern")}),t.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:fe.pattern}),Je&&t.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:s("settings.common.badge.new")}),Xe&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:s("settings.common.badge.modified")}),(Je||Xe)&&t.jsx(J,{size:"sm",variant:"ghost",onClick:()=>Je?Pe(fe.permission,fe.pattern):Te(fe.permission,fe.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(A,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Mt,{value:fe.action,onValueChange:et=>Fe(fe.permission,fe.pattern,et),children:[t.jsx(Rt,{className:"w-[90px]",children:t.jsx(Kt,{children:Me(fe.action)})}),t.jsxs(Tt,{children:[t.jsx(gt,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(gt,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(gt,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},L)})]})]},H)})}),t.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[t.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:s("settings.agents.page.permissions.addCustomRule")}),t.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[t.jsxs(Mt,{value:R,onValueChange:Y,children:[t.jsx(Rt,{className:"w-full sm:w-[160px]",children:R?t.jsx("span",{className:"truncate",children:ze(R)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Tt,{children:Re.map(H=>t.jsx(gt,{value:H,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:ze(H)})})},H))})]}),t.jsx(ot,{value:F,onChange:H=>W(H.target.value),placeholder:s("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>We("allow"),children:s("settings.common.permission.allow")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>We("ask"),children:s("settings.common.permission.ask")}),t.jsx(J,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>We("deny"),children:s("settings.common.permission.deny")})]})]})]})]}):t.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ne.map((H,me)=>{const{defaultAction:Ne,patternRulesCount:Ee,patternSummary:Ce,hasDefaultHint:_e}=ue(H),G=ze(H),$=_e?`${Ne} (env blocked)`:Ne;return t.jsxs("div",{className:ce("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",me>0&&"border-t border-[var(--surface-subtle)]"),children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:G}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:H})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Ee>0?t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.globalSummary",{summary:$})}):t.jsx("span",{className:ce("typography-micro capitalize px-1.5 py-0.5 rounded",$==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":$==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:$}),Ee>0&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:s("settings.agents.page.permissions.rulesSummary",{summary:Ce})})]})]},H)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:oe,disabled:Z||!Qe,size:"xs",className:"!font-normal",children:s(Z?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.agents.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.agents.page.empty.description")})]})})},Zu="~/.config/opencode/AGENTS.md",El=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},ep=s=>s.length>0&&!s.endsWith(`
2
2
  `)?`${s}
3
3
  `:s,ma={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},tp=(s,e)=>s==="custom"?e:Sd(s),sp=s=>s==="custom"?"custom":hl(s)?s:"concise",qi={concise:"settings.behavior.page.responseStyle.option.concise",detailed:"settings.behavior.page.responseStyle.option.detailed",mentor:"settings.behavior.page.responseStyle.option.mentor",pushback:"settings.behavior.page.responseStyle.option.pushback",noFiller:"settings.behavior.page.responseStyle.option.noFiller",matchEnergy:"settings.behavior.page.responseStyle.option.matchEnergy",warmPeer:"settings.behavior.page.responseStyle.option.warmPeer"},Gi=async(s,e)=>{const n=await yt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(s)});if(!n.ok)throw new Error(await El(n,e))},np=()=>{const{t:s}=dt(),[e,n]=l.useState(""),[a,r]=l.useState(ma.responseStyleEnabled),[i,o]=l.useState(ma.responseStylePreset),[d,c]=l.useState(ma.responseStyleCustomInstructions),[x,m]=l.useState(!0),[p,u]=l.useState(!1),[C,f]=l.useState(""),g=l.useRef(null);l.useEffect(()=>{const w=new AbortController;return(async()=>{try{const[N,y]=await Promise.all([yt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:w.signal}),yt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:w.signal})]);let b=ma;if(N.ok){const P=await N.json();b={...b,responseStyleEnabled:P.responseStyleEnabled===!0,responseStylePreset:sp(P.responseStylePreset),responseStyleCustomInstructions:typeof P.responseStyleCustomInstructions=="string"?P.responseStyleCustomInstructions:""},typeof P.globalBehaviorPrompt=="string"&&(b={...b,prompt:P.globalBehaviorPrompt})}if(!b.prompt.trim()&&y.ok){const P=await y.json();typeof P.content=="string"&&(b={...b,prompt:P.content})}n(b.prompt),r(b.responseStyleEnabled),o(b.responseStylePreset),c(b.responseStyleCustomInstructions),f(b.prompt),g.current={enabled:b.responseStyleEnabled,preset:b.responseStylePreset,custom:b.responseStyleCustomInstructions}}catch(N){N.name!=="AbortError"&&console.warn("Failed to load behavior settings:",N)}finally{m(!1)}})(),()=>w.abort()},[]),l.useEffect(()=>{if(x)return;const w=g.current;if(w&&w.enabled===a&&w.preset===i&&w.custom===d)return;const E={enabled:a,preset:i,custom:d},N=setTimeout(async()=>{try{await Gi({responseStyleEnabled:E.enabled,responseStylePreset:E.preset,responseStyleCustomInstructions:E.custom},s("settings.behavior.page.toast.saveFailed")),g.current=E}catch(y){const b=y instanceof Error?y.message:s("settings.behavior.page.toast.saveFailed");_.error(b)}},400);return()=>clearTimeout(N)},[a,i,d,x,s]);const h=tp(i,d),D=e!==C,k=async()=>{u(!0);try{const w=ep(e),E=await yt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:w})});if(!E.ok)throw new Error(await El(E,s("settings.behavior.page.toast.saveFailed")));await Gi({globalBehaviorPrompt:w},s("settings.behavior.page.toast.saveFailed")),n(w),f(w),_.success(s("settings.behavior.page.toast.saved"))}catch(w){console.error("Failed to save behavior:",w);const E=w instanceof Error?w.message:s("settings.behavior.page.toast.saveFailed");_.error(E)}finally{u(!1)}};return t.jsx(Gt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8 space-y-6",children:[t.jsx("div",{className:"space-y-1",children:t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:s("settings.behavior.page.title")})}),t.jsxs("div",{"data-settings-item":"behavior.system-prompt",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.systemPrompt")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:t.jsxs("div",{className:"space-y-1",children:[t.jsx("p",{className:"font-medium text-foreground",children:s("settings.behavior.page.warning.title")}),t.jsx("p",{children:s("settings.behavior.page.warning.description",{path:Zu})})]})})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsx(hs,{value:e,onChange:w=>n(w.target.value),placeholder:s("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:x,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),t.jsx(J,{onClick:k,disabled:p||!D||x,size:"xs",className:"!font-normal",children:s(p?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),t.jsxs("div",{"data-settings-item":"behavior.response-style",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.behavior.page.section.responseStyle")}),t.jsxs(Pt,{children:[t.jsx(It,{asChild:!0,children:t.jsx(A,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Dt,{sideOffset:8,className:"max-w-xs",children:s("settings.behavior.page.responseStyle.tooltip")})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[t.jsx(St,{checked:a,onChange:r,disabled:x,ariaLabel:s("settings.behavior.page.responseStyle.enableAria")}),s("settings.behavior.page.responseStyle.enable")]}),t.jsxs(Mt,{value:i,onValueChange:w=>o(w),disabled:x||!a,children:[t.jsx(Rt,{className:"w-full sm:w-56",size:"lg",children:t.jsx(Kt,{children:w=>w==="custom"?s("settings.behavior.page.responseStyle.option.custom"):hl(w)?s(qi[w]):null})}),t.jsxs(Tt,{children:[kd.map(w=>t.jsx(gt,{value:w,children:s(qi[w])},w)),t.jsx(gt,{value:"custom",children:s("settings.behavior.page.responseStyle.option.custom")})]})]}),t.jsx(hs,{value:h,onChange:w=>c(w.target.value),placeholder:s("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:x||!a||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},ap=s=>{const e=rt.c(169),{onItemSelect:n}=s,{t:a}=dt(),[r,i]=l.useState(null),[o,d]=l.useState(""),[c,x]=l.useState(null),[m,p]=l.useState(null),[u,C]=l.useState(!1),[f,g]=l.useState(null),{selectedCommandName:h,commands:D,setSelectedCommand:k,setCommandDraft:w,createCommand:E,deleteCommand:N,loadCommands:y}=Ba(Ss(rp)),b=Hs(ip),P=Hs(op);let z,M;e[0]!==y||e[1]!==P?(z=()=>{y(),P()},M=[y,P],e[0]=y,e[1]=P,e[2]=z,e[3]=M):(z=e[2],M=e[3]),l.useEffect(z,M);let I;e[4]!==b?(I=new Set(b.map(lp)),e[4]=b,e[5]=I):I=e[5];const v=I;let j;if(e[6]!==D||e[7]!==v){let pe;e[9]!==v?(pe=nt=>!v.has(nt.name),e[9]=v,e[10]=pe):pe=e[10],j=D.filter(pe),e[6]=D,e[7]=v,e[8]=j}else j=e[8];const O=j;let T,B;e[11]!==h||e[12]!==k||e[13]!==v?(T=()=>{h&&v.has(h)&&k(null)},B=[h,k,v],e[11]=h,e[12]=k,e[13]=v,e[14]=T,e[15]=B):(T=e[14],B=e[15]),l.useEffect(T,B);let U;e[16]!==D||e[17]!==n||e[18]!==w||e[19]!==k?(U=()=>{let pe="new-command",nt=1;for(;D.some(st=>st.name===pe);)pe=`new-command-${nt}`,nt++;w({name:pe,scope:"user"}),k(pe),n?.()},e[16]=D,e[17]=n,e[18]=w,e[19]=k,e[20]=U):U=e[20];const Q=U;let q;e[21]!==a?(q=async pe=>{if(An(pe)){_.error(a("settings.commands.sidebar.toast.builtInCannotDelete"));return}x(pe),p("delete")},e[21]=a,e[22]=q):q=e[22];const R=q;let Y;e[23]===Symbol.for("react.memo_cache_sentinel")?(Y=async pe=>{An(pe)&&(x(pe),p("reset"))},e[23]=Y):Y=e[23];const F=Y;let W;e[24]===Symbol.for("react.memo_cache_sentinel")?(W=()=>{x(null),p(null)},e[24]=W):W=e[24];const X=W;let re;e[25]!==c||e[26]!==m||e[27]!==N||e[28]!==a?(re=async()=>{if(!c||!m)return;C(!0),await N(c.name)?(m==="delete"?_.success(a("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):_.success(a("settings.commands.sidebar.toast.commandReset",{name:c.name})),X()):m==="delete"?_.error(a("settings.commands.sidebar.toast.deleteFailed")):_.error(a("settings.commands.sidebar.toast.resetFailed")),C(!1)},e[25]=c,e[26]=m,e[27]=N,e[28]=a,e[29]=re):re=e[29];const Z=re;let de;e[30]!==D||e[31]!==w||e[32]!==k?(de=pe=>{const nt=pe.name;let st=1,Ge=`${nt}-copy`;for(;D.some(ht=>ht.name===Ge);)st++,Ge=`${nt}-copy-${st}`;w({name:Ge,scope:pe.scope||"user",description:pe.description,template:pe.template,agent:pe.agent,model:pe.model}),k(Ge)},e[30]=D,e[31]=w,e[32]=k,e[33]=de):de=e[33];const le=de;let ee;e[34]===Symbol.for("react.memo_cache_sentinel")?(ee=pe=>{d(pe.name),i(pe)},e[34]=ee):ee=e[34];const xe=ee;let we;e[35]!==D||e[36]!==E||e[37]!==N||e[38]!==r||e[39]!==o||e[40]!==k||e[41]!==a?(we=async()=>{if(!r)return;const pe=o.trim().replace(/\s+/g,"-");if(!pe){_.error(a("settings.commands.sidebar.toast.commandNameRequired"));return}if(pe===r.name){i(null);return}if(D.some(st=>st.name===pe)){_.error(a("settings.commands.sidebar.toast.commandExists"));return}await E({name:pe,description:r.description,template:r.template,agent:r.agent,model:r.model})?await N(r.name)?(_.success(`Command renamed to "${pe}"`),k(pe)):_.error(a("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):_.error(a("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=D,e[36]=E,e[37]=N,e[38]=r,e[39]=o,e[40]=k,e[41]=a,e[42]=we):we=e[42];const he=we;let Ie,be,je,ye,se,ie;if(e[43]!==O||e[44]!==Q||e[45]!==R||e[46]!==le||e[47]!==n||e[48]!==f||e[49]!==h||e[50]!==k||e[51]!==a){const pe=O.filter(An),nt=O.filter(cp);e[58]===Symbol.for("react.memo_cache_sentinel")?(se=ce("flex h-full flex-col","bg-background"),e[58]=se):se=e[58];let st;e[59]!==a?(st=a("settings.commands.sidebar.title"),e[59]=a,e[60]=st):st=e[60];let Ge;e[61]!==st?(Ge=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:st}),e[61]=st,e[62]=Ge):Ge=e[62];let ht;e[63]===Symbol.for("react.memo_cache_sentinel")?(ht=t.jsx(na,{className:"mb-3"}),e[63]=ht):ht=e[63];let wt;e[64]!==O.length||e[65]!==a?(wt=a("settings.commands.sidebar.total",{count:O.length}),e[64]=O.length,e[65]=a,e[66]=wt):wt=e[66];let Nt;e[67]!==wt?(Nt=t.jsx("span",{className:"typography-meta text-muted-foreground",children:wt}),e[67]=wt,e[68]=Nt):Nt=e[68];let ae;e[69]===Symbol.for("react.memo_cache_sentinel")?(ae=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[69]=ae):ae=e[69];let Ue;e[70]!==Q?(Ue=t.jsx(J,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,children:ae}),e[70]=Q,e[71]=Ue):Ue=e[71];let tt;e[72]!==Nt||e[73]!==Ue?(tt=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Nt,Ue]}),e[72]=Nt,e[73]=Ue,e[74]=tt):tt=e[74],e[75]!==Ge||e[76]!==tt?(ie=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Ge,ht,tt]}),e[75]=Ge,e[76]=tt,e[77]=ie):ie=e[77],Ie=Gt,be="flex-1 min-h-0",je="space-y-1 px-3 py-2",ye=O.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.commands.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.commands.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[pe.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.commands.sidebar.section.builtIn")}),[...pe].sort(dp).map(Ye=>t.jsx(Ji,{command:Ye,isSelected:h===Ye.name,onSelect:()=>{k(Ye.name),n?.()},onReset:()=>F(Ye),onDuplicate:()=>le(Ye),isMenuOpen:f===Ye.name,onMenuOpenChange:ft=>g(ft?Ye.name:null)},Ye.name))]}),nt.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.commands.sidebar.section.custom")}),[...nt].sort(mp).map(Ye=>t.jsx(Ji,{command:Ye,isSelected:h===Ye.name,onSelect:()=>{k(Ye.name),n?.()},onRename:()=>xe(Ye),onDelete:()=>R(Ye),onDuplicate:()=>le(Ye),isMenuOpen:f===Ye.name,onMenuOpenChange:ft=>g(ft?Ye.name:null)},Ye.name))]})]}),e[43]=O,e[44]=Q,e[45]=R,e[46]=le,e[47]=n,e[48]=f,e[49]=h,e[50]=k,e[51]=a,e[52]=Ie,e[53]=be,e[54]=je,e[55]=ye,e[56]=se,e[57]=ie}else Ie=e[52],be=e[53],je=e[54],ye=e[55],se=e[56],ie=e[57];let ge;e[78]!==Ie||e[79]!==be||e[80]!==je||e[81]!==ye?(ge=t.jsx(Ie,{outerClassName:be,className:je,children:ye}),e[78]=Ie,e[79]=be,e[80]=je,e[81]=ye,e[82]=ge):ge=e[82];const V=c!==null&&m!==null;let te;e[83]!==u?(te=pe=>{!pe&&!u&&X()},e[83]=u,e[84]=te):te=e[84];let ne;e[85]!==m||e[86]!==a?(ne=a(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=a,e[87]=ne):ne=e[87];let ue;e[88]!==ne?(ue=t.jsx(Ut,{children:ne}),e[88]=ne,e[89]=ue):ue=e[89];let Me;e[90]!==c?.name||e[91]!==m||e[92]!==a?(Me=m==="delete"?a("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):a("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[90]=c?.name,e[91]=m,e[92]=a,e[93]=Me):Me=e[93];let ke;e[94]!==Me?(ke=t.jsx(Wt,{children:Me}),e[94]=Me,e[95]=ke):ke=e[95];let Re;e[96]!==ue||e[97]!==ke?(Re=t.jsxs(_t,{children:[ue,ke]}),e[96]=ue,e[97]=ke,e[98]=Re):Re=e[98];let Ae;e[99]!==a?(Ae=a("settings.common.actions.cancel"),e[99]=a,e[100]=Ae):Ae=e[100];let Pe;e[101]!==u||e[102]!==Ae?(Pe=t.jsx(J,{size:"sm",variant:"ghost",onClick:X,disabled:u,children:Ae}),e[101]=u,e[102]=Ae,e[103]=Pe):Pe=e[103];let Te;e[104]!==m||e[105]!==a?(Te=a(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=a,e[106]=Te):Te=e[106];let Fe;e[107]!==Z||e[108]!==u||e[109]!==Te?(Fe=t.jsx(J,{size:"sm",onClick:Z,disabled:u,children:Te}),e[107]=Z,e[108]=u,e[109]=Te,e[110]=Fe):Fe=e[110];let Be;e[111]!==Pe||e[112]!==Fe?(Be=t.jsxs(Yt,{children:[Pe,Fe]}),e[111]=Pe,e[112]=Fe,e[113]=Be):Be=e[113];let We;e[114]!==Re||e[115]!==Be?(We=t.jsxs(Bt,{className:"max-w-md",children:[Re,Be]}),e[114]=Re,e[115]=Be,e[116]=We):We=e[116];let ze;e[117]!==V||e[118]!==te||e[119]!==We?(ze=t.jsx($t,{open:V,onOpenChange:te,children:We}),e[117]=V,e[118]=te,e[119]=We,e[120]=ze):ze=e[120];const Qe=r!==null;let oe;e[121]===Symbol.for("react.memo_cache_sentinel")?(oe=pe=>!pe&&i(null),e[121]=oe):oe=e[121];let H;e[122]!==a?(H=a("settings.commands.sidebar.renameDialog.title"),e[122]=a,e[123]=H):H=e[123];let me;e[124]!==H?(me=t.jsx(Ut,{children:H}),e[124]=H,e[125]=me):me=e[125];const Ne=r?.name??"";let Ee;e[126]!==a||e[127]!==Ne?(Ee=a("settings.commands.sidebar.renameDialog.description",{name:Ne}),e[126]=a,e[127]=Ne,e[128]=Ee):Ee=e[128];let Ce;e[129]!==Ee?(Ce=t.jsx(Wt,{children:Ee}),e[129]=Ee,e[130]=Ce):Ce=e[130];let _e;e[131]!==me||e[132]!==Ce?(_e=t.jsxs(_t,{children:[me,Ce]}),e[131]=me,e[132]=Ce,e[133]=_e):_e=e[133];let G;e[134]===Symbol.for("react.memo_cache_sentinel")?(G=pe=>d(pe.target.value),e[134]=G):G=e[134];let $;e[135]!==a?($=a("settings.commands.sidebar.renameDialog.placeholder"),e[135]=a,e[136]=$):$=e[136];let fe;e[137]!==he?(fe=pe=>{pe.key==="Enter"&&he()},e[137]=he,e[138]=fe):fe=e[138];let L;e[139]!==o||e[140]!==$||e[141]!==fe?(L=t.jsx(ot,{value:o,onChange:G,placeholder:$,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:fe}),e[139]=o,e[140]=$,e[141]=fe,e[142]=L):L=e[142];let Le;e[143]===Symbol.for("react.memo_cache_sentinel")?(Le=()=>i(null),e[143]=Le):Le=e[143];let Je;e[144]!==a?(Je=a("settings.common.actions.cancel"),e[144]=a,e[145]=Je):Je=e[145];let Xe;e[146]!==Je?(Xe=t.jsx(J,{size:"sm",variant:"ghost",onClick:Le,children:Je}),e[146]=Je,e[147]=Xe):Xe=e[147];let et;e[148]!==a?(et=a("settings.common.actions.rename"),e[148]=a,e[149]=et):et=e[149];let at;e[150]!==he||e[151]!==et?(at=t.jsx(J,{size:"sm",onClick:he,children:et}),e[150]=he,e[151]=et,e[152]=at):at=e[152];let ct;e[153]!==Xe||e[154]!==at?(ct=t.jsxs(Yt,{children:[Xe,at]}),e[153]=Xe,e[154]=at,e[155]=ct):ct=e[155];let Ze;e[156]!==_e||e[157]!==L||e[158]!==ct?(Ze=t.jsxs(Bt,{children:[_e,L,ct]}),e[156]=_e,e[157]=L,e[158]=ct,e[159]=Ze):Ze=e[159];let He;e[160]!==Qe||e[161]!==Ze?(He=t.jsx($t,{open:Qe,onOpenChange:oe,children:Ze}),e[160]=Qe,e[161]=Ze,e[162]=He):He=e[162];let mt;return e[163]!==se||e[164]!==ie||e[165]!==ge||e[166]!==ze||e[167]!==He?(mt=t.jsxs("div",{className:se,children:[ie,ge,ze,He]}),e[163]=se,e[164]=ie,e[165]=ge,e[166]=ze,e[167]=He,e[168]=mt):mt=e[168],mt},Ji=s=>{const e=rt.c(47),{command:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,isMenuOpen:x,onMenuOpenChange:m}=s,{t:p}=dt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Xn(),e[0]=u):u=e[0];const C=u,[f,g]=l.useState(!1);let h;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==p?(h=q=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(q,{onClick:R=>{R.stopPropagation(),d()},children:[t.jsx(A,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),t.jsxs(q,{onClick:R=>{R.stopPropagation(),c()},children:[t.jsx(A,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),o&&t.jsxs(q,{onClick:R=>{R.stopPropagation(),o()},children:[t.jsx(A,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),i&&t.jsxs(q,{onClick:R=>{R.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[1]=i,e[2]=c,e[3]=d,e[4]=o,e[5]=p,e[6]=h):h=e[6];const D=h,k=a?"bg-interactive-selection":"hover:bg-interactive-hover";let w;e[7]!==k?(w=ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",k),e[7]=k,e[8]=w):w=e[8];let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=C?void 0:q=>{q.preventDefault(),g(!0)},e[9]=E):E=e[9];let N;e[10]!==w?(N=t.jsx("div",{className:w,onContextMenu:E}),e[10]=w,e[11]=N):N=e[11];let y;e[12]!==n.name?(y=t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[12]=n.name,e[13]=y):y=e[13];let b;e[14]!==n||e[15]!==p?(b=(n.scope||An(n))&&t.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:An(n)?p("settings.agents.sidebar.badge.system"):n.scope}),e[14]=n,e[15]=p,e[16]=b):b=e[16];let P;e[17]!==y||e[18]!==b?(P=t.jsxs("div",{className:"flex items-center gap-2",children:[y,b]}),e[17]=y,e[18]=b,e[19]=P):P=e[19];let z;e[20]!==n.description?(z=n.description&&t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[20]=n.description,e[21]=z):z=e[21];let M;e[22]!==r||e[23]!==z||e[24]!==P?(M=t.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[P,z]}),e[22]=r,e[23]=z,e[24]=P,e[25]=M):M=e[25];let I;e[26]!==m?(I=q=>{q&&g(!1),m(q)},e[26]=m,e[27]=I):I=e[27];let v;e[28]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=v):v=e[28];let j;e[29]!==D?(j=t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:D(vs)}),e[29]=D,e[30]=j):j=e[30];let O;e[31]!==x||e[32]!==I||e[33]!==j?(O=t.jsxs(gs,{open:x,onOpenChange:I,children:[v,j]}),e[31]=x,e[32]=I,e[33]=j,e[34]=O):O=e[34];let T;e[35]!==M||e[36]!==O?(T=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[M,O]}),e[35]=M,e[36]=O,e[37]=T):T=e[37];let B;e[38]!==T||e[39]!==N?(B=t.jsx(tn,{render:N,children:T}),e[38]=T,e[39]=N,e[40]=B):B=e[40];let U;e[41]!==D?(U=t.jsx(sn,{className:"w-fit min-w-20",children:D(qs)}),e[41]=D,e[42]=U):U=e[42];let Q;return e[43]!==f||e[44]!==B||e[45]!==U?(Q=t.jsxs(en,{open:f,onOpenChange:g,children:[B,U]}),e[43]=f,e[44]=B,e[45]=U,e[46]=Q):Q=e[46],Q};function rp(s){return{selectedCommandName:s.selectedCommandName,commands:s.commands,setSelectedCommand:s.setSelectedCommand,setCommandDraft:s.setCommandDraft,createCommand:s.createCommand,deleteCommand:s.deleteCommand,loadCommands:s.loadCommands}}function ip(s){return s.skills}function op(s){return s.loadSkills}function lp(s){return s.name}function cp(s){return!An(s)}function dp(s,e){return s.name.localeCompare(e.name)}function mp(s,e){return s.name.localeCompare(e.name)}const up=()=>{const{t:s}=dt(),{selectedCommandName:e,getCommandByName:n,createCommand:a,updateCommand:r,commands:i,commandDraft:o,setCommandDraft:d}=Ba(Ss(I=>({selectedCommandName:I.selectedCommandName,getCommandByName:I.getCommandByName,createCommand:I.createCommand,updateCommand:I.updateCommand,commands:I.commands,commandDraft:I.commandDraft,setCommandDraft:I.setCommandDraft}))),c=e?n(e):null,x=!!(o&&o.name===e&&!c),[m,p]=l.useState(""),[u,C]=l.useState("user"),[f,g]=l.useState(""),[h,D]=l.useState(""),[k,w]=l.useState(""),[E,N]=l.useState(""),[y,b]=l.useState(!1),P=l.useRef(null);l.useEffect(()=>{if(x&&o){const I=o.name||"",v=o.scope||"user",j=o.description||"",O=o.agent||"",T=o.model||"",B=o.template||"";p(I),C(v),g(j),D(O),w(T),N(B),P.current={draftName:I,draftScope:v,description:j,agent:O,model:T,template:B}}else if(c){const I=c.description||"",v=c.agent||"",j=c.model||"",O=c.template||"";g(I),D(v),w(j),N(O),P.current={draftName:"",draftScope:"user",description:I,agent:v,model:j,template:O}}},[c,x,e,i,o]);const z=l.useMemo(()=>{const I=P.current;return I?!!(x&&(m!==I.draftName||u!==I.draftScope)||f!==I.description||h!==I.agent||k!==I.model||E!==I.template):!1},[h,f,m,u,x,k,E]),M=async()=>{const I=x?m.trim().replace(/\s+/g,"-"):e?.trim();if(!I){_.error(s("settings.commands.sidebar.toast.commandNameRequired"));return}if(!E.trim()){_.error(s("settings.commands.page.toast.templateRequired"));return}if(x&&i.some(v=>v.name===I)){_.error(s("settings.commands.sidebar.toast.commandExists"));return}b(!0);try{const v=h.trim(),j=k.trim(),O=E.trim(),T={name:I,description:f.trim()||void 0,agent:v===""?null:v,model:j===""?null:j,template:O,scope:x?u:void 0};let B;x?(B=await a(T),B&&d(null)):B=await r(I,T),B?_.success(s(x?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):_.error(s(x?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(v){console.error("Error saving command:",v),_.error(s("settings.commands.page.toast.saveUnexpectedError"))}finally{b(!1)}};return e?t.jsx(Gt,{outerClassName:"h-full",className:"w-full",children:t.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[t.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:t.jsxs("div",{className:"min-w-0",children:[t.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:x?s("settings.commands.page.title.new"):`/${e}`}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(x?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.identity")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[x&&t.jsxs("div",{"data-settings-item":"commands.name",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.commands.page.field.commandName")})}),t.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[t.jsxs("div",{className:"flex items-center",children:[t.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),t.jsx(ot,{value:m,onChange:I=>p(I.target.value),placeholder:s("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Mt,{value:u,onValueChange:I=>C(I),children:[t.jsx(Rt,{className:"w-fit min-w-[100px]",children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Tt,{align:"end",children:[t.jsx(gt,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(gt,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(A,{name:"folder",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.project")})]})})]})]})]})]}),t.jsxs("div",{className:"py-1.5",children:[t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.common.field.description")}),t.jsx("div",{className:"mt-1.5",children:t.jsx(hs,{value:f,onChange:I=>g(I.target.value),placeholder:s("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]})]}),t.jsxs("div",{className:"mb-8",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.executionContext")})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[t.jsxs("div",{"data-settings-item":"commands.agent",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.commands.page.field.overrideAgent")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(fl,{agentName:h,onChange:I=>D(I)})})]}),t.jsxs("div",{"data-settings-item":"commands.model",className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[t.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:t.jsx("span",{className:"typography-ui-label text-foreground",children:s("settings.agents.page.field.overrideModel")})}),t.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:t.jsx(Hr,{providerId:un(k)?.providerId??"",modelId:un(k)?.modelId??"",onChange:(I,v)=>{w(I&&v?`${I}/${v}`:"")}})})]})]})]}),t.jsxs("div",{"data-settings-item":"commands.template",className:"mb-2",children:[t.jsx("div",{className:"mb-1 px-1",children:t.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:s("settings.commands.page.section.template")})}),t.jsx("section",{className:"px-2 pb-2 pt-0",children:t.jsx(hs,{value:E,onChange:I=>N(I.target.value),placeholder:s("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),t.jsx("div",{className:"mt-2 px-2",children:t.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",s("settings.commands.page.templateHint.userInput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",s("settings.commands.page.templateHint.shellOutput")," ·"," ",t.jsx("code",{className:"text-foreground",children:"@file"})," ",s("settings.commands.page.templateHint.fileContents")]})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(J,{onClick:M,disabled:y||!z,size:"xs",className:"!font-normal",children:s(y?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxs("div",{className:"text-center text-muted-foreground",children:[t.jsx(A,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),t.jsx("p",{className:"typography-body",children:s("settings.commands.page.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:s("settings.commands.page.empty.description")})]})})},Qi=s=>{switch(s){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Yi=s=>{const e=rt.c(5),{tone:n,enabled:a}=s;if(!a){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=t.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=o):o=e[0],o}let r;e[1]!==n?(r=ce("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[n]),e[1]=n,e[2]=r):r=e[2];let i;return e[3]!==r?(i=t.jsx("span",{className:r}),e[3]=r,e[4]=i):i=e[4],i},pp=s=>{const e=rt.c(120),{onItemSelect:n}=s,{t:a}=dt(),{mcpServers:r,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:d,loadMcpConfigs:c,deleteMcp:x}=Rn(Ss(gp)),m=ys(hp);let p;e[0]!==m?(p=Ce=>Ce.getStatusForDirectory(m??null),e[0]=m,e[1]=p):p=e[1];const u=ls(p),C=ls(fp),f=ls(xp),[g,h]=l.useState(null),[D,k]=l.useState(!1),[w,E]=l.useState(null),[N,y]=l.useState(null),[b,P]=l.useState(!1);let z;e[2]!==r?(z=r.filter(bp),e[2]=r,e[3]=z):z=e[3];const M=z;let I;e[4]!==r?(I=r.filter(yp),e[4]=r,e[5]=I):I=e[5];const v=I;let j,O;e[6]!==c?(j=()=>{c()},O=[c],e[6]=c,e[7]=j,e[8]=O):(j=e[7],O=e[8]),l.useEffect(j,O);let T;e[9]!==m||e[10]!==f||e[11]!==b||e[12]!==C?(T=()=>{if(b)return;P(!0);const Ce=new Promise(vp);Promise.all([C({directory:m,silent:!0}),Ce]).then(()=>{const _e=f(m);_e&&_.error(_e)}).finally(()=>{P(!1)})},e[9]=m,e[10]=f,e[11]=b,e[12]=C,e[13]=T):T=e[13];const B=T;let U;e[14]!==r||e[15]!==n||e[16]!==d||e[17]!==o?(U=()=>{let Ce="new-mcp-server",_e=1;for(;r.some($=>$.name===Ce);)Ce=`new-mcp-server-${_e}`,_e++;d({name:Ce,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(Ce),n?.()},e[14]=r,e[15]=n,e[16]=d,e[17]=o,e[18]=U):U=e[18];const Q=U;let q;e[19]!==x||e[20]!==g||e[21]!==a?(q=async()=>{if(!g)return;k(!0);const Ce=await x(g.name);Ce.ok?Ce.reloadFailed?_.warning(Ce.message||`MCP server "${g.name}" deleted, but OpenCode reload failed`,{description:Ce.warning||a("settings.mcp.sidebar.toast.refreshListIfStale")}):_.success(Ce.message||a("settings.mcp.sidebar.toast.serverDeleted",{name:g.name})):_.error(a("settings.mcp.sidebar.toast.deleteFailed")),h(null),k(!1)},e[19]=x,e[20]=g,e[21]=a,e[22]=q):q=e[22];const R=q;let Y;e[23]!==a?(Y=(Ce,_e)=>t.jsxs(_e,{onClick:G=>{G.stopPropagation(),h(Ce)},className:"text-destructive focus:text-destructive",children:[t.jsx(A,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]}),e[23]=a,e[24]=Y):Y=e[24];const F=Y;let W;e[25]===Symbol.for("react.memo_cache_sentinel")?(W=ce("flex h-full flex-col","bg-background"),e[25]=W):W=e[25];let X;e[26]!==a?(X=a("settings.mcp.sidebar.title"),e[26]=a,e[27]=X):X=e[27];let re;e[28]!==X?(re=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:X}),e[28]=X,e[29]=re):re=e[29];let Z;e[30]!==a?(Z=a("settings.mcp.sidebar.actions.refreshStatusAria"),e[30]=a,e[31]=Z):Z=e[31];let de;e[32]!==a?(de=a("settings.mcp.sidebar.actions.refreshStatusTitle"),e[32]=a,e[33]=de):de=e[33];const le=b&&"animate-spin";let ee;e[34]!==le?(ee=ce("h-4 w-4",le),e[34]=le,e[35]=ee):ee=e[35];let xe;e[36]!==ee?(xe=t.jsx(A,{name:"refresh",className:ee}),e[36]=ee,e[37]=xe):xe=e[37];let we;e[38]!==B||e[39]!==b||e[40]!==Z||e[41]!==de||e[42]!==xe?(we=t.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:b,onClick:B,"aria-label":Z,title:de,children:xe}),e[38]=B,e[39]=b,e[40]=Z,e[41]=de,e[42]=xe,e[43]=we):we=e[43];let he;e[44]!==re||e[45]!==we?(he=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[re,we]}),e[44]=re,e[45]=we,e[46]=he):he=e[46];let Ie;e[47]===Symbol.for("react.memo_cache_sentinel")?(Ie=t.jsx(na,{className:"mb-3"}),e[47]=Ie):Ie=e[47];let be;e[48]!==r.length||e[49]!==a?(be=a("settings.mcp.sidebar.total",{count:r.length}),e[48]=r.length,e[49]=a,e[50]=be):be=e[50];let je;e[51]!==be?(je=t.jsx("span",{className:"typography-meta text-muted-foreground",children:be}),e[51]=be,e[52]=je):je=e[52];let ye;e[53]!==a?(ye=a("settings.mcp.sidebar.actions.addServerTitle"),e[53]=a,e[54]=ye):ye=e[54];let se;e[55]===Symbol.for("react.memo_cache_sentinel")?(se=t.jsx(A,{name:"add",className:"h-3.5 w-3.5"}),e[55]=se):se=e[55];let ie;e[56]!==Q||e[57]!==ye?(ie=t.jsx(J,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,title:ye,children:se}),e[56]=Q,e[57]=ye,e[58]=ie):ie=e[58];let ge;e[59]!==je||e[60]!==ie?(ge=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[je,ie]}),e[59]=je,e[60]=ie,e[61]=ge):ge=e[61];let V;e[62]!==he||e[63]!==ge?(V=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[he,Ie,ge]}),e[62]=he,e[63]=ge,e[64]=V):V=e[64];let te;e[65]!==r.length||e[66]!==u||e[67]!==n||e[68]!==w||e[69]!==M||e[70]!==F||e[71]!==N||e[72]!==i||e[73]!==d||e[74]!==o||e[75]!==a||e[76]!==v?(te=t.jsx(Gt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:r.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(A,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),t.jsx("p",{className:"typography-ui-label font-medium",children:a("settings.mcp.sidebar.empty.title")}),t.jsx("p",{className:"typography-meta mt-1 opacity-75",children:a("settings.mcp.sidebar.empty.description")})]}):t.jsxs(t.Fragment,{children:[M.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.mcp.sidebar.group.projectServers")}),M.map(Ce=>{const _e=u[Ce.name],G=Qi(_e?.status),$=i===Ce.name,fe=Xn();return t.jsxs(en,{open:N===Ce.name,onOpenChange:L=>y(L?Ce.name:null),children:[t.jsxs(tn,{render:t.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",$?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:fe?void 0:L=>{L.preventDefault(),y(Ce.name)}}),children:[t.jsxs("button",{onClick:()=>{o(Ce.name),d(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Yi,{tone:G,enabled:Ce.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ce.name}),t.jsx("span",{title:Ce.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Ce.type==="local"?t.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(A,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ce.type==="local"?Ce.command?.join(" ")??"":Ce.url??""})]}),t.jsxs(gs,{open:w===Ce.name,onOpenChange:L=>{L&&y(null),E(L?Ce.name:null)},children:[t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:F(Ce,vs)})]})]}),t.jsx(sn,{className:"w-fit min-w-20",children:F(Ce,qs)})]},Ce.name)})]}),v.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("settings.mcp.sidebar.group.userServers")}),v.map(Ce=>{const _e=u[Ce.name],G=Qi(_e?.status),$=i===Ce.name,fe=Xn();return t.jsxs(en,{open:N===Ce.name,onOpenChange:L=>y(L?Ce.name:null),children:[t.jsxs(tn,{render:t.jsx("div",{className:ce("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",$?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:fe?void 0:L=>{L.preventDefault(),y(Ce.name)}}),children:[t.jsxs("button",{onClick:()=>{o(Ce.name),d(null),n?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Yi,{tone:G,enabled:Ce.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Ce.name}),t.jsx("span",{title:Ce.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Ce.type==="local"?t.jsx(A,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(A,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),t.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:Ce.type==="local"?Ce.command?.join(" ")??"":Ce.url??""})]}),t.jsxs(gs,{open:w===Ce.name,onOpenChange:L=>{L&&y(null),E(L?Ce.name:null)},children:[t.jsx(us,{asChild:!0,children:t.jsx(J,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:t.jsx(A,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ps,{align:"end",className:"w-fit min-w-20",children:F(Ce,vs)})]})]}),t.jsx(sn,{className:"w-fit min-w-20",children:F(Ce,qs)})]},Ce.name)})]})]})}),e[65]=r.length,e[66]=u,e[67]=n,e[68]=w,e[69]=M,e[70]=F,e[71]=N,e[72]=i,e[73]=d,e[74]=o,e[75]=a,e[76]=v,e[77]=te):te=e[77];const ne=g!==null;let ue;e[78]!==D?(ue=Ce=>{!Ce&&!D&&h(null)},e[78]=D,e[79]=ue):ue=e[79];let Me;e[80]!==a?(Me=a("settings.mcp.sidebar.deleteDialog.title"),e[80]=a,e[81]=Me):Me=e[81];let ke;e[82]!==Me?(ke=t.jsx(Ut,{children:Me}),e[82]=Me,e[83]=ke):ke=e[83];const Re=g?.name||"";let Ae;e[84]!==a||e[85]!==Re?(Ae=a("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Re}),e[84]=a,e[85]=Re,e[86]=Ae):Ae=e[86];let Pe;e[87]===Symbol.for("react.memo_cache_sentinel")?(Pe=t.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[87]=Pe):Pe=e[87];let Te;e[88]!==Ae?(Te=t.jsxs(Wt,{children:[Ae," ",Pe,"."]}),e[88]=Ae,e[89]=Te):Te=e[89];let Fe;e[90]!==ke||e[91]!==Te?(Fe=t.jsxs(_t,{children:[ke,Te]}),e[90]=ke,e[91]=Te,e[92]=Fe):Fe=e[92];let Be;e[93]===Symbol.for("react.memo_cache_sentinel")?(Be=()=>h(null),e[93]=Be):Be=e[93];let We;e[94]!==a?(We=a("settings.common.actions.cancel"),e[94]=a,e[95]=We):We=e[95];let ze;e[96]!==D||e[97]!==We?(ze=t.jsx(J,{size:"sm",variant:"ghost",onClick:Be,disabled:D,children:We}),e[96]=D,e[97]=We,e[98]=ze):ze=e[98];let Qe;e[99]!==D||e[100]!==a?(Qe=a(D?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[99]=D,e[100]=a,e[101]=Qe):Qe=e[101];let oe;e[102]!==R||e[103]!==D||e[104]!==Qe?(oe=t.jsx(J,{size:"sm",onClick:R,disabled:D,children:Qe}),e[102]=R,e[103]=D,e[104]=Qe,e[105]=oe):oe=e[105];let H;e[106]!==ze||e[107]!==oe?(H=t.jsxs(Yt,{children:[ze,oe]}),e[106]=ze,e[107]=oe,e[108]=H):H=e[108];let me;e[109]!==Fe||e[110]!==H?(me=t.jsxs(Bt,{className:"max-w-md",children:[Fe,H]}),e[109]=Fe,e[110]=H,e[111]=me):me=e[111];let Ne;e[112]!==ne||e[113]!==ue||e[114]!==me?(Ne=t.jsx($t,{open:ne,onOpenChange:ue,children:me}),e[112]=ne,e[113]=ue,e[114]=me,e[115]=Ne):Ne=e[115];let Ee;return e[116]!==V||e[117]!==te||e[118]!==Ne?(Ee=t.jsxs("div",{className:W,children:[V,te,Ne]}),e[116]=V,e[117]=te,e[118]=Ne,e[119]=Ee):Ee=e[119],Ee};function gp(s){return{mcpServers:s.mcpServers,selectedMcpName:s.selectedMcpName,setSelectedMcp:s.setSelectedMcp,setMcpDraft:s.setMcpDraft,loadMcpConfigs:s.loadMcpConfigs,deleteMcp:s.deleteMcp}}function hp(s){return s.currentDirectory}function fp(s){return s.refresh}function xp(s){return s.getErrorForDirectory}function bp(s){return s.scope==="project"}function yp(s){return s.scope!=="project"}function vp(s){return setTimeout(s,500)}function Ls(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function Un(s){return Array.isArray(s)&&s.every(e=>typeof e=="string")}function Fs(s,e){return e!==void 0?{ok:!1,error:s,parsed:e}:{ok:!1,error:s}}function ua(s,e,n){const a=jp(n),r=typeof n.url=="string"?n.url.trim():"",i=Xi(n,"env","environment"),o=Xi(n,"headers"),d=wp(n),c=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",x=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",m=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",u=Np(n),C=kp(n);return{ok:!0,name:s,type:e,command:a,url:r,environment:i,headers:o,oauthEnabled:d,oauthClientId:c,oauthClientSecret:x,oauthScope:m,oauthRedirectUri:p,timeout:u,enabled:C}}function jp(s){const e=s.command,n=s.args;if(Un(e)&&Un(n))return[...e,...n];if(Un(e))return e;if(typeof e=="string"&&e.trim()){const a=e.trim().split(/\s+/);return Un(n)?[...a,...n]:a}return Un(n)?n:[]}function Xi(s,...e){for(const n of e){const a=s[n];if(!Ls(a))continue;const r=Object.entries(a).filter(([i,o])=>i&&typeof o=="string");if(r.length>0)return r.map(([i,o])=>({key:i,value:String(o)}))}return[]}function wp(s){if(s.oauth===!1||s.oauth===null||s.oauth===void 0||!Ls(s.oauth))return!1;const e=s.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function Np(s){const e=s.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const n=Number(e);if(Number.isFinite(n)&&n>0)return String(Math.floor(n))}return""}function kp(s){return"disabled"in s&&s.disabled===!0?!1:"enabled"in s?!!s.enabled:!0}function Sp(s){const e=s.mcpServers;if(Ls(e)){const a=Object.keys(e);if(a.length===1){const r=a[0],i=e[r];if(Ls(i))return{name:r,entry:i}}if(a.length>1)return null}const n=Object.keys(s).filter(a=>{const r=s[a];return a!=="mcpServers"&&Ls(r)});if(n.length===1){const a=n[0],r=s[a];if(Ml(r))return{name:a,entry:r}}return null}function Ml(s){return s.type==="local"||s.type==="remote"||Array.isArray(s.command)||typeof s.url=="string"||Array.isArray(s.args)}function Cp(s,e){let n;try{const d=s.trim();if(!d)return Fs("No JSON content provided");n=JSON.parse(d)}catch(d){return Fs(d instanceof Error?`Invalid JSON: ${d.message}`:"Invalid JSON")}if(!Ls(n))return Fs("Expected a JSON object, not an array or primitive");const a=n,r=a.mcpServers;if(Ls(r)){const d=Object.keys(r);if(d.length===0)return Fs("mcpServers object is empty",n);if(d.length>1)return Fs("Paste one server at a time. Found "+d.length+" servers in mcpServers",n);const c=d[0],x=r[c];return Ls(x)?ua(c,pa(x),x):Fs("Server entry is not a valid object",n)}const i=a.mcp;if(Ls(i)){const d=Object.keys(i);if(d.length===0)return Fs("mcp object is empty",n);if(d.length>1)return Fs("Paste one server at a time. Found "+d.length+" servers in mcp",n);const c=d[0],x=i[c];return Ls(x)?ua(c,pa(x),x):Fs("Server entry in mcp is not a valid object",n)}const o=Sp(a);if(o)return ua(o.name,pa(o.entry),o.entry);if(Ml(a)){const d=pa(a),c=typeof a.name=="string"&&a.name.trim()?a.name.trim():e?.fallbackName;return ua(c,d,a)}return Fs("No recognizable MCP server configuration found in JSON",n)}function pa(s){return s.type==="remote"?"remote":s.type==="local"?"local":typeof s.url=="string"&&s.url.trim()?"remote":(Array.isArray(s.command)||typeof s.command=="string"||Array.isArray(s.args),"local")}function Pp(s,e,n){const a=n?.isNewServer??!1,r=s.name,i=a&&r?r:e.name??"";return{...e,name:i,type:s.type,command:s.type==="local"?s.command:[],url:s.type==="remote"?s.url:"",environment:s.environment,headers:s.type==="remote"?s.headers:[],oauthEnabled:s.type==="remote"?s.oauthEnabled:!1,oauthClientId:s.type==="remote"?s.oauthClientId:"",oauthClientSecret:s.type==="remote"?s.oauthClientSecret:"",oauthScope:s.type==="remote"?s.oauthScope:"",oauthRedirectUri:s.type==="remote"?s.oauthRedirectUri:"",timeout:s.type==="remote"?s.timeout:"",enabled:s.enabled}}const Ip="/mcp/oauth/callback",Dp=s=>{if(typeof window>"u")return null;try{const e=s.replace(/-/g,"+").replace(/_/g,"/"),n=e.length%4===0?"":"=".repeat(4-e.length%4),a=window.atob(e+n),r=Uint8Array.from(a,i=>i.charCodeAt(0));return new TextDecoder().decode(r)}catch{return null}},Ap=s=>{const e=Ep(s.get("state"));if(e)return e;const n=s.get("server");if(typeof n!="string"||!n.trim())return null;const a=s.get("directory");return{name:n.trim(),directory:typeof a=="string"&&a.trim()?a.trim():null}},Rl=s=>{const e=s.get("state");return typeof e!="string"?null:e.trim()||null},Ep=s=>{if(typeof s!="string"||!s.trim())return null;const e=Dp(s.trim());if(!e)return null;try{const n=JSON.parse(e);return n?.v!==1||typeof n.n!="string"||!n.n.trim()?null:{name:n.n.trim(),directory:typeof n.d=="string"&&n.d.trim()?n.d.trim():null}}catch{return null}},pn=Cc,gn=s=>{const e=rt.c(14);let n,a,r,i;e[0]!==s?({className:r,asChild:n,children:a,...i}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=r,e[4]=i):(n=e[1],a=e[2],r=e[3],i=e[4]);let o;e[5]!==n||e[6]!==a?(o=n&&ve.isValidElement(a)?{render:a}:{children:a},e[5]=n,e[6]=a,e[7]=o):o=e[7];const d=o;let c;e[8]!==r?(c=ce("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",r),e[8]=r,e[9]=c):c=e[9];let x;return e[10]!==i||e[11]!==d||e[12]!==c?(x=t.jsx(Sc,{className:c,...i,...d}),e[10]=i,e[11]=d,e[12]=c,e[13]=x):x=e[13],x},hn=s=>{const e=rt.c(8);let n,a;e[0]!==s?({className:n,...a}=s,e[0]=s,e[1]=n,e[2]=a):(n=e[1],a=e[2]);let r;e[3]!==n?(r=ce("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(Pc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i};function Mp(s){const e=[];let n="",a=!1,r=!1;for(let i=0;i<s.length;i++){const o=s[i];if(o==="'"&&!r){a=!a;continue}if(o==='"'&&!a){r=!r;continue}if((o===" "||o===" ")&&!a&&!r){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function Rp(s){const e=s.trim();if(!e)return{code:null,context:null,stateKey:null};try{const n=new URL(e),a=n.searchParams.get("code");if(typeof a=="string"&&a.trim())return{code:a.trim(),context:Ap(n.searchParams),stateKey:Rl(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Tp=({value:s,onChange:e,pasteCommandTitle:n,pasteCommandLabel:a,pasteSuccess:r,clipboardReadFailed:i,preview:o})=>{const[d,c]=l.useState(()=>s.join(`
4
4
  `)),x=l.useRef(s);l.useEffect(()=>{JSON.stringify(x.current)!==JSON.stringify(s)&&(x.current=s,c(s.join(`