@openchamber/web 1.13.1 → 1.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/assets/{DiagramView-la2P5DUr.js → DiagramView-l49NCoWI.js} +1 -1
  2. package/dist/assets/MarkdownRendererImpl-BspFAgXe.js +7 -0
  3. package/dist/assets/{MultiRunWindow-B9NPliTC.js → MultiRunWindow-BP1L8slG.js} +1 -1
  4. package/dist/assets/{NewWorktreeDialog-BnK_0_OO.js → NewWorktreeDialog-B2o615D_.js} +1 -1
  5. package/dist/assets/OnboardingScreen-DNQQWFmn.js +1 -0
  6. package/dist/assets/{SessionSwitcherDropdown-CuRsG7FM.js → SessionSwitcherDropdown-Bz03hrU9.js} +1 -1
  7. package/dist/assets/{SettingsWindow-Cs3xbqtf.js → SettingsWindow-L-jJDG3k.js} +1 -1
  8. package/dist/assets/{TerminalView-CLKpaKdm.js → TerminalView-CZYwjWYc.js} +1 -1
  9. package/dist/assets/index-Di3CDurc.css +1 -0
  10. package/dist/assets/index-DkRLSXEX.js +3 -0
  11. package/dist/assets/{main-B2rXVG8L.js → main-DmS7A2g8.js} +2 -2
  12. package/dist/assets/main-gqEqIL1b.js +214 -0
  13. package/dist/assets/miniChat-DZORfsku.js +2 -0
  14. package/dist/assets/mobile-DkitItmP.js +2 -0
  15. package/dist/assets/{renderElectronMiniChatApp-BLM-RCP0.js → renderElectronMiniChatApp-S7GCIhbH.js} +2 -2
  16. package/dist/assets/{renderMobileApp-BXScr4up.js → renderMobileApp-CxEnmaQL.js} +3 -3
  17. package/dist/assets/{useAppFontEffects-ByW8wOJM.js → useAppFontEffects-DkrfZHQv.js} +114 -114
  18. package/dist/assets/vendor--Dwc_TRgJ.css +1 -0
  19. package/dist/assets/{vendor-.bun-d5B0wgQr.js → vendor-.bun-CIlawBoH.js} +1 -1
  20. package/dist/index.html +5 -5
  21. package/dist/mini-chat.html +5 -5
  22. package/dist/mobile.html +5 -5
  23. package/package.json +1 -1
  24. package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  25. package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  26. package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  27. package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  28. package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  29. package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  30. package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  31. package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  32. package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  33. package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  34. package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  35. package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  36. package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  37. package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  38. package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  39. package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  40. package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  41. package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  42. package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  43. package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  44. package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  45. package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  46. package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  47. package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  48. package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  49. package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  50. package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  51. package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  52. package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  53. package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  54. package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  55. package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  56. package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  57. package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  58. package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  59. package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  60. package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  61. package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  62. package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  63. package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  64. package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  65. package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  66. package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  67. package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  68. package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  69. package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  70. package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  71. package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  72. package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  73. package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  74. package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  75. package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  76. package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  77. package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  78. package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  79. package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  80. package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  81. package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  82. package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  83. package/dist/assets/MarkdownRendererImpl-CkGSBGo5.js +0 -8
  84. package/dist/assets/OnboardingScreen-laLzQZgy.js +0 -1
  85. package/dist/assets/index-68ujKCUc.js +0 -3
  86. package/dist/assets/index-C-aQ_xRH.css +0 -1
  87. package/dist/assets/main-CuEzPtRt.js +0 -214
  88. package/dist/assets/miniChat-DVXSR0vu.js +0 -2
  89. package/dist/assets/mobile-BgYrNCOf.js +0 -2
  90. package/dist/assets/vendor--V65Sl9C2.css +0 -1
