@vantran-se/openchamber-web 1.22.1 → 1.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +2 -3
  2. package/bin/cli.js +4 -1
  3. package/bin/cli.test.js +92 -0
  4. package/bin/lib/cli-startup.js +49 -0
  5. package/bin/lib/commands-startup.js +41 -6
  6. package/dist/assets/{CodeMirrorCommentWidgets-C53Q7pbX.js → CodeMirrorCommentWidgets-CV1HNV5l.js} +1 -1
  7. package/dist/assets/{DiffView-Dh1ey2x9.js → DiffView-DkkSa30n.js} +3 -3
  8. package/dist/assets/DirtyBranchSwitchDialog-DW4WaXPc.js +1 -0
  9. package/dist/assets/FilesView-DDu8zDy5.js +17 -0
  10. package/dist/assets/GitView-1Ixo8z-M.js +6 -0
  11. package/dist/assets/{JsonTreeView-Bl0lp9Rs.js → JsonTreeView-DvCLL7dT.js} +1 -1
  12. package/dist/assets/LinearIssuesView-Bs1rZrF2.js +1 -0
  13. package/dist/assets/{MarkdownImageGallery-bA0PS-tn.js → MarkdownImageGallery-DyJUc6h9.js} +1 -1
  14. package/dist/assets/MarkdownRendererImpl-Bdm8vMkS.js +12 -0
  15. package/dist/assets/{OnboardingScreen-D3kYJIb6.js → OnboardingScreen-Dg66B6oB.js} +1 -1
  16. package/dist/assets/{PatchDiff-D6NXAfJk.js → PatchDiff-CAduNjfZ.js} +1 -1
  17. package/dist/assets/{PierreDiffViewer-Ct2A13NO.js → PierreDiffViewer-CTIb1GYD.js} +2 -2
  18. package/dist/assets/PlanView-trDaszfq.js +5 -0
  19. package/dist/assets/SettingsView-DStMfBmy.js +28 -0
  20. package/dist/assets/{SettingsWindow-BiWDBRvb.js → SettingsWindow-DQQFnrSZ.js} +1 -1
  21. package/dist/assets/{ToolOutputDialog-BQexMQIm.js → ToolOutputDialog-SjY2XZlA.js} +6 -6
  22. package/dist/assets/ToolPartDiffPreview-DJdzUQPE.js +8 -0
  23. package/dist/assets/{VirtualizedFileDiff-Dpz2ra8h.js → VirtualizedFileDiff-Iehm4iMH.js} +1 -1
  24. package/dist/assets/{WalkthroughView-AX-u2pFg.js → WalkthroughView-BALp2d9O.js} +2 -2
  25. package/dist/assets/{computeVirtualFileMetrics-DtyozJdt.js → computeVirtualFileMetrics-BKZA43vN.js} +2 -2
  26. package/dist/assets/{contextPanelEmbeddedChat-C9EcRSDF.js → contextPanelEmbeddedChat-D2PM_pEv.js} +1 -1
  27. package/dist/assets/{de-DqVn5vme.js → de-DlSNLAcy.js} +6 -5
  28. package/dist/assets/{es-hj43Z53i.js → es-D1GbowZ3.js} +6 -5
  29. package/dist/assets/{fr-BmkZt2mF.js → fr-BPOLXIAY.js} +6 -5
  30. package/dist/assets/{index-DmhujXbT.js → index-Ce0LR32V.js} +1 -1
  31. package/dist/assets/index-D42fPvt4.css +1 -0
  32. package/dist/assets/index-DlFbCkEy.js +39 -0
  33. package/dist/assets/{isDiffPlainText-XyulMHxx.js → isDiffPlainText-DaB2u_Kv.js} +1 -1
  34. package/dist/assets/{isFilePlainText-B19Ddps1.js → isFilePlainText-yJZa2IAC.js} +1 -1
  35. package/dist/assets/{ja-DioMIEGF.js → ja-Dm2-m9io.js} +7 -6
  36. package/dist/assets/{ko-BqPgaQJb.js → ko-CIXlzQ5-.js} +7 -6
  37. package/dist/assets/main-B7qTsd_w.js +930 -0
  38. package/dist/assets/{main-B2a_JfKZ.js → main-CyQrD9dG.js} +2 -2
  39. package/dist/assets/{markdownCore-CWRCqSH2.js → markdownCore-CeEwGgEK.js} +2 -2
  40. package/dist/assets/{miniChat-B3CSU_Ps.js → miniChat-7cPEx4sV.js} +2 -2
  41. package/dist/assets/{mobile-QNcFIVCW.js → mobile-QtzkPTM8.js} +2 -2
  42. package/dist/assets/{patchFileDiff-BpMQZnYu.js → patchFileDiff-No55fDiD.js} +1 -1
  43. package/dist/assets/pl-B2zmkOpw.js +16 -0
  44. package/dist/assets/{pt-BR-BqH8fuCH.js → pt-BR-C-JE5H6y.js} +6 -5
  45. package/dist/assets/{renderElectronMiniChatApp-D77bmLqo.js → renderElectronMiniChatApp-ePTkBJNS.js} +2 -2
  46. package/dist/assets/renderMobileApp-D9RjB9DX.js +25 -0
  47. package/dist/assets/runtimeEndpointReset-DfJIWwwo.js +17 -0
  48. package/dist/assets/{scheduledTasksApi-BSRCtP6T.js → scheduledTasksApi-DuhdyYEa.js} +1 -1
  49. package/dist/assets/{shikiHighlight-DE-OwqGw.js → shikiHighlight-EHEg58-n.js} +1 -1
  50. package/dist/assets/tr-MJmRIzEY.js +7 -0
  51. package/dist/assets/{uk-BkkfxbOs.js → uk-BmD7eM8k.js} +6 -5
  52. package/dist/assets/{useAppFontEffects-COAeIX-D.js → useAppFontEffects-CuJPKtI1.js} +151 -180
  53. package/dist/assets/useInlineCommentController-DD7_7OP_.js +2 -0
  54. package/dist/assets/{useRootScrollLock-C0N9mCwz.js → useRootScrollLock-DRGAe8PN.js} +1 -1
  55. package/dist/assets/{vendor-codemirror-language-data-BG3v1Ghq.js → vendor-codemirror-language-data-9ZzoH0o0.js} +2 -2
  56. package/dist/assets/vendor-zod-CK21ihK-.js +39 -0
  57. package/dist/assets/{web-components-BNMwa0qm.js → web-components-PttKBrhi.js} +1 -1
  58. package/dist/assets/{zh-CN-C6FMdVgv.js → zh-CN-JJHl4ehT.js} +6 -5
  59. package/dist/assets/{zh-TW-CdcMjDxv.js → zh-TW-DPc4DEEW.js} +6 -5
  60. package/dist/index.html +5 -5
  61. package/dist/mini-chat.html +4 -4
  62. package/dist/mobile.html +4 -4
  63. package/package.json +8 -4
  64. package/server/index.js +38 -5
  65. package/server/lib/agent-tool/runtime.js +2 -19
  66. package/server/lib/changelog/update-notes.js +82 -0
  67. package/server/lib/changelog/update-notes.test.js +59 -0
  68. package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
  69. package/server/lib/dev-tunnel/runtime.js +4 -4
  70. package/server/lib/dev-tunnel/tunnel.test.js +20 -0
  71. package/server/lib/fs/DOCUMENTATION.md +2 -0
  72. package/server/lib/fs/routes.js +32 -21
  73. package/server/lib/fs/routes.test.js +77 -0
  74. package/server/lib/git/DOCUMENTATION.md +3 -1
  75. package/server/lib/git/routes.js +16 -0
  76. package/server/lib/git/service.js +107 -17
  77. package/server/lib/git/service.test.js +171 -0
  78. package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
  79. package/server/lib/mcp-reconnect/runtime.js +122 -0
  80. package/server/lib/mcp-reconnect/runtime.test.js +140 -0
  81. package/server/lib/message-queue/DOCUMENTATION.md +158 -0
  82. package/server/lib/message-queue/runtime.js +870 -0
  83. package/server/lib/message-queue/runtime.test.js +482 -0
  84. package/server/lib/openchamber-sessions/routes.js +102 -0
  85. package/server/lib/openchamber-sessions/routes.test.js +88 -0
  86. package/server/lib/opencode/DOCUMENTATION.md +13 -5
  87. package/server/lib/opencode/config-paths.test.js +116 -0
  88. package/server/lib/opencode/core-routes.js +1 -0
  89. package/server/lib/opencode/feature-routes-runtime.js +5 -0
  90. package/server/lib/opencode/input-history-scope.js +14 -0
  91. package/server/lib/opencode/managed-plugin-config.js +35 -0
  92. package/server/lib/opencode/openchamber-routes.test.js +2 -2
  93. package/server/lib/opencode/plugins.js +2 -2
  94. package/server/lib/opencode/providers.js +44 -2
  95. package/server/lib/opencode/providers.test.js +131 -4
  96. package/server/lib/opencode/routes.js +4 -4
  97. package/server/lib/opencode/server-startup-runtime.js +1 -1
  98. package/server/lib/opencode/settings-helpers.js +28 -0
  99. package/server/lib/opencode/settings-helpers.test.js +177 -0
  100. package/server/lib/opencode/settings-runtime.js +2 -2
  101. package/server/lib/opencode/settings-runtime.test.js +29 -0
  102. package/server/lib/opencode/shared.js +4 -1
  103. package/server/lib/opencode/shutdown-runtime.js +2 -0
  104. package/server/lib/opencode/skill-routes.js +2 -1
  105. package/server/lib/opencode/snippets.js +1 -2
  106. package/server/lib/package-manager.js +4 -29
  107. package/server/lib/package-manager.test.js +2 -2
  108. package/server/lib/quota/DOCUMENTATION.md +2 -1
  109. package/server/lib/quota/credentials/providers.js +4 -0
  110. package/server/lib/quota/credentials/store.js +1 -1
  111. package/server/lib/quota/credentials/store.test.js +4 -4
  112. package/server/lib/quota/providers/exe-dev.js +75 -0
  113. package/server/lib/quota/providers/exe-dev.test.js +47 -0
  114. package/server/lib/quota/providers/index.js +7 -0
  115. package/server/lib/quota/providers/opencode-go.js +1 -0
  116. package/server/lib/quota/providers/opencode-go.test.js +5 -1
  117. package/server/lib/quota/routes.js +2 -0
  118. package/server/lib/quota/utils/auth.js +1 -1
  119. package/server/lib/relay/DOCUMENTATION.md +1 -1
  120. package/server/lib/relay/host-client.test.js +9 -1
  121. package/server/lib/relay/tunnel-host.js +3 -1
  122. package/server/lib/relay/tunnel-host.test.js +9 -1
  123. package/server/lib/security/request-security.js +21 -6
  124. package/server/lib/security/request-security.test.js +42 -8
  125. package/server/lib/session-assist/runtime.js +1 -0
  126. package/server/lib/session-goal/DOCUMENTATION.md +20 -7
  127. package/server/lib/session-goal/create.js +3 -1
  128. package/server/lib/session-goal/runtime.js +77 -11
  129. package/server/lib/session-goal/runtime.test.js +426 -0
  130. package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
  131. package/server/lib/skills-catalog/install.js +3 -2
  132. package/server/lib/small-model/DOCUMENTATION.md +4 -0
  133. package/server/lib/small-model/call.js +8 -2
  134. package/server/lib/small-model/call.test.js +23 -0
  135. package/server/lib/small-model/index.js +2 -1
  136. package/server/lib/small-model/routes.js +2 -1
  137. package/server/lib/system-prompt/runtime.js +2 -21
  138. package/server/lib/terminal/DOCUMENTATION.md +11 -7
  139. package/server/lib/terminal/runtime.js +180 -26
  140. package/server/lib/terminal/runtime.test.js +553 -26
  141. package/server/lib/terminal/shells.js +17 -0
  142. package/server/lib/terminal/shells.test.js +32 -1
  143. package/server/lib/ui-auth/ui-auth.js +4 -1
  144. package/server/lib/ui-auth/ui-auth.test.js +16 -0
  145. package/server/lib/walkthrough/index.js +1 -0
  146. package/server/lib/walkthrough/routes.test.js +26 -5
  147. package/dist/assets/CommitSection-X-f2RgYr.js +0 -1
  148. package/dist/assets/FilesView-3ZYP72ki.js +0 -17
  149. package/dist/assets/GitView-CMuN7z2Z.js +0 -6
  150. package/dist/assets/LinearIssuesView-CQiUDU8b.js +0 -1
  151. package/dist/assets/MarkdownRendererImpl-BGQi2PLq.js +0 -12
  152. package/dist/assets/PlanView-6AUjzNQn.js +0 -5
  153. package/dist/assets/SettingsView-CHI8fFaK.js +0 -28
  154. package/dist/assets/ToolPartDiffPreview-DPAATNn6.js +0 -8
  155. package/dist/assets/index-L_ncV-6H.css +0 -1
  156. package/dist/assets/index-qES19dlJ.js +0 -7
  157. package/dist/assets/main-CYgSu6dx.js +0 -928
  158. package/dist/assets/pl-slULBF4R.js +0 -15
  159. package/dist/assets/renderMobileApp-BQ3Kdm-d.js +0 -25
  160. package/dist/assets/runtimeEndpointReset-CRGn1gVj.js +0 -16
  161. package/dist/assets/tr-CjEbw1Aw.js +0 -6
  162. package/dist/assets/useInlineCommentController-JsBboQwt.js +0 -2
  163. package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
@@ -0,0 +1,28 @@
1
+ import{R as o,j as s,f as gt,r as We}from"./vendor-react-BUCujlKS.js";import{f as it,B as H,I as R,o as Dn,b7 as ja,t as D,O as dc,fI as pc,es as _e,fJ as Et,b as Bs,h as ve,fK as mc,b3 as rn,b5 as on,fL as uc,b6 as ln,ej as Jn,fM as ul,fN as gc,fO as fa,fP as dn,c0 as Hs,bF as Kt,bG as zt,bH as _t,bI as $t,bJ as Vt,bK as ts,T as Je,fQ as $a,b2 as cn,e6 as rr,fR as hc,fS as Vn,eu as Jt,fT as Qs,l as Ze,eI as Lt,bT as It,bU as Pt,eF as Ft,bV as Rt,bW as At,bX as ot,fU as Wt,bY as As,du as Ka,eH as En,eK as ba,eJ as nn,fV as hs,dz as xs,fW as Cs,fX as fc,cn as ht,fY as gl,fZ as xc,f_ as Gn,f$ as hl,g0 as bc,g1 as va,fi as Vs,g2 as xa,g3 as fl,g4 as vr,dv as xl,g5 as qn,a6 as ya,a5 as Os,g6 as bl,g7 as Lr,ab as vc,e4 as vl,g as za,g8 as yc,g9 as Ys,e3 as jc,ga as wc,gb as kc,gc as yr,a7 as jr,a8 as wr,a9 as yl,gd as hn,a1 as Ni,bg as kr,N as Nr,ge as Or,ao as Nc,bZ as Sc,cD as Cc,R as Ic,Q as Pc,S as Ac,W as jl,gf as Tc,gg as Ec,bQ as Dc,b_ as or,gh as wl,aa as bi,gi as kl,P as Bn,gj as Js,er as Fs,ec as Nl,a0 as Mc,n as Zt,d_ as Si,x as Sl,w as Rc,i as Lc,j as Oc,d$ as Fc,p as Kc,gk as zc,gl as Uc,gm as Fr,dA as Cl,gn as _c,go as Vi,gp as Kr,gq as $c,gr as Vc,gs as Bc,gt as Hc,dG as Ci,gu as fs,gv as Ps,gw as en,gx as tn,av as Tn,aw as pa,gy as An,eE as Nn,gz as Va,gA as zr,gB as ma,gC as ua,bC as Qn,gD as Gc,gE as qc,gF as Wc,gG as Jc,gH as Bi,gI as Ur,gJ as Qc,gK as Yc,gL as Xc,gM as Zc,gN as _r,y as ed,m as $r,cR as td,gO as sd,gP as Hi,gQ as Vr,e1 as nd,gR as Pi,gS as ad,gT as id,gU as rd,gV as od,gW as ld,gX as Gi,co as cd,bD as Il,gY as Pl,gZ as dd,aq as Sn,as as pd}from"./useAppFontEffects-CuJPKtI1.js";import{r as ut,u as le,G as cs,d3 as md,d4 as Br,w as fn,az as xn,a0 as ud,a8 as vt,o as an,z as as,L as Hr,cl as Gr,cs as qr,S as Ia,p as gd,d5 as hd,j as fd,ck as ha,d6 as xd,aj as bd,cp as vd,d7 as yd,d8 as jd,s as wd,e as Ba,cq as kd,A as Ha,d9 as Al,Y as Nd,da as Sd,cV as Cd,X as Id,aJ as Wr,aY as ii,aK as Pd,db as Ad,a7 as Wn,dc as Td,v as Tl,dd as Jr,d2 as Qr,de as Yr,aH as Xr,df as Ed,dg as Dd,dh as Md,di as Rd,dj as Zr,b as Ld,aC as El,dk as Dl,dl as Od,dm as Fd,dn as Kd,dp as zd,dq as Ud,dr as _d,au as $d,i as Ml}from"./index-DlFbCkEy.js";import{u as Vd,U as eo,G as Yn,I as Xn,J as Zn,K as ea,d as Sr,A as Mn,F as Rn,E as Ln,a2 as Hn,Q as Bd,k as Is,a0 as Hd,a3 as Oa,a4 as Rl,L as Gd,M as qd}from"./runtimeEndpointReset-DfJIWwwo.js";import{u as Ks,c as Ll,d as Wd,p as Jd}from"./vendor-zustand-BAGL70zf.js";import{o as Qd,s as to,c as Yd}from"./vendor-zod-CK21ihK-.js";import{s as Xd,p as Zd}from"./vendor-yaml-3778uTud.js";import{c as so,s as ep,C as no,P as tp}from"./shikiHighlight-EHEg58-n.js";import{getResolvedShikiTheme as sp}from"./appThemeRegistry-BK0dHKa6.js";import{E as ao}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Ol}from"./vendor-qrcode-DTJ12-WC.js";const io=()=>{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 m=await ut("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!m.ok)return;const u=await m.json().catch(()=>null);if(!u||i)return;const x=typeof u.port=="number"&&Number.isFinite(u.port)&&u.port>0?u.port:null,d=typeof u.tunnelUrl=="string"&&u.tunnelUrl.trim().length>0?u.tunnelUrl.trim():null;a({port:x,tunnelUrl:d})}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:()=>{Dn(i.url)},children:[s.jsx(R,{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))})},ro="https://github.com/openchamber/openchamber",np="https://discord.gg/ZYRSdnwwKA",oo="https://x.com/openchamber_dev",ap=800,Fl=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=it(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,m]=o.useState(null),[u,x]=o.useState(null),d=Vd(Ks(C=>({info:C.info,checking:C.checking,available:C.available,error:C.error,downloading:C.downloading,downloaded:C.downloaded,progress:C.progress,runtimeType:C.runtimeType,checkForUpdates:C.checkForUpdates,downloadUpdate:C.downloadUpdate,restartToUpdate:C.restartToUpdate}))),{isMobile:v}=ja(),c=l||d.info?.currentVersion||"unknown";o.useEffect(()=>{let C=!1;return(async()=>{try{const S=await ut("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const g=await S.json().catch(()=>null),T=typeof g?.openchamberVersion=="string"&&g.openchamberVersion.trim().length>0?g.openchamberVersion.trim():null;C||m(T)}catch{C||m(null)}})(),()=>{C=!0}},[]),o.useEffect(()=>{let C=!1;return(async()=>{try{const S=await ut("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const g=await S.json().catch(()=>null),T=typeof g?.currentVersion=="string"&&g.currentVersion.trim().length>0?g.currentVersion.trim():null;C||x(T)}catch{C||x(null)}})(),()=>{C=!0}},[]);const N=o.useRef(!1);o.useEffect(()=>{if(d.checking)r(!0),N.current=!0;else if(i){const C=setTimeout(()=>{r(!1),N.current&&!d.available&&!d.error&&(D.success(e("settings.openchamber.about.toast.latestVersion")),N.current=!1)},ap);return()=>clearTimeout(C)}},[e,d.checking,i,d.available,d.error]);const f=d.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(dc,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${pc}`,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:c})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:u||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(io,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!d.available&&!d.error&&s.jsxs(H,{type:"button",variant:"outline",size:"sm",onClick:()=>d.checkForUpdates(),disabled:f,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[f?s.jsx(R,{name:"loader",className:"size-4 animate-spin"}):s.jsx(R,{name:"refresh",className:"size-4"}),e(f?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!f&&d.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(R,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:d.info?.version||""})]})]}),d.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:d.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:ro,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(R,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:np,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(R,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:oo,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(R,{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(eo,{open:a,onOpenChange:n,info:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]}):s.jsxs(_e,{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:Et,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Et,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:u||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[d.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(R,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!d.checking&&d.available&&s.jsxs(H,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(R,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:d.info?.version||""})]}),!d.checking&&!d.available&&!d.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:()=>d.checkForUpdates(),disabled:d.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),d.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:d.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:Et,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(io,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:ro,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(R,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:oo,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(R,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(eo,{open:a,onOpenChange:n,info:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]})},ip=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,Us=()=>{const t=gt.c(4),e=le(rp),a=Bs(op),n=Bs(lp);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=ip(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function rp(t){return t.settingsProjectPath}function op(t){return t.projects}function lp(t){return t.activeProjectId}const Kl=t=>t.trim(),Ga=t=>{const e=gt.c(40),{className:a}=t,{t:n}=it(),i=Bs(cp),r=Us(),l=le(dp),m=cs();let u;e[0]!==i?(u=[...i].sort(pp),e[0]=i,e[1]=u):u=e[1];const x=u;let d;e:{if(x.length===0){d=null;break e}let _;e[2]!==r||e[3]!==x?(_=x.find(w=>w.path===r)??x[0],e[2]=r,e[3]=x,e[4]=_):_=e[4],d=_}const v=d;if(m||x.length===0)return null;let c;e[5]!==v||e[6]!==n?(c=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]=c):c=e[7];const N=c;let f;e[8]!==N?(f=Kl(N),e[8]=N,e[9]=f):f=e[9];const C=f;let y;e[10]!==a?(y=ve(a),e[10]=a,e[11]=y):y=e[11];let S;e[12]!==n?(S=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=S):S=e[13];let g;e[14]!==n?(g=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=g):g=e[15];let T,M;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=ve("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"),M=s.jsx(R,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=T,e[17]=M):(T=e[16],M=e[17]);let P;e[18]!==C?(P=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:C}),e[18]=C,e[19]=P):P=e[19];let k;e[20]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(R,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=k):k=e[20];let h;e[21]!==P||e[22]!==S||e[23]!==g?(h=s.jsx(rn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":S,title:g,className:T,children:[M,P,k]})}),e[21]=P,e[22]=S,e[23]=g,e[24]=h):h=e[24];const j=v?.id??"";let F;e[25]!==l||e[26]!==x?(F=_=>{if(!_)return;const w=x.find(V=>V.id===_);w&&l(w.path)},e[25]=l,e[26]=x,e[27]=F):F=e[27];let A;e[28]!==x?(A=x.map(mp),e[28]=x,e[29]=A):A=e[29];let I;e[30]!==j||e[31]!==F||e[32]!==A?(I=s.jsx(on,{align:"start",className:"w-auto",children:s.jsx(uc,{value:j,onValueChange:F,children:A})}),e[30]=j,e[31]=F,e[32]=A,e[33]=I):I=e[33];let E;e[34]!==h||e[35]!==I?(E=s.jsxs(ln,{children:[h,I]}),e[34]=h,e[35]=I,e[36]=E):E=e[36];let B;return e[37]!==E||e[38]!==y?(B=s.jsx("div",{className:y,children:E}),e[37]=E,e[38]=y,e[39]=B):B=e[39],B};function cp(t){return t.projects}function dp(t){return t.setSettingsProjectPath}function pp(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function mp(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Kl(e);return s.jsx(mc,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function up(t,e){return`opencode:sidebar-group:${t}:${e}`}const lr=t=>{const e=gt.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,m=r===void 0?!0:r;let u;e[0]!==a||e[1]!==i?(u=up(i,a),e[0]=a,e[1]=i,e[2]=u):u=e[2];const x=u,d=o.useId();let v;e[3]!==m||e[4]!==x?(v=()=>{try{const I=localStorage.getItem(x);if(I!==null)return I==="true"}catch{}return m},e[3]=m,e[4]=x,e[5]=v):v=e[5];const[c,N]=We.useState(v);let f,C;e[6]!==c||e[7]!==x?(f=()=>{try{localStorage.setItem(x,String(c))}catch{}},C=[x,c],e[6]=c,e[7]=x,e[8]=f,e[9]=C):(f=e[8],C=e[9]),We.useEffect(f,C);let y;e[10]===Symbol.for("react.memo_cache_sentinel")?(y=()=>N(gp),e[10]=y):y=e[10];let S;e[11]===Symbol.for("react.memo_cache_sentinel")?(S=ve("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]=S):S=e[11];const g=!c&&"-rotate-90";let T;e[12]!==g?(T=ve("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",g),e[12]=g,e[13]=T):T=e[13];let M;e[14]!==T?(M=s.jsx(R,{name:"arrow-down-s",className:T}),e[14]=T,e[15]=M):M=e[15];let P;e[16]!==a?(P=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=P):P=e[17];let k;e[18]!==n?(k=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=k):k=e[19];let h;e[20]!==d||e[21]!==c||e[22]!==M||e[23]!==P||e[24]!==k?(h=s.jsxs("button",{type:"button",onClick:y,"aria-expanded":c,"aria-controls":d,className:S,children:[M,P,k]}),e[20]=d,e[21]=c,e[22]=M,e[23]=P,e[24]=k,e[25]=h):h=e[25];const j=!c;let F;e[26]!==l||e[27]!==d||e[28]!==j?(F=s.jsx("div",{id:d,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]=d,e[28]=j,e[29]=F):F=e[29];let A;return e[30]!==h||e[31]!==F?(A=s.jsxs("div",{children:[h,F]}),e[30]=h,e[31]=F,e[32]=A):A=e[32],A};function gp(t){return!t}const hp=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},fp=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())},lo=t=>{const e=fp(hp(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},xp=({onItemSelect:t})=>{const{t:e}=it(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,m]=o.useState(null),[u,x]=o.useState(null),[d,v]=o.useState(!1),[c,N]=o.useState(null),{selectedAgentName:f,setSelectedAgent:C,setAgentDraft:y,createAgent:S,deleteAgent:g,loadAgents:T}=Jn(Ks(z=>({selectedAgentName:z.selectedAgentName,setSelectedAgent:z.setSelectedAgent,setAgentDraft:z.setAgentDraft,createAgent:z.createAgent,deleteAgent:z.deleteAgent,loadAgents:z.loadAgents}))),M=Us(),P=Jn(z=>ul(z,M));o.useEffect(()=>{T(M)},[T,M]);const k="bg-background",h=()=>{const z="new-agent";let re=z,$=1;for(;P.some(U=>U.name===re);)re=`${z}-${$}`,$++;y({name:re,scope:"user"}),C(re),t?.()},j=async z=>{if(fa(z)){D.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}m(z),x("delete")},F=async z=>{fa(z)&&(m(z),x("reset"))},A=()=>{m(null),x(null)},I=async()=>{if(!(!l||!u)){v(!0);try{const z=await g(l.name,l.scope,M);z.ok?(z.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):z.restartDeferred?D.success(e("settings.view.pendingRestart.saved")):u==="delete"?D.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):D.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),A()):u==="delete"?D.error(e("settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(z){const re=z instanceof Error?z.message:"",$=/built-in|not deletable|not found/i.test(re);u==="delete"?D.error(e($?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}v(!1)}},E=z=>{const re=z.name;let $=1,U=`${re}-copy`;for(;P.some(X=>X.name===U);)$++,U=`${re}-copy-${$}`;const K=z,O=z.model?.providerID&&z.model?.modelID?`${z.model.providerID}/${z.model.modelID}`:null,Y=z;y({name:U,scope:K.scope||"user",description:z.description,model:O,variant:z.variant,temperature:z.temperature,top_p:z.topP,prompt:z.prompt,mode:z.mode,permission:lo(z.permission),disable:Y.disable}),C(U),t?.()},B=z=>{r(z.name),n(z)},_=async()=>{if(!a)return;const z=i.trim().replace(/\s+/g,"-");if(!z){D.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(z===a.name){n(null);return}if(P.some(K=>K.name===z)){D.error(e("settings.agents.sidebar.toast.agentExists"));return}const re=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,$=a,U=await S({name:z,description:a.description,model:re,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:lo(a.permission),disable:$.disable,scope:$.scope},M);if(U.ok){const K=await g(a.name,$.scope,M);K.ok?(U.requiresManualRestart||K.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):D.success(e("settings.agents.sidebar.toast.agentRenamed",{name:z})),C(z)):D.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else D.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},w=z=>{switch(z){case"primary":return s.jsx(R,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(R,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(R,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},V=P.filter(z=>!gc(z)),W=V.filter(fa),L=V.filter(z=>!fa(z)),{groupedCustomAgents:Q,ungroupedCustomAgents:ne}=We.useMemo(()=>{const z={},re=[];for(const U of L){const K=U;K.group?(z[K.group]||(z[K.group]=[]),z[K.group].push(U)):re.push(U)}return{groupedCustomAgents:Object.keys(z).sort((U,K)=>U.localeCompare(K)).map(U=>({name:U,agents:z[U]})),ungroupedCustomAgents:re}},[L]);return s.jsxs("div",{className:ve("flex h-full flex-col",k),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${dn} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Ga,{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:V.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:h,children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:V.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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(z=>s.jsx(qi,{agent:z,isSelected:f===z.name,onSelect:()=>{C(z.name),t?.()},onReset:()=>F(z),onDuplicate:()=>E(z),getAgentModeIcon:w,isMenuOpen:c===z.name,onMenuOpenChange:re=>N(re?z.name:null)},z.name))]}),L.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")}),Q.map(({name:z,agents:re})=>s.jsx(lr,{label:z,count:re.length,storageKey:"agents",children:re.map($=>s.jsx(qi,{agent:$,isSelected:f===$.name,onSelect:()=>{C($.name),t?.()},onRename:()=>B($),onDelete:()=>j($),onDuplicate:()=>E($),getAgentModeIcon:w,isMenuOpen:c===$.name,onMenuOpenChange:U=>N(U?$.name:null)},$.name))},z)),ne.map(z=>s.jsx(qi,{agent:z,isSelected:f===z.name,onSelect:()=>{C(z.name),t?.()},onRename:()=>B(z),onDelete:()=>j(z),onDuplicate:()=>E(z),getAgentModeIcon:w,isMenuOpen:c===z.name,onMenuOpenChange:re=>N(re?z.name:null)},z.name))]})]})}),s.jsx(Kt,{open:l!==null&&u!==null,onOpenChange:z=>{!z&&!d&&A()},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:e(u==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Vt,{children:u==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:A,disabled:d,children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:I,disabled:d,children:e(u==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Kt,{open:a!==null,onOpenChange:z=>!z&&n(null),children:s.jsxs(zt,{children:[s.jsxs(_t,{children:[s.jsx($t,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Vt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(Je,{value:i,onChange:z=>r(z.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:z=>{z.key==="Enter"&&_()}}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:_,children:e("settings.common.actions.rename")})]})]})})]})},qi=t=>{const e=gt.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:m,onDuplicate:u,getAgentModeIcon:x,isMenuOpen:d,onMenuOpenChange:v}=t,{t:c}=it(),N=a;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=$a(),e[0]=f):f=e[0];const C=f,[y,S]=o.useState(!1);let g;e[1]!==r||e[2]!==u||e[3]!==m||e[4]!==l||e[5]!==c?(g=re=>s.jsxs(s.Fragment,{children:[m&&s.jsxs(re,{onClick:$=>{$.stopPropagation(),m()},children:[s.jsx(R,{name:"edit",className:"h-4 w-4 mr-px"}),c("settings.common.actions.rename")]}),s.jsxs(re,{onClick:$=>{$.stopPropagation(),u()},children:[s.jsx(R,{name:"file-copy",className:"h-4 w-4 mr-px"}),c("settings.common.actions.duplicate")]}),l&&s.jsxs(re,{onClick:$=>{$.stopPropagation(),l()},children:[s.jsx(R,{name:"restart",className:"h-4 w-4 mr-px"}),c("settings.common.actions.reset")]}),r&&s.jsxs(re,{onClick:$=>{$.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),c("settings.common.actions.delete")]})]}),e[1]=r,e[2]=u,e[3]=m,e[4]=l,e[5]=c,e[6]=g):g=e[6];const T=g,M=n?"bg-interactive-selection":"hover:bg-interactive-hover";let P;e[7]!==M?(P=ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",M),e[7]=M,e[8]=P):P=e[8];let k;e[9]===Symbol.for("react.memo_cache_sentinel")?(k=C?void 0:re=>{re.preventDefault(),S(!0)},e[9]=k):k=e[9];let h;e[10]!==P?(h=s.jsx("div",{className:P,onContextMenu:k}),e[10]=P,e[11]=h):h=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 F;e[14]!==a.mode||e[15]!==x?(F=x(a.mode),e[14]=a.mode,e[15]=x,e[16]=F):F=e[16];let A;e[17]!==a||e[18]!==N.scope||e[19]!==c?(A=(N.scope||fa(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:fa(a)?c("settings.agents.sidebar.badge.system"):N.scope}),e[17]=a,e[18]=N.scope,e[19]=c,e[20]=A):A=e[20];let I;e[21]!==j||e[22]!==F||e[23]!==A?(I=s.jsxs("div",{className:"flex items-center gap-1.5",children:[j,F,A]}),e[21]=j,e[22]=F,e[23]=A,e[24]=I):I=e[24];let E;e[25]!==a.description?(E=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=E):E=e[26];let B;e[27]!==i||e[28]!==I||e[29]!==E?(B=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:[I,E]}),e[27]=i,e[28]=I,e[29]=E,e[30]=B):B=e[30];let _;e[31]!==v?(_=re=>{re&&S(!1),v(re)},e[31]=v,e[32]=_):_=e[32];let w;e[33]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(rn,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=w):w=e[33];let V;e[34]!==T?(V=s.jsx(on,{align:"end",className:"w-fit min-w-20",children:T(cn)}),e[34]=T,e[35]=V):V=e[35];let W;e[36]!==d||e[37]!==_||e[38]!==V?(W=s.jsxs(ln,{open:d,onOpenChange:_,children:[w,V]}),e[36]=d,e[37]=_,e[38]=V,e[39]=W):W=e[39];let L;e[40]!==B||e[41]!==W?(L=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[B,W]}),e[40]=B,e[41]=W,e[42]=L):L=e[42];let Q;e[43]!==L||e[44]!==h?(Q=s.jsx(Zn,{render:h,children:L}),e[43]=L,e[44]=h,e[45]=Q):Q=e[45];let ne;e[46]!==T?(ne=s.jsx(Yn,{className:"w-fit min-w-20",children:T(Xn)}),e[46]=T,e[47]=ne):ne=e[47];let z;return e[48]!==y||e[49]!==Q||e[50]!==ne?(z=s.jsxs(ea,{open:y,onOpenChange:S,children:[Q,ne]}),e[48]=y,e[49]=Q,e[50]=ne,e[51]=z):z=e[51],z},es=t=>{const e=gt.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:m,description:u,headerEnd:x,showSaveStatus:d}=t,v=d===void 0?!1:d,c=r!=null||u!=null||x!=null||v,N=typeof r=="string"||typeof r=="number",f=l!=null||m!=null;let C;e[0]!==i?(C=ve("h-full",i),e[0]=i,e[1]=C):C=e[1];let y;e[2]!==n?(y=ve("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]=y):y=e[3];let S;e[4]!==u||e[5]!==c||e[6]!==f||e[7]!==x||e[8]!==N||e[9]!==v||e[10]!==r||e[11]!==m||e[12]!==l?(S=c&&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?N?f?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:ve(rr,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:m})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:rr,children:r}):r:null,u!=null?typeof u=="string"||typeof u=="number"?s.jsx("p",{className:hc,children:u}):u:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[x,v&&s.jsx(vp,{})]})]}),e[4]=u,e[5]=c,e[6]=f,e[7]=x,e[8]=N,e[9]=v,e[10]=r,e[11]=m,e[12]=l,e[13]=S):S=e[13];let g;e[14]!==a||e[15]!==y||e[16]!==S?(g=s.jsxs("div",{className:y,children:[S,a]}),e[14]=a,e[15]=y,e[16]=S,e[17]=g):g=e[17];let T;return e[18]!==C||e[19]!==g?(T=s.jsx(Hs,{outerClassName:C,className:"w-full @container",children:g}),e[18]=C,e[19]=g,e[20]=T):T=e[20],T},bp=500,vp=()=>{const t=gt.c(13),{t:e}=it(),a=o.useSyncExternalStore(md,Br,Br),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const d=setTimeout(()=>i(!0),bp);return()=>clearTimeout(d)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let d;t[3]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(R,{name:"error-warning",className:"size-3.5"}),t[3]=d):d=t[3];let v;t[4]!==e?(v=e("settings.common.status.saveFailed"),t[4]=e,t[5]=v):v=t[5];let c;return t[6]!==v?(c=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[d,s.jsx("span",{children:v})]}),t[6]=v,t[7]=c):c=t[7],c}if(a!=="saving"||!n)return null;let m;t[8]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=m):m=t[8];let u;t[9]!==e?(u=e("settings.common.actions.saving"),t[9]=e,t[10]=u):u=t[10];let x;return t[11]!==u?(x=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[m,s.jsx("span",{children:u})]}),t[11]=u,t[12]=x):x=t[12],x},yp=["allow","ask","deny"],Fa=t=>t==="allow"||t==="ask"||t==="deny",cr=()=>({global:null,keys:{}}),jp=t=>{const e=cr();if(t==null)return e;if(typeof t=="string")return Fa(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Fa(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(Fa(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))Fa(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},dr=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},wp=(t,e)=>JSON.stringify(dr(t))===JSON.stringify(dr(e)),Cn=t=>JSON.parse(JSON.stringify(t)),kp=["edit","external_directory","doom_loop","plan_enter","plan_exit"],Np=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),co=new Set(["write","patch","apply_patch","multiedit","invalid"]),Sp=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),Cp=({agent:t})=>{const{t:e}=it(),a=Jn(K=>K.updateAgent),[n,i]=o.useState(cr),[r,l]=o.useState(cr),[m,u]=o.useState(!0),[x,d]=o.useState(!1),[v,c]=o.useState(!1),[N,f]=o.useState({}),[C,y]=o.useState([]),[S,g]=o.useState(""),[T,M]=o.useState(0),P=t.name,k=Us();o.useEffect(()=>{let K=!1;return u(!0),d(!1),(async()=>{try{const O=k,Y=O?`?directory=${encodeURIComponent(O)}`:"",X=await ut(`/api/config/agents/${encodeURIComponent(P)}/config${Y}`,{headers:{"Cache-Control":"no-cache",...O?{"x-opencode-directory":O}:{}}});if(!X.ok)throw new Error(String(X.status));const ee=await X.json().catch(()=>null);if(K)return;const ge=jp(ee?.config?.permission);i(Cn(ge)),l(ge)}catch{K||d(!0)}finally{K||u(!1)}})(),()=>{K=!0}},[P,T,k]),o.useEffect(()=>{let K=!1;return(async()=>{try{const O=await fn.listToolIds({directory:k});!K&&Array.isArray(O)&&y(O.filter(Y=>typeof Y=="string"&&!co.has(Y)))}catch{}})(),()=>{K=!0}},[P,k]);const h=o.useMemo(()=>{const K=t.permission;if(!Array.isArray(K))return[];const O=[];for(const Y of K){if(!Y||typeof Y!="object")continue;const{permission:X,pattern:ee,action:ge}=Y;typeof X=="string"&&typeof ee=="string"&&Fa(ge)&&O.push({permission:X,pattern:ee,action:ge})}return O},[t]),j=o.useCallback(K=>{const O=h.find(X=>X.permission===K&&X.pattern==="*");if(O)return O.action;const Y=h.find(X=>X.permission==="*"&&X.pattern==="*");return Y?Y.action:null},[h]),F=o.useCallback(K=>{const O=r.keys[K]?.patterns??[],Y=new Set(O.map(X=>X.pattern));return h.filter(X=>X.permission===K&&X.pattern!=="*"&&!Y.has(X.pattern))},[h,r.keys]),A=o.useMemo(()=>{const K=new Set;for(const O of C)K.add(O);for(const O of kp)K.add(O);for(const O of Object.keys(r.keys))K.add(O);for(const O of co)K.delete(O);return Array.from(K).sort((O,Y)=>O.localeCompare(Y))},[C,r.keys]),I=o.useMemo(()=>!wp(r,n),[r,n]),E=K=>{l(O=>({...O,global:K}))},B=(K,O)=>{l(Y=>{const X=Cn(Y),ee=X.keys[K]??{action:null,patterns:[]};return ee.action=O,ee.action===null&&ee.patterns.length===0?delete X.keys[K]:X.keys[K]=ee,X})},_=(K,O,Y,X)=>{l(ee=>{const ge=Cn(ee),de=ge.keys[K]??{action:null,patterns:[]};return de.patterns[O]={pattern:Y,action:X},ge.keys[K]=de,ge})},w=K=>{l(O=>{const Y=Cn(O),X=Y.keys[K]??{action:null,patterns:[]};return X.patterns.push({pattern:"",action:"allow"}),Y.keys[K]=X,Y}),f(O=>({...O,[K]:!0}))},V=(K,O)=>{l(Y=>{const X=Cn(Y),ee=X.keys[K];return ee?(ee.patterns.splice(O,1),ee.action===null&&ee.patterns.length===0&&delete X.keys[K],X):Y})},W=()=>{const K=S.trim();!K||K==="*"||(l(O=>{if(O.keys[K])return O;const Y=Cn(O);return Y.keys[K]={action:"ask",patterns:[]},Y}),f(O=>({...O,[K]:!0})),g(""))},L=async()=>{c(!0);try{const K=dr(r),O=await a(P,{permission:K});O.ok?(i(Cn(r)),D.success(O.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):D.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{c(!1)}},Q=()=>{l(Cn(n))},ne=K=>e(K==="allow"?"settings.agents.page.permissionsEditor.action.allow":K==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),z=e("settings.agents.page.permissionsEditor.action.inherit"),re=e("settings.agents.page.permissionsEditor.action.default"),$=K=>[...K?[{value:"inherit",label:K}]:[],...yp.map(O=>({value:O,label:ne(O)}))],U=(K,O,Y,X=z)=>s.jsx(Qs,{value:K??"inherit",options:$(X),onChange:ee=>O(ee==="inherit"?null:ee),"aria-label":Y});return m?s.jsx(_e,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:Vn,children:e("common.loading")})}):x?s.jsx(_e,{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:()=>M(K=>K+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(_e,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:I?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:Q,disabled:v,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(H,{size:"xs",className:"!font-normal",onClick:()=>{L()},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:Et,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Jt,{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:ne(j("*")??"allow")})})]}),U(r.global,E,e("settings.agents.page.permissionsEditor.defaultAria"),re)]}),s.jsx("div",{children:A.map(K=>{const O=r.keys[K]??{action:null,patterns:[]},Y=F(K),X=Np.has(K)||O.patterns.length>0,ee=X||Y.length>0,ge=N[K]===!0,de=j(K);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:ee?()=>f(xe=>({...xe,[K]:!ge})):void 0,className:ve("flex min-w-0 items-center gap-1.5 text-left",!ee&&"cursor-default"),"aria-expanded":ee?ge:void 0,children:[s.jsx(R,{name:ge&&ee?"arrow-down-s":"arrow-right-s",className:ve("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ee&&"opacity-0")}),s.jsx("span",{className:Et,children:Sp(K)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:K}),O.action===null&&de!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:ne(de)})}),O.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(O.patterns.length)})})]}),U(O.action,xe=>B(K,xe),e("settings.agents.page.permissionsEditor.keyAria",{key:K}))]}),ge&&ee&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[O.patterns.map((xe,ae)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(Je,{value:xe.pattern,onChange:te=>_(K,ae,te.target.value,xe.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(Qs,{value:xe.action,options:$(),onChange:te=>_(K,ae,xe.pattern,te),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:K})}),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:()=>V(K,ae),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]},ae)),X&&s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>w(K),children:[s.jsx(R,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),Y.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(Jt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),Y.map(xe=>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:xe.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:ne(xe.action)})]},`${xe.pattern}-${xe.action}`))]})]})]},K)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(Je,{value:S,onChange:K=>g(K.target.value),onKeyDown:K=>{K.key==="Enter"&&(K.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:!S.trim(),children:[s.jsx(R,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},Ip=(t,e)=>{const a=ba(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):[]},Pp=()=>{const{t}=it(),e=Ze(U=>U.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agentDraft:l,setAgentDraft:m}=Jn(Ks(U=>({selectedAgentName:U.selectedAgentName,getAgentByName:U.getAgentByName,createAgent:U.createAgent,updateAgent:U.updateAgent,agentDraft:U.agentDraft,setAgentDraft:U.setAgentDraft}))),u=Us(),x=Jn(U=>ul(U,u)),d=a?n(a,u):null,v=!!(l&&l.name===a&&!d),[c,N]=o.useState(""),[f,C]=o.useState("user"),[y,S]=o.useState(""),[g,T]=o.useState("subagent"),[M,P]=o.useState(""),[k,h]=o.useState(""),[j,F]=o.useState(void 0),[A,I]=o.useState(void 0),[E,B]=o.useState(""),[_,w]=o.useState(!1),V=o.useRef(null),W=o.useMemo(()=>Ip(e,M),[M,e]),L=W.length>0,Q=k||"__default",ne=L,z=o.useMemo(()=>k&&!W.includes(k)?[k,...W]:W,[k,W]);o.useEffect(()=>{if(v&&l){const U=l.name||"",K=l.scope||"user",O=l.description||"",Y=l.mode||"subagent",X=l.model||"",ee=l.variant||"",ge=l.temperature??void 0,de=l.top_p??void 0,xe=l.prompt||"";N(U),C(K),S(O),T(Y),P(X),h(ee),F(ge),I(de),B(xe),V.current={draftName:U,draftScope:K,description:O,mode:Y,model:X,variant:ee,temperature:ge,topP:de,prompt:xe};return}if(d&&a===d.name){const U=d.description||"",K=d.mode||"subagent",O=d.model?.providerID&&d.model?.modelID?`${d.model.providerID}/${d.model.modelID}`:"",Y=d.variant||"",X=d.temperature??void 0,ee=d.topP??void 0,ge=d.prompt||"";S(U),T(K),P(O),h(Y),F(X),I(ee),B(ge),V.current={draftName:"",draftScope:"user",description:U,mode:K,model:O,variant:Y,temperature:X,topP:ee,prompt:ge}}},[l,v,d,a]);const re=o.useMemo(()=>{const U=V.current;return U?!!(v&&(c!==U.draftName||f!==U.draftScope)||y!==U.description||g!==U.mode||M!==U.model||k!==U.variant||j!==U.temperature||A!==U.topP||E!==U.prompt):!1},[y,c,f,v,g,M,E,j,A,k]),$=async()=>{const U=v?c.trim().replace(/\s+/g,"-"):a?.trim();if(!U){D.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(v&&x.some(K=>K.name===U)){D.error(t("settings.agents.sidebar.toast.agentExists"));return}w(!0);try{const K=M.trim(),O=k.trim(),Y=E.trim(),X={name:U,...y.trim()?{description:y.trim()}:{},mode:g,model:K===""?null:K,variant:O===""?null:O||void 0,temperature:j??null,top_p:A??null,prompt:Y||(v?void 0:null),...v&&f?{scope:f}:{}};let ee;v?(ee=await i(X,u),ee.ok&&m(null)):ee=await r(U,X,u),ee.ok?ee.requiresManualRestart?D.warning(t("settings.agents.page.toast.savedManualRestart")):ee.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(t(v?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):D.error(t(v?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(K){console.error("Error saving agent:",K);const O=K instanceof Error&&K.message?K.message:t("settings.agents.page.toast.saveUnexpectedError");D.error(O)}finally{w(!1)}};return a?s.jsxs(es,{title:v?t("settings.agents.page.title.new"):a,description:t(v?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(_e,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[v&&s.jsxs(Lt,{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(Je,{value:c,onChange:U=>N(U.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(It,{value:f,onValueChange:U=>C(U),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Wt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(As,{value:y,onChange:U=>S(U.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Wt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Qs,{"aria-label":t("settings.agents.page.field.mode"),value:g,onChange:T,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(_e,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Lt,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Ka,{providerId:ba(M)?.providerId??"",modelId:ba(M)?.modelId??"",onChange:(U,K)=>{P(U&&K?`${U}/${K}`:""),h("")},className:En})}),s.jsx(Lt,{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:ne?s.jsxs(It,{value:Q,onValueChange:U=>h(U==="__default"?"":U),children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:U=>U==="__default"?t("chat.modelControls.default"):U})}),s.jsxs(At,{children:[s.jsx(ot,{value:"__default",children:t("chat.modelControls.default")}),z.map(U=>s.jsx(ot,{value:U,children:U},U))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Je,{value:k,onChange:U=>h(U.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!M&&!k,className:"h-8 w-40 rounded-md px-3"}),k&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>h(""),className:hs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Lt,{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(xs,{value:j,fallbackValue:.7,onValueChange:F,onClear:()=>F(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Cs}),j!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(void 0),className:hs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Lt,{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(xs,{value:A,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Cs}),A!==void 0&&s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(void 0),className:hs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(R,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(_e,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(As,{value:E,onChange:U=>B(U.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"})}),!v&&d&&s.jsx(Cp,{agent:d}),s.jsx("div",{className:"pb-8",children:s.jsx(H,{onClick:$,disabled:_||!re,size:"xs",className:"!font-normal",children:t(_?"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(R,{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")})]})})},Ap=Qd({content:to(),exists:Yd(),path:to().min(1).optional()}),zl=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},Tp=t=>t.length>0&&!t.endsWith(`
2
+ `)?`${t}
3
+ `:t,ri={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},Ep=(t,e)=>t==="custom"?e:bc(t),Dp=t=>t==="custom"?"custom":gl(t)?t:"concise",po={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"},Wi=async(t,e)=>{xn("saving");try{const a=await ut("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(await zl(a,e));xn("saved")}catch(a){throw xn("error"),a}},Mp=()=>{const{t}=it(),e=fc(),[a,n]=o.useState(""),[i,r]=o.useState("AGENTS.md"),[l,m]=o.useState(!1),[u,x]=o.useState(ri.responseStyleEnabled),[d,v]=o.useState(ri.responseStylePreset),[c,N]=o.useState(ri.responseStyleCustomInstructions),[f,C]=o.useState(!0),[y,S]=o.useState(!1),[g,T]=o.useState(!1),[M,P]=o.useState(""),[k,h]=o.useState(!1),j=o.useRef(null);o.useEffect(()=>{const _=new AbortController;return(async()=>{try{const[V,W]=await Promise.all([ut("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:_.signal}),ut("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:_.signal})]);let L=ri;if(V.ok){const Q=await V.json();L={...L,optimizeSystemPrompt:Q.optimizeSystemPrompt===!0,responseStyleEnabled:Q.responseStyleEnabled===!0,responseStylePreset:Dp(Q.responseStylePreset),responseStyleCustomInstructions:typeof Q.responseStyleCustomInstructions=="string"?Q.responseStyleCustomInstructions:""},typeof Q.globalBehaviorPrompt=="string"&&(L={...L,prompt:Q.globalBehaviorPrompt})}if(W.ok){const Q=Ap.parse(await W.json());if(_.signal.aborted)return;r(Q.path??"AGENTS.md"),L.prompt.trim()||(L={...L,prompt:Q.content})}n(L.prompt),m(L.optimizeSystemPrompt),h(L.optimizeSystemPrompt),x(L.responseStyleEnabled),v(L.responseStylePreset),N(L.responseStyleCustomInstructions),P(L.prompt),j.current={enabled:L.responseStyleEnabled,preset:L.responseStylePreset,custom:L.responseStyleCustomInstructions}}catch(V){V.name!=="AbortError"&&console.warn("Failed to load behavior settings:",V)}finally{C(!1)}})(),()=>_.abort()},[]),o.useEffect(()=>{if(f)return;const _=j.current;if(_&&_.enabled===u&&_.preset===d&&_.custom===c)return;const w={enabled:u,preset:d,custom:c},V=setTimeout(async()=>{try{await Wi({responseStyleEnabled:w.enabled,responseStylePreset:w.preset,responseStyleCustomInstructions:w.custom},t("settings.behavior.page.toast.saveFailed")),j.current=w}catch(W){const L=W instanceof Error?W.message:t("settings.behavior.page.toast.saveFailed");D.error(L)}},400);return()=>clearTimeout(V)},[u,d,c,f,t]);const F=Ep(d,c),A=a!==M,I=l!==k,E=async()=>{S(!0);try{const _=Tp(a),w=await ut("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:_})});if(!w.ok)throw new Error(await zl(w,t("settings.behavior.page.toast.saveFailed")));const V=await w.json().catch(()=>null),W=hl(V,"behavior",{id:"agents-md"});await Wi({globalBehaviorPrompt:_},t("settings.behavior.page.toast.saveFailed")),n(_),P(_),D.success(t(W?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(_){console.error("Failed to save behavior:",_);const w=_ instanceof Error?_.message:t("settings.behavior.page.toast.saveFailed");D.error(w)}finally{S(!1)}},B=async()=>{T(!0);try{await Wi({optimizeSystemPrompt:l},t("settings.behavior.page.toast.saveFailed")),h(l),Gn("behavior",{id:"optimize-system-prompt"}),D.success(t("settings.view.pendingRestart.saved"))}catch(_){const w=_ instanceof Error?_.message:t("settings.behavior.page.toast.saveFailed");D.error(w)}finally{T(!1)}};return s.jsxs(es,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(_e,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(ht,{checked:l,onChange:m,disabled:f||g,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:()=>{B()},disabled:f||g||!I,className:"!font-normal",children:t(g?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(_e,{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:i})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(As,{value:a,onChange:_=>n(_.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:f,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(H,{onClick:E,disabled:y||!A||f,size:"xs",className:"!font-normal",children:t(y?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(_e,{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(ht,{checked:u,onChange:x,disabled:f,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Lt,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(It,{value:d,onValueChange:_=>v(_),disabled:f||!u,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{children:_=>_==="custom"?t("settings.behavior.page.responseStyle.option.custom"):gl(_)?t(po[_]):null})}),s.jsxs(At,{children:[xc.map(_=>s.jsx(ot,{value:_,children:t(po[_])},_)),s.jsx(ot,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(As,{value:F,onChange:_=>N(_.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:f||!u||d!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},Rp=t=>{const e=gt.c(176),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,m]=o.useState(""),[u,x]=o.useState(null),[d,v]=o.useState(null),[c,N]=o.useState(!1),[f,C]=o.useState(null),{selectedCommandName:y,setSelectedCommand:S,setCommandDraft:g,createCommand:T,deleteCommand:M,loadCommands:P}=va(Ks(Lp)),k=Us();let h;e[0]!==k?(h=ze=>fl(ze,k),e[0]=k,e[1]=h):h=e[1];const j=va(h);let F;e[2]!==k?(F=ze=>vr(ze,k),e[2]=k,e[3]=F):F=e[3];const A=Vs(F),I=Vs(Op);let E,B;e[4]!==P||e[5]!==I||e[6]!==k?(E=()=>{P(k),I(k)},B=[P,I,k],e[4]=P,e[5]=I,e[6]=k,e[7]=E,e[8]=B):(E=e[7],B=e[8]),o.useEffect(E,B);let _;e[9]!==A?(_=new Set(A.map(Fp)),e[9]=A,e[10]=_):_=e[10];const w=_;let V;if(e[11]!==j||e[12]!==w){let ze;e[14]!==w?(ze=wt=>!w.has(wt.name),e[14]=w,e[15]=ze):ze=e[15],V=j.filter(ze),e[11]=j,e[12]=w,e[13]=V}else V=e[13];const W=V;let L,Q;e[16]!==y||e[17]!==S||e[18]!==w?(L=()=>{y&&w.has(y)&&S(null)},Q=[y,S,w],e[16]=y,e[17]=S,e[18]=w,e[19]=L,e[20]=Q):(L=e[19],Q=e[20]),o.useEffect(L,Q);let ne;e[21]!==j||e[22]!==a||e[23]!==g||e[24]!==S?(ne=()=>{let ze="new-command",wt=1;for(;j.some(Ee=>Ee.name===ze);)ze=`new-command-${wt}`,wt++;g({name:ze,scope:"user"}),S(ze),a?.()},e[21]=j,e[22]=a,e[23]=g,e[24]=S,e[25]=ne):ne=e[25];const z=ne;let re;e[26]!==n?(re=async ze=>{if(xa(ze)){D.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}x(ze),v("delete")},e[26]=n,e[27]=re):re=e[27];const $=re;let U;e[28]===Symbol.for("react.memo_cache_sentinel")?(U=async ze=>{xa(ze)&&(x(ze),v("reset"))},e[28]=U):U=e[28];const K=U;let O;e[29]===Symbol.for("react.memo_cache_sentinel")?(O=()=>{x(null),v(null)},e[29]=O):O=e[29];const Y=O;let X;e[30]!==u||e[31]!==d||e[32]!==M||e[33]!==k||e[34]!==n?(X=async()=>{if(!u||!d)return;N(!0),await M(u.name,k)?(d==="delete"?D.success(n("settings.commands.sidebar.toast.commandDeleted",{name:u.name})):D.success(n("settings.commands.sidebar.toast.commandReset",{name:u.name})),Y()):d==="delete"?D.error(n("settings.commands.sidebar.toast.deleteFailed")):D.error(n("settings.commands.sidebar.toast.resetFailed")),N(!1)},e[30]=u,e[31]=d,e[32]=M,e[33]=k,e[34]=n,e[35]=X):X=e[35];const ee=X;let ge;e[36]!==j||e[37]!==g||e[38]!==S?(ge=ze=>{const wt=ze.name;let Ee=1,jt=`${wt}-copy`;for(;j.some(J=>J.name===jt);)Ee++,jt=`${wt}-copy-${Ee}`;g({name:jt,scope:ze.scope||"user",description:ze.description,template:ze.template,agent:ze.agent,model:ze.model}),S(jt)},e[36]=j,e[37]=g,e[38]=S,e[39]=ge):ge=e[39];const de=ge;let xe;e[40]===Symbol.for("react.memo_cache_sentinel")?(xe=ze=>{m(ze.name),r(ze)},e[40]=xe):xe=e[40];const ae=xe;let te;e[41]!==j||e[42]!==T||e[43]!==M||e[44]!==i||e[45]!==l||e[46]!==S||e[47]!==k||e[48]!==n?(te=async()=>{if(!i)return;const ze=l.trim().replace(/\s+/g,"-");if(!ze){D.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(ze===i.name){r(null);return}if(j.some(Ee=>Ee.name===ze)){D.error(n("settings.commands.sidebar.toast.commandExists"));return}await T({name:ze,description:i.description,template:i.template,agent:i.agent,model:i.model},k)?await M(i.name,k)?(D.success(`Command renamed to "${ze}"`),S(ze)):D.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):D.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[41]=j,e[42]=T,e[43]=M,e[44]=i,e[45]=l,e[46]=S,e[47]=k,e[48]=n,e[49]=te):te=e[49];const pe=te;let Ie,Ne,Se,be,Oe,Le;if(e[50]!==W||e[51]!==z||e[52]!==$||e[53]!==de||e[54]!==a||e[55]!==f||e[56]!==y||e[57]!==S||e[58]!==n){const ze=W.filter(xa),wt=W.filter(Kp);e[65]===Symbol.for("react.memo_cache_sentinel")?(Oe=ve("flex h-full flex-col","bg-background"),e[65]=Oe):Oe=e[65];let Ee;e[66]!==n?(Ee=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Ee):Ee=e[67];let jt;e[68]!==Ee?(jt=s.jsx("h2",{className:`${dn} mb-3`,children:Ee}),e[68]=Ee,e[69]=jt):jt=e[69];let J;e[70]===Symbol.for("react.memo_cache_sentinel")?(J=s.jsx(Ga,{className:"mb-3"}),e[70]=J):J=e[70];let he;e[71]!==W.length||e[72]!==n?(he=n("settings.commands.sidebar.total",{count:W.length}),e[71]=W.length,e[72]=n,e[73]=he):he=e[73];let Fe;e[74]!==he?(Fe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:he}),e[74]=he,e[75]=Fe):Fe=e[75];let De;e[76]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[76]=De):De=e[76];let lt;e[77]!==z?(lt=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:z,children:De}),e[77]=z,e[78]=lt):lt=e[78];let ct;e[79]!==Fe||e[80]!==lt?(ct=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Fe,lt]}),e[79]=Fe,e[80]=lt,e[81]=ct):ct=e[81],e[82]!==jt||e[83]!==ct?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[jt,J,ct]}),e[82]=jt,e[83]=ct,e[84]=Le):Le=e[84],Ie=Hs,Ne="flex-1 min-h-0",Se="space-y-1 px-3 py-2",be=W.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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:[ze.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")}),[...ze].sort(zp).map(Qe=>s.jsx(mo,{command:Qe,isSelected:y===Qe.name,onSelect:()=>{S(Qe.name),a?.()},onReset:()=>K(Qe),onDuplicate:()=>de(Qe),isMenuOpen:f===Qe.name,onMenuOpenChange:kt=>C(kt?Qe.name:null)},Qe.name))]}),wt.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")}),[...wt].sort(Up).map(Qe=>s.jsx(mo,{command:Qe,isSelected:y===Qe.name,onSelect:()=>{S(Qe.name),a?.()},onRename:()=>ae(Qe),onDelete:()=>$(Qe),onDuplicate:()=>de(Qe),isMenuOpen:f===Qe.name,onMenuOpenChange:kt=>C(kt?Qe.name:null)},Qe.name))]})]}),e[50]=W,e[51]=z,e[52]=$,e[53]=de,e[54]=a,e[55]=f,e[56]=y,e[57]=S,e[58]=n,e[59]=Ie,e[60]=Ne,e[61]=Se,e[62]=be,e[63]=Oe,e[64]=Le}else Ie=e[59],Ne=e[60],Se=e[61],be=e[62],Oe=e[63],Le=e[64];let oe;e[85]!==Ie||e[86]!==Ne||e[87]!==Se||e[88]!==be?(oe=s.jsx(Ie,{outerClassName:Ne,className:Se,children:be}),e[85]=Ie,e[86]=Ne,e[87]=Se,e[88]=be,e[89]=oe):oe=e[89];const fe=u!==null&&d!==null;let Me;e[90]!==c?(Me=ze=>{!ze&&!c&&Y()},e[90]=c,e[91]=Me):Me=e[91];let $e;e[92]!==d||e[93]!==n?($e=n(d==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=d,e[93]=n,e[94]=$e):$e=e[94];let Ve;e[95]!==$e?(Ve=s.jsx($t,{children:$e}),e[95]=$e,e[96]=Ve):Ve=e[96];let qe;e[97]!==u?.name||e[98]!==d||e[99]!==n?(qe=d==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:u?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:u?.name??""}),e[97]=u?.name,e[98]=d,e[99]=n,e[100]=qe):qe=e[100];let se;e[101]!==qe?(se=s.jsx(Vt,{children:qe}),e[101]=qe,e[102]=se):se=e[102];let ie;e[103]!==Ve||e[104]!==se?(ie=s.jsxs(_t,{children:[Ve,se]}),e[103]=Ve,e[104]=se,e[105]=ie):ie=e[105];let we;e[106]!==n?(we=n("settings.common.actions.cancel"),e[106]=n,e[107]=we):we=e[107];let ye;e[108]!==c||e[109]!==we?(ye=s.jsx(H,{size:"sm",variant:"ghost",onClick:Y,disabled:c,children:we}),e[108]=c,e[109]=we,e[110]=ye):ye=e[110];let Te;e[111]!==d||e[112]!==n?(Te=n(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=d,e[112]=n,e[113]=Te):Te=e[113];let Ue;e[114]!==ee||e[115]!==c||e[116]!==Te?(Ue=s.jsx(H,{size:"sm",onClick:ee,disabled:c,children:Te}),e[114]=ee,e[115]=c,e[116]=Te,e[117]=Ue):Ue=e[117];let Pe;e[118]!==ye||e[119]!==Ue?(Pe=s.jsxs(ts,{children:[ye,Ue]}),e[118]=ye,e[119]=Ue,e[120]=Pe):Pe=e[120];let je;e[121]!==ie||e[122]!==Pe?(je=s.jsxs(zt,{className:"max-w-md",children:[ie,Pe]}),e[121]=ie,e[122]=Pe,e[123]=je):je=e[123];let Ge;e[124]!==fe||e[125]!==Me||e[126]!==je?(Ge=s.jsx(Kt,{open:fe,onOpenChange:Me,children:je}),e[124]=fe,e[125]=Me,e[126]=je,e[127]=Ge):Ge=e[127];const me=i!==null;let Ce;e[128]===Symbol.for("react.memo_cache_sentinel")?(Ce=ze=>!ze&&r(null),e[128]=Ce):Ce=e[128];let Re;e[129]!==n?(Re=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=Re):Re=e[130];let Ye;e[131]!==Re?(Ye=s.jsx($t,{children:Re}),e[131]=Re,e[132]=Ye):Ye=e[132];const q=i?.name??"";let ke;e[133]!==n||e[134]!==q?(ke=n("settings.commands.sidebar.renameDialog.description",{name:q}),e[133]=n,e[134]=q,e[135]=ke):ke=e[135];let Ae;e[136]!==ke?(Ae=s.jsx(Vt,{children:ke}),e[136]=ke,e[137]=Ae):Ae=e[137];let He;e[138]!==Ye||e[139]!==Ae?(He=s.jsxs(_t,{children:[Ye,Ae]}),e[138]=Ye,e[139]=Ae,e[140]=He):He=e[140];let at;e[141]===Symbol.for("react.memo_cache_sentinel")?(at=ze=>m(ze.target.value),e[141]=at):at=e[141];let nt;e[142]!==n?(nt=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=nt):nt=e[143];let dt;e[144]!==pe?(dt=ze=>{ze.key==="Enter"&&pe()},e[144]=pe,e[145]=dt):dt=e[145];let xt;e[146]!==l||e[147]!==nt||e[148]!==dt?(xt=s.jsx(Je,{value:l,onChange:at,placeholder:nt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:dt}),e[146]=l,e[147]=nt,e[148]=dt,e[149]=xt):xt=e[149];let G;e[150]===Symbol.for("react.memo_cache_sentinel")?(G=()=>r(null),e[150]=G):G=e[150];let Be;e[151]!==n?(Be=n("settings.common.actions.cancel"),e[151]=n,e[152]=Be):Be=e[152];let st;e[153]!==Be?(st=s.jsx(H,{size:"sm",variant:"ghost",onClick:G,children:Be}),e[153]=Be,e[154]=st):st=e[154];let rt;e[155]!==n?(rt=n("settings.common.actions.rename"),e[155]=n,e[156]=rt):rt=e[156];let pt;e[157]!==pe||e[158]!==rt?(pt=s.jsx(H,{size:"sm",onClick:pe,children:rt}),e[157]=pe,e[158]=rt,e[159]=pt):pt=e[159];let St;e[160]!==st||e[161]!==pt?(St=s.jsxs(ts,{children:[st,pt]}),e[160]=st,e[161]=pt,e[162]=St):St=e[162];let et;e[163]!==He||e[164]!==xt||e[165]!==St?(et=s.jsxs(zt,{children:[He,xt,St]}),e[163]=He,e[164]=xt,e[165]=St,e[166]=et):et=e[166];let Xe;e[167]!==me||e[168]!==et?(Xe=s.jsx(Kt,{open:me,onOpenChange:Ce,children:et}),e[167]=me,e[168]=et,e[169]=Xe):Xe=e[169];let ft;return e[170]!==Oe||e[171]!==Le||e[172]!==oe||e[173]!==Ge||e[174]!==Xe?(ft=s.jsxs("div",{className:Oe,children:[Le,oe,Ge,Xe]}),e[170]=Oe,e[171]=Le,e[172]=oe,e[173]=Ge,e[174]=Xe,e[175]=ft):ft=e[175],ft},mo=t=>{const e=gt.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:m,onDuplicate:u,isMenuOpen:x,onMenuOpenChange:d}=t,{t:v}=it();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=$a(),e[0]=c):c=e[0];const N=c,[f,C]=o.useState(!1);let y;e[1]!==r||e[2]!==u||e[3]!==m||e[4]!==l||e[5]!==v?(y=Q=>s.jsxs(s.Fragment,{children:[m&&s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),m()},children:[s.jsx(R,{name:"edit",className:"h-4 w-4 mr-px"}),v("settings.common.actions.rename")]}),s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),u()},children:[s.jsx(R,{name:"file-copy",className:"h-4 w-4 mr-px"}),v("settings.common.actions.duplicate")]}),l&&s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),l()},children:[s.jsx(R,{name:"restart",className:"h-4 w-4 mr-px"}),v("settings.common.actions.reset")]}),r&&s.jsxs(Q,{onClick:ne=>{ne.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),v("settings.common.actions.delete")]})]}),e[1]=r,e[2]=u,e[3]=m,e[4]=l,e[5]=v,e[6]=y):y=e[6];const S=y,g=n?"bg-interactive-selection":"hover:bg-interactive-hover";let T;e[7]!==g?(T=ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",g),e[7]=g,e[8]=T):T=e[8];let M;e[9]===Symbol.for("react.memo_cache_sentinel")?(M=N?void 0:Q=>{Q.preventDefault(),C(!0)},e[9]=M):M=e[9];let P;e[10]!==T?(P=s.jsx("div",{className:T,onContextMenu:M}),e[10]=T,e[11]=P):P=e[11];let k;e[12]!==a.name?(k=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=k):k=e[13];let h;e[14]!==a||e[15]!==v?(h=(a.scope||xa(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:xa(a)?v("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=v,e[16]=h):h=e[16];let j;e[17]!==k||e[18]!==h?(j=s.jsxs("div",{className:"flex items-center gap-2",children:[k,h]}),e[17]=k,e[18]=h,e[19]=j):j=e[19];let F;e[20]!==a.description?(F=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=F):F=e[21];let A;e[22]!==i||e[23]!==F||e[24]!==j?(A=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,F]}),e[22]=i,e[23]=F,e[24]=j,e[25]=A):A=e[25];let I;e[26]!==d?(I=Q=>{Q&&C(!1),d(Q)},e[26]=d,e[27]=I):I=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(rn,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=E):E=e[28];let B;e[29]!==S?(B=s.jsx(on,{align:"end",className:"w-fit min-w-20",children:S(cn)}),e[29]=S,e[30]=B):B=e[30];let _;e[31]!==x||e[32]!==I||e[33]!==B?(_=s.jsxs(ln,{open:x,onOpenChange:I,children:[E,B]}),e[31]=x,e[32]=I,e[33]=B,e[34]=_):_=e[34];let w;e[35]!==A||e[36]!==_?(w=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,_]}),e[35]=A,e[36]=_,e[37]=w):w=e[37];let V;e[38]!==w||e[39]!==P?(V=s.jsx(Zn,{render:P,children:w}),e[38]=w,e[39]=P,e[40]=V):V=e[40];let W;e[41]!==S?(W=s.jsx(Yn,{className:"w-fit min-w-20",children:S(Xn)}),e[41]=S,e[42]=W):W=e[42];let L;return e[43]!==f||e[44]!==V||e[45]!==W?(L=s.jsxs(ea,{open:f,onOpenChange:C,children:[V,W]}),e[43]=f,e[44]=V,e[45]=W,e[46]=L):L=e[46],L};function Lp(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Op(t){return t.loadSkills}function Fp(t){return t.name}function Kp(t){return!xa(t)}function zp(t,e){return t.name.localeCompare(e.name)}function Up(t,e){return t.name.localeCompare(e.name)}const _p=()=>{const{t}=it(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:r,setCommandDraft:l}=va(Ks(E=>({selectedCommandName:E.selectedCommandName,getCommandByName:E.getCommandByName,createCommand:E.createCommand,updateCommand:E.updateCommand,commandDraft:E.commandDraft,setCommandDraft:E.setCommandDraft}))),m=Us(),u=va(E=>fl(E,m)),x=e?a(e,m):null,d=!!(r&&r.name===e&&!x),[v,c]=o.useState(""),[N,f]=o.useState("user"),[C,y]=o.useState(""),[S,g]=o.useState(""),[T,M]=o.useState(""),[P,k]=o.useState(""),[h,j]=o.useState(!1),F=o.useRef(null);o.useEffect(()=>{if(d&&r){const E=r.name||"",B=r.scope||"user",_=r.description||"",w=r.agent||"",V=r.model||"",W=r.template||"";c(E),f(B),y(_),g(w),M(V),k(W),F.current={draftName:E,draftScope:B,description:_,agent:w,model:V,template:W}}else if(x){const E=x.description||"",B=x.agent||"",_=x.model||"",w=x.template||"";y(E),g(B),M(_),k(w),F.current={draftName:"",draftScope:"user",description:E,agent:B,model:_,template:w}}},[x,d,e,u,r]);const A=o.useMemo(()=>{const E=F.current;return E?!!(d&&(v!==E.draftName||N!==E.draftScope)||C!==E.description||S!==E.agent||T!==E.model||P!==E.template):!1},[S,C,v,N,d,T,P]),I=async()=>{const E=d?v.trim().replace(/\s+/g,"-"):e?.trim();if(!E){D.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!P.trim()){D.error(t("settings.commands.page.toast.templateRequired"));return}if(d&&u.some(B=>B.name===E)){D.error(t("settings.commands.sidebar.toast.commandExists"));return}j(!0);try{const B=S.trim(),_=T.trim(),w=P.trim(),V={name:E,description:C.trim()||void 0,agent:B===""?null:B,model:_===""?null:_,template:w,scope:d?N:void 0};let W;if(d?(W=await n(V,m),W&&l(null)):W=await i(E,V,m),W){const L=qn.getState().changes.some(Q=>Q.scope==="commands"&&Q.id.startsWith(`commands:${E}:`));D.success(t(L?"settings.view.pendingRestart.saved":d?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else D.error(t(d?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(B){console.error("Error saving command:",B),D.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{j(!1)}};return e?s.jsxs(es,{title:d?t("settings.commands.page.title.new"):`/${e}`,description:t(d?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(_e,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[d&&s.jsxs(Lt,{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(Je,{value:v,onChange:E=>c(E.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(It,{value:N,onValueChange:E=>f(E),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{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(As,{value:C,onChange:E=>y(E.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(_e,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Lt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(xl,{agentName:S,onChange:E=>g(E),className:En})}),s.jsx(Lt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Ka,{providerId:ba(T)?.providerId??"",modelId:ba(T)?.modelId??"",onChange:(E,B)=>{M(E&&B?`${E}/${B}`:"")},className:En})})]}),s.jsxs(_e,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(As,{value:P,onChange:E=>k(E.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:I,disabled:h||!A,size:"xs",className:"!font-normal",children:t(h?"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(R,{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")})]})})},uo=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},go=t=>{const e=gt.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=ve("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},$p=t=>{const e=gt.c(124),{onItemSelect:a}=t,{t:n}=it(),{selectedMcpName:i,setSelectedMcp:r,setMcpDraft:l,loadMcpConfigs:m,deleteMcp:u}=ya(Ks(Vp)),x=Us();let d;e[0]!==x?(d=q=>bl(q,x),e[0]=x,e[1]=d):d=e[1];const v=ya(d);let c;e[2]!==x?(c=q=>q.getStatusForDirectory(x),e[2]=x,e[3]=c):c=e[3];const N=Os(c),f=Os(Bp),C=Os(Hp),[y,S]=o.useState(null),[g,T]=o.useState(!1),[M,P]=o.useState(null),[k,h]=o.useState(null),[j,F]=o.useState(!1);let A;e[4]!==v?(A=v.filter(Gp),e[4]=v,e[5]=A):A=e[5];const I=A;let E;e[6]!==v?(E=v.filter(qp),e[6]=v,e[7]=E):E=e[7];const B=E;let _,w;e[8]!==m||e[9]!==x?(_=()=>{m({directory:x})},w=[m,x],e[8]=m,e[9]=x,e[10]=_,e[11]=w):(_=e[10],w=e[11]),o.useEffect(_,w);let V;e[12]!==C||e[13]!==j||e[14]!==f||e[15]!==x?(V=()=>{if(j)return;F(!0);const q=new Promise(Wp);Promise.all([f({directory:x,silent:!0}),q]).then(()=>{const ke=C(x);ke&&D.error(ke)}).finally(()=>{F(!1)})},e[12]=C,e[13]=j,e[14]=f,e[15]=x,e[16]=V):V=e[16];const W=V;let L;e[17]!==v||e[18]!==a||e[19]!==l||e[20]!==r?(L=()=>{let q="new-mcp-server",ke=1;for(;v.some(He=>He.name===q);)q=`new-mcp-server-${ke}`,ke++;l({name:q,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),r(q),a?.()},e[17]=v,e[18]=a,e[19]=l,e[20]=r,e[21]=L):L=e[21];const Q=L;let ne;e[22]!==u||e[23]!==y||e[24]!==x||e[25]!==n?(ne=async()=>{if(!y)return;T(!0);const q=await u(y.name,x);q.ok?q.reloadFailed?D.warning(q.message||`MCP server "${y.name}" deleted, but OpenCode reload failed`,{description:q.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):D.success(q.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:y.name})):D.error(n("settings.mcp.sidebar.toast.deleteFailed")),S(null),T(!1)},e[22]=u,e[23]=y,e[24]=x,e[25]=n,e[26]=ne):ne=e[26];const z=ne;let re;e[27]!==n?(re=(q,ke)=>s.jsxs(ke,{onClick:Ae=>{Ae.stopPropagation(),S(q)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=re):re=e[28];const $=re;let U;e[29]===Symbol.for("react.memo_cache_sentinel")?(U=ve("flex h-full flex-col","bg-background"),e[29]=U):U=e[29];let K;e[30]!==n?(K=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=K):K=e[31];let O;e[32]!==K?(O=s.jsx("h2",{className:dn,children:K}),e[32]=K,e[33]=O):O=e[33];let Y;e[34]!==n?(Y=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=Y):Y=e[35];let X;e[36]!==n?(X=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=X):X=e[37];const ee=j&&"animate-spin";let ge;e[38]!==ee?(ge=ve("h-4 w-4",ee),e[38]=ee,e[39]=ge):ge=e[39];let de;e[40]!==ge?(de=s.jsx(R,{name:"refresh",className:ge}),e[40]=ge,e[41]=de):de=e[41];let xe;e[42]!==W||e[43]!==j||e[44]!==Y||e[45]!==X||e[46]!==de?(xe=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:j,onClick:W,"aria-label":Y,title:X,children:de}),e[42]=W,e[43]=j,e[44]=Y,e[45]=X,e[46]=de,e[47]=xe):xe=e[47];let ae;e[48]!==O||e[49]!==xe?(ae=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[O,xe]}),e[48]=O,e[49]=xe,e[50]=ae):ae=e[50];let te;e[51]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(Ga,{className:"mb-3"}),e[51]=te):te=e[51];let pe;e[52]!==v.length||e[53]!==n?(pe=n("settings.mcp.sidebar.total",{count:v.length}),e[52]=v.length,e[53]=n,e[54]=pe):pe=e[54];let Ie;e[55]!==pe?(Ie=s.jsx("span",{className:"typography-meta text-muted-foreground",children:pe}),e[55]=pe,e[56]=Ie):Ie=e[56];let Ne;e[57]!==n?(Ne=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=Ne):Ne=e[58];let Se;e[59]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[59]=Se):Se=e[59];let be;e[60]!==Q||e[61]!==Ne?(be=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:Q,title:Ne,children:Se}),e[60]=Q,e[61]=Ne,e[62]=be):be=e[62];let Oe;e[63]!==Ie||e[64]!==be?(Oe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ie,be]}),e[63]=Ie,e[64]=be,e[65]=Oe):Oe=e[65];let Le;e[66]!==ae||e[67]!==Oe?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ae,te,Oe]}),e[66]=ae,e[67]=Oe,e[68]=Le):Le=e[68];let oe;e[69]!==v.length||e[70]!==N||e[71]!==a||e[72]!==M||e[73]!==I||e[74]!==$||e[75]!==k||e[76]!==i||e[77]!==l||e[78]!==r||e[79]!==n||e[80]!==B?(oe=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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:[I.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")}),I.map(q=>{const ke=N[q.name],Ae=uo(ke?.status),He=i===q.name,at=$a();return s.jsxs(ea,{open:k===q.name,onOpenChange:nt=>h(nt?q.name:null),children:[s.jsxs(Zn,{render:s.jsx("div",{className:ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",He?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:at?void 0:nt=>{nt.preventDefault(),h(q.name)}}),children:[s.jsxs("button",{onClick:()=>{r(q.name),l(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(go,{tone:Ae,enabled:q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:q.name}),s.jsx("span",{title:q.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:q.type==="local"?s.jsx(R,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(R,{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:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(ln,{open:M===q.name,onOpenChange:nt=>{nt&&h(null),P(nt?q.name:null)},children:[s.jsx(rn,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:$(q,cn)})]})]}),s.jsx(Yn,{className:"w-fit min-w-20",children:$(q,Xn)})]},q.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(q=>{const ke=N[q.name],Ae=uo(ke?.status),He=i===q.name,at=$a();return s.jsxs(ea,{open:k===q.name,onOpenChange:nt=>h(nt?q.name:null),children:[s.jsxs(Zn,{render:s.jsx("div",{className:ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",He?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:at?void 0:nt=>{nt.preventDefault(),h(q.name)}}),children:[s.jsxs("button",{onClick:()=>{r(q.name),l(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(go,{tone:Ae,enabled:q.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:q.name}),s.jsx("span",{title:q.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:q.type==="local"?s.jsx(R,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(R,{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:q.type==="local"?q.command?.join(" ")??"":q.url??""})]}),s.jsxs(ln,{open:M===q.name,onOpenChange:nt=>{nt&&h(null),P(nt?q.name:null)},children:[s.jsx(rn,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:$(q,cn)})]})]}),s.jsx(Yn,{className:"w-fit min-w-20",children:$(q,Xn)})]},q.name)})]})]})}),e[69]=v.length,e[70]=N,e[71]=a,e[72]=M,e[73]=I,e[74]=$,e[75]=k,e[76]=i,e[77]=l,e[78]=r,e[79]=n,e[80]=B,e[81]=oe):oe=e[81];const fe=y!==null;let Me;e[82]!==g?(Me=q=>{!q&&!g&&S(null)},e[82]=g,e[83]=Me):Me=e[83];let $e;e[84]!==n?($e=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=$e):$e=e[85];let Ve;e[86]!==$e?(Ve=s.jsx($t,{children:$e}),e[86]=$e,e[87]=Ve):Ve=e[87];const qe=y?.name||"";let se;e[88]!==n||e[89]!==qe?(se=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:qe}),e[88]=n,e[89]=qe,e[90]=se):se=e[90];let ie;e[91]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=ie):ie=e[91];let we;e[92]!==se?(we=s.jsxs(Vt,{children:[se," ",ie,"."]}),e[92]=se,e[93]=we):we=e[93];let ye;e[94]!==Ve||e[95]!==we?(ye=s.jsxs(_t,{children:[Ve,we]}),e[94]=Ve,e[95]=we,e[96]=ye):ye=e[96];let Te;e[97]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>S(null),e[97]=Te):Te=e[97];let Ue;e[98]!==n?(Ue=n("settings.common.actions.cancel"),e[98]=n,e[99]=Ue):Ue=e[99];let Pe;e[100]!==g||e[101]!==Ue?(Pe=s.jsx(H,{size:"sm",variant:"ghost",onClick:Te,disabled:g,children:Ue}),e[100]=g,e[101]=Ue,e[102]=Pe):Pe=e[102];let je;e[103]!==g||e[104]!==n?(je=n(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=g,e[104]=n,e[105]=je):je=e[105];let Ge;e[106]!==z||e[107]!==g||e[108]!==je?(Ge=s.jsx(H,{size:"sm",onClick:z,disabled:g,children:je}),e[106]=z,e[107]=g,e[108]=je,e[109]=Ge):Ge=e[109];let me;e[110]!==Pe||e[111]!==Ge?(me=s.jsxs(ts,{children:[Pe,Ge]}),e[110]=Pe,e[111]=Ge,e[112]=me):me=e[112];let Ce;e[113]!==ye||e[114]!==me?(Ce=s.jsxs(zt,{className:"max-w-md",children:[ye,me]}),e[113]=ye,e[114]=me,e[115]=Ce):Ce=e[115];let Re;e[116]!==fe||e[117]!==Me||e[118]!==Ce?(Re=s.jsx(Kt,{open:fe,onOpenChange:Me,children:Ce}),e[116]=fe,e[117]=Me,e[118]=Ce,e[119]=Re):Re=e[119];let Ye;return e[120]!==Le||e[121]!==oe||e[122]!==Re?(Ye=s.jsxs("div",{className:U,children:[Le,oe,Re]}),e[120]=Le,e[121]=oe,e[122]=Re,e[123]=Ye):Ye=e[123],Ye};function Vp(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Bp(t){return t.refresh}function Hp(t){return t.getErrorForDirectory}function Gp(t){return t.scope==="project"}function qp(t){return t.scope!=="project"}function Wp(t){return setTimeout(t,500)}function sn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Pa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Zs(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function oi(t,e,a){const n=Jp(a),i=typeof a.url=="string"?a.url.trim():"",r=ho(a,"env","environment"),l=ho(a,"headers"),m=Qp(a),u=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",x=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",d=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():"",c=Yp(a),N=Xp(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:m,oauthClientId:u,oauthClientSecret:x,oauthScope:d,oauthRedirectUri:v,timeout:c,enabled:N}}function Jp(t){const e=t.command,a=t.args;if(Pa(e)&&Pa(a))return[...e,...a];if(Pa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Pa(a)?[...n,...a]:n}return Pa(a)?a:[]}function ho(t,...e){for(const a of e){const n=t[a];if(!sn(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 Qp(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!sn(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 Yp(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 Xp(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function Zp(t){const e=t.mcpServers;if(sn(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(sn(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"&&sn(i)});if(a.length===1){const n=a[0],i=t[n];if(Ul(i))return{name:n,entry:i}}return null}function Ul(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function em(t,e){let a;try{const m=t.trim();if(!m)return Zs("No JSON content provided");a=JSON.parse(m)}catch(m){return Zs(m instanceof Error?`Invalid JSON: ${m.message}`:"Invalid JSON")}if(!sn(a))return Zs("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(sn(i)){const m=Object.keys(i);if(m.length===0)return Zs("mcpServers object is empty",a);if(m.length>1)return Zs("Paste one server at a time. Found "+m.length+" servers in mcpServers",a);const u=m[0],x=i[u];return sn(x)?oi(u,li(x),x):Zs("Server entry is not a valid object",a)}const r=n.mcp;if(sn(r)){const m=Object.keys(r);if(m.length===0)return Zs("mcp object is empty",a);if(m.length>1)return Zs("Paste one server at a time. Found "+m.length+" servers in mcp",a);const u=m[0],x=r[u];return sn(x)?oi(u,li(x),x):Zs("Server entry in mcp is not a valid object",a)}const l=Zp(n);if(l)return oi(l.name,li(l.entry),l.entry);if(Ul(n)){const m=li(n),u=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return oi(u,m,n)}return Zs("No recognizable MCP server configuration found in JSON",a)}function li(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 tm(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 _l(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 sm(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:jc(a.searchParams),stateKey:vl(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const nm=t=>{const e=gt.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[m,u]=o.useState(l),x=o.useRef(a);let d,v;e[2]!==a?(d=()=>{JSON.stringify(x.current)!==JSON.stringify(a)&&(x.current=a,u(a.join(`
5
+ `)))},v=[a],e[2]=a,e[3]=d,e[4]=v):(d=e[3],v=e[4]),o.useEffect(d,v);let c;e[5]!==n||e[6]!==r?(c=k=>{const h=k.split(`
6
+ `).filter(pm);if(r&&h.length===1&&/^https?:\/\/\S+$/i.test(h[0].trim())){r(h[0].trim());return}n(h)},e[5]=n,e[6]=r,e[7]=c):c=e[7];const N=c;let f;e[8]!==n?(f=k=>{const j=k.clipboardData.getData("text").trim();if(!j||j.includes(`
7
+ `)||!/\s/.test(j))return;const F=k.currentTarget;if(F.selectionStart!==0||F.selectionEnd!==F.value.length)return;k.preventDefault();const A=_l(j);u(A.join(`
8
+ `)),n(A)},e[8]=n,e[9]=f):f=e[9];const C=f;let y;e[10]!==N?(y=k=>{u(k.target.value),N(k.target.value)},e[10]=N,e[11]=y):y=e[11];let S;e[12]!==N||e[13]!==m?(S=()=>{const k=m.split(`
9
+ `).map(mm).join(`
10
+ `);u(k),N(k)},e[12]=N,e[13]=m,e[14]=S):S=e[14];const g=Math.max(4,a.length+1);let T;e[15]!==C||e[16]!==y||e[17]!==S||e[18]!==g||e[19]!==m?(T=s.jsx(As,{onPaste:C,value:m,onChange:y,onBlur:S,placeholder:`npx
11
+ -y
12
+ @modelcontextprotocol/server-postgres
13
+ postgresql://user:pass@host/db`,rows:g,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=C,e[16]=y,e[17]=S,e[18]=g,e[19]=m,e[20]=T):T=e[20];let M;e[21]!==i||e[22]!==a?(M=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(um)})})]}),e[21]=i,e[22]=a,e[23]=M):M=e[23];let P;return e[24]!==M||e[25]!==T?(P=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[T,M]}),e[24]=M,e[25]=T,e[26]=P):P=e[26],P},am=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),fo=({value:t,onChange:e,keyTransform:a=am,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:m,importSuccess:u,clipboardReadFailed:x,keyLabel:d,valueLabel:v,valuePlaceholder:c,hideValueTitle:N,showValueTitle:f,addVariable:C,plainTextWarning:y,removeVariableAria:S})=>{const[g,T]=o.useState(new Set),M=()=>e([...t,{key:"",value:""}]),P=A=>{e(t.filter((I,E)=>E!==A)),T(I=>{const E=new Set(I);return E.delete(A),E})},k=(A,I,E)=>{const B=[...t];B[A]={...B[A],[I]:E},e(B)},h=A=>{T(I=>{const E=new Set(I);return E.has(A)?E.delete(A):E.add(A),E})},j=async()=>{try{const A=await navigator.clipboard.readText(),I=[];for(const B of A.split(`
14
+ `)){const _=B.trim();if(!_||_.startsWith("#"))continue;const w=_.indexOf("=");if(w===-1)continue;const V=_.slice(0,w).trim();let W=_.slice(w+1).trim();(W.startsWith('"')&&W.endsWith('"')||W.startsWith("'")&&W.endsWith("'"))&&(W=W.slice(1,-1)),V&&I.push({key:V,value:W})}if(I.length===0){D.error(m);return}const E=[...t];for(const B of I){const _=E.findIndex(w=>w.key===B.key);_!==-1?E[_]=B:E.push(B)}e(E),D.success(u(I.length))}catch{D.error(x)}},F=t.some(A=>A.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:d}),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(R,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((A,I)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:A.key,onChange:E=>k(I,"key",a(E.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(Je,{type:g.has(I)?"text":"password",value:A.value,onChange:E=>k(I,"value",E.target.value),placeholder:c,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:()=>h(I),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:g.has(I)?N:f,children:g.has(I)?s.jsx(R,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(R,{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:()=>P(I),"aria-label":S,children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},I))}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:M,type:"button",children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),C]}),F&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:y})]})},Ji=t=>{const e=gt.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let m,u;if(e[0]!==i||e[1]!==a||e[2]!==l){u=Symbol.for("react.early_return_sentinel");e:{const c={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 N=ve("typography-micro font-medium rounded-full px-2 py-0.5",c.text,c.bg);let f;e[5]!==i||e[6]!==a?(f=i(a),e[5]=i,e[6]=a,e[7]=f):f=e[7],u=s.jsxs("span",{className:N,children:["● ",f]});break e}m=ve("typography-micro font-medium",c.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=m,e[4]=u}else m=e[3],u=e[4];if(u!==Symbol.for("react.early_return_sentinel"))return u;let x;e[8]!==i||e[9]!==a?(x=i(a),e[8]=i,e[9]=a,e[10]=x):x=e[10];let d;return e[11]!==m||e[12]!==x?(d=s.jsxs("span",{className:m,children:["● ",x]}),e[11]=m,e[12]=x,e[13]=d):d=e[13],d},im=(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")}},rm=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)]"}},om=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),lm=async t=>{const e=await ut(`/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},Aa=async t=>{typeof t!="string"||!t.trim()||await ut(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},ci=(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},cm=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},dm=()=>{const{t}=it(),e=o.useCallback((ce,mt)=>t(ce,mt),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:r,getMcpByName:l,createMcp:m,updateMcp:u,deleteMcp:x}=ya(Ks(ce=>({selectedMcpName:ce.selectedMcpName,mcpDraft:ce.mcpDraft,setMcpDraft:ce.setMcpDraft,setSelectedMcp:ce.setSelectedMcp,getMcpByName:ce.getMcpByName,createMcp:ce.createMcp,updateMcp:ce.updateMcp,deleteMcp:ce.deleteMcp}))),d=Us(),v=o.useMemo(()=>cs(),[]),c=Os(ce=>ce.getStatusForDirectory(d)),N=Os(ce=>ce.getDiagnosticForDirectory(d)),f=Os(ce=>ce.refresh),C=Os(ce=>ce.connect),y=Os(ce=>ce.disconnect),S=Os(ce=>ce.completeAuth),g=Os(ce=>ce.clearAuth),T=Os(ce=>ce.testConnection),M=qn(ce=>ce.changes),P=ya(ce=>bl(ce,d)),k=a?l(a,d):null,h=!!(n&&n.name===a&&!k),[j,F]=o.useState(""),[A,I]=o.useState("user"),[E,B]=o.useState("local"),[_,w]=o.useState([]),[V,W]=o.useState(""),[L,Q]=o.useState([]),[ne,z]=o.useState([]),[re,$]=o.useState(!0),[U,K]=o.useState(""),[O,Y]=o.useState(""),[X,ee]=o.useState(""),[ge,de]=o.useState(""),[xe,ae]=o.useState(""),[te,pe]=o.useState(!0),[Ie,Ne]=o.useState(!1),[Se,be]=o.useState(!1),[Oe,Le]=o.useState(!1),[oe,fe]=o.useState(!1),[Me,$e]=o.useState(!1),[Ve,qe]=o.useState(!1),[se,ie]=o.useState(!1),[we,ye]=o.useState(!1),[Te,Ue]=o.useState(null),[Pe,je]=o.useState(null),[Ge,me]=o.useState(""),[Ce,Re]=o.useState(!1),Ye=o.useRef(0),q=o.useRef(!1),[ke,Ae]=o.useState(!1),[He,at]=o.useState(!1),[nt,dt]=o.useState(""),[xt,G]=o.useState(null),Be=o.useMemo(()=>cm(a,d),[d,a]),st=o.useRef(Be),rt=o.useRef(null),pt=o.useCallback(()=>{Ue(null),je(null),me(""),Re(!1),Ye.current=0,ye(!1),$e(!1),qe(!1),q.current=!1},[]),St=o.useCallback(()=>{dt(""),G(null),at(!0)},[]),et=o.useCallback(async()=>{try{const ce=await navigator.clipboard.readText();dt(ce),G(null)}catch{D.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Xe=o.useCallback(()=>{const ce=em(nt,{fallbackName:j});if(!ce.ok){G(ce.error);return}const yt=tm(ce,{name:j,scope:A,type:E,command:_,url:V,environment:L,headers:ne,oauthEnabled:re,oauthClientId:U,oauthClientSecret:O,oauthScope:X,oauthRedirectUri:ge,timeout:xe,enabled:te},{isNewServer:h});F(yt.name),B(yt.type),w(yt.command??[]),W(yt.url??""),Q(yt.environment??[]),z(yt.headers??[]),$(yt.oauthEnabled??!1),K(yt.oauthClientId??""),Y(yt.oauthClientSecret??""),ee(yt.oauthScope??""),de(yt.oauthRedirectUri??""),ae(yt.timeout??""),pe(yt.enabled??!0),at(!1),dt(""),G(null),D.success(t("settings.mcp.page.toast.configImported"))},[nt,j,A,E,_,V,L,ne,re,U,O,X,ge,xe,te,h,t]);o.useEffect(()=>{if(h&&n){F(n.name),I(n.scope||"user"),B(n.type),w(n.command),W(n.url),Q(n.environment),z(n.headers),$(n.oauthEnabled),K(n.oauthClientId),Y(n.oauthClientSecret),ee(n.oauthScope),de(n.oauthRedirectUri),ae(n.timeout),pe(n.enabled),Ae(!1),rt.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,timeout:n.timeout,enabled:n.enabled};return}if(k){I(k.scope==="project"?"project":"user");const ce=Lr(k.environment),mt=k.type==="remote"?k:null,yt=Lr(mt?.headers),Qt=mt?.oauth,Yt=Qt&&typeof Qt=="object"?Qt:null,Bt=Qt!==!1,rs=k.type,ys=rs==="local"?k.command??[]:[],ss=rs==="remote"?k.url??"":"",Nt=typeof mt?.timeout=="number"&&Number.isFinite(mt.timeout)?String(mt.timeout):"";B(rs),w(ys),W(ss),Q(ce),z(yt),$(Bt),K(Bt?Yt?.clientId??"":""),Y(Bt?Yt?.clientSecret??"":""),ee(Bt?Yt?.scope??"":""),de(Bt?Yt?.redirectUri??"":""),ae(Nt),pe(k.enabled),Ae(!1),rt.current={mcpType:rs,command:ys,url:ss,envEntries:ce,headerEntries:yt,oauthEnabled:Bt,oauthClientId:Bt?Yt?.clientId??"":"",oauthClientSecret:Bt?Yt?.clientSecret??"":"",oauthScope:Bt?Yt?.scope??"":"",oauthRedirectUri:Bt?Yt?.redirectUri??"":"",timeout:Nt,enabled:k.enabled}}},[k,h,n]);const ft=o.useMemo(()=>{const ce=rt.current;return ce?E!==ce.mcpType||te!==ce.enabled||JSON.stringify(_)!==JSON.stringify(ce.command)||V!==ce.url||JSON.stringify(L)!==JSON.stringify(ce.envEntries)||JSON.stringify(ne)!==JSON.stringify(ce.headerEntries)||re!==ce.oauthEnabled||U!==ce.oauthClientId||O!==ce.oauthClientSecret||X!==ce.oauthScope||ge!==ce.oauthRedirectUri||xe!==ce.timeout:!1},[E,_,V,L,ne,re,U,O,X,ge,xe,te]),ze=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(R,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(R,{name:"global",className:"h-3.5 w-3.5"})}],[t]),wt=o.useCallback(ce=>{B("remote"),W(ce),w([])},[]),Ee=o.useCallback(ce=>{W(ce);const mt=ce.trim();mt&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(mt)&&/\s/.test(mt)&&(B("local"),w(_l(mt)),W(""))},[]),jt=async()=>{const ce=h?j.trim():a??"";if(!ce){D.error(t("settings.mcp.page.toast.nameRequired"));return}if(h&&P.some(yt=>yt.name===ce)){D.error(t("settings.mcp.page.toast.serverNameExists"));return}if(E==="local"&&_.filter(Boolean).length===0){D.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(E==="remote"&&!V.trim()){D.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const mt={name:ce,scope:A,type:E,command:_,url:V,environment:L,headers:ne,oauthEnabled:re,oauthClientId:U,oauthClientSecret:O,oauthScope:X,oauthRedirectUri:ge,timeout:xe,enabled:te};Ne(!0);try{const yt=h?await m(mt,d):await u(ce,mt,d);yt.ok?(await Aa(Pe),pt(),h&&(i(null),r(ce)),await f({directory:d,silent:!0}),yt.reloadFailed?D.warning(yt.message||t(h?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:yt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):yt.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(yt.message||t(h?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):D.error(t("settings.mcp.page.toast.saveFailed"))}catch(yt){D.error(yt instanceof Error?yt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Ne(!1)}},J=async()=>{if(!a)return;Le(!0);const ce=await x(a,d);ce.ok?(await Aa(Pe),pt(),ce.reloadFailed?D.warning(ce.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:ce.warning||t("settings.mcp.page.toast.refreshListIfStale")}):D.success(ce.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),be(!1)):D.error(t("settings.mcp.page.toast.deleteFailed")),Le(!1)},he=async()=>{if(a){fe(!0);try{if(c[a]?.status==="connected")await y(a,d),D.success(t("settings.mcp.page.toast.disconnected"));else{await C(a,d),await f({directory:d,silent:!0});const mt=Os.getState().getStatusForDirectory(d)[a];mt?.status==="connected"?D.success(t("settings.mcp.page.toast.connected")):mt?.status==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):mt?.status==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):mt?.status==="failed"?D.error(mt.error||t("settings.mcp.page.toast.connectionFailed")):D.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await f({directory:d,silent:!0})}catch(ce){D.error(ce instanceof Error?ce.message:t("settings.mcp.page.toast.connectionFailed"))}finally{fe(!1)}}},Fe=o.useCallback(()=>h?(D.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):ft?(D.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[ft,h,t]),De=o.useCallback(async(ce=!1)=>{try{await f({directory:d,silent:ce})}catch(mt){ce||D.error(mt instanceof Error?mt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[d,f,t]);o.useEffect(()=>{De(!0)},[De]),o.useEffect(()=>{st.current=Be,fe(!1),ie(!1),pt()},[pt,Be]);const lt=o.useCallback(async()=>{if(!a||E!=="remote"||!Fe())return;$e(!0);const ce=Be;let mt=null;try{const yt=Os.getState().getStatusForDirectory(d)[a]?.status;q.current=yt==="needs_auth"||yt==="needs_client_registration";const{authorizationUrl:Qt,opened:Yt,nativeFlow:Bt,completion:rs}=await vc({name:a,directory:d});if(Bt){if(st.current!==ce)return;Ue(null),je(null),Re(!0),Ye.current=0,D.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),rs?.then(()=>{st.current===ce&&(Re(!1),Ye.current=0,q.current=!1,D.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(ss=>{st.current===ce&&(Re(!1),Ye.current=0,q.current=!1,D.error(ci(ss,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const ys=vl(new URL(Qt).searchParams);if(mt=ys,st.current!==ce||(Ue(Qt),je(ys??null),Re(!0),Ye.current=0,st.current!==ce))return;Yt?D.message(t(v?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):D.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(yt){await Aa(mt),st.current===ce&&D.error(ci(yt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{st.current===ce&&$e(!1)}},[d,v,E,Fe,Be,a,t,e]),ct=o.useCallback(async()=>{if(!a||!Fe())return;qe(!0);const ce=Be;try{if(await g(a,d),st.current!==ce)return;Ue(null),je(null),me(""),Re(!1),Ye.current=0,await Aa(Pe),D.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(mt){st.current===ce&&D.error(ci(mt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{st.current===ce&&qe(!1)}},[Pe,g,d,Fe,Be,a,t,e]),Qe=o.useCallback(async()=>{if(!Te)return;if((await za(Te)).ok){D.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}D.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Te,t]),kt=o.useCallback(async()=>{const ce=sm(Ge);if(!ce.code){D.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const mt=ce.stateKey?await lm(ce.stateKey):null,yt=ce.context??mt,Qt=yt?.name??a,Yt=yt?.directory??d;if(!Qt){D.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!yt&&!Fe())return;ye(!0);const Bt=Be;try{if(await S(Qt,ce.code,Yt),await Aa(ce.stateKey??Pe),st.current!==Bt)return;me(""),Ue(null),je(null),Re(!1),Ye.current=0,D.success(Qt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Qt}))}catch(rs){st.current===Bt&&D.error(ci(rs,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{st.current===Bt&&ye(!1)}},[Ge,Pe,S,d,Fe,Be,a,t,e]),bs=o.useCallback(async()=>{if(!(!a||!Fe())){if(!te){D.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ie(!0);try{const ce=await T(a,d),mt=ce.status?.status;ce.warning?D.warning(ce.warning):mt==="connected"?D.success(t("settings.mcp.page.toast.connectionTestSucceeded")):mt==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):mt==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):mt==="failed"?D.error(ce.status?.error||ce.error||t("settings.mcp.page.toast.connectionTestFailed")):ce.error?D.error(ce.error):D.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(ce){D.error(ce instanceof Error?ce.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{ie(!1)}}},[d,te,Fe,a,t,T]);if(o.useEffect(()=>{if(!Ce||!a)return;const ce=window.setInterval(()=>{(async()=>{Ye.current+=1,await f({directory:d,silent:!0});const mt=Os.getState().getStatusForDirectory(d)[a];if(mt){if(q.current&&mt.status!=="needs_auth"&&mt.status!=="needs_client_registration"){Re(!1),Ye.current=0,q.current=!1,Ue(null),me(""),mt.status==="connected"&&D.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!q.current&&mt.status==="failed"){Re(!1),Ye.current=0,q.current=!1,D.error(mt.error||t("settings.mcp.page.toast.authorizationFailed"));return}Ye.current>=30&&(Re(!1),Ye.current=0,q.current=!1,D.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(ce)}},[d,Ce,f,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(R,{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 Xt=c[a],Ls=a?N[a]:void 0,Gt=Xt??Ls,is=!h&&!Gt&&M.some(ce=>ce.scope==="mcp"&&ce.id.startsWith(`mcp:${a}:`)),Ht=Xt?.status==="connected",vs=Xt?.status==="needs_auth"||Xt?.status==="needs_client_registration",us=v||!a?null:yc(a),gs=async()=>{if(us)try{await navigator.clipboard.writeText(us),D.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{D.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},ds=im(Gt?.status,e,Gt&&"error"in Gt?Gt.error:void 0),Ts=ce=>{switch(ce){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 ce}};return s.jsxs(s.Fragment,{children:[s.jsxs(es,{title:h?t("settings.mcp.page.header.newServer"):a,titleAccessory:h?void 0:s.jsx(Ji,{status:is?"awaiting_restart":Gt?.status,enabled:te,getStatusLabel:Ts,variant:"pill"}),description:h?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(E==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!h&&!is?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{variant:Ht?"outline":"default",size:"xs",className:"!font-normal",onClick:he,disabled:oe||!te,children:t(oe?"settings.mcp.page.actions.working":Ht?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),E==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(H,{variant:vs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{lt()},disabled:Me||!te,children:t(Me?"settings.mcp.page.actions.starting":Ht?"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:Ve||!te,children:t(Ve?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Ht&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{bs()},disabled:se||!te,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[is&&s.jsx(_e,{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:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Ji,{status:"awaiting_restart",enabled:te,getStatusLabel:Ts})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!h&&!is&&om(Gt?.status,Te,vs,Ce)&&s.jsx(_e,{divider:!1,children:s.jsxs("div",{className:ve("rounded-lg border p-3",rm(Gt?.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:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Ji,{status:Gt?.status,enabled:te,getStatusLabel:Ts})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ds}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:A==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:d??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Ht&&s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{bs()},disabled:se||!te,children:t(se?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Gt?.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(Ys,{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")})]}),us&&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:us}),s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{gs()},children:[s.jsx(R,{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(Wt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(Je,{value:U,onChange:ce=>{K(ce.target.value),$(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(Wt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(Je,{type:"password",value:O,onChange:ce=>{Y(ce.target.value),$(!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")})]}),Te&&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:Te}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Dn(Te)},children:[s.jsx(R,{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:()=>{Qe()},children:[s.jsx(R,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),v&&E==="remote"&&(vs||Ce||Te)&&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(Ys,{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(As,{value:Ge,onChange:ce=>me(ce.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:()=>{kt()},disabled:we,children:t(we?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Ce&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs(_e,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:h?s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:St,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(R,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[h&&s.jsxs(Lt,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(Je,{value:j,onChange:ce=>F(ce.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(It,{value:A,onValueChange:ce=>I(ce),children:[s.jsxs(Pt,{size:Ft,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(R,{name:A==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(A==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(ht,{checked:te,onChange:pe,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(_e,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(Sr,{items:ze,activeId:E,onSelect:ce=>B(ce),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),E==="local"?s.jsx(nm,{value:_,onChange:w,preview:ce=>t("settings.mcp.page.connection.previewArgs",{count:ce}),onDetectUrl:wt}):s.jsx(Je,{value:V,onChange:ce=>Ee(ce.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(E==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),E==="remote"&&s.jsx(_e,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(Mn,{open:ke,onOpenChange:Ae,children:[s.jsxs(Rn,{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:["(",ne.length," ",t("settings.mcp.page.advanced.headers"),xe?` · ${xe}ms`:"",")"]})]}),ke?s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Ln,{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:Et,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Jt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Je,{type:"number",min:"1",step:"1",value:xe,onChange:ce=>ae(ce.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(Ys,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),ne.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",ne.length,")"]})]}),s.jsx(fo,{value:ne,onChange:z,keyTransform:ce=>ce.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:ce=>t("settings.mcp.page.toast.importedVariablesCount",{count:ce}),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(_e,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:L.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",L.length,")"]}):null,settingsItem:"mcp.environment",children:L.length===0?s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Q([{key:"",value:""}]),children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(fo,{value:L,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:ce=>t("settings.mcp.page.toast.importedVariablesCount",{count:ce}),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:jt,disabled:Ie||!ft&&!h,size:"xs",className:"!font-normal",children:t(Ie?"settings.common.actions.saving":h?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!h&&s.jsx(H,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>be(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Kt,{open:He,onOpenChange:ce=>{ce||(at(!1),dt(""),G(null))},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Vt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(As,{value:nt,onChange:ce=>{dt(ce.target.value),G(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"}),xt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:xt}),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:et,type:"button",children:[s.jsx(R,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(ts,{children:[s.jsx(H,{variant:"outline",onClick:()=>{at(!1),dt(""),G(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{onClick:Xe,disabled:!nt.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Kt,{open:Se,onOpenChange:ce=>{!ce&&!Oe&&be(!1)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Vt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(ts,{children:[s.jsx(H,{variant:"outline",onClick:()=>be(!1),disabled:Oe,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(H,{variant:"destructive",size:"sm",onClick:J,disabled:Oe,children:t(Oe?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function pm(t){return t.trim().length>0}function mm(t){return t.trimEnd()}function um(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 vi=()=>{try{const e=Bs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=fn.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},gm=800,hm=5e3,fm="__default__",pr=new Map,Qi=new Map,xm=1500,$l=t=>t?.trim()||fm,bm=t=>{pr.delete($l(t))},ms=Ll()(Wd(Jd((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=vi(),i=$l(n),r=Date.now(),l=pr.get(i)??0,m=e().entries.length>0||e().files.length>0;if(!a?.force&&m&&r-l<hm)return!0;const u=Qi.get(i);if(!a?.force&&u)return u;const x=(async()=>{t({isLoading:!0});try{const d=await ut(In("/api/config/plugins",n),{headers:Ta(n)});if(!d.ok)throw new Error("Failed to load plugins");const v=await yi(d);return t({entries:v.entries??[],files:v.files??[],isLoading:!1}),pr.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(d){return console.error("[PluginsStore] Failed to load plugins:",d),t({isLoading:!1}),!1}})();Qi.set(i,x);try{return await x}finally{Qi.delete(i)}},loadRegistryInfo:async a=>{const n=ym(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=vi(),r={...e().registryInfo};for(const l of jm(n)){const m=await ut(vm(l,a?.force===!0,i),{headers:Ta(i)});if(!m.ok)throw new Error("Failed to load plugin registry info");const u=await yi(m);for(const x of u.results??[])r[x.spec]=x}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 ga("Creating plugin entry…",async i=>await ut(In("/api/config/plugins/entry",i),{method:"POST",headers:di(i),body:JSON.stringify(xo(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(m=>m.id===a)?.spec,r=n.spec??i,l=await ga("Updating plugin entry…",async m=>await ut(In(`/api/config/plugins/entry/${encodeURIComponent(a)}`,m),{method:"PATCH",headers:di(m),body:JSON.stringify(xo(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 ga("Deleting plugin entry…",async r=>await ut(In(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:Ta(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=vi(),i=await ut(In(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:Ta(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await yi(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>ga("Creating plugin file…",async n=>await ut(In("/api/config/plugins/file",n),{method:"POST",headers:di(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>ga("Updating plugin file…",async i=>await ut(In(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:di(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await ga("Deleting plugin file…",async i=>await ut(In(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:Ta(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:ud(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function In(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function vm(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 ym(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function jm(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>xm?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function Ta(t){return t?{"x-opencode-directory":t}:void 0}function di(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function xo(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 ga(t,e,a,n){try{const i=vi(),r=await e(i),l=await yi(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return bm(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):hl(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&&(wc(t),await kc({message:l.message,delayMs:l.reloadDelayMs??gm,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 yi(t){return await t.json()}const wm=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function km(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 Nm=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=it(),i=ms(w=>w.createEntry),r=ms(w=>w.createFile),[l,m]=o.useState("npm"),[u,x]=o.useState(""),[d,v]=o.useState(""),[c,N]=o.useState(""),[f,C]=o.useState(""),[y,S]=o.useState(a),[g,T]=o.useState(!1),M=o.useCallback(()=>{x(""),v(""),N(""),C(""),S(a)},[a]);o.useEffect(()=>{t&&(m("npm"),M())},[t,M]);const P=w=>{w!==l&&(m(w),M())},k=o.useMemo(()=>km(d),[d]),h=!k.ok,j=l==="file"&&c.trim()!==""&&!wm.test(c.trim()),F=(l==="npm"||l==="path")&&u.trim()==="",A=l==="file"&&f.trim()==="",I=l==="file"&&c.trim()==="",E=g||h||l==="npm"&&F||l==="path"&&F||l==="file"&&(I||j||A),B=async()=>{if(!E){T(!0);try{let w;l==="file"?w=await r({fileName:c.trim(),content:f,scope:y}):w=await i({spec:u.trim(),options:k.ok?k.value:void 0,scope:y}),w.ok?(w.restartDeferred?D.success(n("settings.view.pendingRestart.saved")):D.success(w.message||n("settings.plugins.toast.created")),w.reloadFailed&&D.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):D.error(w.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{T(!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(Kt,{open:t,onOpenChange:w=>{!w&&g||e(w)},children:s.jsxs(zt,{className:"max-w-xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Vt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(Sr,{items:_,activeId:l,onSelect:w=>P(w),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(Je,{id:"plugin-spec",value:u,onChange:w=>x(w.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":F?!1:void 0,disabled:g}),F&&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(As,{id:"plugin-options",value:d,onChange:w=>v(w.target.value),rows:5,className:"font-mono",hasError:h,disabled:g}),h&&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(Je,{id:"plugin-filename",value:c,onChange:w=>N(w.target.value),placeholder:"my-plugin.ts","aria-invalid":j||void 0,disabled:g}),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(As,{id:"plugin-content",value:f,onChange:w=>C(w.target.value),rows:16,className:"font-mono",disabled:g})]})]}),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(w=>{const V=y===w,W=n(w==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>S(w),disabled:g,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(yr,{checked:V,onChange:()=>S(w),ariaLabel:W}),s.jsx("span",{className:ve("typography-ui-label font-normal",V?"text-foreground":"text-foreground/60"),children:W})]},w)})})]})]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:g,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(H,{size:"sm",onClick:()=>{B()},disabled:E,children:[g?s.jsx(R,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},Sm=t=>{const e=gt.c(33),{spec:a}=t;let n;e[0]!==a?(n=m=>m.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=ms(n),{t:r}=it();if(!i)return null;const l=Cm;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(R,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=m):m=e[2];let u;e[3]!==i.latestVersion?(u=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[m,i.latestVersion]}),e[3]=i.latestVersion,e[4]=u):u=e[4];let x;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==u?(x=l(u,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]=u,e[9]=x):x=e[9],x}case"npm-missing-version":{let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=m):m=e[10];let u;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(u=l(m,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]=u):u=e[14],u}case"npm-missing-package":{let m;e[15]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=m):m=e[15];let u;return e[16]!==i.name||e[17]!==r?(u=l(m,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=u):u=e[18],u}case"npm-malformed":{let m;e[19]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=m):m=e[19];let u;return e[20]!==r?(u=l(m,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=u):u=e[21],u}case"npm-network":{let m;e[22]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(R,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=m):m=e[22];let u;return e[23]!==r?(u=l(m,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=u):u=e[24],u}case"path-missing":{let m;e[25]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=m):m=e[25];let u;return e[26]!==i.absolutePath||e[27]!==r?(u=l(m,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=u):u=e[28],u}case"path-unreadable":{let m;e[29]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(R,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=m):m=e[29];let u;return e[30]!==i.absolutePath||e[31]!==r?(u=l(m,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=u):u=e[32],u}case"path-ok":return null;default:return null}};function Cm(t,e){return s.jsxs(jr,{children:[s.jsx(wr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(yl,{children:e})]})}const Vl=t=>{const e=gt.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,m=l===void 0?"sidebar":l,u=cs(),x=o.useRef(null),[d,v]=o.useState(!1),[c,N]=o.useState(!1),f=m==="background"||u?"bg-background":"bg-sidebar",C=f==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{const E=x.current;if(!E){v(!1),N(!1);return}if(!(E.scrollHeight>E.clientHeight+1)){v(!1),N(!1);return}v(E.scrollTop>1),N(E.scrollTop+E.clientHeight<E.scrollHeight-1)},e[0]=y):y=e[0];const S=y;let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{S()},e[1]=g):g=e[1];let T;e[2]!==i?(T=[i,S],e[2]=i,e[3]=T):T=e[3],o.useEffect(g,T);let M,P;e[4]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{const E=x.current;if(!E)return;const B=()=>S();return E.addEventListener("scroll",B,{passive:!0}),()=>E.removeEventListener("scroll",B)},P=[S],e[4]=M,e[5]=P):(M=e[4],P=e[5]),o.useEffect(M,P);let k;e[6]!==f||e[7]!==r?(k=ve("flex h-full flex-col",f,r),e[6]=f,e[7]=r,e[8]=k):k=e[8];let h;e[9]!==i?(h=s.jsx(Hs,{ref:x,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]=h):h=e[10];let j;e[11]!==C||e[12]!==d?(j=d&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${C} 0%, transparent 100%)`}}),e[11]=C,e[12]=d,e[13]=j):j=e[13];let F;e[14]!==C||e[15]!==c?(F=c&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${C} 0%, transparent 100%)`}}),e[14]=C,e[15]=c,e[16]=F):F=e[16];let A;e[17]!==F||e[18]!==h||e[19]!==j?(A=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[h,j,F]}),e[17]=F,e[18]=h,e[19]=j,e[20]=A):A=e[20];let I;return e[21]!==n||e[22]!==a||e[23]!==A||e[24]!==k?(I=s.jsxs("div",{className:k,children:[a,A,n]}),e[21]=n,e[22]=a,e[23]=A,e[24]=k,e[25]=I):I=e[25],I},mr=t=>{const e=gt.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:m,className:u}=t,x=i===void 0?!1:i,d=m&&m.length>0,v=x?"bg-interactive-selection":"hover:bg-interactive-hover";let c;e[0]!==u||e[1]!==v?(c=ve("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",v,u),e[0]=u,e[1]=v,e[2]=c):c=e[2];let N;e[3]!==a?(N=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=N):N=e[4];let f;e[5]!==l||e[6]!==N?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,N]}),e[5]=l,e[6]=N,e[7]=f):f=e[7];let C;e[8]!==n?(C=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=C):C=e[9];let y;e[10]!==r||e[11]!==f||e[12]!==C?(y=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:[f,C]}),e[10]=r,e[11]=f,e[12]=C,e[13]=y):y=e[13];let S;e[14]!==m||e[15]!==d?(S=d&&s.jsxs(ln,{children:[s.jsx(rn,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:m.map(Im)})]}),e[14]=m,e[15]=d,e[16]=S):S=e[16];let g;e[17]!==y||e[18]!==S?(g=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[y,S]}),e[17]=y,e[18]=S,e[19]=g):g=e[19];let T;return e[20]!==c||e[21]!==g?(T=s.jsx("div",{className:c,children:g}),e[20]=c,e[21]=g,e[22]=T):T=e[22],T};function Im(t){const e=t.icon;return s.jsxs(cn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:ve(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(R,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Pm=t=>t.parsedKind==="npm"?"code-box":"folder",Am=t=>{const e=gt.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=it(),{entries:r,files:l,selectedId:m,setSelected:u,deleteEntry:x,deleteFile:d,loadPlugins:v}=ms(Ks(Tm)),c=ms(Em),N=ms(Dm),f=ms(Mm),C=ms(Rm),[y,S]=o.useState(null),[g,T]=o.useState(!1),[M,P]=o.useState(!1);let k,h;e[0]!==v?(k=()=>{v()},h=[v],e[0]=v,e[1]=k,e[2]=h):(k=e[1],h=e[2]),o.useEffect(k,h);let j,F;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{const et=()=>P(!0);return window.addEventListener("openchamber:settings-open-plugin-add",et),()=>window.removeEventListener("openchamber:settings-open-plugin-add",et)},F=[],e[3]=j,e[4]=F):(j=e[3],F=e[4]),o.useEffect(j,F);let A;if(e[5]!==r||e[6]!==c){A={userEntries:0,projectEntries:0};for(const et of r){const Xe=c[et.spec];Xe?.kind==="npm-ok"&&Xe.hasUpdate&&(et.scope==="user"?A.userEntries=A.userEntries+1:et.scope==="project"&&(A.projectEntries=A.projectEntries+1))}e[5]=r,e[6]=c,e[7]=A}else A=e[7];const I=A;let E;e[8]!==r?(E=r.filter(Lm),e[8]=r,e[9]=E):E=e[9];const B=E;let _;e[10]!==r?(_=r.filter(Om),e[10]=r,e[11]=_):_=e[11];const w=_;let V;e[12]!==l?(V=l.filter(Fm),e[12]=l,e[13]=V):V=e[13];const W=V;let L;e[14]!==l?(L=l.filter(Km),e[14]=l,e[15]=L):L=e[15];const Q=L,ne=r.length+l.length,z=ne===0;let re;e[16]!==n?(re=()=>{n?n():P(!0)},e[16]=n,e[17]=re):re=e[17];const $=re;let U;e[18]!==a||e[19]!==u?(U=et=>{u(et),a?.()},e[18]=a,e[19]=u,e[20]=U):U=e[20];const K=U;let O;e[21]!==r||e[22]!==c||e[23]!==i||e[24]!==C?(O=async et=>{const Xe=r.find(Ee=>Ee.id===et);if(!Xe)return;const ft=c[Xe.spec];if(!ft||ft.kind!=="npm-ok"||!ft.hasUpdate||!ft.latestVersion)return;const ze=ft.latestVersion;(await C(et)).ok?D.success(i("settings.plugins.toast.updatedToLatest",{version:ze})):D.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=c,e[23]=i,e[24]=C,e[25]=O):O=e[25];const Y=O;let X;e[26]!==f||e[27]!==i?(X=async()=>{D.info(i("settings.plugins.toast.refreshing"));try{await f({force:!0})}catch{D.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=f,e[27]=i,e[28]=X):X=e[28];const ee=X;let ge;e[29]!==x||e[30]!==d||e[31]!==y||e[32]!==i?(ge=async()=>{if(!y)return;T(!0);const et=y.kind==="entry"?await x(y.id):await d(y.id);et.ok?D.success(et.message||i("settings.plugins.sidebar.toast.deleted",{name:y.label})):D.error(i("settings.plugins.sidebar.toast.deleteFailed")),S(null),T(!1)},e[29]=x,e[30]=d,e[31]=y,e[32]=i,e[33]=ge):ge=e[33];const de=ge;let xe;e[34]!==K||e[35]!==Y||e[36]!==c||e[37]!==m||e[38]!==i?(xe=et=>{const Xe=c[et.spec],ft=Xe?.kind==="npm-ok"&&Xe.hasUpdate&&!!Xe.latestVersion,ze=[];return ft&&ze.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{Y(et.id)}}),ze.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>S({kind:"entry",id:et.id,label:et.spec})}),s.jsx(mr,{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:et.spec}),s.jsx(Sm,{spec:et.spec})]}),metadata:et.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:m===et.id,onSelect:()=>K(et.id),icon:s.jsx(R,{name:Pm(et),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:ze},et.id)},e[34]=K,e[35]=Y,e[36]=c,e[37]=m,e[38]=i,e[39]=xe):xe=e[39];const ae=xe;let te;e[40]!==K||e[41]!==m||e[42]!==i?(te=et=>s.jsx(mr,{title:et.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:m===et.id,onSelect:()=>K(et.id),icon:s.jsx(R,{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:()=>S({kind:"file",id:et.id,label:et.fileName})}]},et.id),e[40]=K,e[41]=m,e[42]=i,e[43]=te):te=e[43];const pe=te;let Ie;e[44]!==i?(Ie=(et,Xe,ft)=>{const ze=ft===void 0?0:ft;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:[et,ze>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(ze===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:ze})})]}),Xe]})},e[44]=i,e[45]=Ie):Ie=e[45];const Ne=Ie;let Se;e[46]!==i?(Se=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=Se):Se=e[47];let be;e[48]!==Se?(be=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:dn,children:Se})}),e[48]=Se,e[49]=be):be=e[49];let Oe;e[50]!==i||e[51]!==ne?(Oe=i("settings.plugins.sidebar.total",{count:ne}),e[50]=i,e[51]=ne,e[52]=Oe):Oe=e[52];let Le;e[53]!==Oe?(Le=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Oe}),e[53]=Oe,e[54]=Le):Le=e[54];let oe;e[55]!==ee?(oe=()=>{ee()},e[55]=ee,e[56]=oe):oe=e[56];let fe;e[57]!==i?(fe=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=fe):fe=e[58];let Me;e[59]!==i?(Me=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=Me):Me=e[60];const $e=N?"size-4 animate-spin":"size-4";let Ve;e[61]!==$e?(Ve=s.jsx(R,{name:"refresh",className:$e}),e[61]=$e,e[62]=Ve):Ve=e[62];let qe;e[63]!==N||e[64]!==oe||e[65]!==fe||e[66]!==Me||e[67]!==Ve?(qe=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:oe,disabled:N,"aria-label":fe,title:Me,children:Ve}),e[63]=N,e[64]=oe,e[65]=fe,e[66]=Me,e[67]=Ve,e[68]=qe):qe=e[68];let se;e[69]!==i?(se=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=se):se=e[70];let ie;e[71]!==i?(ie=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=ie):ie=e[72];let we;e[73]===Symbol.for("react.memo_cache_sentinel")?(we=s.jsx(R,{name:"add",className:"size-4"}),e[73]=we):we=e[73];let ye;e[74]!==$||e[75]!==se||e[76]!==ie?(ye=s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:$,"aria-label":se,title:ie,children:we}),e[74]=$,e[75]=se,e[76]=ie,e[77]=ye):ye=e[77];let Te;e[78]!==qe||e[79]!==ye?(Te=s.jsxs("div",{className:"flex items-center gap-1",children:[qe,ye]}),e[78]=qe,e[79]=ye,e[80]=Te):Te=e[80];let Ue;e[81]!==Le||e[82]!==Te?(Ue=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Le,Te]}),e[81]=Le,e[82]=Te,e[83]=Ue):Ue=e[83];let Pe;e[84]!==be||e[85]!==Ue?(Pe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[be,Ue]}),e[84]=be,e[85]=Ue,e[86]=Pe):Pe=e[86];let je;e[87]!==z||e[88]!==w||e[89]!==Q||e[90]!==ae||e[91]!==pe||e[92]!==Ne||e[93]!==i||e[94]!==I||e[95]!==B||e[96]!==W?(je=z?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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:[B.length>0&&Ne(i("settings.plugins.sidebar.group.userEntries"),B.map(ae),I.userEntries),W.length>0&&Ne(i("settings.plugins.sidebar.group.userFiles"),W.map(pe)),w.length>0&&Ne(i("settings.plugins.sidebar.group.projectEntries"),w.map(ae),I.projectEntries),Q.length>0&&Ne(i("settings.plugins.sidebar.group.projectFiles"),Q.map(pe))]}),e[87]=z,e[88]=w,e[89]=Q,e[90]=ae,e[91]=pe,e[92]=Ne,e[93]=i,e[94]=I,e[95]=B,e[96]=W,e[97]=je):je=e[97];let Ge;e[98]!==Pe||e[99]!==je?(Ge=s.jsx(Vl,{variant:"background",header:Pe,children:je}),e[98]=Pe,e[99]=je,e[100]=Ge):Ge=e[100];let me;e[101]!==M?(me=s.jsx(Nm,{open:M,onOpenChange:P}),e[101]=M,e[102]=me):me=e[102];const Ce=y!==null;let Re;e[103]!==g?(Re=et=>{!et&&!g&&S(null)},e[103]=g,e[104]=Re):Re=e[104];let Ye;e[105]!==i?(Ye=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=Ye):Ye=e[106];let q;e[107]!==Ye?(q=s.jsx($t,{children:Ye}),e[107]=Ye,e[108]=q):q=e[108];const ke=y?.label??"";let Ae;e[109]!==i||e[110]!==ke?(Ae=i("settings.plugins.sidebar.deleteDialog.description",{name:ke}),e[109]=i,e[110]=ke,e[111]=Ae):Ae=e[111];let He;e[112]!==Ae?(He=s.jsx(Vt,{children:Ae}),e[112]=Ae,e[113]=He):He=e[113];let at;e[114]!==q||e[115]!==He?(at=s.jsxs(_t,{children:[q,He]}),e[114]=q,e[115]=He,e[116]=at):at=e[116];let nt;e[117]===Symbol.for("react.memo_cache_sentinel")?(nt=()=>S(null),e[117]=nt):nt=e[117];let dt;e[118]!==i?(dt=i("settings.common.actions.cancel"),e[118]=i,e[119]=dt):dt=e[119];let xt;e[120]!==g||e[121]!==dt?(xt=s.jsx(H,{size:"sm",variant:"ghost",onClick:nt,disabled:g,children:dt}),e[120]=g,e[121]=dt,e[122]=xt):xt=e[122];let G;e[123]!==g||e[124]!==i?(G=i(g?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=g,e[124]=i,e[125]=G):G=e[125];let Be;e[126]!==de||e[127]!==g||e[128]!==G?(Be=s.jsx(H,{size:"sm",variant:"destructive",onClick:de,disabled:g,children:G}),e[126]=de,e[127]=g,e[128]=G,e[129]=Be):Be=e[129];let st;e[130]!==xt||e[131]!==Be?(st=s.jsxs(ts,{children:[xt,Be]}),e[130]=xt,e[131]=Be,e[132]=st):st=e[132];let rt;e[133]!==at||e[134]!==st?(rt=s.jsxs(zt,{className:"max-w-md",children:[at,st]}),e[133]=at,e[134]=st,e[135]=rt):rt=e[135];let pt;e[136]!==Ce||e[137]!==Re||e[138]!==rt?(pt=s.jsx(Kt,{open:Ce,onOpenChange:Re,children:rt}),e[136]=Ce,e[137]=Re,e[138]=rt,e[139]=pt):pt=e[139];let St;return e[140]!==Ge||e[141]!==me||e[142]!==pt?(St=s.jsxs(s.Fragment,{children:[Ge,me,pt]}),e[140]=Ge,e[141]=me,e[142]=pt,e[143]=St):St=e[143],St};function Tm(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function Em(t){return t.registryInfo}function Dm(t){return t.isLoadingRegistry}function Mm(t){return t.loadRegistryInfo}function Rm(t){return t.updateToLatest}function Lm(t){return t.scope==="user"}function Om(t){return t.scope==="project"}function Fm(t){return t.scope==="user"}function Km(t){return t.scope==="project"}const zm=({entryId:t,spec:e})=>{const{t:a}=it(),n=ms(v=>v.registryInfo[e]),i=ms(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,c=n.currentVersion??"",N=async()=>{l(!0);try{(await i(t)).ok?D.success(a("settings.plugins.toast.updatedToLatest",{version:v})):D.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(R,{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:c,latest:v})})]}),s.jsx(H,{variant:"default",size:"sm",onClick:()=>{N()},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(R,{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 m=n.kind==="path-unreadable",u=m?"var(--status-warning)":"var(--status-error)",x=m?"alert":"error-warning",d=(()=>{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(R,{name:x,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:u}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:u},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:d})]})]})};function Um(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 Bl(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function bo(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Bl(t.options),fileName:"",content:""}}function vo(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const yo=t=>{const e=gt.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=ve("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},_m=()=>{const{t}=it(),e=ms(y=>y.selectedId),a=ms(y=>y.entries),n=ms(y=>y.files),i=ms(y=>y.draft),r=ms(y=>y.setDraft),l=ms(y=>y.updateEntry),m=ms(y=>y.updateFile),u=ms(y=>y.readFile),x=o.useMemo(()=>e?a.find(y=>y.id===e)??null:null,[a,e]),d=o.useMemo(()=>e?n.find(y=>y.id===e)??null:null,[n,e]),[v,c]=o.useState(!1),[N,f]=o.useState(!1),C=o.useRef(new Map);if(o.useEffect(()=>{let y=!1;return x?(r(bo(x)),()=>{y=!0}):d?(f(!0),(async()=>{const S=await u(d.id);if(y)return;f(!1);const g=S?.content??"";C.current.set(d.id,g),r(vo(d,g))})(),()=>{y=!0}):(r(null),()=>{y=!0})},[x,d,u,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(R,{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(x&&i&&i.mode==="entry"){const y=Um(i.optionsJson),S=y.ok,g=i.spec!==x.spec||i.optionsJson!==Bl(x.options),T=()=>{r(bo(x))},M=async()=>{if(!S)return;const P=i.spec.trim();if(!P){D.error(t("settings.plugins.validation.specRequired"));return}c(!0);try{const k=await l(x.id,{spec:P,options:y.value});k.ok?k.reloadFailed?D.warning(k.message||t("settings.plugins.toast.reloadFailed"),{description:k.warning}):k.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(k.message||t("settings.plugins.toast.updated")):D.error(k.message||t("settings.plugins.toast.reloadFailed"))}finally{c(!1)}};return s.jsxs(es,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(yo,{scope:x.scope,label:x.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(_e,{divider:!1,children:s.jsx(zm,{entryId:x.id,spec:x.spec})}),s.jsx(_e,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(Je,{value:i.spec,onChange:P=>r({...i,spec:P.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(_e,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(As,{value:i.optionsJson,onChange:P=>r({...i,optionsJson:P.target.value}),rows:10,className:ve("font-mono typography-meta min-h-[200px]",!S&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!S&&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:()=>{M()},disabled:!g||!S||v,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:T,disabled:!g||v,children:t("settings.plugins.page.action.discard")})]})]})]})}if(d&&i&&i.mode==="file"){const y=C.current.get(d.id)??"",S=i.content!==y||i.fileName!==d.fileName,g=()=>{(async()=>{f(!0);const P=(await u(d.id))?.content??"";f(!1),C.current.set(d.id,P),r(vo(d,P))})()},T=async()=>{c(!0);try{const M=await m(d.id,{content:i.content});M.ok?(C.current.set(d.id,i.content),M.reloadFailed?D.warning(M.message||t("settings.plugins.toast.reloadFailed"),{description:M.warning}):M.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(M.message||t("settings.plugins.toast.updated"))):D.error(M.message||t("settings.plugins.toast.reloadFailed"))}finally{c(!1)}};return s.jsx(es,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(yo,{scope:d.scope,label:d.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:ve("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:d.fileName})]}),showSaveStatus:!1,children:s.jsxs(_e,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(As,{value:i.content,onChange:M=>r({...i,content:M.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:N}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(H,{variant:"default",size:"sm",onClick:()=>{T()},disabled:!S||v||N,children:t("settings.plugins.page.action.save")}),s.jsx(H,{variant:"outline",size:"sm",onClick:g,disabled:v||N,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(R,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},$m="<built-in>",Ua=t=>t?.path===$m,ur=t=>!!t&&!Ua(t)&&t.renamable===!0,Vm=t=>{const e=gt.c(157),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,m]=o.useState(""),[u,x]=o.useState(null),[d,v]=o.useState(!1),[c,N]=o.useState(null),{selectedSkillName:f,setSelectedSkill:C,setSkillDraft:y,deleteSkill:S,renameSkill:g,getSkillDetail:T}=Vs(Ks(Bm)),M=Us();let P;e[0]!==M?(P=Ee=>vr(Ee,M),e[0]=M,e[1]=P):P=e[1];const k=Vs(P),h=Vs(Hm);let j,F;e[2]!==h||e[3]!==M?(j=()=>{h(M)},F=[h,M],e[2]=h,e[3]=M,e[4]=j,e[5]=F):(j=e[4],F=e[5]),o.useEffect(j,F);let A;e[6]!==a||e[7]!==C||e[8]!==y||e[9]!==k?(A=()=>{let Ee="new-skill",jt=1;for(;k.some(J=>J.name===Ee);)Ee=`new-skill-${jt}`,jt++;y({name:Ee,scope:"user",source:"opencode",description:""}),C(Ee),a?.()},e[6]=a,e[7]=C,e[8]=y,e[9]=k,e[10]=A):A=e[10];const I=A;let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=async Ee=>{Ua(Ee)||x(Ee)},e[11]=E):E=e[11];const B=E;let _;e[12]!==u||e[13]!==S||e[14]!==M||e[15]!==n?(_=async()=>{if(!u)return;if(Ua(u)){x(null);return}v(!0),await S(u.name,M)?(D.success(n("settings.skills.sidebar.toast.skillDeleted",{name:u.name})),x(null)):D.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),v(!1)},e[12]=u,e[13]=S,e[14]=M,e[15]=n,e[16]=_):_=e[16];const w=_;let V;e[17]!==T||e[18]!==C||e[19]!==y||e[20]!==M||e[21]!==k||e[22]!==n?(V=async Ee=>{if(Ua(Ee))return;const jt=Ee.name;let J=1,he=`${jt}-copy`;for(;k.some(De=>De.name===he);)J++,he=`${jt}-copy-${J}`;const Fe=await T(Ee.name,M);if(!Fe){D.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}y({name:he,scope:Ee.scope||"user",source:Ee.source||"opencode",description:(Fe.sources.md.fields.includes("description"),""),instructions:""}),C(he)},e[17]=T,e[18]=C,e[19]=y,e[20]=M,e[21]=k,e[22]=n,e[23]=V):V=e[23];const W=V;let L;e[24]===Symbol.for("react.memo_cache_sentinel")?(L=Ee=>{ur(Ee)&&(m(Ee.name),r(Ee))},e[24]=L):L=e[24];const Q=L;let ne;e[25]!==i||e[26]!==l||e[27]!==g||e[28]!==C||e[29]!==M||e[30]!==k||e[31]!==n?(ne=async()=>{if(!i)return;if(!ur(i)){r(null);return}const Ee=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Ee){D.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Ee===i.name){r(null);return}if(k.some(J=>J.name===Ee)){D.error(n("settings.skills.page.toast.skillExists"));return}await g(i.name,Ee,M)?(D.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Ee})),C(Ee)):D.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[25]=i,e[26]=l,e[27]=g,e[28]=C,e[29]=M,e[30]=k,e[31]=n,e[32]=ne):ne=e[32];const z=ne;let re;e[33]!==k?(re=k.filter(Gm),e[33]=k,e[34]=re):re=e[34];const $=re;let U;e[35]!==k?(U=k.filter(qm),e[35]=k,e[36]=U):U=e[36];const K=U;let O;e[37]===Symbol.for("react.memo_cache_sentinel")?(O=function(jt){const J={},he=[];for(const De of jt)De.group?(J[De.group]||(J[De.group]=[]),J[De.group].push(De)):he.push(De);const Fe=Object.keys(J).sort(Wm).map(De=>({name:De,skills:[...J[De]].sort(Jm)}));return he.sort(Qm),{sortedGroups:Fe,ungrouped:he}},e[37]=O):O=e[37];const Y=O;let X;e[38]!==$?(X=Y($),e[38]=$,e[39]=X):X=e[39];const ee=X;let ge;e[40]!==K?(ge=Y(K),e[40]=K,e[41]=ge):ge=e[41];const de=ge;let xe;e[42]===Symbol.for("react.memo_cache_sentinel")?(xe=ve("flex h-full flex-col","bg-background"),e[42]=xe):xe=e[42];let ae;e[43]!==n?(ae=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ae):ae=e[44];let te;e[45]!==ae?(te=s.jsx("h2",{className:`${dn} mb-3`,children:ae}),e[45]=ae,e[46]=te):te=e[46];let pe;e[47]===Symbol.for("react.memo_cache_sentinel")?(pe=s.jsx(Ga,{className:"mb-3"}),e[47]=pe):pe=e[47];let Ie;e[48]!==k.length||e[49]!==n?(Ie=n("settings.skills.sidebar.total",{count:k.length}),e[48]=k.length,e[49]=n,e[50]=Ie):Ie=e[50];let Ne;e[51]!==Ie?(Ne=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ie}),e[51]=Ie,e[52]=Ne):Ne=e[52];let Se;e[53]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[53]=Se):Se=e[53];let be;e[54]!==I?(be=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:I,children:Se}),e[54]=I,e[55]=be):be=e[55];let Oe;e[56]!==Ne||e[57]!==be?(Oe=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ne,be]}),e[56]=Ne,e[57]=be,e[58]=Oe):Oe=e[58];let Le;e[59]!==te||e[60]!==Oe?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[te,pe,Oe]}),e[59]=te,e[60]=Oe,e[61]=Le):Le=e[61];let oe;e[62]!==ee||e[63]!==de||e[64]!==W||e[65]!==a||e[66]!==c||e[67]!==$||e[68]!==f||e[69]!==C||e[70]!==k.length||e[71]!==n||e[72]!==K?(oe=s.jsx(Hs,{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(R,{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:[$.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")}),ee.sortedGroups.map(Ee=>{const{name:jt,skills:J}=Ee;return s.jsx(lr,{label:jt,count:J.length,storageKey:"project-skills",children:J.map(he=>s.jsx(pi,{skill:he,isSelected:f===he.name,onSelect:()=>{C(he.name),a?.()},onRename:()=>Q(he),onDelete:()=>B(he),onDuplicate:()=>W(he),isMenuOpen:c===he.name,onMenuOpenChange:Fe=>N(Fe?he.name:null)},he.name))},jt)}),ee.ungrouped.map(Ee=>s.jsx(pi,{skill:Ee,isSelected:f===Ee.name,onSelect:()=>{C(Ee.name),a?.()},onRename:()=>Q(Ee),onDelete:()=>B(Ee),onDuplicate:()=>W(Ee),isMenuOpen:c===Ee.name,onMenuOpenChange:jt=>N(jt?Ee.name:null)},Ee.name))]}),K.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")}),de.sortedGroups.map(Ee=>{const{name:jt,skills:J}=Ee;return s.jsx(lr,{label:jt,count:J.length,storageKey:"user-skills",children:J.map(he=>s.jsx(pi,{skill:he,isSelected:f===he.name,onSelect:()=>{C(he.name),a?.()},onRename:()=>Q(he),onDelete:()=>B(he),onDuplicate:()=>W(he),isMenuOpen:c===he.name,onMenuOpenChange:Fe=>N(Fe?he.name:null)},he.name))},jt)}),de.ungrouped.map(Ee=>s.jsx(pi,{skill:Ee,isSelected:f===Ee.name,onSelect:()=>{C(Ee.name),a?.()},onRename:()=>Q(Ee),onDelete:()=>B(Ee),onDuplicate:()=>W(Ee),isMenuOpen:c===Ee.name,onMenuOpenChange:jt=>N(jt?Ee.name:null)},Ee.name))]})]})}),e[62]=ee,e[63]=de,e[64]=W,e[65]=a,e[66]=c,e[67]=$,e[68]=f,e[69]=C,e[70]=k.length,e[71]=n,e[72]=K,e[73]=oe):oe=e[73];const fe=u!==null;let Me;e[74]!==d?(Me=Ee=>{!Ee&&!d&&x(null)},e[74]=d,e[75]=Me):Me=e[75];let $e;e[76]!==n?($e=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=$e):$e=e[77];let Ve;e[78]!==$e?(Ve=s.jsx($t,{children:$e}),e[78]=$e,e[79]=Ve):Ve=e[79];const qe=u?.name??"";let se;e[80]!==n||e[81]!==qe?(se=n("settings.skills.sidebar.deleteDialog.description",{name:qe}),e[80]=n,e[81]=qe,e[82]=se):se=e[82];let ie;e[83]!==se?(ie=s.jsx(Vt,{children:se}),e[83]=se,e[84]=ie):ie=e[84];let we;e[85]!==Ve||e[86]!==ie?(we=s.jsxs(_t,{children:[Ve,ie]}),e[85]=Ve,e[86]=ie,e[87]=we):we=e[87];let ye;e[88]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>x(null),e[88]=ye):ye=e[88];let Te;e[89]!==n?(Te=n("settings.common.actions.cancel"),e[89]=n,e[90]=Te):Te=e[90];let Ue;e[91]!==d||e[92]!==Te?(Ue=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:ye,disabled:d,children:Te}),e[91]=d,e[92]=Te,e[93]=Ue):Ue=e[93];let Pe;e[94]!==n?(Pe=n("settings.common.actions.delete"),e[94]=n,e[95]=Pe):Pe=e[95];let je;e[96]!==w||e[97]!==d||e[98]!==Pe?(je=s.jsx(H,{size:"sm",onClick:w,disabled:d,children:Pe}),e[96]=w,e[97]=d,e[98]=Pe,e[99]=je):je=e[99];let Ge;e[100]!==Ue||e[101]!==je?(Ge=s.jsxs(ts,{children:[Ue,je]}),e[100]=Ue,e[101]=je,e[102]=Ge):Ge=e[102];let me;e[103]!==we||e[104]!==Ge?(me=s.jsxs(zt,{className:"max-w-md",children:[we,Ge]}),e[103]=we,e[104]=Ge,e[105]=me):me=e[105];let Ce;e[106]!==fe||e[107]!==Me||e[108]!==me?(Ce=s.jsx(Kt,{open:fe,onOpenChange:Me,children:me}),e[106]=fe,e[107]=Me,e[108]=me,e[109]=Ce):Ce=e[109];const Re=i!==null;let Ye;e[110]===Symbol.for("react.memo_cache_sentinel")?(Ye=Ee=>!Ee&&r(null),e[110]=Ye):Ye=e[110];let q;e[111]!==n?(q=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=q):q=e[112];let ke;e[113]!==q?(ke=s.jsx($t,{children:q}),e[113]=q,e[114]=ke):ke=e[114];const Ae=i?.name??"";let He;e[115]!==n||e[116]!==Ae?(He=n("settings.skills.sidebar.renameDialog.description",{name:Ae}),e[115]=n,e[116]=Ae,e[117]=He):He=e[117];let at;e[118]!==He?(at=s.jsx(Vt,{children:He}),e[118]=He,e[119]=at):at=e[119];let nt;e[120]!==ke||e[121]!==at?(nt=s.jsxs(_t,{children:[ke,at]}),e[120]=ke,e[121]=at,e[122]=nt):nt=e[122];let dt;e[123]===Symbol.for("react.memo_cache_sentinel")?(dt=Ee=>m(Ee.target.value),e[123]=dt):dt=e[123];let xt;e[124]!==n?(xt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=xt):xt=e[125];let G;e[126]!==z?(G=Ee=>{Ee.key==="Enter"&&z()},e[126]=z,e[127]=G):G=e[127];let Be;e[128]!==l||e[129]!==xt||e[130]!==G?(Be=s.jsx(Je,{value:l,onChange:dt,placeholder:xt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:G}),e[128]=l,e[129]=xt,e[130]=G,e[131]=Be):Be=e[131];let st;e[132]===Symbol.for("react.memo_cache_sentinel")?(st=()=>r(null),e[132]=st):st=e[132];let rt;e[133]!==n?(rt=n("settings.common.actions.cancel"),e[133]=n,e[134]=rt):rt=e[134];let pt;e[135]!==rt?(pt=s.jsx(H,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:st,children:rt}),e[135]=rt,e[136]=pt):pt=e[136];let St;e[137]!==n?(St=n("settings.common.actions.rename"),e[137]=n,e[138]=St):St=e[138];let et;e[139]!==z||e[140]!==St?(et=s.jsx(H,{size:"sm",onClick:z,children:St}),e[139]=z,e[140]=St,e[141]=et):et=e[141];let Xe;e[142]!==pt||e[143]!==et?(Xe=s.jsxs(ts,{children:[pt,et]}),e[142]=pt,e[143]=et,e[144]=Xe):Xe=e[144];let ft;e[145]!==nt||e[146]!==Be||e[147]!==Xe?(ft=s.jsxs(zt,{children:[nt,Be,Xe]}),e[145]=nt,e[146]=Be,e[147]=Xe,e[148]=ft):ft=e[148];let ze;e[149]!==Re||e[150]!==ft?(ze=s.jsx(Kt,{open:Re,onOpenChange:Ye,children:ft}),e[149]=Re,e[150]=ft,e[151]=ze):ze=e[151];let wt;return e[152]!==Le||e[153]!==oe||e[154]!==Ce||e[155]!==ze?(wt=s.jsxs("div",{className:xe,children:[Le,oe,Ce,ze]}),e[152]=Le,e[153]=oe,e[154]=Ce,e[155]=ze,e[156]=wt):wt=e[156],wt},pi=t=>{const e=gt.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:m,isMenuOpen:u,onMenuOpenChange:x}=t,{t:d}=it();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=$a(),e[0]=v):v=e[0];const c=v;let N;e[1]!==a?(N=Ua(a),e[1]=a,e[2]=N):N=e[2];const f=N;let C;e[3]!==a?(C=ur(a),e[3]=a,e[4]=C):C=e[4];const y=C,[S,g]=o.useState(!1);let T;e[5]!==y||e[6]!==r||e[7]!==m||e[8]!==l||e[9]!==d?(T=W=>s.jsxs(s.Fragment,{children:[y?s.jsxs(W,{onClick:L=>{L.stopPropagation(),l()},children:[s.jsx(R,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}):null,s.jsxs(W,{onClick:L=>{L.stopPropagation(),m()},children:[s.jsx(R,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),s.jsxs(W,{onClick:L=>{L.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[5]=y,e[6]=r,e[7]=m,e[8]=l,e[9]=d,e[10]=T):T=e[10];const M=T,P=!f&&S,k=n?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[11]!==k?(h=ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",k),e[11]=k,e[12]=h):h=e[12];let j;e[13]!==f?(j=!c&&!f?W=>{W.preventDefault(),g(!0)}:void 0,e[13]=f,e[14]=j):j=e[14];let F;e[15]!==h||e[16]!==j?(F=s.jsx("div",{className:h,onContextMenu:j}),e[15]=h,e[16]=j,e[17]=F):F=e[17];let A;e[18]!==a.name?(A=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name})}),e[18]=a.name,e[19]=A):A=e[19];let I;e[20]!==i||e[21]!==A?(I=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:A}),e[20]=i,e[21]=A,e[22]=I):I=e[22];let E;e[23]!==f||e[24]!==u||e[25]!==x||e[26]!==M?(E=f?null:s.jsxs(ln,{open:u,onOpenChange:W=>{W&&g(!1),x(W)},children:[s.jsx(rn,{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(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:M(cn)})]}),e[23]=f,e[24]=u,e[25]=x,e[26]=M,e[27]=E):E=e[27];let B;e[28]!==I||e[29]!==E?(B=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,E]}),e[28]=I,e[29]=E,e[30]=B):B=e[30];let _;e[31]!==B||e[32]!==F?(_=s.jsx(Zn,{render:F,children:B}),e[31]=B,e[32]=F,e[33]=_):_=e[33];let w;e[34]!==f||e[35]!==M?(w=f?null:s.jsx(Yn,{className:"w-fit min-w-20",children:M(Xn)}),e[34]=f,e[35]=M,e[36]=w):w=e[36];let V;return e[37]!==_||e[38]!==w||e[39]!==P?(V=s.jsxs(ea,{open:P,onOpenChange:g,children:[_,w]}),e[37]=_,e[38]=w,e[39]=P,e[40]=V):V=e[40],V};function Bm(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Hm(t){return t.loadSkills}function Gm(t){return t.scope==="project"}function qm(t){return t.scope==="user"}function Wm(t,e){return t.localeCompare(e)}function Jm(t,e){return t.name.localeCompare(e.name)}function Qm(t,e){return t.name.localeCompare(e.name)}const Ym=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Xm=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},Zm=async()=>{try{const t=an()?.settings;if(t)return(await t.load())?.settings||{};const e=await ut("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},eu=t=>{const e=gt.c(162),{open:a,onOpenChange:n}=t,{t:i}=it(),r=hn(tu),l=hn(su),m=hn(nu),u=hn(au),x=hn(iu),d=Hn(ru),v=Hn(ou),[c,N]=o.useState(""),[f,C]=o.useState(""),[y,S]=o.useState("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[T,M]=o.useState(g),[P,k]=o.useState(null),[h,j]=o.useState(!1);let F;e[1]===Symbol.for("react.memo_cache_sentinel")?(F=[],e[1]=F):F=e[1];const[A,I]=o.useState(F),[E,B]=o.useState(null),_=o.useRef(0);let w;e[2]===Symbol.for("react.memo_cache_sentinel")?(w=Xe=>{_.current=_.current+1,j(!1),k(null),Xe?.clearIdentity&&(I([]),B(null))},e[2]=w):w=e[2];const V=w;let W,L;e[3]!==v||e[4]!==a?(W=()=>{a&&(_.current=_.current+1,N(""),C(""),S(""),k(null),j(!1),I([]),B(null),v(),(async()=>{const Xe=await Zm(),ft=Array.isArray(Xe?.skillCatalogs)?Xe?.skillCatalogs:[];M(ft||[])})())},L=[a,v],e[3]=v,e[4]=a,e[5]=W,e[6]=L):(W=e[5],L=e[6]),o.useEffect(W,L);let Q;e[7]!==f?(Q=f.trim(),e[7]=f,e[8]=Q):Q=e[8];const ne=Q;let z;e[9]!==y?(z=y.trim(),e[9]=y,e[10]=z):z=e[10];const re=z;let $;if(e[11]!==T||e[12]!==ne||e[13]!==re){let Xe;e[15]!==ne||e[16]!==re?(Xe=ft=>{const ze=(ft.source||"").trim(),wt=(ft.subpath||"").trim();return ze===ne&&wt===re},e[15]=ne,e[16]=re,e[17]=Xe):Xe=e[17],$=T.some(Xe),e[11]=T,e[12]=ne,e[13]=re,e[14]=$}else $=e[14];const U=$;let K;e[18]!==d||e[19]!==E||e[20]!==c||e[21]!==r||e[22]!==f||e[23]!==y||e[24]!==i?(K=async()=>{const Xe=f.trim();if(!Xe){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}c.trim()||N(Xm(Xe)),j(!1),k(null);const ft=_.current+1;_.current=ft;const ze=await r({source:Xe,subpath:y.trim()||void 0,gitIdentityId:E||void 0});if(_.current!==ft)return;if(!ze.ok){if(ze.error?.kind==="authRequired"){if(cs()){D.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Ee=ze.error.identities||[];if(I(Ee),!E&&Ee.length>0){const jt=d&&d!=="global"&&Ee.some(J=>J.id===d)?d:Ee[0].id;B(jt)}D.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}D.error(ze.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const wt=ze.items?.length||0;if(k(wt),wt===0){D.error(i("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}I([]),j(!0),D.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:wt}))},e[18]=d,e[19]=E,e[20]=c,e[21]=r,e[22]=f,e[23]=y,e[24]=i,e[25]=K):K=e[25];const O=K;let Y;e[26]!==T||e[27]!==E||e[28]!==U||e[29]!==c||e[30]!==l||e[31]!==m||e[32]!==n||e[33]!==h||e[34]!==u||e[35]!==f||e[36]!==y||e[37]!==i?(Y=async()=>{const Xe=c.trim(),ft=f.trim(),ze=y.trim();if(!Xe){D.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!ft){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!h){D.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(U){D.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const wt={id:Ym(),label:Xe,source:ft,...ze?{subpath:ze}:{},...E?{gitIdentityId:E}:{}},Ee=[...T,wt];try{await vt({skillCatalogs:Ee}),M(Ee),D.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await m(wt.id,{refresh:!0}),u(wt.id),n(!1)}catch(jt){const J=jt;D.error(J instanceof Error?J.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=T,e[27]=E,e[28]=U,e[29]=c,e[30]=l,e[31]=m,e[32]=n,e[33]=h,e[34]=u,e[35]=f,e[36]=y,e[37]=i,e[38]=Y):Y=e[38];const X=Y;let ee;e[39]!==i?(ee=i("settings.skills.catalog.add.title"),e[39]=i,e[40]=ee):ee=e[40];let ge;e[41]!==ee?(ge=s.jsx($t,{children:ee}),e[41]=ee,e[42]=ge):ge=e[42];let de;e[43]!==i?(de=i("settings.skills.catalog.add.descriptionPrefix"),e[43]=i,e[44]=de):de=e[44];let xe;e[45]===Symbol.for("react.memo_cache_sentinel")?(xe=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=xe):xe=e[45];let ae;e[46]!==i?(ae=i("settings.skills.catalog.add.descriptionSuffix"),e[46]=i,e[47]=ae):ae=e[47];let te;e[48]!==de||e[49]!==ae?(te=s.jsxs(Vt,{children:[de," ",xe,ae]}),e[48]=de,e[49]=ae,e[50]=te):te=e[50];let pe;e[51]!==ge||e[52]!==te?(pe=s.jsxs(_t,{children:[ge,te]}),e[51]=ge,e[52]=te,e[53]=pe):pe=e[53];let Ie;e[54]!==i?(Ie=i("settings.skills.catalog.add.field.catalogName"),e[54]=i,e[55]=Ie):Ie=e[55];let Ne;e[56]!==Ie?(Ne=s.jsx("label",{className:"typography-ui-label text-foreground",children:Ie}),e[56]=Ie,e[57]=Ne):Ne=e[57];let Se;e[58]===Symbol.for("react.memo_cache_sentinel")?(Se=Xe=>N(Xe.target.value),e[58]=Se):Se=e[58];let be;e[59]!==i?(be=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=i,e[60]=be):be=e[60];let Oe;e[61]!==c||e[62]!==be?(Oe=s.jsx(Je,{value:c,onChange:Se,placeholder:be}),e[61]=c,e[62]=be,e[63]=Oe):Oe=e[63];let Le;e[64]!==Ne||e[65]!==Oe?(Le=s.jsxs("div",{className:"space-y-2",children:[Ne,Oe]}),e[64]=Ne,e[65]=Oe,e[66]=Le):Le=e[66];let oe;e[67]!==i?(oe=i("settings.skills.catalog.add.field.repository"),e[67]=i,e[68]=oe):oe=e[68];let fe;e[69]!==oe?(fe=s.jsx("label",{className:"typography-ui-label text-foreground",children:oe}),e[69]=oe,e[70]=fe):fe=e[70];let Me;e[71]!==i?(Me=i("settings.skills.catalog.add.field.repositoryHint"),e[71]=i,e[72]=Me):Me=e[72];let $e;e[73]!==Me?($e=s.jsx(Jt,{children:Me}),e[73]=Me,e[74]=$e):$e=e[74];let Ve;e[75]!==fe||e[76]!==$e?(Ve=s.jsxs("div",{className:"flex items-center gap-1",children:[fe,$e]}),e[75]=fe,e[76]=$e,e[77]=Ve):Ve=e[77];let qe;e[78]===Symbol.for("react.memo_cache_sentinel")?(qe=Xe=>{C(Xe.target.value),V({clearIdentity:!0})},e[78]=qe):qe=e[78];let se;e[79]!==i?(se=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[79]=i,e[80]=se):se=e[80];let ie;e[81]!==f||e[82]!==se?(ie=s.jsx(Je,{value:f,onChange:qe,placeholder:se}),e[81]=f,e[82]=se,e[83]=ie):ie=e[83];let we;e[84]!==Ve||e[85]!==ie?(we=s.jsxs("div",{className:"space-y-2",children:[Ve,ie]}),e[84]=Ve,e[85]=ie,e[86]=we):we=e[86];let ye;e[87]!==i?(ye=i("settings.skills.catalog.add.field.optionalSubpath"),e[87]=i,e[88]=ye):ye=e[88];let Te;e[89]!==ye?(Te=s.jsx("label",{className:"typography-ui-label text-foreground",children:ye}),e[89]=ye,e[90]=Te):Te=e[90];let Ue;e[91]===Symbol.for("react.memo_cache_sentinel")?(Ue=Xe=>{S(Xe.target.value),V({clearIdentity:!0})},e[91]=Ue):Ue=e[91];let Pe;e[92]!==i?(Pe=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[92]=i,e[93]=Pe):Pe=e[93];let je;e[94]!==y||e[95]!==Pe?(je=s.jsx(Je,{value:y,onChange:Ue,placeholder:Pe}),e[94]=y,e[95]=Pe,e[96]=je):je=e[96];let Ge;e[97]!==Te||e[98]!==je?(Ge=s.jsxs("div",{className:"space-y-2",children:[Te,je]}),e[97]=Te,e[98]=je,e[99]=Ge):Ge=e[99];let me;e[100]!==E||e[101]!==A||e[102]!==i?(me=A.length>0&&!cs()?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(Jt,{className:"ml-1",children:i("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(It,{value:E||"",onValueChange:Xe=>{B(Xe),V()},children:[s.jsx(Pt,{className:"w-fit",children:s.jsx("span",{children:A.find(Xe=>Xe.id===E)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(At,{align:"start",children:A.map(lu)})]})]}):null,e[100]=E,e[101]=A,e[102]=i,e[103]=me):me=e[103];let Ce;e[104]!==P||e[105]!==i?(Ce=P!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:P})}):null,e[104]=P,e[105]=i,e[106]=Ce):Ce=e[106];let Re;e[107]!==U||e[108]!==i?(Re=U?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[107]=U,e[108]=i,e[109]=Re):Re=e[109];let Ye;e[110]!==Le||e[111]!==we||e[112]!==Ge||e[113]!==me||e[114]!==Ce||e[115]!==Re?(Ye=s.jsxs("div",{className:"space-y-4",children:[Le,we,Ge,me,Ce,Re]}),e[110]=Le,e[111]=we,e[112]=Ge,e[113]=me,e[114]=Ce,e[115]=Re,e[116]=Ye):Ye=e[116];let q;e[117]!==n?(q=()=>n(!1),e[117]=n,e[118]=q):q=e[118];let ke;e[119]!==i?(ke=i("settings.common.actions.cancel"),e[119]=i,e[120]=ke):ke=e[120];let Ae;e[121]!==q||e[122]!==ke?(Ae=s.jsx(H,{size:"sm",variant:"ghost",onClick:q,children:ke}),e[121]=q,e[122]=ke,e[123]=Ae):Ae=e[123];let He;e[124]!==O?(He=()=>{O()},e[124]=O,e[125]=He):He=e[125];let at;e[126]!==x||e[127]!==f?(at=x||!f.trim(),e[126]=x,e[127]=f,e[128]=at):at=e[128];let nt;e[129]===Symbol.for("react.memo_cache_sentinel")?(nt=s.jsx(R,{name:"git-repository",className:"h-4 w-4"}),e[129]=nt):nt=e[129];let dt;e[130]!==x||e[131]!==i?(dt=i(x?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[130]=x,e[131]=i,e[132]=dt):dt=e[132];let xt;e[133]!==He||e[134]!==at||e[135]!==dt?(xt=s.jsxs(H,{size:"sm",className:"gap-2",variant:"ghost",onClick:He,disabled:at,children:[nt,dt]}),e[133]=He,e[134]=at,e[135]=dt,e[136]=xt):xt=e[136];let G;e[137]!==X?(G=()=>{X()},e[137]=X,e[138]=G):G=e[138];let Be;e[139]!==U||e[140]!==c||e[141]!==h||e[142]!==f?(Be=!h||U||!c.trim()||!f.trim(),e[139]=U,e[140]=c,e[141]=h,e[142]=f,e[143]=Be):Be=e[143];let st;e[144]!==i?(st=i("settings.skills.catalog.add.actions.addCatalog"),e[144]=i,e[145]=st):st=e[145];let rt;e[146]!==G||e[147]!==Be||e[148]!==st?(rt=s.jsx(H,{size:"sm",onClick:G,disabled:Be,children:st}),e[146]=G,e[147]=Be,e[148]=st,e[149]=rt):rt=e[149];let pt;e[150]!==Ae||e[151]!==xt||e[152]!==rt?(pt=s.jsxs(ts,{children:[Ae,xt,rt]}),e[150]=Ae,e[151]=xt,e[152]=rt,e[153]=pt):pt=e[153];let St;e[154]!==pe||e[155]!==Ye||e[156]!==pt?(St=s.jsxs(zt,{className:"max-w-xl",children:[pe,Ye,pt]}),e[154]=pe,e[155]=Ye,e[156]=pt,e[157]=St):St=e[157];let et;return e[158]!==n||e[159]!==a||e[160]!==St?(et=s.jsx(Kt,{open:a,onOpenChange:n,children:St}),e[158]=n,e[159]=a,e[160]=St,e[161]=et):et=e[161],et};function tu(t){return t.scanRepo}function su(t){return t.loadCatalog}function nu(t){return t.loadSource}function au(t){return t.setSelectedSource}function iu(t){return t.isScanning}function ru(t){return t.defaultGitIdentityId}function ou(t){return t.loadDefaultGitIdentityId}function lu(t){return s.jsx(ot,{value:t.id,children:t.name},t.id)}const cu=t=>{const e=gt.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=it();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={},e[0]=m):m=e[0];const[u,x]=o.useState(m);let d,v;e[1]!==i||e[2]!==a?(d=()=>{if(!a)return;const X={};for(const ee of i)X[ee.skillName]="skip";x(X)},v=[a,i],e[1]=i,e[2]=a,e[3]=d,e[4]=v):(d=e[3],v=e[4]),o.useEffect(d,v);let c;e[5]!==i?(c=X=>{const ee={};for(const ge of i)ee[ge.skillName]=X;x(ee)},e[5]=i,e[6]=c):c=e[6];const N=c;let f;e[7]!==i||e[8]!==u?(f=i.length>0&&i.every(X=>u[X.skillName]),e[7]=i,e[8]=u,e[9]=f):f=e[9];const C=f;let y;e[10]!==l?(y=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=y):y=e[11];let S;e[12]!==y?(S=s.jsx($t,{children:y}),e[12]=y,e[13]=S):S=e[13];let g;e[14]!==l?(g=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=g):g=e[15];let T;e[16]!==g?(T=s.jsx(Vt,{children:g}),e[16]=g,e[17]=T):T=e[17];let M;e[18]!==S||e[19]!==T?(M=s.jsxs(_t,{children:[S,T]}),e[18]=S,e[19]=T,e[20]=M):M=e[20];let P;e[21]!==i.length||e[22]!==l?(P=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=l,e[23]=P):P=e[23];let k;e[24]!==P?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[24]=P,e[25]=k):k=e[25];let h;e[26]!==N?(h=()=>N("skip"),e[26]=N,e[27]=h):h=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 F;e[30]!==h||e[31]!==j?(F=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:h,children:j}),e[30]=h,e[31]=j,e[32]=F):F=e[32];let A;e[33]!==N?(A=()=>N("overwrite"),e[33]=N,e[34]=A):A=e[34];let I;e[35]!==l?(I=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=I):I=e[36];let E;e[37]!==A||e[38]!==I?(E=s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:A,children:I}),e[37]=A,e[38]=I,e[39]=E):E=e[39];let B;e[40]!==F||e[41]!==E?(B=s.jsxs("div",{className:"flex items-center gap-2",children:[F,E]}),e[40]=F,e[41]=E,e[42]=B):B=e[42];let _;e[43]!==k||e[44]!==B?(_=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,B]}),e[43]=k,e[44]=B,e[45]=_):_=e[45];let w;if(e[46]!==i||e[47]!==u||e[48]!==l){let X;e[50]!==u||e[51]!==l?(X=ee=>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:ee.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:ee.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:ee.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(It,{value:u[ee.skillName]||"skip",onValueChange:ge=>x(de=>({...de,[ee.skillName]:ge})),children:[s.jsx(Pt,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(u[ee.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(ot,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},ee.skillName),e[50]=u,e[51]=l,e[52]=X):X=e[52],w=i.map(X),e[46]=i,e[47]=u,e[48]=l,e[49]=w}else w=e[49];let V;e[53]!==w?(V=s.jsx("div",{className:"space-y-2",children:w}),e[53]=w,e[54]=V):V=e[54];let W;e[55]!==_||e[56]!==V?(W=s.jsxs("div",{className:"space-y-3",children:[_,V]}),e[55]=_,e[56]=V,e[57]=W):W=e[57];let L;e[58]!==n?(L=()=>n(!1),e[58]=n,e[59]=L):L=e[59];let Q;e[60]!==l?(Q=l("settings.common.actions.cancel"),e[60]=l,e[61]=Q):Q=e[61];let ne;e[62]!==L||e[63]!==Q?(ne=s.jsx(H,{size:"sm",variant:"ghost",onClick:L,children:Q}),e[62]=L,e[63]=Q,e[64]=ne):ne=e[64];let z;e[65]!==u||e[66]!==r?(z=()=>r(u),e[65]=u,e[66]=r,e[67]=z):z=e[67];const re=!C;let $;e[68]!==l?($=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=$):$=e[69];let U;e[70]!==z||e[71]!==re||e[72]!==$?(U=s.jsx(H,{size:"sm",onClick:z,disabled:re,children:$}),e[70]=z,e[71]=re,e[72]=$,e[73]=U):U=e[73];let K;e[74]!==ne||e[75]!==U?(K=s.jsxs(ts,{children:[ne,U]}),e[74]=ne,e[75]=U,e[76]=K):K=e[76];let O;e[77]!==M||e[78]!==W||e[79]!==K?(O=s.jsxs(zt,{className:"max-w-2xl",children:[M,W,K]}),e[77]=M,e[78]=W,e[79]=K,e[80]=O):O=e[80];let Y;return e[81]!==n||e[82]!==a||e[83]!==O?(Y=s.jsx(Kt,{open:a,onOpenChange:n,children:O}),e[81]=n,e[82]=a,e[83]=O,e[84]=Y):Y=e[84],Y},Cr=[{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 _a(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 Hl(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=Cr.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const du=t=>{const e=gt.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=it(),l=hn(pu),m=hn(mu),[u,x]=o.useState("user"),[d,v]=o.useState("opencode"),c=Bs(uu),N=Bs(gu),[f,C]=o.useState(null),[y,S]=o.useState(!1);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[T,M]=o.useState(g),[P,k]=o.useState(null);let h,j;e[1]!==N||e[2]!==a?(h=()=>{a&&(x("user"),v("opencode"),C(N),S(!1),M([]),k(null))},j=[a,N],e[1]=N,e[2]=a,e[3]=h,e[4]=j):(h=e[3],j=e[4]),o.useEffect(h,j);let F;e[5]!==r?(F=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]=F):F=e[6];const A=F;let I;e[7]!==r?(I=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]=I):I=e[8];const E=I;let B;e:{if(c.length===0){B=null;break e}if(f&&c.some(je=>je.id===f)){B=f;break e}if(N&&c.some(je=>je.id===N)){B=N;break e}B=c[0]?.id??null}const _=B;let w;e:{if(u!=="project"){w=null;break e}const je=_;if(!je){w=null;break e}let Ge;if(e[9]!==je||e[10]!==c){let Ce;e[12]!==je?(Ce=Re=>Re.id===je,e[12]=je,e[13]=Ce):Ce=e[13],Ge=c.find(Ce),e[9]=je,e[10]=c,e[11]=Ge}else Ge=e[11];w=Ge?.path??null}const V=w;let W;e[14]!==l||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==r?(W=async je=>{const Ge=await l({source:je.source,subpath:je.subpath,gitIdentityId:i?.gitIdentityId,scope:je.scope,targetSource:je.targetSource,selections:[{skillDir:je.skillDir}],conflictPolicy:"prompt",conflictDecisions:je.conflictDecisions},{directory:je.directoryOverride??null});if(Ge.ok){D.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(Ge.error?.kind==="conflicts"){k({source:je.source,subpath:je.subpath,scope:je.scope,targetSource:je.targetSource,skillDir:je.skillDir,directoryOverride:je.directoryOverride??null}),M(Ge.error.conflicts),S(!0);return}if(Ge.error?.kind==="authRequired"){D.error(Ge.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}D.error(Ge.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i?.gitIdentityId,e[16]=n,e[17]=r,e[18]=W):W=e[18];const L=W;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 ne;e[21]!==Q?(ne=s.jsx($t,{children:Q}),e[21]=Q,e[22]=ne):ne=e[22];let z;e[23]!==r?(z=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=z):z=e[24];let re;e[25]!==i.skillName?(re=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=re):re=e[26];let $;e[27]!==r?($=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=$):$=e[28];let U;e[29]!==z||e[30]!==re||e[31]!==$?(U=s.jsxs(Vt,{children:[z," ",re," ",$]}),e[29]=z,e[30]=re,e[31]=$,e[32]=U):U=e[32];let K;e[33]!==ne||e[34]!==U?(K=s.jsxs(_t,{children:[ne,U]}),e[33]=ne,e[34]=U,e[35]=K):K=e[35];let O;e[36]!==r?(O=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=O):O=e[37];let Y;e[38]!==O?(Y=s.jsx("span",{className:"typography-ui-label text-foreground",children:O}),e[38]=O,e[39]=Y):Y=e[39];let X;e[40]!==u||e[41]!==d?(X=_a(u,d),e[40]=u,e[41]=d,e[42]=X):X=e[42];let ee;e[43]===Symbol.for("react.memo_cache_sentinel")?(ee=je=>{const Ge=Hl(je);x(Ge.scope),v(Ge.source==="agents"?"agents":"opencode")},e[43]=ee):ee=e[43];let ge;e[44]!==u?(ge=u==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=u,e[45]=ge):ge=e[45];let de;e[46]!==d?(de=d==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=d,e[47]=de):de=e[47];let xe;e[48]!==A||e[49]!==u||e[50]!==d?(xe=A(_a(u,d)),e[48]=A,e[49]=u,e[50]=d,e[51]=xe):xe=e[51];let ae;e[52]!==xe?(ae=s.jsx("span",{children:xe}),e[52]=xe,e[53]=ae):ae=e[53];let te;e[54]!==ge||e[55]!==de||e[56]!==ae?(te=s.jsxs(Pt,{className:"w-fit gap-1.5",children:[ge,de,ae]}),e[54]=ge,e[55]=de,e[56]=ae,e[57]=te):te=e[57];let pe;e[58]!==E||e[59]!==A?(pe=Cr.map(je=>s.jsx(ot,{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(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),je.source==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:A(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:E(je.value)})]})},je.value)),e[58]=E,e[59]=A,e[60]=pe):pe=e[60];let Ie;e[61]!==pe?(Ie=s.jsx(At,{align:"start",children:pe}),e[61]=pe,e[62]=Ie):Ie=e[62];let Ne;e[63]!==X||e[64]!==te||e[65]!==Ie?(Ne=s.jsxs(It,{value:X,onValueChange:ee,children:[te,Ie]}),e[63]=X,e[64]=te,e[65]=Ie,e[66]=Ne):Ne=e[66];let Se;e[67]!==Y||e[68]!==Ne?(Se=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Y,Ne]}),e[67]=Y,e[68]=Ne,e[69]=Se):Se=e[69];let be;e[70]!==c||e[71]!==_||e[72]!==u||e[73]!==r?(be=u==="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")}),c.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(It,{value:_??"",onValueChange:je=>C(je),disabled:c.length===1,children:[s.jsx(Pt,{className:"w-fit",children:s.jsx(Rt,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(At,{align:"start",children:c.map(hu)})]})]}),e[70]=c,e[71]=_,e[72]=u,e[73]=r,e[74]=be):be=e[74];let Oe;e[75]!==i.warnings?(Oe=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]=Oe):Oe=e[76];let Le;e[77]!==Se||e[78]!==be||e[79]!==Oe?(Le=s.jsxs("div",{className:"mt-2 space-y-3",children:[Se,be,Oe]}),e[77]=Se,e[78]=be,e[79]=Oe,e[80]=Le):Le=e[80];let oe;e[81]!==n?(oe=()=>n(!1),e[81]=n,e[82]=oe):oe=e[82];let fe;e[83]!==r?(fe=r("settings.common.actions.cancel"),e[83]=r,e[84]=fe):fe=e[84];let Me;e[85]!==oe||e[86]!==fe?(Me=s.jsx(H,{size:"sm",variant:"ghost",onClick:oe,children:fe}),e[85]=oe,e[86]=fe,e[87]=Me):Me=e[87];const $e=m||!i.installable||u==="project"&&!V;let Ve;e[88]!==V||e[89]!==L||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==u||e[94]!==d?(Ve=()=>{L({source:i.repoSource,subpath:i.repoSubpath,scope:u,targetSource:d,skillDir:i.skillDir,directoryOverride:V})},e[88]=V,e[89]=L,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=u,e[94]=d,e[95]=Ve):Ve=e[95];let qe;e[96]!==m||e[97]!==r?(qe=r(m?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=m,e[97]=r,e[98]=qe):qe=e[98];let se;e[99]!==$e||e[100]!==Ve||e[101]!==qe?(se=s.jsx(H,{size:"sm",disabled:$e,onClick:Ve,children:qe}),e[99]=$e,e[100]=Ve,e[101]=qe,e[102]=se):se=e[102];let ie;e[103]!==Me||e[104]!==se?(ie=s.jsxs(ts,{children:[Me,se]}),e[103]=Me,e[104]=se,e[105]=ie):ie=e[105];let we;e[106]!==K||e[107]!==Le||e[108]!==ie?(we=s.jsxs(zt,{className:"max-w-md",children:[K,Le,ie]}),e[106]=K,e[107]=Le,e[108]=ie,e[109]=we):we=e[109];let ye;e[110]!==n||e[111]!==a||e[112]!==we?(ye=s.jsx(Kt,{open:a,onOpenChange:n,children:we}),e[110]=n,e[111]=a,e[112]=we,e[113]=ye):ye=e[113];let Te;e[114]!==P||e[115]!==L?(Te=je=>{P&&(L({source:P.source,subpath:P.subpath,scope:P.scope,targetSource:P.targetSource,skillDir:P.skillDir,conflictDecisions:je,directoryOverride:P.directoryOverride??null}),S(!1))},e[114]=P,e[115]=L,e[116]=Te):Te=e[116];let Ue;e[117]!==T||e[118]!==y||e[119]!==Te?(Ue=s.jsx(cu,{open:y,onOpenChange:S,conflicts:T,onConfirm:Te}),e[117]=T,e[118]=y,e[119]=Te,e[120]=Ue):Ue=e[120];let Pe;return e[121]!==ye||e[122]!==Ue?(Pe=s.jsxs(s.Fragment,{children:[ye,Ue]}),e[121]=ye,e[122]=Ue,e[123]=Pe):Pe=e[123],Pe};function pu(t){return t.installSkills}function mu(t){return t.isInstalling}function uu(t){return t.projects}function gu(t){return t.activeProjectId}function hu(t){return s.jsx(ot,{value:t.id,children:t.label||t.path},t.id)}const fu=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,xu=t=>{const e=t.trim();return fu.test(e)?`https://github.com/${e}`:null},bu=t=>{const e=xu(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let mi=null;const vu=t=>{const e=kr();return(!mi||mi.locale!==e)&&(mi={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),mi.formatter.format(t)},yu=t=>{const e=Date.parse(t);if(Number.isNaN(e))return null;const a=Date.now()-e;if(a<6e4)return{key:"common.relative.justNow",count:0};const n=Math.floor(a/6e4);if(n<60)return{key:"common.relative.minutesAgoShort",count:n};const i=Math.floor(n/60);if(i<24)return{key:"common.relative.hoursAgoShort",count:i};const r=Math.floor(i/24);if(r<7)return{key:"common.relative.daysAgoShort",count:r};const l=Math.floor(r/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(r/365)}},ju=async()=>{try{const t=an()?.settings;if(t)return(await t.load())?.settings||{};const e=await ut("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},wu=t=>{const e=gt.c(50),{source:a,isActive:n,isLoading:i,skillsCount:r,onSelect:l,t:m}=t,u=a.stars??null;let x,d,v,c,N,f,C,y,S,g;if(e[0]!==n||e[1]!==i||e[2]!==l||e[3]!==r||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==u||e[8]!==m){const k=a.repoUpdatedAt?yu(a.repoUpdatedAt):null;y="button",S=l,g=n;const h=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==h?(d=ve("w-full min-h-24 text-left rounded-lg border bg-[var(--surface-elevated)] p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",h),e[19]=h,e[20]=d):d=e[20],N="min-w-0 flex-1 block";let j;e[21]!==a.label?(j=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=j):j=e[22];let F;e[23]!==i||e[24]!==r||e[25]!==m?(F=i?s.jsx(R,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):r!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:m("settings.skills.catalog.page.source.skillsCount",{count:r})}),e[23]=i,e[24]=r,e[25]=m,e[26]=F):F=e[26],e[27]!==j||e[28]!==F?(f=s.jsxs("span",{className:"flex items-center gap-2",children:[j,F]}),e[27]=j,e[28]=F,e[29]=f):f=e[29],e[30]!==a.source?(C=s.jsx("span",{className:"typography-micro font-mono text-muted-foreground block mt-0.5 truncate",children:a.source}),e[30]=a.source,e[31]=C):C=e[31],x="flex items-center gap-3 mt-1",e[32]!==u||e[33]!==m?(v=u!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:m("settings.skills.catalog.page.source.stars",{count:u}),children:[s.jsx(R,{name:"star",className:"h-3 w-3"}),vu(u)]}),e[32]=u,e[33]=m,e[34]=v):v=e[34],c=k&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:k.key==="common.relative.justNow"?m(k.key):m("settings.skills.catalog.page.source.updated",{time:m(k.key,{count:k.count})})}),e[0]=n,e[1]=i,e[2]=l,e[3]=r,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=u,e[8]=m,e[9]=x,e[10]=d,e[11]=v,e[12]=c,e[13]=N,e[14]=f,e[15]=C,e[16]=y,e[17]=S,e[18]=g}else x=e[9],d=e[10],v=e[11],c=e[12],N=e[13],f=e[14],C=e[15],y=e[16],S=e[17],g=e[18];let T;e[35]!==x||e[36]!==v||e[37]!==c?(T=s.jsxs("span",{className:x,children:[v,c]}),e[35]=x,e[36]=v,e[37]=c,e[38]=T):T=e[38];let M;e[39]!==T||e[40]!==N||e[41]!==f||e[42]!==C?(M=s.jsxs("span",{className:N,children:[f,C,T]}),e[39]=T,e[40]=N,e[41]=f,e[42]=C,e[43]=M):M=e[43];let P;return e[44]!==d||e[45]!==M||e[46]!==y||e[47]!==S||e[48]!==g?(P=s.jsx("button",{type:y,onClick:S,"aria-pressed":g,className:d,children:M}),e[44]=d,e[45]=M,e[46]=y,e[47]=S,e[48]=g,e[49]=P):P=e[49],P},ku=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=it(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:m,loadCatalog:u,loadSource:x,isLoadingCatalog:d,isLoadingSource:v,loadedSourceIds:c,lastCatalogError:N}=hn(Ks(L=>({sources:L.sources,itemsBySource:L.itemsBySource,selectedSourceId:L.selectedSourceId,setSelectedSource:L.setSelectedSource,loadCatalog:L.loadCatalog,loadSource:L.loadSource,isLoadingCatalog:L.isLoadingCatalog,isLoadingSource:L.isLoadingSource,loadedSourceIds:L.loadedSourceIds,lastCatalogError:L.lastCatalogError}))),[f,C]=o.useState(""),[y,S]=o.useState(!1),[g,T]=o.useState(!1),[M,P]=o.useState(null),[k,h]=o.useState(!1),[j,F]=o.useState(!1),A=o.useRef(null);o.useEffect(()=>{u()},[u]),o.useEffect(()=>{const L=i.filter(z=>!c[z.id]);if(L.length===0)return;let Q=!1;return(async()=>{for(const z of L){if(Q)return;await x(z.id)}})(),()=>{Q=!0}},[i,c,x]),o.useEffect(()=>{!l||c[l]||x(l)},[l,c,x]),o.useEffect(()=>{const L=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key.toLowerCase()==="k"&&(Q.preventDefault(),A.current?.focus())};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[]);const I=f.trim().length>0,E=o.useMemo(()=>I?Ni(i.flatMap(L=>r[L.id]||[]),f,L=>[L.skillName,L.frontmatterName,L.description]):l?r[l]||[]:[],[i,r,l,f,I]),B=o.useMemo(()=>i.find(L=>L.id===l)||null,[i,l]),_=!!(l&&l.startsWith("custom:")),w=async()=>{if(!(!l||!_)){h(!0);try{const L=await ju(),ne=(Array.isArray(L?.skillCatalogs)?L?.skillCatalogs:[]).filter(z=>z.id!==l);await vt({skillCatalogs:ne}),await u({refresh:!0}),F(!1)}finally{h(!1)}}},V=I?n("settings.skills.catalog.page.list.searchTitle"):B?.label??"",W=!I&&l!==null&&!c[l]&&(v||d);return s.jsxs(s.Fragment,{children:[s.jsxs(es,{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(Sr,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:L=>e(L),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:n("settings.skills.catalog.page.subtitle")}),s.jsx("div",{"data-settings-item":"skills.catalog.search",className:"mb-5",children:s.jsxs("div",{className:"relative max-w-md",children:[s.jsx(R,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Je,{ref:A,value:f,onChange:L=>C(L.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:ve("h-8 pl-8 w-full",f&&"pr-8")}),f&&s.jsx("button",{type:"button",onClick:()=>{C(""),A.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center h-4 w-4 rounded text-muted-foreground hover:text-foreground transition-colors",title:n("settings.skills.catalog.page.search.clear"),children:s.jsx(R,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(_e,{title:n("settings.skills.catalog.page.section.sources"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 py-1.5",children:[i.map(L=>s.jsx(wu,{source:L,isActive:L.id===l,isLoading:v&&!c[L.id],skillsCount:c[L.id]?(r[L.id]||[]).length:null,onSelect:()=>m(L.id),t:n},L.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>S(!0),className:"min-h-24 text-left rounded-lg border border-dashed border-[var(--interactive-border)] hover:border-[var(--interactive-border-hover)] hover:bg-[var(--surface-muted)] p-3.5 flex gap-3 items-start transition-colors",children:[s.jsx("span",{className:"flex items-center justify-center rounded-md bg-transparent text-muted-foreground w-8 h-8 shrink-0",children:s.jsx(R,{name:"add",className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground block",children:n("settings.skills.catalog.page.source.addOwnTitle")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 block mt-0.5",children:n("settings.skills.catalog.page.source.addOwnDescription")})]})]})]})}),N&&s.jsx(_e,{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:N.message})]})}),s.jsxs(_e,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 pb-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"typography-micro font-medium uppercase tracking-wide text-muted-foreground truncate",children:V}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:E.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!I?x(l,{refresh:!0}):u({refresh:!0})},disabled:d||v,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(R,{name:"refresh",className:ve("h-3.5 w-3.5",(d||v)&&"animate-spin")})}),_&&!I&&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:()=>F(!0),disabled:k,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),W||v&&E.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(R,{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")})]}):E.length===0?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")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:E.map(L=>{const Q=L.installed?.isInstalled,ne=L.installed?.scope,z=bu(L);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:L.skillName}),Q&&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:ne||n("settings.skills.catalog.page.badge.unknown")})}),!L.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")})]}),L.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:L.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:n("settings.skills.catalog.shared.noDescription")}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80 mt-1 flex items-center gap-2 min-w-0",children:[z?s.jsxs("a",{href:z,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline truncate inline-flex items-center gap-1",title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:[s.jsx(R,{name:"github",className:"h-3 w-3 shrink-0"}),L.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:L.repoSource}),L.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:L.skillDir})]})]}),L.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:L.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[z&&s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(z,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"})}),Q?s.jsx("span",{className:"text-[var(--status-success)] flex items-center justify-center w-7 h-7",title:n("settings.skills.catalog.page.badge.installed",{scope:ne||""}),children:s.jsx(R,{name:"check",className:"h-4 w-4"})}):s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",disabled:!L.installable,onClick:()=>{P(L),T(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${L.sourceId}:${L.skillDir}`)})})]})]}),s.jsx(eu,{open:y,onOpenChange:S}),s.jsx(du,{open:g,onOpenChange:T,item:M}),s.jsx(Kt,{open:j,onOpenChange:L=>{k||F(L)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Vt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>F(!1),disabled:k,children:n("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{w()},disabled:k,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},Nu=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(ku,{mode:"external",onModeChange:Tu,showModeTabs:!1}),t[0]=e):e=t[0],e},Su="SKILL.md",Cu="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",ji=(t,e)=>{const a=Xd({description:t}).trimEnd(),n=e.trimStart();return`---
22
+ ${a}
23
+ ---${n?`
24
+
25
+ ${n}`:`
26
+ `}`},Iu=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Gl=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=Zd(e[1]);if(Iu(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},Pu=(t,e)=>{const a=Gl(t);return ji(e,a.instructions)},Au=()=>{const{t}=it(),{currentTheme:e}=Nr(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skillDraft:m,setSkillDraft:u,setSelectedSkill:x}=Vs(Ks(me=>({selectedSkillName:me.selectedSkillName,getSkillByName:me.getSkillByName,getSkillDetail:me.getSkillDetail,createSkill:me.createSkill,updateSkill:me.updateSkill,skillDraft:me.skillDraft,setSkillDraft:me.setSkillDraft,setSelectedSkill:me.setSelectedSkill}))),d=Us(),v=Vs(me=>vr(me,d)),c=a?n(a,d):null,N=!!(m&&m.name===a&&!c),f=!!(a&&!c&&!m),C=c?.path==="<built-in>";o.useEffect(()=>{f&&x(null)},[f,x]);const[y,S]=o.useState(""),[g,T]=o.useState("user"),[M,P]=o.useState("opencode"),[k,h]=o.useState(""),[j,F]=o.useState(""),[A,I]=o.useState(()=>ji("","")),[E,B]=o.useState("edit"),[_,w]=o.useState([]),[V,W]=o.useState([]),[L,Q]=o.useState(!1),[ne,z]=o.useState(!1),[re,$]=o.useState(""),[U,K]=o.useState(""),[O,Y]=o.useState(!1),[X,ee]=o.useState(""),[ge,de]=o.useState(""),[xe,ae]=o.useState(null),[te,pe]=o.useState(!1),[Ie,Ne]=o.useState(""),[Se,be]=o.useState(null),[Oe,Le]=o.useState(!1),oe=N?y.trim()!==""||k.trim()!==""||j.trim()!==""||V.length>0:k!==re||j!==U,fe=xe?ge!==Ie:X.trim()!=="",Me=o.useCallback(me=>{switch(me){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]),$e=o.useCallback(me=>{switch(me){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(N&&m){const Ce=m.description||"",Re=m.instructions||"";S(m.name||""),T(m.scope||"user"),P(m.source==="agents"?"agents":"opencode"),h(Ce),F(Re),I(ji(Ce,Re)),$(""),K(""),w([]),W(m.pendingFiles||[])}else if(a&&c){z(!0);try{const Ce=await i(a,d);if(Ce){const Re=Ce.sources.md,Ye=Re.description||"",q=Re.instructions||"";h(Ye),F(q),I(ji(Ye,q)),$(Ye),K(q),w(Re.supportingFiles||[])}}catch(Ce){console.error("Failed to load skill details:",Ce)}finally{z(!1)}}})()},[c,N,a,d,v,m,i]);const Ve=le(me=>me.editorFontSize),qe=o.useMemo(()=>{const me=[so(e,{fontSize:Ve})],Ce=Or(Su);return Ce&&me.push(Ce),me.push(ao.lineWrapping),me},[e,Ve]),se=o.useMemo(()=>{const me=X.trim()||"supporting-file.md",Ce=Nc(me),Re=!!Ce&&Ce!=="markdown",Ye=[so(e,Re?{syntaxColors:!1,fontSize:Ve}:{fontSize:Ve})],q=Or(me);return q&&Ye.push(q),Re&&Ce&&Ye.push(ep({language:Ce,themeName:e.metadata.id,theme:sp(e)})),Ye.push(ao.lineWrapping),Ye},[e,X,Ve]),ie=o.useCallback(me=>{h(me),I(Ce=>Pu(Ce,me))},[]),we=o.useCallback(me=>{I(me);const Ce=Gl(me);h(Ce.description??""),F(Ce.instructions)},[]),ye=async()=>{const me=N?y.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!me){D.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(me)||me.length>64){D.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!k.trim()){D.error(t("settings.skills.page.toast.descriptionRequired"));return}if(N&&v.some(Ce=>Ce.name===me)){D.error(t("settings.skills.page.toast.skillExists"));return}Q(!0);try{const Ce={name:me,description:k.trim(),instructions:j.trim()||void 0,scope:N?g:void 0,source:N?M:void 0,targetPath:N?void 0:c?.path,supportingFiles:N&&V.length>0?V:void 0};let Re;if(N?(Re=await r(Ce,d),Re&&(u(null),W([]),x(me))):(Re=await l(me,Ce,d),Re&&($(k.trim()),K(j.trim()))),Re){const Ye=qn.getState().changes.some(q=>q.scope==="skills"&&q.id.startsWith(`skills:${me}:`));D.success(t(Ye?"settings.view.pendingRestart.saved":N?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else D.error(t(N?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Ce){console.error("Error saving skill:",Ce),D.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{Q(!1)}},Te=()=>{ae(null),ee(""),de(""),Ne(""),Y(!0)},Ue=async me=>{if(ae(me),ee(me),N){const Re=V.find(Ye=>Ye.path===me)?.content||"";de(Re),Ne(Re),Y(!0);return}if(a){pe(!0),Y(!0);try{const{readSupportingFile:Ce}=Vs.getState(),Re=await Ce(a,me,d);de(Re||""),Ne(Re||"")}catch{D.error(t("settings.skills.page.toast.loadFileContentFailed")),de(""),Ne("")}finally{pe(!1)}}},Pe=async()=>{if(!X.trim()){D.error(t("settings.skills.page.toast.fileNameRequired"));return}const me=X.trim(),Ce=xe!==null;if(N){if(Ce)W(q=>q.map(ke=>ke.path===xe?{path:me,content:ge}:ke)),D.success(t("settings.skills.page.toast.fileUpdated",{path:me}));else{if(V.some(q=>q.path===me)){D.error(t("settings.skills.page.toast.fileExists"));return}W(q=>[...q,{path:me,content:ge}]),D.success(t("settings.skills.page.toast.fileAdded",{path:me}))}Y(!1),ae(null);return}if(!a){D.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Re}=Vs.getState();if(await Re(a,me,ge,d)){D.success(Ce?t("settings.skills.page.toast.fileUpdated",{path:me}):t("settings.skills.page.toast.fileCreated",{path:me})),Y(!1),ae(null);const q=await i(a,d);q&&w(q.sources.md.supportingFiles||[])}else D.error(t(Ce?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},je=me=>{if(N){W(Ce=>Ce.filter(Re=>Re.path!==me)),D.success(t("settings.skills.page.toast.fileRemoved",{path:me}));return}a&&be(me)},Ge=async()=>{if(!Se||!a)return;Le(!0);const{deleteSupportingFile:me}=Vs.getState();if(await me(a,Se,d)){D.success(t("settings.skills.page.toast.fileDeleted",{path:Se}));const Re=await i(a,d);Re&&w(Re.sources.md.supportingFiles||[]),be(null)}else D.error(t("settings.skills.page.toast.deleteFileFailed"));Le(!1)};return!a&&!m||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(R,{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")})]})}):ne?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(es,{title:N?t("settings.skills.page.title.newSkill"):a,description:c?t("settings.skills.page.subtitle.skillLocation",{location:Me(_a(c.scope,c.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(_e,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[N&&s.jsxs(Lt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(Je,{value:y,onChange:me=>S(me.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(It,{value:_a(g,M),onValueChange:me=>{const Ce=Hl(me);T(Ce.scope),P(Ce.source==="agents"?"agents":"opencode")},children:[s.jsxs(Pt,{size:Ft,className:"w-fit gap-1.5",children:[g==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),M==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Me(_a(g,M))})]}),s.jsx(At,{align:"start",children:Cr.map(me=>s.jsx(ot,{value:me.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[me.scope==="user"?s.jsx(R,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"folder",className:"h-3.5 w-3.5"}),me.source==="agents"?s.jsx(R,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Me(me.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:$e(me.value)})]})},me.value))})]})]}),s.jsx(Wt,{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(As,{value:k,onChange:me=>ie(me.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:C})})]}),s.jsx(_e,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(tp,{currentMode:E==="preview"?"preview":"edit",onToggle:()=>B(me=>me==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:ve("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",Cu),children:E==="preview"?s.jsx(Hs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(Sc,{content:A,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(no,{value:A,onChange:we,readOnly:C,extensions:qe,className:"h-full",enableSearch:!0})})}),s.jsx(_e,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(H,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Te,disabled:C,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const me=N?V:_;return me.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:me.map(Ce=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Ue(Ce.path),children:[s.jsx(R,{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:Ce.path}),N&&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")}),!C&&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:Re=>{Re.stopPropagation(),je(Ce.path)},children:s.jsx(R,{name:"delete-bin",className:"h-3 w-3"})})]},Ce.path))})})()}),s.jsx(_e,{children:s.jsx(H,{onClick:ye,disabled:C||L||!oe,size:"xs",className:"!font-normal",children:t(L?"settings.common.actions.saving":N?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Kt,{open:Se!==null,onOpenChange:me=>{!me&&!Oe&&be(null)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Vt,{children:t("settings.skills.page.deleteFileDialog.description",{path:Se??""})})]}),s.jsxs(ts,{children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>be(null),disabled:Oe,children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:Ge,disabled:Oe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Kt,{open:O,onOpenChange:me=>{Y(me),me||ae(null)},children:s.jsxs(zt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(_t,{className:"flex-shrink-0",children:[s.jsx($t,{children:t(xe?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Vt,{children:t(xe?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),te?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:Et,children:t("settings.skills.page.fileDialog.field.filePath")}),!xe&&s.jsx(Jt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(Je,{value:X,onChange:me=>ee(me.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:xe!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Et} 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(no,{value:ge,onChange:de,extensions:se,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(ts,{className:"mt-4",children:[s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>{Y(!1),ae(null)},children:t("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",onClick:Pe,disabled:te||!fe,children:t(xe?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},jo=t=>{const e=gt.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(Nu,{}):s.jsx(Au,{}),e[0]=n,e[1]=i):i=e[1],i};function Tu(){}const Eu=t=>{const e=gt.c(38),{onItemSelect:a}=t,{t:n}=it(),i=Bs(Du),r=le(Mu),l=le(Ru),{currentTheme:m}=Nr();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=cs(),e[0]=u):u=e[0];const x=u,d=Lu;let v,c;e[1]!==i||e[2]!==r||e[3]!==l?(v=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(h=>h.id===r)||l(i[0].id)},c=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=v,e[5]=c):(v=e[4],c=e[5]),o.useEffect(v,c);let N;e[6]===Symbol.for("react.memo_cache_sentinel")?(N=ve("border-b px-3","pt-4 pb-3"),e[6]=N):N=e[6];let f;e[7]!==n?(f=n("settings.page.projects.title"),e[7]=n,e[8]=f):f=e[8];let C;e[9]!==f?(C=s.jsx("h2",{className:`${dn} mb-3`,children:f}),e[9]=f,e[10]=C):C=e[10];let y;e[11]!==i.length||e[12]!==n?(y=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=y):y=e[13];let S;e[14]!==y?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:y}),e[14]=y,e[15]=S):S=e[15];let g;e[16]!==n?(g=!x&&s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:d,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(R,{name:"add",className:"size-4"})}),e[16]=n,e[17]=g):g=e[17];let T;e[18]!==S||e[19]!==g?(T=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,g]}),e[18]=S,e[19]=g,e[20]=T):T=e[20];let M;e[21]!==T||e[22]!==C?(M=s.jsxs("div",{className:N,children:[C,T]}),e[21]=T,e[22]=C,e[23]=M):M=e[23];let P;if(e[24]!==m||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let h;e[30]!==m||e[31]!==a||e[32]!==r||e[33]!==l?(h=j=>{const F=j.id===r,A=j.icon?Ic[j.icon]:null,I=j.color?Pc[j.color]??null:null,E=A?s.jsx(R,{name:A,className:ve("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:I?{color:I}:void 0}):s.jsx(R,{name:"folder",className:ve("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:I?{color:I}:void 0}),B=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(Ac,{project:j,options:{themeVariant:m.metadata.variant,iconColor:m.colors.surface.foreground},className:"h-full w-full object-contain",fallback:E})}):E;return s.jsx(mr,{title:j.label||j.path,icon:B,selected:F,onSelect:()=>{l(j.id),a?.()}},j.id)},e[30]=m,e[31]=a,e[32]=r,e[33]=l,e[34]=h):h=e[34],P=i.map(h),e[24]=m,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=P}else P=e[29];let k;return e[35]!==M||e[36]!==P?(k=s.jsx(Vl,{variant:"background",header:M,children:P}),e[35]=M,e[36]=P,e[37]=k):k=e[37],k};function Du(t){return t.projects}function Mu(t){return t.settingsProjectsSelectedId}function Ru(t){return t.setSettingsProjectsSelectedId}function Lu(){Cc.requestDirectoryDialog()}const Ou=()=>{const t=gt.c(30),{t:e}=it(),a=Bs(Fu),n=Bs(Ku),i=le(zu),r=le(Uu);let l;e:{if(!i){l=null;break e}let y;t[0]!==a||t[1]!==i?(y=a.find(S=>S.id===i)??null,t[0]=a,t[1]=i,t[2]=y):y=t[2],l=y}const m=l;let u,x;t[3]!==a||t[4]!==i||t[5]!==r?(u=()=>{if(a.length===0){r(null);return}i&&a.some(y=>y.id===i)||r(a[0].id)},x=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=u,t[7]=x):(u=t[6],x=t[7]),o.useEffect(u,x);let d;t[8]!==m||t[9]!==n?(d=async y=>{m&&n(m.id,{label:y.label,icon:y.icon,color:y.color,iconBackground:y.iconBackground,defaultModel:y.defaultModel??null,defaultVariant:y.defaultVariant??null})},t[8]=m,t[9]=n,t[10]=d):d=t[10];const v=d;if(!m){let y;t[11]!==e?(y=e("settings.page.projects.title"),t[11]=e,t[12]=y):y=t[12];let S;t[13]!==e?(S=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=S):S=t[14];let g;t[15]!==S?(g=s.jsx("p",{className:"typography-meta text-muted-foreground",children:S}),t[15]=S,t[16]=g):g=t[16];let T;return t[17]!==y||t[18]!==g?(T=s.jsx(es,{title:y,showSaveStatus:!0,children:g}),t[17]=y,t[18]=g,t[19]=T):T=t[19],T}let c;t[20]!==m.label||t[21]!==e?(c=m.label??e("settings.projects.page.title.default"),t[20]=m.label,t[21]=e,t[22]=c):c=t[22];const N=c;let f;t[23]!==v||t[24]!==m?(f=s.jsx(Bd,{project:m,onIdentitySave:v}),t[23]=v,t[24]=m,t[25]=f):f=t[25];let C;return t[26]!==N||t[27]!==m.path||t[28]!==f?(C=s.jsx(es,{title:N,description:m.path,showSaveStatus:!0,outerClassName:"bg-background",children:f}),t[26]=N,t[27]=m.path,t[28]=f,t[29]=C):C=t[29],C};function Fu(t){return t.projects}function Ku(t){return t.updateProjectMeta}function zu(t){return t.settingsProjectsSelectedId}function Uu(t){return t.setSettingsProjectsSelectedId}const wi=()=>Math.floor(2e4+Math.random()*3e4),_u=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")},$u=()=>{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"},wo=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}},ko=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"}},Vu=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Ir=t=>!!(t&&Vu.has(t)),No=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||Ir(t)?"connecting":"idle",So=t=>{switch(t){case"ready":return"settings.remoteInstances.page.state.ready";case"connecting":return"settings.remoteInstances.page.state.connecting";case"error":return"settings.remoteInstances.page.state.problem";default:return"settings.remoteInstances.page.state.notConnected"}},Bu=t=>{const e=(t||"").toLowerCase();return e?e.includes("ui authentication")||e.includes("ui password")?"uiPassword":e.includes("already in use")||e.includes("eaddrinuse")?"localPort":e.includes("neither bun nor npm")?"noRuntime":e.includes("opencode cli is not installed")?"noOpencode":e.includes("requires a ui password")?"uiPassword":e.includes("preferred remote openchamber port")?"externalPort":null:null},Co={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Hu=t=>t==="noRuntime"?Co.noRuntime:t==="noOpencode"?Co.noOpencode:null,Io=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Ir(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Gu=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}`,qu=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:wi(),remoteHost:"127.0.0.1",remotePort:80}),Wu=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",$s=t=>{const e=gt.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(Jt,{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 ${Et}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},Ju=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"}},Po=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Qu=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Yu=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}`},gr=(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}),Xu=t=>t.trim().toLowerCase()==="authorization",Yi=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!Xu(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},Zu=t=>Object.entries(t||{}).map(([e,a])=>gr(e,a)),ql=()=>{if(typeof window>"u")return null;const e=Ba()||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}},Ao=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},eg=async()=>{const t=ha(Ba())||window.location.origin;if(!as()||!Ha())return t;let e;try{e=await ut("/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 Al(),i=ql();return!n||!i?t:`http://${n}:${i}`},ui=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},tg=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}},sg=()=>{const{t}=it(),e=le(b=>b.timeFormatPreference),{clientAuth:a}=jl(),n=as(),i=Is(b=>b.instances),r=Is(b=>b.statusesById),l=Is(b=>b.importCandidates),m=Is(b=>b.isLoading),u=Is(b=>b.isImportsLoading),x=Is(b=>b.isSaving),d=Is(b=>b.error),v=Is(b=>b.load),c=Is(b=>b.loadImports),N=Is(b=>b.refreshStatuses),f=Is(b=>b.upsertInstance),C=Is(b=>b.createFromCommand),y=Is(b=>b.removeInstance),S=Is(b=>b.connect),g=Is(b=>b.disconnect),T=Is(b=>b.retry),M=le(b=>b.settingsRemoteInstancesSelectedId),P=le(b=>b.setSettingsRemoteInstancesSelectedId),k=o.useMemo(()=>M&&i.find(b=>b.id===M)||null,[i,M]),[h,j]=o.useState(null),[F,A]=o.useState(!1),[I,E]=o.useState(!1),[B,_]=o.useState(null),[w,V]=o.useState([]),[W,L]=o.useState(null),[Q,ne]=o.useState(""),[z,re]=o.useState(!1),[$,U]=o.useState({}),[K,O]=o.useState(!1),[Y,X]=o.useState(!1),[ee,ge]=o.useState(()=>Date.now()),[de,xe]=o.useState([]),[ae,te]=o.useState({}),[pe,Ie]=o.useState("local"),[Ne,Se]=o.useState(!1),[be,Oe]=o.useState(!1),[Le,oe]=o.useState(""),[fe,Me]=o.useState(""),[$e,Ve]=o.useState(""),[qe,se]=o.useState([]),[ie,we]=o.useState(""),[ye,Te]=o.useState(null),[Ue,Pe]=o.useState(!1),[je,Ge]=o.useState(!1),[me,Ce]=o.useState(null),[Re,Ye]=o.useState(""),[q,ke]=o.useState(""),[Ae,He]=o.useState(""),[at,nt]=o.useState([]),[dt,xt]=o.useState([]),[G,Be]=o.useState([]),[st,rt]=o.useState(!1),[pt,St]=o.useState(""),[et,Xe]=o.useState(null),[ft,ze]=o.useState(null),[wt,Ee]=o.useState(null),[jt,J]=o.useState(null),[he,Fe]=o.useState(!1),[De,lt]=o.useState(!1),[ct,Qe]=o.useState("configure"),[kt,bs]=o.useState(!1),[Xt,Ls]=o.useState("relay"),[Gt,is]=o.useState(!0),[Ht,vs]=o.useState(null),us=o.useMemo(()=>dt.filter(b=>!!b.revokedAt).length,[dt]),[gs,ds]=o.useState(!1),[Ts,ce]=o.useState("saved"),[mt,yt]=o.useState(""),[Qt,Yt]=o.useState(""),[Bt,rs]=o.useState(""),[ys,ss]=o.useState(!1);o.useEffect(()=>{v(),c()},[v,c]);const Nt=o.useCallback(async()=>{Se(!0),Te(null);try{const b=await Hr();xe(b.hosts||[]),Ie(b.defaultHostId||"local")}catch(b){Te(b instanceof Error?b.message:String(b))}finally{Se(!1)}},[]);o.useEffect(()=>{Nt()},[Nt]);const Tt=o.useCallback(async(b,Z=pe)=>{Oe(!0),Te(null);try{await Gr({hosts:b,defaultHostId:Z,initialHostChoiceCompleted:!0}),xe(b),Ie(Z)}catch(Ke){Te(Ke instanceof Error?Ke.message:String(Ke))}finally{Oe(!1)}},[pe]),Ut=o.useCallback(async()=>{const b=qr(fe);if(!b){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const Z=b.persistedUrl,tt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Le.trim()||Ia(Z),url:Z,apiUrl:Z,...$e.trim()?{clientToken:$e.trim()}:{},...Yi(qe)?{requestHeaders:Yi(qe)}:{}};await Tt([tt,...de],pe),oe(""),Me(""),Ve(""),se([]),Pe(!1),b.redeemUrl&&ui(b.redeemUrl)},[pe,qe,de,Le,$e,fe,Tt,t]),Ot=o.useCallback(async()=>{const b=gd(ie);if(!b){Te(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const Z=await hd().catch(()=>""),Ke=JSON.stringify({pairingId:b.pairingId,secret:b.secret,clientLabel:b.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:$u(),...Z?{dedupeKey:`desktop:${Z}`}:{}}),tt={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Ke},Dt=async Mt=>{if(!Mt.ok)return null;const Ms=await Mt.json().catch(()=>null);return(typeof Ms?.clientToken=="string"?Ms.clientToken.trim():"")||null},Ds=[...b.candidates].sort((Mt,Ms)=>(Mt.type==="relay"?1:0)-(Ms.type==="relay"?1:0));let ws=null;for(const Mt of Ds){if(Mt.type==="relay"){const Un=fd({relayUrl:Mt.relayUrl,serverId:Mt.serverId,hostEncPubJwk:Mt.hostEncPubJwk,...Mt.grant?{grant:Mt.grant}:{}});try{const kn=await Un.fetch("/api/client-auth/pairing/redeem",tt),Ca=await Dt(kn);if(Ca){ws={kind:"relay",relay:{relayUrl:Mt.relayUrl,serverId:Mt.serverId,hostEncPubJwk:Mt.hostEncPubJwk},token:Ca};break}}catch{}finally{Un.close()}continue}const Ms=ha(Mt.url);if(Ms)try{const Un=await fetch(`${Ms}/api/client-auth/pairing/redeem`,tt),kn=await Dt(Un);if(kn){ws={kind:"direct",url:Ms,token:kn};break}}catch{}}if(!ws){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const _s=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,ks=b.candidates.find(Mt=>Mt.type==="relay"),qs=ws.kind==="relay"?ws.relay:ks?{relayUrl:ks.relayUrl,serverId:ks.serverId,hostEncPubJwk:ks.hostEncPubJwk}:void 0,Sa=b.candidates.filter(Mt=>Mt.type!=="relay").map(Mt=>ha(Mt.url)).find(Mt=>!!Mt),un=ws.kind==="direct"?ws.url:Sa,{token:Ws}=ws,Ct=un||(qs?xd(qs.serverId):null);if(!Ct){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const qt={url:Ct,apiUrl:un||void 0,clientToken:Ws,...qs?{relay:qs}:{}},zn=de.find(Mt=>qs?Mt.relay?.serverId===qs.serverId:!Mt.relay&&ha(Mt.apiUrl||Mt.url)===Ct);if(zn){const Mt=de.map(Ms=>Ms.id===zn.id?{...Ms,label:b.label||Ms.label,...qt}:Ms);await Tt(Mt,pe)}else await Tt([{id:_s(),label:b.label||Ia(Ct),...qt},...de],pe);we(""),Te(null),Ge(!1)},[ie,pe,de,Tt,t]),ns=o.useCallback(async b=>{const Z=de.filter(tt=>tt.id!==b);await Tt(Z,pe===b?"local":pe),me===b&&Ce(null)},[pe,me,de,Tt]),Es=o.useCallback(b=>{Ce(b.id),Ye(b.label),ke(b.apiUrl||b.url),He(b.clientToken||""),nt(Zu(b.requestHeaders)),Te(null)},[]),qa=o.useCallback(async()=>{if(!me)return;const b=qr(q);if(!b){Te(t("desktopHostSwitcher.error.invalidUrl"));return}const Z=b.persistedUrl,Ke=de.map(tt=>tt.id===me?{...tt,label:Re.trim()||Ia(Z),url:Z,apiUrl:Z,clientToken:Ae.trim()||void 0,requestHeaders:Yi(at)}:tt);await Tt(Ke,pe),Ce(null),b.redeemUrl&&ui(b.redeemUrl)},[pe,at,Re,Ae,q,me,de,Tt,t]),Ti=o.useCallback(async()=>{const b=Qt.trim();if(!b){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const Z=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await C(Z,b,Bt.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),P(Z),ds(!1),Yt(""),rs(""),D.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Ke){D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Ke instanceof Error?Ke.message:String(Ke)})}},[C,P,Qt,Bt,t]),Wa=o.useCallback(()=>{yt(""),ce(l.length>0?"saved":"manual"),ds(!0)},[l.length]),Ei=o.useCallback(async b=>{await Tt(de,b)},[de,Tt]);o.useEffect(()=>{if(!n||de.length===0)return;let b=!1;return Promise.all(de.map(async Z=>{const Ke=()=>kd(Z.relay,{clientToken:Z.clientToken||null,requestHeaders:Z.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Z.relay&&!Z.apiUrl)return[Z.id,await Ke()];const tt=ha(bd(Z));if(!tt)return[Z.id,Z.relay?await Ke():{status:"unreachable",latencyMs:0}];const Dt=await vd(tt,{clientToken:Z.clientToken||null,requestHeaders:Z.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(Dt.status==="unreachable"&&Z.relay){const Ds=await Ke();if(Ds.status==="ok")return[Z.id,Ds]}return[Z.id,Dt]})).then(Z=>{b||te(Object.fromEntries(Z))}),()=>{b=!0}},[de,n]);const zs=o.useCallback(async b=>{if(a){b?.silent||rt(!0),b?.silent||Xe(null);try{const[Z,Ke]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);xt(Z),Ke&&Be(Ke)}catch(Z){b?.silent||Xe(Z instanceof Error?Z.message:String(Z))}finally{b?.silent||rt(!1)}}},[a]),wa=o.useRef(!1);o.useEffect(()=>{if(!(!De||ct!=="result"||!wt)){if(G.some(b=>b.id===wt)){wa.current=!0;return}wa.current&&(Ee(null),lt(!1),dt.some(b=>b.pairingId===wt)&&D.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[De,ct,wt,G,dt,t]);const Ja=o.useCallback(async b=>{if(a)try{await a.cancelPairing(b),Be(Z=>Z.filter(Ke=>Ke.id!==b)),await zs({silent:!0})}catch(Z){Xe(Z instanceof Error?Z.message:String(Z))}},[a,zs]);o.useEffect(()=>{if(!a)return;zs();const b=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||zs({silent:!0})},5e3);return()=>window.clearInterval(b)},[a,zs]);const Qa=o.useCallback(async()=>{if(a?.getPairingTransports)try{const tt=await a.getPairingTransports();return{localUrl:tt.local,lanUrl:tt.lan,relayAvailable:tt.relayAvailable}}catch{}const b=ql(),Z=b?`http://127.0.0.1:${b}`:Ao(window.location.origin)?window.location.origin:null;let Ke=null;try{const tt=ha(await eg());Ke=tt&&!Ao(tt)?tt:null}catch{}return{localUrl:Z,lanUrl:Ke,relayAvailable:!0}},[a]),Di=o.useCallback(async()=>{Xe(null),ze(null),J(null),Fe(!1),Ee(null),Qe("configure"),is(!0),lt(!0);const b=await Qa();vs(b),Ls(b.relayAvailable?"relay":b.lanUrl?"lan":"local")},[Qa]),Mi=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Ht)){Xe(null),bs(!0);try{const b=pt.trim()||void 0;let Z,Ke,tt=!0;Xt==="local"?(Z=Ht.localUrl??void 0,Ke=!1):Xt==="lan"?(Z=Ht.lanUrl??void 0,Ke=Gt):Gt&&Ht.lanUrl?(Z=Ht.lanUrl,Ke=!0):(tt=!1,Ke=!0);const{pairing:Dt,server:Ds}=await a.createPairingSession({label:b,allowedClientKinds:["mobile","desktop"],serverUrl:Z,includeRelay:Ke,includeDirect:tt}),ws=yd({pairingId:Dt.id,secret:Dt.secret,label:Ds.label,fingerprint:Dt.fingerprint??void 0,expiresAt:Dt.expiresAt,candidates:Ds.candidates}),_s=jd(ws);ze(_s),J(await Ol.toDataURL(_s,{width:1024,margin:2,errorCorrectionLevel:"L"})),Fe(!1),wa.current=!1,Ee(Dt.id),Qe("result"),await zs({silent:!0})}catch(b){Xe(b instanceof Error?b.message:String(b))}finally{bs(!1)}}},[a,Ht,Xt,Gt,pt,zs]),Ya=o.useCallback(()=>{ft&&za(ft).then(b=>{b.ok&&(Fe(!0),window.setTimeout(()=>Fe(!1),2e3))})},[ft]),Ri=o.useCallback(async b=>{if(!a)return;const Z=b.clientKind==="desktop-local";Xe(null);try{if(await a.revokeClient(b.id),Z&&as()){const Ke=await Hr();await Gr({hosts:Ke.hosts,defaultHostId:Ke.defaultHostId,initialHostChoiceCompleted:Ke.initialHostChoiceCompleted,localClientToken:null}),xt(tt=>tt.map(Dt=>Dt.id===b.id?{...Dt,revokedAt:new Date().toISOString()}:Dt)),wd({apiBaseUrl:Ba(),clientToken:null,runtimeKey:"local"});return}await zs()}catch(Ke){Xe(Ke instanceof Error?Ke.message:String(Ke))}},[a,zs]),Li=o.useCallback(async()=>{if(a){Xe(null);try{await a.purgeRevokedClients(),await zs()}catch(b){Xe(b instanceof Error?b.message:String(b))}}},[a,zs]);o.useEffect(()=>{j(k)},[k]),o.useEffect(()=>{ss(!1)},[M]),o.useEffect(()=>{if(!M)return;const b=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||N()},2e3);return()=>{window.clearInterval(b)}},[N,M]),o.useEffect(()=>{let b=null,Z=Date.now();const Ke=()=>{const Dt=Date.now();Dt-Z>=1e3&&(ge(Dt),Z=Dt),b=requestAnimationFrame(Ke)};(typeof document>"u"||document.visibilityState==="visible")&&(b=requestAnimationFrame(Ke));const tt=()=>{document.visibilityState==="visible"&&b===null?b=requestAnimationFrame(Ke):document.visibilityState!=="visible"&&b!==null&&(cancelAnimationFrame(b),b=null)};return document.addEventListener("visibilitychange",tt),()=>{document.removeEventListener("visibilitychange",tt),b!==null&&cancelAnimationFrame(b)}},[]);const js=M?r[M]:null,Gs=js?.phase,sa=Gs==="ready",pn=Gs==="degraded",bn=Ir(Gs),Xs=sa||(bn||pn),Oi=js?Math.max(0,ee-js.updatedAtMs):0,na=pn&&Oi>12e3,aa=No(Gs),On=aa==="error"?Bu(js?.detail):null,ka=Hu(On),Fi=o.useMemo(()=>!h||!k?!1:JSON.stringify(h)!==JSON.stringify(k),[h,k]),os=o.useCallback(b=>{j(Z=>Z&&b(Z))},[]),Ki=o.useCallback(async()=>{if(!h)return;const b=tg(h);if(!b.sshCommand.trim()){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(b.remoteOpenchamber.mode==="external"&&!b.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ss(!0);return}if(b.remoteOpenchamber.mode==="managed"&&b.remoteOpenchamber.bindHost==="0.0.0.0"&&!b.auth.openchamberPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>vn.current?.focus(),0);return}if(!(b.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(b.auth.sshPassword?.enabled&&b.auth.sshPassword.value?.trim()&&b.auth.sshPassword.store!=="settings"){const Z=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));b.auth.sshPassword.store=Z?"settings":"never",Z||(b.auth.sshPassword.value=void 0)}if(b.auth.openchamberPassword?.enabled&&b.auth.openchamberPassword.value?.trim()&&b.auth.openchamberPassword.store!=="settings"){const Z=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));b.auth.openchamberPassword.store=Z?"settings":"never",Z||(b.auth.openchamberPassword.value=void 0)}try{await f(b),D.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(Z){D.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:Z instanceof Error?Z.message:String(Z)})}}},[h,t,f]),ia=o.useCallback(async(b,Z)=>{const Ke=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await C(Ke,`ssh ${Z}`,b),P(Ke),D.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(tt){return D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:tt instanceof Error?tt.message:String(tt)}),!1}},[C,P,t]),ra=o.useCallback(()=>{z||(L(null),ne(""))},[z]),zi=o.useCallback((b,Z)=>{if(ds(!1),Z){L(b),ne(Wu(b));return}ia(b,b)},[ia]),Xa=o.useMemo(()=>Ni(l,mt,b=>[b.host,b.sshCommand]),[l,mt]),Ui=o.useCallback(b=>{const Z=(b||"").trim();if(!Z){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ui(Z)},[t]),Fn=o.useCallback(async()=>{const b=W,Z=Q.trim();if(b){if(!Z){D.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}re(!0);try{await ia(b,Z)&&(L(null),ne(""))}finally{re(!1)}}},[ia,Q,W,t]),mn=o.useCallback(async()=>{if(k)try{await S(k.id);return}catch(b){if(!_u(b)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw b;const Ke={...k,localForward:{...k.localForward,preferredLocalPort:wi()}};await f(Ke),await S(Ke.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[S,k,t,f]),vn=o.useRef(null),oa=o.useRef(null),la=o.useCallback(async b=>{if(k){if(b==="localPort"){const Z={...k,localForward:{...k.localForward,preferredLocalPort:wi()}};try{await f(Z),await S(Z.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Ke){D.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Ke instanceof Error?Ke.message:String(Ke)})}return}ss(!0),window.setTimeout(()=>{if(b==="uiPassword"){vn.current?.focus();return}oa.current?.scrollIntoView({block:"center"})},0)}},[S,k,t,f]),ue=o.useCallback(async b=>(await Tc(b,600)).map(Ke=>Yu(Ke)),[]),ls=o.useCallback(async()=>{if(h){A(!0),E(!0),_(null);try{const b=await ue(h.id);V(b)}catch(b){V([]),_(b instanceof Error?b.message:String(b))}finally{E(!1)}}},[h,ue]);o.useEffect(()=>{if(!F||!h)return;let b=!1;const Z=async()=>{try{const tt=await ue(h.id);b||(V(tt),_(null))}catch(tt){b||_(tt instanceof Error?tt.message:String(tt))}};Z();const Ke=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Z()},1e3);return()=>{b=!0,window.clearInterval(Ke)}},[h,F,ue]);const Kn=o.useMemo(()=>w.join(`
27
+ `),[w]),Za=o.useCallback(()=>{if(!Kn.trim()){D.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}za(Kn).then(b=>{b.ok&&D.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Kn,t]),ei=o.useCallback(async()=>{if(h)try{await Ec(h.id),V([]),D.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(b){D.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:b instanceof Error?b.message:String(b)})}},[h,t]),ti=o.useCallback(async()=>{if(!js?.localUrl){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const b=js.localUrl.trim();if(!b){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ui(b)},[js?.localUrl,t]),si=o.useCallback(()=>{if(!h)return;if(!Xs&&h.remoteOpenchamber.mode==="external"&&!h.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),ss(!0);return}if(!Xs&&h.remoteOpenchamber.mode==="managed"&&h.remoteOpenchamber.bindHost==="0.0.0.0"&&!h.auth.openchamberPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),ss(!0),window.setTimeout(()=>vn.current?.focus(),0);return}O(!0),(Xs?g(h.id):mn()).catch(Z=>{const Ke=Xs?sa?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";D.error(t(Ke),{description:Z instanceof Error?Z.message:String(Z)})}).finally(()=>{O(!1)})},[Xs,mn,g,h,sa,t]),ni=o.useCallback(()=>{if(!h||bn)return;X(!0),(pn?g(h.id).then(()=>mn()):T(h.id)).catch(Z=>{D.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:Z instanceof Error?Z.message:String(Z)})}).finally(()=>{X(!1)})},[mn,g,h,bn,pn,T,t]),_i=t(bn?"settings.remoteInstances.page.actions.connecting":pn?na?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),ca=!K&&!Y&&(Gs==="error"||Gs==="idle"||!Gs||pn&&na)&&!bn,Na=t(sa?"settings.remoteInstances.sidebar.actions.disconnect":Xs?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!h)return s.jsxs(es,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(_e,{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:()=>{Di()},children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[us>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Li()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,st&&dt.length===0&&G.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):dt.length===0&&G.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[G.map(b=>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:b.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),b.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:()=>{Ja(b.id)},children:t("settings.common.actions.cancel")})]},`pending-${b.id}`)),dt.map(b=>{const Z=b.clientKind==="desktop-local",Ke=b.lastUsedAt?Date.parse(b.lastUsedAt):Number.NaN,tt=!b.revokedAt&&(Z||Number.isFinite(Ke)&&Date.now()-Ke<9e4),Dt=b.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):tt?b.lastTransport==="relay"&&!Z?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Ke)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Dc(Ke,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:ve("h-2 w-2 shrink-0 rounded-full",b.revokedAt?"bg-muted-foreground/20":tt?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:b.label}),wo(b.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:wo(b.devicePlatform)}):null,Z?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:ve("typography-micro truncate",tt&&!b.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:Dt})]})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ri(b)},disabled:!!b.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},b.id)})]})]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null]}):null,n?s.jsxs(_e,{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:()=>Ge(!0),disabled:be,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Pe(!0),disabled:be,children:[s.jsx(R,{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:Ne?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):de.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):de.map(b=>{const Z=ae[b.id],Ke=Z?Z.status==="ok"?"desktopHostSwitcher.status.connected":Z.status==="auth"?"desktopHostSwitcher.status.authRequired":Z.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":Z.status==="incompatible"?"desktopHostSwitcher.status.incompatible":Z.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",tt=Z?.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:ve("h-2 w-2 shrink-0 rounded-full",Z?tt?"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:Ia(b.label)}),pe===b.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:ve("typography-micro shrink-0",tt?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Ke),tt&&typeof Z?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(Z.latencyMs))}):""]})]}),s.jsx("p",{className:ve("typography-micro text-muted-foreground truncate",b.apiUrl&&"font-mono"),children:b.relay&&!b.apiUrl?t("mobile.connect.relay.badge"):Ia(b.apiUrl||b.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:()=>{Ei(b.id)},disabled:be||pe===b.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:pe===b.id?s.jsx(R,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"star",className:"h-3.5 w-3.5"})}),b.relay&&!b.apiUrl?null:s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Es(b),disabled:be,children:[s.jsx(R,{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:()=>{ns(b.id)},disabled:be,children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},b.id)})}),ye?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:ye}):null]}):null,n?s.jsx(Kt,{open:Ue,onOpenChange:Pe,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:b=>{b.preventDefault(),Ut()},children:[s.jsx(Je,{className:"h-8",value:Le,onChange:b=>oe(b.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8",value:fe,onChange:b=>Me(b.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:be,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(Je,{className:"h-8",value:$e,onChange:b=>Ve(b.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:be}),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(Ys,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),qe.map(b=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Je,{className:"h-8 font-mono text-xs",value:b.name,onChange:Z=>se(Ke=>Ke.map(tt=>tt.id===b.id?{...tt,name:Z.target.value}:tt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8 font-mono text-xs",value:b.value,onChange:Z=>se(Ke=>Ke.map(tt=>tt.id===b.id?{...tt,value:Z.target.value}:tt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:be}),s.jsx("button",{type:"button",onClick:()=>se(Z=>Z.filter(Ke=>Ke.id!==b.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:be,children:s.jsx(R,{name:"close",className:"h-4 w-4"})})]},b.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>se(b=>[...b,gr()]),disabled:be,children:[s.jsx(R,{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(!1),disabled:be,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:be||!fe.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Kt,{open:!!me,onOpenChange:b=>{b||Ce(null)},children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:b=>{b.preventDefault(),qa()},children:[s.jsx(Je,{className:"h-8",value:Re,onChange:b=>Ye(b.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8",value:q,onChange:b=>ke(b.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:be,autoFocus:!0}),s.jsx(Je,{className:"h-8",value:Ae,onChange:b=>He(b.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:be}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ys,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),at.map(b=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Je,{className:"h-8 font-mono text-xs",value:b.name,onChange:Z=>nt(Ke=>Ke.map(tt=>tt.id===b.id?{...tt,name:Z.target.value}:tt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8 font-mono text-xs",value:b.value,onChange:Z=>nt(Ke=>Ke.map(tt=>tt.id===b.id?{...tt,value:Z.target.value}:tt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:be}),s.jsx("button",{type:"button",onClick:()=>nt(Z=>Z.filter(Ke=>Ke.id!==b.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:be,children:s.jsx(R,{name:"close",className:"h-4 w-4"})})]},b.id)),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>nt(b=>[...b,gr()]),disabled:be,children:[s.jsx(R,{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:()=>Ce(null),disabled:be,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:be,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Kt,{open:je,onOpenChange:Ge,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Vt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:b=>{b.preventDefault(),Ot()},children:[s.jsx(Je,{className:"h-8",value:ie,onChange:b=>we(b.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:be,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:()=>Ge(!1),disabled:be,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:be||!ie.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Kt,{open:De,onOpenChange:lt,children:s.jsxs(zt,{className:ct==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t(ct==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Vt,{children:t(ct==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),ct==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:b=>{b.preventDefault(),Mi()},children:[s.jsx(Je,{className:"h-8",value:pt,onChange:b=>St(b.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:!!Ht?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Ht?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Ht?.localUrl}].map(b=>{const Z=Xt===b.key;return s.jsxs("div",{className:ve("flex items-start gap-2 py-0.5",b.available?"cursor-pointer":"opacity-45"),onClick:()=>{b.available&&Ls(b.key)},role:"presentation",children:[s.jsx(yr,{checked:Z,disabled:!b.available,onChange:()=>Ls(b.key),ariaLabel:b.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:ve("typography-ui-label font-normal",Z?"text-foreground":"text-foreground/70"),children:b.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:b.hint})]})]},b.key)})}),Xt==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(or,{checked:Gt,onChange:is,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,Xt==="relay"&&Ht?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(or,{checked:Gt,onChange:is,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]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>lt(!1),disabled:kt,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:kt||!Ht,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[jt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:jt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,ft?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:ft}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Ya,children:[s.jsx(R,{name:he?"check":"file-copy",className:ve("h-3.5 w-3.5",he&&"text-[var(--status-success)]")}),t(he?"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:()=>lt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(_e,{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:Wa,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:m?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):i.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:l.length===1?t("settings.remoteInstances.page.empty.noInstancesWithOneImport"):l.length>1?t("settings.remoteInstances.page.empty.noInstancesWithImports",{count:l.length}):t("settings.remoteInstances.page.empty.noInstances")}):i.map(b=>{const Z=r[b.id],Ke=b.nickname?.trim()||b.sshParsed?.destination||b.id,tt=Z?.phase,Dt=tt==="ready",Ds=No(tt),ws=Ds==="error"?Z?.detail:void 0;return s.jsxs("div",{className:"space-y-1.5 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:`h-2 w-2 rounded-full ${Io(tt)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Ke})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(So(Ds)),Ds==="connecting"?` · ${t(ko(tt))}`:"",Dt&&Z?.localUrl?` · ${Z.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Dt?s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ui(Z?.localUrl),children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(Dt?g(b.id):S(b.id)).catch(ks=>D.error(t(Dt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:ks instanceof Error?ks.message:String(ks)}))},children:[Dt?s.jsx(R,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"plug-2",className:"h-3.5 w-3.5"}),t(Dt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>P(b.id),children:[s.jsx(R,{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"))&&y(b.id).catch(ks=>D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ks instanceof Error?ks.message:String(ks)}))},children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),ws?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:ws}):null]},b.id)})}):null,n?s.jsx(Kt,{open:gs,onOpenChange:ds,children:s.jsxs(zt,{className:"sm:max-w-lg",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Vt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Qs,{value:Ts,onChange:ce,"aria-label":t("settings.remoteInstances.page.addDialog.sourceLabel"),options:[{value:"saved",label:t("settings.remoteInstances.page.addDialog.tab.saved")},{value:"manual",label:t("settings.remoteInstances.page.addDialog.tab.manual")}]}),Ts==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Je,{className:"h-8",value:mt,onChange:b=>yt(b.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),u?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.addDialog.emptySaved")}):Xa.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.searchEmpty")}):s.jsx("div",{className:"max-h-[45vh] overflow-auto",children:Xa.map(b=>s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] py-2.5 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:[b.host,b.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:b.sshCommand})]}),s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{zi(b.host,b.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${b.source}:${b.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:b=>{b.preventDefault(),Ti()},children:[s.jsx(Je,{className:"h-8",value:Bt,onChange:b=>rs(b.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:x}),s.jsx(Je,{className:"h-8",value:Qt,onChange:b=>Yt(b.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:x,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:()=>ds(!1),disabled:x,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:x||!Qt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Kt,{open:!!W,onOpenChange:b=>{b||ra()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:W?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:W}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:b=>{b.preventDefault(),Fn()},children:[s.jsx(Je,{value:Q,onChange:b=>ne(b.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:ra,disabled:z,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:z,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const yn=h.remoteOpenchamber.mode==="managed",da=yn&&h.remoteOpenchamber.bindHost==="0.0.0.0",jn=da&&!h.auth.openchamberPassword?.value?.trim(),wn=h.nickname?.trim()||h.sshParsed?.destination||h.id;return s.jsx(Kt,{open:!!h,onOpenChange:b=>{b||P(null)},children:s.jsxs(zt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${rr} truncate`,children:wn}),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 ${Io(Gs)}`}),s.jsx("span",{className:"text-foreground",children:t(So(aa))}),aa==="connecting"?s.jsx("span",{children:t(ko(Gs))}):null,js?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:js.localUrl}):null,na?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(_e,{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:Xs?"outline":"default",size:"xs",className:"!font-normal",onClick:si,disabled:K||Y,children:[Xs?s.jsx(R,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"plug-2",className:"h-3.5 w-3.5"}),Na]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ni,disabled:!ca,children:[s.jsx(R,{name:"refresh",className:`h-3.5 w-3.5 ${bn||pn&&!na?"animate-spin":""}`}),_i]}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ls()},children:[s.jsx(R,{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"))&&y(h.id).then(()=>{P(null),D.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(Z=>{D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:Z instanceof Error?Z.message:String(Z)})})},children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),aa==="error"&&js?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:js.detail}),ka?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(ka)}):null,On&&!ka?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{la(On)},children:t(On==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":On==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,js?.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:js.localUrl})]}):null]}),s.jsxs(_e,{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(Je,{className:"h-7 md:max-w-xl",value:h.sshCommand,onChange:b=>os(Z=>({...Z,sshCommand:b.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(Je,{className:"h-7 md:max-w-sm",value:h.nickname||"",onChange:b=>os(Z=>({...Z,nickname:b.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("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(It,{value:h.remoteOpenchamber.mode,onValueChange:b=>os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,mode:b==="external"?"external":"managed"}})),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(ot,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(Mn,{open:ys,onOpenChange:ss,children:[s.jsxs(Rn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:wl,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(R,{name:ys?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(Ln,{children:[s.jsx("p",{className:"px-2 pb-2 typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.section.advancedHint")}),s.jsxs("div",{className:"flex flex-col gap-1.5 px-2 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(xs,{containerClassName:"w-fit",min:5,max:240,step:1,className:ve(Cs,"tabular-nums"),value:h.connectionTimeoutSec,onValueChange:b=>{os(Z=>({...Z,connectionTimeoutSec:Number.isFinite(b)?b:Z.connectionTimeoutSec}))}})]}),s.jsxs(_e,{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",ref:oa,children:s.jsx($s,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ve(Cs,"tabular-nums"),value:h.remoteOpenchamber.preferredPort,onValueChange:b=>{os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,preferredPort:Number.isFinite(b)&&b>0?b:void 0}}))},onClear:()=>{os(b=>({...b,remoteOpenchamber:{...b.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),yn?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($s,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(It,{value:h.remoteOpenchamber.installMethod,onValueChange:b=>os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,installMethod:b==="npm"||b==="bun"?b:"auto"}})),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(ot,{value:"bun",children:"bun"}),s.jsx(ot,{value:"npm",children:"npm"})]})]})]}):null,yn?s.jsxs("div",{className:"py-1.5",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(bi,{checked:da,onCheckedChange:b=>os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,bindHost:b?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),da?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,yn?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($s,{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(bi,{checked:h.remoteOpenchamber.keepRunning,onCheckedChange:b=>os(Z=>({...Z,remoteOpenchamber:{...Z.remoteOpenchamber,keepRunning:b}}))})})]}):null]}),s.jsxs(_e,{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($s,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(It,{value:h.localForward.bindHost,onValueChange:b=>{b==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||os(Z=>({...Z,localForward:{...Z.localForward,bindHost:b==="localhost"||b==="0.0.0.0"?b:"127.0.0.1"}}))},children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[240px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(ot,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(ot,{value:"0.0.0.0",children:t("settings.remoteInstances.page.field.bindHostOption.lan")})]})]})]}),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($s,{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(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ve(Cs,"tabular-nums"),value:h.localForward.preferredLocalPort,onValueChange:b=>{os(Z=>({...Z,localForward:{...Z.localForward,preferredLocalPort:Number.isFinite(b)&&b>0?b:void 0}}))},onClear:()=>{os(b=>({...b,localForward:{...b.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:()=>os(b=>({...b,localForward:{...b.localForward,preferredLocalPort:wi()}})),children:s.jsx(R,{name:"shuffle",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.remoteInstances.page.tunnelPreview.caption")}),s.jsx("p",{className:"typography-micro font-mono text-foreground/80 break-all",children:`${h.localForward.bindHost}:${h.localForward.preferredLocalPort||"auto"} → ${h.sshParsed?.destination||h.nickname||"remote"}:${h.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(_e,{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("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(Je,{className:"h-7 md:max-w-sm",type:"password",value:h.auth.sshPassword?.value||"",onChange:b=>os(Z=>({...Z,auth:{...Z.auth,sshPassword:{enabled:b.target.value.trim().length>0,value:b.target.value,store:Z.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("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t(da?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(yn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(Je,{className:ve("h-7 md:max-w-sm",jn&&"border-[var(--status-error)]"),type:"password",ref:vn,"aria-invalid":jn,value:h.auth.openchamberPassword?.value||"",onChange:b=>os(Z=>({...Z,auth:{...Z.auth,openchamberPassword:{enabled:b.target.value.trim().length>0,value:b.target.value,store:Z.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),jn?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(_e,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[h.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,h.portForwards.map((b,Z)=>{const Ke=Ct=>{os(qt=>({...qt,portForwards:qt.portForwards.map((zn,Mt)=>Mt===Z?Ct(zn):zn)}))},tt=b.type==="remote"?"Local target":"Local listen",Dt=b.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.",Ds=b.type==="remote"?"Remote listen":"Remote target",ws=b.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",_s=Po(b.localHost||"localhost",b.localPort),ks=Po(b.remoteHost||"localhost",b.remotePort),qs=b.type==="local"&&typeof b.localPort=="number"&&b.localPort>0,Sa=qs?`http://${Qu(b.localHost)}:${b.localPort}`:"",un=!!$[b.id],Ws=b.type==="local"?t("settings.remoteInstances.page.forwardType.local"):b.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(Mn,{open:un,onOpenChange:Ct=>{U(qt=>({...qt,[b.id]:Ct}))},className:`${Z>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(Rn,{className:"flex items-center gap-2 group",children:[s.jsx(R,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${un?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Gu(b)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Ws})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(bi,{checked:b.enabled,onCheckedChange:Ct=>Ke(qt=>({...qt,enabled:Ct})),"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:()=>os(Ct=>({...Ct,portForwards:Ct.portForwards.filter(qt=>qt.id!==b.id)})),children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ln,{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($s,{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(Ju(b.type))})]})})}),s.jsxs(It,{value:b.type,onValueChange:Ct=>Ke(qt=>({...qt,type:Ct==="dynamic"||Ct==="remote"?Ct:"local"})),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(ot,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(ot,{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($s,{label:tt,hint:Dt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Je,{className:"h-7 w-32",value:b.localHost||"127.0.0.1",onChange:Ct=>Ke(qt=>({...qt,localHost:Ct.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ve(Cs,"tabular-nums"),value:b.localPort,onValueChange:Ct=>{Ke(qt=>({...qt,localPort:Number.isFinite(Ct)&&Ct>0?Ct:void 0}))},onClear:()=>{Ke(Ct=>({...Ct,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),b.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($s,{label:Ds,hint:ws})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Je,{className:"h-7 w-32",value:b.remoteHost||"",onChange:Ct=>Ke(qt=>({...qt,remoteHost:Ct.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xs,{containerClassName:"w-fit",min:1,max:65535,step:1,className:ve(Cs,"tabular-nums"),value:b.remotePort,onValueChange:Ct=>{Ke(qt=>({...qt,remotePort:Number.isFinite(Ct)&&Ct>0?Ct:void 0}))},onClear:()=>{Ke(Ct=>({...Ct,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:b.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:_s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):b.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ks}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(R,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(R,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:_s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:_s}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(R,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(R,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:ks}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),qs?s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Dn(Sa).then(Ct=>{Ct||D.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},b.id)}),s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const b=qu();os(Z=>({...Z,portForwards:[...Z.portForwards,b]})),U(Z=>({...Z,[b.id]:!0}))},children:[s.jsx(R,{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:()=>{Ki()},disabled:!Fi||x,children:t("settings.common.actions.saveChanges")}),js?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{za(js.localUrl||"").then(b=>{b.ok&&D.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(R,{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:()=>{ti()},children:[s.jsx(R,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,d?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:d}):null]})}),s.jsx(Kt,{open:F,onOpenChange:A,children:s.jsxs(zt,{className:"sm:max-w-2xl",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Vt,{children:h?.nickname?.trim()||h?.sshParsed?.destination||h?.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:Za,disabled:I||!Kn.trim(),children:[s.jsx(R,{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:()=>{ei()},disabled:I,children:[s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),I?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):B?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:B}):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:w.length>0?w.join(`
28
+ `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Kt,{open:!!W,onOpenChange:b=>{b||ra()},children:s.jsxs(zt,{className:"sm:max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Vt,{children:W?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:W}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:b=>{b.preventDefault(),Fn()},children:[s.jsx(Je,{value:Q,onChange:b=>ne(b.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:ra,disabled:z,children:t("settings.common.actions.cancel")}),s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:z,children:t("settings.common.actions.create")})]})]})]})})]})})},ng="__add_provider__",ag=()=>{const t=fn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},ig=({onItemSelect:t})=>{const{t:e}=it(),a=Us(),n=Ze(f=>kl(f,a)),i=Ze(f=>f.selectedProviderId),r=Ze(f=>f.setSelectedProvider),l=Bs(f=>f.activeProjectId),[m,u]=o.useState({}),x=o.useMemo(()=>a||ag(),[l,a]),d=Ze(f=>f.loadProviders);o.useEffect(()=>{a&&d({directory:a,source:"settings:providers"})},[d,a]),o.useEffect(()=>{if(n.length===0){u({});return}let f=!1;return(async()=>{const y=n.map(async S=>{try{const g=x?`?directory=${encodeURIComponent(x)}`:"",T=await ut(`/api/provider/${encodeURIComponent(S.id)}/source${g}`,{method:"GET",headers:{Accept:"application/json"}});if(!T.ok)return;const M=await T.json().catch(()=>null),P=M?.sources??M?.data?.sources;if(!P||f)return;u(k=>({...k,[S.id]:P}))}catch{}});await Promise.all(y)})(),()=>{f=!0}},[x,n]);const v="bg-background",c=o.useMemo(()=>n.filter(f=>!!m[f.id]?.project?.exists),[n,m]),N=o.useMemo(()=>n.filter(f=>!m[f.id]?.project?.exists),[n,m]);return s.jsxs("div",{className:ve("flex h-full flex-col",v),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${dn} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(Ga,{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:n.length})}),s.jsx(H,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(ng),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(R,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Hs,{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(R,{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:[N.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")}),N.map(f=>s.jsx(To,{provider:f,selectedProviderId:i,onSelect:()=>{r(f.id),t?.()}},f.id))]}),c.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ve("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",N.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),c.map(f=>s.jsx(To,{provider:f,selectedProviderId:i,onSelect:()=>{r(f.id),t?.()}},f.id))]})]})})]})},To=t=>{const e=gt.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,m=a.id,u=l?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[0]!==u?(x=ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",u),e[0]=u,e[1]=x):x=e[1];let d;e[2]!==a.id?(d=s.jsx(Bn,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=d):d=e[3];const v=a.name||a.id;let c;e[4]!==v?(c=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:v}),e[4]=v,e[5]=c):c=e[5];let N;e[6]!==r?(N=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=N):N=e[7];let f;e[8]!==i||e[9]!==d||e[10]!==c||e[11]!==N?(f=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:[d,c,N]}),e[8]=i,e[9]=d,e[10]=c,e[11]=N,e[12]=f):f=e[12];let C;return e[13]!==a.id||e[14]!==x||e[15]!==f?(C=s.jsx("div",{className:x,children:f},m),e[13]=a.id,e[14]=x,e[15]=f,e[16]=C):C=e[16],C},rg=t=>t,og=(t,e,a)=>t&&!e&&!a,Eo=t=>typeof t=="object"&&t!==null,Wl=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()},lg=t=>{if(!Eo(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>Eo(i)));return e},Do=t=>t.length===0?!0:t.some(e=>Wl(e)==="api"),Mo=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>Wl(e)==="oauth"),cg=t=>t!=="claude-code",Ro=t=>typeof t.key=="string"&&t.key.trim().length>0||typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0||t.envDeclared===!0?!0:t.authSourceExists===!0,dg=t=>t.modelCount>0&&(!t.sourcesLoaded||t.hasCredentials||!!t.isEditableCustomProvider),pg=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,Pr={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},$n="__custom_provider__",mg=/^[a-z0-9][a-z0-9-_]*$/,Jl=/^https?:\/\//,ug=/^\{env:([^}]+)\}$/;let gg=0;const Ii=()=>`row-${gg++}`,Ar=()=>({row:Ii(),id:"",name:""}),Tr=()=>({row:Ii(),key:"",value:""}),hg=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[Ar()],headers:[Tr()]});function fg(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function xg(t){const e=t.trim();if(!e)return{};const n=e.match(ug)?.[1]?.trim();return n?{env:n}:{key:e}}function bg(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&Jl.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"&&new Set(Object.values(Pr)).has(r.npm)})}function Lo(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&bg(t):!1}function Oo(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function vg(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(x=>typeof x[0]=="string"&&typeof x[1]=="string").map(([x,d])=>({row:Ii(),key:x,value:d})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([x,d])=>({id:x,name:d&&typeof d=="object"&&"name"in d&&typeof d.name=="string"?d.name:x})):[],l=r.length>0?r.map(x=>({row:Ii(),id:typeof x?.id=="string"?x.id:"",name:typeof x?.name=="string"?x.name:typeof x?.id=="string"?x.id:""})):[Ar()],m=Array.isArray(t.env)?t.env.find(x=>typeof x=="string"&&x.trim().length>0)?.trim():void 0,u=r.find(x=>"api"in x);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:fg(u?.api?.npm),baseURL:a,apiKey:m?`{env:${m}}`:"",models:l,headers:i.length>0?i:[Tr()]}}function yg(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=xg(t.form.apiKey),l=t.disabledProviders??[],m=t.editingProviderID?.trim(),u=e?mg.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),x=a?void 0:t.t("settings.providers.page.custom.error.name.required"),d=n?Jl.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),c=!!(i||r||m&&t.allowExistingAuth&&m===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),N=l.includes(e),C=u||!!(m&&m===e)?void 0:t.existingProviderIDs.has(e)&&!N?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,y=new Set,S=t.form.models.map(A=>{const I=A.id.trim(),E=I?y.has(I)?t.t("settings.providers.page.custom.error.duplicate"):void y.add(I):t.t("settings.providers.page.custom.error.required"),B=A.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:E,name:B}}),g=S.every(A=>!A.id&&!A.name),T=Object.fromEntries(t.form.models.map(A=>[A.id.trim(),{name:A.name.trim()}])),M=new Set,P=t.form.headers.map(A=>{const I=A.key.trim(),E=A.value.trim();if(!I&&!E)return{};const B=I?M.has(I.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void M.add(I.toLowerCase()):t.t("settings.providers.page.custom.error.required"),_=E?void 0:t.t("settings.providers.page.custom.error.required");return{key:B,value:_}}),k=P.every(A=>!A.key&&!A.value),h=Object.fromEntries(t.form.headers.map(A=>({key:A.key.trim(),value:A.value.trim()})).filter(A=>A.key&&A.value).map(A=>[A.key,A.value])),j={providerID:u??C,name:x,baseURL:d,apiKey:c};return!u&&!C&&!x&&!d&&!c&&g&&k?{err:j,models:S,headers:P,result:{providerID:e,name:a,apiKey:r,config:{npm:Pr[t.form.protocol],name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(h).length>0?{headers:h}:{}},models:T}}}:{err:j,models:S,headers:P}}function jg(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function wg(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Fo=t=>{const e=gt.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:m,authFailureHint:u,onSubmit:x,onCancel:d,onDisconnect:v}=t;let c;e[0]!==n?(c=n===void 0?[]:n,e[0]=n,e[1]=c):c=e[1];const N=c,f=i===void 0?!1:i,C=r===void 0?"create":r,y=m===void 0?!1:m,S=u===void 0?null:u,{t:g}=it(),T=C==="edit";let M;e[2]!==l?(M=()=>l??hg(),e[2]=l,e[3]=M):M=e[3];const[P,k]=o.useState(M);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h={},e[4]=h):h=e[4];const[j,F]=o.useState(h);let A;e[5]===Symbol.for("react.memo_cache_sentinel")?(A=[],e[5]=A):A=e[5];const[I,E]=o.useState(A);let B;e[6]===Symbol.for("react.memo_cache_sentinel")?(B=[],e[6]=B):B=e[6];const[_,w]=o.useState(B),V=o.useRef(null);let W,L;e[7]!==l||e[8]!==T?(W=()=>{l&&(T&&V.current===l.providerID||(V.current=T?l.providerID:null,k(l),F({}),E([]),w([])))},L=[l,T],e[7]=l,e[8]=T,e[9]=W,e[10]=L):(W=e[9],L=e[10]),o.useEffect(W,L);let Q;e[11]===Symbol.for("react.memo_cache_sentinel")?(Q=(Nt,Tt)=>{k(Ut=>({...Ut,[Nt]:Tt})),F(Ut=>({...Ut,[Nt]:void 0}))},e[11]=Q):Q=e[11];const ne=Q;let z;e[12]===Symbol.for("react.memo_cache_sentinel")?(z=(Nt,Tt,Ut)=>{k(Ot=>({...Ot,models:Ot.models.map((ns,Es)=>Es===Nt?{...ns,[Tt]:Ut}:ns)})),E(Ot=>{const ns=[...Ot];return ns[Nt]={...ns[Nt]??{},[Tt]:void 0},ns})},e[12]=z):z=e[12];const re=z;let $;e[13]===Symbol.for("react.memo_cache_sentinel")?($=(Nt,Tt,Ut)=>{k(Ot=>({...Ot,headers:Ot.headers.map((ns,Es)=>Es===Nt?{...ns,[Tt]:Ut}:ns)})),w(Ot=>{const ns=[...Ot];return ns[Nt]={...ns[Nt]??{},[Tt]:void 0},ns})},e[13]=$):$=e[13];const U=$;let K;e[14]!==y||e[15]!==f||e[16]!==N||e[17]!==a||e[18]!==P||e[19]!==T||e[20]!==x||e[21]!==g?(K=async Nt=>{if(Nt.preventDefault(),f)return;const Tt=yg({form:P,t:((Ut,Ot)=>g(Ut,Ot)),existingProviderIDs:a,disabledProviders:N,editingProviderID:T?P.providerID:void 0,allowExistingAuth:T&&y});F(Tt.err),E(Tt.models),w(Tt.headers),Tt.result&&await x(Tt.result)},e[14]=y,e[15]=f,e[16]=N,e[17]=a,e[18]=P,e[19]=T,e[20]=x,e[21]=g,e[22]=K):K=e[22];const O=K;let Y;e[23]!==T||e[24]!==g?(Y=g(T?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=T,e[24]=g,e[25]=Y):Y=e[25];let X;e[26]!==g?(X=g("settings.providers.page.custom.description"),e[26]=g,e[27]=X):X=e[27];let ee;e[28]!==X?(ee=s.jsx("p",{className:Vn,children:X}),e[28]=X,e[29]=ee):ee=e[29];let ge;e[30]!==S?(ge=S?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:S}):null,e[30]=S,e[31]=ge):ge=e[31];let de;e[32]!==g?(de=g("settings.providers.page.custom.field.providerID.label"),e[32]=g,e[33]=de):de=e[33];let xe;e[34]!==g?(xe=g("settings.providers.page.custom.field.providerID.info"),e[34]=g,e[35]=xe):xe=e[35];const ae=P.providerID;let te;e[36]===Symbol.for("react.memo_cache_sentinel")?(te=Nt=>ne("providerID",Nt.target.value),e[36]=te):te=e[36];let pe;e[37]!==g?(pe=g("settings.providers.page.custom.field.providerID.placeholder"),e[37]=g,e[38]=pe):pe=e[38];const Ie=!T,Ne=T||f,Se=!!j.providerID;let be;e[39]!==g?(be=g("settings.providers.page.custom.field.providerID.label"),e[39]=g,e[40]=be):be=e[40];let Oe;e[41]!==P.providerID||e[42]!==pe||e[43]!==Ie||e[44]!==Ne||e[45]!==Se||e[46]!==be?(Oe=s.jsx(Je,{value:ae,onChange:te,placeholder:pe,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:Ie,disabled:Ne,"aria-invalid":Se,"aria-label":be}),e[41]=P.providerID,e[42]=pe,e[43]=Ie,e[44]=Ne,e[45]=Se,e[46]=be,e[47]=Oe):Oe=e[47];let Le;e[48]!==j.providerID?(Le=j.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.providerID}):null,e[48]=j.providerID,e[49]=Le):Le=e[49];let oe;e[50]!==de||e[51]!==xe||e[52]!==Oe||e[53]!==Le?(oe=s.jsxs(Wt,{label:de,info:xe,children:[Oe,Le]}),e[50]=de,e[51]=xe,e[52]=Oe,e[53]=Le,e[54]=oe):oe=e[54];let fe;e[55]!==g?(fe=g("settings.providers.page.custom.field.protocol.label"),e[55]=g,e[56]=fe):fe=e[56];let Me;e[57]!==g?(Me=g("settings.providers.page.custom.field.protocol.info"),e[57]=g,e[58]=Me):Me=e[58];const $e=P.protocol;let Ve;e[59]===Symbol.for("react.memo_cache_sentinel")?(Ve=Nt=>{Nt in Pr&&k(Tt=>({...Tt,protocol:Nt}))},e[59]=Ve):Ve=e[59];let qe;e[60]!==g?(qe=g("settings.providers.page.custom.field.protocol.label"),e[60]=g,e[61]=qe):qe=e[61];let se;e[62]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(Rt,{}),e[62]=se):se=e[62];let ie;e[63]!==qe?(ie=s.jsx(Pt,{"aria-label":qe,className:"w-full",children:se}),e[63]=qe,e[64]=ie):ie=e[64];let we;e[65]!==g?(we=g("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=g,e[66]=we):we=e[66];let ye;e[67]!==we?(ye=s.jsx(ot,{value:"openai-chat",children:we}),e[67]=we,e[68]=ye):ye=e[68];let Te;e[69]!==g?(Te=g("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=g,e[70]=Te):Te=e[70];let Ue;e[71]!==Te?(Ue=s.jsx(ot,{value:"openai-responses",children:Te}),e[71]=Te,e[72]=Ue):Ue=e[72];let Pe;e[73]!==g?(Pe=g("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=g,e[74]=Pe):Pe=e[74];let je;e[75]!==Pe?(je=s.jsx(ot,{value:"anthropic-messages",children:Pe}),e[75]=Pe,e[76]=je):je=e[76];let Ge;e[77]!==ye||e[78]!==Ue||e[79]!==je?(Ge=s.jsxs(At,{children:[ye,Ue,je]}),e[77]=ye,e[78]=Ue,e[79]=je,e[80]=Ge):Ge=e[80];let me;e[81]!==f||e[82]!==P.protocol||e[83]!==ie||e[84]!==Ge?(me=s.jsxs(It,{value:$e,onValueChange:Ve,disabled:f,children:[ie,Ge]}),e[81]=f,e[82]=P.protocol,e[83]=ie,e[84]=Ge,e[85]=me):me=e[85];let Ce;e[86]!==fe||e[87]!==Me||e[88]!==me?(Ce=s.jsx(Wt,{label:fe,info:Me,children:me}),e[86]=fe,e[87]=Me,e[88]=me,e[89]=Ce):Ce=e[89];let Re;e[90]!==g?(Re=g("settings.providers.page.custom.field.name.label"),e[90]=g,e[91]=Re):Re=e[91];let Ye;e[92]!==g?(Ye=g("settings.providers.page.custom.field.name.info"),e[92]=g,e[93]=Ye):Ye=e[93];const q=P.name;let ke;e[94]===Symbol.for("react.memo_cache_sentinel")?(ke=Nt=>ne("name",Nt.target.value),e[94]=ke):ke=e[94];let Ae;e[95]!==g?(Ae=g("settings.providers.page.custom.field.name.placeholder"),e[95]=g,e[96]=Ae):Ae=e[96];const He=!!j.name;let at;e[97]!==g?(at=g("settings.providers.page.custom.field.name.label"),e[97]=g,e[98]=at):at=e[98];let nt;e[99]!==P.name||e[100]!==Ae||e[101]!==He||e[102]!==at?(nt=s.jsx(Je,{value:q,onChange:ke,placeholder:Ae,className:"h-8 rounded-md px-3","aria-invalid":He,"aria-label":at}),e[99]=P.name,e[100]=Ae,e[101]=He,e[102]=at,e[103]=nt):nt=e[103];let dt;e[104]!==j.name?(dt=j.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.name}):null,e[104]=j.name,e[105]=dt):dt=e[105];let xt;e[106]!==Re||e[107]!==Ye||e[108]!==nt||e[109]!==dt?(xt=s.jsxs(Wt,{label:Re,info:Ye,children:[nt,dt]}),e[106]=Re,e[107]=Ye,e[108]=nt,e[109]=dt,e[110]=xt):xt=e[110];let G;e[111]!==g?(G=g("settings.providers.page.custom.field.baseURL.label"),e[111]=g,e[112]=G):G=e[112];let Be;e[113]!==g?(Be=g("settings.providers.page.custom.field.baseURL.info"),e[113]=g,e[114]=Be):Be=e[114];const st=P.baseURL;let rt;e[115]===Symbol.for("react.memo_cache_sentinel")?(rt=Nt=>ne("baseURL",Nt.target.value),e[115]=rt):rt=e[115];let pt;e[116]!==g?(pt=g("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=g,e[117]=pt):pt=e[117];const St=!!j.baseURL;let et;e[118]!==g?(et=g("settings.providers.page.custom.field.baseURL.label"),e[118]=g,e[119]=et):et=e[119];let Xe;e[120]!==P.baseURL||e[121]!==pt||e[122]!==St||e[123]!==et?(Xe=s.jsx(Je,{value:st,onChange:rt,placeholder:pt,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":St,"aria-label":et}),e[120]=P.baseURL,e[121]=pt,e[122]=St,e[123]=et,e[124]=Xe):Xe=e[124];let ft;e[125]!==j.baseURL?(ft=j.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.baseURL}):null,e[125]=j.baseURL,e[126]=ft):ft=e[126];let ze;e[127]!==G||e[128]!==Be||e[129]!==Xe||e[130]!==ft?(ze=s.jsxs(Wt,{label:G,info:Be,children:[Xe,ft]}),e[127]=G,e[128]=Be,e[129]=Xe,e[130]=ft,e[131]=ze):ze=e[131];let wt;e[132]!==g?(wt=g("settings.providers.page.custom.field.apiKey.label"),e[132]=g,e[133]=wt):wt=e[133];let Ee;e[134]!==y||e[135]!==T||e[136]!==g?(Ee=g(T&&y?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=y,e[135]=T,e[136]=g,e[137]=Ee):Ee=e[137];const jt=P.apiKey;let J;e[138]===Symbol.for("react.memo_cache_sentinel")?(J=Nt=>ne("apiKey",Nt.target.value),e[138]=J):J=e[138];let he;e[139]!==y||e[140]!==T||e[141]!==g?(he=g(T&&y?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=y,e[140]=T,e[141]=g,e[142]=he):he=e[142];const Fe=!!j.apiKey;let De;e[143]!==g?(De=g("settings.providers.page.custom.field.apiKey.label"),e[143]=g,e[144]=De):De=e[144];let lt;e[145]!==P.apiKey||e[146]!==he||e[147]!==Fe||e[148]!==De?(lt=s.jsx(Je,{type:"password",value:jt,onChange:J,placeholder:he,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Fe,"aria-label":De}),e[145]=P.apiKey,e[146]=he,e[147]=Fe,e[148]=De,e[149]=lt):lt=e[149];let ct;e[150]!==j.apiKey?(ct=j.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:j.apiKey}):null,e[150]=j.apiKey,e[151]=ct):ct=e[151];let Qe;e[152]!==wt||e[153]!==Ee||e[154]!==lt||e[155]!==ct?(Qe=s.jsxs(Wt,{label:wt,info:Ee,children:[lt,ct]}),e[152]=wt,e[153]=Ee,e[154]=lt,e[155]=ct,e[156]=Qe):Qe=e[156];let kt;e[157]!==Y||e[158]!==ee||e[159]!==ge||e[160]!==oe||e[161]!==Ce||e[162]!==xt||e[163]!==ze||e[164]!==Qe?(kt=s.jsxs(_e,{title:Y,divider:!1,settingsItem:"providers.custom",contentClassName:Js,children:[ee,ge,oe,Ce,xt,ze,Qe]}),e[157]=Y,e[158]=ee,e[159]=ge,e[160]=oe,e[161]=Ce,e[162]=xt,e[163]=ze,e[164]=Qe,e[165]=kt):kt=e[165];let bs;e[166]!==g?(bs=g("settings.providers.page.custom.models.title"),e[166]=g,e[167]=bs):bs=e[167];let Xt;if(e[168]!==P.models||e[169]!==I||e[170]!==g){let Nt;e[172]!==P.models.length||e[173]!==I||e[174]!==g?(Nt=(Tt,Ut)=>s.jsx("div",{className:`${Fs} 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:Et,children:g("settings.providers.page.custom.models.idLabel")}),s.jsx(Je,{value:Tt.id,onChange:Ot=>re(Ut,"id",Ot.target.value),placeholder:g("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.models.idLabel")}),I[Ut]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:I[Ut]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.models.nameLabel")}),s.jsx(Je,{value:Tt.name,onChange:Ot=>re(Ut,"name",Ot.target.value),placeholder:g("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":g("settings.providers.page.custom.models.nameLabel")}),I[Ut]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:I[Ut]?.name}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:hs,disabled:P.models.length<=1,onClick:()=>{P.models.length<=1||(k(Ot=>({...Ot,models:Ot.models.filter((ns,Es)=>Es!==Ut)})),E(Ot=>Ot.filter((ns,Es)=>Es!==Ut)))},"aria-label":g("settings.providers.page.custom.models.remove"),children:s.jsx(R,{name:"delete-bin",className:"size-4"})})]})},Tt.row),e[172]=P.models.length,e[173]=I,e[174]=g,e[175]=Nt):Nt=e[175],Xt=P.models.map(Nt),e[168]=P.models,e[169]=I,e[170]=g,e[171]=Xt}else Xt=e[171];let Ls;e[176]===Symbol.for("react.memo_cache_sentinel")?(Ls=()=>{k(kg),E(Ng)},e[176]=Ls):Ls=e[176];let Gt;e[177]!==g?(Gt=g("settings.providers.page.custom.models.add"),e[177]=g,e[178]=Gt):Gt=e[178];let is;e[179]!==Gt?(is=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ls,children:Gt}),e[179]=Gt,e[180]=is):is=e[180];let Ht;e[181]!==bs||e[182]!==Xt||e[183]!==is?(Ht=s.jsxs(_e,{title:bs,contentClassName:Js,children:[Xt,is]}),e[181]=bs,e[182]=Xt,e[183]=is,e[184]=Ht):Ht=e[184];let vs;e[185]!==g?(vs=g("settings.providers.page.custom.headers.title"),e[185]=g,e[186]=vs):vs=e[186];let us;e[187]!==g?(us=g("settings.providers.page.custom.headers.description"),e[187]=g,e[188]=us):us=e[188];let gs;e[189]!==us?(gs=s.jsx("p",{className:Vn,children:us}),e[189]=us,e[190]=gs):gs=e[190];let ds;if(e[191]!==P.headers||e[192]!==_||e[193]!==g){let Nt;e[195]!==P.headers.length||e[196]!==_||e[197]!==g?(Nt=(Tt,Ut)=>s.jsx("div",{className:`${Fs} 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:Et,children:g("settings.providers.page.custom.headers.keyLabel")}),s.jsx(Je,{value:Tt.key,onChange:Ot=>U(Ut,"key",Ot.target.value),placeholder:g("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.keyLabel")}),_[Ut]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:_[Ut]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.headers.valueLabel")}),s.jsx(Je,{value:Tt.value,onChange:Ot=>U(Ut,"value",Ot.target.value),placeholder:g("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.valueLabel")}),_[Ut]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:_[Ut]?.value}):null]})]}),s.jsx(H,{type:"button",variant:"ghost",size:"icon",className:hs,disabled:P.headers.length<=1,onClick:()=>{P.headers.length<=1||(k(Ot=>({...Ot,headers:Ot.headers.filter((ns,Es)=>Es!==Ut)})),w(Ot=>Ot.filter((ns,Es)=>Es!==Ut)))},"aria-label":g("settings.providers.page.custom.headers.remove"),children:s.jsx(R,{name:"delete-bin",className:"size-4"})})]})},Tt.row),e[195]=P.headers.length,e[196]=_,e[197]=g,e[198]=Nt):Nt=e[198],ds=P.headers.map(Nt),e[191]=P.headers,e[192]=_,e[193]=g,e[194]=ds}else ds=e[194];let Ts;e[199]===Symbol.for("react.memo_cache_sentinel")?(Ts=()=>{k(Sg),w(Cg)},e[199]=Ts):Ts=e[199];let ce;e[200]!==g?(ce=g("settings.providers.page.custom.headers.add"),e[200]=g,e[201]=ce):ce=e[201];let mt;e[202]!==ce?(mt=s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ts,children:ce}),e[202]=ce,e[203]=mt):mt=e[203];let yt;e[204]!==vs||e[205]!==gs||e[206]!==ds||e[207]!==mt?(yt=s.jsxs(_e,{title:vs,contentClassName:Js,children:[gs,ds,mt]}),e[204]=vs,e[205]=gs,e[206]=ds,e[207]=mt,e[208]=yt):yt=e[208];let Qt;e[209]!==f||e[210]!==d||e[211]!==g?(Qt=d?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:d,disabled:f,children:g("settings.providers.page.custom.actions.back")}):null,e[209]=f,e[210]=d,e[211]=g,e[212]=Qt):Qt=e[212];let Yt;e[213]!==f||e[214]!==v||e[215]!==g?(Yt=v?s.jsx(H,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{v()},disabled:f,children:g("settings.providers.page.actions.disconnect")}):null,e[213]=f,e[214]=v,e[215]=g,e[216]=Yt):Yt=e[216];let Bt;e[217]!==f||e[218]!==T||e[219]!==g?(Bt=g(f?"settings.providers.page.actions.saving":T?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=f,e[218]=T,e[219]=g,e[220]=Bt):Bt=e[220];let rs;e[221]!==f||e[222]!==Bt?(rs=s.jsx(H,{type:"submit",size:"xs",className:"!font-normal",disabled:f,children:Bt}),e[221]=f,e[222]=Bt,e[223]=rs):rs=e[223];let ys;e[224]!==Qt||e[225]!==Yt||e[226]!==rs?(ys=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Qt,Yt,rs]}),e[224]=Qt,e[225]=Yt,e[226]=rs,e[227]=ys):ys=e[227];let ss;return e[228]!==O||e[229]!==kt||e[230]!==Ht||e[231]!==yt||e[232]!==ys?(ss=s.jsxs("form",{onSubmit:O,className:"space-y-0",children:[kt,Ht,yt,ys]}),e[228]=O,e[229]=kt,e[230]=Ht,e[231]=yt,e[232]=ys,e[233]=ss):ss=e[233],ss};function kg(t){return{...t,models:[...t.models,Ar()]}}function Ng(t){return[...t,{}]}function Sg(t){return{...t,headers:[...t.headers,Tr()]}}function Cg(t){return[...t,{}]}const Ig=(t,e)=>!!e&&t!=="claude-code",Pg=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,ta=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ss=t=>typeof t=="string"&&t.length>0?t:void 0,Ag=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!ta(a))continue;const n=Ss(a.value);n!==void 0&&e.push({value:n,label:Ss(a.label)??n,...Ss(a.hint)?{hint:Ss(a.hint)}:{}})}return e},Tg=t=>{if(!ta(t))return;const e=Ss(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}},Eg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!ta(a))continue;const n=Ss(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?Ag(a.options):[];if(i==="select"&&r.length===0)continue;const l=Tg(a.when);e.push({type:i,key:n,message:Ss(a.message)??n,options:r,...Ss(a.placeholder)?{placeholder:Ss(a.placeholder)}:{},...l?{when:l}:{}})}return e},Dg=(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},Er=(t,e)=>t.filter(a=>Dg(a,e)),Mg=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},Rg=(t,e)=>Er(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,Lg=(t,e)=>{const a={};for(const n of Er(t,e))a[n.key]=(e[n.key]??"").trim();return a},Og=t=>{const e=ta(t)?t:{},a=ta(e.data)?e.data:e,n=Ss(a.url)??Ss(a.verification_uri_complete)??Ss(a.verification_uri),i=Ss(a.instructions)??Ss(a.message);if(!n&&!i)return null;const r=Ss(a.user_code)??Ss(a.userCode)??(i?Pg.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},Ko=(t,e,a)=>{const n=ta(t)?t:{},i=ta(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 Ss(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},Xi={phase:"idle"},zo=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=it(),[r,l]=o.useState(Xi),[m,u]=o.useState({}),[x,d]=o.useState(""),v=o.useRef(null);o.useEffect(()=>()=>v.current?.abort(),[]);const c=r.phase==="idle"?null:r.methodIndex,N=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,f=async(h,j,F)=>{const A=await za(h);if(A.ok){D.success(i(j));return}console.error("Failed to copy OAuth value:",A.error),D.error(i(F))},C=async(h,j)=>{const F=new AbortController;v.current?.abort(),v.current=F;try{const A=await fn.getSdkClient().provider.oauth.callback({providerID:t,method:h,...j?{code:j}:{}},{signal:F.signal});if(F.signal.aborted)return;if(A.error)throw A.error;l(Xi),D.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(A){if(F.signal.aborted)return;console.error("Failed to complete OAuth flow:",A),l({phase:"failed",methodIndex:h,message:Ko(A,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{v.current===F&&(v.current=null)}},y=async(h,j)=>{l({phase:"authorizing",methodIndex:h});let F;try{const A=await fn.getSdkClient().provider.oauth.authorize({providerID:t,method:h,...Object.keys(j).length>0?{inputs:j}:{}});if(A.error)throw A.error;const I=Og(A.data);if(!I){l({phase:"failed",methodIndex:h,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}F=I}catch(A){console.error("Failed to start OAuth flow:",A),l({phase:"failed",methodIndex:h,message:Ko(A,i,"settings.providers.page.toast.oauthStartFailed")});return}if(F.url&&Ig(t,F.url)&&Dn(F.url),F.method==="code"){d(""),l({phase:"awaitingCode",methodIndex:h,authorization:F,submitting:!1});return}l({phase:"waiting",methodIndex:h,authorization:F}),await C(h)},S=h=>{const j=Eg(h.prompts);if(j.length===0){y(h.index,{});return}u(Mg(j)),l({phase:"prompting",methodIndex:h.index,prompts:j,error:null})},g=()=>{if(r.phase!=="prompting")return;const h=Rg(r.prompts,m);if(h){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:h.message})});return}y(r.methodIndex,Lg(r.prompts,m))},T=()=>{if(r.phase!=="awaitingCode")return;const h=x.trim();h&&(l({...r,submitting:!0}),C(r.methodIndex,h))},M=()=>{v.current?.abort(),v.current=null,l(Xi)},P=h=>{const j=m[h.key]??"",F=A=>u(I=>({...I,[h.key]:A}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:h.message}),h.type==="select"?s.jsxs(It,{value:j,onValueChange:F,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{children:A=>h.options.find(I=>I.value===A)?.label??null})}),s.jsx(At,{children:h.options.map(A=>s.jsx(ot,{value:A.value,children:A.hint?`${A.label} · ${A.hint}`:A.label},A.value))})]}):s.jsx(Je,{value:j,onChange:A=>F(A.target.value),placeholder:h.placeholder,className:"max-w-[24rem] text-xs"})]},h.key)},k=h=>s.jsxs(s.Fragment,{children:[h.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:h.instructions}),h.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:h.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:()=>{f(h.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),h.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:h.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:()=>{Dn(h.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{f(h.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:ve("space-y-4",n),children:e.map(h=>{const j=c===h.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:h.label}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>S(h),disabled:N,children:i("settings.providers.page.actions.connect")})]}),j&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Er(r.prompts,m).map(P),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:g,children:i("settings.providers.page.actions.continue")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:M,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(R,{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:[k(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(R,{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:M,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:[k(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(Je,{value:x,onChange:F=>d(F.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:T,disabled:r.submitting||x.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:M,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:()=>S(h),children:i("settings.providers.page.actions.tryAgain")})]})]},h.index)})})},Uo=t=>Array.isArray(t?.env)&&t.env.some(e=>e.trim().length>0),Fg=t=>new Intl.NumberFormat(kr(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),_o=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Fg(t);return e.endsWith(".0")?e.slice(0,-2):e},Ea="__add_provider__",Ql=t=>typeof t=="object"&&t!==null,$o=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),Kg=t=>{if(typeof t=="string")return{id:t};if(!Ql(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}},zg=t=>{let e=[];Array.isArray(t)?e=t:Ql(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>Kg(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},Ug=()=>{const{t}=it(),e=Us(),a=Ze(q=>kl(q,e)),n=Ze(q=>q.selectedProviderId),i=Ze(q=>q.setSelectedProvider),r=Ze(q=>q.getModelMetadata),l=le(q=>q.hiddenModels),m=le(q=>q.toggleHiddenModel),u=le(q=>q.hideAllModels),x=le(q=>q.showAllModels),[d,v]=o.useState({}),[c,N]=o.useState(!1),[f,C]=o.useState({}),[y,S]=o.useState(null),[g,T]=o.useState(""),[M,P]=o.useState([]),[k,h]=o.useState(!1),[j,F]=o.useState(null),[A,I]=o.useState(""),[E,B]=o.useState(""),[_,w]=o.useState(!1),[V,W]=o.useState({}),[L,Q]=o.useState(0),[ne,z]=o.useState(!1),[re,$]=o.useState(null),[U,K]=o.useState(null),[O,Y]=o.useState(null),[X,ee]=o.useState(null),[ge,de]=o.useState(null),[xe,ae]=o.useState(null),te=n===Ea,pe=te&&A===$n,Ie=!!(U&&n&&U===n&&!te);o.useEffect(()=>{!n&&a.length>0&&i(a[0].id)},[a,n,i]),o.useEffect(()=>{if(!n)return;let q=!0;return(async()=>{N(!0);try{const Ae=await fn.getSdkClient().provider.auth();if(Ae.error)throw new Error(`provider.auth failed: ${String(Ae.error)}`);if(!q)return;v(lg(Ae.data))}catch(Ae){if(!q)return;console.error("Failed to load provider auth methods:",Ae),D.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{q&&N(!1)}})(),()=>{q=!1}},[n,t]),o.useEffect(()=>{if(!rg(te))return;let q=!0;return(async()=>{h(!0),F(null);try{const Ae=await fn.getSdkClient().provider.list();if(Ae.error)throw new Error(`provider.list failed: ${String(Ae.error)}`);if(!q)return;P(zg(Ae.data))}catch(Ae){if(!q)return;console.error("Failed to load available providers:",Ae),F(t("settings.providers.page.state.unableToLoadProviderList"))}finally{q&&h(!1)}})(),()=>{q=!1}},[te,t]);const Ne=o.useMemo(()=>new Set(a.map(q=>q.id)),[a]),Se=o.useMemo(()=>M.filter(q=>!Ne.has(q.id)).sort((q,ke)=>{const Ae=(q.name||q.id).toLowerCase(),He=(ke.name||ke.id).toLowerCase();return Ae.localeCompare(He)}),[M,Ne]);o.useEffect(()=>{n===Ea&&A&&A!==$n&&!Se.some(q=>q.id===A)&&I("")},[n,A,Se]),o.useEffect(()=>{if(n===Ea){z(!0),$(null),K(null),Y(null),ee(null),de(null);return}z(!1),$(null),U&&U!==n&&(K(null),Y(null),ee(null),de(null))},[n,U]),o.useEffect(()=>{if(!n||n===Ea)return;const q=V[n];if(!q)return;const ke=a.find(at=>at.id===n),Ae=Ro({key:ke?.key,authSourceExists:q.auth.exists,optionsApiKey:ke?.options?.apiKey??null,envDeclared:Uo(ke)}),He=!!(ke&&Lo(ke,q));pg({hasCredentials:Ae,userDismissed:re===n,isEditableCustomProvider:He})&&z(!0)},[n,V,a,re]),o.useEffect(()=>{if(!n||n===Ea)return;let q=!1;return(async()=>{try{const Ae=e?`?directory=${encodeURIComponent(e)}`:"",He=await ut(`/api/provider/${encodeURIComponent(n)}/source${Ae}`,{method:"GET",headers:{Accept:"application/json"}}),at=await He.json().catch(()=>null);if(!He.ok)throw new Error(at?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const nt=at?.sources??at?.data?.sources;!q&&nt&&W(dt=>({...dt,[n]:nt}))}catch(Ae){q||console.error("Failed to load provider sources:",Ae)}})(),()=>{q=!0}},[n,L,e,t]);const be=o.useCallback(()=>{Q(q=>q+1)},[]),Oe=o.useCallback(q=>{W(ke=>{const Ae=ke[q];return{...ke,[q]:{auth:{exists:!0,path:Ae?.auth.path??null},user:Ae?.user??{exists:!1,path:null},project:Ae?.project??{exists:!1,path:null},...Ae?.custom?{custom:Ae.custom}:{}}}}),$(null),z(!1),i(q),be()},[be,i]),Le=o.useCallback(async(q,ke)=>{try{return await Nl({scopes:[q],mode:"active"}),"reloaded"}catch(Ae){if(Ae?.requiresManualRestart===!0)return ke&&Gn(q,{id:ke}),"manual-restart";throw Ae}},[]),oe=a.find(q=>q.id===n),fe=n?V[n]:void 0,Me=async q=>{const ke=f[q]?.trim()??"";if(!ke){D.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ae=`api:${q}`;S(Ae);try{if((await fn.getSdkClient().auth.set({providerID:q,auth:{type:"api",key:ke}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));D.success(t("settings.providers.page.toast.apiKeySaved")),C(at=>({...at,[q]:""})),await Le("providers",q),Oe(q)}catch(He){console.error("Failed to save API key:",He),D.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{S(null)}},$e=async q=>{const ke=`custom:${q.providerID}`;S(ke),ae(q.providerID),de(null);try{const Ae=jg(q);if(Ae&&(await fn.getSdkClient().auth.set(Ae)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const He=wg(q,{scope:U?X??Oo(V[U]):"user"}),at=await ut(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(He)}),nt=await at.json().catch(()=>null);if(!at.ok)throw Ae&&de(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(nt?.error||t("settings.providers.page.toast.customProviderSaveFailed"));D.success(t("settings.providers.page.toast.customProviderSaved",{provider:q.name})),I(""),K(null),Y(null),ee(null),de(null),ae(null),await Le("providers",q.providerID),Oe(q.providerID)}catch(Ae){console.error("Failed to save custom provider:",Ae),D.error(Ae instanceof Error&&Ae.message?Ae.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{S(null)}},Ve=q=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(q+1)}),qe=q=>{z(!1),cg(q)&&Gn("providers",{id:q}),Oe(q)},se=async q=>{const ke=`disconnect:${q}`;S(ke);try{const Ae=await ut(`/api/provider/${encodeURIComponent(q)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),He=await Ae.json().catch(()=>null);if(!Ae.ok)throw new Error(He?.error||t("settings.providers.page.toast.providerDisconnectFailed"));D.success(t("settings.providers.page.toast.providerDisconnected")),await Le("providers",q),$(null),be()}catch(Ae){console.error("Failed to disconnect provider:",Ae),D.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{S(null)}},ie=async q=>{q&&(await se(q),K(null),Y(null),ee(null),de(null),ae(null),I(""))};if(!te&&a.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(R,{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(es,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(_e,{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")}),k?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):j?s.jsx("p",{className:"typography-meta text-muted-foreground",children:j}):s.jsxs(ln,{open:_,onOpenChange:q=>{w(q),q||B("")},children:[s.jsx(rn,{asChild:!0,children:s.jsxs("button",{type:"button",className:En,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[A&&A!==$n?s.jsx(Bn,{providerId:A,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ve("truncate typography-ui-label font-normal",A?"text-foreground":"text-muted-foreground"),children:A===$n?t("settings.providers.page.custom.optionLabel"):A?Se.find(q=>q.id===A)?.name||A:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(on,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:q=>q.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:q=>q.stopPropagation(),children:[s.jsx(R,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:E,onChange:q=>B(q.target.value),onKeyDown:q=>q.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(Hs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const q=t("settings.providers.page.custom.optionLabel"),ke=Mc([q,"other","custom"],E),Ae=Ni(Se,E,He=>[He.name||He.id,He.id]);return Ae.length===0&&!ke?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:[Ae.map(He=>s.jsxs(cn,{onSelect:()=>{I(He.id),w(!1),B("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Bn,{providerId:He.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:He.name||He.id})]}),A===He.id&&s.jsx(R,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},He.id)),ke?s.jsxs(cn,{onSelect:()=>{I($n),w(!1),B("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(R,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:q})]}),A===$n&&s.jsx(R,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},$n):null]})})()})]})]})]})}),pe?s.jsx(Fo,{mode:"create",existingProviderIDs:Ne,busy:y?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{I(""),de(null),ae(null)},onDisconnect:ge&&xe?()=>{ie(xe)}:void 0,onSubmit:$e}):A?s.jsx(_e,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const q=d[A]??[],ke=$o(Mo(q),Ve),Ae=Do(q);return s.jsxs(s.Fragment,{children:[Ae?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(Jt,{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(Je,{type:"password",value:f[A]??"",onChange:He=>C(at=>({...at,[A]:He.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(A),disabled:y===`api:${A}`,children:y===`api:${A}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ke.length>0?s.jsx(zo,{providerId:A,methods:ke,onConnected:()=>qe(A),className:ve(Ae&&"border-t border-[var(--surface-subtle)] pt-2")},A):null]})})()})}):null]});if(!oe)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(R,{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 we=Array.isArray(oe.models)?oe.models:[],ye=d[oe.id]??[],Te=$o(Mo(ye),Ve),Ue=Do(ye),Pe=!!fe,je=Pe&&Lo(oe,fe),Ge=Ro({key:oe.key,authSourceExists:fe?.auth.exists,optionsApiKey:oe.options?.apiKey??null,envDeclared:Uo(oe)}),me=og(Pe,Ge,je),Ce=dg({modelCount:we.length,sourcesLoaded:Pe,hasCredentials:Ge,isEditableCustomProvider:je}),Re=!Ue&&Te.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),Ye=Ni(we,g,q=>[typeof q?.name=="string"?q.name:"",typeof q?.id=="string"?q.id:""]);return Ie&&je&&O?s.jsx(es,{title:oe.name||oe.id,titleLeading:s.jsx(Bn,{providerId:oe.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:oe.id}),showSaveStatus:!1,children:s.jsx(Fo,{mode:"edit",existingProviderIDs:Ne,initialValues:O,allowExistingAuth:Ge||!Pe,busy:y?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{K(null),Y(null),ee(null),de(null),ae(null)},onDisconnect:()=>{ie(oe.id)},onSubmit:$e})}):s.jsxs(es,{title:oe.name||oe.id,titleLeading:s.jsx(Bn,{providerId:oe.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:oe.id}),showSaveStatus:!1,children:[s.jsx(_e,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[je?s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{de(null),Y(vg(oe)),ee(Oo(fe)),K(oe.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=!ne;z(q),$(q?null:oe.id)},children:t(ne?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:ne?c?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:[Ue?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(Jt,{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(Je,{type:"password",value:f[oe.id]??"",onChange:q=>C(ke=>({...ke,[oe.id]:q.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(oe.id),disabled:y===`api:${oe.id}`,children:y===`api:${oe.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,Te.length>0&&s.jsx(zo,{providerId:oe.id,methods:Te,onConnected:()=>qe(oe.id),className:ve(Ue&&"border-t border-[var(--surface-subtle)] pt-2")},oe.id)]}):me?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(R,{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(Jt,{children:Re})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(R,{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(Jt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(_e,{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:fe&&(fe.auth.exists||fe.user.exists||fe.project.exists||fe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[fe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,fe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,fe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,fe.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:()=>se(oe.id),disabled:y===`disconnect:${oe.id}`,children:y===`disconnect:${oe.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Ce?s.jsxs(_e,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",we.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const q=we.map(ke=>typeof ke?.id=="string"?ke.id:"").filter(ke=>ke.length>0);u(oe.id,q)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(H,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>x(oe.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(R,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Je,{value:g,onChange:q=>T(q.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),Ye.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:Ye.map(q=>{const ke=typeof q?.id=="string"?q.id:"",Ae=typeof q?.name=="string"?q.name:ke,He=ke?r(oe.id,ke):void 0,at=l.some(G=>G.providerID===oe.id&&G.modelID===ke),nt=_o(He?.limit?.context),dt=_o(He?.limit?.output),xt=[];return He?.tool_call&&xt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),He?.reasoning&&xt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),He?.attachment&&xt.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:ve("flex items-center gap-3",at&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Ae}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(nt||dt)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[nt?`${nt} ${t("settings.providers.page.models.tokenBadge.context")}`:"",nt&&dt?" · ":"",dt?`${dt} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),xt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:xt.map(({key:G,icon:Be,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(R,{name:Be,className:"h-3 w-3"})},G))}),s.jsx("button",{type:"button",onClick:()=>m(oe.id,ke),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(at?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(at?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:at?s.jsx(R,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(R,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ke)})})]}):null]})},_g=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)},$g=t=>{const e=gt.c(75),{onItemSelect:a}=t,{t:n}=it(),i=Zt(Vg),r=Zt(Bg),l=Zt(Hg),m=Zt(Gg),u=Zt(qg),x=Zt(Wg),d=Zt(Jg),v=Zt(Qg);let c,N;e[0]!==v?(c=()=>{v()},N=[v],e[0]=v,e[1]=c,e[2]=N):(c=e[1],N=e[2]),o.useEffect(c,N);const f=Yg;let C;e[3]!==d?(C=ee=>{ee!=="usage"&&ee!=="remaining"||(d(ee),f({usageDisplayMode:ee}))},e[3]=d,e[4]=C):C=e[4];const y=C;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=ve("flex h-full flex-col","bg-background"),e[5]=S):S=e[5];let g;e[6]!==n?(g=n("settings.usage.sidebar.title"),e[6]=n,e[7]=g):g=e[7];let T;e[8]!==g?(T=s.jsx("h2",{className:`${dn} mb-3`,children:g}),e[8]=g,e[9]=T):T=e[9];let M;e[10]!==n?(M=n("settings.usage.sidebar.total",{count:Si.length}),e[10]=n,e[11]=M):M=e[11];let P;e[12]!==M?(P=s.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[12]=M,e[13]=P):P=e[13];let k;e[14]!==m?(k=()=>m(),e[14]=m,e[15]=k):k=e[15];let h;e[16]!==n?(h=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=h):h=e[17];let j;e[18]!==n?(j=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=j):j=e[19];const F=u&&"animate-spin";let A;e[20]!==F?(A=ve("h-3.5 w-3.5",F),e[20]=F,e[21]=A):A=e[21];let I;e[22]!==A?(I=s.jsx(R,{name:"refresh",className:A}),e[22]=A,e[23]=I):I=e[23];let E;e[24]!==u||e[25]!==h||e[26]!==j||e[27]!==I||e[28]!==k?(E=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:k,"aria-label":h,title:j,disabled:u,children:I})}),e[24]=u,e[25]=h,e[26]=j,e[27]=I,e[28]=k,e[29]=E):E=e[29];let B;e[30]!==E||e[31]!==P?(B=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,E]}),e[30]=E,e[31]=P,e[32]=B):B=e[32];let _;e[33]!==n?(_=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=_):_=e[34];let w;e[35]!==_?(w=s.jsx("span",{className:"typography-micro text-muted-foreground",children:_}),e[35]=_,e[36]=w):w=e[36];let V;e[37]!==n?(V=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=V):V=e[38];let W;e[39]!==V?(W=s.jsx(Pt,{className:"w-fit",children:s.jsx(Rt,{placeholder:V})}),e[39]=V,e[40]=W):W=e[40];let L;e[41]!==n?(L=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=L):L=e[42];let Q;e[43]!==L?(Q=s.jsx(ot,{value:"usage",children:L}),e[43]=L,e[44]=Q):Q=e[44];let ne;e[45]!==n?(ne=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=ne):ne=e[46];let z;e[47]!==ne?(z=s.jsx(ot,{value:"remaining",children:ne}),e[47]=ne,e[48]=z):z=e[48];let re;e[49]!==Q||e[50]!==z?(re=s.jsxs(At,{children:[Q,z]}),e[49]=Q,e[50]=z,e[51]=re):re=e[51];let $;e[52]!==y||e[53]!==W||e[54]!==re||e[55]!==x?($=s.jsxs(It,{value:x,onValueChange:y,children:[W,re]}),e[52]=y,e[53]=W,e[54]=re,e[55]=x,e[56]=$):$=e[56];let U;e[57]!==w||e[58]!==$?(U=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[w,$]}),e[57]=w,e[58]=$,e[59]=U):U=e[59];let K;e[60]!==B||e[61]!==U||e[62]!==T?(K=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,B,U]}),e[60]=B,e[61]=U,e[62]=T,e[63]=K):K=e[63];let O;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(O=Si.map(ee=>{const ge=i.find(Ie=>Ie.providerId===ee.id),de=_g(ge?.usage),xe=Sl(de),ae=ee.id===r,te=ge?.configured??!1,pe=te?xe==="critical"?{backgroundColor:"var(--status-error)"}:xe==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ae?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(ee.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:pe}),s.jsx(Bn,{providerId:ee.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:ee.name}),!te&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},ee.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=O):O=e[69];let Y;e[70]!==O?(Y=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:O}),e[70]=O,e[71]=Y):Y=e[71];let X;return e[72]!==K||e[73]!==Y?(X=s.jsxs("div",{className:S,children:[K,Y]}),e[72]=K,e[73]=Y,e[74]=X):X=e[74],X};function Vg(t){return t.results}function Bg(t){return t.selectedProviderId}function Hg(t){return t.setSelectedProvider}function Gg(t){return t.fetchAllQuotas}function qg(t){return t.isLoading}function Wg(t){return t.displayMode}function Jg(t){return t.setDisplayMode}function Qg(t){return t.loadSettings}async function Yg(t){try{await vt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Xg=t=>{const e=gt.c(17),{percent:a,tonePercent:n,className:i}=t;let r;e[0]!==a?(r=Rc(a)??0,e[0]=a,e[1]=r):r=e[1];const l=r,m=n??a;let u;e[2]!==m?(u=Sl(m),e[2]=m,e[3]=u):u=e[3];const x=u;let d;e[4]!==x?(d=x==="critical"?{backgroundColor:"var(--status-error)"}:x==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=x,e[5]=d):d=e[5];const v=d;let c;e[6]!==i?(c=ve("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=c):c=e[7];const N=`${l}%`;let f;e[8]!==v||e[9]!==N?(f={...v,width:N},e[8]=v,e[9]=N,e[10]=f):f=e[10];let C;e[11]!==l||e[12]!==f?(C=s.jsx("div",{className:"h-full transition-all duration-300",style:f,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=f,e[13]=C):C=e[13];let y;return e[14]!==c||e[15]!==C?(y=s.jsx("div",{className:c,children:C}),e[14]=c,e[15]=C,e[16]=y):y=e[16],y},Zi=t=>{const e=gt.c(44),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:m}=t,u=r===void 0?!1:r,x=l===void 0?!1:l,d=Zt(Zg),v=le(eh),c=d==="remaining"?n.remainingPercent:n.usedPercent,N=d==="remaining"?"remaining":"used";let f;e[0]!==c||e[1]!==n.valueLabel?(f=Lc(n.valueLabel,c),e[0]=c,e[1]=n.valueLabel,e[2]=f):f=e[2];const C=f,y=n.resetAfterFormatted??n.resetAtFormatted;let S;e[3]!==y||e[4]!==v||e[5]!==n.resetAt?(S=Oc(n.resetAt,y,v),e[3]=y,e[4]=v,e[5]=n.resetAt,e[6]=S):S=e[6];const g=S;let T;e[7]!==a?(T=Fc(a),e[7]=a,e[8]=T):T=e[8];const M=T;let P;e[9]!==m||e[10]!==u||e[11]!==x?(P=u&&s.jsx(or,{checked:x,onChange:ne=>m?.(ne),ariaLabel:"Show in dropdown"}),e[9]=m,e[10]=u,e[11]=x,e[12]=P):P=e[12];let k;e[13]!==M?(k=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:M}),e[13]=M,e[14]=k):k=e[14];let h;e[15]!==i?(h=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=h):h=e[16];let j;e[17]!==k||e[18]!==h?(j=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[k,h]}),e[17]=k,e[18]=h,e[19]=j):j=e[19];let F;e[20]!==j||e[21]!==P?(F=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[P,j]}),e[20]=j,e[21]=P,e[22]=F):F=e[22];const A=C==="-"?"":C;let I;e[23]!==A?(I=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:A}),e[23]=A,e[24]=I):I=e[24];let E;e[25]!==F||e[26]!==I?(E=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[F,I]}),e[25]=F,e[26]=I,e[27]=E):E=e[27];let B;e[28]!==c||e[29]!==n.usedPercent?(B=s.jsx(Xg,{percent:c,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=c,e[29]=n.usedPercent,e[30]=B):B=e[30];const _=g?`Resets ${g}`:"";let w;e[31]!==_?(w=s.jsx("span",{className:"typography-micro text-muted-foreground",children:_}),e[31]=_,e[32]=w):w=e[32];let V;e[33]!==N?(V=s.jsx("span",{className:"typography-micro text-muted-foreground",children:N}),e[33]=N,e[34]=V):V=e[34];let W;e[35]!==w||e[36]!==V?(W=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[w,V]}),e[35]=w,e[36]=V,e[37]=W):W=e[37];let L;e[38]!==B||e[39]!==W?(L=s.jsxs("div",{className:"mt-2.5",children:[B,W]}),e[38]=B,e[39]=W,e[40]=L):L=e[40];let Q;return e[41]!==E||e[42]!==L?(Q=s.jsxs("div",{className:"py-3",children:[E,L]}),e[41]=E,e[42]=L,e[43]=Q):Q=e[43],Q};function Zg(t){return t.displayMode}function eh(t){return t.timeFormatPreference}const th=`ssh exe.dev "ssh-key generate-api-key --label=openchamber --exp=30d --cmds='billing credits usage'"`,sh=({providerId:t,providerName:e})=>{const{t:a}=it(),[n,i]=o.useState(null),[r,l]=o.useState({}),[m,u]=o.useState(!1),x=`/api/quota/credentials/${t}`;o.useEffect(()=>{ut(x).then(async c=>{if(!c.ok)throw new Error;const N=await c.json();i(N),l({})}).catch(()=>i({configured:!1}))},[x]);const d=async(c,N,f)=>{u(!0);try{const C=await ut(c,{method:N,headers:f?{"Content-Type":"application/json"}:void 0,body:f?JSON.stringify(f):void 0}),y=await C.json().catch(()=>null);if(!C.ok)throw new Error(y?.error);y?.configured!==void 0&&i(y),l({}),D.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(C){D.error(C instanceof Error&&C.message?C.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{u(!1)}},v=(c,N,f)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[N,s.jsx(Je,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[c]??"",onChange:C=>l(y=>({...y,[c]:C.target.value})),placeholder:n?.secretMasked??f})]});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==="exe-dev"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:a("settings.providers.page.quotaCredentials.exeDevTokenInstructions")}),s.jsx("code",{className:"typography-code block whitespace-pre-wrap break-all rounded bg-muted/50 px-2 py-1.5 text-xs text-foreground",children:th})]}),t==="ollama-cloud"&&v("cookie",a("settings.providers.page.openCodeGo.authCookie"),"session=..."),t==="exe-dev"&&v("usageToken",a("settings.providers.page.quotaCredentials.usageToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),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:m,onClick:()=>d(x,"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:m,onClick:()=>d(`${x}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(H,{variant:"outline",size:"xs",disabled:m,onClick:()=>d(`${x}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(H,{variant:"destructive",size:"xs",disabled:m,onClick:()=>d(x,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Vo=(t,e)=>{if(!t)return"-";try{return Cl(t,e,{fallback:"-"})}catch{return"-"}},nh=()=>{const{t}=it(),e=le(w=>w.timeFormatPreference),a=Zt(w=>w.results),n=Zt(w=>w.selectedProviderId),i=Zt(w=>w.setSelectedProvider),r=Zt(w=>w.loadSettings),l=Zt(w=>w.fetchAllQuotas),m=Zt(w=>w.isLoading),u=Zt(w=>w.lastUpdated),x=Zt(w=>w.error),d=Zt(w=>w.dropdownProviderIds),v=Zt(w=>w.setDropdownProviderIds),c=Zt(w=>w.selectedModels),N=Zt(w=>w.toggleModelSelected),f=Zt(w=>w.applyDefaultSelections);Kc(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const w=a.find(V=>V.configured)?.providerId;i(w??Si[0]?.id??null)},[a,n,i]);const C=a.find(w=>w.providerId===n)??null,S=Si.find(w=>w.id===n)?.name??n??t("settings.usage.sidebar.title"),g=C?.usage,T=C?.configured&&!C.ok?C.error:null,M=n?d.includes(n):!1,P=n==="exe-dev"||n==="ollama-cloud"||n==="cursor",k=o.useCallback(w=>{if(!n)return;const V=w?Array.from(new Set([...d,n])):d.filter(W=>W!==n);v(V),vt({usageDropdownProviders:V})},[d,n,v]),h=o.useMemo(()=>g?.models?Object.entries(g.models).map(([w,V])=>({name:w,windows:V})).filter(w=>Object.keys(w.windows.windows).length>0):[],[g?.models]);o.useEffect(()=>{n&&h.length>0&&f(n,h.map(w=>w.name))},[n,h,f]);const j=o.useMemo(()=>!n||h.length===0?new Map:zc(h,w=>w.name,n),[h,n]),F=o.useMemo(()=>{if(!n)return[];const w=_c(n);return Uc(w)},[n]),[A,I]=o.useState(()=>({})),E=o.useCallback(w=>{I(V=>({...V,[w]:!V[w]}))},[]),B=o.useCallback(w=>{if(!n)return;N(n,w);const V=c[n]??[],L=V.includes(w)?V.filter(ne=>ne!==w):[...V,w],Q={...c,[n]:L};vt({usageSelectedModels:Q})},[n,c,N]),_=n?c[n]??[]:[];return n?s.jsxs(es,{title:t("settings.usage.page.header.providerUsage",{provider:S}),titleLeading:s.jsx(Bn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:m?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):C?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:C.planLabel,time:Vo(u,e)}):t("settings.usage.page.header.lastUpdated",{time:Vo(u,e)}),showSaveStatus:!0,children:[s.jsx(_e,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(ht,{checked:M,onChange:k,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!C&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(x||T)&&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:x??T})]}),C&&!C.configured&&!P&&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==="exe-dev"||n==="ollama-cloud"||n==="cursor")&&s.jsx(sh,{providerId:n,providerName:S}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx(_e,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([w,V])=>s.jsx(Zi,{title:w,window:V},w))})}),h.length>0&&s.jsxs(_e,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[F.map(w=>{const V=j.get(w.id)??[];if(V.length===0)return null;const W=A[w.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Mn,{open:!W,onOpenChange:()=>E(w.id),children:[s.jsxs(Rn,{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:w.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",V.length,")"]})]}),W?s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Ln,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:V.map(L=>{const Q=Object.entries(L.windows.windows);if(Q.length===0)return null;const[ne,z]=Q[0],re=_.includes(L.name);return s.jsx(Zi,{title:ne,subtitle:Fr(L.name),window:z,showToggle:!0,toggleEnabled:re,onToggle:()=>B(L.name)},L.name)})})})]})},w.id)}),(()=>{const w=j.get(null)??[];if(w.length===0)return null;const V=A.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Mn,{open:!V,onOpenChange:()=>E("other"),children:[s.jsxs(Rn,{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:["(",w.length,")"]})]}),V?s.jsx(R,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Ln,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:w.map(W=>{const L=Object.entries(W.windows.windows);if(L.length===0)return null;const[Q,ne]=L[0],z=_.includes(W.name);return s.jsx(Zi,{title:Q,subtitle:Fr(W.name),window:ne,showToggle:!0,toggleEnabled:z,onToggle:()=>B(W.name)},W.name)})})})]})})})()]}),C?.configured&&g&&Object.keys(g.windows??{}).length===0&&h.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")})})},ah="git.commit.generate",hr=Ll(t=>({selectedPromptId:ah,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),ih=t=>{const e=gt.c(24),{onItemSelect:a}=t,{t:n}=it(),i=hr(rh),r=hr(oh);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 m;e[1]===Symbol.for("react.memo_cache_sentinel")?(m={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]=m):m=e[1];let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=u):u=e[2];let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x={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[3]=x):x=e[3];let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=[l,m,u,x,{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[4]=d):d=e[4];const v=d;let c;e[5]!==n?(c=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=c):c=e[6];let N;e[7]!==c?(N=s.jsx("h2",{className:dn,children:c}),e[7]=c,e[8]=N):N=e[8];let f;e[9]!==n?(f=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=f):f=e[10];let C;e[11]!==f?(C=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:f}),e[11]=f,e[12]=C):C=e[12];let y;e[13]!==N||e[14]!==C?(y=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[N,C]}),e[13]=N,e[14]=C,e[15]=y):y=e[15];let S;e[16]!==a||e[17]!==i||e[18]!==r||e[19]!==n?(S=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:v.map(T=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(T.groupKey)}),T.items.map(M=>{const P=i===M.id;return s.jsx("button",{type:"button",onClick:()=>{r(M.id),a?.()},className:ve("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",P?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(M.titleKey)})},M.id)})]},T.groupKey))}),e[16]=a,e[17]=i,e[18]=r,e[19]=n,e[20]=S):S=e[20];let g;return e[21]!==y||e[22]!==S?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[y,S]}),e[21]=y,e[22]=S,e[23]=g):g=e[23],g};function rh(t){return t.selectedPromptId}function oh(t){return t.setSelectedPromptId}const Bo={"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"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.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"}]}},Ho=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),er=t=>t.endsWith(".visible"),lh=()=>{const{t}=it(),e=o.useCallback(k=>t(k),[t]),a=hr(k=>k.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[m,u]=o.useState({}),[x,d]=o.useState({}),[v,c]=o.useState({}),[N,f]=o.useState(!1);o.useEffect(()=>{let k=!0;return(async()=>{i(!0);try{const j=await Hc();if(!k)return;l(j)}catch(j){console.warn("Failed to load magic prompts:",j),D.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{k&&i(!1)}})(),()=>{k=!1}},[t]);const C=Bo[a]??Bo["git.commit.generate"],y=o.useCallback(k=>Ho(r,k)?r[k]:Vi(k),[r]),S=o.useCallback(k=>m[k]??y(k),[m,y]),g=o.useCallback((k,h)=>{u(j=>j[k]===h?j:{...j,[k]:h})},[]),T=o.useCallback(async k=>{const h=S(k);if(er(k)&&h.trim().length===0){D.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}d(j=>({...j,[k]:!0}));try{const j=h===Vi(k)?await Kr(k):await $c(k,h);l(j.overrides),D.success(t("settings.magicPrompts.page.toast.saved"))}catch(j){const F=j instanceof Error?j.message:String(j);D.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:F})}finally{d(j=>({...j,[k]:!1}))}},[S,t]),M=o.useCallback(async k=>{c(h=>({...h,[k]:!0}));try{const h=await Kr(k);l(h.overrides),u(j=>({...j,[k]:Vi(k)})),D.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(h){const j=h instanceof Error?h.message:String(h);D.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:j})}finally{c(h=>({...h,[k]:!1}))}},[t]),P=o.useCallback(async()=>{f(!0);try{const k=await Vc();l(k.overrides),u({}),D.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(k){const h=k instanceof Error?k.message:String(k);D.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:h})}finally{f(!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(es,{title:e(C.titleKey),titleAccessory:s.jsx(Jt,{contentClassName:"max-w-xs",children:e(C.descriptionKey)}),headerEnd:s.jsx(H,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{P()},disabled:N||Object.keys(r).length===0,children:t(N?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:C.blocks.map((k,h)=>{const j=Bc(k.id),F=y(k.id),A=S(k.id),I=Ho(r,k.id),E=A!==F,B=er(k.id)&&A.trim().length===0,_=x[k.id]===!0,w=v[k.id]===!0;return s.jsxs(_e,{title:e(k.titleKey),info:j.description,description:j.placeholders&&j.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${j.placeholders.map(V=>`{{${V.key}}}`).join(", ")}`:void 0,divider:h>0,settingsItem:er(k.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(As,{value:A,onChange:V=>g(k.id,V.target.value),className:"min-h-[220px] font-mono text-sm"}),B&&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(E?"settings.magicPrompts.page.status.unsavedChanges":I?"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:()=>{M(k.id)},disabled:!I||_||w,children:t(w?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(H,{size:"sm",onClick:()=>{T(k.id)},disabled:!E||_||w||B,children:t(_?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},k.id)})})},ch=t=>{const e=gt.c(89),{onItemSelect:a}=t,{t:n}=it(),[i,r]=o.useState(null),[l,m]=o.useState(null),[u,x]=o.useState(null),{selectedSnippetName:d,snippets:v,setSelectedSnippet:c,setSnippetDraft:N,deleteSnippet:f,loadSnippets:C}=Ci(Ks(dh));let y,S;e[0]!==C?(y=()=>{C()},S=[C],e[0]=C,e[1]=y,e[2]=S):(y=e[1],S=e[2]),o.useEffect(y,S);let g;e[3]!==a||e[4]!==c||e[5]!==N||e[6]!==v?(g=async()=>{const Ne=new Set(v.map(ph));let Se="new-snippet",be=1;for(;Ne.has(Se);)Se=`new-snippet-${be++}`;N({name:Se,scope:"global"}),c(Se),a?.()},e[3]=a,e[4]=c,e[5]=N,e[6]=v,e[7]=g):g=e[7];const T=g;let M;e[8]!==i||e[9]!==f||e[10]!==n?(M=async()=>{if(!i)return;await f(i.name)?(D.success(n("settings.snippets.sidebar.toast.deleted")),r(null)):D.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=f,e[10]=n,e[11]=M):M=e[11];const P=M;let k;e[12]!==v?(k=[...v].sort(mh),e[12]=v,e[13]=k):k=e[13];const h=k;let j;e[14]===Symbol.for("react.memo_cache_sentinel")?(j=ve("flex h-full flex-col","bg-background"),e[14]=j):j=e[14];let F;e[15]!==n?(F=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=F):F=e[16];let A;e[17]!==F?(A=s.jsx("h2",{className:`${dn} mb-3`,children:F}),e[17]=F,e[18]=A):A=e[18];let I;e[19]!==v.length||e[20]!==n?(I=n("settings.snippets.sidebar.total",{count:v.length}),e[19]=v.length,e[20]=n,e[21]=I):I=e[21];let E;e[22]!==I?(E=s.jsx("span",{className:"typography-meta text-muted-foreground",children:I}),e[22]=I,e[23]=E):E=e[23];let B;e[24]!==n?(B=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=B):B=e[25];let _;e[26]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),e[26]=_):_=e[26];let w;e[27]!==T||e[28]!==B?(w=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:T,"aria-label":B,children:_}),e[27]=T,e[28]=B,e[29]=w):w=e[29];let V;e[30]!==E||e[31]!==w?(V=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[E,w]}),e[30]=E,e[31]=w,e[32]=V):V=e[32];let W;e[33]!==V||e[34]!==A?(W=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[A,V]}),e[33]=V,e[34]=A,e[35]=W):W=e[35];let L;if(e[36]!==a||e[37]!==l||e[38]!==u||e[39]!==d||e[40]!==c||e[41]!==h||e[42]!==n){let Ne;e[44]!==a||e[45]!==l||e[46]!==u||e[47]!==d||e[48]!==c||e[49]!==n?(Ne=Se=>s.jsxs(ea,{open:u===Se.name,onOpenChange:be=>x(be?Se.name:null),children:[s.jsxs(Zn,{render:s.jsx("div",{className:ve("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",d===Se.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:be=>{be.preventDefault(),x(Se.name)}}),children:[s.jsxs("button",{onClick:()=>{c(Se.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:["#",Se.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.${Se.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:Se.description||Se.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(ln,{open:l===Se.name,onOpenChange:be=>{be&&x(null),m(be?Se.name:null)},children:[s.jsx(rn,{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:Se.name}),children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(on,{align:"end",className:"w-fit min-w-20",children:s.jsxs(cn,{onClick:be=>{be.stopPropagation(),r(Se)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Yn,{className:"w-fit min-w-20",children:s.jsxs(Xn,{onClick:be=>{be.stopPropagation(),r(Se)},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${Se.source}:${Se.filePath}`),e[44]=a,e[45]=l,e[46]=u,e[47]=d,e[48]=c,e[49]=n,e[50]=Ne):Ne=e[50],L=h.map(Ne),e[36]=a,e[37]=l,e[38]=u,e[39]=d,e[40]=c,e[41]=h,e[42]=n,e[43]=L}else L=e[43];let Q;e[51]!==L?(Q=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:L}),e[51]=L,e[52]=Q):Q=e[52];const ne=i!==null;let z;e[53]===Symbol.for("react.memo_cache_sentinel")?(z=Ne=>{Ne||r(null)},e[53]=z):z=e[53];let re;e[54]!==n?(re=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=re):re=e[55];let $;e[56]!==re?($=s.jsx($t,{children:re}),e[56]=re,e[57]=$):$=e[57];const U=i?.name??"";let K;e[58]!==n||e[59]!==U?(K=n("settings.snippets.sidebar.dialog.deleteDescription",{name:U}),e[58]=n,e[59]=U,e[60]=K):K=e[60];let O;e[61]!==K?(O=s.jsx(Vt,{children:K}),e[61]=K,e[62]=O):O=e[62];let Y;e[63]!==$||e[64]!==O?(Y=s.jsxs(_t,{children:[$,O]}),e[63]=$,e[64]=O,e[65]=Y):Y=e[65];let X;e[66]===Symbol.for("react.memo_cache_sentinel")?(X=()=>r(null),e[66]=X):X=e[66];let ee;e[67]!==n?(ee=n("settings.common.actions.cancel"),e[67]=n,e[68]=ee):ee=e[68];let ge;e[69]!==ee?(ge=s.jsx(H,{size:"sm",variant:"ghost",onClick:X,children:ee}),e[69]=ee,e[70]=ge):ge=e[70];let de;e[71]!==n?(de=n("settings.common.actions.delete"),e[71]=n,e[72]=de):de=e[72];let xe;e[73]!==P||e[74]!==de?(xe=s.jsx(H,{size:"sm",onClick:P,children:de}),e[73]=P,e[74]=de,e[75]=xe):xe=e[75];let ae;e[76]!==ge||e[77]!==xe?(ae=s.jsxs(ts,{children:[ge,xe]}),e[76]=ge,e[77]=xe,e[78]=ae):ae=e[78];let te;e[79]!==Y||e[80]!==ae?(te=s.jsxs(zt,{className:"max-w-md",children:[Y,ae]}),e[79]=Y,e[80]=ae,e[81]=te):te=e[81];let pe;e[82]!==ne||e[83]!==te?(pe=s.jsx(Kt,{open:ne,onOpenChange:z,children:te}),e[82]=ne,e[83]=te,e[84]=pe):pe=e[84];let Ie;return e[85]!==W||e[86]!==Q||e[87]!==pe?(Ie=s.jsxs("div",{className:j,children:[W,Q,pe]}),e[85]=W,e[86]=Q,e[87]=pe,e[88]=Ie):Ie=e[88],Ie};function dh(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function ph(t){return t.name}function mh(t,e){return t.name.localeCompare(e.name)}const uh=()=>{const{t}=it(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=Ci(Ks(j=>({selectedSnippetName:j.selectedSnippetName,snippets:j.snippets,snippetDraft:j.snippetDraft,setSnippetDraft:j.setSnippetDraft,updateSnippet:j.updateSnippet,createSnippet:j.createSnippet}))),m=o.useMemo(()=>e?a.find(j=>j.name===e||j.aliases.includes(e))??null:null,[e,a]),u=!!(n&&n.name===e&&!m),[x,d]=o.useState(""),[v,c]=o.useState("global"),[N,f]=o.useState(""),[C,y]=o.useState(""),[S,g]=o.useState(""),[T,M]=o.useState(!1),P=o.useRef(null);o.useEffect(()=>{if(u&&n){const j={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};d(j.draftName),c(j.draftScope),f(j.description),y(j.aliases),g(j.content),P.current=j}else if(m){const j={draftName:"",draftScope:"global",description:m.description??"",aliases:m.aliases.join(", "),content:m.content};f(j.description),y(j.aliases),g(j.content),P.current=j}},[m,u,e,n]);const k=o.useMemo(()=>{const j=P.current;return j?u&&x!==j.draftName||u&&v!==j.draftScope?!0:N!==j.description||C!==j.aliases||S!==j.content:!1},[C,S,N,x,v,u]),h=async()=>{const j=u?x.trim().replace(/\s+/g,"-"):e?.trim();if(!j){D.error(t("settings.snippets.page.toast.nameRequired"));return}if(!S.trim()){D.error(t("settings.snippets.page.toast.contentRequired"));return}const F=C.split(",").map(A=>A.trim()).filter(Boolean);M(!0);try{if(!(u?await l(j,S,{aliases:F,description:N,scope:v}):await r(j,{content:S,aliases:F,description:N}))){D.error(t("settings.snippets.page.toast.saveFailed"));return}D.success(t("settings.snippets.page.toast.saved")),u&&i(null)}finally{M(!1)}};return e?s.jsxs(es,{title:u?t("settings.snippets.page.title.new"):`#${e}`,description:m?m.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(_e,{divider:!1,contentClassName:"space-y-0",children:[u?s.jsxs(Lt,{label:"#",children:[s.jsx(Je,{value:x,onChange:j=>d(j.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(It,{value:v,onValueChange:j=>c(j),children:[s.jsx(Pt,{size:Ft,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"global",children:t("settings.common.scope.global")}),s.jsx(ot,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Wt,{label:t("settings.common.field.description"),children:s.jsx(Je,{value:N,onChange:j=>f(j.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Wt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(Je,{value:C,onChange:j=>y(j.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(_e,{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(Jt,{children:t("settings.snippets.page.hint")})]}),s.jsx(As,{value:S,onChange:j=>g(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:h,disabled:T||!k,size:"xs",className:"!font-normal",children:t(T?"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(R,{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")})]})})},Yl=()=>{const{t}=it(),e=Ze(v=>v.settingsGitmojiEnabled),a=Ze(v=>v.setSettingsGitmojiEnabled),n=Nd(),i=le(v=>v.gitChangesViewMode),r=le(v=>v.setGitChangesViewMode),[l,m]=o.useState(!0),u=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 c=null;if(!c){const N=an()?.settings;if(N)try{const C=(await N.load())?.settings;C&&(c={gitmojiEnabled:typeof C.gitmojiEnabled=="boolean"?C.gitmojiEnabled:void 0,gitChangesViewMode:C.gitChangesViewMode==="flat"||C.gitChangesViewMode==="tree"?C.gitChangesViewMode:void 0})}catch{}}if(!c){const N=await ut("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});N.ok&&(c=await N.json())}c&&(typeof c.gitmojiEnabled=="boolean"&&a(c.gitmojiEnabled),(c.gitChangesViewMode==="flat"||c.gitChangesViewMode==="tree")&&r(c.gitChangesViewMode))}catch(c){console.warn("Failed to load git settings:",c)}finally{m(!1)}})()},[r,a]);const x=o.useCallback(async v=>{a(v);try{await vt({gitmojiEnabled:v})}catch(c){console.warn("Failed to save gitmoji setting:",c)}},[a]),d=o.useCallback(v=>{v!==i&&(r(v),vt({gitChangesViewMode:v}))},[i,r]);return l?null:s.jsx(_e,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(Ps,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(en,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:u.map(v=>s.jsx(tn,{selected:i===v.id,onSelect:()=>{d(v.id)},label:v.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:v.label})},v.id))})}),s.jsx(ht,{settingsItem:"git.gitmoji",checked:e,onChange:v=>{x(v)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(ht,{settingsItem:"git.gitignored-files",checked:n,onChange:Sd,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Go=[{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)"}],gh=[{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"}],hh=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=it(),r=Hn(O=>O.getProfileById),l=Hn(O=>O.createProfile),m=Hn(O=>O.updateProfile),u=Hn(O=>O.deleteProfile),x=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),d=a==="new"||n!=null,v=a==="global",[c,N]=o.useState(""),[f,C]=o.useState(""),[y,S]=o.useState(""),[g,T]=o.useState("ssh"),[M,P]=o.useState(""),[k,h]=o.useState(!1),[j,F]=o.useState(""),[A,I]=o.useState(""),[E,B]=o.useState("keyword"),[_,w]=o.useState("branch"),[V,W]=o.useState(!1),[L,Q]=o.useState(!1),[ne,z]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const O=n.host.split("/"),Y=O.length>=3?O[O.length-1]:n.host;N(Y),C(n.username),S(""),T("token"),P(""),h(!1),F(""),I(n.host),B("string"),w("code")}else if(d)N(""),C(""),S(""),T("ssh"),P(""),h(!1),F(""),I(""),B("keyword"),w("branch");else if(x)N(x.name),C(x.userName),S(x.userEmail),T(x.authType||"ssh"),P(x.sshKey||""),h(x.signCommits===!0),F(x.signingKey||""),I(x.host||""),B(x.color||"keyword"),w(x.icon||"branch");else if(v){const O=r("global");O&&(N(O.name),C(O.userName),S(O.userEmail),T(O.authType||"ssh"),P(O.sshKey||""),h(!1),F(""),I(O.host||""),B(O.color||"keyword"),w(O.icon||"branch"))}}},[t,a,x,d,n,v,r]);const re=async()=>{if(!f.trim()||!y.trim()){D.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(g==="token"&&!A.trim()){D.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(k&&!j.trim()){D.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}W(!0);try{const O={name:c.trim()||f.trim(),userName:f.trim(),userEmail:y.trim(),authType:g,sshKey:g==="ssh"&&M.trim()||null,signCommits:k,signingKey:j.trim()||null,host:g==="token"&&A.trim()||null,color:E,icon:_};let Y;if(d)Y=await l(O);else if(a)Y=await m(a,O);else return;Y?(D.success(i(d?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):D.error(i(d?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(O){console.error("Error saving profile:",O),D.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{W(!1)}},$=async()=>{if(!(!a||d)){z(!0);try{await u(a)?(D.success(i("settings.gitIdentities.editor.toast.profileDeleted")),Q(!1),e(!1)):D.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(O){console.error("Error deleting profile:",O),D.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{z(!1)}}},U=o.useMemo(()=>Go.find(Y=>Y.key===E)?.cssVar||"var(--syntax-keyword)",[E]),K=n?i("settings.gitIdentities.editor.title.importCredential"):d?i("settings.gitIdentities.editor.title.newIdentity"):v?i("settings.gitIdentities.editor.title.globalIdentity"):x?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Kt,{open:t,onOpenChange:e,children:s.jsxs(zt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(_t,{children:[s.jsx($t,{children:K}),s.jsx(Vt,{children:i(v?"settings.gitIdentities.editor.description.globalReadOnly":d?"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:`${Et} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(Je,{value:c,onChange:O=>N(O.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:Go.map(O=>s.jsx("button",{type:"button",onClick:()=>B(O.key),className:ve("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",E===O.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:O.cssVar},title:O.label},O.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:gh.map(O=>{const Y=O.Icon;return s.jsx("button",{type:"button",onClick:()=>w(O.key),className:ve("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",_===O.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:O.label,children:s.jsx(R,{name:Y,className:"w-3.5 h-3.5",style:{color:_===O.key?U:"var(--surface-muted-foreground)"}})},O.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:Et,children:i("settings.gitIdentities.editor.field.userName")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(Je,{value:f,onChange:O=>C(O.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:Et,children:i("settings.gitIdentities.editor.field.emailAddress")}),!v&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(Je,{type:"email",value:y,onChange:O=>S(O.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":g==="ssh",onClick:()=>T("ssh"),children:[s.jsx(R,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(H,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="token",onClick:()=>T("token"),children:[s.jsx(R,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),g==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(Je,{value:M,onChange:O=>P(O.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(ht,{checked:k,onChange:h,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:Et,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(Je,{value:j,onChange:O=>F(O.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!k,className:"h-8 font-mono text-xs"})]})]}),g==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(Je,{value:A,onChange:O=>I(O.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(ts,{className:"gap-2",children:[!v&&!d&&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(R,{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:re,disabled:V,children:i(V?"settings.common.actions.saving":d?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Kt,{open:L,onOpenChange:O=>{ne||Q(O)},children:s.jsxs(zt,{className:"max-w-md",children:[s.jsxs(_t,{children:[s.jsx($t,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Vt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:x?.name||c})})]}),s.jsxs(ts,{children:[s.jsx(H,{variant:"ghost",onClick:()=>Q(!1),disabled:ne,children:i("settings.common.actions.cancel")}),s.jsx(H,{size:"sm",variant:"destructive",onClick:()=>{$()},disabled:ne,children:i("settings.common.actions.delete")})]})]})})]})},fh={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},xh={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},bh=()=>{const t=gt.c(112),{t:e}=it(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:m,loadDiscoveredCredentials:u,loadDefaultGitIdentityId:x,setDefaultGitIdentityId:d,getUnimportedCredentials:v}=Hn(Ks(yh)),[c,N]=o.useState(!1),[f,C]=o.useState(null),[y,S]=o.useState(null),[g,T]=o.useState(null),[M,P]=o.useState(!1);let k,h;t[0]!==x||t[1]!==u||t[2]!==m||t[3]!==l?(k=()=>{l(),m(),u(),x()},h=[l,m,u,x],t[0]=x,t[1]=u,t[2]=m,t[3]=l,t[4]=k,t[5]=h):(k=t[4],h=t[5]),o.useEffect(k,h);let j,F,A,I,E,B,_,w,V,W,L,Q,ne,z;if(t[6]!==i||t[7]!==g||t[8]!==r||t[9]!==v||t[10]!==n||t[11]!==a||t[12]!==d||t[13]!==e){const $e=v();let Ve;t[28]===Symbol.for("react.memo_cache_sentinel")?(Ve=(Pe,je)=>{C(Pe),S(je??null),N(!0)},t[28]=Ve):Ve=t[28];const qe=Ve;let se;t[29]!==i||t[30]!==d||t[31]!==e?(se=async Pe=>{const je=i===Pe?null:Pe;if(!await d(je)){D.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}D.success(e(je?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=d,t[31]=e,t[32]=se):se=t[32];const ie=se;let we;t[33]!==g||t[34]!==r||t[35]!==e?(we=async()=>{if(!g)return;P(!0),await r(g.id)?(D.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:g.name})),T(null)):D.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),P(!1)},t[33]=g,t[34]=r,t[35]=e,t[36]=we):we=t[36],A=we,F=es,t[37]!==e?(E=e("settings.page.git.title"),t[37]=e,t[38]=E):E=t[38],B=!0,j=_e,t[39]!==e?(Q=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=Q):Q=t[40],ne=!1;let ye,Te;t[41]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>qe("new"),Te=s.jsx(R,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=ye,t[42]=Te):(ye=t[41],Te=t[42]);let Ue;t[43]!==e?(Ue=e("settings.common.badge.new"),t[43]=e,t[44]=Ue):Ue=t[44],t[45]!==Ue?(z=s.jsxs(H,{size:"sm",variant:"outline",onClick:ye,children:[Te," ",Ue]}),t[45]=Ue,t[46]=z):z=t[46],I="git.identities",_="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",w=n&&s.jsx(qo,{profile:n,isDefault:i==="global",onEdit:()=>qe("global"),onToggleDefault:()=>ie("global"),isReadOnly:!0,hasBorder:a.length>0||$e.length>0}),V=a.map((Pe,je)=>s.jsx(qo,{profile:Pe,isDefault:i===Pe.id,onEdit:()=>qe(Pe.id),onToggleDefault:()=>ie(Pe.id),onDelete:()=>T(Pe),hasBorder:je<a.length-1||$e.length>0},Pe.id)),W=!n&&a.length===0&&$e.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(R,{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")})]}),L=$e.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")})}),$e.map((Pe,je)=>s.jsx(vh,{credential:Pe,onImport:()=>qe("new",{host:Pe.host,username:Pe.username}),hasBorder:je<$e.length-1},`${Pe.host}-${Pe.username}`))]}),t[6]=i,t[7]=g,t[8]=r,t[9]=v,t[10]=n,t[11]=a,t[12]=d,t[13]=e,t[14]=j,t[15]=F,t[16]=A,t[17]=I,t[18]=E,t[19]=B,t[20]=_,t[21]=w,t[22]=V,t[23]=W,t[24]=L,t[25]=Q,t[26]=ne,t[27]=z}else j=t[14],F=t[15],A=t[16],I=t[17],E=t[18],B=t[19],_=t[20],w=t[21],V=t[22],W=t[23],L=t[24],Q=t[25],ne=t[26],z=t[27];let re;t[47]!==_||t[48]!==w||t[49]!==V||t[50]!==W||t[51]!==L?(re=s.jsxs("div",{className:_,children:[w,V,W,L]}),t[47]=_,t[48]=w,t[49]=V,t[50]=W,t[51]=L,t[52]=re):re=t[52];let $;t[53]!==j||t[54]!==I||t[55]!==re||t[56]!==Q||t[57]!==ne||t[58]!==z?($=s.jsx(j,{title:Q,divider:ne,headerAction:z,settingsItem:I,children:re}),t[53]=j,t[54]=I,t[55]=re,t[56]=Q,t[57]=ne,t[58]=z,t[59]=$):$=t[59];let U;t[60]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(Yl,{}),t[60]=U):U=t[60];let K;t[61]!==F||t[62]!==E||t[63]!==B||t[64]!==$?(K=s.jsxs(F,{title:E,showSaveStatus:B,children:[$,U]}),t[61]=F,t[62]=E,t[63]=B,t[64]=$,t[65]=K):K=t[65];let O;t[66]!==y||t[67]!==c||t[68]!==f?(O=s.jsx(hh,{open:c,onOpenChange:N,profileId:f,importData:y}),t[66]=y,t[67]=c,t[68]=f,t[69]=O):O=t[69];const Y=g!==null;let X;t[70]!==M?(X=$e=>{M||$e||T(null)},t[70]=M,t[71]=X):X=t[71];let ee;t[72]!==e?(ee=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=ee):ee=t[73];let ge;t[74]!==ee?(ge=s.jsx($t,{children:ee}),t[74]=ee,t[75]=ge):ge=t[75];const de=g?.name??"";let xe;t[76]!==e||t[77]!==de?(xe=e("settings.gitIdentities.page.deleteDialog.description",{name:de}),t[76]=e,t[77]=de,t[78]=xe):xe=t[78];let ae;t[79]!==xe?(ae=s.jsx(Vt,{children:xe}),t[79]=xe,t[80]=ae):ae=t[80];let te;t[81]!==ge||t[82]!==ae?(te=s.jsxs(_t,{children:[ge,ae]}),t[81]=ge,t[82]=ae,t[83]=te):te=t[83];let pe;t[84]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>T(null),t[84]=pe):pe=t[84];let Ie;t[85]!==e?(Ie=e("settings.common.actions.cancel"),t[85]=e,t[86]=Ie):Ie=t[86];let Ne;t[87]!==M||t[88]!==Ie?(Ne=s.jsx(H,{variant:"ghost",onClick:pe,disabled:M,children:Ie}),t[87]=M,t[88]=Ie,t[89]=Ne):Ne=t[89];let Se;t[90]!==A?(Se=()=>{A()},t[90]=A,t[91]=Se):Se=t[91];let be;t[92]!==e?(be=e("settings.common.actions.delete"),t[92]=e,t[93]=be):be=t[93];let Oe;t[94]!==M||t[95]!==Se||t[96]!==be?(Oe=s.jsx(H,{size:"sm",variant:"destructive",onClick:Se,disabled:M,children:be}),t[94]=M,t[95]=Se,t[96]=be,t[97]=Oe):Oe=t[97];let Le;t[98]!==Ne||t[99]!==Oe?(Le=s.jsxs(ts,{children:[Ne,Oe]}),t[98]=Ne,t[99]=Oe,t[100]=Le):Le=t[100];let oe;t[101]!==te||t[102]!==Le?(oe=s.jsxs(zt,{className:"max-w-md",children:[te,Le]}),t[101]=te,t[102]=Le,t[103]=oe):oe=t[103];let fe;t[104]!==Y||t[105]!==X||t[106]!==oe?(fe=s.jsx(Kt,{open:Y,onOpenChange:X,children:oe}),t[104]=Y,t[105]=X,t[106]=oe,t[107]=fe):fe=t[107];let Me;return t[108]!==K||t[109]!==O||t[110]!==fe?(Me=s.jsxs(s.Fragment,{children:[K,O,fe]}),t[108]=K,t[109]=O,t[110]=fe,t[111]=Me):Me=t[111],Me},qo=t=>{const e=gt.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:m,hasBorder:u}=t,{t:x}=it(),[d,v]=o.useState(!1),c=fh[a.icon||"branch"]||"git-branch",N=xh[a.color||""],f=a.authType||"ssh";let C;e[0]!==i?(C=$=>{$.currentTarget===$.target&&($.key!=="Enter"&&$.key!==" "||($.preventDefault(),i()))},e[0]=i,e[1]=C):C=e[1];const y=C;let S;e[2]!==n||e[3]!==m||e[4]!==l||e[5]!==r||e[6]!==x?(S=$=>s.jsxs(s.Fragment,{children:[s.jsx($,{onClick:U=>{U.stopPropagation(),r()},children:x(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!m&&l&&s.jsxs($,{onClick:U=>{U.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(R,{name:"delete-bin",className:"h-4 w-4 mr-px"}),x("settings.common.actions.delete")]})]}),e[2]=n,e[3]=m,e[4]=l,e[5]=r,e[6]=x,e[7]=S):S=e[7];const g=S,T=u&&"border-b border-[var(--surface-subtle)]";let M;e[8]!==T?(M=ve("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",T),e[8]=T,e[9]=M):M=e[9];let P;e[10]===Symbol.for("react.memo_cache_sentinel")?(P=$=>{$.preventDefault(),v(!0)},e[10]=P):P=e[10];let k;e[11]!==y||e[12]!==i||e[13]!==M?(k=s.jsx("div",{className:M,onClick:i,role:"button",tabIndex:0,onKeyDown:y,onContextMenu:P}),e[11]=y,e[12]=i,e[13]=M,e[14]=k):k=e[14];let h;e[15]!==N?(h={color:N},e[15]=N,e[16]=h):h=e[16];let j;e[17]!==c||e[18]!==h?(j=s.jsx(R,{name:c,className:"w-4 h-4 shrink-0",style:h}),e[17]=c,e[18]=h,e[19]=j):j=e[19];let F;e[20]!==a.name?(F=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=F):F=e[21];let A;e[22]!==f?(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:f}),e[22]=f,e[23]=A):A=e[23];let I;e[24]!==n||e[25]!==x?(I=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:x("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=x,e[26]=I):I=e[26];let E;e[27]!==m||e[28]!==x?(E=m&&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:x("settings.agents.sidebar.badge.system")}),e[27]=m,e[28]=x,e[29]=E):E=e[29];let B;e[30]!==A||e[31]!==I||e[32]!==E||e[33]!==F?(B=s.jsxs("div",{className:"flex items-center gap-1.5",children:[F,A,I,E]}),e[30]=A,e[31]=I,e[32]=E,e[33]=F,e[34]=B):B=e[34];const _=f==="token"&&a.host?a.host:a.userEmail;let w;e[35]!==_?(w=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:_}),e[35]=_,e[36]=w):w=e[36];let V;e[37]!==B||e[38]!==w?(V=s.jsxs("div",{className:"min-w-0",children:[B,w]}),e[37]=B,e[38]=w,e[39]=V):V=e[39];let W;e[40]!==V||e[41]!==j?(W=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[j,V]}),e[40]=V,e[41]=j,e[42]=W):W=e[42];let L;e[43]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(rn,{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:jh,children:s.jsx(R,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=L):L=e[43];let Q;e[44]!==g?(Q=s.jsxs(ln,{children:[L,s.jsx(on,{align:"end",className:"w-fit min-w-28",children:g(cn)})]}),e[44]=g,e[45]=Q):Q=e[45];let ne;e[46]!==W||e[47]!==Q||e[48]!==k?(ne=s.jsxs(Zn,{render:k,children:[W,Q]}),e[46]=W,e[47]=Q,e[48]=k,e[49]=ne):ne=e[49];let z;e[50]!==g?(z=s.jsx(Yn,{className:"w-fit min-w-28",children:g(Xn)}),e[50]=g,e[51]=z):z=e[51];let re;return e[52]!==d||e[53]!==ne||e[54]!==z?(re=s.jsxs(ea,{open:d,onOpenChange:v,children:[ne,z]}),e[52]=d,e[53]=ne,e[54]=z,e[55]=re):re=e[55],re},vh=t=>{const e=gt.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 m=l,u=m.length>=3?m[m.length-1]:a.host,x=a.host.includes("/"),d=i&&"border-b border-[var(--surface-subtle)]";let v;e[2]!==d?(v=ve("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",d),e[2]=d,e[3]=v):v=e[3];let c;e[4]!==u?(c=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:u}),e[4]=u,e[5]=c):c=e[5];const N=x?a.host:a.username;let f;e[6]!==N?(f=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:N}),e[6]=N,e[7]=f):f=e[7];let C;e[8]!==c||e[9]!==f?(C=s.jsxs("div",{className:"min-w-0",children:[c,f]}),e[8]=c,e[9]=f,e[10]=C):C=e[10];let y;e[11]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(R,{name:"download",className:"h-3 w-3"}),e[11]=y):y=e[11];let S;e[12]!==r?(S=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=S):S=e[13];let g;e[14]!==n||e[15]!==S?(g=s.jsxs(H,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[y,S]}),e[14]=n,e[15]=S,e[16]=g):g=e[16];let T;return e[17]!==g||e[18]!==v||e[19]!==C?(T=s.jsxs("div",{className:v,children:[C,g]}),e[17]=g,e[18]=v,e[19]=C,e[20]=T):T=e[20],T};function yh(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 jh(t){return t.stopPropagation()}const wh=({embedded:t=!1})=>{const{t:e}=it(),{isMobile:a}=ja(),n=an()?.github,i=Tn(w=>w.status),r=Tn(w=>w.isLoading),l=Tn(w=>w.hasChecked),m=Tn(w=>w.refreshStatus),u=Tn(w=>w.setStatus),x=o.useCallback(async w=>{await Dn(w)},[]),[d,v]=o.useState(!1),[c,N]=o.useState(null),[f,C]=o.useState(null),y=o.useRef(null),S=o.useCallback(()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null),C(null)},[]);o.useEffect(()=>((async()=>{try{l||await m(n)}catch(w){console.warn("Failed to load GitHub auth status:",w)}})(),()=>{S()}),[l,m,n,S]);const g=o.useCallback(async()=>{v(!0);try{const w=n?await n.authStart():await(async()=>{const W=await ut("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),L=await W.json().catch(()=>null);if(!W.ok||!L||!("deviceCode"in L))throw new Error(L?.error||W.statusText);return L})();N(w),C(Math.max(1,w.interval)*1e3);const V=w.verificationUriComplete||w.verificationUri;x(V)}catch(w){console.error("Failed to start GitHub connect:",w),D.error(e("settings.github.page.toast.startConnectFailed"))}finally{v(!1)}},[x,n,e]),T=o.useCallback(async w=>{if(n)return n.authComplete(w);const V=await ut("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:w})}),W=await V.json().catch(()=>null);if(!V.ok||!W)throw new Error(W?.error||V.statusText);return W},[n]);o.useEffect(()=>{if(!(!c?.deviceCode||!f)&&y.current==null)return y.current=window.setInterval(()=>{(async()=>{try{const w=await T(c.deviceCode);if(w.connected){D.success(e("settings.github.page.toast.connected")),N(null),S(),await m(n,{force:!0});return}w.status==="slow_down"&&C(V=>V?V+5e3:5e3),(w.status==="expired_token"||w.status==="access_denied")&&(D.error(w.error||e("settings.github.page.toast.authorizationFailed")),N(null),S())}catch(w){console.warn("GitHub polling failed:",w)}})()},f),()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null)}},[c,f,T,m,n,S,e]);const M=o.useCallback(async w=>{v(!0);try{if(n)await n.authSetGhCliDisabled(w);else{const V=await ut("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:w})}),W=await V.json().catch(()=>null);if(!V.ok)throw new Error(W?.error||V.statusText)}D.success(e(w?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await m(n,{force:!0})}catch(V){console.error("Failed to update gh CLI setting:",V),D.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{v(!1)}},[m,n,e]),P=o.useCallback(async()=>{v(!0);try{if(S(),N(null),n)await n.authDisconnect();else{const w=await ut("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!w.ok)throw new Error(w.statusText)}D.success(e("settings.github.page.toast.disconnected")),await m(n,{force:!0})}catch(w){console.error("Failed to disconnect GitHub:",w),D.error(e("settings.github.page.toast.disconnectFailed"))}finally{v(!1)}},[m,n,S,e]),k=o.useCallback(async w=>{if(w){v(!0);try{const V=n?await n.authActivate(w):await(async()=>{const W=await ut("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:w})}),L=await W.json().catch(()=>null);if(!W.ok||!L)throw new Error(L?.error||W.statusText);return L})();u(V),D.success(e("settings.github.page.toast.accountSwitched"))}catch(V){console.error("Failed to switch GitHub account:",V),D.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{v(!1)}}},[n,u,e]);if(r&&!l)return null;const h=!!i?.connected,j=i?.user,A=(i?.accounts??[]).filter(w=>!w.current),I=i?.ghCli??null,E=I?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),B=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[h?s.jsxs("div",{className:ve("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ve("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:j.login?e("settings.github.page.avatarAlt.withLogin",{login:j.login}):e("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:j?.name?.trim()||j?.login||"GitHub"}),s.jsxs("div",{className:ve("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(R,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:j?.login||e("settings.github.page.label.unknownUser")}),j?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&s.jsx("span",{children:j.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:E})]}),i?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:i.scope})}),I?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),I?.active?s.jsx(H,{size:"sm",variant:"outline",onClick:()=>M(!0),disabled:d,className:ve(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(H,{size:"sm",variant:"outline",onClick:P,disabled:d,className:ve("text-[var(--status-error)] hover:text-[var(--status-error)]",a?"w-full":void 0),children:e("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:e("settings.github.page.status.notConnected")})}),s.jsx(H,{size:"sm",variant:"default",onClick:g,disabled:d,children:e("settings.github.page.actions.connect")})]}),A.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:e("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:A.map(w=>{const V=w.user,W=w.source==="gh-cli"?e("settings.github.page.accountSource.cli"):e("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:[V?.avatarUrl?s.jsx("img",{src:V.avatarUrl,alt:V.login?e("settings.github.page.avatarAlt.withLogin",{login:V.login}):e("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(R,{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:V?.name?.trim()||V?.login||"GitHub"}),V?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:V.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:W})]})]})]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:()=>k(w.id),disabled:d,children:e("settings.github.page.actions.switchTo")})]},w.id)})})]})]}),h&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(H,{size:"sm",variant:"outline",onClick:g,disabled:d,className:ve(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),c&&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(Ys,{children:e("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("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:c.userCode}),s.jsx(H,{size:"sm",asChild:!0,children:s.jsx("a",{href:c.verificationUriComplete||c.verificationUri,target:"_blank",rel:"noopener noreferrer",children:e("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:e("settings.github.page.flow.waiting")}),s.jsx(H,{size:"sm",variant:"ghost",disabled:d,onClick:()=>{S(),N(null)},children:e("settings.common.actions.cancel")})]})]})]}),_=I?.available&&!I?.active&&(!I.user||I.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:ve("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ve("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[I.user?.avatarUrl?s.jsx("img",{src:I.user.avatarUrl,alt:I.user.login?e("settings.github.page.avatarAlt.withLogin",{login:I.user.login}):e("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(R,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!I.disabled&&I.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:I.user.name?.trim()||I.user.login||"GitHub"}),!I.disabled&&I.user?.login&&s.jsxs("div",{className:ve("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(R,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:I.user.login}),I.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),I.user.email&&s.jsx("span",{children:I.user.email})]}),s.jsx("div",{className:ve("typography-meta text-muted-foreground",I.disabled?"opacity-60":void 0),children:I.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(H,{size:"sm",variant:"outline",onClick:()=>M(!I.disabled),disabled:d,className:ve(a?"w-full":void 0),children:I.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[B,_?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ys,{children:e("settings.github.page.ghCli.title")}),_]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(_e,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:B}),_?s.jsx(_e,{title:e("settings.github.page.ghCli.title"),children:_}):null]})},kh=()=>{const t=gt.c(37),{t:e}=it(),a=Tn(Nh),n=Tn(Sh),i=Tn(Ch),[r,l]=o.useState(!1),m=a?.connected===!0;let u;t[0]!==m||t[1]!==i||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(u=n&&!i?e("common.loading"):m?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=m,t[1]=i,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=u):u=t[5];const x=u,d=m?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let v;t[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(R,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=v):v=t[6];let c;t[7]!==e?(c=e("settings.integrations.github.title"),t[7]=e,t[8]=c):c=t[8];let N;t[9]!==c?(N=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:c}),t[9]=c,t[10]=N):N=t[10];let f;t[11]!==e?(f=e("settings.integrations.github.description"),t[11]=e,t[12]=f):f=t[12];let C;t[13]!==f?(C=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:f}),t[13]=f,t[14]=C):C=t[14];let y;t[15]!==N||t[16]!==C?(y=s.jsxs("div",{className:"min-w-0 flex-1",children:[N,C]}),t[15]=N,t[16]=C,t[17]=y):y=t[17];let S;t[18]!==d?(S=ve("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",d),t[18]=d,t[19]=S):S=t[19];let g;t[20]!==x||t[21]!==S?(g=s.jsx("span",{"aria-live":"polite",className:S,children:x}),t[20]=x,t[21]=S,t[22]=g):g=t[22];const T=r&&"rotate-180";let M;t[23]!==T?(M=ve("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",T),t[23]=T,t[24]=M):M=t[24];let P;t[25]!==M?(P=s.jsx(R,{name:"arrow-down-s",className:M}),t[25]=M,t[26]=P):P=t[26];let k;t[27]!==P||t[28]!==y||t[29]!==g?(k=s.jsxs(Rn,{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:[v,y,g,P]}),t[27]=P,t[28]=y,t[29]=g,t[30]=k):k=t[30];let h;t[31]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Ln,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(wh,{embedded:!0})}),t[31]=h):h=t[31];let j;t[32]!==k?(j=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[k,h]}),t[32]=k,t[33]=j):j=t[33];let F;return t[34]!==r||t[35]!==j?(F=s.jsx(Mn,{open:r,onOpenChange:l,children:j}),t[34]=r,t[35]=j,t[36]=F):F=t[36],F};function Nh(t){return t.status}function Sh(t){return t.isLoading}function Ch(t){return t.hasChecked}const gi="__none__",hi="__inherit__";function Ih({linear:t,connected:e,organizationId:a}){const{t:n}=it(),i=Bs(y=>y.projects),[r,l]=o.useState(null),[m,u]=o.useState(!1),[x,d]=o.useState(!1),v=o.useCallback(async()=>{if(!e){l(null),u(!1);return}try{const y=await t.mappingGet();if(y.connected===!1){l(null),u(!1);return}l(y),u(!1)}catch(y){console.error("Failed to load Linear mapping:",y),u(!0)}},[e,t]);o.useEffect(()=>{v()},[v,a]);const c=o.useCallback(async y=>{const S={};for(const g of y.teams??[])g.projectPath&&(S[g.id]=g.projectPath);d(!0),xn("saving");try{const g=await t.mappingSet({defaultProjectPath:y.defaultProjectPath??null,teamProjectPaths:S});if(g.connected===!1){l(null),xn("error");return}l(g),u(!1),xn("saved")}catch(g){console.error("Failed to save Linear mapping:",g),xn("error")}finally{d(!1)}},[t]);if(!e)return null;if(m&&!r)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!r)return null;const N=y=>i.find(g=>g.path===y)?.label?.trim()||y,f=y=>!y||y===gi?n("settings.integrations.linear.mapping.defaultProject.placeholder"):N(y),C=y=>!y||y===hi?n("settings.integrations.linear.mapping.teams.useDefault"):N(y);return s.jsxs("div",{className:Js,children:[i.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Lt,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(It,{value:r.defaultProjectPath||gi,disabled:x||i.length===0,onValueChange:y=>{c({...r,defaultProjectPath:y===gi?null:y})},children:[s.jsx(Pt,{size:Ft,className:nn,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(Rt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:f})}),s.jsxs(At,{children:[s.jsx(ot,{value:gi,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),r.defaultProjectPath&&!i.some(y=>y.path===r.defaultProjectPath)?s.jsx(ot,{value:r.defaultProjectPath,children:r.defaultProjectPath}):null,i.map(y=>s.jsx(ot,{value:y.path,children:N(y.path)},y.id))]})]})}),s.jsx(Ps,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(r.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:Js,children:(r.teams??[]).map(y=>s.jsx(Lt,{label:`${y.key} · ${y.name}`,children:s.jsxs(It,{value:y.projectPath||hi,disabled:x||i.length===0,onValueChange:S=>{c({...r,teams:(r.teams??[]).map(g=>g.id===y.id?{...g,projectPath:S===hi?null:S}:g)})},children:[s.jsx(Pt,{size:Ft,className:nn,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:y.key}),children:s.jsx(Rt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:C})}),s.jsxs(At,{children:[s.jsx(ot,{value:hi,children:n("settings.integrations.linear.mapping.teams.useDefault")}),y.projectPath&&!i.some(S=>S.path===y.projectPath)?s.jsx(ot,{value:y.projectPath,children:y.projectPath}):null,i.map(S=>s.jsx(ot,{value:S.path,children:N(S.path)},S.id))]})]})},y.id))})})]})}function Ph({linear:t,connected:e}){const{t:a}=it(),[n,i]=o.useState(null),[r,l]=o.useState(!1),[m,u]=o.useState(!1);o.useEffect(()=>{if(!e){i(null),l(!1);return}let d=!1;return t.preferencesGet().then(v=>{d||(i(v.sessionComments),l(!1))}).catch(()=>{d||l(!0)}),()=>{d=!0}},[e,t]);const x=o.useCallback(async d=>{const v=n;i(d),u(!0);try{const c=await t.preferencesSet({sessionComments:d});i(c.sessionComments),xn("saved")}catch{i(v),xn("error")}finally{u(!1)}},[n,t]);return e?r?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:Js,children:s.jsx(Lt,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(bi,{checked:n===!0,disabled:n===null||m,onCheckedChange:d=>{x(d)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const Ah=3*6e4,Th=1500;function Wo(t){const e=t?.workspaces??[],a=e.find(n=>n.current);return{connected:!!t?.connected,ids:e.map(n=>n.id).slice().sort().join(","),currentId:a?.id||t?.organization?.id||"",currentAuthorizedAt:a?.authorizedAt??0}}function Eh(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const Dh=()=>{const{t}=it(),e=an()?.linear,a=pa(I=>I.status),n=pa(I=>I.isLoading),i=pa(I=>I.hasChecked),r=pa(I=>I.refreshStatus),l=pa(I=>I.setStatus),[m,u]=o.useState(!1),[x,d]=o.useState(!1),[v,c]=o.useState(!1),N=o.useRef(null),f=o.useCallback(()=>{N.current!=null&&(window.clearInterval(N.current),N.current=null),d(!1)},[]);o.useEffect(()=>{if(e)return i||r(e),()=>{f()}},[i,r,e,f]);const C=o.useCallback(async()=>{if(!e)return;f(),u(!0);const I=Wo(pa.getState().status);try{const E=await e.authStart(as()?"desktop":"web");d(!0),c(!0),Dn(E.authorizationUrl);const B=Date.now()+Ah;N.current=window.setInterval(()=>{(async()=>{if(Date.now()>B){f(),D.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const _=await r(e,{force:!0});Eh(I,Wo(_))&&(f(),D.success(t("settings.integrations.linear.toast.connected")),Cd())})()},Th)}catch(E){console.error("Failed to start Linear connect:",E),D.error(t("settings.integrations.linear.toast.startConnectFailed")),f()}finally{u(!1)}},[r,e,f,t]),y=o.useCallback(async I=>{if(!(!e||!I)){u(!0);try{const E=await e.authActivate(I);l(E),D.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(E){console.error("Failed to switch Linear workspace:",E),D.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{u(!1)}}},[e,l,t]),S=o.useCallback(async()=>{if(e){u(!0);try{f(),await e.authDisconnect(),D.success(t("settings.integrations.linear.toast.disconnected")),await r(e,{force:!0})}catch(I){console.error("Failed to disconnect Linear:",I),D.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{u(!1)}}},[r,e,f,t]);if(!e)return null;const g=!!a?.connected,T=a?.user,M=a?.organization,k=(a?.workspaces??[]).filter(I=>!I.current),h=T?.displayName?.trim()||T?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),j=x?t("settings.integrations.linear.status.waiting"):n&&!i?t("common.loading"):g?M?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),F=x?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":g?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",A=x||v;return s.jsx(Mn,{open:A,onOpenChange:I=>{if(x){c(!0);return}c(I)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(Rn,{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:s.jsx(R,{name:"linear",className:"size-5 text-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:t("settings.integrations.linear.title")}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:t("settings.integrations.linear.description")})]}),s.jsx("span",{"aria-live":"polite",className:ve("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",F),children:j}),s.jsx(R,{name:"arrow-down-s",className:ve("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",A&&"rotate-180")})]}),s.jsx(Ln,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[g?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[T?.avatarUrl?s.jsx("img",{src:T.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:h}),className:"size-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 size-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(R,{name:"linear",className:"size-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:h}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[M?.name,T?.email].filter(Boolean).join(" · ")})]})]}):x?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,g?s.jsxs(s.Fragment,{children:[s.jsx(Ih,{linear:e,connected:g,organizationId:M?.id??null}),s.jsx(Ph,{linear:e,connected:g}),k.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.integrations.linear.label.otherWorkspaces")}),s.jsx("div",{className:"space-y-1",children:k.map(I=>{const E=I.user,B=I.name?.trim()||t("settings.integrations.linear.status.connected");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:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:B}),E?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:E.email}):null]}),s.jsx(H,{type:"button",size:"sm",variant:"ghost",onClick:()=>{y(I.id)},disabled:m,children:t("settings.integrations.linear.actions.switchTo")})]},I.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(H,{type:"button",size:"sm",variant:"outline",onClick:()=>{C()},disabled:m||x,"data-settings-item":"integrations.linear.add-workspace",children:t("settings.integrations.linear.actions.addWorkspace")}),s.jsx(H,{type:"button",size:"sm",variant:"destructive",onClick:()=>{S()},disabled:m,children:t("settings.integrations.linear.actions.disconnect")})]})]}):x?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(H,{type:"button",size:"sm",variant:"ghost",disabled:m,onClick:f,children:t("settings.common.actions.cancel")})]}):s.jsxs(H,{type:"button",size:"sm",variant:"default",onClick:()=>{C()},disabled:m||n&&!i,children:[m?s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},Mh=()=>{const t=gt.c(18),{t:e}=it();let a;t[0]===Symbol.for("react.memo_cache_sentinel")?(a=cs(),t[0]=a):a=t[0];const n=!a,i=!!an()?.linear;let r;t[1]!==e?(r=e("settings.page.integrations.title"),t[1]=e,t[2]=r):r=t[2];let l;t[3]!==e?(l=e("settings.page.integrations.description"),t[3]=e,t[4]=l):l=t[4];let m;t[5]!==e?(m=e("settings.integrations.firstParty.title"),t[5]=e,t[6]=m):m=t[6];let u;t[7]!==e?(u=e("settings.integrations.firstParty.info"),t[7]=e,t[8]=u):u=t[8];let x,d;t[9]===Symbol.for("react.memo_cache_sentinel")?(x=n?s.jsx(kh,{}):null,d=i?s.jsx(Dh,{}):null,t[9]=x,t[10]=d):(x=t[9],d=t[10]);let v;t[11]!==m||t[12]!==u?(v=s.jsxs(_e,{title:m,info:u,divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[x,d]}),t[11]=m,t[12]=u,t[13]=v):v=t[13];let c;return t[14]!==r||t[15]!==l||t[16]!==v?(c=s.jsx(es,{title:r,description:l,showSaveStatus:!0,children:v}),t[14]=r,t[15]=l,t[16]=v,t[17]=c):c=t[17],c},Rh=[{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"}],Lh=[{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"}],Oh=[{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"}],Da="OpenChamber - AI Coding Assistant",Jo=[{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"}],Qo=[{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"}],tr=t=>t==="portrait"||t==="landscape"?t:"system",Fh=[{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"}],Kh=[{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"}],zh=[{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"}],Xo=[{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"}],Zo=[{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"}],Uh=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],_h=[{id:"ask",labelKey:"settings.openchamber.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.openchamber.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.openchamber.visual.option.largeTextPaste.inline.label"}],$h=[{id:"global",labelKey:"settings.openchamber.visual.option.inputHistoryScope.global.label"},{id:"session",labelKey:"settings.openchamber.visual.option.inputHistoryScope.session.label"}],Vh=t=>t==="markdown"?"markdown":"plain",Bh=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],Hh=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],Ai=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=it(),l=o.useCallback(p=>r(p),[r]),{isMobile:m}=ja(),{terminal:u}=jl(),{browserTab:x}=Hd(),d=Id(),v=le(p=>p.showReasoningTraces),c=le(p=>p.sessionRecapEnabled),N=le(p=>p.sessionSuggestionEnabled),f=le(p=>p.setSessionRecapEnabled),C=le(p=>p.setSessionSuggestionEnabled),y=le(p=>p.sessionGoalEnabled),S=le(p=>p.setSessionGoalEnabled),g=le(p=>p.sessionGoalDefaultBudgetEnabled),T=le(p=>p.setSessionGoalDefaultBudgetEnabled),M=le(p=>p.sessionGoalDefaultBudget),P=le(p=>p.setSessionGoalDefaultBudget),k=le(p=>p.setShowReasoningTraces),h=le(p=>p.streamingAutoFollowEnabled),j=le(p=>p.setStreamingAutoFollowEnabled),F=le(p=>p.collapsibleThinkingBlocks),A=le(p=>p.setCollapsibleThinkingBlocks),I=le(p=>p.mermaidRenderingMode),E=le(p=>p.setMermaidRenderingMode),B=le(p=>p.userMessageRenderingMode),_=le(p=>p.setUserMessageRenderingMode),w=le(p=>p.collapsibleUserMessages),V=le(p=>p.setCollapsibleUserMessages),W=le(p=>p.stickyUserHeader),L=le(p=>p.promptNavigatorEnabled),Q=le(p=>p.setStickyUserHeader),ne=le(p=>p.setPromptNavigatorEnabled),z=le(p=>p.autoSaveEnabled),re=le(p=>p.setAutoSaveEnabled),$=le(p=>p.wideChatLayoutEnabled),U=le(p=>p.setWideChatLayoutEnabled),K=le(p=>p.codeBlockLineWrap),O=le(p=>p.setCodeBlockLineWrap),Y=le(p=>p.chatRenderMode),X=le(p=>p.setChatRenderMode),ee=le(p=>p.activityRenderMode),ge=le(p=>p.setActivityRenderMode),de=le(p=>p.fontSize),xe=le(p=>p.setFontSize),ae=le(p=>p.terminalFontSize),te=le(p=>p.setTerminalFontSize),pe=le(p=>p.terminalShell),Ie=le(p=>p.setTerminalShell),Ne=le(p=>p.terminalLoginShells),Se=le(p=>p.setTerminalLoginShells),be=le(p=>p.editorFontSize),Oe=le(p=>p.setEditorFontSize),Le=le(p=>p.uiFont),oe=le(p=>p.setUiFont),fe=le(p=>p.monoFont),Me=le(p=>p.setMonoFont),$e=le(p=>p.padding),Ve=le(p=>p.setPadding),qe=le(p=>p.inputBarOffset),se=le(p=>p.setInputBarOffset),ie=le(p=>p.mobileKeyboardMode),we=le(p=>p.setMobileKeyboardMode),ye=le(p=>p.diffLayoutPreference),Te=le(p=>p.setDiffLayoutPreference),Ue=le(p=>p.showTerminalQuickKeysOnDesktop),Pe=le(p=>p.sessionTabsEnabled),je=le(p=>p.setSessionTabsEnabled),Ge=le(p=>p.setShowTerminalQuickKeysOnDesktop),me=le(p=>p.fileEditorKeymap),Ce=le(p=>p.setFileEditorKeymap),Re=Wr(p=>p.followUpBehavior),Ye=Wr(p=>p.setFollowUpBehavior),q=ii(p=>p.scope),ke=ii(p=>p.entryLimit),Ae=ii(p=>p.applyScope),He=ii(p=>p.applyEntryLimit),at=le(p=>p.persistChatDraft),nt=le(p=>p.setPersistChatDraft),dt=le(p=>p.inputSpellcheckEnabled),xt=le(p=>p.setInputSpellcheckEnabled),G=le(p=>p.largeTextPasteBehavior),Be=le(p=>p.setLargeTextPasteBehavior),st=le(p=>p.enterToSend),rt=le(p=>p.setEnterToSend),pt=le(p=>p.enterToSendConfigured),St=le(p=>p.setEnterToSendConfigured),et=le(p=>p.isExpandedInput),Xe=le(p=>p.showToolFileIcons),ft=le(p=>p.setShowToolFileIcons),ze=le(p=>p.showTurnChangedFiles),wt=le(p=>p.setShowTurnChangedFiles),Ee=le(p=>p.showExpandedBashTools),jt=le(p=>p.setShowExpandedBashTools),J=le(p=>p.showExpandedEditTools),he=le(p=>p.setShowExpandedEditTools),Fe=le(p=>p.timeFormatPreference),De=le(p=>p.setTimeFormatPreference),lt=le(p=>p.weekStartPreference),ct=le(p=>p.setWeekStartPreference),Qe=le(p=>p.showSplitAssistantMessageActions),kt=le(p=>p.setShowSplitAssistantMessageActions),bs=le(p=>p.allowPromptingSubagentSessions),Xt=le(p=>p.setAllowPromptingSubagentSessions),Ls=le(p=>p.draftStartersVisible),Gt=le(p=>p.setDraftStartersVisible),is=Ze(p=>p.settingsMessageStreamTransport),Ht=Ze(p=>p.setSettingsMessageStreamTransport),vs=is,us=Ze(p=>p.settingsDefaultFileViewerPreview),gs=Ze(p=>p.setSettingsDefaultFileViewerPreview),ds=le(p=>p.isSettingsDialogOpen),{themeMode:Ts,setThemeMode:ce,availableThemes:mt,customThemesLoading:yt,reloadCustomThemes:Qt,lightThemeId:Yt,darkThemeId:Bt,setLightThemePreference:rs,setDarkThemePreference:ys}=Nr(),[ss,Nt]=o.useState(!1),Tt=o.useMemo(()=>as()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),Ut=le(p=>p.dockBadgeEnabled),Ot=le(p=>p.setDockBadgeEnabled),ns=Pd(),Es=le(p=>p.desktopWindowControlsPosition),qa=le(p=>p.setDesktopWindowControlsPosition),Ti=le(p=>p.desktopWindowControlsStyle),Wa=le(p=>p.setDesktopWindowControlsStyle),[Ei,zs]=o.useState(0),wa=le(p=>p.reportUsage),Ja=le(p=>p.setReportUsage),Qa=o.useCallback(p=>{Ja(p),vt({reportUsage:p})},[Ja]),Di=o.useCallback(p=>{qa(p),vt({desktopWindowControlsPosition:p})},[qa]),Mi=o.useCallback(p=>{Wa(p),vt({desktopWindowControlsStyle:p})},[Wa]),Ya=(ds||m||cs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Ya)return;let p=null,bt=Date.now();const Ns=()=>{const gn=Date.now();gn-bt>=420&&(zs(_n=>(_n+1)%24),bt=gn),p=requestAnimationFrame(Ns)};(typeof document>"u"||document.visibilityState==="visible")&&(p=requestAnimationFrame(Ns));const ps=()=>{document.visibilityState==="visible"&&p===null?p=requestAnimationFrame(Ns):document.visibilityState!=="visible"&&p!==null&&(cancelAnimationFrame(p),p=null)};return document.addEventListener("visibilitychange",ps),()=>{document.removeEventListener("visibilitychange",ps),p!==null&&cancelAnimationFrame(p)}},[Ya]);const Ri=o.useCallback(p=>{_(p),vt({userMessageRenderingMode:p})},[_]),Li=o.useCallback(p=>{Q(p),vt({stickyUserHeader:p})},[Q]),js=o.useCallback(p=>{ne(p),vt({promptNavigatorEnabled:p})},[ne]),Gs=o.useCallback(p=>{Gt(p),vt({draftStartersVisible:p})},[Gt]),sa=o.useCallback(p=>{V(p),vt({collapsibleUserMessages:p})},[V]),pn=o.useCallback(p=>{U(p),vt({wideChatLayoutEnabled:p})},[U]),bn=o.useCallback(p=>{kt(p),vt({showSplitAssistantMessageActions:p})},[kt]),Rr=o.useCallback(p=>{xt(p),vt({inputSpellcheckEnabled:p})},[xt]),Xs=o.useCallback(p=>{rt(p),St(!0),vt({enterToSend:p,enterToSendConfigured:!0})},[rt,St]),Oi=o.useCallback(p=>{X(p),vt({chatRenderMode:p})},[X]),na=o.useCallback(p=>{Ht(p),vt({messageStreamTransport:p})},[Ht]),aa=o.useCallback(p=>{Ae(p),vt({inputHistoryScope:p})},[Ae]),On=o.useCallback(p=>{const bt=Math.round(p);Ad(bt)&&(He(bt),vt({inputHistoryLimit:bt}))},[He]),ka=o.useCallback(p=>{ge(p),vt({activityRenderMode:p})},[ge]),Fi=o.useCallback(p=>{E(p),vt({mermaidRenderingMode:p})},[E]),os=o.useCallback(p=>{ft(p),vt({showToolFileIcons:p})},[ft]),Ki=o.useCallback(p=>{wt(p),vt({showTurnChangedFiles:p})},[wt]),ia=o.useCallback(p=>{gs(p),vt({defaultFileViewerPreview:p}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:p}}))},[gs]),ra=o.useCallback(p=>{jt(p),vt({showExpandedBashTools:p})},[jt]),zi=o.useCallback(p=>{he(p),vt({showExpandedEditTools:p})},[he]),Xa=o.useCallback(p=>{De(p),vt({timeFormatPreference:p})},[De]),Ui=o.useCallback(p=>{ct(p),vt({weekStartPreference:p})},[ct]),Fn=o.useMemo(()=>mt.filter(p=>p.metadata.variant==="light").sort((p,bt)=>p.metadata.name.localeCompare(bt.metadata.name)),[mt]),mn=o.useMemo(()=>mt.filter(p=>p.metadata.variant==="dark").sort((p,bt)=>p.metadata.name.localeCompare(bt.metadata.name)),[mt]),vn=o.useMemo(()=>Fn.find(p=>p.metadata.id===Yt)??Fn[0],[Fn,Yt]),oa=o.useMemo(()=>mn.find(p=>p.metadata.id===Bt)??mn[0],[mn,Bt]),la=o.useCallback((p,bt)=>{const Ns=bt==="dark"?" Dark":" Light";return p.endsWith(Ns)?p.slice(0,-Ns.length):p},[]),ue=p=>t?t.includes(p):!0,ls=cs(),Kn=ue("theme")&&!ls,Za=ue("windowControlsPosition")&&ns,ei=ue("theme")||ue("timeFormat")||ue("weekStart"),ti=ls?ei:ue("theme")||Za||ue("pwaInstallName")||ue("pwaOrientation")||ue("timeFormat")||ue("weekStart"),si=ue("fontSize")||ue("terminalFontSize")||ue("editorFontSize")||ue("spacing")||ue("inputBarOffset")&&m,ni=ue("terminalQuickKeys")&&!m||(ue("terminalShell")||ue("terminalLoginShell"))&&!ls||ue("fileEditorKeymap")||ue("autoSaveEnabled")||ue("sessionTabs")&&!ls&&!m,_i=ue("mermaidRendering")||ue("sessionGoal")&&!ls||ue("userMessageRendering")||ue("chatRenderMode")||ue("messageTransport")||ue("activityRenderMode")&&Y==="sorted"||ue("collapsibleUserMessages")||ue("stickyUserHeader")||ue("promptNavigatorEnabled")&&!ls||ue("wideChatLayout")||ue("codeBlockLineWrap")||ue("splitAssistantMessageActions")||ue("subagentReadOnlyBanner")||ue("diffLayout")||ue("dotfiles")||ue("fileViewerPreview")||ue("reasoning")||ue("followUpBehavior")||ue("inputHistoryScope")||ue("inputHistoryLimit")||ue("persistDraft")||ue("largeTextPaste")||ue("showToolFileIcons")||ue("expandedTools")||!m&&ue("inputSpellcheck")||ue("enterToSend"),ca=ue("chatRenderMode")||ue("activityRenderMode")&&Y==="sorted",Na=ue("messageTransport"),yn=ue("userMessageRendering")||ue("mermaidRendering")||ue("diffLayout")&&!ls||ue("followUpBehavior")||ue("inputHistoryScope")||ue("inputHistoryLimit"),da=ue("sessionAssist")||ue("sessionGoal")&&!ls||ue("subagentReadOnlyBanner")||ue("collapsibleUserMessages")||ue("stickyUserHeader")||ue("promptNavigatorEnabled")&&!ls||ue("wideChatLayout")||ue("codeBlockLineWrap")||ue("splitAssistantMessageActions")||ue("dotfiles")||ue("fileViewerPreview")||ue("persistDraft")||ue("largeTextPaste")||ue("showToolFileIcons")||ue("showTurnChangedFiles")||!m&&ue("inputSpellcheck")||ue("enterToSend")||ue("reasoning")||ue("expandedTools"),jn=ti||si||ni,wn=ue("pwaInstallName")&&Wn()&&x&&!as()&&!ls,b=ue("pwaOrientation")&&Wn()&&!as()&&!ls,Z=ue("mobileKeyboardMode")&&Wn()&&!as()&&!ls&&Td(),Ke=(ue("terminalShell")||ue("terminalLoginShell"))&&!ls,[tt,Dt]=o.useState([]),[Ds,ws]=o.useState(0);o.useEffect(()=>Tl(()=>{Dt([]),ws(p=>p+1)}),[]),o.useEffect(()=>{let p=!1;if(!(!Ke||!u.listShells))return u.listShells().then(bt=>{p||Dt(bt)}).catch(()=>{p||Dt([])}),()=>{p=!0}},[Ke,u,Ds]);const _s=o.useMemo(()=>{const p=tt.filter(bt=>bt.id!=="auto");return pe==="auto"||p.some(bt=>bt.id===pe)?p:[{id:pe,name:pe,supportsLogin:!1},...p]},[tt,pe]),ks=tt.find(p=>p.id===pe)?.supportsLogin===!0,qs=Ne.includes(pe),Sa=p=>{Se(p?[...Ne.filter(bt=>bt!==pe),pe]:Ne.filter(bt=>bt!==pe))},[un,Ws]=o.useState(""),[Ct,qt]=o.useState("system"),zn=o.useMemo(()=>{const p=Xo.find(bt=>bt.id===Fe);return l(p?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Fe,l]),Mt=o.useMemo(()=>{const p=Zo.find(bt=>bt.id===lt);return l(p?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[lt,l]),Ms=o.useMemo(()=>{const p=Jo.find(bt=>bt.id===Ct);return p?l(p.labelKey):void 0},[Ct,l]),Un=o.useMemo(()=>{const p=Qo.find(bt=>bt.id===ie);return p?l(p.labelKey):void 0},[ie,l]),kn=o.useCallback(async p=>{if(typeof window>"u")return;const bt=window,ps=p.trim().replace(/\s+/g," ").slice(0,64);if(await vt({pwaAppName:ps}),typeof bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const gn=bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(ps);Ws(gn);return}Ws(ps||Da),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Ca=o.useCallback(async p=>{if(typeof window>"u")return;const bt=window,Ns=tr(p);if(await vt({pwaOrientation:Ns}),typeof bt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const ps=bt.__OPENCHAMBER_SET_PWA_ORIENTATION__(Ns);qt(ps);return}qt(Ns),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!wn&&!b&&!Z)return;let p=!1;return(async()=>{try{const Ns=await ut("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Ns.ok){p||Ws(Da);return}const ps=await Ns.json().catch(()=>({})),_n=(typeof ps?.pwaAppName=="string"?ps.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),ai=tr(ps?.pwaOrientation),$i=Zr(ps?.mobileKeyboardMode);p||(wn&&Ws(_n||Da),b&&qt(ai),Z&&we($i))}catch{p||(wn&&Ws(Da),b&&qt("system"),Z&&we("native"))}})(),()=>{p=!0}},[we,Z,wn,b]),s.jsxs("div",{className:"space-y-0",children:[ti&&s.jsxs("div",{className:"space-y-0",children:[Kn&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(An,{children:[s.jsx("div",{className:Js,children:s.jsx(en,{"aria-label":r("settings.openchamber.visual.section.colorMode"),children:Rh.map(p=>s.jsx(tn,{selected:Ts===p.value,onSelect:()=>ce(p.value),label:l(p.labelKey),ariaLabel:l(p.labelKey)},p.value))})}),s.jsxs("div",{className:Js,children:[s.jsx(Wt,{label:r("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(It,{value:vn?.metadata.id??"",onValueChange:rs,children:[s.jsx(Pt,{"aria-label":r("settings.openchamber.visual.field.selectLightThemeAria"),size:Ft,className:Nn,children:s.jsx(Rt,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:vn?la(vn.metadata.name,"light"):void 0})}),s.jsx(At,{children:Fn.map(p=>s.jsx(ot,{value:p.metadata.id,children:la(p.metadata.name,"light")},p.metadata.id))})]})}),s.jsx(Wt,{label:r("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(It,{value:oa?.metadata.id??"",onValueChange:ys,children:[s.jsx(Pt,{"aria-label":r("settings.openchamber.visual.field.selectDarkThemeAria"),size:Ft,className:Nn,children:s.jsx(Rt,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:oa?la(oa.metadata.name,"dark"):void 0})}),s.jsx(At,{children:mn.map(p=>s.jsx(ot,{value:p.metadata.id,children:la(p.metadata.name,"dark")},p.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:yt||ss,onClick:()=>{const p=Date.now();Nt(!0),Qt().finally(()=>{const bt=Date.now()-p;if(bt<500){window.setTimeout(()=>{Nt(!1)},500-bt);return}Nt(!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(R,{name:"restart",className:ve("h-3.5 w-3.5",ss&&"animate-spin")}),r(ss?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(Jt,{children:r("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),Tt&&s.jsx(Va,{settingsItem:"appearance.dock-badge",children:s.jsx(ht,{checked:Ut,onChange:Ot,label:r("settings.openchamber.visual.field.dockBadge"),info:r("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:r("settings.openchamber.visual.field.dockBadge")})})]}),Za&&s.jsx(_e,{title:r("settings.openchamber.desktopNetwork.field.windowControls"),info:r("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:Kn,children:s.jsxs(An,{children:[s.jsx(Wt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Qs,{value:Es,options:Bh.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:Di,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Wt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Qs,{value:Ti,options:Hh.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:Mi,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),ei&&s.jsx(_e,{title:r("settings.openchamber.visual.section.localization"),children:s.jsxs(An,{children:[s.jsx(Wt,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(It,{value:e,onValueChange:p=>n(p),children:[s.jsx(Pt,{"aria-label":r("settings.appearance.language.select"),size:Ft,className:Nn,children:s.jsx(Rt,{children:i(e)})}),s.jsx(At,{children:a.map(p=>s.jsx(ot,{value:p,children:i(p)},p))})]})}),(ue("timeFormat")||ue("weekStart"))&&s.jsxs("div",{className:Js,children:[ue("timeFormat")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(It,{value:Fe,onValueChange:p=>Xa(p),children:[s.jsx(Pt,{"aria-label":r("settings.openchamber.visual.field.selectTimeFormatAria"),size:Ft,className:Nn,children:s.jsx(Rt,{children:zn})}),s.jsx(At,{children:Xo.map(p=>s.jsx(ot,{value:p.id,children:l(p.labelKey)},p.id))})]})}),ue("weekStart")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(It,{value:lt,onValueChange:p=>Ui(p),children:[s.jsx(Pt,{"aria-label":r("settings.openchamber.visual.field.selectWeekStartAria"),size:Ft,className:Nn,children:s.jsx(Rt,{children:Mt})}),s.jsx(At,{children:Zo.map(p=>s.jsx(ot,{value:p.id,children:l(p.labelKey)},p.id))})]})})]})]})}),(wn||b||Z)&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.appInstall"),contentClassName:Js,children:[wn&&s.jsxs(Lt,{label:r("settings.openchamber.visual.field.installAppName"),info:r("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Fs,children:[s.jsx(Je,{value:un,onChange:p=>{Ws(p.target.value)},onBlur:()=>{kn(un)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),kn(un))},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:()=>{Ws(Da),kn("")},className:hs,"aria-label":r("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]}),b&&s.jsxs(Lt,{label:r("settings.openchamber.visual.field.installOrientation"),description:r("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Fs,children:[s.jsxs(It,{value:Ct,onValueChange:p=>{const bt=tr(p);qt(bt),Ca(bt)},children:[s.jsx(Pt,{"aria-label":r("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:Ft,className:zr,children:s.jsx(Rt,{placeholder:r("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Ms})}),s.jsx(At,{children:Jo.map(p=>s.jsx(ot,{value:p.id,children:l(p.labelKey)},p.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{qt("system"),Ca("system")},disabled:Ct==="system",className:hs,"aria-label":r("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]}),Z&&s.jsxs(Lt,{label:r("settings.openchamber.visual.field.mobileKeyboardMode"),info:r("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Fs,children:[s.jsxs(It,{value:ie,onValueChange:p=>{const bt=Zr(p);we(bt),vt({mobileKeyboardMode:bt})},children:[s.jsx(Pt,{"aria-label":r("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:Ft,className:zr,children:s.jsx(Rt,{placeholder:r("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Un})}),s.jsx(At,{children:Qo.map(p=>s.jsx(ot,{value:p.id,children:l(p.labelKey)},p.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>{we("native"),vt({mobileKeyboardMode:"native"})},disabled:ie==="native",className:hs,"aria-label":r("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),si&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.densityAndType"),contentClassName:Js,children:[ue("fontSize")&&!m||ue("terminalFontSize")?s.jsxs(An,{children:[ue("fontSize")&&!m&&s.jsxs(Wt,{label:r("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(It,{value:Le,onValueChange:p=>oe(p),children:[s.jsx(Pt,{"aria-label":r("settings.openchamber.visual.field.selectInterfaceFontAria"),size:Ft,className:Nn,children:s.jsx(Rt,{children:Jr.find(p=>p.id===Le)?.label})}),s.jsx(At,{children:Jr.map(p=>s.jsx(ot,{value:p.id,children:s.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>oe(Qr),disabled:Le===Qr,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]}),ue("terminalFontSize")&&s.jsxs(Wt,{label:r("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(It,{value:fe,onValueChange:p=>Me(p),children:[s.jsx(Pt,{"aria-label":r("settings.openchamber.visual.field.selectCodeFontAria"),size:Ft,className:Nn,children:s.jsx(Rt,{children:Yr.find(p=>p.id===fe)?.label})}),s.jsx(At,{children:Yr.map(p=>s.jsx(ot,{value:p.id,children:s.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Me(Xr),disabled:fe===Xr,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,ue("fontSize")&&!m||ue("terminalFontSize")||ue("editorFontSize")?s.jsxs(An,{children:[ue("fontSize")&&!m&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:ma,children:[s.jsx(xs,{value:de,onValueChange:xe,min:50,max:200,step:5,className:Cs,"aria-label":r("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:ua,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>xe(100),disabled:de===100,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ue("terminalFontSize")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ma,children:[s.jsx(xs,{value:ae,onValueChange:te,min:9,max:52,step:1,className:Cs}),s.jsx("span",{className:ua,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>te(13),disabled:ae===13,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ue("editorFontSize")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ma,children:[s.jsx(xs,{value:be,onValueChange:Oe,min:9,max:32,step:1,className:Cs}),s.jsx("span",{className:ua,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Oe(13),disabled:be===13,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,ue("spacing")||ue("inputBarOffset")&&m?s.jsxs(An,{children:[ue("spacing")&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:ma,children:[s.jsx(xs,{value:$e,onValueChange:Ve,min:50,max:200,step:5,className:Cs}),s.jsx("span",{className:ua,children:"%"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ve(100),disabled:$e===100,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})}),ue("inputBarOffset")&&m&&s.jsx(Wt,{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:ma,children:[s.jsx(xs,{value:qe,onValueChange:se,min:0,max:100,step:5,className:Cs}),s.jsx("span",{className:ua,children:"px"}),s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:()=>se(0),disabled:qe===0,className:hs,"aria-label":r("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null]}),ni&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[ue("fileEditorKeymap")&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(en,{"aria-label":r("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(p=>s.jsx(tn,{selected:me===p,onSelect:()=>Ce(p),label:r(`settings.openchamber.visual.option.fileEditorKeymap.${p}`),ariaLabel:r(`settings.openchamber.visual.option.fileEditorKeymap.${p}`)},p))})}),s.jsxs("div",{className:fs,children:[ue("autoSaveEnabled")&&s.jsx(ht,{checked:z,onChange:re,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"}),Ke&&s.jsx(Wt,{label:r("settings.openchamber.visual.field.terminalShell"),info:r("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(It,{value:pe,onValueChange:p=>{Ed(p)&&Ie(p)},children:[s.jsx(Pt,{"aria-label":r("settings.openchamber.visual.field.terminalShellAria"),size:Ft,className:Nn,children:s.jsx(Rt,{})}),s.jsxs(At,{children:[s.jsx(ot,{value:"auto",children:r("settings.openchamber.visual.option.terminalShell.auto")}),_s.map(p=>s.jsx(ot,{value:p.id,children:p.name},p.id))]})]})}),Ke&&ks&&s.jsx(ht,{checked:qs,onChange:Sa,label:r("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:r("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),ue("terminalQuickKeys")&&!m&&s.jsx(ht,{checked:Ue,onChange:Ge,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",{control:Qn("ctrl"),alt:Qn("alt")})})]}),ue("sessionTabs")&&!ls&&!m&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(ht,{checked:Pe,onChange:je,label:r("settings.openchamber.visual.field.sessionTabs"),ariaLabel:r("settings.openchamber.visual.field.sessionTabsAria"),info:r("settings.openchamber.visual.field.sessionTabsInfo")})})]}),_i&&s.jsxs(s.Fragment,{children:[ca&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.chatDisplay"),divider:jn,contentClassName:"space-y-6",children:[ue("chatRenderMode")&&s.jsx(Ps,{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:Kh.map(p=>{const bt=Y===p.id,Ns=Ei%12;return s.jsxs("button",{type:"button",onClick:()=>Oi(p.id),"aria-pressed":bt,className:ve("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",bt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ve("typography-ui-label",bt?"text-foreground":"text-muted-foreground"),children:l(p.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:p.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ps=>{const gn=ps*3+1,_n=Ns-gn+1,ai=_n<=0?0:_n===1?42:_n===2?68:92,$i=ai>0;return s.jsxs("div",{className:ve("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",$i?"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:`${ai}%`}})]},ps)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(ps=>{const gn=Ns>=(ps+1)*3;return s.jsxs("div",{className:ve("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",gn?"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%"}})]},ps)})})})]},p.id)})})}),ue("activityRenderMode")&&Y==="sorted"&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.activityDefault"),children:s.jsx(en,{"aria-label":r("settings.openchamber.visual.section.activityDefaultAria"),children:zh.map(p=>s.jsx(tn,{selected:ee===p.id,onSelect:()=>ka(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(p.labelKey)})},p.id))})})]}),Na&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.messageStreamTransport"),divider:ca||jn,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Qs,{value:vs,options:Yo.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:na,"aria-label":r("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const p=Yo.find(bt=>bt.id===vs);return p?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(p.descriptionKey)}):null})()]}),yn&&s.jsx(_e,{title:r("settings.openchamber.visual.section.chatMessageOptions"),divider:ca||Na||jn,children:s.jsxs(An,{className:"lg:gap-y-6",children:[ue("userMessageRendering")&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(en,{"aria-label":r("settings.openchamber.visual.section.userMessageRenderingAria"),children:Fh.map(p=>s.jsx(tn,{selected:Vh(B)===p.id,onSelect:()=>Ri(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(p.labelKey)})},p.id))})}),ue("mermaidRendering")&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(en,{"aria-label":r("settings.openchamber.visual.section.mermaidRenderingAria"),children:Oh.map(p=>s.jsx(tn,{selected:I===p.id,onSelect:()=>Fi(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(p.labelKey)})},p.id))})}),ue("diffLayout")&&!ls&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.diffLayout"),children:s.jsx(en,{"aria-label":r("settings.openchamber.visual.section.diffLayoutAria"),children:Lh.map(p=>s.jsx(tn,{selected:ye===p.id,onSelect:()=>Te(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.diffLayoutAria",{option:l(p.labelKey)})},p.id))})}),ue("followUpBehavior")&&s.jsx(Ps,{title:r("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(en,{"aria-label":r("settings.openchamber.visual.section.followUpBehaviorAria"),children:Uh.map(p=>s.jsx(tn,{selected:Re===p.id,onSelect:()=>Ye(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(p.labelKey)})},p.id))})}),ue("inputHistoryScope")&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.inputHistoryScope"),info:r("settings.openchamber.visual.field.inputHistoryScopeDescription"),settingsItem:"chat.input-history-scope",children:s.jsx(en,{"aria-label":r("settings.openchamber.visual.section.inputHistoryScopeAria"),children:$h.map(p=>s.jsx(tn,{selected:q===p.id,onSelect:()=>aa(p.id),label:l(p.labelKey),ariaLabel:l(p.labelKey)},p.id))})}),ue("inputHistoryLimit")&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.inputHistoryLimit"),description:r("settings.openchamber.visual.field.inputHistoryLimitDescription"),contentClassName:Fs,settingsItem:"chat.input-history-limit",children:s.jsxs("div",{className:ma,children:[s.jsx(xs,{value:ke,onValueChange:On,min:Md,max:Dd,step:1,className:Cs,deferExternalValueWhileFocused:!0,"aria-label":r("settings.openchamber.visual.field.inputHistoryLimitAria")}),s.jsx("span",{className:ua,children:r("settings.openchamber.visual.field.inputHistoryLimitUnit")})]})})]})}),da&&s.jsxs(s.Fragment,{children:[ue("expandedTools")&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:ca||Na||yn||jn,contentClassName:fs,children:[s.jsx(ht,{checked:Ee,onChange:ra,label:r("settings.openchamber.visual.field.bash"),ariaLabel:r("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(ht,{checked:J,onChange:zi,label:r("settings.openchamber.visual.field.editTools"),ariaLabel:r("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(_e,{title:r("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:fs,children:[s.jsx(ht,{checked:Ls,onChange:Gs,label:r("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:r("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),ue("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(ht,{checked:c,onChange:f,label:r("settings.openchamber.visual.field.sessionRecap"),ariaLabel:r("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(ht,{checked:N,onChange:C,label:r("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:r("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),ue("subagentReadOnlyBanner")&&s.jsx(ht,{checked:bs,onChange:Xt,label:r("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),ue("sessionGoal")&&!ls&&s.jsxs(_e,{title:r("settings.openchamber.visual.goal.sectionTitle"),info:r("settings.openchamber.visual.goal.description"),contentClassName:fs,children:[s.jsx(ht,{checked:y,onChange:S,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(ht,{checked:g,onChange:T,disabled:!y,label:r("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:r("settings.openchamber.visual.goal.budgetAria")}),y&&g?s.jsx(xs,{value:M,onValueChange:p=>{typeof p=="number"&&Number.isFinite(p)&&p>0&&P(Math.floor(p))},min:1e3,max:1e8,step:5e4}):null]})]}),ue("reasoning")&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:fs,children:[s.jsx(ht,{checked:v,onChange:k,label:r("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:r("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),v&&s.jsx(ht,{checked:F,onChange:A,label:r("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(_e,{title:r("settings.openchamber.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:fs,children:s.jsx(ht,{checked:h,onChange:j,label:r("settings.openchamber.visual.field.streamingAutoFollow"),ariaLabel:r("settings.openchamber.visual.field.streamingAutoFollowAria"),info:r("settings.openchamber.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(ue("collapsibleUserMessages")||ue("stickyUserHeader")||ue("promptNavigatorEnabled")&&!ls||ue("wideChatLayout")||ue("splitAssistantMessageActions")||ue("codeBlockLineWrap"))&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:fs,children:[ue("collapsibleUserMessages")&&s.jsx(ht,{checked:w,onChange:sa,label:r("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),ue("stickyUserHeader")&&s.jsx(ht,{checked:W,onChange:Li,label:r("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:r("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),ue("promptNavigatorEnabled")&&!ls&&s.jsx(ht,{checked:L,onChange:js,label:r("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),ue("wideChatLayout")&&s.jsx(ht,{checked:$,onChange:pn,label:r("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:r("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),ue("splitAssistantMessageActions")&&s.jsx(ht,{checked:Qe,onChange:bn,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")}),ue("codeBlockLineWrap")&&s.jsx(ht,{checked:K,onChange:O,label:r("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(ue("showToolFileIcons")||ue("showTurnChangedFiles")||ue("dotfiles")&&!cs()||ue("fileViewerPreview"))&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:fs,children:[ue("showToolFileIcons")&&s.jsx(ht,{checked:Xe,onChange:os,label:r("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:r("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),ue("showTurnChangedFiles")&&s.jsx(ht,{checked:ze,onChange:Ki,label:r("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),ue("dotfiles")&&!cs()&&s.jsx(ht,{checked:d,onChange:Rd,label:r("settings.openchamber.visual.field.showDotfiles"),ariaLabel:r("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),ue("fileViewerPreview")&&s.jsx(ht,{checked:us,onChange:ia,label:r("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:r("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(ue("persistDraft")||ue("largeTextPaste")||!m&&ue("inputSpellcheck")||ue("enterToSend"))&&s.jsxs(_e,{title:r("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:fs,children:[ue("persistDraft")&&s.jsx(ht,{checked:at,onChange:nt,label:r("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:r("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!m&&ue("inputSpellcheck")&&s.jsx(ht,{checked:dt,onChange:Rr,label:r("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"}),ue("largeTextPaste")&&s.jsx(Ps,{title:r("settings.openchamber.visual.field.largeTextPaste"),info:r("settings.openchamber.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(en,{"aria-label":r("settings.openchamber.visual.field.largeTextPasteAria"),children:_h.map(p=>s.jsx(tn,{selected:G===p.id,onSelect:()=>Be(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.largeTextPasteOptionAria",{option:l(p.labelKey)})},p.id))})}),ue("enterToSend")&&s.jsx(ht,{checked:pt?st:!m&&!et,onChange:Xs,label:r("settings.openchamber.visual.field.enterToSend"),info:r("settings.openchamber.visual.field.enterToSendHint"),ariaLabel:r("settings.openchamber.visual.field.enterToSend"),settingsItem:"chat.enter-to-send"})]})]})]}),ue("reportUsage")&&s.jsx(_e,{title:r("settings.openchamber.visual.section.privacy"),children:s.jsx(ht,{checked:wa,onChange:Qa,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"})})]})},Gh=1,qh=365,el=30,Wh=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Xl=()=>{const t=gt.c(88),{t:e}=it(),a=le(Jh),n=le(Qh),i=le(Yh),r=le(Xh),l=le(Zh),m=le(ef);let u;t[0]===Symbol.for("react.memo_cache_sentinel")?(u={autoRun:!1},t[0]=u):u=t[0];const{candidates:x,isRunning:d,runCleanup:v,action:c}=Gc(u),N=x.length;let f;t[1]!==v||t[2]!==e?(f=async()=>{const de=await v({force:!0});if(de.completedIds.length===0&&de.failedIds.length===0){D.message(de.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}de.completedIds.length>0&&D.success(de.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:de.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:de.completedIds.length})),de.failedIds.length>0&&D.error(de.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:de.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:de.failedIds.length}))},t[1]=v,t[2]=e,t[3]=f):f=t[3];const C=f;let y;t[4]!==e?(y=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=y):y=t[5];let S;t[6]!==e?(S=e("settings.openchamber.sessionRetention.tooltip"),t[6]=e,t[7]=S):S=t[7];let g;t[8]!==e?(g=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=g):g=t[9];let T;t[10]!==e?(T=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=T):T=t[11];let M;t[12]!==a||t[13]!==r||t[14]!==g||t[15]!==T?(M=s.jsx(ht,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:g,ariaLabel:T}),t[12]=a,t[13]=r,t[14]=g,t[15]=T,t[16]=M):M=t[16];let P;t[17]!==e?(P=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[17]=e,t[18]=P):P=t[18];let k;t[19]!==e?(k=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[19]=e,t[20]=k):k=t[20];let h;t[21]===Symbol.for("react.memo_cache_sentinel")?(h=ve(Cs,"tabular-nums"),t[21]=h):h=t[21];let j;t[22]!==n||t[23]!==l||t[24]!==k?(j=s.jsx(xs,{value:n,onValueChange:l,min:Gh,max:qh,step:1,"aria-label":k,className:h}),t[22]=n,t[23]=l,t[24]=k,t[25]=j):j=t[25];let F;t[26]!==e?(F=e("settings.openchamber.sessionRetention.field.days"),t[26]=e,t[27]=F):F=t[27];let A;t[28]!==F?(A=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:F}),t[28]=F,t[29]=A):A=t[29];let I;t[30]!==l?(I=()=>l(el),t[30]=l,t[31]=I):I=t[31];const E=n===el;let B;t[32]!==e?(B=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[32]=e,t[33]=B):B=t[33];let _;t[34]!==e?(_=e("settings.common.actions.reset"),t[34]=e,t[35]=_):_=t[35];let w;t[36]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(R,{name:"restart",className:"h-3.5 w-3.5"}),t[36]=w):w=t[36];let V;t[37]!==I||t[38]!==E||t[39]!==B||t[40]!==_?(V=s.jsx(H,{size:"sm",type:"button",variant:"ghost",onClick:I,disabled:E,className:hs,"aria-label":B,title:_,children:w}),t[37]=I,t[38]=E,t[39]=B,t[40]=_,t[41]=V):V=t[41];let W;t[42]!==j||t[43]!==A||t[44]!==V||t[45]!==P?(W=s.jsxs(Lt,{settingsItem:"sessions.retention-period",label:P,children:[j,A,V]}),t[42]=j,t[43]=A,t[44]=V,t[45]=P,t[46]=W):W=t[46];let L;t[47]!==e?(L=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[47]=e,t[48]=L):L=t[48];let Q;t[49]!==e?(Q=Wh.map(de=>({value:de.value,label:e(de.labelKey)})),t[49]=e,t[50]=Q):Q=t[50];let ne;t[51]!==i||t[52]!==m||t[53]!==Q?(ne=s.jsx(Qs,{value:i,onChange:m,options:Q}),t[51]=i,t[52]=m,t[53]=Q,t[54]=ne):ne=t[54];let z;t[55]!==L||t[56]!==ne?(z=s.jsx(Lt,{settingsItem:"sessions.retention-action",label:L,children:ne}),t[55]=L,t[56]=ne,t[57]=z):z=t[57];let re;t[58]!==W||t[59]!==z?(re=s.jsxs(Va,{className:"space-y-0",children:[W,z]}),t[58]=W,t[59]=z,t[60]=re):re=t[60];let $;t[61]!==e?($=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[61]=e,t[62]=$):$=t[62];let U;t[63]!==d||t[64]!==e?(U=e(d?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[63]=d,t[64]=e,t[65]=U):U=t[65];let K;t[66]!==C||t[67]!==d||t[68]!==U?(K=s.jsx(H,{type:"button",variant:"outline",size:"xs",onClick:C,disabled:d,className:"!font-normal",children:U}),t[66]=C,t[67]=d,t[68]=U,t[69]=K):K=t[69];let O;t[70]!==$||t[71]!==K?(O=s.jsx(Lt,{label:$,children:K}),t[70]=$,t[71]=K,t[72]=O):O=t[72];let Y;t[73]!==c||t[74]!==N||t[75]!==e?(Y=c==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:N}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:N}),t[73]=c,t[74]=N,t[75]=e,t[76]=Y):Y=t[76];let X;t[77]!==Y?(X=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Y}),t[77]=Y,t[78]=X):X=t[78];let ee;t[79]!==O||t[80]!==X?(ee=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[O,X]}),t[79]=O,t[80]=X,t[81]=ee):ee=t[81];let ge;return t[82]!==y||t[83]!==re||t[84]!==S||t[85]!==ee||t[86]!==M?(ge=s.jsxs(_e,{title:y,info:S,children:[M,re,ee]}),t[82]=y,t[83]=re,t[84]=S,t[85]=ee,t[86]=M,t[87]=ge):ge=t[87],ge};function Jh(t){return t.autoDeleteEnabled}function Qh(t){return t.autoDeleteAfterDays}function Yh(t){return t.sessionRetentionAction}function Xh(t){return t.setAutoDeleteEnabled}function Zh(t){return t.setAutoDeleteAfterDays}function ef(t){return t.setSessionRetentionAction}const tl=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(kr(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),Zl=()=>{const{t}=it(),e=le(h=>h.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,m]=o.useState(!1),[u,x]=o.useState(null),[d,v]=o.useState(!1),[c,N]=o.useState([]),[f,C]=o.useState(qc),[y,S]=o.useState(""),g=o.useMemo(()=>Wc(),[]),T=o.useCallback(async()=>{r(!0),S("");try{const h=await Jc();N(h)}catch(h){const j=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.loadFailed");S(j)}finally{r(!1)}},[t]);o.useEffect(()=>{let h=!1;return(async()=>{try{if(!g.supported){h||(n(!1),r(!1));return}h||n(!0)}catch{h||n(!1)}if(!h){const j=await Bi();if(C(j),!j.enabled){N([]),r(!1);return}await T()}})(),()=>{h=!0,Ur()}},[T,g.supported]);const M=o.useCallback(async()=>{if(!f.enabled){const h=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");S(h),D.message(h);return}if(!a){S(g.reason),D.message(g.reason);return}if(l){Ur(),m(!1);return}S(""),m(!0);try{await Qc(),C(await Bi()),await T(),D.success(t("settings.openchamber.passkeys.toast.added"))}catch(h){if(Yc(h)){D.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const j=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.addFailed");S(j),D.error(j)}finally{m(!1)}},[l,T,f.enabled,g.reason,a,t]),P=o.useCallback(async h=>{x(h),S("");try{await Xc(h),C(await Bi()),await T(),D.success(t("settings.openchamber.passkeys.toast.removed"))}catch(j){const F=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.removeFailed");S(F),D.error(F)}finally{x(null)}},[T,t]),k=o.useCallback(async()=>{v(!0),S("");try{await Zc(),window.location.reload()}catch(h){const j=h instanceof Error?h.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");S(j),D.error(j),v(!1)}},[t]);return s.jsxs(_e,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Lt,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(H,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{M()},disabled:i||d,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:()=>{k()},disabled:i||l||d,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(d?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!f.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),f.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):c.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:c.map(h=>s.jsxs(Lt,{label:s.jsx("span",{title:h.label,children:h.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:h.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:tl(h.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:tl(h.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>{P(h.id)},disabled:u===h.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:u===h.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},h.id))})]}),y&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:y})})]})},ec=()=>{const t=gt.c(14),{t:e}=it(),a=_r(tf),n=_r(sf);let i;t[0]!==e?(i=e("settings.openchamber.appLinks.title"),t[0]=e,t[1]=i):i=t[1];let r;t[2]!==e?(r=e("settings.openchamber.appLinks.info"),t[2]=e,t[3]=r):r=t[3];let l;t[4]!==n||t[5]!==e||t[6]!==a?(l=a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.appLinks.empty")}):a.map(x=>s.jsxs("div",{className:"flex items-center justify-between gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-[13px]",children:`${x}://`}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(x),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${x}://`}),children:e("settings.common.actions.delete")})]},x)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let m;t[8]!==l?(m=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=m):m=t[9];let u;return t[10]!==i||t[11]!==r||t[12]!==m?(u=s.jsx(_e,{title:i,description:r,children:m}),t[10]=i,t[11]=r,t[12]=m,t[13]=u):u=t[13],u};function tf(t){return t.trustedSchemes}function sf(t){return t.removeTrustedScheme}const sr=t=>{const e=ba(t);return e||{providerId:"",modelId:""}},tc=()=>{const{t}=it(),e=Ze(ae=>ae.setProvider),a=Ze(ae=>ae.setModel),n=Ze(ae=>ae.setAgent),i=Ze(ae=>ae.setCurrentVariant),r=Ze(ae=>ae.setCurrentVariantOverride),l=Ze(ae=>ae.setSettingsDefaultModel),m=Ze(ae=>ae.setSettingsDefaultVariant),u=Ze(ae=>ae.setSettingsDefaultAgent),x=Ze(ae=>ae.selectionSource==="manual"),d=ed(ae=>ae.currentSessionId),v=$r(ae=>ae.getSessionModelSelection),c=$r(ae=>ae.getSessionAgentSelection),N=!!(x&&d&&v(d)),f=!!(x&&d&&c(d)),C=le(ae=>ae.showDeletionDialog),y=le(ae=>ae.setShowDeletionDialog),S=Ze(ae=>ae.providers),g=Ze(ae=>ae.modelsMetadata),[T,M]=o.useState(),[P,k]=o.useState(),[h,j]=o.useState(),[F,A]=o.useState(!0),[I,E]=o.useState(),[B,_]=o.useState([]),[w,V]=o.useState(),[W,L]=o.useState(!0),Q=o.useMemo(()=>sr(T),[T]);o.useEffect(()=>{(async()=>{try{let te=null;if(!te){const pe=an()?.settings;if(pe)try{const Ne=(await pe.load())?.settings;if(Ne){const Se=Ne;te={defaultModel:typeof Ne.defaultModel=="string"?Ne.defaultModel:void 0,defaultVariant:typeof Se.defaultVariant=="string"?Se.defaultVariant:void 0,defaultAgent:typeof Ne.defaultAgent=="string"?Ne.defaultAgent:void 0,smallModelUseDefault:typeof Se.smallModelUseDefault=="boolean"?Se.smallModelUseDefault:void 0,smallModelOverride:typeof Se.smallModelOverride=="string"?Se.smallModelOverride:void 0,walkthroughModelOverride:typeof Se.walkthroughModelOverride=="string"?Se.walkthroughModelOverride:void 0}}}catch{}}if(!te){const pe=await ut("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});pe.ok&&(te=await pe.json())}if(te){const pe=typeof te.defaultModel=="string"&&te.defaultModel.trim().length>0?te.defaultModel.trim():void 0,Ie=typeof te.defaultVariant=="string"&&te.defaultVariant.trim().length>0?te.defaultVariant.trim():void 0,Ne=typeof te.defaultAgent=="string"&&te.defaultAgent.trim().length>0?te.defaultAgent.trim():void 0;pe!==void 0&&M(pe),Ie!==void 0&&k(Ie),Ne!==void 0&&j(Ne),typeof te.smallModelUseDefault=="boolean"&&A(te.smallModelUseDefault),typeof te.smallModelOverride=="string"&&te.smallModelOverride.trim()&&E(te.smallModelOverride.trim()),typeof te.walkthroughModelOverride=="string"&&te.walkthroughModelOverride.trim()&&V(te.walkthroughModelOverride.trim())}}catch(te){console.warn("Failed to load defaults settings:",te)}finally{L(!1)}})()},[]);const ne=o.useCallback(async(ae,te)=>{const pe=ae&&te?`${ae}/${te}`:void 0;M(pe),k(void 0),m(void 0),l(pe),N||(i(void 0),ae&&te&&S.find(Ne=>Ne.id===ae)&&(e(ae),a(te)));try{await vt({defaultModel:pe??"",defaultVariant:""});const Ie=await ut("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:pe})});Ie.ok||console.warn("Failed to save default model to server:",Ie.status,Ie.statusText)}catch(Ie){console.warn("Failed to save default model:",Ie)}},[N,S,i,a,e,l,m]),z="__default__",re=o.useCallback(ae=>ae===z?t("settings.openchamber.defaults.option.default"):ae.charAt(0).toUpperCase()+ae.slice(1),[t]),$=o.useCallback(async ae=>{const te=ae===z?void 0:ae||void 0;k(te),m(te),N||r(te??null,te);try{await vt({defaultVariant:te??""})}catch(pe){console.warn("Failed to save default variant:",pe)}},[N,r,m]),U=o.useCallback(async ae=>{const te=ae||void 0;j(te),u(te),ae&&!f&&n(ae);try{await vt({defaultAgent:te??""})}catch(pe){console.warn("Failed to save default agent:",pe)}},[f,n,u]),K=o.useCallback(async ae=>{A(ae);try{await vt({smallModelUseDefault:ae})}catch(te){console.warn("Failed to save small model preference:",te)}},[]),O=o.useCallback(async(ae,te)=>{const pe=ae&&te?`${ae}/${te}`:void 0;E(pe);try{await vt({smallModelOverride:pe??""})}catch(Ie){console.warn("Failed to save small model override:",Ie)}},[]),Y=o.useCallback(async(ae,te)=>{const pe=ae&&te?`${ae}/${te}`:void 0;V(pe);try{await vt({walkthroughModelOverride:pe??""})}catch(Ie){console.warn("Failed to save walkthrough model override:",Ie)}},[]),X=o.useCallback((ae,te)=>g.get(`${ae}/${te}`)?.structured_output!==!1,[g]),ee=o.useMemo(()=>sr(I),[I]),ge=o.useMemo(()=>sr(w),[w]);o.useEffect(()=>{let ae=!1;return(async()=>{try{const te=await ut("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!te.ok)return;const pe=await te.json().catch(()=>null);!ae&&Array.isArray(pe?.authenticatedProviders)&&_(pe.authenticatedProviders.filter(Ie=>typeof Ie=="string"))}catch{}})(),()=>{ae=!0}},[]);const de=o.useMemo(()=>{if(!Q.providerId||!Q.modelId)return[];const pe=S.find(Ie=>Ie.id===Q.providerId)?.models.find(Ie=>Ie.id===Q.modelId)?.variants;return pe?Object.keys(pe):[]},[Q.modelId,Q.providerId,S]),xe=de.length>0;return o.useEffect(()=>{!xe&&P&&(k(void 0),m(void 0),N||i(void 0),vt({defaultVariant:""}).catch(()=>{}))},[N,P,i,m,xe]),W?null:s.jsx(s.Fragment,{children:s.jsx(_e,{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")," ",Q.providerId?s.jsxs("span",{className:"text-foreground",children:[Q.providerId,"/",Q.modelId,xe?` (${P??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(Lt,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(Ka,{providerId:Q.providerId,modelId:Q.modelId,onChange:ne,className:En})}),s.jsx(Lt,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(It,{value:P??z,onValueChange:$,disabled:!xe,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:re(P??z)})}),s.jsxs(At,{children:[s.jsx(ot,{value:z,children:t("settings.openchamber.defaults.option.default")}),de.map(ae=>s.jsx(ot,{value:ae,children:re(ae)},ae))]})]})}),s.jsx(Lt,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(xl,{agentName:h||"",onChange:U,filter:ae=>td(ae.mode),className:En})})]}),s.jsx(Va,{className:fs,children:s.jsx(ht,{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(Ys,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(Jt,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(ht,{settingsItem:"sessions.small-model",checked:F,onChange:ae=>{K(ae)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),F?null:s.jsx(Lt,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(Ka,{providerId:ee.providerId,modelId:ee.modelId,onChange:O,allowedProviderIds:B,className:En})}),s.jsxs(Va,{className:fs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ys,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(Jt,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Lt,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(Ka,{providerId:ge.providerId,modelId:ge.modelId,onChange:Y,allowedProviderIds:B,isModelAllowed:X,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:En})})]})]})]})})})},sl={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"}},nf={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"},af=()=>{const{t}=it(),e=o.useMemo(()=>as(),[]),a=o.useMemo(()=>cs(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=le($=>$.nativeNotificationsEnabled),l=le($=>$.setNativeNotificationsEnabled),m=le($=>$.notificationMode),u=le($=>$.setNotificationMode),x=le($=>$.notifyOnSubtasks),d=le($=>$.setNotifyOnSubtasks),v=le($=>$.notifyOnCompletion),c=le($=>$.setNotifyOnCompletion),N=le($=>$.notifyOnError),f=le($=>$.setNotifyOnError),C=le($=>$.notifyOnQuestion),y=le($=>$.setNotifyOnQuestion),S=le($=>$.notificationTemplates),g=le($=>$.setNotificationTemplates),[T,M]=o.useState("default"),[P,k]=o.useState(!1),[h,j]=o.useState(!1),[F,A]=o.useState(!1);o.useEffect(()=>{if(!i){k(!1),j(!1);return}typeof Notification<"u"&&M(Notification.permission);const $=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;k($),(async()=>{if(!$){j(!1);return}try{const K=await navigator.serviceWorker.getRegistration();if(!K){j(!1);return}const O=await K.pushManager.getSubscription();j(!!O)}catch{j(!1)}})()},[i]);const I=async $=>{if(e){l($);return}if(!i){l($);return}if($&&typeof Notification<"u"&&Notification.permission==="default")try{const U=await Notification.requestPermission();M(U),U==="granted"?l(!0):D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(U){console.error("Failed to request notification permission:",U),D.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!($&&T==="granted"))},E=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",B=($,U,K)=>{g(O=>({...O,[$]:{...O[$],[U]:K}}))},_=$=>{const U="=".repeat((4-$.length%4)%4),K=($+U).replace(/-/g,"+").replace(/_/g,"/"),O=atob(K),Y=new Uint8Array(O.length);for(let X=0;X<O.length;X+=1)Y[X]=O.charCodeAt(X);return Y},w=async($,U,K)=>{let O=null;const Y=new Promise((X,ee)=>{O=setTimeout(()=>{ee(new Error(K))},U)});try{return await Promise.race([$,Y])}finally{O&&clearTimeout(O)}},V=async $=>{if($.active)return;const U=$.installing||$.waiting;U&&U.state!=="activated"&&await w(new Promise(K=>{const O=()=>{U.state==="activated"&&(U.removeEventListener("statechange",O),K())};U.addEventListener("statechange",O),O()}),15e3,"Service worker activation timed out")},W=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const $=[{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 U=null;for(const K of $)try{const O=K.opts?navigator.serviceWorker.register("/sw.js",K.opts):navigator.serviceWorker.register("/sw.js");return await w(O,1e4,`Service worker registration timed out (${K.label})`)}catch(O){U=O}throw U instanceof Error?U:new Error("Service worker registration failed")},L=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const $=await navigator.serviceWorker.getRegistration();if($)return $;const U=await W();try{await U.update()}catch{}return await V(U),U},Q=$=>{const U=$,K=[`type=${typeof $}`,`toString=${String($)}`,`name=${String(U?.name??"")}`,`message=${String(U?.message??"")}`];let O="";try{O=JSON.stringify($)}catch{}return{summary:K.filter(Boolean).join(" | "),json:O,stack:typeof U?.stack=="string"?U.stack:""}},ne=async()=>{const $=an();if(!$?.notifications){D.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await $.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?D.success(t("settings.notifications.page.toast.testNotificationSent")):D.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(U){console.error("Test notification failed:",U),D.error(t("settings.notifications.page.toast.testNotificationFailed"))}},z=async()=>{if(!P){D.error(t("settings.notifications.page.toast.pushUnsupported"));return}const $=an();if(!$?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}A(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const de=await Notification.requestPermission();if(M(de),de!=="granted"){D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const U=await $.push.getVapidPublicKey();if(!U?.publicKey){D.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const K=await L();await V(K);const O=await K.pushManager.getSubscription();if(!("pushManager"in K)||!K.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const X=(O??await w(K.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:_(U.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ee=X.keys;if(!X.endpoint||!ee?.p256dh||!ee.auth)throw new Error("Push subscription missing keys");if(!(await w($.push.subscribe({endpoint:X.endpoint,keys:{p256dh:ee.p256dh,auth:ee.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:Ld()}),15e3,"Push subscribe request timed out"))?.ok){D.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}j(!0),D.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(U){console.error("[Push] Enable failed:",U);const K=Q(U);D.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:K.summary})}finally{A(!1)}},re=async()=>{if(!P){j(!1);return}const $=an();if(!$?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}A(!0);try{const K=await(await L()).pushManager.getSubscription();if(!K){j(!1);return}const O=K.endpoint;await K.unsubscribe(),await $.push.unsubscribe({endpoint:O}),j(!1),D.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{A(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(_e,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:fs,children:[s.jsx(ht,{checked:r&&E,onChange:$=>{I($)},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&&E&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(ht,{checked:m==="always",onChange:$=>u($?"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:()=>{ne()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[T==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),T==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&E&&s.jsxs(s.Fragment,{children:[s.jsx(_e,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:fs,children:[s.jsx(ht,{checked:v,onChange:c,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(ht,{checked:x,onChange:d,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(ht,{checked:N,onChange:f,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(ht,{checked:C,onChange:y,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(_e,{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(An,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map($=>s.jsxs("section",{className:"p-2",children:[s.jsx(Ys,{className:"capitalize",children:t(nf[$])}),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(Je,{value:S[$].title,onChange:U=>B($,"title",U.target.value),className:"h-7",placeholder:t(sl[$].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(Je,{value:S[$].message,onChange:U=>B($,"message",U.target.value),className:"h-7",placeholder:t(sl[$].messageKey)})]})]})]},$))})})]}),i&&s.jsx(_e,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(ht,{checked:P?h:!1,disabled:!P||F,onChange:$=>{$?z():re()},label:t("settings.notifications.page.push.enableLabel"),description:P?void 0:t("settings.notifications.page.push.unsupportedHint"),info:P?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:F?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})})]})},Rs=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},rf=[{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"}],nl=t=>{const e=gt.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 m;e[2]!==n?(m=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=m):m=e[3];let u;return e[4]!==i||e[5]!==l||e[6]!==m?(u=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,m]}),e[4]=i,e[5]=l,e[6]=m,e[7]=u):u=e[7],u},of=({selectedModelId:t,onSelect:e})=>{const{t:a}=it(),n=We.useCallback(c=>a(c),[a]),[i,r]=We.useState(new Map),[l,m]=We.useState(null),u=We.useCallback(async()=>{try{const c=await ut("/api/dictation/status",{query:{provider:"local"}});if(!c.ok)return;const N=await c.json();Array.isArray(N?.models)&&r(new Map(N.models.map(f=>[f.id,f])))}catch{}},[]);We.useEffect(()=>{u()},[u]);const x=Array.from(i.values()).some(c=>c.downloading);We.useEffect(()=>{if(!x)return;const c=setInterval(()=>{u()},2e3);return()=>clearInterval(c)},[x,u]);const d=async c=>{m(c);try{await ut(`/api/dictation/models/${encodeURIComponent(c)}/download`,{method:"POST"}),await u()}catch{}finally{m(null)}},v=async c=>{m(c);try{await ut(`/api/dictation/models/${encodeURIComponent(c)}`,{method:"DELETE"}),await u()}catch{}finally{m(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:rf.map(c=>{const N=t===c.id,f=i.get(c.id)??null;return s.jsx("div",{className:ve("rounded-lg border border-[var(--interactive-border)] p-3",N&&"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(c.id),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),e(c.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(yr,{checked:N,onChange:()=>e(c.id),ariaLabel:n(c.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:ve("typography-ui-label font-normal",N?"text-foreground":"text-foreground/50"),children:n(c.labelKey)}),c.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(c.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(nl,{value:c.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(nl,{value:c.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:c.size})]}),f?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:f.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:f?.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===c.id,onClick:()=>{v(c.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(R,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):f?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(R,{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 f.downloadProgress=="number"?`${f.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===c.id,onClick:()=>{d(c.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(R,{name:"download",className:"h-4 w-4"})})})]})},c.id)})})},lf=[{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)"}],fr="kokoro-en-v0_19",cf="kokoro-multi-lang-v1_1",df=[{id:0,label:"Maple (af)"},{id:1,label:"Sol (af)"},{id:2,label:"Vale (bf)"},{id:3,label:"Xiaoxiao (zf)"},{id:58,label:"Yunxi (zm)"}],Ma=(t,e)=>`${t}:${e}`,pf=()=>{const[t,e]=We.useState([]),[a,n]=We.useState(null),i=We.useCallback(async()=>{try{const m=await ut("/api/dictation/status",{query:{provider:"local"}});if(!m.ok)return;const u=await m.json();Array.isArray(u?.ttsModels)&&e(u.ttsModels)}catch{}},[]);We.useEffect(()=>{i()},[i]);const r=t.some(m=>m.downloading);We.useEffect(()=>{if(!r)return;const m=setInterval(()=>{i()},2e3);return()=>clearInterval(m)},[r,i]);const l=We.useCallback(async(m,u)=>{n(m);try{const x=u==="POST"?`/api/dictation/models/${m}/download`:`/api/dictation/models/${m}`;await ut(x,{method:u}),await i()}catch{}finally{n(null)}},[i]);return{models:t,requestingId:a,request:l,refresh:i}},mf=t=>{const e=lf.map(a=>({modelId:fr,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===fr||!a.installed)){if(a.id===cf){for(const n of df)e.push({modelId:a.id,speakerId:n.id,label:`${n.label} · Kokoro zh/en`});continue}e.push({modelId:a.id,speakerId:0,label:a.description??a.id})}return e},uf=t=>{const e=gt.c(14),{models:a,requestingId:n,request:i}=t,{t:r}=it();let l,m,u;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==r){u=Symbol.for("react.early_return_sentinel");e:{const d=a.filter(ff);if(d.length===0){u=null;break e}l="flex flex-col";let v;e[7]!==i||e[8]!==n||e[9]!==r?(v=c=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:c.description??c.id}),c.installed?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":r("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!==null,onClick:()=>{i(c.id,"DELETE")},title:r("settings.voice.page.stt.modelDelete"),"aria-label":r("settings.voice.page.stt.modelDelete"),children:s.jsx(R,{name:"delete-bin",className:"h-4 w-4"})})]}):c.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(R,{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 c.downloadProgress=="number"?`${c.downloadProgress}%`:""})]}):s.jsx(H,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{i(c.id,"POST")},title:r("settings.voice.page.stt.modelDownload"),"aria-label":r("settings.voice.page.stt.modelDownload"),children:s.jsx(R,{name:"download",className:"h-4 w-4"})}),c.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:c.downloadError}):null]},c.id),e[7]=i,e[8]=n,e[9]=r,e[10]=v):v=e[10],m=d.map(v)}e[0]=a,e[1]=i,e[2]=n,e[3]=r,e[4]=l,e[5]=m,e[6]=u}else l=e[4],m=e[5],u=e[6];if(u!==Symbol.for("react.early_return_sentinel"))return u;let x;return e[11]!==l||e[12]!==m?(x=s.jsx("div",{className:l,children:m}),e[11]=l,e[12]=m,e[13]=x):x=e[13],x},gf=[{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"}],hf=()=>{const{t}=it(),{isMobile:e}=ja(),a=Ze(G=>G.voiceProvider),n=Ze(G=>G.setVoiceProvider),i=Ze(G=>G.speechRate),r=Ze(G=>G.setSpeechRate),l=Ze(G=>G.speechPitch),m=Ze(G=>G.setSpeechPitch),u=Ze(G=>G.speechVolume),x=Ze(G=>G.setSpeechVolume),d=Ze(G=>G.sayVoice),v=Ze(G=>G.setSayVoice),c=Ze(G=>G.localTtsVoiceId),N=Ze(G=>G.localTtsModelId),f=Ze(G=>G.setLocalTtsModelId),C=pf(),y=We.useMemo(()=>mf(C.models),[C.models]),S=Ze(G=>G.ttsFollowTextLanguage),g=Ze(G=>G.setTtsFollowTextLanguage),T=Ze(G=>G.setLocalTtsVoiceId),{speak:M,stop:P,isPlaying:k,error:h}=sd(),j=We.useCallback(()=>{if(k){P();return}const G=y.find(Be=>Be.modelId===N&&Be.speakerId===c)?.label??String(c);M(t("settings.voice.page.preview.voiceLine",{voiceName:G}),{model:N,speakerId:c,speed:Ze.getState().speechRate})},[k,N,c,y,M,P,t]),F=Ze(G=>G.browserVoice),A=Ze(G=>G.setBrowserVoice),I=Ze(G=>G.openaiVoice),E=Ze(G=>G.setOpenaiVoice),B=Ze(G=>G.openaiApiKey),_=Ze(G=>G.setOpenaiApiKey),w=Ze(G=>G.openaiCompatibleUrl),V=Ze(G=>G.setOpenaiCompatibleUrl),W=Ze(G=>G.openaiCompatibleApiKey),L=Ze(G=>G.setOpenaiCompatibleApiKey),Q=Ze(G=>G.openaiCompatibleVoice),ne=Ze(G=>G.setOpenaiCompatibleVoice),z=Ze(G=>G.openaiCompatibleTtsModel),re=Ze(G=>G.setOpenaiCompatibleTtsModel),$=Ze(G=>G.showMessageTTSButtons),U=Ze(G=>G.ttsInputMode),K=Ze(G=>G.setTtsInputMode),O=Ze(G=>G.sttProvider),Y=Ze(G=>G.setSttProvider),X=Ze(G=>G.sttServerUrl),ee=Ze(G=>G.setSttServerUrl),ge=Ze(G=>G.sttApiKey),de=Ze(G=>G.setSttApiKey),xe=Ze(G=>G.sttModel),ae=Ze(G=>G.setSttModel),te=Ze(G=>G.sttLocalModel),pe=Ze(G=>G.setSttLocalModel),Ie=Ze(G=>G.sttLanguage),Ne=Ze(G=>G.setSttLanguage),Se=Ze(G=>G.setShowMessageTTSButtons),be=Ze(G=>G.dictationEnabled),Oe=Ze(G=>G.setDictationEnabled),[Le,oe]=We.useState(!1),[fe,Me]=We.useState([]),[$e,Ve]=We.useState(!1),[qe,se]=We.useState(null),[ie,we]=We.useState(!1),[ye,Te]=We.useState(!1),[Ue,Pe]=We.useState(null),[je,Ge]=We.useState(!1),[me,Ce]=We.useState(null),[Re,Ye]=We.useState([]),[q,ke]=We.useState(!1);We.useEffect(()=>((async()=>{const Be=await Hi.waitForVoices();Ye(Be)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ye(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ae=We.useMemo(()=>Re.filter(G=>G.lang).sort((G,Be)=>{const st=G.lang.startsWith("en"),rt=Be.lang.startsWith("en");if(st&&!rt)return-1;if(!st&&rt)return 1;const pt=G.lang.localeCompare(Be.lang);return pt!==0?pt:G.name.localeCompare(Be.name)}),[Re]),He=We.useCallback(()=>{if(q){Hi.cancelSpeech(),ke(!1);return}const G=Re.find(pt=>pt.name===F),Be=G?.name??t("settings.voice.page.preview.browserVoiceFallback"),st=t("settings.voice.page.preview.voiceLine",{voiceName:Be});ke(!0);const rt=new SpeechSynthesisUtterance(st);rt.rate=i,rt.pitch=l,rt.volume=u,G&&(rt.voice=G,rt.lang=G.lang),rt.onend=()=>ke(!1),rt.onerror=()=>ke(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(rt)},[F,Re,i,l,u,q,t]);We.useEffect(()=>()=>{q&&Hi.cancelSpeech()},[q]),We.useEffect(()=>{if(!$||a!=="openai"&&a!=="openai-compatible"){we(B.trim().length>0);return}(async()=>{try{const rt=(await(await ut("/api/tts/status")).json()).available,pt=B.trim().length>0;we(rt||pt)}catch{we(B.trim().length>0)}})()},[B,$,a]),We.useEffect(()=>{if(!$){oe(!1),Me([]);return}ut("/api/tts/say/status").then(G=>G.json()).then(G=>{if(oe(G.available),G.voices){const Be=G.voices.filter((st,rt,pt)=>pt.findIndex(St=>St.name===st.name)===rt).sort((st,rt)=>st.name.localeCompare(rt.name));Me(Be)}}).catch(()=>{oe(!1)})},[$]);const at=We.useCallback(async()=>{if(qe){Rs(qe),se(null),Ve(!1);return}Ve(!0);let G=null;try{const Be=await ut("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:d}),voice:d,rate:Math.round(100+(i-.5)*200)})});if(!Be.ok)throw new Error("Preview failed");const st=await Be.blob(),rt=URL.createObjectURL(st);G=new Audio(rt),G.onended=()=>{Rs(G),se(null),Ve(!1)},G.onerror=()=>{Rs(G),se(null),Ve(!1)},se(G),await G.play()}catch{Rs(G),se(null),Ve(!1)}},[d,i,qe,t]);We.useEffect(()=>()=>{Rs(qe)},[qe]);const nt=We.useCallback(async()=>{if(Ue){Rs(Ue),Pe(null),Te(!1);return}Te(!0);let G=null;try{const Be=await ut("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:I}),voice:I,speed:i,apiKey:B||void 0})});if(!Be.ok){const pt=await Be.json().catch(()=>({error:"Unknown error"}));throw new Error(pt.error||`HTTP ${Be.status}`)}const st=await Be.blob(),rt=URL.createObjectURL(st);G=new Audio(rt),G.onended=()=>{Rs(G),Pe(null),Te(!1)},G.onerror=()=>{Rs(G),Pe(null),Te(!1)},Pe(G),await G.play()}catch{Rs(G),Pe(null),Te(!1)}},[I,i,Ue,B,t]);We.useEffect(()=>()=>{Rs(Ue)},[Ue]);const dt=We.useCallback(async()=>{if(me){Rs(me),Ce(null),Ge(!1);return}if(!w.trim())return;Ge(!0);let G=null;try{const Be=await ut("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:Q,model:z||void 0,speed:i,baseURL:w,apiKey:W||void 0})});if(!Be.ok){const pt=await Be.json().catch(()=>({error:"Unknown error"}));throw new Error(pt.error||`HTTP ${Be.status}`)}const st=await Be.blob(),rt=URL.createObjectURL(st);G=new Audio(rt),G.onended=()=>{Rs(G),Ce(null),Ge(!1)},G.onerror=()=>{Rs(G),Ce(null),Ge(!1)},Ce(G),await G.play()}catch{Rs(G),Ce(null),Ge(!1)}},[w,Q,z,W,i,me,t]);We.useEffect(()=>()=>{Rs(me)},[me]);const xt="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(_e,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(ht,{checked:$,onChange:Se,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),$&&s.jsxs(s.Fragment,{children:[s.jsx(Ps,{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(Qs,{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")},...Le?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(R,{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:ve(Et,!ie&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ve(Vn,!ie&&"text-[var(--status-error)]/80"),children:t(ie&&!B?"settings.voice.page.field.apiKeyHintUsingConfig":ie?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:ve("relative",Fs),children:[s.jsx("input",{type:"password",value:B,onChange:G=>_(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"}),B&&s.jsx("button",{type:"button",onClick:()=>_(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{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:ve(Et,!w.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:ve("relative",Fs),children:[s.jsx("input",{type:"text",value:w,onChange:G=>V(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"}),w&&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(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:Vn,children:"Optional"}),s.jsxs("div",{className:ve("relative",Fs),children:[s.jsx("input",{type:"password",value:W,onChange:G=>L(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"}),W&&s.jsx("button",{type:"button",onClick:()=>L(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ve("relative",Fs),children:s.jsx("input",{type:"text",value:z,onChange:G=>re(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:Et,children:t("settings.voice.page.field.voice")}),s.jsx(Jt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:ve("flex items-center gap-2",Fs),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:Q,onChange:G=>ne(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:dt,title:t("settings.voice.page.actions.preview"),disabled:!w.trim(),children:je?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(uf,{...C}),(a==="local"||a==="say")&&s.jsx(ht,{checked:S,onChange:g,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Lt,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(It,{value:Ma(N,c),onValueChange:G=>{const Be=y.find(st=>Ma(st.modelId,st.speakerId)===G);Be&&(f(Be.modelId),T(Be.speakerId))},children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:G=>y.find(Be=>Ma(Be.modelId,Be.speakerId)===G)?.label??G})}),s.jsx(At,{children:y.map(G=>s.jsx(ot,{value:Ma(G.modelId,G.speakerId),children:G.label},Ma(G.modelId,G.speakerId)))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:j,title:t("settings.voice.page.actions.preview"),children:k?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})}),h?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:h}):null]}),a==="openai"&&ie&&s.jsxs(s.Fragment,{children:[s.jsxs(It,{value:I,onValueChange:E,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:gf.map(G=>s.jsx(ot,{value:G.value,children:G.label},G.value))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:nt,title:t("settings.voice.page.actions.preview"),children:ye?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:Vn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&Le&&fe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(It,{value:d,onValueChange:v,children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:fe.map(G=>s.jsx(ot,{value:G.name,children:G.name},G.name))})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:at,title:t("settings.voice.page.actions.preview"),children:$e?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Ae.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(It,{value:F||"$auto",onValueChange:G=>A(G==="$auto"?"":G),children:[s.jsx(Pt,{size:Ft,className:nn,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"$auto",children:t("settings.voice.page.field.auto")}),Ae.map(G=>s.jsxs(ot,{value:G.name,children:[G.name," (",G.lang,")"]},G.name))]})]}),s.jsx(H,{size:"xs",variant:"ghost",onClick:He,title:t("settings.voice.page.actions.preview"),children:q?s.jsx(R,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(R,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Lt,{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:xt}),s.jsx(xs,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:ve(Cs,"tabular-nums")})]}),s.jsxs(Lt,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:G=>m(Number(G.target.value)),className:xt}),s.jsx(xs,{value:l,onValueChange:m,min:.5,max:2,step:.1,className:ve(Cs,"tabular-nums")})]}),s.jsxs(Lt,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:u,onChange:G=>x(Number(G.target.value)),className:xt}),e?s.jsx(xs,{value:Math.round(u*100),onValueChange:G=>x(G/100),min:0,max:100,step:10,className:ve(Cs,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(u*100),"%"]})]}),s.jsx(Ps,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Qs,{value:U,onChange:K,"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(_e,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(ht,{checked:be,onChange:Oe,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),be&&s.jsxs(s.Fragment,{children:[s.jsx(Ps,{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(Qs,{value:O,onChange:Y,"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")}]})}),O==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx(of,{selectedModelId:te,onSelect:pe})]}),O==="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:ve(Et,!X.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:ve("relative",Fs),children:[s.jsx("input",{type:"text",value:X,onChange:G=>ee(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"}),X&&s.jsx("button",{type:"button",onClick:()=>ee(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:Vn,children:"Optional"}),s.jsxs("div",{className:ve("relative",Fs),children:[s.jsx("input",{type:"password",value:ge,onChange:G=>de(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"}),ge&&s.jsx("button",{type:"button",onClick:()=>de(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(R,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ve("relative",Fs),children:s.jsx("input",{type:"text",value:xe,onChange:G=>ae(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:Et,children:t("settings.voice.page.field.language")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:Ie,onChange:G=>Ne(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"})})]})]})]})]})]})};function ff(t){return t.id===fr||t.installed||t.downloading}const fi=[{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}],xi=[{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}],xf="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",bf="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",nr=[{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"}],vf=[".yml",".yaml",".json"],yf="settings.openchamber.tunnel.error.invalidConfigExtension",Ra=t=>{const e=t.trim().toLowerCase();return vf.some(a=>e.endsWith(a))},jf=t=>t==="ngrok"?"ngrok":"cloudflared",sc=()=>{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"},wf=(t,e=sc())=>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/cloudflare-tunnel/downloads/",ar=(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():jf(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():sc(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():wf(a,i);return{provider:a,dependency:n,installCommand:r}},nc=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,al=t=>{const e=gt.c(11),{provider:a}=t;let n;e[0]!==a?(n=nc(a),e[0]=a,e[1]=n):n=e[1];const i=n,m=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let u;e[2]!==m?(u=ve("size-4 shrink-0",m),e[2]=m,e[3]=u):u=e[3];let x;e[4]!==u?(x=s.jsx(R,{name:"cloud",className:u}),e[4]=u,e[5]=x):x=e[5];let d;e[6]!==i?(d=s.jsx("span",{children:i}),e[6]=i,e[7]=d):d=e[7];let v;return e[8]!==x||e[9]!==d?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[x,d]}),e[8]=x,e[9]=d,e[10]=v):v=e[10],v},Pn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",xr=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,il=(t,e,a)=>{const n=xr(t,e,a);return t.find(i=>i.value===n)?.label||n},rl=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`},kf=(t,e)=>Cl(t,e,{hour:"2-digit",precision:"second"}),ki=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()}},Nf=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():"",m=typeof r.name=="string"?r.name.trim():"",u=ki(typeof r.hostname=="string"?r.hostname:"");!l||!m||!u||e.has(l)||a.has(u)||(e.add(l),a.add(u),n.push({id:l,name:m,hostname:u}))}return n},Sf=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Cf=()=>{const{t}=it(),e=le(J=>J.timeFormatPreference),a=o.useCallback(J=>t(J),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[m,u]=o.useState(null),[x,d]=o.useState(null),[v,c]=o.useState(null),[N,f]=o.useState(null),[C,y]=o.useState(!1),[S,g]=o.useState(!1),[T,M]=o.useState(!1),[P,k]=o.useState("cloudflare"),[h,j]=o.useState(()=>ar("cloudflare")),[F,A]=o.useState([]),[I,E]=o.useState("quick"),[B,_]=o.useState(null),[w,V]=o.useState([]),[W,L]=o.useState({}),[Q,ne]=o.useState(""),[z,re]=o.useState({}),[$,U]=o.useState(new Set),[K,O]=o.useState(!1),[Y,X]=o.useState(""),[ee,ge]=o.useState(""),[de,xe]=o.useState(""),[ae,te]=o.useState(1800*1e3),[pe,Ie]=o.useState(480*60*1e3),[Ne,Se]=o.useState(""),[be,Oe]=o.useState([]),[Le,oe]=o.useState(()=>Date.now()),[fe,Me]=o.useState(null),$e=t(yf),Ve=o.useRef(null),qe=o.useMemo(()=>B?!Ra(B):!1,[B]),se=o.useMemo(()=>w.find(J=>J.id===Q)||w[0]||null,[w,Q]),ie=o.useMemo(()=>be.map(J=>{const he=J.expiresAt<=Le,Fe=J.status==="active"&&!he,De=Fe?rl(J.expiresAt-Le):J.inactiveReason==="expired"||he?"expired":"inactive",lt=De==="expired"?t("settings.openchamber.tunnel.state.expired"):J.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),ct=Pn(J.mode);return{...J,isActive:Fe,mode:ct,remainingTextForSession:De,inactiveLabel:lt}}),[Le,be,t]),we=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Le:!1,[Le,r?.bootstrapExpiresAt,r?.connectUrl]),ye=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:m===I,[m,n,r,I]),Te=o.useMemo(()=>!r||n!=="active"||!m?!1:m!==I,[m,n,r,I]),Ue=o.useMemo(()=>{if(typeof fe=="number"&&Number.isFinite(fe)&&fe>0)return fe;if(typeof window>"u")return null;const he=Ba()||window.location.href;let Fe=0;try{Fe=Number(new URL(he).port)}catch{Fe=Number(window.location.port)}return Number.isFinite(Fe)&&Fe>0?Fe:null},[fe]),Pe=o.useMemo(()=>F.find(J=>J.provider===P)??null,[F,P]),je=o.useMemo(()=>{const J=new Set(Pe?.modes?.map(he=>he.key).filter(he=>he==="quick"||he==="managed-remote"||he==="managed-local"));return J.size===0?nr:nr.filter(he=>J.has(he.value))},[Pe]),Ge=o.useMemo(()=>je.some(J=>J.value==="managed-remote"||J.value==="managed-local"),[je]),me=o.useMemo(()=>h.provider===P?h:ar(P),[h,P]),Ce=o.useCallback(async J=>{await Dn(J)},[]),Re=o.useCallback((J,he)=>(j(ar(he,J)),J.available===!0),[]),Ye=o.useCallback(async(J,he)=>{try{const Fe=await ut("/api/openchamber/tunnel/check",{query:{provider:J},...he?{signal:he}:{}});if(!Fe.ok)return null;const De=await Fe.json();if(he?.aborted)return null;const lt=Re(De,J);return i(ct=>ct==="checking"||ct==="starting"||ct==="active"||ct==="stopping"?ct:lt?"idle":"not-available"),lt}catch{return null}},[Re]),q=o.useCallback(async J=>{try{const[he,Fe,De,lt]=await Promise.all([ut("/api/openchamber/tunnel/check",{signal:J}),ut("/api/openchamber/tunnel/status",{signal:J}),ut("/api/config/settings",{signal:J,headers:{Accept:"application/json"}}),ut("/api/openchamber/tunnel/providers",{signal:J})]),ct=await he.json(),Qe=await Fe.json(),kt=De.ok?await De.json():{},bs=lt.ok?await lt.json():{},Xt=Qe.ttlConfig?.bootstrapTtlMs??(kt?.tunnelBootstrapTtlMs===null?null:typeof kt?.tunnelBootstrapTtlMs=="number"?kt.tunnelBootstrapTtlMs:1800*1e3),Ls=typeof Qe.ttlConfig?.sessionTtlMs=="number"?Qe.ttlConfig.sessionTtlMs:typeof kt?.tunnelSessionTtlMs=="number"?kt.tunnelSessionTtlMs:480*60*1e3,Gt=Pn(Qe.mode??kt?.tunnelMode),is=typeof kt?.tunnelProvider=="string"&&kt.tunnelProvider.trim().length>0?kt.tunnelProvider.trim().toLowerCase():"cloudflare",Ht=typeof kt?.managedLocalTunnelConfigPath=="string"&&kt.managedLocalTunnelConfigPath.trim()||null,vs=Re(ct,is),us=Nf(Qe?.managedRemoteTunnelPresets),gs=typeof Qe.managedRemoteTunnelHostname=="string"?Qe.managedRemoteTunnelHostname:"",ds=us.length>0?us:gs?[{id:`legacy-${ki(gs)}`,name:gs,hostname:ki(gs)}]:[],Ts=ds[0]?.id||"";if(te(Xt),Ie(Ls),k(is),A(Array.isArray(bs?.providers)?bs.providers:[]),E(Gt),_(Ht),V(ds),ne(Ts),Oe(Array.isArray(Qe.activeSessions)?Qe.activeSessions:[]),u(Qe.activeTunnelMode?Pn(Qe.activeTunnelMode):Qe.active&&Qe.mode?Pn(Qe.mode):null),U(new Set(Array.isArray(Qe.managedRemoteTunnelTokenPresetIds)?Qe.managedRemoteTunnelTokenPresetIds:[])),Me(typeof Qe.localPort=="number"?Qe.localPort:null),Qe.active&&Qe.url){l({url:Qe.url,connectUrl:null,bootstrapExpiresAt:typeof Qe.bootstrapExpiresAt=="number"?Qe.bootstrapExpiresAt:null}),i("active");return}i(vs?"idle":"not-available")}catch{J.aborted||(i("error"),c(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[Re,t]);o.useEffect(()=>{const J=new AbortController;return q(J.signal),()=>J.abort()},[q]),o.useEffect(()=>{if(!r?.connectUrl){d(null);return}let J=!1;return Ol.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(he=>{J||d(he)}).catch(()=>{J||d(null)}),()=>{J=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){Se(t("settings.openchamber.tunnel.state.noExpiry"));return}let J=null,he=Date.now();const Fe=()=>{const ct=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;ct<=0?Se(t("settings.openchamber.tunnel.state.expired")):Se(rl(ct))},De=()=>{const ct=Date.now();ct-he>=1e3&&(Fe(),he=ct),J=requestAnimationFrame(De)};Fe(),(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(De));const lt=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(De):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),J!==null&&cancelAnimationFrame(J)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let J=null,he=Date.now();const Fe=()=>{const lt=Date.now();lt-he>=1e3&&(oe(lt),he=lt),J=requestAnimationFrame(Fe)};(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(Fe));const De=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(Fe):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",De),()=>{document.removeEventListener("visibilitychange",De),J!==null&&cancelAnimationFrame(J)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let J=!1;const he=async()=>{try{const De=await ut("/api/openchamber/tunnel/status");if(!De.ok||J)return;const lt=await De.json();if(J)return;Oe(Array.isArray(lt.activeSessions)?lt.activeSessions:[]),U(new Set(Array.isArray(lt.managedRemoteTunnelTokenPresetIds)?lt.managedRemoteTunnelTokenPresetIds:[])),Me(typeof lt.localPort=="number"?lt.localPort:null)}catch{}},Fe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||he()},5e3);return()=>{J=!0,window.clearInterval(Fe)}},[n]);const ke=o.useCallback(async J=>{M(!0);try{await vt(J),Object.prototype.hasOwnProperty.call(J,"tunnelMode")&&J.tunnelMode&&E(J.tunnelMode),Object.prototype.hasOwnProperty.call(J,"tunnelProvider")&&typeof J.tunnelProvider=="string"&&k(J.tunnelProvider),Object.prototype.hasOwnProperty.call(J,"managedLocalTunnelConfigPath")&&_(J.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(J,"managedRemoteTunnelPresets")&&J.managedRemoteTunnelPresets&&V(J.managedRemoteTunnelPresets)}catch{D.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{M(!1)}},[t]),Ae=o.useCallback(async(J,he)=>{g(!0);try{await vt({tunnelBootstrapTtlMs:J,tunnelSessionTtlMs:he})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),He=o.useCallback(async J=>{const he=J.token.trim();if(he)try{const Fe={...z,[J.presetId]:he};await vt({managedRemoteTunnelPresetTokens:Fe}),U(De=>{const lt=new Set(De);return lt.add(J.presetId),lt})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[z,t]),at=o.useCallback(async J=>{f(null),c(null);const he=F.find(De=>De.provider===J),Fe=he?.modes?.some(De=>De.key===I)?I:Pn(he?.modes?.[0]?.key);await ke({tunnelProvider:J,tunnelMode:Fe}),Ye(J)},[F,Ye,ke,I]),nt=o.useCallback(async()=>{const J=await El({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(J.success&&typeof J.path=="string"&&J.path.trim().length>0){const he=J.path.trim();if(!Ra(he)){D.error($e);return}_(he),await ke({managedLocalTunnelConfigPath:he});return}Ve.current?.click()},[$e,ke]),dt=o.useCallback(J=>{const he=J.trim();_(he.length>0?he:null)},[]),xt=o.useCallback(async()=>{if(B&&!Ra(B)){D.error($e);return}await ke({managedLocalTunnelConfigPath:B})},[$e,B,ke]),G=o.useCallback(async()=>{_(null),await ke({managedLocalTunnelConfigPath:null})},[ke]),Be=o.useCallback(async J=>{const he=J.target.files?.[0];if(!he)return;const Fe=he.name.trim();if(Fe.length!==0){if(!Ra(Fe)){D.error($e);return}_(Fe),await ke({managedLocalTunnelConfigPath:Fe}),J.target.value=""}},[$e,ke]),st=o.useCallback(async()=>{if(c(null),f(null),I==="managed-local"&&B&&!Ra(B)){c($e),D.error($e);return}i("starting");try{let J="",he="";if(I==="managed-remote"){if(!se){i("idle"),f(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),D.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}J=se.hostname,he=(z[se.id]||"").trim(),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:w})}const Fe=await ut("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:P,mode:I,...I==="managed-remote"&&se?{managedRemoteTunnelPresetId:se.id,managedRemoteTunnelPresetName:se.name}:{},...I==="managed-remote"&&J?{managedRemoteTunnelHostname:J}:{},...I==="managed-remote"&&he?{managedRemoteTunnelToken:he}:{},...I==="managed-local"&&B?{configPath:B}:{}})}),De=await Fe.json();if(!Fe.ok||!De.ok){if(I==="managed-remote"&&typeof De.error=="string"&&De.error.includes("Managed remote tunnel token is required")){i("idle"),f(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),D.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),c(De.error||t("settings.openchamber.tunnel.toast.startFailed")),D.error(De.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const lt=typeof De.url=="string"?De.url:"";if(!lt){i("error"),c(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),D.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:lt,connectUrl:typeof De.connectUrl=="string"?De.connectUrl:null,bootstrapExpiresAt:typeof De.bootstrapExpiresAt=="number"?De.bootstrapExpiresAt:null}),u(De.activeTunnelMode?Pn(De.activeTunnelMode):De.mode?Pn(De.mode):I),Oe(Array.isArray(De.activeSessions)?De.activeSessions:[]),Array.isArray(De.managedRemoteTunnelTokenPresetIds)&&U(new Set(De.managedRemoteTunnelTokenPresetIds)),typeof De.localPort=="number"&&Me(De.localPort),typeof De.mode=="string"&&E(Pn(De.mode)),i("active"),De.replacedTunnel){const ct=typeof De.revokedBootstrapCount=="number"?De.revokedBootstrapCount:0,Qe=typeof De.invalidatedSessionCount=="number"?De.invalidatedSessionCount:0;ct===1&&Qe===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):ct===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Qe})):Qe===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:ct})):D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:ct,invalidatedSessionCount:Qe}))}else D.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),c(t("settings.openchamber.tunnel.toast.startFailed")),D.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[$e,w,ke,se,z,t,P,I,B]),rt=o.useCallback(async()=>{i("stopping");try{await ut("/api/openchamber/tunnel/stop",{method:"POST"});const J=await ut("/api/openchamber/tunnel/status");if(J.ok){const he=await J.json();Oe(Array.isArray(he.activeSessions)?he.activeSessions:[]),U(new Set(Array.isArray(he.managedRemoteTunnelTokenPresetIds)?he.managedRemoteTunnelTokenPresetIds:[])),Me(typeof he.localPort=="number"?he.localPort:null)}l(null),u(null),d(null),i("idle"),D.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),c(t("settings.openchamber.tunnel.toast.stopFailed")),D.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),pt=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),y(!0),D.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>y(!1),2e3)}catch{D.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),St=o.useCallback(async J=>{const he=fi.find(Fe=>Fe.value===J);he&&(te(he.ms),await Ae(he.ms,pe))},[Ae,pe]),et=o.useCallback(async J=>{const he=xi.find(Fe=>Fe.value===J);!he||he.ms===null||(Ie(he.ms),await Ae(ae,he.ms))},[ae,Ae]),Xe=o.useCallback(async J=>{f(null),c(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await ke({tunnelMode:J,managedRemoteTunnelPresets:w})},[w,ke,n]),ft=o.useCallback(async(J,he)=>{try{await vt({managedRemoteTunnelPresets:he})}catch{D.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),ze=o.useCallback(J=>{const he=w.find(Fe=>Fe.id===J);he&&(ne(he.id),f(null),ft(he,w))},[w,ft]),wt=o.useCallback(async()=>{const J=Y.trim(),he=ki(ee),Fe=de.trim();if(!J){D.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!he){D.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Fe){D.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(w.some(ct=>ct.hostname===he)){D.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const De={id:Sf(),name:J,hostname:he},lt=[...w,De];V(lt),ne(De.id),L(ct=>({...ct,[De.id]:!0})),re(ct=>({...ct,[De.id]:Fe})),f(null),O(!1),X(""),ge(""),xe(""),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:lt,managedRemoteTunnelPresetTokens:{...z,[De.id]:Fe}}),await He({presetId:De.id,presetName:De.name,hostname:De.hostname,token:Fe}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[w,ee,Y,de,He,ke,z,t]),Ee=o.useCallback(async J=>{const he=w.find(Qe=>Qe.id===J);if(!he)return;const Fe=w.filter(Qe=>Qe.id!==he.id),De=Fe[0]?.id||"",lt=Q===he.id?De:Q,ct=Object.fromEntries(Object.entries(z).filter(([Qe,kt])=>Qe!==he.id&&kt.trim().length>0));V(Fe),ne(lt),L(Qe=>{const kt={...Qe};return delete kt[he.id],kt}),re(Qe=>{const kt={...Qe};return delete kt[he.id],kt}),U(Qe=>{const kt=new Set(Qe);return kt.delete(he.id),kt}),f(null),await ke({managedRemoteTunnelPresets:Fe,managedRemoteTunnelPresetTokens:ct}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[w,ke,Q,z,t]),jt="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(_e,{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:[ie.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(R,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Vr,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ie.map(J=>{const he=J.mode==="quick",Fe=J.mode==="managed-remote",De=he?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Fe?"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)]",lt=J.isActive?he?"text-[var(--status-warning)]":Fe?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",ct=t(he?"settings.openchamber.tunnel.badge.quick":Fe?"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(R,{name:"checkbox-blank-circle-fill",className:ve("size-2.5 shrink-0",lt)}),s.jsx("span",{className:ve("typography-micro rounded border px-1.5 py-0.5 uppercase",De),children:ct}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:kf(J.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:J.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:J.remainingTextForSession}):J.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:J.inactiveLabel})})]},J.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(R,{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:Vr,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:me.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:me.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:Et,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(It,{value:P,onValueChange:J=>{at(J)},disabled:T||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:Ft,className:"max-w-[16rem]",children:s.jsx(Rt,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:nc(P)})}),s.jsxs(At,{children:[F.length>0?F.map(J=>s.jsx(ot,{value:J.provider,children:s.jsx(al,{provider:J.provider})},J.provider)):s.jsx(ot,{value:"cloudflare",children:s.jsx(al,{provider:"cloudflare"})}),s.jsx(ot,{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:Et,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:je.map(J=>s.jsxs(jr,{children:[s.jsx(wr,{asChild:!0,children:s.jsx(H,{variant:"chip",size:"xs","aria-pressed":I===J.value,className:"!font-normal",onClick:()=>{Xe(J.value)},disabled:T||n==="starting"||n==="stopping",children:a(J.labelKey)})}),s.jsx(yl,{sideOffset:8,className:"max-w-xs",children:a(J.tooltipKey)})]},J.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:ve(Et,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(It,{value:xr(fi,ae,"1800000"),onValueChange:J=>{St(J)},disabled:S||T||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:Ft,className:"max-w-[11rem] min-w-0",children:s.jsx(Rt,{className:"truncate",children:il(fi,ae,"1800000")})}),s.jsx(At,{children:fi.map(J=>s.jsx(ot,{value:J.value,children:J.label},J.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ve(Et,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(It,{value:xr(xi,pe,"28800000"),onValueChange:J=>{et(J)},disabled:S||T||n==="starting"||n==="stopping",children:[s.jsx(Pt,{size:Ft,className:"max-w-[11rem] min-w-0",children:s.jsx(Rt,{className:"truncate",children:il(xi,pe,"28800000")})}),s.jsx(At,{children:xi.map(J=>s.jsx(ot,{value:J.value,children:J.label},J.value))})]})]})]}),I==="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(R,{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")}),Ge&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),I==="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 Ue=="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:",Ue]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Ys,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>O(J=>!J),disabled:n==="starting"||n==="stopping"||T,children:[s.jsx(R,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),w.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:w.map((J,he)=>{const Fe=z[J.id]||"",De=$.has(J.id),lt=W[J.id]??!1;return s.jsx("div",{className:ve(he<w.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(Mn,{open:lt,onOpenChange:ct=>{L(Qe=>({...Qe,[J.id]:ct})),ct&&ze(J.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Rn,{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"||T,children:[lt?s.jsx(R,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(R,{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:J.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:J.name}),onClick:()=>{Ee(J.id)},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(R,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Ln,{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:J.hostname})]}),s.jsx(Je,{type:"password",value:Fe,onChange:ct=>{const Qe=ct.target.value;f(null),re(kt=>({...kt,[J.id]:Qe}))},onBlur:ct=>{const Qe=ct.currentTarget.value.trim();Qe&&He({presetId:J.id,presetName:J.name,hostname:J.hostname,token:Qe})},placeholder:t(De?"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"||Fe.trim().length===0,onClick:()=>{He({presetId:J.id,presetName:J.name,hostname:J.hostname,token:Fe})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},J.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),K&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Je,{value:Y,onChange:J=>X(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),s.jsx(Je,{value:ee,onChange:J=>ge(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),s.jsx(Je,{type:"password",value:de,onChange:J=>xe(J.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),typeof Ue=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ue]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{wt()},disabled:T||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(H,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{O(!1),X(""),ge(""),xe("")},disabled:T||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(Jt,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!se&&N&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:N})]}),I==="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:Et,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Ve,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:J=>{Be(J)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:B||"",onChange:J=>{dt(J.target.value)},onBlur:()=>{xt()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||T}),s.jsx(H,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{nt()},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(R,{name:"folder",className:"size-3.5"})}),B&&s.jsx(H,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{G()},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(R,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(B?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),qe&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:$e})]})}),!ye&&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(R,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[I==="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:()=>{Ce(xf)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(R,{name:"external-link",className:"size-3.5"})]})]}),I==="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:()=>{Ce(bf)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(R,{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(nr.find(J=>J.value===I)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),I==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(It,{value:Q||(w[0]?.id??""),onValueChange:J=>{ze(J)},disabled:T||n==="starting"||n==="stopping"||w.length<=1,children:[s.jsx(Pt,{size:Ft,children:s.jsx(Rt,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:se?.name})}),s.jsx(At,{fitContent:!0,children:w.map(J=>s.jsx(ot,{value:J.id,children:J.name},J.id))})]})]}),Te&&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(R,{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:st,disabled:n==="starting"||T||I==="managed-remote"&&!se||I==="managed-local"&&qe,className:ve(jt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),ye&&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})]}),we&&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:pt,className:"shrink-0 gap-1.5",children:[C?s.jsx(R,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(R,{name:"file-copy",className:"size-3.5"}),t(C?"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?Ne: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:[x?s.jsx("img",{src:x,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:st,disabled:n==="stopping"||T||I==="managed-local"&&qe,className:jt,children:[s.jsx(R,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(H,{size:"sm",variant:"ghost",onClick:rt,disabled:n==="stopping"||T,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(R,{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:st,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},ac=()=>{const{t}=it(),[e,a]=We.useState(""),[n,i]=We.useState(!0),[r,l]=We.useState(!1),m=le(c=>c.showOpenCodeUpdateNotifications),u=le(c=>c.setShowOpenCodeUpdateNotifications);We.useEffect(()=>{let c=!1;return(async()=>{try{const N=await ut("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const f=await N.json().catch(()=>null);if(c||!f)return;const C=typeof f.opencodeBinary=="string"?f.opencodeBinary.trim():"";a(C)}catch{}finally{c||i(!1)}})(),()=>{c=!0}},[]);const x=We.useCallback(async()=>{if(!(typeof window>"u")&&as())try{const c=await El();c.success&&c.path&&c.path.trim().length>0&&a(c.path.trim())}catch{}},[]),d=We.useCallback(async()=>{l(!0);try{const c=e.trim(),N=c.length>=2&&(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))?c.slice(1,-1).trim():c;await vt({opencodeBinary:N}),Gn("cli",{id:"opencode-binary"}),D.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),v=We.useCallback(c=>{u(c),vt({showOpenCodeUpdateNotifications:c})},[u]);return s.jsx(_e,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Lt,{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(Je,{value:e,onChange:c=>a(c.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:x,disabled:n||r||!as(),className:hs,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(R,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Va,{className:fs,children:[!Dl()&&s.jsx(ht,{settingsItem:"sessions.opencode-update-notifications",checked:m,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:d,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},ic=()=>{const t=gt.c(44),{t:e}=it(),a=le(If),n=le(Pf),i=le(Af),r=le(Tf),l=le(Ef),m=le(Df),u=le(Mf);let x;t[0]!==n?(x=I=>{n(I),vt({agentControlToolEnabled:I}),Gn("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=x):x=t[1];const d=x;let v;t[2]!==r?(v=I=>{r(I),vt({agentWebToolEnabled:I}),Gn("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=v):v=t[3];const c=v;let N;t[4]!==u?(N=I=>{u(I),vt({agentMemoryToolEnabled:I}).finally(()=>{I&&nd.getState().refresh()}),Gn("cli",{id:"agent-memory-tool"})},t[4]=u,t[5]=N):N=t[5];const f=N;let C;t[6]!==e?(C=e("settings.openchamber.tools.title"),t[6]=e,t[7]=C):C=t[7];let y;t[8]!==e?(y=e("settings.openchamber.tools.field.agentControlTool"),t[8]=e,t[9]=y):y=t[9];let S;t[10]!==e?(S=e("settings.openchamber.tools.field.agentControlToolAria"),t[10]=e,t[11]=S):S=t[11];let g;t[12]!==e?(g=e("settings.openchamber.tools.field.agentControlToolInfo"),t[12]=e,t[13]=g):g=t[13];let T;t[14]!==a||t[15]!==d||t[16]!==y||t[17]!==S||t[18]!==g?(T=s.jsx(ht,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:d,label:y,ariaLabel:S,info:g}),t[14]=a,t[15]=d,t[16]=y,t[17]=S,t[18]=g,t[19]=T):T=t[19];let M;t[20]!==e?(M=e("settings.openchamber.tools.field.agentWebTool"),t[20]=e,t[21]=M):M=t[21];let P;t[22]!==e?(P=e("settings.openchamber.tools.field.agentWebToolAria"),t[22]=e,t[23]=P):P=t[23];let k;t[24]!==e?(k=e("settings.openchamber.tools.field.agentWebToolInfo"),t[24]=e,t[25]=k):k=t[25];let h;t[26]!==i||t[27]!==c||t[28]!==k||t[29]!==M||t[30]!==P?(h=s.jsx(ht,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:c,label:M,ariaLabel:P,info:k}),t[26]=i,t[27]=c,t[28]=k,t[29]=M,t[30]=P,t[31]=h):h=t[31];let j;t[32]!==m||t[33]!==l||t[34]!==f||t[35]!==e?(j=m?s.jsx(ht,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:f,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[32]=m,t[33]=l,t[34]=f,t[35]=e,t[36]=j):j=t[36];let F;t[37]!==h||t[38]!==j||t[39]!==T?(F=s.jsxs("div",{className:fs,children:[T,h,j]}),t[37]=h,t[38]=j,t[39]=T,t[40]=F):F=t[40];let A;return t[41]!==F||t[42]!==C?(A=s.jsx(_e,{title:C,children:F}),t[41]=F,t[42]=C,t[43]=A):A=t[43],A};function If(t){return t.agentControlToolEnabled}function Pf(t){return t.setAgentControlToolEnabled}function Af(t){return t.agentWebToolEnabled}function Tf(t){return t.setAgentWebToolEnabled}function Ef(t){return t.agentMemoryToolEnabled}function Df(t){return t.agentMemoryFeatureAvailable}function Mf(t){return t.setAgentMemoryToolEnabled}const rc=()=>{const{t}=it(),e=as()&&Ha(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=We.useState(!1),[r,l]=We.useState(!1),[m,u]=We.useState(""),[x,d]=We.useState(""),[v,c]=We.useState(!1),[N,f]=We.useState(!1),[C,y]=We.useState(null),[S,g]=We.useState(!0),[T,M]=We.useState(!1),[P,k]=We.useState(!1),[h,j]=We.useState(!1),[F,A]=We.useState(!1),[I,E]=We.useState(!1),[B,_]=We.useState(!1),[w,V]=We.useState(!1),[W,L]=We.useState(!0),[Q,ne]=We.useState(!0),[z,re]=We.useState(!1),[$,U]=We.useState(!1),[K,O]=We.useState(!1),[Y,X]=We.useState(null),[ee,ge]=We.useState(null);We.useEffect(()=>{if(!e){g(!1);return}let oe=!1;return(async()=>{try{const fe=await ut("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!fe.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const Me=await fe.json().catch(()=>null);if(oe)return;const $e=Me?.desktopLanAccessEnabled===!0,Ve=typeof Me?.desktopUiPassword=="string"?Me.desktopUiPassword:"";i($e),l($e),u(Ve),d(Ve),f(Me?.desktopLanAccessActive===!0),y(typeof Me?.desktopLanAccessBlockedReason=="string"?Me.desktopLanAccessBlockedReason:null);const qe=Me?.desktopMacMenuBarEnabled!==!1;L(qe),ne(qe),X(null)}catch(fe){oe||X(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{oe||g(!1)}})(),()=>{oe=!0}},[e,t]),We.useEffect(()=>{if(!e){k(!1);return}let oe=!1;return(async()=>{const fe=await Od();oe||(k(fe?.supported===!0),j(fe?.enabled===!0))})(),()=>{oe=!0}},[e]),We.useEffect(()=>{if(!e){E(!1);return}let oe=!1;return(async()=>{const fe=await Fd();oe||(E(fe?.supported===!0),_(fe?.enabled===!0))})(),()=>{oe=!0}},[e]),We.useEffect(()=>{if(!e){re(!1);return}let oe=!1;return(async()=>{const fe=await Kd();oe||(re(fe?.supported===!0),U(fe?.enabled===!0))})(),()=>{oe=!0}},[e]),We.useEffect(()=>{if(!e||!r){ge(null);return}let oe=!1;return(async()=>{const fe=await Al();oe||ge(fe)})(),()=>{oe=!0}},[r,e]);const de=r!==n||x!==m||Q!==W,xe=We.useMemo(()=>{if(typeof window>"u")return null;const fe=Ba()||window.location.href;let Me=0;try{Me=Number(new URL(fe).port)}catch{Me=Number(window.location.port)}return Number.isFinite(Me)&&Me>0?Me:null},[]),ae=r&&N&&ee&&xe?`http://${ee}:${xe}`:null,te=r&&!x.trim(),pe=n&&!N&&C==="missing-password",Ie=S||T||!de||te,Ne=We.useCallback(oe=>{d(oe),oe.trim()||l(!1)},[]),Se=We.useCallback(async()=>{if(!P||F)return;const oe=!h;j(oe),A(!0),X(null);try{const fe=await zd(oe);if(!fe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));j(fe.enabled)}catch(fe){j(!oe),X(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{A(!1)}},[F,h,P,t]),be=We.useCallback(async()=>{if(!I||w)return;const oe=!B;_(oe),V(!0),X(null);try{const fe=await Ud(oe);if(!fe)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!fe.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));_(fe.enabled)}catch(fe){_(!oe),X(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{V(!1)}},[w,B,I,t]),Oe=We.useCallback(async()=>{if(!z||K)return;const oe=!$;U(oe),O(!0),X(null);try{const fe=await _d(oe);if(!fe?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));U(fe.enabled)}catch(fe){U(!oe),X(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{O(!1)}},[K,$,z,t]),Le=We.useCallback(async()=>{if(de){M(!0),X(null);try{if(!(await ut("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:x,desktopMacMenuBarEnabled:Q})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(r),u(x),L(Q),!await $d())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(oe){X(oe instanceof Error?oe.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),M(!1)}}},[Q,x,r,de,t]);return e?s.jsx(_e,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[P||a||I||z?s.jsxs("div",{className:fs,children:[P?s.jsx(ht,{settingsItem:"sessions.desktop-launch-at-login",checked:h,onChange:oe=>{oe!==h&&Se()},disabled:F,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(ht,{settingsItem:"sessions.desktop-mac-menu-bar",checked:Q,onChange:ne,disabled:S||T,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,I?s.jsx(ht,{settingsItem:"sessions.desktop-minimize-to-tray",checked:B,onChange:oe=>{oe!==B&&be()},disabled:w,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,z?s.jsx(ht,{settingsItem:"sessions.desktop-keep-awake",checked:$,onChange:oe=>{oe!==$&&Oe()},disabled:K,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(Wt,{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(Je,{id:"desktop-ui-password",type:v?"text":"password",className:"h-8 min-w-0 flex-1",value:x,onChange:oe=>Ne(oe.target.value),placeholder:t("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:S||T,required:r,"aria-invalid":te}),s.jsx(H,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(oe=>!oe),className:hs,"aria-label":t(v?"settings.openchamber.desktopPassword.actions.hidePassword":"settings.openchamber.desktopPassword.actions.showPassword"),"aria-pressed":v,children:s.jsx(R,{name:v?"eye-off":"eye",className:"h-4 w-4"})})]}),s.jsx("div",{className:fs,children:s.jsx(ht,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:S||T,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")}),te||pe?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")})}),Y?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:Y}):null,ae?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(de&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ae})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(H,{type:"button",size:"xs",onClick:Le,disabled:Ie,className:"shrink-0 !font-normal",children:t(T?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},oc=new Set(["shift","control","alt","meta"]),Dr=3,Rf=3e3;function Mr(t,e=!1){const a=new Set;return t.altKey&&a.add("alt"),t.ctrlKey&&a.add("control"),t.metaKey&&a.add("meta"),t.shiftKey&&a.add("shift"),e&&a.add(t.key.toLowerCase()),a.size}function Lf(t){return t.action.customizable}function ol(t){if(Mr(t)>Dr)return null;const e=[];return(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),e.length>0?Pi(e.join("+")):null}function Of(t){if(oc.has(t.key.toLowerCase())||Mr(t,!0)>Dr)return null;const e=rd(od(t));if(!e)return null;const a=[];return(t.metaKey||t.ctrlKey)&&a.push("mod"),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a.push(e),Pi(a.join("+"))}function Ff(t){const e=t.key.toLowerCase();if(!oc.has(e)||Mr(t,!0)>Dr)return null;const a=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&a.push("mod"),(t.shiftKey||e==="shift")&&a.push("shift"),(t.altKey||e==="alt")&&a.push("alt"),a.length>0?Pi(a.join("+")):null}function ll(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function Kf(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:ol(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Of(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const i=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:i,livePreview:null,settled:i.length===2}}return{...t,livePreview:ol(e)}}const zf=t=>{const e=gt.c(117),{action:a,overrides:n,onSave:i,onOpenChange:r}=t,{t:l}=it();let m;e[0]!==l?(m=te=>l(te.settingsLabelKey),e[0]=l,e[1]=m):m=e[1];const u=m;let x;e[2]!==u?(x=te=>te.action.customizable?u(te.action):Qn(te.action.defaultBinding),e[2]=u,e[3]=x):x=e[3];const d=x;let v;e[4]===Symbol.for("react.memo_cache_sentinel")?(v={chords:[],livePreview:null,settled:!1},e[4]=v):v=e[4];const[c,N]=o.useState(v),f=o.useRef(null);let C,y;e[5]!==a?(C=()=>{a&&(N({chords:[],livePreview:null,settled:!1}),f.current?.focus())},y=[a],e[5]=a,e[6]=C,e[7]=y):(C=e[6],y=e[7]),o.useEffect(C,y);const S=c.chords.length===1&&!c.settled;let g,T;e[8]!==S?(g=()=>{if(!S)return;const te=window.setTimeout(()=>N(ll),Rf);return()=>window.clearTimeout(te)},T=[S],e[8]=S,e[9]=g,e[10]=T):(g=e[9],T=e[10]),o.useEffect(g,T);let M;e[11]!==c.chords?(M=Pi(c.chords.join(" ")),e[11]=c.chords,e[12]=M):M=e[12];const P=M;let k;e[13]!==a||e[14]!==P||e[15]!==n?(k=a&&P?ad(a.id,P,n):[],e[13]=a,e[14]=P,e[15]=n,e[16]=k):k=e[16];const h=k;let j;e[17]!==h?(j=h.find(Uf),e[17]=h,e[18]=j):j=e[18];const F=j;let A,I,E,B,_,w,V,W,L,Q,ne,z,re,$,U;if(e[19]!==a||e[20]!==u||e[21]!==P||e[22]!==d||e[23]!==h||e[24]!==r||e[25]!==i||e[26]!==F||e[27]!==c||e[28]!==l){const te=h.filter(Lf);_=te.find(_f);const pe=te.find($f),Ie=h.find(Vf);let Ne;e[44]!==r?(Ne=()=>r(!1),e[44]=r,e[45]=Ne):Ne=e[45],E=Ne,B=()=>{c.settled||N(ll),!(!a||!P||F||_)&&(i(a.id,P,pe?.action.id),E())};let Se;e[46]!==a||e[47]!==c?(Se=(ye,Te)=>{ye.preventDefault(),ye.stopPropagation();const Ue=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(Te==="keyup"&&Ue&&c.chords.length===0){const je=Ff(ye);if(je){N({chords:[je],livePreview:null,settled:!0});return}}const Pe=Kf(c,{altKey:ye.altKey,code:ye.nativeEvent.code,ctrlKey:ye.ctrlKey,isComposing:ye.nativeEvent.isComposing,key:ye.key,metaKey:ye.metaKey,repeat:ye.repeat,shiftKey:ye.shiftKey},Te);N(Ue&&Pe.chords.length>1?c:Pe)},e[46]=a,e[47]=c,e[48]=Se):Se=e[48];const be=Se;I=Kt,$=a!==null,U=Bf,A=zt,w="max-w-md",V=f,W=!1;let Oe;e[49]!==a||e[50]!==u||e[51]!==l?(Oe=a?l("settings.openchamber.keyboardShortcuts.dialog.title",{action:u(a)}):"",e[49]=a,e[50]=u,e[51]=l,e[52]=Oe):Oe=e[52];let Le;e[53]!==Oe?(Le=s.jsx($t,{children:Oe}),e[53]=Oe,e[54]=Le):Le=e[54];let oe;e[55]!==l?(oe=l("settings.openchamber.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=oe):oe=e[56];let fe;e[57]!==oe?(fe=s.jsx(Vt,{children:oe}),e[57]=oe,e[58]=fe):fe=e[58],e[59]!==Le||e[60]!==fe?(L=s.jsxs(_t,{children:[Le,fe]}),e[59]=Le,e[60]=fe,e[61]=L):L=e[61];let Me,$e;e[62]!==be?(Me=ye=>be(ye,"keydown"),$e=ye=>be(ye,"keyup"),e[62]=be,e[63]=Me,e[64]=$e):(Me=e[63],$e=e[64]);let Ve;e[65]===Symbol.for("react.memo_cache_sentinel")?(Ve=()=>N(Hf),e[65]=Ve):Ve=e[65];let qe;e[66]!==c.chords?(qe=c.chords.map(Gf),e[66]=c.chords,e[67]=qe):qe=e[67];let se;e[68]!==c.livePreview?(se=c.livePreview?s.jsx("kbd",{className:"rounded-md border border-dashed border-border bg-muted px-3 py-2 typography-ui-label font-mono text-muted-foreground",children:Qn(c.livePreview)}):null,e[68]=c.livePreview,e[69]=se):se=e[69];let ie;e[70]!==c.chords.length||e[71]!==c.livePreview||e[72]!==l?(ie=c.chords.length===0&&!c.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.openchamber.keyboardShortcuts.dialog.recording")}):null,e[70]=c.chords.length,e[71]=c.livePreview,e[72]=l,e[73]=ie):ie=e[73];let we;e[74]!==qe||e[75]!==se||e[76]!==ie?(we=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[qe,se,ie]}),e[74]=qe,e[75]=se,e[76]=ie,e[77]=we):we=e[77],e[78]!==Me||e[79]!==$e||e[80]!==we?(Q=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:f,onKeyDown:Me,onKeyUp:$e,onBlur:Ve,children:we}),e[78]=Me,e[79]=$e,e[80]=we,e[81]=Q):Q=e[81],ne=c.settled&&F?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.internalConflict")}):c.settled&&_?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.openchamber.keyboardShortcuts.error.prefixConflict",{action:u(_.action)})}):null,z=c.settled&&pe&&!F&&!_?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.error.exactConflict",{action:u(pe.action)})}):null,re=c.settled&&Ie&&!F&&!_?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.contextualPrefix",{action:d(Ie)})}):null,e[19]=a,e[20]=u,e[21]=P,e[22]=d,e[23]=h,e[24]=r,e[25]=i,e[26]=F,e[27]=c,e[28]=l,e[29]=A,e[30]=I,e[31]=E,e[32]=B,e[33]=_,e[34]=w,e[35]=V,e[36]=W,e[37]=L,e[38]=Q,e[39]=ne,e[40]=z,e[41]=re,e[42]=$,e[43]=U}else A=e[29],I=e[30],E=e[31],B=e[32],_=e[33],w=e[34],V=e[35],W=e[36],L=e[37],Q=e[38],ne=e[39],z=e[40],re=e[41],$=e[42],U=e[43];let K;e[82]!==P||e[83]!==c.settled||e[84]!==l?(K=c.settled&&P&&id(P)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=P,e[83]=c.settled,e[84]=l,e[85]=K):K=e[85];let O;e[86]!==l?(O=l("settings.common.actions.cancel"),e[86]=l,e[87]=O):O=e[87];let Y;e[88]!==E||e[89]!==O?(Y=s.jsx(H,{type:"button",variant:"ghost",size:"sm",onClick:E,children:O}),e[88]=E,e[89]=O,e[90]=Y):Y=e[90];const X=!P||c.settled&&(!!F||!!_);let ee;e[91]!==l?(ee=l("settings.openchamber.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=ee):ee=e[92];let ge;e[93]!==B||e[94]!==X||e[95]!==ee?(ge=s.jsx(H,{type:"button",size:"sm",disabled:X,onClick:B,children:ee}),e[93]=B,e[94]=X,e[95]=ee,e[96]=ge):ge=e[96];let de;e[97]!==Y||e[98]!==ge?(de=s.jsxs(ts,{children:[Y,ge]}),e[97]=Y,e[98]=ge,e[99]=de):de=e[99];let xe;e[100]!==A||e[101]!==w||e[102]!==V||e[103]!==W||e[104]!==L||e[105]!==Q||e[106]!==ne||e[107]!==z||e[108]!==re||e[109]!==K||e[110]!==de?(xe=s.jsxs(A,{className:w,initialFocus:V,showCloseButton:W,children:[L,Q,ne,z,re,K,de]}),e[100]=A,e[101]=w,e[102]=V,e[103]=W,e[104]=L,e[105]=Q,e[106]=ne,e[107]=z,e[108]=re,e[109]=K,e[110]=de,e[111]=xe):xe=e[111];let ae;return e[112]!==I||e[113]!==$||e[114]!==U||e[115]!==xe?(ae=s.jsx(I,{open:$,onOpenChange:U,children:xe}),e[112]=I,e[113]=$,e[114]=U,e[115]=xe,e[116]=ae):ae=e[116],ae};function Uf(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function _f(t){return t.kind==="prefix"}function $f(t){return t.kind==="exact"}function Vf(t){return t.kind==="contextual-prefix"}function Bf(t,e){t||e.cancel()}function Hf(t){return{...t,livePreview:null}}function Gf(t,e){return s.jsx("kbd",{className:"rounded-md border border-border bg-muted px-3 py-2 typography-ui-label font-mono text-foreground",children:Qn(t)},`${t}-${e}`)}const qf=["session","models","panels","navigation","application"],Wf=()=>{const t=gt.c(24),{t:e}=it(),a=le(Jf),n=le(Qf),i=le(Yf),r=le(Xf),[l,m]=o.useState(null);let u;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const P=ld();u=cs()?P.filter(Zf):P,t[0]=u}else u=t[0];const x=u,d=ex;let v;t[1]!==n||t[2]!==a?(v=(P,k,h)=>{const j={...a,[P]:k};h&&(j[h]=Gi),n(P,k),h&&n(h,Gi),d(j)},t[1]=n,t[2]=a,t[3]=v):v=t[3];const c=v;let N;t[4]!==i||t[5]!==a?(N=P=>{const k={...a};delete k[P],i(P),d(k)},t[4]=i,t[5]=a,t[6]=N):N=t[6];const f=N;let C;t[7]!==a||t[8]!==e?(C=P=>{const k="prefixStyle"in P&&P.prefixStyle,h=k?cd(P.id,a):Il(P.id,a),j=Qn(h,e("settings.openchamber.keyboardShortcuts.unassigned"));if(!k||!h||h===Gi)return j;const F=P.id==="switch_session_tab"?e("settings.openchamber.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix");return`${j}${F}`},t[7]=a,t[8]=e,t[9]=C):C=t[9];const y=C;let S;t[10]!==r||t[11]!==f||t[12]!==y||t[13]!==a||t[14]!==e?(S=qf.map((P,k)=>{const h=x.filter(j=>j.category===P);return h.length===0?null:s.jsx(_e,{settingsItem:k===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.openchamber.keyboardShortcuts.category.${P}`),divider:k!==0,info:k===0?e("settings.openchamber.keyboardShortcuts.tooltip"):void 0,headerAction:k===0?s.jsx(H,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{r(),d({})},children:e("settings.openchamber.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:h.map(j=>s.jsxs(Lt,{label:e(j.settingsLabelKey),children:[s.jsx("kbd",{className:"min-w-32 rounded-md border border-border bg-muted px-2 py-1 text-center typography-meta font-mono text-foreground",children:y(j)}),s.jsx(H,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>m(j),children:e("settings.openchamber.keyboardShortcuts.actions.edit")}),j.id in a?s.jsx(H,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>f(j.id),children:e("settings.common.actions.reset")}):null]},j.id))})},P)}),t[10]=r,t[11]=f,t[12]=y,t[13]=a,t[14]=e,t[15]=S):S=t[15];let g;t[16]===Symbol.for("react.memo_cache_sentinel")?(g=P=>{P||m(null)},t[16]=g):g=t[16];let T;t[17]!==l||t[18]!==c||t[19]!==a?(T=s.jsx(zf,{action:l,overrides:a,onSave:c,onOpenChange:g}),t[17]=l,t[18]=c,t[19]=a,t[20]=T):T=t[20];let M;return t[21]!==S||t[22]!==T?(M=s.jsxs(s.Fragment,{children:[S,T]}),t[21]=S,t[22]=T,t[23]=M):M=t[23],M};function Jf(t){return t.shortcutOverrides}function Qf(t){return t.setShortcutOverride}function Yf(t){return t.clearShortcutOverride}function Xf(t){return t.resetAllShortcutOverrides}function Zf(t){return t.id!=="toggle_prompt_navigator"}function ex(t){vt({shortcutOverrides:t})}const lc=()=>{const t=gt.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>Tl(()=>a(px)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},tx=t=>{const e=gt.c(80),{section:a}=t,{t:n}=it(),{isMobile:i}=ja();lc();let r;e[0]!==i?(r=i&&Wn(),e[0]=i,e[1]=r):r=e[1];const l=r;let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=cs(),e[2]=m):m=e[2];const u=m;let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=as()&&Ha(),e[3]=x):x=e[3];const d=x;if(!a){let z,re,$,U,K,O,Y,X;e[4]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(Ai,{}),U=s.jsx(tc,{}),K=d&&s.jsx(rc,{}),O=!u&&s.jsx(ac,{}),Y=!u&&s.jsx(ic,{}),X=s.jsx(Xl,{}),z=s.jsx(ec,{}),re=Wn()&&!as()&&!u&&!Ml()&&s.jsx(Zl,{}),e[4]=z,e[5]=re,e[6]=$,e[7]=U,e[8]=K,e[9]=O,e[10]=Y,e[11]=X):(z=e[4],re=e[5],$=e[6],U=e[7],K=e[8],O=e[9],Y=e[10],X=e[11]);let ee;e[12]!==l?(ee=l&&s.jsx(Fl,{}),e[12]=l,e[13]=ee):ee=e[13];let ge;return e[14]!==ee?(ge=s.jsxs(es,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[$,U,K,O,Y,X,z,re,ee]}),e[14]=ee,e[15]=ge):ge=e[15],ge}let v;e[16]!==a?(v=()=>{switch(a){case"general":return s.jsx(nx,{});case"visual":return s.jsx(ax,{});case"chat":return s.jsx(ix,{});case"sessions":return s.jsx(rx,{});case"shortcuts":return s.jsx(sx,{});case"git":return s.jsx(ox,{});case"notifications":return s.jsx(lx,{});case"voice":return s.jsx(cx,{});case"tunnel":return s.jsx(dx,{});default:return null}},e[16]=a,e[17]=v):v=e[17];const c=v;let N;e[18]!==n?(N=n("settings.page.general.title"),e[18]=n,e[19]=N):N=e[19];let f;e[20]!==n?(f=n("settings.page.appearance.title"),e[20]=n,e[21]=f):f=e[21];let C;e[22]!==n?(C=n("settings.page.chat.title"),e[22]=n,e[23]=C):C=e[23];let y;e[24]!==n?(y=n("settings.page.sessions.title"),e[24]=n,e[25]=y):y=e[25];let S;e[26]!==n?(S=n("settings.page.shortcuts.title"),e[26]=n,e[27]=S):S=e[27];let g;e[28]!==n?(g=n("settings.page.git.title"),e[28]=n,e[29]=g):g=e[29];let T;e[30]!==n?(T=n("settings.page.git.title"),e[30]=n,e[31]=T):T=e[31];let M;e[32]!==n?(M=n("settings.page.notifications.title"),e[32]=n,e[33]=M):M=e[33];let P;e[34]!==n?(P=n("settings.page.voice.title"),e[34]=n,e[35]=P):P=e[35];let k;e[36]!==n?(k=n("settings.page.tunnel.title"),e[36]=n,e[37]=k):k=e[37];let h;e[38]!==g||e[39]!==T||e[40]!==M||e[41]!==P||e[42]!==k||e[43]!==N||e[44]!==f||e[45]!==C||e[46]!==y||e[47]!==S?(h={general:N,visual:f,chat:C,sessions:y,shortcuts:S,git:g,github:T,notifications:M,voice:P,tunnel:k},e[38]=g,e[39]=T,e[40]=M,e[41]=P,e[42]=k,e[43]=N,e[44]=f,e[45]=C,e[46]=y,e[47]=S,e[48]=h):h=e[48];const j=h[a];let F;e[49]!==n?(F=n("settings.page.general.description"),e[49]=n,e[50]=F):F=e[50];let A;e[51]!==n?(A=n("settings.page.appearance.description"),e[51]=n,e[52]=A):A=e[52];let I;e[53]!==n?(I=n("settings.page.chat.description"),e[53]=n,e[54]=I):I=e[54];let E;e[55]!==n?(E=n("settings.page.sessions.description"),e[55]=n,e[56]=E):E=e[56];let B;e[57]!==n?(B=n("settings.page.shortcuts.description"),e[57]=n,e[58]=B):B=e[58];let _;e[59]!==n?(_=n("settings.page.notifications.description"),e[59]=n,e[60]=_):_=e[60];let w;e[61]!==n?(w=n("settings.page.voice.description"),e[61]=n,e[62]=w):w=e[62];let V;e[63]!==n?(V=n("settings.page.tunnel.description"),e[63]=n,e[64]=V):V=e[64];let W;e[65]!==F||e[66]!==A||e[67]!==I||e[68]!==E||e[69]!==B||e[70]!==_||e[71]!==w||e[72]!==V?(W={general:F,visual:A,chat:I,sessions:E,shortcuts:B,git:void 0,github:void 0,notifications:_,voice:w,tunnel:V},e[65]=F,e[66]=A,e[67]=I,e[68]=E,e[69]=B,e[70]=_,e[71]=w,e[72]=V,e[73]=W):W=e[73];const L=W[a];let Q;e[74]!==c?(Q=c(),e[74]=c,e[75]=Q):Q=e[75];let ne;return e[76]!==L||e[77]!==j||e[78]!==Q?(ne=s.jsx(es,{title:j,description:L,showSaveStatus:!0,className:"openchamber-page-body",children:Q}),e[76]=L,e[77]=j,e[78]=Q,e[79]=ne):ne=e[79],ne},sx=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Wf,{}),t[0]=e):e=t[0],e},nx=()=>{const t=gt.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;lc();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=as()&&Ha(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=Wn()&&!as()&&!a&&!Ml(),t[2]=r):r=t[2];const l=r;let m,u,x,d,v;t[3]===Symbol.for("react.memo_cache_sentinel")?(m=i&&s.jsx(rc,{}),u=l&&s.jsx(Zl,{}),x=s.jsx(ec,{}),d=!a&&s.jsx(ac,{}),v=!a&&s.jsx(ic,{}),t[3]=m,t[4]=u,t[5]=x,t[6]=d,t[7]=v):(m=t[3],u=t[4],x=t[5],d=t[6],v=t[7]);let c;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=a?[]:["sessionTabs"],t[8]=c):c=t[8];let N;return t[9]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsxs(s.Fragment,{children:[m,u,x,d,v,s.jsx(Ai,{visibleSettings:["fileEditorKeymap",...c,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=N):N=t[9],N},ax=()=>{const t=gt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Ai,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","inputBarOffset"]}),t[1]=n):n=t[1],n},ix=()=>{const t=gt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=cs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Ai,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","inputHistoryScope","inputHistoryLimit","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste","enterToSend"]}),t[1]=n):n=t[1],n},rx=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(tc,{}),s.jsx(Xl,{})]}),t[0]=e):e=t[0],e},ox=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Yl,{}),t[0]=e):e=t[0],e},lx=()=>{const t=gt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(af,{}),t[0]=e):e=t[0],e},cx=()=>{const t=gt.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(hf,{}),t[0]=e):e=t[0],e},dx=()=>{const t=gt.c(1);if(cs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Cf,{}),t[0]=e):e=t[0],e};function px(t){return t+1}const mx=t=>{const e=gt.c(85),{className:a}=t,{t:n}=it(),i=qn(Pl),r=qn(ux),l=le(gx),m=le(hx),[u,x]=We.useState(!1),[d,v]=We.useState(!1),c=i>0;let N;e[0]!==n?(N=async()=>{try{const Ne=await dd({message:n("settings.view.pendingRestart.applying")});if(Ne.requiresManualRestart){D.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Ne.ok&&D.success(n("settings.view.pendingRestart.applied"))}catch(Ne){const Se=Ne,be=Se instanceof Error&&Se.message?Se.message:n("settings.view.pendingRestart.applyFailed");D.error(be)}},e[0]=n,e[1]=N):N=e[1];const f=N;let C;e[2]!==n?(C=async()=>{try{await Nl({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),qn.getState().clear()}catch{}},e[2]=n,e[3]=C):C=e[3];const y=C;let S;e[4]!==d||e[5]!==f||e[6]!==m?(S=()=>{d&&m(!1),x(!1),v(!1),f()},e[4]=d,e[5]=f,e[6]=m,e[7]=S):S=e[7];const g=S;let T;e[8]!==c||e[9]!==f||e[10]!==y||e[11]!==l?(T=()=>{if(!c){y();return}if(l){v(!1),x(!0);return}f()},e[8]=c,e[9]=f,e[10]=y,e[11]=l,e[12]=T):T=e[12];const M=T;let P;e[13]!==c||e[14]!==r||e[15]!==n?(P=n(c?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=c,e[14]=r,e[15]=n,e[16]=P):P=e[16];const k=P;let h;e[17]!==c||e[18]!==i||e[19]!==n?(h=c?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=c,e[18]=i,e[19]=n,e[20]=h):h=e[20];const j=h,F=c?"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",A=r&&"opacity-80";let I;e[21]!==a||e[22]!==F||e[23]!==A?(I=ve("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",F,A,a),e[21]=a,e[22]=F,e[23]=A,e[24]=I):I=e[24];let E;e[25]!==c||e[26]!==i?(E=c?s.jsx("span",{className:ve("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(R,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=c,e[26]=i,e[27]=E):E=e[27];let B;e[28]!==k?(B=s.jsx("span",{className:"truncate",children:k}),e[28]=k,e[29]=B):B=e[29];let _;e[30]!==M||e[31]!==r||e[32]!==E||e[33]!==B||e[34]!==I||e[35]!==j?(_=s.jsxs("button",{type:"button",disabled:r,title:j,"aria-label":j,onClick:M,className:I,children:[E,B]}),e[30]=M,e[31]=r,e[32]=E,e[33]=B,e[34]=I,e[35]=j,e[36]=_):_=e[36];let w;e[37]===Symbol.for("react.memo_cache_sentinel")?(w=Ne=>{x(Ne),Ne||v(!1)},e[37]=w):w=e[37];let V;e[38]!==n?(V=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=V):V=e[39];let W;e[40]!==V?(W=s.jsx($t,{children:V}),e[40]=V,e[41]=W):W=e[41];let L;e[42]!==n?(L=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=L):L=e[43];let Q;e[44]!==L?(Q=s.jsx(Vt,{children:L}),e[44]=L,e[45]=Q):Q=e[45];let ne;e[46]!==W||e[47]!==Q?(ne=s.jsxs(_t,{children:[W,Q]}),e[46]=W,e[47]=Q,e[48]=ne):ne=e[48];let z;e[49]===Symbol.for("react.memo_cache_sentinel")?(z={width:"40%"},e[49]=z):z=e[49];let re;e[50]===Symbol.for("react.memo_cache_sentinel")?(re=()=>x(!1),e[50]=re):re=e[50];let $;e[51]!==n?($=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=$):$=e[52];let U;e[53]!==$?(U=s.jsx("div",{className:"min-w-0 shrink-0",style:z,children:s.jsx(H,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:re,children:$})}),e[53]=$,e[54]=U):U=e[54];let K;e[55]===Symbol.for("react.memo_cache_sentinel")?(K={width:"40%"},e[55]=K):K=e[55];let O;e[56]!==n?(O=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=O):O=e[57];let Y;e[58]!==g||e[59]!==O?(Y=s.jsx("div",{className:"min-w-0 shrink-0",style:K,children:s.jsx(H,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:g,children:O})}),e[58]=g,e[59]=O,e[60]=Y):Y=e[60];let X;e[61]!==U||e[62]!==Y?(X=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[U,Y]}),e[61]=U,e[62]=Y,e[63]=X):X=e[63];let ee;e[64]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>v(fx),e[64]=ee):ee=e[64];let ge;e[65]!==d?(ge=d?s.jsx(R,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(R,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=d,e[66]=ge):ge=e[66];let de;e[67]!==n?(de=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=de):de=e[68];let xe;e[69]!==d||e[70]!==ge||e[71]!==de?(xe=s.jsxs("button",{type:"button",onClick:ee,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":d,children:[ge,de]}),e[69]=d,e[70]=ge,e[71]=de,e[72]=xe):xe=e[72];let ae;e[73]!==X||e[74]!==xe?(ae=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[X,xe]}),e[73]=X,e[74]=xe,e[75]=ae):ae=e[75];let te;e[76]!==ne||e[77]!==ae?(te=s.jsxs(zt,{showCloseButton:!1,className:"max-w-md gap-5",children:[ne,ae]}),e[76]=ne,e[77]=ae,e[78]=te):te=e[78];let pe;e[79]!==u||e[80]!==te?(pe=s.jsx(Kt,{open:u,onOpenChange:w,children:te}),e[79]=u,e[80]=te,e[81]=pe):pe=e[81];let Ie;return e[82]!==_||e[83]!==pe?(Ie=s.jsxs(s.Fragment,{children:[_,pe]}),e[82]=_,e[83]=pe,e[84]=Ie):Ie=e[84],Ie};function ux(t){return t.isApplying}function gx(t){return t.showOpenCodeRestartConfirm}function hx(t){return t.setShowOpenCodeRestartConfirm}function fx(t){return!t}const xx=[{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"]},{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.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.openchamber.visual.field.sessionTabsGroup",descriptionKey:"settings.openchamber.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{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:"general.app-links",page:"general",titleKey:"settings.openchamber.appLinks.title",descriptionKey:"settings.openchamber.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{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.streaming",page:"chat",titleKey:"settings.openchamber.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.openchamber.visual.field.streamingAutoFollow",descriptionKey:"settings.openchamber.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{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.input-history-scope",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryScope",descriptionKey:"settings.openchamber.visual.field.inputHistoryScopeDescription",keywords:["input history","composer history","global","session","reuse"]},{id:"chat.input-history-limit",page:"chat",titleKey:"settings.openchamber.visual.field.inputHistoryLimit",descriptionKey:"settings.openchamber.visual.field.inputHistoryLimitDescription",keywords:["history limit","prompt recall","remember prompts","composer history","submitted prompts","trim history"]},{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","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.openchamber.visual.field.largeTextPaste",descriptionKey:"settings.openchamber.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"chat.enter-to-send",page:"chat",titleKey:"settings.openchamber.visual.field.enterToSend",descriptionKey:"settings.openchamber.visual.field.enterToSendHint",keywords:["enter","shift enter","send","newline"]},{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&&le.getState().agentMemoryFeatureAvailable},{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.default-model",page:"projects",titleKey:"settings.projects.page.field.projectModel",keywords:["model","default","new chat","project metadata"]},{id:"projects.default-thinking",page:"projects",titleKey:"settings.projects.page.field.projectThinking",keywords:["thinking","variant","reasoning","effort","model","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.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode}];function cl(t){return t.trim().toLocaleLowerCase()}function bx({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=cl(t);if(!r)return[];const l=a?new Set(a):null,m=r.split(/\s+/).filter(Boolean);return xx.flatMap(u=>{if(l&&!l.has(u.page))return[];const x=Oa(u.page);if(!x||x.isAvailable&&!x.isAvailable(e)||u.isAvailable&&!u.isAvailable(e))return[];const d=n(u.titleKey),v=u.descriptionKey?n(u.descriptionKey):null,c=cl([d,v,i(u.page),...u.keywords??[]].filter(Boolean).join(" "));return m.every(N=>c.includes(N))?[{...u,title:d,description:v,pageTitle:i(u.page)}]:[]})}const dl=256,pl=280,cc="__openchamberSettingsDetail",vx=["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"],yx=["general","projects","opencode","content"],jx="__add_provider__";function wx(t,e){const a=cs(),n=!t&&Wn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function ml(t,e){return t.isAvailable?t.isAvailable(e):!0}function br(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function La(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function ir(t){if(!br(t))return null;const e=t[cc];if(!br(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Rl(a),stage:n}}function kx(){return typeof window>"u"||!br(window.history.state)?{}:window.history.state}const Lx=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:i="nav"})=>{const{t:r}=it(),l=ja(),m=e??l.isMobile,u=qn(Pl),x=le(se=>se.settingsPage),d=le(se=>se.isSettingsDialogOpen),v=le(se=>se.setSettingsPage),c=le(se=>se.shortcutOverrides.open_settings),N=Rl(x),[f,C]=o.useState(i),y=o.useRef(i==="nav"?N:null);o.useEffect(()=>{!m&&N==="home"&&v("general")},[m,v,N]);const[S,g]=o.useState(""),[T,M]=o.useState(null),[P,k]=o.useState(0),h=o.useRef(null),j=o.useRef(!1),F=o.useRef([]),A=o.useRef(0),I=o.useRef(!1),E=o.useMemo(()=>as(),[]),B=o.useMemo(()=>as()&&Ha(),[]),_=o.useMemo(()=>as()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),w=o.useMemo(()=>as()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",[]),V=o.useMemo(()=>as()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",[]),W=o.useMemo(()=>Dl(),[]),L=o.useMemo(()=>wx(E,m),[E,m]),Q=o.useMemo(()=>{const se=n?new Set(n):null;return Gd.filter(ie=>ie.slug!=="home").filter(ie=>!se||se.has(ie.slug)).filter(ie=>ml(ie,L)).filter(ie=>!(L.isVSCode&&ie.slug==="projects")).filter(ie=>!(m&&ie.slug==="shortcuts"))},[L,m,n]),ne=o.useMemo(()=>{const se=new Map(vx.map((ie,we)=>[ie,we]));return Q.slice().sort((ie,we)=>(se.get(ie.slug)??999)-(se.get(we.slug)??999))},[Q]),z=Bs(se=>se.activeProjectId),re=Us();o.useEffect(()=>{if(!(!d&&!L.isVSCode&&!a)){if(N==="agents"){Jn.getState().loadAgents(re);return}if(N==="commands"){va.getState().loadCommands(re);return}if(N==="mcp"){ya.getState().loadMcpConfigs({directory:re});return}if(N==="plugins"){ms.getState().loadPlugins();return}(N==="skills.installed"||N==="skills.catalog")&&(Vs.getState().loadSkills(re),hn.getState().loadCatalog()),N==="snippets"&&Ci.getState().loadSnippets()}},[z,d,a,L.isVSCode,re,N]);const $=o.useCallback(se=>{if(v(se),y.current=se,!m)return;const ie=Oa(se);if(!ie||ie.slug==="home"){C("nav");return}C(ie.kind==="split"?"page-sidebar":"page-content")},[m,v]),U=o.useMemo(()=>Oa(N),[N]),K=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),O=o.useCallback(se=>{switch(se){case"general":return r("settings.page.general.title");case"projects":return r("settings.page.projects.title");case"remote-instances":return r("settings.page.remoteInstances.title");case"providers":return r("settings.page.providers.title");case"usage":return r("settings.page.usage.title");case"agents":return r("settings.page.agents.title");case"behavior":return r("settings.page.behavior.title");case"commands":return r("settings.page.commands.title");case"mcp":return r("settings.page.mcp.title");case"plugins":return r("settings.page.plugins.title");case"skills.installed":return r("settings.page.skills.title");case"skills.catalog":return r("settings.page.skillsCatalog.title");case"git":return r("settings.page.git.title");case"integrations":return r("settings.page.integrations.title");case"appearance":return r("settings.page.appearance.title");case"chat":return r("settings.page.chat.title");case"shortcuts":return r("settings.page.shortcuts.title");case"sessions":return r("settings.page.sessions.title");case"magic-prompts":return r("settings.page.magicPrompts.title");case"snippets":return r("settings.page.snippets.title");case"notifications":return r("settings.page.notifications.title");case"voice":return r("settings.page.voice.title");case"tunnel":return r("settings.page.tunnel.title");case"about":return r("settings.page.about.title");default:return r("settings.view.home.title")}},[r]),Y=o.useMemo(()=>bx({query:S,runtimeCtx:{...L,isDesktopLocalOrigin:B,isMac:_,isWindows:w,isLinux:V,isWindowsArm64:W},visiblePageSlugs:n,t:r,getPageTitle:O}),[O,W,B,_,w,V,L,S,r,n]),X=o.useCallback(se=>{if(se.id.startsWith("agents.")){const ie=Jn.getState(),we=La("new-agent",ie.agents.map(ye=>ye.name));return ie.setAgentDraft({name:we,scope:"user"}),ie.setSelectedAgent(we),se.id==="agents.create"?"agents.name":se.id}if(se.id.startsWith("commands.")){const ie=va.getState(),we=La("new-command",ie.commands.map(ye=>ye.name));return ie.setCommandDraft({name:we,scope:"user"}),ie.setSelectedCommand(we),se.id==="commands.create"?"commands.name":se.id}if(se.id.startsWith("mcp.")){const ie=ya.getState(),we=La("new-mcp-server",ie.mcpServers.map(ye=>ye.name));return ie.setMcpDraft({name:we,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),ie.setSelectedMcp(we),se.id==="mcp.create"?"mcp.server":se.id}if(se.id.startsWith("snippets.")){const ie=Ci.getState(),we=La("new-snippet",ie.snippets.map(ye=>ye.name));return ie.setSnippetDraft({name:we,scope:"global"}),ie.setSelectedSnippet(we),se.id==="snippets.create"?"snippets.content":se.id}if(se.id.startsWith("skills.")){const ie=Vs.getState(),we=La("new-skill",ie.skills.map(ye=>ye.name));return ie.setSkillDraft({name:we,scope:"user",source:"opencode",description:"",instructions:""}),ie.setSelectedSkill(we),se.id==="skills.create"?"skills.basic-information":se.id}return se.id==="providers.connect"&&Ze.getState().setSelectedProvider(jx),se.id==="plugins.create"?"plugins.spec":se.id},[]),ee=o.useMemo(()=>{const se=[],ie=new Map;for(const we of Y){let ye=ie.get(we.page);ye||(ye={page:we.page,pageTitle:we.pageTitle,results:[]},ie.set(we.page,ye),se.push(ye)),ye.results.push(we)}return se},[Y]);o.useEffect(()=>{k(0),A.current=0,I.current=!1},[S]),o.useEffect(()=>{A.current=P},[P]),o.useEffect(()=>{F.current[P]?.scrollIntoView({block:"nearest"})},[P]),o.useEffect(()=>{P>=Y.length&&k(Math.max(0,Y.length-1)),F.current.length=Y.length},[P,Y.length]);const ge=o.useCallback(se=>{const ie=X(se);M(ie),$(se.page),m&&C("page-content"),se.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))},50)},[m,$,X]),de=o.useCallback(se=>{if(S.trim()){if(se.key==="Escape"){se.preventDefault(),g("");return}if(Y.length!==0){if(se.key==="ArrowDown"){se.preventDefault(),I.current=!0,k(ie=>(ie+1)%Y.length);return}if(se.key==="ArrowUp"){se.preventDefault(),I.current=!0,k(ie=>(ie-1+Y.length)%Y.length);return}if(se.key==="Enter"){se.preventDefault();const ie=(A.current%Y.length+Y.length)%Y.length,we=Y[ie]??Y[0];we&&ge(we)}}}},[ge,S,Y]);o.useEffect(()=>{const se=T;if(!se)return;let ie=!1;const we=window.requestAnimationFrame(()=>{if(ie)return;const ye=typeof CSS<"u"&&CSS.escape?CSS.escape(se):se.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Te=h.current?.querySelector(`[data-settings-item="${ye}"]`);Te&&(M(null),Te.scrollIntoView({block:"center",behavior:"smooth"}),Te.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Te.removeAttribute("data-settings-search-highlight")},1600))});return()=>{ie=!0,window.cancelAnimationFrame(we)}},[T,N]);const xe=o.useCallback(()=>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:wl,children:r("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:r("settings.view.unavailable.description")})]})}),[r]),ae=o.useCallback((se,ie)=>{switch(se){case"projects":return s.jsx(Eu,{onItemSelect:ie.onItemSelect});case"agents":return s.jsx(xp,{onItemSelect:ie.onItemSelect});case"commands":return s.jsx(Rp,{onItemSelect:ie.onItemSelect});case"mcp":return s.jsx($p,{onItemSelect:ie.onItemSelect});case"plugins":return s.jsx(Am,{onItemSelect:ie.onItemSelect});case"skills.installed":return s.jsx(Vm,{onItemSelect:ie.onItemSelect});case"providers":return s.jsx(ig,{onItemSelect:ie.onItemSelect});case"usage":return s.jsx($g,{onItemSelect:ie.onItemSelect});case"magic-prompts":return s.jsx(ih,{onItemSelect:ie.onItemSelect});case"snippets":return s.jsx(ch,{onItemSelect:ie.onItemSelect});default:return null}},[]),te=o.useCallback(se=>{const ie=Oa(se);if(ie&&!ml(ie,L))return xe();switch(se){case"projects":return s.jsx(Ou,{});case"remote-instances":return s.jsx(sg,{});case"agents":return s.jsx(Pp,{});case"behavior":return s.jsx(Mp,{});case"commands":return s.jsx(_p,{});case"mcp":return s.jsx(dm,{});case"plugins":return s.jsx(_m,{});case"skills.installed":return s.jsx(jo,{view:"installed"});case"skills.catalog":return s.jsx(jo,{view:"catalog"});case"providers":return s.jsx(Ug,{});case"usage":return s.jsx(nh,{});case"about":return s.jsx(es,{title:r("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(Fl,{})});case"magic-prompts":return s.jsx(lh,{});case"snippets":return s.jsx(uh,{});case"git":return s.jsx(bh,{});case"integrations":return s.jsx(Mh,{});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const we=K[se]??"visual";return s.jsx(tx,{section:we})}default:return null}},[K,xe,L,r]);o.useEffect(()=>{if(!m||f!=="nav"||N==="home"||y.current===N)return;const se=Oa(N);!se||se.slug==="home"||(y.current=N,C(se.kind==="split"?"page-sidebar":"page-content"))},[m,f,N]);const pe=m&&f!=="nav",Ie=m&&f==="page-content"&&N==="skills.installed",Ne=f==="page-content"&&U?.kind==="split"&&!Ie,Se=r(Ie?"settings.view.actions.back":pe?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),be=Il("open_settings",c===void 0?void 0:{open_settings:c}),Oe=be?r("settings.view.actions.closeSettingsWithShortcut",{shortcut:Qn(be)}):r("settings.view.actions.closeSettings"),Le=o.useCallback(se=>{if(typeof window>"u"||L.isVSCode)return;const ie=ir(window.history.state);ie?.page===se&&ie.stage==="page-content"||window.history.pushState({...kx(),[cc]:{page:se,stage:"page-content"}},"",window.location.href)},[L.isVSCode]),oe=o.useCallback(()=>{j.current=!0,C("page-content"),N==="skills.installed"&&Le(N)},[Le,N]);o.useEffect(()=>{if(!m||f!=="page-content"||!j.current)return;j.current=!1;const se=window.requestAnimationFrame(()=>{h.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(se)}},[m,f,N]);const fe=o.useCallback(()=>{if(Ie){if((typeof window<"u"?ir(window.history.state):null)?.page===N&&!L.isVSCode){window.history.back();return}C("page-sidebar");return}C("nav")},[Ie,L.isVSCode,N]);o.useEffect(()=>{if(!m||L.isVSCode)return;const se=ie=>{if(N!=="skills.installed")return;if(ir(ie.state)?.page==="skills.installed"){C("page-content");return}C(ye=>ye==="page-content"?"page-sidebar":ye)};return window.addEventListener("popstate",se),()=>{window.removeEventListener("popstate",se)}},[m,L.isVSCode,N]);const Me=o.useCallback(()=>{C("page-sidebar")},[]),$e=()=>{const se=S.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(R,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:S,onChange:ie=>g(ie.target.value),onKeyDown:de,placeholder:r("settings.view.search.placeholder"),"aria-label":r("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":r("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(R,{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?Y.length>0?(()=>{let ie=0;return ee.map(we=>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:we.pageTitle}),we.results.map(ye=>{const Te=ie;ie+=1;const Ue=Te===P,Pe=!!ye.description;return s.jsxs("button",{type:"button",ref:je=>{F.current[Te]=je},onMouseMove:()=>{I.current=!1,k(Te)},onClick:()=>ge(ye),className:ve("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Pe?"min-h-11 py-1.5":"py-2",Ue?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ye.title}),Pe&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:ye.description})]},ye.id)})]},we.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:r("settings.view.search.noResults")}):(()=>{const ie=new Map;for(const ye of ne){const Te=ye.group,Ue=ie.get(Te);Ue?Ue.push(ye):ie.set(Te,[ye])}return yx.map(ye=>({group:ye,pages:ie.get(ye)??[]})).filter(ye=>ye.pages.length>0).map(({group:ye,pages:Te},Ue)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:ve("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Ue===0?"pt-1":"pt-4 sm:pt-3"),children:r(`settings.view.nav.group.${ye}`)}),Te.map(Pe=>{const je=N===Pe.slug&&!(m&&f==="nav"),Ge=qd(Pe.slug);return!Ge&&Pe.slug!=="mcp"?null:s.jsx(jr,{children:s.jsx(wr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>$(Pe.slug),"aria-current":je?"page":void 0,className:ve("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",je?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[Pe.slug==="mcp"?s.jsx(pd,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(R,{name:Ge,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:O(Pe.slug)}),Pe.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:r("settings.view.badge.beta")})]})]})})},Pe.slug)})]},ye))})()})}),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:(!L.isVSCode||u>0)&&s.jsx(mx,{})})})]})},Ve=()=>{if(f==="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(Sn,{children:$e()})})});if(!U)return s.jsx("div",{className:"flex-1 bg-background"});if(f==="page-sidebar"){if(U.kind!=="split"){const ie=te(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:ie})})}return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:ae(N,{onItemSelect:oe})})})}const se=te(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:se})})},qe=()=>!U||N==="home"?null:U.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ve("border-r",L.isVSCode?"bg-background":"bg-sidebar"),style:{width:pl,minWidth:pl,borderColor:"var(--interactive-border)"},children:s.jsx(Sn,{children:ae(N,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:te(N)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Sn,{children:te(N)})});return s.jsxs("div",{ref:h,"data-settings-view":"true",className:ve("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[m?s.jsxs("div",{className:ve("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",f!=="nav"&&"border-b","bg-background"),style:f!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[pe?s.jsx("button",{type:"button",onClick:fe,"aria-label":Se,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(R,{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:f==="nav"?r("settings.view.home.title"):U?O(U.slug):r("settings.view.home.title")}),Ne&&s.jsx("button",{type:"button",onClick:Me,"aria-label":r("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(R,{name:"list-unordered",className:"h-5 w-5"})}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Oe,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(R,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[pe&&s.jsx("div",{className:ve("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:fe,"aria-label":r("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(R,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:ve("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Oe,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(R,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:m?Ve():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ve("relative flex h-full min-h-0 flex-col overflow-hidden border-r",E?"bg-sidebar":L.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${dl}px`,minWidth:`${dl}px`,borderColor:"var(--interactive-border)"},children:s.jsx(Sn,{children:$e()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:qe()})]})})]})};export{Fl as A,Lx as S};