@openchamber/web 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-DAvopJvy.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
  2. package/dist/assets/{CommitSection-D9cV-qR9.js → CommitSection-C-F3AX6D.js} +1 -1
  3. package/dist/assets/{DiagramEditor-B9NCadU7.js → DiagramEditor-BPECg1jS.js} +1 -1
  4. package/dist/assets/DiagramView-D0YNMix8.js +1 -0
  5. package/dist/assets/DiffView-BHWaMYCC.js +4 -0
  6. package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
  7. package/dist/assets/{GitView-DsWXqWx3.js → GitView-Rp8P1KEI.js} +4 -4
  8. package/dist/assets/{JsonTreeView-h4dHASlq.js → JsonTreeView-KnXFN2A-.js} +1 -1
  9. package/dist/assets/{MarkdownImageGallery-n0ikH-xm.js → MarkdownImageGallery-BMn3mtor.js} +1 -1
  10. package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
  11. package/dist/assets/{OnboardingScreen-CDjgzxEe.js → OnboardingScreen-CenIeD4v.js} +1 -1
  12. package/dist/assets/{PatchDiff-jPKTJje5.js → PatchDiff-BzVOVog8.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-D_Gt4A_6.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
  14. package/dist/assets/PlanView-Czu1KMJa.js +4 -0
  15. package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
  16. package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
  17. package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
  18. package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
  19. package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
  20. package/dist/assets/{VirtualizedFileDiff-B37yB9jZ.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
  21. package/dist/assets/{WalkthroughView-Bxun3k66.js → WalkthroughView-CaSYE0lw.js} +1 -1
  22. package/dist/assets/{computeVirtualFileMetrics-DYFv_yZS.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
  23. package/dist/assets/{contextPanelEmbeddedChat-BO1wRpaN.js → contextPanelEmbeddedChat-BEARQjgn.js} +1 -1
  24. package/dist/assets/de-DFdX3ABv.js +9 -0
  25. package/dist/assets/es-iC-FKvV9.js +15 -0
  26. package/dist/assets/fr-BBbi_1AL.js +13 -0
  27. package/dist/assets/{index-BSvmTvZl.js → index-BiEgzzkg.js} +1 -1
  28. package/dist/assets/index-Cwmuwk3V.js +7 -0
  29. package/dist/assets/index-GNm1wgUH.css +1 -0
  30. package/dist/assets/{isDiffPlainText-DwHKxDYc.js → isDiffPlainText-BG53Ixxy.js} +1 -1
  31. package/dist/assets/{isFilePlainText-Dwq6ILxo.js → isFilePlainText-BbV-39jl.js} +1 -1
  32. package/dist/assets/ja-DQLQJL2J.js +15 -0
  33. package/dist/assets/ko-BeElEB4Y.js +15 -0
  34. package/dist/assets/main-Dpzo18z7.js +2 -0
  35. package/dist/assets/main-WMjtYzJs.js +921 -0
  36. package/dist/assets/markdownCore--tDmyI_v.js +2 -0
  37. package/dist/assets/miniChat-ldEghBLB.js +2 -0
  38. package/dist/assets/mobile-Dk-VGreF.js +2 -0
  39. package/dist/assets/{patchFileDiff-BEDPDypx.js → patchFileDiff-BcFaMtMu.js} +2 -2
  40. package/dist/assets/pl-CLHt2_vV.js +15 -0
  41. package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
  42. package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
  43. package/dist/assets/{renderMobileApp-BiMbzPq9.js → renderMobileApp-CDfHS5rr.js} +7 -7
  44. package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
  45. package/dist/assets/{scheduledTasksApi-01zzfzqH.js → scheduledTasksApi-BFSlqgnG.js} +1 -1
  46. package/dist/assets/{shikiHighlight-DXYW46vW.js → shikiHighlight-DCT2Sq_z.js} +1 -1
  47. package/dist/assets/uk-PhsC-c4-.js +15 -0
  48. package/dist/assets/{useAppFontEffects-CbzHzFop.js → useAppFontEffects-B53Rb6m7.js} +166 -159
  49. package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
  50. package/dist/assets/{vendor-base-ui-BYlZTzrw.js → vendor-base-ui-DsHmyMwp.js} +1 -1
  51. package/dist/assets/{vendor-codemirror-language-data-CiAYDJXN.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
  52. package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
  53. package/dist/assets/{web-components-DCLjCO9n.js → web-components-pcwCTWjC.js} +4 -4
  54. package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
  55. package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
  56. package/dist/index.html +5 -4
  57. package/dist/mini-chat.html +4 -3
  58. package/dist/mobile.html +4 -3
  59. package/package.json +3 -5
  60. package/server/index.js +36 -0
  61. package/server/lib/agent-memory/project-resolution.js +10 -1
  62. package/server/lib/agent-memory/project-resolution.test.js +9 -0
  63. package/server/lib/agent-memory/runtime.js +7 -2
  64. package/server/lib/dictation/DOCUMENTATION.md +32 -8
  65. package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
  66. package/server/lib/dictation/local/worker-process.js +2 -2
  67. package/server/lib/dictation/openai-compatible-session.js +3 -2
  68. package/server/lib/dictation/stream-manager.js +77 -34
  69. package/server/lib/dictation/stream-manager.test.js +60 -2
  70. package/server/lib/fs/routes.test.js +76 -0
  71. package/server/lib/git/routes.js +43 -0
  72. package/server/lib/git/service.js +85 -5
  73. package/server/lib/git/service.test.js +93 -0
  74. package/server/lib/opencode/DOCUMENTATION.md +6 -2
  75. package/server/lib/opencode/feature-routes-runtime.js +5 -9
  76. package/server/lib/opencode/lifecycle.js +202 -26
  77. package/server/lib/opencode/lifecycle.test.js +179 -1
  78. package/server/lib/opencode/providers.js +9 -4
  79. package/server/lib/opencode/providers.test.js +27 -0
  80. package/server/lib/opencode/restart-session-recovery.test.js +59 -0
  81. package/server/lib/opencode/session-runtime.js +39 -2
  82. package/server/lib/opencode/session-runtime.test.js +74 -0
  83. package/server/lib/opencode/settings-helpers.js +15 -0
  84. package/server/lib/opencode/settings-helpers.test.js +22 -0
  85. package/server/lib/opencode/settings-normalization-runtime.js +3 -0
  86. package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
  87. package/server/lib/opencode/settings-runtime.js +32 -10
  88. package/server/lib/opencode/settings-runtime.test.js +85 -0
  89. package/server/lib/opencode/skill-routes.js +29 -73
  90. package/server/lib/opencode/skill-routes.test.js +2 -5
  91. package/server/lib/project-context/DOCUMENTATION.md +2 -0
  92. package/server/lib/project-context/runtime.js +7 -2
  93. package/server/lib/projects/project-config.js +7 -2
  94. package/server/lib/quota/DOCUMENTATION.md +1 -1
  95. package/server/lib/quota/providers/claude/index.js +2 -2
  96. package/server/lib/quota/providers/command-code.js +1 -1
  97. package/server/lib/quota/providers/command-code.test.js +13 -0
  98. package/server/lib/quota/providers/index.js +12 -4
  99. package/server/lib/quota/providers/zai.js +26 -6
  100. package/server/lib/quota/providers/zai.test.js +33 -0
  101. package/server/lib/session-knowledge/DOCUMENTATION.md +2 -0
  102. package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
  103. package/server/lib/skills-catalog/cache.js +120 -1
  104. package/server/lib/skills-catalog/cache.test.js +77 -0
  105. package/server/lib/skills-catalog/curated-sources.js +21 -5
  106. package/server/lib/skills-catalog/curated-sources.test.js +4 -4
  107. package/server/lib/skills-catalog/disk-cache.js +52 -0
  108. package/server/lib/skills-catalog/github-meta.js +139 -0
  109. package/server/lib/skills-catalog/github-meta.test.js +71 -0
  110. package/server/lib/skills-catalog/source.js +0 -5
  111. package/server/lib/small-model/DOCUMENTATION.md +74 -6
  112. package/server/lib/small-model/call.js +46 -12
  113. package/server/lib/small-model/call.test.js +79 -0
  114. package/server/lib/small-model/index.js +51 -8
  115. package/server/lib/small-model/index.test.js +73 -3
  116. package/server/lib/small-model/routes.js +1 -1
  117. package/server/lib/small-model/runtime-providers.js +156 -0
  118. package/server/lib/small-model/runtime-providers.test.js +112 -0
  119. package/dist/assets/DiagramView-LKGBwf4G.js +0 -1
  120. package/dist/assets/DiffView-BWNq-0ov.js +0 -4
  121. package/dist/assets/FilesView-DB-Q0Gkz.js +0 -14
  122. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +0 -12
  123. package/dist/assets/PlanView-UvuxIl9-.js +0 -4
  124. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +0 -1
  125. package/dist/assets/SettingsView-3B9VN6Ys.js +0 -28
  126. package/dist/assets/SettingsWindow-CqQNDKNd.js +0 -1
  127. package/dist/assets/ToolOutputDialog-PmjlAxVE.js +0 -15
  128. package/dist/assets/ToolPartDiffPreview-B34Xw9wq.js +0 -8
  129. package/dist/assets/de-DbV6CLxv.js +0 -9
  130. package/dist/assets/es-CVDlyzZ4.js +0 -15
  131. package/dist/assets/fr-Czc-p0g-.js +0 -13
  132. package/dist/assets/index-1OhiMDBz.css +0 -1
  133. package/dist/assets/index-DzriVon2.js +0 -7
  134. package/dist/assets/ja-dwc9NM_S.js +0 -15
  135. package/dist/assets/ko-Ds1DZ8FX.js +0 -15
  136. package/dist/assets/main-BF51IOVF.js +0 -921
  137. package/dist/assets/main-D7UPARut.js +0 -2
  138. package/dist/assets/markdownCore-BgeBDwD3.js +0 -2
  139. package/dist/assets/miniChat-BISXSGOo.js +0 -2
  140. package/dist/assets/mobile-BnYxVuvw.js +0 -2
  141. package/dist/assets/pl-CLiTO7i-.js +0 -15
  142. package/dist/assets/pt-BR-GIimJgpK.js +0 -15
  143. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +0 -2
  144. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +0 -15
  145. package/dist/assets/uk-DLfgD1ki.js +0 -15
  146. package/dist/assets/useInlineCommentController-CegKdDXi.js +0 -2
  147. package/dist/assets/vendor-zod-adaMkgkm.js +0 -39
  148. package/dist/assets/zh-CN-DkeP5awK.js +0 -15
  149. package/dist/assets/zh-TW-BocaFm3d.js +0 -15
  150. package/server/lib/skills-catalog/clawdhub/api.js +0 -126
  151. package/server/lib/skills-catalog/clawdhub/install.js +0 -238
  152. package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
  153. package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
@@ -0,0 +1,28 @@
1
+ import{R as o,j as s,f as mt,r as Qe}from"./vendor-react-BUCujlKS.js";import{f as rt,B as V,I as L,o as En,aW as oa,t as D,O as Jl,fq as Ql,el as Ue,fr as Ot,b as Qs,h as ye,fs as Yl,aS as en,aU as tn,ft as Zl,aV as sn,ec as _n,fu as Xo,fv as Xl,fw as ta,fx as an,bW as Hs,bu as Vt,bv as Bt,bw as Wt,bx as Jt,by as Qt,bz as ds,S as He,fy as Ra,aR as nn,e0 as Ji,fz as el,fA as Fn,en as ts,fB as Bs,l as st,ez as Yt,bM as Lt,bN as Ft,ex as qt,bO as $t,bP as Kt,bQ as pt,fC as Zt,bR as As,dq as Ea,ey as Cn,eB as na,eA as Pn,fD as vs,dv as Ps,fE as ec,fF as xt,fG as tl,fH as tc,fI as zn,fJ as ii,fK as sc,fL as aa,fM as Vs,fN as sa,fO as sl,fP as lr,dr as nl,fQ as pn,ag as ia,af as Rs,fR as al,fS as wr,eR as nc,d_ as il,g as Ta,fT as ac,fU as Xs,dZ as ic,fV as rc,fW as oc,fX as cr,aY as dr,aZ as pr,a_ as rl,fY as cn,b0 as mr,L as ur,fZ as kr,aa as lc,bS as cc,ct as dc,Q as pc,N as mc,R as uc,V as ol,f_ as gc,f$ as hc,bJ as fc,bT as Qi,g0 as ll,eQ as Ci,g1 as cl,P as Kn,g2 as Sn,ek as Ks,n as ls,bh as ri,x as xc,i as bc,j as vc,bC as yc,p as jc,g3 as wc,bk as kc,bD as Nr,bE as dl,bj as Nc,g4 as Pi,g5 as Sr,g6 as Sc,g7 as Cc,g8 as Pc,g9 as Ic,dB as li,ga as Ss,gb as Js,gc as wn,gd as kn,aj as xa,ge as Nn,gf as ra,gg as xn,gh as Cr,gi as ba,gj as va,gk as Ac,gl as Ec,gm as Tc,gn as Dc,go as Ii,gp as Pr,gq as Mc,gr as Rc,gs as Oc,gt as Lc,gu as Ir,y as Fc,m as Ar,cQ as Kc,gv as Uc,gw as Ai,gx as Er,dX as zc,gy as _c,cd as $c,bt as Tr,gz as ln,gA as Ei,bs as Dr,gB as pl,gC as Mr,gD as ml,gE as Vc,e5 as Bc,gF as Hc,ac as bn,ae as Gc}from"./useAppFontEffects-B53Rb6m7.js";import{r as dt,u as ce,E as xs,cv as qc,cw as Rr,v as dn,ao as Ti,W as Wc,L as kt,o as An,y as hs,J as Or,c0 as Lr,c3 as Fr,K as ya,p as Jc,cx as Qc,j as Yc,b$ as ea,cy as Zc,a7 as Xc,c2 as ed,cz as td,cA as sd,s as nd,e as Oa,c1 as ad,z as La,cB as ul,S as id,cC as rd,R as od,aD as Kr,av as ld,_ as In,cD as cd,t as gl,cE as Ur,cu as zr,cF as _r,at as $r,cG as dd,cH as pd,cI as Vr,b as md,ar as hl,cJ as fl,cK as ud,cL as gd,cM as hd,cN as fd,cO as xd,cP as bd,ai as vd,i as xl}from"./index-Cwmuwk3V.js";import{u as yd,U as Br,w as $n,y as Vn,z as Bn,A as Hn,b as gr,q as Gn,s as qn,v as Wn,J as Un,F as jd,h as Is,p as wd,H as kd,K as Ia,Q as bl,B as Nd,E as Sd}from"./runtimeEndpointReset-ovNbaZ-x.js";import{u as Ms,c as vl,d as Cd,p as Pd}from"./vendor-zustand-BAGL70zf.js";import{s as Id,p as Ad}from"./vendor-yaml-3778uTud.js";import{c as Hr,s as Ed,C as Gr,P as Td}from"./shikiHighlight-DCT2Sq_z.js";import{getResolvedShikiTheme as Dd}from"./appThemeRegistry-BK0dHKa6.js";import{E as qr}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as yl}from"./vendor-qrcode-DTJ12-WC.js";import{k as Md,s as Rd}from"./contextPanelEmbeddedChat-BEARQjgn.js";const Wr=()=>{const{t}=rt(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const h=await dt("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!h.ok)return;const d=await h.json().catch(()=>null);if(!d||i)return;const b=typeof d.port=="number"&&Number.isFinite(d.port)&&d.port>0?d.port:null,c=typeof d.tunnelUrl=="string"&&d.tunnelUrl.trim().length>0?d.tunnelUrl.trim():null;a({port:b,tunnelUrl:c})}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(V,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{En(i.url)},children:[s.jsx(L,{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))})},Jr="https://github.com/openchamber/openchamber",Od="https://discord.gg/ZYRSdnwwKA",Qr="https://x.com/openchamber_dev",Ld=800,jl=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=rt(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,h]=o.useState(null),[d,b]=o.useState(null),c=yd(Ms(P=>({info:P.info,checking:P.checking,available:P.available,error:P.error,downloading:P.downloading,downloaded:P.downloaded,progress:P.progress,runtimeType:P.runtimeType,checkForUpdates:P.checkForUpdates,downloadUpdate:P.downloadUpdate,restartToUpdate:P.restartToUpdate}))),{isMobile:j}=oa(),m=l||c.info?.currentVersion||"unknown";o.useEffect(()=>{let P=!1;return(async()=>{try{const C=await dt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!C.ok)return;const u=await C.json().catch(()=>null),I=typeof u?.openchamberVersion=="string"&&u.openchamberVersion.trim().length>0?u.openchamberVersion.trim():null;P||h(I)}catch{P||h(null)}})(),()=>{P=!0}},[]),o.useEffect(()=>{let P=!1;return(async()=>{try{const C=await dt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!C.ok)return;const u=await C.json().catch(()=>null),I=typeof u?.currentVersion=="string"&&u.currentVersion.trim().length>0?u.currentVersion.trim():null;P||b(I)}catch{P||b(null)}})(),()=>{P=!0}},[]);const E=o.useRef(!1);o.useEffect(()=>{if(c.checking)r(!0),E.current=!0;else if(i){const P=setTimeout(()=>{r(!1),E.current&&!c.available&&!c.error&&(D.success(e("settings.openchamber.about.toast.latestVersion")),E.current=!1)},Ld);return()=>clearTimeout(P)}},[e,c.checking,i,c.available,c.error]);const v=c.checking||i;return j?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(Jl,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${Ql}`,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:m})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:d||e("settings.openchamber.about.state.unknown")})})]}),s.jsx(Wr,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!c.available&&!c.error&&s.jsxs(V,{type:"button",variant:"outline",size:"sm",onClick:()=>c.checkForUpdates(),disabled:v,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[v?s.jsx(L,{name:"loader",className:"size-4 animate-spin"}):s.jsx(L,{name:"refresh",className:"size-4"}),e(v?"settings.openchamber.about.state.checking":"settings.openchamber.about.actions.checkForUpdates")]}),!v&&c.available&&s.jsxs(V,{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(L,{name:"download",className:"size-4"}),e("settings.openchamber.about.actions.updateToVersion",{version:c.info?.version||""})]})]}),c.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:c.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:Jr,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(L,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Od,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(L,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:Qr,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(L,{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(Br,{open:a,onOpenChange:n,info:c.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:c.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:c.runtimeType})]}):s.jsxs(Ue,{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:Ot,children:e("settings.openchamber.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:m})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Ot,children:e("settings.openchamber.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d||e("settings.openchamber.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[c.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(L,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),!c.checking&&c.available&&s.jsxs(V,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(L,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:c.info?.version||""})]}),!c.checking&&!c.available&&!c.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),s.jsx(V,{size:"sm",variant:"outline",onClick:()=>c.checkForUpdates(),disabled:c.checking,children:e("settings.openchamber.about.actions.checkForUpdates")})]})]}),c.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:c.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:Ot,children:e("settings.openchamber.about.field.instanceUrls")}),s.jsx(Wr,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:Jr,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(L,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Qr,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(L,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]})]}),s.jsx(Br,{open:a,onOpenChange:n,info:c.info,downloading:c.downloading,downloaded:c.downloaded,progress:c.progress,error:c.error,onDownload:c.downloadUpdate,onRestart:c.restartToUpdate,runtimeType:c.runtimeType})]})},Fd=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,Us=()=>{const t=mt.c(4),e=ce(Kd),a=Qs(Ud),n=Qs(zd);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=Fd(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function Kd(t){return t.settingsProjectPath}function Ud(t){return t.projects}function zd(t){return t.activeProjectId}const wl=t=>t.trim(),Fa=t=>{const e=mt.c(40),{className:a}=t,{t:n}=rt(),i=Qs(_d),r=Us(),l=ce($d),h=xs();let d;e[0]!==i?(d=[...i].sort(Vd),e[0]=i,e[1]=d):d=e[1];const b=d;let c;e:{if(b.length===0){c=null;break e}let q;e[2]!==r||e[3]!==b?(q=b.find(S=>S.path===r)??b[0],e[2]=r,e[3]=b,e[4]=q):q=e[4],c=q}const j=c;if(h||b.length===0)return null;let m;e[5]!==j||e[6]!==n?(m=j?.label&&j.label.trim().length>0?j.label:j?.path.split("/").filter(Boolean).pop()||j?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=j,e[6]=n,e[7]=m):m=e[7];const E=m;let v;e[8]!==E?(v=wl(E),e[8]=E,e[9]=v):v=e[9];const P=v;let x;e[10]!==a?(x=ye(a),e[10]=a,e[11]=x):x=e[11];let C;e[12]!==n?(C=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=C):C=e[13];let u;e[14]!==n?(u=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=u):u=e[15];let I,F;e[16]===Symbol.for("react.memo_cache_sentinel")?(I=ye("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),F=s.jsx(L,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=I,e[17]=F):(I=e[16],F=e[17]);let A;e[18]!==P?(A=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:P}),e[18]=P,e[19]=A):A=e[19];let k;e[20]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(L,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=k):k=e[20];let g;e[21]!==A||e[22]!==C||e[23]!==u?(g=s.jsx(en,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":C,title:u,className:I,children:[F,A,k]})}),e[21]=A,e[22]=C,e[23]=u,e[24]=g):g=e[24];const w=j?.id??"";let z;e[25]!==l||e[26]!==b?(z=q=>{if(!q)return;const S=b.find(G=>G.id===q);S&&l(S.path)},e[25]=l,e[26]=b,e[27]=z):z=e[27];let N;e[28]!==b?(N=b.map(Bd),e[28]=b,e[29]=N):N=e[29];let R;e[30]!==w||e[31]!==z||e[32]!==N?(R=s.jsx(tn,{align:"start",className:"w-auto",children:s.jsx(Zl,{value:w,onValueChange:z,children:N})}),e[30]=w,e[31]=z,e[32]=N,e[33]=R):R=e[33];let y;e[34]!==g||e[35]!==R?(y=s.jsxs(sn,{children:[g,R]}),e[34]=g,e[35]=R,e[36]=y):y=e[36];let O;return e[37]!==y||e[38]!==x?(O=s.jsx("div",{className:x,children:y}),e[37]=y,e[38]=x,e[39]=O):O=e[39],O};function _d(t){return t.projects}function $d(t){return t.setSettingsProjectPath}function Vd(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function Bd(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=wl(e);return s.jsx(Yl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function Hd(t,e){return`opencode:sidebar-group:${t}:${e}`}const Yi=t=>{const e=mt.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,h=r===void 0?!0:r;let d;e[0]!==a||e[1]!==i?(d=Hd(i,a),e[0]=a,e[1]=i,e[2]=d):d=e[2];const b=d,c=o.useId();let j;e[3]!==h||e[4]!==b?(j=()=>{try{const R=localStorage.getItem(b);if(R!==null)return R==="true"}catch{}return h},e[3]=h,e[4]=b,e[5]=j):j=e[5];const[m,E]=Qe.useState(j);let v,P;e[6]!==m||e[7]!==b?(v=()=>{try{localStorage.setItem(b,String(m))}catch{}},P=[b,m],e[6]=m,e[7]=b,e[8]=v,e[9]=P):(v=e[8],P=e[9]),Qe.useEffect(v,P);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>E(Gd),e[10]=x):x=e[10];let C;e[11]===Symbol.for("react.memo_cache_sentinel")?(C=ye("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=C):C=e[11];const u=!m&&"-rotate-90";let I;e[12]!==u?(I=ye("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",u),e[12]=u,e[13]=I):I=e[13];let F;e[14]!==I?(F=s.jsx(L,{name:"arrow-down-s",className:I}),e[14]=I,e[15]=F):F=e[15];let A;e[16]!==a?(A=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=A):A=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 g;e[20]!==c||e[21]!==m||e[22]!==F||e[23]!==A||e[24]!==k?(g=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":m,"aria-controls":c,className:C,children:[F,A,k]}),e[20]=c,e[21]=m,e[22]=F,e[23]=A,e[24]=k,e[25]=g):g=e[25];const w=!m;let z;e[26]!==l||e[27]!==c||e[28]!==w?(z=s.jsx("div",{id:c,hidden:w,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]=c,e[28]=w,e[29]=z):z=e[29];let N;return e[30]!==g||e[31]!==z?(N=s.jsxs("div",{children:[g,z]}),e[30]=g,e[31]=z,e[32]=N):N=e[32],N};function Gd(t){return!t}const qd=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},Wd=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())},Yr=t=>{const e=Wd(qd(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},Jd=({onItemSelect:t})=>{const{t:e}=rt(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,h]=o.useState(null),[d,b]=o.useState(null),[c,j]=o.useState(!1),[m,E]=o.useState(null),{selectedAgentName:v,setSelectedAgent:P,setAgentDraft:x,createAgent:C,deleteAgent:u,loadAgents:I}=_n(Ms(K=>({selectedAgentName:K.selectedAgentName,setSelectedAgent:K.setSelectedAgent,setAgentDraft:K.setAgentDraft,createAgent:K.createAgent,deleteAgent:K.deleteAgent,loadAgents:K.loadAgents}))),F=Us(),A=_n(K=>Xo(K,F));o.useEffect(()=>{I(F)},[I,F]);const k="bg-background",g=()=>{const K="new-agent";let ae=K,_=1;for(;A.some(B=>B.name===ae);)ae=`${K}-${_}`,_++;x({name:ae,scope:"user"}),P(ae),t?.()},w=async K=>{if(ta(K)){D.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}h(K),b("delete")},z=async K=>{ta(K)&&(h(K),b("reset"))},N=()=>{h(null),b(null)},R=async()=>{if(!(!l||!d)){j(!0);try{const K=await u(l.name,l.scope,F);K.ok?(K.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):K.restartDeferred?D.success(e("settings.view.pendingRestart.saved")):d==="delete"?D.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):D.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),N()):d==="delete"?D.error(e("settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(K){const ae=K instanceof Error?K.message:"",_=/built-in|not deletable|not found/i.test(ae);d==="delete"?D.error(e(_?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):D.error(e("settings.agents.sidebar.toast.resetFailed"))}j(!1)}},y=K=>{const ae=K.name;let _=1,B=`${ae}-copy`;for(;A.some(X=>X.name===B);)_++,B=`${ae}-copy-${_}`;const M=K,U=K.model?.providerID&&K.model?.modelID?`${K.model.providerID}/${K.model.modelID}`:null,Y=K;x({name:B,scope:M.scope||"user",description:K.description,model:U,variant:K.variant,temperature:K.temperature,top_p:K.topP,prompt:K.prompt,mode:K.mode,permission:Yr(K.permission),disable:Y.disable}),P(B)},O=K=>{r(K.name),n(K)},q=async()=>{if(!a)return;const K=i.trim().replace(/\s+/g,"-");if(!K){D.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(K===a.name){n(null);return}if(A.some(M=>M.name===K)){D.error(e("settings.agents.sidebar.toast.agentExists"));return}const ae=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,_=a,B=await C({name:K,description:a.description,model:ae,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:Yr(a.permission),disable:_.disable,scope:_.scope},F);if(B.ok){const M=await u(a.name,_.scope,F);M.ok?(B.requiresManualRestart||M.requiresManualRestart?D.warning(e("settings.agents.page.toast.savedManualRestart")):D.success(e("settings.agents.sidebar.toast.agentRenamed",{name:K})),P(K)):D.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else D.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},S=K=>{switch(K){case"primary":return s.jsx(L,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(L,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(L,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},G=A.filter(K=>!Xl(K)),J=G.filter(ta),T=G.filter(K=>!ta(K)),{groupedCustomAgents:Q,ungroupedCustomAgents:Z}=Qe.useMemo(()=>{const K={},ae=[];for(const B of T){const M=B;M.group?(K[M.group]||(K[M.group]=[]),K[M.group].push(B)):ae.push(B)}return{groupedCustomAgents:Object.keys(K).sort((B,M)=>B.localeCompare(M)).map(B=>({name:B,agents:K[B]})),ungroupedCustomAgents:ae}},[T]);return s.jsxs("div",{className:ye("flex h-full flex-col",k),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${an} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Fa,{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:G.length})}),s.jsx(V,{size:"sm","data-settings-item":"agents.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:g,children:s.jsx(L,{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:G.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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:[J.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")}),J.map(K=>s.jsx(Di,{agent:K,isSelected:v===K.name,onSelect:()=>{P(K.name),t?.()},onReset:()=>z(K),onDuplicate:()=>y(K),getAgentModeIcon:S,isMenuOpen:m===K.name,onMenuOpenChange:ae=>E(ae?K.name:null)},K.name))]}),T.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:K,agents:ae})=>s.jsx(Yi,{label:K,count:ae.length,storageKey:"agents",children:ae.map(_=>s.jsx(Di,{agent:_,isSelected:v===_.name,onSelect:()=>{P(_.name),t?.()},onRename:()=>O(_),onDelete:()=>w(_),onDuplicate:()=>y(_),getAgentModeIcon:S,isMenuOpen:m===_.name,onMenuOpenChange:B=>E(B?_.name:null)},_.name))},K)),Z.map(K=>s.jsx(Di,{agent:K,isSelected:v===K.name,onSelect:()=>{P(K.name),t?.()},onRename:()=>O(K),onDelete:()=>w(K),onDuplicate:()=>y(K),getAgentModeIcon:S,isMenuOpen:m===K.name,onMenuOpenChange:ae=>E(ae?K.name:null)},K.name))]})]})}),s.jsx(Vt,{open:l!==null&&d!==null,onOpenChange:K=>{!K&&!c&&N()},children:s.jsxs(Bt,{className:"max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Qt,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(ds,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:N,disabled:c,children:e("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",onClick:R,disabled:c,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Vt,{open:a!==null,onOpenChange:K=>!K&&n(null),children:s.jsxs(Bt,{children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Qt,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(He,{value:i,onChange:K=>r(K.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:K=>{K.key==="Enter"&&q()}}),s.jsxs(ds,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",onClick:q,children:e("settings.common.actions.rename")})]})]})})]})},Di=t=>{const e=mt.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:h,onDuplicate:d,getAgentModeIcon:b,isMenuOpen:c,onMenuOpenChange:j}=t,{t:m}=rt(),E=a;let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=Ra(),e[0]=v):v=e[0];const P=v,[x,C]=o.useState(!1);let u;e[1]!==r||e[2]!==d||e[3]!==h||e[4]!==l||e[5]!==m?(u=ae=>s.jsxs(s.Fragment,{children:[h&&s.jsxs(ae,{onClick:_=>{_.stopPropagation(),h()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),s.jsxs(ae,{onClick:_=>{_.stopPropagation(),d()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),l&&s.jsxs(ae,{onClick:_=>{_.stopPropagation(),l()},children:[s.jsx(L,{name:"restart",className:"h-4 w-4 mr-px"}),m("settings.common.actions.reset")]}),r&&s.jsxs(ae,{onClick:_=>{_.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]}),e[1]=r,e[2]=d,e[3]=h,e[4]=l,e[5]=m,e[6]=u):u=e[6];const I=u,F=n?"bg-interactive-selection":"hover:bg-interactive-hover";let A;e[7]!==F?(A=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",F),e[7]=F,e[8]=A):A=e[8];let k;e[9]===Symbol.for("react.memo_cache_sentinel")?(k=P?void 0:ae=>{ae.preventDefault(),C(!0)},e[9]=k):k=e[9];let g;e[10]!==A?(g=s.jsx("div",{className:A,onContextMenu:k}),e[10]=A,e[11]=g):g=e[11];let w;e[12]!==a.name?(w=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=w):w=e[13];let z;e[14]!==a.mode||e[15]!==b?(z=b(a.mode),e[14]=a.mode,e[15]=b,e[16]=z):z=e[16];let N;e[17]!==a||e[18]!==E.scope||e[19]!==m?(N=(E.scope||ta(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:ta(a)?m("settings.agents.sidebar.badge.system"):E.scope}),e[17]=a,e[18]=E.scope,e[19]=m,e[20]=N):N=e[20];let R;e[21]!==w||e[22]!==z||e[23]!==N?(R=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,z,N]}),e[21]=w,e[22]=z,e[23]=N,e[24]=R):R=e[24];let y;e[25]!==a.description?(y=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=y):y=e[26];let O;e[27]!==i||e[28]!==R||e[29]!==y?(O=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:[R,y]}),e[27]=i,e[28]=R,e[29]=y,e[30]=O):O=e[30];let q;e[31]!==j?(q=ae=>{ae&&C(!1),j(ae)},e[31]=j,e[32]=q):q=e[32];let S;e[33]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(en,{asChild:!0,children:s.jsx(V,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=S):S=e[33];let G;e[34]!==I?(G=s.jsx(tn,{align:"end",className:"w-fit min-w-20",children:I(nn)}),e[34]=I,e[35]=G):G=e[35];let J;e[36]!==c||e[37]!==q||e[38]!==G?(J=s.jsxs(sn,{open:c,onOpenChange:q,children:[S,G]}),e[36]=c,e[37]=q,e[38]=G,e[39]=J):J=e[39];let T;e[40]!==O||e[41]!==J?(T=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[O,J]}),e[40]=O,e[41]=J,e[42]=T):T=e[42];let Q;e[43]!==T||e[44]!==g?(Q=s.jsx(Bn,{render:g,children:T}),e[43]=T,e[44]=g,e[45]=Q):Q=e[45];let Z;e[46]!==I?(Z=s.jsx($n,{className:"w-fit min-w-20",children:I(Vn)}),e[46]=I,e[47]=Z):Z=e[47];let K;return e[48]!==x||e[49]!==Q||e[50]!==Z?(K=s.jsxs(Hn,{open:x,onOpenChange:C,children:[Q,Z]}),e[48]=x,e[49]=Q,e[50]=Z,e[51]=K):K=e[51],K},cs=t=>{const e=mt.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:h,description:d,headerEnd:b,showSaveStatus:c}=t,j=c===void 0?!1:c,m=r!=null||d!=null||b!=null||j,E=typeof r=="string"||typeof r=="number",v=l!=null||h!=null;let P;e[0]!==i?(P=ye("h-full",i),e[0]=i,e[1]=P):P=e[1];let x;e[2]!==n?(x=ye("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=x):x=e[3];let C;e[4]!==d||e[5]!==m||e[6]!==v||e[7]!==b||e[8]!==E||e[9]!==j||e[10]!==r||e[11]!==h||e[12]!==l?(C=m&&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?E?v?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{className:ye(Ji,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:h})]}):s.jsx("h1",{className:Ji,children:r}):r:null,d!=null?typeof d=="string"||typeof d=="number"?s.jsx("p",{className:el,children:d}):d:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[b,j&&s.jsx(Yd,{})]})]}),e[4]=d,e[5]=m,e[6]=v,e[7]=b,e[8]=E,e[9]=j,e[10]=r,e[11]=h,e[12]=l,e[13]=C):C=e[13];let u;e[14]!==a||e[15]!==x||e[16]!==C?(u=s.jsxs("div",{className:x,children:[C,a]}),e[14]=a,e[15]=x,e[16]=C,e[17]=u):u=e[17];let I;return e[18]!==P||e[19]!==u?(I=s.jsx(Hs,{outerClassName:P,className:"w-full @container",children:u}),e[18]=P,e[19]=u,e[20]=I):I=e[20],I},Qd=500,Yd=()=>{const t=mt.c(13),{t:e}=rt(),a=o.useSyncExternalStore(qc,Rr,Rr),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const c=setTimeout(()=>i(!0),Qd);return()=>clearTimeout(c)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let c;t[3]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(L,{name:"error-warning",className:"size-3.5"}),t[3]=c):c=t[3];let j;t[4]!==e?(j=e("settings.common.status.saveFailed"),t[4]=e,t[5]=j):j=t[5];let m;return t[6]!==j?(m=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[c,s.jsx("span",{children:j})]}),t[6]=j,t[7]=m):m=t[7],m}if(a!=="saving"||!n)return null;let h;t[8]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=h):h=t[8];let d;t[9]!==e?(d=e("settings.common.actions.saving"),t[9]=e,t[10]=d):d=t[10];let b;return t[11]!==d?(b=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[h,s.jsx("span",{children:d})]}),t[11]=d,t[12]=b):b=t[12],b},Zd=["allow","ask","deny"],Aa=t=>t==="allow"||t==="ask"||t==="deny",Zi=()=>({global:null,keys:{}}),Xd=t=>{const e=Zi();if(t==null)return e;if(typeof t=="string")return Aa(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Aa(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(Aa(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))Aa(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},Xi=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},ep=(t,e)=>JSON.stringify(Xi(t))===JSON.stringify(Xi(e)),vn=t=>JSON.parse(JSON.stringify(t)),tp=["edit","external_directory","doom_loop","plan_enter","plan_exit"],sp=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),Zr=new Set(["write","patch","apply_patch","multiedit","invalid"]),np=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),ap=({agent:t})=>{const{t:e}=rt(),a=_n(M=>M.updateAgent),[n,i]=o.useState(Zi),[r,l]=o.useState(Zi),[h,d]=o.useState(!0),[b,c]=o.useState(!1),[j,m]=o.useState(!1),[E,v]=o.useState({}),[P,x]=o.useState([]),[C,u]=o.useState(""),[I,F]=o.useState(0),A=t.name,k=Us();o.useEffect(()=>{let M=!1;return d(!0),c(!1),(async()=>{try{const U=k,Y=U?`?directory=${encodeURIComponent(U)}`:"",X=await dt(`/api/config/agents/${encodeURIComponent(A)}/config${Y}`,{headers:{"Cache-Control":"no-cache",...U?{"x-opencode-directory":U}:{}}});if(!X.ok)throw new Error(String(X.status));const ne=await X.json().catch(()=>null);if(M)return;const te=Xd(ne?.config?.permission);i(vn(te)),l(te)}catch{M||c(!0)}finally{M||d(!1)}})(),()=>{M=!0}},[A,I,k]),o.useEffect(()=>{let M=!1;return(async()=>{try{const U=await dn.listToolIds({directory:k});!M&&Array.isArray(U)&&x(U.filter(Y=>typeof Y=="string"&&!Zr.has(Y)))}catch{}})(),()=>{M=!0}},[A,k]);const g=o.useMemo(()=>{const M=t.permission;if(!Array.isArray(M))return[];const U=[];for(const Y of M){if(!Y||typeof Y!="object")continue;const{permission:X,pattern:ne,action:te}=Y;typeof X=="string"&&typeof ne=="string"&&Aa(te)&&U.push({permission:X,pattern:ne,action:te})}return U},[t]),w=o.useCallback(M=>{const U=g.find(X=>X.permission===M&&X.pattern==="*");if(U)return U.action;const Y=g.find(X=>X.permission==="*"&&X.pattern==="*");return Y?Y.action:null},[g]),z=o.useCallback(M=>{const U=r.keys[M]?.patterns??[],Y=new Set(U.map(X=>X.pattern));return g.filter(X=>X.permission===M&&X.pattern!=="*"&&!Y.has(X.pattern))},[g,r.keys]),N=o.useMemo(()=>{const M=new Set;for(const U of P)M.add(U);for(const U of tp)M.add(U);for(const U of Object.keys(r.keys))M.add(U);for(const U of Zr)M.delete(U);return Array.from(M).sort((U,Y)=>U.localeCompare(Y))},[P,r.keys]),R=o.useMemo(()=>!ep(r,n),[r,n]),y=M=>{l(U=>({...U,global:M}))},O=(M,U)=>{l(Y=>{const X=vn(Y),ne=X.keys[M]??{action:null,patterns:[]};return ne.action=U,ne.action===null&&ne.patterns.length===0?delete X.keys[M]:X.keys[M]=ne,X})},q=(M,U,Y,X)=>{l(ne=>{const te=vn(ne),ge=te.keys[M]??{action:null,patterns:[]};return ge.patterns[U]={pattern:Y,action:X},te.keys[M]=ge,te})},S=M=>{l(U=>{const Y=vn(U),X=Y.keys[M]??{action:null,patterns:[]};return X.patterns.push({pattern:"",action:"allow"}),Y.keys[M]=X,Y}),v(U=>({...U,[M]:!0}))},G=(M,U)=>{l(Y=>{const X=vn(Y),ne=X.keys[M];return ne?(ne.patterns.splice(U,1),ne.action===null&&ne.patterns.length===0&&delete X.keys[M],X):Y})},J=()=>{const M=C.trim();!M||M==="*"||(l(U=>{if(U.keys[M])return U;const Y=vn(U);return Y.keys[M]={action:"ask",patterns:[]},Y}),v(U=>({...U,[M]:!0})),u(""))},T=async()=>{m(!0);try{const M=Xi(r),U=await a(A,{permission:M});U.ok?(i(vn(r)),D.success(U.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{m(!1)}},Q=()=>{l(vn(n))},Z=M=>e(M==="allow"?"settings.agents.page.permissionsEditor.action.allow":M==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),K=e("settings.agents.page.permissionsEditor.action.inherit"),ae=e("settings.agents.page.permissionsEditor.action.default"),_=M=>[...M?[{value:"inherit",label:M}]:[],...Zd.map(U=>({value:U,label:Z(U)}))],B=(M,U,Y,X=K)=>s.jsx(Bs,{value:M??"inherit",options:_(X),onChange:ne=>U(ne==="inherit"?null:ne),"aria-label":Y});return h?s.jsx(Ue,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:Fn,children:e("common.loading")})}):b?s.jsx(Ue,{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(V,{variant:"outline",size:"xs",onClick:()=>F(M=>M+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(Ue,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:R?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:Q,disabled:j,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(V,{size:"xs",className:"!font-normal",onClick:()=>{T()},disabled:j,children:e(j?"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:Ot,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(ts,{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:Z(w("*")??"allow")})})]}),B(r.global,y,e("settings.agents.page.permissionsEditor.defaultAria"),ae)]}),s.jsx("div",{children:N.map(M=>{const U=r.keys[M]??{action:null,patterns:[]},Y=z(M),X=sp.has(M)||U.patterns.length>0,ne=X||Y.length>0,te=E[M]===!0,ge=w(M);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:ne?()=>v(ee=>({...ee,[M]:!te})):void 0,className:ye("flex min-w-0 items-center gap-1.5 text-left",!ne&&"cursor-default"),"aria-expanded":ne?te:void 0,children:[s.jsx(L,{name:te&&ne?"arrow-down-s":"arrow-right-s",className:ye("h-3.5 w-3.5 shrink-0 text-muted-foreground",!ne&&"opacity-0")}),s.jsx("span",{className:Ot,children:np(M)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:M}),U.action===null&&ge!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:Z(ge)})}),U.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(U.patterns.length)})})]}),B(U.action,ee=>O(M,ee),e("settings.agents.page.permissionsEditor.keyAria",{key:M}))]}),te&&ne&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[U.patterns.map((ee,le)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(He,{value:ee.pattern,onChange:pe=>q(M,le,pe.target.value,ee.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(Bs,{value:ee.action,options:_(),onChange:pe=>q(M,le,ee.pattern,pe),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:M})}),s.jsx(V,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>G(M,le),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]},le)),X&&s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>S(M),children:[s.jsx(L,{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(ts,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),Y.map(ee=>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:ee.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:Z(ee.action)})]},`${ee.pattern}-${ee.action}`))]})]})]},M)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(He,{value:C,onChange:M=>u(M.target.value),onKeyDown:M=>{M.key==="Enter"&&(M.preventDefault(),J())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:J,disabled:!C.trim(),children:[s.jsx(L,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},ip=(t,e)=>{const a=na(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):[]},rp=()=>{const{t}=rt(),e=st(B=>B.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agentDraft:l,setAgentDraft:h}=_n(Ms(B=>({selectedAgentName:B.selectedAgentName,getAgentByName:B.getAgentByName,createAgent:B.createAgent,updateAgent:B.updateAgent,agentDraft:B.agentDraft,setAgentDraft:B.setAgentDraft}))),d=Us(),b=_n(B=>Xo(B,d)),c=a?n(a,d):null,j=!!(l&&l.name===a&&!c),[m,E]=o.useState(""),[v,P]=o.useState("user"),[x,C]=o.useState(""),[u,I]=o.useState("subagent"),[F,A]=o.useState(""),[k,g]=o.useState(""),[w,z]=o.useState(void 0),[N,R]=o.useState(void 0),[y,O]=o.useState(""),[q,S]=o.useState(!1),G=o.useRef(null),J=o.useMemo(()=>ip(e,F),[F,e]),T=J.length>0,Q=k||"__default",Z=T,K=o.useMemo(()=>k&&!J.includes(k)?[k,...J]:J,[k,J]);o.useEffect(()=>{if(j&&l){const B=l.name||"",M=l.scope||"user",U=l.description||"",Y=l.mode||"subagent",X=l.model||"",ne=l.variant||"",te=l.temperature??void 0,ge=l.top_p??void 0,ee=l.prompt||"";E(B),P(M),C(U),I(Y),A(X),g(ne),z(te),R(ge),O(ee),G.current={draftName:B,draftScope:M,description:U,mode:Y,model:X,variant:ne,temperature:te,topP:ge,prompt:ee};return}if(c&&a===c.name){const B=c.description||"",M=c.mode||"subagent",U=c.model?.providerID&&c.model?.modelID?`${c.model.providerID}/${c.model.modelID}`:"",Y=c.variant||"",X=c.temperature??void 0,ne=c.topP??void 0,te=c.prompt||"";C(B),I(M),A(U),g(Y),z(X),R(ne),O(te),G.current={draftName:"",draftScope:"user",description:B,mode:M,model:U,variant:Y,temperature:X,topP:ne,prompt:te}}},[l,j,c,a]);const ae=o.useMemo(()=>{const B=G.current;return B?!!(j&&(m!==B.draftName||v!==B.draftScope)||x!==B.description||u!==B.mode||F!==B.model||k!==B.variant||w!==B.temperature||N!==B.topP||y!==B.prompt):!1},[x,m,v,j,u,F,y,w,N,k]),_=async()=>{const B=j?m.trim().replace(/\s+/g,"-"):a?.trim();if(!B){D.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(j&&b.some(M=>M.name===B)){D.error(t("settings.agents.sidebar.toast.agentExists"));return}S(!0);try{const M=F.trim(),U=k.trim(),Y=y.trim(),X={name:B,...x.trim()?{description:x.trim()}:{},mode:u,model:M===""?null:M,variant:U===""?null:U||void 0,temperature:w??null,top_p:N??null,prompt:Y||(j?void 0:null),...j&&v?{scope:v}:{}};let ne;j?(ne=await i(X,d),ne.ok&&h(null)):ne=await r(B,X,d),ne.ok?ne.requiresManualRestart?D.warning(t("settings.agents.page.toast.savedManualRestart")):ne.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(t(j?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):D.error(t(j?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(M){console.error("Error saving agent:",M);const U=M instanceof Error&&M.message?M.message:t("settings.agents.page.toast.saveUnexpectedError");D.error(U)}finally{S(!1)}};return a?s.jsxs(cs,{title:j?t("settings.agents.page.title.new"):a,description:t(j?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(Ue,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[j&&s.jsxs(Yt,{settingsItem:"agents.name",label:t("settings.agents.page.field.agentName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(He,{value:m,onChange:B=>E(B.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Lt,{value:v,onValueChange:B=>P(B),children:[s.jsx(Ft,{size:qt,className:"w-fit min-w-[100px]",children:s.jsx($t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Kt,{align:"end",children:[s.jsx(pt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(pt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(Zt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(As,{value:x,onChange:B=>C(B.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(Zt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(Bs,{"aria-label":t("settings.agents.page.field.mode"),value:u,onChange:I,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(Ue,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Yt,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Ea,{providerId:na(F)?.providerId??"",modelId:na(F)?.modelId??"",onChange:(B,M)=>{A(B&&M?`${B}/${M}`:""),g("")},className:Cn})}),s.jsx(Yt,{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:Z?s.jsxs(Lt,{value:Q,onValueChange:B=>g(B==="__default"?"":B),children:[s.jsx(Ft,{size:qt,className:Pn,children:s.jsx($t,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:B=>B==="__default"?t("chat.modelControls.default"):B})}),s.jsxs(Kt,{children:[s.jsx(pt,{value:"__default",children:t("chat.modelControls.default")}),K.map(B=>s.jsx(pt,{value:B,children:B},B))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(He,{value:k,onChange:B=>g(B.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!F&&!k,className:"h-8 w-40 rounded-md px-3"}),k&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>g(""),className:vs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Yt,{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(Ps,{value:w,fallbackValue:.7,onValueChange:z,onClear:()=>z(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),w!==void 0&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>z(void 0),className:vs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Yt,{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(Ps,{value:N,fallbackValue:.9,onValueChange:R,onClear:()=>R(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),N!==void 0&&s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(void 0),className:vs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(L,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ue,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(As,{value:y,onChange:B=>O(B.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"})}),!j&&c&&s.jsx(ap,{agent:c}),s.jsx("div",{className:"pb-8",children:s.jsx(V,{onClick:_,disabled:q||!ae,size:"xs",className:"!font-normal",children:t(q?"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(L,{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")})]})})},op="~/.config/opencode/AGENTS.md",kl=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},lp=t=>t.length>0&&!t.endsWith(`
2
+ `)?`${t}
3
+ `:t,Ba={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},cp=(t,e)=>t==="custom"?e:sc(t),dp=t=>t==="custom"?"custom":tl(t)?t:"concise",Xr={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"},Mi=async(t,e)=>{Ti("saving");try{const a=await dt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(await kl(a,e));Ti("saved")}catch(a){throw Ti("error"),a}},pp=()=>{const{t}=rt(),e=ec(),[a,n]=o.useState(""),[i,r]=o.useState(!1),[l,h]=o.useState(Ba.responseStyleEnabled),[d,b]=o.useState(Ba.responseStylePreset),[c,j]=o.useState(Ba.responseStyleCustomInstructions),[m,E]=o.useState(!0),[v,P]=o.useState(!1),[x,C]=o.useState(!1),[u,I]=o.useState(""),[F,A]=o.useState(!1),k=o.useRef(null);o.useEffect(()=>{const y=new AbortController;return(async()=>{try{const[q,S]=await Promise.all([dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:y.signal}),dt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:y.signal})]);let G=Ba;if(q.ok){const J=await q.json();G={...G,optimizeSystemPrompt:J.optimizeSystemPrompt===!0,responseStyleEnabled:J.responseStyleEnabled===!0,responseStylePreset:dp(J.responseStylePreset),responseStyleCustomInstructions:typeof J.responseStyleCustomInstructions=="string"?J.responseStyleCustomInstructions:""},typeof J.globalBehaviorPrompt=="string"&&(G={...G,prompt:J.globalBehaviorPrompt})}if(!G.prompt.trim()&&S.ok){const J=await S.json();typeof J.content=="string"&&(G={...G,prompt:J.content})}n(G.prompt),r(G.optimizeSystemPrompt),A(G.optimizeSystemPrompt),h(G.responseStyleEnabled),b(G.responseStylePreset),j(G.responseStyleCustomInstructions),I(G.prompt),k.current={enabled:G.responseStyleEnabled,preset:G.responseStylePreset,custom:G.responseStyleCustomInstructions}}catch(q){q.name!=="AbortError"&&console.warn("Failed to load behavior settings:",q)}finally{E(!1)}})(),()=>y.abort()},[]),o.useEffect(()=>{if(m)return;const y=k.current;if(y&&y.enabled===l&&y.preset===d&&y.custom===c)return;const O={enabled:l,preset:d,custom:c},q=setTimeout(async()=>{try{await Mi({responseStyleEnabled:O.enabled,responseStylePreset:O.preset,responseStyleCustomInstructions:O.custom},t("settings.behavior.page.toast.saveFailed")),k.current=O}catch(S){const G=S instanceof Error?S.message:t("settings.behavior.page.toast.saveFailed");D.error(G)}},400);return()=>clearTimeout(q)},[l,d,c,m,t]);const g=cp(d,c),w=a!==u,z=i!==F,N=async()=>{P(!0);try{const y=lp(a),O=await dt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:y})});if(!O.ok)throw new Error(await kl(O,t("settings.behavior.page.toast.saveFailed")));const q=await O.json().catch(()=>null),S=ii(q,"behavior",{id:"agents-md"});await Mi({globalBehaviorPrompt:y},t("settings.behavior.page.toast.saveFailed")),n(y),I(y),D.success(t(S?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(y){console.error("Failed to save behavior:",y);const O=y instanceof Error?y.message:t("settings.behavior.page.toast.saveFailed");D.error(O)}finally{P(!1)}},R=async()=>{C(!0);try{await Mi({optimizeSystemPrompt:i},t("settings.behavior.page.toast.saveFailed")),A(i),zn("behavior",{id:"optimize-system-prompt"}),D.success(t("settings.view.pendingRestart.saved"))}catch(y){const O=y instanceof Error?y.message:t("settings.behavior.page.toast.saveFailed");D.error(O)}finally{C(!1)}};return s.jsxs(cs,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(Ue,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(xt,{checked:i,onChange:r,disabled:m||x,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(V,{type:"button",size:"xs",onClick:()=>{R()},disabled:m||x||!z,className:"!font-normal",children:t(x?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(Ue,{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:op})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(As,{value:a,onChange:y=>n(y.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:m,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(V,{onClick:N,disabled:v||!w||m,size:"xs",className:"!font-normal",children:t(v?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(Ue,{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(xt,{checked:l,onChange:h,disabled:m,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Yt,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Lt,{value:d,onValueChange:y=>b(y),disabled:m||!l,children:[s.jsx(Ft,{size:qt,className:Pn,children:s.jsx($t,{children:y=>y==="custom"?t("settings.behavior.page.responseStyle.option.custom"):tl(y)?t(Xr[y]):null})}),s.jsxs(Kt,{children:[tc.map(y=>s.jsx(pt,{value:y,children:t(Xr[y])},y)),s.jsx(pt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(As,{value:g,onChange:y=>j(y.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:m||!l||d!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},mp=t=>{const e=mt.c(176),{onItemSelect:a}=t,{t:n}=rt(),[i,r]=o.useState(null),[l,h]=o.useState(""),[d,b]=o.useState(null),[c,j]=o.useState(null),[m,E]=o.useState(!1),[v,P]=o.useState(null),{selectedCommandName:x,setSelectedCommand:C,setCommandDraft:u,createCommand:I,deleteCommand:F,loadCommands:A}=aa(Ms(up)),k=Us();let g;e[0]!==k?(g=Ie=>sl(Ie,k),e[0]=k,e[1]=g):g=e[1];const w=aa(g);let z;e[2]!==k?(z=Ie=>lr(Ie,k),e[2]=k,e[3]=z):z=e[3];const N=Vs(z),R=Vs(gp);let y,O;e[4]!==A||e[5]!==R||e[6]!==k?(y=()=>{A(k),R(k)},O=[A,R,k],e[4]=A,e[5]=R,e[6]=k,e[7]=y,e[8]=O):(y=e[7],O=e[8]),o.useEffect(y,O);let q;e[9]!==N?(q=new Set(N.map(hp)),e[9]=N,e[10]=q):q=e[10];const S=q;let G;if(e[11]!==w||e[12]!==S){let Ie;e[14]!==S?(Ie=It=>!S.has(It.name),e[14]=S,e[15]=Ie):Ie=e[15],G=w.filter(Ie),e[11]=w,e[12]=S,e[13]=G}else G=e[13];const J=G;let T,Q;e[16]!==x||e[17]!==C||e[18]!==S?(T=()=>{x&&S.has(x)&&C(null)},Q=[x,C,S],e[16]=x,e[17]=C,e[18]=S,e[19]=T,e[20]=Q):(T=e[19],Q=e[20]),o.useEffect(T,Q);let Z;e[21]!==w||e[22]!==a||e[23]!==u||e[24]!==C?(Z=()=>{let Ie="new-command",It=1;for(;w.some(Ne=>Ne.name===Ie);)Ie=`new-command-${It}`,It++;u({name:Ie,scope:"user"}),C(Ie),a?.()},e[21]=w,e[22]=a,e[23]=u,e[24]=C,e[25]=Z):Z=e[25];const K=Z;let ae;e[26]!==n?(ae=async Ie=>{if(sa(Ie)){D.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}b(Ie),j("delete")},e[26]=n,e[27]=ae):ae=e[27];const _=ae;let B;e[28]===Symbol.for("react.memo_cache_sentinel")?(B=async Ie=>{sa(Ie)&&(b(Ie),j("reset"))},e[28]=B):B=e[28];const M=B;let U;e[29]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{b(null),j(null)},e[29]=U):U=e[29];const Y=U;let X;e[30]!==d||e[31]!==c||e[32]!==F||e[33]!==k||e[34]!==n?(X=async()=>{if(!d||!c)return;E(!0),await F(d.name,k)?(c==="delete"?D.success(n("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):D.success(n("settings.commands.sidebar.toast.commandReset",{name:d.name})),Y()):c==="delete"?D.error(n("settings.commands.sidebar.toast.deleteFailed")):D.error(n("settings.commands.sidebar.toast.resetFailed")),E(!1)},e[30]=d,e[31]=c,e[32]=F,e[33]=k,e[34]=n,e[35]=X):X=e[35];const ne=X;let te;e[36]!==w||e[37]!==u||e[38]!==C?(te=Ie=>{const It=Ie.name;let Ne=1,Ct=`${It}-copy`;for(;w.some(W=>W.name===Ct);)Ne++,Ct=`${It}-copy-${Ne}`;u({name:Ct,scope:Ie.scope||"user",description:Ie.description,template:Ie.template,agent:Ie.agent,model:Ie.model}),C(Ct)},e[36]=w,e[37]=u,e[38]=C,e[39]=te):te=e[39];const ge=te;let ee;e[40]===Symbol.for("react.memo_cache_sentinel")?(ee=Ie=>{h(Ie.name),r(Ie)},e[40]=ee):ee=e[40];const le=ee;let pe;e[41]!==w||e[42]!==I||e[43]!==F||e[44]!==i||e[45]!==l||e[46]!==C||e[47]!==k||e[48]!==n?(pe=async()=>{if(!i)return;const Ie=l.trim().replace(/\s+/g,"-");if(!Ie){D.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ie===i.name){r(null);return}if(w.some(Ne=>Ne.name===Ie)){D.error(n("settings.commands.sidebar.toast.commandExists"));return}await I({name:Ie,description:i.description,template:i.template,agent:i.agent,model:i.model},k)?await F(i.name,k)?(D.success(`Command renamed to "${Ie}"`),C(Ie)):D.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):D.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[41]=w,e[42]=I,e[43]=F,e[44]=i,e[45]=l,e[46]=C,e[47]=k,e[48]=n,e[49]=pe):pe=e[49];const ie=pe;let je,Se,Ce,xe,Re,Oe;if(e[50]!==J||e[51]!==K||e[52]!==_||e[53]!==ge||e[54]!==a||e[55]!==v||e[56]!==x||e[57]!==C||e[58]!==n){const Ie=J.filter(sa),It=J.filter(fp);e[65]===Symbol.for("react.memo_cache_sentinel")?(Re=ye("flex h-full flex-col","bg-background"),e[65]=Re):Re=e[65];let Ne;e[66]!==n?(Ne=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Ne):Ne=e[67];let Ct;e[68]!==Ne?(Ct=s.jsx("h2",{className:`${an} mb-3`,children:Ne}),e[68]=Ne,e[69]=Ct):Ct=e[69];let W;e[70]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(Fa,{className:"mb-3"}),e[70]=W):W=e[70];let me;e[71]!==J.length||e[72]!==n?(me=n("settings.commands.sidebar.total",{count:J.length}),e[71]=J.length,e[72]=n,e[73]=me):me=e[73];let Ee;e[74]!==me?(Ee=s.jsx("span",{className:"typography-meta text-muted-foreground",children:me}),e[74]=me,e[75]=Ee):Ee=e[75];let Pe;e[76]===Symbol.for("react.memo_cache_sentinel")?(Pe=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Pe):Pe=e[76];let lt;e[77]!==K?(lt=s.jsx(V,{size:"sm","data-settings-item":"commands.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:K,children:Pe}),e[77]=K,e[78]=lt):lt=e[78];let it;e[79]!==Ee||e[80]!==lt?(it=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ee,lt]}),e[79]=Ee,e[80]=lt,e[81]=it):it=e[81],e[82]!==Ct||e[83]!==it?(Oe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Ct,W,it]}),e[82]=Ct,e[83]=it,e[84]=Oe):Oe=e[84],je=Hs,Se="flex-1 min-h-0",Ce="space-y-1 px-3 py-2",xe=J.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[Ie.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.builtIn")}),[...Ie].sort(xp).map(Ve=>s.jsx(eo,{command:Ve,isSelected:x===Ve.name,onSelect:()=>{C(Ve.name),a?.()},onReset:()=>M(Ve),onDuplicate:()=>ge(Ve),isMenuOpen:v===Ve.name,onMenuOpenChange:Nt=>P(Nt?Ve.name:null)},Ve.name))]}),It.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")}),[...It].sort(bp).map(Ve=>s.jsx(eo,{command:Ve,isSelected:x===Ve.name,onSelect:()=>{C(Ve.name),a?.()},onRename:()=>le(Ve),onDelete:()=>_(Ve),onDuplicate:()=>ge(Ve),isMenuOpen:v===Ve.name,onMenuOpenChange:Nt=>P(Nt?Ve.name:null)},Ve.name))]})]}),e[50]=J,e[51]=K,e[52]=_,e[53]=ge,e[54]=a,e[55]=v,e[56]=x,e[57]=C,e[58]=n,e[59]=je,e[60]=Se,e[61]=Ce,e[62]=xe,e[63]=Re,e[64]=Oe}else je=e[59],Se=e[60],Ce=e[61],xe=e[62],Re=e[63],Oe=e[64];let fe;e[85]!==je||e[86]!==Se||e[87]!==Ce||e[88]!==xe?(fe=s.jsx(je,{outerClassName:Se,className:Ce,children:xe}),e[85]=je,e[86]=Se,e[87]=Ce,e[88]=xe,e[89]=fe):fe=e[89];const be=d!==null&&c!==null;let De;e[90]!==m?(De=Ie=>{!Ie&&!m&&Y()},e[90]=m,e[91]=De):De=e[91];let _e;e[92]!==c||e[93]!==n?(_e=n(c==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=c,e[93]=n,e[94]=_e):_e=e[94];let Le;e[95]!==_e?(Le=s.jsx(Jt,{children:_e}),e[95]=_e,e[96]=Le):Le=e[96];let qe;e[97]!==d?.name||e[98]!==c||e[99]!==n?(qe=c==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[97]=d?.name,e[98]=c,e[99]=n,e[100]=qe):qe=e[100];let Ke;e[101]!==qe?(Ke=s.jsx(Qt,{children:qe}),e[101]=qe,e[102]=Ke):Ke=e[102];let Xe;e[103]!==Le||e[104]!==Ke?(Xe=s.jsxs(Wt,{children:[Le,Ke]}),e[103]=Le,e[104]=Ke,e[105]=Xe):Xe=e[105];let We;e[106]!==n?(We=n("settings.common.actions.cancel"),e[106]=n,e[107]=We):We=e[107];let Ze;e[108]!==m||e[109]!==We?(Ze=s.jsx(V,{size:"sm",variant:"ghost",onClick:Y,disabled:m,children:We}),e[108]=m,e[109]=We,e[110]=Ze):Ze=e[110];let we;e[111]!==c||e[112]!==n?(we=n(c==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=c,e[112]=n,e[113]=we):we=e[113];let Je;e[114]!==ne||e[115]!==m||e[116]!==we?(Je=s.jsx(V,{size:"sm",onClick:ne,disabled:m,children:we}),e[114]=ne,e[115]=m,e[116]=we,e[117]=Je):Je=e[117];let Me;e[118]!==Ze||e[119]!==Je?(Me=s.jsxs(ds,{children:[Ze,Je]}),e[118]=Ze,e[119]=Je,e[120]=Me):Me=e[120];let ve;e[121]!==Xe||e[122]!==Me?(ve=s.jsxs(Bt,{className:"max-w-md",children:[Xe,Me]}),e[121]=Xe,e[122]=Me,e[123]=ve):ve=e[123];let $e;e[124]!==be||e[125]!==De||e[126]!==ve?($e=s.jsx(Vt,{open:be,onOpenChange:De,children:ve}),e[124]=be,e[125]=De,e[126]=ve,e[127]=$e):$e=e[127];const $=i!==null;let de;e[128]===Symbol.for("react.memo_cache_sentinel")?(de=Ie=>!Ie&&r(null),e[128]=de):de=e[128];let ue;e[129]!==n?(ue=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=ue):ue=e[130];let ke;e[131]!==ue?(ke=s.jsx(Jt,{children:ue}),e[131]=ue,e[132]=ke):ke=e[132];const oe=i?.name??"";let Ae;e[133]!==n||e[134]!==oe?(Ae=n("settings.commands.sidebar.renameDialog.description",{name:oe}),e[133]=n,e[134]=oe,e[135]=Ae):Ae=e[135];let H;e[136]!==Ae?(H=s.jsx(Qt,{children:Ae}),e[136]=Ae,e[137]=H):H=e[137];let ze;e[138]!==ke||e[139]!==H?(ze=s.jsxs(Wt,{children:[ke,H]}),e[138]=ke,e[139]=H,e[140]=ze):ze=e[140];let tt;e[141]===Symbol.for("react.memo_cache_sentinel")?(tt=Ie=>h(Ie.target.value),e[141]=tt):tt=e[141];let Fe;e[142]!==n?(Fe=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=Fe):Fe=e[143];let at;e[144]!==ie?(at=Ie=>{Ie.key==="Enter"&&ie()},e[144]=ie,e[145]=at):at=e[145];let wt;e[146]!==l||e[147]!==Fe||e[148]!==at?(wt=s.jsx(He,{value:l,onChange:tt,placeholder:Fe,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:at}),e[146]=l,e[147]=Fe,e[148]=at,e[149]=wt):wt=e[149];let bt;e[150]===Symbol.for("react.memo_cache_sentinel")?(bt=()=>r(null),e[150]=bt):bt=e[150];let ut;e[151]!==n?(ut=n("settings.common.actions.cancel"),e[151]=n,e[152]=ut):ut=e[152];let gt;e[153]!==ut?(gt=s.jsx(V,{size:"sm",variant:"ghost",onClick:bt,children:ut}),e[153]=ut,e[154]=gt):gt=e[154];let Pt;e[155]!==n?(Pt=n("settings.common.actions.rename"),e[155]=n,e[156]=Pt):Pt=e[156];let jt;e[157]!==ie||e[158]!==Pt?(jt=s.jsx(V,{size:"sm",onClick:ie,children:Pt}),e[157]=ie,e[158]=Pt,e[159]=jt):jt=e[159];let Et;e[160]!==gt||e[161]!==jt?(Et=s.jsxs(ds,{children:[gt,jt]}),e[160]=gt,e[161]=jt,e[162]=Et):Et=e[162];let Ye;e[163]!==ze||e[164]!==wt||e[165]!==Et?(Ye=s.jsxs(Bt,{children:[ze,wt,Et]}),e[163]=ze,e[164]=wt,e[165]=Et,e[166]=Ye):Ye=e[166];let Ge;e[167]!==$||e[168]!==Ye?(Ge=s.jsx(Vt,{open:$,onOpenChange:de,children:Ye}),e[167]=$,e[168]=Ye,e[169]=Ge):Ge=e[169];let ct;return e[170]!==Re||e[171]!==Oe||e[172]!==fe||e[173]!==$e||e[174]!==Ge?(ct=s.jsxs("div",{className:Re,children:[Oe,fe,$e,Ge]}),e[170]=Re,e[171]=Oe,e[172]=fe,e[173]=$e,e[174]=Ge,e[175]=ct):ct=e[175],ct},eo=t=>{const e=mt.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:h,onDuplicate:d,isMenuOpen:b,onMenuOpenChange:c}=t,{t:j}=rt();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=Ra(),e[0]=m):m=e[0];const E=m,[v,P]=o.useState(!1);let x;e[1]!==r||e[2]!==d||e[3]!==h||e[4]!==l||e[5]!==j?(x=Q=>s.jsxs(s.Fragment,{children:[h&&s.jsxs(Q,{onClick:Z=>{Z.stopPropagation(),h()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),j("settings.common.actions.rename")]}),s.jsxs(Q,{onClick:Z=>{Z.stopPropagation(),d()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),j("settings.common.actions.duplicate")]}),l&&s.jsxs(Q,{onClick:Z=>{Z.stopPropagation(),l()},children:[s.jsx(L,{name:"restart",className:"h-4 w-4 mr-px"}),j("settings.common.actions.reset")]}),r&&s.jsxs(Q,{onClick:Z=>{Z.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),j("settings.common.actions.delete")]})]}),e[1]=r,e[2]=d,e[3]=h,e[4]=l,e[5]=j,e[6]=x):x=e[6];const C=x,u=n?"bg-interactive-selection":"hover:bg-interactive-hover";let I;e[7]!==u?(I=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",u),e[7]=u,e[8]=I):I=e[8];let F;e[9]===Symbol.for("react.memo_cache_sentinel")?(F=E?void 0:Q=>{Q.preventDefault(),P(!0)},e[9]=F):F=e[9];let A;e[10]!==I?(A=s.jsx("div",{className:I,onContextMenu:F}),e[10]=I,e[11]=A):A=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 g;e[14]!==a||e[15]!==j?(g=(a.scope||sa(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:sa(a)?j("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=j,e[16]=g):g=e[16];let w;e[17]!==k||e[18]!==g?(w=s.jsxs("div",{className:"flex items-center gap-2",children:[k,g]}),e[17]=k,e[18]=g,e[19]=w):w=e[19];let z;e[20]!==a.description?(z=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=z):z=e[21];let N;e[22]!==i||e[23]!==z||e[24]!==w?(N=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:[w,z]}),e[22]=i,e[23]=z,e[24]=w,e[25]=N):N=e[25];let R;e[26]!==c?(R=Q=>{Q&&P(!1),c(Q)},e[26]=c,e[27]=R):R=e[27];let y;e[28]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(en,{asChild:!0,children:s.jsx(V,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=y):y=e[28];let O;e[29]!==C?(O=s.jsx(tn,{align:"end",className:"w-fit min-w-20",children:C(nn)}),e[29]=C,e[30]=O):O=e[30];let q;e[31]!==b||e[32]!==R||e[33]!==O?(q=s.jsxs(sn,{open:b,onOpenChange:R,children:[y,O]}),e[31]=b,e[32]=R,e[33]=O,e[34]=q):q=e[34];let S;e[35]!==N||e[36]!==q?(S=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[N,q]}),e[35]=N,e[36]=q,e[37]=S):S=e[37];let G;e[38]!==S||e[39]!==A?(G=s.jsx(Bn,{render:A,children:S}),e[38]=S,e[39]=A,e[40]=G):G=e[40];let J;e[41]!==C?(J=s.jsx($n,{className:"w-fit min-w-20",children:C(Vn)}),e[41]=C,e[42]=J):J=e[42];let T;return e[43]!==v||e[44]!==G||e[45]!==J?(T=s.jsxs(Hn,{open:v,onOpenChange:P,children:[G,J]}),e[43]=v,e[44]=G,e[45]=J,e[46]=T):T=e[46],T};function up(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function gp(t){return t.loadSkills}function hp(t){return t.name}function fp(t){return!sa(t)}function xp(t,e){return t.name.localeCompare(e.name)}function bp(t,e){return t.name.localeCompare(e.name)}const vp=()=>{const{t}=rt(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:r,setCommandDraft:l}=aa(Ms(y=>({selectedCommandName:y.selectedCommandName,getCommandByName:y.getCommandByName,createCommand:y.createCommand,updateCommand:y.updateCommand,commandDraft:y.commandDraft,setCommandDraft:y.setCommandDraft}))),h=Us(),d=aa(y=>sl(y,h)),b=e?a(e,h):null,c=!!(r&&r.name===e&&!b),[j,m]=o.useState(""),[E,v]=o.useState("user"),[P,x]=o.useState(""),[C,u]=o.useState(""),[I,F]=o.useState(""),[A,k]=o.useState(""),[g,w]=o.useState(!1),z=o.useRef(null);o.useEffect(()=>{if(c&&r){const y=r.name||"",O=r.scope||"user",q=r.description||"",S=r.agent||"",G=r.model||"",J=r.template||"";m(y),v(O),x(q),u(S),F(G),k(J),z.current={draftName:y,draftScope:O,description:q,agent:S,model:G,template:J}}else if(b){const y=b.description||"",O=b.agent||"",q=b.model||"",S=b.template||"";x(y),u(O),F(q),k(S),z.current={draftName:"",draftScope:"user",description:y,agent:O,model:q,template:S}}},[b,c,e,d,r]);const N=o.useMemo(()=>{const y=z.current;return y?!!(c&&(j!==y.draftName||E!==y.draftScope)||P!==y.description||C!==y.agent||I!==y.model||A!==y.template):!1},[C,P,j,E,c,I,A]),R=async()=>{const y=c?j.trim().replace(/\s+/g,"-"):e?.trim();if(!y){D.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!A.trim()){D.error(t("settings.commands.page.toast.templateRequired"));return}if(c&&d.some(O=>O.name===y)){D.error(t("settings.commands.sidebar.toast.commandExists"));return}w(!0);try{const O=C.trim(),q=I.trim(),S=A.trim(),G={name:y,description:P.trim()||void 0,agent:O===""?null:O,model:q===""?null:q,template:S,scope:c?E:void 0};let J;if(c?(J=await n(G,h),J&&l(null)):J=await i(y,G,h),J){const T=pn.getState().changes.some(Q=>Q.scope==="commands"&&Q.id.startsWith(`commands:${y}:`));D.success(t(T?"settings.view.pendingRestart.saved":c?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else D.error(t(c?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(O){console.error("Error saving command:",O),D.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{w(!1)}};return e?s.jsxs(cs,{title:c?t("settings.commands.page.title.new"):`/${e}`,description:t(c?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(Ue,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[c&&s.jsxs(Yt,{settingsItem:"commands.name",label:t("settings.commands.page.field.commandName"),children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(He,{value:j,onChange:y=>m(y.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Lt,{value:E,onValueChange:y=>v(y),children:[s.jsx(Ft,{size:qt,className:"w-fit min-w-[100px]",children:s.jsx($t,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(Kt,{align:"end",children:[s.jsx(pt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(pt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{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:P,onChange:y=>x(y.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(Ue,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Yt,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(nl,{agentName:C,onChange:y=>u(y),className:Cn})}),s.jsx(Yt,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Ea,{providerId:na(I)?.providerId??"",modelId:na(I)?.modelId??"",onChange:(y,O)=>{F(y&&O?`${y}/${O}`:"")},className:Cn})})]}),s.jsxs(Ue,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(As,{value:A,onChange:y=>k(y.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(V,{onClick:R,disabled:g||!N,size:"xs",className:"!font-normal",children:t(g?"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(L,{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")})]})})},to=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},so=t=>{const e=mt.c(5),{tone:a,enabled:n}=t;if(!n){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let i;e[1]!==a?(i=ye("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[a]),e[1]=a,e[2]=i):i=e[2];let r;return e[3]!==i?(r=s.jsx("span",{className:i}),e[3]=i,e[4]=r):r=e[4],r},yp=t=>{const e=mt.c(124),{onItemSelect:a}=t,{t:n}=rt(),{selectedMcpName:i,setSelectedMcp:r,setMcpDraft:l,loadMcpConfigs:h,deleteMcp:d}=ia(Ms(jp)),b=Us();let c;e[0]!==b?(c=oe=>al(oe,b),e[0]=b,e[1]=c):c=e[1];const j=ia(c);let m;e[2]!==b?(m=oe=>oe.getStatusForDirectory(b),e[2]=b,e[3]=m):m=e[3];const E=Rs(m),v=Rs(wp),P=Rs(kp),[x,C]=o.useState(null),[u,I]=o.useState(!1),[F,A]=o.useState(null),[k,g]=o.useState(null),[w,z]=o.useState(!1);let N;e[4]!==j?(N=j.filter(Np),e[4]=j,e[5]=N):N=e[5];const R=N;let y;e[6]!==j?(y=j.filter(Sp),e[6]=j,e[7]=y):y=e[7];const O=y;let q,S;e[8]!==h||e[9]!==b?(q=()=>{h({directory:b})},S=[h,b],e[8]=h,e[9]=b,e[10]=q,e[11]=S):(q=e[10],S=e[11]),o.useEffect(q,S);let G;e[12]!==P||e[13]!==w||e[14]!==v||e[15]!==b?(G=()=>{if(w)return;z(!0);const oe=new Promise(Cp);Promise.all([v({directory:b,silent:!0}),oe]).then(()=>{const Ae=P(b);Ae&&D.error(Ae)}).finally(()=>{z(!1)})},e[12]=P,e[13]=w,e[14]=v,e[15]=b,e[16]=G):G=e[16];const J=G;let T;e[17]!==j||e[18]!==a||e[19]!==l||e[20]!==r?(T=()=>{let oe="new-mcp-server",Ae=1;for(;j.some(ze=>ze.name===oe);)oe=`new-mcp-server-${Ae}`,Ae++;l({name:oe,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),r(oe),a?.()},e[17]=j,e[18]=a,e[19]=l,e[20]=r,e[21]=T):T=e[21];const Q=T;let Z;e[22]!==d||e[23]!==x||e[24]!==b||e[25]!==n?(Z=async()=>{if(!x)return;I(!0);const oe=await d(x.name,b);oe.ok?oe.reloadFailed?D.warning(oe.message||`MCP server "${x.name}" deleted, but OpenCode reload failed`,{description:oe.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):D.success(oe.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:x.name})):D.error(n("settings.mcp.sidebar.toast.deleteFailed")),C(null),I(!1)},e[22]=d,e[23]=x,e[24]=b,e[25]=n,e[26]=Z):Z=e[26];const K=Z;let ae;e[27]!==n?(ae=(oe,Ae)=>s.jsxs(Ae,{onClick:H=>{H.stopPropagation(),C(oe)},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=ae):ae=e[28];const _=ae;let B;e[29]===Symbol.for("react.memo_cache_sentinel")?(B=ye("flex h-full flex-col","bg-background"),e[29]=B):B=e[29];let M;e[30]!==n?(M=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=M):M=e[31];let U;e[32]!==M?(U=s.jsx("h2",{className:an,children:M}),e[32]=M,e[33]=U):U=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 ne=w&&"animate-spin";let te;e[38]!==ne?(te=ye("h-4 w-4",ne),e[38]=ne,e[39]=te):te=e[39];let ge;e[40]!==te?(ge=s.jsx(L,{name:"refresh",className:te}),e[40]=te,e[41]=ge):ge=e[41];let ee;e[42]!==J||e[43]!==w||e[44]!==Y||e[45]!==X||e[46]!==ge?(ee=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:w,onClick:J,"aria-label":Y,title:X,children:ge}),e[42]=J,e[43]=w,e[44]=Y,e[45]=X,e[46]=ge,e[47]=ee):ee=e[47];let le;e[48]!==U||e[49]!==ee?(le=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[U,ee]}),e[48]=U,e[49]=ee,e[50]=le):le=e[50];let pe;e[51]===Symbol.for("react.memo_cache_sentinel")?(pe=s.jsx(Fa,{className:"mb-3"}),e[51]=pe):pe=e[51];let ie;e[52]!==j.length||e[53]!==n?(ie=n("settings.mcp.sidebar.total",{count:j.length}),e[52]=j.length,e[53]=n,e[54]=ie):ie=e[54];let je;e[55]!==ie?(je=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ie}),e[55]=ie,e[56]=je):je=e[56];let Se;e[57]!==n?(Se=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=Se):Se=e[58];let Ce;e[59]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[59]=Ce):Ce=e[59];let xe;e[60]!==Q||e[61]!==Se?(xe=s.jsx(V,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:Q,title:Se,children:Ce}),e[60]=Q,e[61]=Se,e[62]=xe):xe=e[62];let Re;e[63]!==je||e[64]!==xe?(Re=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[je,xe]}),e[63]=je,e[64]=xe,e[65]=Re):Re=e[65];let Oe;e[66]!==le||e[67]!==Re?(Oe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[le,pe,Re]}),e[66]=le,e[67]=Re,e[68]=Oe):Oe=e[68];let fe;e[69]!==j.length||e[70]!==E||e[71]!==a||e[72]!==F||e[73]!==R||e[74]!==_||e[75]!==k||e[76]!==i||e[77]!==l||e[78]!==r||e[79]!==n||e[80]!==O?(fe=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:j.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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:[R.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")}),R.map(oe=>{const Ae=E[oe.name],H=to(Ae?.status),ze=i===oe.name,tt=Ra();return s.jsxs(Hn,{open:k===oe.name,onOpenChange:Fe=>g(Fe?oe.name:null),children:[s.jsxs(Bn,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",ze?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:tt?void 0:Fe=>{Fe.preventDefault(),g(oe.name)}}),children:[s.jsxs("button",{onClick:()=>{r(oe.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(so,{tone:H,enabled:oe.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:oe.name}),s.jsx("span",{title:oe.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:oe.type==="local"?s.jsx(L,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(L,{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:oe.type==="local"?oe.command?.join(" ")??"":oe.url??""})]}),s.jsxs(sn,{open:F===oe.name,onOpenChange:Fe=>{Fe&&g(null),A(Fe?oe.name:null)},children:[s.jsx(en,{asChild:!0,children:s.jsx(V,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(tn,{align:"end",className:"w-fit min-w-20",children:_(oe,nn)})]})]}),s.jsx($n,{className:"w-fit min-w-20",children:_(oe,Vn)})]},oe.name)})]}),O.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")}),O.map(oe=>{const Ae=E[oe.name],H=to(Ae?.status),ze=i===oe.name,tt=Ra();return s.jsxs(Hn,{open:k===oe.name,onOpenChange:Fe=>g(Fe?oe.name:null),children:[s.jsxs(Bn,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",ze?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:tt?void 0:Fe=>{Fe.preventDefault(),g(oe.name)}}),children:[s.jsxs("button",{onClick:()=>{r(oe.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(so,{tone:H,enabled:oe.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:oe.name}),s.jsx("span",{title:oe.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:oe.type==="local"?s.jsx(L,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(L,{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:oe.type==="local"?oe.command?.join(" ")??"":oe.url??""})]}),s.jsxs(sn,{open:F===oe.name,onOpenChange:Fe=>{Fe&&g(null),A(Fe?oe.name:null)},children:[s.jsx(en,{asChild:!0,children:s.jsx(V,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(tn,{align:"end",className:"w-fit min-w-20",children:_(oe,nn)})]})]}),s.jsx($n,{className:"w-fit min-w-20",children:_(oe,Vn)})]},oe.name)})]})]})}),e[69]=j.length,e[70]=E,e[71]=a,e[72]=F,e[73]=R,e[74]=_,e[75]=k,e[76]=i,e[77]=l,e[78]=r,e[79]=n,e[80]=O,e[81]=fe):fe=e[81];const be=x!==null;let De;e[82]!==u?(De=oe=>{!oe&&!u&&C(null)},e[82]=u,e[83]=De):De=e[83];let _e;e[84]!==n?(_e=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=_e):_e=e[85];let Le;e[86]!==_e?(Le=s.jsx(Jt,{children:_e}),e[86]=_e,e[87]=Le):Le=e[87];const qe=x?.name||"";let Ke;e[88]!==n||e[89]!==qe?(Ke=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:qe}),e[88]=n,e[89]=qe,e[90]=Ke):Ke=e[90];let Xe;e[91]===Symbol.for("react.memo_cache_sentinel")?(Xe=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=Xe):Xe=e[91];let We;e[92]!==Ke?(We=s.jsxs(Qt,{children:[Ke," ",Xe,"."]}),e[92]=Ke,e[93]=We):We=e[93];let Ze;e[94]!==Le||e[95]!==We?(Ze=s.jsxs(Wt,{children:[Le,We]}),e[94]=Le,e[95]=We,e[96]=Ze):Ze=e[96];let we;e[97]===Symbol.for("react.memo_cache_sentinel")?(we=()=>C(null),e[97]=we):we=e[97];let Je;e[98]!==n?(Je=n("settings.common.actions.cancel"),e[98]=n,e[99]=Je):Je=e[99];let Me;e[100]!==u||e[101]!==Je?(Me=s.jsx(V,{size:"sm",variant:"ghost",onClick:we,disabled:u,children:Je}),e[100]=u,e[101]=Je,e[102]=Me):Me=e[102];let ve;e[103]!==u||e[104]!==n?(ve=n(u?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=u,e[104]=n,e[105]=ve):ve=e[105];let $e;e[106]!==K||e[107]!==u||e[108]!==ve?($e=s.jsx(V,{size:"sm",onClick:K,disabled:u,children:ve}),e[106]=K,e[107]=u,e[108]=ve,e[109]=$e):$e=e[109];let $;e[110]!==Me||e[111]!==$e?($=s.jsxs(ds,{children:[Me,$e]}),e[110]=Me,e[111]=$e,e[112]=$):$=e[112];let de;e[113]!==Ze||e[114]!==$?(de=s.jsxs(Bt,{className:"max-w-md",children:[Ze,$]}),e[113]=Ze,e[114]=$,e[115]=de):de=e[115];let ue;e[116]!==be||e[117]!==De||e[118]!==de?(ue=s.jsx(Vt,{open:be,onOpenChange:De,children:de}),e[116]=be,e[117]=De,e[118]=de,e[119]=ue):ue=e[119];let ke;return e[120]!==Oe||e[121]!==fe||e[122]!==ue?(ke=s.jsxs("div",{className:B,children:[Oe,fe,ue]}),e[120]=Oe,e[121]=fe,e[122]=ue,e[123]=ke):ke=e[123],ke};function jp(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function wp(t){return t.refresh}function kp(t){return t.getErrorForDirectory}function Np(t){return t.scope==="project"}function Sp(t){return t.scope!=="project"}function Cp(t){return setTimeout(t,500)}function Zs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ja(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Ys(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Ha(t,e,a){const n=Pp(a),i=typeof a.url=="string"?a.url.trim():"",r=no(a,"env","environment"),l=no(a,"headers"),h=Ip(a),d=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",b=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",c=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",j=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",m=Ap(a),E=Ep(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:h,oauthClientId:d,oauthClientSecret:b,oauthScope:c,oauthRedirectUri:j,timeout:m,enabled:E}}function Pp(t){const e=t.command,a=t.args;if(ja(e)&&ja(a))return[...e,...a];if(ja(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return ja(a)?[...n,...a]:n}return ja(a)?a:[]}function no(t,...e){for(const a of e){const n=t[a];if(!Zs(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 Ip(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!Zs(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 Ap(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 Ep(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function Tp(t){const e=t.mcpServers;if(Zs(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(Zs(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"&&Zs(i)});if(a.length===1){const n=a[0],i=t[n];if(Nl(i))return{name:n,entry:i}}return null}function Nl(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function Dp(t,e){let a;try{const h=t.trim();if(!h)return Ys("No JSON content provided");a=JSON.parse(h)}catch(h){return Ys(h instanceof Error?`Invalid JSON: ${h.message}`:"Invalid JSON")}if(!Zs(a))return Ys("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(Zs(i)){const h=Object.keys(i);if(h.length===0)return Ys("mcpServers object is empty",a);if(h.length>1)return Ys("Paste one server at a time. Found "+h.length+" servers in mcpServers",a);const d=h[0],b=i[d];return Zs(b)?Ha(d,Ga(b),b):Ys("Server entry is not a valid object",a)}const r=n.mcp;if(Zs(r)){const h=Object.keys(r);if(h.length===0)return Ys("mcp object is empty",a);if(h.length>1)return Ys("Paste one server at a time. Found "+h.length+" servers in mcp",a);const d=h[0],b=r[d];return Zs(b)?Ha(d,Ga(b),b):Ys("Server entry in mcp is not a valid object",a)}const l=Tp(n);if(l)return Ha(l.name,Ga(l.entry),l.entry);if(Nl(n)){const h=Ga(n),d=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Ha(d,h,n)}return Ys("No recognizable MCP server configuration found in JSON",a)}function Ga(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 Mp(t,e,a){const n=a?.isNewServer??!1,i=t.name,r=n&&i?i:e.name??"";return{...e,name:r,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}function Sl(t){const e=[];let a="",n=!1,i=!1;for(let r=0;r<t.length;r++){const l=t[r];if(l==="'"&&!i){n=!n;continue}if(l==='"'&&!n){i=!i;continue}if((l===" "||l===" ")&&!n&&!i){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function Rp(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:ic(a.searchParams),stateKey:il(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Op=t=>{const e=mt.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[h,d]=o.useState(l),b=o.useRef(a);let c,j;e[2]!==a?(c=()=>{JSON.stringify(b.current)!==JSON.stringify(a)&&(b.current=a,d(a.join(`
5
+ `)))},j=[a],e[2]=a,e[3]=c,e[4]=j):(c=e[3],j=e[4]),o.useEffect(c,j);let m;e[5]!==n||e[6]!==r?(m=k=>{const g=k.split(`
6
+ `).filter(Vp);if(r&&g.length===1&&/^https?:\/\/\S+$/i.test(g[0].trim())){r(g[0].trim());return}n(g)},e[5]=n,e[6]=r,e[7]=m):m=e[7];const E=m;let v;e[8]!==n?(v=k=>{const w=k.clipboardData.getData("text").trim();if(!w||w.includes(`
7
+ `)||!/\s/.test(w))return;const z=k.currentTarget;if(z.selectionStart!==0||z.selectionEnd!==z.value.length)return;k.preventDefault();const N=Sl(w);d(N.join(`
8
+ `)),n(N)},e[8]=n,e[9]=v):v=e[9];const P=v;let x;e[10]!==E?(x=k=>{d(k.target.value),E(k.target.value)},e[10]=E,e[11]=x):x=e[11];let C;e[12]!==E||e[13]!==h?(C=()=>{const k=h.split(`
9
+ `).map(Bp).join(`
10
+ `);d(k),E(k)},e[12]=E,e[13]=h,e[14]=C):C=e[14];const u=Math.max(4,a.length+1);let I;e[15]!==P||e[16]!==x||e[17]!==C||e[18]!==u||e[19]!==h?(I=s.jsx(As,{onPaste:P,value:h,onChange:x,onBlur:C,placeholder:`npx
11
+ -y
12
+ @modelcontextprotocol/server-postgres
13
+ postgresql://user:pass@host/db`,rows:u,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=P,e[16]=x,e[17]=C,e[18]=u,e[19]=h,e[20]=I):I=e[20];let F;e[21]!==i||e[22]!==a?(F=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(Hp)})})]}),e[21]=i,e[22]=a,e[23]=F):F=e[23];let A;return e[24]!==F||e[25]!==I?(A=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[I,F]}),e[24]=F,e[25]=I,e[26]=A):A=e[26],A},Lp=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),ao=({value:t,onChange:e,keyTransform:a=Lp,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:h,importSuccess:d,clipboardReadFailed:b,keyLabel:c,valueLabel:j,valuePlaceholder:m,hideValueTitle:E,showValueTitle:v,addVariable:P,plainTextWarning:x,removeVariableAria:C})=>{const[u,I]=o.useState(new Set),F=()=>e([...t,{key:"",value:""}]),A=N=>{e(t.filter((R,y)=>y!==N)),I(R=>{const y=new Set(R);return y.delete(N),y})},k=(N,R,y)=>{const O=[...t];O[N]={...O[N],[R]:y},e(O)},g=N=>{I(R=>{const y=new Set(R);return y.has(N)?y.delete(N):y.add(N),y})},w=async()=>{try{const N=await navigator.clipboard.readText(),R=[];for(const O of N.split(`
14
+ `)){const q=O.trim();if(!q||q.startsWith("#"))continue;const S=q.indexOf("=");if(S===-1)continue;const G=q.slice(0,S).trim();let J=q.slice(S+1).trim();(J.startsWith('"')&&J.endsWith('"')||J.startsWith("'")&&J.endsWith("'"))&&(J=J.slice(1,-1)),G&&R.push({key:G,value:J})}if(R.length===0){D.error(h);return}const y=[...t];for(const O of R){const q=y.findIndex(S=>S.key===O.key);q!==-1?y[q]=O:y.push(O)}e(y),D.success(d(R.length))}catch{D.error(b)}},z=t.some(N=>N.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:c}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:j})]}),s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:w,type:"button",title:l,children:[s.jsx(L,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((N,R)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:N.key,onChange:y=>k(R,"key",a(y.target.value)),placeholder:n,className:i,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(He,{type:u.has(R)?"text":"password",value:N.value,onChange:y=>k(R,"value",y.target.value),placeholder:m,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>g(R),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:u.has(R)?E:v,children:u.has(R)?s.jsx(L,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>A(R),"aria-label":C,children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},R))}),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:F,type:"button",children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),P]}),z&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},Ri=t=>{const e=mt.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let h,d;if(e[0]!==i||e[1]!==a||e[2]!==l){d=Symbol.for("react.early_return_sentinel");e:{const m={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 E=ye("typography-micro font-medium rounded-full px-2 py-0.5",m.text,m.bg);let v;e[5]!==i||e[6]!==a?(v=i(a),e[5]=i,e[6]=a,e[7]=v):v=e[7],d=s.jsxs("span",{className:E,children:["● ",v]});break e}h=ye("typography-micro font-medium",m.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=h,e[4]=d}else h=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;let b;e[8]!==i||e[9]!==a?(b=i(a),e[8]=i,e[9]=a,e[10]=b):b=e[10];let c;return e[11]!==h||e[12]!==b?(c=s.jsxs("span",{className:h,children:["● ",b]}),e[11]=h,e[12]=b,e[13]=c):c=e[13],c},Fp=(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")}},Kp=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)]"}},Up=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),zp=async t=>{const e=await dt(`/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},wa=async t=>{typeof t!="string"||!t.trim()||await dt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},qa=(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},_p=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},$p=()=>{const{t}=rt(),e=o.useCallback((re,ot)=>t(re,ot),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:r,getMcpByName:l,createMcp:h,updateMcp:d,deleteMcp:b}=ia(Ms(re=>({selectedMcpName:re.selectedMcpName,mcpDraft:re.mcpDraft,setMcpDraft:re.setMcpDraft,setSelectedMcp:re.setSelectedMcp,getMcpByName:re.getMcpByName,createMcp:re.createMcp,updateMcp:re.updateMcp,deleteMcp:re.deleteMcp}))),c=Us(),j=o.useMemo(()=>xs(),[]),m=Rs(re=>re.getStatusForDirectory(c)),E=Rs(re=>re.getDiagnosticForDirectory(c)),v=Rs(re=>re.refresh),P=Rs(re=>re.connect),x=Rs(re=>re.disconnect),C=Rs(re=>re.completeAuth),u=Rs(re=>re.clearAuth),I=Rs(re=>re.testConnection),F=pn(re=>re.changes),A=ia(re=>al(re,c)),k=a?l(a,c):null,g=!!(n&&n.name===a&&!k),[w,z]=o.useState(""),[N,R]=o.useState("user"),[y,O]=o.useState("local"),[q,S]=o.useState([]),[G,J]=o.useState(""),[T,Q]=o.useState([]),[Z,K]=o.useState([]),[ae,_]=o.useState(!0),[B,M]=o.useState(""),[U,Y]=o.useState(""),[X,ne]=o.useState(""),[te,ge]=o.useState(""),[ee,le]=o.useState(""),[pe,ie]=o.useState(!0),[je,Se]=o.useState(!1),[Ce,xe]=o.useState(!1),[Re,Oe]=o.useState(!1),[fe,be]=o.useState(!1),[De,_e]=o.useState(!1),[Le,qe]=o.useState(!1),[Ke,Xe]=o.useState(!1),[We,Ze]=o.useState(!1),[we,Je]=o.useState(null),[Me,ve]=o.useState(null),[$e,$]=o.useState(""),[de,ue]=o.useState(!1),ke=o.useRef(0),oe=o.useRef(!1),[Ae,H]=o.useState(!1),[ze,tt]=o.useState(!1),[Fe,at]=o.useState(""),[wt,bt]=o.useState(null),ut=o.useMemo(()=>_p(a,c),[c,a]),gt=o.useRef(ut),Pt=o.useRef(null),jt=o.useCallback(()=>{Je(null),ve(null),$(""),ue(!1),ke.current=0,Ze(!1),_e(!1),qe(!1),oe.current=!1},[]),Et=o.useCallback(()=>{at(""),bt(null),tt(!0)},[]),Ye=o.useCallback(async()=>{try{const re=await navigator.clipboard.readText();at(re),bt(null)}catch{D.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Ge=o.useCallback(()=>{const re=Dp(Fe,{fallbackName:w});if(!re.ok){bt(re.error);return}const vt=Mp(re,{name:w,scope:N,type:y,command:q,url:G,environment:T,headers:Z,oauthEnabled:ae,oauthClientId:B,oauthClientSecret:U,oauthScope:X,oauthRedirectUri:te,timeout:ee,enabled:pe},{isNewServer:g});z(vt.name),O(vt.type),S(vt.command??[]),J(vt.url??""),Q(vt.environment??[]),K(vt.headers??[]),_(vt.oauthEnabled??!1),M(vt.oauthClientId??""),Y(vt.oauthClientSecret??""),ne(vt.oauthScope??""),ge(vt.oauthRedirectUri??""),le(vt.timeout??""),ie(vt.enabled??!0),tt(!1),at(""),bt(null),D.success(t("settings.mcp.page.toast.configImported"))},[Fe,w,N,y,q,G,T,Z,ae,B,U,X,te,ee,pe,g,t]);o.useEffect(()=>{if(g&&n){z(n.name),R(n.scope||"user"),O(n.type),S(n.command),J(n.url),Q(n.environment),K(n.headers),_(n.oauthEnabled),M(n.oauthClientId),Y(n.oauthClientSecret),ne(n.oauthScope),ge(n.oauthRedirectUri),le(n.timeout),ie(n.enabled),H(!1),Pt.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){R(k.scope==="project"?"project":"user");const re=wr(k.environment),ot=k.type==="remote"?k:null,vt=wr(ot?.headers),Be=ot?.oauth,et=Be&&typeof Be=="object"?Be:null,ht=Be!==!1,Tt=k.type,Dt=Tt==="local"?k.command??[]:[],Xt=Tt==="remote"?k.url??"":"",At=typeof ot?.timeout=="number"&&Number.isFinite(ot.timeout)?String(ot.timeout):"";O(Tt),S(Dt),J(Xt),Q(re),K(vt),_(ht),M(ht?et?.clientId??"":""),Y(ht?et?.clientSecret??"":""),ne(ht?et?.scope??"":""),ge(ht?et?.redirectUri??"":""),le(At),ie(k.enabled),H(!1),Pt.current={mcpType:Tt,command:Dt,url:Xt,envEntries:re,headerEntries:vt,oauthEnabled:ht,oauthClientId:ht?et?.clientId??"":"",oauthClientSecret:ht?et?.clientSecret??"":"",oauthScope:ht?et?.scope??"":"",oauthRedirectUri:ht?et?.redirectUri??"":"",timeout:At,enabled:k.enabled}}},[k,g,n]);const ct=o.useMemo(()=>{const re=Pt.current;return re?y!==re.mcpType||pe!==re.enabled||JSON.stringify(q)!==JSON.stringify(re.command)||G!==re.url||JSON.stringify(T)!==JSON.stringify(re.envEntries)||JSON.stringify(Z)!==JSON.stringify(re.headerEntries)||ae!==re.oauthEnabled||B!==re.oauthClientId||U!==re.oauthClientSecret||X!==re.oauthScope||te!==re.oauthRedirectUri||ee!==re.timeout:!1},[y,q,G,T,Z,ae,B,U,X,te,ee,pe]),Ie=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(L,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(L,{name:"global",className:"h-3.5 w-3.5"})}],[t]),It=o.useCallback(re=>{O("remote"),J(re),S([])},[]),Ne=o.useCallback(re=>{J(re);const ot=re.trim();ot&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ot)&&/\s/.test(ot)&&(O("local"),S(Sl(ot)),J(""))},[]),Ct=async()=>{const re=g?w.trim():a??"";if(!re){D.error(t("settings.mcp.page.toast.nameRequired"));return}if(g&&A.some(vt=>vt.name===re)){D.error(t("settings.mcp.page.toast.serverNameExists"));return}if(y==="local"&&q.filter(Boolean).length===0){D.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(y==="remote"&&!G.trim()){D.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ot={name:re,scope:N,type:y,command:q,url:G,environment:T,headers:Z,oauthEnabled:ae,oauthClientId:B,oauthClientSecret:U,oauthScope:X,oauthRedirectUri:te,timeout:ee,enabled:pe};Se(!0);try{const vt=g?await h(ot,c):await d(re,ot,c);vt.ok?(await wa(Me),jt(),g&&(i(null),r(re)),await v({directory:c,silent:!0}),vt.reloadFailed?D.warning(vt.message||t(g?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:vt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):vt.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(vt.message||t(g?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):D.error(t("settings.mcp.page.toast.saveFailed"))}catch(vt){D.error(vt instanceof Error?vt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Se(!1)}},W=async()=>{if(!a)return;Oe(!0);const re=await b(a,c);re.ok?(await wa(Me),jt(),re.reloadFailed?D.warning(re.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:re.warning||t("settings.mcp.page.toast.refreshListIfStale")}):D.success(re.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),xe(!1)):D.error(t("settings.mcp.page.toast.deleteFailed")),Oe(!1)},me=async()=>{if(a){be(!0);try{if(m[a]?.status==="connected")await x(a,c),D.success(t("settings.mcp.page.toast.disconnected"));else{await P(a,c),await v({directory:c,silent:!0});const ot=Rs.getState().getStatusForDirectory(c)[a];ot?.status==="connected"?D.success(t("settings.mcp.page.toast.connected")):ot?.status==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ot?.status==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ot?.status==="failed"?D.error(ot.error||t("settings.mcp.page.toast.connectionFailed")):D.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await v({directory:c,silent:!0})}catch(re){D.error(re instanceof Error?re.message:t("settings.mcp.page.toast.connectionFailed"))}finally{be(!1)}}},Ee=o.useCallback(()=>g?(D.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):ct?(D.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[ct,g,t]),Pe=o.useCallback(async(re=!1)=>{try{await v({directory:c,silent:re})}catch(ot){re||D.error(ot instanceof Error?ot.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[c,v,t]);o.useEffect(()=>{Pe(!0)},[Pe]),o.useEffect(()=>{gt.current=ut,be(!1),Xe(!1),jt()},[jt,ut]);const lt=o.useCallback(async()=>{if(!a||y!=="remote"||!Ee())return;_e(!0);const re=ut;let ot=null;try{const vt=Rs.getState().getStatusForDirectory(c)[a]?.status;oe.current=vt==="needs_auth"||vt==="needs_client_registration";const{authorizationUrl:Be,opened:et,nativeFlow:ht,completion:Tt}=await nc({name:a,directory:c});if(ht){if(gt.current!==re)return;Je(null),ve(null),ue(!0),ke.current=0,D.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),Tt?.then(()=>{gt.current===re&&(ue(!1),ke.current=0,oe.current=!1,D.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(Xt=>{gt.current===re&&(ue(!1),ke.current=0,oe.current=!1,D.error(qa(Xt,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const Dt=il(new URL(Be).searchParams);if(ot=Dt,gt.current!==re||(Je(Be),ve(Dt??null),ue(!0),ke.current=0,gt.current!==re))return;et?D.message(t(j?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):D.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(vt){await wa(ot),gt.current===re&&D.error(qa(vt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{gt.current===re&&_e(!1)}},[c,j,y,Ee,ut,a,t,e]),it=o.useCallback(async()=>{if(!a||!Ee())return;qe(!0);const re=ut;try{if(await u(a,c),gt.current!==re)return;Je(null),ve(null),$(""),ue(!1),ke.current=0,await wa(Me),D.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(ot){gt.current===re&&D.error(qa(ot,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{gt.current===re&&qe(!1)}},[Me,u,c,Ee,ut,a,t,e]),Ve=o.useCallback(async()=>{if(!we)return;if((await Ta(we)).ok){D.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}D.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[we,t]),Nt=o.useCallback(async()=>{const re=Rp($e);if(!re.code){D.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ot=re.stateKey?await zp(re.stateKey):null,vt=re.context??ot,Be=vt?.name??a,et=vt?.directory??c;if(!Be){D.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!vt&&!Ee())return;Ze(!0);const ht=ut;try{if(await C(Be,re.code,et),await wa(re.stateKey??Me),gt.current!==ht)return;$(""),Je(null),ve(null),ue(!1),ke.current=0,D.success(Be===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Be}))}catch(Tt){gt.current===ht&&D.error(qa(Tt,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{gt.current===ht&&Ze(!1)}},[$e,Me,C,c,Ee,ut,a,t,e]),is=o.useCallback(async()=>{if(!(!a||!Ee())){if(!pe){D.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}Xe(!0);try{const re=await I(a,c),ot=re.status?.status;re.warning?D.warning(re.warning):ot==="connected"?D.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ot==="needs_auth"?D.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ot==="needs_client_registration"?D.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ot==="failed"?D.error(re.status?.error||re.error||t("settings.mcp.page.toast.connectionTestFailed")):re.error?D.error(re.error):D.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(re){D.error(re instanceof Error?re.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{Xe(!1)}}},[c,pe,Ee,a,t,I]);if(o.useEffect(()=>{if(!de||!a)return;const re=window.setInterval(()=>{(async()=>{ke.current+=1,await v({directory:c,silent:!0});const ot=Rs.getState().getStatusForDirectory(c)[a];if(ot){if(oe.current&&ot.status!=="needs_auth"&&ot.status!=="needs_client_registration"){ue(!1),ke.current=0,oe.current=!1,Je(null),$(""),ot.status==="connected"&&D.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!oe.current&&ot.status==="failed"){ue(!1),ke.current=0,oe.current=!1,D.error(ot.error||t("settings.mcp.page.toast.authorizationFailed"));return}ke.current>=30&&(ue(!1),ke.current=0,oe.current=!1,D.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(re)}},[c,de,v,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(L,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const es=m[a],ys=a?E[a]:void 0,Ht=es??ys,rs=!g&&!Ht&&F.some(re=>re.scope==="mcp"&&re.id.startsWith(`mcp:${a}:`)),zt=es?.status==="connected",fs=es?.status==="needs_auth"||es?.status==="needs_client_registration",os=j||!a?null:ac(a),ss=async()=>{if(os)try{await navigator.clipboard.writeText(os),D.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{D.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},ns=Fp(Ht?.status,e,Ht&&"error"in Ht?Ht.error:void 0),js=re=>{switch(re){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 re}};return s.jsxs(s.Fragment,{children:[s.jsxs(cs,{title:g?t("settings.mcp.page.header.newServer"):a,titleAccessory:g?void 0:s.jsx(Ri,{status:rs?"awaiting_restart":Ht?.status,enabled:pe,getStatusLabel:js,variant:"pill"}),description:g?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(y==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!g&&!rs?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(V,{variant:zt?"outline":"default",size:"xs",className:"!font-normal",onClick:me,disabled:fe||!pe,children:t(fe?"settings.mcp.page.actions.working":zt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),y==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(V,{variant:fs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{lt()},disabled:De||!pe,children:t(De?"settings.mcp.page.actions.starting":zt?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{it()},disabled:Le||!pe,children:t(Le?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),zt&&s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{is()},disabled:Ke||!pe,children:t(Ke?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[rs&&s.jsx(Ue,{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:Ot,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Ri,{status:"awaiting_restart",enabled:pe,getStatusLabel:js})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!g&&!rs&&Up(Ht?.status,we,fs,de)&&s.jsx(Ue,{divider:!1,children:s.jsxs("div",{className:ye("rounded-lg border p-3",Kp(Ht?.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:Ot,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(Ri,{status:Ht?.status,enabled:pe,getStatusLabel:js})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ns}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:N==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:c??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!zt&&s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{is()},disabled:Ke||!pe,children:t(Ke?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Ht?.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(Xs,{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")})]}),os&&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:os}),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ss()},children:[s.jsx(L,{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(Zt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(He,{value:B,onChange:re=>{M(re.target.value),_(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(Zt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(He,{type:"password",value:U,onChange:re=>{Y(re.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")})]}),we&&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:we}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{En(we)},children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ve()},children:[s.jsx(L,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),j&&y==="remote"&&(fs||de||we)&&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(Xs,{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:$e,onChange:re=>$(re.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(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nt()},disabled:We,children:t(We?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),de&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs(Ue,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:g?s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:Et,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(L,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[g&&s.jsxs(Yt,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(He,{value:w,onChange:re=>z(re.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(Lt,{value:N,onValueChange:re=>R(re),children:[s.jsxs(Ft,{size:qt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(L,{name:N==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(N==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(Kt,{align:"end",children:[s.jsx(pt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(pt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(xt,{checked:pe,onChange:ie,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(Ue,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(gr,{items:Ie,activeId:y,onSelect:re=>O(re),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),y==="local"?s.jsx(Op,{value:q,onChange:S,preview:re=>t("settings.mcp.page.connection.previewArgs",{count:re}),onDetectUrl:It}):s.jsx(He,{value:G,onChange:re=>Ne(re.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(y==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),y==="remote"&&s.jsx(Ue,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(Gn,{open:Ae,onOpenChange:H,children:[s.jsxs(qn,{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:["(",Z.length," ",t("settings.mcp.page.advanced.headers"),ee?` · ${ee}ms`:"",")"]})]}),Ae?s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Wn,{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:Ot,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(ts,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(He,{type:"number",min:"1",step:"1",value:ee,onChange:re=>le(re.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(Xs,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),Z.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",Z.length,")"]})]}),s.jsx(ao,{value:Z,onChange:K,keyTransform:re=>re.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:re=>t("settings.mcp.page.toast.importedVariablesCount",{count:re}),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(Ue,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:T.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",T.length,")"]}):null,settingsItem:"mcp.environment",children:T.length===0?s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>Q([{key:"",value:""}]),children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(ao,{value:T,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:re=>t("settings.mcp.page.toast.importedVariablesCount",{count:re}),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(V,{onClick:Ct,disabled:je||!ct&&!g,size:"xs",className:"!font-normal",children:t(je?"settings.common.actions.saving":g?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!g&&s.jsx(V,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>xe(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Vt,{open:ze,onOpenChange:re=>{re||(tt(!1),at(""),bt(null))},children:s.jsxs(Bt,{className:"max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Qt,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(As,{value:Fe,onChange:re=>{at(re.target.value),bt(null)},placeholder:`{
15
+ "mcpServers": {
16
+ "postgres": {
17
+ "command": "npx",
18
+ "args": ["-y", "@modelcontextprotocol/server-postgres"]
19
+ }
20
+ }
21
+ }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),wt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:wt}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ye,type:"button",children:[s.jsx(L,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(ds,{children:[s.jsx(V,{variant:"outline",onClick:()=>{tt(!1),at(""),bt(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(V,{onClick:Ge,disabled:!Fe.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Vt,{open:Ce,onOpenChange:re=>{!re&&!Re&&xe(!1)},children:s.jsxs(Bt,{className:"max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs(Qt,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(ds,{children:[s.jsx(V,{variant:"outline",onClick:()=>xe(!1),disabled:Re,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(V,{variant:"destructive",size:"sm",onClick:W,disabled:Re,children:t(Re?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function Vp(t){return t.trim().length>0}function Bp(t){return t.trimEnd()}function Hp(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 ei=()=>{try{const e=Qs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=dn.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},Gp=800,qp=5e3,Wp="__default__",er=new Map,Oi=new Map,Jp=1500,Cl=t=>t?.trim()||Wp,Qp=t=>{er.delete(Cl(t))},gs=vl()(Cd(Pd((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=ei(),i=Cl(n),r=Date.now(),l=er.get(i)??0,h=e().entries.length>0||e().files.length>0;if(!a?.force&&h&&r-l<qp)return!0;const d=Oi.get(i);if(!a?.force&&d)return d;const b=(async()=>{t({isLoading:!0});try{const c=await dt(yn("/api/config/plugins",n),{headers:ka(n)});if(!c.ok)throw new Error("Failed to load plugins");const j=await ti(c);return t({entries:j.entries??[],files:j.files??[],isLoading:!1}),er.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(c){return console.error("[PluginsStore] Failed to load plugins:",c),t({isLoading:!1}),!1}})();Oi.set(i,b);try{return await b}finally{Oi.delete(i)}},loadRegistryInfo:async a=>{const n=Zp(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=ei(),r={...e().registryInfo};for(const l of Xp(n)){const h=await dt(Yp(l,a?.force===!0,i),{headers:ka(i)});if(!h.ok)throw new Error("Failed to load plugin registry info");const d=await ti(h);for(const b of d.results??[])r[b.spec]=b}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 Xn("Creating plugin entry…",async i=>await dt(yn("/api/config/plugins/entry",i),{method:"POST",headers:Wa(i),body:JSON.stringify(io(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(h=>h.id===a)?.spec,r=n.spec??i,l=await Xn("Updating plugin entry…",async h=>await dt(yn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,h),{method:"PATCH",headers:Wa(h),body:JSON.stringify(io(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 Xn("Deleting plugin entry…",async r=>await dt(yn(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:ka(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=ei(),i=await dt(yn(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:ka(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await ti(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>Xn("Creating plugin file…",async n=>await dt(yn("/api/config/plugins/file",n),{method:"POST",headers:Wa(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>Xn("Updating plugin file…",async i=>await dt(yn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:Wa(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await Xn("Deleting plugin file…",async i=>await dt(yn(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:ka(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:Wc(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function yn(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function Yp(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 Zp(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function Xp(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>Jp?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function ka(t){return t?{"x-opencode-directory":t}:void 0}function Wa(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function io(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 Xn(t,e,a,n){try{const i=ei(),r=await e(i),l=await ti(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return Qp(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):ii(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&&(rc(t),await oc({message:l.message,delayMs:l.reloadDelayMs??Gp,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 ti(t){return await t.json()}const em=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function tm(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 sm=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=rt(),i=gs(S=>S.createEntry),r=gs(S=>S.createFile),[l,h]=o.useState("npm"),[d,b]=o.useState(""),[c,j]=o.useState(""),[m,E]=o.useState(""),[v,P]=o.useState(""),[x,C]=o.useState(a),[u,I]=o.useState(!1),F=o.useCallback(()=>{b(""),j(""),E(""),P(""),C(a)},[a]);o.useEffect(()=>{t&&(h("npm"),F())},[t,F]);const A=S=>{S!==l&&(h(S),F())},k=o.useMemo(()=>tm(c),[c]),g=!k.ok,w=l==="file"&&m.trim()!==""&&!em.test(m.trim()),z=(l==="npm"||l==="path")&&d.trim()==="",N=l==="file"&&v.trim()==="",R=l==="file"&&m.trim()==="",y=u||g||l==="npm"&&z||l==="path"&&z||l==="file"&&(R||w||N),O=async()=>{if(!y){I(!0);try{let S;l==="file"?S=await r({fileName:m.trim(),content:v,scope:x}):S=await i({spec:d.trim(),options:k.ok?k.value:void 0,scope:x}),S.ok?(S.restartDeferred?D.success(n("settings.view.pendingRestart.saved")):D.success(S.message||n("settings.plugins.toast.created")),S.reloadFailed&&D.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):D.error(S.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{I(!1)}}},q=o.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(Vt,{open:t,onOpenChange:S=>{!S&&u||e(S)},children:s.jsxs(Bt,{className:"max-w-xl",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:n("settings.plugins.dialog.add.title")}),s.jsx(Qt,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(gr,{items:q,activeId:l,onSelect:S=>A(S),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.spec")}),s.jsx(He,{id:"plugin-spec",value:d,onChange:S=>b(S.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":z?!1:void 0,disabled:u}),z&&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:c,onChange:S=>j(S.target.value),rows:5,className:"font-mono",hasError:g,disabled:u}),g&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(He,{id:"plugin-filename",value:m,onChange:S=>E(S.target.value),placeholder:"my-plugin.ts","aria-invalid":w||void 0,disabled:u}),w&&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:v,onChange:S=>P(S.target.value),rows:16,className:"font-mono",disabled:u})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(S=>{const G=x===S,J=n(S==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>C(S),disabled:u,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(cr,{checked:G,onChange:()=>C(S),ariaLabel:J}),s.jsx("span",{className:ye("typography-ui-label font-normal",G?"text-foreground":"text-foreground/60"),children:J})]},S)})})]})]}),s.jsxs(ds,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:u,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(V,{size:"sm",onClick:()=>{O()},disabled:y,children:[u?s.jsx(L,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},nm=t=>{const e=mt.c(33),{spec:a}=t;let n;e[0]!==a?(n=h=>h.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=gs(n),{t:r}=rt();if(!i)return null;const l=am;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=h):h=e[2];let d;e[3]!==i.latestVersion?(d=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[h,i.latestVersion]}),e[3]=i.latestVersion,e[4]=d):d=e[4];let b;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==d?(b=l(d,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]=d,e[9]=b):b=e[9],b}case"npm-missing-version":{let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=h):h=e[10];let d;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(d=l(h,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]=d):d=e[14],d}case"npm-missing-package":{let h;e[15]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=h):h=e[15];let d;return e[16]!==i.name||e[17]!==r?(d=l(h,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=d):d=e[18],d}case"npm-malformed":{let h;e[19]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=h):h=e[19];let d;return e[20]!==r?(d=l(h,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=d):d=e[21],d}case"npm-network":{let h;e[22]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=h):h=e[22];let d;return e[23]!==r?(d=l(h,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=d):d=e[24],d}case"path-missing":{let h;e[25]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=h):h=e[25];let d;return e[26]!==i.absolutePath||e[27]!==r?(d=l(h,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=d):d=e[28],d}case"path-unreadable":{let h;e[29]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(L,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=h):h=e[29];let d;return e[30]!==i.absolutePath||e[31]!==r?(d=l(h,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=d):d=e[32],d}case"path-ok":return null;default:return null}};function am(t,e){return s.jsxs(dr,{children:[s.jsx(pr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(rl,{children:e})]})}const Pl=t=>{const e=mt.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,h=l===void 0?"sidebar":l,d=xs(),b=o.useRef(null),[c,j]=o.useState(!1),[m,E]=o.useState(!1),v=h==="background"||d?"bg-background":"bg-sidebar",P=v==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const y=b.current;if(!y){j(!1),E(!1);return}if(!(y.scrollHeight>y.clientHeight+1)){j(!1),E(!1);return}j(y.scrollTop>1),E(y.scrollTop+y.clientHeight<y.scrollHeight-1)},e[0]=x):x=e[0];const C=x;let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{C()},e[1]=u):u=e[1];let I;e[2]!==i?(I=[i,C],e[2]=i,e[3]=I):I=e[3],o.useEffect(u,I);let F,A;e[4]===Symbol.for("react.memo_cache_sentinel")?(F=()=>{const y=b.current;if(!y)return;const O=()=>C();return y.addEventListener("scroll",O,{passive:!0}),()=>y.removeEventListener("scroll",O)},A=[C],e[4]=F,e[5]=A):(F=e[4],A=e[5]),o.useEffect(F,A);let k;e[6]!==v||e[7]!==r?(k=ye("flex h-full flex-col",v,r),e[6]=v,e[7]=r,e[8]=k):k=e[8];let g;e[9]!==i?(g=s.jsx(Hs,{ref:b,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:i}),e[9]=i,e[10]=g):g=e[10];let w;e[11]!==P||e[12]!==c?(w=c&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${P} 0%, transparent 100%)`}}),e[11]=P,e[12]=c,e[13]=w):w=e[13];let z;e[14]!==P||e[15]!==m?(z=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${P} 0%, transparent 100%)`}}),e[14]=P,e[15]=m,e[16]=z):z=e[16];let N;e[17]!==z||e[18]!==g||e[19]!==w?(N=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[g,w,z]}),e[17]=z,e[18]=g,e[19]=w,e[20]=N):N=e[20];let R;return e[21]!==n||e[22]!==a||e[23]!==N||e[24]!==k?(R=s.jsxs("div",{className:k,children:[a,N,n]}),e[21]=n,e[22]=a,e[23]=N,e[24]=k,e[25]=R):R=e[25],R},tr=t=>{const e=mt.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:h,className:d}=t,b=i===void 0?!1:i,c=h&&h.length>0,j=b?"bg-interactive-selection":"hover:bg-interactive-hover";let m;e[0]!==d||e[1]!==j?(m=ye("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",j,d),e[0]=d,e[1]=j,e[2]=m):m=e[2];let E;e[3]!==a?(E=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=E):E=e[4];let v;e[5]!==l||e[6]!==E?(v=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,E]}),e[5]=l,e[6]=E,e[7]=v):v=e[7];let P;e[8]!==n?(P=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=P):P=e[9];let x;e[10]!==r||e[11]!==v||e[12]!==P?(x=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:[v,P]}),e[10]=r,e[11]=v,e[12]=P,e[13]=x):x=e[13];let C;e[14]!==h||e[15]!==c?(C=c&&s.jsxs(sn,{children:[s.jsx(en,{asChild:!0,children:s.jsx(V,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(tn,{align:"end",className:"w-fit min-w-20",children:h.map(im)})]}),e[14]=h,e[15]=c,e[16]=C):C=e[16];let u;e[17]!==x||e[18]!==C?(u=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,C]}),e[17]=x,e[18]=C,e[19]=u):u=e[19];let I;return e[20]!==m||e[21]!==u?(I=s.jsx("div",{className:m,children:u}),e[20]=m,e[21]=u,e[22]=I):I=e[22],I};function im(t){const e=t.icon;return s.jsxs(nn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:ye(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(L,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const rm=t=>t.parsedKind==="npm"?"code-box":"folder",om=t=>{const e=mt.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=rt(),{entries:r,files:l,selectedId:h,setSelected:d,deleteEntry:b,deleteFile:c,loadPlugins:j}=gs(Ms(lm)),m=gs(cm),E=gs(dm),v=gs(pm),P=gs(mm),[x,C]=o.useState(null),[u,I]=o.useState(!1),[F,A]=o.useState(!1);let k,g;e[0]!==j?(k=()=>{j()},g=[j],e[0]=j,e[1]=k,e[2]=g):(k=e[1],g=e[2]),o.useEffect(k,g);let w,z;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{const Ye=()=>A(!0);return window.addEventListener("openchamber:settings-open-plugin-add",Ye),()=>window.removeEventListener("openchamber:settings-open-plugin-add",Ye)},z=[],e[3]=w,e[4]=z):(w=e[3],z=e[4]),o.useEffect(w,z);let N;if(e[5]!==r||e[6]!==m){N={userEntries:0,projectEntries:0};for(const Ye of r){const Ge=m[Ye.spec];Ge?.kind==="npm-ok"&&Ge.hasUpdate&&(Ye.scope==="user"?N.userEntries=N.userEntries+1:Ye.scope==="project"&&(N.projectEntries=N.projectEntries+1))}e[5]=r,e[6]=m,e[7]=N}else N=e[7];const R=N;let y;e[8]!==r?(y=r.filter(um),e[8]=r,e[9]=y):y=e[9];const O=y;let q;e[10]!==r?(q=r.filter(gm),e[10]=r,e[11]=q):q=e[11];const S=q;let G;e[12]!==l?(G=l.filter(hm),e[12]=l,e[13]=G):G=e[13];const J=G;let T;e[14]!==l?(T=l.filter(fm),e[14]=l,e[15]=T):T=e[15];const Q=T,Z=r.length+l.length,K=Z===0;let ae;e[16]!==n?(ae=()=>{n?n():A(!0)},e[16]=n,e[17]=ae):ae=e[17];const _=ae;let B;e[18]!==a||e[19]!==d?(B=Ye=>{d(Ye),a?.()},e[18]=a,e[19]=d,e[20]=B):B=e[20];const M=B;let U;e[21]!==r||e[22]!==m||e[23]!==i||e[24]!==P?(U=async Ye=>{const Ge=r.find(Ne=>Ne.id===Ye);if(!Ge)return;const ct=m[Ge.spec];if(!ct||ct.kind!=="npm-ok"||!ct.hasUpdate||!ct.latestVersion)return;const Ie=ct.latestVersion;(await P(Ye)).ok?D.success(i("settings.plugins.toast.updatedToLatest",{version:Ie})):D.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=m,e[23]=i,e[24]=P,e[25]=U):U=e[25];const Y=U;let X;e[26]!==v||e[27]!==i?(X=async()=>{D.info(i("settings.plugins.toast.refreshing"));try{await v({force:!0})}catch{D.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=v,e[27]=i,e[28]=X):X=e[28];const ne=X;let te;e[29]!==b||e[30]!==c||e[31]!==x||e[32]!==i?(te=async()=>{if(!x)return;I(!0);const Ye=x.kind==="entry"?await b(x.id):await c(x.id);Ye.ok?D.success(Ye.message||i("settings.plugins.sidebar.toast.deleted",{name:x.label})):D.error(i("settings.plugins.sidebar.toast.deleteFailed")),C(null),I(!1)},e[29]=b,e[30]=c,e[31]=x,e[32]=i,e[33]=te):te=e[33];const ge=te;let ee;e[34]!==M||e[35]!==Y||e[36]!==m||e[37]!==h||e[38]!==i?(ee=Ye=>{const Ge=m[Ye.spec],ct=Ge?.kind==="npm-ok"&&Ge.hasUpdate&&!!Ge.latestVersion,Ie=[];return ct&&Ie.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{Y(Ye.id)}}),Ie.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>C({kind:"entry",id:Ye.id,label:Ye.spec})}),s.jsx(tr,{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:Ye.spec}),s.jsx(nm,{spec:Ye.spec})]}),metadata:Ye.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:h===Ye.id,onSelect:()=>M(Ye.id),icon:s.jsx(L,{name:rm(Ye),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:Ie},Ye.id)},e[34]=M,e[35]=Y,e[36]=m,e[37]=h,e[38]=i,e[39]=ee):ee=e[39];const le=ee;let pe;e[40]!==M||e[41]!==h||e[42]!==i?(pe=Ye=>s.jsx(tr,{title:Ye.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:h===Ye.id,onSelect:()=>M(Ye.id),icon:s.jsx(L,{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:()=>C({kind:"file",id:Ye.id,label:Ye.fileName})}]},Ye.id),e[40]=M,e[41]=h,e[42]=i,e[43]=pe):pe=e[43];const ie=pe;let je;e[44]!==i?(je=(Ye,Ge,ct)=>{const Ie=ct===void 0?0:ct;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:[Ye,Ie>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(Ie===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:Ie})})]}),Ge]})},e[44]=i,e[45]=je):je=e[45];const Se=je;let Ce;e[46]!==i?(Ce=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=Ce):Ce=e[47];let xe;e[48]!==Ce?(xe=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:an,children:Ce})}),e[48]=Ce,e[49]=xe):xe=e[49];let Re;e[50]!==i||e[51]!==Z?(Re=i("settings.plugins.sidebar.total",{count:Z}),e[50]=i,e[51]=Z,e[52]=Re):Re=e[52];let Oe;e[53]!==Re?(Oe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Re}),e[53]=Re,e[54]=Oe):Oe=e[54];let fe;e[55]!==ne?(fe=()=>{ne()},e[55]=ne,e[56]=fe):fe=e[56];let be;e[57]!==i?(be=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=be):be=e[58];let De;e[59]!==i?(De=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=De):De=e[60];const _e=E?"size-4 animate-spin":"size-4";let Le;e[61]!==_e?(Le=s.jsx(L,{name:"refresh",className:_e}),e[61]=_e,e[62]=Le):Le=e[62];let qe;e[63]!==E||e[64]!==fe||e[65]!==be||e[66]!==De||e[67]!==Le?(qe=s.jsx(V,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:fe,disabled:E,"aria-label":be,title:De,children:Le}),e[63]=E,e[64]=fe,e[65]=be,e[66]=De,e[67]=Le,e[68]=qe):qe=e[68];let Ke;e[69]!==i?(Ke=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=Ke):Ke=e[70];let Xe;e[71]!==i?(Xe=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=Xe):Xe=e[72];let We;e[73]===Symbol.for("react.memo_cache_sentinel")?(We=s.jsx(L,{name:"add",className:"size-4"}),e[73]=We):We=e[73];let Ze;e[74]!==_||e[75]!==Ke||e[76]!==Xe?(Ze=s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:_,"aria-label":Ke,title:Xe,children:We}),e[74]=_,e[75]=Ke,e[76]=Xe,e[77]=Ze):Ze=e[77];let we;e[78]!==qe||e[79]!==Ze?(we=s.jsxs("div",{className:"flex items-center gap-1",children:[qe,Ze]}),e[78]=qe,e[79]=Ze,e[80]=we):we=e[80];let Je;e[81]!==Oe||e[82]!==we?(Je=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Oe,we]}),e[81]=Oe,e[82]=we,e[83]=Je):Je=e[83];let Me;e[84]!==xe||e[85]!==Je?(Me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[xe,Je]}),e[84]=xe,e[85]=Je,e[86]=Me):Me=e[86];let ve;e[87]!==K||e[88]!==S||e[89]!==Q||e[90]!==le||e[91]!==ie||e[92]!==Se||e[93]!==i||e[94]!==R||e[95]!==O||e[96]!==J?(ve=K?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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:[O.length>0&&Se(i("settings.plugins.sidebar.group.userEntries"),O.map(le),R.userEntries),J.length>0&&Se(i("settings.plugins.sidebar.group.userFiles"),J.map(ie)),S.length>0&&Se(i("settings.plugins.sidebar.group.projectEntries"),S.map(le),R.projectEntries),Q.length>0&&Se(i("settings.plugins.sidebar.group.projectFiles"),Q.map(ie))]}),e[87]=K,e[88]=S,e[89]=Q,e[90]=le,e[91]=ie,e[92]=Se,e[93]=i,e[94]=R,e[95]=O,e[96]=J,e[97]=ve):ve=e[97];let $e;e[98]!==Me||e[99]!==ve?($e=s.jsx(Pl,{variant:"background",header:Me,children:ve}),e[98]=Me,e[99]=ve,e[100]=$e):$e=e[100];let $;e[101]!==F?($=s.jsx(sm,{open:F,onOpenChange:A}),e[101]=F,e[102]=$):$=e[102];const de=x!==null;let ue;e[103]!==u?(ue=Ye=>{!Ye&&!u&&C(null)},e[103]=u,e[104]=ue):ue=e[104];let ke;e[105]!==i?(ke=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=ke):ke=e[106];let oe;e[107]!==ke?(oe=s.jsx(Jt,{children:ke}),e[107]=ke,e[108]=oe):oe=e[108];const Ae=x?.label??"";let H;e[109]!==i||e[110]!==Ae?(H=i("settings.plugins.sidebar.deleteDialog.description",{name:Ae}),e[109]=i,e[110]=Ae,e[111]=H):H=e[111];let ze;e[112]!==H?(ze=s.jsx(Qt,{children:H}),e[112]=H,e[113]=ze):ze=e[113];let tt;e[114]!==oe||e[115]!==ze?(tt=s.jsxs(Wt,{children:[oe,ze]}),e[114]=oe,e[115]=ze,e[116]=tt):tt=e[116];let Fe;e[117]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>C(null),e[117]=Fe):Fe=e[117];let at;e[118]!==i?(at=i("settings.common.actions.cancel"),e[118]=i,e[119]=at):at=e[119];let wt;e[120]!==u||e[121]!==at?(wt=s.jsx(V,{size:"sm",variant:"ghost",onClick:Fe,disabled:u,children:at}),e[120]=u,e[121]=at,e[122]=wt):wt=e[122];let bt;e[123]!==u||e[124]!==i?(bt=i(u?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=u,e[124]=i,e[125]=bt):bt=e[125];let ut;e[126]!==ge||e[127]!==u||e[128]!==bt?(ut=s.jsx(V,{size:"sm",variant:"destructive",onClick:ge,disabled:u,children:bt}),e[126]=ge,e[127]=u,e[128]=bt,e[129]=ut):ut=e[129];let gt;e[130]!==wt||e[131]!==ut?(gt=s.jsxs(ds,{children:[wt,ut]}),e[130]=wt,e[131]=ut,e[132]=gt):gt=e[132];let Pt;e[133]!==tt||e[134]!==gt?(Pt=s.jsxs(Bt,{className:"max-w-md",children:[tt,gt]}),e[133]=tt,e[134]=gt,e[135]=Pt):Pt=e[135];let jt;e[136]!==de||e[137]!==ue||e[138]!==Pt?(jt=s.jsx(Vt,{open:de,onOpenChange:ue,children:Pt}),e[136]=de,e[137]=ue,e[138]=Pt,e[139]=jt):jt=e[139];let Et;return e[140]!==$e||e[141]!==$||e[142]!==jt?(Et=s.jsxs(s.Fragment,{children:[$e,$,jt]}),e[140]=$e,e[141]=$,e[142]=jt,e[143]=Et):Et=e[143],Et};function lm(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function cm(t){return t.registryInfo}function dm(t){return t.isLoadingRegistry}function pm(t){return t.loadRegistryInfo}function mm(t){return t.updateToLatest}function um(t){return t.scope==="user"}function gm(t){return t.scope==="project"}function hm(t){return t.scope==="user"}function fm(t){return t.scope==="project"}const xm=({entryId:t,spec:e})=>{const{t:a}=rt(),n=gs(j=>j.registryInfo[e]),i=gs(j=>j.updateToLatest),[r,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const j=n.latestVersion,m=n.currentVersion??"",E=async()=>{l(!0);try{(await i(t)).ok?D.success(a("settings.plugins.toast.updatedToLatest",{version:j})):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(L,{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:m,latest:j})})]}),s.jsx(V,{variant:"default",size:"sm",onClick:()=>{E()},disabled:r,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:j})})]})}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(L,{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 h=n.kind==="path-unreadable",d=h?"var(--status-warning)":"var(--status-error)",b=h?"alert":"error-warning",c=(()=>{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(L,{name:b,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:d}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:d},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:c})]})]})};function bm(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}function Il(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function ro(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Il(t.options),fileName:"",content:""}}function oo(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const lo=t=>{const e=mt.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=ye("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=i):i=e[0];let r;return e[1]!==n||e[2]!==a?(r=s.jsx("span",{className:i,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=r):r=e[3],r},vm=()=>{const{t}=rt(),e=gs(x=>x.selectedId),a=gs(x=>x.entries),n=gs(x=>x.files),i=gs(x=>x.draft),r=gs(x=>x.setDraft),l=gs(x=>x.updateEntry),h=gs(x=>x.updateFile),d=gs(x=>x.readFile),b=o.useMemo(()=>e?a.find(x=>x.id===e)??null:null,[a,e]),c=o.useMemo(()=>e?n.find(x=>x.id===e)??null:null,[n,e]),[j,m]=o.useState(!1),[E,v]=o.useState(!1),P=o.useRef(new Map);if(o.useEffect(()=>{let x=!1;return b?(r(ro(b)),()=>{x=!0}):c?(v(!0),(async()=>{const C=await d(c.id);if(x)return;v(!1);const u=C?.content??"";P.current.set(c.id,u),r(oo(c,u))})(),()=>{x=!0}):(r(null),()=>{x=!0})},[b,c,d,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(L,{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(b&&i&&i.mode==="entry"){const x=bm(i.optionsJson),C=x.ok,u=i.spec!==b.spec||i.optionsJson!==Il(b.options),I=()=>{r(ro(b))},F=async()=>{if(!C)return;const A=i.spec.trim();if(!A){D.error(t("settings.plugins.validation.specRequired"));return}m(!0);try{const k=await l(b.id,{spec:A,options:x.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{m(!1)}};return s.jsxs(cs,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(lo,{scope:b.scope,label:b.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(Ue,{divider:!1,children:s.jsx(xm,{entryId:b.id,spec:b.spec})}),s.jsx(Ue,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(He,{value:i.spec,onChange:A=>r({...i,spec:A.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(Ue,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(As,{value:i.optionsJson,onChange:A=>r({...i,optionsJson:A.target.value}),rows:10,className:ye("font-mono typography-meta min-h-[200px]",!C&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!C&&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(V,{variant:"default",size:"sm",onClick:()=>{F()},disabled:!u||!C||j,children:t("settings.plugins.page.action.save")}),s.jsx(V,{variant:"outline",size:"sm",onClick:I,disabled:!u||j,children:t("settings.plugins.page.action.discard")})]})]})]})}if(c&&i&&i.mode==="file"){const x=P.current.get(c.id)??"",C=i.content!==x||i.fileName!==c.fileName,u=()=>{(async()=>{v(!0);const A=(await d(c.id))?.content??"";v(!1),P.current.set(c.id,A),r(oo(c,A))})()},I=async()=>{m(!0);try{const F=await h(c.id,{content:i.content});F.ok?(P.current.set(c.id,i.content),F.reloadFailed?D.warning(F.message||t("settings.plugins.toast.reloadFailed"),{description:F.warning}):F.restartDeferred?D.success(t("settings.view.pendingRestart.saved")):D.success(F.message||t("settings.plugins.toast.updated"))):D.error(F.message||t("settings.plugins.toast.reloadFailed"))}finally{m(!1)}};return s.jsx(cs,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(lo,{scope:c.scope,label:c.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:ye("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:c.fileName})]}),showSaveStatus:!1,children:s.jsxs(Ue,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(As,{value:i.content,onChange:F=>r({...i,content:F.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:E}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(V,{variant:"default",size:"sm",onClick:()=>{I()},disabled:!C||j||E,children:t("settings.plugins.page.action.save")}),s.jsx(V,{variant:"outline",size:"sm",onClick:u,disabled:j||E,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(L,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},ym="<built-in>",Da=t=>t?.path===ym,sr=t=>!!t&&!Da(t)&&t.renamable===!0,jm=t=>{const e=mt.c(157),{onItemSelect:a}=t,{t:n}=rt(),[i,r]=o.useState(null),[l,h]=o.useState(""),[d,b]=o.useState(null),[c,j]=o.useState(!1),[m,E]=o.useState(null),{selectedSkillName:v,setSelectedSkill:P,setSkillDraft:x,deleteSkill:C,renameSkill:u,getSkillDetail:I}=Vs(Ms(wm)),F=Us();let A;e[0]!==F?(A=Ne=>lr(Ne,F),e[0]=F,e[1]=A):A=e[1];const k=Vs(A),g=Vs(km);let w,z;e[2]!==g||e[3]!==F?(w=()=>{g(F)},z=[g,F],e[2]=g,e[3]=F,e[4]=w,e[5]=z):(w=e[4],z=e[5]),o.useEffect(w,z);let N;e[6]!==a||e[7]!==P||e[8]!==x||e[9]!==k?(N=()=>{let Ne="new-skill",Ct=1;for(;k.some(W=>W.name===Ne);)Ne=`new-skill-${Ct}`,Ct++;x({name:Ne,scope:"user",source:"opencode",description:""}),P(Ne),a?.()},e[6]=a,e[7]=P,e[8]=x,e[9]=k,e[10]=N):N=e[10];const R=N;let y;e[11]===Symbol.for("react.memo_cache_sentinel")?(y=async Ne=>{Da(Ne)||b(Ne)},e[11]=y):y=e[11];const O=y;let q;e[12]!==d||e[13]!==C||e[14]!==F||e[15]!==n?(q=async()=>{if(!d)return;if(Da(d)){b(null);return}j(!0),await C(d.name,F)?(D.success(n("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),b(null)):D.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),j(!1)},e[12]=d,e[13]=C,e[14]=F,e[15]=n,e[16]=q):q=e[16];const S=q;let G;e[17]!==I||e[18]!==P||e[19]!==x||e[20]!==F||e[21]!==k||e[22]!==n?(G=async Ne=>{if(Da(Ne))return;const Ct=Ne.name;let W=1,me=`${Ct}-copy`;for(;k.some(Pe=>Pe.name===me);)W++,me=`${Ct}-copy-${W}`;const Ee=await I(Ne.name,F);if(!Ee){D.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}x({name:me,scope:Ne.scope||"user",source:Ne.source||"opencode",description:(Ee.sources.md.fields.includes("description"),""),instructions:""}),P(me)},e[17]=I,e[18]=P,e[19]=x,e[20]=F,e[21]=k,e[22]=n,e[23]=G):G=e[23];const J=G;let T;e[24]===Symbol.for("react.memo_cache_sentinel")?(T=Ne=>{sr(Ne)&&(h(Ne.name),r(Ne))},e[24]=T):T=e[24];const Q=T;let Z;e[25]!==i||e[26]!==l||e[27]!==u||e[28]!==P||e[29]!==F||e[30]!==k||e[31]!==n?(Z=async()=>{if(!i)return;if(!sr(i)){r(null);return}const Ne=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Ne){D.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Ne===i.name){r(null);return}if(k.some(W=>W.name===Ne)){D.error(n("settings.skills.page.toast.skillExists"));return}await u(i.name,Ne,F)?(D.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Ne})),P(Ne)):D.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[25]=i,e[26]=l,e[27]=u,e[28]=P,e[29]=F,e[30]=k,e[31]=n,e[32]=Z):Z=e[32];const K=Z;let ae;e[33]!==k?(ae=k.filter(Nm),e[33]=k,e[34]=ae):ae=e[34];const _=ae;let B;e[35]!==k?(B=k.filter(Sm),e[35]=k,e[36]=B):B=e[36];const M=B;let U;e[37]===Symbol.for("react.memo_cache_sentinel")?(U=function(Ct){const W={},me=[];for(const Pe of Ct)Pe.group?(W[Pe.group]||(W[Pe.group]=[]),W[Pe.group].push(Pe)):me.push(Pe);const Ee=Object.keys(W).sort(Cm).map(Pe=>({name:Pe,skills:[...W[Pe]].sort(Pm)}));return me.sort(Im),{sortedGroups:Ee,ungrouped:me}},e[37]=U):U=e[37];const Y=U;let X;e[38]!==_?(X=Y(_),e[38]=_,e[39]=X):X=e[39];const ne=X;let te;e[40]!==M?(te=Y(M),e[40]=M,e[41]=te):te=e[41];const ge=te;let ee;e[42]===Symbol.for("react.memo_cache_sentinel")?(ee=ye("flex h-full flex-col","bg-background"),e[42]=ee):ee=e[42];let le;e[43]!==n?(le=n("settings.skills.sidebar.title"),e[43]=n,e[44]=le):le=e[44];let pe;e[45]!==le?(pe=s.jsx("h2",{className:`${an} mb-3`,children:le}),e[45]=le,e[46]=pe):pe=e[46];let ie;e[47]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(Fa,{className:"mb-3"}),e[47]=ie):ie=e[47];let je;e[48]!==k.length||e[49]!==n?(je=n("settings.skills.sidebar.total",{count:k.length}),e[48]=k.length,e[49]=n,e[50]=je):je=e[50];let Se;e[51]!==je?(Se=s.jsx("span",{className:"typography-meta text-muted-foreground",children:je}),e[51]=je,e[52]=Se):Se=e[52];let Ce;e[53]===Symbol.for("react.memo_cache_sentinel")?(Ce=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[53]=Ce):Ce=e[53];let xe;e[54]!==R?(xe=s.jsx(V,{size:"sm","data-settings-item":"skills.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:R,children:Ce}),e[54]=R,e[55]=xe):xe=e[55];let Re;e[56]!==Se||e[57]!==xe?(Re=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Se,xe]}),e[56]=Se,e[57]=xe,e[58]=Re):Re=e[58];let Oe;e[59]!==pe||e[60]!==Re?(Oe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[pe,ie,Re]}),e[59]=pe,e[60]=Re,e[61]=Oe):Oe=e[61];let fe;e[62]!==ne||e[63]!==ge||e[64]!==J||e[65]!==a||e[66]!==m||e[67]!==_||e[68]!==v||e[69]!==P||e[70]!==k.length||e[71]!==n||e[72]!==M?(fe=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(L,{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")}),ne.sortedGroups.map(Ne=>{const{name:Ct,skills:W}=Ne;return s.jsx(Yi,{label:Ct,count:W.length,storageKey:"project-skills",children:W.map(me=>s.jsx(Ja,{skill:me,isSelected:v===me.name,onSelect:()=>{P(me.name),a?.()},onRename:()=>Q(me),onDelete:()=>O(me),onDuplicate:()=>J(me),isMenuOpen:m===me.name,onMenuOpenChange:Ee=>E(Ee?me.name:null)},me.name))},Ct)}),ne.ungrouped.map(Ne=>s.jsx(Ja,{skill:Ne,isSelected:v===Ne.name,onSelect:()=>{P(Ne.name),a?.()},onRename:()=>Q(Ne),onDelete:()=>O(Ne),onDuplicate:()=>J(Ne),isMenuOpen:m===Ne.name,onMenuOpenChange:Ct=>E(Ct?Ne.name:null)},Ne.name))]}),M.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")}),ge.sortedGroups.map(Ne=>{const{name:Ct,skills:W}=Ne;return s.jsx(Yi,{label:Ct,count:W.length,storageKey:"user-skills",children:W.map(me=>s.jsx(Ja,{skill:me,isSelected:v===me.name,onSelect:()=>{P(me.name),a?.()},onRename:()=>Q(me),onDelete:()=>O(me),onDuplicate:()=>J(me),isMenuOpen:m===me.name,onMenuOpenChange:Ee=>E(Ee?me.name:null)},me.name))},Ct)}),ge.ungrouped.map(Ne=>s.jsx(Ja,{skill:Ne,isSelected:v===Ne.name,onSelect:()=>{P(Ne.name),a?.()},onRename:()=>Q(Ne),onDelete:()=>O(Ne),onDuplicate:()=>J(Ne),isMenuOpen:m===Ne.name,onMenuOpenChange:Ct=>E(Ct?Ne.name:null)},Ne.name))]})]})}),e[62]=ne,e[63]=ge,e[64]=J,e[65]=a,e[66]=m,e[67]=_,e[68]=v,e[69]=P,e[70]=k.length,e[71]=n,e[72]=M,e[73]=fe):fe=e[73];const be=d!==null;let De;e[74]!==c?(De=Ne=>{!Ne&&!c&&b(null)},e[74]=c,e[75]=De):De=e[75];let _e;e[76]!==n?(_e=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=_e):_e=e[77];let Le;e[78]!==_e?(Le=s.jsx(Jt,{children:_e}),e[78]=_e,e[79]=Le):Le=e[79];const qe=d?.name??"";let Ke;e[80]!==n||e[81]!==qe?(Ke=n("settings.skills.sidebar.deleteDialog.description",{name:qe}),e[80]=n,e[81]=qe,e[82]=Ke):Ke=e[82];let Xe;e[83]!==Ke?(Xe=s.jsx(Qt,{children:Ke}),e[83]=Ke,e[84]=Xe):Xe=e[84];let We;e[85]!==Le||e[86]!==Xe?(We=s.jsxs(Wt,{children:[Le,Xe]}),e[85]=Le,e[86]=Xe,e[87]=We):We=e[87];let Ze;e[88]===Symbol.for("react.memo_cache_sentinel")?(Ze=()=>b(null),e[88]=Ze):Ze=e[88];let we;e[89]!==n?(we=n("settings.common.actions.cancel"),e[89]=n,e[90]=we):we=e[90];let Je;e[91]!==c||e[92]!==we?(Je=s.jsx(V,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Ze,disabled:c,children:we}),e[91]=c,e[92]=we,e[93]=Je):Je=e[93];let Me;e[94]!==n?(Me=n("settings.common.actions.delete"),e[94]=n,e[95]=Me):Me=e[95];let ve;e[96]!==S||e[97]!==c||e[98]!==Me?(ve=s.jsx(V,{size:"sm",onClick:S,disabled:c,children:Me}),e[96]=S,e[97]=c,e[98]=Me,e[99]=ve):ve=e[99];let $e;e[100]!==Je||e[101]!==ve?($e=s.jsxs(ds,{children:[Je,ve]}),e[100]=Je,e[101]=ve,e[102]=$e):$e=e[102];let $;e[103]!==We||e[104]!==$e?($=s.jsxs(Bt,{className:"max-w-md",children:[We,$e]}),e[103]=We,e[104]=$e,e[105]=$):$=e[105];let de;e[106]!==be||e[107]!==De||e[108]!==$?(de=s.jsx(Vt,{open:be,onOpenChange:De,children:$}),e[106]=be,e[107]=De,e[108]=$,e[109]=de):de=e[109];const ue=i!==null;let ke;e[110]===Symbol.for("react.memo_cache_sentinel")?(ke=Ne=>!Ne&&r(null),e[110]=ke):ke=e[110];let oe;e[111]!==n?(oe=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=oe):oe=e[112];let Ae;e[113]!==oe?(Ae=s.jsx(Jt,{children:oe}),e[113]=oe,e[114]=Ae):Ae=e[114];const H=i?.name??"";let ze;e[115]!==n||e[116]!==H?(ze=n("settings.skills.sidebar.renameDialog.description",{name:H}),e[115]=n,e[116]=H,e[117]=ze):ze=e[117];let tt;e[118]!==ze?(tt=s.jsx(Qt,{children:ze}),e[118]=ze,e[119]=tt):tt=e[119];let Fe;e[120]!==Ae||e[121]!==tt?(Fe=s.jsxs(Wt,{children:[Ae,tt]}),e[120]=Ae,e[121]=tt,e[122]=Fe):Fe=e[122];let at;e[123]===Symbol.for("react.memo_cache_sentinel")?(at=Ne=>h(Ne.target.value),e[123]=at):at=e[123];let wt;e[124]!==n?(wt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=wt):wt=e[125];let bt;e[126]!==K?(bt=Ne=>{Ne.key==="Enter"&&K()},e[126]=K,e[127]=bt):bt=e[127];let ut;e[128]!==l||e[129]!==wt||e[130]!==bt?(ut=s.jsx(He,{value:l,onChange:at,placeholder:wt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:bt}),e[128]=l,e[129]=wt,e[130]=bt,e[131]=ut):ut=e[131];let gt;e[132]===Symbol.for("react.memo_cache_sentinel")?(gt=()=>r(null),e[132]=gt):gt=e[132];let Pt;e[133]!==n?(Pt=n("settings.common.actions.cancel"),e[133]=n,e[134]=Pt):Pt=e[134];let jt;e[135]!==Pt?(jt=s.jsx(V,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:gt,children:Pt}),e[135]=Pt,e[136]=jt):jt=e[136];let Et;e[137]!==n?(Et=n("settings.common.actions.rename"),e[137]=n,e[138]=Et):Et=e[138];let Ye;e[139]!==K||e[140]!==Et?(Ye=s.jsx(V,{size:"sm",onClick:K,children:Et}),e[139]=K,e[140]=Et,e[141]=Ye):Ye=e[141];let Ge;e[142]!==jt||e[143]!==Ye?(Ge=s.jsxs(ds,{children:[jt,Ye]}),e[142]=jt,e[143]=Ye,e[144]=Ge):Ge=e[144];let ct;e[145]!==Fe||e[146]!==ut||e[147]!==Ge?(ct=s.jsxs(Bt,{children:[Fe,ut,Ge]}),e[145]=Fe,e[146]=ut,e[147]=Ge,e[148]=ct):ct=e[148];let Ie;e[149]!==ue||e[150]!==ct?(Ie=s.jsx(Vt,{open:ue,onOpenChange:ke,children:ct}),e[149]=ue,e[150]=ct,e[151]=Ie):Ie=e[151];let It;return e[152]!==Oe||e[153]!==fe||e[154]!==de||e[155]!==Ie?(It=s.jsxs("div",{className:ee,children:[Oe,fe,de,Ie]}),e[152]=Oe,e[153]=fe,e[154]=de,e[155]=Ie,e[156]=It):It=e[156],It},Ja=t=>{const e=mt.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:h,isMenuOpen:d,onMenuOpenChange:b}=t,{t:c}=rt();let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=Ra(),e[0]=j):j=e[0];const m=j;let E;e[1]!==a?(E=Da(a),e[1]=a,e[2]=E):E=e[2];const v=E;let P;e[3]!==a?(P=sr(a),e[3]=a,e[4]=P):P=e[4];const x=P,[C,u]=o.useState(!1);let I;e[5]!==x||e[6]!==r||e[7]!==h||e[8]!==l||e[9]!==c?(I=J=>s.jsxs(s.Fragment,{children:[x?s.jsxs(J,{onClick:T=>{T.stopPropagation(),l()},children:[s.jsx(L,{name:"edit",className:"h-4 w-4 mr-px"}),c("settings.common.actions.rename")]}):null,s.jsxs(J,{onClick:T=>{T.stopPropagation(),h()},children:[s.jsx(L,{name:"file-copy",className:"h-4 w-4 mr-px"}),c("settings.common.actions.duplicate")]}),s.jsxs(J,{onClick:T=>{T.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),c("settings.common.actions.delete")]})]}),e[5]=x,e[6]=r,e[7]=h,e[8]=l,e[9]=c,e[10]=I):I=e[10];const F=I,A=!v&&C,k=n?"bg-interactive-selection":"hover:bg-interactive-hover";let g;e[11]!==k?(g=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",k),e[11]=k,e[12]=g):g=e[12];let w;e[13]!==v?(w=!m&&!v?J=>{J.preventDefault(),u(!0)}:void 0,e[13]=v,e[14]=w):w=e[14];let z;e[15]!==g||e[16]!==w?(z=s.jsx("div",{className:g,onContextMenu:w}),e[15]=g,e[16]=w,e[17]=z):z=e[17];let N;e[18]!==a.name?(N=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]=N):N=e[19];let R;e[20]!==i||e[21]!==N?(R=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:N}),e[20]=i,e[21]=N,e[22]=R):R=e[22];let y;e[23]!==v||e[24]!==d||e[25]!==b||e[26]!==F?(y=v?null:s.jsxs(sn,{open:d,onOpenChange:J=>{J&&u(!1),b(J)},children:[s.jsx(en,{asChild:!0,children:s.jsx(V,{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(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(tn,{align:"end",className:"w-fit min-w-20",children:F(nn)})]}),e[23]=v,e[24]=d,e[25]=b,e[26]=F,e[27]=y):y=e[27];let O;e[28]!==R||e[29]!==y?(O=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[R,y]}),e[28]=R,e[29]=y,e[30]=O):O=e[30];let q;e[31]!==O||e[32]!==z?(q=s.jsx(Bn,{render:z,children:O}),e[31]=O,e[32]=z,e[33]=q):q=e[33];let S;e[34]!==v||e[35]!==F?(S=v?null:s.jsx($n,{className:"w-fit min-w-20",children:F(Vn)}),e[34]=v,e[35]=F,e[36]=S):S=e[36];let G;return e[37]!==q||e[38]!==S||e[39]!==A?(G=s.jsxs(Hn,{open:A,onOpenChange:u,children:[q,S]}),e[37]=q,e[38]=S,e[39]=A,e[40]=G):G=e[40],G};function wm(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function km(t){return t.loadSkills}function Nm(t){return t.scope==="project"}function Sm(t){return t.scope==="user"}function Cm(t,e){return t.localeCompare(e)}function Pm(t,e){return t.name.localeCompare(e.name)}function Im(t,e){return t.name.localeCompare(e.name)}const Am=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Em=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},Tm=async()=>{try{const t=An()?.settings;if(t)return(await t.load())?.settings||{};const e=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Dm=t=>{const e=mt.c(162),{open:a,onOpenChange:n}=t,{t:i}=rt(),r=cn(Mm),l=cn(Rm),h=cn(Om),d=cn(Lm),b=cn(Fm),c=Un(Km),j=Un(Um),[m,E]=o.useState(""),[v,P]=o.useState(""),[x,C]=o.useState("");let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];const[I,F]=o.useState(u),[A,k]=o.useState(null),[g,w]=o.useState(!1);let z;e[1]===Symbol.for("react.memo_cache_sentinel")?(z=[],e[1]=z):z=e[1];const[N,R]=o.useState(z),[y,O]=o.useState(null),q=o.useRef(0);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=Ge=>{q.current=q.current+1,w(!1),k(null),Ge?.clearIdentity&&(R([]),O(null))},e[2]=S):S=e[2];const G=S;let J,T;e[3]!==j||e[4]!==a?(J=()=>{a&&(q.current=q.current+1,E(""),P(""),C(""),k(null),w(!1),R([]),O(null),j(),(async()=>{const Ge=await Tm(),ct=Array.isArray(Ge?.skillCatalogs)?Ge?.skillCatalogs:[];F(ct||[])})())},T=[a,j],e[3]=j,e[4]=a,e[5]=J,e[6]=T):(J=e[5],T=e[6]),o.useEffect(J,T);let Q;e[7]!==v?(Q=v.trim(),e[7]=v,e[8]=Q):Q=e[8];const Z=Q;let K;e[9]!==x?(K=x.trim(),e[9]=x,e[10]=K):K=e[10];const ae=K;let _;if(e[11]!==I||e[12]!==Z||e[13]!==ae){let Ge;e[15]!==Z||e[16]!==ae?(Ge=ct=>{const Ie=(ct.source||"").trim(),It=(ct.subpath||"").trim();return Ie===Z&&It===ae},e[15]=Z,e[16]=ae,e[17]=Ge):Ge=e[17],_=I.some(Ge),e[11]=I,e[12]=Z,e[13]=ae,e[14]=_}else _=e[14];const B=_;let M;e[18]!==c||e[19]!==y||e[20]!==m||e[21]!==r||e[22]!==v||e[23]!==x||e[24]!==i?(M=async()=>{const Ge=v.trim();if(!Ge){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||E(Em(Ge)),w(!1),k(null);const ct=q.current+1;q.current=ct;const Ie=await r({source:Ge,subpath:x.trim()||void 0,gitIdentityId:y||void 0});if(q.current!==ct)return;if(!Ie.ok){if(Ie.error?.kind==="authRequired"){if(xs()){D.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Ne=Ie.error.identities||[];if(R(Ne),!y&&Ne.length>0){const Ct=c&&c!=="global"&&Ne.some(W=>W.id===c)?c:Ne[0].id;O(Ct)}D.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}D.error(Ie.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const It=Ie.items?.length||0;if(k(It),It===0){D.error(i("settings.skills.catalog.add.toast.noSkillsFound")),w(!1);return}R([]),w(!0),D.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:It}))},e[18]=c,e[19]=y,e[20]=m,e[21]=r,e[22]=v,e[23]=x,e[24]=i,e[25]=M):M=e[25];const U=M;let Y;e[26]!==I||e[27]!==y||e[28]!==B||e[29]!==m||e[30]!==l||e[31]!==h||e[32]!==n||e[33]!==g||e[34]!==d||e[35]!==v||e[36]!==x||e[37]!==i?(Y=async()=>{const Ge=m.trim(),ct=v.trim(),Ie=x.trim();if(!Ge){D.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!ct){D.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!g){D.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(B){D.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const It={id:Am(),label:Ge,source:ct,...Ie?{subpath:Ie}:{},...y?{gitIdentityId:y}:{}},Ne=[...I,It];try{await kt({skillCatalogs:Ne}),F(Ne),D.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await h(It.id,{refresh:!0}),d(It.id),n(!1)}catch(Ct){const W=Ct;D.error(W instanceof Error?W.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=I,e[27]=y,e[28]=B,e[29]=m,e[30]=l,e[31]=h,e[32]=n,e[33]=g,e[34]=d,e[35]=v,e[36]=x,e[37]=i,e[38]=Y):Y=e[38];const X=Y;let ne;e[39]!==i?(ne=i("settings.skills.catalog.add.title"),e[39]=i,e[40]=ne):ne=e[40];let te;e[41]!==ne?(te=s.jsx(Jt,{children:ne}),e[41]=ne,e[42]=te):te=e[42];let ge;e[43]!==i?(ge=i("settings.skills.catalog.add.descriptionPrefix"),e[43]=i,e[44]=ge):ge=e[44];let ee;e[45]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=ee):ee=e[45];let le;e[46]!==i?(le=i("settings.skills.catalog.add.descriptionSuffix"),e[46]=i,e[47]=le):le=e[47];let pe;e[48]!==ge||e[49]!==le?(pe=s.jsxs(Qt,{children:[ge," ",ee,le]}),e[48]=ge,e[49]=le,e[50]=pe):pe=e[50];let ie;e[51]!==te||e[52]!==pe?(ie=s.jsxs(Wt,{children:[te,pe]}),e[51]=te,e[52]=pe,e[53]=ie):ie=e[53];let je;e[54]!==i?(je=i("settings.skills.catalog.add.field.catalogName"),e[54]=i,e[55]=je):je=e[55];let Se;e[56]!==je?(Se=s.jsx("label",{className:"typography-ui-label text-foreground",children:je}),e[56]=je,e[57]=Se):Se=e[57];let Ce;e[58]===Symbol.for("react.memo_cache_sentinel")?(Ce=Ge=>E(Ge.target.value),e[58]=Ce):Ce=e[58];let xe;e[59]!==i?(xe=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=i,e[60]=xe):xe=e[60];let Re;e[61]!==m||e[62]!==xe?(Re=s.jsx(He,{value:m,onChange:Ce,placeholder:xe}),e[61]=m,e[62]=xe,e[63]=Re):Re=e[63];let Oe;e[64]!==Se||e[65]!==Re?(Oe=s.jsxs("div",{className:"space-y-2",children:[Se,Re]}),e[64]=Se,e[65]=Re,e[66]=Oe):Oe=e[66];let fe;e[67]!==i?(fe=i("settings.skills.catalog.add.field.repository"),e[67]=i,e[68]=fe):fe=e[68];let be;e[69]!==fe?(be=s.jsx("label",{className:"typography-ui-label text-foreground",children:fe}),e[69]=fe,e[70]=be):be=e[70];let De;e[71]!==i?(De=i("settings.skills.catalog.add.field.repositoryHint"),e[71]=i,e[72]=De):De=e[72];let _e;e[73]!==De?(_e=s.jsx(ts,{children:De}),e[73]=De,e[74]=_e):_e=e[74];let Le;e[75]!==be||e[76]!==_e?(Le=s.jsxs("div",{className:"flex items-center gap-1",children:[be,_e]}),e[75]=be,e[76]=_e,e[77]=Le):Le=e[77];let qe;e[78]===Symbol.for("react.memo_cache_sentinel")?(qe=Ge=>{P(Ge.target.value),G({clearIdentity:!0})},e[78]=qe):qe=e[78];let Ke;e[79]!==i?(Ke=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[79]=i,e[80]=Ke):Ke=e[80];let Xe;e[81]!==v||e[82]!==Ke?(Xe=s.jsx(He,{value:v,onChange:qe,placeholder:Ke}),e[81]=v,e[82]=Ke,e[83]=Xe):Xe=e[83];let We;e[84]!==Le||e[85]!==Xe?(We=s.jsxs("div",{className:"space-y-2",children:[Le,Xe]}),e[84]=Le,e[85]=Xe,e[86]=We):We=e[86];let Ze;e[87]!==i?(Ze=i("settings.skills.catalog.add.field.optionalSubpath"),e[87]=i,e[88]=Ze):Ze=e[88];let we;e[89]!==Ze?(we=s.jsx("label",{className:"typography-ui-label text-foreground",children:Ze}),e[89]=Ze,e[90]=we):we=e[90];let Je;e[91]===Symbol.for("react.memo_cache_sentinel")?(Je=Ge=>{C(Ge.target.value),G({clearIdentity:!0})},e[91]=Je):Je=e[91];let Me;e[92]!==i?(Me=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[92]=i,e[93]=Me):Me=e[93];let ve;e[94]!==x||e[95]!==Me?(ve=s.jsx(He,{value:x,onChange:Je,placeholder:Me}),e[94]=x,e[95]=Me,e[96]=ve):ve=e[96];let $e;e[97]!==we||e[98]!==ve?($e=s.jsxs("div",{className:"space-y-2",children:[we,ve]}),e[97]=we,e[98]=ve,e[99]=$e):$e=e[99];let $;e[100]!==y||e[101]!==N||e[102]!==i?($=N.length>0&&!xs()?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(ts,{className:"ml-1",children:i("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Lt,{value:y||"",onValueChange:Ge=>{O(Ge),G()},children:[s.jsx(Ft,{className:"w-fit",children:s.jsx("span",{children:N.find(Ge=>Ge.id===y)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(Kt,{align:"start",children:N.map(zm)})]})]}):null,e[100]=y,e[101]=N,e[102]=i,e[103]=$):$=e[103];let de;e[104]!==A||e[105]!==i?(de=A!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:A})}):null,e[104]=A,e[105]=i,e[106]=de):de=e[106];let ue;e[107]!==B||e[108]!==i?(ue=B?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[107]=B,e[108]=i,e[109]=ue):ue=e[109];let ke;e[110]!==Oe||e[111]!==We||e[112]!==$e||e[113]!==$||e[114]!==de||e[115]!==ue?(ke=s.jsxs("div",{className:"space-y-4",children:[Oe,We,$e,$,de,ue]}),e[110]=Oe,e[111]=We,e[112]=$e,e[113]=$,e[114]=de,e[115]=ue,e[116]=ke):ke=e[116];let oe;e[117]!==n?(oe=()=>n(!1),e[117]=n,e[118]=oe):oe=e[118];let Ae;e[119]!==i?(Ae=i("settings.common.actions.cancel"),e[119]=i,e[120]=Ae):Ae=e[120];let H;e[121]!==oe||e[122]!==Ae?(H=s.jsx(V,{size:"sm",variant:"ghost",onClick:oe,children:Ae}),e[121]=oe,e[122]=Ae,e[123]=H):H=e[123];let ze;e[124]!==U?(ze=()=>{U()},e[124]=U,e[125]=ze):ze=e[125];let tt;e[126]!==b||e[127]!==v?(tt=b||!v.trim(),e[126]=b,e[127]=v,e[128]=tt):tt=e[128];let Fe;e[129]===Symbol.for("react.memo_cache_sentinel")?(Fe=s.jsx(L,{name:"git-repository",className:"h-4 w-4"}),e[129]=Fe):Fe=e[129];let at;e[130]!==b||e[131]!==i?(at=i(b?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[130]=b,e[131]=i,e[132]=at):at=e[132];let wt;e[133]!==ze||e[134]!==tt||e[135]!==at?(wt=s.jsxs(V,{size:"sm",className:"gap-2",variant:"ghost",onClick:ze,disabled:tt,children:[Fe,at]}),e[133]=ze,e[134]=tt,e[135]=at,e[136]=wt):wt=e[136];let bt;e[137]!==X?(bt=()=>{X()},e[137]=X,e[138]=bt):bt=e[138];let ut;e[139]!==B||e[140]!==m||e[141]!==g||e[142]!==v?(ut=!g||B||!m.trim()||!v.trim(),e[139]=B,e[140]=m,e[141]=g,e[142]=v,e[143]=ut):ut=e[143];let gt;e[144]!==i?(gt=i("settings.skills.catalog.add.actions.addCatalog"),e[144]=i,e[145]=gt):gt=e[145];let Pt;e[146]!==bt||e[147]!==ut||e[148]!==gt?(Pt=s.jsx(V,{size:"sm",onClick:bt,disabled:ut,children:gt}),e[146]=bt,e[147]=ut,e[148]=gt,e[149]=Pt):Pt=e[149];let jt;e[150]!==H||e[151]!==wt||e[152]!==Pt?(jt=s.jsxs(ds,{children:[H,wt,Pt]}),e[150]=H,e[151]=wt,e[152]=Pt,e[153]=jt):jt=e[153];let Et;e[154]!==ie||e[155]!==ke||e[156]!==jt?(Et=s.jsxs(Bt,{className:"max-w-xl",children:[ie,ke,jt]}),e[154]=ie,e[155]=ke,e[156]=jt,e[157]=Et):Et=e[157];let Ye;return e[158]!==n||e[159]!==a||e[160]!==Et?(Ye=s.jsx(Vt,{open:a,onOpenChange:n,children:Et}),e[158]=n,e[159]=a,e[160]=Et,e[161]=Ye):Ye=e[161],Ye};function Mm(t){return t.scanRepo}function Rm(t){return t.loadCatalog}function Om(t){return t.loadSource}function Lm(t){return t.setSelectedSource}function Fm(t){return t.isScanning}function Km(t){return t.defaultGitIdentityId}function Um(t){return t.loadDefaultGitIdentityId}function zm(t){return s.jsx(pt,{value:t.id,children:t.name},t.id)}const _m=t=>{const e=mt.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=rt();let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={},e[0]=h):h=e[0];const[d,b]=o.useState(h);let c,j;e[1]!==i||e[2]!==a?(c=()=>{if(!a)return;const X={};for(const ne of i)X[ne.skillName]="skip";b(X)},j=[a,i],e[1]=i,e[2]=a,e[3]=c,e[4]=j):(c=e[3],j=e[4]),o.useEffect(c,j);let m;e[5]!==i?(m=X=>{const ne={};for(const te of i)ne[te.skillName]=X;b(ne)},e[5]=i,e[6]=m):m=e[6];const E=m;let v;e[7]!==i||e[8]!==d?(v=i.length>0&&i.every(X=>d[X.skillName]),e[7]=i,e[8]=d,e[9]=v):v=e[9];const P=v;let x;e[10]!==l?(x=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=x):x=e[11];let C;e[12]!==x?(C=s.jsx(Jt,{children:x}),e[12]=x,e[13]=C):C=e[13];let u;e[14]!==l?(u=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=u):u=e[15];let I;e[16]!==u?(I=s.jsx(Qt,{children:u}),e[16]=u,e[17]=I):I=e[17];let F;e[18]!==C||e[19]!==I?(F=s.jsxs(Wt,{children:[C,I]}),e[18]=C,e[19]=I,e[20]=F):F=e[20];let A;e[21]!==i.length||e[22]!==l?(A=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=l,e[23]=A):A=e[23];let k;e[24]!==A?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:A}),e[24]=A,e[25]=k):k=e[25];let g;e[26]!==E?(g=()=>E("skip"),e[26]=E,e[27]=g):g=e[27];let w;e[28]!==l?(w=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=w):w=e[29];let z;e[30]!==g||e[31]!==w?(z=s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:g,children:w}),e[30]=g,e[31]=w,e[32]=z):z=e[32];let N;e[33]!==E?(N=()=>E("overwrite"),e[33]=E,e[34]=N):N=e[34];let R;e[35]!==l?(R=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=R):R=e[36];let y;e[37]!==N||e[38]!==R?(y=s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:N,children:R}),e[37]=N,e[38]=R,e[39]=y):y=e[39];let O;e[40]!==z||e[41]!==y?(O=s.jsxs("div",{className:"flex items-center gap-2",children:[z,y]}),e[40]=z,e[41]=y,e[42]=O):O=e[42];let q;e[43]!==k||e[44]!==O?(q=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,O]}),e[43]=k,e[44]=O,e[45]=q):q=e[45];let S;if(e[46]!==i||e[47]!==d||e[48]!==l){let X;e[50]!==d||e[51]!==l?(X=ne=>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:ne.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:ne.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:ne.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Lt,{value:d[ne.skillName]||"skip",onValueChange:te=>b(ge=>({...ge,[ne.skillName]:te})),children:[s.jsx(Ft,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[ne.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(Kt,{align:"end",children:[s.jsx(pt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(pt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},ne.skillName),e[50]=d,e[51]=l,e[52]=X):X=e[52],S=i.map(X),e[46]=i,e[47]=d,e[48]=l,e[49]=S}else S=e[49];let G;e[53]!==S?(G=s.jsx("div",{className:"space-y-2",children:S}),e[53]=S,e[54]=G):G=e[54];let J;e[55]!==q||e[56]!==G?(J=s.jsxs("div",{className:"space-y-3",children:[q,G]}),e[55]=q,e[56]=G,e[57]=J):J=e[57];let T;e[58]!==n?(T=()=>n(!1),e[58]=n,e[59]=T):T=e[59];let Q;e[60]!==l?(Q=l("settings.common.actions.cancel"),e[60]=l,e[61]=Q):Q=e[61];let Z;e[62]!==T||e[63]!==Q?(Z=s.jsx(V,{size:"sm",variant:"ghost",onClick:T,children:Q}),e[62]=T,e[63]=Q,e[64]=Z):Z=e[64];let K;e[65]!==d||e[66]!==r?(K=()=>r(d),e[65]=d,e[66]=r,e[67]=K):K=e[67];const ae=!P;let _;e[68]!==l?(_=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=_):_=e[69];let B;e[70]!==K||e[71]!==ae||e[72]!==_?(B=s.jsx(V,{size:"sm",onClick:K,disabled:ae,children:_}),e[70]=K,e[71]=ae,e[72]=_,e[73]=B):B=e[73];let M;e[74]!==Z||e[75]!==B?(M=s.jsxs(ds,{children:[Z,B]}),e[74]=Z,e[75]=B,e[76]=M):M=e[76];let U;e[77]!==F||e[78]!==J||e[79]!==M?(U=s.jsxs(Bt,{className:"max-w-2xl",children:[F,J,M]}),e[77]=F,e[78]=J,e[79]=M,e[80]=U):U=e[80];let Y;return e[81]!==n||e[82]!==a||e[83]!==U?(Y=s.jsx(Vt,{open:a,onOpenChange:n,children:U}),e[81]=n,e[82]=a,e[83]=U,e[84]=Y):Y=e[84],Y},hr=[{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 Ma(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 Al(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=hr.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const $m=t=>{const e=mt.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=rt(),l=cn(Vm),h=cn(Bm),[d,b]=o.useState("user"),[c,j]=o.useState("opencode"),m=Qs(Hm),E=Qs(Gm),[v,P]=o.useState(null),[x,C]=o.useState(!1);let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=[],e[0]=u):u=e[0];const[I,F]=o.useState(u),[A,k]=o.useState(null);let g,w;e[1]!==E||e[2]!==a?(g=()=>{a&&(b("user"),j("opencode"),P(E),C(!1),F([]),k(null))},w=[a,E],e[1]=E,e[2]=a,e[3]=g,e[4]=w):(g=e[3],w=e[4]),o.useEffect(g,w);let z;e[5]!==r?(z=ve=>{switch(ve){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]=z):z=e[6];const N=z;let R;e[7]!==r?(R=ve=>{switch(ve){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]=R):R=e[8];const y=R;let O;e:{if(m.length===0){O=null;break e}if(v&&m.some(ve=>ve.id===v)){O=v;break e}if(E&&m.some(ve=>ve.id===E)){O=E;break e}O=m[0]?.id??null}const q=O;let S;e:{if(d!=="project"){S=null;break e}const ve=q;if(!ve){S=null;break e}let $e;if(e[9]!==ve||e[10]!==m){let de;e[12]!==ve?(de=ue=>ue.id===ve,e[12]=ve,e[13]=de):de=e[13],$e=m.find(de),e[9]=ve,e[10]=m,e[11]=$e}else $e=e[11];S=$e?.path??null}const G=S;let J;e[14]!==l||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==r?(J=async ve=>{const $e=await l({source:ve.source,subpath:ve.subpath,gitIdentityId:i?.gitIdentityId,scope:ve.scope,targetSource:ve.targetSource,selections:[{skillDir:ve.skillDir}],conflictPolicy:"prompt",conflictDecisions:ve.conflictDecisions},{directory:ve.directoryOverride??null});if($e.ok){D.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if($e.error?.kind==="conflicts"){k({source:ve.source,subpath:ve.subpath,scope:ve.scope,targetSource:ve.targetSource,skillDir:ve.skillDir,directoryOverride:ve.directoryOverride??null}),F($e.error.conflicts),C(!0);return}if($e.error?.kind==="authRequired"){D.error($e.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}D.error($e.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i?.gitIdentityId,e[16]=n,e[17]=r,e[18]=J):J=e[18];const T=J;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 Z;e[21]!==Q?(Z=s.jsx(Jt,{children:Q}),e[21]=Q,e[22]=Z):Z=e[22];let K;e[23]!==r?(K=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=K):K=e[24];let ae;e[25]!==i.skillName?(ae=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=ae):ae=e[26];let _;e[27]!==r?(_=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=_):_=e[28];let B;e[29]!==K||e[30]!==ae||e[31]!==_?(B=s.jsxs(Qt,{children:[K," ",ae," ",_]}),e[29]=K,e[30]=ae,e[31]=_,e[32]=B):B=e[32];let M;e[33]!==Z||e[34]!==B?(M=s.jsxs(Wt,{children:[Z,B]}),e[33]=Z,e[34]=B,e[35]=M):M=e[35];let U;e[36]!==r?(U=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=U):U=e[37];let Y;e[38]!==U?(Y=s.jsx("span",{className:"typography-ui-label text-foreground",children:U}),e[38]=U,e[39]=Y):Y=e[39];let X;e[40]!==d||e[41]!==c?(X=Ma(d,c),e[40]=d,e[41]=c,e[42]=X):X=e[42];let ne;e[43]===Symbol.for("react.memo_cache_sentinel")?(ne=ve=>{const $e=Al(ve);b($e.scope),j($e.source==="agents"?"agents":"opencode")},e[43]=ne):ne=e[43];let te;e[44]!==d?(te=d==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=te):te=e[45];let ge;e[46]!==c?(ge=c==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=c,e[47]=ge):ge=e[47];let ee;e[48]!==N||e[49]!==d||e[50]!==c?(ee=N(Ma(d,c)),e[48]=N,e[49]=d,e[50]=c,e[51]=ee):ee=e[51];let le;e[52]!==ee?(le=s.jsx("span",{children:ee}),e[52]=ee,e[53]=le):le=e[53];let pe;e[54]!==te||e[55]!==ge||e[56]!==le?(pe=s.jsxs(Ft,{className:"w-fit gap-1.5",children:[te,ge,le]}),e[54]=te,e[55]=ge,e[56]=le,e[57]=pe):pe=e[57];let ie;e[58]!==y||e[59]!==N?(ie=hr.map(ve=>s.jsx(pt,{value:ve.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:[ve.scope==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),ve.source==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:N(ve.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:y(ve.value)})]})},ve.value)),e[58]=y,e[59]=N,e[60]=ie):ie=e[60];let je;e[61]!==ie?(je=s.jsx(Kt,{align:"start",children:ie}),e[61]=ie,e[62]=je):je=e[62];let Se;e[63]!==X||e[64]!==pe||e[65]!==je?(Se=s.jsxs(Lt,{value:X,onValueChange:ne,children:[pe,je]}),e[63]=X,e[64]=pe,e[65]=je,e[66]=Se):Se=e[66];let Ce;e[67]!==Y||e[68]!==Se?(Ce=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Y,Se]}),e[67]=Y,e[68]=Se,e[69]=Ce):Ce=e[69];let xe;e[70]!==m||e[71]!==q||e[72]!==d||e[73]!==r?(xe=d==="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")}),m.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Lt,{value:q??"",onValueChange:ve=>P(ve),disabled:m.length===1,children:[s.jsx(Ft,{className:"w-fit",children:s.jsx($t,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(Kt,{align:"start",children:m.map(qm)})]})]}),e[70]=m,e[71]=q,e[72]=d,e[73]=r,e[74]=xe):xe=e[74];let Re;e[75]!==i.warnings?(Re=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]=Re):Re=e[76];let Oe;e[77]!==Ce||e[78]!==xe||e[79]!==Re?(Oe=s.jsxs("div",{className:"mt-2 space-y-3",children:[Ce,xe,Re]}),e[77]=Ce,e[78]=xe,e[79]=Re,e[80]=Oe):Oe=e[80];let fe;e[81]!==n?(fe=()=>n(!1),e[81]=n,e[82]=fe):fe=e[82];let be;e[83]!==r?(be=r("settings.common.actions.cancel"),e[83]=r,e[84]=be):be=e[84];let De;e[85]!==fe||e[86]!==be?(De=s.jsx(V,{size:"sm",variant:"ghost",onClick:fe,children:be}),e[85]=fe,e[86]=be,e[87]=De):De=e[87];const _e=h||!i.installable||d==="project"&&!G;let Le;e[88]!==G||e[89]!==T||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==d||e[94]!==c?(Le=()=>{T({source:i.repoSource,subpath:i.repoSubpath,scope:d,targetSource:c,skillDir:i.skillDir,directoryOverride:G})},e[88]=G,e[89]=T,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=d,e[94]=c,e[95]=Le):Le=e[95];let qe;e[96]!==h||e[97]!==r?(qe=r(h?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=h,e[97]=r,e[98]=qe):qe=e[98];let Ke;e[99]!==_e||e[100]!==Le||e[101]!==qe?(Ke=s.jsx(V,{size:"sm",disabled:_e,onClick:Le,children:qe}),e[99]=_e,e[100]=Le,e[101]=qe,e[102]=Ke):Ke=e[102];let Xe;e[103]!==De||e[104]!==Ke?(Xe=s.jsxs(ds,{children:[De,Ke]}),e[103]=De,e[104]=Ke,e[105]=Xe):Xe=e[105];let We;e[106]!==M||e[107]!==Oe||e[108]!==Xe?(We=s.jsxs(Bt,{className:"max-w-md",children:[M,Oe,Xe]}),e[106]=M,e[107]=Oe,e[108]=Xe,e[109]=We):We=e[109];let Ze;e[110]!==n||e[111]!==a||e[112]!==We?(Ze=s.jsx(Vt,{open:a,onOpenChange:n,children:We}),e[110]=n,e[111]=a,e[112]=We,e[113]=Ze):Ze=e[113];let we;e[114]!==A||e[115]!==T?(we=ve=>{A&&(T({source:A.source,subpath:A.subpath,scope:A.scope,targetSource:A.targetSource,skillDir:A.skillDir,conflictDecisions:ve,directoryOverride:A.directoryOverride??null}),C(!1))},e[114]=A,e[115]=T,e[116]=we):we=e[116];let Je;e[117]!==I||e[118]!==x||e[119]!==we?(Je=s.jsx(_m,{open:x,onOpenChange:C,conflicts:I,onConfirm:we}),e[117]=I,e[118]=x,e[119]=we,e[120]=Je):Je=e[120];let Me;return e[121]!==Ze||e[122]!==Je?(Me=s.jsxs(s.Fragment,{children:[Ze,Je]}),e[121]=Ze,e[122]=Je,e[123]=Me):Me=e[123],Me};function Vm(t){return t.installSkills}function Bm(t){return t.isInstalling}function Hm(t){return t.projects}function Gm(t){return t.activeProjectId}function qm(t){return s.jsx(pt,{value:t.id,children:t.label||t.path},t.id)}const Wm=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,Jm=t=>{const e=t.trim();return Wm.test(e)?`https://github.com/${e}`:null},Qm=t=>{const e=Jm(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let Qa=null;const Ym=t=>{const e=mr();return(!Qa||Qa.locale!==e)&&(Qa={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),Qa.formatter.format(t)},Zm=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)}},Xm=async()=>{try{const t=An()?.settings;if(t)return(await t.load())?.settings||{};const e=await dt("/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=mt.c(50),{source:a,isActive:n,isLoading:i,skillsCount:r,onSelect:l,t:h}=t,d=a.stars??null;let b,c,j,m,E,v,P,x,C,u;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]!==d||e[8]!==h){const k=a.repoUpdatedAt?Zm(a.repoUpdatedAt):null;x="button",C=l,u=n;const g=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==g?(c=ye("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",g),e[19]=g,e[20]=c):c=e[20],E="min-w-0 flex-1 block";let w;e[21]!==a.label?(w=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=w):w=e[22];let z;e[23]!==i||e[24]!==r||e[25]!==h?(z=i?s.jsx(L,{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:h("settings.skills.catalog.page.source.skillsCount",{count:r})}),e[23]=i,e[24]=r,e[25]=h,e[26]=z):z=e[26],e[27]!==w||e[28]!==z?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[w,z]}),e[27]=w,e[28]=z,e[29]=v):v=e[29],e[30]!==a.source?(P=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]=P):P=e[31],b="flex items-center gap-3 mt-1",e[32]!==d||e[33]!==h?(j=d!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:h("settings.skills.catalog.page.source.stars",{count:d}),children:[s.jsx(L,{name:"star",className:"h-3 w-3"}),Ym(d)]}),e[32]=d,e[33]=h,e[34]=j):j=e[34],m=k&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:k.key==="common.relative.justNow"?h(k.key):h("settings.skills.catalog.page.source.updated",{time:h(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]=d,e[8]=h,e[9]=b,e[10]=c,e[11]=j,e[12]=m,e[13]=E,e[14]=v,e[15]=P,e[16]=x,e[17]=C,e[18]=u}else b=e[9],c=e[10],j=e[11],m=e[12],E=e[13],v=e[14],P=e[15],x=e[16],C=e[17],u=e[18];let I;e[35]!==b||e[36]!==j||e[37]!==m?(I=s.jsxs("span",{className:b,children:[j,m]}),e[35]=b,e[36]=j,e[37]=m,e[38]=I):I=e[38];let F;e[39]!==I||e[40]!==E||e[41]!==v||e[42]!==P?(F=s.jsxs("span",{className:E,children:[v,P,I]}),e[39]=I,e[40]=E,e[41]=v,e[42]=P,e[43]=F):F=e[43];let A;return e[44]!==c||e[45]!==F||e[46]!==x||e[47]!==C||e[48]!==u?(A=s.jsx("button",{type:x,onClick:C,"aria-pressed":u,className:c,children:F}),e[44]=c,e[45]=F,e[46]=x,e[47]=C,e[48]=u,e[49]=A):A=e[49],A},tu=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=rt(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:h,loadCatalog:d,loadSource:b,isLoadingCatalog:c,isLoadingSource:j,loadedSourceIds:m,lastCatalogError:E}=cn(Ms(T=>({sources:T.sources,itemsBySource:T.itemsBySource,selectedSourceId:T.selectedSourceId,setSelectedSource:T.setSelectedSource,loadCatalog:T.loadCatalog,loadSource:T.loadSource,isLoadingCatalog:T.isLoadingCatalog,isLoadingSource:T.isLoadingSource,loadedSourceIds:T.loadedSourceIds,lastCatalogError:T.lastCatalogError}))),[v,P]=o.useState(""),[x,C]=o.useState(!1),[u,I]=o.useState(!1),[F,A]=o.useState(null),[k,g]=o.useState(!1),[w,z]=o.useState(!1),N=o.useRef(null);o.useEffect(()=>{d()},[d]),o.useEffect(()=>{const T=i.filter(K=>!m[K.id]);if(T.length===0)return;let Q=!1;return(async()=>{for(const K of T){if(Q)return;await b(K.id)}})(),()=>{Q=!0}},[i,m,b]),o.useEffect(()=>{!l||m[l]||b(l)},[l,m,b]),o.useEffect(()=>{const T=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key.toLowerCase()==="k"&&(Q.preventDefault(),N.current?.focus())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[]);const R=v.trim().length>0,y=o.useMemo(()=>{const T=v.trim().toLowerCase(),Q=Z=>Z.skillName.toLowerCase().includes(T)||(Z.description||"").toLowerCase().includes(T)||(Z.frontmatterName||"").toLowerCase().includes(T);return R?i.flatMap(Z=>(r[Z.id]||[]).filter(Q)):l?r[l]||[]:[]},[i,r,l,v,R]),O=o.useMemo(()=>i.find(T=>T.id===l)||null,[i,l]),q=!!(l&&l.startsWith("custom:")),S=async()=>{if(!(!l||!q)){g(!0);try{const T=await Xm(),Z=(Array.isArray(T?.skillCatalogs)?T?.skillCatalogs:[]).filter(K=>K.id!==l);await kt({skillCatalogs:Z}),await d({refresh:!0}),z(!1)}finally{g(!1)}}},G=R?n("settings.skills.catalog.page.list.searchTitle"):O?.label??"",J=!R&&l!==null&&!m[l]&&(j||c);return s.jsxs(s.Fragment,{children:[s.jsxs(cs,{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(gr,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:T=>e(T),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(L,{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(He,{ref:N,value:v,onChange:T=>P(T.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:ye("h-8 pl-8 w-full",v&&"pr-8")}),v&&s.jsx("button",{type:"button",onClick:()=>{P(""),N.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(L,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(Ue,{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(T=>s.jsx(eu,{source:T,isActive:T.id===l,isLoading:j&&!m[T.id],skillsCount:m[T.id]?(r[T.id]||[]).length:null,onSelect:()=>h(T.id),t:n},T.id)),s.jsxs("button",{type:"button","data-settings-item":"skills.catalog.add-catalog",onClick:()=>C(!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(L,{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")})]})]})]})}),E&&s.jsx(Ue,{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:E.message})]})}),s.jsxs(Ue,{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:G}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:y.length})})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l&&!R?b(l,{refresh:!0}):d({refresh:!0})},disabled:c||j,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(L,{name:"refresh",className:ye("h-3.5 w-3.5",(c||j)&&"animate-spin")})}),q&&!R&&s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>z(!0),disabled:k,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),J||j&&y.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(L,{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")})]}):y.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:y.map(T=>{const Q=T.installed?.isInstalled,Z=T.installed?.scope,K=Qm(T);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:T.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:Z||n("settings.skills.catalog.page.badge.unknown")})}),!T.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")})]}),T.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:T.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:[K?s.jsxs("a",{href:K,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(L,{name:"github",className:"h-3 w-3 shrink-0"}),T.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:T.repoSource}),T.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:T.skillDir})]})]}),T.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:T.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[K&&s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(K,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(L,{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:Z||""}),children:s.jsx(L,{name:"check",className:"h-4 w-4"})}):s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",disabled:!T.installable,onClick:()=>{A(T),I(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${T.sourceId}:${T.skillDir}`)})})]})]}),s.jsx(Dm,{open:x,onOpenChange:C}),s.jsx($m,{open:u,onOpenChange:I,item:F}),s.jsx(Vt,{open:w,onOpenChange:T=>{k||z(T)},children:s.jsxs(Bt,{className:"max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Qt,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(ds,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>z(!1),disabled:k,children:n("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",variant:"destructive",onClick:()=>{S()},disabled:k,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},su=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(tu,{mode:"external",onModeChange:lu,showModeTabs:!1}),t[0]=e):e=t[0],e},nu="SKILL.md",au="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",si=(t,e)=>{const a=Id({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),El=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=Ad(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/,"")}},ru=(t,e)=>{const a=El(t);return si(e,a.instructions)},ou=()=>{const{t}=rt(),{currentTheme:e}=ur(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skillDraft:h,setSkillDraft:d,setSelectedSkill:b}=Vs(Ms($=>({selectedSkillName:$.selectedSkillName,getSkillByName:$.getSkillByName,getSkillDetail:$.getSkillDetail,createSkill:$.createSkill,updateSkill:$.updateSkill,skillDraft:$.skillDraft,setSkillDraft:$.setSkillDraft,setSelectedSkill:$.setSelectedSkill}))),c=Us(),j=Vs($=>lr($,c)),m=a?n(a,c):null,E=!!(h&&h.name===a&&!m),v=!!(a&&!m&&!h),P=m?.path==="<built-in>";o.useEffect(()=>{v&&b(null)},[v,b]);const[x,C]=o.useState(""),[u,I]=o.useState("user"),[F,A]=o.useState("opencode"),[k,g]=o.useState(""),[w,z]=o.useState(""),[N,R]=o.useState(()=>si("","")),[y,O]=o.useState("edit"),[q,S]=o.useState([]),[G,J]=o.useState([]),[T,Q]=o.useState(!1),[Z,K]=o.useState(!1),[ae,_]=o.useState(""),[B,M]=o.useState(""),[U,Y]=o.useState(!1),[X,ne]=o.useState(""),[te,ge]=o.useState(""),[ee,le]=o.useState(null),[pe,ie]=o.useState(!1),[je,Se]=o.useState(""),[Ce,xe]=o.useState(null),[Re,Oe]=o.useState(!1),fe=E?x.trim()!==""||k.trim()!==""||w.trim()!==""||G.length>0:k!==ae||w!==B,be=ee?te!==je:X.trim()!=="",De=o.useCallback($=>{switch($){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($=>{switch($){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(E&&h){const de=h.description||"",ue=h.instructions||"";C(h.name||""),I(h.scope||"user"),A(h.source==="agents"?"agents":"opencode"),g(de),z(ue),R(si(de,ue)),_(""),M(""),S([]),J(h.pendingFiles||[])}else if(a&&m){K(!0);try{const de=await i(a,c);if(de){const ue=de.sources.md,ke=ue.description||"",oe=ue.instructions||"";g(ke),z(oe),R(si(ke,oe)),_(ke),M(oe),S(ue.supportingFiles||[])}}catch(de){console.error("Failed to load skill details:",de)}finally{K(!1)}}})()},[m,E,a,c,j,h,i]);const Le=ce($=>$.editorFontSize),qe=o.useMemo(()=>{const $=[Hr(e,{fontSize:Le})],de=kr(nu);return de&&$.push(de),$.push(qr.lineWrapping),$},[e,Le]),Ke=o.useMemo(()=>{const $=X.trim()||"supporting-file.md",de=lc($),ue=!!de&&de!=="markdown",ke=[Hr(e,ue?{syntaxColors:!1,fontSize:Le}:{fontSize:Le})],oe=kr($);return oe&&ke.push(oe),ue&&de&&ke.push(Ed({language:de,themeName:e.metadata.id,theme:Dd(e)})),ke.push(qr.lineWrapping),ke},[e,X,Le]),Xe=o.useCallback($=>{g($),R(de=>ru(de,$))},[]),We=o.useCallback($=>{R($);const de=El($);g(de.description??""),z(de.instructions)},[]),Ze=async()=>{const $=E?x.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!$){D.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test($)||$.length>64){D.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!k.trim()){D.error(t("settings.skills.page.toast.descriptionRequired"));return}if(E&&j.some(de=>de.name===$)){D.error(t("settings.skills.page.toast.skillExists"));return}Q(!0);try{const de={name:$,description:k.trim(),instructions:w.trim()||void 0,scope:E?u:void 0,source:E?F:void 0,targetPath:E?void 0:m?.path,supportingFiles:E&&G.length>0?G:void 0};let ue;if(E?(ue=await r(de,c),ue&&(d(null),J([]),b($))):(ue=await l($,de,c),ue&&(_(k.trim()),M(w.trim()))),ue){const ke=pn.getState().changes.some(oe=>oe.scope==="skills"&&oe.id.startsWith(`skills:${$}:`));D.success(t(ke?"settings.view.pendingRestart.saved":E?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else D.error(t(E?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(de){console.error("Error saving skill:",de),D.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{Q(!1)}},we=()=>{le(null),ne(""),ge(""),Se(""),Y(!0)},Je=async $=>{if(le($),ne($),E){const ue=G.find(ke=>ke.path===$)?.content||"";ge(ue),Se(ue),Y(!0);return}if(a){ie(!0),Y(!0);try{const{readSupportingFile:de}=Vs.getState(),ue=await de(a,$,c);ge(ue||""),Se(ue||"")}catch{D.error(t("settings.skills.page.toast.loadFileContentFailed")),ge(""),Se("")}finally{ie(!1)}}},Me=async()=>{if(!X.trim()){D.error(t("settings.skills.page.toast.fileNameRequired"));return}const $=X.trim(),de=ee!==null;if(E){if(de)J(oe=>oe.map(Ae=>Ae.path===ee?{path:$,content:te}:Ae)),D.success(t("settings.skills.page.toast.fileUpdated",{path:$}));else{if(G.some(oe=>oe.path===$)){D.error(t("settings.skills.page.toast.fileExists"));return}J(oe=>[...oe,{path:$,content:te}]),D.success(t("settings.skills.page.toast.fileAdded",{path:$}))}Y(!1),le(null);return}if(!a){D.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:ue}=Vs.getState();if(await ue(a,$,te,c)){D.success(de?t("settings.skills.page.toast.fileUpdated",{path:$}):t("settings.skills.page.toast.fileCreated",{path:$})),Y(!1),le(null);const oe=await i(a,c);oe&&S(oe.sources.md.supportingFiles||[])}else D.error(t(de?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},ve=$=>{if(E){J(de=>de.filter(ue=>ue.path!==$)),D.success(t("settings.skills.page.toast.fileRemoved",{path:$}));return}a&&xe($)},$e=async()=>{if(!Ce||!a)return;Oe(!0);const{deleteSupportingFile:$}=Vs.getState();if(await $(a,Ce,c)){D.success(t("settings.skills.page.toast.fileDeleted",{path:Ce}));const ue=await i(a,c);ue&&S(ue.sources.md.supportingFiles||[]),xe(null)}else D.error(t("settings.skills.page.toast.deleteFileFailed"));Oe(!1)};return!a&&!h||v?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(L,{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")})]})}):Z?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(cs,{title:E?t("settings.skills.page.title.newSkill"):a,description:m?t("settings.skills.page.subtitle.skillLocation",{location:De(Ma(m.scope,m.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(Ue,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[E&&s.jsxs(Yt,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(He,{value:x,onChange:$=>C($.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Lt,{value:Ma(u,F),onValueChange:$=>{const de=Al($);I(de.scope),A(de.source==="agents"?"agents":"opencode")},children:[s.jsxs(Ft,{size:qt,className:"w-fit gap-1.5",children:[u==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),F==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:De(Ma(u,F))})]}),s.jsx(Kt,{align:"start",children:hr.map($=>s.jsx(pt,{value:$.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[$.scope==="user"?s.jsx(L,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"folder",className:"h-3.5 w-3.5"}),$.source==="agents"?s.jsx(L,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:De($.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:_e($.value)})]})},$.value))})]})]}),s.jsx(Zt,{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:$=>Xe($.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:P})})]}),s.jsx(Ue,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(Td,{currentMode:y==="preview"?"preview":"edit",onToggle:()=>O($=>$==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:ye("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",au),children:y==="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(cc,{content:N,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(Gr,{value:N,onChange:We,readOnly:P,extensions:qe,className:"h-full",enableSearch:!0})})}),s.jsx(Ue,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(V,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:we,disabled:P,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const $=E?G:q;return $.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:$.map(de=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Je(de.path),children:[s.jsx(L,{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:de.path}),E&&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")}),!P&&s.jsx(V,{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:ue=>{ue.stopPropagation(),ve(de.path)},children:s.jsx(L,{name:"delete-bin",className:"h-3 w-3"})})]},de.path))})})()}),s.jsx(Ue,{children:s.jsx(V,{onClick:Ze,disabled:P||T||!fe,size:"xs",className:"!font-normal",children:t(T?"settings.common.actions.saving":E?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Vt,{open:Ce!==null,onOpenChange:$=>{!$&&!Re&&xe(null)},children:s.jsxs(Bt,{className:"max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Qt,{children:t("settings.skills.page.deleteFileDialog.description",{path:Ce??""})})]}),s.jsxs(ds,{children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>xe(null),disabled:Re,children:t("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",variant:"destructive",onClick:$e,disabled:Re,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Vt,{open:U,onOpenChange:$=>{Y($),$||le(null)},children:s.jsxs(Bt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Wt,{className:"flex-shrink-0",children:[s.jsx(Jt,{children:t(ee?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Qt,{children:t(ee?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),pe?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:Ot,children:t("settings.skills.page.fileDialog.field.filePath")}),!ee&&s.jsx(ts,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(He,{value:X,onChange:$=>ne($.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:ee!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Ot} 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(Gr,{value:te,onChange:ge,extensions:Ke,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(ds,{className:"mt-4",children:[s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>{Y(!1),le(null)},children:t("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",onClick:Me,disabled:pe||!be,children:t(ee?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},co=t=>{const e=mt.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(su,{}):s.jsx(ou,{}),e[0]=n,e[1]=i):i=e[1],i};function lu(){}const cu=t=>{const e=mt.c(38),{onItemSelect:a}=t,{t:n}=rt(),i=Qs(du),r=ce(pu),l=ce(mu),{currentTheme:h}=ur();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=xs(),e[0]=d):d=e[0];const b=d,c=uu;let j,m;e[1]!==i||e[2]!==r||e[3]!==l?(j=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(g=>g.id===r)||l(i[0].id)},m=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=j,e[5]=m):(j=e[4],m=e[5]),o.useEffect(j,m);let E;e[6]===Symbol.for("react.memo_cache_sentinel")?(E=ye("border-b px-3","pt-4 pb-3"),e[6]=E):E=e[6];let v;e[7]!==n?(v=n("settings.page.projects.title"),e[7]=n,e[8]=v):v=e[8];let P;e[9]!==v?(P=s.jsx("h2",{className:`${an} mb-3`,children:v}),e[9]=v,e[10]=P):P=e[10];let x;e[11]!==i.length||e[12]!==n?(x=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=x):x=e[13];let C;e[14]!==x?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:x}),e[14]=x,e[15]=C):C=e[15];let u;e[16]!==n?(u=!b&&s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:c,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(L,{name:"add",className:"size-4"})}),e[16]=n,e[17]=u):u=e[17];let I;e[18]!==C||e[19]!==u?(I=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[C,u]}),e[18]=C,e[19]=u,e[20]=I):I=e[20];let F;e[21]!==I||e[22]!==P?(F=s.jsxs("div",{className:E,children:[P,I]}),e[21]=I,e[22]=P,e[23]=F):F=e[23];let A;if(e[24]!==h||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let g;e[30]!==h||e[31]!==a||e[32]!==r||e[33]!==l?(g=w=>{const z=w.id===r,N=w.icon?pc[w.icon]:null,R=w.color?mc[w.color]??null:null,y=N?s.jsx(L,{name:N,className:ye("h-4 w-4",z?"text-foreground":"text-muted-foreground/70"),style:R?{color:R}:void 0}):s.jsx(L,{name:"folder",className:ye("h-4 w-4",z?"text-foreground":"text-muted-foreground/70"),style:R?{color:R}:void 0}),O=w.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:w.iconBackground?{backgroundColor:w.iconBackground}:void 0,children:s.jsx(uc,{project:w,options:{themeVariant:h.metadata.variant,iconColor:h.colors.surface.foreground},className:"h-full w-full object-contain",fallback:y})}):y;return s.jsx(tr,{title:w.label||w.path,icon:O,selected:z,onSelect:()=>{l(w.id),a?.()}},w.id)},e[30]=h,e[31]=a,e[32]=r,e[33]=l,e[34]=g):g=e[34],A=i.map(g),e[24]=h,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=A}else A=e[29];let k;return e[35]!==F||e[36]!==A?(k=s.jsx(Pl,{variant:"background",header:F,children:A}),e[35]=F,e[36]=A,e[37]=k):k=e[37],k};function du(t){return t.projects}function pu(t){return t.settingsProjectsSelectedId}function mu(t){return t.setSettingsProjectsSelectedId}function uu(){dc.requestDirectoryDialog()}const gu=()=>{const t=mt.c(30),{t:e}=rt(),a=Qs(hu),n=Qs(fu),i=ce(xu),r=ce(bu);let l;e:{if(!i){l=null;break e}let x;t[0]!==a||t[1]!==i?(x=a.find(C=>C.id===i)??null,t[0]=a,t[1]=i,t[2]=x):x=t[2],l=x}const h=l;let d,b;t[3]!==a||t[4]!==i||t[5]!==r?(d=()=>{if(a.length===0){r(null);return}i&&a.some(x=>x.id===i)||r(a[0].id)},b=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=d,t[7]=b):(d=t[6],b=t[7]),o.useEffect(d,b);let c;t[8]!==h||t[9]!==n?(c=async x=>{h&&n(h.id,{label:x.label,icon:x.icon,color:x.color,iconBackground:x.iconBackground,defaultModel:x.defaultModel??null,defaultVariant:x.defaultVariant??null})},t[8]=h,t[9]=n,t[10]=c):c=t[10];const j=c;if(!h){let x;t[11]!==e?(x=e("settings.page.projects.title"),t[11]=e,t[12]=x):x=t[12];let C;t[13]!==e?(C=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=C):C=t[14];let u;t[15]!==C?(u=s.jsx("p",{className:"typography-meta text-muted-foreground",children:C}),t[15]=C,t[16]=u):u=t[16];let I;return t[17]!==x||t[18]!==u?(I=s.jsx(cs,{title:x,showSaveStatus:!0,children:u}),t[17]=x,t[18]=u,t[19]=I):I=t[19],I}let m;t[20]!==h.label||t[21]!==e?(m=h.label??e("settings.projects.page.title.default"),t[20]=h.label,t[21]=e,t[22]=m):m=t[22];const E=m;let v;t[23]!==j||t[24]!==h?(v=s.jsx(jd,{project:h,onIdentitySave:j}),t[23]=j,t[24]=h,t[25]=v):v=t[25];let P;return t[26]!==E||t[27]!==h.path||t[28]!==v?(P=s.jsx(cs,{title:E,description:h.path,showSaveStatus:!0,outerClassName:"bg-background",children:v}),t[26]=E,t[27]=h.path,t[28]=v,t[29]=P):P=t[29],P};function hu(t){return t.projects}function fu(t){return t.updateProjectMeta}function xu(t){return t.settingsProjectsSelectedId}function bu(t){return t.setSettingsProjectsSelectedId}const ni=()=>Math.floor(2e4+Math.random()*3e4),vu=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")},yu=()=>{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"},po=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}},mo=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"}},ju=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),fr=t=>!!(t&&ju.has(t)),uo=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||fr(t)?"connecting":"idle",go=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"}},wu=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},ho={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},ku=t=>t==="noRuntime"?ho.noRuntime:t==="noOpencode"?ho.noOpencode:null,fo=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||fr(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Nu=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}`,Su=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:ni(),remoteHost:"127.0.0.1",remotePort:80}),Cu=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",$s=t=>{const e=mt.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(ts,{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 ${Ot}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},Pu=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"}},xo=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},Iu=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Au=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}`},nr=(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}),Eu=t=>t.trim().toLowerCase()==="authorization",Li=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!Eu(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},Tu=t=>Object.entries(t||{}).map(([e,a])=>nr(e,a)),Tl=()=>{if(typeof window>"u")return null;const e=Oa()||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}},bo=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},Du=async()=>{const t=ea(Oa())||window.location.origin;if(!hs()||!La())return t;let e;try{e=await dt("/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 ul(),i=Tl();return!n||!i?t:`http://${n}:${i}`},Ya=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Mu=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},Ru=()=>{const{t}=rt(),e=ce(f=>f.timeFormatPreference),{clientAuth:a}=ol(),n=hs(),i=Is(f=>f.instances),r=Is(f=>f.statusesById),l=Is(f=>f.importCandidates),h=Is(f=>f.isLoading),d=Is(f=>f.isImportsLoading),b=Is(f=>f.isSaving),c=Is(f=>f.error),j=Is(f=>f.load),m=Is(f=>f.loadImports),E=Is(f=>f.refreshStatuses),v=Is(f=>f.upsertInstance),P=Is(f=>f.createFromCommand),x=Is(f=>f.removeInstance),C=Is(f=>f.connect),u=Is(f=>f.disconnect),I=Is(f=>f.retry),F=ce(f=>f.settingsRemoteInstancesSelectedId),A=ce(f=>f.setSettingsRemoteInstancesSelectedId),k=o.useMemo(()=>F&&i.find(f=>f.id===F)||null,[i,F]),[g,w]=o.useState(null),[z,N]=o.useState(!1),[R,y]=o.useState(!1),[O,q]=o.useState(null),[S,G]=o.useState([]),[J,T]=o.useState(null),[Q,Z]=o.useState(""),[K,ae]=o.useState(!1),[_,B]=o.useState({}),[M,U]=o.useState(!1),[Y,X]=o.useState(!1),[ne,te]=o.useState(()=>Date.now()),[ge,ee]=o.useState([]),[le,pe]=o.useState({}),[ie,je]=o.useState("local"),[Se,Ce]=o.useState(!1),[xe,Re]=o.useState(!1),[Oe,fe]=o.useState(""),[be,De]=o.useState(""),[_e,Le]=o.useState(""),[qe,Ke]=o.useState([]),[Xe,We]=o.useState(""),[Ze,we]=o.useState(null),[Je,Me]=o.useState(!1),[ve,$e]=o.useState(!1),[$,de]=o.useState(null),[ue,ke]=o.useState(""),[oe,Ae]=o.useState(""),[H,ze]=o.useState(""),[tt,Fe]=o.useState([]),[at,wt]=o.useState([]),[bt,ut]=o.useState([]),[gt,Pt]=o.useState(!1),[jt,Et]=o.useState(""),[Ye,Ge]=o.useState(null),[ct,Ie]=o.useState(null),[It,Ne]=o.useState(null),[Ct,W]=o.useState(null),[me,Ee]=o.useState(!1),[Pe,lt]=o.useState(!1),[it,Ve]=o.useState("configure"),[Nt,is]=o.useState(!1),[es,ys]=o.useState("relay"),[Ht,rs]=o.useState(!0),[zt,fs]=o.useState(null),os=o.useMemo(()=>at.filter(f=>!!f.revokedAt).length,[at]),[ss,ns]=o.useState(!1),[js,re]=o.useState("saved"),[ot,vt]=o.useState(""),[Be,et]=o.useState(""),[ht,Tt]=o.useState(""),[Dt,Xt]=o.useState(!1);o.useEffect(()=>{j(),m()},[j,m]);const At=o.useCallback(async()=>{Ce(!0),we(null);try{const f=await Or();ee(f.hosts||[]),je(f.defaultHostId||"local")}catch(f){we(f instanceof Error?f.message:String(f))}finally{Ce(!1)}},[]);o.useEffect(()=>{At()},[At]);const St=o.useCallback(async(f,se=ie)=>{Re(!0),we(null);try{await Lr({hosts:f,defaultHostId:se,initialHostChoiceCompleted:!0}),ee(f),je(se)}catch(Te){we(Te instanceof Error?Te.message:String(Te))}finally{Re(!1)}},[ie]),Ut=o.useCallback(async()=>{const f=Fr(be);if(!f){we(t("desktopHostSwitcher.error.invalidUrl"));return}const se=f.persistedUrl,nt={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Oe.trim()||ya(se),url:se,apiUrl:se,..._e.trim()?{clientToken:_e.trim()}:{},...Li(qe)?{requestHeaders:Li(qe)}:{}};await St([nt,...ge],ie),fe(""),De(""),Le(""),Ke([]),Me(!1),f.redeemUrl&&Ya(f.redeemUrl)},[ie,qe,ge,Oe,_e,be,St,t]),Mt=o.useCallback(async()=>{const f=Jc(Xe);if(!f){we(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const se=await Qc().catch(()=>""),Te=JSON.stringify({pairingId:f.pairingId,secret:f.secret,clientLabel:f.label||"OpenChamber Desktop",clientKind:"desktop",deviceName:"OpenChamber Desktop",devicePlatform:yu(),...se?{dedupeKey:`desktop:${se}`}:{}}),nt={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Te},_t=async Rt=>{if(!Rt.ok)return null;const Ns=await Rt.json().catch(()=>null);return(typeof Ns?.clientToken=="string"?Ns.clientToken.trim():"")||null},Ts=[...f.candidates].sort((Rt,Ns)=>(Rt.type==="relay"?1:0)-(Ns.type==="relay"?1:0));let ks=null;for(const Rt of Ts){if(Rt.type==="relay"){const fa=Yc({relayUrl:Rt.relayUrl,serverId:Rt.serverId,hostEncPubJwk:Rt.hostEncPubJwk,...Rt.grant?{grant:Rt.grant}:{}});try{const Va=await fa.fetch("/api/client-auth/pairing/redeem",nt),jr=await _t(Va);if(jr){ks={kind:"relay",relay:{relayUrl:Rt.relayUrl,serverId:Rt.serverId,hostEncPubJwk:Rt.hostEncPubJwk},token:jr};break}}catch{}finally{fa.close()}continue}const Ns=ea(Rt.url);if(Ns)try{const fa=await fetch(`${Ns}/api/client-auth/pairing/redeem`,nt),Va=await _t(fa);if(Va){ks={kind:"direct",url:Ns,token:Va};break}}catch{}}if(!ks){we(t("desktopHostSwitcher.error.invalidUrl"));return}const zs=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,bs=f.candidates.find(Rt=>Rt.type==="relay"),_s=ks.kind==="relay"?ks.relay:bs?{relayUrl:bs.relayUrl,serverId:bs.serverId,hostEncPubJwk:bs.hostEncPubJwk}:void 0,p=f.candidates.filter(Rt=>Rt.type!=="relay").map(Rt=>ea(Rt.url)).find(Rt=>!!Rt),ft=ks.kind==="direct"?ks.url:p,{token:us}=ks,yt=ft||(_s?Zc(_s.serverId):null);if(!yt){we(t("desktopHostSwitcher.error.invalidUrl"));return}const Gt={url:yt,apiUrl:ft||void 0,clientToken:us,..._s?{relay:_s}:{}},Fs=ge.find(Rt=>_s?Rt.relay?.serverId===_s.serverId:!Rt.relay&&ea(Rt.apiUrl||Rt.url)===yt);if(Fs){const Rt=ge.map(Ns=>Ns.id===Fs.id?{...Ns,label:f.label||Ns.label,...Gt}:Ns);await St(Rt,ie)}else await St([{id:zs(),label:f.label||ya(yt),...Gt},...ge],ie);We(""),we(null),$e(!1)},[Xe,ie,ge,St,t]),ps=o.useCallback(async f=>{const se=ge.filter(nt=>nt.id!==f);await St(se,ie===f?"local":ie),$===f&&de(null)},[ie,$,ge,St]),Es=o.useCallback(f=>{de(f.id),ke(f.label),Ae(f.apiUrl||f.url),ze(f.clientToken||""),Fe(Tu(f.requestHeaders)),we(null)},[]),di=o.useCallback(async()=>{if(!$)return;const f=Fr(oe);if(!f){we(t("desktopHostSwitcher.error.invalidUrl"));return}const se=f.persistedUrl,Te=ge.map(nt=>nt.id===$?{...nt,label:ue.trim()||ya(se),url:se,apiUrl:se,clientToken:H.trim()||void 0,requestHeaders:Li(tt)}:nt);await St(Te,ie),de(null),f.redeemUrl&&Ya(f.redeemUrl)},[ie,tt,ue,H,oe,$,ge,St,t]),pi=o.useCallback(async()=>{const f=Be.trim();if(!f){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const se=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await P(se,f,ht.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),A(se),ns(!1),et(""),Tt(""),D.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Te){D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Te instanceof Error?Te.message:String(Te)})}},[P,A,Be,ht,t]),mi=o.useCallback(()=>{vt(""),re(l.length>0?"saved":"manual"),ns(!0)},[l.length]),ui=o.useCallback(async f=>{await St(ge,f)},[ge,St]);o.useEffect(()=>{if(!n||ge.length===0)return;let f=!1;return Promise.all(ge.map(async se=>{const Te=()=>ad(se.relay,{clientToken:se.clientToken||null,requestHeaders:se.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(se.relay&&!se.apiUrl)return[se.id,await Te()];const nt=ea(Xc(se));if(!nt)return[se.id,se.relay?await Te():{status:"unreachable",latencyMs:0}];const _t=await ed(nt,{clientToken:se.clientToken||null,requestHeaders:se.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(_t.status==="unreachable"&&se.relay){const Ts=await Te();if(Ts.status==="ok")return[se.id,Ts]}return[se.id,_t]})).then(se=>{f||pe(Object.fromEntries(se))}),()=>{f=!0}},[ge,n]);const Os=o.useCallback(async f=>{if(a){f?.silent||Pt(!0),f?.silent||Ge(null);try{const[se,Te]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);wt(se),Te&&ut(Te)}catch(se){f?.silent||Ge(se instanceof Error?se.message:String(se))}finally{f?.silent||Pt(!1)}}},[a]),la=o.useRef(!1);o.useEffect(()=>{if(!(!Pe||it!=="result"||!It)){if(bt.some(f=>f.id===It)){la.current=!0;return}la.current&&(Ne(null),lt(!1),at.some(f=>f.pairingId===It)&&D.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Pe,it,It,bt,at,t]);const gi=o.useCallback(async f=>{if(a)try{await a.cancelPairing(f),ut(se=>se.filter(Te=>Te.id!==f)),await Os({silent:!0})}catch(se){Ge(se instanceof Error?se.message:String(se))}},[a,Os]);o.useEffect(()=>{if(!a)return;Os();const f=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Os({silent:!0})},5e3);return()=>window.clearInterval(f)},[a,Os]);const Ka=o.useCallback(async()=>{if(a?.getPairingTransports)try{const nt=await a.getPairingTransports();return{localUrl:nt.local,lanUrl:nt.lan,relayAvailable:nt.relayAvailable}}catch{}const f=Tl(),se=f?`http://127.0.0.1:${f}`:bo(window.location.origin)?window.location.origin:null;let Te=null;try{const nt=ea(await Du());Te=nt&&!bo(nt)?nt:null}catch{}return{localUrl:se,lanUrl:Te,relayAvailable:!0}},[a]),hi=o.useCallback(async()=>{Ge(null),Ie(null),W(null),Ee(!1),Ne(null),Ve("configure"),rs(!0),lt(!0);const f=await Ka();fs(f),ys(f.relayAvailable?"relay":f.lanUrl?"lan":"local")},[Ka]),fi=o.useCallback(async()=>{if(!(!a?.createPairingSession||!zt)){Ge(null),is(!0);try{const f=jt.trim()||void 0;let se,Te,nt=!0;es==="local"?(se=zt.localUrl??void 0,Te=!1):es==="lan"?(se=zt.lanUrl??void 0,Te=Ht):Ht&&zt.lanUrl?(se=zt.lanUrl,Te=!0):(nt=!1,Te=!0);const{pairing:_t,server:Ts}=await a.createPairingSession({label:f,allowedClientKinds:["mobile","desktop"],serverUrl:se,includeRelay:Te,includeDirect:nt}),ks=td({pairingId:_t.id,secret:_t.secret,label:Ts.label,fingerprint:_t.fingerprint??void 0,expiresAt:_t.expiresAt,candidates:Ts.candidates}),zs=sd(ks);Ie(zs),W(await yl.toDataURL(zs,{width:1024,margin:2,errorCorrectionLevel:"L"})),Ee(!1),la.current=!1,Ne(_t.id),Ve("result"),await Os({silent:!0})}catch(f){Ge(f instanceof Error?f.message:String(f))}finally{is(!1)}}},[a,zt,es,Ht,jt,Os]),xi=o.useCallback(()=>{ct&&Ta(ct).then(f=>{f.ok&&(Ee(!0),window.setTimeout(()=>Ee(!1),2e3))})},[ct]),bi=o.useCallback(async f=>{if(!a)return;const se=f.clientKind==="desktop-local";Ge(null);try{if(await a.revokeClient(f.id),se&&hs()){const Te=await Or();await Lr({hosts:Te.hosts,defaultHostId:Te.defaultHostId,initialHostChoiceCompleted:Te.initialHostChoiceCompleted,localClientToken:null}),wt(nt=>nt.map(_t=>_t.id===f.id?{..._t,revokedAt:new Date().toISOString()}:_t)),nd({apiBaseUrl:Oa(),clientToken:null,runtimeKey:"local"});return}await Os()}catch(Te){Ge(Te instanceof Error?Te.message:String(Te))}},[a,Os]),vi=o.useCallback(async()=>{if(a){Ge(null);try{await a.purgeRevokedClients(),await Os()}catch(f){Ge(f instanceof Error?f.message:String(f))}}},[a,Os]);o.useEffect(()=>{w(k)},[k]),o.useEffect(()=>{Xt(!1)},[F]),o.useEffect(()=>{if(!F)return;const f=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||E()},2e3);return()=>{window.clearInterval(f)}},[E,F]),o.useEffect(()=>{let f=null,se=Date.now();const Te=()=>{const _t=Date.now();_t-se>=1e3&&(te(_t),se=_t),f=requestAnimationFrame(Te)};(typeof document>"u"||document.visibilityState==="visible")&&(f=requestAnimationFrame(Te));const nt=()=>{document.visibilityState==="visible"&&f===null?f=requestAnimationFrame(Te):document.visibilityState!=="visible"&&f!==null&&(cancelAnimationFrame(f),f=null)};return document.addEventListener("visibilitychange",nt),()=>{document.removeEventListener("visibilitychange",nt),f!==null&&cancelAnimationFrame(f)}},[]);const ws=F?r[F]:null,Gs=ws?.phase,Qn=Gs==="ready",rn=Gs==="degraded",mn=fr(Gs),Ls=Qn||(mn||rn),da=ws?Math.max(0,ne-ws.updatedAtMs):0,un=rn&&da>12e3,on=uo(Gs),he=on==="error"?wu(ws?.detail):null,as=ku(he),Ua=o.useMemo(()=>!g||!k?!1:JSON.stringify(g)!==JSON.stringify(k),[g,k]),ms=o.useCallback(f=>{w(se=>se&&f(se))},[]),za=o.useCallback(async()=>{if(!g)return;const f=Mu(g);if(!f.sshCommand.trim()){D.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(f.remoteOpenchamber.mode==="external"&&!f.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Xt(!0);return}if(f.remoteOpenchamber.mode==="managed"&&f.remoteOpenchamber.bindHost==="0.0.0.0"&&!f.auth.openchamberPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Xt(!0),window.setTimeout(()=>Rn.current?.focus(),0);return}if(!(f.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(f.auth.sshPassword?.enabled&&f.auth.sshPassword.value?.trim()&&f.auth.sshPassword.store!=="settings"){const se=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));f.auth.sshPassword.store=se?"settings":"never",se||(f.auth.sshPassword.value=void 0)}if(f.auth.openchamberPassword?.enabled&&f.auth.openchamberPassword.value?.trim()&&f.auth.openchamberPassword.store!=="settings"){const se=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));f.auth.openchamberPassword.store=se?"settings":"never",se||(f.auth.openchamberPassword.value=void 0)}try{await v(f),D.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(se){D.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:se instanceof Error?se.message:String(se)})}}},[g,t,v]),Tn=o.useCallback(async(f,se)=>{const Te=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await P(Te,`ssh ${se}`,f),A(Te),D.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(nt){return D.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:nt instanceof Error?nt.message:String(nt)}),!1}},[P,A,t]),Dn=o.useCallback(()=>{K||(T(null),Z(""))},[K]),_a=o.useCallback((f,se)=>{if(ns(!1),se){T(f),Z(Cu(f));return}Tn(f,f)},[Tn]),pa=o.useMemo(()=>{const f=ot.trim().toLowerCase();return f?l.filter(se=>se.host.toLowerCase().includes(f)||se.sshCommand.toLowerCase().includes(f)):l},[l,ot]),yi=o.useCallback(f=>{const se=(f||"").trim();if(!se){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Ya(se)},[t]),Mn=o.useCallback(async()=>{const f=J,se=Q.trim();if(f){if(!se){D.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}ae(!0);try{await Tn(f,se)&&(T(null),Z(""))}finally{ae(!1)}}},[Tn,Q,J,t]),gn=o.useCallback(async()=>{if(k)try{await C(k.id);return}catch(f){if(!vu(f)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw f;const Te={...k,localForward:{...k.localForward,preferredLocalPort:ni()}};await v(Te),await C(Te.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[C,k,t,v]),Rn=o.useRef(null),$a=o.useRef(null),Yn=o.useCallback(async f=>{if(k){if(f==="localPort"){const se={...k,localForward:{...k.localForward,preferredLocalPort:ni()}};try{await v(se),await C(se.id),D.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Te){D.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Te instanceof Error?Te.message:String(Te)})}return}Xt(!0),window.setTimeout(()=>{if(f==="uiPassword"){Rn.current?.focus();return}$a.current?.scrollIntoView({block:"center"})},0)}},[C,k,t,v]),qs=o.useCallback(async f=>(await gc(f,600)).map(Te=>Au(Te)),[]),hn=o.useCallback(async()=>{if(g){N(!0),y(!0),q(null);try{const f=await qs(g.id);G(f)}catch(f){G([]),q(f instanceof Error?f.message:String(f))}finally{y(!1)}}},[g,qs]);o.useEffect(()=>{if(!z||!g)return;let f=!1;const se=async()=>{try{const nt=await qs(g.id);f||(G(nt),q(null))}catch(nt){f||q(nt instanceof Error?nt.message:String(nt))}};se();const Te=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||se()},1e3);return()=>{f=!0,window.clearInterval(Te)}},[g,z,qs]);const Ws=o.useMemo(()=>S.join(`
27
+ `),[S]),Zn=o.useCallback(()=>{if(!Ws.trim()){D.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Ta(Ws).then(f=>{f.ok&&D.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Ws,t]),ma=o.useCallback(async()=>{if(g)try{await hc(g.id),G([]),D.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(f){D.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:f instanceof Error?f.message:String(f)})}},[g,t]),ua=o.useCallback(async()=>{if(!ws?.localUrl){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const f=ws.localUrl.trim();if(!f){D.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Ya(f)},[ws?.localUrl,t]),ji=o.useCallback(()=>{if(!g)return;if(!Ls&&g.remoteOpenchamber.mode==="external"&&!g.remoteOpenchamber.preferredPort){D.error(t("settings.remoteInstances.page.validation.externalPortRequired")),Xt(!0);return}if(!Ls&&g.remoteOpenchamber.mode==="managed"&&g.remoteOpenchamber.bindHost==="0.0.0.0"&&!g.auth.openchamberPassword?.value?.trim()){D.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),Xt(!0),window.setTimeout(()=>Rn.current?.focus(),0);return}U(!0),(Ls?u(g.id):gn()).catch(se=>{const Te=Ls?Qn?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";D.error(t(Te),{description:se instanceof Error?se.message:String(se)})}).finally(()=>{U(!1)})},[Ls,gn,u,g,Qn,t]),wi=o.useCallback(()=>{if(!g||mn)return;X(!0),(rn?u(g.id).then(()=>gn()):I(g.id)).catch(se=>{D.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:se instanceof Error?se.message:String(se)})}).finally(()=>{X(!1)})},[gn,u,g,mn,rn,I,t]),ki=t(mn?"settings.remoteInstances.page.actions.connecting":rn?un?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Ni=!M&&!Y&&(Gs==="error"||Gs==="idle"||!Gs||rn&&un)&&!mn,Si=t(Qn?"settings.remoteInstances.sidebar.actions.disconnect":Ls?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!g)return s.jsxs(cs,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(Ue,{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(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{hi()},children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[os>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{vi()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,gt&&at.length===0&&bt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):at.length===0&&bt.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[bt.map(f=>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:f.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),f.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(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{gi(f.id)},children:t("settings.common.actions.cancel")})]},`pending-${f.id}`)),at.map(f=>{const se=f.clientKind==="desktop-local",Te=f.lastUsedAt?Date.parse(f.lastUsedAt):Number.NaN,nt=!f.revokedAt&&(se||Number.isFinite(Te)&&Date.now()-Te<9e4),_t=f.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):nt?f.lastTransport==="relay"&&!se?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Te)?t("settings.remoteInstances.clientAuth.lastUsed",{date:fc(Te,e,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}):t("settings.remoteInstances.clientAuth.neverUsed");return s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsx("div",{className:"min-w-0",children:s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",f.revokedAt?"bg-muted-foreground/20":nt?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:f.label}),po(f.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:po(f.devicePlatform)}):null,se?s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:t("settings.remoteInstances.clientAuth.state.thisDevice")}):null,s.jsx("span",{className:ye("typography-micro truncate",nt&&!f.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:_t})]})}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{bi(f)},disabled:!!f.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},f.id)})]})]}),Ye?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ye}):null]}):null,n?s.jsxs(Ue,{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(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>$e(!0),disabled:xe,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Me(!0),disabled:xe,children:[s.jsx(L,{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:Se?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):ge.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):ge.map(f=>{const se=le[f.id],Te=se?se.status==="ok"?"desktopHostSwitcher.status.connected":se.status==="auth"?"desktopHostSwitcher.status.authRequired":se.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":se.status==="incompatible"?"desktopHostSwitcher.status.incompatible":se.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",nt=se?.status==="ok";return s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye("h-2 w-2 shrink-0 rounded-full",se?nt?"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:ya(f.label)}),ie===f.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:ye("typography-micro shrink-0",nt?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Te),nt&&typeof se?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(se.latencyMs))}):""]})]}),s.jsx("p",{className:ye("typography-micro text-muted-foreground truncate",f.apiUrl&&"font-mono"),children:f.relay&&!f.apiUrl?t("mobile.connect.relay.badge"):ya(f.apiUrl||f.url)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ui(f.id)},disabled:xe||ie===f.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:ie===f.id?s.jsx(L,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"star",className:"h-3.5 w-3.5"})}),f.relay&&!f.apiUrl?null:s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Es(f),disabled:xe,children:[s.jsx(L,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ps(f.id)},disabled:xe,children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},f.id)})}),Ze?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ze}):null]}):null,n?s.jsx(Vt,{open:Je,onOpenChange:Me,children:s.jsxs(Bt,{className:"sm:max-w-lg",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx(Qt,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Ut()},children:[s.jsx(He,{className:"h-8",value:Oe,onChange:f=>fe(f.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:xe}),s.jsx(He,{className:"h-8",value:be,onChange:f=>De(f.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:xe,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(He,{className:"h-8",value:_e,onChange:f=>Le(f.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:xe}),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(Xs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(ts,{children:t("settings.remoteInstances.direct.headers.description")})]}),qe.map(f=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:f.name,onChange:se=>Ke(Te=>Te.map(nt=>nt.id===f.id?{...nt,name:se.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:xe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:f.value,onChange:se=>Ke(Te=>Te.map(nt=>nt.id===f.id?{...nt,value:se.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:xe}),s.jsx("button",{type:"button",onClick:()=>Ke(se=>se.filter(Te=>Te.id!==f.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:xe,children:s.jsx(L,{name:"close",className:"h-4 w-4"})})]},f.id)),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Ke(f=>[...f,nr()]),disabled:xe,children:[s.jsx(L,{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(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Me(!1),disabled:xe,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:xe||!be.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Vt,{open:!!$,onOpenChange:f=>{f||de(null)},children:s.jsxs(Bt,{className:"sm:max-w-lg",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx(Qt,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),di()},children:[s.jsx(He,{className:"h-8",value:ue,onChange:f=>ke(f.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:xe}),s.jsx(He,{className:"h-8",value:oe,onChange:f=>Ae(f.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:xe,autoFocus:!0}),s.jsx(He,{className:"h-8",value:H,onChange:f=>ze(f.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:xe}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Xs,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(ts,{children:t("settings.remoteInstances.direct.headers.description")})]}),tt.map(f=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(He,{className:"h-8 font-mono text-xs",value:f.name,onChange:se=>Fe(Te=>Te.map(nt=>nt.id===f.id?{...nt,name:se.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:xe}),s.jsx(He,{className:"h-8 font-mono text-xs",value:f.value,onChange:se=>Fe(Te=>Te.map(nt=>nt.id===f.id?{...nt,value:se.target.value}:nt)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:xe}),s.jsx("button",{type:"button",onClick:()=>Fe(se=>se.filter(Te=>Te.id!==f.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:xe,children:s.jsx(L,{name:"close",className:"h-4 w-4"})})]},f.id)),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Fe(f=>[...f,nr()]),disabled:xe,children:[s.jsx(L,{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(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>de(null),disabled:xe,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:xe,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Vt,{open:ve,onOpenChange:$e,children:s.jsxs(Bt,{className:"sm:max-w-lg",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx(Qt,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Mt()},children:[s.jsx(He,{className:"h-8",value:Xe,onChange:f=>We(f.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:xe,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>$e(!1),disabled:xe,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:xe||!Xe.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Vt,{open:Pe,onOpenChange:lt,children:s.jsxs(Bt,{className:it==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t(it==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx(Qt,{children:t(it==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),it==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:f=>{f.preventDefault(),fi()},children:[s.jsx(He,{className:"h-8",value:jt,onChange:f=>Et(f.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:!!zt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!zt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!zt?.localUrl}].map(f=>{const se=es===f.key;return s.jsxs("div",{className:ye("flex items-start gap-2 py-0.5",f.available?"cursor-pointer":"opacity-45"),onClick:()=>{f.available&&ys(f.key)},role:"presentation",children:[s.jsx(cr,{checked:se,disabled:!f.available,onChange:()=>ys(f.key),ariaLabel:f.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:ye("typography-ui-label font-normal",se?"text-foreground":"text-foreground/70"),children:f.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:f.hint})]})]},f.key)})}),es==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Qi,{checked:Ht,onChange:rs,ariaLabel:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.addDevice.fallback.relay")})]}):null,es==="relay"&&zt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Qi,{checked:Ht,onChange:rs,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]}),Ye?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ye}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>lt(!1),disabled:Nt,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:Nt||!zt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[Ct?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:Ct,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,ct?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:ct}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:xi,children:[s.jsx(L,{name:me?"check":"file-copy",className:ye("h-3.5 w-3.5",me&&"text-[var(--status-success)]")}),t(me?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>lt(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(Ue,{title:t("settings.remoteInstances.sidebar.title"),description:t("settings.remoteInstances.sidebar.total",{count:i.length}),headerAction:s.jsxs(V,{type:"button",size:"xs",className:"!font-normal",onClick:mi,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:h?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(f=>{const se=r[f.id],Te=f.nickname?.trim()||f.sshParsed?.destination||f.id,nt=se?.phase,_t=nt==="ready",Ts=uo(nt),ks=Ts==="error"?se?.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 ${fo(nt)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Te})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(go(Ts)),Ts==="connecting"?` · ${t(mo(nt))}`:"",_t&&se?.localUrl?` · ${se.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[_t?s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>yi(se?.localUrl),children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]}):null,s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{(_t?u(f.id):C(f.id)).catch(bs=>D.error(t(_t?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:bs instanceof Error?bs.message:String(bs)}))},children:[_t?s.jsx(L,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"plug-2",className:"h-3.5 w-3.5"}),t(_t?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>A(f.id),children:[s.jsx(L,{name:"pencil",className:"h-3.5 w-3.5"}),t("desktopHostSwitcher.actions.edit")]}),s.jsxs(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&x(f.id).catch(bs=>D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:bs instanceof Error?bs.message:String(bs)}))},children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),ks?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:ks}):null]},f.id)})}):null,n?s.jsx(Vt,{open:ss,onOpenChange:ns,children:s.jsxs(Bt,{className:"sm:max-w-lg",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx(Qt,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(Bs,{value:js,onChange:re,"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")}]}),js==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(He,{className:"h-8",value:ot,onChange:f=>vt(f.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),d?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")}):pa.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:pa.map(f=>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:[f.host,f.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:f.sshCommand})]}),s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_a(f.host,f.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${f.source}:${f.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),pi()},children:[s.jsx(He,{className:"h-8",value:ht,onChange:f=>Tt(f.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:b}),s.jsx(He,{className:"h-8",value:Be,onChange:f=>et(f.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:b,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ns(!1),disabled:b,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:b||!Be.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Vt,{open:!!J,onOpenChange:f=>{f||Dn()},children:s.jsxs(Bt,{className:"sm:max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Qt,{children:J?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:J}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Mn()},children:[s.jsx(He,{value:Q,onChange:f=>Z(f.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(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Dn,disabled:K,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:K,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const On=g.remoteOpenchamber.mode==="managed",fn=On&&g.remoteOpenchamber.bindHost==="0.0.0.0",ga=fn&&!g.auth.openchamberPassword?.value?.trim(),ha=g.nickname?.trim()||g.sshParsed?.destination||g.id;return s.jsx(Vt,{open:!!g,onOpenChange:f=>{f||A(null)},children:s.jsxs(Bt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Ji} truncate`,children:ha}),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 ${fo(Gs)}`}),s.jsx("span",{className:"text-foreground",children:t(go(on))}),on==="connecting"?s.jsx("span",{children:t(mo(Gs))}):null,ws?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:ws.localUrl}):null,un?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(Ue,{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(V,{type:"button",variant:Ls?"outline":"default",size:"xs",className:"!font-normal",onClick:ji,disabled:M||Y,children:[Ls?s.jsx(L,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"plug-2",className:"h-3.5 w-3.5"}),Si]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:wi,disabled:!Ni,children:[s.jsx(L,{name:"refresh",className:`h-3.5 w-3.5 ${mn||rn&&!un?"animate-spin":""}`}),ki]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{hn()},children:[s.jsx(L,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(V,{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"))&&x(g.id).then(()=>{A(null),D.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(se=>{D.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:se instanceof Error?se.message:String(se)})})},children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),on==="error"&&ws?.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:ws.detail}),as?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(as)}):null,he&&!as?s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Yn(he)},children:t(he==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":he==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,ws?.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:ws.localUrl})]}):null]}),s.jsxs(Ue,{title:t("settings.remoteInstances.page.section.instance"),info:t("settings.remoteInstances.page.section.instanceDescription"),contentClassName:"space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(He,{className:"h-7 md:max-w-xl",value:g.sshCommand,onChange:f=>ms(se=>({...se,sshCommand:f.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(He,{className:"h-7 md:max-w-sm",value:g.nickname||"",onChange:f=>ms(se=>({...se,nickname:f.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(Lt,{value:g.remoteOpenchamber.mode,onValueChange:f=>ms(se=>({...se,remoteOpenchamber:{...se.remoteOpenchamber,mode:f==="external"?"external":"managed"}})),children:[s.jsx(Ft,{size:qt,className:"w-fit min-w-[140px]",children:s.jsx($t,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(Kt,{children:[s.jsx(pt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(pt,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(Gn,{open:Dt,onOpenChange:Xt,children:[s.jsxs(qn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:ll,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(L,{name:Dt?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(Wn,{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(Ps,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:g.connectionTimeoutSec,onValueChange:f=>{ms(se=>({...se,connectionTimeoutSec:Number.isFinite(f)?f:se.connectionTimeoutSec}))}})]}),s.jsxs(Ue,{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:$a,children:s.jsx($s,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(Ps,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:g.remoteOpenchamber.preferredPort,onValueChange:f=>{ms(se=>({...se,remoteOpenchamber:{...se.remoteOpenchamber,preferredPort:Number.isFinite(f)&&f>0?f:void 0}}))},onClear:()=>{ms(f=>({...f,remoteOpenchamber:{...f.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),On?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(Lt,{value:g.remoteOpenchamber.installMethod,onValueChange:f=>ms(se=>({...se,remoteOpenchamber:{...se.remoteOpenchamber,installMethod:f==="npm"||f==="bun"?f:"auto"}})),children:[s.jsx(Ft,{size:qt,className:"w-fit min-w-[140px]",children:s.jsx($t,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(Kt,{children:[s.jsx(pt,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(pt,{value:"bun",children:"bun"}),s.jsx(pt,{value:"npm",children:"npm"})]})]})]}):null,On?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(Ci,{checked:fn,onCheckedChange:f=>ms(se=>({...se,remoteOpenchamber:{...se.remoteOpenchamber,bindHost:f?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),fn?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,On?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(Ci,{checked:g.remoteOpenchamber.keepRunning,onCheckedChange:f=>ms(se=>({...se,remoteOpenchamber:{...se.remoteOpenchamber,keepRunning:f}}))})})]}):null]}),s.jsxs(Ue,{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(Lt,{value:g.localForward.bindHost,onValueChange:f=>{f==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ms(se=>({...se,localForward:{...se.localForward,bindHost:f==="localhost"||f==="0.0.0.0"?f:"127.0.0.1"}}))},children:[s.jsx(Ft,{size:qt,className:"w-fit min-w-[240px]",children:s.jsx($t,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(Kt,{children:[s.jsx(pt,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(pt,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(pt,{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(Ps,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:g.localForward.preferredLocalPort,onValueChange:f=>{ms(se=>({...se,localForward:{...se.localForward,preferredLocalPort:Number.isFinite(f)&&f>0?f:void 0}}))},onClear:()=>{ms(f=>({...f,localForward:{...f.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ms(f=>({...f,localForward:{...f.localForward,preferredLocalPort:ni()}})),children:s.jsx(L,{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:`${g.localForward.bindHost}:${g.localForward.preferredLocalPort||"auto"} → ${g.sshParsed?.destination||g.nickname||"remote"}:${g.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(Ue,{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(He,{className:"h-7 md:max-w-sm",type:"password",value:g.auth.sshPassword?.value||"",onChange:f=>ms(se=>({...se,auth:{...se.auth,sshPassword:{enabled:f.target.value.trim().length>0,value:f.target.value,store:se.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx($s,{label:t(fn?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(On?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(He,{className:ye("h-7 md:max-w-sm",ga&&"border-[var(--status-error)]"),type:"password",ref:Rn,"aria-invalid":ga,value:g.auth.openchamberPassword?.value||"",onChange:f=>ms(se=>({...se,auth:{...se.auth,openchamberPassword:{enabled:f.target.value.trim().length>0,value:f.target.value,store:se.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),ga?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(Ue,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[g.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,g.portForwards.map((f,se)=>{const Te=yt=>{ms(Gt=>({...Gt,portForwards:Gt.portForwards.map((Fs,Rt)=>Rt===se?yt(Fs):Fs)}))},nt=f.type==="remote"?"Local target":"Local listen",_t=f.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.",Ts=f.type==="remote"?"Remote listen":"Remote target",ks=f.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",zs=xo(f.localHost||"localhost",f.localPort),bs=xo(f.remoteHost||"localhost",f.remotePort),_s=f.type==="local"&&typeof f.localPort=="number"&&f.localPort>0,p=_s?`http://${Iu(f.localHost)}:${f.localPort}`:"",ft=!!_[f.id],us=f.type==="local"?t("settings.remoteInstances.page.forwardType.local"):f.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(Gn,{open:ft,onOpenChange:yt=>{B(Gt=>({...Gt,[f.id]:yt}))},className:`${se>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(qn,{className:"flex items-center gap-2 group",children:[s.jsx(L,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${ft?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Nu(f)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:us})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ci,{checked:f.enabled,onCheckedChange:yt=>Te(Gt=>({...Gt,enabled:yt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ms(yt=>({...yt,portForwards:yt.portForwards.filter(Gt=>Gt.id!==f.id)})),children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Wn,{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(Pu(f.type))})]})})}),s.jsxs(Lt,{value:f.type,onValueChange:yt=>Te(Gt=>({...Gt,type:yt==="dynamic"||yt==="remote"?yt:"local"})),children:[s.jsx(Ft,{size:qt,className:"w-fit min-w-[140px]",children:s.jsx($t,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(Kt,{children:[s.jsx(pt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(pt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(pt,{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:nt,hint:_t})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:f.localHost||"127.0.0.1",onChange:yt=>Te(Gt=>({...Gt,localHost:yt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Ps,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:f.localPort,onValueChange:yt=>{Te(Gt=>({...Gt,localPort:Number.isFinite(yt)&&yt>0?yt:void 0}))},onClear:()=>{Te(yt=>({...yt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),f.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:Ts,hint:ks})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(He,{className:"h-7 w-32",value:f.remoteHost||"",onChange:yt=>Te(Gt=>({...Gt,remoteHost:yt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Ps,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:f.remotePort,onValueChange:yt=>{Te(Gt=>({...Gt,remotePort:Number.isFinite(yt)&&yt>0?yt:void 0}))},onClear:()=>{Te(yt=>({...yt,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:f.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:zs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):f.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:bs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(L,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(L,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:zs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:zs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(L,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(L,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:bs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),_s?s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{En(p).then(yt=>{yt||D.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},f.id)}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const f=Su();ms(se=>({...se,portForwards:[...se.portForwards,f]})),B(se=>({...se,[f.id]:!0}))},children:[s.jsx(L,{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(V,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{za()},disabled:!Ua||b,children:t("settings.common.actions.saveChanges")}),ws?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ta(ws.localUrl||"").then(f=>{f.ok&&D.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(L,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ua()},children:[s.jsx(L,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,c?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:c}):null]})}),s.jsx(Vt,{open:z,onOpenChange:N,children:s.jsxs(Bt,{className:"sm:max-w-2xl",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Qt,{children:g?.nickname?.trim()||g?.sshParsed?.destination||g?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Zn,disabled:R||!Ws.trim(),children:[s.jsx(L,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ma()},disabled:R,children:[s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),R?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):O?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:O}):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:S.length>0?S.join(`
28
+ `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Vt,{open:!!J,onOpenChange:f=>{f||Dn()},children:s.jsxs(Bt,{className:"sm:max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Qt,{children:J?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:J}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:f=>{f.preventDefault(),Mn()},children:[s.jsx(He,{value:Q,onChange:f=>Z(f.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(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Dn,disabled:K,children:t("settings.common.actions.cancel")}),s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:K,children:t("settings.common.actions.create")})]})]})]})})]})})},Ou="__add_provider__",Lu=()=>{const t=dn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},Fu=({onItemSelect:t})=>{const{t:e}=rt(),a=Us(),n=st(v=>cl(v,a)),i=st(v=>v.selectedProviderId),r=st(v=>v.setSelectedProvider),l=Qs(v=>v.activeProjectId),[h,d]=o.useState({}),b=o.useMemo(()=>a||Lu(),[l,a]),c=st(v=>v.loadProviders);o.useEffect(()=>{a&&c({directory:a,source:"settings:providers"})},[c,a]),o.useEffect(()=>{if(n.length===0){d({});return}let v=!1;return(async()=>{const x=n.map(async C=>{try{const u=b?`?directory=${encodeURIComponent(b)}`:"",I=await dt(`/api/provider/${encodeURIComponent(C.id)}/source${u}`,{method:"GET",headers:{Accept:"application/json"}});if(!I.ok)return;const F=await I.json().catch(()=>null),A=F?.sources??F?.data?.sources;if(!A||v)return;d(k=>({...k,[C.id]:A}))}catch{}});await Promise.all(x)})(),()=>{v=!0}},[b,n]);const j="bg-background",m=o.useMemo(()=>n.filter(v=>!!h[v.id]?.project?.exists),[n,h]),E=o.useMemo(()=>n.filter(v=>!h[v.id]?.project?.exists),[n,h]);return s.jsxs("div",{className:ye("flex h-full flex-col",j),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${an} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(Fa,{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(V,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(Ou),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(L,{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(L,{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:[E.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")}),E.map(v=>s.jsx(vo,{provider:v,selectedProviderId:i,onSelect:()=>{r(v.id),t?.()}},v.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",E.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(v=>s.jsx(vo,{provider:v,selectedProviderId:i,onSelect:()=>{r(v.id),t?.()}},v.id))]})]})})]})},vo=t=>{const e=mt.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,h=a.id,d=l?"bg-interactive-selection":"hover:bg-interactive-hover";let b;e[0]!==d?(b=ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",d),e[0]=d,e[1]=b):b=e[1];let c;e[2]!==a.id?(c=s.jsx(Kn,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=c):c=e[3];const j=a.name||a.id;let m;e[4]!==j?(m=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:j}),e[4]=j,e[5]=m):m=e[5];let E;e[6]!==r?(E=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=E):E=e[7];let v;e[8]!==i||e[9]!==c||e[10]!==m||e[11]!==E?(v=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:[c,m,E]}),e[8]=i,e[9]=c,e[10]=m,e[11]=E,e[12]=v):v=e[12];let P;return e[13]!==a.id||e[14]!==b||e[15]!==v?(P=s.jsx("div",{className:b,children:v},h),e[13]=a.id,e[14]=b,e[15]=v,e[16]=P):P=e[16],P},Ku=t=>t,yo=(t,e,a)=>t&&!e&&!a,jo=t=>typeof t=="object"&&t!==null,Dl=t=>{const e=typeof t.type=="string"?t.type:"",a=`${t.name??""} ${t.label??""}`.toLowerCase(),n=`${e} ${a}`.toLowerCase();return n.includes("oauth")?"oauth":n.includes("api")?"api":e.toLowerCase()},Uu=t=>{if(!jo(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>jo(i)));return e},wo=t=>t.length===0?!0:t.some(e=>Dl(e)==="api"),ko=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>Dl(e)==="oauth"),zu=t=>t!=="claude-code",xr={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},Ln="__custom_provider__",_u=/^[a-z0-9][a-z0-9-_]*$/,Ml=/^https?:\/\//,$u=/^\{env:([^}]+)\}$/;let Vu=0;const oi=()=>`row-${Vu++}`,br=()=>({row:oi(),id:"",name:""}),vr=()=>({row:oi(),key:"",value:""}),Bu=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[br()],headers:[vr()]});function Hu(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function Gu(t){const e=t.trim();if(!e)return{};const n=e.match($u)?.[1]?.trim();return n?{env:n}:{key:e}}function qu(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&Ml.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>{if(!i||typeof i!="object")return!1;const r="api"in i&&i.api&&typeof i.api=="object"?i.api:null;return typeof r?.npm=="string"&&new Set(Object.values(xr)).has(r.npm)})}function No(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&qu(t):!1}function So(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function Wu(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(b=>typeof b[0]=="string"&&typeof b[1]=="string").map(([b,c])=>({row:oi(),key:b,value:c})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([b,c])=>({id:b,name:c&&typeof c=="object"&&"name"in c&&typeof c.name=="string"?c.name:b})):[],l=r.length>0?r.map(b=>({row:oi(),id:typeof b?.id=="string"?b.id:"",name:typeof b?.name=="string"?b.name:typeof b?.id=="string"?b.id:""})):[br()],h=Array.isArray(t.env)?t.env.find(b=>typeof b=="string"&&b.trim().length>0)?.trim():void 0,d=r.find(b=>"api"in b);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:Hu(d?.api?.npm),baseURL:a,apiKey:h?`{env:${h}}`:"",models:l,headers:i.length>0?i:[vr()]}}function Ju(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=Gu(t.form.apiKey),l=t.disabledProviders??[],h=t.editingProviderID?.trim(),d=e?_u.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),b=a?void 0:t.t("settings.providers.page.custom.error.name.required"),c=n?Ml.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),m=!!(i||r||h&&t.allowExistingAuth&&h===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),E=l.includes(e),P=d||!!(h&&h===e)?void 0:t.existingProviderIDs.has(e)&&!E?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,x=new Set,C=t.form.models.map(N=>{const R=N.id.trim(),y=R?x.has(R)?t.t("settings.providers.page.custom.error.duplicate"):void x.add(R):t.t("settings.providers.page.custom.error.required"),O=N.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:y,name:O}}),u=C.every(N=>!N.id&&!N.name),I=Object.fromEntries(t.form.models.map(N=>[N.id.trim(),{name:N.name.trim()}])),F=new Set,A=t.form.headers.map(N=>{const R=N.key.trim(),y=N.value.trim();if(!R&&!y)return{};const O=R?F.has(R.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void F.add(R.toLowerCase()):t.t("settings.providers.page.custom.error.required"),q=y?void 0:t.t("settings.providers.page.custom.error.required");return{key:O,value:q}}),k=A.every(N=>!N.key&&!N.value),g=Object.fromEntries(t.form.headers.map(N=>({key:N.key.trim(),value:N.value.trim()})).filter(N=>N.key&&N.value).map(N=>[N.key,N.value])),w={providerID:d??P,name:b,baseURL:c,apiKey:m};return!d&&!P&&!b&&!c&&!m&&u&&k?{err:w,models:C,headers:A,result:{providerID:e,name:a,apiKey:r,config:{npm:xr[t.form.protocol],name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(g).length>0?{headers:g}:{}},models:I}}}:{err:w,models:C,headers:A}}function Qu(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function Yu(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const Co=t=>{const e=mt.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:h,authFailureHint:d,onSubmit:b,onCancel:c,onDisconnect:j}=t;let m;e[0]!==n?(m=n===void 0?[]:n,e[0]=n,e[1]=m):m=e[1];const E=m,v=i===void 0?!1:i,P=r===void 0?"create":r,x=h===void 0?!1:h,C=d===void 0?null:d,{t:u}=rt(),I=P==="edit";let F;e[2]!==l?(F=()=>l??Bu(),e[2]=l,e[3]=F):F=e[3];const[A,k]=o.useState(F);let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g={},e[4]=g):g=e[4];const[w,z]=o.useState(g);let N;e[5]===Symbol.for("react.memo_cache_sentinel")?(N=[],e[5]=N):N=e[5];const[R,y]=o.useState(N);let O;e[6]===Symbol.for("react.memo_cache_sentinel")?(O=[],e[6]=O):O=e[6];const[q,S]=o.useState(O),G=o.useRef(null);let J,T;e[7]!==l||e[8]!==I?(J=()=>{l&&(I&&G.current===l.providerID||(G.current=I?l.providerID:null,k(l),z({}),y([]),S([])))},T=[l,I],e[7]=l,e[8]=I,e[9]=J,e[10]=T):(J=e[9],T=e[10]),o.useEffect(J,T);let Q;e[11]===Symbol.for("react.memo_cache_sentinel")?(Q=(At,St)=>{k(Ut=>({...Ut,[At]:St})),z(Ut=>({...Ut,[At]:void 0}))},e[11]=Q):Q=e[11];const Z=Q;let K;e[12]===Symbol.for("react.memo_cache_sentinel")?(K=(At,St,Ut)=>{k(Mt=>({...Mt,models:Mt.models.map((ps,Es)=>Es===At?{...ps,[St]:Ut}:ps)})),y(Mt=>{const ps=[...Mt];return ps[At]={...ps[At]??{},[St]:void 0},ps})},e[12]=K):K=e[12];const ae=K;let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=(At,St,Ut)=>{k(Mt=>({...Mt,headers:Mt.headers.map((ps,Es)=>Es===At?{...ps,[St]:Ut}:ps)})),S(Mt=>{const ps=[...Mt];return ps[At]={...ps[At]??{},[St]:void 0},ps})},e[13]=_):_=e[13];const B=_;let M;e[14]!==x||e[15]!==v||e[16]!==E||e[17]!==a||e[18]!==A||e[19]!==I||e[20]!==b||e[21]!==u?(M=async At=>{if(At.preventDefault(),v)return;const St=Ju({form:A,t:((Ut,Mt)=>u(Ut,Mt)),existingProviderIDs:a,disabledProviders:E,editingProviderID:I?A.providerID:void 0,allowExistingAuth:I&&x});z(St.err),y(St.models),S(St.headers),St.result&&await b(St.result)},e[14]=x,e[15]=v,e[16]=E,e[17]=a,e[18]=A,e[19]=I,e[20]=b,e[21]=u,e[22]=M):M=e[22];const U=M;let Y;e[23]!==I||e[24]!==u?(Y=u(I?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=I,e[24]=u,e[25]=Y):Y=e[25];let X;e[26]!==u?(X=u("settings.providers.page.custom.description"),e[26]=u,e[27]=X):X=e[27];let ne;e[28]!==X?(ne=s.jsx("p",{className:Fn,children:X}),e[28]=X,e[29]=ne):ne=e[29];let te;e[30]!==C?(te=C?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:C}):null,e[30]=C,e[31]=te):te=e[31];let ge;e[32]!==u?(ge=u("settings.providers.page.custom.field.providerID.label"),e[32]=u,e[33]=ge):ge=e[33];let ee;e[34]!==u?(ee=u("settings.providers.page.custom.field.providerID.info"),e[34]=u,e[35]=ee):ee=e[35];const le=A.providerID;let pe;e[36]===Symbol.for("react.memo_cache_sentinel")?(pe=At=>Z("providerID",At.target.value),e[36]=pe):pe=e[36];let ie;e[37]!==u?(ie=u("settings.providers.page.custom.field.providerID.placeholder"),e[37]=u,e[38]=ie):ie=e[38];const je=!I,Se=I||v,Ce=!!w.providerID;let xe;e[39]!==u?(xe=u("settings.providers.page.custom.field.providerID.label"),e[39]=u,e[40]=xe):xe=e[40];let Re;e[41]!==A.providerID||e[42]!==ie||e[43]!==je||e[44]!==Se||e[45]!==Ce||e[46]!==xe?(Re=s.jsx(He,{value:le,onChange:pe,placeholder:ie,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:je,disabled:Se,"aria-invalid":Ce,"aria-label":xe}),e[41]=A.providerID,e[42]=ie,e[43]=je,e[44]=Se,e[45]=Ce,e[46]=xe,e[47]=Re):Re=e[47];let Oe;e[48]!==w.providerID?(Oe=w.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.providerID}):null,e[48]=w.providerID,e[49]=Oe):Oe=e[49];let fe;e[50]!==ge||e[51]!==ee||e[52]!==Re||e[53]!==Oe?(fe=s.jsxs(Zt,{label:ge,info:ee,children:[Re,Oe]}),e[50]=ge,e[51]=ee,e[52]=Re,e[53]=Oe,e[54]=fe):fe=e[54];let be;e[55]!==u?(be=u("settings.providers.page.custom.field.protocol.label"),e[55]=u,e[56]=be):be=e[56];let De;e[57]!==u?(De=u("settings.providers.page.custom.field.protocol.info"),e[57]=u,e[58]=De):De=e[58];const _e=A.protocol;let Le;e[59]===Symbol.for("react.memo_cache_sentinel")?(Le=At=>{At in xr&&k(St=>({...St,protocol:At}))},e[59]=Le):Le=e[59];let qe;e[60]!==u?(qe=u("settings.providers.page.custom.field.protocol.label"),e[60]=u,e[61]=qe):qe=e[61];let Ke;e[62]===Symbol.for("react.memo_cache_sentinel")?(Ke=s.jsx($t,{}),e[62]=Ke):Ke=e[62];let Xe;e[63]!==qe?(Xe=s.jsx(Ft,{"aria-label":qe,className:"w-full",children:Ke}),e[63]=qe,e[64]=Xe):Xe=e[64];let We;e[65]!==u?(We=u("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=u,e[66]=We):We=e[66];let Ze;e[67]!==We?(Ze=s.jsx(pt,{value:"openai-chat",children:We}),e[67]=We,e[68]=Ze):Ze=e[68];let we;e[69]!==u?(we=u("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=u,e[70]=we):we=e[70];let Je;e[71]!==we?(Je=s.jsx(pt,{value:"openai-responses",children:we}),e[71]=we,e[72]=Je):Je=e[72];let Me;e[73]!==u?(Me=u("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=u,e[74]=Me):Me=e[74];let ve;e[75]!==Me?(ve=s.jsx(pt,{value:"anthropic-messages",children:Me}),e[75]=Me,e[76]=ve):ve=e[76];let $e;e[77]!==Ze||e[78]!==Je||e[79]!==ve?($e=s.jsxs(Kt,{children:[Ze,Je,ve]}),e[77]=Ze,e[78]=Je,e[79]=ve,e[80]=$e):$e=e[80];let $;e[81]!==v||e[82]!==A.protocol||e[83]!==Xe||e[84]!==$e?($=s.jsxs(Lt,{value:_e,onValueChange:Le,disabled:v,children:[Xe,$e]}),e[81]=v,e[82]=A.protocol,e[83]=Xe,e[84]=$e,e[85]=$):$=e[85];let de;e[86]!==be||e[87]!==De||e[88]!==$?(de=s.jsx(Zt,{label:be,info:De,children:$}),e[86]=be,e[87]=De,e[88]=$,e[89]=de):de=e[89];let ue;e[90]!==u?(ue=u("settings.providers.page.custom.field.name.label"),e[90]=u,e[91]=ue):ue=e[91];let ke;e[92]!==u?(ke=u("settings.providers.page.custom.field.name.info"),e[92]=u,e[93]=ke):ke=e[93];const oe=A.name;let Ae;e[94]===Symbol.for("react.memo_cache_sentinel")?(Ae=At=>Z("name",At.target.value),e[94]=Ae):Ae=e[94];let H;e[95]!==u?(H=u("settings.providers.page.custom.field.name.placeholder"),e[95]=u,e[96]=H):H=e[96];const ze=!!w.name;let tt;e[97]!==u?(tt=u("settings.providers.page.custom.field.name.label"),e[97]=u,e[98]=tt):tt=e[98];let Fe;e[99]!==A.name||e[100]!==H||e[101]!==ze||e[102]!==tt?(Fe=s.jsx(He,{value:oe,onChange:Ae,placeholder:H,className:"h-8 rounded-md px-3","aria-invalid":ze,"aria-label":tt}),e[99]=A.name,e[100]=H,e[101]=ze,e[102]=tt,e[103]=Fe):Fe=e[103];let at;e[104]!==w.name?(at=w.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.name}):null,e[104]=w.name,e[105]=at):at=e[105];let wt;e[106]!==ue||e[107]!==ke||e[108]!==Fe||e[109]!==at?(wt=s.jsxs(Zt,{label:ue,info:ke,children:[Fe,at]}),e[106]=ue,e[107]=ke,e[108]=Fe,e[109]=at,e[110]=wt):wt=e[110];let bt;e[111]!==u?(bt=u("settings.providers.page.custom.field.baseURL.label"),e[111]=u,e[112]=bt):bt=e[112];let ut;e[113]!==u?(ut=u("settings.providers.page.custom.field.baseURL.info"),e[113]=u,e[114]=ut):ut=e[114];const gt=A.baseURL;let Pt;e[115]===Symbol.for("react.memo_cache_sentinel")?(Pt=At=>Z("baseURL",At.target.value),e[115]=Pt):Pt=e[115];let jt;e[116]!==u?(jt=u("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=u,e[117]=jt):jt=e[117];const Et=!!w.baseURL;let Ye;e[118]!==u?(Ye=u("settings.providers.page.custom.field.baseURL.label"),e[118]=u,e[119]=Ye):Ye=e[119];let Ge;e[120]!==A.baseURL||e[121]!==jt||e[122]!==Et||e[123]!==Ye?(Ge=s.jsx(He,{value:gt,onChange:Pt,placeholder:jt,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Et,"aria-label":Ye}),e[120]=A.baseURL,e[121]=jt,e[122]=Et,e[123]=Ye,e[124]=Ge):Ge=e[124];let ct;e[125]!==w.baseURL?(ct=w.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.baseURL}):null,e[125]=w.baseURL,e[126]=ct):ct=e[126];let Ie;e[127]!==bt||e[128]!==ut||e[129]!==Ge||e[130]!==ct?(Ie=s.jsxs(Zt,{label:bt,info:ut,children:[Ge,ct]}),e[127]=bt,e[128]=ut,e[129]=Ge,e[130]=ct,e[131]=Ie):Ie=e[131];let It;e[132]!==u?(It=u("settings.providers.page.custom.field.apiKey.label"),e[132]=u,e[133]=It):It=e[133];let Ne;e[134]!==x||e[135]!==I||e[136]!==u?(Ne=u(I&&x?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=x,e[135]=I,e[136]=u,e[137]=Ne):Ne=e[137];const Ct=A.apiKey;let W;e[138]===Symbol.for("react.memo_cache_sentinel")?(W=At=>Z("apiKey",At.target.value),e[138]=W):W=e[138];let me;e[139]!==x||e[140]!==I||e[141]!==u?(me=u(I&&x?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=x,e[140]=I,e[141]=u,e[142]=me):me=e[142];const Ee=!!w.apiKey;let Pe;e[143]!==u?(Pe=u("settings.providers.page.custom.field.apiKey.label"),e[143]=u,e[144]=Pe):Pe=e[144];let lt;e[145]!==A.apiKey||e[146]!==me||e[147]!==Ee||e[148]!==Pe?(lt=s.jsx(He,{type:"password",value:Ct,onChange:W,placeholder:me,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Ee,"aria-label":Pe}),e[145]=A.apiKey,e[146]=me,e[147]=Ee,e[148]=Pe,e[149]=lt):lt=e[149];let it;e[150]!==w.apiKey?(it=w.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:w.apiKey}):null,e[150]=w.apiKey,e[151]=it):it=e[151];let Ve;e[152]!==It||e[153]!==Ne||e[154]!==lt||e[155]!==it?(Ve=s.jsxs(Zt,{label:It,info:Ne,children:[lt,it]}),e[152]=It,e[153]=Ne,e[154]=lt,e[155]=it,e[156]=Ve):Ve=e[156];let Nt;e[157]!==Y||e[158]!==ne||e[159]!==te||e[160]!==fe||e[161]!==de||e[162]!==wt||e[163]!==Ie||e[164]!==Ve?(Nt=s.jsxs(Ue,{title:Y,divider:!1,settingsItem:"providers.custom",contentClassName:Sn,children:[ne,te,fe,de,wt,Ie,Ve]}),e[157]=Y,e[158]=ne,e[159]=te,e[160]=fe,e[161]=de,e[162]=wt,e[163]=Ie,e[164]=Ve,e[165]=Nt):Nt=e[165];let is;e[166]!==u?(is=u("settings.providers.page.custom.models.title"),e[166]=u,e[167]=is):is=e[167];let es;if(e[168]!==A.models||e[169]!==R||e[170]!==u){let At;e[172]!==A.models.length||e[173]!==R||e[174]!==u?(At=(St,Ut)=>s.jsx("div",{className:`${Ks} 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:Ot,children:u("settings.providers.page.custom.models.idLabel")}),s.jsx(He,{value:St.id,onChange:Mt=>ae(Ut,"id",Mt.target.value),placeholder:u("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.models.idLabel")}),R[Ut]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:R[Ut]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Ot,children:u("settings.providers.page.custom.models.nameLabel")}),s.jsx(He,{value:St.name,onChange:Mt=>ae(Ut,"name",Mt.target.value),placeholder:u("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":u("settings.providers.page.custom.models.nameLabel")}),R[Ut]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:R[Ut]?.name}):null]})]}),s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:vs,disabled:A.models.length<=1,onClick:()=>{A.models.length<=1||(k(Mt=>({...Mt,models:Mt.models.filter((ps,Es)=>Es!==Ut)})),y(Mt=>Mt.filter((ps,Es)=>Es!==Ut)))},"aria-label":u("settings.providers.page.custom.models.remove"),children:s.jsx(L,{name:"delete-bin",className:"size-4"})})]})},St.row),e[172]=A.models.length,e[173]=R,e[174]=u,e[175]=At):At=e[175],es=A.models.map(At),e[168]=A.models,e[169]=R,e[170]=u,e[171]=es}else es=e[171];let ys;e[176]===Symbol.for("react.memo_cache_sentinel")?(ys=()=>{k(Zu),y(Xu)},e[176]=ys):ys=e[176];let Ht;e[177]!==u?(Ht=u("settings.providers.page.custom.models.add"),e[177]=u,e[178]=Ht):Ht=e[178];let rs;e[179]!==Ht?(rs=s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ys,children:Ht}),e[179]=Ht,e[180]=rs):rs=e[180];let zt;e[181]!==is||e[182]!==es||e[183]!==rs?(zt=s.jsxs(Ue,{title:is,contentClassName:Sn,children:[es,rs]}),e[181]=is,e[182]=es,e[183]=rs,e[184]=zt):zt=e[184];let fs;e[185]!==u?(fs=u("settings.providers.page.custom.headers.title"),e[185]=u,e[186]=fs):fs=e[186];let os;e[187]!==u?(os=u("settings.providers.page.custom.headers.description"),e[187]=u,e[188]=os):os=e[188];let ss;e[189]!==os?(ss=s.jsx("p",{className:Fn,children:os}),e[189]=os,e[190]=ss):ss=e[190];let ns;if(e[191]!==A.headers||e[192]!==q||e[193]!==u){let At;e[195]!==A.headers.length||e[196]!==q||e[197]!==u?(At=(St,Ut)=>s.jsx("div",{className:`${Ks} 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:Ot,children:u("settings.providers.page.custom.headers.keyLabel")}),s.jsx(He,{value:St.key,onChange:Mt=>B(Ut,"key",Mt.target.value),placeholder:u("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.keyLabel")}),q[Ut]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:q[Ut]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Ot,children:u("settings.providers.page.custom.headers.valueLabel")}),s.jsx(He,{value:St.value,onChange:Mt=>B(Ut,"value",Mt.target.value),placeholder:u("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":u("settings.providers.page.custom.headers.valueLabel")}),q[Ut]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:q[Ut]?.value}):null]})]}),s.jsx(V,{type:"button",variant:"ghost",size:"icon",className:vs,disabled:A.headers.length<=1,onClick:()=>{A.headers.length<=1||(k(Mt=>({...Mt,headers:Mt.headers.filter((ps,Es)=>Es!==Ut)})),S(Mt=>Mt.filter((ps,Es)=>Es!==Ut)))},"aria-label":u("settings.providers.page.custom.headers.remove"),children:s.jsx(L,{name:"delete-bin",className:"size-4"})})]})},St.row),e[195]=A.headers.length,e[196]=q,e[197]=u,e[198]=At):At=e[198],ns=A.headers.map(At),e[191]=A.headers,e[192]=q,e[193]=u,e[194]=ns}else ns=e[194];let js;e[199]===Symbol.for("react.memo_cache_sentinel")?(js=()=>{k(eg),S(tg)},e[199]=js):js=e[199];let re;e[200]!==u?(re=u("settings.providers.page.custom.headers.add"),e[200]=u,e[201]=re):re=e[201];let ot;e[202]!==re?(ot=s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:js,children:re}),e[202]=re,e[203]=ot):ot=e[203];let vt;e[204]!==fs||e[205]!==ss||e[206]!==ns||e[207]!==ot?(vt=s.jsxs(Ue,{title:fs,contentClassName:Sn,children:[ss,ns,ot]}),e[204]=fs,e[205]=ss,e[206]=ns,e[207]=ot,e[208]=vt):vt=e[208];let Be;e[209]!==v||e[210]!==c||e[211]!==u?(Be=c?s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:c,disabled:v,children:u("settings.providers.page.custom.actions.back")}):null,e[209]=v,e[210]=c,e[211]=u,e[212]=Be):Be=e[212];let et;e[213]!==v||e[214]!==j||e[215]!==u?(et=j?s.jsx(V,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{j()},disabled:v,children:u("settings.providers.page.actions.disconnect")}):null,e[213]=v,e[214]=j,e[215]=u,e[216]=et):et=e[216];let ht;e[217]!==v||e[218]!==I||e[219]!==u?(ht=u(v?"settings.providers.page.actions.saving":I?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=v,e[218]=I,e[219]=u,e[220]=ht):ht=e[220];let Tt;e[221]!==v||e[222]!==ht?(Tt=s.jsx(V,{type:"submit",size:"xs",className:"!font-normal",disabled:v,children:ht}),e[221]=v,e[222]=ht,e[223]=Tt):Tt=e[223];let Dt;e[224]!==Be||e[225]!==et||e[226]!==Tt?(Dt=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Be,et,Tt]}),e[224]=Be,e[225]=et,e[226]=Tt,e[227]=Dt):Dt=e[227];let Xt;return e[228]!==U||e[229]!==Nt||e[230]!==zt||e[231]!==vt||e[232]!==Dt?(Xt=s.jsxs("form",{onSubmit:U,className:"space-y-0",children:[Nt,zt,vt,Dt]}),e[228]=U,e[229]=Nt,e[230]=zt,e[231]=vt,e[232]=Dt,e[233]=Xt):Xt=e[233],Xt};function Zu(t){return{...t,models:[...t.models,br()]}}function Xu(t){return[...t,{}]}function eg(t){return{...t,headers:[...t.headers,vr()]}}function tg(t){return[...t,{}]}const sg=(t,e)=>!!e&&t!=="claude-code",ng=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Jn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Cs=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(!Jn(a))continue;const n=Cs(a.value);n!==void 0&&e.push({value:n,label:Cs(a.label)??n,...Cs(a.hint)?{hint:Cs(a.hint)}:{}})}return e},ig=t=>{if(!Jn(t))return;const e=Cs(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}},rg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Jn(a))continue;const n=Cs(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=ig(a.when);e.push({type:i,key:n,message:Cs(a.message)??n,options:r,...Cs(a.placeholder)?{placeholder:Cs(a.placeholder)}:{},...l?{when:l}:{}})}return e},og=(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},yr=(t,e)=>t.filter(a=>og(a,e)),lg=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},cg=(t,e)=>yr(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,dg=(t,e)=>{const a={};for(const n of yr(t,e))a[n.key]=(e[n.key]??"").trim();return a},pg=t=>{const e=Jn(t)?t:{},a=Jn(e.data)?e.data:e,n=Cs(a.url)??Cs(a.verification_uri_complete)??Cs(a.verification_uri),i=Cs(a.instructions)??Cs(a.message);if(!n&&!i)return null;const r=Cs(a.user_code)??Cs(a.userCode)??(i?ng.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},Po=(t,e,a)=>{const n=Jn(t)?t:{},i=Jn(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 Cs(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},Fi={phase:"idle"},Io=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=rt(),[r,l]=o.useState(Fi),[h,d]=o.useState({}),[b,c]=o.useState(""),j=o.useRef(null);o.useEffect(()=>()=>j.current?.abort(),[]);const m=r.phase==="idle"?null:r.methodIndex,E=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,v=async(g,w,z)=>{const N=await Ta(g);if(N.ok){D.success(i(w));return}console.error("Failed to copy OAuth value:",N.error),D.error(i(z))},P=async(g,w)=>{const z=new AbortController;j.current?.abort(),j.current=z;try{const N=await dn.getSdkClient().provider.oauth.callback({providerID:t,method:g,...w?{code:w}:{}},{signal:z.signal});if(z.signal.aborted)return;if(N.error)throw N.error;l(Fi),D.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(N){if(z.signal.aborted)return;console.error("Failed to complete OAuth flow:",N),l({phase:"failed",methodIndex:g,message:Po(N,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{j.current===z&&(j.current=null)}},x=async(g,w)=>{l({phase:"authorizing",methodIndex:g});let z;try{const N=await dn.getSdkClient().provider.oauth.authorize({providerID:t,method:g,...Object.keys(w).length>0?{inputs:w}:{}});if(N.error)throw N.error;const R=pg(N.data);if(!R){l({phase:"failed",methodIndex:g,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}z=R}catch(N){console.error("Failed to start OAuth flow:",N),l({phase:"failed",methodIndex:g,message:Po(N,i,"settings.providers.page.toast.oauthStartFailed")});return}if(z.url&&sg(t,z.url)&&En(z.url),z.method==="code"){c(""),l({phase:"awaitingCode",methodIndex:g,authorization:z,submitting:!1});return}l({phase:"waiting",methodIndex:g,authorization:z}),await P(g)},C=g=>{const w=rg(g.prompts);if(w.length===0){x(g.index,{});return}d(lg(w)),l({phase:"prompting",methodIndex:g.index,prompts:w,error:null})},u=()=>{if(r.phase!=="prompting")return;const g=cg(r.prompts,h);if(g){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:g.message})});return}x(r.methodIndex,dg(r.prompts,h))},I=()=>{if(r.phase!=="awaitingCode")return;const g=b.trim();g&&(l({...r,submitting:!0}),P(r.methodIndex,g))},F=()=>{j.current?.abort(),j.current=null,l(Fi)},A=g=>{const w=h[g.key]??"",z=N=>d(R=>({...R,[g.key]:N}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:g.message}),g.type==="select"?s.jsxs(Lt,{value:w,onValueChange:z,children:[s.jsx(Ft,{size:qt,className:Pn,children:s.jsx($t,{children:N=>g.options.find(R=>R.value===N)?.label??null})}),s.jsx(Kt,{children:g.options.map(N=>s.jsx(pt,{value:N.value,children:N.hint?`${N.label} · ${N.hint}`:N.label},N.value))})]}):s.jsx(He,{value:w,onChange:N=>z(N.target.value),placeholder:g.placeholder,className:"max-w-[24rem] text-xs"})]},g.key)},k=g=>s.jsxs(s.Fragment,{children:[g.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:g.instructions}),g.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:g.userCode,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.deviceCodeLabel"),className:"font-mono text-center tracking-widest"}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>{v(g.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),g.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:g.url,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{En(g.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{v(g.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:ye("space-y-4",n),children:e.map(g=>{const w=m===g.index;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:g.label}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>C(g),disabled:E,children:i("settings.providers.page.actions.connect")})]}),w&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[yr(r.prompts,h).map(A),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(V,{size:"xs",className:"!font-normal",onClick:u,children:i("settings.providers.page.actions.continue")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:F,children:i("settings.providers.page.actions.cancel")})]})]}),w&&r.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(L,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),w&&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(L,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:F,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),w&&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(He,{value:b,onChange:z=>c(z.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:r.submitting}),s.jsx(V,{size:"xs",className:"!font-normal shrink-0",onClick:I,disabled:r.submitting||b.trim().length===0,children:r.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:F,disabled:r.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),w&&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(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>C(g),children:i("settings.providers.page.actions.tryAgain")})]})]},g.index)})})},mg=t=>new Intl.NumberFormat(mr(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),Ao=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=mg(t);return e.endsWith(".0")?e.slice(0,-2):e},Na="__add_provider__",Rl=t=>typeof t=="object"&&t!==null,Eo=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),ug=t=>{if(typeof t=="string")return{id:t};if(!Rl(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}},gg=t=>{let e=[];Array.isArray(t)?e=t:Rl(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>ug(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},hg=()=>{const{t}=rt(),e=Us(),a=st($=>cl($,e)),n=st($=>$.selectedProviderId),i=st($=>$.setSelectedProvider),r=st($=>$.getModelMetadata),l=ce($=>$.hiddenModels),h=ce($=>$.toggleHiddenModel),d=ce($=>$.hideAllModels),b=ce($=>$.showAllModels),[c,j]=o.useState({}),[m,E]=o.useState(!1),[v,P]=o.useState({}),[x,C]=o.useState(null),[u,I]=o.useState(""),[F,A]=o.useState([]),[k,g]=o.useState(!1),[w,z]=o.useState(null),[N,R]=o.useState(""),[y,O]=o.useState(""),[q,S]=o.useState(!1),[G,J]=o.useState({}),[T,Q]=o.useState(!1),[Z,K]=o.useState(null),[ae,_]=o.useState(null),[B,M]=o.useState(null),[U,Y]=o.useState(null),[X,ne]=o.useState(null),te=n===Na,ge=te&&N===Ln,ee=!!(Z&&n&&Z===n&&!te);o.useEffect(()=>{!n&&a.length>0&&i(a[0].id)},[a,n,i]),o.useEffect(()=>{if(!n)return;let $=!0;return(async()=>{E(!0);try{const ue=await dn.getSdkClient().provider.auth();if(ue.error)throw new Error(`provider.auth failed: ${String(ue.error)}`);if(!$)return;j(Uu(ue.data))}catch(ue){if(!$)return;console.error("Failed to load provider auth methods:",ue),D.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{$&&E(!1)}})(),()=>{$=!1}},[n,t]),o.useEffect(()=>{if(!Ku(te))return;let $=!0;return(async()=>{g(!0),z(null);try{const ue=await dn.getSdkClient().provider.list();if(ue.error)throw new Error(`provider.list failed: ${String(ue.error)}`);if(!$)return;A(gg(ue.data))}catch(ue){if(!$)return;console.error("Failed to load available providers:",ue),z(t("settings.providers.page.state.unableToLoadProviderList"))}finally{$&&g(!1)}})(),()=>{$=!1}},[te,t]);const le=o.useMemo(()=>new Set(a.map($=>$.id)),[a]),pe=o.useMemo(()=>F.filter($=>!le.has($.id)).sort(($,de)=>{const ue=($.name||$.id).toLowerCase(),ke=(de.name||de.id).toLowerCase();return ue.localeCompare(ke)}),[F,le]);o.useEffect(()=>{n===Na&&N&&N!==Ln&&!pe.some($=>$.id===N)&&R("")},[n,N,pe]),o.useEffect(()=>{if(n===Na){Q(!0),K(null),_(null),M(null),Y(null);return}Q(!1),Z&&Z!==n&&(K(null),_(null),M(null),Y(null))},[n,Z]),o.useEffect(()=>{if(!n||n===Na)return;const $=G[n];if(!$)return;const de=a.find(Ae=>Ae.id===n),ue=Array.isArray(de?.env)?de.env.filter(Ae=>typeof Ae=="string"&&Ae.trim().length>0):[],ke=!!$.auth.exists||ue.length>0,oe=!!(de&&No(de,$));yo(!0,ke,oe)&&Q(!0)},[n,G,a]),o.useEffect(()=>{if(!n||n===Na)return;let $=!1;return(async()=>{try{const ue=e?`?directory=${encodeURIComponent(e)}`:"",ke=await dt(`/api/provider/${encodeURIComponent(n)}/source${ue}`,{method:"GET",headers:{Accept:"application/json"}}),oe=await ke.json().catch(()=>null);if(!ke.ok)throw new Error(oe?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Ae=oe?.sources??oe?.data?.sources;!$&&Ae&&J(H=>({...H,[n]:Ae}))}catch(ue){$||console.error("Failed to load provider sources:",ue)}})(),()=>{$=!0}},[n,e,t]);const ie=a.find($=>$.id===n),je=n?G[n]:void 0,Se=async $=>{const de=v[$]?.trim()??"";if(!de){D.error(t("settings.providers.page.toast.apiKeyRequired"));return}const ue=`api:${$}`;C(ue);try{if((await dn.getSdkClient().auth.set({providerID:$,auth:{type:"api",key:de}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));D.success(t("settings.providers.page.toast.apiKeySaved")),P(oe=>({...oe,[$]:""})),zn("providers",{id:$}),i($)}catch(ke){console.error("Failed to save API key:",ke),D.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{C(null)}},Ce=async $=>{const de=`custom:${$.providerID}`;C(de),ne($.providerID),Y(null);try{const ue=Qu($);if(ue&&(await dn.getSdkClient().auth.set(ue)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const ke=Yu($,{scope:Z?B??So(G[Z]):"user"}),oe=await dt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(ke)}),Ae=await oe.json().catch(()=>null);if(!oe.ok)throw ue&&Y(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(Ae?.error||t("settings.providers.page.toast.customProviderSaveFailed"));D.success(t("settings.providers.page.toast.customProviderSaved",{provider:$.name})),R(""),K(null),_(null),M(null),Y(null),ne(null),ii(Ae,"providers",{id:$.providerID}),i($.providerID)}catch(ue){console.error("Failed to save custom provider:",ue),D.error(ue instanceof Error&&ue.message?ue.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{C(null)}},xe=$=>t("settings.providers.page.auth.oauthMethodFallback",{index:String($+1)}),Re=$=>{Q(!1),zu($)&&zn("providers",{id:$}),i($)},Oe=async $=>{const de=`disconnect:${$}`;C(de);try{const ue=await dt(`/api/provider/${encodeURIComponent($)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),ke=await ue.json().catch(()=>null);if(!ue.ok)throw new Error(ke?.error||t("settings.providers.page.toast.providerDisconnectFailed"));D.success(t("settings.providers.page.toast.providerDisconnected")),ii(ke,"providers",{id:$})}catch(ue){console.error("Failed to disconnect provider:",ue),D.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{C(null)}},fe=async $=>{$&&(await Oe($),K(null),_(null),M(null),Y(null),ne(null),R(""))};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(L,{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(cs,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(Ue,{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")}):w?s.jsx("p",{className:"typography-meta text-muted-foreground",children:w}):s.jsxs(sn,{open:q,onOpenChange:$=>{S($),$||O("")},children:[s.jsx(en,{asChild:!0,children:s.jsxs("button",{type:"button",className:Cn,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[N&&N!==Ln?s.jsx(Kn,{providerId:N,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ye("truncate typography-ui-label font-normal",N?"text-foreground":"text-muted-foreground"),children:N===Ln?t("settings.providers.page.custom.optionLabel"):N?pe.find($=>$.id===N)?.name||N:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(tn,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:$=>$.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:$=>$.stopPropagation(),children:[s.jsx(L,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:y,onChange:$=>O($.target.value),onKeyDown:$=>$.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 $=y.toLowerCase(),de=t("settings.providers.page.custom.optionLabel"),ue=!$||de.toLowerCase().includes($)||"other".includes($)||"custom".includes($),ke=pe.filter(oe=>(oe.name||oe.id).toLowerCase().includes($)||oe.id.toLowerCase().includes($));return ke.length===0&&!ue?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:[ke.map(oe=>s.jsxs(nn,{onSelect:()=>{R(oe.id),S(!1),O("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Kn,{providerId:oe.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:oe.name||oe.id})]}),N===oe.id&&s.jsx(L,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},oe.id)),ue?s.jsxs(nn,{onSelect:()=>{R(Ln),S(!1),O("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(L,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:de})]}),N===Ln&&s.jsx(L,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Ln):null]})})()})]})]})]})}),ge?s.jsx(Co,{mode:"create",existingProviderIDs:le,busy:x?.startsWith("custom:")??!1,authFailureHint:U,onCancel:()=>{R(""),Y(null),ne(null)},onDisconnect:U&&X?()=>{fe(X)}:void 0,onSubmit:Ce}):N?s.jsx(Ue,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:m?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const $=c[N]??[],de=Eo(ko($),xe),ue=wo($);return s.jsxs(s.Fragment,{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(ts,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:v[N]??"",onChange:ke=>P(oe=>({...oe,[N]:ke.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(V,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Se(N),disabled:x===`api:${N}`,children:x===`api:${N}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,de.length>0?s.jsx(Io,{providerId:N,methods:de,onConnected:()=>Re(N),className:ye(ue&&"border-t border-[var(--surface-subtle)] pt-2")},N):null]})})()})}):null]});if(!ie)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(L,{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 be=Array.isArray(ie.models)?ie.models:[],De=c[ie.id]??[],_e=Eo(ko(De),xe),Le=wo(De),qe=!!je,Ke=qe&&No(ie,je),Xe=Array.isArray(ie.env)?ie.env.filter($=>typeof $=="string"&&$.trim().length>0):[],We=!!je?.auth.exists,Ze=Xe.length>0,we=We||Ze,Je=yo(qe,we,Ke),Me=be.length>0&&!Je,ve=!Le&&_e.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),$e=be.filter($=>{const de=typeof $?.name=="string"?$.name:"",ue=typeof $?.id=="string"?$.id:"",ke=u.trim().toLowerCase();return ke?de.toLowerCase().includes(ke)||ue.toLowerCase().includes(ke):!0});return ee&&Ke&&ae?s.jsx(cs,{title:ie.name||ie.id,titleLeading:s.jsx(Kn,{providerId:ie.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:ie.id}),showSaveStatus:!1,children:s.jsx(Co,{mode:"edit",existingProviderIDs:le,initialValues:ae,allowExistingAuth:we||!qe,busy:x?.startsWith("custom:")??!1,authFailureHint:U,onCancel:()=>{K(null),_(null),M(null),Y(null),ne(null)},onDisconnect:()=>{fe(ie.id)},onSubmit:Ce})}):s.jsxs(cs,{title:ie.name||ie.id,titleLeading:s.jsx(Kn,{providerId:ie.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:ie.id}),showSaveStatus:!1,children:[s.jsx(Ue,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[Ke?s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Y(null),_(Wu(ie)),M(So(je)),K(ie.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Q($=>!$),children:t(T?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:T?m?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:[Le?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(ts,{children:t("settings.providers.page.auth.apiKeyTooltip")})]}),s.jsxs("div",{className:"flex flex-col @xl:flex-row @xl:items-center gap-2 mt-1.5",children:[s.jsx(He,{type:"password",value:v[ie.id]??"",onChange:$=>P(de=>({...de,[ie.id]:$.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(V,{size:"xs",className:"!font-normal shrink-0",onClick:()=>Se(ie.id),disabled:x===`api:${ie.id}`,children:x===`api:${ie.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,_e.length>0&&s.jsx(Io,{providerId:ie.id,methods:_e,onConnected:()=>Re(ie.id),className:ye(Le&&"border-t border-[var(--surface-subtle)] pt-2")},ie.id)]}):Je?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(L,{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(ts,{children:ve})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(L,{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(ts,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(Ue,{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:je&&(je.auth.exists||je.user.exists||je.project.exists||je.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[je.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,je.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,je.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,je.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(V,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>Oe(ie.id),disabled:x===`disconnect:${ie.id}`,children:x===`disconnect:${ie.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Me?s.jsxs(Ue,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",be.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const $=be.map(de=>typeof de?.id=="string"?de.id:"").filter(de=>de.length>0);d(ie.id,$)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(V,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>b(ie.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(L,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(He,{value:u,onChange:$=>I($.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),$e.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:$e.map($=>{const de=typeof $?.id=="string"?$.id:"",ue=typeof $?.name=="string"?$.name:de,ke=de?r(ie.id,de):void 0,oe=l.some(tt=>tt.providerID===ie.id&&tt.modelID===de),Ae=Ao(ke?.limit?.context),H=Ao(ke?.limit?.output),ze=[];return ke?.tool_call&&ze.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),ke?.reasoning&&ze.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),ke?.attachment&&ze.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:ye("flex items-center gap-3",oe&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:ue}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Ae||H)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Ae?`${Ae} ${t("settings.providers.page.models.tokenBadge.context")}`:"",Ae&&H?" · ":"",H?`${H} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),ze.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:ze.map(({key:tt,icon:Fe,label:at})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:at,"aria-label":at,children:s.jsx(L,{name:Fe,className:"h-3 w-3"})},tt))}),s.jsx("button",{type:"button",onClick:()=>h(ie.id,de),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(oe?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(oe?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:oe?s.jsx(L,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(L,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},de)})})]}):null]})},fg=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)},xg=t=>{const e=mt.c(75),{onItemSelect:a}=t,{t:n}=rt(),i=ls(bg),r=ls(vg),l=ls(yg),h=ls(jg),d=ls(wg),b=ls(kg),c=ls(Ng),j=ls(Sg);let m,E;e[0]!==j?(m=()=>{j()},E=[j],e[0]=j,e[1]=m,e[2]=E):(m=e[1],E=e[2]),o.useEffect(m,E);const v=Cg;let P;e[3]!==c?(P=ne=>{ne!=="usage"&&ne!=="remaining"||(c(ne),v({usageDisplayMode:ne}))},e[3]=c,e[4]=P):P=e[4];const x=P;let C;e[5]===Symbol.for("react.memo_cache_sentinel")?(C=ye("flex h-full flex-col","bg-background"),e[5]=C):C=e[5];let u;e[6]!==n?(u=n("settings.usage.sidebar.title"),e[6]=n,e[7]=u):u=e[7];let I;e[8]!==u?(I=s.jsx("h2",{className:`${an} mb-3`,children:u}),e[8]=u,e[9]=I):I=e[9];let F;e[10]!==n?(F=n("settings.usage.sidebar.total",{count:ri.length}),e[10]=n,e[11]=F):F=e[11];let A;e[12]!==F?(A=s.jsx("span",{className:"typography-meta text-muted-foreground",children:F}),e[12]=F,e[13]=A):A=e[13];let k;e[14]!==h?(k=()=>h(),e[14]=h,e[15]=k):k=e[15];let g;e[16]!==n?(g=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=g):g=e[17];let w;e[18]!==n?(w=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=w):w=e[19];const z=d&&"animate-spin";let N;e[20]!==z?(N=ye("h-3.5 w-3.5",z),e[20]=z,e[21]=N):N=e[21];let R;e[22]!==N?(R=s.jsx(L,{name:"refresh",className:N}),e[22]=N,e[23]=R):R=e[23];let y;e[24]!==d||e[25]!==g||e[26]!==w||e[27]!==R||e[28]!==k?(y=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:k,"aria-label":g,title:w,disabled:d,children:R})}),e[24]=d,e[25]=g,e[26]=w,e[27]=R,e[28]=k,e[29]=y):y=e[29];let O;e[30]!==y||e[31]!==A?(O=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[A,y]}),e[30]=y,e[31]=A,e[32]=O):O=e[32];let q;e[33]!==n?(q=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=q):q=e[34];let S;e[35]!==q?(S=s.jsx("span",{className:"typography-micro text-muted-foreground",children:q}),e[35]=q,e[36]=S):S=e[36];let G;e[37]!==n?(G=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=G):G=e[38];let J;e[39]!==G?(J=s.jsx(Ft,{className:"w-fit",children:s.jsx($t,{placeholder:G})}),e[39]=G,e[40]=J):J=e[40];let T;e[41]!==n?(T=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=T):T=e[42];let Q;e[43]!==T?(Q=s.jsx(pt,{value:"usage",children:T}),e[43]=T,e[44]=Q):Q=e[44];let Z;e[45]!==n?(Z=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=Z):Z=e[46];let K;e[47]!==Z?(K=s.jsx(pt,{value:"remaining",children:Z}),e[47]=Z,e[48]=K):K=e[48];let ae;e[49]!==Q||e[50]!==K?(ae=s.jsxs(Kt,{children:[Q,K]}),e[49]=Q,e[50]=K,e[51]=ae):ae=e[51];let _;e[52]!==x||e[53]!==J||e[54]!==ae||e[55]!==b?(_=s.jsxs(Lt,{value:b,onValueChange:x,children:[J,ae]}),e[52]=x,e[53]=J,e[54]=ae,e[55]=b,e[56]=_):_=e[56];let B;e[57]!==S||e[58]!==_?(B=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[S,_]}),e[57]=S,e[58]=_,e[59]=B):B=e[59];let M;e[60]!==O||e[61]!==B||e[62]!==I?(M=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[I,O,B]}),e[60]=O,e[61]=B,e[62]=I,e[63]=M):M=e[63];let U;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(U=ri.map(ne=>{const te=i.find(je=>je.providerId===ne.id),ge=fg(te?.usage),ee=xc(ge),le=ne.id===r,pe=te?.configured??!1,ie=pe?ee==="critical"?{backgroundColor:"var(--status-error)"}:ee==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",le?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(ne.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:ie}),s.jsx(Kn,{providerId:ne.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:ne.name}),!pe&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},ne.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=U):U=e[69];let Y;e[70]!==U?(Y=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:U}),e[70]=U,e[71]=Y):Y=e[71];let X;return e[72]!==M||e[73]!==Y?(X=s.jsxs("div",{className:C,children:[M,Y]}),e[72]=M,e[73]=Y,e[74]=X):X=e[74],X};function bg(t){return t.results}function vg(t){return t.selectedProviderId}function yg(t){return t.setSelectedProvider}function jg(t){return t.fetchAllQuotas}function wg(t){return t.isLoading}function kg(t){return t.displayMode}function Ng(t){return t.setDisplayMode}function Sg(t){return t.loadSettings}async function Cg(t){try{await kt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Ki=t=>{const e=mt.c(44),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:h}=t,d=r===void 0?!1:r,b=l===void 0?!1:l,c=ls(Pg),j=ce(Ig),m=c==="remaining"?n.remainingPercent:n.usedPercent,E=c==="remaining"?"remaining":"used";let v;e[0]!==m||e[1]!==n.valueLabel?(v=bc(n.valueLabel,m),e[0]=m,e[1]=n.valueLabel,e[2]=v):v=e[2];const P=v,x=n.resetAfterFormatted??n.resetAtFormatted;let C;e[3]!==x||e[4]!==j||e[5]!==n.resetAt?(C=vc(n.resetAt,x,j),e[3]=x,e[4]=j,e[5]=n.resetAt,e[6]=C):C=e[6];const u=C;let I;e[7]!==a?(I=yc(a),e[7]=a,e[8]=I):I=e[8];const F=I;let A;e[9]!==h||e[10]!==d||e[11]!==b?(A=d&&s.jsx(Qi,{checked:b,onChange:Z=>h?.(Z),ariaLabel:"Show in dropdown"}),e[9]=h,e[10]=d,e[11]=b,e[12]=A):A=e[12];let k;e[13]!==F?(k=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:F}),e[13]=F,e[14]=k):k=e[14];let g;e[15]!==i?(g=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=g):g=e[16];let w;e[17]!==k||e[18]!==g?(w=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[k,g]}),e[17]=k,e[18]=g,e[19]=w):w=e[19];let z;e[20]!==w||e[21]!==A?(z=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[A,w]}),e[20]=w,e[21]=A,e[22]=z):z=e[22];const N=P==="-"?"":P;let R;e[23]!==N?(R=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:N}),e[23]=N,e[24]=R):R=e[24];let y;e[25]!==z||e[26]!==R?(y=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[z,R]}),e[25]=z,e[26]=R,e[27]=y):y=e[27];let O;e[28]!==m||e[29]!==n.usedPercent?(O=s.jsx(wd,{percent:m,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=m,e[29]=n.usedPercent,e[30]=O):O=e[30];const q=u?`Resets ${u}`:"";let S;e[31]!==q?(S=s.jsx("span",{className:"typography-micro text-muted-foreground",children:q}),e[31]=q,e[32]=S):S=e[32];let G;e[33]!==E?(G=s.jsx("span",{className:"typography-micro text-muted-foreground",children:E}),e[33]=E,e[34]=G):G=e[34];let J;e[35]!==S||e[36]!==G?(J=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[S,G]}),e[35]=S,e[36]=G,e[37]=J):J=e[37];let T;e[38]!==O||e[39]!==J?(T=s.jsxs("div",{className:"mt-2.5",children:[O,J]}),e[38]=O,e[39]=J,e[40]=T):T=e[40];let Q;return e[41]!==y||e[42]!==T?(Q=s.jsxs("div",{className:"py-3",children:[y,T]}),e[41]=y,e[42]=T,e[43]=Q):Q=e[43],Q};function Pg(t){return t.displayMode}function Ig(t){return t.timeFormatPreference}const Ag=({providerId:t,providerName:e})=>{const{t:a}=rt(),[n,i]=o.useState(null),[r,l]=o.useState({}),[h,d]=o.useState(!1),b=`/api/quota/credentials/${t}`;o.useEffect(()=>{dt(b).then(async m=>{if(!m.ok)throw new Error;const E=await m.json();i(E),l({})}).catch(()=>i({configured:!1}))},[b]);const c=async(m,E,v)=>{d(!0);try{const P=await dt(m,{method:E,headers:v?{"Content-Type":"application/json"}:void 0,body:v?JSON.stringify(v):void 0}),x=await P.json().catch(()=>null);if(!P.ok)throw new Error(x?.error);x?.configured!==void 0&&i(x),l({}),D.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(P){D.error(P instanceof Error&&P.message?P.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{d(!1)}},j=(m,E,v)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[E,s.jsx(He,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[m]??"",onChange:P=>l(x=>({...x,[m]:P.target.value})),placeholder:n?.secretMasked??v})]});return s.jsxs("div",{"data-settings-item":`usage.${t}-credentials`,className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t==="ollama-cloud"&&j("cookie",a("settings.providers.page.openCodeGo.authCookie"),"session=..."),t==="cursor"&&j("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&j("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(V,{size:"xs",disabled:h,onClick:()=>c(b,"PUT",r),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(V,{variant:"outline",size:"xs",disabled:h,onClick:()=>c(`${b}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(V,{variant:"outline",size:"xs",disabled:h,onClick:()=>c(`${b}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(V,{variant:"destructive",size:"xs",disabled:h,onClick:()=>c(b,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},To=(t,e)=>{if(!t)return"-";try{return dl(t,e,{fallback:"-"})}catch{return"-"}},Eg=()=>{const{t}=rt(),e=ce(S=>S.timeFormatPreference),a=ls(S=>S.results),n=ls(S=>S.selectedProviderId),i=ls(S=>S.setSelectedProvider),r=ls(S=>S.loadSettings),l=ls(S=>S.fetchAllQuotas),h=ls(S=>S.isLoading),d=ls(S=>S.lastUpdated),b=ls(S=>S.error),c=ls(S=>S.dropdownProviderIds),j=ls(S=>S.setDropdownProviderIds),m=ls(S=>S.selectedModels),E=ls(S=>S.toggleModelSelected),v=ls(S=>S.applyDefaultSelections);jc(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const S=a.find(G=>G.configured)?.providerId;i(S??ri[0]?.id??null)},[a,n,i]);const P=a.find(S=>S.providerId===n)??null,C=ri.find(S=>S.id===n)?.name??n??t("settings.usage.sidebar.title"),u=P?.usage,I=P?.configured&&!P.ok?P.error:null,F=n?c.includes(n):!1,A=n==="ollama-cloud"||n==="cursor",k=o.useCallback(S=>{if(!n)return;const G=S?Array.from(new Set([...c,n])):c.filter(J=>J!==n);j(G),kt({usageDropdownProviders:G})},[c,n,j]),g=o.useMemo(()=>u?.models?Object.entries(u.models).map(([S,G])=>({name:S,windows:G})).filter(S=>Object.keys(S.windows.windows).length>0):[],[u?.models]);o.useEffect(()=>{n&&g.length>0&&v(n,g.map(S=>S.name))},[n,g,v]);const w=o.useMemo(()=>!n||g.length===0?new Map:wc(g,S=>S.name,n),[g,n]),z=o.useMemo(()=>{if(!n)return[];const S=Nc(n);return kc(S)},[n]),[N,R]=o.useState(()=>({})),y=o.useCallback(S=>{R(G=>({...G,[S]:!G[S]}))},[]),O=o.useCallback(S=>{if(!n)return;E(n,S);const G=m[n]??[],T=G.includes(S)?G.filter(Z=>Z!==S):[...G,S],Q={...m,[n]:T};kt({usageSelectedModels:Q})},[n,m,E]),q=n?m[n]??[]:[];return n?s.jsxs(cs,{title:t("settings.usage.page.header.providerUsage",{provider:C}),titleLeading:s.jsx(Kn,{providerId:n,className:"h-5 w-5 shrink-0"}),description:h?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):P?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:P.planLabel,time:To(d,e)}):t("settings.usage.page.header.lastUpdated",{time:To(d,e)}),showSaveStatus:!0,children:[s.jsx(Ue,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(xt,{checked:F,onChange:k,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!P&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(b||I)&&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:b??I})]}),P&&!P.configured&&!A&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="ollama-cloud"||n==="cursor")&&s.jsx(Ag,{providerId:n,providerName:C}),u?.windows&&Object.keys(u.windows).length>0&&s.jsx(Ue,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(u.windows).map(([S,G])=>s.jsx(Ki,{title:S,window:G},S))})}),g.length>0&&s.jsxs(Ue,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[z.map(S=>{const G=w.get(S.id)??[];if(G.length===0)return null;const J=N[S.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Gn,{open:!J,onOpenChange:()=>y(S.id),children:[s.jsxs(qn,{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:S.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",G.length,")"]})]}),J?s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Wn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:G.map(T=>{const Q=Object.entries(T.windows.windows);if(Q.length===0)return null;const[Z,K]=Q[0],ae=q.includes(T.name);return s.jsx(Ki,{title:Z,subtitle:Nr(T.name),window:K,showToggle:!0,toggleEnabled:ae,onToggle:()=>O(T.name)},T.name)})})})]})},S.id)}),(()=>{const S=w.get(null)??[];if(S.length===0)return null;const G=N.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(Gn,{open:!G,onOpenChange:()=>y("other"),children:[s.jsxs(qn,{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:["(",S.length,")"]})]}),G?s.jsx(L,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(Wn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:S.map(J=>{const T=Object.entries(J.windows.windows);if(T.length===0)return null;const[Q,Z]=T[0],K=q.includes(J.name);return s.jsx(Ki,{title:Q,subtitle:Nr(J.name),window:Z,showToggle:!0,toggleEnabled:K,onToggle:()=>O(J.name)},J.name)})})})]})})})()]}),P?.configured&&u&&Object.keys(u.windows??{}).length===0&&g.length===0&&s.jsxs("div",{className:"pb-8",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},Tg="git.commit.generate",ar=vl(t=>({selectedPromptId:Tg,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Dg=t=>{const e=mt.c(23),{onItemSelect:a}=t,{t:n}=rt(),i=ar(Mg),r=ar(Rg);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let h;e[1]===Symbol.for("react.memo_cache_sentinel")?(h={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]=h):h=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=[l,h,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=b):b=e[3];const c=b;let j;e[4]!==n?(j=n("settings.magicPrompts.sidebar.title"),e[4]=n,e[5]=j):j=e[5];let m;e[6]!==j?(m=s.jsx("h2",{className:an,children:j}),e[6]=j,e[7]=m):m=e[7];let E;e[8]!==n?(E=n("settings.magicPrompts.sidebar.description"),e[8]=n,e[9]=E):E=e[9];let v;e[10]!==E?(v=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:E}),e[10]=E,e[11]=v):v=e[11];let P;e[12]!==m||e[13]!==v?(P=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[m,v]}),e[12]=m,e[13]=v,e[14]=P):P=e[14];let x;e[15]!==a||e[16]!==i||e[17]!==r||e[18]!==n?(x=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:c.map(u=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(u.groupKey)}),u.items.map(I=>{const F=i===I.id;return s.jsx("button",{type:"button",onClick:()=>{r(I.id),a?.()},className:ye("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",F?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(I.titleKey)})},I.id)})]},u.groupKey))}),e[15]=a,e[16]=i,e[17]=r,e[18]=n,e[19]=x):x=e[19];let C;return e[20]!==x||e[21]!==P?(C=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[P,x]}),e[20]=x,e[21]=P,e[22]=C):C=e[22],C};function Mg(t){return t.selectedPromptId}function Rg(t){return t.setSelectedPromptId}const Do={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},Mo=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Ui=t=>t.endsWith(".visible"),Og=()=>{const{t}=rt(),e=o.useCallback(k=>t(k),[t]),a=ar(k=>k.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[h,d]=o.useState({}),[b,c]=o.useState({}),[j,m]=o.useState({}),[E,v]=o.useState(!1);o.useEffect(()=>{let k=!0;return(async()=>{i(!0);try{const w=await Ic();if(!k)return;l(w)}catch(w){console.warn("Failed to load magic prompts:",w),D.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{k&&i(!1)}})(),()=>{k=!1}},[t]);const P=Do[a]??Do["git.commit.generate"],x=o.useCallback(k=>Mo(r,k)?r[k]:Pi(k),[r]),C=o.useCallback(k=>h[k]??x(k),[h,x]),u=o.useCallback((k,g)=>{d(w=>w[k]===g?w:{...w,[k]:g})},[]),I=o.useCallback(async k=>{const g=C(k);if(Ui(k)&&g.trim().length===0){D.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}c(w=>({...w,[k]:!0}));try{const w=g===Pi(k)?await Sr(k):await Sc(k,g);l(w.overrides),D.success(t("settings.magicPrompts.page.toast.saved"))}catch(w){const z=w instanceof Error?w.message:String(w);D.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:z})}finally{c(w=>({...w,[k]:!1}))}},[C,t]),F=o.useCallback(async k=>{m(g=>({...g,[k]:!0}));try{const g=await Sr(k);l(g.overrides),d(w=>({...w,[k]:Pi(k)})),D.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(g){const w=g instanceof Error?g.message:String(g);D.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:w})}finally{m(g=>({...g,[k]:!1}))}},[t]),A=o.useCallback(async()=>{v(!0);try{const k=await Cc();l(k.overrides),d({}),D.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(k){const g=k instanceof Error?k.message:String(k);D.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:g})}finally{v(!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(cs,{title:e(P.titleKey),titleAccessory:s.jsx(ts,{contentClassName:"max-w-xs",children:e(P.descriptionKey)}),headerEnd:s.jsx(V,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{A()},disabled:E||Object.keys(r).length===0,children:t(E?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:P.blocks.map((k,g)=>{const w=Pc(k.id),z=x(k.id),N=C(k.id),R=Mo(r,k.id),y=N!==z,O=Ui(k.id)&&N.trim().length===0,q=b[k.id]===!0,S=j[k.id]===!0;return s.jsxs(Ue,{title:e(k.titleKey),info:w.description,description:w.placeholders&&w.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${w.placeholders.map(G=>`{{${G.key}}}`).join(", ")}`:void 0,divider:g>0,settingsItem:Ui(k.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(As,{value:N,onChange:G=>u(k.id,G.target.value),className:"min-h-[220px] font-mono text-sm"}),O&&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(y?"settings.magicPrompts.page.status.unsavedChanges":R?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{variant:"outline",size:"sm",onClick:()=>{F(k.id)},disabled:!R||q||S,children:t(S?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(V,{size:"sm",onClick:()=>{I(k.id)},disabled:!y||q||S||O,children:t(q?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},k.id)})})},Lg=t=>{const e=mt.c(89),{onItemSelect:a}=t,{t:n}=rt(),[i,r]=o.useState(null),[l,h]=o.useState(null),[d,b]=o.useState(null),{selectedSnippetName:c,snippets:j,setSelectedSnippet:m,setSnippetDraft:E,deleteSnippet:v,loadSnippets:P}=li(Ms(Fg));let x,C;e[0]!==P?(x=()=>{P()},C=[P],e[0]=P,e[1]=x,e[2]=C):(x=e[1],C=e[2]),o.useEffect(x,C);let u;e[3]!==a||e[4]!==m||e[5]!==E||e[6]!==j?(u=async()=>{const Se=new Set(j.map(Kg));let Ce="new-snippet",xe=1;for(;Se.has(Ce);)Ce=`new-snippet-${xe++}`;E({name:Ce,scope:"global"}),m(Ce),a?.()},e[3]=a,e[4]=m,e[5]=E,e[6]=j,e[7]=u):u=e[7];const I=u;let F;e[8]!==i||e[9]!==v||e[10]!==n?(F=async()=>{if(!i)return;await v(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]=v,e[10]=n,e[11]=F):F=e[11];const A=F;let k;e[12]!==j?(k=[...j].sort(Ug),e[12]=j,e[13]=k):k=e[13];const g=k;let w;e[14]===Symbol.for("react.memo_cache_sentinel")?(w=ye("flex h-full flex-col","bg-background"),e[14]=w):w=e[14];let z;e[15]!==n?(z=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=z):z=e[16];let N;e[17]!==z?(N=s.jsx("h2",{className:`${an} mb-3`,children:z}),e[17]=z,e[18]=N):N=e[18];let R;e[19]!==j.length||e[20]!==n?(R=n("settings.snippets.sidebar.total",{count:j.length}),e[19]=j.length,e[20]=n,e[21]=R):R=e[21];let y;e[22]!==R?(y=s.jsx("span",{className:"typography-meta text-muted-foreground",children:R}),e[22]=R,e[23]=y):y=e[23];let O;e[24]!==n?(O=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=O):O=e[25];let q;e[26]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),e[26]=q):q=e[26];let S;e[27]!==I||e[28]!==O?(S=s.jsx(V,{size:"sm","data-settings-item":"snippets.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:I,"aria-label":O,children:q}),e[27]=I,e[28]=O,e[29]=S):S=e[29];let G;e[30]!==y||e[31]!==S?(G=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[y,S]}),e[30]=y,e[31]=S,e[32]=G):G=e[32];let J;e[33]!==G||e[34]!==N?(J=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[N,G]}),e[33]=G,e[34]=N,e[35]=J):J=e[35];let T;if(e[36]!==a||e[37]!==l||e[38]!==d||e[39]!==c||e[40]!==m||e[41]!==g||e[42]!==n){let Se;e[44]!==a||e[45]!==l||e[46]!==d||e[47]!==c||e[48]!==m||e[49]!==n?(Se=Ce=>s.jsxs(Hn,{open:d===Ce.name,onOpenChange:xe=>b(xe?Ce.name:null),children:[s.jsxs(Bn,{render:s.jsx("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",c===Ce.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:xe=>{xe.preventDefault(),b(Ce.name)}}),children:[s.jsxs("button",{onClick:()=>{m(Ce.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:["#",Ce.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.${Ce.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:Ce.description||Ce.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(sn,{open:l===Ce.name,onOpenChange:xe=>{xe&&b(null),h(xe?Ce.name:null)},children:[s.jsx(en,{asChild:!0,children:s.jsx(V,{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:Ce.name}),children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(tn,{align:"end",className:"w-fit min-w-20",children:s.jsxs(nn,{onClick:xe=>{xe.stopPropagation(),r(Ce)},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx($n,{className:"w-fit min-w-20",children:s.jsxs(Vn,{onClick:xe=>{xe.stopPropagation(),r(Ce)},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${Ce.source}:${Ce.filePath}`),e[44]=a,e[45]=l,e[46]=d,e[47]=c,e[48]=m,e[49]=n,e[50]=Se):Se=e[50],T=g.map(Se),e[36]=a,e[37]=l,e[38]=d,e[39]=c,e[40]=m,e[41]=g,e[42]=n,e[43]=T}else T=e[43];let Q;e[51]!==T?(Q=s.jsx(Hs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:T}),e[51]=T,e[52]=Q):Q=e[52];const Z=i!==null;let K;e[53]===Symbol.for("react.memo_cache_sentinel")?(K=Se=>{Se||r(null)},e[53]=K):K=e[53];let ae;e[54]!==n?(ae=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=ae):ae=e[55];let _;e[56]!==ae?(_=s.jsx(Jt,{children:ae}),e[56]=ae,e[57]=_):_=e[57];const B=i?.name??"";let M;e[58]!==n||e[59]!==B?(M=n("settings.snippets.sidebar.dialog.deleteDescription",{name:B}),e[58]=n,e[59]=B,e[60]=M):M=e[60];let U;e[61]!==M?(U=s.jsx(Qt,{children:M}),e[61]=M,e[62]=U):U=e[62];let Y;e[63]!==_||e[64]!==U?(Y=s.jsxs(Wt,{children:[_,U]}),e[63]=_,e[64]=U,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 ne;e[67]!==n?(ne=n("settings.common.actions.cancel"),e[67]=n,e[68]=ne):ne=e[68];let te;e[69]!==ne?(te=s.jsx(V,{size:"sm",variant:"ghost",onClick:X,children:ne}),e[69]=ne,e[70]=te):te=e[70];let ge;e[71]!==n?(ge=n("settings.common.actions.delete"),e[71]=n,e[72]=ge):ge=e[72];let ee;e[73]!==A||e[74]!==ge?(ee=s.jsx(V,{size:"sm",onClick:A,children:ge}),e[73]=A,e[74]=ge,e[75]=ee):ee=e[75];let le;e[76]!==te||e[77]!==ee?(le=s.jsxs(ds,{children:[te,ee]}),e[76]=te,e[77]=ee,e[78]=le):le=e[78];let pe;e[79]!==Y||e[80]!==le?(pe=s.jsxs(Bt,{className:"max-w-md",children:[Y,le]}),e[79]=Y,e[80]=le,e[81]=pe):pe=e[81];let ie;e[82]!==Z||e[83]!==pe?(ie=s.jsx(Vt,{open:Z,onOpenChange:K,children:pe}),e[82]=Z,e[83]=pe,e[84]=ie):ie=e[84];let je;return e[85]!==J||e[86]!==Q||e[87]!==ie?(je=s.jsxs("div",{className:w,children:[J,Q,ie]}),e[85]=J,e[86]=Q,e[87]=ie,e[88]=je):je=e[88],je};function Fg(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function Kg(t){return t.name}function Ug(t,e){return t.name.localeCompare(e.name)}const zg=()=>{const{t}=rt(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=li(Ms(w=>({selectedSnippetName:w.selectedSnippetName,snippets:w.snippets,snippetDraft:w.snippetDraft,setSnippetDraft:w.setSnippetDraft,updateSnippet:w.updateSnippet,createSnippet:w.createSnippet}))),h=o.useMemo(()=>e?a.find(w=>w.name===e||w.aliases.includes(e))??null:null,[e,a]),d=!!(n&&n.name===e&&!h),[b,c]=o.useState(""),[j,m]=o.useState("global"),[E,v]=o.useState(""),[P,x]=o.useState(""),[C,u]=o.useState(""),[I,F]=o.useState(!1),A=o.useRef(null);o.useEffect(()=>{if(d&&n){const w={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};c(w.draftName),m(w.draftScope),v(w.description),x(w.aliases),u(w.content),A.current=w}else if(h){const w={draftName:"",draftScope:"global",description:h.description??"",aliases:h.aliases.join(", "),content:h.content};v(w.description),x(w.aliases),u(w.content),A.current=w}},[h,d,e,n]);const k=o.useMemo(()=>{const w=A.current;return w?d&&b!==w.draftName||d&&j!==w.draftScope?!0:E!==w.description||P!==w.aliases||C!==w.content:!1},[P,C,E,b,j,d]),g=async()=>{const w=d?b.trim().replace(/\s+/g,"-"):e?.trim();if(!w){D.error(t("settings.snippets.page.toast.nameRequired"));return}if(!C.trim()){D.error(t("settings.snippets.page.toast.contentRequired"));return}const z=P.split(",").map(N=>N.trim()).filter(Boolean);F(!0);try{if(!(d?await l(w,C,{aliases:z,description:E,scope:j}):await r(w,{content:C,aliases:z,description:E}))){D.error(t("settings.snippets.page.toast.saveFailed"));return}D.success(t("settings.snippets.page.toast.saved")),d&&i(null)}finally{F(!1)}};return e?s.jsxs(cs,{title:d?t("settings.snippets.page.title.new"):`#${e}`,description:h?h.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(Ue,{divider:!1,contentClassName:"space-y-0",children:[d?s.jsxs(Yt,{label:"#",children:[s.jsx(He,{value:b,onChange:w=>c(w.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Lt,{value:j,onValueChange:w=>m(w),children:[s.jsx(Ft,{size:qt,className:"w-fit min-w-[100px]",children:s.jsx($t,{})}),s.jsxs(Kt,{align:"end",children:[s.jsx(pt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(pt,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(Zt,{label:t("settings.common.field.description"),children:s.jsx(He,{value:E,onChange:w=>v(w.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(Zt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(He,{value:P,onChange:w=>x(w.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(Ue,{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(ts,{children:t("settings.snippets.page.hint")})]}),s.jsx(As,{value:C,onChange:w=>u(w.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(V,{onClick:g,disabled:I||!k,size:"xs",className:"!font-normal",children:t(I?"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(L,{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")})]})})},Ol=()=>{const{t}=rt(),e=st(j=>j.settingsGitmojiEnabled),a=st(j=>j.setSettingsGitmojiEnabled),n=id(),i=ce(j=>j.gitChangesViewMode),r=ce(j=>j.setGitChangesViewMode),[l,h]=o.useState(!0),d=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 m=null;if(!m){const E=An()?.settings;if(E)try{const P=(await E.load())?.settings;P&&(m={gitmojiEnabled:typeof P.gitmojiEnabled=="boolean"?P.gitmojiEnabled:void 0,gitChangesViewMode:P.gitChangesViewMode==="flat"||P.gitChangesViewMode==="tree"?P.gitChangesViewMode:void 0})}catch{}}if(!m){const E=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});E.ok&&(m=await E.json())}m&&(typeof m.gitmojiEnabled=="boolean"&&a(m.gitmojiEnabled),(m.gitChangesViewMode==="flat"||m.gitChangesViewMode==="tree")&&r(m.gitChangesViewMode))}catch(m){console.warn("Failed to load git settings:",m)}finally{h(!1)}})()},[r,a]);const b=o.useCallback(async j=>{a(j);try{await kt({gitmojiEnabled:j})}catch(m){console.warn("Failed to save gitmoji setting:",m)}},[a]),c=o.useCallback(j=>{j!==i&&(r(j),kt({gitChangesViewMode:j}))},[i,r]);return l?null:s.jsx(Ue,{title:t("settings.openchamber.git.title"),children:s.jsxs("div",{className:Ss,children:[s.jsx(Js,{settingsItem:"git.changes-view",title:t("settings.openchamber.git.changesViewTitle"),children:s.jsx(wn,{"aria-label":t("settings.openchamber.git.changesViewAria"),children:d.map(j=>s.jsx(kn,{selected:i===j.id,onSelect:()=>{c(j.id)},label:j.label,ariaLabel:t("settings.openchamber.git.optionAria",{option:j.label})},j.id))})}),s.jsx(xt,{settingsItem:"git.gitmoji",checked:e,onChange:j=>{b(j)},label:t("settings.openchamber.git.enableGitmoji"),ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx(xt,{settingsItem:"git.gitignored-files",checked:n,onChange:rd,label:t("settings.openchamber.git.showGitignored"),ariaLabel:t("settings.openchamber.git.showGitignoredAria")})]})})},Ll=()=>{const{t}=rt(),{isMobile:e}=oa(),a=An()?.github,n=xa(y=>y.status),i=xa(y=>y.isLoading),r=xa(y=>y.hasChecked),l=xa(y=>y.refreshStatus),h=xa(y=>y.setStatus),d=o.useCallback(async y=>{await En(y)},[]),[b,c]=o.useState(!1),[j,m]=o.useState(null),[E,v]=o.useState(null),P=o.useRef(null),x=o.useCallback(()=>{P.current!=null&&(window.clearInterval(P.current),P.current=null),v(null)},[]);o.useEffect(()=>((async()=>{try{r||await l(a)}catch(y){console.warn("Failed to load GitHub auth status:",y)}})(),()=>{x()}),[r,l,a,x]);const C=o.useCallback(async()=>{c(!0);try{const y=a?await a.authStart():await(async()=>{const q=await dt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),S=await q.json().catch(()=>null);if(!q.ok||!S||!("deviceCode"in S))throw new Error(S?.error||q.statusText);return S})();m(y),v(Math.max(1,y.interval)*1e3);const O=y.verificationUriComplete||y.verificationUri;d(O)}catch(y){console.error("Failed to start GitHub connect:",y),D.error(t("settings.github.page.toast.startConnectFailed"))}finally{c(!1)}},[d,a,t]),u=o.useCallback(async y=>{if(a)return a.authComplete(y);const O=await dt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:y})}),q=await O.json().catch(()=>null);if(!O.ok||!q)throw new Error(q?.error||O.statusText);return q},[a]);o.useEffect(()=>{if(!(!j?.deviceCode||!E)&&P.current==null)return P.current=window.setInterval(()=>{(async()=>{try{const y=await u(j.deviceCode);if(y.connected){D.success(t("settings.github.page.toast.connected")),m(null),x(),await l(a,{force:!0});return}y.status==="slow_down"&&v(O=>O?O+5e3:5e3),(y.status==="expired_token"||y.status==="access_denied")&&(D.error(y.error||t("settings.github.page.toast.authorizationFailed")),m(null),x())}catch(y){console.warn("GitHub polling failed:",y)}})()},E),()=>{P.current!=null&&(window.clearInterval(P.current),P.current=null)}},[j,E,u,l,a,x,t]);const I=o.useCallback(async y=>{c(!0);try{if(a)await a.authSetGhCliDisabled(y);else{const O=await dt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:y})}),q=await O.json().catch(()=>null);if(!O.ok)throw new Error(q?.error||O.statusText)}D.success(t(y?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await l(a,{force:!0})}catch(O){console.error("Failed to update gh CLI setting:",O),D.error(t("settings.github.page.toast.ghCliUpdateFailed"))}finally{c(!1)}},[l,a,t]),F=o.useCallback(async()=>{c(!0);try{if(x(),m(null),a)await a.authDisconnect();else{const y=await dt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!y.ok)throw new Error(y.statusText)}D.success(t("settings.github.page.toast.disconnected")),await l(a,{force:!0})}catch(y){console.error("Failed to disconnect GitHub:",y),D.error(t("settings.github.page.toast.disconnectFailed"))}finally{c(!1)}},[l,a,x,t]),A=o.useCallback(async y=>{if(y){c(!0);try{const O=a?await a.authActivate(y):await(async()=>{const q=await dt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:y})}),S=await q.json().catch(()=>null);if(!q.ok||!S)throw new Error(S?.error||q.statusText);return S})();h(O),D.success(t("settings.github.page.toast.accountSwitched"))}catch(O){console.error("Failed to switch GitHub account:",O),D.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{c(!1)}}},[a,h,t]);if(i)return null;const k=!!n?.connected,g=n?.user,z=(n?.accounts??[]).filter(y=>!y.current),N=n?.ghCli??null,R=N?.active?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth");return s.jsxs(s.Fragment,{children:[s.jsxs(Ue,{title:t("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:t("settings.github.page.tooltip.connectAccount"),children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[k?s.jsxs("div",{className:ye("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[g?.avatarUrl?s.jsx("img",{src:g.avatarUrl,alt:g.login?t("settings.github.page.avatarAlt.withLogin",{login:g.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:g?.name?.trim()||g?.login||"GitHub"}),s.jsxs("div",{className:ye("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(L,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:g?.login||t("settings.github.page.label.unknownUser")}),g?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),g?.email&&s.jsx("span",{children:g.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:R})]}),n?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:n.scope})}),N?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.ghCli.activeDescription")})]})]}),N?.active?s.jsx(V,{size:"sm",variant:"outline",onClick:()=>I(!0),disabled:b,className:ye(e?"w-full":void 0),children:t("settings.github.page.ghCli.actions.disable")}):s.jsx(V,{size:"sm",variant:"outline",onClick:F,disabled:b,className:ye("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(V,{size:"sm",variant:"default",onClick:C,disabled:b,children:t("settings.github.page.actions.connect")})]}),z.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:z.map(y=>{const O=y.user,q=y.source==="gh-cli"?t("settings.github.page.accountSource.cli"):t("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[O?.avatarUrl?s.jsx("img",{src:O.avatarUrl,alt:O.login?t("settings.github.page.avatarAlt.withLogin",{login:O.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(L,{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:O?.name?.trim()||O?.login||"GitHub"}),O?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:O.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:q})]})]})]}),s.jsx(V,{size:"sm",variant:"ghost",onClick:()=>A(y.id),disabled:b,children:t("settings.github.page.actions.switchTo")})]},y.id)})})]})]}),k&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(V,{size:"sm",variant:"outline",onClick:C,disabled:b,className:ye(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),j&&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(Xs,{children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:j.userCode}),s.jsx(V,{size:"sm",asChild:!0,children:s.jsx("a",{href:j.verificationUriComplete||j.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(V,{size:"sm",variant:"ghost",disabled:b,onClick:()=>{x(),m(null)},children:t("settings.common.actions.cancel")})]})]})]}),N?.available&&!N?.active&&(!N.user||N.disabled)&&s.jsx(Ue,{title:t("settings.github.page.ghCli.title"),children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:ye("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:ye("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[N.user?.avatarUrl?s.jsx("img",{src:N.user.avatarUrl,alt:N.user.login?t("settings.github.page.avatarAlt.withLogin",{login:N.user.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(L,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!N.disabled&&N.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:N.user.name?.trim()||N.user.login||"GitHub"}),!N.disabled&&N.user?.login&&s.jsxs("div",{className:ye("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(L,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:N.user.login}),N.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),N.user.email&&s.jsx("span",{children:N.user.email})]}),s.jsx("div",{className:ye("typography-meta text-muted-foreground",N.disabled?"opacity-60":void 0),children:N.disabled?t("settings.github.page.ghCli.disabledDescription"):t("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(V,{size:"sm",variant:"outline",onClick:()=>I(!N.disabled),disabled:b,className:ye(e?"w-full":void 0),children:N.disabled?t("settings.github.page.ghCli.actions.enable"):t("settings.github.page.ghCli.actions.disable")})]})})})]})},Ro=[{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)"}],_g=[{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"}],$g=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=rt(),r=Un(U=>U.getProfileById),l=Un(U=>U.createProfile),h=Un(U=>U.updateProfile),d=Un(U=>U.deleteProfile),b=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),c=a==="new"||n!=null,j=a==="global",[m,E]=o.useState(""),[v,P]=o.useState(""),[x,C]=o.useState(""),[u,I]=o.useState("ssh"),[F,A]=o.useState(""),[k,g]=o.useState(!1),[w,z]=o.useState(""),[N,R]=o.useState(""),[y,O]=o.useState("keyword"),[q,S]=o.useState("branch"),[G,J]=o.useState(!1),[T,Q]=o.useState(!1),[Z,K]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const U=n.host.split("/"),Y=U.length>=3?U[U.length-1]:n.host;E(Y),P(n.username),C(""),I("token"),A(""),g(!1),z(""),R(n.host),O("string"),S("code")}else if(c)E(""),P(""),C(""),I("ssh"),A(""),g(!1),z(""),R(""),O("keyword"),S("branch");else if(b)E(b.name),P(b.userName),C(b.userEmail),I(b.authType||"ssh"),A(b.sshKey||""),g(b.signCommits===!0),z(b.signingKey||""),R(b.host||""),O(b.color||"keyword"),S(b.icon||"branch");else if(j){const U=r("global");U&&(E(U.name),P(U.userName),C(U.userEmail),I(U.authType||"ssh"),A(U.sshKey||""),g(!1),z(""),R(U.host||""),O(U.color||"keyword"),S(U.icon||"branch"))}}},[t,a,b,c,n,j,r]);const ae=async()=>{if(!v.trim()||!x.trim()){D.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(u==="token"&&!N.trim()){D.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(k&&!w.trim()){D.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}J(!0);try{const U={name:m.trim()||v.trim(),userName:v.trim(),userEmail:x.trim(),authType:u,sshKey:u==="ssh"&&F.trim()||null,signCommits:k,signingKey:w.trim()||null,host:u==="token"&&N.trim()||null,color:y,icon:q};let Y;if(c)Y=await l(U);else if(a)Y=await h(a,U);else return;Y?(D.success(i(c?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):D.error(i(c?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(U){console.error("Error saving profile:",U),D.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{J(!1)}},_=async()=>{if(!(!a||c)){K(!0);try{await d(a)?(D.success(i("settings.gitIdentities.editor.toast.profileDeleted")),Q(!1),e(!1)):D.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(U){console.error("Error deleting profile:",U),D.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{K(!1)}}},B=o.useMemo(()=>Ro.find(Y=>Y.key===y)?.cssVar||"var(--syntax-keyword)",[y]),M=n?i("settings.gitIdentities.editor.title.importCredential"):c?i("settings.gitIdentities.editor.title.newIdentity"):j?i("settings.gitIdentities.editor.title.globalIdentity"):b?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Vt,{open:t,onOpenChange:e,children:s.jsxs(Bt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:M}),s.jsx(Qt,{children:i(j?"settings.gitIdentities.editor.description.globalReadOnly":c?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!j&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Ot} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(He,{value:m,onChange:U=>E(U.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:Ro.map(U=>s.jsx("button",{type:"button",onClick:()=>O(U.key),className:ye("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",y===U.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:U.cssVar},title:U.label},U.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:_g.map(U=>{const Y=U.Icon;return s.jsx("button",{type:"button",onClick:()=>S(U.key),className:ye("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",q===U.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:U.label,children:s.jsx(L,{name:Y,className:"w-3.5 h-3.5",style:{color:q===U.key?B:"var(--surface-muted-foreground)"}})},U.key)})})]})]}),!j&&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:Ot,children:i("settings.gitIdentities.editor.field.userName")}),!j&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(ts,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(He,{value:v,onChange:U=>P(U.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!j,readOnly:j,disabled:j,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:Ot,children:i("settings.gitIdentities.editor.field.emailAddress")}),!j&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(ts,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(He,{type:"email",value:x,onChange:U=>C(U.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!j,readOnly:j,disabled:j,className:"h-8"})]})]}),!j&&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(V,{size:"sm",type:"button",variant:"chip","aria-pressed":u==="ssh",onClick:()=>I("ssh"),children:[s.jsx(L,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(V,{size:"sm",type:"button",variant:"chip","aria-pressed":u==="token",onClick:()=>I("token"),children:[s.jsx(L,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),u==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Ot,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(ts,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(He,{value:F,onChange:U=>A(U.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(xt,{checked:k,onChange:g,label:i("settings.gitIdentities.editor.field.signCommits"),info:i("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:i("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Ot,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(He,{value:w,onChange:U=>z(U.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!k,className:"h-8 font-mono text-xs"})]})]}),u==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Ot,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(ts,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(He,{value:N,onChange:U=>R(U.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(ds,{className:"gap-2",children:[!j&&!c&&s.jsxs(V,{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(L,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.common.actions.delete")]}),s.jsx(V,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:i(j?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!j&&s.jsx(V,{size:"sm",onClick:ae,disabled:G,children:i(G?"settings.common.actions.saving":c?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Vt,{open:T,onOpenChange:U=>{Z||Q(U)},children:s.jsxs(Bt,{className:"max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Qt,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:b?.name||m})})]}),s.jsxs(ds,{children:[s.jsx(V,{variant:"ghost",onClick:()=>Q(!1),disabled:Z,children:i("settings.common.actions.cancel")}),s.jsx(V,{size:"sm",variant:"destructive",onClick:()=>{_()},disabled:Z,children:i("settings.common.actions.delete")})]})]})})]})},Vg={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},Bg={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},Hg=()=>{const t=mt.c(113),{t:e}=rt(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:h,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:b,setDefaultGitIdentityId:c,getUnimportedCredentials:j}=Un(Ms(qg)),[m,E]=o.useState(!1),[v,P]=o.useState(null),[x,C]=o.useState(null),[u,I]=o.useState(null),[F,A]=o.useState(!1);let k,g;t[0]!==b||t[1]!==d||t[2]!==h||t[3]!==l?(k=()=>{l(),h(),d(),b()},g=[l,h,d,b],t[0]=b,t[1]=d,t[2]=h,t[3]=l,t[4]=k,t[5]=g):(k=t[4],g=t[5]),o.useEffect(k,g);let w,z,N,R,y,O,q,S,G,J,T,Q,Z,K;if(t[6]!==i||t[7]!==u||t[8]!==r||t[9]!==j||t[10]!==n||t[11]!==a||t[12]!==c||t[13]!==e){const _e=j();let Le;t[28]===Symbol.for("react.memo_cache_sentinel")?(Le=(Me,ve)=>{P(Me),C(ve??null),E(!0)},t[28]=Le):Le=t[28];const qe=Le;let Ke;t[29]!==i||t[30]!==c||t[31]!==e?(Ke=async Me=>{const ve=i===Me?null:Me;if(!await c(ve)){D.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}D.success(e(ve?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=c,t[31]=e,t[32]=Ke):Ke=t[32];const Xe=Ke;let We;t[33]!==u||t[34]!==r||t[35]!==e?(We=async()=>{if(!u)return;A(!0),await r(u.id)?(D.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:u.name})),I(null)):D.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),A(!1)},t[33]=u,t[34]=r,t[35]=e,t[36]=We):We=t[36],N=We,z=cs,t[37]!==e?(R=e("settings.page.git.title"),t[37]=e,t[38]=R):R=t[38],y=!0,t[39]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(Ll,{}),t[39]=O):O=t[39],w=Ue,t[40]!==e?(Q=e("settings.gitIdentities.page.section.title"),t[40]=e,t[41]=Q):Q=t[41];let Ze,we;t[42]===Symbol.for("react.memo_cache_sentinel")?(Ze=()=>qe("new"),we=s.jsx(L,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[42]=Ze,t[43]=we):(Ze=t[42],we=t[43]);let Je;t[44]!==e?(Je=e("settings.common.badge.new"),t[44]=e,t[45]=Je):Je=t[45],t[46]!==Je?(Z=s.jsxs(V,{size:"sm",variant:"outline",onClick:Ze,children:[we," ",Je]}),t[46]=Je,t[47]=Z):Z=t[47],K="git.identities",q="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",S=n&&s.jsx(Oo,{profile:n,isDefault:i==="global",onEdit:()=>qe("global"),onToggleDefault:()=>Xe("global"),isReadOnly:!0,hasBorder:a.length>0||_e.length>0}),G=a.map((Me,ve)=>s.jsx(Oo,{profile:Me,isDefault:i===Me.id,onEdit:()=>qe(Me.id),onToggleDefault:()=>Xe(Me.id),onDelete:()=>I(Me),hasBorder:ve<a.length-1||_e.length>0},Me.id)),J=!n&&a.length===0&&_e.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(L,{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")})]}),T=_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((Me,ve)=>s.jsx(Gg,{credential:Me,onImport:()=>qe("new",{host:Me.host,username:Me.username}),hasBorder:ve<_e.length-1},`${Me.host}-${Me.username}`))]}),t[6]=i,t[7]=u,t[8]=r,t[9]=j,t[10]=n,t[11]=a,t[12]=c,t[13]=e,t[14]=w,t[15]=z,t[16]=N,t[17]=R,t[18]=y,t[19]=O,t[20]=q,t[21]=S,t[22]=G,t[23]=J,t[24]=T,t[25]=Q,t[26]=Z,t[27]=K}else w=t[14],z=t[15],N=t[16],R=t[17],y=t[18],O=t[19],q=t[20],S=t[21],G=t[22],J=t[23],T=t[24],Q=t[25],Z=t[26],K=t[27];let ae;t[48]!==q||t[49]!==S||t[50]!==G||t[51]!==J||t[52]!==T?(ae=s.jsxs("div",{className:q,children:[S,G,J,T]}),t[48]=q,t[49]=S,t[50]=G,t[51]=J,t[52]=T,t[53]=ae):ae=t[53];let _;t[54]!==w||t[55]!==ae||t[56]!==Q||t[57]!==Z||t[58]!==K?(_=s.jsx(w,{title:Q,headerAction:Z,settingsItem:K,children:ae}),t[54]=w,t[55]=ae,t[56]=Q,t[57]=Z,t[58]=K,t[59]=_):_=t[59];let B;t[60]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Ol,{}),t[60]=B):B=t[60];let M;t[61]!==z||t[62]!==R||t[63]!==y||t[64]!==O||t[65]!==_?(M=s.jsxs(z,{title:R,showSaveStatus:y,children:[O,_,B]}),t[61]=z,t[62]=R,t[63]=y,t[64]=O,t[65]=_,t[66]=M):M=t[66];let U;t[67]!==x||t[68]!==m||t[69]!==v?(U=s.jsx($g,{open:m,onOpenChange:E,profileId:v,importData:x}),t[67]=x,t[68]=m,t[69]=v,t[70]=U):U=t[70];const Y=u!==null;let X;t[71]!==F?(X=_e=>{F||_e||I(null)},t[71]=F,t[72]=X):X=t[72];let ne;t[73]!==e?(ne=e("settings.gitIdentities.page.deleteDialog.title"),t[73]=e,t[74]=ne):ne=t[74];let te;t[75]!==ne?(te=s.jsx(Jt,{children:ne}),t[75]=ne,t[76]=te):te=t[76];const ge=u?.name??"";let ee;t[77]!==e||t[78]!==ge?(ee=e("settings.gitIdentities.page.deleteDialog.description",{name:ge}),t[77]=e,t[78]=ge,t[79]=ee):ee=t[79];let le;t[80]!==ee?(le=s.jsx(Qt,{children:ee}),t[80]=ee,t[81]=le):le=t[81];let pe;t[82]!==te||t[83]!==le?(pe=s.jsxs(Wt,{children:[te,le]}),t[82]=te,t[83]=le,t[84]=pe):pe=t[84];let ie;t[85]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>I(null),t[85]=ie):ie=t[85];let je;t[86]!==e?(je=e("settings.common.actions.cancel"),t[86]=e,t[87]=je):je=t[87];let Se;t[88]!==F||t[89]!==je?(Se=s.jsx(V,{variant:"ghost",onClick:ie,disabled:F,children:je}),t[88]=F,t[89]=je,t[90]=Se):Se=t[90];let Ce;t[91]!==N?(Ce=()=>{N()},t[91]=N,t[92]=Ce):Ce=t[92];let xe;t[93]!==e?(xe=e("settings.common.actions.delete"),t[93]=e,t[94]=xe):xe=t[94];let Re;t[95]!==F||t[96]!==Ce||t[97]!==xe?(Re=s.jsx(V,{size:"sm",variant:"destructive",onClick:Ce,disabled:F,children:xe}),t[95]=F,t[96]=Ce,t[97]=xe,t[98]=Re):Re=t[98];let Oe;t[99]!==Se||t[100]!==Re?(Oe=s.jsxs(ds,{children:[Se,Re]}),t[99]=Se,t[100]=Re,t[101]=Oe):Oe=t[101];let fe;t[102]!==pe||t[103]!==Oe?(fe=s.jsxs(Bt,{className:"max-w-md",children:[pe,Oe]}),t[102]=pe,t[103]=Oe,t[104]=fe):fe=t[104];let be;t[105]!==Y||t[106]!==X||t[107]!==fe?(be=s.jsx(Vt,{open:Y,onOpenChange:X,children:fe}),t[105]=Y,t[106]=X,t[107]=fe,t[108]=be):be=t[108];let De;return t[109]!==M||t[110]!==U||t[111]!==be?(De=s.jsxs(s.Fragment,{children:[M,U,be]}),t[109]=M,t[110]=U,t[111]=be,t[112]=De):De=t[112],De},Oo=t=>{const e=mt.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:h,hasBorder:d}=t,{t:b}=rt(),[c,j]=o.useState(!1),m=Vg[a.icon||"branch"]||"git-branch",E=Bg[a.color||""],v=a.authType||"ssh";let P;e[0]!==i?(P=_=>{_.currentTarget===_.target&&(_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),i()))},e[0]=i,e[1]=P):P=e[1];const x=P;let C;e[2]!==n||e[3]!==h||e[4]!==l||e[5]!==r||e[6]!==b?(C=_=>s.jsxs(s.Fragment,{children:[s.jsx(_,{onClick:B=>{B.stopPropagation(),r()},children:b(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!h&&l&&s.jsxs(_,{onClick:B=>{B.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(L,{name:"delete-bin",className:"h-4 w-4 mr-px"}),b("settings.common.actions.delete")]})]}),e[2]=n,e[3]=h,e[4]=l,e[5]=r,e[6]=b,e[7]=C):C=e[7];const u=C,I=d&&"border-b border-[var(--surface-subtle)]";let F;e[8]!==I?(F=ye("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",I),e[8]=I,e[9]=F):F=e[9];let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=_=>{_.preventDefault(),j(!0)},e[10]=A):A=e[10];let k;e[11]!==x||e[12]!==i||e[13]!==F?(k=s.jsx("div",{className:F,onClick:i,role:"button",tabIndex:0,onKeyDown:x,onContextMenu:A}),e[11]=x,e[12]=i,e[13]=F,e[14]=k):k=e[14];let g;e[15]!==E?(g={color:E},e[15]=E,e[16]=g):g=e[16];let w;e[17]!==m||e[18]!==g?(w=s.jsx(L,{name:m,className:"w-4 h-4 shrink-0",style:g}),e[17]=m,e[18]=g,e[19]=w):w=e[19];let z;e[20]!==a.name?(z=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=z):z=e[21];let N;e[22]!==v?(N=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:v}),e[22]=v,e[23]=N):N=e[23];let R;e[24]!==n||e[25]!==b?(R=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:b("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=b,e[26]=R):R=e[26];let y;e[27]!==h||e[28]!==b?(y=h&&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:b("settings.agents.sidebar.badge.system")}),e[27]=h,e[28]=b,e[29]=y):y=e[29];let O;e[30]!==N||e[31]!==R||e[32]!==y||e[33]!==z?(O=s.jsxs("div",{className:"flex items-center gap-1.5",children:[z,N,R,y]}),e[30]=N,e[31]=R,e[32]=y,e[33]=z,e[34]=O):O=e[34];const q=v==="token"&&a.host?a.host:a.userEmail;let S;e[35]!==q?(S=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:q}),e[35]=q,e[36]=S):S=e[36];let G;e[37]!==O||e[38]!==S?(G=s.jsxs("div",{className:"min-w-0",children:[O,S]}),e[37]=O,e[38]=S,e[39]=G):G=e[39];let J;e[40]!==G||e[41]!==w?(J=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[w,G]}),e[40]=G,e[41]=w,e[42]=J):J=e[42];let T;e[43]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(en,{asChild:!0,children:s.jsx(V,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:Wg,children:s.jsx(L,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=T):T=e[43];let Q;e[44]!==u?(Q=s.jsxs(sn,{children:[T,s.jsx(tn,{align:"end",className:"w-fit min-w-28",children:u(nn)})]}),e[44]=u,e[45]=Q):Q=e[45];let Z;e[46]!==J||e[47]!==Q||e[48]!==k?(Z=s.jsxs(Bn,{render:k,children:[J,Q]}),e[46]=J,e[47]=Q,e[48]=k,e[49]=Z):Z=e[49];let K;e[50]!==u?(K=s.jsx($n,{className:"w-fit min-w-28",children:u(Vn)}),e[50]=u,e[51]=K):K=e[51];let ae;return e[52]!==c||e[53]!==Z||e[54]!==K?(ae=s.jsxs(Hn,{open:c,onOpenChange:j,children:[Z,K]}),e[52]=c,e[53]=Z,e[54]=K,e[55]=ae):ae=e[55],ae},Gg=t=>{const e=mt.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=rt();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const h=l,d=h.length>=3?h[h.length-1]:a.host,b=a.host.includes("/"),c=i&&"border-b border-[var(--surface-subtle)]";let j;e[2]!==c?(j=ye("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",c),e[2]=c,e[3]=j):j=e[3];let m;e[4]!==d?(m=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=m):m=e[5];const E=b?a.host:a.username;let v;e[6]!==E?(v=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:E}),e[6]=E,e[7]=v):v=e[7];let P;e[8]!==m||e[9]!==v?(P=s.jsxs("div",{className:"min-w-0",children:[m,v]}),e[8]=m,e[9]=v,e[10]=P):P=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(L,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let C;e[12]!==r?(C=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=C):C=e[13];let u;e[14]!==n||e[15]!==C?(u=s.jsxs(V,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[x,C]}),e[14]=n,e[15]=C,e[16]=u):u=e[16];let I;return e[17]!==u||e[18]!==j||e[19]!==P?(I=s.jsxs("div",{className:j,children:[P,u]}),e[17]=u,e[18]=j,e[19]=P,e[20]=I):I=e[20],I};function qg(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 Wg(t){return t.stopPropagation()}const zi=[{id:"opencode-claude",packageName:"@openchamber/opencode-claude",providerId:"claude-code",icon:"claude-code",brandClassName:"text-[#D97757]",nameKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",homepage:"https://github.com/openchamber/opencode-claude"},{id:"opencode-cursor-oauth",packageName:"@openchamber/opencode-cursor",providerId:"cursor",icon:"cursor",brandClassName:"text-foreground",nameKey:"settings.integrations.thirdParty.opencodeCursorOauth.name",descriptionKey:"settings.integrations.thirdParty.opencodeCursorOauth.description",homepage:"https://github.com/openchamber/opencode-cursor"}],Jg=(t,e)=>t===e||t.startsWith(`${e}@`);function _i(t,e,a){const n=t.filter(d=>Jg(d.spec,e)),i=n.filter(d=>d.scope==="user"),r=n.filter(d=>d.scope==="project"),l=i.length===1?i[0]:null,h=a[l?.spec??e]??a[e]??null;return{userEntry:l,userEntryIsAmbiguous:i.length>1,projectEntries:r,registry:h}}function ir(t,e){return e?.kind!=="npm-ok"||e.name!==t||!e.latestVersion?null:`${t}@${e.latestVersion}`}function Lo(t,e){if(t.userEntryIsAmbiguous)return"manage";if(!t.userEntry)return"install";const a=ir(e,t.registry);return a&&a!==t.userEntry.spec?"update":"setup"}function Qg(t,e={}){const a=t.registry?.kind==="npm-ok"?t.registry.latestVersion:null;return t.userEntryIsAmbiguous?{status:"ambiguous",latestVersion:a}:e.restartRequired?{status:"restart-required",latestVersion:a}:e.providerUnavailable?{status:"provider-unavailable",latestVersion:a}:e.registryUnavailable?{status:"registry-unavailable",latestVersion:a}:t.userEntry?t.registry?.kind==="npm-ok"&&t.registry.currentVersion===t.registry.latestVersion?{status:"installed-version",latestVersion:a}:t.registry?.kind==="npm-ok"&&t.registry.currentVersion===null?{status:"unpinned",latestVersion:a}:t.registry?.kind==="npm-ok"&&a?{status:"update-available",latestVersion:a}:{status:"installed",latestVersion:a}:{status:"not-installed",latestVersion:a}}const Yg=t=>t.restartDeferred===!0||t.requiresManualRestart===!0||t.reloadFailed===!0,Zg=({divider:t=!0,onOpenProviderSetup:e,onOpenPluginManager:a})=>{const{t:n}=rt(),{entries:i,registryInfo:r,loadPlugins:l,loadRegistryInfo:h,createEntry:d,updateEntry:b,deleteEntry:c}=gs(Ms(T=>({entries:T.entries,registryInfo:T.registryInfo,loadPlugins:T.loadPlugins,loadRegistryInfo:T.loadRegistryInfo,createEntry:T.createEntry,updateEntry:T.updateEntry,deleteEntry:T.deleteEntry}))),[j,m]=o.useState(!1),[E,v]=o.useState(null),[P,x]=o.useState(()=>new Set),[C,u]=o.useState(()=>new Set),[I,F]=o.useState(null),[A,k]=o.useState(()=>new Set),g=o.useCallback(async()=>{if(!await l({force:!0})){m(!0);return}const Q=gs.getState().entries,Z=new Set(zi.map(ae=>ae.packageName));for(const ae of Q)zi.some(_=>ae.spec===_.packageName||ae.spec.startsWith(`${_.packageName}@`))&&Z.add(ae.spec);const K=await h({specs:[...Z],force:!0});m(!K)},[l,h]);o.useEffect(()=>{g()},[g]);const w=pn(T=>T.changes.filter(Q=>Q.scope==="plugins").length),z=pn(T=>T.isApplying),N=o.useRef(w);o.useEffect(()=>{const T=N.current;N.current=w,!z&&(T<=0||w>0||(x(new Set),u(new Set),g()))},[z,w,g]);const R=o.useCallback((T,Q)=>{x(Z=>{const K=new Set(Z);return Q?K.add(T):K.delete(T),K})},[]),y=o.useCallback((T,Q)=>{u(Z=>{const K=new Set(Z);return Q?K.add(T):K.delete(T),K})},[]),O=o.useCallback(async(T,Q,Z)=>{v({pluginId:T.id,action:Q});try{const K=await Z();if(!K.ok){D.error(n("settings.integrations.thirdParty.toast.actionFailed"));return}y(T.id,!1);const ae=Yg(K);R(T.id,ae);const _=ae?{description:n("settings.integrations.thirdParty.toast.restartRequired")}:void 0;Q==="install"?D.success(n("settings.integrations.thirdParty.toast.installed",{name:n(T.nameKey)}),_):Q==="update"?D.success(n("settings.integrations.thirdParty.toast.updated",{name:n(T.nameKey)}),_):D.success(n("settings.integrations.thirdParty.toast.removed",{name:n(T.nameKey)}),_),await g()}finally{v(null)}},[g,y,R,n]),q=o.useCallback(async T=>{const Q=_i(i,T.packageName,r),Z=Lo(Q,T.packageName);if(Z==="manage"){a();return}if(Z==="setup"){v({pluginId:T.id,action:Z});try{const ae=await e(T.providerId);y(T.id,!ae),ae||D.error(n("settings.integrations.thirdParty.toast.providerUnavailable"))}finally{v(null)}return}const K=ir(T.packageName,Q.registry);if(!K){m(!0);return}if(Z==="install"){await O(T,"install",()=>d({spec:K,scope:"user"}));return}Q.userEntry&&await O(T,"update",()=>b(Q.userEntry.id,{spec:K}))},[d,i,a,e,r,O,y,n,b]),S=o.useCallback(async()=>{const T=I;if(!T)return;const Q=_i(i,T.packageName,r);if(!Q.userEntry||Q.userEntryIsAmbiguous){F(null),a();return}F(null),await O(T,"remove",()=>c(Q.userEntry.id))},[c,i,a,r,I,O]),G=o.useCallback((T,Q)=>{k(Z=>{const K=new Set(Z);return Q?K.add(T):K.delete(T),K})},[]),J=T=>{const Q=_i(i,T.packageName,r),Z=Lo(Q,T.packageName),K=ir(T.packageName,Q.registry),ae=E?.pluginId===T.id,_=P.has(T.id),B=C.has(T.id),M=j||Q.registry?.kind==="npm-network",U=ae||_||(Z==="install"||Z==="update")&&(M||!K),Y=Qg(Q,{registryUnavailable:M,restartRequired:_,providerUnavailable:B});let X;switch(Y.status){case"installed-version":X=Y.latestVersion?n("settings.integrations.thirdParty.status.installedVersion",{version:Y.latestVersion}):n("settings.integrations.thirdParty.status.installed");break;case"update-available":X=Y.latestVersion?n("settings.integrations.thirdParty.status.updateAvailable",{version:Y.latestVersion}):n("settings.integrations.thirdParty.status.unpinned");break;case"not-installed":X=n("settings.integrations.thirdParty.status.notInstalled");break;case"installed":X=n("settings.integrations.thirdParty.status.installed");break;case"unpinned":X=n("settings.integrations.thirdParty.status.unpinned");break;case"ambiguous":X=n("settings.integrations.thirdParty.status.ambiguous");break;case"restart-required":X=n("settings.integrations.thirdParty.status.restartRequired");break;case"registry-unavailable":X=n("settings.integrations.thirdParty.status.registryUnavailable");break;case"provider-unavailable":X=n("settings.integrations.thirdParty.status.providerUnavailable");break}const ne=Y.status==="installed-version"?"bg-[var(--status-success)]/15 text-[var(--status-success)]":Y.status==="update-available"||Y.status==="ambiguous"||Y.status==="restart-required"||Y.status==="registry-unavailable"||Y.status==="provider-unavailable"?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":"bg-[var(--surface-muted)] text-muted-foreground",te={install:n("settings.integrations.thirdParty.actions.install"),update:n("settings.integrations.thirdParty.actions.update"),setup:n("settings.integrations.thirdParty.actions.setup"),manage:n("settings.integrations.thirdParty.actions.managePlugins")}[Z],ge=A.has(T.id);return s.jsx(Gn,{open:ge,onOpenChange:ee=>G(T.id,ee),children:s.jsxs("div",{"data-settings-item":`integrations.third-party.${T.id}`,className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(qn,{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(L,{name:T.icon,className:ye("size-5",T.brandClassName)})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:n(T.nameKey)}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:n(T.descriptionKey)})]}),s.jsx("span",{"aria-live":"polite",className:ye("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",ne),children:X}),s.jsx(L,{name:"arrow-down-s",className:ye("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",ge&&"rotate-180")})]}),s.jsx(Wn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[Q.projectEntries.length>0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.thirdParty.status.projectInstalled")}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(V,{type:"button",size:"sm",variant:Z==="manage"?"outline":"default",onClick:()=>{q(T)},disabled:U,children:[ae?s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"}):Z==="setup"?s.jsx(L,{name:"plug-2",className:"size-3.5"}):null,te]}),s.jsxs(V,{type:"button",size:"sm",variant:"secondary",onClick:()=>{En(T.homepage)},children:[s.jsx(L,{name:"external-link",className:"size-3.5"}),n("settings.integrations.thirdParty.actions.docs")]}),Q.userEntry&&!Q.userEntryIsAmbiguous?s.jsxs(V,{type:"button",size:"sm",variant:"destructive",onClick:()=>F(T),disabled:ae,children:[s.jsx(L,{name:"delete-bin",className:"size-3.5"}),n("settings.integrations.thirdParty.actions.remove")]}):null]})]})})]})},T.id)};return s.jsxs(s.Fragment,{children:[s.jsx(Ue,{title:n("settings.integrations.thirdParty.title"),info:n("settings.integrations.thirdParty.info"),divider:t,settingsItem:"integrations.third-party",contentClassName:"space-y-3",children:zi.map(J)}),s.jsx(Vt,{open:I!==null,onOpenChange:T=>!T&&F(null),children:s.jsxs(Bt,{className:"max-w-md",children:[s.jsxs(Wt,{children:[s.jsx(Jt,{children:n("settings.integrations.thirdParty.dialog.remove.title")}),s.jsx(Qt,{children:n("settings.integrations.thirdParty.dialog.remove.description",{name:I?n(I.nameKey):""})})]}),s.jsxs(ds,{children:[s.jsx(V,{type:"button",size:"sm",variant:"ghost",onClick:()=>F(null),children:n("settings.common.actions.cancel")}),s.jsx(V,{type:"button",size:"sm",variant:"destructive",onClick:()=>{S()},children:n("settings.integrations.thirdParty.actions.remove")})]})]})})]})},Xg=t=>{const e=mt.c(21),{onOpenProviderSetup:a,onOpenPluginManager:n}=t,{t:i}=rt();let r;e[0]!==i?(r=i("settings.page.integrations.title"),e[0]=i,e[1]=r):r=e[1];let l;e[2]!==i?(l=i("settings.page.integrations.description"),e[2]=i,e[3]=l):l=e[3];let h;e[4]!==l?(h=s.jsx("p",{className:el,children:l}),e[4]=l,e[5]=h):h=e[5];let d;e[6]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(L,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),e[6]=d):d=e[6];let b;e[7]!==i?(b=i("settings.integrations.experimentalWarning"),e[7]=i,e[8]=b):b=e[8];let c;e[9]!==b?(c=s.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:[d,s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:b})]}),e[9]=b,e[10]=c):c=e[10];let j;e[11]!==h||e[12]!==c?(j=s.jsxs("div",{className:"space-y-3",children:[h,c]}),e[11]=h,e[12]=c,e[13]=j):j=e[13];let m;e[14]!==n||e[15]!==a?(m=s.jsx(Zg,{divider:!1,onOpenProviderSetup:a,onOpenPluginManager:n}),e[14]=n,e[15]=a,e[16]=m):m=e[16];let E;return e[17]!==r||e[18]!==j||e[19]!==m?(E=s.jsx(cs,{title:r,description:j,showSaveStatus:!1,children:m}),e[17]=r,e[18]=j,e[19]=m,e[20]=E):E=e[20],E},eh=[{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"}],th=[{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"}],sh=[{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"}],Sa="OpenChamber - AI Coding Assistant",Fo=[{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"}],Ko=[{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"}],nh=[{value:"default",labelKey:"settings.openchamber.visual.option.mobileLayout.default"},{value:"new",labelKey:"settings.openchamber.visual.option.mobileLayout.new"}],$i=t=>t==="portrait"||t==="landscape"?t:"system",ah=[{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"}],ih=[{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"}],Uo=[{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"}],rh=[{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"}],zo=[{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"}],_o=[{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"}],oh=[{id:"steer",labelKey:"settings.openchamber.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.openchamber.visual.option.followUpBehavior.queue.label"}],lh=t=>t==="markdown"?"markdown":"plain",ch=[{id:"left",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsRight"}],dh=[{id:"classic",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.openchamber.desktopNetwork.option.windowControlsTrafficLights"}],ci=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=rt(),l=o.useCallback(p=>r(p),[r]),{isMobile:h}=oa(),{terminal:d}=ol(),{browserTab:b}=kd(),c=od(),j=ce(p=>p.showReasoningTraces),m=ce(p=>p.sessionRecapEnabled),E=ce(p=>p.sessionSuggestionEnabled),v=ce(p=>p.setSessionRecapEnabled),P=ce(p=>p.setSessionSuggestionEnabled),x=ce(p=>p.sessionGoalEnabled),C=ce(p=>p.setSessionGoalEnabled),u=ce(p=>p.sessionGoalDefaultBudgetEnabled),I=ce(p=>p.setSessionGoalDefaultBudgetEnabled),F=ce(p=>p.sessionGoalDefaultBudget),A=ce(p=>p.setSessionGoalDefaultBudget),k=ce(p=>p.setShowReasoningTraces),g=ce(p=>p.collapsibleThinkingBlocks),w=ce(p=>p.setCollapsibleThinkingBlocks),z=ce(p=>p.mermaidRenderingMode),N=ce(p=>p.setMermaidRenderingMode),R=ce(p=>p.userMessageRenderingMode),y=ce(p=>p.setUserMessageRenderingMode),O=ce(p=>p.collapsibleUserMessages),q=ce(p=>p.setCollapsibleUserMessages),S=ce(p=>p.stickyUserHeader),G=ce(p=>p.promptNavigatorEnabled),J=ce(p=>p.setStickyUserHeader),T=ce(p=>p.setPromptNavigatorEnabled),Q=ce(p=>p.expandedEditorToolbar),Z=ce(p=>p.setExpandedEditorToolbar),K=ce(p=>p.autoSaveEnabled),ae=ce(p=>p.setAutoSaveEnabled),_=ce(p=>p.wideChatLayoutEnabled),B=ce(p=>p.setWideChatLayoutEnabled),M=ce(p=>p.codeBlockLineWrap),U=ce(p=>p.setCodeBlockLineWrap),Y=ce(p=>p.chatRenderMode),X=ce(p=>p.setChatRenderMode),ne=ce(p=>p.activityRenderMode),te=ce(p=>p.setActivityRenderMode),ge=ce(p=>p.fontSize),ee=ce(p=>p.setFontSize),le=ce(p=>p.terminalFontSize),pe=ce(p=>p.setTerminalFontSize),ie=ce(p=>p.terminalShell),je=ce(p=>p.setTerminalShell),Se=ce(p=>p.terminalLoginShells),Ce=ce(p=>p.setTerminalLoginShells),xe=ce(p=>p.editorFontSize),Re=ce(p=>p.setEditorFontSize),Oe=ce(p=>p.uiFont),fe=ce(p=>p.setUiFont),be=ce(p=>p.monoFont),De=ce(p=>p.setMonoFont),_e=ce(p=>p.padding),Le=ce(p=>p.setPadding),qe=ce(p=>p.inputBarOffset),Ke=ce(p=>p.setInputBarOffset),Xe=ce(p=>p.mobileKeyboardMode),We=ce(p=>p.setMobileKeyboardMode),Ze=ce(p=>p.diffLayoutPreference),we=ce(p=>p.setDiffLayoutPreference),Je=ce(p=>p.showTerminalQuickKeysOnDesktop),Me=ce(p=>p.setShowTerminalQuickKeysOnDesktop),ve=ce(p=>p.fileEditorKeymap),$e=ce(p=>p.setFileEditorKeymap),$=Kr(p=>p.followUpBehavior),de=Kr(p=>p.setFollowUpBehavior),ue=ce(p=>p.persistChatDraft),ke=ce(p=>p.setPersistChatDraft),oe=ce(p=>p.inputSpellcheckEnabled),Ae=ce(p=>p.setInputSpellcheckEnabled),H=ce(p=>p.showToolFileIcons),ze=ce(p=>p.setShowToolFileIcons),tt=ce(p=>p.showTurnChangedFiles),Fe=ce(p=>p.setShowTurnChangedFiles),at=ce(p=>p.showExpandedBashTools),wt=ce(p=>p.setShowExpandedBashTools),bt=ce(p=>p.showExpandedEditTools),ut=ce(p=>p.setShowExpandedEditTools),gt=ce(p=>p.timeFormatPreference),Pt=ce(p=>p.setTimeFormatPreference),jt=ce(p=>p.weekStartPreference),Et=ce(p=>p.setWeekStartPreference),Ye=ce(p=>p.showSplitAssistantMessageActions),Ge=ce(p=>p.setShowSplitAssistantMessageActions),ct=ce(p=>p.allowPromptingSubagentSessions),Ie=ce(p=>p.setAllowPromptingSubagentSessions),It=ce(p=>p.draftStartersVisible),Ne=ce(p=>p.setDraftStartersVisible),Ct=st(p=>p.settingsMessageStreamTransport),W=st(p=>p.setSettingsMessageStreamTransport),me=Ct,Ee=st(p=>p.settingsDefaultFileViewerPreview),Pe=st(p=>p.setSettingsDefaultFileViewerPreview),lt=ce(p=>p.isSettingsDialogOpen),{themeMode:it,setThemeMode:Ve,availableThemes:Nt,customThemesLoading:is,reloadCustomThemes:es,lightThemeId:ys,darkThemeId:Ht,setLightThemePreference:rs,setDarkThemePreference:zt}=ur(),[fs,os]=o.useState(!1),ss=o.useMemo(()=>hs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[]),ns=ce(p=>p.dockBadgeEnabled),js=ce(p=>p.setDockBadgeEnabled),re=ld(),ot=ce(p=>p.desktopWindowControlsPosition),vt=ce(p=>p.setDesktopWindowControlsPosition),Be=ce(p=>p.desktopWindowControlsStyle),et=ce(p=>p.setDesktopWindowControlsStyle),[ht,Tt]=o.useState(0),Dt=ce(p=>p.reportUsage),Xt=ce(p=>p.setReportUsage),At=o.useCallback(p=>{Xt(p),kt({reportUsage:p})},[Xt]),St=o.useCallback(p=>{vt(p),kt({desktopWindowControlsPosition:p})},[vt]),Ut=o.useCallback(p=>{et(p),kt({desktopWindowControlsStyle:p})},[et]),Mt=(lt||h||xs())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Mt)return;let p=null,ft=Date.now();const us=()=>{const Gt=Date.now();Gt-ft>=420&&(Tt(Fs=>(Fs+1)%24),ft=Gt),p=requestAnimationFrame(us)};(typeof document>"u"||document.visibilityState==="visible")&&(p=requestAnimationFrame(us));const yt=()=>{document.visibilityState==="visible"&&p===null?p=requestAnimationFrame(us):document.visibilityState!=="visible"&&p!==null&&(cancelAnimationFrame(p),p=null)};return document.addEventListener("visibilitychange",yt),()=>{document.removeEventListener("visibilitychange",yt),p!==null&&cancelAnimationFrame(p)}},[Mt]);const ps=o.useCallback(p=>{y(p),kt({userMessageRenderingMode:p})},[y]),Es=o.useCallback(p=>{J(p),kt({stickyUserHeader:p})},[J]),di=o.useCallback(p=>{T(p),kt({promptNavigatorEnabled:p})},[T]),pi=o.useCallback(p=>{Ne(p),kt({draftStartersVisible:p})},[Ne]),mi=o.useCallback(p=>{Z(p),kt({expandedEditorToolbar:p})},[Z]),ui=o.useCallback(p=>{q(p),kt({collapsibleUserMessages:p})},[q]),Os=o.useCallback(p=>{B(p),kt({wideChatLayoutEnabled:p})},[B]),la=o.useCallback(p=>{Ge(p),kt({showSplitAssistantMessageActions:p})},[Ge]),gi=o.useCallback(p=>{Ae(p),kt({inputSpellcheckEnabled:p})},[Ae]),Ka=o.useCallback(p=>{X(p),kt({chatRenderMode:p})},[X]),hi=o.useCallback(p=>{W(p),kt({messageStreamTransport:p})},[W]),fi=o.useCallback(p=>{te(p),kt({activityRenderMode:p})},[te]),xi=o.useCallback(p=>{N(p),kt({mermaidRenderingMode:p})},[N]),bi=o.useCallback(p=>{ze(p),kt({showToolFileIcons:p})},[ze]),vi=o.useCallback(p=>{Fe(p),kt({showTurnChangedFiles:p})},[Fe]),ws=o.useCallback(p=>{Pe(p),kt({defaultFileViewerPreview:p}),window.dispatchEvent(new CustomEvent("openchamber:file-viewer-preview-mode-changed",{detail:{enabled:p}}))},[Pe]),Gs=o.useCallback(p=>{wt(p),kt({showExpandedBashTools:p})},[wt]),Qn=o.useCallback(p=>{ut(p),kt({showExpandedEditTools:p})},[ut]),rn=o.useCallback(p=>{Pt(p),kt({timeFormatPreference:p})},[Pt]),mn=o.useCallback(p=>{Et(p),kt({weekStartPreference:p})},[Et]),ca=o.useMemo(()=>Nt.filter(p=>p.metadata.variant==="light").sort((p,ft)=>p.metadata.name.localeCompare(ft.metadata.name)),[Nt]),Ls=o.useMemo(()=>Nt.filter(p=>p.metadata.variant==="dark").sort((p,ft)=>p.metadata.name.localeCompare(ft.metadata.name)),[Nt]),da=o.useMemo(()=>ca.find(p=>p.metadata.id===ys)??ca[0],[ca,ys]),un=o.useMemo(()=>Ls.find(p=>p.metadata.id===Ht)??Ls[0],[Ls,Ht]),on=o.useCallback((p,ft)=>{const us=ft==="dark"?" Dark":" Light";return p.endsWith(us)?p.slice(0,-us.length):p},[]),he=p=>t?t.includes(p):!0,as=xs(),Ua=he("theme")&&!as,ms=he("windowControlsPosition")&&re,za=he("theme")||he("timeFormat")||he("weekStart"),Tn=h&&In()&&!hs()&&!as,Dn=as?za:he("theme")||ms||Tn||he("pwaInstallName")||he("pwaOrientation")||he("timeFormat")||he("weekStart"),_a=he("fontSize")||he("terminalFontSize")||he("editorFontSize")||he("spacing")||he("inputBarOffset")&&h,pa=he("terminalQuickKeys")&&!h||(he("terminalShell")||he("terminalLoginShell"))&&!as||he("fileEditorKeymap")||he("autoSaveEnabled")||he("expandedEditorToolbar")&&!as,yi=he("mermaidRendering")||he("sessionGoal")&&!as||he("userMessageRendering")||he("chatRenderMode")||he("messageTransport")||he("activityRenderMode")&&Y==="sorted"||he("collapsibleUserMessages")||he("stickyUserHeader")||he("promptNavigatorEnabled")&&!as||he("wideChatLayout")||he("codeBlockLineWrap")||he("splitAssistantMessageActions")||he("subagentReadOnlyBanner")||he("diffLayout")||he("dotfiles")||he("fileViewerPreview")||he("reasoning")||he("followUpBehavior")||he("persistDraft")||he("showToolFileIcons")||he("expandedTools")||!h&&he("inputSpellcheck"),Mn=he("chatRenderMode")||he("activityRenderMode")&&Y==="sorted",gn=he("messageTransport"),Rn=he("userMessageRendering")||he("mermaidRendering")||he("diffLayout")&&!as||he("followUpBehavior"),$a=he("sessionAssist")||he("sessionGoal")&&!as||he("subagentReadOnlyBanner")||he("collapsibleUserMessages")||he("stickyUserHeader")||he("promptNavigatorEnabled")&&!as||he("wideChatLayout")||he("codeBlockLineWrap")||he("splitAssistantMessageActions")||he("dotfiles")||he("fileViewerPreview")||he("persistDraft")||he("showToolFileIcons")||he("showTurnChangedFiles")||!h&&he("inputSpellcheck")||he("reasoning")||he("expandedTools"),Yn=Dn||_a||pa,qs=he("pwaInstallName")&&In()&&b&&!hs()&&!as,hn=he("pwaOrientation")&&In()&&!hs()&&!as,Ws=he("mobileKeyboardMode")&&In()&&!hs()&&!as&&cd(),Zn=(he("terminalShell")||he("terminalLoginShell"))&&!as,[ma,ua]=o.useState([]),[ji,wi]=o.useState(0);o.useEffect(()=>gl(()=>{ua([]),wi(p=>p+1)}),[]),o.useEffect(()=>{let p=!1;if(!(!Zn||!d.listShells))return d.listShells().then(ft=>{p||ua(ft)}).catch(()=>{p||ua([])}),()=>{p=!0}},[Zn,d,ji]);const ki=o.useMemo(()=>{const p=ma.filter(ft=>ft.id!=="auto");return ie==="auto"||p.some(ft=>ft.id===ie)?p:[{id:ie,name:ie,supportsLogin:!1},...p]},[ma,ie]),Ni=ma.find(p=>p.id===ie)?.supportsLogin===!0,Si=Se.includes(ie),On=p=>{Ce(p?[...Se.filter(ft=>ft!==ie),ie]:Se.filter(ft=>ft!==ie))},[fn,ga]=o.useState(()=>Md()),[ha,f]=o.useState(""),[se,Te]=o.useState("system"),nt=o.useMemo(()=>{const p=zo.find(ft=>ft.id===gt);return l(p?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[gt,l]),_t=o.useMemo(()=>{const p=_o.find(ft=>ft.id===jt);return l(p?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[jt,l]),Ts=o.useMemo(()=>{const p=Fo.find(ft=>ft.id===se);return p?l(p.labelKey):void 0},[se,l]),ks=o.useMemo(()=>{const p=Ko.find(ft=>ft.id===Xe);return p?l(p.labelKey):void 0},[Xe,l]),zs=o.useCallback(p=>{p!==fn&&(ga(p),Rd(p),window.location.reload())},[fn]),bs=o.useCallback(async p=>{if(typeof window>"u")return;const ft=window,yt=p.trim().replace(/\s+/g," ").slice(0,64);if(await kt({pwaAppName:yt}),typeof ft.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const Gt=ft.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(yt);f(Gt);return}f(yt||Sa),ft.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),_s=o.useCallback(async p=>{if(typeof window>"u")return;const ft=window,us=$i(p);if(await kt({pwaOrientation:us}),typeof ft.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const yt=ft.__OPENCHAMBER_SET_PWA_ORIENTATION__(us);Te(yt);return}Te(us),ft.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!qs&&!hn&&!Ws)return;let p=!1;return(async()=>{try{const us=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!us.ok){p||f(Sa);return}const yt=await us.json().catch(()=>({})),Fs=(typeof yt?.pwaAppName=="string"?yt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Rt=$i(yt?.pwaOrientation),Ns=Vr(yt?.mobileKeyboardMode);p||(qs&&f(Fs||Sa),hn&&Te(Rt),Ws&&We(Ns))}catch{p||(qs&&f(Sa),hn&&Te("system"),Ws&&We("native"))}})(),()=>{p=!0}},[We,Ws,qs,hn]),s.jsxs("div",{className:"space-y-0",children:[Dn&&s.jsxs("div",{className:"space-y-0",children:[Ua&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(Nn,{children:[s.jsxs("div",{className:Sn,children:[s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.colorMode"),children:eh.map(p=>s.jsx(kn,{selected:it===p.value,onSelect:()=>Ve(p.value),label:l(p.labelKey),ariaLabel:l(p.labelKey)},p.value))}),Tn&&s.jsx(ra,{children:s.jsx(Zt,{label:r("settings.openchamber.visual.section.mobileLayout"),children:s.jsx(Bs,{value:fn,options:nh.map(p=>({value:p.value,label:l(p.labelKey)})),onChange:zs,"aria-label":r("settings.openchamber.visual.section.mobileLayout")})})})]}),s.jsxs("div",{className:Sn,children:[s.jsx(Zt,{label:r("settings.openchamber.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(Lt,{value:da?.metadata.id??"",onValueChange:rs,children:[s.jsx(Ft,{"aria-label":r("settings.openchamber.visual.field.selectLightThemeAria"),size:qt,className:xn,children:s.jsx($t,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:da?on(da.metadata.name,"light"):void 0})}),s.jsx(Kt,{children:ca.map(p=>s.jsx(pt,{value:p.metadata.id,children:on(p.metadata.name,"light")},p.metadata.id))})]})}),s.jsx(Zt,{label:r("settings.openchamber.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(Lt,{value:un?.metadata.id??"",onValueChange:zt,children:[s.jsx(Ft,{"aria-label":r("settings.openchamber.visual.field.selectDarkThemeAria"),size:qt,className:xn,children:s.jsx($t,{placeholder:r("settings.openchamber.visual.field.selectThemePlaceholder"),children:un?on(un.metadata.name,"dark"):void 0})}),s.jsx(Kt,{children:Ls.map(p=>s.jsx(pt,{value:p.metadata.id,children:on(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:is||fs,onClick:()=>{const p=Date.now();os(!0),es().finally(()=>{const ft=Date.now()-p;if(ft<500){window.setTimeout(()=>{os(!1)},500-ft);return}os(!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(L,{name:"restart",className:ye("h-3.5 w-3.5",fs&&"animate-spin")}),r(fs?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")]}),s.jsx(ts,{children:r("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),ss&&s.jsx(ra,{settingsItem:"appearance.dock-badge",children:s.jsx(xt,{checked:ns,onChange:js,label:r("settings.openchamber.visual.field.dockBadge"),info:r("settings.openchamber.visual.field.dockBadgeHint"),ariaLabel:r("settings.openchamber.visual.field.dockBadge")})})]}),ms&&s.jsx(Ue,{title:r("settings.openchamber.desktopNetwork.field.windowControls"),info:r("settings.openchamber.desktopNetwork.field.windowControlsPositionDescription"),divider:Ua,children:s.jsxs(Nn,{children:[s.jsx(Zt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(Bs,{value:ot,options:ch.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:St,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(Zt,{label:r("settings.openchamber.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(Bs,{value:Be,options:dh.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:Ut,"aria-label":r("settings.openchamber.desktopNetwork.field.windowControlsStyleAria")})})]})}),za&&s.jsx(Ue,{title:r("settings.openchamber.visual.section.localization"),children:s.jsxs(Nn,{children:[s.jsx(Zt,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Lt,{value:e,onValueChange:p=>n(p),children:[s.jsx(Ft,{"aria-label":r("settings.appearance.language.select"),size:qt,className:xn,children:s.jsx($t,{children:i(e)})}),s.jsx(Kt,{children:a.map(p=>s.jsx(pt,{value:p,children:i(p)},p))})]})}),(he("timeFormat")||he("weekStart"))&&s.jsxs("div",{className:Sn,children:[he("timeFormat")&&s.jsx(Zt,{label:r("settings.openchamber.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Lt,{value:gt,onValueChange:p=>rn(p),children:[s.jsx(Ft,{"aria-label":r("settings.openchamber.visual.field.selectTimeFormatAria"),size:qt,className:xn,children:s.jsx($t,{children:nt})}),s.jsx(Kt,{children:zo.map(p=>s.jsx(pt,{value:p.id,children:l(p.labelKey)},p.id))})]})}),he("weekStart")&&s.jsx(Zt,{label:r("settings.openchamber.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Lt,{value:jt,onValueChange:p=>mn(p),children:[s.jsx(Ft,{"aria-label":r("settings.openchamber.visual.field.selectWeekStartAria"),size:qt,className:xn,children:s.jsx($t,{children:_t})}),s.jsx(Kt,{children:_o.map(p=>s.jsx(pt,{value:p.id,children:l(p.labelKey)},p.id))})]})})]})]})}),(qs||hn||Ws)&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.appInstall"),contentClassName:Sn,children:[qs&&s.jsxs(Yt,{label:r("settings.openchamber.visual.field.installAppName"),info:r("settings.openchamber.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:Ks,children:[s.jsx(He,{value:ha,onChange:p=>{f(p.target.value)},onBlur:()=>{bs(ha)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),bs(ha))},className:"min-w-0 flex-1",maxLength:64,"aria-label":r("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{f(Sa),bs("")},className:vs,"aria-label":r("settings.openchamber.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]}),hn&&s.jsxs(Yt,{label:r("settings.openchamber.visual.field.installOrientation"),description:r("settings.openchamber.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:Ks,children:[s.jsxs(Lt,{value:se,onValueChange:p=>{const ft=$i(p);Te(ft),_s(ft)},children:[s.jsx(Ft,{"aria-label":r("settings.openchamber.visual.field.pwaInstallOrientationAria"),size:qt,className:Cr,children:s.jsx($t,{placeholder:r("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Ts})}),s.jsx(Kt,{children:Fo.map(p=>s.jsx(pt,{value:p.id,children:l(p.labelKey)},p.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Te("system"),_s("system")},disabled:se==="system",className:vs,"aria-label":r("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]}),Ws&&s.jsxs(Yt,{label:r("settings.openchamber.visual.field.mobileKeyboardMode"),info:r("settings.openchamber.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:Ks,children:[s.jsxs(Lt,{value:Xe,onValueChange:p=>{const ft=Vr(p);We(ft),kt({mobileKeyboardMode:ft})},children:[s.jsx(Ft,{"aria-label":r("settings.openchamber.visual.field.mobileKeyboardModeAria"),size:qt,className:Cr,children:s.jsx($t,{placeholder:r("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:ks})}),s.jsx(Kt,{children:Ko.map(p=>s.jsx(pt,{value:p.id,children:l(p.labelKey)},p.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>{We("native"),kt({mobileKeyboardMode:"native"})},disabled:Xe==="native",className:vs,"aria-label":r("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),_a&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.densityAndType"),contentClassName:Sn,children:[he("fontSize")&&!h||he("terminalFontSize")?s.jsxs(Nn,{children:[he("fontSize")&&!h&&s.jsxs(Zt,{label:r("settings.openchamber.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Lt,{value:Oe,onValueChange:p=>fe(p),children:[s.jsx(Ft,{"aria-label":r("settings.openchamber.visual.field.selectInterfaceFontAria"),size:qt,className:xn,children:s.jsx($t,{children:Ur.find(p=>p.id===Oe)?.label})}),s.jsx(Kt,{children:Ur.map(p=>s.jsx(pt,{value:p.id,children:s.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>fe(zr),disabled:Oe===zr,className:vs,"aria-label":r("settings.openchamber.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]}),he("terminalFontSize")&&s.jsxs(Zt,{label:r("settings.openchamber.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Lt,{value:be,onValueChange:p=>De(p),children:[s.jsx(Ft,{"aria-label":r("settings.openchamber.visual.field.selectCodeFontAria"),size:qt,className:xn,children:s.jsx($t,{children:_r.find(p=>p.id===be)?.label})}),s.jsx(Kt,{children:_r.map(p=>s.jsx(pt,{value:p.id,children:s.jsx("span",{style:{fontFamily:p.stack},children:p.label})},p.id))})]}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>De($r),disabled:be===$r,className:vs,"aria-label":r("settings.openchamber.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,he("fontSize")&&!h||he("terminalFontSize")||he("editorFontSize")?s.jsxs(Nn,{children:[he("fontSize")&&!h&&s.jsx(Zt,{label:r("settings.openchamber.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:ba,children:[s.jsx(Ps,{value:ge,onValueChange:ee,min:50,max:200,step:5,"aria-label":r("settings.openchamber.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:va,children:"%"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>ee(100),disabled:ge===100,className:vs,"aria-label":r("settings.openchamber.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})}),he("terminalFontSize")&&s.jsx(Zt,{label:r("settings.openchamber.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ba,children:[s.jsx(Ps,{value:le,onValueChange:pe,min:9,max:52,step:1}),s.jsx("span",{className:va,children:"px"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>pe(13),disabled:le===13,className:vs,"aria-label":r("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})}),he("editorFontSize")&&s.jsx(Zt,{label:r("settings.openchamber.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ba,children:[s.jsx(Ps,{value:xe,onValueChange:Re,min:9,max:32,step:1}),s.jsx("span",{className:va,children:"px"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>Re(13),disabled:xe===13,className:vs,"aria-label":r("settings.openchamber.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,he("spacing")||he("inputBarOffset")&&h?s.jsxs(Nn,{children:[he("spacing")&&s.jsx(Zt,{label:r("settings.openchamber.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:ba,children:[s.jsx(Ps,{value:_e,onValueChange:Le,min:50,max:200,step:5}),s.jsx("span",{className:va,children:"%"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>Le(100),disabled:_e===100,className:vs,"aria-label":r("settings.openchamber.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})}),he("inputBarOffset")&&h&&s.jsx(Zt,{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:ba,children:[s.jsx(Ps,{value:qe,onValueChange:Ke,min:0,max:100,step:5}),s.jsx("span",{className:va,children:"px"}),s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ke(0),disabled:qe===0,className:vs,"aria-label":r("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null]}),pa&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.navigation"),contentClassName:"space-y-4",children:[he("fileEditorKeymap")&&s.jsx(Js,{title:r("settings.openchamber.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.field.fileEditorKeymap"),children:["default","vim"].map(p=>s.jsx(kn,{selected:ve===p,onSelect:()=>$e(p),label:r(`settings.openchamber.visual.option.fileEditorKeymap.${p}`),ariaLabel:r(`settings.openchamber.visual.option.fileEditorKeymap.${p}`)},p))})}),s.jsxs("div",{className:Ss,children:[he("autoSaveEnabled")&&s.jsx(xt,{checked:K,onChange:ae,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"}),he("expandedEditorToolbar")&&!as&&s.jsx(xt,{checked:Q,onChange:mi,label:r("settings.openchamber.visual.field.expandedEditorToolbar"),ariaLabel:r("settings.openchamber.visual.field.expandedEditorToolbarAria"),settingsItem:"appearance.expanded-editor-toolbar"}),he("terminalQuickKeys")&&!h&&s.jsx(xt,{checked:Je,onChange:Me,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")}),Zn&&s.jsx(Zt,{label:r("settings.openchamber.visual.field.terminalShell"),info:r("settings.openchamber.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Lt,{value:ie,onValueChange:p=>{dd(p)&&je(p)},children:[s.jsx(Ft,{"aria-label":r("settings.openchamber.visual.field.terminalShellAria"),size:qt,className:xn,children:s.jsx($t,{})}),s.jsxs(Kt,{children:[s.jsx(pt,{value:"auto",children:r("settings.openchamber.visual.option.terminalShell.auto")}),ki.map(p=>s.jsx(pt,{value:p.id,children:p.name},p.id))]})]})}),Zn&&Ni&&s.jsx(xt,{checked:Si,onChange:On,label:r("settings.openchamber.visual.field.terminalLoginShell"),ariaLabel:r("settings.openchamber.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"})]})]}),yi&&s.jsxs(s.Fragment,{children:[Mn&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.chatDisplay"),divider:Yn,contentClassName:"space-y-6",children:[he("chatRenderMode")&&s.jsx(Js,{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:ih.map(p=>{const ft=Y===p.id,us=ht%12;return s.jsxs("button",{type:"button",onClick:()=>Ka(p.id),"aria-pressed":ft,className:ye("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",ft?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ye("typography-ui-label",ft?"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(yt=>{const Gt=yt*3+1,Fs=us-Gt+1,Rt=Fs<=0?0:Fs===1?42:Fs===2?68:92,Ns=Rt>0;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Ns?"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:`${Rt}%`}})]},yt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(yt=>{const Gt=us>=(yt+1)*3;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Gt?"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%"}})]},yt)})})})]},p.id)})})}),he("activityRenderMode")&&Y==="sorted"&&s.jsx(Js,{title:r("settings.openchamber.visual.section.activityDefault"),children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.activityDefaultAria"),children:rh.map(p=>s.jsx(kn,{selected:ne===p.id,onSelect:()=>fi(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(p.labelKey)})},p.id))})})]}),gn&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.messageStreamTransport"),divider:Mn||Yn,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(Bs,{value:me,options:Uo.map(p=>({value:p.id,label:l(p.labelKey)})),onChange:hi,"aria-label":r("settings.openchamber.visual.section.messageStreamTransport")}),(()=>{const p=Uo.find(ft=>ft.id===me);return p?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(p.descriptionKey)}):null})()]}),Rn&&s.jsx(Ue,{title:r("settings.openchamber.visual.section.chatMessageOptions"),divider:Mn||gn||Yn,children:s.jsxs(Nn,{className:"lg:gap-y-6",children:[he("userMessageRendering")&&s.jsx(Js,{title:r("settings.openchamber.visual.section.userMessageRendering"),children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.userMessageRenderingAria"),children:ah.map(p=>s.jsx(kn,{selected:lh(R)===p.id,onSelect:()=>ps(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(p.labelKey)})},p.id))})}),he("mermaidRendering")&&s.jsx(Js,{title:r("settings.openchamber.visual.section.mermaidRendering"),children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.mermaidRenderingAria"),children:sh.map(p=>s.jsx(kn,{selected:z===p.id,onSelect:()=>xi(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(p.labelKey)})},p.id))})}),he("diffLayout")&&!as&&s.jsx(Js,{title:r("settings.openchamber.visual.section.diffLayout"),children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.diffLayoutAria"),children:th.map(p=>s.jsx(kn,{selected:Ze===p.id,onSelect:()=>we(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.diffLayoutAria",{option:l(p.labelKey)})},p.id))})}),he("followUpBehavior")&&s.jsx(Js,{title:r("settings.openchamber.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(wn,{"aria-label":r("settings.openchamber.visual.section.followUpBehaviorAria"),children:oh.map(p=>s.jsx(kn,{selected:$===p.id,onSelect:()=>de(p.id),label:l(p.labelKey),ariaLabel:r("settings.openchamber.visual.field.followUpBehaviorAria",{option:l(p.labelKey)})},p.id))})})]})}),$a&&s.jsxs(s.Fragment,{children:[he("expandedTools")&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.showToolsOpenedByDefault"),divider:Mn||gn||Rn||Yn,contentClassName:Ss,children:[s.jsx(xt,{checked:at,onChange:Gs,label:r("settings.openchamber.visual.field.bash"),ariaLabel:r("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx(xt,{checked:bt,onChange:Qn,label:r("settings.openchamber.visual.field.editTools"),ariaLabel:r("settings.openchamber.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(Ue,{title:r("settings.openchamber.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:Ss,children:[s.jsx(xt,{checked:It,onChange:pi,label:r("settings.openchamber.visual.field.draftStartersVisible"),ariaLabel:r("settings.openchamber.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),he("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(xt,{checked:m,onChange:v,label:r("settings.openchamber.visual.field.sessionRecap"),ariaLabel:r("settings.openchamber.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(xt,{checked:E,onChange:P,label:r("settings.openchamber.visual.field.sessionSuggestion"),ariaLabel:r("settings.openchamber.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),he("subagentReadOnlyBanner")&&s.jsx(xt,{checked:ct,onChange:Ie,label:r("settings.openchamber.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.openchamber.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),he("sessionGoal")&&!as&&s.jsxs(Ue,{title:r("settings.openchamber.visual.goal.sectionTitle"),info:r("settings.openchamber.visual.goal.description"),contentClassName:Ss,children:[s.jsx(xt,{checked:x,onChange:C,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(xt,{checked:u,onChange:I,disabled:!x,label:r("settings.openchamber.visual.goal.budgetLabel"),ariaLabel:r("settings.openchamber.visual.goal.budgetAria")}),x&&u?s.jsx(Ps,{value:F,onValueChange:p=>{typeof p=="number"&&Number.isFinite(p)&&p>0&&A(Math.floor(p))},min:1e3,max:1e8,step:5e4}):null]})]}),he("reasoning")&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:Ss,children:[s.jsx(xt,{checked:j,onChange:k,label:r("settings.openchamber.visual.field.showReasoningTraces"),ariaLabel:r("settings.openchamber.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),j&&s.jsx(xt,{checked:g,onChange:w,label:r("settings.openchamber.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")})]}),(he("collapsibleUserMessages")||he("stickyUserHeader")||he("promptNavigatorEnabled")&&!as||he("wideChatLayout")||he("splitAssistantMessageActions")||he("codeBlockLineWrap"))&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:Ss,children:[he("collapsibleUserMessages")&&s.jsx(xt,{checked:O,onChange:ui,label:r("settings.openchamber.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.openchamber.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),he("stickyUserHeader")&&s.jsx(xt,{checked:S,onChange:Es,label:r("settings.openchamber.visual.field.stickyUserHeader"),ariaLabel:r("settings.openchamber.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),he("promptNavigatorEnabled")&&!as&&s.jsx(xt,{checked:G,onChange:di,label:r("settings.openchamber.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.openchamber.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),he("wideChatLayout")&&s.jsx(xt,{checked:_,onChange:Os,label:r("settings.openchamber.visual.field.wideChatLayout"),ariaLabel:r("settings.openchamber.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),he("splitAssistantMessageActions")&&s.jsx(xt,{checked:Ye,onChange:la,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")}),he("codeBlockLineWrap")&&s.jsx(xt,{checked:M,onChange:U,label:r("settings.openchamber.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.openchamber.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(he("showToolFileIcons")||he("showTurnChangedFiles")||he("dotfiles")&&!xs()||he("fileViewerPreview"))&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:Ss,children:[he("showToolFileIcons")&&s.jsx(xt,{checked:H,onChange:bi,label:r("settings.openchamber.visual.field.showToolFileIcons"),ariaLabel:r("settings.openchamber.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),he("showTurnChangedFiles")&&s.jsx(xt,{checked:tt,onChange:vi,label:r("settings.openchamber.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.openchamber.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),he("dotfiles")&&!xs()&&s.jsx(xt,{checked:c,onChange:pd,label:r("settings.openchamber.visual.field.showDotfiles"),ariaLabel:r("settings.openchamber.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),he("fileViewerPreview")&&s.jsx(xt,{checked:Ee,onChange:ws,label:r("settings.openchamber.defaults.field.openFilesPreview"),ariaLabel:r("settings.openchamber.defaults.field.openFilesPreviewAria")})]}),(he("persistDraft")||!h&&he("inputSpellcheck"))&&s.jsxs(Ue,{title:r("settings.openchamber.visual.section.composer"),settingsItem:"chat.composer",contentClassName:Ss,children:[he("persistDraft")&&s.jsx(xt,{checked:ue,onChange:ke,label:r("settings.openchamber.visual.field.persistDraftMessages"),ariaLabel:r("settings.openchamber.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!h&&he("inputSpellcheck")&&s.jsx(xt,{checked:oe,onChange:gi,label:r("settings.openchamber.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"})]})]})]}),he("reportUsage")&&s.jsx(Ue,{title:r("settings.openchamber.visual.section.privacy"),children:s.jsx(xt,{checked:Dt,onChange:At,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"})})]})},ph=1,mh=365,$o=30,uh=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Fl=()=>{const t=mt.c(87),{t:e}=rt(),a=ce(gh),n=ce(hh),i=ce(fh),r=ce(xh),l=ce(bh),h=ce(vh);let d;t[0]===Symbol.for("react.memo_cache_sentinel")?(d={autoRun:!1},t[0]=d):d=t[0];const{candidates:b,isRunning:c,runCleanup:j,action:m}=Ac(d),E=b.length;let v;t[1]!==j||t[2]!==e?(v=async()=>{const te=await j({force:!0});if(te.completedIds.length===0&&te.failedIds.length===0){D.message(te.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}te.completedIds.length>0&&D.success(te.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:te.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:te.completedIds.length})),te.failedIds.length>0&&D.error(te.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:te.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:te.failedIds.length}))},t[1]=j,t[2]=e,t[3]=v):v=t[3];const P=v;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let C;t[6]!==e?(C=e("settings.openchamber.sessionRetention.tooltip"),t[6]=e,t[7]=C):C=t[7];let u;t[8]!==e?(u=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=u):u=t[9];let I;t[10]!==e?(I=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=I):I=t[11];let F;t[12]!==a||t[13]!==r||t[14]!==u||t[15]!==I?(F=s.jsx(xt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:u,ariaLabel:I}),t[12]=a,t[13]=r,t[14]=u,t[15]=I,t[16]=F):F=t[16];let A;t[17]!==e?(A=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[17]=e,t[18]=A):A=t[18];let k;t[19]!==e?(k=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[19]=e,t[20]=k):k=t[20];let g;t[21]!==n||t[22]!==l||t[23]!==k?(g=s.jsx(Ps,{value:n,onValueChange:l,min:ph,max:mh,step:1,"aria-label":k,className:"w-20 tabular-nums"}),t[21]=n,t[22]=l,t[23]=k,t[24]=g):g=t[24];let w;t[25]!==e?(w=e("settings.openchamber.sessionRetention.field.days"),t[25]=e,t[26]=w):w=t[26];let z;t[27]!==w?(z=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:w}),t[27]=w,t[28]=z):z=t[28];let N;t[29]!==l?(N=()=>l($o),t[29]=l,t[30]=N):N=t[30];const R=n===$o;let y;t[31]!==e?(y=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[31]=e,t[32]=y):y=t[32];let O;t[33]!==e?(O=e("settings.common.actions.reset"),t[33]=e,t[34]=O):O=t[34];let q;t[35]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(L,{name:"restart",className:"h-3.5 w-3.5"}),t[35]=q):q=t[35];let S;t[36]!==N||t[37]!==R||t[38]!==y||t[39]!==O?(S=s.jsx(V,{size:"sm",type:"button",variant:"ghost",onClick:N,disabled:R,className:vs,"aria-label":y,title:O,children:q}),t[36]=N,t[37]=R,t[38]=y,t[39]=O,t[40]=S):S=t[40];let G;t[41]!==z||t[42]!==S||t[43]!==A||t[44]!==g?(G=s.jsxs(Yt,{settingsItem:"sessions.retention-period",label:A,children:[g,z,S]}),t[41]=z,t[42]=S,t[43]=A,t[44]=g,t[45]=G):G=t[45];let J;t[46]!==e?(J=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[46]=e,t[47]=J):J=t[47];let T;t[48]!==e?(T=uh.map(te=>({value:te.value,label:e(te.labelKey)})),t[48]=e,t[49]=T):T=t[49];let Q;t[50]!==i||t[51]!==h||t[52]!==T?(Q=s.jsx(Bs,{value:i,onChange:h,options:T}),t[50]=i,t[51]=h,t[52]=T,t[53]=Q):Q=t[53];let Z;t[54]!==J||t[55]!==Q?(Z=s.jsx(Yt,{settingsItem:"sessions.retention-action",label:J,children:Q}),t[54]=J,t[55]=Q,t[56]=Z):Z=t[56];let K;t[57]!==G||t[58]!==Z?(K=s.jsxs(ra,{className:"space-y-0",children:[G,Z]}),t[57]=G,t[58]=Z,t[59]=K):K=t[59];let ae;t[60]!==e?(ae=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[60]=e,t[61]=ae):ae=t[61];let _;t[62]!==c||t[63]!==e?(_=e(c?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[62]=c,t[63]=e,t[64]=_):_=t[64];let B;t[65]!==P||t[66]!==c||t[67]!==_?(B=s.jsx(V,{type:"button",variant:"outline",size:"xs",onClick:P,disabled:c,className:"!font-normal",children:_}),t[65]=P,t[66]=c,t[67]=_,t[68]=B):B=t[68];let M;t[69]!==ae||t[70]!==B?(M=s.jsx(Yt,{label:ae,children:B}),t[69]=ae,t[70]=B,t[71]=M):M=t[71];let U;t[72]!==m||t[73]!==E||t[74]!==e?(U=m==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:E}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:E}),t[72]=m,t[73]=E,t[74]=e,t[75]=U):U=t[75];let Y;t[76]!==U?(Y=s.jsx("p",{className:"typography-meta text-muted-foreground",children:U}),t[76]=U,t[77]=Y):Y=t[77];let X;t[78]!==M||t[79]!==Y?(X=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[M,Y]}),t[78]=M,t[79]=Y,t[80]=X):X=t[80];let ne;return t[81]!==x||t[82]!==K||t[83]!==C||t[84]!==X||t[85]!==F?(ne=s.jsxs(Ue,{title:x,info:C,children:[F,K,X]}),t[81]=x,t[82]=K,t[83]=C,t[84]=X,t[85]=F,t[86]=ne):ne=t[86],ne};function gh(t){return t.autoDeleteEnabled}function hh(t){return t.autoDeleteAfterDays}function fh(t){return t.sessionRetentionAction}function xh(t){return t.setAutoDeleteEnabled}function bh(t){return t.setAutoDeleteAfterDays}function vh(t){return t.setSessionRetentionAction}const Vo=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(mr(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),Kl=()=>{const{t}=rt(),e=ce(g=>g.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,h]=o.useState(!1),[d,b]=o.useState(null),[c,j]=o.useState(!1),[m,E]=o.useState([]),[v,P]=o.useState(Ec),[x,C]=o.useState(""),u=o.useMemo(()=>Tc(),[]),I=o.useCallback(async()=>{r(!0),C("");try{const g=await Dc();E(g)}catch(g){const w=g instanceof Error?g.message:t("settings.openchamber.passkeys.toast.loadFailed");C(w)}finally{r(!1)}},[t]);o.useEffect(()=>{let g=!1;return(async()=>{try{if(!u.supported){g||(n(!1),r(!1));return}g||n(!0)}catch{g||n(!1)}if(!g){const w=await Ii();if(P(w),!w.enabled){E([]),r(!1);return}await I()}})(),()=>{g=!0,Pr()}},[I,u.supported]);const F=o.useCallback(async()=>{if(!v.enabled){const g=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");C(g),D.message(g);return}if(!a){C(u.reason),D.message(u.reason);return}if(l){Pr(),h(!1);return}C(""),h(!0);try{await Mc(),P(await Ii()),await I(),D.success(t("settings.openchamber.passkeys.toast.added"))}catch(g){if(Rc(g)){D.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const w=g instanceof Error?g.message:t("settings.openchamber.passkeys.toast.addFailed");C(w),D.error(w)}finally{h(!1)}},[l,I,v.enabled,u.reason,a,t]),A=o.useCallback(async g=>{b(g),C("");try{await Oc(g),P(await Ii()),await I(),D.success(t("settings.openchamber.passkeys.toast.removed"))}catch(w){const z=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.removeFailed");C(z),D.error(z)}finally{b(null)}},[I,t]),k=o.useCallback(async()=>{j(!0),C("");try{await Lc(),window.location.reload()}catch(g){const w=g instanceof Error?g.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");C(w),D.error(w),j(!1)}},[t]);return s.jsxs(Ue,{title:t("settings.openchamber.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Yt,{label:t("settings.openchamber.passkeys.field.currentDevice"),children:[s.jsx(V,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{F()},disabled:i||c,className:"!font-normal",children:t(l?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k()},disabled:i||l||c,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(c?"settings.openchamber.passkeys.actions.signingOut":"settings.openchamber.passkeys.actions.signOutEverywhere")})]}),!v.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.uiPasswordRequired")}),v.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:u.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):m.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:m.map(g=>s.jsxs(Yt,{label:s.jsx("span",{className:"truncate",children:g.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:g.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Vo(g.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"),e)}):t("settings.openchamber.passkeys.item.added",{time:Vo(g.createdAt,t("settings.openchamber.passkeys.time.neverUsed"),e)})}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>{A(g.id)},disabled:d===g.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:d===g.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]},g.id))})]}),x&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:x})})]})},Ul=()=>{const t=mt.c(14),{t:e}=rt(),a=Ir(yh),n=Ir(jh);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(b=>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:`${b}://`}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(b),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.openchamber.appLinks.removeAria",{scheme:`${b}://`}),children:e("settings.common.actions.delete")})]},b)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let h;t[8]!==l?(h=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=h):h=t[9];let d;return t[10]!==i||t[11]!==r||t[12]!==h?(d=s.jsx(Ue,{title:i,description:r,children:h}),t[10]=i,t[11]=r,t[12]=h,t[13]=d):d=t[13],d};function yh(t){return t.trustedSchemes}function jh(t){return t.removeTrustedScheme}const Vi=t=>{const e=na(t);return e||{providerId:"",modelId:""}},zl=()=>{const{t}=rt(),e=st(ee=>ee.setProvider),a=st(ee=>ee.setModel),n=st(ee=>ee.setAgent),i=st(ee=>ee.setCurrentVariant),r=st(ee=>ee.setSettingsDefaultModel),l=st(ee=>ee.setSettingsDefaultVariant),h=st(ee=>ee.setSettingsDefaultAgent),d=st(ee=>ee.selectionSource==="manual"),b=Fc(ee=>ee.currentSessionId),c=Ar(ee=>ee.getSessionModelSelection),j=Ar(ee=>ee.getSessionAgentSelection),m=!!(d&&b&&c(b)),E=!!(d&&b&&j(b)),v=ce(ee=>ee.showDeletionDialog),P=ce(ee=>ee.setShowDeletionDialog),x=st(ee=>ee.providers),C=st(ee=>ee.modelsMetadata),[u,I]=o.useState(),[F,A]=o.useState(),[k,g]=o.useState(),[w,z]=o.useState(!0),[N,R]=o.useState(),[y,O]=o.useState([]),[q,S]=o.useState(),[G,J]=o.useState(!0),T=o.useMemo(()=>Vi(u),[u]);o.useEffect(()=>{(async()=>{try{let le=null;if(!le){const pe=An()?.settings;if(pe)try{const je=(await pe.load())?.settings;if(je){const Se=je;le={defaultModel:typeof je.defaultModel=="string"?je.defaultModel:void 0,defaultVariant:typeof Se.defaultVariant=="string"?Se.defaultVariant:void 0,defaultAgent:typeof je.defaultAgent=="string"?je.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(!le){const pe=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});pe.ok&&(le=await pe.json())}if(le){const pe=typeof le.defaultModel=="string"&&le.defaultModel.trim().length>0?le.defaultModel.trim():void 0,ie=typeof le.defaultVariant=="string"&&le.defaultVariant.trim().length>0?le.defaultVariant.trim():void 0,je=typeof le.defaultAgent=="string"&&le.defaultAgent.trim().length>0?le.defaultAgent.trim():void 0;pe!==void 0&&I(pe),ie!==void 0&&A(ie),je!==void 0&&g(je),typeof le.smallModelUseDefault=="boolean"&&z(le.smallModelUseDefault),typeof le.smallModelOverride=="string"&&le.smallModelOverride.trim()&&R(le.smallModelOverride.trim()),typeof le.walkthroughModelOverride=="string"&&le.walkthroughModelOverride.trim()&&S(le.walkthroughModelOverride.trim())}}catch(le){console.warn("Failed to load defaults settings:",le)}finally{J(!1)}})()},[]);const Q=o.useCallback(async(ee,le)=>{const pe=ee&&le?`${ee}/${le}`:void 0;I(pe),A(void 0),l(void 0),r(pe),m||(i(void 0),ee&&le&&x.find(je=>je.id===ee)&&(e(ee),a(le)));try{await kt({defaultModel:pe??"",defaultVariant:""});const ie=await dt("/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)}},[m,x,i,a,e,r,l]),Z="__default__",K=o.useCallback(ee=>ee===Z?t("settings.openchamber.defaults.option.default"):ee.charAt(0).toUpperCase()+ee.slice(1),[t]),ae=o.useCallback(async ee=>{const le=ee===Z?void 0:ee||void 0;A(le),l(le),m||i(le);try{await kt({defaultVariant:le??""})}catch(pe){console.warn("Failed to save default variant:",pe)}},[m,i,l]),_=o.useCallback(async ee=>{const le=ee||void 0;g(le),h(le),ee&&!E&&n(ee);try{await kt({defaultAgent:le??""})}catch(pe){console.warn("Failed to save default agent:",pe)}},[E,n,h]),B=o.useCallback(async ee=>{z(ee);try{await kt({smallModelUseDefault:ee})}catch(le){console.warn("Failed to save small model preference:",le)}},[]),M=o.useCallback(async(ee,le)=>{const pe=ee&&le?`${ee}/${le}`:void 0;R(pe);try{await kt({smallModelOverride:pe??""})}catch(ie){console.warn("Failed to save small model override:",ie)}},[]),U=o.useCallback(async(ee,le)=>{const pe=ee&&le?`${ee}/${le}`:void 0;S(pe);try{await kt({walkthroughModelOverride:pe??""})}catch(ie){console.warn("Failed to save walkthrough model override:",ie)}},[]),Y=o.useCallback((ee,le)=>C.get(`${ee}/${le}`)?.structured_output!==!1,[C]),X=o.useMemo(()=>Vi(N),[N]),ne=o.useMemo(()=>Vi(q),[q]);o.useEffect(()=>{let ee=!1;return(async()=>{try{const le=await dt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!le.ok)return;const pe=await le.json().catch(()=>null);!ee&&Array.isArray(pe?.authenticatedProviders)&&O(pe.authenticatedProviders.filter(ie=>typeof ie=="string"))}catch{}})(),()=>{ee=!0}},[]);const te=o.useMemo(()=>{if(!T.providerId||!T.modelId)return[];const pe=x.find(ie=>ie.id===T.providerId)?.models.find(ie=>ie.id===T.modelId)?.variants;return pe?Object.keys(pe):[]},[T.modelId,T.providerId,x]),ge=te.length>0;return o.useEffect(()=>{!ge&&F&&(A(void 0),l(void 0),m||i(void 0),kt({defaultVariant:""}).catch(()=>{}))},[m,F,i,l,ge]),G?null:s.jsx(s.Fragment,{children:s.jsx(Ue,{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")," ",T.providerId?s.jsxs("span",{className:"text-foreground",children:[T.providerId,"/",T.modelId,ge?` (${F??t("settings.openchamber.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.openchamber.defaults.summaryOpenCodeDefault")}),k&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:k})]})]}),s.jsxs("div",{children:[s.jsx(Yt,{settingsItem:"sessions.default-model",label:t("settings.openchamber.defaults.field.defaultModel"),children:s.jsx(Ea,{providerId:T.providerId,modelId:T.modelId,onChange:Q,className:Cn})}),s.jsx(Yt,{settingsItem:"sessions.default-thinking",label:t("settings.openchamber.defaults.field.defaultThinking"),children:s.jsxs(Lt,{value:F??Z,onValueChange:ae,disabled:!ge,children:[s.jsx(Ft,{size:qt,className:Pn,children:s.jsx($t,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:K(F??Z)})}),s.jsxs(Kt,{children:[s.jsx(pt,{value:Z,children:t("settings.openchamber.defaults.option.default")}),te.map(ee=>s.jsx(pt,{value:ee,children:K(ee)},ee))]})]})}),s.jsx(Yt,{settingsItem:"sessions.default-agent",label:t("settings.openchamber.defaults.field.defaultAgent"),children:s.jsx(nl,{agentName:k||"",onChange:_,filter:ee=>Kc(ee.mode),className:Cn})})]}),s.jsx(ra,{className:Ss,children:s.jsx(xt,{settingsItem:"sessions.deletion-dialog",checked:v,onChange:P,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(Xs,{children:t("settings.openchamber.defaults.smallModel.title")}),s.jsx(ts,{children:t("settings.openchamber.defaults.smallModel.description")})]}),s.jsx(xt,{settingsItem:"sessions.small-model",checked:w,onChange:ee=>{B(ee)},label:t("settings.openchamber.defaults.smallModel.useDefault"),ariaLabel:t("settings.openchamber.defaults.smallModel.useDefaultAria")}),w?null:s.jsx(Yt,{label:t("settings.openchamber.defaults.smallModel.overrideModel"),children:s.jsx(Ea,{providerId:X.providerId,modelId:X.modelId,onChange:M,allowedProviderIds:y,className:Cn})}),s.jsxs(ra,{className:Ss,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Xs,{children:t("settings.openchamber.defaults.walkthroughModel.title")}),s.jsx(ts,{children:t("settings.openchamber.defaults.walkthroughModel.description")})]}),s.jsx(Yt,{settingsItem:"sessions.walkthrough-model",label:t("settings.openchamber.defaults.walkthroughModel.overrideModel"),children:s.jsx(Ea,{providerId:ne.providerId,modelId:ne.modelId,onChange:U,allowedProviderIds:y,isModelAllowed:Y,placeholder:t("settings.openchamber.defaults.walkthroughModel.usesSmallModel"),className:Cn})})]})]})]})})})},Bo={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"}},wh={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"},kh=()=>{const{t}=rt(),e=o.useMemo(()=>hs(),[]),a=o.useMemo(()=>xs(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=ce(_=>_.nativeNotificationsEnabled),l=ce(_=>_.setNativeNotificationsEnabled),h=ce(_=>_.notificationMode),d=ce(_=>_.setNotificationMode),b=ce(_=>_.notifyOnSubtasks),c=ce(_=>_.setNotifyOnSubtasks),j=ce(_=>_.notifyOnCompletion),m=ce(_=>_.setNotifyOnCompletion),E=ce(_=>_.notifyOnError),v=ce(_=>_.setNotifyOnError),P=ce(_=>_.notifyOnQuestion),x=ce(_=>_.setNotifyOnQuestion),C=ce(_=>_.notificationTemplates),u=ce(_=>_.setNotificationTemplates),[I,F]=o.useState("default"),[A,k]=o.useState(!1),[g,w]=o.useState(!1),[z,N]=o.useState(!1);o.useEffect(()=>{if(!i){k(!1),w(!1);return}typeof Notification<"u"&&F(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;k(_),(async()=>{if(!_){w(!1);return}try{const M=await navigator.serviceWorker.getRegistration();if(!M){w(!1);return}const U=await M.pushManager.getSubscription();w(!!U)}catch{w(!1)}})()},[i]);const R=async _=>{if(e){l(_);return}if(!i){l(_);return}if(_&&typeof Notification<"u"&&Notification.permission==="default")try{const B=await Notification.requestPermission();F(B),B==="granted"?l(!0):D.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(B){console.error("Failed to request notification permission:",B),D.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(_&&I==="granted"))},y=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",O=(_,B,M)=>{u(U=>({...U,[_]:{...U[_],[B]:M}}))},q=_=>{const B="=".repeat((4-_.length%4)%4),M=(_+B).replace(/-/g,"+").replace(/_/g,"/"),U=atob(M),Y=new Uint8Array(U.length);for(let X=0;X<U.length;X+=1)Y[X]=U.charCodeAt(X);return Y},S=async(_,B,M)=>{let U=null;const Y=new Promise((X,ne)=>{U=setTimeout(()=>{ne(new Error(M))},B)});try{return await Promise.race([_,Y])}finally{U&&clearTimeout(U)}},G=async _=>{if(_.active)return;const B=_.installing||_.waiting;B&&B.state!=="activated"&&await S(new Promise(M=>{const U=()=>{B.state==="activated"&&(B.removeEventListener("statechange",U),M())};B.addEventListener("statechange",U),U()}),15e3,"Service worker activation timed out")},J=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 B=null;for(const M of _)try{const U=M.opts?navigator.serviceWorker.register("/sw.js",M.opts):navigator.serviceWorker.register("/sw.js");return await S(U,1e4,`Service worker registration timed out (${M.label})`)}catch(U){B=U}throw B instanceof Error?B:new Error("Service worker registration failed")},T=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const _=await navigator.serviceWorker.getRegistration();if(_)return _;const B=await J();try{await B.update()}catch{}return await G(B),B},Q=_=>{const B=_,M=[`type=${typeof _}`,`toString=${String(_)}`,`name=${String(B?.name??"")}`,`message=${String(B?.message??"")}`];let U="";try{U=JSON.stringify(_)}catch{}return{summary:M.filter(Boolean).join(" | "),json:U,stack:typeof B?.stack=="string"?B.stack:""}},Z=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(B){console.error("Test notification failed:",B),D.error(t("settings.notifications.page.toast.testNotificationFailed"))}},K=async()=>{if(!A){D.error(t("settings.notifications.page.toast.pushUnsupported"));return}const _=An();if(!_?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}N(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const ge=await Notification.requestPermission();if(F(ge),ge!=="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 B=await _.push.getVapidPublicKey();if(!B?.publicKey){D.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const M=await T();await G(M);const U=await M.pushManager.getSubscription();if(!("pushManager"in M)||!M.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const X=(U??await S(M.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:q(B.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ne=X.keys;if(!X.endpoint||!ne?.p256dh||!ne.auth)throw new Error("Push subscription missing keys");if(!(await S(_.push.subscribe({endpoint:X.endpoint,keys:{p256dh:ne.p256dh,auth:ne.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:md()}),15e3,"Push subscribe request timed out"))?.ok){D.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}w(!0),D.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(B){console.error("[Push] Enable failed:",B);const M=Q(B);D.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:M.summary})}finally{N(!1)}},ae=async()=>{if(!A){w(!1);return}const _=An();if(!_?.push){D.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}N(!0);try{const M=await(await T()).pushManager.getSubscription();if(!M){w(!1);return}const U=M.endpoint;await M.unsubscribe(),await _.push.unsubscribe({endpoint:U}),w(!1),D.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{N(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(Ue,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:Ss,children:[s.jsx(xt,{checked:r&&y,onChange:_=>{R(_)},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&&y&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(xt,{checked:h==="always",onChange:_=>d(_?"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(V,{type:"button",variant:"outline",size:"sm",onClick:()=>{Z()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[I==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),I==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&y&&s.jsxs(s.Fragment,{children:[s.jsx(Ue,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:Ss,children:[s.jsx(xt,{checked:j,onChange:m,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(xt,{checked:b,onChange:c,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(xt,{checked:E,onChange:v,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(xt,{checked:P,onChange:x,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(Ue,{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(Nn,{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(Xs,{className:"capitalize",children:t(wh[_])}),s.jsxs("div",{className:"mt-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.title")}),s.jsx(He,{value:C[_].title,onChange:B=>O(_,"title",B.target.value),className:"h-7",placeholder:t(Bo[_].titleKey)})]}),s.jsxs("div",{children:[s.jsx("label",{className:"typography-micro text-muted-foreground block mb-1",children:t("settings.notifications.page.template.field.message")}),s.jsx(He,{value:C[_].message,onChange:B=>O(_,"message",B.target.value),className:"h-7",placeholder:t(Bo[_].messageKey)})]})]})]},_))})})]}),i&&s.jsx(Ue,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(xt,{checked:A?g:!1,disabled:!A||z,onChange:_=>{_?K():ae()},label:t("settings.notifications.page.push.enableLabel"),description:A?void 0:t("settings.notifications.page.push.unsupportedHint"),info:A?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:z?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})})]})},Ds=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Nh=[{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"}],Ho=t=>{const e=mt.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 h;e[2]!==n?(h=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=h):h=e[3];let d;return e[4]!==i||e[5]!==l||e[6]!==h?(d=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,h]}),e[4]=i,e[5]=l,e[6]=h,e[7]=d):d=e[7],d},Sh=({selectedModelId:t,onSelect:e})=>{const{t:a}=rt(),n=Qe.useCallback(m=>a(m),[a]),[i,r]=Qe.useState(new Map),[l,h]=Qe.useState(null),d=Qe.useCallback(async()=>{try{const m=await dt("/api/dictation/status",{query:{provider:"local"}});if(!m.ok)return;const E=await m.json();Array.isArray(E?.models)&&r(new Map(E.models.map(v=>[v.id,v])))}catch{}},[]);Qe.useEffect(()=>{d()},[d]);const b=Array.from(i.values()).some(m=>m.downloading);Qe.useEffect(()=>{if(!b)return;const m=setInterval(()=>{d()},2e3);return()=>clearInterval(m)},[b,d]);const c=async m=>{h(m);try{await dt(`/api/dictation/models/${encodeURIComponent(m)}/download`,{method:"POST"}),await d()}catch{}finally{h(null)}},j=async m=>{h(m);try{await dt(`/api/dictation/models/${encodeURIComponent(m)}`,{method:"DELETE"}),await d()}catch{}finally{h(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:Nh.map(m=>{const E=t===m.id,v=i.get(m.id)??null;return s.jsx("div",{className:ye("rounded-lg border border-[var(--interactive-border)] p-3",E&&"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(m.id),onKeyDown:P=>{(P.key===" "||P.key==="Enter")&&(P.preventDefault(),e(m.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(cr,{checked:E,onChange:()=>e(m.id),ariaLabel:n(m.labelKey)})}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:ye("typography-ui-label font-normal",E?"text-foreground":"text-foreground/50"),children:n(m.labelKey)}),m.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(m.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ho,{value:m.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(Ho,{value:m.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:m.size})]}),v?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:v?.installed?s.jsxs(s.Fragment,{children:[s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===m.id,onClick:()=>{j(m.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(L,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(L,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):v?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(L,{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 v.downloadProgress=="number"?`${v.downloadProgress}%`:""})]}):s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===m.id,onClick:()=>{c(m.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(L,{name:"download",className:"h-4 w-4"})})})]})},m.id)})})},Bi=[{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)"}],Hi="kokoro-en-v0_19",Ch=()=>{const{t}=rt(),[e,a]=Qe.useState(null),[n,i]=Qe.useState(!1),r=Qe.useCallback(async()=>{try{const h=await dt("/api/dictation/status",{query:{provider:"local"}});if(!h.ok)return;const d=await h.json(),b=Array.isArray(d?.ttsModels)?d.ttsModels.find(c=>c.id===Hi):null;b&&a(b)}catch{}},[]);Qe.useEffect(()=>{r()},[r]),Qe.useEffect(()=>{if(!e?.downloading)return;const h=setInterval(()=>{r()},2e3);return()=>clearInterval(h)},[e?.downloading,r]);const l=async h=>{i(!0);try{const d=h==="POST"?`/api/dictation/models/${Hi}/download`:`/api/dictation/models/${Hi}`;await dt(d,{method:h}),await r()}catch{}finally{i(!1)}};return e?s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"Kokoro"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:"305 MB"}),e.installed?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":t("settings.voice.page.stt.modelInstalled")}),s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:n,onClick:()=>{l("DELETE")},title:t("settings.voice.page.stt.modelDelete"),"aria-label":t("settings.voice.page.stt.modelDelete"),children:s.jsx(L,{name:"delete-bin",className:"h-4 w-4"})})]}):e.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(L,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof e.downloadProgress=="number"?`${e.downloadProgress}%`:""})]}):s.jsx(V,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n,onClick:()=>{l("POST")},title:t("settings.voice.page.stt.modelDownload"),"aria-label":t("settings.voice.page.stt.modelDownload"),children:s.jsx(L,{name:"download",className:"h-4 w-4"})}),e.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:e.downloadError}):null]}):null},Ph=[{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"}],Ih=()=>{const{t}=rt(),{isMobile:e}=oa(),a=st(H=>H.voiceProvider),n=st(H=>H.setVoiceProvider),i=st(H=>H.speechRate),r=st(H=>H.setSpeechRate),l=st(H=>H.speechPitch),h=st(H=>H.setSpeechPitch),d=st(H=>H.speechVolume),b=st(H=>H.setSpeechVolume),c=st(H=>H.sayVoice),j=st(H=>H.setSayVoice),m=st(H=>H.localTtsVoiceId),E=st(H=>H.setLocalTtsVoiceId),{speak:v,stop:P,isPlaying:x,error:C}=Uc(),u=Qe.useCallback(()=>{if(x){P();return}const H=Bi.find(ze=>ze.id===m)?.label??String(m);v(t("settings.voice.page.preview.voiceLine",{voiceName:H}),{speakerId:m,speed:st.getState().speechRate})},[x,m,v,P,t]),I=st(H=>H.browserVoice),F=st(H=>H.setBrowserVoice),A=st(H=>H.openaiVoice),k=st(H=>H.setOpenaiVoice),g=st(H=>H.openaiApiKey),w=st(H=>H.setOpenaiApiKey),z=st(H=>H.openaiCompatibleUrl),N=st(H=>H.setOpenaiCompatibleUrl),R=st(H=>H.openaiCompatibleApiKey),y=st(H=>H.setOpenaiCompatibleApiKey),O=st(H=>H.openaiCompatibleVoice),q=st(H=>H.setOpenaiCompatibleVoice),S=st(H=>H.openaiCompatibleTtsModel),G=st(H=>H.setOpenaiCompatibleTtsModel),J=st(H=>H.showMessageTTSButtons),T=st(H=>H.ttsInputMode),Q=st(H=>H.setTtsInputMode),Z=st(H=>H.sttProvider),K=st(H=>H.setSttProvider),ae=st(H=>H.sttServerUrl),_=st(H=>H.setSttServerUrl),B=st(H=>H.sttApiKey),M=st(H=>H.setSttApiKey),U=st(H=>H.sttModel),Y=st(H=>H.setSttModel),X=st(H=>H.sttLocalModel),ne=st(H=>H.setSttLocalModel),te=st(H=>H.sttLanguage),ge=st(H=>H.setSttLanguage),ee=st(H=>H.setShowMessageTTSButtons),le=st(H=>H.dictationEnabled),pe=st(H=>H.setDictationEnabled),[ie,je]=Qe.useState(!1),[Se,Ce]=Qe.useState([]),[xe,Re]=Qe.useState(!1),[Oe,fe]=Qe.useState(null),[be,De]=Qe.useState(!1),[_e,Le]=Qe.useState(!1),[qe,Ke]=Qe.useState(null),[Xe,We]=Qe.useState(!1),[Ze,we]=Qe.useState(null),[Je,Me]=Qe.useState([]),[ve,$e]=Qe.useState(!1);Qe.useEffect(()=>((async()=>{const ze=await Ai.waitForVoices();Me(ze)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Me(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const $=Qe.useMemo(()=>Je.filter(H=>H.lang).sort((H,ze)=>{const tt=H.lang.startsWith("en"),Fe=ze.lang.startsWith("en");if(tt&&!Fe)return-1;if(!tt&&Fe)return 1;const at=H.lang.localeCompare(ze.lang);return at!==0?at:H.name.localeCompare(ze.name)}),[Je]),de=Qe.useCallback(()=>{if(ve){Ai.cancelSpeech(),$e(!1);return}const H=Je.find(at=>at.name===I),ze=H?.name??t("settings.voice.page.preview.browserVoiceFallback"),tt=t("settings.voice.page.preview.voiceLine",{voiceName:ze});$e(!0);const Fe=new SpeechSynthesisUtterance(tt);Fe.rate=i,Fe.pitch=l,Fe.volume=d,H&&(Fe.voice=H,Fe.lang=H.lang),Fe.onend=()=>$e(!1),Fe.onerror=()=>$e(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(Fe)},[I,Je,i,l,d,ve,t]);Qe.useEffect(()=>()=>{ve&&Ai.cancelSpeech()},[ve]),Qe.useEffect(()=>{if(!J||a!=="openai"&&a!=="openai-compatible"){De(g.trim().length>0);return}(async()=>{try{const Fe=(await(await dt("/api/tts/status")).json()).available,at=g.trim().length>0;De(Fe||at)}catch{De(g.trim().length>0)}})()},[g,J,a]),Qe.useEffect(()=>{if(!J){je(!1),Ce([]);return}dt("/api/tts/say/status").then(H=>H.json()).then(H=>{if(je(H.available),H.voices){const ze=H.voices.filter((tt,Fe,at)=>at.findIndex(wt=>wt.name===tt.name)===Fe).sort((tt,Fe)=>tt.name.localeCompare(Fe.name));Ce(ze)}}).catch(()=>{je(!1)})},[J]);const ue=Qe.useCallback(async()=>{if(Oe){Ds(Oe),fe(null),Re(!1);return}Re(!0);let H=null;try{const ze=await dt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:c}),voice:c,rate:Math.round(100+(i-.5)*200)})});if(!ze.ok)throw new Error("Preview failed");const tt=await ze.blob(),Fe=URL.createObjectURL(tt);H=new Audio(Fe),H.onended=()=>{Ds(H),fe(null),Re(!1)},H.onerror=()=>{Ds(H),fe(null),Re(!1)},fe(H),await H.play()}catch{Ds(H),fe(null),Re(!1)}},[c,i,Oe,t]);Qe.useEffect(()=>()=>{Ds(Oe)},[Oe]);const ke=Qe.useCallback(async()=>{if(qe){Ds(qe),Ke(null),Le(!1);return}Le(!0);let H=null;try{const ze=await dt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:A}),voice:A,speed:i,apiKey:g||void 0})});if(!ze.ok){const at=await ze.json().catch(()=>({error:"Unknown error"}));throw new Error(at.error||`HTTP ${ze.status}`)}const tt=await ze.blob(),Fe=URL.createObjectURL(tt);H=new Audio(Fe),H.onended=()=>{Ds(H),Ke(null),Le(!1)},H.onerror=()=>{Ds(H),Ke(null),Le(!1)},Ke(H),await H.play()}catch{Ds(H),Ke(null),Le(!1)}},[A,i,qe,g,t]);Qe.useEffect(()=>()=>{Ds(qe)},[qe]);const oe=Qe.useCallback(async()=>{if(Ze){Ds(Ze),we(null),We(!1);return}if(!z.trim())return;We(!0);let H=null;try{const ze=await dt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:O,model:S||void 0,speed:i,baseURL:z,apiKey:R||void 0})});if(!ze.ok){const at=await ze.json().catch(()=>({error:"Unknown error"}));throw new Error(at.error||`HTTP ${ze.status}`)}const tt=await ze.blob(),Fe=URL.createObjectURL(tt);H=new Audio(Fe),H.onended=()=>{Ds(H),we(null),We(!1)},H.onerror=()=>{Ds(H),we(null),We(!1)},we(H),await H.play()}catch{Ds(H),we(null),We(!1)}},[z,O,S,R,i,Ze,t]);Qe.useEffect(()=>()=>{Ds(Ze)},[Ze]);const Ae="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(Ue,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(xt,{checked:J,onChange:ee,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),J&&s.jsxs(s.Fragment,{children:[s.jsx(Js,{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(Bs,{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")},...ie?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:ye(Ot,!be&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:ye(Fn,!be&&"text-[var(--status-error)]/80"),children:t(be&&!g?"settings.voice.page.field.apiKeyHintUsingConfig":be?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:ye("relative",Ks),children:[s.jsx("input",{type:"password",value:g,onChange:H=>w(H.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),g&&s.jsx("button",{type:"button",onClick:()=>w(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Ot,!z.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(ts,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:ye("relative",Ks),children:[s.jsx("input",{type:"text",value:z,onChange:H=>N(H.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"}),z&&s.jsx("button",{type:"button",onClick:()=>N(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:"API Key"}),s.jsx("span",{className:Fn,children:"Optional"}),s.jsxs("div",{className:ye("relative",Ks),children:[s.jsx("input",{type:"password",value:R,onChange:H=>y(H.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"}),R&&s.jsx("button",{type:"button",onClick:()=>y(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Ks),children:s.jsx("input",{type:"text",value:S,onChange:H=>G(H.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:Ot,children:t("settings.voice.page.field.voice")}),s.jsx(ts,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:ye("flex items-center gap-2",Ks),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:O,onChange:H=>q(H.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(V,{size:"xs",variant:"ghost",onClick:oe,title:t("settings.voice.page.actions.preview"),disabled:!z.trim(),children:Xe?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(Ch,{}),s.jsxs(Yt,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Lt,{value:String(m),onValueChange:H=>E(Number.parseInt(H,10)||0),children:[s.jsx(Ft,{size:qt,className:Pn,children:s.jsx($t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:H=>Bi.find(ze=>String(ze.id)===H)?.label??H})}),s.jsx(Kt,{children:Bi.map(H=>s.jsx(pt,{value:String(H.id),children:H.label},H.id))})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:u,title:t("settings.voice.page.actions.preview"),children:x?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})}),C?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:C}):null]}),a==="openai"&&be&&s.jsxs(s.Fragment,{children:[s.jsxs(Lt,{value:A,onValueChange:k,children:[s.jsx(Ft,{size:qt,className:Pn,children:s.jsx($t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Kt,{children:Ph.map(H=>s.jsx(pt,{value:H.value,children:H.label},H.value))})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:ke,title:t("settings.voice.page.actions.preview"),children:_e?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:Fn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&ie&&Se.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Lt,{value:c,onValueChange:j,children:[s.jsx(Ft,{size:qt,className:Pn,children:s.jsx($t,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(Kt,{children:Se.map(H=>s.jsx(pt,{value:H.name,children:H.name},H.name))})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:ue,title:t("settings.voice.page.actions.preview"),children:xe?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&$.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Lt,{value:I||"$auto",onValueChange:H=>F(H==="$auto"?"":H),children:[s.jsx(Ft,{size:qt,className:Pn,children:s.jsx($t,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(Kt,{children:[s.jsx(pt,{value:"$auto",children:t("settings.voice.page.field.auto")}),$.map(H=>s.jsxs(pt,{value:H.name,children:[H.name," (",H.lang,")"]},H.name))]})]}),s.jsx(V,{size:"xs",variant:"ghost",onClick:de,title:t("settings.voice.page.actions.preview"),children:ve?s.jsx(L,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(L,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Yt,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:H=>r(Number(H.target.value)),className:Ae}),s.jsx(Ps,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]}),s.jsxs(Yt,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:H=>h(Number(H.target.value)),className:Ae}),s.jsx(Ps,{value:l,onValueChange:h,min:.5,max:2,step:.1,className:"w-16 tabular-nums"})]}),s.jsxs(Yt,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:d,onChange:H=>b(Number(H.target.value)),className:Ae}),e?s.jsx(Ps,{value:Math.round(d*100),onValueChange:H=>b(H/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(d*100),"%"]})]}),s.jsx(Js,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(Bs,{value:T,onChange:Q,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})})]})]}),s.jsxs(Ue,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(xt,{checked:le,onChange:pe,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),le&&s.jsxs(s.Fragment,{children:[s.jsx(Js,{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(Bs,{value:Z,onChange:K,"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")}]})}),Z==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:t("settings.voice.page.field.model")}),s.jsx(Sh,{selectedModelId:X,onSelect:ne})]}),Z==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:ye(Ot,!ae.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(ts,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:ye("relative",Ks),children:[s.jsx("input",{type:"text",value:ae,onChange:H=>_(H.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"}),ae&&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(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:"API Key"}),s.jsx("span",{className:Fn,children:"Optional"}),s.jsxs("div",{className:ye("relative",Ks),children:[s.jsx("input",{type:"password",value:B,onChange:H=>M(H.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:()=>M(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(L,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Ot,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:ye("relative",Ks),children:s.jsx("input",{type:"text",value:U,onChange:H=>Y(H.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:Ot,children:t("settings.voice.page.field.language")}),s.jsx(ts,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:te,onChange:H=>ge(H.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"})})]})]})]})]})]})},Za=[{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}],Xa=[{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}],Ah="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",Eh="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Gi=[{value:"quick",labelKey:"settings.openchamber.tunnel.option.mode.quick.label",tooltipKey:"settings.openchamber.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.openchamber.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.openchamber.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.openchamber.tunnel.option.mode.managedLocal.tooltip"}],Th=[".yml",".yaml",".json"],Dh="settings.openchamber.tunnel.error.invalidConfigExtension",Ca=t=>{const e=t.trim().toLowerCase();return Th.some(a=>e.endsWith(a))},Mh=t=>t==="ngrok"?"ngrok":"cloudflared",_l=()=>{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"},Rh=(t,e=_l())=>t==="ngrok"?e==="win32"?"winget install ngrok -s msstore":e==="darwin"?"brew install ngrok":"https://ngrok.com/download":e==="win32"?"winget install --id Cloudflare.cloudflared":e==="darwin"?"brew install cloudflared":"https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/",qi=(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():Mh(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():_l(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():Rh(a,i);return{provider:a,dependency:n,installCommand:r}},$l=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,Go=t=>{const e=mt.c(11),{provider:a}=t;let n;e[0]!==a?(n=$l(a),e[0]=a,e[1]=n):n=e[1];const i=n,h=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let d;e[2]!==h?(d=ye("size-4 shrink-0",h),e[2]=h,e[3]=d):d=e[3];let b;e[4]!==d?(b=s.jsx(L,{name:"cloud",className:d}),e[4]=d,e[5]=b):b=e[5];let c;e[6]!==i?(c=s.jsx("span",{children:i}),e[6]=i,e[7]=c):c=e[7];let j;return e[8]!==b||e[9]!==c?(j=s.jsxs("span",{className:"flex items-center gap-2",children:[b,c]}),e[8]=b,e[9]=c,e[10]=j):j=e[10],j},jn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",rr=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,qo=(t,e,a)=>{const n=rr(t,e,a);return t.find(i=>i.value===n)?.label||n},Wo=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`},Oh=(t,e)=>dl(t,e,{hour:"2-digit",precision:"second"}),ai=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()}},Lh=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():"",h=typeof r.name=="string"?r.name.trim():"",d=ai(typeof r.hostname=="string"?r.hostname:"");!l||!h||!d||e.has(l)||a.has(d)||(e.add(l),a.add(d),n.push({id:l,name:h,hostname:d}))}return n},Fh=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,Kh=()=>{const{t}=rt(),e=ce(W=>W.timeFormatPreference),a=o.useCallback(W=>t(W),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[h,d]=o.useState(null),[b,c]=o.useState(null),[j,m]=o.useState(null),[E,v]=o.useState(null),[P,x]=o.useState(!1),[C,u]=o.useState(!1),[I,F]=o.useState(!1),[A,k]=o.useState("cloudflare"),[g,w]=o.useState(()=>qi("cloudflare")),[z,N]=o.useState([]),[R,y]=o.useState("quick"),[O,q]=o.useState(null),[S,G]=o.useState([]),[J,T]=o.useState({}),[Q,Z]=o.useState(""),[K,ae]=o.useState({}),[_,B]=o.useState(new Set),[M,U]=o.useState(!1),[Y,X]=o.useState(""),[ne,te]=o.useState(""),[ge,ee]=o.useState(""),[le,pe]=o.useState(1800*1e3),[ie,je]=o.useState(480*60*1e3),[Se,Ce]=o.useState(""),[xe,Re]=o.useState([]),[Oe,fe]=o.useState(()=>Date.now()),[be,De]=o.useState(null),_e=t(Dh),Le=o.useRef(null),qe=o.useMemo(()=>O?!Ca(O):!1,[O]),Ke=o.useMemo(()=>S.find(W=>W.id===Q)||S[0]||null,[S,Q]),Xe=o.useMemo(()=>xe.map(W=>{const me=W.expiresAt<=Oe,Ee=W.status==="active"&&!me,Pe=Ee?Wo(W.expiresAt-Oe):W.inactiveReason==="expired"||me?"expired":"inactive",lt=Pe==="expired"?t("settings.openchamber.tunnel.state.expired"):W.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),it=jn(W.mode);return{...W,isActive:Ee,mode:it,remainingTextForSession:Pe,inactiveLabel:lt}}),[Oe,xe,t]),We=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Oe:!1,[Oe,r?.bootstrapExpiresAt,r?.connectUrl]),Ze=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:h===R,[h,n,r,R]),we=o.useMemo(()=>!r||n!=="active"||!h?!1:h!==R,[h,n,r,R]),Je=o.useMemo(()=>{if(typeof be=="number"&&Number.isFinite(be)&&be>0)return be;if(typeof window>"u")return null;const me=Oa()||window.location.href;let Ee=0;try{Ee=Number(new URL(me).port)}catch{Ee=Number(window.location.port)}return Number.isFinite(Ee)&&Ee>0?Ee:null},[be]),Me=o.useMemo(()=>z.find(W=>W.provider===A)??null,[z,A]),ve=o.useMemo(()=>{const W=new Set(Me?.modes?.map(me=>me.key).filter(me=>me==="quick"||me==="managed-remote"||me==="managed-local"));return W.size===0?Gi:Gi.filter(me=>W.has(me.value))},[Me]),$e=o.useMemo(()=>ve.some(W=>W.value==="managed-remote"||W.value==="managed-local"),[ve]),$=o.useMemo(()=>g.provider===A?g:qi(A),[g,A]),de=o.useCallback(async W=>{await En(W)},[]),ue=o.useCallback((W,me)=>(w(qi(me,W)),W.available===!0),[]),ke=o.useCallback(async(W,me)=>{try{const Ee=await dt("/api/openchamber/tunnel/check",{query:{provider:W},...me?{signal:me}:{}});if(!Ee.ok)return null;const Pe=await Ee.json();if(me?.aborted)return null;const lt=ue(Pe,W);return i(it=>it==="checking"||it==="starting"||it==="active"||it==="stopping"?it:lt?"idle":"not-available"),lt}catch{return null}},[ue]),oe=o.useCallback(async W=>{try{const[me,Ee,Pe,lt]=await Promise.all([dt("/api/openchamber/tunnel/check",{signal:W}),dt("/api/openchamber/tunnel/status",{signal:W}),dt("/api/config/settings",{signal:W,headers:{Accept:"application/json"}}),dt("/api/openchamber/tunnel/providers",{signal:W})]),it=await me.json(),Ve=await Ee.json(),Nt=Pe.ok?await Pe.json():{},is=lt.ok?await lt.json():{},es=Ve.ttlConfig?.bootstrapTtlMs??(Nt?.tunnelBootstrapTtlMs===null?null:typeof Nt?.tunnelBootstrapTtlMs=="number"?Nt.tunnelBootstrapTtlMs:1800*1e3),ys=typeof Ve.ttlConfig?.sessionTtlMs=="number"?Ve.ttlConfig.sessionTtlMs:typeof Nt?.tunnelSessionTtlMs=="number"?Nt.tunnelSessionTtlMs:480*60*1e3,Ht=jn(Ve.mode??Nt?.tunnelMode),rs=typeof Nt?.tunnelProvider=="string"&&Nt.tunnelProvider.trim().length>0?Nt.tunnelProvider.trim().toLowerCase():"cloudflare",zt=typeof Nt?.managedLocalTunnelConfigPath=="string"&&Nt.managedLocalTunnelConfigPath.trim()||null,fs=ue(it,rs),os=Lh(Ve?.managedRemoteTunnelPresets),ss=typeof Ve.managedRemoteTunnelHostname=="string"?Ve.managedRemoteTunnelHostname:"",ns=os.length>0?os:ss?[{id:`legacy-${ai(ss)}`,name:ss,hostname:ai(ss)}]:[],js=ns[0]?.id||"";if(pe(es),je(ys),k(rs),N(Array.isArray(is?.providers)?is.providers:[]),y(Ht),q(zt),G(ns),Z(js),Re(Array.isArray(Ve.activeSessions)?Ve.activeSessions:[]),d(Ve.activeTunnelMode?jn(Ve.activeTunnelMode):Ve.active&&Ve.mode?jn(Ve.mode):null),B(new Set(Array.isArray(Ve.managedRemoteTunnelTokenPresetIds)?Ve.managedRemoteTunnelTokenPresetIds:[])),De(typeof Ve.localPort=="number"?Ve.localPort:null),Ve.active&&Ve.url){l({url:Ve.url,connectUrl:null,bootstrapExpiresAt:typeof Ve.bootstrapExpiresAt=="number"?Ve.bootstrapExpiresAt:null}),i("active");return}i(fs?"idle":"not-available")}catch{W.aborted||(i("error"),m(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[ue,t]);o.useEffect(()=>{const W=new AbortController;return oe(W.signal),()=>W.abort()},[oe]),o.useEffect(()=>{if(!r?.connectUrl){c(null);return}let W=!1;return yl.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(me=>{W||c(me)}).catch(()=>{W||c(null)}),()=>{W=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){Ce(t("settings.openchamber.tunnel.state.noExpiry"));return}let W=null,me=Date.now();const Ee=()=>{const it=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;it<=0?Ce(t("settings.openchamber.tunnel.state.expired")):Ce(Wo(it))},Pe=()=>{const it=Date.now();it-me>=1e3&&(Ee(),me=it),W=requestAnimationFrame(Pe)};Ee(),(typeof document>"u"||document.visibilityState==="visible")&&(W=requestAnimationFrame(Pe));const lt=()=>{document.visibilityState==="visible"&&W===null?W=requestAnimationFrame(Pe):document.visibilityState!=="visible"&&W!==null&&(cancelAnimationFrame(W),W=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),W!==null&&cancelAnimationFrame(W)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let W=null,me=Date.now();const Ee=()=>{const lt=Date.now();lt-me>=1e3&&(fe(lt),me=lt),W=requestAnimationFrame(Ee)};(typeof document>"u"||document.visibilityState==="visible")&&(W=requestAnimationFrame(Ee));const Pe=()=>{document.visibilityState==="visible"&&W===null?W=requestAnimationFrame(Ee):document.visibilityState!=="visible"&&W!==null&&(cancelAnimationFrame(W),W=null)};return document.addEventListener("visibilitychange",Pe),()=>{document.removeEventListener("visibilitychange",Pe),W!==null&&cancelAnimationFrame(W)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let W=!1;const me=async()=>{try{const Pe=await dt("/api/openchamber/tunnel/status");if(!Pe.ok||W)return;const lt=await Pe.json();if(W)return;Re(Array.isArray(lt.activeSessions)?lt.activeSessions:[]),B(new Set(Array.isArray(lt.managedRemoteTunnelTokenPresetIds)?lt.managedRemoteTunnelTokenPresetIds:[])),De(typeof lt.localPort=="number"?lt.localPort:null)}catch{}},Ee=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||me()},5e3);return()=>{W=!0,window.clearInterval(Ee)}},[n]);const Ae=o.useCallback(async W=>{F(!0);try{await kt(W),Object.prototype.hasOwnProperty.call(W,"tunnelMode")&&W.tunnelMode&&y(W.tunnelMode),Object.prototype.hasOwnProperty.call(W,"tunnelProvider")&&typeof W.tunnelProvider=="string"&&k(W.tunnelProvider),Object.prototype.hasOwnProperty.call(W,"managedLocalTunnelConfigPath")&&q(W.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(W,"managedRemoteTunnelPresets")&&W.managedRemoteTunnelPresets&&G(W.managedRemoteTunnelPresets)}catch{D.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{F(!1)}},[t]),H=o.useCallback(async(W,me)=>{u(!0);try{await kt({tunnelBootstrapTtlMs:W,tunnelSessionTtlMs:me})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{u(!1)}},[t]),ze=o.useCallback(async W=>{const me=W.token.trim();if(me)try{const Ee={...K,[W.presetId]:me};await kt({managedRemoteTunnelPresetTokens:Ee}),B(Pe=>{const lt=new Set(Pe);return lt.add(W.presetId),lt})}catch{D.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[K,t]),tt=o.useCallback(async W=>{v(null),m(null);const me=z.find(Pe=>Pe.provider===W),Ee=me?.modes?.some(Pe=>Pe.key===R)?R:jn(me?.modes?.[0]?.key);await Ae({tunnelProvider:W,tunnelMode:Ee}),ke(W)},[z,ke,Ae,R]),Fe=o.useCallback(async()=>{const W=await hl({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(W.success&&typeof W.path=="string"&&W.path.trim().length>0){const me=W.path.trim();if(!Ca(me)){D.error(_e);return}q(me),await Ae({managedLocalTunnelConfigPath:me});return}Le.current?.click()},[_e,Ae]),at=o.useCallback(W=>{const me=W.trim();q(me.length>0?me:null)},[]),wt=o.useCallback(async()=>{if(O&&!Ca(O)){D.error(_e);return}await Ae({managedLocalTunnelConfigPath:O})},[_e,O,Ae]),bt=o.useCallback(async()=>{q(null),await Ae({managedLocalTunnelConfigPath:null})},[Ae]),ut=o.useCallback(async W=>{const me=W.target.files?.[0];if(!me)return;const Ee=me.name.trim();if(Ee.length!==0){if(!Ca(Ee)){D.error(_e);return}q(Ee),await Ae({managedLocalTunnelConfigPath:Ee}),W.target.value=""}},[_e,Ae]),gt=o.useCallback(async()=>{if(m(null),v(null),R==="managed-local"&&O&&!Ca(O)){m(_e),D.error(_e);return}i("starting");try{let W="",me="";if(R==="managed-remote"){if(!Ke){i("idle"),v(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),D.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}W=Ke.hostname,me=(K[Ke.id]||"").trim(),await Ae({tunnelMode:"managed-remote",managedRemoteTunnelPresets:S})}const Ee=await dt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:A,mode:R,...R==="managed-remote"&&Ke?{managedRemoteTunnelPresetId:Ke.id,managedRemoteTunnelPresetName:Ke.name}:{},...R==="managed-remote"&&W?{managedRemoteTunnelHostname:W}:{},...R==="managed-remote"&&me?{managedRemoteTunnelToken:me}:{},...R==="managed-local"&&O?{configPath:O}:{}})}),Pe=await Ee.json();if(!Ee.ok||!Pe.ok){if(R==="managed-remote"&&typeof Pe.error=="string"&&Pe.error.includes("Managed remote tunnel token is required")){i("idle"),v(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),D.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),m(Pe.error||t("settings.openchamber.tunnel.toast.startFailed")),D.error(Pe.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const lt=typeof Pe.url=="string"?Pe.url:"";if(!lt){i("error"),m(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),D.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:lt,connectUrl:typeof Pe.connectUrl=="string"?Pe.connectUrl:null,bootstrapExpiresAt:typeof Pe.bootstrapExpiresAt=="number"?Pe.bootstrapExpiresAt:null}),d(Pe.activeTunnelMode?jn(Pe.activeTunnelMode):Pe.mode?jn(Pe.mode):R),Re(Array.isArray(Pe.activeSessions)?Pe.activeSessions:[]),Array.isArray(Pe.managedRemoteTunnelTokenPresetIds)&&B(new Set(Pe.managedRemoteTunnelTokenPresetIds)),typeof Pe.localPort=="number"&&De(Pe.localPort),typeof Pe.mode=="string"&&y(jn(Pe.mode)),i("active"),Pe.replacedTunnel){const it=typeof Pe.revokedBootstrapCount=="number"?Pe.revokedBootstrapCount:0,Ve=typeof Pe.invalidatedSessionCount=="number"?Pe.invalidatedSessionCount:0;it===1&&Ve===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):it===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Ve})):Ve===1?D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:it})):D.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:it,invalidatedSessionCount:Ve}))}else D.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{i("error"),m(t("settings.openchamber.tunnel.toast.startFailed")),D.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[_e,S,Ae,Ke,K,t,A,R,O]),Pt=o.useCallback(async()=>{i("stopping");try{await dt("/api/openchamber/tunnel/stop",{method:"POST"});const W=await dt("/api/openchamber/tunnel/status");if(W.ok){const me=await W.json();Re(Array.isArray(me.activeSessions)?me.activeSessions:[]),B(new Set(Array.isArray(me.managedRemoteTunnelTokenPresetIds)?me.managedRemoteTunnelTokenPresetIds:[])),De(typeof me.localPort=="number"?me.localPort:null)}l(null),d(null),c(null),i("idle"),D.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{i("error"),m(t("settings.openchamber.tunnel.toast.stopFailed")),D.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),jt=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),x(!0),D.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>x(!1),2e3)}catch{D.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),Et=o.useCallback(async W=>{const me=Za.find(Ee=>Ee.value===W);me&&(pe(me.ms),await H(me.ms,ie))},[H,ie]),Ye=o.useCallback(async W=>{const me=Xa.find(Ee=>Ee.value===W);!me||me.ms===null||(je(me.ms),await H(le,me.ms))},[le,H]),Ge=o.useCallback(async W=>{v(null),m(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await Ae({tunnelMode:W,managedRemoteTunnelPresets:S})},[S,Ae,n]),ct=o.useCallback(async(W,me)=>{try{await kt({managedRemoteTunnelPresets:me})}catch{D.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),Ie=o.useCallback(W=>{const me=S.find(Ee=>Ee.id===W);me&&(Z(me.id),v(null),ct(me,S))},[S,ct]),It=o.useCallback(async()=>{const W=Y.trim(),me=ai(ne),Ee=ge.trim();if(!W){D.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!me){D.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Ee){D.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(S.some(it=>it.hostname===me)){D.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Pe={id:Fh(),name:W,hostname:me},lt=[...S,Pe];G(lt),Z(Pe.id),T(it=>({...it,[Pe.id]:!0})),ae(it=>({...it,[Pe.id]:Ee})),v(null),U(!1),X(""),te(""),ee(""),await Ae({tunnelMode:"managed-remote",managedRemoteTunnelPresets:lt,managedRemoteTunnelPresetTokens:{...K,[Pe.id]:Ee}}),await ze({presetId:Pe.id,presetName:Pe.name,hostname:Pe.hostname,token:Ee}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[S,ne,Y,ge,ze,Ae,K,t]),Ne=o.useCallback(async W=>{const me=S.find(Ve=>Ve.id===W);if(!me)return;const Ee=S.filter(Ve=>Ve.id!==me.id),Pe=Ee[0]?.id||"",lt=Q===me.id?Pe:Q,it=Object.fromEntries(Object.entries(K).filter(([Ve,Nt])=>Ve!==me.id&&Nt.trim().length>0));G(Ee),Z(lt),T(Ve=>{const Nt={...Ve};return delete Nt[me.id],Nt}),ae(Ve=>{const Nt={...Ve};return delete Nt[me.id],Nt}),B(Ve=>{const Nt=new Set(Ve);return Nt.delete(me.id),Nt}),v(null),await Ae({managedRemoteTunnelPresets:Ee,managedRemoteTunnelPresetTokens:it}),D.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[S,Ae,Q,K,t]),Ct="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(Ue,{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:[Xe.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(L,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Er,children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:Xe.map(W=>{const me=W.mode==="quick",Ee=W.mode==="managed-remote",Pe=me?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Ee?"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=W.isActive?me?"text-[var(--status-warning)]":Ee?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",it=t(me?"settings.openchamber.tunnel.badge.quick":Ee?"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(L,{name:"checkbox-blank-circle-fill",className:ye("size-2.5 shrink-0",lt)}),s.jsx("span",{className:ye("typography-micro rounded border px-1.5 py-0.5 uppercase",Pe),children:it}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:Oh(W.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:W.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:W.remainingTextForSession}):W.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:W.inactiveLabel})})]},W.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(L,{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:Er,children:t("settings.openchamber.tunnel.notAvailable.dependencyNotFound",{dependency:$.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:$.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:Ot,children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(Lt,{value:A,onValueChange:W=>{tt(W)},disabled:I||n==="starting"||n==="stopping",children:[s.jsx(Ft,{size:qt,className:"max-w-[16rem]",children:s.jsx($t,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:$l(A)})}),s.jsxs(Kt,{children:[z.length>0?z.map(W=>s.jsx(pt,{value:W.provider,children:s.jsx(Go,{provider:W.provider})},W.provider)):s.jsx(pt,{value:"cloudflare",children:s.jsx(Go,{provider:"cloudflare"})}),s.jsx(pt,{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:Ot,children:t("settings.openchamber.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:ve.map(W=>s.jsxs(dr,{children:[s.jsx(pr,{asChild:!0,children:s.jsx(V,{variant:"chip",size:"xs","aria-pressed":R===W.value,className:"!font-normal",onClick:()=>{Ge(W.value)},disabled:I||n==="starting"||n==="stopping",children:a(W.labelKey)})}),s.jsx(rl,{sideOffset:8,className:"max-w-xs",children:a(W.tooltipKey)})]},W.value))})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.ttl",className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Ot,"shrink-0"),children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(Lt,{value:rr(Za,le,"1800000"),onValueChange:W=>{Et(W)},disabled:C||I||n==="starting"||n==="stopping",children:[s.jsx(Ft,{size:qt,className:"max-w-[11rem] min-w-0",children:s.jsx($t,{className:"truncate",children:qo(Za,le,"1800000")})}),s.jsx(Kt,{children:Za.map(W=>s.jsx(pt,{value:W.value,children:W.label},W.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:ye(Ot,"shrink-0"),children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(Lt,{value:rr(Xa,ie,"28800000"),onValueChange:W=>{Ye(W)},disabled:C||I||n==="starting"||n==="stopping",children:[s.jsx(Ft,{size:qt,className:"max-w-[11rem] min-w-0",children:s.jsx($t,{className:"truncate",children:qo(Xa,ie,"28800000")})}),s.jsx(Kt,{children:Xa.map(W=>s.jsx(pt,{value:W.value,children:W.label},W.value))})]})]})]}),R==="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(L,{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")}),$e&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),R==="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 Je=="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:",Je]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Xs,{children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>U(W=>!W),disabled:n==="starting"||n==="stopping"||I,children:[s.jsx(L,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),S.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:S.map((W,me)=>{const Ee=K[W.id]||"",Pe=_.has(W.id),lt=J[W.id]??!1;return s.jsx("div",{className:ye(me<S.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(Gn,{open:lt,onOpenChange:it=>{T(Ve=>({...Ve,[W.id]:it})),it&&Ie(W.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(qn,{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"||I,children:[lt?s.jsx(L,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(L,{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:W.name})]}),s.jsx(V,{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:W.name}),onClick:()=>{Ne(W.id)},disabled:n==="starting"||n==="stopping"||I,children:s.jsx(L,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(Wn,{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:W.hostname})]}),s.jsx(He,{type:"password",value:Ee,onChange:it=>{const Ve=it.target.value;v(null),ae(Nt=>({...Nt,[W.id]:Ve}))},onBlur:it=>{const Ve=it.currentTarget.value.trim();Ve&&ze({presetId:W.id,presetName:W.name,hostname:W.hostname,token:Ve})},placeholder:t(Pe?"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(V,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Ee.trim().length===0,onClick:()=>{ze({presetId:W.id,presetName:W.name,hostname:W.hostname,token:Ee})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},W.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),M&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(He,{value:Y,onChange:W=>X(W.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:I||n==="starting"||n==="stopping"}),s.jsx(He,{value:ne,onChange:W=>te(W.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:I||n==="starting"||n==="stopping"}),s.jsx(He,{type:"password",value:ge,onChange:W=>ee(W.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:I||n==="starting"||n==="stopping"}),typeof Je=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Je]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{It()},disabled:I||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(V,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{U(!1),X(""),te(""),ee("")},disabled:I||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(ts,{children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]}),!Ke&&E&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:E})]}),R==="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:Ot,children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Le,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:W=>{ut(W)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{value:O||"",onChange:W=>{at(W.target.value)},onBlur:()=>{wt()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||I}),s.jsx(V,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{Fe()},disabled:n==="starting"||n==="stopping"||I,children:s.jsx(L,{name:"folder",className:"size-3.5"})}),O&&s.jsx(V,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{bt()},disabled:n==="starting"||n==="stopping"||I,children:s.jsx(L,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(O?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),qe&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:_e})]})}),!Ze&&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(L,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[R==="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:()=>{de(Ah)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(L,{name:"external-link",className:"size-3.5"})]})]}),R==="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:()=>{de(Eh)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(L,{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(Gi.find(W=>W.value===R)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),R==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Ot,children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Lt,{value:Q||(S[0]?.id??""),onValueChange:W=>{Ie(W)},disabled:I||n==="starting"||n==="stopping"||S.length<=1,children:[s.jsx(Ft,{size:qt,children:s.jsx($t,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Ke?.name})}),s.jsx(Kt,{fitContent:!0,children:S.map(W=>s.jsx(pt,{value:W.id,children:W.name},W.id))})]})]}),we&&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(L,{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(V,{size:"sm",variant:"outline",onClick:gt,disabled:n==="starting"||I||R==="managed-remote"&&!Ke||R==="managed-local"&&qe,className:ye(Ct,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),Ze&&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(V,{size:"sm",variant:"ghost",onClick:jt,className:"shrink-0 gap-1.5",children:[P?s.jsx(L,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(L,{name:"file-copy",className:"size-3.5"}),t(P?"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?Se: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:[b?s.jsx("img",{src:b,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(V,{size:"sm",variant:"outline",onClick:gt,disabled:n==="stopping"||I||R==="managed-local"&&qe,className:Ct,children:[s.jsx(L,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(V,{size:"sm",variant:"ghost",onClick:Pt,disabled:n==="stopping"||I,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(L,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.stopping")]}):t("settings.openchamber.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&j&&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:j}),s.jsx(V,{size:"sm",variant:"ghost",onClick:gt,children:t("settings.openchamber.tunnel.actions.retry")})]})]})})},Vl=()=>{const{t}=rt(),[e,a]=Qe.useState(""),[n,i]=Qe.useState(!0),[r,l]=Qe.useState(!1),h=ce(m=>m.showOpenCodeUpdateNotifications),d=ce(m=>m.setShowOpenCodeUpdateNotifications);Qe.useEffect(()=>{let m=!1;return(async()=>{try{const E=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!E.ok)return;const v=await E.json().catch(()=>null);if(m||!v)return;const P=typeof v.opencodeBinary=="string"?v.opencodeBinary.trim():"";a(P)}catch{}finally{m||i(!1)}})(),()=>{m=!0}},[]);const b=Qe.useCallback(async()=>{if(!(typeof window>"u")&&hs())try{const m=await hl();m.success&&m.path&&m.path.trim().length>0&&a(m.path.trim())}catch{}},[]),c=Qe.useCallback(async()=>{l(!0);try{const m=e.trim(),E=m.length>=2&&(m.startsWith('"')&&m.endsWith('"')||m.startsWith("'")&&m.endsWith("'"))?m.slice(1,-1).trim():m;await kt({opencodeBinary:E}),zn("cli",{id:"opencode-binary"}),D.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),j=Qe.useCallback(m=>{d(m),kt({showOpenCodeUpdateNotifications:m})},[d]);return s.jsx(Ue,{title:t("settings.openchamber.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Yt,{settingsItem:"sessions.opencode-binary",label:t("settings.openchamber.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(He,{value:e,onChange:m=>a(m.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(V,{type:"button",variant:"outline",size:"xs",onClick:b,disabled:n||r||!hs(),className:vs,"aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(L,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(ra,{className:Ss,children:[!fl()&&s.jsx(xt,{settingsItem:"sessions.opencode-update-notifications",checked:h,onChange:j,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(V,{type:"button",size:"xs",onClick:c,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},Bl=()=>{const t=mt.c(44),{t:e}=rt(),a=ce(Uh),n=ce(zh),i=ce(_h),r=ce($h),l=ce(Vh),h=ce(Bh),d=ce(Hh);let b;t[0]!==n?(b=R=>{n(R),kt({agentControlToolEnabled:R}),zn("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=b):b=t[1];const c=b;let j;t[2]!==r?(j=R=>{r(R),kt({agentWebToolEnabled:R}),zn("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=j):j=t[3];const m=j;let E;t[4]!==d?(E=R=>{d(R),kt({agentMemoryToolEnabled:R}).finally(()=>{R&&zc.getState().refresh()}),zn("cli",{id:"agent-memory-tool"})},t[4]=d,t[5]=E):E=t[5];const v=E;let P;t[6]!==e?(P=e("settings.openchamber.tools.title"),t[6]=e,t[7]=P):P=t[7];let x;t[8]!==e?(x=e("settings.openchamber.tools.field.agentControlTool"),t[8]=e,t[9]=x):x=t[9];let C;t[10]!==e?(C=e("settings.openchamber.tools.field.agentControlToolAria"),t[10]=e,t[11]=C):C=t[11];let u;t[12]!==e?(u=e("settings.openchamber.tools.field.agentControlToolInfo"),t[12]=e,t[13]=u):u=t[13];let I;t[14]!==a||t[15]!==c||t[16]!==x||t[17]!==C||t[18]!==u?(I=s.jsx(xt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:c,label:x,ariaLabel:C,info:u}),t[14]=a,t[15]=c,t[16]=x,t[17]=C,t[18]=u,t[19]=I):I=t[19];let F;t[20]!==e?(F=e("settings.openchamber.tools.field.agentWebTool"),t[20]=e,t[21]=F):F=t[21];let A;t[22]!==e?(A=e("settings.openchamber.tools.field.agentWebToolAria"),t[22]=e,t[23]=A):A=t[23];let k;t[24]!==e?(k=e("settings.openchamber.tools.field.agentWebToolInfo"),t[24]=e,t[25]=k):k=t[25];let g;t[26]!==i||t[27]!==m||t[28]!==k||t[29]!==F||t[30]!==A?(g=s.jsx(xt,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:m,label:F,ariaLabel:A,info:k}),t[26]=i,t[27]=m,t[28]=k,t[29]=F,t[30]=A,t[31]=g):g=t[31];let w;t[32]!==h||t[33]!==l||t[34]!==v||t[35]!==e?(w=h?s.jsx(xt,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:v,label:e("settings.openchamber.tools.field.agentMemoryTool"),ariaLabel:e("settings.openchamber.tools.field.agentMemoryToolAria"),info:e("settings.openchamber.tools.field.agentMemoryToolInfo")}):null,t[32]=h,t[33]=l,t[34]=v,t[35]=e,t[36]=w):w=t[36];let z;t[37]!==g||t[38]!==w||t[39]!==I?(z=s.jsxs("div",{className:Ss,children:[I,g,w]}),t[37]=g,t[38]=w,t[39]=I,t[40]=z):z=t[40];let N;return t[41]!==z||t[42]!==P?(N=s.jsx(Ue,{title:P,children:z}),t[41]=z,t[42]=P,t[43]=N):N=t[43],N};function Uh(t){return t.agentControlToolEnabled}function zh(t){return t.setAgentControlToolEnabled}function _h(t){return t.agentWebToolEnabled}function $h(t){return t.setAgentWebToolEnabled}function Vh(t){return t.agentMemoryToolEnabled}function Bh(t){return t.agentMemoryFeatureAvailable}function Hh(t){return t.setAgentMemoryToolEnabled}const Hl=()=>{const{t}=rt(),e=hs()&&La(),a=e&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",[n,i]=Qe.useState(!1),[r,l]=Qe.useState(!1),[h,d]=Qe.useState(""),[b,c]=Qe.useState(""),[j,m]=Qe.useState(!1),[E,v]=Qe.useState(!1),[P,x]=Qe.useState(null),[C,u]=Qe.useState(!0),[I,F]=Qe.useState(!1),[A,k]=Qe.useState(!1),[g,w]=Qe.useState(!1),[z,N]=Qe.useState(!1),[R,y]=Qe.useState(!1),[O,q]=Qe.useState(!1),[S,G]=Qe.useState(!1),[J,T]=Qe.useState(!0),[Q,Z]=Qe.useState(!0),[K,ae]=Qe.useState(!1),[_,B]=Qe.useState(!1),[M,U]=Qe.useState(!1),[Y,X]=Qe.useState(null),[ne,te]=Qe.useState(null);Qe.useEffect(()=>{if(!e){u(!1);return}let fe=!1;return(async()=>{try{const be=await dt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!be.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const De=await be.json().catch(()=>null);if(fe)return;const _e=De?.desktopLanAccessEnabled===!0,Le=typeof De?.desktopUiPassword=="string"?De.desktopUiPassword:"";i(_e),l(_e),d(Le),c(Le),v(De?.desktopLanAccessActive===!0),x(typeof De?.desktopLanAccessBlockedReason=="string"?De.desktopLanAccessBlockedReason:null);const qe=De?.desktopMacMenuBarEnabled!==!1;T(qe),Z(qe),X(null)}catch(be){fe||X(be instanceof Error?be.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{fe||u(!1)}})(),()=>{fe=!0}},[e,t]),Qe.useEffect(()=>{if(!e){k(!1);return}let fe=!1;return(async()=>{const be=await ud();fe||(k(be?.supported===!0),w(be?.enabled===!0))})(),()=>{fe=!0}},[e]),Qe.useEffect(()=>{if(!e){y(!1);return}let fe=!1;return(async()=>{const be=await gd();fe||(y(be?.supported===!0),q(be?.enabled===!0))})(),()=>{fe=!0}},[e]),Qe.useEffect(()=>{if(!e){ae(!1);return}let fe=!1;return(async()=>{const be=await hd();fe||(ae(be?.supported===!0),B(be?.enabled===!0))})(),()=>{fe=!0}},[e]),Qe.useEffect(()=>{if(!e||!r){te(null);return}let fe=!1;return(async()=>{const be=await ul();fe||te(be)})(),()=>{fe=!0}},[r,e]);const ge=r!==n||b!==h||Q!==J,ee=Qe.useMemo(()=>{if(typeof window>"u")return null;const be=Oa()||window.location.href;let De=0;try{De=Number(new URL(be).port)}catch{De=Number(window.location.port)}return Number.isFinite(De)&&De>0?De:null},[]),le=r&&E&&ne&&ee?`http://${ne}:${ee}`:null,pe=r&&!b.trim(),ie=n&&!E&&P==="missing-password",je=C||I||!ge||pe,Se=Qe.useCallback(fe=>{c(fe),fe.trim()||l(!1)},[]),Ce=Qe.useCallback(async()=>{if(!A||z)return;const fe=!g;w(fe),N(!0),X(null);try{const be=await fd(fe);if(!be?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported"));w(be.enabled)}catch(be){w(!fe),X(be instanceof Error?be.message:t("settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{N(!1)}},[z,g,A,t]),xe=Qe.useCallback(async()=>{if(!R||S)return;const fe=!O;q(fe),G(!0),X(null);try{const be=await xd(fe);if(!be)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"));if(!be.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.minimizeToTrayUnsupported"));q(be.enabled)}catch(be){q(!fe),X(be instanceof Error?be.message:t("settings.openchamber.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{G(!1)}},[S,O,R,t]),Re=Qe.useCallback(async()=>{if(!K||M)return;const fe=!_;B(fe),U(!0),X(null);try{const be=await bd(fe);if(!be?.supported)throw new Error(t("settings.openchamber.desktopNetwork.error.keepAwakeUnsupported"));B(be.enabled)}catch(be){B(!fe),X(be instanceof Error?be.message:t("settings.openchamber.desktopNetwork.error.keepAwakeSaveFailed"))}finally{U(!1)}},[M,_,K,t]),Oe=Qe.useCallback(async()=>{if(ge){F(!0),X(null);try{if(!(await dt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:b,desktopMacMenuBarEnabled:Q})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(i(r),d(b),T(Q),!await vd())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(fe){X(fe instanceof Error?fe.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),F(!1)}}},[Q,b,r,ge,t]);return e?s.jsx(Ue,{title:t("settings.openchamber.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[A||a||R||K?s.jsxs("div",{className:Ss,children:[A?s.jsx(xt,{settingsItem:"sessions.desktop-launch-at-login",checked:g,onChange:fe=>{fe!==g&&Ce()},disabled:z,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(xt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:Q,onChange:Z,disabled:C||I,label:t("settings.openchamber.desktopNetwork.field.macMenuBar"),info:t("settings.openchamber.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.macMenuBarAria")}):null,R?s.jsx(xt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:O,onChange:fe=>{fe!==O&&xe()},disabled:S,label:t("settings.openchamber.desktopNetwork.field.minimizeToTray"),info:t("settings.openchamber.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.openchamber.desktopNetwork.field.minimizeToTrayAria")}):null,K?s.jsx(xt,{settingsItem:"sessions.desktop-keep-awake",checked:_,onChange:fe=>{fe!==_&&Re()},disabled:M,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(Zt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.openchamber.desktopPassword.field.password")}),info:t("settings.openchamber.desktopPassword.field.passwordDescription"),children:[s.jsx(He,{id:"desktop-ui-password",type:j?"text":"password",className:"h-8 min-w-0 flex-1",value:b,onChange:fe=>Se(fe.target.value),placeholder:t("settings.openchamber.desktopPassword.field.passwordPlaceholder"),disabled:C||I,required:r,"aria-invalid":pe}),s.jsx(V,{type:"button",variant:"ghost",size:"xs",onClick:()=>m(fe=>!fe),className:vs,"aria-label":t(j?"settings.openchamber.desktopPassword.actions.hidePassword":"settings.openchamber.desktopPassword.actions.showPassword"),"aria-pressed":j,children:s.jsx(L,{name:j?"eye-off":"eye",className:"h-4 w-4"})})]}),s.jsx("div",{className:Ss,children:s.jsx(xt,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:C||I,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")}),pe||ie?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,le?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(ge&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:le})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(V,{type:"button",size:"xs",onClick:Oe,disabled:je,className:"shrink-0 !font-normal",children:t(I?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})}):null},Gl=new Set(["shift","control","alt","meta"]),Gh=t=>{if(Gl.has(t.key.toLowerCase()))return null;const e=[];(t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt");const a=pl(t.key);return a?(e.push(a),ln(e.join("+"))):null},qh=t=>{const e=[];if((t.metaKey||t.ctrlKey)&&e.push("mod"),t.shiftKey&&e.push("shift"),t.altKey&&e.push("alt"),Gl.has(t.key.toLowerCase()))return e.length>0?ln(e.join("+")):null;const a=pl(t.key);return a?(e.push(a),e.length>0?ln(e.join("+")):null):null},Wh=()=>{const t=mt.c(54),{t:e}=rt();let a;t[0]!==e?(a=M=>e(M),t[0]=e,t[1]=a):a=t[1];const n=a,i=ce(Jh),r=ce(Qh),l=ce(Yh),h=ce(Zh);let d;if(t[2]===Symbol.for("react.memo_cache_sentinel")){e:{const M=_c();if(!xs()){d=M;break e}d=M.filter(Xh)}t[2]=d}else d=t[2];const b=d;let c;t[3]!==n?(c=(M,U)=>{const Y=`settings.openchamber.keyboardShortcuts.action.${M}.label`,X=n(Y);return X===Y?U:X},t[3]=n,t[4]=c):c=t[4];const j=c,[m,E]=o.useState(null);let v;t[5]===Symbol.for("react.memo_cache_sentinel")?(v={},t[5]=v):v=t[5];const[P,x]=o.useState(v),[C,u]=o.useState(""),[I,F]=o.useState(""),[A,k]=o.useState(null),g=ef;let w;t[6]!==i?(w=(M,U)=>{const Y=ln(U);for(const X of b){if(X.id===M)continue;const ne=Tr(X.id,i);if(ln(ne)===Y)return X.id}return null},t[6]=i,t[7]=w):w=t[7];const z=w;let N;t[8]!==z||t[9]!==r||t[10]!==i||t[11]!==e?(N=(M,U)=>{const Y=ln(U),X=z(M,Y);if(X){k({actionId:M,combo:Y,conflictActionId:X}),u("");return}const ne={...i,[M]:Y};r(M,Y),g(ne),k(null),u(""),F(Mr(Y)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(te=>{const ge={...te};return delete ge[M],ge})},t[8]=z,t[9]=r,t[10]=i,t[11]=e,t[12]=N):N=t[12];const R=N;let y;t[13]!==A||t[14]!==r||t[15]!==i||t[16]!==e?(y=()=>{if(!A)return;const M={...i,[A.conflictActionId]:Ei,[A.actionId]:A.combo};r(A.conflictActionId,Ei),r(A.actionId,A.combo),g(M),k(null),u(""),F(Mr(A.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(U=>{const Y={...U};return delete Y[A.actionId],Y})},t[13]=A,t[14]=r,t[15]=i,t[16]=e,t[17]=y):y=t[17];const O=y;let q;t[18]!==l||t[19]!==i?(q=M=>{const U={...i};delete U[M],l(M),g(U),x(Y=>{const X={...Y};return delete X[M],X}),k(null),u(""),F("")},t[18]=l,t[19]=i,t[20]=q):q=t[20];const S=q;let G;t[21]!==e?(G=e("settings.openchamber.keyboardShortcuts.title"),t[21]=e,t[22]=G):G=t[22];let J;t[23]!==e?(J=e("settings.openchamber.keyboardShortcuts.tooltip"),t[23]=e,t[24]=J):J=t[24];let T;t[25]!==h?(T=()=>{h(),g({}),x({}),k(null),u(""),F("")},t[25]=h,t[26]=T):T=t[26];let Q;t[27]!==e?(Q=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[27]=e,t[28]=Q):Q=t[28];let Z;t[29]!==T||t[30]!==Q?(Z=s.jsx(V,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:T,children:Q}),t[29]=T,t[30]=Q,t[31]=Z):Z=t[31];let K;t[32]!==O||t[33]!==C||t[34]!==A||t[35]!==e||t[36]!==I?(K=(C||I||A)&&s.jsxs("div",{className:"mb-2 space-y-2",children:[A&&s.jsxs("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 flex flex-col @xl:flex-row @xl:items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-foreground",children:e("settings.openchamber.keyboardShortcuts.overwritePrompt")}),s.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.jsx(V,{type:"button",size:"xs",className:"!font-normal",onClick:O,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(V,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>k(null),children:e("settings.common.actions.cancel")})]})]}),C&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:C}),I&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:I})]}),t[32]=O,t[33]=C,t[34]=A,t[35]=e,t[36]=I,t[37]=K):K=t[37];let ae;t[38]!==j||t[39]!==m||t[40]!==P||t[41]!==S||t[42]!==R||t[43]!==i||t[44]!==e?(ae=b.map((M,U)=>{const Y=M.id==="switch_context_surface",X=Y?$c(M.id,i):Tr(M.id,i),ne=P[M.id],te=ne??X,ge=typeof ne=="string"&&ln(ne)!==ln(X),ee=te===""||ln(te)===Ei,le=m===M.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):Y&&!ee?`${Dr(te)}${e("settings.openchamber.keyboardShortcuts.action.switch_context_surface.suffix")}`:Dr(te);return s.jsx("div",{className:ye("py-1.5",U>0&&"border-t border-border/40"),children:s.jsxs(Yt,{label:j(M.id,M.label),alignEnd:!1,children:[s.jsx(He,{readOnly:!0,value:le,onFocus:()=>{E(M.id),u("")},onBlur:()=>{m===M.id&&E(null)},onKeyDown:pe=>{if(pe.preventDefault(),pe.stopPropagation(),pe.key==="Escape"){E(null);return}const ie=Y?qh(pe):Gh(pe);ie&&(x(je=>({...je,[M.id]:ie})),E(null),k(null),u(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(V,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const pe=P[M.id];if(!pe){u(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}R(M.id,pe)},disabled:!ge,children:e("settings.common.actions.saveChanges")}),s.jsx(V,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>S(M.id),children:e("settings.common.actions.reset")})]})},M.id)}),t[38]=j,t[39]=m,t[40]=P,t[41]=S,t[42]=R,t[43]=i,t[44]=e,t[45]=ae):ae=t[45];let _;t[46]!==ae?(_=s.jsx("div",{children:ae}),t[46]=ae,t[47]=_):_=t[47];let B;return t[48]!==Z||t[49]!==K||t[50]!==_||t[51]!==G||t[52]!==J?(B=s.jsxs(Ue,{settingsItem:"shortcuts.keyboard-shortcuts",title:G,divider:!1,info:J,headerAction:Z,children:[K,_]}),t[48]=Z,t[49]=K,t[50]=_,t[51]=G,t[52]=J,t[53]=B):B=t[53],B};function Jh(t){return t.shortcutOverrides}function Qh(t){return t.setShortcutOverride}function Yh(t){return t.clearShortcutOverride}function Zh(t){return t.resetAllShortcutOverrides}function Xh(t){return t.id!=="toggle_prompt_navigator"}function ef(t){kt({shortcutOverrides:t})}const ql=()=>{const t=mt.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>gl(()=>a(uf)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},tf=t=>{const e=mt.c(80),{section:a}=t,{t:n}=rt(),{isMobile:i}=oa();ql();let r;e[0]!==i?(r=i&&In(),e[0]=i,e[1]=r):r=e[1];const l=r;let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=xs(),e[2]=h):h=e[2];const d=h;let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=hs()&&La(),e[3]=b):b=e[3];const c=b;if(!a){let K,ae,_,B,M,U,Y,X;e[4]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(ci,{}),B=s.jsx(zl,{}),M=c&&s.jsx(Hl,{}),U=!d&&s.jsx(Vl,{}),Y=!d&&s.jsx(Bl,{}),X=s.jsx(Fl,{}),K=s.jsx(Ul,{}),ae=In()&&!hs()&&!d&&!xl()&&s.jsx(Kl,{}),e[4]=K,e[5]=ae,e[6]=_,e[7]=B,e[8]=M,e[9]=U,e[10]=Y,e[11]=X):(K=e[4],ae=e[5],_=e[6],B=e[7],M=e[8],U=e[9],Y=e[10],X=e[11]);let ne;e[12]!==l?(ne=l&&s.jsx(jl,{}),e[12]=l,e[13]=ne):ne=e[13];let te;return e[14]!==ne?(te=s.jsxs(cs,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[_,B,M,U,Y,X,K,ae,ne]}),e[14]=ne,e[15]=te):te=e[15],te}let j;e[16]!==a?(j=()=>{switch(a){case"general":return s.jsx(nf,{});case"visual":return s.jsx(af,{});case"chat":return s.jsx(rf,{});case"sessions":return s.jsx(of,{});case"shortcuts":return s.jsx(sf,{});case"git":return s.jsx(lf,{});case"github":return s.jsx(cf,{});case"notifications":return s.jsx(df,{});case"voice":return s.jsx(pf,{});case"tunnel":return s.jsx(mf,{});default:return null}},e[16]=a,e[17]=j):j=e[17];const m=j;let E;e[18]!==n?(E=n("settings.page.general.title"),e[18]=n,e[19]=E):E=e[19];let v;e[20]!==n?(v=n("settings.page.appearance.title"),e[20]=n,e[21]=v):v=e[21];let P;e[22]!==n?(P=n("settings.page.chat.title"),e[22]=n,e[23]=P):P=e[23];let x;e[24]!==n?(x=n("settings.page.sessions.title"),e[24]=n,e[25]=x):x=e[25];let C;e[26]!==n?(C=n("settings.page.shortcuts.title"),e[26]=n,e[27]=C):C=e[27];let u;e[28]!==n?(u=n("settings.page.git.title"),e[28]=n,e[29]=u):u=e[29];let I;e[30]!==n?(I=n("settings.page.git.title"),e[30]=n,e[31]=I):I=e[31];let F;e[32]!==n?(F=n("settings.page.notifications.title"),e[32]=n,e[33]=F):F=e[33];let A;e[34]!==n?(A=n("settings.page.voice.title"),e[34]=n,e[35]=A):A=e[35];let k;e[36]!==n?(k=n("settings.page.tunnel.title"),e[36]=n,e[37]=k):k=e[37];let g;e[38]!==u||e[39]!==I||e[40]!==F||e[41]!==A||e[42]!==k||e[43]!==E||e[44]!==v||e[45]!==P||e[46]!==x||e[47]!==C?(g={general:E,visual:v,chat:P,sessions:x,shortcuts:C,git:u,github:I,notifications:F,voice:A,tunnel:k},e[38]=u,e[39]=I,e[40]=F,e[41]=A,e[42]=k,e[43]=E,e[44]=v,e[45]=P,e[46]=x,e[47]=C,e[48]=g):g=e[48];const w=g[a];let z;e[49]!==n?(z=n("settings.page.general.description"),e[49]=n,e[50]=z):z=e[50];let N;e[51]!==n?(N=n("settings.page.appearance.description"),e[51]=n,e[52]=N):N=e[52];let R;e[53]!==n?(R=n("settings.page.chat.description"),e[53]=n,e[54]=R):R=e[54];let y;e[55]!==n?(y=n("settings.page.sessions.description"),e[55]=n,e[56]=y):y=e[56];let O;e[57]!==n?(O=n("settings.page.shortcuts.description"),e[57]=n,e[58]=O):O=e[58];let q;e[59]!==n?(q=n("settings.page.notifications.description"),e[59]=n,e[60]=q):q=e[60];let S;e[61]!==n?(S=n("settings.page.voice.description"),e[61]=n,e[62]=S):S=e[62];let G;e[63]!==n?(G=n("settings.page.tunnel.description"),e[63]=n,e[64]=G):G=e[64];let J;e[65]!==z||e[66]!==N||e[67]!==R||e[68]!==y||e[69]!==O||e[70]!==q||e[71]!==S||e[72]!==G?(J={general:z,visual:N,chat:R,sessions:y,shortcuts:O,git:void 0,github:void 0,notifications:q,voice:S,tunnel:G},e[65]=z,e[66]=N,e[67]=R,e[68]=y,e[69]=O,e[70]=q,e[71]=S,e[72]=G,e[73]=J):J=e[73];const T=J[a];let Q;e[74]!==m?(Q=m(),e[74]=m,e[75]=Q):Q=e[75];let Z;return e[76]!==T||e[77]!==w||e[78]!==Q?(Z=s.jsx(cs,{title:w,description:T,showSaveStatus:!0,className:"openchamber-page-body",children:Q}),e[76]=T,e[77]=w,e[78]=Q,e[79]=Z):Z=e[79],Z},sf=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Wh,{}),t[0]=e):e=t[0],e},nf=()=>{const t=mt.c(9);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=xs(),t[0]=e):e=t[0];const a=e;ql();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=hs()&&La(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=In()&&!hs()&&!a&&!xl(),t[2]=r):r=t[2];const l=r;let h,d,b,c,j;t[3]===Symbol.for("react.memo_cache_sentinel")?(h=i&&s.jsx(Hl,{}),d=l&&s.jsx(Kl,{}),b=s.jsx(Ul,{}),c=!a&&s.jsx(Vl,{}),j=!a&&s.jsx(Bl,{}),t[3]=h,t[4]=d,t[5]=b,t[6]=c,t[7]=j):(h=t[3],d=t[4],b=t[5],c=t[6],j=t[7]);let m;return t[8]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsxs(s.Fragment,{children:[h,d,b,c,j,s.jsx(ci,{visibleSettings:["fileEditorKeymap","autoSaveEnabled","expandedEditorToolbar",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[8]=m):m=t[8],m},af=()=>{const t=mt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=xs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(ci,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","inputBarOffset"]}),t[1]=n):n=t[1],n},rf=()=>{const t=mt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=xs(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(ci,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck"]}),t[1]=n):n=t[1],n},of=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(zl,{}),s.jsx(Fl,{})]}),t[0]=e):e=t[0],e},lf=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ol,{}),t[0]=e):e=t[0],e},cf=()=>{const t=mt.c(1);if(xs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ll,{}),t[0]=e):e=t[0],e},df=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(kh,{}),t[0]=e):e=t[0],e},pf=()=>{const t=mt.c(1);if(xs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ih,{}),t[0]=e):e=t[0],e},mf=()=>{const t=mt.c(1);if(xs())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Kh,{}),t[0]=e):e=t[0],e};function uf(t){return t+1}const gf=t=>{const e=mt.c(85),{className:a}=t,{t:n}=rt(),i=pn(ml),r=pn(hf),l=ce(ff),h=ce(xf),[d,b]=Qe.useState(!1),[c,j]=Qe.useState(!1),m=i>0;let E;e[0]!==n?(E=async()=>{try{const Se=await Vc({message:n("settings.view.pendingRestart.applying")});if(Se.requiresManualRestart){D.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Se.ok&&D.success(n("settings.view.pendingRestart.applied"))}catch(Se){const Ce=Se,xe=Ce instanceof Error&&Ce.message?Ce.message:n("settings.view.pendingRestart.applyFailed");D.error(xe)}},e[0]=n,e[1]=E):E=e[1];const v=E;let P;e[2]!==n?(P=async()=>{try{await Bc({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),pn.getState().clear()}catch{}},e[2]=n,e[3]=P):P=e[3];const x=P;let C;e[4]!==c||e[5]!==v||e[6]!==h?(C=()=>{c&&h(!1),b(!1),j(!1),v()},e[4]=c,e[5]=v,e[6]=h,e[7]=C):C=e[7];const u=C;let I;e[8]!==m||e[9]!==v||e[10]!==x||e[11]!==l?(I=()=>{if(!m){x();return}if(l){j(!1),b(!0);return}v()},e[8]=m,e[9]=v,e[10]=x,e[11]=l,e[12]=I):I=e[12];const F=I;let A;e[13]!==m||e[14]!==r||e[15]!==n?(A=n(m?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=m,e[14]=r,e[15]=n,e[16]=A):A=e[16];const k=A;let g;e[17]!==m||e[18]!==i||e[19]!==n?(g=m?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=m,e[18]=i,e[19]=n,e[20]=g):g=e[20];const w=g,z=m?"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",N=r&&"opacity-80";let R;e[21]!==a||e[22]!==z||e[23]!==N?(R=ye("flex w-full items-center gap-2 rounded-md overflow-hidden whitespace-nowrap","h-11 px-3 sm:h-8 sm:px-2","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",z,N,a),e[21]=a,e[22]=z,e[23]=N,e[24]=R):R=e[24];let y;e[25]!==m||e[26]!==i?(y=m?s.jsx("span",{className:ye("inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1.5","bg-background text-foreground typography-micro font-semibold tabular-nums"),"aria-hidden":"true",children:i}):s.jsx(L,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=m,e[26]=i,e[27]=y):y=e[27];let O;e[28]!==k?(O=s.jsx("span",{className:"truncate",children:k}),e[28]=k,e[29]=O):O=e[29];let q;e[30]!==F||e[31]!==r||e[32]!==y||e[33]!==O||e[34]!==R||e[35]!==w?(q=s.jsxs("button",{type:"button",disabled:r,title:w,"aria-label":w,onClick:F,className:R,children:[y,O]}),e[30]=F,e[31]=r,e[32]=y,e[33]=O,e[34]=R,e[35]=w,e[36]=q):q=e[36];let S;e[37]===Symbol.for("react.memo_cache_sentinel")?(S=Se=>{b(Se),Se||j(!1)},e[37]=S):S=e[37];let G;e[38]!==n?(G=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=G):G=e[39];let J;e[40]!==G?(J=s.jsx(Jt,{children:G}),e[40]=G,e[41]=J):J=e[41];let T;e[42]!==n?(T=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=T):T=e[43];let Q;e[44]!==T?(Q=s.jsx(Qt,{children:T}),e[44]=T,e[45]=Q):Q=e[45];let Z;e[46]!==J||e[47]!==Q?(Z=s.jsxs(Wt,{children:[J,Q]}),e[46]=J,e[47]=Q,e[48]=Z):Z=e[48];let K;e[49]===Symbol.for("react.memo_cache_sentinel")?(K={width:"40%"},e[49]=K):K=e[49];let ae;e[50]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>b(!1),e[50]=ae):ae=e[50];let _;e[51]!==n?(_=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=_):_=e[52];let B;e[53]!==_?(B=s.jsx("div",{className:"min-w-0 shrink-0",style:K,children:s.jsx(V,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:ae,children:_})}),e[53]=_,e[54]=B):B=e[54];let M;e[55]===Symbol.for("react.memo_cache_sentinel")?(M={width:"40%"},e[55]=M):M=e[55];let U;e[56]!==n?(U=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=U):U=e[57];let Y;e[58]!==u||e[59]!==U?(Y=s.jsx("div",{className:"min-w-0 shrink-0",style:M,children:s.jsx(V,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:u,children:U})}),e[58]=u,e[59]=U,e[60]=Y):Y=e[60];let X;e[61]!==B||e[62]!==Y?(X=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[B,Y]}),e[61]=B,e[62]=Y,e[63]=X):X=e[63];let ne;e[64]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>j(bf),e[64]=ne):ne=e[64];let te;e[65]!==c?(te=c?s.jsx(L,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(L,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=c,e[66]=te):te=e[66];let ge;e[67]!==n?(ge=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=ge):ge=e[68];let ee;e[69]!==c||e[70]!==te||e[71]!==ge?(ee=s.jsxs("button",{type:"button",onClick:ne,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":c,children:[te,ge]}),e[69]=c,e[70]=te,e[71]=ge,e[72]=ee):ee=e[72];let le;e[73]!==X||e[74]!==ee?(le=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[X,ee]}),e[73]=X,e[74]=ee,e[75]=le):le=e[75];let pe;e[76]!==Z||e[77]!==le?(pe=s.jsxs(Bt,{showCloseButton:!1,className:"max-w-md gap-5",children:[Z,le]}),e[76]=Z,e[77]=le,e[78]=pe):pe=e[78];let ie;e[79]!==d||e[80]!==pe?(ie=s.jsx(Vt,{open:d,onOpenChange:S,children:pe}),e[79]=d,e[80]=pe,e[81]=ie):ie=e[81];let je;return e[82]!==q||e[83]!==ie?(je=s.jsxs(s.Fragment,{children:[q,ie]}),e[82]=q,e[83]=ie,e[84]=je):je=e[84],je};function hf(t){return t.isApplying}function ff(t){return t.showOpenCodeRestartConfirm}function xf(t){return t.setShowOpenCodeRestartConfirm}function bf(t){return!t}const vf=[{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.expanded-editor-toolbar",page:"general",titleKey:"settings.openchamber.visual.field.expandedEditorToolbar",keywords:["editor","toolbar","tabs","docked","files"],isAvailable:t=>!t.isVSCode},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.openchamber.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.openchamber.visual.field.terminalQuickKeys",descriptionKey:"settings.openchamber.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.openchamber.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.openchamber.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"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.sticky-user-header",page:"chat",titleKey:"settings.openchamber.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.openchamber.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.openchamber.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.openchamber.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.openchamber.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.openchamber.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.openchamber.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.openchamber.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.openchamber.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.openchamber.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.openchamber.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.openchamber.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.openchamber.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.openchamber.visual.section.followUpBehavior",descriptionKey:"settings.openchamber.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.openchamber.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.openchamber.visual.section.composer",keywords:["input","draft","spellcheck"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.openchamber.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"sessions.default-model",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.openchamber.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.openchamber.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.openchamber.defaults.smallModel.title",descriptionKey:"settings.openchamber.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.openchamber.defaults.walkthroughModel.title",descriptionKey:"settings.openchamber.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.openchamber.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.openchamber.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.openchamber.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.openchamber.desktopNetwork.field.windowControlsPositionDescription",keywords:["desktop","window","controls","minimize","maximize","close","titlebar","linux","windows"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-window-controls-style",page:"appearance",titleKey:"settings.openchamber.desktopNetwork.field.windowControlsStyle",keywords:["desktop","window","controls","style","traffic","lights","classic","macos","titlebar"],isAvailable:t=>t.isDesktop&&(t.isWindows||!t.isMac)},{id:"sessions.desktop-mac-menu-bar",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.macMenuBar",descriptionKey:"settings.openchamber.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.openchamber.desktopNetwork.field.minimizeToTrayDescription",keywords:["desktop","tray","system tray","minimize","close","background","windows","linux"],isAvailable:t=>t.isDesktopLocalOrigin&&(t.isWindows||t.isLinux)},{id:"sessions.desktop-keep-awake",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.keepAwake",descriptionKey:"settings.openchamber.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.openchamber.desktopPassword.field.password",descriptionKey:"settings.openchamber.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.openchamber.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.openchamber.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.openchamber.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.openchamber.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentControlTool",descriptionKey:"settings.openchamber.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","openchamber","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentWebTool",descriptionKey:"settings.openchamber.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","openchamber"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-memory-tool",page:"general",titleKey:"settings.openchamber.tools.field.agentMemoryTool",descriptionKey:"settings.openchamber.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","openchamber"],isAvailable:t=>!t.isVSCode&&ce.getState().agentMemoryFeatureAvailable},{id:"git.github-account",page:"git",titleKey:"settings.github.page.actions.connect",keywords:["github","account","oauth","prs","issues"]},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.openchamber.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.openchamber.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.openchamber.git.showGitignored",keywords:["ignored","files","gitignore"]},{id:"usage.work-status-panel",page:"usage",titleKey:"settings.usage.page.options.showInWorkStatus",descriptionKey:"settings.usage.page.options.showInWorkStatusTooltip",keywords:["quota","work","status","panel"]},{id:"usage.model-quotas",page:"usage",titleKey:"settings.usage.page.section.modelQuotas",keywords:["models","quota","limits","tokens"]},{id:"projects.name",page:"projects",titleKey:"settings.projects.page.field.projectName",keywords:["label","display name","project metadata"]},{id:"projects.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.third-party",page:"integrations",titleKey:"settings.integrations.thirdParty.title",keywords:["plugin","provider","oauth","install","update","remove"]},{id:"integrations.third-party.opencode-claude",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",keywords:["claude","anthropic","claude code","pro","max","agent sdk","@openchamber/opencode-claude"]},{id:"integrations.third-party.opencode-cursor-oauth",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeCursorOauth.name",descriptionKey:"settings.integrations.thirdParty.opencodeCursorOauth.description",keywords:["cursor","oauth","subscription","openai compatible","@openchamber/opencode-cursor"]}];function Jo(t){return t.trim().toLocaleLowerCase()}function yf({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=Jo(t);if(!r)return[];const l=a?new Set(a):null,h=r.split(/\s+/).filter(Boolean);return vf.flatMap(d=>{if(l&&!l.has(d.page))return[];const b=Ia(d.page);if(!b||b.isAvailable&&!b.isAvailable(e)||d.isAvailable&&!d.isAvailable(e))return[];const c=n(d.titleKey),j=d.descriptionKey?n(d.descriptionKey):null,m=Jo([c,j,i(d.page),...d.keywords??[]].filter(Boolean).join(" "));return h.every(E=>m.includes(E))?[{...d,title:c,description:j,pageTitle:i(d.page)}]:[]})}const Qo=256,Yo=280,Wl="__openchamberSettingsDetail",jf=["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"],wf=["general","projects","opencode","content"],kf="__add_provider__";function Nf(t,e){const a=xs(),n=!t&&In();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function Zo(t,e){return t.isAvailable?t.isAvailable(e):!0}function or(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Pa(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function Wi(t){if(!or(t))return null;const e=t[Wl];if(!or(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:bl(a),stage:n}}function Sf(){return typeof window>"u"||!or(window.history.state)?{}:window.history.state}const Cf=t=>{const e=mt.c(131),{onClose:a,forceMobile:n,isWindowed:i,visiblePageSlugs:r,initialMobileStage:l}=t,h=l===void 0?"nav":l,{t:d}=rt(),b=oa(),c=n??b.isMobile,j=pn(ml),m=ce(Pf),E=ce(If),v=ce(Af);let P;e[0]!==m?(P=bl(m),e[0]=m,e[1]=P):P=e[1];const x=P,[C,u]=o.useState(h),I=o.useRef(h==="nav"?x:null);let F,A;e[2]!==c||e[3]!==v||e[4]!==x?(F=()=>{!c&&x==="home"&&v("general")},A=[c,v,x],e[2]=c,e[3]=v,e[4]=x,e[5]=F,e[6]=A):(F=e[5],A=e[6]),o.useEffect(F,A);const[k,g]=o.useState(""),[w,z]=o.useState(null),[N,R]=o.useState(0),y=o.useRef(null);let O;e[7]===Symbol.for("react.memo_cache_sentinel")?(O=[],e[7]=O):O=e[7];const q=o.useRef(O),S=o.useRef(0),G=o.useRef(!1);let J;e[8]===Symbol.for("react.memo_cache_sentinel")?(J=hs(),e[8]=J):J=e[8];const T=J;let Q;e[9]===Symbol.for("react.memo_cache_sentinel")?(Q=hs()&&La(),e[9]=Q):Q=e[9];const Z=Q;let K;e[10]===Symbol.for("react.memo_cache_sentinel")?(K=hs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="darwin",e[10]=K):K=e[10];const ae=K;let _;e[11]===Symbol.for("react.memo_cache_sentinel")?(_=hs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="win32",e[11]=_):_=e[11];const B=_;let M;e[12]===Symbol.for("react.memo_cache_sentinel")?(M=hs()&&typeof window<"u"&&window.__OPENCHAMBER_PLATFORM__==="linux",e[12]=M):M=e[12];const U=M;let Y;e[13]===Symbol.for("react.memo_cache_sentinel")?(Y=fl(),e[13]=Y):Y=e[13];const X=Y;let ne;e[14]!==c?(ne=Nf(T,c),e[14]=c,e[15]=ne):ne=e[15];const te=ne;let ge;if(e[16]!==c||e[17]!==te||e[18]!==r){const Be=r?new Set(r):null;let et;e[20]!==te?(et=Dt=>Zo(Dt,te),e[20]=te,e[21]=et):et=e[21];let ht;e[22]!==te.isVSCode?(ht=Dt=>!(te.isVSCode&&Dt.slug==="projects"),e[22]=te.isVSCode,e[23]=ht):ht=e[23];let Tt;e[24]!==c?(Tt=Dt=>!(c&&Dt.slug==="shortcuts"),e[24]=c,e[25]=Tt):Tt=e[25],ge=Nd.filter(Ef).filter(Dt=>!Be||Be.has(Dt.slug)).filter(et).filter(ht).filter(Tt),e[16]=c,e[17]=te,e[18]=r,e[19]=ge}else ge=e[19];const ee=ge;let le;e[26]===Symbol.for("react.memo_cache_sentinel")?(le=new Map(jf.map(Tf)),e[26]=le):le=e[26];const pe=le;let ie;if(e[27]!==ee){let Be;e[29]===Symbol.for("react.memo_cache_sentinel")?(Be=(et,ht)=>(pe.get(et.slug)??999)-(pe.get(ht.slug)??999),e[29]=Be):Be=e[29],ie=ee.slice().sort(Be),e[27]=ee,e[28]=ie}else ie=e[28];const je=ie,Se=Qs(Df),Ce=Us();let xe;e[30]!==E||e[31]!==i||e[32]!==te.isVSCode||e[33]!==Ce||e[34]!==x?(xe=()=>{if(!(!E&&!te.isVSCode&&!i)){if(x==="agents"){_n.getState().loadAgents(Ce);return}if(x==="commands"){aa.getState().loadCommands(Ce);return}if(x==="mcp"){ia.getState().loadMcpConfigs({directory:Ce});return}if(x==="plugins"){gs.getState().loadPlugins();return}(x==="skills.installed"||x==="skills.catalog")&&(Vs.getState().loadSkills(Ce),cn.getState().loadCatalog()),x==="snippets"&&li.getState().loadSnippets()}},e[30]=E,e[31]=i,e[32]=te.isVSCode,e[33]=Ce,e[34]=x,e[35]=xe):xe=e[35];let Re;e[36]!==Se||e[37]!==E||e[38]!==i||e[39]!==te.isVSCode||e[40]!==Ce||e[41]!==x?(Re=[Se,E,i,te.isVSCode,Ce,x],e[36]=Se,e[37]=E,e[38]=i,e[39]=te.isVSCode,e[40]=Ce,e[41]=x,e[42]=Re):Re=e[42],o.useEffect(xe,Re);let Oe;e[43]!==c||e[44]!==v?(Oe=Be=>{if(v(Be),I.current=Be,!c)return;const et=Ia(Be);if(!et||et.slug==="home"){u("nav");return}u(et.kind==="split"?"page-sidebar":"page-content")},e[43]=c,e[44]=v,e[45]=Oe):Oe=e[45];const fe=Oe;let be;e[46]!==c||e[47]!==fe?(be=async Be=>{const et=st.getState();return await et.loadProviders({source:"settings:third-party-provider-setup"}),st.getState().providers.some(Tt=>Tt.id===Be)?(et.setSelectedProvider(Be),fe("providers"),c&&u("page-content"),!0):!1},e[46]=c,e[47]=fe,e[48]=be):be=e[48];const De=be;let _e;e[49]!==x?(_e=Ia(x),e[49]=x,e[50]=_e):_e=e[50];const Le=_e;let qe;e[51]===Symbol.for("react.memo_cache_sentinel")?(qe={general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[51]=qe):qe=e[51];const Ke=qe;let Xe;e[52]!==d?(Xe=Be=>{switch(Be){case"general":return d("settings.page.general.title");case"projects":return d("settings.page.projects.title");case"remote-instances":return d("settings.page.remoteInstances.title");case"providers":return d("settings.page.providers.title");case"usage":return d("settings.page.usage.title");case"agents":return d("settings.page.agents.title");case"behavior":return d("settings.page.behavior.title");case"commands":return d("settings.page.commands.title");case"mcp":return d("settings.page.mcp.title");case"plugins":return d("settings.page.plugins.title");case"skills.installed":return d("settings.page.skills.title");case"skills.catalog":return d("settings.page.skillsCatalog.title");case"git":return d("settings.page.git.title");case"integrations":return d("settings.page.integrations.title");case"appearance":return d("settings.page.appearance.title");case"chat":return d("settings.page.chat.title");case"shortcuts":return d("settings.page.shortcuts.title");case"sessions":return d("settings.page.sessions.title");case"magic-prompts":return d("settings.page.magicPrompts.title");case"snippets":return d("settings.page.snippets.title");case"notifications":return d("settings.page.notifications.title");case"voice":return d("settings.page.voice.title");case"tunnel":return d("settings.page.tunnel.title");case"about":return d("settings.page.about.title");default:return d("settings.view.home.title")}},e[52]=d,e[53]=Xe):Xe=e[53];const We=Xe;let Ze;e[54]!==We||e[55]!==te||e[56]!==k||e[57]!==d||e[58]!==r?(Ze=yf({query:k,runtimeCtx:{...te,isDesktopLocalOrigin:Z,isMac:ae,isWindows:B,isLinux:U,isWindowsArm64:X},visiblePageSlugs:r,t:d,getPageTitle:We}),e[54]=We,e[55]=te,e[56]=k,e[57]=d,e[58]=r,e[59]=Ze):Ze=e[59];const we=Ze,Je=Kf;let Me;if(e[60]!==we){Me=[];const Be=new Map;for(const et of we){let ht=Be.get(et.page);ht||(ht={page:et.page,pageTitle:et.pageTitle,results:[]},Be.set(et.page,ht),Me.push(ht)),ht.results.push(et)}e[60]=we,e[61]=Me}else Me=e[61];const ve=Me;let $e;e[62]===Symbol.for("react.memo_cache_sentinel")?($e=()=>{R(0),S.current=0,G.current=!1},e[62]=$e):$e=e[62];let $;e[63]!==k?($=[k],e[63]=k,e[64]=$):$=e[64],o.useEffect($e,$);let de,ue;e[65]!==N?(de=()=>{S.current=N},ue=[N],e[65]=N,e[66]=de,e[67]=ue):(de=e[66],ue=e[67]),o.useEffect(de,ue);let ke,oe;e[68]!==N?(ke=()=>{q.current[N]?.scrollIntoView({block:"nearest"})},oe=[N],e[68]=N,e[69]=ke,e[70]=oe):(ke=e[69],oe=e[70]),o.useEffect(ke,oe);let Ae,H;e[71]!==N||e[72]!==we.length?(Ae=()=>{N>=we.length&&R(Math.max(0,we.length-1)),q.current.length=we.length},H=[N,we.length],e[71]=N,e[72]=we.length,e[73]=Ae,e[74]=H):(Ae=e[73],H=e[74]),o.useEffect(Ae,H);let ze;e[75]!==c||e[76]!==fe?(ze=Be=>{const et=Je(Be);z(et),fe(Be.page),c&&u("page-content"),Be.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(Uf,50)},e[75]=c,e[76]=fe,e[77]=ze):ze=e[77];const tt=ze;let Fe;e[78]!==tt||e[79]!==k||e[80]!==we?(Fe=Be=>{if(k.trim()){if(Be.key==="Escape"){Be.preventDefault(),g("");return}if(we.length!==0){if(Be.key==="ArrowDown"){Be.preventDefault(),G.current=!0,R(et=>(et+1)%we.length);return}if(Be.key==="ArrowUp"){Be.preventDefault(),G.current=!0,R(et=>(et-1+we.length)%we.length);return}if(Be.key==="Enter"){Be.preventDefault();const et=(S.current%we.length+we.length)%we.length,ht=we[et]??we[0];ht&&tt(ht)}}}},e[78]=tt,e[79]=k,e[80]=we,e[81]=Fe):Fe=e[81];const at=Fe;let wt;e[82]!==w?(wt=()=>{const Be=w;if(!Be)return;let et=!1;const ht=window.requestAnimationFrame(()=>{if(et)return;const Tt=typeof CSS<"u"&&CSS.escape?CSS.escape(Be):Be.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Dt=y.current?.querySelector(`[data-settings-item="${Tt}"]`);Dt&&(z(null),Dt.scrollIntoView({block:"center",behavior:"smooth"}),Dt.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Dt.removeAttribute("data-settings-search-highlight")},1600))});return()=>{et=!0,window.cancelAnimationFrame(ht)}},e[82]=w,e[83]=wt):wt=e[83];let bt;e[84]!==w||e[85]!==x?(bt=[w,x],e[84]=w,e[85]=x,e[86]=bt):bt=e[86],o.useEffect(wt,bt);let ut;e[87]!==d?(ut=()=>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:ll,children:d("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:d("settings.view.unavailable.description")})]})}),e[87]=d,e[88]=ut):ut=e[88];const gt=ut,Pt=zf;let jt;e[89]!==fe||e[90]!==De||e[91]!==gt||e[92]!==te||e[93]!==d?(jt=Be=>{const et=Ia(Be);if(et&&!Zo(et,te))return gt();switch(Be){case"projects":return s.jsx(gu,{});case"remote-instances":return s.jsx(Ru,{});case"agents":return s.jsx(rp,{});case"behavior":return s.jsx(pp,{});case"commands":return s.jsx(vp,{});case"mcp":return s.jsx($p,{});case"plugins":return s.jsx(vm,{});case"skills.installed":return s.jsx(co,{view:"installed"});case"skills.catalog":return s.jsx(co,{view:"catalog"});case"providers":return s.jsx(hg,{});case"usage":return s.jsx(Eg,{});case"about":return s.jsx(cs,{title:d("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(jl,{})});case"magic-prompts":return s.jsx(Og,{});case"snippets":return s.jsx(zg,{});case"git":return s.jsx(Hg,{});case"integrations":return s.jsx(Xg,{onOpenProviderSetup:De,onOpenPluginManager:()=>fe("plugins")});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const ht=Ke[Be]??"visual";return s.jsx(tf,{section:ht})}default:return null}},e[89]=fe,e[90]=De,e[91]=gt,e[92]=te,e[93]=d,e[94]=jt):jt=e[94];const Et=jt;let Ye,Ge;e[95]!==c||e[96]!==C||e[97]!==x?(Ye=()=>{if(!c||C!=="nav"||x==="home"||I.current===x)return;const Be=Ia(x);!Be||Be.slug==="home"||(I.current=x,u(Be.kind==="split"?"page-sidebar":"page-content"))},Ge=[c,C,x],e[95]=c,e[96]=C,e[97]=x,e[98]=Ye,e[99]=Ge):(Ye=e[98],Ge=e[99]),o.useEffect(Ye,Ge);const ct=c&&C!=="nav",Ie=c&&C==="page-content"&&x==="skills.installed",It=C==="page-content"&&Le?.kind==="split"&&!Ie;let Ne;e[100]!==Ie||e[101]!==ct||e[102]!==d?(Ne=d(Ie?"settings.view.actions.back":ct?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[100]=Ie,e[101]=ct,e[102]=d,e[103]=Ne):Ne=e[103];const Ct=Ne,W=Hc();let me;e[104]!==te.isVSCode?(me=Be=>{if(typeof window>"u"||te.isVSCode)return;const et=Wi(window.history.state);et?.page===Be&&et.stage==="page-content"||window.history.pushState({...Sf(),[Wl]:{page:Be,stage:"page-content"}},"",window.location.href)},e[104]=te.isVSCode,e[105]=me):me=e[105];const Ee=me;let Pe;e[106]!==Ee||e[107]!==x?(Pe=()=>{u("page-content"),x==="skills.installed"&&Ee(x)},e[106]=Ee,e[107]=x,e[108]=Pe):Pe=e[108];const lt=Pe;let it;e[109]!==Ie||e[110]!==te.isVSCode||e[111]!==x?(it=()=>{if(Ie){if((typeof window<"u"?Wi(window.history.state):null)?.page===x&&!te.isVSCode){window.history.back();return}u("page-sidebar");return}u("nav")},e[109]=Ie,e[110]=te.isVSCode,e[111]=x,e[112]=it):it=e[112];const Ve=it;let Nt,is;e[113]!==c||e[114]!==te.isVSCode||e[115]!==x?(Nt=()=>{if(!c||te.isVSCode)return;const Be=et=>{if(x!=="skills.installed")return;if(Wi(et.state)?.page==="skills.installed"){u("page-content");return}u(_f)};return window.addEventListener("popstate",Be),()=>{window.removeEventListener("popstate",Be)}},is=[c,te.isVSCode,x],e[113]=c,e[114]=te.isVSCode,e[115]=x,e[116]=Nt,e[117]=is):(Nt=e[116],is=e[117]),o.useEffect(Nt,is);let es;e[118]===Symbol.for("react.memo_cache_sentinel")?(es=()=>{u("page-sidebar")},e[118]=es):es=e[118];const ys=es,Ht=()=>{const Be=k.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(L,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:k,onChange:et=>g(et.target.value),onKeyDown:at,placeholder:d("settings.view.search.placeholder"),"aria-label":d("settings.view.search.aria"),className:"typography-ui min-w-0 flex-1 bg-transparent text-foreground outline-none placeholder:text-muted-foreground/70"}),Be&&s.jsx("button",{type:"button",onClick:()=>g(""),"aria-label":d("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(L,{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:Be?we.length>0?(()=>{let et=0;return ve.map(ht=>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:ht.pageTitle}),ht.results.map(Tt=>{const Dt=et;et=et+1;const Xt=Dt===N,At=!!Tt.description;return s.jsxs("button",{type:"button",ref:St=>{q.current[Dt]=St},onMouseMove:()=>{G.current=!1,R(Dt)},onClick:()=>tt(Tt),className:ye("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",At?"min-h-11 py-1.5":"py-2",Xt?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Tt.title}),At&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:Tt.description})]},Tt.id)})]},ht.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:d("settings.view.search.noResults")}):(()=>{const et=new Map;for(const Tt of je){const Dt=Tt.group,Xt=et.get(Dt);Xt?Xt.push(Tt):et.set(Dt,[Tt])}return wf.map(Tt=>({group:Tt,pages:et.get(Tt)??[]})).filter($f).map((Tt,Dt)=>{const{group:Xt,pages:At}=Tt;return s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:ye("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Dt===0?"pt-1":"pt-4 sm:pt-3"),children:d(`settings.view.nav.group.${Xt}`)}),At.map(St=>{const Ut=x===St.slug&&!(c&&C==="nav"),Mt=Sd(St.slug);return!Mt&&St.slug!=="mcp"?null:s.jsx(dr,{children:s.jsx(pr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>fe(St.slug),"aria-current":Ut?"page":void 0,className:ye("flex h-11 w-full items-center gap-2.5 rounded-md px-3 overflow-hidden sm:h-8 sm:gap-2 sm:px-2",Ut?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[St.slug==="mcp"?s.jsx(Gc,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(L,{name:Mt,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:We(St.slug)}),(St.slug==="tunnel"||St.slug==="integrations")&&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:d("settings.view.badge.beta")})]})]})})},St.slug)})]},Xt)})})()})}),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:(!te.isVSCode||j>0)&&s.jsx(gf,{})})})]})},rs=()=>{if(C==="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(bn,{children:Ht()})})});if(!Le)return s.jsx("div",{className:"flex-1 bg-background"});if(C==="page-sidebar"){if(Le.kind!=="split"){const et=Et(x);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:et})})}return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:Pt(x,{onItemSelect:lt})})})}const Be=Et(x);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:Be})})};let zt;e[119]!==Le||e[120]!==Et||e[121]!==te.isVSCode||e[122]!==x?(zt=()=>!Le||x==="home"?null:Le.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:ye("border-r",te.isVSCode?"bg-background":"bg-sidebar"),style:{width:Yo,minWidth:Yo,borderColor:"var(--interactive-border)"},children:s.jsx(bn,{children:Pt(x,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:Et(x)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(bn,{children:Et(x)})}),e[119]=Le,e[120]=Et,e[121]=te.isVSCode,e[122]=x,e[123]=zt):zt=e[123];const fs=zt,os="true";let ss;e[124]===Symbol.for("react.memo_cache_sentinel")?(ss=ye("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[124]=ss):ss=e[124];const ns=c?s.jsxs("div",{className:ye("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",C!=="nav"&&"border-b","bg-background"),style:C!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[ct?s.jsx("button",{type:"button",onClick:Ve,"aria-label":Ct,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(L,{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:C==="nav"?d("settings.view.home.title"):Le?We(Le.slug):d("settings.view.home.title")}),It&&s.jsx("button",{type:"button",onClick:ys,"aria-label":d("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(L,{name:"list-unordered",className:"h-5 w-5"})}),a&&s.jsx("button",{type:"button",onClick:a,"aria-label":d("settings.view.actions.closeSettings"),title:d("settings.view.actions.closeSettingsWithShortcut",{shortcut:W}),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(L,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[ct&&s.jsx("div",{className:ye("absolute left-3 z-50",i?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Ve,"aria-label":d("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(L,{name:"arrow-left-s",className:"h-5 w-5"})})}),a&&s.jsx("div",{className:ye("absolute right-0.5 z-50",i?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:a,"aria-label":d("settings.view.actions.closeSettings"),title:d("settings.view.actions.closeSettingsWithShortcut",{shortcut:W}),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(L,{name:"close",className:"h-5 w-5"})})})]}),js="flex flex-1 min-h-0 overflow-hidden",re=c?rs():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:ye("relative flex h-full min-h-0 flex-col overflow-hidden border-r",T?"bg-sidebar":te.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${Qo}px`,minWidth:`${Qo}px`,borderColor:"var(--interactive-border)"},children:s.jsx(bn,{children:Ht()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:fs()})]});let ot;e[125]!==re?(ot=s.jsx("div",{className:js,children:re}),e[125]=re,e[126]=ot):ot=e[126];let vt;return e[127]!==ss||e[128]!==ns||e[129]!==ot?(vt=s.jsxs("div",{ref:y,"data-settings-view":os,className:ss,children:[ns,ot]}),e[127]=ss,e[128]=ns,e[129]=ot,e[130]=vt):vt=e[130],vt};function Pf(t){return t.settingsPage}function If(t){return t.isSettingsDialogOpen}function Af(t){return t.setSettingsPage}function Ef(t){return t.slug!=="home"}function Tf(t,e){return[t,e]}function Df(t){return t.activeProjectId}function Mf(t){return t.name}function Rf(t){return t.name}function Of(t){return t.name}function Lf(t){return t.name}function Ff(t){return t.name}function Kf(t){if(t.id.startsWith("agents.")){const e=_n.getState(),a=Pa("new-agent",e.agents.map(Mf));return e.setAgentDraft({name:a,scope:"user"}),e.setSelectedAgent(a),t.id==="agents.create"?"agents.name":t.id}if(t.id.startsWith("commands.")){const e=aa.getState(),a=Pa("new-command",e.commands.map(Rf));return e.setCommandDraft({name:a,scope:"user"}),e.setSelectedCommand(a),t.id==="commands.create"?"commands.name":t.id}if(t.id.startsWith("mcp.")){const e=ia.getState(),a=Pa("new-mcp-server",e.mcpServers.map(Of));return e.setMcpDraft({name:a,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),e.setSelectedMcp(a),t.id==="mcp.create"?"mcp.server":t.id}if(t.id.startsWith("snippets.")){const e=li.getState(),a=Pa("new-snippet",e.snippets.map(Lf));return e.setSnippetDraft({name:a,scope:"global"}),e.setSelectedSnippet(a),t.id==="snippets.create"?"snippets.content":t.id}if(t.id.startsWith("skills.")){const e=Vs.getState(),a=Pa("new-skill",e.skills.map(Ff));return e.setSkillDraft({name:a,scope:"user",source:"opencode",description:"",instructions:""}),e.setSelectedSkill(a),t.id==="skills.create"?"skills.basic-information":t.id}return t.id==="providers.connect"&&st.getState().setSelectedProvider(kf),t.id==="plugins.create"?"plugins.spec":t.id}function Uf(){window.dispatchEvent(new CustomEvent("openchamber:settings-open-plugin-add"))}function zf(t,e){switch(t){case"projects":return s.jsx(cu,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(Jd,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(mp,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(yp,{onItemSelect:e.onItemSelect});case"plugins":return s.jsx(om,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(jm,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(Fu,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(xg,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(Dg,{onItemSelect:e.onItemSelect});case"snippets":return s.jsx(Lg,{onItemSelect:e.onItemSelect});default:return null}}function _f(t){return t==="page-content"?"page-sidebar":t}function $f(t){return t.pages.length>0}const ex=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:Cf},Symbol.toStringTag,{value:"Module"}));export{jl as A,Cf as S,ex as a};