@@ -1,4 +1,4 @@
1
- import{ak as pc,e as rt,al as gc,j as t,H as ve,am as hc,an as fc,a as an,d as Zn,p as Kr,b as Ur,R as l,L as Ss,ab as xc,ac as bc,aa as yc,ad as vc,a8 as jc,a9 as wc,ae as Nc,ao as kc,ap as Sc,aq as Cc,u as Pc,l as Ic,n as Dc,w as Ac,C as Ec,S as Mc,ar as Rc,a6 as Tc,D as Fc,q as Lc,as as Oc,at as zc,au as $c,av as Kc,aw as Uc,X as Rs,ax as Bc,ay as xn,az as Zr,aA as Vc,aB as _c,aC as Ha,aD as Hc,aE as Wc,aF as qc,aG as ei,aH as Ma,aI as ti,k as wa,aJ as ml,aK as Br,aL as Oa,aM as ul,aN as si,aO as Gc,aP as Jc,aQ as Qc,aR as Yc,aS as ni,aT as Oe,aU as na,aV as Xc,aW as Zc,aX as ed,aY as td,aZ as sd,a_ as pl,a7 as nd,a$ as ai,b0 as ad,b1 as rd,b2 as id,b3 as od}from"./vendor-.bun-d5B0wgQr.js";import{du as za,r as Ra,v as Ta,m as de,dv as Na,dw as ka,dx as Sa,D as as,u as mt,I as T,ax as It,ay as Dt,az as Et,dy as ld,av as _s,a$ as Ut,a_ as Bt,aZ as Vt,bD as Jt,w as jr,bc as Vr,p as mn,au as Cs,t as B,cl as gl,B as q,dz as Pn,dA as cd,dB as dd,dg as md,dC as ud,dD as pd,dE as gd,z as Ps,dF as hd,cQ as fd,cR as xd,cS as bd,c3 as yd,aq as ds,as as ms,c4 as vd,at as us,aT as $a,dG as jd,dH as Nn,aY as _t,bp as qt,bL as Yt,n as ot,dI as Qn,ap as ws,dd as wd,bE as Ft,bF as Lt,bG as Kt,bH as Ot,bI as ft,ba as ps,aU as _r,dJ as En,bb as Pt,dK as hl,dL as Nd,dM as kd,dN as Ka,dO as Vs,dP as In,aW as fl,dQ as kn,dR as Sd,dS as Cd,dT as Pd,dU as Id,dV as Dd,dW as Ad,dX as un,dY as Ed,q as Ua,c9 as ri,k as Md,cb as wr,a3 as xl,E as Rd,P as bl,G as yl,cd as Td,O as ii,c$ as Fd,db as vl,d2 as Ld,cy as Od,dZ as oi,d_ as zd,d$ as $d,e0 as li,e1 as Kd,e2 as Ud,e3 as Bd,e4 as Vd,aw as _d,e5 as Hd,H as Wd,K as qd,a as Hr,aH as ci,e6 as di,e7 as mi,aK as zn,e8 as Wa,e9 as Gd,ea as Jd,Q as pt,ad as Dn,a5 as Zs,ac as jl,ab as Qd,eb as Yd,ec as ui,ae as Xd,af as Zd,a6 as em,aB as tm,aC as sm,aD as wl,ed as qa,ee as pi,ef as nm,eg as am,eh as rm,ei as im,d3 as Ba,R as Bs,ej as om,cc as Nl,ek as lm,el as cm,em as dm,en as mm,eo as Ga,ep as gi,eq as um,er as pm,es as gm,et as hm,eu as fm,ev as Ja,ew as xm,ex as hi,ey as Wn,ez as bm,aQ as fi,eA as jn,aP as ym,eB as vm,eC as xi,eD as bi,X as Qs,F as jm,S as wm,eE as Nm,cj as aa,bh as Nr,bi as kr,bj as Sr,bk as Cr,bl as Us,bm as Es,bM as Sn,M as Gn,eF as yi,bY as km,eG as kl,bO as Sm,d7 as Cm,f as Pm,eH as Qa,a2 as Im,b4 as ra,bS as Dm,eI as Am,eJ as Em,eK as Mm,eL as Rm}from"./useAppFontEffects-ByW8wOJM.js";import{D as Yn,e as jt,o as js,u as vs,$ as Tm,a0 as vi,a1 as Fm,a2 as Lm,w as gs,I as dn,b as Ve,j as ea,f as Ct,a as Xn,q as Fs,h as fs,a3 as Om,F as zm,a4 as Ya,E as $m,a5 as ji,a6 as Km,x as Um,a7 as wi,a8 as Ni,a9 as ki,aa as Si,ab as Xa,ac as Ci,C as Sl,ad as Bm,ae as Vm,af as _m,_ as Hm,J as Wm,ag as qm,ah as Gm,ai as Jm}from"./index-68ujKCUc.js";import{g as Qm,s as Ym}from"./mobileLayoutPreference-Dio-WWkI.js";function Xm(){return new Worker(pc,{type:"module"})}const Zm=["typescript","javascript","tsx","jsx","json","markdown"],Pr={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Pi,Ii;const Di=s=>{const e=Pr[s],n=new gc({workerFactory:Xm,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:Zm,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},eu=s=>{if(!(typeof window>"u"))return s==="split"?(Ii??=Di("split"),Ii):(Pi??=Di("unified"),Pi)},tu=s=>{const e=rt.c(7),{children:n,renderTheme:a}=s,r=Ir("unified"),i=Ir("split");let o,d;e[0]!==a||e[1]!==i||e[2]!==r?(o=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:Pr.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:Pr.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},kv=s=>{const e=rt.c(11),{children:n}=s,a=za();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const h=Ra(!1),m=Ra(!0),p=a?.lightThemeId??h.metadata.id,u=a?.darkThemeId??m.metadata.id;i=a?.availableThemes.find(C=>C.metadata.id===p)??h,r=a?.availableThemes.find(C=>C.metadata.id===u)??m,Ta(i),Ta(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(tu,{renderTheme:d,children:n}),e[8]=n,e[9]=d,e[10]=c):c=e[10],c},Ir=s=>{const e=rt.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=eu(n),e[0]=n,e[1]=a):a=e[1],a};function su(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 Fa=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=de("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(hc,{className:de("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(fc,{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});Fa.displayName="Switch";const ia=()=>{try{const e=as.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=js.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]))},oa=s=>typeof s!="string"?void 0:s.trim()||void 0,Za=800,nu=5e3,au="__default__",Dr=new Map,er=new Map,Cl=s=>s?.trim()||au,tr=s=>{Dr.delete(Cl(s))},Mn=an()(Zn(Kr((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=ia(),r=Cl(a),i=Date.now(),o=Dr.get(r)??0,d=e().mcpServers.length>0;if(!n?.force&&d&&i-o<nu)return!0;const c=er.get(r);if(!n?.force&&c)return c;const h=(async()=>{s({isLoading:!0});try{const m=a?`?directory=${encodeURIComponent(a)}`:"",p=await jt(`/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}),Dr.set(r,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),s({isLoading:!1}),!1}})();er.set(r,h);try{return await h}finally{er.delete(r)}},createMcp:async n=>{Na("Creating MCP server configuration…");let a=!1;try{const r=Mi(n),i=ia(),o=i?`?directory=${encodeURIComponent(i)}`:"",d=await jt(`/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 tr(i),c?.requiresReload?(a=!0,await ka({message:c.message,delayMs:c.reloadDelayMs??Za,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||Sa()}},updateMcp:async(n,a)=>{Na("Updating MCP server configuration…");let r=!1;try{const i=Mi(a),o=ia(),d=o?`?directory=${encodeURIComponent(o)}`:"",c=await jt(`/api/config/mcp/${encodeURIComponent(n)}${d}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),h=await c.json().catch(()=>null);if(!c.ok)throw new Error(h?.error||"Failed to update MCP server");return tr(o),h?.requiresReload?(r=!0,await ka({message:h.message,delayMs:h.reloadDelayMs??Za,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:h?.reloadFailed===!0,message:h?.message,warning:h?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:h?.reloadFailed===!0,message:h?.message,warning:h?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||Sa()}},deleteMcp:async n=>{Na("Deleting MCP server configuration…");let a=!1;try{const r=ia(),i=r?`?directory=${encodeURIComponent(r)}`:"",o=await jt(`/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 tr(r),d?.requiresReload&&(a=!0,await ka({message:d.message,delayMs:d.reloadDelayMs??Za,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||Sa()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:Ur(()=>Yn()),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:oa(s.oauthClientId),clientSecret:oa(s.oauthClientSecret),scope:oa(s.oauthScope),redirectUri:oa(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 ru={},iu={},Ks=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},yn=s=>Ks(s)??"__global__",on=s=>{const e=Ks(s);return e?js.getScopedApiClient(e):js.getApiClient()},is=an()(Zn((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=yn(n??vs.getState().currentDirectory);return e().byDirectory[a]??ru},getDiagnosticForDirectory:n=>{const a=yn(n??vs.getState().currentDirectory);return e().diagnosticsByDirectory[a]??iu},getErrorForDirectory:n=>{const a=yn(n??vs.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=Ks(n?.directory??vs.getState().currentDirectory),r=yn(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(([h])=>!d[h]))},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=Ks(a??vs.getState().currentDirectory),i=yn(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(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:c}}}})),d}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=Ks(a??vs.getState().currentDirectory);await on(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=Ks(a??vs.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=Ks(r??vs.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=Ks(a??vs.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=Ks(a??vs.getState().currentDirectory),i=yn(r),o=on(r),c=e().getStatusForDirectory(r)[n]?.status==="connected";let h,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(C){h=C instanceof Error?C.message:"Connection failed",s(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:h??"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:h,warning:m}}}))),ou=(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}},lu=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Sv=({active:s,className:e,headerAction:n,listClassName:a,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:o}=mt(),c=vs(N=>N.currentDirectory)??null,h=is(N=>N.getStatusForDirectory(c)),m=is(N=>N.refresh),p=is(N=>N.connect),u=is(N=>N.disconnect),C=Mn(N=>N.mcpServers),f=Mn(N=>N.loadMcpConfigs),[g,b]=l.useState(!1),[A,S]=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 k=l.useMemo(()=>{const N=new Set(Object.keys(h));for(const j of C)j?.name&&N.add(j.name);return Array.from(N).sort((j,x)=>j.localeCompare(x))},[C,h]),E=l.useCallback(N=>{if(N?.preventDefault(),g)return;b(!0);const j=new Promise(x=>setTimeout(x,500));Promise.all([m({directory:c}),j]).finally(()=>{b(!1)})},[g,m,c]);return t.jsxs("div",{className:de("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(T,{name:"refresh",className:de("h-4 w-4",g&&"animate-spin")})})]})]})}),t.jsxs("div",{className:de("max-h-64 overflow-y-auto py-2",i&&"space-y-1 py-3",a),children:[k.map(N=>{const j=h[N],x=lu(j),I=j?.status==="connected",z=A===N,R=ou(j,o);return t.jsxs("div",{className:de("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx("span",{className:de("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",x==="success"&&"bg-status-success",x==="error"&&"bg-status-error",x==="warning"&&"bg-status-warning",x==="default"&&"bg-muted-foreground/40"),"aria-label":R})}),t.jsx(Et,{side:"left",children:t.jsx("p",{children:R})})]}),t.jsx("span",{className:de("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:N})]})}),t.jsx(Fa,{checked:I,disabled:z,className:"data-[checked]:bg-status-info",onCheckedChange:async D=>{S(N);try{D?await p(N,c):await u(N,c)}finally{S(null)}}})]},N)}),k.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:o("mcpDropdown.empty.configureInConfig")})]})]})};function cu(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=ld();return s}catch{return"unknown"}}function du(){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 mu(){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 uu(s){const e=Ve.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",cu()),n.set("arch",du()),n.set("platform",mu()),s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",ea()?"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=uu(s),a=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e||s==="vscode"&&a&&n.set("currentVersion",a);const r=await jt(`/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 pu(){return Lm()?"desktop":gs()?"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},Pl=an()((s,e)=>({...Ti,checkForUpdates:async()=>{const n=pu();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 Fm(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 Tm())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 gu(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(Vr(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function hu(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Li(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function fu(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 xu(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 Oi=2e3,bu=600*1e3;async function yu(){try{const s=await jt("/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 vu(){try{return(await jt("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function ju(s,e=Math.ceil(bu/Oi),n=Oi){for(let a=0;a<e;a++){try{const r=await jt("/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 vu())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:h="desktop"})=>{const{t:m}=mt(),[p,u]=ve.useState(!1),[C,f]=ve.useState("idle"),[g,b]=ve.useState(null),A=n?.version?`${Fi}/tag/v${n.version}`:Fi,S=i?.total?Math.round(i.downloaded/i.total*100):0,k=h==="web",E=n?.updateCommand||"openchamber update";ve.useEffect(()=>{s||(f("idle"),b(null))},[s]);const N=async()=>{(await mn(E)).ok&&(u(!0),setTimeout(()=>u(!1),2e3))},j=ve.useCallback(async R=>{await _s(R)},[]),x=ve.useCallback(async()=>{f("updating"),b(null);const R=await yu();if(!R.success){f("error"),b(R.error||m("updateDialog.error.updateFailed"));return}R.autoRestart&&(f("restarting"),await new Promise(v=>setTimeout(v,2e3))),f("reconnecting"),await ju(n?.currentVersion)?window.location.reload():(f("error"),b(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),I=C!=="idle"&&C!=="error",z=ve.useMemo(()=>{if(!n?.body)return null;const R=n.body.trim();if(!R)return null;const D=xu(R);if(D.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Li(R)};const v=[...D].sort((y,L)=>fu(y.version,L.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:v.map(y=>({version:y.version,dateLabel:gu(y.date),content:Li(hu(y.raw)||R)}))}},[n?.body,m]);return t.jsx(Ut,{open:s,onOpenChange:I?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(Vt,{className:"flex items-center gap-2.5",children:[t.jsx(T,{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:[k&&I&&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(T,{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&&!I&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(Jt,{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:R=>{const v=R.target.closest("a");v&&v.href&&(R.preventDefault(),R.stopPropagation(),j(v.href))},children:t.jsx(jr,{content:z.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:z.sections.map(R=>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",R.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:R.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:D=>{const y=D.target.closest("a");y&&y.href&&(D.preventDefault(),D.stopPropagation(),j(y.href))},children:t.jsx(jr,{content:R.content,disableLinkSafety:!0,enableFileReferences:!1})})]},R.version))})})}),k&&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(T,{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:de("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(T,{name:"check",className:"h-4 w-4"}):t.jsx(T,{name:"clipboard",className:"h-4 w-4"})})]})]}),!k&&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:[S,"%"]})]}),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:`${S}%`}})})]}),(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:A,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(T,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!k&&!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(T,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!k&&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(T,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!k&&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(T,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),k&&!I&&t.jsxs("button",{onClick:x,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(T,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),k&&I&&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(T,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},$i="https://github.com/openchamber/openchamber",wu="https://discord.gg/ZYRSdnwwKA",Ki="https://x.com/openchamber_dev",Nu=800,Il=({initialUpdateDialogOpen:s=!1})=>{const{t:e}=mt(),[n,a]=l.useState(s),[r,i]=l.useState(!1),[o,d]=l.useState(null),[c,h]=l.useState(null),m=Pl(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 A=await jt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const S=await A.json().catch(()=>null),k=typeof S?.openchamberVersion=="string"&&S.openchamberVersion.trim().length>0?S.openchamberVersion.trim():null;g||d(k)}catch{g||d(null)}})(),()=>{g=!0}},[]),l.useEffect(()=>{let g=!1;return(async()=>{try{const A=await jt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const S=await A.json().catch(()=>null),k=typeof S?.currentVersion=="string"&&S.currentVersion.trim().length>0?S.currentVersion.trim():null;g||h(k)}catch{g||h(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&&(B.success(e("settings.openchamber.about.toast.latestVersion")),C.current=!1)},Nu);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(q,{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(T,{name:"loader",className:"size-4 animate-spin"}):t.jsx(T,{name:"refresh",className:"size-4"}),e(f?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!f&&m.available&&t.jsxs(q,{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(T,{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:$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(T,{name:"github-fill",className:"size-5"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:wu,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(T,{name:"discord-fill",className:"size-5"}),t.jsx("span",{children:"Discord"})]})]}),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(T,{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(T,{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(q,{size:"sm",variant:"default",onClick:()=>a(!0),children:[t.jsx(T,{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(q,{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:$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(T,{name:"github-fill",className:"h-4 w-4"}),t.jsx("span",{children:"GitHub"})]}),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(T,{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})]})},Cv=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),ku=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),Su=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},Cu=s=>!s||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),$n="opencode-update-available",la="opencode-upgrade-progress",Pu=5e3,Iu=[1e4,6e4],Ui="opencode-update-toast-dismissed-version",Pv=()=>{const{t:s}=mt(),e=Ve(o=>o.showOpenCodeUpdateNotifications),n=ve.useRef(new Set),a=ve.useRef(!1);ve.useEffect(()=>{e||B.dismiss($n)},[e]);const r=ve.useCallback(()=>{B.dismiss(la),Pn({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),i=ve.useCallback(async()=>{if(!a.current){a.current=!0,B.dismiss($n),B.message(s("opencodeUpdate.toast.upgrading.title"),{id:la,description:s("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:t.jsx(T,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const o=await jt("/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"));B.success(s("opencodeUpdate.toast.updated.title"),{id:la,description:d?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:d.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(T,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(o){B.error(s("opencodeUpdate.toast.failed.title"),{id:la,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(!Ve.getState().showOpenCodeUpdateNotifications){B.dismiss($n);return}ku({version:p,dismissedVersion:Yn().getItem(Ui),seenVersions:n.current})&&(n.current.add(p),B.info(s("opencodeUpdate.toast.available.title"),{id:$n,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:()=>{Yn().setItem(Ui,p),Ct({openCodeUpdateToastDismissedVersion:p}),B.dismiss($n)}}}))},d=p=>{const u=Su(p.detail);o(u)};let c=!1;const h=[],m=async p=>{try{const u=await jt("/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=Cu(C);!c&&f&&o(f)}catch{const u=Iu[p];!c&&u!==void 0&&h.push(setTimeout(()=>{m(p+1)},u))}};return e&&h.push(setTimeout(()=>{m(0)},Pu)),window.addEventListener("openchamber:opencode-update-available",d),()=>{c=!0;for(const p of h)clearTimeout(p);window.removeEventListener("openchamber:opencode-update-available",d)}},[i,e,s]),null},Iv=()=>{const s=rt.c(3),[e,n]=l.useState(Du),{isUpdating:a}=e;let r,i;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>dd(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 Du(){return cd()}class Au 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(md,{className:"w-full max-w-md",children:[t.jsx(ud,{className:"text-center",children:t.jsxs(pd,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(T,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(gd,{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(q,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(T,{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 Eu(s){const e=rt.c(22),{t:n}=mt();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 h;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==o||e[16]!==d||e[17]!==c?(h={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]=h):h=e[18];let m;return e[19]!==s||e[20]!==h?(m=t.jsx(Au,{...s,texts:h}),e[19]=s,e[20]=h,e[21]=m):m=e[21],m}const Dv=s=>{const e=rt.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=Ps(Mu)||void 0;let o;e[0]!==a?(o=t.jsx(hd,{readOnly:a}),e[0]=a,e[1]=o):o=e[1];let d;return e[2]!==i||e[3]!==o?(d=t.jsx(Eu,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=d):d=e[4],d};function Mu(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(xc,{...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(bc,{...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=de("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 h;e[10]!==a?(h=de(fd,a),e[10]=a,e[11]=h):h=e[11];let m;e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==h?(m=t.jsx(yc,{"data-slot":"dropdown-menu-content",style:c,className:h,...i,children:n}),e[12]=n,e[13]=i,e[14]=c,e[15]=h,e[16]=m):m=e[16];let p;return e[17]!==d||e[18]!==m?(p=t.jsx(jc,{children:t.jsx(wc,{className:d,children:m})}),e[17]=d,e[18]=m,e[19]=p):p=e[19],p}function Hs(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=de(xd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(vc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}function Av(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=de(bd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(Nc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}const Dl=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),ta=s=>{const e=rt.c(39),{className:n}=s,{t:a}=mt(),r=as(Ru),i=as(Tu),o=as(Fu),d=gs();let c;e[0]!==r?(c=[...r].sort(Lu),e[0]=r,e[1]=c):c=e[1];const h=c;let m;e:{if(h.length===0){m=null;break e}let L;e[2]!==i||e[3]!==h?(L=h.find(M=>M.id===i)??h[0],e[2]=i,e[3]=h,e[4]=L):L=e[4],m=L}const p=m;if(d||h.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=Dl(C),e[8]=C,e[9]=f):f=e[9];const g=f;let b;e[10]!==n?(b=de(n),e[10]=n,e[11]=b):b=e[11];let A;e[12]!==a?(A=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=A):A=e[13];let S;e[14]!==a?(S=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=S):S=e[15];let k,E;e[16]===Symbol.for("react.memo_cache_sentinel")?(k=de("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(T,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=k,e[17]=E):(k=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 j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=t.jsx(T,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let x;e[21]!==N||e[22]!==A||e[23]!==S?(x=t.jsx(ds,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":A,title:S,className:k,children:[E,N,j]})}),e[21]=N,e[22]=A,e[23]=S,e[24]=x):x=e[24];const I=p?.id??"";let z;e[25]!==o?(z=L=>{L&&o(L)},e[25]=o,e[26]=z):z=e[26];let R;e[27]!==h?(R=h.map(Ou),e[27]=h,e[28]=R):R=e[28];let D;e[29]!==I||e[30]!==z||e[31]!==R?(D=t.jsx(ms,{align:"start",className:"w-auto",children:t.jsx(vd,{value:I,onValueChange:z,children:R})}),e[29]=I,e[30]=z,e[31]=R,e[32]=D):D=e[32];let v;e[33]!==x||e[34]!==D?(v=t.jsxs(us,{children:[x,D]}),e[33]=x,e[34]=D,e[35]=v):v=e[35];let y;return e[36]!==v||e[37]!==b?(y=t.jsx("div",{className:b,children:v}),e[36]=v,e[37]=b,e[38]=y):y=e[38],y};function Ru(s){return s.projects}function Tu(s){return s.activeProjectId}function Fu(s){return s.setActiveProject}function Lu(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function Ou(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=Dl(e);return t.jsx(yd,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function zu(s,e){return`opencode:sidebar-group:${s}:${e}`}const Ar=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=zu(r,n),e[0]=n,e[1]=r,e[2]=c):c=e[2];const h=c,m=l.useId();let p;e[3]!==d||e[4]!==h?(p=()=>{try{const D=localStorage.getItem(h);if(D!==null)return D==="true"}catch{}return d},e[3]=d,e[4]=h,e[5]=p):p=e[5];const[u,C]=ve.useState(p);let f,g;e[6]!==u||e[7]!==h?(f=()=>{try{localStorage.setItem(h,String(u))}catch{}},g=[h,u],e[6]=u,e[7]=h,e[8]=f,e[9]=g):(f=e[8],g=e[9]),ve.useEffect(f,g);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>C($u),e[10]=b):b=e[10];let A;e[11]===Symbol.for("react.memo_cache_sentinel")?(A=de("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]=A):A=e[11];const S=!u&&"-rotate-90";let k;e[12]!==S?(k=de("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",S),e[12]=S,e[13]=k):k=e[13];let E;e[14]!==k?(E=t.jsx(T,{name:"arrow-down-s",className:k}),e[14]=k,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 j;e[18]!==a?(j=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=j):j=e[19];let x;e[20]!==m||e[21]!==u||e[22]!==E||e[23]!==N||e[24]!==j?(x=t.jsxs("button",{type:"button",onClick:b,"aria-expanded":u,"aria-controls":m,className:A,children:[E,N,j]}),e[20]=m,e[21]=u,e[22]=E,e[23]=N,e[24]=j,e[25]=x):x=e[25];const I=!u;let z;e[26]!==o||e[27]!==m||e[28]!==I?(z=t.jsx("div",{id:m,hidden:I,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]=I,e[29]=z):z=e[29];let R;return e[30]!==x||e[31]!==z?(R=t.jsxs("div",{children:[x,z]}),e[30]=x,e[31]=z,e[32]=R):R=e[32],R};function $u(s){return!s}const Ku=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},Uu=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())},Bi=s=>{const e=Uu(Ku(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},Bu=({onItemSelect:s})=>{const{t:e}=mt(),[n,a]=l.useState(null),[r,i]=l.useState(""),[o,d]=l.useState(null),[c,h]=l.useState(null),[m,p]=l.useState(!1),[u,C]=l.useState(null),{selectedAgentName:f,agents:g,setSelectedAgent:b,setAgentDraft:A,createAgent:S,deleteAgent:k,loadAgents:E}=$a(Ss(F=>({selectedAgentName:F.selectedAgentName,agents:F.agents,setSelectedAgent:F.setSelectedAgent,setAgentDraft:F.setAgentDraft,createAgent:F.createAgent,deleteAgent:F.deleteAgent,loadAgents:F.loadAgents})));l.useEffect(()=>{E()},[E]);const N="bg-background",j=()=>{const F="new-agent";let G=F,w=1;for(;g.some(U=>U.name===G);)G=`${F}-${w}`,w++;A({name:G,scope:"user"}),b(G),s?.()},x=async F=>{if(Nn(F)){B.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(F),h("delete")},I=async F=>{Nn(F)&&(d(F),h("reset"))},z=()=>{d(null),h(null)},R=async()=>{if(!(!o||!c)){p(!0);try{await k(o.name,o.scope)?(c==="delete"?B.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):B.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),z()):c==="delete"?B.error(e("settings.agents.sidebar.toast.deleteFailed")):B.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(F){const G=F instanceof Error?F.message:"",w=/built-in|not deletable|not found/i.test(G);c==="delete"?B.error(e(w?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):B.error(e("settings.agents.sidebar.toast.resetFailed"))}p(!1)}},D=F=>{const G=F.name;let w=1,U=`${G}-copy`;for(;g.some(se=>se.name===U);)w++,U=`${G}-copy-${w}`;const Q=F,ie=F.model?.providerID&&F.model?.modelID?`${F.model.providerID}/${F.model.modelID}`:null,ce=F;A({name:U,scope:Q.scope||"user",description:F.description,model:ie,temperature:F.temperature,top_p:F.topP,prompt:F.prompt,mode:F.mode,permission:Bi(F.permission),disable:ce.disable}),b(U)},v=F=>{i(F.name),a(F)},y=async()=>{if(!n)return;const F=r.trim().replace(/\s+/g,"-");if(!F){B.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(F===n.name){a(null);return}if(g.some(Q=>Q.name===F)){B.error(e("settings.agents.sidebar.toast.agentExists"));return}const G=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,w=n;await S({name:F,description:n.description,model:G,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Bi(n.permission),disable:w.disable,scope:w.scope})?await k(n.name,w.scope)?(B.success(`Agent renamed to "${F}"`),b(F)):B.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):B.error(e("settings.agents.sidebar.toast.renameFailed")),a(null)},L=F=>{switch(F){case"primary":return t.jsx(T,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(T,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(T,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},M=g.filter(F=>!jd(F)),H=M.filter(Nn),_=M.filter(F=>!Nn(F)),{groupedCustomAgents:Z,ungroupedCustomAgents:W}=ve.useMemo(()=>{const F={},G=[];for(const U of _){const Q=U;Q.group?(F[Q.group]||(F[Q.group]=[]),F[Q.group].push(U)):G.push(U)}return{groupedCustomAgents:Object.keys(F).sort((U,Q)=>U.localeCompare(Q)).map(U=>({name:U,agents:F[U]})),ungroupedCustomAgents:G}},[_]);return t.jsxs("div",{className:de("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(ta,{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:M.length})}),t.jsx(q,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:t.jsx(T,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:M.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(T,{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:[H.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")}),H.map(F=>t.jsx(sr,{agent:F,isSelected:f===F.name,onSelect:()=>{b(F.name),s?.()},onReset:()=>I(F),onDuplicate:()=>D(F),getAgentModeIcon:L,isMenuOpen:u===F.name,onMenuOpenChange:G=>C(G?F.name:null)},F.name))]}),_.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")}),Z.map(({name:F,agents:G})=>t.jsx(Ar,{label:F,count:G.length,storageKey:"agents",children:G.map(w=>t.jsx(sr,{agent:w,isSelected:f===w.name,onSelect:()=>{b(w.name),s?.()},onRename:()=>v(w),onDelete:()=>x(w),onDuplicate:()=>D(w),getAgentModeIcon:L,isMenuOpen:u===w.name,onMenuOpenChange:U=>C(U?w.name:null)},w.name))},F)),W.map(F=>t.jsx(sr,{agent:F,isSelected:f===F.name,onSelect:()=>{b(F.name),s?.()},onRename:()=>v(F),onDelete:()=>x(F),onDuplicate:()=>D(F),getAgentModeIcon:L,isMenuOpen:u===F.name,onMenuOpenChange:G=>C(G?F.name:null)},F.name))]})]})}),t.jsx(Ut,{open:o!==null&&c!==null,onOpenChange:F=>{!F&&!m&&z()},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(qt,{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(q,{size:"sm",variant:"ghost",onClick:z,disabled:m,children:e("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",onClick:R,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx(Ut,{open:n!==null,onOpenChange:F=>!F&&a(null),children:t.jsxs(Bt,{children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(qt,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(ot,{value:r,onChange:F=>i(F.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:F=>{F.key==="Enter"&&y()}}),t.jsxs(Yt,{children:[t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",onClick:y,children:e("settings.common.actions.rename")})]})]})})]})},sr=s=>{const e=rt.c(52),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,getAgentModeIcon:h,isMenuOpen:m,onMenuOpenChange:p}=s,{t:u}=mt(),C=n;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Qn(),e[0]=f):f=e[0];const g=f,[b,A]=l.useState(!1);let S;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==u?(S=w=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(w,{onClick:U=>{U.stopPropagation(),d()},children:[t.jsx(T,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),t.jsxs(w,{onClick:U=>{U.stopPropagation(),c()},children:[t.jsx(T,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),o&&t.jsxs(w,{onClick:U=>{U.stopPropagation(),o()},children:[t.jsx(T,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),i&&t.jsxs(w,{onClick:U=>{U.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(T,{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]=S):S=e[6];const k=S,E=a?"bg-interactive-selection":"hover:bg-interactive-hover";let N;e[7]!==E?(N=de("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 j;e[9]===Symbol.for("react.memo_cache_sentinel")?(j=g?void 0:w=>{w.preventDefault(),A(!0)},e[9]=j):j=e[9];let x;e[10]!==N?(x=t.jsx("div",{className:N,onContextMenu:j}),e[10]=N,e[11]=x):x=e[11];let I;e[12]!==n.name?(I=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[12]=n.name,e[13]=I):I=e[13];let z;e[14]!==n.mode||e[15]!==h?(z=h(n.mode),e[14]=n.mode,e[15]=h,e[16]=z):z=e[16];let R;e[17]!==n||e[18]!==C.scope||e[19]!==u?(R=(C.scope||Nn(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:Nn(n)?u("settings.agents.sidebar.badge.system"):C.scope}),e[17]=n,e[18]=C.scope,e[19]=u,e[20]=R):R=e[20];let D;e[21]!==I||e[22]!==z||e[23]!==R?(D=t.jsxs("div",{className:"flex items-center gap-1.5",children:[I,z,R]}),e[21]=I,e[22]=z,e[23]=R,e[24]=D):D=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 y;e[27]!==r||e[28]!==D||e[29]!==v?(y=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:[D,v]}),e[27]=r,e[28]=D,e[29]=v,e[30]=y):y=e[30];let L;e[31]!==p?(L=w=>{w&&A(!1),p(w)},e[31]=p,e[32]=L):L=e[32];let M;e[33]===Symbol.for("react.memo_cache_sentinel")?(M=t.jsx(ds,{asChild:!0,children:t.jsx(q,{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(T,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=M):M=e[33];let H;e[34]!==k?(H=t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:k(ws)}),e[34]=k,e[35]=H):H=e[35];let _;e[36]!==m||e[37]!==L||e[38]!==H?(_=t.jsxs(us,{open:m,onOpenChange:L,children:[M,H]}),e[36]=m,e[37]=L,e[38]=H,e[39]=_):_=e[39];let Z;e[40]!==y||e[41]!==_?(Z=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[y,_]}),e[40]=y,e[41]=_,e[42]=Z):Z=e[42];let W;e[43]!==Z||e[44]!==x?(W=t.jsx(tn,{render:x,children:Z}),e[43]=Z,e[44]=x,e[45]=W):W=e[45];let F;e[46]!==k?(F=t.jsx(sn,{className:"w-fit min-w-20",children:k(Hs)}),e[46]=k,e[47]=F):F=e[47];let G;return e[48]!==b||e[49]!==W||e[50]!==F?(G=t.jsxs(en,{open:b,onOpenChange:A,children:[W,F]}),e[48]=b,e[49]=W,e[50]=F,e[51]=G):G=e[51],G};function Vi(s,e,n){return Math.min(n,Math.max(e,s))}function Vu(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=Vu(e);return n<=0?s:Number(s.toFixed(n))}const xs=ve.forwardRef((s,e)=>{const n=rt.c(125);let a,r,i,o,d,c,h,m,p,u,C,f,g;n[0]!==s?({value:g,onValueChange:h,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]=h,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],h=n[7],m=n[8],p=n[9],u=n[10],C=n[11],f=n[12],g=n[13]);const b=p===void 0?-1/0:p,A=u===void 0?1/0:u,S=C===void 0?1:C,k=f===void 0?"—":f,{t:E}=mt();let N;n[14]!==g?(N=()=>g===void 0?"":String(g),n[14]=g,n[15]=N):N=n[15];const[j,x]=ve.useState(N),{isMobile:I}=Cs(),z=ve.useRef(!1),R=ve.useRef(null);let D;n[16]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{if(typeof document>"u"||typeof window>"u")return;R.current?.();const Te=ue=>{ue.preventDefault(),ue.stopPropagation(),ue.stopImmediatePropagation?.(),R.current?.()},Me=window.setTimeout(()=>{R.current?.()},700),Y=()=>{window.clearTimeout(Me),document.removeEventListener("click",Te,!0),R.current=null};R.current=Y,document.addEventListener("click",Te,!0)},n[16]=D):D=n[16];const v=D;let y,L;n[17]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>{R.current?.()},L=[],n[17]=y,n[18]=L):(y=n[17],L=n[18]),ve.useEffect(y,L);let M,H;n[19]!==g?(H=()=>{x(g===void 0?"":String(g))},M=[g],n[19]=g,n[20]=M,n[21]=H):(M=n[20],H=n[21]),ve.useEffect(H,M);let _;e:{if(g!==void 0){_=g;break e}if(o!==void 0){_=o;break e}if(Number.isFinite(b)){_=b;break e}_=0}const Z=_;let W;n[22]!==A||n[23]!==b||n[24]!==h||n[25]!==S?(W=Te=>{const Me=Vi(Te,b,A);h(_i(Me,S))},n[22]=A,n[23]=b,n[24]=h,n[25]=S,n[26]=W):W=n[26];const F=W;let G;n[27]!==F||n[28]!==c?(G=Te=>{const Me=Te.target.value;if(x(Me),Me.trim()===""){c?.();return}const Y=Number(Me);Number.isFinite(Y)&&F(Y)},n[27]=F,n[28]=c,n[29]=G):G=n[29];const w=G;let U;n[30]!==j||n[31]!==A||n[32]!==b||n[33]!==d||n[34]!==c||n[35]!==h||n[36]!==S||n[37]!==g?(U=Te=>{if(j.trim()===""){c||x(g===void 0?"":String(g)),d?.(Te);return}const Me=Number(j);if(!Number.isFinite(Me))x(g===void 0?"":String(g));else{const Y=Vi(Me,b,A),ue=_i(Y,S);ue!==g&&h(ue),x(String(ue))}d?.(Te)},n[30]=j,n[31]=A,n[32]=b,n[33]=d,n[34]=c,n[35]=h,n[36]=S,n[37]=g,n[38]=U):U=n[38];const Q=U,ie=!!(i||Z>=A),ce=!!(i||Z<=b);let se;n[39]!==Z||n[40]!==F||n[41]!==ce||n[42]!==S?(se=()=>{ce||F(Z-S)},n[39]=Z,n[40]=F,n[41]=ce,n[42]=S,n[43]=se):se=n[43];const le=se;let oe;n[44]!==Z||n[45]!==F||n[46]!==ie||n[47]!==S?(oe=()=>{ie||F(Z+S)},n[44]=Z,n[45]=F,n[46]=ie,n[47]=S,n[48]=oe):oe=n[48];const fe=oe;let je;if(n[49]!==a||n[50]!==r||n[51]!==ce||n[52]!==j||n[53]!==k||n[54]!==le||n[55]!==fe||n[56]!==ie||n[57]!==I||n[58]!==E||n[59]!==g){je=Symbol.for("react.early_return_sentinel");e:{const Te=Y=>ue=>{ue.preventDefault(),ue.stopPropagation(),z.current=!0,v(),Y()},Me=Y=>ue=>{if(z.current){z.current=!1,ue.preventDefault(),ue.stopPropagation();return}Y()};if(I){let Y;n[61]!==r?(Y=de("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]=Y):Y=n[62];let ue;n[63]!==E?(ue=E("numberInput.actions.decreaseAria"),n[63]=E,n[64]=ue):ue=n[64];const Ne=Te(le),Ae=Me(le),Re=!ce&&"active:bg-interactive-hover";let Fe;n[65]!==Re?(Fe=de("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",Re),n[65]=Re,n[66]=Fe):Fe=n[66];let ne;n[67]===Symbol.for("react.memo_cache_sentinel")?(ne=t.jsx(T,{name:"subtract",className:"block h-4 w-4"}),n[67]=ne):ne=n[67];const Se=t.jsx("button",{type:"button","aria-label":ue,disabled:ce,onTouchStart:Ne,onClick:Ae,className:Fe,children:ne});let Pe;n[68]!==a?(Pe=de("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]=Pe):Pe=n[69];const $e=g===void 0?k:j;let Be;n[70]!==Pe||n[71]!==$e?(Be=t.jsx("div",{className:Pe,"aria-live":"polite",children:$e}),n[70]=Pe,n[71]=$e,n[72]=Be):Be=n[72];let Le;n[73]!==E?(Le=E("numberInput.actions.increaseAria"),n[73]=E,n[74]=Le):Le=n[74];const tt=Te(fe),J=Me(fe),V=!ie&&"active:bg-interactive-hover";let Ce;n[75]!==V?(Ce=de("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",V),n[75]=V,n[76]=Ce):Ce=n[76];let O;n[77]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx(T,{name:"add",className:"block h-4 w-4"}),n[77]=O):O=n[77];const Ke=t.jsx("button",{type:"button","aria-label":Le,disabled:ie,onTouchStart:tt,onClick:J,className:Ce,children:O});let Qe;n[78]!==Y||n[79]!==Se||n[80]!==Be||n[81]!==Ke?(Qe=t.jsxs("div",{className:Y,children:[Se,Be,Ke]}),n[78]=Y,n[79]=Se,n[80]=Be,n[81]=Ke,n[82]=Qe):Qe=n[82],je=Qe;break e}}n[49]=a,n[50]=r,n[51]=ce,n[52]=j,n[53]=k,n[54]=le,n[55]=fe,n[56]=ie,n[57]=I,n[58]=E,n[59]=g,n[60]=je}else je=n[60];if(je!==Symbol.for("react.early_return_sentinel"))return je;let ge;n[83]!==r?(ge=de("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]=ge):ge=n[84];let De;n[85]!==E?(De=E("numberInput.actions.decreaseAria"),n[85]=E,n[86]=De):De=n[86];let xe;n[87]!==Z||n[88]!==F||n[89]!==S?(xe=()=>F(Z-S),n[87]=Z,n[88]=F,n[89]=S,n[90]=xe):xe=n[90];let he,ye;n[91]===Symbol.for("react.memo_cache_sentinel")?(he=de("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(T,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=he,n[92]=ye):(he=n[91],ye=n[92]);let ee;n[93]!==ce||n[94]!==De||n[95]!==xe?(ee=t.jsx("button",{type:"button","aria-label":De,disabled:ce,onClick:xe,className:he,children:ye}),n[93]=ce,n[94]=De,n[95]=xe,n[96]=ee):ee=n[96];const re=m.inputMode??"numeric";let pe;n[97]!==a?(pe=de("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]=pe):pe=n[98];let K;n[99]!==i||n[100]!==j||n[101]!==Q||n[102]!==w||n[103]!==m||n[104]!==e||n[105]!==re||n[106]!==pe?(K=t.jsx("input",{...m,ref:e,type:"text",inputMode:re,value:j,onChange:w,onBlur:Q,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:pe}),n[99]=i,n[100]=j,n[101]=Q,n[102]=w,n[103]=m,n[104]=e,n[105]=re,n[106]=pe,n[107]=K):K=n[107];let X;n[108]!==E?(X=E("numberInput.actions.increaseAria"),n[108]=E,n[109]=X):X=n[109];let te;n[110]!==Z||n[111]!==F||n[112]!==S?(te=()=>F(Z+S),n[110]=Z,n[111]=F,n[112]=S,n[113]=te):te=n[113];let me,Ee;n[114]===Symbol.for("react.memo_cache_sentinel")?(me=de("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"),Ee=t.jsx(T,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=me,n[115]=Ee):(me=n[114],Ee=n[115]);let we;n[116]!==ie||n[117]!==X||n[118]!==te?(we=t.jsx("button",{type:"button","aria-label":X,disabled:ie,onClick:te,className:me,children:Ee}),n[116]=ie,n[117]=X,n[118]=te,n[119]=we):we=n[119];let Ie;return n[120]!==ge||n[121]!==ee||n[122]!==K||n[123]!==we?(Ie=t.jsxs("div",{className:ge,children:[ee,K,we]}),n[120]=ge,n[121]=ee,n[122]=K,n[123]=we,n[124]=Ie):Ie=n[124],Ie});xs.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"],Ca=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&&Ca(n.action)&&e.set(cn(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},ca=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)}),_u=(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})},Hu=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",Wu=(s,e)=>nn(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),nr=s=>{if(Array.isArray(s))return nn(s);if(Ca(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(Ca(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))Ca(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)},Gu=()=>{const{t:s}=mt(),{isMobile:e}=Cs(),{selectedAgentName:n,getAgentByName:a,createAgent:r,updateAgent:i,agents:o,agentDraft:d,setAgentDraft:c}=$a(Ss(Y=>({selectedAgentName:Y.selectedAgentName,getAgentByName:Y.getAgentByName,createAgent:Y.createAgent,updateAgent:Y.updateAgent,agents:Y.agents,agentDraft:Y.agentDraft,setAgentDraft:Y.setAgentDraft}))),h=n?a(n):null,m=!!(d&&d.name===n&&!h),[p,u]=l.useState(""),[C,f]=l.useState("user"),[g,b]=l.useState(""),[A,S]=l.useState("subagent"),[k,E]=l.useState(""),[N,j]=l.useState(void 0),[x,I]=l.useState(void 0),[z,R]=l.useState(""),[D,v]=l.useState("allow"),[y,L]=l.useState([]),[M,H]=l.useState([]),[_,Z]=l.useState(""),[W,F]=l.useState("*"),[G,w]=l.useState(!1),[U,Q]=l.useState(!1),ie=l.useRef(null),ce=vs(Y=>Y.currentDirectory??null),[se,le]=l.useState([]),oe=wd(Y=>Y.permission);l.useEffect(()=>{let Y=!1;return(async()=>{const Ne=await js.listToolIds({directory:ce});if(Y)return;const Ae=new Set(["write","patch","multiedit"]),Re=Ne.map(Fe=>typeof Fe=="string"?Fe.trim():"").filter(Boolean).filter(Fe=>Fe!=="*").filter(Fe=>Fe!=="invalid").filter(Fe=>!Ae.has(Fe));le(Array.from(new Set(Re)).sort((Fe,ne)=>Fe.localeCompare(ne)))})(),()=>{Y=!0}},[ce]);const fe=l.useMemo(()=>{const Y=new Set;for(const ue of o){const Ne=nn(nr(ue.permission));for(const Ae of Ne)Ae.permission&&Ae.permission!=="*"&&Ae.permission!=="invalid"&&Y.add(Ae.permission)}for(const ue of Object.values(oe))for(const Ne of ue){const Ae=Ne.permission?.trim();Ae&&Ae!=="invalid"&&Y.add(Ae)}for(const ue of se)Y.add(ue);return Array.from(Y).sort((ue,Ne)=>ue.localeCompare(Ne))},[o,oe,se]),je=l.useMemo(()=>ca(y),[y]),ge=l.useMemo(()=>ca(M),[M]),De=l.useCallback(Y=>ge.get(cn(Y,"*"))?.action,[ge]),xe=l.useCallback(Y=>M.filter(ue=>ue.permission===Y&&ue.pattern!=="*").sort((ue,Ne)=>ue.pattern.localeCompare(Ne.pattern)),[M]),he=l.useMemo(()=>{const Y=new Set;for(const ue of Hi)Y.add(ue);for(const ue of fe)Y.add(ue);return Array.from(Y).sort((ue,Ne)=>ue.localeCompare(Ne))},[fe]),ye=l.useCallback(Y=>{const ue=Y==="*"?D:De(Y)??D,Ne=xe(Y),Ae=!1,Re=Ne.reduce((ne,Se)=>(ne[Se.action]=(ne[Se.action]??0)+1,ne),{allow:0,ask:0,deny:0}),Fe=["allow","ask","deny"].filter(ne=>Re[ne]>0).map(ne=>`${Re[ne]} ${ne}`).join(", ");return{defaultAction:ue,patternRulesCount:Ne.length,patternSummary:Fe,hasDefaultHint:Ae}},[xe,De,D]),ee=l.useCallback(Y=>s(Y==="allow"?"settings.common.permission.allow":Y==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),re=l.useCallback(Y=>Y==="global"?s("settings.common.scope.global"):ee(Y),[ee,s]),pe=l.useMemo(()=>{const Y=new Set;for(const ue of Hi)Y.add(ue);for(const ue of fe)Y.add(ue);return Array.from(Y).sort((ue,Ne)=>ue.localeCompare(Ne))},[fe]),K=l.useCallback((Y,ue,Ne)=>{H(Ae=>{const Re=ca(Ae);return Re.set(cn(Y,ue),{permission:Y,pattern:ue,action:Ne}),Array.from(Re.values())})},[]),X=l.useCallback((Y,ue)=>{H(Ne=>{const Ae=ca(Ne);return Ae.delete(cn(Y,ue)),Array.from(Ae.values())})},[]),te=l.useCallback((Y,ue)=>{const Ne=je.get(cn(Y,ue));if(Ne){K(Y,ue,Ne.action);return}X(Y,ue)},[je,X,K]),me=l.useCallback((Y,ue,Ne)=>{K(Y,ue,Ne)},[K]),Ee=l.useCallback(Y=>{v(Y),H(ue=>ue.filter(Ne=>!(Ne.pattern==="*"&&Ne.action===Y)))},[]),we=l.useCallback(Y=>{const ue=_.trim();if(!ue){B.error(s("settings.agents.page.toast.permissionNameRequired"));return}const Ne=W.trim()||"*";if(ue==="*"&&Ne==="*"){Ee(Y),Z(""),F("*");return}Ne==="*"&&ue!=="*"&&Y===D?X(ue,"*"):K(ue,Ne,Y),Z(""),F("*")},[D,_,W,X,Ee,s,K]),Ie=l.useCallback(Y=>Y==="*"?s("settings.agents.page.permissions.defaultLabel"):Y==="webfetch"?"WebFetch":Y==="websearch"?"WebSearch":Y==="codesearch"?"CodeSearch":Y==="doom_loop"?"Doom Loop":Y==="external_directory"?"External Directory":Y==="todowrite"?"TodoWrite":Y==="todoread"?"TodoRead":Y.split(/[_-]+/g).filter(Boolean).map(ue=>ue.charAt(0).toUpperCase()+ue.slice(1)).join(" "),[s]);l.useEffect(()=>{Z(""),F("*");const Y=ue=>{const Ne=nn(ue),Ae=Hu(Ne),Re=Wu(Ne,Ae);return v(Ae),L(Re),H(Re),{global:Ae,rules:Re}};if(m&&d){const ue=d.name||"",Ne=d.scope||"user",Ae=d.description||"",Re=d.mode||"subagent",Fe=d.model||"",ne=d.temperature,Se=d.top_p,Pe=d.prompt||"";u(ue),f(Ne),b(Ae),S(Re),E(Fe),j(ne),I(Se),R(Pe);const $e=nr(d.permission),Be=Y($e);ie.current={draftName:ue,draftScope:Ne,description:Ae,mode:Re,model:Fe,temperature:ne,topP:Se,prompt:Pe,globalPermission:Be.global,permissionRules:Be.rules};return}if(h&&n===h.name){const ue=h.description||"",Ne=h.mode||"subagent",Ae=h.model?.providerID&&h.model?.modelID?`${h.model.providerID}/${h.model.modelID}`:"",Re=h.temperature,Fe=h.topP,ne=h.prompt||"";b(ue),S(Ne),E(Ae),j(Re),I(Fe),R(ne);const Se=Y(nr(h.permission));ie.current={draftName:"",draftScope:"user",description:ue,mode:Ne,model:Ae,temperature:Re,topP:Fe,prompt:ne,globalPermission:Se.global,permissionRules:Se.rules}}},[d,m,h,n]);const Te=l.useMemo(()=>{const Y=ie.current;return Y?!!(m&&(p!==Y.draftName||C!==Y.draftScope)||g!==Y.description||A!==Y.mode||k!==Y.model||N!==Y.temperature||x!==Y.topP||z!==Y.prompt||D!==Y.globalPermission||!_u(M,Y.permissionRules)):!1},[g,p,C,D,m,A,k,M,z,N,x]),Me=async()=>{const Y=m?p.trim().replace(/\s+/g,"-"):n?.trim();if(!Y){B.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(ue=>ue.name===Y)){B.error(s("settings.agents.sidebar.toast.agentExists"));return}Q(!0);try{const ue=k.trim(),Ne=z.trim(),Ae=qu(D,M),Re={name:Y,description:g.trim()||void 0,mode:A,model:ue===""?null:ue,temperature:N,top_p:x,prompt:Ne||(m?void 0:null),permission:Ae,scope:m?C:void 0};let Fe;m?(Fe=await r(Re),Fe&&c(null)):Fe=await i(Y,Re),Fe?B.success(s(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):B.error(s(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(ue){console.error("Error saving agent:",ue);const Ne=ue instanceof Error&&ue.message?ue.message:s("settings.agents.page.toast.saveUnexpectedError");B.error(Ne)}finally{Q(!1)}};return n?t.jsx(Jt,{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:m?s("settings.agents.page.title.new"):n}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(m?"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:[m&&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:p,onChange:Y=>u(Y.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Ft,{value:C,onValueChange:Y=>f(Y),children:[t.jsx(Lt,{className:"w-fit min-w-[100px]",children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Ot,{align:"end",children:[t.jsx(ft,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ft,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{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(ps,{value:g,onChange:Y=>b(Y.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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(T,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{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(q,{variant:"chip",size:"xs","aria-pressed":A==="primary",onClick:()=>S("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":A==="subagent",onClick:()=>S("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":A==="all",onClick:()=>S("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(_r,{providerId:En(k)?.providerId??"",modelId:En(k)?.modelId??"",onChange:(Y,ue)=>{E(Y&&ue?`${Y}/${ue}`:"")}})})]}),t.jsxs("div",{"data-settings-item":"agents.temperature",className:de("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:de("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(T,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{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:de("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(xs,{value:N,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),N!==void 0&&t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(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(T,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{"data-settings-item":"agents.top-p",className:de("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:de("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(T,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{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:de("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(xs,{value:x,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),x!==void 0&&t.jsx(q,{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(T,{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(ps,{value:z,onChange:Y=>R(Y.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(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>w(Y=>!Y),children:s(G?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),G?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(Ft,{value:D,onValueChange:Y=>Ee(Y),children:[t.jsx(Lt,{className:"w-[100px]",children:t.jsx(Kt,{children:ee(D)})}),t.jsxs(Ot,{children:[t.jsx(ft,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ft,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ft,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:he.filter(Y=>Y!=="*").map(Y=>{const ue=Ie(Y),{defaultAction:Ne,patternRulesCount:Ae}=ye(Y),Re=De(Y),Fe=Re??"global",ne=xe(Y),Se=["allow","ask","deny"].filter(Pe=>Pe!==D);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:ue}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:Y})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Ae>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:"*"}),Re&&t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>te(Y,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(T,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Ft,{value:Fe,onValueChange:Pe=>{if(Pe==="global"){X(Y,"*");return}K(Y,"*",Pe)},children:[t.jsx(Lt,{className:"w-[90px]",children:t.jsx(Kt,{children:re(Fe)})}),t.jsxs(Ot,{children:[t.jsx(ft,{value:"global",children:s("settings.common.scope.global")}),Se.map(Pe=>t.jsx(ft,{value:Pe,className:"capitalize",children:ee(Pe)},Pe))]})]})]}),ne.map(Pe=>{const $e=cn(Pe.permission,Pe.pattern),Be=je.get($e),Le=!Be,tt=!!(Be&&Be.action!==Pe.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:Pe.pattern}),Le&&t.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:s("settings.common.badge.new")}),tt&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:s("settings.common.badge.modified")}),(Le||tt)&&t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>Le?X(Pe.permission,Pe.pattern):te(Pe.permission,Pe.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(T,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Ft,{value:Pe.action,onValueChange:J=>me(Pe.permission,Pe.pattern,J),children:[t.jsx(Lt,{className:"w-[90px]",children:t.jsx(Kt,{children:ee(Pe.action)})}),t.jsxs(Ot,{children:[t.jsx(ft,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ft,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ft,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},$e)})]})]},Y)})}),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(Ft,{value:_,onValueChange:Z,children:[t.jsx(Lt,{className:"w-full sm:w-[160px]",children:_?t.jsx("span",{className:"truncate",children:Ie(_)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Ot,{children:pe.map(Y=>t.jsx(ft,{value:Y,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:Ie(Y)})})},Y))})]}),t.jsx(ot,{value:W,onChange:Y=>F(Y.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(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>we("allow"),children:s("settings.common.permission.allow")}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>we("ask"),children:s("settings.common.permission.ask")}),t.jsx(q,{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:he.map((Y,ue)=>{const{defaultAction:Ne,patternRulesCount:Ae,patternSummary:Re,hasDefaultHint:Fe}=ye(Y),ne=Ie(Y),Se=Fe?`${Ne} (env blocked)`:Ne;return t.jsxs("div",{className:de("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",ue>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:ne}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:Y})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Ae>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:Se})}):t.jsx("span",{className:de("typography-micro capitalize px-1.5 py-0.5 rounded",Se==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":Se==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:Se}),Ae>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:Re})})]})]},Y)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(q,{onClick:Me,disabled:U||!Te,size:"xs",className:"!font-normal",children:s(U?"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(T,{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")})]})})},Ju="~/.config/opencode/AGENTS.md",Al=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},Qu=s=>s.length>0&&!s.endsWith(`
1
+ import{ak as pc,e as rt,al as gc,j as t,H as ve,am as hc,an as fc,a as an,d as Zn,p as Kr,b as Ur,R as l,L as Ss,ab as xc,ac as bc,aa as yc,ad as vc,a8 as jc,a9 as wc,ae as Nc,ao as kc,ap as Sc,aq as Cc,u as Pc,l as Ic,n as Dc,w as Ac,C as Ec,S as Mc,ar as Rc,a6 as Tc,D as Fc,q as Lc,as as Oc,at as zc,au as $c,av as Kc,aw as Uc,X as Rs,ax as Bc,ay as xn,az as Zr,aA as Vc,aB as _c,aC as Ha,aD as Hc,aE as Wc,aF as qc,aG as ei,aH as Ma,aI as ti,k as wa,aJ as ml,aK as Br,aL as Oa,aM as ul,aN as si,aO as Gc,aP as Jc,aQ as Qc,aR as Yc,aS as ni,aT as Oe,aU as na,aV as Xc,aW as Zc,aX as ed,aY as td,aZ as sd,a_ as pl,a7 as nd,a$ as ai,b0 as ad,b1 as rd,b2 as id,b3 as od}from"./vendor-.bun-CIlawBoH.js";import{du as za,r as Ra,v as Ta,m as de,dv as Na,dw as ka,dx as Sa,D as as,u as mt,I as T,ax as It,ay as Dt,az as Et,dy as ld,av as _s,a$ as Ut,a_ as Bt,aZ as Vt,bD as Jt,w as jr,bc as Vr,p as mn,au as Cs,t as B,cl as gl,B as q,dz as Pn,dA as cd,dB as dd,dg as md,dC as ud,dD as pd,dE as gd,z as Ps,dF as hd,cQ as fd,cR as xd,cS as bd,c3 as yd,aq as ds,as as ms,c4 as vd,at as us,aT as $a,dG as jd,dH as Nn,aY as _t,bp as qt,bL as Yt,n as ot,dI as Qn,ap as ws,dd as wd,bE as Ft,bF as Lt,bG as Kt,bH as Ot,bI as ft,ba as ps,aU as _r,dJ as En,bb as Pt,dK as hl,dL as Nd,dM as kd,dN as Ka,dO as Vs,dP as In,aW as fl,dQ as kn,dR as Sd,dS as Cd,dT as Pd,dU as Id,dV as Dd,dW as Ad,dX as un,dY as Ed,q as Ua,c9 as ri,k as Md,cb as wr,a3 as xl,E as Rd,P as bl,G as yl,cd as Td,O as ii,cZ as Fd,db as vl,d2 as Ld,cy as Od,dZ as oi,d_ as zd,d$ as $d,e0 as li,e1 as Kd,e2 as Ud,e3 as Bd,e4 as Vd,aw as _d,e5 as Hd,H as Wd,K as qd,a as Hr,aH as ci,e6 as di,e7 as mi,aK as zn,e8 as Wa,e9 as Gd,ea as Jd,Q as pt,ad as Dn,a5 as Zs,ac as jl,ab as Qd,eb as Yd,ec as ui,ae as Xd,af as Zd,a6 as em,aB as tm,aC as sm,aD as wl,ed as qa,ee as pi,ef as nm,eg as am,eh as rm,ei as im,d3 as Ba,R as Bs,ej as om,cc as Nl,ek as lm,el as cm,em as dm,en as mm,eo as Ga,ep as gi,eq as um,er as pm,es as gm,et as hm,eu as fm,ev as Ja,ew as xm,ex as hi,ey as Wn,ez as bm,aQ as fi,eA as jn,aP as ym,eB as vm,eC as xi,eD as bi,X as Qs,F as jm,S as wm,eE as Nm,cj as aa,bh as Nr,bi as kr,bj as Sr,bk as Cr,bl as Us,bm as Es,bM as Sn,M as Gn,eF as yi,bY as km,eG as kl,bO as Sm,d7 as Cm,f as Pm,eH as Qa,a2 as Im,b4 as ra,bS as Dm,eI as Am,eJ as Em,eK as Mm,eL as Rm}from"./useAppFontEffects-DkrfZHQv.js";import{D as Yn,e as jt,o as js,u as vs,a1 as Tm,a2 as vi,a3 as Fm,a4 as Lm,w as gs,K as dn,b as Ve,j as ea,f as Ct,a as Xn,q as Fs,h as fs,a5 as Om,F as zm,a6 as Ya,E as $m,a7 as ji,a8 as Km,x as Um,a9 as wi,aa as Ni,ab as ki,ac as Si,ad as Xa,ae as Ci,C as Sl,af as Bm,ag as Vm,ah as _m,a0 as Hm,L as Wm,ai as qm,aj as Gm,ak as Jm}from"./index-DkRLSXEX.js";import{g as Qm,s as Ym}from"./mobileLayoutPreference-Dio-WWkI.js";function Xm(){return new Worker(pc,{type:"module"})}const Zm=["typescript","javascript","tsx","jsx","json","markdown"],Pr={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let Pi,Ii;const Di=s=>{const e=Pr[s],n=new gc({workerFactory:Xm,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:Zm,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},eu=s=>{if(!(typeof window>"u"))return s==="split"?(Ii??=Di("split"),Ii):(Pi??=Di("unified"),Pi)},tu=s=>{const e=rt.c(7),{children:n,renderTheme:a}=s,r=Ir("unified"),i=Ir("split");let o,d;e[0]!==a||e[1]!==i||e[2]!==r?(o=()=>{r&&r.setRenderOptions({theme:a,lineDiffType:Pr.unified.lineDiffType}),i&&i.setRenderOptions({theme:a,lineDiffType:Pr.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},kv=s=>{const e=rt.c(11),{children:n}=s,a=za();let r,i;if(e[0]!==a?.availableThemes||e[1]!==a?.darkThemeId||e[2]!==a?.lightThemeId){const h=Ra(!1),m=Ra(!0),p=a?.lightThemeId??h.metadata.id,u=a?.darkThemeId??m.metadata.id;i=a?.availableThemes.find(C=>C.metadata.id===p)??h,r=a?.availableThemes.find(C=>C.metadata.id===u)??m,Ta(i),Ta(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(tu,{renderTheme:d,children:n}),e[8]=n,e[9]=d,e[10]=c):c=e[10],c},Ir=s=>{const e=rt.c(2),n=s===void 0?"unified":s;let a;return e[0]!==n?(a=eu(n),e[0]=n,e[1]=a):a=e[1],a};function su(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 Fa=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=de("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(hc,{className:de("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(fc,{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});Fa.displayName="Switch";const ia=()=>{try{const e=as.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=js.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]))},oa=s=>typeof s!="string"?void 0:s.trim()||void 0,Za=800,nu=5e3,au="__default__",Dr=new Map,er=new Map,Cl=s=>s?.trim()||au,tr=s=>{Dr.delete(Cl(s))},Mn=an()(Zn(Kr((s,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>s({selectedMcpName:n}),setMcpDraft:n=>s({mcpDraft:n}),loadMcpConfigs:async n=>{const a=ia(),r=Cl(a),i=Date.now(),o=Dr.get(r)??0,d=e().mcpServers.length>0;if(!n?.force&&d&&i-o<nu)return!0;const c=er.get(r);if(!n?.force&&c)return c;const h=(async()=>{s({isLoading:!0});try{const m=a?`?directory=${encodeURIComponent(a)}`:"",p=await jt(`/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}),Dr.set(r,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),s({isLoading:!1}),!1}})();er.set(r,h);try{return await h}finally{er.delete(r)}},createMcp:async n=>{Na("Creating MCP server configuration…");let a=!1;try{const r=Mi(n),i=ia(),o=i?`?directory=${encodeURIComponent(i)}`:"",d=await jt(`/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 tr(i),c?.requiresReload?(a=!0,await ka({message:c.message,delayMs:c.reloadDelayMs??Za,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||Sa()}},updateMcp:async(n,a)=>{Na("Updating MCP server configuration…");let r=!1;try{const i=Mi(a),o=ia(),d=o?`?directory=${encodeURIComponent(o)}`:"",c=await jt(`/api/config/mcp/${encodeURIComponent(n)}${d}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),h=await c.json().catch(()=>null);if(!c.ok)throw new Error(h?.error||"Failed to update MCP server");return tr(o),h?.requiresReload?(r=!0,await ka({message:h.message,delayMs:h.reloadDelayMs??Za,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:h?.reloadFailed===!0,message:h?.message,warning:h?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:h?.reloadFailed===!0,message:h?.message,warning:h?.warning})}catch(i){throw console.error("[McpConfigStore] Failed to update MCP:",i),i}finally{r||Sa()}},deleteMcp:async n=>{Na("Deleting MCP server configuration…");let a=!1;try{const r=ia(),i=r?`?directory=${encodeURIComponent(r)}`:"",o=await jt(`/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 tr(r),d?.requiresReload&&(a=!0,await ka({message:d.message,delayMs:d.reloadDelayMs??Za,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||Sa()}},getMcpByName:n=>e().mcpServers.find(a=>a.name===n)}),{name:"mcp-config-store",storage:Ur(()=>Yn()),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:oa(s.oauthClientId),clientSecret:oa(s.oauthClientSecret),scope:oa(s.oauthScope),redirectUri:oa(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 ru={},iu={},Ks=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},yn=s=>Ks(s)??"__global__",on=s=>{const e=Ks(s);return e?js.getScopedApiClient(e):js.getApiClient()},is=an()(Zn((s,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const a=yn(n??vs.getState().currentDirectory);return e().byDirectory[a]??ru},getDiagnosticForDirectory:n=>{const a=yn(n??vs.getState().currentDirectory);return e().diagnosticsByDirectory[a]??iu},getErrorForDirectory:n=>{const a=yn(n??vs.getState().currentDirectory);return e().lastErrorKeys[a]??null},refresh:async n=>{const a=Ks(n?.directory??vs.getState().currentDirectory),r=yn(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(([h])=>!d[h]))},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=Ks(a??vs.getState().currentDirectory),i=yn(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(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:c}}}})),d}await e().refresh({directory:r,silent:!0})},disconnect:async(n,a)=>{const r=Ks(a??vs.getState().currentDirectory);await on(r).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:r,silent:!0})},startAuth:async(n,a)=>{const r=Ks(a??vs.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=Ks(r??vs.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=Ks(a??vs.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=Ks(a??vs.getState().currentDirectory),i=yn(r),o=on(r),c=e().getStatusForDirectory(r)[n]?.status==="connected";let h,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(C){h=C instanceof Error?C.message:"Connection failed",s(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:h??"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:h,warning:m}}}))),ou=(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}},lu=s=>{switch(s?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Sv=({active:s,className:e,headerAction:n,listClassName:a,hideHeader:r=!1,mobileListDensity:i=!1})=>{const{t:o}=mt(),c=vs(N=>N.currentDirectory)??null,h=is(N=>N.getStatusForDirectory(c)),m=is(N=>N.refresh),p=is(N=>N.connect),u=is(N=>N.disconnect),C=Mn(N=>N.mcpServers),f=Mn(N=>N.loadMcpConfigs),[g,b]=l.useState(!1),[A,S]=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 k=l.useMemo(()=>{const N=new Set(Object.keys(h));for(const j of C)j?.name&&N.add(j.name);return Array.from(N).sort((j,x)=>j.localeCompare(x))},[C,h]),E=l.useCallback(N=>{if(N?.preventDefault(),g)return;b(!0);const j=new Promise(x=>setTimeout(x,500));Promise.all([m({directory:c}),j]).finally(()=>{b(!1)})},[g,m,c]);return t.jsxs("div",{className:de("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(T,{name:"refresh",className:de("h-4 w-4",g&&"animate-spin")})})]})]})}),t.jsxs("div",{className:de("max-h-64 overflow-y-auto py-2",i&&"space-y-1 py-3",a),children:[k.map(N=>{const j=h[N],x=lu(j),I=j?.status==="connected",z=A===N,R=ou(j,o);return t.jsxs("div",{className:de("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx("span",{className:de("rounded-full flex-shrink-0",i?"h-2.5 w-2.5":"h-2 w-2",x==="success"&&"bg-status-success",x==="error"&&"bg-status-error",x==="warning"&&"bg-status-warning",x==="default"&&"bg-muted-foreground/40"),"aria-label":R})}),t.jsx(Et,{side:"left",children:t.jsx("p",{children:R})})]}),t.jsx("span",{className:de("truncate",i?"text-[17px] leading-6 font-medium":"typography-ui-label"),children:N})]})}),t.jsx(Fa,{checked:I,disabled:z,className:"data-[checked]:bg-status-info",onCheckedChange:async D=>{S(N);try{D?await p(N,c):await u(N,c)}finally{S(null)}}})]},N)}),k.length===0&&t.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:o("mcpDropdown.empty.configureInConfig")})]})]})};function cu(){if(typeof window>"u")return"unknown";try{const{deviceType:s}=ld();return s}catch{return"unknown"}}function du(){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 mu(){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 uu(s){const e=Ve.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",cu()),n.set("arch",du()),n.set("platform",mu()),s==="desktop"?(n.set("appType","desktop-electron"),n.set("instanceMode",ea()?"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=uu(s),a=typeof window<"u"?window.__VSCODE_CONFIG__?.extensionVersion:void 0;e||s==="vscode"&&a&&n.set("currentVersion",a);const r=await jt(`/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 pu(){return Lm()?"desktop":gs()?"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},Pl=an()((s,e)=>({...Ti,checkForUpdates:async()=>{const n=pu();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 Fm(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 Tm())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 gu(s){const e=new Date(`${s}T00:00:00`);return Number.isNaN(e.getTime())?s:new Intl.DateTimeFormat(Vr(),{year:"numeric",month:"short",day:"numeric"}).format(e)}function hu(s){return s.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Li(s){return s.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function fu(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 xu(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 Oi=2e3,bu=600*1e3;async function yu(){try{const s=await jt("/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 vu(){try{return(await jt("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function ju(s,e=Math.ceil(bu/Oi),n=Oi){for(let a=0;a<e;a++){try{const r=await jt("/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 vu())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:h="desktop"})=>{const{t:m}=mt(),[p,u]=ve.useState(!1),[C,f]=ve.useState("idle"),[g,b]=ve.useState(null),A=n?.version?`${Fi}/tag/v${n.version}`:Fi,S=i?.total?Math.round(i.downloaded/i.total*100):0,k=h==="web",E=n?.updateCommand||"openchamber update";ve.useEffect(()=>{s||(f("idle"),b(null))},[s]);const N=async()=>{(await mn(E)).ok&&(u(!0),setTimeout(()=>u(!1),2e3))},j=ve.useCallback(async R=>{await _s(R)},[]),x=ve.useCallback(async()=>{f("updating"),b(null);const R=await yu();if(!R.success){f("error"),b(R.error||m("updateDialog.error.updateFailed"));return}R.autoRestart&&(f("restarting"),await new Promise(v=>setTimeout(v,2e3))),f("reconnecting"),await ju(n?.currentVersion)?window.location.reload():(f("error"),b(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),I=C!=="idle"&&C!=="error",z=ve.useMemo(()=>{if(!n?.body)return null;const R=n.body.trim();if(!R)return null;const D=xu(R);if(D.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Li(R)};const v=[...D].sort((y,L)=>fu(y.version,L.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:v.map(y=>({version:y.version,dateLabel:gu(y.date),content:Li(hu(y.raw)||R)}))}},[n?.body,m]);return t.jsx(Ut,{open:s,onOpenChange:I?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(Vt,{className:"flex items-center gap-2.5",children:[t.jsx(T,{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:[k&&I&&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(T,{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&&!I&&t.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:t.jsx(Jt,{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:R=>{const v=R.target.closest("a");v&&v.href&&(R.preventDefault(),R.stopPropagation(),j(v.href))},children:t.jsx(jr,{content:z.content,disableLinkSafety:!0,enableFileReferences:!1})}):t.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:z.sections.map(R=>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",R.version]}),t.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:R.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:D=>{const y=D.target.closest("a");y&&y.href&&(D.preventDefault(),D.stopPropagation(),j(y.href))},children:t.jsx(jr,{content:R.content,disableLinkSafety:!0,enableFileReferences:!1})})]},R.version))})})}),k&&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(T,{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:de("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(T,{name:"check",className:"h-4 w-4"}):t.jsx(T,{name:"clipboard",className:"h-4 w-4"})})]})]}),!k&&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:[S,"%"]})]}),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:`${S}%`}})})]}),(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:A,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(T,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),t.jsxs("div",{className:"flex-1 flex justify-end",children:[!k&&!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(T,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!k&&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(T,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!k&&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(T,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),k&&!I&&t.jsxs("button",{onClick:x,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(T,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),k&&I&&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(T,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},$i="https://github.com/openchamber/openchamber",wu="https://discord.gg/ZYRSdnwwKA",Ki="https://x.com/openchamber_dev",Nu=800,Il=({initialUpdateDialogOpen:s=!1})=>{const{t:e}=mt(),[n,a]=l.useState(s),[r,i]=l.useState(!1),[o,d]=l.useState(null),[c,h]=l.useState(null),m=Pl(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 A=await jt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const S=await A.json().catch(()=>null),k=typeof S?.openchamberVersion=="string"&&S.openchamberVersion.trim().length>0?S.openchamberVersion.trim():null;g||d(k)}catch{g||d(null)}})(),()=>{g=!0}},[]),l.useEffect(()=>{let g=!1;return(async()=>{try{const A=await jt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!A.ok)return;const S=await A.json().catch(()=>null),k=typeof S?.currentVersion=="string"&&S.currentVersion.trim().length>0?S.currentVersion.trim():null;g||h(k)}catch{g||h(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&&(B.success(e("settings.openchamber.about.toast.latestVersion")),C.current=!1)},Nu);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(q,{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(T,{name:"loader",className:"size-4 animate-spin"}):t.jsx(T,{name:"refresh",className:"size-4"}),e(f?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!f&&m.available&&t.jsxs(q,{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(T,{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:$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(T,{name:"github-fill",className:"size-5"}),t.jsx("span",{children:"GitHub"})]}),t.jsxs("a",{href:wu,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(T,{name:"discord-fill",className:"size-5"}),t.jsx("span",{children:"Discord"})]})]}),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(T,{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(T,{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(q,{size:"sm",variant:"default",onClick:()=>a(!0),children:[t.jsx(T,{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(q,{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:$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(T,{name:"github-fill",className:"h-4 w-4"}),t.jsx("span",{children:"GitHub"})]}),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(T,{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})]})},Cv=s=>!(s.dismissed==="true"||s.sessionShown==="true"||s.hasActiveToast),ku=s=>!(!s.version||s.seenVersions.has(s.version)||s.dismissedVersion!==null&&s.dismissedVersion===s.version),Su=s=>{if(s===null||typeof s!="object")return"";const e=s.version;return typeof e!="string"?"":e.trim()},Cu=s=>!s||s.available!==!0||typeof s.latestVersion!="string"?"":s.latestVersion.trim(),$n="opencode-update-available",la="opencode-upgrade-progress",Pu=5e3,Iu=[1e4,6e4],Ui="opencode-update-toast-dismissed-version",Pv=()=>{const{t:s}=mt(),e=Ve(o=>o.showOpenCodeUpdateNotifications),n=ve.useRef(new Set),a=ve.useRef(!1);ve.useEffect(()=>{e||B.dismiss($n)},[e]);const r=ve.useCallback(()=>{B.dismiss(la),Pn({message:s("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]}).catch(()=>{})},[s]),i=ve.useCallback(async()=>{if(!a.current){a.current=!0,B.dismiss($n),B.message(s("opencodeUpdate.toast.upgrading.title"),{id:la,description:s("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:t.jsx(T,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const o=await jt("/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"));B.success(s("opencodeUpdate.toast.updated.title"),{id:la,description:d?.version?s("opencodeUpdate.toast.updated.descriptionWithVersion",{version:d.version}):s("opencodeUpdate.toast.updated.description"),duration:1/0,icon:t.jsx(T,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:s("opencodeUpdate.toast.actions.reload"),onClick:r}})}catch(o){B.error(s("opencodeUpdate.toast.failed.title"),{id:la,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(!Ve.getState().showOpenCodeUpdateNotifications){B.dismiss($n);return}ku({version:p,dismissedVersion:Yn().getItem(Ui),seenVersions:n.current})&&(n.current.add(p),B.info(s("opencodeUpdate.toast.available.title"),{id:$n,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:()=>{Yn().setItem(Ui,p),Ct({openCodeUpdateToastDismissedVersion:p}),B.dismiss($n)}}}))},d=p=>{const u=Su(p.detail);o(u)};let c=!1;const h=[],m=async p=>{try{const u=await jt("/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=Cu(C);!c&&f&&o(f)}catch{const u=Iu[p];!c&&u!==void 0&&h.push(setTimeout(()=>{m(p+1)},u))}};return e&&h.push(setTimeout(()=>{m(0)},Pu)),window.addEventListener("openchamber:opencode-update-available",d),()=>{c=!0;for(const p of h)clearTimeout(p);window.removeEventListener("openchamber:opencode-update-available",d)}},[i,e,s]),null},Iv=()=>{const s=rt.c(3),[e,n]=l.useState(Du),{isUpdating:a}=e;let r,i;if(s[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>dd(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 Du(){return cd()}class Au 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(md,{className:"w-full max-w-md",children:[t.jsx(ud,{className:"text-center",children:t.jsxs(pd,{className:"flex items-center justify-center gap-2 text-destructive",children:[t.jsx(T,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),t.jsxs(gd,{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(q,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[t.jsx(T,{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 Eu(s){const e=rt.c(22),{t:n}=mt();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 h;e[12]!==a||e[13]!==r||e[14]!==i||e[15]!==o||e[16]!==d||e[17]!==c?(h={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]=h):h=e[18];let m;return e[19]!==s||e[20]!==h?(m=t.jsx(Au,{...s,texts:h}),e[19]=s,e[20]=h,e[21]=m):m=e[21],m}const Dv=s=>{const e=rt.c(5),{readOnly:n}=s,a=n===void 0?!1:n,i=Ps(Mu)||void 0;let o;e[0]!==a?(o=t.jsx(hd,{readOnly:a}),e[0]=a,e[1]=o):o=e[1];let d;return e[2]!==i||e[3]!==o?(d=t.jsx(Eu,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=d):d=e[4],d};function Mu(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(xc,{...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(bc,{...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=de("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 h;e[10]!==a?(h=de(fd,a),e[10]=a,e[11]=h):h=e[11];let m;e[12]!==n||e[13]!==i||e[14]!==c||e[15]!==h?(m=t.jsx(yc,{"data-slot":"dropdown-menu-content",style:c,className:h,...i,children:n}),e[12]=n,e[13]=i,e[14]=c,e[15]=h,e[16]=m):m=e[16];let p;return e[17]!==d||e[18]!==m?(p=t.jsx(jc,{children:t.jsx(wc,{className:d,children:m})}),e[17]=d,e[18]=m,e[19]=p):p=e[19],p}function Hs(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=de(xd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(vc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}function Av(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=de(bd,n),e[3]=n,e[4]=r):r=e[4];let i;return e[5]!==a||e[6]!==r?(i=t.jsx(Nc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i}const Dl=s=>s.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),ta=s=>{const e=rt.c(39),{className:n}=s,{t:a}=mt(),r=as(Ru),i=as(Tu),o=as(Fu),d=gs();let c;e[0]!==r?(c=[...r].sort(Lu),e[0]=r,e[1]=c):c=e[1];const h=c;let m;e:{if(h.length===0){m=null;break e}let L;e[2]!==i||e[3]!==h?(L=h.find(M=>M.id===i)??h[0],e[2]=i,e[3]=h,e[4]=L):L=e[4],m=L}const p=m;if(d||h.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=Dl(C),e[8]=C,e[9]=f):f=e[9];const g=f;let b;e[10]!==n?(b=de(n),e[10]=n,e[11]=b):b=e[11];let A;e[12]!==a?(A=a("settings.shared.projectSelector.switchProjectAria"),e[12]=a,e[13]=A):A=e[13];let S;e[14]!==a?(S=a("settings.shared.projectSelector.switchProjectTitle"),e[14]=a,e[15]=S):S=e[15];let k,E;e[16]===Symbol.for("react.memo_cache_sentinel")?(k=de("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(T,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=k,e[17]=E):(k=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 j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=t.jsx(T,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let x;e[21]!==N||e[22]!==A||e[23]!==S?(x=t.jsx(ds,{asChild:!0,children:t.jsxs("button",{type:"button","aria-label":A,title:S,className:k,children:[E,N,j]})}),e[21]=N,e[22]=A,e[23]=S,e[24]=x):x=e[24];const I=p?.id??"";let z;e[25]!==o?(z=L=>{L&&o(L)},e[25]=o,e[26]=z):z=e[26];let R;e[27]!==h?(R=h.map(Ou),e[27]=h,e[28]=R):R=e[28];let D;e[29]!==I||e[30]!==z||e[31]!==R?(D=t.jsx(ms,{align:"start",className:"w-auto",children:t.jsx(vd,{value:I,onValueChange:z,children:R})}),e[29]=I,e[30]=z,e[31]=R,e[32]=D):D=e[32];let v;e[33]!==x||e[34]!==D?(v=t.jsxs(us,{children:[x,D]}),e[33]=x,e[34]=D,e[35]=v):v=e[35];let y;return e[36]!==v||e[37]!==b?(y=t.jsx("div",{className:b,children:v}),e[36]=v,e[37]=b,e[38]=y):y=e[38],y};function Ru(s){return s.projects}function Tu(s){return s.activeProjectId}function Fu(s){return s.setActiveProject}function Lu(s,e){return(s.label||s.path).localeCompare(e.label||e.path)}function Ou(s){const e=s.label?.trim()?s.label.trim():s.path.split("/").filter(Boolean).pop()||s.path,n=Dl(e);return t.jsx(yd,{value:s.id,children:t.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},s.id)}function zu(s,e){return`opencode:sidebar-group:${s}:${e}`}const Ar=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=zu(r,n),e[0]=n,e[1]=r,e[2]=c):c=e[2];const h=c,m=l.useId();let p;e[3]!==d||e[4]!==h?(p=()=>{try{const D=localStorage.getItem(h);if(D!==null)return D==="true"}catch{}return d},e[3]=d,e[4]=h,e[5]=p):p=e[5];const[u,C]=ve.useState(p);let f,g;e[6]!==u||e[7]!==h?(f=()=>{try{localStorage.setItem(h,String(u))}catch{}},g=[h,u],e[6]=u,e[7]=h,e[8]=f,e[9]=g):(f=e[8],g=e[9]),ve.useEffect(f,g);let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=()=>C($u),e[10]=b):b=e[10];let A;e[11]===Symbol.for("react.memo_cache_sentinel")?(A=de("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]=A):A=e[11];const S=!u&&"-rotate-90";let k;e[12]!==S?(k=de("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",S),e[12]=S,e[13]=k):k=e[13];let E;e[14]!==k?(E=t.jsx(T,{name:"arrow-down-s",className:k}),e[14]=k,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 j;e[18]!==a?(j=t.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:a}),e[18]=a,e[19]=j):j=e[19];let x;e[20]!==m||e[21]!==u||e[22]!==E||e[23]!==N||e[24]!==j?(x=t.jsxs("button",{type:"button",onClick:b,"aria-expanded":u,"aria-controls":m,className:A,children:[E,N,j]}),e[20]=m,e[21]=u,e[22]=E,e[23]=N,e[24]=j,e[25]=x):x=e[25];const I=!u;let z;e[26]!==o||e[27]!==m||e[28]!==I?(z=t.jsx("div",{id:m,hidden:I,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]=I,e[29]=z):z=e[29];let R;return e[30]!==x||e[31]!==z?(R=t.jsxs("div",{children:[x,z]}),e[30]=x,e[31]=z,e[32]=R):R=e[32],R};function $u(s){return!s}const Ku=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},Uu=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())},Bi=s=>{const e=Uu(Ku(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},Bu=({onItemSelect:s})=>{const{t:e}=mt(),[n,a]=l.useState(null),[r,i]=l.useState(""),[o,d]=l.useState(null),[c,h]=l.useState(null),[m,p]=l.useState(!1),[u,C]=l.useState(null),{selectedAgentName:f,agents:g,setSelectedAgent:b,setAgentDraft:A,createAgent:S,deleteAgent:k,loadAgents:E}=$a(Ss(F=>({selectedAgentName:F.selectedAgentName,agents:F.agents,setSelectedAgent:F.setSelectedAgent,setAgentDraft:F.setAgentDraft,createAgent:F.createAgent,deleteAgent:F.deleteAgent,loadAgents:F.loadAgents})));l.useEffect(()=>{E()},[E]);const N="bg-background",j=()=>{const F="new-agent";let G=F,w=1;for(;g.some(U=>U.name===G);)G=`${F}-${w}`,w++;A({name:G,scope:"user"}),b(G),s?.()},x=async F=>{if(Nn(F)){B.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}d(F),h("delete")},I=async F=>{Nn(F)&&(d(F),h("reset"))},z=()=>{d(null),h(null)},R=async()=>{if(!(!o||!c)){p(!0);try{await k(o.name,o.scope)?(c==="delete"?B.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):B.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),z()):c==="delete"?B.error(e("settings.agents.sidebar.toast.deleteFailed")):B.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(F){const G=F instanceof Error?F.message:"",w=/built-in|not deletable|not found/i.test(G);c==="delete"?B.error(e(w?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):B.error(e("settings.agents.sidebar.toast.resetFailed"))}p(!1)}},D=F=>{const G=F.name;let w=1,U=`${G}-copy`;for(;g.some(se=>se.name===U);)w++,U=`${G}-copy-${w}`;const Q=F,ie=F.model?.providerID&&F.model?.modelID?`${F.model.providerID}/${F.model.modelID}`:null,ce=F;A({name:U,scope:Q.scope||"user",description:F.description,model:ie,temperature:F.temperature,top_p:F.topP,prompt:F.prompt,mode:F.mode,permission:Bi(F.permission),disable:ce.disable}),b(U)},v=F=>{i(F.name),a(F)},y=async()=>{if(!n)return;const F=r.trim().replace(/\s+/g,"-");if(!F){B.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(F===n.name){a(null);return}if(g.some(Q=>Q.name===F)){B.error(e("settings.agents.sidebar.toast.agentExists"));return}const G=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,w=n;await S({name:F,description:n.description,model:G,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Bi(n.permission),disable:w.disable,scope:w.scope})?await k(n.name,w.scope)?(B.success(`Agent renamed to "${F}"`),b(F)):B.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):B.error(e("settings.agents.sidebar.toast.renameFailed")),a(null)},L=F=>{switch(F){case"primary":return t.jsx(T,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return t.jsx(T,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return t.jsx(T,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},M=g.filter(F=>!jd(F)),H=M.filter(Nn),_=M.filter(F=>!Nn(F)),{groupedCustomAgents:Z,ungroupedCustomAgents:W}=ve.useMemo(()=>{const F={},G=[];for(const U of _){const Q=U;Q.group?(F[Q.group]||(F[Q.group]=[]),F[Q.group].push(U)):G.push(U)}return{groupedCustomAgents:Object.keys(F).sort((U,Q)=>U.localeCompare(Q)).map(U=>({name:U,agents:F[U]})),ungroupedCustomAgents:G}},[_]);return t.jsxs("div",{className:de("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(ta,{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:M.length})}),t.jsx(q,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:t.jsx(T,{name:"add",className:"h-3.5 w-3.5"})})]})]}),t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:M.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(T,{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:[H.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")}),H.map(F=>t.jsx(sr,{agent:F,isSelected:f===F.name,onSelect:()=>{b(F.name),s?.()},onReset:()=>I(F),onDuplicate:()=>D(F),getAgentModeIcon:L,isMenuOpen:u===F.name,onMenuOpenChange:G=>C(G?F.name:null)},F.name))]}),_.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")}),Z.map(({name:F,agents:G})=>t.jsx(Ar,{label:F,count:G.length,storageKey:"agents",children:G.map(w=>t.jsx(sr,{agent:w,isSelected:f===w.name,onSelect:()=>{b(w.name),s?.()},onRename:()=>v(w),onDelete:()=>x(w),onDuplicate:()=>D(w),getAgentModeIcon:L,isMenuOpen:u===w.name,onMenuOpenChange:U=>C(U?w.name:null)},w.name))},F)),W.map(F=>t.jsx(sr,{agent:F,isSelected:f===F.name,onSelect:()=>{b(F.name),s?.()},onRename:()=>v(F),onDelete:()=>x(F),onDuplicate:()=>D(F),getAgentModeIcon:L,isMenuOpen:u===F.name,onMenuOpenChange:G=>C(G?F.name:null)},F.name))]})]})}),t.jsx(Ut,{open:o!==null&&c!==null,onOpenChange:F=>{!F&&!m&&z()},children:t.jsxs(Bt,{className:"max-w-md",children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),t.jsx(qt,{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(q,{size:"sm",variant:"ghost",onClick:z,disabled:m,children:e("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",onClick:R,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),t.jsx(Ut,{open:n!==null,onOpenChange:F=>!F&&a(null),children:t.jsxs(Bt,{children:[t.jsxs(_t,{children:[t.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.title")}),t.jsx(qt,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),t.jsx(ot,{value:r,onChange:F=>i(F.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:F=>{F.key==="Enter"&&y()}}),t.jsxs(Yt,{children:[t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e("settings.common.actions.cancel")}),t.jsx(q,{size:"sm",onClick:y,children:e("settings.common.actions.rename")})]})]})})]})},sr=s=>{const e=rt.c(52),{agent:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,getAgentModeIcon:h,isMenuOpen:m,onMenuOpenChange:p}=s,{t:u}=mt(),C=n;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Qn(),e[0]=f):f=e[0];const g=f,[b,A]=l.useState(!1);let S;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==u?(S=w=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(w,{onClick:U=>{U.stopPropagation(),d()},children:[t.jsx(T,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),t.jsxs(w,{onClick:U=>{U.stopPropagation(),c()},children:[t.jsx(T,{name:"file-copy",className:"h-4 w-4 mr-px"}),u("settings.common.actions.duplicate")]}),o&&t.jsxs(w,{onClick:U=>{U.stopPropagation(),o()},children:[t.jsx(T,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),i&&t.jsxs(w,{onClick:U=>{U.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(T,{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]=S):S=e[6];const k=S,E=a?"bg-interactive-selection":"hover:bg-interactive-hover";let N;e[7]!==E?(N=de("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 j;e[9]===Symbol.for("react.memo_cache_sentinel")?(j=g?void 0:w=>{w.preventDefault(),A(!0)},e[9]=j):j=e[9];let x;e[10]!==N?(x=t.jsx("div",{className:N,onContextMenu:j}),e[10]=N,e[11]=x):x=e[11];let I;e[12]!==n.name?(I=t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[12]=n.name,e[13]=I):I=e[13];let z;e[14]!==n.mode||e[15]!==h?(z=h(n.mode),e[14]=n.mode,e[15]=h,e[16]=z):z=e[16];let R;e[17]!==n||e[18]!==C.scope||e[19]!==u?(R=(C.scope||Nn(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:Nn(n)?u("settings.agents.sidebar.badge.system"):C.scope}),e[17]=n,e[18]=C.scope,e[19]=u,e[20]=R):R=e[20];let D;e[21]!==I||e[22]!==z||e[23]!==R?(D=t.jsxs("div",{className:"flex items-center gap-1.5",children:[I,z,R]}),e[21]=I,e[22]=z,e[23]=R,e[24]=D):D=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 y;e[27]!==r||e[28]!==D||e[29]!==v?(y=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:[D,v]}),e[27]=r,e[28]=D,e[29]=v,e[30]=y):y=e[30];let L;e[31]!==p?(L=w=>{w&&A(!1),p(w)},e[31]=p,e[32]=L):L=e[32];let M;e[33]===Symbol.for("react.memo_cache_sentinel")?(M=t.jsx(ds,{asChild:!0,children:t.jsx(q,{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(T,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=M):M=e[33];let H;e[34]!==k?(H=t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:k(ws)}),e[34]=k,e[35]=H):H=e[35];let _;e[36]!==m||e[37]!==L||e[38]!==H?(_=t.jsxs(us,{open:m,onOpenChange:L,children:[M,H]}),e[36]=m,e[37]=L,e[38]=H,e[39]=_):_=e[39];let Z;e[40]!==y||e[41]!==_?(Z=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[y,_]}),e[40]=y,e[41]=_,e[42]=Z):Z=e[42];let W;e[43]!==Z||e[44]!==x?(W=t.jsx(tn,{render:x,children:Z}),e[43]=Z,e[44]=x,e[45]=W):W=e[45];let F;e[46]!==k?(F=t.jsx(sn,{className:"w-fit min-w-20",children:k(Hs)}),e[46]=k,e[47]=F):F=e[47];let G;return e[48]!==b||e[49]!==W||e[50]!==F?(G=t.jsxs(en,{open:b,onOpenChange:A,children:[W,F]}),e[48]=b,e[49]=W,e[50]=F,e[51]=G):G=e[51],G};function Vi(s,e,n){return Math.min(n,Math.max(e,s))}function Vu(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=Vu(e);return n<=0?s:Number(s.toFixed(n))}const xs=ve.forwardRef((s,e)=>{const n=rt.c(125);let a,r,i,o,d,c,h,m,p,u,C,f,g;n[0]!==s?({value:g,onValueChange:h,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]=h,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],h=n[7],m=n[8],p=n[9],u=n[10],C=n[11],f=n[12],g=n[13]);const b=p===void 0?-1/0:p,A=u===void 0?1/0:u,S=C===void 0?1:C,k=f===void 0?"—":f,{t:E}=mt();let N;n[14]!==g?(N=()=>g===void 0?"":String(g),n[14]=g,n[15]=N):N=n[15];const[j,x]=ve.useState(N),{isMobile:I}=Cs(),z=ve.useRef(!1),R=ve.useRef(null);let D;n[16]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{if(typeof document>"u"||typeof window>"u")return;R.current?.();const Te=ue=>{ue.preventDefault(),ue.stopPropagation(),ue.stopImmediatePropagation?.(),R.current?.()},Me=window.setTimeout(()=>{R.current?.()},700),Y=()=>{window.clearTimeout(Me),document.removeEventListener("click",Te,!0),R.current=null};R.current=Y,document.addEventListener("click",Te,!0)},n[16]=D):D=n[16];const v=D;let y,L;n[17]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>{R.current?.()},L=[],n[17]=y,n[18]=L):(y=n[17],L=n[18]),ve.useEffect(y,L);let M,H;n[19]!==g?(H=()=>{x(g===void 0?"":String(g))},M=[g],n[19]=g,n[20]=M,n[21]=H):(M=n[20],H=n[21]),ve.useEffect(H,M);let _;e:{if(g!==void 0){_=g;break e}if(o!==void 0){_=o;break e}if(Number.isFinite(b)){_=b;break e}_=0}const Z=_;let W;n[22]!==A||n[23]!==b||n[24]!==h||n[25]!==S?(W=Te=>{const Me=Vi(Te,b,A);h(_i(Me,S))},n[22]=A,n[23]=b,n[24]=h,n[25]=S,n[26]=W):W=n[26];const F=W;let G;n[27]!==F||n[28]!==c?(G=Te=>{const Me=Te.target.value;if(x(Me),Me.trim()===""){c?.();return}const Y=Number(Me);Number.isFinite(Y)&&F(Y)},n[27]=F,n[28]=c,n[29]=G):G=n[29];const w=G;let U;n[30]!==j||n[31]!==A||n[32]!==b||n[33]!==d||n[34]!==c||n[35]!==h||n[36]!==S||n[37]!==g?(U=Te=>{if(j.trim()===""){c||x(g===void 0?"":String(g)),d?.(Te);return}const Me=Number(j);if(!Number.isFinite(Me))x(g===void 0?"":String(g));else{const Y=Vi(Me,b,A),ue=_i(Y,S);ue!==g&&h(ue),x(String(ue))}d?.(Te)},n[30]=j,n[31]=A,n[32]=b,n[33]=d,n[34]=c,n[35]=h,n[36]=S,n[37]=g,n[38]=U):U=n[38];const Q=U,ie=!!(i||Z>=A),ce=!!(i||Z<=b);let se;n[39]!==Z||n[40]!==F||n[41]!==ce||n[42]!==S?(se=()=>{ce||F(Z-S)},n[39]=Z,n[40]=F,n[41]=ce,n[42]=S,n[43]=se):se=n[43];const le=se;let oe;n[44]!==Z||n[45]!==F||n[46]!==ie||n[47]!==S?(oe=()=>{ie||F(Z+S)},n[44]=Z,n[45]=F,n[46]=ie,n[47]=S,n[48]=oe):oe=n[48];const fe=oe;let je;if(n[49]!==a||n[50]!==r||n[51]!==ce||n[52]!==j||n[53]!==k||n[54]!==le||n[55]!==fe||n[56]!==ie||n[57]!==I||n[58]!==E||n[59]!==g){je=Symbol.for("react.early_return_sentinel");e:{const Te=Y=>ue=>{ue.preventDefault(),ue.stopPropagation(),z.current=!0,v(),Y()},Me=Y=>ue=>{if(z.current){z.current=!1,ue.preventDefault(),ue.stopPropagation();return}Y()};if(I){let Y;n[61]!==r?(Y=de("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]=Y):Y=n[62];let ue;n[63]!==E?(ue=E("numberInput.actions.decreaseAria"),n[63]=E,n[64]=ue):ue=n[64];const Ne=Te(le),Ae=Me(le),Re=!ce&&"active:bg-interactive-hover";let Fe;n[65]!==Re?(Fe=de("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",Re),n[65]=Re,n[66]=Fe):Fe=n[66];let ne;n[67]===Symbol.for("react.memo_cache_sentinel")?(ne=t.jsx(T,{name:"subtract",className:"block h-4 w-4"}),n[67]=ne):ne=n[67];const Se=t.jsx("button",{type:"button","aria-label":ue,disabled:ce,onTouchStart:Ne,onClick:Ae,className:Fe,children:ne});let Pe;n[68]!==a?(Pe=de("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]=Pe):Pe=n[69];const $e=g===void 0?k:j;let Be;n[70]!==Pe||n[71]!==$e?(Be=t.jsx("div",{className:Pe,"aria-live":"polite",children:$e}),n[70]=Pe,n[71]=$e,n[72]=Be):Be=n[72];let Le;n[73]!==E?(Le=E("numberInput.actions.increaseAria"),n[73]=E,n[74]=Le):Le=n[74];const tt=Te(fe),J=Me(fe),V=!ie&&"active:bg-interactive-hover";let Ce;n[75]!==V?(Ce=de("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",V),n[75]=V,n[76]=Ce):Ce=n[76];let O;n[77]===Symbol.for("react.memo_cache_sentinel")?(O=t.jsx(T,{name:"add",className:"block h-4 w-4"}),n[77]=O):O=n[77];const Ke=t.jsx("button",{type:"button","aria-label":Le,disabled:ie,onTouchStart:tt,onClick:J,className:Ce,children:O});let Qe;n[78]!==Y||n[79]!==Se||n[80]!==Be||n[81]!==Ke?(Qe=t.jsxs("div",{className:Y,children:[Se,Be,Ke]}),n[78]=Y,n[79]=Se,n[80]=Be,n[81]=Ke,n[82]=Qe):Qe=n[82],je=Qe;break e}}n[49]=a,n[50]=r,n[51]=ce,n[52]=j,n[53]=k,n[54]=le,n[55]=fe,n[56]=ie,n[57]=I,n[58]=E,n[59]=g,n[60]=je}else je=n[60];if(je!==Symbol.for("react.early_return_sentinel"))return je;let ge;n[83]!==r?(ge=de("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]=ge):ge=n[84];let De;n[85]!==E?(De=E("numberInput.actions.decreaseAria"),n[85]=E,n[86]=De):De=n[86];let xe;n[87]!==Z||n[88]!==F||n[89]!==S?(xe=()=>F(Z-S),n[87]=Z,n[88]=F,n[89]=S,n[90]=xe):xe=n[90];let he,ye;n[91]===Symbol.for("react.memo_cache_sentinel")?(he=de("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(T,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=he,n[92]=ye):(he=n[91],ye=n[92]);let ee;n[93]!==ce||n[94]!==De||n[95]!==xe?(ee=t.jsx("button",{type:"button","aria-label":De,disabled:ce,onClick:xe,className:he,children:ye}),n[93]=ce,n[94]=De,n[95]=xe,n[96]=ee):ee=n[96];const re=m.inputMode??"numeric";let pe;n[97]!==a?(pe=de("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]=pe):pe=n[98];let K;n[99]!==i||n[100]!==j||n[101]!==Q||n[102]!==w||n[103]!==m||n[104]!==e||n[105]!==re||n[106]!==pe?(K=t.jsx("input",{...m,ref:e,type:"text",inputMode:re,value:j,onChange:w,onBlur:Q,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:pe}),n[99]=i,n[100]=j,n[101]=Q,n[102]=w,n[103]=m,n[104]=e,n[105]=re,n[106]=pe,n[107]=K):K=n[107];let X;n[108]!==E?(X=E("numberInput.actions.increaseAria"),n[108]=E,n[109]=X):X=n[109];let te;n[110]!==Z||n[111]!==F||n[112]!==S?(te=()=>F(Z+S),n[110]=Z,n[111]=F,n[112]=S,n[113]=te):te=n[113];let me,Ee;n[114]===Symbol.for("react.memo_cache_sentinel")?(me=de("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"),Ee=t.jsx(T,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=me,n[115]=Ee):(me=n[114],Ee=n[115]);let we;n[116]!==ie||n[117]!==X||n[118]!==te?(we=t.jsx("button",{type:"button","aria-label":X,disabled:ie,onClick:te,className:me,children:Ee}),n[116]=ie,n[117]=X,n[118]=te,n[119]=we):we=n[119];let Ie;return n[120]!==ge||n[121]!==ee||n[122]!==K||n[123]!==we?(Ie=t.jsxs("div",{className:ge,children:[ee,K,we]}),n[120]=ge,n[121]=ee,n[122]=K,n[123]=we,n[124]=Ie):Ie=n[124],Ie});xs.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"],Ca=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&&Ca(n.action)&&e.set(cn(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},ca=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)}),_u=(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})},Hu=s=>s.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",Wu=(s,e)=>nn(s).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),nr=s=>{if(Array.isArray(s))return nn(s);if(Ca(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(Ca(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))Ca(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)},Gu=()=>{const{t:s}=mt(),{isMobile:e}=Cs(),{selectedAgentName:n,getAgentByName:a,createAgent:r,updateAgent:i,agents:o,agentDraft:d,setAgentDraft:c}=$a(Ss(Y=>({selectedAgentName:Y.selectedAgentName,getAgentByName:Y.getAgentByName,createAgent:Y.createAgent,updateAgent:Y.updateAgent,agents:Y.agents,agentDraft:Y.agentDraft,setAgentDraft:Y.setAgentDraft}))),h=n?a(n):null,m=!!(d&&d.name===n&&!h),[p,u]=l.useState(""),[C,f]=l.useState("user"),[g,b]=l.useState(""),[A,S]=l.useState("subagent"),[k,E]=l.useState(""),[N,j]=l.useState(void 0),[x,I]=l.useState(void 0),[z,R]=l.useState(""),[D,v]=l.useState("allow"),[y,L]=l.useState([]),[M,H]=l.useState([]),[_,Z]=l.useState(""),[W,F]=l.useState("*"),[G,w]=l.useState(!1),[U,Q]=l.useState(!1),ie=l.useRef(null),ce=vs(Y=>Y.currentDirectory??null),[se,le]=l.useState([]),oe=wd(Y=>Y.permission);l.useEffect(()=>{let Y=!1;return(async()=>{const Ne=await js.listToolIds({directory:ce});if(Y)return;const Ae=new Set(["write","patch","multiedit"]),Re=Ne.map(Fe=>typeof Fe=="string"?Fe.trim():"").filter(Boolean).filter(Fe=>Fe!=="*").filter(Fe=>Fe!=="invalid").filter(Fe=>!Ae.has(Fe));le(Array.from(new Set(Re)).sort((Fe,ne)=>Fe.localeCompare(ne)))})(),()=>{Y=!0}},[ce]);const fe=l.useMemo(()=>{const Y=new Set;for(const ue of o){const Ne=nn(nr(ue.permission));for(const Ae of Ne)Ae.permission&&Ae.permission!=="*"&&Ae.permission!=="invalid"&&Y.add(Ae.permission)}for(const ue of Object.values(oe))for(const Ne of ue){const Ae=Ne.permission?.trim();Ae&&Ae!=="invalid"&&Y.add(Ae)}for(const ue of se)Y.add(ue);return Array.from(Y).sort((ue,Ne)=>ue.localeCompare(Ne))},[o,oe,se]),je=l.useMemo(()=>ca(y),[y]),ge=l.useMemo(()=>ca(M),[M]),De=l.useCallback(Y=>ge.get(cn(Y,"*"))?.action,[ge]),xe=l.useCallback(Y=>M.filter(ue=>ue.permission===Y&&ue.pattern!=="*").sort((ue,Ne)=>ue.pattern.localeCompare(Ne.pattern)),[M]),he=l.useMemo(()=>{const Y=new Set;for(const ue of Hi)Y.add(ue);for(const ue of fe)Y.add(ue);return Array.from(Y).sort((ue,Ne)=>ue.localeCompare(Ne))},[fe]),ye=l.useCallback(Y=>{const ue=Y==="*"?D:De(Y)??D,Ne=xe(Y),Ae=!1,Re=Ne.reduce((ne,Se)=>(ne[Se.action]=(ne[Se.action]??0)+1,ne),{allow:0,ask:0,deny:0}),Fe=["allow","ask","deny"].filter(ne=>Re[ne]>0).map(ne=>`${Re[ne]} ${ne}`).join(", ");return{defaultAction:ue,patternRulesCount:Ne.length,patternSummary:Fe,hasDefaultHint:Ae}},[xe,De,D]),ee=l.useCallback(Y=>s(Y==="allow"?"settings.common.permission.allow":Y==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[s]),re=l.useCallback(Y=>Y==="global"?s("settings.common.scope.global"):ee(Y),[ee,s]),pe=l.useMemo(()=>{const Y=new Set;for(const ue of Hi)Y.add(ue);for(const ue of fe)Y.add(ue);return Array.from(Y).sort((ue,Ne)=>ue.localeCompare(Ne))},[fe]),K=l.useCallback((Y,ue,Ne)=>{H(Ae=>{const Re=ca(Ae);return Re.set(cn(Y,ue),{permission:Y,pattern:ue,action:Ne}),Array.from(Re.values())})},[]),X=l.useCallback((Y,ue)=>{H(Ne=>{const Ae=ca(Ne);return Ae.delete(cn(Y,ue)),Array.from(Ae.values())})},[]),te=l.useCallback((Y,ue)=>{const Ne=je.get(cn(Y,ue));if(Ne){K(Y,ue,Ne.action);return}X(Y,ue)},[je,X,K]),me=l.useCallback((Y,ue,Ne)=>{K(Y,ue,Ne)},[K]),Ee=l.useCallback(Y=>{v(Y),H(ue=>ue.filter(Ne=>!(Ne.pattern==="*"&&Ne.action===Y)))},[]),we=l.useCallback(Y=>{const ue=_.trim();if(!ue){B.error(s("settings.agents.page.toast.permissionNameRequired"));return}const Ne=W.trim()||"*";if(ue==="*"&&Ne==="*"){Ee(Y),Z(""),F("*");return}Ne==="*"&&ue!=="*"&&Y===D?X(ue,"*"):K(ue,Ne,Y),Z(""),F("*")},[D,_,W,X,Ee,s,K]),Ie=l.useCallback(Y=>Y==="*"?s("settings.agents.page.permissions.defaultLabel"):Y==="webfetch"?"WebFetch":Y==="websearch"?"WebSearch":Y==="codesearch"?"CodeSearch":Y==="doom_loop"?"Doom Loop":Y==="external_directory"?"External Directory":Y==="todowrite"?"TodoWrite":Y==="todoread"?"TodoRead":Y.split(/[_-]+/g).filter(Boolean).map(ue=>ue.charAt(0).toUpperCase()+ue.slice(1)).join(" "),[s]);l.useEffect(()=>{Z(""),F("*");const Y=ue=>{const Ne=nn(ue),Ae=Hu(Ne),Re=Wu(Ne,Ae);return v(Ae),L(Re),H(Re),{global:Ae,rules:Re}};if(m&&d){const ue=d.name||"",Ne=d.scope||"user",Ae=d.description||"",Re=d.mode||"subagent",Fe=d.model||"",ne=d.temperature,Se=d.top_p,Pe=d.prompt||"";u(ue),f(Ne),b(Ae),S(Re),E(Fe),j(ne),I(Se),R(Pe);const $e=nr(d.permission),Be=Y($e);ie.current={draftName:ue,draftScope:Ne,description:Ae,mode:Re,model:Fe,temperature:ne,topP:Se,prompt:Pe,globalPermission:Be.global,permissionRules:Be.rules};return}if(h&&n===h.name){const ue=h.description||"",Ne=h.mode||"subagent",Ae=h.model?.providerID&&h.model?.modelID?`${h.model.providerID}/${h.model.modelID}`:"",Re=h.temperature,Fe=h.topP,ne=h.prompt||"";b(ue),S(Ne),E(Ae),j(Re),I(Fe),R(ne);const Se=Y(nr(h.permission));ie.current={draftName:"",draftScope:"user",description:ue,mode:Ne,model:Ae,temperature:Re,topP:Fe,prompt:ne,globalPermission:Se.global,permissionRules:Se.rules}}},[d,m,h,n]);const Te=l.useMemo(()=>{const Y=ie.current;return Y?!!(m&&(p!==Y.draftName||C!==Y.draftScope)||g!==Y.description||A!==Y.mode||k!==Y.model||N!==Y.temperature||x!==Y.topP||z!==Y.prompt||D!==Y.globalPermission||!_u(M,Y.permissionRules)):!1},[g,p,C,D,m,A,k,M,z,N,x]),Me=async()=>{const Y=m?p.trim().replace(/\s+/g,"-"):n?.trim();if(!Y){B.error(s("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(ue=>ue.name===Y)){B.error(s("settings.agents.sidebar.toast.agentExists"));return}Q(!0);try{const ue=k.trim(),Ne=z.trim(),Ae=qu(D,M),Re={name:Y,description:g.trim()||void 0,mode:A,model:ue===""?null:ue,temperature:N,top_p:x,prompt:Ne||(m?void 0:null),permission:Ae,scope:m?C:void 0};let Fe;m?(Fe=await r(Re),Fe&&c(null)):Fe=await i(Y,Re),Fe?B.success(s(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):B.error(s(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(ue){console.error("Error saving agent:",ue);const Ne=ue instanceof Error&&ue.message?ue.message:s("settings.agents.page.toast.saveUnexpectedError");B.error(Ne)}finally{Q(!1)}};return n?t.jsx(Jt,{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:m?s("settings.agents.page.title.new"):n}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(m?"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:[m&&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:p,onChange:Y=>u(Y.target.value),placeholder:s("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Ft,{value:C,onValueChange:Y=>f(Y),children:[t.jsx(Lt,{className:"w-fit min-w-[100px]",children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Ot,{align:"end",children:[t.jsx(ft,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ft,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{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(ps,{value:g,onChange:Y=>b(Y.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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(T,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{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(q,{variant:"chip",size:"xs","aria-pressed":A==="primary",onClick:()=>S("primary"),className:"!font-normal",children:s("settings.agents.page.mode.primary")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":A==="subagent",onClick:()=>S("subagent"),className:"!font-normal",children:s("settings.agents.page.mode.subagent")}),t.jsx(q,{variant:"chip",size:"xs","aria-pressed":A==="all",onClick:()=>S("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(_r,{providerId:En(k)?.providerId??"",modelId:En(k)?.modelId??"",onChange:(Y,ue)=>{E(Y&&ue?`${Y}/${ue}`:"")}})})]}),t.jsxs("div",{"data-settings-item":"agents.temperature",className:de("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:de("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(T,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{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:de("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(xs,{value:N,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),N!==void 0&&t.jsx(q,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(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(T,{name:"close",className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{"data-settings-item":"agents.top-p",className:de("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[t.jsxs("div",{className:de("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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(T,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{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:de("flex items-center gap-2",e?"w-full":"w-fit"),children:[t.jsx(xs,{value:x,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),x!==void 0&&t.jsx(q,{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(T,{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(ps,{value:z,onChange:Y=>R(Y.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(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>w(Y=>!Y),children:s(G?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),G?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(Ft,{value:D,onValueChange:Y=>Ee(Y),children:[t.jsx(Lt,{className:"w-[100px]",children:t.jsx(Kt,{children:ee(D)})}),t.jsxs(Ot,{children:[t.jsx(ft,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ft,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ft,{value:"deny",children:s("settings.common.permission.deny")})]})]})]}),t.jsx("div",{className:"space-y-4",children:he.filter(Y=>Y!=="*").map(Y=>{const ue=Ie(Y),{defaultAction:Ne,patternRulesCount:Ae}=ye(Y),Re=De(Y),Fe=Re??"global",ne=xe(Y),Se=["allow","ask","deny"].filter(Pe=>Pe!==D);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:ue}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:Y})]}),t.jsx("div",{className:"typography-micro text-muted-foreground",children:Ae>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:"*"}),Re&&t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>te(Y,"*"),className:"px-1.5 py-0 h-5",children:t.jsx(T,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Ft,{value:Fe,onValueChange:Pe=>{if(Pe==="global"){X(Y,"*");return}K(Y,"*",Pe)},children:[t.jsx(Lt,{className:"w-[90px]",children:t.jsx(Kt,{children:re(Fe)})}),t.jsxs(Ot,{children:[t.jsx(ft,{value:"global",children:s("settings.common.scope.global")}),Se.map(Pe=>t.jsx(ft,{value:Pe,className:"capitalize",children:ee(Pe)},Pe))]})]})]}),ne.map(Pe=>{const $e=cn(Pe.permission,Pe.pattern),Be=je.get($e),Le=!Be,tt=!!(Be&&Be.action!==Pe.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:Pe.pattern}),Le&&t.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:s("settings.common.badge.new")}),tt&&t.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:s("settings.common.badge.modified")}),(Le||tt)&&t.jsx(q,{size:"sm",variant:"ghost",onClick:()=>Le?X(Pe.permission,Pe.pattern):te(Pe.permission,Pe.pattern),className:"px-1.5 py-0 h-5",children:t.jsx(T,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t.jsxs(Ft,{value:Pe.action,onValueChange:J=>me(Pe.permission,Pe.pattern,J),children:[t.jsx(Lt,{className:"w-[90px]",children:t.jsx(Kt,{children:ee(Pe.action)})}),t.jsxs(Ot,{children:[t.jsx(ft,{value:"allow",children:s("settings.common.permission.allow")}),t.jsx(ft,{value:"ask",children:s("settings.common.permission.ask")}),t.jsx(ft,{value:"deny",children:s("settings.common.permission.deny")})]})]})]},$e)})]})]},Y)})}),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(Ft,{value:_,onValueChange:Z,children:[t.jsx(Lt,{className:"w-full sm:w-[160px]",children:_?t.jsx("span",{className:"truncate",children:Ie(_)}):t.jsx("span",{className:"text-muted-foreground",children:s("settings.agents.page.permissions.permissionPlaceholder")})}),t.jsx(Ot,{children:pe.map(Y=>t.jsx(ft,{value:Y,children:t.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:t.jsx("span",{children:Ie(Y)})})},Y))})]}),t.jsx(ot,{value:W,onChange:Y=>F(Y.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(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>we("allow"),children:s("settings.common.permission.allow")}),t.jsx(q,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>we("ask"),children:s("settings.common.permission.ask")}),t.jsx(q,{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:he.map((Y,ue)=>{const{defaultAction:Ne,patternRulesCount:Ae,patternSummary:Re,hasDefaultHint:Fe}=ye(Y),ne=Ie(Y),Se=Fe?`${Ne} (env blocked)`:Ne;return t.jsxs("div",{className:de("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",ue>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:ne}),t.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:Y})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[Ae>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:Se})}):t.jsx("span",{className:de("typography-micro capitalize px-1.5 py-0.5 rounded",Se==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":Se==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:Se}),Ae>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:Re})})]})]},Y)})})]}),t.jsx("div",{className:"px-2 py-1",children:t.jsx(q,{onClick:Me,disabled:U||!Te,size:"xs",className:"!font-normal",children:s(U?"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(T,{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")})]})})},Ju="~/.config/opencode/AGENTS.md",Al=async(s,e)=>{const n=await s.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},Qu=s=>s.length>0&&!s.endsWith(`
2
2
  `)?`${s}
3
3
  `:s,da={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Yu=(s,e)=>s==="custom"?e:kd(s),Xu=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 jt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(s)});if(!n.ok)throw new Error(await Al(n,e))},Zu=()=>{const{t:s}=mt(),[e,n]=l.useState(""),[a,r]=l.useState(da.responseStyleEnabled),[i,o]=l.useState(da.responseStylePreset),[d,c]=l.useState(da.responseStyleCustomInstructions),[h,m]=l.useState(!0),[p,u]=l.useState(!1),[C,f]=l.useState(""),g=l.useRef(null);l.useEffect(()=>{const k=new AbortController;return(async()=>{try{const[N,j]=await Promise.all([jt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:k.signal}),jt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:k.signal})]);let x=da;if(N.ok){const I=await N.json();x={...x,responseStyleEnabled:I.responseStyleEnabled===!0,responseStylePreset:Xu(I.responseStylePreset),responseStyleCustomInstructions:typeof I.responseStyleCustomInstructions=="string"?I.responseStyleCustomInstructions:""},typeof I.globalBehaviorPrompt=="string"&&(x={...x,prompt:I.globalBehaviorPrompt})}if(!x.prompt.trim()&&j.ok){const I=await j.json();typeof I.content=="string"&&(x={...x,prompt:I.content})}n(x.prompt),r(x.responseStyleEnabled),o(x.responseStylePreset),c(x.responseStyleCustomInstructions),f(x.prompt),g.current={enabled:x.responseStyleEnabled,preset:x.responseStylePreset,custom:x.responseStyleCustomInstructions}}catch(N){N.name!=="AbortError"&&console.warn("Failed to load behavior settings:",N)}finally{m(!1)}})(),()=>k.abort()},[]),l.useEffect(()=>{if(h)return;const k=g.current;if(k&&k.enabled===a&&k.preset===i&&k.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(j){const x=j instanceof Error?j.message:s("settings.behavior.page.toast.saveFailed");B.error(x)}},400);return()=>clearTimeout(N)},[a,i,d,h,s]);const b=Yu(i,d),A=e!==C,S=async()=>{u(!0);try{const k=Qu(e),E=await jt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:k})});if(!E.ok)throw new Error(await Al(E,s("settings.behavior.page.toast.saveFailed")));await Gi({globalBehaviorPrompt:k},s("settings.behavior.page.toast.saveFailed")),n(k),f(k),B.success(s("settings.behavior.page.toast.saved"))}catch(k){console.error("Failed to save behavior:",k);const E=k instanceof Error?k.message:s("settings.behavior.page.toast.saveFailed");B.error(E)}finally{u(!1)}};return t.jsx(Jt,{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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(T,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{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:Ju})})]})})]})]})}),t.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[t.jsx(ps,{value:e,onChange:k=>n(k.target.value),placeholder:s("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:h,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),t.jsx(q,{onClick:S,disabled:p||!A||h,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(It,{children:[t.jsx(Dt,{asChild:!0,children:t.jsx(T,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t.jsx(Et,{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(Pt,{checked:a,onChange:r,disabled:h,ariaLabel:s("settings.behavior.page.responseStyle.enableAria")}),s("settings.behavior.page.responseStyle.enable")]}),t.jsxs(Ft,{value:i,onValueChange:k=>o(k),disabled:h||!a,children:[t.jsx(Lt,{className:"w-full sm:w-56",size:"lg",children:t.jsx(Kt,{children:k=>k==="custom"?s("settings.behavior.page.responseStyle.option.custom"):hl(k)?s(qi[k]):null})}),t.jsxs(Ot,{children:[Nd.map(k=>t.jsx(ft,{value:k,children:s(qi[k])},k)),t.jsx(ft,{value:"custom",children:s("settings.behavior.page.responseStyle.option.custom")})]})]}),t.jsx(ps,{value:b,onChange:k=>c(k.target.value),placeholder:s("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:h||!a||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},ep=s=>{const e=rt.c(169),{onItemSelect:n}=s,{t:a}=mt(),[r,i]=l.useState(null),[o,d]=l.useState(""),[c,h]=l.useState(null),[m,p]=l.useState(null),[u,C]=l.useState(!1),[f,g]=l.useState(null),{selectedCommandName:b,commands:A,setSelectedCommand:S,setCommandDraft:k,createCommand:E,deleteCommand:N,loadCommands:j}=Ka(Ss(tp)),x=Vs(sp),I=Vs(np);let z,R;e[0]!==j||e[1]!==I?(z=()=>{j(),I()},R=[j,I],e[0]=j,e[1]=I,e[2]=z,e[3]=R):(z=e[2],R=e[3]),l.useEffect(z,R);let D;e[4]!==x?(D=new Set(x.map(ap)),e[4]=x,e[5]=D):D=e[5];const v=D;let y;if(e[6]!==A||e[7]!==v){let be;e[9]!==v?(be=st=>!v.has(st.name),e[9]=v,e[10]=be):be=e[10],y=A.filter(be),e[6]=A,e[7]=v,e[8]=y}else y=e[8];const L=y;let M,H;e[11]!==b||e[12]!==S||e[13]!==v?(M=()=>{b&&v.has(b)&&S(null)},H=[b,S,v],e[11]=b,e[12]=S,e[13]=v,e[14]=M,e[15]=H):(M=e[14],H=e[15]),l.useEffect(M,H);let _;e[16]!==A||e[17]!==n||e[18]!==k||e[19]!==S?(_=()=>{let be="new-command",st=1;for(;A.some(at=>at.name===be);)be=`new-command-${st}`,st++;k({name:be,scope:"user"}),S(be),n?.()},e[16]=A,e[17]=n,e[18]=k,e[19]=S,e[20]=_):_=e[20];const Z=_;let W;e[21]!==a?(W=async be=>{if(In(be)){B.error(a("settings.commands.sidebar.toast.builtInCannotDelete"));return}h(be),p("delete")},e[21]=a,e[22]=W):W=e[22];const F=W;let G;e[23]===Symbol.for("react.memo_cache_sentinel")?(G=async be=>{In(be)&&(h(be),p("reset"))},e[23]=G):G=e[23];const w=G;let U;e[24]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{h(null),p(null)},e[24]=U):U=e[24];const Q=U;let ie;e[25]!==c||e[26]!==m||e[27]!==N||e[28]!==a?(ie=async()=>{if(!c||!m)return;C(!0),await N(c.name)?(m==="delete"?B.success(a("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):B.success(a("settings.commands.sidebar.toast.commandReset",{name:c.name})),Q()):m==="delete"?B.error(a("settings.commands.sidebar.toast.deleteFailed")):B.error(a("settings.commands.sidebar.toast.resetFailed")),C(!1)},e[25]=c,e[26]=m,e[27]=N,e[28]=a,e[29]=ie):ie=e[29];const ce=ie;let se;e[30]!==A||e[31]!==k||e[32]!==S?(se=be=>{const st=be.name;let at=1,Je=`${st}-copy`;for(;A.some(xt=>xt.name===Je);)at++,Je=`${st}-copy-${at}`;k({name:Je,scope:be.scope||"user",description:be.description,template:be.template,agent:be.agent,model:be.model}),S(Je)},e[30]=A,e[31]=k,e[32]=S,e[33]=se):se=e[33];const le=se;let oe;e[34]===Symbol.for("react.memo_cache_sentinel")?(oe=be=>{d(be.name),i(be)},e[34]=oe):oe=e[34];const fe=oe;let je;e[35]!==A||e[36]!==E||e[37]!==N||e[38]!==r||e[39]!==o||e[40]!==S||e[41]!==a?(je=async()=>{if(!r)return;const be=o.trim().replace(/\s+/g,"-");if(!be){B.error(a("settings.commands.sidebar.toast.commandNameRequired"));return}if(be===r.name){i(null);return}if(A.some(at=>at.name===be)){B.error(a("settings.commands.sidebar.toast.commandExists"));return}await E({name:be,description:r.description,template:r.template,agent:r.agent,model:r.model})?await N(r.name)?(B.success(`Command renamed to "${be}"`),S(be)):B.error(a("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):B.error(a("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=A,e[36]=E,e[37]=N,e[38]=r,e[39]=o,e[40]=S,e[41]=a,e[42]=je):je=e[42];const ge=je;let De,xe,he,ye,ee,re;if(e[43]!==L||e[44]!==Z||e[45]!==F||e[46]!==le||e[47]!==n||e[48]!==f||e[49]!==b||e[50]!==S||e[51]!==a){const be=L.filter(In),st=L.filter(rp);e[58]===Symbol.for("react.memo_cache_sentinel")?(ee=de("flex h-full flex-col","bg-background"),e[58]=ee):ee=e[58];let at;e[59]!==a?(at=a("settings.commands.sidebar.title"),e[59]=a,e[60]=at):at=e[60];let Je;e[61]!==at?(Je=t.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:at}),e[61]=at,e[62]=Je):Je=e[62];let xt;e[63]===Symbol.for("react.memo_cache_sentinel")?(xt=t.jsx(ta,{className:"mb-3"}),e[63]=xt):xt=e[63];let Nt;e[64]!==L.length||e[65]!==a?(Nt=a("settings.commands.sidebar.total",{count:L.length}),e[64]=L.length,e[65]=a,e[66]=Nt):Nt=e[66];let Rt;e[67]!==Nt?(Rt=t.jsx("span",{className:"typography-meta text-muted-foreground",children:Nt}),e[67]=Nt,e[68]=Rt):Rt=e[68];let ae;e[69]===Symbol.for("react.memo_cache_sentinel")?(ae=t.jsx(T,{name:"add",className:"h-3.5 w-3.5"}),e[69]=ae):ae=e[69];let _e;e[70]!==Z?(_e=t.jsx(q,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Z,children:ae}),e[70]=Z,e[71]=_e):_e=e[71];let Ze;e[72]!==Rt||e[73]!==_e?(Ze=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Rt,_e]}),e[72]=Rt,e[73]=_e,e[74]=Ze):Ze=e[74],e[75]!==Je||e[76]!==Ze?(re=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Je,xt,Ze]}),e[75]=Je,e[76]=Ze,e[77]=re):re=e[77],De=Jt,xe="flex-1 min-h-0",he="space-y-1 px-3 py-2",ye=L.length===0?t.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[t.jsx(T,{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:[be.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")}),[...be].sort(ip).map(Ge=>t.jsx(Ji,{command:Ge,isSelected:b===Ge.name,onSelect:()=>{S(Ge.name),n?.()},onReset:()=>w(Ge),onDuplicate:()=>le(Ge),isMenuOpen:f===Ge.name,onMenuOpenChange:bt=>g(bt?Ge.name:null)},Ge.name))]}),st.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")}),[...st].sort(op).map(Ge=>t.jsx(Ji,{command:Ge,isSelected:b===Ge.name,onSelect:()=>{S(Ge.name),n?.()},onRename:()=>fe(Ge),onDelete:()=>F(Ge),onDuplicate:()=>le(Ge),isMenuOpen:f===Ge.name,onMenuOpenChange:bt=>g(bt?Ge.name:null)},Ge.name))]})]}),e[43]=L,e[44]=Z,e[45]=F,e[46]=le,e[47]=n,e[48]=f,e[49]=b,e[50]=S,e[51]=a,e[52]=De,e[53]=xe,e[54]=he,e[55]=ye,e[56]=ee,e[57]=re}else De=e[52],xe=e[53],he=e[54],ye=e[55],ee=e[56],re=e[57];let pe;e[78]!==De||e[79]!==xe||e[80]!==he||e[81]!==ye?(pe=t.jsx(De,{outerClassName:xe,className:he,children:ye}),e[78]=De,e[79]=xe,e[80]=he,e[81]=ye,e[82]=pe):pe=e[82];const K=c!==null&&m!==null;let X;e[83]!==u?(X=be=>{!be&&!u&&Q()},e[83]=u,e[84]=X):X=e[84];let te;e[85]!==m||e[86]!==a?(te=a(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=a,e[87]=te):te=e[87];let me;e[88]!==te?(me=t.jsx(Vt,{children:te}),e[88]=te,e[89]=me):me=e[89];let Ee;e[90]!==c?.name||e[91]!==m||e[92]!==a?(Ee=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]=Ee):Ee=e[93];let we;e[94]!==Ee?(we=t.jsx(qt,{children:Ee}),e[94]=Ee,e[95]=we):we=e[95];let Ie;e[96]!==me||e[97]!==we?(Ie=t.jsxs(_t,{children:[me,we]}),e[96]=me,e[97]=we,e[98]=Ie):Ie=e[98];let Te;e[99]!==a?(Te=a("settings.common.actions.cancel"),e[99]=a,e[100]=Te):Te=e[100];let Me;e[101]!==u||e[102]!==Te?(Me=t.jsx(q,{size:"sm",variant:"ghost",onClick:Q,disabled:u,children:Te}),e[101]=u,e[102]=Te,e[103]=Me):Me=e[103];let Y;e[104]!==m||e[105]!==a?(Y=a(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=a,e[106]=Y):Y=e[106];let ue;e[107]!==ce||e[108]!==u||e[109]!==Y?(ue=t.jsx(q,{size:"sm",onClick:ce,disabled:u,children:Y}),e[107]=ce,e[108]=u,e[109]=Y,e[110]=ue):ue=e[110];let Ne;e[111]!==Me||e[112]!==ue?(Ne=t.jsxs(Yt,{children:[Me,ue]}),e[111]=Me,e[112]=ue,e[113]=Ne):Ne=e[113];let Ae;e[114]!==Ie||e[115]!==Ne?(Ae=t.jsxs(Bt,{className:"max-w-md",children:[Ie,Ne]}),e[114]=Ie,e[115]=Ne,e[116]=Ae):Ae=e[116];let Re;e[117]!==K||e[118]!==X||e[119]!==Ae?(Re=t.jsx(Ut,{open:K,onOpenChange:X,children:Ae}),e[117]=K,e[118]=X,e[119]=Ae,e[120]=Re):Re=e[120];const Fe=r!==null;let ne;e[121]===Symbol.for("react.memo_cache_sentinel")?(ne=be=>!be&&i(null),e[121]=ne):ne=e[121];let Se;e[122]!==a?(Se=a("settings.commands.sidebar.renameDialog.title"),e[122]=a,e[123]=Se):Se=e[123];let Pe;e[124]!==Se?(Pe=t.jsx(Vt,{children:Se}),e[124]=Se,e[125]=Pe):Pe=e[125];const $e=r?.name??"";let Be;e[126]!==a||e[127]!==$e?(Be=a("settings.commands.sidebar.renameDialog.description",{name:$e}),e[126]=a,e[127]=$e,e[128]=Be):Be=e[128];let Le;e[129]!==Be?(Le=t.jsx(qt,{children:Be}),e[129]=Be,e[130]=Le):Le=e[130];let tt;e[131]!==Pe||e[132]!==Le?(tt=t.jsxs(_t,{children:[Pe,Le]}),e[131]=Pe,e[132]=Le,e[133]=tt):tt=e[133];let J;e[134]===Symbol.for("react.memo_cache_sentinel")?(J=be=>d(be.target.value),e[134]=J):J=e[134];let V;e[135]!==a?(V=a("settings.commands.sidebar.renameDialog.placeholder"),e[135]=a,e[136]=V):V=e[136];let Ce;e[137]!==ge?(Ce=be=>{be.key==="Enter"&&ge()},e[137]=ge,e[138]=Ce):Ce=e[138];let O;e[139]!==o||e[140]!==V||e[141]!==Ce?(O=t.jsx(ot,{value:o,onChange:J,placeholder:V,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ce}),e[139]=o,e[140]=V,e[141]=Ce,e[142]=O):O=e[142];let Ke;e[143]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>i(null),e[143]=Ke):Ke=e[143];let Qe;e[144]!==a?(Qe=a("settings.common.actions.cancel"),e[144]=a,e[145]=Qe):Qe=e[145];let Ye;e[146]!==Qe?(Ye=t.jsx(q,{size:"sm",variant:"ghost",onClick:Ke,children:Qe}),e[146]=Qe,e[147]=Ye):Ye=e[147];let et;e[148]!==a?(et=a("settings.common.actions.rename"),e[148]=a,e[149]=et):et=e[149];let nt;e[150]!==ge||e[151]!==et?(nt=t.jsx(q,{size:"sm",onClick:ge,children:et}),e[150]=ge,e[151]=et,e[152]=nt):nt=e[152];let lt;e[153]!==Ye||e[154]!==nt?(lt=t.jsxs(Yt,{children:[Ye,nt]}),e[153]=Ye,e[154]=nt,e[155]=lt):lt=e[155];let Xe;e[156]!==tt||e[157]!==O||e[158]!==lt?(Xe=t.jsxs(Bt,{children:[tt,O,lt]}),e[156]=tt,e[157]=O,e[158]=lt,e[159]=Xe):Xe=e[159];let ze;e[160]!==Fe||e[161]!==Xe?(ze=t.jsx(Ut,{open:Fe,onOpenChange:ne,children:Xe}),e[160]=Fe,e[161]=Xe,e[162]=ze):ze=e[162];let ct;return e[163]!==ee||e[164]!==re||e[165]!==pe||e[166]!==Re||e[167]!==ze?(ct=t.jsxs("div",{className:ee,children:[re,pe,Re,ze]}),e[163]=ee,e[164]=re,e[165]=pe,e[166]=Re,e[167]=ze,e[168]=ct):ct=e[168],ct},Ji=s=>{const e=rt.c(47),{command:n,isSelected:a,onSelect:r,onDelete:i,onReset:o,onRename:d,onDuplicate:c,isMenuOpen:h,onMenuOpenChange:m}=s,{t:p}=mt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Qn(),e[0]=u):u=e[0];const C=u,[f,g]=l.useState(!1);let b;e[1]!==i||e[2]!==c||e[3]!==d||e[4]!==o||e[5]!==p?(b=W=>t.jsxs(t.Fragment,{children:[d&&t.jsxs(W,{onClick:F=>{F.stopPropagation(),d()},children:[t.jsx(T,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),t.jsxs(W,{onClick:F=>{F.stopPropagation(),c()},children:[t.jsx(T,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),o&&t.jsxs(W,{onClick:F=>{F.stopPropagation(),o()},children:[t.jsx(T,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),i&&t.jsxs(W,{onClick:F=>{F.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[t.jsx(T,{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]=b):b=e[6];const A=b,S=a?"bg-interactive-selection":"hover:bg-interactive-hover";let k;e[7]!==S?(k=de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",S),e[7]=S,e[8]=k):k=e[8];let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=C?void 0:W=>{W.preventDefault(),g(!0)},e[9]=E):E=e[9];let N;e[10]!==k?(N=t.jsx("div",{className:k,onContextMenu:E}),e[10]=k,e[11]=N):N=e[11];let j;e[12]!==n.name?(j=t.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[12]=n.name,e[13]=j):j=e[13];let x;e[14]!==n||e[15]!==p?(x=(n.scope||In(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:In(n)?p("settings.agents.sidebar.badge.system"):n.scope}),e[14]=n,e[15]=p,e[16]=x):x=e[16];let I;e[17]!==j||e[18]!==x?(I=t.jsxs("div",{className:"flex items-center gap-2",children:[j,x]}),e[17]=j,e[18]=x,e[19]=I):I=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 R;e[22]!==r||e[23]!==z||e[24]!==I?(R=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,z]}),e[22]=r,e[23]=z,e[24]=I,e[25]=R):R=e[25];let D;e[26]!==m?(D=W=>{W&&g(!1),m(W)},e[26]=m,e[27]=D):D=e[27];let v;e[28]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(ds,{asChild:!0,children:t.jsx(q,{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(T,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=v):v=e[28];let y;e[29]!==A?(y=t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:A(ws)}),e[29]=A,e[30]=y):y=e[30];let L;e[31]!==h||e[32]!==D||e[33]!==y?(L=t.jsxs(us,{open:h,onOpenChange:D,children:[v,y]}),e[31]=h,e[32]=D,e[33]=y,e[34]=L):L=e[34];let M;e[35]!==R||e[36]!==L?(M=t.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[R,L]}),e[35]=R,e[36]=L,e[37]=M):M=e[37];let H;e[38]!==M||e[39]!==N?(H=t.jsx(tn,{render:N,children:M}),e[38]=M,e[39]=N,e[40]=H):H=e[40];let _;e[41]!==A?(_=t.jsx(sn,{className:"w-fit min-w-20",children:A(Hs)}),e[41]=A,e[42]=_):_=e[42];let Z;return e[43]!==f||e[44]!==H||e[45]!==_?(Z=t.jsxs(en,{open:f,onOpenChange:g,children:[H,_]}),e[43]=f,e[44]=H,e[45]=_,e[46]=Z):Z=e[46],Z};function tp(s){return{selectedCommandName:s.selectedCommandName,commands:s.commands,setSelectedCommand:s.setSelectedCommand,setCommandDraft:s.setCommandDraft,createCommand:s.createCommand,deleteCommand:s.deleteCommand,loadCommands:s.loadCommands}}function sp(s){return s.skills}function np(s){return s.loadSkills}function ap(s){return s.name}function rp(s){return!In(s)}function ip(s,e){return s.name.localeCompare(e.name)}function op(s,e){return s.name.localeCompare(e.name)}const lp=()=>{const{t:s}=mt(),{selectedCommandName:e,getCommandByName:n,createCommand:a,updateCommand:r,commands:i,commandDraft:o,setCommandDraft:d}=Ka(Ss(D=>({selectedCommandName:D.selectedCommandName,getCommandByName:D.getCommandByName,createCommand:D.createCommand,updateCommand:D.updateCommand,commands:D.commands,commandDraft:D.commandDraft,setCommandDraft:D.setCommandDraft}))),c=e?n(e):null,h=!!(o&&o.name===e&&!c),[m,p]=l.useState(""),[u,C]=l.useState("user"),[f,g]=l.useState(""),[b,A]=l.useState(""),[S,k]=l.useState(""),[E,N]=l.useState(""),[j,x]=l.useState(!1),I=l.useRef(null);l.useEffect(()=>{if(h&&o){const D=o.name||"",v=o.scope||"user",y=o.description||"",L=o.agent||"",M=o.model||"",H=o.template||"";p(D),C(v),g(y),A(L),k(M),N(H),I.current={draftName:D,draftScope:v,description:y,agent:L,model:M,template:H}}else if(c){const D=c.description||"",v=c.agent||"",y=c.model||"",L=c.template||"";g(D),A(v),k(y),N(L),I.current={draftName:"",draftScope:"user",description:D,agent:v,model:y,template:L}}},[c,h,e,i,o]);const z=l.useMemo(()=>{const D=I.current;return D?!!(h&&(m!==D.draftName||u!==D.draftScope)||f!==D.description||b!==D.agent||S!==D.model||E!==D.template):!1},[b,f,m,u,h,S,E]),R=async()=>{const D=h?m.trim().replace(/\s+/g,"-"):e?.trim();if(!D){B.error(s("settings.commands.sidebar.toast.commandNameRequired"));return}if(!E.trim()){B.error(s("settings.commands.page.toast.templateRequired"));return}if(h&&i.some(v=>v.name===D)){B.error(s("settings.commands.sidebar.toast.commandExists"));return}x(!0);try{const v=b.trim(),y=S.trim(),L=E.trim(),M={name:D,description:f.trim()||void 0,agent:v===""?null:v,model:y===""?null:y,template:L,scope:h?u:void 0};let H;h?(H=await a(M),H&&d(null)):H=await r(D,M),H?B.success(s(h?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):B.error(s(h?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(v){console.error("Error saving command:",v),B.error(s("settings.commands.page.toast.saveUnexpectedError"))}finally{x(!1)}};return e?t.jsx(Jt,{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:h?s("settings.commands.page.title.new"):`/${e}`}),t.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s(h?"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:[h&&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:D=>p(D.target.value),placeholder:s("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),t.jsxs(Ft,{value:u,onValueChange:D=>C(D),children:[t.jsx(Lt,{className:"w-fit min-w-[100px]",children:t.jsx(Kt,{placeholder:s("settings.agents.page.field.scopePlaceholder")})}),t.jsxs(Ot,{align:"end",children:[t.jsx(ft,{value:"user",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{name:"user-3",className:"h-3.5 w-3.5"}),t.jsx("span",{children:s("settings.common.scope.global")})]})}),t.jsx(ft,{value:"project",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{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(ps,{value:f,onChange:D=>g(D.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:b,onChange:D=>A(D)})})]}),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(_r,{providerId:En(S)?.providerId??"",modelId:En(S)?.modelId??"",onChange:(D,v)=>{k(D&&v?`${D}/${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(ps,{value:E,onChange:D=>N(D.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(q,{onClick:R,disabled:j||!z,size:"xs",className:"!font-normal",children:s(j?"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(T,{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=de("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},cp=s=>{const e=rt.c(120),{onItemSelect:n}=s,{t:a}=mt(),{mcpServers:r,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:d,loadMcpConfigs:c,deleteMcp:h}=Mn(Ss(dp)),m=vs(mp);let p;e[0]!==m?(p=Le=>Le.getStatusForDirectory(m??null),e[0]=m,e[1]=p):p=e[1];const u=is(p),C=is(up),f=is(pp),[g,b]=l.useState(null),[A,S]=l.useState(!1),[k,E]=l.useState(null),[N,j]=l.useState(null),[x,I]=l.useState(!1);let z;e[2]!==r?(z=r.filter(gp),e[2]=r,e[3]=z):z=e[3];const R=z;let D;e[4]!==r?(D=r.filter(hp),e[4]=r,e[5]=D):D=e[5];const v=D;let y,L;e[6]!==c?(y=()=>{c()},L=[c],e[6]=c,e[7]=y,e[8]=L):(y=e[7],L=e[8]),l.useEffect(y,L);let M;e[9]!==m||e[10]!==f||e[11]!==x||e[12]!==C?(M=()=>{if(x)return;I(!0);const Le=new Promise(fp);Promise.all([C({directory:m,silent:!0}),Le]).then(()=>{const tt=f(m);tt&&B.error(tt)}).finally(()=>{I(!1)})},e[9]=m,e[10]=f,e[11]=x,e[12]=C,e[13]=M):M=e[13];const H=M;let _;e[14]!==r||e[15]!==n||e[16]!==d||e[17]!==o?(_=()=>{let Le="new-mcp-server",tt=1;for(;r.some(V=>V.name===Le);)Le=`new-mcp-server-${tt}`,tt++;d({name:Le,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(Le),n?.()},e[14]=r,e[15]=n,e[16]=d,e[17]=o,e[18]=_):_=e[18];const Z=_;let W;e[19]!==h||e[20]!==g||e[21]!==a?(W=async()=>{if(!g)return;S(!0);const Le=await h(g.name);Le.ok?Le.reloadFailed?B.warning(Le.message||`MCP server "${g.name}" deleted, but OpenCode reload failed`,{description:Le.warning||a("settings.mcp.sidebar.toast.refreshListIfStale")}):B.success(Le.message||a("settings.mcp.sidebar.toast.serverDeleted",{name:g.name})):B.error(a("settings.mcp.sidebar.toast.deleteFailed")),b(null),S(!1)},e[19]=h,e[20]=g,e[21]=a,e[22]=W):W=e[22];const F=W;let G;e[23]!==a?(G=(Le,tt)=>t.jsxs(tt,{onClick:J=>{J.stopPropagation(),b(Le)},className:"text-destructive focus:text-destructive",children:[t.jsx(T,{name:"delete-bin",className:"h-4 w-4 mr-px"}),a("settings.common.actions.delete")]}),e[23]=a,e[24]=G):G=e[24];const w=G;let U;e[25]===Symbol.for("react.memo_cache_sentinel")?(U=de("flex h-full flex-col","bg-background"),e[25]=U):U=e[25];let Q;e[26]!==a?(Q=a("settings.mcp.sidebar.title"),e[26]=a,e[27]=Q):Q=e[27];let ie;e[28]!==Q?(ie=t.jsx("h2",{className:"text-base font-semibold text-foreground",children:Q}),e[28]=Q,e[29]=ie):ie=e[29];let ce;e[30]!==a?(ce=a("settings.mcp.sidebar.actions.refreshStatusAria"),e[30]=a,e[31]=ce):ce=e[31];let se;e[32]!==a?(se=a("settings.mcp.sidebar.actions.refreshStatusTitle"),e[32]=a,e[33]=se):se=e[33];const le=x&&"animate-spin";let oe;e[34]!==le?(oe=de("h-4 w-4",le),e[34]=le,e[35]=oe):oe=e[35];let fe;e[36]!==oe?(fe=t.jsx(T,{name:"refresh",className:oe}),e[36]=oe,e[37]=fe):fe=e[37];let je;e[38]!==H||e[39]!==x||e[40]!==ce||e[41]!==se||e[42]!==fe?(je=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:x,onClick:H,"aria-label":ce,title:se,children:fe}),e[38]=H,e[39]=x,e[40]=ce,e[41]=se,e[42]=fe,e[43]=je):je=e[43];let ge;e[44]!==ie||e[45]!==je?(ge=t.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[ie,je]}),e[44]=ie,e[45]=je,e[46]=ge):ge=e[46];let De;e[47]===Symbol.for("react.memo_cache_sentinel")?(De=t.jsx(ta,{className:"mb-3"}),e[47]=De):De=e[47];let xe;e[48]!==r.length||e[49]!==a?(xe=a("settings.mcp.sidebar.total",{count:r.length}),e[48]=r.length,e[49]=a,e[50]=xe):xe=e[50];let he;e[51]!==xe?(he=t.jsx("span",{className:"typography-meta text-muted-foreground",children:xe}),e[51]=xe,e[52]=he):he=e[52];let ye;e[53]!==a?(ye=a("settings.mcp.sidebar.actions.addServerTitle"),e[53]=a,e[54]=ye):ye=e[54];let ee;e[55]===Symbol.for("react.memo_cache_sentinel")?(ee=t.jsx(T,{name:"add",className:"h-3.5 w-3.5"}),e[55]=ee):ee=e[55];let re;e[56]!==Z||e[57]!==ye?(re=t.jsx(q,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Z,title:ye,children:ee}),e[56]=Z,e[57]=ye,e[58]=re):re=e[58];let pe;e[59]!==he||e[60]!==re?(pe=t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[he,re]}),e[59]=he,e[60]=re,e[61]=pe):pe=e[61];let K;e[62]!==ge||e[63]!==pe?(K=t.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ge,De,pe]}),e[62]=ge,e[63]=pe,e[64]=K):K=e[64];let X;e[65]!==r.length||e[66]!==u||e[67]!==n||e[68]!==k||e[69]!==R||e[70]!==w||e[71]!==N||e[72]!==i||e[73]!==d||e[74]!==o||e[75]!==a||e[76]!==v?(X=t.jsx(Jt,{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(T,{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:[R.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")}),R.map(Le=>{const tt=u[Le.name],J=Qi(tt?.status),V=i===Le.name,Ce=Qn();return t.jsxs(en,{open:N===Le.name,onOpenChange:O=>j(O?Le.name:null),children:[t.jsxs(tn,{render:t.jsx("div",{className:de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",V?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ce?void 0:O=>{O.preventDefault(),j(Le.name)}}),children:[t.jsxs("button",{onClick:()=>{o(Le.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:J,enabled:Le.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Le.name}),t.jsx("span",{title:Le.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Le.type==="local"?t.jsx(T,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(T,{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:Le.type==="local"?Le.command?.join(" ")??"":Le.url??""})]}),t.jsxs(us,{open:k===Le.name,onOpenChange:O=>{O&&j(null),E(O?Le.name:null)},children:[t.jsx(ds,{asChild:!0,children:t.jsx(q,{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(T,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:w(Le,ws)})]})]}),t.jsx(sn,{className:"w-fit min-w-20",children:w(Le,Hs)})]},Le.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(Le=>{const tt=u[Le.name],J=Qi(tt?.status),V=i===Le.name,Ce=Qn();return t.jsxs(en,{open:N===Le.name,onOpenChange:O=>j(O?Le.name:null),children:[t.jsxs(tn,{render:t.jsx("div",{className:de("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",V?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ce?void 0:O=>{O.preventDefault(),j(Le.name)}}),children:[t.jsxs("button",{onClick:()=>{o(Le.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:J,enabled:Le.enabled}),t.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:Le.name}),t.jsx("span",{title:Le.type==="local"?a("settings.mcp.sidebar.serverType.localTitle"):a("settings.mcp.sidebar.serverType.remoteTitle"),children:Le.type==="local"?t.jsx(T,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):t.jsx(T,{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:Le.type==="local"?Le.command?.join(" ")??"":Le.url??""})]}),t.jsxs(us,{open:k===Le.name,onOpenChange:O=>{O&&j(null),E(O?Le.name:null)},children:[t.jsx(ds,{asChild:!0,children:t.jsx(q,{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(T,{name:"more-2",className:"h-3.5 w-3.5"})})}),t.jsx(ms,{align:"end",className:"w-fit min-w-20",children:w(Le,ws)})]})]}),t.jsx(sn,{className:"w-fit min-w-20",children:w(Le,Hs)})]},Le.name)})]})]})}),e[65]=r.length,e[66]=u,e[67]=n,e[68]=k,e[69]=R,e[70]=w,e[71]=N,e[72]=i,e[73]=d,e[74]=o,e[75]=a,e[76]=v,e[77]=X):X=e[77];const te=g!==null;let me;e[78]!==A?(me=Le=>{!Le&&!A&&b(null)},e[78]=A,e[79]=me):me=e[79];let Ee;e[80]!==a?(Ee=a("settings.mcp.sidebar.deleteDialog.title"),e[80]=a,e[81]=Ee):Ee=e[81];let we;e[82]!==Ee?(we=t.jsx(Vt,{children:Ee}),e[82]=Ee,e[83]=we):we=e[83];const Ie=g?.name||"";let Te;e[84]!==a||e[85]!==Ie?(Te=a("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Ie}),e[84]=a,e[85]=Ie,e[86]=Te):Te=e[86];let Me;e[87]===Symbol.for("react.memo_cache_sentinel")?(Me=t.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[87]=Me):Me=e[87];let Y;e[88]!==Te?(Y=t.jsxs(qt,{children:[Te," ",Me,"."]}),e[88]=Te,e[89]=Y):Y=e[89];let ue;e[90]!==we||e[91]!==Y?(ue=t.jsxs(_t,{children:[we,Y]}),e[90]=we,e[91]=Y,e[92]=ue):ue=e[92];let Ne;e[93]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>b(null),e[93]=Ne):Ne=e[93];let Ae;e[94]!==a?(Ae=a("settings.common.actions.cancel"),e[94]=a,e[95]=Ae):Ae=e[95];let Re;e[96]!==A||e[97]!==Ae?(Re=t.jsx(q,{size:"sm",variant:"ghost",onClick:Ne,disabled:A,children:Ae}),e[96]=A,e[97]=Ae,e[98]=Re):Re=e[98];let Fe;e[99]!==A||e[100]!==a?(Fe=a(A?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[99]=A,e[100]=a,e[101]=Fe):Fe=e[101];let ne;e[102]!==F||e[103]!==A||e[104]!==Fe?(ne=t.jsx(q,{size:"sm",onClick:F,disabled:A,children:Fe}),e[102]=F,e[103]=A,e[104]=Fe,e[105]=ne):ne=e[105];let Se;e[106]!==Re||e[107]!==ne?(Se=t.jsxs(Yt,{children:[Re,ne]}),e[106]=Re,e[107]=ne,e[108]=Se):Se=e[108];let Pe;e[109]!==ue||e[110]!==Se?(Pe=t.jsxs(Bt,{className:"max-w-md",children:[ue,Se]}),e[109]=ue,e[110]=Se,e[111]=Pe):Pe=e[111];let $e;e[112]!==te||e[113]!==me||e[114]!==Pe?($e=t.jsx(Ut,{open:te,onOpenChange:me,children:Pe}),e[112]=te,e[113]=me,e[114]=Pe,e[115]=$e):$e=e[115];let Be;return e[116]!==K||e[117]!==X||e[118]!==$e?(Be=t.jsxs("div",{className:U,children:[K,X,$e]}),e[116]=K,e[117]=X,e[118]=$e,e[119]=Be):Be=e[119],Be};function dp(s){return{mcpServers:s.mcpServers,selectedMcpName:s.selectedMcpName,setSelectedMcp:s.setSelectedMcp,setMcpDraft:s.setMcpDraft,loadMcpConfigs:s.loadMcpConfigs,deleteMcp:s.deleteMcp}}function mp(s){return s.currentDirectory}function up(s){return s.refresh}function pp(s){return s.getErrorForDirectory}function gp(s){return s.scope==="project"}function hp(s){return s.scope!=="project"}function fp(s){return setTimeout(s,500)}function Ts(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function Kn(s){return Array.isArray(s)&&s.every(e=>typeof e=="string")}function Ms(s,e){return e!==void 0?{ok:!1,error:s,parsed:e}:{ok:!1,error:s}}function ma(s,e,n){const a=xp(n),r=typeof n.url=="string"?n.url.trim():"",i=Xi(n,"env","environment"),o=Xi(n,"headers"),d=bp(n),c=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",h=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=yp(n),C=vp(n);return{ok:!0,name:s,type:e,command:a,url:r,environment:i,headers:o,oauthEnabled:d,oauthClientId:c,oauthClientSecret:h,oauthScope:m,oauthRedirectUri:p,timeout:u,enabled:C}}function xp(s){const e=s.command,n=s.args;if(Kn(e)&&Kn(n))return[...e,...n];if(Kn(e))return e;if(typeof e=="string"&&e.trim()){const a=e.trim().split(/\s+/);return Kn(n)?[...a,...n]:a}return Kn(n)?n:[]}function Xi(s,...e){for(const n of e){const a=s[n];if(!Ts(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 bp(s){if(s.oauth===!1||s.oauth===null||s.oauth===void 0||!Ts(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 yp(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 vp(s){return"disabled"in s&&s.disabled===!0?!1:"enabled"in s?!!s.enabled:!0}function jp(s){const e=s.mcpServers;if(Ts(e)){const a=Object.keys(e);if(a.length===1){const r=a[0],i=e[r];if(Ts(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"&&Ts(r)});if(n.length===1){const a=n[0],r=s[a];if(El(r))return{name:a,entry:r}}return null}function El(s){return s.type==="local"||s.type==="remote"||Array.isArray(s.command)||typeof s.url=="string"||Array.isArray(s.args)}function wp(s,e){let n;try{const d=s.trim();if(!d)return Ms("No JSON content provided");n=JSON.parse(d)}catch(d){return Ms(d instanceof Error?`Invalid JSON: ${d.message}`:"Invalid JSON")}if(!Ts(n))return Ms("Expected a JSON object, not an array or primitive");const a=n,r=a.mcpServers;if(Ts(r)){const d=Object.keys(r);if(d.length===0)return Ms("mcpServers object is empty",n);if(d.length>1)return Ms("Paste one server at a time. Found "+d.length+" servers in mcpServers",n);const c=d[0],h=r[c];return Ts(h)?ma(c,ua(h),h):Ms("Server entry is not a valid object",n)}const i=a.mcp;if(Ts(i)){const d=Object.keys(i);if(d.length===0)return Ms("mcp object is empty",n);if(d.length>1)return Ms("Paste one server at a time. Found "+d.length+" servers in mcp",n);const c=d[0],h=i[c];return Ts(h)?ma(c,ua(h),h):Ms("Server entry in mcp is not a valid object",n)}const o=jp(a);if(o)return ma(o.name,ua(o.entry),o.entry);if(El(a)){const d=ua(a),c=typeof a.name=="string"&&a.name.trim()?a.name.trim():e?.fallbackName;return ma(c,d,a)}return Ms("No recognizable MCP server configuration found in JSON",n)}function ua(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 Np(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 kp="/mcp/oauth/callback",Sp=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}},Cp=s=>{const e=Pp(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}},Ml=s=>{const e=s.get("state");return typeof e!="string"?null:e.trim()||null},Pp=s=>{if(typeof s!="string"||!s.trim())return null;const e=Sp(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=Sc,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=de("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 h;return e[10]!==i||e[11]!==d||e[12]!==c?(h=t.jsx(kc,{className:c,...i,...d}),e[10]=i,e[11]=d,e[12]=c,e[13]=h):h=e[13],h},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=de("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(Cc,{className:r,...a}),e[5]=a,e[6]=r,e[7]=i):i=e[7],i};function Ip(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 Dp(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:Cp(n.searchParams),stateKey:Ml(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Ap=({value:s,onChange:e,pasteCommandTitle:n,pasteCommandLabel:a,pasteSuccess:r,clipboardReadFailed:i,preview:o})=>{const[d,c]=l.useState(()=>s.join(`
4
4
  `)),h=l.useRef(s);l.useEffect(()=>{JSON.stringify(h.current)!==JSON.stringify(s)&&(h.current=s,c(s.join(`