@openchamber/web 1.19.0 → 1.21.0

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 (182) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-DAvopJvy.js → CodeMirrorCommentWidgets-C2BopIs3.js} +1 -1
  2. package/dist/assets/CommitSection-HJeMUAWb.js +1 -0
  3. package/dist/assets/DiffView-D5cvbEPb.js +4 -0
  4. package/dist/assets/FilesView-DPU8aNPL.js +17 -0
  5. package/dist/assets/GitView-Ct6xWrVH.js +6 -0
  6. package/dist/assets/{JsonTreeView-h4dHASlq.js → JsonTreeView-osju7J70.js} +1 -1
  7. package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +1 -0
  8. package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +12 -0
  9. package/dist/assets/OnboardingScreen-w2VG4fWY.js +1 -0
  10. package/dist/assets/{PatchDiff-jPKTJje5.js → PatchDiff-Dan3mADn.js} +1 -1
  11. package/dist/assets/PierreDiffViewer-CGoI2v0q.js +157 -0
  12. package/dist/assets/PlanView-Dgg-WTEc.js +4 -0
  13. package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +1 -0
  14. package/dist/assets/SettingsView-D9yRuFZw.js +28 -0
  15. package/dist/assets/SettingsWindow-DXF-MTHG.js +1 -0
  16. package/dist/assets/ToolOutputDialog-DrCa1JRk.js +15 -0
  17. package/dist/assets/ToolPartDiffPreview-B_tfvlNF.js +8 -0
  18. package/dist/assets/{VirtualizedFileDiff-B37yB9jZ.js → VirtualizedFileDiff-CN_BctrR.js} +4 -4
  19. package/dist/assets/{Virtualizer-X_7XPoTH.js → Virtualizer-CZlLSacm.js} +1 -1
  20. package/dist/assets/Virtualizer-D_a8gKmg.js +1 -0
  21. package/dist/assets/{WalkthroughView-Bxun3k66.js → WalkthroughView-D9Q4lr5x.js} +2 -2
  22. package/dist/assets/{computeVirtualFileMetrics-DYFv_yZS.js → computeVirtualFileMetrics-Gi1d5eU1.js} +1 -1
  23. package/dist/assets/contextPanelEmbeddedChat-CpzVNWAv.js +1 -0
  24. package/dist/assets/de-B_LdJwEM.js +9 -0
  25. package/dist/assets/es-CubfsAYV.js +15 -0
  26. package/dist/assets/fr-5qJM0nFS.js +13 -0
  27. package/dist/assets/index-BW82eK5v.css +1 -0
  28. package/dist/assets/index-Brm3X9rs.js +1 -0
  29. package/dist/assets/index-rlLjZUM5.js +7 -0
  30. package/dist/assets/{isDiffPlainText-DwHKxDYc.js → isDiffPlainText-pH9kAJQH.js} +1 -1
  31. package/dist/assets/{isFilePlainText-Dwq6ILxo.js → isFilePlainText-CVKy_dgB.js} +1 -1
  32. package/dist/assets/ja-DJYIBUlH.js +15 -0
  33. package/dist/assets/ko-DcUBkB7y.js +15 -0
  34. package/dist/assets/main-DLBxKIoX.js +926 -0
  35. package/dist/assets/main-vUCh0VB0.js +2 -0
  36. package/dist/assets/markdownCore-DG6GHLF4.js +3 -0
  37. package/dist/assets/miniChat-BlzGEYgE.js +2 -0
  38. package/dist/assets/mobile-CkX6H-IT.js +2 -0
  39. package/dist/assets/{patchFileDiff-BEDPDypx.js → patchFileDiff-BCTsE43U.js} +3 -3
  40. package/dist/assets/pl-rB6BLcio.js +15 -0
  41. package/dist/assets/pt-BR-DcwtlO-o.js +15 -0
  42. package/dist/assets/renderElectronMiniChatApp-CJYe_KOL.js +2 -0
  43. package/dist/assets/renderMobileApp-hQJTnr8B.js +25 -0
  44. package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +15 -0
  45. package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +1 -0
  46. package/dist/assets/{shikiHighlight-DXYW46vW.js → shikiHighlight-BgTPSITe.js} +1 -1
  47. package/dist/assets/uk-INZlFD9A.js +15 -0
  48. package/dist/assets/useAppFontEffects-Cll4gnsh.js +7268 -0
  49. package/dist/assets/useInlineCommentController-DFFv0hae.js +2 -0
  50. package/dist/assets/{vendor-base-ui-BYlZTzrw.js → vendor-base-ui-_6j2xOWl.js} +1 -1
  51. package/dist/assets/{vendor-codemirror-language-data-CiAYDJXN.js → vendor-codemirror-language-data-DkQX2EBa.js} +2 -2
  52. package/dist/assets/{vendor-framer-motion-CRSgBxjL.js → vendor-framer-motion-livSKyyV.js} +1 -1
  53. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +1 -0
  54. package/dist/assets/{vendor-motion-dom-DJLgZh4Q.js → vendor-motion-dom-D_o3BTI3.js} +1 -1
  55. package/dist/assets/vendor-zod-BLfBSgBh.js +39 -0
  56. package/dist/assets/{web-components-DCLjCO9n.js → web-components-DLnGY4fs.js} +4 -4
  57. package/dist/assets/zh-CN-Dzda8xa1.js +15 -0
  58. package/dist/assets/zh-TW-Cwn3rNYZ.js +15 -0
  59. package/dist/index.html +6 -5
  60. package/dist/mini-chat.html +5 -4
  61. package/dist/mobile.html +5 -4
  62. package/package.json +5 -7
  63. package/server/index.js +44 -0
  64. package/server/lib/agent-memory/project-resolution.js +10 -1
  65. package/server/lib/agent-memory/project-resolution.test.js +9 -0
  66. package/server/lib/agent-memory/runtime.js +7 -2
  67. package/server/lib/client-auth/pairing.js +8 -7
  68. package/server/lib/client-auth/pairing.test.js +5 -1
  69. package/server/lib/client-auth/remote-clients.js +9 -1
  70. package/server/lib/client-auth/remote-clients.test.js +17 -0
  71. package/server/lib/dictation/DOCUMENTATION.md +32 -8
  72. package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
  73. package/server/lib/dictation/local/worker-process.js +2 -2
  74. package/server/lib/dictation/openai-compatible-session.js +3 -2
  75. package/server/lib/dictation/stream-manager.js +77 -34
  76. package/server/lib/dictation/stream-manager.test.js +60 -2
  77. package/server/lib/fs/routes.test.js +76 -0
  78. package/server/lib/git/routes.js +43 -0
  79. package/server/lib/git/service.js +85 -5
  80. package/server/lib/git/service.test.js +93 -0
  81. package/server/lib/github/pr-status.js +10 -1
  82. package/server/lib/opencode/DOCUMENTATION.md +6 -2
  83. package/server/lib/opencode/feature-routes-runtime.js +5 -9
  84. package/server/lib/opencode/lifecycle.js +202 -26
  85. package/server/lib/opencode/lifecycle.test.js +179 -1
  86. package/server/lib/opencode/providers.js +9 -4
  87. package/server/lib/opencode/providers.test.js +27 -0
  88. package/server/lib/opencode/restart-session-recovery.test.js +59 -0
  89. package/server/lib/opencode/session-runtime.js +39 -2
  90. package/server/lib/opencode/session-runtime.test.js +74 -0
  91. package/server/lib/opencode/settings-helpers.js +15 -0
  92. package/server/lib/opencode/settings-helpers.test.js +22 -0
  93. package/server/lib/opencode/settings-normalization-runtime.js +3 -0
  94. package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
  95. package/server/lib/opencode/settings-runtime.js +32 -10
  96. package/server/lib/opencode/settings-runtime.test.js +85 -0
  97. package/server/lib/opencode/skill-routes.js +29 -73
  98. package/server/lib/opencode/skill-routes.test.js +2 -5
  99. package/server/lib/project-context/DOCUMENTATION.md +2 -0
  100. package/server/lib/project-context/runtime.js +7 -2
  101. package/server/lib/projects/project-config.js +7 -2
  102. package/server/lib/quota/DOCUMENTATION.md +1 -1
  103. package/server/lib/quota/providers/claude/index.js +2 -2
  104. package/server/lib/quota/providers/index.js +1 -7
  105. package/server/lib/quota/providers/zai.js +26 -6
  106. package/server/lib/quota/providers/zai.test.js +33 -0
  107. package/server/lib/relay/DOCUMENTATION.md +1 -1
  108. package/server/lib/relay/service.js +34 -2
  109. package/server/lib/relay/service.test.js +69 -0
  110. package/server/lib/session-goal/runtime.js +2 -1
  111. package/server/lib/session-goal/runtime.test.js +4 -2
  112. package/server/lib/session-knowledge/DOCUMENTATION.md +2 -0
  113. package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
  114. package/server/lib/skills-catalog/cache.js +120 -1
  115. package/server/lib/skills-catalog/cache.test.js +77 -0
  116. package/server/lib/skills-catalog/curated-sources.js +21 -5
  117. package/server/lib/skills-catalog/curated-sources.test.js +4 -4
  118. package/server/lib/skills-catalog/disk-cache.js +52 -0
  119. package/server/lib/skills-catalog/github-meta.js +139 -0
  120. package/server/lib/skills-catalog/github-meta.test.js +71 -0
  121. package/server/lib/skills-catalog/source.js +0 -5
  122. package/server/lib/small-model/DOCUMENTATION.md +74 -6
  123. package/server/lib/small-model/call.js +46 -12
  124. package/server/lib/small-model/call.test.js +79 -0
  125. package/server/lib/small-model/index.js +51 -8
  126. package/server/lib/small-model/index.test.js +73 -3
  127. package/server/lib/small-model/routes.js +1 -1
  128. package/server/lib/small-model/runtime-providers.js +156 -0
  129. package/server/lib/small-model/runtime-providers.test.js +112 -0
  130. package/server/lib/terminal/DOCUMENTATION.md +2 -0
  131. package/server/lib/terminal/runtime.js +29 -1
  132. package/server/lib/terminal/runtime.test.js +26 -0
  133. package/server/lib/ui-auth/ui-auth.js +2 -2
  134. package/server/lib/ui-auth/ui-auth.test.js +2 -2
  135. package/dist/assets/CommitSection-D9cV-qR9.js +0 -1
  136. package/dist/assets/DiagramEditor-B9NCadU7.js +0 -1
  137. package/dist/assets/DiagramView-LKGBwf4G.js +0 -1
  138. package/dist/assets/DiffView-BWNq-0ov.js +0 -4
  139. package/dist/assets/FilesView-DB-Q0Gkz.js +0 -14
  140. package/dist/assets/GitView-DsWXqWx3.js +0 -6
  141. package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +0 -1
  142. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +0 -12
  143. package/dist/assets/OnboardingScreen-CDjgzxEe.js +0 -1
  144. package/dist/assets/PierreDiffViewer-D_Gt4A_6.js +0 -136
  145. package/dist/assets/PlanView-UvuxIl9-.js +0 -4
  146. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +0 -1
  147. package/dist/assets/SettingsView-3B9VN6Ys.js +0 -28
  148. package/dist/assets/SettingsWindow-CqQNDKNd.js +0 -1
  149. package/dist/assets/ToolOutputDialog-PmjlAxVE.js +0 -15
  150. package/dist/assets/ToolPartDiffPreview-B34Xw9wq.js +0 -8
  151. package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +0 -1
  152. package/dist/assets/de-DbV6CLxv.js +0 -9
  153. package/dist/assets/es-CVDlyzZ4.js +0 -15
  154. package/dist/assets/fr-Czc-p0g-.js +0 -13
  155. package/dist/assets/index-1OhiMDBz.css +0 -1
  156. package/dist/assets/index-BSvmTvZl.js +0 -1
  157. package/dist/assets/index-DzriVon2.js +0 -7
  158. package/dist/assets/ja-dwc9NM_S.js +0 -15
  159. package/dist/assets/ko-Ds1DZ8FX.js +0 -15
  160. package/dist/assets/main-BF51IOVF.js +0 -921
  161. package/dist/assets/main-D7UPARut.js +0 -2
  162. package/dist/assets/markdownCore-BgeBDwD3.js +0 -2
  163. package/dist/assets/miniChat-BISXSGOo.js +0 -2
  164. package/dist/assets/mobile-BnYxVuvw.js +0 -2
  165. package/dist/assets/pl-CLiTO7i-.js +0 -15
  166. package/dist/assets/pt-BR-GIimJgpK.js +0 -15
  167. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +0 -2
  168. package/dist/assets/renderMobileApp-BiMbzPq9.js +0 -25
  169. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +0 -15
  170. package/dist/assets/scheduledTasksApi-01zzfzqH.js +0 -1
  171. package/dist/assets/uk-DLfgD1ki.js +0 -15
  172. package/dist/assets/useAppFontEffects-CbzHzFop.js +0 -7271
  173. package/dist/assets/useInlineCommentController-CegKdDXi.js +0 -2
  174. package/dist/assets/vendor-zod-adaMkgkm.js +0 -39
  175. package/dist/assets/zh-CN-DkeP5awK.js +0 -15
  176. package/dist/assets/zh-TW-BocaFm3d.js +0 -15
  177. package/server/lib/quota/providers/command-code.js +0 -90
  178. package/server/lib/quota/providers/command-code.test.js +0 -72
  179. package/server/lib/skills-catalog/clawdhub/api.js +0 -126
  180. package/server/lib/skills-catalog/clawdhub/install.js +0 -238
  181. package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
  182. package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
@@ -1,28 +0,0 @@
1
- import{R as o,j as s,f as ft,r as Je}from"./vendor-react-BUCujlKS.js";import{f as it,B as H,I as z,o as Nn,aV as ea,t as R,O as Tl,fe as Dl,ef as Le,ff as Dt,b as Ks,h as ye,fg as Ml,aR as Bs,aT as Hs,fh as Rl,aU as Gs,e6 as ka,fi as Ol,fj as qn,fk as Ws,bU as Ms,bs as Vt,bt as $t,bu as Bt,bv as Ht,bw as Gt,bx as is,S as He,fl as wa,aQ as qs,dW as Fi,fm as Ll,fn as lr,fo as En,eh as Yt,fp as Fs,l as tt,fq as qt,bK as Mt,bL as Rt,er as Ut,bM as _t,bN as Ot,bO as dt,fr as Qt,bP as Ns,dj as ba,fs as vn,es as Jn,ft as yn,fu as gs,dp as ys,fv as Fl,fw as gt,fx as Ro,fy as Kl,fz as Dn,fA as Ja,fB as zl,fC as Za,fD as rn,fE as Wn,dk as Oo,fF as ln,ag as Xa,af as Es,fG as cr,eI as Ul,dU as Lo,g as va,fH as _l,fI as $s,dT as Vl,fJ as $l,fK as Bl,fL as Yi,aX as Zi,aY as Xi,aZ as Fo,fM as an,fN as sn,L as er,fO as dr,aa as Hl,bQ as Gl,cq as ql,Q as Wl,N as Jl,R as Ql,V as Ko,fP as Yl,fQ as Zl,bH as Xl,bR as Ki,eH as pr,P as jn,fR as bn,ee as Ts,a$ as zo,n as ns,bg as Qa,x as ec,i as tc,j as sc,bA as nc,p as ac,fS as ic,bj as rc,bB as mr,bC as Uo,bi as oc,fT as gi,fU as ur,fV as lc,fW as cc,fX as dc,fY as pc,dv as ei,fZ as bs,f_ as Ls,f$ as hn,g0 as fn,aj as ia,g1 as xn,g2 as Qn,g3 as gr,g4 as ra,g5 as oa,g6 as mc,g7 as uc,g8 as gc,g9 as hc,ga as hi,gb as hr,gc as fc,gd as xc,ge as bc,gf as vc,gg as yc,gh as fi,gi as fr,dR as jc,gj as wc,cb as kc,br as xr,gk as nn,gl as xi,bq as br,gm as _o,gn as vr,go as Vo,gp as Nc,d$ as Sc,gq as Cc,ac as pn,ae as Pc,gr as Ic}from"./useAppFontEffects-CbzHzFop.js";import{r as lt,E as ps,cs as Ac,ct as yr,v as on,an as bi,m as $o,W as Ec,L as vt,o as kn,u as ce,y as cs,J as jr,bZ as wr,c0 as kr,K as la,p as Tc,cu as Dc,j as Mc,bY as Gn,cv as Rc,a6 as Oc,b$ as Lc,cw as Fc,cx as Kc,s as zc,e as Na,b_ as Uc,z as Sa,cy as Bo,S as _c,cz as Vc,R as $c,aC as Nr,au as Bc,_ as wn,cA as Hc,t as Ho,cB as Sr,cr as Cr,cC as Pr,as as Ir,cD as Gc,cE as qc,cF as Ar,b as Wc,aq as Go,cG as qo,cH as Jc,cI as Qc,cJ as Yc,cK as Zc,cL as Xc,cM as ed,ah as td,i as Wo}from"./index-DzriVon2.js";import{u as sd,U as Er,w as Mn,y as Rn,z as On,A as Ln,b as tr,q as Yn,s as Zn,v as Xn,J as Tn,F as nd,h as ks,p as ad,H as id,K as fa,Q as Jo,B as rd,E as od}from"./runtimeEndpointReset-BMBRhIbf.js";import{u as Cs,c as Qo,d as ld,p as cd}from"./vendor-zustand-BAGL70zf.js";import{s as dd,p as pd}from"./vendor-yaml-3778uTud.js";import{c as Tr,s as md,C as Dr,P as ud}from"./shikiHighlight-DXYW46vW.js";import{getResolvedShikiTheme as gd}from"./appThemeRegistry-BK0dHKa6.js";import{E as Mr}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Yo}from"./vendor-qrcode-DTJ12-WC.js";import{k as hd,s as fd}from"./contextPanelEmbeddedChat-BO1wRpaN.js";const Rr=()=>{const{t}=it(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const f=await lt("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!f.ok)return;const c=await f.json().catch(()=>null);if(!c||i)return;const y=typeof c.port=="number"&&Number.isFinite(c.port)&&c.port>0?c.port:null,m=typeof c.tunnelUrl=="string"&&c.tunnelUrl.trim().length>0?c.tunnelUrl.trim():null;a({port:y,tunnelUrl:m})}catch{}})(),()=>{i=!0,r?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.openchamber.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.openchamber.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(i=>s.jsxs(H,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{Nn(i.url)},children:[s.jsx(z,{name:"external-link",className:"size-3.5 shrink-0"}),s.jsx("span",{className:"max-w-64 truncate font-mono typography-micro",children:i.url})]},i.key))})},Or="https://github.com/openchamber/openchamber",xd="https://discord.gg/ZYRSdnwwKA",Lr="https://x.com/openchamber_dev",bd=800,Zo=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=it(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,f]=o.useState(null),[c,y]=o.useState(null),m=sd(Cs(N=>({info:N.info,checking:N.checking,available:N.available,error:N.error,downloading:N.downloading,downloaded:N.downloaded,progress:N.progress,runtimeType:N.runtimeType,checkForUpdates:N.checkForUpdates,downloadUpdate:N.downloadUpdate,restartToUpdate:N.restartToUpdate}))),{isMobile:v}=ea(),p=l||m.info?.currentVersion||"unknown";o.useEffect(()=>{let N=!1;return(async()=>{try{const I=await lt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!I.ok)return;const u=await I.json().catch(()=>null),D=typeof u?.openchamberVersion=="string"&&u.openchamberVersion.trim().length>0?u.openchamberVersion.trim():null;N||f(D)}catch{N||f(null)}})(),()=>{N=!0}},[]),o.useEffect(()=>{let N=!1;return(async()=>{try{const I=await lt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!I.ok)return;const u=await I.json().catch(()=>null),D=typeof u?.currentVersion=="string"&&u.currentVersion.trim().length>0?u.currentVersion.trim():null;N||y(D)}catch{N||y(null)}})(),()=>{N=!0}},[]);const F=o.useRef(!1);o.useEffect(()=>{if(m.checking)r(!0),F.current=!0;else if(i){const N=setTimeout(()=>{r(!1),F.current&&!m.available&&!m.error&&(R.success(e("settings.openchamber.about.toast.latestVersion")),F.current=!1)},bd);return()=>clearTimeout(N)}},[e,m.checking,i,m.available,m.error]);const S=m.checking||i;return v?s.jsxs("div",{className:"w-full space-y-6 pb-2",children:[s.jsxs("div",{className:"flex flex-col items-center text-center",children:[s.jsx(Tl,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${Dl}`,children:"OpenChamber"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:p})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:c||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(Rr,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!m.available&&!m.error&&s.jsxs(H,{type:"button",variant:"outline",size:"sm",onClick:()=>m.checkForUpdates(),disabled:S,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[S?s.jsx(z,{name:"loader",className:"size-4 animate-spin"}):s.jsx(z,{name:"refresh",className:"size-4"}),e(S?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!S&&m.available&&s.jsxs(H,{type:"button",variant:"default",size:"sm",onClick:()=>n(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(z,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:m.info?.version||""})]})]}),m.error&&s.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}),s.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[s.jsxs("div",{className:"flex items-center justify-center gap-5",children:[s.jsxs("a",{href:Or,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:xd,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:Lr,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground",children:[s.jsx(z,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(Er,{open:a,onOpenChange:n,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]}):s.jsxs(Le,{divider:!1,children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center justify-between gap-4 px-4 py-3 border-b border-border/40",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Dt,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:p})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Dt,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[m.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(z,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!m.checking&&m.available&&s.jsxs(H,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(z,{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&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>m.checkForUpdates(),disabled:m.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),m.error&&s.jsx("div",{className:"px-3 py-2 border-b border-border/40",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:m.error})}),s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-4 py-3 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsx("span",{className:Dt,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(Rr,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:Or,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(z,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Lr,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(z,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(Er,{open:a,onOpenChange:n,info:m.info,downloading:m.downloading,downloaded:m.downloaded,progress:m.progress,error:m.error,onDownload:m.downloadUpdate,onRestart:m.restartToUpdate,runtimeType:m.runtimeType})]})},Xo=t=>t.trim(),Ca=t=>{const e=ft.c(39),{className:a}=t,{t:n}=it(),i=Ks(vd),r=Ks(yd),l=Ks(jd),f=ps();let c;e[0]!==i?(c=[...i].sort(wd),e[0]=i,e[1]=c):c=e[1];const y=c;let m;e:{if(y.length===0){m=null;break e}let $;e[2]!==r||e[3]!==y?($=y.find(k=>k.id===r)??y[0],e[2]=r,e[3]=y,e[4]=$):$=e[4],m=$}const v=m;if(f||y.length===0)return null;let p;e[5]!==v||e[6]!==n?(p=v?.label&&v.label.trim().length>0?v.label:v?.path.split("/").filter(Boolean).pop()||v?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=v,e[6]=n,e[7]=p):p=e[7];const F=p;let S;e[8]!==F?(S=Xo(F),e[8]=F,e[9]=S):S=e[9];const N=S;let h;e[10]!==a?(h=ye(a),e[10]=a,e[11]=h):h=e[11];let I;e[12]!==n?(I=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=I):I=e[13];let u;e[14]!==n?(u=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=u):u=e[15];let D,q;e[16]===Symbol.for("react.memo_cache_sentinel")?(D=ye("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"),q=s.jsx(z,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=D,e[17]=q):(D=e[16],q=e[17]);let M;e[18]!==N?(M=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:N}),e[18]=N,e[19]=M):M=e[19];let P;e[20]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(z,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=P):P=e[20];let g;e[21]!==M||e[22]!==I||e[23]!==u?(g=s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":I,title:u,className:D,children:[q,M,P]})}),e[21]=M,e[22]=I,e[23]=u,e[24]=g):g=e[24];const j=v?.id??"";let L;e[25]!==l?(L=$=>{$&&l($)},e[25]=l,e[26]=L):L=e[26];let C;e[27]!==y?(C=y.map(kd),e[27]=y,e[28]=C):C=e[28];let A;e[29]!==j||e[30]!==L||e[31]!==C?(A=s.jsx(Hs,{align:"start",className:"w-auto",children:s.jsx(Rl,{value:j,onValueChange:L,children:C})}),e[29]=j,e[30]=L,e[31]=C,e[32]=A):A=e[32];let b;e[33]!==g||e[34]!==A?(b=s.jsxs(Gs,{children:[g,A]}),e[33]=g,e[34]=A,e[35]=b):b=e[35];let K;return e[36]!==b||e[37]!==h?(K=s.jsx("div",{className:h,children:b}),e[36]=b,e[37]=h,e[38]=K):K=e[38],K};function vd(t){return t.projects}function yd(t){return t.activeProjectId}function jd(t){return t.setActiveProject}function wd(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function kd(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Xo(e);return s.jsx(Ml,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function Nd(t,e){return`opencode:sidebar-group:${t}:${e}`}const zi=t=>{const e=ft.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,f=r===void 0?!0:r;let c;e[0]!==a||e[1]!==i?(c=Nd(i,a),e[0]=a,e[1]=i,e[2]=c):c=e[2];const y=c,m=o.useId();let v;e[3]!==f||e[4]!==y?(v=()=>{try{const A=localStorage.getItem(y);if(A!==null)return A==="true"}catch{}return f},e[3]=f,e[4]=y,e[5]=v):v=e[5];const[p,F]=Je.useState(v);let S,N;e[6]!==p||e[7]!==y?(S=()=>{try{localStorage.setItem(y,String(p))}catch{}},N=[y,p],e[6]=p,e[7]=y,e[8]=S,e[9]=N):(S=e[8],N=e[9]),Je.useEffect(S,N);let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=()=>F(Sd),e[10]=h):h=e[10];let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=ye("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]=I):I=e[11];const u=!p&&"-rotate-90";let D;e[12]!==u?(D=ye("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",u),e[12]=u,e[13]=D):D=e[13];let q;e[14]!==D?(q=s.jsx(z,{name:"arrow-down-s",className:D}),e[14]=D,e[15]=q):q=e[15];let M;e[16]!==a?(M=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=M):M=e[17];let P;e[18]!==n?(P=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=P):P=e[19];let g;e[20]!==m||e[21]!==p||e[22]!==q||e[23]!==M||e[24]!==P?(g=s.jsxs("button",{type:"button",onClick:h,"aria-expanded":p,"aria-controls":m,className:I,children:[q,M,P]}),e[20]=m,e[21]=p,e[22]=q,e[23]=M,e[24]=P,e[25]=g):g=e[25];const j=!p;let L;e[26]!==l||e[27]!==m||e[28]!==j?(L=s.jsx("div",{id:m,hidden:j,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=m,e[28]=j,e[29]=L):L=e[29];let C;return e[30]!==g||e[31]!==L?(C=s.jsxs("div",{children:[g,L]}),e[30]=g,e[31]=L,e[32]=C):C=e[32],C};function Sd(t){return!t}const Cd=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!a||typeof a!="object")continue;const n=a;typeof n.permission!="string"||typeof n.pattern!="string"||typeof n.action!="string"||n.action!=="allow"&&n.action!=="ask"&&n.action!=="deny"||e.push({permission:n.permission,pattern:n.pattern,action:n.action})}return e},Pd=t=>{const e=new Map;for(const a of t)!a.permission||a.permission==="invalid"||a.pattern&&e.set(`${a.permission}::${a.pattern}`,a);return Array.from(e.values())},Fr=t=>{const e=Pd(Cd(t));if(e.length===0)return;const a={};for(const i of e)i.permission&&((a[i.permission]||={})[i.pattern]=i.action);const n={};for(const[i,r]of Object.entries(a)){const l=Object.keys(r);if(l.length===1&&l[0]==="*"){n[i]=r["*"];continue}n[i]=r}return Object.keys(n).length>0?n:void 0},Id=({onItemSelect:t})=>{const{t:e}=it(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,f]=o.useState(null),[c,y]=o.useState(null),[m,v]=o.useState(!1),[p,F]=o.useState(null),{selectedAgentName:S,agents:N,setSelectedAgent:h,setAgentDraft:I,createAgent:u,deleteAgent:D,loadAgents:q}=ka(Cs(w=>({selectedAgentName:w.selectedAgentName,agents:w.agents,setSelectedAgent:w.setSelectedAgent,setAgentDraft:w.setAgentDraft,createAgent:w.createAgent,deleteAgent:w.deleteAgent,loadAgents:w.loadAgents})));o.useEffect(()=>{q()},[q]);const M="bg-background",P=()=>{const w="new-agent";let X=w,ee=1;for(;N.some(T=>T.name===X);)X=`${w}-${ee}`,ee++;I({name:X,scope:"user"}),h(X),t?.()},g=async w=>{if(qn(w)){R.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}f(w),y("delete")},j=async w=>{qn(w)&&(f(w),y("reset"))},L=()=>{f(null),y(null)},C=async()=>{if(!(!l||!c)){v(!0);try{const w=await D(l.name,l.scope);w.ok?(w.requiresManualRestart?R.warning(e("settings.agents.page.toast.savedManualRestart")):w.restartDeferred?R.success(e("settings.view.pendingRestart.saved")):c==="delete"?R.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):R.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),L()):c==="delete"?R.error(e("settings.agents.sidebar.toast.deleteFailed")):R.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(w){const X=w instanceof Error?w.message:"",ee=/built-in|not deletable|not found/i.test(X);c==="delete"?R.error(e(ee?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):R.error(e("settings.agents.sidebar.toast.resetFailed"))}v(!1)}},A=w=>{const X=w.name;let ee=1,T=`${X}-copy`;for(;N.some(_=>_.name===T);)ee++,T=`${X}-copy-${ee}`;const O=w,V=w.model?.providerID&&w.model?.modelID?`${w.model.providerID}/${w.model.modelID}`:null,E=w;I({name:T,scope:O.scope||"user",description:w.description,model:V,variant:w.variant,temperature:w.temperature,top_p:w.topP,prompt:w.prompt,mode:w.mode,permission:Fr(w.permission),disable:E.disable}),h(T)},b=w=>{r(w.name),n(w)},K=async()=>{if(!a)return;const w=i.trim().replace(/\s+/g,"-");if(!w){R.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(w===a.name){n(null);return}if(N.some(O=>O.name===w)){R.error(e("settings.agents.sidebar.toast.agentExists"));return}const X=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,ee=a,T=await u({name:w,description:a.description,model:X,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:Fr(a.permission),disable:ee.disable,scope:ee.scope});if(T.ok){const O=await D(a.name,ee.scope);O.ok?(T.requiresManualRestart||O.requiresManualRestart?R.warning(e("settings.agents.page.toast.savedManualRestart")):R.success(e("settings.agents.sidebar.toast.agentRenamed",{name:w})),h(w)):R.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else R.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},$=w=>{switch(w){case"primary":return s.jsx(z,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(z,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(z,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},k=N.filter(w=>!Ol(w)),W=k.filter(qn),Z=k.filter(w=>!qn(w)),{groupedCustomAgents:B,ungroupedCustomAgents:Q}=Je.useMemo(()=>{const w={},X=[];for(const T of Z){const O=T;O.group?(w[O.group]||(w[O.group]=[]),w[O.group].push(T)):X.push(T)}return{groupedCustomAgents:Object.keys(w).sort((T,O)=>T.localeCompare(O)).map(T=>({name:T,agents:w[T]})),ungroupedCustomAgents:X}},[Z]);return s.jsxs("div",{className:ye("flex h-full flex-col",M),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${Ws} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Ca,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:k.length})}),s.jsx(H,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:P,children:s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ms,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:k.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[W.length>0&&s.jsxs(s.Fragment,{children:[s.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")}),W.map(w=>s.jsx(vi,{agent:w,isSelected:S===w.name,onSelect:()=>{h(w.name),t?.()},onReset:()=>j(w),onDuplicate:()=>A(w),getAgentModeIcon:$,isMenuOpen:p===w.name,onMenuOpenChange:X=>F(X?w.name:null)},w.name))]}),Z.length>0&&s.jsxs(s.Fragment,{children:[s.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")}),B.map(({name:w,agents:X})=>s.jsx(zi,{label:w,count:X.length,storageKey:"agents",children:X.map(ee=>s.jsx(vi,{agent:ee,isSelected:S===ee.name,onSelect:()=>{h(ee.name),t?.()},onRename:()=>b(ee),onDelete:()=>g(ee),onDuplicate:()=>A(ee),getAgentModeIcon:$,isMenuOpen:p===ee.name,onMenuOpenChange:T=>F(T?ee.name:null)},ee.name))},w)),Q.map(w=>s.jsx(vi,{agent:w,isSelected:S===w.name,onSelect:()=>{h(w.name),t?.()},onRename:()=>b(w),onDelete:()=>g(w),onDuplicate:()=>A(w),getAgentModeIcon:$,isMenuOpen:p===w.name,onMenuOpenChange:X=>F(X?w.name:null)},w.name))]})]})}),s.jsx(Vt,{open:l!==null&&c!==null,onOpenChange:w=>{!w&&!m&&L()},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:e(c==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Gt,{children:c==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:L,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:C,disabled:m,children:e(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Vt,{open:a!==null,onOpenChange:w=>!w&&n(null),children:s.jsxs($t,{children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Gt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(He,{value:i,onChange:w=>r(w.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:w=>{w.key==="Enter"&&K()}}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:K,children:e("settings.common.actions.rename")})]})]})})]})},vi=t=>{const e=ft.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:f,onDuplicate:c,getAgentModeIcon:y,isMenuOpen:m,onMenuOpenChange:v}=t,{t:p}=it(),F=a;let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S=wa(),e[0]=S):S=e[0];const N=S,[h,I]=o.useState(!1);let u;e[1]!==r||e[2]!==c||e[3]!==f||e[4]!==l||e[5]!==p?(u=ee=>s.jsxs(s.Fragment,{children:[f&&s.jsxs(ee,{onClick:T=>{T.stopPropagation(),f()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),p("settings.common.actions.rename")]}),s.jsxs(ee,{onClick:T=>{T.stopPropagation(),c()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),p("settings.common.actions.duplicate")]}),l&&s.jsxs(ee,{onClick:T=>{T.stopPropagation(),l()},children:[s.jsx(z,{name:"restart",className:"h-4 w-4 mr-px"}),p("settings.common.actions.reset")]}),r&&s.jsxs(ee,{onClick:T=>{T.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]})]}),e[1]=r,e[2]=c,e[3]=f,e[4]=l,e[5]=p,e[6]=u):u=e[6];const D=u,q=n?"bg-interactive-selection":"hover:bg-interactive-hover";let M;e[7]!==q?(M=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",q),e[7]=q,e[8]=M):M=e[8];let P;e[9]===Symbol.for("react.memo_cache_sentinel")?(P=N?void 0:ee=>{ee.preventDefault(),I(!0)},e[9]=P):P=e[9];let g;e[10]!==M?(g=s.jsx("div",{className:M,onContextMenu:P}),e[10]=M,e[11]=g):g=e[11];let j;e[12]!==a.name?(j=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=j):j=e[13];let L;e[14]!==a.mode||e[15]!==y?(L=y(a.mode),e[14]=a.mode,e[15]=y,e[16]=L):L=e[16];let C;e[17]!==a||e[18]!==F.scope||e[19]!==p?(C=(F.scope||qn(a))&&s.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:qn(a)?p("settings.agents.sidebar.badge.system"):F.scope}),e[17]=a,e[18]=F.scope,e[19]=p,e[20]=C):C=e[20];let A;e[21]!==j||e[22]!==L||e[23]!==C?(A=s.jsxs("div",{className:"flex items-center gap-1.5",children:[j,L,C]}),e[21]=j,e[22]=L,e[23]=C,e[24]=A):A=e[24];let b;e[25]!==a.description?(b=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=b):b=e[26];let K;e[27]!==i||e[28]!==A||e[29]!==b?(K=s.jsxs("button",{onClick:i,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:[A,b]}),e[27]=i,e[28]=A,e[29]=b,e[30]=K):K=e[30];let $;e[31]!==v?($=ee=>{ee&&I(!1),v(ee)},e[31]=v,e[32]=$):$=e[32];let k;e[33]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(Bs,{asChild:!0,children:s.jsx(H,{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:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=k):k=e[33];let W;e[34]!==D?(W=s.jsx(Hs,{align:"end",className:"w-fit min-w-20",children:D(qs)}),e[34]=D,e[35]=W):W=e[35];let Z;e[36]!==m||e[37]!==$||e[38]!==W?(Z=s.jsxs(Gs,{open:m,onOpenChange:$,children:[k,W]}),e[36]=m,e[37]=$,e[38]=W,e[39]=Z):Z=e[39];let B;e[40]!==K||e[41]!==Z?(B=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[K,Z]}),e[40]=K,e[41]=Z,e[42]=B):B=e[42];let Q;e[43]!==B||e[44]!==g?(Q=s.jsx(On,{render:g,children:B}),e[43]=B,e[44]=g,e[45]=Q):Q=e[45];let w;e[46]!==D?(w=s.jsx(Mn,{className:"w-fit min-w-20",children:D(Rn)}),e[46]=D,e[47]=w):w=e[47];let X;return e[48]!==h||e[49]!==Q||e[50]!==w?(X=s.jsxs(Ln,{open:h,onOpenChange:I,children:[Q,w]}),e[48]=h,e[49]=Q,e[50]=w,e[51]=X):X=e[51],X},as=t=>{const e=ft.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:f,description:c,headerEnd:y,showSaveStatus:m}=t,v=m===void 0?!1:m,p=r!=null||c!=null||y!=null||v,F=typeof r=="string"||typeof r=="number",S=l!=null||f!=null;let N;e[0]!==i?(N=ye("h-full",i),e[0]=i,e[1]=N):N=e[1];let h;e[2]!==n?(h=ye("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=h):h=e[3];let I;e[4]!==c||e[5]!==p||e[6]!==S||e[7]!==y||e[8]!==F||e[9]!==v||e[10]!==r||e[11]!==f||e[12]!==l?(I=p&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[r!=null?F?S?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{className:ye(Fi,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:f})]}):s.jsx("h1",{className:Fi,children:r}):r:null,c!=null?typeof c=="string"||typeof c=="number"?s.jsx("p",{className:Ll,children:c}):c:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[y,v&&s.jsx(Ed,{})]})]}),e[4]=c,e[5]=p,e[6]=S,e[7]=y,e[8]=F,e[9]=v,e[10]=r,e[11]=f,e[12]=l,e[13]=I):I=e[13];let u;e[14]!==a||e[15]!==h||e[16]!==I?(u=s.jsxs("div",{className:h,children:[I,a]}),e[14]=a,e[15]=h,e[16]=I,e[17]=u):u=e[17];let D;return e[18]!==N||e[19]!==u?(D=s.jsx(Ms,{outerClassName:N,className:"w-full @container",children:u}),e[18]=N,e[19]=u,e[20]=D):D=e[20],D},Ad=500,Ed=()=>{const t=ft.c(13),{t:e}=it(),a=o.useSyncExternalStore(Ac,yr,yr),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const m=setTimeout(()=>i(!0),Ad);return()=>clearTimeout(m)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let m;t[3]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(z,{name:"error-warning",className:"size-3.5"}),t[3]=m):m=t[3];let v;t[4]!==e?(v=e("settings.common.status.saveFailed"),t[4]=e,t[5]=v):v=t[5];let p;return t[6]!==v?(p=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[m,s.jsx("span",{children:v})]}),t[6]=v,t[7]=p):p=t[7],p}if(a!=="saving"||!n)return null;let f;t[8]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=f):f=t[8];let c;t[9]!==e?(c=e("settings.common.actions.saving"),t[9]=e,t[10]=c):c=t[10];let y;return t[11]!==c?(y=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[f,s.jsx("span",{children:c})]}),t[11]=c,t[12]=y):y=t[12],y},Td=["allow","ask","deny"],xa=t=>t==="allow"||t==="ask"||t==="deny",Ui=()=>({global:null,keys:{}}),Dd=t=>{const e=Ui();if(t==null)return e;if(typeof t=="string")return xa(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){xa(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(xa(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))xa(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},_i=t=>{const e={};t.global!==null&&(e["*"]=t.global);for(const[a,n]of Object.entries(t.keys)){const i=n.patterns.filter(r=>r.pattern.trim().length>0);if(n.action!==null&&i.length===0)e[a]=n.action;else if(i.length>0){const r={};n.action!==null&&(r["*"]=n.action);for(const l of i)r[l.pattern]=l.action;e[a]=r}}return Object.keys(e).length>0?e:null},Md=(t,e)=>JSON.stringify(_i(t))===JSON.stringify(_i(e)),mn=t=>JSON.parse(JSON.stringify(t)),Rd=["edit","external_directory","doom_loop","plan_enter","plan_exit"],Od=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),Kr=new Set(["write","patch","apply_patch","multiedit","invalid"]),Ld=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Fd=({agent:t})=>{const{t:e}=it(),a=ka(O=>O.updateAgent),[n,i]=o.useState(Ui),[r,l]=o.useState(Ui),[f,c]=o.useState(!0),[y,m]=o.useState(!1),[v,p]=o.useState(!1),[F,S]=o.useState({}),[N,h]=o.useState([]),[I,u]=o.useState(""),[D,q]=o.useState(0),M=t.name;o.useEffect(()=>{let O=!1;return c(!0),m(!1),(async()=>{try{const V=lr(),E=V?`?directory=${encodeURIComponent(V)}`:"",_=await lt(`/api/config/agents/${encodeURIComponent(M)}/config${E}`,{headers:{"Cache-Control":"no-cache",...V?{"x-opencode-directory":V}:{}}});if(!_.ok)throw new Error(String(_.status));const J=await _.json().catch(()=>null);if(O)return;const te=Dd(J?.config?.permission);i(mn(te)),l(te)}catch{O||m(!0)}finally{O||c(!1)}})(),()=>{O=!0}},[M,D]),o.useEffect(()=>{let O=!1;return(async()=>{try{const V=await on.listToolIds({directory:lr()});!O&&Array.isArray(V)&&h(V.filter(E=>typeof E=="string"&&!Kr.has(E)))}catch{}})(),()=>{O=!0}},[M]);const P=o.useMemo(()=>{const O=t.permission;if(!Array.isArray(O))return[];const V=[];for(const E of O){if(!E||typeof E!="object")continue;const{permission:_,pattern:J,action:te}=E;typeof _=="string"&&typeof J=="string"&&xa(te)&&V.push({permission:_,pattern:J,action:te})}return V},[t]),g=o.useCallback(O=>{const V=P.find(_=>_.permission===O&&_.pattern==="*");if(V)return V.action;const E=P.find(_=>_.permission==="*"&&_.pattern==="*");return E?E.action:null},[P]),j=o.useCallback(O=>{const V=r.keys[O]?.patterns??[],E=new Set(V.map(_=>_.pattern));return P.filter(_=>_.permission===O&&_.pattern!=="*"&&!E.has(_.pattern))},[P,r.keys]),L=o.useMemo(()=>{const O=new Set;for(const V of N)O.add(V);for(const V of Rd)O.add(V);for(const V of Object.keys(r.keys))O.add(V);for(const V of Kr)O.delete(V);return Array.from(O).sort((V,E)=>V.localeCompare(E))},[N,r.keys]),C=o.useMemo(()=>!Md(r,n),[r,n]),A=O=>{l(V=>({...V,global:O}))},b=(O,V)=>{l(E=>{const _=mn(E),J=_.keys[O]??{action:null,patterns:[]};return J.action=V,J.action===null&&J.patterns.length===0?delete _.keys[O]:_.keys[O]=J,_})},K=(O,V,E,_)=>{l(J=>{const te=mn(J),ne=te.keys[O]??{action:null,patterns:[]};return ne.patterns[V]={pattern:E,action:_},te.keys[O]=ne,te})},$=O=>{l(V=>{const E=mn(V),_=E.keys[O]??{action:null,patterns:[]};return _.patterns.push({pattern:"",action:"allow"}),E.keys[O]=_,E}),S(V=>({...V,[O]:!0}))},k=(O,V)=>{l(E=>{const _=mn(E),J=_.keys[O];return J?(J.patterns.splice(V,1),J.action===null&&J.patterns.length===0&&delete _.keys[O],_):E})},W=()=>{const O=I.trim();!O||O==="*"||(l(V=>{if(V.keys[O])return V;const E=mn(V);return E.keys[O]={action:"ask",patterns:[]},E}),S(V=>({...V,[O]:!0})),u(""))},Z=async()=>{p(!0);try{const O=_i(r),V=await a(M,{permission:O});V.ok?(i(mn(r)),R.success(V.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):R.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{p(!1)}},B=()=>{l(mn(n))},Q=O=>e(O==="allow"?"settings.agents.page.permissionsEditor.action.allow":O==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),w=e("settings.agents.page.permissionsEditor.action.inherit"),X=e("settings.agents.page.permissionsEditor.action.default"),ee=O=>[...O?[{value:"inherit",label:O}]:[],...Td.map(V=>({value:V,label:Q(V)}))],T=(O,V,E,_=w)=>s.jsx(Fs,{value:O??"inherit",options:ee(_),onChange:J=>V(J==="inherit"?null:J),"aria-label":E});return f?s.jsx(Le,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:En,children:e("common.loading")})}):y?s.jsx(Le,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.agents.page.permissionsEditor.state.loadFailed")}),s.jsx(H,{variant:"outline",size:"xs",onClick:()=>q(O=>O+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(Le,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:C?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:B,disabled:v,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(H,{size:"xs",className:"!font-normal",onClick:()=>{Z()},disabled:v,children:e(v?"settings.common.actions.saving":"settings.agents.page.permissionsEditor.actions.save")})]}):void 0,contentClassName:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Dt,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Yt,{children:e("settings.agents.page.permissionsEditor.defaultInfo")}),r.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:Q(g("*")??"allow")})})]}),T(r.global,A,e("settings.agents.page.permissionsEditor.defaultAria"),X)]}),s.jsx("div",{children:L.map(O=>{const V=r.keys[O]??{action:null,patterns:[]},E=j(O),_=Od.has(O)||V.patterns.length>0,J=_||E.length>0,te=F[O]===!0,ne=g(O);return s.jsxs("div",{className:"border-t border-border/40 py-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("button",{type:"button",onClick:J?()=>S(le=>({...le,[O]:!te})):void 0,className:ye("flex min-w-0 items-center gap-1.5 text-left",!J&&"cursor-default"),"aria-expanded":J?te:void 0,children:[s.jsx(z,{name:te&&J?"arrow-down-s":"arrow-right-s",className:ye("h-3.5 w-3.5 shrink-0 text-muted-foreground",!J&&"opacity-0")}),s.jsx("span",{className:Dt,children:Ld(O)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:O}),V.action===null&&ne!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:Q(ne)})}),V.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:e("settings.agents.page.permissionsEditor.ruleCount",{count:String(V.patterns.length)})})]}),T(V.action,le=>b(O,le),e("settings.agents.page.permissionsEditor.keyAria",{key:O}))]}),te&&J&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[V.patterns.map((le,be)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(He,{value:le.pattern,onChange:Ne=>K(O,be,Ne.target.value,le.action),placeholder:e("settings.agents.page.permissionsEditor.patternPlaceholder"),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(Fs,{value:le.action,options:ee(),onChange:Ne=>K(O,be,le.pattern,Ne),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:O})}),s.jsx(H,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>k(O,be),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]},be)),_&&s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$(O),children:[s.jsx(z,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),E.length>0&&s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-micro font-medium text-muted-foreground",children:e("settings.agents.page.permissionsEditor.sessionRulesTitle")}),s.jsx(Yt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),E.map(le=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro min-w-0 flex-1 truncate font-mono text-muted-foreground/70",children:le.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:Q(le.action)})]},`${le.pattern}-${le.action}`))]})]})]},O)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(He,{value:I,onChange:O=>u(O.target.value),onKeyDown:O=>{O.key==="Enter"&&(O.preventDefault(),W())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:W,disabled:!I.trim(),children:[s.jsx(z,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},Kd=(t,e)=>{const a=Jn(e);if(!a)return[];const i=t.find(r=>r.id===a.providerId)?.models?.find(r=>r.id===a.modelId);return i?.variants?Object.keys(i.variants):[]},zd=()=>{const{t}=it(),e=tt(T=>T.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agents:l,agentDraft:f,setAgentDraft:c}=ka(Cs(T=>({selectedAgentName:T.selectedAgentName,getAgentByName:T.getAgentByName,createAgent:T.createAgent,updateAgent:T.updateAgent,agents:T.agents,agentDraft:T.agentDraft,setAgentDraft:T.setAgentDraft}))),y=a?n(a):null,m=!!(f&&f.name===a&&!y),[v,p]=o.useState(""),[F,S]=o.useState("user"),[N,h]=o.useState(""),[I,u]=o.useState("subagent"),[D,q]=o.useState(""),[M,P]=o.useState(""),[g,j]=o.useState(void 0),[L,C]=o.useState(void 0),[A,b]=o.useState(""),[K,$]=o.useState(!1),k=o.useRef(null),W=o.useMemo(()=>Kd(e,D),[D,e]),Z=W.length>0,B=M||"__default",Q=Z,w=o.useMemo(()=>M&&!W.includes(M)?[M,...W]:W,[M,W]);o.useEffect(()=>{if(m&&f){const T=f.name||"",O=f.scope||"user",V=f.description||"",E=f.mode||"subagent",_=f.model||"",J=f.variant||"",te=f.temperature??void 0,ne=f.top_p??void 0,le=f.prompt||"";p(T),S(O),h(V),u(E),q(_),P(J),j(te),C(ne),b(le),k.current={draftName:T,draftScope:O,description:V,mode:E,model:_,variant:J,temperature:te,topP:ne,prompt:le};return}if(y&&a===y.name){const T=y.description||"",O=y.mode||"subagent",V=y.model?.providerID&&y.model?.modelID?`${y.model.providerID}/${y.model.modelID}`:"",E=y.variant||"",_=y.temperature??void 0,J=y.topP??void 0,te=y.prompt||"";h(T),u(O),q(V),P(E),j(_),C(J),b(te),k.current={draftName:"",draftScope:"user",description:T,mode:O,model:V,variant:E,temperature:_,topP:J,prompt:te}}},[f,m,y,a]);const X=o.useMemo(()=>{const T=k.current;return T?!!(m&&(v!==T.draftName||F!==T.draftScope)||N!==T.description||I!==T.mode||D!==T.model||M!==T.variant||g!==T.temperature||L!==T.topP||A!==T.prompt):!1},[N,v,F,m,I,D,A,g,L,M]),ee=async()=>{const T=m?v.trim().replace(/\s+/g,"-"):a?.trim();if(!T){R.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&l.some(O=>O.name===T)){R.error(t("settings.agents.sidebar.toast.agentExists"));return}$(!0);try{const O=D.trim(),V=M.trim(),E=A.trim(),_={name:T,...N.trim()?{description:N.trim()}:{},mode:I,model:O===""?null:O,variant:V===""?null:V||void 0,temperature:g??null,top_p:L??null,prompt:E||(m?void 0:null),...m&&F?{scope:F}:{}};let J;m?(J=await i(_),J.ok&&c(null)):J=await r(T,_),J.ok?J.requiresManualRestart?R.warning(t("settings.agents.page.toast.savedManualRestart")):J.restartDeferred?R.success(t("settings.view.pendingRestart.saved")):R.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):R.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(O){console.error("Error saving agent:",O);const V=O instanceof Error&&O.message?O.message:t("settings.agents.page.toast.saveUnexpectedError");R.error(V)}finally{$(!1)}};return a?s.jsxs(as,{title:m?t("settings.agents.page.title.new"):a,description:t(m?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(Le,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[m&&s.jsxs(qt,{settingsItem:"agents.name",label:t("settings.agents.page.field.agentName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(He,{value:v,onChange:T=>p(T.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Mt,{value:F,onValueChange:T=>S(T),children:[s.jsx(Rt,{size:Ut,className:"w-fit min-w-[100px]",children:s.jsx(_t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Ot,{align:"end",children:[s.jsx(dt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(dt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Qt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Ns,{value:N,onChange:T=>h(T.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Qt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Fs,{"aria-label":t("settings.agents.page.field.mode"),value:I,onChange:u,options:[{value:"primary",label:t("settings.agents.page.mode.primary")},{value:"subagent",label:t("settings.agents.page.mode.subagent")},{value:"all",label:t("settings.agents.page.mode.all")}]})})]}),s.jsxs(Le,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(qt,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ba,{providerId:Jn(D)?.providerId??"",modelId:Jn(D)?.modelId??"",onChange:(T,O)=>{q(T&&O?`${T}/${O}`:""),P("")},className:vn})}),s.jsx(qt,{settingsItem:"agents.variant",label:t("settings.agents.page.field.variant"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.variantTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.variantHint")})]}),children:Q?s.jsxs(Mt,{value:B,onValueChange:T=>P(T==="__default"?"":T),children:[s.jsx(Rt,{size:Ut,className:yn,children:s.jsx(_t,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:T=>T==="__default"?t("chat.modelControls.default"):T})}),s.jsxs(Ot,{children:[s.jsx(dt,{value:"__default",children:t("chat.modelControls.default")}),w.map(T=>s.jsx(dt,{value:T,children:T},T))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(He,{value:M,onChange:T=>P(T.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!D&&!M,className:"h-8 w-40 rounded-md px-3"}),M&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>P(""),className:gs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(qt,{settingsItem:"agents.temperature",label:t("settings.agents.page.field.temperature"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.temperatureTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.temperatureRange")})]}),children:[s.jsx(ys,{value:g,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),g!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(void 0),className:gs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(qt,{settingsItem:"agents.top-p",label:t("settings.agents.page.field.topP"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.agents.page.field.topPTooltip")}),s.jsx("p",{children:t("settings.agents.page.field.topPRange")})]}),children:[s.jsx(ys,{value:L,fallbackValue:.9,onValueChange:C,onClear:()=>C(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),L!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>C(void 0),className:gs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Le,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Ns,{value:A,onChange:T=>b(T.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})}),!m&&y&&s.jsx(Fd,{agent:y}),s.jsx("div",{className:"pb-8",children:s.jsx(H,{onClick:ee,disabled:K||!X,size:"xs",className:"!font-normal",children:t(K?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"robot-2",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},Ud="~/.config/opencode/AGENTS.md",el=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},_d=t=>t.length>0&&!t.endsWith(`
2
- `)?`${t}
3
- `:t,Fa={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Vd=(t,e)=>t==="custom"?e:zl(t),$d=t=>t==="custom"?"custom":Ro(t)?t:"concise",zr={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"},yi=async(t,e)=>{bi("saving");try{const a=await lt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(await el(a,e));bi("saved")}catch(a){throw bi("error"),a}},Bd=()=>{const{t}=it(),e=Fl(),[a,n]=o.useState(""),[i,r]=o.useState(!1),[l,f]=o.useState(Fa.responseStyleEnabled),[c,y]=o.useState(Fa.responseStylePreset),[m,v]=o.useState(Fa.responseStyleCustomInstructions),[p,F]=o.useState(!0),[S,N]=o.useState(!1),[h,I]=o.useState(!1),[u,D]=o.useState(""),[q,M]=o.useState(!1),P=o.useRef(null);o.useEffect(()=>{const b=new AbortController;return(async()=>{try{const[$,k]=await Promise.all([lt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:b.signal}),lt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:b.signal})]);let W=Fa;if($.ok){const Z=await $.json();W={...W,optimizeSystemPrompt:Z.optimizeSystemPrompt===!0,responseStyleEnabled:Z.responseStyleEnabled===!0,responseStylePreset:$d(Z.responseStylePreset),responseStyleCustomInstructions:typeof Z.responseStyleCustomInstructions=="string"?Z.responseStyleCustomInstructions:""},typeof Z.globalBehaviorPrompt=="string"&&(W={...W,prompt:Z.globalBehaviorPrompt})}if(!W.prompt.trim()&&k.ok){const Z=await k.json();typeof Z.content=="string"&&(W={...W,prompt:Z.content})}n(W.prompt),r(W.optimizeSystemPrompt),M(W.optimizeSystemPrompt),f(W.responseStyleEnabled),y(W.responseStylePreset),v(W.responseStyleCustomInstructions),D(W.prompt),P.current={enabled:W.responseStyleEnabled,preset:W.responseStylePreset,custom:W.responseStyleCustomInstructions}}catch($){$.name!=="AbortError"&&console.warn("Failed to load behavior settings:",$)}finally{F(!1)}})(),()=>b.abort()},[]),o.useEffect(()=>{if(p)return;const b=P.current;if(b&&b.enabled===l&&b.preset===c&&b.custom===m)return;const K={enabled:l,preset:c,custom:m},$=setTimeout(async()=>{try{await yi({responseStyleEnabled:K.enabled,responseStylePreset:K.preset,responseStyleCustomInstructions:K.custom},t("settings.behavior.page.toast.saveFailed")),P.current=K}catch(k){const W=k instanceof Error?k.message:t("settings.behavior.page.toast.saveFailed");R.error(W)}},400);return()=>clearTimeout($)},[l,c,m,p,t]);const g=Vd(c,m),j=a!==u,L=i!==q,C=async()=>{N(!0);try{const b=_d(a),K=await lt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:b})});if(!K.ok)throw new Error(await el(K,t("settings.behavior.page.toast.saveFailed")));const $=await K.json().catch(()=>null),k=Ja($,"behavior",{id:"agents-md"});await yi({globalBehaviorPrompt:b},t("settings.behavior.page.toast.saveFailed")),n(b),D(b),R.success(t(k?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(b){console.error("Failed to save behavior:",b);const K=b instanceof Error?b.message:t("settings.behavior.page.toast.saveFailed");R.error(K)}finally{N(!1)}},A=async()=>{I(!0);try{await yi({optimizeSystemPrompt:i},t("settings.behavior.page.toast.saveFailed")),M(i),Dn("behavior",{id:"optimize-system-prompt"}),R.success(t("settings.view.pendingRestart.saved"))}catch(b){const K=b instanceof Error?b.message:t("settings.behavior.page.toast.saveFailed");R.error(K)}finally{I(!1)}};return s.jsxs(as,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(Le,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(gt,{checked:i,onChange:r,disabled:p||h,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(H,{type:"button",size:"xs",onClick:()=>{A()},disabled:p||h||!L,className:"!font-normal",children:t(h?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(Le,{title:t("settings.behavior.page.section.systemPrompt"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:Ud})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Ns,{value:a,onChange:b=>n(b.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(H,{onClick:C,disabled:S||!j||p,size:"xs",className:"!font-normal",children:t(S?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(Le,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(gt,{checked:l,onChange:f,disabled:p,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(qt,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Mt,{value:c,onValueChange:b=>y(b),disabled:p||!l,children:[s.jsx(Rt,{size:Ut,className:yn,children:s.jsx(_t,{children:b=>b==="custom"?t("settings.behavior.page.responseStyle.option.custom"):Ro(b)?t(zr[b]):null})}),s.jsxs(Ot,{children:[Kl.map(b=>s.jsx(dt,{value:b,children:t(zr[b])},b)),s.jsx(dt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Ns,{value:g,onChange:b=>v(b.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!l||c!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Hd=t=>{const e=ft.c(169),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,f]=o.useState(""),[c,y]=o.useState(null),[m,v]=o.useState(null),[p,F]=o.useState(!1),[S,N]=o.useState(null),{selectedCommandName:h,commands:I,setSelectedCommand:u,setCommandDraft:D,createCommand:q,deleteCommand:M,loadCommands:P}=Za(Cs(Gd)),g=rn(qd),j=rn(Wd);let L,C;e[0]!==P||e[1]!==j?(L=()=>{P(),j()},C=[P,j],e[0]=P,e[1]=j,e[2]=L,e[3]=C):(L=e[2],C=e[3]),o.useEffect(L,C);let A;e[4]!==g?(A=new Set(g.map(Jd)),e[4]=g,e[5]=A):A=e[5];const b=A;let K;if(e[6]!==I||e[7]!==b){let ie;e[9]!==b?(ie=Pe=>!b.has(Pe.name),e[9]=b,e[10]=ie):ie=e[10],K=I.filter(ie),e[6]=I,e[7]=b,e[8]=K}else K=e[8];const $=K;let k,W;e[11]!==h||e[12]!==u||e[13]!==b?(k=()=>{h&&b.has(h)&&u(null)},W=[h,u,b],e[11]=h,e[12]=u,e[13]=b,e[14]=k,e[15]=W):(k=e[14],W=e[15]),o.useEffect(k,W);let Z;e[16]!==I||e[17]!==a||e[18]!==D||e[19]!==u?(Z=()=>{let ie="new-command",Pe=1;for(;I.some(Ve=>Ve.name===ie);)ie=`new-command-${Pe}`,Pe++;D({name:ie,scope:"user"}),u(ie),a?.()},e[16]=I,e[17]=a,e[18]=D,e[19]=u,e[20]=Z):Z=e[20];const B=Z;let Q;e[21]!==n?(Q=async ie=>{if(Wn(ie)){R.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}y(ie),v("delete")},e[21]=n,e[22]=Q):Q=e[22];const w=Q;let X;e[23]===Symbol.for("react.memo_cache_sentinel")?(X=async ie=>{Wn(ie)&&(y(ie),v("reset"))},e[23]=X):X=e[23];const ee=X;let T;e[24]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{y(null),v(null)},e[24]=T):T=e[24];const O=T;let V;e[25]!==c||e[26]!==m||e[27]!==M||e[28]!==n?(V=async()=>{if(!c||!m)return;F(!0),await M(c.name)?(m==="delete"?R.success(n("settings.commands.sidebar.toast.commandDeleted",{name:c.name})):R.success(n("settings.commands.sidebar.toast.commandReset",{name:c.name})),O()):m==="delete"?R.error(n("settings.commands.sidebar.toast.deleteFailed")):R.error(n("settings.commands.sidebar.toast.resetFailed")),F(!1)},e[25]=c,e[26]=m,e[27]=M,e[28]=n,e[29]=V):V=e[29];const E=V;let _;e[30]!==I||e[31]!==D||e[32]!==u?(_=ie=>{const Pe=ie.name;let Ve=1,We=`${Pe}-copy`;for(;I.some(kt=>kt.name===We);)Ve++,We=`${Pe}-copy-${Ve}`;D({name:We,scope:ie.scope||"user",description:ie.description,template:ie.template,agent:ie.agent,model:ie.model}),u(We)},e[30]=I,e[31]=D,e[32]=u,e[33]=_):_=e[33];const J=_;let te;e[34]===Symbol.for("react.memo_cache_sentinel")?(te=ie=>{f(ie.name),r(ie)},e[34]=te):te=e[34];const ne=te;let le;e[35]!==I||e[36]!==q||e[37]!==M||e[38]!==i||e[39]!==l||e[40]!==u||e[41]!==n?(le=async()=>{if(!i)return;const ie=l.trim().replace(/\s+/g,"-");if(!ie){R.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(ie===i.name){r(null);return}if(I.some(Ve=>Ve.name===ie)){R.error(n("settings.commands.sidebar.toast.commandExists"));return}await q({name:ie,description:i.description,template:i.template,agent:i.agent,model:i.model})?await M(i.name)?(R.success(`Command renamed to "${ie}"`),u(ie)):R.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):R.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[35]=I,e[36]=q,e[37]=M,e[38]=i,e[39]=l,e[40]=u,e[41]=n,e[42]=le):le=e[42];const be=le;let Ne,de,ue,Me,Ce,ke;if(e[43]!==$||e[44]!==B||e[45]!==w||e[46]!==J||e[47]!==a||e[48]!==S||e[49]!==h||e[50]!==u||e[51]!==n){const ie=$.filter(Wn),Pe=$.filter(Qd);e[58]===Symbol.for("react.memo_cache_sentinel")?(Ce=ye("flex h-full flex-col","bg-background"),e[58]=Ce):Ce=e[58];let Ve;e[59]!==n?(Ve=n("settings.commands.sidebar.title"),e[59]=n,e[60]=Ve):Ve=e[60];let We;e[61]!==Ve?(We=s.jsx("h2",{className:`${Ws} mb-3`,children:Ve}),e[61]=Ve,e[62]=We):We=e[62];let kt;e[63]===Symbol.for("react.memo_cache_sentinel")?(kt=s.jsx(Ca,{className:"mb-3"}),e[63]=kt):kt=e[63];let St;e[64]!==$.length||e[65]!==n?(St=n("settings.commands.sidebar.total",{count:$.length}),e[64]=$.length,e[65]=n,e[66]=St):St=e[66];let Wt;e[67]!==St?(Wt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:St}),e[67]=St,e[68]=Wt):Wt=e[68];let Y;e[69]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[69]=Y):Y=e[69];let xe;e[70]!==B?(xe=s.jsx(H,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:B,children:Y}),e[70]=B,e[71]=xe):xe=e[71];let Oe;e[72]!==Wt||e[73]!==xe?(Oe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Wt,xe]}),e[72]=Wt,e[73]=xe,e[74]=Oe):Oe=e[74],e[75]!==We||e[76]!==Oe?(ke=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[We,kt,Oe]}),e[75]=We,e[76]=Oe,e[77]=ke):ke=e[77],Ne=Ms,de="flex-1 min-h-0",ue="space-y-1 px-3 py-2",Me=$.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[ie.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.builtIn")}),[...ie].sort(Yd).map(we=>s.jsx(Ur,{command:we,isSelected:h===we.name,onSelect:()=>{u(we.name),a?.()},onReset:()=>ee(we),onDuplicate:()=>J(we),isMenuOpen:S===we.name,onMenuOpenChange:rt=>N(rt?we.name:null)},we.name))]}),Pe.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.custom")}),[...Pe].sort(Zd).map(we=>s.jsx(Ur,{command:we,isSelected:h===we.name,onSelect:()=>{u(we.name),a?.()},onRename:()=>ne(we),onDelete:()=>w(we),onDuplicate:()=>J(we),isMenuOpen:S===we.name,onMenuOpenChange:rt=>N(rt?we.name:null)},we.name))]})]}),e[43]=$,e[44]=B,e[45]=w,e[46]=J,e[47]=a,e[48]=S,e[49]=h,e[50]=u,e[51]=n,e[52]=Ne,e[53]=de,e[54]=ue,e[55]=Me,e[56]=Ce,e[57]=ke}else Ne=e[52],de=e[53],ue=e[54],Me=e[55],Ce=e[56],ke=e[57];let fe;e[78]!==Ne||e[79]!==de||e[80]!==ue||e[81]!==Me?(fe=s.jsx(Ne,{outerClassName:de,className:ue,children:Me}),e[78]=Ne,e[79]=de,e[80]=ue,e[81]=Me,e[82]=fe):fe=e[82];const ze=c!==null&&m!==null;let Ae;e[83]!==p?(Ae=ie=>{!ie&&!p&&O()},e[83]=p,e[84]=Ae):Ae=e[84];let he;e[85]!==m||e[86]!==n?(he=n(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=n,e[87]=he):he=e[87];let ge;e[88]!==he?(ge=s.jsx(Ht,{children:he}),e[88]=he,e[89]=ge):ge=e[89];let Ee;e[90]!==c?.name||e[91]!==m||e[92]!==n?(Ee=m==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:c?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:c?.name??""}),e[90]=c?.name,e[91]=m,e[92]=n,e[93]=Ee):Ee=e[93];let Te;e[94]!==Ee?(Te=s.jsx(Gt,{children:Ee}),e[94]=Ee,e[95]=Te):Te=e[95];let Qe;e[96]!==ge||e[97]!==Te?(Qe=s.jsxs(Bt,{children:[ge,Te]}),e[96]=ge,e[97]=Te,e[98]=Qe):Qe=e[98];let Be;e[99]!==n?(Be=n("settings.common.actions.cancel"),e[99]=n,e[100]=Be):Be=e[100];let Ke;e[101]!==p||e[102]!==Be?(Ke=s.jsx(H,{size:"sm",variant:"ghost",onClick:O,disabled:p,children:Be}),e[101]=p,e[102]=Be,e[103]=Ke):Ke=e[103];let Ge;e[104]!==m||e[105]!==n?(Ge=n(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=n,e[106]=Ge):Ge=e[106];let qe;e[107]!==E||e[108]!==p||e[109]!==Ge?(qe=s.jsx(H,{size:"sm",onClick:E,disabled:p,children:Ge}),e[107]=E,e[108]=p,e[109]=Ge,e[110]=qe):qe=e[110];let Ie;e[111]!==Ke||e[112]!==qe?(Ie=s.jsxs(is,{children:[Ke,qe]}),e[111]=Ke,e[112]=qe,e[113]=Ie):Ie=e[113];let Re;e[114]!==Qe||e[115]!==Ie?(Re=s.jsxs($t,{className:"max-w-md",children:[Qe,Ie]}),e[114]=Qe,e[115]=Ie,e[116]=Re):Re=e[116];let $e;e[117]!==ze||e[118]!==Ae||e[119]!==Re?($e=s.jsx(Vt,{open:ze,onOpenChange:Ae,children:Re}),e[117]=ze,e[118]=Ae,e[119]=Re,e[120]=$e):$e=e[120];const Ue=i!==null;let je;e[121]===Symbol.for("react.memo_cache_sentinel")?(je=ie=>!ie&&r(null),e[121]=je):je=e[121];let U;e[122]!==n?(U=n("settings.commands.sidebar.renameDialog.title"),e[122]=n,e[123]=U):U=e[123];let re;e[124]!==U?(re=s.jsx(Ht,{children:U}),e[124]=U,e[125]=re):re=e[125];const pe=i?.name??"";let ve;e[126]!==n||e[127]!==pe?(ve=n("settings.commands.sidebar.renameDialog.description",{name:pe}),e[126]=n,e[127]=pe,e[128]=ve):ve=e[128];let ae;e[129]!==ve?(ae=s.jsx(Gt,{children:ve}),e[129]=ve,e[130]=ae):ae=e[130];let _e;e[131]!==re||e[132]!==ae?(_e=s.jsxs(Bt,{children:[re,ae]}),e[131]=re,e[132]=ae,e[133]=_e):_e=e[133];let Ze;e[134]===Symbol.for("react.memo_cache_sentinel")?(Ze=ie=>f(ie.target.value),e[134]=Ze):Ze=e[134];let G;e[135]!==n?(G=n("settings.commands.sidebar.renameDialog.placeholder"),e[135]=n,e[136]=G):G=e[136];let Fe;e[137]!==be?(Fe=ie=>{ie.key==="Enter"&&be()},e[137]=be,e[138]=Fe):Fe=e[138];let Ye;e[139]!==l||e[140]!==G||e[141]!==Fe?(Ye=s.jsx(He,{value:l,onChange:Ze,placeholder:G,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Fe}),e[139]=l,e[140]=G,e[141]=Fe,e[142]=Ye):Ye=e[142];let st;e[143]===Symbol.for("react.memo_cache_sentinel")?(st=()=>r(null),e[143]=st):st=e[143];let et;e[144]!==n?(et=n("settings.common.actions.cancel"),e[144]=n,e[145]=et):et=e[145];let wt;e[146]!==et?(wt=s.jsx(H,{size:"sm",variant:"ghost",onClick:st,children:et}),e[146]=et,e[147]=wt):wt=e[147];let pt;e[148]!==n?(pt=n("settings.common.actions.rename"),e[148]=n,e[149]=pt):pt=e[149];let mt;e[150]!==be||e[151]!==pt?(mt=s.jsx(H,{size:"sm",onClick:be,children:pt}),e[150]=be,e[151]=pt,e[152]=mt):mt=e[152];let ot;e[153]!==wt||e[154]!==mt?(ot=s.jsxs(is,{children:[wt,mt]}),e[153]=wt,e[154]=mt,e[155]=ot):ot=e[155];let bt;e[156]!==_e||e[157]!==Ye||e[158]!==ot?(bt=s.jsxs($t,{children:[_e,Ye,ot]}),e[156]=_e,e[157]=Ye,e[158]=ot,e[159]=bt):bt=e[159];let ut;e[160]!==Ue||e[161]!==bt?(ut=s.jsx(Vt,{open:Ue,onOpenChange:je,children:bt}),e[160]=Ue,e[161]=bt,e[162]=ut):ut=e[162];let At;return e[163]!==Ce||e[164]!==ke||e[165]!==fe||e[166]!==$e||e[167]!==ut?(At=s.jsxs("div",{className:Ce,children:[ke,fe,$e,ut]}),e[163]=Ce,e[164]=ke,e[165]=fe,e[166]=$e,e[167]=ut,e[168]=At):At=e[168],At},Ur=t=>{const e=ft.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:f,onDuplicate:c,isMenuOpen:y,onMenuOpenChange:m}=t,{t:v}=it();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=wa(),e[0]=p):p=e[0];const F=p,[S,N]=o.useState(!1);let h;e[1]!==r||e[2]!==c||e[3]!==f||e[4]!==l||e[5]!==v?(h=Q=>s.jsxs(s.Fragment,{children:[f&&s.jsxs(Q,{onClick:w=>{w.stopPropagation(),f()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),v("settings.common.actions.rename")]}),s.jsxs(Q,{onClick:w=>{w.stopPropagation(),c()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),v("settings.common.actions.duplicate")]}),l&&s.jsxs(Q,{onClick:w=>{w.stopPropagation(),l()},children:[s.jsx(z,{name:"restart",className:"h-4 w-4 mr-px"}),v("settings.common.actions.reset")]}),r&&s.jsxs(Q,{onClick:w=>{w.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),v("settings.common.actions.delete")]})]}),e[1]=r,e[2]=c,e[3]=f,e[4]=l,e[5]=v,e[6]=h):h=e[6];const I=h,u=n?"bg-interactive-selection":"hover:bg-interactive-hover";let D;e[7]!==u?(D=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",u),e[7]=u,e[8]=D):D=e[8];let q;e[9]===Symbol.for("react.memo_cache_sentinel")?(q=F?void 0:Q=>{Q.preventDefault(),N(!0)},e[9]=q):q=e[9];let M;e[10]!==D?(M=s.jsx("div",{className:D,onContextMenu:q}),e[10]=D,e[11]=M):M=e[11];let P;e[12]!==a.name?(P=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=P):P=e[13];let g;e[14]!==a||e[15]!==v?(g=(a.scope||Wn(a))&&s.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:Wn(a)?v("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=v,e[16]=g):g=e[16];let j;e[17]!==P||e[18]!==g?(j=s.jsxs("div",{className:"flex items-center gap-2",children:[P,g]}),e[17]=P,e[18]=g,e[19]=j):j=e[19];let L;e[20]!==a.description?(L=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=L):L=e[21];let C;e[22]!==i||e[23]!==L||e[24]!==j?(C=s.jsxs("button",{onClick:i,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:[j,L]}),e[22]=i,e[23]=L,e[24]=j,e[25]=C):C=e[25];let A;e[26]!==m?(A=Q=>{Q&&N(!1),m(Q)},e[26]=m,e[27]=A):A=e[27];let b;e[28]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(Bs,{asChild:!0,children:s.jsx(H,{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:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=b):b=e[28];let K;e[29]!==I?(K=s.jsx(Hs,{align:"end",className:"w-fit min-w-20",children:I(qs)}),e[29]=I,e[30]=K):K=e[30];let $;e[31]!==y||e[32]!==A||e[33]!==K?($=s.jsxs(Gs,{open:y,onOpenChange:A,children:[b,K]}),e[31]=y,e[32]=A,e[33]=K,e[34]=$):$=e[34];let k;e[35]!==C||e[36]!==$?(k=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[C,$]}),e[35]=C,e[36]=$,e[37]=k):k=e[37];let W;e[38]!==k||e[39]!==M?(W=s.jsx(On,{render:M,children:k}),e[38]=k,e[39]=M,e[40]=W):W=e[40];let Z;e[41]!==I?(Z=s.jsx(Mn,{className:"w-fit min-w-20",children:I(Rn)}),e[41]=I,e[42]=Z):Z=e[42];let B;return e[43]!==S||e[44]!==W||e[45]!==Z?(B=s.jsxs(Ln,{open:S,onOpenChange:N,children:[W,Z]}),e[43]=S,e[44]=W,e[45]=Z,e[46]=B):B=e[46],B};function Gd(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function qd(t){return t.skills}function Wd(t){return t.loadSkills}function Jd(t){return t.name}function Qd(t){return!Wn(t)}function Yd(t,e){return t.name.localeCompare(e.name)}function Zd(t,e){return t.name.localeCompare(e.name)}const Xd=()=>{const{t}=it(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commands:r,commandDraft:l,setCommandDraft:f}=Za(Cs(A=>({selectedCommandName:A.selectedCommandName,getCommandByName:A.getCommandByName,createCommand:A.createCommand,updateCommand:A.updateCommand,commands:A.commands,commandDraft:A.commandDraft,setCommandDraft:A.setCommandDraft}))),c=e?a(e):null,y=!!(l&&l.name===e&&!c),[m,v]=o.useState(""),[p,F]=o.useState("user"),[S,N]=o.useState(""),[h,I]=o.useState(""),[u,D]=o.useState(""),[q,M]=o.useState(""),[P,g]=o.useState(!1),j=o.useRef(null);o.useEffect(()=>{if(y&&l){const A=l.name||"",b=l.scope||"user",K=l.description||"",$=l.agent||"",k=l.model||"",W=l.template||"";v(A),F(b),N(K),I($),D(k),M(W),j.current={draftName:A,draftScope:b,description:K,agent:$,model:k,template:W}}else if(c){const A=c.description||"",b=c.agent||"",K=c.model||"",$=c.template||"";N(A),I(b),D(K),M($),j.current={draftName:"",draftScope:"user",description:A,agent:b,model:K,template:$}}},[c,y,e,r,l]);const L=o.useMemo(()=>{const A=j.current;return A?!!(y&&(m!==A.draftName||p!==A.draftScope)||S!==A.description||h!==A.agent||u!==A.model||q!==A.template):!1},[h,S,m,p,y,u,q]),C=async()=>{const A=y?m.trim().replace(/\s+/g,"-"):e?.trim();if(!A){R.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!q.trim()){R.error(t("settings.commands.page.toast.templateRequired"));return}if(y&&r.some(b=>b.name===A)){R.error(t("settings.commands.sidebar.toast.commandExists"));return}g(!0);try{const b=h.trim(),K=u.trim(),$=q.trim(),k={name:A,description:S.trim()||void 0,agent:b===""?null:b,model:K===""?null:K,template:$,scope:y?p:void 0};let W;if(y?(W=await n(k),W&&f(null)):W=await i(A,k),W){const Z=ln.getState().changes.some(B=>B.scope==="commands"&&B.id.startsWith(`commands:${A}:`));R.success(t(Z?"settings.view.pendingRestart.saved":y?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else R.error(t(y?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(b){console.error("Error saving command:",b),R.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{g(!1)}};return e?s.jsxs(as,{title:y?t("settings.commands.page.title.new"):`/${e}`,description:t(y?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(Le,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[y&&s.jsxs(qt,{settingsItem:"commands.name",label:t("settings.commands.page.field.commandName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(He,{value:m,onChange:A=>v(A.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Mt,{value:p,onValueChange:A=>F(A),children:[s.jsx(Rt,{size:Ut,className:"w-fit min-w-[100px]",children:s.jsx(_t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Ot,{align:"end",children:[s.jsx(dt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(dt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.common.field.description")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(Ns,{value:S,onChange:A=>N(A.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(Le,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(qt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(Oo,{agentName:h,onChange:A=>I(A),className:vn})}),s.jsx(qt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(ba,{providerId:Jn(u)?.providerId??"",modelId:Jn(u)?.modelId??"",onChange:(A,b)=>{D(A&&b?`${A}/${b}`:"")},className:vn})})]}),s.jsxs(Le,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Ns,{value:q,onChange:A=>M(A.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"}),s.jsxs("p",{className:"mt-2 typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]}),s.jsx("div",{className:"pt-3",children:s.jsx(H,{onClick:C,disabled:P||!L,size:"xs",className:"!font-normal",children:t(P?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"terminal-box",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},_r=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Vr=t=>{const e=ft.c(5),{tone:a,enabled:n}=t;if(!n){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let i;e[1]!==a?(i=ye("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"}[a]),e[1]=a,e[2]=i):i=e[2];let r;return e[3]!==i?(r=s.jsx("span",{className:i}),e[3]=i,e[4]=r):r=e[4],r},ep=t=>{const e=ft.c(120),{onItemSelect:a}=t,{t:n}=it(),{mcpServers:i,selectedMcpName:r,setSelectedMcp:l,setMcpDraft:f,loadMcpConfigs:c,deleteMcp:y}=Xa(Cs(tp)),m=$o(sp);let v;e[0]!==m?(v=ae=>ae.getStatusForDirectory(m??null),e[0]=m,e[1]=v):v=e[1];const p=Es(v),F=Es(np),S=Es(ap),[N,h]=o.useState(null),[I,u]=o.useState(!1),[D,q]=o.useState(null),[M,P]=o.useState(null),[g,j]=o.useState(!1);let L;e[2]!==i?(L=i.filter(ip),e[2]=i,e[3]=L):L=e[3];const C=L;let A;e[4]!==i?(A=i.filter(rp),e[4]=i,e[5]=A):A=e[5];const b=A;let K,$;e[6]!==c?(K=()=>{c()},$=[c],e[6]=c,e[7]=K,e[8]=$):(K=e[7],$=e[8]),o.useEffect(K,$);let k;e[9]!==m||e[10]!==S||e[11]!==g||e[12]!==F?(k=()=>{if(g)return;j(!0);const ae=new Promise(op);Promise.all([F({directory:m,silent:!0}),ae]).then(()=>{const _e=S(m);_e&&R.error(_e)}).finally(()=>{j(!1)})},e[9]=m,e[10]=S,e[11]=g,e[12]=F,e[13]=k):k=e[13];const W=k;let Z;e[14]!==i||e[15]!==a||e[16]!==f||e[17]!==l?(Z=()=>{let ae="new-mcp-server",_e=1;for(;i.some(G=>G.name===ae);)ae=`new-mcp-server-${_e}`,_e++;f({name:ae,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),l(ae),a?.()},e[14]=i,e[15]=a,e[16]=f,e[17]=l,e[18]=Z):Z=e[18];const B=Z;let Q;e[19]!==y||e[20]!==N||e[21]!==n?(Q=async()=>{if(!N)return;u(!0);const ae=await y(N.name);ae.ok?ae.reloadFailed?R.warning(ae.message||`MCP server "${N.name}" deleted, but OpenCode reload failed`,{description:ae.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):R.success(ae.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:N.name})):R.error(n("settings.mcp.sidebar.toast.deleteFailed")),h(null),u(!1)},e[19]=y,e[20]=N,e[21]=n,e[22]=Q):Q=e[22];const w=Q;let X;e[23]!==n?(X=(ae,_e)=>s.jsxs(_e,{onClick:Ze=>{Ze.stopPropagation(),h(ae)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[23]=n,e[24]=X):X=e[24];const ee=X;let T;e[25]===Symbol.for("react.memo_cache_sentinel")?(T=ye("flex h-full flex-col","bg-background"),e[25]=T):T=e[25];let O;e[26]!==n?(O=n("settings.mcp.sidebar.title"),e[26]=n,e[27]=O):O=e[27];let V;e[28]!==O?(V=s.jsx("h2",{className:Ws,children:O}),e[28]=O,e[29]=V):V=e[29];let E;e[30]!==n?(E=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[30]=n,e[31]=E):E=e[31];let _;e[32]!==n?(_=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[32]=n,e[33]=_):_=e[33];const J=g&&"animate-spin";let te;e[34]!==J?(te=ye("h-4 w-4",J),e[34]=J,e[35]=te):te=e[35];let ne;e[36]!==te?(ne=s.jsx(z,{name:"refresh",className:te}),e[36]=te,e[37]=ne):ne=e[37];let le;e[38]!==W||e[39]!==g||e[40]!==E||e[41]!==_||e[42]!==ne?(le=s.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:W,"aria-label":E,title:_,children:ne}),e[38]=W,e[39]=g,e[40]=E,e[41]=_,e[42]=ne,e[43]=le):le=e[43];let be;e[44]!==V||e[45]!==le?(be=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[V,le]}),e[44]=V,e[45]=le,e[46]=be):be=e[46];let Ne;e[47]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx(Ca,{className:"mb-3"}),e[47]=Ne):Ne=e[47];let de;e[48]!==i.length||e[49]!==n?(de=n("settings.mcp.sidebar.total",{count:i.length}),e[48]=i.length,e[49]=n,e[50]=de):de=e[50];let ue;e[51]!==de?(ue=s.jsx("span",{className:"typography-meta text-muted-foreground",children:de}),e[51]=de,e[52]=ue):ue=e[52];let Me;e[53]!==n?(Me=n("settings.mcp.sidebar.actions.addServerTitle"),e[53]=n,e[54]=Me):Me=e[54];let Ce;e[55]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[55]=Ce):Ce=e[55];let ke;e[56]!==B||e[57]!==Me?(ke=s.jsx(H,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:B,title:Me,children:Ce}),e[56]=B,e[57]=Me,e[58]=ke):ke=e[58];let fe;e[59]!==ue||e[60]!==ke?(fe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ue,ke]}),e[59]=ue,e[60]=ke,e[61]=fe):fe=e[61];let ze;e[62]!==be||e[63]!==fe?(ze=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[be,Ne,fe]}),e[62]=be,e[63]=fe,e[64]=ze):ze=e[64];let Ae;e[65]!==i.length||e[66]!==p||e[67]!==a||e[68]!==D||e[69]!==C||e[70]!==ee||e[71]!==M||e[72]!==r||e[73]!==f||e[74]!==l||e[75]!==n||e[76]!==b?(Ae=s.jsx(Ms,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:i.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[C.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.projectServers")}),C.map(ae=>{const _e=p[ae.name],Ze=_r(_e?.status),G=r===ae.name,Fe=wa();return s.jsxs(Ln,{open:M===ae.name,onOpenChange:Ye=>P(Ye?ae.name:null),children:[s.jsxs(On,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",G?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Fe?void 0:Ye=>{Ye.preventDefault(),P(ae.name)}}),children:[s.jsxs("button",{onClick:()=>{l(ae.name),f(null),a?.()},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:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vr,{tone:Ze,enabled:ae.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ae.name}),s.jsx("span",{title:ae.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:ae.type==="local"?s.jsx(z,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(z,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ae.type==="local"?ae.command?.join(" ")??"":ae.url??""})]}),s.jsxs(Gs,{open:D===ae.name,onOpenChange:Ye=>{Ye&&P(null),q(Ye?ae.name:null)},children:[s.jsx(Bs,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Hs,{align:"end",className:"w-fit min-w-20",children:ee(ae,qs)})]})]}),s.jsx(Mn,{className:"w-fit min-w-20",children:ee(ae,Rn)})]},ae.name)})]}),b.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.userServers")}),b.map(ae=>{const _e=p[ae.name],Ze=_r(_e?.status),G=r===ae.name,Fe=wa();return s.jsxs(Ln,{open:M===ae.name,onOpenChange:Ye=>P(Ye?ae.name:null),children:[s.jsxs(On,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",G?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Fe?void 0:Ye=>{Ye.preventDefault(),P(ae.name)}}),children:[s.jsxs("button",{onClick:()=>{l(ae.name),f(null),a?.()},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:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vr,{tone:Ze,enabled:ae.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ae.name}),s.jsx("span",{title:ae.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:ae.type==="local"?s.jsx(z,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(z,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ae.type==="local"?ae.command?.join(" ")??"":ae.url??""})]}),s.jsxs(Gs,{open:D===ae.name,onOpenChange:Ye=>{Ye&&P(null),q(Ye?ae.name:null)},children:[s.jsx(Bs,{asChild:!0,children:s.jsx(H,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Hs,{align:"end",className:"w-fit min-w-20",children:ee(ae,qs)})]})]}),s.jsx(Mn,{className:"w-fit min-w-20",children:ee(ae,Rn)})]},ae.name)})]})]})}),e[65]=i.length,e[66]=p,e[67]=a,e[68]=D,e[69]=C,e[70]=ee,e[71]=M,e[72]=r,e[73]=f,e[74]=l,e[75]=n,e[76]=b,e[77]=Ae):Ae=e[77];const he=N!==null;let ge;e[78]!==I?(ge=ae=>{!ae&&!I&&h(null)},e[78]=I,e[79]=ge):ge=e[79];let Ee;e[80]!==n?(Ee=n("settings.mcp.sidebar.deleteDialog.title"),e[80]=n,e[81]=Ee):Ee=e[81];let Te;e[82]!==Ee?(Te=s.jsx(Ht,{children:Ee}),e[82]=Ee,e[83]=Te):Te=e[83];const Qe=N?.name||"";let Be;e[84]!==n||e[85]!==Qe?(Be=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Qe}),e[84]=n,e[85]=Qe,e[86]=Be):Be=e[86];let Ke;e[87]===Symbol.for("react.memo_cache_sentinel")?(Ke=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[87]=Ke):Ke=e[87];let Ge;e[88]!==Be?(Ge=s.jsxs(Gt,{children:[Be," ",Ke,"."]}),e[88]=Be,e[89]=Ge):Ge=e[89];let qe;e[90]!==Te||e[91]!==Ge?(qe=s.jsxs(Bt,{children:[Te,Ge]}),e[90]=Te,e[91]=Ge,e[92]=qe):qe=e[92];let Ie;e[93]===Symbol.for("react.memo_cache_sentinel")?(Ie=()=>h(null),e[93]=Ie):Ie=e[93];let Re;e[94]!==n?(Re=n("settings.common.actions.cancel"),e[94]=n,e[95]=Re):Re=e[95];let $e;e[96]!==I||e[97]!==Re?($e=s.jsx(H,{size:"sm",variant:"ghost",onClick:Ie,disabled:I,children:Re}),e[96]=I,e[97]=Re,e[98]=$e):$e=e[98];let Ue;e[99]!==I||e[100]!==n?(Ue=n(I?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[99]=I,e[100]=n,e[101]=Ue):Ue=e[101];let je;e[102]!==w||e[103]!==I||e[104]!==Ue?(je=s.jsx(H,{size:"sm",onClick:w,disabled:I,children:Ue}),e[102]=w,e[103]=I,e[104]=Ue,e[105]=je):je=e[105];let U;e[106]!==$e||e[107]!==je?(U=s.jsxs(is,{children:[$e,je]}),e[106]=$e,e[107]=je,e[108]=U):U=e[108];let re;e[109]!==qe||e[110]!==U?(re=s.jsxs($t,{className:"max-w-md",children:[qe,U]}),e[109]=qe,e[110]=U,e[111]=re):re=e[111];let pe;e[112]!==he||e[113]!==ge||e[114]!==re?(pe=s.jsx(Vt,{open:he,onOpenChange:ge,children:re}),e[112]=he,e[113]=ge,e[114]=re,e[115]=pe):pe=e[115];let ve;return e[116]!==ze||e[117]!==Ae||e[118]!==pe?(ve=s.jsxs("div",{className:T,children:[ze,Ae,pe]}),e[116]=ze,e[117]=Ae,e[118]=pe,e[119]=ve):ve=e[119],ve};function tp(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function sp(t){return t.currentDirectory}function np(t){return t.refresh}function ap(t){return t.getErrorForDirectory}function ip(t){return t.scope==="project"}function rp(t){return t.scope!=="project"}function op(t){return setTimeout(t,500)}function Vs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ca(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function _s(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Ka(t,e,a){const n=lp(a),i=typeof a.url=="string"?a.url.trim():"",r=$r(a,"env","environment"),l=$r(a,"headers"),f=cp(a),c=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",y=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",m=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",v=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",p=dp(a),F=pp(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:f,oauthClientId:c,oauthClientSecret:y,oauthScope:m,oauthRedirectUri:v,timeout:p,enabled:F}}function lp(t){const e=t.command,a=t.args;if(ca(e)&&ca(a))return[...e,...a];if(ca(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return ca(a)?[...n,...a]:n}return ca(a)?a:[]}function $r(t,...e){for(const a of e){const n=t[a];if(!Vs(n))continue;const i=Object.entries(n).filter(([r,l])=>r&&typeof l=="string");if(i.length>0)return i.map(([r,l])=>({key:r,value:String(l)}))}return[]}function cp(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!Vs(t.oauth))return!1;const e=t.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 dp(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const a=Number(e);if(Number.isFinite(a)&&a>0)return String(Math.floor(a))}return""}function pp(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function mp(t){const e=t.mcpServers;if(Vs(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(Vs(r))return{name:i,entry:r}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const i=t[n];return n!=="mcpServers"&&Vs(i)});if(a.length===1){const n=a[0],i=t[n];if(tl(i))return{name:n,entry:i}}return null}function tl(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function up(t,e){let a;try{const f=t.trim();if(!f)return _s("No JSON content provided");a=JSON.parse(f)}catch(f){return _s(f instanceof Error?`Invalid JSON: ${f.message}`:"Invalid JSON")}if(!Vs(a))return _s("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(Vs(i)){const f=Object.keys(i);if(f.length===0)return _s("mcpServers object is empty",a);if(f.length>1)return _s("Paste one server at a time. Found "+f.length+" servers in mcpServers",a);const c=f[0],y=i[c];return Vs(y)?Ka(c,za(y),y):_s("Server entry is not a valid object",a)}const r=n.mcp;if(Vs(r)){const f=Object.keys(r);if(f.length===0)return _s("mcp object is empty",a);if(f.length>1)return _s("Paste one server at a time. Found "+f.length+" servers in mcp",a);const c=f[0],y=r[c];return Vs(y)?Ka(c,za(y),y):_s("Server entry in mcp is not a valid object",a)}const l=mp(n);if(l)return Ka(l.name,za(l.entry),l.entry);if(tl(n)){const f=za(n),c=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Ka(c,f,n)}return _s("No recognizable MCP server configuration found in JSON",a)}function za(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function gp(t,e,a){const n=a?.isNewServer??!1,i=t.name,r=n&&i?i:e.name??"";return{...e,name:r,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}function sl(t){const e=[];let a="",n=!1,i=!1;for(let r=0;r<t.length;r++){const l=t[r];if(l==="'"&&!i){n=!n;continue}if(l==='"'&&!n){i=!i;continue}if((l===" "||l===" ")&&!n&&!i){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function hp(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const a=new URL(e),n=a.searchParams.get("code");if(typeof n=="string"&&n.trim())return{code:n.trim(),context:Vl(a.searchParams),stateKey:Lo(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const fp=t=>{const e=ft.c(27),{value:a,onChange:n,preview:i,onDetectUrl:r}=t;let l;e[0]!==a?(l=()=>a.join(`
4
- `),e[0]=a,e[1]=l):l=e[1];const[f,c]=o.useState(l),y=o.useRef(a);let m,v;e[2]!==a?(m=()=>{JSON.stringify(y.current)!==JSON.stringify(a)&&(y.current=a,c(a.join(`
5
- `)))},v=[a],e[2]=a,e[3]=m,e[4]=v):(m=e[3],v=e[4]),o.useEffect(m,v);let p;e[5]!==n||e[6]!==r?(p=P=>{const g=P.split(`
6
- `).filter(Np);if(r&&g.length===1&&/^https?:\/\/\S+$/i.test(g[0].trim())){r(g[0].trim());return}n(g)},e[5]=n,e[6]=r,e[7]=p):p=e[7];const F=p;let S;e[8]!==n?(S=P=>{const j=P.clipboardData.getData("text").trim();if(!j||j.includes(`
7
- `)||!/\s/.test(j))return;const L=P.currentTarget;if(L.selectionStart!==0||L.selectionEnd!==L.value.length)return;P.preventDefault();const C=sl(j);c(C.join(`
8
- `)),n(C)},e[8]=n,e[9]=S):S=e[9];const N=S;let h;e[10]!==F?(h=P=>{c(P.target.value),F(P.target.value)},e[10]=F,e[11]=h):h=e[11];let I;e[12]!==F||e[13]!==f?(I=()=>{const P=f.split(`
9
- `).map(Sp).join(`
10
- `);c(P),F(P)},e[12]=F,e[13]=f,e[14]=I):I=e[14];const u=Math.max(4,a.length+1);let D;e[15]!==N||e[16]!==h||e[17]!==I||e[18]!==u||e[19]!==f?(D=s.jsx(Ns,{onPaste:N,value:f,onChange:h,onBlur:I,placeholder:`npx
11
- -y
12
- @modelcontextprotocol/server-postgres
13
- postgresql://user:pass@host/db`,rows:u,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=N,e[16]=h,e[17]=I,e[18]=u,e[19]=f,e[20]=D):D=e[20];let q;e[21]!==i||e[22]!==a?(q=a.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:i(a.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:a.map(Cp)})})]}),e[21]=i,e[22]=a,e[23]=q):q=e[23];let M;return e[24]!==q||e[25]!==D?(M=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[D,q]}),e[24]=q,e[25]=D,e[26]=M):M=e[26],M},xp=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),Br=({value:t,onChange:e,keyTransform:a=xp,keyPlaceholder:n="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:r="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:f,importSuccess:c,clipboardReadFailed:y,keyLabel:m,valueLabel:v,valuePlaceholder:p,hideValueTitle:F,showValueTitle:S,addVariable:N,plainTextWarning:h,removeVariableAria:I})=>{const[u,D]=o.useState(new Set),q=()=>e([...t,{key:"",value:""}]),M=C=>{e(t.filter((A,b)=>b!==C)),D(A=>{const b=new Set(A);return b.delete(C),b})},P=(C,A,b)=>{const K=[...t];K[C]={...K[C],[A]:b},e(K)},g=C=>{D(A=>{const b=new Set(A);return b.has(C)?b.delete(C):b.add(C),b})},j=async()=>{try{const C=await navigator.clipboard.readText(),A=[];for(const K of C.split(`
14
- `)){const $=K.trim();if(!$||$.startsWith("#"))continue;const k=$.indexOf("=");if(k===-1)continue;const W=$.slice(0,k).trim();let Z=$.slice(k+1).trim();(Z.startsWith('"')&&Z.endsWith('"')||Z.startsWith("'")&&Z.endsWith("'"))&&(Z=Z.slice(1,-1)),W&&A.push({key:W,value:Z})}if(A.length===0){R.error(f);return}const b=[...t];for(const K of A){const $=b.findIndex(k=>k.key===K.key);$!==-1?b[$]=K:b.push(K)}e(b),R.success(c(A.length))}catch{R.error(y)}},L=t.some(C=>C.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:v})]}),s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:j,type:"button",title:l,children:[s.jsx(z,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((C,A)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:C.key,onChange:b=>P(A,"key",a(b.target.value)),placeholder:n,className:i,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(He,{type:u.has(A)?"text":"password",value:C.value,onChange:b=>P(A,"value",b.target.value),placeholder:p,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>g(A),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:u.has(A)?F:S,children:u.has(A)?s.jsx(z,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>M(A),"aria-label":I,children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},A))}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:q,type:"button",children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),N]}),L&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:h})]})},ji=t=>{const e=ft.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let f,c;if(e[0]!==i||e[1]!==a||e[2]!==l){c=Symbol.for("react.early_return_sentinel");e:{const p={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},awaiting_restart:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const F=ye("typography-micro font-medium rounded-full px-2 py-0.5",p.text,p.bg);let S;e[5]!==i||e[6]!==a?(S=i(a),e[5]=i,e[6]=a,e[7]=S):S=e[7],c=s.jsxs("span",{className:F,children:["● ",S]});break e}f=ye("typography-micro font-medium",p.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=f,e[4]=c}else f=e[3],c=e[4];if(c!==Symbol.for("react.early_return_sentinel"))return c;let y;e[8]!==i||e[9]!==a?(y=i(a),e[8]=i,e[9]=a,e[10]=y):y=e[10];let m;return e[11]!==f||e[12]!==y?(m=s.jsxs("span",{className:f,children:["● ",y]}),e[11]=f,e[12]=y,e[13]=m):m=e[13],m},bp=(t,e,a)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return a?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return a?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},vp=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},yp=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),jp=async t=>{const e=await lt(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const a=await e.json().catch(()=>null);return a?.name?.trim()?{name:a.name.trim(),directory:typeof a.directory=="string"&&a.directory.trim()?a.directory.trim():null}:null},da=async t=>{typeof t!="string"||!t.trim()||await lt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Ua=(t,e,a)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?a("settings.mcp.page.toast.authSessionExpired"):n},wp=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},kp=()=>{const{t}=it(),e=o.useCallback((oe,ht)=>t(oe,ht),[t]),{selectedMcpName:a,mcpServers:n,mcpDraft:i,setMcpDraft:r,setSelectedMcp:l,getMcpByName:f,createMcp:c,updateMcp:y,deleteMcp:m}=Xa(Cs(oe=>({selectedMcpName:oe.selectedMcpName,mcpServers:oe.mcpServers,mcpDraft:oe.mcpDraft,setMcpDraft:oe.setMcpDraft,setSelectedMcp:oe.setSelectedMcp,getMcpByName:oe.getMcpByName,createMcp:oe.createMcp,updateMcp:oe.updateMcp,deleteMcp:oe.deleteMcp}))),v=$o(oe=>oe.currentDirectory),p=o.useMemo(()=>ps(),[]),F=Es(oe=>oe.getStatusForDirectory(v??null)),S=Es(oe=>oe.getDiagnosticForDirectory(v??null)),N=Es(oe=>oe.refresh),h=Es(oe=>oe.connect),I=Es(oe=>oe.disconnect),u=Es(oe=>oe.completeAuth),D=Es(oe=>oe.clearAuth),q=Es(oe=>oe.testConnection),M=ln(oe=>oe.changes),P=a?f(a):null,g=!!(i&&i.name===a&&!P),[j,L]=o.useState(""),[C,A]=o.useState("user"),[b,K]=o.useState("local"),[$,k]=o.useState([]),[W,Z]=o.useState(""),[B,Q]=o.useState([]),[w,X]=o.useState([]),[ee,T]=o.useState(!0),[O,V]=o.useState(""),[E,_]=o.useState(""),[J,te]=o.useState(""),[ne,le]=o.useState(""),[be,Ne]=o.useState(""),[de,ue]=o.useState(!0),[Me,Ce]=o.useState(!1),[ke,fe]=o.useState(!1),[ze,Ae]=o.useState(!1),[he,ge]=o.useState(!1),[Ee,Te]=o.useState(!1),[Qe,Be]=o.useState(!1),[Ke,Ge]=o.useState(!1),[qe,Ie]=o.useState(!1),[Re,$e]=o.useState(null),[Ue,je]=o.useState(null),[U,re]=o.useState(""),[pe,ve]=o.useState(!1),ae=o.useRef(0),_e=o.useRef(!1),[Ze,G]=o.useState(!1),[Fe,Ye]=o.useState(!1),[st,et]=o.useState(""),[wt,pt]=o.useState(null),mt=o.useMemo(()=>wp(a,v),[v,a]),ot=o.useRef(mt),bt=o.useRef(null),ut=o.useCallback(()=>{$e(null),je(null),re(""),ve(!1),ae.current=0,Ie(!1),Te(!1),Be(!1),_e.current=!1},[]),At=o.useCallback(()=>{et(""),pt(null),Ye(!0)},[]),ie=o.useCallback(async()=>{try{const oe=await navigator.clipboard.readText();et(oe),pt(null)}catch{R.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Pe=o.useCallback(()=>{const oe=up(st,{fallbackName:j});if(!oe.ok){pt(oe.error);return}const Se=gp(oe,{name:j,scope:C,type:b,command:$,url:W,environment:B,headers:w,oauthEnabled:ee,oauthClientId:O,oauthClientSecret:E,oauthScope:J,oauthRedirectUri:ne,timeout:be,enabled:de},{isNewServer:g});L(Se.name),K(Se.type),k(Se.command??[]),Z(Se.url??""),Q(Se.environment??[]),X(Se.headers??[]),T(Se.oauthEnabled??!1),V(Se.oauthClientId??""),_(Se.oauthClientSecret??""),te(Se.oauthScope??""),le(Se.oauthRedirectUri??""),Ne(Se.timeout??""),ue(Se.enabled??!0),Ye(!1),et(""),pt(null),R.success(t("settings.mcp.page.toast.configImported"))},[st,j,C,b,$,W,B,w,ee,O,E,J,ne,be,de,g,t]);o.useEffect(()=>{if(g&&i){L(i.name),A(i.scope||"user"),K(i.type),k(i.command),Z(i.url),Q(i.environment),X(i.headers),T(i.oauthEnabled),V(i.oauthClientId),_(i.oauthClientSecret),te(i.oauthScope),le(i.oauthRedirectUri),Ne(i.timeout),ue(i.enabled),G(!1),bt.current={mcpType:i.type,command:i.command,url:i.url,envEntries:i.environment,headerEntries:i.headers,oauthEnabled:i.oauthEnabled,oauthClientId:i.oauthClientId,oauthClientSecret:i.oauthClientSecret,oauthScope:i.oauthScope,oauthRedirectUri:i.oauthRedirectUri,timeout:i.timeout,enabled:i.enabled};return}if(P){A(P.scope==="project"?"project":"user");const oe=cr(P.environment),ht=P.type==="remote"?P:null,Se=cr(ht?.headers),nt=ht?.oauth,xt=nt&&typeof nt=="object"?nt:null,It=nt!==!1,Kt=P.type,hs=Kt==="local"?P.command??[]:[],Ps=Kt==="remote"?P.url??"":"",fs=typeof ht?.timeout=="number"&&Number.isFinite(ht.timeout)?String(ht.timeout):"";K(Kt),k(hs),Z(Ps),Q(oe),X(Se),T(It),V(It?xt?.clientId??"":""),_(It?xt?.clientSecret??"":""),te(It?xt?.scope??"":""),le(It?xt?.redirectUri??"":""),Ne(fs),ue(P.enabled),G(!1),bt.current={mcpType:Kt,command:hs,url:Ps,envEntries:oe,headerEntries:Se,oauthEnabled:It,oauthClientId:It?xt?.clientId??"":"",oauthClientSecret:It?xt?.clientSecret??"":"",oauthScope:It?xt?.scope??"":"",oauthRedirectUri:It?xt?.redirectUri??"":"",timeout:fs,enabled:P.enabled}}},[P,g,i]);const Ve=o.useMemo(()=>{const oe=bt.current;return oe?b!==oe.mcpType||de!==oe.enabled||JSON.stringify($)!==JSON.stringify(oe.command)||W!==oe.url||JSON.stringify(B)!==JSON.stringify(oe.envEntries)||JSON.stringify(w)!==JSON.stringify(oe.headerEntries)||ee!==oe.oauthEnabled||O!==oe.oauthClientId||E!==oe.oauthClientSecret||J!==oe.oauthScope||ne!==oe.oauthRedirectUri||be!==oe.timeout:!1},[b,$,W,B,w,ee,O,E,J,ne,be,de]),We=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(z,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(z,{name:"global",className:"h-3.5 w-3.5"})}],[t]),kt=o.useCallback(oe=>{K("remote"),Z(oe),k([])},[]),St=o.useCallback(oe=>{Z(oe);const ht=oe.trim();ht&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ht)&&/\s/.test(ht)&&(K("local"),k(sl(ht)),Z(""))},[]),Wt=async()=>{const oe=g?j.trim():a??"";if(!oe){R.error(t("settings.mcp.page.toast.nameRequired"));return}if(g&&n.some(Se=>Se.name===oe)){R.error(t("settings.mcp.page.toast.serverNameExists"));return}if(b==="local"&&$.filter(Boolean).length===0){R.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(b==="remote"&&!W.trim()){R.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ht={name:oe,scope:C,type:b,command:$,url:W,environment:B,headers:w,oauthEnabled:ee,oauthClientId:O,oauthClientSecret:E,oauthScope:J,oauthRedirectUri:ne,timeout:be,enabled:de};Ce(!0);try{const Se=g?await c(ht):await y(oe,ht);Se.ok?(await da(Ue),ut(),g&&(r(null),l(oe)),await N({directory:v,silent:!0}),Se.reloadFailed?R.warning(Se.message||t(g?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Se.warning||t("settings.mcp.page.toast.retryRefreshHint")}):Se.restartDeferred?R.success(t("settings.view.pendingRestart.saved")):R.success(Se.message||t(g?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):R.error(t("settings.mcp.page.toast.saveFailed"))}catch(Se){R.error(Se instanceof Error?Se.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Ce(!1)}},Y=async()=>{if(!a)return;Ae(!0);const oe=await m(a);oe.ok?(await da(Ue),ut(),oe.reloadFailed?R.warning(oe.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:oe.warning||t("settings.mcp.page.toast.refreshListIfStale")}):R.success(oe.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),fe(!1)):R.error(t("settings.mcp.page.toast.deleteFailed")),Ae(!1)},xe=async()=>{if(a){ge(!0);try{if(F[a]?.status==="connected")await I(a,v),R.success(t("settings.mcp.page.toast.disconnected"));else{await h(a,v),await N({directory:v,silent:!0});const ht=Es.getState().getStatusForDirectory(v??null)[a];ht?.status==="connected"?R.success(t("settings.mcp.page.toast.connected")):ht?.status==="needs_auth"?R.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ht?.status==="needs_client_registration"?R.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ht?.status==="failed"?R.error(ht.error||t("settings.mcp.page.toast.connectionFailed")):R.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await N({directory:v,silent:!0})}catch(oe){R.error(oe instanceof Error?oe.message:t("settings.mcp.page.toast.connectionFailed"))}finally{ge(!1)}}},Oe=o.useCallback(()=>g?(R.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):Ve?(R.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[Ve,g,t]),we=o.useCallback(async(oe=!1)=>{try{await N({directory:v,silent:oe})}catch(ht){oe||R.error(ht instanceof Error?ht.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[v,N,t]);o.useEffect(()=>{we(!0)},[we]),o.useEffect(()=>{ot.current=mt,ge(!1),Ge(!1),ut()},[ut,mt]);const rt=o.useCallback(async()=>{if(!a||b!=="remote"||!Oe())return;Te(!0);const oe=mt;let ht=null;try{const Se=Es.getState().getStatusForDirectory(v??null)[a]?.status;_e.current=Se==="needs_auth"||Se==="needs_client_registration";const{authorizationUrl:nt,opened:xt,nativeFlow:It,completion:Kt}=await Ul({name:a,directory:v});if(It){if(ot.current!==oe)return;$e(null),je(null),ve(!0),ae.current=0,R.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),Kt?.then(()=>{ot.current===oe&&(ve(!1),ae.current=0,_e.current=!1,R.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(Ps=>{ot.current===oe&&(ve(!1),ae.current=0,_e.current=!1,R.error(Ua(Ps,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const hs=Lo(new URL(nt).searchParams);if(ht=hs,ot.current!==oe||($e(nt),je(hs??null),ve(!0),ae.current=0,ot.current!==oe))return;xt?R.message(t(p?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):R.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Se){await da(ht),ot.current===oe&&R.error(Ua(Se,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{ot.current===oe&&Te(!1)}},[v,p,b,Oe,mt,a,t,e]),ct=o.useCallback(async()=>{if(!a||!Oe())return;Be(!0);const oe=mt;try{if(await D(a,v),ot.current!==oe)return;$e(null),je(null),re(""),ve(!1),ae.current=0,await da(Ue),R.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(ht){ot.current===oe&&R.error(Ua(ht,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{ot.current===oe&&Be(!1)}},[Ue,D,v,Oe,mt,a,t,e]),at=o.useCallback(async()=>{if(!Re)return;if((await va(Re)).ok){R.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}R.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Re,t]),Ct=o.useCallback(async()=>{const oe=hp(U);if(!oe.code){R.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ht=oe.stateKey?await jp(oe.stateKey):null,Se=oe.context??ht,nt=Se?.name??a,xt=Se?.directory??v;if(!nt){R.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Se&&!Oe())return;Ie(!0);const It=mt;try{if(await u(nt,oe.code,xt),await da(oe.stateKey??Ue),ot.current!==It)return;re(""),$e(null),je(null),ve(!1),ae.current=0,R.success(nt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:nt}))}catch(Kt){ot.current===It&&R.error(Ua(Kt,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{ot.current===It&&Ie(!1)}},[U,Ue,u,v,Oe,mt,a,t,e]),ss=o.useCallback(async()=>{if(!(!a||!Oe())){if(!de){R.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Ge(!0);try{const oe=await q(a,v),ht=oe.status?.status;oe.warning?R.warning(oe.warning):ht==="connected"?R.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ht==="needs_auth"?R.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ht==="needs_client_registration"?R.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ht==="failed"?R.error(oe.status?.error||oe.error||t("settings.mcp.page.toast.connectionTestFailed")):oe.error?R.error(oe.error):R.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(oe){R.error(oe instanceof Error?oe.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Ge(!1)}}},[v,de,Oe,a,t,q]);if(o.useEffect(()=>{if(!pe||!a)return;const oe=window.setInterval(()=>{(async()=>{ae.current+=1,await N({directory:v,silent:!0});const ht=Es.getState().getStatusForDirectory(v??null)[a];if(ht){if(_e.current&&ht.status!=="needs_auth"&&ht.status!=="needs_client_registration"){ve(!1),ae.current=0,_e.current=!1,$e(null),re(""),ht.status==="connected"&&R.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!_e.current&&ht.status==="failed"){ve(!1),ae.current=0,_e.current=!1,R.error(ht.error||t("settings.mcp.page.toast.authorizationFailed"));return}ae.current>=30&&(ve(!1),ae.current=0,_e.current=!1,R.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(oe)}},[v,pe,N,a,t]),!a)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const es=F[a],ds=a?S[a]:void 0,Jt=es??ds,Nt=!g&&!Jt&&M.some(oe=>oe.scope==="mcp"&&oe.id.startsWith(`mcp:${a}:`)),Pt=es?.status==="connected",Et=es?.status==="needs_auth"||es?.status==="needs_client_registration",yt=p||!a?null:_l(a),zt=async()=>{if(yt)try{await navigator.clipboard.writeText(yt),R.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{R.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},Zt=bp(Jt?.status,e,Jt&&"error"in Jt?Jt.error:void 0),js=oe=>{switch(oe){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");case"awaiting_restart":return t("settings.mcp.page.status.label.awaitingRestart");default:return oe}};return s.jsxs(s.Fragment,{children:[s.jsxs(as,{title:g?t("settings.mcp.page.header.newServer"):a,titleAccessory:g?void 0:s.jsx(ji,{status:Nt?"awaiting_restart":Jt?.status,enabled:de,getStatusLabel:js,variant:"pill"}),description:g?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(b==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!g&&!Nt?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{variant:Pt?"outline":"default",size:"xs",className:"!font-normal",onClick:xe,disabled:he||!de,children:t(he?"settings.mcp.page.actions.working":Pt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),b==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(H,{variant:Et?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{rt()},disabled:Ee||!de,children:t(Ee?"settings.mcp.page.actions.starting":Pt?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ct()},disabled:Qe||!de,children:t(Qe?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Pt&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ss()},disabled:Ke||!de,children:t(Ke?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[Nt&&s.jsx(Le,{divider:!1,children:s.jsx("div",{className:"rounded-lg border p-3 border-[var(--status-warning-border)] bg-[var(--status-warning-background)]",children:s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Dt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(ji,{status:"awaiting_restart",enabled:de,getStatusLabel:js})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!g&&!Nt&&yp(Jt?.status,Re,Et,pe)&&s.jsx(Le,{divider:!1,children:s.jsxs("div",{className:ye("rounded-lg border p-3",vp(Jt?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Dt,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(ji,{status:Jt?.status,enabled:de,getStatusLabel:js})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:Zt}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:C==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:v??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Pt&&s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ss()},disabled:Ke||!de,children:t(Ke?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Jt?.status==="needs_client_registration"&&s.jsxs("div",{className:"space-y-3 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:[s.jsxs("div",{children:[s.jsx($s,{as:"div",children:t("settings.mcp.page.registration.title")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.description")})]}),yt&&s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.callbackLabel")}),s.jsxs("div",{className:"mt-1 flex items-start gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 break-all font-mono typography-micro text-foreground/80",children:yt}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{zt()},children:[s.jsx(z,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]}),s.jsxs("div",{className:"grid gap-3 @xl:grid-cols-2",children:[s.jsx(Qt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(He,{value:O,onChange:oe=>{V(oe.target.value),T(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(Qt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(He,{type:"password",value:E,onChange:oe=>{_(oe.target.value),T(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.afterSaving")})]}),Re&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:Re}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nn(Re)},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{at()},children:[s.jsx(z,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),p&&b==="remote"&&(Et||pe||Re)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx($s,{as:"div",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(Ns,{value:U,onChange:oe=>re(oe.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ct()},disabled:qe,children:t(qe?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),pe&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs(Le,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:g?s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:At,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(z,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[g&&s.jsxs(qt,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(He,{value:j,onChange:oe=>L(oe.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 min-w-0 max-w-full shrink font-mono px-2",autoFocus:!0}),s.jsxs(Mt,{value:C,onValueChange:oe=>A(oe),children:[s.jsxs(Rt,{size:Ut,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(z,{name:C==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(C==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Ot,{align:"end",children:[s.jsx(dt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(dt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(gt,{checked:de,onChange:ue,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(Le,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(tr,{items:We,activeId:b,onSelect:oe=>K(oe),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),b==="local"?s.jsx(fp,{value:$,onChange:k,preview:oe=>t("settings.mcp.page.connection.previewArgs",{count:oe}),onDetectUrl:kt}):s.jsx(He,{value:W,onChange:oe=>St(oe.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(b==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),b==="remote"&&s.jsx(Le,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(Yn,{open:Ze,onOpenChange:G,children:[s.jsxs(Zn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",w.length," ",t("settings.mcp.page.advanced.headers"),be?` · ${be}ms`:"",")"]})]}),Ze?s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Xn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("div",{className:"space-y-2",children:s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Dt,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Yt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(He,{type:"number",min:"1",step:"1",value:be,onChange:oe=>Ne(oe.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]})}),s.jsxs("div",{children:[s.jsxs($s,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),w.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",w.length,")"]})]}),s.jsx(Br,{value:w,onChange:X,keyTransform:oe=>oe.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:oe=>t("settings.mcp.page.toast.importedVariablesCount",{count:oe}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]})]})})]})}),s.jsx(Le,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:B.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",B.length,")"]}):null,settingsItem:"mcp.environment",children:B.length===0?s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Q([{key:"",value:""}]),children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(Br,{value:B,onChange:Q,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:oe=>t("settings.mcp.page.toast.importedVariablesCount",{count:oe}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(H,{onClick:Wt,disabled:Me||!Ve&&!g,size:"xs",className:"!font-normal",children:t(Me?"settings.common.actions.saving":g?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!g&&s.jsx(H,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>fe(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Vt,{open:Fe,onOpenChange:oe=>{oe||(Ye(!1),et(""),pt(null))},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Gt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Ns,{value:st,onChange:oe=>{et(oe.target.value),pt(null)},placeholder:`{
15
- "mcpServers": {
16
- "postgres": {
17
- "command": "npx",
18
- "args": ["-y", "@modelcontextprotocol/server-postgres"]
19
- }
20
- }
21
- }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),wt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:wt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:ie,type:"button",children:[s.jsx(z,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(is,{children:[s.jsx(H,{variant:"outline",onClick:()=>{Ye(!1),et(""),pt(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{onClick:Pe,disabled:!st.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Vt,{open:ke,onOpenChange:oe=>{!oe&&!ze&&fe(!1)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Gt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(is,{children:[s.jsx(H,{variant:"outline",onClick:()=>fe(!1),disabled:ze,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{variant:"destructive",size:"sm",onClick:Y,disabled:ze,children:t(ze?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function Np(t){return t.trim().length>0}function Sp(t){return t.trimEnd()}function Cp(t,e){return s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",e,"]"]}),t]},e)}const Ha=()=>{try{const e=Ks.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=on.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},Pp=800,Ip=5e3,Ap="__default__",Vi=new Map,wi=new Map,Ep=1500,nl=t=>t?.trim()||Ap,Tp=t=>{Vi.delete(nl(t))},ls=Qo()(ld(cd((t,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:a=>t({selectedId:a}),setDraft:a=>t({draft:a}),loadPlugins:async a=>{const n=Ha(),i=nl(n),r=Date.now(),l=Vi.get(i)??0,f=e().entries.length>0||e().files.length>0;if(!a?.force&&f&&r-l<Ip)return!0;const c=wi.get(i);if(!a?.force&&c)return c;const y=(async()=>{t({isLoading:!0});try{const m=await lt(un("/api/config/plugins",n),{headers:pa(n)});if(!m.ok)throw new Error("Failed to load plugins");const v=await Ga(m);return t({entries:v.entries??[],files:v.files??[],isLoading:!1}),Vi.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(m){return console.error("[PluginsStore] Failed to load plugins:",m),t({isLoading:!1}),!1}})();wi.set(i,y);try{return await y}finally{wi.delete(i)}},loadRegistryInfo:async a=>{const n=Mp(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=Ha(),r={...e().registryInfo};for(const l of Rp(n)){const f=await lt(Dp(l,a?.force===!0,i),{headers:pa(i)});if(!f.ok)throw new Error("Failed to load plugin registry info");const c=await Ga(f);for(const y of c.results??[])r[y.spec]=y}return t({registryInfo:r,isLoadingRegistry:!1}),!0}catch(i){return console.error("[PluginsStore] Failed to load plugin registry info:",i),t({isLoadingRegistry:!1}),!1}},updateToLatest:async a=>{const n=e().entries.find(r=>r.id===a);if(!n)return{ok:!1};const i=e().registryInfo[n.spec];return!i||i.kind!=="npm-ok"||!i.hasUpdate||!i.latestVersion?{ok:!1}:await e().updateEntry(a,{spec:`${i.name}@${i.latestVersion}`})},createEntry:async a=>{const n=await Hn("Creating plugin entry…",async i=>await lt(un("/api/config/plugins/entry",i),{method:"POST",headers:_a(i),body:JSON.stringify(Hr(a))}),e,{restartId:a.spec});return n.ok&&e().loadRegistryInfo({specs:[a.spec],force:!0}),n},updateEntry:async(a,n)=>{const i=e().entries.find(f=>f.id===a)?.spec,r=n.spec??i,l=await Hn("Updating plugin entry…",async f=>await lt(un(`/api/config/plugins/entry/${encodeURIComponent(a)}`,f),{method:"PATCH",headers:_a(f),body:JSON.stringify(Hr(n))}),e,{restartId:a});return l.ok&&r&&e().loadRegistryInfo({specs:[r],force:!0}),l},deleteEntry:async a=>{const n=e().entries.find(r=>r.id===a),i=await Hn("Deleting plugin entry…",async r=>await lt(un(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:pa(r)}),e,{restartId:a});if(i.ok&&e().selectedId===a&&t({selectedId:null}),i.ok&&n){const r={...e().registryInfo};delete r[n.spec],t({registryInfo:r})}return i},readFile:async a=>{try{const n=Ha(),i=await lt(un(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:pa(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await Ga(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>Hn("Creating plugin file…",async n=>await lt(un("/api/config/plugins/file",n),{method:"POST",headers:_a(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>Hn("Updating plugin file…",async i=>await lt(un(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:_a(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await Hn("Deleting plugin file…",async i=>await lt(un(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:pa(i)}),e,{restartId:a});return n.ok&&e().selectedId===a&&t({selectedId:null}),n},getById:a=>e().entries.find(n=>n.id===a)??e().files.find(n=>n.id===a)}),{name:"plugins-store",storage:Ec(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function un(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function Dp(t,e,a){const n=new URLSearchParams;e&&n.set("refresh","true"),a&&n.set("directory",a);const i=n.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${i?`&${i}`:""}`}function Mp(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function Rp(t){const e=[];let a=[],n=0;for(const i of t){const r=encodeURIComponent(i),l=a.length===0?r.length:n+1+r.length;a.length>0&&l>Ep?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function pa(t){return t?{"x-opencode-directory":t}:void 0}function _a(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function Hr(t){const e={};return t.spec!==void 0&&(e.spec=t.spec),t.options!==void 0&&(e.options=t.options),t.scope!==void 0&&(e.scope=t.scope),e}async function Hn(t,e,a,n){try{const i=Ha(),r=await e(i),l=await Ga(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return Tp(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):Ja(l,"plugins",{id:n?.restartId})?(await a().loadPlugins({force:!0}),{ok:!0,restartDeferred:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):(l?.requiresReload&&($l(t),await Bl({message:l.message,delayMs:l.reloadDelayMs??Pp,scopes:["all"]})),await a().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning})}catch(i){return console.error("[PluginsStore] Failed to update plugin configuration:",i),{ok:!1}}}async function Ga(t){return await t.json()}const Op=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function Lp(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}const Fp=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=it(),i=ls(k=>k.createEntry),r=ls(k=>k.createFile),[l,f]=o.useState("npm"),[c,y]=o.useState(""),[m,v]=o.useState(""),[p,F]=o.useState(""),[S,N]=o.useState(""),[h,I]=o.useState(a),[u,D]=o.useState(!1),q=o.useCallback(()=>{y(""),v(""),F(""),N(""),I(a)},[a]);o.useEffect(()=>{t&&(f("npm"),q())},[t,q]);const M=k=>{k!==l&&(f(k),q())},P=o.useMemo(()=>Lp(m),[m]),g=!P.ok,j=l==="file"&&p.trim()!==""&&!Op.test(p.trim()),L=(l==="npm"||l==="path")&&c.trim()==="",C=l==="file"&&S.trim()==="",A=l==="file"&&p.trim()==="",b=u||g||l==="npm"&&L||l==="path"&&L||l==="file"&&(A||j||C),K=async()=>{if(!b){D(!0);try{let k;l==="file"?k=await r({fileName:p.trim(),content:S,scope:h}):k=await i({spec:c.trim(),options:P.ok?P.value:void 0,scope:h}),k.ok?(k.restartDeferred?R.success(n("settings.view.pendingRestart.saved")):R.success(k.message||n("settings.plugins.toast.created")),k.reloadFailed&&R.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):R.error(k.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{D(!1)}}},$=o.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(Vt,{open:t,onOpenChange:k=>{!k&&u||e(k)},children:s.jsxs($t,{className:"max-w-xl",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Gt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(tr,{items:$,activeId:l,onSelect:k=>M(k),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.spec")}),s.jsx(He,{id:"plugin-spec",value:c,onChange:k=>y(k.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":L?!1:void 0,disabled:u}),L&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.options")}),s.jsx(Ns,{id:"plugin-options",value:m,onChange:k=>v(k.target.value),rows:5,className:"font-mono",hasError:g,disabled:u}),g&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(He,{id:"plugin-filename",value:p,onChange:k=>F(k.target.value),placeholder:"my-plugin.ts","aria-invalid":j||void 0,disabled:u}),j&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.content")}),s.jsx(Ns,{id:"plugin-content",value:S,onChange:k=>N(k.target.value),rows:16,className:"font-mono",disabled:u})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(k=>{const W=h===k,Z=n(k==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>I(k),disabled:u,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(Yi,{checked:W,onChange:()=>I(k),ariaLabel:Z}),s.jsx("span",{className:ye("typography-ui-label font-normal",W?"text-foreground":"text-foreground/60"),children:Z})]},k)})})]})]}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:u,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(H,{size:"sm",onClick:()=>{K()},disabled:b,children:[u?s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},Kp=t=>{const e=ft.c(33),{spec:a}=t;let n;e[0]!==a?(n=f=>f.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=ls(n),{t:r}=it();if(!i)return null;const l=zp;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=f):f=e[2];let c;e[3]!==i.latestVersion?(c=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[f,i.latestVersion]}),e[3]=i.latestVersion,e[4]=c):c=e[4];let y;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==c?(y=l(c,r("settings.plugins.registry.badge.update.tooltip",{current:i.currentVersion??"",latest:i.latestVersion})),e[5]=i.currentVersion,e[6]=i.latestVersion,e[7]=r,e[8]=c,e[9]=y):y=e[9],y}case"npm-missing-version":{let f;e[10]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=f):f=e[10];let c;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(c=l(f,r("settings.plugins.registry.badge.missingVersion.tooltip",{version:i.currentVersion,name:i.name})),e[11]=i.currentVersion,e[12]=i.name,e[13]=r,e[14]=c):c=e[14],c}case"npm-missing-package":{let f;e[15]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=f):f=e[15];let c;return e[16]!==i.name||e[17]!==r?(c=l(f,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=c):c=e[18],c}case"npm-malformed":{let f;e[19]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=f):f=e[19];let c;return e[20]!==r?(c=l(f,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=c):c=e[21],c}case"npm-network":{let f;e[22]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=f):f=e[22];let c;return e[23]!==r?(c=l(f,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=c):c=e[24],c}case"path-missing":{let f;e[25]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=f):f=e[25];let c;return e[26]!==i.absolutePath||e[27]!==r?(c=l(f,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=c):c=e[28],c}case"path-unreadable":{let f;e[29]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(z,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=f):f=e[29];let c;return e[30]!==i.absolutePath||e[31]!==r?(c=l(f,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=c):c=e[32],c}case"path-ok":return null;default:return null}};function zp(t,e){return s.jsxs(Zi,{children:[s.jsx(Xi,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(Fo,{children:e})]})}const al=t=>{const e=ft.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,f=l===void 0?"sidebar":l,c=ps(),y=o.useRef(null),[m,v]=o.useState(!1),[p,F]=o.useState(!1),S=f==="background"||c?"bg-background":"bg-sidebar",N=S==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const b=y.current;if(!b){v(!1),F(!1);return}if(!(b.scrollHeight>b.clientHeight+1)){v(!1),F(!1);return}v(b.scrollTop>1),F(b.scrollTop+b.clientHeight<b.scrollHeight-1)},e[0]=h):h=e[0];const I=h;let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{I()},e[1]=u):u=e[1];let D;e[2]!==i?(D=[i,I],e[2]=i,e[3]=D):D=e[3],o.useEffect(u,D);let q,M;e[4]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{const b=y.current;if(!b)return;const K=()=>I();return b.addEventListener("scroll",K,{passive:!0}),()=>b.removeEventListener("scroll",K)},M=[I],e[4]=q,e[5]=M):(q=e[4],M=e[5]),o.useEffect(q,M);let P;e[6]!==S||e[7]!==r?(P=ye("flex h-full flex-col",S,r),e[6]=S,e[7]=r,e[8]=P):P=e[8];let g;e[9]!==i?(g=s.jsx(Ms,{ref:y,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=g):g=e[10];let j;e[11]!==N||e[12]!==m?(j=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${N} 0%, transparent 100%)`}}),e[11]=N,e[12]=m,e[13]=j):j=e[13];let L;e[14]!==N||e[15]!==p?(L=p&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${N} 0%, transparent 100%)`}}),e[14]=N,e[15]=p,e[16]=L):L=e[16];let C;e[17]!==L||e[18]!==g||e[19]!==j?(C=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[g,j,L]}),e[17]=L,e[18]=g,e[19]=j,e[20]=C):C=e[20];let A;return e[21]!==n||e[22]!==a||e[23]!==C||e[24]!==P?(A=s.jsxs("div",{className:P,children:[a,C,n]}),e[21]=n,e[22]=a,e[23]=C,e[24]=P,e[25]=A):A=e[25],A},$i=t=>{const e=ft.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:f,className:c}=t,y=i===void 0?!1:i,m=f&&f.length>0,v=y?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==c||e[1]!==v?(p=ye("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",v,c),e[0]=c,e[1]=v,e[2]=p):p=e[2];let F;e[3]!==a?(F=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=F):F=e[4];let S;e[5]!==l||e[6]!==F?(S=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,F]}),e[5]=l,e[6]=F,e[7]=S):S=e[7];let N;e[8]!==n?(N=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=N):N=e[9];let h;e[10]!==r||e[11]!==S||e[12]!==N?(h=s.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:[S,N]}),e[10]=r,e[11]=S,e[12]=N,e[13]=h):h=e[13];let I;e[14]!==f||e[15]!==m?(I=m&&s.jsxs(Gs,{children:[s.jsx(Bs,{asChild:!0,children:s.jsx(H,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Hs,{align:"end",className:"w-fit min-w-20",children:f.map(Up)})]}),e[14]=f,e[15]=m,e[16]=I):I=e[16];let u;e[17]!==h||e[18]!==I?(u=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[h,I]}),e[17]=h,e[18]=I,e[19]=u):u=e[19];let D;return e[20]!==p||e[21]!==u?(D=s.jsx("div",{className:p,children:u}),e[20]=p,e[21]=u,e[22]=D):D=e[22],D};function Up(t){const e=t.icon;return s.jsxs(qs,{onClick:a=>{a.stopPropagation(),t.onClick()},className:ye(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(z,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const _p=t=>t.parsedKind==="npm"?"code-box":"folder",Vp=t=>{const e=ft.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=it(),{entries:r,files:l,selectedId:f,setSelected:c,deleteEntry:y,deleteFile:m,loadPlugins:v}=ls(Cs($p)),p=ls(Bp),F=ls(Hp),S=ls(Gp),N=ls(qp),[h,I]=o.useState(null),[u,D]=o.useState(!1),[q,M]=o.useState(!1);let P,g;e[0]!==v?(P=()=>{v()},g=[v],e[0]=v,e[1]=P,e[2]=g):(P=e[1],g=e[2]),o.useEffect(P,g);let j,L;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{const ie=()=>M(!0);return window.addEventListener("openchamber:settings-open-plugin-add",ie),()=>window.removeEventListener("openchamber:settings-open-plugin-add",ie)},L=[],e[3]=j,e[4]=L):(j=e[3],L=e[4]),o.useEffect(j,L);let C;if(e[5]!==r||e[6]!==p){C={userEntries:0,projectEntries:0};for(const ie of r){const Pe=p[ie.spec];Pe?.kind==="npm-ok"&&Pe.hasUpdate&&(ie.scope==="user"?C.userEntries=C.userEntries+1:ie.scope==="project"&&(C.projectEntries=C.projectEntries+1))}e[5]=r,e[6]=p,e[7]=C}else C=e[7];const A=C;let b;e[8]!==r?(b=r.filter(Wp),e[8]=r,e[9]=b):b=e[9];const K=b;let $;e[10]!==r?($=r.filter(Jp),e[10]=r,e[11]=$):$=e[11];const k=$;let W;e[12]!==l?(W=l.filter(Qp),e[12]=l,e[13]=W):W=e[13];const Z=W;let B;e[14]!==l?(B=l.filter(Yp),e[14]=l,e[15]=B):B=e[15];const Q=B,w=r.length+l.length,X=w===0;let ee;e[16]!==n?(ee=()=>{n?n():M(!0)},e[16]=n,e[17]=ee):ee=e[17];const T=ee;let O;e[18]!==a||e[19]!==c?(O=ie=>{c(ie),a?.()},e[18]=a,e[19]=c,e[20]=O):O=e[20];const V=O;let E;e[21]!==r||e[22]!==p||e[23]!==i||e[24]!==N?(E=async ie=>{const Pe=r.find(St=>St.id===ie);if(!Pe)return;const Ve=p[Pe.spec];if(!Ve||Ve.kind!=="npm-ok"||!Ve.hasUpdate||!Ve.latestVersion)return;const We=Ve.latestVersion;(await N(ie)).ok?R.success(i("settings.plugins.toast.updatedToLatest",{version:We})):R.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=p,e[23]=i,e[24]=N,e[25]=E):E=e[25];const _=E;let J;e[26]!==S||e[27]!==i?(J=async()=>{R.info(i("settings.plugins.toast.refreshing"));try{await S({force:!0})}catch{R.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=S,e[27]=i,e[28]=J):J=e[28];const te=J;let ne;e[29]!==y||e[30]!==m||e[31]!==h||e[32]!==i?(ne=async()=>{if(!h)return;D(!0);const ie=h.kind==="entry"?await y(h.id):await m(h.id);ie.ok?R.success(ie.message||i("settings.plugins.sidebar.toast.deleted",{name:h.label})):R.error(i("settings.plugins.sidebar.toast.deleteFailed")),I(null),D(!1)},e[29]=y,e[30]=m,e[31]=h,e[32]=i,e[33]=ne):ne=e[33];const le=ne;let be;e[34]!==V||e[35]!==_||e[36]!==p||e[37]!==f||e[38]!==i?(be=ie=>{const Pe=p[ie.spec],Ve=Pe?.kind==="npm-ok"&&Pe.hasUpdate&&!!Pe.latestVersion,We=[];return Ve&&We.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{_(ie.id)}}),We.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>I({kind:"entry",id:ie.id,label:ie.spec})}),s.jsx($i,{title:s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:ie.spec}),s.jsx(Kp,{spec:ie.spec})]}),metadata:ie.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:f===ie.id,onSelect:()=>V(ie.id),icon:s.jsx(z,{name:_p(ie),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:We},ie.id)},e[34]=V,e[35]=_,e[36]=p,e[37]=f,e[38]=i,e[39]=be):be=e[39];const Ne=be;let de;e[40]!==V||e[41]!==f||e[42]!==i?(de=ie=>s.jsx($i,{title:ie.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:f===ie.id,onSelect:()=>V(ie.id),icon:s.jsx(z,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>I({kind:"file",id:ie.id,label:ie.fileName})}]},ie.id),e[40]=V,e[41]=f,e[42]=i,e[43]=de):de=e[43];const ue=de;let Me;e[44]!==i?(Me=(ie,Pe,Ve)=>{const We=Ve===void 0?0:Ve;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[ie,We>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(We===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:We})})]}),Pe]})},e[44]=i,e[45]=Me):Me=e[45];const Ce=Me;let ke;e[46]!==i?(ke=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=ke):ke=e[47];let fe;e[48]!==ke?(fe=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:Ws,children:ke})}),e[48]=ke,e[49]=fe):fe=e[49];let ze;e[50]!==i||e[51]!==w?(ze=i("settings.plugins.sidebar.total",{count:w}),e[50]=i,e[51]=w,e[52]=ze):ze=e[52];let Ae;e[53]!==ze?(Ae=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ze}),e[53]=ze,e[54]=Ae):Ae=e[54];let he;e[55]!==te?(he=()=>{te()},e[55]=te,e[56]=he):he=e[56];let ge;e[57]!==i?(ge=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=ge):ge=e[58];let Ee;e[59]!==i?(Ee=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=Ee):Ee=e[60];const Te=F?"size-4 animate-spin":"size-4";let Qe;e[61]!==Te?(Qe=s.jsx(z,{name:"refresh",className:Te}),e[61]=Te,e[62]=Qe):Qe=e[62];let Be;e[63]!==F||e[64]!==he||e[65]!==ge||e[66]!==Ee||e[67]!==Qe?(Be=s.jsx(H,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:he,disabled:F,"aria-label":ge,title:Ee,children:Qe}),e[63]=F,e[64]=he,e[65]=ge,e[66]=Ee,e[67]=Qe,e[68]=Be):Be=e[68];let Ke;e[69]!==i?(Ke=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=Ke):Ke=e[70];let Ge;e[71]!==i?(Ge=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=Ge):Ge=e[72];let qe;e[73]===Symbol.for("react.memo_cache_sentinel")?(qe=s.jsx(z,{name:"add",className:"size-4"}),e[73]=qe):qe=e[73];let Ie;e[74]!==T||e[75]!==Ke||e[76]!==Ge?(Ie=s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:T,"aria-label":Ke,title:Ge,children:qe}),e[74]=T,e[75]=Ke,e[76]=Ge,e[77]=Ie):Ie=e[77];let Re;e[78]!==Be||e[79]!==Ie?(Re=s.jsxs("div",{className:"flex items-center gap-1",children:[Be,Ie]}),e[78]=Be,e[79]=Ie,e[80]=Re):Re=e[80];let $e;e[81]!==Ae||e[82]!==Re?($e=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ae,Re]}),e[81]=Ae,e[82]=Re,e[83]=$e):$e=e[83];let Ue;e[84]!==fe||e[85]!==$e?(Ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[fe,$e]}),e[84]=fe,e[85]=$e,e[86]=Ue):Ue=e[86];let je;e[87]!==X||e[88]!==k||e[89]!==Q||e[90]!==Ne||e[91]!==ue||e[92]!==Ce||e[93]!==i||e[94]!==A||e[95]!==K||e[96]!==Z?(je=X?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:i("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:i("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[K.length>0&&Ce(i("settings.plugins.sidebar.group.userEntries"),K.map(Ne),A.userEntries),Z.length>0&&Ce(i("settings.plugins.sidebar.group.userFiles"),Z.map(ue)),k.length>0&&Ce(i("settings.plugins.sidebar.group.projectEntries"),k.map(Ne),A.projectEntries),Q.length>0&&Ce(i("settings.plugins.sidebar.group.projectFiles"),Q.map(ue))]}),e[87]=X,e[88]=k,e[89]=Q,e[90]=Ne,e[91]=ue,e[92]=Ce,e[93]=i,e[94]=A,e[95]=K,e[96]=Z,e[97]=je):je=e[97];let U;e[98]!==Ue||e[99]!==je?(U=s.jsx(al,{variant:"background",header:Ue,children:je}),e[98]=Ue,e[99]=je,e[100]=U):U=e[100];let re;e[101]!==q?(re=s.jsx(Fp,{open:q,onOpenChange:M}),e[101]=q,e[102]=re):re=e[102];const pe=h!==null;let ve;e[103]!==u?(ve=ie=>{!ie&&!u&&I(null)},e[103]=u,e[104]=ve):ve=e[104];let ae;e[105]!==i?(ae=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=ae):ae=e[106];let _e;e[107]!==ae?(_e=s.jsx(Ht,{children:ae}),e[107]=ae,e[108]=_e):_e=e[108];const Ze=h?.label??"";let G;e[109]!==i||e[110]!==Ze?(G=i("settings.plugins.sidebar.deleteDialog.description",{name:Ze}),e[109]=i,e[110]=Ze,e[111]=G):G=e[111];let Fe;e[112]!==G?(Fe=s.jsx(Gt,{children:G}),e[112]=G,e[113]=Fe):Fe=e[113];let Ye;e[114]!==_e||e[115]!==Fe?(Ye=s.jsxs(Bt,{children:[_e,Fe]}),e[114]=_e,e[115]=Fe,e[116]=Ye):Ye=e[116];let st;e[117]===Symbol.for("react.memo_cache_sentinel")?(st=()=>I(null),e[117]=st):st=e[117];let et;e[118]!==i?(et=i("settings.common.actions.cancel"),e[118]=i,e[119]=et):et=e[119];let wt;e[120]!==u||e[121]!==et?(wt=s.jsx(H,{size:"sm",variant:"ghost",onClick:st,disabled:u,children:et}),e[120]=u,e[121]=et,e[122]=wt):wt=e[122];let pt;e[123]!==u||e[124]!==i?(pt=i(u?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=u,e[124]=i,e[125]=pt):pt=e[125];let mt;e[126]!==le||e[127]!==u||e[128]!==pt?(mt=s.jsx(H,{size:"sm",variant:"destructive",onClick:le,disabled:u,children:pt}),e[126]=le,e[127]=u,e[128]=pt,e[129]=mt):mt=e[129];let ot;e[130]!==wt||e[131]!==mt?(ot=s.jsxs(is,{children:[wt,mt]}),e[130]=wt,e[131]=mt,e[132]=ot):ot=e[132];let bt;e[133]!==Ye||e[134]!==ot?(bt=s.jsxs($t,{className:"max-w-md",children:[Ye,ot]}),e[133]=Ye,e[134]=ot,e[135]=bt):bt=e[135];let ut;e[136]!==pe||e[137]!==ve||e[138]!==bt?(ut=s.jsx(Vt,{open:pe,onOpenChange:ve,children:bt}),e[136]=pe,e[137]=ve,e[138]=bt,e[139]=ut):ut=e[139];let At;return e[140]!==U||e[141]!==re||e[142]!==ut?(At=s.jsxs(s.Fragment,{children:[U,re,ut]}),e[140]=U,e[141]=re,e[142]=ut,e[143]=At):At=e[143],At};function $p(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function Bp(t){return t.registryInfo}function Hp(t){return t.isLoadingRegistry}function Gp(t){return t.loadRegistryInfo}function qp(t){return t.updateToLatest}function Wp(t){return t.scope==="user"}function Jp(t){return t.scope==="project"}function Qp(t){return t.scope==="user"}function Yp(t){return t.scope==="project"}const Zp=({entryId:t,spec:e})=>{const{t:a}=it(),n=ls(v=>v.registryInfo[e]),i=ls(v=>v.updateToLatest),[r,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const v=n.latestVersion,p=n.currentVersion??"",F=async()=>{l(!0);try{(await i(t)).ok?R.success(a("settings.plugins.toast.updatedToLatest",{version:v})):R.error(a("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:p,latest:v})})]}),s.jsx(H,{variant:"default",size:"sm",onClick:()=>{F()},disabled:r,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:v})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const f=n.kind==="path-unreadable",c=f?"var(--status-warning)":"var(--status-error)",y=f?"alert":"error-warning",m=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(z,{name:y,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:c}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:c},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:m})]})]})};function Xp(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}function il(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function Gr(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:il(t.options),fileName:"",content:""}}function qr(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const Wr=t=>{const e=ft.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=ye("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=i):i=e[0];let r;return e[1]!==n||e[2]!==a?(r=s.jsx("span",{className:i,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=r):r=e[3],r},em=()=>{const{t}=it(),e=ls(h=>h.selectedId),a=ls(h=>h.entries),n=ls(h=>h.files),i=ls(h=>h.draft),r=ls(h=>h.setDraft),l=ls(h=>h.updateEntry),f=ls(h=>h.updateFile),c=ls(h=>h.readFile),y=o.useMemo(()=>e?a.find(h=>h.id===e)??null:null,[a,e]),m=o.useMemo(()=>e?n.find(h=>h.id===e)??null:null,[n,e]),[v,p]=o.useState(!1),[F,S]=o.useState(!1),N=o.useRef(new Map);if(o.useEffect(()=>{let h=!1;return y?(r(Gr(y)),()=>{h=!0}):m?(S(!0),(async()=>{const I=await c(m.id);if(h)return;S(!1);const u=I?.content??"";N.current.set(m.id,u),r(qr(m,u))})(),()=>{h=!0}):(r(null),()=>{h=!0})},[y,m,c,r]),!e)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(y&&i&&i.mode==="entry"){const h=Xp(i.optionsJson),I=h.ok,u=i.spec!==y.spec||i.optionsJson!==il(y.options),D=()=>{r(Gr(y))},q=async()=>{if(!I)return;const M=i.spec.trim();if(!M){R.error(t("settings.plugins.validation.specRequired"));return}p(!0);try{const P=await l(y.id,{spec:M,options:h.value});P.ok?P.reloadFailed?R.warning(P.message||t("settings.plugins.toast.reloadFailed"),{description:P.warning}):P.restartDeferred?R.success(t("settings.view.pendingRestart.saved")):R.success(P.message||t("settings.plugins.toast.updated")):R.error(P.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsxs(as,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(Wr,{scope:y.scope,label:y.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(Le,{divider:!1,children:s.jsx(Zp,{entryId:y.id,spec:y.spec})}),s.jsx(Le,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(He,{value:i.spec,onChange:M=>r({...i,spec:M.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(Le,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(Ns,{value:i.optionsJson,onChange:M=>r({...i,optionsJson:M.target.value}),rows:10,className:ye("font-mono typography-meta min-h-[200px]",!I&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!I&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:t("settings.plugins.page.field.options.invalidJson")}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{q()},disabled:!u||!I||v,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:D,disabled:!u||v,children:t("settings.plugins.page.action.discard")})]})]})]})}if(m&&i&&i.mode==="file"){const h=N.current.get(m.id)??"",I=i.content!==h||i.fileName!==m.fileName,u=()=>{(async()=>{S(!0);const M=(await c(m.id))?.content??"";S(!1),N.current.set(m.id,M),r(qr(m,M))})()},D=async()=>{p(!0);try{const q=await f(m.id,{content:i.content});q.ok?(N.current.set(m.id,i.content),q.reloadFailed?R.warning(q.message||t("settings.plugins.toast.reloadFailed"),{description:q.warning}):q.restartDeferred?R.success(t("settings.view.pendingRestart.saved")):R.success(q.message||t("settings.plugins.toast.updated"))):R.error(q.message||t("settings.plugins.toast.reloadFailed"))}finally{p(!1)}};return s.jsx(as,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(Wr,{scope:m.scope,label:m.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:ye("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:m.fileName})]}),showSaveStatus:!1,children:s.jsxs(Le,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(Ns,{value:i.content,onChange:q=>r({...i,content:q.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:F}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{D()},disabled:!I||v||F,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:u,disabled:v||F,children:t("settings.plugins.page.action.discard")})]})]})})}return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(z,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},tm="<built-in>",ya=t=>t?.path===tm,Bi=t=>!!t&&!ya(t)&&t.renamable===!0,sm=t=>{const e=ft.c(148),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,f]=o.useState(""),[c,y]=o.useState(null),[m,v]=o.useState(!1),[p,F]=o.useState(null),{selectedSkillName:S,skills:N,setSelectedSkill:h,setSkillDraft:I,deleteSkill:u,renameSkill:D,getSkillDetail:q}=rn(Cs(nm));let M;e[0]!==a||e[1]!==h||e[2]!==I||e[3]!==N?(M=()=>{let ie="new-skill",Pe=1;for(;N.some(Ve=>Ve.name===ie);)ie=`new-skill-${Pe}`,Pe++;I({name:ie,scope:"user",source:"opencode",description:""}),h(ie),a?.()},e[0]=a,e[1]=h,e[2]=I,e[3]=N,e[4]=M):M=e[4];const P=M;let g;e[5]===Symbol.for("react.memo_cache_sentinel")?(g=async ie=>{ya(ie)||y(ie)},e[5]=g):g=e[5];const j=g;let L;e[6]!==c||e[7]!==u||e[8]!==n?(L=async()=>{if(!c)return;if(ya(c)){y(null);return}v(!0),await u(c.name)?(R.success(n("settings.skills.sidebar.toast.skillDeleted",{name:c.name})),y(null)):R.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),v(!1)},e[6]=c,e[7]=u,e[8]=n,e[9]=L):L=e[9];const C=L;let A;e[10]!==q||e[11]!==h||e[12]!==I||e[13]!==N||e[14]!==n?(A=async ie=>{if(ya(ie))return;const Pe=ie.name;let Ve=1,We=`${Pe}-copy`;for(;N.some(St=>St.name===We);)Ve++,We=`${Pe}-copy-${Ve}`;const kt=await q(ie.name);if(!kt){R.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}I({name:We,scope:ie.scope||"user",source:ie.source||"opencode",description:(kt.sources.md.fields.includes("description"),""),instructions:""}),h(We)},e[10]=q,e[11]=h,e[12]=I,e[13]=N,e[14]=n,e[15]=A):A=e[15];const b=A;let K;e[16]===Symbol.for("react.memo_cache_sentinel")?(K=ie=>{Bi(ie)&&(f(ie.name),r(ie))},e[16]=K):K=e[16];const $=K;let k;e[17]!==i||e[18]!==l||e[19]!==D||e[20]!==h||e[21]!==N||e[22]!==n?(k=async()=>{if(!i)return;if(!Bi(i)){r(null);return}const ie=l.trim().replace(/\s+/g,"-").toLowerCase();if(!ie){R.error(n("settings.skills.page.toast.skillNameRequired"));return}if(ie===i.name){r(null);return}if(N.some(Ve=>Ve.name===ie)){R.error(n("settings.skills.page.toast.skillExists"));return}await D(i.name,ie)?(R.success(n("settings.skills.sidebar.toast.skillRenamed",{name:ie})),h(ie)):R.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[17]=i,e[18]=l,e[19]=D,e[20]=h,e[21]=N,e[22]=n,e[23]=k):k=e[23];const W=k;let Z;e[24]!==N?(Z=N.filter(am),e[24]=N,e[25]=Z):Z=e[25];const B=Z;let Q;e[26]!==N?(Q=N.filter(im),e[26]=N,e[27]=Q):Q=e[27];const w=Q;let X;e[28]===Symbol.for("react.memo_cache_sentinel")?(X=function(Pe){const Ve={},We=[];for(const St of Pe)St.group?(Ve[St.group]||(Ve[St.group]=[]),Ve[St.group].push(St)):We.push(St);const kt=Object.keys(Ve).sort(rm).map(St=>({name:St,skills:[...Ve[St]].sort(om)}));return We.sort(lm),{sortedGroups:kt,ungrouped:We}},e[28]=X):X=e[28];const ee=X;let T;e[29]!==B?(T=ee(B),e[29]=B,e[30]=T):T=e[30];const O=T;let V;e[31]!==w?(V=ee(w),e[31]=w,e[32]=V):V=e[32];const E=V;let _;e[33]===Symbol.for("react.memo_cache_sentinel")?(_=ye("flex h-full flex-col","bg-background"),e[33]=_):_=e[33];let J;e[34]!==n?(J=n("settings.skills.sidebar.title"),e[34]=n,e[35]=J):J=e[35];let te;e[36]!==J?(te=s.jsx("h2",{className:`${Ws} mb-3`,children:J}),e[36]=J,e[37]=te):te=e[37];let ne;e[38]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(Ca,{className:"mb-3"}),e[38]=ne):ne=e[38];let le;e[39]!==N.length||e[40]!==n?(le=n("settings.skills.sidebar.total",{count:N.length}),e[39]=N.length,e[40]=n,e[41]=le):le=e[41];let be;e[42]!==le?(be=s.jsx("span",{className:"typography-meta text-muted-foreground",children:le}),e[42]=le,e[43]=be):be=e[43];let Ne;e[44]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[44]=Ne):Ne=e[44];let de;e[45]!==P?(de=s.jsx(H,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:P,children:Ne}),e[45]=P,e[46]=de):de=e[46];let ue;e[47]!==be||e[48]!==de?(ue=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[be,de]}),e[47]=be,e[48]=de,e[49]=ue):ue=e[49];let Me;e[50]!==te||e[51]!==ue?(Me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[te,ne,ue]}),e[50]=te,e[51]=ue,e[52]=Me):Me=e[52];let Ce;e[53]!==O||e[54]!==E||e[55]!==b||e[56]!==a||e[57]!==p||e[58]!==B||e[59]!==S||e[60]!==h||e[61]!==N.length||e[62]!==n||e[63]!==w?(Ce=s.jsx(Ms,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:N.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[B.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.project")}),O.sortedGroups.map(ie=>{const{name:Pe,skills:Ve}=ie;return s.jsx(zi,{label:Pe,count:Ve.length,storageKey:"project-skills",children:Ve.map(We=>s.jsx(Va,{skill:We,isSelected:S===We.name,onSelect:()=>{h(We.name),a?.()},onRename:()=>$(We),onDelete:()=>j(We),onDuplicate:()=>b(We),isMenuOpen:p===We.name,onMenuOpenChange:kt=>F(kt?We.name:null)},We.name))},Pe)}),O.ungrouped.map(ie=>s.jsx(Va,{skill:ie,isSelected:S===ie.name,onSelect:()=>{h(ie.name),a?.()},onRename:()=>$(ie),onDelete:()=>j(ie),onDuplicate:()=>b(ie),isMenuOpen:p===ie.name,onMenuOpenChange:Pe=>F(Pe?ie.name:null)},ie.name))]}),w.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),E.sortedGroups.map(ie=>{const{name:Pe,skills:Ve}=ie;return s.jsx(zi,{label:Pe,count:Ve.length,storageKey:"user-skills",children:Ve.map(We=>s.jsx(Va,{skill:We,isSelected:S===We.name,onSelect:()=>{h(We.name),a?.()},onRename:()=>$(We),onDelete:()=>j(We),onDuplicate:()=>b(We),isMenuOpen:p===We.name,onMenuOpenChange:kt=>F(kt?We.name:null)},We.name))},Pe)}),E.ungrouped.map(ie=>s.jsx(Va,{skill:ie,isSelected:S===ie.name,onSelect:()=>{h(ie.name),a?.()},onRename:()=>$(ie),onDelete:()=>j(ie),onDuplicate:()=>b(ie),isMenuOpen:p===ie.name,onMenuOpenChange:Pe=>F(Pe?ie.name:null)},ie.name))]})]})}),e[53]=O,e[54]=E,e[55]=b,e[56]=a,e[57]=p,e[58]=B,e[59]=S,e[60]=h,e[61]=N.length,e[62]=n,e[63]=w,e[64]=Ce):Ce=e[64];const ke=c!==null;let fe;e[65]!==m?(fe=ie=>{!ie&&!m&&y(null)},e[65]=m,e[66]=fe):fe=e[66];let ze;e[67]!==n?(ze=n("settings.skills.sidebar.deleteDialog.title"),e[67]=n,e[68]=ze):ze=e[68];let Ae;e[69]!==ze?(Ae=s.jsx(Ht,{children:ze}),e[69]=ze,e[70]=Ae):Ae=e[70];const he=c?.name??"";let ge;e[71]!==n||e[72]!==he?(ge=n("settings.skills.sidebar.deleteDialog.description",{name:he}),e[71]=n,e[72]=he,e[73]=ge):ge=e[73];let Ee;e[74]!==ge?(Ee=s.jsx(Gt,{children:ge}),e[74]=ge,e[75]=Ee):Ee=e[75];let Te;e[76]!==Ae||e[77]!==Ee?(Te=s.jsxs(Bt,{children:[Ae,Ee]}),e[76]=Ae,e[77]=Ee,e[78]=Te):Te=e[78];let Qe;e[79]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>y(null),e[79]=Qe):Qe=e[79];let Be;e[80]!==n?(Be=n("settings.common.actions.cancel"),e[80]=n,e[81]=Be):Be=e[81];let Ke;e[82]!==m||e[83]!==Be?(Ke=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Qe,disabled:m,children:Be}),e[82]=m,e[83]=Be,e[84]=Ke):Ke=e[84];let Ge;e[85]!==n?(Ge=n("settings.common.actions.delete"),e[85]=n,e[86]=Ge):Ge=e[86];let qe;e[87]!==C||e[88]!==m||e[89]!==Ge?(qe=s.jsx(H,{size:"sm",onClick:C,disabled:m,children:Ge}),e[87]=C,e[88]=m,e[89]=Ge,e[90]=qe):qe=e[90];let Ie;e[91]!==Ke||e[92]!==qe?(Ie=s.jsxs(is,{children:[Ke,qe]}),e[91]=Ke,e[92]=qe,e[93]=Ie):Ie=e[93];let Re;e[94]!==Te||e[95]!==Ie?(Re=s.jsxs($t,{className:"max-w-md",children:[Te,Ie]}),e[94]=Te,e[95]=Ie,e[96]=Re):Re=e[96];let $e;e[97]!==ke||e[98]!==fe||e[99]!==Re?($e=s.jsx(Vt,{open:ke,onOpenChange:fe,children:Re}),e[97]=ke,e[98]=fe,e[99]=Re,e[100]=$e):$e=e[100];const Ue=i!==null;let je;e[101]===Symbol.for("react.memo_cache_sentinel")?(je=ie=>!ie&&r(null),e[101]=je):je=e[101];let U;e[102]!==n?(U=n("settings.skills.sidebar.renameDialog.title"),e[102]=n,e[103]=U):U=e[103];let re;e[104]!==U?(re=s.jsx(Ht,{children:U}),e[104]=U,e[105]=re):re=e[105];const pe=i?.name??"";let ve;e[106]!==n||e[107]!==pe?(ve=n("settings.skills.sidebar.renameDialog.description",{name:pe}),e[106]=n,e[107]=pe,e[108]=ve):ve=e[108];let ae;e[109]!==ve?(ae=s.jsx(Gt,{children:ve}),e[109]=ve,e[110]=ae):ae=e[110];let _e;e[111]!==re||e[112]!==ae?(_e=s.jsxs(Bt,{children:[re,ae]}),e[111]=re,e[112]=ae,e[113]=_e):_e=e[113];let Ze;e[114]===Symbol.for("react.memo_cache_sentinel")?(Ze=ie=>f(ie.target.value),e[114]=Ze):Ze=e[114];let G;e[115]!==n?(G=n("settings.skills.sidebar.renameDialog.placeholder"),e[115]=n,e[116]=G):G=e[116];let Fe;e[117]!==W?(Fe=ie=>{ie.key==="Enter"&&W()},e[117]=W,e[118]=Fe):Fe=e[118];let Ye;e[119]!==l||e[120]!==G||e[121]!==Fe?(Ye=s.jsx(He,{value:l,onChange:Ze,placeholder:G,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Fe}),e[119]=l,e[120]=G,e[121]=Fe,e[122]=Ye):Ye=e[122];let st;e[123]===Symbol.for("react.memo_cache_sentinel")?(st=()=>r(null),e[123]=st):st=e[123];let et;e[124]!==n?(et=n("settings.common.actions.cancel"),e[124]=n,e[125]=et):et=e[125];let wt;e[126]!==et?(wt=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:st,children:et}),e[126]=et,e[127]=wt):wt=e[127];let pt;e[128]!==n?(pt=n("settings.common.actions.rename"),e[128]=n,e[129]=pt):pt=e[129];let mt;e[130]!==W||e[131]!==pt?(mt=s.jsx(H,{size:"sm",onClick:W,children:pt}),e[130]=W,e[131]=pt,e[132]=mt):mt=e[132];let ot;e[133]!==wt||e[134]!==mt?(ot=s.jsxs(is,{children:[wt,mt]}),e[133]=wt,e[134]=mt,e[135]=ot):ot=e[135];let bt;e[136]!==_e||e[137]!==Ye||e[138]!==ot?(bt=s.jsxs($t,{children:[_e,Ye,ot]}),e[136]=_e,e[137]=Ye,e[138]=ot,e[139]=bt):bt=e[139];let ut;e[140]!==Ue||e[141]!==bt?(ut=s.jsx(Vt,{open:Ue,onOpenChange:je,children:bt}),e[140]=Ue,e[141]=bt,e[142]=ut):ut=e[142];let At;return e[143]!==Me||e[144]!==Ce||e[145]!==$e||e[146]!==ut?(At=s.jsxs("div",{className:_,children:[Me,Ce,$e,ut]}),e[143]=Me,e[144]=Ce,e[145]=$e,e[146]=ut,e[147]=At):At=e[147],At},Va=t=>{const e=ft.c(52),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:f,isMenuOpen:c,onMenuOpenChange:y}=t,{t:m}=it();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=wa(),e[0]=v):v=e[0];const p=v;let F;e[1]!==a.source||e[2]!==m?(F=a.source==="claude"?m("settings.skills.sidebar.badge.claude"):a.source==="agents"?m("settings.skills.sidebar.badge.agents"):m("settings.skills.sidebar.badge.opencode"),e[1]=a.source,e[2]=m,e[3]=F):F=e[3];const S=F;let N;e[4]!==a?(N=ya(a),e[4]=a,e[5]=N):N=e[5];const h=N;let I;e[6]!==a?(I=Bi(a),e[6]=a,e[7]=I):I=e[7];const u=I,[D,q]=o.useState(!1);let M;e[8]!==u||e[9]!==r||e[10]!==f||e[11]!==l||e[12]!==m?(M=ee=>s.jsxs(s.Fragment,{children:[u?s.jsxs(ee,{onClick:T=>{T.stopPropagation(),l()},children:[s.jsx(z,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}):null,s.jsxs(ee,{onClick:T=>{T.stopPropagation(),f()},children:[s.jsx(z,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),s.jsxs(ee,{onClick:T=>{T.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[8]=u,e[9]=r,e[10]=f,e[11]=l,e[12]=m,e[13]=M):M=e[13];const P=M,g=!h&&D,j=n?"bg-interactive-selection":"hover:bg-interactive-hover";let L;e[14]!==j?(L=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j),e[14]=j,e[15]=L):L=e[15];let C;e[16]!==h?(C=!p&&!h?ee=>{ee.preventDefault(),q(!0)}:void 0,e[16]=h,e[17]=C):C=e[17];let A;e[18]!==L||e[19]!==C?(A=s.jsx("div",{className:L,onContextMenu:C}),e[18]=L,e[19]=C,e[20]=A):A=e[20];let b;e[21]!==a.name?(b=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[21]=a.name,e[22]=b):b=e[22];let K;e[23]!==a.scope?(K=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:a.scope}),e[23]=a.scope,e[24]=K):K=e[24];let $;e[25]!==S?($=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:S}),e[25]=S,e[26]=$):$=e[26];let k;e[27]!==b||e[28]!==K||e[29]!==$?(k=s.jsxs("div",{className:"flex items-center gap-1.5",children:[b,K,$]}),e[27]=b,e[28]=K,e[29]=$,e[30]=k):k=e[30];let W;e[31]!==i||e[32]!==k?(W=s.jsx("button",{onClick:i,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:k}),e[31]=i,e[32]=k,e[33]=W):W=e[33];let Z;e[34]!==h||e[35]!==c||e[36]!==y||e[37]!==P?(Z=h?null:s.jsxs(Gs,{open:c,onOpenChange:ee=>{ee&&q(!1),y(ee)},children:[s.jsx(Bs,{asChild:!0,children:s.jsx(H,{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:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Hs,{align:"end",className:"w-fit min-w-20",children:P(qs)})]}),e[34]=h,e[35]=c,e[36]=y,e[37]=P,e[38]=Z):Z=e[38];let B;e[39]!==W||e[40]!==Z?(B=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[W,Z]}),e[39]=W,e[40]=Z,e[41]=B):B=e[41];let Q;e[42]!==A||e[43]!==B?(Q=s.jsx(On,{render:A,children:B}),e[42]=A,e[43]=B,e[44]=Q):Q=e[44];let w;e[45]!==h||e[46]!==P?(w=h?null:s.jsx(Mn,{className:"w-fit min-w-20",children:P(Rn)}),e[45]=h,e[46]=P,e[47]=w):w=e[47];let X;return e[48]!==Q||e[49]!==w||e[50]!==g?(X=s.jsxs(Ln,{open:g,onOpenChange:q,children:[Q,w]}),e[48]=Q,e[49]=w,e[50]=g,e[51]=X):X=e[51],X};function nm(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function am(t){return t.scope==="project"}function im(t){return t.scope==="user"}function rm(t,e){return t.localeCompare(e)}function om(t,e){return t.name.localeCompare(e.name)}function lm(t,e){return t.name.localeCompare(e.name)}const cm=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,dm=t=>{const e=t.trim(),a=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(a==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(a==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const n=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return n?`${n[1]}/${n[2].replace(/\.git$/i,"")}`:e},pm=async()=>{try{const t=kn()?.settings;if(t)return(await t.load())?.settings||{};const e=await lt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},mm=t=>{const e=ft.c(162),{open:a,onOpenChange:n}=t,{t:i}=it(),r=an(um),l=an(gm),f=an(hm),c=an(fm),y=an(xm),m=Tn(bm),v=Tn(vm),[p,F]=o.useState(""),[S,N]=o.useState(""),[h,I]=o.useState("");let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];const[D,q]=o.useState(u),[M,P]=o.useState(null),[g,j]=o.useState(!1);let L;e[1]===Symbol.for("react.memo_cache_sentinel")?(L=[],e[1]=L):L=e[1];const[C,A]=o.useState(L),[b,K]=o.useState(null),$=o.useRef(0);let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=Pe=>{$.current=$.current+1,j(!1),P(null),Pe?.clearIdentity&&(A([]),K(null))},e[2]=k):k=e[2];const W=k;let Z,B;e[3]!==v||e[4]!==a?(Z=()=>{a&&($.current=$.current+1,F(""),N(""),I(""),P(null),j(!1),A([]),K(null),v(),(async()=>{const Pe=await pm(),Ve=Array.isArray(Pe?.skillCatalogs)?Pe?.skillCatalogs:[];q(Ve||[])})())},B=[a,v],e[3]=v,e[4]=a,e[5]=Z,e[6]=B):(Z=e[5],B=e[6]),o.useEffect(Z,B);let Q;e[7]!==S?(Q=S.trim(),e[7]=S,e[8]=Q):Q=e[8];const w=Q;let X;e[9]!==h?(X=h.trim(),e[9]=h,e[10]=X):X=e[10];const ee=X;let T;if(e[11]!==D||e[12]!==w||e[13]!==ee){let Pe;e[15]!==w||e[16]!==ee?(Pe=Ve=>{const We=(Ve.source||"").trim(),kt=(Ve.subpath||"").trim();return We===w&&kt===ee},e[15]=w,e[16]=ee,e[17]=Pe):Pe=e[17],T=D.some(Pe),e[11]=D,e[12]=w,e[13]=ee,e[14]=T}else T=e[14];const O=T;let V;e[18]!==m||e[19]!==b||e[20]!==p||e[21]!==r||e[22]!==S||e[23]!==h||e[24]!==i?(V=async()=>{const Pe=S.trim();if(!Pe){R.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}p.trim()||F(dm(Pe)),j(!1),P(null);const Ve=$.current+1;$.current=Ve;const We=await r({source:Pe,subpath:h.trim()||void 0,gitIdentityId:b||void 0});if($.current!==Ve)return;if(!We.ok){if(We.error?.kind==="authRequired"){if(ps()){R.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const St=We.error.identities||[];if(A(St),!b&&St.length>0){const Wt=m&&m!=="global"&&St.some(Y=>Y.id===m)?m:St[0].id;K(Wt)}R.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}R.error(We.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const kt=We.items?.length||0;if(P(kt),kt===0){R.error(i("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}A([]),j(!0),R.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:kt}))},e[18]=m,e[19]=b,e[20]=p,e[21]=r,e[22]=S,e[23]=h,e[24]=i,e[25]=V):V=e[25];const E=V;let _;e[26]!==D||e[27]!==b||e[28]!==O||e[29]!==p||e[30]!==l||e[31]!==f||e[32]!==n||e[33]!==g||e[34]!==c||e[35]!==S||e[36]!==h||e[37]!==i?(_=async()=>{const Pe=p.trim(),Ve=S.trim(),We=h.trim();if(!Pe){R.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!Ve){R.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!g){R.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(O){R.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const kt={id:cm(),label:Pe,source:Ve,...We?{subpath:We}:{},...b?{gitIdentityId:b}:{}},St=[...D,kt];try{await vt({skillCatalogs:St}),q(St),R.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await f(kt.id,{refresh:!0}),c(kt.id),n(!1)}catch(Wt){const Y=Wt;R.error(Y instanceof Error?Y.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=D,e[27]=b,e[28]=O,e[29]=p,e[30]=l,e[31]=f,e[32]=n,e[33]=g,e[34]=c,e[35]=S,e[36]=h,e[37]=i,e[38]=_):_=e[38];const J=_;let te;e[39]!==i?(te=i("settings.skills.catalog.add.title"),e[39]=i,e[40]=te):te=e[40];let ne;e[41]!==te?(ne=s.jsx(Ht,{children:te}),e[41]=te,e[42]=ne):ne=e[42];let le;e[43]!==i?(le=i("settings.skills.catalog.add.descriptionPrefix"),e[43]=i,e[44]=le):le=e[44];let be;e[45]===Symbol.for("react.memo_cache_sentinel")?(be=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=be):be=e[45];let Ne;e[46]!==i?(Ne=i("settings.skills.catalog.add.descriptionSuffix"),e[46]=i,e[47]=Ne):Ne=e[47];let de;e[48]!==le||e[49]!==Ne?(de=s.jsxs(Gt,{children:[le," ",be,Ne]}),e[48]=le,e[49]=Ne,e[50]=de):de=e[50];let ue;e[51]!==ne||e[52]!==de?(ue=s.jsxs(Bt,{children:[ne,de]}),e[51]=ne,e[52]=de,e[53]=ue):ue=e[53];let Me;e[54]!==i?(Me=i("settings.skills.catalog.add.field.catalogName"),e[54]=i,e[55]=Me):Me=e[55];let Ce;e[56]!==Me?(Ce=s.jsx("label",{className:"typography-ui-label text-foreground",children:Me}),e[56]=Me,e[57]=Ce):Ce=e[57];let ke;e[58]===Symbol.for("react.memo_cache_sentinel")?(ke=Pe=>F(Pe.target.value),e[58]=ke):ke=e[58];let fe;e[59]!==i?(fe=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=i,e[60]=fe):fe=e[60];let ze;e[61]!==p||e[62]!==fe?(ze=s.jsx(He,{value:p,onChange:ke,placeholder:fe}),e[61]=p,e[62]=fe,e[63]=ze):ze=e[63];let Ae;e[64]!==Ce||e[65]!==ze?(Ae=s.jsxs("div",{className:"space-y-2",children:[Ce,ze]}),e[64]=Ce,e[65]=ze,e[66]=Ae):Ae=e[66];let he;e[67]!==i?(he=i("settings.skills.catalog.add.field.repository"),e[67]=i,e[68]=he):he=e[68];let ge;e[69]!==he?(ge=s.jsx("label",{className:"typography-ui-label text-foreground",children:he}),e[69]=he,e[70]=ge):ge=e[70];let Ee;e[71]!==i?(Ee=i("settings.skills.catalog.add.field.repositoryHint"),e[71]=i,e[72]=Ee):Ee=e[72];let Te;e[73]!==Ee?(Te=s.jsx(Yt,{children:Ee}),e[73]=Ee,e[74]=Te):Te=e[74];let Qe;e[75]!==ge||e[76]!==Te?(Qe=s.jsxs("div",{className:"flex items-center gap-1",children:[ge,Te]}),e[75]=ge,e[76]=Te,e[77]=Qe):Qe=e[77];let Be;e[78]===Symbol.for("react.memo_cache_sentinel")?(Be=Pe=>{N(Pe.target.value),W({clearIdentity:!0})},e[78]=Be):Be=e[78];let Ke;e[79]!==i?(Ke=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[79]=i,e[80]=Ke):Ke=e[80];let Ge;e[81]!==S||e[82]!==Ke?(Ge=s.jsx(He,{value:S,onChange:Be,placeholder:Ke}),e[81]=S,e[82]=Ke,e[83]=Ge):Ge=e[83];let qe;e[84]!==Qe||e[85]!==Ge?(qe=s.jsxs("div",{className:"space-y-2",children:[Qe,Ge]}),e[84]=Qe,e[85]=Ge,e[86]=qe):qe=e[86];let Ie;e[87]!==i?(Ie=i("settings.skills.catalog.add.field.optionalSubpath"),e[87]=i,e[88]=Ie):Ie=e[88];let Re;e[89]!==Ie?(Re=s.jsx("label",{className:"typography-ui-label text-foreground",children:Ie}),e[89]=Ie,e[90]=Re):Re=e[90];let $e;e[91]===Symbol.for("react.memo_cache_sentinel")?($e=Pe=>{I(Pe.target.value),W({clearIdentity:!0})},e[91]=$e):$e=e[91];let Ue;e[92]!==i?(Ue=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[92]=i,e[93]=Ue):Ue=e[93];let je;e[94]!==h||e[95]!==Ue?(je=s.jsx(He,{value:h,onChange:$e,placeholder:Ue}),e[94]=h,e[95]=Ue,e[96]=je):je=e[96];let U;e[97]!==Re||e[98]!==je?(U=s.jsxs("div",{className:"space-y-2",children:[Re,je]}),e[97]=Re,e[98]=je,e[99]=U):U=e[99];let re;e[100]!==b||e[101]!==C||e[102]!==i?(re=C.length>0&&!ps()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:i("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:i("settings.skills.catalog.shared.auth.description")}),s.jsx(Yt,{className:"ml-1",children:i("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Mt,{value:b||"",onValueChange:Pe=>{K(Pe),W()},children:[s.jsx(Rt,{className:"w-fit",children:s.jsx("span",{children:C.find(Pe=>Pe.id===b)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Ot,{align:"start",children:C.map(ym)})]})]}):null,e[100]=b,e[101]=C,e[102]=i,e[103]=re):re=e[103];let pe;e[104]!==M||e[105]!==i?(pe=M!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:M})}):null,e[104]=M,e[105]=i,e[106]=pe):pe=e[106];let ve;e[107]!==O||e[108]!==i?(ve=O?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[107]=O,e[108]=i,e[109]=ve):ve=e[109];let ae;e[110]!==Ae||e[111]!==qe||e[112]!==U||e[113]!==re||e[114]!==pe||e[115]!==ve?(ae=s.jsxs("div",{className:"space-y-4",children:[Ae,qe,U,re,pe,ve]}),e[110]=Ae,e[111]=qe,e[112]=U,e[113]=re,e[114]=pe,e[115]=ve,e[116]=ae):ae=e[116];let _e;e[117]!==n?(_e=()=>n(!1),e[117]=n,e[118]=_e):_e=e[118];let Ze;e[119]!==i?(Ze=i("settings.common.actions.cancel"),e[119]=i,e[120]=Ze):Ze=e[120];let G;e[121]!==_e||e[122]!==Ze?(G=s.jsx(H,{size:"sm",variant:"ghost",onClick:_e,children:Ze}),e[121]=_e,e[122]=Ze,e[123]=G):G=e[123];let Fe;e[124]!==E?(Fe=()=>{E()},e[124]=E,e[125]=Fe):Fe=e[125];let Ye;e[126]!==y||e[127]!==S?(Ye=y||!S.trim(),e[126]=y,e[127]=S,e[128]=Ye):Ye=e[128];let st;e[129]===Symbol.for("react.memo_cache_sentinel")?(st=s.jsx(z,{name:"git-repository",className:"h-4 w-4"}),e[129]=st):st=e[129];let et;e[130]!==y||e[131]!==i?(et=i(y?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[130]=y,e[131]=i,e[132]=et):et=e[132];let wt;e[133]!==Fe||e[134]!==Ye||e[135]!==et?(wt=s.jsxs(H,{size:"sm",className:"gap-2",variant:"ghost",onClick:Fe,disabled:Ye,children:[st,et]}),e[133]=Fe,e[134]=Ye,e[135]=et,e[136]=wt):wt=e[136];let pt;e[137]!==J?(pt=()=>{J()},e[137]=J,e[138]=pt):pt=e[138];let mt;e[139]!==O||e[140]!==p||e[141]!==g||e[142]!==S?(mt=!g||O||!p.trim()||!S.trim(),e[139]=O,e[140]=p,e[141]=g,e[142]=S,e[143]=mt):mt=e[143];let ot;e[144]!==i?(ot=i("settings.skills.catalog.add.actions.addCatalog"),e[144]=i,e[145]=ot):ot=e[145];let bt;e[146]!==pt||e[147]!==mt||e[148]!==ot?(bt=s.jsx(H,{size:"sm",onClick:pt,disabled:mt,children:ot}),e[146]=pt,e[147]=mt,e[148]=ot,e[149]=bt):bt=e[149];let ut;e[150]!==G||e[151]!==wt||e[152]!==bt?(ut=s.jsxs(is,{children:[G,wt,bt]}),e[150]=G,e[151]=wt,e[152]=bt,e[153]=ut):ut=e[153];let At;e[154]!==ue||e[155]!==ae||e[156]!==ut?(At=s.jsxs($t,{className:"max-w-xl",children:[ue,ae,ut]}),e[154]=ue,e[155]=ae,e[156]=ut,e[157]=At):At=e[157];let ie;return e[158]!==n||e[159]!==a||e[160]!==At?(ie=s.jsx(Vt,{open:a,onOpenChange:n,children:At}),e[158]=n,e[159]=a,e[160]=At,e[161]=ie):ie=e[161],ie};function um(t){return t.scanRepo}function gm(t){return t.loadCatalog}function hm(t){return t.loadSource}function fm(t){return t.setSelectedSource}function xm(t){return t.isScanning}function bm(t){return t.defaultGitIdentityId}function vm(t){return t.loadDefaultGitIdentityId}function ym(t){return s.jsx(dt,{value:t.id,children:t.name},t.id)}const jm=t=>{const e=ft.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=it();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f={},e[0]=f):f=e[0];const[c,y]=o.useState(f);let m,v;e[1]!==i||e[2]!==a?(m=()=>{if(!a)return;const J={};for(const te of i)J[te.skillName]="skip";y(J)},v=[a,i],e[1]=i,e[2]=a,e[3]=m,e[4]=v):(m=e[3],v=e[4]),o.useEffect(m,v);let p;e[5]!==i?(p=J=>{const te={};for(const ne of i)te[ne.skillName]=J;y(te)},e[5]=i,e[6]=p):p=e[6];const F=p;let S;e[7]!==i||e[8]!==c?(S=i.length>0&&i.every(J=>c[J.skillName]),e[7]=i,e[8]=c,e[9]=S):S=e[9];const N=S;let h;e[10]!==l?(h=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=h):h=e[11];let I;e[12]!==h?(I=s.jsx(Ht,{children:h}),e[12]=h,e[13]=I):I=e[13];let u;e[14]!==l?(u=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=u):u=e[15];let D;e[16]!==u?(D=s.jsx(Gt,{children:u}),e[16]=u,e[17]=D):D=e[17];let q;e[18]!==I||e[19]!==D?(q=s.jsxs(Bt,{children:[I,D]}),e[18]=I,e[19]=D,e[20]=q):q=e[20];let M;e[21]!==i.length||e[22]!==l?(M=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=l,e[23]=M):M=e[23];let P;e[24]!==M?(P=s.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[24]=M,e[25]=P):P=e[25];let g;e[26]!==F?(g=()=>F("skip"),e[26]=F,e[27]=g):g=e[27];let j;e[28]!==l?(j=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=j):j=e[29];let L;e[30]!==g||e[31]!==j?(L=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:g,children:j}),e[30]=g,e[31]=j,e[32]=L):L=e[32];let C;e[33]!==F?(C=()=>F("overwrite"),e[33]=F,e[34]=C):C=e[34];let A;e[35]!==l?(A=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=A):A=e[36];let b;e[37]!==C||e[38]!==A?(b=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:C,children:A}),e[37]=C,e[38]=A,e[39]=b):b=e[39];let K;e[40]!==L||e[41]!==b?(K=s.jsxs("div",{className:"flex items-center gap-2",children:[L,b]}),e[40]=L,e[41]=b,e[42]=K):K=e[42];let $;e[43]!==P||e[44]!==K?($=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,K]}),e[43]=P,e[44]=K,e[45]=$):$=e[45];let k;if(e[46]!==i||e[47]!==c||e[48]!==l){let J;e[50]!==c||e[51]!==l?(J=te=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:te.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:te.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:te.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Mt,{value:c[te.skillName]||"skip",onValueChange:ne=>y(le=>({...le,[te.skillName]:ne})),children:[s.jsx(Rt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(c[te.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Ot,{align:"end",children:[s.jsx(dt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(dt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},te.skillName),e[50]=c,e[51]=l,e[52]=J):J=e[52],k=i.map(J),e[46]=i,e[47]=c,e[48]=l,e[49]=k}else k=e[49];let W;e[53]!==k?(W=s.jsx("div",{className:"space-y-2",children:k}),e[53]=k,e[54]=W):W=e[54];let Z;e[55]!==$||e[56]!==W?(Z=s.jsxs("div",{className:"space-y-3",children:[$,W]}),e[55]=$,e[56]=W,e[57]=Z):Z=e[57];let B;e[58]!==n?(B=()=>n(!1),e[58]=n,e[59]=B):B=e[59];let Q;e[60]!==l?(Q=l("settings.common.actions.cancel"),e[60]=l,e[61]=Q):Q=e[61];let w;e[62]!==B||e[63]!==Q?(w=s.jsx(H,{size:"sm",variant:"ghost",onClick:B,children:Q}),e[62]=B,e[63]=Q,e[64]=w):w=e[64];let X;e[65]!==c||e[66]!==r?(X=()=>r(c),e[65]=c,e[66]=r,e[67]=X):X=e[67];const ee=!N;let T;e[68]!==l?(T=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=T):T=e[69];let O;e[70]!==X||e[71]!==ee||e[72]!==T?(O=s.jsx(H,{size:"sm",onClick:X,disabled:ee,children:T}),e[70]=X,e[71]=ee,e[72]=T,e[73]=O):O=e[73];let V;e[74]!==w||e[75]!==O?(V=s.jsxs(is,{children:[w,O]}),e[74]=w,e[75]=O,e[76]=V):V=e[76];let E;e[77]!==q||e[78]!==Z||e[79]!==V?(E=s.jsxs($t,{className:"max-w-2xl",children:[q,Z,V]}),e[77]=q,e[78]=Z,e[79]=V,e[80]=E):E=e[80];let _;return e[81]!==n||e[82]!==a||e[83]!==E?(_=s.jsx(Vt,{open:a,onOpenChange:n,children:E}),e[81]=n,e[82]=a,e[83]=E,e[84]=_):_=e[84],_},sr=[{value:"user-opencode",scope:"user",source:"opencode",label:"User / OpenCode",description:"Global OpenCode config location"},{value:"project-opencode",scope:"project",source:"opencode",label:"Project / OpenCode",description:"Current project .opencode location"},{value:"user-agents",scope:"user",source:"agents",label:"User / Agents",description:"Global .agents compatibility location"},{value:"project-agents",scope:"project",source:"agents",label:"Project / Agents",description:"Current project .agents compatibility location"}];function ja(t,e){return t==="project"&&e==="claude"?"project-claude":t==="project"&&e==="agents"?"project-agents":e==="claude"?"user-claude":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function rl(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=sr.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const wm=t=>{const e=ft.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=it(),l=an(km),f=an(Nm),[c,y]=o.useState("user"),[m,v]=o.useState("opencode"),p=Ks(Sm),F=Ks(Cm),[S,N]=o.useState(null),[h,I]=o.useState(!1);let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];const[D,q]=o.useState(u),[M,P]=o.useState(null);let g,j;e[1]!==F||e[2]!==a?(g=()=>{a&&(y("user"),v("opencode"),N(F),I(!1),q([]),P(null))},j=[a,F],e[1]=F,e[2]=a,e[3]=g,e[4]=j):(g=e[3],j=e[4]),o.useEffect(g,j);let L;e[5]!==r?(L=je=>{switch(je){case"project-opencode":return r("settings.skills.location.option.projectOpencode.label");case"user-agents":return r("settings.skills.location.option.userAgents.label");case"project-agents":return r("settings.skills.location.option.projectAgents.label");default:return r("settings.skills.location.option.userOpencode.label")}},e[5]=r,e[6]=L):L=e[6];const C=L;let A;e[7]!==r?(A=je=>{switch(je){case"project-opencode":return r("settings.skills.location.option.projectOpencode.description");case"user-agents":return r("settings.skills.location.option.userAgents.description");case"project-agents":return r("settings.skills.location.option.projectAgents.description");default:return r("settings.skills.location.option.userOpencode.description")}},e[7]=r,e[8]=A):A=e[8];const b=A;let K;e:{if(p.length===0){K=null;break e}if(S&&p.some(je=>je.id===S)){K=S;break e}if(F&&p.some(je=>je.id===F)){K=F;break e}K=p[0]?.id??null}const $=K;let k;e:{if(c!=="project"){k=null;break e}const je=$;if(!je){k=null;break e}let U;if(e[9]!==je||e[10]!==p){let pe;e[12]!==je?(pe=ve=>ve.id===je,e[12]=je,e[13]=pe):pe=e[13],U=p.find(pe),e[9]=je,e[10]=p,e[11]=U}else U=e[11];k=U?.path??null}const W=k;let Z;e[14]!==l||e[15]!==i||e[16]!==n||e[17]!==r?(Z=async je=>{const U={skillDir:je.skillDir};i?.clawdhub&&(U.clawdhub={slug:i.clawdhub.slug,version:i.clawdhub.version});const re=await l({source:je.source,subpath:je.subpath,gitIdentityId:i?.gitIdentityId,scope:je.scope,targetSource:je.targetSource,selections:[U],conflictPolicy:"prompt",conflictDecisions:je.conflictDecisions},{directory:je.directoryOverride??null});if(re.ok){R.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(re.error?.kind==="conflicts"){P({source:je.source,subpath:je.subpath,scope:je.scope,targetSource:je.targetSource,skillDir:je.skillDir,directoryOverride:je.directoryOverride??null}),q(re.error.conflicts),I(!0);return}if(re.error?.kind==="authRequired"){R.error(re.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}R.error(re.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i,e[16]=n,e[17]=r,e[18]=Z):Z=e[18];const B=Z;if(!i)return null;let Q;e[19]!==r?(Q=r("settings.skills.catalog.installSkill.title"),e[19]=r,e[20]=Q):Q=e[20];let w;e[21]!==Q?(w=s.jsx(Ht,{children:Q}),e[21]=Q,e[22]=w):w=e[22];let X;e[23]!==r?(X=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=X):X=e[24];let ee;e[25]!==i.skillName?(ee=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=ee):ee=e[26];let T;e[27]!==r?(T=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=T):T=e[28];let O;e[29]!==X||e[30]!==ee||e[31]!==T?(O=s.jsxs(Gt,{children:[X," ",ee," ",T]}),e[29]=X,e[30]=ee,e[31]=T,e[32]=O):O=e[32];let V;e[33]!==w||e[34]!==O?(V=s.jsxs(Bt,{children:[w,O]}),e[33]=w,e[34]=O,e[35]=V):V=e[35];let E;e[36]!==r?(E=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=E):E=e[37];let _;e[38]!==E?(_=s.jsx("span",{className:"typography-ui-label text-foreground",children:E}),e[38]=E,e[39]=_):_=e[39];let J;e[40]!==c||e[41]!==m?(J=ja(c,m),e[40]=c,e[41]=m,e[42]=J):J=e[42];let te;e[43]===Symbol.for("react.memo_cache_sentinel")?(te=je=>{const U=rl(je);y(U.scope),v(U.source==="agents"?"agents":"opencode")},e[43]=te):te=e[43];let ne;e[44]!==c?(ne=c==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=c,e[45]=ne):ne=e[45];let le;e[46]!==m?(le=m==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=le):le=e[47];let be;e[48]!==C||e[49]!==c||e[50]!==m?(be=C(ja(c,m)),e[48]=C,e[49]=c,e[50]=m,e[51]=be):be=e[51];let Ne;e[52]!==be?(Ne=s.jsx("span",{children:be}),e[52]=be,e[53]=Ne):Ne=e[53];let de;e[54]!==ne||e[55]!==le||e[56]!==Ne?(de=s.jsxs(Rt,{className:"w-fit gap-1.5",children:[ne,le,Ne]}),e[54]=ne,e[55]=le,e[56]=Ne,e[57]=de):de=e[57];let ue;e[58]!==b||e[59]!==C?(ue=sr.map(je=>s.jsx(dt,{value:je.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[je.scope==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),je.source==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:C(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:b(je.value)})]})},je.value)),e[58]=b,e[59]=C,e[60]=ue):ue=e[60];let Me;e[61]!==ue?(Me=s.jsx(Ot,{align:"start",children:ue}),e[61]=ue,e[62]=Me):Me=e[62];let Ce;e[63]!==J||e[64]!==de||e[65]!==Me?(Ce=s.jsxs(Mt,{value:J,onValueChange:te,children:[de,Me]}),e[63]=J,e[64]=de,e[65]=Me,e[66]=Ce):Ce=e[66];let ke;e[67]!==_||e[68]!==Ce?(ke=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[_,Ce]}),e[67]=_,e[68]=Ce,e[69]=ke):ke=e[69];let fe;e[70]!==p||e[71]!==$||e[72]!==c||e[73]!==r?(fe=c==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.skills.catalog.installSkill.field.project")}),p.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Mt,{value:$??"",onValueChange:je=>N(je),disabled:p.length===1,children:[s.jsx(Rt,{className:"w-fit",children:s.jsx(_t,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Ot,{align:"start",children:p.map(Pm)})]})]}),e[70]=p,e[71]=$,e[72]=c,e[73]=r,e[74]=fe):fe=e[74];let ze;e[75]!==i.warnings?(ze=i.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:i.warnings.join(" · ")}):null,e[75]=i.warnings,e[76]=ze):ze=e[76];let Ae;e[77]!==ke||e[78]!==fe||e[79]!==ze?(Ae=s.jsxs("div",{className:"mt-2 space-y-3",children:[ke,fe,ze]}),e[77]=ke,e[78]=fe,e[79]=ze,e[80]=Ae):Ae=e[80];let he;e[81]!==n?(he=()=>n(!1),e[81]=n,e[82]=he):he=e[82];let ge;e[83]!==r?(ge=r("settings.common.actions.cancel"),e[83]=r,e[84]=ge):ge=e[84];let Ee;e[85]!==he||e[86]!==ge?(Ee=s.jsx(H,{size:"sm",variant:"ghost",onClick:he,children:ge}),e[85]=he,e[86]=ge,e[87]=Ee):Ee=e[87];const Te=f||!i.installable||c==="project"&&!W;let Qe;e[88]!==W||e[89]!==B||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==c||e[94]!==m?(Qe=()=>{B({source:i.repoSource,subpath:i.repoSubpath,scope:c,targetSource:m,skillDir:i.skillDir,directoryOverride:W})},e[88]=W,e[89]=B,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=c,e[94]=m,e[95]=Qe):Qe=e[95];let Be;e[96]!==f||e[97]!==r?(Be=r(f?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=f,e[97]=r,e[98]=Be):Be=e[98];let Ke;e[99]!==Te||e[100]!==Qe||e[101]!==Be?(Ke=s.jsx(H,{size:"sm",disabled:Te,onClick:Qe,children:Be}),e[99]=Te,e[100]=Qe,e[101]=Be,e[102]=Ke):Ke=e[102];let Ge;e[103]!==Ee||e[104]!==Ke?(Ge=s.jsxs(is,{children:[Ee,Ke]}),e[103]=Ee,e[104]=Ke,e[105]=Ge):Ge=e[105];let qe;e[106]!==V||e[107]!==Ae||e[108]!==Ge?(qe=s.jsxs($t,{className:"max-w-md",children:[V,Ae,Ge]}),e[106]=V,e[107]=Ae,e[108]=Ge,e[109]=qe):qe=e[109];let Ie;e[110]!==n||e[111]!==a||e[112]!==qe?(Ie=s.jsx(Vt,{open:a,onOpenChange:n,children:qe}),e[110]=n,e[111]=a,e[112]=qe,e[113]=Ie):Ie=e[113];let Re;e[114]!==M||e[115]!==B?(Re=je=>{M&&(B({source:M.source,subpath:M.subpath,scope:M.scope,targetSource:M.targetSource,skillDir:M.skillDir,conflictDecisions:je,directoryOverride:M.directoryOverride??null}),I(!1))},e[114]=M,e[115]=B,e[116]=Re):Re=e[116];let $e;e[117]!==D||e[118]!==h||e[119]!==Re?($e=s.jsx(jm,{open:h,onOpenChange:I,conflicts:D,onConfirm:Re}),e[117]=D,e[118]=h,e[119]=Re,e[120]=$e):$e=e[120];let Ue;return e[121]!==Ie||e[122]!==$e?(Ue=s.jsxs(s.Fragment,{children:[Ie,$e]}),e[121]=Ie,e[122]=$e,e[123]=Ue):Ue=e[123],Ue};function km(t){return t.installSkills}function Nm(t){return t.isInstalling}function Sm(t){return t.projects}function Cm(t){return t.activeProjectId}function Pm(t){return s.jsx(dt,{value:t.id,children:t.label||t.path},t.id)}const Im=async()=>{try{const t=kn()?.settings;if(t)return(await t.load())?.settings||{};const e=await lt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Am=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=it(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:f,loadCatalog:c,loadSource:y,loadMoreClawdHub:m,isLoadingCatalog:v,isLoadingSource:p,isLoadingMore:F,loadedSourceIds:S,clawdhubHasMoreBySource:N,lastCatalogError:h}=an(Cs(w=>({sources:w.sources,itemsBySource:w.itemsBySource,selectedSourceId:w.selectedSourceId,setSelectedSource:w.setSelectedSource,loadCatalog:w.loadCatalog,loadSource:w.loadSource,loadMoreClawdHub:w.loadMoreClawdHub,isLoadingCatalog:w.isLoadingCatalog,isLoadingSource:w.isLoadingSource,isLoadingMore:w.isLoadingMore,loadedSourceIds:w.loadedSourceIds,clawdhubHasMoreBySource:w.clawdhubHasMoreBySource,lastCatalogError:w.lastCatalogError}))),[I,u]=o.useState(""),[D,q]=o.useState(!1),[M,P]=o.useState(!1),[g,j]=o.useState(null),[L,C]=o.useState(!1),[A,b]=o.useState(!1);o.useEffect(()=>{c()},[c]),o.useEffect(()=>{l&&(S[l]||y(l))},[l,S,y]);const K=o.useMemo(()=>l?r[l]||[]:[],[r,l]),$=o.useMemo(()=>{const w=I.trim().toLowerCase();return w?K.filter(X=>{const ee=X.skillName.toLowerCase(),T=(X.description||"").toLowerCase(),O=(X.frontmatterName||"").toLowerCase();return ee.includes(w)||T.includes(w)||O.includes(w)}):K},[K,I]),k=o.useMemo(()=>i.find(w=>w.id===l)||null,[i,l]),W=!!(l&&l.startsWith("custom:")),Z=k?.source==="clawdhub:registry"||k?.sourceType==="clawdhub",B=!!(l&&(N[l]??!0)),Q=async()=>{if(!(!l||!W)){C(!0);try{const w=await Im(),ee=(Array.isArray(w?.skillCatalogs)?w?.skillCatalogs:[]).filter(T=>T.id!==l);await vt({skillCatalogs:ee}),await c({refresh:!0}),b(!1)}finally{C(!1)}}};return s.jsxs(s.Fragment,{children:[s.jsxs(as,{title:n("settings.skills.catalog.page.title"),showSaveStatus:!1,children:[a&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(tr,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:w=>e(w),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsxs(Le,{title:n("settings.skills.catalog.page.section.sourceRepository"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsxs(Mt,{value:l||"",onValueChange:w=>f(w),children:[s.jsx(Rt,{size:Ut,className:ye(sn,"w-fit"),children:s.jsx(_t,{placeholder:n("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:k?.label})}),s.jsx(Ot,{align:"start",children:i.map(w=>s.jsx(dt,{value:w.id,children:w.label},w.id))})]}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l?y(l,{refresh:!0}):c({refresh:!0})},disabled:v||p,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(z,{name:"refresh",className:ye("h-3.5 w-3.5",(v||p)&&"animate-spin")})}),W&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>b(!0),disabled:L,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(H,{"data-settings-item":"skills.catalog.add-catalog",size:"xs",className:"!font-normal gap-1",onClick:()=>q(!0),children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})," ",n("settings.skills.catalog.page.actions.addCatalog")]})]}),s.jsxs("div",{"data-settings-item":"skills.catalog.search",className:"py-1.5",children:[s.jsxs("div",{className:"relative",children:[s.jsx(z,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{value:I,onChange:w=>u(w.target.value),placeholder:n("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:v?n("settings.skills.catalog.page.loading.catalog"):n("settings.skills.catalog.page.foundCount",{count:$.length})})]})]}),h&&s.jsx(Le,{children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:n("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:h.message})]})}),s.jsxs(Le,{children:[$.length===0&&!p?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:n("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.catalog.page.empty.noSkillsDescription")})]}):p?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(z,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:n("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:$.map(w=>{const X=w.installed?.isInstalled,ee=w.installed?.scope;return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:w.skillName}),X&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:ee||n("settings.skills.catalog.page.badge.unknown")})}),!w.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.notInstallable")})]}),w.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:w.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:n("settings.skills.catalog.shared.noDescription")}),w.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[w.clawdhub.owner&&s.jsxs("span",{children:[n("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:w.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(z,{name:"download",className:"h-3 w-3"}),w.clawdhub.downloads?.toLocaleString()??0]}),(w.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(z,{name:"star",className:"h-3 w-3"}),w.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",w.clawdhub.version]})]}),w.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:w.warnings.join(" · ")}):null]}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!w.installable,onClick:()=>{j(w),P(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})},`${w.sourceId}:${w.skillDir}`)})}),Z&&B&&!p&&$.length>0&&s.jsx("div",{className:"flex justify-center mt-2",children:s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:F,children:n(F?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]})]}),s.jsx(mm,{open:D,onOpenChange:q}),s.jsx(wm,{open:M,onOpenChange:P,item:g}),s.jsx(Vt,{open:A,onOpenChange:w=>{L||b(w)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Gt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>b(!1),disabled:L,children:n("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{Q()},disabled:L,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},Em=()=>{const t=ft.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Am,{mode:"external",onModeChange:Lm,showModeTabs:!1}),t[0]=e):e=t[0],e},Tm="SKILL.md",Dm="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",qa=(t,e)=>{const a=dd({description:t}).trimEnd(),n=e.trimStart();return`---
22
- ${a}
23
- ---${n?`
24
-
25
- ${n}`:`
26
- `}`},Mm=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),ol=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let a=null;try{const n=pd(e[1]);if(Mm(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},Rm=(t,e)=>{const a=ol(t);return qa(e,a.instructions)},Om=()=>{const{t}=it(),{currentTheme:e}=er(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skills:f,skillDraft:c,setSkillDraft:y,setSelectedSkill:m}=rn(Cs(U=>({selectedSkillName:U.selectedSkillName,getSkillByName:U.getSkillByName,getSkillDetail:U.getSkillDetail,createSkill:U.createSkill,updateSkill:U.updateSkill,skills:U.skills,skillDraft:U.skillDraft,setSkillDraft:U.setSkillDraft,setSelectedSkill:U.setSelectedSkill}))),v=a?n(a):null,p=!!(c&&c.name===a&&!v),F=!!(a&&!v&&!c),S=v?.path==="<built-in>";o.useEffect(()=>{F&&m(null)},[F,m]);const[N,h]=o.useState(""),[I,u]=o.useState("user"),[D,q]=o.useState("opencode"),[M,P]=o.useState(""),[g,j]=o.useState(""),[L,C]=o.useState(()=>qa("","")),[A,b]=o.useState("edit"),[K,$]=o.useState([]),[k,W]=o.useState([]),[Z,B]=o.useState(!1),[Q,w]=o.useState(!1),[X,ee]=o.useState(""),[T,O]=o.useState(""),[V,E]=o.useState(!1),[_,J]=o.useState(""),[te,ne]=o.useState(""),[le,be]=o.useState(null),[Ne,de]=o.useState(!1),[ue,Me]=o.useState(""),[Ce,ke]=o.useState(null),[fe,ze]=o.useState(!1),Ae=p?N.trim()!==""||M.trim()!==""||g.trim()!==""||k.length>0:M!==X||g!==T,he=le?te!==ue:_.trim()!=="",ge=o.useCallback(U=>{switch(U){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),Ee=o.useCallback(U=>{switch(U){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);o.useEffect(()=>{(async()=>{if(p&&c){const re=c.description||"",pe=c.instructions||"";h(c.name||""),u(c.scope||"user"),q(c.source==="agents"?"agents":"opencode"),P(re),j(pe),C(qa(re,pe)),ee(""),O(""),$([]),W(c.pendingFiles||[])}else if(a&&v){w(!0);try{const re=await i(a);if(re){const pe=re.sources.md,ve=pe.description||"",ae=pe.instructions||"";P(ve),j(ae),C(qa(ve,ae)),ee(ve),O(ae),$(pe.supportingFiles||[])}}catch(re){console.error("Failed to load skill details:",re)}finally{w(!1)}}})()},[v,p,a,f,c,i]);const Te=ce(U=>U.editorFontSize),Qe=o.useMemo(()=>{const U=[Tr(e,{fontSize:Te})],re=dr(Tm);return re&&U.push(re),U.push(Mr.lineWrapping),U},[e,Te]),Be=o.useMemo(()=>{const U=_.trim()||"supporting-file.md",re=Hl(U),pe=!!re&&re!=="markdown",ve=[Tr(e,pe?{syntaxColors:!1,fontSize:Te}:{fontSize:Te})],ae=dr(U);return ae&&ve.push(ae),pe&&re&&ve.push(md({language:re,themeName:e.metadata.id,theme:gd(e)})),ve.push(Mr.lineWrapping),ve},[e,_,Te]),Ke=o.useCallback(U=>{P(U),C(re=>Rm(re,U))},[]),Ge=o.useCallback(U=>{C(U);const re=ol(U);P(re.description??""),j(re.instructions)},[]),qe=async()=>{const U=p?N.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!U){R.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(U)||U.length>64){R.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!M.trim()){R.error(t("settings.skills.page.toast.descriptionRequired"));return}if(p&&f.some(re=>re.name===U)){R.error(t("settings.skills.page.toast.skillExists"));return}B(!0);try{const re={name:U,description:M.trim(),instructions:g.trim()||void 0,scope:p?I:void 0,source:p?D:void 0,targetPath:p?void 0:v?.path,supportingFiles:p&&k.length>0?k:void 0};let pe;if(p?(pe=await r(re),pe&&(y(null),W([]),m(U))):(pe=await l(U,re),pe&&(ee(M.trim()),O(g.trim()))),pe){const ve=ln.getState().changes.some(ae=>ae.scope==="skills"&&ae.id.startsWith(`skills:${U}:`));R.success(t(ve?"settings.view.pendingRestart.saved":p?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else R.error(t(p?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(re){console.error("Error saving skill:",re),R.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{B(!1)}},Ie=()=>{be(null),J(""),ne(""),Me(""),E(!0)},Re=async U=>{if(be(U),J(U),p){const pe=k.find(ve=>ve.path===U)?.content||"";ne(pe),Me(pe),E(!0);return}if(a){de(!0),E(!0);try{const{readSupportingFile:re}=rn.getState(),pe=await re(a,U);ne(pe||""),Me(pe||"")}catch{R.error(t("settings.skills.page.toast.loadFileContentFailed")),ne(""),Me("")}finally{de(!1)}}},$e=async()=>{if(!_.trim()){R.error(t("settings.skills.page.toast.fileNameRequired"));return}const U=_.trim(),re=le!==null;if(p){if(re)W(ae=>ae.map(_e=>_e.path===le?{path:U,content:te}:_e)),R.success(t("settings.skills.page.toast.fileUpdated",{path:U}));else{if(k.some(ae=>ae.path===U)){R.error(t("settings.skills.page.toast.fileExists"));return}W(ae=>[...ae,{path:U,content:te}]),R.success(t("settings.skills.page.toast.fileAdded",{path:U}))}E(!1),be(null);return}if(!a){R.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:pe}=rn.getState();if(await pe(a,U,te)){R.success(re?t("settings.skills.page.toast.fileUpdated",{path:U}):t("settings.skills.page.toast.fileCreated",{path:U})),E(!1),be(null);const ae=await i(a);ae&&$(ae.sources.md.supportingFiles||[])}else R.error(t(re?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ue=U=>{if(p){W(re=>re.filter(pe=>pe.path!==U)),R.success(t("settings.skills.page.toast.fileRemoved",{path:U}));return}a&&ke(U)},je=async()=>{if(!Ce||!a)return;ze(!0);const{deleteSupportingFile:U}=rn.getState();if(await U(a,Ce)){R.success(t("settings.skills.page.toast.fileDeleted",{path:Ce}));const pe=await i(a);pe&&$(pe.sources.md.supportingFiles||[]),ke(null)}else R.error(t("settings.skills.page.toast.deleteFileFailed"));ze(!1)};return!a&&!c||F?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):Q?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(s.Fragment,{children:[s.jsxs(as,{title:p?t("settings.skills.page.title.newSkill"):a,description:v?t("settings.skills.page.subtitle.skillLocation",{location:ge(ja(v.scope,v.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(Le,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[p&&s.jsxs(qt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(He,{value:N,onChange:U=>h(U.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Mt,{value:ja(I,D),onValueChange:U=>{const re=rl(U);u(re.scope),q(re.source==="agents"?"agents":"opencode")},children:[s.jsxs(Rt,{size:Ut,className:"w-fit gap-1.5",children:[I==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),D==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:ge(ja(I,D))})]}),s.jsx(Ot,{align:"start",children:sr.map(U=>s.jsx(dt,{value:U.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[U.scope==="user"?s.jsx(z,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"folder",className:"h-3.5 w-3.5"}),U.source==="agents"?s.jsx(z,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:ge(U.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ee(U.value)})]})},U.value))})]})]}),s.jsx(Qt,{label:s.jsxs(s.Fragment,{children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),info:t("settings.skills.page.field.descriptionHint"),controlClassName:"w-full max-w-none",children:s.jsx(Ns,{value:M,onChange:U=>Ke(U.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:S})})]}),s.jsx(Le,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(ud,{currentMode:A==="preview"?"preview":"edit",onToggle:()=>b(U=>U==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:ye("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Dm),children:A==="preview"?s.jsx(Ms,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Gl,{content:L,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(Dr,{value:L,onChange:Ge,readOnly:S,extensions:Qe,className:"h-full",enableSearch:!0})})}),s.jsx(Le,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ie,disabled:S,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const U=p?k:K;return U.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:U.map(re=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Re(re.path),children:[s.jsx(z,{name:"file",className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:re.path}),p&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),!S&&s.jsx(H,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:pe=>{pe.stopPropagation(),Ue(re.path)},children:s.jsx(z,{name:"delete-bin",className:"h-3 w-3"})})]},re.path))})})()}),s.jsx(Le,{children:s.jsx(H,{onClick:qe,disabled:S||Z||!Ae,size:"xs",className:"!font-normal",children:t(Z?"settings.common.actions.saving":p?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Vt,{open:Ce!==null,onOpenChange:U=>{!U&&!fe&&ke(null)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Gt,{children:t("settings.skills.page.deleteFileDialog.description",{path:Ce??""})})]}),s.jsxs(is,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>ke(null),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:je,disabled:fe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Vt,{open:V,onOpenChange:U=>{E(U),U||be(null)},children:s.jsxs($t,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Bt,{className:"flex-shrink-0",children:[s.jsx(Ht,{children:t(le?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Gt,{children:t(le?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),Ne?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("label",{className:Dt,children:t("settings.skills.page.fileDialog.field.filePath")}),!le&&s.jsx(Yt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(He,{value:_,onChange:U=>J(U.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:le!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Dt} flex-shrink-0`,children:t("settings.skills.page.fileDialog.field.content")}),s.jsx("div",{className:"h-[45vh] min-h-[250px] max-h-[55vh] overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",children:s.jsx(Dr,{value:te,onChange:ne,extensions:Be,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(is,{className:"mt-4",children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>{E(!1),be(null)},children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:$e,disabled:Ne||!he,children:t(le?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},Jr=t=>{const e=ft.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(Em,{}):s.jsx(Om,{}),e[0]=n,e[1]=i):i=e[1],i};function Lm(){}const Fm=t=>{const e=ft.c(38),{onItemSelect:a}=t,{t:n}=it(),i=Ks(Km),r=ce(zm),l=ce(Um),{currentTheme:f}=er();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=ps(),e[0]=c):c=e[0];const y=c,m=_m;let v,p;e[1]!==i||e[2]!==r||e[3]!==l?(v=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(g=>g.id===r)||l(i[0].id)},p=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=v,e[5]=p):(v=e[4],p=e[5]),o.useEffect(v,p);let F;e[6]===Symbol.for("react.memo_cache_sentinel")?(F=ye("border-b px-3","pt-4 pb-3"),e[6]=F):F=e[6];let S;e[7]!==n?(S=n("settings.page.projects.title"),e[7]=n,e[8]=S):S=e[8];let N;e[9]!==S?(N=s.jsx("h2",{className:`${Ws} mb-3`,children:S}),e[9]=S,e[10]=N):N=e[10];let h;e[11]!==i.length||e[12]!==n?(h=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=h):h=e[13];let I;e[14]!==h?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:h}),e[14]=h,e[15]=I):I=e[15];let u;e[16]!==n?(u=!y&&s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:m,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(z,{name:"add",className:"size-4"})}),e[16]=n,e[17]=u):u=e[17];let D;e[18]!==I||e[19]!==u?(D=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,u]}),e[18]=I,e[19]=u,e[20]=D):D=e[20];let q;e[21]!==D||e[22]!==N?(q=s.jsxs("div",{className:F,children:[N,D]}),e[21]=D,e[22]=N,e[23]=q):q=e[23];let M;if(e[24]!==f||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let g;e[30]!==f||e[31]!==a||e[32]!==r||e[33]!==l?(g=j=>{const L=j.id===r,C=j.icon?Wl[j.icon]:null,A=j.color?Jl[j.color]??null:null,b=C?s.jsx(z,{name:C,className:ye("h-4 w-4",L?"text-foreground":"text-muted-foreground/70"),style:A?{color:A}:void 0}):s.jsx(z,{name:"folder",className:ye("h-4 w-4",L?"text-foreground":"text-muted-foreground/70"),style:A?{color:A}:void 0}),K=j.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:j.iconBackground?{backgroundColor:j.iconBackground}:void 0,children:s.jsx(Ql,{project:j,options:{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground},className:"h-full w-full object-contain",fallback:b})}):b;return s.jsx($i,{title:j.label||j.path,icon:K,selected:L,onSelect:()=>{l(j.id),a?.()}},j.id)},e[30]=f,e[31]=a,e[32]=r,e[33]=l,e[34]=g):g=e[34],M=i.map(g),e[24]=f,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=M}else M=e[29];let P;return e[35]!==q||e[36]!==M?(P=s.jsx(al,{variant:"background",header:q,children:M}),e[35]=q,e[36]=M,e[37]=P):P=e[37],P};function Km(t){return t.projects}function zm(t){return t.settingsProjectsSelectedId}function Um(t){return t.setSettingsProjectsSelectedId}function _m(){ql.requestDirectoryDialog()}const Vm=()=>{const t=ft.c(30),{t:e}=it(),a=Ks($m),n=Ks(Bm),i=ce(Hm),r=ce(Gm);let l;e:{if(!i){l=null;break e}let h;t[0]!==a||t[1]!==i?(h=a.find(I=>I.id===i)??null,t[0]=a,t[1]=i,t[2]=h):h=t[2],l=h}const f=l;let c,y;t[3]!==a||t[4]!==i||t[5]!==r?(c=()=>{if(a.length===0){r(null);return}i&&a.some(h=>h.id===i)||r(a[0].id)},y=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=c,t[7]=y):(c=t[6],y=t[7]),o.useEffect(c,y);let m;t[8]!==f||t[9]!==n?(m=async h=>{f&&n(f.id,{label:h.label,icon:h.icon,color:h.color,iconBackground:h.iconBackground,defaultModel:h.defaultModel??null})},t[8]=f,t[9]=n,t[10]=m):m=t[10];const v=m;if(!f){let h;t[11]!==e?(h=e("settings.page.projects.title"),t[11]=e,t[12]=h):h=t[12];let I;t[13]!==e?(I=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=I):I=t[14];let u;t[15]!==I?(u=s.jsx("p",{className:"typography-meta text-muted-foreground",children:I}),t[15]=I,t[16]=u):u=t[16];let D;return t[17]!==h||t[18]!==u?(D=s.jsx(as,{title:h,showSaveStatus:!0,children:u}),t[17]=h,t[18]=u,t[19]=D):D=t[19],D}let p;t[20]!==f.label||t[21]!==e?(p=f.label??e("settings.projects.page.title.default"),t[20]=f.label,t[21]=e,t[22]=p):p=t[22];const F=p;let S;t[23]!==v||t[24]!==f?(S=s.jsx(nd,{project:f,onIdentitySave:v}),t[23]=v,t[24]=f,t[25]=S):S=t[25];let N;return t[26]!==F||t[27]!==f.path||t[28]!==S?(N=s.jsx(as,{title:F,description:f.path,showSaveStatus:!0,outerClassName:"bg-background",children:S}),t[26]=F,t[27]=f.path,t[28]=S,t[29]=N):N=t[29],N};function $m(t){return t.projects}function Bm(t){return t.updateProjectMeta}function Hm(t){return t.settingsProjectsSelectedId}function Gm(t){return t.setSettingsProjectsSelectedId}const Hi=()=>Math.floor(2e4+Math.random()*3e4),qm=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},Wm=()=>{if(typeof navigator>"u")return;const t=(navigator.userAgent||"").toLowerCase();if(t.includes("mac"))return"macos";if(t.includes("win"))return"windows";if(t.includes("linux"))return"linux"},Qr=t=>{switch((t||"").toLowerCase()){case"ios":return"iOS";case"android":return"Android";case"macos":case"darwin":return"macOS";case"windows":case"win32":return"Windows";case"linux":return"Linux";default:return null}},Yr=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingOpenChamber";case"updating":return"settings.remoteInstances.page.phase.updatingOpenChamber";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},Jm=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),ll=t=>!!(t&&Jm.has(t)),Zr=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||ll(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Qm=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,Ym=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:Hi(),remoteHost:"127.0.0.1",remotePort:80}),Zm=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",tn=t=>{const e=ft.c(7),{label:a,hint:n}=t;let i;e[0]!==a?(i=s.jsx("span",{children:a}),e[0]=a,e[1]=i):i=e[1];let r;e[2]!==n?(r=s.jsx(Yt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=r):r=e[3];let l;return e[4]!==i||e[5]!==r?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Dt}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},Xm=t=>{switch(t){case"remote":return"settings.remoteInstances.page.forwardTypeDescription.remote";case"dynamic":return"settings.remoteInstances.page.forwardTypeDescription.dynamic";default:return"settings.remoteInstances.page.forwardTypeDescription.local"}},Xr=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},eu=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},tu=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const a=Number(e[1]),n=Number.isFinite(a)?new Date(a).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),r=e[3]||"";return`[${n}] [${i}] ${r}`},Gi=(t="",e="")=>({id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`header-${Date.now()}-${Math.random().toString(16).slice(2)}`,name:t,value:e}),su=t=>t.trim().toLowerCase()==="authorization",ki=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!su(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},nu=t=>Object.entries(t||{}).map(([e,a])=>Gi(e,a)),cl=()=>{if(typeof window>"u")return null;const e=Na()||window.location.href;try{const a=Number(new URL(e).port||window.location.port);return Number.isFinite(a)&&a>0?a:null}catch{const a=Number(window.location.port);return Number.isFinite(a)&&a>0?a:null}},eo=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},au=async()=>{const t=Gn(Na())||window.location.origin;if(!cs()||!Sa())return t;let e;try{e=await lt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}})}catch{return t}if(!e.ok||(await e.json().catch(()=>null))?.desktopLanAccessActive!==!0)return t;const n=await Bo(),i=cl();return!n||!i?t:`http://${n}:${i}`},Ni=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},iu=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},ru=()=>{const{t}=it(),e=ce(x=>x.timeFormatPreference),{clientAuth:a}=Ko(),n=cs(),i=ks(x=>x.instances),r=ks(x=>x.statusesById),l=ks(x=>x.importCandidates),f=ks(x=>x.isLoading),c=ks(x=>x.isImportsLoading),y=ks(x=>x.isSaving),m=ks(x=>x.error),v=ks(x=>x.load),p=ks(x=>x.loadImports),F=ks(x=>x.refreshStatuses),S=ks(x=>x.upsertInstance),N=ks(x=>x.createFromCommand),h=ks(x=>x.removeInstance),I=ks(x=>x.connect),u=ks(x=>x.disconnect),D=ks(x=>x.retry),q=ce(x=>x.settingsRemoteInstancesSelectedId),M=ce(x=>x.setSettingsRemoteInstancesSelectedId),P=o.useMemo(()=>q&&i.find(x=>x.id===q)||null,[i,q]),[g,j]=o.useState(null),[L,C]=o.useState(!1),[A,b]=o.useState(!1),[K,$]=o.useState(null),[k,W]=o.useState([]),[Z,B]=o.useState(null),[Q,w]=o.useState(""),[X,ee]=o.useState(!1),[T,O]=o.useState({}),[V,E]=o.useState(!1),[_,J]=o.useState(!1),[te,ne]=o.useState(()=>Date.now()),[le,be]=o.useState([]),[Ne,de]=o.useState({}),[ue,Me]=o.useState("local"),[Ce,ke]=o.useState(!1),[fe,ze]=o.useState(!1),[Ae,he]=o.useState(""),[ge,Ee]=o.useState(""),[Te,Qe]=o.useState(""),[Be,Ke]=o.useState([]),[Ge,qe]=o.useState(""),[Ie,Re]=o.useState(null),[$e,Ue]=o.useState(!1),[je,U]=o.useState(!1),[re,pe]=o.useState(null),[ve,ae]=o.useState(""),[_e,Ze]=o.useState(""),[G,Fe]=o.useState(""),[Ye,st]=o.useState([]),[et,wt]=o.useState([]),[pt,mt]=o.useState([]),[ot,bt]=o.useState(!1),[ut,At]=o.useState(""),[ie,Pe]=o.useState(null),[Ve,We]=o.useState(null),[kt,St]=o.useState(null),[Wt,Y]=o.useState(null),[xe,Oe]=o.useState(!1),[we,rt]=o.useState(!1),[ct,at]=o.useState("configure"),[Ct,ss]=o.useState(!1),[es,ds]=o.useState("relay"),[Jt,Nt]=o.useState(!0),[Pt,Et]=o.useState(null),yt=o.useMemo(()=>et.filter(x=>!!x.revokedAt).length,[et]),[zt,Zt]=o.useState(!1),[js,oe]=o.useState("ssh user@example.com"),[ht,Se]=o.useState("");o.useEffect(()=>{v(),p()},[v,p]);const nt=o.useCallback(async()=>{ke(!0),Re(null);try{const x=await jr();be(x.hosts||[]),Me(x.defaultHostId||"local")}catch(x){Re(x instanceof Error?x.message:String(x))}finally{ke(!1)}},[]);o.useEffect(()=>{nt()},[nt]);const xt=o.useCallback(async(x,se=ue)=>{ze(!0),Re(null);try{await wr({hosts:x,defaultHostId:se,initialHostChoiceCompleted:!0}),be(x),Me(se)}catch(De){Re(De instanceof Error?De.message:String(De))}finally{ze(!1)}},[ue]),It=o.useCallback(async()=>{const x=kr(ge);if(!x){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const se=x.persistedUrl,Xe={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Ae.trim()||la(se),url:se,apiUrl:se,...Te.trim()?{clientToken:Te.trim()}:{},...ki(Be)?{requestHeaders:ki(Be)}:{}};await xt([Xe,...le],ue),he(""),Ee(""),Qe(""),Ke([]),Ue(!1),x.redeemUrl&&Ni(x.redeemUrl)},[ue,Be,le,Ae,Te,ge,xt,t]),Kt=o.useCallback(async()=>{const x=Tc(Ge);if(!x){Re(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const se=await Dc().catch(()=>""),De=JSON.stringify({pairingId:x.pairingId,secret:x.secret,clientLabel:x.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:Wm(),...se?{dedupeKey:`desktop:${se}`}:{}}),Xe={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:De},Ft=async Lt=>{if(!Lt.ok)return null;const os=await Lt.json().catch(()=>null);return(typeof os?.clientToken=="string"?os.clientToken.trim():"")||null},ws=[...x.candidates].sort((Lt,os)=>(Lt.type==="relay"?1:0)-(os.type==="relay"?1:0));let ts=null;for(const Lt of ws){if(Lt.type==="relay"){const Us=Mc({relayUrl:Lt.relayUrl,serverId:Lt.serverId,hostEncPubJwk:Lt.hostEncPubJwk,...Lt.grant?{grant:Lt.grant}:{}});try{const Os=await Us.fetch("/api/client-auth/pairing/redeem",Xe),Oa=await Ft(Os);if(Oa){ts={kind:"relay",relay:{relayUrl:Lt.relayUrl,serverId:Lt.serverId,hostEncPubJwk:Lt.hostEncPubJwk},token:Oa};break}}catch{}finally{Us.close()}continue}const os=Gn(Lt.url);if(os)try{const Us=await fetch(`${os}/api/client-auth/pairing/redeem`,Xe),Os=await Ft(Us);if(Os){ts={kind:"direct",url:os,token:Os};break}}catch{}}if(!ts){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const Ds=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,Xs=x.candidates.find(Lt=>Lt.type==="relay"),Rs=ts.kind==="relay"?ts.relay:Xs?{relayUrl:Xs.relayUrl,serverId:Xs.serverId,hostEncPubJwk:Xs.hostEncPubJwk}:void 0,na=x.candidates.filter(Lt=>Lt.type!=="relay").map(Lt=>Gn(Lt.url)).find(Lt=>!!Lt),Cn=ts.kind==="direct"?ts.url:na,{token:aa}=ts,Tt=Cn||(Rs?Rc(Rs.serverId):null);if(!Tt){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const Xt={url:Tt,apiUrl:Cn||void 0,clientToken:aa,...Rs?{relay:Rs}:{}},Pn=le.find(Lt=>Rs?Lt.relay?.serverId===Rs.serverId:!Lt.relay&&Gn(Lt.apiUrl||Lt.url)===Tt);if(Pn){const Lt=le.map(os=>os.id===Pn.id?{...os,label:x.label||os.label,...Xt}:os);await xt(Lt,ue)}else await xt([{id:Ds(),label:x.label||la(Tt),...Xt},...le],ue);qe(""),Re(null),U(!1)},[Ge,ue,le,xt,t]),hs=o.useCallback(async x=>{const se=le.filter(Xe=>Xe.id!==x);await xt(se,ue===x?"local":ue),re===x&&pe(null)},[ue,re,le,xt]),Ps=o.useCallback(x=>{pe(x.id),ae(x.label),Ze(x.apiUrl||x.url),Fe(x.clientToken||""),st(nu(x.requestHeaders)),Re(null)},[]),fs=o.useCallback(async()=>{if(!re)return;const x=kr(_e);if(!x){Re(t("desktopHostSwitcher.error.invalidUrl"));return}const se=x.persistedUrl,De=le.map(Xe=>Xe.id===re?{...Xe,label:ve.trim()||la(se),url:se,apiUrl:se,clientToken:G.trim()||void 0,requestHeaders:ki(Ye)}:Xe);await xt(De,ue),pe(null),x.redeemUrl&&Ni(x.redeemUrl)},[ue,Ye,ve,G,_e,re,le,xt,t]),Kn=o.useCallback(async()=>{const x=js.trim();if(!x){R.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const se=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await N(se,x,ht.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),M(se),Zt(!1),oe("ssh user@example.com"),Se(""),R.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(De){R.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:De instanceof Error?De.message:String(De)})}},[N,M,js,ht,t]),zn=o.useCallback(async x=>{await xt(le,x)},[le,xt]);o.useEffect(()=>{if(!n||le.length===0)return;let x=!1;return Promise.all(le.map(async se=>{const De=()=>Uc(se.relay,{clientToken:se.clientToken||null,requestHeaders:se.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(se.relay&&!se.apiUrl)return[se.id,await De()];const Xe=Gn(Oc(se));if(!Xe)return[se.id,se.relay?await De():{status:"unreachable",latencyMs:0}];const Ft=await Lc(Xe,{clientToken:se.clientToken||null,requestHeaders:se.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Ft.status==="unreachable"&&se.relay){const ws=await De();if(ws.status==="ok")return[se.id,ws]}return[se.id,Ft]})).then(se=>{x||de(Object.fromEntries(se))}),()=>{x=!0}},[le,n]);const Is=o.useCallback(async x=>{if(a){x?.silent||bt(!0),x?.silent||Pe(null);try{const[se,De]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);wt(se),De&&mt(De)}catch(se){x?.silent||Pe(se instanceof Error?se.message:String(se))}finally{x?.silent||bt(!1)}}},[a]),ta=o.useRef(!1);o.useEffect(()=>{if(!(!we||ct!=="result"||!kt)){if(pt.some(x=>x.id===kt)){ta.current=!0;return}ta.current&&(St(null),rt(!1),et.some(x=>x.pairingId===kt)&&R.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[we,ct,kt,pt,et,t]);const si=o.useCallback(async x=>{if(a)try{await a.cancelPairing(x),mt(se=>se.filter(De=>De.id!==x)),await Is({silent:!0})}catch(se){Pe(se instanceof Error?se.message:String(se))}},[a,Is]);o.useEffect(()=>{if(!a)return;Is();const x=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Is({silent:!0})},5e3);return()=>window.clearInterval(x)},[a,Is]);const Pa=o.useCallback(async()=>{if(a?.getPairingTransports)try{const Xe=await a.getPairingTransports();return{localUrl:Xe.local,lanUrl:Xe.lan,relayAvailable:Xe.relayAvailable}}catch{}const x=cl(),se=x?`http://127.0.0.1:${x}`:eo(window.location.origin)?window.location.origin:null;let De=null;try{const Xe=Gn(await au());De=Xe&&!eo(Xe)?Xe:null}catch{}return{localUrl:se,lanUrl:De,relayAvailable:!0}},[a]),ni=o.useCallback(async()=>{Pe(null),We(null),Y(null),Oe(!1),St(null),at("configure"),Nt(!0),rt(!0);const x=await Pa();Et(x),ds(x.relayAvailable?"relay":x.lanUrl?"lan":"local")},[Pa]),ai=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Pt)){Pe(null),ss(!0);try{const x=ut.trim()||void 0;let se,De,Xe=!0;es==="local"?(se=Pt.localUrl??void 0,De=!1):es==="lan"?(se=Pt.lanUrl??void 0,De=Jt):Jt&&Pt.lanUrl?(se=Pt.lanUrl,De=!0):(Xe=!1,De=!0);const{pairing:Ft,server:ws}=await a.createPairingSession({label:x,allowedClientKinds:["mobile","desktop"],serverUrl:se,includeRelay:De,includeDirect:Xe}),ts=Fc({pairingId:Ft.id,secret:Ft.secret,label:ws.label,fingerprint:Ft.fingerprint??void 0,expiresAt:Ft.expiresAt,candidates:ws.candidates}),Ds=Kc(ts);We(Ds),Y(await Yo.toDataURL(Ds,{width:1024,margin:2,errorCorrectionLevel:"L"})),Oe(!1),ta.current=!1,St(Ft.id),at("result"),await Is({silent:!0})}catch(x){Pe(x instanceof Error?x.message:String(x))}finally{ss(!1)}}},[a,Pt,es,Jt,ut,Is]),ii=o.useCallback(()=>{Ve&&va(Ve).then(x=>{x.ok&&(Oe(!0),window.setTimeout(()=>Oe(!1),2e3))})},[Ve]),ri=o.useCallback(async x=>{if(!a)return;const se=x.clientKind==="desktop-local";Pe(null);try{if(await a.revokeClient(x.id),se&&cs()){const De=await jr();await wr({hosts:De.hosts,defaultHostId:De.defaultHostId,initialHostChoiceCompleted:De.initialHostChoiceCompleted,localClientToken:null}),wt(Xe=>Xe.map(Ft=>Ft.id===x.id?{...Ft,revokedAt:new Date().toISOString()}:Ft)),zc({apiBaseUrl:Na(),clientToken:null,runtimeKey:"local"});return}await Is()}catch(De){Pe(De instanceof Error?De.message:String(De))}},[a,Is]),oi=o.useCallback(async()=>{if(a){Pe(null);try{await a.purgeRevokedClients(),await Is()}catch(x){Pe(x instanceof Error?x.message:String(x))}}},[a,Is]);o.useEffect(()=>{j(P)},[P]),o.useEffect(()=>{if(!q)return;const x=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||F()},2e3);return()=>{window.clearInterval(x)}},[F,q]),o.useEffect(()=>{let x=null,se=Date.now();const De=()=>{const Ft=Date.now();Ft-se>=1e3&&(ne(Ft),se=Ft),x=requestAnimationFrame(De)};(typeof document>"u"||document.visibilityState==="visible")&&(x=requestAnimationFrame(De));const Xe=()=>{document.visibilityState==="visible"&&x===null?x=requestAnimationFrame(De):document.visibilityState!=="visible"&&x!==null&&(cancelAnimationFrame(x),x=null)};return document.addEventListener("visibilitychange",Xe),()=>{document.removeEventListener("visibilitychange",Xe),x!==null&&cancelAnimationFrame(x)}},[]);const As=q?r[q]:null,zs=As?.phase,Un=zs==="ready",Js=zs==="degraded",cn=ll(zs),dn=Un||(cn||Js),li=As?Math.max(0,te-As.updatedAtMs):0,_n=Js&&li>12e3,ci=o.useMemo(()=>!g||!P?!1:JSON.stringify(g)!==JSON.stringify(P),[g,P]),ms=o.useCallback(x=>{j(se=>se&&x(se))},[]),di=o.useCallback(async()=>{if(!g)return;const x=iu(g);if(!x.sshCommand.trim()){R.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(x.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(x.auth.sshPassword?.enabled&&x.auth.sshPassword.value?.trim()&&x.auth.sshPassword.store!=="settings"){const se=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));x.auth.sshPassword.store=se?"settings":"never",se||(x.auth.sshPassword.value=void 0)}if(x.auth.openchamberPassword?.enabled&&x.auth.openchamberPassword.value?.trim()&&x.auth.openchamberPassword.store!=="settings"){const se=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));x.auth.openchamberPassword.store=se?"settings":"never",se||(x.auth.openchamberPassword.value=void 0)}try{await S(x),R.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(se){R.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:se instanceof Error?se.message:String(se)})}}},[g,t,S]),Qs=o.useCallback(async(x,se)=>{const De=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await N(De,`ssh ${se}`,x),M(De),R.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Xe){return R.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Xe instanceof Error?Xe.message:String(Xe)}),!1}},[N,M,t]),Ys=o.useCallback(()=>{X||(B(null),w(""))},[X]),sa=o.useCallback((x,se)=>{if(se){B(x),w(Zm(x));return}Qs(x,x)},[Qs]),Vn=o.useCallback(async()=>{const x=Z,se=Q.trim();if(x){if(!se){R.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}ee(!0);try{await Qs(x,se)&&(B(null),w(""))}finally{ee(!1)}}},[Qs,Q,Z,t]),Zs=o.useCallback(async()=>{if(P)try{await I(P.id);return}catch(x){if(!qm(x)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw x;const De={...P,localForward:{...P.localForward,preferredLocalPort:Hi()}};await S(De),await I(De.id),R.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[I,P,t,S]),me=o.useCallback(async x=>(await Yl(x,600)).map(De=>tu(De)),[]),rs=o.useCallback(async()=>{if(g){C(!0),b(!0),$(null);try{const x=await me(g.id);W(x)}catch(x){W([]),$(x instanceof Error?x.message:String(x))}finally{b(!1)}}},[g,me]);o.useEffect(()=>{if(!L||!g)return;let x=!1;const se=async()=>{try{const Xe=await me(g.id);x||(W(Xe),$(null))}catch(Xe){x||$(Xe instanceof Error?Xe.message:String(Xe))}};se();const De=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||se()},1e3);return()=>{x=!0,window.clearInterval(De)}},[g,L,me]);const Sn=o.useMemo(()=>k.join(`
27
- `),[k]),Ia=o.useCallback(()=>{if(!Sn.trim()){R.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}va(Sn).then(x=>{x.ok&&R.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Sn,t]),Aa=o.useCallback(async()=>{if(g)try{await Zl(g.id),W([]),R.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(x){R.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:x instanceof Error?x.message:String(x)})}},[g,t]),Ea=o.useCallback(async()=>{if(!As?.localUrl){R.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const x=As.localUrl.trim();if(!x){R.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Ni(x)},[As?.localUrl,t]),Ta=o.useCallback(()=>{if(!g)return;E(!0),(dn?u(g.id):Zs()).catch(se=>{const De=dn?Un?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";R.error(t(De),{description:se instanceof Error?se.message:String(se)})}).finally(()=>{E(!1)})},[dn,Zs,u,g,Un,t]),Da=o.useCallback(()=>{if(!g||cn)return;J(!0),(Js?u(g.id).then(()=>Zs()):D(g.id)).catch(se=>{R.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:se instanceof Error?se.message:String(se)})}).finally(()=>{J(!1)})},[Zs,u,g,cn,Js,D,t]),Ma=t(cn?"settings.remoteInstances.page.actions.connecting":Js?_n?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),pi=!V&&!_&&(zs==="error"||zs==="idle"||!zs||Js&&_n)&&!cn,$n=t(Un?"settings.remoteInstances.sidebar.actions.disconnect":dn?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!g)return s.jsxs(as,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(Le,{title:t("settings.remoteInstances.clientAuth.title"),info:t("settings.remoteInstances.clientAuth.description"),divider:!1,settingsItem:"remote-instances.client-auth",contentClassName:"space-y-3",children:[s.jsx("div",{children:s.jsxs(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{ni()},children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[yt>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{oi()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,ot&&et.length===0&&pt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):et.length===0&&pt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[pt.map(x=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-[var(--status-warning)] animate-pulse"}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:x.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),x.usesRelay?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.viaRelay")}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:t("settings.remoteInstances.clientAuth.state.pending")})]}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{si(x.id)},children:t("settings.common.actions.cancel")})]},`pending-${x.id}`)),et.map(x=>{const se=x.clientKind==="desktop-local",De=x.lastUsedAt?Date.parse(x.lastUsedAt):Number.NaN,Xe=!x.revokedAt&&(se||Number.isFinite(De)&&Date.now()-De<9e4),Ft=x.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):Xe?x.lastTransport==="relay"&&!se?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(De)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Xl(De,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",x.revokedAt?"bg-muted-foreground/20":Xe?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:x.label}),Qr(x.devicePlatform)?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded shrink-0 leading-none pb-px border border-border/50",children:Qr(x.devicePlatform)}):null,se?s.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:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:ye("typography-micro truncate",Xe&&!x.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Ft})]})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ri(x)},disabled:!!x.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},x.id)})]})]}),ie?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ie}):null]}):null,n?s.jsxs(Le,{title:t("settings.remoteInstances.direct.title"),info:t("settings.remoteInstances.direct.description"),settingsItem:"remote-instances.direct-hosts",contentClassName:"space-y-4",headerAction:s.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>U(!0),disabled:fe,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ue(!0),disabled:fe,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:Ce?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):le.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):le.map(x=>{const se=Ne[x.id],De=se?se.status==="ok"?"desktopHostSwitcher.status.connected":se.status==="auth"?"desktopHostSwitcher.status.authRequired":se.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":se.status==="incompatible"?"desktopHostSwitcher.status.incompatible":se.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",Xe=se?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",se?Xe?"bg-[var(--status-success)]":"bg-[var(--status-error)]":"bg-muted-foreground/30 animate-pulse")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:la(x.label)}),ue===x.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:ye("typography-micro shrink-0",Xe?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(De),Xe&&typeof se?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(se.latencyMs))}):""]})]}),s.jsx("p",{className:ye("typography-micro text-muted-foreground truncate",x.apiUrl&&"font-mono"),children:x.relay&&!x.apiUrl?t("mobile.connect.relay.badge"):la(x.apiUrl||x.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{zn(x.id)},disabled:fe||ue===x.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ue===x.id?s.jsx(z,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"star",className:"h-3.5 w-3.5"})}),x.relay&&!x.apiUrl?null:s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ps(x),disabled:fe,children:[s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{hs(x.id)},disabled:fe,children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},x.id)})}),Ie?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ie}):null]}):null,n?s.jsx(Vt,{open:$e,onOpenChange:Ue,children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Gt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),It()},children:[s.jsx(He,{className:"h-8",value:Ae,onChange:x=>he(x.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8",value:ge,onChange:x=>Ee(x.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:fe,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(He,{className:"h-8",value:Te,onChange:x=>Qe(x.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:fe}),s.jsx("p",{className:"px-1 typography-micro text-muted-foreground",children:t("settings.remoteInstances.direct.note")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx($s,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Yt,{children:t("settings.remoteInstances.direct.headers.description")})]}),Be.map(x=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:x.name,onChange:se=>Ke(De=>De.map(Xe=>Xe.id===x.id?{...Xe,name:se.target.value}:Xe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:x.value,onChange:se=>Ke(De=>De.map(Xe=>Xe.id===x.id?{...Xe,value:se.target.value}:Xe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:fe}),s.jsx("button",{type:"button",onClick:()=>Ke(se=>se.filter(De=>De.id!==x.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:fe,children:s.jsx(z,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ke(x=>[...x,Gi()]),disabled:fe,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ue(!1),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:fe||!ge.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Vt,{open:!!re,onOpenChange:x=>{x||pe(null)},children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Gt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),fs()},children:[s.jsx(He,{className:"h-8",value:ve,onChange:x=>ae(x.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8",value:_e,onChange:x=>Ze(x.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:fe,autoFocus:!0}),s.jsx(He,{className:"h-8",value:G,onChange:x=>Fe(x.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:fe}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx($s,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Yt,{children:t("settings.remoteInstances.direct.headers.description")})]}),Ye.map(x=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:x.name,onChange:se=>st(De=>De.map(Xe=>Xe.id===x.id?{...Xe,name:se.target.value}:Xe)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:fe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:x.value,onChange:se=>st(De=>De.map(Xe=>Xe.id===x.id?{...Xe,value:se.target.value}:Xe)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:fe}),s.jsx("button",{type:"button",onClick:()=>st(se=>se.filter(De=>De.id!==x.id)),className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-[var(--status-error-background)] hover:text-[var(--status-error)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t("settings.remoteInstances.direct.headers.removeAria"),disabled:fe,children:s.jsx(z,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>st(x=>[...x,Gi()]),disabled:fe,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.headers.actions.add")]})]}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>pe(null),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:fe,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Vt,{open:je,onOpenChange:U,children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Gt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Kt()},children:[s.jsx(He,{className:"h-8",value:Ge,onChange:x=>qe(x.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:fe,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>U(!1),disabled:fe,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:fe||!Ge.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Vt,{open:we,onOpenChange:rt,children:s.jsxs($t,{className:ct==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t(ct==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Gt,{children:t(ct==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),ct==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:x=>{x.preventDefault(),ai()},children:[s.jsx(He,{className:"h-8",value:ut,onChange:x=>At(x.target.value),placeholder:t("settings.remoteInstances.clientAuth.field.labelPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.transportLabel")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.remoteInstances.clientAuth.addDevice.transportLabel"),className:"space-y-1.5",children:[{key:"relay",label:t("settings.remoteInstances.clientAuth.addDevice.transport.relay"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.relayHint"),available:!!Pt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Pt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Pt?.localUrl}].map(x=>{const se=es===x.key;return s.jsxs("div",{className:ye("flex items-start gap-2 py-0.5",x.available?"cursor-pointer":"opacity-45"),onClick:()=>{x.available&&ds(x.key)},role:"presentation",children:[s.jsx(Yi,{checked:se,disabled:!x.available,onChange:()=>ds(x.key),ariaLabel:x.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:ye("typography-ui-label font-normal",se?"text-foreground":"text-foreground/70"),children:x.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:x.hint})]})]},x.key)})}),es==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Ki,{checked:Jt,onChange:Nt,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,es==="relay"&&Pt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Ki,{checked:Jt,onChange:Nt,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.preferLocal")})]}):null]}),ie?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ie}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>rt(!1),disabled:Ct,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:Ct||!Pt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[Wt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:Wt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,Ve?s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-[var(--interactive-border)] p-2",children:[s.jsx("code",{className:"min-w-0 flex-1 truncate typography-code text-muted-foreground",children:Ve}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:ii,children:[s.jsx(z,{name:xe?"check":"file-copy",className:ye("h-3.5 w-3.5",xe&&"text-[var(--status-success)]")}),t(xe?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>rt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(Le,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:i.length}),headerAction:s.jsxs(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>Zt(!0),children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:f?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):i.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneFound")}):i.map(x=>{const se=r[x.id],De=x.nickname?.trim()||x.sshParsed?.destination||x.id,Xe=se?.phase,Ft=Xe==="ready";return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${Zr(Xe)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:De})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(Yr(Xe)),se?.localUrl?` · ${se.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Ft?u(x.id):I(x.id)).catch(ts=>R.error(t(Ft?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:ts instanceof Error?ts.message:String(ts)}))},children:[Ft?s.jsx(z,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Ft?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>M(x.id),children:[s.jsx(z,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&h(x.id).catch(ts=>R.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ts instanceof Error?ts.message:String(ts)}))},children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]},x.id)})}):null,n?s.jsx(Vt,{open:zt,onOpenChange:Zt,children:s.jsxs($t,{className:"sm:max-w-lg",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Gt,{children:t("settings.remoteInstances.page.section.instanceDescription")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Kn()},children:[s.jsx(He,{className:"h-8",value:ht,onChange:x=>Se(x.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:y}),s.jsx(He,{className:"h-8",value:js,onChange:x=>oe(x.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:y,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Zt(!1),disabled:y,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:y||!js.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,n?s.jsx(Le,{title:t("settings.remoteInstances.page.import.sectionTitle"),children:c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):l.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.noneFound")}):s.jsx("div",{children:l.map(x=>s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] py-3 last:border-b-0",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label font-medium text-foreground truncate",children:[x.host,x.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:x.sshCommand})]}),s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{sa(x.host,x.pattern)},children:t("settings.common.actions.import")})]},`${x.source}:${x.host}`))})}):null,s.jsx(Vt,{open:!!Z,onOpenChange:x=>{x||Ys()},children:s.jsxs($t,{className:"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Gt,{children:Z?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Z}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Vn()},children:[s.jsx(He,{value:Q,onChange:x=>w(x.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ys,disabled:X,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:X,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Bn=g.remoteOpenchamber.mode==="managed",Ra=g.nickname?.trim()||g.sshParsed?.destination||g.id;return s.jsx(Vt,{open:!!g,onOpenChange:x=>{x||M(null)},children:s.jsxs($t,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Fi} truncate`,children:Ra}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${Zr(zs)}`}),s.jsx("span",{children:t(Yr(zs))}),As?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:As.localUrl}):null,_n?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(Le,{title:t("settings.remoteInstances.page.section.actions"),info:t("settings.remoteInstances.page.section.actionsDescription"),divider:!1,contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{type:"button",variant:dn?"outline":"default",size:"xs",className:"!font-normal",onClick:Ta,disabled:V||_,children:[dn?s.jsx(z,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"plug-2",className:"h-3.5 w-3.5"}),$n]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Da,disabled:!pi,children:[s.jsx(z,{name:"refresh",className:`h-3.5 w-3.5 ${cn||Js&&!_n?"animate-spin":""}`}),Ma]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{rs()},children:[s.jsx(z,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&h(g.id).then(()=>{M(null),R.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(se=>{R.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:se instanceof Error?se.message:String(se)})})},children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),As?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:As.localUrl})]}):null]}),s.jsxs(Le,{title:t("settings.remoteInstances.page.section.instance"),info:t("settings.remoteInstances.page.section.instanceDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(He,{className:"h-7 md:max-w-xl",value:g.sshCommand,onChange:x=>ms(se=>({...se,sshCommand:x.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(He,{className:"h-7 md:max-w-sm",value:g.nickname||"",onChange:x=>ms(se=>({...se,nickname:x.target.value})),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.connectionTimeoutSeconds")}),s.jsx(ys,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:g.connectionTimeoutSec,onValueChange:x=>{ms(se=>({...se,connectionTimeoutSec:Number.isFinite(x)?x:se.connectionTimeoutSec}))}})]})]}),s.jsxs(Le,{title:t("settings.remoteInstances.page.section.remoteServer"),info:t("settings.remoteInstances.page.section.remoteServerDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Mt,{value:g.remoteOpenchamber.mode,onValueChange:x=>ms(se=>({...se,remoteOpenchamber:{...se.remoteOpenchamber,mode:x==="external"?"external":"managed"}})),children:[s.jsx(Rt,{size:Ut,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Ot,{children:[s.jsx(dt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(dt,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(ys,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:g.remoteOpenchamber.preferredPort,onValueChange:x=>{ms(se=>({...se,remoteOpenchamber:{...se.remoteOpenchamber,preferredPort:Number.isFinite(x)&&x>0?x:void 0}}))},onClear:()=>{ms(x=>({...x,remoteOpenchamber:{...x.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Bn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Mt,{value:g.remoteOpenchamber.installMethod,onValueChange:x=>ms(se=>({...se,remoteOpenchamber:{...se.remoteOpenchamber,installMethod:x==="npm"||x==="download_release"||x==="upload_bundle"?x:"bun"}})),children:[s.jsx(Rt,{size:Ut,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Ot,{children:[s.jsx(dt,{value:"bun",children:"bun"}),s.jsx(dt,{value:"npm",children:"npm"}),s.jsx(dt,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(dt,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,Bn?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(pr,{checked:g.remoteOpenchamber.keepRunning,onCheckedChange:x=>ms(se=>({...se,remoteOpenchamber:{...se.remoteOpenchamber,keepRunning:x}}))})})]}):null]}),s.jsxs(Le,{title:t("settings.remoteInstances.page.section.mainTunnel"),info:t("settings.remoteInstances.page.section.mainTunnelDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Mt,{value:g.localForward.bindHost,onValueChange:x=>{x==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ms(se=>({...se,localForward:{...se.localForward,bindHost:x==="localhost"||x==="0.0.0.0"?x:"127.0.0.1"}}))},children:[s.jsx(Rt,{size:Ut,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Ot,{children:[s.jsx(dt,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(dt,{value:"localhost",children:"localhost"}),s.jsx(dt,{value:"0.0.0.0",children:"0.0.0.0"})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.preferredLocalPort"),hint:t("settings.remoteInstances.page.field.preferredLocalPortHint")})}),s.jsxs("div",{className:"flex w-full items-center gap-2 md:max-w-sm",children:[s.jsx(ys,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:g.localForward.preferredLocalPort,onValueChange:x=>{ms(se=>({...se,localForward:{...se.localForward,preferredLocalPort:Number.isFinite(x)&&x>0?x:void 0}}))},onClear:()=>{ms(x=>({...x,localForward:{...x.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ms(x=>({...x,localForward:{...x.localForward,preferredLocalPort:Hi()}})),children:s.jsx(z,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]})]}),s.jsxs(Le,{title:t("settings.remoteInstances.page.section.authentication"),info:t("settings.remoteInstances.page.section.authenticationDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshPasswordOptional")}),s.jsx(He,{className:"h-7 md:max-w-sm",type:"password",value:g.auth.sshPassword?.value||"",onChange:x=>ms(se=>({...se,auth:{...se.auth,sshPassword:{enabled:x.target.value.trim().length>0,value:x.target.value,store:se.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.uiPasswordOptional")}),s.jsx(He,{className:"h-7 md:max-w-sm",type:"password",value:g.auth.openchamberPassword?.value||"",onChange:x=>ms(se=>({...se,auth:{...se.auth,openchamberPassword:{enabled:x.target.value.trim().length>0,value:x.target.value,store:se.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]}),s.jsxs(Le,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[g.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,g.portForwards.map((x,se)=>{const De=Tt=>{ms(Xt=>({...Xt,portForwards:Xt.portForwards.map((Pn,Lt)=>Lt===se?Tt(Pn):Pn)}))},Xe=x.type==="remote"?"Local target":"Local listen",Ft=x.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",ws=x.type==="remote"?"Remote listen":"Remote target",ts=x.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Ds=Xr(x.localHost||"localhost",x.localPort),Xs=Xr(x.remoteHost||"localhost",x.remotePort),Rs=x.type==="local"&&typeof x.localPort=="number"&&x.localPort>0,na=Rs?`http://${eu(x.localHost)}:${x.localPort}`:"",Cn=!!T[x.id],aa=x.type==="local"?t("settings.remoteInstances.page.forwardType.local"):x.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(Yn,{open:Cn,onOpenChange:Tt=>{O(Xt=>({...Xt,[x.id]:Tt}))},className:`${se>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(Zn,{className:"flex items-center gap-2 group",children:[s.jsx(z,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Cn?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Qm(x)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:aa})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(pr,{checked:x.enabled,onCheckedChange:Tt=>De(Xt=>({...Xt,enabled:Tt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ms(Tt=>({...Tt,portForwards:Tt.portForwards.filter(Xt=>Xt.id!==x.id)})),children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Xn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-0 pb-2",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:t("settings.remoteInstances.page.field.forwardType"),hint:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.remoteInstances.page.field.forwardTypeHint")}),s.jsx("p",{children:t(Xm(x.type))})]})})}),s.jsxs(Mt,{value:x.type,onValueChange:Tt=>De(Xt=>({...Xt,type:Tt==="dynamic"||Tt==="remote"?Tt:"local"})),children:[s.jsx(Rt,{size:Ut,className:"w-fit min-w-[140px]",children:s.jsx(_t,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Ot,{children:[s.jsx(dt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(dt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(dt,{value:"dynamic",children:t("settings.remoteInstances.page.forwardType.dynamic")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:Xe,hint:Ft})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:x.localHost||"127.0.0.1",onChange:Tt=>De(Xt=>({...Xt,localHost:Tt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ys,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:x.localPort,onValueChange:Tt=>{De(Xt=>({...Xt,localPort:Number.isFinite(Tt)&&Tt>0?Tt:void 0}))},onClear:()=>{De(Tt=>({...Tt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),x.type!=="dynamic"?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(tn,{label:ws,hint:ts})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:x.remoteHost||"",onChange:Tt=>De(Xt=>({...Xt,remoteHost:Tt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(ys,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:x.remotePort,onValueChange:Tt=>{De(Xt=>({...Xt,remotePort:Number.isFinite(Tt)&&Tt>0?Tt:void 0}))},onClear:()=>{De(Tt=>({...Tt,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:x.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ds}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):x.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Xs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(z,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ds}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ds}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(z,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(z,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Xs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Rs?s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nn(na).then(Tt=>{Tt||R.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},x.id)}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const x=Ym();ms(se=>({...se,portForwards:[...se.portForwards,x]})),O(se=>({...se,[x.id]:!0}))},children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.addForward")]})]}),s.jsx("div",{className:"mt-8 border-t border-[var(--interactive-border)] pt-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{di()},disabled:!ci||y,children:t("settings.common.actions.saveChanges")}),As?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{va(As.localUrl||"").then(x=>{x.ok&&R.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(z,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ea()},children:[s.jsx(z,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,m?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:m}):null]})}),s.jsx(Vt,{open:L,onOpenChange:C,children:s.jsxs($t,{className:"sm:max-w-2xl",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Gt,{children:g?.nickname?.trim()||g?.sshParsed?.destination||g?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ia,disabled:A||!Sn.trim(),children:[s.jsx(z,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Aa()},disabled:A,children:[s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),A?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):K?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:K}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:k.length>0?k.join(`
28
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Vt,{open:!!Z,onOpenChange:x=>{x||Ys()},children:s.jsxs($t,{className:"sm:max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Gt,{children:Z?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:Z}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Vn()},children:[s.jsx(He,{value:Q,onChange:x=>w(x.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ys,disabled:X,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:X,children:t("settings.common.actions.create")})]})]})]})})]})})},ou="__add_provider__",lu=()=>{const t=on.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},cu=({onItemSelect:t})=>{const{t:e}=it(),a=tt(p=>p.providers),n=tt(p=>p.selectedProviderId),i=tt(p=>p.setSelectedProvider),r=Ks(p=>p.activeProjectId),[l,f]=o.useState({}),c=o.useMemo(()=>lu(),[r]);o.useEffect(()=>{if(a.length===0){f({});return}let p=!1;return(async()=>{const S=a.map(async N=>{try{const h=c?`?directory=${encodeURIComponent(c)}`:"",I=await lt(`/api/provider/${encodeURIComponent(N.id)}/source${h}`,{method:"GET",headers:{Accept:"application/json"}});if(!I.ok)return;const u=await I.json().catch(()=>null),D=u?.sources??u?.data?.sources;if(!D||p)return;f(q=>({...q,[N.id]:D}))}catch{}});await Promise.all(S)})(),()=>{p=!0}},[c,a]);const y="bg-background",m=o.useMemo(()=>a.filter(p=>!!l[p.id]?.project?.exists),[a,l]),v=o.useMemo(()=>a.filter(p=>!l[p.id]?.project?.exists),[a,l]);return s.jsxs("div",{className:ye("flex h-full flex-col",y),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${Ws} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(Ca,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:a.length})}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{i(ou),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(z,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ms,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:a.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[v.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),v.map(p=>s.jsx(to,{provider:p,selectedProviderId:n,onSelect:()=>{i(p.id),t?.()}},p.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",v.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(p=>s.jsx(to,{provider:p,selectedProviderId:n,onSelect:()=>{i(p.id),t?.()}},p.id))]})]})})]})},to=t=>{const e=ft.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,f=a.id,c=l?"bg-interactive-selection":"hover:bg-interactive-hover";let y;e[0]!==c?(y=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",c),e[0]=c,e[1]=y):y=e[1];let m;e[2]!==a.id?(m=s.jsx(jn,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=m):m=e[3];const v=a.name||a.id;let p;e[4]!==v?(p=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:v}),e[4]=v,e[5]=p):p=e[5];let F;e[6]!==r?(F=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=F):F=e[7];let S;e[8]!==i||e[9]!==m||e[10]!==p||e[11]!==F?(S=s.jsxs("button",{type:"button",onClick:i,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,p,F]}),e[8]=i,e[9]=m,e[10]=p,e[11]=F,e[12]=S):S=e[12];let N;return e[13]!==a.id||e[14]!==y||e[15]!==S?(N=s.jsx("div",{className:y,children:S},f),e[13]=a.id,e[14]=y,e[15]=S,e[16]=N):N=e[16],N},du=t=>t,so=t=>typeof t=="object"&&t!==null,dl=t=>{const e=typeof t.type=="string"?t.type:"",a=`${t.name??""} ${t.label??""}`.toLowerCase(),n=`${e} ${a}`.toLowerCase();return n.includes("oauth")?"oauth":n.includes("api")?"api":e.toLowerCase()},pu=t=>{if(!so(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>so(i)));return e},no=t=>t.length===0?!0:t.some(e=>dl(e)==="api"),ao=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>dl(e)==="oauth"),mu=t=>t!=="claude-code",pl="@ai-sdk/openai-compatible",An="__custom_provider__",uu=/^[a-z0-9][a-z0-9-_]*$/,ml=/^https?:\/\//,gu=/^\{env:([^}]+)\}$/;let hu=0;const Ya=()=>`row-${hu++}`,nr=()=>({row:Ya(),id:"",name:""}),ar=()=>({row:Ya(),key:"",value:""}),fu=()=>({providerID:"",name:"",baseURL:"",apiKey:"",models:[nr()],headers:[ar()]});function xu(t){const e=t.trim();if(!e)return{};const n=e.match(gu)?.[1]?.trim();return n?{env:n}:{key:e}}function bu(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&ml.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>{if(!i||typeof i!="object")return!1;const r="api"in i&&i.api&&typeof i.api=="object"?i.api:null;return typeof r?.npm=="string"&&r.npm===pl})}function vu(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&bu(t):!1}function io(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function yu(t){const e=t.options&&typeof t.options=="object"?t.options:{},a=typeof e.baseURL=="string"?e.baseURL:"",n=e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},i=Object.entries(n).filter(c=>typeof c[0]=="string"&&typeof c[1]=="string").map(([c,y])=>({row:Ya(),key:c,value:y})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([c,y])=>({id:c,name:y&&typeof y=="object"&&"name"in y&&typeof y.name=="string"?y.name:c})):[],l=r.length>0?r.map(c=>({row:Ya(),id:typeof c?.id=="string"?c.id:"",name:typeof c?.name=="string"?c.name:typeof c?.id=="string"?c.id:""})):[nr()],f=Array.isArray(t.env)?t.env.find(c=>typeof c=="string"&&c.trim().length>0)?.trim():void 0;return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,baseURL:a,apiKey:f?`{env:${f}}`:"",models:l,headers:i.length>0?i:[ar()]}}function ju(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=xu(t.form.apiKey),l=t.disabledProviders??[],f=t.editingProviderID?.trim(),c=e?uu.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),y=a?void 0:t.t("settings.providers.page.custom.error.name.required"),m=n?ml.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),p=!!(i||r||f&&t.allowExistingAuth&&f===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),F=l.includes(e),N=c||!!(f&&f===e)?void 0:t.existingProviderIDs.has(e)&&!F?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,h=new Set,I=t.form.models.map(C=>{const A=C.id.trim(),b=A?h.has(A)?t.t("settings.providers.page.custom.error.duplicate"):void h.add(A):t.t("settings.providers.page.custom.error.required"),K=C.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:b,name:K}}),u=I.every(C=>!C.id&&!C.name),D=Object.fromEntries(t.form.models.map(C=>[C.id.trim(),{name:C.name.trim()}])),q=new Set,M=t.form.headers.map(C=>{const A=C.key.trim(),b=C.value.trim();if(!A&&!b)return{};const K=A?q.has(A.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void q.add(A.toLowerCase()):t.t("settings.providers.page.custom.error.required"),$=b?void 0:t.t("settings.providers.page.custom.error.required");return{key:K,value:$}}),P=M.every(C=>!C.key&&!C.value),g=Object.fromEntries(t.form.headers.map(C=>({key:C.key.trim(),value:C.value.trim()})).filter(C=>C.key&&C.value).map(C=>[C.key,C.value])),j={providerID:c??N,name:y,baseURL:m,apiKey:p};return!c&&!N&&!y&&!m&&!p&&u&&P?{err:j,models:I,headers:M,result:{providerID:e,name:a,apiKey:r,config:{npm:pl,name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(g).length>0?{headers:g}:{}},models:D}}}:{err:j,models:I,headers:M}}function wu(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function ku(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const ro=t=>{const e=ft.c(198),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:f,authFailureHint:c,onSubmit:y,onCancel:m,onDisconnect:v}=t;let p;e[0]!==n?(p=n===void 0?[]:n,e[0]=n,e[1]=p):p=e[1];const F=p,S=i===void 0?!1:i,N=r===void 0?"create":r,h=f===void 0?!1:f,I=c===void 0?null:c,{t:u}=it(),D=N==="edit";let q;e[2]!==l?(q=()=>l??fu(),e[2]=l,e[3]=q):q=e[3];const[M,P]=o.useState(q);let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g={},e[4]=g):g=e[4];const[j,L]=o.useState(g);let C;e[5]===Symbol.for("react.memo_cache_sentinel")?(C=[],e[5]=C):C=e[5];const[A,b]=o.useState(C);let K;e[6]===Symbol.for("react.memo_cache_sentinel")?(K=[],e[6]=K):K=e[6];const[$,k]=o.useState(K),W=o.useRef(null);let Z,B;e[7]!==l||e[8]!==D?(Z=()=>{l&&(D&&W.current===l.providerID||(W.current=D?l.providerID:null,P(l),L({}),b([]),k([])))},B=[l,D],e[7]=l,e[8]=D,e[9]=Z,e[10]=B):(Z=e[9],B=e[10]),o.useEffect(Z,B);let Q;e[11]===Symbol.for("react.memo_cache_sentinel")?(Q=(Nt,Pt)=>{P(Et=>({...Et,[Nt]:Pt})),L(Et=>({...Et,[Nt]:void 0}))},e[11]=Q):Q=e[11];const w=Q;let X;e[12]===Symbol.for("react.memo_cache_sentinel")?(X=(Nt,Pt,Et)=>{P(yt=>({...yt,models:yt.models.map((zt,Zt)=>Zt===Nt?{...zt,[Pt]:Et}:zt)})),b(yt=>{const zt=[...yt];return zt[Nt]={...zt[Nt]??{},[Pt]:void 0},zt})},e[12]=X):X=e[12];const ee=X;let T;e[13]===Symbol.for("react.memo_cache_sentinel")?(T=(Nt,Pt,Et)=>{P(yt=>({...yt,headers:yt.headers.map((zt,Zt)=>Zt===Nt?{...zt,[Pt]:Et}:zt)})),k(yt=>{const zt=[...yt];return zt[Nt]={...zt[Nt]??{},[Pt]:void 0},zt})},e[13]=T):T=e[13];const O=T;let V;e[14]!==h||e[15]!==S||e[16]!==F||e[17]!==a||e[18]!==M||e[19]!==D||e[20]!==y||e[21]!==u?(V=async Nt=>{if(Nt.preventDefault(),S)return;const Pt=ju({form:M,t:((Et,yt)=>u(Et,yt)),existingProviderIDs:a,disabledProviders:F,editingProviderID:D?M.providerID:void 0,allowExistingAuth:D&&h});L(Pt.err),b(Pt.models),k(Pt.headers),Pt.result&&await y(Pt.result)},e[14]=h,e[15]=S,e[16]=F,e[17]=a,e[18]=M,e[19]=D,e[20]=y,e[21]=u,e[22]=V):V=e[22];const E=V;let _;e[23]!==D||e[24]!==u?(_=u(D?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=D,e[24]=u,e[25]=_):_=e[25];let J;e[26]!==u?(J=u("settings.providers.page.custom.description"),e[26]=u,e[27]=J):J=e[27];let te;e[28]!==J?(te=s.jsx("p",{className:En,children:J}),e[28]=J,e[29]=te):te=e[29];let ne;e[30]!==I?(ne=I?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:I}):null,e[30]=I,e[31]=ne):ne=e[31];let le;e[32]!==u?(le=u("settings.providers.page.custom.field.providerID.label"),e[32]=u,e[33]=le):le=e[33];let be;e[34]!==u?(be=u("settings.providers.page.custom.field.providerID.info"),e[34]=u,e[35]=be):be=e[35];const Ne=M.providerID;let de;e[36]===Symbol.for("react.memo_cache_sentinel")?(de=Nt=>w("providerID",Nt.target.value),e[36]=de):de=e[36];let ue;e[37]!==u?(ue=u("settings.providers.page.custom.field.providerID.placeholder"),e[37]=u,e[38]=ue):ue=e[38];const Me=!D,Ce=D||S,ke=!!j.providerID;let fe;e[39]!==u?(fe=u("settings.providers.page.custom.field.providerID.label"),e[39]=u,e[40]=fe):fe=e[40];let ze;e[41]!==M.providerID||e[42]!==ue||e[43]!==Me||e[44]!==Ce||e[45]!==ke||e[46]!==fe?(ze=s.jsx(He,{value:Ne,onChange:de,placeholder:ue,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:Me,disabled:Ce,"aria-invalid":ke,"aria-label":fe}),e[41]=M.providerID,e[42]=ue,e[43]=Me,e[44]=Ce,e[45]=ke,e[46]=fe,e[47]=ze):ze=e[47];let Ae;e[48]!==j.providerID?(Ae=j.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.providerID}):null,e[48]=j.providerID,e[49]=Ae):Ae=e[49];let he;e[50]!==le||e[51]!==be||e[52]!==ze||e[53]!==Ae?(he=s.jsxs(Qt,{label:le,info:be,children:[ze,Ae]}),e[50]=le,e[51]=be,e[52]=ze,e[53]=Ae,e[54]=he):he=e[54];let ge;e[55]!==u?(ge=u("settings.providers.page.custom.field.name.label"),e[55]=u,e[56]=ge):ge=e[56];let Ee;e[57]!==u?(Ee=u("settings.providers.page.custom.field.name.info"),e[57]=u,e[58]=Ee):Ee=e[58];const Te=M.name;let Qe;e[59]===Symbol.for("react.memo_cache_sentinel")?(Qe=Nt=>w("name",Nt.target.value),e[59]=Qe):Qe=e[59];let Be;e[60]!==u?(Be=u("settings.providers.page.custom.field.name.placeholder"),e[60]=u,e[61]=Be):Be=e[61];const Ke=!!j.name;let Ge;e[62]!==u?(Ge=u("settings.providers.page.custom.field.name.label"),e[62]=u,e[63]=Ge):Ge=e[63];let qe;e[64]!==M.name||e[65]!==Be||e[66]!==Ke||e[67]!==Ge?(qe=s.jsx(He,{value:Te,onChange:Qe,placeholder:Be,className:"h-8 rounded-md px-3","aria-invalid":Ke,"aria-label":Ge}),e[64]=M.name,e[65]=Be,e[66]=Ke,e[67]=Ge,e[68]=qe):qe=e[68];let Ie;e[69]!==j.name?(Ie=j.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.name}):null,e[69]=j.name,e[70]=Ie):Ie=e[70];let Re;e[71]!==ge||e[72]!==Ee||e[73]!==qe||e[74]!==Ie?(Re=s.jsxs(Qt,{label:ge,info:Ee,children:[qe,Ie]}),e[71]=ge,e[72]=Ee,e[73]=qe,e[74]=Ie,e[75]=Re):Re=e[75];let $e;e[76]!==u?($e=u("settings.providers.page.custom.field.baseURL.label"),e[76]=u,e[77]=$e):$e=e[77];let Ue;e[78]!==u?(Ue=u("settings.providers.page.custom.field.baseURL.info"),e[78]=u,e[79]=Ue):Ue=e[79];const je=M.baseURL;let U;e[80]===Symbol.for("react.memo_cache_sentinel")?(U=Nt=>w("baseURL",Nt.target.value),e[80]=U):U=e[80];let re;e[81]!==u?(re=u("settings.providers.page.custom.field.baseURL.placeholder"),e[81]=u,e[82]=re):re=e[82];const pe=!!j.baseURL;let ve;e[83]!==u?(ve=u("settings.providers.page.custom.field.baseURL.label"),e[83]=u,e[84]=ve):ve=e[84];let ae;e[85]!==M.baseURL||e[86]!==re||e[87]!==pe||e[88]!==ve?(ae=s.jsx(He,{value:je,onChange:U,placeholder:re,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":pe,"aria-label":ve}),e[85]=M.baseURL,e[86]=re,e[87]=pe,e[88]=ve,e[89]=ae):ae=e[89];let _e;e[90]!==j.baseURL?(_e=j.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.baseURL}):null,e[90]=j.baseURL,e[91]=_e):_e=e[91];let Ze;e[92]!==$e||e[93]!==Ue||e[94]!==ae||e[95]!==_e?(Ze=s.jsxs(Qt,{label:$e,info:Ue,children:[ae,_e]}),e[92]=$e,e[93]=Ue,e[94]=ae,e[95]=_e,e[96]=Ze):Ze=e[96];let G;e[97]!==u?(G=u("settings.providers.page.custom.field.apiKey.label"),e[97]=u,e[98]=G):G=e[98];let Fe;e[99]!==h||e[100]!==D||e[101]!==u?(Fe=u(D&&h?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[99]=h,e[100]=D,e[101]=u,e[102]=Fe):Fe=e[102];const Ye=M.apiKey;let st;e[103]===Symbol.for("react.memo_cache_sentinel")?(st=Nt=>w("apiKey",Nt.target.value),e[103]=st):st=e[103];let et;e[104]!==h||e[105]!==D||e[106]!==u?(et=u(D&&h?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[104]=h,e[105]=D,e[106]=u,e[107]=et):et=e[107];const wt=!!j.apiKey;let pt;e[108]!==u?(pt=u("settings.providers.page.custom.field.apiKey.label"),e[108]=u,e[109]=pt):pt=e[109];let mt;e[110]!==M.apiKey||e[111]!==et||e[112]!==wt||e[113]!==pt?(mt=s.jsx(He,{type:"password",value:Ye,onChange:st,placeholder:et,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":wt,"aria-label":pt}),e[110]=M.apiKey,e[111]=et,e[112]=wt,e[113]=pt,e[114]=mt):mt=e[114];let ot;e[115]!==j.apiKey?(ot=j.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.apiKey}):null,e[115]=j.apiKey,e[116]=ot):ot=e[116];let bt;e[117]!==G||e[118]!==Fe||e[119]!==mt||e[120]!==ot?(bt=s.jsxs(Qt,{label:G,info:Fe,children:[mt,ot]}),e[117]=G,e[118]=Fe,e[119]=mt,e[120]=ot,e[121]=bt):bt=e[121];let ut;e[122]!==_||e[123]!==te||e[124]!==ne||e[125]!==he||e[126]!==Re||e[127]!==Ze||e[128]!==bt?(ut=s.jsxs(Le,{title:_,divider:!1,settingsItem:"providers.custom",contentClassName:bn,children:[te,ne,he,Re,Ze,bt]}),e[122]=_,e[123]=te,e[124]=ne,e[125]=he,e[126]=Re,e[127]=Ze,e[128]=bt,e[129]=ut):ut=e[129];let At;e[130]!==u?(At=u("settings.providers.page.custom.models.title"),e[130]=u,e[131]=At):At=e[131];let ie;if(e[132]!==M.models||e[133]!==A||e[134]!==u){let Nt;e[136]!==M.models.length||e[137]!==A||e[138]!==u?(Nt=(Pt,Et)=>s.jsx("div",{className:`${Ts} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Dt,children:u("settings.providers.page.custom.models.idLabel")}),s.jsx(He,{value:Pt.id,onChange:yt=>ee(Et,"id",yt.target.value),placeholder:u("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.models.idLabel")}),A[Et]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:A[Et]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Dt,children:u("settings.providers.page.custom.models.nameLabel")}),s.jsx(He,{value:Pt.name,onChange:yt=>ee(Et,"name",yt.target.value),placeholder:u("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":u("settings.providers.page.custom.models.nameLabel")}),A[Et]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:A[Et]?.name}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:gs,disabled:M.models.length<=1,onClick:()=>{M.models.length<=1||(P(yt=>({...yt,models:yt.models.filter((zt,Zt)=>Zt!==Et)})),b(yt=>yt.filter((zt,Zt)=>Zt!==Et)))},"aria-label":u("settings.providers.page.custom.models.remove"),children:s.jsx(z,{name:"delete-bin",className:"size-4"})})]})},Pt.row),e[136]=M.models.length,e[137]=A,e[138]=u,e[139]=Nt):Nt=e[139],ie=M.models.map(Nt),e[132]=M.models,e[133]=A,e[134]=u,e[135]=ie}else ie=e[135];let Pe;e[140]===Symbol.for("react.memo_cache_sentinel")?(Pe=()=>{P(Nu),b(Su)},e[140]=Pe):Pe=e[140];let Ve;e[141]!==u?(Ve=u("settings.providers.page.custom.models.add"),e[141]=u,e[142]=Ve):Ve=e[142];let We;e[143]!==Ve?(We=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Pe,children:Ve}),e[143]=Ve,e[144]=We):We=e[144];let kt;e[145]!==At||e[146]!==ie||e[147]!==We?(kt=s.jsxs(Le,{title:At,contentClassName:bn,children:[ie,We]}),e[145]=At,e[146]=ie,e[147]=We,e[148]=kt):kt=e[148];let St;e[149]!==u?(St=u("settings.providers.page.custom.headers.title"),e[149]=u,e[150]=St):St=e[150];let Wt;e[151]!==u?(Wt=u("settings.providers.page.custom.headers.description"),e[151]=u,e[152]=Wt):Wt=e[152];let Y;e[153]!==Wt?(Y=s.jsx("p",{className:En,children:Wt}),e[153]=Wt,e[154]=Y):Y=e[154];let xe;if(e[155]!==M.headers||e[156]!==$||e[157]!==u){let Nt;e[159]!==M.headers.length||e[160]!==$||e[161]!==u?(Nt=(Pt,Et)=>s.jsx("div",{className:`${Ts} space-y-2`,children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:Dt,children:u("settings.providers.page.custom.headers.keyLabel")}),s.jsx(He,{value:Pt.key,onChange:yt=>O(Et,"key",yt.target.value),placeholder:u("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.keyLabel")}),$[Et]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:$[Et]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Dt,children:u("settings.providers.page.custom.headers.valueLabel")}),s.jsx(He,{value:Pt.value,onChange:yt=>O(Et,"value",yt.target.value),placeholder:u("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.valueLabel")}),$[Et]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:$[Et]?.value}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:gs,disabled:M.headers.length<=1,onClick:()=>{M.headers.length<=1||(P(yt=>({...yt,headers:yt.headers.filter((zt,Zt)=>Zt!==Et)})),k(yt=>yt.filter((zt,Zt)=>Zt!==Et)))},"aria-label":u("settings.providers.page.custom.headers.remove"),children:s.jsx(z,{name:"delete-bin",className:"size-4"})})]})},Pt.row),e[159]=M.headers.length,e[160]=$,e[161]=u,e[162]=Nt):Nt=e[162],xe=M.headers.map(Nt),e[155]=M.headers,e[156]=$,e[157]=u,e[158]=xe}else xe=e[158];let Oe;e[163]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>{P(Cu),k(Pu)},e[163]=Oe):Oe=e[163];let we;e[164]!==u?(we=u("settings.providers.page.custom.headers.add"),e[164]=u,e[165]=we):we=e[165];let rt;e[166]!==we?(rt=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Oe,children:we}),e[166]=we,e[167]=rt):rt=e[167];let ct;e[168]!==St||e[169]!==Y||e[170]!==xe||e[171]!==rt?(ct=s.jsxs(Le,{title:St,contentClassName:bn,children:[Y,xe,rt]}),e[168]=St,e[169]=Y,e[170]=xe,e[171]=rt,e[172]=ct):ct=e[172];let at;e[173]!==S||e[174]!==m||e[175]!==u?(at=m?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:m,disabled:S,children:u("settings.providers.page.custom.actions.back")}):null,e[173]=S,e[174]=m,e[175]=u,e[176]=at):at=e[176];let Ct;e[177]!==S||e[178]!==v||e[179]!==u?(Ct=v?s.jsx(H,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{v()},disabled:S,children:u("settings.providers.page.actions.disconnect")}):null,e[177]=S,e[178]=v,e[179]=u,e[180]=Ct):Ct=e[180];let ss;e[181]!==S||e[182]!==D||e[183]!==u?(ss=u(S?"settings.providers.page.actions.saving":D?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[181]=S,e[182]=D,e[183]=u,e[184]=ss):ss=e[184];let es;e[185]!==S||e[186]!==ss?(es=s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:S,children:ss}),e[185]=S,e[186]=ss,e[187]=es):es=e[187];let ds;e[188]!==at||e[189]!==Ct||e[190]!==es?(ds=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[at,Ct,es]}),e[188]=at,e[189]=Ct,e[190]=es,e[191]=ds):ds=e[191];let Jt;return e[192]!==E||e[193]!==ut||e[194]!==kt||e[195]!==ct||e[196]!==ds?(Jt=s.jsxs("form",{onSubmit:E,className:"space-y-0",children:[ut,kt,ct,ds]}),e[192]=E,e[193]=ut,e[194]=kt,e[195]=ct,e[196]=ds,e[197]=Jt):Jt=e[197],Jt};function Nu(t){return{...t,models:[...t.models,nr()]}}function Su(t){return[...t,{}]}function Cu(t){return{...t,headers:[...t.headers,ar()]}}function Pu(t){return[...t,{}]}const Iu=(t,e)=>!!e&&t!=="claude-code",Au=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Fn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),vs=t=>typeof t=="string"&&t.length>0?t:void 0,Eu=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Fn(a))continue;const n=vs(a.value);n!==void 0&&e.push({value:n,label:vs(a.label)??n,...vs(a.hint)?{hint:vs(a.hint)}:{}})}return e},Tu=t=>{if(!Fn(t))return;const e=vs(t.key),a=t.op==="eq"||t.op==="neq"?t.op:void 0;if(!(!e||!a||typeof t.value!="string"))return{key:e,op:a,value:t.value}},Du=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Fn(a))continue;const n=vs(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?Eu(a.options):[];if(i==="select"&&r.length===0)continue;const l=Tu(a.when);e.push({type:i,key:n,message:vs(a.message)??n,options:r,...vs(a.placeholder)?{placeholder:vs(a.placeholder)}:{},...l?{when:l}:{}})}return e},Mu=(t,e)=>{if(!t.when)return!0;const a=e[t.when.key]??"";return t.when.op==="eq"?a===t.when.value:a!==t.when.value},ir=(t,e)=>t.filter(a=>Mu(a,e)),Ru=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},Ou=(t,e)=>ir(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,Lu=(t,e)=>{const a={};for(const n of ir(t,e))a[n.key]=(e[n.key]??"").trim();return a},Fu=t=>{const e=Fn(t)?t:{},a=Fn(e.data)?e.data:e,n=vs(a.url)??vs(a.verification_uri_complete)??vs(a.verification_uri),i=vs(a.instructions)??vs(a.message);if(!n&&!i)return null;const r=vs(a.user_code)??vs(a.userCode)??(i?Au.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},oo=(t,e,a)=>{const n=Fn(t)?t:{},i=Fn(n.data)?n.data:{};switch(n.name){case"ProviderAuthOauthMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"ProviderAuthOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"ProviderAuthOauthCallbackFailed":return e("settings.providers.page.auth.oauth.error.declined");case"ProviderAuthValidationFailed":return vs(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},Si={phase:"idle"},lo=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=it(),[r,l]=o.useState(Si),[f,c]=o.useState({}),[y,m]=o.useState(""),v=o.useRef(null);o.useEffect(()=>()=>v.current?.abort(),[]);const p=r.phase==="idle"?null:r.methodIndex,F=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,S=async(g,j,L)=>{const C=await va(g);if(C.ok){R.success(i(j));return}console.error("Failed to copy OAuth value:",C.error),R.error(i(L))},N=async(g,j)=>{const L=new AbortController;v.current?.abort(),v.current=L;try{const C=await on.getSdkClient().provider.oauth.callback({providerID:t,method:g,...j?{code:j}:{}},{signal:L.signal});if(L.signal.aborted)return;if(C.error)throw C.error;l(Si),R.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(C){if(L.signal.aborted)return;console.error("Failed to complete OAuth flow:",C),l({phase:"failed",methodIndex:g,message:oo(C,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{v.current===L&&(v.current=null)}},h=async(g,j)=>{l({phase:"authorizing",methodIndex:g});let L;try{const C=await on.getSdkClient().provider.oauth.authorize({providerID:t,method:g,...Object.keys(j).length>0?{inputs:j}:{}});if(C.error)throw C.error;const A=Fu(C.data);if(!A){l({phase:"failed",methodIndex:g,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}L=A}catch(C){console.error("Failed to start OAuth flow:",C),l({phase:"failed",methodIndex:g,message:oo(C,i,"settings.providers.page.toast.oauthStartFailed")});return}if(L.url&&Iu(t,L.url)&&Nn(L.url),L.method==="code"){m(""),l({phase:"awaitingCode",methodIndex:g,authorization:L,submitting:!1});return}l({phase:"waiting",methodIndex:g,authorization:L}),await N(g)},I=g=>{const j=Du(g.prompts);if(j.length===0){h(g.index,{});return}c(Ru(j)),l({phase:"prompting",methodIndex:g.index,prompts:j,error:null})},u=()=>{if(r.phase!=="prompting")return;const g=Ou(r.prompts,f);if(g){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:g.message})});return}h(r.methodIndex,Lu(r.prompts,f))},D=()=>{if(r.phase!=="awaitingCode")return;const g=y.trim();g&&(l({...r,submitting:!0}),N(r.methodIndex,g))},q=()=>{v.current?.abort(),v.current=null,l(Si)},M=g=>{const j=f[g.key]??"",L=C=>c(A=>({...A,[g.key]:C}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:g.message}),g.type==="select"?s.jsxs(Mt,{value:j,onValueChange:L,children:[s.jsx(Rt,{size:Ut,className:yn,children:s.jsx(_t,{children:C=>g.options.find(A=>A.value===C)?.label??null})}),s.jsx(Ot,{children:g.options.map(C=>s.jsx(dt,{value:C.value,children:C.hint?`${C.label} · ${C.hint}`:C.label},C.value))})]}):s.jsx(He,{value:j,onChange:C=>L(C.target.value),placeholder:g.placeholder,className:"max-w-[24rem] text-xs"})]},g.key)},P=g=>s.jsxs(s.Fragment,{children:[g.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:g.instructions}),g.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:g.userCode,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{S(g.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),g.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:g.url,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nn(g.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{S(g.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:ye("space-y-4",n),children:e.map(g=>{const j=p===g.index;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:g.label}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>I(g),disabled:F,children:i("settings.providers.page.actions.connect")})]}),j&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[ir(r.prompts,f).map(M),r.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{size:"xs",className:"!font-normal",onClick:u,children:i("settings.providers.page.actions.continue")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:q,children:i("settings.providers.page.actions.cancel")})]})]}),j&&r.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(z,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),j&&r.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[P(r.authorization),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(z,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:q,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),j&&r.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[P(r.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:y,onChange:L=>m(L.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:r.submitting}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:D,disabled:r.submitting||y.trim().length===0,children:r.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:q,disabled:r.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),j&&r.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.message}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>I(g),children:i("settings.providers.page.actions.tryAgain")})]})]},g.index)})})},Ku=t=>new Intl.NumberFormat(zo(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),co=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Ku(t);return e.endsWith(".0")?e.slice(0,-2):e},ma="__add_provider__",ul=t=>typeof t=="object"&&t!==null,po=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),zu=t=>{if(typeof t=="string")return{id:t};if(!ul(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const a=typeof t.name=="string"?t.name:void 0;return{id:e,name:a}},Uu=t=>{let e=[];Array.isArray(t)?e=t:ul(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>zu(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},_u=()=>{const{t}=it(),e=tt(U=>U.providers),a=tt(U=>U.selectedProviderId),n=tt(U=>U.setSelectedProvider),i=tt(U=>U.getModelMetadata),r=ce(U=>U.hiddenModels),l=ce(U=>U.toggleHiddenModel),f=ce(U=>U.hideAllModels),c=ce(U=>U.showAllModels),[y,m]=o.useState({}),[v,p]=o.useState(!1),[F,S]=o.useState({}),[N,h]=o.useState(null),[I,u]=o.useState(""),[D,q]=o.useState([]),[M,P]=o.useState(!1),[g,j]=o.useState(null),[L,C]=o.useState(""),[A,b]=o.useState(""),[K,$]=o.useState(!1),[k,W]=o.useState({}),[Z,B]=o.useState(!1),[Q,w]=o.useState(null),[X,ee]=o.useState(null),[T,O]=o.useState(null),[V,E]=o.useState(null),[_,J]=o.useState(null),te=a===ma,ne=te&&L===An,le=!!(Q&&a&&Q===a&&!te);o.useEffect(()=>{!a&&e.length>0&&n(e[0].id)},[e,a,n]),o.useEffect(()=>{if(!a)return;let U=!0;return(async()=>{p(!0);try{const pe=await on.getSdkClient().provider.auth();if(pe.error)throw new Error(`provider.auth failed: ${String(pe.error)}`);if(!U)return;m(pu(pe.data))}catch(pe){if(!U)return;console.error("Failed to load provider auth methods:",pe),R.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{U&&p(!1)}})(),()=>{U=!1}},[a,t]),o.useEffect(()=>{if(!du(te))return;let U=!0;return(async()=>{P(!0),j(null);try{const pe=await on.getSdkClient().provider.list();if(pe.error)throw new Error(`provider.list failed: ${String(pe.error)}`);if(!U)return;q(Uu(pe.data))}catch(pe){if(!U)return;console.error("Failed to load available providers:",pe),j(t("settings.providers.page.state.unableToLoadProviderList"))}finally{U&&P(!1)}})(),()=>{U=!1}},[te,t]);const be=o.useMemo(()=>new Set(e.map(U=>U.id)),[e]),Ne=o.useMemo(()=>D.filter(U=>!be.has(U.id)).sort((U,re)=>{const pe=(U.name||U.id).toLowerCase(),ve=(re.name||re.id).toLowerCase();return pe.localeCompare(ve)}),[D,be]);o.useEffect(()=>{a===ma&&L&&L!==An&&!Ne.some(U=>U.id===L)&&C("")},[a,L,Ne]),o.useEffect(()=>{if(a===ma){B(!0),w(null),ee(null),O(null),E(null);return}B(!1),Q&&Q!==a&&(w(null),ee(null),O(null),E(null))},[a,Q]),o.useEffect(()=>{if(!a||a===ma)return;const U=k[a];if(!U)return;const re=e.find(ae=>ae.id===a),pe=Array.isArray(re?.env)?re.env.filter(ae=>typeof ae=="string"&&ae.trim().length>0):[];U.auth.exists||pe.length>0||B(!0)},[a,k,e]),o.useEffect(()=>{if(!a||a===ma)return;let U=!1;return(async()=>{try{const pe=await lt(`/api/provider/${encodeURIComponent(a)}/source`,{method:"GET",headers:{Accept:"application/json"}}),ve=await pe.json().catch(()=>null);if(!pe.ok)throw new Error(ve?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const ae=ve?.sources??ve?.data?.sources;!U&&ae&&W(_e=>({..._e,[a]:ae}))}catch(pe){U||console.error("Failed to load provider sources:",pe)}})(),()=>{U=!0}},[a,t]);const de=e.find(U=>U.id===a),ue=a?k[a]:void 0,Me=async U=>{const re=F[U]?.trim()??"";if(!re){R.error(t("settings.providers.page.toast.apiKeyRequired"));return}const pe=`api:${U}`;h(pe);try{if((await on.getSdkClient().auth.set({providerID:U,auth:{type:"api",key:re}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));R.success(t("settings.providers.page.toast.apiKeySaved")),S(ae=>({...ae,[U]:""})),Dn("providers",{id:U}),n(U)}catch(ve){console.error("Failed to save API key:",ve),R.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{h(null)}},Ce=async U=>{const re=`custom:${U.providerID}`;h(re),J(U.providerID),E(null);try{const pe=wu(U);if(pe&&(await on.getSdkClient().auth.set(pe)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const ve=ku(U,{scope:Q?T??io(k[Q]):"user"}),ae=await lt("/api/provider",{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(ve)}),_e=await ae.json().catch(()=>null);if(!ae.ok)throw pe&&E(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(_e?.error||t("settings.providers.page.toast.customProviderSaveFailed"));R.success(t("settings.providers.page.toast.customProviderSaved",{provider:U.name})),C(""),w(null),ee(null),O(null),E(null),J(null),Ja(_e,"providers",{id:U.providerID}),n(U.providerID)}catch(pe){console.error("Failed to save custom provider:",pe),R.error(pe instanceof Error&&pe.message?pe.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{h(null)}},ke=U=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(U+1)}),fe=U=>{B(!1),mu(U)&&Dn("providers",{id:U}),n(U)},ze=async U=>{const re=`disconnect:${U}`;h(re);try{const pe=await lt(`/api/provider/${encodeURIComponent(U)}/auth?scope=all`,{method:"DELETE",headers:{Accept:"application/json"}}),ve=await pe.json().catch(()=>null);if(!pe.ok)throw new Error(ve?.error||t("settings.providers.page.toast.providerDisconnectFailed"));R.success(t("settings.providers.page.toast.providerDisconnected")),Ja(ve,"providers",{id:U})}catch(pe){console.error("Failed to disconnect provider:",pe),R.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{h(null)}},Ae=async U=>{U&&(await ze(U),w(null),ee(null),O(null),E(null),J(null),C(""))};if(!te&&e.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(te)return s.jsxs(as,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(Le,{title:t("settings.providers.page.connect.selectProviderTitle"),divider:!1,settingsItem:"providers.connect",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),M?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):g?s.jsx("p",{className:"typography-meta text-muted-foreground",children:g}):s.jsxs(Gs,{open:K,onOpenChange:U=>{$(U),U||b("")},children:[s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{type:"button",className:vn,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[L&&L!==An?s.jsx(jn,{providerId:L,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ye("truncate typography-ui-label font-normal",L?"text-foreground":"text-muted-foreground"),children:L===An?t("settings.providers.page.custom.optionLabel"):L?Ne.find(U=>U.id===L)?.name||L:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Hs,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:U=>U.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:U=>U.stopPropagation(),children:[s.jsx(z,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:A,onChange:U=>b(U.target.value),onKeyDown:U=>U.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Ms,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const U=A.toLowerCase(),re=t("settings.providers.page.custom.optionLabel"),pe=!U||re.toLowerCase().includes(U)||"other".includes(U)||"custom".includes(U),ve=Ne.filter(ae=>(ae.name||ae.id).toLowerCase().includes(U)||ae.id.toLowerCase().includes(U));return ve.length===0&&!pe?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):s.jsxs(s.Fragment,{children:[ve.map(ae=>s.jsxs(qs,{onSelect:()=>{C(ae.id),$(!1),b("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(jn,{providerId:ae.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ae.name||ae.id})]}),L===ae.id&&s.jsx(z,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ae.id)),pe?s.jsxs(qs,{onSelect:()=>{C(An),$(!1),b("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(z,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:re})]}),L===An&&s.jsx(z,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},An):null]})})()})]})]})]})}),ne?s.jsx(ro,{mode:"create",existingProviderIDs:be,busy:N?.startsWith("custom:")??!1,authFailureHint:V,onCancel:()=>{C(""),E(null),J(null)},onDisconnect:V&&_?()=>{Ae(_)}:void 0,onSubmit:Ce}):L?s.jsx(Le,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:v?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const U=y[L]??[],re=po(ao(U),ke),pe=no(U);return s.jsxs(s.Fragment,{children:[pe?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Yt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:F[L]??"",onChange:ve=>S(ae=>({...ae,[L]:ve.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Me(L),disabled:N===`api:${L}`,children:N===`api:${L}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,re.length>0?s.jsx(lo,{providerId:L,methods:re,onConnected:()=>fe(L),className:ye(pe&&"border-t border-[var(--surface-subtle)] pt-2")},L):null]})})()})}):null]});if(!de)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const he=Array.isArray(de.models)?de.models:[],ge=y[de.id]??[],Ee=po(ao(ge),ke),Te=no(ge),Qe=!!ue,Be=Qe&&vu(de,ue),Ke=Array.isArray(de.env)?de.env.filter(U=>typeof U=="string"&&U.trim().length>0):[],Ge=!!ue?.auth.exists,qe=Ke.length>0,Ie=Ge||qe,Re=Qe&&!Ie,$e=he.length>0&&(!Qe||Ie),Ue=!Te&&Ee.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),je=he.filter(U=>{const re=typeof U?.name=="string"?U.name:"",pe=typeof U?.id=="string"?U.id:"",ve=I.trim().toLowerCase();return ve?re.toLowerCase().includes(ve)||pe.toLowerCase().includes(ve):!0});return le&&Be&&X?s.jsx(as,{title:de.name||de.id,titleLeading:s.jsx(jn,{providerId:de.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:de.id}),showSaveStatus:!1,children:s.jsx(ro,{mode:"edit",existingProviderIDs:be,initialValues:X,allowExistingAuth:Ie||!Qe,busy:N?.startsWith("custom:")??!1,authFailureHint:V,onCancel:()=>{w(null),ee(null),O(null),E(null),J(null)},onDisconnect:()=>{Ae(de.id)},onSubmit:Ce})}):s.jsxs(as,{title:de.name||de.id,titleLeading:s.jsx(jn,{providerId:de.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:de.id}),showSaveStatus:!1,children:[s.jsx(Le,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[Be?s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{E(null),ee(yu(de)),O(io(ue)),w(de.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>B(U=>!U),children:t(Z?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:Z?v?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[Te?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsx(Yt,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:F[de.id]??"",onChange:U=>S(re=>({...re,[de.id]:U.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(H,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Me(de.id),disabled:N===`api:${de.id}`,children:N===`api:${de.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Ee.length>0&&s.jsx(lo,{providerId:de.id,methods:Ee,onConnected:()=>fe(de.id),className:ye(Te&&"border-t border-[var(--surface-subtle)] pt-2")},de.id)]}):Re?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(z,{name:"alert",className:"w-4 h-4 text-[var(--status-warning)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.incomplete")}),s.jsx(Yt,{children:Ue})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(z,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx(Yt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(Le,{title:t("settings.providers.page.connectionDetails.title"),settingsItem:"providers.connection-details",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 @xl:flex-row @xl:items-center @xl:justify-between @xl:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:ue&&(ue.auth.exists||ue.user.exists||ue.project.exists||ue.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[ue.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,ue.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,ue.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,ue.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ze(de.id),disabled:N===`disconnect:${de.id}`,children:N===`disconnect:${de.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),$e?s.jsxs(Le,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",he.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const U=he.map(re=>typeof re?.id=="string"?re.id:"").filter(re=>re.length>0);f(de.id,U)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>c(de.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(z,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{value:I,onChange:U=>u(U.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),je.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:je.map(U=>{const re=typeof U?.id=="string"?U.id:"",pe=typeof U?.name=="string"?U.name:re,ve=re?i(de.id,re):void 0,ae=r.some(Fe=>Fe.providerID===de.id&&Fe.modelID===re),_e=co(ve?.limit?.context),Ze=co(ve?.limit?.output),G=[];return ve?.tool_call&&G.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),ve?.reasoning&&G.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),ve?.attachment&&G.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:ye("flex items-center gap-3",ae&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:pe}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(_e||Ze)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[_e?`${_e} ${t("settings.providers.page.models.tokenBadge.context")}`:"",_e&&Ze?" · ":"",Ze?`${Ze} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),G.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:G.map(({key:Fe,icon:Ye,label:st})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:st,"aria-label":st,children:s.jsx(z,{name:Ye,className:"h-3 w-3"})},Fe))}),s.jsx("button",{type:"button",onClick:()=>l(de.id,re),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(ae?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(ae?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:ae?s.jsx(z,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(z,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},re)})})]}):null]})},Vu=t=>{const e=t?.windows??{},a=Object.values(e).map(n=>n.usedPercent).filter(n=>typeof n=="number");return a.length===0?null:Math.max(...a)},$u=t=>{const e=ft.c(75),{onItemSelect:a}=t,{t:n}=it(),i=ns(Bu),r=ns(Hu),l=ns(Gu),f=ns(qu),c=ns(Wu),y=ns(Ju),m=ns(Qu),v=ns(Yu);let p,F;e[0]!==v?(p=()=>{v()},F=[v],e[0]=v,e[1]=p,e[2]=F):(p=e[1],F=e[2]),o.useEffect(p,F);const S=Zu;let N;e[3]!==m?(N=te=>{te!=="usage"&&te!=="remaining"||(m(te),S({usageDisplayMode:te}))},e[3]=m,e[4]=N):N=e[4];const h=N;let I;e[5]===Symbol.for("react.memo_cache_sentinel")?(I=ye("flex h-full flex-col","bg-background"),e[5]=I):I=e[5];let u;e[6]!==n?(u=n("settings.usage.sidebar.title"),e[6]=n,e[7]=u):u=e[7];let D;e[8]!==u?(D=s.jsx("h2",{className:`${Ws} mb-3`,children:u}),e[8]=u,e[9]=D):D=e[9];let q;e[10]!==n?(q=n("settings.usage.sidebar.total",{count:Qa.length}),e[10]=n,e[11]=q):q=e[11];let M;e[12]!==q?(M=s.jsx("span",{className:"typography-meta text-muted-foreground",children:q}),e[12]=q,e[13]=M):M=e[13];let P;e[14]!==f?(P=()=>f(),e[14]=f,e[15]=P):P=e[15];let g;e[16]!==n?(g=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=g):g=e[17];let j;e[18]!==n?(j=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=j):j=e[19];const L=c&&"animate-spin";let C;e[20]!==L?(C=ye("h-3.5 w-3.5",L),e[20]=L,e[21]=C):C=e[21];let A;e[22]!==C?(A=s.jsx(z,{name:"refresh",className:C}),e[22]=C,e[23]=A):A=e[23];let b;e[24]!==c||e[25]!==g||e[26]!==j||e[27]!==A||e[28]!==P?(b=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:P,"aria-label":g,title:j,disabled:c,children:A})}),e[24]=c,e[25]=g,e[26]=j,e[27]=A,e[28]=P,e[29]=b):b=e[29];let K;e[30]!==b||e[31]!==M?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[M,b]}),e[30]=b,e[31]=M,e[32]=K):K=e[32];let $;e[33]!==n?($=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=$):$=e[34];let k;e[35]!==$?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[35]=$,e[36]=k):k=e[36];let W;e[37]!==n?(W=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=W):W=e[38];let Z;e[39]!==W?(Z=s.jsx(Rt,{className:"w-fit",children:s.jsx(_t,{placeholder:W})}),e[39]=W,e[40]=Z):Z=e[40];let B;e[41]!==n?(B=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=B):B=e[42];let Q;e[43]!==B?(Q=s.jsx(dt,{value:"usage",children:B}),e[43]=B,e[44]=Q):Q=e[44];let w;e[45]!==n?(w=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=w):w=e[46];let X;e[47]!==w?(X=s.jsx(dt,{value:"remaining",children:w}),e[47]=w,e[48]=X):X=e[48];let ee;e[49]!==Q||e[50]!==X?(ee=s.jsxs(Ot,{children:[Q,X]}),e[49]=Q,e[50]=X,e[51]=ee):ee=e[51];let T;e[52]!==h||e[53]!==Z||e[54]!==ee||e[55]!==y?(T=s.jsxs(Mt,{value:y,onValueChange:h,children:[Z,ee]}),e[52]=h,e[53]=Z,e[54]=ee,e[55]=y,e[56]=T):T=e[56];let O;e[57]!==k||e[58]!==T?(O=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[k,T]}),e[57]=k,e[58]=T,e[59]=O):O=e[59];let V;e[60]!==K||e[61]!==O||e[62]!==D?(V=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[D,K,O]}),e[60]=K,e[61]=O,e[62]=D,e[63]=V):V=e[63];let E;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(E=Qa.map(te=>{const ne=i.find(Me=>Me.providerId===te.id),le=Vu(ne?.usage),be=ec(le),Ne=te.id===r,de=ne?.configured??!1,ue=de?be==="critical"?{backgroundColor:"var(--status-error)"}:be==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",Ne?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(te.id),a?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:ue}),s.jsx(jn,{providerId:te.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:te.name}),!de&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},te.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=E):E=e[69];let _;e[70]!==E?(_=s.jsx(Ms,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:E}),e[70]=E,e[71]=_):_=e[71];let J;return e[72]!==V||e[73]!==_?(J=s.jsxs("div",{className:I,children:[V,_]}),e[72]=V,e[73]=_,e[74]=J):J=e[74],J};function Bu(t){return t.results}function Hu(t){return t.selectedProviderId}function Gu(t){return t.setSelectedProvider}function qu(t){return t.fetchAllQuotas}function Wu(t){return t.isLoading}function Ju(t){return t.displayMode}function Qu(t){return t.setDisplayMode}function Yu(t){return t.loadSettings}async function Zu(t){try{await vt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Ci=t=>{const e=ft.c(44),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:f}=t,c=r===void 0?!1:r,y=l===void 0?!1:l,m=ns(Xu),v=ce(eg),p=m==="remaining"?n.remainingPercent:n.usedPercent,F=m==="remaining"?"remaining":"used";let S;e[0]!==p||e[1]!==n.valueLabel?(S=tc(n.valueLabel,p),e[0]=p,e[1]=n.valueLabel,e[2]=S):S=e[2];const N=S,h=n.resetAfterFormatted??n.resetAtFormatted;let I;e[3]!==h||e[4]!==v||e[5]!==n.resetAt?(I=sc(n.resetAt,h,v),e[3]=h,e[4]=v,e[5]=n.resetAt,e[6]=I):I=e[6];const u=I;let D;e[7]!==a?(D=nc(a),e[7]=a,e[8]=D):D=e[8];const q=D;let M;e[9]!==f||e[10]!==c||e[11]!==y?(M=c&&s.jsx(Ki,{checked:y,onChange:w=>f?.(w),ariaLabel:"Show in dropdown"}),e[9]=f,e[10]=c,e[11]=y,e[12]=M):M=e[12];let P;e[13]!==q?(P=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:q}),e[13]=q,e[14]=P):P=e[14];let g;e[15]!==i?(g=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=g):g=e[16];let j;e[17]!==P||e[18]!==g?(j=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[P,g]}),e[17]=P,e[18]=g,e[19]=j):j=e[19];let L;e[20]!==j||e[21]!==M?(L=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[M,j]}),e[20]=j,e[21]=M,e[22]=L):L=e[22];const C=N==="-"?"":N;let A;e[23]!==C?(A=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:C}),e[23]=C,e[24]=A):A=e[24];let b;e[25]!==L||e[26]!==A?(b=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[L,A]}),e[25]=L,e[26]=A,e[27]=b):b=e[27];let K;e[28]!==p||e[29]!==n.usedPercent?(K=s.jsx(ad,{percent:p,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=p,e[29]=n.usedPercent,e[30]=K):K=e[30];const $=u?`Resets ${u}`:"";let k;e[31]!==$?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[31]=$,e[32]=k):k=e[32];let W;e[33]!==F?(W=s.jsx("span",{className:"typography-micro text-muted-foreground",children:F}),e[33]=F,e[34]=W):W=e[34];let Z;e[35]!==k||e[36]!==W?(Z=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[k,W]}),e[35]=k,e[36]=W,e[37]=Z):Z=e[37];let B;e[38]!==K||e[39]!==Z?(B=s.jsxs("div",{className:"mt-2.5",children:[K,Z]}),e[38]=K,e[39]=Z,e[40]=B):B=e[40];let Q;return e[41]!==b||e[42]!==B?(Q=s.jsxs("div",{className:"py-3",children:[b,B]}),e[41]=b,e[42]=B,e[43]=Q):Q=e[43],Q};function Xu(t){return t.displayMode}function eg(t){return t.timeFormatPreference}const tg=({providerId:t,providerName:e})=>{const{t:a}=it(),[n,i]=o.useState(null),[r,l]=o.useState({}),[f,c]=o.useState(!1),y=`/api/quota/credentials/${t}`;o.useEffect(()=>{lt(y).then(async p=>{if(!p.ok)throw new Error;const F=await p.json();i(F),l({})}).catch(()=>i({configured:!1}))},[y]);const m=async(p,F,S)=>{c(!0);try{const N=await lt(p,{method:F,headers:S?{"Content-Type":"application/json"}:void 0,body:S?JSON.stringify(S):void 0}),h=await N.json().catch(()=>null);if(!N.ok)throw new Error(h?.error);h?.configured!==void 0&&i(h),l({}),R.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(N){R.error(N instanceof Error&&N.message?N.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{c(!1)}},v=(p,F,S)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[F,s.jsx(He,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[p]??"",onChange:N=>l(h=>({...h,[p]:N.target.value})),placeholder:n?.secretMasked??S})]});return s.jsxs("div",{"data-settings-item":`usage.${t}-credentials`,className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t==="ollama-cloud"&&v("cookie",a("settings.providers.page.openCodeGo.authCookie"),"session=..."),t==="cursor"&&v("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&v("refreshToken",a("settings.providers.page.quotaCredentials.refreshToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(H,{size:"xs",disabled:f,onClick:()=>m(y,"PUT",r),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(H,{variant:"outline",size:"xs",disabled:f,onClick:()=>m(`${y}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(H,{variant:"outline",size:"xs",disabled:f,onClick:()=>m(`${y}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(H,{variant:"destructive",size:"xs",disabled:f,onClick:()=>m(y,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},mo=(t,e)=>{if(!t)return"-";try{return Uo(t,e,{fallback:"-"})}catch{return"-"}},sg=()=>{const{t}=it(),e=ce(k=>k.timeFormatPreference),a=ns(k=>k.results),n=ns(k=>k.selectedProviderId),i=ns(k=>k.setSelectedProvider),r=ns(k=>k.loadSettings),l=ns(k=>k.fetchAllQuotas),f=ns(k=>k.isLoading),c=ns(k=>k.lastUpdated),y=ns(k=>k.error),m=ns(k=>k.dropdownProviderIds),v=ns(k=>k.setDropdownProviderIds),p=ns(k=>k.selectedModels),F=ns(k=>k.toggleModelSelected),S=ns(k=>k.applyDefaultSelections);ac(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const k=a.find(W=>W.configured)?.providerId;i(k??Qa[0]?.id??null)},[a,n,i]);const N=a.find(k=>k.providerId===n)??null,I=Qa.find(k=>k.id===n)?.name??n??t("settings.usage.sidebar.title"),u=N?.usage,D=N?.configured&&!N.ok?N.error:null,q=n?m.includes(n):!1,M=n==="ollama-cloud"||n==="cursor",P=o.useCallback(k=>{if(!n)return;const W=k?Array.from(new Set([...m,n])):m.filter(Z=>Z!==n);v(W),vt({usageDropdownProviders:W})},[m,n,v]),g=o.useMemo(()=>u?.models?Object.entries(u.models).map(([k,W])=>({name:k,windows:W})).filter(k=>Object.keys(k.windows.windows).length>0):[],[u?.models]);o.useEffect(()=>{n&&g.length>0&&S(n,g.map(k=>k.name))},[n,g,S]);const j=o.useMemo(()=>!n||g.length===0?new Map:ic(g,k=>k.name,n),[g,n]),L=o.useMemo(()=>{if(!n)return[];const k=oc(n);return rc(k)},[n]),[C,A]=o.useState(()=>({})),b=o.useCallback(k=>{A(W=>({...W,[k]:!W[k]}))},[]),K=o.useCallback(k=>{if(!n)return;F(n,k);const W=p[n]??[],B=W.includes(k)?W.filter(w=>w!==k):[...W,k],Q={...p,[n]:B};vt({usageSelectedModels:Q})},[n,p,F]),$=n?p[n]??[]:[];return n?s.jsxs(as,{title:t("settings.usage.page.header.providerUsage",{provider:I}),titleLeading:s.jsx(jn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:f?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):N?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:N.planLabel,time:mo(c,e)}):t("settings.usage.page.header.lastUpdated",{time:mo(c,e)}),showSaveStatus:!0,children:[s.jsx(Le,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(gt,{checked:q,onChange:P,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!N&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(y||D)&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:y??D})]}),N&&!N.configured&&!M&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="ollama-cloud"||n==="cursor")&&s.jsx(tg,{providerId:n,providerName:I}),u?.windows&&Object.keys(u.windows).length>0&&s.jsx(Le,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(u.windows).map(([k,W])=>s.jsx(Ci,{title:k,window:W},k))})}),g.length>0&&s.jsxs(Le,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[L.map(k=>{const W=j.get(k.id)??[];if(W.length===0)return null;const Z=C[k.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Yn,{open:!Z,onOpenChange:()=>b(k.id),children:[s.jsxs(Zn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:k.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",W.length,")"]})]}),Z?s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Xn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:W.map(B=>{const Q=Object.entries(B.windows.windows);if(Q.length===0)return null;const[w,X]=Q[0],ee=$.includes(B.name);return s.jsx(Ci,{title:w,subtitle:mr(B.name),window:X,showToggle:!0,toggleEnabled:ee,onToggle:()=>K(B.name)},B.name)})})})]})},k.id)}),(()=>{const k=j.get(null)??[];if(k.length===0)return null;const W=C.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Yn,{open:!W,onOpenChange:()=>b("other"),children:[s.jsxs(Zn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",k.length,")"]})]}),W?s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Xn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:k.map(Z=>{const B=Object.entries(Z.windows.windows);if(B.length===0)return null;const[Q,w]=B[0],X=$.includes(Z.name);return s.jsx(Ci,{title:Q,subtitle:mr(Z.name),window:w,showToggle:!0,toggleEnabled:X,onToggle:()=>K(Z.name)},Z.name)})})})]})})})()]}),N?.configured&&u&&Object.keys(u.windows??{}).length===0&&g.length===0&&s.jsxs("div",{className:"pb-8",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},ng="git.commit.generate",qi=Qo(t=>({selectedPromptId:ng,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),ag=t=>{const e=ft.c(23),{onItemSelect:a}=t,{t:n}=it(),i=qi(ig),r=qi(rg);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let f;e[1]===Symbol.for("react.memo_cache_sentinel")?(f={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=f):f=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=c):c=e[2];let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=[l,f,c,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=y):y=e[3];const m=y;let v;e[4]!==n?(v=n("settings.magicPrompts.sidebar.title"),e[4]=n,e[5]=v):v=e[5];let p;e[6]!==v?(p=s.jsx("h2",{className:Ws,children:v}),e[6]=v,e[7]=p):p=e[7];let F;e[8]!==n?(F=n("settings.magicPrompts.sidebar.description"),e[8]=n,e[9]=F):F=e[9];let S;e[10]!==F?(S=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:F}),e[10]=F,e[11]=S):S=e[11];let N;e[12]!==p||e[13]!==S?(N=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[p,S]}),e[12]=p,e[13]=S,e[14]=N):N=e[14];let h;e[15]!==a||e[16]!==i||e[17]!==r||e[18]!==n?(h=s.jsx(Ms,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(u=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(u.groupKey)}),u.items.map(D=>{const q=i===D.id;return s.jsx("button",{type:"button",onClick:()=>{r(D.id),a?.()},className:ye("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",q?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(D.titleKey)})},D.id)})]},u.groupKey))}),e[15]=a,e[16]=i,e[17]=r,e[18]=n,e[19]=h):h=e[19];let I;return e[20]!==h||e[21]!==N?(I=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[N,h]}),e[20]=h,e[21]=N,e[22]=I):I=e[22],I};function ig(t){return t.selectedPromptId}function rg(t){return t.setSelectedPromptId}const uo={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},go=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Pi=t=>t.endsWith(".visible"),og=()=>{const{t}=it(),e=o.useCallback(P=>t(P),[t]),a=qi(P=>P.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[f,c]=o.useState({}),[y,m]=o.useState({}),[v,p]=o.useState({}),[F,S]=o.useState(!1);o.useEffect(()=>{let P=!0;return(async()=>{i(!0);try{const j=await pc();if(!P)return;l(j)}catch(j){console.warn("Failed to load magic prompts:",j),R.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{P&&i(!1)}})(),()=>{P=!1}},[t]);const N=uo[a]??uo["git.commit.generate"],h=o.useCallback(P=>go(r,P)?r[P]:gi(P),[r]),I=o.useCallback(P=>f[P]??h(P),[f,h]),u=o.useCallback((P,g)=>{c(j=>j[P]===g?j:{...j,[P]:g})},[]),D=o.useCallback(async P=>{const g=I(P);if(Pi(P)&&g.trim().length===0){R.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(j=>({...j,[P]:!0}));try{const j=g===gi(P)?await ur(P):await lc(P,g);l(j.overrides),R.success(t("settings.magicPrompts.page.toast.saved"))}catch(j){const L=j instanceof Error?j.message:String(j);R.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:L})}finally{m(j=>({...j,[P]:!1}))}},[I,t]),q=o.useCallback(async P=>{p(g=>({...g,[P]:!0}));try{const g=await ur(P);l(g.overrides),c(j=>({...j,[P]:gi(P)})),R.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(g){const j=g instanceof Error?g.message:String(g);R.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:j})}finally{p(g=>({...g,[P]:!1}))}},[t]),M=o.useCallback(async()=>{S(!0);try{const P=await cc();l(P.overrides),c({}),R.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(P){const g=P instanceof Error?P.message:String(P);R.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:g})}finally{S(!1)}},[t]);return n?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx(as,{title:e(N.titleKey),titleAccessory:s.jsx(Yt,{contentClassName:"max-w-xs",children:e(N.descriptionKey)}),headerEnd:s.jsx(H,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{M()},disabled:F||Object.keys(r).length===0,children:t(F?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:N.blocks.map((P,g)=>{const j=dc(P.id),L=h(P.id),C=I(P.id),A=go(r,P.id),b=C!==L,K=Pi(P.id)&&C.trim().length===0,$=y[P.id]===!0,k=v[P.id]===!0;return s.jsxs(Le,{title:e(P.titleKey),info:j.description,description:j.placeholders&&j.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${j.placeholders.map(W=>`{{${W.key}}}`).join(", ")}`:void 0,divider:g>0,settingsItem:Pi(P.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Ns,{value:C,onChange:W=>u(P.id,W.target.value),className:"min-h-[220px] font-mono text-sm"}),K&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(b?"settings.magicPrompts.page.status.unsavedChanges":A?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"outline",size:"sm",onClick:()=>{q(P.id)},disabled:!A||$||k,children:t(k?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(H,{size:"sm",onClick:()=>{D(P.id)},disabled:!b||$||k||K,children:t($?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},P.id)})})},lg=t=>{const e=ft.c(89),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,f]=o.useState(null),[c,y]=o.useState(null),{selectedSnippetName:m,snippets:v,setSelectedSnippet:p,setSnippetDraft:F,deleteSnippet:S,loadSnippets:N}=ei(Cs(cg));let h,I;e[0]!==N?(h=()=>{N()},I=[N],e[0]=N,e[1]=h,e[2]=I):(h=e[1],I=e[2]),o.useEffect(h,I);let u;e[3]!==a||e[4]!==p||e[5]!==F||e[6]!==v?(u=async()=>{const Ce=new Set(v.map(dg));let ke="new-snippet",fe=1;for(;Ce.has(ke);)ke=`new-snippet-${fe++}`;F({name:ke,scope:"global"}),p(ke),a?.()},e[3]=a,e[4]=p,e[5]=F,e[6]=v,e[7]=u):u=e[7];const D=u;let q;e[8]!==i||e[9]!==S||e[10]!==n?(q=async()=>{if(!i)return;await S(i.name)?(R.success(n("settings.snippets.sidebar.toast.deleted")),r(null)):R.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=S,e[10]=n,e[11]=q):q=e[11];const M=q;let P;e[12]!==v?(P=[...v].sort(pg),e[12]=v,e[13]=P):P=e[13];const g=P;let j;e[14]===Symbol.for("react.memo_cache_sentinel")?(j=ye("flex h-full flex-col","bg-background"),e[14]=j):j=e[14];let L;e[15]!==n?(L=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=L):L=e[16];let C;e[17]!==L?(C=s.jsx("h2",{className:`${Ws} mb-3`,children:L}),e[17]=L,e[18]=C):C=e[18];let A;e[19]!==v.length||e[20]!==n?(A=n("settings.snippets.sidebar.total",{count:v.length}),e[19]=v.length,e[20]=n,e[21]=A):A=e[21];let b;e[22]!==A?(b=s.jsx("span",{className:"typography-meta text-muted-foreground",children:A}),e[22]=A,e[23]=b):b=e[23];let K;e[24]!==n?(K=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=K):K=e[25];let $;e[26]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),e[26]=$):$=e[26];let k;e[27]!==D||e[28]!==K?(k=s.jsx(H,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:D,"aria-label":K,children:$}),e[27]=D,e[28]=K,e[29]=k):k=e[29];let W;e[30]!==b||e[31]!==k?(W=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[b,k]}),e[30]=b,e[31]=k,e[32]=W):W=e[32];let Z;e[33]!==W||e[34]!==C?(Z=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,W]}),e[33]=W,e[34]=C,e[35]=Z):Z=e[35];let B;if(e[36]!==a||e[37]!==l||e[38]!==c||e[39]!==m||e[40]!==p||e[41]!==g||e[42]!==n){let Ce;e[44]!==a||e[45]!==l||e[46]!==c||e[47]!==m||e[48]!==p||e[49]!==n?(Ce=ke=>s.jsxs(Ln,{open:c===ke.name,onOpenChange:fe=>y(fe?ke.name:null),children:[s.jsxs(On,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",m===ke.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:fe=>{fe.preventDefault(),y(ke.name)}}),children:[s.jsxs("button",{onClick:()=>{p(ke.name),a?.()},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:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",ke.name]}),s.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:n(`snippets.source.${ke.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:ke.description||ke.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(Gs,{open:l===ke.name,onOpenChange:fe=>{fe&&y(null),f(fe?ke.name:null)},children:[s.jsx(Bs,{asChild:!0,children:s.jsx(H,{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","aria-label":n("settings.snippets.sidebar.actions.more",{name:ke.name}),children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Hs,{align:"end",className:"w-fit min-w-20",children:s.jsxs(qs,{onClick:fe=>{fe.stopPropagation(),r(ke)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Mn,{className:"w-fit min-w-20",children:s.jsxs(Rn,{onClick:fe=>{fe.stopPropagation(),r(ke)},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${ke.source}:${ke.filePath}`),e[44]=a,e[45]=l,e[46]=c,e[47]=m,e[48]=p,e[49]=n,e[50]=Ce):Ce=e[50],B=g.map(Ce),e[36]=a,e[37]=l,e[38]=c,e[39]=m,e[40]=p,e[41]=g,e[42]=n,e[43]=B}else B=e[43];let Q;e[51]!==B?(Q=s.jsx(Ms,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:B}),e[51]=B,e[52]=Q):Q=e[52];const w=i!==null;let X;e[53]===Symbol.for("react.memo_cache_sentinel")?(X=Ce=>{Ce||r(null)},e[53]=X):X=e[53];let ee;e[54]!==n?(ee=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=ee):ee=e[55];let T;e[56]!==ee?(T=s.jsx(Ht,{children:ee}),e[56]=ee,e[57]=T):T=e[57];const O=i?.name??"";let V;e[58]!==n||e[59]!==O?(V=n("settings.snippets.sidebar.dialog.deleteDescription",{name:O}),e[58]=n,e[59]=O,e[60]=V):V=e[60];let E;e[61]!==V?(E=s.jsx(Gt,{children:V}),e[61]=V,e[62]=E):E=e[62];let _;e[63]!==T||e[64]!==E?(_=s.jsxs(Bt,{children:[T,E]}),e[63]=T,e[64]=E,e[65]=_):_=e[65];let J;e[66]===Symbol.for("react.memo_cache_sentinel")?(J=()=>r(null),e[66]=J):J=e[66];let te;e[67]!==n?(te=n("settings.common.actions.cancel"),e[67]=n,e[68]=te):te=e[68];let ne;e[69]!==te?(ne=s.jsx(H,{size:"sm",variant:"ghost",onClick:J,children:te}),e[69]=te,e[70]=ne):ne=e[70];let le;e[71]!==n?(le=n("settings.common.actions.delete"),e[71]=n,e[72]=le):le=e[72];let be;e[73]!==M||e[74]!==le?(be=s.jsx(H,{size:"sm",onClick:M,children:le}),e[73]=M,e[74]=le,e[75]=be):be=e[75];let Ne;e[76]!==ne||e[77]!==be?(Ne=s.jsxs(is,{children:[ne,be]}),e[76]=ne,e[77]=be,e[78]=Ne):Ne=e[78];let de;e[79]!==_||e[80]!==Ne?(de=s.jsxs($t,{className:"max-w-md",children:[_,Ne]}),e[79]=_,e[80]=Ne,e[81]=de):de=e[81];let ue;e[82]!==w||e[83]!==de?(ue=s.jsx(Vt,{open:w,onOpenChange:X,children:de}),e[82]=w,e[83]=de,e[84]=ue):ue=e[84];let Me;return e[85]!==Z||e[86]!==Q||e[87]!==ue?(Me=s.jsxs("div",{className:j,children:[Z,Q,ue]}),e[85]=Z,e[86]=Q,e[87]=ue,e[88]=Me):Me=e[88],Me};function cg(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function dg(t){return t.name}function pg(t,e){return t.name.localeCompare(e.name)}const mg=()=>{const{t}=it(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=ei(Cs(j=>({selectedSnippetName:j.selectedSnippetName,snippets:j.snippets,snippetDraft:j.snippetDraft,setSnippetDraft:j.setSnippetDraft,updateSnippet:j.updateSnippet,createSnippet:j.createSnippet}))),f=o.useMemo(()=>e?a.find(j=>j.name===e||j.aliases.includes(e))??null:null,[e,a]),c=!!(n&&n.name===e&&!f),[y,m]=o.useState(""),[v,p]=o.useState("global"),[F,S]=o.useState(""),[N,h]=o.useState(""),[I,u]=o.useState(""),[D,q]=o.useState(!1),M=o.useRef(null);o.useEffect(()=>{if(c&&n){const j={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};m(j.draftName),p(j.draftScope),S(j.description),h(j.aliases),u(j.content),M.current=j}else if(f){const j={draftName:"",draftScope:"global",description:f.description??"",aliases:f.aliases.join(", "),content:f.content};S(j.description),h(j.aliases),u(j.content),M.current=j}},[f,c,e,n]);const P=o.useMemo(()=>{const j=M.current;return j?c&&y!==j.draftName||c&&v!==j.draftScope?!0:F!==j.description||N!==j.aliases||I!==j.content:!1},[N,I,F,y,v,c]),g=async()=>{const j=c?y.trim().replace(/\s+/g,"-"):e?.trim();if(!j){R.error(t("settings.snippets.page.toast.nameRequired"));return}if(!I.trim()){R.error(t("settings.snippets.page.toast.contentRequired"));return}const L=N.split(",").map(C=>C.trim()).filter(Boolean);q(!0);try{if(!(c?await l(j,I,{aliases:L,description:F,scope:v}):await r(j,{content:I,aliases:L,description:F}))){R.error(t("settings.snippets.page.toast.saveFailed"));return}R.success(t("settings.snippets.page.toast.saved")),c&&i(null)}finally{q(!1)}};return e?s.jsxs(as,{title:c?t("settings.snippets.page.title.new"):`#${e}`,description:f?f.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(Le,{divider:!1,contentClassName:"space-y-0",children:[c?s.jsxs(qt,{label:"#",children:[s.jsx(He,{value:y,onChange:j=>m(j.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Mt,{value:v,onValueChange:j=>p(j),children:[s.jsx(Rt,{size:Ut,className:"w-fit min-w-[100px]",children:s.jsx(_t,{})}),s.jsxs(Ot,{align:"end",children:[s.jsx(dt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(dt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Qt,{label:t("settings.common.field.description"),children:s.jsx(He,{value:F,onChange:j=>S(j.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Qt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(He,{value:N,onChange:j=>h(j.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(Le,{settingsItem:"snippets.content",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(Yt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Ns,{value:I,onChange:j=>u(j.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("div",{className:"pt-3",children:s.jsx(H,{onClick:g,disabled:D||!P,size:"xs",className:"!font-normal",children:t(D?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(z,{name:"file-text",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.snippets.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.snippets.page.empty.description")})]})})},gl=()=>{const{t}=it(),e=tt(v=>v.settingsGitmojiEnabled),a=tt(v=>v.setSettingsGitmojiEnabled),n=_c(),i=ce(v=>v.gitChangesViewMode),r=ce(v=>v.setGitChangesViewMode),[l,f]=o.useState(!0),c=o.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{let p=null;if(!p){const F=kn()?.settings;if(F)try{const N=(await F.load())?.settings;N&&(p={gitmojiEnabled:typeof N.gitmojiEnabled=="boolean"?N.gitmojiEnabled:void 0,gitChangesViewMode:N.gitChangesViewMode==="flat"||N.gitChangesViewMode==="tree"?N.gitChangesViewMode:void 0})}catch{}}if(!p){const F=await lt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});F.ok&&(p=await F.json())}p&&(typeof p.gitmojiEnabled=="boolean"&&a(p.gitmojiEnabled),(p.gitChangesViewMode==="flat"||p.gitChangesViewMode==="tree")&&r(p.gitChangesViewMode))}catch(p){console.warn("Failed to load git settings:",p)}finally{f(!1)}})()},[r,a]);const y=o.useCallback(async v=>{a(v);try{await vt({gitmojiEnabled:v})}catch(p){console.warn("Failed to save gitmoji setting:",p)}},[a]),m=o.useCallback(v=>{v!==i&&(r(v),vt({gitChangesViewMode:v}))},[i,r]);return l?null:s.jsx(Le,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:bs,children:[s.jsx(Ls,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(hn,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:c.map(v=>s.jsx(fn,{selected:i===v.id,onSelect:()=>{m(v.id)},label:v.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:v.label})},v.id))})}),s.jsx(gt,{settingsItem:"git.gitmoji",checked:e,onChange:v=>{y(v)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(gt,{settingsItem:"git.gitignored-files",checked:n,onChange:Vc,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},hl=()=>{const{t}=it(),{isMobile:e}=ea(),a=kn()?.github,n=ia(b=>b.status),i=ia(b=>b.isLoading),r=ia(b=>b.hasChecked),l=ia(b=>b.refreshStatus),f=ia(b=>b.setStatus),c=o.useCallback(async b=>{await Nn(b)},[]),[y,m]=o.useState(!1),[v,p]=o.useState(null),[F,S]=o.useState(null),N=o.useRef(null),h=o.useCallback(()=>{N.current!=null&&(window.clearInterval(N.current),N.current=null),S(null)},[]);o.useEffect(()=>((async()=>{try{r||await l(a)}catch(b){console.warn("Failed to load GitHub auth status:",b)}})(),()=>{h()}),[r,l,a,h]);const I=o.useCallback(async()=>{m(!0);try{const b=a?await a.authStart():await(async()=>{const $=await lt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),k=await $.json().catch(()=>null);if(!$.ok||!k||!("deviceCode"in k))throw new Error(k?.error||$.statusText);return k})();p(b),S(Math.max(1,b.interval)*1e3);const K=b.verificationUriComplete||b.verificationUri;c(K)}catch(b){console.error("Failed to start GitHub connect:",b),R.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[c,a,t]),u=o.useCallback(async b=>{if(a)return a.authComplete(b);const K=await lt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:b})}),$=await K.json().catch(()=>null);if(!K.ok||!$)throw new Error($?.error||K.statusText);return $},[a]);o.useEffect(()=>{if(!(!v?.deviceCode||!F)&&N.current==null)return N.current=window.setInterval(()=>{(async()=>{try{const b=await u(v.deviceCode);if(b.connected){R.success(t("settings.github.page.toast.connected")),p(null),h(),await l(a,{force:!0});return}b.status==="slow_down"&&S(K=>K?K+5e3:5e3),(b.status==="expired_token"||b.status==="access_denied")&&(R.error(b.error||t("settings.github.page.toast.authorizationFailed")),p(null),h())}catch(b){console.warn("GitHub polling failed:",b)}})()},F),()=>{N.current!=null&&(window.clearInterval(N.current),N.current=null)}},[v,F,u,l,a,h,t]);const D=o.useCallback(async b=>{m(!0);try{if(a)await a.authSetGhCliDisabled(b);else{const K=await lt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:b})}),$=await K.json().catch(()=>null);if(!K.ok)throw new Error($?.error||K.statusText)}R.success(t(b?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await l(a,{force:!0})}catch(K){console.error("Failed to update gh CLI setting:",K),R.error(t("settings.github.page.toast.ghCliUpdateFailed"))}finally{m(!1)}},[l,a,t]),q=o.useCallback(async()=>{m(!0);try{if(h(),p(null),a)await a.authDisconnect();else{const b=await lt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!b.ok)throw new Error(b.statusText)}R.success(t("settings.github.page.toast.disconnected")),await l(a,{force:!0})}catch(b){console.error("Failed to disconnect GitHub:",b),R.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[l,a,h,t]),M=o.useCallback(async b=>{if(b){m(!0);try{const K=a?await a.authActivate(b):await(async()=>{const $=await lt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:b})}),k=await $.json().catch(()=>null);if(!$.ok||!k)throw new Error(k?.error||$.statusText);return k})();f(K),R.success(t("settings.github.page.toast.accountSwitched"))}catch(K){console.error("Failed to switch GitHub account:",K),R.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[a,f,t]);if(i)return null;const P=!!n?.connected,g=n?.user,L=(n?.accounts??[]).filter(b=>!b.current),C=n?.ghCli??null,A=C?.active?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth");return s.jsxs(s.Fragment,{children:[s.jsxs(Le,{title:t("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:t("settings.github.page.tooltip.connectAccount"),children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[P?s.jsxs("div",{className:ye("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[g?.avatarUrl?s.jsx("img",{src:g.avatarUrl,alt:g.login?t("settings.github.page.avatarAlt.withLogin",{login:g.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:g?.name?.trim()||g?.login||"GitHub"}),s.jsxs("div",{className:ye("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(z,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:g?.login||t("settings.github.page.label.unknownUser")}),g?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),g?.email&&s.jsx("span",{children:g.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:A})]}),n?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:n.scope})}),C?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.ghCli.activeDescription")})]})]}),C?.active?s.jsx(H,{size:"sm",variant:"outline",onClick:()=>D(!0),disabled:y,className:ye(e?"w-full":void 0),children:t("settings.github.page.ghCli.actions.disable")}):s.jsx(H,{size:"sm",variant:"outline",onClick:q,disabled:y,className:ye("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(H,{size:"sm",variant:"default",onClick:I,disabled:y,children:t("settings.github.page.actions.connect")})]}),L.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:L.map(b=>{const K=b.user,$=b.source==="gh-cli"?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[K?.avatarUrl?s.jsx("img",{src:K.avatarUrl,alt:K.login?t("settings.github.page.avatarAlt.withLogin",{login:K.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:K?.name?.trim()||K?.login||"GitHub"}),K?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:K.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:$})]})]})]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>M(b.id),disabled:y,children:t("settings.github.page.actions.switchTo")})]},b.id)})})]})]}),P&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(H,{size:"sm",variant:"outline",onClick:I,disabled:y,className:ye(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),v&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx($s,{children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:v.userCode}),s.jsx(H,{size:"sm",asChild:!0,children:s.jsx("a",{href:v.verificationUriComplete||v.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(H,{size:"sm",variant:"ghost",disabled:y,onClick:()=>{h(),p(null)},children:t("settings.common.actions.cancel")})]})]})]}),C?.available&&!C?.active&&(!C.user||C.disabled)&&s.jsx(Le,{title:t("settings.github.page.ghCli.title"),children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:ye("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[C.user?.avatarUrl?s.jsx("img",{src:C.user.avatarUrl,alt:C.user.login?t("settings.github.page.avatarAlt.withLogin",{login:C.user.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(z,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!C.disabled&&C.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:C.user.name?.trim()||C.user.login||"GitHub"}),!C.disabled&&C.user?.login&&s.jsxs("div",{className:ye("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(z,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:C.user.login}),C.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),C.user.email&&s.jsx("span",{children:C.user.email})]}),s.jsx("div",{className:ye("typography-meta text-muted-foreground",C.disabled?"opacity-60":void 0),children:C.disabled?t("settings.github.page.ghCli.disabledDescription"):t("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>D(!C.disabled),disabled:y,className:ye(e?"w-full":void 0),children:C.disabled?t("settings.github.page.ghCli.actions.enable"):t("settings.github.page.ghCli.actions.disable")})]})})})]})},ho=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],ug=[{key:"branch",Icon:"git-branch",label:"Branch"},{key:"briefcase",Icon:"briefcase",label:"Work"},{key:"house",Icon:"home",label:"Personal"},{key:"graduation",Icon:"graduation-cap",label:"School"},{key:"code",Icon:"code",label:"Code"}],gg=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=it(),r=Tn(E=>E.getProfileById),l=Tn(E=>E.createProfile),f=Tn(E=>E.updateProfile),c=Tn(E=>E.deleteProfile),y=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),m=a==="new"||n!=null,v=a==="global",[p,F]=o.useState(""),[S,N]=o.useState(""),[h,I]=o.useState(""),[u,D]=o.useState("ssh"),[q,M]=o.useState(""),[P,g]=o.useState(!1),[j,L]=o.useState(""),[C,A]=o.useState(""),[b,K]=o.useState("keyword"),[$,k]=o.useState("branch"),[W,Z]=o.useState(!1),[B,Q]=o.useState(!1),[w,X]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const E=n.host.split("/"),_=E.length>=3?E[E.length-1]:n.host;F(_),N(n.username),I(""),D("token"),M(""),g(!1),L(""),A(n.host),K("string"),k("code")}else if(m)F(""),N(""),I(""),D("ssh"),M(""),g(!1),L(""),A(""),K("keyword"),k("branch");else if(y)F(y.name),N(y.userName),I(y.userEmail),D(y.authType||"ssh"),M(y.sshKey||""),g(y.signCommits===!0),L(y.signingKey||""),A(y.host||""),K(y.color||"keyword"),k(y.icon||"branch");else if(v){const E=r("global");E&&(F(E.name),N(E.userName),I(E.userEmail),D(E.authType||"ssh"),M(E.sshKey||""),g(!1),L(""),A(E.host||""),K(E.color||"keyword"),k(E.icon||"branch"))}}},[t,a,y,m,n,v,r]);const ee=async()=>{if(!S.trim()||!h.trim()){R.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(u==="token"&&!C.trim()){R.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(P&&!j.trim()){R.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}Z(!0);try{const E={name:p.trim()||S.trim(),userName:S.trim(),userEmail:h.trim(),authType:u,sshKey:u==="ssh"&&q.trim()||null,signCommits:P,signingKey:j.trim()||null,host:u==="token"&&C.trim()||null,color:b,icon:$};let _;if(m)_=await l(E);else if(a)_=await f(a,E);else return;_?(R.success(i(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):R.error(i(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(E){console.error("Error saving profile:",E),R.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{Z(!1)}},T=async()=>{if(!(!a||m)){X(!0);try{await c(a)?(R.success(i("settings.gitIdentities.editor.toast.profileDeleted")),Q(!1),e(!1)):R.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(E){console.error("Error deleting profile:",E),R.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{X(!1)}}},O=o.useMemo(()=>ho.find(_=>_.key===b)?.cssVar||"var(--syntax-keyword)",[b]),V=n?i("settings.gitIdentities.editor.title.importCredential"):m?i("settings.gitIdentities.editor.title.newIdentity"):v?i("settings.gitIdentities.editor.title.globalIdentity"):y?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Vt,{open:t,onOpenChange:e,children:s.jsxs($t,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:V}),s.jsx(Gt,{children:i(v?"settings.gitIdentities.editor.description.globalReadOnly":m?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!v&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Dt} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(He,{value:p,onChange:E=>F(E.target.value),placeholder:i("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:ho.map(E=>s.jsx("button",{type:"button",onClick:()=>K(E.key),className:ye("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",b===E.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:E.cssVar},title:E.label},E.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:ug.map(E=>{const _=E.Icon;return s.jsx("button",{type:"button",onClick:()=>k(E.key),className:ye("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",$===E.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:E.label,children:s.jsx(z,{name:_,className:"w-3.5 h-3.5",style:{color:$===E.key?O:"var(--surface-muted-foreground)"}})},E.key)})})]})]}),!v&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Dt,children:i("settings.gitIdentities.editor.field.userName")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(He,{value:S,onChange:E=>N(E.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!v,readOnly:v,disabled:v,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Dt,children:i("settings.gitIdentities.editor.field.emailAddress")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(He,{type:"email",value:h,onChange:E=>I(E.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!v,readOnly:v,disabled:v,className:"h-8"})]})]}),!v&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":u==="ssh",onClick:()=>D("ssh"),children:[s.jsx(z,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":u==="token",onClick:()=>D("token"),children:[s.jsx(z,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),u==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Dt,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(He,{value:q,onChange:E=>M(E.target.value),placeholder:i("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(gt,{checked:P,onChange:g,label:i("settings.gitIdentities.editor.field.signCommits"),info:i("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:i("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Dt,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(He,{value:j,onChange:E=>L(E.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!P,className:"h-8 font-mono text-xs"})]})]}),u==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Dt,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Yt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(He,{value:C,onChange:E=>A(E.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(is,{className:"gap-2",children:[!v&&!m&&s.jsxs(H,{variant:"outline",size:"sm",onClick:()=>Q(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(z,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.common.actions.delete")]}),s.jsx(H,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:i(v?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!v&&s.jsx(H,{size:"sm",onClick:ee,disabled:W,children:i(W?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Vt,{open:B,onOpenChange:E=>{w||Q(E)},children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Gt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:y?.name||p})})]}),s.jsxs(is,{children:[s.jsx(H,{variant:"ghost",onClick:()=>Q(!1),disabled:w,children:i("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{T()},disabled:w,children:i("settings.common.actions.delete")})]})]})})]})},hg={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},fg={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},xg=()=>{const t=ft.c(113),{t:e}=it(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:f,loadDiscoveredCredentials:c,loadDefaultGitIdentityId:y,setDefaultGitIdentityId:m,getUnimportedCredentials:v}=Tn(Cs(vg)),[p,F]=o.useState(!1),[S,N]=o.useState(null),[h,I]=o.useState(null),[u,D]=o.useState(null),[q,M]=o.useState(!1);let P,g;t[0]!==y||t[1]!==c||t[2]!==f||t[3]!==l?(P=()=>{l(),f(),c(),y()},g=[l,f,c,y],t[0]=y,t[1]=c,t[2]=f,t[3]=l,t[4]=P,t[5]=g):(P=t[4],g=t[5]),o.useEffect(P,g);let j,L,C,A,b,K,$,k,W,Z,B,Q,w,X;if(t[6]!==i||t[7]!==u||t[8]!==r||t[9]!==v||t[10]!==n||t[11]!==a||t[12]!==m||t[13]!==e){const Te=v();let Qe;t[28]===Symbol.for("react.memo_cache_sentinel")?(Qe=(Ue,je)=>{N(Ue),I(je??null),F(!0)},t[28]=Qe):Qe=t[28];const Be=Qe;let Ke;t[29]!==i||t[30]!==m||t[31]!==e?(Ke=async Ue=>{const je=i===Ue?null:Ue;if(!await m(je)){R.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}R.success(e(je?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=m,t[31]=e,t[32]=Ke):Ke=t[32];const Ge=Ke;let qe;t[33]!==u||t[34]!==r||t[35]!==e?(qe=async()=>{if(!u)return;M(!0),await r(u.id)?(R.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:u.name})),D(null)):R.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),M(!1)},t[33]=u,t[34]=r,t[35]=e,t[36]=qe):qe=t[36],C=qe,L=as,t[37]!==e?(A=e("settings.page.git.title"),t[37]=e,t[38]=A):A=t[38],b=!0,t[39]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(hl,{}),t[39]=K):K=t[39],j=Le,t[40]!==e?(Q=e("settings.gitIdentities.page.section.title"),t[40]=e,t[41]=Q):Q=t[41];let Ie,Re;t[42]===Symbol.for("react.memo_cache_sentinel")?(Ie=()=>Be("new"),Re=s.jsx(z,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[42]=Ie,t[43]=Re):(Ie=t[42],Re=t[43]);let $e;t[44]!==e?($e=e("settings.common.badge.new"),t[44]=e,t[45]=$e):$e=t[45],t[46]!==$e?(w=s.jsxs(H,{size:"sm",variant:"outline",onClick:Ie,children:[Re," ",$e]}),t[46]=$e,t[47]=w):w=t[47],X="git.identities",$="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",k=n&&s.jsx(fo,{profile:n,isDefault:i==="global",onEdit:()=>Be("global"),onToggleDefault:()=>Ge("global"),isReadOnly:!0,hasBorder:a.length>0||Te.length>0}),W=a.map((Ue,je)=>s.jsx(fo,{profile:Ue,isDefault:i===Ue.id,onEdit:()=>Be(Ue.id),onToggleDefault:()=>Ge(Ue.id),onDelete:()=>D(Ue),hasBorder:je<a.length-1||Te.length>0},Ue.id)),Z=!n&&a.length===0&&Te.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(z,{name:"shield-keyhole",className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),B=Te.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),Te.map((Ue,je)=>s.jsx(bg,{credential:Ue,onImport:()=>Be("new",{host:Ue.host,username:Ue.username}),hasBorder:je<Te.length-1},`${Ue.host}-${Ue.username}`))]}),t[6]=i,t[7]=u,t[8]=r,t[9]=v,t[10]=n,t[11]=a,t[12]=m,t[13]=e,t[14]=j,t[15]=L,t[16]=C,t[17]=A,t[18]=b,t[19]=K,t[20]=$,t[21]=k,t[22]=W,t[23]=Z,t[24]=B,t[25]=Q,t[26]=w,t[27]=X}else j=t[14],L=t[15],C=t[16],A=t[17],b=t[18],K=t[19],$=t[20],k=t[21],W=t[22],Z=t[23],B=t[24],Q=t[25],w=t[26],X=t[27];let ee;t[48]!==$||t[49]!==k||t[50]!==W||t[51]!==Z||t[52]!==B?(ee=s.jsxs("div",{className:$,children:[k,W,Z,B]}),t[48]=$,t[49]=k,t[50]=W,t[51]=Z,t[52]=B,t[53]=ee):ee=t[53];let T;t[54]!==j||t[55]!==ee||t[56]!==Q||t[57]!==w||t[58]!==X?(T=s.jsx(j,{title:Q,headerAction:w,settingsItem:X,children:ee}),t[54]=j,t[55]=ee,t[56]=Q,t[57]=w,t[58]=X,t[59]=T):T=t[59];let O;t[60]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(gl,{}),t[60]=O):O=t[60];let V;t[61]!==L||t[62]!==A||t[63]!==b||t[64]!==K||t[65]!==T?(V=s.jsxs(L,{title:A,showSaveStatus:b,children:[K,T,O]}),t[61]=L,t[62]=A,t[63]=b,t[64]=K,t[65]=T,t[66]=V):V=t[66];let E;t[67]!==h||t[68]!==p||t[69]!==S?(E=s.jsx(gg,{open:p,onOpenChange:F,profileId:S,importData:h}),t[67]=h,t[68]=p,t[69]=S,t[70]=E):E=t[70];const _=u!==null;let J;t[71]!==q?(J=Te=>{q||Te||D(null)},t[71]=q,t[72]=J):J=t[72];let te;t[73]!==e?(te=e("settings.gitIdentities.page.deleteDialog.title"),t[73]=e,t[74]=te):te=t[74];let ne;t[75]!==te?(ne=s.jsx(Ht,{children:te}),t[75]=te,t[76]=ne):ne=t[76];const le=u?.name??"";let be;t[77]!==e||t[78]!==le?(be=e("settings.gitIdentities.page.deleteDialog.description",{name:le}),t[77]=e,t[78]=le,t[79]=be):be=t[79];let Ne;t[80]!==be?(Ne=s.jsx(Gt,{children:be}),t[80]=be,t[81]=Ne):Ne=t[81];let de;t[82]!==ne||t[83]!==Ne?(de=s.jsxs(Bt,{children:[ne,Ne]}),t[82]=ne,t[83]=Ne,t[84]=de):de=t[84];let ue;t[85]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>D(null),t[85]=ue):ue=t[85];let Me;t[86]!==e?(Me=e("settings.common.actions.cancel"),t[86]=e,t[87]=Me):Me=t[87];let Ce;t[88]!==q||t[89]!==Me?(Ce=s.jsx(H,{variant:"ghost",onClick:ue,disabled:q,children:Me}),t[88]=q,t[89]=Me,t[90]=Ce):Ce=t[90];let ke;t[91]!==C?(ke=()=>{C()},t[91]=C,t[92]=ke):ke=t[92];let fe;t[93]!==e?(fe=e("settings.common.actions.delete"),t[93]=e,t[94]=fe):fe=t[94];let ze;t[95]!==q||t[96]!==ke||t[97]!==fe?(ze=s.jsx(H,{size:"sm",variant:"destructive",onClick:ke,disabled:q,children:fe}),t[95]=q,t[96]=ke,t[97]=fe,t[98]=ze):ze=t[98];let Ae;t[99]!==Ce||t[100]!==ze?(Ae=s.jsxs(is,{children:[Ce,ze]}),t[99]=Ce,t[100]=ze,t[101]=Ae):Ae=t[101];let he;t[102]!==de||t[103]!==Ae?(he=s.jsxs($t,{className:"max-w-md",children:[de,Ae]}),t[102]=de,t[103]=Ae,t[104]=he):he=t[104];let ge;t[105]!==_||t[106]!==J||t[107]!==he?(ge=s.jsx(Vt,{open:_,onOpenChange:J,children:he}),t[105]=_,t[106]=J,t[107]=he,t[108]=ge):ge=t[108];let Ee;return t[109]!==V||t[110]!==E||t[111]!==ge?(Ee=s.jsxs(s.Fragment,{children:[V,E,ge]}),t[109]=V,t[110]=E,t[111]=ge,t[112]=Ee):Ee=t[112],Ee},fo=t=>{const e=ft.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:f,hasBorder:c}=t,{t:y}=it(),[m,v]=o.useState(!1),p=hg[a.icon||"branch"]||"git-branch",F=fg[a.color||""],S=a.authType||"ssh";let N;e[0]!==i?(N=T=>{T.currentTarget===T.target&&(T.key!=="Enter"&&T.key!==" "||(T.preventDefault(),i()))},e[0]=i,e[1]=N):N=e[1];const h=N;let I;e[2]!==n||e[3]!==f||e[4]!==l||e[5]!==r||e[6]!==y?(I=T=>s.jsxs(s.Fragment,{children:[s.jsx(T,{onClick:O=>{O.stopPropagation(),r()},children:y(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!f&&l&&s.jsxs(T,{onClick:O=>{O.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(z,{name:"delete-bin",className:"h-4 w-4 mr-px"}),y("settings.common.actions.delete")]})]}),e[2]=n,e[3]=f,e[4]=l,e[5]=r,e[6]=y,e[7]=I):I=e[7];const u=I,D=c&&"border-b border-[var(--surface-subtle)]";let q;e[8]!==D?(q=ye("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",D),e[8]=D,e[9]=q):q=e[9];let M;e[10]===Symbol.for("react.memo_cache_sentinel")?(M=T=>{T.preventDefault(),v(!0)},e[10]=M):M=e[10];let P;e[11]!==h||e[12]!==i||e[13]!==q?(P=s.jsx("div",{className:q,onClick:i,role:"button",tabIndex:0,onKeyDown:h,onContextMenu:M}),e[11]=h,e[12]=i,e[13]=q,e[14]=P):P=e[14];let g;e[15]!==F?(g={color:F},e[15]=F,e[16]=g):g=e[16];let j;e[17]!==p||e[18]!==g?(j=s.jsx(z,{name:p,className:"w-4 h-4 shrink-0",style:g}),e[17]=p,e[18]=g,e[19]=j):j=e[19];let L;e[20]!==a.name?(L=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=L):L=e[21];let C;e[22]!==S?(C=s.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:S}),e[22]=S,e[23]=C):C=e[23];let A;e[24]!==n||e[25]!==y?(A=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:y("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=y,e[26]=A):A=e[26];let b;e[27]!==f||e[28]!==y?(b=f&&s.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:y("settings.agents.sidebar.badge.system")}),e[27]=f,e[28]=y,e[29]=b):b=e[29];let K;e[30]!==C||e[31]!==A||e[32]!==b||e[33]!==L?(K=s.jsxs("div",{className:"flex items-center gap-1.5",children:[L,C,A,b]}),e[30]=C,e[31]=A,e[32]=b,e[33]=L,e[34]=K):K=e[34];const $=S==="token"&&a.host?a.host:a.userEmail;let k;e[35]!==$?(k=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:$}),e[35]=$,e[36]=k):k=e[36];let W;e[37]!==K||e[38]!==k?(W=s.jsxs("div",{className:"min-w-0",children:[K,k]}),e[37]=K,e[38]=k,e[39]=W):W=e[39];let Z;e[40]!==W||e[41]!==j?(Z=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[j,W]}),e[40]=W,e[41]=j,e[42]=Z):Z=e[42];let B;e[43]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Bs,{asChild:!0,children:s.jsx(H,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:yg,children:s.jsx(z,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=B):B=e[43];let Q;e[44]!==u?(Q=s.jsxs(Gs,{children:[B,s.jsx(Hs,{align:"end",className:"w-fit min-w-28",children:u(qs)})]}),e[44]=u,e[45]=Q):Q=e[45];let w;e[46]!==Z||e[47]!==Q||e[48]!==P?(w=s.jsxs(On,{render:P,children:[Z,Q]}),e[46]=Z,e[47]=Q,e[48]=P,e[49]=w):w=e[49];let X;e[50]!==u?(X=s.jsx(Mn,{className:"w-fit min-w-28",children:u(Rn)}),e[50]=u,e[51]=X):X=e[51];let ee;return e[52]!==m||e[53]!==w||e[54]!==X?(ee=s.jsxs(Ln,{open:m,onOpenChange:v,children:[w,X]}),e[52]=m,e[53]=w,e[54]=X,e[55]=ee):ee=e[55],ee},bg=t=>{const e=ft.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=it();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const f=l,c=f.length>=3?f[f.length-1]:a.host,y=a.host.includes("/"),m=i&&"border-b border-[var(--surface-subtle)]";let v;e[2]!==m?(v=ye("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=v):v=e[3];let p;e[4]!==c?(p=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:c}),e[4]=c,e[5]=p):p=e[5];const F=y?a.host:a.username;let S;e[6]!==F?(S=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:F}),e[6]=F,e[7]=S):S=e[7];let N;e[8]!==p||e[9]!==S?(N=s.jsxs("div",{className:"min-w-0",children:[p,S]}),e[8]=p,e[9]=S,e[10]=N):N=e[10];let h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(z,{name:"download",className:"h-3 w-3"}),e[11]=h):h=e[11];let I;e[12]!==r?(I=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=I):I=e[13];let u;e[14]!==n||e[15]!==I?(u=s.jsxs(H,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[h,I]}),e[14]=n,e[15]=I,e[16]=u):u=e[16];let D;return e[17]!==u||e[18]!==v||e[19]!==N?(D=s.jsxs("div",{className:v,children:[N,u]}),e[17]=u,e[18]=v,e[19]=N,e[20]=D):D=e[20],D};function vg(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function yg(t){return t.stopPropagation()}const Ii=[{id:"opencode-claude",packageName:"@openchamber/opencode-claude",providerId:"claude-code",icon:"claude-code",brandClassName:"text-[#D97757]",nameKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",homepage:"https://github.com/openchamber/opencode-claude"},{id:"opencode-commandcode",packageName:"@openchamber/opencode-commandcode",providerId:"command-code",icon:"command-code",brandClassName:"text-foreground",nameKey:"settings.integrations.thirdParty.opencodeCommandcode.name",descriptionKey:"settings.integrations.thirdParty.opencodeCommandcode.description",homepage:"https://github.com/openchamber/opencode-commandcode"},{id:"opencode-cursor-oauth",packageName:"@openchamber/opencode-cursor",providerId:"cursor",icon:"cursor",brandClassName:"text-foreground",nameKey:"settings.integrations.thirdParty.opencodeCursorOauth.name",descriptionKey:"settings.integrations.thirdParty.opencodeCursorOauth.description",homepage:"https://github.com/openchamber/opencode-cursor"}],jg=(t,e)=>t===e||t.startsWith(`${e}@`);function Ai(t,e,a){const n=t.filter(c=>jg(c.spec,e)),i=n.filter(c=>c.scope==="user"),r=n.filter(c=>c.scope==="project"),l=i.length===1?i[0]:null,f=a[l?.spec??e]??a[e]??null;return{userEntry:l,userEntryIsAmbiguous:i.length>1,projectEntries:r,registry:f}}function Wi(t,e){return e?.kind!=="npm-ok"||e.name!==t||!e.latestVersion?null:`${t}@${e.latestVersion}`}function xo(t,e){if(t.userEntryIsAmbiguous)return"manage";if(!t.userEntry)return"install";const a=Wi(e,t.registry);return a&&a!==t.userEntry.spec?"update":"setup"}function wg(t,e={}){const a=t.registry?.kind==="npm-ok"?t.registry.latestVersion:null;return t.userEntryIsAmbiguous?{status:"ambiguous",latestVersion:a}:e.restartRequired?{status:"restart-required",latestVersion:a}:e.providerUnavailable?{status:"provider-unavailable",latestVersion:a}:e.registryUnavailable?{status:"registry-unavailable",latestVersion:a}:t.userEntry?t.registry?.kind==="npm-ok"&&t.registry.currentVersion===t.registry.latestVersion?{status:"installed-version",latestVersion:a}:t.registry?.kind==="npm-ok"&&t.registry.currentVersion===null?{status:"unpinned",latestVersion:a}:t.registry?.kind==="npm-ok"&&a?{status:"update-available",latestVersion:a}:{status:"installed",latestVersion:a}:{status:"not-installed",latestVersion:a}}const kg=t=>t.restartDeferred===!0||t.requiresManualRestart===!0||t.reloadFailed===!0,Ng=({divider:t=!0,onOpenProviderSetup:e,onOpenPluginManager:a})=>{const{t:n}=it(),{entries:i,registryInfo:r,loadPlugins:l,loadRegistryInfo:f,createEntry:c,updateEntry:y,deleteEntry:m}=ls(Cs(B=>({entries:B.entries,registryInfo:B.registryInfo,loadPlugins:B.loadPlugins,loadRegistryInfo:B.loadRegistryInfo,createEntry:B.createEntry,updateEntry:B.updateEntry,deleteEntry:B.deleteEntry}))),[v,p]=o.useState(!1),[F,S]=o.useState(null),[N,h]=o.useState(()=>new Set),[I,u]=o.useState(()=>new Set),[D,q]=o.useState(null),[M,P]=o.useState(()=>new Set),g=o.useCallback(async()=>{if(!await l({force:!0})){p(!0);return}const Q=ls.getState().entries,w=new Set(Ii.map(ee=>ee.packageName));for(const ee of Q)Ii.some(T=>ee.spec===T.packageName||ee.spec.startsWith(`${T.packageName}@`))&&w.add(ee.spec);const X=await f({specs:[...w],force:!0});p(!X)},[l,f]);o.useEffect(()=>{g()},[g]);const j=ln(B=>B.changes.filter(Q=>Q.scope==="plugins").length),L=ln(B=>B.isApplying),C=o.useRef(j);o.useEffect(()=>{const B=C.current;C.current=j,!L&&(B<=0||j>0||(h(new Set),u(new Set),g()))},[L,j,g]);const A=o.useCallback((B,Q)=>{h(w=>{const X=new Set(w);return Q?X.add(B):X.delete(B),X})},[]),b=o.useCallback((B,Q)=>{u(w=>{const X=new Set(w);return Q?X.add(B):X.delete(B),X})},[]),K=o.useCallback(async(B,Q,w)=>{S({pluginId:B.id,action:Q});try{const X=await w();if(!X.ok){R.error(n("settings.integrations.thirdParty.toast.actionFailed"));return}b(B.id,!1);const ee=kg(X);A(B.id,ee);const T=ee?{description:n("settings.integrations.thirdParty.toast.restartRequired")}:void 0;Q==="install"?R.success(n("settings.integrations.thirdParty.toast.installed",{name:n(B.nameKey)}),T):Q==="update"?R.success(n("settings.integrations.thirdParty.toast.updated",{name:n(B.nameKey)}),T):R.success(n("settings.integrations.thirdParty.toast.removed",{name:n(B.nameKey)}),T),await g()}finally{S(null)}},[g,b,A,n]),$=o.useCallback(async B=>{const Q=Ai(i,B.packageName,r),w=xo(Q,B.packageName);if(w==="manage"){a();return}if(w==="setup"){S({pluginId:B.id,action:w});try{const ee=await e(B.providerId);b(B.id,!ee),ee||R.error(n("settings.integrations.thirdParty.toast.providerUnavailable"))}finally{S(null)}return}const X=Wi(B.packageName,Q.registry);if(!X){p(!0);return}if(w==="install"){await K(B,"install",()=>c({spec:X,scope:"user"}));return}Q.userEntry&&await K(B,"update",()=>y(Q.userEntry.id,{spec:X}))},[c,i,a,e,r,K,b,n,y]),k=o.useCallback(async()=>{const B=D;if(!B)return;const Q=Ai(i,B.packageName,r);if(!Q.userEntry||Q.userEntryIsAmbiguous){q(null),a();return}q(null),await K(B,"remove",()=>m(Q.userEntry.id))},[m,i,a,r,D,K]),W=o.useCallback((B,Q)=>{P(w=>{const X=new Set(w);return Q?X.add(B):X.delete(B),X})},[]),Z=B=>{const Q=Ai(i,B.packageName,r),w=xo(Q,B.packageName),X=Wi(B.packageName,Q.registry),ee=F?.pluginId===B.id,T=N.has(B.id),O=I.has(B.id),V=v||Q.registry?.kind==="npm-network",E=ee||T||(w==="install"||w==="update")&&(V||!X),_=wg(Q,{registryUnavailable:V,restartRequired:T,providerUnavailable:O});let J;switch(_.status){case"installed-version":J=_.latestVersion?n("settings.integrations.thirdParty.status.installedVersion",{version:_.latestVersion}):n("settings.integrations.thirdParty.status.installed");break;case"update-available":J=_.latestVersion?n("settings.integrations.thirdParty.status.updateAvailable",{version:_.latestVersion}):n("settings.integrations.thirdParty.status.unpinned");break;case"not-installed":J=n("settings.integrations.thirdParty.status.notInstalled");break;case"installed":J=n("settings.integrations.thirdParty.status.installed");break;case"unpinned":J=n("settings.integrations.thirdParty.status.unpinned");break;case"ambiguous":J=n("settings.integrations.thirdParty.status.ambiguous");break;case"restart-required":J=n("settings.integrations.thirdParty.status.restartRequired");break;case"registry-unavailable":J=n("settings.integrations.thirdParty.status.registryUnavailable");break;case"provider-unavailable":J=n("settings.integrations.thirdParty.status.providerUnavailable");break}const te=_.status==="installed-version"?"bg-[var(--status-success)]/15 text-[var(--status-success)]":_.status==="update-available"||_.status==="ambiguous"||_.status==="restart-required"||_.status==="registry-unavailable"||_.status==="provider-unavailable"?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":"bg-[var(--surface-muted)] text-muted-foreground",ne={install:n("settings.integrations.thirdParty.actions.install"),update:n("settings.integrations.thirdParty.actions.update"),setup:n("settings.integrations.thirdParty.actions.setup"),manage:n("settings.integrations.thirdParty.actions.managePlugins")}[w],le=M.has(B.id);return s.jsx(Yn,{open:le,onOpenChange:be=>W(B.id,be),children:s.jsxs("div",{"data-settings-item":`integrations.third-party.${B.id}`,className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Zn,{className:"flex w-full min-w-0 items-center gap-3 px-4 py-3 text-left hover:bg-[var(--interactive-hover)]/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]",children:[s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:B.providerId==="command-code"?s.jsx(jn,{providerId:B.providerId,className:"size-5"}):s.jsx(z,{name:B.icon,className:ye("size-5",B.brandClassName)})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:n(B.nameKey)}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:n(B.descriptionKey)})]}),s.jsx("span",{"aria-live":"polite",className:ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",te),children:J}),s.jsx(z,{name:"arrow-down-s",className:ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",le&&"rotate-180")})]}),s.jsx(Xn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[Q.projectEntries.length>0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.thirdParty.status.projectInstalled")}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{type:"button",size:"sm",variant:w==="manage"?"outline":"default",onClick:()=>{$(B)},disabled:E,children:[ee?s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"}):w==="setup"?s.jsx(z,{name:"plug-2",className:"size-3.5"}):null,ne]}),s.jsxs(H,{type:"button",size:"sm",variant:"secondary",onClick:()=>{Nn(B.homepage)},children:[s.jsx(z,{name:"external-link",className:"size-3.5"}),n("settings.integrations.thirdParty.actions.docs")]}),Q.userEntry&&!Q.userEntryIsAmbiguous?s.jsxs(H,{type:"button",size:"sm",variant:"destructive",onClick:()=>q(B),disabled:ee,children:[s.jsx(z,{name:"delete-bin",className:"size-3.5"}),n("settings.integrations.thirdParty.actions.remove")]}):null]})]})})]})},B.id)};return s.jsxs(s.Fragment,{children:[s.jsx(Le,{title:n("settings.integrations.thirdParty.title"),info:n("settings.integrations.thirdParty.info"),divider:t,settingsItem:"integrations.third-party",contentClassName:"space-y-3",children:Ii.map(Z)}),s.jsx(Vt,{open:D!==null,onOpenChange:B=>!B&&q(null),children:s.jsxs($t,{className:"max-w-md",children:[s.jsxs(Bt,{children:[s.jsx(Ht,{children:n("settings.integrations.thirdParty.dialog.remove.title")}),s.jsx(Gt,{children:n("settings.integrations.thirdParty.dialog.remove.description",{name:D?n(D.nameKey):""})})]}),s.jsxs(is,{children:[s.jsx(H,{type:"button",size:"sm",variant:"ghost",onClick:()=>q(null),children:n("settings.common.actions.cancel")}),s.jsx(H,{type:"button",size:"sm",variant:"destructive",onClick:()=>{k()},children:n("settings.integrations.thirdParty.actions.remove")})]})]})})]})},Sg=t=>{const e=ft.c(11),{onOpenProviderSetup:a,onOpenPluginManager:n}=t,{t:i}=it();let r;e[0]!==i?(r=i("settings.page.integrations.title"),e[0]=i,e[1]=r):r=e[1];let l;e[2]!==i?(l=i("settings.page.integrations.description"),e[2]=i,e[3]=l):l=e[3];let f;e[4]!==n||e[5]!==a?(f=s.jsx(Ng,{divider:!1,onOpenProviderSetup:a,onOpenPluginManager:n}),e[4]=n,e[5]=a,e[6]=f):f=e[6];let c;return e[7]!==r||e[8]!==l||e[9]!==f?(c=s.jsx(as,{title:r,description:l,showSaveStatus:!1,children:f}),e[7]=r,e[8]=l,e[9]=f,e[10]=c):c=e[10],c},Cg=[{value:"system",labelKey:"settings.openchamber.visual.option.themeMode.system",descriptionKey:"settings.openchamber.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.openchamber.visual.option.themeMode.light",descriptionKey:"settings.openchamber.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.openchamber.visual.option.themeMode.dark",descriptionKey:"settings.openchamber.visual.option.themeMode.dark.description"}],Pg=[{id:"dynamic",labelKey:"settings.openchamber.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.openchamber.visual.option.diffLayout.inline.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.openchamber.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.openchamber.visual.option.diffLayout.sideBySide.description"}],Ig=[{id:"svg",labelKey:"settings.openchamber.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.openchamber.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.openchamber.visual.option.mermaidRendering.ascii.description"}],ua="OpenChamber - AI Coding Assistant",bo=[{id:"system",labelKey:"settings.openchamber.visual.option.pwaOrientation.system.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.openchamber.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.openchamber.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.openchamber.visual.option.pwaOrientation.landscape.description"}],vo=[{id:"native",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.description"}],Ag=[{value:"default",labelKey:"settings.openchamber.visual.option.mobileLayout.default"},{value:"new",labelKey:"settings.openchamber.visual.option.mobileLayout.new"}],Ei=t=>t==="portrait"||t==="landscape"?t:"system",Eg=[{id:"markdown",labelKey:"settings.openchamber.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.openchamber.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.openchamber.visual.option.userMessageRendering.plain.description"}],Tg=[{id:"sorted",labelKey:"settings.openchamber.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.openchamber.visual.option.chatRenderMode.live.label",descriptionKey:"settings.openchamber.visual.option.chatRenderMode.live.description"}],yo=[{id:"auto",labelKey:"settings.openchamber.visual.option.messageTransport.auto.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.openchamber.visual.option.messageTransport.ws.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.openchamber.visual.option.messageTransport.sse.label",descriptionKey:"settings.openchamber.visual.option.messageTransport.sse.description"}],Dg=[{id:"collapsed",labelKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.openchamber.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.openchamber.visual.option.activityRenderMode.summary.description"}],jo=[{id:"auto",labelKey:"settings.openchamber.visual.option.timeFormat.auto.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.openchamber.visual.option.timeFormat.24h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.openchamber.visual.option.timeFormat.12h.label",descriptionKey:"settings.openchamber.visual.option.timeFormat.12h.description"}],wo=[{id:"auto",labelKey:"settings.openchamber.visual.option.weekStart.auto.label",descriptionKey:"settings.openchamber.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.openchamber.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.openchamber.visual.option.weekStart.sunday.label"}],Mg=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],Rg=t=>t==="markdown"?"markdown":"plain",Og=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],Lg=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],ti=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=it(),l=o.useCallback(d=>r(d),[r]),{isMobile:f}=ea(),{terminal:c}=Ko(),{browserTab:y}=id(),m=$c(),v=ce(d=>d.showReasoningTraces),p=ce(d=>d.sessionRecapEnabled),F=ce(d=>d.sessionSuggestionEnabled),S=ce(d=>d.setSessionRecapEnabled),N=ce(d=>d.setSessionSuggestionEnabled),h=ce(d=>d.sessionGoalEnabled),I=ce(d=>d.setSessionGoalEnabled),u=ce(d=>d.sessionGoalDefaultBudgetEnabled),D=ce(d=>d.setSessionGoalDefaultBudgetEnabled),q=ce(d=>d.sessionGoalDefaultBudget),M=ce(d=>d.setSessionGoalDefaultBudget),P=ce(d=>d.setShowReasoningTraces),g=ce(d=>d.collapsibleThinkingBlocks),j=ce(d=>d.setCollapsibleThinkingBlocks),L=ce(d=>d.mermaidRenderingMode),C=ce(d=>d.setMermaidRenderingMode),A=ce(d=>d.userMessageRenderingMode),b=ce(d=>d.setUserMessageRenderingMode),K=ce(d=>d.collapsibleUserMessages),$=ce(d=>d.setCollapsibleUserMessages),k=ce(d=>d.stickyUserHeader),W=ce(d=>d.promptNavigatorEnabled),Z=ce(d=>d.setStickyUserHeader),B=ce(d=>d.setPromptNavigatorEnabled),Q=ce(d=>d.expandedEditorToolbar),w=ce(d=>d.setExpandedEditorToolbar),X=ce(d=>d.autoSaveEnabled),ee=ce(d=>d.setAutoSaveEnabled),T=ce(d=>d.wideChatLayoutEnabled),O=ce(d=>d.setWideChatLayoutEnabled),V=ce(d=>d.codeBlockLineWrap),E=ce(d=>d.setCodeBlockLineWrap),_=ce(d=>d.chatRenderMode),J=ce(d=>d.setChatRenderMode),te=ce(d=>d.activityRenderMode),ne=ce(d=>d.setActivityRenderMode),le=ce(d=>d.fontSize),be=ce(d=>d.setFontSize),Ne=ce(d=>d.terminalFontSize),de=ce(d=>d.setTerminalFontSize),ue=ce(d=>d.terminalShell),Me=ce(d=>d.setTerminalShell),Ce=ce(d=>d.terminalLoginShells),ke=ce(d=>d.setTerminalLoginShells),fe=ce(d=>d.editorFontSize),ze=ce(d=>d.setEditorFontSize),Ae=ce(d=>d.uiFont),he=ce(d=>d.setUiFont),ge=ce(d=>d.monoFont),Ee=ce(d=>d.setMonoFont),Te=ce(d=>d.padding),Qe=ce(d=>d.setPadding),Be=ce(d=>d.inputBarOffset),Ke=ce(d=>d.setInputBarOffset),Ge=ce(d=>d.mobileKeyboardMode),qe=ce(d=>d.setMobileKeyboardMode),Ie=ce(d=>d.diffLayoutPreference),Re=ce(d=>d.setDiffLayoutPreference),$e=ce(d=>d.showTerminalQuickKeysOnDesktop),Ue=ce(d=>d.setShowTerminalQuickKeysOnDesktop),je=ce(d=>d.fileEditorKeymap),U=ce(d=>d.setFileEditorKeymap),re=Nr(d=>d.followUpBehavior),pe=Nr(d=>d.setFollowUpBehavior),ve=ce(d=>d.persistChatDraft),ae=ce(d=>d.setPersistChatDraft),_e=ce(d=>d.inputSpellcheckEnabled),Ze=ce(d=>d.setInputSpellcheckEnabled),G=ce(d=>d.showToolFileIcons),Fe=ce(d=>d.setShowToolFileIcons),Ye=ce(d=>d.showTurnChangedFiles),st=ce(d=>d.setShowTurnChangedFiles),et=ce(d=>d.showExpandedBashTools),wt=ce(d=>d.setShowExpandedBashTools),pt=ce(d=>d.showExpandedEditTools),mt=ce(d=>d.setShowExpandedEditTools),ot=ce(d=>d.timeFormatPreference),bt=ce(d=>d.setTimeFormatPreference),ut=ce(d=>d.weekStartPreference),At=ce(d=>d.setWeekStartPreference),ie=ce(d=>d.showSplitAssistantMessageActions),Pe=ce(d=>d.setShowSplitAssistantMessageActions),Ve=ce(d=>d.allowPromptingSubagentSessions),We=ce(d=>d.setAllowPromptingSubagentSessions),kt=ce(d=>d.draftStartersVisible),St=ce(d=>d.setDraftStartersVisible),Wt=tt(d=>d.settingsMessageStreamTransport),Y=tt(d=>d.setSettingsMessageStreamTransport),xe=Wt,Oe=tt(d=>d.settingsDefaultFileViewerPreview),we=tt(d=>d.setSettingsDefaultFileViewerPreview),rt=ce(d=>d.isSettingsDialogOpen),{themeMode:ct,setThemeMode:at,availableThemes:Ct,customThemesLoading:ss,reloadCustomThemes:es,lightThemeId:ds,darkThemeId:Jt,setLightThemePreference:Nt,setDarkThemePreference:Pt}=er(),[Et,yt]=o.useState(!1),zt=o.useMemo(()=>cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Zt=ce(d=>d.dockBadgeEnabled),js=ce(d=>d.setDockBadgeEnabled),oe=Bc(),ht=ce(d=>d.desktopWindowControlsPosition),Se=ce(d=>d.setDesktopWindowControlsPosition),nt=ce(d=>d.desktopWindowControlsStyle),xt=ce(d=>d.setDesktopWindowControlsStyle),[It,Kt]=o.useState(0),hs=ce(d=>d.reportUsage),Ps=ce(d=>d.setReportUsage),fs=o.useCallback(d=>{Ps(d),vt({reportUsage:d})},[Ps]),Kn=o.useCallback(d=>{Se(d),vt({desktopWindowControlsPosition:d})},[Se]),zn=o.useCallback(d=>{xt(d),vt({desktopWindowControlsStyle:d})},[xt]),Is=(rt||f||ps())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Is)return;let d=null,jt=Date.now();const xs=()=>{const en=Date.now();en-jt>=420&&(Kt(In=>(In+1)%24),jt=en),d=requestAnimationFrame(xs)};(typeof document>"u"||document.visibilityState==="visible")&&(d=requestAnimationFrame(xs));const us=()=>{document.visibilityState==="visible"&&d===null?d=requestAnimationFrame(xs):document.visibilityState!=="visible"&&d!==null&&(cancelAnimationFrame(d),d=null)};return document.addEventListener("visibilitychange",us),()=>{document.removeEventListener("visibilitychange",us),d!==null&&cancelAnimationFrame(d)}},[Is]);const ta=o.useCallback(d=>{b(d),vt({userMessageRenderingMode:d})},[b]),si=o.useCallback(d=>{Z(d),vt({stickyUserHeader:d})},[Z]),Pa=o.useCallback(d=>{B(d),vt({promptNavigatorEnabled:d})},[B]),ni=o.useCallback(d=>{St(d),vt({draftStartersVisible:d})},[St]),ai=o.useCallback(d=>{w(d),vt({expandedEditorToolbar:d})},[w]),ii=o.useCallback(d=>{$(d),vt({collapsibleUserMessages:d})},[$]),ri=o.useCallback(d=>{O(d),vt({wideChatLayoutEnabled:d})},[O]),oi=o.useCallback(d=>{Pe(d),vt({showSplitAssistantMessageActions:d})},[Pe]),As=o.useCallback(d=>{Ze(d),vt({inputSpellcheckEnabled:d})},[Ze]),zs=o.useCallback(d=>{J(d),vt({chatRenderMode:d})},[J]),Un=o.useCallback(d=>{Y(d),vt({messageStreamTransport:d})},[Y]),Js=o.useCallback(d=>{ne(d),vt({activityRenderMode:d})},[ne]),cn=o.useCallback(d=>{C(d),vt({mermaidRenderingMode:d})},[C]),rr=o.useCallback(d=>{Fe(d),vt({showToolFileIcons:d})},[Fe]),dn=o.useCallback(d=>{st(d),vt({showTurnChangedFiles:d})},[st]),li=o.useCallback(d=>{we(d),vt({defaultFileViewerPreview:d}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:d}}))},[we]),_n=o.useCallback(d=>{wt(d),vt({showExpandedBashTools:d})},[wt]),ci=o.useCallback(d=>{mt(d),vt({showExpandedEditTools:d})},[mt]),ms=o.useCallback(d=>{bt(d),vt({timeFormatPreference:d})},[bt]),di=o.useCallback(d=>{At(d),vt({weekStartPreference:d})},[At]),Qs=o.useMemo(()=>Ct.filter(d=>d.metadata.variant==="light").sort((d,jt)=>d.metadata.name.localeCompare(jt.metadata.name)),[Ct]),Ys=o.useMemo(()=>Ct.filter(d=>d.metadata.variant==="dark").sort((d,jt)=>d.metadata.name.localeCompare(jt.metadata.name)),[Ct]),sa=o.useMemo(()=>Qs.find(d=>d.metadata.id===ds)??Qs[0],[Qs,ds]),Vn=o.useMemo(()=>Ys.find(d=>d.metadata.id===Jt)??Ys[0],[Ys,Jt]),Zs=o.useCallback((d,jt)=>{const xs=jt==="dark"?" Dark":" Light";return d.endsWith(xs)?d.slice(0,-xs.length):d},[]),me=d=>t?t.includes(d):!0,rs=ps(),Sn=me("theme")&&!rs,Ia=me("windowControlsPosition")&&oe,Aa=me("theme")||me("timeFormat")||me("weekStart"),Ea=f&&wn()&&!cs()&&!rs,Ta=rs?Aa:me("theme")||Ia||Ea||me("pwaInstallName")||me("pwaOrientation")||me("timeFormat")||me("weekStart"),Da=me("fontSize")||me("terminalFontSize")||me("editorFontSize")||me("spacing")||me("inputBarOffset")&&f,Ma=me("terminalQuickKeys")&&!f||(me("terminalShell")||me("terminalLoginShell"))&&!rs||me("fileEditorKeymap")||me("autoSaveEnabled")||me("expandedEditorToolbar")&&!rs,pi=me("mermaidRendering")||me("sessionGoal")&&!rs||me("userMessageRendering")||me("chatRenderMode")||me("messageTransport")||me("activityRenderMode")&&_==="sorted"||me("collapsibleUserMessages")||me("stickyUserHeader")||me("promptNavigatorEnabled")&&!rs||me("wideChatLayout")||me("codeBlockLineWrap")||me("splitAssistantMessageActions")||me("subagentReadOnlyBanner")||me("diffLayout")||me("dotfiles")||me("fileViewerPreview")||me("reasoning")||me("followUpBehavior")||me("persistDraft")||me("showToolFileIcons")||me("expandedTools")||!f&&me("inputSpellcheck"),$n=me("chatRenderMode")||me("activityRenderMode")&&_==="sorted",Bn=me("messageTransport"),Ra=me("userMessageRendering")||me("mermaidRendering")||me("diffLayout")&&!rs||me("followUpBehavior"),x=me("sessionAssist")||me("sessionGoal")&&!rs||me("subagentReadOnlyBanner")||me("collapsibleUserMessages")||me("stickyUserHeader")||me("promptNavigatorEnabled")&&!rs||me("wideChatLayout")||me("codeBlockLineWrap")||me("splitAssistantMessageActions")||me("dotfiles")||me("fileViewerPreview")||me("persistDraft")||me("showToolFileIcons")||me("showTurnChangedFiles")||!f&&me("inputSpellcheck")||me("reasoning")||me("expandedTools"),se=Ta||Da||Ma,De=me("pwaInstallName")&&wn()&&y&&!cs()&&!rs,Xe=me("pwaOrientation")&&wn()&&!cs()&&!rs,Ft=me("mobileKeyboardMode")&&wn()&&!cs()&&!rs&&Hc(),ws=(me("terminalShell")||me("terminalLoginShell"))&&!rs,[ts,Ds]=o.useState([]),[Xs,Rs]=o.useState(0);o.useEffect(()=>Ho(()=>{Ds([]),Rs(d=>d+1)}),[]),o.useEffect(()=>{let d=!1;if(!(!ws||!c.listShells))return c.listShells().then(jt=>{d||Ds(jt)}).catch(()=>{d||Ds([])}),()=>{d=!0}},[ws,c,Xs]);const na=o.useMemo(()=>{const d=ts.filter(jt=>jt.id!=="auto");return ue==="auto"||d.some(jt=>jt.id===ue)?d:[{id:ue,name:ue,supportsLogin:!1},...d]},[ts,ue]),Cn=ts.find(d=>d.id===ue)?.supportsLogin===!0,aa=Ce.includes(ue),Tt=d=>{ke(d?[...Ce.filter(jt=>jt!==ue),ue]:Ce.filter(jt=>jt!==ue))},[Xt,Pn]=o.useState(()=>hd()),[Lt,os]=o.useState(""),[Us,Os]=o.useState("system"),Oa=o.useMemo(()=>{const d=jo.find(jt=>jt.id===ot);return l(d?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[ot,l]),Pl=o.useMemo(()=>{const d=wo.find(jt=>jt.id===ut);return l(d?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[ut,l]),Il=o.useMemo(()=>{const d=bo.find(jt=>jt.id===Us);return d?l(d.labelKey):void 0},[Us,l]),Al=o.useMemo(()=>{const d=vo.find(jt=>jt.id===Ge);return d?l(d.labelKey):void 0},[Ge,l]),El=o.useCallback(d=>{d!==Xt&&(Pn(d),fd(d),window.location.reload())},[Xt]),mi=o.useCallback(async d=>{if(typeof window>"u")return;const jt=window,us=d.trim().replace(/\s+/g," ").slice(0,64);if(await vt({pwaAppName:us}),typeof jt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const en=jt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(us);os(en);return}os(us||ua),jt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),or=o.useCallback(async d=>{if(typeof window>"u")return;const jt=window,xs=Ei(d);if(await vt({pwaOrientation:xs}),typeof jt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const us=jt.__OPENCHAMBER_SET_PWA_ORIENTATION__(xs);Os(us);return}Os(xs),jt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!De&&!Xe&&!Ft)return;let d=!1;return(async()=>{try{const xs=await lt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!xs.ok){d||os(ua);return}const us=await xs.json().catch(()=>({})),In=(typeof us?.pwaAppName=="string"?us.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),La=Ei(us?.pwaOrientation),ui=Ar(us?.mobileKeyboardMode);d||(De&&os(In||ua),Xe&&Os(La),Ft&&qe(ui))}catch{d||(De&&os(ua),Xe&&Os("system"),Ft&&qe("native"))}})(),()=>{d=!0}},[qe,Ft,De,Xe]),s.jsxs("div",{className:"space-y-0",children:[Ta&&s.jsxs("div",{className:"space-y-0",children:[Sn&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(xn,{children:[s.jsxs("div",{className:bn,children:[s.jsx(hn,{"aria-label":r("settings.openchamber.visual.section.colorMode"),children:Cg.map(d=>s.jsx(fn,{selected:ct===d.value,onSelect:()=>at(d.value),label:l(d.labelKey),ariaLabel:l(d.labelKey)},d.value))}),Ea&&s.jsx(Qn,{children:s.jsx(Qt,{label:r("settings.openchamber.visual.section.mobileLayout"),children:s.jsx(Fs,{value:Xt,options:Ag.map(d=>({value:d.value,label:l(d.labelKey)})),onChange:El,"aria-label":r("settings.openchamber.visual.section.mobileLayout")})})})]}),s.jsxs("div",{className:bn,children:[s.jsx(Qt,{label:r("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(Mt,{value:sa?.metadata.id??"",onValueChange:Nt,children:[s.jsx(Rt,{"aria-label":r("settings.openchamber.visual.field.selectLightThemeAria"),size:Ut,className:sn,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:sa?Zs(sa.metadata.name,"light"):void 0})}),s.jsx(Ot,{children:Qs.map(d=>s.jsx(dt,{value:d.metadata.id,children:Zs(d.metadata.name,"light")},d.metadata.id))})]})}),s.jsx(Qt,{label:r("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(Mt,{value:Vn?.metadata.id??"",onValueChange:Pt,children:[s.jsx(Rt,{"aria-label":r("settings.openchamber.visual.field.selectDarkThemeAria"),size:Ut,className:sn,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:Vn?Zs(Vn.metadata.name,"dark"):void 0})}),s.jsx(Ot,{children:Ys.map(d=>s.jsx(dt,{value:d.metadata.id,children:Zs(d.metadata.name,"dark")},d.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:ss||Et,onClick:()=>{const d=Date.now();yt(!0),es().finally(()=>{const jt=Date.now()-d;if(jt<500){window.setTimeout(()=>{yt(!1)},500-jt);return}yt(!1)})},className:"typography-settings-link inline-flex items-center gap-1.5 disabled:cursor-not-allowed disabled:opacity-50 disabled:no-underline",children:[s.jsx(z,{name:"restart",className:ye("h-3.5 w-3.5",Et&&"animate-spin")}),r(Et?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Yt,{children:r("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),zt&&s.jsx(Qn,{settingsItem:"appearance.dock-badge",children:s.jsx(gt,{checked:Zt,onChange:js,label:r("settings.openchamber.visual.field.dockBadge"),info:r("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:r("settings.openchamber.visual.field.dockBadge")})})]}),Ia&&s.jsx(Le,{title:r("settings.openchamber.desktopNetwork.field.windowControls"),info:r("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:Sn,children:s.jsxs(xn,{children:[s.jsx(Qt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Fs,{value:ht,options:Og.map(d=>({value:d.id,label:l(d.labelKey)})),onChange:Kn,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Qt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Fs,{value:nt,options:Lg.map(d=>({value:d.id,label:l(d.labelKey)})),onChange:zn,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),Aa&&s.jsx(Le,{title:r("settings.openchamber.visual.section.localization"),children:s.jsxs(xn,{children:[s.jsx(Qt,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Mt,{value:e,onValueChange:d=>n(d),children:[s.jsx(Rt,{"aria-label":r("settings.appearance.language.select"),size:Ut,className:sn,children:s.jsx(_t,{children:i(e)})}),s.jsx(Ot,{children:a.map(d=>s.jsx(dt,{value:d,children:i(d)},d))})]})}),(me("timeFormat")||me("weekStart"))&&s.jsxs("div",{className:bn,children:[me("timeFormat")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Mt,{value:ot,onValueChange:d=>ms(d),children:[s.jsx(Rt,{"aria-label":r("settings.openchamber.visual.field.selectTimeFormatAria"),size:Ut,className:sn,children:s.jsx(_t,{children:Oa})}),s.jsx(Ot,{children:jo.map(d=>s.jsx(dt,{value:d.id,children:l(d.labelKey)},d.id))})]})}),me("weekStart")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Mt,{value:ut,onValueChange:d=>di(d),children:[s.jsx(Rt,{"aria-label":r("settings.openchamber.visual.field.selectWeekStartAria"),size:Ut,className:sn,children:s.jsx(_t,{children:Pl})}),s.jsx(Ot,{children:wo.map(d=>s.jsx(dt,{value:d.id,children:l(d.labelKey)},d.id))})]})})]})]})}),(De||Xe||Ft)&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.appInstall"),contentClassName:bn,children:[De&&s.jsxs(qt,{label:r("settings.openchamber.visual.field.installAppName"),info:r("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Ts,children:[s.jsx(He,{value:Lt,onChange:d=>{os(d.target.value)},onBlur:()=>{mi(Lt)},onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),mi(Lt))},className:"min-w-0 flex-1",maxLength:64,"aria-label":r("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{os(ua),mi("")},className:gs,"aria-label":r("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),Xe&&s.jsxs(qt,{label:r("settings.openchamber.visual.field.installOrientation"),description:r("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Ts,children:[s.jsxs(Mt,{value:Us,onValueChange:d=>{const jt=Ei(d);Os(jt),or(jt)},children:[s.jsx(Rt,{"aria-label":r("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Ut,className:gr,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Il})}),s.jsx(Ot,{children:bo.map(d=>s.jsx(dt,{value:d.id,children:l(d.labelKey)},d.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Os("system"),or("system")},disabled:Us==="system",className:gs,"aria-label":r("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),Ft&&s.jsxs(qt,{label:r("settings.openchamber.visual.field.mobileKeyboardMode"),info:r("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Ts,children:[s.jsxs(Mt,{value:Ge,onValueChange:d=>{const jt=Ar(d);qe(jt),vt({mobileKeyboardMode:jt})},children:[s.jsx(Rt,{"aria-label":r("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Ut,className:gr,children:s.jsx(_t,{placeholder:r("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Al})}),s.jsx(Ot,{children:vo.map(d=>s.jsx(dt,{value:d.id,children:l(d.labelKey)},d.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{qe("native"),vt({mobileKeyboardMode:"native"})},disabled:Ge==="native",className:gs,"aria-label":r("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),Da&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.densityAndType"),contentClassName:bn,children:[me("fontSize")&&!f||me("terminalFontSize")?s.jsxs(xn,{children:[me("fontSize")&&!f&&s.jsxs(Qt,{label:r("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Mt,{value:Ae,onValueChange:d=>he(d),children:[s.jsx(Rt,{"aria-label":r("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Ut,className:sn,children:s.jsx(_t,{children:Sr.find(d=>d.id===Ae)?.label})}),s.jsx(Ot,{children:Sr.map(d=>s.jsx(dt,{value:d.id,children:s.jsx("span",{style:{fontFamily:d.stack},children:d.label})},d.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>he(Cr),disabled:Ae===Cr,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]}),me("terminalFontSize")&&s.jsxs(Qt,{label:r("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Mt,{value:ge,onValueChange:d=>Ee(d),children:[s.jsx(Rt,{"aria-label":r("settings.openchamber.visual.field.selectCodeFontAria"),size:Ut,className:sn,children:s.jsx(_t,{children:Pr.find(d=>d.id===ge)?.label})}),s.jsx(Ot,{children:Pr.map(d=>s.jsx(dt,{value:d.id,children:s.jsx("span",{style:{fontFamily:d.stack},children:d.label})},d.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ee(Ir),disabled:ge===Ir,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,me("fontSize")&&!f||me("terminalFontSize")||me("editorFontSize")?s.jsxs(xn,{children:[me("fontSize")&&!f&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ys,{value:le,onValueChange:be,min:50,max:200,step:5,"aria-label":r("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:oa,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>be(100),disabled:le===100,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),me("terminalFontSize")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ys,{value:Ne,onValueChange:de,min:9,max:52,step:1}),s.jsx("span",{className:oa,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>de(13),disabled:Ne===13,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),me("editorFontSize")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ys,{value:fe,onValueChange:ze,min:9,max:32,step:1}),s.jsx("span",{className:oa,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>ze(13),disabled:fe===13,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,me("spacing")||me("inputBarOffset")&&f?s.jsxs(xn,{children:[me("spacing")&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ys,{value:Te,onValueChange:Qe,min:50,max:200,step:5}),s.jsx("span",{className:oa,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Qe(100),disabled:Te===100,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})}),me("inputBarOffset")&&f&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.inputBarOffset"),info:r("settings.openchamber.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:ra,children:[s.jsx(ys,{value:Be,onValueChange:Ke,min:0,max:100,step:5}),s.jsx("span",{className:oa,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ke(0),disabled:Be===0,className:gs,"aria-label":r("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null]}),Ma&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[me("fileEditorKeymap")&&s.jsx(Ls,{title:r("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(hn,{"aria-label":r("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(d=>s.jsx(fn,{selected:je===d,onSelect:()=>U(d),label:r(`settings.openchamber.visual.option.fileEditorKeymap.${d}`),ariaLabel:r(`settings.openchamber.visual.option.fileEditorKeymap.${d}`)},d))})}),s.jsxs("div",{className:bs,children:[me("autoSaveEnabled")&&s.jsx(gt,{checked:X,onChange:ee,label:r("settings.openchamber.visual.field.autoSaveEnabled"),ariaLabel:r("settings.openchamber.visual.field.autoSaveEnabledAria"),info:r("settings.openchamber.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),me("expandedEditorToolbar")&&!rs&&s.jsx(gt,{checked:Q,onChange:ai,label:r("settings.openchamber.visual.field.expandedEditorToolbar"),ariaLabel:r("settings.openchamber.visual.field.expandedEditorToolbarAria"),settingsItem:"appearance.expanded-editor-toolbar"}),me("terminalQuickKeys")&&!f&&s.jsx(gt,{checked:$e,onChange:Ue,label:r("settings.openchamber.visual.field.terminalQuickKeys"),ariaLabel:r("settings.openchamber.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:r("settings.openchamber.visual.field.terminalQuickKeysTooltip")}),ws&&s.jsx(Qt,{label:r("settings.openchamber.visual.field.terminalShell"),info:r("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Mt,{value:ue,onValueChange:d=>{Gc(d)&&Me(d)},children:[s.jsx(Rt,{"aria-label":r("settings.openchamber.visual.field.terminalShellAria"),size:Ut,className:sn,children:s.jsx(_t,{})}),s.jsxs(Ot,{children:[s.jsx(dt,{value:"auto",children:r("settings.openchamber.visual.option.terminalShell.auto")}),na.map(d=>s.jsx(dt,{value:d.id,children:d.name},d.id))]})]})}),ws&&Cn&&s.jsx(gt,{checked:aa,onChange:Tt,label:r("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:r("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"})]})]}),pi&&s.jsxs(s.Fragment,{children:[$n&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.chatDisplay"),divider:se,contentClassName:"space-y-6",children:[me("chatRenderMode")&&s.jsx(Ls,{title:r("settings.openchamber.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":r("settings.openchamber.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:Tg.map(d=>{const jt=_===d.id,xs=It%12;return s.jsxs("button",{type:"button",onClick:()=>zs(d.id),"aria-pressed":jt,className:ye("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",jt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ye("typography-ui-label",jt?"text-foreground":"text-muted-foreground"),children:l(d.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:d.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(us=>{const en=us*3+1,In=xs-en+1,La=In<=0?0:In===1?42:In===2?68:92,ui=La>0;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",ui?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${La}%`}})]},us)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(us=>{const en=xs>=(us+1)*3;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",en?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},us)})})})]},d.id)})})}),me("activityRenderMode")&&_==="sorted"&&s.jsx(Ls,{title:r("settings.openchamber.visual.section.activityDefault"),children:s.jsx(hn,{"aria-label":r("settings.openchamber.visual.section.activityDefaultAria"),children:Dg.map(d=>s.jsx(fn,{selected:te===d.id,onSelect:()=>Js(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(d.labelKey)})},d.id))})})]}),Bn&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.messageStreamTransport"),divider:$n||se,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Fs,{value:xe,options:yo.map(d=>({value:d.id,label:l(d.labelKey)})),onChange:Un,"aria-label":r("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const d=yo.find(jt=>jt.id===xe);return d?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(d.descriptionKey)}):null})()]}),Ra&&s.jsx(Le,{title:r("settings.openchamber.visual.section.chatMessageOptions"),divider:$n||Bn||se,children:s.jsxs(xn,{className:"lg:gap-y-6",children:[me("userMessageRendering")&&s.jsx(Ls,{title:r("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(hn,{"aria-label":r("settings.openchamber.visual.section.userMessageRenderingAria"),children:Eg.map(d=>s.jsx(fn,{selected:Rg(A)===d.id,onSelect:()=>ta(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(d.labelKey)})},d.id))})}),me("mermaidRendering")&&s.jsx(Ls,{title:r("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(hn,{"aria-label":r("settings.openchamber.visual.section.mermaidRenderingAria"),children:Ig.map(d=>s.jsx(fn,{selected:L===d.id,onSelect:()=>cn(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(d.labelKey)})},d.id))})}),me("diffLayout")&&!rs&&s.jsx(Ls,{title:r("settings.openchamber.visual.section.diffLayout"),children:s.jsx(hn,{"aria-label":r("settings.openchamber.visual.section.diffLayoutAria"),children:Pg.map(d=>s.jsx(fn,{selected:Ie===d.id,onSelect:()=>Re(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.diffLayoutAria",{option:l(d.labelKey)})},d.id))})}),me("followUpBehavior")&&s.jsx(Ls,{title:r("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(hn,{"aria-label":r("settings.openchamber.visual.section.followUpBehaviorAria"),children:Mg.map(d=>s.jsx(fn,{selected:re===d.id,onSelect:()=>pe(d.id),label:l(d.labelKey),ariaLabel:r("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(d.labelKey)})},d.id))})})]})}),x&&s.jsxs(s.Fragment,{children:[me("expandedTools")&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:$n||Bn||Ra||se,contentClassName:bs,children:[s.jsx(gt,{checked:et,onChange:_n,label:r("settings.openchamber.visual.field.bash"),ariaLabel:r("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(gt,{checked:pt,onChange:ci,label:r("settings.openchamber.visual.field.editTools"),ariaLabel:r("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(Le,{title:r("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:bs,children:[s.jsx(gt,{checked:kt,onChange:ni,label:r("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:r("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),me("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:p,onChange:S,label:r("settings.openchamber.visual.field.sessionRecap"),ariaLabel:r("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(gt,{checked:F,onChange:N,label:r("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:r("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),me("subagentReadOnlyBanner")&&s.jsx(gt,{checked:Ve,onChange:We,label:r("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),me("sessionGoal")&&!rs&&s.jsxs(Le,{title:r("settings.openchamber.visual.goal.sectionTitle"),info:r("settings.openchamber.visual.goal.description"),contentClassName:bs,children:[s.jsx(gt,{checked:h,onChange:I,label:r("settings.openchamber.visual.field.sessionGoal"),ariaLabel:r("settings.openchamber.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(gt,{checked:u,onChange:D,disabled:!h,label:r("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:r("settings.openchamber.visual.goal.budgetAria")}),h&&u?s.jsx(ys,{value:q,onValueChange:d=>{typeof d=="number"&&Number.isFinite(d)&&d>0&&M(Math.floor(d))},min:1e3,max:1e8,step:5e4}):null]})]}),me("reasoning")&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:bs,children:[s.jsx(gt,{checked:v,onChange:P,label:r("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:r("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),v&&s.jsx(gt,{checked:g,onChange:j,label:r("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),(me("collapsibleUserMessages")||me("stickyUserHeader")||me("promptNavigatorEnabled")&&!rs||me("wideChatLayout")||me("splitAssistantMessageActions")||me("codeBlockLineWrap"))&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:bs,children:[me("collapsibleUserMessages")&&s.jsx(gt,{checked:K,onChange:ii,label:r("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),me("stickyUserHeader")&&s.jsx(gt,{checked:k,onChange:si,label:r("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:r("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),me("promptNavigatorEnabled")&&!rs&&s.jsx(gt,{checked:W,onChange:Pa,label:r("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),me("wideChatLayout")&&s.jsx(gt,{checked:T,onChange:ri,label:r("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:r("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),me("splitAssistantMessageActions")&&s.jsx(gt,{checked:ie,onChange:oi,label:r("settings.openchamber.visual.field.showSplitAssistantMessageActions"),ariaLabel:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:r("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")}),me("codeBlockLineWrap")&&s.jsx(gt,{checked:V,onChange:E,label:r("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(me("showToolFileIcons")||me("showTurnChangedFiles")||me("dotfiles")&&!ps()||me("fileViewerPreview"))&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:bs,children:[me("showToolFileIcons")&&s.jsx(gt,{checked:G,onChange:rr,label:r("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:r("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),me("showTurnChangedFiles")&&s.jsx(gt,{checked:Ye,onChange:dn,label:r("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),me("dotfiles")&&!ps()&&s.jsx(gt,{checked:m,onChange:qc,label:r("settings.openchamber.visual.field.showDotfiles"),ariaLabel:r("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),me("fileViewerPreview")&&s.jsx(gt,{checked:Oe,onChange:li,label:r("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:r("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(me("persistDraft")||!f&&me("inputSpellcheck"))&&s.jsxs(Le,{title:r("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:bs,children:[me("persistDraft")&&s.jsx(gt,{checked:ve,onChange:ae,label:r("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:r("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!f&&me("inputSpellcheck")&&s.jsx(gt,{checked:_e,onChange:As,label:r("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]})]})]}),me("reportUsage")&&s.jsx(Le,{title:r("settings.openchamber.visual.section.privacy"),children:s.jsx(gt,{checked:hs,onChange:fs,label:r("settings.openchamber.visual.field.sendAnonymousUsageReports"),info:r("settings.openchamber.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:r("settings.openchamber.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},Fg=1,Kg=365,ko=30,zg=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],fl=()=>{const t=ft.c(87),{t:e}=it(),a=ce(Ug),n=ce(_g),i=ce(Vg),r=ce($g),l=ce(Bg),f=ce(Hg);let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c={autoRun:!1},t[0]=c):c=t[0];const{candidates:y,isRunning:m,runCleanup:v,action:p}=mc(c),F=y.length;let S;t[1]!==v||t[2]!==e?(S=async()=>{const ne=await v({force:!0});if(ne.completedIds.length===0&&ne.failedIds.length===0){R.message(ne.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}ne.completedIds.length>0&&R.success(ne.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:ne.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:ne.completedIds.length})),ne.failedIds.length>0&&R.error(ne.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:ne.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:ne.failedIds.length}))},t[1]=v,t[2]=e,t[3]=S):S=t[3];const N=S;let h;t[4]!==e?(h=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=h):h=t[5];let I;t[6]!==e?(I=e("settings.openchamber.sessionRetention.tooltip"),t[6]=e,t[7]=I):I=t[7];let u;t[8]!==e?(u=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=u):u=t[9];let D;t[10]!==e?(D=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=D):D=t[11];let q;t[12]!==a||t[13]!==r||t[14]!==u||t[15]!==D?(q=s.jsx(gt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:u,ariaLabel:D}),t[12]=a,t[13]=r,t[14]=u,t[15]=D,t[16]=q):q=t[16];let M;t[17]!==e?(M=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[17]=e,t[18]=M):M=t[18];let P;t[19]!==e?(P=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[19]=e,t[20]=P):P=t[20];let g;t[21]!==n||t[22]!==l||t[23]!==P?(g=s.jsx(ys,{value:n,onValueChange:l,min:Fg,max:Kg,step:1,"aria-label":P,className:"w-20 tabular-nums"}),t[21]=n,t[22]=l,t[23]=P,t[24]=g):g=t[24];let j;t[25]!==e?(j=e("settings.openchamber.sessionRetention.field.days"),t[25]=e,t[26]=j):j=t[26];let L;t[27]!==j?(L=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:j}),t[27]=j,t[28]=L):L=t[28];let C;t[29]!==l?(C=()=>l(ko),t[29]=l,t[30]=C):C=t[30];const A=n===ko;let b;t[31]!==e?(b=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[31]=e,t[32]=b):b=t[32];let K;t[33]!==e?(K=e("settings.common.actions.reset"),t[33]=e,t[34]=K):K=t[34];let $;t[35]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(z,{name:"restart",className:"h-3.5 w-3.5"}),t[35]=$):$=t[35];let k;t[36]!==C||t[37]!==A||t[38]!==b||t[39]!==K?(k=s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:C,disabled:A,className:gs,"aria-label":b,title:K,children:$}),t[36]=C,t[37]=A,t[38]=b,t[39]=K,t[40]=k):k=t[40];let W;t[41]!==L||t[42]!==k||t[43]!==M||t[44]!==g?(W=s.jsxs(qt,{settingsItem:"sessions.retention-period",label:M,children:[g,L,k]}),t[41]=L,t[42]=k,t[43]=M,t[44]=g,t[45]=W):W=t[45];let Z;t[46]!==e?(Z=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[46]=e,t[47]=Z):Z=t[47];let B;t[48]!==e?(B=zg.map(ne=>({value:ne.value,label:e(ne.labelKey)})),t[48]=e,t[49]=B):B=t[49];let Q;t[50]!==i||t[51]!==f||t[52]!==B?(Q=s.jsx(Fs,{value:i,onChange:f,options:B}),t[50]=i,t[51]=f,t[52]=B,t[53]=Q):Q=t[53];let w;t[54]!==Z||t[55]!==Q?(w=s.jsx(qt,{settingsItem:"sessions.retention-action",label:Z,children:Q}),t[54]=Z,t[55]=Q,t[56]=w):w=t[56];let X;t[57]!==W||t[58]!==w?(X=s.jsxs(Qn,{className:"space-y-0",children:[W,w]}),t[57]=W,t[58]=w,t[59]=X):X=t[59];let ee;t[60]!==e?(ee=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[60]=e,t[61]=ee):ee=t[61];let T;t[62]!==m||t[63]!==e?(T=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[62]=m,t[63]=e,t[64]=T):T=t[64];let O;t[65]!==N||t[66]!==m||t[67]!==T?(O=s.jsx(H,{type:"button",variant:"outline",size:"xs",onClick:N,disabled:m,className:"!font-normal",children:T}),t[65]=N,t[66]=m,t[67]=T,t[68]=O):O=t[68];let V;t[69]!==ee||t[70]!==O?(V=s.jsx(qt,{label:ee,children:O}),t[69]=ee,t[70]=O,t[71]=V):V=t[71];let E;t[72]!==p||t[73]!==F||t[74]!==e?(E=p==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:F}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:F}),t[72]=p,t[73]=F,t[74]=e,t[75]=E):E=t[75];let _;t[76]!==E?(_=s.jsx("p",{className:"typography-meta text-muted-foreground",children:E}),t[76]=E,t[77]=_):_=t[77];let J;t[78]!==V||t[79]!==_?(J=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[V,_]}),t[78]=V,t[79]=_,t[80]=J):J=t[80];let te;return t[81]!==h||t[82]!==X||t[83]!==I||t[84]!==J||t[85]!==q?(te=s.jsxs(Le,{title:h,info:I,children:[q,X,J]}),t[81]=h,t[82]=X,t[83]=I,t[84]=J,t[85]=q,t[86]=te):te=t[86],te};function Ug(t){return t.autoDeleteEnabled}function _g(t){return t.autoDeleteAfterDays}function Vg(t){return t.sessionRetentionAction}function $g(t){return t.setAutoDeleteEnabled}function Bg(t){return t.setAutoDeleteAfterDays}function Hg(t){return t.setSessionRetentionAction}const No=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(zo(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),xl=()=>{const{t}=it(),e=ce(g=>g.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,f]=o.useState(!1),[c,y]=o.useState(null),[m,v]=o.useState(!1),[p,F]=o.useState([]),[S,N]=o.useState(uc),[h,I]=o.useState(""),u=o.useMemo(()=>gc(),[]),D=o.useCallback(async()=>{r(!0),I("");try{const g=await hc();F(g)}catch(g){const j=g instanceof Error?g.message:t("settings.openchamber.passkeys.toast.loadFailed");I(j)}finally{r(!1)}},[t]);o.useEffect(()=>{let g=!1;return(async()=>{try{if(!u.supported){g||(n(!1),r(!1));return}g||n(!0)}catch{g||n(!1)}if(!g){const j=await hi();if(N(j),!j.enabled){F([]),r(!1);return}await D()}})(),()=>{g=!0,hr()}},[D,u.supported]);const q=o.useCallback(async()=>{if(!S.enabled){const g=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");I(g),R.message(g);return}if(!a){I(u.reason),R.message(u.reason);return}if(l){hr(),f(!1);return}I(""),f(!0);try{await fc(),N(await hi()),await D(),R.success(t("settings.openchamber.passkeys.toast.added"))}catch(g){if(xc(g)){R.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const j=g instanceof Error?g.message:t("settings.openchamber.passkeys.toast.addFailed");I(j),R.error(j)}finally{f(!1)}},[l,D,S.enabled,u.reason,a,t]),M=o.useCallback(async g=>{y(g),I("");try{await bc(g),N(await hi()),await D(),R.success(t("settings.openchamber.passkeys.toast.removed"))}catch(j){const L=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.removeFailed");I(L),R.error(L)}finally{y(null)}},[D,t]),P=o.useCallback(async()=>{v(!0),I("");try{await vc(),window.location.reload()}catch(g){const j=g instanceof Error?g.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");I(j),R.error(j),v(!1)}},[t]);return s.jsxs(Le,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(qt,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(H,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{q()},disabled:i||m,className:"!font-normal",children:t(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{P()},disabled:i||l||m,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(m?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!S.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),S.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:u.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):p.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:p.map(g=>s.jsxs(qt,{label:s.jsx("span",{className:"truncate",children:g.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:g.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:No(g.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:No(g.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{M(g.id)},disabled:c===g.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===g.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},g.id))})]}),h&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:h})})]})},Ti=t=>{const e=Jn(t);return e||{providerId:"",modelId:""}},bl=()=>{const{t}=it(),e=tt(E=>E.setProvider),a=tt(E=>E.setModel),n=tt(E=>E.setAgent),i=tt(E=>E.setCurrentVariant),r=tt(E=>E.setSettingsDefaultModel),l=tt(E=>E.setSettingsDefaultVariant),f=tt(E=>E.setSettingsDefaultAgent),c=ce(E=>E.showDeletionDialog),y=ce(E=>E.setShowDeletionDialog),m=tt(E=>E.providers),v=tt(E=>E.modelsMetadata),[p,F]=o.useState(),[S,N]=o.useState(),[h,I]=o.useState(),[u,D]=o.useState(!0),[q,M]=o.useState(),[P,g]=o.useState([]),[j,L]=o.useState(),[C,A]=o.useState(!0),b=o.useMemo(()=>Ti(p),[p]);o.useEffect(()=>{(async()=>{try{let _=null;if(!_){const J=kn()?.settings;if(J)try{const ne=(await J.load())?.settings;if(ne){const le=ne;_={defaultModel:typeof ne.defaultModel=="string"?ne.defaultModel:void 0,defaultVariant:typeof le.defaultVariant=="string"?le.defaultVariant:void 0,defaultAgent:typeof ne.defaultAgent=="string"?ne.defaultAgent:void 0,smallModelUseDefault:typeof le.smallModelUseDefault=="boolean"?le.smallModelUseDefault:void 0,smallModelOverride:typeof le.smallModelOverride=="string"?le.smallModelOverride:void 0,walkthroughModelOverride:typeof le.walkthroughModelOverride=="string"?le.walkthroughModelOverride:void 0}}}catch{}}if(!_){const J=await lt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});J.ok&&(_=await J.json())}if(_){const J=typeof _.defaultModel=="string"&&_.defaultModel.trim().length>0?_.defaultModel.trim():void 0,te=typeof _.defaultVariant=="string"&&_.defaultVariant.trim().length>0?_.defaultVariant.trim():void 0,ne=typeof _.defaultAgent=="string"&&_.defaultAgent.trim().length>0?_.defaultAgent.trim():void 0;J!==void 0&&F(J),te!==void 0&&N(te),ne!==void 0&&I(ne),typeof _.smallModelUseDefault=="boolean"&&D(_.smallModelUseDefault),typeof _.smallModelOverride=="string"&&_.smallModelOverride.trim()&&M(_.smallModelOverride.trim()),typeof _.walkthroughModelOverride=="string"&&_.walkthroughModelOverride.trim()&&L(_.walkthroughModelOverride.trim())}}catch(_){console.warn("Failed to load defaults settings:",_)}finally{A(!1)}})()},[]);const K=o.useCallback(async(E,_)=>{const J=E&&_?`${E}/${_}`:void 0;F(J),N(void 0),l(void 0),i(void 0),r(J),E&&_&&m.find(ne=>ne.id===E)&&(e(E),a(_));try{await vt({defaultModel:J??"",defaultVariant:""});const te=await lt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:J})});te.ok||console.warn("Failed to save default model to server:",te.status,te.statusText)}catch(te){console.warn("Failed to save default model:",te)}},[m,i,a,e,r,l]),$="__default__",k=o.useCallback(E=>E===$?t("settings.openchamber.defaults.option.default"):E.charAt(0).toUpperCase()+E.slice(1),[t]),W=o.useCallback(async E=>{const _=E===$?void 0:E||void 0;N(_),l(_),i(_);try{await vt({defaultVariant:_??""})}catch(J){console.warn("Failed to save default variant:",J)}},[i,l]),Z=o.useCallback(async E=>{const _=E||void 0;I(_),f(_),E&&n(E);try{await vt({defaultAgent:_??""})}catch(J){console.warn("Failed to save default agent:",J)}},[n,f]),B=o.useCallback(async E=>{D(E);try{await vt({smallModelUseDefault:E})}catch(_){console.warn("Failed to save small model preference:",_)}},[]),Q=o.useCallback(async(E,_)=>{const J=E&&_?`${E}/${_}`:void 0;M(J);try{await vt({smallModelOverride:J??""})}catch(te){console.warn("Failed to save small model override:",te)}},[]),w=o.useCallback(async(E,_)=>{const J=E&&_?`${E}/${_}`:void 0;L(J);try{await vt({walkthroughModelOverride:J??""})}catch(te){console.warn("Failed to save walkthrough model override:",te)}},[]),X=o.useCallback((E,_)=>v.get(`${E}/${_}`)?.structured_output!==!1,[v]),ee=o.useMemo(()=>Ti(q),[q]),T=o.useMemo(()=>Ti(j),[j]);o.useEffect(()=>{let E=!1;return(async()=>{try{const _=await lt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!_.ok)return;const J=await _.json().catch(()=>null);!E&&Array.isArray(J?.authenticatedProviders)&&g(J.authenticatedProviders.filter(te=>typeof te=="string"))}catch{}})(),()=>{E=!0}},[]);const O=o.useMemo(()=>{if(!b.providerId||!b.modelId)return[];const J=m.find(te=>te.id===b.providerId)?.models.find(te=>te.id===b.modelId)?.variants;return J?Object.keys(J):[]},[b.modelId,b.providerId,m]),V=O.length>0;return o.useEffect(()=>{!V&&S&&(N(void 0),l(void 0),i(void 0),vt({defaultVariant:""}).catch(()=>{}))},[S,i,l,V]),C?null:s.jsx(s.Fragment,{children:s.jsx(Le,{title:t("settings.openchamber.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",b.providerId?s.jsxs("span",{className:"text-foreground",children:[b.providerId,"/",b.modelId,V?` (${S??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),h&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:h})]})]}),s.jsxs("div",{children:[s.jsx(qt,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(ba,{providerId:b.providerId,modelId:b.modelId,onChange:K,className:vn})}),s.jsx(qt,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Mt,{value:S??$,onValueChange:W,disabled:!V,children:[s.jsx(Rt,{size:Ut,className:yn,children:s.jsx(_t,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:k(S??$)})}),s.jsxs(Ot,{children:[s.jsx(dt,{value:$,children:t("settings.openchamber.defaults.option.default")}),O.map(E=>s.jsx(dt,{value:E,children:k(E)},E))]})]})}),s.jsx(qt,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(Oo,{agentName:h||"",onChange:Z,className:vn})})]}),s.jsx(Qn,{className:bs,children:s.jsx(gt,{settingsItem:"sessions.deletion-dialog",checked:c,onChange:y,label:t("settings.openchamber.defaults.field.showDeletionDialog"),ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")})}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx($s,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Yt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(gt,{settingsItem:"sessions.small-model",checked:u,onChange:E=>{B(E)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),u?null:s.jsx(qt,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(ba,{providerId:ee.providerId,modelId:ee.modelId,onChange:Q,allowedProviderIds:P,className:vn})}),s.jsxs(Qn,{className:bs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx($s,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Yt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(qt,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(ba,{providerId:T.providerId,modelId:T.modelId,onChange:w,allowedProviderIds:P,isModelAllowed:X,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:vn})})]})]})]})})})},So={completion:{titleKey:"settings.notifications.page.template.defaults.completion.title",messageKey:"settings.notifications.page.template.defaults.completion.message"},error:{titleKey:"settings.notifications.page.template.defaults.error.title",messageKey:"settings.notifications.page.template.defaults.error.message"},question:{titleKey:"settings.notifications.page.template.defaults.question.title",messageKey:"settings.notifications.page.template.defaults.question.message"},subtask:{titleKey:"settings.notifications.page.template.defaults.subtask.title",messageKey:"settings.notifications.page.template.defaults.subtask.message"}},Gg={completion:"settings.notifications.page.template.event.completion",subtask:"settings.notifications.page.template.event.subtask",error:"settings.notifications.page.template.event.error",question:"settings.notifications.page.template.event.question"},qg=()=>{const{t}=it(),e=o.useMemo(()=>cs(),[]),a=o.useMemo(()=>ps(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=ce(T=>T.nativeNotificationsEnabled),l=ce(T=>T.setNativeNotificationsEnabled),f=ce(T=>T.notificationMode),c=ce(T=>T.setNotificationMode),y=ce(T=>T.notifyOnSubtasks),m=ce(T=>T.setNotifyOnSubtasks),v=ce(T=>T.notifyOnCompletion),p=ce(T=>T.setNotifyOnCompletion),F=ce(T=>T.notifyOnError),S=ce(T=>T.setNotifyOnError),N=ce(T=>T.notifyOnQuestion),h=ce(T=>T.setNotifyOnQuestion),I=ce(T=>T.notificationTemplates),u=ce(T=>T.setNotificationTemplates),[D,q]=o.useState("default"),[M,P]=o.useState(!1),[g,j]=o.useState(!1),[L,C]=o.useState(!1);o.useEffect(()=>{if(!i){P(!1),j(!1);return}typeof Notification<"u"&&q(Notification.permission);const T=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;P(T),(async()=>{if(!T){j(!1);return}try{const V=await navigator.serviceWorker.getRegistration();if(!V){j(!1);return}const E=await V.pushManager.getSubscription();j(!!E)}catch{j(!1)}})()},[i]);const A=async T=>{if(e){l(T);return}if(!i){l(T);return}if(T&&typeof Notification<"u"&&Notification.permission==="default")try{const O=await Notification.requestPermission();q(O),O==="granted"?l(!0):R.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(O){console.error("Failed to request notification permission:",O),R.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(T&&D==="granted"))},b=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",K=(T,O,V)=>{u(E=>({...E,[T]:{...E[T],[O]:V}}))},$=T=>{const O="=".repeat((4-T.length%4)%4),V=(T+O).replace(/-/g,"+").replace(/_/g,"/"),E=atob(V),_=new Uint8Array(E.length);for(let J=0;J<E.length;J+=1)_[J]=E.charCodeAt(J);return _},k=async(T,O,V)=>{let E=null;const _=new Promise((J,te)=>{E=setTimeout(()=>{te(new Error(V))},O)});try{return await Promise.race([T,_])}finally{E&&clearTimeout(E)}},W=async T=>{if(T.active)return;const O=T.installing||T.waiting;O&&O.state!=="activated"&&await k(new Promise(V=>{const E=()=>{O.state==="activated"&&(O.removeEventListener("statechange",E),V())};O.addEventListener("statechange",E),E()}),15e3,"Service worker activation timed out")},Z=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const T=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let O=null;for(const V of T)try{const E=V.opts?navigator.serviceWorker.register("/sw.js",V.opts):navigator.serviceWorker.register("/sw.js");return await k(E,1e4,`Service worker registration timed out (${V.label})`)}catch(E){O=E}throw O instanceof Error?O:new Error("Service worker registration failed")},B=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const T=await navigator.serviceWorker.getRegistration();if(T)return T;const O=await Z();try{await O.update()}catch{}return await W(O),O},Q=T=>{const O=T,V=[`type=${typeof T}`,`toString=${String(T)}`,`name=${String(O?.name??"")}`,`message=${String(O?.message??"")}`];let E="";try{E=JSON.stringify(T)}catch{}return{summary:V.filter(Boolean).join(" | "),json:E,stack:typeof O?.stack=="string"?O.stack:""}},w=async()=>{const T=kn();if(!T?.notifications){R.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await T.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?R.success(t("settings.notifications.page.toast.testNotificationSent")):R.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(O){console.error("Test notification failed:",O),R.error(t("settings.notifications.page.toast.testNotificationFailed"))}},X=async()=>{if(!M){R.error(t("settings.notifications.page.toast.pushUnsupported"));return}const T=kn();if(!T?.push){R.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}C(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const le=await Notification.requestPermission();if(q(le),le!=="granted"){R.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){R.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const O=await T.push.getVapidPublicKey();if(!O?.publicKey){R.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const V=await B();await W(V);const E=await V.pushManager.getSubscription();if(!("pushManager"in V)||!V.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const J=(E??await k(V.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:$(O.publicKey)}),15e3,"Push subscription timed out")).toJSON(),te=J.keys;if(!J.endpoint||!te?.p256dh||!te.auth)throw new Error("Push subscription missing keys");if(!(await k(T.push.subscribe({endpoint:J.endpoint,keys:{p256dh:te.p256dh,auth:te.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:Wc()}),15e3,"Push subscribe request timed out"))?.ok){R.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}j(!0),R.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(O){console.error("[Push] Enable failed:",O);const V=Q(O);R.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:V.summary})}finally{C(!1)}},ee=async()=>{if(!M){j(!1);return}const T=kn();if(!T?.push){R.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}C(!0);try{const V=await(await B()).pushManager.getSubscription();if(!V){j(!1);return}const E=V.endpoint;await V.unsubscribe(),await T.push.unsubscribe({endpoint:E}),j(!1),R.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{C(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(Le,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:bs,children:[s.jsx(gt,{checked:r&&b,onChange:T=>{A(T)},label:t("settings.notifications.page.delivery.enableLabel"),info:i?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),r&&b&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:f==="always",onChange:T=>c(T?"always":"hidden-only"),label:t("settings.notifications.page.delivery.focusedLabel"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("div",{className:"py-2",children:s.jsx(H,{type:"button",variant:"outline",size:"sm",onClick:()=>{w()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[D==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),D==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&b&&s.jsxs(s.Fragment,{children:[s.jsx(Le,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:bs,children:[s.jsx(gt,{checked:v,onChange:p,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(gt,{checked:y,onChange:m,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(gt,{checked:F,onChange:S,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(gt,{checked:N,onChange:h,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(Le,{title:t("settings.notifications.page.template.title"),description:s.jsxs(s.Fragment,{children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]}),children:s.jsx(xn,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(T=>s.jsxs("section",{className:"p-2",children:[s.jsx($s,{className:"capitalize",children:t(Gg[T])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(He,{value:I[T].title,onChange:O=>K(T,"title",O.target.value),className:"h-7",placeholder:t(So[T].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(He,{value:I[T].message,onChange:O=>K(T,"message",O.target.value),className:"h-7",placeholder:t(So[T].messageKey)})]})]})]},T))})})]}),i&&s.jsx(Le,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(gt,{checked:M?g:!1,disabled:!M||L,onChange:T=>{T?X():ee()},label:t("settings.notifications.page.push.enableLabel"),description:M?void 0:t("settings.notifications.page.push.unsupportedHint"),info:M?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:L?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},Ss=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Wg=[{id:"parakeet-tdt-0.6b-v2-int8",labelKey:"settings.voice.page.stt.model.parakeetV2",badgeKey:"settings.voice.page.stt.badge.bestForEnglish",accuracy:5,speed:5,size:"460 MB"},{id:"parakeet-tdt-0.6b-v3-int8",labelKey:"settings.voice.page.stt.model.parakeetV3",badgeKey:"settings.voice.page.stt.badge.bestForMultilingual",accuracy:5,speed:4,size:"465 MB"},{id:"whisper-base-int8",labelKey:"settings.voice.page.stt.model.whisperBase",badgeKey:null,accuracy:3,speed:3,size:"200 MB"},{id:"whisper-tiny-int8",labelKey:"settings.voice.page.stt.model.whisperTiny",badgeKey:null,accuracy:2,speed:4,size:"115 MB"}],Co=t=>{const e=ft.c(8),{value:a,label:n}=t,i=`${n}: ${a}/5`,r=`${a/5*100}%`;let l;e[0]!==r?(l=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:r}})}),e[0]=r,e[1]=l):l=e[1];let f;e[2]!==n?(f=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=f):f=e[3];let c;return e[4]!==i||e[5]!==l||e[6]!==f?(c=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,f]}),e[4]=i,e[5]=l,e[6]=f,e[7]=c):c=e[7],c},Jg=({selectedModelId:t,onSelect:e})=>{const{t:a}=it(),n=Je.useCallback(p=>a(p),[a]),[i,r]=Je.useState(new Map),[l,f]=Je.useState(null),c=Je.useCallback(async()=>{try{const p=await lt("/api/dictation/status",{query:{provider:"local"}});if(!p.ok)return;const F=await p.json();Array.isArray(F?.models)&&r(new Map(F.models.map(S=>[S.id,S])))}catch{}},[]);Je.useEffect(()=>{c()},[c]);const y=Array.from(i.values()).some(p=>p.downloading);Je.useEffect(()=>{if(!y)return;const p=setInterval(()=>{c()},2e3);return()=>clearInterval(p)},[y,c]);const m=async p=>{f(p);try{await lt(`/api/dictation/models/${encodeURIComponent(p)}/download`,{method:"POST"}),await c()}catch{}finally{f(null)}},v=async p=>{f(p);try{await lt(`/api/dictation/models/${encodeURIComponent(p)}`,{method:"DELETE"}),await c()}catch{}finally{f(null)}};return s.jsx("div",{role:"radiogroup","aria-label":a("settings.voice.page.field.model"),className:"mt-1.5 grid w-full grid-cols-1 gap-3 @xl:grid-cols-2",children:Wg.map(p=>{const F=t===p.id,S=i.get(p.id)??null;return s.jsx("div",{className:ye("rounded-lg border border-[var(--interactive-border)] p-3",F&&"border-[var(--primary-base)] bg-[var(--primary-base)]/5"),children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 cursor-pointer items-start gap-2",role:"button",tabIndex:0,onClick:()=>e(p.id),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),e(p.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(Yi,{checked:F,onChange:()=>e(p.id),ariaLabel:n(p.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:ye("typography-ui-label font-normal",F?"text-foreground":"text-foreground/50"),children:n(p.labelKey)}),p.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(p.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Co,{value:p.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(Co,{value:p.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:p.size})]}),S?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:S.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:S?.installed?s.jsxs(s.Fragment,{children:[s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===p.id,onClick:()=>{v(p.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(z,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):S?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof S.downloadProgress=="number"?`${S.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===p.id,onClick:()=>{m(p.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(z,{name:"download",className:"h-4 w-4"})})})]})},p.id)})})},Di=[{id:0,label:"Alloy (af)"},{id:1,label:"Bella (af)"},{id:2,label:"Nicole (af)"},{id:3,label:"Sarah (af)"},{id:4,label:"Sky (af)"},{id:5,label:"Adam (am)"},{id:6,label:"Michael (am)"},{id:7,label:"Emma (bf)"},{id:8,label:"Isabella (bf)"},{id:9,label:"George (bm)"},{id:10,label:"Lewis (bm)"}],Mi="kokoro-en-v0_19",Qg=()=>{const{t}=it(),[e,a]=Je.useState(null),[n,i]=Je.useState(!1),r=Je.useCallback(async()=>{try{const f=await lt("/api/dictation/status",{query:{provider:"local"}});if(!f.ok)return;const c=await f.json(),y=Array.isArray(c?.ttsModels)?c.ttsModels.find(m=>m.id===Mi):null;y&&a(y)}catch{}},[]);Je.useEffect(()=>{r()},[r]),Je.useEffect(()=>{if(!e?.downloading)return;const f=setInterval(()=>{r()},2e3);return()=>clearInterval(f)},[e?.downloading,r]);const l=async f=>{i(!0);try{const c=f==="POST"?`/api/dictation/models/${Mi}/download`:`/api/dictation/models/${Mi}`;await lt(c,{method:f}),await r()}catch{}finally{i(!1)}};return e?s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"Kokoro"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:"305 MB"}),e.installed?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":t("settings.voice.page.stt.modelInstalled")}),s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n,onClick:()=>{l("DELETE")},title:t("settings.voice.page.stt.modelDelete"),"aria-label":t("settings.voice.page.stt.modelDelete"),children:s.jsx(z,{name:"delete-bin",className:"h-4 w-4"})})]}):e.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(z,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof e.downloadProgress=="number"?`${e.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n,onClick:()=>{l("POST")},title:t("settings.voice.page.stt.modelDownload"),"aria-label":t("settings.voice.page.stt.modelDownload"),children:s.jsx(z,{name:"download",className:"h-4 w-4"})}),e.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:e.downloadError}):null]}):null},Yg=[{value:"alloy",label:"Alloy"},{value:"ash",label:"Ash"},{value:"ballad",label:"Ballad"},{value:"coral",label:"Coral"},{value:"echo",label:"Echo"},{value:"fable",label:"Fable"},{value:"nova",label:"Nova"},{value:"onyx",label:"Onyx"},{value:"sage",label:"Sage"},{value:"shimmer",label:"Shimmer"},{value:"verse",label:"Verse"},{value:"marin",label:"Marin"},{value:"cedar",label:"Cedar"}],Zg=()=>{const{t}=it(),{isMobile:e}=ea(),a=tt(G=>G.voiceProvider),n=tt(G=>G.setVoiceProvider),i=tt(G=>G.speechRate),r=tt(G=>G.setSpeechRate),l=tt(G=>G.speechPitch),f=tt(G=>G.setSpeechPitch),c=tt(G=>G.speechVolume),y=tt(G=>G.setSpeechVolume),m=tt(G=>G.sayVoice),v=tt(G=>G.setSayVoice),p=tt(G=>G.localTtsVoiceId),F=tt(G=>G.setLocalTtsVoiceId),{speak:S,stop:N,isPlaying:h,error:I}=yc(),u=Je.useCallback(()=>{if(h){N();return}const G=Di.find(Fe=>Fe.id===p)?.label??String(p);S(t("settings.voice.page.preview.voiceLine",{voiceName:G}),{speakerId:p,speed:tt.getState().speechRate})},[h,p,S,N,t]),D=tt(G=>G.browserVoice),q=tt(G=>G.setBrowserVoice),M=tt(G=>G.openaiVoice),P=tt(G=>G.setOpenaiVoice),g=tt(G=>G.openaiApiKey),j=tt(G=>G.setOpenaiApiKey),L=tt(G=>G.openaiCompatibleUrl),C=tt(G=>G.setOpenaiCompatibleUrl),A=tt(G=>G.openaiCompatibleApiKey),b=tt(G=>G.setOpenaiCompatibleApiKey),K=tt(G=>G.openaiCompatibleVoice),$=tt(G=>G.setOpenaiCompatibleVoice),k=tt(G=>G.openaiCompatibleTtsModel),W=tt(G=>G.setOpenaiCompatibleTtsModel),Z=tt(G=>G.showMessageTTSButtons),B=tt(G=>G.ttsInputMode),Q=tt(G=>G.setTtsInputMode),w=tt(G=>G.sttProvider),X=tt(G=>G.setSttProvider),ee=tt(G=>G.sttServerUrl),T=tt(G=>G.setSttServerUrl),O=tt(G=>G.sttApiKey),V=tt(G=>G.setSttApiKey),E=tt(G=>G.sttModel),_=tt(G=>G.setSttModel),J=tt(G=>G.sttLocalModel),te=tt(G=>G.setSttLocalModel),ne=tt(G=>G.sttLanguage),le=tt(G=>G.setSttLanguage),be=tt(G=>G.setShowMessageTTSButtons),Ne=tt(G=>G.dictationEnabled),de=tt(G=>G.setDictationEnabled),[ue,Me]=Je.useState(!1),[Ce,ke]=Je.useState([]),[fe,ze]=Je.useState(!1),[Ae,he]=Je.useState(null),[ge,Ee]=Je.useState(!1),[Te,Qe]=Je.useState(!1),[Be,Ke]=Je.useState(null),[Ge,qe]=Je.useState(!1),[Ie,Re]=Je.useState(null),[$e,Ue]=Je.useState([]),[je,U]=Je.useState(!1);Je.useEffect(()=>((async()=>{const Fe=await fi.waitForVoices();Ue(Fe)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ue(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const re=Je.useMemo(()=>$e.filter(G=>G.lang).sort((G,Fe)=>{const Ye=G.lang.startsWith("en"),st=Fe.lang.startsWith("en");if(Ye&&!st)return-1;if(!Ye&&st)return 1;const et=G.lang.localeCompare(Fe.lang);return et!==0?et:G.name.localeCompare(Fe.name)}),[$e]),pe=Je.useCallback(()=>{if(je){fi.cancelSpeech(),U(!1);return}const G=$e.find(et=>et.name===D),Fe=G?.name??t("settings.voice.page.preview.browserVoiceFallback"),Ye=t("settings.voice.page.preview.voiceLine",{voiceName:Fe});U(!0);const st=new SpeechSynthesisUtterance(Ye);st.rate=i,st.pitch=l,st.volume=c,G&&(st.voice=G,st.lang=G.lang),st.onend=()=>U(!1),st.onerror=()=>U(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(st)},[D,$e,i,l,c,je,t]);Je.useEffect(()=>()=>{je&&fi.cancelSpeech()},[je]),Je.useEffect(()=>{if(!Z||a!=="openai"&&a!=="openai-compatible"){Ee(g.trim().length>0);return}(async()=>{try{const st=(await(await lt("/api/tts/status")).json()).available,et=g.trim().length>0;Ee(st||et)}catch{Ee(g.trim().length>0)}})()},[g,Z,a]),Je.useEffect(()=>{if(!Z){Me(!1),ke([]);return}lt("/api/tts/say/status").then(G=>G.json()).then(G=>{if(Me(G.available),G.voices){const Fe=G.voices.filter((Ye,st,et)=>et.findIndex(wt=>wt.name===Ye.name)===st).sort((Ye,st)=>Ye.name.localeCompare(st.name));ke(Fe)}}).catch(()=>{Me(!1)})},[Z]);const ve=Je.useCallback(async()=>{if(Ae){Ss(Ae),he(null),ze(!1);return}ze(!0);let G=null;try{const Fe=await lt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:m}),voice:m,rate:Math.round(100+(i-.5)*200)})});if(!Fe.ok)throw new Error("Preview failed");const Ye=await Fe.blob(),st=URL.createObjectURL(Ye);G=new Audio(st),G.onended=()=>{Ss(G),he(null),ze(!1)},G.onerror=()=>{Ss(G),he(null),ze(!1)},he(G),await G.play()}catch{Ss(G),he(null),ze(!1)}},[m,i,Ae,t]);Je.useEffect(()=>()=>{Ss(Ae)},[Ae]);const ae=Je.useCallback(async()=>{if(Be){Ss(Be),Ke(null),Qe(!1);return}Qe(!0);let G=null;try{const Fe=await lt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:M}),voice:M,speed:i,apiKey:g||void 0})});if(!Fe.ok){const et=await Fe.json().catch(()=>({error:"Unknown error"}));throw new Error(et.error||`HTTP ${Fe.status}`)}const Ye=await Fe.blob(),st=URL.createObjectURL(Ye);G=new Audio(st),G.onended=()=>{Ss(G),Ke(null),Qe(!1)},G.onerror=()=>{Ss(G),Ke(null),Qe(!1)},Ke(G),await G.play()}catch{Ss(G),Ke(null),Qe(!1)}},[M,i,Be,g,t]);Je.useEffect(()=>()=>{Ss(Be)},[Be]);const _e=Je.useCallback(async()=>{if(Ie){Ss(Ie),Re(null),qe(!1);return}if(!L.trim())return;qe(!0);let G=null;try{const Fe=await lt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:K,model:k||void 0,speed:i,baseURL:L,apiKey:A||void 0})});if(!Fe.ok){const et=await Fe.json().catch(()=>({error:"Unknown error"}));throw new Error(et.error||`HTTP ${Fe.status}`)}const Ye=await Fe.blob(),st=URL.createObjectURL(Ye);G=new Audio(st),G.onended=()=>{Ss(G),Re(null),qe(!1)},G.onerror=()=>{Ss(G),Re(null),qe(!1)},Re(G),await G.play()}catch{Ss(G),Re(null),qe(!1)}},[L,K,k,A,i,Ie,t]);Je.useEffect(()=>()=>{Ss(Ie)},[Ie]);const Ze="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs(s.Fragment,{children:[s.jsxs(Le,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(gt,{checked:Z,onChange:be,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),Z&&s.jsxs(s.Fragment,{children:[s.jsx(Ls,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.localTts")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.openai")})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]}),children:s.jsx(Fs,{value:a,onChange:n,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"browser",label:t("settings.voice.page.provider.browser")},{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai",label:t("settings.voice.page.provider.openai")},{value:"openai-compatible",label:t("settings.voice.page.provider.custom")},...ue?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:ye(Dt,!ge&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ye(En,!ge&&"text-[var(--status-error)]/80"),children:t(ge&&!g?"settings.voice.page.field.apiKeyHintUsingConfig":ge?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:ye("relative",Ts),children:[s.jsx("input",{type:"password",value:g,onChange:G=>j(G.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),g&&s.jsx("button",{type:"button",onClick:()=>j(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Dt,!L.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Yt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:ye("relative",Ts),children:[s.jsx("input",{type:"text",value:L,onChange:G=>C(G.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),L&&s.jsx("button",{type:"button",onClick:()=>C(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Dt,children:"API Key"}),s.jsx("span",{className:En,children:"Optional"}),s.jsxs("div",{className:ye("relative",Ts),children:[s.jsx("input",{type:"password",value:A,onChange:G=>b(G.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),A&&s.jsx("button",{type:"button",onClick:()=>b(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Dt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Ts),children:s.jsx("input",{type:"text",value:k,onChange:G=>W(G.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Dt,children:t("settings.voice.page.field.voice")}),s.jsx(Yt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:ye("flex items-center gap-2",Ts),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:K,onChange:G=>$(G.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(H,{size:"xs",variant:"ghost",onClick:_e,title:t("settings.voice.page.actions.preview"),disabled:!L.trim(),children:Ge?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(Qg,{}),s.jsxs(qt,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Mt,{value:String(p),onValueChange:G=>F(Number.parseInt(G,10)||0),children:[s.jsx(Rt,{size:Ut,className:yn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:G=>Di.find(Fe=>String(Fe.id)===G)?.label??G})}),s.jsx(Ot,{children:Di.map(G=>s.jsx(dt,{value:String(G.id),children:G.label},G.id))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:u,title:t("settings.voice.page.actions.preview"),children:h?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})}),I?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:I}):null]}),a==="openai"&&ge&&s.jsxs(s.Fragment,{children:[s.jsxs(Mt,{value:M,onValueChange:P,children:[s.jsx(Rt,{size:Ut,className:yn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Ot,{children:Yg.map(G=>s.jsx(dt,{value:G.value,children:G.label},G.value))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:ae,title:t("settings.voice.page.actions.preview"),children:Te?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:En,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&ue&&Ce.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Mt,{value:m,onValueChange:v,children:[s.jsx(Rt,{size:Ut,className:yn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Ot,{children:Ce.map(G=>s.jsx(dt,{value:G.name,children:G.name},G.name))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:ve,title:t("settings.voice.page.actions.preview"),children:fe?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&re.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Mt,{value:D||"$auto",onValueChange:G=>q(G==="$auto"?"":G),children:[s.jsx(Rt,{size:Ut,className:yn,children:s.jsx(_t,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Ot,{children:[s.jsx(dt,{value:"$auto",children:t("settings.voice.page.field.auto")}),re.map(G=>s.jsxs(dt,{value:G.name,children:[G.name," (",G.lang,")"]},G.name))]})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:pe,title:t("settings.voice.page.actions.preview"),children:je?s.jsx(z,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(z,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(qt,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:G=>r(Number(G.target.value)),className:Ze}),s.jsx(ys,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]}),s.jsxs(qt,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:G=>f(Number(G.target.value)),className:Ze}),s.jsx(ys,{value:l,onValueChange:f,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]}),s.jsxs(qt,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:c,onChange:G=>y(Number(G.target.value)),className:Ze}),e?s.jsx(ys,{value:Math.round(c*100),onValueChange:G=>y(G/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(c*100),"%"]})]}),s.jsx(Ls,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Fs,{value:B,onChange:Q,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})})]})]}),s.jsxs(Le,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(gt,{checked:Ne,onChange:de,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),Ne&&s.jsxs(s.Fragment,{children:[s.jsx(Ls,{title:t("settings.voice.page.field.provider"),info:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.local")})," ",t("settings.voice.page.tooltip.sttLocal")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]}),children:s.jsx(Fs,{value:w,onChange:X,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai-compatible",label:t("settings.voice.page.provider.server")}]})}),w==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Dt,children:t("settings.voice.page.field.model")}),s.jsx(Jg,{selectedModelId:J,onSelect:te})]}),w==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Dt,!ee.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Yt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:ye("relative",Ts),children:[s.jsx("input",{type:"text",value:ee,onChange:G=>T(G.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),ee&&s.jsx("button",{type:"button",onClick:()=>T(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Dt,children:"API Key"}),s.jsx("span",{className:En,children:"Optional"}),s.jsxs("div",{className:ye("relative",Ts),children:[s.jsx("input",{type:"password",value:O,onChange:G=>V(G.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),O&&s.jsx("button",{type:"button",onClick:()=>V(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(z,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Dt,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Ts),children:s.jsx("input",{type:"text",value:E,onChange:G=>_(G.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Dt,children:t("settings.voice.page.field.language")}),s.jsx(Yt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:ne,onChange:G=>le(G.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]})]})]})]})]})},$a=[{value:"1800000",label:"30m",ms:1800*1e3},{value:"180000",label:"3m",ms:180*1e3},{value:"7200000",label:"2h",ms:7200*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3}],Ba=[{value:"3600000",label:"1h",ms:3600*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"43200000",label:"12h",ms:720*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3},{value:"604800000",label:"1w",ms:10080*60*1e3},{value:"2592000000",label:"30d",ms:720*60*60*1e3}],Xg="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",eh="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Ri=[{value:"quick",labelKey:"settings.openchamber.tunnel.option.mode.quick.label",tooltipKey:"settings.openchamber.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.openchamber.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.openchamber.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedLocal.tooltip"}],th=[".yml",".yaml",".json"],sh="settings.openchamber.tunnel.error.invalidConfigExtension",ga=t=>{const e=t.trim().toLowerCase();return th.some(a=>e.endsWith(a))},nh=t=>t==="ngrok"?"ngrok":"cloudflared",vl=()=>{if(typeof window<"u"&&typeof window.__OPENCHAMBER_PLATFORM__=="string"){const e=window.__OPENCHAMBER_PLATFORM__;if(e==="win32"||e==="darwin"||e==="linux")return e}const t=typeof navigator<"u"?`${navigator.platform||""} ${navigator.userAgent||""}`.toLowerCase():"";return t.includes("win")?"win32":t.includes("mac")?"darwin":"linux"},ah=(t,e=vl())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/",Oi=(t,e)=>{const a=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():t,n=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():nh(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():vl(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():ah(a,i);return{provider:a,dependency:n,installCommand:r}},yl=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,Po=t=>{const e=ft.c(11),{provider:a}=t;let n;e[0]!==a?(n=yl(a),e[0]=a,e[1]=n):n=e[1];const i=n,f=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==f?(c=ye("size-4 shrink-0",f),e[2]=f,e[3]=c):c=e[3];let y;e[4]!==c?(y=s.jsx(z,{name:"cloud",className:c}),e[4]=c,e[5]=y):y=e[5];let m;e[6]!==i?(m=s.jsx("span",{children:i}),e[6]=i,e[7]=m):m=e[7];let v;return e[8]!==y||e[9]!==m?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[y,m]}),e[8]=y,e[9]=m,e[10]=v):v=e[10],v},gn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Ji=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,Io=(t,e,a)=>{const n=Ji(t,e,a);return t.find(i=>i.value===n)?.label||n},Ao=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),i=Math.floor(a%3600/60),r=a%60;return n>0?`${n}h ${i}m`:i>0?`${i}m ${r}s`:`${r}s`},ih=(t,e)=>Uo(t,e,{hour:"2-digit",precision:"second"}),Wa=t=>{const e=t.trim();if(!e)return"";try{return(e.includes("://")?new URL(e):new URL(`https://${e}`)).hostname.trim().toLowerCase()}catch{return e.toLowerCase()}},rh=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const i of t){if(!i||typeof i!="object")continue;const r=i,l=typeof r.id=="string"?r.id.trim():"",f=typeof r.name=="string"?r.name.trim():"",c=Wa(typeof r.hostname=="string"?r.hostname:"");!l||!f||!c||e.has(l)||a.has(c)||(e.add(l),a.add(c),n.push({id:l,name:f,hostname:c}))}return n},oh=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,lh=()=>{const{t}=it(),e=ce(Y=>Y.timeFormatPreference),a=o.useCallback(Y=>t(Y),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[f,c]=o.useState(null),[y,m]=o.useState(null),[v,p]=o.useState(null),[F,S]=o.useState(null),[N,h]=o.useState(!1),[I,u]=o.useState(!1),[D,q]=o.useState(!1),[M,P]=o.useState("cloudflare"),[g,j]=o.useState(()=>Oi("cloudflare")),[L,C]=o.useState([]),[A,b]=o.useState("quick"),[K,$]=o.useState(null),[k,W]=o.useState([]),[Z,B]=o.useState({}),[Q,w]=o.useState(""),[X,ee]=o.useState({}),[T,O]=o.useState(new Set),[V,E]=o.useState(!1),[_,J]=o.useState(""),[te,ne]=o.useState(""),[le,be]=o.useState(""),[Ne,de]=o.useState(1800*1e3),[ue,Me]=o.useState(480*60*1e3),[Ce,ke]=o.useState(""),[fe,ze]=o.useState([]),[Ae,he]=o.useState(()=>Date.now()),[ge,Ee]=o.useState(null),Te=t(sh),Qe=o.useRef(null),Be=o.useMemo(()=>K?!ga(K):!1,[K]),Ke=o.useMemo(()=>k.find(Y=>Y.id===Q)||k[0]||null,[k,Q]),Ge=o.useMemo(()=>fe.map(Y=>{const xe=Y.expiresAt<=Ae,Oe=Y.status==="active"&&!xe,we=Oe?Ao(Y.expiresAt-Ae):Y.inactiveReason==="expired"||xe?"expired":"inactive",rt=we==="expired"?t("settings.openchamber.tunnel.state.expired"):Y.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),ct=gn(Y.mode);return{...Y,isActive:Oe,mode:ct,remainingTextForSession:we,inactiveLabel:rt}}),[Ae,fe,t]),qe=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Ae:!1,[Ae,r?.bootstrapExpiresAt,r?.connectUrl]),Ie=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:f===A,[f,n,r,A]),Re=o.useMemo(()=>!r||n!=="active"||!f?!1:f!==A,[f,n,r,A]),$e=o.useMemo(()=>{if(typeof ge=="number"&&Number.isFinite(ge)&&ge>0)return ge;if(typeof window>"u")return null;const xe=Na()||window.location.href;let Oe=0;try{Oe=Number(new URL(xe).port)}catch{Oe=Number(window.location.port)}return Number.isFinite(Oe)&&Oe>0?Oe:null},[ge]),Ue=o.useMemo(()=>L.find(Y=>Y.provider===M)??null,[L,M]),je=o.useMemo(()=>{const Y=new Set(Ue?.modes?.map(xe=>xe.key).filter(xe=>xe==="quick"||xe==="managed-remote"||xe==="managed-local"));return Y.size===0?Ri:Ri.filter(xe=>Y.has(xe.value))},[Ue]),U=o.useMemo(()=>je.some(Y=>Y.value==="managed-remote"||Y.value==="managed-local"),[je]),re=o.useMemo(()=>g.provider===M?g:Oi(M),[g,M]),pe=o.useCallback(async Y=>{await Nn(Y)},[]),ve=o.useCallback((Y,xe)=>(j(Oi(xe,Y)),Y.available===!0),[]),ae=o.useCallback(async(Y,xe)=>{try{const Oe=await lt("/api/openchamber/tunnel/check",{query:{provider:Y},...xe?{signal:xe}:{}});if(!Oe.ok)return null;const we=await Oe.json();if(xe?.aborted)return null;const rt=ve(we,Y);return i(ct=>ct==="checking"||ct==="starting"||ct==="active"||ct==="stopping"?ct:rt?"idle":"not-available"),rt}catch{return null}},[ve]),_e=o.useCallback(async Y=>{try{const[xe,Oe,we,rt]=await Promise.all([lt("/api/openchamber/tunnel/check",{signal:Y}),lt("/api/openchamber/tunnel/status",{signal:Y}),lt("/api/config/settings",{signal:Y,headers:{Accept:"application/json"}}),lt("/api/openchamber/tunnel/providers",{signal:Y})]),ct=await xe.json(),at=await Oe.json(),Ct=we.ok?await we.json():{},ss=rt.ok?await rt.json():{},es=at.ttlConfig?.bootstrapTtlMs??(Ct?.tunnelBootstrapTtlMs===null?null:typeof Ct?.tunnelBootstrapTtlMs=="number"?Ct.tunnelBootstrapTtlMs:1800*1e3),ds=typeof at.ttlConfig?.sessionTtlMs=="number"?at.ttlConfig.sessionTtlMs:typeof Ct?.tunnelSessionTtlMs=="number"?Ct.tunnelSessionTtlMs:480*60*1e3,Jt=gn(at.mode??Ct?.tunnelMode),Nt=typeof Ct?.tunnelProvider=="string"&&Ct.tunnelProvider.trim().length>0?Ct.tunnelProvider.trim().toLowerCase():"cloudflare",Pt=typeof Ct?.managedLocalTunnelConfigPath=="string"&&Ct.managedLocalTunnelConfigPath.trim()||null,Et=ve(ct,Nt),yt=rh(at?.managedRemoteTunnelPresets),zt=typeof at.managedRemoteTunnelHostname=="string"?at.managedRemoteTunnelHostname:"",Zt=yt.length>0?yt:zt?[{id:`legacy-${Wa(zt)}`,name:zt,hostname:Wa(zt)}]:[],js=Zt[0]?.id||"";if(de(es),Me(ds),P(Nt),C(Array.isArray(ss?.providers)?ss.providers:[]),b(Jt),$(Pt),W(Zt),w(js),ze(Array.isArray(at.activeSessions)?at.activeSessions:[]),c(at.activeTunnelMode?gn(at.activeTunnelMode):at.active&&at.mode?gn(at.mode):null),O(new Set(Array.isArray(at.managedRemoteTunnelTokenPresetIds)?at.managedRemoteTunnelTokenPresetIds:[])),Ee(typeof at.localPort=="number"?at.localPort:null),at.active&&at.url){l({url:at.url,connectUrl:null,bootstrapExpiresAt:typeof at.bootstrapExpiresAt=="number"?at.bootstrapExpiresAt:null}),i("active");return}i(Et?"idle":"not-available")}catch{Y.aborted||(i("error"),p(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[ve,t]);o.useEffect(()=>{const Y=new AbortController;return _e(Y.signal),()=>Y.abort()},[_e]),o.useEffect(()=>{if(!r?.connectUrl){m(null);return}let Y=!1;return Yo.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(xe=>{Y||m(xe)}).catch(()=>{Y||m(null)}),()=>{Y=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){ke(t("settings.openchamber.tunnel.state.noExpiry"));return}let Y=null,xe=Date.now();const Oe=()=>{const ct=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;ct<=0?ke(t("settings.openchamber.tunnel.state.expired")):ke(Ao(ct))},we=()=>{const ct=Date.now();ct-xe>=1e3&&(Oe(),xe=ct),Y=requestAnimationFrame(we)};Oe(),(typeof document>"u"||document.visibilityState==="visible")&&(Y=requestAnimationFrame(we));const rt=()=>{document.visibilityState==="visible"&&Y===null?Y=requestAnimationFrame(we):document.visibilityState!=="visible"&&Y!==null&&(cancelAnimationFrame(Y),Y=null)};return document.addEventListener("visibilitychange",rt),()=>{document.removeEventListener("visibilitychange",rt),Y!==null&&cancelAnimationFrame(Y)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let Y=null,xe=Date.now();const Oe=()=>{const rt=Date.now();rt-xe>=1e3&&(he(rt),xe=rt),Y=requestAnimationFrame(Oe)};(typeof document>"u"||document.visibilityState==="visible")&&(Y=requestAnimationFrame(Oe));const we=()=>{document.visibilityState==="visible"&&Y===null?Y=requestAnimationFrame(Oe):document.visibilityState!=="visible"&&Y!==null&&(cancelAnimationFrame(Y),Y=null)};return document.addEventListener("visibilitychange",we),()=>{document.removeEventListener("visibilitychange",we),Y!==null&&cancelAnimationFrame(Y)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Y=!1;const xe=async()=>{try{const we=await lt("/api/openchamber/tunnel/status");if(!we.ok||Y)return;const rt=await we.json();if(Y)return;ze(Array.isArray(rt.activeSessions)?rt.activeSessions:[]),O(new Set(Array.isArray(rt.managedRemoteTunnelTokenPresetIds)?rt.managedRemoteTunnelTokenPresetIds:[])),Ee(typeof rt.localPort=="number"?rt.localPort:null)}catch{}},Oe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||xe()},5e3);return()=>{Y=!0,window.clearInterval(Oe)}},[n]);const Ze=o.useCallback(async Y=>{q(!0);try{await vt(Y),Object.prototype.hasOwnProperty.call(Y,"tunnelMode")&&Y.tunnelMode&&b(Y.tunnelMode),Object.prototype.hasOwnProperty.call(Y,"tunnelProvider")&&typeof Y.tunnelProvider=="string"&&P(Y.tunnelProvider),Object.prototype.hasOwnProperty.call(Y,"managedLocalTunnelConfigPath")&&$(Y.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Y,"managedRemoteTunnelPresets")&&Y.managedRemoteTunnelPresets&&W(Y.managedRemoteTunnelPresets)}catch{R.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{q(!1)}},[t]),G=o.useCallback(async(Y,xe)=>{u(!0);try{await vt({tunnelBootstrapTtlMs:Y,tunnelSessionTtlMs:xe})}catch{R.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{u(!1)}},[t]),Fe=o.useCallback(async Y=>{const xe=Y.token.trim();if(xe)try{const Oe={...X,[Y.presetId]:xe};await vt({managedRemoteTunnelPresetTokens:Oe}),O(we=>{const rt=new Set(we);return rt.add(Y.presetId),rt})}catch{R.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[X,t]),Ye=o.useCallback(async Y=>{S(null),p(null);const xe=L.find(we=>we.provider===Y),Oe=xe?.modes?.some(we=>we.key===A)?A:gn(xe?.modes?.[0]?.key);await Ze({tunnelProvider:Y,tunnelMode:Oe}),ae(Y)},[L,ae,Ze,A]),st=o.useCallback(async()=>{const Y=await Go({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Y.success&&typeof Y.path=="string"&&Y.path.trim().length>0){const xe=Y.path.trim();if(!ga(xe)){R.error(Te);return}$(xe),await Ze({managedLocalTunnelConfigPath:xe});return}Qe.current?.click()},[Te,Ze]),et=o.useCallback(Y=>{const xe=Y.trim();$(xe.length>0?xe:null)},[]),wt=o.useCallback(async()=>{if(K&&!ga(K)){R.error(Te);return}await Ze({managedLocalTunnelConfigPath:K})},[Te,K,Ze]),pt=o.useCallback(async()=>{$(null),await Ze({managedLocalTunnelConfigPath:null})},[Ze]),mt=o.useCallback(async Y=>{const xe=Y.target.files?.[0];if(!xe)return;const Oe=xe.name.trim();if(Oe.length!==0){if(!ga(Oe)){R.error(Te);return}$(Oe),await Ze({managedLocalTunnelConfigPath:Oe}),Y.target.value=""}},[Te,Ze]),ot=o.useCallback(async()=>{if(p(null),S(null),A==="managed-local"&&K&&!ga(K)){p(Te),R.error(Te);return}i("starting");try{let Y="",xe="";if(A==="managed-remote"){if(!Ke){i("idle"),S(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),R.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Y=Ke.hostname,xe=(X[Ke.id]||"").trim(),await Ze({tunnelMode:"managed-remote",managedRemoteTunnelPresets:k})}const Oe=await lt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:M,mode:A,...A==="managed-remote"&&Ke?{managedRemoteTunnelPresetId:Ke.id,managedRemoteTunnelPresetName:Ke.name}:{},...A==="managed-remote"&&Y?{managedRemoteTunnelHostname:Y}:{},...A==="managed-remote"&&xe?{managedRemoteTunnelToken:xe}:{},...A==="managed-local"&&K?{configPath:K}:{}})}),we=await Oe.json();if(!Oe.ok||!we.ok){if(A==="managed-remote"&&typeof we.error=="string"&&we.error.includes("Managed remote tunnel token is required")){i("idle"),S(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),R.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),p(we.error||t("settings.openchamber.tunnel.toast.startFailed")),R.error(we.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const rt=typeof we.url=="string"?we.url:"";if(!rt){i("error"),p(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),R.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:rt,connectUrl:typeof we.connectUrl=="string"?we.connectUrl:null,bootstrapExpiresAt:typeof we.bootstrapExpiresAt=="number"?we.bootstrapExpiresAt:null}),c(we.activeTunnelMode?gn(we.activeTunnelMode):we.mode?gn(we.mode):A),ze(Array.isArray(we.activeSessions)?we.activeSessions:[]),Array.isArray(we.managedRemoteTunnelTokenPresetIds)&&O(new Set(we.managedRemoteTunnelTokenPresetIds)),typeof we.localPort=="number"&&Ee(we.localPort),typeof we.mode=="string"&&b(gn(we.mode)),i("active"),we.replacedTunnel){const ct=typeof we.revokedBootstrapCount=="number"?we.revokedBootstrapCount:0,at=typeof we.invalidatedSessionCount=="number"?we.invalidatedSessionCount:0;ct===1&&at===1?R.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):ct===1?R.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:at})):at===1?R.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:ct})):R.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:ct,invalidatedSessionCount:at}))}else R.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),p(t("settings.openchamber.tunnel.toast.startFailed")),R.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Te,k,Ze,Ke,X,t,M,A,K]),bt=o.useCallback(async()=>{i("stopping");try{await lt("/api/openchamber/tunnel/stop",{method:"POST"});const Y=await lt("/api/openchamber/tunnel/status");if(Y.ok){const xe=await Y.json();ze(Array.isArray(xe.activeSessions)?xe.activeSessions:[]),O(new Set(Array.isArray(xe.managedRemoteTunnelTokenPresetIds)?xe.managedRemoteTunnelTokenPresetIds:[])),Ee(typeof xe.localPort=="number"?xe.localPort:null)}l(null),c(null),m(null),i("idle"),R.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),p(t("settings.openchamber.tunnel.toast.stopFailed")),R.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),ut=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),h(!0),R.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>h(!1),2e3)}catch{R.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),At=o.useCallback(async Y=>{const xe=$a.find(Oe=>Oe.value===Y);xe&&(de(xe.ms),await G(xe.ms,ue))},[G,ue]),ie=o.useCallback(async Y=>{const xe=Ba.find(Oe=>Oe.value===Y);!xe||xe.ms===null||(Me(xe.ms),await G(Ne,xe.ms))},[Ne,G]),Pe=o.useCallback(async Y=>{S(null),p(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await Ze({tunnelMode:Y,managedRemoteTunnelPresets:k})},[k,Ze,n]),Ve=o.useCallback(async(Y,xe)=>{try{await vt({managedRemoteTunnelPresets:xe})}catch{R.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),We=o.useCallback(Y=>{const xe=k.find(Oe=>Oe.id===Y);xe&&(w(xe.id),S(null),Ve(xe,k))},[k,Ve]),kt=o.useCallback(async()=>{const Y=_.trim(),xe=Wa(te),Oe=le.trim();if(!Y){R.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!xe){R.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Oe){R.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(k.some(ct=>ct.hostname===xe)){R.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const we={id:oh(),name:Y,hostname:xe},rt=[...k,we];W(rt),w(we.id),B(ct=>({...ct,[we.id]:!0})),ee(ct=>({...ct,[we.id]:Oe})),S(null),E(!1),J(""),ne(""),be(""),await Ze({tunnelMode:"managed-remote",managedRemoteTunnelPresets:rt,managedRemoteTunnelPresetTokens:{...X,[we.id]:Oe}}),await Fe({presetId:we.id,presetName:we.name,hostname:we.hostname,token:Oe}),R.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[k,te,_,le,Fe,Ze,X,t]),St=o.useCallback(async Y=>{const xe=k.find(at=>at.id===Y);if(!xe)return;const Oe=k.filter(at=>at.id!==xe.id),we=Oe[0]?.id||"",rt=Q===xe.id?we:Q,ct=Object.fromEntries(Object.entries(X).filter(([at,Ct])=>at!==xe.id&&Ct.trim().length>0));W(Oe),w(rt),B(at=>{const Ct={...at};return delete Ct[xe.id],Ct}),ee(at=>{const Ct={...at};return delete Ct[xe.id],Ct}),O(at=>{const Ct=new Set(at);return Ct.delete(xe.id),Ct}),S(null),await Ze({managedRemoteTunnelPresets:Oe,managedRemoteTunnelPresetTokens:ct}),R.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[k,Ze,Q,X,t]),Wt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.openchamber.tunnel.state.loading")})}):s.jsx(Le,{title:t("settings.openchamber.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.openchamber.tunnel.description")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.openchamber.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[Ge.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(z,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:fr,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:Ge.map(Y=>{const xe=Y.mode==="quick",Oe=Y.mode==="managed-remote",we=xe?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Oe?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",rt=Y.isActive?xe?"text-[var(--status-warning)]":Oe?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",ct=t(xe?"settings.openchamber.tunnel.badge.quick":Oe?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(z,{name:"checkbox-blank-circle-fill",className:ye("size-2.5 shrink-0",rt)}),s.jsx("span",{className:ye("typography-micro rounded border px-1.5 py-0.5 uppercase",we),children:ct}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:ih(Y.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Y.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Y.remainingTextForSession}):Y.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:Y.inactiveLabel})})]},Y.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:fr,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:re.dependency})}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:re.installCommand})]})]})}),s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{"data-settings-item":"tunnel.provider",className:"space-y-1.5",children:[s.jsx("p",{className:Dt,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Mt,{value:M,onValueChange:Y=>{Ye(Y)},disabled:D||n==="starting"||n==="stopping",children:[s.jsx(Rt,{size:Ut,className:"max-w-[16rem]",children:s.jsx(_t,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:yl(M)})}),s.jsxs(Ot,{children:[L.length>0?L.map(Y=>s.jsx(dt,{value:Y.provider,children:s.jsx(Po,{provider:Y.provider})},Y.provider)):s.jsx(dt,{value:"cloudflare",children:s.jsx(Po,{provider:"cloudflare"})}),s.jsx(dt,{value:"__more-soon",disabled:!0,children:t("settings.openchamber.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Dt,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:je.map(Y=>s.jsxs(Zi,{children:[s.jsx(Xi,{asChild:!0,children:s.jsx(H,{variant:"chip",size:"xs","aria-pressed":A===Y.value,className:"!font-normal",onClick:()=>{Pe(Y.value)},disabled:D||n==="starting"||n==="stopping",children:a(Y.labelKey)})}),s.jsx(Fo,{sideOffset:8,className:"max-w-xs",children:a(Y.tooltipKey)})]},Y.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Dt,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Mt,{value:Ji($a,Ne,"1800000"),onValueChange:Y=>{At(Y)},disabled:I||D||n==="starting"||n==="stopping",children:[s.jsx(Rt,{size:Ut,className:"max-w-[11rem] min-w-0",children:s.jsx(_t,{className:"truncate",children:Io($a,Ne,"1800000")})}),s.jsx(Ot,{children:$a.map(Y=>s.jsx(dt,{value:Y.value,children:Y.label},Y.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Dt,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Mt,{value:Ji(Ba,ue,"28800000"),onValueChange:Y=>{ie(Y)},disabled:I||D||n==="starting"||n==="stopping",children:[s.jsx(Rt,{size:Ut,className:"max-w-[11rem] min-w-0",children:s.jsx(_t,{className:"truncate",children:Io(Ba,ue,"28800000")})}),s.jsx(Ot,{children:Ba.map(Y=>s.jsx(dt,{value:Y.value,children:Y.label},Y.value))})]})]})]}),A==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),U&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),A==="managed-remote"&&s.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof $e=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",$e]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx($s,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>E(Y=>!Y),disabled:n==="starting"||n==="stopping"||D,children:[s.jsx(z,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),k.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:k.map((Y,xe)=>{const Oe=X[Y.id]||"",we=T.has(Y.id),rt=Z[Y.id]??!1;return s.jsx("div",{className:ye(xe<k.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(Yn,{open:rt,onOpenChange:ct=>{B(at=>({...at,[Y.id]:ct})),ct&&We(Y.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Zn,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||D,children:[rt?s.jsx(z,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(z,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label min-w-0 flex-1 truncate text-foreground",children:Y.name})]}),s.jsx(H,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:Y.name}),onClick:()=>{St(Y.id)},disabled:n==="starting"||n==="stopping"||D,children:s.jsx(z,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Xn,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:Y.hostname})]}),s.jsx(He,{type:"password",value:Oe,onChange:ct=>{const at=ct.target.value;S(null),ee(Ct=>({...Ct,[Y.id]:at}))},onBlur:ct=>{const at=ct.currentTarget.value.trim();at&&Fe({presetId:Y.id,presetName:Y.name,hostname:Y.hostname,token:at})},placeholder:t(we?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Oe.trim().length===0,onClick:()=>{Fe({presetId:Y.id,presetName:Y.name,hostname:Y.hostname,token:Oe})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},Y.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),V&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(He,{value:_,onChange:Y=>J(Y.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:D||n==="starting"||n==="stopping"}),s.jsx(He,{value:te,onChange:Y=>ne(Y.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:D||n==="starting"||n==="stopping"}),s.jsx(He,{type:"password",value:le,onChange:Y=>be(Y.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:D||n==="starting"||n==="stopping"}),typeof $e=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",$e]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{kt()},disabled:D||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{E(!1),J(""),ne(""),be("")},disabled:D||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Yt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!Ke&&F&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:F})]}),A==="managed-local"&&s.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Dt,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Qe,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Y=>{mt(Y)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:K||"",onChange:Y=>{et(Y.target.value)},onBlur:()=>{wt()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||D}),s.jsx(H,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{st()},disabled:n==="starting"||n==="stopping"||D,children:s.jsx(z,{name:"folder",className:"size-3.5"})}),K&&s.jsx(H,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{pt()},disabled:n==="starting"||n==="stopping"||D,children:s.jsx(z,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(K?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Be&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Te})]})}),!Ie&&s.jsxs("div",{"data-settings-item":"tunnel.start",className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[A==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{pe(Xg)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(z,{name:"external-link",className:"size-3.5"})]})]}),A==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{pe(eh)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(z,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:a(Ri.find(Y=>Y.value===A)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),A==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Dt,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Mt,{value:Q||(k[0]?.id??""),onValueChange:Y=>{We(Y)},disabled:D||n==="starting"||n==="stopping"||k.length<=1,children:[s.jsx(Rt,{size:Ut,children:s.jsx(_t,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Ke?.name})}),s.jsx(Ot,{fitContent:!0,children:k.map(Y=>s.jsx(dt,{value:Y.id,children:Y.name},Y.id))})]})]}),Re&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(z,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(H,{size:"sm",variant:"outline",onClick:ot,disabled:n==="starting"||D||A==="managed-remote"&&!Ke||A==="managed-local"&&Be,className:ye(Wt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ie&&r&&s.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.url})]}),qe&&r.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.connectUrl}),s.jsxs(H,{size:"sm",variant:"ghost",onClick:ut,className:"shrink-0 gap-1.5",children:[N?s.jsx(z,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(z,{name:"file-copy",className:"size-3.5"}),t(N?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",r.bootstrapExpiresAt?Ce:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[y?s.jsx("img",{src:y,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{size:"sm",variant:"outline",onClick:ot,disabled:n==="stopping"||D||A==="managed-local"&&Be,className:Wt,children:[s.jsx(z,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:bt,disabled:n==="stopping"||D,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(z,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&v&&s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v}),s.jsx(H,{size:"sm",variant:"ghost",onClick:ot,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},jl=()=>{const{t}=it(),[e,a]=Je.useState(""),[n,i]=Je.useState(!0),[r,l]=Je.useState(!1),f=ce(p=>p.showOpenCodeUpdateNotifications),c=ce(p=>p.setShowOpenCodeUpdateNotifications);Je.useEffect(()=>{let p=!1;return(async()=>{try{const F=await lt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!F.ok)return;const S=await F.json().catch(()=>null);if(p||!S)return;const N=typeof S.opencodeBinary=="string"?S.opencodeBinary.trim():"";a(N)}catch{}finally{p||i(!1)}})(),()=>{p=!0}},[]);const y=Je.useCallback(async()=>{if(!(typeof window>"u")&&cs())try{const p=await Go();p.success&&p.path&&p.path.trim().length>0&&a(p.path.trim())}catch{}},[]),m=Je.useCallback(async()=>{l(!0);try{const p=e.trim(),F=p.length>=2&&(p.startsWith('"')&&p.endsWith('"')||p.startsWith("'")&&p.endsWith("'"))?p.slice(1,-1).trim():p;await vt({opencodeBinary:F}),Dn("cli",{id:"opencode-binary"}),R.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),v=Je.useCallback(p=>{c(p),vt({showOpenCodeUpdateNotifications:p})},[c]);return s.jsx(Le,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(qt,{settingsItem:"sessions.opencode-binary",label:t("settings.openchamber.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(He,{value:e,onChange:p=>a(p.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:n||r,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(H,{type:"button",variant:"outline",size:"xs",onClick:y,disabled:n||r||!cs(),className:gs,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(z,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Qn,{className:bs,children:[!qo()&&s.jsx(gt,{settingsItem:"sessions.opencode-update-notifications",checked:f,onChange:v,label:t("settings.openchamber.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(H,{type:"button",size:"xs",onClick:m,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},wl=()=>{const t=ft.c(44),{t:e}=it(),a=ce(ch),n=ce(dh),i=ce(ph),r=ce(mh),l=ce(uh),f=ce(gh),c=ce(hh);let y;t[0]!==n?(y=A=>{n(A),vt({agentControlToolEnabled:A}),Dn("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=y):y=t[1];const m=y;let v;t[2]!==r?(v=A=>{r(A),vt({agentWebToolEnabled:A}),Dn("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=v):v=t[3];const p=v;let F;t[4]!==c?(F=A=>{c(A),vt({agentMemoryToolEnabled:A}).finally(()=>{A&&jc.getState().refresh()}),Dn("cli",{id:"agent-memory-tool"})},t[4]=c,t[5]=F):F=t[5];const S=F;let N;t[6]!==e?(N=e("settings.openchamber.tools.title"),t[6]=e,t[7]=N):N=t[7];let h;t[8]!==e?(h=e("settings.openchamber.tools.field.agentControlTool"),t[8]=e,t[9]=h):h=t[9];let I;t[10]!==e?(I=e("settings.openchamber.tools.field.agentControlToolAria"),t[10]=e,t[11]=I):I=t[11];let u;t[12]!==e?(u=e("settings.openchamber.tools.field.agentControlToolInfo"),t[12]=e,t[13]=u):u=t[13];let D;t[14]!==a||t[15]!==m||t[16]!==h||t[17]!==I||t[18]!==u?(D=s.jsx(gt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:m,label:h,ariaLabel:I,info:u}),t[14]=a,t[15]=m,t[16]=h,t[17]=I,t[18]=u,t[19]=D):D=t[19];let q;t[20]!==e?(q=e("settings.openchamber.tools.field.agentWebTool"),t[20]=e,t[21]=q):q=t[21];let M;t[22]!==e?(M=e("settings.openchamber.tools.field.agentWebToolAria"),t[22]=e,t[23]=M):M=t[23];let P;t[24]!==e?(P=e("settings.openchamber.tools.field.agentWebToolInfo"),t[24]=e,t[25]=P):P=t[25];let g;t[26]!==i||t[27]!==p||t[28]!==P||t[29]!==q||t[30]!==M?(g=s.jsx(gt,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:p,label:q,ariaLabel:M,info:P}),t[26]=i,t[27]=p,t[28]=P,t[29]=q,t[30]=M,t[31]=g):g=t[31];let j;t[32]!==f||t[33]!==l||t[34]!==S||t[35]!==e?(j=f?s.jsx(gt,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:S,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[32]=f,t[33]=l,t[34]=S,t[35]=e,t[36]=j):j=t[36];let L;t[37]!==g||t[38]!==j||t[39]!==D?(L=s.jsxs("div",{className:bs,children:[D,g,j]}),t[37]=g,t[38]=j,t[39]=D,t[40]=L):L=t[40];let C;return t[41]!==L||t[42]!==N?(C=s.jsx(Le,{title:N,children:L}),t[41]=L,t[42]=N,t[43]=C):C=t[43],C};function ch(t){return t.agentControlToolEnabled}function dh(t){return t.setAgentControlToolEnabled}function ph(t){return t.agentWebToolEnabled}function mh(t){return t.setAgentWebToolEnabled}function uh(t){return t.agentMemoryToolEnabled}function gh(t){return t.agentMemoryFeatureAvailable}function hh(t){return t.setAgentMemoryToolEnabled}const kl=()=>{const{t}=it(),e=cs()&&Sa(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=Je.useState(!1),[r,l]=Je.useState(!1),[f,c]=Je.useState(""),[y,m]=Je.useState(""),[v,p]=Je.useState(!1),[F,S]=Je.useState(!1),[N,h]=Je.useState(null),[I,u]=Je.useState(!0),[D,q]=Je.useState(!1),[M,P]=Je.useState(!1),[g,j]=Je.useState(!1),[L,C]=Je.useState(!1),[A,b]=Je.useState(!1),[K,$]=Je.useState(!1),[k,W]=Je.useState(!1),[Z,B]=Je.useState(!0),[Q,w]=Je.useState(!0),[X,ee]=Je.useState(!1),[T,O]=Je.useState(!1),[V,E]=Je.useState(!1),[_,J]=Je.useState(null),[te,ne]=Je.useState(null);Je.useEffect(()=>{if(!e){u(!1);return}let he=!1;return(async()=>{try{const ge=await lt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!ge.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const Ee=await ge.json().catch(()=>null);if(he)return;const Te=Ee?.desktopLanAccessEnabled===!0,Qe=typeof Ee?.desktopUiPassword=="string"?Ee.desktopUiPassword:"";i(Te),l(Te),c(Qe),m(Qe),S(Ee?.desktopLanAccessActive===!0),h(typeof Ee?.desktopLanAccessBlockedReason=="string"?Ee.desktopLanAccessBlockedReason:null);const Be=Ee?.desktopMacMenuBarEnabled!==!1;B(Be),w(Be),J(null)}catch(ge){he||J(ge instanceof Error?ge.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{he||u(!1)}})(),()=>{he=!0}},[e,t]),Je.useEffect(()=>{if(!e){P(!1);return}let he=!1;return(async()=>{const ge=await Jc();he||(P(ge?.supported===!0),j(ge?.enabled===!0))})(),()=>{he=!0}},[e]),Je.useEffect(()=>{if(!e){b(!1);return}let he=!1;return(async()=>{const ge=await Qc();he||(b(ge?.supported===!0),$(ge?.enabled===!0))})(),()=>{he=!0}},[e]),Je.useEffect(()=>{if(!e){ee(!1);return}let he=!1;return(async()=>{const ge=await Yc();he||(ee(ge?.supported===!0),O(ge?.enabled===!0))})(),()=>{he=!0}},[e]),Je.useEffect(()=>{if(!e||!r){ne(null);return}let he=!1;return(async()=>{const ge=await Bo();he||ne(ge)})(),()=>{he=!0}},[r,e]);const le=r!==n||y!==f||Q!==Z,be=Je.useMemo(()=>{if(typeof window>"u")return null;const ge=Na()||window.location.href;let Ee=0;try{Ee=Number(new URL(ge).port)}catch{Ee=Number(window.location.port)}return Number.isFinite(Ee)&&Ee>0?Ee:null},[]),Ne=r&&F&&te&&be?`http://${te}:${be}`:null,de=r&&!y.trim(),ue=n&&!F&&N==="missing-password",Me=I||D||!le||de,Ce=Je.useCallback(he=>{m(he),he.trim()||l(!1)},[]),ke=Je.useCallback(async()=>{if(!M||L)return;const he=!g;j(he),C(!0),J(null);try{const ge=await Zc(he);if(!ge?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));j(ge.enabled)}catch(ge){j(!he),J(ge instanceof Error?ge.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{C(!1)}},[L,g,M,t]),fe=Je.useCallback(async()=>{if(!A||k)return;const he=!K;$(he),W(!0),J(null);try{const ge=await Xc(he);if(!ge)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!ge.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));$(ge.enabled)}catch(ge){$(!he),J(ge instanceof Error?ge.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{W(!1)}},[k,K,A,t]),ze=Je.useCallback(async()=>{if(!X||V)return;const he=!T;O(he),E(!0),J(null);try{const ge=await ed(he);if(!ge?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));O(ge.enabled)}catch(ge){O(!he),J(ge instanceof Error?ge.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{E(!1)}},[V,T,X,t]),Ae=Je.useCallback(async()=>{if(le){q(!0),J(null);try{if(!(await lt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:y,desktopMacMenuBarEnabled:Q})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(r),c(y),B(Q),!await td())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(he){J(he instanceof Error?he.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),q(!1)}}},[Q,y,r,le,t]);return e?s.jsx(Le,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[M||a||A||X?s.jsxs("div",{className:bs,children:[M?s.jsx(gt,{settingsItem:"sessions.desktop-launch-at-login",checked:g,onChange:he=>{he!==g&&ke()},disabled:L,label:t("settings.openchamber.desktopNetwork.field.launchAtLogin"),info:t("settings.openchamber.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(gt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:Q,onChange:w,disabled:I||D,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,A?s.jsx(gt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:K,onChange:he=>{he!==K&&fe()},disabled:k,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,X?s.jsx(gt,{settingsItem:"sessions.desktop-keep-awake",checked:T,onChange:he=>{he!==T&&ze()},disabled:V,label:t("settings.openchamber.desktopNetwork.field.keepAwake"),info:t("settings.openchamber.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(Qt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),info:t("settings.openchamber.desktopPassword.field.passwordDescription"),children:[s.jsx(He,{id:"desktop-ui-password",type:v?"text":"password",className:"h-8 min-w-0 flex-1",value:y,onChange:he=>Ce(he.target.value),placeholder:t("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:I||D,required:r,"aria-invalid":de}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>p(he=>!he),className:gs,"aria-label":t(v?"settings.openchamber.desktopPassword.actions.hidePassword":"settings.openchamber.desktopPassword.actions.showPassword"),"aria-pressed":v,children:s.jsx(z,{name:v?"eye-off":"eye",className:"h-4 w-4"})})]}),s.jsx("div",{className:bs,children:s.jsx(gt,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:I||D,label:t("settings.openchamber.desktopNetwork.field.allowLanAccess"),info:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription"),description:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")}),de||ue?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria")})}),_?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:_}):null,Ne?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(le&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:Ne})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(H,{type:"button",size:"xs",onClick:Ae,disabled:Me,className:"shrink-0 !font-normal",children:t(D?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},Nl=new Set(["shift","control","alt","meta"]),fh=t=>{if(Nl.has(t.key.toLowerCase()))return null;const e=[];(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt");const a=_o(t.key);return a?(e.push(a),nn(e.join("+"))):null},xh=t=>{const e=[];if((t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),Nl.has(t.key.toLowerCase()))return e.length>0?nn(e.join("+")):null;const a=_o(t.key);return a?(e.push(a),e.length>0?nn(e.join("+")):null):null},bh=()=>{const t=ft.c(54),{t:e}=it();let a;t[0]!==e?(a=V=>e(V),t[0]=e,t[1]=a):a=t[1];const n=a,i=ce(vh),r=ce(yh),l=ce(jh),f=ce(wh);let c;if(t[2]===Symbol.for("react.memo_cache_sentinel")){e:{const V=wc();if(!ps()){c=V;break e}c=V.filter(kh)}t[2]=c}else c=t[2];const y=c;let m;t[3]!==n?(m=(V,E)=>{const _=`settings.openchamber.keyboardShortcuts.action.${V}.label`,J=n(_);return J===_?E:J},t[3]=n,t[4]=m):m=t[4];const v=m,[p,F]=o.useState(null);let S;t[5]===Symbol.for("react.memo_cache_sentinel")?(S={},t[5]=S):S=t[5];const[N,h]=o.useState(S),[I,u]=o.useState(""),[D,q]=o.useState(""),[M,P]=o.useState(null),g=Nh;let j;t[6]!==i?(j=(V,E)=>{const _=nn(E);for(const J of y){if(J.id===V)continue;const te=xr(J.id,i);if(nn(te)===_)return J.id}return null},t[6]=i,t[7]=j):j=t[7];const L=j;let C;t[8]!==L||t[9]!==r||t[10]!==i||t[11]!==e?(C=(V,E)=>{const _=nn(E),J=L(V,_);if(J){P({actionId:V,combo:_,conflictActionId:J}),u("");return}const te={...i,[V]:_};r(V,_),g(te),P(null),u(""),q(vr(_)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),h(ne=>{const le={...ne};return delete le[V],le})},t[8]=L,t[9]=r,t[10]=i,t[11]=e,t[12]=C):C=t[12];const A=C;let b;t[13]!==M||t[14]!==r||t[15]!==i||t[16]!==e?(b=()=>{if(!M)return;const V={...i,[M.conflictActionId]:xi,[M.actionId]:M.combo};r(M.conflictActionId,xi),r(M.actionId,M.combo),g(V),P(null),u(""),q(vr(M.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),h(E=>{const _={...E};return delete _[M.actionId],_})},t[13]=M,t[14]=r,t[15]=i,t[16]=e,t[17]=b):b=t[17];const K=b;let $;t[18]!==l||t[19]!==i?($=V=>{const E={...i};delete E[V],l(V),g(E),h(_=>{const J={..._};return delete J[V],J}),P(null),u(""),q("")},t[18]=l,t[19]=i,t[20]=$):$=t[20];const k=$;let W;t[21]!==e?(W=e("settings.openchamber.keyboardShortcuts.title"),t[21]=e,t[22]=W):W=t[22];let Z;t[23]!==e?(Z=e("settings.openchamber.keyboardShortcuts.tooltip"),t[23]=e,t[24]=Z):Z=t[24];let B;t[25]!==f?(B=()=>{f(),g({}),h({}),P(null),u(""),q("")},t[25]=f,t[26]=B):B=t[26];let Q;t[27]!==e?(Q=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[27]=e,t[28]=Q):Q=t[28];let w;t[29]!==B||t[30]!==Q?(w=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:B,children:Q}),t[29]=B,t[30]=Q,t[31]=w):w=t[31];let X;t[32]!==K||t[33]!==I||t[34]!==M||t[35]!==e||t[36]!==D?(X=(I||D||M)&&s.jsxs("div",{className:"mb-2 space-y-2",children:[M&&s.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col @xl:flex-row @xl:items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),s.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.jsx(H,{type:"button",size:"xs",className:"!font-normal",onClick:K,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(H,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>P(null),children:e("settings.common.actions.cancel")})]})]}),I&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:I}),D&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:D})]}),t[32]=K,t[33]=I,t[34]=M,t[35]=e,t[36]=D,t[37]=X):X=t[37];let ee;t[38]!==v||t[39]!==p||t[40]!==N||t[41]!==k||t[42]!==A||t[43]!==i||t[44]!==e?(ee=y.map((V,E)=>{const _=V.id==="switch_context_surface",J=_?kc(V.id,i):xr(V.id,i),te=N[V.id],ne=te??J,le=typeof te=="string"&&nn(te)!==nn(J),be=ne===""||nn(ne)===xi,Ne=p===V.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):_&&!be?`${br(ne)}${e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix")}`:br(ne);return s.jsx("div",{className:ye("py-1.5",E>0&&"border-t border-border/40"),children:s.jsxs(qt,{label:v(V.id,V.label),alignEnd:!1,children:[s.jsx(He,{readOnly:!0,value:Ne,onFocus:()=>{F(V.id),u("")},onBlur:()=>{p===V.id&&F(null)},onKeyDown:de=>{if(de.preventDefault(),de.stopPropagation(),de.key==="Escape"){F(null);return}const ue=_?xh(de):fh(de);ue&&(h(Me=>({...Me,[V.id]:ue})),F(null),P(null),u(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(H,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const de=N[V.id];if(!de){u(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}A(V.id,de)},disabled:!le,children:e("settings.common.actions.saveChanges")}),s.jsx(H,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>k(V.id),children:e("settings.common.actions.reset")})]})},V.id)}),t[38]=v,t[39]=p,t[40]=N,t[41]=k,t[42]=A,t[43]=i,t[44]=e,t[45]=ee):ee=t[45];let T;t[46]!==ee?(T=s.jsx("div",{children:ee}),t[46]=ee,t[47]=T):T=t[47];let O;return t[48]!==w||t[49]!==X||t[50]!==T||t[51]!==W||t[52]!==Z?(O=s.jsxs(Le,{settingsItem:"shortcuts.keyboard-shortcuts",title:W,divider:!1,info:Z,headerAction:w,children:[X,T]}),t[48]=w,t[49]=X,t[50]=T,t[51]=W,t[52]=Z,t[53]=O):O=t[53],O};function vh(t){return t.shortcutOverrides}function yh(t){return t.setShortcutOverride}function jh(t){return t.clearShortcutOverride}function wh(t){return t.resetAllShortcutOverrides}function kh(t){return t.id!=="toggle_prompt_navigator"}function Nh(t){vt({shortcutOverrides:t})}const Sl=()=>{const t=ft.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>Ho(()=>a(Lh)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},Sh=t=>{const e=ft.c(79),{section:a}=t,{t:n}=it(),{isMobile:i}=ea();Sl();let r;e[0]!==i?(r=i&&wn(),e[0]=i,e[1]=r):r=e[1];const l=r;let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=ps(),e[2]=f):f=e[2];const c=f;let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=cs()&&Sa(),e[3]=y):y=e[3];const m=y;if(!a){let X,ee,T,O,V,E,_;e[4]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsx(ti,{}),T=s.jsx(bl,{}),O=m&&s.jsx(kl,{}),V=!c&&s.jsx(jl,{}),E=!c&&s.jsx(wl,{}),_=s.jsx(fl,{}),X=wn()&&!cs()&&!c&&!Wo()&&s.jsx(xl,{}),e[4]=X,e[5]=ee,e[6]=T,e[7]=O,e[8]=V,e[9]=E,e[10]=_):(X=e[4],ee=e[5],T=e[6],O=e[7],V=e[8],E=e[9],_=e[10]);let J;e[11]!==l?(J=l&&s.jsx(Zo,{}),e[11]=l,e[12]=J):J=e[12];let te;return e[13]!==J?(te=s.jsxs(as,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[ee,T,O,V,E,_,X,J]}),e[13]=J,e[14]=te):te=e[14],te}let v;e[15]!==a?(v=()=>{switch(a){case"general":return s.jsx(Ph,{});case"visual":return s.jsx(Ih,{});case"chat":return s.jsx(Ah,{});case"sessions":return s.jsx(Eh,{});case"shortcuts":return s.jsx(Ch,{});case"git":return s.jsx(Th,{});case"github":return s.jsx(Dh,{});case"notifications":return s.jsx(Mh,{});case"voice":return s.jsx(Rh,{});case"tunnel":return s.jsx(Oh,{});default:return null}},e[15]=a,e[16]=v):v=e[16];const p=v;let F;e[17]!==n?(F=n("settings.page.general.title"),e[17]=n,e[18]=F):F=e[18];let S;e[19]!==n?(S=n("settings.page.appearance.title"),e[19]=n,e[20]=S):S=e[20];let N;e[21]!==n?(N=n("settings.page.chat.title"),e[21]=n,e[22]=N):N=e[22];let h;e[23]!==n?(h=n("settings.page.sessions.title"),e[23]=n,e[24]=h):h=e[24];let I;e[25]!==n?(I=n("settings.page.shortcuts.title"),e[25]=n,e[26]=I):I=e[26];let u;e[27]!==n?(u=n("settings.page.git.title"),e[27]=n,e[28]=u):u=e[28];let D;e[29]!==n?(D=n("settings.page.git.title"),e[29]=n,e[30]=D):D=e[30];let q;e[31]!==n?(q=n("settings.page.notifications.title"),e[31]=n,e[32]=q):q=e[32];let M;e[33]!==n?(M=n("settings.page.voice.title"),e[33]=n,e[34]=M):M=e[34];let P;e[35]!==n?(P=n("settings.page.tunnel.title"),e[35]=n,e[36]=P):P=e[36];let g;e[37]!==u||e[38]!==D||e[39]!==q||e[40]!==M||e[41]!==P||e[42]!==F||e[43]!==S||e[44]!==N||e[45]!==h||e[46]!==I?(g={general:F,visual:S,chat:N,sessions:h,shortcuts:I,git:u,github:D,notifications:q,voice:M,tunnel:P},e[37]=u,e[38]=D,e[39]=q,e[40]=M,e[41]=P,e[42]=F,e[43]=S,e[44]=N,e[45]=h,e[46]=I,e[47]=g):g=e[47];const j=g[a];let L;e[48]!==n?(L=n("settings.page.general.description"),e[48]=n,e[49]=L):L=e[49];let C;e[50]!==n?(C=n("settings.page.appearance.description"),e[50]=n,e[51]=C):C=e[51];let A;e[52]!==n?(A=n("settings.page.chat.description"),e[52]=n,e[53]=A):A=e[53];let b;e[54]!==n?(b=n("settings.page.sessions.description"),e[54]=n,e[55]=b):b=e[55];let K;e[56]!==n?(K=n("settings.page.shortcuts.description"),e[56]=n,e[57]=K):K=e[57];let $;e[58]!==n?($=n("settings.page.notifications.description"),e[58]=n,e[59]=$):$=e[59];let k;e[60]!==n?(k=n("settings.page.voice.description"),e[60]=n,e[61]=k):k=e[61];let W;e[62]!==n?(W=n("settings.page.tunnel.description"),e[62]=n,e[63]=W):W=e[63];let Z;e[64]!==L||e[65]!==C||e[66]!==A||e[67]!==b||e[68]!==K||e[69]!==$||e[70]!==k||e[71]!==W?(Z={general:L,visual:C,chat:A,sessions:b,shortcuts:K,git:void 0,github:void 0,notifications:$,voice:k,tunnel:W},e[64]=L,e[65]=C,e[66]=A,e[67]=b,e[68]=K,e[69]=$,e[70]=k,e[71]=W,e[72]=Z):Z=e[72];const B=Z[a];let Q;e[73]!==p?(Q=p(),e[73]=p,e[74]=Q):Q=e[74];let w;return e[75]!==B||e[76]!==j||e[77]!==Q?(w=s.jsx(as,{title:j,description:B,showSaveStatus:!0,className:"openchamber-page-body",children:Q}),e[75]=B,e[76]=j,e[77]=Q,e[78]=w):w=e[78],w},Ch=()=>{const t=ft.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(bh,{}),t[0]=e):e=t[0],e},Ph=()=>{const t=ft.c(8);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ps(),t[0]=e):e=t[0];const a=e;Sl();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=cs()&&Sa(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=wn()&&!cs()&&!a&&!Wo(),t[2]=r):r=t[2];const l=r;let f,c,y,m;t[3]===Symbol.for("react.memo_cache_sentinel")?(f=i&&s.jsx(kl,{}),c=l&&s.jsx(xl,{}),y=!a&&s.jsx(jl,{}),m=!a&&s.jsx(wl,{}),t[3]=f,t[4]=c,t[5]=y,t[6]=m):(f=t[3],c=t[4],y=t[5],m=t[6]);let v;return t[7]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsxs(s.Fragment,{children:[f,c,y,m,s.jsx(ti,{visibleSettings:["fileEditorKeymap","autoSaveEnabled","expandedEditorToolbar",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[7]=v):v=t[7],v},Ih=()=>{const t=ft.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ps(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(ti,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","inputBarOffset"]}),t[1]=n):n=t[1],n},Ah=()=>{const t=ft.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=ps(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(ti,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck"]}),t[1]=n):n=t[1],n},Eh=()=>{const t=ft.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(bl,{}),s.jsx(fl,{})]}),t[0]=e):e=t[0],e},Th=()=>{const t=ft.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(gl,{}),t[0]=e):e=t[0],e},Dh=()=>{const t=ft.c(1);if(ps())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(hl,{}),t[0]=e):e=t[0],e},Mh=()=>{const t=ft.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(qg,{}),t[0]=e):e=t[0],e},Rh=()=>{const t=ft.c(1);if(ps())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Zg,{}),t[0]=e):e=t[0],e},Oh=()=>{const t=ft.c(1);if(ps())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(lh,{}),t[0]=e):e=t[0],e};function Lh(t){return t+1}const Fh=t=>{const e=ft.c(85),{className:a}=t,{t:n}=it(),i=ln(Vo),r=ln(Kh),l=ce(zh),f=ce(Uh),[c,y]=Je.useState(!1),[m,v]=Je.useState(!1),p=i>0;let F;e[0]!==n?(F=async()=>{try{const Ce=await Nc({message:n("settings.view.pendingRestart.applying")});if(Ce.requiresManualRestart){R.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Ce.ok&&R.success(n("settings.view.pendingRestart.applied"))}catch(Ce){const ke=Ce,fe=ke instanceof Error&&ke.message?ke.message:n("settings.view.pendingRestart.applyFailed");R.error(fe)}},e[0]=n,e[1]=F):F=e[1];const S=F;let N;e[2]!==n?(N=async()=>{try{await Sc({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),ln.getState().clear()}catch{}},e[2]=n,e[3]=N):N=e[3];const h=N;let I;e[4]!==m||e[5]!==S||e[6]!==f?(I=()=>{m&&f(!1),y(!1),v(!1),S()},e[4]=m,e[5]=S,e[6]=f,e[7]=I):I=e[7];const u=I;let D;e[8]!==p||e[9]!==S||e[10]!==h||e[11]!==l?(D=()=>{if(!p){h();return}if(l){v(!1),y(!0);return}S()},e[8]=p,e[9]=S,e[10]=h,e[11]=l,e[12]=D):D=e[12];const q=D;let M;e[13]!==p||e[14]!==r||e[15]!==n?(M=n(p?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=p,e[14]=r,e[15]=n,e[16]=M):M=e[16];const P=M;let g;e[17]!==p||e[18]!==i||e[19]!==n?(g=p?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=p,e[18]=i,e[19]=n,e[20]=g):g=e[20];const j=g,L=p?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",C=r&&"opacity-80";let A;e[21]!==a||e[22]!==L||e[23]!==C?(A=ye("flex w-full items-center gap-2 rounded-md overflow-hidden whitespace-nowrap","h-11 px-3 sm:h-8 sm:px-2","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",L,C,a),e[21]=a,e[22]=L,e[23]=C,e[24]=A):A=e[24];let b;e[25]!==p||e[26]!==i?(b=p?s.jsx("span",{className:ye("inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1.5","bg-background text-foreground typography-micro font-semibold tabular-nums"),"aria-hidden":"true",children:i}):s.jsx(z,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=p,e[26]=i,e[27]=b):b=e[27];let K;e[28]!==P?(K=s.jsx("span",{className:"truncate",children:P}),e[28]=P,e[29]=K):K=e[29];let $;e[30]!==q||e[31]!==r||e[32]!==b||e[33]!==K||e[34]!==A||e[35]!==j?($=s.jsxs("button",{type:"button",disabled:r,title:j,"aria-label":j,onClick:q,className:A,children:[b,K]}),e[30]=q,e[31]=r,e[32]=b,e[33]=K,e[34]=A,e[35]=j,e[36]=$):$=e[36];let k;e[37]===Symbol.for("react.memo_cache_sentinel")?(k=Ce=>{y(Ce),Ce||v(!1)},e[37]=k):k=e[37];let W;e[38]!==n?(W=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=W):W=e[39];let Z;e[40]!==W?(Z=s.jsx(Ht,{children:W}),e[40]=W,e[41]=Z):Z=e[41];let B;e[42]!==n?(B=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=B):B=e[43];let Q;e[44]!==B?(Q=s.jsx(Gt,{children:B}),e[44]=B,e[45]=Q):Q=e[45];let w;e[46]!==Z||e[47]!==Q?(w=s.jsxs(Bt,{children:[Z,Q]}),e[46]=Z,e[47]=Q,e[48]=w):w=e[48];let X;e[49]===Symbol.for("react.memo_cache_sentinel")?(X={width:"40%"},e[49]=X):X=e[49];let ee;e[50]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>y(!1),e[50]=ee):ee=e[50];let T;e[51]!==n?(T=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=T):T=e[52];let O;e[53]!==T?(O=s.jsx("div",{className:"min-w-0 shrink-0",style:X,children:s.jsx(H,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:ee,children:T})}),e[53]=T,e[54]=O):O=e[54];let V;e[55]===Symbol.for("react.memo_cache_sentinel")?(V={width:"40%"},e[55]=V):V=e[55];let E;e[56]!==n?(E=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=E):E=e[57];let _;e[58]!==u||e[59]!==E?(_=s.jsx("div",{className:"min-w-0 shrink-0",style:V,children:s.jsx(H,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:u,children:E})}),e[58]=u,e[59]=E,e[60]=_):_=e[60];let J;e[61]!==O||e[62]!==_?(J=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[O,_]}),e[61]=O,e[62]=_,e[63]=J):J=e[63];let te;e[64]===Symbol.for("react.memo_cache_sentinel")?(te=()=>v(_h),e[64]=te):te=e[64];let ne;e[65]!==m?(ne=m?s.jsx(z,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(z,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=m,e[66]=ne):ne=e[66];let le;e[67]!==n?(le=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=le):le=e[68];let be;e[69]!==m||e[70]!==ne||e[71]!==le?(be=s.jsxs("button",{type:"button",onClick:te,className:"inline-flex items-center justify-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":m,children:[ne,le]}),e[69]=m,e[70]=ne,e[71]=le,e[72]=be):be=e[72];let Ne;e[73]!==J||e[74]!==be?(Ne=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[J,be]}),e[73]=J,e[74]=be,e[75]=Ne):Ne=e[75];let de;e[76]!==w||e[77]!==Ne?(de=s.jsxs($t,{showCloseButton:!1,className:"max-w-md gap-5",children:[w,Ne]}),e[76]=w,e[77]=Ne,e[78]=de):de=e[78];let ue;e[79]!==c||e[80]!==de?(ue=s.jsx(Vt,{open:c,onOpenChange:k,children:de}),e[79]=c,e[80]=de,e[81]=ue):ue=e[81];let Me;return e[82]!==$||e[83]!==ue?(Me=s.jsxs(s.Fragment,{children:[$,ue]}),e[82]=$,e[83]=ue,e[84]=Me):Me=e[84],Me};function Kh(t){return t.isApplying}function zh(t){return t.showOpenCodeRestartConfirm}function Uh(t){return t.setShowOpenCodeRestartConfirm}function _h(t){return!t}const Vh=[{id:"appearance.language",page:"appearance",titleKey:"settings.appearance.language.label",descriptionKey:"settings.appearance.language.description",keywords:["locale","translation","ui language"]},{id:"appearance.time-format",page:"appearance",titleKey:"settings.openchamber.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.openchamber.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"],isAvailable:t=>!t.isVSCode},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.openchamber.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.openchamber.visual.field.dockBadge",descriptionKey:"settings.openchamber.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.openchamber.visual.field.installAppName",descriptionKey:"settings.openchamber.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.openchamber.visual.field.installOrientation",descriptionKey:"settings.openchamber.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.openchamber.visual.field.mobileKeyboardMode",descriptionKey:"settings.openchamber.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.openchamber.visual.field.terminalShell",descriptionKey:"settings.openchamber.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.openchamber.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.openchamber.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.openchamber.visual.field.inputBarOffset",descriptionKey:"settings.openchamber.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.openchamber.visual.field.autoSaveEnabled",descriptionKey:"settings.openchamber.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.expanded-editor-toolbar",page:"general",titleKey:"settings.openchamber.visual.field.expandedEditorToolbar",keywords:["editor","toolbar","tabs","docked","files"],isAvailable:t=>!t.isVSCode},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.openchamber.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.openchamber.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.openchamber.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.openchamber.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.openchamber.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.openchamber.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.openchamber.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.openchamber.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.openchamber.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.openchamber.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.openchamber.defaults.smallModel.title",descriptionKey:"settings.openchamber.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.openchamber.defaults.walkthroughModel.title",descriptionKey:"settings.openchamber.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.openchamber.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.openchamber.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-window-controls-style",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsStyle",keywords:["desktop","window","controls","style","traffic","lights","classic","macos","titlebar"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-mac-menu-bar",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.macMenuBar",descriptionKey:"settings.openchamber.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.openchamber.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows","linux"],isAvailable:t=>t.isDesktopLocalOrigin&&(t.isWindows||t.isLinux)},{id:"sessions.desktop-keep-awake",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.keepAwake",descriptionKey:"settings.openchamber.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentControlTool",descriptionKey:"settings.openchamber.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","openchamber","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentWebTool",descriptionKey:"settings.openchamber.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","openchamber"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-memory-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentMemoryTool",descriptionKey:"settings.openchamber.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","openchamber"],isAvailable:t=>!t.isVSCode&&ce.getState().agentMemoryFeatureAvailable},{id:"git.github-account",page:"git",titleKey:"settings.github.page.actions.connect",keywords:["github","account","oauth","prs","issues"]},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.openchamber.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.openchamber.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.openchamber.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.work-status-panel",page:"usage",titleKey:"settings.usage.page.options.showInWorkStatus",descriptionKey:"settings.usage.page.options.showInWorkStatusTooltip",keywords:["quota","work","status","panel"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.accent-color",page:"projects",titleKey:"settings.projects.page.field.accentColor",keywords:["color","appearance","project metadata"]},{id:"projects.icon",page:"projects",titleKey:"settings.projects.page.field.projectIcon",keywords:["icon","favicon","upload","project metadata"]},{id:"projects.worktree",page:"projects",titleKey:"settings.projects.page.section.worktree",keywords:["worktree","branch","repository"]},{id:"projects.worktree.setup.wait",page:"projects",titleKey:"settings.openchamber.worktrees.setup.waitForCommands",keywords:["worktree","setup commands","bootstrap","wait"]},{id:"remote-instances.client-auth",page:"remote-instances",titleKey:"settings.remoteInstances.clientAuth.title",descriptionKey:"settings.remoteInstances.clientAuth.description",keywords:["pairing link","client token","connect desktop","remote access","relay","devices","connect from anywhere"],isAvailable:t=>!t.isVSCode},{id:"remote-instances.direct-hosts",page:"remote-instances",titleKey:"settings.remoteInstances.direct.title",descriptionKey:"settings.remoteInstances.direct.description",keywords:["server url","connection token","import link","host switcher","additional headers","request headers","cloudflare access","service token"],isAvailable:t=>t.isDesktop},{id:"behavior.system-prompt-optimization",page:"behavior",titleKey:"settings.behavior.page.section.systemPromptOptimization",descriptionKey:"settings.behavior.page.systemPromptOptimization.info",keywords:["system prompt","tokens","context","optimize","minimal"],isAvailable:t=>!t.isVSCode},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.custom",page:"providers",titleKey:"settings.providers.page.custom.title",descriptionKey:"settings.providers.page.custom.description",keywords:["other","custom","openai-compatible","base url","api key"]},{id:"providers.auth",page:"providers",titleKey:"settings.providers.page.auth.title",keywords:["api key","oauth","credentials"]},{id:"providers.connection-details",page:"providers",titleKey:"settings.providers.page.connectionDetails.title",keywords:["config","source","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.openchamber.keyboardShortcuts.title",descriptionKey:"settings.openchamber.keyboardShortcuts.tooltip",keywords:["keyboard","hotkeys","bindings"]},{id:"voice.playback",page:"voice",titleKey:"settings.voice.page.section.playbackAndSummary",keywords:["tts","read aloud","voice","provider","speech rate","speech pitch","speech volume","tts input mode","markdown"]},{id:"voice.speech-recognition",page:"voice",titleKey:"settings.voice.page.section.speechRecognition",keywords:["stt","dictation","voice input","transcribe","whisper","parakeet","microphone"]},{id:"tunnel.provider",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.provider",descriptionKey:"settings.openchamber.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.connectLinkTtl",descriptionKey:"settings.openchamber.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.openchamber.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.openchamber.tunnel.field.configurationFile",descriptionKey:"settings.openchamber.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.openchamber.tunnel.actions.startTunnel",descriptionKey:"settings.openchamber.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"integrations.third-party",page:"integrations",titleKey:"settings.integrations.thirdParty.title",keywords:["plugin","provider","oauth","install","update","remove"]},{id:"integrations.third-party.opencode-claude",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",keywords:["claude","anthropic","claude code","pro","max","agent sdk","@openchamber/opencode-claude"]},{id:"integrations.third-party.opencode-commandcode",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeCommandcode.name",descriptionKey:"settings.integrations.thirdParty.opencodeCommandcode.description",keywords:["command code","commandcode","laguna","poolside","gateway","@openchamber/opencode-commandcode"]},{id:"integrations.third-party.opencode-cursor-oauth",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeCursorOauth.name",descriptionKey:"settings.integrations.thirdParty.opencodeCursorOauth.description",keywords:["cursor","oauth","subscription","openai compatible","@openchamber/opencode-cursor"]}];function Eo(t){return t.trim().toLocaleLowerCase()}function $h({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=Eo(t);if(!r)return[];const l=a?new Set(a):null,f=r.split(/\s+/).filter(Boolean);return Vh.flatMap(c=>{if(l&&!l.has(c.page))return[];const y=fa(c.page);if(!y||y.isAvailable&&!y.isAvailable(e)||c.isAvailable&&!c.isAvailable(e))return[];const m=n(c.titleKey),v=c.descriptionKey?n(c.descriptionKey):null,p=Eo([m,v,i(c.page),...c.keywords??[]].filter(Boolean).join(" "));return f.every(F=>p.includes(F))?[{...c,title:m,description:v,pageTitle:i(c.page)}]:[]})}const To=256,Do=280,Cl="__openchamberSettingsDetail",Bh=["general","appearance","chat","notifications","sessions","shortcuts","voice","integrations","usage","about","projects","remote-instances","tunnel","git","providers","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],Hh=["general","projects","opencode","content"],Gh="__add_provider__";function qh(t,e){const a=ps(),n=!t&&wn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function Mo(t,e){return t.isAvailable?t.isAvailable(e):!0}function Qi(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ha(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function Li(t){if(!Qi(t))return null;const e=t[Cl];if(!Qi(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Jo(a),stage:n}}function Wh(){return typeof window>"u"||!Qi(window.history.state)?{}:window.history.state}const Jh=t=>{const e=ft.c(129),{onClose:a,forceMobile:n,isWindowed:i,visiblePageSlugs:r,initialMobileStage:l}=t,f=l===void 0?"nav":l,{t:c}=it(),y=ea(),m=n??y.isMobile,v=ln(Vo),p=ce(Qh),F=ce(Yh),S=ce(Zh);let N;e[0]!==p?(N=Jo(p),e[0]=p,e[1]=N):N=e[1];const h=N,[I,u]=o.useState(f),D=o.useRef(f==="nav"?h:null);let q,M;e[2]!==m||e[3]!==S||e[4]!==h?(q=()=>{!m&&h==="home"&&S("general")},M=[m,S,h],e[2]=m,e[3]=S,e[4]=h,e[5]=q,e[6]=M):(q=e[5],M=e[6]),o.useEffect(q,M);const[P,g]=o.useState(""),[j,L]=o.useState(null),[C,A]=o.useState(0),b=o.useRef(null);let K;e[7]===Symbol.for("react.memo_cache_sentinel")?(K=[],e[7]=K):K=e[7];const $=o.useRef(K),k=o.useRef(0),W=o.useRef(!1);let Z;e[8]===Symbol.for("react.memo_cache_sentinel")?(Z=cs(),e[8]=Z):Z=e[8];const B=Z;let Q;e[9]===Symbol.for("react.memo_cache_sentinel")?(Q=cs()&&Sa(),e[9]=Q):Q=e[9];const w=Q;let X;e[10]===Symbol.for("react.memo_cache_sentinel")?(X=cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",e[10]=X):X=e[10];const ee=X;let T;e[11]===Symbol.for("react.memo_cache_sentinel")?(T=cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",e[11]=T):T=e[11];const O=T;let V;e[12]===Symbol.for("react.memo_cache_sentinel")?(V=cs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",e[12]=V):V=e[12];const E=V;let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=qo(),e[13]=_):_=e[13];const J=_;let te;e[14]!==m?(te=qh(B,m),e[14]=m,e[15]=te):te=e[15];const ne=te;let le;if(e[16]!==m||e[17]!==ne||e[18]!==r){const Se=r?new Set(r):null;let nt;e[20]!==ne?(nt=Kt=>Mo(Kt,ne),e[20]=ne,e[21]=nt):nt=e[21];let xt;e[22]!==ne.isVSCode?(xt=Kt=>!(ne.isVSCode&&Kt.slug==="projects"),e[22]=ne.isVSCode,e[23]=xt):xt=e[23];let It;e[24]!==m?(It=Kt=>!(m&&Kt.slug==="shortcuts"),e[24]=m,e[25]=It):It=e[25],le=rd.filter(Xh).filter(Kt=>!Se||Se.has(Kt.slug)).filter(nt).filter(xt).filter(It),e[16]=m,e[17]=ne,e[18]=r,e[19]=le}else le=e[19];const be=le;let Ne;e[26]===Symbol.for("react.memo_cache_sentinel")?(Ne=new Map(Bh.map(ef)),e[26]=Ne):Ne=e[26];const de=Ne;let ue;if(e[27]!==be){let Se;e[29]===Symbol.for("react.memo_cache_sentinel")?(Se=(nt,xt)=>(de.get(nt.slug)??999)-(de.get(xt.slug)??999),e[29]=Se):Se=e[29],ue=be.slice().sort(Se),e[27]=be,e[28]=ue}else ue=e[28];const Me=ue,Ce=Ks(tf);let ke;e[30]!==F||e[31]!==i||e[32]!==ne.isVSCode||e[33]!==h?(ke=()=>{if(!(!F&&!ne.isVSCode&&!i)){if(h==="agents"){ka.getState().loadAgents();return}if(h==="commands"){Za.getState().loadCommands();return}if(h==="mcp"){Xa.getState().loadMcpConfigs();return}if(h==="plugins"){ls.getState().loadPlugins();return}(h==="skills.installed"||h==="skills.catalog")&&(rn.getState().loadSkills(),an.getState().loadCatalog()),h==="snippets"&&ei.getState().loadSnippets()}},e[30]=F,e[31]=i,e[32]=ne.isVSCode,e[33]=h,e[34]=ke):ke=e[34];let fe;e[35]!==Ce||e[36]!==F||e[37]!==i||e[38]!==ne.isVSCode||e[39]!==h?(fe=[Ce,F,i,ne.isVSCode,h],e[35]=Ce,e[36]=F,e[37]=i,e[38]=ne.isVSCode,e[39]=h,e[40]=fe):fe=e[40],o.useEffect(ke,fe);let ze;e[41]!==m||e[42]!==S?(ze=Se=>{if(S(Se),D.current=Se,!m)return;const nt=fa(Se);if(!nt||nt.slug==="home"){u("nav");return}u(nt.kind==="split"?"page-sidebar":"page-content")},e[41]=m,e[42]=S,e[43]=ze):ze=e[43];const Ae=ze;let he;e[44]!==m||e[45]!==Ae?(he=async Se=>{const nt=tt.getState();return await nt.loadProviders({source:"settings:third-party-provider-setup"}),tt.getState().providers.some(It=>It.id===Se)?(nt.setSelectedProvider(Se),Ae("providers"),m&&u("page-content"),!0):!1},e[44]=m,e[45]=Ae,e[46]=he):he=e[46];const ge=he;let Ee;e[47]!==h?(Ee=fa(h),e[47]=h,e[48]=Ee):Ee=e[48];const Te=Ee;let Qe;e[49]===Symbol.for("react.memo_cache_sentinel")?(Qe={general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[49]=Qe):Qe=e[49];const Be=Qe;let Ke;e[50]!==c?(Ke=Se=>{switch(Se){case"general":return c("settings.page.general.title");case"projects":return c("settings.page.projects.title");case"remote-instances":return c("settings.page.remoteInstances.title");case"providers":return c("settings.page.providers.title");case"usage":return c("settings.page.usage.title");case"agents":return c("settings.page.agents.title");case"behavior":return c("settings.page.behavior.title");case"commands":return c("settings.page.commands.title");case"mcp":return c("settings.page.mcp.title");case"plugins":return c("settings.page.plugins.title");case"skills.installed":return c("settings.page.skills.title");case"skills.catalog":return c("settings.page.skillsCatalog.title");case"git":return c("settings.page.git.title");case"integrations":return c("settings.page.integrations.title");case"appearance":return c("settings.page.appearance.title");case"chat":return c("settings.page.chat.title");case"shortcuts":return c("settings.page.shortcuts.title");case"sessions":return c("settings.page.sessions.title");case"magic-prompts":return c("settings.page.magicPrompts.title");case"snippets":return c("settings.page.snippets.title");case"notifications":return c("settings.page.notifications.title");case"voice":return c("settings.page.voice.title");case"tunnel":return c("settings.page.tunnel.title");case"about":return c("settings.page.about.title");default:return c("settings.view.home.title")}},e[50]=c,e[51]=Ke):Ke=e[51];const Ge=Ke;let qe;e[52]!==Ge||e[53]!==ne||e[54]!==P||e[55]!==c||e[56]!==r?(qe=$h({query:P,runtimeCtx:{...ne,isDesktopLocalOrigin:w,isMac:ee,isWindows:O,isLinux:E,isWindowsArm64:J},visiblePageSlugs:r,t:c,getPageTitle:Ge}),e[52]=Ge,e[53]=ne,e[54]=P,e[55]=c,e[56]=r,e[57]=qe):qe=e[57];const Ie=qe,Re=lf;let $e;if(e[58]!==Ie){$e=[];const Se=new Map;for(const nt of Ie){let xt=Se.get(nt.page);xt||(xt={page:nt.page,pageTitle:nt.pageTitle,results:[]},Se.set(nt.page,xt),$e.push(xt)),xt.results.push(nt)}e[58]=Ie,e[59]=$e}else $e=e[59];const Ue=$e;let je;e[60]===Symbol.for("react.memo_cache_sentinel")?(je=()=>{A(0),k.current=0,W.current=!1},e[60]=je):je=e[60];let U;e[61]!==P?(U=[P],e[61]=P,e[62]=U):U=e[62],o.useEffect(je,U);let re,pe;e[63]!==C?(re=()=>{k.current=C},pe=[C],e[63]=C,e[64]=re,e[65]=pe):(re=e[64],pe=e[65]),o.useEffect(re,pe);let ve,ae;e[66]!==C?(ve=()=>{$.current[C]?.scrollIntoView({block:"nearest"})},ae=[C],e[66]=C,e[67]=ve,e[68]=ae):(ve=e[67],ae=e[68]),o.useEffect(ve,ae);let _e,Ze;e[69]!==C||e[70]!==Ie.length?(_e=()=>{C>=Ie.length&&A(Math.max(0,Ie.length-1)),$.current.length=Ie.length},Ze=[C,Ie.length],e[69]=C,e[70]=Ie.length,e[71]=_e,e[72]=Ze):(_e=e[71],Ze=e[72]),o.useEffect(_e,Ze);let G;e[73]!==m||e[74]!==Ae?(G=Se=>{const nt=Re(Se);L(nt),Ae(Se.page),m&&u("page-content"),Se.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(cf,50)},e[73]=m,e[74]=Ae,e[75]=G):G=e[75];const Fe=G;let Ye;e[76]!==Fe||e[77]!==P||e[78]!==Ie?(Ye=Se=>{if(P.trim()){if(Se.key==="Escape"){Se.preventDefault(),g("");return}if(Ie.length!==0){if(Se.key==="ArrowDown"){Se.preventDefault(),W.current=!0,A(nt=>(nt+1)%Ie.length);return}if(Se.key==="ArrowUp"){Se.preventDefault(),W.current=!0,A(nt=>(nt-1+Ie.length)%Ie.length);return}if(Se.key==="Enter"){Se.preventDefault();const nt=(k.current%Ie.length+Ie.length)%Ie.length,xt=Ie[nt]??Ie[0];xt&&Fe(xt)}}}},e[76]=Fe,e[77]=P,e[78]=Ie,e[79]=Ye):Ye=e[79];const st=Ye;let et;e[80]!==j?(et=()=>{const Se=j;if(!Se)return;let nt=!1;const xt=window.requestAnimationFrame(()=>{if(nt)return;const It=typeof CSS<"u"&&CSS.escape?CSS.escape(Se):Se.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Kt=b.current?.querySelector(`[data-settings-item="${It}"]`);Kt&&(L(null),Kt.scrollIntoView({block:"center",behavior:"smooth"}),Kt.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Kt.removeAttribute("data-settings-search-highlight")},1600))});return()=>{nt=!0,window.cancelAnimationFrame(xt)}},e[80]=j,e[81]=et):et=e[81];let wt;e[82]!==j||e[83]!==h?(wt=[j,h],e[82]=j,e[83]=h,e[84]=wt):wt=e[84],o.useEffect(et,wt);let pt;e[85]!==c?(pt=()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:Ic,children:c("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:c("settings.view.unavailable.description")})]})}),e[85]=c,e[86]=pt):pt=e[86];const mt=pt,ot=df;let bt;e[87]!==Ae||e[88]!==ge||e[89]!==mt||e[90]!==ne||e[91]!==c?(bt=Se=>{const nt=fa(Se);if(nt&&!Mo(nt,ne))return mt();switch(Se){case"projects":return s.jsx(Vm,{});case"remote-instances":return s.jsx(ru,{});case"agents":return s.jsx(zd,{});case"behavior":return s.jsx(Bd,{});case"commands":return s.jsx(Xd,{});case"mcp":return s.jsx(kp,{});case"plugins":return s.jsx(em,{});case"skills.installed":return s.jsx(Jr,{view:"installed"});case"skills.catalog":return s.jsx(Jr,{view:"catalog"});case"providers":return s.jsx(_u,{});case"usage":return s.jsx(sg,{});case"about":return s.jsx(as,{title:c("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Zo,{})});case"magic-prompts":return s.jsx(og,{});case"snippets":return s.jsx(mg,{});case"git":return s.jsx(xg,{});case"integrations":return s.jsx(Sg,{onOpenProviderSetup:ge,onOpenPluginManager:()=>Ae("plugins")});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const xt=Be[Se]??"visual";return s.jsx(Sh,{section:xt})}default:return null}},e[87]=Ae,e[88]=ge,e[89]=mt,e[90]=ne,e[91]=c,e[92]=bt):bt=e[92];const ut=bt;let At,ie;e[93]!==m||e[94]!==I||e[95]!==h?(At=()=>{if(!m||I!=="nav"||h==="home"||D.current===h)return;const Se=fa(h);!Se||Se.slug==="home"||(D.current=h,u(Se.kind==="split"?"page-sidebar":"page-content"))},ie=[m,I,h],e[93]=m,e[94]=I,e[95]=h,e[96]=At,e[97]=ie):(At=e[96],ie=e[97]),o.useEffect(At,ie);const Pe=m&&I!=="nav",Ve=m&&I==="page-content"&&h==="skills.installed",We=I==="page-content"&&Te?.kind==="split"&&!Ve;let kt;e[98]!==Ve||e[99]!==Pe||e[100]!==c?(kt=c(Ve?"settings.view.actions.back":Pe?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[98]=Ve,e[99]=Pe,e[100]=c,e[101]=kt):kt=e[101];const St=kt,Wt=Cc();let Y;e[102]!==ne.isVSCode?(Y=Se=>{if(typeof window>"u"||ne.isVSCode)return;const nt=Li(window.history.state);nt?.page===Se&&nt.stage==="page-content"||window.history.pushState({...Wh(),[Cl]:{page:Se,stage:"page-content"}},"",window.location.href)},e[102]=ne.isVSCode,e[103]=Y):Y=e[103];const xe=Y;let Oe;e[104]!==xe||e[105]!==h?(Oe=()=>{u("page-content"),h==="skills.installed"&&xe(h)},e[104]=xe,e[105]=h,e[106]=Oe):Oe=e[106];const we=Oe;let rt;e[107]!==Ve||e[108]!==ne.isVSCode||e[109]!==h?(rt=()=>{if(Ve){if((typeof window<"u"?Li(window.history.state):null)?.page===h&&!ne.isVSCode){window.history.back();return}u("page-sidebar");return}u("nav")},e[107]=Ve,e[108]=ne.isVSCode,e[109]=h,e[110]=rt):rt=e[110];const ct=rt;let at,Ct;e[111]!==m||e[112]!==ne.isVSCode||e[113]!==h?(at=()=>{if(!m||ne.isVSCode)return;const Se=nt=>{if(h!=="skills.installed")return;if(Li(nt.state)?.page==="skills.installed"){u("page-content");return}u(pf)};return window.addEventListener("popstate",Se),()=>{window.removeEventListener("popstate",Se)}},Ct=[m,ne.isVSCode,h],e[111]=m,e[112]=ne.isVSCode,e[113]=h,e[114]=at,e[115]=Ct):(at=e[114],Ct=e[115]),o.useEffect(at,Ct);let ss;e[116]===Symbol.for("react.memo_cache_sentinel")?(ss=()=>{u("page-sidebar")},e[116]=ss):ss=e[116];const es=ss,ds=()=>{const Se=P.trim().length>0;return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[s.jsx("div",{className:"px-4 pt-3",children:s.jsxs("div",{className:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[s.jsx(z,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:P,onChange:nt=>g(nt.target.value),onKeyDown:st,placeholder:c("settings.view.search.placeholder"),"aria-label":c("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),Se&&s.jsx("button",{type:"button",onClick:()=>g(""),"aria-label":c("settings.view.search.clear"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-interactive-hover hover:text-foreground sm:h-5 sm:w-5",children:s.jsx(z,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:Se?Ie.length>0?(()=>{let nt=0;return Ue.map(xt=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:"px-2 pb-0.5 pt-2 typography-micro font-medium text-muted-foreground/70",children:xt.pageTitle}),xt.results.map(It=>{const Kt=nt;nt=nt+1;const hs=Kt===C,Ps=!!It.description;return s.jsxs("button",{type:"button",ref:fs=>{$.current[Kt]=fs},onMouseMove:()=>{W.current=!1,A(Kt)},onClick:()=>Fe(It),className:ye("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Ps?"min-h-11 py-1.5":"py-2",hs?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:It.title}),Ps&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:It.description})]},It.id)})]},xt.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:c("settings.view.search.noResults")}):(()=>{const nt=new Map;for(const It of Me){const Kt=It.group,hs=nt.get(Kt);hs?hs.push(It):nt.set(Kt,[It])}return Hh.map(It=>({group:It,pages:nt.get(It)??[]})).filter(mf).map((It,Kt)=>{const{group:hs,pages:Ps}=It;return s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:ye("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Kt===0?"pt-1":"pt-4 sm:pt-3"),children:c(`settings.view.nav.group.${hs}`)}),Ps.map(fs=>{const Kn=h===fs.slug&&!(m&&I==="nav"),zn=od(fs.slug);return!zn&&fs.slug!=="mcp"?null:s.jsx(Zi,{children:s.jsx(Xi,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>Ae(fs.slug),"aria-current":Kn?"page":void 0,className:ye("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",Kn?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[fs.slug==="mcp"?s.jsx(Pc,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(z,{name:zn,className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:Ge(fs.slug)}),fs.slug==="tunnel"&&s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:c("settings.view.badge.beta")})]})]})})},fs.slug)})]},hs)})})()})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-background px-4 py-1.5 space-y-0.5 sm:bg-sidebar",children:(!ne.isVSCode||v>0)&&s.jsx(Fh,{})})})]})},Jt=()=>{if(I==="nav")return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(pn,{children:ds()})})});if(!Te)return s.jsx("div",{className:"flex-1 bg-background"});if(I==="page-sidebar"){if(Te.kind!=="split"){const nt=ut(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(pn,{children:nt})})}return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(pn,{children:ot(h,{onItemSelect:we})})})}const Se=ut(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(pn,{children:Se})})};let Nt;e[117]!==Te||e[118]!==ut||e[119]!==ne.isVSCode||e[120]!==h?(Nt=()=>!Te||h==="home"?null:Te.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ye("border-r",ne.isVSCode?"bg-background":"bg-sidebar"),style:{width:Do,minWidth:Do,borderColor:"var(--interactive-border)"},children:s.jsx(pn,{children:ot(h,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(pn,{children:ut(h)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(pn,{children:ut(h)})}),e[117]=Te,e[118]=ut,e[119]=ne.isVSCode,e[120]=h,e[121]=Nt):Nt=e[121];const Pt=Nt,Et="true";let yt;e[122]===Symbol.for("react.memo_cache_sentinel")?(yt=ye("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[122]=yt):yt=e[122];const zt=m?s.jsxs("div",{className:ye("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",I!=="nav"&&"border-b","bg-background"),style:I!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[Pe?s.jsx("button",{type:"button",onClick:ct,"aria-label":St,className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(z,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:I==="nav"?c("settings.view.home.title"):Te?Ge(Te.slug):c("settings.view.home.title")}),We&&s.jsx("button",{type:"button",onClick:es,"aria-label":c("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(z,{name:"list-unordered",className:"h-5 w-5"})}),a&&s.jsx("button",{type:"button",onClick:a,"aria-label":c("settings.view.actions.closeSettings"),title:c("settings.view.actions.closeSettingsWithShortcut",{shortcut:Wt}),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(z,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Pe&&s.jsx("div",{className:ye("absolute left-3 z-50",i?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:ct,"aria-label":c("settings.view.actions.back"),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(z,{name:"arrow-left-s",className:"h-5 w-5"})})}),a&&s.jsx("div",{className:ye("absolute right-0.5 z-50",i?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:a,"aria-label":c("settings.view.actions.closeSettings"),title:c("settings.view.actions.closeSettingsWithShortcut",{shortcut:Wt}),className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(z,{name:"close",className:"h-5 w-5"})})})]}),Zt="flex flex-1 min-h-0 overflow-hidden",js=m?Jt():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("relative flex h-full min-h-0 flex-col overflow-hidden border-r",B?"bg-sidebar":ne.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${To}px`,minWidth:`${To}px`,borderColor:"var(--interactive-border)"},children:s.jsx(pn,{children:ds()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Pt()})]});let oe;e[123]!==js?(oe=s.jsx("div",{className:Zt,children:js}),e[123]=js,e[124]=oe):oe=e[124];let ht;return e[125]!==yt||e[126]!==zt||e[127]!==oe?(ht=s.jsxs("div",{ref:b,"data-settings-view":Et,className:yt,children:[zt,oe]}),e[125]=yt,e[126]=zt,e[127]=oe,e[128]=ht):ht=e[128],ht};function Qh(t){return t.settingsPage}function Yh(t){return t.isSettingsDialogOpen}function Zh(t){return t.setSettingsPage}function Xh(t){return t.slug!=="home"}function ef(t,e){return[t,e]}function tf(t){return t.activeProjectId}function sf(t){return t.name}function nf(t){return t.name}function af(t){return t.name}function rf(t){return t.name}function of(t){return t.name}function lf(t){if(t.id.startsWith("agents.")){const e=ka.getState(),a=ha("new-agent",e.agents.map(sf));return e.setAgentDraft({name:a,scope:"user"}),e.setSelectedAgent(a),t.id==="agents.create"?"agents.name":t.id}if(t.id.startsWith("commands.")){const e=Za.getState(),a=ha("new-command",e.commands.map(nf));return e.setCommandDraft({name:a,scope:"user"}),e.setSelectedCommand(a),t.id==="commands.create"?"commands.name":t.id}if(t.id.startsWith("mcp.")){const e=Xa.getState(),a=ha("new-mcp-server",e.mcpServers.map(af));return e.setMcpDraft({name:a,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),e.setSelectedMcp(a),t.id==="mcp.create"?"mcp.server":t.id}if(t.id.startsWith("snippets.")){const e=ei.getState(),a=ha("new-snippet",e.snippets.map(rf));return e.setSnippetDraft({name:a,scope:"global"}),e.setSelectedSnippet(a),t.id==="snippets.create"?"snippets.content":t.id}if(t.id.startsWith("skills.")){const e=rn.getState(),a=ha("new-skill",e.skills.map(of));return e.setSkillDraft({name:a,scope:"user",source:"opencode",description:"",instructions:""}),e.setSelectedSkill(a),t.id==="skills.create"?"skills.basic-information":t.id}return t.id==="providers.connect"&&tt.getState().setSelectedProvider(Gh),t.id==="plugins.create"?"plugins.spec":t.id}function cf(){window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))}function df(t,e){switch(t){case"projects":return s.jsx(Fm,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(Id,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(Hd,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(ep,{onItemSelect:e.onItemSelect});case"plugins":return s.jsx(Vp,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(sm,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(cu,{onItemSelect:e.onItemSelect});case"usage":return s.jsx($u,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(ag,{onItemSelect:e.onItemSelect});case"snippets":return s.jsx(lg,{onItemSelect:e.onItemSelect});default:return null}}function pf(t){return t==="page-content"?"page-sidebar":t}function mf(t){return t.pages.length>0}const Nf=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:Jh},Symbol.toStringTag,{value:"Module"}));export{Zo as A,Jh as S,Nf as a};